From d5ccf2939cf1723df3af219a02944296bb5f5fc7 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Fri, 23 Aug 2013 14:31:06 +0000 Subject: [PATCH] core: - add hack for firmware boot in JIT mode (JIT block size change to 12 until finish firmware boot process); --- desmume/src/MMU.cpp | 5 ++ desmume/src/NDSSystem.cpp | 61 +++++++++++++----------- desmume/src/addons/slot1_retail_nand.cpp | 4 +- desmume/src/arm_jit.cpp | 4 ++ desmume/src/arm_jit.h | 1 + desmume/src/firmware.cpp | 1 + desmume/src/firmware.h | 10 ++-- 7 files changed, 50 insertions(+), 36 deletions(-) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 42bfd142e..abdecd695 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -4193,6 +4193,11 @@ void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val) #endif //The NDS7 register can be written to only from code executed in BIOS. if (NDS_ARM7.instruct_adr > 0x3FFF) return; +#ifdef HAVE_JIT + // hack for firmware boot in JIT mode + if (CommonSettings.UseExtFirmware && CommonSettings.BootFromFirmware && firmware->loaded() && val == 1) + CommonSettings.jit_max_block_size = saveBlockSizeJIT; +#endif break; case REG_HALTCNT: diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 23d27c466..cd882495a 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -2535,13 +2535,16 @@ void NDS_Reset() } firmware = new CFIRMWARE(); - // TODO: fw_success should be global - bool fw_success = firmware->load(); + firmware->load(); //the firmware can't be booted without the roms, for the following reasons: //TBD - if (NDS_ARM7.BIOS_loaded && NDS_ARM9.BIOS_loaded && CommonSettings.BootFromFirmware && fw_success) + if (NDS_ARM7.BIOS_loaded && NDS_ARM9.BIOS_loaded && CommonSettings.BootFromFirmware && firmware->loaded()) { +#ifdef HAVE_JIT + // hack for firmware boot in JIT mode + CommonSettings.jit_max_block_size = 12; +#endif //crazymax: how would it have got whacked? dont think we need this //gameInfo.restoreSecureArea(); @@ -2599,7 +2602,7 @@ void NDS_Reset() //EDIT - whats this firmware and how is it relating to the dummy firmware below //how do these even get used? what is the purpose of unpack and why is it not used by the firmware boot process? - if (CommonSettings.UseExtFirmware && fw_success) + if (CommonSettings.UseExtFirmware && firmware->loaded()) { firmware->unpack(); firmware->loadSettings(); @@ -2721,32 +2724,32 @@ void NDS_Reset() NDS_ARM9.R[13] = NDS_ARM9.R13_usr; //n.b.: im not sure about all these, I dont know enough about arm9 svc/irq/etc modes //and how theyre named in desmume to match them up correctly. i just guessed. + + //-------------------------------- + //setup the homebrew argv + //this is useful for nitrofs apps which are emulating themselves via cflash + //struct __argv { + // int argvMagic; //!< argv magic number, set to 0x5f617267 ('_arg') if valid + // char *commandLine; //!< base address of command line, set of null terminated strings + // int length; //!< total length of command line + // int argc; //!< internal use, number of arguments + // char **argv; //!< internal use, argv pointer + //}; + std::string rompath = "fat:/" + path.RomName; + const u32 kCommandline = 0x027E0000; + //const u32 kCommandline = 0x027FFF84; + + // + _MMU_write32(0x02FFFE70, 0x5f617267); + _MMU_write32(0x02FFFE74, kCommandline); //(commandline starts here) + _MMU_write32(0x02FFFE78, rompath.size()+1); + //0x027FFF7C (argc) + //0x027FFF80 (argv) + for(size_t i=0;i(kCommandline+i, rompath[i]); + _MMU_write08(kCommandline+rompath.size(), 0); + //-------------------------------- } - - //-------------------------------- - //setup the homebrew argv - //this is useful for nitrofs apps which are emulating themselves via cflash - //struct __argv { - // int argvMagic; //!< argv magic number, set to 0x5f617267 ('_arg') if valid - // char *commandLine; //!< base address of command line, set of null terminated strings - // int length; //!< total length of command line - // int argc; //!< internal use, number of arguments - // char **argv; //!< internal use, argv pointer - //}; - std::string rompath = "fat:/" + path.RomName; - const u32 kCommandline = 0x027E0000; - //const u32 kCommandline = 0x027FFF84; - - // - _MMU_write32(0x02FFFE70, 0x5f617267); - _MMU_write32(0x02FFFE74, kCommandline); //(commandline starts here) - _MMU_write32(0x02FFFE78, rompath.size()+1); - //0x027FFF7C (argc) - //0x027FFF80 (argv) - for(size_t i=0;i(kCommandline+i, rompath[i]); - _MMU_write08(kCommandline+rompath.size(), 0); - //-------------------------------- delete header; diff --git a/desmume/src/addons/slot1_retail_nand.cpp b/desmume/src/addons/slot1_retail_nand.cpp index 9da2b3cf0..ba430c645 100644 --- a/desmume/src/addons/slot1_retail_nand.cpp +++ b/desmume/src/addons/slot1_retail_nand.cpp @@ -16,8 +16,8 @@ */ // Games with NAND Flash: -// - Ore/WarioWare D.I.Y. - 8Mbit -// - Daigassou! Band Brothers DX - 64MBit +// - Ore/WarioWare D.I.Y. - 128Mbit +// - Daigassou! Band Brothers DX - 64MBit (NAND?) // Ore/WarioWare D.I.Y. - chip: SAMSUNG 004 // KLC2811ANB-P204 diff --git a/desmume/src/arm_jit.cpp b/desmume/src/arm_jit.cpp index 11766d822..7f450421b 100644 --- a/desmume/src/arm_jit.cpp +++ b/desmume/src/arm_jit.cpp @@ -77,6 +77,8 @@ using namespace AsmJit; #ifdef MAPPED_JIT_FUNCS CACHE_ALIGN JIT_struct JIT; +u32 saveBlockSizeJIT = 0; + uintptr_t *JIT_struct::JIT_MEM[2][0x4000] = {{0}}; static uintptr_t *JIT_MEM[2][32] = { @@ -4219,10 +4221,12 @@ void arm_jit_reset(bool enable) scratchptr = scratchpad; #endif printf("CPU mode: %s\n", enable?"JIT":"Interpreter"); + saveBlockSizeJIT = CommonSettings.jit_max_block_size; if (enable) { printf("JIT: max block size %d instruction(s)\n", CommonSettings.jit_max_block_size); + #ifdef MAPPED_JIT_FUNCS //these pointers are allocated by asmjit and need freeing diff --git a/desmume/src/arm_jit.h b/desmume/src/arm_jit.h index 091b61e6f..9c02f97c2 100644 --- a/desmume/src/arm_jit.h +++ b/desmume/src/arm_jit.h @@ -65,5 +65,6 @@ extern uintptr_t compiled_funcs[]; #define JIT_MAPPED(adr, PROCNUM) true #endif +extern u32 saveBlockSizeJIT; #endif diff --git a/desmume/src/firmware.cpp b/desmume/src/firmware.cpp index c36c0b012..e6f260ced 100644 --- a/desmume/src/firmware.cpp +++ b/desmume/src/firmware.cpp @@ -303,6 +303,7 @@ bool CFIRMWARE::load() std::string extFilePath = CFIRMWARE::GetExternalFilePath(); strncpy(MMU.fw.userfile, extFilePath.c_str(), MAX_PATH); + successLoad = true; return true; } diff --git a/desmume/src/firmware.h b/desmume/src/firmware.h index 72c387903..d552e0f4b 100644 --- a/desmume/src/firmware.h +++ b/desmume/src/firmware.h @@ -40,8 +40,10 @@ private: u32 decrypt(const u8 *in, u8* &out); u32 decompress(const u8 *in, u8* &out); + bool successLoad; + public: - CFIRMWARE(): size9(0), size7(0), ARM9bootAddr(0), ARM7bootAddr(0), patched(0), userDataAddr(0x3FE00) {}; + CFIRMWARE(): size9(0), size7(0), ARM9bootAddr(0), ARM7bootAddr(0), patched(0), userDataAddr(0x3FE00), successLoad(false) {}; bool load(); bool unpack(); @@ -50,10 +52,8 @@ public: static std::string GetExternalFilePath(); - u32 getID() - { - return header.fw_identifier; - } + u32 getID() { return header.fw_identifier; } + bool loaded() { return successLoad; } struct HEADER {