| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- // Copyright 2018 yuzu emulator team
- // 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/result.h"
- namespace Kernel {
- static inline u64 Param(const Core::System& system, int n) {
- return system.CurrentArmInterface().GetReg(n);
- }
- static inline u32 Param32(const Core::System& system, int n) {
- return static_cast<u32>(system.CurrentArmInterface().GetReg(n));
- }
- /**
- * HLE a function return from the current ARM userland process
- * @param system System context
- * @param result Result to return
- */
- static inline void FuncReturn(Core::System& system, u64 result) {
- system.CurrentArmInterface().SetReg(0, result);
- }
- static inline void FuncReturn32(Core::System& system, u32 result) {
- system.CurrentArmInterface().SetReg(0, (u64)result);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- // Function wrappers that return type ResultCode
- template <ResultCode func(Core::System&, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0)).raw);
- }
- template <ResultCode func(Core::System&, u64, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), Param(system, 1)).raw);
- }
- template <ResultCode func(Core::System&, u32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, static_cast<u32>(Param(system, 0))).raw);
- }
- template <ResultCode func(Core::System&, u32, u32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(
- system,
- func(system, static_cast<u32>(Param(system, 0)), static_cast<u32>(Param(system, 1))).raw);
- }
- template <ResultCode func(Core::System&, u32, u64, u64, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, static_cast<u32>(Param(system, 0)), Param(system, 1),
- Param(system, 2), Param(system, 3))
- .raw);
- }
- template <ResultCode func(Core::System&, u32*)>
- void SvcWrap64(Core::System& system) {
- u32 param = 0;
- const u32 retval = func(system, ¶m).raw;
- system.CurrentArmInterface().SetReg(1, param);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u32*, u32)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, ¶m_1, static_cast<u32>(Param(system, 1))).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u32*, u32*)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- u32 param_2 = 0;
- const u32 retval = func(system, ¶m_1, ¶m_2).raw;
- auto& arm_interface = system.CurrentArmInterface();
- arm_interface.SetReg(1, param_1);
- arm_interface.SetReg(2, param_2);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u32*, u64)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param(system, 1)).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u32*, u64, u32)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval =
- func(system, ¶m_1, Param(system, 1), static_cast<u32>(Param(system, 2))).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u64*, u32)>
- void SvcWrap64(Core::System& system) {
- u64 param_1 = 0;
- const u32 retval = func(system, ¶m_1, static_cast<u32>(Param(system, 1))).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u64, u32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), static_cast<u32>(Param(system, 1))).raw);
- }
- template <ResultCode func(Core::System&, u64*, u64)>
- void SvcWrap64(Core::System& system) {
- u64 param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param(system, 1)).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u64*, u32, u32)>
- void SvcWrap64(Core::System& system) {
- u64 param_1 = 0;
- const u32 retval = func(system, ¶m_1, static_cast<u32>(Param(system, 1)),
- static_cast<u32>(Param(system, 2)))
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u32, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, static_cast<u32>(Param(system, 0)), Param(system, 1)).raw);
- }
- template <ResultCode func(Core::System&, u32, u32, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, static_cast<u32>(Param(system, 0)),
- static_cast<u32>(Param(system, 1)), Param(system, 2))
- .raw);
- }
- template <ResultCode func(Core::System&, u32, u32*, u64*)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- u64 param_2 = 0;
- const ResultCode retval = func(system, static_cast<u32>(Param(system, 2)), ¶m_1, ¶m_2);
- system.CurrentArmInterface().SetReg(1, param_1);
- system.CurrentArmInterface().SetReg(2, param_2);
- FuncReturn(system, retval.raw);
- }
- template <ResultCode func(Core::System&, u64, u64, u32, u32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), Param(system, 1),
- static_cast<u32>(Param(system, 2)), static_cast<u32>(Param(system, 3)))
- .raw);
- }
- template <ResultCode func(Core::System&, u64, u64, u32, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), Param(system, 1),
- static_cast<u32>(Param(system, 2)), Param(system, 3))
- .raw);
- }
- template <ResultCode func(Core::System&, u32, u64, u32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, static_cast<u32>(Param(system, 0)), Param(system, 1),
- static_cast<u32>(Param(system, 2)))
- .raw);
- }
- template <ResultCode func(Core::System&, u64, u64, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), Param(system, 1), Param(system, 2)).raw);
- }
- template <ResultCode func(Core::System&, u64, u64, u32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(
- system,
- func(system, Param(system, 0), Param(system, 1), static_cast<u32>(Param(system, 2))).raw);
- }
- template <ResultCode func(Core::System&, u32, u64, u64, u32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, static_cast<u32>(Param(system, 0)), Param(system, 1),
- Param(system, 2), static_cast<u32>(Param(system, 3)))
- .raw);
- }
- template <ResultCode func(Core::System&, u32, u64, u64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(
- system,
- func(system, static_cast<u32>(Param(system, 0)), Param(system, 1), Param(system, 2)).raw);
- }
- template <ResultCode func(Core::System&, u32*, u64, u64, s64)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param(system, 1), static_cast<u32>(Param(system, 2)),
- static_cast<s64>(Param(system, 3)))
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u64, u64, u32, s64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), Param(system, 1),
- static_cast<u32>(Param(system, 2)), static_cast<s64>(Param(system, 3)))
- .raw);
- }
- template <ResultCode func(Core::System&, u64*, u64, u64, u64)>
- void SvcWrap64(Core::System& system) {
- u64 param_1 = 0;
- const u32 retval =
- func(system, ¶m_1, Param(system, 1), Param(system, 2), Param(system, 3)).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u32*, u64, u64, u64, u32, s32)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param(system, 1), Param(system, 2), Param(system, 3),
- static_cast<u32>(Param(system, 4)), static_cast<s32>(Param(system, 5)))
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u32*, u64, u64, u32)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param(system, 1), Param(system, 2),
- static_cast<u32>(Param(system, 3)))
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, Handle*, u64, u32, u32)>
- void SvcWrap64(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param(system, 1), static_cast<u32>(Param(system, 2)),
- static_cast<u32>(Param(system, 3)))
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- template <ResultCode func(Core::System&, u64, u32, s32, s64)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), static_cast<u32>(Param(system, 1)),
- static_cast<s32>(Param(system, 2)), static_cast<s64>(Param(system, 3)))
- .raw);
- }
- template <ResultCode func(Core::System&, u64, u32, s32, s32)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system, Param(system, 0), static_cast<u32>(Param(system, 1)),
- static_cast<s32>(Param(system, 2)), static_cast<s32>(Param(system, 3)))
- .raw);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- // Function wrappers that return type u32
- template <u32 func(Core::System&)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system));
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- // Function wrappers that return type u64
- template <u64 func(Core::System&)>
- void SvcWrap64(Core::System& system) {
- FuncReturn(system, func(system));
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Function wrappers that return type void
- template <void func(Core::System&)>
- void SvcWrap64(Core::System& system) {
- func(system);
- }
- template <void func(Core::System&, u32)>
- void SvcWrap64(Core::System& system) {
- func(system, static_cast<u32>(Param(system, 0)));
- }
- template <void func(Core::System&, u32, u64, u64, u64)>
- void SvcWrap64(Core::System& system) {
- func(system, static_cast<u32>(Param(system, 0)), Param(system, 1), Param(system, 2),
- Param(system, 3));
- }
- template <void func(Core::System&, s64)>
- void SvcWrap64(Core::System& system) {
- func(system, static_cast<s64>(Param(system, 0)));
- }
- template <void func(Core::System&, u64, s32)>
- void SvcWrap64(Core::System& system) {
- func(system, Param(system, 0), static_cast<s32>(Param(system, 1)));
- }
- template <void func(Core::System&, u64, u64)>
- void SvcWrap64(Core::System& system) {
- func(system, Param(system, 0), Param(system, 1));
- }
- template <void func(Core::System&, u64, u64, u64)>
- void SvcWrap64(Core::System& system) {
- func(system, Param(system, 0), Param(system, 1), Param(system, 2));
- }
- template <void func(Core::System&, u32, u64, u64)>
- void SvcWrap64(Core::System& system) {
- func(system, static_cast<u32>(Param(system, 0)), Param(system, 1), Param(system, 2));
- }
- // Used by QueryMemory32, ArbitrateLock32
- template <ResultCode func(Core::System&, u32, u32, u32)>
- void SvcWrap32(Core::System& system) {
- FuncReturn32(system,
- func(system, Param32(system, 0), Param32(system, 1), Param32(system, 2)).raw);
- }
- // Used by Break32
- template <void func(Core::System&, u32, u32, u32)>
- void SvcWrap32(Core::System& system) {
- func(system, Param32(system, 0), Param32(system, 1), Param32(system, 2));
- }
- // Used by ExitProcess32, ExitThread32
- template <void func(Core::System&)>
- void SvcWrap32(Core::System& system) {
- func(system);
- }
- // Used by GetCurrentProcessorNumber32
- template <u32 func(Core::System&)>
- void SvcWrap32(Core::System& system) {
- FuncReturn32(system, func(system));
- }
- // Used by SleepThread32
- template <void func(Core::System&, u32, u32)>
- void SvcWrap32(Core::System& system) {
- func(system, Param32(system, 0), Param32(system, 1));
- }
- // Used by CreateThread32
- template <ResultCode func(Core::System&, Handle*, u32, u32, u32, u32, s32)>
- void SvcWrap32(Core::System& system) {
- Handle param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param32(system, 0), Param32(system, 1),
- Param32(system, 2), Param32(system, 3), Param32(system, 4))
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- // Used by GetInfo32
- template <ResultCode func(Core::System&, u32*, u32*, u32, u32, u32, u32)>
- void SvcWrap32(Core::System& system) {
- u32 param_1 = 0;
- u32 param_2 = 0;
- const u32 retval = func(system, ¶m_1, ¶m_2, Param32(system, 0), Param32(system, 1),
- Param32(system, 2), Param32(system, 3))
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- system.CurrentArmInterface().SetReg(2, param_2);
- FuncReturn(system, retval);
- }
- // Used by GetThreadPriority32, ConnectToNamedPort32
- template <ResultCode func(Core::System&, u32*, u32)>
- void SvcWrap32(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, ¶m_1, Param32(system, 1)).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- // Used by GetThreadId32
- template <ResultCode func(Core::System&, u32*, u32*, u32)>
- void SvcWrap32(Core::System& system) {
- u32 param_1 = 0;
- u32 param_2 = 0;
- const u32 retval = func(system, ¶m_1, ¶m_2, Param32(system, 1)).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- system.CurrentArmInterface().SetReg(2, param_2);
- FuncReturn(system, retval);
- }
- // Used by GetSystemTick32
- template <void func(Core::System&, u32*, u32*)>
- void SvcWrap32(Core::System& system) {
- u32 param_1 = 0;
- u32 param_2 = 0;
- func(system, ¶m_1, ¶m_2);
- system.CurrentArmInterface().SetReg(0, param_1);
- system.CurrentArmInterface().SetReg(1, param_2);
- }
- // Used by CreateEvent32
- template <ResultCode func(Core::System&, Handle*, Handle*)>
- void SvcWrap32(Core::System& system) {
- Handle param_1 = 0;
- Handle param_2 = 0;
- const u32 retval = func(system, ¶m_1, ¶m_2).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- system.CurrentArmInterface().SetReg(2, param_2);
- FuncReturn(system, retval);
- }
- // Used by GetThreadId32
- template <ResultCode func(Core::System&, Handle, u32*, u32*, u32*)>
- void SvcWrap32(Core::System& system) {
- u32 param_1 = 0;
- u32 param_2 = 0;
- u32 param_3 = 0;
- const u32 retval = func(system, Param32(system, 2), ¶m_1, ¶m_2, ¶m_3).raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- system.CurrentArmInterface().SetReg(2, param_2);
- system.CurrentArmInterface().SetReg(3, param_3);
- FuncReturn(system, retval);
- }
- // Used by SignalProcessWideKey32
- template <void func(Core::System&, u32, s32)>
- void SvcWrap32(Core::System& system) {
- func(system, static_cast<u32>(Param(system, 0)), static_cast<s32>(Param(system, 1)));
- }
- // Used by SetThreadPriority32
- template <ResultCode func(Core::System&, Handle, u32)>
- void SvcWrap32(Core::System& system) {
- const u32 retval =
- func(system, static_cast<Handle>(Param(system, 0)), static_cast<u32>(Param(system, 1))).raw;
- FuncReturn(system, retval);
- }
- // Used by SetThreadCoreMask32
- template <ResultCode func(Core::System&, Handle, u32, u32, u32)>
- void SvcWrap32(Core::System& system) {
- const u32 retval =
- func(system, static_cast<Handle>(Param(system, 0)), static_cast<u32>(Param(system, 1)),
- static_cast<u32>(Param(system, 2)), static_cast<u32>(Param(system, 3)))
- .raw;
- FuncReturn(system, retval);
- }
- // Used by WaitProcessWideKeyAtomic32
- template <ResultCode func(Core::System&, u32, u32, Handle, u32, u32)>
- void SvcWrap32(Core::System& system) {
- const u32 retval =
- func(system, static_cast<u32>(Param(system, 0)), static_cast<u32>(Param(system, 1)),
- static_cast<Handle>(Param(system, 2)), static_cast<u32>(Param(system, 3)),
- static_cast<u32>(Param(system, 4)))
- .raw;
- FuncReturn(system, retval);
- }
- // Used by WaitForAddress32
- template <ResultCode func(Core::System&, u32, u32, s32, u32, u32)>
- void SvcWrap32(Core::System& system) {
- const u32 retval = func(system, static_cast<u32>(Param(system, 0)),
- static_cast<u32>(Param(system, 1)), static_cast<s32>(Param(system, 2)),
- static_cast<u32>(Param(system, 3)), static_cast<u32>(Param(system, 4)))
- .raw;
- FuncReturn(system, retval);
- }
- // Used by SignalToAddress32
- template <ResultCode func(Core::System&, u32, u32, s32, s32)>
- void SvcWrap32(Core::System& system) {
- const u32 retval =
- func(system, static_cast<u32>(Param(system, 0)), static_cast<u32>(Param(system, 1)),
- static_cast<s32>(Param(system, 2)), static_cast<s32>(Param(system, 3)))
- .raw;
- FuncReturn(system, retval);
- }
- // Used by SendSyncRequest32, ArbitrateUnlock32
- template <ResultCode func(Core::System&, u32)>
- void SvcWrap32(Core::System& system) {
- FuncReturn(system, func(system, static_cast<u32>(Param(system, 0))).raw);
- }
- // Used by CreateTransferMemory32
- template <ResultCode func(Core::System&, Handle*, u32, u32, u32)>
- void SvcWrap32(Core::System& system) {
- Handle handle = 0;
- const u32 retval =
- func(system, &handle, Param32(system, 1), Param32(system, 2), Param32(system, 3)).raw;
- system.CurrentArmInterface().SetReg(1, handle);
- FuncReturn(system, retval);
- }
- // Used by WaitSynchronization32
- template <ResultCode func(Core::System&, u32, u32, s32, u32, Handle*)>
- void SvcWrap32(Core::System& system) {
- u32 param_1 = 0;
- const u32 retval = func(system, Param32(system, 0), Param32(system, 1), Param32(system, 2),
- Param32(system, 3), ¶m_1)
- .raw;
- system.CurrentArmInterface().SetReg(1, param_1);
- FuncReturn(system, retval);
- }
- } // namespace Kernel
|