Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into screenshot-filename…
Browse files Browse the repository at this point in the history
…-improvements
  • Loading branch information
ioistired committed Nov 22, 2020
2 parents 50d9fa2 + 87fa35c commit 89a872e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
31 changes: 30 additions & 1 deletion arm9/source/arm9_exception_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
#define REG_DUMP_SIZE 4 * 17
#define CODE_DUMP_SIZE 48

static inline void dumpArm9Memory(ExceptionDumpHeader *dumpHeader, u8 *buf)
{
// Check if n3ds extra arm9 mem is enabled (if it's possible to read CFG9_EXTMEMCNT9)
u8 extmemcnt9 = 0;
safecpy(&extmemcnt9, (const void *)0x10000200, 1);

u32 size = (extmemcnt9 & 1) ? 0x180000 : 0x100000;
dumpHeader->additionalDataSize += safecpy(buf, (const void *)0x08000000, size);
}

void __attribute__((noreturn)) arm9ExceptionHandlerMain(u32 *registerDump, u32 type)
{
ExceptionDumpHeader dumpHeader;
Expand All @@ -42,7 +52,7 @@ void __attribute__((noreturn)) arm9ExceptionHandlerMain(u32 *registerDump, u32 t
dumpHeader.magic[0] = 0xDEADC0DE;
dumpHeader.magic[1] = 0xDEADCAFE;
dumpHeader.versionMajor = 1;
dumpHeader.versionMinor = 2;
dumpHeader.versionMinor = 3;

dumpHeader.processor = 9;
dumpHeader.core = 0;
Expand All @@ -68,6 +78,25 @@ void __attribute__((noreturn)) arm9ExceptionHandlerMain(u32 *registerDump, u32 t

//Dump stack in place
dumpHeader.stackDumpSize = safecpy(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF));
final += dumpHeader.stackDumpSize;

// See if we need to copy Arm9 memory (check for bkpt 0xFFFD / bkpt 0xFD)
if(dumpHeader.codeDumpSize > 0)
{
if(cpsr & 0x20)
{
// Thumb
u16 instr;
safecpy(&instr, codeDump + dumpHeader.codeDumpSize - 2, 2);
if(instr == 0xBEFD) dumpArm9Memory(&dumpHeader, final);
}
else
{
u32 instr;
safecpy(&instr, codeDump + dumpHeader.codeDumpSize - 4, 4);
if(instr == 0xE12FFF7D) dumpArm9Memory(&dumpHeader, final);
}
}

dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;

Expand Down
2 changes: 2 additions & 0 deletions arm9/source/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@
bool loadSplash(void);
void drawCharacter(bool isTopScreen, u32 posX, u32 posY, u32 color, char character);
u32 drawString(bool isTopScreen, u32 posX, u32 posY, u32 color, const char *string);

__attribute__((format(printf,5,6)))
u32 drawFormattedString(bool isTopScreen, u32 posX, u32 posY, u32 color, const char *fmt, ...);
11 changes: 9 additions & 2 deletions arm9/source/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ void detectAndProcessExceptionDumps(void)
}

if(dumpHeader->additionalDataSize != 0)
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
"Current process: %.8s (%016llX)", (const char *)additionalData, *(vu64 *)(additionalData + 8));
{
u32 size = dumpHeader->additionalDataSize;
if(dumpHeader->processor == 11)
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
"Current process: %.8s (%016llX)", (const char *)additionalData, *(vu64 *)(additionalData + 8));
else
posY = drawFormattedString(true, 10, posY + SPACING_Y, COLOR_WHITE,
"Arm9 memory dump at offset %X size %lX", (uintptr_t)additionalData - (uintptr_t)dumpHeader, size);
}
posY += SPACING_Y;

for(u32 i = 0; i < 17; i += 2)
Expand Down
2 changes: 1 addition & 1 deletion k11_extension/source/fatalExceptionHandlersMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void fatalExceptionHandlersMain(u32 *registerDump, u32 type, u32 cpuId)
dumpHeader.magic[0] = 0xDEADC0DE;
dumpHeader.magic[1] = 0xDEADCAFE;
dumpHeader.versionMajor = 1;
dumpHeader.versionMinor = 2;
dumpHeader.versionMinor = 3;

dumpHeader.processor = 11;
dumpHeader.core = cpuId & 0xF;
Expand Down

0 comments on commit 89a872e

Please sign in to comment.