|
@@ -8,17 +8,20 @@
|
|
|
#include "common/logging/log.h"
|
|
#include "common/logging/log.h"
|
|
|
#include "common/string_util.h"
|
|
#include "common/string_util.h"
|
|
|
#include "core/hle/ipc.h"
|
|
#include "core/hle/ipc.h"
|
|
|
|
|
+#include "core/hle/ipc_helpers.h"
|
|
|
#include "core/hle/kernel/client_port.h"
|
|
#include "core/hle/kernel/client_port.h"
|
|
|
#include "core/hle/kernel/process.h"
|
|
#include "core/hle/kernel/process.h"
|
|
|
#include "core/hle/kernel/server_port.h"
|
|
#include "core/hle/kernel/server_port.h"
|
|
|
#include "core/hle/kernel/server_session.h"
|
|
#include "core/hle/kernel/server_session.h"
|
|
|
|
|
+#include "core/hle/kernel/thread.h"
|
|
|
#include "core/hle/kernel/handle_table.h"
|
|
#include "core/hle/kernel/handle_table.h"
|
|
|
#include "core/hle/service/dsp_dsp.h"
|
|
#include "core/hle/service/dsp_dsp.h"
|
|
|
#include "core/hle/service/gsp_gpu.h"
|
|
#include "core/hle/service/gsp_gpu.h"
|
|
|
#include "core/hle/service/hid/hid.h"
|
|
#include "core/hle/service/hid/hid.h"
|
|
|
|
|
+#include "core/hle/service/lm/lm.h"
|
|
|
#include "core/hle/service/service.h"
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
+#include "core/hle/service/sm/controller.h"
|
|
|
#include "core/hle/service/sm/sm.h"
|
|
#include "core/hle/service/sm/sm.h"
|
|
|
-#include "core/hle/service/sm/srv.h"
|
|
|
|
|
|
|
|
|
|
using Kernel::ClientPort;
|
|
using Kernel::ClientPort;
|
|
|
using Kernel::ServerPort;
|
|
using Kernel::ServerPort;
|
|
@@ -46,42 +49,6 @@ static std::string MakeFunctionString(const char* name, const char* port_name,
|
|
|
return function_string;
|
|
return function_string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Interface::Interface(u32 max_sessions) : max_sessions(max_sessions) {}
|
|
|
|
|
-Interface::~Interface() = default;
|
|
|
|
|
-
|
|
|
|
|
-void Interface::HandleSyncRequest(SharedPtr<ServerSession> server_session) {
|
|
|
|
|
- // TODO(Subv): Make use of the server_session in the HLE service handlers to distinguish which
|
|
|
|
|
- // session triggered each command.
|
|
|
|
|
-
|
|
|
|
|
- u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
- auto itr = m_functions.find(cmd_buff[0]);
|
|
|
|
|
-
|
|
|
|
|
- if (itr == m_functions.end() || itr->second.func == nullptr) {
|
|
|
|
|
- std::string function_name = (itr == m_functions.end())
|
|
|
|
|
- ? Common::StringFromFormat("0x%08X", cmd_buff[0])
|
|
|
|
|
- : itr->second.name;
|
|
|
|
|
- LOG_ERROR(
|
|
|
|
|
- Service, "unknown / unimplemented %s",
|
|
|
|
|
- MakeFunctionString(function_name.c_str(), GetPortName().c_str(), cmd_buff).c_str());
|
|
|
|
|
-
|
|
|
|
|
- // TODO(bunnei): Hack - ignore error
|
|
|
|
|
- cmd_buff[1] = 0;
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- LOG_TRACE(Service, "%s",
|
|
|
|
|
- MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str());
|
|
|
|
|
-
|
|
|
|
|
- itr->second.func(this);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void Interface::Register(const FunctionInfo* functions, size_t n) {
|
|
|
|
|
- m_functions.reserve(n);
|
|
|
|
|
- for (size_t i = 0; i < n; ++i) {
|
|
|
|
|
- // Usually this array is sorted by id already, so hint to instead at the end
|
|
|
|
|
- m_functions.emplace_hint(m_functions.cend(), functions[i].id, functions[i]);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
ServiceFrameworkBase::ServiceFrameworkBase(const char* service_name, u32 max_sessions,
|
|
ServiceFrameworkBase::ServiceFrameworkBase(const char* service_name, u32 max_sessions,
|
|
@@ -113,43 +80,66 @@ void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* function
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void ServiceFrameworkBase::ReportUnimplementedFunction(u32* cmd_buf, const FunctionInfoBase* info) {
|
|
|
|
|
- IPC::Header header{cmd_buf[0]};
|
|
|
|
|
- int num_params = header.normal_params_size + header.translate_params_size;
|
|
|
|
|
|
|
+void ServiceFrameworkBase::ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info) {
|
|
|
|
|
+ auto cmd_buf = ctx.CommandBuffer();
|
|
|
std::string function_name = info == nullptr ? fmt::format("{:#08x}", cmd_buf[0]) : info->name;
|
|
std::string function_name = info == nullptr ? fmt::format("{:#08x}", cmd_buf[0]) : info->name;
|
|
|
|
|
|
|
|
fmt::MemoryWriter w;
|
|
fmt::MemoryWriter w;
|
|
|
w.write("function '{}': port='{}' cmd_buf={{[0]={:#x}", function_name, service_name,
|
|
w.write("function '{}': port='{}' cmd_buf={{[0]={:#x}", function_name, service_name,
|
|
|
cmd_buf[0]);
|
|
cmd_buf[0]);
|
|
|
- for (int i = 1; i <= num_params; ++i) {
|
|
|
|
|
|
|
+ for (int i = 1; i <= 8; ++i) {
|
|
|
w.write(", [{}]={:#x}", i, cmd_buf[i]);
|
|
w.write(", [{}]={:#x}", i, cmd_buf[i]);
|
|
|
}
|
|
}
|
|
|
w << '}';
|
|
w << '}';
|
|
|
|
|
|
|
|
LOG_ERROR(Service, "unknown / unimplemented %s", w.c_str());
|
|
LOG_ERROR(Service, "unknown / unimplemented %s", w.c_str());
|
|
|
// TODO(bunnei): Hack - ignore error
|
|
// TODO(bunnei): Hack - ignore error
|
|
|
- cmd_buf[1] = 0;
|
|
|
|
|
|
|
+ IPC::RequestBuilder rb{ ctx, 1 };
|
|
|
|
|
+ rb.Push(RESULT_SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void ServiceFrameworkBase::HandleSyncRequest(SharedPtr<ServerSession> server_session) {
|
|
|
|
|
- u32* cmd_buf = Kernel::GetCommandBuffer();
|
|
|
|
|
-
|
|
|
|
|
- u32 header_code = cmd_buf[0];
|
|
|
|
|
- auto itr = handlers.find(header_code);
|
|
|
|
|
|
|
+void ServiceFrameworkBase::InvokeRequest(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
+ auto itr = handlers.find(ctx.GetCommand());
|
|
|
const FunctionInfoBase* info = itr == handlers.end() ? nullptr : &itr->second;
|
|
const FunctionInfoBase* info = itr == handlers.end() ? nullptr : &itr->second;
|
|
|
if (info == nullptr || info->handler_callback == nullptr) {
|
|
if (info == nullptr || info->handler_callback == nullptr) {
|
|
|
- return ReportUnimplementedFunction(cmd_buf, info);
|
|
|
|
|
|
|
+ return ReportUnimplementedFunction(ctx, info);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ LOG_TRACE(Service, "%s",
|
|
|
|
|
+ MakeFunctionString(info->name, GetServiceName().c_str(), ctx.CommandBuffer()).c_str());
|
|
|
|
|
+ handler_invoker(this, info->handler_callback, ctx);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void ServiceFrameworkBase::HandleSyncRequest(SharedPtr<ServerSession> server_session) {
|
|
|
|
|
+ u32* cmd_buf = (u32*)Memory::GetPointer(Kernel::GetCurrentThread()->GetTLSAddress());;
|
|
|
|
|
+
|
|
|
// TODO(yuriks): The kernel should be the one handling this as part of translation after
|
|
// TODO(yuriks): The kernel should be the one handling this as part of translation after
|
|
|
// everything else is migrated
|
|
// everything else is migrated
|
|
|
Kernel::HLERequestContext context(std::move(server_session));
|
|
Kernel::HLERequestContext context(std::move(server_session));
|
|
|
context.PopulateFromIncomingCommandBuffer(cmd_buf, *Kernel::g_current_process,
|
|
context.PopulateFromIncomingCommandBuffer(cmd_buf, *Kernel::g_current_process,
|
|
|
Kernel::g_handle_table);
|
|
Kernel::g_handle_table);
|
|
|
|
|
|
|
|
- LOG_TRACE(Service, "%s",
|
|
|
|
|
- MakeFunctionString(info->name, GetServiceName().c_str(), cmd_buf).c_str());
|
|
|
|
|
- handler_invoker(this, info->handler_callback, context);
|
|
|
|
|
|
|
+ switch (context.GetCommandType()) {
|
|
|
|
|
+ case IPC::CommandType::Close:
|
|
|
|
|
+ {
|
|
|
|
|
+ IPC::RequestBuilder rb{context, 1};
|
|
|
|
|
+ rb.Push(RESULT_SUCCESS);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case IPC::CommandType::Control:
|
|
|
|
|
+ {
|
|
|
|
|
+ SM::g_service_manager->InvokeControlRequest(context);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case IPC::CommandType::Request:
|
|
|
|
|
+ {
|
|
|
|
|
+ InvokeRequest(context);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ default:
|
|
|
|
|
+ UNIMPLEMENTED_MSG("command_type=%d", context.GetCommandType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
context.WriteToOutgoingCommandBuffer(cmd_buf, *Kernel::g_current_process,
|
|
context.WriteToOutgoingCommandBuffer(cmd_buf, *Kernel::g_current_process,
|
|
|
Kernel::g_handle_table);
|
|
Kernel::g_handle_table);
|
|
|
}
|
|
}
|
|
@@ -162,33 +152,14 @@ void AddNamedPort(std::string name, SharedPtr<ClientPort> port) {
|
|
|
g_kernel_named_ports.emplace(std::move(name), std::move(port));
|
|
g_kernel_named_ports.emplace(std::move(name), std::move(port));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void AddNamedPort(Interface* interface_) {
|
|
|
|
|
- SharedPtr<ServerPort> server_port;
|
|
|
|
|
- SharedPtr<ClientPort> client_port;
|
|
|
|
|
- std::tie(server_port, client_port) =
|
|
|
|
|
- ServerPort::CreatePortPair(interface_->GetMaxSessions(), interface_->GetPortName());
|
|
|
|
|
-
|
|
|
|
|
- server_port->SetHleHandler(std::shared_ptr<Interface>(interface_));
|
|
|
|
|
- AddNamedPort(interface_->GetPortName(), std::move(client_port));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void AddService(Interface* interface_) {
|
|
|
|
|
- auto server_port =
|
|
|
|
|
- SM::g_service_manager
|
|
|
|
|
- ->RegisterService(interface_->GetPortName(), interface_->GetMaxSessions())
|
|
|
|
|
- .Unwrap();
|
|
|
|
|
- server_port->SetHleHandler(std::shared_ptr<Interface>(interface_));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/// Initialize ServiceManager
|
|
/// Initialize ServiceManager
|
|
|
void Init() {
|
|
void Init() {
|
|
|
SM::g_service_manager = std::make_shared<SM::ServiceManager>();
|
|
SM::g_service_manager = std::make_shared<SM::ServiceManager>();
|
|
|
SM::ServiceManager::InstallInterfaces(SM::g_service_manager);
|
|
SM::ServiceManager::InstallInterfaces(SM::g_service_manager);
|
|
|
|
|
|
|
|
- HID::Init();
|
|
|
|
|
|
|
+ LM::InstallInterfaces(*SM::g_service_manager);
|
|
|
|
|
|
|
|
- AddService(new DSP_DSP::Interface);
|
|
|
|
|
- AddService(new GSP::GSP_GPU);
|
|
|
|
|
|
|
+ HID::Init();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service, "initialized OK");
|
|
LOG_DEBUG(Service, "initialized OK");
|
|
|
}
|
|
}
|