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.
This commit is contained in:
Lioncash 2020-10-20 18:05:59 -04:00
parent 7e197186b9
commit 57534777d4
9 changed files with 49 additions and 45 deletions

View File

@ -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

View File

@ -48,7 +48,6 @@
<ClInclude Include="CPUDetect.h" />
<ClInclude Include="DebugInterface.h" />
<ClInclude Include="Debug\MemoryPatches.h" />
<ClInclude Include="Debug\OSThread.h" />
<ClInclude Include="Debug\Threads.h" />
<ClInclude Include="Debug\Watches.h" />
<ClInclude Include="DynamicLibrary.h" />
@ -191,7 +190,6 @@
<ClCompile Include="Config\ConfigInfo.cpp" />
<ClCompile Include="Config\Layer.cpp" />
<ClCompile Include="Debug\MemoryPatches.cpp" />
<ClCompile Include="Debug\OSThread.cpp" />
<ClCompile Include="Debug\Watches.cpp" />
<ClCompile Include="DynamicLibrary.cpp" />
<ClCompile Include="ENetUtil.cpp" />

View File

@ -273,9 +273,6 @@
<ClInclude Include="Debug\MemoryPatches.h">
<Filter>Debug</Filter>
</ClInclude>
<ClInclude Include="Debug\OSThread.h">
<Filter>Debug</Filter>
</ClInclude>
<ClInclude Include="Debug\Threads.h">
<Filter>Debug</Filter>
</ClInclude>
@ -365,9 +362,6 @@
<ClCompile Include="Debug\MemoryPatches.cpp">
<Filter>Debug</Filter>
</ClCompile>
<ClCompile Include="Debug\OSThread.cpp">
<Filter>Debug</Filter>
</ClCompile>
<ClCompile Include="GL\GLContext.cpp">
<Filter>GL\GLInterface</Filter>
</ClCompile>

View File

@ -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

View File

@ -40,6 +40,7 @@
<ClCompile Include="CoreTiming.cpp" />
<ClCompile Include="Debugger\Debugger_SymbolMap.cpp" />
<ClCompile Include="Debugger\Dump.cpp" />
<ClCompile Include="Debugger\OSThread.cpp" />
<ClCompile Include="Debugger\PPCDebugInterface.cpp" />
<ClCompile Include="Debugger\RSO.cpp" />
<ClCompile Include="DSPEmulator.cpp" />
@ -399,6 +400,7 @@
<ClInclude Include="Debugger\Debugger_SymbolMap.h" />
<ClInclude Include="Debugger\Dump.h" />
<ClInclude Include="Debugger\GCELF.h" />
<ClInclude Include="Debugger\OSThread.h" />
<ClInclude Include="Debugger\PPCDebugInterface.h" />
<ClInclude Include="Debugger\RSO.h" />
<ClInclude Include="DSPEmulator.h" />

View File

@ -217,6 +217,9 @@
<ClCompile Include="Debugger\Dump.cpp">
<Filter>Debugger</Filter>
</ClCompile>
<ClCompile Include="Debugger\OSThread.cpp">
<Filter>Debugger</Filter>
</ClCompile>
<ClCompile Include="Debugger\PPCDebugInterface.cpp">
<Filter>Debugger</Filter>
</ClCompile>
@ -1050,6 +1053,9 @@
<ClInclude Include="Debugger\GCELF.h">
<Filter>Debugger</Filter>
</ClInclude>
<ClInclude Include="Debugger\OSThread.h">
<Filter>Debugger</Filter>
</ClInclude>
<ClInclude Include="Debugger\PPCDebugInterface.h">
<Filter>Debugger</Filter>
</ClInclude>

View File

@ -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 <algorithm>
#include <fmt/format.h>
#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

View File

@ -11,7 +11,7 @@
#include "Common/CommonTypes.h"
#include "Common/Debug/Threads.h"
namespace Common::Debug
namespace Core::Debug
{
template <class C>
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

View File

@ -11,10 +11,10 @@
#include <fmt/format.h>
#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<Common::Debug::OSThreadView>(active_queue_head);
auto active_thread = std::make_unique<Core::Debug::OSThreadView>(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<Common::Debug::OSThreadView>(addr);
auto thread = std::make_unique<Core::Debug::OSThreadView>(addr);
if (!thread->IsValid())
break;
addr = get_next_addr(*thread);