From 2ab160b91634a192812b6bc1d6744d1fe9143bac Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:08:25 +0000 Subject: [PATCH 1/8] Split debug.c --- include/spm/debug.h | 2 +- include/wii/base.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 include/wii/base.h diff --git a/include/spm/debug.h b/include/spm/debug.h index 9a12f47..7e66341 100644 --- a/include/spm/debug.h +++ b/include/spm/debug.h @@ -15,6 +15,6 @@ void debugReInit(); // OSPanic DECOMP_STATIC(DebugWork debug_work) -DECOMP_STATIC(DebugWork debug_wp) +DECOMP_STATIC(DebugWork * debug_wp) CPP_WRAPPER_END() diff --git a/include/wii/base.h b/include/wii/base.h new file mode 100644 index 0000000..8b44083 --- /dev/null +++ b/include/wii/base.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +CPP_WRAPPER(wii::base) + +UNKNOWN_FUNCTION(PPCMfmsr); +UNKNOWN_FUNCTION(PPCMtmsr); +UNKNOWN_FUNCTION(PPCMfhid0); +UNKNOWN_FUNCTION(PPCMthid0); +UNKNOWN_FUNCTION(PPCMfl2cr); +UNKNOWN_FUNCTION(PPCMtl2cr); +UNKNOWN_FUNCTION(PPCMtdec); +UNKNOWN_FUNCTION(PPCSync); +UNKNOWN_FUNCTION(PPCHalt); +UNKNOWN_FUNCTION(PPCMtmmcr0); +UNKNOWN_FUNCTION(PPCMfmmcr1); +UNKNOWN_FUNCTION(PPCMtpmc1); +UNKNOWN_FUNCTION(PPCMtpmc2); +UNKNOWN_FUNCTION(PPCMtpmc3); +UNKNOWN_FUNCTION(PPCMtpmc4); +UNKNOWN_FUNCTION(PPCMffpscr); +UNKNOWN_FUNCTION(PPCMtfpscr); +UNKNOWN_FUNCTION(PPCMfhid2); +UNKNOWN_FUNCTION(PPCMthid2); +UNKNOWN_FUNCTION(PPCMfwpar); +UNKNOWN_FUNCTION(PPCMtwpar); +UNKNOWN_FUNCTION(PPCDisableSpeculation); +UNKNOWN_FUNCTION(PPCSetFpNonIEEEMode); +UNKNOWN_FUNCTION(PPCMthid4); + +CPP_WRAPPER_END() From a954279b457d6123ee75894d736f379ed758db39 Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:34:26 +0000 Subject: [PATCH 2/8] Fix stdarg intellisense --- include/msl/stdarg.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/msl/stdarg.h b/include/msl/stdarg.h index def3902..8dfadc9 100644 --- a/include/msl/stdarg.h +++ b/include/msl/stdarg.h @@ -22,9 +22,13 @@ typedef struct __va_list_struct { void* __va_arg(va_list, int); +#ifndef __INTELLISENSE__ #define va_start(VA_LIST, ARG) ((void)ARG, __builtin_va_info(&VA_LIST)) #define va_end(VA_LIST) ((void)VA_LIST) #define va_arg(VA_LIST, ARG_TYPE) \ (*(ARG_TYPE*)__va_arg(VA_LIST, _var_arg_typeof(ARG_TYPE))) +#else +#include +#endif CPP_WRAPPER_END() From f85bf1089b84488c2914ba96f84b5247de07bd39 Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:34:54 +0000 Subject: [PATCH 3/8] Decompile OSPanic --- include/wii/os/OSContext.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wii/os/OSContext.h b/include/wii/os/OSContext.h index 0119211..9038335 100644 --- a/include/wii/os/OSContext.h +++ b/include/wii/os/OSContext.h @@ -31,7 +31,7 @@ UNKNOWN_FUNCTION(OSSetCurrentContext); UNKNOWN_FUNCTION(OSGetCurrentContext); UNKNOWN_FUNCTION(OSSaveContext); UNKNOWN_FUNCTION(OSLoadContext); -UNKNOWN_FUNCTION(OSGetStackPointer); +u32 OSGetStackPointer(); UNKNOWN_FUNCTION(OSSwitchFiber); UNKNOWN_FUNCTION(OSSwitchFiberEx); UNKNOWN_FUNCTION(OSClearContext); From bc62838b6f0e04c381ee0ddc794d7011943d67b2 Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:38:27 +0000 Subject: [PATCH 4/8] Fix stdarg in makectx --- include/msl/stdarg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/msl/stdarg.h b/include/msl/stdarg.h index 8dfadc9..8cef2c6 100644 --- a/include/msl/stdarg.h +++ b/include/msl/stdarg.h @@ -28,7 +28,7 @@ void* __va_arg(va_list, int); #define va_arg(VA_LIST, ARG_TYPE) \ (*(ARG_TYPE*)__va_arg(VA_LIST, _var_arg_typeof(ARG_TYPE))) #else -#include +#include // makectx-ignore #endif CPP_WRAPPER_END() From e1ed311ab7f81dd05b74b8cc570bfbc08c444025 Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:38:40 +0000 Subject: [PATCH 5/8] Complete base.h --- include/wii/base.h | 63 ++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/include/wii/base.h b/include/wii/base.h index 8b44083..96bae35 100644 --- a/include/wii/base.h +++ b/include/wii/base.h @@ -4,29 +4,44 @@ CPP_WRAPPER(wii::base) -UNKNOWN_FUNCTION(PPCMfmsr); -UNKNOWN_FUNCTION(PPCMtmsr); -UNKNOWN_FUNCTION(PPCMfhid0); -UNKNOWN_FUNCTION(PPCMthid0); -UNKNOWN_FUNCTION(PPCMfl2cr); -UNKNOWN_FUNCTION(PPCMtl2cr); -UNKNOWN_FUNCTION(PPCMtdec); -UNKNOWN_FUNCTION(PPCSync); -UNKNOWN_FUNCTION(PPCHalt); -UNKNOWN_FUNCTION(PPCMtmmcr0); -UNKNOWN_FUNCTION(PPCMfmmcr1); -UNKNOWN_FUNCTION(PPCMtpmc1); -UNKNOWN_FUNCTION(PPCMtpmc2); -UNKNOWN_FUNCTION(PPCMtpmc3); -UNKNOWN_FUNCTION(PPCMtpmc4); -UNKNOWN_FUNCTION(PPCMffpscr); -UNKNOWN_FUNCTION(PPCMtfpscr); -UNKNOWN_FUNCTION(PPCMfhid2); -UNKNOWN_FUNCTION(PPCMthid2); -UNKNOWN_FUNCTION(PPCMfwpar); -UNKNOWN_FUNCTION(PPCMtwpar); -UNKNOWN_FUNCTION(PPCDisableSpeculation); -UNKNOWN_FUNCTION(PPCSetFpNonIEEEMode); -UNKNOWN_FUNCTION(PPCMthid4); +u32 PPCMfmsr(); +void PPCMtmsr(u32); + +u32 PPCMfhid0(); +void PPCMthid0(u32); + +u32 PPCMfl2cr(); +void PPCMtl2cr(u32); + +void PPCMtdec(u32); + +void PPCSync(); +void PPCHalt(); + +void PPCMtmmcr0(u32); + +u32 PPCMfmmcr1(); + +void PPCMtpmc1(u32); + +void PPCMtpmc2(u32); + +void PPCMtpmc3(u32); + +void PPCMtpmc4(u32); + +u32 PPCMffpscr(); +void PPCMtfpscr(u32); + +u32 PPCMfhid2(); +void PPCMthid2(u32); + +u32 PPCMfwpar(); +void PPCMtwpar(u32); + +void PPCDisableSpeculation(); +void PPCSetFpNonIEEEMode(); + +void PPCMthid4(u32); CPP_WRAPPER_END() From 7d480ac47e43ae9b35b1d4b16954a9ab4b6d048f Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:47:33 +0000 Subject: [PATCH 6/8] FIXED_ADDR intellisense fix --- include/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index 981e5af..0f5457a 100644 --- a/include/common.h +++ b/include/common.h @@ -136,7 +136,7 @@ typedef u8 unk8; #endif // For GCC these have to be defined in the linker script -#if (defined __MWERKS__) && !(defined M2C) +#if (defined __MWERKS__) && !(defined M2C) && !(defined __INTELLISENSE__) #define FIXED_ADDR(type, name, addr) \ type name : addr #else From 79032c1a1c3ee6953ecd555361417bb010fae6e0 Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:51:00 +0000 Subject: [PATCH 7/8] Exception-related header stuff --- include/wii/base.h | 45 ++++++++++++++++++++++++++++++++++++ include/wii/dsp.h | 40 ++++++++++++++++++++++++++++++++ include/wii/os/OSContext.h | 30 ++++++++++++++---------- include/wii/os/OSError.h | 29 +++++++++++++++++++++-- include/wii/os/OSHardware.h | 16 +++++++++++++ include/wii/os/OSInterrupt.h | 7 ++++++ 6 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 include/wii/dsp.h create mode 100644 include/wii/os/OSHardware.h diff --git a/include/wii/base.h b/include/wii/base.h index 96bae35..172903a 100644 --- a/include/wii/base.h +++ b/include/wii/base.h @@ -4,6 +4,51 @@ CPP_WRAPPER(wii::base) +#define FPSCR_FX 0x80000000 +#define FPSCR_FEX 0x40000000 +#define FPSCR_VX 0x20000000 +#define FPSCR_OX 0x10000000 +#define FPSCR_UX 0x8000000 +#define FPSCR_ZX 0x4000000 +#define FPSCR_XX 0x2000000 +#define FPSCR_VXSNAN 0x1000000 +#define FPSCR_VXISI 0x800000 +#define FPSCR_VXIDI 0x400000 +#define FPSCR_VXZDZ 0x200000 +#define FPSCR_VXIMZ 0x100000 +#define FPSCR_VXVC 0x80000 +#define FPSCR_FR 0x40000 +#define FPSCR_FI 0x20000 +#define FPSCR_FPRF 0x1f000 +#define FPSCR_UNK20 0x800 +#define FPSCR_VXSOFT 0x400 +#define FPSCR_VXSQRT 0x200 +#define FPSCR_VXCVI 0x100 +#define FPSCR_VE 0x80 +#define FPSCR_OE 0x40 +#define FPSCR_UE 0x20 +#define FPSCR_ZE 0x10 +#define FPSCR_XE 0x8 +#define FPSCR_NI 0x4 +#define FPSCR_RN 0x3 + +#define MSR_POW 0x40000 +#define MSR_ILE 0x10000 +#define MSR_EE 0x8000 +#define MSR_PR 0x4000 +#define MSR_FP 0x2000 +#define MSR_ME 0x1000 +#define MSR_FE0 0x800 +#define MSR_SE 0x400 +#define MSR_BE 0x200 +#define MSR_FE1 0x100 +#define MSR_IP 0x40 +#define MSR_IR 0x20 +#define MSR_DR 0x10 +#define MSR_PM 0x4 +#define MSR_RI 0x2 +#define MSR_LE 0x1 + u32 PPCMfmsr(); void PPCMtmsr(u32); diff --git a/include/wii/dsp.h b/include/wii/dsp.h new file mode 100644 index 0000000..3ad45ba --- /dev/null +++ b/include/wii/dsp.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +CPP_WRAPPER(wii::dsp) + +#define DSP_DSPMBOX_H 0 +#define DSP_DSPMBOX_L 1 +#define DSP_CPUMBOX_H 2 +#define DSP_CPUMBOX_L 3 +#define DSP_REG_0x8 4 +#define DSP_CSR 5 +#define DSP_REG_0xC 6 +#define DSP_REG_0xE 7 +#define DSP_REG_0x10 8 +#define DSP_AR_SIZE 9 +#define DSP_REG_0x14 10 +#define DSP_AR_MODE 11 +#define DSP_REG_0x18 12 +#define DSP_AR_REFRESH 13 +#define DSP_REG_0x1C 14 +#define DSP_REG_0x1E 15 +#define DSP_AR_DMA_MMADDR_H 16 +#define DSP_AR_DMA_MMADDR_L 17 +#define DSP_AR_DMA_ARADDR_H 18 +#define DSP_AR_DMA_ARADDR_L 19 +#define DSP_AR_DMA_CNT_H 20 +#define DSP_AR_DMA_CNT_L 21 +#define DSP_REG_0x2C 22 +#define DSP_REG_0x2E 23 +#define DSP_AI_DMA_START_H 24 +#define DSP_AI_DMA_START_L 25 +#define DSP_REG_0x34 26 +#define DSP_AI_DMA_CSR 27 +#define DSP_REG_0x38 28 +#define DSP_AI_DMA_BYTES_LEFT 29 + +FIXED_ADDR(volatile u16, DSP_HW_REGS[], 0xCC005000); + +CPP_WRAPPER_END() diff --git a/include/wii/os/OSContext.h b/include/wii/os/OSContext.h index 9038335..0fc542e 100644 --- a/include/wii/os/OSContext.h +++ b/include/wii/os/OSContext.h @@ -24,20 +24,26 @@ typedef struct } OSContext; SIZE_ASSERT(OSContext, 0x2c8) -UNKNOWN_FUNCTION(__OSLoadFPUContext); -UNKNOWN_FUNCTION(__OSSaveFPUContext); -UNKNOWN_FUNCTION(OSSaveFPUContext); -UNKNOWN_FUNCTION(OSSetCurrentContext); -UNKNOWN_FUNCTION(OSGetCurrentContext); -UNKNOWN_FUNCTION(OSSaveContext); -UNKNOWN_FUNCTION(OSLoadContext); +void __OSLoadFPUContext(u32, OSContext *); +void __OSSaveFPUContext(u32, u32, OSContext *); +void OSSaveFPUContext(OSContext * context); + +void OSSetCurrentContext(OSContext * context); +OSContext * OSGetCurrentContext(); + +u32 OSSaveContext(OSContext * context); +u32 OSLoadContext(OSContext * context); + u32 OSGetStackPointer(); -UNKNOWN_FUNCTION(OSSwitchFiber); -UNKNOWN_FUNCTION(OSSwitchFiberEx); -UNKNOWN_FUNCTION(OSClearContext); -UNKNOWN_FUNCTION(OSInitContext); + +s32 OSSwitchFiber(u32 pc, u32 r1); +s32 OSSwitchFiberEx(u32, u32, u32, u32, u32 pc, u32 r1); + +void OSClearContext(OSContext * context); +void OSInitContext(OSContext * context, u32 pc, u32 r1); void OSDumpContext(OSContext * context); + UNKNOWN_FUNCTION(OSSwitchFPUContext); -UNKNOWN_FUNCTION(__OSContextInit); +void __OSContextInit(); CPP_WRAPPER_END() diff --git a/include/wii/os/OSError.h b/include/wii/os/OSError.h index 5fe7e4e..bc97431 100644 --- a/include/wii/os/OSError.h +++ b/include/wii/os/OSError.h @@ -1,9 +1,34 @@ #pragma once #include +#include CPP_WRAPPER(wii::os) +USING(wii::os::OSContext) + +#define OS_ERROR_SYSTEM_RESET 0 +#define OS_ERROR_MACHINE_CHECK 1 +#define OS_ERROR_DSI 2 +#define OS_ERROR_ISI 3 +#define OS_ERROR_EXT_INTERRUPT 4 +#define OS_ERROR_ALIGNMENT 5 +#define OS_ERROR_PROGRAM 6 +#define OS_ERROR_FP_UNAVAIL 7 +#define OS_ERROR_DECREMENTER 8 +#define OS_ERROR_SYSTEM_CALL 9 +#define OS_ERROR_TRACE 10 +#define OS_ERROR_PERF_MONITOR 11 +#define OS_ERROR_IABR 12 +#define OS_ERROR_SMI 13 +#define OS_ERROR_THERMAL 14 +#define OS_ERROR_PROTECTION 15 +#define OS_ERROR_FP_EXCEPTION 16 +#define OS_ERROR_MAX 17 + +typedef void (*OSErrorHandler)(u16 error, OSContext* context, u32 dsisr, u32 dar, ...); +extern OSErrorHandler __OSErrorTable[OS_ERROR_MAX]; + DECOMP_STATIC(char __OSUnhandledException_msg1[]) DECOMP_STATIC(char __OSUnhandledException_msg2[]) DECOMP_STATIC(char __OSUnhandledException_msg3[]) @@ -11,11 +36,11 @@ DECOMP_STATIC(char __OSUnhandledException_msg3[]) ATTRIBUTE_FORMAT(printf, 1, 2) void OSReport(const char * message, ...); UNKNOWN_FUNCTION(OSVReport); -// Weak symbol, games overrides with its own +// Weak symbol, game overrides with its own ATTRIBUTE_FORMAT(printf, 3, 4) void OSPanic(const char * filename, s32 line, const char * msg, ...); UNKNOWN_FUNCTION(OSSetErrorHandler); -void __OSUnhandledException(s32 p1, s32 p2, s32 p3, s32 p4); +void __OSUnhandledException(u8 exception, OSContext* context, u32 dsisr, u32 dar); CPP_WRAPPER_END() diff --git a/include/wii/os/OSHardware.h b/include/wii/os/OSHardware.h new file mode 100644 index 0000000..e87a842 --- /dev/null +++ b/include/wii/os/OSHardware.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +CPP_WRAPPER(wii::os) + +USING(wii::os::OSContext) + +#define DI_DMA_MMADDR 5 + +FIXED_ADDR(volatile u32, DI_HW_REGS[], 0xcd006000); + +FIXED_ADDR(volatile OSContext *, OS_CURRENT_FPU_CONTEXT, 0x800000d8); + +CPP_WRAPPER_END() diff --git a/include/wii/os/OSInterrupt.h b/include/wii/os/OSInterrupt.h index 53f967a..1431e0e 100644 --- a/include/wii/os/OSInterrupt.h +++ b/include/wii/os/OSInterrupt.h @@ -1,9 +1,16 @@ #pragma once #include +#include CPP_WRAPPER(wii::os) +USING(wii::OS::OSTime) + +extern volatile OSTime __OSLastInterruptTime; +extern volatile s16 __OSLastInterrupt; +extern volatile u32 __OSLastInterruptSrr0; + u32 OSDisableInterrupts(); UNKNOWN_FUNCTION(OSEnableInterrupts); void OSRestoreInterrupts(u32 interruptMask); From f6494b55c38c9f9b8be056d37f30201d3f14b57a Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Fri, 29 Dec 2023 19:15:54 +0000 Subject: [PATCH 8/8] Fix OSInterrupt USING --- include/wii/os/OSInterrupt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wii/os/OSInterrupt.h b/include/wii/os/OSInterrupt.h index 1431e0e..bdc3ffe 100644 --- a/include/wii/os/OSInterrupt.h +++ b/include/wii/os/OSInterrupt.h @@ -5,7 +5,7 @@ CPP_WRAPPER(wii::os) -USING(wii::OS::OSTime) +USING(wii::os::OSTime) extern volatile OSTime __OSLastInterruptTime; extern volatile s16 __OSLastInterrupt;