2019-06-21 23:28:32 +00:00
|
|
|
#ifndef ARMJIT_COMPILER_H
|
|
|
|
#define ARMJIT_COMPILER_H
|
|
|
|
|
|
|
|
#include "../dolphin/x64Emitter.h"
|
|
|
|
|
|
|
|
#include "../ARMJIT.h"
|
2019-10-02 23:10:59 +00:00
|
|
|
#include "../ARMJIT_Internal.h"
|
2019-07-09 22:57:59 +00:00
|
|
|
#include "../ARMJIT_RegisterCache.h"
|
2019-06-21 23:28:32 +00:00
|
|
|
|
|
|
|
namespace ARMJIT
|
|
|
|
{
|
|
|
|
|
|
|
|
const Gen::X64Reg RCPU = Gen::RBP;
|
|
|
|
const Gen::X64Reg RCPSR = Gen::R15;
|
|
|
|
|
|
|
|
const Gen::X64Reg RSCRATCH = Gen::EAX;
|
|
|
|
const Gen::X64Reg RSCRATCH2 = Gen::EDX;
|
|
|
|
const Gen::X64Reg RSCRATCH3 = Gen::ECX;
|
2020-04-26 18:47:36 +00:00
|
|
|
const Gen::X64Reg RSCRATCH4 = Gen::R8;
|
2019-06-21 23:28:32 +00:00
|
|
|
|
2019-10-02 23:10:59 +00:00
|
|
|
struct ComplexOperand
|
|
|
|
{
|
|
|
|
ComplexOperand()
|
|
|
|
{}
|
|
|
|
|
|
|
|
ComplexOperand(u32 imm)
|
|
|
|
: IsImm(true), Imm(imm)
|
|
|
|
{}
|
|
|
|
ComplexOperand(int reg, int op, int amount)
|
|
|
|
: IsImm(false)
|
|
|
|
{
|
|
|
|
Reg.Reg = reg;
|
|
|
|
Reg.Op = op;
|
|
|
|
Reg.Amount = amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsImm;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int Reg, Op, Amount;
|
|
|
|
} Reg;
|
|
|
|
u32 Imm;
|
|
|
|
};
|
|
|
|
};
|
2019-06-25 15:09:27 +00:00
|
|
|
|
2019-08-16 21:17:08 +00:00
|
|
|
class Compiler : public Gen::XEmitter
|
2019-06-21 23:28:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Compiler();
|
|
|
|
|
2019-07-14 02:33:36 +00:00
|
|
|
void Reset();
|
|
|
|
|
2020-04-25 11:40:51 +00:00
|
|
|
void LinkBlock(u32 offset, JitBlockEntry entry);
|
|
|
|
void UnlinkBlock(u32 offset);
|
|
|
|
|
|
|
|
JitBlockEntry CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount);
|
2019-06-21 23:28:32 +00:00
|
|
|
|
2019-06-25 15:09:27 +00:00
|
|
|
void LoadReg(int reg, Gen::X64Reg nativeReg);
|
2019-06-30 11:35:03 +00:00
|
|
|
void SaveReg(int reg, Gen::X64Reg nativeReg);
|
2019-06-21 23:28:32 +00:00
|
|
|
|
2019-08-25 10:28:48 +00:00
|
|
|
bool CanCompile(bool thumb, u16 kind);
|
|
|
|
|
2019-07-14 00:37:32 +00:00
|
|
|
typedef void (Compiler::*CompileFunc)();
|
2019-06-25 15:09:27 +00:00
|
|
|
|
2019-07-05 23:48:42 +00:00
|
|
|
void Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR = false);
|
2019-07-11 14:22:47 +00:00
|
|
|
void Comp_JumpTo(u32 addr, bool forceNonConstantCycles = false);
|
2019-07-05 23:48:42 +00:00
|
|
|
|
2019-07-11 14:22:47 +00:00
|
|
|
void Comp_AddCycles_C(bool forceNonConstant = false);
|
2019-06-25 15:09:27 +00:00
|
|
|
void Comp_AddCycles_CI(u32 i);
|
2019-07-12 01:43:45 +00:00
|
|
|
void Comp_AddCycles_CI(Gen::X64Reg i, int add);
|
2019-10-02 23:10:59 +00:00
|
|
|
void Comp_AddCycles_CDI();
|
|
|
|
void Comp_AddCycles_CD();
|
2019-06-25 15:09:27 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
opSetsFlags = 1 << 0,
|
|
|
|
opSymmetric = 1 << 1,
|
|
|
|
opRetriveCV = 1 << 2,
|
|
|
|
opInvertCarry = 1 << 3,
|
|
|
|
opSyncCarry = 1 << 4,
|
|
|
|
opInvertOp2 = 1 << 5,
|
|
|
|
};
|
|
|
|
|
2020-02-04 16:28:51 +00:00
|
|
|
void Nop() {}
|
|
|
|
|
2019-06-25 15:09:27 +00:00
|
|
|
void A_Comp_Arith();
|
|
|
|
void A_Comp_MovOp();
|
|
|
|
void A_Comp_CmpOp();
|
2019-06-21 23:28:32 +00:00
|
|
|
|
2019-07-12 01:43:45 +00:00
|
|
|
void A_Comp_MUL_MLA();
|
2020-04-25 12:42:37 +00:00
|
|
|
void A_Comp_Mul_Long();
|
2019-07-12 01:43:45 +00:00
|
|
|
|
|
|
|
void A_Comp_CLZ();
|
|
|
|
|
2019-06-30 11:35:03 +00:00
|
|
|
void A_Comp_MemWB();
|
2019-07-05 23:48:42 +00:00
|
|
|
void A_Comp_MemHalf();
|
2019-07-09 22:57:59 +00:00
|
|
|
void A_Comp_LDM_STM();
|
2019-06-30 11:35:03 +00:00
|
|
|
|
2019-07-11 14:22:47 +00:00
|
|
|
void A_Comp_BranchImm();
|
|
|
|
void A_Comp_BranchXchangeReg();
|
|
|
|
|
2020-04-25 17:35:40 +00:00
|
|
|
void A_Comp_MRS();
|
|
|
|
void A_Comp_MSR();
|
|
|
|
|
2019-06-25 15:09:27 +00:00
|
|
|
void T_Comp_ShiftImm();
|
|
|
|
void T_Comp_AddSub_();
|
|
|
|
void T_Comp_ALU_Imm8();
|
|
|
|
void T_Comp_ALU();
|
|
|
|
void T_Comp_ALU_HiReg();
|
2019-07-12 01:43:45 +00:00
|
|
|
void T_Comp_MUL();
|
2019-06-21 23:28:32 +00:00
|
|
|
|
2019-07-05 23:48:42 +00:00
|
|
|
void T_Comp_RelAddr();
|
|
|
|
void T_Comp_AddSP();
|
|
|
|
|
2019-06-30 11:35:03 +00:00
|
|
|
void T_Comp_MemReg();
|
|
|
|
void T_Comp_MemImm();
|
2019-07-05 23:48:42 +00:00
|
|
|
void T_Comp_MemRegHalf();
|
|
|
|
void T_Comp_MemImmHalf();
|
2019-07-09 22:57:59 +00:00
|
|
|
void T_Comp_LoadPCRel();
|
|
|
|
void T_Comp_MemSPRel();
|
|
|
|
void T_Comp_PUSH_POP();
|
|
|
|
void T_Comp_LDMIA_STMIA();
|
2019-07-05 23:48:42 +00:00
|
|
|
|
2019-07-11 14:22:47 +00:00
|
|
|
void T_Comp_BCOND();
|
|
|
|
void T_Comp_B();
|
|
|
|
void T_Comp_BranchXchangeReg();
|
|
|
|
void T_Comp_BL_LONG_1();
|
|
|
|
void T_Comp_BL_LONG_2();
|
2019-09-08 12:48:20 +00:00
|
|
|
void T_Comp_BL_Merged();
|
2019-07-11 14:22:47 +00:00
|
|
|
|
2019-10-02 23:10:59 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
memop_Writeback = 1 << 0,
|
|
|
|
memop_Post = 1 << 1,
|
|
|
|
memop_SignExtend = 1 << 2,
|
|
|
|
memop_Store = 1 << 3,
|
|
|
|
memop_SubtractOffset = 1 << 4
|
|
|
|
};
|
|
|
|
void Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int size, int flags);
|
2019-07-12 01:43:45 +00:00
|
|
|
s32 Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode);
|
2020-05-08 22:45:05 +00:00
|
|
|
bool Comp_MemLoadLiteral(int size, int rd, u32 addr);
|
2019-06-30 11:35:03 +00:00
|
|
|
|
2019-06-25 15:09:27 +00:00
|
|
|
void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&),
|
|
|
|
Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags);
|
|
|
|
void Comp_ArithTriOpReverse(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&),
|
|
|
|
Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags);
|
|
|
|
void Comp_CmpOp(int op, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed);
|
|
|
|
|
2019-07-12 01:43:45 +00:00
|
|
|
void Comp_MulOp(bool S, bool add, Gen::OpArg rd, Gen::OpArg rm, Gen::OpArg rs, Gen::OpArg rn);
|
|
|
|
|
2019-06-25 15:09:27 +00:00
|
|
|
void Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed);
|
|
|
|
|
2020-04-25 11:40:51 +00:00
|
|
|
void Comp_SpecialBranchBehaviour(bool taken);
|
2019-10-02 23:10:59 +00:00
|
|
|
|
2019-07-09 22:57:59 +00:00
|
|
|
|
2019-06-25 15:09:27 +00:00
|
|
|
Gen::OpArg Comp_RegShiftImm(int op, int amount, Gen::OpArg rm, bool S, bool& carryUsed);
|
|
|
|
Gen::OpArg Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed);
|
|
|
|
|
|
|
|
Gen::OpArg A_Comp_GetALUOp2(bool S, bool& carryUsed);
|
2019-06-21 23:28:32 +00:00
|
|
|
|
|
|
|
void LoadCPSR();
|
2019-10-02 23:10:59 +00:00
|
|
|
void SaveCPSR(bool flagClean = true);
|
2019-06-21 23:28:32 +00:00
|
|
|
|
2019-08-25 10:28:48 +00:00
|
|
|
bool FlagsNZRequired()
|
|
|
|
{ return CurInstr.SetFlags & 0xC; }
|
|
|
|
|
2019-07-11 14:22:47 +00:00
|
|
|
Gen::FixupBranch CheckCondition(u32 cond);
|
|
|
|
|
2019-06-25 15:09:27 +00:00
|
|
|
Gen::OpArg MapReg(int reg)
|
|
|
|
{
|
|
|
|
if (reg == 15 && RegCache.Mapping[reg] == Gen::INVALID_REG)
|
|
|
|
return Gen::Imm32(R15);
|
|
|
|
|
|
|
|
assert(RegCache.Mapping[reg] != Gen::INVALID_REG);
|
|
|
|
return Gen::R(RegCache.Mapping[reg]);
|
|
|
|
}
|
|
|
|
|
2020-04-25 11:40:51 +00:00
|
|
|
JitBlockEntry AddEntryOffset(u32 offset)
|
|
|
|
{
|
|
|
|
return (JitBlockEntry)(ResetStart + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 SubEntryOffset(JitBlockEntry entry)
|
|
|
|
{
|
|
|
|
return (u8*)entry - ResetStart;
|
|
|
|
}
|
|
|
|
|
2020-05-08 22:45:05 +00:00
|
|
|
void SwitchToNearCode()
|
|
|
|
{
|
|
|
|
FarCode = GetWritableCodePtr();
|
|
|
|
SetCodePtr(NearCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchToFarCode()
|
|
|
|
{
|
|
|
|
NearCode = GetWritableCodePtr();
|
|
|
|
SetCodePtr(FarCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8* FarCode;
|
|
|
|
u8* NearCode;
|
|
|
|
u32 FarSize;
|
|
|
|
u32 NearSize;
|
|
|
|
|
|
|
|
u8* NearStart;
|
|
|
|
u8* FarStart;
|
|
|
|
|
2019-08-16 21:17:08 +00:00
|
|
|
u8* ResetStart;
|
|
|
|
u32 CodeMemSize;
|
|
|
|
|
2019-10-02 23:10:59 +00:00
|
|
|
bool Exit;
|
2019-09-08 12:09:00 +00:00
|
|
|
bool IrregularCycles;
|
|
|
|
|
2020-04-25 11:40:51 +00:00
|
|
|
void* BranchStub[2];
|
|
|
|
|
2019-07-12 01:43:45 +00:00
|
|
|
void* ReadBanked;
|
|
|
|
void* WriteBanked;
|
|
|
|
|
2019-06-21 23:28:32 +00:00
|
|
|
bool CPSRDirty = false;
|
|
|
|
|
2019-07-05 23:48:42 +00:00
|
|
|
FetchedInstr CurInstr;
|
2019-06-21 23:28:32 +00:00
|
|
|
|
2019-07-09 22:57:59 +00:00
|
|
|
RegisterCache<Compiler, Gen::X64Reg> RegCache;
|
2019-06-25 15:09:27 +00:00
|
|
|
|
2019-06-21 23:28:32 +00:00
|
|
|
bool Thumb;
|
|
|
|
u32 Num;
|
|
|
|
u32 R15;
|
2019-06-30 11:35:03 +00:00
|
|
|
u32 CodeRegion;
|
2019-06-21 23:28:32 +00:00
|
|
|
|
|
|
|
u32 ConstantCycles;
|
|
|
|
|
2019-07-05 23:48:42 +00:00
|
|
|
ARM* CurCPU;
|
|
|
|
};
|
2019-06-30 11:35:03 +00:00
|
|
|
|
2019-06-21 23:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|