--- BasiliskII/src/uae_cpu/newcpu.cpp 2002/09/01 15:17:13 1.13 +++ BasiliskII/src/uae_cpu/newcpu.cpp 2002/11/02 18:13:27 1.18 @@ -22,10 +22,11 @@ extern int intlev(void); // From baisili #include "memory.h" #include "readcpu.h" #include "newcpu.h" +#include "compiler/compemu.h" +#include "fpu/fpu.h" -#if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS) && defined(HAVE_PTHREADS) -#include -pthread_mutex_t spcflags_lock = PTHREAD_MUTEX_INITIALIZER; +#if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS) +B2_mutex *spcflags_lock = NULL; #endif #if ENABLE_MON @@ -33,8 +34,7 @@ pthread_mutex_t spcflags_lock = PTHREAD_ #include "mon_disass.h" #endif -int quit_program = 0; -const int debugging = 0; +bool quit_program = false; struct flag_struct regflags; /* Opcode of faulting instruction */ @@ -51,14 +51,8 @@ int movem_index1[256]; int movem_index2[256]; int movem_next[256]; -int fpp_movem_index1[256]; -int fpp_movem_index2[256]; -int fpp_movem_next[256]; - cpuop_func *cpufunctbl[65536]; -#define FLIGHT_RECORDER 0 - #if FLIGHT_RECORDER struct rec_step { uae_u32 d[8]; @@ -76,7 +70,7 @@ static const char *log_filename(void) return name ? name : "log.68k"; } -static void record_step(uaecptr pc) +void m68k_record_step(uaecptr pc) { for (int i = 0; i < 8; i++) { log[log_ptr].d[i] = m68k_dreg(regs, i); @@ -169,11 +163,11 @@ static __inline__ unsigned int cft_map ( #endif } -cpuop_rettype REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM; +void REGPARAM2 op_illg_1 (uae_u32 opcode) REGPARAM; -cpuop_rettype REGPARAM2 op_illg_1 (uae_u32 opcode) +void REGPARAM2 op_illg_1 (uae_u32 opcode) { - cpuop_return( op_illg (cft_map (opcode)) ); + op_illg (cft_map (opcode)); } static void build_cpufunctbl (void) @@ -236,15 +230,6 @@ void init_m68k (void) movem_index2[i] = 7-j; movem_next[i] = i & (~(1 << j)); } - for (i = 0 ; i < 256 ; i++) { - int j; - for (j = 7 ; j >= 0 ; j--) { - if (i & (1 << j)) break; - } - fpp_movem_index1[i] = 7-j; - fpp_movem_index2[i] = j; - fpp_movem_next[i] = i & (~(1 << j)); - } #if COUNT_INSTRS { FILE *f = fopen (icountfilename (), "r"); @@ -265,14 +250,19 @@ void init_m68k (void) do_merges (); build_cpufunctbl (); - - fpu_init (); - fpu_set_integral_fpu (CPUType == 4); + +#if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS) + spcflags_lock = B2_create_mutex(); +#endif + fpu_init(CPUType == 4); } void exit_m68k (void) { fpu_exit (); +#if defined(ENABLE_EXCLUSIVE_SPCFLAGS) && !defined(HAVE_HARDWARE_LOCKS) + B2_delete_mutex(spcflags_lock); +#endif } struct regstruct regs, lastint_regs; @@ -810,7 +800,22 @@ int m68k_move2c (int regno, uae_u32 *reg switch (regno) { case 0: regs.sfc = *regp & 7; break; case 1: regs.dfc = *regp & 7; break; - case 2: cacr = *regp & (CPUType < 4 ? 0x3 : 0x80008000); break; + case 2: + cacr = *regp & (CPUType < 4 ? 0x3 : 0x80008000); +#if USE_JIT + if (CPUType < 4) { + set_cache_state(cacr&1); + if (*regp & 0x08) + flush_icache(1); + } + else { + set_cache_state((cacr&0x8000) || 0); + // FIXME: The User Manual claims bit 3 of CACR is undefined + if (*regp & 0x08) + flush_icache(2); + } +#endif + break; case 3: tc = *regp & 0xc000; break; case 4: itt0 = *regp & 0xffffe364; break; case 5: itt1 = *regp & 0xffffe364; break; @@ -1161,7 +1166,7 @@ void m68k_reset (void) void m68k_emulop_return(void) { SPCFLAGS_SET( SPCFLAG_BRK ); - quit_program = 1; + quit_program = true; } void m68k_emulop(uae_u32 opcode) @@ -1184,24 +1189,27 @@ void m68k_emulop(uae_u32 opcode) MakeFromSR(); } -cpuop_rettype REGPARAM2 op_illg (uae_u32 opcode) +void REGPARAM2 op_illg (uae_u32 opcode) { uaecptr pc = m68k_getpc (); if ((opcode & 0xF000) == 0xA000) { Exception(0xA,0); - cpuop_return(CFLOW_TRAP); + return; } if ((opcode & 0xF000) == 0xF000) { Exception(0xB,0); - cpuop_return(CFLOW_TRAP); + return; } write_log ("Illegal instruction: %04x at %08lx\n", opcode, pc); +#if USE_JIT && JIT_DEBUG + compiler_dumpstate(); +#endif Exception (4,0); - cpuop_return(CFLOW_TRAP); + return; } void mmu_op(uae_u32 opcode, uae_u16 extra) @@ -1256,6 +1264,18 @@ static void do_trace (void) int m68k_do_specialties (void) { +#if USE_JIT + // Block was compiled + SPCFLAGS_CLEAR( SPCFLAG_JIT_END_COMPILE ); + + // Retain the request to get out of compiled code until + // we reached the toplevel execution, i.e. the one that + // can compile then run compiled code. This also means + // we processed all (nested) EmulOps + if ((m68k_execute_depth == 0) && SPCFLAGS_TEST( SPCFLAG_JIT_EXEC_RETURN )) + SPCFLAGS_CLEAR( SPCFLAG_JIT_EXEC_RETURN ); +#endif + if (SPCFLAGS_TEST( SPCFLAG_DOTRACE )) { Exception (9,last_trace_ad); } @@ -1287,7 +1307,7 @@ int m68k_do_specialties (void) } if (SPCFLAGS_TEST( SPCFLAG_BRK )) { SPCFLAGS_CLEAR( SPCFLAG_BRK ); - return CFLOW_EXEC_RETURN; + return 1; } return 0; } @@ -1297,38 +1317,40 @@ void m68k_do_execute (void) for (;;) { uae_u32 opcode = GET_OPCODE; #if FLIGHT_RECORDER - record_step(m68k_getpc()); + m68k_record_step(m68k_getpc()); #endif -#ifdef X86_ASSEMBLY - __asm__ __volatile__("\tpushl %%ebp\n\tcall *%%ebx\n\tpopl %%ebp" /* FIXME */ - : : "b" (cpufunctbl[opcode]), "a" (opcode) - : "%edx", "%ecx", "%esi", "%edi", "%ebp", "memory", "cc"); -#else (*cpufunctbl[opcode])(opcode); -#endif - if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) { - if (m68k_do_specialties()) + if (SPCFLAGS_TEST(SPCFLAG_ALL_BUT_EXEC_RETURN)) { + if (m68k_do_specialties()) return; } } } +#if USE_JIT && !defined(X86_ASSEMBLY) +void m68k_compile_execute (void) +{ + for (;;) { + if (quit_program) + break; + m68k_do_compile_execute(); + } +} +#endif + void m68k_execute (void) { +#if USE_JIT + ++m68k_execute_depth; +#endif for (;;) { - if (quit_program > 0) { - if (quit_program == 1) + if (quit_program) break; - quit_program = 0; - m68k_reset (); - } - m68k_do_execute(); + m68k_do_execute(); } - if (debugging) { - uaecptr nextpc; - m68k_dumpstate(&nextpc); - exit(1); - } +#if USE_JIT + --m68k_execute_depth; +#endif } static void m68k_verify (uaecptr addr, uaecptr *nextpc) @@ -1437,16 +1459,10 @@ void m68k_dumpstate (uaecptr *nextpc) printf ("T=%d%d S=%d M=%d X=%d N=%d Z=%d V=%d C=%d IMASK=%d\n", regs.t1, regs.t0, regs.s, regs.m, GET_XFLG, GET_NFLG, GET_ZFLG, GET_VFLG, GET_CFLG, regs.intmask); - for (i = 0; i < 8; i++){ - printf ("FP%d: %g ", i, regs.fp[i]); - if ((i & 3) == 3) printf ("\n"); - } - printf ("N=%d Z=%d I=%d NAN=%d\n", - (regs.fpsr & 0x8000000) != 0, - (regs.fpsr & 0x4000000) != 0, - (regs.fpsr & 0x2000000) != 0, - (regs.fpsr & 0x1000000) != 0); - + + fpu_dump_registers(); + fpu_dump_flags(); + m68k_disasm(m68k_getpc (), nextpc, 1); if (nextpc) printf ("next PC: %08lx\n", *nextpc);