From 5756e35dfd64e6583835c870d4051f091b333ab6 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Mon, 21 Aug 2023 16:34:39 +0200 Subject: [PATCH] link executor --- config/rel_slices.yml | 4 +++ include/executor.h | 10 ++++++++ include/main.h | 2 ++ rel/executor.c | 44 +++++++++++++++++++++++++++++++++ src/dolphin/__ppc_eabi_init.cpp | 9 ++----- 5 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 include/executor.h create mode 100644 rel/executor.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index ce43852b..17da8bbf 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -1,3 +1,7 @@ +executor.c: + .text: [0x803702A8, 0x803703F8] + .data: [0x8064D500, 0x8064D580] + .bss: [0x8125A7C0, 0x8125A7C8] sys_vimgr.c: .text: [0x803703F8, 0x80370418] c_keyframe.c: diff --git a/include/executor.h b/include/executor.h new file mode 100644 index 00000000..63d898d1 --- /dev/null +++ b/include/executor.h @@ -0,0 +1,10 @@ +#ifndef EXECUTOR_H +#define EXECUTOR_H + +#include "types.h" + +void _prolog(); +void _epilog(); +void _unresolved(); + +#endif diff --git a/include/main.h b/include/main.h index 53341f03..d395446c 100644 --- a/include/main.h +++ b/include/main.h @@ -20,6 +20,8 @@ extern int ScreenHeight; extern OSThread graphThread; extern u8 SegmentBaseAddress[0x40]; +void foresta_main(); + #ifdef __cplusplus } #endif diff --git a/rel/executor.c b/rel/executor.c new file mode 100644 index 00000000..c91871cb --- /dev/null +++ b/rel/executor.c @@ -0,0 +1,44 @@ +#include "executor.h" + +#include "dolphin/os/__ppc_eabi_init.h" +#include "dolphin/os.h" +#include "dolphin/os/OSContext.h" +#include "terminal.h" +#include "main.h" + +BOOL construct_skip; + +void _prolog() { + voidfunctionptr *constructor; + + /* call static initializers */ + if (!construct_skip) { + for (constructor = _ctors; *constructor; constructor++) { + (*constructor)(); + } + } + foresta_main(); +} + +void _epilog() { + voidfunctionptr *destructor; + + /* call static destructors */ + for (destructor = _dtors; *destructor; destructor++) { + (*destructor)(); + } +} + +void _unresolved() { + u32 i; + u32* p; + + OSReport(VT_COL(RED, WHITE) "\nError: A called an unlinked function.\n"); + OSReport("Address: Back Chain LR Save\n"); + + for (i = 0, p = (u32*)OSGetStackPointer(); p && (u32)p != 0xffffffff && i++ < 16; p = (u32*)*p) { + OSReport("0x%08x: 0x%08x 0x%08x\n", p, p[0], p[1]); + } + + OSReport("\n" VT_RST "\n"); +} \ No newline at end of file diff --git a/src/dolphin/__ppc_eabi_init.cpp b/src/dolphin/__ppc_eabi_init.cpp index 931164e9..93b67f0e 100644 --- a/src/dolphin/__ppc_eabi_init.cpp +++ b/src/dolphin/__ppc_eabi_init.cpp @@ -1,17 +1,13 @@ #include "types.h" #include "dolphin/os.h" #include "dolphin/PPCArch.h" - +#include "dolphin/os/__ppc_eabi_init.h" #ifdef __cplusplus extern "C" { #endif -typedef void (*voidfunctionptr)(void); // pointer to function returning void -__declspec(section ".ctors") extern voidfunctionptr _ctors[]; -__declspec(section ".dtors") extern voidfunctionptr _dtors[]; static void __init_cpp(void); -// clang-format off __declspec(section ".init") asm void __init_hardware(void) { nofralloc mfmsr r0 @@ -24,7 +20,7 @@ __declspec(section ".init") asm void __init_hardware(void) { blr } -__declspec(section ".init") asm void __flush_cache(void) { +__declspec(section ".init") asm void __flush_cache(void*, size_t) { nofralloc lis r5, 0xFFFFFFF1@h ori r5, r5, 0xFFFFFFF1@l @@ -41,7 +37,6 @@ loop: isync blr } -// clang-format on void __init_user(void) { __init_cpp(); }