Reactivate Assert Functionality, make ISV the only canon debug hardware (#12)

* add assertf; reactivate assertBreak

* newline after user crafted fmt string

* assertf implemented; EX cond fixed

* format

* make ISV the only initialize for now

* force initialize to 'autodetect'

* fix assertf with only format str

* format

---------

Co-authored-by: someone2639 <someone2639@gmail.com>
This commit is contained in:
someone2639
2025-08-23 17:41:37 -04:00
committed by GitHub
parent 4029179754
commit dba3265aac
8 changed files with 40 additions and 455 deletions

View File

@@ -69,59 +69,13 @@ extern void __osInitialize_common(void);
#else
/* PARTNER-N64 */
#if defined(PTN64)
extern void __osInitialize_kmc(void);
#define osReadHost osReadHost_pt
#define osWriteHost osWriteHost_pt
#define osInitialize() \
{ \
__osInitialize_common(); \
__osInitialize_kmc(); \
}
/* MONEGI SMART PACK A */
#elif defined(MWN64)
extern void __osInitialize_msp(void);
#define osReadHost osReadHost_pt
#define osWriteHost osWriteHost_pt
#define osInitialize() \
{ \
__osInitialize_common(); \
__osInitialize_msp(); \
}
/* IS-Viewer(for Debugger) */
#elif defined(ISV64)
extern void __osInitialize_isv(void);
#define osInitialize() \
{ \
__osInitialize_common(); \
__osInitialize_isv(); \
}
/* Emulation board for INDY */
#elif defined(EMU64)
extern void __osInitialize_emu(void);
#define osInitialize() \
{ \
__osInitialize_common(); \
__osInitialize_emu(); \
}
#else
/* Default (auto detect) */
extern void __osInitialize_autodetect(void);
extern void __osInitialize_msp(void);
extern void __osInitialize_kmc(void);
extern void __osInitialize_isv(void);
extern void __osInitialize_emu(void);
#define osInitialize() \
{ \
__osInitialize_common(); \
__osInitialize_autodetect(); \
}
#endif
#endif /* _FINAL_ROM */

View File

@@ -6,7 +6,9 @@
#define assert(EX) ((void)0)
#else
extern void __assert(const char*, const char*, int);
#define assert(EX) ((EX) ? ((void)0) : __assert("EX", __FILE__, __LINE__))
extern void __assertf(const char* exp, const char* filename, int line, const char* fmt, ...);
#define assert(EX) ((EX) ? ((void)0) : __assert(#EX, __FILE__, __LINE__))
#define assertf(EX, fmt, ...) ((EX) ? ((void)0) : __assertf(#EX, __FILE__, __LINE__, fmt, ##__VA_ARGS__))
#endif /* NDEBUG */
#endif /* !__ASSERT_H__ */

View File

@@ -1,12 +1,28 @@
#include "os.h"
#include "PRinternal/osint.h"
#include "osint_debug.h"
#include <stdarg.h>
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
__assertBreak();
#endif
}
void __assertf(const char* exp, const char* filename, int line, const char* fmt, ...) {
#ifndef _FINALROM
va_list args;
va_start(args, fmt);
osSyncPrintf("\nASSERTION FAULT: %s, %d: \"%s\"\n", filename, line, exp);
osSyncPrintf(fmt, args);
osSyncPrintf("\n");
va_end(args);
__assertBreak(); // Doesn't actually do anything, but is needed for matching
#endif
}

View File

@@ -96,14 +96,6 @@ void INITIALIZE_FUNC() {
void __osInitialize_autodetect(void) {
#ifndef _FINALROM
if (__checkHardware_msp()) {
__osInitialize_msp();
} else if (__checkHardware_kmc()) {
__osInitialize_kmc();
} else if (__checkHardware_isv()) {
__osInitialize_isv();
} else {
__osInitialize_emu();
}
__osInitialize_isv();
#endif
}

View File

@@ -1,28 +0,0 @@
#ifndef _FINALROM
#include "stdlib.h"
#include "PR/os_internal.h"
#include "PR/rdb.h"
#include "PRinternal/osint.h"
typedef struct {
/* 0x0 */ unsigned int inst1;
/* 0x4 */ unsigned int inst2;
/* 0x8 */ unsigned int inst3;
/* 0xC */ unsigned int inst4;
} __osExceptionVector;
static void* proutSyncPrintf(void* str, const char* buf, size_t n) {
size_t sent = 0;
while (sent < n) {
sent += __osRdbSend(buf + sent, n - sent, RDB_TYPE_GtoH_PRINT);
}
return 1;
}
void __osInitialize_emu(void) {
__printfunc = proutSyncPrintf;
}
#endif

View File

@@ -25,12 +25,12 @@ void MonitorInitBreak(void);
#define ISV_BUFFER_LEN (0x10000 - 0x20)
#define IS64_MAGIC 'IS64'
#define IS64_MAGIC 0x49533634 // 'IS64'
__osExceptionVector ramOldVector ALIGNED(0x8);
u32 gISVFlag;
u16 gISVChk;
u32 gISVDbgPrnAdrs;
u32 gISVDbgPrnAdrs = 0x13FF0000;
u32 leoComuBuffAdd;
static OSPiHandle* is_Handle;
@@ -97,78 +97,31 @@ static void* is_proutSyncPrintf(void* arg, const u8* str, u32 count) {
return 1;
}
int __checkHardware_isv(void) {
u32 i = 0;
u32 data;
u32 save[4];
OSPiHandle* hnd = osCartRomInit();
gISVDbgPrnAdrs = 0;
leoComuBuffAdd = 0;
gISVFlag = IS64_MAGIC;
gISVChk = 0;
for (i = 0; i < 4; i++) {
osEPiReadIo(hnd, 0xB0000100 + i * 4, &save[i]);
}
#ifndef __GNU__ // BUG: data is used uninitialized for GCC
data = 0;
#endif
osEPiWriteIo(hnd, 0xB000010C, data);
data = IS64_MAGIC;
osEPiWriteIo(hnd, 0xB0000100, IS64_MAGIC);
for (i = 0; i < 0x20000; i++) {
osEPiReadIo(hnd, 0xB000010C, &data);
if (data == IS64_MAGIC) {
data = 0;
osEPiWriteIo(hnd, 0xB0000100, data);
gISVChk |= 1;
osEPiReadIo(hnd, 0xB0000104, &gISVDbgPrnAdrs);
osEPiReadIo(hnd, 0xB0000108, &leoComuBuffAdd);
break;
}
}
for (i = 0; i < 4; i++) {
osEPiWriteIo(hnd, 0xB0000100 + i * 4, save[i]);
}
osEPiReadIo(hnd, 0xBFF00000, &data);
gISVChk |= ((data == IS64_MAGIC) ? 2 : 0);
return (gISVChk != 0) ? TRUE : FALSE;
}
void __osInitialize_isv(void) {
void (*fn)(void);
OSPiHandle* hnd;
s32 pad;
s32 pad2;
if (gISVFlag == IS64_MAGIC || __checkHardware_isv()) {
if (gISVDbgPrnAdrs != 0) {
__printfunc = is_proutSyncPrintf;
isPrintfInit();
}
if (gISVChk & 2) {
hnd = osCartRomInit();
if (gISVDbgPrnAdrs != 0) {
__printfunc = is_proutSyncPrintf;
isPrintfInit();
}
if (gISVChk & 2) {
hnd = osCartRomInit();
ramOldVector = *(__osExceptionVector*)E_VEC;
*(__osExceptionVector*)E_VEC = __isExpJP;
ramOldVector = *(__osExceptionVector*)E_VEC;
*(__osExceptionVector*)E_VEC = __isExpJP;
osWritebackDCache(&ramOldVector, 0x10);
osInvalICache(&ramOldVector, 0x10);
osWritebackDCache(0x80000000, 0x190);
osInvalICache(0x80000000, 0x190);
osEPiReadIo(hnd, 0xBFF00010, (u32*)&fn);
fn();
}
if (gISVChk & 2) {
MonitorInitBreak();
}
osWritebackDCache(&ramOldVector, 0x10);
osInvalICache(&ramOldVector, 0x10);
osWritebackDCache(0x80000000, 0x190);
osInvalICache(0x80000000, 0x190);
osEPiReadIo(hnd, 0xBFF00010, (u32*)&fn);
fn();
}
if (gISVChk & 2) {
MonitorInitBreak();
}
}

View File

@@ -1,152 +0,0 @@
#ifndef _FINALROM
#include "PR/os_internal.h"
#include "PR/rcp.h"
#include "PRinternal/osint.h"
typedef struct {
/* 0x0 */ unsigned int inst1;
/* 0x4 */ unsigned int inst2;
/* 0x8 */ unsigned int inst3;
/* 0xC */ unsigned int inst4;
} __osExceptionVector;
extern __osExceptionVector __ptExceptionPreamble[];
static volatile unsigned int* stat = (unsigned*)0xbff08004;
static volatile unsigned int* wport = (unsigned*)0xbff08000;
static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG);
static void rmonPutchar(char c) {
u32 data;
while (TRUE) {
osPiReadIo(stat, &data);
if (data & 4) {
osPiWriteIo(wport, c);
break;
}
}
}
static void* kmc_proutSyncPrintf(void* str, const char* buf, int n) {
int i;
char c;
char* p;
char* q;
char xbuf[128];
static int column = 0;
p = &xbuf;
for (i = 0; i < n; i++) {
c = *buf++;
switch (c) {
case '\n':
*p++ = '\n';
column = 0;
break;
case '\t':
do {
*p++ = ' ';
} while (++column % 8);
break;
default:
column++;
*p++ = c;
break;
}
if (c == '\n' || (p - xbuf) > 100) {
rmonPutchar((p - xbuf) - 1);
q = xbuf;
while (q != p) {
rmonPutchar(*q++);
}
p = xbuf;
}
}
if (p != xbuf) {
rmonPutchar((p - xbuf) - 1);
q = xbuf;
while (q != p) {
rmonPutchar(*q++);
}
}
return (void*)1;
}
extern u32 __kmc_pt_mode;
void __osInitialize_kmc(void) {
if (!__kmc_pt_mode) {
int (*fnc)();
unsigned int* src;
unsigned int* dst;
unsigned int monadr;
volatile unsigned int* mon;
volatile unsigned int* stat;
stat = (unsigned*)0xbff08004;
mon = (unsigned*)0xBFF00000;
if (*mon != 0x4B4D4300) {
return;
}
src = (unsigned*)__ptExceptionPreamble;
dst = (unsigned*)E_VEC;
*dst++ = *src++;
*dst++ = *src++;
*dst++ = *src++;
src += 2;
dst += 2;
*dst++ = *src++;
*dst++ = *src++;
*dst++ = *src++;
osWritebackDCache(E_VEC, 0x24);
osInvalICache(E_VEC, 0x24);
__kmc_pt_mode = TRUE;
if ((*stat & 0x10) == 0) {
monadr = *(mon + 1);
if (monadr != 0xBFF00000) {
unsigned int* src;
unsigned int* dst = monadr | 0x20000000;
unsigned int ct = 0x2000 / 4;
src = 0xBFF00000;
while (ct != 0) {
*dst++ = *src++;
ct--;
}
}
fnc = monadr + 8;
fnc(0x4B4D4300, 0);
}
__printfunc = kmc_proutSyncPrintf;
}
}
int __checkHardware_kmc(void) {
volatile unsigned int* mon = (unsigned*)0xBFF00000;
if (*mon == 0x4B4D4300) {
mon = (unsigned*)0xBFF00010;
if (*mon == 0xB0FFB000) {
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
}
#endif

View File

@@ -1,152 +0,0 @@
#ifndef _FINALROM
#include "PR/os_internal.h"
#include "PR/rcp.h"
#include "PRinternal/osint.h"
typedef struct {
/* 0x0 */ unsigned int inst1;
/* 0x4 */ unsigned int inst2;
/* 0x8 */ unsigned int inst3;
/* 0xC */ unsigned int inst4;
} __osExceptionVector;
extern __osExceptionVector __ptExceptionPreamble[];
static volatile unsigned int* stat = (unsigned*)0xbff08004;
static volatile unsigned int* wport = (unsigned*)0xbff08000;
static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG);
static void rmonPutchar(char c) {
u32 data;
while (TRUE) {
osPiReadIo(stat, &data);
if (data & 4) {
osPiWriteIo(wport, c);
break;
}
}
}
static void* msp_proutSyncPrintf(void* str, const char* buf, int n) {
int i;
char c;
char* p;
char* q;
char xbuf[128];
static int column = 0;
p = &xbuf;
for (i = 0; i < n; i++) {
c = *buf++;
switch (c) {
case '\n':
*p++ = '\n';
column = 0;
break;
case '\t':
do {
*p++ = ' ';
} while (++column % 8);
break;
default:
column++;
*p++ = c;
break;
}
if (c == '\n' || (p - xbuf) > 100) {
rmonPutchar((p - xbuf) - 1);
q = xbuf;
while (q != p) {
rmonPutchar(*q++);
}
p = xbuf;
}
}
if (p != xbuf) {
rmonPutchar((p - xbuf) - 1);
q = xbuf;
while (q != p) {
rmonPutchar(*q++);
}
}
return (void*)1;
}
extern u32 __kmc_pt_mode;
void __osInitialize_msp(void) {
if (!__kmc_pt_mode) {
int (*fnc)();
unsigned int* src;
unsigned int* dst;
unsigned int monadr;
volatile unsigned int* mon;
volatile unsigned int* stat;
stat = (unsigned*)0xbff08004;
mon = (unsigned*)0xBFF00000;
if (*mon != 0x4B4D4300) {
return;
}
src = (unsigned*)__ptExceptionPreamble;
dst = (unsigned*)E_VEC;
*dst++ = *src++;
*dst++ = *src++;
*dst++ = *src++;
src += 2;
dst += 2;
*dst++ = *src++;
*dst++ = *src++;
*dst++ = *src++;
osWritebackDCache(E_VEC, 0x24);
osInvalICache(E_VEC, 0x24);
__kmc_pt_mode = TRUE;
if ((*stat & 0x10) == 0) {
monadr = *(mon + 1);
if (monadr != 0xBFF00000) {
unsigned int* src;
unsigned int* dst = monadr | 0x20000000;
unsigned int ct = 0x2000 / 4;
src = 0xBFF00000;
while (ct != 0) {
*dst++ = *src++;
ct--;
}
}
fnc = monadr + 8;
fnc(0x4B4D4300, 0);
}
__printfunc = msp_proutSyncPrintf;
}
}
int __checkHardware_msp(void) {
volatile unsigned int* mon = (unsigned*)0xBFF00000;
if (*mon == 0x4B4D4300) {
mon = (unsigned*)0xBFF00010;
if (*mon == 0) {
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
}
#endif