EmuCodeBlock: Make CheckIfSafeAddress PIE-compliant

This commit is contained in:
MerryMage 2017-04-14 12:21:33 +01:00
parent 05fec44ff5
commit daa03cd106
1 changed files with 14 additions and 17 deletions

View File

@ -89,27 +89,24 @@ FixupBranch EmuCodeBlock::CheckIfSafeAddress(const OpArg& reg_value, X64Reg reg_
if (reg_value.IsSimpleReg()) if (reg_value.IsSimpleReg())
registers_in_use[reg_value.GetSimpleReg()] = true; registers_in_use[reg_value.GetSimpleReg()] = true;
// Get ourselves a free register; try to pick one that doesn't involve pushing, if we can. // Get ourselves two free registers
X64Reg scratch = RSCRATCH; if (registers_in_use[RSCRATCH])
if (!registers_in_use[RSCRATCH]) PUSH(RSCRATCH);
scratch = RSCRATCH; if (registers_in_use[RSCRATCH_EXTRA])
else if (!registers_in_use[RSCRATCH_EXTRA]) PUSH(RSCRATCH_EXTRA);
scratch = RSCRATCH_EXTRA;
else
scratch = reg_addr;
if (scratch == reg_addr) if (reg_addr != RSCRATCH_EXTRA)
PUSH(scratch); MOV(32, R(RSCRATCH_EXTRA), R(reg_addr));
else
MOV(32, R(scratch), R(reg_addr));
// Perform lookup to see if we can use fast path. // Perform lookup to see if we can use fast path.
SHR(32, R(scratch), Imm8(PowerPC::BAT_INDEX_SHIFT)); MOV(64, R(RSCRATCH), ImmPtr(&PowerPC::dbat_table[0]));
TEST(32, MScaled(scratch, SCALE_4, PtrOffset(&PowerPC::dbat_table[0])), SHR(32, R(RSCRATCH_EXTRA), Imm8(PowerPC::BAT_INDEX_SHIFT));
Imm32(PowerPC::BAT_PHYSICAL_BIT)); TEST(32, MComplex(RSCRATCH, RSCRATCH_EXTRA, SCALE_4, 0), Imm32(PowerPC::BAT_PHYSICAL_BIT));
if (scratch == reg_addr) if (registers_in_use[RSCRATCH_EXTRA])
POP(scratch); POP(RSCRATCH_EXTRA);
if (registers_in_use[RSCRATCH])
POP(RSCRATCH);
return J_CC(CC_Z, m_far_code.Enabled()); return J_CC(CC_Z, m_far_code.Enabled());
} }