4 typedef signed char INT8;
5 typedef signed short INT16;
6 typedef signed int INT32;
7 typedef unsigned int UINT32;
8 typedef unsigned short UINT16;
9 typedef unsigned char UINT8;
11 #define RB(a) p32x_sh2_read8(a,sh2)
12 #define RW(a) p32x_sh2_read16(a,sh2)
13 #define RL(a) p32x_sh2_read32(a,sh2)
14 #define WB(a,d) p32x_sh2_write8(a,d,sh2)
15 #define WW(a,d) p32x_sh2_write16(a,d,sh2)
16 #define WL(a,d) p32x_sh2_write32(a,d,sh2)
18 // some stuff from sh2comn.h
27 #define FLAGS (M|Q|I|S|T)
29 #define Rn ((opcode>>8)&15)
30 #define Rm ((opcode>>4)&15)
32 #define sh2_icount sh2->icount
36 static unsigned int op_refs[0x10000];
39 # define LRNM (LRN|LRM)
40 # define rlog(rnm) { \
52 # define rlog1(x) sh2_stats.r[x]++
53 # define rlog2(x1,x2) sh2_stats.r[x1]++; sh2_stats.r[x2]++
64 int sh2_execute(SH2 *sh2_, int cycles)
72 sh2->cycles_timeslice = cycles;
80 sh2->ppc = sh2->delay;
81 opcode = RW(sh2->delay);
93 switch (opcode & ( 15 << 12))
95 case 0<<12: op0000(opcode); break;
96 case 1<<12: op0001(opcode); break;
97 case 2<<12: op0010(opcode); break;
98 case 3<<12: op0011(opcode); break;
99 case 4<<12: op0100(opcode); break;
100 case 5<<12: op0101(opcode); break;
101 case 6<<12: op0110(opcode); break;
102 case 7<<12: op0111(opcode); break;
103 case 8<<12: op1000(opcode); break;
104 case 9<<12: op1001(opcode); break;
105 case 10<<12: op1010(opcode); break;
106 case 11<<12: op1011(opcode); break;
107 case 12<<12: op1100(opcode); break;
108 case 13<<12: op1101(opcode); break;
109 case 14<<12: op1110(opcode); break;
110 default: op1111(opcode); break;
115 if (sh2->test_irq && !sh2->delay && sh2->pending_level > ((sh2->sr >> 4) & 0x0f))
117 int level = sh2->pending_level;
118 int vector = sh2->irq_callback(sh2, level);
119 sh2_do_irq(sh2, level, vector);
124 while (sh2->icount > 0 || sh2->delay); /* can't interrupt before delay */
126 return sh2->cycles_timeslice - sh2->icount;
132 #define REGPARM(x) __attribute__((regparm(x)))
138 void REGPARM(2) sh2_do_op(SH2 *sh2_, int opcode)
143 switch (opcode & ( 15 << 12))
145 case 0<<12: op0000(opcode); break;
146 case 1<<12: op0001(opcode); break;
147 case 2<<12: op0010(opcode); break;
148 case 3<<12: op0011(opcode); break;
149 case 4<<12: op0100(opcode); break;
150 case 5<<12: op0101(opcode); break;
151 case 6<<12: op0110(opcode); break;
152 case 7<<12: op0111(opcode); break;
153 case 8<<12: op1000(opcode); break;
154 case 9<<12: op1001(opcode); break;
155 case 10<<12: op1010(opcode); break;
156 case 11<<12: op1011(opcode); break;
157 case 12<<12: op1100(opcode); break;
158 case 13<<12: op1101(opcode); break;
159 case 14<<12: op1110(opcode); break;
160 default: op1111(opcode); break;
171 void sh2_dump_stats(void)
173 static const char *rnames[] = {
174 "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7",
175 "R8", "R9", "R10", "R11", "R12", "R13", "R14", "SP",
176 "PC", "", "PR", "SR", "GBR", "VBR", "MACH", "MACL"
184 for (i = 0; i < 24; i++)
185 total += sh2_stats.r[i];
187 for (i = 0; i < 24; i++) {
188 if (i == 16 || i == 17 || i == 19)
190 printf("r %6.3f%% %-4s %9d\n", (double)sh2_stats.r[i] * 100.0 / total,
191 rnames[i], sh2_stats.r[i]);
194 memset(&sh2_stats, 0, sizeof(sh2_stats));
199 for (i = 0; i < 0x10000; i++)
202 for (u = 0; u < 16; u++) {
204 for (i = 0; i < 0x10000; i++) {
205 if (op_refs[i] > max) {
210 DasmSH2(buff, 0, op);
211 printf("i %6.3f%% %9d %s\n", (double)op_refs[op] * 100.0 / total,
215 memset(op_refs, 0, sizeof(op_refs));