Display the stack dump partially on the bottom screen when handling an exception

This commit is contained in:
TuxSH 2016-09-13 00:52:15 +02:00
parent e0b5539b91
commit 50e5c29b1c
6 changed files with 43 additions and 12 deletions

View File

@ -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;

View File

@ -30,7 +30,8 @@
#include "types.h"
#define SCREEN_TOP_WIDTH 400
#define SCREEN_TOP_HEIGHT 240
#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);

View File

@ -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";

View File

@ -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);

View File

@ -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';
}

View File

@ -26,4 +26,4 @@
int strlen(const char *string);
void concatenateStrings(char *destination, const char *source);
void hexItoa(u32 number, char *out);
void hexItoa(u32 number, char *out, u32 nbDigits);