#!/bin/sh
-./ld-acess --open /Devices/VTerm/0 --open /Devices/VTerm/0 --open /Devices/VTerm/0 $*
+
+$DBG ./ld-acess --open /Devices/VTerm/0 --open /Devices/VTerm/0 --open /Devices/VTerm/0 $*
#include <stdio.h>
#include <string.h>
-#define LIBRARY_PATH "$$$$../Usermode/Output/i386/Libs"
+#define LIBRARY_PATH "$$$$../Usermode/Output/x86/Libs"
// === TYPES ===
typedef struct sBinary {
// === IMPORTS ===
extern void *Elf_Load(int fd);
extern uintptr_t ElfRelocate(void *Base);
-extern int ElfGetSymbol(void *Base, char *Name, uintptr_t *ret);
+extern int ElfGetSymbol(void *Base, char *Name, uintptr_t *ret, size_t *size);
extern int ciNumBuiltinSymbols;
extern tSym caBuiltinSymbols[];
return NULL;
}
- acess_read(fd, 4, &dword);
+ acess_read(fd, &dword, 4);
acess_seek(fd, 0, ACESS_SEEK_SET);
if( memcmp(&dword, "\x7F""ELF", 4) == 0 ) {
}
}
-int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value)
+int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size)
{
int i;
tBinary *bin;
{
if( strcmp(caBuiltinSymbols[i].Name, SymbolName) == 0 ) {
*Value = (uintptr_t)caBuiltinSymbols[i].Value;
+ if(Size) *Size = 0;
return 1;
}
}
{
if( !bin->Ready ) continue;
//printf(" Binary_GetSymbol: bin = %p{%p, %s}\n", bin, bin->Base, bin->Path);
- if( bin->Format->GetSymbol(bin->Base, (char*)SymbolName, Value) )
+ if( bin->Format->GetSymbol(bin->Base, (char*)SymbolName, Value, Size) )
return 1;
}
#include <stdint.h>
#include <string.h>
-extern int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value);
+extern int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size);
extern void *Binary_LoadLibrary(const char *Path);
extern void *Binary_Load(const char *Path, uintptr_t *EntryPoint);
extern void Binary_SetReadyToUse(void *Base);
static inline void *GetSymbol(const char*sym, size_t*sz)
{
uintptr_t rv;
- if( Binary_GetSymbol(sym, &rv) )
+ if( !Binary_GetSymbol(sym, &rv, sz) )
return NULL;
return (void*)rv;
}
char *Name;
void *(*Load)(int fd);
uintptr_t (*Relocate)(void *base);
- int (*GetSymbol)(void*,char*,uintptr_t*);
+ int (*GetSymbol)(void*,char*,uintptr_t*,size_t*);
} tBinFmt;
#endif
* Acess v0.1\r
* ELF Executable Loader Code\r
*/\r
-#define DEBUG 0\r
+#define DEBUG 1\r
#include <stdlib.h>\r
#include <stdio.h>\r
#include <string.h>\r
#define PTR(_val) ((void*)(uintptr_t)(_val))\r
\r
#if DEBUG\r
-# define ENTER(...)\r
+# define ENTER(...) printf("%s: ---- ENTER ----\n", __func__);\r
# define LOG(s, ...) printf("%s: " s, __func__, __VA_ARGS__)\r
# define LOGS(s) printf("%s: " s, __func__)\r
# define LEAVE(...)\r
Elf32_Ehdr hdr;\r
\r
// Read ELF Header\r
- acess_read(FD, sizeof(hdr), &hdr);\r
+ acess_read(FD, &hdr, sizeof(hdr));\r
\r
// Check the file type\r
if(hdr.e_ident[0] != 0x7F || hdr.e_ident[1] != 'E' || hdr.e_ident[2] != 'L' || hdr.e_ident[3] != 'F') {\r
}\r
LOG("hdr.phoff = 0x%08x\n", hdr->phoff);\r
acess_seek(FD, hdr->phoff, ACESS_SEEK_SET);\r
- acess_read(FD, sizeof(Elf32_Phdr) * hdr->phentcount, phtab);\r
+ acess_read(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount);\r
\r
// Count Pages\r
iPageCount = 0;\r
// Load Pages\r
for( i = 0; i < hdr->phentcount; i++ )\r
{\r
- //LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type);\r
- LOG("phtab[%i] = {\n", i);\r
- LOG(" .Type = 0x%08x\n", phtab[i].Type);\r
- LOG(" .Offset = 0x%08x\n", phtab[i].Offset);\r
- LOG(" .VAddr = 0x%08x\n", phtab[i].VAddr);\r
- LOG(" .PAddr = 0x%08x\n", phtab[i].PAddr);\r
- LOG(" .FileSize = 0x%08x\n", phtab[i].FileSize);\r
- LOG(" .MemSize = 0x%08x\n", phtab[i].MemSize);\r
- LOG(" .Flags = 0x%08x\n", phtab[i].Flags);\r
- LOG(" .Align = 0x%08x\n", phtab[i].Align);\r
- LOGS(" }\n");\r
// Get Interpreter Name\r
if( phtab[i].Type == PT_INTERP )\r
{\r
//if(ret->Interpreter) continue;\r
tmp = malloc(phtab[i].FileSize);\r
acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
- acess_read(FD, phtab[i].FileSize, tmp);\r
+ acess_read(FD, tmp, phtab[i].FileSize);\r
//ret->Interpreter = Binary_RegInterp(tmp);\r
LOG("Interpreter '%s'\n", tmp);\r
free(tmp);\r
// Ignore non-LOAD types\r
if(phtab[i].Type != PT_LOAD) continue;\r
\r
- LOG("phtab[%i] = {VAddr:0x%x,Offset:0x%x,FileSize:0x%x}\n",\r
- i, phtab[i].VAddr+baseDiff, phtab[i].Offset, phtab[i].FileSize);\r
+ LOG("phtab[%i] = PT_LOAD {Adj VAddr:0x%x, Offset:0x%x, FileSize:0x%x, MemSize:0x%x}\n",\r
+ i, phtab[i].VAddr+baseDiff, phtab[i].Offset, phtab[i].FileSize, phtab[i].MemSize);\r
\r
addr = phtab[i].VAddr + baseDiff;\r
\r
}\r
\r
acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET);\r
- acess_read(FD, phtab[i].FileSize, PTRMK(void, addr) );\r
+ acess_read(FD, PTRMK(void, addr), phtab[i].FileSize);\r
memset( PTRMK(char, addr) + phtab[i].FileSize, 0, phtab[i].MemSize - phtab[i].FileSize );\r
}\r
\r
return _Syscall(SYS_REOPEN, ">i >s >i", FD, Path, Flags);
}
-size_t acess_read(int FD, size_t Bytes, void *Dest) {
+size_t acess_read(int FD, void *Dest, size_t Bytes) {
if(FD & NATIVE_FILE_MASK)
- return native_read(FD & (NATIVE_FILE_MASK-1), Bytes, Dest);
+ return native_read(FD & (NATIVE_FILE_MASK-1), Dest, Bytes);
DEBUG("read(0x%x, 0x%x, *%p)", FD, Bytes, Dest);
return _Syscall(SYS_READ, ">i >i <d", FD, Bytes, Bytes, Dest);
}
-size_t acess_write(int FD, size_t Bytes, const void *Src) {
+size_t acess_write(int FD, const void *Src, size_t Bytes) {
if(FD & NATIVE_FILE_MASK)
- return native_write(FD & (NATIVE_FILE_MASK-1), Bytes, Src);
+ return native_write(FD & (NATIVE_FILE_MASK-1), Src, Bytes);
DEBUG("write(0x%x, 0x%x, %p\"%.*s\")", FD, Bytes, Src, Bytes, (char*)Src);
return _Syscall(SYS_WRITE, ">i >i >d", FD, Bytes, Bytes, Src);
}
extern int native_open(const char *Path, int Flags);
extern void native_close(int FD);
-extern size_t native_read(int FD, size_t Bytes, void *Dest);
-extern size_t native_write(int FD, size_t Bytes, const void *Src);
+extern size_t native_read(int FD, void *Dest, size_t Bytes);
+extern size_t native_write(int FD, const void *Src, size_t Bytes);
extern int native_seek(int FD, int64_t Offset, int Dir);
extern uint64_t native_tell(int FD);
// Syscalls used by the linker
extern int acess_open(const char *Path, int Flags);
extern void acess_close(int FD);
-extern size_t acess_read(int FD, size_t Bytes, void *Dest);
+extern size_t acess_read(int FD, void *Dest, size_t Bytes);
extern int acess_seek(int FD, int64_t Offset, int Dir);
// Symbol type
gaSyscall_LocalFPs[FD] = NULL;
}
-size_t native_read(int FD, size_t Bytes, void *Dest)
+size_t native_read(int FD, void *Dest, size_t Bytes)
{
return fread( Dest, Bytes, 1, gaSyscall_LocalFPs[FD] );
}
-size_t native_write(int FD, size_t Bytes, const void *Src)
+size_t native_write(int FD, const void *Src, size_t Bytes)
{
return fwrite( Src, Bytes, 1, gaSyscall_LocalFPs[FD] );
}