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);
15 void System_Init(char *ArgString);
16 void System_ParseCommandLine(char *ArgString);
17 void System_ParseVFS(char *Arg);
18 void System_ParseSetting(char *Arg);
19 void System_ExecuteScript();
20 int System_Int_GetString(char *Str, char **Dest);
23 char *gsConfigScript = "/Acess/Conf/BootConf.cfg";
26 void System_Init(char *ArgString)
28 // - Start Builtin Drivers & Filesystems
31 Modules_LoadBuiltins();
33 // Set the debug to be echoed to the terminal
34 Debug_SetKTerminal("/Devices/VTerm/6");
36 // - Parse Kernel's Command Line
37 System_ParseCommandLine(ArgString);
39 // - Execute the Config Script
40 Log("Executing config script...");
41 System_ExecuteScript();
45 * \fn void System_ParseCommandLine(char *ArgString)
46 * \brief Parses the kernel's command line and sets the environment
48 void System_ParseCommandLine(char *ArgString)
55 Log("Kernel Command Line: \"%s\"", ArgString);
57 // --- Get Arguments ---
59 for( argc = 0; argc < 32; argc++ )
61 while(*str == ' ') str++; // Eat Whitespace
62 if(*str == '\0') { argc--; break;} // End of string
64 while(*str && *str != ' ')
67 while(*str && !(*str == '"' && str[-1] != '\\'))
72 if(*str == '\0') break; // End of string
73 *str = '\0'; // Cap off argument string
74 str ++; // and increment the string pointer
77 argc ++; // Count last argument
79 // --- Parse Arguments ---
80 for( i = 1; i < argc; i++ )
82 if( argv[i][0] == '/' )
83 System_ParseVFS( argv[i] );
85 System_ParseSetting( argv[i] );
90 * \fn void System_ParseVFS(char *Arg)
92 void System_ParseVFS(char *Arg)
98 // Search for the '=' token
99 while( *value && *value != '=' )
102 // Check if the equals was found
103 if( *value == '\0' ) {
104 Warning("Expected '=' in the string '%s'", Arg);
109 *value = '\0'; value ++;
111 // Check assignment type
112 // - Symbolic Link <link>=<destination>
115 Log("Symbolic link '%s' pointing to '%s'", Arg, value);
116 VFS_Symlink(Arg, value);
118 // - Mount <mountpoint>=<fs>:<device>
123 while(*dev && *dev != ':') dev++;
129 if( (fd = VFS_Open(Arg, 0)) == -1 ) {
130 Log("Creating directory '%s'", Arg, value);
136 Log("Mounting '%s' to '%s' ('%s')", dev, Arg, value);
137 VFS_Mount(dev, Arg, value, "");
142 * \fn void System_ParseSetting(char *Arg)
144 void System_ParseSetting(char *Arg)
149 // Search for the '=' token
150 while( *value && *value != '=' )
153 // Check for boolean/flag (no '=')
156 if(strcmp(Arg, "") == 0) {
158 Warning("Kernel flag '%s' is not recognised", Arg);
163 *value = '\0'; // Remove '='
164 value ++; // and eat it's position
166 if(strcmp(Arg, "SCRIPT") == 0) {
167 Log("Config Script: '%s'", value);
168 gsConfigScript = value;
170 Warning("Kernel config setting '%s' is not recognised", Arg);
177 * \fn void System_ExecuteScript()
179 void System_ExecuteScript()
183 int i = 0, lineStart;
184 char *sArg1, *sArg2, *sArg3;
188 fp = VFS_Open(gsConfigScript, VFS_OPENFLAG_READ);
190 Warning("[CFG] Passed script '%s' does not exist", gsConfigScript);
194 // Read into memory buffer
195 VFS_Seek(fp, 0, SEEK_END);
197 VFS_Seek(fp, 0, SEEK_SET);
198 fData = malloc(fLen+1);
199 VFS_Read(fp, fLen, fData);
206 sArg1 = sArg2 = sArg3 = NULL;
209 // Clear leading whitespace and find empty lines
210 while(i < fLen && (fData[i] == ' ' || fData[i]=='\t')) i ++;
212 if(fData[i] == '\n') {
218 if(fData[i] == ';' || fData[i] == '#') {
219 while(i < fLen && fData[i] != '\n') i ++;
226 if(strncmp("mount ", fData+i, 6) == 0) {
228 i += System_Int_GetString(fData+i, &sArg1);
229 if(!sArg1) goto read2eol;
230 i += System_Int_GetString(fData+i, &sArg2);
231 if(!sArg2) goto read2eol;
232 i += System_Int_GetString(fData+i, &sArg3);
233 if(!sArg3) goto read2eol;
234 //Log("[CFG ] Mount '%s' to '%s' (%s)\n", sArg1, sArg2, sArg3);
235 VFS_Mount(sArg1, sArg2, sArg3, "");
238 else if(strncmp("module ", fData+i, 6) == 0) {
241 i += System_Int_GetString(fData+i, &sArg1);
242 if(!sArg1) goto read2eol;
243 Module_LoadFile(sArg1, ""); //!\todo Use the rest of the line as the argument string
246 else if(strncmp("edimod ", fData+i, 6) == 0) {
248 i += System_Int_GetString(fData+i, &sArg1);
249 if(!sArg1) goto read2eol;
250 Log("[CFG ] Load EDI Module '%s'\n", sArg1);
251 Module_LoadFile(sArg1, "");
254 else if(strncmp("symlink ", fData+i, 7) == 0) {
256 i += System_Int_GetString(fData+i, &sArg1);
257 if(!sArg1) goto read2eol;
258 i += System_Int_GetString(fData+i, &sArg2);
259 if(!sArg2) goto read2eol;
260 Log("[CFG ] Symlink '%s' pointing to '%s'\n", sArg1, sArg2);
261 VFS_Symlink(sArg1, sArg2);
264 else if(strncmp("mkdir ", fData+i, 5) == 0) {
266 i += System_Int_GetString(fData+i, &sArg1);
267 if(!sArg1) goto read2eol;
268 Log("[CFG ] New Directory '%s'\n", sArg1);
272 else if(strncmp("spawn ", fData+i, 5) == 0) {
274 i += System_Int_GetString(fData+i, &sArg1);
275 if(!sArg1) goto read2eol;
276 Log("[CFG ] Starting '%s' as a new task\n", sArg1);
280 Warning("Unknown configuration command, Line: '%s'", fData+i);
284 if(sArg1) free(sArg1);
285 if(sArg2) free(sArg2);
286 if(sArg3) free(sArg3);
288 while(i < fLen && fData[i] != '\n') i++;
295 * \fn int System_Int_GetString(char *Str, char **Dest)
296 * \brief Gets a string from another
298 * \param Str Input String
299 * \param Dest Pointer to output pointer
300 * \return Characters eaten from input
302 int System_Int_GetString(char *Str, char **Dest)
308 //LogF("GetString: (Str='%s', Dest=0x%x)\n", Str, Dest);
310 while(Str[pos] == ' ' || Str[pos] == '\t') pos++;
311 if(Str[pos] == '\n' || Str[pos] == '\0') {
321 while(Str[pos] != '"') pos++;
324 *Dest = malloc( len + 1 );
325 memcpy( *Dest, Str+start, len );
328 //LogF("GetString: RETURN *Dest = '%s'\n", *Dest);
334 // Non-Quoted String - Whitespace deliminated
336 while(Str[pos] != ' ' && Str[pos] != '\t' && Str[pos] != '\n') pos++;
339 //LogF(" GetString: len = %i\n", len);
340 *Dest = malloc( len + 1 );
341 memcpy( *Dest, Str+start, len );
344 //LogF("GetString: RETURN *Dest = '%s'\n", *Dest);