eventually figure out why xbyak complains about certains movs
This commit is contained in:
@@ -5,6 +5,7 @@ namespace n64 {
|
||||
#ifndef __aarch64__
|
||||
JIT::JIT(Mem& mem, Registers& regs) : regs(regs), mem(mem) {
|
||||
regs.SetJIT(this);
|
||||
mem.SetJIT(this);
|
||||
blockCache.resize(kUpperSize);
|
||||
if (cs_open(CS_ARCH_MIPS, static_cast<cs_mode>(CS_MODE_MIPS64 | CS_MODE_BIG_ENDIAN), &disassemblerMips) !=
|
||||
CS_ERR_OK) {
|
||||
@@ -39,20 +40,20 @@ void JIT::InvalidateBlock(const u32 paddr) {
|
||||
blockCache[index] = {};
|
||||
}
|
||||
|
||||
u32 JIT::FetchInstruction() {
|
||||
std::optional<u32> JIT::FetchInstruction(s64 vaddr) {
|
||||
u32 paddr = 0;
|
||||
|
||||
if (check_address_error(0b11, u64(blockPC))) [[unlikely]] {
|
||||
if (check_address_error(0b11, vaddr)) [[unlikely]] {
|
||||
/*regs.cop0.HandleTLBException(blockPC);
|
||||
regs.cop0.FireException(ExceptionCode::AddressErrorLoad, 0, blockPC);
|
||||
return 1;*/
|
||||
Util::Error::GetInstance().Throw(
|
||||
{Util::Error::Severity::NON_FATAL}, {Util::Error::Type::UNHANDLED_EXCEPTION}, blockPC, {},
|
||||
"[JIT]: Unhandled exception ADL due to unaligned PC virtual value!");
|
||||
return 0;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!regs.cop0.MapVAddr(Cop0::LOAD, blockPC, paddr)) {
|
||||
if (!regs.cop0.MapVAddr(Cop0::LOAD, vaddr, paddr)) {
|
||||
/*regs.cop0.HandleTLBException(blockPC);
|
||||
regs.cop0.FireException(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD), 0, blockPC);
|
||||
return 1;*/
|
||||
@@ -60,7 +61,7 @@ u32 JIT::FetchInstruction() {
|
||||
{Util::Error::Severity::NON_FATAL}, {Util::Error::Type::UNHANDLED_EXCEPTION}, blockPC, {},
|
||||
"[JIT]: Unhandled exception TLB exception {} when retrieving PC physical address!",
|
||||
static_cast<int>(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD)));
|
||||
return 0;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const u32 instr = Core::GetMem().Read<u32>(paddr);
|
||||
@@ -142,7 +143,6 @@ u32 JIT::Step() {
|
||||
code.setProtectModeRW();
|
||||
|
||||
u32 instructionsInBlock = 0;
|
||||
u32 instruction = 0;
|
||||
|
||||
bool instrEndsBlock = false;
|
||||
|
||||
@@ -152,87 +152,70 @@ u32 JIT::Step() {
|
||||
|
||||
cs_insn *insn;
|
||||
info("\tMIPS code (guest PC = 0x{:016X}):", static_cast<u64>(blockPC));
|
||||
while (!instrEndsBlock) {
|
||||
code.mov(code.SCR1, REG(byte, delaySlot));
|
||||
code.mov(REG(byte, prevDelaySlot), code.SCR1);
|
||||
code.mov(REG(byte, delaySlot), 0);
|
||||
|
||||
emitMemberFunctionCall(&JIT::AdvanceDelaySlot, this);
|
||||
|
||||
// CheckCompareInterrupt();
|
||||
while (true) {
|
||||
paddr = 0;
|
||||
|
||||
if (check_address_error(0b11, u64(blockPC))) [[unlikely]] {
|
||||
/*regs.cop0.HandleTLBException(blockPC);
|
||||
regs.cop0.FireException(ExceptionCode::AddressErrorLoad, 0, blockPC);
|
||||
return 1;*/
|
||||
Util::Error::GetInstance().Throw(
|
||||
{Util::Error::Severity::NON_FATAL}, {Util::Error::Type::UNHANDLED_EXCEPTION}, blockPC, {},
|
||||
"[JIT]: Unhandled exception ADL due to unaligned PC virtual value!");
|
||||
return 0;
|
||||
}
|
||||
auto instruction = FetchInstruction(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::Error::GetInstance().Throw(
|
||||
{Util::Error::Severity::NON_FATAL}, {Util::Error::Type::UNHANDLED_EXCEPTION}, blockPC, {},
|
||||
"[JIT]: Unhandled exception TLB exception {} when retrieving PC physical address!",
|
||||
static_cast<int>(Cop0::GetTLBExceptionCode(regs.cop0.tlbError, Cop0::LOAD)));
|
||||
if(!instruction)
|
||||
return 0;
|
||||
}
|
||||
|
||||
instruction = Core::GetMem().Read<u32>(paddr);
|
||||
instructionsInBlock++;
|
||||
|
||||
blockOldPC = blockPC;
|
||||
blockPC = blockNextPC;
|
||||
blockNextPC += 4;
|
||||
|
||||
info("{}", Disassembler::GetInstance().DisassembleSimple(paddr, instruction).full);
|
||||
if((instrEndsBlock = InstrEndsBlock(instruction)))
|
||||
continue;
|
||||
if(InstrEndsBlock(instruction.value())) {
|
||||
const auto delay_instruction = FetchInstruction(blockPC); // get instruction in delay slot
|
||||
if(!delay_instruction)
|
||||
return 0;
|
||||
|
||||
/*if(ShouldServiceInterrupt()) {
|
||||
regs.cop0.FireException(ExceptionCode::Interrupt, 0, blockPC);
|
||||
return 1;
|
||||
}*/
|
||||
if(InstrEndsBlock(delay_instruction.value())) {
|
||||
Util::Error::GetInstance().Throw(
|
||||
{Util::Error::Severity::NON_FATAL}, {Util::Error::Type::JIT_BRANCH_INSIDE_DELAY_SLOT},
|
||||
blockPC, {}, "[JIT]: Unhandled case of branch from delay slot!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Emit(instruction);
|
||||
instructionsInBlock++;
|
||||
|
||||
blockOldPC = blockPC;
|
||||
blockPC = blockNextPC;
|
||||
blockNextPC += 4;
|
||||
|
||||
Emit(delay_instruction.value());
|
||||
Emit(instruction.value());
|
||||
|
||||
if(!branch_taken) {
|
||||
Xbyak::Label runtime_branch_taken;
|
||||
code.mov(code.SCR1, JIT_VAR(byte, branch_taken));
|
||||
code.cmp(code.SCR1, 0);
|
||||
code.jne(runtime_branch_taken);
|
||||
code.mov(code.SCR1, blockOldPC);
|
||||
code.mov(REG(qword, oldPC), code.SCR1);
|
||||
code.mov(code.SCR1, blockPC);
|
||||
code.mov(REG(qword, pc), code.SCR1);
|
||||
code.mov(code.SCR1, blockNextPC);
|
||||
code.mov(REG(qword, nextPC), code.SCR1);
|
||||
code.L(runtime_branch_taken);
|
||||
}
|
||||
|
||||
if(branch_taken) branch_taken = false;
|
||||
|
||||
emitMemberFunctionCall(&JIT::AdvanceDelaySlot, this);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Emit(instruction.value());
|
||||
|
||||
emitMemberFunctionCall(&JIT::AdvanceDelaySlot, this);
|
||||
}
|
||||
|
||||
instructionsInBlock++;
|
||||
const u32 delay_instruction = FetchInstruction();
|
||||
|
||||
instrEndsBlock = InstrEndsBlock(delay_instruction);
|
||||
if(instrEndsBlock) {
|
||||
Util::Error::GetInstance().Throw(
|
||||
{Util::Error::Severity::NON_FATAL}, {Util::Error::Type::JIT_BRANCH_INSIDE_DELAY_SLOT},
|
||||
blockPC, {}, "[JIT]: Unhandled case of branch from delay slot!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
blockOldPC = blockPC;
|
||||
blockPC = blockNextPC;
|
||||
blockNextPC += 4;
|
||||
|
||||
Emit(delay_instruction);
|
||||
|
||||
Emit(instruction);
|
||||
|
||||
Xbyak::Label clearDelaySlot;
|
||||
|
||||
code.mov(code.SCR1, REG(byte, delaySlot));
|
||||
code.cmp(code.SCR1, 0);
|
||||
code.jne(clearDelaySlot);
|
||||
code.mov(code.SCR1, blockOldPC);
|
||||
code.mov(REG(qword, oldPC), code.SCR1);
|
||||
code.mov(code.SCR1, blockPC);
|
||||
code.mov(REG(qword, pc), code.SCR1);
|
||||
code.mov(code.SCR1, blockNextPC);
|
||||
code.mov(REG(qword, nextPC), code.SCR1);
|
||||
code.L(clearDelaySlot);
|
||||
code.mov(REG(byte, delaySlot), 0);
|
||||
|
||||
code.mov(code.rax, instructionsInBlock);
|
||||
code.pop(code.rbp);
|
||||
code.add(code.rsp, 8);
|
||||
|
||||
Reference in New Issue
Block a user