From 8d6a0134c66b0be4a965771d054f74830c3e6a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 Oct 2026 17:50:04 +0200 Subject: [PATCH 1/6] sceIo: The memory stick's raw device (msstor), for the Saved Data Utility The VSH's Saved Data Utility opens msstor0p1:/ to ask whether a stick is in and writable (ioctls 0x02125008/9) and what type it is (devctl 0x02125802), and gave up quietly when the open failed. msstor paths now open as a node with nothing behind it, answering those as msstor.prx's handlers and a PSP do (pspautotests io/msstor/msstor): in, writable, type 0x40, without rescheduling, and 0x80220183 for a short output buffer. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HLE/ErrorCodes.h | 1 + Core/HLE/sceIo.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ pspautotests | 2 +- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Core/HLE/ErrorCodes.h b/Core/HLE/ErrorCodes.h index b48f5a66b4..35e18fc256 100644 --- a/Core/HLE/ErrorCodes.h +++ b/Core/HLE/ErrorCodes.h @@ -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, diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 693021d959..2c2412790c 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -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); diff --git a/pspautotests b/pspautotests index 8cedd83760..74cdeea078 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit 8cedd83760114df9ab51a1507a1a6cc8d5ecdbeb +Subproject commit 74cdeea078403a9d877b99e28c3cad85ba7f3d7f From cf29cbdfd7e66897c8f7d6dbfe139caf04e59603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 Oct 2026 17:50:04 +0200 Subject: [PATCH 2/6] sceChnnlsv: Allow no key in sceSdGetLastIndex and sceSdCreateList Both took their key through GetPointerWriteOrException, which raises a memory exception for 0, though the code behind them treats a null key as no key. The VSH's Saved Data Utility checks PARAM.SFO hashes without one, and emulation stopped there. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HLE/sceChnnlsv.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceChnnlsv.cpp b/Core/HLE/sceChnnlsv.cpp index 918ca97696..9c704737d5 100644 --- a/Core/HLE/sceChnnlsv.cpp +++ b/Core/HLE/sceChnnlsv.cpp @@ -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::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"); From 9fec7d7fb0f68582f177140fc8025d9def304115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 Oct 2026 17:55:37 +0200 Subject: [PATCH 3/6] VSH: A game launched from the XMB exits back to it On a PSP, sceKernelExitGame in a game the XMB launched goes back to the XMB. Ours ended the session. In a session booted as vshmain.prx, an exit from anything but the VSH itself now LoadExecs vshmain.prx again; the shell then plays its opening and comes back on the Game column. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HLE/sceKernel.cpp | 8 ++++++++ Core/HLE/sceKernelModule.cpp | 17 +++++++++++++++++ Core/HLE/sceKernelModule.h | 3 +++ 3 files changed, 28 insertions(+) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index fc82813739..edfe17bb94 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -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(); diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 411d8e20df..773921cd48 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -2678,6 +2678,23 @@ 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; + if (!__KernelLoadExec(mips, "flash0:/vsh/module/vshmain.prx", 0, &error_string)) { + 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 &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 diff --git a/Core/HLE/sceKernelModule.h b/Core/HLE/sceKernelModule.h index 0490a1aa70..39c6a7547b 100644 --- a/Core/HLE/sceKernelModule.h +++ b/Core/HLE/sceKernelModule.h @@ -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); From 83df04686c3bb46a4d05c3664464e45e0a15b4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 Oct 2026 18:04:11 +0200 Subject: [PATCH 4/6] sceNet: Register sceNetApctl_lib, for the VSH's network connection screen pspnet_apctl.prx exports the internal handler, scan and BSS functions to the VSH under sceNetApctl_lib (as listed by its 6.61 export table). We had them, but only under sceNetApctl, so the XMB's netconf plugin got an unresolved import and the browser and online manuals stopped at 8002013A before their Network Connection screen. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HLE/HLETables.cpp | 1 + Core/HLE/sceNet.cpp | 14 ++++++++++++++ Core/HLE/sceNet.h | 1 + 3 files changed, 16 insertions(+) diff --git a/Core/HLE/HLETables.cpp b/Core/HLE/HLETables.cpp index 20214d49df..d5fea7a970 100644 --- a/Core/HLE/HLETables.cpp +++ b/Core/HLE/HLETables.cpp @@ -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(); diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index ab5907482a..3a5f3b48f6 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -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", 'i', "xx" }, + {0XE11BAFAB, &WrapI_U, "sceNetApctlDelInternalHandler", 'i', "x" }, + {0XB3CF6849, &WrapI_V, "sceNetApctlScan", 'i', "" }, + {0X0C7FFA5C, &WrapI_UU, "sceNetApctlGetBSSDescIDList", 'i', "xx" }, + {0X96BEB231, &WrapI_IIU, "sceNetApctlGetBSSDescEntry", 'i', "iix" }, +}; + const HLEFunction sceWlanDrv[] = { {0XD7763699, &WrapU_V, "sceWlanGetSwitchState", 'x', "" }, {0X0C622081, &WrapU_U, "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); } diff --git a/Core/HLE/sceNet.h b/Core/HLE/sceNet.h index cdaa07e057..8851f219b4 100644 --- a/Core/HLE/sceNet.h +++ b/Core/HLE/sceNet.h @@ -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(); From 6453d7f0b34e2288bcd62ed6a0edc4325e3a5835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 Oct 2026 18:04:11 +0200 Subject: [PATCH 5/6] docs: What works around the XMB Co-Authored-By: Claude Opus 5.5 (1M context) --- docs/VSHBootInvestigation.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/VSHBootInvestigation.md b/docs/VSHBootInvestigation.md index 75e8abd0f0..245c11c8ee 100644 --- a/docs/VSHBootInvestigation.md +++ b/docs/VSHBootInvestigation.md @@ -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 From c4034700fc9ccfba306aaf543ccb47e96836a125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 21 Oct 2026 18:54:14 +0200 Subject: [PATCH 6/6] VSH: Return to the XMB with its own args, and when a launch fails The XMB passes its state as vshmain args (0x400 bytes) when it launches something. We now keep them and start vshmain with them when the game exits, so it comes back where it left off instead of booting fresh: no opening, the launched item selected, and no UMD auto-start. vshmain's module_start only copies them in when they begin with their size and 0x20, which the kernel has to fill in. A launch that fails to load (like the Video Demo Disc's game part, whose EBOOT.BIN is 2384 zero bytes) now goes back to the XMB too, instead of stopping emulation. Before the args were handed back, this looped: the fresh XMB auto-started the disc again. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/HLE/sceKernelModule.cpp | 46 ++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 773921cd48..a75b5723f7 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -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 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 *hostArgs = nullptr) { SceKernelLoadExecParam param{}; auto paramData = PSPPointer::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::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());; } @@ -2685,7 +2707,23 @@ bool __KernelExitToVSH(MIPSState *mips) { return false; } std::string error_string; - if (!__KernelLoadExec(mips, "flash0:/vsh/module/vshmain.prx", 0, &error_string)) { + const char *vshmain = "flash0:/vsh/module/vshmain.prx"; + std::vector 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 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; }