From fa95f9e6e881457b4a711809a1bf62480cea2c82 Mon Sep 17 00:00:00 2001 From: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Date: Wed, 18 Aug 2021 16:12:35 +0100 Subject: [PATCH] Migrated a lot of `boot` bss, matched a few NON_MATCHINGs in `boot` (#266) * Import bss to boot_main and idle, match last function in idle * Some pointer cleanup in idle, spec * Clean up idle, add build.c, add bss to CIC6105 * Import rand bss * sptask bss and a macro * sptask updated to use libultra macros * siacs.c bss * Macros in CIC and idle * controller bss * seteventmesg bss * spec * pimgr and piacs bss * initialize OK, threadsave, initialize, pimgr bss * Match DmaMgr_Start * Fix bss reorder using separate file * Small cleanup of hex/dec in buffer sizes * Add comment, remove unused bss from spec * Merge remote-tracking branch 'upstream/master' into boot_bss * Format * Delete files * remove commented-out structs * Bit more cleanup * Addressed reviews * Format --- include/functions.h | 11 +- include/os.h | 52 ++------- include/ultra64.h | 2 + include/ultra64/rcp.h | 14 +++ include/ultra64/vi.h | 105 ++++++++++++++++++ include/variables.h | 92 +++++++-------- include/viint.h | 10 +- include/z64.h | 7 -- spec | 23 +--- src/boot_O2/rand.c | 7 ++ src/boot_O2_g3/CIC6105.c | 10 +- src/boot_O2_g3/boot_main.c | 6 + src/boot_O2_g3/build.c | 3 + src/boot_O2_g3/idle.c | 37 +++--- src/boot_O2_g3/idle_extra_bss.c | 7 ++ src/boot_O2_g3/z_std_dma.c | 33 ++++-- src/code/z_lifemeter.c | 16 +-- src/libultra/gu/sins.c | 2 +- src/libultra/gu/sqrtf.c | 2 +- src/libultra/io/controller.c | 8 ++ src/libultra/io/piacs.c | 7 +- src/libultra/io/pimgr.c | 9 +- src/libultra/io/siacs.c | 3 + src/libultra/io/sprawdma.c | 2 +- src/libultra/io/sptask.c | 71 +++++------- src/libultra/os/initialize.c | 89 +++++++-------- src/libultra/os/seteventmesg.c | 2 + src/libultra/os/threadsave.c | 3 + src/overlays/actors/ovl_En_Daiku/z_en_daiku.c | 4 +- src/overlays/actors/ovl_En_Dnb/z_en_dnb.c | 2 +- src/overlays/actors/ovl_En_Ma4/z_en_ma4.c | 6 +- tools/disasm/files.txt | 7 +- tools/disasm/variables.txt | 6 +- 33 files changed, 389 insertions(+), 269 deletions(-) create mode 100644 include/ultra64/rcp.h create mode 100644 include/ultra64/vi.h create mode 100644 src/boot_O2_g3/build.c create mode 100644 src/boot_O2_g3/idle_extra_bss.c create mode 100644 src/libultra/os/threadsave.c diff --git a/include/functions.h b/include/functions.h index aead07dd36..184bf7daf1 100644 --- a/include/functions.h +++ b/include/functions.h @@ -11,13 +11,6 @@ double sqrt(double d); #pragma intrinsic(sqrt) void bootproc(void); -void Idle_ClearMemory(void* begin, void* end); -void Idle_InitFramebuffer(u32* ptr, u32 numBytes, u32 value); -void Idle_InitScreen(void); -void Idle_InitMemory(void); -void Idle_InitCodeAndMemory(void); -void Main_ThreadEntry(void* arg); -void Idle_InitVideo(void); void Idle_ThreadEntry(void* arg); void ViConfig_UpdateVi(u32 arg0); void ViConfig_UpdateBlack(void); @@ -315,7 +308,7 @@ void __osInitialize_autodetect(void); void* osViGetNextFramebuffer(void); void guPerspectiveF(float mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale); void guPerspective(Mtx* m, u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale); -s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size); +s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, u32 size); s32 __osSiRawStartDma(s32 direction, void* dramAddr); // void osEPiLinkHandle(void); void osViBlack(u8 active); @@ -494,7 +487,7 @@ float __ull_to_f(unsigned long long l); // void osVoiceControlGain(void); // void osVoiceStartReadData(void); void* osViGetCurrentFramebuffer(void); -s32 __osSpSetPc(u32 data); +s32 __osSpSetPc(void* data); // void __osVoiceContWrite4(void); void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg); // void __osSetHWIntrRoutine(void); diff --git a/include/os.h b/include/os.h index 3ae69bcdfa..50f3b10c48 100644 --- a/include/os.h +++ b/include/os.h @@ -18,7 +18,7 @@ typedef struct { /* 0x0C */ u32 sectorSize; /* 0x10 */ u32 C1ErrNum; /* 0x14 */ u32 C1ErrSector[4]; -} __OSBlockInfo; +} __OSBlockInfo; // size = 0x24 typedef struct { @@ -30,7 +30,7 @@ typedef struct { /* 0x10 */ u32 bmCtlShadow; /* 0x14 */ u32 seqCtlShadow; /* 0x18 */ __OSBlockInfo block[2]; -} __OSTranxInfo; +} __OSTranxInfo; // size = 0x60 typedef struct OSPiHandle_s { @@ -44,13 +44,13 @@ typedef struct OSPiHandle_s { /* 0x0C */ u32 baseAddress; /* 0x10 */ u32 speed; /* 0x14 */ __OSTranxInfo transferInfo; -} OSPiHandle; +} OSPiHandle; // size = 0x74 typedef struct { /* 0x0 */ u8 type; /* 0x4 */ u32 address; -} OSPiInfo; +} OSPiInfo; // size = 0x8 typedef struct { @@ -58,7 +58,7 @@ typedef struct { /* 0x2 */ u8 pri; /* 0x3 */ u8 status; /* 0x4 */ OSMesgQueue* retQueue; -} OSIoMesgHdr; +} OSIoMesgHdr; // size = 0x8 typedef struct { @@ -67,7 +67,7 @@ typedef struct { /* 0x0C */ u32 devAddr; /* 0x10 */ u32 size; /* 0x14 */ OSPiHandle* piHandle; -} OSIoMesg; +} OSIoMesg; // size = 0x88 typedef struct { @@ -78,37 +78,9 @@ typedef struct { /* 0x10 */ OSMesgQueue* acsQueue; /* 0x14 */ s32 (*piDmaCallback)(s32, u32, void*, u32); /* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, u32, void*, u32); -} OSDevMgr; +} OSDevMgr; // size = 0x1C -typedef struct { - /* 0x00 */ u32 ctrl; - /* 0x04 */ u32 width; - /* 0x08 */ u32 burst; - /* 0x0C */ u32 vSync; - /* 0x10 */ u32 hSync; - /* 0x14 */ u32 leap; - /* 0x18 */ u32 hStart; - /* 0x1C */ u32 xScale; - /* 0x20 */ u32 vCurrent; -} OSViCommonRegs; - - -typedef struct { - /* 0x00 */ u32 origin; - /* 0x04 */ u32 yScale; - /* 0x08 */ u32 vStart; - /* 0x0C */ u32 vBurst; - /* 0x10 */ u32 vIntr; -} OSViFieldRegs; - - -typedef struct { - /* 0x00 */ u8 type; - /* 0x04 */ OSViCommonRegs comRegs; - /* 0x28 */ OSViFieldRegs fldRegs[2]; -} OSViMode; - typedef u64 OSTime; @@ -119,14 +91,14 @@ typedef struct OSTimer_s { /* 0x10 */ OSTime value; /* 0x18 */ OSMesgQueue* mq; /* 0x1C */ OSMesg msg; -} OSTimer; +} OSTimer; // size = 0x20 typedef struct { /* 0x0 */ u16 type; /* 0x2 */ u8 status; /* 0x3 */ u8 errno; -} OSContStatus; +} OSContStatus; // size = 0x4 typedef struct { @@ -134,7 +106,7 @@ typedef struct { /* 0x2 */ s8 stick_x; /* 0x3 */ s8 stick_y; /* 0x4 */ u8 errno; -} OSContPad; +} OSContPad; // size = 0x6 typedef struct { @@ -143,14 +115,14 @@ typedef struct { /* 0x24 */ u8 addressCrc; /* 0x25 */ u8 dataCrc; /* 0x26 */ u8 errno; -} OSContRamIo; +} OSContRamIo; // size = 0x28 typedef struct { /* 0x0 */ u16* histo_base; /* 0x4 */ u32 histo_size; /* 0x8 */ u32* text_start; /* 0xC */ u32* text_end; -} OSProf; +} OSProf; // size = 0x10 typedef struct { /* 0x0 */ OSMesgQueue* mq; diff --git a/include/ultra64.h b/include/ultra64.h index be8a7db12b..d309026b97 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -10,6 +10,8 @@ #include "ultra64/message.h" #include "ultra64/sptask.h" #include "ultra64/thread.h" +#include "ultra64/rcp.h" #include "ultra64/rsp.h" +#include "ultra64/vi.h" #endif diff --git a/include/ultra64/rcp.h b/include/ultra64/rcp.h new file mode 100644 index 0000000000..6bd778ccfa --- /dev/null +++ b/include/ultra64/rcp.h @@ -0,0 +1,14 @@ +#ifndef _ULTRA64_RCP_H_ +#define _ULTRA64_RCP_H_ + +#define VI_NTSC_CLOCK 48681812 /* Hz = 48.681812 MHz */ +#define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */ +#define VI_MPAL_CLOCK 48628316 /* Hz = 48.628316 MHz */ + +#define DEVICE_TYPE_CART 0 /* ROM cartridge */ +#define DEVICE_TYPE_BULK 1 /* ROM bulk */ +#define DEVICE_TYPE_64DD 2 /* 64 Disk Drive */ +#define DEVICE_TYPE_SRAM 3 /* SRAM */ +#define DEVICE_TYPE_INIT 7 /* initial value */ + +#endif diff --git a/include/ultra64/vi.h b/include/ultra64/vi.h new file mode 100644 index 0000000000..7830873613 --- /dev/null +++ b/include/ultra64/vi.h @@ -0,0 +1,105 @@ +#ifndef _ULTRA64_VI_H_ +#define _ULTRA64_VI_H_ + +/* Special Features */ +#define OS_VI_GAMMA_ON 0x0001 +#define OS_VI_GAMMA_OFF 0x0002 +#define OS_VI_GAMMA_DITHER_ON 0x0004 +#define OS_VI_GAMMA_DITHER_OFF 0x0008 +#define OS_VI_DIVOT_ON 0x0010 +#define OS_VI_DIVOT_OFF 0x0020 +#define OS_VI_DITHER_FILTER_ON 0x0040 +#define OS_VI_DITHER_FILTER_OFF 0x0080 + +#define OS_VI_GAMMA 0x08 +#define OS_VI_GAMMA_DITHER 0x04 +#define OS_VI_DIVOT 0x10 +#define OS_VI_DITHER_FILTER 0x10000 +#define OS_VI_UNK1 0x1 +#define OS_VI_UNK2 0x2 +#define OS_VI_UNK40 0x40 +#define OS_VI_UNK100 0x100 +#define OS_VI_UNK200 0x200 +#define OS_VI_UNK1000 0x1000 +#define OS_VI_UNK2000 0x2000 + +typedef struct { + /* 0x00 */ u32 ctrl; + /* 0x04 */ u32 width; + /* 0x08 */ u32 burst; + /* 0x0C */ u32 vSync; + /* 0x10 */ u32 hSync; + /* 0x14 */ u32 leap; + /* 0x18 */ u32 hStart; + /* 0x1C */ u32 xScale; + /* 0x20 */ u32 vCurrent; +} OSViCommonRegs; // size = 0x20 + +typedef struct { + /* 0x00 */ u32 origin; + /* 0x04 */ u32 yScale; + /* 0x08 */ u32 vStart; + /* 0x0C */ u32 vBurst; + /* 0x10 */ u32 vIntr; +} OSViFieldRegs; // size = 0x14 + +typedef struct { + /* 0x00 */ u8 type; + /* 0x04 */ OSViCommonRegs comRegs; + /* 0x24 */ OSViFieldRegs fldRegs[2]; +} OSViMode; // size = 0x4C + +typedef struct { + /* 0x0 */ f32 factor; + /* 0x4 */ u16 offset; + /* 0x8 */ u32 scale; +} __OSViScale; // size = 0x0C + +typedef struct { + /* 0x00 */ u16 state; + /* 0x02 */ u16 retraceCount; + /* 0x04 */ void* buffer; + /* 0x08 */ OSViMode* modep; + /* 0x0c */ u32 features; + /* 0x10 */ OSMesgQueue* mq; + /* 0x14 */ OSMesg* msg; + /* 0x18 */ __OSViScale x; + /* 0x24 */ __OSViScale y; +} OSViContext; // size = 0x30 + +#define OS_VI_NTSC_LPN1 0 /* NTSC */ +#define OS_VI_NTSC_LPF1 1 +#define OS_VI_NTSC_LAN1 2 +#define OS_VI_NTSC_LAF1 3 +#define OS_VI_NTSC_LPN2 4 +#define OS_VI_NTSC_LPF2 5 +#define OS_VI_NTSC_LAN2 6 +#define OS_VI_NTSC_LAF2 7 +#define OS_VI_NTSC_HPN1 8 +#define OS_VI_NTSC_HPF1 9 +#define OS_VI_NTSC_HAN1 10 +#define OS_VI_NTSC_HAF1 11 +#define OS_VI_NTSC_HPN2 12 +#define OS_VI_NTSC_HPF2 13 + +#define OS_VI_PAL_LPN1 14 /* PAL */ +#define OS_VI_PAL_LPF1 15 +#define OS_VI_PAL_LAN1 16 +#define OS_VI_PAL_LAF1 17 +#define OS_VI_PAL_LPN2 18 +#define OS_VI_PAL_LPF2 19 +#define OS_VI_PAL_LAN2 20 +#define OS_VI_PAL_LAF2 21 +#define OS_VI_PAL_HPN1 22 +#define OS_VI_PAL_HPF1 23 +#define OS_VI_PAL_HAN1 24 +#define OS_VI_PAL_HAF1 25 +#define OS_VI_PAL_HPN2 26 +#define OS_VI_PAL_HPF2 27 + +#define OS_TV_PAL 0 +#define OS_TV_NTSC 1 +#define OS_TV_MPAL 2 +#define OS_VI_UNK28 28 + +#endif diff --git a/include/variables.h b/include/variables.h index 5cdef41a07..9452578312 100644 --- a/include/variables.h +++ b/include/variables.h @@ -44,10 +44,10 @@ extern StackEntry* sStackInfoListEnd; // extern UNK_TYPE1 sGfxPrintFontData; // extern UNK_TYPE4 D_80097500; // extern UNK_TYPE4 D_80097524; -extern u32 sRandInt; +// extern u32 sRandInt; extern OSViMode osViModeNtscHpf1; extern OSViMode osViModePalLan1; -extern s16 sintable[1024]; +extern s16 sintable[0x400]; extern __osHwInt __osHwIntTable[]; // extern UNK_TYPE1 D_80097DE4; // extern UNK_TYPE4 D_80097E08; @@ -280,21 +280,22 @@ extern char D_800994B0[]; extern f64 D_800994B8; extern f64 D_800994C0; extern f64 D_800994C8; -extern char D_800994D0[]; -extern char D_800994DC[]; -extern StackEntry sBootThreadInfo; -extern OSThread sIdleThread; -extern u8 sIdleThreadStack[1024]; -extern StackEntry sIdleThreadInfo; -extern u8 sBootThreadStack[1024]; -extern IrqMgr gIrqMgr; -extern u8 sIrqMgrStack[1280]; -extern StackEntry sIrqMgrStackInfo; -extern OSThread gMainThread; -extern u8 sMainStack[2304]; -extern StackEntry sMainStackInfo; -extern OSMesg sPiMgrCmdBuff[50]; -extern OSMesgQueue gPiMgrCmdQ; +extern char gBuildTeam[]; +extern char gBuildDate[]; +extern char gBuildMakeOption[]; +// extern StackEntry sBootThreadInfo; +// extern OSThread sIdleThread; +// extern u8 sIdleThreadStack[0x400]; +// extern StackEntry sIdleThreadInfo; +// extern u8 sBootThreadStack[0x400]; +// extern IrqMgr gIrqMgr; +// extern u8 sIrqMgrStack[0x500]; +// extern StackEntry sIrqMgrStackInfo; +// extern OSThread gMainThread; +// extern u8 sMainStack[0x900]; +// extern StackEntry sMainStackInfo; +// extern OSMesg sPiMgrCmdBuff[50]; +// extern OSMesgQueue gPiMgrCmdQ; extern OSViMode gViConfigMode; extern u8 D_8009B290; extern StackEntry sDmaMgrStackInfo; @@ -302,51 +303,50 @@ extern u16 numDmaEntries; extern OSMesgQueue sDmaMgrMsgQueue; extern OSMesg sDmaMgrMsgs[32]; extern OSThread sDmaMgrThread; -extern u8 sDmaMgrStack[1280]; -// extern UNK_TYPE1 D_8009BA08; +extern u8 sDmaMgrStack[0x500]; extern u8 sYaz0DataBuffer[0x400]; extern u8* sYaz0CurDataEnd; extern u32 sYaz0CurRomStart; extern u32 sYaz0CurSize; extern u8* sYaz0MaxPtr; extern u8* D_8009BE20; -extern UNK_TYPE4 D_8009BE30; -extern UNK_TYPE4 D_8009BE34; -extern FaultClient romInfoFaultClient; +// extern UNK_TYPE4 D_8009BE30; +// extern UNK_TYPE4 D_8009BE34; +// extern FaultClient romInfoFaultClient; extern FaultThreadStruct* sFaultContext; extern f32 D_8009BE54; extern u32 faultCustomOptions; extern u32 faultCopyToLog; -extern u8 sFaultStack[1536]; +extern u8 sFaultStack[0x600]; extern StackEntry sFaultThreadInfo; extern FaultThreadStruct gFaultStruct; extern FaultDrawer sFaultDrawerStruct; // extern UNK_TYPE4 D_8009CD10; -extern Arena gSystemArena; +// extern Arena gSystemArena; extern u32 sRandFloat; // extern UNK_TYPE4 sArenaLockMsg; -extern OSTask tmp_task; +// extern OSTask tmp_task; // extern UNK_TYPE1 D_8009CDB0; -extern OSMesg siAccessBuf[1]; -extern OSMesgQueue __osSiAccessQueue; +// extern OSMesg siAccessBuf[1]; +// extern OSMesgQueue __osSiAccessQueue; extern OSPifRam __osContPifRam; // extern UNK_TYPE1 D_8009CF0C; extern u8 __osContLastCmd; extern u8 __osMaxControllers; -extern OSMesgQueue D_8009CF38; -extern OSMesg D_8009CF50[1]; -// extern UNK_TYPE1 D_8009CF60; -extern UNK_TYPE4 D_8009CF70; +// extern OSMesgQueue D_8009CF38; +// extern OSMesg D_8009CF50; +extern UNK_TYPE1 D_8009CF60; +// extern UNK_TYPE4 D_8009CF70; extern OSThread __osThreadSave; extern OSPiHandle D_8009D130; extern OSPiHandle D_8009D1A8; -extern OSThread D_8009D220; -extern u8 piManagerStack[4096]; -extern OSMesgQueue D_8009E3D0; -extern OSMesg D_8009E3E8[1]; +// extern OSThread D_8009D220; +// extern u8 piManagerStack[0x1000]; +// extern OSMesgQueue D_8009E3D0; +// extern OSMesg D_8009E3E8[1]; extern OSMesg D_8009E3F0[1]; extern OSMesgQueue __osPiAccessQueue; -// extern UNK_TYPE1 D_8009E410; +extern __OSInode __osPfsInodeCache; extern __OSEventState __osEventStateTab[16]; extern OSTimer D_8009E590; extern OSTime __osCurrentTime; @@ -356,7 +356,7 @@ extern u32 __osTimerCounter; extern OSPifRam __osPfsPifRam; extern OSPiHandle CartRomHandle; extern OSThread viThread; -extern u8 viThreadStack[4096]; +extern u8 viThreadStack[0x1000]; extern OSMesgQueue viEventQueue; extern OSMesg viEventBuf[5]; extern OSIoMesg viRetraceMsg; @@ -3425,7 +3425,7 @@ extern u8 D_801F6DFC; extern SlowlyTask D_801F6E00; extern s32 D_801F6FC0; extern StackEntry slowlyStackEntry; -extern u8 slowlyStack[4096]; +extern u8 slowlyStack[0x1000]; extern UNK_TYPE1 D_801F7FE8; extern UNK_TYPE1 D_801F7FF0; extern struct_801F8010 D_801F8010; @@ -3445,10 +3445,10 @@ extern IrqMgrClient mainIrqmgrCallbackNode; extern OSMesgQueue mainIrqmgrCallbackQueue; extern OSMesg mainIrqCallbackBuffer[60]; extern OSThread graphOSThread; -extern u8 graphStack[6144]; -extern u8 schedStack[1536]; -extern u8 audioStack[2048]; -extern u8 padmgrStack[1280]; +extern u8 graphStack[0x1800]; +extern u8 schedStack[0x600]; +extern u8 audioStack[0x800]; +extern u8 padmgrStack[0x500]; extern StackEntry graphStackEntry; extern StackEntry schedStackEntry; extern StackEntry audioStackEntry; @@ -3575,7 +3575,7 @@ extern MtxF* sCurrentMatrix; // extern UNK_TYPE1 D_801FBE28; // extern UNK_TYPE1 D_801FBE2C; // extern UNK_TYPE4 D_801FBE30; -extern u8 sys_flashromStack[4096]; +extern u8 sys_flashromStack[0x1000]; extern StackEntry sys_flashromStackEntry; extern OSThread sys_flashromOSThread; extern s80185D40 D_801FD008; @@ -3739,11 +3739,11 @@ extern s801FE7C0 D_801FE7C0[1]; extern OSMesgQueue D_80202980; // extern UNK_TYPE1 D_802029D8; extern OSMesgQueue D_80202AB0; -extern OSMesg D_80202AC8[16]; +extern OSMesg D_80202AC8[0x10]; extern OSMesgQueue D_80202B08; -extern OSMesg D_80202B20[16]; +extern OSMesg D_80202B20[0x10]; extern OSMesgQueue D_80202B60; -extern OSMesg D_80202B78[64]; +extern OSMesg D_80202B78[0x40]; extern OSMesgQueue D_80203278; extern OSMesg D_80203290[1]; // extern UNK_TYPE1 D_80203294; diff --git a/include/viint.h b/include/viint.h index 790bed47bf..e850c895aa 100644 --- a/include/viint.h +++ b/include/viint.h @@ -6,11 +6,11 @@ #include "PR/ultratypes.h" #include "os.h" -typedef struct { - /* 0x0 */ f32 factor; - /* 0x4 */ u16 offset; - /* 0x8 */ u32 scale; -} __OSViScale; +// typedef struct { +// /* 0x0 */ f32 factor; +// /* 0x4 */ u16 offset; +// /* 0x8 */ u32 scale; +// } __OSViScale; typedef struct { diff --git a/include/z64.h b/include/z64.h index 9f186285f1..e7f8b5382e 100644 --- a/include/z64.h +++ b/include/z64.h @@ -390,13 +390,6 @@ typedef struct { /* 0xC */ s32 rightX; } Viewport; // size = 0x10 -typedef struct { - /* 0x0 */ unsigned int inst1; - /* 0x4 */ unsigned int inst2; - /* 0x8 */ unsigned int inst3; - /* 0xC */ unsigned int inst4; -} __osExceptionVector; // size = 0x10 - typedef void*(*fault_address_converter_func)(void* addr, void* arg); typedef void(*fault_client_func)(void* arg1, void* arg2); diff --git a/spec b/spec index 0c41e2903b..9456cfad28 100644 --- a/spec +++ b/spec @@ -14,18 +14,15 @@ beginseg name "boot" address 0x80080060 include "build/src/boot_O2_g3/boot_main.o" - include "build/data/boot/boot_main.bss.o" include "build/data/boot/rsp_boot.data.o" include "build/src/boot_O2_g3/idle.o" - include "build/data/boot/idle.bss.o" + include "build/src/boot_O2_g3/idle_extra_bss.o" include "build/src/boot_O2_g3/viconfig.o" include "build/data/boot/viconfig.data.o" include "build/src/boot_O2_g3/z_std_dma.o" - include "build/data/boot/z_std_dma.bss.o" include "build/src/boot_O2_g3/yaz0.o" include "build/src/boot_O2_g3/irqmgr.o" include "build/src/boot_O2_g3/CIC6105.o" - include "build/data/boot/CIC6105.bss.o" include "build/src/boot_O2_g3/syncprintf.o" include "build/src/boot_O2_g3/fault.o" include "build/data/boot/fault.data.o" @@ -50,8 +47,6 @@ beginseg include "build/asm/boot/fp.text.o" include "build/src/boot_O2/system_malloc.o" include "build/src/boot_O2/rand.o" - include "build/data/boot/rand.data.o" - include "build/data/boot/rand.bss.o" include "build/src/boot_O2/__osMalloc.o" include "build/data/boot/__osMalloc.bss.o" include "build/src/libultra/rmon/sprintf.o" @@ -72,7 +67,6 @@ beginseg include "build/src/libultra/gu/sinf.o" include "build/src/libultra/gu/sins.o" include "build/src/libultra/io/sptask.o" - include "build/data/boot/sptask.bss.o" include "build/src/libultra/libc/ll.o" include "build/asm/boot/exceptasm.text.o" include "build/data/boot/exceptasm.data.o" @@ -84,19 +78,17 @@ beginseg include "build/src/libultra/io/rumblepak.o" include "build/data/boot/rumblepak.bss.o" include "build/src/libultra/io/siacs.o" - include "build/data/boot/siacs.bss.o" include "build/src/libultra/io/controller.o" - include "build/data/boot/controller.bss.o" include "build/src/libultra/os/createthread.o" include "build/src/libultra/io/contreaddata.o" include "build/src/libultra/voice/voicegetreaddata.o" + include "build/data/boot/voicegetreaddata.bss.o" include "build/src/libultra/os/virtualtophysical.o" include "build/asm/boot/getsr.text.o" include "build/asm/boot/setsr.text.o" include "build/asm/boot/writebackdcache.text.o" - include "build/data/boot/threadsave.bss.o" include "build/src/libultra/os/initialize.o" - include "build/data/boot/initialize.bss.o" + include "build/src/libultra/os/threadsave.o" pad_text pad_text pad_text @@ -125,20 +117,19 @@ beginseg include "build/asm/boot/probetlb.text.o" include "build/src/libultra/io/pimgr.o" include "build/data/boot/pimgr.data.o" - include "build/data/boot/pimgr.bss.o" include "build/src/libultra/io/piacs.o" pad_text include "build/src/libultra/io/devmgr.o" include "build/src/libultra/io/pirawdma.o" include "build/src/libultra/io/contpfs.o" include "build/data/boot/contpfs.data.o" + include "build/data/boot/contpfs.bss.o" include "build/asm/boot/getcount.text.o" pad_text include "build/asm/boot/guMtxL2F.text.o" include "build/src/libultra/os/getmemsize.o" include "build/src/libultra/io/pfssearchfile.o" include "build/src/libultra/os/seteventmesg.o" - include "build/data/boot/seteventmesg.bss.o" include "build/src/libultra/gu/sqrtf.o" include "build/src/libultra/os/afterprenmi.o" include "build/src/libultra/io/contquery.o" @@ -263,7 +254,7 @@ beginseg include "build/src/boot_O2/__osStrcmp.o" include "build/src/boot_O2/__osStrcpy.o" include "build/src/boot_O2/__osMemcpy.o" - include "build/data/boot/build.rodata.o" + include "build/src/boot_O2_g3/build.o" endseg beginseg @@ -1767,11 +1758,7 @@ beginseg name "ovl_En_Weather_Tag" compress include "build/src/overlays/actors/ovl_En_Weather_Tag/z_en_weather_tag.o" -#ifdef NON_MATCHING - // TODO -#else include "build/src/overlays/actors/ovl_En_Weather_Tag/ovl_En_Weather_Tag_reloc.o" -#endif endseg beginseg diff --git a/src/boot_O2/rand.c b/src/boot_O2/rand.c index 6edf7490ef..de603590eb 100644 --- a/src/boot_O2/rand.c +++ b/src/boot_O2/rand.c @@ -1,5 +1,12 @@ #include "global.h" +// The latest generated random number, used to generate the next number in the sequence. +static u32 sRandInt = 1; + +// Space to store a value to be re-interpreted as a float. +// This can't be static because it is used in z_kankyo +u32 sRandFloat; + #define RAND_MULTIPLIER 1664525 #define RAND_INCREMENT 1013904223 diff --git a/src/boot_O2_g3/CIC6105.c b/src/boot_O2_g3/CIC6105.c index e0b8811a07..5a51b22c8a 100644 --- a/src/boot_O2_g3/CIC6105.c +++ b/src/boot_O2_g3/CIC6105.c @@ -1,5 +1,9 @@ #include "global.h" +UNK_TYPE4 D_8009BE30; +UNK_TYPE4 D_8009BE34; +FaultClient romInfoFaultClient; + void CIC6105_Nop80081820(void) { } @@ -7,9 +11,9 @@ void CIC6105_Nop80081828(void) { } void CIC6105_PrintRomInfo(void) { - FaultDrawer_DrawText(80, 200, "SP_STATUS %08x", (UNK_PTR)(*(u32*)0xA4040010)); - FaultDrawer_DrawText(40, 184, "ROM_F [Creator:%s]", &D_800994D0); - FaultDrawer_DrawText(56, 192, "[Date:%s]", &D_800994DC); + FaultDrawer_DrawText(80, 200, "SP_STATUS %08x", HW_REG(SP_STATUS_REG, u32)); + FaultDrawer_DrawText(40, 184, "ROM_F [Creator:%s]", gBuildTeam); + FaultDrawer_DrawText(56, 192, "[Date:%s]", gBuildDate); } void CIC6105_AddRomInfoFaultPage(void) { diff --git a/src/boot_O2_g3/boot_main.c b/src/boot_O2_g3/boot_main.c index 488e2dddf2..04bb9a33ae 100644 --- a/src/boot_O2_g3/boot_main.c +++ b/src/boot_O2_g3/boot_main.c @@ -1,5 +1,11 @@ #include "global.h" +StackEntry sBootThreadInfo; +OSThread sIdleThread; +u8 sIdleThreadStack[0x400]; +StackEntry sIdleThreadInfo; +u8 sBootThreadStack[0x400]; + void bootproc(void) { StackCheck_Init(&sBootThreadInfo, sBootThreadStack, sBootThreadStack + sizeof(sBootThreadStack), 0, -1, "boot"); osMemSize = osGetMemSize(); diff --git a/src/boot_O2_g3/build.c b/src/boot_O2_g3/build.c new file mode 100644 index 0000000000..23bd1cd592 --- /dev/null +++ b/src/boot_O2_g3/build.c @@ -0,0 +1,3 @@ +const char gBuildTeam[] = "zelda@srd44"; +const char gBuildDate[] = "00-07-31 17:04:16"; +const char gBuildMakeOption[] = ""; diff --git a/src/boot_O2_g3/idle.c b/src/boot_O2_g3/idle.c index 41a074a026..4d01b4c379 100644 --- a/src/boot_O2_g3/idle.c +++ b/src/boot_O2_g3/idle.c @@ -7,9 +7,18 @@ u32 gViConfigFeatures = 0x42; f32 gViConfigXScale = 1.0f; f32 gViConfigYScale = 1.0f; +IrqMgr gIrqMgr; +u8 sIrqMgrStack[0x500]; +StackEntry sIrqMgrStackInfo; +OSThread gMainThread; +u8 sMainStack[0x900]; +StackEntry sMainStackInfo; +OSMesg sPiMgrCmdBuff[50]; +OSMesgQueue gPiMgrCmdQ; + void Idle_ClearMemory(void* begin, void* end) { if (begin < end) { - bzero(begin, (s32)(int)end - (int)begin); + bzero(begin, (u32)end - (u32)begin); } } @@ -23,23 +32,21 @@ void Idle_InitFramebuffer(u32* ptr, u32 numBytes, u32 value) { } void Idle_InitScreen(void) { - Idle_InitFramebuffer((u32*)&gFramebuffer1, 0x25800, 0x00010001); + Idle_InitFramebuffer((u32*)gFramebuffer1, 0x25800, 0x00010001); ViConfig_UpdateVi(0); - osViSwapBuffer(&gFramebuffer1); + osViSwapBuffer(gFramebuffer1); osViBlack(0); } void Idle_InitMemory(void) { u32 pad; - void* memEnd = (void*)(0x80000000 + osMemSize); + void* memEnd = OS_PHYSICAL_TO_K0(osMemSize); - Idle_ClearMemory((void*)0x80000400, &gFramebuffer1); - Idle_ClearMemory(&D_80025D00, (int*)&bootproc); - Idle_ClearMemory(&gGfxSPTaskYieldBuffer, memEnd); + Idle_ClearMemory(0x80000400, gFramebuffer1); + Idle_ClearMemory(D_80025D00, bootproc); + Idle_ClearMemory(gGfxSPTaskYieldBuffer, memEnd); } -#ifdef NON_MATCHING -// regalloc around DmaMgr_SendRequestImpl void Idle_InitCodeAndMemory(void) { DmaRequest dmaReq; OSMesgQueue queue; @@ -51,8 +58,8 @@ void Idle_InitCodeAndMemory(void) { oldSize = sDmaMgrDmaBuffSize; sDmaMgrDmaBuffSize = 0; - DmaMgr_SendRequestImpl(&dmaReq, (u32)_codeSegmentStart, (u32)_codeSegmentRomStart, - (u32)_codeSegmentRomEnd - (u32)_codeSegmentRomStart, 0, &queue, 0); + DmaMgr_SendRequestImpl(&dmaReq, _codeSegmentStart, _codeSegmentRomStart, _codeSegmentRomEnd - _codeSegmentRomStart, + 0, &queue, 0); Idle_InitScreen(); Idle_InitMemory(); osRecvMesg(&queue, NULL, 1); @@ -61,9 +68,6 @@ void Idle_InitCodeAndMemory(void) { Idle_ClearMemory(_codeSegmentBssStart, _codeSegmentBssEnd); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/boot/idle/Idle_InitCodeAndMemory.s") -#endif void Main_ThreadEntry(void* arg) { StackCheck_Init(&sIrqMgrStackInfo, sIrqMgrStack, sIrqMgrStack + sizeof(sIrqMgrStack), 0, 256, "irqmgr"); @@ -109,7 +113,4 @@ void Idle_ThreadEntry(void* arg) { osStartThread(&gMainThread); osSetThreadPri(NULL, 0); - for (;;) { - ; - } -} + do { } while (true); } diff --git a/src/boot_O2_g3/idle_extra_bss.c b/src/boot_O2_g3/idle_extra_bss.c new file mode 100644 index 0000000000..019b626405 --- /dev/null +++ b/src/boot_O2_g3/idle_extra_bss.c @@ -0,0 +1,7 @@ +#include "global.h" + +// This file is currently required to fix bss reordering in idle.c. It is not resolved by prevent_bss_reordering.h . +// Hopefully it will not be permanent. + +OSViMode gViConfigMode; +u8 D_8009B290; diff --git a/src/boot_O2_g3/z_std_dma.c b/src/boot_O2_g3/z_std_dma.c index 0b278dbb59..5a29d5d56a 100644 --- a/src/boot_O2_g3/z_std_dma.c +++ b/src/boot_O2_g3/z_std_dma.c @@ -2,6 +2,13 @@ u32 sDmaMgrDmaBuffSize = 0x2000; +StackEntry sDmaMgrStackInfo; +u16 numDmaEntries; +OSMesgQueue sDmaMgrMsgQueue; +OSMesg sDmaMgrMsgs[32]; +OSThread sDmaMgrThread; +u8 sDmaMgrStack[0x500]; + s32 DmaMgr_DMARomToRam(u32 rom, void* ram, u32 size) { OSIoMesg ioMsg; OSMesgQueue queue; @@ -202,30 +209,34 @@ s32 DmaMgr_SendRequest0(void* vramStart, u32 vromStart, u32 size) { return 0; } -#ifdef NON_MATCHING -// TODO missing a useless move initializing v0, and some reorderings -void DmaMgr_Start() { +void DmaMgr_Start(void) { DmaEntry* iter; u32 idx; - DmaMgr_DMARomToRam((u32)_dmadataSegmentRomStart, dmadata, (u32)(_dmadataSegmentRomEnd - _dmadataSegmentRomStart)); + DmaMgr_DMARomToRam((u32)_dmadataSegmentRomStart, (u32)dmadata, + (u32)_dmadataSegmentRomEnd - (u32)_dmadataSegmentRomStart); - for (iter = dmadata, idx = 0; iter->vromEnd != 0; iter++, idx++) { - ; +dummy_label:; + + iter = dmadata; + idx = 0; + while (iter->vromEnd != 0) { + iter++; + idx++; } numDmaEntries = idx; +dummy_label_2:; + osCreateMesgQueue(&sDmaMgrMsgQueue, sDmaMgrMsgs, ARRAY_COUNT(sDmaMgrMsgs)); - StackCheck_Init(&sDmaMgrStackInfo, sDmaMgrStack, sDmaMgrStack + sizeof(sDmaMgrStack), 0, 256, dmamgrThreadName); + StackCheck_Init(&sDmaMgrStackInfo, sDmaMgrStack, sDmaMgrStack + sizeof(sDmaMgrStack), 0, 0x100, "dmamgr"); osCreateThread(&sDmaMgrThread, Z_THREAD_ID_DMAMGR, DmaMgr_ThreadEntry, NULL, sDmaMgrStack + sizeof(sDmaMgrStack), Z_PRIORITY_DMAMGR); + osStartThread(&sDmaMgrThread); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/boot/z_std_dma/DmaMgr_Start.s") -#endif -void DmaMgr_Stop() { +void DmaMgr_Stop(void) { osSendMesg(&sDmaMgrMsgQueue, NULL, OS_MESG_BLOCK); } diff --git a/src/code/z_lifemeter.c b/src/code/z_lifemeter.c index e2a91199d3..bbfad829f3 100644 --- a/src/code/z_lifemeter.c +++ b/src/code/z_lifemeter.c @@ -169,7 +169,7 @@ void LifeMeter_UpdateColors(GlobalContext* globalCtx) { s32 LifeMeter_SaveInterfaceHealth(GlobalContext* globalCtx) { gSaveContext.health = globalCtx->interfaceCtx.health; - + return 1; } @@ -227,7 +227,7 @@ void LifeMeter_Draw(GlobalContext* globalCtx) { OPEN_DISPS(gfxCtx); - if ((gSaveContext.health % 0x10) == 0){ + if ((gSaveContext.health % 0x10) == 0) { fullHeartCount--; } offsetY = 0.0f; @@ -342,8 +342,8 @@ void LifeMeter_Draw(GlobalContext* globalCtx) { } else if (curCombineModeSet != 3) { curCombineModeSet = 3; func_8012C654(gfxCtx); - gDPSetCombineLERP(OVERLAY_DISP++, ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, - 0, ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0); + gDPSetCombineLERP(OVERLAY_DISP++, ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, + ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0); } posY = 26.0f + offsetY; posX = 30.0f + offsetX; @@ -353,11 +353,11 @@ void LifeMeter_Draw(GlobalContext* globalCtx) { halfTexSize = 8.0f; halfTexSize *= 0.68f; gSPTextureRectangle(OVERLAY_DISP++, (s32)((posX - halfTexSize) * 4), (s32)((posY - halfTexSize) * 4), - (s32)((posX + halfTexSize) * 4), (s32)((posY + halfTexSize) * 4), G_TX_RENDERTILE, - 0, 0, (s32) temp_f4, (s32) temp_f4); + (s32)((posX + halfTexSize) * 4), (s32)((posY + halfTexSize) * 4), G_TX_RENDERTILE, 0, 0, + (s32)temp_f4, (s32)temp_f4); } else { Mtx* mtx; - + if ((ddCount < 0) || (ddCount < i)) { if (curCombineModeSet != 2) { curCombineModeSet = 2; @@ -401,7 +401,7 @@ void LifeMeter_UpdateSizeAndBeep(GlobalContext* globalCtx) { interfaceCtx->lifeSizeChangeDirection = 0; if (func_801233E4(globalCtx) == 0 && (globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && LifeMeter_IsCritical() && func_801690CC(globalCtx) == 0) { - //func_801233E4 and func_801690CC : Check if in Cutscene + // func_801233E4 and func_801690CC : Check if in Cutscene play_sound(NA_SE_SY_HITPOINT_ALARM); } } diff --git a/src/libultra/gu/sins.c b/src/libultra/gu/sins.c index b05b76b3c2..6dd5f23fcf 100644 --- a/src/libultra/gu/sins.c +++ b/src/libultra/gu/sins.c @@ -1,6 +1,6 @@ #include "math.h" -static s16 sintable[1024] = { +static s16 sintable[0x400] = { 0x0000, 0x0032, 0x0064, 0x0096, 0x00C9, 0x00FB, 0x012D, 0x0160, 0x0192, 0x01C4, 0x01F7, 0x0229, 0x025B, 0x028E, 0x02C0, 0x02F2, 0x0324, 0x0357, 0x0389, 0x03BB, 0x03EE, 0x0420, 0x0452, 0x0484, 0x04B7, 0x04E9, 0x051B, 0x054E, 0x0580, 0x05B2, 0x05E4, 0x0617, 0x0649, 0x067B, 0x06AD, 0x06E0, 0x0712, 0x0744, 0x0776, 0x07A9, 0x07DB, 0x080D, diff --git a/src/libultra/gu/sqrtf.c b/src/libultra/gu/sqrtf.c index b2d27bdb69..5e5fa233cc 100644 --- a/src/libultra/gu/sqrtf.c +++ b/src/libultra/gu/sqrtf.c @@ -6,4 +6,4 @@ f32 sqrtf(f32 f) { return __builtin_sqrtf(f); -} \ No newline at end of file +} diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index 48af72355a..21e376d582 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -2,6 +2,14 @@ UNK_TYPE4 D_80097E40 = 0; +OSPifRam __osContPifRam; +u8 __osContLastCmd; +u8 __osMaxControllers; + +OSTimer __osEepromTimer; +OSMesgQueue D_8009CF38; +OSMesg D_8009CF50[1]; + s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { OSMesg dummy; s32 ret = 0; diff --git a/src/libultra/io/piacs.c b/src/libultra/io/piacs.c index 5a522e244f..8e6f830c0f 100644 --- a/src/libultra/io/piacs.c +++ b/src/libultra/io/piacs.c @@ -2,6 +2,9 @@ UNK_TYPE4 __osPiAccessQueueEnabled = 0; +OSMesg D_8009E3F0[1]; +OSMesgQueue __osPiAccessQueue; + void __osPiCreateAccessQueue(void) { __osPiAccessQueueEnabled = 1; osCreateMesgQueue(&__osPiAccessQueue, D_8009E3F0, 1); @@ -13,9 +16,9 @@ void __osPiGetAccess(void) { if (!__osPiAccessQueueEnabled) { __osPiCreateAccessQueue(); } - osRecvMesg(&__osPiAccessQueue, &dummyMesg, 1); + osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK); } void __osPiRelAccess(void) { - osSendMesg(&__osPiAccessQueue, NULL, 0); + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); } diff --git a/src/libultra/io/pimgr.c b/src/libultra/io/pimgr.c index 78809a5e5d..f5081c050b 100644 --- a/src/libultra/io/pimgr.c +++ b/src/libultra/io/pimgr.c @@ -1,5 +1,12 @@ #include "global.h" +OSPiHandle D_8009D130; +OSPiHandle D_8009D1A8; +OSThread D_8009D220; +u8 piManagerStack[0x1000]; +OSMesgQueue D_8009E3D0; +OSMesg D_8009E3E8[1]; + void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { u32 savedMask; OSPri oldPri; @@ -26,7 +33,7 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC __osPiDevMgr.acsQueue = &__osPiAccessQueue; __osPiDevMgr.piDmaCallback = osPiRawStartDma; __osPiDevMgr.epiDmaCallback = osEPiRawStartDma; - osCreateThread(&D_8009D220, 0, __osDevMgrMain, (void*)&__osPiDevMgr, &piManagerStack[4096], pri); + osCreateThread(&D_8009D220, 0, __osDevMgrMain, &__osPiDevMgr, &piManagerStack[0x1000], pri); osStartThread(&D_8009D220); __osRestoreInt(savedMask); if (oldPri != -1) { diff --git a/src/libultra/io/siacs.c b/src/libultra/io/siacs.c index 8b3b418de9..590f048adf 100644 --- a/src/libultra/io/siacs.c +++ b/src/libultra/io/siacs.c @@ -2,6 +2,9 @@ u32 __osSiAccessQueueEnabled = 0; +OSMesg siAccessBuf[1]; +OSMesgQueue __osSiAccessQueue; + void __osSiCreateAccessQueue() { __osSiAccessQueueEnabled = 1; osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, 1); diff --git a/src/libultra/io/sprawdma.c b/src/libultra/io/sprawdma.c index 9d4203fdf6..01e944c5fb 100644 --- a/src/libultra/io/sprawdma.c +++ b/src/libultra/io/sprawdma.c @@ -1,6 +1,6 @@ #include "global.h" -s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { +s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, u32 size) { if (__osSpDeviceBusy() != 0) { return -1; } diff --git a/src/libultra/io/sptask.c b/src/libultra/io/sptask.c index 256009fe24..84a9624fbd 100644 --- a/src/libultra/io/sptask.c +++ b/src/libultra/io/sptask.c @@ -1,63 +1,53 @@ #include "global.h" -OSTask* _VirtualToPhysicalTask(OSTask* intp) { - OSTask* tp = &tmp_task; - bcopy((void*)intp, (void*)tp, sizeof(OSTask)); - if (tp->t.ucode) { - tp->t.ucode = (u64*)osVirtualToPhysical(tp->t.ucode); - } - if (tp->t.ucode_data) { - tp->t.ucode_data = (u64*)osVirtualToPhysical(tp->t.ucode_data); - } - if (tp->t.dram_stack) { - tp->t.dram_stack = (u64*)osVirtualToPhysical(tp->t.dram_stack); - } - if (tp->t.output_buff) { - tp->t.output_buff = (u64*)osVirtualToPhysical(tp->t.output_buff); - } - if (tp->t.output_buff_size) { - tp->t.output_buff_size = (u64*)osVirtualToPhysical(tp->t.output_buff_size); - } - if (tp->t.data_ptr) { - tp->t.data_ptr = (u64*)osVirtualToPhysical(tp->t.data_ptr); - } - if (tp->t.yield_data_ptr) { - tp->t.yield_data_ptr = (u64*)osVirtualToPhysical(tp->t.yield_data_ptr); +#define _osVirtualToPhysical(ptr) \ + if (ptr != NULL) { \ + ptr = (void*)osVirtualToPhysical(ptr); \ } - return &tmp_task; +static OSTask sTmpTask; + +OSTask* _VirtualToPhysicalTask(OSTask* intp) { + OSTask* tp = &sTmpTask; + + bcopy(intp, tp, sizeof(OSTask)); + + _osVirtualToPhysical(tp->t.ucode); + _osVirtualToPhysical(tp->t.ucode_data); + _osVirtualToPhysical(tp->t.dram_stack); + _osVirtualToPhysical(tp->t.output_buff); + _osVirtualToPhysical(tp->t.output_buff_size); + _osVirtualToPhysical(tp->t.data_ptr); + _osVirtualToPhysical(tp->t.yield_data_ptr); + + return tp; } void osSpTaskLoad(OSTask* intp) { - OSTask* tp; + OSTask* tp = _VirtualToPhysicalTask(intp); - tp = _VirtualToPhysicalTask(intp); - - if ((tp->t.flags & 0x1) != 0) { + if (tp->t.flags & OS_TASK_YIELDED) { tp->t.ucode_data = tp->t.yield_data_ptr; tp->t.ucode_data_size = tp->t.yield_data_size; + intp->t.flags &= ~OS_TASK_YIELDED; - intp->t.flags = intp->t.flags & 0xFFFFFFFE; - - if ((tp->t.flags & 0x4) != 0) { - tp->t.ucode = *(u64**)(((u32)intp->t.yield_data_ptr + 3068) | 0xA0000000); + if (tp->t.flags & OS_TASK_LOADABLE) { + tp->t.ucode = HW_REG((u32)intp->t.yield_data_ptr + OS_YIELD_DATA_SIZE - 4, u32); } } + osWritebackDCache(tp, sizeof(OSTask)); + __osSpSetStatus(SP_CLR_SIG0 | SP_CLR_SIG1 | SP_CLR_SIG2 | SP_SET_INTR_BREAK); - osWritebackDCache((void*)tp, sizeof(OSTask)); - - __osSpSetStatus(11008); - - while (__osSpSetPc(0x04001000) == -1) { + while (__osSpSetPc((void*)SP_IMEM_START) == -1) { ; } - while (__osSpRawStartDma(1, 0x04000FC0, (void*)tp, sizeof(OSTask)) == -1) { + while (__osSpRawStartDma(1, (void*)(SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) { ; } while (__osSpDeviceBusy()) { ; } - while (__osSpRawStartDma(1, 0x04001000, (void*)tp->t.ucode_boot, tp->t.ucode_boot_size) == -1) { + while (__osSpRawStartDma(1, (void*)SP_IMEM_START, tp->t.ucode_boot, tp->t.ucode_boot_size) == -1) { ; } } @@ -66,6 +56,5 @@ void osSpTaskStartGo(OSTask* tp) { while (__osSpDeviceBusy()) { ; } - - __osSpSetStatus(293); + __osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT); } diff --git a/src/libultra/os/initialize.c b/src/libultra/os/initialize.c index 1647401c6e..20564effb4 100644 --- a/src/libultra/os/initialize.c +++ b/src/libultra/os/initialize.c @@ -1,32 +1,35 @@ #include "global.h" -u64 osClockRate = 0x0000000003B9ACA0; -s32 osViClock = 0x02E6D354; +#define COLD_RESET 0 + +typedef struct { + /* 0x0 */ u32 ins_00; // lui k0, 0x8000 + /* 0x4 */ u32 ins_04; // addiu k0, k0, 0x39e0 + /* 0x8 */ u32 ins_08; // jr k0 ; __osException + /* 0xC */ u32 ins_0C; // nop +} struct_exceptionPreamble; + +u64 osClockRate = OS_CLOCK_RATE; +s32 osViClock = VI_NTSC_CLOCK; UNK_TYPE4 __osShutdown = 0; UNK_TYPE4 __OSGlobalIntMask = 0x003FFF01; -#ifdef NON_MATCHING +UNK_TYPE4 D_8009CF70; + void __createSpeedParam(void) { - D_8009D130.type = 7; - D_8009D130.latency = *(u32*)0xA4600014; - D_8009D130.pageSize = *(u32*)0xA4600018; - D_8009D130.relDuration = *(u32*)0xA460001C; - D_8009D130.pulse = *(u32*)0xA4600020; - D_8009D1A8.type = 7; - D_8009D1A8.latency = *(u32*)0xA4600024; - D_8009D1A8.pageSize = *(u32*)0xA4600028; - D_8009D1A8.relDuration = *(u32*)0xA460002C; - D_8009D1A8.pulse = *(u32*)0xA4600030; + D_8009D130.type = DEVICE_TYPE_INIT; + D_8009D130.latency = HW_REG(PI_BSD_DOM1_LAT_REG, u32); + D_8009D130.pulse = HW_REG(PI_BSD_DOM1_PWD_REG, u32); + D_8009D130.pageSize = HW_REG(PI_BSD_DOM1_PGS_REG, u32); + D_8009D130.relDuration = HW_REG(PI_BSD_DOM1_RLS_REG, u32); + + D_8009D1A8.type = DEVICE_TYPE_INIT; + D_8009D1A8.latency = HW_REG(PI_BSD_DOM2_LAT_REG, u32); + D_8009D1A8.pulse = HW_REG(PI_BSD_DOM2_PWD_REG, u32); + D_8009D1A8.pageSize = HW_REG(PI_BSD_DOM2_PGS_REG, u32); + D_8009D1A8.relDuration = HW_REG(PI_BSD_DOM2_RLS_REG, u32); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/boot/initialize/__createSpeedParam.s") -#endif -#ifdef NON_MATCHING -u64 D_80097E50; // this has to be defined in this file for func_8008A6FC to match - -// TODO regalloc is messed up here -// TODO When asm-processor supports -O1, use it here void osInitialize(void) { u32 pifdata; @@ -36,50 +39,48 @@ void osInitialize(void) { __osSetFpcCsr(0x01000800); __osSetWatchLo(0x04900000); - while (__osSiRawReadIo(0x1FC007FC, &pifdata) != 0) { + while (__osSiRawReadIo(0x1FC007FC, &pifdata)) { ; } - while (__osSiRawWriteIo(0x1FC007FC, pifdata | 8) != 0) { + while (__osSiRawWriteIo(0x1FC007FC, pifdata | 8)) { ; } - *(__osExceptionVector*)0x80000000 = *((__osExceptionVector*)__osExceptionPreamble); - *(__osExceptionVector*)0x80000080 = *((__osExceptionVector*)__osExceptionPreamble); - *(__osExceptionVector*)0x80000100 = *((__osExceptionVector*)__osExceptionPreamble); - *(__osExceptionVector*)0x80000180 = *((__osExceptionVector*)__osExceptionPreamble); + *(struct_exceptionPreamble*)0x80000000 = *((struct_exceptionPreamble*)__osExceptionPreamble); + *(struct_exceptionPreamble*)0x80000080 = *((struct_exceptionPreamble*)__osExceptionPreamble); + *(struct_exceptionPreamble*)0x80000100 = *((struct_exceptionPreamble*)__osExceptionPreamble); + *(struct_exceptionPreamble*)0x80000180 = *((struct_exceptionPreamble*)__osExceptionPreamble); - osWritebackDCache((void*)0x80000000, 400); - osInvalICache((void*)0x80000000, 400); + osWritebackDCache(0x80000000, 400); + osInvalICache(0x80000000, 400); __createSpeedParam(); osUnmapTLBAll(); osMapTLBRdb(); - D_80097E50 = (D_80097E50 * 3) / 4; - if (osResetType == 0) { - bzero((u8*)&osAppNmiBuffer, 64); + osClockRate = (u64)((osClockRate * 3ll) / 4ull); + + if (osResetType == COLD_RESET) { + bzero(osAppNmiBuffer, 64); } - if (osTvType == 0) { - osViClock = 0x02F5B2D2; - } else if (osTvType == 2) { - osViClock = 0x02E6025C; + if (osTvType == OS_TV_PAL) { + osViClock = VI_PAL_CLOCK; + } else if (osTvType == OS_TV_MPAL) { + osViClock = VI_MPAL_CLOCK; } else { - osViClock = 0x02E6D354; + osViClock = VI_NTSC_CLOCK; } - if ((__osGetCause() & 0x1000) != 0) { + if (__osGetCause() & 0x1000) { while (1) { ; } } - *(u32*)0xA4500008 = 1; - *(u32*)0xA4500010 = 16383; - *(u32*)0xA4500014 = 15; + HW_REG(AI_CONTROL_REG, u32) = 1; + HW_REG(AI_DACRATE_REG, u32) = 0x3FFF; + HW_REG(AI_BITRATE_REG, u32) = 0xF; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/boot/initialize/osInitialize.s") -#endif void __osInitialize_autodetect(void) { } diff --git a/src/libultra/os/seteventmesg.c b/src/libultra/os/seteventmesg.c index 62a12f68f3..723d1dafc6 100644 --- a/src/libultra/os/seteventmesg.c +++ b/src/libultra/os/seteventmesg.c @@ -2,6 +2,8 @@ UNK_TYPE4 D_80097F10 = 0; +__OSEventState __osEventStateTab[16]; + void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg m) { register u32 saveMask; __OSEventState* es; diff --git a/src/libultra/os/threadsave.c b/src/libultra/os/threadsave.c new file mode 100644 index 0000000000..bcf79be8d6 --- /dev/null +++ b/src/libultra/os/threadsave.c @@ -0,0 +1,3 @@ +#include "global.h" + +OSThread __osThreadSave; diff --git a/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c b/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c index e254084de8..c07c78398e 100644 --- a/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c +++ b/src/overlays/actors/ovl_En_Daiku/z_en_daiku.c @@ -308,9 +308,7 @@ s32 func_80943E18(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* p } void func_80943E60(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s* rot, Actor* thisx) { - static Gfx* D_809440D4[] = { - D_060070C0, D_06006FB0, D_06006E80, D_06006D70, - }; + static Gfx* D_809440D4[] = { D_060070C0, D_06006FB0, D_06006E80, D_06006D70 }; EnDaiku* this = THIS; OPEN_DISPS(globalCtx->state.gfxCtx); diff --git a/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c b/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c index 9257f02053..6aab7a2cdb 100644 --- a/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c +++ b/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c @@ -1,7 +1,7 @@ /* * File: z_en_dnb.c * Overlay: ovl_En_Dnb - * Description: + * Description: */ #include "z_en_dnb.h" diff --git a/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c b/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c index 9badebfe16..4d07c983a1 100644 --- a/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c +++ b/src/overlays/actors/ovl_En_Ma4/z_en_ma4.c @@ -623,8 +623,7 @@ void EnMa4_ChooseNextDialogue(EnMa4* this, GlobalContext* globalCtx) { break; case 0x3358: - if ((gSaveContext.playerForm != PLAYER_FORM_HUMAN) || - !(CHECK_QUEST_ITEM(14))) { + if ((gSaveContext.playerForm != PLAYER_FORM_HUMAN) || !(CHECK_QUEST_ITEM(14))) { func_801518B0(globalCtx, 0x335C, &this->actor); this->textId = 0x335C; func_80151BB4(globalCtx, 5); @@ -663,8 +662,7 @@ void EnMa4_DialogueHandler(EnMa4* this, GlobalContext* globalCtx) { case 6: // End conversation if (func_80147624(globalCtx) != 0) { - if ((globalCtx->msgCtx.unk120B1 == 0) || - !CHECK_QUEST_ITEM(18)) { + if ((globalCtx->msgCtx.unk120B1 == 0) || !CHECK_QUEST_ITEM(18)) { EnMa4_SetupWait(this); } } diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index c6d05fd788..c67e0b7a7c 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -323,9 +323,12 @@ 0x8009CDB0 : "rumblepak", 0x8009CEB0 : "siacs", 0x8009CED0 : "controller", + 0x8009CF60 : "voicegetreaddata", + 0x8009CF70 : "initialize", 0x8009CF80 : "threadsave", - 0x8009D130 : "initialize", - 0x8009D220 : "pimgr", + 0x8009D130 : "pimgr", + 0x8009E3F0 : "piacs", + 0x8009E410 : "contpfs", 0x8009E510 : "seteventmesg", 0x8009E590 : "timerintr", 0x8009E610 : "cartrominit", diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index a9d2c0d4d6..4b2db1d179 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -302,7 +302,6 @@ 0x8009B2D8:("sDmaMgrMsgs","OSMesg","[32]",0x80), 0x8009B358:("sDmaMgrThread","OSThread","",0x1b0), 0x8009B508:("sDmaMgrStack","u8","[1280]",0x500), - 0x8009BA08:("D_8009BA08","UNK_TYPE1","",0x1), 0x8009BA10:("sYaz0DataBuffer","u8","[1024]",0x400), 0x8009BE10:("sYaz0CurDataEnd","u8*","",0x4), 0x8009BE14:("sYaz0CurRomStart","u32","",0x4), @@ -332,8 +331,9 @@ 0x8009CF0C:("D_8009CF0C","UNK_TYPE1","",0x1), 0x8009CF10:("__osContLastCmd","u8","",0x1), 0x8009CF11:("__osMaxControllers","u8","",0x1), + 0x8009CF18:("__osEepromTimer","OSTimer","",0x20), 0x8009CF38:("D_8009CF38","OSMesgQueue","",0x18), - 0x8009CF50:("D_8009CF50","OSMesg","[1]",0x4), + 0x8009CF50:("D_8009CF50","OSMesg","",0x4), 0x8009CF60:("D_8009CF60","UNK_TYPE1","",0x1), 0x8009CF70:("D_8009CF70","UNK_TYPE4","",0x4), 0x8009CF80:("__osThreadSave","OSThread","",0x1b0), @@ -345,7 +345,7 @@ 0x8009E3E8:("D_8009E3E8","OSMesg","[1]",0x4), 0x8009E3F0:("D_8009E3F0","OSMesg","[1]",0x4), 0x8009E3F8:("__osPiAccessQueue","OSMesgQueue","",0x18), - 0x8009E410:("D_8009E410","UNK_TYPE1","",0x1), + 0x8009E410:("__osPfsInodeCache","_OSInode","",0x100), 0x8009E510:("__osEventStateTab","__OSEventState","[16]",0x80), 0x8009E590:("D_8009E590","OSTimer","",0x20), 0x8009E5B0:("__osCurrentTime","OSTime","",0x8),