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 249, Sat Apr 17 18:57:03 1999 UTC revision 418, Fri Sep 3 23:51:27 1999 UTC
# Line 7  Line 7 
7    
8  #include "ml-osdep.h"  #include "ml-osdep.h"
9  #include <stdio.h>  #include <stdio.h>
10    #include <string.h>
11    #include <stdlib.h>
12  #include "ml-base.h"  #include "ml-base.h"
13  #include "ml-limits.h"  #include "ml-limits.h"
14  #include "cache-flush.h"  #include "cache-flush.h"
# Line 48  Line 50 
50      FILE *file, void *buf, int nbytes,      FILE *file, void *buf, int nbytes,
51      const char *binDir, const char *fname      const char *binDir, const char *fname
52  );  );
53  PVT void LoadBinFile (ml_state_t *msp, const char *binDir, const char *fname);  PVT void LoadBinFile (ml_state_t *msp, const char *binDir, char *fname);
54  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);
55  PVT ml_val_t LookupPerID (pers_id_t *perID);  PVT ml_val_t LookupPerID (pers_id_t *perID);
56  PVT void ShowPerID (char *buf, pers_id_t *perID);  PVT void ShowPerID (char *buf, pers_id_t *perID);
57    
58    # define HEX(c) (isdigit(c) ? (c) - '0' : (c) - 'a' + 10)
59    
60  /* BootML:  /* BootML:
61   *   *
62   * Boot the system using the .bin files from binDir.   * Boot the system using the .bin files from binDir.
63   */   */
64  void BootML (const char *binDir, heap_params_t *heapParams)  void BootML (const char *binDir, heap_params_t *heapParams,
65                 const char *rtpid_spec)
66  {  {
67      ml_state_t  *msp;      ml_state_t  *msp;
68      char        fname[512];      char        fname[512];
69    
70        if (rtpid_spec) {
71          int i, l = strlen (rtpid_spec);
72          for (i = 0; i < PERID_LEN; i++) {
73            int i2 = 2 * i;
74            if (i2 + 1 < l) {
75              int c1 = rtpid_spec [i2];
76              int c2 = rtpid_spec [i2 + 1];
77              RunTimePerID.bytes[i] = HEX (c1) * 16 + HEX (c2);
78            }
79          }
80        }
81    
82      msp = AllocMLState (TRUE, heapParams);      msp = AllocMLState (TRUE, heapParams);
83    
84  #ifdef HEAP_MONITOR  #ifdef HEAP_MONITOR
# Line 82  Line 98 
98    /* boot the system */    /* boot the system */
99      while (BinFileList != LIST_nil) {      while (BinFileList != LIST_nil) {
100          strcpy(fname, STR_MLtoC(LIST_hd(BinFileList)));          strcpy(fname, STR_MLtoC(LIST_hd(BinFileList)));
         Say ("[Loading %s]\n", fname);  
101          BinFileList = LIST_tl(BinFileList);          BinFileList = LIST_tl(BinFileList);
102          LoadBinFile (msp, binDir, fname);          LoadBinFile (msp, binDir, fname);
103      }      }
# Line 317  Line 332 
332    
333  /* LoadBinFile:  /* LoadBinFile:
334   */   */
335  PVT void LoadBinFile (ml_state_t *msp, const char *binDir, const char *fname)  PVT void LoadBinFile (ml_state_t *msp, const char *binDir, char *fname)
336  {  {
337      FILE            *file;      FILE            *file;
338      int             i, exportSzB, remainingCode, importRecLen;      int             i, exportSzB, remainingCode, importRecLen;
# Line 326  Line 341 
341      binfile_hdr_t   hdr;      binfile_hdr_t   hdr;
342      pers_id_t       exportPerID;      pers_id_t       exportPerID;
343      Int32_t         thisSzB;      Int32_t         thisSzB;
344        size_t          archive_offset;
345        char            *atptr, *colonptr;
346        char            *objname = fname;
347    
348    
349        if ((atptr = strchr (fname, '@')) == NULL)
350          archive_offset = 0;
351        else {
352          if ((colonptr = strchr (atptr + 1, ':')) != NULL) {
353            objname = colonptr + 1;
354            *colonptr = '\0';
355          }
356          /* not a lot of extensive checking here... */
357          archive_offset = strtoul (atptr + 1, NULL, 0);
358          *atptr = '\0';
359        }
360    
361        Say ("[Loading %s]\n", objname);
362    
363    /* open the file */    /* open the file */
364      file = OpenBinFile (binDir, fname, TRUE);      file = OpenBinFile (binDir, fname, TRUE);
365      if (file == NULL)      if (file == NULL)
366          Exit (1);          Exit (1);
367    
368      /* if an offset is given (i.e., we are probably dealing with a stable
369       * archive), then seek to the beginning of the section that contains
370       * the binfile */
371        if (archive_offset)
372          if (fseek (file, archive_offset, SEEK_SET) == -1)
373            Die ("cannot seek on archive file \"%s%c%s@%ul\"",
374                 binDir, PATH_ARC_SEP, fname, (unsigned long) archive_offset);
375    
376    /* get the header */    /* get the header */
377      ReadBinFile (file, &hdr, sizeof(binfile_hdr_t), binDir, fname);      ReadBinFile (file, &hdr, sizeof(binfile_hdr_t), binDir, fname);
378    
# Line 379  Line 420 
420    
421    /* seek to code section */    /* seek to code section */
422      {      {
423          long        off = sizeof(binfile_hdr_t)          long        off = archive_offset
424                            + sizeof(binfile_hdr_t)
425                          + hdr.importSzB                          + hdr.importSzB
426                          + exportSzB                          + exportSzB
427                          + hdr.cmInfoSzB                          + hdr.cmInfoSzB
# Line 387  Line 429 
429                          + hdr.reserved1 + hdr.reserved2;                          + hdr.reserved1 + hdr.reserved2;
430    
431          if (fseek(file, off, SEEK_SET) == -1)          if (fseek(file, off, SEEK_SET) == -1)
432              Die ("cannot seek on bin file \"%s%c%s\"", binDir, PATH_ARC_SEP, fname);              Die ("cannot seek on bin file \"%s%c%s\"",
433                     binDir, PATH_ARC_SEP, fname);
434      }      }
435    
436    /* 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 440  Line 483 
483         * length byte is WORD_SZB bytes.  The padding is inserted between         * length byte is WORD_SZB bytes.  The padding is inserted between
484         * the code and the string.         * the code and the string.
485         */         */
486          strLen = strlen(fname);          strLen = strlen(objname);
487          if (strLen > 255)          if (strLen > 255)
488              strLen = 255;              strLen = 255;
489          extraLen = strLen+1;  /* include byte for length */          extraLen = strLen+1;  /* include byte for length */
# Line 458  Line 501 
501          ReadBinFile (file, PTR_MLtoC(char, codeObj), thisSzB, binDir, fname);          ReadBinFile (file, PTR_MLtoC(char, codeObj), thisSzB, binDir, fname);
502    
503        /* tack on the bin-file name as a comment string. */        /* tack on the bin-file name as a comment string. */
504          memcpy (PTR_MLtoC(char, codeObj)+thisSzB+padLen, fname, strLen);          memcpy (PTR_MLtoC(char, codeObj)+thisSzB+padLen, objname, strLen);
505          *(PTR_MLtoC(Byte_t, codeObj)+thisSzB+extraLen-1) = (Byte_t)strLen;          *(PTR_MLtoC(Byte_t, codeObj)+thisSzB+extraLen-1) = (Byte_t)strLen;
506    
507          FlushICache (PTR_MLtoC(char, codeObj), thisSzB);          FlushICache (PTR_MLtoC(char, codeObj), thisSzB);

Legend:
Removed from v.249  
changed lines
  Added in v.418

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