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.12 by gbeauche, 2002-03-23T13:57:38Z 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          /* Keep SPCFLAG_DOTRACE, we still want a trace exception for
722             SR-modifying instructions (including STOP).  */
723 <        regs.spcflags &= ~SPCFLAG_TRACE;
723 >                SPCFLAGS_CLEAR( SPCFLAG_TRACE );
724   }
725  
726   void Exception(int nr, uaecptr oldpc)
# Line 774 | 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 787 | 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, mmusr, urp, srp;
# Line 1115 | 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 ();
1123    regs.kick_mask = 0xF80000;
1140      regs.s = 1;
1141      regs.m = 0;
1142      regs.stopped = 0;
# Line 1131 | 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;
1137    /* gb-- moved into {fpp,fpu_x86}.cpp::fpu_init()
1138    regs.fpcr = regs.fpsr = regs.fpiar = 0; */
1153      fpu_reset();
1154          
1155   #if FLIGHT_RECORDER
# Line 1150 | 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  
1161                // Return from Exectue68k()?
1162                if (opcode == M68K_EXEC_RETURN) {
1163                        regs.spcflags |= SPCFLAG_BRK;
1164                        quit_program = 1;
1165                        return;
1166                }
1167
1168                // 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 1179 | 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  
1192 //    write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc);
1193
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)
# Line 1225 | 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 1241 | 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 <
1255 < static int do_specialties (void)
1263 > int m68k_do_specialties (void)
1264   {
1265 <    /*n_spcinsns++;*/
1258 <    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 ();
1264            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 ();
1277        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;
# Line 1305 | Line 1312 | static void m68k_run_1 (void)
1312   #else
1313                  (*cpufunctbl[opcode])(opcode);
1314   #endif
1315 <                if (regs.spcflags) {
1316 <                        if (do_specialties())
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
1316 <
1317 < int in_m68k_go = 0;
1318 <
1319 < void m68k_go (int may_quit)
1322 > void m68k_execute (void)
1323   {
1321 // m68k_go() must be reentrant for Execute68k() and Execute68kTrap() to work
1322 /*
1323    if (in_m68k_go || !may_quit) {
1324        write_log("Bug! m68k_go is not reentrant.\n");
1325        abort();
1326    }
1327 */
1328    in_m68k_go++;
1324      for (;;) {
1325          if (quit_program > 0) {
1326              if (quit_program == 1)
# Line 1333 | 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          }
1343    in_m68k_go--;
1338   }
1339  
1340   static void m68k_verify (uaecptr addr, uaecptr *nextpc)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines