#ifdef BOOTHB #include #include #include #endif #include "common.h" #include "arm9stub_bin.h" #include "arm7stub_bin.h" #ifndef BOOTHB #include "ndsloader_lz.h" #endif //#include "ndsloader_nds.h" #define ARM9STUBVMA 0x02ffa000 int DSi_mode = 0; void __attribute__ ((long_call)) resetArm9(); void bootstrapArm7(); void ndsloadstub(); void bootstrapArm7DSiSync(); int sendipcmsg(u32 channel, u32 data); void* memset16(void* buffer, int val, size_t len); #ifndef BOOTHB //#define CAMINIT #endif #ifndef BOOTHB void ipx_caminit(); #endif #ifndef BOOTHB #ifdef NANDHAX void nandread(); void nandread_asm(); #endif #endif #ifndef BOOTHB int main(void) #else int generictwlpayload_main(void) #endif { #ifdef TWL if(((*((vu32*)0x04004000)) & 3)==1)DSi_mode = 1; #endif #ifdef CAMINIT ipx_caminit(); #endif #ifndef BOOTHB #ifdef NANDHAX nandread(); #endif #endif #ifndef BOOTHB REG_DISPCNT = 0; REG_DISPCNT_SUB = 0; REG_MASTER_BRIGHT = 0; REG_MASTER_BRIGHT_SUB = 0; #endif resetArm9(); bootstrapArm7(); while(1); return 0; } #ifndef BOOTHB #ifdef NANDHAX void nandread() { if(*((u32*)0x02ffe230) != 0x4b344445 && *((u32*)0x02ffe230) != 0x484e4145)return; void (*FS_InitCtx)(u8*); int (*FS_Open)(u8*, char*, u32); int (*FS_Close)(u8*); int (*FS_Read)(u8*, u8*, u32); u8 ctx[0x48]; if(*((u32*)0x02ffe230) == 0x4b344445) { FS_InitCtx = (void*)0x20a1c6c; FS_Open = (void*)0x20a1ea4; FS_Close = (void*)0x20a1f28; } else if(*((u32*)0x02ffe230) == 0x484e4145)//launcher. note that this launcher stuff is for on-the-fly patching stuff, no nand-based only hax. { FS_InitCtx = (void*)0x26baf99; FS_Open = (void*)0x26bb4c5; FS_Close = (void*)0x26bb511; FS_Read = (void*)0x26bb581; } if(*((u32*)0x02ffe230) == 0x4b344445) { nandread_asm(); DC_FlushAll(); REG_IME = 1; FS_InitCtx(ctx); if(FS_Open(ctx, "nand:/", 1)==1)FS_Close(ctx); REG_IME = 0; } else if(*((u32*)0x02ffe230) == 0x484e4145) { REG_IME = 1; FS_InitCtx(ctx); if(FS_Open(ctx, "nand:/sys/arm7hax.bin", 1)==1) { FS_Read(ctx, (void*)0x3780260, 0x40);//this is the beginning of the nand_read_sectors func. since this data won't get written there until after that func returns, another read is triggered below. FS_Close(ctx); FS_InitCtx(ctx); if(FS_Open(ctx, "nand:/", 1)==1)FS_Close(ctx);//unless the arm7hax code returns,(my local code doesn't) this will hang. } REG_IME = 0; } } #endif #endif #ifdef BOOTHB void generictwlpayload_setargv(int argc, char **argv) { u32 *param = (u32*)(BOOTLDR_NDS-0x1000-8); char *argv_params = (char*)(BOOTLDR_NDS-0x1000); int i, pos = 0; if(argc==0)*param = 0; if(argc) { memset(param, 0, 0x1000); *param = 0x56475241; param[1] = (u32)argc; for(i=0; i> 8; #endif DC_FlushAll(); DC_InvalidateAll(); IC_InvalidateAll(); BOOTFLAG = 0; VRAM_C_CR = VRAM_ENABLE | VRAM_C_LCD; #ifndef BOOTHB NDSHEADER->arm7executeAddress = 0x06000000; #endif memcpy16((void*)ARM9STUBVMA, arm9stub_bin, arm9stub_bin_size); memcpy16(VRAM_C, arm7stub_bin, arm7stub_bin_size); VRAM_C_CR = VRAM_ENABLE | VRAM_C_ARM7_0x06000000; DC_FlushAll(); DC_InvalidateAll(); IC_InvalidateAll(); #ifdef BOOTHB resetARM7(0x06000000); #endif func_ptr(); } void bootstrapArm7DSiSync() { vu16 *sync = (vu16*)0x02fffc24; vu16 temp; sync[2] = 3;//When this is 3, Arm7 TWL SDK bootstub skips 7i bin loading, otherwise when 2 it loads the 7i bin. //sync[2] = 2; temp = sync[1]; do { sync[0]++; } while(sync[1]==temp); temp = sync[1]; do { sync[0]++; } while(sync[1]==temp); } #ifndef BOOTHB void* memset(void* buffer, int val, size_t len) { vu32 *buf = (vu32*)buffer; while(len>0) { *buf = val; buf++; len-=4; } return buffer; } #endif void* memcpy16(void* a, const void* b, size_t len) { vu16 *bufa = (vu16*)a; vu16 *bufb = (vu16*)b; while(len>0) { *bufa = *bufb; bufa++; bufb++; len-=2; } return a; } void* memset16(void* buffer, int val, size_t len) { vu16 *buf = (vu16*)buffer; while(len>0) { *buf = val; buf++; len-=2; } return buffer; }