Beautified exception handler

This commit is contained in:
d0k3 2017-09-13 01:10:14 +02:00
parent e8b34a90be
commit f46a88c9ff

View File

@ -6,6 +6,9 @@
#include "common.h"
#include "fsinit.h"
#include "fsutil.h"
#include "power.h"
#include "rtc.h"
#include "hid.h"
#include "ui.h"
#include <arm.h>
@ -42,47 +45,57 @@ extern char __stack_top;
void XRQ_DumpRegisters(u32 xrq, u32 *regs)
{
int y;
u32 sp, st, pc;
char dumpstr[2048], *wstr = dumpstr;
DsTime dstime;
get_dstime(&dstime);
ClearScreen(MAIN_SCREEN, COLOR_BLACK);
/* Print registers on screen */
/* Dump registers */
wstr += sprintf(wstr, "Exception: %s (%lu)\n", XRQ_Name[xrq&7], xrq);
wstr += sprintf(wstr, "20%02lX-%02lX-%02lX %02lX:%02lX:%02lX\n \n",
(u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D,
(u32) dstime.bcd_h, (u32) dstime.bcd_m, (u32) dstime.bcd_s);
for (int i = 0; i < 8; i++) {
int i_ = i*2;
wstr += sprintf(wstr,
"R%02d: %08lX | R%02d: %08lX\n", i_, regs[i_], i_+1, regs[i_+1]);
}
wstr += sprintf(wstr, "CPSR: %08lX\n", regs[16]);
DrawStringF(MAIN_SCREEN, 10, 0, COLOR_WHITE, COLOR_BLACK, dumpstr);
wstr += sprintf(wstr, "CPSR: %08lX\n\n", regs[16]);
/* Output registers to main screen */
u32 draw_width = GetDrawStringWidth(dumpstr);
u32 draw_height = GetDrawStringHeight(dumpstr);
u32 draw_x = (SCREEN_WIDTH_MAIN - draw_width) / 2;
u32 draw_y = (SCREEN_HEIGHT - draw_height) / 2;
u32 draw_y_upd = draw_y + draw_height - 10;
ClearScreen(MAIN_SCREEN, COLOR_STD_BG);
DrawStringF(MAIN_SCREEN, draw_x, draw_y, COLOR_STD_FONT, COLOR_STD_BG, dumpstr);
/* Reinitialize SD */
y = GetDrawStringHeight(dumpstr);
DrawString(MAIN_SCREEN, "Reinitializing SD subsystem...", 10, y,
COLOR_WHITE, COLOR_BLACK);
y+=FONT_HEIGHT_EXT;
while(!InitSDCardFS()) {
DrawStringF(MAIN_SCREEN, draw_x, draw_y_upd, COLOR_STD_FONT, COLOR_STD_BG,
"%-29.29s", "Reinitializing SD card...");
while (!InitSDCardFS()) {
if (InputWait(1) & BUTTON_POWER) PowerOff();
DeinitSDCardFS();
}
DrawString(MAIN_SCREEN, "Done", 10, y, COLOR_WHITE, COLOR_BLACK);
y+=FONT_HEIGHT_EXT;
/* Dump STACK */
sp = regs[13] & ~0xF;
st = (u32)&__stack_top;
wstr += sprintf(wstr, "\nStack dump:\n\n");
wstr += sprintf(wstr, "Stack dump:\n");
wstr += XRQ_DumpData_u8(wstr, sp, min(sp+SP_DUMPLEN, st));
wstr += sprintf(wstr, "\n");
/* Dump TEXT */
pc = regs[15] & ~0xF;
wstr += sprintf(wstr, "\nCode dump:\n\n");
wstr += sprintf(wstr, "Code dump:\n");
if (regs[16] & SR_THUMB) {
wstr += XRQ_DumpData_u16(wstr, pc-PC_DUMPRAD, pc+PC_DUMPRAD);
} else {
@ -91,13 +104,25 @@ void XRQ_DumpRegisters(u32 xrq, u32 *regs)
/* Dump to SD */
DrawString(MAIN_SCREEN, "Dumping state to SD...", 10, y,
COLOR_WHITE, COLOR_BLACK);
y+=FONT_HEIGHT_EXT;
FileSetData(OUTPUT_PATH"/exception_dump.txt", dumpstr, wstr - dumpstr, 0, true);
DrawString(MAIN_SCREEN, "Done", 10, y, COLOR_WHITE, COLOR_BLACK);
char path[64];
snprintf(path, 64, "%s/exception_dump_%02lX%02lX%02lX%02lX%02lX%02lX.txt", OUTPUT_PATH,
(u32) dstime.bcd_Y, (u32) dstime.bcd_M, (u32) dstime.bcd_D,
(u32) dstime.bcd_h, (u32) dstime.bcd_m, (u32) dstime.bcd_s);
DrawStringF(MAIN_SCREEN, draw_x, draw_y_upd, COLOR_STD_FONT, COLOR_STD_BG,
"%-29.29s", "Dumping state to SD card...");
FileSetData(path, dumpstr, wstr - dumpstr, 0, true);
/* Deinit SD */
DeinitSDCardFS();
/* Done, wait for user power off */
DrawStringF(MAIN_SCREEN, draw_x, draw_y_upd, COLOR_STD_FONT, COLOR_STD_BG,
"%-29.29s", "Press POWER to turn off");
while (!(InputWait(0) & BUTTON_POWER));
PowerOff();
/* We will not return */
return;
}