Minor cleanup, added error when writing an exception dump fails
This commit is contained in:
parent
96a274bf7d
commit
6686e4add7
@ -42,7 +42,6 @@ typedef struct __attribute__((packed))
|
||||
void __attribute__((noreturn)) mcuReboot(void);
|
||||
void cleanInvalidateDCacheAndDMB(void);
|
||||
bool cannotAccessVA(const void *address);
|
||||
|
||||
void FIQHandler(void);
|
||||
void undefinedInstructionHandler(void);
|
||||
void dataAbortHandler(void);
|
||||
|
@ -43,7 +43,7 @@ static u32 __attribute__((noinline)) copyMemory(void *dst, const void *src, u32
|
||||
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;
|
||||
|
||||
@ -64,7 +64,6 @@ void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type
|
||||
|
||||
dumpHeader.registerDumpSize = REG_DUMP_SIZE;
|
||||
dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
|
||||
dumpHeader.additionalDataSize = 0;
|
||||
|
||||
//Dump registers
|
||||
//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);
|
||||
final += dumpHeader.stackDumpSize;
|
||||
|
||||
vu8 *currentKProcess = cannotAccessVA((u8 *)0xFFFF9004) ? NULL : *(vu8 **)0xFFFF9004;
|
||||
vu8 *currentKCodeSet = currentKProcess != NULL ? *(vu8 **)(currentKProcess + CODESET_OFFSET) : NULL;
|
||||
|
||||
if(currentKCodeSet != NULL)
|
||||
if(!cannotAccessVA((u8 *)0xFFFF9004))
|
||||
{
|
||||
vu64 *additionalData = (vu64 *)final;
|
||||
dumpHeader.additionalDataSize = 16;
|
||||
vu8 *currentKCodeSet = *(vu8 **)(*(vu8 **)0xFFFF9004 + CODESET_OFFSET); //currentKProcess + CodeSet
|
||||
|
||||
additionalData[0] = *(vu64 *)(currentKCodeSet + 0x50); //Process name
|
||||
additionalData[1] = *(vu64 *)(currentKCodeSet + 0x5C); //Title ID
|
||||
}
|
||||
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;
|
||||
*(ExceptionDumpHeader *)final = dumpHeader;
|
||||
|
||||
//Copy header (actually optimized by the compiler)
|
||||
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
|
||||
|
||||
cleanInvalidateDCacheAndDMB();
|
||||
mcuReboot(); //Also contains DCache-cleaning code
|
||||
|
@ -39,7 +39,7 @@ typedef struct __attribute__((packed))
|
||||
u32 additionalDataSize;
|
||||
} ExceptionDumpHeader;
|
||||
|
||||
u32 readMPUConfig(u32 regionSettings[8]);
|
||||
u32 readMPUConfig(u32 *regionSettings);
|
||||
void FIQHandler(void);
|
||||
void undefinedInstructionHandler(void);
|
||||
void dataAbortHandler(void);
|
||||
|
@ -65,7 +65,7 @@ static u32 __attribute__((noinline)) copyMemory(void *dst, const void *src, u32
|
||||
return size;
|
||||
}
|
||||
|
||||
void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type)
|
||||
void __attribute__((noreturn)) mainHandler(u32 *regs, u32 type)
|
||||
{
|
||||
ExceptionDumpHeader dumpHeader;
|
||||
|
||||
@ -107,10 +107,10 @@ void __attribute__((noreturn)) mainHandler(u32 regs[REG_DUMP_SIZE / 4], u32 type
|
||||
//Dump stack in place
|
||||
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;
|
||||
*(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
|
||||
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
|
||||
|
@ -85,19 +85,6 @@ void detectAndProcessExceptionDumps(void)
|
||||
|
||||
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));
|
||||
vu8 *additionalData = (vu8 *)dumpHeader + dumpHeader->totalSize - dumpHeader->additionalDataSize;
|
||||
|
||||
@ -111,9 +98,8 @@ void detectAndProcessExceptionDumps(void)
|
||||
};
|
||||
|
||||
char hexstring[] = "00000000";
|
||||
|
||||
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();
|
||||
|
||||
@ -176,14 +162,28 @@ void detectAndProcessExceptionDumps(void)
|
||||
if(dumpHeader->processor != 9) posY -= SPACING_Y;
|
||||
}
|
||||
|
||||
u32 size = dumpHeader->totalSize;
|
||||
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;
|
||||
drawString("Press any button to shutdown", 10, posY, COLOR_WHITE);
|
||||
}
|
||||
else posY = drawString("Error writing the dump file", 10, posY, COLOR_RED) + SPACING_Y;
|
||||
|
||||
waitInput();
|
||||
drawString("Press any button to shutdown", 10, posY, COLOR_WHITE);
|
||||
|
||||
memset32((void *)dumpHeader, 0, size);
|
||||
|
||||
waitInput();
|
||||
mcuPowerOff();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user