Link Runtime linker files

This commit is contained in:
1superchip 2023-07-21 12:03:03 -05:00
parent 2077e90e97
commit ebe1097e96
14 changed files with 413 additions and 43 deletions

View File

@ -9,8 +9,8 @@ SECTIONS
GROUP:
{
.init ALIGN(0x20) : {}
extab_ ALIGN(0x20) : {}
extabindex_ ALIGN(0x20) : {}
extab ALIGN(0x20) : {}
extabindex ALIGN(0x20) : {}
.text ALIGN(0x20) : {}
.ctors ALIGN(0x20) : {}
.dtors ALIGN(0x20) : {}

View File

@ -7,9 +7,9 @@ section_defs:
- name: .init
- name: .text
data:
- name: extab_
- name: extab
attr: a
- name: extabindex_
- name: extabindex
attr: a
- name: .ctors
balign: 0

View File

@ -2906,17 +2906,10 @@ Dolphin/os/OSThread.c:
# Dolphin/linker_info.s:
# .init: [0x8000556C, 0x80005620]
# Dolphin/_eti_init_info.s:
# extabindex_: [0x80005658, 0x80005680]
Dolphin/os/__ppc_eabi_init.cpp:
.text: [0x801dc038, 0x801dc0cc]
.init: [0x80003354, 0x800033a8]
# this slice is needed until the rest of the file is decompiled
# Dolphin/__ppc_eabi_init.s:
# .text: [0x801DC058, 0x801DC0AC]
#db.c:
# .text: [0x801dc0cc, 0x801dc1b8]
# .data: [0x80271520, 0x80271538]
@ -3038,10 +3031,10 @@ Dolphin/os/__ppc_eabi_init.cpp:
# .text: [0x801e9d78, 0x801e9d78]
# .sdata: [0x803f97c8, 0x803f97d0]
# Runtime/abort_exit.c:
# .text: [0x801e9d78, 0x801e9e44]
# .bss: [0x802d5ce8, 0x802d5de8]
# .sbss: [0x803fb028, 0x803fb038]
Runtime/abort_exit.c:
.text: [0x801e9d78, 0x801e9e44]
.bss: [0x802d5ce8, 0x802d5de8]
.sbss: [0x803fb028, 0x803fb038]
#alloc.c:
# .text: [0x801e9e44, 0x801eac2c]
@ -3250,18 +3243,18 @@ Runtime/__mem.c:
#__va_arg.c:
# .text: [0x801f6b48, 0x801f6c10]
# Runtime/global_destructor_chain.c:
# .text: [0x801f6c10, 0x801f6c58]
# # .dtors: [0x8023caa8, 0x8023CAAC]
# .sbss: [0x803fb078, 0x803fb080]
# Runtime/__global_destructor_chain_dtor_slice.s:
Runtime/global_destructor_chain.c:
.text: [0x801f6c10, 0x801f6c58]
# .dtors: [0x8023caa8, 0x8023CAAC]
.sbss: [0x803fb078, 0x803fb080]
# Runtime/NMWException.cpp:
# .text: [0x801f6c58, 0x801f6e08]
# extab: [0x80005620, 0x80005640]
# extabindex: [0x80005640, 0x80005680]
Runtime/__global_destructor_chain_dtor_slice.s:
.dtors: [0x8023caa8, 0x8023CAAC]
Runtime/NMWException.cpp:
.text: [0x801f6c58, 0x801f6e08]
extab: [0x80005620, 0x80005640]
extabindex: [0x80005640, 0x80005680]
Runtime/ptmf.c:
.text: [0x801f6e08, 0x801f6e9c]
@ -3271,21 +3264,18 @@ Runtime/ptmf.c:
# .text: [0x801f6e9c, 0x801f762c]
# .rodata: [0x8023f920, 0x8023f938]
# Runtime/__init_cpp_exceptions.cpp:
# .text: [0x801f762c, 0x801f76a8]
# # .ctors: [0x8023c780, 0x8023c784] # what??
# .dtors: [0x8023caa0, 0x8023caa8]
# .sdata: [0x803f9820, 0x803F9828]
Runtime/__init_cpp_exceptions.cpp:
.text: [0x801f762c, 0x801f76a8]
# .ctors: [0x8023c780, 0x8023c784] # what??
.dtors: [0x8023caa0, 0x8023caa8]
.sdata: [0x803f9820, 0x803F9828]
# Runtime/__init_cpp_exceptions_ctor_slice.s:
# .ctors: [0x8023c780, 0x8023c784]
Runtime/__init_cpp_exceptions_ctor_slice.cpp:
.ctors: [0x8023c780, 0x8023c784]
# Runtime/__init_cpp_exceptions_ctor_slice.cpp:
# .ctors: [0x8023c780, 0x8023c784]
# Runtime/Gecko_ExceptionPPC.cpp:
# .text: [0x801f76a8, 0x801f7710]
# .bss: [0x802d6120, 0x802d6130]
Runtime/Gecko_ExceptionPPC.cpp:
.text: [0x801f76a8, 0x801f7710]
.bss: [0x802d6120, 0x802d6130]
#GCN_mem_alloc.c:
# .text: [0x801f7710, 0x801f7880]
@ -3737,9 +3727,9 @@ common/gc/Blitter.cpp:
.sbss: [0x803fb578, 0x803fb580]
.sdata2: [0x80402720, 0x80402760]
#Debug.cpp:
# .text: [0x8023c760, 0x8023C780]
# .sbss: [0x803fb580, 0x803FB5A0] # ?
common/Debug.cpp:
.text: [0x8023c760, 0x8023C780]
.sbss: [0x803fb580, 0x803FB5A0] # ?
#Dolphin/_init_registers.s:
# .init: [0x80003278, 0x80003294]

View File

@ -0,0 +1,73 @@
#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

View File

@ -69,8 +69,8 @@ if __name__=="__main__":
print("Warning: progress for sections other than .text isn't fully accurate")
dol_secs = [
".init",
"extab_",
"extabindex_",
"extab",
"extabindex",
".text",
".ctors",
".dtors",

View File

@ -0,0 +1,40 @@
#include "__ppc_eabi_linker.h"
#include "../src/Runtime/NMWException.h"
#if __MWERKS__
#pragma exceptions on
#endif
typedef struct ProcessInfo {
__eti_init_info* exception_info;
char* TOC;
int active;
} ProcessInfo;
static ProcessInfo fragmentinfo[1];
int __register_fragment(struct __eti_init_info* info, char* TOC) {
ProcessInfo* f;
int i;
for (i = 0, f = fragmentinfo; i < 1; ++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 < 1) {
f = &fragmentinfo[fragmentId];
f->exception_info = 0;
f->TOC = 0;
f->active = 0;
}
}

View File

@ -0,0 +1,49 @@
#include "../src/Runtime/NMWException.h"
#pragma exceptions on
class __partial_array_destructor {
private:
void* p;
size_t size;
size_t n;
void* dtor;
public:
size_t i;
__partial_array_destructor(void* array, size_t elementsize, size_t nelements, void* destructor) {
p = array;
size = elementsize;
n = nelements;
dtor = destructor;
i = n;
}
~__partial_array_destructor() {
char* ptr;
if (i < n && dtor) {
for (ptr = (char*)p + size * i; i > 0; i--) {
ptr -= size;
DTORCALL_COMPLETE(dtor, ptr);
}
}
}
};
extern "C" void __construct_array(void* ptr, void* ctor, void* dtor, size_t size, size_t n) {
__partial_array_destructor pad(ptr, size, n, dtor);
char* p;
for (pad.i = 0, p = (char*)ptr; pad.i < n; pad.i++, p += size)
CTORCALL_COMPLETE(ctor, p);
}
extern "C" void __destroy_arr(void* block, void* dtor, size_t size, size_t n) {
char* p;
for (p = (char*)block + size * n; n > 0; n--) {
p -= size;
DTORCALL_COMPLETE(dtor, p);
}
}

View File

@ -0,0 +1,55 @@
#ifndef _NMWEXCEPTION
#define _NMWEXCEPTION
// #include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define offsetof(type, member) ((size_t) & (((type*)0)->member))
/* These break 1.2.5 */
//typedef __typeof__(sizeof(0)) size_t;
//typedef __typeof__((char*)0 - (char*)0) ptrdiff_t;
typedef unsigned long size_t;
typedef long ptrdiff_t;
#ifndef NULL
#define NULL 0L
#endif
#ifdef __cplusplus
}
#endif
#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 __unregister_fragment(int fragmentID);
int __register_fragment(struct __eti_init_info* info, char* TOC);
void* __register_global_object(void* object, void* destructor, void* regmem);
void __destroy_global_chain(void);
#ifdef __cplusplus
}
#endif
#endif // _NMWEXCEPTION

View File

@ -0,0 +1,62 @@
#include "../src/Runtime/NMWException.h"
#include "__ppc_eabi_linker.h"
#pragma force_active on
static int fragmentID = -2;
#ifdef __cplusplus
extern "C" {
#endif
extern void __init_cpp_exceptions(void);
extern void __fini_cpp_exceptions(void);
extern void suspend(void);
#ifdef __cplusplus
}
#endif
/* clang-format off */
static asm char* GetR2() {
nofralloc;
mr r3, r2
blr
}
/* clang-format on */
extern void __init_cpp_exceptions(void) {
char* R2;
if (fragmentID == -2) {
R2 = GetR2();
fragmentID = __register_fragment(_eti_init_info, R2);
}
}
extern void __fini_cpp_exceptions(void) {
if (fragmentID != -2) {
__unregister_fragment(fragmentID);
fragmentID = -2;
}
}
/*
// this order doesn't seem to match
// __fini_cpp_exceptions_reference needs to come before __destroy_global_chain_reference
__declspec(section
".ctors") static void* const __init_cpp_exceptions_reference = __init_cpp_exceptions;
__declspec(section
".dtors") static void* const __destroy_global_chain_reference = __destroy_global_chain;
__declspec(section
".dtors") static void* const __fini_cpp_exceptions_reference = __fini_cpp_exceptions;
*/
// __declspec(section
// ".ctors") static void* const __init_cpp_exceptions_reference = __init_cpp_exceptions;
__declspec(section
".dtors") static void* const __fini_cpp_exceptions_reference = __fini_cpp_exceptions;
__declspec(section
".dtors") static void* const __destroy_global_chain_reference = __destroy_global_chain;

View File

@ -0,0 +1,18 @@
#ifdef __cplusplus
extern "C" {
#endif
void __init_cpp_exceptions(void);
extern void __fini_cpp_exceptions(void);
extern void suspend(void);
#ifdef __cplusplus
}
#endif
#pragma force_active on
__declspec(section
".ctors") static void* const __init_cpp_exceptions_reference = __init_cpp_exceptions;
// extern void* __init_cpp_exceptions_reference;

40
src/Runtime/abort_exit.c Normal file
View File

@ -0,0 +1,40 @@
// #include <stdlib.h>
#define NULL ((void*)0)
void __destroy_global_chain(void);
void _ExitProcess(void);
extern void (*_dtors[])(void);
static void (*__console_exit)(void);
void (*__stdio_exit)(void);
static int __atexit_curr_func;
int __aborting;
static void (*__atexit_funcs[64])(void);
void exit(int status) {
int i;
void (**dtor)(void);
if (!__aborting) {
__destroy_global_chain();
dtor = _dtors;
while (*dtor != NULL) {
(*dtor)();
dtor++;
}
if (__stdio_exit != NULL) {
__stdio_exit();
__stdio_exit = NULL;
}
}
while (__atexit_curr_func > 0)
__atexit_funcs[--__atexit_curr_func]();
if (__console_exit != NULL) {
__console_exit();
__console_exit = NULL;
}
_ExitProcess();
}

View File

@ -0,0 +1,26 @@
#include "../src/Runtime/NMWException.h"
DestructorChain* __global_destructor_chain;
extern 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_COMPLETE(iter->destructor, iter->object);
}
}
__declspec(section
".dtors") static void* const __destroy_global_chain_reference = __destroy_global_chain;

17
src/common/Debug.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "types.h"
struct Font {};
Font* gpDebugFont;
void Debug_InitModule(void) {
gpDebugFont = NULL;
}
void Debug_DeinitModule(void) {
}
void Debug_SetFont(Font* mDebugFont) {
gpDebugFont = mDebugFont;
}