Working on GUI, side changes to the message passing
[tpg/acess2.git] / Kernel / binary.c
index dae3cfa..a98e192 100644 (file)
@@ -3,15 +3,16 @@
  * Common Binary Loader\r
  */\r
 #define DEBUG  0\r
-#include <common.h>\r
+#include <acess.h>\r
 #include <binary.h>\r
 \r
 // === CONSTANTS ===\r
 #define BIN_LOWEST     MM_USER_MIN             // 1MiB\r
 #define BIN_GRANUALITY 0x10000         // 64KiB\r
+//! \todo Move 0xBC000000 to mm_virt.h\r
 #define BIN_HIGHEST    (0xBC000000-BIN_GRANUALITY)             // Just below the kernel\r
 #define        KLIB_LOWEST     MM_MODULE_MIN\r
-#define KLIB_GRANUALITY        0x8000          // 32KiB\r
+#define KLIB_GRANUALITY        0x10000         // 32KiB\r
 #define        KLIB_HIGHEST    (MM_MODULE_MAX-KLIB_GRANUALITY)\r
 \r
 // === TYPES ===\r
@@ -54,6 +55,16 @@ tKernelBin   *glLoadedKernelLibs;
 tBinaryType    *gRegBinTypes = &gELF_Info;\r
  \r
 // === FUNCTIONS ===\r
+/**\r
+ * \brief Registers a binary type\r
+ */\r
+int Binary_RegisterType(tBinaryType *Type)\r
+{\r
+       Type->Next = gRegBinTypes;\r
+       gRegBinTypes = Type;\r
+       return 1;\r
+}\r
+\r
 /**\r
  * \fn int Proc_Spawn(char *Path)\r
  */\r
@@ -316,12 +327,23 @@ Uint Binary_MapIn(tBinary *binary)
                addr += base;\r
                LOG("%i - 0x%x to 0x%x", i, addr, binary->Pages[i].Physical);\r
                MM_Map( addr, (Uint) (binary->Pages[i].Physical) );\r
-               if( binary->Pages[i].Physical & 1)      // Read-Only\r
+               \r
+               // Read-Only?\r
+               if( binary->Pages[i].Flags & BIN_PAGEFLAG_RO)\r
                        MM_SetFlags( addr, MM_PFLAG_RO, -1 );\r
                else\r
                        MM_SetFlags( addr, MM_PFLAG_COW, -1 );\r
+               \r
+               // Execute?\r
+               if( binary->Pages[i].Flags & BIN_PAGEFLAG_EXEC )\r
+                       MM_SetFlags( addr, MM_PFLAG_EXEC, -1 );\r
+               else\r
+                       MM_SetFlags( addr, MM_PFLAG_EXEC, 0 );\r
+               \r
        }\r
        \r
+       //Log("Mapped '%s' to 0x%x", binary->TruePath, base);\r
+       \r
        //LOG("*0x%x = 0x%x\n", binary->Pages[0].Virtual, *(Uint*)binary->Pages[0].Virtual);\r
        \r
        return base;\r
@@ -417,23 +439,30 @@ tBinary *Binary_DoLoad(char *truePath)
                Uint    dest;\r
                tPAddr  paddr;\r
                paddr = (Uint)MM_AllocPhys();\r
+               if(paddr == 0) {\r
+                       Warning("Binary_DoLoad - Physical memory allocation failed");\r
+                       for( ; i--; ) {\r
+                               MM_DerefPhys( pBinary->Pages[i].Physical );\r
+                       }\r
+                       return NULL;\r
+               }\r
                MM_RefPhys( paddr );    // Make sure it is _NOT_ freed until we want it to be\r
                dest = MM_MapTemp( paddr );\r
                dest += pBinary->Pages[i].Virtual & 0xFFF;\r
                LOG("dest = 0x%x, paddr = 0x%x", dest, paddr);\r
-               LOG("Pages[%i]={Physical:0x%x,Virtual:0x%x,Size:0x%x}",\r
+               LOG("Pages[%i]={Physical:0x%llx,Virtual:%p,Size:0x%x}",\r
                        i, pBinary->Pages[i].Physical, pBinary->Pages[i].Virtual, pBinary->Pages[i].Size);\r
                \r
                // Pure Empty Page\r
                if(pBinary->Pages[i].Physical == -1) {\r
                        LOG("%i - ZERO", i);\r
-                       memsetd( (void*)dest, 0, 1024 );\r
+                       memsetd( (void*)dest, 0, 1024 - (pBinary->Pages[i].Virtual & 0xFFF)/4 );\r
                }\r
                else\r
                {\r
                        VFS_Seek( fp, pBinary->Pages[i].Physical, 1 );\r
                        if(pBinary->Pages[i].Size != 0x1000) {\r
-                               LOG("%i - 0x%x - 0x%x bytes",\r
+                               LOG("%i - 0x%llx - 0x%x bytes",\r
                                        i, pBinary->Pages[i].Physical, pBinary->Pages[i].Size);\r
                                memset( (void*)dest, 0, 0x1000 -(dest&0xFFF) );\r
                                VFS_Read( fp, pBinary->Pages[i].Size, (void*)dest );\r
@@ -675,13 +704,9 @@ void *Binary_LoadKernel(char *file)
                LOG("%i - 0x%x to 0x%x", i, addr, pBinary->Pages[i].Physical);\r
                MM_Map( addr, (Uint) (pBinary->Pages[i].Physical) );\r
                MM_SetFlags( addr, MM_PFLAG_KERNEL, MM_PFLAG_KERNEL );\r
-               #if 0   // Why was this here? It's the kernel\r
-               if( pBinary->Pages[i].Physical & 1)     // Read-Only\r
+               \r
+               if( pBinary->Pages[i].Flags & BIN_PAGEFLAG_RO)  // Read-Only?\r
                        MM_SetFlags( addr, MM_PFLAG_RO, MM_PFLAG_KERNEL );\r
-               else\r
-                       MM_SetFlags( addr, MM_PFLAG_COW, MM_PFLAG_KERNEL );\r
-                       //MM_SetCOW( addr );\r
-               #endif\r
        }
 \r
        // Relocate Library\r
@@ -725,7 +750,7 @@ Uint Binary_Relocate(void *Base)
        }\r
        \r
        Warning("[BIN ] 0x%x is an unknown file type. (0x%x 0x%x 0x%x 0x%x)",\r
-               Base, ident&0xFF, ident>>8, ident>>16, ident>>24);\r
+               Base, ident&0xFF, (ident>>8)&0xFF, (ident>>16)&0xFF, (ident>>24)&0xFF);\r
        return 0;\r
 }\r
 \r
@@ -801,3 +826,7 @@ Uint Binary_FindSymbol(void *Base, char *Name, Uint *val)
                Base, ident&0xFF, ident>>8, ident>>16, ident>>24);\r
        return 0;\r
 }\r
+\r
+// === EXPORTS ===\r
+EXPORT(Binary_FindSymbol);\r
+EXPORT(Binary_Unload);\r

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