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/hle/service/service.cpp | 115 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/core/hle/service/service.cpp (limited to 'src/core/hle/service/service.cpp') 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"); +} + + +} -- cgit v1.2.3 From b24e6f2b609e1a75f05124a6246801dd0e56183a Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 12 Apr 2014 22:08:48 -0400 Subject: cleanups to service HLE --- src/core/hle/service/service.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 4bc96cc18..3434b6dbf 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -75,7 +75,7 @@ public: * Gets the string name used by CTROS for a service * @return String name of service */ - std::string GetName() { + std::string GetName() const { return "ServiceManager"; } @@ -83,7 +83,7 @@ public: * Gets the string name used by CTROS for a service * @return Port name of service */ - std::string GetPortName() { + std::string GetPortName() const { return "srv:"; } @@ -92,8 +92,8 @@ public: * @return Return result of svcSendSyncRequest passed back to user app */ Syscall::Result Sync() { - ERROR_LOG(HLE, "Unimplemented function ServiceManager::Sync"); - return -1; + ERROR_LOG(HLE, "Unimplemented function Interface_SRV::Sync"); + return 0; } }; @@ -102,13 +102,13 @@ public: void Init() { g_manager = new Manager; g_manager->AddService(new Interface_SRV); - NOTICE_LOG(HLE, "ServiceManager initialized OK"); + NOTICE_LOG(HLE, "Services initialized OK"); } /// Shutdown ServiceManager void Shutdown() { delete g_manager; - NOTICE_LOG(HLE, "ServiceManager shutdown OK"); + NOTICE_LOG(HLE, "Services shutdown OK"); } -- cgit v1.2.3 From 5ea4679630d6776837114252476dd445f377322d Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 00:38:48 -0400 Subject: added some very initial command parsing for SRV Sync --- src/core/hle/service/service.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 3434b6dbf..556dfc8a2 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -5,15 +5,16 @@ #include "common/common.h" #include "common/log.h" +#include "core/hle/hle.h" #include "core/hle/service/service.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Namespace Service - namespace Service { Manager* g_manager = NULL; ///< Service manager +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Service Manager class + Manager::Manager() { } @@ -62,7 +63,11 @@ Interface* Manager::FetchFromPortName(std::string port_name) { return FetchFromUID(itr->second); } +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Interface to "SRV" service + class Interface_SRV : public Interface { + public: Interface_SRV() { @@ -71,6 +76,12 @@ public: ~Interface_SRV() { } + enum { + CMD_OFFSET = 0x80, + CMD_HEADER_INIT = 0x10002, ///< Command header to initialize SRV service + CMD_HEADER_GET_HANDLE = 0x50100, ///< Command header to get handle of other services + }; + /** * Gets the string name used by CTROS for a service * @return String name of service @@ -92,12 +103,27 @@ public: * @return Return result of svcSendSyncRequest passed back to user app */ Syscall::Result Sync() { - ERROR_LOG(HLE, "Unimplemented function Interface_SRV::Sync"); + u32 header = 0; + HLE::Read(header, (HLE::CMD_BUFFER_ADDR + CMD_OFFSET)); + + switch (header) { + case CMD_HEADER_INIT: + NOTICE_LOG(HLE, "Interface_SRV::Sync - Initialize"); + break; + + case CMD_HEADER_GET_HANDLE: + NOTICE_LOG(HLE, "Interface_SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); + break; + } + return 0; } - + }; +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Module interface + /// Initialize ServiceManager void Init() { g_manager = new Manager; -- cgit v1.2.3 From 524e78ece8139ad1adf4c6cf08ff1f705e7af823 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 01:22:05 -0400 Subject: renamed class Interface_SRV to SRV --- src/core/hle/service/service.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 556dfc8a2..b0b2b7b35 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -66,14 +66,14 @@ Interface* Manager::FetchFromPortName(std::string port_name) { //////////////////////////////////////////////////////////////////////////////////////////////////// // Interface to "SRV" service -class Interface_SRV : public Interface { +class SRV : public Interface { public: - Interface_SRV() { + SRV() { } - ~Interface_SRV() { + ~SRV() { } enum { @@ -108,11 +108,11 @@ public: switch (header) { case CMD_HEADER_INIT: - NOTICE_LOG(HLE, "Interface_SRV::Sync - Initialize"); + NOTICE_LOG(HLE, "SRV::Sync - Initialize"); break; case CMD_HEADER_GET_HANDLE: - NOTICE_LOG(HLE, "Interface_SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); + NOTICE_LOG(HLE, "SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); break; } @@ -127,7 +127,7 @@ public: /// Initialize ServiceManager void Init() { g_manager = new Manager; - g_manager->AddService(new Interface_SRV); + g_manager->AddService(new SRV); NOTICE_LOG(HLE, "Services initialized OK"); } -- cgit v1.2.3 From 9f4d677cdf1fcc937d2e68cae3f52f53c24582f8 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 16:33:45 -0400 Subject: added framework for APT service (application and title launching service) --- src/core/hle/service/service.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index b0b2b7b35..b2470d814 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -7,6 +7,7 @@ #include "core/hle/hle.h" #include "core/hle/service/service.h" +#include "core/hle/service/apt.h" namespace Service { @@ -104,19 +105,36 @@ public: */ Syscall::Result Sync() { u32 header = 0; - HLE::Read(header, (HLE::CMD_BUFFER_ADDR + CMD_OFFSET)); + Syscall::Result res = 0; + + u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); + + switch (cmd_buff[0]) { - switch (header) { case CMD_HEADER_INIT: - NOTICE_LOG(HLE, "SRV::Sync - Initialize"); + NOTICE_LOG(OSHLE, "SRV::Sync - Initialize"); break; case CMD_HEADER_GET_HANDLE: - NOTICE_LOG(HLE, "SRV::Sync - GetHandle, port: %s", HLE::GetCharPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET + 4)); + const char* port_name = (const char*)&cmd_buff[1]; + Interface* service = g_manager->FetchFromPortName(port_name); + + NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name, + service->GetUID()); + + if (NULL != service) { + cmd_buff[3] = service->GetUID(); + } else { + ERROR_LOG(OSHLE, "Service %s does not exist", port_name); + res = -1; + } + break; } - return 0; + cmd_buff[1] = res; + + return res; } }; @@ -128,6 +146,7 @@ public: void Init() { g_manager = new Manager; g_manager->AddService(new SRV); + g_manager->AddService(new APT); NOTICE_LOG(HLE, "Services initialized OK"); } -- cgit v1.2.3 From 18766b9e69bf822764eba98237325d07b3c4ef0f Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 13 Apr 2014 22:59:16 -0400 Subject: added a stub for GetLockHandle --- src/core/hle/service/service.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index b2470d814..44c7c8627 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -104,9 +104,7 @@ public: * @return Return result of svcSendSyncRequest passed back to user app */ Syscall::Result Sync() { - u32 header = 0; Syscall::Result res = 0; - u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); switch (cmd_buff[0]) { @@ -116,6 +114,7 @@ public: break; case CMD_HEADER_GET_HANDLE: + { const char* port_name = (const char*)&cmd_buff[1]; Interface* service = g_manager->FetchFromPortName(port_name); @@ -128,7 +127,12 @@ public: ERROR_LOG(OSHLE, "Service %s does not exist", port_name); res = -1; } - + break; + } + + default: + ERROR_LOG(OSHLE, "SRV::Sync - Unknown command 0x%08X", cmd_buff[0]); + res = -1; break; } -- cgit v1.2.3 From 7ec5950bc4c8e4a786df1f4c3392d7b5332d1613 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 15 Apr 2014 22:40:19 -0400 Subject: - extracted srv: calls from service.cpp and put in its own module - added function tables for service calls - lots of refactoring --- src/core/hle/service/service.cpp | 84 ++-------------------------------------- 1 file changed, 4 insertions(+), 80 deletions(-) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 44c7c8627..799dbe90e 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -4,10 +4,12 @@ #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/srv.h" namespace Service { @@ -64,84 +66,6 @@ Interface* Manager::FetchFromPortName(std::string port_name) { return FetchFromUID(itr->second); } -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Interface to "SRV" service - -class SRV : public Interface { - -public: - - SRV() { - } - - ~SRV() { - } - - enum { - CMD_OFFSET = 0x80, - CMD_HEADER_INIT = 0x10002, ///< Command header to initialize SRV service - CMD_HEADER_GET_HANDLE = 0x50100, ///< Command header to get handle of other services - }; - - /** - * Gets the string name used by CTROS for a service - * @return String name of service - */ - std::string GetName() const { - return "ServiceManager"; - } - - /** - * Gets the string name used by CTROS for a 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() { - Syscall::Result res = 0; - u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + CMD_OFFSET); - - switch (cmd_buff[0]) { - - case CMD_HEADER_INIT: - NOTICE_LOG(OSHLE, "SRV::Sync - Initialize"); - break; - - case CMD_HEADER_GET_HANDLE: - { - const char* port_name = (const char*)&cmd_buff[1]; - Interface* service = g_manager->FetchFromPortName(port_name); - - NOTICE_LOG(OSHLE, "SRV::Sync - GetHandle - port: %s, handle: 0x%08X", port_name, - service->GetUID()); - - if (NULL != service) { - cmd_buff[3] = service->GetUID(); - } else { - ERROR_LOG(OSHLE, "Service %s does not exist", port_name); - res = -1; - } - break; - } - - default: - ERROR_LOG(OSHLE, "SRV::Sync - Unknown command 0x%08X", cmd_buff[0]); - res = -1; - break; - } - - cmd_buff[1] = res; - - return res; - } - -}; //////////////////////////////////////////////////////////////////////////////////////////////////// // Module interface @@ -149,8 +73,8 @@ public: /// Initialize ServiceManager void Init() { g_manager = new Manager; - g_manager->AddService(new SRV); - g_manager->AddService(new APT); + g_manager->AddService(new SRV::Interface); + g_manager->AddService(new APT_U); NOTICE_LOG(HLE, "Services initialized OK"); } -- cgit v1.2.3 From 386dd722e7a2463eadefd3b1fd82681e8edcb5b7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 15 Apr 2014 22:42:35 -0400 Subject: fixed naming for APT_U --- src/core/hle/service/service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 799dbe90e..81a34ed06 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -74,7 +74,7 @@ Interface* Manager::FetchFromPortName(std::string port_name) { void Init() { g_manager = new Manager; g_manager->AddService(new SRV::Interface); - g_manager->AddService(new APT_U); + g_manager->AddService(new APT_U::Interface); NOTICE_LOG(HLE, "Services initialized OK"); } -- cgit v1.2.3 From 32c3462047d814eada8f3b80ee5ea2cd03936ae0 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 00:03:41 -0400 Subject: - added stubbed out GSP::Gpu service interface - various cleanups/refactors to HLE services --- src/core/hle/service/service.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 81a34ed06..f612ff830 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -9,6 +9,7 @@ #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/srv.h" namespace Service { @@ -73,8 +74,11 @@ Interface* Manager::FetchFromPortName(std::string port_name) { /// 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); + NOTICE_LOG(HLE, "Services initialized OK"); } -- cgit v1.2.3 From bb5bc2df257330561c886ed768ce2191e2641a6c Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 16 Apr 2014 20:58:36 -0400 Subject: added class stub for HID:User service --- src/core/hle/service/service.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/hle/service/service.cpp') diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index f612ff830..e6605a398 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -10,6 +10,7 @@ #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 { @@ -78,6 +79,7 @@ void Init() { 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"); } -- cgit v1.2.3