we can emit the instruction inside the delay slot before actually emitting the branch
This commit is contained in:
@@ -38,6 +38,29 @@ void JIT::InvalidateBlock(const u32 paddr) {
|
|||||||
blockCache[index] = {};
|
blockCache[index] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 JIT::FetchInstruction() {
|
||||||
|
u32 paddr = 0;
|
||||||
|
|
||||||
|
if (check_address_error(0b11, u64(blockPC))) [[unlikely]] {
|
||||||
|
/*regs.cop0.HandleTLBException(blockPC);
|
||||||
|
regs.cop0.FireException(ExceptionCode::AddressErrorLoad, 0, blockPC);
|
||||||
|
return 1;*/
|
||||||
|
|
||||||
|
Util::panic("[JIT]: Unhandled exception ADL due to unaligned PC virtual value! (0x{:016X})", blockPC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!regs.cop0.MapVAddr(Cop0::LOAD, blockPC, paddr)) {
|
||||||
|
/*regs.cop0.HandleTLBException(blockPC);
|
||||||
|
regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, blockPC);
|
||||||
|
return 1;*/
|
||||||
|
Util::panic(
|
||||||
|
"[JIT]: Unhandled exception TLB exception {} when retrieving PC physical address! (virtual: 0x{:016X})",
|
||||||
|
static_cast<int>(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD)), static_cast<u64>(blockPC));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mem.Read<u32>(regs, paddr);
|
||||||
|
}
|
||||||
|
|
||||||
int JIT::Step() {
|
int JIT::Step() {
|
||||||
blockOldPC = regs.oldPC;
|
blockOldPC = regs.oldPC;
|
||||||
blockPC = regs.pc;
|
blockPC = regs.pc;
|
||||||
@@ -85,24 +108,15 @@ int JIT::Step() {
|
|||||||
while (!instrEndsBlock) {
|
while (!instrEndsBlock) {
|
||||||
// CheckCompareInterrupt();
|
// CheckCompareInterrupt();
|
||||||
|
|
||||||
if (check_address_error(0b11, u64(blockPC))) [[unlikely]] {
|
instruction = FetchInstruction();
|
||||||
/*regs.cop0.HandleTLBException(blockPC);
|
instructionsInBlock++;
|
||||||
regs.cop0.FireException(ExceptionCode::AddressErrorLoad, 0, blockPC);
|
|
||||||
return 1;*/
|
|
||||||
|
|
||||||
Util::panic("[JIT]: Unhandled exception ADL due to unaligned PC virtual value! (0x{:016X})", blockPC);
|
blockOldPC = blockPC;
|
||||||
}
|
blockPC = blockNextPC;
|
||||||
|
blockNextPC += 4;
|
||||||
|
|
||||||
if (!regs.cop0.MapVAddr(Cop0::LOAD, blockPC, paddr)) {
|
if(instrEndsBlock = InstrEndsBlock(instruction))
|
||||||
/*regs.cop0.HandleTLBException(blockPC);
|
continue;
|
||||||
regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, blockPC);
|
|
||||||
return 1;*/
|
|
||||||
Util::panic(
|
|
||||||
"[JIT]: Unhandled exception TLB exception {} when retrieving PC physical address! (virtual: 0x{:016X})",
|
|
||||||
static_cast<int>(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD)), static_cast<u64>(blockPC));
|
|
||||||
}
|
|
||||||
|
|
||||||
instruction = mem.Read<u32>(regs, paddr);
|
|
||||||
|
|
||||||
/*u32 bswapped = bswap(instruction);
|
/*u32 bswapped = bswap(instruction);
|
||||||
auto count = cs_disasm(disassemblerMips, reinterpret_cast<const u8 *>(&bswapped), 4, blockPC, 0, &insn);
|
auto count = cs_disasm(disassemblerMips, reinterpret_cast<const u8 *>(&bswapped), 4, blockPC, 0, &insn);
|
||||||
@@ -119,24 +133,21 @@ int JIT::Step() {
|
|||||||
return 1;
|
return 1;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
blockOldPC = blockPC;
|
|
||||||
blockPC = blockNextPC;
|
|
||||||
blockNextPC += 4;
|
|
||||||
instructionsInBlock++;
|
|
||||||
Emit(instruction);
|
Emit(instruction);
|
||||||
|
|
||||||
instrEndsBlock = InstrEndsBlock(instruction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instruction = mem.Read<u32>(regs, paddr);
|
instructionsInBlock++;
|
||||||
instrEndsBlock = InstrEndsBlock(instruction);
|
const u32 delay_instruction = FetchInstruction();
|
||||||
|
instrEndsBlock = InstrEndsBlock(delay_instruction);
|
||||||
if(instrEndsBlock)
|
if(instrEndsBlock)
|
||||||
Util::panic("Branch in delay slot - YOU SHOULD KILL YOURSELF, NOW!!!");
|
Util::panic("Branch in delay slot - YOU SHOULD KILL YOURSELF, NOW!!!");
|
||||||
|
|
||||||
blockOldPC = blockPC;
|
blockOldPC = blockPC;
|
||||||
blockPC = blockNextPC;
|
blockPC = blockNextPC;
|
||||||
blockNextPC += 4;
|
blockNextPC += 4;
|
||||||
instructionsInBlock++;
|
|
||||||
|
Emit(delay_instruction);
|
||||||
|
|
||||||
Emit(instruction);
|
Emit(instruction);
|
||||||
|
|
||||||
code.mov(code.rax, instructionsInBlock);
|
code.mov(code.rax, instructionsInBlock);
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ private:
|
|||||||
void CheckCompareInterrupt() override;
|
void CheckCompareInterrupt() override;
|
||||||
std::vector<u8> Serialize() override;
|
std::vector<u8> Serialize() override;
|
||||||
void Deserialize(const std::vector<u8> &) override;
|
void Deserialize(const std::vector<u8> &) override;
|
||||||
|
u32 FetchInstruction();
|
||||||
|
|
||||||
void Emit(u32);
|
void Emit(u32);
|
||||||
void special(u32);
|
void special(u32);
|
||||||
|
|||||||
Reference in New Issue
Block a user