Merge pull request #22715 from hrydgard/vsh-xmb-fixes

VSH: Saved Data Utility, returning to the XMB, and network connection screen
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2026-10-21 19:39:31 +02:00
commit f8268508f1
11 files changed
+160 -6

No files matched your search

+1
View File
@@ -381,6 +381,7 @@ enum PSPErrorCode : u32 {
SCE_ERROR_UMD_NOT_READY = 0x80210001,
SCE_ERROR_MEMSTICK_DEVCTL_BAD_PARAMS = 0x80220081,
SCE_ERROR_MSSTOR_BAD_PARAMS = 0x80220183, // msstor.prx's ioctls, for a bad output buffer
SCE_ERROR_MEMSTICK_DEVCTL_TOO_MANY_CALLBACKS = 0x80220082,
SCE_ERROR_PGD_INVALID_HEADER = 0x80510204,
+1
View File
@@ -438,6 +438,7 @@ void RegisterAllModules() {
Register_InitForKernel();
Register_PopsBootCalls();
Register_sceVaudio_driver();
Register_sceNetApctl_lib();
// Not ready to enable this due to apparent softlocks in Patapon 3.
// Register_sceNpMatching2();
+5 -2
View File
@@ -226,7 +226,9 @@ static int sceSdGetLastIndex(u32 addressCtx, u32 addressHash, u32 addressKey) {
u8 *hash = Memory::GetPointerWriteOrException(addressHash);
if (!ctx.IsValid() || !hash)
return hleLogError(Log::sceMisc, 0, "Invalid pointer");
return hleLogDebug(Log::sceMisc, sceSdMacFinal(*ctx, hash, Memory::GetPointerWriteOrException(addressKey)));
// The key is optional: the VSH's Saved Data Utility checks PARAM.SFO hashes with none.
const u8 *key = addressKey ? Memory::GetPointerWriteOrException(addressKey) : nullptr;
return hleLogDebug(Log::sceMisc, sceSdMacFinal(*ctx, hash, key));
}
int sceSdMacFinal(pspChnnlsvContext1& ctx, u8* in_hash, const u8* in_key)
@@ -402,7 +404,8 @@ int sceSdMacUpdate(pspChnnlsvContext1& ctx, const u8* data, int length)
static int sceSdCreateList(u32 ctx2Addr, int mode, int unkwn, u32 dataAddr, u32 cryptkeyAddr) {
auto ctx2 = PSPPointer<pspChnnlsvContext2>::Create(ctx2Addr);
u8* data = Memory::GetPointerWriteOrException(dataAddr);
u8* cryptkey = Memory::GetPointerWriteOrException(cryptkeyAddr);
// Optional, as in sceSdGetLastIndex.
u8* cryptkey = cryptkeyAddr ? Memory::GetPointerWriteOrException(cryptkeyAddr) : nullptr;
if (!ctx2.IsValid() || !data)
return hleLogError(Log::sceMisc, 0, "Invalid pointer");
+52
View File
@@ -1622,6 +1622,15 @@ static FileNode *__IoOpen(int &error, const char *filename, int flags, int mode)
info.access = 0777;
info.exists = true;
isTTY = true;
} else if (startsWithNoCase(filename, "msstor")) {
// The memory stick's raw block device. Nothing reads through it yet: the VSH's Saved Data
// Utility opens it only to ask (sceIoIoctl 0x02125008/9) whether a stick is in and writable,
// so a node with nothing behind it does, as for tty0:.
info.name = filename;
info.access = 0777;
info.exists = true;
isTTY = true;
} else {
h = pspFileSystem.OpenFile(filename, (FileAccess)(access | (int)FileAccess::FILEACCESS_PPSSPP_QUIET));
@@ -1695,13 +1704,23 @@ static u32 sceIoOpen(const char *filename, int flags, int mode) {
// These are fast to open, no delay or even rescheduling happens.
return hleLogDebug(Log::sceIo, id);
}
if (startsWithNoCase(filename, "msstor")) {
// Nor does the memory stick's raw device (pspautotests io/msstor/msstor).
return hleLogDebug(Log::sceIo, id);
}
return hleDelayResult(hleLogDebug(Log::sceIo, id), "file opened", __IoOpenDelayUs(filename));
}
}
static u32 sceIoClose(int id) {
u32 error;
// Closing the memory stick's raw device doesn't reschedule (pspautotests io/msstor/msstor).
FileNode *f = __IoGetFd(id, error);
const bool rawMemstick = f && startsWithNoCase(f->fullpath, "msstor");
__IoFreeFd(id, error);
if (rawMemstick) {
return hleLogDebug(Log::sceIo, error);
}
// Timing is not accurate, aiming low for now.
return hleDelayResult(hleLogDebug(Log::sceIo, error), "file closed", 100);
}
@@ -1749,6 +1768,22 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
DEBUG_LOG(Log::sceIo,"sceIoDevctl(\"%s\", %08x, %08x, %i, %08x, %i)", name, cmd, argAddr, argLen, outPtr, outLen);
}
// The memory stick's raw device (see sceIoIoctl). 0x02125802 is the stick's type code, from
// msstor.prx's devctl handler (6.61, 08002988): a PSP with its stick answers 0x40 (pspautotests
// io/msstor/msstor), which the VSH's Saved Data Utility checks against 0x11 and 0x41.
// 0x02125801 copies 5 bytes of the stick's state (08002920), which we don't know; only its size
// check is here.
if (startsWithNoCase(name, "msstor") && cmd == 0x02125801 && (!Memory::IsValidRange(outPtr, 5) || outLen < 5)) {
return hleLogError(Log::sceIo, SCE_ERROR_MSSTOR_BAD_PARAMS, "bad output buffer");
}
if (startsWithNoCase(name, "msstor") && cmd == 0x02125802) {
if (!Memory::IsValidRange(outPtr, 4) || outLen < 4) {
return hleLogError(Log::sceIo, SCE_ERROR_MSSTOR_BAD_PARAMS, "bad output buffer");
}
Memory::WriteUnchecked_U32(0x40, outPtr);
return hleLogDebug(Log::sceIo, 0, "stick type 40");
}
// UMD checks
switch (cmd) {
case 0x01E18030:
@@ -2955,6 +2990,23 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
}
break;
// The memory stick's raw device, from msstor.prx's ioctl handler (6.61, 08001620). Both read the
// same two state words: 0x02125008 gives 1 when a medium is in and the second isn't 1, and
// 0x02125009 gives 1 when it is (write protected, as far as we can tell). A Memory Stick Duo has
// no lock switch, so: in, and writable.
case 0x02125008:
case 0x02125009:
// It only reads the driver's state, without rescheduling (pspautotests io/msstor/msstor).
usec = 0;
if (!startsWithNoCase(f->fullpath, "msstor")) {
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_FUNCTION_NOT_SUPPORTED, "msstor ioctl on %s", f->fullpath.c_str());
}
if (!Memory::IsValidRange(outdataPtr, 4) || outlen < 4) {
return SCE_ERROR_MSSTOR_BAD_PARAMS;
}
Memory::WriteUnchecked_U32(cmd == 0x02125008 ? 1 : 0, outdataPtr);
return 0;
default:
{
int result = pspFileSystem.Ioctl(f->handle, cmd, indataPtr, inlen, outdataPtr, outlen, usec);
+8
View File
@@ -355,6 +355,10 @@ std::string __KernelStateSummary() {
void sceKernelExitGame() {
INFO_LOG(Log::sceKernel, "sceKernelExitGame");
if (__KernelExitToVSH(currentMIPS)) {
hleNoLogVoid();
return;
}
__KernelSwitchOffThread("game exited");
Core_Stop();
@@ -365,6 +369,10 @@ void sceKernelExitGame() {
void sceKernelExitGameWithStatus()
{
INFO_LOG(Log::sceKernel, "sceKernelExitGameWithStatus");
if (__KernelExitToVSH(currentMIPS)) {
hleNoLogVoid();
return;
}
__KernelSwitchOffThread("game exited");
Core_Stop();
+58 -3
View File
@@ -541,6 +541,9 @@ u32 KernelFindModuleImport(const char *moduleName, const char *libraryName, u32
// Set once we've seen a PSP_MODULE_VSH_MODE module load (i.e. we're booting the VSH rather
// than a game), and reset on the next __KernelLoadExec. See ShouldHLEModuleForLoad below.
static bool g_runningVSH = false;
// What the XMB passed as vshmain args when it launched the running game, to hand back on exit.
// Survives the kernel reset that LoadExec does, so it isn't cleared with the rest of this file's state.
static std::vector<u8> g_vshmainArgs;
bool __KernelIsRunningVSH() {
return g_runningVSH;
@@ -2471,7 +2474,7 @@ void __KernelLoadReset() {
// Shared by __KernelLoadExec (loading from a file) and __KernelLoadExecFromBuffer (loading
// from a buffer already in RAM, as used by the VSH's USB/WLAN game-push feature) - everything
// past the point where we have the executable's bytes in hand.
static bool __KernelLoadExecFromPtr(MIPSState * mips, const u8 *data, size_t size, const char *filename, u32 paramPtr, std::string *error_string) {
static bool __KernelLoadExecFromPtr(MIPSState * mips, const u8 *data, size_t size, const char *filename, u32 paramPtr, std::string *error_string, const std::vector<u8> *hostArgs = nullptr) {
SceKernelLoadExecParam param{};
auto paramData = PSPPointer<SceKernelLoadExecParam>::Create(paramPtr);
@@ -2482,7 +2485,11 @@ static bool __KernelLoadExecFromPtr(MIPSState * mips, const u8 *data, size_t siz
u8 *param_argp = nullptr;
u8 *param_key = nullptr;
if (param.args > 0) {
if (hostArgs) {
param.args = (u32)hostArgs->size();
param_argp = new u8[param.args];
memcpy(param_argp, hostArgs->data(), param.args);
} else if (param.args > 0) {
u32 argpAddr = param.argp;
param_argp = new u8[param.args];
Memory::Memcpy(param_argp, argpAddr, param.args, "KernelLoadParam");
@@ -2547,7 +2554,7 @@ static bool __KernelLoadExecFromPtr(MIPSState * mips, const u8 *data, size_t siz
}
INFO_LOG(Log::System, "Starting modules...");
if (paramPtr)
if (paramPtr || hostArgs)
__KernelStartModule(module, param.args, (const char*)param_argp, &option);
else
__KernelStartModule(module, (u32)strlen(filename) + 1, filename, &option);
@@ -2667,8 +2674,23 @@ int sceKernelLoadExec(MIPSState *mips, const char *filename, u32 paramPtr) {
}
DEBUG_LOG(Log::sceModule, "sceKernelLoadExec(name=%s,...): loading %s", filename, exec_filename.c_str());
if (g_runningVSH) {
// The XMB launching something: keep its vshmain args for when it comes back.
g_vshmainArgs.clear();
auto vshParam = PSPPointer<SceKernelLoadExecVSHParam>::Create(paramPtr);
if (vshParam.IsValid() && vshParam->size >= offsetof(SceKernelLoadExecVSHParam, vshmainArgs) + 4 &&
vshParam->vshmainArgsSize != 0 && Memory::IsValidRange(vshParam->vshmainArgs, vshParam->vshmainArgsSize)) {
const u8 *args = Memory::GetPointerUnchecked(vshParam->vshmainArgs);
g_vshmainArgs.assign(args, args + vshParam->vshmainArgsSize);
}
INFO_LOG(Log::sceModule, "Keeping %d bytes of vshmain args", (int)g_vshmainArgs.size());
}
std::string error_string;
if (!__KernelLoadExec(mips, exec_filename.c_str(), paramPtr, &error_string)) {
// The old program is gone by now. A game the XMB couldn't start goes back to the XMB.
if (__KernelExitToVSH(mips)) {
return hleLogError(Log::sceModule, 0, "failed: %s, back to the VSH", error_string.c_str());
}
Core_HLEError("sceKernelLoadExec failed: " + error_string);
return hleLogError(Log::sceModule, -1, "failed: %s", error_string.c_str());;
}
@@ -2678,6 +2700,39 @@ int sceKernelLoadExec(MIPSState *mips, const char *filename, u32 paramPtr) {
return hleLogDebug(Log::sceModule, 0);
}
bool __KernelExitToVSH(MIPSState *mips) {
// A session that started in the XMB, running a game it launched. The XMB itself exiting (power
// off) still ends the session.
if (PSP_CoreParameter().fileToStart.GetFilename() != "vshmain.prx" || g_runningVSH) {
return false;
}
std::string error_string;
const char *vshmain = "flash0:/vsh/module/vshmain.prx";
std::vector<uint8_t> fileData;
if (pspFileSystem.ReadEntireFile(vshmain, fileData) < 0) {
ERROR_LOG(Log::sceModule, "Couldn't return to the VSH: no %s", vshmain);
return false;
}
// Its args from when it launched the game tell it that it's coming back (and not to auto-start
// the disc in the drive, say). vshmain's module_start only takes them (copying them into its
// state) when they're 0x20 or 0x400 bytes and start with that size and then 0x20, which it
// doesn't write itself.
std::vector<u8> args = g_vshmainArgs;
if (args.size() >= 8) {
u32 header[2] = { (u32)args.size(), 0x20 };
memcpy(args.data(), header, sizeof(header));
}
INFO_LOG(Log::sceModule, "Back to the VSH with %d bytes of vshmain args", (int)args.size());
if (!__KernelLoadExecFromPtr(mips, fileData.data(), fileData.size(), vshmain, 0, &error_string, args.empty() ? nullptr : &args)) {
ERROR_LOG(Log::sceModule, "Couldn't return to the VSH: %s", error_string.c_str());
return false;
}
if (gpu) {
gpu->Reinitialize();
}
return true;
}
static u32 KernelLoadModuleFromData(const char *name, std::vector<uint8_t> &fileData, u32 flags, const SceKernelLMOption *lmoption, bool *tryLoadExec, const u8 *secureId = nullptr, const u32 *fuseId = nullptr);
// What sceKernelLoadModule does once the file has been read: decrypt the module, place it in memory
+3
View File
@@ -244,6 +244,9 @@ bool __KernelLoadGEDump(MIPSState *mips, std::string_view base_filename, std::st
bool __KernelLoadExec(MIPSState *mips, const char *filename, u32 paramPtr, std::string *error_string);
// The VSH (the XMB) is what's running, not a game it launched.
bool __KernelIsRunningVSH();
// What sceKernelExitGame does in a game the XMB launched, as on a PSP: back to the XMB. False if this
// session didn't start in the XMB.
bool __KernelExitToVSH(MIPSState *mips);
// Exposed so sceVshBridge can reuse it directly for vshKernelLoadModuleBufferVSH, matching JPCSP.
SceUID sceKernelLoadModuleBufferUsbWlan(u32 size, u32 bufPtr, u32 flags, u32 lmoptionPtr);
bool __KernelLoadExecFromBuffer(MIPSState *mips, const u8 *data, size_t size, u32 paramPtr, std::string *error_string);
+14
View File
@@ -1855,6 +1855,16 @@ const HLEFunction sceNetApctl[] = {
{0X756E6F10, &WrapV_V<__NetApctlCallbacks>, "__NetApctlCallbacks", 'v', "" },
};
// The same functions as pspnet_apctl.prx exports them to the VSH (its netconf plugin, which the
// browser and the online manuals start with).
const HLEFunction sceNetApctl_lib[] = {
{0X7CFAB990, &WrapI_UU<sceNetApctlAddInternalHandler>, "sceNetApctlAddInternalHandler", 'i', "xx" },
{0XE11BAFAB, &WrapI_U<sceNetApctlDelInternalHandler>, "sceNetApctlDelInternalHandler", 'i', "x" },
{0XB3CF6849, &WrapI_V<sceNetApctlScan>, "sceNetApctlScan", 'i', "" },
{0X0C7FFA5C, &WrapI_UU<sceNetApctlGetBSSDescIDList>, "sceNetApctlGetBSSDescIDList", 'i', "xx" },
{0X96BEB231, &WrapI_IIU<sceNetApctlGetBSSDescEntry>, "sceNetApctlGetBSSDescEntry", 'i', "iix" },
};
const HLEFunction sceWlanDrv[] = {
{0XD7763699, &WrapU_V<sceWlanGetSwitchState>, "sceWlanGetSwitchState", 'x', "" },
{0X0C622081, &WrapU_U<sceWlanGetEtherAddr>, "sceWlanGetEtherAddr", 'x', "x" },
@@ -1883,6 +1893,10 @@ void Register_sceNetApctl() {
RegisterHLEModule("sceNetApctl", ARRAY_SIZE(sceNetApctl), sceNetApctl);
}
void Register_sceNetApctl_lib() {
RegisterHLEModule("sceNetApctl_lib", ARRAY_SIZE(sceNetApctl_lib), sceNetApctl_lib);
}
void Register_sceWlanDrv() {
RegisterHLEModule("sceWlanDrv", ARRAY_SIZE(sceWlanDrv), sceWlanDrv);
}
+1
View File
@@ -104,6 +104,7 @@ extern const char * const defaultNetSSID;
void Register_sceNet();
void Register_sceNetApctl();
void Register_sceNetApctl_lib();
void Register_sceWlanDrv();
void Register_sceNetUpnp();
void Register_sceNetIfhandle();
+16
View File
@@ -60,6 +60,22 @@ Two separate things:
retried 12 times. Implemented now - PPSSPP has no region-locked discs, so anything it can load is
something it should run - and the call drops to one.
## Around the XMB (6.61)
- **Game**: the memory stick list shows PSP games, PS1 EBOOTs and homebrew with icons and info.
Homebrew and PS1 games launch from it; PSN titles stop at "The copyright protection information
is invalid (8010850E)", since there's no licence (`PSP/LICENSE/*.RIF`). A game that exits goes
back to the XMB, as on a PSP. The Saved Data Utility lists saves: it needed the raw stick device
`msstor0p1:/` (pspautotests `io/msstor/msstor`) and `sceSdGetLastIndex` without a key.
- **Photo**: folders under `PICTURE/` list with thumbnails, and JPEG and PNG open full screen (R
for the next one).
- **Music**: MP3 plays. SensMe stops at 8002013A.
- **Settings**: the menus open. System Information shows "-" for the MAC address: wlan.prx reads it
from IdStorage key 0x44, and IdStorage is left failing on purpose (see below).
- **Network**: the browser and the online manuals reach their Network Connection screen once
`sceNetApctl_lib` is there, then stop at 8002013A on `sceHttp` functions only the NetFront browser
uses (06488A1C, 2C3C82CF, 3A67F306, 739C2D79, 77EE5319, 8046E250, A461A167, B0257723).
## Current status
`--vsh` boots VSH and renders real XMB frames. Measured on the GE command stream after 25