-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpu_debug.h
More file actions
740 lines (661 loc) · 31.4 KB
/
cpu_debug.h
File metadata and controls
740 lines (661 loc) · 31.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/* ES40 emulator.
* Copyright (C) 2007-2008 by the ES40 Emulator Project
*
* WWW : http://sourceforge.net/projects/es40
* E-mail : camiel@camicom.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Although this is not required, the author would appreciate being notified of,
* and receiving any modifications you may make to the source code that might serve
* the general public.
*/
/**
* \file
* Contains debugging macros used by AlphaCPU.cpp
*
* $Id: cpu_debug.h,v 1.24 2008/02/29 13:50:25 iamcamiel Exp $
*
* X-1.24 Camiel Vanderhoeven 29-FEB-2008
* Comments.
*
* X-1.23 Brian Wheeler 29-FEB-2008
* Fix IDB compilation.
*
* X-1.22 Camiel Vanderhoeven 30-JAN-2008
* Always use set_pc or add_pc to change the program counter.
*
* X-1.21 Camiel Vanderhoeven 30-JAN-2008
* Remember number of instructions left in current memory page, so
* that the translation-buffer doens't need to be consulted on every
* instruction fetch when the Icache is disabled.
*
* X-1.20 Camiel Vanderhoeven 28-JAN-2008
* Better floating-point exception handling.
*
* X-1.19 Camiel Vanderhoeven 27-JAN-2008
* Have GO_PAL throw an exception, so we don't continue doing what we
* were doing before the exception was taken.
*
* X-1.18 Camiel Vanderhoeven 21-JAN-2008
* Moved some macro's to cpu_defs.h.
*
* X-1.17 Camiel Vanderhoeven 16-JAN-2008
* Added ARITH_TRAP macro.
*
* X-1.16 Camiel Vanderhoeven 2-DEC-2007
* Moved PAL_NAME and IPR_NAME to AlphaCPU.cpp.
*
* X-1.15 Camiel Vanderhoeven 10-NOV-2007
* f12_f3 operations show fxx as registers instead of rxx.
*
* X-1.14 Camiel Vanderhoeven 30-OCT-2007
* IPR 0x2d identified as M_FIX (Mbox fixed behaviour)
*
* X-1.13 Camiel Vanderhoeven 11-APR-2007
* Moved all data that should be saved to a state file to a structure
* "state".
*
* X-1.12 Camiel Vanderhoeven 30-MAR-2007
* Added old changelog comments.
*
* X-1.11 Camiel Vanderhoeven 14-MAR-2007
* Small bugfix in DEBUG_XX macro.
*
* X-1.10 Camiel Vanderhoeven 14-MAR-2007
* Small bugfix in FP debugging macro's.
*
* X-1.9 Camiel Vanderhoeven 13-MAR-2007
* Added FP debugging macro's.
*
* X-1.8 Camiel Vanderhoeven 12-MAR-2007
* a) When an exception occurs, debugging information for the previous
* instruction is no longer lost.
* b) Made various printf-statements 64-bit safe in a neater way. (Use
* printf("%" LL "x",value) instead of printf("%x",(u64)value)).
*
* X-1.7 Camiel Vanderhoeven 8-MAR-2007
* Pass "this" as an argument to CTraceEngine::get_fnc_name.
*
* X-1.6 Camiel Vanderhoeven 28-FEB-2007
* a) Removed MINI_DEBUG_XX
* b) Debugging now writes to the char* debug_string, rather than using
* printf directly. This allows us to do other things with debugger
* output.
*
* X-1.5 Camiel Vanderhoeven 22-FEB-2007
* a) Replaced IPR macro's with separate MTPR and MFPR macro's (because
* these instructions use different registers).
* b) Made a couple of printf's multi-platform-safe.
*
* X-1.4 Camiel Vanderhoeven 18-FEB-2007
* Introduced POST_xxx and PRE_xxx macro's. When debugging, these are
* included from the OP macro in AlphaCPU.cpp.
*
* X-1.3 Camiel Vanderhoeven 16-FEB-2007
* a) Macro's that end CAlphaCPU::DoClock() now return 0.
* b) Made a couple of printf's multi-platform-safe.
*
* X-1.2 Brian Wheeler 13-FEB-2007
* Added mini-version of DEBUG_XX, that dumps all registers in a
* concise format.
*
* X-1.1 Camiel Vanderhoeven 12-FEB-2007
* File created. Contains code previously found in AlphaCPU.h
**/
#if defined(IDB)
extern char * PAL_NAME[];
extern char * IPR_NAME[];
extern char dbg_string[1000];
#if !defined(LS_MASTER) && !defined(LS_SLAVE)
extern char * dbg_strptr;
#endif
void handle_debug_string(char * s);
#define TRC_(down,up,x,y) \
if (bTrace) \
trc->trace(this, state.current_pc, state.pc, down, up, x, y);
#define TRC(down,up) \
if (bTrace) \
trc->trace(this, state.current_pc, state.pc, down, up, (char*)0, 0);
#define TRC_BR \
if (bTrace) \
trc->trace_br(this, state.current_pc,state.pc); \
#define GO_PAL(offset) \
{ \
if (bDisassemble) { \
sprintf(dbg_strptr," ==> PAL %x!\n",offset); \
dbg_strptr += strlen(dbg_strptr); \
} \
handle_debug_string(dbg_string); \
state.exc_addr = state.current_pc; \
set_pc(state.pal_base | offset | 1); \
if ((offset==DTBM_SINGLE || offset==ITB_MISS) && bTrace) \
trc->set_waitfor(this, state.exc_addr&~X64(3)); \
else \
TRC_(true,false,"GO_PAL %04x",offset); \
}
#else
#define TRC_(down,up,x,y) ;
#define TRC(down,up) ;
#define TRC_BR ;
#define GO_PAL(offset) \
{ \
state.exc_addr = state.current_pc; \
set_pc(state.pal_base | offset | 1); \
}
#endif
#if defined(IDB)
#define DEBUG_XX \
if (trc->get_fnc_name(this, state.current_pc&~X64(3),&funcname)) \
{ \
if (bListing && !strcmp(funcname,"")) { \
printf("%08" LL "x: \"%s\"\n",state.current_pc, \
cSystem->PtrToMem(state.current_pc)); \
state.pc =( state.current_pc \
+ strlen(cSystem->PtrToMem(state.current_pc)) + 4) \
& ~X64(3); \
while (state.pc < 0x600000 && \
cSystem->ReadMem(state.pc,32,this)==0) \
state.pc += 4; \
return 0; \
} else if (bListing && !strcmp(funcname,"!SKIP")) { \
while (state.pc < 0x600000 && \
cSystem->ReadMem(state.pc,32,this)==0) \
state.pc += 4; \
return 0; \
} else if (bListing && !strncmp(funcname,"!CHAR-",6)) { \
u64 xx_upto; \
int xx_result; \
xx_result = sscanf(&(funcname[6]),"%" LL "x",&xx_upto); \
if (xx_result==1) { \
state.pc = state.current_pc; \
while (state.pc < xx_upto) { \
printf("%08" LL "x: \"%s\"\n", state.pc, \
cSystem->PtrToMem(state.pc)); \
state.pc += strlen(cSystem->PtrToMem(state.pc)); \
while (state.pc < xx_upto && \
cSystem->ReadMem(state.pc,8,this)==0) \
state.pc++; \
} \
return 0; \
} \
} else if (bListing && !strncmp(funcname,"!LCHAR-",7)) { \
char stringval[300]; \
int stringlen; \
u64 xx_upto; \
int xx_result; \
xx_result = sscanf(&(funcname[7]),"%" LL "x",&xx_upto); \
if (xx_result==1) { \
state.pc = state.current_pc; \
while (state.pc < xx_upto) { \
stringlen = (int)cSystem->ReadMem(state.pc++,8,this); \
memset(stringval,0,300); \
strncpy(stringval,cSystem->PtrToMem(state.pc),stringlen); \
printf("%08" LL "x: \"%s\"\n",state.pc-1, stringval); \
state.pc += stringlen; \
while (state.pc < xx_upto && \
cSystem->ReadMem(state.pc,8,this)==0) \
state.pc++; \
} \
return 0; \
} \
} else if (bListing && !strncmp(funcname,"!X64-",5)) { \
printf("\n%s:\n",&(funcname[5])); \
state.pc = state.current_pc; \
while ( (state.pc==state.current_pc) \
|| !trc->get_fnc_name(this,state.pc,&funcname) ) \
{ \
printf("%08" LL "x: %016" LL "x\n",state.pc, \
cSystem->ReadMem(state.pc,64,this)); \
state.pc += 8; \
} \
return 0; \
} else if (bListing&& !strncmp(funcname,"!X32-",5)) { \
printf("\n%s:\n",&(funcname[5])); \
state.pc = state.current_pc; \
while ( (state.pc==state.current_pc) \
|| !trc->get_fnc_name(this,state.pc,&funcname) ) \
{ \
printf("%08" LL "x: %08" LL "x\n",state.pc, \
cSystem->ReadMem(state.pc,32,this)); \
state.pc += 4; \
} \
return 0; \
} else if (!strncmp(funcname,":",1)) { \
sprintf(dbg_strptr,"%s:\n",funcname); \
dbg_strptr += strlen(dbg_strptr); \
} else { \
sprintf(dbg_strptr,"\n%s:\n",funcname); \
dbg_strptr += strlen(dbg_strptr); \
} \
} \
sprintf(dbg_strptr,bListing?"%08" LL "x: ":"%016" LL "x", \
state.current_pc); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) \
sprintf(dbg_strptr, "(%08" LL "x): ", current_pc_physical); \
else \
sprintf(dbg_strptr,"%08x %c%c%c%c: ", ins, \
printable((char)(ins)), printable((char)(ins>>8)), \
printable((char)(ins>>16)), printable((char)(ins>>24))); \
dbg_strptr += strlen(dbg_strptr); \
#define UNKNOWN1 \
if (bDisassemble) { \
DEBUG_XX \
} \
sprintf(dbg_strptr,"Unknown opcode: %02x ", opcode); \
dbg_strptr += strlen(dbg_strptr); \
handle_debug_string(dbg_string); \
return 0;
#define UNKNOWN2 \
if (bDisassemble) { \
DEBUG_XX \
} \
sprintf(dbg_strptr,"Unknown opcode: %02x.%02x ", opcode, \
function); \
dbg_strptr += strlen(dbg_strptr); \
handle_debug_string(dbg_string); \
return 0;
#define POST_X64(a) \
if (bDisassemble) { \
if (!bListing) { \
sprintf(dbg_strptr, " ==> %" LL "x", a); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define PRE_PAL(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
if (function < 0x40 || ( function > 0x7f && function < 0xc0)) \
sprintf(dbg_strptr, #mnemonic " %s", PAL_NAME[function]); \
else \
sprintf(dbg_strptr,#mnemonic " ?%x?", function); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_PAL \
TRC(1,0);
#define PRE_BR(mnemonic) \
if (bDisassemble) { \
u64 dbg_x = (state.current_pc + 4 + (DISP_21 * 4))&~X64(3); \
DEBUG_XX \
sprintf(dbg_strptr,#mnemonic " r%d, ", REG_1&31); \
dbg_strptr += strlen(dbg_strptr); \
if (trc->get_fnc_name(this,dbg_x,&funcname)) \
sprintf(dbg_strptr,"%s",funcname); \
else \
sprintf (dbg_strptr,"%" LL "x", dbg_x); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_BR \
TRC_BR;
#define PRE_COND(mnemonic) \
if (bDisassemble) { \
u64 dbg_x = (state.current_pc + 4 + (DISP_21 * 4))&~X64(3); \
DEBUG_XX \
sprintf(dbg_strptr,#mnemonic " r%d, ", REG_1&31); \
dbg_strptr += strlen(dbg_strptr); \
if (trc->get_fnc_name(this,dbg_x,&funcname)) \
sprintf(dbg_strptr,"%s",funcname); \
else \
sprintf (dbg_strptr,"%" LL "x", dbg_x); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.r[REG_1]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_COND \
TRC_BR;
#define PRE_FCOND(mnemonic) \
if (bDisassemble) { \
u64 dbg_x = (state.current_pc + 4 + (DISP_21 * 4))&~X64(3); \
DEBUG_XX \
sprintf(dbg_strptr,#mnemonic " f%d, ", FREG_1); \
dbg_strptr += strlen(dbg_strptr); \
if (trc->get_fnc_name(this,dbg_x,&funcname)) \
sprintf(dbg_strptr,"%s",funcname); \
else \
sprintf (dbg_strptr,"%" LL "x", dbg_x); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.f[FREG_1]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_FCOND \
TRC_BR;
#define PRE_BSR(mnemonic) \
if (bDisassemble) { \
u64 dbg_x = (state.current_pc + 4 + (DISP_21 * 4))&~X64(3); \
DEBUG_XX \
sprintf(dbg_strptr,#mnemonic " r%d, ", REG_1&31); \
dbg_strptr += strlen(dbg_strptr); \
if (trc->get_fnc_name(this,dbg_x,&funcname)) \
sprintf(dbg_strptr,"%s",funcname); \
else \
sprintf (dbg_strptr,"%" LL "x", dbg_x); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_BSR \
if (REG_1==31) { \
TRC(0,1); \
} else { \
TRC(1,1); \
}
#define PRE_JMP(mnemonic) \
if (bDisassemble) { \
DEBUG_XX \
sprintf(dbg_strptr,#mnemonic " r%d, r%d", REG_1&31, REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.r[REG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_JMP \
if (REG_1==31) { \
TRC(0,1); \
} else { \
TRC(1,1); \
}
#define PRE_RET(mnemonic) \
if (bDisassemble) { \
DEBUG_XX \
sprintf(dbg_strptr,#mnemonic " r%d", REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.r[REG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_RET \
TRC(0,1);
#define PRE_MFPR(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " r%d, %s", REG_1&31, \
IPR_NAME[function]); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_MFPR \
POST_X64(state.r[REG_1]);
#define PRE_MTPR(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " r%d, %s", REG_2&31, \
IPR_NAME[function]); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_MTPR \
POST_X64(state.r[REG_2]);
#define PRE_NOP(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic ""); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_NOP ;
#define PRE_MEM(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr, #mnemonic " r%d, %04xH(r%d)", REG_1&31, \
(u32)DISP_16, REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.r[REG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_MEM \
POST_X64(state.r[REG_1]);
#define PRE_R12_R3(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " r%d, ", REG_1&31); \
dbg_strptr += strlen(dbg_strptr); \
if (ins&0x1000) \
sprintf(dbg_strptr,"%02xH",V_2); \
else \
sprintf(dbg_strptr,"r%d",REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
sprintf(dbg_strptr,", r%d", REG_3&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x,%" LL "x)",state.r[REG_1], \
V_2); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_R12_R3 \
POST_X64(state.r[REG_3]);
// Pre-debugging macro for floating-point instructions that have Fa and Fb
// as input and Fc as output.
#define PRE_F12_F3(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " f%d, f%d, f%d", FREG_1, FREG_2, \
FREG_3); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x,%" LL "x)",state.f[FREG_1], \
state.f[FREG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
// Post-debugging macro for floating-point instructions that have Fa and Fb
// as input and Fc as output.
#define POST_F12_F3 \
POST_X64(state.f[FREG_3]);
#define PRE_R1_F3(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " r%d, f%d ", REG_1&31, FREG_3); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)",state.r[REG_1]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_R1_F3 \
POST_X64(state.f[FREG_3]);
#define PRE_F1_R3(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " f%d, r%d ", FREG_1, REG_3&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)",state.f[FREG_1]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_F1_R3 \
POST_X64(state.r[REG_3]);
#define PRE_X_F1(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " f%d ", FREG_1&31); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_X_F1 \
POST_X64(state.f[FREG_1]);
#define PRE_R2_R3(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " "); \
dbg_strptr += strlen(dbg_strptr); \
if (ins&0x1000) \
sprintf(dbg_strptr,"%02xH",V_2); \
else \
sprintf(dbg_strptr,"r%d",REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
sprintf(dbg_strptr,", r%d", REG_3&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)",V_2); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_R2_R3 \
POST_X64(state.r[REG_3]);
#define PRE_X_R1(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " r%d", REG_1&31); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_X_R1 \
POST_X64(state.r[REG_1]);
#define PRE_X_R3(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic " r%d", REG_3&31); \
dbg_strptr += strlen(dbg_strptr); \
}
#define POST_X_R3 \
POST_X64(state.r[REG_3]);
#define PRE_HW_LD(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic); \
dbg_strptr += strlen(dbg_strptr); \
switch(function&~1) { \
case 0: \
sprintf(dbg_strptr,"/Phys"); \
break; \
case 2: \
sprintf(dbg_strptr,"/Phys/Lock"); \
break; \
case 4: \
sprintf(dbg_strptr,"/Vpte"); \
break; \
case 10: \
sprintf(dbg_strptr,"/Chk"); \
break; \
case 12: \
sprintf(dbg_strptr,"/Alt"); \
break; \
case 14: \
sprintf(dbg_strptr,"/Alt/Chk"); \
break; \
} \
dbg_strptr += strlen(dbg_strptr); \
sprintf(dbg_strptr," r%d, %04xH(r%d)", REG_1&31, (u32)DISP_12, \
REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.r[REG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_HW_LD \
POST_X64(state.r[REG_1]);
#define PRE_HW_ST(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr,#mnemonic); \
dbg_strptr += strlen(dbg_strptr); \
switch(function&~1) { \
case 0: \
sprintf(dbg_strptr,"/Phys"); \
break; \
case 2: \
sprintf(dbg_strptr,"/Phys/Cond"); \
break; \
case 12: \
sprintf(dbg_strptr,"/Alt"); \
break; \
} \
dbg_strptr += strlen(dbg_strptr); \
sprintf(dbg_strptr," r%d, %04xH(r%d)", REG_1&31, (u32)DISP_12, \
REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.r[REG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
#define POST_HW_ST \
POST_X64(state.r[REG_1]);
// Pre-debugging macro for floating-point load/store instructions.
#define PRE_FMEM(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr, #mnemonic " f%d, %04xH(r%d)", FREG_1, \
(u32)DISP_16, REG_2&31); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.r[REG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
// Post-debugging macro for floating-point load/store instructions.
#define POST_FMEM \
POST_X64(state.f[FREG_1]);
// Pre-debugging macro for floating-point instructions that have Fb as input
// And Fc as output.
#define PRE_F2_F3(mnemonic) \
if (bDisassemble) { \
DEBUG_XX; \
sprintf(dbg_strptr, #mnemonic " f%d, f%d", FREG_2, FREG_3); \
dbg_strptr += strlen(dbg_strptr); \
if (!bListing) { \
sprintf(dbg_strptr,": (%" LL "x)", state.f[FREG_2]); \
dbg_strptr += strlen(dbg_strptr); \
} \
}
// Post-debugging macro for floating-point instructions that have Fb as input
// And Fc as output.
#define POST_F2_F3 \
POST_X64(state.f[FREG_3]);
#else
#define UNKNOWN1 \
printf("Unknown opcode: %02x \n", opcode); \
return 0;
#define UNKNOWN2 \
printf("Unknown opcode: %02x.%02x \n", opcode, function); \
return 0;
#endif
#if defined(IDB)
// Debugging version of the OP macro:
// Execute the DO_<mnemonic> macro for an instruction, along with disassembling
// the instruction if needed.
#define OP(mnemonic, format) \
PRE_##format(mnemonic); \
if (!bListing) { \
DO_##mnemonic; \
} \
POST_##format; \
handle_debug_string(dbg_string); \
return 0;
// Execute a function rather than a DO_<mnemonic> macro for an instruction
#define OP_FNC(mnemonic, format) \
PRE_##format(mnemonic); \
if (!bListing) { \
mnemonic(); \
} \
POST_##format; \
handle_debug_string(dbg_string); \
return 0;
#else //defined(IDB)
// Non-debugging version of the OP macro:
// Execute the DO_<mnemonic> macro for an instruction.
#define OP(mnemonic, format) \
DO_##mnemonic; \
return 0;
// Execute a function rather than a DO_<mnemonic> macro for an instruction
#define OP_FNC(mnemonic, format) \
mnemonic(); \
return 0;
#endif //defined(IDB)