From 57534777d43c9bc186adff80f52c585ed2d46733 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 20 Oct 2020 18:05:59 -0400 Subject: [PATCH] Common: Move OSThreads into core Common shouldn't be depending on APIs in Core (in this, case depending on the PowerPC namespace). Because of the poor separation here, this moves OSThread functionality into core, so that it resolves the implicit dependency on core. --- Source/Core/Common/CMakeLists.txt | 2 - Source/Core/Common/Common.vcxproj | 2 - Source/Core/Common/Common.vcxproj.filters | 6 --- Source/Core/Core/CMakeLists.txt | 2 + Source/Core/Core/Core.vcxproj | 2 + Source/Core/Core/Core.vcxproj.filters | 22 +++++---- .../Debug => Core/Debugger}/OSThread.cpp | 46 ++++++++++--------- .../Debug => Core/Debugger}/OSThread.h | 6 +-- .../Core/Core/Debugger/PPCDebugInterface.cpp | 6 +-- 9 files changed, 49 insertions(+), 45 deletions(-) rename Source/Core/{Common/Debug => Core/Debugger}/OSThread.cpp (80%) rename Source/Core/{Common/Debug => Core/Debugger}/OSThread.h (97%) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 9592043954..cadb12163d 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -34,8 +34,6 @@ add_library(common Crypto/ec.h Debug/MemoryPatches.cpp Debug/MemoryPatches.h - Debug/OSThread.cpp - Debug/OSThread.h Debug/Threads.h Debug/Watches.cpp Debug/Watches.h diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 47e8957fe4..c45edb1b59 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -48,7 +48,6 @@ - @@ -191,7 +190,6 @@ - diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index 6ae672b770..0db5b561d0 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -273,9 +273,6 @@ Debug - - Debug - Debug @@ -365,9 +362,6 @@ Debug - - Debug - GL\GLInterface diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index f39b52ed9f..017695ce45 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -80,6 +80,8 @@ add_library(core Debugger/Dump.cpp Debugger/Dump.h Debugger/GCELF.h + Debugger/OSThread.cpp + Debugger/OSThread.h Debugger/PPCDebugInterface.cpp Debugger/PPCDebugInterface.h Debugger/RSO.cpp diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 390b467614..35dd58d202 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -40,6 +40,7 @@ + @@ -399,6 +400,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 91553ac3af..73b159219f 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -217,6 +217,9 @@ Debugger + + Debugger + Debugger @@ -996,12 +999,12 @@ PowerPC\Jit64 - - HW %28Flipper/Hollywood%29\EXI - Expansion Interface\BBA - - - HW %28Flipper/Hollywood%29\EXI - Expansion Interface\BBA - + + HW %28Flipper/Hollywood%29\EXI - Expansion Interface\BBA + + + HW %28Flipper/Hollywood%29\EXI - Expansion Interface\BBA + @@ -1050,6 +1053,9 @@ Debugger + + Debugger + Debugger @@ -1755,8 +1761,8 @@ PowerPC\JitArmCommon - - HW %28Flipper/Hollywood%29\EXI - Expansion Interface\BBA + + HW %28Flipper/Hollywood%29\EXI - Expansion Interface\BBA diff --git a/Source/Core/Common/Debug/OSThread.cpp b/Source/Core/Core/Debugger/OSThread.cpp similarity index 80% rename from Source/Core/Common/Debug/OSThread.cpp rename to Source/Core/Core/Debugger/OSThread.cpp index 809e5adccd..18a5a31b83 100644 --- a/Source/Core/Common/Debug/OSThread.cpp +++ b/Source/Core/Core/Debugger/OSThread.cpp @@ -2,20 +2,22 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include "Common/Debug/OSThread.h" +#include "Core/Debugger/OSThread.h" #include #include #include "Core/PowerPC/MMU.h" +namespace Core::Debug +{ // Context offsets based on the following functions: // - OSSaveContext // - OSSaveFPUContext // - OSDumpContext // - OSClearContext // - OSExceptionVector -void Common::Debug::OSContext::Read(u32 addr) +void OSContext::Read(u32 addr) { for (std::size_t i = 0; i < gpr.size(); i++) gpr[i] = PowerPC::HostRead_U32(addr + u32(i * sizeof(int))); @@ -41,7 +43,7 @@ void Common::Debug::OSContext::Read(u32 addr) // - OSInitMutex // - OSLockMutex // - __OSUnlockAllMutex -void Common::Debug::OSMutex::Read(u32 addr) +void OSMutex::Read(u32 addr) { thread_queue.head = PowerPC::HostRead_U32(addr); thread_queue.tail = PowerPC::HostRead_U32(addr + 0x4); @@ -63,7 +65,7 @@ void Common::Debug::OSMutex::Read(u32 addr) // - __OSThreadInit // - OSSetThreadSpecific // - SOInit (for errno) -void Common::Debug::OSThread::Read(u32 addr) +void OSThread::Read(u32 addr) { context.Read(addr); state = PowerPC::HostRead_U16(addr + 0x2c8); @@ -94,25 +96,25 @@ void Common::Debug::OSThread::Read(u32 addr) specific[1] = PowerPC::HostRead_U32(addr + 0x314); } -bool Common::Debug::OSThread::IsValid() const +bool OSThread::IsValid() const { return PowerPC::HostIsRAMAddress(stack_end) && PowerPC::HostRead_U32(stack_end) == STACK_MAGIC; } -Common::Debug::OSThreadView::OSThreadView(u32 addr) +OSThreadView::OSThreadView(u32 addr) { m_address = addr; m_thread.Read(addr); } -const Common::Debug::OSThread& Common::Debug::OSThreadView::Data() const +const OSThread& OSThreadView::Data() const { return m_thread; } -Common::Debug::PartialContext Common::Debug::OSThreadView::GetContext() const +Common::Debug::PartialContext OSThreadView::GetContext() const { - PartialContext context; + Common::Debug::PartialContext context; if (!IsValid()) return context; @@ -134,57 +136,57 @@ Common::Debug::PartialContext Common::Debug::OSThreadView::GetContext() const return context; } -u32 Common::Debug::OSThreadView::GetAddress() const +u32 OSThreadView::GetAddress() const { return m_address; } -u16 Common::Debug::OSThreadView::GetState() const +u16 OSThreadView::GetState() const { return m_thread.state; } -bool Common::Debug::OSThreadView::IsSuspended() const +bool OSThreadView::IsSuspended() const { return m_thread.suspend > 0; } -bool Common::Debug::OSThreadView::IsDetached() const +bool OSThreadView::IsDetached() const { return m_thread.is_detached != 0; } -s32 Common::Debug::OSThreadView::GetBasePriority() const +s32 OSThreadView::GetBasePriority() const { return m_thread.base_priority; } -s32 Common::Debug::OSThreadView::GetEffectivePriority() const +s32 OSThreadView::GetEffectivePriority() const { return m_thread.effective_priority; } -u32 Common::Debug::OSThreadView::GetStackStart() const +u32 OSThreadView::GetStackStart() const { return m_thread.stack_addr; } -u32 Common::Debug::OSThreadView::GetStackEnd() const +u32 OSThreadView::GetStackEnd() const { return m_thread.stack_end; } -std::size_t Common::Debug::OSThreadView::GetStackSize() const +std::size_t OSThreadView::GetStackSize() const { return GetStackStart() - GetStackEnd(); } -s32 Common::Debug::OSThreadView::GetErrno() const +s32 OSThreadView::GetErrno() const { return m_thread.error; } -std::string Common::Debug::OSThreadView::GetSpecific() const +std::string OSThreadView::GetSpecific() const { std::string specific; @@ -198,7 +200,9 @@ std::string Common::Debug::OSThreadView::GetSpecific() const return specific; } -bool Common::Debug::OSThreadView::IsValid() const +bool OSThreadView::IsValid() const { return m_thread.IsValid(); } + +} // namespace Core::Debug diff --git a/Source/Core/Common/Debug/OSThread.h b/Source/Core/Core/Debugger/OSThread.h similarity index 97% rename from Source/Core/Common/Debug/OSThread.h rename to Source/Core/Core/Debugger/OSThread.h index 7a588c670e..c5aa3fee8d 100644 --- a/Source/Core/Common/Debug/OSThread.h +++ b/Source/Core/Core/Debugger/OSThread.h @@ -11,7 +11,7 @@ #include "Common/CommonTypes.h" #include "Common/Debug/Threads.h" -namespace Common::Debug +namespace Core::Debug { template struct OSQueue @@ -132,7 +132,7 @@ public: const OSThread& Data() const; - PartialContext GetContext() const override; + Common::Debug::PartialContext GetContext() const override; u32 GetAddress() const override; u16 GetState() const override; bool IsSuspended() const override; @@ -151,4 +151,4 @@ private: OSThread m_thread; }; -} // namespace Common::Debug +} // namespace Core::Debug diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index f44c20d7f2..0ca90f52b4 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -11,10 +11,10 @@ #include #include "Common/Align.h" -#include "Common/Debug/OSThread.h" #include "Common/GekkoDisassembler.h" #include "Core/Core.h" +#include "Core/Debugger/OSThread.h" #include "Core/HW/DSP.h" #include "Core/PowerPC/MMU.h" #include "Core/PowerPC/PPCSymbolDB.h" @@ -176,14 +176,14 @@ Common::Debug::Threads PPCDebugInterface::GetThreads() const if (!PowerPC::HostIsRAMAddress(active_queue_head)) return threads; - auto active_thread = std::make_unique(active_queue_head); + auto active_thread = std::make_unique(active_queue_head); if (!active_thread->IsValid()) return threads; const auto insert_threads = [&threads](u32 addr, auto get_next_addr) { while (addr != 0 && PowerPC::HostIsRAMAddress(addr)) { - auto thread = std::make_unique(addr); + auto thread = std::make_unique(addr); if (!thread->IsValid()) break; addr = get_next_addr(*thread);