Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/runtime/kernel/boot.c
ViewVC logotype

Diff of /sml/trunk/src/runtime/kernel/boot.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 536, Fri Feb 18 16:51:54 2000 UTC revision 537, Fri Feb 18 17:20:16 2000 UTC
# Line 21  Line 21 
21  #  define SEEK_SET      0  #  define SEEK_SET      0
22  #endif  #endif
23    
 /** The names of the boot and binary file lists **/  
 PVT char        *FileLists[] = {  
         "BOOTLIST", "PERVLIST", "COMPLIST"  
     };  
 #define NUM_FILE_LISTS  (sizeof(FileLists) / sizeof(char *))  
   
   
 pers_id_t       RunTimePerID = {RUNTIME_PERID};  
   
   
24  /* The persistent ID list is stored in the PervStruct refcell.  It has  /* The persistent ID list is stored in the PervStruct refcell.  It has
25   * the following ML type:   * the following ML type:
26   *   *
# Line 44  Line 34 
34    
35    
36  /* local routines */  /* local routines */
37  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *binDir);  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *bootlist);
38  PVT FILE *OpenBinFile (const char *binDir, const char *fname, bool_t isBinary);  PVT FILE *OpenBinFile (const char *fname, bool_t isBinary);
39  PVT void ReadBinFile (  PVT void ReadBinFile (FILE *file, void *buf, int nbytes, const char *fname);
40      FILE *file, void *buf, int nbytes,  PVT void LoadBinFile (ml_state_t *msp, char *fname);
     const char *binDir, const char *fname  
 );  
 PVT void LoadBinFile (ml_state_t *msp, const char *binDir, char *fname);  
41  PVT void EnterPerID (ml_state_t *msp, pers_id_t *perID, ml_val_t obj);  PVT void EnterPerID (ml_state_t *msp, pers_id_t *perID, ml_val_t obj);
42  PVT ml_val_t LookupPerID (pers_id_t *perID);  PVT ml_val_t LookupPerID (pers_id_t *perID);
43  PVT void ShowPerID (char *buf, pers_id_t *perID);  PVT void ShowPerID (char *buf, pers_id_t *perID);
# Line 59  Line 46 
46    
47  /* BootML:  /* BootML:
48   *   *
49  * Boot the system using the .bin files from binDir.  * Boot the system using the items read from the "bootlist" file.
50  */  */
51  void BootML (const char *binDir, heap_params_t *heapParams, const char *rtPID)  void BootML (const char *bootlist, heap_params_t *heapParams)
52  {  {
53      ml_state_t  *msp;      ml_state_t  *msp;
54      char        fname[512];      char        fname[MAX_BOOT_PATH_LEN];
55        int         rts_init = 0;
     if (rtPID != NIL(char *)) {  
         int i, l = strlen (rtPID);  
         for (i = 0; i < PERID_LEN; i++) {  
             int i2 = 2 * i;  
             if (i2 + 1 < l) {  
                 int c1 = rtPID[i2];  
                 int c2 = rtPID[i2 + 1];  
 /* what if upper-case digits are used?? */  
                 RunTimePerID.bytes[i] = (HEX(c1) << 4) + HEX(c2);  
             }  
         }  
     }  
56    
57      msp = AllocMLState (TRUE, heapParams);      msp = AllocMLState (TRUE, heapParams);
58    
# Line 89  Line 64 
64      InitFaultHandlers ();      InitFaultHandlers ();
65      AllocGlobals (msp);      AllocGlobals (msp);
66    
   /* Enter the runtime system binding */  
     EnterPerID (msp, &RunTimePerID, RunTimeCompUnit);  
   
67    /* construct the list of files to be loaded */    /* construct the list of files to be loaded */
68      BinFileList = BuildFileList (msp, binDir);      BinFileList = BuildFileList (msp, bootlist);
69    
70    /* boot the system */    /* boot the system */
71      while (BinFileList != LIST_nil) {      while (BinFileList != LIST_nil) {
72          strcpy(fname, STR_MLtoC(LIST_hd(BinFileList)));          strcpy(fname, STR_MLtoC(LIST_hd(BinFileList)));
73          BinFileList = LIST_tl(BinFileList);          BinFileList = LIST_tl(BinFileList);
74          LoadBinFile (msp, binDir, fname);          if (fname[0] == '#')
75              if (rts_init)
76                Die ("runtime system registered more than once\n");
77              else {
78                /* register the runtime system under the given pers id */
79                pers_id_t pid;
80                int i, l = strlen (fname + 1);
81                for (i = 0; i < PERID_LEN; i++) {
82                  int i2 = 2 * i;
83                  if (i2 + 1 < l) {
84                    int c1 = fname[i2+1];
85                    int c2 = fname[i2+2];
86                    pid.bytes[i] = (HEX(c1) << 4) + HEX(c2);
87                  }
88                }
89                Say ("[Registering runtime system as %s]\n", fname+1);
90                EnterPerID (msp, &pid, RunTimeCompUnit);
91                rts_init = 1;       /* make sure we do this only once */
92              }
93            else
94              LoadBinFile (msp, fname);
95      }      }
96    
97  } /* end of BootML */  } /* end of BootML */
# Line 110  Line 102 
102   * Given the directory path, build a list of the .bin files in the   * Given the directory path, build a list of the .bin files in the
103   * heap.   * heap.
104   */   */
105  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *binDir)  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *bootlist)
106  {  {
107      FILE        *listF;      FILE        *listF;
108      ml_val_t    fileNames[MAX_NUM_BOOT_FILES];      ml_val_t    fileNames[MAX_NUM_BOOT_FILES];
# Line 118  Line 110 
110      char        nameBuf[MAX_BOOT_PATH_LEN];      char        nameBuf[MAX_BOOT_PATH_LEN];
111      ml_val_t    fileList;      ml_val_t    fileList;
112    
113      for (numFiles = 0, i = 0;  i < NUM_FILE_LISTS;  i++) {      listF = OpenBinFile (bootlist, FALSE);
114          listF = OpenBinFile (binDir, FileLists[i], FALSE);      if (listF != NULL) {
         if (listF == NULL)  
             continue;  
115        /* read in the file names, converting them to ML strings. */        /* read in the file names, converting them to ML strings. */
116          while (fgets (nameBuf, MAX_BOOT_PATH_LEN, listF) != NIL(char *)) {          while (fgets (nameBuf, MAX_BOOT_PATH_LEN, listF) != NIL(char *)) {
117              j = strlen(nameBuf)-1;              j = strlen(nameBuf)-1;
# Line 148  Line 138 
138   *   *
139   * Open a file in the bin file directory.   * Open a file in the bin file directory.
140   */   */
141  PVT FILE *OpenBinFile (const char *binDir, const char *fname, bool_t isBinary)  PVT FILE *OpenBinFile (const char *fname, bool_t isBinary)
142  {  {
     char        path[MAX_BOOT_PATH_LEN];  
143      FILE        *file;      FILE        *file;
144    
145      sprintf(path, "%s%c%s", binDir, PATH_ARC_SEP, fname);      if ((file = fopen (fname, isBinary ? "rb" : "r")) == NULL)
146            Error ("unable to open \"%s\"\n", fname);
     if ((file = fopen(path, isBinary ? "rb" : "r")) == NULL)  
         Error ("unable to open \"%s\"\n", path);  
147    
148      return file;      return file;
149    
# Line 274  Line 261 
261    
262  /* ReadBinFile:  /* ReadBinFile:
263   */   */
264  PVT void ReadBinFile (  PVT void ReadBinFile (FILE *file, void *buf, int nbytes, const char *fname)
     FILE *file, void *buf, int nbytes, const char *binDir, const char *fname  
 )  
265  {  {
266      if (fread(buf, nbytes, 1, file) == -1)      if (fread(buf, nbytes, 1, file) == -1)
267          Die ("cannot read file \"%s%c%s\"", binDir, PATH_ARC_SEP, fname);          Die ("cannot read file \"%s\"", fname);
268    
269  } /* end of ReadBinFile */  } /* end of ReadBinFile */
270    
# Line 287  Line 272 
272   *   *
273   * Read an integer in "packed" format.  (Small numbers only require 1 byte.)   * Read an integer in "packed" format.  (Small numbers only require 1 byte.)
274   */   */
275  PVT Int32_t ReadPackedInt32 (FILE *file, const char *binDir, const char *fname)  PVT Int32_t ReadPackedInt32 (FILE *file, const char *fname)
276  {  {
277      Unsigned32_t        n;      Unsigned32_t        n;
278      Byte_t              c;      Byte_t              c;
279    
280      n = 0;      n = 0;
281      do {      do {
282          ReadBinFile (file, &c, sizeof(c), binDir, fname);          ReadBinFile (file, &c, sizeof(c), fname);
283          n = (n << 7) | (c & 0x7f);          n = (n << 7) | (c & 0x7f);
284      } while ((c & 0x80) != 0);      } while ((c & 0x80) != 0);
285    
# Line 306  Line 291 
291   *   *
292   * Select out the interesting bits from the imported object.   * Select out the interesting bits from the imported object.
293   */   */
294  PVT void ImportSelection (  PVT void ImportSelection (ml_state_t *msp, FILE *file, const char *fname,
295      ml_state_t  *msp,                            int *importVecPos, ml_val_t tree)
     FILE        *file,  
     const char  *binDir,  
     const char  *fname,  
     int         *importVecPos,  
     ml_val_t    tree)  
296  {  {
297      Int32_t cnt = ReadPackedInt32 (file, binDir, fname);      Int32_t cnt = ReadPackedInt32 (file, fname);
298      if (cnt == 0) {      if (cnt == 0) {
299          ML_AllocWrite (msp, *importVecPos, tree);          ML_AllocWrite (msp, *importVecPos, tree);
300          (*importVecPos)++;          (*importVecPos)++;
301      }      }
302      else {      else {
303          while (cnt-- > 0) {          while (cnt-- > 0) {
304              Int32_t selector = ReadPackedInt32 (file, binDir, fname);              Int32_t selector = ReadPackedInt32 (file, fname);
305              ImportSelection (              ImportSelection (msp, file, fname, importVecPos,
                 msp, file, binDir, fname, importVecPos,  
306                  REC_SEL(tree, selector));                  REC_SEL(tree, selector));
307          }          }
308      }      }
# Line 332  Line 311 
311    
312  /* LoadBinFile:  /* LoadBinFile:
313   */   */
314  PVT void LoadBinFile (ml_state_t *msp, const char *binDir, char *fname)  PVT void LoadBinFile (ml_state_t *msp, char *fname)
315  {  {
316      FILE            *file;      FILE            *file;
317      int             i, exportSzB, remainingCode, importRecLen;      int             i, exportSzB, remainingCode, importRecLen;
# Line 361  Line 340 
340      Say ("[Loading %s]\n", objname);      Say ("[Loading %s]\n", objname);
341    
342    /* open the file */    /* open the file */
343      file = OpenBinFile (binDir, fname, TRUE);      file = OpenBinFile (fname, TRUE);
344      if (file == NULL)      if (file == NULL)
345          Exit (1);          Exit (1);
346    
# Line 371  Line 350 
350     */     */
351      if (archiveOffset != 0) {      if (archiveOffset != 0) {
352          if (fseek (file, archiveOffset, SEEK_SET) == -1)          if (fseek (file, archiveOffset, SEEK_SET) == -1)
353              Die ("cannot seek on archive file \"%s%c%s@%ul\"",              Die ("cannot seek on archive file \"%s@%ul\"",
354                  binDir, PATH_ARC_SEP, fname, (unsigned long) archiveOffset);                   fname, (unsigned long) archiveOffset);
355      }      }
356    
357    /* get the header */    /* get the header */
358      ReadBinFile (file, &hdr, sizeof(binfile_hdr_t), binDir, fname);      ReadBinFile (file, &hdr, sizeof(binfile_hdr_t), fname);
359    
360    /* get header byte order right */    /* get header byte order right */
361      hdr.importCnt       = BIGENDIAN_TO_HOST(hdr.importCnt);      hdr.importCnt       = BIGENDIAN_TO_HOST(hdr.importCnt);
# Line 401  Line 380 
380          ML_AllocWrite (msp, 0, MAKE_DESC(importRecLen, DTAG_record));          ML_AllocWrite (msp, 0, MAKE_DESC(importRecLen, DTAG_record));
381          for (importVecPos = 1; importVecPos < importRecLen; ) {          for (importVecPos = 1; importVecPos < importRecLen; ) {
382              pers_id_t   importPid;              pers_id_t   importPid;
383              ReadBinFile (file, &importPid, sizeof(pers_id_t), binDir, fname);              ReadBinFile (file, &importPid, sizeof(pers_id_t), fname);
384              ImportSelection (              ImportSelection (msp, file, fname, &importVecPos,
                 msp, file, binDir, fname, &importVecPos,  
385                  LookupPerID(&importPid));                  LookupPerID(&importPid));
386          }          }
387          ML_AllocWrite(msp, importRecLen, ML_nil);          ML_AllocWrite(msp, importRecLen, ML_nil);
# Line 413  Line 391 
391    /* read the export PerID */    /* read the export PerID */
392      if (hdr.exportCnt == 1) {      if (hdr.exportCnt == 1) {
393          exportSzB = sizeof(pers_id_t);          exportSzB = sizeof(pers_id_t);
394          ReadBinFile (file, &exportPerID, exportSzB, binDir, fname);          ReadBinFile (file, &exportPerID, exportSzB, fname);
395      }      }
396      else if (hdr.exportCnt != 0)      else if (hdr.exportCnt != 0)
397          Die ("# of export pids is %d (should be 0 or 1)", (int)hdr.exportCnt);          Die ("# of export pids is %d (should be 0 or 1)", (int)hdr.exportCnt);
# Line 431  Line 409 
409                          + hdr.reserved1 + hdr.reserved2;                          + hdr.reserved1 + hdr.reserved2;
410    
411          if (fseek(file, off, SEEK_SET) == -1)          if (fseek(file, off, SEEK_SET) == -1)
412              Die ("cannot seek on bin file \"%s%c%s\"",              Die ("cannot seek on bin file \"%s\"", fname);
                  binDir, PATH_ARC_SEP, fname);  
413      }      }
414    
415    /* Read code objects and run them.  The first code object will be the    /* Read code objects and run them.  The first code object will be the
# Line 444  Line 421 
421      remainingCode = hdr.codeSzB;      remainingCode = hdr.codeSzB;
422    
423    /* read the size for the data object */    /* read the size for the data object */
424      ReadBinFile (file, &thisSzB, sizeof(Int32_t), binDir, fname);      ReadBinFile (file, &thisSzB, sizeof(Int32_t), fname);
425      thisSzB = BIGENDIAN_TO_HOST(thisSzB);      thisSzB = BIGENDIAN_TO_HOST(thisSzB);
426    
427      remainingCode -= thisSzB + sizeof(Int32_t);      remainingCode -= thisSzB + sizeof(Int32_t);
428      if (remainingCode < 0)      if (remainingCode < 0)
429          Die ("format error (data size mismatch) in bin file \"%s%c%s\"",          Die ("format error (data size mismatch) in bin file \"%s\"", fname);
             binDir, PATH_ARC_SEP, fname);  
430    
431      if (thisSzB > 0) {      if (thisSzB > 0) {
432          Byte_t          *dataObj = NEW_VEC(Byte_t, thisSzB);          Byte_t          *dataObj = NEW_VEC(Byte_t, thisSzB);
433    
434          ReadBinFile (file, dataObj, thisSzB, binDir, fname);          ReadBinFile (file, dataObj, thisSzB, fname);
435          SaveCState (msp, &BinFileList, &importRec, NIL(ml_val_t *));          SaveCState (msp, &BinFileList, &importRec, NIL(ml_val_t *));
436          val = BuildLiterals (msp, dataObj, thisSzB);          val = BuildLiterals (msp, dataObj, thisSzB);
437          FREE(dataObj);          FREE(dataObj);
# Line 477  Line 453 
453          int             strLen, padLen, extraLen;          int             strLen, padLen, extraLen;
454    
455        /* read the size for this code object */        /* read the size for this code object */
456          ReadBinFile (file, &thisSzB, sizeof(Int32_t), binDir, fname);          ReadBinFile (file, &thisSzB, sizeof(Int32_t), fname);
457          thisSzB = BIGENDIAN_TO_HOST(thisSzB);          thisSzB = BIGENDIAN_TO_HOST(thisSzB);
458    
459        /* We use one byte for the length, so the longest string is 255        /* We use one byte for the length, so the longest string is 255
# Line 495  Line 471 
471        /* how much more? */        /* how much more? */
472          remainingCode -= thisSzB + sizeof(Int32_t);          remainingCode -= thisSzB + sizeof(Int32_t);
473          if (remainingCode < 0)          if (remainingCode < 0)
474              Die ("format error (code size mismatch) in bin file \"%s%c%s\"",            Die ("format error (code size mismatch) in bin file \"%s\"", fname);
                 binDir, PATH_ARC_SEP, fname);  
475    
476        /* allocate space and read code object */        /* allocate space and read code object */
477          codeObj = ML_AllocCode (msp, thisSzB+extraLen);          codeObj = ML_AllocCode (msp, thisSzB+extraLen);
478          ReadBinFile (file, PTR_MLtoC(char, codeObj), thisSzB, binDir, fname);          ReadBinFile (file, PTR_MLtoC(char, codeObj), thisSzB, fname);
479    
480        /* tack on the bin-file name as a comment string. */        /* tack on the bin-file name as a comment string. */
481          memcpy (PTR_MLtoC(char, codeObj)+thisSzB+padLen, objname, strLen);          memcpy (PTR_MLtoC(char, codeObj)+thisSzB+padLen, objname, strLen);

Legend:
Removed from v.536  
changed lines
  Added in v.537

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0