Misc Changes, Added Logging Subsystem, Fixes to InitRD, Working on RTL8139 driver
[tpg/acess2.git] / Kernel / system.c
index 66630ce..463b4e0 100644 (file)
@@ -3,7 +3,8 @@
  * Architecture Independent System Init
  * system.c
  */
-#include <common.h>
+#define DEBUG  0
+#include <acess.h>
 
 // === TYPES ===
 typedef struct
@@ -20,7 +21,7 @@ typedef struct
 
 // === IMPORTS ===
 extern int     Modules_LoadBuiltins();
-extern int     PCI_Install();
+//extern int   PCI_Install();
 extern void    DMA_Install();
 extern void    Debug_SetKTerminal(char *File);
 extern void    StartupPrint(char *Str);
@@ -38,18 +39,10 @@ char        *gsConfigScript = "/Acess/Conf/BootConf.cfg";
 
 // === CODE ===
 void System_Init(char *ArgString)
-{
-       // - Start Builtin Drivers & Filesystems
-       StartupPrint("Scanning PCI Bus...");
-       PCI_Install();
-       StartupPrint("Loading DMA...");
-       DMA_Install();
-       StartupPrint("Loading staticly compiled modules...");
-       Modules_LoadBuiltins();
-       
+{      
        // Set the debug to be echoed to the terminal
-       StartupPrint("Kernel now echoes to VT6 (Ctrl-Alt-F7)");
-       Debug_SetKTerminal("/Devices/VTerm/6");
+       StartupPrint("Kernel now echoes to VT7 (Ctrl-Alt-F8)");
+       Debug_SetKTerminal("/Devices/VTerm/7");
        
        // - Parse Kernel's Command Line
        System_ParseCommandLine(ArgString);
@@ -76,8 +69,10 @@ void System_ParseCommandLine(char *ArgString)
        str = ArgString;
        for( argc = 0; argc < 32; argc++ )
        {
-               while(*str == ' ')      str++;  // Eat Whitespace
-               if(*str == '\0') {      argc--; break;} // End of string
+               // Eat Whitespace
+               while(*str == ' ')      str++;
+               // Check for the end of the string
+               if(*str == '\0') {      argc--; break;} 
                argv[argc] = str;
                while(*str && *str != ' ')
                {
@@ -87,7 +82,7 @@ void System_ParseCommandLine(char *ArgString)
                        }*/
                        str++;
                }
-               if(*str == '\0')        break;  // End of string
+               if(*str == '\0')        break;  // Check for EOS
                *str = '\0';    // Cap off argument string
                str ++; // and increment the string pointer
        }
@@ -171,10 +166,10 @@ void System_ParseSetting(char *Arg)
        // Check for boolean/flag (no '=')
        if(*value == '\0')
        {
-               if(strcmp(Arg, "") == 0) {
-               } else {
+               //if(strcmp(Arg, "") == 0) {
+               //} else {
                        Warning("Kernel flag '%s' is not recognised", Arg);
-               }
+               //}
        }
        else
        {
@@ -198,7 +193,7 @@ void System_ExecuteScript()
 {
         int    fp;
         int    fLen = 0;
-        int    i = 0;
+        int    i;
        char    *fData;
        tConfigFile     *file;
        tConfigLine     *line;
@@ -224,14 +219,15 @@ void System_ExecuteScript()
        // Parse File
        file = System_Int_ParseFile(fData);
        
-       // Loop lines
+       // Parse each line
        for( i = 0; i < file->nLines; i++ )
        {
                line = &file->Lines[i];
                if( line->nParts == 0 ) continue;       // Skip blank
                
-               // Mount
-               if( strcmp(line->Parts[0], "mount") == 0 ) {
+               // Mount Device
+               if( strcmp(line->Parts[0], "mount") == 0 )
+               {
                        if( line->nParts != 4 ) {
                                Warning("Configuration command 'mount' requires 3 arguments, %i given",
                                        line->nParts-1);
@@ -242,8 +238,9 @@ void System_ExecuteScript()
                        //! \todo Use an optional 4th argument for the options string
                        VFS_Mount(line->Parts[1], line->Parts[2], line->Parts[3], "");
                }
-               // Module
-               else if(strcmp(line->Parts[0], "module") == 0) {
+               // Load a Module
+               else if(strcmp(line->Parts[0], "module") == 0)
+               {
                        if( line->nParts < 2 || line->nParts > 3 ) {
                                Warning("Configuration command 'module' requires 1 or 2 arguments, %i given",
                                        line->nParts-1);
@@ -254,8 +251,9 @@ void System_ExecuteScript()
                        else
                                Module_LoadFile(line->Parts[1], "");
                }
-               // UDI Module
-               else if(strcmp(line->Parts[0], "udimod") == 0) {
+               // Load a UDI Module
+               else if(strcmp(line->Parts[0], "udimod") == 0)
+               {
                        if( line->nParts != 2 ) {
                                Warning("Configuration command 'udimod' requires 1 argument, %i given",
                                        line->nParts-1);
@@ -264,8 +262,9 @@ void System_ExecuteScript()
                        Log("[CFG  ] Load UDI Module '%s'", line->Parts[1]);
                        Module_LoadFile(line->Parts[1], "");
                }
-               // EDI Module
-               else if(strcmp(line->Parts[0], "edimod") == 0) {
+               // Load a EDI Module
+               else if(strcmp(line->Parts[0], "edimod") == 0)
+               {
                        if( line->nParts != 2 ) {
                                Warning("Configuration command 'edimod' requires 1 argument, %i given",
                                        line->nParts-1);
@@ -274,8 +273,9 @@ void System_ExecuteScript()
                        Log("[CFG  ] Load EDI Module '%s'", line->Parts[1]);
                        Module_LoadFile(line->Parts[1], "");
                }
-               // Symbolic Link
-               else if(strcmp(line->Parts[0], "symlink") == 0) {
+               // Create a Symbolic Link
+               else if(strcmp(line->Parts[0], "symlink") == 0)
+               {
                        if( line->nParts != 3 ) {
                                Warning("Configuration command 'symlink' requires 2 arguments, %i given",
                                        line->nParts-1);
@@ -285,9 +285,10 @@ void System_ExecuteScript()
                                line->Parts[1], line->Parts[2]);
                        VFS_Symlink(line->Parts[1], line->Parts[2]);
                }
-               // Create Directory
-               else if(strcmp(line->Parts[0], "mkdir") == 0) {
-                       if( line->nParts != 3 ) {
+               // Create a Directory
+               else if(strcmp(line->Parts[0], "mkdir") == 0)
+               {
+                       if( line->nParts != 2 ) {
                                Warning("Configuration command 'mkdir' requires 1 argument, %i given",
                                        line->nParts-1);
                                continue;
@@ -296,8 +297,9 @@ void System_ExecuteScript()
                        VFS_MkDir(line->Parts[1]);
                }
                // Spawn a process
-               else if(strcmp(line->Parts[0], "spawn") == 0) {
-                       if( line->nParts != 3 ) {
+               else if(strcmp(line->Parts[0], "spawn") == 0)
+               {
+                       if( line->nParts != 2 ) {
                                Warning("Configuration command 'spawn' requires 1 argument, %i given",
                                        line->nParts-1);
                                continue;
@@ -315,6 +317,7 @@ void System_ExecuteScript()
        
        // Clean up after ourselves
        for( i = 0; i < file->nLines; i++ ) {
+               if( file->Lines[i].nParts == 0 )        continue;       // Skip blank
                free( file->Lines[i].Parts );
        }
        free( file );
@@ -332,10 +335,12 @@ tConfigFile       *System_Int_ParseFile(char *FileData)
 {
        char    *ptr;
        char    *start;
-        int    nLines = 0;
+        int    nLines = 1;
         int    i, j;
        tConfigFile     *ret;
        
+       ENTER("pFileData", FileData);
+       
        // Prescan and count the number of lines
        for(ptr = FileData; *ptr; ptr++)
        {               
@@ -346,23 +351,14 @@ tConfigFile       *System_Int_ParseFile(char *FileData)
                        continue;
                }
                
-               #if 0   // Don't handle windows style EOLs
-               if(ptr[-1] == '\r')
-               {
-                       if( &ptr[-1] == FileData ) {
-                               nLines ++;
-                               continue;
-                       }
-                       if(ptr[-2] == '\\')     continue;
-               }
-               #endif
-               
                // Escaped EOL
                if(ptr[-1] == '\\')     continue;
                
                nLines ++;
        }
        
+       LOG("nLines = %i", nLines);
+       
        // Ok so we have `nLines` lines, now to allocate our return
        ret = malloc( sizeof(tConfigFile) + sizeof(tConfigLine)*nLines );
        ret->nLines = nLines;
@@ -382,12 +378,19 @@ tConfigFile       *System_Int_ParseFile(char *FileData)
                for(;;)
                {
                        // Read leading whitespace
-                       while( *ptr && (*ptr == '\t' || *ptr == ' ') )  ptr++;
+                       while( *ptr == '\t' || *ptr == ' ' )    ptr++;
                        
                        // End of line/file
-                       if( *ptr == '\0' || *ptr == '\n' )      break;
+                       if( *ptr == '\0' || *ptr == '\n' ) {
+                               if(*ptr == '\n')        ptr ++;
+                               break;
+                       }
                        // Comment
-                       if( *ptr == '#' || *ptr == ';' )        break;
+                       if( *ptr == '#' || *ptr == ';' ) {
+                               while( *ptr && *ptr != '\n' )   ptr ++;
+                               if(*ptr == '\n')        ptr ++;
+                               break;
+                       }
                        
                        ret->Lines[i].nParts ++;
                        // Quoted
@@ -398,10 +401,17 @@ tConfigFile       *System_Int_ParseFile(char *FileData)
                                continue;
                        }
                        // Unquoted
-                       while( *ptr && !(*ptr == '\t' || *ptr == ' ') )
+                       while( *ptr && !(*ptr == '\t' || *ptr == ' ') && *ptr != '\n' )
                                ptr++;
                }
                
+               LOG("ret->Lines[%i].nParts = %i", i, ret->Lines[i].nParts);
+               
+               if( ret->Lines[i].nParts == 0 ) {
+                       ret->Lines[i].Parts = NULL;
+                       continue;
+               }
+               
                // Allocate part list
                ret->Lines[i].Parts = malloc( sizeof(char*) * ret->Lines[i].nParts );
                
@@ -409,13 +419,19 @@ tConfigFile       *System_Int_ParseFile(char *FileData)
                for( ptr = start, j = 0; ; j++ )
                {
                        // Read leading whitespace
-                       while( *ptr && (*ptr == '\t' || *ptr == ' ') )  ptr++;
+                       while( *ptr == '\t' || *ptr == ' ' )    ptr++;
                        
                        // End of line/file
-                       if( *ptr == '\0' || *ptr == '\n' )      break;
+                       if( *ptr == '\0' || *ptr == '\n' ) {
+                               if(*ptr == '\n')        ptr ++;
+                               break;
+                       }
                        // Comment
-                       if( *ptr == '#' || *ptr == ';' )        break;
-                       
+                       if( *ptr == '#' || *ptr == ';' ) {
+                               while( *ptr && *ptr != '\n' )   ptr ++;
+                               if(*ptr == '\n')        ptr ++;
+                               break;
+                       }
                        
                        ret->Lines[i].Parts[j] = ptr;
                        
@@ -427,16 +443,27 @@ tConfigFile       *System_Int_ParseFile(char *FileData)
                        }
                        // Unquoted
                        else {
-                               while( *ptr && !(*ptr == '\t' || *ptr == ' ') )
+                               while( *ptr != '\t' && *ptr != ' ' && *ptr != '\n' )
                                        ptr++;
                        }
                        
                        // Break if we have reached NULL
-                       if( *ptr == '\0' )      break;
+                       if( *ptr == '\0' ) {
+                               LOG("ret->Lines[%i].Parts[%i] = '%s'", i, j, ret->Lines[i].Parts[j]);
+                               break;
+                       }
+                       if( *ptr == '\n' ) {
+                               *ptr = '\0';
+                               LOG("ret->Lines[%i].Parts[%i] = '%s'", i, j, ret->Lines[i].Parts[j]);
+                               ptr ++;
+                               break;
+                       }
                        *ptr = '\0';    // Cap off string
+                       LOG("ret->Lines[%i].Parts[%i] = '%s'", i, j, ret->Lines[i].Parts[j]);
                        ptr ++; // And increment for the next round
                }
        }
        
+       LEAVE('p', ret);
        return ret;
 }

UCC git Repository :: git.ucc.asn.au