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; |
34 |
|
#include "mon_disass.h" |
35 |
|
#endif |
36 |
|
|
37 |
< |
int quit_program = 0; |
36 |
< |
const 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 |
|
|
53 |
– |
int fpp_movem_index1[256]; |
54 |
– |
int fpp_movem_index2[256]; |
55 |
– |
int fpp_movem_next[256]; |
56 |
– |
|
54 |
|
cpuop_func *cpufunctbl[65536]; |
55 |
|
|
59 |
– |
#define FLIGHT_RECORDER 0 |
60 |
– |
|
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); |
230 |
|
movem_index2[i] = 7-j; |
231 |
|
movem_next[i] = i & (~(1 << j)); |
232 |
|
} |
238 |
– |
for (i = 0 ; i < 256 ; i++) { |
239 |
– |
int j; |
240 |
– |
for (j = 7 ; j >= 0 ; j--) { |
241 |
– |
if (i & (1 << j)) break; |
242 |
– |
} |
243 |
– |
fpp_movem_index1[i] = 7-j; |
244 |
– |
fpp_movem_index2[i] = j; |
245 |
– |
fpp_movem_next[i] = i & (~(1 << j)); |
246 |
– |
} |
233 |
|
#if COUNT_INSTRS |
234 |
|
{ |
235 |
|
FILE *f = fopen (icountfilename (), "r"); |
254 |
|
#if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS) |
255 |
|
spcflags_lock = B2_create_mutex(); |
256 |
|
#endif |
257 |
< |
|
272 |
< |
fpu_init (); |
273 |
< |
fpu_set_integral_fpu (CPUType == 4); |
257 |
> |
fpu_init(CPUType == 4); |
258 |
|
} |
259 |
|
|
260 |
|
void exit_m68k (void) |
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; |
1166 |
|
void m68k_emulop_return(void) |
1167 |
|
{ |
1168 |
|
SPCFLAGS_SET( SPCFLAG_BRK ); |
1169 |
< |
quit_program = 1; |
1169 |
> |
quit_program = true; |
1170 |
|
} |
1171 |
|
|
1172 |
|
void m68k_emulop(uae_u32 opcode) |
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 |
|
cpuop_return(CFLOW_TRAP); |
1264 |
|
|
1265 |
|
int m68k_do_specialties (void) |
1266 |
|
{ |
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 |
|
} |
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 |
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 |
1322 |
|
(*cpufunctbl[opcode])(opcode); |
1323 |
< |
#endif |
1324 |
< |
if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) { |
1316 |
< |
if (m68k_do_specialties()) |
1323 |
> |
if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) { |
1324 |
> |
if (m68k_do_specialties()) |
1325 |
|
return; |
1326 |
|
} |
1327 |
|
} |
1328 |
|
} |
1329 |
|
|
1330 |
+ |
#if USE_JIT && !defined(X86_ASSEMBLY) |
1331 |
+ |
void m68k_compile_execute (void) |
1332 |
+ |
{ |
1333 |
+ |
for (;;) { |
1334 |
+ |
if (quit_program) |
1335 |
+ |
break; |
1336 |
+ |
m68k_do_compile_execute(); |
1337 |
+ |
} |
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) { |
1326 |
< |
if (quit_program == 1) |
1347 |
> |
if (quit_program) |
1348 |
|
break; |
1349 |
< |
quit_program = 0; |
1329 |
< |
m68k_reset (); |
1330 |
< |
} |
1331 |
< |
m68k_do_execute(); |
1349 |
> |
m68k_do_execute(); |
1350 |
|
} |
1351 |
< |
if (debugging) { |
1352 |
< |
uaecptr nextpc; |
1353 |
< |
m68k_dumpstate(&nextpc); |
1336 |
< |
exit(1); |
1337 |
< |
} |
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 |
< |
} |
1450 |
< |
printf ("N=%d Z=%d I=%d NAN=%d\n", |
1451 |
< |
(regs.fpsr & 0x8000000) != 0, |
1452 |
< |
(regs.fpsr & 0x4000000) != 0, |
1453 |
< |
(regs.fpsr & 0x2000000) != 0, |
1454 |
< |
(regs.fpsr & 0x1000000) != 0); |
1455 |
< |
|
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); |