diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index a98d8c6b63..5eedcc0fcd 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -12,6 +12,11 @@ NamedThreadBase* GetCurrentNamedThread() return g_tls_this_thread; } +void SetCurrentNamedThread(NamedThreadBase* value) +{ + g_tls_this_thread = value; +} + std::string NamedThreadBase::GetThreadName() const { return m_name; @@ -47,32 +52,27 @@ void ThreadBase::Start() m_destroy = false; m_alive = true; - m_executor = new std::thread( - [this]() + m_executor = new std::thread([this]() + { + SetCurrentNamedThread(this); + g_thread_count++; + + try { - g_tls_this_thread = this; - g_thread_count++; + Task(); + } + catch (const std::string& e) + { + LOG_ERROR(GENERAL, "Exception: %s", e.c_str()); + } + catch (const char* e) + { + LOG_ERROR(GENERAL, "Exception: %s", e); + } - try - { - Task(); - } - catch (const std::string& e) - { - LOG_ERROR(GENERAL, "Exception: %s", e.c_str()); - } - catch (const char* e) - { - LOG_ERROR(GENERAL, "Exception: %s", e); - } - catch (int exitcode) - { - LOG_SUCCESS(GENERAL, "Exit Code: %d", exitcode); - } - - m_alive = false; - g_thread_count--; - }); + m_alive = false; + g_thread_count--; + }); } void ThreadBase::Stop(bool wait, bool send_destroy) @@ -141,7 +141,7 @@ void thread::start(std::function func) m_thr = std::thread([func, name]() { NamedThreadBase info(name); - g_tls_this_thread = &info; + SetCurrentNamedThread(&info); g_thread_count++; try diff --git a/Utilities/Thread.h b/Utilities/Thread.h index f38ff73162..b2b7637265 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -48,6 +48,7 @@ public: }; NamedThreadBase* GetCurrentNamedThread(); +void SetCurrentNamedThread(NamedThreadBase* value); class ThreadBase : public NamedThreadBase { diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 474b603c9f..47d09f6090 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -222,13 +222,6 @@ int FPRdouble::Cmp(PPCdouble a, PPCdouble b) u64 PPUThread::FastCall(u64 addr, u64 rtoc, u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7, u64 arg8) { - auto old_status = m_status; - auto old_PC = PC; - auto old_LR = LR; - auto old_rtoc = GPR[2]; - - PC = addr; - GPR[2] = rtoc; GPR[3] = arg1; GPR[4] = arg2; GPR[5] = arg3; @@ -237,35 +230,31 @@ u64 PPUThread::FastCall(u64 addr, u64 rtoc, u64 arg1, u64 arg2, u64 arg3, u64 ar GPR[8] = arg6; GPR[9] = arg7; GPR[10] = arg8; - LR = Emu.m_ppu_thr_stop; - - Task(); - - GPR[2] = old_rtoc; - LR = old_LR; - PC = old_PC; - m_status = old_status; - - return GPR[3]; + + return FastCall2(addr, rtoc); } u64 PPUThread::FastCall2(u64 addr, u64 rtoc) { auto old_status = m_status; auto old_PC = PC; - auto old_LR = LR; auto old_rtoc = GPR[2]; + auto old_LR = LR; + auto old_thread = GetCurrentNamedThread(); + m_status = Running; PC = addr; GPR[2] = rtoc; LR = Emu.m_ppu_thr_stop; + SetCurrentNamedThread(this); Task(); + m_status = old_status; + PC = old_PC; GPR[2] = old_rtoc; LR = old_LR; - PC = old_PC; - m_status = old_status; + SetCurrentNamedThread(old_thread); return GPR[3]; } diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index a40eccdb51..86adba31be 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -225,8 +225,9 @@ s32 _sys_spu_printf_initialize(u32 agcb, u32 dgcb, u32 atcb, u32 dtcb) { sysPrxForUser->Warning("_sys_spu_printf_initialize(agcb=0x%x, dgcb=0x%x, atcb=0x%x, dtcb=0x%x)", agcb, dgcb, atcb, dtcb); + // prx: register some callbacks spu_printf_agcb = agcb; - spu_printf_dgcb = atcb; + spu_printf_dgcb = dgcb; spu_printf_atcb = atcb; spu_printf_dtcb = dtcb; return CELL_OK; @@ -291,6 +292,16 @@ s32 _sys_spu_printf_detach_thread(u32 arg) return GetCurrentPPUThread().FastCall(Memory.Read32(spu_printf_dtcb), Memory.Read32(spu_printf_dtcb + 4), arg); } +s32 _sys_printf(u32 arg1) +{ + sysPrxForUser->Todo("_sys_printf(arg1=0x%x)", arg1); + + // probably, assertion failed + LOG_WARNING(TTY, "%s", (char*)(Memory + arg1)); + Emu.Pause(); + return CELL_OK; +} + void sysPrxForUser_init() { REG_FUNC(sysPrxForUser, sys_initialize_tls); @@ -381,4 +392,6 @@ void sysPrxForUser_init() REG_FUNC(sysPrxForUser, _sys_spu_printf_detach_group); REG_FUNC(sysPrxForUser, _sys_spu_printf_attach_thread); REG_FUNC(sysPrxForUser, _sys_spu_printf_detach_thread); + + REG_FUNC(sysPrxForUser, _sys_printf); }