summaryrefslogtreecommitdiff
path: root/src/Dolphin/os/__ppc_eabi_init.cpp
blob: a0e757483afb06a248450b4ee76861500688305d (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
56
57
58
59
60
61
62
63
64
65
66
67
// This file was taken from the Metroid Prime decompilation project.
// https://github.com/PrimeDecomp/prime/blob/main/src/Dolphin/os/__ppc_eabi_init.cpp
#include "dolphin/__ppc_eabi_init.h"
#include "dolphin/PPCArch.h"

#ifdef __cplusplus
extern "C" {
#endif
void __OSPSInit();
void __OSCacheInit();

asm void __init_hardware(void) {
	nofralloc
	mfmsr r0
	ori r0, r0, 0x2000
	mtmsr r0

	mflr r31
	bl __OSPSInit
	bl __OSCacheInit
	mtlr r31
	blr
}

asm void __flush_cache(register void* address, register unsigned int size) {
	// clang-format off
	nofralloc
	lis r5,  ~0
	ori r5, r5, ~14
	and r5, r5, r3
	subf r3, r5, r3
	add r4, r4, r3

loop:
	dcbst r0, r5
	sync
	icbi r0, r5
	addic r5, r5, 8
	subic. r4, r4, 8
	bge loop
	isync
	blr
	// clang-format on
}

void __init_user() { __init_cpp(); }

typedef void (*voidfunctionptr)(void); // pointer to function returning void
__declspec(section ".init") extern voidfunctionptr _ctors[];
__declspec(section ".init") extern voidfunctionptr _dtors[];

void __init_cpp(void) {
	voidfunctionptr* constructor;

	/*
	 *	call static initializers
	 */
	for (constructor = _ctors; *constructor; constructor++) {
		(*constructor)();
	}
}

void _ExitProcess(void) { PPCHalt(); }

#ifdef __cplusplus
}
#endif