diff --git a/Makefile b/Makefile index 95df9b9e..a394a9d9 100644 --- a/Makefile +++ b/Makefile @@ -151,6 +151,8 @@ $(DTK_FILES): MWCC_VERSION := 1.2.5 $(DTK_FILES): CFLAGS := $(CFLAGS_BASE) $(SI_FILES): MWCC_VERSION := 1.2.5 $(SI_FILES): CFLAGS := $(CFLAGS_BASE) +$(DB_FILES): MWCC_VERSION := 1.2.5 +$(DB_FILES): CFLAGS := $(CFLAGS_BASE) #------------------------------------------------------------------------------- # Recipes diff --git a/configure.py b/configure.py index 1633d7ca..4b21e220 100755 --- a/configure.py +++ b/configure.py @@ -731,7 +731,9 @@ LIBS = [ "lib": "db", "mwcc_version": "1.2.5", "cflags": "$cflags_base", - "objects": ["Dolphin/db"], + "objects": [ + ["Dolphin/db", True], + ], }, { "lib": "dsp", diff --git a/include/dolphin/db.h b/include/dolphin/db.h index ac8c0856..5372190f 100644 --- a/include/dolphin/db.h +++ b/include/dolphin/db.h @@ -7,18 +7,17 @@ extern "C" { #endif -#define ExceptionHookDestination 0x80000048 -#define IsDebuggerPresent 0x80000040 +#define OS_DBINTERFACE_ADDR 0x00000040 -// static int __DBInterface; +typedef struct DBInterface +{ + u32 bPresent; + u32 exceptionMask; + void (*ExceptionDestination) ( void ); + void *exceptionReturn; +} DBInterface; -struct DBInterface { - u8 filler0[4]; - u32 unk4; -}; - -static struct DBInterface* __DBInterface; -static int DBVerbose; +extern DBInterface* __DBInterface; void DBInit(void); void DBInitComm(int* inputFlagPtr, int* mtrCallback); diff --git a/obj_files.mk b/obj_files.mk index 7be3d54a..2c715453 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -643,7 +643,7 @@ BASE_FILES :=\ $(BUILD_DIR)/src/Dolphin/PPCArch.o\ DB_FILES :=\ - $(BUILD_DIR)/asm/Dolphin/db.o\ + $(BUILD_DIR)/src/Dolphin/db.ep.o\ DSP_FILES :=\ $(BUILD_DIR)/asm/Dolphin/dsp/dsp.o\ diff --git a/src/Dolphin/db.c b/src/Dolphin/db.c new file mode 100644 index 00000000..bcf8534d --- /dev/null +++ b/src/Dolphin/db.c @@ -0,0 +1,43 @@ +#include +#include + +DBInterface* __DBInterface = NULL; +int DBVerbose; + +extern void __DBExceptionStart(); +extern void __DBExceptionEnd(); +extern void __DBExceptionSetNumber(); + +void DBInit(void) { + __DBInterface = (DBInterface*)OSPhysicalToCached(OS_DBINTERFACE_ADDR); + __DBInterface->ExceptionDestination = (void (*)())OSCachedToPhysical(__DBExceptionDestination); + DBVerbose = TRUE; +} + +void __DBExceptionDestinationAux(void) { + u32* contextAddr = (void*)0x00C0; + OSContext* context = (OSContext*)OSPhysicalToCached(*contextAddr); + + OSReport("DBExceptionDestination\n"); + OSDumpContext(context); + PPCHalt(); +} + +/* clang-format off */ +asm void __DBExceptionDestination(void) { + nofralloc + mfmsr r3 + ori r3, r3, 0x10|0x20 + mtmsr r3 + + b __DBExceptionDestinationAux +} +/* clang-format on */ + +BOOL __DBIsExceptionMarked(__OSException exception) { + u32 mask = 1 << exception; + + return (BOOL)(__DBInterface->exceptionMask & mask); +} + +void DBPrintf(char* format, ...) {}