/[pcsx2_0.9.7]/trunk/pcsx2/VUmicro.h
ViewVC logotype

Contents of /trunk/pcsx2/VUmicro.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 5 months ago) by william
File MIME type: text/plain
File size: 8658 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 /* 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
18 #include "VU.h"
19 #include "VUops.h"
20 #include "R5900.h"
21
22 static const uint VU0_MEMSIZE = 0x1000;
23 static const uint VU0_PROGSIZE = 0x1000;
24 static const uint VU1_MEMSIZE = 0x4000;
25 static const uint VU1_PROGSIZE = 0x4000;
26
27 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
32 #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 // allocation counter for multiple init/shutdown calls
51 // (most or all implementations will need this!)
52 int m_AllocCount;
53
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 m_AllocCount = 0;
64 }
65
66 virtual ~BaseCpuProvider() throw()
67 {
68 if( m_AllocCount != 0 )
69 Console.Warning( "Cleanup miscount detected on CPU provider. Count=%d", m_AllocCount );
70 }
71
72 virtual const char* GetShortName() const=0;
73 virtual wxString GetLongName() const=0;
74
75 virtual void Allocate()=0;
76 virtual void Shutdown()=0;
77 virtual void Reset()=0;
78 virtual void Execute(u32 cycles)=0;
79 virtual void ExecuteBlock(bool startUp)=0;
80
81 virtual void Step()=0;
82 virtual void Clear(u32 Addr, u32 Size)=0;
83
84 // C++ Calling Conventions are unstable, and some compilers don't even allow us to take the
85 // address of C++ methods. We need to use a wrapper function to invoke the ExecuteBlock from
86 // recompiled code.
87 static void __fastcall ExecuteBlockJIT( BaseCpuProvider* cpu )
88 {
89 cpu->Execute(1024);
90 }
91 };
92
93 // --------------------------------------------------------------------------------------
94 // BaseVUmicroCPU
95 // --------------------------------------------------------------------------------------
96 // Layer class for possible future implementation (currently is nothing more than a type-safe
97 // type define).
98 //
99 class BaseVUmicroCPU : public BaseCpuProvider {
100 public:
101 int m_Idx;
102 u32 m_lastEEcycles;
103
104 BaseVUmicroCPU() {
105 m_Idx = 0;
106 m_lastEEcycles = 0;
107 }
108 virtual ~BaseVUmicroCPU() throw() {}
109
110 // Called by the PS2 VM's event manager for every internal vertical sync (occurs at either
111 // 50hz (pal) or 59.94hz (NTSC).
112 //
113 // Exceptions:
114 // This method is not allowed to throw exceptions, since exceptions may not propagate
115 // safely from the context of recompiled code stackframes.
116 //
117 // Thread Affinity:
118 // Called from the EEcore thread. No locking is performed, so any necessary locks must
119 // be implemented by the CPU provider manually.
120 //
121 virtual void Vsync() throw() { }
122
123 virtual void Step() {
124 // Ideally this would fall back on interpretation for executing single instructions
125 // for all CPU types, but due to VU complexities and large discrepancies between
126 // clamping in recs and ints, it's not really worth bothering with yet.
127 }
128
129 // Execute VU for the number of VU cycles (recs might go over 0~30 cycles)
130 // virtual void Execute(u32 cycles)=0;
131
132 // Executes a Block based on static preset cycles OR
133 // Executes a Block based on EE delta time (see VUmicro.cpp)
134 virtual void ExecuteBlock(bool startUp=0);
135
136 static void __fastcall ExecuteBlockJIT(BaseVUmicroCPU* cpu);
137 };
138
139
140 // --------------------------------------------------------------------------------------
141 // InterpVU0 / InterpVU1
142 // --------------------------------------------------------------------------------------
143 class InterpVU0 : public BaseVUmicroCPU
144 {
145 public:
146 InterpVU0();
147 virtual ~InterpVU0() throw() { Shutdown(); }
148
149 const char* GetShortName() const { return "intVU0"; }
150 wxString GetLongName() const { return L"VU0 Interpreter"; }
151
152 void Allocate() { }
153 void Shutdown() throw() { }
154 void Reset() { }
155
156 void Step();
157 void Execute(u32 cycles);
158 void Clear(u32 addr, u32 size) {}
159 };
160
161 class InterpVU1 : public BaseVUmicroCPU
162 {
163 public:
164 InterpVU1();
165 virtual ~InterpVU1() throw() { Shutdown(); }
166
167 const char* GetShortName() const { return "intVU1"; }
168 wxString GetLongName() const { return L"VU1 Interpreter"; }
169
170 void Allocate() { }
171 void Shutdown() throw() { }
172 void Reset() { }
173
174 void Step();
175 void Execute(u32 cycles);
176 void Clear(u32 addr, u32 size) {}
177 };
178
179 // --------------------------------------------------------------------------------------
180 // recMicroVU0 / recMicroVU1
181 // --------------------------------------------------------------------------------------
182 class recMicroVU0 : public BaseVUmicroCPU
183 {
184 public:
185 recMicroVU0();
186 virtual ~recMicroVU0() throw() { Shutdown(); }
187
188 const char* GetShortName() const { return "mVU0"; }
189 wxString GetLongName() const { return L"microVU0 Recompiler"; }
190
191 void Allocate();
192 void Shutdown() throw();
193
194 void Reset();
195 void Execute(u32 cycles);
196 void Clear(u32 addr, u32 size);
197 void Vsync() throw();
198 };
199
200 class recMicroVU1 : public BaseVUmicroCPU
201 {
202 public:
203 recMicroVU1();
204 virtual ~recMicroVU1() throw() { Shutdown(); }
205
206 const char* GetShortName() const { return "mVU1"; }
207 wxString GetLongName() const { return L"microVU1 Recompiler"; }
208
209 void Allocate();
210 void Shutdown() throw();
211 void Reset();
212 void Execute(u32 cycles);
213 void Clear(u32 addr, u32 size);
214 void Vsync() throw();
215 };
216
217 // --------------------------------------------------------------------------------------
218 // recSuperVU0 / recSuperVU1
219 // --------------------------------------------------------------------------------------
220
221 class recSuperVU0 : public BaseVUmicroCPU
222 {
223 public:
224 recSuperVU0();
225
226 const char* GetShortName() const { return "sVU0"; }
227 wxString GetLongName() const { return L"SuperVU0 Recompiler"; }
228
229 void Allocate();
230 void Shutdown() throw();
231 void Reset();
232 void Execute(u32 cycles);
233 void Clear(u32 Addr, u32 Size);
234 };
235
236 class recSuperVU1 : public BaseVUmicroCPU
237 {
238 public:
239 recSuperVU1();
240
241 const char* GetShortName() const { return "sVU1"; }
242 wxString GetLongName() const { return L"SuperVU1 Recompiler"; }
243
244 void Allocate();
245 void Shutdown() throw();
246 void Reset();
247 void Execute(u32 cycles);
248 void Clear(u32 Addr, u32 Size);
249 };
250
251 extern BaseVUmicroCPU* CpuVU0;
252 extern BaseVUmicroCPU* CpuVU1;
253
254
255 extern void vuMicroMemAlloc();
256 extern void vuMicroMemShutdown();
257 extern void vuMicroMemReset();
258
259 // VU0
260 extern void vu0ResetRegs();
261 extern void __fastcall vu0ExecMicro(u32 addr);
262 extern void vu0Exec(VURegs* VU);
263 extern void vu0Finish();
264 extern void iDumpVU0Registers();
265
266 // VU1
267 extern void vu1Finish();
268 extern void vu1ResetRegs();
269 extern void __fastcall vu1ExecMicro(u32 addr);
270 extern void vu1Exec(VURegs* VU);
271 extern void iDumpVU1Registers();
272
273 #ifdef VUM_LOG
274
275 #define IdebugUPPER(VU) \
276 VUM_LOG("%s", dis##VU##MicroUF(VU.code, VU.VI[REG_TPC].UL));
277 #define IdebugLOWER(VU) \
278 VUM_LOG("%s", dis##VU##MicroLF(VU.code, VU.VI[REG_TPC].UL));
279 #define _vuExecMicroDebug(VU) \
280 VUM_LOG("_vuExecMicro: %8.8x", VU.VI[REG_TPC].UL);
281
282 #else
283
284 #define IdebugUPPER(VU)
285 #define IdebugLOWER(VU)
286 #define _vuExecMicroDebug(VU)
287
288 #endif

  ViewVC Help
Powered by ViewVC 1.1.22