From 10f25866e268756cc32e2e783b3377c34529f7e6 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 14 Aug 2014 20:01:02 -0400 Subject: SVC: Added support for svc_GetSystemTick. Changed HLE function return methods to be static inline functions. --- src/core/hle/function_wrappers.h | 60 ++++++++++++++++++++++++++++------------ src/core/hle/svc.cpp | 7 ++++- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index ea603a1bb..55eaf0621 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -11,24 +11,41 @@ namespace HLE { #define PARAM(n) Core::g_app_core->GetReg(n) -#define RETURN(n) Core::g_app_core->SetReg(0, n) + +/** + * HLE a function return from the current ARM11 userland process + * @param res Result to return + */ +static inline void FuncReturn(u32 res) { + Core::g_app_core->SetReg(0, res); +} + +/** + * HLE a function return (64-bit) from the current ARM11 userland process + * @param res Result to return (64-bit) + * @todo Verify that this function is correct + */ +static inline void FuncReturn64(u64 res) { + Core::g_app_core->SetReg(0, (u32)(res & 0xFFFFFFFF)); + Core::g_app_core->SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF)); +} //////////////////////////////////////////////////////////////////////////////////////////////////// // Function wrappers that return type s32 template void Wrap() { - RETURN(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3))); + FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3))); } template void Wrap() { - RETURN(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4))); + FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4))); } template void Wrap(){ u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)); Core::g_app_core->SetReg(1, param_1); - RETURN(retval); + FuncReturn(retval); } template void Wrap() { @@ -36,57 +53,57 @@ template void Wrap() { s32 retval = func(¶m_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), (PARAM(3) != 0), (((s64)PARAM(4) << 32) | PARAM(0))); Core::g_app_core->SetReg(1, (u32)param_1); - RETURN(retval); + FuncReturn(retval); } // TODO(bunnei): Is this correct? Probably not - Last parameter looks wrong for ArbitrateAddress template void Wrap() { - RETURN(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), (((s64)PARAM(5) << 32) | PARAM(4)))); + FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), (((s64)PARAM(5) << 32) | PARAM(4)))); } template void Wrap(){ u32 param_1 = 0; u32 retval = func(¶m_1); Core::g_app_core->SetReg(1, param_1); - RETURN(retval); + FuncReturn(retval); } template void Wrap() { - RETURN(func(PARAM(0), (((s64)PARAM(3) << 32) | PARAM(2)))); + FuncReturn(func(PARAM(0), (((s64)PARAM(3) << 32) | PARAM(2)))); } template void Wrap(){ - RETURN(func(Memory::GetPointer(PARAM(0)), Memory::GetPointer(PARAM(1)), PARAM(2))); + FuncReturn(func(Memory::GetPointer(PARAM(0)), Memory::GetPointer(PARAM(1)), PARAM(2))); } template void Wrap(){ s32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1)); Core::g_app_core->SetReg(1, param_1); - RETURN(retval); + FuncReturn(retval); } template void Wrap() { - RETURN(func(PARAM(0), (s32)PARAM(1))); + FuncReturn(func(PARAM(0), (s32)PARAM(1))); } template void Wrap(){ u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1)); Core::g_app_core->SetReg(1, param_1); - RETURN(retval); + FuncReturn(retval); } template void Wrap() { - RETURN(func(PARAM(0))); + FuncReturn(func(PARAM(0))); } template void Wrap() { - RETURN(func(Memory::GetPointer(PARAM(0)))); + FuncReturn(func(Memory::GetPointer(PARAM(0)))); } template void Wrap(){ - RETURN(func((s64*)Memory::GetPointer(PARAM(0)), PARAM(1), Memory::GetPointer(PARAM(2)), + FuncReturn(func((s64*)Memory::GetPointer(PARAM(0)), PARAM(1), Memory::GetPointer(PARAM(2)), (s32)PARAM(3))); } @@ -94,14 +111,21 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, Memory::GetCharPointer(PARAM(1))); Core::g_app_core->SetReg(1, param_1); - RETURN(retval); + FuncReturn(retval); } //////////////////////////////////////////////////////////////////////////////////////////////////// // Function wrappers that return type u32 template void Wrap() { - RETURN(func()); + FuncReturn(func()); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Function wrappers that return type s64 + +template void Wrap() { + FuncReturn64(func()); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -116,6 +140,6 @@ template void Wrap() { } #undef PARAM -#undef RETURN +#undef FuncReturn } // namespace HLE diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 8720bed31..4f5ad805e 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -330,6 +330,11 @@ void SleepThread(s64 nanoseconds) { DEBUG_LOG(SVC, "called nanoseconds=%d", nanoseconds); } +/// This returns the total CPU ticks elapsed since the CPU was powered-on +s64 GetSystemTick() { + return (s64)Core::g_app_core->GetTicks(); +} + const HLE::FunctionDef SVC_Table[] = { {0x00, nullptr, "Unknown"}, {0x01, HLE::Wrap, "ControlMemory"}, @@ -371,7 +376,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x25, HLE::Wrap, "WaitSynchronizationN"}, {0x26, nullptr, "SignalAndWait"}, {0x27, HLE::Wrap, "DuplicateHandle"}, - {0x28, nullptr, "GetSystemTick"}, + {0x28, HLE::Wrap, "GetSystemTick"}, {0x29, nullptr, "GetHandleInfo"}, {0x2A, nullptr, "GetSystemInfo"}, {0x2B, nullptr, "GetProcessInfo"}, -- cgit v1.2.3