From b6d91375a5eff24a23f6fc55785e5f8906e1ac35 Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 30 Aug 2016 21:50:04 +0200 Subject: [PATCH] Minor cleanup --- source/exceptions.c | 4 ++-- source/exceptions.h | 2 +- source/firm.c | 5 ++--- source/fs.c | 5 +---- source/patches.c | 12 ++++++------ source/patches.h | 4 ++-- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/source/exceptions.c b/source/exceptions.c index cfe54fc..11fd75a 100644 --- a/source/exceptions.c +++ b/source/exceptions.c @@ -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; 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 { - case 0xFFFF3000: *pos = stackAddr; break; + case 0xFFFF3000: *pos = stackAddress; 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] - 32; break; //bx r12 (mainHandler) diff --git a/source/exceptions.h b/source/exceptions.h index 0d6d8ba..f21d91a 100644 --- a/source/exceptions.h +++ b/source/exceptions.h @@ -43,5 +43,5 @@ typedef struct __attribute__((packed)) } ExceptionDumpHeader; void installArm9Handlers(void); -void installArm11Handlers(u32 *exceptionsPage, u32 stackAddr, u32 codeSetOffset); +void installArm11Handlers(u32 *exceptionsPage, u32 stackAddress, u32 codeSetOffset); void detectAndProcessExceptionDumps(void); \ No newline at end of file diff --git a/source/firm.c b/source/firm.c index a251a48..375ec64 100755 --- a/source/firm.c +++ b/source/firm.c @@ -348,9 +348,8 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 if(DEV_OPTIONS != 2) { //Install arm11 exception handlers - u32 stackAddress, - codeSetOffset; - getInfoForArm11ExceptionHandlers(arm11Section1, section[1].size, &stackAddress, &codeSetOffset); + u32 codeSetOffset; + u32 stackAddress = getInfoForArm11ExceptionHandlers(arm11Section1, section[1].size, &codeSetOffset); installArm11Handlers(arm11ExceptionsPage, stackAddress, codeSetOffset); //Kernel9/Process9 debugging diff --git a/source/fs.c b/source/fs.c index e8adf2c..dd20a5a 100644 --- a/source/fs.c +++ b/source/fs.c @@ -110,8 +110,7 @@ void loadPayload(u32 pressed) else if(pressed & BUTTON_R1) pattern = PATTERN("r"); else if(pressed & BUTTON_A) pattern = PATTERN("a"); else if(pressed & BUTTON_START) pattern = PATTERN("start"); - else if(pressed & BUTTON_SELECT) pattern = PATTERN("select"); - else pattern = "nlc.bin"; + else pattern = PATTERN("select"); DIR dir; FILINFO info; @@ -133,8 +132,6 @@ void loadPayload(u32 pressed) concatenateStrings(path, info.altname); loaderAddress[1] = fileRead((void *)0x24F00000, path); - - if(pattern[0] == 'n') f_unlink(path); flushDCacheRange(loaderAddress, loader_size); flushICacheRange(loaderAddress, loader_size); diff --git a/source/patches.c b/source/patches.c index b9129a0..425e63c 100644 --- a/source/patches.c +++ b/source/patches.c @@ -237,19 +237,19 @@ void patchTwlBg(u8 *pos) 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) const u8 callExceptionDispatcherPattern[] = {0x0F, 0x00, 0xBD, 0xE8, 0x13, 0x00, 0x02, 0xF1}; 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); while((*loadCodeSet >> 20) != 0xE59 || ((*loadCodeSet >> 12) & 0xF) != 0) //ldr r0, [rX, #offset] loadCodeSet--; *codeSetOffset = *loadCodeSet & 0xFFF; + + return *((u32 *)memsearch(pos, callExceptionDispatcherPattern, size, 8) + 3); } 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. //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); while(*arm9SvcTable) arm9SvcTable++; //Look for SVC0 (NULL) - u32 *addr = (u32 *)(pos + arm9SvcTable[0x3C] - k9Address); + u32 *addr = (u32 *)(pos + arm9SvcTable[0x3C] - kernel9Address); *addr = 0xE12FFF7F; } diff --git a/source/patches.h b/source/patches.h index fe80a94..a80a393 100644 --- a/source/patches.h +++ b/source/patches.h @@ -61,9 +61,9 @@ void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space); void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType); 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 patchSvcBreak9(u8 *pos, u32 size, u32 k9Address); +void patchSvcBreak9(u8 *pos, u32 size, u32 kernel9Address); void patchSvcBreak11(u8 *pos, u32 *arm11SvcTable); void patchKernel9Panic(u8 *pos, u32 size, FirmwareType firmType); void patchKernel11Panic(u8 *pos, u32 size);