Post r15: Libultra cleanup and labelling

This commit is contained in:
AloXado320 2021-11-30 19:00:40 -05:00
parent 8290a28428
commit 0de02a2757
28 changed files with 129 additions and 131 deletions

View file

@ -7,7 +7,7 @@
.section .text, "ax" .section .text, "ax"
#ifdef AVOID_UB #ifdef AVOID_UB
.set D_80334890, D_80334890_fix .set __osThreadTail, __osThreadTail_fix
#endif #endif
glabel __osExceptionPreamble glabel __osExceptionPreamble
@ -60,8 +60,8 @@ glabel __osException
#if !defined(VERSION_EU) && !defined(VERSION_SH) #if !defined(VERSION_EU) && !defined(VERSION_SH)
sw $zero, %lo(D_80334938)($at) sw $zero, %lo(D_80334938)($at)
#endif #endif
lui $k0, %hi(D_80334890 + 0x10) lui $k0, %hi(__osThreadTail + 0x10)
lw $k0, %lo(D_80334890 + 0x10)($k0) lw $k0, %lo(__osThreadTail + 0x10)($k0)
ld $t1, 0x20($t0) ld $t1, 0x20($t0)
sd $t1, 0x20($k0) sd $t1, 0x20($k0)
ld $t1, 0x118($t0) ld $t1, 0x118($t0)
@ -433,8 +433,8 @@ glabel L80326AE8
sw $t2, ($t1) sw $t2, ($t1)
jal send_mesg jal send_mesg
li $a0, 112 li $a0, 112
lui $t2, %hi(D_80334890 + 0x8) lui $t2, %hi(__osThreadTail + 0x8)
lw $t2, %lo(D_80334890 + 0x8)($t2) lw $t2, %lo(__osThreadTail + 0x8)($t2)
li $at, -4097 li $at, -4097
and $s0, $s0, $at and $s0, $s0, $at
lw $k1, 0x118($t2) lw $k1, 0x118($t2)
@ -469,23 +469,23 @@ glabel L80326B64
.L80326B9C: .L80326B9C:
glabel L80326B9C glabel L80326B9C
lui $t2, %hi(D_80334890 + 0x8) lui $t2, %hi(__osThreadTail + 0x8)
lw $t2, %lo(D_80334890 + 0x8)($t2) lw $t2, %lo(__osThreadTail + 0x8)($t2)
lw $t1, 4($k0) lw $t1, 4($k0)
lw $t3, 4($t2) lw $t3, 4($t2)
slt $at, $t1, $t3 slt $at, $t1, $t3
beqz $at, .L80326BD0 beqz $at, .L80326BD0
nop nop
lui $a0, %hi(D_80334890 + 0x8) lui $a0, %hi(__osThreadTail + 0x8)
move $a1, $k0 move $a1, $k0
jal __osEnqueueThread jal __osEnqueueThread
addiu $a0, %lo(D_80334890 + 0x8) addiu $a0, %lo(__osThreadTail + 0x8)
j __osDispatchThread j __osDispatchThread
nop nop
.L80326BD0: .L80326BD0:
lui $t1, %hi(D_80334890 + 0x8) lui $t1, %hi(__osThreadTail + 0x8)
addiu $t1, %lo(D_80334890 + 0x8) addiu $t1, %lo(__osThreadTail + 0x8)
lw $t2, ($t1) lw $t2, ($t1)
sw $t2, ($k0) sw $t2, ($k0)
j __osDispatchThread j __osDispatchThread
@ -493,8 +493,8 @@ glabel L80326B9C
.L80326BE8: .L80326BE8:
glabel L80326BE8 glabel L80326BE8
lui $at, %hi(D_80334890 + 0x14) lui $at, %hi(__osThreadTail + 0x14)
sw $k0, %lo(D_80334890 + 0x14)($at) sw $k0, %lo(__osThreadTail + 0x14)($at)
li $t1, 1 li $t1, 1
sh $t1, 0x10($k0) sh $t1, 0x10($k0)
li $t1, 2 li $t1, 2
@ -548,10 +548,10 @@ glabel send_mesg
jal __osPopThread jal __osPopThread
move $a0, $t1 move $a0, $t1
move $t2, $v0 move $t2, $v0
lui $a0, %hi(D_80334890 + 0x8) lui $a0, %hi(__osThreadTail + 0x8)
move $a1, $t2 move $a1, $t2
jal __osEnqueueThread jal __osEnqueueThread
addiu $a0, %lo(D_80334890 + 0x8) addiu $a0, %lo(__osThreadTail + 0x8)
.L80326CC4: .L80326CC4:
jr $s2 jr $s2
nop nop
@ -572,8 +572,8 @@ glabel send_mesg
glabel __osEnqueueAndYield glabel __osEnqueueAndYield
lui $a1, %hi(D_80334890 + 0x10) lui $a1, %hi(__osThreadTail + 0x10)
lw $a1, %lo(D_80334890 + 0x10)($a1) lw $a1, %lo(__osThreadTail + 0x10)($a1)
mfc0 $t0, $12 mfc0 $t0, $12
lw $k1, 0x18($a1) lw $k1, 0x18($a1)
ori $t0, $t0, 2 ori $t0, $t0, 2
@ -676,11 +676,11 @@ glabel __osPopThread
sw $t9, ($a0) sw $t9, ($a0)
glabel __osDispatchThread glabel __osDispatchThread
lui $a0, %hi(D_80334890 + 0x8) lui $a0, %hi(__osThreadTail + 0x8)
jal __osPopThread jal __osPopThread
addiu $a0, %lo(D_80334890 + 0x8) addiu $a0, %lo(__osThreadTail + 0x8)
lui $at, %hi(D_80334890 + 0x10) lui $at, %hi(__osThreadTail + 0x10)
sw $v0, %lo(D_80334890 + 0x10)($at) sw $v0, %lo(__osThreadTail + 0x10)($at)
li $t0, 4 li $t0, 4
sh $t0, 0x10($v0) sh $t0, 0x10($v0)
move $k0, $v0 move $k0, $v0

View file

@ -28,8 +28,8 @@
const char length_str[] = "hlL"; const char length_str[] = "hlL";
const char flags_str[] = " +-#0"; const char flags_str[] = " +-#0";
const u32 flags_arr[] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0 }; const u32 flags_arr[] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0 };
char _spaces[] = " "; char spaces[] = " ";
char _zeroes[] = "00000000000000000000000000000000"; char zeroes[] = "00000000000000000000000000000000";
static void _Putfld(printf_struct *, va_list *, u8, u8 *); static void _Putfld(printf_struct *, va_list *, u8, u8 *);
@ -99,14 +99,14 @@ s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char
_Putfld(&sp78, &args, *fmt_ptr, sp4c); _Putfld(&sp78, &args, *fmt_ptr, sp4c);
sp78.width -= sp78.part1_len + sp78.num_leading_zeros + sp78.part2_len + sp78.num_mid_zeros sp78.width -= sp78.part1_len + sp78.num_leading_zeros + sp78.part2_len + sp78.num_mid_zeros
+ sp78.part3_len + sp78.num_trailing_zeros; + sp78.part3_len + sp78.num_trailing_zeros;
_PAD(sp44, sp78.width, sp48, _spaces, !(sp78.flags & FLAGS_MINUS)); _PAD(sp44, sp78.width, sp48, spaces, !(sp78.flags & FLAGS_MINUS));
_PROUT(dst, (char *) sp4c, sp78.part1_len); _PROUT(dst, (char *) sp4c, sp78.part1_len);
_PAD(sp3c, sp78.num_leading_zeros, sp40, _zeroes, 1); _PAD(sp3c, sp78.num_leading_zeros, sp40, zeroes, 1);
_PROUT(dst, sp78.buff, sp78.part2_len); _PROUT(dst, sp78.buff, sp78.part2_len);
_PAD(sp34, sp78.num_mid_zeros, sp38, _zeroes, 1); _PAD(sp34, sp78.num_mid_zeros, sp38, zeroes, 1);
_PROUT(dst, (char *) (&sp78.buff[sp78.part2_len]), sp78.part3_len) _PROUT(dst, (char *) (&sp78.buff[sp78.part2_len]), sp78.part3_len)
_PAD(sp2c, sp78.num_trailing_zeros, sp30, _zeroes, 1); _PAD(sp2c, sp78.num_trailing_zeros, sp30, zeroes, 1);
_PAD(sp24, sp78.width, sp28, _spaces, sp78.flags & FLAGS_MINUS); _PAD(sp24, sp78.width, sp28, spaces, sp78.flags & FLAGS_MINUS);
fmt = (char *) fmt_ptr + 1; fmt = (char *) fmt_ptr + 1;
} }
} }

View file

@ -3,14 +3,14 @@
// these don't feel like they belong here // these don't feel like they belong here
// but it makes the most logical since there was printf data before // but it makes the most logical since there was printf data before
#ifndef AVOID_UB #ifndef AVOID_UB
OSThread *D_80334890 = NULL; OSThread *__osThreadTail = NULL;
u32 D_80334894 = -1; u32 D_80334894 = -1;
OSThread *D_80334898 = (OSThread *) &D_80334890; OSThread *__osRunQueue = (OSThread *) &__osThreadTail;
OSThread *D_8033489C = (OSThread *) &D_80334890; OSThread *__osActiveQueue = (OSThread *) &__osThreadTail;
OSThread *D_803348A0 = NULL; OSThread *__osRunningThread = { 0 };
u32 D_803348A4 = 0; // UNKNOWN OSThread *__osFaultedThread = { 0 };
#else #else
OSThread_ListHead D_80334890_fix = {NULL, -1, (OSThread *) &D_80334890_fix, (OSThread *) &D_80334890_fix, NULL, 0}; OSThread_ListHead __osThreadTail_fix = {NULL, -1, (OSThread *) &__osThreadTail_fix, (OSThread *) &__osThreadTail_fix, NULL, 0};
#endif #endif
void __osDequeueThread(OSThread **queue, OSThread *thread) { void __osDequeueThread(OSThread **queue, OSThread *thread) {

View file

@ -1,5 +1,5 @@
#include "libultra_internal.h" #include "libultra_internal.h"
OSThread *__osGetCurrFaultedThread() { OSThread *__osGetCurrFaultedThread() {
return D_8033489C; // 80302efc return __osActiveQueue;
} }

View file

@ -12,10 +12,10 @@ u32 sTvType = TV_TYPE_NTSC;
u32 osViClock = 0x02E6D354; u32 osViClock = 0x02E6D354;
#endif #endif
extern OSViMode D_80334990; extern OSViMode osViModePalLan1;
extern OSViMode D_803349E0; extern OSViMode osViModeMpalLan1;
#if defined(VERSION_EU) || defined(VERSION_SH) #if defined(VERSION_EU) || defined(VERSION_SH)
extern OSViMode D_80302FD0; extern OSViMode osViModeNtscLan1;
#endif #endif
void __osViInit(void) { void __osViInit(void) {
@ -32,13 +32,13 @@ void __osViInit(void) {
#if defined(VERSION_EU) #if defined(VERSION_EU)
if (osTvType == TV_TYPE_PAL) { if (osTvType == TV_TYPE_PAL) {
__osViNext->modep = &D_80334990; __osViNext->modep = &osViModePalLan1;
osViClock = 0x02F5B2D2; osViClock = 0x02F5B2D2;
} else if (osTvType == TV_TYPE_MPAL) { } else if (osTvType == TV_TYPE_MPAL) {
__osViNext->modep = &D_803349E0; __osViNext->modep = &osViModeMpalLan1;
osViClock = 0x02E6025C; osViClock = 0x02E6025C;
} else { } else {
__osViNext->modep = &D_80302FD0; __osViNext->modep = &osViModeNtscLan1;
osViClock = 0x02E6D354; osViClock = 0x02E6D354;
} }
@ -47,11 +47,11 @@ void __osViInit(void) {
__osViNext->buffer = (void *) 0x80000000; __osViNext->buffer = (void *) 0x80000000;
__osViCurr->buffer = (void *) 0x80000000; __osViCurr->buffer = (void *) 0x80000000;
if (osTvType == TV_TYPE_PAL) { if (osTvType == TV_TYPE_PAL) {
__osViNext->modep = &D_80334990; __osViNext->modep = &osViModePalLan1;
} else if (osTvType == TV_TYPE_MPAL) { } else if (osTvType == TV_TYPE_MPAL) {
__osViNext->modep = &D_803349E0; __osViNext->modep = &osViModeMpalLan1;
} else { } else {
__osViNext->modep = &D_80302FD0; __osViNext->modep = &osViModeNtscLan1;
} }
#else #else
@ -62,10 +62,10 @@ void __osViInit(void) {
if (sTvType == TV_TYPE_NTSC) if (sTvType == TV_TYPE_NTSC)
#endif #endif
{ {
__osViNext->modep = &D_80334990; __osViNext->modep = &osViModePalLan1;
osViClock = 0x02E6D354; osViClock = 0x02E6D354;
} else { } else {
__osViNext->modep = &D_803349E0; __osViNext->modep = &osViModeMpalLan1;
#if defined(VERSION_JP) #if defined(VERSION_JP)
osViClock = 0x02F5B2D2; osViClock = 0x02F5B2D2;
#elif defined(VERSION_US) #elif defined(VERSION_US)

View file

@ -1,6 +1,7 @@
#include "libultra_internal.h" #include "libultra_internal.h"
#include "PR/rcp.h" #include "PR/rcp.h"
#include "controller.h" #include "controller.h"
#include "macros.h"
extern s32 func_8030A5C0(OSMesgQueue *, s32); extern s32 func_8030A5C0(OSMesgQueue *, s32);
void __osPackRamReadData(int channel, u16 address); void __osPackRamReadData(int channel, u16 address);
@ -41,7 +42,7 @@ s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer) {
} }
ret = PFS_ERR_CONTRFAIL; ret = PFS_ERR_CONTRFAIL;
} else { } else {
for (i = 0; i < ARRLEN(ramreadformat.data); i++) { for (i = 0; i < ARRAY_COUNT(ramreadformat.data); i++) {
*buffer++ = ramreadformat.data[i]; *buffer++ = ramreadformat.data[i];
} }
} }
@ -63,7 +64,7 @@ void __osPackRamReadData(int channel, u16 address) {
ptr = (u8 *)__osPfsPifRam.ramarray; ptr = (u8 *)__osPfsPifRam.ramarray;
for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus for (i = 0; i < ARRAY_COUNT(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus
__osPfsPifRam.ramarray[i] = 0; __osPfsPifRam.ramarray[i] = 0;
} }
@ -74,7 +75,7 @@ void __osPackRamReadData(int channel, u16 address) {
ramreadformat.cmd = CONT_CMD_READ_MEMPACK; ramreadformat.cmd = CONT_CMD_READ_MEMPACK;
ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); ramreadformat.address = (address << 0x5) | __osContAddressCrc(address);
ramreadformat.datacrc = CONT_CMD_NOP; ramreadformat.datacrc = CONT_CMD_NOP;
for (i = 0; i < ARRLEN(ramreadformat.data); i++) { for (i = 0; i < ARRAY_COUNT(ramreadformat.data); i++) {
ramreadformat.data[i] = CONT_CMD_NOP; ramreadformat.data[i] = CONT_CMD_NOP;
} }
if (channel != 0) { if (channel != 0) {

View file

@ -1,6 +1,7 @@
#include "libultra_internal.h" #include "libultra_internal.h"
#include "PR/rcp.h" #include "PR/rcp.h"
#include "controller.h" #include "controller.h"
#include "macros.h"
extern s32 func_8030A5C0(OSMesgQueue *, s32); extern s32 func_8030A5C0(OSMesgQueue *, s32);
void __osPackRamWriteData(int channel, u16 address, u8 *buffer); void __osPackRamWriteData(int channel, u16 address, u8 *buffer);
@ -63,7 +64,7 @@ void __osPackRamWriteData(int channel, u16 address, u8 *buffer) {
ptr = (u8 *)__osPfsPifRam.ramarray; ptr = (u8 *)__osPfsPifRam.ramarray;
for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus for (i = 0; i < ARRAY_COUNT(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus
__osPfsPifRam.ramarray[i] = 0; __osPfsPifRam.ramarray[i] = 0;
} }
@ -74,7 +75,7 @@ void __osPackRamWriteData(int channel, u16 address, u8 *buffer) {
ramreadformat.cmd = CONT_CMD_WRITE_MEMPACK; ramreadformat.cmd = CONT_CMD_WRITE_MEMPACK;
ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); ramreadformat.address = (address << 0x5) | __osContAddressCrc(address);
ramreadformat.datacrc = CONT_CMD_NOP; ramreadformat.datacrc = CONT_CMD_NOP;
for (i = 0; i < ARRLEN(ramreadformat.data); i++) { for (i = 0; i < ARRAY_COUNT(ramreadformat.data); i++) {
ramreadformat.data[i] = *buffer++; ramreadformat.data[i] = *buffer++;
} }
if (channel != 0) { if (channel != 0) {

View file

@ -5,7 +5,6 @@
#include "PR/rcp.h" #include "PR/rcp.h"
//should go somewhere else but //should go somewhere else but
#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0])))
#define CHNL_ERR(format) ((format.rxsize & CHNL_ERR_MASK) >> 4) #define CHNL_ERR(format) ((format.rxsize & CHNL_ERR_MASK) >> 4)
typedef struct typedef struct

View file

@ -35,6 +35,6 @@ void func_802F4B08(void) {
sp28->validCount++; sp28->validCount++;
if (sp28->mtqueue->next != NULL) { if (sp28->mtqueue->next != NULL) {
s0 = __osPopThread(&sp28->mtqueue); s0 = __osPopThread(&sp28->mtqueue);
__osEnqueueThread(&D_80334898, s0); __osEnqueueThread(&__osRunQueue, s0);
} }
} }

View file

@ -2,7 +2,7 @@
void func_802F71F0(void) { void func_802F71F0(void) {
register u32 s0 = __osDisableInt(); register u32 s0 = __osDisableInt();
D_803348A0->state = OS_STATE_RUNNABLE; __osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&D_80334898); __osEnqueueAndYield(&__osRunQueue);
__osRestoreInt(s0); __osRestoreInt(s0);
} }

View file

@ -177,7 +177,7 @@ static void __osLeoResume(void) {
mq->msg[last] = es->message; mq->msg[last] = es->message;
mq->validCount++; mq->validCount++;
if (mq->mtqueue->next != NULL) { if (mq->mtqueue->next != NULL) {
__osEnqueueThread(&D_80334898, __osPopThread(&mq->mtqueue)); __osEnqueueThread(&__osRunQueue, __osPopThread(&mq->mtqueue));
} }
} }

View file

@ -20,13 +20,13 @@ typedef struct OSThread_ListHead_s
} OSThread_ListHead; } OSThread_ListHead;
// Now fix the symbols to the new one. // Now fix the symbols to the new one.
extern OSThread_ListHead D_80334890_fix; extern OSThread_ListHead __osThreadTail_fix;
#define D_80334890 D_80334890_fix.next #define __osThreadTail __osThreadTail_fix.next
#define D_80334894 D_80334890_fix.priority #define D_80334894 __osThreadTail_fix.priority
#define D_80334898 D_80334890_fix.queue #define __osRunQueue __osThreadTail_fix.queue
#define D_8033489C D_80334890_fix.tlnext #define __osActiveQueue __osThreadTail_fix.tlnext
#define D_803348A0 D_80334890_fix.unk10 #define __osRunningThread __osThreadTail_fix.unk10
// Fix for the EEPROM array. // Fix for the EEPROM array.
extern u32 D_80365E00[16]; extern u32 D_80365E00[16];
@ -35,11 +35,11 @@ extern u32 D_80365E00[16];
#define D_80365E3C D_80365E00[15] #define D_80365E3C D_80365E00[15]
#else #else
// Original OSThread_ListHead definitions // Original OSThread_ListHead definitions
extern OSThread *D_80334890; extern OSThread *__osThreadTail;
extern u32 D_80334894; extern u32 D_80334894;
extern OSThread *D_80334898; extern OSThread *__osRunQueue;
extern OSThread *D_8033489C; extern OSThread *__osActiveQueue;
extern OSThread *D_803348A0; extern OSThread *__osRunningThread;
// Original EEPROM definitions // Original EEPROM definitions
extern u32 D_80365E00[15]; extern u32 D_80365E00[15];

View file

@ -2,6 +2,7 @@
#include "PR/os_pi.h" #include "PR/os_pi.h"
#include "libultra_internal.h" #include "libultra_internal.h"
#include "controller.h" #include "controller.h"
#include "macros.h"
void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata); void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata);
u32 __osMotorinitialized[MAXCONTROLLERS] = { 0, 0, 0, 0 }; u32 __osMotorinitialized[MAXCONTROLLERS] = { 0, 0, 0, 0 };
@ -86,7 +87,7 @@ void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata) {
int i; int i;
ptr = (u8 *) mdata->ramarray; ptr = (u8 *) mdata->ramarray;
for (i = 0; i < ARRLEN(mdata->ramarray); i++) { for (i = 0; i < ARRAY_COUNT(mdata->ramarray); i++) {
mdata->ramarray[i] = 0; mdata->ramarray[i] = 0;
} }
mdata->pifstatus = CONT_CMD_EXE; mdata->pifstatus = CONT_CMD_EXE;
@ -97,7 +98,7 @@ void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata) {
ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); ramreadformat.address = (address << 0x5) | __osContAddressCrc(address);
ramreadformat.datacrc = CONT_CMD_NOP; ramreadformat.datacrc = CONT_CMD_NOP;
for (i = 0; i < ARRLEN(ramreadformat.data); i++) { for (i = 0; i < ARRAY_COUNT(ramreadformat.data); i++) {
ramreadformat.data[i] = *buffer++; ramreadformat.data[i] = *buffer++;
} }
if (channel != 0) { if (channel != 0) {
@ -119,7 +120,7 @@ s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel) {
pfs->status = 0; pfs->status = 0;
pfs->activebank = 128; pfs->activebank = 128;
for (i = 0; i < ARRLEN(temp); i++) { for (i = 0; i < ARRAY_COUNT(temp); i++) {
temp[i] = 254; temp[i] = 254;
} }
@ -142,7 +143,7 @@ s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel) {
return PFS_ERR_DEVICE; return PFS_ERR_DEVICE;
} }
for (i = 0; i < ARRLEN(temp); i++) { for (i = 0; i < ARRAY_COUNT(temp); i++) {
temp[i] = 128; temp[i] = 128;
} }
@ -166,7 +167,7 @@ s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel) {
} }
if (!__osMotorinitialized[channel]) { if (!__osMotorinitialized[channel]) {
for (i = 0; i < ARRLEN(_motorstartbuf); i++) { for (i = 0; i < ARRAY_COUNT(_motorstartbuf); i++) {
_motorstartbuf[i] = 1; _motorstartbuf[i] = 1;
_motorstopbuf[i] = 0; _motorstopbuf[i] = 0;
} }

View file

@ -2,8 +2,6 @@
#include "osAi.h" #include "osAi.h"
#include "hardware.h" #include "hardware.h"
u8 D_80334820 = 0;
/** /**
* It is worth noting that a previous hardware bug has been fixed by a software * It is worth noting that a previous hardware bug has been fixed by a software
* patch in osAiSetNextBuffer. This bug occurred when the address of the end of the * patch in osAiSetNextBuffer. This bug occurred when the address of the end of the
@ -19,22 +17,23 @@ u8 D_80334820 = 0;
*/ */
s32 osAiSetNextBuffer(void *buff, u32 len) { s32 osAiSetNextBuffer(void *buff, u32 len) {
u8 *sp1c = buff; static u8 hdwrBugFlag = 0;
if (D_80334820 != 0) { char *bptr = buff;
sp1c -= 0x2000; if (hdwrBugFlag != 0) {
bptr -= 0x2000;
} }
if ((((uintptr_t) buff + len) & 0x3fff) == 0x2000) { if ((((uintptr_t) buff + len) & 0x3fff) == 0x2000) {
D_80334820 = 1; hdwrBugFlag = 1;
} else { } else {
D_80334820 = 0; hdwrBugFlag = 0;
} }
if (__osAiDeviceBusy()) { if (__osAiDeviceBusy()) {
return -1; return -1;
} }
HW_REG(AI_DRAM_ADDR_REG, void *) = (void *) osVirtualToPhysical(sp1c); HW_REG(AI_DRAM_ADDR_REG, void *) = (void *) osVirtualToPhysical(bptr);
HW_REG(AI_LEN_REG, u32) = len; HW_REG(AI_LEN_REG, u32) = len;
return 0; return 0;
} }

View file

@ -1,8 +1,8 @@
#include "libultra_internal.h" #include "libultra_internal.h"
void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msgBuf, s32 count) { void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msgBuf, s32 count) {
mq->mtqueue = (OSThread *) &D_80334890; //? mq->mtqueue = (OSThread *) &__osThreadTail;
mq->fullqueue = (OSThread *) &D_80334890; mq->fullqueue = (OSThread *) &__osThreadTail;
mq->validCount = 0; mq->validCount = 0;
mq->first = 0; mq->first = 0;
mq->msgCount = count; mq->msgCount = count;

View file

@ -1,4 +1,5 @@
#include "libultra_internal.h" #include "libultra_internal.h"
#include <PR/R4300.h>
void __osCleanupThread(void); void __osCleanupThread(void);
@ -7,8 +8,8 @@ void __osCleanupThread(void);
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" #pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
void osCreateThread(OSThread *thread, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri) { void osCreateThread(OSThread *thread, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri) {
register u32 int_disabled; register u32 saveMask;
u32 tmp; OSIntMask mask;
thread->id = id; thread->id = id;
thread->priority = pri; thread->priority = pri;
thread->next = NULL; thread->next = NULL;
@ -17,18 +18,18 @@ void osCreateThread(OSThread *thread, OSId id, void (*entry)(void *), void *arg,
thread->context.a0 = (u64) arg; thread->context.a0 = (u64) arg;
thread->context.sp = (u64) sp - 16; thread->context.sp = (u64) sp - 16;
thread->context.ra = (u64) __osCleanupThread; thread->context.ra = (u64) __osCleanupThread;
tmp = OS_IM_ALL; mask = OS_IM_ALL;
thread->context.sr = 65283; thread->context.sr = SR_IMASK | SR_EXL | SR_IE;
thread->context.rcp = (tmp & 0x3f0000) >> 16; thread->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT;
thread->context.fpcsr = (u32) 0x01000800; thread->context.fpcsr = (u32) (FPCSR_FS | FPCSR_EV);
thread->fp = 0; thread->fp = 0;
thread->state = OS_STATE_STOPPED; thread->state = OS_STATE_STOPPED;
thread->flags = 0; thread->flags = 0;
int_disabled = __osDisableInt(); saveMask = __osDisableInt();
thread->tlnext = D_8033489C; thread->tlnext = __osActiveQueue;
D_8033489C = thread; __osActiveQueue = thread;
__osRestoreInt(int_disabled); __osRestoreInt(saveMask);
} }
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

View file

@ -8,15 +8,15 @@ void osDestroyThread(OSThread *thread) {
int_disabled = __osDisableInt(); int_disabled = __osDisableInt();
if (thread == NULL) { if (thread == NULL) {
thread = D_803348A0; thread = __osRunningThread;
} else if (thread->state != OS_STATE_STOPPED) { } else if (thread->state != OS_STATE_STOPPED) {
__osDequeueThread(thread->queue, thread); __osDequeueThread(thread->queue, thread);
} }
if (D_8033489C == thread) { if (__osActiveQueue == thread) {
D_8033489C = D_8033489C->tlnext; __osActiveQueue = __osActiveQueue->tlnext;
} else { } else {
s1 = D_8033489C; s1 = __osActiveQueue;
s2 = s1->tlnext; s2 = s1->tlnext;
while (s2 != NULL) { while (s2 != NULL) {
if (s2 == thread) { if (s2 == thread) {
@ -29,7 +29,7 @@ void osDestroyThread(OSThread *thread) {
} }
} }
if (thread == D_803348A0) { if (thread == __osRunningThread) {
__osDispatchThread(); __osDispatchThread();
} }

View file

@ -19,9 +19,9 @@ s32 osEepromLongRead(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes) {
return status; return status;
} }
nbytes -= 8; nbytes -= EEPROM_BLOCK_SIZE;
address++; address++;
buffer += 8; buffer += EEPROM_BLOCK_SIZE;
osSetTimer(&D_80365D28, 12000 * osClockRate / 1000000, 0, &_osContMesgQueue, _osContMesgBuff); osSetTimer(&D_80365D28, 12000 * osClockRate / 1000000, 0, &_osContMesgQueue, _osContMesgBuff);
osRecvMesg(&_osContMesgQueue, NULL, OS_MESG_BLOCK); osRecvMesg(&_osContMesgQueue, NULL, OS_MESG_BLOCK);
} }

View file

@ -20,9 +20,9 @@ s32 osEepromLongWrite(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes) {
return result; return result;
} }
nbytes -= 8; nbytes -= EEPROM_BLOCK_SIZE;
address++; address++;
buffer += 8; buffer += EEPROM_BLOCK_SIZE;
osSetTimer(&D_80365D28, 12000 * osClockRate / 1000000, 0, &_osContMesgQueue, _osContMesgBuff); osSetTimer(&D_80365D28, 12000 * osClockRate / 1000000, 0, &_osContMesgQueue, _osContMesgBuff);
osRecvMesg(&_osContMesgQueue, NULL, OS_MESG_BLOCK); osRecvMesg(&_osContMesgQueue, NULL, OS_MESG_BLOCK);
} }

View file

@ -2,7 +2,7 @@
OSPri osGetThreadPri(OSThread *thread) { OSPri osGetThreadPri(OSThread *thread) {
if (thread == NULL) { if (thread == NULL) {
thread = D_803348A0; thread = __osRunningThread;
} }
return thread->priority; return thread->priority;
} }

View file

@ -5,7 +5,7 @@ s32 osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag) {
int_disabled = __osDisableInt(); int_disabled = __osDisableInt();
while (mq->validCount >= mq->msgCount) { while (mq->validCount >= mq->msgCount) {
if (flag == OS_MESG_BLOCK) { if (flag == OS_MESG_BLOCK) {
D_803348A0->state = OS_STATE_WAITING; __osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->fullqueue); __osEnqueueAndYield(&mq->fullqueue);
} else { } else {
__osRestoreInt(int_disabled); __osRestoreInt(int_disabled);

View file

@ -1,6 +1,7 @@
#include "PR/os_pi.h" #include "PR/os_pi.h"
#include "libultra_internal.h" #include "libultra_internal.h"
#include "controller.h" #include "controller.h"
#include "macros.h"
OSPifRam __osPfsPifRam; OSPifRam __osPfsPifRam;
@ -52,7 +53,7 @@ void __osPfsRequestData(u8 cmd) {
_osLastSentSiCmd = cmd; _osLastSentSiCmd = cmd;
for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus for (i = 0; i < ARRAY_COUNT(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus
__osPfsPifRam.ramarray[i] = 0; __osPfsPifRam.ramarray[i] = 0;
} }

View file

@ -10,7 +10,7 @@ s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flag) {
__osRestoreInt(int_disabled); __osRestoreInt(int_disabled);
return -1; return -1;
} }
D_803348A0->state = OS_STATE_WAITING; __osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->mtqueue); __osEnqueueAndYield(&mq->mtqueue);
} }

View file

@ -8,7 +8,7 @@ s32 osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flag) {
while (mq->validCount >= mq->msgCount) { while (mq->validCount >= mq->msgCount) {
if (flag == OS_MESG_BLOCK) { if (flag == OS_MESG_BLOCK) {
D_803348A0->state = 8; __osRunningThread->state = 8;
__osEnqueueAndYield(&mq->fullqueue); __osEnqueueAndYield(&mq->fullqueue);
} else { } else {
__osRestoreInt(int_disabled); __osRestoreInt(int_disabled);

View file

@ -3,20 +3,20 @@
void osSetThreadPri(OSThread *thread, OSPri pri) { void osSetThreadPri(OSThread *thread, OSPri pri) {
register u32 int_disabled = __osDisableInt(); register u32 int_disabled = __osDisableInt();
if (thread == NULL) { if (thread == NULL) {
thread = D_803348A0; thread = __osRunningThread;
} }
if (thread->priority != pri) { if (thread->priority != pri) {
thread->priority = pri; thread->priority = pri;
if (thread != D_803348A0) { if (thread != __osRunningThread) {
if (thread->state != OS_STATE_STOPPED) { if (thread->state != OS_STATE_STOPPED) {
__osDequeueThread(thread->queue, thread); __osDequeueThread(thread->queue, thread);
__osEnqueueThread(thread->queue, thread); __osEnqueueThread(thread->queue, thread);
} }
} }
if (D_803348A0->priority < D_80334898->priority) { if (__osRunningThread->priority < __osRunQueue->priority) {
D_803348A0->state = OS_STATE_RUNNABLE; __osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&D_80334898); __osEnqueueAndYield(&__osRunQueue);
} }
} }

View file

@ -11,26 +11,26 @@ void osStartThread(OSThread *thread) {
do { do {
} while (0); } while (0);
thread->state = OS_STATE_RUNNABLE; thread->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&D_80334898, thread); __osEnqueueThread(&__osRunQueue, thread);
} }
} else { } else {
if (thread->queue == NULL || thread->queue == &D_80334898) { if (thread->queue == NULL || thread->queue == &__osRunQueue) {
thread->state = OS_STATE_RUNNABLE; thread->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&D_80334898, thread); __osEnqueueThread(&__osRunQueue, thread);
} else { } else {
thread->state = OS_STATE_WAITING; thread->state = OS_STATE_WAITING;
__osEnqueueThread(thread->queue, thread); __osEnqueueThread(thread->queue, thread);
state = (uintptr_t) __osPopThread(thread->queue); state = (uintptr_t) __osPopThread(thread->queue);
__osEnqueueThread(&D_80334898, (OSThread *) state); __osEnqueueThread(&__osRunQueue, (OSThread *) state);
} }
} }
if (D_803348A0 == NULL) { if (__osRunningThread == NULL) {
__osDispatchThread(); __osDispatchThread();
} else { } else {
if (D_803348A0->priority < D_80334898->priority) { if (__osRunningThread->priority < __osRunQueue->priority) {
D_803348A0->state = OS_STATE_RUNNABLE; __osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&D_80334898); __osEnqueueAndYield(&__osRunQueue);
} }
} }
__osRestoreInt(int_disabled); __osRestoreInt(int_disabled);

View file

@ -1,7 +1,7 @@
#include "libultra_internal.h" #include "libultra_internal.h"
#if defined(VERSION_EU) || defined(VERSION_SH) #if defined(VERSION_EU) || defined(VERSION_SH)
OSViMode D_80334990 = { OSViMode osViModePalLan1 = {
/*type*/ 16, /*type*/ 16,
/*comRegs*/ /*comRegs*/
{ /*ctrl*/ 12574, { /*ctrl*/ 12574,
@ -35,7 +35,7 @@ OSViMode D_80334990 = {
/*vIntr*/ 2 } } /*vIntr*/ 2 } }
}; };
OSViMode D_803349E0 = { OSViMode osViModeMpalLan1 = {
/*type*/ 30, //osViModePalLan1 /*type*/ 30, //osViModePalLan1
/*comRegs*/ /*comRegs*/
{ /*ctrl*/ 12574, { /*ctrl*/ 12574,
@ -60,7 +60,7 @@ OSViMode D_803349E0 = {
/*vIntr*/ 2 } } /*vIntr*/ 2 } }
}; };
OSViMode D_80302FD0 = { OSViMode osViModeNtscLan1 = {
/*type*/ 2, /*type*/ 2,
/*comRegs*/ /*comRegs*/
{ /*ctrl*/ 12574, { /*ctrl*/ 12574,
@ -85,7 +85,7 @@ OSViMode D_80302FD0 = {
/*vIntr*/ 2 } } /*vIntr*/ 2 } }
}; };
#else #else
OSViMode D_80334990 = { OSViMode osViModePalLan1 = {
/*type*/ 2, /*type*/ 2,
/*comRegs*/ /*comRegs*/
{ /*ctrl*/ 12574, { /*ctrl*/ 12574,
@ -110,7 +110,7 @@ OSViMode D_80334990 = {
/*vIntr*/ 2 } } /*vIntr*/ 2 } }
}; };
OSViMode D_803349E0 = { OSViMode osViModeMpalLan1 = {
/*type*/ 16, /*type*/ 16,
/*comRegs*/ /*comRegs*/
{ /*ctrl*/ 12574, { /*ctrl*/ 12574,

View file

@ -7,11 +7,6 @@ typedef struct __OSEventState
OSMesgQueue *messageQueue; OSMesgQueue *messageQueue;
OSMesg message; OSMesg message;
} __OSEventState; } __OSEventState;
extern struct __osThreadTail
{
OSThread *next;
OSPri priority;
} __osThreadTail;
//maybe should be in exceptasm.h? //maybe should be in exceptasm.h?
extern void __osEnqueueAndYield(OSThread **); extern void __osEnqueueAndYield(OSThread **);
@ -27,12 +22,12 @@ extern u32 __osProbeTLB(void *);
extern int __osSpDeviceBusy(void); extern int __osSpDeviceBusy(void);
#ifdef AVOID_UB #ifdef AVOID_UB
extern OSThread_ListHead D_80334890_fix; extern OSThread_ListHead __osThreadTail_fix;
#else #else
extern OSThread *__osRunningThread; extern OSThread *__osRunningThread;
extern OSThread *D_8033489C; extern OSThread *__osActiveQueue;
extern OSThread *__osFaultedThread; extern OSThread *__osFaultedThread;
extern OSThread *D_80334898; extern OSThread *__osRunQueue;
#endif #endif
extern OSTimer *__osTimerList; extern OSTimer *__osTimerList;