1
0
Fork 0
forked from suyu/suyu

SVC: Added support for svc_GetSystemTick.

Changed HLE function return methods to be static inline functions.
This commit is contained in:
bunnei 2014-08-14 20:01:02 -04:00
parent 0a1aab5b42
commit 10f25866e2
2 changed files with 48 additions and 19 deletions

View file

@ -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<s32 func(u32, u32, u32, u32)> void Wrap() {
RETURN(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)));
FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)));
}
template<s32 func(u32, u32, u32, u32, u32)> 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<s32 func(u32*, u32, u32, u32, u32, u32)> void Wrap(){
u32 param_1 = 0;
u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
Core::g_app_core->SetReg(1, param_1);
RETURN(retval);
FuncReturn(retval);
}
template<s32 func(s32*, u32*, s32, bool, s64)> void Wrap() {
@ -36,57 +53,57 @@ template<s32 func(s32*, u32*, s32, bool, s64)> void Wrap() {
s32 retval = func(&param_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<s32 func(u32, u32, u32, u32, s64)> 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<s32 func(u32*)> void Wrap(){
u32 param_1 = 0;
u32 retval = func(&param_1);
Core::g_app_core->SetReg(1, param_1);
RETURN(retval);
FuncReturn(retval);
}
template<s32 func(u32, s64)> void Wrap() {
RETURN(func(PARAM(0), (((s64)PARAM(3) << 32) | PARAM(2))));
FuncReturn(func(PARAM(0), (((s64)PARAM(3) << 32) | PARAM(2))));
}
template<s32 func(void*, void*, u32)> 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<s32 func(s32*, u32)> void Wrap(){
s32 param_1 = 0;
u32 retval = func(&param_1, PARAM(1));
Core::g_app_core->SetReg(1, param_1);
RETURN(retval);
FuncReturn(retval);
}
template<s32 func(u32, s32)> void Wrap() {
RETURN(func(PARAM(0), (s32)PARAM(1)));
FuncReturn(func(PARAM(0), (s32)PARAM(1)));
}
template<s32 func(u32*, u32)> void Wrap(){
u32 param_1 = 0;
u32 retval = func(&param_1, PARAM(1));
Core::g_app_core->SetReg(1, param_1);
RETURN(retval);
FuncReturn(retval);
}
template<s32 func(u32)> void Wrap() {
RETURN(func(PARAM(0)));
FuncReturn(func(PARAM(0)));
}
template<s32 func(void*)> void Wrap() {
RETURN(func(Memory::GetPointer(PARAM(0))));
FuncReturn(func(Memory::GetPointer(PARAM(0))));
}
template<s32 func(s64*, u32, void*, s32)> 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<s32 func(u32*, const char*)> void Wrap() {
u32 param_1 = 0;
u32 retval = func(&param_1, Memory::GetCharPointer(PARAM(1)));
Core::g_app_core->SetReg(1, param_1);
RETURN(retval);
FuncReturn(retval);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Function wrappers that return type u32
template<u32 func()> void Wrap() {
RETURN(func());
FuncReturn(func());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Function wrappers that return type s64
template<s64 func()> void Wrap() {
FuncReturn64(func());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -116,6 +140,6 @@ template<void func(const char*)> void Wrap() {
}
#undef PARAM
#undef RETURN
#undef FuncReturn
} // namespace HLE

View file

@ -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>, "ControlMemory"},
@ -371,7 +376,7 @@ const HLE::FunctionDef SVC_Table[] = {
{0x25, HLE::Wrap<WaitSynchronizationN>, "WaitSynchronizationN"},
{0x26, nullptr, "SignalAndWait"},
{0x27, HLE::Wrap<DuplicateHandle>, "DuplicateHandle"},
{0x28, nullptr, "GetSystemTick"},
{0x28, HLE::Wrap<GetSystemTick>, "GetSystemTick"},
{0x29, nullptr, "GetHandleInfo"},
{0x2A, nullptr, "GetSystemInfo"},
{0x2B, nullptr, "GetProcessInfo"},