diff --git a/exceptions/exception_dump_parser.py b/exceptions/exception_dump_parser.py index 07df5d5..101e836 100644 --- a/exceptions/exception_dump_parser.py +++ b/exceptions/exception_dump_parser.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # Requires Python >= 3.2 or >= 2.7 -# This is part of AuReiNand +# This is part of Luma3DS, see LICENSE.txt for details __author__ = "TuxSH" __copyright__ = "Copyright (c) 2016 TuxSH" @@ -9,7 +9,7 @@ __license__ = "GPLv3" __version__ = "v1.0" """ -Parses AuReiNand exception dumps +Parses Luma3DS exception dumps """ import argparse @@ -70,7 +70,7 @@ handledExceptionNames = ("FIQ", "undefined instruction", "prefetch abort", "data registerNames = tuple("r{0}".format(i) for i in range(13)) + ("sp", "lr", "pc", "cpsr") if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Parse AuReiNand exception dumps") + parser = argparse.ArgumentParser(description="Parse Luma3DS exception dumps") parser.add_argument("filename") args = parser.parse_args() data = b"" diff --git a/source/exceptions.c b/source/exceptions.c index a6e6059..5dc5856 100644 --- a/source/exceptions.c +++ b/source/exceptions.c @@ -20,8 +20,35 @@ void installArm9Handlers(void) ((void (*)())payloadAddress)(); } +static void hexItoa(u32 n, char* out) +{ + static const char hexDigits[] = "0123456789ABCDEF"; + int i = 0; + + while(n > 0) + { + out[7-i++] = hexDigits[(int)(n & 0xf)]; + n >>= 4; + } + + for(; i < 8; ++i) out[7-i] = '0'; + + out[8] = '\x00'; +} + void detectAndProcessExceptionDumps(void) { + static const char* handledExceptionNames[] = { + "FIQ", "undefined instruction", "prefetch abort", "data abort" + }; + + static const char* registerNames[] = { + "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12", + "SP", "LR", "PC", "CPSR" + }; + + char hexstring[] = "00000000"; + vu32 *dump = (u32 *)0x25000000; if(dump[0] == 0xDEADC0DE && dump[1] == 0xDEADCAFE && dump[3] == 9) @@ -38,11 +65,33 @@ void detectAndProcessExceptionDumps(void) initScreens(); - drawString("An ARM9 exception occurred", 10, 10, COLOR_RED); - int posY = drawString("You can find a dump in the following file:", 10, 30, COLOR_WHITE); - posY = drawString(path, 10, posY + SPACING_Y, COLOR_WHITE); - drawString("Press any button to shutdown", 10, posY + 2 * SPACING_Y, COLOR_WHITE); - + drawString("An exception occurred", 10, 10, COLOR_RED); + int posY = drawString("Processor: ARM9", 10, 30, COLOR_WHITE) + SPACING_Y; + posY = drawString("Exception type: ", 10, posY, COLOR_WHITE); + posY = drawString(handledExceptionNames[dump[4]], 10 + 16 * SPACING_X, posY, COLOR_WHITE); + + posY += 3 * SPACING_Y; + for(u32 i = 0; i < 17; i += 2) + { + posY = drawString(registerNames[i], 10, posY, COLOR_WHITE); + hexItoa(dump[10 + i], hexstring); + posY = drawString(hexstring, 10 + 7 * SPACING_X, posY, COLOR_WHITE); + + if(i != 16) + { + posY = drawString(registerNames[i + 1], 10 + 22 * SPACING_X, posY, COLOR_WHITE); + hexItoa(dump[10 + i + 1], hexstring); + posY = drawString(hexstring, 10 + 29 * SPACING_X, posY, COLOR_WHITE); + } + + posY += SPACING_Y; + } + + posY += 2 * SPACING_Y; + posY = drawString("You can find a dump in the following file:", 10, posY, COLOR_WHITE) + SPACING_Y; + posY = drawString(path, 10, posY, COLOR_WHITE) + 2 * SPACING_Y; + drawString("Press any button to shutdown", 10, posY, COLOR_WHITE); + waitInput(); i2cWriteRegister(I2C_DEV_MCU, 0x20, 1);