Misc changes
[tpg/acess2.git] / Kernel / bin / elf.c
index 731d151..b55011b 100644 (file)
@@ -9,13 +9,12 @@
 \r
 #define DEBUG_WARN     1\r
 \r
-\r
 // === PROTOTYPES ===\r
 tBinary        *Elf_Load(int fp);\r
  int   Elf_Relocate(void *Base);\r
- int   Elf_GetSymbol(void *Base, char *Name, Uint *ret);\r
+ int   Elf_GetSymbol(void *Base, const char *Name, Uint *ret);\r
  int   Elf_Int_DoRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symtab, Uint base);\r
-Uint   Elf_Int_HashString(char *str);\r
+Uint   Elf_Int_HashString(const char *str);\r
 \r
 // === GLOBALS ===\r
 tBinaryType    gELF_Info = {\r
@@ -35,14 +34,14 @@ tBinary *Elf_Load(int fp)
         int    iPageCount;\r
         int    count;\r
        \r
-       ENTER("ifp", fp);\r
+       ENTER("xfp", fp);\r
        \r
        // Read ELF Header\r
        VFS_Read(fp, sizeof(hdr), &hdr);\r
        \r
        // Check the file type\r
        if(hdr.ident[0] != 0x7F || hdr.ident[1] != 'E' || hdr.ident[2] != 'L' || hdr.ident[3] != 'F') {\r
-               Warning("Non-ELF File was passed to the ELF loader\n");\r
+               Log_Warning("ELF", "Non-ELF File was passed to the ELF loader");\r
                LEAVE('n');\r
                return NULL;\r
        }\r
@@ -50,7 +49,7 @@ tBinary *Elf_Load(int fp)
        // Check for a program header\r
        if(hdr.phoff == 0) {\r
                #if DEBUG_WARN\r
-               Warning("ELF File does not contain a program header\n");\r
+               Log_Warning("ELF", "File does not contain a program header (phoff == 0)");\r
                #endif\r
                LEAVE('n');\r
                return NULL;\r
@@ -126,13 +125,15 @@ tBinary *Elf_Load(int fp)
                LOG("phtab[%i] = {VAddr:0x%x,Offset:0x%x,FileSize:0x%x}",\r
                        i, phtab[i].VAddr, phtab[i].Offset, phtab[i].FileSize);\r
                \r
-               if( (phtab[i].FileSize & 0xFFF) < 0x1000 - (phtab[i].VAddr & 0xFFF) )\r
-                       lastSize = phtab[i].FileSize;\r
-               else\r
+               //if( (phtab[i].FileSize & 0xFFF) < 0x1000 - (phtab[i].VAddr & 0xFFF) )\r
+               //      lastSize = phtab[i].FileSize;\r
+               //else\r
                        lastSize = (phtab[i].FileSize & 0xFFF) + (phtab[i].VAddr & 0xFFF);\r
-               lastSize &= 0xFFF;\r
+               //lastSize &= 0xFFF;\r
+               \r
+               //LOG("lastSize = 0x%x", lastSize);\r
                \r
-               LOG("lastSize = 0x%x", lastSize);\r
+               lastSize = phtab[i].FileSize;\r
                \r
                // Get Pages\r
                count = ( (phtab[i].VAddr&0xFFF) + phtab[i].FileSize + 0xFFF) >> 12;\r
@@ -152,6 +153,7 @@ tBinary *Elf_Load(int fp)
                                ret->Pages[j+k].Size = 4096;\r
                        LOG("ret->Pages[%i].Size = 0x%x", j+k, ret->Pages[j+k].Size);\r
                        ret->Pages[j+k].Flags = 0;\r
+                       lastSize -= ret->Pages[j+k].Size;\r
                }\r
                count = (phtab[i].MemSize + 0xFFF) >> 12;\r
                for(;k<count;k++)\r
@@ -220,7 +222,7 @@ tBinary *Elf_Load(int fp)
                // Reallocate\r
                ret = realloc( ret, sizeof(tBinary) + 3*sizeof(Uint)*j );\r
                if(!ret) {\r
-                       Warning("BIN", "ElfLoad: Unable to reallocate return structure");\r
+                       Log_Warning("BIN", "ElfLoad: Unable to reallocate return structure");\r
                        return NULL;\r
                }\r
                ret->NumPages = j;\r
@@ -283,7 +285,7 @@ int Elf_Relocate(void *Base)
        ENTER("pBase", Base);\r
        \r
        // Parse Program Header to get Dynamic Table\r
-       phtab = Base + hdr->phoff;\r
+       phtab = (void *)( (tVAddr)Base + hdr->phoff );\r
        iSegmentCount = hdr->phentcount;\r
        for(i = 0; i < iSegmentCount; i ++ )\r
        {\r
@@ -526,10 +528,10 @@ int Elf_Int_DoRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symta
 }\r
 \r
 /**\r
- * \fn int Elf_GetSymbol(void *Base, char *name, Uint *ret)\r
+ * \fn int Elf_GetSymbol(void *Base, const char *name, Uint *ret)\r
  * \brief Get a symbol from the loaded binary\r
  */\r
-int Elf_GetSymbol(void *Base, char *Name, Uint *ret)\r
+int Elf_GetSymbol(void *Base, const char *Name, Uint *ret)\r
 {\r
        Elf32_Ehdr      *hdr = (void*)Base;\r
        Elf32_Sym       *symtab;\r
@@ -579,7 +581,7 @@ int Elf_GetSymbol(void *Base, char *Name, Uint *ret)
  * \param str  String to hash\r
  * \return Hash value\r
  */\r
-Uint Elf_Int_HashString(char *str)\r
+Uint Elf_Int_HashString(const char *str)\r
 {\r
        Uint    h = 0, g;\r
        while(*str)\r

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