suyu/src/core/hle/kernel/svc_wrap.h

239 lines
6.3 KiB
C
Raw Normal View History

// Copyright 2018 yuzu emulator team
2014-12-17 00:38:14 -05:00
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include "common/common_types.h"
#include "core/arm/arm_interface.h"
#include "core/core.h"
#include "core/hle/kernel/svc.h"
#include "core/hle/result.h"
#include "core/memory.h"
namespace Kernel {
2018-05-02 22:36:51 -04:00
#define PARAM(n) Core::CurrentArmInterface().GetReg(n)
/**
* HLE a function return from the current ARM userland process
* @param res Result to return
*/
static inline void FuncReturn(u64 res) {
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(0, res);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Function wrappers that return type ResultCode
template <ResultCode func(u64)>
void SvcWrap() {
FuncReturn(func(PARAM(0)).raw);
}
template <ResultCode func(u32)>
void SvcWrap() {
FuncReturn(func((u32)PARAM(0)).raw);
2017-12-28 21:38:38 -05:00
}
template <ResultCode func(u32, u32)>
void SvcWrap() {
FuncReturn(func((u32)PARAM(0), (u32)PARAM(1)).raw);
2017-12-28 15:29:52 -05:00
}
template <ResultCode func(u32*, u32)>
void SvcWrap() {
u32 param_1 = 0;
u32 retval = func(&param_1, (u32)PARAM(1)).raw;
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
2017-12-28 15:29:52 -05:00
FuncReturn(retval);
}
template <ResultCode func(u32*, u64)>
void SvcWrap() {
u32 param_1 = 0;
u32 retval = func(&param_1, PARAM(1)).raw;
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval);
}
template <ResultCode func(u64, s32)>
void SvcWrap() {
FuncReturn(func(PARAM(0), (s32)PARAM(1)).raw);
}
template <ResultCode func(u64*, u64)>
void SvcWrap() {
u64 param_1 = 0;
u32 retval = func(&param_1, PARAM(1)).raw;
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval);
}
template <ResultCode func(u32, u64)>
void SvcWrap() {
FuncReturn(func((u32)(PARAM(0) & 0xFFFFFFFF), PARAM(1)).raw);
}
2018-03-29 21:07:49 -04:00
template <ResultCode func(u32, u32, u64)>
void SvcWrap() {
FuncReturn(func((u32)(PARAM(0) & 0xFFFFFFFF), (u32)(PARAM(1) & 0xFFFFFFFF), PARAM(2)).raw);
}
template <ResultCode func(u32, u32*, u64*)>
void SvcWrap() {
u32 param_1 = 0;
u64 param_2 = 0;
ResultCode retval = func((u32)(PARAM(2) & 0xFFFFFFFF), &param_1, &param_2);
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
Core::CurrentArmInterface().SetReg(2, param_2);
2018-03-29 21:07:49 -04:00
FuncReturn(retval.raw);
}
2018-01-07 21:23:42 -05:00
template <ResultCode func(u64, u64, u32, u32)>
void SvcWrap() {
FuncReturn(
func(PARAM(0), PARAM(1), (u32)(PARAM(3) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw);
}
template <ResultCode func(u32, u64, u32)>
void SvcWrap() {
FuncReturn(func((u32)PARAM(0), PARAM(1), (u32)PARAM(2)).raw);
}
template <ResultCode func(u64, u64, u64)>
void SvcWrap() {
FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw);
}
2018-01-14 17:15:31 -05:00
template <ResultCode func(u32, u64, u64, u32)>
void SvcWrap() {
FuncReturn(func((u32)PARAM(0), PARAM(1), PARAM(2), (u32)PARAM(3)).raw);
}
template <ResultCode func(u32, u64, u64)>
void SvcWrap() {
FuncReturn(func((u32)PARAM(0), PARAM(1), PARAM(2)).raw);
}
template <ResultCode func(u32*, u64, u64, s64)>
void SvcWrap() {
u32 param_1 = 0;
ResultCode retval = func(&param_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (s64)PARAM(3));
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval.raw);
}
template <ResultCode func(u64, u64, u32, s64)>
void SvcWrap() {
FuncReturn(func(PARAM(0), PARAM(1), (u32)PARAM(2), (s64)PARAM(3)).raw);
}
template <ResultCode func(u64*, u64, u64, u64)>
void SvcWrap() {
u64 param_1 = 0;
u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3)).raw;
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval);
}
template <ResultCode func(u32*, u64, u64, u64, u32, s32)>
void SvcWrap() {
u32 param_1 = 0;
u32 retval =
func(&param_1, PARAM(1), PARAM(2), PARAM(3), (u32)PARAM(4), (s32)(PARAM(5) & 0xFFFFFFFF))
.raw;
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval);
}
template <ResultCode func(MemoryInfo*, PageInfo*, u64)>
void SvcWrap() {
MemoryInfo memory_info = {};
PageInfo page_info = {};
u32 retval = func(&memory_info, &page_info, PARAM(2)).raw;
Memory::Write64(PARAM(0), memory_info.base_address);
Memory::Write64(PARAM(0) + 8, memory_info.size);
Memory::Write32(PARAM(0) + 16, memory_info.type);
Memory::Write32(PARAM(0) + 20, memory_info.attributes);
Memory::Write32(PARAM(0) + 24, memory_info.permission);
FuncReturn(retval);
}
template <ResultCode func(u32*, u64, u64, u32)>
void SvcWrap() {
u32 param_1 = 0;
u32 retval = func(&param_1, PARAM(1), PARAM(2), (u32)(PARAM(3) & 0xFFFFFFFF)).raw;
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval);
}
template <ResultCode func(Handle*, u64, u32, u32)>
void SvcWrap() {
u32 param_1 = 0;
u32 retval =
func(&param_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw;
2018-05-02 22:36:51 -04:00
Core::CurrentArmInterface().SetReg(1, param_1);
FuncReturn(retval);
}
template <ResultCode func(u64, u32, s32, s64)>
void SvcWrap() {
2018-06-21 23:09:51 -04:00
FuncReturn(
func(PARAM(0), (u32)(PARAM(1) & 0xFFFFFFFF), (s32)(PARAM(2) & 0xFFFFFFFF), (s64)PARAM(3))
.raw);
}
template <ResultCode func(u64, u32, s32, s32)>
void SvcWrap() {
2018-06-21 23:09:51 -04:00
FuncReturn(func(PARAM(0), (u32)(PARAM(1) & 0xFFFFFFFF), (s32)(PARAM(2) & 0xFFFFFFFF),
(s32)(PARAM(3) & 0xFFFFFFFF))
.raw);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Function wrappers that return type u32
template <u32 func()>
void SvcWrap() {
FuncReturn(func());
}
2018-01-11 21:59:31 -05:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// Function wrappers that return type u64
template <u64 func()>
void SvcWrap() {
FuncReturn(func());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// Function wrappers that return type void
template <void func()>
void SvcWrap() {
func();
}
template <void func(s64)>
void SvcWrap() {
func((s64)PARAM(0));
}
template <void func(u64, u64 len)>
void SvcWrap() {
func(PARAM(0), PARAM(1));
}
template <void func(u64, u64, u64)>
void SvcWrap() {
func(PARAM(0), PARAM(1), PARAM(2));
2015-05-17 01:06:59 -04:00
}
#undef PARAM
#undef FuncReturn
} // namespace Kernel