From e1bf1d19d48724cce564aae6768295ce8eeb81c8 Mon Sep 17 00:00:00 2001 From: RocketRobz Date: Wed, 13 Nov 2024 21:50:46 -0700 Subject: [PATCH] Forgot DLDI runs on arm7 in libnds2 homebrew --- settings/bootloader/source/dldi_patcher.c | 12 ++++++------ title/bootloader/source/dldi_patcher.c | 12 ++++++------ universal/bootloader_app/source/dldi_patcher.c | 12 ++++++------ universal/bootloader_menu/source/dldi_patcher.c | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/settings/bootloader/source/dldi_patcher.c b/settings/bootloader/source/dldi_patcher.c index 8982d4e4f9..02dfc99d3c 100644 --- a/settings/bootloader/source/dldi_patcher.c +++ b/settings/bootloader/source/dldi_patcher.c @@ -156,7 +156,11 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { const bool largeDldi = (pDH[DO_driverSize] > pAH[DO_allocatedSpace]); if (largeDldi) { - if (memOffset < 0x02000000 || memOffset >= 0x03000000) { + const u32 a9exeAddress = *(u32*)0x02FFFE24; + u32* a9exe = (u32*)a9exeAddress; + const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); + + if (!libnds2 && (memOffset < 0x02000000 || memOffset >= 0x03000000)) { // Not enough space for patch in arm7 WRAM return false; } @@ -168,12 +172,8 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { tonccpy (pAH+DO_code, bootloader, bootsize); *(u32*)0x02FF4010 = (u32)pAH+DO_code; - const u32 a9exeAddress = *(u32*)0x02FFFE24; - u32* a9exe = (u32*)a9exeAddress; - const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); - // Relocate DLDI file to bootstub RAM space - pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180); + pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180); toncset (pAH, 0, 0x8000); memOffset = (addr_t)pAH; diff --git a/title/bootloader/source/dldi_patcher.c b/title/bootloader/source/dldi_patcher.c index 8982d4e4f9..02dfc99d3c 100644 --- a/title/bootloader/source/dldi_patcher.c +++ b/title/bootloader/source/dldi_patcher.c @@ -156,7 +156,11 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { const bool largeDldi = (pDH[DO_driverSize] > pAH[DO_allocatedSpace]); if (largeDldi) { - if (memOffset < 0x02000000 || memOffset >= 0x03000000) { + const u32 a9exeAddress = *(u32*)0x02FFFE24; + u32* a9exe = (u32*)a9exeAddress; + const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); + + if (!libnds2 && (memOffset < 0x02000000 || memOffset >= 0x03000000)) { // Not enough space for patch in arm7 WRAM return false; } @@ -168,12 +172,8 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { tonccpy (pAH+DO_code, bootloader, bootsize); *(u32*)0x02FF4010 = (u32)pAH+DO_code; - const u32 a9exeAddress = *(u32*)0x02FFFE24; - u32* a9exe = (u32*)a9exeAddress; - const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); - // Relocate DLDI file to bootstub RAM space - pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180); + pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180); toncset (pAH, 0, 0x8000); memOffset = (addr_t)pAH; diff --git a/universal/bootloader_app/source/dldi_patcher.c b/universal/bootloader_app/source/dldi_patcher.c index 8982d4e4f9..02dfc99d3c 100644 --- a/universal/bootloader_app/source/dldi_patcher.c +++ b/universal/bootloader_app/source/dldi_patcher.c @@ -156,7 +156,11 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { const bool largeDldi = (pDH[DO_driverSize] > pAH[DO_allocatedSpace]); if (largeDldi) { - if (memOffset < 0x02000000 || memOffset >= 0x03000000) { + const u32 a9exeAddress = *(u32*)0x02FFFE24; + u32* a9exe = (u32*)a9exeAddress; + const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); + + if (!libnds2 && (memOffset < 0x02000000 || memOffset >= 0x03000000)) { // Not enough space for patch in arm7 WRAM return false; } @@ -168,12 +172,8 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { tonccpy (pAH+DO_code, bootloader, bootsize); *(u32*)0x02FF4010 = (u32)pAH+DO_code; - const u32 a9exeAddress = *(u32*)0x02FFFE24; - u32* a9exe = (u32*)a9exeAddress; - const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); - // Relocate DLDI file to bootstub RAM space - pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180); + pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180); toncset (pAH, 0, 0x8000); memOffset = (addr_t)pAH; diff --git a/universal/bootloader_menu/source/dldi_patcher.c b/universal/bootloader_menu/source/dldi_patcher.c index 8982d4e4f9..02dfc99d3c 100644 --- a/universal/bootloader_menu/source/dldi_patcher.c +++ b/universal/bootloader_menu/source/dldi_patcher.c @@ -156,7 +156,11 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { const bool largeDldi = (pDH[DO_driverSize] > pAH[DO_allocatedSpace]); if (largeDldi) { - if (memOffset < 0x02000000 || memOffset >= 0x03000000) { + const u32 a9exeAddress = *(u32*)0x02FFFE24; + u32* a9exe = (u32*)a9exeAddress; + const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); + + if (!libnds2 && (memOffset < 0x02000000 || memOffset >= 0x03000000)) { // Not enough space for patch in arm7 WRAM return false; } @@ -168,12 +172,8 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) { tonccpy (pAH+DO_code, bootloader, bootsize); *(u32*)0x02FF4010 = (u32)pAH+DO_code; - const u32 a9exeAddress = *(u32*)0x02FFFE24; - u32* a9exe = (u32*)a9exeAddress; - const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D); - // Relocate DLDI file to bootstub RAM space - pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180); + pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180); toncset (pAH, 0, 0x8000); memOffset = (addr_t)pAH;