Bugfixing initrd and ld-acess
authorJohn Hodge <[email protected]>
Thu, 18 Mar 2010 03:07:51 +0000 (11:07 +0800)
committerJohn Hodge <[email protected]>
Thu, 18 Mar 2010 03:07:51 +0000 (11:07 +0800)
- ld-acess passed NULL to SysLoadBin if the file is not found
- InitRD ignored Offset in ReadFile

15 files changed:
Kernel/Makefile.BuildNum
Kernel/arch/x86/main.c
Kernel/bin/elf.c
Kernel/bin/elf.h
Kernel/binary.c
Kernel/include/vfs_ext.h
Kernel/modules.c
Kernel/syscalls.c
Kernel/vfs/main.c
Modules/Filesystems/InitRD/GenerateInitRD.php
Modules/Filesystems/InitRD/Makefile
Modules/Filesystems/InitRD/files.lst
Modules/Filesystems/InitRD/main.c
Usermode/Filesystem/Conf/BootConf.cfg
Usermode/Libraries/ld-acess.so_src/loadlib.c

index 61acd3c..46b9e67 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 1541
+BUILD_NUM = 1556
index f6879f8..c8e4e4d 100644 (file)
@@ -51,11 +51,12 @@ int kmain(Uint MbMagic, tMBoot_Info *MbInfo)
        // Load Virtual Filesystem
        VFS_Init();
        
-       Log("Loading Modules...");
+       Log("Loading Modules... (%i of them)", MbInfo->ModuleCount);
        
        // Load initial modules
        mods = (void*)( MbInfo->Modules + KERNEL_BASE );
-       for(i=0;i<MbInfo->ModuleCount;i++)
+       Log("MbInfo = %p", MbInfo);
+       for( i = 0; i < MbInfo->ModuleCount; i ++ )
        {
                // Adjust into higher half
                mods[i].Start += KERNEL_BASE;
@@ -68,6 +69,7 @@ int kmain(Uint MbMagic, tMBoot_Info *MbInfo)
                {
                        Warning("Unable to load module\n");
                }
+               Log("Done. (MbInfo = %p)", MbInfo);
        }
        
        // Pass on to Independent Loader
@@ -75,6 +77,7 @@ int kmain(Uint MbMagic, tMBoot_Info *MbInfo)
        System_Init( (char*)(MbInfo->CommandLine + KERNEL_BASE) );
        
        // Sleep forever (sleeping beauty)
-       for(;;) Threads_Sleep();
+       for(;;)
+               Threads_Sleep();
        return 0;
 }
index 4bc13b1..ad8edb0 100644 (file)
@@ -57,7 +57,12 @@ tBinary *Elf_Load(int fp)
        }\r
        \r
        // Read Program Header Table\r
-       phtab = malloc(sizeof(Elf32_Phdr)*hdr.phentcount);\r
+       phtab = malloc( sizeof(Elf32_Phdr) * hdr.phentcount );\r
+       if( !phtab ) {\r
+               LEAVE('n');\r
+               return NULL;\r
+       }\r
+       LOG("hdr.phoff = 0x%08x", hdr.phoff);\r
        VFS_Seek(fp, hdr.phoff, SEEK_SET);\r
        VFS_Read(fp, sizeof(Elf32_Phdr)*hdr.phentcount, phtab);\r
        \r
@@ -88,7 +93,17 @@ tBinary *Elf_Load(int fp)
        for( i = 0; i < hdr.phentcount; i++ )\r
        {\r
                 int    lastSize;\r
-               LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type);\r
+               //LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type);\r
+               LOG("phtab[%i] = {", i);\r
+               LOG(" .Type = 0x%08x", phtab[i].Type);\r
+               LOG(" .Offset = 0x%08x", phtab[i].Offset);\r
+               LOG(" .VAddr = 0x%08x", phtab[i].VAddr);\r
+               LOG(" .PAddr = 0x%08x", phtab[i].PAddr);\r
+               LOG(" .FileSize = 0x%08x", phtab[i].FileSize);\r
+               LOG(" .MemSize = 0x%08x", phtab[i].MemSize);\r
+               LOG(" .Flags = 0x%08x", phtab[i].Flags);\r
+               LOG(" .Align = 0x%08x", phtab[i].Align);\r
+               LOG(" }");\r
                // Get Interpreter Name\r
                if( phtab[i].Type == PT_INTERP )\r
                {\r
index 1ff2128..13724eb 100644 (file)
@@ -130,9 +130,9 @@ enum {
 \r
 struct sElf32_Phdr {\r
        Uint32  Type;\r
-       Uint    Offset;\r
-       Uint    VAddr;\r
-       Uint    PAddr;\r
+       Uint32  Offset;\r
+       Uint32  VAddr;\r
+       Uint32  PAddr;\r
        Uint32  FileSize;\r
        Uint32  MemSize;\r
        Uint32  Flags;\r
index b02ca6e..0cd0bf3 100644 (file)
@@ -190,7 +190,7 @@ Uint Binary_Load(char *file, Uint *entryPoint)
        sTruePath = VFS_GetTruePath(file);\r
        \r
        if(sTruePath == NULL) {\r
-               Warning("[BIN ] '%s' does not exist.", file);\r
+               Warning("[BIN  ] '%s' does not exist.", file);\r
                LEAVE('x', 0);\r
                return 0;\r
        }\r
index 2fd7fd3..e2f0344 100644 (file)
@@ -8,7 +8,7 @@
 
 // === CONSTANTS ===
 //! Maximum size of a Memory Path generated by VFS_GetMemPath
-#define        VFS_MEMPATH_SIZE        (3 + (BITS/8)*2)
+#define        VFS_MEMPATH_SIZE        (3 + (BITS/4)*2)
 /**
  * \name Flags for VFS_Open
  * \{
index 5b5a906..29a03f8 100644 (file)
@@ -26,7 +26,7 @@ extern void   gKernelModulesEnd;
 
 // === GLOBALS ===
  int   giNumBuiltinModules = 0;
- int   giModuleSpinlock = 0;
+tSpinlock      glModuleSpinlock;
 tModule        *gLoadedModules = NULL;
 tModuleLoader  *gModule_Loaders = NULL;
 tModule        *gLoadingModules = NULL;
@@ -114,31 +114,33 @@ int Module_int_Initialise(tModule *Module)
        
        ret = Module->Init(NULL);
        if( ret != MODULE_ERR_OK ) {
-               Log("[MOD  ] Loading Failed, all modules that depend on this will also fail");
                switch(ret)
                {
                case MODULE_ERR_MISC:
-                       Log("[MOD  ] Reason: Miscelanious");
+                       Warning("[MOD  ] Unable to load, reason: Miscelanious");
                        break;
                case MODULE_ERR_NOTNEEDED:
-                       Log("[MOD  ] Reason: Module not needed (probably hardware not found)");
+                       Warning("[MOD  ] Unable to load, reason: Module not needed (probably hardware not found)");
                        break;
                case MODULE_ERR_MALLOC:
-                       Log("[MOD  ] Reason: Error in malloc/realloc/calloc, probably not good");
+                       Warning("[MOD  ] Unable to load, reason: Error in malloc/realloc/calloc, probably not good");
                        break;
                default:
-                       Log("[MOD  ] Reason - Unknown code %i", ret);
+                       Warning("[MOD  ] Unable to load reason - Unknown code %i", ret);
                        break;
                }
                LEAVE_RET('i', ret);
+               return ret;
        }
        
        // Remove from loading list
        gLoadingModules = gLoadingModules->Next;
        
        // Add to loaded list
+       LOCK( &glModuleSpinlock );
        Module->Next = gLoadedModules;
        gLoadedModules = Module;
+       RELEASE( &glModuleSpinlock );
        
        LEAVE_RET('i', 0);
 }
@@ -250,6 +252,13 @@ int Module_LoadFile(char *Path, char *ArgString)
                return 0;
        }
        
+       #if 1
+       if( Module_int_Initialise( info ) )
+       {
+               Binary_Unload(base);
+               return 0;
+       }
+       #else
        // Resolve Dependencies
        if( !Module_int_ResolveDeps(info) ) {
                Binary_Unload(base);
@@ -271,10 +280,11 @@ int Module_LoadFile(char *Path, char *ArgString)
        }
        
        // Add to list
-       LOCK( &giModuleSpinlock );
+       LOCK( &glModuleSpinlock );
        info->Next = gLoadedModules;
        gLoadedModules = info;
-       RELEASE( &giModuleSpinlock );
+       RELEASE( &glModuleSpinlock );
+       #endif
        
        return 1;
 }
index 523b3f2..cafe7c2 100644 (file)
@@ -168,7 +168,7 @@ void SyscallHandler(tSyscallRegs *Regs)
                if( !Syscall_ValidString(Regs->Arg1)
                ||  !Syscall_Valid(sizeof(Uint), Regs->Arg2) ) {
                        err = -EINVAL;
-                       ret = -1;
+                       ret = 0;
                        break;
                }
                // Path, *Entrypoint
index c8636b1..736b578 100644 (file)
@@ -20,6 +20,9 @@ tVFS_Driver   *VFS_GetFSByName(char *Name);
  int   VFS_AddDriver(tVFS_Driver *Info);
 void   VFS_UpdateDriverFile();
 
+// === EXPORTS ===
+EXPORT(VFS_AddDriver);
+
 // === GLOBALS ===
 tVFS_Node      NULLNode = {0};
 tSpinlock      siDriverListLock = 0;
@@ -86,6 +89,7 @@ void VFS_GetMemPath(char *Dest, void *Base, Uint Length)
        itoa( &Dest[1], (Uint)Base, 16, BITS/4, '0' );
        Dest[BITS/4+1] = ':';
        itoa( &Dest[BITS/4+2], Length, 16, BITS/4, '0' );
+       Dest[BITS/2+2] = '\0';
        
        Log("VFS_GetMemPath: Dest = \"%s\"", Dest);
 }
index d89d6e9..031ad59 100644 (file)
@@ -1,10 +1,15 @@
+<?php
+$lGenDate = date("Y-m-d H:i");
+$gOutput = <<<EOF
 /*
  * Acess2 InitRD
  * InitRD Data
- * Generated <?php echo date("Y-m-d H:i"),"\n"; ?>
+ * Generated $lGenDate
  */
 #include "initrd.h"
-<?php
+
+EOF;
+
 $lines = file($argv[1]);
 
 $lDepth = 0;
@@ -31,6 +36,8 @@ foreach($lines as $line)
                $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
                continue;
        }
+       echo "ERROR: $line\n";
+       exit(0);
 }
 
 function hd($fp)
@@ -40,22 +47,23 @@ function hd($fp)
 
 function ProcessFolder($prefix, $items)
 {
+       global  $gOutput;
        foreach($items as $i=>$item)
        {
-               if(is_array($item[1])) {
-                       
+               if(is_array($item[1]))
+               {
                        ProcessFolder("{$prefix}_{$i}", $item[1]);
                        
-                       echo "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
+                       $gOutput .= "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
                        foreach($item[1] as $j=>$child)
                        {
-                               if($j)  echo ",\n";
-                               echo "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
+                               if($j)  $gOutput .= ",\n";
+                               $gOutput .= "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
                        }
-                       echo "\n};\n";
+                       $gOutput .= "\n};\n";
                        
                        $size = count($item[1]);
-                       echo <<<EOF
+                       $gOutput .= <<<EOF
 tVFS_Node {$prefix}_{$i} = {
        .NumACLs = 1,
        .ACLs = &gVFS_ACL_EveryoneRX,
@@ -69,31 +77,35 @@ tVFS_Node {$prefix}_{$i} = {
 EOF;
                }
                else {
+                       if(!file_exists($item[1])) {
+                               echo "ERROR: '{$item[1]}' does not exist\n", 
+                               exit(1);
+                       }
                        $size = filesize($item[1]);
                        
-                       echo "Uint8 {$prefix}_{$i}_data[] = {\n";
+                       $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n";
                        $fp = fopen($item[1], "rb");
                        for( $j = 0; $j + 16 < $size; $j += 16 )
                        {
-                               echo "\t";
-                               echo hd($fp),",",hd($fp),",";
-                               echo hd($fp),",",hd($fp),",";
-                               echo hd($fp),",",hd($fp),",";
-                               echo hd($fp),",",hd($fp),",";
-                               echo hd($fp),",",hd($fp),",";
-                               echo hd($fp),",",hd($fp),",";
-                               echo hd($fp),",",hd($fp),",";
-                               echo hd($fp),",",hd($fp),",\n";
+                               $gOutput .= "\t";
+                               $gOutput .= hd($fp).",".hd($fp).",";
+                               $gOutput .= hd($fp).",".hd($fp).",";
+                               $gOutput .= hd($fp).",".hd($fp).",";
+                               $gOutput .= hd($fp).",".hd($fp).",";
+                               $gOutput .= hd($fp).",".hd($fp).",";
+                               $gOutput .= hd($fp).",".hd($fp).",";
+                               $gOutput .= hd($fp).",".hd($fp).",";
+                               $gOutput .= hd($fp).",".hd($fp).",\n";
                        }
-                       echo "\t";
+                       $gOutput .= "\t";
                        for( ; $j < $size; $j ++ )
                        {
-                               if( $j & 15 )   echo ",";
-                               echo hd($fp);
+                               if( $j & 15 )   $gOutput .= ",";
+                               $gOutput .= hd($fp);
                        }
                        fclose($fp);
-                       echo "\n};\n";
-                       echo <<<EOF
+                       $gOutput .= "\n};\n";
+                       $gOutput .= <<<EOF
 tVFS_Node {$prefix}_{$i} = {
        .NumACLs = 1,
        .ACLs = &gVFS_ACL_EveryoneRX,
@@ -108,22 +120,32 @@ EOF;
        }
 }
 
+//print_r($lStack);
+//exit(1);
+
 ProcessFolder("gInitRD_Files", $lStack[0][1]);
 
-echo "tInitRD_File gInitRD_Root_Files[] = {\n";
+$gOutput .= "tInitRD_File gInitRD_Root_Files[] = {\n";
 foreach($lStack[0][1] as $j=>$child)
 {
-       if($j)  echo ",\n";
-       echo "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
+       if($j)  $gOutput .= ",\n";
+       $gOutput .= "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
 }
-echo "\n};\n";
-?>
+$gOutput .= "\n};\n";
+$nRootFiles = count($lStack[0][1]);
+$gOutput .= <<<EOF
 tVFS_Node gInitRD_RootNode = {
        .NumACLs = 1,
        .ACLs = &gVFS_ACL_EveryoneRX,
        .Flags = VFS_FFLAG_DIRECTORY,
-       .Size = <?php echo count($lStack[0][1]);?>,
+       .Size = $nRootFiles,
        .ImplPtr = gInitRD_Root_Files,
        .ReadDir = InitRD_ReadDir,
        .FindDir = InitRD_FindDir
 };
+EOF;
+
+$fp = fopen($argv[2], "w");
+fputs($fp, $gOutput);
+fclose($fp);
+?>
index 18dbc59..1a26301 100644 (file)
@@ -6,5 +6,5 @@ NAME = FS_InitRD
 
 -include ../Makefile.tpl
 
-files.c:
-       php GenerateInitRD.php files.lst files.c
+files.c: GenerateInitRD.php files.lst
+       php GenerateInitRD.php files.lst files.c
index bf36527..ea7797f 100644 (file)
@@ -5,4 +5,14 @@ Dir "SBin" {
 Dir "Bin" {
        File "CLIShell" "../../../Usermode/Applications/CLIShell"
        File "ls" "../../../Usermode/Applications/ls"
+       File "cat" "../../../Usermode/Applications/cat"
+}
+Dir "Libs" {
+       File "ld-acess.so" "../../../Usermode/Libraries/ld-acess.so"
+       File "libacess.so" "../../../Usermode/Libraries/libacess.so"
+       File "libc.so.1" "../../../Usermode/Libraries/libc.so.1"
+       File "libgcc.so" "../../../Usermode/Libraries/libgcc.so"
+}
+Dir "Conf" {
+       File "BootConf.cfg" "../../../Usermode/Filesystem/Conf/BootConf.cfg"
 }
index 1485058..cc54f27 100644 (file)
@@ -56,7 +56,7 @@ Uint64 InitRD_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buff
        if(Offset + Length > Node->Size)
                Length = Node->Size - Offset;
        
-       memcpy(Buffer, Node->ImplPtr, Length);
+       memcpy(Buffer, Node->ImplPtr+Offset, Length);
        
        return Length;
 }
@@ -82,6 +82,8 @@ tVFS_Node *InitRD_FindDir(tVFS_Node *Node, char *Name)
         int    i;
        tInitRD_File    *dir = Node->ImplPtr;
        
+       Log("InirRD_FindDir: Name = '%s'", Name);
+       
        for( i = 0; i < Node->Size; i++ )
        {
                if(strcmp(Name, dir[i].Name) == 0)
index fcd6ad6..788da48 100644 (file)
@@ -1,4 +1,4 @@
-module /Acess/Modules/bochsvbe.kmd
+#module /Acess/Modules/bochsvbe.kmd
 #module /Acess/Modules/ps2mouse
 #edimod /Acess/Modules/serial.edi
 #module /Acess/Modules/ne2000.akm
index b5fb0a1..5cfa26e 100644 (file)
@@ -66,6 +66,10 @@ Uint LoadLibrary(char *SoName, char *SearchDir, char **envp)
        \r
        // Create Temp Name\r
        filename = FindLibrary(sTmpName, SoName, SearchDir);\r
+       if(filename == NULL) {\r
+               DEBUGS("LoadLibrary: RETURN 0\n");\r
+               return 0;\r
+       }\r
        DEBUGS(" LoadLibrary: filename='%s'\n", filename);\r
        \r
        if( (iArg = IsFileLoaded(filename)) )\r

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