summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
authorbunnei <ericbunnie@gmail.com>2014-04-18 23:52:49 +0200
committerbunnei <ericbunnie@gmail.com>2014-04-18 23:52:49 +0200
commit958bca606e80110e05d7c142dda3097fddc96503 (patch)
tree576917751444b4dfdb476d040b4e075bde431b7b /src/core/hle
parentInit window size from VideoCore. Start changing the default window behavior... (diff)
parentrenamed hw_lcd module to just lcd (diff)
downloadyuzu-958bca606e80110e05d7c142dda3097fddc96503.tar
yuzu-958bca606e80110e05d7c142dda3097fddc96503.tar.gz
yuzu-958bca606e80110e05d7c142dda3097fddc96503.tar.bz2
yuzu-958bca606e80110e05d7c142dda3097fddc96503.tar.lz
yuzu-958bca606e80110e05d7c142dda3097fddc96503.tar.xz
yuzu-958bca606e80110e05d7c142dda3097fddc96503.tar.zst
yuzu-958bca606e80110e05d7c142dda3097fddc96503.zip
Diffstat (limited to '')
-rw-r--r--src/core/hle/function_wrappers.h736
-rw-r--r--src/core/hle/hle.cpp120
-rw-r--r--src/core/hle/hle.h66
-rw-r--r--src/core/hle/service/apt.cpp116
-rw-r--r--src/core/hle/service/apt.h41
-rw-r--r--src/core/hle/service/gsp.cpp59
-rw-r--r--src/core/hle/service/gsp.h35
-rw-r--r--src/core/hle/service/hid.cpp33
-rw-r--r--src/core/hle/service/hid.h37
-rw-r--r--src/core/hle/service/service.cpp94
-rw-r--r--src/core/hle/service/service.h143
-rw-r--r--src/core/hle/service/srv.cpp58
-rw-r--r--src/core/hle/service/srv.h40
-rw-r--r--src/core/hle/syscall.cpp197
-rw-r--r--src/core/hle/syscall.h19
15 files changed, 1794 insertions, 0 deletions
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h
new file mode 100644
index 000000000..4897d3f28
--- /dev/null
+++ b/src/core/hle/function_wrappers.h
@@ -0,0 +1,736 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#pragma once
+
+#include "common/common_types.h"
+#include "core/mem_map.h"
+#include "core/hle/hle.h"
+
+// For easy parameter parsing and return value processing.
+
+//32bit wrappers
+template<void func()> void WrapV_V() {
+ func();
+}
+
+template<u32 func()> void WrapU_V() {
+ RETURN(func());
+}
+
+template<int func(void *, const char *)> void WrapI_VC() {
+ u32 retval = func(Memory::GetPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1)));
+ RETURN(retval);
+}
+
+template<u32 func(int, void *, int)> void WrapU_IVI() {
+ u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1)), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(const char *, int, int, u32)> void WrapI_CIIU() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(int, const char *, u32, void *, void *, u32, int)> void WrapI_ICUVVUI() {
+ u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointer(PARAM(3)),Memory::GetPointer(PARAM(4)), PARAM(5), PARAM(6) );
+ RETURN(retval);
+}
+
+// Hm, do so many params get passed in registers?
+template<int func(const char *, int, const char *, int, int, int, int, int)> void WrapI_CICIIIII() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), Memory::GetCharPointer(PARAM(2)),
+ PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7));
+ RETURN(retval);
+}
+
+// Hm, do so many params get passed in registers?
+template<int func(const char *, int, int, int, int, int, int)> void WrapI_CIIIIII() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4), PARAM(5), PARAM(6));
+ RETURN(retval);
+}
+
+// Hm, do so many params get passed in registers?
+template<int func(int, int, int, int, int, int, u32)> void WrapI_IIIIIIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
+ RETURN(retval);
+}
+
+// Hm, do so many params get passed in registers?
+template<int func(int, int, int, int, int, int, int, int, u32)> void WrapI_IIIIIIIIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6), PARAM(7), PARAM(8));
+ RETURN(retval);
+}
+
+template<u32 func(int, void *)> void WrapU_IV() {
+ u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1)));
+ RETURN(retval);
+}
+
+template<float func()> void WrapF_V() {
+ RETURNF(func());
+}
+
+// TODO: Not sure about the floating point parameter passing
+template<float func(int, float, u32)> void WrapF_IFU() {
+ RETURNF(func(PARAM(0), PARAMF(0), PARAM(1)));
+}
+
+template<u32 func(u32)> void WrapU_U() {
+ u32 retval = func(PARAM(0));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int)> void WrapU_UI() {
+ u32 retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<int func(u32)> void WrapI_U() {
+ int retval = func(PARAM(0));
+ RETURN(retval);
+}
+
+template<int func(u32, int)> void WrapI_UI() {
+ int retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<int func(u32, int, int, u32)> void WrapI_UIIU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(int, u32, int)> void WrapU_IUI() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(u32, u32)> void WrapI_UU() {
+ int retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<int func(u32, float, float)> void WrapI_UFF() {
+ // Not sure about the float arguments.
+ int retval = func(PARAM(0), PARAMF(0), PARAMF(1));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, u32)> void WrapI_UUU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, u32, int)> void WrapI_UUUI() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, u32, int, int, int,int )> void WrapI_UUUIIII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, u32, u32)> void WrapI_UUUU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, u32, u32, u32)> void WrapI_UUUUU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func()> void WrapI_V() {
+ int retval = func();
+ RETURN(retval);
+}
+
+template<u32 func(int)> void WrapU_I() {
+ u32 retval = func(PARAM(0));
+ RETURN(retval);
+}
+
+template<u32 func(int, int, u32)> void WrapU_IIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(int)> void WrapI_I() {
+ int retval = func(PARAM(0));
+ RETURN(retval);
+}
+
+template<void func(u32)> void WrapV_U() {
+ func(PARAM(0));
+}
+
+template<void func(int)> void WrapV_I() {
+ func(PARAM(0));
+}
+
+template<void func(u32, u32)> void WrapV_UU() {
+ func(PARAM(0), PARAM(1));
+}
+
+template<void func(int, int)> void WrapV_II() {
+ func(PARAM(0), PARAM(1));
+}
+
+template<void func(u32, const char *)> void WrapV_UC() {
+ func(PARAM(0), Memory::GetCharPointer(PARAM(1)));
+}
+
+template<int func(u32, const char *)> void WrapI_UC() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)));
+ RETURN(retval);
+}
+
+template<int func(u32, const char *, int)> void WrapI_UCI() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int , int , int, int, int)> void WrapU_UIIIII() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int , int , int, u32)> void WrapU_UIIIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int , int , int, int, int, int)> void WrapU_UIIIIII() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32)> void WrapU_UU() {
+ u32 retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, int)> void WrapU_UUI() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, int, int)> void WrapU_UUII() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(const char *, u32, u32, u32)> void WrapU_CUUU() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<void func(u32, int, u32, int, int)> void WrapV_UIUII() {
+ func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+}
+
+template<u32 func(u32, int, u32, int, int)> void WrapU_UIUII() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func(u32, int, u32, int, int)> void WrapI_UIUII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int, u32, int)> void WrapU_UIUI() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(u32, int, u32, int)> void WrapI_UIUI() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int, u32)> void WrapU_UIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int, u32, u32)> void WrapU_UIUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int, int)> void WrapU_UII() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int, int, u32)> void WrapU_UIIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(u32, int, int, u32, u32)> void WrapI_UIIUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, int, int)> void WrapI_UUII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, int, int, int)> void WrapI_UUIII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<void func(u32, int, int, int)> void WrapV_UIII() {
+ func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+}
+
+template<void func(u32, int, int, int, int, int)> void WrapV_UIIIII() {
+ func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
+}
+
+template<void func(u32, int, int)> void WrapV_UII() {
+ func(PARAM(0), PARAM(1), PARAM(2));
+}
+
+template<u32 func(int, u32)> void WrapU_IU() {
+ int retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<int func(int, u32)> void WrapI_IU() {
+ int retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, int)> void WrapI_UUI() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(u32, u32, int, u32)> void WrapI_UUIU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(int, int)> void WrapI_II() {
+ int retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<int func(int, int, int)> void WrapI_III() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(int, u32, int)> void WrapI_IUI() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(int, int, int, int)> void WrapI_IIII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(u32, int, int, int)> void WrapI_UIII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(int, int, int, u32, int)> void WrapI_IIIUI() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func(int, u32, u32, int, int)> void WrapI_IUUII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func(int, const char *, int, u32, u32)> void WrapI_ICIUU() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func(int, int, u32)> void WrapI_IIU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<void func(int, u32)> void WrapV_IU() {
+ func(PARAM(0), PARAM(1));
+}
+
+template<void func(u32, int)> void WrapV_UI() {
+ func(PARAM(0), PARAM(1));
+}
+
+template<u32 func(const char *)> void WrapU_C() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)));
+ RETURN(retval);
+}
+
+template<u32 func(const char *, const char *, const char *, u32)> void WrapU_CCCU() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)),
+ Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)),
+ PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(const char *)> void WrapI_C() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)));
+ RETURN(retval);
+}
+
+template<int func(const char *, u32)> void WrapI_CU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
+ RETURN(retval);
+}
+
+template<int func(const char *, u32, int)> void WrapI_CUI() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(int, const char *, int, u32)> void WrapI_ICIU() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(const char *, int, u32)> void WrapI_CIU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(const char *, u32, u32)> void WrapI_CUU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(const char *, u32, u32, u32)> void WrapI_CUUU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(const char *, const char*, int, int)> void WrapI_CCII() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(const char *, u32, u32, int, u32, u32)> void WrapI_CUUIUU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<int func(const char *, int, int, u32, int, int)> void WrapI_CIIUII() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<int func(const char *, int, u32, u32, u32)> void WrapI_CIUUU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func(const char *, u32, u32, u32, u32, u32)> void WrapI_CUUUUU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<u32 func(const char *, u32)> void WrapU_CU() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
+ RETURN((u32) retval);
+}
+
+template<u32 func(u32, const char *)> void WrapU_UC() {
+ u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)));
+ RETURN(retval);
+}
+
+template<u32 func(const char *, u32, u32)> void WrapU_CUU() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
+ RETURN((u32) retval);
+}
+
+template<u32 func(int, int, int)> void WrapU_III() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<u32 func(int, int)> void WrapU_II() {
+ u32 retval = func(PARAM(0), PARAM(1));
+ RETURN(retval);
+}
+
+template<u32 func(int, int, int, int)> void WrapU_IIII() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(int, u32, u32)> void WrapU_IUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<u32 func(int, u32, u32, u32)> void WrapU_IUUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(int, u32, u32, u32, u32)> void WrapU_IUUUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, u32)> void WrapU_UUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<void func(int, u32, u32)> void WrapV_IUU() {
+ func(PARAM(0), PARAM(1), PARAM(2));
+}
+
+template<void func(int, int, u32)> void WrapV_IIU() {
+ func(PARAM(0), PARAM(1), PARAM(2));
+}
+
+template<void func(u32, int, u32)> void WrapV_UIU() {
+ func(PARAM(0), PARAM(1), PARAM(2));
+}
+
+template<int func(u32, int, u32)> void WrapI_UIU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<void func(int, u32, u32, u32, u32)> void WrapV_IUUUU() {
+ func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+}
+
+template<void func(u32, u32, u32)> void WrapV_UUU() {
+ func(PARAM(0), PARAM(1), PARAM(2));
+}
+
+template<void func(u32, u32, u32, u32)> void WrapV_UUUU() {
+ func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+}
+
+template<void func(const char *, u32, int, u32)> void WrapV_CUIU() {
+ func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3));
+}
+
+template<int func(const char *, u32, int, u32)> void WrapI_CUIU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<void func(u32, const char *, u32, int, u32)> void WrapV_UCUIU() {
+ func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3),
+ PARAM(4));
+}
+
+template<int func(u32, const char *, u32, int, u32)> void WrapI_UCUIU() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2),
+ PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<void func(const char *, u32, int, int, u32)> void WrapV_CUIIU() {
+ func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3),
+ PARAM(4));
+}
+
+template<int func(const char *, u32, int, int, u32)> void WrapI_CUIIU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, u32, u32)> void WrapU_UUUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(u32, const char *, u32, u32)> void WrapU_UCUU() {
+ u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, u32, int)> void WrapU_UUUI() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, u32, int, u32)> void WrapU_UUUIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, u32, int, u32, int)> void WrapU_UUUIUI() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, int, u32)> void WrapU_UUIU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<u32 func(u32, int, int, int)> void WrapU_UIII() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(int, u32, u32, u32, u32)> void WrapI_IUUUU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<int func(int, u32, u32, u32, u32, u32)> void WrapI_IUUUUU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<int func(int, u32, int, int)> void WrapI_IUII() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+template<u32 func(u32, u32, u32, u32, u32)> void WrapU_UUUUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<void func(u32, u32, u32, u32, u32)> void WrapV_UUUUU() {
+ func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4));
+}
+
+template<u32 func(const char *, const char *)> void WrapU_CC() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)),
+ Memory::GetCharPointer(PARAM(1)));
+ RETURN(retval);
+}
+
+template<void func(const char *, int)> void WrapV_CI() {
+ func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
+}
+
+template<u32 func(const char *, int)> void WrapU_CI() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1));
+ RETURN(retval);
+}
+
+template<u32 func(const char *, int, int)> void WrapU_CII() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(const char *, int, u32, int, u32)> void WrapU_CIUIU() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template<u32 func(const char *, int, u32, int, u32, int)> void WrapU_CIUIUI() {
+ u32 retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2),
+ PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, u32, u32, u32, u32)> void WrapU_UUUUUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4),
+ PARAM(5));
+ RETURN(retval);
+}
+
+template<int func(int, u32, u32, u32)> void WrapI_IUUU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(int, u32, u32)> void WrapI_IUU() {
+ int retval = func(PARAM(0), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template<u32 func(u32, u32, u32, u32, u32, u32, u32)> void WrapU_UUUUUUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
+ RETURN(retval);
+}
+
+template<int func(u32, int, u32, u32)> void WrapI_UIUU() {
+ u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
+ RETURN(retval);
+}
+
+template<int func(int, const char *)> void WrapI_IC() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)));
+ RETURN(retval);
+}
+
+template <int func(int, const char *, const char *, u32, int)> void WrapI_ICCUI() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3), PARAM(4));
+ RETURN(retval);
+}
+
+template <int func(int, const char *, const char *, int)> void WrapI_ICCI() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), Memory::GetCharPointer(PARAM(2)), PARAM(3));
+ RETURN(retval);
+}
+
+template <int func(const char *, int, int)> void WrapI_CII() {
+ int retval = func(Memory::GetCharPointer(PARAM(0)), PARAM(1), PARAM(2));
+ RETURN(retval);
+}
+
+template <int func(int, const char *, int)> void WrapI_ICI() {
+ int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2));
+ RETURN(retval);
+}
+
+template<int func(int, void *, void *, void *, void *, u32, int)> void WrapI_IVVVVUI(){
+ u32 retval = func(PARAM(0), Memory::GetPointer(PARAM(1)), Memory::GetPointer(PARAM(2)), Memory::GetPointer(PARAM(3)), Memory::GetPointer(PARAM(4)), PARAM(5), PARAM(6) );
+ RETURN(retval);
+}
+
+template<int func(int, const char *, u32, void *, int, int, int)> void WrapI_ICUVIII(){
+ u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), Memory::GetPointer(PARAM(3)), PARAM(4), PARAM(5), PARAM(6));
+ RETURN(retval);
+}
+
+template<int func(void *, u32, u32, u32, u32, u32)> void WrapI_VUUUUU(){
+ u32 retval = func(Memory::GetPointer(PARAM(0)), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5));
+ RETURN(retval);
+}
+
+template<int func(u32, s64)> void WrapI_US64() {
+ int retval = func(PARAM(0), PARAM64(2));
+ RETURN(retval);
+}
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp
new file mode 100644
index 000000000..5672a659f
--- /dev/null
+++ b/src/core/hle/hle.cpp
@@ -0,0 +1,120 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include <vector>
+
+#include "core/mem_map.h"
+#include "core/hle/hle.h"
+#include "core/hle/syscall.h"
+#include "core/hle/service/service.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+namespace HLE {
+
+static std::vector<ModuleDef> g_module_db;
+
+u8* g_command_buffer = NULL; ///< Command buffer used for sharing between appcore and syscore
+
+// Read from memory used by CTROS HLE functions
+template <typename T>
+inline void Read(T &var, const u32 addr) {
+ if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) {
+ var = *((const T*)&g_command_buffer[addr & CMD_BUFFER_MASK]);
+ } else {
+ ERROR_LOG(HLE, "unknown read from address %08X", addr);
+ }
+}
+
+// Write to memory used by CTROS HLE functions
+template <typename T>
+inline void Write(u32 addr, const T data) {
+ if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) {
+ *(T*)&g_command_buffer[addr & CMD_BUFFER_MASK] = data;
+ } else {
+ ERROR_LOG(HLE, "unknown write to address %08X", addr);
+ }
+}
+
+u8 *GetPointer(const u32 addr) {
+ if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) {
+ return g_command_buffer + (addr & CMD_BUFFER_MASK);
+ } else {
+ ERROR_LOG(HLE, "unknown pointer from address %08X", addr);
+ return 0;
+ }
+}
+
+// Explicitly instantiate template functions because we aren't defining this in the header:
+
+template void Read<u64>(u64 &var, const u32 addr);
+template void Read<u32>(u32 &var, const u32 addr);
+template void Read<u16>(u16 &var, const u32 addr);
+template void Read<u8>(u8 &var, const u32 addr);
+
+template void Write<u64>(u32 addr, const u64 data);
+template void Write<u32>(u32 addr, const u32 data);
+template void Write<u16>(u32 addr, const u16 data);
+template void Write<u8>(u32 addr, const u8 data);
+
+const FunctionDef* GetSyscallInfo(u32 opcode) {
+ u32 func_num = opcode & 0xFFFFFF; // 8 bits
+ if (func_num > 0xFF) {
+ ERROR_LOG(HLE,"Unknown syscall: 0x%02X", func_num);
+ return NULL;
+ }
+ return &g_module_db[0].func_table[func_num];
+}
+
+void CallSyscall(u32 opcode) {
+ const FunctionDef *info = GetSyscallInfo(opcode);
+
+ if (!info) {
+ return;
+ }
+ if (info->func) {
+ info->func();
+ } else {
+ ERROR_LOG(HLE, "Unimplemented SysCall function %s(..)", info->name.c_str());
+ }
+}
+
+/// Returns the coprocessor (in this case, syscore) command buffer pointer
+Addr CallGetThreadCommandBuffer() {
+ // Called on insruction: mrc p15, 0, r0, c13, c0, 3
+ // Returns an address in OSHLE memory for the CPU to read/write to
+ RETURN(CMD_BUFFER_ADDR);
+ return CMD_BUFFER_ADDR;
+}
+
+void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) {
+ ModuleDef module = {name, num_functions, func_table};
+ g_module_db.push_back(module);
+}
+
+void RegisterAllModules() {
+ Syscall::Register();
+}
+
+void Init() {
+ Service::Init();
+
+ g_command_buffer = new u8[CMD_BUFFER_SIZE];
+
+ RegisterAllModules();
+
+ NOTICE_LOG(HLE, "initialized OK");
+}
+
+void Shutdown() {
+ Service::Shutdown();
+
+ delete g_command_buffer;
+
+ g_module_db.clear();
+
+ NOTICE_LOG(HLE, "shutdown OK");
+}
+
+} // namespace
diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h
new file mode 100644
index 000000000..628a1da89
--- /dev/null
+++ b/src/core/hle/hle.h
@@ -0,0 +1,66 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "common/common_types.h"
+#include "core/core.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#define PARAM(n) Core::g_app_core->GetReg(n)
+#define PARAM64(n) (Core::g_app_core->GetReg(n) | ((u64)Core::g_app_core->GetReg(n + 1) << 32))
+#define RETURN(n) Core::g_app_core->SetReg(0, n)
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+namespace HLE {
+
+enum {
+ CMD_BUFFER_ADDR = 0xA0010000, ///< Totally arbitrary unused address space
+ CMD_BUFFER_SIZE = 0x10000,
+ CMD_BUFFER_MASK = (CMD_BUFFER_SIZE - 1),
+ CMD_BUFFER_ADDR_END = (CMD_BUFFER_ADDR + CMD_BUFFER_SIZE),
+};
+
+typedef u32 Addr;
+typedef void (*Func)();
+
+struct FunctionDef {
+ u32 id;
+ Func func;
+ std::string name;
+};
+
+struct ModuleDef {
+ std::string name;
+ int num_funcs;
+ const FunctionDef* func_table;
+};
+
+// Read from memory used by CTROS HLE functions
+template <typename T>
+inline void Read(T &var, const u32 addr);
+
+// Write to memory used by CTROS HLE functions
+template <typename T>
+inline void Write(u32 addr, const T data);
+
+u8* GetPointer(const u32 Address);
+
+inline const char* GetCharPointer(const u32 address) {
+ return (const char *)GetPointer(address);
+}
+
+void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table);
+
+void CallSyscall(u32 opcode);
+
+Addr CallGetThreadCommandBuffer();
+
+void Init();
+
+void Shutdown();
+
+} // namespace
diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp
new file mode 100644
index 000000000..4f8d7248d
--- /dev/null
+++ b/src/core/hle/service/apt.cpp
@@ -0,0 +1,116 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+
+#include "common/log.h"
+
+#include "core/hle/hle.h"
+#include "core/hle/service/apt.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace APT_U
+
+namespace APT_U {
+
+void Initialize() {
+ NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize");
+}
+
+void GetLockHandle() {
+ u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);
+ cmd_buff[5] = 0x00000000; // TODO: This should be an actual mutex handle
+}
+
+const HLE::FunctionDef FunctionTable[] = {
+ {0x00010040, GetLockHandle, "GetLockHandle"},
+ {0x00020080, Initialize, "Initialize"},
+ {0x00030040, NULL, "Enable"},
+ {0x00040040, NULL, "Finalize"},
+ {0x00050040, NULL, "GetAppletManInfo"},
+ {0x00060040, NULL, "GetAppletInfo"},
+ {0x00070000, NULL, "GetLastSignaledAppletId"},
+ {0x00080000, NULL, "CountRegisteredApplet"},
+ {0x00090040, NULL, "IsRegistered"},
+ {0x000A0040, NULL, "GetAttribute"},
+ {0x000B0040, NULL, "InquireNotification"},
+ {0x000C0104, NULL, "SendParameter"},
+ {0x000D0080, NULL, "ReceiveParameter"},
+ {0x000E0080, NULL, "GlanceParameter"},
+ {0x000F0100, NULL, "CancelParameter"},
+ {0x001000C2, NULL, "DebugFunc"},
+ {0x001100C0, NULL, "MapProgramIdForDebug"},
+ {0x00120040, NULL, "SetHomeMenuAppletIdForDebug"},
+ {0x00130000, NULL, "GetPreparationState"},
+ {0x00140040, NULL, "SetPreparationState"},
+ {0x00150140, NULL, "PrepareToStartApplication"},
+ {0x00160040, NULL, "PreloadLibraryApplet"},
+ {0x00170040, NULL, "FinishPreloadingLibraryApplet"},
+ {0x00180040, NULL, "PrepareToStartLibraryApplet"},
+ {0x00190040, NULL, "PrepareToStartSystemApplet"},
+ {0x001A0000, NULL, "PrepareToStartNewestHomeMenu"},
+ {0x001B00C4, NULL, "StartApplication"},
+ {0x001C0000, NULL, "WakeupApplication"},
+ {0x001D0000, NULL, "CancelApplication"},
+ {0x001E0084, NULL, "StartLibraryApplet"},
+ {0x001F0084, NULL, "StartSystemApplet"},
+ {0x00200044, NULL, "StartNewestHomeMenu"},
+ {0x00210000, NULL, "OrderToCloseApplication"},
+ {0x00220040, NULL, "PrepareToCloseApplication"},
+ {0x00230040, NULL, "PrepareToJumpToApplication"},
+ {0x00240044, NULL, "JumpToApplication"},
+ {0x002500C0, NULL, "PrepareToCloseLibraryApplet"},
+ {0x00260000, NULL, "PrepareToCloseSystemApplet"},
+ {0x00270044, NULL, "CloseApplication"},
+ {0x00280044, NULL, "CloseLibraryApplet"},
+ {0x00290044, NULL, "CloseSystemApplet"},
+ {0x002A0000, NULL, "OrderToCloseSystemApplet"},
+ {0x002B0000, NULL, "PrepareToJumpToHomeMenu"},
+ {0x002C0044, NULL, "JumpToHomeMenu"},
+ {0x002D0000, NULL, "PrepareToLeaveHomeMenu"},
+ {0x002E0044, NULL, "LeaveHomeMenu"},
+ {0x002F0040, NULL, "PrepareToLeaveResidentApplet"},
+ {0x00300044, NULL, "LeaveResidentApplet"},
+ {0x00310100, NULL, "PrepareToDoApplicationJump"},
+ {0x00320084, NULL, "DoApplicationJump"},
+ {0x00330000, NULL, "GetProgramIdOnApplicationJump"},
+ {0x00340084, NULL, "SendDeliverArg"},
+ {0x00350080, NULL, "ReceiveDeliverArg"},
+ {0x00360040, NULL, "LoadSysMenuArg"},
+ {0x00370042, NULL, "StoreSysMenuArg"},
+ {0x00380040, NULL, "PreloadResidentApplet"},
+ {0x00390040, NULL, "PrepareToStartResidentApplet"},
+ {0x003A0044, NULL, "StartResidentApplet"},
+ {0x003B0040, NULL, "CancelLibraryApplet"},
+ {0x003C0042, NULL, "SendDspSleep"},
+ {0x003D0042, NULL, "SendDspWakeUp"},
+ {0x003E0080, NULL, "ReplySleepQuery"},
+ {0x003F0040, NULL, "ReplySleepNotificationComplete"},
+ {0x00400042, NULL, "SendCaptureBufferInfo"},
+ {0x00410040, NULL, "ReceiveCaptureBufferInfo"},
+ {0x00420080, NULL, "SleepSystem"},
+ {0x00430040, NULL, "NotifyToWait"},
+ {0x00440000, NULL, "GetSharedFont"},
+ {0x00450040, NULL, "GetWirelessRebootInfo"},
+ {0x00460104, NULL, "Wrap"},
+ {0x00470104, NULL, "Unwrap"},
+ {0x00480100, NULL, "GetProgramInfo"},
+ {0x00490180, NULL, "Reboot"},
+ {0x004A0040, NULL, "GetCaptureInfo"},
+ {0x004B00C2, NULL, "AppletUtility"},
+ {0x004C0000, NULL, "SetFatalErrDispMode"},
+ {0x004D0080, NULL, "GetAppletProgramInfo"},
+ {0x004E0000, NULL, "HardwareResetAsync"},
+};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Interface class
+
+Interface::Interface() {
+ Register(FunctionTable, ARRAY_SIZE(FunctionTable));
+}
+
+Interface::~Interface() {
+}
+
+} // namespace
diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h
new file mode 100644
index 000000000..e74baac0c
--- /dev/null
+++ b/src/core/hle/service/apt.h
@@ -0,0 +1,41 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/hle/service/service.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace APT_U
+
+namespace APT_U {
+
+// Application and title launching service. These services handle signaling for home/power button as
+// well. Only one session for either APT service can be open at a time, normally processes close the
+// service handle immediately once finished using the service. The commands for APT:U and APT:S are
+// exactly the same, however certain commands are only accessible with APT:S(NS module will call
+// svcBreak when the command isn't accessible). See http://3dbrew.org/wiki/NS#APT_Services.
+
+/// Interface to "APT:U" service
+class Interface : public Service::Interface {
+public:
+
+ Interface();
+
+ ~Interface();
+
+ /**
+ * Gets the string port name used by CTROS for the service
+ * @return Port name of service
+ */
+ std::string GetPortName() const {
+ return "APT:U";
+ }
+
+private:
+
+ DISALLOW_COPY_AND_ASSIGN(Interface);
+};
+
+} // namespace
diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp
new file mode 100644
index 000000000..7c80ab8b5
--- /dev/null
+++ b/src/core/hle/service/gsp.cpp
@@ -0,0 +1,59 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+
+#include "common/log.h"
+
+#include "core/hle/hle.h"
+#include "core/hle/service/gsp.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace GSP_GPU
+
+namespace GSP_GPU {
+
+const HLE::FunctionDef FunctionTable[] = {
+ {0x00010082, NULL, "WriteHWRegs"},
+ {0x00020084, NULL, "WriteHWRegsWithMask"},
+ {0x00030082, NULL, "WriteHWRegRepeat"},
+ {0x00040080, NULL, "ReadHWRegs"},
+ {0x00050200, NULL, "SetBufferSwap"},
+ {0x00060082, NULL, "SetCommandList"},
+ {0x000700C2, NULL, "RequestDma"},
+ {0x00080082, NULL, "FlushDataCache"},
+ {0x00090082, NULL, "InvalidateDataCache"},
+ {0x000A0044, NULL, "RegisterInterruptEvents"},
+ {0x000B0040, NULL, "SetLcdForceBlack"},
+ {0x000C0000, NULL, "TriggerCmdReqQueue"},
+ {0x000D0140, NULL, "SetDisplayTransfer"},
+ {0x000E0180, NULL, "SetTextureCopy"},
+ {0x000F0200, NULL, "SetMemoryFill"},
+ {0x00100040, NULL, "SetAxiConfigQoSMode"},
+ {0x00110040, NULL, "SetPerfLogMode"},
+ {0x00120000, NULL, "GetPerfLog"},
+ {0x00130042, NULL, "RegisterInterruptRelayQueue"},
+ {0x00140000, NULL, "UnregisterInterruptRelayQueue"},
+ {0x00150002, NULL, "TryAcquireRight"},
+ {0x00160042, NULL, "AcquireRight"},
+ {0x00170000, NULL, "ReleaseRight"},
+ {0x00180000, NULL, "ImportDisplayCaptureInfo"},
+ {0x00190000, NULL, "SaveVramSysArea"},
+ {0x001A0000, NULL, "RestoreVramSysArea"},
+ {0x001B0000, NULL, "ResetGpuCore"},
+ {0x001C0040, NULL, "SetLedForceOff"},
+ {0x001D0040, NULL, "SetTestCommand"},
+ {0x001E0080, NULL, "SetInternalPriorities"},
+};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Interface class
+
+Interface::Interface() {
+ Register(FunctionTable, ARRAY_SIZE(FunctionTable));
+}
+
+Interface::~Interface() {
+}
+
+} // namespace
diff --git a/src/core/hle/service/gsp.h b/src/core/hle/service/gsp.h
new file mode 100644
index 000000000..3b1846082
--- /dev/null
+++ b/src/core/hle/service/gsp.h
@@ -0,0 +1,35 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/hle/service/service.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace GSP_GPU
+
+namespace GSP_GPU {
+
+/// Interface to "srv:" service
+class Interface : public Service::Interface {
+public:
+
+ Interface();
+
+ ~Interface();
+
+ /**
+ * Gets the string port name used by CTROS for the service
+ * @return Port name of service
+ */
+ std::string GetPortName() const {
+ return "gsp::Gpu";
+ }
+
+private:
+
+ DISALLOW_COPY_AND_ASSIGN(Interface);
+};
+
+} // namespace
diff --git a/src/core/hle/service/hid.cpp b/src/core/hle/service/hid.cpp
new file mode 100644
index 000000000..2d823dd16
--- /dev/null
+++ b/src/core/hle/service/hid.cpp
@@ -0,0 +1,33 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "common/log.h"
+
+#include "core/hle/hle.h"
+#include "core/hle/service/hid.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace HID_User
+
+namespace HID_User {
+
+const HLE::FunctionDef FunctionTable[] = {
+ {0x000A0000, NULL, "GetIPCHandles"},
+ {0x00110000, NULL, "EnableAccelerometer"},
+ {0x00130000, NULL, "EnableGyroscopeLow"},
+ {0x00150000, NULL, "GetGyroscopeLowRawToDpsCoefficient"},
+ {0x00160000, NULL, "GetGyroscopeLowCalibrateParam"},
+};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Interface class
+
+Interface::Interface() {
+ Register(FunctionTable, ARRAY_SIZE(FunctionTable));
+}
+
+Interface::~Interface() {
+}
+
+} // namespace
diff --git a/src/core/hle/service/hid.h b/src/core/hle/service/hid.h
new file mode 100644
index 000000000..746c1b1fc
--- /dev/null
+++ b/src/core/hle/service/hid.h
@@ -0,0 +1,37 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/hle/service/service.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace HID_User
+
+// This service is used for interfacing to physical user controls... perhaps "Human Interface
+// Devices"? Uses include game pad controls, accelerometers, gyroscopes, etc.
+
+namespace HID_User {
+
+class Interface : public Service::Interface {
+public:
+
+ Interface();
+
+ ~Interface();
+
+ /**
+ * Gets the string port name used by CTROS for the service
+ * @return Port name of service
+ */
+ std::string GetPortName() const {
+ return "hid:USER";
+ }
+
+private:
+
+ DISALLOW_COPY_AND_ASSIGN(Interface);
+};
+
+} // namespace
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
new file mode 100644
index 000000000..e6605a398
--- /dev/null
+++ b/src/core/hle/service/service.cpp
@@ -0,0 +1,94 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "common/common.h"
+#include "common/log.h"
+#include "common/string_util.h"
+
+#include "core/hle/hle.h"
+#include "core/hle/service/service.h"
+#include "core/hle/service/apt.h"
+#include "core/hle/service/gsp.h"
+#include "core/hle/service/hid.h"
+#include "core/hle/service/srv.h"
+
+namespace Service {
+
+Manager* g_manager = NULL; ///< Service manager
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Service Manager class
+
+Manager::Manager() {
+}
+
+Manager::~Manager() {
+ for(Interface* service : m_services) {
+ DeleteService(service->GetPortName());
+ }
+}
+
+/// Add a service to the manager (does not create it though)
+void Manager::AddService(Interface* service) {
+ int index = m_services.size();
+ u32 new_uid = GetUIDFromIndex(index);
+
+ m_services.push_back(service);
+
+ m_port_map[service->GetPortName()] = new_uid;
+ service->m_uid = new_uid;
+}
+
+/// Removes a service from the manager, also frees memory
+void Manager::DeleteService(std::string port_name) {
+ auto service = FetchFromPortName(port_name);
+
+ m_services.erase(m_services.begin() + GetIndexFromUID(service->m_uid));
+ m_port_map.erase(port_name);
+
+ delete service;
+}
+
+/// Get a Service Interface from its UID
+Interface* Manager::FetchFromUID(u32 uid) {
+ int index = GetIndexFromUID(uid);
+ if (index < (int)m_services.size()) {
+ return m_services[index];
+ }
+ return NULL;
+}
+
+/// Get a Service Interface from its port
+Interface* Manager::FetchFromPortName(std::string port_name) {
+ auto itr = m_port_map.find(port_name);
+ if (itr == m_port_map.end()) {
+ return NULL;
+ }
+ return FetchFromUID(itr->second);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Module interface
+
+/// Initialize ServiceManager
+void Init() {
+ g_manager = new Manager;
+
+ g_manager->AddService(new SRV::Interface);
+ g_manager->AddService(new APT_U::Interface);
+ g_manager->AddService(new GSP_GPU::Interface);
+ g_manager->AddService(new HID_User::Interface);
+
+ NOTICE_LOG(HLE, "Services initialized OK");
+}
+
+/// Shutdown ServiceManager
+void Shutdown() {
+ delete g_manager;
+ NOTICE_LOG(HLE, "Services shutdown OK");
+}
+
+
+}
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
new file mode 100644
index 000000000..9cbf8b6fa
--- /dev/null
+++ b/src/core/hle/service/service.h
@@ -0,0 +1,143 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <vector>
+#include <map>
+#include <string>
+
+#include "common/common.h"
+#include "common/common_types.h"
+#include "core/hle/syscall.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace Service
+
+namespace Service {
+
+typedef s32 NativeUID; ///< Native handle for a service
+
+static const int kMaxPortSize = 0x08; ///< Maximum size of a port name (8 characters)
+static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header
+
+class Manager;
+
+/// Interface to a CTROS service
+class Interface {
+ friend class Manager;
+public:
+
+ Interface() {
+ }
+
+ virtual ~Interface() {
+ }
+
+ /**
+ * Gets the UID for the serice
+ * @return UID of service in native format
+ */
+ NativeUID GetUID() const {
+ return (NativeUID)m_uid;
+ }
+
+ /**
+ * Gets the string name used by CTROS for a service
+ * @return Port name of service
+ */
+ virtual std::string GetPortName() const {
+ return "[UNKNOWN SERVICE PORT]";
+ }
+
+ /**
+ * Called when svcSendSyncRequest is called, loads command buffer and executes comand
+ * @return Return result of svcSendSyncRequest passed back to user app
+ */
+ Syscall::Result Sync() {
+ u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + kCommandHeaderOffset);
+ auto itr = m_functions.find(cmd_buff[0]);
+
+ if (itr == m_functions.end()) {
+ ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!",
+ GetPortName().c_str(), cmd_buff[0]);
+ return -1;
+ }
+ if (itr->second.func == NULL) {
+ ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!",
+ GetPortName().c_str(), itr->second.name.c_str());
+ return -1;
+ }
+
+ itr->second.func();
+
+ return 0; // TODO: Implement return from actual function
+ }
+
+protected:
+ /**
+ * Registers the functions in the service
+ */
+ void Register(const HLE::FunctionDef* functions, int len) {
+ for (int i = 0; i < len; i++) {
+ m_functions[functions[i].id] = functions[i];
+ }
+ }
+
+private:
+ u32 m_uid;
+ std::map<u32, HLE::FunctionDef> m_functions;
+
+ DISALLOW_COPY_AND_ASSIGN(Interface);
+};
+
+/// Simple class to manage accessing services from ports and UID handles
+class Manager {
+
+public:
+ Manager();
+
+ ~Manager();
+
+ /// Add a service to the manager (does not create it though)
+ void AddService(Interface* service);
+
+ /// Removes a service from the manager (does not delete it though)
+ void DeleteService(std::string port_name);
+
+ /// Get a Service Interface from its UID
+ Interface* FetchFromUID(u32 uid);
+
+ /// Get a Service Interface from its port
+ Interface* FetchFromPortName(std::string port_name);
+
+private:
+
+ /// Convert an index into m_services vector into a UID
+ static u32 GetUIDFromIndex(const int index) {
+ return index | 0x10000000;
+ }
+
+ /// Convert a UID into an index into m_services
+ static int GetIndexFromUID(const u32 uid) {
+ return uid & 0x0FFFFFFF;
+ }
+
+ std::vector<Interface*> m_services;
+ std::map<std::string, u32> m_port_map;
+
+ DISALLOW_COPY_AND_ASSIGN(Manager);
+};
+
+/// Initialize ServiceManager
+void Init();
+
+/// Shutdown ServiceManager
+void Shutdown();
+
+
+extern Manager* g_manager; ///< Service manager
+
+
+} // namespace
diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp
new file mode 100644
index 000000000..579ea4a34
--- /dev/null
+++ b/src/core/hle/service/srv.cpp
@@ -0,0 +1,58 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "core/hle/hle.h"
+#include "core/hle/service/srv.h"
+#include "core/hle/service/service.h"
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace SRV
+
+namespace SRV {
+
+void Initialize() {
+ NOTICE_LOG(OSHLE, "SRV::Sync - Initialize");
+}
+
+void GetServiceHandle() {
+ Syscall::Result res = 0;
+ u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);
+
+ std::string port_name = std::string((const char*)&cmd_buff[1], 0, Service::kMaxPortSize);
+ Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
+
+ NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name.c_str(),
+ service->GetUID());
+
+ if (NULL != service) {
+ cmd_buff[3] = service->GetUID();
+ } else {
+ ERROR_LOG(OSHLE, "Service %s does not exist", port_name.c_str());
+ res = -1;
+ }
+ cmd_buff[1] = res;
+
+ //return res;
+}
+
+const HLE::FunctionDef FunctionTable[] = {
+ {0x00010002, Initialize, "Initialize"},
+ {0x00020000, NULL, "GetProcSemaphore"},
+ {0x00030100, NULL, "RegisterService"},
+ {0x000400C0, NULL, "UnregisterService"},
+ {0x00050100, GetServiceHandle, "GetServiceHandle"},
+};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Interface class
+
+Interface::Interface() {
+ Register(FunctionTable, ARRAY_SIZE(FunctionTable));
+}
+
+Interface::~Interface() {
+}
+
+} // namespace
diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.h
new file mode 100644
index 000000000..d9ac8fc88
--- /dev/null
+++ b/src/core/hle/service/srv.h
@@ -0,0 +1,40 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "core/hle/service/service.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace SRV
+
+namespace SRV {
+
+/// Interface to "srv:" service
+class Interface : public Service::Interface {
+
+public:
+
+ Interface();
+
+ ~Interface();
+
+ /**
+ * Gets the string name used by CTROS for the service
+ * @return Port name of service
+ */
+ std::string GetPortName() const {
+ return "srv:";
+ }
+
+ /**
+ * Called when svcSendSyncRequest is called, loads command buffer and executes comand
+ * @return Return result of svcSendSyncRequest passed back to user app
+ */
+ Syscall::Result Sync();
+
+private:
+
+ DISALLOW_COPY_AND_ASSIGN(Interface);
+};
+
+} // namespace
diff --git a/src/core/hle/syscall.cpp b/src/core/hle/syscall.cpp
new file mode 100644
index 000000000..e5533a741
--- /dev/null
+++ b/src/core/hle/syscall.cpp
@@ -0,0 +1,197 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include <map>
+
+#include "core/mem_map.h"
+
+#include "core/hle/function_wrappers.h"
+#include "core/hle/syscall.h"
+#include "core/hle/service/service.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace Syscall
+
+namespace Syscall {
+
+/// Map application or GSP heap memory
+Result ControlMemory(void* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions) {
+ u32 virtual_address = 0x00000000;
+
+ switch (operation) {
+
+ // Map GSP heap memory?
+ case 0x00010003:
+ virtual_address = Memory::MapBlock_HeapGSP(size, operation, permissions);
+ break;
+
+ // Unknown ControlMemory operation
+ default:
+ ERROR_LOG(OSHLE, "Unknown ControlMemory operation %08X", operation);
+ }
+
+ Core::g_app_core->SetReg(1, Memory::MapBlock_HeapGSP(size, operation, permissions));
+ return 0;
+}
+
+/// Connect to an OS service given the port name, returns the handle to the port to out
+Result ConnectToPort(void* out, const char* port_name) {
+ Service::Interface* service = Service::g_manager->FetchFromPortName(port_name);
+ Core::g_app_core->SetReg(1, service->GetUID());
+ return 0;
+}
+
+/// Synchronize to an OS service
+Result SendSyncRequest(Handle session) {
+ Service::Interface* service = Service::g_manager->FetchFromUID(session);
+ service->Sync();
+ return 0;
+}
+
+/// Close a handle
+Result CloseHandle(Handle handle) {
+ // ImplementMe
+ return 0;
+}
+
+/// Wait for a handle to synchronize, timeout after the specified nanoseconds
+Result WaitSynchronization1(Handle handle, s64 nanoseconds) {
+ // ImplementMe
+ return 0;
+}
+
+const HLE::FunctionDef Syscall_Table[] = {
+ {0x00, NULL, "Unknown"},
+ {0x01, WrapI_VUUUUU<ControlMemory>, "ControlMemory"},
+ {0x02, NULL, "QueryMemory"},
+ {0x03, NULL, "ExitProcess"},
+ {0x04, NULL, "GetProcessAffinityMask"},
+ {0x05, NULL, "SetProcessAffinityMask"},
+ {0x06, NULL, "GetProcessIdealProcessor"},
+ {0x07, NULL, "SetProcessIdealProcessor"},
+ {0x08, NULL, "CreateThread"},
+ {0x09, NULL, "ExitThread"},
+ {0x0A, NULL, "SleepThread"},
+ {0x0B, NULL, "GetThreadPriority"},
+ {0x0C, NULL, "SetThreadPriority"},
+ {0x0D, NULL, "GetThreadAffinityMask"},
+ {0x0E, NULL, "SetThreadAffinityMask"},
+ {0x0F, NULL, "GetThreadIdealProcessor"},
+ {0x10, NULL, "SetThreadIdealProcessor"},
+ {0x11, NULL, "GetCurrentProcessorNumber"},
+ {0x12, NULL, "Run"},
+ {0x13, NULL, "CreateMutex"},
+ {0x14, NULL, "ReleaseMutex"},
+ {0x15, NULL, "CreateSemaphore"},
+ {0x16, NULL, "ReleaseSemaphore"},
+ {0x17, NULL, "CreateEvent"},
+ {0x18, NULL, "SignalEvent"},
+ {0x19, NULL, "ClearEvent"},
+ {0x1A, NULL, "CreateTimer"},
+ {0x1B, NULL, "SetTimer"},
+ {0x1C, NULL, "CancelTimer"},
+ {0x1D, NULL, "ClearTimer"},
+ {0x1E, NULL, "CreateMemoryBlock"},
+ {0x1F, NULL, "MapMemoryBlock"},
+ {0x20, NULL, "UnmapMemoryBlock"},
+ {0x21, NULL, "CreateAddressArbiter"},
+ {0x22, NULL, "ArbitrateAddress"},
+ {0x23, WrapI_U<CloseHandle>, "CloseHandle"},
+ {0x24, WrapI_US64<WaitSynchronization1>, "WaitSynchronization1"},
+ {0x25, NULL, "WaitSynchronizationN"},
+ {0x26, NULL, "SignalAndWait"},
+ {0x27, NULL, "DuplicateHandle"},
+ {0x28, NULL, "GetSystemTick"},
+ {0x29, NULL, "GetHandleInfo"},
+ {0x2A, NULL, "GetSystemInfo"},
+ {0x2B, NULL, "GetProcessInfo"},
+ {0x2C, NULL, "GetThreadInfo"},
+ {0x2D, WrapI_VC<ConnectToPort>, "ConnectToPort"},
+ {0x2E, NULL, "SendSyncRequest1"},
+ {0x2F, NULL, "SendSyncRequest2"},
+ {0x30, NULL, "SendSyncRequest3"},
+ {0x31, NULL, "SendSyncRequest4"},
+ {0x32, WrapI_U<SendSyncRequest>, "SendSyncRequest"},
+ {0x33, NULL, "OpenProcess"},
+ {0x34, NULL, "OpenThread"},
+ {0x35, NULL, "GetProcessId"},
+ {0x36, NULL, "GetProcessIdOfThread"},
+ {0x37, NULL, "GetThreadId"},
+ {0x38, NULL, "GetResourceLimit"},
+ {0x39, NULL, "GetResourceLimitLimitValues"},
+ {0x3A, NULL, "GetResourceLimitCurrentValues"},
+ {0x3B, NULL, "GetThreadContext"},
+ {0x3C, NULL, "Break"},
+ {0x3D, NULL, "OutputDebugString"},
+ {0x3E, NULL, "ControlPerformanceCounter"},
+ {0x3F, NULL, "Unknown"},
+ {0x40, NULL, "Unknown"},
+ {0x41, NULL, "Unknown"},
+ {0x42, NULL, "Unknown"},
+ {0x43, NULL, "Unknown"},
+ {0x44, NULL, "Unknown"},
+ {0x45, NULL, "Unknown"},
+ {0x46, NULL, "Unknown"},
+ {0x47, NULL, "CreatePort"},
+ {0x48, NULL, "CreateSessionToPort"},
+ {0x49, NULL, "CreateSession"},
+ {0x4A, NULL, "AcceptSession"},
+ {0x4B, NULL, "ReplyAndReceive1"},
+ {0x4C, NULL, "ReplyAndReceive2"},
+ {0x4D, NULL, "ReplyAndReceive3"},
+ {0x4E, NULL, "ReplyAndReceive4"},
+ {0x4F, NULL, "ReplyAndReceive"},
+ {0x50, NULL, "BindInterrupt"},
+ {0x51, NULL, "UnbindInterrupt"},
+ {0x52, NULL, "InvalidateProcessDataCache"},
+ {0x53, NULL, "StoreProcessDataCache"},
+ {0x54, NULL, "FlushProcessDataCache"},
+ {0x55, NULL, "StartInterProcessDma"},
+ {0x56, NULL, "StopDma"},
+ {0x57, NULL, "GetDmaState"},
+ {0x58, NULL, "RestartDma"},
+ {0x59, NULL, "Unknown"},
+ {0x5A, NULL, "Unknown"},
+ {0x5B, NULL, "Unknown"},
+ {0x5C, NULL, "Unknown"},
+ {0x5D, NULL, "Unknown"},
+ {0x5E, NULL, "Unknown"},
+ {0x5F, NULL, "Unknown"},
+ {0x60, NULL, "DebugActiveProcess"},
+ {0x61, NULL, "BreakDebugProcess"},
+ {0x62, NULL, "TerminateDebugProcess"},
+ {0x63, NULL, "GetProcessDebugEvent"},
+ {0x64, NULL, "ContinueDebugEvent"},
+ {0x65, NULL, "GetProcessList"},
+ {0x66, NULL, "GetThreadList"},
+ {0x67, NULL, "GetDebugThreadContext"},
+ {0x68, NULL, "SetDebugThreadContext"},
+ {0x69, NULL, "QueryDebugProcessMemory"},
+ {0x6A, NULL, "ReadProcessMemory"},
+ {0x6B, NULL, "WriteProcessMemory"},
+ {0x6C, NULL, "SetHardwareBreakPoint"},
+ {0x6D, NULL, "GetDebugThreadParam"},
+ {0x6E, NULL, "Unknown"},
+ {0x6F, NULL, "Unknown"},
+ {0x70, NULL, "ControlProcessMemory"},
+ {0x71, NULL, "MapProcessMemory"},
+ {0x72, NULL, "UnmapProcessMemory"},
+ {0x73, NULL, "Unknown"},
+ {0x74, NULL, "Unknown"},
+ {0x75, NULL, "Unknown"},
+ {0x76, NULL, "TerminateProcess"},
+ {0x77, NULL, "Unknown"},
+ {0x78, NULL, "CreateResourceLimit"},
+ {0x79, NULL, "Unknown"},
+ {0x7A, NULL, "Unknown"},
+ {0x7B, NULL, "Unknown"},
+ {0x7C, NULL, "KernelSetState"},
+ {0x7D, NULL, "QueryProcessMemory"},
+};
+
+void Register() {
+ HLE::RegisterModule("SyscallTable", ARRAY_SIZE(Syscall_Table), Syscall_Table);
+}
+
+} // namespace
diff --git a/src/core/hle/syscall.h b/src/core/hle/syscall.h
new file mode 100644
index 000000000..7a94e0136
--- /dev/null
+++ b/src/core/hle/syscall.h
@@ -0,0 +1,19 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "common/common_types.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Namespace Syscall
+
+namespace Syscall {
+
+typedef u32 Handle;
+typedef s32 Result;
+
+void Register();
+
+} // namespace