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 568, Tue Mar 7 03:59:09 2000 UTC revision 569, Tue Mar 7 04:01:07 2000 UTC
# Line 9  Line 9 
9  #include <stdio.h>  #include <stdio.h>
10  #include <string.h>  #include <string.h>
11  #include <stdlib.h>  #include <stdlib.h>
12    #include <ctype.h>
13  #include "ml-base.h"  #include "ml-base.h"
14  #include "ml-limits.h"  #include "ml-limits.h"
15  #include "cache-flush.h"  #include "cache-flush.h"
# Line 34  Line 35 
35    
36    
37  /* local routines */  /* local routines */
38  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *bootlist);  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *bootlist,
39                                int *max_boot_path_len_ptr);
40  PVT FILE *OpenBinFile (const char *fname, bool_t isBinary);  PVT FILE *OpenBinFile (const char *fname, bool_t isBinary);
41  PVT void ReadBinFile (FILE *file, void *buf, int nbytes, const char *fname);  PVT void ReadBinFile (FILE *file, void *buf, int nbytes, const char *fname);
42  PVT void LoadBinFile (ml_state_t *msp, char *fname);  PVT void LoadBinFile (ml_state_t *msp, char *fname);
# Line 51  Line 53 
53  void BootML (const char *bootlist, heap_params_t *heapParams)  void BootML (const char *bootlist, heap_params_t *heapParams)
54  {  {
55      ml_state_t  *msp;      ml_state_t  *msp;
56      char        fname[MAX_BOOT_PATH_LEN];      int         max_boot_path_len;
57        char        *fname;
58      int         rts_init = 0;      int         rts_init = 0;
59    
60      msp = AllocMLState (TRUE, heapParams);      msp = AllocMLState (TRUE, heapParams);
# Line 65  Line 68 
68      AllocGlobals (msp);      AllocGlobals (msp);
69    
70    /* construct the list of files to be loaded */    /* construct the list of files to be loaded */
71      BinFileList = BuildFileList (msp, bootlist);      BinFileList = BuildFileList (msp, bootlist, &max_boot_path_len);
72    
73      /* this space is ultimately wasted */
74        if ((fname = malloc (max_boot_path_len)) == NULL)
75          Die ("unable to allocate space for boot file names");
76    
77    /* boot the system */    /* boot the system */
78      while (BinFileList != LIST_nil) {      while (BinFileList != LIST_nil) {
79          /* need to make a copy of the path name because LoadBinFile is
80           * going to scribble into it */
81          strcpy(fname, STR_MLtoC(LIST_hd(BinFileList)));          strcpy(fname, STR_MLtoC(LIST_hd(BinFileList)));
82          BinFileList = LIST_tl(BinFileList);          BinFileList = LIST_tl(BinFileList);
83          if (fname[0] == '#')          if (fname[0] == '#')
# Line 102  Line 111 
111   * 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
112   * heap.   * heap.
113   */   */
114  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *bootlist)  PVT ml_val_t BuildFileList (ml_state_t *msp, const char *bootlist, int *mbplp)
115  {  {
116      FILE        *listF;      FILE        *listF;
117      ml_val_t    fileNames[MAX_NUM_BOOT_FILES];      ml_val_t    *fileNames = NULL;
118        char        *nameBuf = NULL;
119        int         max_num_boot_files = MAX_NUM_BOOT_FILES;
120        int         max_boot_path_len = MAX_BOOT_PATH_LEN;
121      int         i, j, numFiles;      int         i, j, numFiles;
     char        nameBuf[MAX_BOOT_PATH_LEN];  
122      ml_val_t    fileList;      ml_val_t    fileList;
123    # define SIZE_BUF_LEN   128     /* this should be plenty for two numbers */
124        char        sizeBuf[SIZE_BUF_LEN];
125        char        c;
126    
127      numFiles = 0;      numFiles = 0;
128    
129      listF = OpenBinFile (bootlist, FALSE);      listF = OpenBinFile (bootlist, FALSE);
130    
131      if (listF != NULL) {      if (listF != NULL) {
132          c = getc (listF);
133          if (c == EOF)
134            Die ("bootlist file \"%s\" is empty", bootlist);
135          if (c == '%') {
136            if (fgets (sizeBuf, SIZE_BUF_LEN, listF) != NIL(char *)) {
137              /* hardly any checking here... */
138              char *space = strchr (sizeBuf, ' ');
139              *space = '\0';
140              max_num_boot_files = strtoul (sizeBuf, NULL, 0);
141              max_boot_path_len = strtoul (space+1, NULL, 0) + 2;
142            } else
143              Die ("unable to read first line in \"%s\" after %%", bootlist);
144          } else {
145            /* size spec is missing -- use defaults */
146            ungetc (c, listF);
147          }
148    
149          *mbplp = max_boot_path_len; /* tell the calling function... */
150    
151          if ((nameBuf = malloc (max_boot_path_len)) == NULL)
152            Die ("unable to allocate space for boot file names");
153    
154          if ((fileNames = malloc (max_num_boot_files * sizeof (char *))) == NULL)
155            Die ("unable to allocate space for boot file name table");
156    
157        /* read in the file names, converting them to ML strings. */        /* read in the file names, converting them to ML strings. */
158          while (fgets (nameBuf, MAX_BOOT_PATH_LEN, listF) != NIL(char *)) {          while (fgets (nameBuf, max_boot_path_len, listF) != NIL(char *)) {
159              j = strlen(nameBuf)-1;              j = strlen(nameBuf)-1;
160              if (nameBuf[j] == '\n') nameBuf[j] = '\0';  /* remove "\n" */              if (nameBuf[j] == '\n') nameBuf[j] = '\0';  /* remove "\n" */
161              if (numFiles < MAX_NUM_BOOT_FILES)              if (numFiles < max_num_boot_files)
162                  fileNames[numFiles++] = ML_CString(msp, nameBuf);                  fileNames[numFiles++] = ML_CString(msp, nameBuf);
163              else              else
164                  Die ("too many files\n");                  Die ("too many files\n");
# Line 130  Line 171 
171          LIST_cons(msp, fileList, fileNames[i], fileList);          LIST_cons(msp, fileList, fileNames[i], fileList);
172      }      }
173    
174        /* these guys are no longer needed from now on */
175        if (fileNames)
176          free (fileNames);
177        if (nameBuf)
178          free (nameBuf);
179    
180      return fileList;      return fileList;
181    
182  } /* end of BuildFileList */  } /* end of BuildFileList */
# Line 315  Line 362 
362  PVT void LoadBinFile (ml_state_t *msp, char *fname)  PVT void LoadBinFile (ml_state_t *msp, char *fname)
363  {  {
364      FILE            *file;      FILE            *file;
365      int             i, exportSzB, remainingCode, importRecLen;      int             i, remainingCode, importRecLen;
366      bool_t          isDataSeg;      int             exportSzB = 0;
367      ml_val_t        codeObj, importRec, closure, val;      ml_val_t        codeObj, importRec, closure, val;
368      binfile_hdr_t   hdr;      binfile_hdr_t   hdr;
369      pers_id_t       exportPerID;      pers_id_t       exportPerID;
# Line 396  Line 443 
443      }      }
444      else if (hdr.exportCnt != 0)      else if (hdr.exportCnt != 0)
445          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);
     else  
         exportSzB = 0;  
446    
447    /* seek to code section */    /* seek to code section */
448      {      {
# Line 533  Line 578 
578          if (memcmp((char *)perID, STR_MLtoC(id), PERID_LEN) == 0)          if (memcmp((char *)perID, STR_MLtoC(id), PERID_LEN) == 0)
579              return (REC_SEL(p, 1));              return (REC_SEL(p, 1));
580      }      }
   
581      {      {
582          char    buf[64];          char    buf[64];
583          ShowPerID (buf, perID);          ShowPerID (buf, perID);
584          Die ("unable to find PerID %s", buf);          Die ("unable to find PerID %s", buf);
585      }      }
   
586  } /* end of LookupPerID */  } /* end of LookupPerID */
587    
588    

Legend:
Removed from v.568  
changed lines
  Added in v.569

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