From bcebb21d48cce9cd9e3aa6f1b784907da91189ee Mon Sep 17 00:00:00 2001 From: Prakxo Date: Tue, 14 Mar 2023 08:36:15 +0000 Subject: [PATCH] more asset preparation --- config/dol_slices.yml | 12 ++++ configure.py | 8 ++- include/MSL_C/printf.h | 11 ++++ include/dolphin/os.h | 8 +-- include/dolphin/os/OSInterrupt.h | 13 ++++ include/dolphin/os/OSRtc.h | 9 +++ include/libforest/batconfig.h | 2 +- include/libforest/fault.h | 2 +- include/libforest/osreport.h | 19 ++++++ src/dolphin/os/OSAlarm.c | 1 + src/dolphin/os/OSContext.c | 2 + src/dolphin/os/OSDisableInterrupts.c | 2 +- src/libforest/osreport.c | 88 ++++++++++++++++++++++++++++ src/version.c | 8 +++ 14 files changed, 174 insertions(+), 11 deletions(-) create mode 100644 include/MSL_C/printf.h create mode 100644 include/dolphin/os/OSInterrupt.h create mode 100644 include/dolphin/os/OSRtc.h create mode 100644 include/libforest/osreport.h create mode 100644 src/libforest/osreport.c create mode 100644 src/version.c diff --git a/config/dol_slices.yml b/config/dol_slices.yml index d39a09d9..ca0e8ff6 100644 --- a/config/dol_slices.yml +++ b/config/dol_slices.yml @@ -9,11 +9,23 @@ TRK/mem_TRK.c: .init: [0x800034e0, 0x80003534] asm/__exception.s: .init: [0x80003534, 0x80005468] +version.c: + .data: [0x800b05e8, 0x800b0608] jaudio_NES/dummyprobe.c: .text: [0x800083f8, 0x80008400] #jaudio_NES/verysimple.c: # .text: [0x80008400, 0x80008480] # .sdata: [0x80217b80, 0x80217b88] +#libforest/osreport.c: //see why it doesn't match +# .text: [0x8005a654, 0x8005a92c] +# .data: [0x800dc6d8, 0x800dc738] +# .bss: [0x80206f08, 0x80206f20] +# .sbss: [0x80218618, 0x80218628] +#libforest/fault.c: +# .text: [0x8005a92c, 0x8005adac] +# .data: [0x800dc738, 0x800dc7c8] +# .bss: [0x80206f20, 0x80206f30] +# .sbss: [0x80218628, 0x80218630] libforest/ReconfigBATs.c: .text: [0x8005adac, 0x8005aed4] #libu64/debug.c: //not match diff --git a/configure.py b/configure.py index 30329a4d..b7597ea1 100644 --- a/configure.py +++ b/configure.py @@ -256,8 +256,12 @@ class Asset: def dump(self): print(f"Ripping {self.path} from main.dol") os.system( - f"{PYTHON} {c.PPCDIS}/assetrip.py {c.DOL_YML} 0x{self.start:x} {self.end:x} {c.ASSETS}/{self.path}") - + f"{PYTHON} {c.PPCDIS}/assetrip.py {c.DOL_YML} 0x{self.start:x} {self.end:x} {c.ASSETS}/{self.path}" + ) + print(f"Converting {self.path} from main.dol") + os.system( + f"{PYTHON} {c.PPCDIS}/assetinc.py {c.ASSETS}/{self.path} {c.ASSETS}/{self.path}.inc" + ) assets = Asset.load(c.ASSETS_YML) diff --git a/include/MSL_C/printf.h b/include/MSL_C/printf.h new file mode 100644 index 00000000..5b421ff5 --- /dev/null +++ b/include/MSL_C/printf.h @@ -0,0 +1,11 @@ +#ifndef MSL_PRINTF_H +#define MSL_PRINTF_H + +#include "types.h" +#include "va_args.h" + + +void vprintf(const char*, va_list); +void print(const char*, ...); + +#endif \ No newline at end of file diff --git a/include/dolphin/os.h b/include/dolphin/os.h index bb2f1e0f..ced9df20 100644 --- a/include/dolphin/os.h +++ b/include/dolphin/os.h @@ -24,15 +24,11 @@ extern void __OSCacheInit(); #define OSErrorLine(line, ...) \ OSPanic(__FILE__, line, __VA_ARGS__) -asm BOOL OSDisableInterrupts(void); -asm BOOL OSEnableInterrupts(void); -asm BOOL OSRestoreInterrupts(BOOL level); - -void __RAS_OSDisableInterrupts_begin(void); -void __RAS_OSDisableInterrupts_end(void); void OSResetSystem(u32, u32, u32); // goes in reset, but eh void OSInit(void); + + typedef void (*OSExceptionHandler)(u8, OSContext*); OSExceptionHandler __OSSetExceptionHandler(u8, OSExceptionHandler); diff --git a/include/dolphin/os/OSInterrupt.h b/include/dolphin/os/OSInterrupt.h new file mode 100644 index 00000000..d9c3011a --- /dev/null +++ b/include/dolphin/os/OSInterrupt.h @@ -0,0 +1,13 @@ +#ifndef OS_INTERRUPT_H +#define OS_INTERRUPT_H +#include "types.h" + + +BOOL OSDisableInterrupts(void); +BOOL OSEnableInterrupts(void); +BOOL OSRestoreInterrupts(BOOL status); + +void __RAS_OSDisableInterrupts_begin(void); +void __RAS_OSDisableInterrupts_end(void); + +#endif \ No newline at end of file diff --git a/include/dolphin/os/OSRtc.h b/include/dolphin/os/OSRtc.h new file mode 100644 index 00000000..9c0912c3 --- /dev/null +++ b/include/dolphin/os/OSRtc.h @@ -0,0 +1,9 @@ +#ifndef OS_RTC_H +#define OS_RTC_H + +#include "types.h" + +u32 __OSSyncSram(void); +void __OSSetBootMode(u8); + +#endif \ No newline at end of file diff --git a/include/libforest/batconfig.h b/include/libforest/batconfig.h index 0c47e12f..732a494a 100644 --- a/include/libforest/batconfig.h +++ b/include/libforest/batconfig.h @@ -3,7 +3,7 @@ #include "types.h" #include "dolphin/os/OSMemory.h" -#include "dolphin/os.h" +#include "dolphin/os/OSInterrupt.h" asm void Config24MB(); asm void Config48MB(); diff --git a/include/libforest/fault.h b/include/libforest/fault.h index 0e0e8cb3..6bd6cd82 100644 --- a/include/libforest/fault.h +++ b/include/libforest/fault.h @@ -1,7 +1,7 @@ #ifndef FAULT_H #define FAULT_H #include "types.h" -#include "dolphin/OS/os.h" +#include "dolphin/os/OSInterrupt.h" #include "libultra/libultra.h" diff --git a/include/libforest/osreport.h b/include/libforest/osreport.h new file mode 100644 index 00000000..8506708a --- /dev/null +++ b/include/libforest/osreport.h @@ -0,0 +1,19 @@ +#ifndef LIB_OS_REPORT_H +#define LIB_OS_REPORT_H + +#include "types.h" +#include "va_args.h" + +void OSReportDisable(void); +void OSReportEnable(void); + +void OSVReport(const char*, va_list); + +void OSReport(const char*,...); +void OSPanic(const char*, u32, const char*,...); + +void OSChangeBootMode(u32); + +void OSDVDFatalError(void); + +#endif \ No newline at end of file diff --git a/src/dolphin/os/OSAlarm.c b/src/dolphin/os/OSAlarm.c index 9bef3f42..8efaf5d5 100644 --- a/src/dolphin/os/OSAlarm.c +++ b/src/dolphin/os/OSAlarm.c @@ -1,6 +1,7 @@ #include "dolphin/os/OSAlarm.h" #include "dolphin/os/OSTime.h" #include "dolphin/os/OSContext.h" +#include "dolphin/os/OSInterrupt.h" static void DecrementerExceptionHandler(u8, OSContext*); diff --git a/src/dolphin/os/OSContext.c b/src/dolphin/os/OSContext.c index 1aed9c1c..38ed48fd 100644 --- a/src/dolphin/os/OSContext.c +++ b/src/dolphin/os/OSContext.c @@ -1,5 +1,7 @@ #include "dolphin/os/OSContext.h" #include "dolphin/os/OSError.h" +#include "dolphin/os/OSInterrupt.h" + static asm void __OSLoadFPUContext(int unused, register OSContext* ctx){ nofralloc lhz r5, ctx->state diff --git a/src/dolphin/os/OSDisableInterrupts.c b/src/dolphin/os/OSDisableInterrupts.c index dc322d51..3be178ed 100644 --- a/src/dolphin/os/OSDisableInterrupts.c +++ b/src/dolphin/os/OSDisableInterrupts.c @@ -1,4 +1,4 @@ -#include "dolphin/os/os.h" +#include "dolphin/os/OSInterrupt.h" asm BOOL OSDisableInterrupts(void){ nofralloc diff --git a/src/libforest/osreport.c b/src/libforest/osreport.c new file mode 100644 index 00000000..a7524a30 --- /dev/null +++ b/src/libforest/osreport.c @@ -0,0 +1,88 @@ +#include "libforest/osreport.h" +#include "dolphin/os/OSInterrupt.h" +#include "dolphin/os/OSThread.h" +#include "dolphin/os/OSRtc.h" +#include "dolphin/os/OSMutex.h" +#include "MSL_C/printf.h" + +OSMutex print_mutex; +u8 print_mutex_initialized; +static void* __OSReport_MonopolyThread; +static s32 __OSReport_disable; + + +void OSReportDisable (void){ + __OSReport_disable = 1; +} + +void OSReportEnable (void){ + __OSReport_disable = 0; +} + +void OSVReport(const char* fmt, va_list list){ + + OSThread* cur_thread; + u32 enable; + if(__OSReport_disable == 0){ + cur_thread = OSGetCurrentThread(); + if((cur_thread != NULL) && (cur_thread->state !=2)) { + cur_thread = NULL; + } + if((__OSReport_MonopolyThread == NULL) || (__OSReport_MonopolyThread == cur_thread)){ + enable = OSDisableInterrupts(); + if(print_mutex_initialized == 0){ + OSInitMutex(&print_mutex); + print_mutex_initialized = 1; + printf("*** OSVReport - OSInitMutex ***"); + } + OSRestoreInterrupts(enable); + if(cur_thread != NULL){ + OSLockMutex(&print_mutex); + } + vprintf(fmt, list); + if(cur_thread != NULL){ + OSUnlockMutex(&print_mutex); + } + } + } +} + +void OSReport(const char* fmt,...){ + va_list list; + va_start(list, fmt); + OSVReport(fmt, list); + va_end(list); +} + +void OSPanic(const char* file, u32 line, const char* fmt, ...){ + va_list list; + u32 enable; + OSThread* thread; + enable = OSDisableInterrupts(); + + + va_start(list, fmt); + vprintf(fmt, list); + va_end(list); + printf(" in \"%s\" on line %d.\n", file, line); + + thread = OSGetCurrentThread(); + + OSSetThreadPriority(thread, 0x1f); + OSRestoreInterrupts(enable); + *(int*)0 = 0; //why lol +} + +void OSChangeBootMode(u32 mode){ + __OSSetBootMode(mode ? 0x80 : 0); + + while(__OSSyncSram() == 0) { } + +} + +void OSDVDFatalError(void){ + OSReport("OSDVDFatalError called.\nExitThread.\n"); + OSExitThread(0); +} + + diff --git a/src/version.c b/src/version.c new file mode 100644 index 00000000..fe993932 --- /dev/null +++ b/src/version.c @@ -0,0 +1,8 @@ +#include "types.h" + +u8 __Creator__[]{ +#include "assets/__Creator__bin.inc" +} +u8 __DateTime__[]{ +#include "assets/__DateTime__.bin.inc" +} \ No newline at end of file