From: Toni Wilen Date: Mon, 8 Sep 2014 14:46:55 +0000 (+0300) Subject: Use spinlocks even when m68k is running. X-Git-Tag: 3000~47 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=28b8bbdda4243aa8f7cc8d75ab02d1b771394de9;p=francis%2Fwinuae.git Use spinlocks even when m68k is running. --- diff --git a/events.cpp b/events.cpp index aae737ef..5637a3dc 100644 --- a/events.cpp +++ b/events.cpp @@ -68,23 +68,19 @@ void do_cycles_slow (unsigned long cycles_to_add) } if (v < 0 && v2 < 0) { #ifdef WITH_PPC - if (regs.halted < 0) { - + if (ppc_state) { if (is_syncline == 1) { uae_ppc_execute_quick(0); } else { uae_ppc_execute_quick(1); } - - } else { -#endif - if (currprefs.cachesize) - pissoff = pissoff_value; - else - pissoff = pissoff_nojit_value; -#ifdef WITH_PPC } + #endif + if (currprefs.cachesize) + pissoff = pissoff_value; + else + pissoff = pissoff_nojit_value; return; } } else if (is_syncline < 0) { @@ -92,19 +88,14 @@ void do_cycles_slow (unsigned long cycles_to_add) int v = rpt - is_syncline_end; if (v < 0) { #ifdef WITH_PPC - if (regs.halted < 0) { - + if (ppc_state) { uae_ppc_execute_quick(0); - - } else { -#endif - if (currprefs.cachesize) - pissoff = pissoff_value; - else - pissoff = pissoff_nojit_value; -#ifdef WITH_PPC } #endif + if (currprefs.cachesize) + pissoff = pissoff_value; + else + pissoff = pissoff_nojit_value; return; } } diff --git a/flashrom.cpp b/flashrom.cpp index 3139219d..2f9973c1 100644 --- a/flashrom.cpp +++ b/flashrom.cpp @@ -364,6 +364,7 @@ bool flash_write(void *fdv, uaecptr addr, uae_u8 v) if (fd->rom[addr] != v) fd->modified = 1; fd->rom[addr] = v; + gui_flicker_led (LED_MD, 0, 2); return true; } @@ -400,6 +401,7 @@ bool flash_write(void *fdv, uaecptr addr, uae_u8 v) #if FLASH_LOG write_log(_T("flash chip erased\n"), addr); #endif + gui_flicker_led (LED_MD, 0, 2); return true; } else if (fd->state == 6 && v == 0x30) { int saddr = addr & ~(fd->sectorsize - 1); @@ -410,6 +412,7 @@ bool flash_write(void *fdv, uaecptr addr, uae_u8 v) #if FLASH_LOG write_log(_T("flash sector %d erased (%08x)\n"), saddr / fd->sectorsize, addr); #endif + gui_flicker_led (LED_MD, 0, 2); return true; } @@ -435,6 +438,7 @@ uae_u32 flash_read(void *fdv, uaecptr addr) v = fd->devicecode; if (a == 2) v = 0x00; + gui_flicker_led (LED_MD, 0, 1); } else if (fd->state >= 200) { v = 0; if (fd->state & 1) diff --git a/include/uae/ppc.h b/include/uae/ppc.h index 58346f5b..c1570eb9 100644 --- a/include/uae/ppc.h +++ b/include/uae/ppc.h @@ -27,7 +27,6 @@ #ifdef UAE void uae_ppc_doze(void); -void uae_ppc_sync (void); void uae_ppc_crash(void); void uae_ppc_cpu_reboot(void); void uae_ppc_cpu_stop(void); @@ -35,7 +34,6 @@ bool uae_ppc_poll_queue(void); void uae_ppc_interrupt(bool active); void uae_ppc_cpu_lock(void); bool uae_ppc_cpu_unlock(void); -bool uae_ppc_to_main_thread(void); void uae_ppc_emulate(void); void uae_ppc_reset(bool hardreset); void uae_ppc_hsync_handler(void); diff --git a/newcpu.cpp b/newcpu.cpp index 513269f6..cfe24f55 100644 --- a/newcpu.cpp +++ b/newcpu.cpp @@ -3152,26 +3152,8 @@ static void do_trace (void) } -#ifdef WITH_PPC -static void uae_ppc_poll_check(void) -{ - uae_ppc_poll_queue(); -} -#endif - static bool haltloop(void) { -#ifdef WITH_PPC - int lastintr = -1; - // m68k stopped? Move PPC emulator to main thread. - if (regs.halted < 0) { - uae_ppc_spinlock_reset(); - uae_ppc_spinlock_get(); - uae_ppc_to_main_thread(); - write_log(_T("Entered m68k haltloop with PPC active\n")); - } -#endif - while (regs.halted) { if (regs.halted >= 0) { static int prevvpos; @@ -3205,7 +3187,6 @@ static bool haltloop(void) #ifdef WITH_PPC static bool uae_ppc_poll_check_halt(void) { - uae_ppc_poll_check(); if (regs.halted) { if (haltloop()) return true; @@ -3464,19 +3445,6 @@ static int do_specialties (int cycles) return 0; } -#ifdef WITH_PPC -static void do_ppc(void) -{ - while (ppc_state && uae_ppc_poll_queue()) { - if (regs.spcflags) { - if (do_specialties(0)) { - return; - } - } - } -} -#endif - //static uae_u32 pcs[1000]; #if DEBUG_CD32CDTVIO @@ -3885,9 +3853,6 @@ static void m68k_run_jit (void) INTREQ_f (0x8008); set_special (SPCFLAG_INT); } -#ifdef WITH_PPC - do_ppc(); -#endif if (regs.spcflags) { if (do_specialties (0)) { return; @@ -3977,10 +3942,6 @@ retry: cpu_cycles = adjust_cycles (cpu_cycles); -#ifdef WITH_PPC - do_ppc(); -#endif - if (regs.spcflags) { if (do_specialties (cpu_cycles)) return; @@ -4038,10 +3999,6 @@ retry: cpu_cycles = (*cpufunctbl[regs.opcode])(regs.opcode); cpu_cycles = adjust_cycles (cpu_cycles); -#ifdef WITH_PPC - do_ppc(); -#endif - if (regs.spcflags) { if (do_specialties (cpu_cycles)) return; @@ -4179,10 +4136,6 @@ retry: (*cpufunctbl[r->opcode])(r->opcode); - #ifdef WITH_PPC - do_ppc(); - #endif - if (r->spcflags) { if (do_specialties (0)) exit = true; @@ -4220,10 +4173,6 @@ retry: cycles = adjust_cycles(cpu_cycles); do_cycles(cycles); - #ifdef WITH_PPC - do_ppc(); - #endif - if (r->spcflags) { if (do_specialties(0)) exit = true; @@ -4458,10 +4407,6 @@ retry: cpu_cycles = (*cpufunctbl[r->opcode])(r->opcode); cpu_cycles = adjust_cycles (cpu_cycles); - #ifdef WITH_PPC - do_ppc(); - #endif - if (r->spcflags) { if (do_specialties (cpu_cycles)) { break; diff --git a/ppc/pearpc/cpu/cpu_generic/ppc_opc.cpp b/ppc/pearpc/cpu/cpu_generic/ppc_opc.cpp index a3287c7b..8894a81b 100644 --- a/ppc/pearpc/cpu/cpu_generic/ppc_opc.cpp +++ b/ppc/pearpc/cpu/cpu_generic/ppc_opc.cpp @@ -855,7 +855,6 @@ void ppc_opc_sc() ppc_exception(PPC_EXC_SC); } -extern void uae_ppc_sync(void); /* * sync Synchronize * .672 @@ -863,7 +862,6 @@ extern void uae_ppc_sync(void); void ppc_opc_sync() { // NO-OP - uae_ppc_sync(); } /* diff --git a/ppc/ppc.cpp b/ppc/ppc.cpp index 8fda57e0..68bb1401 100644 --- a/ppc/ppc.cpp +++ b/ppc/ppc.cpp @@ -62,15 +62,12 @@ void uae_ppc_spinlock_release(void) } void uae_ppc_spinlock_reset(void) { - spinlock_cnt = 1; - uae_ppc_spinlock_release(); + spinlock_cnt = 0; + uae_ppc_spinlock_get(); } volatile int ppc_state; - static volatile bool ppc_thread_running; -static smp_comm_pipe ppcrequests, ppcreturn; -static smp_comm_pipe ppcquery, ppcreply; int ppc_cycle_count; static volatile bool ppc_access; static volatile int ppc_cpu_lock_state; @@ -78,6 +75,7 @@ static bool ppc_main_thread; static bool ppc_io_pipe; static bool ppc_use_spinlock; static bool ppc_init_done; +static bool ppc_cpu_init_done; static int ppc_implementation; #define CSPPC_PVR 0x00090204 @@ -298,11 +296,11 @@ static void uae_ppc_cpu_reset(void) { TRACE(_T("uae_ppc_cpu_reset\n")); initialize(); - if (!ppc_init_done) { + if (!ppc_cpu_init_done) { write_log(_T("PPC: Hard reset\n")); g_ppc_cpu_init(currprefs.cpuboard_type == BOARD_BLIZZARDPPC ? BLIZZPPC_PVR : CSPPC_PVR); map_banks(); - ppc_init_done = true; + ppc_cpu_init_done = true; } write_log(_T("PPC: Init\n")); g_ppc_cpu_set_pc(0, 0xfff00100); @@ -313,61 +311,15 @@ static void uae_ppc_cpu_reset(void) static void *ppc_thread(void *v) { - for (;;) { - uae_u32 v = read_comm_pipe_u32_blocking(&ppcrequests); - if (v == 0xffffffff) - break; - uae_ppc_spinlock_reset(); - ppc_io_pipe = true; - ppc_use_spinlock = false; - uae_ppc_cpu_reset(); - g_ppc_cpu_run_continuous(); - if (ppc_state == PPC_STATE_ACTIVE || ppc_state == PPC_STATE_SLEEP) - ppc_state = PPC_STATE_STOP; - write_log(_T("ppc_cpu_run() exited.\n")); - write_comm_pipe_u32(&ppcreturn, 0, 0); - } - + uae_ppc_cpu_reset(); + g_ppc_cpu_run_continuous(); + if (ppc_state == PPC_STATE_ACTIVE || ppc_state == PPC_STATE_SLEEP) + ppc_state = PPC_STATE_STOP; + write_log(_T("ppc_cpu_run() exited.\n")); ppc_thread_running = false; return NULL; } -bool uae_ppc_to_main_thread(void) -{ - TRACE(_T("uae_ppc_to_main_thread\n")); - - // QEMU: keep using thread - if (ppc_implementation == PPC_IMPLEMENTATION_QEMU) { - // already done? - if (ppc_io_pipe == false) - return true; - // make sure no new messages added to queue - ppc_cpu_lock_state = 1; - ppc_use_spinlock = true; - // empty queue - while (comm_pipe_has_data(&ppcquery)) - uae_ppc_poll_queue(); - ppc_io_pipe = false; - ppc_cpu_lock_state = 0; - return true; - } - - if (ppc_thread_running) { - write_log(_T("PPC: transferring PPC emulation to main thread.\n")); - uae_ppc_cpu_stop(); - write_comm_pipe_u32(&ppcrequests, 0xffffffff, 1); - while (ppc_thread_running) - sleep_millis(2); - while (comm_pipe_has_data(&ppcquery)) - uae_ppc_poll_queue(); - write_log(_T("PPC: transfer complete.\n")); - } - ppc_state = PPC_STATE_ACTIVE; - ppc_main_thread = true; - ppc_io_pipe = false; - return true; -} - void uae_ppc_execute_quick(int linetype) { if (linetype == 0) { @@ -394,84 +346,12 @@ void uae_ppc_emulate(void) g_ppc_cpu_run_single(10); } -bool uae_ppc_poll_queue(void) -{ - if (!ppc_io_pipe) - return true; - // ppc locked? - if (ppc_cpu_lock_state < 0) - return false; - - if (comm_pipe_has_data(&ppcquery)) { - ppc_access = true; - uae_u32 addr = read_comm_pipe_u32_blocking(&ppcquery); - uae_u32 size = read_comm_pipe_u32_blocking(&ppcquery); - uae_u32 data = 0, data2 = 0; - if (size & 0x80) { - if (size & 0x08) - data2 = read_comm_pipe_u32_blocking(&ppcquery); - data = read_comm_pipe_u32_blocking(&ppcquery); - switch (size & 127) - { - case 8: - put_long(addr + 0, data2); - put_long(addr + 4, data); - break; - case 4: - put_long(addr, data); - break; - case 2: - put_word(addr, data); - break; - case 1: - put_byte(addr, data); - break; - } -#if PPC_SYNC_WRITE - write_comm_pipe_u32(&ppcreply, 0, 1); -#else - read_comm_pipe_u32_blocking(&ppcquery); -#endif - } else { - switch (size & 127) - { - case 8: - data2 = get_long(addr + 0); - data = get_long(addr + 4); - break; - case 4: - data = get_long(addr); - break; - case 2: - data = get_word(addr); - break; - case 1: - data = get_byte(addr); - break; - } - if (size & 0x08) - write_comm_pipe_u32(&ppcreply, data2, 0); - write_comm_pipe_u32(&ppcreply, data, 1); - } - ppc_access = false; - } - if (ppc_cpu_lock_state > 0) - return true; - return false; -} - -void uae_ppc_sync (void) -{ - while (ppc_thread_running && comm_pipe_has_data(&ppcquery)); -} - bool uae_ppc_direct_physical_memory_handle(uint32_t addr, uint8_t *&ptr) { - if (valid_address(addr, 0x1000)) { - ptr = get_real_address(addr); - return true; - } - return false; + ptr = get_real_address(addr); + if (!ptr) + gui_message(_T("Executing PPC code at IO address %08x!"), addr); + return true; } STATIC_INLINE bool spinlock_pre(uaecptr addr) @@ -495,28 +375,16 @@ STATIC_INLINE void spinlock_post(bool locked) bool UAECALL uae_ppc_io_mem_write(uint32_t addr, uint32_t data, int size) { bool locked = false; + while (ppc_thread_running && ppc_cpu_lock_state < 0 && ppc_state); - if (ppc_io_pipe && !valid_address(addr, size)) { - write_comm_pipe_u32(&ppcquery, addr, 0); - write_comm_pipe_u32(&ppcquery, size | 0x80, 0); - write_comm_pipe_u32(&ppcquery, data, 1); -#if PPC_SYNC_WRITE - read_comm_pipe_u32_blocking(&ppcreply); -#else - write_comm_pipe_u32(&ppcquery, data, 0); -#endif -#if PPC_ACCESS_LOG > 0 - write_log(_T("PPC io write %08x = %08x %d\n"), addr, data, size); -#endif - return true; - } #if PPC_ACCESS_LOG > 0 if (!ppc_io_pipe && !valid_address(addr, size)) { if (addr >= PPC_DEBUG_ADDR_FROM && addr < PPC_DEBUG_ADDR_TO) write_log(_T("PPC io write %08x = %08x %d\n"), addr, data, size); } #endif + locked = spinlock_pre(addr); switch (size) { @@ -537,9 +405,11 @@ bool UAECALL uae_ppc_io_mem_write(uint32_t addr, uint32_t data, int size) } spinlock_post(locked); } + #if PPC_ACCESS_LOG > 2 write_log(_T("PPC mem write %08x = %08x %d\n"), addr, data, size); #endif + return true; } @@ -550,16 +420,16 @@ bool UAECALL uae_ppc_io_mem_read(uint32_t addr, uint32_t *data, int size) while (ppc_thread_running && ppc_cpu_lock_state < 0 && ppc_state); - if (ppc_io_pipe && !valid_address(addr, size)) { - write_comm_pipe_u32(&ppcquery, addr, 0); - write_comm_pipe_u32(&ppcquery, size, 1); - v = read_comm_pipe_u32_blocking(&ppcreply); -#if PPC_ACCESS_LOG > 0 - if (addr != 0xbfe001) - write_log(_T("PPC io read %08x=%08x %d\n"), addr, v, size); -#endif - *data = v; - return true; + if (addr >= 0xdff000 && addr < 0xe00000) { + // shortcuts for common registers + if (addr == 0xdff01c) { // INTENAR + *data = intena; + return true; + } + if (addr == 0xdff01e) { // INTREQR + *data = intreq; + return true; + } } locked = spinlock_pre(addr); @@ -595,28 +465,15 @@ bool UAECALL uae_ppc_io_mem_write64(uint32_t addr, uint64_t data) bool locked = false; while (ppc_thread_running && ppc_cpu_lock_state < 0 && ppc_state); - if (ppc_io_pipe && !valid_address(addr, 8)) { -#if PPC_ACCESS_LOG > 0 - write_log(_T("PPC io write64 %08x = %08llx\n"), addr, (unsigned long long) data); -#endif - write_comm_pipe_u32(&ppcquery, addr, 0); - write_comm_pipe_u32(&ppcquery, 8 | 0x80, 0); - write_comm_pipe_u32(&ppcquery, data >> 32, 0); - write_comm_pipe_u32(&ppcquery, data & 0xffffffff, 1); -#if PPC_SYNC_WRITE - read_comm_pipe_u32_blocking(&ppcreply); -#else - write_comm_pipe_u32(&ppcquery, data, 0); -#endif - return true; - } locked = spinlock_pre(addr); put_long(addr + 0, data >> 32); put_long(addr + 4, data & 0xffffffff); spinlock_post(locked); + #if PPC_ACCESS_LOG > 2 write_log(_T("PPC mem write64 %08x = %08llx\n"), addr, data); #endif + return true; } @@ -627,25 +484,16 @@ bool UAECALL uae_ppc_io_mem_read64(uint32_t addr, uint64_t *data) while (ppc_thread_running && ppc_cpu_lock_state < 0 && ppc_state); - if (ppc_io_pipe && !valid_address(addr, 8)) { - write_comm_pipe_u32(&ppcquery, addr, 0); - write_comm_pipe_u32(&ppcquery, 8, 0); - v1 = read_comm_pipe_u32_blocking(&ppcreply); - v2 = read_comm_pipe_u32_blocking(&ppcreply); - *data = ((uint64_t)v1 << 32) | v2; -#if PPC_ACCESS_LOG > 0 - write_log(_T("PPC io read64 %08x = %08llx\n"), addr, (unsigned long long) *data); -#endif - return true; - } locked = spinlock_pre(addr); v1 = get_long(addr + 0); v2 = get_long(addr + 4); *data = ((uint64_t)v1 << 32) | v2; spinlock_post(locked); + #if PPC_ACCESS_LOG > 2 write_log(_T("PPC mem read64 %08x = %08llx\n"), addr, *data); #endif + return true; } @@ -658,13 +506,11 @@ void uae_ppc_cpu_stop(void) g_ppc_cpu_stop(); while (ppc_state != PPC_STATE_STOP && ppc_state != PPC_STATE_CRASH) { uae_ppc_wakeup(); - uae_ppc_poll_queue(); if (ppc_use_spinlock) { uae_ppc_spinlock_release(); uae_ppc_spinlock_get(); } } - read_comm_pipe_u32_blocking(&ppcreturn); ppc_state = PPC_STATE_STOP; write_log(_T("PPC stopped.\n")); } @@ -673,6 +519,11 @@ void uae_ppc_cpu_stop(void) void uae_ppc_cpu_reboot(void) { TRACE(_T("uae_ppc_cpu_reboot\n")); + + uae_ppc_spinlock_reset(); + ppc_io_pipe = false; + ppc_use_spinlock = true; + if (ppc_main_thread) { uae_ppc_cpu_reset(); } else { @@ -680,13 +531,8 @@ void uae_ppc_cpu_reboot(void) if (!ppc_thread_running) { ppc_thread_running = true; ppc_main_thread = false; - init_comm_pipe(&ppcrequests, 10, 1); - init_comm_pipe(&ppcreturn, 10, 1); - init_comm_pipe(&ppcreply, 100, 1); - init_comm_pipe(&ppcquery, 100, 1); uae_start_thread(_T("ppc"), ppc_thread, NULL, NULL); } - write_comm_pipe_u32(&ppcrequests, 1, 1); } }