Fixing up doxygen comments
[tpg/acess2.git] / Kernel / system.c
index a720add..da1dc92 100644 (file)
@@ -32,31 +32,32 @@ typedef struct
 }      tConfigCommand;
 
 // === IMPORTS ===
-extern int     Modules_LoadBuiltins();
-//extern int   PCI_Install();
-extern void    DMA_Install();
+extern void    Arch_LoadBootModules(void);
+extern int     Modules_LoadBuiltins(void);
+extern void    Modules_SetBuiltinParams(char *Name, char *ArgString);
 extern void    Debug_SetKTerminal(char *File);
-extern void    StartupPrint(char *Str);
 
 // === PROTOTYPES ===
-void   System_Init(char *ArgString);
+void   System_Init(char *Commandline);
 void   System_ParseCommandLine(char *ArgString);
+void   System_ExecuteCommandLine(void);
 void   System_ParseVFS(char *Arg);
+void   System_ParseModuleArgs(char *Arg);
 void   System_ParseSetting(char *Arg);
-void   System_ExecuteScript();
+void   System_ExecuteScript(void);
 tConfigFile    *System_Int_ParseFile(char *File);
 
 // === CONSTANTS ===
 const tConfigCommand   caConfigCommands[] = {
-       {"module", 1,2, 0, Module_LoadFile, {(Uint)"",0}},      // Load a module from a file
-       {"spawn", 1,1, 0, Proc_Spawn, {0}},             // Spawn a process
+       {"module",  1,2, 00, Module_LoadFile, {(Uint)"",0}},    // Load a module from a file
+       {"spawn",   1,1, 00, Proc_Spawn, {0}},          // Spawn a process
        // --- VFS ---
-       {"mount", 3,4, 0, VFS_Mount, {(Uint)"",0}},             // Mount a device
-       {"symlink", 2,2, 0, VFS_Symlink, {0}},  // Create a Symbolic Link
-       {"mkdir", 1,1, 0, VFS_MkDir, {0}},              // Create a Directory
-       {"open", 1,2, 0, VFS_Open, {VFS_OPENFLAG_READ,0}},      // Open a file
-       {"close", 1,1, 0x1, VFS_Close, {0}},    // Close an open file
-       {"ioctl", 3,3, 0x3, VFS_IOCtl, {0}},    // Call an IOCtl
+       {"mount",   3,4, 00, VFS_Mount, {(Uint)"",0}},          // Mount a device
+       {"symlink", 2,2, 00, VFS_Symlink, {0}}, // Create a Symbolic Link
+       {"mkdir",   1,1, 00, VFS_MkDir, {0}},           // Create a Directory
+       {"open",    1,2, 00, VFS_Open,  {VFS_OPENFLAG_READ,0}}, // Open a file
+       {"close",   1,1, 01, VFS_Close, {0}},   // Close an open file
+       {"ioctl",   3,3, 03, VFS_IOCtl, {0}},   // Call an IOCtl
        
        {"", 0,0, 0, NULL, {0}}
 };
@@ -64,20 +65,29 @@ const tConfigCommand        caConfigCommands[] = {
 
 // === GLOBALS ===
 char   *gsConfigScript = "/Acess/Conf/BootConf.cfg";
+char   *argv[32];
+ int   argc;
 
 // === CODE ===
-void System_Init(char *ArgString)
-{      
-       // Set the debug to be echoed to the terminal
-       StartupPrint("Kernel now echoes to VT7 (Ctrl-Alt-F8)");
-       Debug_SetKTerminal("/Devices/VTerm/7");
+void System_Init(char *CommandLine)
+{
+       // Parse Kernel's Command Line
+       System_ParseCommandLine(CommandLine);
        
-       // - Parse Kernel's Command Line
-       System_ParseCommandLine(ArgString);
+       // Initialise modules
+       Log_Log("Config", "Initialising builtin modules...");
+       Modules_LoadBuiltins();
+       Arch_LoadBootModules();
+       
+       System_ExecuteCommandLine();
        
        // - Execute the Config Script
        Log_Log("Config", "Executing config script...");
        System_ExecuteScript();
+       
+       // Set the debug to be echoed to the terminal
+       Log_Log("Config", "Kernel now echoes to VT7 (Ctrl-Alt-F8)");
+       Debug_SetKTerminal("/Devices/VTerm/7");
 }
 
 /**
@@ -86,12 +96,11 @@ void System_Init(char *ArgString)
  */
 void System_ParseCommandLine(char *ArgString)
 {
-       char    *argv[32];
-        int    argc;
         int    i;
        char    *str;
        
-       Log_Log("Config", "Kernel Invocation \"%s\"", ArgString);
+       Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
+       Log_Log("Config", "Kernel Invocation '0x%x 0x%x'", ArgString[0], ArgString[1]);
        
        // --- Get Arguments ---
        str = ArgString;
@@ -102,13 +111,13 @@ void System_ParseCommandLine(char *ArgString)
                // Check for the end of the string
                if(*str == '\0') {      argc--; break;} 
                argv[argc] = str;
-               while(*str && *str != ' ')
-               {
-                       /*if(*str == '"') {
-                               while(*str && !(*str == '"' && str[-1] != '\\'))
-                                       str ++;
-                       }*/
-                       str++;
+               if(*str == '"') {
+                       while(*str && !(*str == '"' && str[-1] != '\\'))
+                               str ++;
+               }
+               else {
+                       while(*str && *str != ' ')
+                               str++;
                }
                if(*str == '\0')        break;  // Check for EOS
                *str = '\0';    // Cap off argument string
@@ -117,13 +126,45 @@ void System_ParseCommandLine(char *ArgString)
        if(argc < 32)
                argc ++;        // Count last argument
        
-       // --- Parse Arguments ---
-       for( i = 1; i < argc; i++ )
+       // --- Parse Arguments (Pass 1) ---
+       for( i = 0; i < argc; i++ )
        {
-               if( argv[i][0] == '/' )
-                       System_ParseVFS( argv[i] );
-               else
+               switch(argv[i][0])
+               {
+               // --- VFS ---
+               // Ignored on this pass
+               case '/':
+                       break;
+               
+               // --- Module Paramaters ---
+               // -VTerm:Width=640,Height=480,Scrollback=2
+               case '-':
+                       System_ParseModuleArgs( argv[i] );
+                       break;
+               // --- Config Options ---
+               // SCRIPT=/Acess/Conf/BootConf.cfg
+               default:
                        System_ParseSetting( argv[i] );
+                       break;
+               }
+       }
+}
+
+void System_ExecuteCommandLine(void)
+{
+        int    i;
+       for( i = 0; i < argc; i++ )
+       {
+               Log("argv[%i] = '%s'", i, argv[i]);
+               switch(argv[i][0])
+               {
+               // --- VFS ---
+               // Mount    /System=ext2:/Devices/ATA/A1
+               // Symlink  /Acess=/System/Acess2
+               case '/':
+                       System_ParseVFS( argv[i] );
+                       break;
+               }
        }
 }
 
@@ -179,6 +220,38 @@ void System_ParseVFS(char *Arg)
        }
 }
 
+/**
+ * \brief Parse a module argument string
+ * \param Arg  Argument string
+ */
+void System_ParseModuleArgs(char *Arg)
+{
+       char    *name, *args;
+        int    i;
+       
+       // Remove '-'   
+       name = Arg + 1;
+       
+       // Find the start of the args
+       i = strpos(name, ':');
+       if( i == -1 ) {
+               Log_Warning("Config", "Module spec with no arguments");
+               #if 1
+               return ;
+               #else
+               i = strlen(name);
+               args = name + i;
+               #endif
+       }
+       else {
+               name[i] = '\0';
+               args = name + i + 1;
+       }
+       
+       Log_Log("Config", "Setting boot parameters for '%s' to '%s'", name, args);
+       Modules_SetBuiltinParams(name, args);
+}
+
 /**
  * \fn void System_ParseSetting(char *Arg)
  */
@@ -206,7 +279,10 @@ void System_ParseSetting(char *Arg)
                
                if(strcmp(Arg, "SCRIPT") == 0) {
                        Log_Log("Config", "Config Script: '%s'", value);
-                       gsConfigScript = value;
+                       if(strlen(value) == 0)
+                               gsConfigScript = NULL;
+                       else
+                               gsConfigScript = value;
                } else {
                        Log_Warning("Config", "Kernel config setting '%s' is not recognised", Arg);
                }
@@ -216,8 +292,9 @@ void System_ParseSetting(char *Arg)
 
 /**
  * \fn void System_ExecuteScript()
+ * \brief Reads and parses the boot configuration script
  */
-void System_ExecuteScript()
+void System_ExecuteScript(void)
 {
         int    fp;
         int    fLen = 0;
@@ -238,10 +315,11 @@ void System_ExecuteScript()
                return;
        }
        
-       // Read into memory buffer
+       // Get length
        VFS_Seek(fp, 0, SEEK_END);
        fLen = VFS_Tell(fp);
        VFS_Seek(fp, 0, SEEK_SET);
+       // Read into memory buffer
        fData = malloc(fLen+1);
        VFS_Read(fp, fLen, fData);
        fData[fLen] = '\0';
@@ -415,6 +493,8 @@ void System_ExecuteScript()
                }
                free( file->Lines[i].Parts );
        }
+       
+       // Free data
        free( file );
        free( fData );
 }

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