mirror of
https://github.com/zeldaret/ss
synced 2026-08-03 08:43:32 -04:00
Setup REL runtime
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
#include <REL/executor.h>
|
||||
|
||||
void _prolog(void) {
|
||||
ModuleConstructorsX(_ctors);
|
||||
ModuleProlog();
|
||||
}
|
||||
|
||||
void _epilog(void) {
|
||||
ModuleEpilog();
|
||||
ModuleDestructorsX(_dtors);
|
||||
}
|
||||
|
||||
void _unresolved(void) {
|
||||
ModuleUnresolved();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <Runtime.PPCEABI.H/__init_cpp_exceptions.h>
|
||||
#include <Runtime.PPCEABI.H/__ppc_eabi_linker.h>
|
||||
#include <Runtime.PPCEABI.H/NMWException.h>
|
||||
|
||||
#if __MWERKS__
|
||||
#pragma exceptions off
|
||||
#pragma internal on
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void __init_cpp_exceptions(void);
|
||||
extern void __fini_cpp_exceptions(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fragmentID = -2;
|
||||
|
||||
void __init_cpp_exceptions(void) {
|
||||
register char* R2;
|
||||
if (fragmentID == -2) {
|
||||
__asm {
|
||||
mr R2, r2
|
||||
}
|
||||
fragmentID = __register_fragment(_eti_init_info, R2);
|
||||
}
|
||||
}
|
||||
|
||||
void __fini_cpp_exceptions(void) {
|
||||
if (fragmentID != -2) {
|
||||
__unregister_fragment(fragmentID);
|
||||
fragmentID = -2;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma push
|
||||
// HACK: When DTK sets all objects to force_active, the linker decides to strip
|
||||
// these, for some reason. Set them to force_active as well.
|
||||
#pragma force_active on
|
||||
|
||||
#pragma section ".ctors$10"
|
||||
__declspec(section ".ctors$10")
|
||||
extern void * const __init_cpp_exceptions_reference = __init_cpp_exceptions;
|
||||
#pragma section ".dtors$10"
|
||||
__declspec(section ".dtors$10")
|
||||
extern void * const __destroy_global_chain_reference = __destroy_global_chain;
|
||||
#pragma section ".dtors$15"
|
||||
__declspec(section ".dtors$15")
|
||||
extern void * const __fini_cpp_exceptions_reference = __fini_cpp_exceptions;
|
||||
|
||||
#pragma pop
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <Runtime.PPCEABI.H/NMWException.h>
|
||||
|
||||
DestructorChain* __global_destructor_chain;
|
||||
|
||||
void* __register_global_object(void* object, void* destructor, void* regmem) {
|
||||
((DestructorChain*)regmem)->next = __global_destructor_chain;
|
||||
((DestructorChain*)regmem)->destructor = destructor;
|
||||
((DestructorChain*)regmem)->object = object;
|
||||
__global_destructor_chain = (DestructorChain*)regmem;
|
||||
return object;
|
||||
}
|
||||
|
||||
void __destroy_global_chain(void) {
|
||||
DestructorChain* iter;
|
||||
while ((iter = __global_destructor_chain) != 0) {
|
||||
__global_destructor_chain = iter->next;
|
||||
DTORCALL(iter->destructor, iter->object);
|
||||
}
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
#pragma section ".dtors$10"
|
||||
__declspec(section ".dtors$10") __declspec(weak)
|
||||
extern void * const __destroy_global_chain_reference = __destroy_global_chain;
|
||||
/* clang-format on */
|
||||
Reference in New Issue
Block a user