From 18f3865f8b383aba489fdd8b9f3a531b34604c3b Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 30 Nov 2024 21:51:46 +0200 Subject: [PATCH] Add option to print DSP fw --- include/config.hpp | 1 + include/services/dsp.hpp | 6 ++++- src/config.cpp | 2 ++ src/core/services/dsp.cpp | 32 +++++++++++++++++++++++++-- src/core/services/service_manager.cpp | 2 +- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 9364a33d..5a7c7fff 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -58,6 +58,7 @@ struct EmulatorConfig { bool enableRenderdoc = false; bool printAppVersion = true; + bool printDSPFirmware = false; bool chargerPlugged = true; // Default to 3% battery to make users suffer diff --git a/include/services/dsp.hpp b/include/services/dsp.hpp index bc1adbca..7eb9b28b 100644 --- a/include/services/dsp.hpp +++ b/include/services/dsp.hpp @@ -10,6 +10,7 @@ #include "memory.hpp" #include "result/result.hpp" +struct EmulatorConfig; // Circular dependencies! class Kernel; @@ -19,7 +20,9 @@ class DSPService { Handle handle = KernelHandles::DSP; Memory& mem; Kernel& kernel; + const EmulatorConfig& config; Audio::DSPCore* dsp = nullptr; + MAKE_LOG_FUNCTION(log, dspServiceLogger) // Number of DSP pipes @@ -58,7 +61,7 @@ class DSPService { void writeProcessPipe(u32 messagePointer); public: - DSPService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {} + DSPService(Memory& mem, Kernel& kernel, const EmulatorConfig& config) : mem(mem), kernel(kernel), config(config) {} void reset(); void handleSyncRequest(u32 messagePointer); void setDSPCore(Audio::DSPCore* pointer) { dsp = pointer; } @@ -84,4 +87,5 @@ class DSPService { void triggerInterrupt1(); ComponentDumpResult dumpComponent(const std::filesystem::path& path); + void printFirmwareInfo(); }; \ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index 833a1b4e..93aed106 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -99,6 +99,7 @@ void EmulatorConfig::load() { audioEnabled = toml::find_or(audio, "EnableAudio", false); aacEnabled = toml::find_or(audio, "EnableAACAudio", true); + printDSPFirmware = toml::find_or(audio, "PrintDSPFirmware", false); audioDeviceConfig.muteAudio = toml::find_or(audio, "MuteAudio", false); // Our volume ranges from 0.0 (muted) to 2.0 (boosted, using a logarithmic scale). 1.0 is the "default" volume, ie we don't adjust the PCM @@ -177,6 +178,7 @@ void EmulatorConfig::save() { data["Audio"]["EnableAACAudio"] = aacEnabled; data["Audio"]["MuteAudio"] = audioDeviceConfig.muteAudio; data["Audio"]["AudioVolume"] = double(audioDeviceConfig.volumeRaw); + data["Audio"]["PrintDSPFirmware"] = printDSPFirmware; data["Battery"]["ChargerPlugged"] = chargerPlugged; data["Battery"]["BatteryPercentage"] = batteryPercentage; diff --git a/src/core/services/dsp.cpp b/src/core/services/dsp.cpp index 8c514761..b186e5ad 100644 --- a/src/core/services/dsp.cpp +++ b/src/core/services/dsp.cpp @@ -1,10 +1,17 @@ #include "services/dsp.hpp" -#include "ipc.hpp" -#include "kernel.hpp" + +#include +#include +#include #include +#include #include +#include "config.hpp" +#include "ipc.hpp" +#include "kernel.hpp" + namespace DSPCommands { enum : u32 { RecvData = 0x00010040, @@ -92,6 +99,10 @@ void DSPService::loadComponent(u32 messagePointer) { log("DSP::LoadComponent (size = %08X, program mask = %X, data mask = %X\n", size, programMask, dataMask); dsp->loadComponent(loadedComponent, programMask, dataMask); + if (config.printDSPFirmware) { + printFirmwareInfo(); + } + mem.write32(messagePointer, IPC::responseHeader(0x11, 2, 2)); mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 8, 1); // Component loaded @@ -303,4 +314,21 @@ void DSPService::triggerInterrupt1() { if (interrupt1.has_value()) { kernel.signalEvent(*interrupt1); } +} + +void DSPService::printFirmwareInfo() { + // No component has been loaded, do nothing. + if (!loadedComponent.size()) { + return; + } + const usize firmwareSize = loadedComponent.size(); + std::array hash; + + CryptoPP::SHA256 sha; + sha.CalculateDigest(hash.data(), loadedComponent.data(), firmwareSize); + + fmt::print("\nLoaded DSP firmware\n"); + fmt::print("DSP firmware hash: {:X}\n", fmt::join(hash, "")); + fmt::print("Size: {} bytes ({} KB)\n", firmwareSize, firmwareSize / 1024); + fmt::print("\n"); } \ No newline at end of file diff --git a/src/core/services/service_manager.cpp b/src/core/services/service_manager.cpp index 31e3d702..8fa88a00 100644 --- a/src/core/services/service_manager.cpp +++ b/src/core/services/service_manager.cpp @@ -7,7 +7,7 @@ ServiceManager::ServiceManager(std::span 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, kernel), 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, config), 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, kernel), mcu_hwc(mem, config), mic(mem, kernel), nfc(mem, kernel), nim(mem), ndm(mem), news_u(mem), nwm_uds(mem, kernel), ptm(mem, config), soc(mem), ssl(mem), y2r(mem, kernel) {}