HLE: VAList cleanup and SystemVABI namespace

This commit is contained in:
Sepalani 2017-01-28 02:02:43 +00:00
parent e9dd0072de
commit 5a4f085c10
6 changed files with 46 additions and 18 deletions

View File

@ -72,6 +72,7 @@ set(SRCS
HLE/HLE.cpp HLE/HLE.cpp
HLE/HLE_Misc.cpp HLE/HLE_Misc.cpp
HLE/HLE_OS.cpp HLE/HLE_OS.cpp
HLE/HLE_VarArgs.cpp
HW/AudioInterface.cpp HW/AudioInterface.cpp
HW/CPU.cpp HW/CPU.cpp
HW/DSP.cpp HW/DSP.cpp

View File

@ -100,6 +100,7 @@
<ClCompile Include="HLE\HLE.cpp" /> <ClCompile Include="HLE\HLE.cpp" />
<ClCompile Include="HLE\HLE_Misc.cpp" /> <ClCompile Include="HLE\HLE_Misc.cpp" />
<ClCompile Include="HLE\HLE_OS.cpp" /> <ClCompile Include="HLE\HLE_OS.cpp" />
<ClCompile Include="HLE\HLE_VarArgs.cpp" />
<ClCompile Include="HotkeyManager.cpp" /> <ClCompile Include="HotkeyManager.cpp" />
<ClCompile Include="HW\AudioInterface.cpp" /> <ClCompile Include="HW\AudioInterface.cpp" />
<ClCompile Include="HW\CPU.cpp" /> <ClCompile Include="HW\CPU.cpp" />

View File

@ -293,6 +293,9 @@
<ClCompile Include="HLE\HLE_OS.cpp"> <ClCompile Include="HLE\HLE_OS.cpp">
<Filter>HLE</Filter> <Filter>HLE</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="HLE\HLE_VarArgs.cpp" />
<Filter>HLE</Filter>
</ClCompile>
<ClCompile Include="PowerPC\BreakPoints.cpp"> <ClCompile Include="PowerPC\BreakPoints.cpp">
<Filter>PowerPC</Filter> <Filter>PowerPC</Filter>
</ClCompile> </ClCompile>

View File

@ -95,7 +95,7 @@ std::string GetStringVA(u32 str_reg)
std::string ArgumentBuffer; std::string ArgumentBuffer;
std::string result; std::string result;
std::string string = PowerPC::HostGetString(GPR(str_reg)); std::string string = PowerPC::HostGetString(GPR(str_reg));
HLE::VAList ap(GPR(1) + 0x8, str_reg + 1); HLE::SystemVABI::VAList ap(GPR(1) + 0x8, str_reg + 1);
for (size_t i = 0; i < string.size(); i++) for (size_t i = 0; i < string.size(); i++)
{ {
@ -143,8 +143,8 @@ std::string GetStringVA(u32 str_reg)
break; break;
case 'n': case 'n':
PowerPC::HostWrite_U32(static_cast<u32>(result.size()), ap.GetArgT<u32>());
// %n doesn't output anything, so the result variable is untouched // %n doesn't output anything, so the result variable is untouched
PowerPC::HostWrite_U32(static_cast<u32>(result.size()), ap.GetArgT<u32>());
break; break;
default: default:

View File

@ -0,0 +1,17 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Core/HLE/HLE_VarArgs.h"
HLE::SystemVABI::VAList::~VAList() = default;
u32 HLE::SystemVABI::VAList::GetGPR(u32 gpr) const
{
return GPR(gpr);
}
double HLE::SystemVABI::VAList::GetFPR(u32 fpr) const
{
return rPS0(fpr);
}

View File

@ -1,4 +1,4 @@
// Copyright 2016 Dolphin Emulator Project // Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
@ -14,6 +14,18 @@
namespace HLE namespace HLE
{ {
namespace SystemVABI
{
// SFINAE
template <typename T>
constexpr bool IS_ARG_POINTER = std::is_union<T>() || std::is_class<T>();
template <typename T>
constexpr bool IS_WORD = std::is_pointer<T>() || (std::is_integral<T>() && sizeof(T) <= 4);
template <typename T>
constexpr bool IS_DOUBLE_WORD = std::is_integral<T>() && sizeof(T) == 8;
template <typename T>
constexpr bool IS_ARG_REAL = std::is_floating_point<T>();
// See System V ABI (SVR4) for more details // See System V ABI (SVR4) for more details
// -> 3-18 Parameter Passing // -> 3-18 Parameter Passing
// -> 3-21 Variable Argument Lists // -> 3-21 Variable Argument Lists
@ -27,17 +39,7 @@ public:
: m_gpr(gpr), m_fpr(fpr), m_gpr_max(gpr_max), m_fpr_max(fpr_max), m_stack(stack) : m_gpr(gpr), m_fpr(fpr), m_gpr_max(gpr_max), m_fpr_max(fpr_max), m_stack(stack)
{ {
} }
~VAList() = default; virtual ~VAList();
// SFINAE
template <typename T>
constexpr bool IS_ARG_POINTER = std::is_union<T>() || std::is_class<T>();
template <typename T>
constexpr bool IS_WORD = std::is_pointer<T>() || (std::is_integral<T>() && sizeof(T) <= 4);
template <typename T>
constexpr bool IS_DOUBLE_WORD = std::is_integral<T>() && sizeof(T) == 8;
template <typename T>
constexpr bool IS_ARG_REAL = std::is_floating_point<T>();
// 0 - arg_ARGPOINTER // 0 - arg_ARGPOINTER
template <typename T, typename std::enable_if_t<IS_ARG_POINTER<T>>* = nullptr> template <typename T, typename std::enable_if_t<IS_ARG_POINTER<T>>* = nullptr>
@ -63,7 +65,7 @@ public:
if (m_gpr <= m_gpr_max) if (m_gpr <= m_gpr_max)
{ {
value = GPR(m_gpr); value = GetGPR(m_gpr);
m_gpr += 1; m_gpr += 1;
} }
else else
@ -86,7 +88,7 @@ public:
m_gpr += 1; m_gpr += 1;
if (m_gpr < m_gpr_max) if (m_gpr < m_gpr_max)
{ {
value = static_cast<u64>(GPR(m_gpr)) << 32 | GPR(m_gpr + 1); value = static_cast<u64>(GetGPR(m_gpr)) << 32 | GetGPR(m_gpr + 1);
m_gpr += 2; m_gpr += 2;
} }
else else
@ -107,7 +109,7 @@ public:
if (m_fpr <= m_fpr_max) if (m_fpr <= m_fpr_max)
{ {
value = rPS0(m_fpr); value = GetFPR(m_fpr);
m_fpr += 1; m_fpr += 1;
} }
else else
@ -134,5 +136,9 @@ private:
const u32 m_gpr_max = 10; const u32 m_gpr_max = 10;
const u32 m_fpr_max = 8; const u32 m_fpr_max = 8;
u32 m_stack; u32 m_stack;
virtual u32 GetGPR(u32 gpr) const;
virtual double GetFPR(u32 fpr) const;
}; };
} } // namespace SystemVABI
} // namespace HLE