[CPU] Fix EPC

This commit is contained in:
liuk7071 2023-08-07 21:04:26 +02:00
parent 397b403a10
commit 56b802976d
2 changed files with 9 additions and 8 deletions

View file

@ -3,8 +3,8 @@
void Interpreter::step(CpuCore* core, Memory* mem, Disassembler* disassembler) {
// Handle interrupts
if (core->checkInterrupt(mem->interrupt))
core->pc -= 4;
core->checkInterrupt(mem->interrupt);
// core->pc -= 4;
CpuCore::Instruction instr = { .raw = mem->read<u32>(core->pc) };
@ -73,13 +73,11 @@ void Interpreter::step(CpuCore* core, Memory* mem, Disassembler* disassembler) {
break;
}
case CpuOpcodes::SPECIALOpcode::SYSCALL: {
core->pc -= 4;
core->exception(CpuCore::Exception::SysCall);
core->exception(CpuCore::Exception::SysCall, true);
break;
}
case CpuOpcodes::SPECIALOpcode::BREAK: {
core->pc -= 4;
core->exception(CpuCore::Exception::Break);
core->exception(CpuCore::Exception::Break, true);
break;
}
case CpuOpcodes::SPECIALOpcode::MFHI: {
@ -428,5 +426,5 @@ void Interpreter::step(CpuCore* core, Memory* mem, Disassembler* disassembler) {
Helpers::panic("[FATAL] Unimplemented primary instruction 0x%02x (raw: 0x%08x)\n", instr.primaryOpc.Value(), instr.raw);
}
if (core->isDelaySlot) core->isDelaySlot = false;
core->isDelaySlot = false;
}

View file

@ -125,7 +125,8 @@ public:
Overflow = 0xC
};
void exception(Exception exception) {
// If decrementPc is true, epc will be set to pc - 4 instead of pc
void exception(Exception exception, bool decrementPc = false) {
if (isDelaySlot)
cop0.cause.bd = true;
else
@ -144,6 +145,8 @@ public:
cop0.cause.raw &= ~0xff;
cop0.cause.raw |= (u32)exception << 2;
cop0.epc = pc;
if (decrementPc)
cop0.epc -= 4;
if (isDelaySlot)
cop0.epc -= 4;
pc = handler;