Line 2:
Line 2:
==Functions==
==Functions==
−
===__LoaderStart()===
+
===__LoaderStart(bool user_req, LoaderRequest *request)===
__LoaderStart() is the entry point of loader.elf, the first function called by both the kernel on process startup and loader calls from OSDynLoad. It takes a caller argument from the kernel in r3, which is 0 if called on process startup and 1 if called from OSDynLoad. There is also a loader call buffer passed in r4. If the function has been called from OSDynLoad, it goes to LOADER_Entry() and processes the loader call. Otherwise, it continues and sets up the app address space.
__LoaderStart() is the entry point of loader.elf, the first function called by both the kernel on process startup and loader calls from OSDynLoad. It takes a caller argument from the kernel in r3, which is 0 if called on process startup and 1 if called from OSDynLoad. There is also a loader call buffer passed in r4. If the function has been called from OSDynLoad, it goes to LOADER_Entry() and processes the loader call. Otherwise, it continues and sets up the app address space.
===LOADER_Entry(LoaderRequest* request)===
===LOADER_Entry(LoaderRequest* request)===
+
LOADER_Entry() receives a [[#LoaderRequest|loader request buffer]] from the coreinit OSDynLoad functions. These are copied to the matching LoaderEntry global variables at the start of this method. The dispatch code is looked up in a jumptable, and used to call the appropriate loader function. Once the function completes, it calls a kernel syscall to return to the caller's context.
−
LoaderRequest structure:
+
==Structures==
−
+
===LoaderRequest===
−
<pre>
+
This structure is a request buffer created by the OSDynLoad functions and sent to the loader. It contains the saved context of the caller, the identifying process information, and the function number and arguments. Dispatch codes are from 0-11 (inclusive). After processing the request, the loader sends it back with a return value.
−
void* context; // 0
+
<syntaxhighlight lang="C">
−
int procId; // 4
+
typedef struct
−
void* procConfig; // 8
+
{
−
void* anotherContext? // 12
+
void *context;
−
char filler[24-12];// unknown
+
int procId;
−
int dispatchCode; // 24
+
void *procConfig;
−
</pre>
+
void *context2;
−
+
char unkc[0x14-0xc];
−
These are copied to the matching LoaderEntry global variables at the start of this method.
+
int returnVal;
−
+
int dispatchCode;
−
Dispatch codes are from 0-11 (inclusive).
+
} LoaderRequest;
+
</syntaxhighlight>