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-11-08 17:51:52 +00:00
|
|
|
#include "Core/MIPS/JitCommon/JitState.h"
|
2013-04-26 21:58:20 +00:00
|
|
|
#include "Core/MIPS/JitCommon/JitBlockCache.h"
|
|
|
|
#include "Core/MIPS/ARM/ArmRegCache.h"
|
|
|
|
#include "Core/MIPS/ARM/ArmRegCacheFPU.h"
|
|
|
|
#include "Core/MIPS/ARM/ArmAsm.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-03-22 07:15:00 +00:00
|
|
|
#if defined(MAEMO)
|
|
|
|
#include "stddef.h"
|
|
|
|
#endif
|
|
|
|
|
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-11-09 11:57:07 +00:00
|
|
|
ArmJitOptions();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
bool enableBlocklink;
|
2013-07-27 15:27:26 +00:00
|
|
|
bool downcountInRegister;
|
2013-11-09 11:57:07 +00:00
|
|
|
bool useBackJump;
|
2013-11-09 12:06:10 +00:00
|
|
|
bool useForwardJump;
|
2013-11-09 16:15:30 +00:00
|
|
|
bool cachePointers;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Jit : public ArmGen::ARMXCodeBlock
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Jit(MIPSState *mips);
|
2013-02-18 09:54:25 +00:00
|
|
|
void DoState(PointerWrap &p);
|
2013-03-08 16:49:21 +00:00
|
|
|
static void DoDummyState(PointerWrap &p);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// Compiled ops should ignore delay slots
|
|
|
|
// the compiler will take care of them by itself
|
|
|
|
// OR NOT
|
2013-08-24 21:43:49 +00:00
|
|
|
void Comp_Generic(MIPSOpcode op);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
void RunLoopUntil(u64 globalticks);
|
|
|
|
|
|
|
|
void Compile(u32 em_address); // Compiles a block at current MIPS PC
|
2013-04-26 21:58:20 +00:00
|
|
|
const u8 *DoJit(u32 em_address, JitBlock *b);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-01-29 23:02:04 +00:00
|
|
|
void CompileDelaySlot(int flags);
|
2012-11-01 15:19:01 +00:00
|
|
|
void CompileAt(u32 addr);
|
2013-08-24 21:43:49 +00:00
|
|
|
void EatInstruction(MIPSOpcode op);
|
|
|
|
void Comp_RunBlock(MIPSOpcode op);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// Ops
|
2013-08-24 21:43:49 +00:00
|
|
|
void Comp_ITypeMem(MIPSOpcode op);
|
|
|
|
|
|
|
|
void Comp_RelBranch(MIPSOpcode op);
|
|
|
|
void Comp_RelBranchRI(MIPSOpcode op);
|
|
|
|
void Comp_FPUBranch(MIPSOpcode op);
|
|
|
|
void Comp_FPULS(MIPSOpcode op);
|
|
|
|
void Comp_FPUComp(MIPSOpcode op);
|
|
|
|
void Comp_Jump(MIPSOpcode op);
|
|
|
|
void Comp_JumpReg(MIPSOpcode op);
|
|
|
|
void Comp_Syscall(MIPSOpcode op);
|
|
|
|
void Comp_Break(MIPSOpcode op);
|
|
|
|
|
|
|
|
void Comp_IType(MIPSOpcode op);
|
|
|
|
void Comp_RType2(MIPSOpcode op);
|
|
|
|
void Comp_RType3(MIPSOpcode op);
|
|
|
|
void Comp_ShiftType(MIPSOpcode op);
|
|
|
|
void Comp_Allegrex(MIPSOpcode op);
|
|
|
|
void Comp_Allegrex2(MIPSOpcode op);
|
|
|
|
void Comp_VBranch(MIPSOpcode op);
|
|
|
|
void Comp_MulDivType(MIPSOpcode op);
|
|
|
|
void Comp_Special3(MIPSOpcode op);
|
|
|
|
|
|
|
|
void Comp_FPU3op(MIPSOpcode op);
|
|
|
|
void Comp_FPU2op(MIPSOpcode op);
|
|
|
|
void Comp_mxc1(MIPSOpcode op);
|
|
|
|
|
|
|
|
void Comp_DoNothing(MIPSOpcode op);
|
|
|
|
|
|
|
|
void Comp_SV(MIPSOpcode op);
|
|
|
|
void Comp_SVQ(MIPSOpcode op);
|
|
|
|
void Comp_VPFX(MIPSOpcode op);
|
|
|
|
void Comp_VVectorInit(MIPSOpcode op);
|
|
|
|
void Comp_VMatrixInit(MIPSOpcode op);
|
|
|
|
void Comp_VDot(MIPSOpcode op);
|
|
|
|
void Comp_VecDo3(MIPSOpcode op);
|
|
|
|
void Comp_VV2Op(MIPSOpcode op);
|
|
|
|
void Comp_Mftv(MIPSOpcode op);
|
|
|
|
void Comp_Vmtvc(MIPSOpcode op);
|
|
|
|
void Comp_Vmmov(MIPSOpcode op);
|
|
|
|
void Comp_VScl(MIPSOpcode op);
|
|
|
|
void Comp_Vmmul(MIPSOpcode op);
|
|
|
|
void Comp_Vmscl(MIPSOpcode op);
|
|
|
|
void Comp_Vtfm(MIPSOpcode op);
|
|
|
|
void Comp_VHdp(MIPSOpcode op);
|
|
|
|
void Comp_VCrs(MIPSOpcode op);
|
|
|
|
void Comp_VDet(MIPSOpcode op);
|
|
|
|
void Comp_Vi2x(MIPSOpcode op);
|
|
|
|
void Comp_Vx2i(MIPSOpcode op);
|
|
|
|
void Comp_Vf2i(MIPSOpcode op);
|
|
|
|
void Comp_Vi2f(MIPSOpcode op);
|
2013-09-28 10:30:28 +00:00
|
|
|
void Comp_Vh2f(MIPSOpcode op);
|
2013-08-24 21:43:49 +00:00
|
|
|
void Comp_Vcst(MIPSOpcode op);
|
|
|
|
void Comp_Vhoriz(MIPSOpcode op);
|
|
|
|
void Comp_VRot(MIPSOpcode op);
|
|
|
|
void Comp_VIdt(MIPSOpcode op);
|
|
|
|
void Comp_Vcmp(MIPSOpcode op);
|
|
|
|
void Comp_Vcmov(MIPSOpcode op);
|
|
|
|
void Comp_Viim(MIPSOpcode op);
|
|
|
|
void Comp_Vfim(MIPSOpcode op);
|
|
|
|
void Comp_VCrossQuat(MIPSOpcode op);
|
|
|
|
void Comp_Vsge(MIPSOpcode op);
|
|
|
|
void Comp_Vslt(MIPSOpcode op);
|
2013-11-07 13:34:08 +00:00
|
|
|
void Comp_Vsgn(MIPSOpcode op);
|
2013-02-19 23:03:47 +00:00
|
|
|
|
2013-04-26 21:58:20 +00:00
|
|
|
JitBlockCache *GetBlockCache() { return &blocks; }
|
2012-12-28 23:09:17 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void ClearCache();
|
2013-09-01 07:21:41 +00:00
|
|
|
void ClearCacheAt(u32 em_address, int length = 4);
|
2012-12-28 23:09:17 +00:00
|
|
|
|
2013-07-30 16:15:48 +00:00
|
|
|
void EatPrefix() { js.EatPrefix(); }
|
2013-02-17 23:50:31 +00:00
|
|
|
|
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-02-15 21:38:28 +00:00
|
|
|
void FlushPrefixV();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-01-29 23:02:04 +00:00
|
|
|
void WriteDownCount(int offset = 0);
|
2013-01-08 12:49:52 +00:00
|
|
|
void MovFromPC(ARMReg r);
|
|
|
|
void MovToPC(ARMReg r);
|
2012-11-23 18:41:35 +00:00
|
|
|
|
2013-07-27 15:27:26 +00:00
|
|
|
void SaveDowncount();
|
|
|
|
void RestoreDowncount();
|
|
|
|
|
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
|
2013-08-24 21:43:49 +00:00
|
|
|
void BranchFPFlag(MIPSOpcode op, ArmGen::CCFlags cc, bool likely);
|
|
|
|
void BranchVFPUFlag(MIPSOpcode op, ArmGen::CCFlags cc, bool likely);
|
|
|
|
void BranchRSZeroComp(MIPSOpcode op, ArmGen::CCFlags cc, bool andLink, bool likely);
|
|
|
|
void BranchRSRTComp(MIPSOpcode 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-11-08 18:30:42 +00:00
|
|
|
void CompType3(int rd, int rs, int rt, void (ARMXEmitter::*arithOp2)(ARMReg dst, ARMReg rm, Operand2 rn), u32 (*eval)(u32 a, u32 b), bool symmetric = false, bool useMOV = false);
|
2013-03-09 23:48:44 +00:00
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
void CompShiftImm(MIPSOpcode op, ArmGen::ShiftType shiftType);
|
|
|
|
void CompShiftVar(MIPSOpcode op, ArmGen::ShiftType shiftType);
|
2013-01-29 23:02:04 +00:00
|
|
|
|
2013-02-19 23:03:47 +00:00
|
|
|
void ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz);
|
|
|
|
void ApplyPrefixD(const u8 *vregs, VectorSize sz);
|
|
|
|
void GetVectorRegsPrefixS(u8 *regs, VectorSize sz, int vectorReg) {
|
2013-03-02 19:19:14 +00:00
|
|
|
_assert_(js.prefixSFlag & ArmJitState::PREFIX_KNOWN);
|
2013-02-19 23:03:47 +00:00
|
|
|
GetVectorRegs(regs, sz, vectorReg);
|
|
|
|
ApplyPrefixST(regs, js.prefixS, sz);
|
|
|
|
}
|
|
|
|
void GetVectorRegsPrefixT(u8 *regs, VectorSize sz, int vectorReg) {
|
2013-03-02 19:19:14 +00:00
|
|
|
_assert_(js.prefixTFlag & ArmJitState::PREFIX_KNOWN);
|
2013-02-19 23:03:47 +00:00
|
|
|
GetVectorRegs(regs, sz, vectorReg);
|
|
|
|
ApplyPrefixST(regs, js.prefixT, sz);
|
|
|
|
}
|
|
|
|
void GetVectorRegsPrefixD(u8 *regs, VectorSize sz, int vectorReg);
|
|
|
|
|
2013-01-25 18:50:30 +00:00
|
|
|
// Utils
|
|
|
|
void SetR0ToEffectiveAddress(int rs, s16 offset);
|
2013-03-16 21:22:58 +00:00
|
|
|
void SetCCAndR0ForSafeAddress(int rs, s16 offset, ARMReg tempReg);
|
2013-01-25 18:50:30 +00:00
|
|
|
|
2013-04-26 21:58:20 +00:00
|
|
|
JitBlockCache blocks;
|
2013-01-07 21:33:09 +00:00
|
|
|
ArmJitOptions jo;
|
2013-11-08 17:51:52 +00:00
|
|
|
JitState js;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-23 18:41:35 +00:00
|
|
|
ArmRegCache gpr;
|
2013-02-10 14:53:56 +00:00
|
|
|
ArmRegCacheFPU fpr;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
MIPSState *mips_;
|
2013-01-11 00:59:26 +00:00
|
|
|
|
2013-07-30 20:25:08 +00:00
|
|
|
int dontLogBlocks;
|
|
|
|
int logBlocks;
|
|
|
|
|
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;
|
2013-02-13 23:02:09 +00:00
|
|
|
const u8 *outerLoopPCInR0;
|
2013-01-11 00:59:26 +00:00
|
|
|
const u8 *dispatcherCheckCoreState;
|
2013-02-15 22:33:35 +00:00
|
|
|
const u8 *dispatcherPCInR0;
|
2013-01-11 00:59:26 +00:00
|
|
|
const u8 *dispatcher;
|
|
|
|
const u8 *dispatcherNoCheck;
|
|
|
|
|
|
|
|
const u8 *breakpointBailout;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
2013-08-24 21:43:49 +00:00
|
|
|
typedef void (Jit::*MIPSCompileFunc)(MIPSOpcode opcode);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
} // namespace MIPSComp
|
|
|
|
|