3 * Architecture Independent System Init
9 extern int Modules_LoadBuiltins();
10 extern int PCI_Install();
11 extern void DMA_Install();
12 extern void Debug_SetKTerminal(char *File);
13 extern void StartupPrint(char *Str);
16 void System_Init(char *ArgString);
17 void System_ParseCommandLine(char *ArgString);
18 void System_ParseVFS(char *Arg);
19 void System_ParseSetting(char *Arg);
20 void System_ExecuteScript();
21 int System_Int_GetString(char *Str, char **Dest);
24 char *gsConfigScript = "/Acess/Conf/BootConf.cfg";
27 void System_Init(char *ArgString)
29 // - Start Builtin Drivers & Filesystems
30 StartupPrint("Scanning PCI Bus...");
32 StartupPrint("Loading DMA...");
34 StartupPrint("Loading staticly compiled modules...");
35 Modules_LoadBuiltins();
37 // Set the debug to be echoed to the terminal
38 StartupPrint("Kernel now echoes to VT6 (Ctrl-Alt-F7)");
39 Debug_SetKTerminal("/Devices/VTerm/6");
41 // - Parse Kernel's Command Line
42 System_ParseCommandLine(ArgString);
44 // - Execute the Config Script
45 Log("Executing config script...");
46 System_ExecuteScript();
50 * \fn void System_ParseCommandLine(char *ArgString)
51 * \brief Parses the kernel's command line and sets the environment
53 void System_ParseCommandLine(char *ArgString)
60 Log("Kernel Command Line: \"%s\"", ArgString);
62 // --- Get Arguments ---
64 for( argc = 0; argc < 32; argc++ )
66 while(*str == ' ') str++; // Eat Whitespace
67 if(*str == '\0') { argc--; break;} // End of string
69 while(*str && *str != ' ')
72 while(*str && !(*str == '"' && str[-1] != '\\'))
77 if(*str == '\0') break; // End of string
78 *str = '\0'; // Cap off argument string
79 str ++; // and increment the string pointer
82 argc ++; // Count last argument
84 // --- Parse Arguments ---
85 for( i = 1; i < argc; i++ )
87 if( argv[i][0] == '/' )
88 System_ParseVFS( argv[i] );
90 System_ParseSetting( argv[i] );
95 * \fn void System_ParseVFS(char *Arg)
97 void System_ParseVFS(char *Arg)
103 // Search for the '=' token
104 while( *value && *value != '=' )
107 // Check if the equals was found
108 if( *value == '\0' ) {
109 Warning("Expected '=' in the string '%s'", Arg);
114 *value = '\0'; value ++;
116 // Check assignment type
117 // - Symbolic Link <link>=<destination>
120 Log("Symbolic link '%s' pointing to '%s'", Arg, value);
121 VFS_Symlink(Arg, value);
123 // - Mount <mountpoint>=<fs>:<device>
128 while(*dev && *dev != ':') dev++;
134 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
135 Log("Creating directory '%s'", Arg, value);
141 Log("Mounting '%s' to '%s' ('%s')", dev, Arg, value);
142 VFS_Mount(dev, Arg, value, "");
147 * \fn void System_ParseSetting(char *Arg)
149 void System_ParseSetting(char *Arg)
154 // Search for the '=' token
155 while( *value && *value != '=' )
158 // Check for boolean/flag (no '=')
161 if(strcmp(Arg, "") == 0) {
163 Warning("Kernel flag '%s' is not recognised", Arg);
168 *value = '\0'; // Remove '='
169 value ++; // and eat it's position
171 if(strcmp(Arg, "SCRIPT") == 0) {
172 Log("Config Script: '%s'", value);
173 gsConfigScript = value;
175 Warning("Kernel config setting '%s' is not recognised", Arg);
182 * \fn void System_ExecuteScript()
184 void System_ExecuteScript()
188 int i = 0, lineStart;
189 char *sArg1, *sArg2, *sArg3;
193 fp = VFS_Open(gsConfigScript, VFS_OPENFLAG_READ);
195 Warning("[CFG] Passed script '%s' does not exist", gsConfigScript);
199 // Read into memory buffer
200 VFS_Seek(fp, 0, SEEK_END);
202 VFS_Seek(fp, 0, SEEK_SET);
203 fData = malloc(fLen+1);
204 VFS_Read(fp, fLen, fData);
211 sArg1 = sArg2 = sArg3 = NULL;
214 // Clear leading whitespace and find empty lines
215 while(i < fLen && (fData[i] == ' ' || fData[i]=='\t')) i ++;
217 if(fData[i] == '\n') {
223 if(fData[i] == ';' || fData[i] == '#') {
224 while(i < fLen && fData[i] != '\n') i ++;
231 if(strncmp("mount ", fData+i, 6) == 0) {
233 i += System_Int_GetString(fData+i, &sArg1);
234 if(!sArg1) goto read2eol;
235 i += System_Int_GetString(fData+i, &sArg2);
236 if(!sArg2) goto read2eol;
237 i += System_Int_GetString(fData+i, &sArg3);
238 if(!sArg3) goto read2eol;
239 //Log("[CFG ] Mount '%s' to '%s' (%s)\n", sArg1, sArg2, sArg3);
240 VFS_Mount(sArg1, sArg2, sArg3, "");
243 else if(strncmp("module ", fData+i, 6) == 0) {
246 i += System_Int_GetString(fData+i, &sArg1);
247 if(!sArg1) goto read2eol;
248 Module_LoadFile(sArg1, ""); //!\todo Use the rest of the line as the argument string
251 else if(strncmp("edimod ", fData+i, 6) == 0) {
253 i += System_Int_GetString(fData+i, &sArg1);
254 if(!sArg1) goto read2eol;
255 Log("[CFG ] Load EDI Module '%s'", sArg1);
256 Module_LoadFile(sArg1, "");
259 else if(strncmp("symlink ", fData+i, 7) == 0) {
261 i += System_Int_GetString(fData+i, &sArg1);
262 if(!sArg1) goto read2eol;
263 i += System_Int_GetString(fData+i, &sArg2);
264 if(!sArg2) goto read2eol;
265 Log("[CFG ] Symlink '%s' pointing to '%s'", sArg1, sArg2);
266 VFS_Symlink(sArg1, sArg2);
269 else if(strncmp("mkdir ", fData+i, 5) == 0) {
271 i += System_Int_GetString(fData+i, &sArg1);
272 if(!sArg1) goto read2eol;
273 Log("[CFG ] New Directory '%s'", sArg1);
277 else if(strncmp("spawn ", fData+i, 5) == 0) {
279 i += System_Int_GetString(fData+i, &sArg1);
280 if(!sArg1) goto read2eol;
281 Log("[CFG ] Starting '%s' as a new task", sArg1);
285 Warning("Unknown configuration command, Line: '%s'", fData+i);
289 if(sArg1) free(sArg1);
290 if(sArg2) free(sArg2);
291 if(sArg3) free(sArg3);
293 while(i < fLen && fData[i] != '\n') i++;
300 * \fn int System_Int_GetString(char *Str, char **Dest)
301 * \brief Gets a string from another
303 * \param Str Input String
304 * \param Dest Pointer to output pointer
305 * \return Characters eaten from input
307 int System_Int_GetString(char *Str, char **Dest)
313 //LogF("GetString: (Str='%s', Dest=0x%x)\n", Str, Dest);
315 while(Str[pos] == ' ' || Str[pos] == '\t') pos++;
316 if(Str[pos] == '\n' || Str[pos] == '\0') {
326 while(Str[pos] != '"') pos++;
329 *Dest = malloc( len + 1 );
330 memcpy( *Dest, Str+start, len );
333 //LogF("GetString: RETURN *Dest = '%s'\n", *Dest);
339 // Non-Quoted String - Whitespace deliminated
341 while(Str[pos] != ' ' && Str[pos] != '\t' && Str[pos] != '\n') pos++;
344 //LogF(" GetString: len = %i\n", len);
345 *Dest = malloc( len + 1 );
346 memcpy( *Dest, Str+start, len );
349 //LogF("GetString: RETURN *Dest = '%s'\n", *Dest);