summaryrefslogtreecommitdiff
path: root/src/core/hle/hle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/hle.cpp')
-rw-r--r--src/core/hle/hle.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp
index 3d2c53954..51432dc87 100644
--- a/src/core/hle/hle.cpp
+++ b/src/core/hle/hle.cpp
@@ -15,6 +15,40 @@ namespace HLE {
15 15
16static std::vector<ModuleDef> g_module_db; 16static std::vector<ModuleDef> g_module_db;
17 17
18u8* g_command_buffer = NULL; ///< Command buffer used for sharing between appcore and syscore
19
20// Read from memory used by CTROS HLE functions
21template <typename T>
22inline void Read(T &var, const u32 addr) {
23 if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) {
24 var = *((const T*)&g_command_buffer[addr & CMD_BUFFER_MASK]);
25 } else {
26 ERROR_LOG(HLE, "unknown read from address %08X", addr);
27 }
28}
29
30// Write to memory used by CTROS HLE functions
31template <typename T>
32inline void Write(u32 addr, const T data) {
33 if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) {
34 *(T*)&g_command_buffer[addr & CMD_BUFFER_MASK] = data;
35 } else {
36 ERROR_LOG(HLE, "unknown write to address %08X", addr);
37 }
38}
39
40// Explicitly instantiate template functions because we aren't defining this in the header:
41
42template void Read<u64>(u64 &var, const u32 addr);
43template void Read<u32>(u32 &var, const u32 addr);
44template void Read<u16>(u16 &var, const u32 addr);
45template void Read<u8>(u8 &var, const u32 addr);
46
47template void Write<u64>(u32 addr, const u64 data);
48template void Write<u32>(u32 addr, const u32 data);
49template void Write<u16>(u32 addr, const u16 data);
50template void Write<u8>(u32 addr, const u8 data);
51
18const FunctionDef* GetSyscallInfo(u32 opcode) { 52const FunctionDef* GetSyscallInfo(u32 opcode) {
19 u32 func_num = opcode & 0xFFFFFF; // 8 bits 53 u32 func_num = opcode & 0xFFFFFF; // 8 bits
20 if (func_num > 0xFF) { 54 if (func_num > 0xFF) {
@@ -41,8 +75,8 @@ void CallSyscall(u32 opcode) {
41Addr CallGetThreadCommandBuffer() { 75Addr CallGetThreadCommandBuffer() {
42 // Called on insruction: mrc p15, 0, r0, c13, c0, 3 76 // Called on insruction: mrc p15, 0, r0, c13, c0, 3
43 // Returns an address in OSHLE memory for the CPU to read/write to 77 // Returns an address in OSHLE memory for the CPU to read/write to
44 RETURN(OS_THREAD_COMMAND_BUFFER_ADDR); 78 RETURN(CMD_BUFFER_ADDR);
45 return OS_THREAD_COMMAND_BUFFER_ADDR; 79 return CMD_BUFFER_ADDR;
46} 80}
47 81
48void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) { 82void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) {
@@ -56,6 +90,8 @@ void RegisterAllModules() {
56 90
57void Init() { 91void Init() {
58 Service::Init(); 92 Service::Init();
93
94 g_command_buffer = new u8[CMD_BUFFER_SIZE];
59 95
60 RegisterAllModules(); 96 RegisterAllModules();
61 97
@@ -63,7 +99,12 @@ void Init() {
63} 99}
64 100
65void Shutdown() { 101void Shutdown() {
102 Service::Shutdown();
103
104 delete g_command_buffer;
105
66 g_module_db.clear(); 106 g_module_db.clear();
107
67 NOTICE_LOG(HLE, "shutdown OK"); 108 NOTICE_LOG(HLE, "shutdown OK");
68} 109}
69 110