From 594e90414549029a8be6f84922d68411340b61f5 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Sun, 1 Jan 2023 22:06:28 +0100 Subject: [PATCH] link reconfigbats and sdk stuff --- config/dol_slices.yml | 21 ++-- config/rel_slices.yml | 2 +- include/dolphin/OSArena.h | 18 +++ include/dolphin/OSCache.h | 30 +++++ include/dolphin/OSMemory.h | 7 ++ include/dolphin/os.h | 8 +- include/dolphin/ppcarch.h | 36 ++++++ include/libforest/batconfig.h | 8 +- include/libforest/fault.h | 54 +++++++++ include/libultra/gfxprint.h | 3 +- src/BASE/ppcarch.c | 96 +++++++++++++++ src/OS/OSArena.c | 20 ++++ src/OS/OSCache.c | 215 ++++++++++++++++++++++++++++++++++ src/OS/OSDisableInterrupts.c | 2 - src/libforest/ReconfigBATs.c | 26 ++-- src/libforest/fault.c | 10 ++ tools/ppcdis | 2 +- 17 files changed, 528 insertions(+), 30 deletions(-) create mode 100644 include/dolphin/OSArena.h create mode 100644 include/dolphin/OSCache.h create mode 100644 include/dolphin/OSMemory.h create mode 100644 include/dolphin/ppcarch.h create mode 100644 include/libforest/fault.h create mode 100644 src/BASE/ppcarch.c create mode 100644 src/OS/OSArena.c create mode 100644 src/OS/OSCache.c create mode 100644 src/libforest/fault.c diff --git a/config/dol_slices.yml b/config/dol_slices.yml index bcb20644..e94f3661 100644 --- a/config/dol_slices.yml +++ b/config/dol_slices.yml @@ -2,11 +2,18 @@ libultra/gfxprint/gfxprint_locate.c: .text: [0x8005B1EC, 0x8005B210] libultra/gfxprint/gfxprint_locate8x8.c: .text: [0x8005B210, 0x8005B238] -# libforest/ReconfigBATs.c: - # .text: [0x8007C070, 0x8005ae84] -# OS/OSEnableInterrupts.c: I'm too tired, but I did these and cba to fix atm stuff - # .text: [0x8007ac38, 0x8007ac4c] -# OS/OSRestoreInterrupts.c: - # .text: [0x8007ac4c, 0x8007ac70] +libforest/ReconfigBATs.c: + .text: [0x8005adac, 0x8005aed4] # OS/OSDisableInterrupts.c: - # .text: [0x8007ac24, 0x8007ac38] \ No newline at end of file + # .text: [0x8007ac24, 0x8007ac38] +OS/OSEnableInterrupts.c: + .text: [0x8007ac38, 0x8007ac4c] +OS/OSRestoreInterrupts.c: + .text: [0x8007ac4c, 0x8007ac70] +BASE/ppcarch.c: + .text: [0x8007867c, 0x800786e8] +OS/OSArena.c: + .text: [0x8007988c, 0x800798ac] + .sdata: [0x80218178, 0x80218180] + .sbss: [0x802188f8, 0x80218900] + \ No newline at end of file diff --git a/config/rel_slices.yml b/config/rel_slices.yml index bea3439b..dc9b2e43 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -1,4 +1,4 @@ -# ac_aprilfool_control/aPC_actor_dt.c: +# ac_aprilfool_control/aPC_actor_dt.c: common_data is pure bs, # .text: [0x805153f0, 0x8051542C] zurumode/zerucheck_init.c: .text: [0x8040eb38, 0x8040EB50] diff --git a/include/dolphin/OSArena.h b/include/dolphin/OSArena.h new file mode 100644 index 00000000..72c831ec --- /dev/null +++ b/include/dolphin/OSArena.h @@ -0,0 +1,18 @@ +#ifndef OS_ARENA_H +#define OS_ARENA_H +#include "types.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +void* OSGetArenaHi(void); +void* OSGetArenaLo(void); + +void OSSetArenaHi(void*); +void OSSetArenaLo(void*); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/include/dolphin/OSCache.h b/include/dolphin/OSCache.h new file mode 100644 index 00000000..71ee9e26 --- /dev/null +++ b/include/dolphin/OSCache.h @@ -0,0 +1,30 @@ +#ifndef OS_CACHE_H +#define OS_CACHE_H +#include "types.h" +#ifdef __cplusplus +extern "C" { +#endif + +asm void DCEnable(void); +asm void DCInvalidateRange(void* buf, u32 len); +asm void DCFlushRange(void* buf, u32 len); +asm void DCStoreRange(void* buf, u32 len); +asm void DCFlushRangeNoSync(void* buf, u32 len); +asm void DCStoreRangeNoSync(void* buf, u32 len); +asm void DCZeroRange(void* buf, u32 len); +asm void DCTouchRange(void* buf, u32 len); +asm void ICInvalidateRange(void* buf, u32 len); +asm void ICFlashInvalidate(void); +asm void ICEnable(void); +asm void LCDisable(void); + +void L2GlobalInvalidate(void); + +void DMAErrorHandler(u8, OSContext*, u32, u32, ...); + +void __OSCacheInit(void); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/include/dolphin/OSMemory.h b/include/dolphin/OSMemory.h new file mode 100644 index 00000000..af9089cd --- /dev/null +++ b/include/dolphin/OSMemory.h @@ -0,0 +1,7 @@ +#ifndef OS_MEMORY_H +#define OS_MEMORY_H + +static asm void Config24MB(); +static asm void Config48MB(); +u32 OSGetConsoleSimulatedMemSize(void); +#endif \ No newline at end of file diff --git a/include/dolphin/os.h b/include/dolphin/os.h index 984f0d42..83a730c1 100644 --- a/include/dolphin/os.h +++ b/include/dolphin/os.h @@ -3,10 +3,16 @@ #include "types.h" +#ifdef __cplusplus +extern "C" { +#endif + void OSReport(const char*, ...); asm BOOL OSDisableInterrupts(void); asm BOOL OSEnableInterrupts(void); asm BOOL OSRestoreInterrupts(BOOL level); - +#ifdef __cplusplus +} +#endif #endif \ No newline at end of file diff --git a/include/dolphin/ppcarch.h b/include/dolphin/ppcarch.h new file mode 100644 index 00000000..1e6f8a61 --- /dev/null +++ b/include/dolphin/ppcarch.h @@ -0,0 +1,36 @@ +#ifndef PPCARCH_H +#define PPCARCH_H +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +u32 PPCMfmsr(void); +void PPCMtmsr(u32); + +u32 PPCMfhid0(void); +void PPCMthid0(u32); + +u32 PPCMfl2cr(void); +void PPCMtl2cr(u32); + +void PPCMtdec(u32); + +void PPCSync(void); +void PPCHalt(void); + +u32 PPCMfhid2(void); +void PPCMthid2(u32); + + +void PPCMtwpar(u32); + +// void PPCDisableSpeculation(void); +void PPCSetFpNonIEEEMode(void); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/libforest/batconfig.h b/include/libforest/batconfig.h index 874bec0d..d8fc7839 100644 --- a/include/libforest/batconfig.h +++ b/include/libforest/batconfig.h @@ -1,7 +1,11 @@ #ifndef BATCONFIG_H #define BATCONFIG_H -static asm void Config24MB(); -static asm void Config48MB(); +#include "types.h" +#include "dolphin/OSMemory.h" +#include "dolphin/os.h" + +asm void Config24MB(); +asm void Config48MB(); void ReconfigBATs(); #endif \ No newline at end of file diff --git a/include/libforest/fault.h b/include/libforest/fault.h new file mode 100644 index 00000000..711b16a2 --- /dev/null +++ b/include/libforest/fault.h @@ -0,0 +1,54 @@ +#ifndef FAULT_H +#define FAULT_H +#include "types.h" +#include "dolphin/os.h" +#include "libultra/libultra.h" + + +#ifdef __cplusplus +extern "C"{ +#endif + +#define FAULT_MIN_PRIORITY 0 + +#define FAULT_STAGE_POST 0 +#define FAULT_STAGE_PRE 1 + +#define FAULT_FLAG_POSTEXCEPTION (1 << FAULT_STAGE_POST) +#define FAULT_FLAG_PREEXCEPTION (1 << FAULT_STAGE_PRE) + +#define FAULT_FLAG_DRAW_SEPARATOR (1 << 2) +#define FAULT_FLAG_DRAW_CALLBACK_INFO (1 << 3) + +typedef struct { + fault_client* next; + FaultCallBack callback; + const char* msg; + u32 param; + u8 priority; + u8 flags; +} fault_client; + +typedef struct { + u8 _0, _1, _2, _3; + u8 num_clients; + fault_client* first_client; +} fault; + +typedef void (*FaultCallback)(const char* msg, u32 param); + +void fault_AddClientEx(fault_client* client, FaultCallback callback, const char* msg, u32 param, u8 priority, u8 flags); +void fault_AddClient(fault_client* client, FaultCallback callback, const char* msg, u32 param); +void fault_Printf(const char* msg, ...); +void fault_DrawUpdate(); +void fault_WaitTime(u32 waitTime); +int fault_ReadPad(u32* param_1, u32 param_2); +void fault_CallBackFunc(int stage); + +void fault_Init(); +static void my_PreExceptionCallback(); +static void my_PostExceptionCallback(); +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/libultra/gfxprint.h b/include/libultra/gfxprint.h index c8811b0f..211bcda9 100644 --- a/include/libultra/gfxprint.h +++ b/include/libultra/gfxprint.h @@ -2,8 +2,9 @@ #define GFXPRINT_H #include "types.h" +typedef void* (*PrintCallback)(void*, const char*, size_t); typedef struct gfxprint_obj { - s32 unk0; + PrintCallback callback; struct unknown_struct * unk4; // This is from GBI.h, from what I've seen s16 NewX; s16 NewY; diff --git a/src/BASE/ppcarch.c b/src/BASE/ppcarch.c new file mode 100644 index 00000000..81e61862 --- /dev/null +++ b/src/BASE/ppcarch.c @@ -0,0 +1,96 @@ +#include "dolphin/ppcarch.h" + +asm u32 PPCMfmsr(void){ + nofralloc + mfmsr r3 + blr +} + +asm void PPCMtmsr(register u32 value){ + nofralloc + mtmsr value + blr +} + +asm u32 PPCMfhid0(void){ + nofralloc + mfspr r3, 0x3f0 + blr +} + +asm void PPCMthid0(register u32 value) { + nofralloc + mtspr 0x3f0, value + blr +} + +asm u32 PPCMfl2cr(void) { + nofralloc + mfspr r3, 0x3f9 + blr +} + +asm void PPCMtl2cr(register u32 value) { + nofralloc + mtspr 0x3f9, value + blr +} +asm void PPCMtdec(register u32 value) { + nofralloc + mtspr 0x16, value + blr +} + +asm void PPCSync(void){ + nofralloc + sc + blr +} + +asm void PPCHalt(void){ + nofralloc + sync + +loop: + nop + li r3, 0 + nop + b loop +} +asm u32 PPCMfhid2(void){ + nofralloc + mfspr r3, 0x398 + blr +} + +asm void PPCMthid2(u32 register value){ + nofralloc + mtspr 0x398, value + blr +} +asm void PPCMtwpar(u32 register value){ + nofralloc + mtspr 0x399, value + blr +} + +/* PPCDisableSpeculation: +/* 800786E8 7C0802A6 mflr r0 +/* 800786EC 90010004 stw r0, 4(r1) +/* 800786F0 9421FFF8 stwu r1, -8(r1) +/* 800786F4 4BFFFF99 bl func_8007868c +/* 800786F8 60630200 ori r3, r3, 0x200 +/* 800786FC 4BFFFF99 bl func_80078694 +/* 80078700 8001000C lwz r0, 0xc(r1) +/* 80078704 38210008 addi r1, r1, 0x8 +/* 80078708 7C0803A6 mtlr r0 +/* 8007870C 4E800020 blr + +} + +asm void PPCSetFpNonIEEEMode(void){ + nofralloc + mtfsb1 0x1D + blr +} */ + \ No newline at end of file diff --git a/src/OS/OSArena.c b/src/OS/OSArena.c new file mode 100644 index 00000000..b6ec117a --- /dev/null +++ b/src/OS/OSArena.c @@ -0,0 +1,20 @@ +#include "dolphin/OSArena.h" + +static void* __OSArenaLo = (void*) - 1; +static void* __OSArenaHi = NULL; + +void* OSGetArenaHi(void) { + return (__OSArenaHi); +} + +void* OSGetArenaLo (void) { + return (__OSArenaLo); +} + +void OSSetArenaHi(void* hi){ + __OSArenaHi = hi; +} + +void OSSetArenaLo(void* lo){ + __OSArenaLo = lo; +} \ No newline at end of file diff --git a/src/OS/OSCache.c b/src/OS/OSCache.c new file mode 100644 index 00000000..be8e02dc --- /dev/null +++ b/src/OS/OSCache.c @@ -0,0 +1,215 @@ +#include "dolphin/OSCache.h" +//Needs OSError stuff +asm void DCEnable(void){ + nofralloc + sync 0 + mfspr r3, 0x3f0 + ori r3, r3, 0x4000 + mtspr 0x3f0, r3 + blr +} +asm void DCInvalidateRange(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- pi_r + addi len, len 0x20 + +pi_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +inv_ran: + dcbi 0, buf + addi buf, buf 0x20 + bdnz inv_ran + + blr +} +asm void DCFlushRange(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- pf_r + addi len, len 0x20 + +pf_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +fls_ran: + dcbf 0, buf + addi buf, buf 0x20 + bdnz fls_ran + sc + blr +} + +asm void DCStoreRange(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- ps_r + addi len, len 0x20 + +ps_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +st_ran: + dcbst 0, buf + addi buf, buf 0x20 + bdnz st_ran + sc + blr +} + +asm void DCFlushRangeNoSync(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- pf_r + addi len, len 0x20 + +pfns_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +fls_ranns: + dcbf 0, buf + addi buf, buf 0x20 + bdnz fls_ranns + blr +} + +asm void DCStoreRangeNoSync(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- psns_r + addi len, len 0x20 + +psns_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +st_ranns: + dcbst 0, buf + addi buf, buf 0x20 + bdnz st_ranns + sc + blr +} + +asm void DCZeroRange(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- pzr_r + addi len, len 0x20 + +pzr_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +z_ran: + dcbz 0, buf + addi buf, buf 0x20 + bdnz z_ran + blr +} + +asm void DCTouchRange(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- ptor_r + addi len, len 0x20 + +ptor_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +t_ran: + dcbt 0, buf + addi buf, buf 0x20 + bdnz t_ran + blr +} + +asm void ICInvalidateRange(register void* buf, register u32 len){ + nofralloc + cmplw len, 0 + blelr- + + clrlwi. r5, buf, 0x1b + beq- pir_r + addi len, len 0x20 + +pir_r: + addi len, len 0x1f + srwi len, len, 5 + mtctr len + +i_ran: + icbi 0, buf + addi buf, buf 0x20 + bdnz i_ran + sync 0 + isync + blr +} +asm void ICFlashInvalidate(void){ + nofralloc + mfspr r3, 0x3f0 + ori r3, r3, 0x800 + mtspr 0x3f0, r3 + blr +} + +asm void ICEnable(void){ + nofralloc + isync + mfspr r3, 0x3f0 + ori r3, r3, 0x8000 + mtspr 0x3f0, r3 + blr +} + +asm void ICDisable(void){ + nofralloc + lis r3, 0xE000 + li r4, 0x200 + mtctr r4 +dis: + dcbi 0, r3 + addi r3, r3 0x20 + bdnz dis + mfspr r4, 0x398 + rlwinm r4, r4, 0, 4, 2 + mtspr 0x398, r4 + blr +} + + diff --git a/src/OS/OSDisableInterrupts.c b/src/OS/OSDisableInterrupts.c index 8d1044f0..8c82c584 100644 --- a/src/OS/OSDisableInterrupts.c +++ b/src/OS/OSDisableInterrupts.c @@ -1,9 +1,7 @@ #include "dolphin/os.h" asm BOOL OSDisableInterrupts(void){ - nofralloc - mfmsr r3 rlwinm r4, r3, 0, 17, 15 mtmsr r4 diff --git a/src/libforest/ReconfigBATs.c b/src/libforest/ReconfigBATs.c index 3e4606d7..4074e3df 100644 --- a/src/libforest/ReconfigBATs.c +++ b/src/libforest/ReconfigBATs.c @@ -1,8 +1,6 @@ #include "libforest/batconfig.h" -#include "dolphin/os.h" -// Different to the OS ones. -// Not fully Decompiled, need ReconfigBATs func, however there's os stuff that needs to be known. -static asm void Config24MB(){ + +asm void Config24MB(){ nofralloc /* 8005ADAC 7C6000A6 */ mfmsr r3 /* 8005ADB0 54630734 */ rlwinm r3, r3, 0, 0x1c, 0x1a @@ -32,7 +30,7 @@ nofralloc /* 8005AE10 4C00012C */ isync /* 8005AE14 4E800020 */ blr } -static asm void Config48MB(){ +asm void Config48MB(){ nofralloc /* 8005AE18 7C6000A6 */ mfmsr r3 /* 8005AE1C 54630734 */ rlwinm r3, r3, 0, 0x1c, 0x1a @@ -63,14 +61,12 @@ nofralloc /* 8005AE80 4E800020 */ blr } void ReconfigBATs(){ - -BOOL restore = OSDisableInterrupts(); - -if (OSGetSimulatedMemorySize() <= 0x1800000) { - Config24MB(); - else{ - Config48MB(); - } -} - OSRestoreInterrupts(restore); + BOOL rest = OSDisableInterrupts(); + if (OSGetConsoleSimulatedMemSize() <= 0x1800000){ + Config24MB(); + } + else { + Config48MB(); + } + OSRestoreInterrupts(rest); } \ No newline at end of file diff --git a/src/libforest/fault.c b/src/libforest/fault.c new file mode 100644 index 00000000..30e40cbd --- /dev/null +++ b/src/libforest/fault.c @@ -0,0 +1,10 @@ +#include "fault.h" + +static fault fault_class; +static fault* this; + +void fault_AddClientEx(fault_client* client, FaultCallback callback, const char* msg, u32 param, u8 priority, u8 flags){ + + + +} diff --git a/tools/ppcdis b/tools/ppcdis index 0ab8975b..d770a7a1 160000 --- a/tools/ppcdis +++ b/tools/ppcdis @@ -1 +1 @@ -Subproject commit 0ab8975ba8189db05e2476dc02d39ad644b5925b +Subproject commit d770a7a11369b1f4d7bf8424b5296ec74e730a49