Minor cleanup, added error when writing an exception dump fails

This commit is contained in:
Aurora 2016-09-06 19:17:45 +02:00
parent 96a274bf7d
commit 6686e4add7
5 changed files with 31 additions and 35 deletions

View File

@ -42,7 +42,6 @@ typedef struct __attribute__((packed))
void __attribute__((noreturn)) mcuReboot(void); void __attribute__((noreturn)) mcuReboot(void);
void cleanInvalidateDCacheAndDMB(void); void cleanInvalidateDCacheAndDMB(void);
bool cannotAccessVA(const void *address); bool cannotAccessVA(const void *address);
void FIQHandler(void); void FIQHandler(void);
void undefinedInstructionHandler(void); void undefinedInstructionHandler(void);
void dataAbortHandler(void); void dataAbortHandler(void);

View File

@ -43,7 +43,7 @@ static u32 __attribute__((noinline)) copyMemory(void *dst, const void *src, u32
return size; return size;
} }
void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type, u32 cpuId) void __attribute__((noreturn)) mainHandler(u32 *regs, u32 type, u32 cpuId)
{ {
ExceptionDumpHeader dumpHeader; ExceptionDumpHeader dumpHeader;
@ -64,7 +64,6 @@ void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type
dumpHeader.registerDumpSize = REG_DUMP_SIZE; dumpHeader.registerDumpSize = REG_DUMP_SIZE;
dumpHeader.codeDumpSize = CODE_DUMP_SIZE; dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
dumpHeader.additionalDataSize = 0;
//Dump registers //Dump registers
//Current order of saved regs: dfsr, ifsr, far, fpexc, fpinst, fpinst2, cpsr, pc, r8-r12, sp, lr, r0-r7 //Current order of saved regs: dfsr, ifsr, far, fpexc, fpinst, fpinst2, cpsr, pc, r8-r12, sp, lr, r0-r7
@ -90,23 +89,21 @@ void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type
dumpHeader.stackDumpSize = copyMemory(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF), 1); dumpHeader.stackDumpSize = copyMemory(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF), 1);
final += dumpHeader.stackDumpSize; final += dumpHeader.stackDumpSize;
vu8 *currentKProcess = cannotAccessVA((u8 *)0xFFFF9004) ? NULL : *(vu8 **)0xFFFF9004; if(!cannotAccessVA((u8 *)0xFFFF9004))
vu8 *currentKCodeSet = currentKProcess != NULL ? *(vu8 **)(currentKProcess + CODESET_OFFSET) : NULL;
if(currentKCodeSet != NULL)
{ {
vu64 *additionalData = (vu64 *)final; vu64 *additionalData = (vu64 *)final;
dumpHeader.additionalDataSize = 16; dumpHeader.additionalDataSize = 16;
vu8 *currentKCodeSet = *(vu8 **)(*(vu8 **)0xFFFF9004 + CODESET_OFFSET); //currentKProcess + CodeSet
additionalData[0] = *(vu64 *)(currentKCodeSet + 0x50); //Process name additionalData[0] = *(vu64 *)(currentKCodeSet + 0x50); //Process name
additionalData[1] = *(vu64 *)(currentKCodeSet + 0x5C); //Title ID additionalData[1] = *(vu64 *)(currentKCodeSet + 0x5C); //Title ID
} }
else dumpHeader.additionalDataSize = 0; else dumpHeader.additionalDataSize = 0;
//Copy header (actually optimized by the compiler)
final = (u8 *)FINAL_BUFFER;
dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize; dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;
*(ExceptionDumpHeader *)final = dumpHeader;
//Copy header (actually optimized by the compiler)
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
cleanInvalidateDCacheAndDMB(); cleanInvalidateDCacheAndDMB();
mcuReboot(); //Also contains DCache-cleaning code mcuReboot(); //Also contains DCache-cleaning code

View File

@ -39,7 +39,7 @@ typedef struct __attribute__((packed))
u32 additionalDataSize; u32 additionalDataSize;
} ExceptionDumpHeader; } ExceptionDumpHeader;
u32 readMPUConfig(u32 regionSettings[8]); u32 readMPUConfig(u32 *regionSettings);
void FIQHandler(void); void FIQHandler(void);
void undefinedInstructionHandler(void); void undefinedInstructionHandler(void);
void dataAbortHandler(void); void dataAbortHandler(void);

View File

@ -65,7 +65,7 @@ static u32 __attribute__((noinline)) copyMemory(void *dst, const void *src, u32
return size; return size;
} }
void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type) void __attribute__((noreturn)) mainHandler(u32 *regs, u32 type)
{ {
ExceptionDumpHeader dumpHeader; ExceptionDumpHeader dumpHeader;
@ -107,10 +107,10 @@ void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type
//Dump stack in place //Dump stack in place
dumpHeader.stackDumpSize = copyMemory(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF), 1); dumpHeader.stackDumpSize = copyMemory(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF), 1);
//Copy header (actually optimized by the compiler)
final = (u8 *)FINAL_BUFFER;
dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize; dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;
*(ExceptionDumpHeader *)final = dumpHeader;
//Copy header (actually optimized by the compiler)
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed ((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot

View File

@ -85,19 +85,6 @@ void detectAndProcessExceptionDumps(void)
if(dumpHeader->magic[0] == 0xDEADC0DE && dumpHeader->magic[1] == 0xDEADCAFE && (dumpHeader->processor == 9 || dumpHeader->processor == 11)) if(dumpHeader->magic[0] == 0xDEADC0DE && dumpHeader->magic[1] == 0xDEADCAFE && (dumpHeader->processor == 9 || dumpHeader->processor == 11))
{ {
char path[42];
char fileName[] = "crash_dump_00000000.dmp";
u32 size = dumpHeader->totalSize;
char *pathFolder = dumpHeader->processor == 9 ? "/luma/dumps/arm9" : "/luma/dumps/arm11";
findDumpFile(pathFolder, fileName);
memcpy(path, pathFolder, strlen(pathFolder) + 1);
concatenateStrings(path, "/");
concatenateStrings(path, fileName);
fileWrite((void *)dumpHeader, path, size);
vu32 *regs = (vu32 *)((vu8 *)dumpHeader + sizeof(ExceptionDumpHeader)); vu32 *regs = (vu32 *)((vu8 *)dumpHeader + sizeof(ExceptionDumpHeader));
vu8 *additionalData = (vu8 *)dumpHeader + dumpHeader->totalSize - dumpHeader->additionalDataSize; vu8 *additionalData = (vu8 *)dumpHeader + dumpHeader->totalSize - dumpHeader->additionalDataSize;
@ -111,9 +98,8 @@ void detectAndProcessExceptionDumps(void)
}; };
char hexstring[] = "00000000"; char hexstring[] = "00000000";
char arm11Str[] = "Processor: ARM11 (core X)"; char arm11Str[] = "Processor: ARM11 (core X)";
if(dumpHeader->processor == 11) arm11Str[29] = '0' + (char)(dumpHeader->core); if(dumpHeader->processor == 11) arm11Str[29] = '0' + (char)dumpHeader->core;
initScreens(); initScreens();
@ -176,14 +162,28 @@ void detectAndProcessExceptionDumps(void)
if(dumpHeader->processor != 9) posY -= SPACING_Y; if(dumpHeader->processor != 9) posY -= SPACING_Y;
} }
posY = drawString("You can find a dump in the following file:", 10, posY, COLOR_WHITE) + SPACING_Y; u32 size = dumpHeader->totalSize;
posY = drawString(path, 10, posY, COLOR_WHITE) + 2 * SPACING_Y; char path[42];
char fileName[] = "crash_dump_00000000.dmp";
char *pathFolder = dumpHeader->processor == 9 ? "/luma/dumps/arm9" : "/luma/dumps/arm11";
findDumpFile(pathFolder, fileName);
memcpy(path, pathFolder, strlen(pathFolder) + 1);
concatenateStrings(path, "/");
concatenateStrings(path, fileName);
if(fileWrite((void *)dumpHeader, path, size))
{
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;
}
else posY = drawString("Error writing the dump file", 10, posY, COLOR_RED) + SPACING_Y;
drawString("Press any button to shutdown", 10, posY, COLOR_WHITE); drawString("Press any button to shutdown", 10, posY, COLOR_WHITE);
memset32((void *)dumpHeader, 0, size);
waitInput(); waitInput();
memset32((void *)dumpHeader, 0, size);
mcuPowerOff(); mcuPowerOff();
} }
} }