2 AcessOS 1 - Dynamic Loader
\r
7 // === PROTOTYPES ===
\r
8 int DoRelocate( Uint base, char **envp, char *Filename );
\r
9 int CallUser(Uint entry, Uint SP);
\r
10 int ElfRelocate(void *Base, char *envp[], char *Filename);
\r
11 int PE_Relocate(void *Base, char *envp[], char *Filename);
\r
14 extern void gLinkedBase;
\r
18 \fn int SoMain(Uint base, int argc, char *argv[], char **envp)
\r
19 \brief Library entry point
\r
20 \note This is the entrypoint for the library
\r
22 int SoMain(Uint base, int arg1)
\r
26 //SysDebug("SoMain: base = 0x%x", base);
\r
27 //SysDebug("SoMain: arg1 = 0x%x", arg1);
\r
29 // - Assume that the file pointer will be less than 4096
\r
31 SysDebug("ld-acess - SoMain: Passed file pointer %i\n", base);
\r
35 // Check if we are being called directly
\r
36 if(base == (Uint)&gLinkedBase) {
\r
37 SysDebug("ld-acess should not be directly called\n");
\r
42 // Otherwise do relocations
\r
43 //ret = DoRelocate( base, envp, "Executable" );
\r
44 ret = DoRelocate( base, NULL, "Executable" );
\r
46 SysDebug("ld-acess - SoMain: Relocate failed, base=0x%x\n", base);
\r
52 //SysDebug("Calling User at 0x%x\n", ret);
\r
53 CallUser( ret, (Uint)&arg1 );
\r
59 \fn int DoRelocate(Uint base, char **envp)
\r
60 \brief Relocates an in-memory image
\r
62 int DoRelocate( Uint base, char **envp, char *Filename )
\r
65 if(*(Uint*)base == (0x7F|('E'<<8)|('L'<<16)|('F'<<24)))
\r
66 return ElfRelocate((void*)base, envp, Filename);
\r
67 if(*(Uint16*)base == ('M'|('Z'<<8)))
\r
68 return PE_Relocate((void*)base, envp, Filename);
\r
70 SysDebug("ld-acess - DoRelocate: Unkown file format '0x%x 0x%x 0x%x 0x%x'\n",
\r
71 *(Uint8*)(base), *(Uint8*)(base+1), *(Uint8*)(base+2), *(Uint8*)(base+3) );
\r
72 SysDebug("ld-acess - DoRelocate: File '%s'\n", Filename);
\r
78 \fn int CallUser(Uint entry, Uint sp)
\r
80 int CallUser(Uint entry, Uint sp)
\r
82 //SysDebug("CallUser: (entry=0x%x, sp=0x%x)", entry, sp);
\r
83 *(Uint*)(sp-4) = 0; // Clear return address
\r
84 __asm__ __volatile__ (
\r
85 "mov %%eax, %%esp;\n\t"
\r
87 : : "a"(sp), "c"(entry));
\r