From 340e0c92664aa176f03d82dd7eb492c3a6cd24a0 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sun, 18 Sep 2022 02:31:58 +0300 Subject: [PATCH] Add HID service --- include/kernel/handles.hpp | 4 +++- include/services/hid.hpp | 14 ++++++++++++++ include/services/service_manager.hpp | 2 ++ src/core/services/hid.cpp | 22 ++++++++++++++++++++++ src/core/services/service_manager.cpp | 6 +++++- 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/kernel/handles.hpp b/include/kernel/handles.hpp index 38adb99f..edc55fb3 100644 --- a/include/kernel/handles.hpp +++ b/include/kernel/handles.hpp @@ -11,9 +11,10 @@ namespace KernelHandles { CurrentThread = 0xFFFF8000, // Used by the original kernel CurrentProcess = 0xFFFF8001, // Used by the original kernel APT = 0xFFFF8002, // App Title something service? + HID = 0xFFFF8003, // Handles everything input-related including gyro MinServiceHandle = APT, - MaxServiceHandle = APT + MaxServiceHandle = HID }; // Returns whether "handle" belongs to one of the OS services @@ -25,6 +26,7 @@ namespace KernelHandles { static const char* getServiceName(Handle handle) { switch (handle) { case APT: return "APT"; + case HID: return "HID"; default: return "Unknown"; } } diff --git a/include/services/hid.hpp b/include/services/hid.hpp index e69de29b..eafae219 100644 --- a/include/services/hid.hpp +++ b/include/services/hid.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "helpers.hpp" +#include "kernel_types.hpp" +#include "memory.hpp" + +class HIDService { + Handle handle = KernelHandles::HID; + Memory& mem; + +public: + HIDService(Memory& mem) : mem(mem) {} + void reset(); + void handleSyncRequest(u32 messagePointer); +}; \ No newline at end of file diff --git a/include/services/service_manager.hpp b/include/services/service_manager.hpp index 7a2a90e6..77323cba 100644 --- a/include/services/service_manager.hpp +++ b/include/services/service_manager.hpp @@ -3,12 +3,14 @@ #include "helpers.hpp" #include "memory.hpp" #include "services/apt.hpp" +#include "services/hid.hpp" class ServiceManager { std::array& regs; Memory& mem; APTService apt; + HIDService hid; // "srv:" commands void getServiceHandle(u32 messagePointer); diff --git a/src/core/services/hid.cpp b/src/core/services/hid.cpp index e69de29b..d062d7bf 100644 --- a/src/core/services/hid.cpp +++ b/src/core/services/hid.cpp @@ -0,0 +1,22 @@ +#include "services/hid.hpp" + +namespace HIDCommands { + enum : u32 { + + }; +} + +namespace Result { + enum : u32 { + Success = 0, + }; +} + +void HIDService::reset() {} + +void HIDService::handleSyncRequest(u32 messagePointer) { + const u32 command = mem.read32(messagePointer); + switch (command) { + default: Helpers::panic("HID service requested. Command: %08X\n", command); + } +} \ No newline at end of file diff --git a/src/core/services/service_manager.cpp b/src/core/services/service_manager.cpp index edb8828a..013187b2 100644 --- a/src/core/services/service_manager.cpp +++ b/src/core/services/service_manager.cpp @@ -1,9 +1,10 @@ #include "services/service_manager.hpp" -ServiceManager::ServiceManager(std::array& regs, Memory& mem) : regs(regs), mem(mem), apt(mem) {} +ServiceManager::ServiceManager(std::array& regs, Memory& mem) : regs(regs), mem(mem), apt(mem), hid(mem) {} void ServiceManager::reset() { apt.reset(); + hid.reset(); } // Match IPC messages to a "srv:" command based on their header @@ -62,6 +63,8 @@ void ServiceManager::getServiceHandle(u32 messagePointer) { if (service == "APT:S") { handle = KernelHandles::APT; + } else if (service == "hid:USER") { + handle = KernelHandles::HID; } else { Helpers::panic("srv: GetServiceHandle with unknown service %s", service.c_str()); } @@ -73,6 +76,7 @@ void ServiceManager::getServiceHandle(u32 messagePointer) { void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) { switch (handle) { case KernelHandles::APT: apt.handleSyncRequest(messagePointer); break; + case KernelHandles::HID: hid.handleSyncRequest(messagePointer); break; default: Helpers::panic("Sent IPC message to unknown service %08X\n", handle); } } \ No newline at end of file