From 11c5cdfdb071dcee71df213f0008b591fecf0c1d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 18 Jan 2013 21:23:30 -0800 Subject: [PATCH] Refactor out all the CheckJitBreakpoint()s. Ah, much cleaner. --- Core/MIPS/x86/CompBranch.cpp | 53 +++--------------------------------- Core/MIPS/x86/Jit.cpp | 31 +++++++++++++++++++++ Core/MIPS/x86/Jit.h | 1 + 3 files changed, 36 insertions(+), 49 deletions(-) diff --git a/Core/MIPS/x86/CompBranch.cpp b/Core/MIPS/x86/CompBranch.cpp index 7894558b66..45c3347fa7 100644 --- a/Core/MIPS/x86/CompBranch.cpp +++ b/Core/MIPS/x86/CompBranch.cpp @@ -45,20 +45,6 @@ using namespace MIPSAnalyst; namespace MIPSComp { -#ifdef _M_IX86 - -#define SAVE_FLAGS PUSHF(); -#define LOAD_FLAGS POPF(); - -#else - -static u64 saved_flags; - -#define SAVE_FLAGS {PUSHF(); POP(64, R(EAX)); MOV(64, M(&saved_flags), R(EAX));} -#define LOAD_FLAGS {MOV(64, R(EAX), M(&saved_flags)); PUSH(64, R(EAX)); POPF();} - -#endif - void Jit::BranchRSRTComp(u32 op, Gen::CCFlags cc, bool likely) { if (js.inDelaySlot) { @@ -96,19 +82,12 @@ void Jit::BranchRSRTComp(u32 op, Gen::CCFlags cc, bool likely) Gen::FixupBranch ptr; if (!likely) { - CheckJitBreakpoint(js.compilerPC + 4); - if (!delaySlotIsNice) - SAVE_FLAGS; // preserve flag around the delay slot! - CompileAt(js.compilerPC + 4); - FlushAll(); - if (!delaySlotIsNice) - LOAD_FLAGS; // restore flag! + CompileDelaySlot(js.compilerPC + 4, !delaySlotIsNice); ptr = J_CC(cc, true); } else { ptr = J_CC(cc, true); - CheckJitBreakpoint(js.compilerPC + 4); CompileAt(js.compilerPC + 4); FlushAll(); } @@ -151,19 +130,12 @@ void Jit::BranchRSZeroComp(u32 op, Gen::CCFlags cc, bool likely) js.inDelaySlot = true; if (!likely) { - CheckJitBreakpoint(js.compilerPC + 4); - if (!delaySlotIsNice) - SAVE_FLAGS; // preserve flag around the delay slot! Better hope the delay slot instruction doesn't need to fall back to interpreter... - CompileAt(js.compilerPC + 4); - FlushAll(); - if (!delaySlotIsNice) - LOAD_FLAGS; // restore flag! + CompileDelaySlot(js.compilerPC + 4, !delaySlotIsNice); ptr = J_CC(cc, true); } else { ptr = J_CC(cc, true); - CheckJitBreakpoint(js.compilerPC + 4); CompileAt(js.compilerPC + 4); FlushAll(); } @@ -245,19 +217,12 @@ void Jit::BranchFPFlag(u32 op, Gen::CCFlags cc, bool likely) js.inDelaySlot = true; if (!likely) { - CheckJitBreakpoint(js.compilerPC + 4); - if (!delaySlotIsNice) - SAVE_FLAGS; // preserve flag around the delay slot! - CompileAt(js.compilerPC + 4); - FlushAll(); - if (!delaySlotIsNice) - LOAD_FLAGS; // restore flag! + CompileDelaySlot(js.compilerPC + 4, !delaySlotIsNice); ptr = J_CC(cc, true); } else { ptr = J_CC(cc, true); - CheckJitBreakpoint(js.compilerPC + 4); CompileAt(js.compilerPC + 4); FlushAll(); } @@ -320,19 +285,12 @@ void Jit::BranchVFPUFlag(u32 op, Gen::CCFlags cc, bool likely) js.inDelaySlot = true; if (!likely) { - CheckJitBreakpoint(js.compilerPC + 4); - if (!delaySlotIsNice) - SAVE_FLAGS; // preserve flag around the delay slot! - CompileAt(js.compilerPC + 4); - FlushAll(); - if (!delaySlotIsNice) - LOAD_FLAGS; // restore flag! + CompileDelaySlot(js.compilerPC + 4, !delaySlotIsNice); ptr = J_CC(cc, true); } else { ptr = J_CC(cc, true); - CheckJitBreakpoint(js.compilerPC + 4); CompileAt(js.compilerPC + 4); FlushAll(); } @@ -372,7 +330,6 @@ void Jit::Comp_Jump(u32 op) } u32 off = ((op & 0x3FFFFFF) << 2); u32 targetAddr = (js.compilerPC & 0xF0000000) | off; - CheckJitBreakpoint(js.compilerPC + 4); CompileAt(js.compilerPC + 4); FlushAll(); @@ -411,7 +368,6 @@ void Jit::Comp_JumpReg(u32 op) if (delaySlotIsNice) { - CheckJitBreakpoint(js.compilerPC + 4); CompileAt(js.compilerPC + 4); MOV(32, R(EAX), gpr.R(rs)); FlushAll(); @@ -422,7 +378,6 @@ void Jit::Comp_JumpReg(u32 op) gpr.BindToRegister(rs, true, false); MOV(32, M(¤tMIPS->pc), gpr.R(rs)); // for syscalls in delay slot - could be avoided MOV(32, M(&savedPC), gpr.R(rs)); - CheckJitBreakpoint(js.compilerPC + 4); CompileAt(js.compilerPC + 4); FlushAll(); diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 55ec5ec6fc..52c47a3dce 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -31,6 +31,20 @@ namespace MIPSComp { +#ifdef _M_IX86 + +#define SAVE_FLAGS PUSHF(); +#define LOAD_FLAGS POPF(); + +#else + +static u64 saved_flags; + +#define SAVE_FLAGS {PUSHF(); POP(64, R(EAX)); MOV(64, M(&saved_flags), R(EAX));} +#define LOAD_FLAGS {MOV(64, R(EAX), M(&saved_flags)); PUSH(64, R(EAX)); POPF();} + +#endif + void JitBreakpoint() { Core_EnableStepping(true); @@ -67,8 +81,25 @@ void Jit::ClearCacheAt(u32 em_address) ClearCache(); } +void Jit::CompileDelaySlot(u32 addr, bool saveFlags) +{ + // TODO: If we ever support conditional breakpoints, we need to handle the flags more carefully. + CheckJitBreakpoint(addr); + + if (saveFlags) + SAVE_FLAGS; // preserve flag around the delay slot! + + u32 op = Memory::Read_Instruction(addr); + MIPSCompileOp(op); + + FlushAll(); + if (saveFlags) + LOAD_FLAGS; // restore flag! +} + void Jit::CompileAt(u32 addr) { + CheckJitBreakpoint(addr); u32 op = Memory::Read_Instruction(addr); MIPSCompileOp(op); } diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h index b9ff726e6e..6d895b697c 100644 --- a/Core/MIPS/x86/Jit.h +++ b/Core/MIPS/x86/Jit.h @@ -70,6 +70,7 @@ public: void Compile(u32 em_address); // Compiles a block at current MIPS PC const u8 *DoJit(u32 em_address, JitBlock *b); + void CompileDelaySlot(u32 addr, bool saveFlags = false); void CompileAt(u32 addr); void Comp_RunBlock(u32 op);