From 79bb2ae6e3a8e65a38bee104d074ef8b9973695b Mon Sep 17 00:00:00 2001 From: Prakxo Date: Tue, 7 Feb 2023 11:09:14 +0000 Subject: [PATCH] header fixing --- config/dol_slices.yml | 7 ++-- include/dolphin/{ => BASE}/ppcarch.h | 0 include/dolphin/{ => OS}/OSArena.h | 0 include/dolphin/OS/OSCache.h | 30 ++++++++++++++++ include/dolphin/{ => OS}/OSContext.h | 12 +++---- include/dolphin/{ => OS}/OSError.h | 0 include/dolphin/{ => OS}/OSMemory.h | 0 include/dolphin/{ => OS}/OSTime.h | 0 include/dolphin/{ => OS}/os.h | 2 +- include/dolphin/OSCache.h | 31 ---------------- include/dolphin/dsp/dsp.h | 16 +++++++++ include/libforest/batconfig.h | 4 +-- include/libforest/fault.h | 2 +- include/libultra/libultra.h | 4 +-- include/zurumode.h | 2 +- src/dolphin/BASE/ppcarch.c | 2 +- src/dolphin/OS/OSAlarm.c | 4 ++- src/dolphin/OS/OSArena.c | 2 +- src/dolphin/OS/OSCache.c | 2 +- src/dolphin/OS/OSContext.c | 4 +-- src/dolphin/OS/OSDisableInterrupts.c | 2 +- src/dolphin/OS/OSEnableInterrupts.c | 2 +- src/dolphin/OS/OSError.c | 53 ++++++++++++++++++++++++++++ src/dolphin/OS/OSMemory.c | 2 +- src/dolphin/OS/OSRestoreInterrupts.c | 2 +- src/libultra/ultra.c | 8 ++--- 26 files changed, 132 insertions(+), 61 deletions(-) rename include/dolphin/{ => BASE}/ppcarch.h (100%) rename include/dolphin/{ => OS}/OSArena.h (100%) create mode 100644 include/dolphin/OS/OSCache.h rename include/dolphin/{ => OS}/OSContext.h (67%) rename include/dolphin/{ => OS}/OSError.h (100%) rename include/dolphin/{ => OS}/OSMemory.h (100%) rename include/dolphin/{ => OS}/OSTime.h (100%) rename include/dolphin/{ => OS}/os.h (89%) delete mode 100644 include/dolphin/OSCache.h create mode 100644 include/dolphin/dsp/dsp.h create mode 100644 src/dolphin/OS/OSError.c diff --git a/config/dol_slices.yml b/config/dol_slices.yml index c5d1c51c..766aee32 100644 --- a/config/dol_slices.yml +++ b/config/dol_slices.yml @@ -10,8 +10,9 @@ dolphin/OS/OSArena.c: .text: [0x8007988c, 0x800798ac] .sdata: [0x80218178, 0x80218180] .sbss: [0x802188f8, 0x80218900] -# OS/OSCache.c: - # .text: [0x80079b40, 0x80079d30] +#dolphin/OS/OSCache.c: +# .text: [0x80079b40, 0x8007a01c] +# .data: [0x800dfa00, 0x800dfc30] # OS/OSDisableInterrupts.c: # .text: [0x8007ac24, 0x8007ac38] dolphin/OS/OSEnableInterrupts.c: @@ -25,4 +26,4 @@ libultra/ultra.c: .text: [0x8005d01c, 0x8005d090] libultra/gu/sins.c: .text: [0x8005e860, 0x8005e8ac] - .data: [0x800dd360, 0x800ddb60] \ No newline at end of file + .data: [0x800dd360, 0x800ddb60] diff --git a/include/dolphin/ppcarch.h b/include/dolphin/BASE/ppcarch.h similarity index 100% rename from include/dolphin/ppcarch.h rename to include/dolphin/BASE/ppcarch.h diff --git a/include/dolphin/OSArena.h b/include/dolphin/OS/OSArena.h similarity index 100% rename from include/dolphin/OSArena.h rename to include/dolphin/OS/OSArena.h diff --git a/include/dolphin/OS/OSCache.h b/include/dolphin/OS/OSCache.h new file mode 100644 index 00000000..6db877f3 --- /dev/null +++ b/include/dolphin/OS/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*, u32); +asm void DCFlushRange(void*, u32); +asm void DCStoreRange(void*, u32); +asm void DCFlushRangeNoSync(void*, u32); +asm void DCStoreRangeNoSync(void*, u32); +asm void DCZeroRange(void*, u32); +asm void DCTouchRange(void*, u32 len); +asm void ICInvalidateRange(void*, u32); +asm void ICFlashInvalidate(void); +asm void ICEnable(void); +asm void LCDisable(void); + +//void L2GlobalInvalidate(void); + +//void DMAErrorHandler(u8, struct OSContext*, u32, u32, ...); + +//void __OSCacheInit(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/dolphin/OSContext.h b/include/dolphin/OS/OSContext.h similarity index 67% rename from include/dolphin/OSContext.h rename to include/dolphin/OS/OSContext.h index c7007113..34181d85 100644 --- a/include/dolphin/OSContext.h +++ b/include/dolphin/OS/OSContext.h @@ -28,14 +28,14 @@ OSContext* OS_CURRENT_CONTEXT_PHYS : 0x800000C0; OSContext* OS_CURRENT_CONTEXT : 0x800000D4; OSContext* OS_CURRENT_FPU_CONTEXT : 0x800000D8; -asm void OSSaveFPUContext(OSContext*); -asm void OSSetCurrentContext(OSContext*); +void OSSaveFPUContext(OSContext*); +void OSSetCurrentContext(OSContext*); OSContext* OSGetCurrentContext(void); -asm BOOL OSSaveContext(OSContext*); -asm void OSLoadContext(OSContext*); -asm void* OSGetStackPointer(void); +BOOL OSSaveContext(OSContext*); +void OSLoadContext(OSContext*); +void* OSGetStackPointer(void); void OSClearContext(OSContext*); -asm void OSInitContext(register OSContext* ctx, register u32 srr, register sp); +void OSInitContext(register OSContext*, register u32 srr, register u32 sp); void OSDumpContext(const OSContext*); void __OSContextInit(void); diff --git a/include/dolphin/OSError.h b/include/dolphin/OS/OSError.h similarity index 100% rename from include/dolphin/OSError.h rename to include/dolphin/OS/OSError.h diff --git a/include/dolphin/OSMemory.h b/include/dolphin/OS/OSMemory.h similarity index 100% rename from include/dolphin/OSMemory.h rename to include/dolphin/OS/OSMemory.h diff --git a/include/dolphin/OSTime.h b/include/dolphin/OS/OSTime.h similarity index 100% rename from include/dolphin/OSTime.h rename to include/dolphin/OS/OSTime.h diff --git a/include/dolphin/os.h b/include/dolphin/OS/os.h similarity index 89% rename from include/dolphin/os.h rename to include/dolphin/OS/os.h index 4801ba3f..7c00c583 100644 --- a/include/dolphin/os.h +++ b/include/dolphin/OS/os.h @@ -2,7 +2,7 @@ #define _DOLPHIN_OS #include "types.h" -#include "dolphin/OSContext.h" +#include "dolphin/OS/OSContext.h" #ifdef __cplusplus extern "C" { #endif diff --git a/include/dolphin/OSCache.h b/include/dolphin/OSCache.h deleted file mode 100644 index 301b2777..00000000 --- a/include/dolphin/OSCache.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef OS_CACHE_H -#define OS_CACHE_H -#include "types.h" -#include "dolphin/OSContext.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/dsp/dsp.h b/include/dolphin/dsp/dsp.h new file mode 100644 index 00000000..f7ad97c3 --- /dev/null +++ b/include/dolphin/dsp/dsp.h @@ -0,0 +1,16 @@ +#ifndef DSP_H +#define DSP_H + +#include "types.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +extern volatile u16 __DSPRegs[] : 0XCC005000; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libforest/batconfig.h b/include/libforest/batconfig.h index d8fc7839..11b357d2 100644 --- a/include/libforest/batconfig.h +++ b/include/libforest/batconfig.h @@ -2,8 +2,8 @@ #define BATCONFIG_H #include "types.h" -#include "dolphin/OSMemory.h" -#include "dolphin/os.h" +#include "dolphin/OS/OSMemory.h" +#include "dolphin/OS/os.h" asm void Config24MB(); asm void Config48MB(); diff --git a/include/libforest/fault.h b/include/libforest/fault.h index 711b16a2..06c0e17a 100644 --- a/include/libforest/fault.h +++ b/include/libforest/fault.h @@ -1,7 +1,7 @@ #ifndef FAULT_H #define FAULT_H #include "types.h" -#include "dolphin/os.h" +#include "dolphin/OS/os.h" #include "libultra/libultra.h" diff --git a/include/libultra/libultra.h b/include/libultra/libultra.h index d17d7d13..0da31771 100644 --- a/include/libultra/libultra.h +++ b/include/libultra/libultra.h @@ -1,8 +1,8 @@ #ifndef LIBULTRA_H #define LIBULTRA_H #include "types.h" -#include "dolphin/OSTime.h" -#include "dolphin/OSCache.h" +#include "dolphin/OS/OSTime.h" +#include "dolphin/OS/OSCache.h" int bcmp (void *v1, void *v2, u32 size); void bcopy(void *dst, void *src, size_t n); void bzero(void *ptr, size_t size); diff --git a/include/zurumode.h b/include/zurumode.h index 455a1133..cffb6aaf 100644 --- a/include/zurumode.h +++ b/include/zurumode.h @@ -3,7 +3,7 @@ #include "types.h" -#include "dolphin/os.h" +#include "dolphin/OS/os.h" #include "libultra/libultra.h" #include "JSystem/JUT/JUTAssertion.h" #include "JSystem/JUT/JUTDbPrint.h" diff --git a/src/dolphin/BASE/ppcarch.c b/src/dolphin/BASE/ppcarch.c index 8a680a0e..0baa5f3a 100644 --- a/src/dolphin/BASE/ppcarch.c +++ b/src/dolphin/BASE/ppcarch.c @@ -1,4 +1,4 @@ -#include "dolphin/ppcarch.h" +#include "dolphin/BASE/ppcarch.h" asm u32 PPCMfmsr(void){ nofralloc diff --git a/src/dolphin/OS/OSAlarm.c b/src/dolphin/OS/OSAlarm.c index 352c2e45..795435af 100644 --- a/src/dolphin/OS/OSAlarm.c +++ b/src/dolphin/OS/OSAlarm.c @@ -1,6 +1,8 @@ #include "dolphin/OS/OSAlarm.h" #include "dolphin/OS/OSTime.h" -#inlcude "dolphin/OS/OSContext.h" +#include "dolphin/OS/OSContext.h" + +static void DecrementerExceptionHandler(u8, OSContext*); void OSInitAlarm(void){ diff --git a/src/dolphin/OS/OSArena.c b/src/dolphin/OS/OSArena.c index b6ec117a..69b6dc9b 100644 --- a/src/dolphin/OS/OSArena.c +++ b/src/dolphin/OS/OSArena.c @@ -1,4 +1,4 @@ -#include "dolphin/OSArena.h" +#include "dolphin/OS/OSArena.h" static void* __OSArenaLo = (void*) - 1; static void* __OSArenaHi = NULL; diff --git a/src/dolphin/OS/OSCache.c b/src/dolphin/OS/OSCache.c index 5f0f712f..7c76dd96 100644 --- a/src/dolphin/OS/OSCache.c +++ b/src/dolphin/OS/OSCache.c @@ -1,4 +1,4 @@ -#include "dolphin/OSCache.h" +#include "dolphin/OS/OSCache.h" //Needs OSError stuff asm void DCEnable(void){ nofralloc diff --git a/src/dolphin/OS/OSContext.c b/src/dolphin/OS/OSContext.c index 818ad825..685debca 100644 --- a/src/dolphin/OS/OSContext.c +++ b/src/dolphin/OS/OSContext.c @@ -1,5 +1,5 @@ -#include "dolphin/OSContext.h" -#include "dolphin/OSError.h" +#include "dolphin/OS/OSContext.h" +#include "dolphin/OS/OSError.h" static asm void __OSLoadFPUContext(int unused, register OSContext* ctx){ nofralloc lhz r5, ctx->state diff --git a/src/dolphin/OS/OSDisableInterrupts.c b/src/dolphin/OS/OSDisableInterrupts.c index 635a1909..4bd7b6c9 100644 --- a/src/dolphin/OS/OSDisableInterrupts.c +++ b/src/dolphin/OS/OSDisableInterrupts.c @@ -1,4 +1,4 @@ -#include "dolphin/os.h" +#include "dolphin/OS/os.h" asm BOOL OSDisableInterrupts(void){ nofralloc diff --git a/src/dolphin/OS/OSEnableInterrupts.c b/src/dolphin/OS/OSEnableInterrupts.c index 4abb7ba7..a2dc46a4 100644 --- a/src/dolphin/OS/OSEnableInterrupts.c +++ b/src/dolphin/OS/OSEnableInterrupts.c @@ -1,4 +1,4 @@ -#include "dolphin/os.h" +#include "dolphin/OS/os.h" asm BOOL OSEnableInterrupts(void){ diff --git a/src/dolphin/OS/OSError.c b/src/dolphin/OS/OSError.c new file mode 100644 index 00000000..d2a152b2 --- /dev/null +++ b/src/dolphin/OS/OSError.c @@ -0,0 +1,53 @@ +#include "dolphin/OS/OSError.h" +#include "dolphin/OS/OSContext.h" +#include "dolphin/BASE/ppcarch.h" +#include "dolphin/dsp/dsp.h" +#include "dolphin/OS/OSTime.h" + +OSErrorHandler __OSErrorTable[16]; + +OSErrorHandler OSSetErrorHanlder(OSError error, OSErrorHandler handler){ + OSErrorHandler prevhandler = __OSErrorTable[error]; + __OSErrorTable[error] = handler; + return(prevhandler); +} + +void __OSUnhandledException(u8 error, OSContext* ctx, s32 sdirs, s32 dar){ + if(!(ctx->srr1) & (1 << 1))){ + OSReport("Non-recoverable exception %d", error); +} else { + if(__OSErrorTable[error] != NULL){ + OSDisableScheduler(); + OSErrorTable[error](error, ctx, sdirs, dar); + OSEnableScheduler(); + __OSReschedule(); + OSLoadContext(); +} + if(error = ERROR_OS_DECREMENTER){ + OSLoadContext(ctx); + OSReport("Unhandled Exception %d", error); + } + OSReport("\n"); + OSDumpContext(ctx); + OSReport("\nDSISR = 0x%08x DAR = 0X%08X\n", sdirs, dar); + OSReport("TB = 0x%01611x\n", OSGetTime()); + switch (error) { + case OS_ERROR_DSI: + OSReport("\nInstruction at 0x%x (read from SRR0) attempted to access ""Invalid address 0x%x (read from DAR)\n", ctx->srr0, dar); + break; + case OS_ERROR_ISI: + OSReport("Attempted to fetch instruction from invalid adddress 0x%x ""(read from SRR0)\n",ctx->srr0); + break; + case OS_ERROR_PROGRAM: + OSReport("\nProgram exception : Possible illegal instruction/operation ""at or around 0x%x (read from SRR0)\n", ctx->srr0, dar); + break; + case 15: + OSReport("\n"); + OSREport("AI DMA Address = 0x%04x%04x\n", __DSPRegs[24], __DSPRegs[25]); + OSReport(ARAM DMA Address = 0x%04x%04x\n", __DSPRegs[16], __DSPRegs[17]); + OSReport("DI DMA Address = 0x%08x\n", __DIRegs[5]); + break; +} + OSReport("\nLast interrupt (%d): SRR0 = 0x08x TB = 0x%01611x\n", __OSLastInterrupt, __OSLastInterruptSrr0, __OSLastInterruptTime); + PPCHalt(); +} diff --git a/src/dolphin/OS/OSMemory.c b/src/dolphin/OS/OSMemory.c index bea9420a..8c55045c 100644 --- a/src/dolphin/OS/OSMemory.c +++ b/src/dolphin/OS/OSMemory.c @@ -1,4 +1,4 @@ -#include "dolphin/OSMemory.h" +#include "dolphin/OS/OSMemory.h" u32 OSGetConsoleSimulatedMemSize(void){ return(SIM_MEM); diff --git a/src/dolphin/OS/OSRestoreInterrupts.c b/src/dolphin/OS/OSRestoreInterrupts.c index de96be1c..9712f5aa 100644 --- a/src/dolphin/OS/OSRestoreInterrupts.c +++ b/src/dolphin/OS/OSRestoreInterrupts.c @@ -1,4 +1,4 @@ -#include "dolphin/os.h" +#include "dolphin/OS/os.h" asm BOOL OSRestoreInterrupts(register BOOL level){ diff --git a/src/libultra/ultra.c b/src/libultra/ultra.c index 46a2b393..962d30eb 100644 --- a/src/libultra/ultra.c +++ b/src/libultra/ultra.c @@ -13,11 +13,11 @@ void bzero(void* __s, size_t __n) { memset(__s, 0, __n); } -void osWritebackDCache(void* buf, u32 len){ - DCStoreRange(buf, len); -} +//void osWritebackDCache(void* buf, u32 len){ +// DCStoreRange(buf, len); +//} /* s32 osGetCount(void){ return OSGetTick(); } - */ \ No newline at end of file + */