From 19eb09b086413e889925965f125369a7d9fd7520 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Fri, 24 Mar 2017 10:18:57 +0000 Subject: [PATCH] Jit_SystemRegisters: Make mfspr PIE-compliant --- .../Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp index cf694f89bc..6588763f63 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp @@ -282,18 +282,21 @@ void Jit64::mfspr(UGeckoInstruction inst) // no register choice gpr.FlushLockX(RDX, RAX); + gpr.FlushLockX(RCX); + + MOV(64, R(RCX), ImmPtr(&CoreTiming::g)); // An inline implementation of CoreTiming::GetFakeTimeBase, since in timer-heavy games the // cost of calling out to C for this is actually significant. // Scale downcount by the CPU overclocking factor. CVTSI2SS(XMM0, PPCSTATE(downcount)); - MULSS(XMM0, M(&CoreTiming::g_last_OC_factor_inverted)); + MULSS(XMM0, MDisp(RCX, offsetof(CoreTiming::Globals, last_OC_factor_inverted))); CVTSS2SI(RDX, R(XMM0)); // RDX is downcount scaled by the overclocking factor - MOV(32, R(RAX), M(&CoreTiming::g_slice_length)); + MOV(32, R(RAX), MDisp(RCX, offsetof(CoreTiming::Globals, slice_length))); SUB(64, R(RAX), R(RDX)); // cycles since the last CoreTiming::Advance() event is (slicelength - // Scaled_downcount) - ADD(64, R(RAX), M(&CoreTiming::g_global_timer)); - SUB(64, R(RAX), M(&CoreTiming::g_fake_TB_start_ticks)); + ADD(64, R(RAX), MDisp(RCX, offsetof(CoreTiming::Globals, global_timer))); + SUB(64, R(RAX), MDisp(RCX, offsetof(CoreTiming::Globals, fake_TB_start_ticks))); // It might seem convenient to correct the timer for the block position here for even more // accurate // timing, but as of currently, this can break games. If we end up reading a time *after* the @@ -309,7 +312,7 @@ void Jit64::mfspr(UGeckoInstruction inst) // a / 12 = (a * 0xAAAAAAAAAAAAAAAB) >> 67 MOV(64, R(RDX), Imm64(0xAAAAAAAAAAAAAAABULL)); MUL(64, R(RDX)); - MOV(64, R(RAX), M(&CoreTiming::g_fake_TB_start_value)); + MOV(64, R(RAX), MDisp(RCX, offsetof(CoreTiming::Globals, fake_TB_start_value))); SHR(64, R(RDX), Imm8(3)); ADD(64, R(RAX), R(RDX)); MOV(64, PPCSTATE(spr[SPR_TL]), R(RAX));