Skip to content

Commit

Permalink
Fix DSi Mode related setup (#2506)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzooone authored Jan 13, 2025
1 parent 3b3a50d commit 79e69a6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
3 changes: 3 additions & 0 deletions slot1launch/bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ endif
UNIVERSAL := ../../universal
TARGET := load
BUILD := build
DSIMODE_FULL_SOURCES := source/twltool source/polarssl source/gm9i
SOURCES := source $(UNIVERSAL)/source/tonccpy
#SOURCES := source $(UNIVERSAL)/source/tonccpy $(DSIMODE_FULL_SOURCES)
INCLUDES := build source $(UNIVERSAL)/include
#INCLUDES := build source $(UNIVERSAL)/include $(DSIMODE_FULL_SOURCES)
DATA := ../data
SPECS := specs

Expand Down
39 changes: 29 additions & 10 deletions slot1launch/bootloader/source/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

#define REG_GPIO_WIFI *(vu16*)0x4004C04

//#define FULL_DSI_MODE_ENABLED

#include "common.h"
#include "dmaTwl.h"
#include "common/tonccpy.h"
Expand All @@ -61,13 +63,15 @@
#include "hook.h"
#include "find.h"

/*#include "gm9i/crypto.h"
#ifdef FULL_DSI_MODE_ENABLED
#include "gm9i/crypto.h"
#include "gm9i/f_xy.h"
#include "twltool/dsi.h"
#include "u128_math.h"*/

#include "u128_math.h"
#endif

//extern u32 dsiMode; // Not working?
extern bool __dsimode;
extern u32 dsiMode;
extern u32 language;
extern u32 sdAccess;
extern u32 scfgUnlock;
Expand Down Expand Up @@ -728,7 +732,8 @@ static bool ROMsupportsDsiMode(const tNDSHeader* ndsHeader) {
return (ndsHeader->unitCode > 0);
}

/*void decrypt_modcrypt_area(dsi_context* ctx, u8 *buffer, unsigned int size)
#ifdef FULL_DSI_MODE_ENABLED
void decrypt_modcrypt_area(dsi_context* ctx, u8 *buffer, unsigned int size)
{
uint32_t len = size / 0x10;
u8 block[0x10];
Expand All @@ -740,7 +745,8 @@ static bool ROMsupportsDsiMode(const tNDSHeader* ndsHeader) {
buffer+=0x10;
len--;
}
}*/
}
#endif

int arm7_loadBinary (const tDSiHeader* dsiHeaderTemp) {
u32 errorCode;
Expand Down Expand Up @@ -799,6 +805,10 @@ void arm7_startBinary (void) {
while (REG_VCOUNT!=191);
while (REG_VCOUNT==191);

REG_IE = 0;
REG_IF = ~0;
REG_AUXIE = 0;
REG_AUXIF = ~0;
// Start ARM7
VoidFn arm7code = (VoidFn)ndsHeader->arm7executeAddress;
arm7code();
Expand Down Expand Up @@ -915,6 +925,7 @@ void arm7_main (void) {

initMBK();

__dsimode = dsiMode;
int errorCode;

// Wait for ARM9 to at least start
Expand Down Expand Up @@ -944,9 +955,13 @@ void arm7_main (void) {
if (my_isDSiMode()) {
if (twlMode == 2) {
dsiModeConfirmed = twlMode;
} /*else {
} else {
#ifdef FULL_DSI_MODE_ENABLED
dsiModeConfirmed = twlMode && ROMsupportsDsiMode(&dsiHeaderTemp->ndshdr);
}*/
#else
dsiModeConfirmed = 0;
#endif
}
}

if (dsiModeConfirmed) {
Expand All @@ -957,7 +972,8 @@ void arm7_main (void) {
cardRead((u32)dsiHeaderTemp->arm7iromOffset, (u32*)dsiHeaderTemp->arm7idestination, dsiHeaderTemp->arm7ibinarySize);
}

/*uint8_t *target = (uint8_t *)0x02FFC000 ;
#ifdef FULL_DSI_MODE_ENABLED
uint8_t *target = (uint8_t *)0x02FFC000 ;

if (target[0x01C] & 2) {
u8 key[16] = {0} ;
Expand Down Expand Up @@ -1003,7 +1019,8 @@ void arm7_main (void) {
for (int i=0;i<4;i++) {
((uint32_t *)(target+0x220))[i] = 0;
}
}*/
}
#endif
}

ndsHeader = loadHeader(dsiHeaderTemp);
Expand Down Expand Up @@ -1049,6 +1066,8 @@ void arm7_main (void) {
if (!sdAccess) {
REG_SCFG_EXT = 0x93FBFB06;
}
// Used by ARM7 binaries to determine DSi mode...
toncset((u8*)0x0380FFC0, 0, 0x10);
}
}

Expand Down
2 changes: 2 additions & 0 deletions slot1launch/bootloader/source/main.arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ void __attribute__((target("arm"))) arm9_main (void) {

// arm9_errorOutput (*(u32*)(first), true);

REG_IE = 0;
REG_IF = ~0;
VoidFn arm9code = (VoidFn)ndsHeader->arm9executeAddress;
arm9code();
}
Expand Down

0 comments on commit 79e69a6

Please sign in to comment.