diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 2712a9f951..1f7103009b 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -72,6 +72,7 @@ set(SRCS HLE/HLE.cpp HLE/HLE_Misc.cpp HLE/HLE_OS.cpp + HLE/HLE_VarArgs.cpp HW/AudioInterface.cpp HW/CPU.cpp HW/DSP.cpp diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 55e2d9c328..a6334c1bb9 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -100,6 +100,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 1411269cb1..029ce1d207 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -293,6 +293,9 @@ HLE + + HLE + PowerPC diff --git a/Source/Core/Core/HLE/HLE_OS.cpp b/Source/Core/Core/HLE/HLE_OS.cpp index 547fc7e608..788e21d53b 100644 --- a/Source/Core/Core/HLE/HLE_OS.cpp +++ b/Source/Core/Core/HLE/HLE_OS.cpp @@ -95,7 +95,7 @@ std::string GetStringVA(u32 str_reg) std::string ArgumentBuffer; std::string result; 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++) { @@ -143,8 +143,8 @@ std::string GetStringVA(u32 str_reg) break; case 'n': - PowerPC::HostWrite_U32(static_cast(result.size()), ap.GetArgT()); // %n doesn't output anything, so the result variable is untouched + PowerPC::HostWrite_U32(static_cast(result.size()), ap.GetArgT()); break; default: diff --git a/Source/Core/Core/HLE/HLE_VarArgs.cpp b/Source/Core/Core/HLE/HLE_VarArgs.cpp new file mode 100644 index 0000000000..27ac6f7bf2 --- /dev/null +++ b/Source/Core/Core/HLE/HLE_VarArgs.cpp @@ -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); +} diff --git a/Source/Core/Core/HLE/HLE_VarArgs.h b/Source/Core/Core/HLE/HLE_VarArgs.h index 8c31549d70..a76ae76fe3 100644 --- a/Source/Core/Core/HLE/HLE_VarArgs.h +++ b/Source/Core/Core/HLE/HLE_VarArgs.h @@ -1,4 +1,4 @@ -// Copyright 2016 Dolphin Emulator Project +// Copyright 2017 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. @@ -14,6 +14,18 @@ namespace HLE { +namespace SystemVABI +{ +// SFINAE +template +constexpr bool IS_ARG_POINTER = std::is_union() || std::is_class(); +template +constexpr bool IS_WORD = std::is_pointer() || (std::is_integral() && sizeof(T) <= 4); +template +constexpr bool IS_DOUBLE_WORD = std::is_integral() && sizeof(T) == 8; +template +constexpr bool IS_ARG_REAL = std::is_floating_point(); + // See System V ABI (SVR4) for more details // -> 3-18 Parameter Passing // -> 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) { } - ~VAList() = default; - - // SFINAE - template - constexpr bool IS_ARG_POINTER = std::is_union() || std::is_class(); - template - constexpr bool IS_WORD = std::is_pointer() || (std::is_integral() && sizeof(T) <= 4); - template - constexpr bool IS_DOUBLE_WORD = std::is_integral() && sizeof(T) == 8; - template - constexpr bool IS_ARG_REAL = std::is_floating_point(); + virtual ~VAList(); // 0 - arg_ARGPOINTER template >* = nullptr> @@ -63,7 +65,7 @@ public: if (m_gpr <= m_gpr_max) { - value = GPR(m_gpr); + value = GetGPR(m_gpr); m_gpr += 1; } else @@ -86,7 +88,7 @@ public: m_gpr += 1; if (m_gpr < m_gpr_max) { - value = static_cast(GPR(m_gpr)) << 32 | GPR(m_gpr + 1); + value = static_cast(GetGPR(m_gpr)) << 32 | GetGPR(m_gpr + 1); m_gpr += 2; } else @@ -107,7 +109,7 @@ public: if (m_fpr <= m_fpr_max) { - value = rPS0(m_fpr); + value = GetFPR(m_fpr); m_fpr += 1; } else @@ -134,5 +136,9 @@ private: const u32 m_gpr_max = 10; const u32 m_fpr_max = 8; u32 m_stack; + + virtual u32 GetGPR(u32 gpr) const; + virtual double GetFPR(u32 fpr) const; }; -} +} // namespace SystemVABI +} // namespace HLE