From b632aa8c3d3497db4f67898248e1c7ea525eea87 Mon Sep 17 00:00:00 2001 From: a Date: Mon, 14 Jul 2025 22:36:09 -0400 Subject: [PATCH] Add libultra error handling as an assert --- lib/hackerlibultra/Makefile | 2 +- lib/hackerlibultra/src/debug/assert.c | 2 -- lib/hackerlibultra/src/debug/assertbreak.s | 2 -- lib/hackerlibultra/src/error/commonerror.c | 10 ++++++---- lib/hackerlibultra/src/error/errorasm.s | 2 -- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/hackerlibultra/Makefile b/lib/hackerlibultra/Makefile index d6d6857f..a5067347 100644 --- a/lib/hackerlibultra/Makefile +++ b/lib/hackerlibultra/Makefile @@ -44,7 +44,7 @@ WARNINGS += -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-implicit-fu CFLAGS := -std=gnu23 -G 0 -c -fno-inline -nostdinc -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-PIC -fno-common -ffreestanding -fbuiltin -fno-builtin-sinf -fno-builtin-cosf -funsigned-char $(WARNINGS) CFLAGS += -fno-strict-aliasing # TODO: Try adjusting code to remove this ASFLAGS := -w -nostdinc -c -G 0 -march=vr4300 -mabi=32 -mgp32 -mfp32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64 -CPPFLAGS = -DMODERN_CC -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG) +CPPFLAGS = -DMODERN_CC -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG) -D_DEBUG IINC = -I . -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/compiler/modern_gcc -I $(WORKING_DIR)/include/PR MIPS_VERSION := -mips3 ASOPTFLAGS := diff --git a/lib/hackerlibultra/src/debug/assert.c b/lib/hackerlibultra/src/debug/assert.c index ffdb5eee..9cdb77b6 100644 --- a/lib/hackerlibultra/src/debug/assert.c +++ b/lib/hackerlibultra/src/debug/assert.c @@ -5,8 +5,6 @@ void __assertBreak(void); void __assert(const char* exp, const char* filename, int line) { -#ifndef _FINALROM osSyncPrintf("\nASSERTION FAULT: %s, %d: \"%s\"\n", filename, line, exp); __assertBreak; // Doesn't actually do anything, but is needed for matching -#endif } diff --git a/lib/hackerlibultra/src/debug/assertbreak.s b/lib/hackerlibultra/src/debug/assertbreak.s index 69de71d9..eec7fb5a 100644 --- a/lib/hackerlibultra/src/debug/assertbreak.s +++ b/lib/hackerlibultra/src/debug/assertbreak.s @@ -1,6 +1,5 @@ #include "PR/os_version.h" -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J #include "sys/asm.h" #include "sys/regdef.h" @@ -11,4 +10,3 @@ LEAF(__assertBreak) j ra END(__assertBreak) -#endif diff --git a/lib/hackerlibultra/src/error/commonerror.c b/lib/hackerlibultra/src/error/commonerror.c index 3ed2de96..f3443052 100644 --- a/lib/hackerlibultra/src/error/commonerror.c +++ b/lib/hackerlibultra/src/error/commonerror.c @@ -6,8 +6,6 @@ #include "PRinternal/macros.h" #include "stdarg.h" -#ifndef _FINALROM - void __osSyncVPrintf(const char* fmt, va_list args); static u32 errorLogData[19] ALIGNED(0x8); @@ -23,6 +21,8 @@ static void __commonErrorHandler(s16 code, s16 numArgs, ...); OSErrorHandler __osCommonHandler = __commonErrorHandler; char NULSTR[] = ""; +extern char *assertMsg; +static char errorFmt[256]; const char* __os_error_message[] = { NULSTR, @@ -183,11 +183,13 @@ void __commonErrorHandler(s16 code, s16 numArgs, ...) { fmt = __os_error_message[code]; va_start(argPtr, numArgs); + sprintf(errorFmt, fmt, argPtr); + assertMsg = &errorFmt[0]; + osSyncPrintf("0x%08X (%04d):", osGetCount(), code); __osSyncVPrintf(fmt, argPtr); osSyncPrintf("\n"); va_end(argPtr); + __builtin_trap(); } - -#endif diff --git a/lib/hackerlibultra/src/error/errorasm.s b/lib/hackerlibultra/src/error/errorasm.s index c41cf6d4..0448fa5f 100644 --- a/lib/hackerlibultra/src/error/errorasm.s +++ b/lib/hackerlibultra/src/error/errorasm.s @@ -1,6 +1,5 @@ #include "PR/os_version.h" -#if !defined(_FINALROM) || BUILD_VERSION < VERSION_J #include "sys/asm.h" #include "sys/regdef.h" #include "PR/os_version.h" @@ -30,4 +29,3 @@ _kmc_mode: j ra END(__osError) -#endif