2012-11-01 16:19:01 +01:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 23:01:49 +01:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
2013-01-19 19:07:11 -08:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <iterator>
|
2013-09-07 12:34:19 +02:00
|
|
|
|
2013-09-28 14:01:26 +02:00
|
|
|
#include "math/math_util.h"
|
|
|
|
|
|
2013-02-18 01:14:57 -08:00
|
|
|
#include "Common/ChunkFile.h"
|
2013-03-29 20:51:14 +01:00
|
|
|
#include "Core/Core.h"
|
|
|
|
|
#include "Core/System.h"
|
|
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
|
#include "Core/Config.h"
|
2013-08-11 18:20:43 -07:00
|
|
|
#include "Core/Reporting.h"
|
2013-12-30 00:23:04 +01:00
|
|
|
#include "Core/Debugger/SymbolMap.h"
|
2013-03-29 20:51:14 +01:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
|
|
|
|
#include "Core/MIPS/MIPSCodeUtils.h"
|
|
|
|
|
#include "Core/MIPS/MIPSInt.h"
|
|
|
|
|
#include "Core/MIPS/MIPSTables.h"
|
2013-11-30 20:57:44 +01:00
|
|
|
#include "Core/HLE/ReplaceTables.h"
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
|
#include "RegCache.h"
|
|
|
|
|
#include "Jit.h"
|
|
|
|
|
|
2013-09-07 12:34:19 +02:00
|
|
|
#include "Core/Host.h"
|
|
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
2013-01-18 10:19:43 -08:00
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
namespace MIPSComp
|
|
|
|
|
{
|
|
|
|
|
|
2013-01-18 21:23:30 -08:00
|
|
|
#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
|
|
|
|
|
|
2013-01-19 19:07:11 -08:00
|
|
|
const bool USE_JIT_MISSMAP = false;
|
|
|
|
|
static std::map<std::string, u32> notJitOps;
|
|
|
|
|
|
|
|
|
|
template<typename A, typename B>
|
2013-12-19 11:45:39 +01:00
|
|
|
std::pair<B,A> flip_pair(const std::pair<A,B> &p) {
|
|
|
|
|
return std::pair<B, A>(p.second, p.first);
|
2013-01-19 19:07:11 -08:00
|
|
|
}
|
|
|
|
|
|
2013-06-29 11:22:58 -07:00
|
|
|
u32 JitBreakpoint()
|
2013-01-18 10:19:43 -08:00
|
|
|
{
|
2013-06-29 11:22:58 -07:00
|
|
|
// Should we skip this breakpoint?
|
|
|
|
|
if (CBreakPoints::CheckSkipFirst() == currentMIPS->pc)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-06-30 15:35:03 -07:00
|
|
|
auto cond = CBreakPoints::GetBreakPointCondition(currentMIPS->pc);
|
|
|
|
|
if (cond && !cond->Evaluate())
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-01-18 10:19:43 -08:00
|
|
|
Core_EnableStepping(true);
|
|
|
|
|
host->SetDebugMode(true);
|
|
|
|
|
|
2013-01-19 19:07:11 -08:00
|
|
|
// There's probably a better place for this.
|
|
|
|
|
if (USE_JIT_MISSMAP)
|
|
|
|
|
{
|
|
|
|
|
std::map<u32, std::string> notJitSorted;
|
|
|
|
|
std::transform(notJitOps.begin(), notJitOps.end(), std::inserter(notJitSorted, notJitSorted.begin()), flip_pair<std::string, u32>);
|
|
|
|
|
|
|
|
|
|
std::string message;
|
|
|
|
|
char temp[256];
|
|
|
|
|
int remaining = 15;
|
|
|
|
|
for (auto it = notJitSorted.rbegin(), end = notJitSorted.rend(); it != end && --remaining >= 0; ++it)
|
|
|
|
|
{
|
|
|
|
|
snprintf(temp, 256, " (%d), ", it->first);
|
|
|
|
|
message += it->second + temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (message.size() > 2)
|
|
|
|
|
message.resize(message.size() - 2);
|
|
|
|
|
|
|
|
|
|
NOTICE_LOG(JIT, "Top ops compiled to interpreter: %s", message.c_str());
|
|
|
|
|
}
|
2013-06-29 11:22:58 -07:00
|
|
|
|
|
|
|
|
return 1;
|
2013-01-18 10:19:43 -08:00
|
|
|
}
|
|
|
|
|
|
2014-01-26 11:52:37 -08:00
|
|
|
void JitMemCheck(u32 addr, int size, int isWrite)
|
|
|
|
|
{
|
|
|
|
|
// Should we skip this breakpoint?
|
|
|
|
|
if (CBreakPoints::CheckSkipFirst() == currentMIPS->pc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Did we already hit one?
|
|
|
|
|
if (coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CBreakPoints::ExecMemCheckJitBefore(addr, isWrite == 1, size, currentMIPS->pc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JitMemCheckCleanup()
|
|
|
|
|
{
|
|
|
|
|
CBreakPoints::ExecMemCheckJitCleanup();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 14:43:49 -07:00
|
|
|
static void JitLogMiss(MIPSOpcode op)
|
2013-01-19 20:11:17 -08:00
|
|
|
{
|
|
|
|
|
if (USE_JIT_MISSMAP)
|
|
|
|
|
notJitOps[MIPSGetName(op)]++;
|
|
|
|
|
|
|
|
|
|
MIPSInterpretFunc func = MIPSGetInterpretFunc(op);
|
|
|
|
|
func(op);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 19:38:42 -08:00
|
|
|
JitOptions::JitOptions()
|
|
|
|
|
{
|
|
|
|
|
enableBlocklink = true;
|
|
|
|
|
// WARNING: These options don't work properly with cache clearing.
|
|
|
|
|
// Need to find a smart way to handle before enabling.
|
|
|
|
|
immBranches = false;
|
|
|
|
|
continueBranches = false;
|
2013-11-10 20:29:30 -08:00
|
|
|
continueJumps = false;
|
2013-11-10 19:38:42 -08:00
|
|
|
continueMaxInstructions = 300;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-19 14:02:31 -07:00
|
|
|
#ifdef _MSC_VER
|
2013-05-31 22:15:49 -07:00
|
|
|
// JitBlockCache doesn't use this, just stores it.
|
|
|
|
|
#pragma warning(disable:4355)
|
2013-10-19 14:02:31 -07:00
|
|
|
#endif
|
2013-04-27 00:22:18 +02:00
|
|
|
Jit::Jit(MIPSState *mips) : blocks(mips, this), mips_(mips)
|
2012-11-01 16:19:01 +01:00
|
|
|
{
|
|
|
|
|
blocks.Init();
|
|
|
|
|
gpr.SetEmitter(this);
|
|
|
|
|
fpr.SetEmitter(this);
|
|
|
|
|
AllocCodeSpace(1024 * 1024 * 16);
|
2013-04-27 00:22:18 +02:00
|
|
|
asm_.Init(mips, this);
|
2013-02-18 01:14:57 -08:00
|
|
|
// TODO: If it becomes possible to switch from the interpreter, this should be set right.
|
|
|
|
|
js.startDefaultPrefix = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-28 14:01:26 +02:00
|
|
|
Jit::~Jit() {
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-18 01:14:57 -08:00
|
|
|
void Jit::DoState(PointerWrap &p)
|
|
|
|
|
{
|
2013-09-14 20:23:03 -07:00
|
|
|
auto s = p.Section("Jit", 1);
|
|
|
|
|
if (!s)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-02-18 01:14:57 -08:00
|
|
|
p.Do(js.startDefaultPrefix);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-08 08:49:21 -08:00
|
|
|
// This is here so the savestate matches between jit and non-jit.
|
|
|
|
|
void Jit::DoDummyState(PointerWrap &p)
|
|
|
|
|
{
|
2013-09-14 20:23:03 -07:00
|
|
|
auto s = p.Section("Jit", 1);
|
|
|
|
|
if (!s)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-03-08 08:49:21 -08:00
|
|
|
bool dummy = false;
|
|
|
|
|
p.Do(dummy);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:13:40 -07:00
|
|
|
|
|
|
|
|
void Jit::GetStateAndFlushAll(RegCacheState &state)
|
|
|
|
|
{
|
|
|
|
|
gpr.GetState(state.gpr);
|
|
|
|
|
fpr.GetState(state.fpr);
|
|
|
|
|
FlushAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Jit::RestoreState(const RegCacheState state)
|
|
|
|
|
{
|
|
|
|
|
gpr.RestoreState(state.gpr);
|
|
|
|
|
fpr.RestoreState(state.fpr);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
void Jit::FlushAll()
|
|
|
|
|
{
|
2013-01-25 23:09:11 +01:00
|
|
|
gpr.Flush();
|
|
|
|
|
fpr.Flush();
|
2013-02-15 01:12:43 -08:00
|
|
|
FlushPrefixV();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Jit::FlushPrefixV()
|
|
|
|
|
{
|
|
|
|
|
if ((js.prefixSFlag & JitState::PREFIX_DIRTY) != 0)
|
|
|
|
|
{
|
2014-01-18 09:57:13 -08:00
|
|
|
MOV(32, M(&mips_->vfpuCtrl[VFPU_CTRL_SPREFIX]), Imm32(js.prefixS));
|
2013-02-15 01:12:43 -08:00
|
|
|
js.prefixSFlag = (JitState::PrefixState) (js.prefixSFlag & ~JitState::PREFIX_DIRTY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((js.prefixTFlag & JitState::PREFIX_DIRTY) != 0)
|
|
|
|
|
{
|
2014-01-18 09:57:13 -08:00
|
|
|
MOV(32, M(&mips_->vfpuCtrl[VFPU_CTRL_TPREFIX]), Imm32(js.prefixT));
|
2013-02-15 01:12:43 -08:00
|
|
|
js.prefixTFlag = (JitState::PrefixState) (js.prefixTFlag & ~JitState::PREFIX_DIRTY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((js.prefixDFlag & JitState::PREFIX_DIRTY) != 0)
|
|
|
|
|
{
|
2014-01-18 09:57:13 -08:00
|
|
|
MOV(32, M(&mips_->vfpuCtrl[VFPU_CTRL_DPREFIX]), Imm32(js.prefixD));
|
2013-02-15 01:12:43 -08:00
|
|
|
js.prefixDFlag = (JitState::PrefixState) (js.prefixDFlag & ~JitState::PREFIX_DIRTY);
|
|
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-21 22:57:53 -08:00
|
|
|
void Jit::WriteDowncount(int offset)
|
|
|
|
|
{
|
|
|
|
|
const int downcount = js.downcountAmount + offset;
|
|
|
|
|
SUB(32, M(¤tMIPS->downcount), downcount > 127 ? Imm32(downcount) : Imm8(downcount));
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
void Jit::ClearCache()
|
|
|
|
|
{
|
|
|
|
|
blocks.Clear();
|
|
|
|
|
ClearCodeSpace();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 00:21:41 -07:00
|
|
|
void Jit::ClearCacheAt(u32 em_address, int length)
|
2013-01-18 10:43:40 -08:00
|
|
|
{
|
2013-09-01 00:21:41 -07:00
|
|
|
blocks.InvalidateICache(em_address, length);
|
2013-01-18 10:43:40 -08:00
|
|
|
}
|
|
|
|
|
|
2013-08-16 01:07:11 -07:00
|
|
|
void Jit::CompileDelaySlot(int flags, RegCacheState *state)
|
2013-01-18 21:23:30 -08:00
|
|
|
{
|
2013-01-20 16:42:35 -08:00
|
|
|
const u32 addr = js.compilerPC + 4;
|
|
|
|
|
|
2013-01-21 19:41:12 -08:00
|
|
|
// Need to offset the downcount which was already incremented for the branch + delay slot.
|
|
|
|
|
CheckJitBreakpoint(addr, -2);
|
2013-01-18 21:23:30 -08:00
|
|
|
|
2013-01-24 01:56:47 -08:00
|
|
|
if (flags & DELAYSLOT_SAFE)
|
2013-01-18 21:23:30 -08:00
|
|
|
SAVE_FLAGS; // preserve flag around the delay slot!
|
|
|
|
|
|
2013-01-21 22:45:07 -08:00
|
|
|
js.inDelaySlot = true;
|
2013-12-18 16:27:23 +01:00
|
|
|
MIPSOpcode op = Memory::Read_Opcode_JIT(addr);
|
2013-01-18 21:23:30 -08:00
|
|
|
MIPSCompileOp(op);
|
2013-01-21 22:45:07 -08:00
|
|
|
js.inDelaySlot = false;
|
2013-01-18 21:23:30 -08:00
|
|
|
|
2013-01-24 01:56:47 -08:00
|
|
|
if (flags & DELAYSLOT_FLUSH)
|
2013-08-16 01:07:11 -07:00
|
|
|
{
|
|
|
|
|
if (state != NULL)
|
|
|
|
|
GetStateAndFlushAll(*state);
|
|
|
|
|
else
|
|
|
|
|
FlushAll();
|
|
|
|
|
}
|
2013-01-24 01:56:47 -08:00
|
|
|
if (flags & DELAYSLOT_SAFE)
|
2013-01-18 21:23:30 -08:00
|
|
|
LOAD_FLAGS; // restore flag!
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 14:43:49 -07:00
|
|
|
void Jit::EatInstruction(MIPSOpcode op)
|
2013-02-02 13:12:34 -08:00
|
|
|
{
|
2013-08-24 13:22:10 -07:00
|
|
|
MIPSInfo info = MIPSGetInfo(op);
|
2013-09-07 12:34:19 +02:00
|
|
|
if (info & DELAYSLOT) {
|
|
|
|
|
ERROR_LOG_REPORT_ONCE(ateDelaySlot, JIT, "Ate a branch op.");
|
|
|
|
|
}
|
|
|
|
|
if (js.inDelaySlot) {
|
|
|
|
|
ERROR_LOG_REPORT_ONCE(ateInDelaySlot, JIT, "Ate an instruction inside a delay slot.")
|
|
|
|
|
}
|
2013-02-02 13:12:34 -08:00
|
|
|
|
|
|
|
|
CheckJitBreakpoint(js.compilerPC + 4, 0);
|
|
|
|
|
js.numInstructions++;
|
|
|
|
|
js.compilerPC += 4;
|
|
|
|
|
js.downcountAmount += MIPSGetInstructionCycleEstimate(op);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
void Jit::Compile(u32 em_address)
|
|
|
|
|
{
|
|
|
|
|
if (GetSpaceLeft() < 0x10000 || blocks.IsFull())
|
|
|
|
|
{
|
|
|
|
|
ClearCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int block_num = blocks.AllocateBlock(em_address);
|
|
|
|
|
JitBlock *b = blocks.GetBlock(block_num);
|
2013-04-26 23:39:23 +02:00
|
|
|
DoJit(em_address, b);
|
|
|
|
|
blocks.FinalizeBlock(block_num, jo.enableBlocklink);
|
2013-02-18 01:14:57 -08:00
|
|
|
|
|
|
|
|
// Drat. The VFPU hit an uneaten prefix at the end of a block.
|
2013-09-29 13:39:25 +02:00
|
|
|
if (js.startDefaultPrefix && js.MayHavePrefix()) {
|
|
|
|
|
WARN_LOG(JIT, "Uneaten prefix at end of block: %08x", js.compilerPC - 4);
|
2013-02-18 01:14:57 -08:00
|
|
|
js.startDefaultPrefix = false;
|
|
|
|
|
// Our assumptions are all wrong so it's clean-slate time.
|
|
|
|
|
ClearCache();
|
|
|
|
|
|
|
|
|
|
// Let's try that one more time. We won't get back here because we toggled the value.
|
|
|
|
|
Compile(em_address);
|
|
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Jit::RunLoopUntil(u64 globalticks)
|
|
|
|
|
{
|
|
|
|
|
((void (*)())asm_.enterCode)();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const u8 *Jit::DoJit(u32 em_address, JitBlock *b)
|
|
|
|
|
{
|
|
|
|
|
js.cancel = false;
|
|
|
|
|
js.blockStart = js.compilerPC = mips_->pc;
|
2013-08-16 00:44:23 -07:00
|
|
|
js.nextExit = 0;
|
2012-11-01 16:19:01 +01:00
|
|
|
js.downcountAmount = 0;
|
|
|
|
|
js.curBlock = b;
|
|
|
|
|
js.compiling = true;
|
|
|
|
|
js.inDelaySlot = false;
|
2013-03-09 02:34:31 -08:00
|
|
|
js.afterOp = JitState::AFTER_NONE;
|
2013-01-26 01:33:32 +01:00
|
|
|
js.PrefixStart();
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2013-01-03 12:46:10 +01:00
|
|
|
// We add a check before the block, used when entering from a linked block.
|
|
|
|
|
b->checkedEntry = GetCodePtr();
|
|
|
|
|
// Downcount flag check. The last block decremented downcounter, and the flag should still be available.
|
|
|
|
|
FixupBranch skip = J_CC(CC_NBE);
|
|
|
|
|
MOV(32, M(&mips_->pc), Imm32(js.blockStart));
|
|
|
|
|
JMP(asm_.outerLoop, true); // downcount hit zero - go advance.
|
|
|
|
|
SetJumpTarget(skip);
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
b->normalEntry = GetCodePtr();
|
|
|
|
|
|
2013-08-24 15:35:31 -07:00
|
|
|
MIPSAnalyst::AnalysisResults analysis = MIPSAnalyst::Analyze(em_address);
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
|
gpr.Start(mips_, analysis);
|
|
|
|
|
fpr.Start(mips_, analysis);
|
|
|
|
|
|
2013-02-02 13:12:34 -08:00
|
|
|
js.numInstructions = 0;
|
2013-08-10 23:04:23 +02:00
|
|
|
while (js.compiling) {
|
2013-01-21 19:41:12 -08:00
|
|
|
// Jit breakpoints are quite fast, so let's do them in release too.
|
|
|
|
|
CheckJitBreakpoint(js.compilerPC, 0);
|
|
|
|
|
|
2013-12-18 16:27:23 +01:00
|
|
|
MIPSOpcode inst = Memory::Read_Opcode_JIT(js.compilerPC);
|
2012-11-01 16:19:01 +01:00
|
|
|
js.downcountAmount += MIPSGetInstructionCycleEstimate(inst);
|
|
|
|
|
|
2013-01-18 20:58:29 -08:00
|
|
|
MIPSCompileOp(inst);
|
2013-01-18 10:19:43 -08:00
|
|
|
|
2013-08-10 23:04:23 +02:00
|
|
|
if (js.afterOp & JitState::AFTER_CORE_STATE) {
|
2013-03-09 02:34:31 -08:00
|
|
|
// TODO: Save/restore?
|
|
|
|
|
FlushAll();
|
2013-07-06 13:04:19 -07:00
|
|
|
|
2013-07-27 13:26:43 -07:00
|
|
|
// If we're rewinding, CORE_NEXTFRAME should not cause a rewind.
|
|
|
|
|
// It doesn't really matter either way if we're not rewinding.
|
|
|
|
|
// CORE_RUNNING is <= CORE_NEXTFRAME.
|
2014-01-18 09:57:13 -08:00
|
|
|
CMP(32, M(&coreState), Imm32(CORE_NEXTFRAME));
|
2013-07-27 13:26:43 -07:00
|
|
|
FixupBranch skipCheck = J_CC(CC_LE);
|
2013-07-27 15:05:16 -07:00
|
|
|
if (js.afterOp & JitState::AFTER_REWIND_PC_BAD_STATE)
|
|
|
|
|
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
|
|
|
|
else
|
|
|
|
|
MOV(32, M(&mips_->pc), Imm32(js.compilerPC + 4));
|
2013-07-27 13:26:43 -07:00
|
|
|
WriteSyscallExit();
|
|
|
|
|
SetJumpTarget(skipCheck);
|
2013-03-09 02:34:31 -08:00
|
|
|
|
|
|
|
|
js.afterOp = JitState::AFTER_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
js.compilerPC += 4;
|
2013-02-02 13:12:34 -08:00
|
|
|
js.numInstructions++;
|
2013-08-24 17:38:22 -07:00
|
|
|
|
|
|
|
|
// Safety check, in case we get a bunch of really large jit ops without a lot of branching.
|
|
|
|
|
if (GetSpaceLeft() < 0x800)
|
|
|
|
|
{
|
|
|
|
|
FlushAll();
|
|
|
|
|
WriteExit(js.compilerPC, js.nextExit++);
|
|
|
|
|
js.compiling = false;
|
|
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b->codeSize = (u32)(GetCodePtr() - b->normalEntry);
|
|
|
|
|
NOP();
|
|
|
|
|
AlignCode4();
|
2013-02-02 13:12:34 -08:00
|
|
|
b->originalSize = js.numInstructions;
|
2012-11-01 16:19:01 +01:00
|
|
|
return b->normalEntry;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 23:57:39 -08:00
|
|
|
bool Jit::DescribeCodePtr(const u8 *ptr, std::string &name)
|
|
|
|
|
{
|
|
|
|
|
u32 jitAddr = blocks.GetAddressFromBlockPtr(ptr);
|
|
|
|
|
|
|
|
|
|
// Returns 0 when it's valid, but unknown.
|
|
|
|
|
if (jitAddr == 0)
|
|
|
|
|
name = "UnknownOrDeletedBlock";
|
|
|
|
|
else if (jitAddr != (u32)-1)
|
|
|
|
|
{
|
|
|
|
|
char temp[1024];
|
2014-01-25 21:40:23 -08:00
|
|
|
const std::string label = symbolMap.GetDescription(jitAddr);
|
|
|
|
|
if (!label.empty())
|
|
|
|
|
snprintf(temp, sizeof(temp), "%08x_%s", jitAddr, label.c_str());
|
2013-12-18 23:57:39 -08:00
|
|
|
else
|
|
|
|
|
snprintf(temp, sizeof(temp), "%08x", jitAddr);
|
|
|
|
|
name = temp;
|
|
|
|
|
}
|
|
|
|
|
else if (asm_.IsInSpace(ptr))
|
|
|
|
|
name = "RunLoopUntil";
|
|
|
|
|
else if (thunks.IsInSpace(ptr))
|
|
|
|
|
name = "Thunk";
|
|
|
|
|
else if (IsInSpace(ptr))
|
|
|
|
|
name = "Unknown";
|
|
|
|
|
// Not anywhere in jit, then.
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// If we got here, one of the above cases matched.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 14:43:49 -07:00
|
|
|
void Jit::Comp_RunBlock(MIPSOpcode op)
|
2012-11-01 16:19:01 +01:00
|
|
|
{
|
|
|
|
|
// This shouldn't be necessary, the dispatcher should catch us before we get here.
|
2013-09-07 21:19:21 +02:00
|
|
|
ERROR_LOG(JIT, "Comp_RunBlock");
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-18 16:27:23 +01:00
|
|
|
bool Jit::ReplaceJalTo(u32 dest) {
|
2013-12-19 00:39:49 +01:00
|
|
|
MIPSOpcode op(Memory::Read_Opcode_JIT(dest));
|
|
|
|
|
if (!MIPS_IS_REPLACEMENT(op.encoding))
|
2013-12-18 16:27:23 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int index = op.encoding & MIPS_EMUHACK_VALUE_MASK;
|
|
|
|
|
const ReplacementTableEntry *entry = GetReplacementFunc(index);
|
|
|
|
|
if (!entry) {
|
|
|
|
|
ERROR_LOG(HLE, "ReplaceJalTo: Invalid replacement op %08x at %08x", op.encoding, dest);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Warning - this might be bad if the code at the destination changes...
|
|
|
|
|
if (entry->flags & REPFLAG_ALLOWINLINE) {
|
|
|
|
|
// Jackpot! Just do it, no flushing. The code will be entirely inlined.
|
|
|
|
|
|
|
|
|
|
// First, compile the delay slot. It's unconditional so no issues.
|
|
|
|
|
CompileDelaySlot(DELAYSLOT_NICE);
|
|
|
|
|
// Technically, we should write the unused return address to RA, but meh.
|
|
|
|
|
MIPSReplaceFunc repl = entry->jitReplaceFunc;
|
|
|
|
|
int cycles = (this->*repl)();
|
|
|
|
|
js.downcountAmount += cycles;
|
2013-12-20 15:37:37 +01:00
|
|
|
js.compilerPC += 4;
|
2013-12-18 16:27:23 +01:00
|
|
|
// No writing exits, keep going!
|
2013-12-19 00:39:49 +01:00
|
|
|
|
|
|
|
|
// Add a trigger so that if the inlined code changes, we invalidate this block.
|
|
|
|
|
// TODO: Correctly determine the size of this block.
|
2013-12-19 11:45:39 +01:00
|
|
|
blocks.ProxyBlock(js.blockStart, dest, 4, GetCodePtr());
|
2013-12-18 16:27:23 +01:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-30 20:57:44 +01:00
|
|
|
void Jit::Comp_ReplacementFunc(MIPSOpcode op)
|
|
|
|
|
{
|
2013-12-17 23:40:27 +01:00
|
|
|
// We get here if we execute the first instruction of a replaced function. This means
|
|
|
|
|
// that we do need to return to RA.
|
|
|
|
|
|
|
|
|
|
// Inlined function calls (caught in jal) are handled differently.
|
|
|
|
|
|
|
|
|
|
int index = op.encoding & MIPS_EMUHACK_VALUE_MASK;
|
2013-12-19 11:45:39 +01:00
|
|
|
|
2013-11-30 20:57:44 +01:00
|
|
|
const ReplacementTableEntry *entry = GetReplacementFunc(index);
|
2013-12-17 23:40:27 +01:00
|
|
|
if (!entry) {
|
|
|
|
|
ERROR_LOG(HLE, "Invalid replacement op %08x", op.encoding);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-11-30 20:57:44 +01:00
|
|
|
|
2013-12-17 23:40:27 +01:00
|
|
|
// JIT goes first.
|
|
|
|
|
if (entry->jitReplaceFunc) {
|
|
|
|
|
MIPSReplaceFunc repl = entry->jitReplaceFunc;
|
|
|
|
|
int cycles = (this->*repl)();
|
|
|
|
|
FlushAll();
|
|
|
|
|
MOV(32, R(ECX), M(¤tMIPS->r[MIPS_REG_RA]));
|
|
|
|
|
js.downcountAmount = cycles;
|
|
|
|
|
WriteExitDestInReg(ECX);
|
|
|
|
|
js.compiling = false;
|
|
|
|
|
} else if (entry->replaceFunc) {
|
|
|
|
|
FlushAll();
|
2013-12-18 10:35:16 +01:00
|
|
|
|
2013-12-17 23:40:27 +01:00
|
|
|
// Standard function call, nothing fancy.
|
|
|
|
|
// The function returns the number of cycles it took in EAX.
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunction(entry->replaceFunc);
|
2013-12-17 23:40:27 +01:00
|
|
|
// Alternatively, we could inline it here, instead of calling out, if it's a function
|
|
|
|
|
// we can emit.
|
2013-11-30 20:57:44 +01:00
|
|
|
|
2013-12-17 23:40:27 +01:00
|
|
|
MOV(32, R(ECX), M(¤tMIPS->r[MIPS_REG_RA]));
|
|
|
|
|
SUB(32, M(¤tMIPS->downcount - 1), R(EAX));
|
|
|
|
|
js.downcountAmount = 1; // we just subtracted most of it
|
|
|
|
|
WriteExitDestInReg(ECX);
|
2013-11-30 20:57:44 +01:00
|
|
|
|
2013-12-17 23:40:27 +01:00
|
|
|
js.compiling = false;
|
|
|
|
|
} else {
|
2013-12-18 10:35:16 +01:00
|
|
|
ERROR_LOG(HLE, "Replacement function %s has neither jit nor regular impl", entry->name);
|
2013-12-17 23:40:27 +01:00
|
|
|
}
|
2013-11-30 20:57:44 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-24 14:43:49 -07:00
|
|
|
void Jit::Comp_Generic(MIPSOpcode op)
|
2012-11-01 16:19:01 +01:00
|
|
|
{
|
|
|
|
|
FlushAll();
|
|
|
|
|
MIPSInterpretFunc func = MIPSGetInterpretFunc(op);
|
2013-01-22 08:11:37 -08:00
|
|
|
_dbg_assert_msg_(JIT, (MIPSGetInfo(op) & DELAYSLOT) == 0, "Cannot use interpreter for branch ops.");
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
if (func)
|
|
|
|
|
{
|
|
|
|
|
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
2013-01-19 20:11:17 -08:00
|
|
|
if (USE_JIT_MISSMAP)
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunctionC(&JitLogMiss, op.encoding);
|
2013-01-19 20:11:17 -08:00
|
|
|
else
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunctionC(func, op.encoding);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
2013-01-19 20:11:17 -08:00
|
|
|
else
|
2013-08-25 16:28:19 -04:00
|
|
|
ERROR_LOG_REPORT(JIT, "Trying to compile instruction %08x that can't be interpreted", op.encoding);
|
2013-02-15 01:53:53 -08:00
|
|
|
|
2013-08-24 13:22:10 -07:00
|
|
|
const MIPSInfo info = MIPSGetInfo(op);
|
2013-02-18 01:18:46 -08:00
|
|
|
if ((info & IS_VFPU) != 0 && (info & VFPU_NO_PREFIX) == 0)
|
|
|
|
|
{
|
|
|
|
|
// If it does eat them, it'll happen in MIPSCompileOp().
|
|
|
|
|
if ((info & OUT_EAT_PREFIX) == 0)
|
|
|
|
|
js.PrefixUnknown();
|
|
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Jit::WriteExit(u32 destination, int exit_num)
|
|
|
|
|
{
|
2013-08-15 23:23:39 -07:00
|
|
|
_dbg_assert_msg_(JIT, exit_num < MAX_JIT_BLOCK_EXITS, "Expected a valid exit_num");
|
|
|
|
|
|
2013-04-13 21:24:07 +02:00
|
|
|
if (!Memory::IsValidAddress(destination)) {
|
2013-08-11 18:20:43 -07:00
|
|
|
ERROR_LOG_REPORT(JIT, "Trying to write block exit to illegal destination %08x: pc = %08x", destination, currentMIPS->pc);
|
2013-04-13 21:24:07 +02:00
|
|
|
}
|
2013-03-09 02:34:31 -08:00
|
|
|
// If we need to verify coreState and rewind, we may not jump yet.
|
|
|
|
|
if (js.afterOp & (JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE))
|
|
|
|
|
{
|
2013-07-27 13:26:43 -07:00
|
|
|
// CORE_RUNNING is <= CORE_NEXTFRAME.
|
2014-01-18 09:57:13 -08:00
|
|
|
CMP(32, M(&coreState), Imm32(CORE_NEXTFRAME));
|
2013-07-27 13:26:43 -07:00
|
|
|
FixupBranch skipCheck = J_CC(CC_LE);
|
2013-03-09 02:34:31 -08:00
|
|
|
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
|
|
|
|
WriteSyscallExit();
|
2013-07-27 13:26:43 -07:00
|
|
|
SetJumpTarget(skipCheck);
|
2013-03-09 02:34:31 -08:00
|
|
|
|
|
|
|
|
js.afterOp = JitState::AFTER_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 22:57:53 -08:00
|
|
|
WriteDowncount();
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
|
//If nobody has taken care of this yet (this can be removed when all branches are done)
|
|
|
|
|
JitBlock *b = js.curBlock;
|
|
|
|
|
b->exitAddress[exit_num] = destination;
|
|
|
|
|
b->exitPtrs[exit_num] = GetWritableCodePtr();
|
|
|
|
|
|
|
|
|
|
// Link opportunity!
|
|
|
|
|
int block = blocks.GetBlockNumberFromStartAddress(destination);
|
2013-03-09 02:34:31 -08:00
|
|
|
if (block >= 0 && jo.enableBlocklink) {
|
2013-01-08 21:24:42 +01:00
|
|
|
// It exists! Joy of joy!
|
|
|
|
|
JMP(blocks.GetBlock(block)->checkedEntry, true);
|
|
|
|
|
b->linkStatus[exit_num] = true;
|
|
|
|
|
} else {
|
|
|
|
|
// No blocklinking.
|
|
|
|
|
MOV(32, M(&mips_->pc), Imm32(destination));
|
|
|
|
|
JMP(asm_.dispatcher, true);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 23:40:27 +01:00
|
|
|
void Jit::WriteExitDestInReg(X64Reg reg)
|
2012-11-01 16:19:01 +01:00
|
|
|
{
|
2013-01-21 22:57:53 -08:00
|
|
|
// TODO: Some wasted potential, dispatcher will always read this back into EAX.
|
2013-12-17 23:40:27 +01:00
|
|
|
MOV(32, M(&mips_->pc), R(reg));
|
2013-03-09 02:34:31 -08:00
|
|
|
|
|
|
|
|
// If we need to verify coreState and rewind, we may not jump yet.
|
|
|
|
|
if (js.afterOp & (JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE))
|
|
|
|
|
{
|
2013-07-27 13:26:43 -07:00
|
|
|
// CORE_RUNNING is <= CORE_NEXTFRAME.
|
2014-01-18 09:57:13 -08:00
|
|
|
CMP(32, M(&coreState), Imm32(CORE_NEXTFRAME));
|
2013-07-27 13:26:43 -07:00
|
|
|
FixupBranch skipCheck = J_CC(CC_LE);
|
2013-03-09 02:34:31 -08:00
|
|
|
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
|
|
|
|
WriteSyscallExit();
|
2013-07-27 13:26:43 -07:00
|
|
|
SetJumpTarget(skipCheck);
|
2013-03-09 02:34:31 -08:00
|
|
|
|
|
|
|
|
js.afterOp = JitState::AFTER_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 22:57:53 -08:00
|
|
|
WriteDowncount();
|
2013-02-09 23:11:26 -08:00
|
|
|
|
|
|
|
|
// Validate the jump to avoid a crash?
|
|
|
|
|
if (!g_Config.bFastMemory)
|
|
|
|
|
{
|
2013-12-17 23:40:27 +01:00
|
|
|
CMP(32, R(reg), Imm32(PSP_GetKernelMemoryBase()));
|
2013-03-09 00:18:25 -08:00
|
|
|
FixupBranch tooLow = J_CC(CC_B);
|
2013-12-17 23:40:27 +01:00
|
|
|
CMP(32, R(reg), Imm32(PSP_GetUserMemoryEnd()));
|
2013-03-09 00:18:25 -08:00
|
|
|
FixupBranch tooHigh = J_CC(CC_AE);
|
2013-02-09 23:11:26 -08:00
|
|
|
|
2013-02-23 14:27:57 -08:00
|
|
|
// Need to set neg flag again if necessary.
|
|
|
|
|
SUB(32, M(¤tMIPS->downcount), Imm32(0));
|
2013-02-09 23:11:26 -08:00
|
|
|
JMP(asm_.dispatcher, true);
|
|
|
|
|
|
|
|
|
|
SetJumpTarget(tooLow);
|
|
|
|
|
SetJumpTarget(tooHigh);
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
CallProtectedFunction(Memory::GetPointer, R(reg));
|
2013-12-17 23:40:27 +01:00
|
|
|
CMP(32, R(reg), Imm32(0));
|
2013-02-23 14:27:57 -08:00
|
|
|
FixupBranch skip = J_CC(CC_NE);
|
2013-02-09 23:11:26 -08:00
|
|
|
|
|
|
|
|
// TODO: "Ignore" this so other threads can continue?
|
|
|
|
|
if (g_Config.bIgnoreBadMemAccess)
|
2014-01-18 09:57:13 -08:00
|
|
|
CallProtectedFunction(Core_UpdateState, Imm32(CORE_ERROR));
|
2013-02-23 14:27:57 -08:00
|
|
|
|
|
|
|
|
SUB(32, M(¤tMIPS->downcount), Imm32(0));
|
2013-02-09 23:11:26 -08:00
|
|
|
JMP(asm_.dispatcherCheckCoreState, true);
|
2013-02-23 14:27:57 -08:00
|
|
|
SetJumpTarget(skip);
|
|
|
|
|
|
|
|
|
|
SUB(32, M(¤tMIPS->downcount), Imm32(0));
|
|
|
|
|
J_CC(CC_NE, asm_.dispatcher, true);
|
2013-02-09 23:11:26 -08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
JMP(asm_.dispatcher, true);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Jit::WriteSyscallExit()
|
|
|
|
|
{
|
2013-01-21 22:57:53 -08:00
|
|
|
WriteDowncount();
|
2014-01-26 11:52:37 -08:00
|
|
|
if ((js.afterOp & JitState::AFTER_MEMCHECK_CLEANUP) != 0) {
|
|
|
|
|
ABI_CallFunction(&JitMemCheckCleanup);
|
|
|
|
|
js.afterOp &= ~JitState::AFTER_MEMCHECK_CLEANUP;
|
|
|
|
|
}
|
2012-12-25 09:01:17 +01:00
|
|
|
JMP(asm_.dispatcherCheckCoreState, true);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-21 19:41:12 -08:00
|
|
|
bool Jit::CheckJitBreakpoint(u32 addr, int downcountOffset)
|
2013-01-18 20:58:29 -08:00
|
|
|
{
|
|
|
|
|
if (CBreakPoints::IsAddressBreakPoint(addr))
|
|
|
|
|
{
|
2013-06-29 11:45:29 -07:00
|
|
|
SAVE_FLAGS;
|
2013-01-18 20:58:29 -08:00
|
|
|
FlushAll();
|
|
|
|
|
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunction(&JitBreakpoint);
|
2013-01-21 19:41:12 -08:00
|
|
|
|
2013-06-29 11:22:58 -07:00
|
|
|
// If 0, the conditional breakpoint wasn't taken.
|
|
|
|
|
CMP(32, R(EAX), Imm32(0));
|
|
|
|
|
FixupBranch skip = J_CC(CC_Z);
|
2013-01-21 22:57:53 -08:00
|
|
|
WriteDowncount(downcountOffset);
|
2013-06-29 11:45:29 -07:00
|
|
|
// Just to fix the stack.
|
|
|
|
|
LOAD_FLAGS;
|
2013-01-21 19:41:12 -08:00
|
|
|
JMP(asm_.dispatcherCheckCoreState, true);
|
2013-06-29 11:22:58 -07:00
|
|
|
SetJumpTarget(skip);
|
2013-01-18 20:58:29 -08:00
|
|
|
|
2013-06-29 11:45:29 -07:00
|
|
|
LOAD_FLAGS;
|
|
|
|
|
|
2013-01-18 20:58:29 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 19:31:12 -07:00
|
|
|
Jit::JitSafeMem::JitSafeMem(Jit *jit, MIPSGPReg raddr, s32 offset, u32 alignMask)
|
2013-07-04 15:46:07 -07:00
|
|
|
: jit_(jit), raddr_(raddr), offset_(offset), needsCheck_(false), needsSkip_(false), alignMask_(alignMask)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-01-26 23:08:19 -08:00
|
|
|
// This makes it more instructions, so let's play it safe and say we need a far jump.
|
2013-06-30 15:16:58 -07:00
|
|
|
far_ = !g_Config.bIgnoreBadMemAccess || !CBreakPoints::GetMemChecks().empty();
|
2013-11-10 20:55:20 -08:00
|
|
|
if (jit_->gpr.IsImm(raddr_))
|
|
|
|
|
iaddr_ = jit_->gpr.GetImm(raddr_) + offset_;
|
2013-01-26 23:18:50 -08:00
|
|
|
else
|
|
|
|
|
iaddr_ = (u32) -1;
|
2013-09-07 22:43:02 -07:00
|
|
|
|
|
|
|
|
fast_ = g_Config.bFastMemory || raddr == MIPS_REG_SP;
|
2013-01-26 23:08:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Jit::JitSafeMem::SetFar()
|
|
|
|
|
{
|
|
|
|
|
_dbg_assert_msg_(JIT, !needsSkip_, "Sorry, you need to call SetFar() earlier.");
|
|
|
|
|
far_ = true;
|
2013-01-26 08:42:34 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-08 22:50:08 -08:00
|
|
|
bool Jit::JitSafeMem::PrepareWrite(OpArg &dest, int size)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-03-08 23:18:34 -08:00
|
|
|
size_ = size;
|
2013-01-26 08:42:34 -08:00
|
|
|
// If it's an immediate, we can do the write if valid.
|
2013-01-26 23:18:50 -08:00
|
|
|
if (iaddr_ != (u32) -1)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-03-08 23:18:34 -08:00
|
|
|
if (ImmValid())
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-03-08 23:18:34 -08:00
|
|
|
MemCheckImm(MEM_WRITE);
|
2013-03-08 22:50:08 -08:00
|
|
|
|
2013-01-26 08:42:34 -08:00
|
|
|
#ifdef _M_IX86
|
2013-07-04 15:46:07 -07:00
|
|
|
dest = M(Memory::base + (iaddr_ & Memory::MEMVIEW32_MASK & alignMask_));
|
2013-01-26 08:42:34 -08:00
|
|
|
#else
|
2013-07-04 15:46:07 -07:00
|
|
|
dest = MDisp(RBX, iaddr_ & alignMask_);
|
2013-01-26 08:42:34 -08:00
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Otherwise, we always can do the write (conditionally.)
|
|
|
|
|
else
|
2013-03-08 23:18:34 -08:00
|
|
|
dest = PrepareMemoryOpArg(MEM_WRITE);
|
2013-01-26 08:42:34 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-08 22:50:08 -08:00
|
|
|
bool Jit::JitSafeMem::PrepareRead(OpArg &src, int size)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-03-08 23:18:34 -08:00
|
|
|
size_ = size;
|
2013-01-26 23:18:50 -08:00
|
|
|
if (iaddr_ != (u32) -1)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-03-08 23:18:34 -08:00
|
|
|
if (ImmValid())
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-03-08 23:18:34 -08:00
|
|
|
MemCheckImm(MEM_READ);
|
2013-03-08 22:50:08 -08:00
|
|
|
|
2013-01-26 08:42:34 -08:00
|
|
|
#ifdef _M_IX86
|
2013-07-04 15:46:07 -07:00
|
|
|
src = M(Memory::base + (iaddr_ & Memory::MEMVIEW32_MASK & alignMask_));
|
2013-01-26 08:42:34 -08:00
|
|
|
#else
|
2013-07-04 15:46:07 -07:00
|
|
|
src = MDisp(RBX, iaddr_ & alignMask_);
|
2013-01-26 08:42:34 -08:00
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-03-08 23:18:34 -08:00
|
|
|
src = PrepareMemoryOpArg(MEM_READ);
|
2013-01-26 08:42:34 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-26 10:07:05 -08:00
|
|
|
OpArg Jit::JitSafeMem::NextFastAddress(int suboffset)
|
|
|
|
|
{
|
2013-11-10 20:55:20 -08:00
|
|
|
if (jit_->gpr.IsImm(raddr_))
|
2013-01-26 10:07:05 -08:00
|
|
|
{
|
2013-11-10 20:55:20 -08:00
|
|
|
u32 addr = (jit_->gpr.GetImm(raddr_) + offset_ + suboffset) & alignMask_;
|
2013-01-26 10:07:05 -08:00
|
|
|
|
|
|
|
|
#ifdef _M_IX86
|
2013-01-26 23:54:43 -08:00
|
|
|
return M(Memory::base + (addr & Memory::MEMVIEW32_MASK));
|
2013-01-26 10:07:05 -08:00
|
|
|
#else
|
|
|
|
|
return MDisp(RBX, addr);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-07 22:02:55 +02:00
|
|
|
_dbg_assert_msg_(JIT, (suboffset & alignMask_) == suboffset, "suboffset must be aligned");
|
2013-07-04 15:46:07 -07:00
|
|
|
|
2013-01-26 10:07:05 -08:00
|
|
|
#ifdef _M_IX86
|
|
|
|
|
return MDisp(xaddr_, (u32) Memory::base + offset_ + suboffset);
|
|
|
|
|
#else
|
|
|
|
|
return MComplex(RBX, xaddr_, SCALE_1, offset_ + suboffset);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-08 23:18:34 -08:00
|
|
|
OpArg Jit::JitSafeMem::PrepareMemoryOpArg(ReadType type)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
|
|
|
|
// We may not even need to move into EAX as a temporary.
|
2013-07-04 15:46:07 -07:00
|
|
|
bool needTemp = alignMask_ != 0xFFFFFFFF;
|
|
|
|
|
#ifdef _M_IX86
|
|
|
|
|
// We always mask on 32 bit in fast memory mode.
|
2013-09-07 22:43:02 -07:00
|
|
|
needTemp = needTemp || fast_;
|
2013-07-04 15:46:07 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (jit_->gpr.R(raddr_).IsSimpleReg() && !needTemp)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-11-09 15:23:31 +01:00
|
|
|
jit_->gpr.MapReg(raddr_, true, false);
|
2013-01-26 08:42:34 -08:00
|
|
|
xaddr_ = jit_->gpr.RX(raddr_);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
jit_->MOV(32, R(EAX), jit_->gpr.R(raddr_));
|
|
|
|
|
xaddr_ = EAX;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-08 23:18:34 -08:00
|
|
|
MemCheckAsm(type);
|
2013-03-08 22:50:08 -08:00
|
|
|
|
2013-09-07 22:43:02 -07:00
|
|
|
if (!fast_)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
|
|
|
|
// Is it in physical ram?
|
2013-02-09 23:04:39 -08:00
|
|
|
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetKernelMemoryBase() - offset_));
|
2013-03-09 00:18:25 -08:00
|
|
|
tooLow_ = jit_->J_CC(CC_B);
|
2013-03-08 23:18:34 -08:00
|
|
|
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetUserMemoryEnd() - offset_ - (size_ - 1)));
|
2013-03-09 00:18:25 -08:00
|
|
|
tooHigh_ = jit_->J_CC(CC_AE);
|
2013-01-26 08:42:34 -08:00
|
|
|
|
|
|
|
|
// We may need to jump back up here.
|
|
|
|
|
safe_ = jit_->GetCodePtr();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#ifdef _M_IX86
|
|
|
|
|
jit_->AND(32, R(EAX), Imm32(Memory::MEMVIEW32_MASK));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 15:46:07 -07:00
|
|
|
// TODO: This could be more optimal, but the common case is that we want xaddr_ not to include offset_.
|
|
|
|
|
// Since we need to align them after add, we add and subtract.
|
|
|
|
|
if (alignMask_ != 0xFFFFFFFF)
|
|
|
|
|
{
|
|
|
|
|
jit_->ADD(32, R(xaddr_), Imm32(offset_));
|
|
|
|
|
jit_->AND(32, R(xaddr_), Imm32(alignMask_));
|
|
|
|
|
jit_->SUB(32, R(xaddr_), Imm32(offset_));
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-26 08:42:34 -08:00
|
|
|
#ifdef _M_IX86
|
2013-07-04 15:46:07 -07:00
|
|
|
return MDisp(xaddr_, (u32) Memory::base + offset_);
|
2013-01-26 08:42:34 -08:00
|
|
|
#else
|
2013-07-04 15:46:07 -07:00
|
|
|
return MComplex(RBX, xaddr_, SCALE_1, offset_);
|
2013-01-26 08:42:34 -08:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Jit::JitSafeMem::PrepareSlowAccess()
|
|
|
|
|
{
|
|
|
|
|
// Skip the fast path (which the caller wrote just now.)
|
2013-01-26 23:08:19 -08:00
|
|
|
skip_ = jit_->J(far_);
|
2013-01-26 08:42:34 -08:00
|
|
|
needsSkip_ = true;
|
|
|
|
|
jit_->SetJumpTarget(tooLow_);
|
|
|
|
|
jit_->SetJumpTarget(tooHigh_);
|
|
|
|
|
|
|
|
|
|
// Might also be the scratchpad.
|
2013-02-09 23:04:39 -08:00
|
|
|
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetScratchpadMemoryBase() - offset_));
|
2013-03-09 00:18:25 -08:00
|
|
|
FixupBranch tooLow = jit_->J_CC(CC_B);
|
2013-03-08 23:18:34 -08:00
|
|
|
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetScratchpadMemoryEnd() - offset_ - (size_ - 1)));
|
2013-03-09 00:18:25 -08:00
|
|
|
jit_->J_CC(CC_B, safe_);
|
2013-01-26 08:42:34 -08:00
|
|
|
jit_->SetJumpTarget(tooLow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Jit::JitSafeMem::PrepareSlowWrite()
|
|
|
|
|
{
|
|
|
|
|
// If it's immediate, we only need a slow write on invalid.
|
2013-01-26 23:18:50 -08:00
|
|
|
if (iaddr_ != (u32) -1)
|
2013-09-07 22:43:02 -07:00
|
|
|
return !fast_ && !ImmValid();
|
2013-01-26 08:42:34 -08:00
|
|
|
|
2013-09-07 22:43:02 -07:00
|
|
|
if (!fast_)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
|
|
|
|
PrepareSlowAccess();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
void Jit::JitSafeMem::DoSlowWrite(const void *safeFunc, const OpArg src, int suboffset)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-01-26 23:18:50 -08:00
|
|
|
if (iaddr_ != (u32) -1)
|
2013-07-04 15:46:07 -07:00
|
|
|
jit_->MOV(32, R(EAX), Imm32((iaddr_ + suboffset) & alignMask_));
|
2013-01-26 08:42:34 -08:00
|
|
|
else
|
2013-07-04 15:46:07 -07:00
|
|
|
{
|
2013-01-26 10:07:05 -08:00
|
|
|
jit_->LEA(32, EAX, MDisp(xaddr_, offset_ + suboffset));
|
2013-07-04 15:46:07 -07:00
|
|
|
if (alignMask_ != 0xFFFFFFFF)
|
|
|
|
|
jit_->AND(32, R(EAX), Imm32(alignMask_));
|
|
|
|
|
}
|
2013-01-26 08:42:34 -08:00
|
|
|
|
2013-07-06 00:54:53 -07:00
|
|
|
jit_->CallProtectedFunction(safeFunc, src, R(EAX));
|
2013-01-26 08:42:34 -08:00
|
|
|
needsCheck_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
bool Jit::JitSafeMem::PrepareSlowRead(const void *safeFunc)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-09-07 22:43:02 -07:00
|
|
|
if (!fast_)
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-01-26 23:18:50 -08:00
|
|
|
if (iaddr_ != (u32) -1)
|
2013-01-26 09:23:43 -08:00
|
|
|
{
|
|
|
|
|
// No slow read necessary.
|
2013-03-08 23:18:34 -08:00
|
|
|
if (ImmValid())
|
2013-01-26 09:23:43 -08:00
|
|
|
return false;
|
2013-07-04 15:46:07 -07:00
|
|
|
jit_->MOV(32, R(EAX), Imm32(iaddr_ & alignMask_));
|
2013-01-26 09:23:43 -08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrepareSlowAccess();
|
|
|
|
|
jit_->LEA(32, EAX, MDisp(xaddr_, offset_));
|
2013-07-04 15:46:07 -07:00
|
|
|
if (alignMask_ != 0xFFFFFFFF)
|
|
|
|
|
jit_->AND(32, R(EAX), Imm32(alignMask_));
|
2013-01-26 09:23:43 -08:00
|
|
|
}
|
2013-01-26 08:42:34 -08:00
|
|
|
|
2013-07-06 00:54:53 -07:00
|
|
|
jit_->CallProtectedFunction(safeFunc, R(EAX));
|
2013-01-26 08:42:34 -08:00
|
|
|
needsCheck_ = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
void Jit::JitSafeMem::NextSlowRead(const void *safeFunc, int suboffset)
|
2013-01-26 10:07:05 -08:00
|
|
|
{
|
2013-09-07 22:43:02 -07:00
|
|
|
_dbg_assert_msg_(JIT, !fast_, "NextSlowRead() called in fast memory mode?");
|
2013-01-26 10:07:05 -08:00
|
|
|
|
|
|
|
|
// For simplicity, do nothing for 0. We already read in PrepareSlowRead().
|
|
|
|
|
if (suboffset == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-11-10 20:55:20 -08:00
|
|
|
if (jit_->gpr.IsImm(raddr_))
|
2013-01-26 10:07:05 -08:00
|
|
|
{
|
2013-07-04 15:46:07 -07:00
|
|
|
_dbg_assert_msg_(JIT, !Memory::IsValidAddress(iaddr_ + suboffset), "NextSlowRead() for an invalid immediate address?");
|
2013-01-26 10:07:05 -08:00
|
|
|
|
2013-07-04 15:46:07 -07:00
|
|
|
jit_->MOV(32, R(EAX), Imm32((iaddr_ + suboffset) & alignMask_));
|
2013-01-26 10:07:05 -08:00
|
|
|
}
|
|
|
|
|
// For GPR, if xaddr_ was the dest register, this will be wrong. Don't use in GPR.
|
|
|
|
|
else
|
2013-07-04 15:46:07 -07:00
|
|
|
{
|
2013-01-26 10:07:05 -08:00
|
|
|
jit_->LEA(32, EAX, MDisp(xaddr_, offset_ + suboffset));
|
2013-07-04 15:46:07 -07:00
|
|
|
if (alignMask_ != 0xFFFFFFFF)
|
|
|
|
|
jit_->AND(32, R(EAX), Imm32(alignMask_));
|
|
|
|
|
}
|
2013-01-26 10:07:05 -08:00
|
|
|
|
2013-07-06 00:54:53 -07:00
|
|
|
jit_->CallProtectedFunction(safeFunc, R(EAX));
|
2013-01-26 10:07:05 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-08 23:18:34 -08:00
|
|
|
bool Jit::JitSafeMem::ImmValid()
|
|
|
|
|
{
|
|
|
|
|
return iaddr_ != (u32) -1 && Memory::IsValidAddress(iaddr_) && Memory::IsValidAddress(iaddr_ + size_ - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-26 09:09:47 -08:00
|
|
|
void Jit::JitSafeMem::Finish()
|
2013-01-26 08:42:34 -08:00
|
|
|
{
|
2013-03-08 22:52:55 -08:00
|
|
|
// Memory::Read_U32/etc. may have tripped coreState.
|
|
|
|
|
if (needsCheck_ && !g_Config.bIgnoreBadMemAccess)
|
2013-06-30 16:07:15 -07:00
|
|
|
jit_->js.afterOp |= JitState::AFTER_CORE_STATE;
|
2013-01-26 08:42:34 -08:00
|
|
|
if (needsSkip_)
|
|
|
|
|
jit_->SetJumpTarget(skip_);
|
2013-03-09 02:34:31 -08:00
|
|
|
for (auto it = skipChecks_.begin(), end = skipChecks_.end(); it != end; ++it)
|
|
|
|
|
jit_->SetJumpTarget(*it);
|
2013-03-09 00:09:55 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-08 23:18:34 -08:00
|
|
|
void Jit::JitSafeMem::MemCheckImm(ReadType type)
|
2013-03-08 22:50:08 -08:00
|
|
|
{
|
2013-03-09 00:35:08 -08:00
|
|
|
MemCheck *check = CBreakPoints::GetMemCheck(iaddr_, size_);
|
2013-03-09 00:09:55 -08:00
|
|
|
if (check)
|
|
|
|
|
{
|
2013-06-30 15:16:58 -07:00
|
|
|
if (!(check->cond & MEMCHECK_READ) && type == MEM_READ)
|
2013-03-09 00:40:33 -08:00
|
|
|
return;
|
2013-06-30 15:16:58 -07:00
|
|
|
if (!(check->cond & MEMCHECK_WRITE) && type == MEM_WRITE)
|
2013-03-09 00:40:33 -08:00
|
|
|
return;
|
|
|
|
|
|
2013-03-09 00:09:55 -08:00
|
|
|
jit_->MOV(32, M(&jit_->mips_->pc), Imm32(jit_->js.compilerPC));
|
2014-01-18 09:57:13 -08:00
|
|
|
jit_->CallProtectedFunction(&JitMemCheck, iaddr_, size_, type == MEM_WRITE ? 1 : 0);
|
2013-03-09 00:09:55 -08:00
|
|
|
|
2013-07-27 13:26:43 -07:00
|
|
|
// CORE_RUNNING is <= CORE_NEXTFRAME.
|
2014-01-18 09:57:13 -08:00
|
|
|
jit_->CMP(32, M(&coreState), Imm32(CORE_NEXTFRAME));
|
2013-07-27 13:26:43 -07:00
|
|
|
skipChecks_.push_back(jit_->J_CC(CC_G, true));
|
2014-01-26 11:52:37 -08:00
|
|
|
jit_->js.afterOp |= JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE | JitState::AFTER_MEMCHECK_CLEANUP;
|
2013-03-09 00:09:55 -08:00
|
|
|
}
|
2013-03-08 22:50:08 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-08 23:18:34 -08:00
|
|
|
void Jit::JitSafeMem::MemCheckAsm(ReadType type)
|
2013-03-08 22:50:08 -08:00
|
|
|
{
|
2013-10-27 13:15:12 -07:00
|
|
|
const auto memchecks = CBreakPoints::GetMemCheckRanges();
|
2013-07-05 01:33:39 -07:00
|
|
|
bool possible = false;
|
2013-06-30 15:16:58 -07:00
|
|
|
for (auto it = memchecks.begin(), end = memchecks.end(); it != end; ++it)
|
2013-03-09 00:35:08 -08:00
|
|
|
{
|
2013-06-30 15:16:58 -07:00
|
|
|
if (!(it->cond & MEMCHECK_READ) && type == MEM_READ)
|
2013-07-05 01:25:39 -07:00
|
|
|
continue;
|
2013-06-30 15:16:58 -07:00
|
|
|
if (!(it->cond & MEMCHECK_WRITE) && type == MEM_WRITE)
|
2013-07-05 01:25:39 -07:00
|
|
|
continue;
|
2013-03-09 00:40:33 -08:00
|
|
|
|
2013-07-05 01:33:39 -07:00
|
|
|
possible = true;
|
2013-03-09 00:40:33 -08:00
|
|
|
|
2013-03-09 00:35:08 -08:00
|
|
|
FixupBranch skipNext, skipNextRange;
|
2013-06-30 15:16:58 -07:00
|
|
|
if (it->end != 0)
|
2013-03-09 00:35:08 -08:00
|
|
|
{
|
2013-07-05 01:13:05 -07:00
|
|
|
jit_->CMP(32, R(xaddr_), Imm32(it->start - offset_ - size_));
|
2013-07-06 12:08:34 -07:00
|
|
|
skipNext = jit_->J_CC(CC_BE);
|
2013-07-05 01:13:05 -07:00
|
|
|
jit_->CMP(32, R(xaddr_), Imm32(it->end - offset_));
|
2013-03-09 00:35:08 -08:00
|
|
|
skipNextRange = jit_->J_CC(CC_AE);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-30 15:16:58 -07:00
|
|
|
jit_->CMP(32, R(xaddr_), Imm32(it->start - offset_));
|
2013-03-09 00:35:08 -08:00
|
|
|
skipNext = jit_->J_CC(CC_NE);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 00:22:09 -07:00
|
|
|
// Keep the stack 16-byte aligned, just PUSH/POP 4 times.
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
|
jit_->PUSH(xaddr_);
|
2013-03-09 00:35:08 -08:00
|
|
|
jit_->MOV(32, M(&jit_->mips_->pc), Imm32(jit_->js.compilerPC));
|
2013-03-09 09:01:23 -08:00
|
|
|
jit_->ADD(32, R(xaddr_), Imm32(offset_));
|
2014-01-18 09:57:13 -08:00
|
|
|
jit_->CallProtectedFunction(&JitMemCheck, R(xaddr_), size_, type == MEM_WRITE ? 1 : 0);
|
2013-07-06 00:22:09 -07:00
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
|
jit_->POP(xaddr_);
|
2013-03-09 00:35:08 -08:00
|
|
|
|
|
|
|
|
jit_->SetJumpTarget(skipNext);
|
2013-06-30 15:16:58 -07:00
|
|
|
if (it->end != 0)
|
2013-03-09 00:35:08 -08:00
|
|
|
jit_->SetJumpTarget(skipNextRange);
|
|
|
|
|
}
|
2013-07-05 01:33:39 -07:00
|
|
|
|
|
|
|
|
if (possible)
|
|
|
|
|
{
|
2013-07-27 13:26:43 -07:00
|
|
|
// CORE_RUNNING is <= CORE_NEXTFRAME.
|
2014-01-18 09:57:13 -08:00
|
|
|
jit_->CMP(32, M(&coreState), Imm32(CORE_NEXTFRAME));
|
2013-07-27 13:26:43 -07:00
|
|
|
skipChecks_.push_back(jit_->J_CC(CC_G, true));
|
2014-01-26 11:52:37 -08:00
|
|
|
jit_->js.afterOp |= JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE | JitState::AFTER_MEMCHECK_CLEANUP;
|
2013-07-05 01:33:39 -07:00
|
|
|
}
|
2013-03-08 22:50:08 -08:00
|
|
|
}
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
void Jit::CallProtectedFunction(const void *func, const OpArg &arg1)
|
2013-07-06 00:54:53 -07:00
|
|
|
{
|
|
|
|
|
// We don't regcache RCX, so the below is safe (and also faster, maybe branch prediction?)
|
|
|
|
|
ABI_CallFunctionA(thunks.ProtectFunction(func, 1), arg1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
void Jit::CallProtectedFunction(const void *func, const OpArg &arg1, const OpArg &arg2)
|
2013-07-06 00:54:53 -07:00
|
|
|
{
|
|
|
|
|
// We don't regcache RCX/RDX, so the below is safe (and also faster, maybe branch prediction?)
|
|
|
|
|
ABI_CallFunctionAA(thunks.ProtectFunction(func, 2), arg1, arg2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
void Jit::CallProtectedFunction(const void *func, const u32 arg1, const u32 arg2, const u32 arg3)
|
2013-07-06 00:54:53 -07:00
|
|
|
{
|
|
|
|
|
// On x64, we need to save R8, which is caller saved.
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunction(thunks.GetSaveRegsFunction());
|
2013-07-06 00:54:53 -07:00
|
|
|
ABI_CallFunctionCCC(func, arg1, arg2, arg3);
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunction(thunks.GetLoadRegsFunction());
|
2013-07-06 00:54:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-01-18 09:57:13 -08:00
|
|
|
void Jit::CallProtectedFunction(const void *func, const OpArg &arg1, const u32 arg2, const u32 arg3)
|
2013-07-06 00:54:53 -07:00
|
|
|
{
|
|
|
|
|
// On x64, we need to save R8, which is caller saved.
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunction(thunks.GetSaveRegsFunction());
|
2013-07-06 00:54:53 -07:00
|
|
|
ABI_CallFunctionACC(func, arg1, arg2, arg3);
|
2014-01-18 09:57:13 -08:00
|
|
|
ABI_CallFunction(thunks.GetLoadRegsFunction());
|
2013-07-06 00:54:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-08-24 14:43:49 -07:00
|
|
|
void Jit::Comp_DoNothing(MIPSOpcode op) { }
|
2013-02-10 12:14:55 +01:00
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
} // namespace
|