CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MIPS/JitCommon/JitCommon.h
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <mutex>
21
#include <string>
22
#include <vector>
23
24
#include "Common/CommonTypes.h"
25
#include "Core/MIPS/MIPS.h"
26
27
// TODO: Find a better place for these.
28
std::vector<std::string> DisassembleArm2(const u8 *data, int size);
29
std::vector<std::string> DisassembleArm64(const u8 *data, int size);
30
std::vector<std::string> DisassembleX86(const u8 *data, int size);
31
std::vector<std::string> DisassembleRV64(const u8 *data, int size);
32
33
struct JitBlock;
34
class JitBlockCache;
35
class JitBlockCacheDebugInterface;
36
class PointerWrap;
37
38
#ifdef USING_QT_UI
39
#undef emit
40
#endif
41
42
class MIPSState;
43
44
namespace MIPSComp {
45
void JitAt();
46
47
class MIPSFrontendInterface {
48
public:
49
virtual ~MIPSFrontendInterface() {}
50
51
virtual void EatPrefix() = 0;
52
53
virtual void Comp_Generic(MIPSOpcode op) = 0;
54
virtual void Comp_RunBlock(MIPSOpcode op) = 0;
55
virtual void Comp_ReplacementFunc(MIPSOpcode op) = 0;
56
virtual void Comp_ITypeMem(MIPSOpcode op) = 0;
57
virtual void Comp_StoreSync(MIPSOpcode op) = 0;
58
virtual void Comp_Cache(MIPSOpcode op) = 0;
59
virtual void Comp_RelBranch(MIPSOpcode op) = 0;
60
virtual void Comp_RelBranchRI(MIPSOpcode op) = 0;
61
virtual void Comp_FPUBranch(MIPSOpcode op) = 0;
62
virtual void Comp_FPULS(MIPSOpcode op) = 0;
63
virtual void Comp_FPUComp(MIPSOpcode op) = 0;
64
virtual void Comp_Jump(MIPSOpcode op) = 0;
65
virtual void Comp_JumpReg(MIPSOpcode op) = 0;
66
virtual void Comp_Syscall(MIPSOpcode op) = 0;
67
virtual void Comp_Break(MIPSOpcode op) = 0;
68
virtual void Comp_IType(MIPSOpcode op) = 0;
69
virtual void Comp_RType2(MIPSOpcode op) = 0;
70
virtual void Comp_RType3(MIPSOpcode op) = 0;
71
virtual void Comp_ShiftType(MIPSOpcode op) = 0;
72
virtual void Comp_Allegrex(MIPSOpcode op) = 0;
73
virtual void Comp_Allegrex2(MIPSOpcode op) = 0;
74
virtual void Comp_VBranch(MIPSOpcode op) = 0;
75
virtual void Comp_MulDivType(MIPSOpcode op) = 0;
76
virtual void Comp_Special3(MIPSOpcode op) = 0;
77
virtual void Comp_FPU3op(MIPSOpcode op) = 0;
78
virtual void Comp_FPU2op(MIPSOpcode op) = 0;
79
virtual void Comp_mxc1(MIPSOpcode op) = 0;
80
virtual void Comp_SV(MIPSOpcode op) = 0;
81
virtual void Comp_SVQ(MIPSOpcode op) = 0;
82
virtual void Comp_VPFX(MIPSOpcode op) = 0;
83
virtual void Comp_VVectorInit(MIPSOpcode op) = 0;
84
virtual void Comp_VMatrixInit(MIPSOpcode op) = 0;
85
virtual void Comp_VDot(MIPSOpcode op) = 0;
86
virtual void Comp_VecDo3(MIPSOpcode op) = 0;
87
virtual void Comp_VV2Op(MIPSOpcode op) = 0;
88
virtual void Comp_Mftv(MIPSOpcode op) = 0;
89
virtual void Comp_Vmfvc(MIPSOpcode op) = 0;
90
virtual void Comp_Vmtvc(MIPSOpcode op) = 0;
91
virtual void Comp_Vmmov(MIPSOpcode op) = 0;
92
virtual void Comp_VScl(MIPSOpcode op) = 0;
93
virtual void Comp_Vmmul(MIPSOpcode op) = 0;
94
virtual void Comp_Vmscl(MIPSOpcode op) = 0;
95
virtual void Comp_Vtfm(MIPSOpcode op) = 0;
96
virtual void Comp_VHdp(MIPSOpcode op) = 0;
97
virtual void Comp_VCrs(MIPSOpcode op) = 0;
98
virtual void Comp_VDet(MIPSOpcode op) = 0;
99
virtual void Comp_Vi2x(MIPSOpcode op) = 0;
100
virtual void Comp_Vx2i(MIPSOpcode op) = 0;
101
virtual void Comp_Vf2i(MIPSOpcode op) = 0;
102
virtual void Comp_Vi2f(MIPSOpcode op) = 0;
103
virtual void Comp_Vh2f(MIPSOpcode op) = 0;
104
virtual void Comp_Vcst(MIPSOpcode op) = 0;
105
virtual void Comp_Vhoriz(MIPSOpcode op) = 0;
106
virtual void Comp_VRot(MIPSOpcode op) = 0;
107
virtual void Comp_VIdt(MIPSOpcode op) = 0;
108
virtual void Comp_Vcmp(MIPSOpcode op) = 0;
109
virtual void Comp_Vcmov(MIPSOpcode op) = 0;
110
virtual void Comp_Viim(MIPSOpcode op) = 0;
111
virtual void Comp_Vfim(MIPSOpcode op) = 0;
112
virtual void Comp_VCrossQuat(MIPSOpcode op) = 0;
113
virtual void Comp_Vsgn(MIPSOpcode op) = 0;
114
virtual void Comp_Vocp(MIPSOpcode op) = 0;
115
virtual void Comp_ColorConv(MIPSOpcode op) = 0;
116
virtual void Comp_Vbfy(MIPSOpcode op) = 0;
117
virtual void Comp_DoNothing(MIPSOpcode op) = 0;
118
119
virtual int Replace_fabsf() = 0;
120
};
121
122
class JitInterface {
123
public:
124
virtual ~JitInterface() {}
125
126
virtual bool CodeInRange(const u8 *ptr) const = 0;
127
virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) = 0;
128
virtual bool IsAtDispatchFetch(const u8 *ptr) const {
129
return false;
130
}
131
virtual const u8 *GetDispatcher() const = 0;
132
virtual const u8 *GetCrashHandler() const = 0;
133
virtual JitBlockCache *GetBlockCache() = 0;
134
virtual JitBlockCacheDebugInterface *GetBlockCacheDebugInterface() = 0;
135
virtual void InvalidateCacheAt(u32 em_address, int length = 4) = 0;
136
virtual void DoState(PointerWrap &p) = 0;
137
virtual void RunLoopUntil(u64 globalticks) = 0;
138
virtual void Compile(u32 em_address) = 0;
139
virtual void CompileFunction(u32 start_address, u32 length) { }
140
virtual void ClearCache() = 0;
141
virtual void UpdateFCR31() = 0;
142
virtual MIPSOpcode GetOriginalOp(MIPSOpcode op) = 0;
143
144
// No jit operations may be run between these calls.
145
// Meant to be used to make memory safe for savestates, memcpy, etc.
146
virtual std::vector<u32> SaveAndClearEmuHackOps() = 0;
147
virtual void RestoreSavedEmuHackOps(std::vector<u32> saved) = 0;
148
149
// Block linking. This may need to work differently for whole-function JITs and stuff
150
// like that.
151
virtual void LinkBlock(u8 *exitPoint, const u8 *entryPoint) = 0;
152
virtual void UnlinkBlock(u8 *checkedEntry, u32 originalAddress) = 0;
153
};
154
155
typedef void (MIPSFrontendInterface::*MIPSCompileFunc)(MIPSOpcode opcode);
156
typedef int (MIPSFrontendInterface::*MIPSReplaceFunc)();
157
158
struct BranchInfo {
159
BranchInfo(u32 pc, MIPSOpcode op, MIPSOpcode delaySlotOp, bool andLink, bool likely);
160
161
u32 compilerPC;
162
MIPSOpcode op;
163
MIPSOpcode delaySlotOp;
164
u64 delaySlotInfo;
165
bool likely;
166
bool andLink;
167
// Update manually if it's not always nice (rs/rt, rs/zero, etc.)
168
bool delaySlotIsNice = true;
169
bool delaySlotIsBranch;
170
};
171
172
// This seems to be the same for all branch types.
173
u32 ResolveNotTakenTarget(const BranchInfo &branchInfo);
174
175
extern JitInterface *jit;
176
extern std::recursive_mutex jitLock;
177
178
void DoDummyJitState(PointerWrap &p);
179
180
JitInterface *CreateNativeJit(MIPSState *mipsState, bool useIR);
181
}
182
183