More cleanup

This commit is contained in:
Aurora 2016-05-27 15:15:25 +02:00
parent 477414a636
commit 9017de6082
2 changed files with 15 additions and 17 deletions

View File

@ -20,29 +20,27 @@ void installArm9Handlers(void)
((void (*)())payloadAddress)(); ((void (*)())payloadAddress)();
} }
static void hexItoa(u32 n, char* out) static void hexItoa(u32 n, char *out)
{ {
static const char hexDigits[] = "0123456789ABCDEF"; const char hexDigits[] = "0123456789ABCDEF";
int i = 0; u32 i = 0;
while(n > 0) while(n > 0)
{ {
out[7-i++] = hexDigits[(int)(n & 0xf)]; out[7 - i++] = hexDigits[n & 0xF];
n >>= 4; n >>= 4;
} }
for(; i < 8; ++i) out[7-i] = '0'; for(; i < 8; i++) out[7 - i] = '0';
out[8] = '\x00';
} }
void detectAndProcessExceptionDumps(void) void detectAndProcessExceptionDumps(void)
{ {
static const char* handledExceptionNames[] = { const char *handledExceptionNames[] = {
"FIQ", "undefined instruction", "prefetch abort", "data abort" "FIQ", "undefined instruction", "prefetch abort", "data abort"
}; };
static const char* registerNames[] = { const char *registerNames[] = {
"R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12", "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12",
"SP", "LR", "PC", "CPSR" "SP", "LR", "PC", "CPSR"
}; };
@ -69,29 +67,29 @@ void detectAndProcessExceptionDumps(void)
int posY = drawString("Processor: ARM9", 10, 30, COLOR_WHITE) + SPACING_Y; int posY = drawString("Processor: ARM9", 10, 30, COLOR_WHITE) + SPACING_Y;
posY = drawString("Exception type: ", 10, posY, COLOR_WHITE); posY = drawString("Exception type: ", 10, posY, COLOR_WHITE);
posY = drawString(handledExceptionNames[dump[4]], 10 + 16 * SPACING_X, posY, COLOR_WHITE); posY = drawString(handledExceptionNames[dump[4]], 10 + 16 * SPACING_X, posY, COLOR_WHITE);
posY += 3 * SPACING_Y; posY += 3 * SPACING_Y;
for(u32 i = 0; i < 17; i += 2) for(u32 i = 0; i < 17; i += 2)
{ {
posY = drawString(registerNames[i], 10, posY, COLOR_WHITE); posY = drawString(registerNames[i], 10, posY, COLOR_WHITE);
hexItoa(dump[10 + i], hexstring); hexItoa(dump[10 + i], hexstring);
posY = drawString(hexstring, 10 + 7 * SPACING_X, posY, COLOR_WHITE); posY = drawString(hexstring, 10 + 7 * SPACING_X, posY, COLOR_WHITE);
if(i != 16) if(i != 16)
{ {
posY = drawString(registerNames[i + 1], 10 + 22 * SPACING_X, posY, COLOR_WHITE); posY = drawString(registerNames[i + 1], 10 + 22 * SPACING_X, posY, COLOR_WHITE);
hexItoa(dump[10 + i + 1], hexstring); hexItoa(dump[10 + i + 1], hexstring);
posY = drawString(hexstring, 10 + 29 * SPACING_X, posY, COLOR_WHITE); posY = drawString(hexstring, 10 + 29 * SPACING_X, posY, COLOR_WHITE);
} }
posY += SPACING_Y; posY += SPACING_Y;
} }
posY += 2 * 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("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; posY = drawString(path, 10, posY, COLOR_WHITE) + 2 * SPACING_Y;
drawString("Press any button to shutdown", 10, posY, COLOR_WHITE); drawString("Press any button to shutdown", 10, posY, COLOR_WHITE);
waitInput(); waitInput();
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1); i2cWriteRegister(I2C_DEV_MCU, 0x20, 1);

View File

@ -160,4 +160,4 @@ void firmRead(void *dest, const char *firmFolder)
} }
fileRead(dest, path); fileRead(dest, path);
} }