From 95e5436f41a3cffaace7c48be72373bebcaf91e4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 19:55:59 -0400 Subject: cleaned up arm_interface, added a setter to set registers for use with HLE return values --- src/core/arm/interpreter/arm_interpreter.cpp | 39 +++++++++++++++++++++++++--- src/core/arm/interpreter/arm_interpreter.h | 37 ++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 6 deletions(-) (limited to 'src/core/arm') diff --git a/src/core/arm/interpreter/arm_interpreter.cpp b/src/core/arm/interpreter/arm_interpreter.cpp index 81f38f016..4045779d7 100644 --- a/src/core/arm/interpreter/arm_interpreter.cpp +++ b/src/core/arm/interpreter/arm_interpreter.cpp @@ -31,30 +31,61 @@ ARM_Interpreter::ARM_Interpreter() { m_state->Reg[13] = 0x10000000; // Set stack pointer to the top of the stack } +ARM_Interpreter::~ARM_Interpreter() { + delete m_state; +} + +/** + * Set the Program Counter to an address + * @param addr Address to set PC to + */ void ARM_Interpreter::SetPC(u32 pc) { m_state->pc = m_state->Reg[15] = pc; } +/* + * Get the current Program Counter + * @return Returns current PC + */ u32 ARM_Interpreter::GetPC() const { return m_state->pc; } +/** + * Get an ARM register + * @param index Register index (0-15) + * @return Returns the value in the register + */ u32 ARM_Interpreter::GetReg(int index) const { return m_state->Reg[index]; } +/** + * Set an ARM register + * @param index Register index (0-15) + * @param value Value to set register to + */ +void ARM_Interpreter::SetReg(int index, u32 value) { + m_state->Reg[index] = value; +} + +/** + * Get the current CPSR register + * @return Returns the value of the CPSR register + */ u32 ARM_Interpreter::GetCPSR() const { return m_state->Cpsr; } +/** + * Returns the number of clock ticks since the last reset + * @return Returns number of clock ticks + */ u64 ARM_Interpreter::GetTicks() const { return ARMul_Time(m_state); } -ARM_Interpreter::~ARM_Interpreter() { - delete m_state; -} - +/// Execture next instruction void ARM_Interpreter::ExecuteInstruction() { m_state->step++; m_state->cycle++; diff --git a/src/core/arm/interpreter/arm_interpreter.h b/src/core/arm/interpreter/arm_interpreter.h index 932046d9a..f3c86f8dd 100644 --- a/src/core/arm/interpreter/arm_interpreter.h +++ b/src/core/arm/interpreter/arm_interpreter.h @@ -12,22 +12,55 @@ class ARM_Interpreter : virtual public ARM_Interface { public: + ARM_Interpreter(); ~ARM_Interpreter(); - void ExecuteInstruction(); - + /** + * Set the Program Counter to an address + * @param addr Address to set PC to + */ void SetPC(u32 pc); + /* + * Get the current Program Counter + * @return Returns current PC + */ u32 GetPC() const; + /** + * Get an ARM register + * @param index Register index (0-15) + * @return Returns the value in the register + */ u32 GetReg(int index) const; + /** + * Set an ARM register + * @param index Register index (0-15) + * @param value Value to set register to + */ + void SetReg(int index, u32 value); + + /** + * Get the current CPSR register + * @return Returns the value of the CPSR register + */ u32 GetCPSR() const; + /** + * Returns the number of clock ticks since the last reset + * @return Returns number of clock ticks + */ u64 GetTicks() const; +protected: + + /// Execture next instruction + void ExecuteInstruction(); + private: + ARMul_State* m_state; DISALLOW_COPY_AND_ASSIGN(ARM_Interpreter); -- cgit v1.2.3 From fccbfc208c53ef6c3424531d8f4a42d3d23b200a Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 19:57:56 -0400 Subject: missed this file with commit 95e5436f --- src/core/arm/arm_interface.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/core/arm') diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index dafde8368..eee4726db 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -42,6 +42,13 @@ public: */ virtual u32 GetReg(int index) const = 0; + /** + * Set an ARM register + * @param index Register index (0-15) + * @param value Value to set register to + */ + virtual void SetReg(int index, u32 value) = 0; + /** * Get the current CPSR register * @return Returns the value of the CPSR register @@ -59,11 +66,13 @@ public: return m_num_instructions; } -private: +protected: /// Execture next instruction virtual void ExecuteInstruction() = 0; +private: + u64 m_num_instructions; ///< Number of instructions executed DISALLOW_COPY_AND_ASSIGN(ARM_Interface); -- cgit v1.2.3 From 2bde8f28561ea9436d13d990f6b129a0e80a325e Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 10 Apr 2014 23:26:12 -0400 Subject: base code to call a syscall from ARM11 appcore --- src/core/arm/interpreter/armemu.cpp | 3 ++ src/core/hle.cpp | 28 +++++++++++++++++-- src/core/hle/hle.h | 6 ++-- src/core/hle/hle_syscall.cpp | 55 ++++++++++++++++++++++++++++++++++--- src/core/hle/hle_syscall.h | 2 +- 5 files changed, 85 insertions(+), 9 deletions(-) (limited to 'src/core/arm') diff --git a/src/core/arm/interpreter/armemu.cpp b/src/core/arm/interpreter/armemu.cpp index 46c51fbe8..6074ff480 100644 --- a/src/core/arm/interpreter/armemu.cpp +++ b/src/core/arm/interpreter/armemu.cpp @@ -16,6 +16,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "core/hle/hle.h" + #include "arm_regformat.h" #include "armdefs.h" #include "armemu.h" @@ -4558,6 +4560,7 @@ ARMul_Emulate26 (ARMul_State * state) // ARMul_OSHandleSWI (state, BITS (0, 23)); // break; //} + HLE::CallSyscall(instr); ARMul_Abort (state, ARMul_SWIV); break; } diff --git a/src/core/hle.cpp b/src/core/hle.cpp index 8dad7695b..d62d2d0ce 100644 --- a/src/core/hle.cpp +++ b/src/core/hle.cpp @@ -13,21 +13,45 @@ namespace HLE { static std::vector g_module_db; +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 HLE function %s", info->name); + } +} + 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() { - Register_SysCall(); + Register_Syscall(); } void Init() { RegisterAllModules(); + NOTICE_LOG(HLE, "initialized OK"); } void Shutdown() { - g_module_db.clear(); + g_module_db.clear(); + NOTICE_LOG(HLE, "shutdown OK"); } } // namespace diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 35c8a4621..e3b8d483a 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -30,10 +30,12 @@ struct ModuleDef { const FunctionDef* func_table; }; +void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); + +void CallSyscall(u32 opcode); + void Init(); void Shutdown(); -void RegisterModule(std::string name, int num_functions, const FunctionDef *func_table); - } // namespace diff --git a/src/core/hle/hle_syscall.cpp b/src/core/hle/hle_syscall.cpp index fdcaa914f..53d721275 100644 --- a/src/core/hle/hle_syscall.cpp +++ b/src/core/hle/hle_syscall.cpp @@ -10,15 +10,62 @@ typedef u32 Handle; typedef s32 Result; +//////////////////////////////////////////////////////////////////////////////////////////////////// + Result SVC_ConnectToPort(void* out, const char* port_name) { NOTICE_LOG(OSHLE, "svcConnectToPort called, port_name: %s", port_name); return 0; } -const HLE::FunctionDef SysCall_Table[] = { - {0x2D, WrapI_VC, "svcConnectToPort"}, +const HLE::FunctionDef Syscall_Table[] = { + {0x00, NULL, "Unknown"}, + {0x01, NULL, "svcControlMemory"}, + {0x02, NULL, "svcQueryMemory"}, + {0x03, NULL, "svcExitProcess"}, + {0x04, NULL, "svcGetProcessAffinityMask"}, + {0x05, NULL, "svcSetProcessAffinityMask"}, + {0x06, NULL, "svcGetProcessIdealProcessor"}, + {0x07, NULL, "svcSetProcessIdealProcessor"}, + {0x08, NULL, "svcCreateThread"}, + {0x09, NULL, "svcExitThread"}, + {0x0A, NULL, "svcSleepThread"}, + {0x0B, NULL, "svcGetThreadPriority"}, + {0x0C, NULL, "svcSetThreadPriority"}, + {0x0D, NULL, "svcGetThreadAffinityMask"}, + {0x0E, NULL, "svcSetThreadAffinityMask"}, + {0x0F, NULL, "svcGetThreadIdealProcessor"}, + {0x10, NULL, "svcSetThreadIdealProcessor"}, + {0x11, NULL, "svcGetCurrentProcessorNumber"}, + {0x12, NULL, "svcRun"}, + {0x13, NULL, "svcCreateMutex"}, + {0x14, NULL, "svcReleaseMutex"}, + {0x15, NULL, "svcCreateSemaphore"}, + {0x16, NULL, "svcReleaseSemaphore"}, + {0x17, NULL, "svcCreateEvent"}, + {0x18, NULL, "svcSignalEvent"}, + {0x19, NULL, "svcClearEvent"}, + {0x1A, NULL, "svcCreateTimer"}, + {0x1B, NULL, "svcSetTimer"}, + {0x1C, NULL, "svcCancelTimer"}, + {0x1D, NULL, "svcClearTimer"}, + {0x1E, NULL, "svcCreateMemoryBlock"}, + {0x1F, NULL, "svcMapMemoryBlock"}, + {0x20, NULL, "svcUnmapMemoryBlock"}, + {0x21, NULL, "svcCreateAddressArbiter"}, + {0x22, NULL, "svcArbitrateAddress"}, + {0x23, NULL, "svcCloseHandle"}, + {0x24, NULL, "svcWaitSynchronization1"}, + {0x25, NULL, "svcWaitSynchronizationN"}, + {0x26, NULL, "svcSignalAndWait"}, + {0x27, NULL, "svcDuplicateHandle"}, + {0x28, NULL, "svcGetSystemTick"}, + {0x29, NULL, "svcGetHandleInfo"}, + {0x2A, NULL, "svcGetSystemInfo"}, + {0x2B, NULL, "svcGetProcessInfo"}, + {0x2C, NULL, "svcGetThreadInfo"}, + {0x2D, WrapI_VC, "svcConnectToPort"}, }; -void Register_SysCall() { - HLE::RegisterModule("SysCallTable", ARRAY_SIZE(SysCall_Table), SysCall_Table); +void Register_Syscall() { + HLE::RegisterModule("SyscallTable", ARRAY_SIZE(Syscall_Table), Syscall_Table); } diff --git a/src/core/hle/hle_syscall.h b/src/core/hle/hle_syscall.h index 4faa14535..80b20c358 100644 --- a/src/core/hle/hle_syscall.h +++ b/src/core/hle/hle_syscall.h @@ -34,4 +34,4 @@ // } //}; -void Register_SysCall(); +void Register_Syscall(); -- cgit v1.2.3 From cd7de52fea8359da3c37f661b0da0c145b9b3f7e Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 01:35:45 -0400 Subject: added a SETABORT method that does not update LR (for HLE'd SVC that does not jump appcore CPU to an IRQ vector) --- src/core/arm/interpreter/armemu.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/core/arm') diff --git a/src/core/arm/interpreter/armemu.h b/src/core/arm/interpreter/armemu.h index 7391dea7f..7c118948a 100644 --- a/src/core/arm/interpreter/armemu.h +++ b/src/core/arm/interpreter/armemu.h @@ -229,6 +229,17 @@ extern ARMword isize; } \ while (0) +#define SETABORT_SKIPBRANCH(i, m, d) \ + do \ + { \ + int SETABORT_mode = (m); \ + \ + ARMul_SetSPSR (state, SETABORT_mode, ARMul_GetCPSR (state)); \ + ARMul_SetCPSR (state, ((ARMul_GetCPSR (state) & ~(EMODE | TBIT)) \ + | (i) | SETABORT_mode)); \ + } \ + while (0) + //#ifndef MODE32 #define VECTORS 0x20 #define LEGALADDR 0x03ffffff -- cgit v1.2.3 From 4d8831890321c11e2e29ed9bc87c8a48841b702e Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 01:36:39 -0400 Subject: hacked CPU interpreter to ignore branch on SVC instruction (as we are HLEing this...) --- src/core/arm/interpreter/arminit.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/core/arm') diff --git a/src/core/arm/interpreter/arminit.cpp b/src/core/arm/interpreter/arminit.cpp index cdbd02f3c..a8aeecdea 100644 --- a/src/core/arm/interpreter/arminit.cpp +++ b/src/core/arm/interpreter/arminit.cpp @@ -530,9 +530,13 @@ ARMul_Abort (ARMul_State * state, ARMword vector) isize); break; case ARMul_SWIV: /* Software Interrupt */ - SETABORT (IBIT, state->prog32Sig ? SVC32MODE : SVC26MODE, + // Modified SETABORT that doesn't branch to a SVC vector as we are implementing this in HLE + // Instead of doing normal routine, backup R15 by one instruction (this is what PC will get + // set to, making it the next instruction after the SVC call), and skip setting the LR. + SETABORT_SKIPBRANCH (IBIT, state->prog32Sig ? SVC32MODE : SVC26MODE, isize); - break; + state->Reg[15] -= 4; + return; case ARMul_PrefetchAbortV: /* Prefetch Abort */ state->AbortAddr = 1; SETABORT (IBIT, state->prog32Sig ? ABORT32MODE : SVC26MODE, -- cgit v1.2.3 From 68e198476f17a026fed88f3c9a271aa768694354 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 21:55:36 -0400 Subject: - added HLE to connect to "srv:" service - added a manager for keeping track of services/ports - added a memory mapped region for memory accessed by HLE - added HLE for GetThreadCommandBuffer function --- src/core/arm/interpreter/armsupp.cpp | 68 ++++----- src/core/core.vcxproj | 1 + src/core/core.vcxproj.filters | 3 + src/core/hle/hle.cpp | 13 ++ src/core/hle/hle.h | 7 + src/core/hle/service/service.cpp | 115 +++++++++++++++ src/core/hle/service/service.h | 57 +++++++- src/core/hle/syscall.cpp | 266 ++++++++++++++++++----------------- src/core/mem_map.cpp | 3 +- src/core/mem_map.h | 3 +- src/core/mem_map_funcs.cpp | 18 ++- 11 files changed, 386 insertions(+), 168 deletions(-) create mode 100644 src/core/hle/service/service.cpp (limited to 'src/core/arm') diff --git a/src/core/arm/interpreter/armsupp.cpp b/src/core/arm/interpreter/armsupp.cpp index a0c866c15..101b9807a 100644 --- a/src/core/arm/interpreter/armsupp.cpp +++ b/src/core/arm/interpreter/armsupp.cpp @@ -19,6 +19,8 @@ #include "armemu.h" //#include "ansidecl.h" #include "skyeye_defs.h" +#include "core/hle/hle.h" + unsigned xscale_cp15_cp_access_allowed (ARMul_State * state, unsigned reg, unsigned cpnum); //extern int skyeye_instr_debug; @@ -734,39 +736,39 @@ ARMword ARMul_MRC (ARMul_State * state, ARMword instr) { unsigned cpab; - ARMword result = 0; - - //printf("SKYEYE ARMul_MRC, CPnum is %x, instr %x\n",CPNum, instr); - if (!CP_ACCESS_ALLOWED (state, CPNum)) { - //chy 2004-07-19 should fix in the future????!!!! - //printf("SKYEYE ARMul_MRC,NOT ALLOWed UndefInstr CPnum is %x, instr %x\n",CPNum, instr); - ARMul_UndefInstr (state, instr); - return -1; - } - - cpab = (state->MRC[CPNum]) (state, ARMul_FIRST, instr, &result); - while (cpab == ARMul_BUSY) { - ARMul_Icycles (state, 1, 0); - if (IntPending (state)) { - cpab = (state->MRC[CPNum]) (state, ARMul_INTERRUPT, - instr, 0); - return (0); - } - else - cpab = (state->MRC[CPNum]) (state, ARMul_BUSY, instr, - &result); - } - if (cpab == ARMul_CANT) { - printf ("SKYEYE ARMul_MRC,CANT UndefInstr CPnum is %x, instr %x\n", CPNum, instr); - ARMul_Abort (state, ARMul_UndefinedInstrV); - /* Parent will destroy the flags otherwise. */ - result = ECC; - } - else { - BUSUSEDINCPCN; - ARMul_Ccycles (state, 1, 0); - ARMul_Icycles (state, 1, 0); - } + ARMword result = HLE::CallGetThreadCommandBuffer(); + + ////printf("SKYEYE ARMul_MRC, CPnum is %x, instr %x\n",CPNum, instr); + //if (!CP_ACCESS_ALLOWED (state, CPNum)) { + // //chy 2004-07-19 should fix in the future????!!!! + // //printf("SKYEYE ARMul_MRC,NOT ALLOWed UndefInstr CPnum is %x, instr %x\n",CPNum, instr); + // ARMul_UndefInstr (state, instr); + // return -1; + //} + + //cpab = (state->MRC[CPNum]) (state, ARMul_FIRST, instr, &result); + //while (cpab == ARMul_BUSY) { + // ARMul_Icycles (state, 1, 0); + // if (IntPending (state)) { + // cpab = (state->MRC[CPNum]) (state, ARMul_INTERRUPT, + // instr, 0); + // return (0); + // } + // else + // cpab = (state->MRC[CPNum]) (state, ARMul_BUSY, instr, + // &result); + //} + //if (cpab == ARMul_CANT) { + // printf ("SKYEYE ARMul_MRC,CANT UndefInstr CPnum is %x, instr %x\n", CPNum, instr); + // ARMul_Abort (state, ARMul_UndefinedInstrV); + // /* Parent will destroy the flags otherwise. */ + // result = ECC; + //} + //else { + // BUSUSEDINCPCN; + // ARMul_Ccycles (state, 1, 0); + // ARMul_Icycles (state, 1, 0); + //} return result; } diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 10ecca596..b10ae8684 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -153,6 +153,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index d450224a4..4844e78b8 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -87,6 +87,9 @@ hle + + hle\service + diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 32aff0eb5..3d2c53954 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -4,8 +4,10 @@ #include +#include "core/mem_map.h" #include "core/hle/hle.h" #include "core/hle/syscall.h" +#include "core/hle/service/service.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -35,6 +37,14 @@ void CallSyscall(u32 opcode) { } } +/// 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(OS_THREAD_COMMAND_BUFFER_ADDR); + return OS_THREAD_COMMAND_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); @@ -45,7 +55,10 @@ void RegisterAllModules() { } void Init() { + Service::Init(); + RegisterAllModules(); + NOTICE_LOG(HLE, "initialized OK"); } diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h index 9466be540..2bd1f99a2 100644 --- a/src/core/hle/hle.h +++ b/src/core/hle/hle.h @@ -16,6 +16,11 @@ namespace HLE { +enum { + OS_THREAD_COMMAND_BUFFER_ADDR = 0xA0004000, +}; + +typedef u32 Addr; typedef void (*Func)(); struct FunctionDef { @@ -34,6 +39,8 @@ void RegisterModule(std::string name, int num_functions, const FunctionDef *func void CallSyscall(u32 opcode); +Addr CallGetThreadCommandBuffer(); + void Init(); void Shutdown(); diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp new file mode 100644 index 000000000..4bc96cc18 --- /dev/null +++ b/src/core/hle/service/service.cpp @@ -0,0 +1,115 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "common/common.h" +#include "common/log.h" + +#include "core/hle/service/service.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Namespace Service + +namespace Service { + +Manager* g_manager = NULL; ///< Service manager + +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); +} + +class Interface_SRV : public Interface { +public: + + Interface_SRV() { + } + + ~Interface_SRV() { + } + + /** + * Gets the string name used by CTROS for a service + * @return String name of service + */ + std::string GetName() { + return "ServiceManager"; + } + + /** + * Gets the string name used by CTROS for a service + * @return Port name of service + */ + std::string GetPortName() { + 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() { + ERROR_LOG(HLE, "Unimplemented function ServiceManager::Sync"); + return -1; + } + +}; + +/// Initialize ServiceManager +void Init() { + g_manager = new Manager; + g_manager->AddService(new Interface_SRV); + NOTICE_LOG(HLE, "ServiceManager initialized OK"); +} + +/// Shutdown ServiceManager +void Shutdown() { + delete g_manager; + NOTICE_LOG(HLE, "ServiceManager shutdown OK"); +} + + +} diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index f15099982..3fd855dee 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -4,6 +4,8 @@ #pragma once +#include +#include #include #include "common/common_types.h" @@ -14,10 +16,13 @@ namespace Service { -typedef s32 NativeUID; +typedef s32 NativeUID; ///< Native handle for a service + +class Manager; /// Interface to a CTROS service class Interface { + friend class Manager; public: virtual ~Interface() { @@ -43,7 +48,7 @@ public: * Gets the string name used by CTROS for a service * @return Port name of service */ - virtual std::string GetPort() { + virtual std::string GetPortName() { return "[UNKNOWN SERVICE PORT]"; } @@ -57,4 +62,52 @@ private: u32 m_uid; }; +/// 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 m_services; + std::map 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/syscall.cpp b/src/core/hle/syscall.cpp index 98155dc8e..8225f168b 100644 --- a/src/core/hle/syscall.cpp +++ b/src/core/hle/syscall.cpp @@ -6,144 +6,154 @@ #include "core/hle/function_wrappers.h" #include "core/hle/syscall.h" +#include "core/hle/service/service.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Namespace Syscall namespace Syscall { -Result SVC_ConnectToPort(void* out, const char* port_name) { - NOTICE_LOG(OSHLE, "svcConnectToPort called, port_name: %s", port_name); +/// 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; } const HLE::FunctionDef Syscall_Table[] = { - {0x00, NULL, "Unknown"}, - {0x01, NULL, "svcControlMemory"}, - {0x02, NULL, "svcQueryMemory"}, - {0x03, NULL, "svcExitProcess"}, - {0x04, NULL, "svcGetProcessAffinityMask"}, - {0x05, NULL, "svcSetProcessAffinityMask"}, - {0x06, NULL, "svcGetProcessIdealProcessor"}, - {0x07, NULL, "svcSetProcessIdealProcessor"}, - {0x08, NULL, "svcCreateThread"}, - {0x09, NULL, "svcExitThread"}, - {0x0A, NULL, "svcSleepThread"}, - {0x0B, NULL, "svcGetThreadPriority"}, - {0x0C, NULL, "svcSetThreadPriority"}, - {0x0D, NULL, "svcGetThreadAffinityMask"}, - {0x0E, NULL, "svcSetThreadAffinityMask"}, - {0x0F, NULL, "svcGetThreadIdealProcessor"}, - {0x10, NULL, "svcSetThreadIdealProcessor"}, - {0x11, NULL, "svcGetCurrentProcessorNumber"}, - {0x12, NULL, "svcRun"}, - {0x13, NULL, "svcCreateMutex"}, - {0x14, NULL, "svcReleaseMutex"}, - {0x15, NULL, "svcCreateSemaphore"}, - {0x16, NULL, "svcReleaseSemaphore"}, - {0x17, NULL, "svcCreateEvent"}, - {0x18, NULL, "svcSignalEvent"}, - {0x19, NULL, "svcClearEvent"}, - {0x1A, NULL, "svcCreateTimer"}, - {0x1B, NULL, "svcSetTimer"}, - {0x1C, NULL, "svcCancelTimer"}, - {0x1D, NULL, "svcClearTimer"}, - {0x1E, NULL, "svcCreateMemoryBlock"}, - {0x1F, NULL, "svcMapMemoryBlock"}, - {0x20, NULL, "svcUnmapMemoryBlock"}, - {0x21, NULL, "svcCreateAddressArbiter"}, - {0x22, NULL, "svcArbitrateAddress"}, - {0x23, NULL, "svcCloseHandle"}, - {0x24, NULL, "svcWaitSynchronization1"}, - {0x25, NULL, "svcWaitSynchronizationN"}, - {0x26, NULL, "svcSignalAndWait"}, - {0x27, NULL, "svcDuplicateHandle"}, - {0x28, NULL, "svcGetSystemTick"}, - {0x29, NULL, "svcGetHandleInfo"}, - {0x2A, NULL, "svcGetSystemInfo"}, - {0x2B, NULL, "svcGetProcessInfo"}, - {0x2C, NULL, "svcGetThreadInfo"}, - {0x2D, WrapI_VC, "svcConnectToPort"}, - {0x2E, NULL, "svcSendSyncRequest1"}, - {0x2F, NULL, "svcSendSyncRequest2"}, - {0x30, NULL, "svcSendSyncRequest3"}, - {0x31, NULL, "svcSendSyncRequest4"}, - {0x32, NULL, "svcSendSyncRequest"}, - {0x33, NULL, "svcOpenProcess"}, - {0x34, NULL, "svcOpenThread"}, - {0x35, NULL, "svcGetProcessId"}, - {0x36, NULL, "svcGetProcessIdOfThread"}, - {0x37, NULL, "svcGetThreadId"}, - {0x38, NULL, "svcGetResourceLimit"}, - {0x39, NULL, "svcGetResourceLimitLimitValues"}, - {0x3A, NULL, "svcGetResourceLimitCurrentValues"}, - {0x3B, NULL, "svcGetThreadContext"}, - {0x3C, NULL, "svcBreak"}, - {0x3D, NULL, "svcOutputDebugString"}, - {0x3E, NULL, "svcControlPerformanceCounter"}, - {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, "svcCreatePort"}, - {0x48, NULL, "svcCreateSessionToPort"}, - {0x49, NULL, "svcCreateSession"}, - {0x4A, NULL, "svcAcceptSession"}, - {0x4B, NULL, "svcReplyAndReceive1"}, - {0x4C, NULL, "svcReplyAndReceive2"}, - {0x4D, NULL, "svcReplyAndReceive3"}, - {0x4E, NULL, "svcReplyAndReceive4"}, - {0x4F, NULL, "svcReplyAndReceive"}, - {0x50, NULL, "svcBindInterrupt"}, - {0x51, NULL, "svcUnbindInterrupt"}, - {0x52, NULL, "svcInvalidateProcessDataCache"}, - {0x53, NULL, "svcStoreProcessDataCache"}, - {0x54, NULL, "svcFlushProcessDataCache"}, - {0x55, NULL, "svcStartInterProcessDma"}, - {0x56, NULL, "svcStopDma"}, - {0x57, NULL, "svcGetDmaState"}, - {0x58, NULL, "svcRestartDma"}, - {0x59, NULL, "Unknown"}, - {0x5A, NULL, "Unknown"}, - {0x5B, NULL, "Unknown"}, - {0x5C, NULL, "Unknown"}, - {0x5D, NULL, "Unknown"}, - {0x5E, NULL, "Unknown"}, - {0x5F, NULL, "Unknown"}, - {0x60, NULL, "svcDebugActiveProcess"}, - {0x61, NULL, "svcBreakDebugProcess"}, - {0x62, NULL, "svcTerminateDebugProcess"}, - {0x63, NULL, "svcGetProcessDebugEvent"}, - {0x64, NULL, "svcContinueDebugEvent"}, - {0x65, NULL, "svcGetProcessList"}, - {0x66, NULL, "svcGetThreadList"}, - {0x67, NULL, "svcGetDebugThreadContext"}, - {0x68, NULL, "svcSetDebugThreadContext"}, - {0x69, NULL, "svcQueryDebugProcessMemory"}, - {0x6A, NULL, "svcReadProcessMemory"}, - {0x6B, NULL, "svcWriteProcessMemory"}, - {0x6C, NULL, "svcSetHardwareBreakPoint"}, - {0x6D, NULL, "svcGetDebugThreadParam"}, - {0x6E, NULL, "Unknown"}, - {0x6F, NULL, "Unknown"}, - {0x70, NULL, "svcControlProcessMemory"}, - {0x71, NULL, "svcMapProcessMemory"}, - {0x72, NULL, "svcUnmapProcessMemory"}, - {0x73, NULL, "Unknown"}, - {0x74, NULL, "Unknown"}, - {0x75, NULL, "Unknown"}, - {0x76, NULL, "svcTerminateProcess"}, - {0x77, NULL, "Unknown"}, - {0x78, NULL, "svcCreateResourceLimit"}, - {0x79, NULL, "Unknown"}, - {0x7A, NULL, "Unknown"}, - {0x7B, NULL, "Unknown"}, - {0x7C, NULL, "svcKernelSetState"}, - {0x7D, NULL, "svcQueryProcessMemory"}, + {0x00, NULL, "Unknown"}, + {0x01, NULL, "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, NULL, "CloseHandle"}, + {0x24, NULL, "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"}, + {0x2E, NULL, "SendSyncRequest1"}, + {0x2F, NULL, "SendSyncRequest2"}, + {0x30, NULL, "SendSyncRequest3"}, + {0x31, NULL, "SendSyncRequest4"}, + {0x32, WrapI_U, "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() { diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index a5865d785..5b5c57fca 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project + // Copyright 2014 Citra Emulator Project // Licensed under GPLv2 // Refer to the license.txt file included. @@ -12,7 +12,6 @@ namespace Memory { - u8* g_base = NULL; ///< The base pointer to the auto-mirrored arena. MemArena g_arena; ///< The MemArena class diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 29f2dce86..2596ba925 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h @@ -33,8 +33,9 @@ enum { MEM_VRAM_VADDR = 0x1F000000, MEM_SCRATCHPAD_VADDR = (0x10000000 - MEM_SCRATCHPAD_SIZE), ///< Scratchpad virtual address - MEM_OSHLE_VADDR = 0xC0000000, ///< Memory for use by OSHLE accessible by appcore CPU MEM_OSHLE_SIZE = 0x08000000, ///< ...Same size as FCRAM for now + MEM_OSHLE_VADDR = 0xA0000000, ///< Memory for use by OSHLE accessible by appcore CPU + MEM_OSHLE_VADDR_END = (MEM_OSHLE_VADDR + MEM_OSHLE_SIZE), }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp index 00719445f..f35e25caf 100644 --- a/src/core/mem_map_funcs.cpp +++ b/src/core/mem_map_funcs.cpp @@ -6,6 +6,7 @@ #include "core/mem_map.h" #include "core/hw/hw.h" +#include "hle/hle.h" namespace Memory { @@ -15,9 +16,16 @@ inline void _Read(T &var, const u32 addr) { // TODO: Make sure this represents the mirrors in a correct way. // Could just do a base-relative read, too.... TODO + + // Memory allocated for HLE use that can be addressed from the emulated application + // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE + // core running the user application (appcore) + if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { + NOTICE_LOG(MEMMAP, "OSHLE read @ 0x%08X", addr); + // Hardware I/O register reads // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { HW::Read(var, addr); // FCRAM virtual address reads @@ -47,9 +55,15 @@ inline void _Read(T &var, const u32 addr) { template inline void _Write(u32 addr, const T data) { + // Memory allocated for HLE use that can be addressed from the emulated application + // The primary use of this is sharing a commandbuffer between the HLE OS (syscore) and the LLE + // core running the user application (appcore) + if (addr >= MEM_OSHLE_VADDR && addr < MEM_OSHLE_VADDR_END) { + NOTICE_LOG(MEMMAP, "OSHLE write @ 0x%08X", addr); + // Hardware I/O register writes // 0x10XXXXXX- is physical address space, 0x1EXXXXXX is virtual address space - if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { + } else if ((addr & 0xFF000000) == 0x10000000 || (addr & 0xFF000000) == 0x1E000000) { HW::Write(addr, data); // ExeFS:/.code is loaded here: -- cgit v1.2.3