/[pcsx2_0.9.7]/trunk/pcsx2/Dump.cpp
ViewVC logotype

Contents of /trunk/pcsx2/Dump.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 5 months ago) by william
File size: 10505 byte(s)
committing r3113 initial commit again...
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 #include "PrecompiledHeader.h"
17 #include "IopCommon.h"
18
19 #include "Counters.h"
20 #include "iCore.h"
21 #include "iR5900.h"
22 #include "IPU/IPU.h"
23
24 #include "AppConfig.h"
25 #include "Utilities/AsciiFile.h"
26
27 using namespace R5900;
28 // fixme: currently should not be uncommented.
29 //#define TEST_BROKEN_DUMP_ROUTINES
30
31 #ifdef TEST_BROKEN_DUMP_ROUTINES
32 extern tIPU_BP g_BP;
33
34 #define VF_VAL(x) ((x==0x80000000)?0:(x))
35 #endif
36
37
38 // iR5900-32.cpp
39 extern EEINST* s_pInstCache;
40 extern u32 s_nEndBlock; // what pc the current block ends
41
42
43 void iDumpPsxRegisters(u32 startpc, u32 temp)
44 {
45 // [TODO] fixme : this code is broken and has no labels. Needs a rewrite to be useful.
46
47 #ifdef TEST_BROKEN_DUMP_ROUTINES
48 int i;
49 const char* pstr = temp ? "t" : "";
50
51 // fixme: PSXM doesn't exist any more.
52 //__Log("%spsxreg: %x %x ra:%x k0: %x %x", pstr, startpc, psxRegs.cycle, psxRegs.GPR.n.ra, psxRegs.GPR.n.k0, *(int*)PSXM(0x13c128));
53
54 for(i = 0; i < 34; i+=2) __Log("%spsx%s: %x %x", pstr, disRNameGPR[i], psxRegs.GPR.r[i], psxRegs.GPR.r[i+1]);
55
56 DbgCon.WriteLn("%scycle: %x %x %x; counters %x %x", pstr, psxRegs.cycle, g_psxNextBranchCycle, EEsCycle,
57 psxNextsCounter, psxNextCounter);
58
59 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 2) + hw_dma(2).desc());
60 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 3) + hw_dma(3).desc());
61 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 4) + hw_dma(4).desc());
62 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 6) + hw_dma(6).desc());
63 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 7) + hw_dma(7).desc());
64 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 8) + hw_dma(8).desc());
65 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 9) + hw_dma(9).desc());
66 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 10) + hw_dma(10).desc());
67 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 11) + hw_dma(11).desc());
68 DbgCon.WriteLn(wxsFormat(L"psxdma%d ", 12) + hw_dma(12).desc());
69
70 for(i = 0; i < 7; ++i)
71 DbgCon.WriteLn("%scounter%d: mode %x count %I64x rate %x scycle %x target %I64x", pstr, i, psxCounters[i].mode, psxCounters[i].count, psxCounters[i].rate, psxCounters[i].sCycleT, psxCounters[i].target);
72 #endif
73 }
74
75 void iDumpRegisters(u32 startpc, u32 temp)
76 {
77 // [TODO] fixme : this code is broken and has no labels. Needs a rewrite to be useful.
78
79 #ifdef TEST_BROKEN_DUMP_ROUTINES
80
81 int i;
82 const char* pstr;// = temp ? "t" : "";
83 const u32 dmacs[] = {0x8000, 0x9000, 0xa000, 0xb000, 0xb400, 0xc000, 0xc400, 0xc800, 0xd000, 0xd400 };
84 const char* psymb;
85
86 if (temp)
87 pstr = "t";
88 else
89 pstr = "";
90
91 psymb = disR5900GetSym(startpc);
92
93 if( psymb != NULL )
94 __Log("%sreg(%s): %x %x c:%x", pstr, psymb, startpc, cpuRegs.interrupt, cpuRegs.cycle);
95 else
96 __Log("%sreg: %x %x c:%x", pstr, startpc, cpuRegs.interrupt, cpuRegs.cycle);
97
98 for(i = 1; i < 32; ++i) __Log("%s: %x_%x_%x_%x", disRNameGPR[i], cpuRegs.GPR.r[i].UL[3], cpuRegs.GPR.r[i].UL[2], cpuRegs.GPR.r[i].UL[1], cpuRegs.GPR.r[i].UL[0]);
99
100 //for(i = 0; i < 32; i+=4) __Log("cp%d: %x_%x_%x_%x", i, cpuRegs.CP0.r[i], cpuRegs.CP0.r[i+1], cpuRegs.CP0.r[i+2], cpuRegs.CP0.r[i+3]);
101 //for(i = 0; i < 32; ++i) __Log("%sf%d: %f %x", pstr, i, fpuRegs.fpr[i].f, fpuRegs.fprc[i]);
102 //for(i = 1; i < 32; ++i) __Log("%svf%d: %f %f %f %f, vi: %x", pstr, i, VU0.VF[i].F[3], VU0.VF[i].F[2], VU0.VF[i].F[1], VU0.VF[i].F[0], VU0.VI[i].UL);
103
104 for(i = 0; i < 32; ++i) __Log("%sf%d: %x %x", pstr, i, fpuRegs.fpr[i].UL, fpuRegs.fprc[i]);
105 for(i = 1; i < 32; ++i) __Log("%svf%d: %x %x %x %x, vi: %x", pstr, i, VU0.VF[i].UL[3], VU0.VF[i].UL[2], VU0.VF[i].UL[1], VU0.VF[i].UL[0], VU0.VI[i].UL);
106
107 __Log("%svfACC: %x %x %x %x", pstr, VU0.ACC.UL[3], VU0.ACC.UL[2], VU0.ACC.UL[1], VU0.ACC.UL[0]);
108 __Log("%sLO: %x_%x_%x_%x, HI: %x_%x_%x_%x", pstr, cpuRegs.LO.UL[3], cpuRegs.LO.UL[2], cpuRegs.LO.UL[1], cpuRegs.LO.UL[0],
109 cpuRegs.HI.UL[3], cpuRegs.HI.UL[2], cpuRegs.HI.UL[1], cpuRegs.HI.UL[0]);
110 __Log("%sCycle: %x %x, Count: %x", pstr, cpuRegs.cycle, g_nextBranchCycle, cpuRegs.CP0.n.Count);
111
112 iDumpPsxRegisters(psxRegs.pc, temp);
113
114 __Log("f410,30,40: %x %x %x, %d %d", psHu32(0xf410), psHu32(0xf430), psHu32(0xf440), rdram_sdevid, rdram_devices);
115 __Log("cyc11: %x %x; vu0: %x, vu1: %x", cpuRegs.sCycle[1], cpuRegs.eCycle[1], VU0.cycle, VU1.cycle);
116
117 __Log("%scounters: %x %x; psx: %x %x", pstr, nextsCounter, nextCounter, psxNextsCounter, psxNextCounter);
118
119 // fixme: The members of the counters[i] struct are wrong here.
120 /*for(i = 0; i < 4; ++i) {
121 __Log("eetimer%d: count: %x mode: %x target: %x %x; %x %x; %x %x %x %x", i,
122 counters[i].count, counters[i].mode, counters[i].target, counters[i].hold, counters[i].rate,
123 counters[i].interrupt, counters[i].Cycle, counters[i].sCycle, counters[i].CycleT, counters[i].sCycleT);
124 }*/
125 __Log("VIF0_STAT = %x, VIF1_STAT = %x", psHu32(0x3800), psHu32(0x3C00));
126 __Log("ipu %x %x %x %x; bp: %x %x %x %x", psHu32(0x2000), psHu32(0x2010), psHu32(0x2020), psHu32(0x2030), g_BP.BP, g_BP.bufferhasnew, g_BP.FP, g_BP.IFC);
127 __Log("gif: %x %x %x", psHu32(0x3000), psHu32(0x3010), psHu32(0x3020));
128
129 for(i = 0; i < ArraySize(dmacs); ++i) {
130 DMACh* p = (DMACh*)(PS2MEM_HW+dmacs[i]);
131 __Log("dma%d c%x m%x q%x t%x s%x", i, p->chcr._u32, p->madr, p->qwc, p->tadr, p->sadr);
132 }
133 __Log(L"dmac " + dmacRegs->ctrl.desc() + L" " + dmacRegs->stat.desc() + L" " + dmacRegs->rbsr.desc() + L" " + dmacRegs->rbor.desc());
134 __Log(L"intc " + intcRegs->stat.desc() + L" " + intcRegs->mask.desc());
135 __Log("sif: %x %x %x %x %x", psHu32(SBUS_F200), psHu32(SBUS_F220), psHu32(SBUS_F230), psHu32(SBUS_F240), psHu32(SBUS_F260));
136 #endif
137 }
138
139 void iDumpVU0Registers()
140 {
141 // fixme: This code is outdated, broken, and lacks printed labels.
142 // Needs heavy mods to be useful.
143 #ifdef TEST_BROKEN_DUMP_ROUTINES
144 for(int i = 1; i < 32; ++i) {
145 __Log("v%d: %x %x %x %x, vi: ", i, VF_VAL(VU0.VF[i].UL[3]), VF_VAL(VU0.VF[i].UL[2]),
146 VF_VAL(VU0.VF[i].UL[1]), VF_VAL(VU0.VF[i].UL[0]));
147
148 switch (i)
149 {
150 case REG_Q:
151 case REG_P:
152 __Log("%f", VU0.VI[i].F);
153 break;
154 case REG_MAC_FLAG:
155 __Log("%x", 0);//VU0.VI[i].UL&0xff);
156 break;
157 case REG_STATUS_FLAG:
158 __Log("%x", 0);//VU0.VI[i].UL&0x03);
159 break;
160 case REG_CLIP_FLAG:
161 __Log("0");
162 break;
163 default:
164 __Log("%x", VU0.VI[i].UL);
165 break;
166 }
167 }
168 __Log("vfACC: %f %f %f %f\n", VU0.ACC.F[3], VU0.ACC.F[2], VU0.ACC.F[1], VU0.ACC.F[0]);
169 #endif
170 }
171
172 void iDumpVU1Registers()
173 {
174 // fixme: This code is outdated, broken, and lacks printed labels.
175 // Needs heavy mods to be useful.
176 #ifdef TEST_BROKEN_DUMP_ROUTINES
177 int i;
178
179 // static int icount = 0;
180 // __Log("%x\n", icount);
181
182 for(i = 1; i < 32; ++i) {
183
184 // __Log("v%d: w%f(%x) z%f(%x) y%f(%x) x%f(%x), vi: ", i, VU1.VF[i].F[3], VU1.VF[i].UL[3], VU1.VF[i].F[2], VU1.VF[i].UL[2],
185 // VU1.VF[i].F[1], VU1.VF[i].UL[1], VU1.VF[i].F[0], VU1.VF[i].UL[0]);
186 //__Log("v%d: %f %f %f %f, vi: ", i, VU1.VF[i].F[3], VU1.VF[i].F[2], VU1.VF[i].F[1], VU1.VF[i].F[0]);
187
188 __Log("v%d: %x %x %x %x, vi: ", i, VF_VAL(VU1.VF[i].UL[3]), VF_VAL(VU1.VF[i].UL[2]), VF_VAL(VU1.VF[i].UL[1]), VF_VAL(VU1.VF[i].UL[0]));
189
190 if( i == REG_Q || i == REG_P ) __Log("%f\n", VU1.VI[i].F);
191 //else __Log("%x\n", VU1.VI[i].UL);
192 else __Log("%x\n", (i==REG_STATUS_FLAG||i==REG_MAC_FLAG||i==REG_CLIP_FLAG)?0:VU1.VI[i].UL);
193 }
194 __Log("vfACC: %f %f %f %f\n", VU1.ACC.F[3], VU1.ACC.F[2], VU1.ACC.F[1], VU1.ACC.F[0]);
195 #endif
196 }
197
198 // Originally from iR5900-32.cpp
199 void iDumpBlock( int startpc, u8 * ptr )
200 {
201 u8 used[34];
202 u8 fpuused[33];
203 int numused, fpunumused;
204
205 DbgCon.WriteLn( Color_Gray, "dump1 %x:%x, %x", startpc, pc, cpuRegs.cycle );
206
207 g_Conf->Folders.Logs.Mkdir();
208 AsciiFile eff(
209 Path::Combine( g_Conf->Folders.Logs, wxsFormat(L"R5900dump%.8X.txt", startpc) ), L"w"
210 );
211
212 if( disR5900GetSym(startpc) != NULL )
213 {
214 eff.Printf( disR5900GetSym( startpc ) );
215 eff.Printf( "\n" );
216 }
217
218 for ( uint i = startpc; i < s_nEndBlock; i += 4 )
219 {
220 string output;
221 disR5900Fasm( output, memRead32( i ), i );
222 eff.Printf( output.c_str() );
223 }
224
225 // write the instruction info
226
227 eff.Printf( "\n\nlive0 - %x, live2 - %x, lastuse - %x\nxmm - %x, used - %x\n",
228 EEINST_LIVE0, EEINST_LIVE2, EEINST_LASTUSE, EEINST_XMM, EEINST_USED
229 );
230
231 memzero(used);
232 numused = 0;
233 for(uint i = 0; i < ArraySize(s_pInstCache->regs); ++i) {
234 if( s_pInstCache->regs[i] & EEINST_USED ) {
235 used[i] = 1;
236 numused++;
237 }
238 }
239
240 memzero(fpuused);
241 fpunumused = 0;
242 for(uint i = 0; i < ArraySize(s_pInstCache->fpuregs); ++i) {
243 if( s_pInstCache->fpuregs[i] & EEINST_USED ) {
244 fpuused[i] = 1;
245 fpunumused++;
246 }
247 }
248
249 eff.Printf( " " );
250 for(uint i = 0; i < ArraySize(s_pInstCache->regs); ++i) {
251 if( used[i] ) eff.Printf( "%2d ", i );
252 }
253 eff.Printf( "\n" );
254 for(uint i = 0; i < ArraySize(s_pInstCache->fpuregs); ++i) {
255 if( fpuused[i] ) eff.Printf( "%2d ", i );
256 }
257
258 eff.Printf( "\n" );
259 eff.Printf( " " );
260
261 // TODO : Finish converting this over to wxWidgets wxFile stuff...
262 /*
263 int count;
264 EEINST* pcur;
265
266 for(uint i = 0; i < ArraySize(s_pInstCache->regs); ++i) {
267 if( used[i] ) fprintf(f, "%s ", disRNameGPR[i]);
268 }
269 for(uint i = 0; i < ArraySize(s_pInstCache->fpuregs); ++i) {
270 if( fpuused[i] ) fprintf(f, "%s ", i<32?"FR":"FA");
271 }
272 fprintf(f, "\n");
273
274 pcur = s_pInstCache+1;
275 for( uint i = 0; i < (s_nEndBlock-startpc)/4; ++i, ++pcur) {
276 fprintf(f, "%2d: %2.2x ", i+1, pcur->info);
277
278 count = 1;
279 for(uint j = 0; j < ArraySize(s_pInstCache->regs); j++) {
280 if( used[j] ) {
281 fprintf(f, "%2.2x%s", pcur->regs[j], ((count%8)&&count<numused)?"_":" ");
282 ++count;
283 }
284 }
285 count = 1;
286 for(uint j = 0; j < ArraySize(s_pInstCache->fpuregs); j++) {
287 if( fpuused[j] ) {
288 fprintf(f, "%2.2x%s", pcur->fpuregs[j], ((count%8)&&count<fpunumused)?"_":" ");
289 ++count;
290 }
291 }
292 fprintf(f, "\n");
293 }
294 fclose( f );*/
295 }

  ViewVC Help
Powered by ViewVC 1.1.22