diff options
| author | 2014-04-18 17:52:49 -0400 | |
|---|---|---|
| committer | 2014-04-18 17:52:49 -0400 | |
| commit | 958bca606e80110e05d7c142dda3097fddc96503 (patch) | |
| tree | 576917751444b4dfdb476d040b4e075bde431b7b /src/core/hle/hle.cpp | |
| parent | Init window size from VideoCore. Start changing the default window behavior... (diff) | |
| parent | renamed hw_lcd module to just lcd (diff) | |
| download | yuzu-958bca606e80110e05d7c142dda3097fddc96503.tar.gz yuzu-958bca606e80110e05d7c142dda3097fddc96503.tar.xz yuzu-958bca606e80110e05d7c142dda3097fddc96503.zip | |
Merge branch 'hle-interface'
Diffstat (limited to 'src/core/hle/hle.cpp')
| -rw-r--r-- | src/core/hle/hle.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
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 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "core/mem_map.h" | ||
| 8 | #include "core/hle/hle.h" | ||
| 9 | #include "core/hle/syscall.h" | ||
| 10 | #include "core/hle/service/service.h" | ||
| 11 | |||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 13 | |||
| 14 | namespace HLE { | ||
| 15 | |||
| 16 | static std::vector<ModuleDef> g_module_db; | ||
| 17 | |||
| 18 | u8* g_command_buffer = NULL; ///< Command buffer used for sharing between appcore and syscore | ||
| 19 | |||
| 20 | // Read from memory used by CTROS HLE functions | ||
| 21 | template <typename T> | ||
| 22 | inline 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 | ||
| 31 | template <typename T> | ||
| 32 | inline 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 | u8 *GetPointer(const u32 addr) { | ||
| 41 | if (addr >= HLE::CMD_BUFFER_ADDR && addr < HLE::CMD_BUFFER_ADDR_END) { | ||
| 42 | return g_command_buffer + (addr & CMD_BUFFER_MASK); | ||
| 43 | } else { | ||
| 44 | ERROR_LOG(HLE, "unknown pointer from address %08X", addr); | ||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | // Explicitly instantiate template functions because we aren't defining this in the header: | ||
| 50 | |||
| 51 | template void Read<u64>(u64 &var, const u32 addr); | ||
| 52 | template void Read<u32>(u32 &var, const u32 addr); | ||
| 53 | template void Read<u16>(u16 &var, const u32 addr); | ||
| 54 | template void Read<u8>(u8 &var, const u32 addr); | ||
| 55 | |||
| 56 | template void Write<u64>(u32 addr, const u64 data); | ||
| 57 | template void Write<u32>(u32 addr, const u32 data); | ||
| 58 | template void Write<u16>(u32 addr, const u16 data); | ||
| 59 | template void Write<u8>(u32 addr, const u8 data); | ||
| 60 | |||
| 61 | const FunctionDef* GetSyscallInfo(u32 opcode) { | ||
| 62 | u32 func_num = opcode & 0xFFFFFF; // 8 bits | ||
| 63 | if (func_num > 0xFF) { | ||
| 64 | ERROR_LOG(HLE,"Unknown syscall: 0x%02X", func_num); | ||
| 65 | return NULL; | ||
| 66 | } | ||
| 67 | return &g_module_db[0].func_table[func_num]; | ||
| 68 | } | ||
| 69 | |||
| 70 | void CallSyscall(u32 opcode) { | ||
| 71 | const FunctionDef *info = GetSyscallInfo(opcode); | ||
| 72 | |||
| 73 | if (!info) { | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | if (info->func) { | ||
| 77 | info->func(); | ||
| 78 | } else { | ||
| 79 | ERROR_LOG(HLE, "Unimplemented SysCall function %s(..)", info->name.c_str()); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | /// Returns the coprocessor (in this case, syscore) command buffer pointer | ||
| 84 | Addr CallGetThreadCommandBuffer() { | ||
| 85 | // Called on insruction: mrc p15, 0, r0, c13, c0, 3 | ||
| 86 | // Returns an address in OSHLE memory for the CPU to read/write to | ||
| 87 | RETURN(CMD_BUFFER_ADDR); | ||
| 88 | return CMD_BUFFER_ADDR; | ||
| 89 | } | ||
| 90 | |||
| 91 | void RegisterModule(std::string name, int num_functions, const FunctionDef* func_table) { | ||
| 92 | ModuleDef module = {name, num_functions, func_table}; | ||
| 93 | g_module_db.push_back(module); | ||
| 94 | } | ||
| 95 | |||
| 96 | void RegisterAllModules() { | ||
| 97 | Syscall::Register(); | ||
| 98 | } | ||
| 99 | |||
| 100 | void Init() { | ||
| 101 | Service::Init(); | ||
| 102 | |||
| 103 | g_command_buffer = new u8[CMD_BUFFER_SIZE]; | ||
| 104 | |||
| 105 | RegisterAllModules(); | ||
| 106 | |||
| 107 | NOTICE_LOG(HLE, "initialized OK"); | ||
| 108 | } | ||
| 109 | |||
| 110 | void Shutdown() { | ||
| 111 | Service::Shutdown(); | ||
| 112 | |||
| 113 | delete g_command_buffer; | ||
| 114 | |||
| 115 | g_module_db.clear(); | ||
| 116 | |||
| 117 | NOTICE_LOG(HLE, "shutdown OK"); | ||
| 118 | } | ||
| 119 | |||
| 120 | } // namespace | ||