From 3df37b5bc66a50a5f4e29ed6916f0cce589c3777 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sat, 6 Sep 2025 20:47:22 -0400 Subject: [PATCH 01/16] Remove outdated code from errorasm/exceptasm --- src/error/errorasm.s | 17 ---- src/os/exceptasm.s | 196 ------------------------------------------- 2 files changed, 213 deletions(-) diff --git a/src/error/errorasm.s b/src/error/errorasm.s index c41cf6d4..13870bd7 100644 --- a/src/error/errorasm.s +++ b/src/error/errorasm.s @@ -6,26 +6,9 @@ #include "PR/os_version.h" LEAF(__osError) -#if BUILD_VERSION < VERSION_J - lw t0, __osErrorHandler - beqz t0, 1f - jr t0 -#elif BUILD_VERSION < VERSION_K - lw t0, __kmc_pt_mode - bnez t0, _kmc_mode - - lw t0, __osErrorHandler - beqz t0, 1f - jr t0 -_kmc_mode: - lw t0, __kmcErrorHandler - beqz t0, 1f - jr t0 -#else lw t0, __osCommonHandler beqz t0, 1f jr t0 -#endif 1: j ra END(__osError) diff --git a/src/os/exceptasm.s b/src/os/exceptasm.s index 9a7dbea4..1f42aa84 100644 --- a/src/os/exceptasm.s +++ b/src/os/exceptasm.s @@ -200,202 +200,6 @@ LEAF(__osException) sd $10, THREAD_GP10(k0) /* Mark FPU as unused */ sw zero, THREAD_FP(k0) - /* This instruction is useless, leftover because of bad placement of an ifdef for the debug version */ - MFC0( t0, C0_CAUSE) -#ifndef _FINALROM - lw t2, __kmc_pt_mode - bnez t2, skip_kmc_mode - andi t1, t0, 0x7c - li t2, 0 - bne t1, t2, savecontext - and t1, k1, t0 - andi t2, t1, CAUSE_IP7 - beqz t2, notIP7 - /* clear rdb write interrupt */ - la t1, RDB_WRITE_INTR_REG - sw zero, (t1) -IP7check: - MFC0( t0, C0_CAUSE) - andi t0, t0, CAUSE_IP7 - bne zero, t0, IP7check - la t2, RDB_BASE_REG - lw t0, (t2) - srl t1, t0, 0x1a - andi t1, t1, 0x3f - li t2, RDB_TYPE_HtoG_DATA - beq t1, t2, HandData - li t2, RDB_TYPE_HtoG_DEBUG - beq t1, t2, HandDbg - li t2, RDB_TYPE_HtoG_KDEBUG - beq t1, t2, HandKDebug - li t2, RDB_TYPE_HtoG_DEBUG_CT - beq t1, t2, DbgCnt - li t2, RDB_TYPE_HtoG_DATA_DONE - beq t1, t2, DataRead - li t2, RDB_TYPE_HtoG_LOG_DONE - beq t1, t2, LogRead - li t2, RDB_TYPE_HtoG_REQ_RAMROM - beq t1, t2, ReqRamrom - li t2, RDB_TYPE_HtoG_FREE_RAMROM - beq t1, t2, FreeRamrom - li t2, RDB_TYPE_HtoG_PROF_SIGNAL - beq t1, t2, SignalProf - b rdbout -SignalProf: - li t2, 1 - srl t1, t0, 0x10 - andi t1, t1, 0xff - beq t1, t2, AckProf - li t2, 0xa8 - sw t2, __osRdb_Mesg - b savecontext -AckProf: - li t2, 0xb0 - sw t2, __osRdb_Mesg - b savecontext -HandKDebug: - sw t0, __os_Kdebug_Pkt - b savecontext -DbgCnt: - li t2, 0xffffff - and t1, t0, t2 - sw t1, __osRdb_DbgRead_Ct - b rdbout -DataRead: - li t2, 0x88 - sw t2, __osRdb_Mesg - b savecontext -LogRead: - li t2, 0x80 - sw t2, __osRdb_Mesg - b savecontext -ReqRamrom: - li t2, 0x90 - sw t2, __osRdb_Mesg - b savecontext -FreeRamrom: - li t2, 0x98 - sw t2, __osRdb_Mesg - b savecontext -HandData: - srl t1, t0, 0x18 - andi t1, t1, 3 - beq zero, t1, rdbout - lw t2, __osRdb_Read_Data_Ct - subu t2, t2, t1 - sw t2, __osRdb_Read_Data_Ct - sd t3, THREAD_GP11(k0) - lw t3, __osRdb_Read_Data_Buf - srl t2, t0, 0x10 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneData - srl t2, t0, 8 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneData - andi t0, t0, 0xff - sb t0, (t3) - addi t3, t3, 1 -doneData: - sw t3, __osRdb_Read_Data_Buf - ld t3, THREAD_GP11(k0) - lw t2, __osRdb_Read_Data_Ct - bne zero, t2, rdbout - li t2, 0x78 - sw t2, __osRdb_Mesg - b savecontext -HandDbg: - srl t1, t0, 0x18 - andi t1, t1, 3 - beq zero, t1, rdbout - lw t2, __osRdb_DbgRead_Ct - subu t2, t2, t1 - sw t2, __osRdb_DbgRead_Ct - sd t3, THREAD_GP11(k0) - lw t3, __osRdb_DbgRead_Buf - bne zero, t3, 1f - ld t3, THREAD_GP11(k0) - b rdbout -1: - srl t2, t0, 0x10 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneDbg - srl t2, t0, 8 - andi t2, t2, 0xff - sb t2, (t3) - addi t3, t3, 1 - addi t1, t1, -1 - beq zero, t1, doneDbg - andi t0, t0, 0xff - sb t0, (t3) - addi t3, t3, 1 -doneDbg: - sw t3, __osRdb_DbgRead_Buf - ld t3, THREAD_GP11(k0) - lw t2, __osRdb_DbgRead_Ct - bne zero, t2, rdbout - li t2, 0xa0 - sw t2, __osRdb_Mesg - b savecontext -notIP7: - andi t2, t1, CAUSE_IP6 - beqz t2, savecontext - /* clear rdb read interrupt */ - la t1, RDB_READ_INTR_REG - sw zero, (t1) - lw t2, __osRdb_IP6_Ct - bnez t2, 2f - li t2, 1 - sw t2, __osRdb_IP6_Empty - b rdbout -2: - addi t2, t2, -1 - sw t2, __osRdb_IP6_Ct - lw t0, __osRdb_IP6_Data - lw t1, __osRdb_IP6_CurSend - sll t2, t1, 2 - add t0, t2, t0 - lw t2, (t0) - addi t1, t1, 1 - lw t0, __osRdb_IP6_Size - sub t0, t0, t1 - bgtz t0, 5f - li t1, 0 -5: - sw t1, __osRdb_IP6_CurSend -checkIP6: - MFC0( t0, C0_CAUSE) - andi t0, t0, CAUSE_IP6 - bne zero, t0, checkIP6 - la t0, RDB_BASE_REG - sw t2, (t0) -rdbout: - ld t0, THREAD_GP8(k0) - ld t1, THREAD_GP9(k0) - ld t2, THREAD_GP10(k0) -.set noat - ld $1, THREAD_GP1(k0) -.set at - lw k1, THREAD_SR(k0) - MTC0( k1, C0_SR) -.set noreorder - nop - nop - nop - nop - eret -.set reorder - -skip_kmc_mode: -#endif savecontext: /* Save the context of the previously running thread to be restored when it resumes */ From 434fb48424415718014aef0911196e8ffe79eeac Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:25:46 -0500 Subject: [PATCH 02/16] Delete osAckRamromWrite and osAckRamromRead, old unused stubs --- src/os/ackramromread.c | 8 -------- src/os/ackramromwrite.c | 7 ------- 2 files changed, 15 deletions(-) delete mode 100644 src/os/ackramromread.c delete mode 100644 src/os/ackramromwrite.c diff --git a/src/os/ackramromread.c b/src/os/ackramromread.c deleted file mode 100644 index 76277043..00000000 --- a/src/os/ackramromread.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/os_version.h" - -// TODO: this comes from a header -#ident "$Revision: 1.4 $" - -void osAckRamromRead(void) { -} diff --git a/src/os/ackramromwrite.c b/src/os/ackramromwrite.c deleted file mode 100644 index 545918ba..00000000 --- a/src/os/ackramromwrite.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "PR/os_internal.h" - -// TODO: this comes from a header -#ident "$Revision: 1.4 $" - -void osAckRamromWrite(void) { -} From 3c9c1bea41c6f4a237620699ccbc7985152acbf0 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:30:51 -0500 Subject: [PATCH 03/16] Remove osDriveRomInit, as this is old OS2.0I code that's not supposed to be in later versions --- src/io/driverominit.c | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 src/io/driverominit.c diff --git a/src/io/driverominit.c b/src/io/driverominit.c deleted file mode 100644 index bfa9f76c..00000000 --- a/src/io/driverominit.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PRinternal/macros.h" - -OSPiHandle DriveRomHandle ALIGNED(0x8); - -OSPiHandle* osDriveRomInit(void) { - u32 saveMask; - - if (DriveRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR1)) { - return &DriveRomHandle; - } - - DriveRomHandle.type = DEVICE_TYPE_BULK; - DriveRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR1); - DriveRomHandle.latency = 64; - DriveRomHandle.pulse = 7; - DriveRomHandle.pageSize = 7; - DriveRomHandle.relDuration = 2; - DriveRomHandle.domain = PI_DOMAIN1; - DriveRomHandle.speed = 0; - - bzero(&DriveRomHandle.transferInfo, sizeof(__OSTranxInfo)); - - saveMask = __osDisableInt(); - DriveRomHandle.next = __osPiTable; - __osPiTable = &DriveRomHandle; - __osRestoreInt(saveMask); - - return &DriveRomHandle; -} From 10b45421bc942737fe7a9ef8af5b99ba4f346785 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:32:04 -0500 Subject: [PATCH 04/16] Remove error.c as this was removed in 2.0J and duplicates other code --- src/error/error.c | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 src/error/error.c diff --git a/src/error/error.c b/src/error/error.c deleted file mode 100644 index f4b5e8de..00000000 --- a/src/error/error.c +++ /dev/null @@ -1,30 +0,0 @@ -// This file was removed in 2.0J -#include "stdarg.h" -#include "PR/os_internal.h" -#include "PR/ultralog.h" -#include "PR/ultraerror.h" -#include "PRinternal/macros.h" - -void __osLogWrite(OSLog* log, s16 code, s16 numArgs, va_list argPtr); -static void __osDefaultHandler(s16 code, s16 numArgs, ...); - -static u32 errorLogData[19] ALIGNED(0x8); -static OSLog errorLog ALIGNED(0x8) = { - OS_ERROR_MAGIC, // magic - sizeof(errorLogData), // len - errorLogData, // base - 0, // startCount - 0, // writeOffset -}; - -OSErrorHandler __osErrorHandler = __osDefaultHandler; - -static void __osDefaultHandler(s16 code, s16 numArgs, ...) { - va_list argPtr; - va_start(argPtr, numArgs); - - __osLogWrite(&errorLog, code, numArgs, argPtr); - osFlushLog(&errorLog); - - va_end(argPtr); -} From 7bdc32e3c67183ea156017f95747e62710ad7526 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:33:02 -0500 Subject: [PATCH 05/16] Remove old libleo code which was only in 2.0I --- src/io/leodiskinit.c | 36 -------- src/io/leointerrupt.c | 195 ------------------------------------------ 2 files changed, 231 deletions(-) delete mode 100644 src/io/leodiskinit.c delete mode 100644 src/io/leointerrupt.c diff --git a/src/io/leodiskinit.c b/src/io/leodiskinit.c deleted file mode 100644 index 81c67b9b..00000000 --- a/src/io/leodiskinit.c +++ /dev/null @@ -1,36 +0,0 @@ -// This file was removed in 2.0J -#include "PR/os_internal.h" -#include "PR/os_libc.h" -#include "PR/rcp.h" -#include "PRinternal/macros.h" - -OSPiHandle LeoDiskHandle ALIGNED(0x8); -OSPiHandle* __osDiskHandle; - -OSPiHandle* osLeoDiskInit(void) { - u32 saveMask; - - LeoDiskHandle.type = DEVICE_TYPE_64DD; - LeoDiskHandle.baseAddress = PHYS_TO_K1(PI_DOM2_ADDR1); - LeoDiskHandle.latency = 3; - LeoDiskHandle.pulse = 6; - LeoDiskHandle.pageSize = 6; - LeoDiskHandle.relDuration = 2; - LeoDiskHandle.domain = PI_DOMAIN2; - - IO_WRITE(PI_BSD_DOM2_LAT_REG, LeoDiskHandle.latency); - IO_WRITE(PI_BSD_DOM2_PWD_REG, LeoDiskHandle.pulse); - IO_WRITE(PI_BSD_DOM2_PGS_REG, LeoDiskHandle.pageSize); - IO_WRITE(PI_BSD_DOM2_RLS_REG, LeoDiskHandle.relDuration); - LeoDiskHandle.speed = 0; - - bzero(&LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo)); - - saveMask = __osDisableInt(); - LeoDiskHandle.next = __osPiTable; - __osPiTable = &LeoDiskHandle; - __osDiskHandle = &LeoDiskHandle; - __osRestoreInt(saveMask); - - return &LeoDiskHandle; -} diff --git a/src/io/leointerrupt.c b/src/io/leointerrupt.c deleted file mode 100644 index 651607b4..00000000 --- a/src/io/leointerrupt.c +++ /dev/null @@ -1,195 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PRinternal/osint.h" -#include "PRinternal/piint.h" -#include "PRinternal/macros.h" - -extern OSPiHandle* __osDiskHandle; - -u8 leoDiskStack[OS_PIM_STACKSIZE] ALIGNED(0x10); - -static void __osLeoAbnormalResume(void); -static void __osLeoResume(void); - -s32 __osLeoInterrupt(void) { - u32 stat = 0; - volatile u32 pi_stat; - u32 bm_stat; - __OSTranxInfo* info = &__osDiskHandle->transferInfo; - __OSBlockInfo* blockInfo = &info->block[info->blockNum]; - - pi_stat = IO_READ(PI_STATUS_REG); - if (pi_stat & PI_STATUS_DMA_BUSY) { - __OSGlobalIntMask = __OSGlobalIntMask & ~SR_IBIT4; // cart interrupt - blockInfo->errStatus = LEO_ERROR_29; - __osLeoResume(); - return 1; - } - - WAIT_ON_IOBUSY(pi_stat); - stat = IO_READ(LEO_STATUS); - if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); - blockInfo->errStatus = LEO_ERROR_GOOD; - return 0; - } - - if (info->cmdType == LEO_CMD_TYPE_2) { - return 1; - } - - if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR) { - WAIT_ON_IOBUSY(pi_stat); - stat = IO_READ(LEO_STATUS); - blockInfo->errStatus = LEO_ERROR_22; - __osLeoResume(); - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - return 1; - } - - if (info->cmdType == LEO_CMD_TYPE_1) { - if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { - if (info->sectorNum + 1 != info->transferMode * 85) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - blockInfo->errStatus = LEO_ERROR_GOOD; - __osLeoResume(); - return 1; - } else { - blockInfo->dramAddr = (void*)((u32)blockInfo->dramAddr + blockInfo->sectorSize); - info->sectorNum++; - __osEPiRawStartDma(__osDiskHandle, OS_WRITE, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); - return 1; - } - } else if (info->cmdType == LEO_CMD_TYPE_0) { - if (info->transferMode == LEO_SECTOR_MODE) { - if (info->sectorNum > (s32)blockInfo->C1ErrNum + 17) { - blockInfo->errStatus = LEO_ERROR_GOOD; - __osLeoAbnormalResume(); - return 1; - } - - if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { - blockInfo->errStatus = LEO_ERROR_23; - __osLeoAbnormalResume(); - return 1; - } - } else { - blockInfo->dramAddr = (void*)((u32)blockInfo->dramAddr + blockInfo->sectorSize); - } - - bm_stat = IO_READ(LEO_BM_STATUS); - if ((bm_stat & LEO_BM_STATUS_C1SINGLE && bm_stat & LEO_BM_STATUS_C1DOUBLE) || bm_stat & LEO_BM_STATUS_MICRO) { - if (blockInfo->C1ErrNum > 3) { - if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52) { - blockInfo->errStatus = LEO_ERROR_23; - __osLeoAbnormalResume(); - return 1; - } - } else { - int errNum = blockInfo->C1ErrNum; - blockInfo->C1ErrSector[errNum] = info->sectorNum + 1; - } - - blockInfo->C1ErrNum++; - } - - if (stat & LEO_STATUS_C2_TRANSFER) { - if (info->sectorNum + 1 != 88) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - } - - if (info->transferMode == LEO_TRACK_MODE && info->blockNum == 0) { - info->blockNum = 1; - info->sectorNum = -1; - info->block[1].dramAddr = (void*)((u32)info->block[1].dramAddr - info->block[1].sectorSize); - - blockInfo->errStatus = LEO_ERROR_22; - } else { - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - info->cmdType = LEO_CMD_TYPE_2; - blockInfo->errStatus = LEO_ERROR_GOOD; - } - - __osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4); - return 1; - } - - if (info->sectorNum == -1 && info->transferMode == LEO_TRACK_MODE && info->blockNum == 1) { - __OSBlockInfo* bptr = &info->block[0]; - if (bptr->C1ErrNum == 0) { - if (((u32*)bptr->C2Addr)[0] | ((u32*)bptr->C2Addr)[1] | ((u32*)bptr->C2Addr)[2] - | ((u32*)bptr->C2Addr)[3]) { - bptr->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - } - - bptr->errStatus = 0; - __osLeoResume(); - } - info->sectorNum++; - if (stat & LEO_STATUS_DATA_REQUEST) { - if (info->sectorNum > 0x54) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - - __osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); - blockInfo->errStatus = LEO_ERROR_GOOD; - return 1; - } else if (info->sectorNum <= 0x54) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - - return 1; - } else { - blockInfo->errStatus = LEO_ERROR_4; - __osLeoAbnormalResume(); - return 1; - } -} - -static void __osLeoAbnormalResume(void) { - __OSTranxInfo* info = &__osDiskHandle->transferInfo; - u32 pi_stat; - - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow); - __osLeoResume(); - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; -} - -static void __osLeoResume(void) { - __OSEventState* es = &__osEventStateTab[OS_EVENT_PI]; - OSMesgQueue* mq = es->messageQueue; - s32 last; - - if (mq == NULL || MQ_IS_FULL(mq)) { - return; - } - - last = (mq->first + mq->validCount) % mq->msgCount; - mq->msg[last] = es->message; - mq->validCount++; - - if (mq->mtqueue->next != NULL) { - __osEnqueueThread(&__osRunQueue, __osPopThread(&mq->mtqueue)); - } -} From 032b25988c17c6d66f2710dc0cc944e8d1cf06c8 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:35:16 -0500 Subject: [PATCH 06/16] Remove mtxutil and mtxcatl as these are duplicate of functions rewritten in mgu --- src/gu/mtxcatl.c | 45 ------------------------------- src/gu/mtxutil.c | 70 ------------------------------------------------ 2 files changed, 115 deletions(-) delete mode 100644 src/gu/mtxcatl.c delete mode 100644 src/gu/mtxutil.c diff --git a/src/gu/mtxcatl.c b/src/gu/mtxcatl.c deleted file mode 100644 index adb756b1..00000000 --- a/src/gu/mtxcatl.c +++ /dev/null @@ -1,45 +0,0 @@ - -/* - * Copyright 1995, Silicon Graphics, Inc. - * ALL RIGHTS RESERVED - * - * UNPUBLISHED -- Rights reserved under the copyright laws of the United - * States. Use of a copyright notice is precautionary only and does not - * imply publication or disclosure. - * - * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to restrictions - * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or - * in similar or successor clauses in the FAR, or the DOD or NASA FAR - * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., - * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. - * - * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY - * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, - * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY - * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON - * GRAPHICS, INC. - * - */ - -/* - * File: mtxcatl.c - * Creator: hsa@sgi.com - * Create Date: Thu Nov 2 13:03:02 PST 1995 - * - */ - -#include "guint.h" -#include "os_version.h" - -void guMtxCatL(Mtx* m, Mtx* n, Mtx* res) { - float mf[4][4], nf[4][4], resf[4][4]; - - guMtxL2F(mf, m); - guMtxL2F(nf, n); - - guMtxCatF(mf, nf, resf); - - guMtxF2L(resf, res); -} diff --git a/src/gu/mtxutil.c b/src/gu/mtxutil.c deleted file mode 100644 index 68cd6933..00000000 --- a/src/gu/mtxutil.c +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -#include "guint.h" - -void guMtxF2L(float mf[4][4], Mtx* m) { - int i, j; - int e1, e2; - int *ai, *af; - - ai = (int*)&m->m[0][0]; - af = (int*)&m->m[2][0]; - - for (i = 0; i < 4; i++) - for (j = 0; j < 2; j++) { - e1 = FTOFIX32(mf[i][j * 2]); - e2 = FTOFIX32(mf[i][j * 2 + 1]); - *(ai++) = (e1 & 0xffff0000) | ((e2 >> 16) & 0xffff); - *(af++) = ((e1 << 16) & 0xffff0000) | (e2 & 0xffff); - } -} - -void guMtxL2F(float mf[4][4], Mtx* m) { - int i, j; - unsigned int e1, e2; - unsigned int *ai, *af; - int q1, q2; - - ai = (unsigned int*)&m->m[0][0]; - af = (unsigned int*)&m->m[2][0]; - - for (i = 0; i < 4; i++) - for (j = 0; j < 2; j++) { - e1 = (*ai & 0xffff0000) | ((*af >> 16) & 0xffff); - e2 = ((*(ai++) << 16) & 0xffff0000) | (*(af++) & 0xffff); - q1 = *((int*)&e1); - q2 = *((int*)&e2); - - mf[i][j * 2] = FIX32TOF(q1); - mf[i][j * 2 + 1] = FIX32TOF(q2); - } -} - -void guMtxIdentF(float mf[4][4]) { - int i, j; - - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - if (i == j) - mf[i][j] = 1.0; - else - mf[i][j] = 0.0; -} - -void guMtxIdent(Mtx* m) { - float mf[4][4]; - - guMtxIdentF(mf); - - guMtxF2L(mf, m); -} From 8c5d7a4186b71f197eb7d308b20c6ac0d5e021f2 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:40:12 -0500 Subject: [PATCH 07/16] Remove dump_gbi as it's literally all #if 0 --- src/gu/dump_gbi.c | 271 ---------------------------------------------- 1 file changed, 271 deletions(-) delete mode 100644 src/gu/dump_gbi.c diff --git a/src/gu/dump_gbi.c b/src/gu/dump_gbi.c deleted file mode 100644 index 0121e9e6..00000000 --- a/src/gu/dump_gbi.c +++ /dev/null @@ -1,271 +0,0 @@ - -/************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - *************************************************************************/ - -/* - * Interpret Task with GBI display list and dump it for debugging. - */ - -/************************************************** - * - * guDumpGbiDL no longer supported - * applications should use guParseGbiDL with the - * GU_PARSEGBI_DUMPONLY flag set. - * - **************************************************/ - -#if 0 - -#include "ultra64.h" -#include "bstring.h" - -#undef PRINTF -#define PRINTF osSyncPrintf - -#define DL_STACKSIZE 11 -static u32 *Gp[DL_STACKSIZE]; - -#define TX_MAX 100 -static u32 textures[TX_MAX]; -static u32 numtextures; - -static u32 segment_base[16]; -static u32 dotextures = TRUE; -static int dl_depth = 0; - - -/* - * dump a DMA-type display list command. - */ -static void -dump_dma(u32 *bufp) -{ - u32 addr, - *data; - u8 seg_id; - u16 len; - char op, - b0; - - op = ((*bufp & 0xff000000) >> 24); - - /* - * DMA op addressing is all the same: - */ - seg_id = (u8) ((bufp[1] & 0x0f000000) >> 24); - addr = segment_base[seg_id] + (bufp[1] & 0x00ffffff); - - - addr = (u32) osPhysicalToVirtual(addr); - - len = (u16) (bufp[0] & 0x0000ffff); - - PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); - if (op == (char) G_DL) { - b0 = (char) ((bufp[0] & 0x00ff0000) >> 16); - ++dl_depth; - if (dl_depth > (DL_STACKSIZE - 1)) { - PRINTF("***** Error, max levels of display lists exceeded\n"); - return; - } - Gp[dl_depth] = (u32 *) addr; - PRINTF("@ %08x\n",(int)Gp[dl_depth]&0x7fffffff); - } else { - PRINTF("& %08x\n", (int)addr&0x7fffffff); - data = (u32 *) addr; - while(len>0) { - PRINTF("+%08x\n", *data); - data++; - len -= 4; - } - PRINTF("@ %08x\n",(int)(Gp[dl_depth] + (sizeof(Gfx) >> 2))&0x7fffffff); - } -} - -/* - * dump a IMM-type display list command. - */ -static void -dump_imm(u32 *bufp) -{ - char op, - b0; - - op = ((*bufp & 0xff000000) >> 24); - - PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); - if (op == (char) G_ENDDL) { - dl_depth--; - if (dl_depth >= 0) { - PRINTF("@ %08x\n",(int)(Gp[dl_depth] + (sizeof(Gfx) >> 2))&0x7fffffff); - } - } - if (op == (char) G_MOVEWORD) { - if (((bufp[0] ) & 0xff) == G_MW_SEGMENT) { - b0 = (char) ((bufp[0] & 0xff00)>>10); - segment_base[b0] = bufp[1] & 0x00ffffff; - } - } -} - -/* - * dump a RDP-type display list command. - */ -static void -dump_rdp(u32 *bufp) -{ - u8 seg_id; - u32 addr; - int i0, - i1; - char op; - - op = ((*bufp & 0xff000000) >> 24); - - PRINTF(">%08x\n-%08x\n", bufp[0], bufp[1]); - if (op == (char) G_SETTIMG && dotextures) { - if (numtextures>=TX_MAX) { - PRINTF("GBI DUMP ERROR: too many textures (max=%d)\n",TX_MAX); - return; - } - seg_id = (u8) ((bufp[1] & 0x0f000000) >> 24); - addr = segment_base[seg_id] + (bufp[1] & 0x00ffffff); - addr = (u32) osPhysicalToVirtual(addr); - i1=1; - for (i0=0;i0= 0) && (dl_depth < (DL_STACKSIZE - 1))) { - - op = (u8) ((*Gp[dl_depth] & 0xff000000) >> 24); - bcopy((char *) Gp[dl_depth], (char *) &(readBuf[0]), sizeof(Gfx)); - - switch (op & 0xc0) { - - case (u8) 0x00: - dump_dma(readBuf); - break; - - case (u8) 0x80: - dump_imm(readBuf); - break; - - case (u8) 0xc0: - dump_rdp(readBuf); - break; - - default: - PRINTF("ERROR : display list is lost, op = %02x\n", op); - break; - - } - - if (op != (u8) G_DL) { - Gp[dl_depth] += (sizeof(Gfx) >> 2); - } - } - if (dotextures) { - u32 i,j; - for (i=0; it.ucode_boot & 0x7fffffff); - for (i=(int)tp->t.ucode_boot; i<(int)tp->t.ucode_boot+tp->t.ucode_boot_size; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - PRINTF("? %08x\n",(int) tp->t.ucode& 0x7fffffff); - for (i=(int)tp->t.ucode; i<(int)tp->t.ucode+UCODE_SIZE_MAX; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - PRINTF("? %08x\n",(int) tp->t.ucode_data & 0x7fffffff); - for (i=(int)tp->t.ucode_data; i<(int)tp->t.ucode_data+tp->t.ucode_data_size; i+=4) { - PRINTF("|%08x\n",(int) *((u32 *) i)); - } - - - guDumpGbi((u32 *) tp->t.data_ptr); - - - PRINTF("^\nGBI_DUMP_END:\n"); - - if (flags & GU_PARSEGBI_HANGAFTER) { - int i; - for (i=0; i<1000;i++) - PRINTF("=============================================================\n"); - while(1); - } - - -/* - * Dumps stuff - * each line is either an address for data to follow or data itself - * 1st char on line indicates what it is: - * - * $ task header address - * @ display list address - * & dma data address - * % texture address - * ? code/code data address - * - * < task header data - * > 1st half of display list command - * - 2nd half of display list command - * + dma data - * * texture data - * | code/code data - * - */ - -} - -#endif From b78b25d00b317c4ad3bf7ddd0717fc31ca139d38 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:47:31 -0500 Subject: [PATCH 08/16] Remove GIO functions as they're leftover Indy board code --- Makefile | 4 ++ include/PR/os.h | 1 - include/PR/os_gio.h | 81 ------------------------------------ include/PR/os_internal.h | 1 - include/PR/os_internal_gio.h | 44 -------------------- src/gio/giointerrupt.c | 8 ---- src/gio/giorawinterrupt.c | 13 ------ 7 files changed, 4 insertions(+), 148 deletions(-) delete mode 100644 include/PR/os_gio.h delete mode 100644 include/PR/os_internal_gio.h delete mode 100644 src/gio/giointerrupt.c delete mode 100644 src/gio/giorawinterrupt.c diff --git a/Makefile b/Makefile index 8fbe1370..ecc6aebb 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,10 @@ ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS)) # Make sure build directory exists before compiling anything $(shell mkdir -p $(ALL_DIRS)) +ifeq ($(TARGET),libultra_rom) +C_FILES := $(filter-out src/gt/dumpturbo.c,$(C_FILES)) +endif + $(BUILD_DIR)/src/voice/%.o: CFLAGS += -I$(WORKING_DIR)/src/voice $(BUILD_DIR)/src/voice/%.o: DEFINES += LANG_JAPANESE=1 $(BUILD_DIR)/src/gu/parse_gbi.o: GBIDEFINE := -DF3D_GBI diff --git a/include/PR/os.h b/include/PR/os.h index 2ce02f99..1326963c 100644 --- a/include/PR/os.h +++ b/include/PR/os.h @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include diff --git a/include/PR/os_gio.h b/include/PR/os_gio.h deleted file mode 100644 index 9d45bc9c..00000000 --- a/include/PR/os_gio.h +++ /dev/null @@ -1,81 +0,0 @@ - -/*==================================================================== - * os_gio.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_gio.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:08 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_GIO_H_ -#define _OS_GIO_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -/************************************************************************** - * - * Extern variables - * - */ - -/************************************************************************** - * - * Function prototypes - * - */ - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_GIO_H_ */ diff --git a/include/PR/os_internal.h b/include/PR/os_internal.h index 6a2c731d..80795de5 100644 --- a/include/PR/os_internal.h +++ b/include/PR/os_internal.h @@ -35,7 +35,6 @@ extern "C" { #include "os_internal_si.h" #include "os_internal_rsp.h" #include "os_internal_error.h" -#include "os_internal_gio.h" #include "os_internal_thread.h" #include "os_internal_debug.h" #include "os_internal_host.h" diff --git a/include/PR/os_internal_gio.h b/include/PR/os_internal_gio.h deleted file mode 100644 index 3a6d8d84..00000000 --- a/include/PR/os_internal_gio.h +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************************************** - * * - * Copyright (C) 1995, Silicon Graphics, Inc. * - * * - * These coded instructions, statements, and computer programs contain * - * unpublished proprietary information of Silicon Graphics, Inc., and * - * are protected by Federal copyright law. They may not be disclosed * - * to third parties or copied or duplicated in any form, in whole or * - * in part, without the prior written consent of Silicon Graphics, Inc. * - * * - **************************************************************************/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_internal_gio.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:11 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_INTERNAL_GIO_H_ -#define _OS_INTERNAL_GIO_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/* Development board functions */ - -extern void __osGIOInit(s32); -extern void __osGIOInterrupt(s32); -extern void __osGIORawInterrupt(s32); - -#endif /* _LANGUAGE_C */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_INTERNAL_GIO_H */ diff --git a/src/gio/giointerrupt.c b/src/gio/giointerrupt.c deleted file mode 100644 index 121c5d8e..00000000 --- a/src/gio/giointerrupt.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "PR/os_internal.h" -#include "PRinternal/piint.h" - -void __osGIOInterrupt(s32 value) { - __osPiGetAccess(); - __osGIORawInterrupt(value); - __osPiRelAccess(); -} diff --git a/src/gio/giorawinterrupt.c b/src/gio/giorawinterrupt.c deleted file mode 100644 index e36f5ded..00000000 --- a/src/gio/giorawinterrupt.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/rcp.h" -#include "PRinternal/piint.h" - -void __osGIORawInterrupt(s32 value) { - register u32 stat; - - WAIT_ON_IOBUSY(stat); - - IO_WRITE(GIO_GIO_INTR_REG, value); - - WAIT_ON_IOBUSY(stat); -} From d1662979f3f656f13f63ff1259ba130123333340 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 12:48:10 -0500 Subject: [PATCH 09/16] Remove leftover Partner-N64 code --- src/host/host_ptn64.c | 205 ------------------------------------------ 1 file changed, 205 deletions(-) delete mode 100644 src/host/host_ptn64.c diff --git a/src/host/host_ptn64.c b/src/host/host_ptn64.c deleted file mode 100644 index 3d169316..00000000 --- a/src/host/host_ptn64.c +++ /dev/null @@ -1,205 +0,0 @@ -#include "PR/os_internal.h" -#include "PR/os_version.h" -#include "PR/rcp.h" -#include "memory.h" - -#include "PRinternal/macros.h" - -static volatile unsigned int* ptwtmode = (unsigned*)0xbff08014; -static volatile unsigned int* ptstat = (unsigned*)0xbff08004; -static volatile unsigned int* ptport = (unsigned*)0xbff08000; -static volatile unsigned int* n64piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG); - -static OSMesgQueue waitPtQueue ALIGNED(0x8); -static OSMesg waitPtQueueBuf; -static u32 isWaitPtQueueCreated = FALSE; - -void __osPiRelAccess(void); -void __osPiGetAccess(void); - -static void createWaitPtQueue(void) { - osCreateMesgQueue(&waitPtQueue, &waitPtQueueBuf, 1); - isWaitPtQueueCreated = TRUE; -} - -static u32 getPT_wait(void) { - OSTimer waitTimer; - u32 status UNUSED; - - for (;;) { - while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - ; - } - - if (*ptstat & 2) { - return *ptport; - } - __osPiRelAccess(); - - osRecvMesg(&waitPtQueue, NULL, OS_MESG_NOBLOCK); - osSetTimer(&waitTimer, OS_USEC_TO_CYCLES(1000), 0, &waitPtQueue, NULL); - osRecvMesg(&waitPtQueue, NULL, OS_MESG_BLOCK); - - __osPiGetAccess(); - } -} - -static void putPT(u32 c) { - while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - ; - } - while (!(*ptstat & 4)) { - ; - } - *ptport = c; -} - -static u32 getPT(void) { - while (*n64piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { - ; - } - while (!(*ptstat & 2)) { - ; - } - return *ptport; -} - -void osReadHost_pt(void* dramAddr, u32 nbytes) { - u8* tPtr; - u32 buf[256]; - u32* bp; - u32 data; - u32 ct; - u32 ct1; - u32 ct1_bak; - u32 shift; - u32 cmd; - u32 size; - - if (nbytes == 0) { - return; - } - - if (!isWaitPtQueueCreated) { - createWaitPtQueue(); - } - - __osPiGetAccess(); - - putPT(0x82U); - - cmd = getPT_wait(); - - size = getPT(); - - if (cmd != 2) { - nbytes = -1U; - } - - putPT(nbytes); - - if (size != nbytes) { - goto osReadHost_ret; - } - - tPtr = dramAddr; - ct = nbytes / 4; - - while (ct != 0) { - if (ct > 0x100) { - ct1_bak = ct1 = 0x100; - ct -= 0x100; - } else { - ct1_bak = ct1 = ct; - ct = 0; - } - bp = (u32*)&buf; - - while (ct1 != 0) { - *(bp++) = getPT(); - ct1--; - } - - memcpy(tPtr, &buf, ct1_bak * 4); - tPtr += ct1_bak * 4; - } - - nbytes &= 3; - - if (nbytes != 0) { - data = getPT(); - shift = 0x18; - - do { - *(tPtr++) = (data >> shift); - nbytes--; - shift -= 8; - } while (nbytes != 0); - } - -osReadHost_ret: - __osPiRelAccess(); - return; -} - -void osWriteHost_pt(void* dramAddr, u32 nbytes) { - u8* tPtr; - u32 buf[256]; - u32* bp; - u32 ct; - u32 ct1; - u32 ct1_bak; - u32 cmd; - u32 size; - - if (nbytes == 0) { - return; - } - - if (!isWaitPtQueueCreated) { - createWaitPtQueue(); - } - - __osPiGetAccess(); - putPT(0x82); - - cmd = getPT_wait(); - - size = getPT(); - - if (cmd != 3) { - nbytes = -1; - } - - putPT(nbytes); - - if (size != nbytes) { - goto osWriteHost_ret; - } - - tPtr = dramAddr; - ct = (nbytes + 3) >> 2; - - while (ct != 0) { - if (ct > 0x100) { - ct1_bak = ct1 = 0x100; - ct -= 0x100; - } else { - ct1_bak = ct1 = ct; - ct = 0; - } - - memcpy(bp = buf, tPtr, ct1_bak * 4); - - while (ct1 != 0) { - putPT(*(bp++)); - ct1--; - } - - tPtr += ct1_bak * 4; - } - -osWriteHost_ret: - __osPiRelAccess(); - return; -} From 5698e945e18bddafbd82385917419cb3bc996df1 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 13:18:01 -0500 Subject: [PATCH 10/16] Prevent debug code from being included in ROM version --- Makefile | 20 ++++++++++++++++---- src/monutil.s | 41 ----------------------------------------- 2 files changed, 16 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index ecc6aebb..af829003 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,22 @@ SRC_DIRS += $(shell find src -type d) C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s)) + +ifeq ($(TARGET),libultra_rom) +DEBUGCODE := src/gt/dumpturbo.c src/debug/assert.c src/debug/assertbreak.s \ + src/error/errorasm.s src/error/commonerror.c src/log/delay.s \ + src/os/exit.c src/log/logfloat.c src/log/log.c \ + src/gu/parse_gbi.c src/gu/parse_rdp.c src/gu/parse_string.c \ + src/rg/printregion.c src/debug/profile.c src/host/readhost.c \ + src/os/testhost.c src/host/writehost.c src/os/seterrorhandler.c \ + src/debug/threadprofileclear.c src/debug/threadprofileinit.c \ + src/debug/threadprofile.c src/debug/threadprofilereadcount.c \ + src/debug/threadprofilereadtime.c src/debug/threadprofilestart.c \ + src/debug/threadprofilestop.c +C_FILES := $(filter-out $(DEBUGCODE),$(C_FILES)) +S_FILES := $(filter-out $(DEBUGCODE),$(S_FILES)) +endif + # Object files O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \ $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) @@ -146,10 +162,6 @@ ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS)) # Make sure build directory exists before compiling anything $(shell mkdir -p $(ALL_DIRS)) -ifeq ($(TARGET),libultra_rom) -C_FILES := $(filter-out src/gt/dumpturbo.c,$(C_FILES)) -endif - $(BUILD_DIR)/src/voice/%.o: CFLAGS += -I$(WORKING_DIR)/src/voice $(BUILD_DIR)/src/voice/%.o: DEFINES += LANG_JAPANESE=1 $(BUILD_DIR)/src/gu/parse_gbi.o: GBIDEFINE := -DF3D_GBI diff --git a/src/monutil.s b/src/monutil.s index e5974bd8..4112dee1 100644 --- a/src/monutil.s +++ b/src/monutil.s @@ -5,47 +5,6 @@ #include "sgidefs.h" #include "PR/R4300.h" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #define EXC(code) (EXC_##code >> CAUSE_EXCSHIFT) .text From 96480626623561aed1709cb3b57f8de574e24cf0 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 13:18:15 -0500 Subject: [PATCH 11/16] Remove testhost due to being a stub file with nothing in it --- Makefile | 2 +- src/os/testhost.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 src/os/testhost.c diff --git a/Makefile b/Makefile index af829003..011c9d82 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ DEBUGCODE := src/gt/dumpturbo.c src/debug/assert.c src/debug/assertbreak.s \ src/os/exit.c src/log/logfloat.c src/log/log.c \ src/gu/parse_gbi.c src/gu/parse_rdp.c src/gu/parse_string.c \ src/rg/printregion.c src/debug/profile.c src/host/readhost.c \ - src/os/testhost.c src/host/writehost.c src/os/seterrorhandler.c \ + src/host/writehost.c src/os/seterrorhandler.c \ src/debug/threadprofileclear.c src/debug/threadprofileinit.c \ src/debug/threadprofile.c src/debug/threadprofilereadcount.c \ src/debug/threadprofilereadtime.c src/debug/threadprofilestart.c \ diff --git a/src/os/testhost.c b/src/os/testhost.c deleted file mode 100644 index 70514eb9..00000000 --- a/src/os/testhost.c +++ /dev/null @@ -1,4 +0,0 @@ -#include "PR/os_internal.h" - -// TODO: this comes from a header -#ident "$Revision: 1.4 $" From 7035ebc39bc4933009d359d3f327adda0f474d20 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 13:33:37 -0500 Subject: [PATCH 12/16] Remove osExit as it's indy board code useless on non-indy --- include/PR/os_system.h | 1 - src/os/exit.c | 9 --------- 2 files changed, 10 deletions(-) delete mode 100644 src/os/exit.c diff --git a/include/PR/os_system.h b/include/PR/os_system.h index 20e6f130..05cee4ec 100644 --- a/include/PR/os_system.h +++ b/include/PR/os_system.h @@ -98,7 +98,6 @@ extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ */ extern void osInitialize(void); -extern void osExit(void); extern u32 osGetMemSize(void); /* pre-NMI */ diff --git a/src/os/exit.c b/src/os/exit.c deleted file mode 100644 index 05582c5d..00000000 --- a/src/os/exit.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "PR/os_internal.h" - -void osExit(void) { - __osGIOInterrupt(16); - - for (;;) { - ; - } -} From 5e79d246159fe7665a802de605d5c33699643ffa Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 13:33:50 -0500 Subject: [PATCH 13/16] Add ifdef _FINALROM to dumpturbo --- src/gt/dumpturbo.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gt/dumpturbo.c b/src/gt/dumpturbo.c index 08893f1b..e8e3598b 100644 --- a/src/gt/dumpturbo.c +++ b/src/gt/dumpturbo.c @@ -16,6 +16,8 @@ * */ +#ifndef _FINALROM + #include #include #include "PRinternal/macros.h" @@ -220,3 +222,4 @@ void gtDumpTurbo(OSTask* tp, u8 flags) { * */ } +#endif From 5e3f4a45ef8a411c5a771127db278ca39a9b0e93 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 13:47:34 -0500 Subject: [PATCH 14/16] All debug code included in non ROM builds checked and #ifndef _FINALROM added where needed --- Makefile | 16 ---------------- src/debug/threadprofile.c | 2 ++ src/debug/threadprofileclear.c | 1 + src/debug/threadprofileinit.c | 2 ++ src/debug/threadprofilereadcount.c | 2 ++ src/debug/threadprofilereadtime.c | 2 ++ src/debug/threadprofilestart.c | 2 ++ src/debug/threadprofilestop.c | 2 ++ src/os/seterrorhandler.c | 2 ++ 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 011c9d82..8fbe1370 100644 --- a/Makefile +++ b/Makefile @@ -79,22 +79,6 @@ SRC_DIRS += $(shell find src -type d) C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s)) - -ifeq ($(TARGET),libultra_rom) -DEBUGCODE := src/gt/dumpturbo.c src/debug/assert.c src/debug/assertbreak.s \ - src/error/errorasm.s src/error/commonerror.c src/log/delay.s \ - src/os/exit.c src/log/logfloat.c src/log/log.c \ - src/gu/parse_gbi.c src/gu/parse_rdp.c src/gu/parse_string.c \ - src/rg/printregion.c src/debug/profile.c src/host/readhost.c \ - src/host/writehost.c src/os/seterrorhandler.c \ - src/debug/threadprofileclear.c src/debug/threadprofileinit.c \ - src/debug/threadprofile.c src/debug/threadprofilereadcount.c \ - src/debug/threadprofilereadtime.c src/debug/threadprofilestart.c \ - src/debug/threadprofilestop.c -C_FILES := $(filter-out $(DEBUGCODE),$(C_FILES)) -S_FILES := $(filter-out $(DEBUGCODE),$(S_FILES)) -endif - # Object files O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \ $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) diff --git a/src/debug/threadprofile.c b/src/debug/threadprofile.c index 55f1353c..58ed7aff 100644 --- a/src/debug/threadprofile.c +++ b/src/debug/threadprofile.c @@ -1,3 +1,4 @@ +#ifndef _FINALROM #include "osint_debug.h" #include "PRinternal/macros.h" @@ -20,3 +21,4 @@ void osThreadProfileCallback(OSThread* osthread) { __osThprofCount++; __osThprofLastTimer = now_time; } +#endif diff --git a/src/debug/threadprofileclear.c b/src/debug/threadprofileclear.c index 42788f86..0e8eac00 100644 --- a/src/debug/threadprofileclear.c +++ b/src/debug/threadprofileclear.c @@ -9,3 +9,4 @@ void osThreadProfileClear(OSId id) { __osRestoreInt(saveMask); } +#endif \ No newline at end of file diff --git a/src/debug/threadprofileinit.c b/src/debug/threadprofileinit.c index 7fef229b..fef4d1bb 100644 --- a/src/debug/threadprofileinit.c +++ b/src/debug/threadprofileinit.c @@ -1,3 +1,4 @@ +#ifndef _FINALROM #include "osint_debug.h" void osThreadProfileInit(void) { @@ -14,3 +15,4 @@ void osThreadProfileInit(void) { osThreadProfileClear(i); } } +#endif \ No newline at end of file diff --git a/src/debug/threadprofilereadcount.c b/src/debug/threadprofilereadcount.c index 32379879..9bb5683f 100644 --- a/src/debug/threadprofilereadcount.c +++ b/src/debug/threadprofilereadcount.c @@ -1,3 +1,4 @@ +#ifndef _FINALROM #include "osint_debug.h" u32 osThreadProfileReadCount(OSId id) { @@ -37,3 +38,4 @@ u32 osThreadProfileReadCountTh(OSThread* thread) { } return thprof[id].count; } +#endif diff --git a/src/debug/threadprofilereadtime.c b/src/debug/threadprofilereadtime.c index 9930cacd..53125a6a 100644 --- a/src/debug/threadprofilereadtime.c +++ b/src/debug/threadprofilereadtime.c @@ -1,3 +1,4 @@ +#ifndef _FINALROM #include "osint_debug.h" OSTime osThreadProfileReadTime(OSId id) { @@ -49,3 +50,4 @@ OSTime osThreadProfileReadTimeTh(OSThread* thread) { } return thprof[id].time + adjust; } +#endif diff --git a/src/debug/threadprofilestart.c b/src/debug/threadprofilestart.c index 3ef8fa76..683a298c 100644 --- a/src/debug/threadprofilestart.c +++ b/src/debug/threadprofilestart.c @@ -1,4 +1,5 @@ #include "osint_debug.h" +#ifndef _FINALROM void osThreadProfileStart(void) { register u32 saveMask; @@ -20,3 +21,4 @@ void osThreadProfileStart(void) { __osThprofFunc = osThreadProfileCallback; __osRestoreInt(saveMask); } +#endif diff --git a/src/debug/threadprofilestop.c b/src/debug/threadprofilestop.c index 7cc20e7a..779d5ff8 100644 --- a/src/debug/threadprofilestop.c +++ b/src/debug/threadprofilestop.c @@ -1,4 +1,5 @@ #include "osint_debug.h" +#ifndef _FINALROM void osThreadProfileStop(void) { register u32 saveMask; @@ -36,3 +37,4 @@ void osThreadProfileStop(void) { } __osRestoreInt(saveMask); } +#endif \ No newline at end of file diff --git a/src/os/seterrorhandler.c b/src/os/seterrorhandler.c index 4e839e88..d7113e74 100644 --- a/src/os/seterrorhandler.c +++ b/src/os/seterrorhandler.c @@ -1,3 +1,4 @@ +#ifndef _FINALROM #include "PR/ultraerror.h" extern OSErrorHandler __osErrorHandler; @@ -8,3 +9,4 @@ OSErrorHandler osSetErrorHandler(OSErrorHandler handler) { __osErrorHandler = handler; return oldHandler; } +#endif From b981bd732517b5d021b65dd30e9e40de972a490f Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 14:39:32 -0500 Subject: [PATCH 15/16] Add missing ifdef and endlines --- src/debug/threadprofileclear.c | 3 ++- src/debug/threadprofileinit.c | 2 +- src/debug/threadprofilestop.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/debug/threadprofileclear.c b/src/debug/threadprofileclear.c index 0e8eac00..849ba302 100644 --- a/src/debug/threadprofileclear.c +++ b/src/debug/threadprofileclear.c @@ -1,3 +1,4 @@ +#ifndef _FINALROM #include "osint_debug.h" void osThreadProfileClear(OSId id) { @@ -9,4 +10,4 @@ void osThreadProfileClear(OSId id) { __osRestoreInt(saveMask); } -#endif \ No newline at end of file +#endif diff --git a/src/debug/threadprofileinit.c b/src/debug/threadprofileinit.c index fef4d1bb..4c80d7b8 100644 --- a/src/debug/threadprofileinit.c +++ b/src/debug/threadprofileinit.c @@ -15,4 +15,4 @@ void osThreadProfileInit(void) { osThreadProfileClear(i); } } -#endif \ No newline at end of file +#endif diff --git a/src/debug/threadprofilestop.c b/src/debug/threadprofilestop.c index 779d5ff8..4a30f145 100644 --- a/src/debug/threadprofilestop.c +++ b/src/debug/threadprofilestop.c @@ -37,4 +37,4 @@ void osThreadProfileStop(void) { } __osRestoreInt(saveMask); } -#endif \ No newline at end of file +#endif From 6824ae527aca60bfb85ff180ce73abe998207d37 Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Sun, 2 Nov 2025 20:04:02 -0500 Subject: [PATCH 16/16] Restore libleo code (will be taken care of in a seperate PR) --- src/io/driverominit.c | 31 +++++++ src/io/leodiskinit.c | 36 ++++++++ src/io/leointerrupt.c | 195 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 src/io/driverominit.c create mode 100644 src/io/leodiskinit.c create mode 100644 src/io/leointerrupt.c diff --git a/src/io/driverominit.c b/src/io/driverominit.c new file mode 100644 index 00000000..bfa9f76c --- /dev/null +++ b/src/io/driverominit.c @@ -0,0 +1,31 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PRinternal/macros.h" + +OSPiHandle DriveRomHandle ALIGNED(0x8); + +OSPiHandle* osDriveRomInit(void) { + u32 saveMask; + + if (DriveRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR1)) { + return &DriveRomHandle; + } + + DriveRomHandle.type = DEVICE_TYPE_BULK; + DriveRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR1); + DriveRomHandle.latency = 64; + DriveRomHandle.pulse = 7; + DriveRomHandle.pageSize = 7; + DriveRomHandle.relDuration = 2; + DriveRomHandle.domain = PI_DOMAIN1; + DriveRomHandle.speed = 0; + + bzero(&DriveRomHandle.transferInfo, sizeof(__OSTranxInfo)); + + saveMask = __osDisableInt(); + DriveRomHandle.next = __osPiTable; + __osPiTable = &DriveRomHandle; + __osRestoreInt(saveMask); + + return &DriveRomHandle; +} diff --git a/src/io/leodiskinit.c b/src/io/leodiskinit.c new file mode 100644 index 00000000..81c67b9b --- /dev/null +++ b/src/io/leodiskinit.c @@ -0,0 +1,36 @@ +// This file was removed in 2.0J +#include "PR/os_internal.h" +#include "PR/os_libc.h" +#include "PR/rcp.h" +#include "PRinternal/macros.h" + +OSPiHandle LeoDiskHandle ALIGNED(0x8); +OSPiHandle* __osDiskHandle; + +OSPiHandle* osLeoDiskInit(void) { + u32 saveMask; + + LeoDiskHandle.type = DEVICE_TYPE_64DD; + LeoDiskHandle.baseAddress = PHYS_TO_K1(PI_DOM2_ADDR1); + LeoDiskHandle.latency = 3; + LeoDiskHandle.pulse = 6; + LeoDiskHandle.pageSize = 6; + LeoDiskHandle.relDuration = 2; + LeoDiskHandle.domain = PI_DOMAIN2; + + IO_WRITE(PI_BSD_DOM2_LAT_REG, LeoDiskHandle.latency); + IO_WRITE(PI_BSD_DOM2_PWD_REG, LeoDiskHandle.pulse); + IO_WRITE(PI_BSD_DOM2_PGS_REG, LeoDiskHandle.pageSize); + IO_WRITE(PI_BSD_DOM2_RLS_REG, LeoDiskHandle.relDuration); + LeoDiskHandle.speed = 0; + + bzero(&LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo)); + + saveMask = __osDisableInt(); + LeoDiskHandle.next = __osPiTable; + __osPiTable = &LeoDiskHandle; + __osDiskHandle = &LeoDiskHandle; + __osRestoreInt(saveMask); + + return &LeoDiskHandle; +} diff --git a/src/io/leointerrupt.c b/src/io/leointerrupt.c new file mode 100644 index 00000000..651607b4 --- /dev/null +++ b/src/io/leointerrupt.c @@ -0,0 +1,195 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PRinternal/osint.h" +#include "PRinternal/piint.h" +#include "PRinternal/macros.h" + +extern OSPiHandle* __osDiskHandle; + +u8 leoDiskStack[OS_PIM_STACKSIZE] ALIGNED(0x10); + +static void __osLeoAbnormalResume(void); +static void __osLeoResume(void); + +s32 __osLeoInterrupt(void) { + u32 stat = 0; + volatile u32 pi_stat; + u32 bm_stat; + __OSTranxInfo* info = &__osDiskHandle->transferInfo; + __OSBlockInfo* blockInfo = &info->block[info->blockNum]; + + pi_stat = IO_READ(PI_STATUS_REG); + if (pi_stat & PI_STATUS_DMA_BUSY) { + __OSGlobalIntMask = __OSGlobalIntMask & ~SR_IBIT4; // cart interrupt + blockInfo->errStatus = LEO_ERROR_29; + __osLeoResume(); + return 1; + } + + WAIT_ON_IOBUSY(pi_stat); + stat = IO_READ(LEO_STATUS); + if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); + blockInfo->errStatus = LEO_ERROR_GOOD; + return 0; + } + + if (info->cmdType == LEO_CMD_TYPE_2) { + return 1; + } + + if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR) { + WAIT_ON_IOBUSY(pi_stat); + stat = IO_READ(LEO_STATUS); + blockInfo->errStatus = LEO_ERROR_22; + __osLeoResume(); + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + return 1; + } + + if (info->cmdType == LEO_CMD_TYPE_1) { + if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { + if (info->sectorNum + 1 != info->transferMode * 85) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + blockInfo->errStatus = LEO_ERROR_GOOD; + __osLeoResume(); + return 1; + } else { + blockInfo->dramAddr = (void*)((u32)blockInfo->dramAddr + blockInfo->sectorSize); + info->sectorNum++; + __osEPiRawStartDma(__osDiskHandle, OS_WRITE, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); + return 1; + } + } else if (info->cmdType == LEO_CMD_TYPE_0) { + if (info->transferMode == LEO_SECTOR_MODE) { + if (info->sectorNum > (s32)blockInfo->C1ErrNum + 17) { + blockInfo->errStatus = LEO_ERROR_GOOD; + __osLeoAbnormalResume(); + return 1; + } + + if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { + blockInfo->errStatus = LEO_ERROR_23; + __osLeoAbnormalResume(); + return 1; + } + } else { + blockInfo->dramAddr = (void*)((u32)blockInfo->dramAddr + blockInfo->sectorSize); + } + + bm_stat = IO_READ(LEO_BM_STATUS); + if ((bm_stat & LEO_BM_STATUS_C1SINGLE && bm_stat & LEO_BM_STATUS_C1DOUBLE) || bm_stat & LEO_BM_STATUS_MICRO) { + if (blockInfo->C1ErrNum > 3) { + if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52) { + blockInfo->errStatus = LEO_ERROR_23; + __osLeoAbnormalResume(); + return 1; + } + } else { + int errNum = blockInfo->C1ErrNum; + blockInfo->C1ErrSector[errNum] = info->sectorNum + 1; + } + + blockInfo->C1ErrNum++; + } + + if (stat & LEO_STATUS_C2_TRANSFER) { + if (info->sectorNum + 1 != 88) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + } + + if (info->transferMode == LEO_TRACK_MODE && info->blockNum == 0) { + info->blockNum = 1; + info->sectorNum = -1; + info->block[1].dramAddr = (void*)((u32)info->block[1].dramAddr - info->block[1].sectorSize); + + blockInfo->errStatus = LEO_ERROR_22; + } else { + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; + info->cmdType = LEO_CMD_TYPE_2; + blockInfo->errStatus = LEO_ERROR_GOOD; + } + + __osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4); + return 1; + } + + if (info->sectorNum == -1 && info->transferMode == LEO_TRACK_MODE && info->blockNum == 1) { + __OSBlockInfo* bptr = &info->block[0]; + if (bptr->C1ErrNum == 0) { + if (((u32*)bptr->C2Addr)[0] | ((u32*)bptr->C2Addr)[1] | ((u32*)bptr->C2Addr)[2] + | ((u32*)bptr->C2Addr)[3]) { + bptr->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + } + + bptr->errStatus = 0; + __osLeoResume(); + } + info->sectorNum++; + if (stat & LEO_STATUS_DATA_REQUEST) { + if (info->sectorNum > 0x54) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + __osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); + blockInfo->errStatus = LEO_ERROR_GOOD; + return 1; + } else if (info->sectorNum <= 0x54) { + blockInfo->errStatus = LEO_ERROR_24; + __osLeoAbnormalResume(); + return 1; + } + + return 1; + } else { + blockInfo->errStatus = LEO_ERROR_4; + __osLeoAbnormalResume(); + return 1; + } +} + +static void __osLeoAbnormalResume(void) { + __OSTranxInfo* info = &__osDiskHandle->transferInfo; + u32 pi_stat; + + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); + WAIT_ON_IOBUSY(pi_stat); + IO_WRITE(LEO_BM_CTL, info->bmCtlShadow); + __osLeoResume(); + IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); + __OSGlobalIntMask |= OS_IM_PI; +} + +static void __osLeoResume(void) { + __OSEventState* es = &__osEventStateTab[OS_EVENT_PI]; + OSMesgQueue* mq = es->messageQueue; + s32 last; + + if (mq == NULL || MQ_IS_FULL(mq)) { + return; + } + + last = (mq->first + mq->validCount) % mq->msgCount; + mq->msg[last] = es->message; + mq->validCount++; + + if (mq->mtqueue->next != NULL) { + __osEnqueueThread(&__osRunQueue, __osPopThread(&mq->mtqueue)); + } +}