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.11 by gbeauche, 2002-03-18T21:25:07Z vs.
Revision 1.14 by gbeauche, 2002-09-01T16:32:02Z

# Line 23 | Line 23 | extern int intlev(void);       // From baisili
23   #include "readcpu.h"
24   #include "newcpu.h"
25  
26 + #if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS)
27 + B2_mutex *spcflags_lock = NULL;
28 + #endif
29 +
30   #if ENABLE_MON
31   #include "mon.h"
32   #include "mon_disass.h"
33   #endif
34  
35   int quit_program = 0;
36 < int debugging = 0;
36 > const int debugging = 0;
37   struct flag_struct regflags;
38  
39   /* Opcode of faulting instruction */
# Line 164 | Line 168 | static __inline__ unsigned int cft_map (
168   #endif
169   }
170  
171 < static void REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM;
171 > cpuop_rettype REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM;
172  
173 < static void REGPARAM2 op_illg_1 (uae_u32 opcode)
173 > cpuop_rettype REGPARAM2 op_illg_1 (uae_u32 opcode)
174   {
175 <    op_illg (cft_map (opcode));
175 >    cpuop_return( op_illg (cft_map (opcode)) );
176   }
177  
178   static void build_cpufunctbl (void)
# Line 187 | Line 191 | static void build_cpufunctbl (void)
191                          cpu_level = 1;
192          }
193      struct cputbl *tbl = (
194 <                  cpu_level == 4 ? op_smalltbl_0
195 <                : cpu_level == 3 ? op_smalltbl_1
196 <                : cpu_level == 2 ? op_smalltbl_2
197 <                : cpu_level == 1 ? op_smalltbl_3
198 <                : op_smalltbl_4);
194 >                  cpu_level == 4 ? op_smalltbl_0_ff
195 >                : cpu_level == 3 ? op_smalltbl_1_ff
196 >                : cpu_level == 2 ? op_smalltbl_2_ff
197 >                : cpu_level == 1 ? op_smalltbl_3_ff
198 >                : op_smalltbl_4_ff);
199  
200      for (opcode = 0; opcode < 65536; opcode++)
201          cpufunctbl[cft_map (opcode)] = op_illg_1;
# Line 260 | Line 264 | void init_m68k (void)
264      do_merges ();
265  
266      build_cpufunctbl ();
267 +        
268 + #if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS)
269 +        spcflags_lock = B2_create_mutex();
270 + #endif
271      
272      fpu_init ();
273      fpu_set_integral_fpu (CPUType == 4);
# Line 268 | Line 276 | void init_m68k (void)
276   void exit_m68k (void)
277   {
278          fpu_exit ();
279 + #if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS)
280 +        B2_delete_mutex(spcflags_lock);
281 + #endif
282   }
283  
284   struct regstruct regs, lastint_regs;
# Line 703 | Line 714 | void MakeFromSR (void)
714          }
715      }
716  
717 <    regs.spcflags |= SPCFLAG_INT;
717 >    SPCFLAGS_SET( SPCFLAG_INT );
718      if (regs.t1 || regs.t0)
719 <        regs.spcflags |= SPCFLAG_TRACE;
719 >                SPCFLAGS_SET( SPCFLAG_TRACE );
720      else
721 <        regs.spcflags &= ~(SPCFLAG_TRACE | SPCFLAG_DOTRACE);
721 >        /* Keep SPCFLAG_DOTRACE, we still want a trace exception for
722 >           SR-modifying instructions (including STOP).  */
723 >                SPCFLAGS_CLEAR( SPCFLAG_TRACE );
724   }
725  
726   void Exception(int nr, uaecptr oldpc)
# Line 772 | Line 785 | kludge_me_do:
785      m68k_areg(regs, 7) -= 2;
786      put_word (m68k_areg(regs, 7), regs.sr);
787      m68k_setpc (get_long (regs.vbr + 4*nr));
788 +        SPCFLAGS_SET( SPCFLAG_JIT_END_COMPILE );
789      fill_prefetch_0 ();
790      regs.t1 = regs.t0 = regs.m = 0;
791 <    regs.spcflags &= ~(SPCFLAG_TRACE | SPCFLAG_DOTRACE);
791 >        SPCFLAGS_CLEAR( SPCFLAG_TRACE | SPCFLAG_DOTRACE );
792   }
793  
794   static void Interrupt(int nr)
# Line 785 | Line 799 | static void Interrupt(int nr)
799      Exception(nr+24, 0);
800  
801      regs.intmask = nr;
802 <    regs.spcflags |= SPCFLAG_INT;
802 >        SPCFLAGS_SET( SPCFLAG_INT );
803   }
804  
805 < static int caar, cacr, tc, itt0, itt1, dtt0, dtt1;
805 > static int caar, cacr, tc, itt0, itt1, dtt0, dtt1, mmusr, urp, srp;
806  
807   int m68k_move2c (int regno, uae_u32 *regp)
808   {
809    if ((CPUType == 1 && (regno & 0x7FF) > 1)
810 <  || (CPUType < 4 && (regno & 0x7FF) > 2)
811 <  || (CPUType == 4 && regno == 0x802))
810 >          || (CPUType < 4 && (regno & 0x7FF) > 2)
811 >          || (CPUType == 4 && regno == 0x802))
812    {
813          op_illg (0x4E7B);
814          return 0;
# Line 813 | Line 827 | int m68k_move2c (int regno, uae_u32 *reg
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              return 0;
# Line 824 | Line 841 | int m68k_move2c (int regno, uae_u32 *reg
841   int m68k_movec2 (int regno, uae_u32 *regp)
842   {
843      if ((CPUType == 1 && (regno & 0x7FF) > 1)
844 <        || (CPUType < 4 && (regno & 0x7FF) > 2)
845 <        || (CPUType == 4 && regno == 0x802))
844 >                || (CPUType < 4 && (regno & 0x7FF) > 2)
845 >                || (CPUType == 4 && regno == 0x802))
846      {
847          op_illg (0x4E7A);
848          return 0;
# Line 844 | Line 861 | int m68k_movec2 (int regno, uae_u32 *reg
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              return 0;
# Line 1107 | 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 ();
1115    regs.kick_mask = 0xF80000;
1140      regs.s = 1;
1141      regs.m = 0;
1142      regs.stopped = 0;
# Line 1123 | 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;
1129    /* gb-- moved into {fpp,fpu_x86}.cpp::fpu_init()
1130    regs.fpcr = regs.fpsr = regs.fpiar = 0; */
1153      fpu_reset();
1154          
1155   #if FLIGHT_RECORDER
# Line 1142 | Line 1164 | void m68k_reset (void)
1164   #endif
1165   }
1166  
1167 < void REGPARAM2 op_illg (uae_u32 opcode)
1167 > void m68k_emulop_return(void)
1168   {
1169 <    uaecptr pc = m68k_getpc ();
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  
1153                // Return from Exectue68k()?
1154                if (opcode == M68K_EXEC_RETURN) {
1155                        regs.spcflags |= SPCFLAG_BRK;
1156                        quit_program = 1;
1157                        return;
1158                }
1159
1160                // 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 1171 | Line 1188 | void REGPARAM2 op_illg (uae_u32 opcode)
1188                  }
1189                  regs.sr = r.sr;
1190                  MakeFromSR();
1191 <                m68k_incpc(2);
1192 <                fill_prefetch_0 ();
1193 <                return;
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;
1199 >        cpuop_return(CFLOW_TRAP);
1200      }
1201  
1184 //    write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc);
1185
1202      if ((opcode & 0xF000) == 0xF000) {
1203          Exception(0xB,0);
1204 <        return;
1204 >        cpuop_return(CFLOW_TRAP);
1205      }
1206  
1207      write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc);
1208  
1209      Exception (4,0);
1210 +        cpuop_return(CFLOW_TRAP);
1211   }
1212  
1213   void mmu_op(uae_u32 opcode, uae_u16 extra)
1214   {
1215 <    if ((extra & 0xB000) == 0) { /* PMOVE instruction */
1216 <
1217 <    } else if ((extra & 0xF000) == 0x2000) { /* PLOAD instruction */
1218 <    } else if ((extra & 0xF000) == 0x8000) { /* PTEST instruction */
1215 >    if ((opcode & 0xFE0) == 0x0500) {
1216 >                /* PFLUSH */
1217 >                mmusr = 0;
1218 >        } else if ((opcode & 0x0FD8) == 0x548) {
1219 >                /* PTEST */
1220      } else
1221 <        op_illg (opcode);
1221 >                op_illg (opcode);
1222   }
1223  
1224   static int n_insns = 0, n_spcinsns = 0;
# Line 1216 | Line 1234 | static void do_trace (void)
1234         /* We can afford this to be inefficient... */
1235         m68k_setpc (m68k_getpc ());
1236         fill_prefetch_0 ();
1237 <       opcode = get_word (regs.pc);
1237 >       opcode = get_word(m68k_getpc());
1238         if (opcode == 0x4e72            /* RTE */
1239             || opcode == 0x4e74                 /* RTD */
1240             || opcode == 0x4e75                 /* RTS */
# Line 1232 | Line 1250 | static void do_trace (void)
1250                 && (uae_s16)m68k_dreg(regs, opcode & 7) != 0))
1251        {
1252              last_trace_ad = m68k_getpc ();
1253 <            regs.spcflags &= ~SPCFLAG_TRACE;
1254 <            regs.spcflags |= SPCFLAG_DOTRACE;
1253 >                SPCFLAGS_CLEAR( SPCFLAG_TRACE );
1254 >                SPCFLAGS_SET( SPCFLAG_DOTRACE );
1255          }
1256      } else if (regs.t1) {
1257         last_trace_ad = m68k_getpc ();
1258 <       regs.spcflags &= ~SPCFLAG_TRACE;
1259 <       regs.spcflags |= SPCFLAG_DOTRACE;
1258 >       SPCFLAGS_CLEAR( SPCFLAG_TRACE );
1259 >       SPCFLAGS_SET( SPCFLAG_DOTRACE );
1260      }
1261   }
1262  
1263 <
1246 < static int do_specialties (void)
1263 > int m68k_do_specialties (void)
1264   {
1265 <    /*n_spcinsns++;*/
1249 <    if (regs.spcflags & SPCFLAG_DOTRACE) {
1265 >    if (SPCFLAGS_TEST( SPCFLAG_DOTRACE )) {
1266          Exception (9,last_trace_ad);
1267      }
1268 <    while (regs.spcflags & SPCFLAG_STOP) {
1269 <        if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)){
1268 >    while (SPCFLAGS_TEST( SPCFLAG_STOP )) {
1269 >        if (SPCFLAGS_TEST( SPCFLAG_INT | SPCFLAG_DOINT )){
1270 >                SPCFLAGS_CLEAR( SPCFLAG_INT | SPCFLAG_DOINT );
1271              int intr = intlev ();
1255            regs.spcflags &= ~(SPCFLAG_INT | SPCFLAG_DOINT);
1272              if (intr != -1 && intr > regs.intmask) {
1273                  Interrupt (intr);
1274                  regs.stopped = 0;
1275 <                regs.spcflags &= ~SPCFLAG_STOP;
1275 >                SPCFLAGS_CLEAR( SPCFLAG_STOP );
1276              }
1277          }
1278      }
1279 <    if (regs.spcflags & SPCFLAG_TRACE)
1279 >    if (SPCFLAGS_TEST( SPCFLAG_TRACE ))
1280         do_trace ();
1281  
1282 <    if (regs.spcflags & SPCFLAG_DOINT) {
1282 >    if (SPCFLAGS_TEST( SPCFLAG_DOINT )) {
1283 >        SPCFLAGS_CLEAR( SPCFLAG_DOINT );
1284          int intr = intlev ();
1268        regs.spcflags &= ~SPCFLAG_DOINT;
1285          if (intr != -1 && intr > regs.intmask) {
1286              Interrupt (intr);
1287              regs.stopped = 0;
1288          }
1289      }
1290 <    if (regs.spcflags & SPCFLAG_INT) {
1291 <        regs.spcflags &= ~SPCFLAG_INT;
1292 <        regs.spcflags |= SPCFLAG_DOINT;
1293 <    }
1294 <    if (regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)) {
1295 <        regs.spcflags &= ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE);
1296 <        return 1;
1290 >    if (SPCFLAGS_TEST( SPCFLAG_INT )) {
1291 >        SPCFLAGS_CLEAR( SPCFLAG_INT );
1292 >        SPCFLAGS_SET( SPCFLAG_DOINT );
1293 >    }
1294 >    if (SPCFLAGS_TEST( SPCFLAG_BRK )) {
1295 >        SPCFLAGS_CLEAR( SPCFLAG_BRK );
1296 >        return CFLOW_EXEC_RETURN;
1297      }
1298      return 0;
1299   }
1300  
1301 < static void m68k_run_1 (void)
1301 > void m68k_do_execute (void)
1302   {
1303          for (;;) {
1304                  uae_u32 opcode = GET_OPCODE;
1305   #if FLIGHT_RECORDER
1306                  record_step(m68k_getpc());
1307   #endif
1308 + #ifdef X86_ASSEMBLY
1309 +                __asm__ __volatile__("\tpushl %%ebp\n\tcall *%%ebx\n\tpopl %%ebp" /* FIXME */
1310 +                                                         : : "b" (cpufunctbl[opcode]), "a" (opcode)
1311 +                                                         : "%edx", "%ecx", "%esi", "%edi",  "%ebp", "memory", "cc");
1312 + #else
1313                  (*cpufunctbl[opcode])(opcode);
1314 <                if (regs.spcflags) {
1315 <                        if (do_specialties())
1314 > #endif
1315 >        if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) {
1316 >            if (m68k_do_specialties())
1317                                  return;
1318                  }
1319          }
1320   }
1321  
1322 < #define m68k_run1 m68k_run_1
1301 <
1302 < int in_m68k_go = 0;
1303 <
1304 < void m68k_go (int may_quit)
1322 > void m68k_execute (void)
1323   {
1306 // m68k_go() must be reentrant for Execute68k() and Execute68kTrap() to work
1307 /*
1308    if (in_m68k_go || !may_quit) {
1309        write_log("Bug! m68k_go is not reentrant.\n");
1310        abort();
1311    }
1312 */
1313    in_m68k_go++;
1324      for (;;) {
1325          if (quit_program > 0) {
1326              if (quit_program == 1)
# Line 1318 | Line 1328 | void m68k_go (int may_quit)
1328              quit_program = 0;
1329              m68k_reset ();
1330          }
1331 <        m68k_run1();
1331 >        m68k_do_execute();
1332      }
1333          if (debugging) {
1334                  uaecptr nextpc;
1335                  m68k_dumpstate(&nextpc);
1336                  exit(1);
1337          }
1328    in_m68k_go--;
1338   }
1339  
1340   static void m68k_verify (uaecptr addr, uaecptr *nextpc)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines