1 |
cebix |
1.1 |
/* |
2 |
|
|
* UAE - The Un*x Amiga Emulator |
3 |
|
|
* |
4 |
|
|
* MC68000 emulation |
5 |
|
|
* |
6 |
|
|
* (c) 1995 Bernd Schmidt |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
#include <stdio.h> |
10 |
|
|
#include <stdlib.h> |
11 |
|
|
#include <string.h> |
12 |
|
|
|
13 |
|
|
#include "sysdeps.h" |
14 |
|
|
|
15 |
|
|
#include "cpu_emulation.h" |
16 |
|
|
#include "main.h" |
17 |
|
|
#include "emul_op.h" |
18 |
|
|
|
19 |
|
|
extern int intlev(void); // From baisilisk_glue.cpp |
20 |
|
|
|
21 |
|
|
#include "m68k.h" |
22 |
|
|
#include "memory.h" |
23 |
|
|
#include "readcpu.h" |
24 |
|
|
#include "newcpu.h" |
25 |
|
|
#include "compiler.h" |
26 |
|
|
|
27 |
|
|
int quit_program = 0; |
28 |
|
|
int debugging = 0; |
29 |
|
|
struct flag_struct regflags; |
30 |
|
|
|
31 |
|
|
/* Opcode of faulting instruction */ |
32 |
|
|
uae_u16 last_op_for_exception_3; |
33 |
|
|
/* PC at fault time */ |
34 |
|
|
uaecptr last_addr_for_exception_3; |
35 |
|
|
/* Address that generated the exception */ |
36 |
|
|
uaecptr last_fault_for_exception_3; |
37 |
|
|
|
38 |
|
|
int areg_byteinc[] = { 1,1,1,1,1,1,1,2 }; |
39 |
|
|
int imm8_table[] = { 8,1,2,3,4,5,6,7 }; |
40 |
|
|
|
41 |
|
|
int movem_index1[256]; |
42 |
|
|
int movem_index2[256]; |
43 |
|
|
int movem_next[256]; |
44 |
|
|
|
45 |
|
|
int fpp_movem_index1[256]; |
46 |
|
|
int fpp_movem_index2[256]; |
47 |
|
|
int fpp_movem_next[256]; |
48 |
|
|
|
49 |
|
|
cpuop_func *cpufunctbl[65536]; |
50 |
|
|
|
51 |
|
|
#define COUNT_INSTRS 0 |
52 |
|
|
|
53 |
|
|
#if COUNT_INSTRS |
54 |
|
|
static unsigned long int instrcount[65536]; |
55 |
|
|
static uae_u16 opcodenums[65536]; |
56 |
|
|
|
57 |
|
|
static int compfn (const void *el1, const void *el2) |
58 |
|
|
{ |
59 |
|
|
return instrcount[*(const uae_u16 *)el1] < instrcount[*(const uae_u16 *)el2]; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
static char *icountfilename (void) |
63 |
|
|
{ |
64 |
|
|
char *name = getenv ("INSNCOUNT"); |
65 |
|
|
if (name) |
66 |
|
|
return name; |
67 |
|
|
return COUNT_INSTRS == 2 ? "frequent.68k" : "insncount"; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
void dump_counts (void) |
71 |
|
|
{ |
72 |
|
|
FILE *f = fopen (icountfilename (), "w"); |
73 |
|
|
unsigned long int total; |
74 |
|
|
int i; |
75 |
|
|
|
76 |
|
|
write_log ("Writing instruction count file...\n"); |
77 |
|
|
for (i = 0; i < 65536; i++) { |
78 |
|
|
opcodenums[i] = i; |
79 |
|
|
total += instrcount[i]; |
80 |
|
|
} |
81 |
|
|
qsort (opcodenums, 65536, sizeof(uae_u16), compfn); |
82 |
|
|
|
83 |
|
|
fprintf (f, "Total: %lu\n", total); |
84 |
|
|
for (i=0; i < 65536; i++) { |
85 |
|
|
unsigned long int cnt = instrcount[opcodenums[i]]; |
86 |
|
|
struct instr *dp; |
87 |
|
|
struct mnemolookup *lookup; |
88 |
|
|
if (!cnt) |
89 |
|
|
break; |
90 |
|
|
dp = table68k + opcodenums[i]; |
91 |
|
|
for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) |
92 |
|
|
; |
93 |
|
|
fprintf (f, "%04x: %lu %s\n", opcodenums[i], cnt, lookup->name); |
94 |
|
|
} |
95 |
|
|
fclose (f); |
96 |
|
|
} |
97 |
|
|
#else |
98 |
|
|
void dump_counts (void) |
99 |
|
|
{ |
100 |
|
|
} |
101 |
|
|
#endif |
102 |
|
|
|
103 |
|
|
int broken_in; |
104 |
|
|
|
105 |
|
|
static __inline__ unsigned int cft_map (unsigned int f) |
106 |
|
|
{ |
107 |
|
|
#ifndef HAVE_GET_WORD_UNSWAPPED |
108 |
|
|
return f; |
109 |
|
|
#else |
110 |
|
|
return ((f >> 8) & 255) | ((f & 255) << 8); |
111 |
|
|
#endif |
112 |
|
|
} |
113 |
|
|
|
114 |
cebix |
1.4 |
static void REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM; |
115 |
cebix |
1.1 |
|
116 |
cebix |
1.4 |
static void REGPARAM2 op_illg_1 (uae_u32 opcode) |
117 |
cebix |
1.1 |
{ |
118 |
|
|
op_illg (cft_map (opcode)); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
static void build_cpufunctbl (void) |
122 |
|
|
{ |
123 |
|
|
int i; |
124 |
|
|
unsigned long opcode; |
125 |
cebix |
1.2 |
int cpu_level = 0; // 68000 (default) |
126 |
|
|
if (CPUType == 4) |
127 |
|
|
cpu_level = 4; // 68040 with FPU |
128 |
|
|
else { |
129 |
|
|
if (FPUType) |
130 |
|
|
cpu_level = 3; // 68020 with FPU |
131 |
|
|
else if (CPUType >= 2) |
132 |
|
|
cpu_level = 2; // 68020 |
133 |
|
|
else if (CPUType == 1) |
134 |
|
|
cpu_level = 1; |
135 |
|
|
} |
136 |
|
|
struct cputbl *tbl = ( |
137 |
|
|
cpu_level == 4 ? op_smalltbl_0 |
138 |
|
|
: cpu_level == 3 ? op_smalltbl_1 |
139 |
|
|
: cpu_level == 2 ? op_smalltbl_2 |
140 |
|
|
: cpu_level == 1 ? op_smalltbl_3 |
141 |
|
|
: op_smalltbl_4); |
142 |
cebix |
1.1 |
|
143 |
|
|
for (opcode = 0; opcode < 65536; opcode++) |
144 |
|
|
cpufunctbl[cft_map (opcode)] = op_illg_1; |
145 |
|
|
for (i = 0; tbl[i].handler != NULL; i++) { |
146 |
|
|
if (! tbl[i].specific) |
147 |
|
|
cpufunctbl[cft_map (tbl[i].opcode)] = tbl[i].handler; |
148 |
|
|
} |
149 |
|
|
for (opcode = 0; opcode < 65536; opcode++) { |
150 |
|
|
cpuop_func *f; |
151 |
|
|
|
152 |
|
|
if (table68k[opcode].mnemo == i_ILLG || table68k[opcode].clev > cpu_level) |
153 |
|
|
continue; |
154 |
|
|
|
155 |
|
|
if (table68k[opcode].handler != -1) { |
156 |
|
|
f = cpufunctbl[cft_map (table68k[opcode].handler)]; |
157 |
|
|
if (f == op_illg_1) |
158 |
|
|
abort(); |
159 |
|
|
cpufunctbl[cft_map (opcode)] = f; |
160 |
|
|
} |
161 |
|
|
} |
162 |
|
|
for (i = 0; tbl[i].handler != NULL; i++) { |
163 |
|
|
if (tbl[i].specific) |
164 |
|
|
cpufunctbl[cft_map (tbl[i].opcode)] = tbl[i].handler; |
165 |
|
|
} |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
void init_m68k (void) |
169 |
|
|
{ |
170 |
|
|
int i; |
171 |
|
|
|
172 |
|
|
for (i = 0 ; i < 256 ; i++) { |
173 |
|
|
int j; |
174 |
|
|
for (j = 0 ; j < 8 ; j++) { |
175 |
|
|
if (i & (1 << j)) break; |
176 |
|
|
} |
177 |
|
|
movem_index1[i] = j; |
178 |
|
|
movem_index2[i] = 7-j; |
179 |
|
|
movem_next[i] = i & (~(1 << j)); |
180 |
|
|
} |
181 |
|
|
for (i = 0 ; i < 256 ; i++) { |
182 |
|
|
int j; |
183 |
|
|
for (j = 7 ; j >= 0 ; j--) { |
184 |
|
|
if (i & (1 << j)) break; |
185 |
|
|
} |
186 |
|
|
fpp_movem_index1[i] = j; |
187 |
|
|
fpp_movem_index2[i] = 7-j; |
188 |
|
|
fpp_movem_next[i] = i & (~(1 << j)); |
189 |
|
|
} |
190 |
|
|
#if COUNT_INSTRS |
191 |
|
|
{ |
192 |
|
|
FILE *f = fopen (icountfilename (), "r"); |
193 |
|
|
memset (instrcount, 0, sizeof instrcount); |
194 |
|
|
if (f) { |
195 |
|
|
uae_u32 opcode, count, total; |
196 |
|
|
char name[20]; |
197 |
|
|
write_log ("Reading instruction count file...\n"); |
198 |
|
|
fscanf (f, "Total: %lu\n", &total); |
199 |
|
|
while (fscanf (f, "%lx: %lu %s\n", &opcode, &count, name) == 3) { |
200 |
|
|
instrcount[opcode] = count; |
201 |
|
|
} |
202 |
|
|
fclose(f); |
203 |
|
|
} |
204 |
|
|
} |
205 |
|
|
#endif |
206 |
|
|
read_table68k (); |
207 |
|
|
do_merges (); |
208 |
|
|
|
209 |
|
|
build_cpufunctbl (); |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
struct regstruct regs, lastint_regs; |
213 |
|
|
static struct regstruct regs_backup[16]; |
214 |
|
|
static int backup_pointer = 0; |
215 |
|
|
static long int m68kpc_offset; |
216 |
|
|
int lastint_no; |
217 |
|
|
|
218 |
|
|
#define get_ibyte_1(o) get_byte(regs.pc + (regs.pc_p - regs.pc_oldp) + (o) + 1) |
219 |
|
|
#define get_iword_1(o) get_word(regs.pc + (regs.pc_p - regs.pc_oldp) + (o)) |
220 |
|
|
#define get_ilong_1(o) get_long(regs.pc + (regs.pc_p - regs.pc_oldp) + (o)) |
221 |
|
|
|
222 |
|
|
uae_s32 ShowEA (int reg, amodes mode, wordsizes size, char *buf) |
223 |
|
|
{ |
224 |
|
|
uae_u16 dp; |
225 |
|
|
uae_s8 disp8; |
226 |
|
|
uae_s16 disp16; |
227 |
|
|
int r; |
228 |
|
|
uae_u32 dispreg; |
229 |
|
|
uaecptr addr; |
230 |
|
|
uae_s32 offset = 0; |
231 |
|
|
char buffer[80]; |
232 |
|
|
|
233 |
|
|
switch (mode){ |
234 |
|
|
case Dreg: |
235 |
|
|
sprintf (buffer,"D%d", reg); |
236 |
|
|
break; |
237 |
|
|
case Areg: |
238 |
|
|
sprintf (buffer,"A%d", reg); |
239 |
|
|
break; |
240 |
|
|
case Aind: |
241 |
|
|
sprintf (buffer,"(A%d)", reg); |
242 |
|
|
break; |
243 |
|
|
case Aipi: |
244 |
|
|
sprintf (buffer,"(A%d)+", reg); |
245 |
|
|
break; |
246 |
|
|
case Apdi: |
247 |
|
|
sprintf (buffer,"-(A%d)", reg); |
248 |
|
|
break; |
249 |
|
|
case Ad16: |
250 |
|
|
disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; |
251 |
|
|
addr = m68k_areg(regs,reg) + (uae_s16)disp16; |
252 |
|
|
sprintf (buffer,"(A%d,$%04x) == $%08lx", reg, disp16 & 0xffff, |
253 |
|
|
(long unsigned int)addr); |
254 |
|
|
break; |
255 |
|
|
case Ad8r: |
256 |
|
|
dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; |
257 |
|
|
disp8 = dp & 0xFF; |
258 |
|
|
r = (dp & 0x7000) >> 12; |
259 |
|
|
dispreg = dp & 0x8000 ? m68k_areg(regs,r) : m68k_dreg(regs,r); |
260 |
|
|
if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); |
261 |
|
|
dispreg <<= (dp >> 9) & 3; |
262 |
|
|
|
263 |
|
|
if (dp & 0x100) { |
264 |
|
|
uae_s32 outer = 0, disp = 0; |
265 |
|
|
uae_s32 base = m68k_areg(regs,reg); |
266 |
|
|
char name[10]; |
267 |
|
|
sprintf (name,"A%d, ",reg); |
268 |
|
|
if (dp & 0x80) { base = 0; name[0] = 0; } |
269 |
|
|
if (dp & 0x40) dispreg = 0; |
270 |
|
|
if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } |
271 |
|
|
if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } |
272 |
|
|
base += disp; |
273 |
|
|
|
274 |
|
|
if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } |
275 |
|
|
if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } |
276 |
|
|
|
277 |
|
|
if (!(dp & 4)) base += dispreg; |
278 |
|
|
if (dp & 3) base = get_long (base); |
279 |
|
|
if (dp & 4) base += dispreg; |
280 |
|
|
|
281 |
|
|
addr = base + outer; |
282 |
|
|
sprintf (buffer,"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, |
283 |
|
|
dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', |
284 |
|
|
1 << ((dp >> 9) & 3), |
285 |
|
|
disp,outer, |
286 |
|
|
(long unsigned int)addr); |
287 |
|
|
} else { |
288 |
|
|
addr = m68k_areg(regs,reg) + (uae_s32)((uae_s8)disp8) + dispreg; |
289 |
|
|
sprintf (buffer,"(A%d, %c%d.%c*%d, $%02x) == $%08lx", reg, |
290 |
|
|
dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', |
291 |
|
|
1 << ((dp >> 9) & 3), disp8, |
292 |
|
|
(long unsigned int)addr); |
293 |
|
|
} |
294 |
|
|
break; |
295 |
|
|
case PC16: |
296 |
|
|
addr = m68k_getpc () + m68kpc_offset; |
297 |
|
|
disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; |
298 |
|
|
addr += (uae_s16)disp16; |
299 |
|
|
sprintf (buffer,"(PC,$%04x) == $%08lx", disp16 & 0xffff,(long unsigned int)addr); |
300 |
|
|
break; |
301 |
|
|
case PC8r: |
302 |
|
|
addr = m68k_getpc () + m68kpc_offset; |
303 |
|
|
dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; |
304 |
|
|
disp8 = dp & 0xFF; |
305 |
|
|
r = (dp & 0x7000) >> 12; |
306 |
|
|
dispreg = dp & 0x8000 ? m68k_areg(regs,r) : m68k_dreg(regs,r); |
307 |
|
|
if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); |
308 |
|
|
dispreg <<= (dp >> 9) & 3; |
309 |
|
|
|
310 |
|
|
if (dp & 0x100) { |
311 |
|
|
uae_s32 outer = 0,disp = 0; |
312 |
|
|
uae_s32 base = addr; |
313 |
|
|
char name[10]; |
314 |
|
|
sprintf (name,"PC, "); |
315 |
|
|
if (dp & 0x80) { base = 0; name[0] = 0; } |
316 |
|
|
if (dp & 0x40) dispreg = 0; |
317 |
|
|
if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } |
318 |
|
|
if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } |
319 |
|
|
base += disp; |
320 |
|
|
|
321 |
|
|
if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } |
322 |
|
|
if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } |
323 |
|
|
|
324 |
|
|
if (!(dp & 4)) base += dispreg; |
325 |
|
|
if (dp & 3) base = get_long (base); |
326 |
|
|
if (dp & 4) base += dispreg; |
327 |
|
|
|
328 |
|
|
addr = base + outer; |
329 |
|
|
sprintf (buffer,"(%s%c%d.%c*%d+%ld)+%ld == $%08lx", name, |
330 |
|
|
dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W', |
331 |
|
|
1 << ((dp >> 9) & 3), |
332 |
|
|
disp,outer, |
333 |
|
|
(long unsigned int)addr); |
334 |
|
|
} else { |
335 |
|
|
addr += (uae_s32)((uae_s8)disp8) + dispreg; |
336 |
|
|
sprintf (buffer,"(PC, %c%d.%c*%d, $%02x) == $%08lx", dp & 0x8000 ? 'A' : 'D', |
337 |
|
|
(int)r, dp & 0x800 ? 'L' : 'W', 1 << ((dp >> 9) & 3), |
338 |
|
|
disp8, (long unsigned int)addr); |
339 |
|
|
} |
340 |
|
|
break; |
341 |
|
|
case absw: |
342 |
|
|
sprintf (buffer,"$%08lx", (long unsigned int)(uae_s32)(uae_s16)get_iword_1 (m68kpc_offset)); |
343 |
|
|
m68kpc_offset += 2; |
344 |
|
|
break; |
345 |
|
|
case absl: |
346 |
|
|
sprintf (buffer,"$%08lx", (long unsigned int)get_ilong_1 (m68kpc_offset)); |
347 |
|
|
m68kpc_offset += 4; |
348 |
|
|
break; |
349 |
|
|
case imm: |
350 |
|
|
switch (size){ |
351 |
|
|
case sz_byte: |
352 |
|
|
sprintf (buffer,"#$%02x", (unsigned int)(get_iword_1 (m68kpc_offset) & 0xff)); |
353 |
|
|
m68kpc_offset += 2; |
354 |
|
|
break; |
355 |
|
|
case sz_word: |
356 |
|
|
sprintf (buffer,"#$%04x", (unsigned int)(get_iword_1 (m68kpc_offset) & 0xffff)); |
357 |
|
|
m68kpc_offset += 2; |
358 |
|
|
break; |
359 |
|
|
case sz_long: |
360 |
|
|
sprintf (buffer,"#$%08lx", (long unsigned int)(get_ilong_1 (m68kpc_offset))); |
361 |
|
|
m68kpc_offset += 4; |
362 |
|
|
break; |
363 |
|
|
default: |
364 |
|
|
break; |
365 |
|
|
} |
366 |
|
|
break; |
367 |
|
|
case imm0: |
368 |
|
|
offset = (uae_s32)(uae_s8)get_iword_1 (m68kpc_offset); |
369 |
|
|
m68kpc_offset += 2; |
370 |
|
|
sprintf (buffer,"#$%02x", (unsigned int)(offset & 0xff)); |
371 |
|
|
break; |
372 |
|
|
case imm1: |
373 |
|
|
offset = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); |
374 |
|
|
m68kpc_offset += 2; |
375 |
|
|
sprintf (buffer,"#$%04x", (unsigned int)(offset & 0xffff)); |
376 |
|
|
break; |
377 |
|
|
case imm2: |
378 |
|
|
offset = (uae_s32)get_ilong_1 (m68kpc_offset); |
379 |
|
|
m68kpc_offset += 4; |
380 |
|
|
sprintf (buffer,"#$%08lx", (long unsigned int)offset); |
381 |
|
|
break; |
382 |
|
|
case immi: |
383 |
|
|
offset = (uae_s32)(uae_s8)(reg & 0xff); |
384 |
|
|
sprintf (buffer,"#$%08lx", (long unsigned int)offset); |
385 |
|
|
break; |
386 |
|
|
default: |
387 |
|
|
break; |
388 |
|
|
} |
389 |
|
|
if (buf == 0) |
390 |
|
|
printf ("%s", buffer); |
391 |
|
|
else |
392 |
|
|
strcat (buf, buffer); |
393 |
|
|
return offset; |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
/* The plan is that this will take over the job of exception 3 handling - |
397 |
|
|
* the CPU emulation functions will just do a longjmp to m68k_go whenever |
398 |
|
|
* they hit an odd address. */ |
399 |
|
|
static int verify_ea (int reg, amodes mode, wordsizes size, uae_u32 *val) |
400 |
|
|
{ |
401 |
|
|
uae_u16 dp; |
402 |
|
|
uae_s8 disp8; |
403 |
|
|
uae_s16 disp16; |
404 |
|
|
int r; |
405 |
|
|
uae_u32 dispreg; |
406 |
|
|
uaecptr addr; |
407 |
|
|
uae_s32 offset = 0; |
408 |
|
|
|
409 |
|
|
switch (mode){ |
410 |
|
|
case Dreg: |
411 |
|
|
*val = m68k_dreg (regs, reg); |
412 |
|
|
return 1; |
413 |
|
|
case Areg: |
414 |
|
|
*val = m68k_areg (regs, reg); |
415 |
|
|
return 1; |
416 |
|
|
|
417 |
|
|
case Aind: |
418 |
|
|
case Aipi: |
419 |
|
|
addr = m68k_areg (regs, reg); |
420 |
|
|
break; |
421 |
|
|
case Apdi: |
422 |
|
|
addr = m68k_areg (regs, reg); |
423 |
|
|
break; |
424 |
|
|
case Ad16: |
425 |
|
|
disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; |
426 |
|
|
addr = m68k_areg(regs,reg) + (uae_s16)disp16; |
427 |
|
|
break; |
428 |
|
|
case Ad8r: |
429 |
|
|
addr = m68k_areg (regs, reg); |
430 |
|
|
d8r_common: |
431 |
|
|
dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; |
432 |
|
|
disp8 = dp & 0xFF; |
433 |
|
|
r = (dp & 0x7000) >> 12; |
434 |
|
|
dispreg = dp & 0x8000 ? m68k_areg(regs,r) : m68k_dreg(regs,r); |
435 |
|
|
if (!(dp & 0x800)) dispreg = (uae_s32)(uae_s16)(dispreg); |
436 |
|
|
dispreg <<= (dp >> 9) & 3; |
437 |
|
|
|
438 |
|
|
if (dp & 0x100) { |
439 |
|
|
uae_s32 outer = 0, disp = 0; |
440 |
|
|
uae_s32 base = addr; |
441 |
|
|
if (dp & 0x80) base = 0; |
442 |
|
|
if (dp & 0x40) dispreg = 0; |
443 |
|
|
if ((dp & 0x30) == 0x20) { disp = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } |
444 |
|
|
if ((dp & 0x30) == 0x30) { disp = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } |
445 |
|
|
base += disp; |
446 |
|
|
|
447 |
|
|
if ((dp & 0x3) == 0x2) { outer = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); m68kpc_offset += 2; } |
448 |
|
|
if ((dp & 0x3) == 0x3) { outer = get_ilong_1 (m68kpc_offset); m68kpc_offset += 4; } |
449 |
|
|
|
450 |
|
|
if (!(dp & 4)) base += dispreg; |
451 |
|
|
if (dp & 3) base = get_long (base); |
452 |
|
|
if (dp & 4) base += dispreg; |
453 |
|
|
|
454 |
|
|
addr = base + outer; |
455 |
|
|
} else { |
456 |
|
|
addr += (uae_s32)((uae_s8)disp8) + dispreg; |
457 |
|
|
} |
458 |
|
|
break; |
459 |
|
|
case PC16: |
460 |
|
|
addr = m68k_getpc () + m68kpc_offset; |
461 |
|
|
disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2; |
462 |
|
|
addr += (uae_s16)disp16; |
463 |
|
|
break; |
464 |
|
|
case PC8r: |
465 |
|
|
addr = m68k_getpc () + m68kpc_offset; |
466 |
|
|
goto d8r_common; |
467 |
|
|
case absw: |
468 |
|
|
addr = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); |
469 |
|
|
m68kpc_offset += 2; |
470 |
|
|
break; |
471 |
|
|
case absl: |
472 |
|
|
addr = get_ilong_1 (m68kpc_offset); |
473 |
|
|
m68kpc_offset += 4; |
474 |
|
|
break; |
475 |
|
|
case imm: |
476 |
|
|
switch (size){ |
477 |
|
|
case sz_byte: |
478 |
|
|
*val = get_iword_1 (m68kpc_offset) & 0xff; |
479 |
|
|
m68kpc_offset += 2; |
480 |
|
|
break; |
481 |
|
|
case sz_word: |
482 |
|
|
*val = get_iword_1 (m68kpc_offset) & 0xffff; |
483 |
|
|
m68kpc_offset += 2; |
484 |
|
|
break; |
485 |
|
|
case sz_long: |
486 |
|
|
*val = get_ilong_1 (m68kpc_offset); |
487 |
|
|
m68kpc_offset += 4; |
488 |
|
|
break; |
489 |
|
|
default: |
490 |
|
|
break; |
491 |
|
|
} |
492 |
|
|
return 1; |
493 |
|
|
case imm0: |
494 |
|
|
*val = (uae_s32)(uae_s8)get_iword_1 (m68kpc_offset); |
495 |
|
|
m68kpc_offset += 2; |
496 |
|
|
return 1; |
497 |
|
|
case imm1: |
498 |
|
|
*val = (uae_s32)(uae_s16)get_iword_1 (m68kpc_offset); |
499 |
|
|
m68kpc_offset += 2; |
500 |
|
|
return 1; |
501 |
|
|
case imm2: |
502 |
|
|
*val = get_ilong_1 (m68kpc_offset); |
503 |
|
|
m68kpc_offset += 4; |
504 |
|
|
return 1; |
505 |
|
|
case immi: |
506 |
|
|
*val = (uae_s32)(uae_s8)(reg & 0xff); |
507 |
|
|
return 1; |
508 |
|
|
default: |
509 |
|
|
addr = 0; |
510 |
|
|
break; |
511 |
|
|
} |
512 |
|
|
if ((addr & 1) == 0) |
513 |
|
|
return 1; |
514 |
|
|
|
515 |
|
|
last_addr_for_exception_3 = m68k_getpc () + m68kpc_offset; |
516 |
|
|
last_fault_for_exception_3 = addr; |
517 |
|
|
return 0; |
518 |
|
|
} |
519 |
|
|
|
520 |
|
|
uae_u32 get_disp_ea_020 (uae_u32 base, uae_u32 dp) |
521 |
|
|
{ |
522 |
|
|
int reg = (dp >> 12) & 15; |
523 |
|
|
uae_s32 regd = regs.regs[reg]; |
524 |
|
|
if ((dp & 0x800) == 0) |
525 |
|
|
regd = (uae_s32)(uae_s16)regd; |
526 |
|
|
regd <<= (dp >> 9) & 3; |
527 |
|
|
if (dp & 0x100) { |
528 |
|
|
uae_s32 outer = 0; |
529 |
|
|
if (dp & 0x80) base = 0; |
530 |
|
|
if (dp & 0x40) regd = 0; |
531 |
|
|
|
532 |
|
|
if ((dp & 0x30) == 0x20) base += (uae_s32)(uae_s16)next_iword(); |
533 |
|
|
if ((dp & 0x30) == 0x30) base += next_ilong(); |
534 |
|
|
|
535 |
|
|
if ((dp & 0x3) == 0x2) outer = (uae_s32)(uae_s16)next_iword(); |
536 |
|
|
if ((dp & 0x3) == 0x3) outer = next_ilong(); |
537 |
|
|
|
538 |
|
|
if ((dp & 0x4) == 0) base += regd; |
539 |
|
|
if (dp & 0x3) base = get_long (base); |
540 |
|
|
if (dp & 0x4) base += regd; |
541 |
|
|
|
542 |
|
|
return base + outer; |
543 |
|
|
} else { |
544 |
|
|
return base + (uae_s32)((uae_s8)dp) + regd; |
545 |
|
|
} |
546 |
|
|
} |
547 |
|
|
|
548 |
|
|
uae_u32 get_disp_ea_000 (uae_u32 base, uae_u32 dp) |
549 |
|
|
{ |
550 |
|
|
int reg = (dp >> 12) & 15; |
551 |
|
|
uae_s32 regd = regs.regs[reg]; |
552 |
|
|
#if 1 |
553 |
|
|
if ((dp & 0x800) == 0) |
554 |
|
|
regd = (uae_s32)(uae_s16)regd; |
555 |
|
|
return base + (uae_s8)dp + regd; |
556 |
|
|
#else |
557 |
|
|
/* Branch-free code... benchmark this again now that |
558 |
|
|
* things are no longer inline. */ |
559 |
|
|
uae_s32 regd16; |
560 |
|
|
uae_u32 mask; |
561 |
|
|
mask = ((dp & 0x800) >> 11) - 1; |
562 |
|
|
regd16 = (uae_s32)(uae_s16)regd; |
563 |
|
|
regd16 &= mask; |
564 |
|
|
mask = ~mask; |
565 |
|
|
base += (uae_s8)dp; |
566 |
|
|
regd &= mask; |
567 |
|
|
regd |= regd16; |
568 |
|
|
return base + regd; |
569 |
|
|
#endif |
570 |
|
|
} |
571 |
|
|
|
572 |
|
|
void MakeSR (void) |
573 |
|
|
{ |
574 |
|
|
#if 0 |
575 |
|
|
assert((regs.t1 & 1) == regs.t1); |
576 |
|
|
assert((regs.t0 & 1) == regs.t0); |
577 |
|
|
assert((regs.s & 1) == regs.s); |
578 |
|
|
assert((regs.m & 1) == regs.m); |
579 |
|
|
assert((XFLG & 1) == XFLG); |
580 |
|
|
assert((NFLG & 1) == NFLG); |
581 |
|
|
assert((ZFLG & 1) == ZFLG); |
582 |
|
|
assert((VFLG & 1) == VFLG); |
583 |
|
|
assert((CFLG & 1) == CFLG); |
584 |
|
|
#endif |
585 |
|
|
regs.sr = ((regs.t1 << 15) | (regs.t0 << 14) |
586 |
|
|
| (regs.s << 13) | (regs.m << 12) | (regs.intmask << 8) |
587 |
|
|
| (GET_XFLG << 4) | (GET_NFLG << 3) | (GET_ZFLG << 2) | (GET_VFLG << 1) |
588 |
|
|
| GET_CFLG); |
589 |
|
|
} |
590 |
|
|
|
591 |
|
|
void MakeFromSR (void) |
592 |
|
|
{ |
593 |
|
|
int oldm = regs.m; |
594 |
|
|
int olds = regs.s; |
595 |
|
|
|
596 |
|
|
regs.t1 = (regs.sr >> 15) & 1; |
597 |
|
|
regs.t0 = (regs.sr >> 14) & 1; |
598 |
|
|
regs.s = (regs.sr >> 13) & 1; |
599 |
|
|
regs.m = (regs.sr >> 12) & 1; |
600 |
|
|
regs.intmask = (regs.sr >> 8) & 7; |
601 |
|
|
SET_XFLG ((regs.sr >> 4) & 1); |
602 |
|
|
SET_NFLG ((regs.sr >> 3) & 1); |
603 |
|
|
SET_ZFLG ((regs.sr >> 2) & 1); |
604 |
|
|
SET_VFLG ((regs.sr >> 1) & 1); |
605 |
|
|
SET_CFLG (regs.sr & 1); |
606 |
|
|
if (CPUType >= 2) { |
607 |
|
|
if (olds != regs.s) { |
608 |
|
|
if (olds) { |
609 |
|
|
if (oldm) |
610 |
|
|
regs.msp = m68k_areg(regs, 7); |
611 |
|
|
else |
612 |
|
|
regs.isp = m68k_areg(regs, 7); |
613 |
|
|
m68k_areg(regs, 7) = regs.usp; |
614 |
|
|
} else { |
615 |
|
|
regs.usp = m68k_areg(regs, 7); |
616 |
|
|
m68k_areg(regs, 7) = regs.m ? regs.msp : regs.isp; |
617 |
|
|
} |
618 |
|
|
} else if (olds && oldm != regs.m) { |
619 |
|
|
if (oldm) { |
620 |
|
|
regs.msp = m68k_areg(regs, 7); |
621 |
|
|
m68k_areg(regs, 7) = regs.isp; |
622 |
|
|
} else { |
623 |
|
|
regs.isp = m68k_areg(regs, 7); |
624 |
|
|
m68k_areg(regs, 7) = regs.msp; |
625 |
|
|
} |
626 |
|
|
} |
627 |
|
|
} else { |
628 |
|
|
if (olds != regs.s) { |
629 |
|
|
if (olds) { |
630 |
|
|
regs.isp = m68k_areg(regs, 7); |
631 |
|
|
m68k_areg(regs, 7) = regs.usp; |
632 |
|
|
} else { |
633 |
|
|
regs.usp = m68k_areg(regs, 7); |
634 |
|
|
m68k_areg(regs, 7) = regs.isp; |
635 |
|
|
} |
636 |
|
|
} |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
regs.spcflags |= SPCFLAG_INT; |
640 |
|
|
if (regs.t1 || regs.t0) |
641 |
|
|
regs.spcflags |= SPCFLAG_TRACE; |
642 |
|
|
else |
643 |
|
|
regs.spcflags &= ~(SPCFLAG_TRACE | SPCFLAG_DOTRACE); |
644 |
|
|
} |
645 |
|
|
|
646 |
|
|
void Exception(int nr, uaecptr oldpc) |
647 |
|
|
{ |
648 |
|
|
compiler_flush_jsr_stack(); |
649 |
|
|
MakeSR(); |
650 |
|
|
if (!regs.s) { |
651 |
|
|
regs.usp = m68k_areg(regs, 7); |
652 |
|
|
if (CPUType >= 2) |
653 |
|
|
m68k_areg(regs, 7) = regs.m ? regs.msp : regs.isp; |
654 |
|
|
else |
655 |
|
|
m68k_areg(regs, 7) = regs.isp; |
656 |
|
|
regs.s = 1; |
657 |
|
|
} |
658 |
|
|
if (CPUType > 0) { |
659 |
|
|
if (nr == 2 || nr == 3) { |
660 |
|
|
int i; |
661 |
|
|
/* @@@ this is probably wrong (?) */ |
662 |
|
|
for (i = 0 ; i < 12 ; i++) { |
663 |
|
|
m68k_areg(regs, 7) -= 2; |
664 |
|
|
put_word (m68k_areg(regs, 7), 0); |
665 |
|
|
} |
666 |
|
|
m68k_areg(regs, 7) -= 2; |
667 |
|
|
put_word (m68k_areg(regs, 7), 0xa000 + nr * 4); |
668 |
|
|
} else if (nr ==5 || nr == 6 || nr == 7 || nr == 9) { |
669 |
|
|
m68k_areg(regs, 7) -= 4; |
670 |
|
|
put_long (m68k_areg(regs, 7), oldpc); |
671 |
|
|
m68k_areg(regs, 7) -= 2; |
672 |
|
|
put_word (m68k_areg(regs, 7), 0x2000 + nr * 4); |
673 |
|
|
} else if (regs.m && nr >= 24 && nr < 32) { |
674 |
|
|
m68k_areg(regs, 7) -= 2; |
675 |
|
|
put_word (m68k_areg(regs, 7), nr * 4); |
676 |
|
|
m68k_areg(regs, 7) -= 4; |
677 |
|
|
put_long (m68k_areg(regs, 7), m68k_getpc ()); |
678 |
|
|
m68k_areg(regs, 7) -= 2; |
679 |
|
|
put_word (m68k_areg(regs, 7), regs.sr); |
680 |
|
|
regs.sr |= (1 << 13); |
681 |
|
|
regs.msp = m68k_areg(regs, 7); |
682 |
|
|
m68k_areg(regs, 7) = regs.isp; |
683 |
|
|
m68k_areg(regs, 7) -= 2; |
684 |
|
|
put_word (m68k_areg(regs, 7), 0x1000 + nr * 4); |
685 |
|
|
} else { |
686 |
|
|
m68k_areg(regs, 7) -= 2; |
687 |
|
|
put_word (m68k_areg(regs, 7), nr * 4); |
688 |
|
|
} |
689 |
|
|
} else { |
690 |
|
|
if (nr == 2 || nr == 3) { |
691 |
|
|
m68k_areg(regs, 7) -= 12; |
692 |
|
|
/* ??????? */ |
693 |
|
|
if (nr == 3) { |
694 |
|
|
put_long (m68k_areg(regs, 7), last_fault_for_exception_3); |
695 |
|
|
put_word (m68k_areg(regs, 7)+4, last_op_for_exception_3); |
696 |
|
|
put_long (m68k_areg(regs, 7)+8, last_addr_for_exception_3); |
697 |
|
|
} |
698 |
|
|
write_log ("Exception!\n"); |
699 |
|
|
goto kludge_me_do; |
700 |
|
|
} |
701 |
|
|
} |
702 |
|
|
m68k_areg(regs, 7) -= 4; |
703 |
|
|
put_long (m68k_areg(regs, 7), m68k_getpc ()); |
704 |
|
|
kludge_me_do: |
705 |
|
|
m68k_areg(regs, 7) -= 2; |
706 |
|
|
put_word (m68k_areg(regs, 7), regs.sr); |
707 |
|
|
m68k_setpc (get_long (regs.vbr + 4*nr)); |
708 |
|
|
fill_prefetch_0 (); |
709 |
|
|
regs.t1 = regs.t0 = regs.m = 0; |
710 |
|
|
regs.spcflags &= ~(SPCFLAG_TRACE | SPCFLAG_DOTRACE); |
711 |
|
|
} |
712 |
|
|
|
713 |
|
|
static void Interrupt(int nr) |
714 |
|
|
{ |
715 |
|
|
assert(nr < 8 && nr >= 0); |
716 |
|
|
lastint_regs = regs; |
717 |
|
|
lastint_no = nr; |
718 |
|
|
Exception(nr+24, 0); |
719 |
|
|
|
720 |
|
|
regs.intmask = nr; |
721 |
|
|
regs.spcflags |= SPCFLAG_INT; |
722 |
|
|
} |
723 |
|
|
|
724 |
cebix |
1.2 |
static int caar, cacr, tc, itt0, itt1, dtt0, dtt1; |
725 |
cebix |
1.1 |
|
726 |
|
|
void m68k_move2c (int regno, uae_u32 *regp) |
727 |
|
|
{ |
728 |
|
|
if (CPUType == 1 && (regno & 0x7FF) > 1) |
729 |
|
|
op_illg (0x4E7B); |
730 |
|
|
else |
731 |
|
|
switch (regno) { |
732 |
|
|
case 0: regs.sfc = *regp & 7; break; |
733 |
|
|
case 1: regs.dfc = *regp & 7; break; |
734 |
|
|
case 2: cacr = *regp & 0x3; break; /* ignore C and CE */ |
735 |
cebix |
1.2 |
case 3: tc = *regp & 0xc000; break; |
736 |
|
|
case 4: itt0 = *regp & 0xffffe364; break; |
737 |
|
|
case 5: itt1 = *regp & 0xffffe364; break; |
738 |
|
|
case 6: dtt0 = *regp & 0xffffe364; break; |
739 |
|
|
case 7: dtt1 = *regp & 0xffffe364; break; |
740 |
cebix |
1.1 |
case 0x800: regs.usp = *regp; break; |
741 |
|
|
case 0x801: regs.vbr = *regp; break; |
742 |
|
|
case 0x802: caar = *regp &0xfc; break; |
743 |
|
|
case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg(regs, 7) = regs.msp; break; |
744 |
|
|
case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg(regs, 7) = regs.isp; break; |
745 |
|
|
default: |
746 |
|
|
op_illg (0x4E7B); |
747 |
|
|
break; |
748 |
|
|
} |
749 |
|
|
} |
750 |
|
|
|
751 |
|
|
void m68k_movec2 (int regno, uae_u32 *regp) |
752 |
|
|
{ |
753 |
|
|
if (CPUType == 1 && (regno & 0x7FF) > 1) |
754 |
|
|
op_illg (0x4E7A); |
755 |
|
|
else |
756 |
|
|
switch (regno) { |
757 |
|
|
case 0: *regp = regs.sfc; break; |
758 |
|
|
case 1: *regp = regs.dfc; break; |
759 |
|
|
case 2: *regp = cacr; break; |
760 |
cebix |
1.2 |
case 3: *regp = tc; break; |
761 |
|
|
case 4: *regp = itt0; break; |
762 |
|
|
case 5: *regp = itt1; break; |
763 |
|
|
case 6: *regp = dtt0; break; |
764 |
|
|
case 7: *regp = dtt1; break; |
765 |
cebix |
1.1 |
case 0x800: *regp = regs.usp; break; |
766 |
|
|
case 0x801: *regp = regs.vbr; break; |
767 |
|
|
case 0x802: *regp = caar; break; |
768 |
|
|
case 0x803: *regp = regs.m == 1 ? m68k_areg(regs, 7) : regs.msp; break; |
769 |
|
|
case 0x804: *regp = regs.m == 0 ? m68k_areg(regs, 7) : regs.isp; break; |
770 |
|
|
default: |
771 |
|
|
op_illg (0x4E7A); |
772 |
|
|
break; |
773 |
|
|
} |
774 |
|
|
} |
775 |
|
|
|
776 |
|
|
static __inline__ int |
777 |
|
|
div_unsigned(uae_u32 src_hi, uae_u32 src_lo, uae_u32 div, uae_u32 *quot, uae_u32 *rem) |
778 |
|
|
{ |
779 |
|
|
uae_u32 q = 0, cbit = 0; |
780 |
|
|
int i; |
781 |
|
|
|
782 |
|
|
if (div <= src_hi) { |
783 |
|
|
return 1; |
784 |
|
|
} |
785 |
|
|
for (i = 0 ; i < 32 ; i++) { |
786 |
|
|
cbit = src_hi & 0x80000000ul; |
787 |
|
|
src_hi <<= 1; |
788 |
|
|
if (src_lo & 0x80000000ul) src_hi++; |
789 |
|
|
src_lo <<= 1; |
790 |
|
|
q = q << 1; |
791 |
|
|
if (cbit || div <= src_hi) { |
792 |
|
|
q |= 1; |
793 |
|
|
src_hi -= div; |
794 |
|
|
} |
795 |
|
|
} |
796 |
|
|
*quot = q; |
797 |
|
|
*rem = src_hi; |
798 |
|
|
return 0; |
799 |
|
|
} |
800 |
|
|
|
801 |
|
|
void m68k_divl (uae_u32 opcode, uae_u32 src, uae_u16 extra, uaecptr oldpc) |
802 |
|
|
{ |
803 |
|
|
#if defined(uae_s64) |
804 |
|
|
if (src == 0) { |
805 |
|
|
Exception (5, oldpc); |
806 |
|
|
return; |
807 |
|
|
} |
808 |
|
|
if (extra & 0x800) { |
809 |
|
|
/* signed variant */ |
810 |
|
|
uae_s64 a = (uae_s64)(uae_s32)m68k_dreg(regs, (extra >> 12) & 7); |
811 |
|
|
uae_s64 quot, rem; |
812 |
|
|
|
813 |
|
|
if (extra & 0x400) { |
814 |
|
|
a &= 0xffffffffu; |
815 |
|
|
a |= (uae_s64)m68k_dreg(regs, extra & 7) << 32; |
816 |
|
|
} |
817 |
|
|
rem = a % (uae_s64)(uae_s32)src; |
818 |
|
|
quot = a / (uae_s64)(uae_s32)src; |
819 |
|
|
if ((quot & UVAL64(0xffffffff80000000)) != 0 |
820 |
|
|
&& (quot & UVAL64(0xffffffff80000000)) != UVAL64(0xffffffff80000000)) |
821 |
|
|
{ |
822 |
|
|
SET_VFLG (1); |
823 |
|
|
SET_NFLG (1); |
824 |
|
|
SET_CFLG (0); |
825 |
|
|
} else { |
826 |
|
|
if (((uae_s32)rem < 0) != ((uae_s64)a < 0)) rem = -rem; |
827 |
|
|
SET_VFLG (0); |
828 |
|
|
SET_CFLG (0); |
829 |
|
|
SET_ZFLG (((uae_s32)quot) == 0); |
830 |
|
|
SET_NFLG (((uae_s32)quot) < 0); |
831 |
|
|
m68k_dreg(regs, extra & 7) = rem; |
832 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = quot; |
833 |
|
|
} |
834 |
|
|
} else { |
835 |
|
|
/* unsigned */ |
836 |
|
|
uae_u64 a = (uae_u64)(uae_u32)m68k_dreg(regs, (extra >> 12) & 7); |
837 |
|
|
uae_u64 quot, rem; |
838 |
|
|
|
839 |
|
|
if (extra & 0x400) { |
840 |
|
|
a &= 0xffffffffu; |
841 |
|
|
a |= (uae_u64)m68k_dreg(regs, extra & 7) << 32; |
842 |
|
|
} |
843 |
|
|
rem = a % (uae_u64)src; |
844 |
|
|
quot = a / (uae_u64)src; |
845 |
|
|
if (quot > 0xffffffffu) { |
846 |
|
|
SET_VFLG (1); |
847 |
|
|
SET_NFLG (1); |
848 |
|
|
SET_CFLG (0); |
849 |
|
|
} else { |
850 |
|
|
SET_VFLG (0); |
851 |
|
|
SET_CFLG (0); |
852 |
|
|
SET_ZFLG (((uae_s32)quot) == 0); |
853 |
|
|
SET_NFLG (((uae_s32)quot) < 0); |
854 |
|
|
m68k_dreg(regs, extra & 7) = rem; |
855 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = quot; |
856 |
|
|
} |
857 |
|
|
} |
858 |
|
|
#else |
859 |
|
|
if (src == 0) { |
860 |
|
|
Exception (5, oldpc); |
861 |
|
|
return; |
862 |
|
|
} |
863 |
|
|
if (extra & 0x800) { |
864 |
|
|
/* signed variant */ |
865 |
|
|
uae_s32 lo = (uae_s32)m68k_dreg(regs, (extra >> 12) & 7); |
866 |
|
|
uae_s32 hi = lo < 0 ? -1 : 0; |
867 |
|
|
uae_s32 save_high; |
868 |
|
|
uae_u32 quot, rem; |
869 |
|
|
uae_u32 sign; |
870 |
|
|
|
871 |
|
|
if (extra & 0x400) { |
872 |
|
|
hi = (uae_s32)m68k_dreg(regs, extra & 7); |
873 |
|
|
} |
874 |
|
|
save_high = hi; |
875 |
|
|
sign = (hi ^ src); |
876 |
|
|
if (hi < 0) { |
877 |
|
|
hi = ~hi; |
878 |
|
|
lo = -lo; |
879 |
|
|
if (lo == 0) hi++; |
880 |
|
|
} |
881 |
|
|
if ((uae_s32)src < 0) src = -src; |
882 |
|
|
if (div_unsigned(hi, lo, src, ", &rem) || |
883 |
|
|
(sign & 0x80000000) ? quot > 0x80000000 : quot > 0x7fffffff) { |
884 |
|
|
SET_VFLG (1); |
885 |
|
|
SET_NFLG (1); |
886 |
|
|
SET_CFLG (0); |
887 |
|
|
} else { |
888 |
|
|
if (sign & 0x80000000) quot = -quot; |
889 |
|
|
if (((uae_s32)rem < 0) != (save_high < 0)) rem = -rem; |
890 |
|
|
SET_VFLG (0); |
891 |
|
|
SET_CFLG (0); |
892 |
|
|
SET_ZFLG (((uae_s32)quot) == 0); |
893 |
|
|
SET_NFLG (((uae_s32)quot) < 0); |
894 |
|
|
m68k_dreg(regs, extra & 7) = rem; |
895 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = quot; |
896 |
|
|
} |
897 |
|
|
} else { |
898 |
|
|
/* unsigned */ |
899 |
|
|
uae_u32 lo = (uae_u32)m68k_dreg(regs, (extra >> 12) & 7); |
900 |
|
|
uae_u32 hi = 0; |
901 |
|
|
uae_u32 quot, rem; |
902 |
|
|
|
903 |
|
|
if (extra & 0x400) { |
904 |
|
|
hi = (uae_u32)m68k_dreg(regs, extra & 7); |
905 |
|
|
} |
906 |
|
|
if (div_unsigned(hi, lo, src, ", &rem)) { |
907 |
|
|
SET_VFLG (1); |
908 |
|
|
SET_NFLG (1); |
909 |
|
|
SET_CFLG (0); |
910 |
|
|
} else { |
911 |
|
|
SET_VFLG (0); |
912 |
|
|
SET_CFLG (0); |
913 |
|
|
SET_ZFLG (((uae_s32)quot) == 0); |
914 |
|
|
SET_NFLG (((uae_s32)quot) < 0); |
915 |
|
|
m68k_dreg(regs, extra & 7) = rem; |
916 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = quot; |
917 |
|
|
} |
918 |
|
|
} |
919 |
|
|
#endif |
920 |
|
|
} |
921 |
|
|
|
922 |
|
|
static __inline__ void |
923 |
|
|
mul_unsigned(uae_u32 src1, uae_u32 src2, uae_u32 *dst_hi, uae_u32 *dst_lo) |
924 |
|
|
{ |
925 |
|
|
uae_u32 r0 = (src1 & 0xffff) * (src2 & 0xffff); |
926 |
|
|
uae_u32 r1 = ((src1 >> 16) & 0xffff) * (src2 & 0xffff); |
927 |
|
|
uae_u32 r2 = (src1 & 0xffff) * ((src2 >> 16) & 0xffff); |
928 |
|
|
uae_u32 r3 = ((src1 >> 16) & 0xffff) * ((src2 >> 16) & 0xffff); |
929 |
|
|
uae_u32 lo; |
930 |
|
|
|
931 |
|
|
lo = r0 + ((r1 << 16) & 0xffff0000ul); |
932 |
|
|
if (lo < r0) r3++; |
933 |
|
|
r0 = lo; |
934 |
|
|
lo = r0 + ((r2 << 16) & 0xffff0000ul); |
935 |
|
|
if (lo < r0) r3++; |
936 |
|
|
r3 += ((r1 >> 16) & 0xffff) + ((r2 >> 16) & 0xffff); |
937 |
|
|
*dst_lo = lo; |
938 |
|
|
*dst_hi = r3; |
939 |
|
|
} |
940 |
|
|
|
941 |
|
|
void m68k_mull (uae_u32 opcode, uae_u32 src, uae_u16 extra) |
942 |
|
|
{ |
943 |
|
|
#if defined(uae_s64) |
944 |
|
|
if (extra & 0x800) { |
945 |
|
|
/* signed variant */ |
946 |
|
|
uae_s64 a = (uae_s64)(uae_s32)m68k_dreg(regs, (extra >> 12) & 7); |
947 |
|
|
|
948 |
|
|
a *= (uae_s64)(uae_s32)src; |
949 |
|
|
SET_VFLG (0); |
950 |
|
|
SET_CFLG (0); |
951 |
|
|
SET_ZFLG (a == 0); |
952 |
|
|
SET_NFLG (a < 0); |
953 |
|
|
if (extra & 0x400) |
954 |
|
|
m68k_dreg(regs, extra & 7) = a >> 32; |
955 |
|
|
else if ((a & UVAL64(0xffffffff80000000)) != 0 |
956 |
|
|
&& (a & UVAL64(0xffffffff80000000)) != UVAL64(0xffffffff80000000)) |
957 |
|
|
{ |
958 |
|
|
SET_VFLG (1); |
959 |
|
|
} |
960 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)a; |
961 |
|
|
} else { |
962 |
|
|
/* unsigned */ |
963 |
|
|
uae_u64 a = (uae_u64)(uae_u32)m68k_dreg(regs, (extra >> 12) & 7); |
964 |
|
|
|
965 |
|
|
a *= (uae_u64)src; |
966 |
|
|
SET_VFLG (0); |
967 |
|
|
SET_CFLG (0); |
968 |
|
|
SET_ZFLG (a == 0); |
969 |
|
|
SET_NFLG (((uae_s64)a) < 0); |
970 |
|
|
if (extra & 0x400) |
971 |
|
|
m68k_dreg(regs, extra & 7) = a >> 32; |
972 |
|
|
else if ((a & UVAL64(0xffffffff00000000)) != 0) { |
973 |
|
|
SET_VFLG (1); |
974 |
|
|
} |
975 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = (uae_u32)a; |
976 |
|
|
} |
977 |
|
|
#else |
978 |
|
|
if (extra & 0x800) { |
979 |
|
|
/* signed variant */ |
980 |
|
|
uae_s32 src1,src2; |
981 |
|
|
uae_u32 dst_lo,dst_hi; |
982 |
|
|
uae_u32 sign; |
983 |
|
|
|
984 |
|
|
src1 = (uae_s32)src; |
985 |
|
|
src2 = (uae_s32)m68k_dreg(regs, (extra >> 12) & 7); |
986 |
|
|
sign = (src1 ^ src2); |
987 |
|
|
if (src1 < 0) src1 = -src1; |
988 |
|
|
if (src2 < 0) src2 = -src2; |
989 |
|
|
mul_unsigned((uae_u32)src1,(uae_u32)src2,&dst_hi,&dst_lo); |
990 |
|
|
if (sign & 0x80000000) { |
991 |
|
|
dst_hi = ~dst_hi; |
992 |
|
|
dst_lo = -dst_lo; |
993 |
|
|
if (dst_lo == 0) dst_hi++; |
994 |
|
|
} |
995 |
|
|
SET_VFLG (0); |
996 |
|
|
SET_CFLG (0); |
997 |
|
|
SET_ZFLG (dst_hi == 0 && dst_lo == 0); |
998 |
|
|
SET_NFLG (((uae_s32)dst_hi) < 0); |
999 |
|
|
if (extra & 0x400) |
1000 |
|
|
m68k_dreg(regs, extra & 7) = dst_hi; |
1001 |
|
|
else if ((dst_hi != 0 || (dst_lo & 0x80000000) != 0) |
1002 |
|
|
&& ((dst_hi & 0xffffffff) != 0xffffffff |
1003 |
|
|
|| (dst_lo & 0x80000000) != 0x80000000)) |
1004 |
|
|
{ |
1005 |
|
|
SET_VFLG (1); |
1006 |
|
|
} |
1007 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = dst_lo; |
1008 |
|
|
} else { |
1009 |
|
|
/* unsigned */ |
1010 |
|
|
uae_u32 dst_lo,dst_hi; |
1011 |
|
|
|
1012 |
|
|
mul_unsigned(src,(uae_u32)m68k_dreg(regs, (extra >> 12) & 7),&dst_hi,&dst_lo); |
1013 |
|
|
|
1014 |
|
|
SET_VFLG (0); |
1015 |
|
|
SET_CFLG (0); |
1016 |
|
|
SET_ZFLG (dst_hi == 0 && dst_lo == 0); |
1017 |
|
|
SET_NFLG (((uae_s32)dst_hi) < 0); |
1018 |
|
|
if (extra & 0x400) |
1019 |
|
|
m68k_dreg(regs, extra & 7) = dst_hi; |
1020 |
|
|
else if (dst_hi != 0) { |
1021 |
|
|
SET_VFLG (1); |
1022 |
|
|
} |
1023 |
|
|
m68k_dreg(regs, (extra >> 12) & 7) = dst_lo; |
1024 |
|
|
} |
1025 |
|
|
#endif |
1026 |
|
|
} |
1027 |
|
|
static char* ccnames[] = |
1028 |
|
|
{ "T ","F ","HI","LS","CC","CS","NE","EQ", |
1029 |
|
|
"VC","VS","PL","MI","GE","LT","GT","LE" }; |
1030 |
|
|
|
1031 |
|
|
void m68k_reset (void) |
1032 |
|
|
{ |
1033 |
|
|
m68k_areg (regs, 7) = 0x2000; |
1034 |
|
|
m68k_setpc (ROMBaseMac + 0x2a); |
1035 |
|
|
fill_prefetch_0 (); |
1036 |
|
|
regs.kick_mask = 0xF80000; |
1037 |
|
|
regs.s = 1; |
1038 |
|
|
regs.m = 0; |
1039 |
|
|
regs.stopped = 0; |
1040 |
|
|
regs.t1 = 0; |
1041 |
|
|
regs.t0 = 0; |
1042 |
|
|
SET_ZFLG (0); |
1043 |
|
|
SET_XFLG (0); |
1044 |
|
|
SET_CFLG (0); |
1045 |
|
|
SET_VFLG (0); |
1046 |
|
|
SET_NFLG (0); |
1047 |
|
|
regs.spcflags = 0; |
1048 |
|
|
regs.intmask = 7; |
1049 |
|
|
regs.vbr = regs.sfc = regs.dfc = 0; |
1050 |
|
|
regs.fpcr = regs.fpsr = regs.fpiar = 0; |
1051 |
|
|
} |
1052 |
|
|
|
1053 |
cebix |
1.4 |
void REGPARAM2 op_illg (uae_u32 opcode) |
1054 |
cebix |
1.1 |
{ |
1055 |
|
|
uaecptr pc = m68k_getpc (); |
1056 |
|
|
|
1057 |
|
|
compiler_flush_jsr_stack (); |
1058 |
|
|
|
1059 |
|
|
if ((opcode & 0xFF00) == 0x7100) { |
1060 |
|
|
struct M68kRegisters r; |
1061 |
|
|
int i; |
1062 |
|
|
|
1063 |
|
|
// Return from Execute68k()? |
1064 |
|
|
if (opcode == M68K_EXEC_RETURN) { |
1065 |
|
|
regs.spcflags |= SPCFLAG_BRK; |
1066 |
|
|
quit_program = 1; |
1067 |
cebix |
1.4 |
return; |
1068 |
cebix |
1.1 |
} |
1069 |
|
|
|
1070 |
|
|
// Call EMUL_OP opcode |
1071 |
|
|
for (i=0; i<8; i++) { |
1072 |
|
|
r.d[i] = m68k_dreg(regs, i); |
1073 |
|
|
r.a[i] = m68k_areg(regs, i); |
1074 |
|
|
} |
1075 |
|
|
MakeSR(); |
1076 |
|
|
r.sr = regs.sr; |
1077 |
|
|
EmulOp(opcode, &r); |
1078 |
|
|
for (i=0; i<8; i++) { |
1079 |
|
|
m68k_dreg(regs, i) = r.d[i]; |
1080 |
|
|
m68k_areg(regs, i) = r.a[i]; |
1081 |
|
|
} |
1082 |
|
|
regs.sr = r.sr; |
1083 |
|
|
MakeFromSR(); |
1084 |
|
|
m68k_incpc(2); |
1085 |
|
|
fill_prefetch_0 (); |
1086 |
cebix |
1.4 |
return; |
1087 |
cebix |
1.1 |
} |
1088 |
|
|
|
1089 |
|
|
if ((opcode & 0xF000) == 0xA000) { |
1090 |
|
|
Exception(0xA,0); |
1091 |
cebix |
1.4 |
return; |
1092 |
cebix |
1.1 |
} |
1093 |
|
|
|
1094 |
cebix |
1.4 |
// write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); |
1095 |
cebix |
1.3 |
|
1096 |
cebix |
1.1 |
if ((opcode & 0xF000) == 0xF000) { |
1097 |
|
|
Exception(0xB,0); |
1098 |
cebix |
1.4 |
return; |
1099 |
cebix |
1.1 |
} |
1100 |
|
|
|
1101 |
cebix |
1.4 |
write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); |
1102 |
|
|
|
1103 |
cebix |
1.1 |
Exception (4,0); |
1104 |
|
|
} |
1105 |
|
|
|
1106 |
|
|
void mmu_op(uae_u32 opcode, uae_u16 extra) |
1107 |
|
|
{ |
1108 |
|
|
if ((extra & 0xB000) == 0) { /* PMOVE instruction */ |
1109 |
|
|
|
1110 |
|
|
} else if ((extra & 0xF000) == 0x2000) { /* PLOAD instruction */ |
1111 |
|
|
} else if ((extra & 0xF000) == 0x8000) { /* PTEST instruction */ |
1112 |
|
|
} else |
1113 |
|
|
op_illg (opcode); |
1114 |
|
|
} |
1115 |
|
|
|
1116 |
|
|
static int n_insns = 0, n_spcinsns = 0; |
1117 |
|
|
|
1118 |
|
|
static uaecptr last_trace_ad = 0; |
1119 |
|
|
|
1120 |
|
|
static void do_trace (void) |
1121 |
|
|
{ |
1122 |
|
|
if (regs.t0) { |
1123 |
|
|
uae_u16 opcode; |
1124 |
|
|
/* should also include TRAP, CHK, SR modification FPcc */ |
1125 |
|
|
/* probably never used so why bother */ |
1126 |
|
|
/* We can afford this to be inefficient... */ |
1127 |
|
|
m68k_setpc (m68k_getpc ()); |
1128 |
|
|
fill_prefetch_0 (); |
1129 |
|
|
opcode = get_word (regs.pc); |
1130 |
|
|
if (opcode == 0x4e72 /* RTE */ |
1131 |
|
|
|| opcode == 0x4e74 /* RTD */ |
1132 |
|
|
|| opcode == 0x4e75 /* RTS */ |
1133 |
|
|
|| opcode == 0x4e77 /* RTR */ |
1134 |
|
|
|| opcode == 0x4e76 /* TRAPV */ |
1135 |
|
|
|| (opcode & 0xffc0) == 0x4e80 /* JSR */ |
1136 |
|
|
|| (opcode & 0xffc0) == 0x4ec0 /* JMP */ |
1137 |
|
|
|| (opcode & 0xff00) == 0x6100 /* BSR */ |
1138 |
|
|
|| ((opcode & 0xf000) == 0x6000 /* Bcc */ |
1139 |
|
|
&& cctrue((opcode >> 8) & 0xf)) |
1140 |
|
|
|| ((opcode & 0xf0f0) == 0x5050 /* DBcc */ |
1141 |
|
|
&& !cctrue((opcode >> 8) & 0xf) |
1142 |
|
|
&& (uae_s16)m68k_dreg(regs, opcode & 7) != 0)) |
1143 |
|
|
{ |
1144 |
|
|
last_trace_ad = m68k_getpc (); |
1145 |
|
|
regs.spcflags &= ~SPCFLAG_TRACE; |
1146 |
|
|
regs.spcflags |= SPCFLAG_DOTRACE; |
1147 |
|
|
} |
1148 |
|
|
} else if (regs.t1) { |
1149 |
|
|
last_trace_ad = m68k_getpc (); |
1150 |
|
|
regs.spcflags &= ~SPCFLAG_TRACE; |
1151 |
|
|
regs.spcflags |= SPCFLAG_DOTRACE; |
1152 |
|
|
} |
1153 |
|
|
} |
1154 |
|
|
|
1155 |
|
|
|
1156 |
|
|
static int do_specialties (void) |
1157 |
|
|
{ |
1158 |
|
|
/*n_spcinsns++;*/ |
1159 |
|
|
run_compiled_code(); |
1160 |
|
|
if (regs.spcflags & SPCFLAG_DOTRACE) { |
1161 |
|
|
Exception (9,last_trace_ad); |
1162 |
|
|
} |
1163 |
|
|
while (regs.spcflags & SPCFLAG_STOP) { |
1164 |
|
|
if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)){ |
1165 |
|
|
int intr = intlev (); |
1166 |
|
|
regs.spcflags &= ~(SPCFLAG_INT | SPCFLAG_DOINT); |
1167 |
|
|
if (intr != -1 && intr > regs.intmask) { |
1168 |
|
|
Interrupt (intr); |
1169 |
|
|
regs.stopped = 0; |
1170 |
|
|
regs.spcflags &= ~SPCFLAG_STOP; |
1171 |
|
|
} |
1172 |
|
|
} |
1173 |
|
|
} |
1174 |
|
|
if (regs.spcflags & SPCFLAG_TRACE) |
1175 |
|
|
do_trace (); |
1176 |
|
|
|
1177 |
|
|
if (regs.spcflags & SPCFLAG_DOINT) { |
1178 |
|
|
int intr = intlev (); |
1179 |
|
|
regs.spcflags &= ~SPCFLAG_DOINT; |
1180 |
|
|
if (intr != -1 && intr > regs.intmask) { |
1181 |
|
|
Interrupt (intr); |
1182 |
|
|
regs.stopped = 0; |
1183 |
|
|
} |
1184 |
|
|
} |
1185 |
|
|
if (regs.spcflags & SPCFLAG_INT) { |
1186 |
|
|
regs.spcflags &= ~SPCFLAG_INT; |
1187 |
|
|
regs.spcflags |= SPCFLAG_DOINT; |
1188 |
|
|
} |
1189 |
|
|
if (regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)) { |
1190 |
|
|
regs.spcflags &= ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); |
1191 |
|
|
return 1; |
1192 |
|
|
} |
1193 |
|
|
return 0; |
1194 |
|
|
} |
1195 |
|
|
|
1196 |
|
|
static void m68k_run_1 (void) |
1197 |
|
|
{ |
1198 |
cebix |
1.4 |
for (;;) { |
1199 |
|
|
uae_u32 opcode = GET_OPCODE; |
1200 |
|
|
(*cpufunctbl[opcode])(opcode); |
1201 |
|
|
if (regs.spcflags) { |
1202 |
|
|
if (do_specialties()) |
1203 |
|
|
return; |
1204 |
|
|
} |
1205 |
cebix |
1.1 |
} |
1206 |
|
|
} |
1207 |
|
|
|
1208 |
|
|
#define m68k_run1 m68k_run_1 |
1209 |
|
|
|
1210 |
|
|
int in_m68k_go = 0; |
1211 |
|
|
|
1212 |
|
|
void m68k_go (int may_quit) |
1213 |
|
|
{ |
1214 |
|
|
// m68k_go() must be reentrant for Execute68k() and Execute68kTrap() to work |
1215 |
|
|
/* |
1216 |
|
|
if (in_m68k_go || !may_quit) { |
1217 |
|
|
write_log("Bug! m68k_go is not reentrant.\n"); |
1218 |
|
|
abort(); |
1219 |
|
|
} |
1220 |
|
|
*/ |
1221 |
|
|
in_m68k_go++; |
1222 |
|
|
for (;;) { |
1223 |
|
|
if (quit_program > 0) { |
1224 |
|
|
if (quit_program == 1) |
1225 |
|
|
break; |
1226 |
|
|
quit_program = 0; |
1227 |
|
|
m68k_reset (); |
1228 |
|
|
} |
1229 |
|
|
m68k_run1(); |
1230 |
|
|
} |
1231 |
|
|
if (debugging) { |
1232 |
|
|
uaecptr nextpc; |
1233 |
|
|
m68k_dumpstate(&nextpc); |
1234 |
|
|
exit(1); |
1235 |
|
|
} |
1236 |
|
|
in_m68k_go--; |
1237 |
|
|
} |
1238 |
|
|
|
1239 |
|
|
static void m68k_verify (uaecptr addr, uaecptr *nextpc) |
1240 |
|
|
{ |
1241 |
|
|
uae_u32 opcode, val; |
1242 |
|
|
struct instr *dp; |
1243 |
|
|
|
1244 |
|
|
opcode = get_iword_1(0); |
1245 |
|
|
last_op_for_exception_3 = opcode; |
1246 |
|
|
m68kpc_offset = 2; |
1247 |
|
|
|
1248 |
|
|
if (cpufunctbl[cft_map (opcode)] == op_illg_1) { |
1249 |
|
|
opcode = 0x4AFC; |
1250 |
|
|
} |
1251 |
|
|
dp = table68k + opcode; |
1252 |
|
|
|
1253 |
|
|
if (dp->suse) { |
1254 |
|
|
if (!verify_ea (dp->sreg, (amodes)dp->smode, (wordsizes)dp->size, &val)) { |
1255 |
|
|
Exception (3, 0); |
1256 |
|
|
return; |
1257 |
|
|
} |
1258 |
|
|
} |
1259 |
|
|
if (dp->duse) { |
1260 |
|
|
if (!verify_ea (dp->dreg, (amodes)dp->dmode, (wordsizes)dp->size, &val)) { |
1261 |
|
|
Exception (3, 0); |
1262 |
|
|
return; |
1263 |
|
|
} |
1264 |
|
|
} |
1265 |
|
|
} |
1266 |
|
|
|
1267 |
|
|
void m68k_disasm (uaecptr addr, uaecptr *nextpc, int cnt) |
1268 |
|
|
{ |
1269 |
|
|
uaecptr newpc = 0; |
1270 |
|
|
m68kpc_offset = addr - m68k_getpc (); |
1271 |
|
|
while (cnt-- > 0) { |
1272 |
|
|
char instrname[20],*ccpt; |
1273 |
|
|
int opwords; |
1274 |
|
|
uae_u32 opcode; |
1275 |
|
|
struct mnemolookup *lookup; |
1276 |
|
|
struct instr *dp; |
1277 |
|
|
printf ("%08lx: ", m68k_getpc () + m68kpc_offset); |
1278 |
|
|
for (opwords = 0; opwords < 5; opwords++){ |
1279 |
|
|
printf ("%04x ", get_iword_1 (m68kpc_offset + opwords*2)); |
1280 |
|
|
} |
1281 |
|
|
opcode = get_iword_1 (m68kpc_offset); |
1282 |
|
|
m68kpc_offset += 2; |
1283 |
|
|
if (cpufunctbl[cft_map (opcode)] == op_illg_1) { |
1284 |
|
|
opcode = 0x4AFC; |
1285 |
|
|
} |
1286 |
|
|
dp = table68k + opcode; |
1287 |
|
|
for (lookup = lookuptab;lookup->mnemo != dp->mnemo; lookup++) |
1288 |
|
|
; |
1289 |
|
|
|
1290 |
|
|
strcpy (instrname, lookup->name); |
1291 |
|
|
ccpt = strstr (instrname, "cc"); |
1292 |
|
|
if (ccpt != 0) { |
1293 |
|
|
strncpy (ccpt, ccnames[dp->cc], 2); |
1294 |
|
|
} |
1295 |
|
|
printf ("%s", instrname); |
1296 |
|
|
switch (dp->size){ |
1297 |
|
|
case sz_byte: printf (".B "); break; |
1298 |
|
|
case sz_word: printf (".W "); break; |
1299 |
|
|
case sz_long: printf (".L "); break; |
1300 |
|
|
default: printf (" "); break; |
1301 |
|
|
} |
1302 |
|
|
|
1303 |
|
|
if (dp->suse) { |
1304 |
|
|
newpc = m68k_getpc () + m68kpc_offset; |
1305 |
|
|
newpc += ShowEA (dp->sreg, (amodes)dp->smode, (wordsizes)dp->size, 0); |
1306 |
|
|
} |
1307 |
|
|
if (dp->suse && dp->duse) |
1308 |
|
|
printf (","); |
1309 |
|
|
if (dp->duse) { |
1310 |
|
|
newpc = m68k_getpc () + m68kpc_offset; |
1311 |
|
|
newpc += ShowEA (dp->dreg, (amodes)dp->dmode, (wordsizes)dp->size, 0); |
1312 |
|
|
} |
1313 |
|
|
if (ccpt != 0) { |
1314 |
|
|
if (cctrue(dp->cc)) |
1315 |
|
|
printf (" == %08lx (TRUE)", newpc); |
1316 |
|
|
else |
1317 |
|
|
printf (" == %08lx (FALSE)", newpc); |
1318 |
|
|
} else if ((opcode & 0xff00) == 0x6100) /* BSR */ |
1319 |
|
|
printf (" == %08lx", newpc); |
1320 |
|
|
printf ("\n"); |
1321 |
|
|
} |
1322 |
|
|
if (nextpc) |
1323 |
|
|
*nextpc = m68k_getpc () + m68kpc_offset; |
1324 |
|
|
} |
1325 |
|
|
|
1326 |
|
|
void m68k_dumpstate (uaecptr *nextpc) |
1327 |
|
|
{ |
1328 |
|
|
int i; |
1329 |
|
|
for (i = 0; i < 8; i++){ |
1330 |
|
|
printf ("D%d: %08lx ", i, m68k_dreg(regs, i)); |
1331 |
|
|
if ((i & 3) == 3) printf ("\n"); |
1332 |
|
|
} |
1333 |
|
|
for (i = 0; i < 8; i++){ |
1334 |
|
|
printf ("A%d: %08lx ", i, m68k_areg(regs, i)); |
1335 |
|
|
if ((i & 3) == 3) printf ("\n"); |
1336 |
|
|
} |
1337 |
|
|
if (regs.s == 0) regs.usp = m68k_areg(regs, 7); |
1338 |
|
|
if (regs.s && regs.m) regs.msp = m68k_areg(regs, 7); |
1339 |
|
|
if (regs.s && regs.m == 0) regs.isp = m68k_areg(regs, 7); |
1340 |
|
|
printf ("USP=%08lx ISP=%08lx MSP=%08lx VBR=%08lx\n", |
1341 |
|
|
regs.usp,regs.isp,regs.msp,regs.vbr); |
1342 |
|
|
printf ("T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d\n", |
1343 |
|
|
regs.t1, regs.t0, regs.s, regs.m, |
1344 |
|
|
GET_XFLG, GET_NFLG, GET_ZFLG, GET_VFLG, GET_CFLG, regs.intmask); |
1345 |
|
|
for (i = 0; i < 8; i++){ |
1346 |
|
|
printf ("FP%d: %g ", i, regs.fp[i]); |
1347 |
|
|
if ((i & 3) == 3) printf ("\n"); |
1348 |
|
|
} |
1349 |
|
|
printf ("N=%d Z=%d I=%d NAN=%d\n", |
1350 |
|
|
(regs.fpsr & 0x8000000) != 0, |
1351 |
|
|
(regs.fpsr & 0x4000000) != 0, |
1352 |
|
|
(regs.fpsr & 0x2000000) != 0, |
1353 |
|
|
(regs.fpsr & 0x1000000) != 0); |
1354 |
|
|
|
1355 |
|
|
m68k_disasm(m68k_getpc (), nextpc, 1); |
1356 |
|
|
if (nextpc) |
1357 |
|
|
printf ("next PC: %08lx\n", *nextpc); |
1358 |
|
|
} |