summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/hle/hle.cpp45
-rw-r--r--src/core/hle/hle.h13
-rw-r--r--src/core/mem_map.h4
-rw-r--r--src/core/mem_map_funcs.cpp10
4 files changed, 60 insertions, 12 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
diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h
index 2bd1f99a2..5ee90bcdc 100644
--- a/src/core/hle/hle.h
+++ b/src/core/hle/hle.h
@@ -17,7 +17,10 @@
17namespace HLE { 17namespace HLE {
18 18
19enum { 19enum {
20 OS_THREAD_COMMAND_BUFFER_ADDR = 0xA0004000, 20 CMD_BUFFER_ADDR = 0xA0010000, ///< Totally arbitrary unused address space
21 CMD_BUFFER_SIZE = 0x10000,
22 CMD_BUFFER_MASK = (CMD_BUFFER_SIZE - 1),
23 CMD_BUFFER_ADDR_END = (CMD_BUFFER_ADDR + CMD_BUFFER_SIZE),
21}; 24};
22 25
23typedef u32 Addr; 26typedef u32 Addr;
@@ -35,6 +38,14 @@ struct ModuleDef {
35 const FunctionDef* func_table; 38 const FunctionDef* func_table;
36}; 39};
37 40
41// Read from memory used by CTROS HLE functions
42template <typename T>
43inline void Read(T &var, const u32 addr);
44
45// Write to memory used by CTROS HLE functions
46template <typename T>
47inline void Write(u32 addr, const T data);
48
38void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); 49void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table);
39 50
40void CallSyscall(u32 opcode); 51void CallSyscall(u32 opcode);
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index 2596ba925..ab2c2d4ec 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -32,10 +32,6 @@ enum {
32 32
33 MEM_VRAM_VADDR = 0x1F000000, 33 MEM_VRAM_VADDR = 0x1F000000,
34 MEM_SCRATCHPAD_VADDR = (0x10000000 - MEM_SCRATCHPAD_SIZE), ///< Scratchpad virtual address 34 MEM_SCRATCHPAD_VADDR = (0x10000000 - MEM_SCRATCHPAD_SIZE), ///< Scratchpad virtual address
35
36 MEM_OSHLE_SIZE = 0x08000000, ///< ...Same size as FCRAM for now
37 MEM_OSHLE_VADDR = 0xA0000000, ///< Memory for use by OSHLE accessible by appcore CPU
38 MEM_OSHLE_VADDR_END = (MEM_OSHLE_VADDR + MEM_OSHLE_SIZE),
39}; 35};
40 36
41//////////////////////////////////////////////////////////////////////////////////////////////////// 37////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index f35e25caf..184296287 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -20,8 +20,8 @@ inline void _Read(T &var, const u32 addr) {
20 // Memory allocated for HLE use that can be addressed from the emulated application 20 // Memory allocated for HLE use that can be addressed from the emulated application
21 // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE 21 // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE
22 // core running the user application (appcore) 22 // core running the user application (appcore)
23 if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { 23 if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) {
24 NOTICE_LOG(MEMMAP, "OSHLE read @ 0x%08X", addr); 24 HLE::Read<T>(var, addr);
25 25
26 // Hardware I/O register reads 26 // Hardware I/O register reads
27 // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space 27 // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space
@@ -58,13 +58,13 @@ inline void _Write(u32 addr, const T data) {
58 // Memory allocated for HLE use that can be addressed from the emulated application 58 // Memory allocated for HLE use that can be addressed from the emulated application
59 // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE 59 // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE
60 // core running the user application (appcore) 60 // core running the user application (appcore)
61 if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { 61 if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) {
62 NOTICE_LOG(MEMMAP, "OSHLE write @ 0x%08X", addr); 62 HLE::Write<T>(addr, data);
63 63
64 // Hardware I/O register writes 64 // Hardware I/O register writes
65 // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space 65 // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space
66 } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { 66 } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) {
67 HW::Write<const T>(addr, data); 67 HW::Write<T>(addr, data);
68 68
69 // ExeFS:/.code is loaded here: 69 // ExeFS:/.code is loaded here:
70 } else if ((addr & 0xFFF00000) == 0x00100000) { 70 } else if ((addr & 0xFFF00000) == 0x00100000) {