Skip to content

Commit

Permalink
Preliminary fixes for boot/libultra (zeldaret#1032)
Browse files Browse the repository at this point in the history
* Preliminary fixes

* Missed a NULL
  • Loading branch information
Thar0 committed Nov 28, 2021
1 parent 09f0dc8 commit 982e7be
Show file tree
Hide file tree
Showing 31 changed files with 68 additions and 88 deletions.
16 changes: 9 additions & 7 deletions asm/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions asm/osInvalDCache.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions asm/osInvalICache.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions asm/osWritebackDCache.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions asm/osWritebackDCacheAll.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
.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
.L801064A0:
/* 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
4 changes: 2 additions & 2 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/ultra64/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/ultra64/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions include/ultra64/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define ULTRA64_INTERRUPT_H

typedef u32 OSIntMask;
typedef u32 OSHWIntr;

#endif
20 changes: 10 additions & 10 deletions include/ultra64/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 1 addition & 7 deletions include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
6 changes: 3 additions & 3 deletions src/libultra_boot_O1/__osGetHWIntrRoutine.c
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/libultra_boot_O1/__osResetGlobalIntMask.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "global.h"

void __osResetGlobalIntMask(u32 mask) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();

__OSGlobalIntMask &= ~(mask & ~0x401);
__osRestoreInt(prevInt);
Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O1/__osSetGlobalIntMask.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "global.h"

void __osSetGlobalIntMask(u32 mask) {
register s32 prevInt = __osDisableInt();
register u32 prevInt = __osDisableInt();

__OSGlobalIntMask |= mask;
__osRestoreInt(prevInt);
Expand Down
8 changes: 4 additions & 4 deletions src/libultra_boot_O1/__osSetHWIntrRoutine.c
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion src/libultra_boot_O1/initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O1/osDestroyThread.c
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O1/osJamMesg.c
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O1/osRecvMesg.c
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O2/__osEPiRawReadIo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O2/__osEPiRawStartDma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O2/__osEPiRawWriteIo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O2/__osPiRawStartDma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O2/osCartRomInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libultra_boot_O2/osDriveRomInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)) {
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O2/osViGetNextFramebuffer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "global.h"

void* osViGetNextFramebuffer(void) {
s32 prevInt = __osDisableInt();
u32 prevInt = __osDisableInt();
void* buff = __osViNext->buffer;

__osRestoreInt(prevInt);
Expand Down
2 changes: 1 addition & 1 deletion src/libultra_boot_O2/osViSetYScale.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit 982e7be

Please sign in to comment.