From: John Hodge Date: Sat, 12 Oct 2013 13:49:13 +0000 (+0800) Subject: Kernel - Cleanup and fix all memfiles treated as same by binary loader X-Git-Tag: rel0.15~113 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=82595a34a73b4667a98349cceeb17f618bd41282;p=tpg%2Facess2.git Kernel - Cleanup and fix all memfiles treated as same by binary loader --- diff --git a/KernelLand/Kernel/arch/x86/main.c b/KernelLand/Kernel/arch/x86/main.c index 865e53e4..8b85d063 100644 --- a/KernelLand/Kernel/arch/x86/main.c +++ b/KernelLand/Kernel/arch/x86/main.c @@ -107,27 +107,29 @@ int kmain(Uint MbMagic, void *MbInfoPtr) void Arch_LoadBootModules(void) { - int i, j, numPages; - for( i = 0; i < giArch_NumBootModules; i ++ ) + for( int i = 0; i < giArch_NumBootModules; i ++ ) { - Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString); + const tBootModule *mod = &gaArch_BootModules[i]; + Log_Log("Arch", "Loading (%p[%P]+%x) '%s'", + mod->Base, mod->PBase, mod->Size, + mod->ArgString); - if( !Module_LoadMem( gaArch_BootModules[i].Base, - gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString - ) ) - { + if( !Module_LoadMem( mod->Base, mod->Size, mod->ArgString) ) { Log_Warning("Arch", "Unable to load module"); + continue ; } + #if 0 // Unmap and free - numPages = (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12; + int numPages = (mod->Size + ((tVAddr)mod->Base&0xFFF) + 0xFFF) >> 12; MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages ); - for( j = 0; j < numPages; j++ ) - MM_DerefPhys( gaArch_BootModules[i].PBase + (j << 12) ); + //for( int j = 0; j < numPages; j++ ) + // MM_DerefPhys( mod->PBase + (j << 12) ); - if( (tVAddr) gaArch_BootModules[i].ArgString > MAX_ARGSTR_POS ) - MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].ArgString, 2 ); + if( (tVAddr) mod->ArgString > MAX_ARGSTR_POS ) + MM_UnmapHWPages( (tVAddr)mod->ArgString, 2 ); + #endif } Log_Log("Arch", "Boot modules loaded"); if( gaArch_BootModules ) diff --git a/KernelLand/Kernel/binary.c b/KernelLand/Kernel/binary.c index cca55b48..46f93232 100644 --- a/KernelLand/Kernel/binary.c +++ b/KernelLand/Kernel/binary.c @@ -826,22 +826,20 @@ int Binary_GetSymbol(const char *Name, Uint *Val) */ Uint Binary_GetSymbolEx(const char *Name, Uint *Value) { - int i; tKernelBin *pKBin; int numKSyms = ((Uint)&gKernelSymbolsEnd-(Uint)&gKernelSymbols)/sizeof(tKernelSymbol); - LOG("numKSyms = %i", numKSyms); - // Scan Kernel - for( i = 0; i < numKSyms; i++ ) + for( int i = 0; i < numKSyms; i++ ) { - LOG("KSym %s = %p", gKernelSymbols[i].Name, gKernelSymbols[i].Value); if(strcmp(Name, gKernelSymbols[i].Name) == 0) { + LOG("KSym %s = %p", gKernelSymbols[i].Name, gKernelSymbols[i].Value); *Value = gKernelSymbols[i].Value; return 1; } } + // Scan Loaded Libraries for(pKBin = glLoadedKernelLibs; pKBin; diff --git a/KernelLand/Kernel/modules.c b/KernelLand/Kernel/modules.c index b5e917c3..5fff929a 100644 --- a/KernelLand/Kernel/modules.c +++ b/KernelLand/Kernel/modules.c @@ -12,6 +12,7 @@ // === PROTOTYPES === int Module_int_Initialise(tModule *Module, const char *ArgString); +size_t Modules_int_PopulateBuiltins(tModule **Array); void Modules_int_GetBuiltinArray(void); void Modules_LoadBuiltins(void); void Modules_SetBuiltinParams(const char *Name, char *ArgString); @@ -202,59 +203,51 @@ int Module_int_Initialise(tModule *Module, const char *ArgString) LEAVE_RET('i', 0); } -/** - * \brief Scans the builtin modules and creates an array of them - */ -void Modules_int_GetBuiltinArray(void) +size_t Modules_int_PopulateBuiltins(tModule **Array) { - int i; - tModule *module; - - // Count - module = &gKernelModules; - i = 0; - while( (tVAddr)module < (tVAddr)&gKernelModulesEnd ) + size_t count = 0; + for( tModule *module = &gKernelModules; module < (tModule*)&gKernelModulesEnd; ) { if(module->Magic == MODULE_MAGIC) { - i ++; + if( Array ) { + Array[count] = module; + } + count ++; module ++; } - else + else { module = (void*)( (tVAddr)module + 4 ); + } } - - // Create - giNumBuiltinModules = i; - gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) ); - gapBuiltinModules = malloc( giNumBuiltinModules * sizeof(tModule*) ); - - - // Fill - module = &gKernelModules; - i = 0; - while( (tVAddr)module < (tVAddr)&gKernelModulesEnd ) + return count; +} + +/** + * \brief Scans the builtin modules and creates an array of them + */ +void Modules_int_GetBuiltinArray(void) +{ + if( !gapBuiltinModules ) { - if(module->Magic == MODULE_MAGIC) { - gapBuiltinModules[i] = module; - i ++; - module ++; - } - else - module = (void*)( (tVAddr)module + 4 ); + // Count + giNumBuiltinModules = Modules_int_PopulateBuiltins(NULL); + + // Create + gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) ); + gapBuiltinModules = malloc( giNumBuiltinModules * sizeof(tModule*) ); + + // Fill + Modules_int_PopulateBuiltins(gapBuiltinModules); } } /** * \brief Initialises builtin modules */ -void Modules_LoadBuiltins() +void Modules_LoadBuiltins(void) { - int i; - - if( !gapBuiltinModules ) - Modules_int_GetBuiltinArray(); - - for( i = 0; i < giNumBuiltinModules; i++ ) + Modules_int_GetBuiltinArray(); + for( int i = 0; i < giNumBuiltinModules; i++ ) { Module_int_Initialise( gapBuiltinModules[i], diff --git a/KernelLand/Kernel/vfs/memfile.c b/KernelLand/Kernel/vfs/memfile.c index e2253d70..ad686711 100644 --- a/KernelLand/Kernel/vfs/memfile.c +++ b/KernelLand/Kernel/vfs/memfile.c @@ -64,6 +64,7 @@ tVFS_Node *VFS_MemFile_Create(const char *Path) memset(ret, 0, sizeof(tVFS_Node)); // State + ret->Inode = base; ret->ImplPtr = (void*)base; ret->Size = size;