From 2200e6f4d9eb79d96c89660ec1ace4aa464cd88b Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 25 Jun 2014 02:16:44 +0400 Subject: [PATCH] Small fixes --- Utilities/SSemaphore.cpp | 36 ++++++---- Utilities/SSemaphore.h | 8 ++- rpcs3/Emu/Cell/RawSPUThread.h | 30 --------- rpcs3/Emu/Cell/SPUThread.h | 87 ++++++++++++++++++++++--- rpcs3/Emu/SysCalls/lv2/SC_Interrupt.cpp | 4 +- 5 files changed, 110 insertions(+), 55 deletions(-) diff --git a/Utilities/SSemaphore.cpp b/Utilities/SSemaphore.cpp index 60c0331971..ec23211dd6 100644 --- a/Utilities/SSemaphore.cpp +++ b/Utilities/SSemaphore.cpp @@ -1,29 +1,38 @@ #include "stdafx.h" #include "Utilities/SSemaphore.h" -bool SSemaphore::wait(u64 timeout) +void SSemaphore::wait() { - std::unique_lock lock(m_cv_mutex); + u32 order; + { + std::lock_guard lock(m_mutex); + order = m_in_order++; + } + + std::unique_lock cv_lock(m_cv_mutex); - u64 counter = 0; while (true) { if (Emu.IsStopped()) { - return false; + return; } - if (timeout && counter >= timeout) - { - return false; - } - m_cond.wait_for(lock, std::chrono::milliseconds(1)); - counter++; + + m_cond.wait_for(cv_lock, std::chrono::milliseconds(1)); std::lock_guard lock(m_mutex); if (m_count) { - m_count--; - return true; + if (m_out_order == order) + { + m_count--; + m_out_order++; + return; + } + else + { + m_cond.notify_one(); + } } } } @@ -32,7 +41,8 @@ bool SSemaphore::try_wait() { std::lock_guard lock(m_mutex); - if (m_count) + // TODO: ordering? + if (m_count && m_in_order == m_out_order) { m_count--; return true; diff --git a/Utilities/SSemaphore.h b/Utilities/SSemaphore.h index 4c96a9c5a3..890b445d91 100644 --- a/Utilities/SSemaphore.h +++ b/Utilities/SSemaphore.h @@ -4,6 +4,8 @@ class SSemaphore { const u32 m_max; u32 m_count; + u32 m_in_order; + u32 m_out_order; std::mutex m_mutex, m_cv_mutex; std::condition_variable m_cond; @@ -11,12 +13,16 @@ public: SSemaphore(u32 value, u32 max = 1) : m_max(max > 0 ? max : 0xffffffff) , m_count(value > m_max ? m_max : value) + , m_in_order(0) + , m_out_order(0) { } SSemaphore() : m_max(0xffffffff) , m_count(0) + , m_in_order(0) + , m_out_order(0) { } @@ -24,7 +30,7 @@ public: { } - bool wait(u64 timeout = 0); + void wait(); bool try_wait(); diff --git a/rpcs3/Emu/Cell/RawSPUThread.h b/rpcs3/Emu/Cell/RawSPUThread.h index 51164dfad6..78a3bb297d 100644 --- a/rpcs3/Emu/Cell/RawSPUThread.h +++ b/rpcs3/Emu/Cell/RawSPUThread.h @@ -2,36 +2,6 @@ #include "SPUThread.h" #include "Emu/event.h" -enum -{ - MFC_LSA_offs = 0x3004, - MFC_EAH_offs = 0x3008, - MFC_EAL_offs = 0x300C, - MFC_Size_Tag_offs = 0x3010, - MFC_Class_CMD_offs = 0x3014, - MFC_CMDStatus_offs = 0x3014, - MFC_QStatus_offs = 0x3104, - Prxy_QueryType_offs = 0x3204, - Prxy_QueryMask_offs = 0x321C, - Prxy_TagStatus_offs = 0x322C, - SPU_Out_MBox_offs = 0x4004, - SPU_In_MBox_offs = 0x400C, - SPU_MBox_Status_offs = 0x4014, - SPU_RunCntl_offs = 0x401C, - SPU_Status_offs = 0x4024, - SPU_NPC_offs = 0x4034, - SPU_RdSigNotify1_offs = 0x1400C, - SPU_RdSigNotify2_offs = 0x1C00C, -}; - -enum : u64 -{ - RAW_SPU_OFFSET = 0x0000000000100000, - RAW_SPU_BASE_ADDR = 0x00000000E0000000, - RAW_SPU_LS_OFFSET = 0x0000000000000000, - RAW_SPU_PROB_OFFSET = 0x0000000000040000, -}; - __forceinline static u32 GetRawSPURegAddrByNum(int num, int offset) { return RAW_SPU_OFFSET * num + RAW_SPU_BASE_ADDR + RAW_SPU_PROB_OFFSET + offset; diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index aa6d8d33a4..8a789cee2a 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -129,6 +129,36 @@ enum : u32 SYS_SPU_THREAD_SNR2 = 0x05C00c, }; +enum +{ + MFC_LSA_offs = 0x3004, + MFC_EAH_offs = 0x3008, + MFC_EAL_offs = 0x300C, + MFC_Size_Tag_offs = 0x3010, + MFC_Class_CMD_offs = 0x3014, + MFC_CMDStatus_offs = 0x3014, + MFC_QStatus_offs = 0x3104, + Prxy_QueryType_offs = 0x3204, + Prxy_QueryMask_offs = 0x321C, + Prxy_TagStatus_offs = 0x322C, + SPU_Out_MBox_offs = 0x4004, + SPU_In_MBox_offs = 0x400C, + SPU_MBox_Status_offs = 0x4014, + SPU_RunCntl_offs = 0x401C, + SPU_Status_offs = 0x4024, + SPU_NPC_offs = 0x4034, + SPU_RdSigNotify1_offs = 0x1400C, + SPU_RdSigNotify2_offs = 0x1C00C, +}; + +enum : u64 +{ + RAW_SPU_OFFSET = 0x0000000000100000, + RAW_SPU_BASE_ADDR = 0x00000000E0000000, + RAW_SPU_LS_OFFSET = 0x0000000000000000, + RAW_SPU_PROB_OFFSET = 0x0000000000040000, +}; + //Floating point status and control register. Unsure if this is one of the GPRs or SPRs //Is 128 bits, but bits 0-19, 24-28, 32-49, 56-60, 64-81, 88-92, 96-115, 120-124 are unused class FPSCR @@ -598,26 +628,65 @@ public: return false; } } - - //Sleep(1); // hack - - switch(cmd & ~(MFC_BARRIER_MASK | MFC_FENCE_MASK | MFC_LIST_MASK | MFC_RESULT_MASK)) + else if (ea >= RAW_SPU_BASE_ADDR && size == 4) { - case MFC_PUT_CMD: + switch (cmd & ~(MFC_BARRIER_MASK | MFC_FENCE_MASK | MFC_LIST_MASK | MFC_RESULT_MASK)) { - return Memory.Copy(ea, dmac.ls_offset + lsa, size); + case MFC_PUT_CMD: + { + Memory.Write32(ea, ReadLS32(lsa)); + return true; } - case MFC_GET_CMD: + case MFC_GET_CMD: { - return Memory.Copy(dmac.ls_offset + lsa, ea, size); + WriteLS32(lsa, Memory.Read32(ea)); + return true; } - default: + default: { ConLog.Error("DMAC::ProcessCmd(): Unknown DMA cmd."); return false; } + } + } + + //Sleep(1); // hack + + switch (cmd & ~(MFC_BARRIER_MASK | MFC_FENCE_MASK | MFC_LIST_MASK | MFC_RESULT_MASK)) + { + case MFC_PUT_CMD: + { + if (Memory.Copy(ea, dmac.ls_offset + lsa, size)) + { + return true; + } + else + { + ConLog.Error("DMAC::ProcessCmd(): PUT* cmd failed (ea=0x%llx, lsa=0x%x, size=%d)", ea, lsa, size); + return false; // TODO: page fault (?) + } + } + + case MFC_GET_CMD: + { + if (Memory.Copy(dmac.ls_offset + lsa, ea, size)) + { + return true; + } + else + { + ConLog.Error("DMAC::ProcessCmd(): GET* cmd failed (ea=0x%llx, lsa=0x%x, size=%d)", ea, lsa, size); + return false; // TODO: page fault (?) + } + } + + default: + { + ConLog.Error("DMAC::ProcessCmd(): Unknown DMA cmd."); + return false; // ??? + } } } diff --git a/rpcs3/Emu/SysCalls/lv2/SC_Interrupt.cpp b/rpcs3/Emu/SysCalls/lv2/SC_Interrupt.cpp index 78e5a22a36..95573ba690 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_Interrupt.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_Interrupt.cpp @@ -13,7 +13,7 @@ static SysCallBase sc_int("sys_interrupt"); int sys_interrupt_tag_destroy(u32 intrtag) { - sc_int.Error("sys_interrupt_tag_destroy(intrtag=%d)", intrtag); + sc_int.Warning("sys_interrupt_tag_destroy(intrtag=%d)", intrtag); u32 id = intrtag & 0xff; u32 class_id = intrtag >> 8; @@ -40,7 +40,7 @@ int sys_interrupt_tag_destroy(u32 intrtag) int sys_interrupt_thread_establish(mem32_t ih, u32 intrtag, u64 intrthread, u64 arg) { - sc_int.Error("sys_interrupt_thread_establish(ih_addr=0x%x, intrtag=%d, intrthread=%lld, arg=0x%llx)", ih.GetAddr(), intrtag, intrthread, arg); + sc_int.Warning("sys_interrupt_thread_establish(ih_addr=0x%x, intrtag=%d, intrthread=%lld, arg=0x%llx)", ih.GetAddr(), intrtag, intrthread, arg); if (!ih.IsGood()) {