From 2f3107216a74661c9d8a76347b0f7f96d58131d3 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 23 Nov 2019 12:48:53 +1000 Subject: [PATCH] CPU/Recompiler: Implement syscall/break --- src/core/cpu_recompiler_code_generator.cpp | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/core/cpu_recompiler_code_generator.cpp b/src/core/cpu_recompiler_code_generator.cpp index a43ab7031..93d9e7de1 100644 --- a/src/core/cpu_recompiler_code_generator.cpp +++ b/src/core/cpu_recompiler_code_generator.cpp @@ -163,6 +163,8 @@ bool CodeGenerator::CompileInstruction(const CodeBlockInstruction& cbi) case InstructionFunct::jr: case InstructionFunct::jalr: + case InstructionFunct::syscall: + case InstructionFunct::break_: result = Compile_Branch(cbi); break; @@ -1219,13 +1221,25 @@ bool CodeGenerator::Compile_Branch(const CodeBlockInstruction& cbi) case InstructionOp::funct: { - Assert(cbi.instruction.r.funct == InstructionFunct::jr || cbi.instruction.r.funct == InstructionFunct::jalr); - - // npc = rs, link to rt - Value branch_target = m_register_cache.ReadGuestRegister(cbi.instruction.r.rs); - EmitBranch(Condition::Always, - (cbi.instruction.r.funct == InstructionFunct::jalr) ? cbi.instruction.r.rd : Reg::count, false, - std::move(branch_target)); + if (cbi.instruction.r.funct == InstructionFunct::jr || cbi.instruction.r.funct == InstructionFunct::jalr) + { + // npc = rs, link to rt + Value branch_target = m_register_cache.ReadGuestRegister(cbi.instruction.r.rs); + EmitBranch(Condition::Always, + (cbi.instruction.r.funct == InstructionFunct::jalr) ? cbi.instruction.r.rd : Reg::count, false, + std::move(branch_target)); + } + else if (cbi.instruction.r.funct == InstructionFunct::syscall || + cbi.instruction.r.funct == InstructionFunct::break_) + { + const Exception excode = + (cbi.instruction.r.funct == InstructionFunct::syscall) ? Exception::Syscall : Exception::BP; + EmitRaiseException(excode); + } + else + { + UnreachableCode(); + } } break;