X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fsystem.c;h=986734cd56b6cef686aceaa63f448fdfeb2faccc;hb=784b6fc9ee5221ed58ed7a118c0c856d483a2ea7;hp=66f645f2f5a1d385e52a4e6b27844330e13d7ad8;hpb=952891ddb96a341c0e24ecb7dec6361c7bbeaece;p=tpg%2Facess2.git diff --git a/Kernel/system.c b/Kernel/system.c index 66f645f2..986734cd 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -27,8 +27,8 @@ typedef struct 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 === @@ -48,18 +48,28 @@ 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])) @@ -100,7 +110,6 @@ void System_ParseCommandLine(char *ArgString) char *str; 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; @@ -155,7 +164,7 @@ void System_ExecuteCommandLine(void) int i; for( i = 0; i < argc; i++ ) { - Log("argv[%i] = '%s'", i, argv[i]); + LOG("argv[%i] = '%s'", i, argv[i]); switch(argv[i][0]) { // --- VFS --- @@ -308,17 +317,20 @@ void System_ExecuteScript(void) tConfigFile *file; tConfigLine *line; + ENTER(""); + // Open Script fp = VFS_Open(gsConfigScript, VFS_OPENFLAG_READ); if(fp == -1) { Log_Warning("Config", "Passed script '%s' does not exist", gsConfigScript); + LEAVE('-'); return; } // Get length VFS_Seek(fp, 0, SEEK_END); fLen = VFS_Tell(fp); - Log_Debug("System", "VFS_Tell(%i) = %i", fp, fLen); + LOG("VFS_Tell(0x%x) = %i", fp, fLen); VFS_Seek(fp, 0, SEEK_SET); // Read into memory buffer fData = malloc(fLen+1); @@ -341,7 +353,7 @@ void System_ExecuteScript(void) // Prescan and eliminate variables for( j = 1; j < line->nParts; j++ ) { - Log_Debug("Config", "Arg #%i is '%s'", j, line->Parts[j]); + LOG("Arg #%i is '%s'", j, line->Parts[j]); bReplaced[j] = 0; if( line->Parts[j][0] != '$' ) continue; if( line->Parts[j][1] == '?' ) { @@ -352,7 +364,7 @@ void System_ExecuteScript(void) if( val < 0 || val > N_VARIABLES ) continue; val = variables[ val ]; } - Log_Debug("Config", "Replaced arg %i ('%s') with 0x%x", j, line->Parts[j], val); + LOG("Replaced arg %i ('%s') with 0x%x", j, line->Parts[j], val); line->Parts[j] = malloc( BITS/8+2+1 ); sprintf(line->Parts[j], "0x%x", val); bReplaced[j] = 1; @@ -361,7 +373,7 @@ void System_ExecuteScript(void) // 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; @@ -394,15 +406,42 @@ void System_ExecuteScript(void) for( k = line->nParts-1; k--; ) { if( k < 32 && (caConfigCommands[j].IntArgs & (1 << k)) ) { - args[k] = atoi(line->Parts[k+1]); + 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("args[%i] = %p", k, args[k]); } - result = CallWithArgArray(caConfigCommands[j].Func, caConfigCommands[j].MaxArgs, args); - Log_Debug("Config", "result = %i", result); + 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; + } + LOG("Config", "result = %i", result); break; } if( j < NUM_CONFIG_COMMANDS ) continue; @@ -505,6 +544,8 @@ void System_ExecuteScript(void) // Free data free( file ); free( fData ); + + LEAVE('-'); } /** @@ -514,7 +555,7 @@ void System_ExecuteScript(void) * \return ::tConfigFile structure that represents the original contents * of \a FileData */ -tConfigFile *System_Int_ParseFile(char *FileData) +tConfigFile *System_Int_ParseFile(char *FileData) { char *ptr; char *start; @@ -652,7 +693,7 @@ 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"); + LOG("Cleaning up final empty line"); } LEAVE('p', ret);