More CSND stubbing

This commit is contained in:
wheremyfoodat 2023-09-10 16:51:44 +03:00
parent da29cecf7a
commit b394cacbc7
6 changed files with 67 additions and 6 deletions

View file

@ -46,6 +46,7 @@ namespace KernelHandles {
GSPSharedMemHandle = MaxServiceHandle + 1, // Handle for the GSP shared memory
FontSharedMemHandle,
CSNDSharedMemHandle,
HIDSharedMemHandle,
MinSharedMemHandle = GSPSharedMemHandle,

View file

@ -112,10 +112,11 @@ class Memory {
// This tracks our OS' memory allocations
std::vector<KernelMemoryTypes::MemoryInfo> memoryInfo;
std::array<SharedMemoryBlock, 3> sharedMemBlocks = {
std::array<SharedMemoryBlock, 4> sharedMemBlocks = {
SharedMemoryBlock(0, 0, KernelHandles::FontSharedMemHandle), // Shared memory for the system font (size is 0 because we read the size from the cmrc filesystem
SharedMemoryBlock(0, 0x1000, KernelHandles::GSPSharedMemHandle), // GSP shared memory
SharedMemoryBlock(0, 0x1000, KernelHandles::HIDSharedMemHandle) // HID shared memory
SharedMemoryBlock(0, 0x1000, KernelHandles::HIDSharedMemHandle), // HID shared memory
SharedMemoryBlock(0, 0x3000, KernelHandles::CSNDSharedMemHandle), // CSND shared memory
};
public:

View file

@ -1,16 +1,28 @@
#pragma once
#include <optional>
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "logger.hpp"
#include "memory.hpp"
// Circular dependencies ^-^
class Kernel;
class CSNDService {
Handle handle = KernelHandles::CSND;
Memory& mem;
Kernel& kernel;
MAKE_LOG_FUNCTION(log, csndLogger)
bool initialized = false;
std::optional<Handle> csndMutex = std::nullopt;
// Service functions
void initialize(u32 messagePointer);
public:
CSNDService(Memory& mem) : mem(mem) {}
CSNDService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -139,6 +139,8 @@ void Kernel::mapMemoryBlock() {
mem.copySharedFont(ptr);
break;
case KernelHandles::CSNDSharedMemHandle: printf("Mapping CSND memory block\n"); break;
default: Helpers::panic("Mapping unknown shared memory block: %X", block);
}
} else {

View file

@ -1,16 +1,61 @@
#include "services/csnd.hpp"
#include "ipc.hpp"
#include "kernel.hpp"
#include "result/result.hpp"
void CSNDService::reset() {}
namespace CSNDCommands {
enum : u32 {
Initialize = 0x00010140,
};
}
void CSNDService::reset() {
csndMutex = std::nullopt;
initialized = false;
}
void CSNDService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
case CSNDCommands::Initialize: initialize(messagePointer); break;
default:
Helpers::panic("Unimplemented CSND service requested. Command: %08X\n", command);
Helpers::warn("Unimplemented CSND service requested. Command: %08X\n", command);
mem.write32(messagePointer + 4, Result::Success);
break;
}
}
void CSNDService::initialize(u32 messagePointer) {
u32 blockSize = mem.read32(messagePointer + 4);
const u32 offset0 = mem.read32(messagePointer + 8);
const u32 offset1 = mem.read32(messagePointer + 12);
const u32 offset2 = mem.read32(messagePointer + 16);
const u32 offset3 = mem.read32(messagePointer + 20);
log("CSND::Initialize (Block size = %08X, offset0 = %X, offset1 = %X, offset2 = %X, offset3 = %X)\n", blockSize, offset0, offset1, offset2, offset3);
// Align block size to 4KB. CSND shared memory block is currently stubbed to be 0x3000 == 12KB, so panic if this is more than requested
blockSize = (blockSize + 0xFFF) & ~0xFFF;
if (blockSize != 12_KB) {
Helpers::panic("Unhandled size for CSND shared memory block");
}
if (initialized) {
printf("CSND initialized twice\n");
}
if (!csndMutex.has_value()) {
csndMutex = kernel.makeMutex(false);
}
initialized = true;
mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 3));
mem.write32(messagePointer + 4, Result::Success);
mem.write32(messagePointer + 8, 0x4000000);
mem.write32(messagePointer + 12, csndMutex.value());
mem.write32(messagePointer + 16, KernelHandles::CSNDSharedMemHandle);
}

View file

@ -7,7 +7,7 @@
ServiceManager::ServiceManager(std::span<u32, 16> regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel, const EmulatorConfig& config)
: regs(regs), mem(mem), kernel(kernel), ac(mem), am(mem), boss(mem), act(mem), apt(mem, kernel), cam(mem, kernel), cecd(mem, kernel), cfg(mem),
csnd(mem), dlp_srvr(mem), dsp(mem, kernel), hid(mem, kernel), http(mem), ir_user(mem, kernel), frd(mem), fs(mem, kernel, config),
csnd(mem, kernel), dlp_srvr(mem), dsp(mem, kernel), hid(mem, kernel), http(mem), ir_user(mem, kernel), frd(mem), fs(mem, kernel, config),
gsp_gpu(mem, gpu, kernel, currentPID), gsp_lcd(mem), ldr(mem), mcu_hwc(mem, config), mic(mem, kernel), nfc(mem, kernel), nim(mem), ndm(mem),
news_u(mem), ptm(mem, config), soc(mem), ssl(mem), y2r(mem, kernel) {}