From 50e5c29b1c87e2c2d05002228852a903d0946a37 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Tue, 13 Sep 2016 00:52:15 +0200 Subject: [PATCH] Display the stack dump partially on the bottom screen when handling an exception --- source/draw.c | 13 ++++++++++--- source/draw.h | 6 ++++-- source/exceptions.c | 26 ++++++++++++++++++++++++-- source/fs.c | 2 +- source/strings.c | 6 +++--- source/strings.h | 2 +- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/source/draw.c b/source/draw.c index 73e603e..3538fce 100644 --- a/source/draw.c +++ b/source/draw.c @@ -32,6 +32,8 @@ #include "fs.h" #include "font.h" +static bool bottomScreenSelected = false; + bool loadSplash(void) { //Don't delay boot nor init the screens if no splash image is on the SD @@ -48,9 +50,14 @@ bool loadSplash(void) return true; } +void selectScreen(bool isBottomScreen) +{ + bottomScreenSelected = isBottomScreen; +} + void drawCharacter(char character, int posX, int posY, u32 color) { - u8 *const select = fb->top_left; + u8 *const select = (bottomScreenSelected) ? fb->bottom : fb->top_left; for(int y = 0; y < 8; y++) { @@ -59,7 +66,7 @@ void drawCharacter(char character, int posX, int posY, u32 color) for(int x = 7; x >= 0; x--) if ((charPos >> x) & 1) { - int screenPos = (posX * SCREEN_TOP_HEIGHT * 3 + (SCREEN_TOP_HEIGHT - y - posY - 1) * 3) + (7 - x) * 3 * SCREEN_TOP_HEIGHT; + int screenPos = (posX * SCREEN_HEIGHT * 3 + (SCREEN_HEIGHT - y - posY - 1) * 3) + (7 - x) * 3 * SCREEN_HEIGHT; select[screenPos] = color >> 16; select[screenPos + 1] = color >> 8; @@ -78,7 +85,7 @@ int drawString(const char *string, int posX, int posY, u32 color) line_i = 0; i++; } - else if(line_i >= (SCREEN_TOP_WIDTH - posX) / SPACING_X) + else if(line_i >= ((bottomScreenSelected ? SCREEN_BOTTOM_WIDTH : SCREEN_TOP_WIDTH)- posX) / SPACING_X) { // Make sure we never get out of the screen. posY += SPACING_Y; diff --git a/source/draw.h b/source/draw.h index 1f1c345..8d79013 100644 --- a/source/draw.h +++ b/source/draw.h @@ -29,8 +29,9 @@ #include "types.h" -#define SCREEN_TOP_WIDTH 400 -#define SCREEN_TOP_HEIGHT 240 +#define SCREEN_TOP_WIDTH 400 +#define SCREEN_BOTTOM_WIDTH 320 +#define SCREEN_HEIGHT 240 #define SPACING_Y 10 #define SPACING_X 8 @@ -42,5 +43,6 @@ #define COLOR_YELLOW 0x00FFFF bool loadSplash(void); +void selectScreen(bool isBottomScreen); void drawCharacter(char character, int posX, int posY, u32 color); int drawString(const char *string, int posX, int posY, u32 color); \ No newline at end of file diff --git a/source/exceptions.c b/source/exceptions.c index 47691c3..854fbb8 100644 --- a/source/exceptions.c +++ b/source/exceptions.c @@ -140,13 +140,13 @@ void detectAndProcessExceptionDumps(void) for(u32 i = 0; i < 17; i += 2) { posY = drawString(registerNames[i], 10, posY, COLOR_WHITE); - hexItoa(regs[i], hexString); + hexItoa(regs[i], hexString, 8); posY = drawString(hexString, 10 + 7 * SPACING_X, posY, COLOR_WHITE); if(dumpHeader->processor != 9 || i != 16) { posY = drawString(registerNames[i + 1], 10 + 22 * SPACING_X, posY, COLOR_WHITE); - hexItoa(i == 16 ? regs[20] : regs[i + 1], hexString); + hexItoa(i == 16 ? regs[20] : regs[i + 1], hexString, 8); posY = drawString(hexString, 10 + 29 * SPACING_X, posY, COLOR_WHITE); } @@ -162,6 +162,28 @@ void detectAndProcessExceptionDumps(void) if(dumpHeader->processor != 9) posY -= SPACING_Y; } + selectScreen(true); + + int posYBottom = drawString("Stack dump:", 10, 10, COLOR_WHITE) + 2 * SPACING_Y; + vu8 *stackDump = (vu8 *)dumpHeader + sizeof(ExceptionDumpHeader) + dumpHeader->registerDumpSize + dumpHeader->codeDumpSize + dumpHeader->stackDumpSize + dumpHeader->additionalDataSize; + u32 stackBytePos = 0; + for(u32 line = 0; line < 19 && stackBytePos < dumpHeader->stackDumpSize; line++) + { + hexItoa(regs[13] + 8 * line, hexString, 8); + drawString(hexString, 10, posYBottom, COLOR_WHITE); + drawCharacter(':', 10 + 8 * SPACING_X, posYBottom, COLOR_WHITE); + for(u32 i = 0; i < 8 && stackBytePos < dumpHeader->stackDumpSize; i++) + { + char byteString[] = "00"; + hexItoa(*stackDump++, byteString, 2); + drawString(byteString, 10 + 10 * SPACING_X + 3 * i * SPACING_X, posYBottom, COLOR_WHITE); + } + + posYBottom += SPACING_Y; + } + + selectScreen(false); + u32 size = dumpHeader->totalSize; char path[42]; char fileName[] = "crash_dump_00000000.dmp"; diff --git a/source/fs.c b/source/fs.c index 0a0d6b0..8c93f84 100644 --- a/source/fs.c +++ b/source/fs.c @@ -185,7 +185,7 @@ u32 firmRead(void *dest, u32 firmType) concatenateStrings(path, "/00000000.app"); //Convert back the .app name from integer to array - hexItoa(firmVersion, &path[35]); + hexItoa(firmVersion, &path[35], 8); fileRead(dest, path); diff --git a/source/strings.c b/source/strings.c index 9d0bb2d..552cbe5 100644 --- a/source/strings.c +++ b/source/strings.c @@ -40,16 +40,16 @@ void concatenateStrings(char *destination, const char *source) memcpy(&destination[j], source, i + 1); } -void hexItoa(u32 number, char *out) +void hexItoa(u32 number, char *out, u32 nbDigits) { const char hexDigits[] = "0123456789ABCDEF"; u32 i = 0; while(number > 0) { - out[7 - i++] = hexDigits[number & 0xF]; + out[nbDigits - 1 - i++] = hexDigits[number & 0xF]; number >>= 4; } - for(; i < 8; i++) out[7 - i] = '0'; + for(; i < nbDigits; i++) out[nbDigits - 1 - i] = '0'; } \ No newline at end of file diff --git a/source/strings.h b/source/strings.h index f6ac599..6a7ee4a 100644 --- a/source/strings.h +++ b/source/strings.h @@ -26,4 +26,4 @@ int strlen(const char *string); void concatenateStrings(char *destination, const char *source); -void hexItoa(u32 number, char *out); \ No newline at end of file +void hexItoa(u32 number, char *out, u32 nbDigits); \ No newline at end of file