* Common Binary Loader\r
*/\r
#define DEBUG 0\r
-#include <common.h>\r
+#include <acess.h>\r
#include <binary.h>\r
\r
// === CONSTANTS ===\r
void Binary_Dereference(tBinary *Info);\r
Uint Binary_Relocate(void *Base);\r
Uint Binary_GetSymbolEx(char *Name, Uint *Value);\r
-Uint Binary_FindSymbol(void *Base, char *Name, Uint *val);\r
+Uint Binary_FindSymbol(void *Base, char *Name, Uint *Val);\r
\r
// === GLOBALS ===\r
int glBinListLock = 0;\r
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
}\r
\r
/**\r
- \fn tBinary *Binary_GetInfo(char *truePath)\r
- \brief Finds a matching binary entry\r
- \param truePath File Identifier (True path name)\r
-*/\r
-tBinary *Binary_GetInfo(char *truePath)\r
+ * \brief Finds a matching binary entry\r
+ * \param TruePath File Identifier (True path name)\r
+ */\r
+tBinary *Binary_GetInfo(char *TruePath)\r
{\r
tBinary *pBinary;\r
pBinary = glLoadedBinaries;\r
while(pBinary)\r
{\r
- if(strcmp(pBinary->TruePath, truePath) == 0)\r
+ if(strcmp(pBinary->TruePath, TruePath) == 0)\r
return pBinary;\r
pBinary = pBinary->Next;\r
}\r
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
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
}\r
\r
/**\r
- \fn char *Binary_RegInterp(char *path)\r
- \brief Registers an Interpreter\r
- \param path Path to interpreter provided by executable\r
-*/\r
-char *Binary_RegInterp(char *path)\r
+ * \fn char *Binary_RegInterp(char *Path)\r
+ * \brief Registers an Interpreter\r
+ * \param Path Path to interpreter provided by executable\r
+ */\r
+char *Binary_RegInterp(char *Path)\r
{\r
int i;\r
// NULL Check Argument\r
- if(path == NULL) return NULL;\r
+ if(Path == NULL) return NULL;\r
// NULL Check the array\r
if(gsaRegInterps == NULL)\r
{\r
giRegInterps = 1;\r
gsaRegInterps = malloc( sizeof(char*) );\r
- gsaRegInterps[0] = malloc( strlen(path) );\r
- strcpy(gsaRegInterps[0], path);\r
+ gsaRegInterps[0] = malloc( strlen(Path) );\r
+ strcpy(gsaRegInterps[0], Path);\r
return gsaRegInterps[0];\r
}\r
\r
// Scan Array\r
for( i = 0; i < giRegInterps; i++ )\r
{\r
- if(strcmp(gsaRegInterps[i], path) == 0)\r
+ if(strcmp(gsaRegInterps[i], Path) == 0)\r
return gsaRegInterps[i];\r
}\r
\r
// Interpreter is not in list\r
giRegInterps ++;\r
gsaRegInterps = malloc( sizeof(char*)*giRegInterps );\r
- gsaRegInterps[i] = malloc( strlen(path) );\r
- strcpy(gsaRegInterps[i], path);\r
+ gsaRegInterps[i] = malloc( strlen(Path) );\r
+ strcpy(gsaRegInterps[i], Path);\r
return gsaRegInterps[i];\r
}\r
\r
// Kernel Binary Handling\r
// ============\r
/**\r
- * \fn void *Binary_LoadKernel(char *path)\r
+ * \fn void *Binary_LoadKernel(char *File)\r
* \brief Load a binary into kernel space\r
* \note This function shares much with #Binary_Load, but does it's own mapping\r
+ * \param File File to load into the kernel\r
*/\r
-void *Binary_LoadKernel(char *file)\r
+void *Binary_LoadKernel(char *File)\r
{\r
char *sTruePath;\r
tBinary *pBinary;\r
Uint addr;\r
int i;\r
\r
- ENTER("sfile", file);\r
+ ENTER("sfile", File);\r
\r
// Sanity Check Argument\r
- if(file == NULL) {\r
+ if(File == NULL) {\r
LEAVE('n');\r
return 0;\r
}\r
\r
// Get True File Path\r
- sTruePath = VFS_GetTruePath(file);\r
+ sTruePath = VFS_GetTruePath(File);\r
if(sTruePath == NULL) {\r
LEAVE('n');\r
return 0;\r
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
}\r
\r
/**\r
- * \fn Uint Binary_GetSymbolBin(void *Base, char *Name, Uint *val)\r
+ * \fn Uint Binary_FindSymbol(void *Base, char *Name, Uint *Val)\r
* \brief Get a symbol from the specified library\r
* \param Base Base address\r
* \param Name Name of symbol to find\r
- * \param val Pointer to place final value\r
+ * \param Val Pointer to place final value\r
*/\r
-Uint Binary_FindSymbol(void *Base, char *Name, Uint *val)\r
+Uint Binary_FindSymbol(void *Base, char *Name, Uint *Val)\r
{\r
Uint32 ident = *(Uint32*) Base;\r
tBinaryType *bt = gRegBinTypes;\r
for(; bt; bt = bt->Next)\r
{\r
if( (ident & bt->Mask) == (Uint)bt->Ident )\r
- return bt->GetSymbol(Base, Name, val);\r
+ return bt->GetSymbol(Base, Name, Val);\r
}\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
return 0;\r
}\r
+\r
+// === EXPORTS ===\r
+EXPORT(Binary_FindSymbol);\r
+EXPORT(Binary_Unload);\r