summaryrefslogtreecommitdiffstats
path: root/source/load_elf.c
blob: 1519db8d229db77c4097b38b3d63bf104fa15f41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ogcsys.h>
#include <gccore.h>
#include <ogc/machine/processor.h>

#include "elf-loader.h"
#include "sync.h"
#include "gecko.h"

extern void __exception_closeall(void);

//taken from https://github.com/Fullmetal5/WiiNetworkLoader
//Note: There isn't any point for printf() messages, since you can't read them fast enough anyway
void boot_elf(void *payload, size_t size)
{

	gprintf("Shutting down IOS Subsystems... ");

	__IOS_ShutdownSubsystems();

	gprintf("OK");
	gprintf("Shutting down CPU ISR... ");

	uint32_t level;
	_CPU_ISR_Disable(level);

	gprintf("OK");
	gprintf("Shutting down exception vectors... ");

	__exception_closeall();

	gprintf("OK");
	gprintf("Copying ELF loading stub... ");


	memcpy((void*)0x81330000, loader_bin, loader_bin_len);
	sync_before_exec((void*)0x81330000, loader_bin_len);


	gprintf("OK");
	gprintf("Jumping to entry point!");


	void (*entry)(void*, uint32_t) = (void*)0x81330000;
	entry(payload, size);

	printf("If you can see this then something has gone very wrong!\n");

	gprintf("ELF failed to load somehow!");

	fflush(stdout);
	while(1);
}