22 |
|
#include "memory.h" |
23 |
|
#include "readcpu.h" |
24 |
|
#include "newcpu.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; |
32 |
< |
int debugging = 0; |
37 |
> |
bool quit_program = false; |
38 |
|
struct flag_struct regflags; |
39 |
|
|
40 |
|
/* Opcode of faulting instruction */ |
51 |
|
int movem_index2[256]; |
52 |
|
int movem_next[256]; |
53 |
|
|
49 |
– |
int fpp_movem_index1[256]; |
50 |
– |
int fpp_movem_index2[256]; |
51 |
– |
int fpp_movem_next[256]; |
52 |
– |
|
54 |
|
cpuop_func *cpufunctbl[65536]; |
55 |
|
|
55 |
– |
#define FLIGHT_RECORDER 0 |
56 |
– |
|
56 |
|
#if FLIGHT_RECORDER |
57 |
|
struct rec_step { |
58 |
|
uae_u32 d[8]; |
70 |
|
return name ? name : "log.68k"; |
71 |
|
} |
72 |
|
|
73 |
< |
static void record_step(uaecptr pc) |
73 |
> |
void m68k_record_step(uaecptr pc) |
74 |
|
{ |
75 |
|
for (int i = 0; i < 8; i++) { |
76 |
|
log[log_ptr].d[i] = m68k_dreg(regs, i); |
163 |
|
#endif |
164 |
|
} |
165 |
|
|
166 |
< |
static void REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM; |
166 |
> |
void REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM; |
167 |
|
|
168 |
< |
static void REGPARAM2 op_illg_1 (uae_u32 opcode) |
168 |
> |
void REGPARAM2 op_illg_1 (uae_u32 opcode) |
169 |
|
{ |
170 |
|
op_illg (cft_map (opcode)); |
171 |
|
} |
186 |
|
cpu_level = 1; |
187 |
|
} |
188 |
|
struct cputbl *tbl = ( |
189 |
< |
cpu_level == 4 ? op_smalltbl_0 |
190 |
< |
: cpu_level == 3 ? op_smalltbl_1 |
191 |
< |
: cpu_level == 2 ? op_smalltbl_2 |
192 |
< |
: cpu_level == 1 ? op_smalltbl_3 |
193 |
< |
: op_smalltbl_4); |
189 |
> |
cpu_level == 4 ? op_smalltbl_0_ff |
190 |
> |
: cpu_level == 3 ? op_smalltbl_1_ff |
191 |
> |
: cpu_level == 2 ? op_smalltbl_2_ff |
192 |
> |
: cpu_level == 1 ? op_smalltbl_3_ff |
193 |
> |
: op_smalltbl_4_ff); |
194 |
|
|
195 |
|
for (opcode = 0; opcode < 65536; opcode++) |
196 |
|
cpufunctbl[cft_map (opcode)] = op_illg_1; |
230 |
|
movem_index2[i] = 7-j; |
231 |
|
movem_next[i] = i & (~(1 << j)); |
232 |
|
} |
234 |
– |
for (i = 0 ; i < 256 ; i++) { |
235 |
– |
int j; |
236 |
– |
for (j = 7 ; j >= 0 ; j--) { |
237 |
– |
if (i & (1 << j)) break; |
238 |
– |
} |
239 |
– |
fpp_movem_index1[i] = 7-j; |
240 |
– |
fpp_movem_index2[i] = j; |
241 |
– |
fpp_movem_next[i] = i & (~(1 << j)); |
242 |
– |
} |
233 |
|
#if COUNT_INSTRS |
234 |
|
{ |
235 |
|
FILE *f = fopen (icountfilename (), "r"); |
250 |
|
do_merges (); |
251 |
|
|
252 |
|
build_cpufunctbl (); |
253 |
< |
|
254 |
< |
fpu_init (); |
255 |
< |
fpu_set_integral_fpu (CPUType == 4); |
253 |
> |
|
254 |
> |
#if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS) |
255 |
> |
spcflags_lock = B2_create_mutex(); |
256 |
> |
#endif |
257 |
> |
fpu_init(CPUType == 4); |
258 |
|
} |
259 |
|
|
260 |
|
void exit_m68k (void) |
261 |
|
{ |
262 |
|
fpu_exit (); |
263 |
+ |
#if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS) |
264 |
+ |
B2_delete_mutex(spcflags_lock); |
265 |
+ |
#endif |
266 |
|
} |
267 |
|
|
268 |
|
struct regstruct regs, lastint_regs; |
698 |
|
} |
699 |
|
} |
700 |
|
|
701 |
< |
regs.spcflags |= SPCFLAG_INT; |
701 |
> |
SPCFLAGS_SET( SPCFLAG_INT ); |
702 |
|
if (regs.t1 || regs.t0) |
703 |
< |
regs.spcflags |= SPCFLAG_TRACE; |
703 |
> |
SPCFLAGS_SET( SPCFLAG_TRACE ); |
704 |
|
else |
705 |
|
/* Keep SPCFLAG_DOTRACE, we still want a trace exception for |
706 |
|
SR-modifying instructions (including STOP). */ |
707 |
< |
regs.spcflags &= ~SPCFLAG_TRACE; |
707 |
> |
SPCFLAGS_CLEAR( SPCFLAG_TRACE ); |
708 |
|
} |
709 |
|
|
710 |
|
void Exception(int nr, uaecptr oldpc) |
769 |
|
m68k_areg(regs, 7) -= 2; |
770 |
|
put_word (m68k_areg(regs, 7), regs.sr); |
771 |
|
m68k_setpc (get_long (regs.vbr + 4*nr)); |
772 |
+ |
SPCFLAGS_SET( SPCFLAG_JIT_END_COMPILE ); |
773 |
|
fill_prefetch_0 (); |
774 |
|
regs.t1 = regs.t0 = regs.m = 0; |
775 |
< |
regs.spcflags &= ~(SPCFLAG_TRACE | SPCFLAG_DOTRACE); |
775 |
> |
SPCFLAGS_CLEAR( SPCFLAG_TRACE | SPCFLAG_DOTRACE ); |
776 |
|
} |
777 |
|
|
778 |
|
static void Interrupt(int nr) |
783 |
|
Exception(nr+24, 0); |
784 |
|
|
785 |
|
regs.intmask = nr; |
786 |
< |
regs.spcflags |= SPCFLAG_INT; |
786 |
> |
SPCFLAGS_SET( SPCFLAG_INT ); |
787 |
|
} |
788 |
|
|
789 |
|
static int caar, cacr, tc, itt0, itt1, dtt0, dtt1, mmusr, urp, srp; |
800 |
|
switch (regno) { |
801 |
|
case 0: regs.sfc = *regp & 7; break; |
802 |
|
case 1: regs.dfc = *regp & 7; break; |
803 |
< |
case 2: cacr = *regp & (CPUType < 4 ? 0x3 : 0x80008000); break; |
803 |
> |
case 2: |
804 |
> |
cacr = *regp & (CPUType < 4 ? 0x3 : 0x80008000); |
805 |
> |
#if USE_JIT |
806 |
> |
if (CPUType < 4) { |
807 |
> |
set_cache_state(cacr&1); |
808 |
> |
if (*regp & 0x08) |
809 |
> |
flush_icache(1); |
810 |
> |
} |
811 |
> |
else { |
812 |
> |
set_cache_state((cacr&0x8000) || 0); |
813 |
> |
// FIXME: The User Manual claims bit 3 of CACR is undefined |
814 |
> |
if (*regp & 0x08) |
815 |
> |
flush_icache(2); |
816 |
> |
} |
817 |
> |
#endif |
818 |
> |
break; |
819 |
|
case 3: tc = *regp & 0xc000; break; |
820 |
|
case 4: itt0 = *regp & 0xffffe364; break; |
821 |
|
case 5: itt1 = *regp & 0xffffe364; break; |
1126 |
|
{ "T ","F ","HI","LS","CC","CS","NE","EQ", |
1127 |
|
"VC","VS","PL","MI","GE","LT","GT","LE" }; |
1128 |
|
|
1129 |
+ |
// If value is greater than zero, this means we are still processing an EmulOp |
1130 |
+ |
// because the counter is incremented only in m68k_execute(), i.e. interpretive |
1131 |
+ |
// execution only |
1132 |
+ |
static int m68k_execute_depth = 0; |
1133 |
+ |
|
1134 |
|
void m68k_reset (void) |
1135 |
|
{ |
1136 |
|
m68k_areg (regs, 7) = 0x2000; |
1137 |
|
m68k_setpc (ROMBaseMac + 0x2a); |
1138 |
|
fill_prefetch_0 (); |
1123 |
– |
regs.kick_mask = 0xF80000; |
1139 |
|
regs.s = 1; |
1140 |
|
regs.m = 0; |
1141 |
|
regs.stopped = 0; |
1146 |
|
SET_CFLG (0); |
1147 |
|
SET_VFLG (0); |
1148 |
|
SET_NFLG (0); |
1149 |
< |
regs.spcflags = 0; |
1149 |
> |
SPCFLAGS_INIT( 0 ); |
1150 |
|
regs.intmask = 7; |
1151 |
|
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; */ |
1152 |
|
fpu_reset(); |
1153 |
|
|
1154 |
|
#if FLIGHT_RECORDER |
1163 |
|
#endif |
1164 |
|
} |
1165 |
|
|
1166 |
< |
void REGPARAM2 op_illg (uae_u32 opcode) |
1166 |
> |
void m68k_emulop_return(void) |
1167 |
|
{ |
1168 |
< |
uaecptr pc = m68k_getpc (); |
1168 |
> |
SPCFLAGS_SET( SPCFLAG_BRK ); |
1169 |
> |
quit_program = true; |
1170 |
> |
} |
1171 |
|
|
1172 |
< |
if ((opcode & 0xFF00) == 0x7100) { |
1172 |
> |
void m68k_emulop(uae_u32 opcode) |
1173 |
> |
{ |
1174 |
|
struct M68kRegisters r; |
1175 |
|
int i; |
1176 |
|
|
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 |
1177 |
|
for (i=0; i<8; i++) { |
1178 |
|
r.d[i] = m68k_dreg(regs, i); |
1179 |
|
r.a[i] = m68k_areg(regs, i); |
1187 |
|
} |
1188 |
|
regs.sr = r.sr; |
1189 |
|
MakeFromSR(); |
1190 |
< |
m68k_incpc(2); |
1191 |
< |
fill_prefetch_0 (); |
1192 |
< |
return; |
1193 |
< |
} |
1190 |
> |
} |
1191 |
> |
|
1192 |
> |
void REGPARAM2 op_illg (uae_u32 opcode) |
1193 |
> |
{ |
1194 |
> |
uaecptr pc = m68k_getpc (); |
1195 |
|
|
1196 |
|
if ((opcode & 0xF000) == 0xA000) { |
1197 |
|
Exception(0xA,0); |
1198 |
|
return; |
1199 |
|
} |
1200 |
|
|
1192 |
– |
// write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); |
1193 |
– |
|
1201 |
|
if ((opcode & 0xF000) == 0xF000) { |
1202 |
|
Exception(0xB,0); |
1203 |
|
return; |
1204 |
|
} |
1205 |
|
|
1206 |
|
write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); |
1207 |
+ |
#if USE_JIT && JIT_DEBUG |
1208 |
+ |
compiler_dumpstate(); |
1209 |
+ |
#endif |
1210 |
|
|
1211 |
|
Exception (4,0); |
1212 |
+ |
return; |
1213 |
|
} |
1214 |
|
|
1215 |
|
void mmu_op(uae_u32 opcode, uae_u16 extra) |
1236 |
|
/* We can afford this to be inefficient... */ |
1237 |
|
m68k_setpc (m68k_getpc ()); |
1238 |
|
fill_prefetch_0 (); |
1239 |
< |
opcode = get_word (regs.pc); |
1239 |
> |
opcode = get_word(m68k_getpc()); |
1240 |
|
if (opcode == 0x4e72 /* RTE */ |
1241 |
|
|| opcode == 0x4e74 /* RTD */ |
1242 |
|
|| opcode == 0x4e75 /* RTS */ |
1252 |
|
&& (uae_s16)m68k_dreg(regs, opcode & 7) != 0)) |
1253 |
|
{ |
1254 |
|
last_trace_ad = m68k_getpc (); |
1255 |
< |
regs.spcflags &= ~SPCFLAG_TRACE; |
1256 |
< |
regs.spcflags |= SPCFLAG_DOTRACE; |
1255 |
> |
SPCFLAGS_CLEAR( SPCFLAG_TRACE ); |
1256 |
> |
SPCFLAGS_SET( SPCFLAG_DOTRACE ); |
1257 |
|
} |
1258 |
|
} else if (regs.t1) { |
1259 |
|
last_trace_ad = m68k_getpc (); |
1260 |
< |
regs.spcflags &= ~SPCFLAG_TRACE; |
1261 |
< |
regs.spcflags |= SPCFLAG_DOTRACE; |
1260 |
> |
SPCFLAGS_CLEAR( SPCFLAG_TRACE ); |
1261 |
> |
SPCFLAGS_SET( SPCFLAG_DOTRACE ); |
1262 |
|
} |
1263 |
|
} |
1264 |
|
|
1265 |
< |
|
1255 |
< |
static int do_specialties (void) |
1265 |
> |
int m68k_do_specialties (void) |
1266 |
|
{ |
1267 |
< |
/*n_spcinsns++;*/ |
1268 |
< |
if (regs.spcflags & SPCFLAG_DOTRACE) { |
1267 |
> |
#if USE_JIT |
1268 |
> |
// Block was compiled |
1269 |
> |
SPCFLAGS_CLEAR( SPCFLAG_JIT_END_COMPILE ); |
1270 |
> |
|
1271 |
> |
// Retain the request to get out of compiled code until |
1272 |
> |
// we reached the toplevel execution, i.e. the one that |
1273 |
> |
// can compile then run compiled code. This also means |
1274 |
> |
// we processed all (nested) EmulOps |
1275 |
> |
if ((m68k_execute_depth == 0) && SPCFLAGS_TEST( SPCFLAG_JIT_EXEC_RETURN )) |
1276 |
> |
SPCFLAGS_CLEAR( SPCFLAG_JIT_EXEC_RETURN ); |
1277 |
> |
#endif |
1278 |
> |
|
1279 |
> |
if (SPCFLAGS_TEST( SPCFLAG_DOTRACE )) { |
1280 |
|
Exception (9,last_trace_ad); |
1281 |
|
} |
1282 |
< |
while (regs.spcflags & SPCFLAG_STOP) { |
1283 |
< |
if (regs.spcflags & (SPCFLAG_INT | SPCFLAG_DOINT)){ |
1282 |
> |
while (SPCFLAGS_TEST( SPCFLAG_STOP )) { |
1283 |
> |
if (SPCFLAGS_TEST( SPCFLAG_INT | SPCFLAG_DOINT )){ |
1284 |
> |
SPCFLAGS_CLEAR( SPCFLAG_INT | SPCFLAG_DOINT ); |
1285 |
|
int intr = intlev (); |
1264 |
– |
regs.spcflags &= ~(SPCFLAG_INT | SPCFLAG_DOINT); |
1286 |
|
if (intr != -1 && intr > regs.intmask) { |
1287 |
|
Interrupt (intr); |
1288 |
|
regs.stopped = 0; |
1289 |
< |
regs.spcflags &= ~SPCFLAG_STOP; |
1289 |
> |
SPCFLAGS_CLEAR( SPCFLAG_STOP ); |
1290 |
|
} |
1291 |
|
} |
1292 |
|
} |
1293 |
< |
if (regs.spcflags & SPCFLAG_TRACE) |
1293 |
> |
if (SPCFLAGS_TEST( SPCFLAG_TRACE )) |
1294 |
|
do_trace (); |
1295 |
|
|
1296 |
< |
if (regs.spcflags & SPCFLAG_DOINT) { |
1296 |
> |
if (SPCFLAGS_TEST( SPCFLAG_DOINT )) { |
1297 |
> |
SPCFLAGS_CLEAR( SPCFLAG_DOINT ); |
1298 |
|
int intr = intlev (); |
1277 |
– |
regs.spcflags &= ~SPCFLAG_DOINT; |
1299 |
|
if (intr != -1 && intr > regs.intmask) { |
1300 |
|
Interrupt (intr); |
1301 |
|
regs.stopped = 0; |
1302 |
|
} |
1303 |
|
} |
1304 |
< |
if (regs.spcflags & SPCFLAG_INT) { |
1305 |
< |
regs.spcflags &= ~SPCFLAG_INT; |
1306 |
< |
regs.spcflags |= SPCFLAG_DOINT; |
1304 |
> |
if (SPCFLAGS_TEST( SPCFLAG_INT )) { |
1305 |
> |
SPCFLAGS_CLEAR( SPCFLAG_INT ); |
1306 |
> |
SPCFLAGS_SET( SPCFLAG_DOINT ); |
1307 |
|
} |
1308 |
< |
if (regs.spcflags & (SPCFLAG_BRK | SPCFLAG_MODE_CHANGE)) { |
1309 |
< |
regs.spcflags &= ~(SPCFLAG_BRK | SPCFLAG_MODE_CHANGE); |
1308 |
> |
if (SPCFLAGS_TEST( SPCFLAG_BRK )) { |
1309 |
> |
SPCFLAGS_CLEAR( SPCFLAG_BRK ); |
1310 |
|
return 1; |
1311 |
|
} |
1312 |
|
return 0; |
1313 |
|
} |
1314 |
|
|
1315 |
< |
static void m68k_run_1 (void) |
1315 |
> |
void m68k_do_execute (void) |
1316 |
|
{ |
1317 |
|
for (;;) { |
1318 |
|
uae_u32 opcode = GET_OPCODE; |
1319 |
|
#if FLIGHT_RECORDER |
1320 |
< |
record_step(m68k_getpc()); |
1320 |
> |
m68k_record_step(m68k_getpc()); |
1321 |
|
#endif |
1301 |
– |
#ifdef X86_ASSEMBLY |
1302 |
– |
__asm__ __volatile__("\tpushl %%ebp\n\tcall *%%ebx\n\tpopl %%ebp" /* FIXME */ |
1303 |
– |
: : "b" (cpufunctbl[opcode]), "a" (opcode) |
1304 |
– |
: "%edx", "%ecx", "%esi", "%edi", "%ebp", "memory", "cc"); |
1305 |
– |
#else |
1322 |
|
(*cpufunctbl[opcode])(opcode); |
1323 |
< |
#endif |
1324 |
< |
if (regs.spcflags) { |
1309 |
< |
if (do_specialties()) |
1323 |
> |
if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) { |
1324 |
> |
if (m68k_do_specialties()) |
1325 |
|
return; |
1326 |
|
} |
1327 |
|
} |
1328 |
|
} |
1329 |
|
|
1330 |
< |
#define m68k_run1 m68k_run_1 |
1331 |
< |
|
1317 |
< |
int in_m68k_go = 0; |
1318 |
< |
|
1319 |
< |
void m68k_go (int may_quit) |
1330 |
> |
#if USE_JIT && !defined(X86_ASSEMBLY) |
1331 |
> |
void m68k_compile_execute (void) |
1332 |
|
{ |
1333 |
< |
// m68k_go() must be reentrant for Execute68k() and Execute68kTrap() to work |
1334 |
< |
/* |
1335 |
< |
if (in_m68k_go || !may_quit) { |
1336 |
< |
write_log("Bug! m68k_go is not reentrant.\n"); |
1325 |
< |
abort(); |
1333 |
> |
for (;;) { |
1334 |
> |
if (quit_program) |
1335 |
> |
break; |
1336 |
> |
m68k_do_compile_execute(); |
1337 |
|
} |
1338 |
< |
*/ |
1339 |
< |
in_m68k_go++; |
1338 |
> |
} |
1339 |
> |
#endif |
1340 |
> |
|
1341 |
> |
void m68k_execute (void) |
1342 |
> |
{ |
1343 |
> |
#if USE_JIT |
1344 |
> |
++m68k_execute_depth; |
1345 |
> |
#endif |
1346 |
|
for (;;) { |
1347 |
< |
if (quit_program > 0) { |
1331 |
< |
if (quit_program == 1) |
1347 |
> |
if (quit_program) |
1348 |
|
break; |
1349 |
< |
quit_program = 0; |
1334 |
< |
m68k_reset (); |
1335 |
< |
} |
1336 |
< |
m68k_run1(); |
1349 |
> |
m68k_do_execute(); |
1350 |
|
} |
1351 |
< |
if (debugging) { |
1352 |
< |
uaecptr nextpc; |
1353 |
< |
m68k_dumpstate(&nextpc); |
1341 |
< |
exit(1); |
1342 |
< |
} |
1343 |
< |
in_m68k_go--; |
1351 |
> |
#if USE_JIT |
1352 |
> |
--m68k_execute_depth; |
1353 |
> |
#endif |
1354 |
|
} |
1355 |
|
|
1356 |
|
static void m68k_verify (uaecptr addr, uaecptr *nextpc) |
1459 |
|
printf ("T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d\n", |
1460 |
|
regs.t1, regs.t0, regs.s, regs.m, |
1461 |
|
GET_XFLG, GET_NFLG, GET_ZFLG, GET_VFLG, GET_CFLG, regs.intmask); |
1462 |
< |
for (i = 0; i < 8; i++){ |
1463 |
< |
printf ("FP%d: %g ", i, regs.fp[i]); |
1464 |
< |
if ((i & 3) == 3) printf ("\n"); |
1465 |
< |
} |
1456 |
< |
printf ("N=%d Z=%d I=%d NAN=%d\n", |
1457 |
< |
(regs.fpsr & 0x8000000) != 0, |
1458 |
< |
(regs.fpsr & 0x4000000) != 0, |
1459 |
< |
(regs.fpsr & 0x2000000) != 0, |
1460 |
< |
(regs.fpsr & 0x1000000) != 0); |
1461 |
< |
|
1462 |
> |
|
1463 |
> |
fpu_dump_registers(); |
1464 |
> |
fpu_dump_flags(); |
1465 |
> |
|
1466 |
|
m68k_disasm(m68k_getpc (), nextpc, 1); |
1467 |
|
if (nextpc) |
1468 |
|
printf ("next PC: %08lx\n", *nextpc); |