Minor cleanup

This commit is contained in:
Aurora 2016-08-30 21:50:04 +02:00
parent 61305688fd
commit b6d91375a5
6 changed files with 14 additions and 18 deletions

View File

@ -47,7 +47,7 @@ void installArm9Handlers(void)
} }
} }
void installArm11Handlers(u32 *exceptionsPage, u32 stackAddr, u32 codeSetOffset) void installArm11Handlers(u32 *exceptionsPage, u32 stackAddress, u32 codeSetOffset)
{ {
u32 *initFPU; u32 *initFPU;
for(initFPU = exceptionsPage; initFPU < (exceptionsPage + 0x400) && (initFPU[0] != 0xE59F0008 || initFPU[1] != 0xE5900000); initFPU++); for(initFPU = exceptionsPage; initFPU < (exceptionsPage + 0x400) && (initFPU[0] != 0xE59F0008 || initFPU[1] != 0xE5900000); initFPU++);
@ -70,7 +70,7 @@ void installArm11Handlers(u32 *exceptionsPage, u32 stackAddr, u32 codeSetOffset)
{ {
switch(*pos) //Perform relocations switch(*pos) //Perform relocations
{ {
case 0xFFFF3000: *pos = stackAddr; break; case 0xFFFF3000: *pos = stackAddress; break;
case 0xEBFFFFFE: *pos = MAKE_BRANCH_LINK(pos, initFPU); break; case 0xEBFFFFFE: *pos = MAKE_BRANCH_LINK(pos, initFPU); break;
case 0xEAFFFFFE: *pos = MAKE_BRANCH(pos, mcuReboot); break; case 0xEAFFFFFE: *pos = MAKE_BRANCH(pos, mcuReboot); break;
case 0xE12FFF1C: pos[1] = 0xFFFF0000 + 4 * (u32)(freeSpace - exceptionsPage) + pos[1] - 32; break; //bx r12 (mainHandler) case 0xE12FFF1C: pos[1] = 0xFFFF0000 + 4 * (u32)(freeSpace - exceptionsPage) + pos[1] - 32; break; //bx r12 (mainHandler)

View File

@ -43,5 +43,5 @@ typedef struct __attribute__((packed))
} ExceptionDumpHeader; } ExceptionDumpHeader;
void installArm9Handlers(void); void installArm9Handlers(void);
void installArm11Handlers(u32 *exceptionsPage, u32 stackAddr, u32 codeSetOffset); void installArm11Handlers(u32 *exceptionsPage, u32 stackAddress, u32 codeSetOffset);
void detectAndProcessExceptionDumps(void); void detectAndProcessExceptionDumps(void);

View File

@ -348,9 +348,8 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
if(DEV_OPTIONS != 2) if(DEV_OPTIONS != 2)
{ {
//Install arm11 exception handlers //Install arm11 exception handlers
u32 stackAddress, u32 codeSetOffset;
codeSetOffset; u32 stackAddress = getInfoForArm11ExceptionHandlers(arm11Section1, section[1].size, &codeSetOffset);
getInfoForArm11ExceptionHandlers(arm11Section1, section[1].size, &stackAddress, &codeSetOffset);
installArm11Handlers(arm11ExceptionsPage, stackAddress, codeSetOffset); installArm11Handlers(arm11ExceptionsPage, stackAddress, codeSetOffset);
//Kernel9/Process9 debugging //Kernel9/Process9 debugging

View File

@ -110,8 +110,7 @@ void loadPayload(u32 pressed)
else if(pressed & BUTTON_R1) pattern = PATTERN("r"); else if(pressed & BUTTON_R1) pattern = PATTERN("r");
else if(pressed & BUTTON_A) pattern = PATTERN("a"); else if(pressed & BUTTON_A) pattern = PATTERN("a");
else if(pressed & BUTTON_START) pattern = PATTERN("start"); else if(pressed & BUTTON_START) pattern = PATTERN("start");
else if(pressed & BUTTON_SELECT) pattern = PATTERN("select"); else pattern = PATTERN("select");
else pattern = "nlc.bin";
DIR dir; DIR dir;
FILINFO info; FILINFO info;
@ -133,8 +132,6 @@ void loadPayload(u32 pressed)
concatenateStrings(path, info.altname); concatenateStrings(path, info.altname);
loaderAddress[1] = fileRead((void *)0x24F00000, path); loaderAddress[1] = fileRead((void *)0x24F00000, path);
if(pattern[0] == 'n') f_unlink(path);
flushDCacheRange(loaderAddress, loader_size); flushDCacheRange(loaderAddress, loader_size);
flushICacheRange(loaderAddress, loader_size); flushICacheRange(loaderAddress, loader_size);

View File

@ -237,19 +237,19 @@ void patchTwlBg(u8 *pos)
src2[1] = 0xE800 | ((((u32)dst - (u32)src2 - 4) & 0xFFF) >> 1); src2[1] = 0xE800 | ((((u32)dst - (u32)src2 - 4) & 0xFFF) >> 1);
} }
void getInfoForArm11ExceptionHandlers(u8 *pos, u32 size, u32 *stackAddr, u32 *codeSetOffset) u32 getInfoForArm11ExceptionHandlers(u8 *pos, u32 size, u32 *codeSetOffset)
{ {
//This function has to succeed. Crash if it doesn't (we'll get an exception dump of it anyways) //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 callExceptionDispatcherPattern[] = {0x0F, 0x00, 0xBD, 0xE8, 0x13, 0x00, 0x02, 0xF1};
const u8 getTitleIDFromCodeSetPattern[] = {0xDC, 0x05, 0xC0, 0xE1, 0x20, 0x04, 0xA0, 0xE1}; const u8 getTitleIDFromCodeSetPattern[] = {0xDC, 0x05, 0xC0, 0xE1, 0x20, 0x04, 0xA0, 0xE1};
*stackAddr = *((u32 *)memsearch(pos, callExceptionDispatcherPattern, size, 8) + 3);
u32 *loadCodeSet = (u32 *)memsearch(pos, getTitleIDFromCodeSetPattern, size, 8); u32 *loadCodeSet = (u32 *)memsearch(pos, getTitleIDFromCodeSetPattern, size, 8);
while((*loadCodeSet >> 20) != 0xE59 || ((*loadCodeSet >> 12) & 0xF) != 0) //ldr r0, [rX, #offset] while((*loadCodeSet >> 20) != 0xE59 || ((*loadCodeSet >> 12) & 0xF) != 0) //ldr r0, [rX, #offset]
loadCodeSet--; loadCodeSet--;
*codeSetOffset = *loadCodeSet & 0xFFF; *codeSetOffset = *loadCodeSet & 0xFFF;
return *((u32 *)memsearch(pos, callExceptionDispatcherPattern, size, 8) + 3);
} }
void patchArm9ExceptionHandlersInstall(u8 *pos, u32 size) void patchArm9ExceptionHandlersInstall(u8 *pos, u32 size)
@ -286,7 +286,7 @@ void patchArm9ExceptionHandlersInstall(u8 *pos, u32 size)
} }
} }
void patchSvcBreak9(u8 *pos, u32 size, u32 k9Address) void patchSvcBreak9(u8 *pos, u32 size, u32 kernel9Address)
{ {
//Stub svcBreak with "bkpt 65535" so we can debug the panic. //Stub svcBreak with "bkpt 65535" so we can debug the panic.
//Thanks @yellows8 and others for mentioning this idea on #3dsdev. //Thanks @yellows8 and others for mentioning this idea on #3dsdev.
@ -295,7 +295,7 @@ void patchSvcBreak9(u8 *pos, u32 size, u32 k9Address)
u32 *arm9SvcTable = (u32 *)memsearch(pos, svcHandlerPattern, size, 4); u32 *arm9SvcTable = (u32 *)memsearch(pos, svcHandlerPattern, size, 4);
while(*arm9SvcTable) arm9SvcTable++; //Look for SVC0 (NULL) while(*arm9SvcTable) arm9SvcTable++; //Look for SVC0 (NULL)
u32 *addr = (u32 *)(pos + arm9SvcTable[0x3C] - k9Address); u32 *addr = (u32 *)(pos + arm9SvcTable[0x3C] - kernel9Address);
*addr = 0xE12FFF7F; *addr = 0xE12FFF7F;
} }

View File

@ -61,9 +61,9 @@ void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space);
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType); void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType);
void patchTwlBg(u8 *pos); void patchTwlBg(u8 *pos);
void getInfoForArm11ExceptionHandlers(u8 *pos, u32 size, u32 *stackAddr, u32 *codeSetOffset); u32 getInfoForArm11ExceptionHandlers(u8 *pos, u32 size, u32 *codeSetOffset);
void patchArm9ExceptionHandlersInstall(u8 *pos, u32 size); void patchArm9ExceptionHandlersInstall(u8 *pos, u32 size);
void patchSvcBreak9(u8 *pos, u32 size, u32 k9Address); void patchSvcBreak9(u8 *pos, u32 size, u32 kernel9Address);
void patchSvcBreak11(u8 *pos, u32 *arm11SvcTable); void patchSvcBreak11(u8 *pos, u32 *arm11SvcTable);
void patchKernel9Panic(u8 *pos, u32 size, FirmwareType firmType); void patchKernel9Panic(u8 *pos, u32 size, FirmwareType firmType);
void patchKernel11Panic(u8 *pos, u32 size); void patchKernel11Panic(u8 *pos, u32 size);