summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-01-29 17:11:40 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-01-29 17:11:40 -0400
commit9943fe31f61f4f632064cbc3c4fce9bd7bfe21ae (patch)
treeb6fedfac2ebedf6394ea557f156ad606085157dc
parent3125154316a235574579e9d25985236bd799982b (diff)
__start: Use `__start` from the Super Mario Sunshine decomp project
Link to project: https://github.com/doldecomp/sms
-rw-r--r--include/__start.h46
-rw-r--r--include/dolphin/__start.h54
-rw-r--r--src/Dolphin/os/__start.c150
3 files changed, 132 insertions, 118 deletions
diff --git a/include/__start.h b/include/__start.h
deleted file mode 100644
index 1cf3da4..0000000
--- a/include/__start.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// This file was taken from the Metroid Prime decompilation project.
-// https://github.com/PrimeDecomp/prime/blob/main/include/dolphin/__start.h
-#ifndef _DOLPHIN__START
-#define _DOLPHIN__START
-
-#include "dolphin/db.h"
-#include "types.h"
-
-#define PAD3_BUTTON_ADDR 0x800030E4
-#define OS_RESET_RESTART 0
-#define EXCEPTIONMASK_ADDR 0x80000044
-#define BOOTINFO2_ADDR 0x800000F4
-#define OS_BI2_DEBUGFLAG_OFFSET 0xC
-#define ARENAHI_ADDR 0x80000034
-#define DEBUGFLAG_ADDR 0x800030E8
-#define DVD_DEVICECODE_ADDR 0x800030E6
-
-#define MSR_FP 0x2000
-
-extern void InitMetroTRK();
-
-u16 Pad3Button : PAD3_BUTTON_ADDR;
-static u8 Debug_BBA = 0;
-
-extern void memset(void*, int, int);
-extern int main(int argc, char* argv[]);
-extern void exit(int);
-extern void __init_user(void);
-extern void OSInit(void);
-extern void DBInit(void);
-extern void OSResetSystem(BOOL reset, u32 resetCode, BOOL forceMenu);
-extern void __OSCacheInit(void);
-extern void __OSPSInit(void);
-
-__declspec(section ".init") extern void __check_pad3(void);
-__declspec(section ".init") extern void __start(void);
-__declspec(section ".init") extern void __init_registers(void);
-__declspec(section ".init") extern void __init_data(void);
-__declspec(section ".init") extern void __init_hardware(void);
-__declspec(section ".init") extern void __flush_cache(void* address, unsigned int size);
-
-__declspec(section ".init") extern char _stack_addr[];
-__declspec(section ".init") extern char _SDA_BASE_[];
-__declspec(section ".init") extern char _SDA2_BASE_[];
-
-#endif // _DOLPHIN__START
diff --git a/include/dolphin/__start.h b/include/dolphin/__start.h
index 07bb2bf..1b74138 100644
--- a/include/dolphin/__start.h
+++ b/include/dolphin/__start.h
@@ -1,6 +1,52 @@
-unsigned short Pad3Button : 0x800030e4;
+// This file was taken from the Super Mario Sunshine decompilation project.
+// https://github.com/doldecomp/sms/blob/master/include/dolphin/__start.h
+#include "dolphin/types.h"
+#include "dolphin/db.h"
-extern int main(int argc, char **argv);
+#define PAD3_BUTTON_ADDR 0x800030E4
+#define OS_RESET_RESTART 0
+#define FALSE 0
+#define TRUE 1
+#define EXCEPTIONMASK_ADDR 0x80000044
+#define BOOTINFO2_ADDR 0x800000F4
+#define OS_BI2_DEBUGFLAG_OFFSET 0xC
+#define ARENAHI_ADDR 0x80000034
+#define DEBUGFLAG_ADDR 0x800030E8
+#define DVD_DEVICECODE_ADDR 0x800030E6
-__declspec(section ".init") void __check_pad3(void);
-__declspec(section ".init") void __start(void);
+extern void InitMetroTRK();
+
+u16 Pad3Button : PAD3_BUTTON_ADDR;
+
+extern void memset(void*, int, int);
+extern int main(int argc, char* argv[]);
+extern void exit(int);
+extern void __init_user(void);
+extern void InitMetroTRK_BBA(void);
+extern void OSInit(void);
+extern void OSResetSystem(BOOL reset, u32 resetCode, BOOL forceMenu);
+extern void __init_hardware(void);
+
+__declspec(section ".init") extern void __check_pad3(void);
+__declspec(section ".init") extern void __start(void);
+__declspec(section ".init") extern void __init_registers(void);
+__declspec(section ".init") extern void __init_data(void);
+
+__declspec(section ".init") extern char _stack_addr[];
+__declspec(section ".init") extern char _SDA_BASE_[];
+__declspec(section ".init") extern char _SDA2_BASE_[];
+
+typedef struct __rom_copy_info {
+ char* rom;
+ char* addr;
+ unsigned int size;
+} __rom_copy_info;
+
+__declspec(section ".init") extern __rom_copy_info _rom_copy_info[];
+
+typedef struct __bss_init_info {
+ char* addr;
+ unsigned int size;
+} __bss_init_info;
+
+__declspec(section ".init") extern __bss_init_info _bss_init_info[];
diff --git a/src/Dolphin/os/__start.c b/src/Dolphin/os/__start.c
index 1113e15..cebb086 100644
--- a/src/Dolphin/os/__start.c
+++ b/src/Dolphin/os/__start.c
@@ -1,48 +1,52 @@
-// This file was taken from the Metroid Prime decompilation project.
-// https://github.com/PrimeDecomp/prime/blob/main/src/Dolphin/os/__start.c
+// This file was taken from the Super Mario Sunshine decompilation project.
+// https://github.com/doldecomp/sms/blob/master/src/os/__start.c
#include "dolphin/__start.h"
-#include "__ppc_eabi_linker.h"
-void __check_pad3(void) {
- if ((Pad3Button & 0x0eef) == 0x0eef) {
- OSResetSystem(OS_RESET_RESTART, 0, FALSE);
- }
- return;
+#pragma section code_type ".init"
+
+void __check_pad3(void)
+{
+ if ((Pad3Button & 0x0eef) == 0x0eef) {
+ OSResetSystem(OS_RESET_RESTART, 0, FALSE);
+ }
+ return;
}
-__declspec(weak) asm void __start(void) {
- // clang-format off
- nofralloc
+// clang-format off
+
+__declspec (weak) asm void __start(void)
+{
+ nofralloc
bl __init_registers
- bl __init_hardware
- li r0, -1
- stwu r1, -8(r1)
- stw r0, 4(r1)
- stw r0, 0(r1)
- bl __init_data
- li r0, 0
- lis r6, EXCEPTIONMASK_ADDR@ha
- addi r6, r6, EXCEPTIONMASK_ADDR@l
- stw r0, 0(r6)
- lis r6, BOOTINFO2_ADDR@ha
- addi r6, r6, BOOTINFO2_ADDR@l
- lwz r6, 0(r6)
+ bl __init_hardware
+ li r0, -1
+ stwu r1, -8(r1)
+ stw r0, 4(r1)
+ stw r0, 0(r1)
+ bl __init_data
+ li r0, 0
+ lis r6, EXCEPTIONMASK_ADDR@ha
+ addi r6, r6, EXCEPTIONMASK_ADDR@l
+ stw r0, 0(r6)
+ lis r6, BOOTINFO2_ADDR@ha
+ addi r6, r6, BOOTINFO2_ADDR@l
+ lwz r6, 0(r6)
_check_TRK:
- cmplwi r6, 0
- beq _load_lomem_debug_flag
- lwz r7, OS_BI2_DEBUGFLAG_OFFSET(r6)
- b _check_debug_flag
+ cmplwi r6, 0
+ beq _load_lomem_debug_flag
+ lwz r7, OS_BI2_DEBUGFLAG_OFFSET(r6)
+ b _check_debug_flag
_load_lomem_debug_flag:
lis r5, ARENAHI_ADDR@ha
addi r5, r5, ARENAHI_ADDR@l
- lwz r5, 0(r5)
- cmplwi r5, 0
- beq _goto_main
- lis r7, DEBUGFLAG_ADDR@ha
- addi r7, r7, DEBUGFLAG_ADDR@l
- lwz r7, 0(r7)
+ lwz r5, 0(r5)
+ cmplwi r5, 0
+ beq _goto_main
+ lis r7, DEBUGFLAG_ADDR@ha
+ addi r7, r7, DEBUGFLAG_ADDR@l
+ lwz r7, 0(r7)
_check_debug_flag:
li r5, 0
@@ -100,22 +104,21 @@ _end_of_parseargs:
beq _check_pad3
andi. r3, r3, 0x7fff
cmplwi r3, 1
- bne _goto_skip_init_bba
+ bne _skip_crc
_check_pad3:
bl __check_pad3
-_goto_skip_init_bba:
+_skip_crc:
bl __init_user
mr r3, r14
mr r4, r15
bl main
b exit
- // clang-format on
}
-asm static void __init_registers(void) {
- // clang-format off
+asm static void __init_registers(void)
+{
nofralloc
lis r1, _stack_addr@h
ori r1, r1, _stack_addr@l
@@ -124,40 +127,51 @@ asm static void __init_registers(void) {
lis r13, _SDA_BASE_@h
ori r13, r13, _SDA_BASE_@l
blr
- // clang-format on
}
-inline static void __copy_rom_section(void* dst, const void* src, unsigned long size) {
- if (size && (dst != src)) {
- memcpy(dst, src, size);
- __flush_cache(dst, size);
- }
+__declspec(section ".init") extern __rom_copy_info _rom_copy_info[];
+__declspec(section ".init") extern __bss_init_info _bss_init_info[];
+
+// clang-format on
+
+inline static void __copy_rom_section(void* dst, const void* src,
+ unsigned long size)
+{
+ if (size && (dst != src)) {
+ memcpy(dst, src, size);
+ __flush_cache(dst, size);
+ }
}
-inline static void __init_bss_section(void* dst, unsigned long size) {
- if (size) {
- memset(dst, 0, size);
- }
+inline static void __init_bss_section(void* dst, unsigned long size)
+{
+ if (size) {
+ memset(dst, 0, size);
+ }
}
#pragma scheduling off
-void __init_data(void) {
- __rom_copy_info* dci;
- __bss_init_info* bii;
-
- dci = _rom_copy_info;
- while (TRUE) {
- if (dci->size == 0)
- break;
- __copy_rom_section(dci->addr, dci->rom, dci->size);
- dci++;
- }
-
- bii = _bss_init_info;
- while (TRUE) {
- if (bii->size == 0)
- break;
- __init_bss_section(bii->addr, bii->size);
- bii++;
- }
+#pragma peephole off
+// peephole might have been turned off due to the inline asm peephole bug
+// which turns off peephole optimizations after an inline-asm function
+void __init_data(void)
+{
+ __rom_copy_info* dci;
+ __bss_init_info* bii;
+
+ dci = _rom_copy_info;
+ while (TRUE) {
+ if (dci->size == 0)
+ break;
+ __copy_rom_section(dci->addr, dci->rom, dci->size);
+ dci++;
+ }
+
+ bii = _bss_init_info;
+ while (TRUE) {
+ if (bii->size == 0)
+ break;
+ __init_bss_section(bii->addr, bii->size);
+ bii++;
+ }
}