mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 06:35:40 +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
|
@ -136,6 +136,7 @@ set(SERVICE_SOURCE_FILES src/core/services/service_manager.cpp src/core/services
|
|||
src/core/services/y2r.cpp src/core/services/cam.cpp src/core/services/ldr_ro.cpp
|
||||
src/core/services/act.cpp src/core/services/nfc.cpp src/core/services/dlp_srvr.cpp
|
||||
src/core/services/ir_user.cpp src/core/services/http.cpp src/core/services/soc.cpp
|
||||
src/core/services/ssl.cpp
|
||||
)
|
||||
set(PICA_SOURCE_FILES src/core/PICA/gpu.cpp src/core/PICA/regs.cpp src/core/PICA/shader_unit.cpp
|
||||
src/core/PICA/shader_interpreter.cpp src/core/PICA/dynapica/shader_rec.cpp
|
||||
|
@ -176,7 +177,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/termcolor.hpp
|
|||
include/config.hpp include/services/ir_user.hpp include/http_server.hpp include/cheats.hpp
|
||||
include/action_replay.hpp include/renderer_sw/renderer_sw.hpp include/compiler_builtins.hpp
|
||||
include/fs/romfs.hpp include/fs/ivfc.hpp include/discord_rpc.hpp include/services/http.hpp include/result/result_cfg.hpp
|
||||
include/math_util.hpp include/services/soc.hpp
|
||||
include/math_util.hpp include/services/soc.hpp include/services/ssl.hpp
|
||||
)
|
||||
|
||||
set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace KernelHandles {
|
|||
NDM, // ?????
|
||||
PTM, // PTM service (Used for accessing various console info, such as battery, shell and pedometer state)
|
||||
SOC, // Socket service
|
||||
SSL, // SSL service (Totally didn't expect that)
|
||||
Y2R, // Also does camera stuff
|
||||
|
||||
MinServiceHandle = AC,
|
||||
|
@ -86,6 +87,7 @@ namespace KernelHandles {
|
|||
case NIM: return "NIM";
|
||||
case PTM: return "PTM";
|
||||
case SOC: return "SOC";
|
||||
case SSL: return "SSL";
|
||||
case Y2R: return "Y2R";
|
||||
default: return "Unknown";
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace Log {
|
|||
static Logger<false> ndmLogger;
|
||||
static Logger<false> ptmLogger;
|
||||
static Logger<false> socLogger;
|
||||
static Logger<false> sslLogger;
|
||||
static Logger<false> y2rLogger;
|
||||
static Logger<false> srvLogger;
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "services/nim.hpp"
|
||||
#include "services/ptm.hpp"
|
||||
#include "services/soc.hpp"
|
||||
#include "services/ssl.hpp"
|
||||
#include "services/y2r.hpp"
|
||||
|
||||
// More circular dependencies!!
|
||||
|
@ -68,6 +69,7 @@ class ServiceManager {
|
|||
NDMService ndm;
|
||||
PTMService ptm;
|
||||
SOCService soc;
|
||||
SSLService ssl;
|
||||
Y2RService y2r;
|
||||
|
||||
// "srv:" commands
|
||||
|
|
25
include/services/ssl.hpp
Normal file
25
include/services/ssl.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
#include "helpers.hpp"
|
||||
#include "kernel_types.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "memory.hpp"
|
||||
|
||||
#include <random>
|
||||
|
||||
class SSLService {
|
||||
Handle handle = KernelHandles::SSL;
|
||||
Memory& mem;
|
||||
MAKE_LOG_FUNCTION(log, sslLogger)
|
||||
|
||||
std::mt19937 rng; // Use a Mersenne Twister for RNG since this service is supposed to have better rng than just rand()
|
||||
bool initialized;
|
||||
|
||||
// Service commands
|
||||
void initialize(u32 messagePointer);
|
||||
void generateRandomData(u32 messagePointer);
|
||||
|
||||
public:
|
||||
SSLService(Memory& mem) : mem(mem) {}
|
||||
void reset();
|
||||
void handleSyncRequest(u32 messagePointer);
|
||||
};
|
|
@ -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
Reference in a new issue