Skip to content

Commit

Permalink
Decompile OSPanic
Browse files Browse the repository at this point in the history
  • Loading branch information
SeekyCt committed Dec 29, 2023
1 parent 56ab817 commit 2d1baee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spm-headers/include/wii/os/OSContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ UNKNOWN_FUNCTION(OSSetCurrentContext);
UNKNOWN_FUNCTION(OSGetCurrentContext);
UNKNOWN_FUNCTION(OSSaveContext);
UNKNOWN_FUNCTION(OSLoadContext);
UNKNOWN_FUNCTION(OSGetStackPointer);
u32 OSGetStackPointer();
UNKNOWN_FUNCTION(OSSwitchFiber);
UNKNOWN_FUNCTION(OSSwitchFiberEx);
UNKNOWN_FUNCTION(OSClearContext);
Expand Down
30 changes: 28 additions & 2 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <spm/debug.h>
#include <wii/base.h>
#include <wii/os.h>
#include <msl/stdarg.h>
#include <msl/stdio.h>
#include <msl/string.h>

Expand All @@ -20,7 +21,32 @@ void debugReInit()

}

asm void OSPanic(const char * filename, s32 line, const char * msg, ...)
void OSPanic(const char * filename, s32 line, const char * msg, ...)
{
#include "asm/8019e33c.s"
va_list args;
char buf[2048];
u32 stackDepth;
u32 * stack;
int pos;

// Format header text
va_start(args, msg);
pos = vsprintf(buf, msg, args);
va_end(args);
pos += sprintf(buf + pos, "\n in \"%s\" on line %d.\n", filename, line);
pos += sprintf(buf + pos, "\nAddress: Back Chain LR Save\n");

// Traverse stack
stackDepth = 0;
stack = (u32 *) OSGetStackPointer();
while (stack != NULL && stack != (u32 *)0xffffffff && stackDepth++ < 16)
{
pos += sprintf(buf + pos, "0x%08x: 0x%08x 0x%08x\n", stack, stack[0], stack[1]);
stack = (u32 *) *stack;
}

// Halt execution
OSDisableInterrupts();
PPCHalt();
while (1);
}

0 comments on commit 2d1baee

Please sign in to comment.