Skip to content

Commit

Permalink
Almost match all of Runtime.PPCEABI.H (STOLEN)
Browse files Browse the repository at this point in the history
Stolen Runtime.PPCEABI.H from Pikmin2, most of it matched instantly but
a couple of changes were required. Sadly, ExceptionPPC.cp I couldn't
match, as well as a couple finicky linker section things which I have no
idea how they work.
  • Loading branch information
Mrkol committed Dec 22, 2024
1 parent 4c2f6b0 commit fa95dea
Show file tree
Hide file tree
Showing 15 changed files with 1,237 additions and 41 deletions.
81 changes: 44 additions & 37 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,31 +314,63 @@ def MatchingFor(*versions):
],
},
{
"lib": "Runtime.PPCEABI.H",
"lib": "Player",
"mw_version": "GC/1.2.5",
"cflags": cflags_runtime,
"cflags": cflags_game,
"objects": [
Object(NonMatching, "Runtime.PPCEABI.H/__init_cpp_exceptions.cpp"),
Object(NonMatching, "Runtime.PPCEABI.H/Gecko_ExceptionPPC.cp"),
Object(NonMatching, "Runtime.PPCEABI.H/global_destructor_chain.c"),
Object(Matching, "Player/MarioAccess.cpp"),
],
},
{
"lib": "MSL_C.PPCEABI.bare.H",
"lib": "NPC",
"mw_version": "GC/1.2.5",
"cflags": cflags_game,
"objects": [
Object(Matching, "NPC/NpcBalloon.cpp"),
Object(Matching, "NPC/NpcInitActionData.cpp"),
],
},
{
"lib": "System",
"mw_version": "GC/1.2.5",
"cflags": cflags_system,
"objects": [
Object(
Matching,
"System/FlagManager.cpp",
cflags=[*cflags_system, "-inline all,level=1,deferred"],
),
Object(Matching, "System/ParamInst.cpp"),
Object(Matching, "System/ProcessMeter.cpp"),
Object(Matching, "System/Resolution.cpp"),
Object(Matching, "System/StageUtil.cpp"),
Object(Matching, "System/TexCache.cpp"),
],
},
{
"lib": "Runtime.PPCEABI.H",
"progress_category": "sdk",
"mw_version": "GC/1.2.5",
"cflags": cflags_runtime,
"objects": [
Object(Matching, "MSL_C.PPCEABI.bare.H/hyperbolicsf.c"),
Object(Matching, "MSL_C.PPCEABI.bare.H/rand.c"),
Object(Matching, "Runtime.PPCEABI.H/__mem.c"),
Object(Matching, "Runtime.PPCEABI.H/__va_arg.c"),
Object(Matching, "Runtime.PPCEABI.H/global_destructor_chain.c"),
Object(Matching, "Runtime.PPCEABI.H/NMWException.cp"),
Object(Matching, "Runtime.PPCEABI.H/ptmf.c"),
Object(Matching, "Runtime.PPCEABI.H/ExceptionPPC.cp"),
Object(Matching, "Runtime.PPCEABI.H/runtime.c"),
Object(Matching, "Runtime.PPCEABI.H/__init_cpp_exceptions.cpp"),
],
},
{
"lib": "NPC",
"lib": "MSL_C.PPCEABI.bare.H",
"progress_category": "sdk",
"mw_version": "GC/1.2.5",
"cflags": cflags_game,
"cflags": cflags_runtime,
"objects": [
Object(Matching, "NPC/NpcBalloon.cpp"),
Object(Matching, "NPC/NpcInitActionData.cpp"),
Object(Matching, "MSL_C.PPCEABI.bare.H/hyperbolicsf.c"),
Object(Matching, "MSL_C.PPCEABI.bare.H/rand.c"),
],
},
DolphinLib("base", [
Expand Down Expand Up @@ -444,31 +476,6 @@ def MatchingFor(*versions):
DolphinLib("odenotstub", [
Object(Matching, "odenotstub/odenotstub.c"),
]),
{
"lib": "Player",
"mw_version": "GC/1.2.5",
"cflags": cflags_game,
"objects": [
Object(Matching, "Player/MarioAccess.cpp"),
],
},
{
"lib": "System",
"mw_version": "GC/1.2.5",
"cflags": cflags_system,
"objects": [
Object(
Matching,
"System/FlagManager.cpp",
cflags=[*cflags_system, "-inline all,level=1,deferred"],
),
Object(Matching, "System/ParamInst.cpp"),
Object(Matching, "System/ProcessMeter.cpp"),
Object(Matching, "System/Resolution.cpp"),
Object(Matching, "System/StageUtil.cpp"),
Object(Matching, "System/TexCache.cpp"),
],
},
]

# Optional extra categories for progress tracking
Expand Down
34 changes: 34 additions & 0 deletions include/Runtime.PPCEABI.H/MWCPlusLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef _RUNTIME_MWCPLUSLIB_H
#define _RUNTIME_MWCPLUSLIB_H

#include "stddef.h"

#ifdef __cplusplus
extern "C" {
#endif

#define CTORARG_TYPE int
#define CTORARG_PARTIAL (0)
#define CTORARG_COMPLETE (1)

#define CTORCALL_COMPLETE(ctor, objptr) (((void (*)(void*, CTORARG_TYPE))ctor)(objptr, CTORARG_COMPLETE))

#define DTORARG_TYPE int

#define DTORCALL_COMPLETE(dtor, objptr) (((void (*)(void*, DTORARG_TYPE))dtor)(objptr, -1))
#define DTORCALL_PARTIAL(dtor, objptr) (((void (*)(void*, DTORARG_TYPE))dtor)(objptr, 0))

typedef void* ConstructorDestructor;

extern void __construct_array(void* ptr, ConstructorDestructor ctor, ConstructorDestructor dtor, size_t size, size_t n);
extern void __destroy_arr(void* block, ConstructorDestructor* dtor, size_t size, size_t n);
extern void* __construct_new_array(void* block, ConstructorDestructor ctor, ConstructorDestructor dtor_arg, size_t size, size_t n);
extern void __destroy_new_array(void* block, ConstructorDestructor dtor);
extern void __destroy_new_array2();
extern void __destroy_new_array3();

#ifdef __cplusplus
}
#endif

#endif
44 changes: 44 additions & 0 deletions include/Runtime.PPCEABI.H/NMWException.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef _NMWEXCEPTION
#define _NMWEXCEPTION

#include "dolphin/types.h"
#include "Runtime.PPCEABI.H/__ppc_eabi_linker.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef s16 vbase_ctor_arg_type;
typedef char local_cond_type;

typedef struct CatchInfo {
void* location;
void* typeinfo;
void* dtor;
void* sublocation;
s32 pointercopy;
void* stacktop;
} CatchInfo;

typedef struct DestructorChain {
struct DestructorChain* next;
void* destructor;
void* object;
} DestructorChain;

extern void* __register_global_object(void* object, void* destructor, void* registration);
extern void __destroy_global_chain(void);

extern void __end__catch(CatchInfo* catchinfo);
extern void __throw(char* throwtype, void* location, void* dtor);
extern char __throw_catch_compare(const char* throwtype, const char* catchtype, s32* offset_result);
extern void __unexpected(CatchInfo* catchinfo);

extern int __register_fragment(struct __eti_init_info* info, char* TOC);
extern void __unregister_fragment(int fragmentID);

#ifdef __cplusplus
}
#endif

#endif // _NMWEXCEPTION
9 changes: 5 additions & 4 deletions include/Runtime.PPCEABI.H/__mem.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#ifndef __MEM_H
#define __MEM_H
#ifndef _RUNTIME_MEM_H
#define _RUNTIME_MEM_H

#include "dolphin/types.h"
#include "stddef.h"

#ifdef __cplusplus
extern "C" {
#endif

void* memcpy(void* dest, const void* src, u32 n);
__declspec(section ".init") void* memcpy(void* dest, const void* src, size_t n);
__declspec(section ".init") void* memset(void* dest, int val, size_t count);

#ifdef __cplusplus
}
Expand Down
72 changes: 72 additions & 0 deletions include/Runtime.PPCEABI.H/__ppc_eabi_linker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef __PPC_EABI_LINKER
#define __PPC_EABI_LINKER

__declspec(section ".init") extern char _stack_addr[];
__declspec(section ".init") extern char _stack_end[];
__declspec(section ".init") extern char _heap_addr[];
__declspec(section ".init") extern char _heap_end[];
__declspec(section ".init") extern const char _fextabindex_rom[];
__declspec(section ".init") extern char _fextabindex[];
__declspec(section ".init") extern char _eextabindex[];

__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[];

typedef struct __eti_init_info {
void* eti_start;
void* eti_end;
void* code_start;
unsigned long code_size;
} __eti_init_info;

__declspec(section ".init") extern __eti_init_info _eti_init_info[];
__declspec(section ".init") extern const char _f_init_rom[];
__declspec(section ".init") extern char _f_init[];
__declspec(section ".init") extern char _e_init[];
__declspec(section ".init") extern const char _f_text_rom[];
__declspec(section ".init") extern char _f_text[];
__declspec(section ".init") extern char _e_text[];
__declspec(section ".init") extern const char _f_rodata_rom[];
__declspec(section ".init") extern char _f_rodata[];
__declspec(section ".init") extern char _e_rodata[];
__declspec(section ".init") extern const char _fextab_rom[];
__declspec(section ".init") extern char _fextab[];
__declspec(section ".init") extern char _eextab[];
__declspec(section ".init") extern const char _f_data_rom[];
__declspec(section ".init") extern char _f_data[];
__declspec(section ".init") extern char _e_data[];
__declspec(section ".init") extern char _f_bss[];
__declspec(section ".init") extern char _e_bss[];
__declspec(section ".init") extern const char _f_sdata_rom[];
__declspec(section ".init") extern char _f_sdata[];
__declspec(section ".init") extern char _e_sdata[];
__declspec(section ".init") extern char _f_sbss[];
__declspec(section ".init") extern char _e_sbss[];
__declspec(section ".init") extern const char _f_sdata2_rom[];
__declspec(section ".init") extern char _f_sdata2[];
__declspec(section ".init") extern char _e_sdata2[];
__declspec(section ".init") extern char _f_sbss2[];
__declspec(section ".init") extern char _e_sbss2[];
__declspec(section ".init") extern const char _f_PPC_EMB_sdata0_rom[];
__declspec(section ".init") extern char _f_PPC_EMB_sdata0[];
__declspec(section ".init") extern char _e_PPC_EMB_sdata0[];
__declspec(section ".init") extern char _f_PPC_EMB_sbss0[];
__declspec(section ".init") extern char _e_PPC_EMB_sbss0[];

#endif // __PPC_EABI_LINKER
34 changes: 34 additions & 0 deletions include/Runtime.PPCEABI.H/global_destructor_chain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef _GLOBALDESTRUCTORCHAIN
#define _GLOBALDESTRUCTORCHAIN

#ifdef __cplusplus
extern "C" {
#endif

#define CTORARG_TYPE int
#define CTORARG_PARTIAL (0)
#define CTORARG_COMPLETE (1)

#define CTORCALL_COMPLETE(ctor, objptr) (((void (*)(void*, CTORARG_TYPE))ctor)(objptr, CTORARG_COMPLETE))

#define DTORARG_TYPE int

#define DTORCALL_COMPLETE(dtor, objptr) (((void (*)(void*, DTORARG_TYPE))dtor)(objptr, -1))

typedef struct DestructorChain {
struct DestructorChain* next;
void* destructor;
void* object;
} DestructorChain;

void* __register_global_object(void* object, void* destructor, void* registration);

void __destroy_global_chain(void);

int __register_atexit(void (*)(void));

#ifdef __cplusplus
}
#endif

#endif
19 changes: 19 additions & 0 deletions include/Runtime.PPCEABI.H/runtime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _DOLPHIN_RUNTIME_H
#define _DOLPHIN_RUNTIME_H

#include "dolphin/types.h"

#ifdef __cplusplus
extern "C" {
#endif // ifdef __cplusplus

u32 __cvt_fp2unsigned(f64);
// TODO: The rest

void* __copy(char*, char*, size_t);

#ifdef __cplusplus
};
#endif // ifdef __cplusplus

#endif
40 changes: 40 additions & 0 deletions src/Runtime.PPCEABI.H/ExceptionPPC.cp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "Runtime.PPCEABI.H/NMWException.h"
#include "Runtime.PPCEABI.H/__ppc_eabi_linker.h"

typedef struct ProcessInfo {
__eti_init_info* exception_info;
char* TOC;
int active;
} ProcessInfo;

#define MAXFRAGMENTS 1
static ProcessInfo fragmentinfo[MAXFRAGMENTS];

int __register_fragment(struct __eti_init_info* info, char* TOC)
{
ProcessInfo* f = fragmentinfo;
int i;

for (i = 0; i < MAXFRAGMENTS; i++, f++) {
if (f->active == 0) {
f->exception_info = info;
f->TOC = TOC;
f->active = 1;
return i;
}
}

return -1;
}

void __unregister_fragment(int fragmentID)
{
ProcessInfo* f;

if (fragmentID >= 0 && fragmentID < MAXFRAGMENTS) {
f = &fragmentinfo[fragmentID];
f->exception_info = 0;
f->TOC = 0;
f->active = 0;
}
}
Loading

0 comments on commit fa95dea

Please sign in to comment.