1
0
mirror of https://github.com/blawar/ooot.git synced 2024-07-04 18:13:37 +00:00

Preliminary fixes for boot/libultra (#1032)

* Preliminary fixes

* Missed a NULL
This commit is contained in:
Tharo 2021-11-28 12:50:35 +00:00 committed by GitHub
parent 09f0dc84b8
commit 982e7be1f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 68 additions and 88 deletions

View File

@ -7,21 +7,23 @@
.section .text
.set BOOT_STACK_SIZE, 0x400
glabel entrypoint # 0x80000400
lui $t0, %hi(_bootSegmentBssStart) # $t0, 0x8001
addiu $t0, %lo(_bootSegmentBssStart) # addiu $t0, $t0, 0x2370
li $t1, %lo(_bootSegmentBssSize) # li $t1, 0x4A30
lui $t0, %hi(_bootSegmentBssStart)
addiu $t0, %lo(_bootSegmentBssStart)
li $t1, %lo(_bootSegmentBssSize)
.L8000040C:
addi $t1, $t1, -8
sw $zero, ($t0)
sw $zero, 4($t0)
bnez $t1, .L8000040C
addi $t0, $t0, 8
lui $t2, %hi(bootproc) # $t2, 0x8000
lui $sp, %hi(gMainThread) # $sp, 0x8001
addiu $t2, %lo(bootproc) # addiu $t2, $t2, 0x0498
lui $t2, %hi(bootproc)
lui $sp, %hi(sBootThreadStack + BOOT_STACK_SIZE)
addiu $t2, %lo(bootproc)
jr $t2
addiu $sp, %lo(gMainThread) # addiu $sp, $sp, 0x2D60
addiu $sp, %lo(sBootThreadStack + BOOT_STACK_SIZE)
nop
nop
nop

View File

@ -49,13 +49,13 @@ glabel osInvalDCache
/* 006E84 80006284 00000000 */ nop
.L80006288:
/* 006E88 80006288 3C088000 */ lui $t0, %hi(D_80000010) # $t0, 0x8000
/* 006E88 80006288 3C088000 */ lui $t0, 0x8000
/* 006E8C 8000628C 010B4821 */ addu $t1, $t0, $t3
/* 006E90 80006290 2529FFF0 */ addiu $t1, $t1, -0x10
.L80006294:
/* 006E94 80006294 BD010000 */ cache 1, ($t0)
/* 006E98 80006298 0109082B */ sltu $at, $t0, $t1
/* 006E9C 8000629C 1420FFFD */ bnez $at, .L80006294
/* 006EA0 800062A0 25080010 */ addiu $t0, %lo(D_80000010) # addiu $t0, $t0, 0x10
/* 006EA0 800062A0 25080010 */ addiu $t0, 0x10
/* 006EA4 800062A4 03E00008 */ jr $ra
/* 006EA8 800062A8 00000000 */ nop

View File

@ -34,13 +34,13 @@ glabel osInvalICache
/* 006D9C 8000619C 00000000 */ nop
.L800061A0:
/* 006DA0 800061A0 3C088000 */ lui $t0, %hi(D_80000020) # $t0, 0x8000
/* 006DA0 800061A0 3C088000 */ lui $t0, 0x8000
/* 006DA4 800061A4 010B4821 */ addu $t1, $t0, $t3
/* 006DA8 800061A8 2529FFE0 */ addiu $t1, $t1, -0x20
.L800061AC:
/* 006DAC 800061AC BD000000 */ cache 0, ($t0)
/* 006DB0 800061B0 0109082B */ sltu $at, $t0, $t1
/* 006DB4 800061B4 1420FFFD */ bnez $at, .L800061AC
/* 006DB8 800061B8 25080020 */ addiu $t0, %lo(D_80000020) # addiu $t0, $t0, 0x20
/* 006DB8 800061B8 25080020 */ addiu $t0, 0x20
/* 006DBC 800061BC 03E00008 */ jr $ra
/* 006DC0 800061C0 00000000 */ nop

View File

@ -34,13 +34,13 @@ glabel osWritebackDCache
/* 00530C 8000470C 00000000 */ nop
.L80004710:
/* 005310 80004710 3C088000 */ lui $t0, %hi(D_80000010) # $t0, 0x8000
/* 005310 80004710 3C088000 */ lui $t0, 0x8000
/* 005314 80004714 010B4821 */ addu $t1, $t0, $t3
/* 005318 80004718 2529FFF0 */ addiu $t1, $t1, -0x10
.L8000471C:
/* 00531C 8000471C BD010000 */ cache 1, ($t0)
/* 005320 80004720 0109082B */ sltu $at, $t0, $t1
/* 005324 80004724 1420FFFD */ bnez $at, .L8000471C
/* 005328 80004728 25080010 */ addiu $t0, %lo(D_80000010) # addiu $t0, $t0, 0x10
/* 005328 80004728 25080010 */ addiu $t0, 0x10
/* 00532C 8000472C 03E00008 */ jr $ra
/* 005330 80004730 00000000 */ nop

View File

@ -10,7 +10,7 @@
.balign 16
glabel osWritebackDCacheAll
/* B7D630 80106490 3C088000 */ lui $t0, %hi(D_80000010) # $t0, 0x8000
/* B7D630 80106490 3C088000 */ lui $t0, 0x8000
/* B7D634 80106494 240A2000 */ li $t2, 8192
/* B7D638 80106498 010A4821 */ addu $t1, $t0, $t2
/* B7D63C 8010649C 2529FFF0 */ addiu $t1, $t1, -0x10
@ -18,6 +18,6 @@ glabel osWritebackDCacheAll
/* B7D640 801064A0 BD010000 */ cache 1, ($t0)
/* B7D644 801064A4 0109082B */ sltu $at, $t0, $t1
/* B7D648 801064A8 1420FFFD */ bnez $at, .L801064A0
/* B7D64C 801064AC 25080010 */ addiu $t0, %lo(D_80000010) # addiu $t0, $t0, 0x10
/* B7D64C 801064AC 25080010 */ addiu $t0, 0x10
/* B7D650 801064B0 03E00008 */ jr $ra
/* B7D654 801064B4 00000000 */ nop

View File

@ -160,8 +160,8 @@ OSViContext* __osViGetCurrentContext(void);
void osStartThread(OSThread* thread);
void osViSetYScale(f32 scale);
void osViSetXScale(f32 value);
void __osSetHWIntrRoutine(s32 idx, OSMesgQueue* queue, OSMesg msg);
void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg);
void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* sp);
void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handlerOut)(void), void** spOut);
void __osSetWatchLo(u32);
EnItem00* Item_DropCollectible(GlobalContext* globalCtx, Vec3f* spawnPos, s16 params);

View File

@ -64,7 +64,7 @@
#define PI_STATUS_BUSY 0x1
#define PI_STATUS_IOBUSY 0x2
#define PI_STATUS_ERROR 0x3
#define PI_STATUS_ERROR 0x4
#define PI_STATUS_RESET_CONTROLLER 0x1
#define PI_STATUS_CLEAR_INTR 0x2

View File

@ -12,8 +12,8 @@ typedef struct {
} OSMgrArgs; // size = 0x1C
typedef struct {
/* 0x00 */ OSMesgQueue* queue;
/* 0x04 */ OSMesg msg;
/* 0x00 */ s32 (*handler)(void);
/* 0x04 */ void* sp;
} __osHwInt; // size = 0x08
typedef struct {

View File

@ -2,5 +2,6 @@
#define ULTRA64_INTERRUPT_H
typedef u32 OSIntMask;
typedef u32 OSHWIntr;
#endif

View File

@ -44,16 +44,16 @@ typedef struct {
} __OSThreadprofile; // size = 0x10
typedef struct OSThread {
/*0x00*/ struct OSThread* next;
/*0x04*/ OSPri priority;
/*0x08*/ struct OSThread** queue;
/*0x0C*/ struct OSThread* tlnext;
/*0x10*/ u16 state;
/*0x12*/ u16 flags;
/*0x14*/ OSId id;
/*0x18*/ s32 fp;
/*0x1C*/ __OSThreadprofile* thprof;
/*0x20*/ __OSThreadContext context;
/* 0x00 */ struct OSThread* next;
/* 0x04 */ OSPri priority;
/* 0x08 */ struct OSThread** queue;
/* 0x0C */ struct OSThread* tlnext;
/* 0x10 */ u16 state;
/* 0x12 */ u16 flags;
/* 0x14 */ OSId id;
/* 0x18 */ s32 fp;
/* 0x1C */ __OSThreadprofile* thprof;
/* 0x20 */ __OSThreadContext context;
} OSThread; // size = 0x1B0
#endif

View File

@ -14,17 +14,11 @@ extern Gfx D_060257B8[];
extern Gfx D_0602A738[];
extern Gfx D_0602CB48[];
//extern ? D_80000004;
//extern ? D_80000008;
//extern ? D_8000000C;
//extern ? D_80000010;
//extern ? D_80000020;
extern u32 osTvType;
extern u32 osRomBase;
extern u32 osResetType;
extern u32 osMemSize;
extern u8 osAppNmiBuffer[];
extern u8 osAppNmiBuffer[0x40];
extern u8 D_80009320[];
extern u8 D_800093F0[];

View File

@ -1,7 +1,7 @@
#include "global.h"
#include "ultra64/internal.h"
void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg) {
*outQueue = __osHwIntTable[idx].queue;
*outMsg = __osHwIntTable[idx].msg;
void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handlerOut)(void), void** spOut) {
*handlerOut = __osHwIntTable[interrupt].handler;
*spOut = __osHwIntTable[interrupt].sp;
}

View File

@ -1,7 +1,7 @@
#include "global.h"
void __osResetGlobalIntMask(u32 mask) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();
__OSGlobalIntMask &= ~(mask & ~0x401);
__osRestoreInt(prevInt);

View File

@ -1,7 +1,7 @@
#include "global.h"
void __osSetGlobalIntMask(u32 mask) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();
__OSGlobalIntMask |= mask;
__osRestoreInt(prevInt);

View File

@ -1,11 +1,11 @@
#include "global.h"
#include "ultra64/internal.h"
void __osSetHWIntrRoutine(s32 idx, OSMesgQueue* queue, OSMesg msg) {
register s32 prevInt = __osDisableInt();
void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* sp) {
register u32 prevInt = __osDisableInt();
__osHwIntTable[idx].queue = queue;
__osHwIntTable[idx].msg = msg;
__osHwIntTable[interrupt].handler = handler;
__osHwIntTable[interrupt].sp = sp;
__osRestoreInt(prevInt);
}

View File

@ -58,7 +58,7 @@ void __osInitialize_common(void) {
osClockRate = (u64)((osClockRate * 3ll) / 4ull);
if (!osResetType) {
bzero(osAppNmiBuffer, 0x40);
bzero(osAppNmiBuffer, sizeof(osAppNmiBuffer));
}
if (osTvType == OS_TV_PAL) {

View File

@ -1,7 +1,7 @@
#include "global.h"
void osDestroyThread(OSThread* thread) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();
register OSThread* s1;
register OSThread* s2;

View File

@ -1,7 +1,7 @@
#include "global.h"
s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();
while (mq->validCount >= mq->msgCount) {
if (flag == OS_MESG_BLOCK) {

View File

@ -1,7 +1,7 @@
#include "global.h"
s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();
while (mq->validCount == 0) {
if (flag == OS_MESG_NOBLOCK) {

View File

@ -4,7 +4,7 @@ s32 __osEPiRawReadIo(OSPiHandle* handle, u32 devAddr, u32* data) {
s32 status;
OSPiHandle* curHandle;
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY | PI_STATUS_ERROR)) {
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) {
;
}

View File

@ -4,7 +4,7 @@ s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, u32 cartAddr, void* dr
s32 status;
OSPiHandle* curHandle;
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY | PI_STATUS_ERROR)) {
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) {
;
}

View File

@ -4,7 +4,7 @@ s32 __osEPiRawWriteIo(OSPiHandle* handle, u32 devAddr, u32 data) {
s32 status;
OSPiHandle* curHandle;
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY | PI_STATUS_ERROR)) {
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) {
;
}

View File

@ -3,7 +3,7 @@
s32 __osPiRawStartDma(s32 dir, u32 cartAddr, void* dramAddr, size_t size) {
register s32 status = HW_REG(PI_STATUS_REG, u32);
while (status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY | PI_STATUS_ERROR)) {
while (status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) {
status = HW_REG(PI_STATUS_REG, u32);
}

View File

@ -27,7 +27,7 @@ OSPiHandle* osCartRomInit(void) {
__CartRomHandle.speed = 0;
bzero(&__CartRomHandle.transferInfo, sizeof(__OSTranxInfo));
while (status = HW_REG(PI_STATUS_REG, u32), status & PI_STATUS_ERROR) {
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) {
;
}

View File

@ -5,7 +5,7 @@ OSPiHandle __DriveRomHandle;
OSPiHandle* osDriveRomInit(void) {
register s32 status;
register u32 a;
register s32 prevInt;
register u32 prevInt;
static u32 D_8000AC70 = 1;
__osPiGetAccess();
@ -22,7 +22,7 @@ OSPiHandle* osDriveRomInit(void) {
__DriveRomHandle.speed = 0;
bzero(&__DriveRomHandle.transferInfo, sizeof(__OSTranxInfo));
while (status = HW_REG(PI_STATUS_REG, u32), status & PI_STATUS_ERROR) {
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY)) {
;
}

View File

@ -1,7 +1,7 @@
#include "global.h"
void* osViGetNextFramebuffer(void) {
s32 prevInt = __osDisableInt();
u32 prevInt = __osDisableInt();
void* buff = __osViNext->buffer;
__osRestoreInt(prevInt);

View File

@ -1,7 +1,7 @@
#include "global.h"
void osViSetYScale(f32 scale) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();
__osViNext->y.factor = scale;
__osViNext->state |= 4;

View File

@ -1,21 +1,12 @@
#include "global.h"
#include "ultra64/internal.h"
typedef struct {
u16 unk00;
u8 unk02;
u32 unk04;
u8 pad[0xC];
u16 unk14;
u16 unk16;
} viMesgStruct;
OSThread viThread;
u8 viThreadStack[0x1000];
OSMesgQueue viEventQueue;
OSMesg viEventBuf[6];
viMesgStruct viRetraceMsg;
viMesgStruct viCounterMsg;
OSIoMesg viRetraceMsg;
OSIoMesg viCounterMsg;
OSMgrArgs __osViDevMgr = { 0 };
u32 __additional_scanline = 0;
@ -30,12 +21,12 @@ void osCreateViManager(OSPri pri) {
__osTimerServicesInit();
__additional_scanline = 0;
osCreateMesgQueue(&viEventQueue, viEventBuf, 5);
viRetraceMsg.unk00 = 13;
viRetraceMsg.unk02 = 0;
viRetraceMsg.unk04 = 0;
viCounterMsg.unk00 = 14;
viCounterMsg.unk02 = 0;
viCounterMsg.unk04 = 0;
viRetraceMsg.hdr.type = 13;
viRetraceMsg.hdr.pri = 0;
viRetraceMsg.hdr.retQueue = NULL;
viCounterMsg.hdr.type = 14;
viCounterMsg.hdr.pri = 0;
viCounterMsg.hdr.retQueue = NULL;
osSetEventMesg(OS_EVENT_VI, &viEventQueue, &viRetraceMsg);
osSetEventMesg(OS_EVENT_COUNTER, &viEventQueue, &viCounterMsg);
newPri = -1;
@ -68,10 +59,9 @@ void viMgrMain(void* vargs) {
OSMgrArgs* args;
static u16 viRetrace;
u32 addTime;
viMesgStruct* mesg;
OSIoMesg* mesg = NULL;
u32 temp = 0; // always 0
mesg = NULL;
viRetrace = __osViGetCurrentContext()->retraceCount;
if (viRetrace == 0) {
viRetrace = 1;
@ -81,7 +71,7 @@ void viMgrMain(void* vargs) {
while (true) {
osRecvMesg(args->eventQueue, (OSMesg)&mesg, OS_MESG_BLOCK);
switch (mesg->unk00) {
switch (mesg->hdr.type) {
case 13:
__osViSwapContext();
viRetrace--;

View File

@ -5,7 +5,7 @@ s32 osSetTimer(OSTimer* timer, OSTime countdown, OSTime interval, OSMesgQueue* m
OSTimer* next;
u32 count;
u32 value;
s32 prevInt;
u32 prevInt;
timer->next = NULL;
timer->prev = NULL;

View File

@ -1,7 +1,7 @@
#include "global.h"
s32 osStopTimer(OSTimer* timer) {
register s32 prevInt;
register u32 prevInt;
OSTimer* next;
if (!timer->next) {

View File

@ -1,11 +1,4 @@
// libultra OS symbols
D_80000000 = 0x80000000;
D_80000002 = 0x80000002;
D_80000004 = 0x80000004;
D_80000008 = 0x80000008;
D_8000000C = 0x8000000C;
D_80000010 = 0x80000010;
D_80000020 = 0x80000020;
osTvType = 0x80000300;
osRomBase = 0x80000308;
osResetType = 0x8000030C;