Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from spm-decomp #17

Merged
merged 8 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions include/msl/stdarg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdarg.h> // makectx-ignore
#endif

CPP_WRAPPER_END()
2 changes: 1 addition & 1 deletion include/spm/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
92 changes: 92 additions & 0 deletions include/wii/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#pragma once

#include <common.h>

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);

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()
40 changes: 40 additions & 0 deletions include/wii/dsp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <common.h>

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()
32 changes: 19 additions & 13 deletions include/wii/os/OSContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
UNKNOWN_FUNCTION(OSGetStackPointer);
UNKNOWN_FUNCTION(OSSwitchFiber);
UNKNOWN_FUNCTION(OSSwitchFiberEx);
UNKNOWN_FUNCTION(OSClearContext);
UNKNOWN_FUNCTION(OSInitContext);
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();

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()
29 changes: 27 additions & 2 deletions include/wii/os/OSError.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
#pragma once

#include <common.h>
#include <wii/os/OSContext.h>

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[])

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()
16 changes: 16 additions & 0 deletions include/wii/os/OSHardware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <common.h>
#include <wii/os/OSContext.h>

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()
7 changes: 7 additions & 0 deletions include/wii/os/OSInterrupt.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#pragma once

#include <common.h>
#include <wii/os/OSTime.h>

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);
Expand Down