X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fsystem.c;h=f346d69c3b070351fb7fe250e314829f850ac769;hb=58c7107eb0a5ae254c135f2eaa6263751f1ebe67;hp=7c5ff32feac923125cc41c24ae53cf60564cc3d3;hpb=b98fbd4e9c71447d81fc9bd643fb174c76346e0f;p=tpg%2Facess2.git diff --git a/Kernel/system.c b/Kernel/system.c index 7c5ff32f..f346d69c 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -23,19 +23,19 @@ typedef struct } tConfigFile; typedef struct { - char *Name; // Name + const char *Name; // Name int MinArgs; // Minimum number of arguments int MaxArgs; // Maximum number of arguments Uint IntArgs; // Bitmap of arguments that should be treated as integers - void *Func; // Function pointer - Uint OptDefaults[N_MAX_ARGS]; // Default values for optional arguments + int Index; // + const char *OptDefaults[N_MAX_ARGS]; // Default values for optional arguments } tConfigCommand; // === IMPORTS === -extern void Arch_LoadBootModules(); -extern int Modules_LoadBuiltins(); +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 Debug_SetKTerminal(const char *File); // === PROTOTYPES === void System_Init(char *Commandline); @@ -48,23 +48,33 @@ void System_ExecuteScript(void); tConfigFile *System_Int_ParseFile(char *File); // === CONSTANTS === +enum eConfigCommands { + CC_LOADMODULE, + CC_SPAWN, + CC_MOUNT, + CC_SYMLINK, + CC_MKDIR, + CC_OPEN, + CC_CLOSE, + CC_IOCTL +}; const tConfigCommand caConfigCommands[] = { - {"module", 1,2, 00, Module_LoadFile, {(Uint)"",0}}, // Load a module from a file - {"spawn", 1,1, 00, Proc_Spawn, {0}}, // Spawn a process + {"module", 1,2, 00, CC_LOADMODULE, {"",NULL}}, // Load a module from a file + {"spawn", 1,1, 00, CC_SPAWN, {NULL}}, // Spawn a process // --- VFS --- - {"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 + {"mount", 3,4, 00, CC_MOUNT, {"",0}}, // Mount a device + {"symlink", 2,2, 00, CC_SYMLINK, {0}}, // Create a Symbolic Link + {"mkdir", 1,1, 00, CC_MKDIR, {0}}, // Create a Directory + {"open", 1,2, 00, CC_OPEN, {(void*)VFS_OPENFLAG_READ,0}}, // Open a file + {"close", 1,1, 01, CC_CLOSE, {0}}, // Close an open file + {"ioctl", 3,3, 03, CC_IOCTL, {0}}, // Call an IOCtl - {"", 0,0, 0, NULL, {0}} + {"", 0,0, 0, 0, {0}} }; #define NUM_CONFIG_COMMANDS (sizeof(caConfigCommands)/sizeof(caConfigCommands[0])) // === GLOBALS === -char *gsConfigScript = "/Acess/Conf/BootConf.cfg"; +const char *gsConfigScript = "/Acess/Conf/BootConf.cfg"; char *argv[32]; int argc; @@ -82,7 +92,7 @@ void System_Init(char *CommandLine) System_ExecuteCommandLine(); // - Execute the Config Script - Log_Log("Config", "Executing config script..."); + Log_Log("Config", "Executing config script '%s'", gsConfigScript); System_ExecuteScript(); // Set the debug to be echoed to the terminal @@ -99,7 +109,7 @@ void System_ParseCommandLine(char *ArgString) int i; char *str; - Log_Log("Config", "Kernel Invocation \"%s\"", ArgString); + Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString); // --- Get Arguments --- str = ArgString; @@ -126,7 +136,7 @@ void System_ParseCommandLine(char *ArgString) argc ++; // Count last argument // --- Parse Arguments (Pass 1) --- - for( i = 1; i < argc; i++ ) + for( i = 0; i < argc; i++ ) { switch(argv[i][0]) { @@ -152,8 +162,9 @@ void System_ParseCommandLine(char *ArgString) void System_ExecuteCommandLine(void) { int i; - for( i = 1; i < argc; i++ ) + for( i = 0; i < argc; i++ ) { + Log("argv[%i] = '%s'", i, argv[i]); switch(argv[i][0]) { // --- VFS --- @@ -219,7 +230,8 @@ void System_ParseVFS(char *Arg) } /** - * \biref Parse a module argument string + * \brief Parse a module argument string + * \param Arg Argument string */ void System_ParseModuleArgs(char *Arg) { @@ -315,6 +327,7 @@ void System_ExecuteScript(void) // Get length VFS_Seek(fp, 0, SEEK_END); fLen = VFS_Tell(fp); + Log_Debug("System", "VFS_Tell(%i) = %i", fp, fLen); VFS_Seek(fp, 0, SEEK_SET); // Read into memory buffer fData = malloc(fLen+1); @@ -335,7 +348,8 @@ void System_ExecuteScript(void) if(line->Parts[0][0] == ':') continue; // Ignore labels // Prescan and eliminate variables - for( j = 1; j < line->nParts; j++ ) { + for( j = 1; j < line->nParts; j++ ) + { Log_Debug("Config", "Arg #%i is '%s'", j, line->Parts[j]); bReplaced[j] = 0; if( line->Parts[j][0] != '$' ) continue; @@ -353,13 +367,16 @@ void System_ExecuteScript(void) bReplaced[j] = 1; } + // Find the command name for( j = 0; j < NUM_CONFIG_COMMANDS; j++ ) { - Uint args[N_MAX_ARGS]; + const char *args[N_MAX_ARGS]; + if(strcmp(line->Parts[0], caConfigCommands[j].Name) != 0) continue; Log_Debug("Config", "Command '%s', %i args passed", line->Parts[0], line->nParts-1); + // Check against minimum argument count if( line->nParts - 1 < caConfigCommands[j].MinArgs ) { Log_Warning("Config", "Configuration command '%s' requires at least %i arguments, %i given", @@ -368,6 +385,7 @@ void System_ExecuteScript(void) break; } + // Check for extra arguments if( line->nParts - 1 > caConfigCommands[j].MaxArgs ) { Log_Warning("Config", "Configuration command '%s' takes at most %i arguments, %i given", @@ -376,21 +394,50 @@ void System_ExecuteScript(void) break; } + // Fill in defaults for( k = caConfigCommands[j].MaxArgs-1; k > line->nParts - 1; k-- ) { args[k] = caConfigCommands[j].OptDefaults[k]; } + // Convert arguments to integers for( k = line->nParts-1; k--; ) { - if( caConfigCommands[j].IntArgs & (1 << k) ) { - args[k] = atoi(line->Parts[k+1]); + if( k < 32 && (caConfigCommands[j].IntArgs & (1 << k)) ) { + args[k] = (const char *)(Uint)atoi(line->Parts[k+1]); } else { - args[k] = (Uint)line->Parts[k+1]; + args[k] = (char *)line->Parts[k+1]; } - Log_Debug("Config", "args[%i] = 0x%x", k, args[k]); + Log_Debug("Config", "args[%i] = %p", k, args[k]); + } + switch( (enum eConfigCommands) caConfigCommands[j].Index ) + { + case CC_LOADMODULE: + result = Module_LoadFile( args[0], args[1] ); + break; + case CC_SPAWN: + result = Proc_Spawn( args[0] ); + break; + case CC_MOUNT: + result = VFS_Mount( args[0], args[1], args[2], args[3] ); + break; + case CC_SYMLINK: + result = VFS_Symlink( args[0], args[1] ); + break; + case CC_OPEN: + result = VFS_Open( args[0], (Uint)args[1] ); + break; + case CC_CLOSE: + VFS_Close( (Uint)args[0] ); + result = 0; + break; + case CC_MKDIR: + result = VFS_MkDir( args[0] ); + break; + case CC_IOCTL: + result = VFS_IOCtl( (Uint)args[0], (Uint)args[1], (void *)args[2] ); + break; } - result = CallWithArgArray(caConfigCommands[j].Func, caConfigCommands[j].MaxArgs, args); Log_Debug("Config", "result = %i", result); break; } @@ -545,6 +592,7 @@ tConfigFile *System_Int_ParseFile(char *FileData) start = ptr; ret->Lines[i].nParts = 0; + ret->Lines[i].Parts = NULL; // Count parts for(;;) @@ -637,6 +685,12 @@ tConfigFile *System_Int_ParseFile(char *FileData) } } + if( i < ret->nLines ) { + ret->Lines[i].nParts = 0; + ret->Lines[i].Parts = NULL; + Log_Log("System", "Cleaning up final empty line"); + } + LEAVE('p', ret); return ret; }