2012-11-01 15:19:01 +00: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 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00: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/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../../Globals.h"
|
|
|
|
|
2013-01-07 21:33:09 +00:00
|
|
|
#include "ArmJitCache.h"
|
|
|
|
#include "ArmRegCache.h"
|
2013-01-17 01:00:07 +00:00
|
|
|
#include "ArmAsm.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
namespace MIPSComp
|
|
|
|
{
|
|
|
|
|
2013-01-07 21:33:09 +00:00
|
|
|
struct ArmJitOptions
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-01-07 21:33:09 +00:00
|
|
|
ArmJitOptions()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-01-11 23:44:18 +00:00
|
|
|
enableBlocklink = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool enableBlocklink;
|
|
|
|
};
|
|
|
|
|
2013-01-07 21:33:09 +00:00
|
|
|
struct ArmJitState
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
u32 compilerPC;
|
|
|
|
u32 blockStart;
|
|
|
|
bool cancel;
|
|
|
|
bool inDelaySlot;
|
|
|
|
int downcountAmount;
|
|
|
|
bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block
|
2013-01-07 21:33:09 +00:00
|
|
|
ArmJitBlock *curBlock;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Jit : public ArmGen::ARMXCodeBlock
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Jit(MIPSState *mips);
|
|
|
|
|
|
|
|
// Compiled ops should ignore delay slots
|
|
|
|
// the compiler will take care of them by itself
|
|
|
|
// OR NOT
|
|
|
|
void Comp_Generic(u32 op);
|
|
|
|
|
|
|
|
void RunLoopUntil(u64 globalticks);
|
|
|
|
|
|
|
|
void Compile(u32 em_address); // Compiles a block at current MIPS PC
|
2013-01-07 21:33:09 +00:00
|
|
|
const u8 *DoJit(u32 em_address, ArmJitBlock *b);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
void CompileAt(u32 addr);
|
|
|
|
void Comp_RunBlock(u32 op);
|
|
|
|
|
|
|
|
// Ops
|
|
|
|
void Comp_ITypeMem(u32 op);
|
|
|
|
|
|
|
|
void Comp_RelBranch(u32 op);
|
|
|
|
void Comp_RelBranchRI(u32 op);
|
|
|
|
void Comp_FPUBranch(u32 op);
|
|
|
|
void Comp_FPULS(u32 op);
|
|
|
|
void Comp_Jump(u32 op);
|
|
|
|
void Comp_JumpReg(u32 op);
|
|
|
|
void Comp_Syscall(u32 op);
|
|
|
|
|
|
|
|
void Comp_IType(u32 op);
|
|
|
|
void Comp_RType3(u32 op);
|
|
|
|
void Comp_ShiftType(u32 op);
|
|
|
|
void Comp_Allegrex(u32 op);
|
|
|
|
void Comp_VBranch(u32 op);
|
|
|
|
|
|
|
|
void Comp_FPU3op(u32 op);
|
|
|
|
void Comp_FPU2op(u32 op);
|
|
|
|
void Comp_mxc1(u32 op);
|
|
|
|
|
2013-01-07 21:33:09 +00:00
|
|
|
ArmJitBlockCache *GetBlockCache() { return &blocks; }
|
2012-12-28 23:09:17 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void ClearCache();
|
2013-01-18 18:43:40 +00:00
|
|
|
void ClearCacheAt(u32 em_address);
|
2012-12-28 23:09:17 +00:00
|
|
|
|
|
|
|
private:
|
2013-01-11 00:59:26 +00:00
|
|
|
void GenerateFixedCode();
|
2012-11-01 15:19:01 +00:00
|
|
|
void FlushAll();
|
|
|
|
|
2013-01-11 00:59:26 +00:00
|
|
|
// TODO: Split into two parts, the first part can be shared in branches.
|
2012-11-23 18:41:35 +00:00
|
|
|
void DoDownCount();
|
2013-01-08 12:49:52 +00:00
|
|
|
void MovFromPC(ARMReg r);
|
|
|
|
void MovToPC(ARMReg r);
|
2012-11-23 18:41:35 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void WriteExit(u32 destination, int exit_num);
|
2012-11-23 18:41:35 +00:00
|
|
|
void WriteExitDestInR(ARMReg Reg);
|
2012-11-01 15:19:01 +00:00
|
|
|
void WriteSyscallExit();
|
|
|
|
|
|
|
|
// Utility compilation functions
|
2012-11-23 18:41:35 +00:00
|
|
|
void BranchFPFlag(u32 op, ArmGen::CCFlags cc, bool likely);
|
2013-01-07 23:26:42 +00:00
|
|
|
void BranchVFPUFlag(u32 op, ArmGen::CCFlags cc, bool likely);
|
2013-01-22 16:04:01 +00:00
|
|
|
void BranchRSZeroComp(u32 op, ArmGen::CCFlags cc, bool andLink, bool likely);
|
2012-11-23 18:41:35 +00:00
|
|
|
void BranchRSRTComp(u32 op, ArmGen::CCFlags cc, bool likely);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// Utilities to reduce duplicated code
|
2013-01-09 10:20:48 +00:00
|
|
|
void CompImmLogic(int rs, int rt, u32 uimm, void (ARMXEmitter::*arith)(ARMReg dst, ARMReg src, Operand2 op2), u32 (*eval)(u32 a, u32 b));
|
2013-01-10 00:08:24 +00:00
|
|
|
void CompShiftImm(u32 op, ArmGen::ShiftType shiftType);
|
|
|
|
/*
|
2012-11-01 15:19:01 +00:00
|
|
|
void CompImmLogic(u32 op, void (ARMXEmitter::*arith)(int, const OpArg &, const OpArg &));
|
|
|
|
void CompTriArith(u32 op, void (ARMXEmitter::*arith)(int, const OpArg &, const OpArg &));
|
|
|
|
void CompShiftImm(u32 op, void (ARMXEmitter::*shift)(int, OpArg, OpArg));
|
|
|
|
void CompShiftVar(u32 op, void (XEmitter::*shift)(int, OpArg, OpArg));
|
|
|
|
|
|
|
|
void CompFPTriArith(u32 op, void (XEmitter::*arith)(X64Reg reg, OpArg), bool orderMatters);
|
|
|
|
*/
|
|
|
|
|
2013-01-07 21:33:09 +00:00
|
|
|
ArmJitBlockCache blocks;
|
|
|
|
ArmJitOptions jo;
|
|
|
|
ArmJitState js;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-23 18:41:35 +00:00
|
|
|
ArmRegCache gpr;
|
|
|
|
// FPURegCache fpr;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
MIPSState *mips_;
|
2013-01-11 00:59:26 +00:00
|
|
|
|
2013-01-11 23:44:18 +00:00
|
|
|
public:
|
2013-01-11 00:59:26 +00:00
|
|
|
// Code pointers
|
|
|
|
const u8 *enterCode;
|
|
|
|
|
|
|
|
const u8 *outerLoop;
|
|
|
|
const u8 *dispatcherCheckCoreState;
|
|
|
|
const u8 *dispatcher;
|
|
|
|
const u8 *dispatcherNoCheck;
|
|
|
|
|
|
|
|
const u8 *breakpointBailout;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (Jit::*MIPSCompileFunc)(u32 opcode);
|
|
|
|
|
|
|
|
} // namespace MIPSComp
|
|
|
|
|