Stub FS service, we now get to main in libctru

This commit is contained in:
wheremyfoodat 2022-09-18 03:09:35 +03:00
parent 083a0d04d7
commit 91356f1de9
6 changed files with 70 additions and 4 deletions

View file

@ -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

View file

@ -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";
}
}

18
include/services/fs.hpp Normal file
View file

@ -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);
};

View file

@ -4,6 +4,7 @@
#include "memory.hpp"
#include "services/apt.hpp"
#include "services/hid.hpp"
#include "services/fs.hpp"
class ServiceManager {
std::array<u32, 16>& regs;
@ -11,6 +12,7 @@ class ServiceManager {
APTService apt;
HIDService hid;
FSService fs;
// "srv:" commands
void getServiceHandle(u32 messagePointer);

36
src/core/services/fs.cpp Normal file
View file

@ -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);
}

View file

@ -1,10 +1,12 @@
#include "services/service_manager.hpp"
ServiceManager::ServiceManager(std::array<u32, 16>& regs, Memory& mem) : regs(regs), mem(mem), apt(mem), hid(mem) {}
ServiceManager::ServiceManager(std::array<u32, 16>& 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));
}
}