From 91356f1de9224d8d8cca830a1acf9ef06b70cabf Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sun, 18 Sep 2022 03:09:35 +0300 Subject: [PATCH] Stub FS service, we now get to main in libctru --- CMakeLists.txt | 7 ++++-- include/kernel/handles.hpp | 4 ++- include/services/fs.hpp | 18 ++++++++++++++ include/services/service_manager.hpp | 2 ++ src/core/services/fs.cpp | 36 +++++++++++++++++++++++++++ src/core/services/service_manager.cpp | 7 +++++- 6 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 include/services/fs.hpp create mode 100644 src/core/services/fs.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ed3b75de..3c6ba70f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,13 +48,16 @@ set(SOURCE_FILES src/main.cpp src/emulator.cpp src/core/CPU/cpu_dynarmic.cpp src set(KERNEL_SOURCE_FILES src/core/kernel/kernel.cpp src/core/kernel/resource_limits.cpp src/core/kernel/memory_management.cpp src/core/kernel/ports.cpp ) -set(SERVICE_SOURCE_FILES src/core/services/service_manager.cpp src/core/services/apt.cpp src/core/services/hid.cpp) +set(SERVICE_SOURCE_FILES src/core/services/service_manager.cpp src/core/services/apt.cpp src/core/services/hid.cpp + src/core/services/fs.cpp +) + set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp include/termcolor.hpp include/cpu.hpp include/cpu_dynarmic.hpp include/memory.hpp include/kernel/kernel.hpp include/dynarmic_cp15.hpp include/kernel/resource_limits.hpp include/kernel/kernel_types.hpp include/kernel/config_mem.hpp include/services/service_manager.hpp include/services/apt.hpp - include/kernel/handles.hpp include/services/hid.hpp + include/kernel/handles.hpp include/services/hid.hpp include/services/fs.hpp ) set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp diff --git a/include/kernel/handles.hpp b/include/kernel/handles.hpp index edc55fb3..a1112672 100644 --- a/include/kernel/handles.hpp +++ b/include/kernel/handles.hpp @@ -12,9 +12,10 @@ namespace KernelHandles { CurrentProcess = 0xFFFF8001, // Used by the original kernel APT = 0xFFFF8002, // App Title something service? HID = 0xFFFF8003, // Handles everything input-related including gyro + FS = 0xFFFF8004, // Filesystem service MinServiceHandle = APT, - MaxServiceHandle = HID + MaxServiceHandle = FS }; // Returns whether "handle" belongs to one of the OS services @@ -27,6 +28,7 @@ namespace KernelHandles { switch (handle) { case APT: return "APT"; case HID: return "HID"; + case FS: return "FS"; default: return "Unknown"; } } diff --git a/include/services/fs.hpp b/include/services/fs.hpp new file mode 100644 index 00000000..22081b8e --- /dev/null +++ b/include/services/fs.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "helpers.hpp" +#include "kernel_types.hpp" +#include "memory.hpp" + +class FSService { + Handle handle = KernelHandles::FS; + Memory& mem; + + // Service commands + void initialize(u32 messagePointer); + void openArchive(u32 messagePointer); + +public: + FSService(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 77323cba..28e31b29 100644 --- a/include/services/service_manager.hpp +++ b/include/services/service_manager.hpp @@ -4,6 +4,7 @@ #include "memory.hpp" #include "services/apt.hpp" #include "services/hid.hpp" +#include "services/fs.hpp" class ServiceManager { std::array& regs; @@ -11,6 +12,7 @@ class ServiceManager { APTService apt; HIDService hid; + FSService fs; // "srv:" commands void getServiceHandle(u32 messagePointer); diff --git a/src/core/services/fs.cpp b/src/core/services/fs.cpp new file mode 100644 index 00000000..b084b6bc --- /dev/null +++ b/src/core/services/fs.cpp @@ -0,0 +1,36 @@ +#include "services/fs.hpp" + +namespace FSCommands { + enum : u32 { + Initialize = 0x08010002, + OpenArchive = 0x080C00C2 + }; +} + +namespace Result { + enum : u32 { + Success = 0, + Failure = 0xFFFF'FFFF + }; +} + +void FSService::reset() {} + +void FSService::handleSyncRequest(u32 messagePointer) { + const u32 command = mem.read32(messagePointer); + switch (command) { + case FSCommands::Initialize: initialize(messagePointer); break; + case FSCommands::OpenArchive: openArchive(messagePointer); break; + default: Helpers::panic("FS service requested. Command: %08X\n", command); + } +} + +void FSService::initialize(u32 messagePointer) { + printf("FS: Initialize (failure)\n"); + mem.write32(messagePointer + 4, Result::Failure); +} + +void FSService::openArchive(u32 messagePointer) { + printf("FS: OpenArchive (failure)\n"); + mem.write32(messagePointer + 4, Result::Failure); +} \ No newline at end of file diff --git a/src/core/services/service_manager.cpp b/src/core/services/service_manager.cpp index 6a163862..421a61ff 100644 --- a/src/core/services/service_manager.cpp +++ b/src/core/services/service_manager.cpp @@ -1,10 +1,12 @@ #include "services/service_manager.hpp" -ServiceManager::ServiceManager(std::array& regs, Memory& mem) : regs(regs), mem(mem), apt(mem), hid(mem) {} +ServiceManager::ServiceManager(std::array& regs, Memory& mem) : regs(regs), mem(mem), + apt(mem), hid(mem), fs(mem) {} void ServiceManager::reset() { apt.reset(); hid.reset(); + fs.reset(); } // Match IPC messages to a "srv:" command based on their header @@ -65,6 +67,8 @@ void ServiceManager::getServiceHandle(u32 messagePointer) { handle = KernelHandles::APT; } else if (service == "hid:USER") { handle = KernelHandles::HID; + } else if (service == "fs:USER") { + handle = KernelHandles::FS; } else { Helpers::panic("srv: GetServiceHandle with unknown service %s", service.c_str()); } @@ -77,6 +81,7 @@ void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) { switch (handle) { case KernelHandles::APT: apt.handleSyncRequest(messagePointer); break; case KernelHandles::HID: hid.handleSyncRequest(messagePointer); break; + case KernelHandles::FS: fs.handleSyncRequest(messagePointer); break; default: Helpers::panic("Sent IPC message to unknown service %08X\n Command: %08X", handle, mem.read32(messagePointer)); } } \ No newline at end of file