mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 12:39:13 +12:00
Merge remote-tracking branch 'upstream/master' into moar-gpu
This commit is contained in:
commit
e9bff39a7f
7 changed files with 99 additions and 2 deletions
|
@ -9,7 +9,7 @@ ServiceManager::ServiceManager(std::span<u32, 16> regs, Memory& mem, GPU& gpu, u
|
|||
: regs(regs), mem(mem), kernel(kernel), ac(mem), am(mem), boss(mem), act(mem), apt(mem, kernel), cam(mem), cecd(mem, kernel), cfg(mem),
|
||||
dlp_srvr(mem), dsp(mem, kernel), hid(mem, kernel), http(mem), ir_user(mem, kernel), frd(mem), fs(mem, kernel),
|
||||
gsp_gpu(mem, gpu, kernel, currentPID), gsp_lcd(mem), ldr(mem), mic(mem), nfc(mem, kernel), nim(mem), ndm(mem), ptm(mem), soc(mem),
|
||||
y2r(mem, kernel) {}
|
||||
ssl(mem), y2r(mem, kernel) {}
|
||||
|
||||
static constexpr int MAX_NOTIFICATION_COUNT = 16;
|
||||
|
||||
|
@ -38,6 +38,7 @@ void ServiceManager::reset() {
|
|||
ndm.reset();
|
||||
ptm.reset();
|
||||
soc.reset();
|
||||
ssl.reset();
|
||||
y2r.reset();
|
||||
|
||||
notificationSemaphore = std::nullopt;
|
||||
|
@ -116,6 +117,7 @@ static std::map<std::string, Handle> serviceMap = {
|
|||
{ "ptm:u", KernelHandles::PTM }, // TODO: ptm:u and ptm:sysm have very different command sets
|
||||
{ "ptm:sysm", KernelHandles::PTM },
|
||||
{ "soc:U", KernelHandles::SOC },
|
||||
{ "ssl:C", KernelHandles::SSL },
|
||||
{ "y2r:u", KernelHandles::Y2R }
|
||||
};
|
||||
// clang-format on
|
||||
|
@ -199,6 +201,7 @@ void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
|
|||
case KernelHandles::NDM: ndm.handleSyncRequest(messagePointer); break;
|
||||
case KernelHandles::PTM: ptm.handleSyncRequest(messagePointer); break;
|
||||
case KernelHandles::SOC: soc.handleSyncRequest(messagePointer); break;
|
||||
case KernelHandles::SSL: ssl.handleSyncRequest(messagePointer); break;
|
||||
case KernelHandles::Y2R: y2r.handleSyncRequest(messagePointer); break;
|
||||
default: Helpers::panic("Sent IPC message to unknown service %08X\n Command: %08X", handle, mem.read32(messagePointer));
|
||||
}
|
||||
|
|
63
src/core/services/ssl.cpp
Normal file
63
src/core/services/ssl.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include "ipc.hpp"
|
||||
#include "result/result.hpp"
|
||||
#include "services/ssl.hpp"
|
||||
|
||||
namespace SSLCommands {
|
||||
enum : u32 {
|
||||
Initialize = 0x00010002,
|
||||
GenerateRandomData = 0x00110042,
|
||||
};
|
||||
}
|
||||
|
||||
void SSLService::reset() {
|
||||
initialized = false;
|
||||
|
||||
// Use the default seed on reset to avoid funny bugs
|
||||
rng.seed();
|
||||
}
|
||||
|
||||
void SSLService::handleSyncRequest(u32 messagePointer) {
|
||||
const u32 command = mem.read32(messagePointer);
|
||||
switch (command) {
|
||||
case SSLCommands::Initialize: initialize(messagePointer); break;
|
||||
case SSLCommands::GenerateRandomData: generateRandomData(messagePointer); break;
|
||||
default: Helpers::panic("SSL service requested. Command: %08X\n", command);
|
||||
}
|
||||
}
|
||||
|
||||
void SSLService::initialize(u32 messagePointer) {
|
||||
log("SSL::Initialize\n");
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x01, 1, 0));
|
||||
|
||||
if (initialized) {
|
||||
Helpers::warn("SSL service initialized twice");
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
rng.seed(std::random_device()()); // Seed rng via std::random_device
|
||||
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
}
|
||||
|
||||
void SSLService::generateRandomData(u32 messagePointer) {
|
||||
const u32 size = mem.read32(messagePointer + 4);
|
||||
const u32 output = mem.read32(messagePointer + 12);
|
||||
log("SSL::GenerateRandomData (out = %08X, size = %08X)\n", output, size);
|
||||
|
||||
// TODO: This might be a biiit slow, might want to make it write in word quantities
|
||||
u32 data;
|
||||
|
||||
for (u32 i = 0; i < size; i++) {
|
||||
// We don't have an available random value since we're on a multiple of 4 bytes and our Twister is 32-bit, generate a new one from the Mersenne Twister
|
||||
if ((i & 3) == 0) {
|
||||
data = rng();
|
||||
}
|
||||
|
||||
mem.write8(output + i, u8(data));
|
||||
// Shift data by 8 to get the next byte
|
||||
data >>= 8;
|
||||
}
|
||||
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x11, 1, 2));
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue