diff --git a/src/ARM.cpp b/src/ARM.cpp index 0d2976d2..a9c2d124 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -177,6 +177,8 @@ void ARM::Reset() ExceptionBase = Num ? 0x00000000 : 0xFFFF0000; + BuggyJump = 0; + CodeMem.Mem = NULL; #ifdef JIT_ENABLED @@ -284,6 +286,32 @@ void ARM::SetupCodeMem(u32 addr) } } +void ARMv5::BuggedJumpTo32(const u32 addr) +{ + if (BuggyJump == 1) + { + BuggyJump = 2; + JumpTo(addr); + } + else + { + JumpTo(addr & ~0x1); + } +} + +void ARMv5::BuggedJumpTo(const u32 addr) +{ + if ((BuggyJump == 0) && (addr & 0x3)) + { + BuggyJump = 1; + PrefetchAbort(); // checkme + } + else + { + JumpTo(addr); + } +} + void ARMv5::JumpTo(u32 addr, bool restorecpsr) { if (restorecpsr) @@ -352,6 +380,16 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr) NDS.MonitorARM9Jump(addr); } +void ARMv4::BuggedJumpTo32(const u32 addr) +{ + JumpTo(addr); // todo +} + +void ARMv4::BuggedJumpTo(const u32 addr) +{ + JumpTo(addr); // todo +} + void ARMv4::JumpTo(u32 addr, bool restorecpsr) { if (restorecpsr) diff --git a/src/ARM.h b/src/ARM.h index 1f68567c..9cda0be1 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -64,7 +64,9 @@ public: virtual void DoSavestate(Savestate* file); virtual void FillPipeline() = 0; - + + virtual void BuggedJumpTo32(const u32 addr) = 0; + virtual void BuggedJumpTo(const u32 addr) = 0; virtual void JumpTo(u32 addr, bool restorecpsr = false) = 0; void RestoreCPSR(); @@ -173,6 +175,7 @@ public: u32 R_UND[3]; u32 CurInstr; u32 NextInstr[2]; + u32 BuggyJump; u32 ExceptionBase; @@ -235,7 +238,9 @@ public: void UpdateRegionTimings(u32 addrstart, u32 addrend); void FillPipeline() override; - + + void BuggedJumpTo32(const u32 addr) override; + void BuggedJumpTo(const u32 addr) override; void JumpTo(u32 addr, bool restorecpsr = false) override; void PrefetchAbort(); @@ -380,7 +385,9 @@ public: ARMv4(melonDS::NDS& nds, std::optional gdb, bool jit); void FillPipeline() override; - + + void BuggedJumpTo32(const u32 addr) override; + void BuggedJumpTo(const u32 addr) override; void JumpTo(u32 addr, bool restorecpsr = false) override; void Execute() override; diff --git a/src/ARMInterpreter_LoadStore.cpp b/src/ARMInterpreter_LoadStore.cpp index 19136cce..b5a3ee63 100644 --- a/src/ARMInterpreter_LoadStore.cpp +++ b/src/ARMInterpreter_LoadStore.cpp @@ -141,8 +141,8 @@ namespace melonDS::ARMInterpreter cpu->AddCycles_CDI(); \ if (dataabort) return; \ if (cpu->CurInstr & (1<<21)) cpu->R[(cpu->CurInstr>>16) & 0xF] = offset; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->JumpTo(val); \ - else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ + else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; // TODO: user mode (note: ldrbt w/ rd = 15 may be an undef instr) #define A_LDRB_POST \ @@ -151,8 +151,8 @@ namespace melonDS::ARMInterpreter cpu->AddCycles_CDI(); \ if (dataabort) return; \ cpu->R[(cpu->CurInstr>>16) & 0xF] += offset; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->JumpTo(val); \ - else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ + else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; @@ -262,7 +262,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) if (r&1) { A_UNK(cpu); return; } /* checkme */ \ if (!cpu->DataRead32 (offset , &cpu->R[r ])) {cpu->AddCycles_CDI(); return;} \ u32 val; if (!cpu->DataRead32S(offset+4, &val)) {cpu->AddCycles_CDI(); return;} \ - if (r == 14) A_UNK(cpu); /* checkme */ \ + if (r == 14) cpu->BuggedJumpTo32(val); \ else cpu->R[r+1] = val; \ cpu->AddCycles_CDI(); \ if (cpu->CurInstr & (1<<21)) cpu->R[(cpu->CurInstr>>16) & 0xF] = offset; @@ -274,7 +274,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) if (r&1) { A_UNK(cpu); return; } /* checkme */ \ if (!cpu->DataRead32 (addr , &cpu->R[r ])) {cpu->AddCycles_CDI(); return;} \ u32 val; if (!cpu->DataRead32S(addr+4, &val)) {cpu->AddCycles_CDI(); return;} \ - if (r == 14) A_UNK(cpu); /* checkme */ \ + if (r == 14) cpu->BuggedJumpTo32(val); \ else cpu->R[r+1] = val; \ cpu->AddCycles_CDI(); \ cpu->R[(cpu->CurInstr>>16) & 0xF] += offset; @@ -308,7 +308,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) u32 val; bool dataabort = !cpu->DataRead16(offset, &val); \ cpu->AddCycles_CDI(); \ if (dataabort) return; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->JumpTo(val); \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ if (cpu->CurInstr & (1<<21)) cpu->R[(cpu->CurInstr>>16) & 0xF] = offset; @@ -317,7 +317,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) u32 val; bool dataabort = !cpu->DataRead16(addr, &val); \ cpu->AddCycles_CDI(); \ if (dataabort) return; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->JumpTo(val); \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ cpu->R[(cpu->CurInstr>>16) & 0xF] += offset; @@ -327,7 +327,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) cpu->AddCycles_CDI(); \ if (dataabort) return; \ val = (s32)(s8)val; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) A_UNK(cpu); \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ if (cpu->CurInstr & (1<<21)) cpu->R[(cpu->CurInstr>>16) & 0xF] = offset; @@ -337,7 +337,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) cpu->AddCycles_CDI(); \ if (dataabort) return; \ val = (s32)(s8)val; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) A_UNK(cpu); \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ cpu->R[(cpu->CurInstr>>16) & 0xF] += offset; @@ -347,7 +347,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) cpu->AddCycles_CDI(); \ if (dataabort) return; \ val = (s32)(s16)val; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) A_UNK(cpu); /* checkme */ \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ if (cpu->CurInstr & (1<<21)) cpu->R[(cpu->CurInstr>>16) & 0xF] = offset; @@ -357,7 +357,7 @@ A_IMPLEMENT_WB_LDRSTR(LDRB) cpu->AddCycles_CDI(); \ if (dataabort) return; \ val = (s32)(s16)val; \ - if (((cpu->CurInstr>>12) & 0xF) == 15) A_UNK(cpu); /* checkme */ \ + if (((cpu->CurInstr>>12) & 0xF) == 15) cpu->BuggedJumpTo(val); \ else cpu->R[(cpu->CurInstr>>12) & 0xF] = val; \ cpu->R[(cpu->CurInstr>>16) & 0xF] += offset;