ARM11 exception handlers (not working yet, it fails to retrieve the data after the reboot)
Uncomment the appropriate line in firm.c to test.
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "i2c.h"
|
||||
#include "utils.h"
|
||||
#include "../build/arm9_exceptions.h"
|
||||
#include "../build/arm11_exceptions.h"
|
||||
|
||||
|
||||
#define _U __attribute__((unused)) //Silence "unused parameter" warnings
|
||||
static void __attribute__((naked)) setupStack(_U u32 mode, _U void* SP)
|
||||
@@ -55,6 +57,40 @@ void installArm9Handlers(void)
|
||||
}
|
||||
}
|
||||
|
||||
#define MAKE_BRANCH(src,dst) (0xEA000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
#define MAKE_BRANCH_LINK(src,dst) (0xEB000000 | ((u32)((((u8 *)(dst) - (u8 *)(src)) >> 2) - 2) & 0xFFFFFF))
|
||||
|
||||
void installArm11Handlers(u32 *exceptionsPage, u32 stackAddr)
|
||||
{
|
||||
u32 *initFPU;
|
||||
for(initFPU = exceptionsPage; initFPU < (exceptionsPage + 0x400) && (initFPU[0] != 0xE59F0008 || initFPU[1] != 0xE5900000); initFPU += 1);
|
||||
|
||||
u32 *mcuReboot;
|
||||
for(mcuReboot = exceptionsPage; mcuReboot < (exceptionsPage + 0x400) && (mcuReboot[0] != 0xE59F4104 || mcuReboot[1] != 0xE3A0A0C2); mcuReboot += 1);
|
||||
|
||||
u32 *freeSpace;
|
||||
for(freeSpace = initFPU; freeSpace < (exceptionsPage + 0x400) && (freeSpace[0] != 0xFFFFFFFF || freeSpace[1] != 0xFFFFFFFF); freeSpace += 1);
|
||||
//freeSpace += 4 - ((u32)(freeSpace - exceptionsPage) & 3);
|
||||
memcpy(freeSpace, arm11_exceptions + 20, arm11_exceptions_size - 20);
|
||||
|
||||
exceptionsPage[1] = MAKE_BRANCH(exceptionsPage + 1, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 8) - 20); //Undefined Instruction
|
||||
exceptionsPage[3] = MAKE_BRANCH(exceptionsPage + 3, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 12) - 20); //Prefetch Abort
|
||||
exceptionsPage[4] = MAKE_BRANCH(exceptionsPage + 4, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 16) - 20); //Data Abort
|
||||
exceptionsPage[7] = MAKE_BRANCH(exceptionsPage + 7, (u8 *)freeSpace + *(u32 *)(arm11_exceptions + 4) - 20); //FIQ
|
||||
|
||||
for(u32 *pos = freeSpace; pos < (u32 *)((u8 *)freeSpace + arm11_exceptions_size - 20); pos++)
|
||||
{
|
||||
switch(*pos)
|
||||
{
|
||||
case 0xFFFF3000: *pos = stackAddr; break;
|
||||
case 0xEBFFFFFE: *pos = MAKE_BRANCH_LINK(pos, initFPU); break;
|
||||
case 0xEAFFFFFE: *pos = MAKE_BRANCH(pos, mcuReboot); break;
|
||||
case 0xE12FFF1C: pos[1] = 0xFFFF0000 + 4 * (u32)(freeSpace - exceptionsPage) + pos[1] - 20; break; // bx r12 (mainHandler)
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void hexItoa(u32 n, char *out)
|
||||
{
|
||||
const char hexDigits[] = "0123456789ABCDEF";
|
||||
@@ -77,29 +113,43 @@ void detectAndProcessExceptionDumps(void)
|
||||
|
||||
const char *registerNames[] = {
|
||||
"R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12",
|
||||
"SP", "LR", "PC", "CPSR"
|
||||
"SP", "LR", "PC", "CPSR", "FPEXC"
|
||||
};
|
||||
|
||||
char hexstring[] = "00000000";
|
||||
|
||||
vu32 *dump = (u32 *)0x25000000;
|
||||
vu32 *dump = (vu32 *)0x25000000;
|
||||
|
||||
if(dump[0] == 0xDEADC0DE && dump[1] == 0xDEADCAFE && dump[3] == 9)
|
||||
if(dump[0] == 0xDEADC0DE && dump[1] == 0xDEADCAFE && (dump[3] == 9 || (dump[3] & 0xFFFF) == 11))
|
||||
{
|
||||
char path[41] = "/luma/dumps/arm9";
|
||||
char path9[41] = "/luma/dumps/arm9";
|
||||
char path11[42] = "/luma/dumps/arm11";
|
||||
char fileName[] = "crash_dump_00000000.dmp";
|
||||
|
||||
findDumpFile(path, fileName);
|
||||
|
||||
path[16] = '/';
|
||||
memcpy(&path[17], fileName, sizeof(fileName));
|
||||
|
||||
fileWrite((void *)dump, path, dump[5]);
|
||||
if(dump[3] == 9)
|
||||
{
|
||||
findDumpFile(path9, fileName);
|
||||
path9[16] = '/';
|
||||
memcpy(&path9[17], fileName, sizeof(fileName));
|
||||
fileWrite((void *)dump, path9, dump[5]);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
findDumpFile(path11, fileName);
|
||||
path11[17] = '/';
|
||||
memcpy(&path11[18], fileName, sizeof(fileName));
|
||||
fileWrite((void *)dump, path11, dump[5]);
|
||||
}
|
||||
|
||||
|
||||
char arm11Str[] = "Processor: ARM11 (core X)";
|
||||
if((dump[3] & 0xFFFF) == 11) arm11Str[28] = '0' + (char)(dump[3] >> 16);
|
||||
|
||||
initScreens();
|
||||
|
||||
drawString("An exception occurred", 10, 10, COLOR_RED);
|
||||
int posY = drawString("Processor: ARM9", 10, 30, COLOR_WHITE) + SPACING_Y;
|
||||
int posY = drawString(((dump[3] & 0xFFFF) == 11) ? arm11Str : "Processor: ARM9", 10, 30, COLOR_WHITE) + SPACING_Y;
|
||||
posY = drawString("Exception type: ", 10, posY, COLOR_WHITE);
|
||||
posY = drawString(handledExceptionNames[dump[4]], 10 + 16 * SPACING_X, posY, COLOR_WHITE);
|
||||
|
||||
@@ -110,7 +160,7 @@ void detectAndProcessExceptionDumps(void)
|
||||
hexItoa(dump[10 + i], hexstring);
|
||||
posY = drawString(hexstring, 10 + 7 * SPACING_X, posY, COLOR_WHITE);
|
||||
|
||||
if(i != 16)
|
||||
if(dump[3] != 9 || i != 16)
|
||||
{
|
||||
posY = drawString(registerNames[i + 1], 10 + 22 * SPACING_X, posY, COLOR_WHITE);
|
||||
hexItoa(dump[10 + i + 1], hexstring);
|
||||
@@ -122,7 +172,7 @@ void detectAndProcessExceptionDumps(void)
|
||||
|
||||
posY += 2 * SPACING_Y;
|
||||
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;
|
||||
posY = drawString((dump[3] == 9) ? path9 : path11, 10, posY, COLOR_WHITE) + 2 * SPACING_Y;
|
||||
drawString("Press any button to shutdown", 10, posY, COLOR_WHITE);
|
||||
|
||||
waitInput();
|
||||
|
||||
@@ -8,4 +8,5 @@
|
||||
#include "types.h"
|
||||
|
||||
void installArm9Handlers(void);
|
||||
void installArm11Handlers(u32 *exceptionsPage, u32 stackAddr);
|
||||
void detectAndProcessExceptionDumps(void);
|
||||
@@ -86,7 +86,7 @@ void main(void)
|
||||
if(DEVMODE)
|
||||
{
|
||||
detectAndProcessExceptionDumps();
|
||||
installArm9Handlers();
|
||||
installArm9Handlers();
|
||||
}
|
||||
|
||||
bootType = 0;
|
||||
@@ -331,7 +331,12 @@ static inline void patchNativeFirm(u32 nandType, u32 emuHeader, u32 a9lhMode)
|
||||
{
|
||||
//Apply UNITINFO patch
|
||||
if(DEVMODE == 2) patchUnitInfoValueSet(arm9Section, section[2].size);
|
||||
|
||||
|
||||
//Install arm11 exception handlers
|
||||
u32 stackAddress;
|
||||
u32 *exceptionsPage = getInfoForArm11ExceptionHandlers(arm11Section1, section[1].size, &stackAddress);
|
||||
//installArm11Handlers(exceptionsPage, stackAddress);
|
||||
|
||||
//Make FCRAM (and VRAM as a side effect) globally executable from arm11 kernel
|
||||
patchKernelFCRAMAndVRAMMappingPermissions(arm11Section1, section[1].size);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "config.h"
|
||||
#include "../build/rebootpatch.h"
|
||||
|
||||
static u32 *exceptionsPage = NULL;
|
||||
|
||||
u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr)
|
||||
{
|
||||
u8 *off = memsearch(pos, "ess9", size, 4);
|
||||
@@ -18,6 +20,20 @@ u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr)
|
||||
return off - 0x204 + (*(u32 *)(off - 0x64) * 0x200) + 0x200;
|
||||
}
|
||||
|
||||
u32* getInfoForArm11ExceptionHandlers(u8 *pos, u32 size, u32 *stackAddr)
|
||||
{
|
||||
//This function has to succeed. Crash if it doesn't (we'll get an exception dump of it anyways)
|
||||
|
||||
const u8 callExceptionDispatcherPattern[] = {0x0F, 0x00, 0xBD, 0xE8, 0x13, 0x00, 0x02, 0xF1};
|
||||
const u8 exceptionsPagePattern[] = {0x00, 0xB0, 0x9C, 0xE5};
|
||||
|
||||
*stackAddr = *((u32 *)memsearch(pos, callExceptionDispatcherPattern, size, 8) + 3);
|
||||
|
||||
if(exceptionsPage == NULL) exceptionsPage = (u32 *)memsearch(pos, exceptionsPagePattern, size, 4) - 0xB;
|
||||
|
||||
return exceptionsPage;
|
||||
}
|
||||
|
||||
void patchSignatureChecks(u8 *pos, u32 size)
|
||||
{
|
||||
const u16 sigPatch[2] = {0x2000, 0x4770};
|
||||
@@ -152,7 +168,7 @@ void reimplementSvcBackdoor(u8 *pos, u32 size)
|
||||
|
||||
const u8 pattern[] = {0x00, 0xB0, 0x9C, 0xE5}; //cpsid aif
|
||||
|
||||
u32 *exceptionsPage = (u32 *)memsearch(pos, pattern, size, 4) - 0xB;
|
||||
if(exceptionsPage == NULL) exceptionsPage = (u32 *)memsearch(pos, pattern, size, 4) - 0xB;
|
||||
|
||||
u32 svcOffset = (-((exceptionsPage[2] & 0xFFFFFF) << 2) & (0xFFFFFF << 2)) - 8; //Branch offset + 8 for prefetch
|
||||
u32 *svcTable = (u32 *)(pos + *(u32 *)(pos + 0xFFFF0008 - svcOffset - 0xFFF00000 + 8) - 0xFFF00000); //SVC handler address
|
||||
|
||||
@@ -16,6 +16,7 @@ typedef struct patchData {
|
||||
} patchData;
|
||||
|
||||
u8 *getProcess9(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr);
|
||||
u32* getInfoForArm11ExceptionHandlers(u8 *pos, u32 size, u32 *stackAddr);
|
||||
void patchSignatureChecks(u8 *pos, u32 size);
|
||||
void patchTitleInstallMinVersionCheck(u8 *pos, u32 size);
|
||||
void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr);
|
||||
|
||||
Reference in New Issue
Block a user