diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/hle.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 43 | ||||
| -rw-r--r-- | src/core/hle/service/service.h | 55 |
3 files changed, 49 insertions, 50 deletions
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 1aaeaa9c9..c645d6563 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "core/hle/shared_page.h" | 13 | #include "core/hle/shared_page.h" |
| 14 | #include "core/hle/kernel/thread.h" | 14 | #include "core/hle/kernel/thread.h" |
| 15 | #include "core/hle/service/service.h" | 15 | #include "core/hle/service/service.h" |
| 16 | #include "core/hle/svc.h" | ||
| 16 | 17 | ||
| 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 18 | 19 | ||
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 134ff1740..d50327cb9 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -51,6 +51,49 @@ namespace Service { | |||
| 51 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_kernel_named_ports; | 51 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_kernel_named_ports; |
| 52 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_srv_services; | 52 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_srv_services; |
| 53 | 53 | ||
| 54 | /** | ||
| 55 | * Creates a function string for logging, complete with the name (or header code, depending | ||
| 56 | * on what's passed in) the port name, and all the cmd_buff arguments. | ||
| 57 | */ | ||
| 58 | static std::string MakeFunctionString(const char* name, const char* port_name, const u32* cmd_buff) { | ||
| 59 | // Number of params == bits 0-5 + bits 6-11 | ||
| 60 | int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); | ||
| 61 | |||
| 62 | std::string function_string = Common::StringFromFormat("function '%s': port=%s", name, port_name); | ||
| 63 | for (int i = 1; i <= num_params; ++i) { | ||
| 64 | function_string += Common::StringFromFormat(", cmd_buff[%i]=%u", i, cmd_buff[i]); | ||
| 65 | } | ||
| 66 | return function_string; | ||
| 67 | } | ||
| 68 | |||
| 69 | ResultVal<bool> Interface::SyncRequest() { | ||
| 70 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 71 | auto itr = m_functions.find(cmd_buff[0]); | ||
| 72 | |||
| 73 | if (itr == m_functions.end() || itr->second.func == nullptr) { | ||
| 74 | std::string function_name = (itr == m_functions.end()) ? Common::StringFromFormat("0x%08X", cmd_buff[0]) : itr->second.name; | ||
| 75 | LOG_ERROR(Service, "unknown / unimplemented %s", MakeFunctionString(function_name.c_str(), GetPortName().c_str(), cmd_buff).c_str()); | ||
| 76 | |||
| 77 | // TODO(bunnei): Hack - ignore error | ||
| 78 | cmd_buff[1] = 0; | ||
| 79 | return MakeResult<bool>(false); | ||
| 80 | } else { | ||
| 81 | LOG_TRACE(Service, "%s", MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str()); | ||
| 82 | } | ||
| 83 | |||
| 84 | itr->second.func(this); | ||
| 85 | |||
| 86 | return MakeResult<bool>(false); // TODO: Implement return from actual function | ||
| 87 | } | ||
| 88 | |||
| 89 | void Interface::Register(const FunctionInfo* functions, size_t n) { | ||
| 90 | m_functions.reserve(n); | ||
| 91 | for (size_t i = 0; i < n; ++i) { | ||
| 92 | // Usually this array is sorted by id already, so hint to instead at the end | ||
| 93 | m_functions.emplace_hint(m_functions.cend(), functions[i].id, functions[i]); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 54 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 97 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | // Module interface | 98 | // Module interface |
| 56 | 99 | ||
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index bfe16ebad..21ada67b5 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h | |||
| @@ -4,20 +4,15 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <algorithm> | ||
| 8 | #include <string> | 7 | #include <string> |
| 9 | #include <unordered_map> | 8 | #include <unordered_map> |
| 10 | #include <vector> | ||
| 11 | 9 | ||
| 12 | #include <boost/container/flat_map.hpp> | 10 | #include <boost/container/flat_map.hpp> |
| 13 | 11 | ||
| 14 | #include "common/common.h" | 12 | #include "common/common.h" |
| 15 | #include "common/string_util.h" | ||
| 16 | #include "core/mem_map.h" | ||
| 17 | 13 | ||
| 18 | #include "core/hle/kernel/kernel.h" | 14 | #include "core/hle/kernel/kernel.h" |
| 19 | #include "core/hle/kernel/session.h" | 15 | #include "core/hle/kernel/session.h" |
| 20 | #include "core/hle/svc.h" | ||
| 21 | 16 | ||
| 22 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | // Namespace Service | 18 | // Namespace Service |
| @@ -26,31 +21,11 @@ namespace Service { | |||
| 26 | 21 | ||
| 27 | static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 characters) | 22 | static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 characters) |
| 28 | 23 | ||
| 29 | class Manager; | ||
| 30 | |||
| 31 | /// Interface to a CTROS service | 24 | /// Interface to a CTROS service |
| 32 | class Interface : public Kernel::Session { | 25 | class Interface : public Kernel::Session { |
| 33 | // TODO(yuriks): An "Interface" being a Kernel::Object is mostly non-sense. Interface should be | 26 | // TODO(yuriks): An "Interface" being a Kernel::Object is mostly non-sense. Interface should be |
| 34 | // just something that encapsulates a session and acts as a helper to implement service | 27 | // just something that encapsulates a session and acts as a helper to implement service |
| 35 | // processes. | 28 | // processes. |
| 36 | |||
| 37 | friend class Manager; | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Creates a function string for logging, complete with the name (or header code, depending | ||
| 41 | * on what's passed in) the port name, and all the cmd_buff arguments. | ||
| 42 | */ | ||
| 43 | std::string MakeFunctionString(const char* name, const char* port_name, const u32* cmd_buff) { | ||
| 44 | // Number of params == bits 0-5 + bits 6-11 | ||
| 45 | int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); | ||
| 46 | |||
| 47 | std::string function_string = Common::StringFromFormat("function '%s': port=%s", name, port_name); | ||
| 48 | for (int i = 1; i <= num_params; ++i) { | ||
| 49 | function_string += Common::StringFromFormat(", cmd_buff[%i]=%u", i, cmd_buff[i]); | ||
| 50 | } | ||
| 51 | return function_string; | ||
| 52 | } | ||
| 53 | |||
| 54 | public: | 29 | public: |
| 55 | std::string GetName() const override { return GetPortName(); } | 30 | std::string GetName() const override { return GetPortName(); } |
| 56 | 31 | ||
| @@ -70,25 +45,7 @@ public: | |||
| 70 | return "[UNKNOWN SERVICE PORT]"; | 45 | return "[UNKNOWN SERVICE PORT]"; |
| 71 | } | 46 | } |
| 72 | 47 | ||
| 73 | ResultVal<bool> SyncRequest() override { | 48 | ResultVal<bool> SyncRequest() override; |
| 74 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 75 | auto itr = m_functions.find(cmd_buff[0]); | ||
| 76 | |||
| 77 | if (itr == m_functions.end() || itr->second.func == nullptr) { | ||
| 78 | std::string function_name = (itr == m_functions.end()) ? Common::StringFromFormat("0x%08X", cmd_buff[0]) : itr->second.name; | ||
| 79 | LOG_ERROR(Service, "unknown / unimplemented %s", MakeFunctionString(function_name.c_str(), GetPortName().c_str(), cmd_buff).c_str()); | ||
| 80 | |||
| 81 | // TODO(bunnei): Hack - ignore error | ||
| 82 | cmd_buff[1] = 0; | ||
| 83 | return MakeResult<bool>(false); | ||
| 84 | } else { | ||
| 85 | LOG_TRACE(Service, "%s", MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str()); | ||
| 86 | } | ||
| 87 | |||
| 88 | itr->second.func(this); | ||
| 89 | |||
| 90 | return MakeResult<bool>(false); // TODO: Implement return from actual function | ||
| 91 | } | ||
| 92 | 49 | ||
| 93 | protected: | 50 | protected: |
| 94 | 51 | ||
| @@ -96,14 +53,12 @@ protected: | |||
| 96 | * Registers the functions in the service | 53 | * Registers the functions in the service |
| 97 | */ | 54 | */ |
| 98 | template <size_t N> | 55 | template <size_t N> |
| 99 | void Register(const FunctionInfo (&functions)[N]) { | 56 | inline void Register(const FunctionInfo (&functions)[N]) { |
| 100 | m_functions.reserve(N); | 57 | Register(functions, N); |
| 101 | for (auto& fn : functions) { | ||
| 102 | // Usually this array is sorted by id already, so hint to instead at the end | ||
| 103 | m_functions.emplace_hint(m_functions.cend(), fn.id, fn); | ||
| 104 | } | ||
| 105 | } | 58 | } |
| 106 | 59 | ||
| 60 | void Register(const FunctionInfo* functions, size_t n); | ||
| 61 | |||
| 107 | private: | 62 | private: |
| 108 | boost::container::flat_map<u32, FunctionInfo> m_functions; | 63 | boost::container::flat_map<u32, FunctionInfo> m_functions; |
| 109 | 64 | ||