From c1da446653e417b80dc03e2623e5a61bbdfc3381 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 12 Sep 2014 23:27:33 +0400 Subject: [PATCH] FastCall() removed --- Utilities/Thread.cpp | 4 +- Utilities/Thread.h | 2 +- rpcs3/Emu/Cell/PPUThread.cpp | 14 ------- rpcs3/Emu/Cell/PPUThread.h | 1 - rpcs3/Emu/Cell/SPUThread.cpp | 3 +- rpcs3/Emu/SysCalls/CB_FUNC.h | 14 +++++-- rpcs3/Emu/SysCalls/Modules/cellSync.cpp | 29 ++++++++----- rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp | 44 ++++++++++++-------- 8 files changed, 61 insertions(+), 50 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 727005e651..ab804bd2e4 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -25,10 +25,10 @@ void NamedThreadBase::SetThreadName(const std::string& name) m_name = name; } -void NamedThreadBase::WaitForAnySignal() // wait 1 ms for something +void NamedThreadBase::WaitForAnySignal(u64 time) // wait for Notify() signal or sleep { std::unique_lock lock(m_signal_mtx); - m_signal_cv.wait_for(lock, std::chrono::milliseconds(1)); + m_signal_cv.wait_for(lock, std::chrono::milliseconds(time)); } void NamedThreadBase::Notify() // wake up waiting thread or nothing diff --git a/Utilities/Thread.h b/Utilities/Thread.h index 1daeeb5f59..72daae43ab 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -21,7 +21,7 @@ public: virtual std::string GetThreadName() const; virtual void SetThreadName(const std::string& name); - void WaitForAnySignal(); + void WaitForAnySignal(u64 time = 1); void Notify(); }; diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index dfa0654251..94752d653b 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -222,20 +222,6 @@ u64 PPUThread::GetStackArg(s32 i) return vm::read64(GPR[1] + 0x70 + 0x8 * (i - 9)); } -u64 PPUThread::FastCall(u64 addr, u64 rtoc, u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7, u64 arg8) -{ - GPR[3] = arg1; - GPR[4] = arg2; - GPR[5] = arg3; - GPR[6] = arg4; - GPR[7] = arg5; - GPR[8] = arg6; - GPR[9] = arg7; - GPR[10] = arg8; - - return FastCall2(addr, rtoc); -} - u64 PPUThread::FastCall2(u64 addr, u64 rtoc) { auto old_status = m_status; diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index 4583172ff5..fd30fdca16 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -789,7 +789,6 @@ public: virtual void InitRegs(); virtual u64 GetFreeStackSize() const; u64 GetStackArg(s32 i); - u64 FastCall(u64 addr, u64 rtoc, u64 arg1 = 0, u64 arg2 = 0, u64 arg3 = 0, u64 arg4 = 0, u64 arg5 = 0, u64 arg6 = 0, u64 arg7 = 0, u64 arg8 = 0); u64 FastCall2(u64 addr, u64 rtoc); void FastStop(); diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 137b5c2326..b82f9047d6 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -561,7 +561,8 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) PPUThread& ppu = *(PPUThread*)t; ppu.FastStop(); ppu.Run(); - ppu.FastCall(ppu.PC, ppu.GPR[2], ppu.m_interrupt_arg); + ppu.GPR[3] = ppu.m_interrupt_arg; + ppu.FastCall2(ppu.PC, ppu.GPR[2]); } } } diff --git a/rpcs3/Emu/SysCalls/CB_FUNC.h b/rpcs3/Emu/SysCalls/CB_FUNC.h index 9d35e3d885..7b00d0ac70 100644 --- a/rpcs3/Emu/SysCalls/CB_FUNC.h +++ b/rpcs3/Emu/SysCalls/CB_FUNC.h @@ -1,7 +1,7 @@ #pragma once #include "Emu/Cell/PPUThread.h" -namespace vm +namespace cb_detail { enum _func_arg_type { @@ -132,14 +132,17 @@ namespace vm return _func_res::get_value(CPU); } }; +} +namespace vm +{ template __forceinline RT _ptr_base::call(PPUThread& CPU, T... args) const { const u32 pc = vm::get_ref>(m_addr); const u32 rtoc = vm::get_ref>(m_addr + 4); - return _func_caller::call(CPU, pc, rtoc, args...); + return cb_detail::_func_caller::call(CPU, pc, rtoc, args...); } template @@ -147,4 +150,9 @@ namespace vm { return call(GetCurrentPPUThread(), args...); } -} \ No newline at end of file +} + +template +struct cb_caller : public cb_detail::_func_caller +{ +}; diff --git a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp index eda13622ec..15e293c746 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp @@ -15,7 +15,7 @@ Module *cellSync = nullptr; #ifdef PRX_DEBUG #include "prx_libsre.h" u32 libsre; -u32 libsre_rtoc; +u32 libsre_rtoc; #endif s32 syncMutexInitialize(vm::ptr mutex) @@ -1081,7 +1081,8 @@ void syncLFQueueInit(vm::ptr queue, vm::ptr buffer, u32 siz s32 syncLFQueueInitialize(vm::ptr queue, vm::ptr buffer, u32 size, u32 depth, CellSyncQueueDirection direction, vm::ptr eaSignal) { #ifdef PRX_DEBUG_XXX - return GetCurrentPPUThread().FastCall(libsre + 0x205C, libsre_rtoc, queue.addr(), buffer_addr, size, depth, direction, eaSignal_addr); + return cb_caller, vm::ptr, u32, u32, CellSyncQueueDirection, vm::ptr>::call(GetCurrentPPUThread(), libsre + 0x205C, libsre_rtoc, + queue, buffer, size, depth, direction, eaSignal); #else if (!queue) @@ -1526,7 +1527,8 @@ s32 _cellSyncLFQueuePushBody(vm::ptr queue, vm::ptr if (queue->m_direction.ToBE() != se32(CELL_SYNC_QUEUE_ANY2ANY)) { #ifdef PRX_DEBUG_XXX - res = GetCurrentPPUThread().FastCall(libsre + 0x24B0, libsre_rtoc, queue.addr(), position_v.addr(), isBlocking, 0); + res = cb_caller, u32, u32, u64>::call(GetCurrentPPUThread(), libsre + 0x24B0, libsre_rtoc, + queue, position_v.addr(), isBlocking, 0); position = position_v->ToLE(); #else res = syncLFQueueGetPushPointer(queue, position, isBlocking, 0); @@ -1535,7 +1537,8 @@ s32 _cellSyncLFQueuePushBody(vm::ptr queue, vm::ptr else { #ifdef PRX_DEBUG - res = (s32)GetCurrentPPUThread().FastCall(libsre + 0x3050, libsre_rtoc, queue.addr(), position_v.addr(), isBlocking, 0); + res = cb_caller, u32, u32, u64>::call(GetCurrentPPUThread(), libsre + 0x3050, libsre_rtoc, + queue, position_v.addr(), isBlocking, 0); position = position_v->ToLE(); #else res = syncLFQueueGetPushPointer2(queue, position, isBlocking, 0); @@ -1570,7 +1573,8 @@ s32 _cellSyncLFQueuePushBody(vm::ptr queue, vm::ptr if (queue->m_direction.ToBE() != se32(CELL_SYNC_QUEUE_ANY2ANY)) { #ifdef PRX_DEBUG_XXX - res = GetCurrentPPUThread().FastCall(libsre + 0x26C0, libsre_rtoc, queue.addr(), position, 0); + res = cb_caller, s32, u64>::call(GetCurrentPPUThread(), libsre + 0x26C0, libsre_rtoc, + queue, position, 0); #else res = syncLFQueueCompletePushPointer(queue, position, nullptr); #endif @@ -1578,7 +1582,8 @@ s32 _cellSyncLFQueuePushBody(vm::ptr queue, vm::ptr else { #ifdef PRX_DEBUG - res = (s32)GetCurrentPPUThread().FastCall(libsre + 0x355C, libsre_rtoc, queue.addr(), position, 0); + res = cb_caller, s32, u64>::call(GetCurrentPPUThread(), libsre + 0x355C, libsre_rtoc, + queue, position, 0); #else res = syncLFQueueCompletePushPointer2(queue, position, nullptr); #endif @@ -1917,7 +1922,8 @@ s32 _cellSyncLFQueuePopBody(vm::ptr queue, vm::ptr buffer if (queue->m_direction.ToBE() != se32(CELL_SYNC_QUEUE_ANY2ANY)) { #ifdef PRX_DEBUG_XXX - res = GetCurrentPPUThread().FastCall(libsre + 0x2A90, libsre_rtoc, queue.addr(), position_v.addr(), isBlocking, 0, 0); + res = cb_caller, u32, u32, u64, u64>::call(GetCurrentPPUThread(), libsre + 0x2A90, libsre_rtoc, + queue, position_v.addr(), isBlocking, 0, 0); position = position_v->ToLE(); #else res = syncLFQueueGetPopPointer(queue, position, isBlocking, 0, 0); @@ -1926,7 +1932,8 @@ s32 _cellSyncLFQueuePopBody(vm::ptr queue, vm::ptr buffer else { #ifdef PRX_DEBUG - res = (s32)GetCurrentPPUThread().FastCall(libsre + 0x39AC, libsre_rtoc, queue.addr(), position_v.addr(), isBlocking, 0); + res = cb_caller, u32, u32, u64>::call(GetCurrentPPUThread(), libsre + 0x39AC, libsre_rtoc, + queue, position_v.addr(), isBlocking, 0); position = position_v->ToLE(); #else res = syncLFQueueGetPopPointer2(queue, position, isBlocking, 0); @@ -1958,7 +1965,8 @@ s32 _cellSyncLFQueuePopBody(vm::ptr queue, vm::ptr buffer if (queue->m_direction.ToBE() != se32(CELL_SYNC_QUEUE_ANY2ANY)) { #ifdef PRX_DEBUG_XXX - res = GetCurrentPPUThread().FastCall(libsre + 0x2CA8, libsre_rtoc, queue.addr(), position, 0, 0); + res = cb_caller, s32, u64, u64>::call(GetCurrentPPUThread(), libsre + 0x2CA8, libsre_rtoc, + queue, position, 0, 0); #else res = syncLFQueueCompletePopPointer(queue, position, nullptr, 0); #endif @@ -1966,7 +1974,8 @@ s32 _cellSyncLFQueuePopBody(vm::ptr queue, vm::ptr buffer else { #ifdef PRX_DEBUG - res = (s32)GetCurrentPPUThread().FastCall(libsre + 0x3EB8, libsre_rtoc, queue.addr(), position, 0, 0); + res = cb_caller, s32, u64, u64>::call(GetCurrentPPUThread(), libsre + 0x3EB8, libsre_rtoc, + queue, position, 0, 0); #else res = syncLFQueueCompletePopPointer2(queue, position, nullptr, 0); #endif diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index b01d5e6c68..0c297d4715 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -2,6 +2,7 @@ #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/SysCalls/Modules.h" +#include "Emu/SysCalls/Callback.h" #include "Emu/FS/vfsFile.h" #include "Emu/FS/vfsStreamMemory.h" @@ -224,14 +225,21 @@ vm::ptr _sys_strncpy(vm::ptr dest, vm::ptr source, u32 l return dest; } -u32 spu_printf_agcb; -u32 spu_printf_dgcb; -u32 spu_printf_atcb; -u32 spu_printf_dtcb; +typedef s32(*spu_printf_cb_t)(u32 arg); -s32 _sys_spu_printf_initialize(u32 agcb, u32 dgcb, u32 atcb, u32 dtcb) +vm::ptr spu_printf_agcb; +vm::ptr spu_printf_dgcb; +vm::ptr spu_printf_atcb; +vm::ptr spu_printf_dtcb; + +s32 _sys_spu_printf_initialize( + vm::ptr agcb, + vm::ptr dgcb, + vm::ptr atcb, + vm::ptr dtcb) { - sysPrxForUser->Warning("_sys_spu_printf_initialize(agcb=0x%x, dgcb=0x%x, atcb=0x%x, dtcb=0x%x)", agcb, dgcb, atcb, dtcb); + sysPrxForUser->Warning("_sys_spu_printf_initialize(agcb_addr=0x%x, dgcb_addr=0x%x, atcb_addr=0x%x, dtcb_addr=0x%x)", + agcb.addr(), dgcb.addr(), atcb.addr(), dtcb.addr()); // prx: register some callbacks spu_printf_agcb = agcb; @@ -245,10 +253,10 @@ s32 _sys_spu_printf_finalize() { sysPrxForUser->Warning("_sys_spu_printf_finalize()"); - spu_printf_agcb = 0; - spu_printf_dgcb = 0; - spu_printf_atcb = 0; - spu_printf_dtcb = 0; + spu_printf_agcb.set(0); + spu_printf_dgcb.set(0); + spu_printf_atcb.set(0); + spu_printf_dtcb.set(0); return CELL_OK; } @@ -261,7 +269,7 @@ s64 _sys_spu_printf_attach_group(u32 arg) return CELL_ESTAT; } - return GetCurrentPPUThread().FastCall(vm::read32(spu_printf_agcb), vm::read32(spu_printf_agcb + 4), arg); + return spu_printf_agcb(arg); } s64 _sys_spu_printf_detach_group(u32 arg) @@ -273,7 +281,7 @@ s64 _sys_spu_printf_detach_group(u32 arg) return CELL_ESTAT; } - return GetCurrentPPUThread().FastCall(vm::read32(spu_printf_dgcb), vm::read32(spu_printf_dgcb + 4), arg); + return spu_printf_dgcb(arg); } s64 _sys_spu_printf_attach_thread(u32 arg) @@ -285,7 +293,7 @@ s64 _sys_spu_printf_attach_thread(u32 arg) return CELL_ESTAT; } - return GetCurrentPPUThread().FastCall(vm::read32(spu_printf_atcb), vm::read32(spu_printf_atcb + 4), arg); + return spu_printf_atcb(arg); } s64 _sys_spu_printf_detach_thread(u32 arg) @@ -297,7 +305,7 @@ s64 _sys_spu_printf_detach_thread(u32 arg) return CELL_ESTAT; } - return GetCurrentPPUThread().FastCall(vm::read32(spu_printf_dtcb), vm::read32(spu_printf_dtcb + 4), arg); + return spu_printf_dtcb(arg); } s32 _sys_snprintf(vm::ptr dst, u32 count, vm::ptr fmt, u32 a1, u32 a2) // va_args... @@ -426,8 +434,8 @@ void sysPrxForUser_init() void sysPrxForUser_load() { - spu_printf_agcb = 0; - spu_printf_dgcb = 0; - spu_printf_atcb = 0; - spu_printf_dtcb = 0; + spu_printf_agcb.set(0); + spu_printf_dgcb.set(0); + spu_printf_atcb.set(0); + spu_printf_dtcb.set(0); } \ No newline at end of file