Commit Graph
195 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 6110a27b73 sceVideocodec: one layout helper for the eight frame buffers
Four places were each computing the same sizes and 64-byte-aligned offsets:
the allocation, the recovery sceMpegbase uses, and the readers on both sides.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-12 12:53:13 -06:00
Henrik RydgårdandClaude Opus 5 4df01fd990 sceUtility: load the firmware's module for a disabled HLE library
Doing this was written once, for sceMp4, remembering the two UIDs it had
loaded in a static. That static was the only thing stopping a second copy
being loaded on top of the first, and it didn't survive a savestate: resuming
in a fresh process left it at zero while the restored module list already had
the modules in it. Ask the module list instead, which needs no state of its
own and is right after a savestate load and across games.

With the mechanism shared, sceMp3 and sceAtrac get it too. libmp3.prx and
libatrac3plus.prx each import nothing but the kernel and sceAudiocodec, so
both run against what we already have. The sceAtrac checkbox previously led
to an error log and a debug assert saying it wouldn't work, with a note that
we could go and find the file - which is what this does.

This is only ever the path for a game that ships no copy of the library. One
that does loads it directly and never asks sceUtility for it.

Also:
 - a module we're really loading no longer reserves its stand-in block as
   well. That block only stands in for memory we aren't otherwise taking, so
   reserving both charges the game twice, at the top of user memory where
   thread stacks come from.
 - the module loads at the bottom of the user partition. fromTop is for a
   module injected before the game's executable is placed; by the time a game
   calls sceUtility nothing moves either way, and the firmware's utility.prx
   allocates AV module memory as PSP_SMEM_Low.
 - NotifyLoadStatusAtrac read the raw setting rather than the effective
   flags, so it could fire for a flag that wasn't in effect.
 - the missing-firmware case now says so on screen, naming the library and
   pointing at installing a firmware, rather than only logging.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-12 11:11:41 -06:00
Henrik Rydgård b693490ced De-claude some comments 2026-09-11 21:24:18 -06:00
Henrik RydgårdandClaude Opus 5 039ffc682d HLE: graduate the leaf libraries games carry on the disc
A survey of disc images found these shipped on a lot of them: LIBDEFLT and
LIBMT19937, LIBADLER, LIBMD5 on about 1/6, LIBSHA256 on 1/7, LIBHEAP on
1/12, LIBSFMT19937 on 1/24. None appears in any firmware dump and none is loadable
through sceUtility, so a game that imports one has to carry it - which makes
running the game's own module the safe default, the same argument psmfplayer
graduated on. Read off real discs with --re-module disc0:/..., all but sceHeap
import nothing at all, and sceHeap only Kernel_Library and ThreadManForUser.

sceFont joins them with a condition. Its module is on the disc like the others -
the most-shipped of all, on a third of the discs - but it reads its fonts from
flash0:/font and has nothing to fall back on, so it is only usable with a
firmware dump installed (our own fallback fonts are just not good enough anyway, it
chokes on them). CheckDisableHLEAvailability puts the HLE back when
those fonts are missing, since ours does have a fallback.

sceParseUri and sceParseHttp look like candidates and aren't: they are in the
firmware and sceUtility can load them, so a game may import them without
shipping one. Their headers say so.

The HLE implementations stay - old savestates index these tables by syscall
opcode - and are marked legacy the way scePsmf is.

Also: Move HLEInit after the filesystems are mounted

It ran before MountFileSystems, so the checks in it deciding whether a library
can run its real module instead of our HLE couldn't ask the PSP filesystem and
had to reach for host paths under the NAND directory. Nothing between
CoreTiming::Init and here touches HLE, and the kernel and the game's modules are
both loaded later, so it can simply move.

Two things fall out. The checks now spell their paths flash0:/... like the rest
of the emulator. And they run after AutoInstallFirmwareFromDisc, so a disc that
carries a firmware counts on the launch that installs it rather than the next
one - verified with an empty NAND and a disc carrying 3.11: the fonts land and
sceFont runs the game's own module the same boot.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-11 21:09:33 -06:00
Henrik RydgårdandClaude Opus 5 386ff2fc3d headless: add --re-module, a static reverse-engineering dump for one PRX
Loads a single module standalone - no game, no boot - and writes a report:
module header and segments, the export and import tables with NIDs resolved to
names through the HLE tables, one annotated disassembly file per function, and
a call graph as JSON.

Reuses the emulator's own loader rather than parsing PRXes a second time, so
decryption, decompression, relocation and import resolution can't drift from
what actually runs. Only enough of the system is brought up to load a module:
memory map, timing, HLE tables and the kernel allocators. Nothing executes.

Two things beyond a plain disassembly, both aimed at the questions that come up
when reading unfamiliar MIPS:

- lui/addiu (and lui/load) pairs are folded and reported as the address they
  form, which is how every global and constant table gets reached.
- Per function, a register evidence block instead of a guessed signature. A
  MIPS function that takes two arguments and passes the second one down often
  never reads it, so 'never read but live across a call' is reported as
  forwarded rather than quietly dropped from the signature.

SetForceRealModuleLoads() is needed because modules like sceAudiocodec_Driver
have no DisableHLEFlags bit and so can't be turned off the normal way - they'd
fake-load and there would be nothing to look at.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 15:32:14 -06:00
Henrik RydgårdandClaude Opus 5 5a7ca5a6a5 HLE: make the HLE boundary part of the machine state, so savestates survive it
Which modules we HLE is decided when each module is loaded, and the syscall
stubs written into memory then are what a savestate captures. But the setting
was read live, so loading a state re-resolved its imports against whatever the
config said now - and if that disagreed with how the state was made, every call
into the module landed on an unresolved stub returning LIBRARY_NOT_YET_LINKED.
Thrillville just retried sceMpegInit forever.

Latch the flags on first use after boot, save them in the state, and restore
them on load. Changing the setting now takes effect on the next boot, which is
the only point it could have taken effect anyway.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GgACRqkQNpfJQ4fjwyoEup
2026-09-08 11:47:44 -06:00
Henrik RydgårdandClaude Opus 5 c80f3d33c2 Run the real libmp4.prx/mp4msv.prx instead of our sceMp4 HLE, when asked
The MP4 libraries turn out to be the easiest place to hand a game Sony's own
code: libmp4.prx needs only sceAudiocodecInit and sceAudiocodecDecode from us
plus ordinary kernel calls, and mp4msv.prx - where the 41 functions libmp4
leans on live - imports nothing at all. So with a firmware dump present the
pair can be loaded for real and left to decode through our sceAudiocodec.

Adds DisableHLEFlags::sceMp4, which loads and starts both modules when the
game asks sceUtility for the MP4 module, and a --disable-hle bitmask so a
headless run can ask for this without a config file.

Two things had to be fixed to make it work at all:
 - ModuleMgrForUser 0xD2FBC957 was unimplemented, and libmp4 calls it to get
   the gp of each callback it is handed. Implemented as
   sceKernelGetModuleGPByAddress.
 - Headless forced every module to HLE unconditionally, which silently undid
   the flag, and it did so before ApplyToConfig() had even parsed it.

Tested with Speedball 2 - Evolution, which uses sceMp4 for its music: the game
goes from 255645 calls into our stubs and 39 unresolved imports, to zero of
each and 1943 AAC frames decoded through sceAudiocodec.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-08 09:44:26 -06:00
Henrik Rydgård a810597ac0 Implement MMIO for the JIT (by falling back to the interpreter for load/stores from kernel addresses)
Fixes the VSH in JIT mode (but NOT ir)
2026-08-25 00:22:40 +02:00
Henrik Rydgård a0ecf545a6 Implement or stub assorted functions the VSH is calling 2026-08-21 10:56:06 +02:00
Henrik Rydgård 8d0d601b5b Clean up how the instruction cache is invalidated from the breakpoint manager 2026-08-16 18:10:02 +02:00
Henrik Rydgård 67ddf899ba Plumb through the PC value for syscalls, so we can get better diagnostics for unresolved ones. 2026-08-15 19:14:13 +02:00
Henrik Rydgård 2096179dce Drive-by code cleanup 2026-08-15 18:31:20 +02:00
Henrik Rydgård 5ce4cbc18a Fix some function name shenanigans 2026-08-14 14:55:06 +02:00
Henrik Rydgård eb0813c0e3 Add a utility function for all the ABIs to call functions with a pointer arg. Use to call Advance from the JIT with the MIPSContext. Indent some code better. 2026-08-13 08:09:30 +02:00
Henrik Rydgård e9a3449ede More MIPSState * plumbing (manual) 2026-08-12 14:02:19 +02:00
Henrik Rydgård 0596ee97f6 More memory access cleanup 2026-08-11 20:14:01 +02:00
Henrik Rydgård 3c81d6b121 More manual Read_U32 cleanup
Buildfix
2026-08-11 10:28:36 +02:00
Henrik Rydgård 9396030f02 More Read_U32 cleanup 2026-08-11 09:08:52 +02:00
Henrik Rydgård b42157aa49 Core: Add utility function to properly report memory exceptions from HLE functions (when they would actually crash the PSP) 2026-08-10 10:41:32 +02:00
Henrik Rydgård a957086eeb Try to fix test failure (vary strange) 2026-08-08 00:45:11 +02:00
Henrik Rydgård c99a303646 Fix behavior so we can turn off "IgnoreBadMemAccess" in headless 2026-07-29 18:38:25 +02:00
Henrik RydgårdandClaude Sonnet 5 ca34a14fd8 Resolve unresolved-import calls to a module/NID in the "Unknown syscall" log
A call through a still-pending import gets written as a generic "invalid
syscall" opcode (WriteFuncMissingStub) that no longer carries the
original module name or NID by the time it's actually invoked - but the
address of the syscall instruction itself is exactly the stubAddr every
pending FuncSymbolImport already records. Added
KernelFindImportByStubAddr() to search loaded modules' importedFuncs for
a match, and use it in GetSyscallFuncPointer's unknown-syscall path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-25 14:52:19 +02:00
Henrik Rydgård 5f7a937466 Rename ValidSize to ClampValidSizeAt 2025-12-30 20:31:07 +01:00
Nemoumbra c9c74f751c Fixed an out-of-range access crash 2025-08-11 01:15:44 +03:00
Henrik Rydgård 266a6a33be Add workaround for scePsmf LLE not working with Dragon's Lair 2025-06-07 15:05:33 +02:00
Henrik Rydgård 3d8233b7f8 Some sceAudiocodec MP3 work. Not yet working in Beats (trying to DisableHLE of sceMp3). 2025-04-07 10:27:53 +02:00
Henrik Rydgård a870c2155d Always load sceCcc if possible (disable HLE). PRX dumping fix. 2025-04-06 23:34:16 +02:00
Henrik Rydgård b52e7913eb Add disable HLE flag for sceCcc (character conversion library). 2025-04-06 23:34:16 +02:00
Henrik Rydgård 740f885277 Add an escape route from DisableHLE for headless (testing).
May later be turned into developer settings, too.
2025-04-03 21:13:39 +02:00
Henrik Rydgård 96275ec844 Disable HLE of scePsmf and scePsmfPlayer
Testing has shown that this seems to work great and fixes issues. These
two modules are just a parser and a shim over sceMpeg, and we're better
off running the original code, instead of re-implementing it.

sceMpeg still needs accuracy improvements though, and it's built on some
pretty low level components so it will be harder to peel off the next
level of the HLE onion.

Se #20200.
2025-04-03 20:24:03 +02:00
Henrik Rydgård a31d7dc0b3 Add mechanism to "graduate" DisableHLE flags to be permanently on. Will be used soon. 2025-04-03 20:04:42 +02:00
Henrik Rydgård e961c1ed96 Add support for compat flags that control DisableHLE 2025-04-03 20:04:04 +02:00
Henrik Rydgård 62cd4bbefc Minor cleanups and fixes. sceJpeg will not work without HLE, so removed from disable-list. 2025-04-03 18:16:10 +02:00
Henrik Rydgård 343ca2600a Add a developer setting to disable individual HLE modules, allowing them to be loaded properly.
Some games survive with a loaded sceAtrac, and start talking to
sceAudioCodec instead, the underlying library, though unsuccessfully
since it's not properly implemented yet.
2025-04-02 10:19:24 +02:00
Henrik Rydgård 4e25f44eef Rename some module-related functions to include HLE where appropriate 2025-03-31 11:17:50 +02:00
Henrik Rydgård 0ecd72416b Reduce overhead of logging further. 2025-03-25 23:09:11 +01:00
Henrik Rydgård 0f840e6240 Move JPEG error codes to the big enum, some include cleanup 2025-03-21 20:44:46 +01:00
Henrik Rydgård 82728652d8 Move Font and Psmf error codes to the big enum 2025-03-21 20:44:46 +01:00
Henrik Rydgård 31cf5771f4 Turn the break reason into an enum, fix some minor issues 2025-02-19 16:01:11 -06:00
Henrik Rydgård d39655ff17 Second attempt at fixing #19935
Fixes #19935. Forgot to update the formatting for the reporting case.

I'll clean this up in a more general way later, I don't like how this code currently looks.
2025-02-02 20:21:17 -06:00
Henrik Rydgård e53fd10edd Format string fix in hleDoLogInternal
Hopefully fixes #19935, but can't confirm myself right now.
2025-02-02 11:46:08 -06:00
Henrik Rydgård b763cb3f03 Make the auto error logging 32-bit compatible, oops. 2025-01-29 11:08:55 +01:00
Henrik Rydgård b4f0e3dd5c HLE logging: Automatically log SCE_KERNEL_ERRORs as strings for functions returning 'i' and 'x' types. 2025-01-29 10:47:18 +01:00
Henrik Rydgård 2af7a047d2 HLE logging; Use function metadata to decide the type for logging the return type. 2025-01-29 10:14:54 +01:00
Henrik Rydgård 7db68d50bb More hleLog* 2025-01-28 09:31:38 +01:00
Henrik Rydgård eb0102d781 Use more hleLog* functionality to simplify code. 2025-01-28 09:31:34 +01:00
Henrik Rydgård 0f5d9fe753 Paper over the problems of the hlecall stack 2025-01-27 14:13:31 +01:00
Henrik Rydgård 5abb1be440 Some more logging cleanup 2025-01-21 17:33:59 +01:00
Henrik Rydgård 33fbc17e2c Disable the function stacksize sanity checks. 2025-01-20 12:20:21 +01:00
Henrik Rydgård 16dcb9ee8a And more 2025-01-20 12:20:21 +01:00