1 |
william |
31 |
/* PCSX2 - PS2 Emulator for PCs |
2 |
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team |
3 |
|
|
* |
4 |
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms |
5 |
|
|
* of the GNU Lesser General Public License as published by the Free Software Found- |
6 |
|
|
* ation, either version 3 of the License, or (at your option) any later version. |
7 |
|
|
* |
8 |
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
9 |
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
10 |
|
|
* PURPOSE. See the GNU General Public License for more details. |
11 |
|
|
* |
12 |
|
|
* You should have received a copy of the GNU General Public License along with PCSX2. |
13 |
|
|
* If not, see <http://www.gnu.org/licenses/>. |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
#pragma once |
17 |
william |
62 |
|
18 |
william |
31 |
#include "VU.h" |
19 |
|
|
#include "VUops.h" |
20 |
|
|
#include "R5900.h" |
21 |
william |
62 |
|
22 |
william |
280 |
static const uint VU0_MEMSIZE = 0x1000; // 4kb |
23 |
|
|
static const uint VU0_PROGSIZE = 0x1000; // 4kb |
24 |
|
|
static const uint VU1_MEMSIZE = 0x4000; // 16kb |
25 |
|
|
static const uint VU1_PROGSIZE = 0x4000; // 16kb |
26 |
william |
62 |
|
27 |
william |
280 |
static const uint VU0_MEMMASK = VU0_MEMSIZE-1; |
28 |
|
|
static const uint VU0_PROGMASK = VU0_PROGSIZE-1; |
29 |
|
|
static const uint VU1_MEMMASK = VU1_MEMSIZE-1; |
30 |
|
|
static const uint VU1_PROGMASK = VU1_PROGSIZE-1; |
31 |
william |
62 |
|
32 |
william |
31 |
#define vuRunCycles (512*12) // Cycles to run ExecuteBlockJIT() for (called from within recs) |
33 |
|
|
#define vu0RunCycles (512*12) // Cycles to run vu0 for whenever ExecuteBlock() is called |
34 |
|
|
#define vu1RunCycles (3000000) // mVU1 uses this for inf loop detection on dev builds |
35 |
|
|
|
36 |
|
|
// -------------------------------------------------------------------------------------- |
37 |
|
|
// BaseCpuProvider |
38 |
|
|
// -------------------------------------------------------------------------------------- |
39 |
|
|
// |
40 |
|
|
// Design Note: This class is only partial C++ style. It still relies on Alloc and Shutdown |
41 |
|
|
// calls for memory and resource management. This is because the underlying implementations |
42 |
|
|
// of our CPU emulators don't have properly encapsulated objects yet -- if we allocate ram |
43 |
|
|
// in a constructor, it won't get free'd if an exception occurs during object construction. |
44 |
|
|
// Once we've resolved all the 'dangling pointers' and stuff in the recompilers, Alloc |
45 |
|
|
// and Shutdown can be removed in favor of constructor/destructor syntax. |
46 |
|
|
// |
47 |
|
|
class BaseCpuProvider |
48 |
|
|
{ |
49 |
|
|
protected: |
50 |
william |
280 |
// allocation counter for multiple calls to Reserve. Most implementations should utilize |
51 |
|
|
// this variable for sake of robustness. |
52 |
|
|
u32 m_Reserved; |
53 |
william |
31 |
|
54 |
|
|
public: |
55 |
|
|
// this boolean indicates to some generic logging facilities if the VU's registers |
56 |
|
|
// are valid for logging or not. (see DisVU1Micro.cpp, etc) [kinda hacky, might |
57 |
|
|
// be removed in the future] |
58 |
|
|
bool IsInterpreter; |
59 |
|
|
|
60 |
|
|
public: |
61 |
|
|
BaseCpuProvider() |
62 |
|
|
{ |
63 |
william |
280 |
m_Reserved = 0; |
64 |
william |
31 |
} |
65 |
|
|
|
66 |
|
|
virtual ~BaseCpuProvider() throw() |
67 |
|
|
{ |
68 |
william |
280 |
if( m_Reserved != 0 ) |
69 |
|
|
Console.Warning( "Cleanup miscount detected on CPU provider. Count=%d", m_Reserved ); |
70 |
william |
31 |
} |
71 |
|
|
|
72 |
|
|
virtual const char* GetShortName() const=0; |
73 |
|
|
virtual wxString GetLongName() const=0; |
74 |
|
|
|
75 |
william |
280 |
// returns the number of bytes committed to the working caches for this CPU |
76 |
|
|
// provider (typically this refers to recompiled code caches, but could also refer |
77 |
|
|
// to other optional growable allocations). |
78 |
|
|
virtual size_t GetCommittedCache() const |
79 |
|
|
{ |
80 |
|
|
return 0; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
virtual void Reserve()=0; |
84 |
william |
31 |
virtual void Shutdown()=0; |
85 |
|
|
virtual void Reset()=0; |
86 |
|
|
virtual void Execute(u32 cycles)=0; |
87 |
|
|
virtual void ExecuteBlock(bool startUp)=0; |
88 |
|
|
|
89 |
|
|
virtual void Step()=0; |
90 |
|
|
virtual void Clear(u32 Addr, u32 Size)=0; |
91 |
|
|
|
92 |
|
|
// C++ Calling Conventions are unstable, and some compilers don't even allow us to take the |
93 |
|
|
// address of C++ methods. We need to use a wrapper function to invoke the ExecuteBlock from |
94 |
|
|
// recompiled code. |
95 |
|
|
static void __fastcall ExecuteBlockJIT( BaseCpuProvider* cpu ) |
96 |
|
|
{ |
97 |
|
|
cpu->Execute(1024); |
98 |
|
|
} |
99 |
william |
280 |
|
100 |
|
|
// Gets the current cache reserve allocated to this CPU (value returned in megabytes) |
101 |
|
|
virtual uint GetCacheReserve() const=0; |
102 |
|
|
|
103 |
|
|
// Specifies the maximum cache reserve amount for this CPU (value in megabytes). |
104 |
|
|
// CPU providers are allowed to reset their reserves (recompiler resets, etc) if such is |
105 |
|
|
// needed to conform to the new amount requested. |
106 |
|
|
virtual void SetCacheReserve( uint reserveInMegs ) const=0; |
107 |
|
|
|
108 |
william |
31 |
}; |
109 |
|
|
|
110 |
|
|
// -------------------------------------------------------------------------------------- |
111 |
|
|
// BaseVUmicroCPU |
112 |
|
|
// -------------------------------------------------------------------------------------- |
113 |
|
|
// Layer class for possible future implementation (currently is nothing more than a type-safe |
114 |
|
|
// type define). |
115 |
|
|
// |
116 |
|
|
class BaseVUmicroCPU : public BaseCpuProvider { |
117 |
|
|
public: |
118 |
|
|
int m_Idx; |
119 |
|
|
u32 m_lastEEcycles; |
120 |
|
|
|
121 |
|
|
BaseVUmicroCPU() { |
122 |
|
|
m_Idx = 0; |
123 |
|
|
m_lastEEcycles = 0; |
124 |
|
|
} |
125 |
|
|
virtual ~BaseVUmicroCPU() throw() {} |
126 |
|
|
|
127 |
|
|
// Called by the PS2 VM's event manager for every internal vertical sync (occurs at either |
128 |
|
|
// 50hz (pal) or 59.94hz (NTSC). |
129 |
|
|
// |
130 |
|
|
// Exceptions: |
131 |
|
|
// This method is not allowed to throw exceptions, since exceptions may not propagate |
132 |
|
|
// safely from the context of recompiled code stackframes. |
133 |
|
|
// |
134 |
|
|
// Thread Affinity: |
135 |
|
|
// Called from the EEcore thread. No locking is performed, so any necessary locks must |
136 |
|
|
// be implemented by the CPU provider manually. |
137 |
|
|
// |
138 |
|
|
virtual void Vsync() throw() { } |
139 |
|
|
|
140 |
|
|
virtual void Step() { |
141 |
|
|
// Ideally this would fall back on interpretation for executing single instructions |
142 |
|
|
// for all CPU types, but due to VU complexities and large discrepancies between |
143 |
|
|
// clamping in recs and ints, it's not really worth bothering with yet. |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
// Execute VU for the number of VU cycles (recs might go over 0~30 cycles) |
147 |
|
|
// virtual void Execute(u32 cycles)=0; |
148 |
|
|
|
149 |
|
|
// Executes a Block based on static preset cycles OR |
150 |
|
|
// Executes a Block based on EE delta time (see VUmicro.cpp) |
151 |
|
|
virtual void ExecuteBlock(bool startUp=0); |
152 |
|
|
|
153 |
|
|
static void __fastcall ExecuteBlockJIT(BaseVUmicroCPU* cpu); |
154 |
|
|
}; |
155 |
|
|
|
156 |
|
|
|
157 |
|
|
// -------------------------------------------------------------------------------------- |
158 |
|
|
// InterpVU0 / InterpVU1 |
159 |
|
|
// -------------------------------------------------------------------------------------- |
160 |
|
|
class InterpVU0 : public BaseVUmicroCPU |
161 |
|
|
{ |
162 |
|
|
public: |
163 |
|
|
InterpVU0(); |
164 |
|
|
virtual ~InterpVU0() throw() { Shutdown(); } |
165 |
|
|
|
166 |
|
|
const char* GetShortName() const { return "intVU0"; } |
167 |
|
|
wxString GetLongName() const { return L"VU0 Interpreter"; } |
168 |
|
|
|
169 |
william |
280 |
void Reserve() { } |
170 |
william |
31 |
void Shutdown() throw() { } |
171 |
|
|
void Reset() { } |
172 |
|
|
|
173 |
|
|
void Step(); |
174 |
|
|
void Execute(u32 cycles); |
175 |
|
|
void Clear(u32 addr, u32 size) {} |
176 |
william |
280 |
|
177 |
|
|
uint GetCacheReserve() const { return 0; } |
178 |
|
|
void SetCacheReserve( uint reserveInMegs ) const {} |
179 |
william |
31 |
}; |
180 |
|
|
|
181 |
|
|
class InterpVU1 : public BaseVUmicroCPU |
182 |
|
|
{ |
183 |
|
|
public: |
184 |
|
|
InterpVU1(); |
185 |
|
|
virtual ~InterpVU1() throw() { Shutdown(); } |
186 |
|
|
|
187 |
|
|
const char* GetShortName() const { return "intVU1"; } |
188 |
|
|
wxString GetLongName() const { return L"VU1 Interpreter"; } |
189 |
|
|
|
190 |
william |
280 |
void Reserve() { } |
191 |
william |
31 |
void Shutdown() throw() { } |
192 |
|
|
void Reset() { } |
193 |
|
|
|
194 |
|
|
void Step(); |
195 |
|
|
void Execute(u32 cycles); |
196 |
|
|
void Clear(u32 addr, u32 size) {} |
197 |
william |
280 |
|
198 |
|
|
uint GetCacheReserve() const { return 0; } |
199 |
|
|
void SetCacheReserve( uint reserveInMegs ) const {} |
200 |
william |
31 |
}; |
201 |
|
|
|
202 |
|
|
// -------------------------------------------------------------------------------------- |
203 |
|
|
// recMicroVU0 / recMicroVU1 |
204 |
|
|
// -------------------------------------------------------------------------------------- |
205 |
|
|
class recMicroVU0 : public BaseVUmicroCPU |
206 |
|
|
{ |
207 |
|
|
public: |
208 |
|
|
recMicroVU0(); |
209 |
|
|
virtual ~recMicroVU0() throw() { Shutdown(); } |
210 |
|
|
|
211 |
|
|
const char* GetShortName() const { return "mVU0"; } |
212 |
|
|
wxString GetLongName() const { return L"microVU0 Recompiler"; } |
213 |
|
|
|
214 |
william |
280 |
void Reserve(); |
215 |
william |
31 |
void Shutdown() throw(); |
216 |
|
|
|
217 |
|
|
void Reset(); |
218 |
|
|
void Execute(u32 cycles); |
219 |
|
|
void Clear(u32 addr, u32 size); |
220 |
|
|
void Vsync() throw(); |
221 |
william |
280 |
|
222 |
|
|
uint GetCacheReserve() const; |
223 |
|
|
void SetCacheReserve( uint reserveInMegs ) const; |
224 |
william |
31 |
}; |
225 |
|
|
|
226 |
|
|
class recMicroVU1 : public BaseVUmicroCPU |
227 |
|
|
{ |
228 |
|
|
public: |
229 |
|
|
recMicroVU1(); |
230 |
|
|
virtual ~recMicroVU1() throw() { Shutdown(); } |
231 |
|
|
|
232 |
|
|
const char* GetShortName() const { return "mVU1"; } |
233 |
|
|
wxString GetLongName() const { return L"microVU1 Recompiler"; } |
234 |
|
|
|
235 |
william |
280 |
void Reserve(); |
236 |
william |
31 |
void Shutdown() throw(); |
237 |
|
|
void Reset(); |
238 |
|
|
void Execute(u32 cycles); |
239 |
|
|
void Clear(u32 addr, u32 size); |
240 |
|
|
void Vsync() throw(); |
241 |
william |
280 |
|
242 |
|
|
uint GetCacheReserve() const; |
243 |
|
|
void SetCacheReserve( uint reserveInMegs ) const; |
244 |
william |
31 |
}; |
245 |
|
|
|
246 |
|
|
// -------------------------------------------------------------------------------------- |
247 |
|
|
// recSuperVU0 / recSuperVU1 |
248 |
|
|
// -------------------------------------------------------------------------------------- |
249 |
|
|
|
250 |
|
|
class recSuperVU0 : public BaseVUmicroCPU |
251 |
|
|
{ |
252 |
|
|
public: |
253 |
|
|
recSuperVU0(); |
254 |
|
|
|
255 |
|
|
const char* GetShortName() const { return "sVU0"; } |
256 |
|
|
wxString GetLongName() const { return L"SuperVU0 Recompiler"; } |
257 |
|
|
|
258 |
william |
280 |
void Reserve(); |
259 |
william |
31 |
void Shutdown() throw(); |
260 |
|
|
void Reset(); |
261 |
|
|
void Execute(u32 cycles); |
262 |
|
|
void Clear(u32 Addr, u32 Size); |
263 |
william |
280 |
|
264 |
|
|
uint GetCacheReserve() const; |
265 |
|
|
void SetCacheReserve( uint reserveInMegs ) const; |
266 |
william |
31 |
}; |
267 |
|
|
|
268 |
|
|
class recSuperVU1 : public BaseVUmicroCPU |
269 |
|
|
{ |
270 |
|
|
public: |
271 |
|
|
recSuperVU1(); |
272 |
|
|
|
273 |
|
|
const char* GetShortName() const { return "sVU1"; } |
274 |
|
|
wxString GetLongName() const { return L"SuperVU1 Recompiler"; } |
275 |
|
|
|
276 |
william |
280 |
void Reserve(); |
277 |
william |
31 |
void Shutdown() throw(); |
278 |
|
|
void Reset(); |
279 |
|
|
void Execute(u32 cycles); |
280 |
|
|
void Clear(u32 Addr, u32 Size); |
281 |
william |
280 |
|
282 |
|
|
uint GetCacheReserve() const; |
283 |
|
|
void SetCacheReserve( uint reserveInMegs ) const; |
284 |
william |
31 |
}; |
285 |
|
|
|
286 |
|
|
extern BaseVUmicroCPU* CpuVU0; |
287 |
|
|
extern BaseVUmicroCPU* CpuVU1; |
288 |
|
|
|
289 |
|
|
|
290 |
|
|
// VU0 |
291 |
|
|
extern void vu0ResetRegs(); |
292 |
|
|
extern void __fastcall vu0ExecMicro(u32 addr); |
293 |
|
|
extern void vu0Exec(VURegs* VU); |
294 |
|
|
extern void vu0Finish(); |
295 |
william |
62 |
extern void iDumpVU0Registers(); |
296 |
william |
31 |
|
297 |
|
|
// VU1 |
298 |
|
|
extern void vu1Finish(); |
299 |
|
|
extern void vu1ResetRegs(); |
300 |
|
|
extern void __fastcall vu1ExecMicro(u32 addr); |
301 |
|
|
extern void vu1Exec(VURegs* VU); |
302 |
william |
62 |
extern void iDumpVU1Registers(); |
303 |
william |
31 |
|
304 |
|
|
#ifdef VUM_LOG |
305 |
|
|
|
306 |
|
|
#define IdebugUPPER(VU) \ |
307 |
|
|
VUM_LOG("%s", dis##VU##MicroUF(VU.code, VU.VI[REG_TPC].UL)); |
308 |
|
|
#define IdebugLOWER(VU) \ |
309 |
|
|
VUM_LOG("%s", dis##VU##MicroLF(VU.code, VU.VI[REG_TPC].UL)); |
310 |
|
|
#define _vuExecMicroDebug(VU) \ |
311 |
|
|
VUM_LOG("_vuExecMicro: %8.8x", VU.VI[REG_TPC].UL); |
312 |
|
|
|
313 |
|
|
#else |
314 |
|
|
|
315 |
|
|
#define IdebugUPPER(VU) |
316 |
|
|
#define IdebugLOWER(VU) |
317 |
|
|
#define _vuExecMicroDebug(VU) |
318 |
|
|
|
319 |
|
|
#endif |