ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/newcpu.cpp
(Generate patch)

Comparing BasiliskII/src/uae_cpu/newcpu.cpp (file contents):
Revision 1.3 by cebix, 1999-10-28T16:00:28Z vs.
Revision 1.16 by gbeauche, 2002-09-17T16:05:39Z

# Line 22 | Line 22 | extern int intlev(void);       // From baisili
22   #include "memory.h"
23   #include "readcpu.h"
24   #include "newcpu.h"
25 < #include "compiler.h"
25 > #include "compiler/compemu.h"
26 > #include "fpu/fpu.h"
27 >
28 > #if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS)
29 > B2_mutex *spcflags_lock = NULL;
30 > #endif
31 >
32 > #if ENABLE_MON
33 > #include "mon.h"
34 > #include "mon_disass.h"
35 > #endif
36  
37   int quit_program = 0;
38 < int debugging = 0;
38 > const int debugging = 0;
39   struct flag_struct regflags;
40  
41   /* Opcode of faulting instruction */
# Line 42 | Line 52 | int movem_index1[256];
52   int movem_index2[256];
53   int movem_next[256];
54  
45 int fpp_movem_index1[256];
46 int fpp_movem_index2[256];
47 int fpp_movem_next[256];
48
55   cpuop_func *cpufunctbl[65536];
56  
57 + #if FLIGHT_RECORDER
58 + struct rec_step {
59 +        uae_u32 d[8];
60 +        uae_u32 a[8];
61 +        uae_u32 pc;
62 + };
63 +
64 + const int LOG_SIZE = 8192;
65 + static rec_step log[LOG_SIZE];
66 + static int log_ptr = -1; // First time initialization
67 +
68 + static const char *log_filename(void)
69 + {
70 +        const char *name = getenv("M68K_LOG_FILE");
71 +        return name ? name : "log.68k";
72 + }
73 +
74 + void m68k_record_step(uaecptr pc)
75 + {
76 +        for (int i = 0; i < 8; i++) {
77 +                log[log_ptr].d[i] = m68k_dreg(regs, i);
78 +                log[log_ptr].a[i] = m68k_areg(regs, i);
79 +        }
80 +        log[log_ptr].pc = pc;
81 +        log_ptr = (log_ptr + 1) % LOG_SIZE;
82 + }
83 +
84 + static void dump_log(void)
85 + {
86 +        FILE *f = fopen(log_filename(), "w");
87 +        if (f == NULL)
88 +                return;
89 +        for (int i = 0; i < LOG_SIZE; i++) {
90 +                int j = (i + log_ptr) % LOG_SIZE;
91 +                fprintf(f, "pc %08x\n", log[j].pc);
92 +                fprintf(f, "d0 %08x d1 %08x d2 %08x d3 %08x\n", log[j].d[0], log[j].d[1], log[j].d[2], log[j].d[3]);
93 +                fprintf(f, "d4 %08x d5 %08x d6 %08x d7 %08x\n", log[j].d[4], log[j].d[5], log[j].d[6], log[j].d[7]);
94 +                fprintf(f, "a0 %08x a1 %08x a2 %08x a3 %08x\n", log[j].a[0], log[j].a[1], log[j].a[2], log[j].a[3]);
95 +                fprintf(f, "a4 %08x a5 %08x a6 %08x a7 %08x\n", log[j].a[4], log[j].a[5], log[j].a[6], log[j].a[7]);
96 + #if ENABLE_MON
97 +                disass_68k(f, log[j].pc);
98 + #endif
99 +        }
100 +        fclose(f);
101 + }
102 + #endif
103 +
104   #define COUNT_INSTRS 0
105  
106   #if COUNT_INSTRS
# Line 111 | Line 164 | static __inline__ unsigned int cft_map (
164   #endif
165   }
166  
167 < static unsigned long REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM;
167 > cpuop_rettype REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM;
168  
169 < static unsigned long REGPARAM2 op_illg_1 (uae_u32 opcode)
169 > cpuop_rettype REGPARAM2 op_illg_1 (uae_u32 opcode)
170   {
171 <    op_illg (cft_map (opcode));
119 <    return 4;
171 >    cpuop_return( op_illg (cft_map (opcode)) );
172   }
173  
174   static void build_cpufunctbl (void)
# Line 135 | Line 187 | static void build_cpufunctbl (void)
187                          cpu_level = 1;
188          }
189      struct cputbl *tbl = (
190 <                  cpu_level == 4 ? op_smalltbl_0
191 <                : cpu_level == 3 ? op_smalltbl_1
192 <                : cpu_level == 2 ? op_smalltbl_2
193 <                : cpu_level == 1 ? op_smalltbl_3
194 <                : op_smalltbl_4);
190 >                  cpu_level == 4 ? op_smalltbl_0_ff
191 >                : cpu_level == 3 ? op_smalltbl_1_ff
192 >                : cpu_level == 2 ? op_smalltbl_2_ff
193 >                : cpu_level == 1 ? op_smalltbl_3_ff
194 >                : op_smalltbl_4_ff);
195  
196      for (opcode = 0; opcode < 65536; opcode++)
197          cpufunctbl[cft_map (opcode)] = op_illg_1;
# Line 179 | Line 231 | void init_m68k (void)
231          movem_index2[i] = 7-j;
232          movem_next[i] = i & (~(1 << j));
233      }
182    for (i = 0 ; i < 256 ; i++) {
183        int j;
184        for (j = 7 ; j >= 0 ; j--) {
185                if (i & (1 << j)) break;
186        }
187        fpp_movem_index1[i] = j;
188        fpp_movem_index2[i] = 7-j;
189        fpp_movem_next[i] = i & (~(1 << j));
190    }
234   #if COUNT_INSTRS
235      {
236          FILE *f = fopen (icountfilename (), "r");
# Line 208 | Line 251 | void init_m68k (void)
251      do_merges ();
252  
253      build_cpufunctbl ();
254 +        
255 + #if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS)
256 +        spcflags_lock = B2_create_mutex();
257 + #endif
258 +    fpu_init(CPUType == 4);
259 + }
260 +
261 + void exit_m68k (void)
262 + {
263 +        fpu_exit ();
264 + #if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS)
265 +        B2_delete_mutex(spcflags_lock);
266 + #endif
267   }
268  
269   struct regstruct regs, lastint_regs;
# Line 216 | Line 272 | static int backup_pointer = 0;
272   static long int m68kpc_offset;
273   int lastint_no;
274  
275 + #if REAL_ADDRESSING || DIRECT_ADDRESSING
276 + #define get_ibyte_1(o) get_byte(get_virtual_address(regs.pc_p) + (o) + 1)
277 + #define get_iword_1(o) get_word(get_virtual_address(regs.pc_p) + (o))
278 + #define get_ilong_1(o) get_long(get_virtual_address(regs.pc_p) + (o))
279 + #else
280   #define get_ibyte_1(o) get_byte(regs.pc + (regs.pc_p - regs.pc_oldp) + (o) + 1)
281   #define get_iword_1(o) get_word(regs.pc + (regs.pc_p - regs.pc_oldp) + (o))
282   #define get_ilong_1(o) get_long(regs.pc + (regs.pc_p - regs.pc_oldp) + (o))
283 + #endif
284  
285   uae_s32 ShowEA (int reg, amodes mode, wordsizes size, char *buf)
286   {
# Line 251 | Line 313 | uae_s32 ShowEA (int reg, amodes mode, wo
313          disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
314          addr = m68k_areg(regs,reg) + (uae_s16)disp16;
315          sprintf (buffer,"(A%d,$%04x) == $%08lx", reg, disp16 & 0xffff,
316 <                                        (long unsigned int)addr);
316 >                                        (unsigned long)addr);
317          break;
318       case Ad8r:
319          dp = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
# Line 284 | Line 346 | uae_s32 ShowEA (int reg, amodes mode, wo
346                      dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W',
347                      1 << ((dp >> 9) & 3),
348                      disp,outer,
349 <                    (long unsigned int)addr);
349 >                    (unsigned long)addr);
350          } else {
351            addr = m68k_areg(regs,reg) + (uae_s32)((uae_s8)disp8) + dispreg;
352            sprintf (buffer,"(A%d, %c%d.%c*%d, $%02x) == $%08lx", reg,
353                 dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W',
354                 1 << ((dp >> 9) & 3), disp8,
355 <               (long unsigned int)addr);
355 >               (unsigned long)addr);
356          }
357          break;
358       case PC16:
359          addr = m68k_getpc () + m68kpc_offset;
360          disp16 = get_iword_1 (m68kpc_offset); m68kpc_offset += 2;
361          addr += (uae_s16)disp16;
362 <        sprintf (buffer,"(PC,$%04x) == $%08lx", disp16 & 0xffff,(long unsigned int)addr);
362 >        sprintf (buffer,"(PC,$%04x) == $%08lx", disp16 & 0xffff,(unsigned long)addr);
363          break;
364       case PC8r:
365          addr = m68k_getpc () + m68kpc_offset;
# Line 331 | Line 393 | uae_s32 ShowEA (int reg, amodes mode, wo
393                      dp & 0x8000 ? 'A' : 'D', (int)r, dp & 0x800 ? 'L' : 'W',
394                      1 << ((dp >> 9) & 3),
395                      disp,outer,
396 <                    (long unsigned int)addr);
396 >                    (unsigned long)addr);
397          } else {
398            addr += (uae_s32)((uae_s8)disp8) + dispreg;
399            sprintf (buffer,"(PC, %c%d.%c*%d, $%02x) == $%08lx", dp & 0x8000 ? 'A' : 'D',
400                  (int)r, dp & 0x800 ? 'L' : 'W',  1 << ((dp >> 9) & 3),
401 <                disp8, (long unsigned int)addr);
401 >                disp8, (unsigned long)addr);
402          }
403          break;
404       case absw:
405 <        sprintf (buffer,"$%08lx", (long unsigned int)(uae_s32)(uae_s16)get_iword_1 (m68kpc_offset));
405 >        sprintf (buffer,"$%08lx", (unsigned long)(uae_s32)(uae_s16)get_iword_1 (m68kpc_offset));
406          m68kpc_offset += 2;
407          break;
408       case absl:
409 <        sprintf (buffer,"$%08lx", (long unsigned int)get_ilong_1 (m68kpc_offset));
409 >        sprintf (buffer,"$%08lx", (unsigned long)get_ilong_1 (m68kpc_offset));
410          m68kpc_offset += 4;
411          break;
412       case imm:
# Line 358 | Line 420 | uae_s32 ShowEA (int reg, amodes mode, wo
420              m68kpc_offset += 2;
421              break;
422           case sz_long:
423 <            sprintf (buffer,"#$%08lx", (long unsigned int)(get_ilong_1 (m68kpc_offset)));
423 >            sprintf (buffer,"#$%08lx", (unsigned long)(get_ilong_1 (m68kpc_offset)));
424              m68kpc_offset += 4;
425              break;
426           default:
# Line 378 | Line 440 | uae_s32 ShowEA (int reg, amodes mode, wo
440       case imm2:
441          offset = (uae_s32)get_ilong_1 (m68kpc_offset);
442          m68kpc_offset += 4;
443 <        sprintf (buffer,"#$%08lx", (long unsigned int)offset);
443 >        sprintf (buffer,"#$%08lx", (unsigned long)offset);
444          break;
445       case immi:
446          offset = (uae_s32)(uae_s8)(reg & 0xff);
447 <        sprintf (buffer,"#$%08lx", (long unsigned int)offset);
447 >        sprintf (buffer,"#$%08lx", (unsigned long)offset);
448          break;
449       default:
450          break;
# Line 637 | Line 699 | void MakeFromSR (void)
699          }
700      }
701  
702 <    regs.spcflags |= SPCFLAG_INT;
702 >    SPCFLAGS_SET( SPCFLAG_INT );
703      if (regs.t1 || regs.t0)
704 <        regs.spcflags |= SPCFLAG_TRACE;
704 >                SPCFLAGS_SET( SPCFLAG_TRACE );
705      else
706 <        regs.spcflags &= ~(SPCFLAG_TRACE | SPCFLAG_DOTRACE);
706 >        /* Keep SPCFLAG_DOTRACE, we still want a trace exception for
707 >           SR-modifying instructions (including STOP).  */
708 >                SPCFLAGS_CLEAR( SPCFLAG_TRACE );
709   }
710  
711   void Exception(int nr, uaecptr oldpc)
712   {
713 <    compiler_flush_jsr_stack();
713 >    uae_u32 currpc = m68k_getpc ();
714      MakeSR();
715      if (!regs.s) {
716          regs.usp = m68k_areg(regs, 7);
# Line 675 | Line 739 | void Exception(int nr, uaecptr oldpc)
739              m68k_areg(regs, 7) -= 2;
740              put_word (m68k_areg(regs, 7), nr * 4);
741              m68k_areg(regs, 7) -= 4;
742 <            put_long (m68k_areg(regs, 7), m68k_getpc ());
742 >            put_long (m68k_areg(regs, 7), currpc);
743              m68k_areg(regs, 7) -= 2;
744              put_word (m68k_areg(regs, 7), regs.sr);
745              regs.sr |= (1 << 13);
# Line 701 | Line 765 | void Exception(int nr, uaecptr oldpc)
765          }
766      }
767      m68k_areg(regs, 7) -= 4;
768 <    put_long (m68k_areg(regs, 7), m68k_getpc ());
768 >    put_long (m68k_areg(regs, 7), currpc);
769   kludge_me_do:
770      m68k_areg(regs, 7) -= 2;
771      put_word (m68k_areg(regs, 7), regs.sr);
772      m68k_setpc (get_long (regs.vbr + 4*nr));
773 +        SPCFLAGS_SET( SPCFLAG_JIT_END_COMPILE );
774      fill_prefetch_0 ();
775      regs.t1 = regs.t0 = regs.m = 0;
776 <    regs.spcflags &= ~(SPCFLAG_TRACE | SPCFLAG_DOTRACE);
776 >        SPCFLAGS_CLEAR( SPCFLAG_TRACE | SPCFLAG_DOTRACE );
777   }
778  
779   static void Interrupt(int nr)
# Line 719 | Line 784 | static void Interrupt(int nr)
784      Exception(nr+24, 0);
785  
786      regs.intmask = nr;
787 <    regs.spcflags |= SPCFLAG_INT;
787 >        SPCFLAGS_SET( SPCFLAG_INT );
788   }
789  
790 < static int caar, cacr, tc, itt0, itt1, dtt0, dtt1;
790 > static int caar, cacr, tc, itt0, itt1, dtt0, dtt1, mmusr, urp, srp;
791  
792 < void m68k_move2c (int regno, uae_u32 *regp)
792 > int m68k_move2c (int regno, uae_u32 *regp)
793   {
794 <    if (CPUType == 1 && (regno & 0x7FF) > 1)
794 >  if ((CPUType == 1 && (regno & 0x7FF) > 1)
795 >          || (CPUType < 4 && (regno & 0x7FF) > 2)
796 >          || (CPUType == 4 && regno == 0x802))
797 >  {
798          op_illg (0x4E7B);
799 <    else
799 >        return 0;
800 >  } else {
801          switch (regno) {
802           case 0: regs.sfc = *regp & 7; break;
803           case 1: regs.dfc = *regp & 7; break;
804 <         case 2: cacr = *regp & 0x3; break;     /* ignore C and CE */
804 >         case 2:
805 >                cacr = *regp & (CPUType < 4 ? 0x3 : 0x80008000);
806 > #if USE_JIT
807 >                if (CPUType < 4) {
808 >                        set_cache_state(cacr&1);
809 >                        if (*regp & 0x08)
810 >                                flush_icache(1);
811 >                }
812 >                else {
813 >                        set_cache_state((cacr&0x8000) || 0);
814 >                        // FIXME: The User Manual claims bit 3 of CACR is undefined
815 >                        if (*regp & 0x08)
816 >                                flush_icache(2);
817 >                }
818 > #endif
819 >         break;
820           case 3: tc = *regp & 0xc000; break;
821           case 4: itt0 = *regp & 0xffffe364; break;
822           case 5: itt1 = *regp & 0xffffe364; break;
# Line 743 | Line 827 | void m68k_move2c (int regno, uae_u32 *re
827           case 0x802: caar = *regp &0xfc; break;
828           case 0x803: regs.msp = *regp; if (regs.m == 1) m68k_areg(regs, 7) = regs.msp; break;
829           case 0x804: regs.isp = *regp; if (regs.m == 0) m68k_areg(regs, 7) = regs.isp; break;
830 +        case 0x805: mmusr = *regp; break;
831 +        case 0x806: urp = *regp; break;
832 +        case 0x807: srp = *regp; break;
833           default:
834              op_illg (0x4E7B);
835 <            break;
835 >            return 0;
836          }
837 +  }
838 +  return 1;
839   }
840  
841 < void m68k_movec2 (int regno, uae_u32 *regp)
841 > int m68k_movec2 (int regno, uae_u32 *regp)
842   {
843 <    if (CPUType == 1 && (regno & 0x7FF) > 1)
843 >    if ((CPUType == 1 && (regno & 0x7FF) > 1)
844 >                || (CPUType < 4 && (regno & 0x7FF) > 2)
845 >                || (CPUType == 4 && regno == 0x802))
846 >    {
847          op_illg (0x4E7A);
848 <    else
848 >        return 0;
849 >    } else {
850          switch (regno) {
851           case 0: *regp = regs.sfc; break;
852           case 1: *regp = regs.dfc; break;
# Line 768 | Line 861 | void m68k_movec2 (int regno, uae_u32 *re
861           case 0x802: *regp = caar; break;
862           case 0x803: *regp = regs.m == 1 ? m68k_areg(regs, 7) : regs.msp; break;
863           case 0x804: *regp = regs.m == 0 ? m68k_areg(regs, 7) : regs.isp; break;
864 +        case 0x805: *regp = mmusr; break;
865 +        case 0x806: *regp = urp; break;
866 +        case 0x807: *regp = srp; break;
867           default:
868              op_illg (0x4E7A);
869 <            break;
869 >            return 0;
870 >        }
871          }
872 +        return 1;
873   }
874  
875   static __inline__ int
# Line 1029 | Line 1127 | static char* ccnames[] =
1127   { "T ","F ","HI","LS","CC","CS","NE","EQ",
1128    "VC","VS","PL","MI","GE","LT","GT","LE" };
1129  
1130 + // If value is greater than zero, this means we are still processing an EmulOp
1131 + // because the counter is incremented only in m68k_execute(), i.e. interpretive
1132 + // execution only
1133 + static int m68k_execute_depth = 0;
1134 +
1135   void m68k_reset (void)
1136   {
1137      m68k_areg (regs, 7) = 0x2000;
1138      m68k_setpc (ROMBaseMac + 0x2a);
1139      fill_prefetch_0 ();
1037    regs.kick_mask = 0xF80000;
1140      regs.s = 1;
1141      regs.m = 0;
1142      regs.stopped = 0;
# Line 1045 | Line 1147 | void m68k_reset (void)
1147      SET_CFLG (0);
1148      SET_VFLG (0);
1149      SET_NFLG (0);
1150 <    regs.spcflags = 0;
1150 >        SPCFLAGS_INIT( 0 );
1151      regs.intmask = 7;
1152      regs.vbr = regs.sfc = regs.dfc = 0;
1153 <    regs.fpcr = regs.fpsr = regs.fpiar = 0;
1153 >    fpu_reset();
1154 >        
1155 > #if FLIGHT_RECORDER
1156 > #if ENABLE_MON
1157 >        if (log_ptr == -1) {
1158 >                // Install "log" command in mon
1159 >                mon_add_command("log", dump_log, "log                      Dump m68k emulation log\n");
1160 >        }
1161 > #endif
1162 >        log_ptr = 0;
1163 >        memset(log, 0, sizeof(log));
1164 > #endif
1165   }
1166  
1167 < unsigned long REGPARAM2 op_illg (uae_u32 opcode)
1167 > void m68k_emulop_return(void)
1168   {
1169 <    uaecptr pc = m68k_getpc ();
1170 <
1171 <    compiler_flush_jsr_stack ();
1169 >        SPCFLAGS_SET( SPCFLAG_BRK );
1170 >        quit_program = 1;
1171 > }
1172  
1173 <        if ((opcode & 0xFF00) == 0x7100) {
1173 > void m68k_emulop(uae_u32 opcode)
1174 > {
1175                  struct M68kRegisters r;
1176                  int i;
1177  
1064                // Return from Execute68k()?
1065                if (opcode == M68K_EXEC_RETURN) {
1066                        regs.spcflags |= SPCFLAG_BRK;
1067                        quit_program = 1;
1068                        return 4;
1069                }
1070
1071                // Call EMUL_OP opcode
1178                  for (i=0; i<8; i++) {
1179                          r.d[i] = m68k_dreg(regs, i);
1180                          r.a[i] = m68k_areg(regs, i);
# Line 1082 | Line 1188 | unsigned long REGPARAM2 op_illg (uae_u32
1188                  }
1189                  regs.sr = r.sr;
1190                  MakeFromSR();
1191 <                m68k_incpc(2);
1192 <                fill_prefetch_0 ();
1193 <                return 4;
1194 <        }
1191 > }
1192 >
1193 > cpuop_rettype REGPARAM2 op_illg (uae_u32 opcode)
1194 > {
1195 >        uaecptr pc = m68k_getpc ();
1196  
1197      if ((opcode & 0xF000) == 0xA000) {
1198          Exception(0xA,0);
1199 <        return 4;
1199 >        cpuop_return(CFLOW_TRAP);
1200      }
1201  
1095    write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc);
1096
1202      if ((opcode & 0xF000) == 0xF000) {
1203          Exception(0xB,0);
1204 <        return 4;
1204 >        cpuop_return(CFLOW_TRAP);
1205      }
1206  
1207 +    write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc);
1208 + #if USE_JIT && JIT_DEBUG
1209 +    compiler_dumpstate();
1210 + #endif
1211 +
1212      Exception (4,0);
1213 <    return 4;
1213 >        cpuop_return(CFLOW_TRAP);
1214   }
1215  
1216   void mmu_op(uae_u32 opcode, uae_u16 extra)
1217   {
1218 <    if ((extra & 0xB000) == 0) { /* PMOVE instruction */
1219 <
1220 <    } else if ((extra & 0xF000) == 0x2000) { /* PLOAD instruction */
1221 <    } else if ((extra & 0xF000) == 0x8000) { /* PTEST instruction */
1218 >    if ((opcode & 0xFE0) == 0x0500) {
1219 >                /* PFLUSH */
1220 >                mmusr = 0;
1221 >        } else if ((opcode & 0x0FD8) == 0x548) {
1222 >                /* PTEST */
1223      } else
1224 <        op_illg (opcode);
1224 >                op_illg (opcode);
1225   }
1226  
1227   static int n_insns = 0, n_spcinsns = 0;
# Line 1119 | Line 1230 | static uaecptr last_trace_ad = 0;
1230  
1231   static void do_trace (void)
1232   {
1233 <    if (regs.t0) {
1233 >    if (regs.t0 && CPUType >= 2) {
1234         uae_u16 opcode;
1235         /* should also include TRAP, CHK, SR modification FPcc */
1236         /* probably never used so why bother */
1237         /* We can afford this to be inefficient... */
1238         m68k_setpc (m68k_getpc ());
1239         fill_prefetch_0 ();
1240 <       opcode = get_word (regs.pc);
1240 >       opcode = get_word(m68k_getpc());
1241         if (opcode == 0x4e72            /* RTE */
1242             || opcode == 0x4e74                 /* RTD */
1243             || opcode == 0x4e75                 /* RTS */
# Line 1142 | Line 1253 | static void do_trace (void)
1253                 && (uae_s16)m68k_dreg(regs, opcode & 7) != 0))
1254        {
1255              last_trace_ad = m68k_getpc ();
1256 <            regs.spcflags &= ~SPCFLAG_TRACE;
1257 <            regs.spcflags |= SPCFLAG_DOTRACE;
1256 >                SPCFLAGS_CLEAR( SPCFLAG_TRACE );
1257 >                SPCFLAGS_SET( SPCFLAG_DOTRACE );
1258          }
1259      } else if (regs.t1) {
1260         last_trace_ad = m68k_getpc ();
1261 <       regs.spcflags &= ~SPCFLAG_TRACE;
1262 <       regs.spcflags |= SPCFLAG_DOTRACE;
1261 >       SPCFLAGS_CLEAR( SPCFLAG_TRACE );
1262 >       SPCFLAGS_SET( SPCFLAG_DOTRACE );
1263      }
1264   }
1265  
1266 <
1156 < static int do_specialties (void)
1266 > int m68k_do_specialties (void)
1267   {
1268 <    /*n_spcinsns++;*/
1269 <    run_compiled_code();
1270 <    if (regs.spcflags & SPCFLAG_DOTRACE) {
1268 > #if USE_JIT
1269 >    // Block was compiled
1270 >    SPCFLAGS_CLEAR( SPCFLAG_JIT_END_COMPILE );
1271 >
1272 >    // Retain the request to get out of compiled code until
1273 >    // we reached the toplevel execution, i.e. the one that
1274 >    // can compile then run compiled code. This also means
1275 >    // we processed all (nested) EmulOps
1276 >    if ((m68k_execute_depth == 0) && SPCFLAGS_TEST( SPCFLAG_JIT_EXEC_RETURN ))
1277 >        SPCFLAGS_CLEAR( SPCFLAG_JIT_EXEC_RETURN );
1278 > #endif
1279 >        
1280 >    if (SPCFLAGS_TEST( SPCFLAG_DOTRACE )) {
1281          Exception (9,last_trace_ad);
1282      }
1283 <    while (regs.spcflags & SPCFLAG_STOP) {
1284 <        if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)){
1283 >    while (SPCFLAGS_TEST( SPCFLAG_STOP )) {
1284 >        if (SPCFLAGS_TEST( SPCFLAG_INT | SPCFLAG_DOINT )){
1285 >                SPCFLAGS_CLEAR( SPCFLAG_INT | SPCFLAG_DOINT );
1286              int intr = intlev ();
1166            regs.spcflags &= ~(SPCFLAG_INT | SPCFLAG_DOINT);
1287              if (intr != -1 && intr > regs.intmask) {
1288                  Interrupt (intr);
1289                  regs.stopped = 0;
1290 <                regs.spcflags &= ~SPCFLAG_STOP;
1290 >                SPCFLAGS_CLEAR( SPCFLAG_STOP );
1291              }
1292          }
1293      }
1294 <    if (regs.spcflags & SPCFLAG_TRACE)
1294 >    if (SPCFLAGS_TEST( SPCFLAG_TRACE ))
1295         do_trace ();
1296  
1297 <    if (regs.spcflags & SPCFLAG_DOINT) {
1297 >    if (SPCFLAGS_TEST( SPCFLAG_DOINT )) {
1298 >        SPCFLAGS_CLEAR( SPCFLAG_DOINT );
1299          int intr = intlev ();
1179        regs.spcflags &= ~SPCFLAG_DOINT;
1300          if (intr != -1 && intr > regs.intmask) {
1301              Interrupt (intr);
1302              regs.stopped = 0;
1303          }
1304      }
1305 <    if (regs.spcflags & SPCFLAG_INT) {
1306 <        regs.spcflags &= ~SPCFLAG_INT;
1307 <        regs.spcflags |= SPCFLAG_DOINT;
1308 <    }
1309 <    if (regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)) {
1310 <        regs.spcflags &= ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
1311 <        return 1;
1305 >    if (SPCFLAGS_TEST( SPCFLAG_INT )) {
1306 >        SPCFLAGS_CLEAR( SPCFLAG_INT );
1307 >        SPCFLAGS_SET( SPCFLAG_DOINT );
1308 >    }
1309 >    if (SPCFLAGS_TEST( SPCFLAG_BRK )) {
1310 >        SPCFLAGS_CLEAR( SPCFLAG_BRK );
1311 >        return CFLOW_EXEC_RETURN;
1312      }
1313      return 0;
1314   }
1315  
1316 < static void m68k_run_1 (void)
1316 > void m68k_do_execute (void)
1317   {
1318 <    for (;;) {
1319 <        int cycles;
1320 <        uae_u32 opcode = GET_OPCODE;
1321 < #if 0
1202 <        if (get_ilong (0) != do_get_mem_long (&regs.prefetch)) {
1203 <            debugging = 1;
1204 <            return;
1205 <        }
1318 >        for (;;) {
1319 >                uae_u32 opcode = GET_OPCODE;
1320 > #if FLIGHT_RECORDER
1321 >                m68k_record_step(m68k_getpc());
1322   #endif
1323 <        /* assert (!regs.stopped && !(regs.spcflags & SPCFLAG_STOP)); */
1324 < /*      regs_backup[backup_pointer = (backup_pointer + 1) % 16] = regs;*/
1325 < #if COUNT_INSTRS == 2
1326 <        if (table68k[cft_map (opcode)].handler != -1)
1211 <            instrcount[table68k[cft_map (opcode)].handler]++;
1212 < #elif COUNT_INSTRS == 1
1213 <        instrcount[opcode]++;
1214 < #endif
1215 < #if defined(X86_ASSEMBLYxxx)
1216 <        __asm__ __volatile__("\tcall *%%ebx"
1217 <                             : "=&a" (cycles) : "b" (cpufunctbl[opcode]), "0" (opcode)
1218 <                             : "%edx", "%ecx",
1219 <                             "%esi", "%edi", "%ebp", "memory", "cc");
1323 > #ifdef X86_ASSEMBLY
1324 >                __asm__ __volatile__("\tpushl %%ebp\n\tcall *%%ebx\n\tpopl %%ebp" /* FIXME */
1325 >                                                         : : "b" (cpufunctbl[opcode]), "a" (opcode)
1326 >                                                         : "%edx", "%ecx", "%esi", "%edi",  "%ebp", "memory", "cc");
1327   #else
1328 <        cycles = (*cpufunctbl[opcode])(opcode);
1328 >                (*cpufunctbl[opcode])(opcode);
1329   #endif
1330 <        /*n_insns++;*/
1331 <        if (regs.spcflags) {
1332 <            if (do_specialties ())
1333 <                return;
1330 >        if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) {
1331 >            if (m68k_do_specialties())
1332 >                                return;
1333 >                }
1334          }
1228    }
1335   }
1336  
1337 < #ifdef X86_ASSEMBLYxxx
1338 < static __inline__ void m68k_run1 (void)
1337 > #if USE_JIT
1338 > void m68k_compile_execute (void)
1339   {
1340 <    /* Work around compiler bug: GCC doesn't push %ebp in m68k_run_1. */
1341 <    __asm__ __volatile__ ("pushl %%ebp\n\tcall *%0\n\tpopl %%ebp" : : "r" (m68k_run_1) : "%eax", "%edx", "%ecx", "memory", "cc");
1340 >    for (;;) {
1341 >        if (quit_program > 0) {
1342 >            if (quit_program == 1)
1343 >                break;
1344 >            quit_program = 0;
1345 >            m68k_reset ();
1346 >        }
1347 >        m68k_do_compile_execute();
1348 >    }
1349 >    if (debugging) {
1350 >        uaecptr nextpc;
1351 >        m68k_dumpstate(&nextpc);
1352 >        exit(1);
1353 >    }
1354   }
1237 #else
1238 #define m68k_run1 m68k_run_1
1355   #endif
1356  
1357 < int in_m68k_go = 0;
1242 <
1243 < void m68k_go (int may_quit)
1357 > void m68k_execute (void)
1358   {
1359 < // m68k_go() must be reentrant for Execute68k() and Execute68kTrap() to work
1360 < /*
1361 <    if (in_m68k_go || !may_quit) {
1362 <        write_log("Bug! m68k_go is not reentrant.\n");
1249 <        abort();
1250 <    }
1251 < */
1252 <    in_m68k_go++;
1359 > #if USE_JIT
1360 >    ++m68k_execute_depth;
1361 > #endif
1362 >        
1363      for (;;) {
1364          if (quit_program > 0) {
1365              if (quit_program == 1)
# Line 1257 | Line 1367 | void m68k_go (int may_quit)
1367              quit_program = 0;
1368              m68k_reset ();
1369          }
1370 <        m68k_run1();
1370 >        m68k_do_execute();
1371      }
1372          if (debugging) {
1373                  uaecptr nextpc;
1374                  m68k_dumpstate(&nextpc);
1375                  exit(1);
1376          }
1377 <    in_m68k_go--;
1377 >        
1378 > #if USE_JIT
1379 >    --m68k_execute_depth;
1380 > #endif
1381   }
1382  
1383   static void m68k_verify (uaecptr addr, uaecptr *nextpc)
# Line 1373 | Line 1486 | void m68k_dumpstate (uaecptr *nextpc)
1486      printf ("T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d\n",
1487              regs.t1, regs.t0, regs.s, regs.m,
1488              GET_XFLG, GET_NFLG, GET_ZFLG, GET_VFLG, GET_CFLG, regs.intmask);
1489 <    for (i = 0; i < 8; i++){
1490 <        printf ("FP%d: %g ", i, regs.fp[i]);
1491 <        if ((i & 3) == 3) printf ("\n");
1492 <    }
1380 <    printf ("N=%d Z=%d I=%d NAN=%d\n",
1381 <                (regs.fpsr & 0x8000000) != 0,
1382 <                (regs.fpsr & 0x4000000) != 0,
1383 <                (regs.fpsr & 0x2000000) != 0,
1384 <                (regs.fpsr & 0x1000000) != 0);
1385 <
1489 >        
1490 >        fpu_dump_registers();
1491 >        fpu_dump_flags();
1492 >        
1493      m68k_disasm(m68k_getpc (), nextpc, 1);
1494      if (nextpc)
1495          printf ("next PC: %08lx\n", *nextpc);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines