From 860d7bd3f1e3f282a8959925d151840f97f2764e Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 13 Sep 2014 18:25:02 +0400 Subject: [PATCH] Small fix 2 --- rpcs3/Emu/CPU/CPUThread.cpp | 4 ++-- rpcs3/Emu/Cell/PPUThread.cpp | 6 ++++-- rpcs3/Emu/Cell/PPUThread.h | 1 - rpcs3/Emu/Cell/SPUThread.cpp | 12 ++++++++---- rpcs3/Emu/SysCalls/Callback.cpp | 21 ++++++--------------- rpcs3/Emu/SysCalls/Callback.h | 2 +- rpcs3/Emu/SysCalls/Modules/cellAdec.cpp | 6 ++++-- rpcs3/Emu/SysCalls/Modules/cellDmux.cpp | 6 ++++-- rpcs3/Emu/SysCalls/Modules/cellVdec.cpp | 6 ++++-- rpcs3/Emu/SysCalls/Modules/libmixer.cpp | 6 ++++-- rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp | 8 +++++++- 11 files changed, 44 insertions(+), 34 deletions(-) diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index 407055df5e..d27a608a49 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -287,8 +287,8 @@ void _se_translator(unsigned int u, EXCEPTION_POINTERS* pExp) if (u == EXCEPTION_ACCESS_VIOLATION && addr < 0x100000000 && t) { // TODO: allow recovering from a page fault - throw fmt::Format("Access violation: addr = 0x%x (last_syscall=0x%llx (%s))", - (u32)addr, (u64)t->m_last_syscall, SysCalls::GetHLEFuncName((u32)t->m_last_syscall).c_str()); + throw fmt::Format("Access violation: addr = 0x%x (is_alive=%d, last_syscall=0x%llx (%s))", + (u32)addr, t->IsAlive() ? 1 : 0, (u64)t->m_last_syscall, SysCalls::GetHLEFuncName((u32)t->m_last_syscall).c_str()); } else { diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 94752d653b..b0c69f4daa 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -61,8 +61,8 @@ void PPUThread::AddArgv(const std::string& arg) void PPUThread::InitRegs() { - const u32 pc = vm::read32(entry); - const u32 rtoc = vm::read32(entry + 4); + const u32 pc = entry ? vm::read32(entry) : 0; + const u32 rtoc = entry ? vm::read32(entry + 4) : 0; //ConLog.Write("entry = 0x%x", entry); //ConLog.Write("rtoc = 0x%x", rtoc); @@ -226,6 +226,7 @@ u64 PPUThread::FastCall2(u64 addr, u64 rtoc) { auto old_status = m_status; auto old_PC = PC; + auto old_stack = GPR[1]; // only saved and restored (may be wrong) auto old_rtoc = GPR[2]; auto old_LR = LR; auto old_thread = GetCurrentNamedThread(); @@ -240,6 +241,7 @@ u64 PPUThread::FastCall2(u64 addr, u64 rtoc) m_status = old_status; PC = old_PC; + GPR[1] = old_stack; GPR[2] = old_rtoc; LR = old_LR; SetCurrentNamedThread(old_thread); diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index fd30fdca16..19f16b1d61 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -792,7 +792,6 @@ public: u64 FastCall2(u64 addr, u64 rtoc); void FastStop(); -protected: virtual void DoReset() override; virtual void DoRun() override; virtual void DoPause() override; diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index b82f9047d6..985f1c5528 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -556,13 +556,17 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) m_intrtag[2].stat |= 1; if (CPUThread* t = Emu.GetCPU().GetThread(m_intrtag[2].thread)) { - if (t->GetType() == CPU_THREAD_PPU && !t->IsAlive()) + if (t->GetType() == CPU_THREAD_PPU) { + if (t->IsAlive()) + { + LOG_ERROR(Log::SPU, "%s(%s): interrupt thread was alive", __FUNCTION__, spu_ch_name[ch]); + Emu.Pause(); + return; + } PPUThread& ppu = *(PPUThread*)t; - ppu.FastStop(); - ppu.Run(); ppu.GPR[3] = ppu.m_interrupt_arg; - ppu.FastCall2(ppu.PC, ppu.GPR[2]); + ppu.FastCall2(vm::read32(ppu.entry), vm::read32(ppu.entry + 4)); } } } diff --git a/rpcs3/Emu/SysCalls/Callback.cpp b/rpcs3/Emu/SysCalls/Callback.cpp index 1425647de6..310316a6cd 100644 --- a/rpcs3/Emu/SysCalls/Callback.cpp +++ b/rpcs3/Emu/SysCalls/Callback.cpp @@ -51,26 +51,17 @@ void CallbackManager::Init() { std::lock_guard lock(m_mutex); - m_cb_thread = &Emu.GetCPU().AddThread(CPU_THREAD_PPU); - - u32 cb_shit = Memory.MainMem.AllocAlign(8); - vm::write32(cb_shit, Emu.m_ppu_thr_stop); - vm::write32(cb_shit + 4, 0); - + m_cb_thread = (PPUThread*)&Emu.GetCPU().AddThread(CPU_THREAD_PPU); m_cb_thread->SetName("Callback Thread"); - m_cb_thread->SetEntry(cb_shit); - m_cb_thread->SetPrio(1001); // ??? + m_cb_thread->SetEntry(0); + m_cb_thread->SetPrio(1001); m_cb_thread->SetStackSize(0x10000); + m_cb_thread->InitStack(); + m_cb_thread->InitRegs(); + m_cb_thread->DoRun(); thread cb_async_thread("CallbackManager::Async() thread", [this]() { - while (Emu.IsReady()) - { - m_cb_thread->WaitForAnySignal(); - } - - m_cb_thread->Run(); - SetCurrentNamedThread(m_cb_thread); while (!Emu.IsStopped()) diff --git a/rpcs3/Emu/SysCalls/Callback.h b/rpcs3/Emu/SysCalls/Callback.h index f5747e6ac5..7f5f00a3b7 100644 --- a/rpcs3/Emu/SysCalls/Callback.h +++ b/rpcs3/Emu/SysCalls/Callback.h @@ -5,7 +5,7 @@ class CallbackManager { std::vector> m_cb_list; std::vector> m_async_list; - CPUThread* m_cb_thread; + PPUThread* m_cb_thread; std::mutex m_mutex; public: diff --git a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp index 9a6ced9dae..17af4d56b7 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp @@ -251,10 +251,12 @@ u32 adecOpen(AudioDecoder* data) adec.adecCb = (PPUThread*)&Emu.GetCPU().AddThread(CPU_THREAD_PPU); adec.adecCb->SetName("Audio Decoder[" + std::to_string(adec_id) + "] Callback"); - adec.adecCb->SetEntry(0x10000); + adec.adecCb->SetEntry(0); adec.adecCb->SetPrio(1001); adec.adecCb->SetStackSize(0x10000); - adec.adecCb->Run(); + adec.adecCb->InitStack(); + adec.adecCb->InitRegs(); + adec.adecCb->DoRun(); thread t("Audio Decoder[" + std::to_string(adec_id) + "] Thread", [&]() { diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp index a3422b0e11..ee89639795 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -299,10 +299,12 @@ u32 dmuxOpen(Demuxer* data) dmux.dmuxCb = (PPUThread*)&Emu.GetCPU().AddThread(CPU_THREAD_PPU); dmux.dmuxCb->SetName("Demuxer[" + std::to_string(dmux_id) + "] Callback"); - dmux.dmuxCb->SetEntry(0x10000); + dmux.dmuxCb->SetEntry(0); dmux.dmuxCb->SetPrio(1001); dmux.dmuxCb->SetStackSize(0x10000); - dmux.dmuxCb->Run(); + dmux.dmuxCb->InitStack(); + dmux.dmuxCb->InitRegs(); + dmux.dmuxCb->DoRun(); thread t("Demuxer[" + std::to_string(dmux_id) + "] Thread", [&]() { diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp index 9d89d2c984..1da760f52b 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp @@ -186,10 +186,12 @@ u32 vdecOpen(VideoDecoder* data) vdec.vdecCb = (PPUThread*)&Emu.GetCPU().AddThread(CPU_THREAD_PPU); vdec.vdecCb->SetName("Video Decoder[" + std::to_string(vdec_id) + "] Callback"); - vdec.vdecCb->SetEntry(0x10000); + vdec.vdecCb->SetEntry(0); vdec.vdecCb->SetPrio(1001); vdec.vdecCb->SetStackSize(0x10000); - vdec.vdecCb->Run(); + vdec.vdecCb->InitStack(); + vdec.vdecCb->InitRegs(); + vdec.vdecCb->DoRun(); thread t("Video Decoder[" + std::to_string(vdec_id) + "] Thread", [&]() { diff --git a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp index d3b540cd60..2042eb1e78 100644 --- a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp +++ b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp @@ -332,10 +332,12 @@ int cellSurMixerCreate(vm::ptr config) PPUThread& cb_thread = *(PPUThread*)&Emu.GetCPU().AddThread(CPU_THREAD_PPU); cb_thread.SetName("Surmixer Callback Thread"); - cb_thread.SetEntry(0x10000); + cb_thread.SetEntry(0); cb_thread.SetPrio(1001); cb_thread.SetStackSize(0x10000); - cb_thread.Run(); + cb_thread.InitStack(); + cb_thread.InitRegs(); + cb_thread.DoRun(); while (port.m_is_audio_port_opened) { diff --git a/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp b/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp index b1cf660cc3..1114a15d8b 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp @@ -174,7 +174,7 @@ s32 sys_ppu_thread_create(vm::ptr> thread_id, u32 entry, u64 arg, s32 default: sys_ppu_thread.Error("sys_ppu_thread_create(): unknown flags value (0x%llx)", flags); return CELL_EPERM; } - CPUThread& new_thread = Emu.GetCPU().AddThread(CPU_THREAD_PPU); + PPUThread& new_thread = *(PPUThread*)&Emu.GetCPU().AddThread(CPU_THREAD_PPU); *thread_id = new_thread.GetId(); new_thread.SetEntry(entry); @@ -193,6 +193,12 @@ s32 sys_ppu_thread_create(vm::ptr> thread_id, u32 entry, u64 arg, s32 new_thread.Run(); new_thread.Exec(); } + else + { + new_thread.InitStack(); + new_thread.InitRegs(); + new_thread.DoRun(); + } return CELL_OK; }