ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/newcpu.cpp
Revision: 1.6
Committed: 2000-09-05T16:53:19Z (24 years, 2 months ago) by gbeauche
Branch: MAIN
Changes since 1.5: +11 -1 lines
Log Message:
- updated init_m68k with fpu_init() and fpu_set_integral_fpu() calls
- added exit_m68k() and handle deinitialization of the FPU
- updated m68k_reset to call fpu_reset()

File Contents

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