From a91035abf4513ee68d4aa501c1ed87aea1d883a0 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sun, 18 Sep 2022 18:17:41 +0300 Subject: [PATCH] Initial impl for createEvent SVC --- CMakeLists.txt | 1 + include/kernel/kernel.hpp | 4 +++- include/kernel/kernel_types.hpp | 3 ++- src/core/kernel/events.cpp | 21 +++++++++++++++++++++ src/core/kernel/kernel.cpp | 1 + src/core/kernel/threads.cpp | 0 6 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/core/kernel/events.cpp create mode 100644 src/core/kernel/threads.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e32c2ca1..73a5b94e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ endif() set(SOURCE_FILES src/main.cpp src/emulator.cpp src/core/CPU/cpu_dynarmic.cpp src/core/memory.cpp src/core/elf.cpp) 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 + src/core/kernel/events.cpp src/core/kernel/threads.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 src/core/services/gsp_gpu.cpp src/core/services/gsp_lcd.cpp diff --git a/include/kernel/kernel.hpp b/include/kernel/kernel.hpp index d8c70be6..cbb9e293 100644 --- a/include/kernel/kernel.hpp +++ b/include/kernel/kernel.hpp @@ -49,6 +49,7 @@ class Kernel { return handleCounter++; } + Handle makeEvent(u32 resetType); Handle makeProcess(); Handle makePort(const char* name); Handle makeSession(Handle port); @@ -63,8 +64,9 @@ class Kernel { std::string getProcessName(u32 pid); // SVC implementations - void controlMemory(); void createAddressArbiter(); + void createEvent(); + void controlMemory(); void getResourceLimit(); void getResourceLimitLimitValues(); void getResourceLimitCurrentValues(); diff --git a/include/kernel/kernel_types.hpp b/include/kernel/kernel_types.hpp index 11aa415d..f7c36fae 100644 --- a/include/kernel/kernel_types.hpp +++ b/include/kernel/kernel_types.hpp @@ -15,7 +15,7 @@ namespace SVCResult { } enum class KernelObjectType : u8 { - Port, Process, ResourceLimit, Session, Dummy + Event, Port, Process, ResourceLimit, Session, Dummy }; enum class ResourceLimitCategory : int { @@ -68,6 +68,7 @@ struct SessionData { static const char* kernelObjectTypeToString(KernelObjectType t) { switch (t) { + case KernelObjectType::Event: return "event"; case KernelObjectType::Port: return "port"; case KernelObjectType::Process: return "process"; case KernelObjectType::ResourceLimit: return "resource limit"; diff --git a/src/core/kernel/events.cpp b/src/core/kernel/events.cpp new file mode 100644 index 00000000..ed87c314 --- /dev/null +++ b/src/core/kernel/events.cpp @@ -0,0 +1,21 @@ +#include "kernel.hpp" + +// TODO: What the fuck is resetType meant to be? +Handle Kernel::makeEvent(u32 resetType) { + Handle ret = makeObject(KernelObjectType::Event); + return ret; +} + +// Result CreateEvent(Handle* event, ResetType resetType) +// TODO: Just like getResourceLimit this seems to output the handle in r1 even though 3dbrew doesn't mention this +// Should the handle be written both in memory and r1, or just r1? +void Kernel::createEvent() { + const u32 outPointer = regs[0]; + const u32 resetType = regs[1]; + printf("CreateEvent(handle pointer = %08X, resetType = %d)\n", outPointer, resetType); + + Handle handle = makeEvent(resetType); + regs[0] = SVCResult::Success; + regs[1] = handle; + mem.write32(outPointer, handle); +} \ No newline at end of file diff --git a/src/core/kernel/kernel.cpp b/src/core/kernel/kernel.cpp index b40a06e3..0614e169 100644 --- a/src/core/kernel/kernel.cpp +++ b/src/core/kernel/kernel.cpp @@ -5,6 +5,7 @@ void Kernel::serviceSVC(u32 svc) { switch (svc) { case 0x01: controlMemory(); break; + case 0x17: createEvent(); break; case 0x21: createAddressArbiter(); break; case 0x23: svcCloseHandle(); break; case 0x2D: connectToPort(); break; diff --git a/src/core/kernel/threads.cpp b/src/core/kernel/threads.cpp new file mode 100644 index 00000000..e69de29b