[NDM] Stub NDM service

This commit is contained in:
wheremyfoodat 2022-09-22 00:33:54 +03:00
parent aef1520f17
commit 36a30da78d
9 changed files with 84 additions and 10 deletions

View file

@ -52,6 +52,7 @@ set(KERNEL_SOURCE_FILES src/core/kernel/kernel.cpp src/core/kernel/resource_limi
)
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
src/core/services/ndm.cpp
)
set(PICA_SOURCE_FILES src/core/PICA/gpu.cpp src/core/PICA/regs.cpp)
@ -61,7 +62,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp inc
include/kernel/config_mem.hpp include/services/service_manager.hpp include/services/apt.hpp
include/kernel/handles.hpp include/services/hid.hpp include/services/fs.hpp
include/services/gsp_gpu.hpp include/services/gsp_lcd.hpp include/arm_defs.hpp
include/gpu.hpp
include/gpu.hpp include/services/ndm.hpp
)
set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp

View file

@ -15,9 +15,10 @@ namespace KernelHandles {
FS = 0xFFFF8004, // Filesystem service
GPU = 0xFFFF8005, // GPU service
LCD = 0xFFFF8006, // LCD service
NDM = 0xFFFF8007, // ?????
MinServiceHandle = APT,
MaxServiceHandle = LCD,
MaxServiceHandle = NDM,
GSPSharedMemHandle = MaxServiceHandle + 1 // Handle for the GSP shared memory
};

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

@ -0,0 +1,18 @@
#pragma once
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "memory.hpp"
class NDMService {
Handle handle = KernelHandles::NDM;
Memory& mem;
// Service commands
void overrideDefaultDaemons(u32 messagePointer);
void suspendDaemons(u32 messagePointer);
public:
NDMService(Memory& mem) : mem(mem) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -7,6 +7,7 @@
#include "services/fs.hpp"
#include "services/gsp_gpu.hpp"
#include "services/gsp_lcd.hpp"
#include "services/ndm.hpp"
class ServiceManager {
std::array<u32, 16>& regs;
@ -17,8 +18,10 @@ class ServiceManager {
FSService fs;
GPUService gsp_gpu;
LCDService gsp_lcd;
NDMService ndm;
// "srv:" commands
void enableNotification(u32 messagePointer);
void getServiceHandle(u32 messagePointer);
void registerClient(u32 messagePointer);

View file

@ -24,7 +24,7 @@ void APTService::handleSyncRequest(u32 messagePointer) {
}
void APTService::getLockHandle(u32 messagePointer) {
printf("APT: getLockHandle (Failure)\n");
printf("APT::GetLockHandle (Failure)\n");
mem.write32(messagePointer + 4, Result::Failure); // Result code
mem.write32(messagePointer + 16, 0); // Translation descriptor
}

View file

@ -26,11 +26,11 @@ void FSService::handleSyncRequest(u32 messagePointer) {
}
void FSService::initialize(u32 messagePointer) {
printf("FS: Initialize (failure)\n");
printf("FS::Initialize (failure)\n");
mem.write32(messagePointer + 4, Result::Failure);
}
void FSService::openArchive(u32 messagePointer) {
printf("FS: OpenArchive (failure)\n");
printf("FS::OpenArchive (failure)\n");
mem.write32(messagePointer + 4, Result::Failure);
}

View file

@ -24,7 +24,7 @@ void HIDService::handleSyncRequest(u32 messagePointer) {
}
void HIDService::getIPCHandles(u32 messagePointer) {
printf("HID: getIPCHandles (Failure)\n");
printf("HID::GetIPCHandles (Failure)\n");
mem.write32(messagePointer + 4, Result::Failure); // Result code
mem.write32(messagePointer + 8, 0x14000000); // Translation descriptor
}

35
src/core/services/ndm.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "services/ndm.hpp"
namespace NDMCommands {
enum : u32 {
OverrideDefaultDaemons = 0x00140040,
SuspendDaemons = 0x00060040
};
}
namespace Result {
enum : u32 {
Success = 0,
};
}
void NDMService::reset() {}
void NDMService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
case NDMCommands::OverrideDefaultDaemons: overrideDefaultDaemons(messagePointer); break;
case NDMCommands::SuspendDaemons: suspendDaemons(messagePointer); break;
default: Helpers::panic("NDM service requested. Command: %08X\n", command);
}
}
void NDMService::overrideDefaultDaemons(u32 messagePointer) {
printf("NDM::OverrideDefaultDaemons(stubbed)\n");
mem.write32(messagePointer + 4, Result::Success);
}
void NDMService::suspendDaemons(u32 messagePointer) {
printf("NDM::SuspendDaemons(stubbed)\n");
mem.write32(messagePointer + 4, Result::Success);
}

View file

@ -1,7 +1,7 @@
#include "services/service_manager.hpp"
ServiceManager::ServiceManager(std::array<u32, 16>& regs, Memory& mem, GPU& gpu, u32& currentPID)
: regs(regs), mem(mem), apt(mem), hid(mem), fs(mem), gsp_gpu(mem, gpu, currentPID), gsp_lcd(mem) {}
: regs(regs), mem(mem), apt(mem), hid(mem), fs(mem), gsp_gpu(mem, gpu, currentPID), gsp_lcd(mem), ndm(mem) {}
void ServiceManager::reset() {
apt.reset();
@ -9,6 +9,7 @@ void ServiceManager::reset() {
fs.reset();
gsp_gpu.reset();
gsp_lcd.reset();
ndm.reset();
}
// Match IPC messages to a "srv:" command based on their header
@ -44,6 +45,7 @@ void ServiceManager::handleSyncRequest(u32 messagePointer) {
const u32 header = mem.read32(messagePointer);
switch (header) {
case Commands::EnableNotification: enableNotification(messagePointer); break;
case Commands::RegisterClient: registerClient(messagePointer); break;
case Commands::GetServiceHandle: getServiceHandle(messagePointer); break;
default: Helpers::panic("Unknown \"srv:\" command: %08X", header);
@ -52,7 +54,7 @@ void ServiceManager::handleSyncRequest(u32 messagePointer) {
// https://www.3dbrew.org/wiki/SRV:RegisterClient
void ServiceManager::registerClient(u32 messagePointer) {
printf("srv: registerClient (Stubbed)\n");
printf("srv::registerClient (Stubbed)\n");
mem.write32(messagePointer + 4, Result::Success);
}
@ -63,10 +65,12 @@ void ServiceManager::getServiceHandle(u32 messagePointer) {
u32 handle = 0;
std::string service = mem.readString(messagePointer + 4, 8);
printf("srv: getServiceHandle (Service: %s, nameLength: %d, flags: %d)\n", service.c_str(), nameLength, flags);
printf("srv::getServiceHandle (Service: %s, nameLength: %d, flags: %d)\n", service.c_str(), nameLength, flags);
if (service == "APT:S") {
handle = KernelHandles::APT;
} else if (service == "APT:A") { // TODO: APT:A and APT:S are slightly different
handle = KernelHandles::APT;
} else if (service == "hid:USER") {
handle = KernelHandles::HID;
} else if (service == "fs:USER") {
@ -75,7 +79,9 @@ void ServiceManager::getServiceHandle(u32 messagePointer) {
handle = KernelHandles::GPU;
} else if (service == "gsp::Lcd") {
handle = KernelHandles::LCD;
} else {
} else if (service == "ndm:u") {
handle = KernelHandles::NDM;
}else {
Helpers::panic("srv: GetServiceHandle with unknown service %s", service.c_str());
}
@ -83,6 +89,15 @@ void ServiceManager::getServiceHandle(u32 messagePointer) {
mem.write32(messagePointer + 12, handle);
}
void ServiceManager::enableNotification(u32 messagePointer) {
printf("srv::EnableNotification()\n");
mem.write32(messagePointer + 4, Result::Success); // Result code
mem.write32(messagePointer + 8, 0); // Translation descriptor
// TODO: Unstub. Handle to semaphore signaled on process notification
mem.write32(messagePointer + 12, 0x69696979);
}
void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
switch (handle) {
case KernelHandles::APT: apt.handleSyncRequest(messagePointer); break;
@ -90,6 +105,7 @@ void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
case KernelHandles::FS: fs.handleSyncRequest(messagePointer); break;
case KernelHandles::GPU: [[likely]] gsp_gpu.handleSyncRequest(messagePointer); break;
case KernelHandles::LCD: gsp_lcd.handleSyncRequest(messagePointer); break;
case KernelHandles::NDM: ndm.handleSyncRequest(messagePointer); break;
default: Helpers::panic("Sent IPC message to unknown service %08X\n Command: %08X", handle, mem.read32(messagePointer));
}
}