Kernel - Cleanup and fix all memfiles treated as same by binary loader
authorJohn Hodge <[email protected]>
Sat, 12 Oct 2013 13:49:13 +0000 (21:49 +0800)
committerJohn Hodge <[email protected]>
Sat, 12 Oct 2013 13:49:13 +0000 (21:49 +0800)
KernelLand/Kernel/arch/x86/main.c
KernelLand/Kernel/binary.c
KernelLand/Kernel/modules.c
KernelLand/Kernel/vfs/memfile.c

index 865e53e..8b85d06 100644 (file)
@@ -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 )
index cca55b4..46f9323 100644 (file)
@@ -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;
index b5e917c..5fff929 100644 (file)
@@ -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],
index e2253d7..ad68671 100644 (file)
@@ -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;
        

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