Skip to content

Commit 2a2b2c7

Browse files
committed
Fix 32KB DLDI workaround for homebrew made with libnds2
1 parent 7d8ec9e commit 2a2b2c7

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

settings/bootloader/source/dldi_patcher.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) {
168168
tonccpy (pAH+DO_code, bootloader, bootsize);
169169
*(u32*)0x02FF4010 = (u32)pAH+DO_code;
170170

171+
const u32 a9exeAddress = *(u32*)0x02FFFE24;
172+
u32* a9exe = (u32*)a9exeAddress;
173+
const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D);
174+
171175
// Relocate DLDI file to bootstub RAM space
172-
pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180);
176+
pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180);
173177
toncset (pAH, 0, 0x8000);
174178

175179
memOffset = (addr_t)pAH;

title/bootloader/source/dldi_patcher.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) {
168168
tonccpy (pAH+DO_code, bootloader, bootsize);
169169
*(u32*)0x02FF4010 = (u32)pAH+DO_code;
170170

171+
const u32 a9exeAddress = *(u32*)0x02FFFE24;
172+
u32* a9exe = (u32*)a9exeAddress;
173+
const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D);
174+
171175
// Relocate DLDI file to bootstub RAM space
172-
pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180);
176+
pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180);
173177
toncset (pAH, 0, 0x8000);
174178

175179
memOffset = (addr_t)pAH;

universal/bootloader_app/source/dldi_patcher.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) {
168168
tonccpy (pAH+DO_code, bootloader, bootsize);
169169
*(u32*)0x02FF4010 = (u32)pAH+DO_code;
170170

171+
const u32 a9exeAddress = *(u32*)0x02FFFE24;
172+
u32* a9exe = (u32*)a9exeAddress;
173+
const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D);
174+
171175
// Relocate DLDI file to bootstub RAM space
172-
pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180);
176+
pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180);
173177
toncset (pAH, 0, 0x8000);
174178

175179
memOffset = (addr_t)pAH;

universal/bootloader_menu/source/dldi_patcher.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ bool dldiPatchBinary (data_t *binData, u32 binSize) {
168168
tonccpy (pAH+DO_code, bootloader, bootsize);
169169
*(u32*)0x02FF4010 = (u32)pAH+DO_code;
170170

171+
const u32 a9exeAddress = *(u32*)0x02FFFE24;
172+
u32* a9exe = (u32*)a9exeAddress;
173+
const bool libnds2 = (a9exe[0] == 0xEA000007 && a9exe[1] == 0x39444F4D);
174+
171175
// Relocate DLDI file to bootstub RAM space
172-
pAH = (data_t*)(dsiMode&&!dsMode ? 0x02FF4180 : 0x023F4180);
176+
pAH = (data_t*)(dsiMode&&!dsMode ? (libnds2 ? 0x02FE8000 : 0x02FF4180) : 0x023F4180);
173177
toncset (pAH, 0, 0x8000);
174178

175179
memOffset = (addr_t)pAH;

0 commit comments

Comments
 (0)