From 244409fc983fd7ded1c1003848215a5e42cbd4ca Mon Sep 17 00:00:00 2001 From: TuxSH Date: Thu, 7 Jun 2018 16:44:29 +0200 Subject: [PATCH] Change k11 mapping logic again --- arm9/source/patches.c | 4 ++-- k11_extension/source/main.c | 7 ++++--- k11_extension/source/svc.c | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arm9/source/patches.c b/arm9/source/patches.c index eca3eeb..ab75403 100644 --- a/arm9/source/patches.c +++ b/arm9/source/patches.c @@ -135,7 +135,7 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 //Our kernel11 extension is initially loaded in VRAM u32 kextTotalSize = *(u32 *)0x18000020 - 0x40000000; - u32 dstKextPA = (ISN3DS ? 0x2E000000 : 0x26C00000) - (0x1000 + kextTotalSize); + u32 dstKextPA = (ISN3DS ? 0x2E000000 : 0x26C00000) - kextTotalSize; u32 *hookVeneers = (u32 *)*freeK11Space; u32 relocBase = 0xFFFF0000 + (*freeK11Space - (u8 *)arm11ExceptionsPage); @@ -176,7 +176,7 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 *off = MAKE_BRANCH_LINK(baseK11VA + ((u8 *)off - pos), relocBase + 24); struct KExtParameters *p = (struct KExtParameters *)(*(u32 *)0x18000024 - 0x40000000 + 0x18000000); - p->basePA = dstKextPA + 0x1000; + p->basePA = dstKextPA; for(u32 i = 0; i < 4; i++) { diff --git a/k11_extension/source/main.c b/k11_extension/source/main.c index bce89c2..fadb3a4 100644 --- a/k11_extension/source/main.c +++ b/k11_extension/source/main.c @@ -41,11 +41,13 @@ struct KExtParameters CfwInfo cfwInfo; } kExtParameters = { .basePA = 0x12345678 }; // place this in .data +static ALIGN(1024) u32 L2TableFor0x40000000[256] = {0}; + void relocateAndSetupMMU(u32 coreId, u32 *L1Table) { struct KExtParameters *p0 = (struct KExtParameters *)((u32)&kExtParameters - 0x40000000 + 0x18000000); struct KExtParameters *p = (struct KExtParameters *)((u32)&kExtParameters - 0x40000000 + p0->basePA); - u32 *L2Table = (u32 *)(p0->basePA - 0x1000); + u32 *L2Table = (u32 *)((u32)L2TableFor0x40000000 - 0x40000000 + p0->basePA); if(coreId == 0) { @@ -56,7 +58,6 @@ void relocateAndSetupMMU(u32 coreId, u32 *L1Table) // Map the kernel ext to 0x40000000 // 4KB extended small pages: [SYS:RW USR:-- X TYP:NORMAL SHARED OUTER NOCACHE, INNER CACHED WB WA] - memset(L2Table, 0, 4 * 256); for(u32 offset = 0; offset < (u32)(__end__ - __start__); offset += 0x1000) L2Table[offset >> 12] = (p0->basePA + offset) | 0x516; @@ -258,7 +259,7 @@ void main(FcramLayout *layout, KCoreContext *ctxs) u32 TTBCR_; s64 nb; - layout->systemSize -= 0x1000 + __end__ - __start__; + layout->systemSize -= __end__ - __start__; fcramLayout = *layout; coreCtxs = ctxs; diff --git a/k11_extension/source/svc.c b/k11_extension/source/svc.c index 7fecfef..50ac06d 100644 --- a/k11_extension/source/svc.c +++ b/k11_extension/source/svc.c @@ -100,7 +100,7 @@ void *svcHook(u8 *pageEnd) case 0x17: if(strcmp(codeSetOfProcess(currentProcess)->processName, "pm") == 0) // only called twice in pm, by the same function { - *(vu32 *)(configPage + 0x44) += 0x1000 + __end__ - __start__; + *(vu32 *)(configPage + 0x44) += __end__ - __start__; doingVeryShittyPmResLimitWorkaround = true; } return officialSVCs[0x17]; @@ -127,7 +127,7 @@ void *svcHook(u8 *pageEnd) case 0x79: if(doingVeryShittyPmResLimitWorkaround) { - *(vu32 *)(configPage + 0x44) -= 0x1000 + __end__ - __start__; + *(vu32 *)(configPage + 0x44) -= __end__ - __start__; doingVeryShittyPmResLimitWorkaround = false; } return officialSVCs[0x79];