feat(libkernel): stop at start-up on a host CPU without the PS5's extensions #5705

Merged
oneandonlydean merged 1 commit from upstream-pr/5705 into main 2026-10-14 07:47:35 +00:00
oneandonlydean commented 2026-10-14 07:30:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T07:30:59Z.


What

Addresses #3719. Titles run natively, so a host CPU that lacks an extension the PS5's Zen 2 has stops with an illegal instruction somewhere inside the title; in #3719 that is shlx (BMI2) in the title's libc, and the log does not say why.

libkernel now reads CPUID (leaves 1, 7, 0xD.1, 0x80000001, 0x80000008) and XCR0 when it loads on a Linux or Windows x86-64 host, logs which of the Zen 2 user-mode extensions the host has, and throws before any title code runs if one is missing that compiled code uses without checking, naming the host CPU and the missing extensions:

The host CPU (<brand string>) lacks BMI2. The PS5's Zen 2 CPU has these extensions and titles run their instructions natively, so this CPU cannot run them.

Required: the extensions LLVM selects from plain C/C++ for -march=znver2 (LLVM's Zen 2 feature list): SSE to SSE4.2, SSSE3, POPCNT, LZCNT, BMI1, BMI2, MOVBE, CMPXCHG16B, LAHF/SAHF, AVX, AVX2, FMA, F16C, plus the OS's AVX state in XCR0. Logged only: SSE4A, CLZERO and SHA (--to-intel converts them) and the extensions compilers emit only for intrinsics or explicit prefetches (AES, PCLMULQDQ, RDRAND, RDSEED, ADX, CLFLUSHOPT, CLWB, RDPID, XSAVEOPT, XSAVEC, PREFETCHW). macOS is not checked: Rosetta runs AVX2, FMA, BMI1/2, F16C and MOVBE without reporting them through CPUID. Both limits are in TechnicalDebt.

The CPUID brand-string reader moves from SystemConfiguration.cpp (hw.model) to HostCpu.cpp and is shared.

Tested

Linux, GCC, i9-14900KF:

  • host_cpu (new) feeds fake CPUID/XCR0 values to the comparison: a Zen 2 set and an AVX2 Intel set without the AMD-only and intrinsic-only extensions pass; clearing any one required bit (BMI2, BMI1, AVX2, MOVBE, FMA, F16C, POPCNT, SSE4.2, CMPXCHG16B, LZCNT, LAHF/SAHF) reports exactly that one; an AVX-only host reports LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA; XCR0 without YMM state or OSXSAVE clear reports the OS AVX state; the error names the CPU (trailing brand padding trimmed, empty brand as "unknown model").
  • Full build with tests, ctest: 1107/1107 passed (the start-up line appears in every libkernel test's output).
  • Dreaming Sarah (PPSA02929) starts and renders as before; the first log line is host CPU Intel(R) Core(TM) i9-14900KF: has SSE, ..., OS AVX state (XCR0); lacks SSE4A, CLZERO.
  • Windows is built only by CI here.
  • python tools/check_conventions.py --base origin/main passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4854497448 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5705). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T07:30:59Z. --- ### What Addresses #3719. Titles run natively, so a host CPU that lacks an extension the PS5's Zen 2 has stops with an illegal instruction somewhere inside the title; in #3719 that is `shlx` (BMI2) in the title's libc, and the log does not say why. libkernel now reads CPUID (leaves 1, 7, 0xD.1, 0x80000001, 0x80000008) and XCR0 when it loads on a Linux or Windows x86-64 host, logs which of the Zen 2 user-mode extensions the host has, and throws before any title code runs if one is missing that compiled code uses without checking, naming the host CPU and the missing extensions: ```text The host CPU (<brand string>) lacks BMI2. The PS5's Zen 2 CPU has these extensions and titles run their instructions natively, so this CPU cannot run them. ``` Required: the extensions LLVM selects from plain C/C++ for `-march=znver2` ([LLVM's Zen 2 feature list](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.7/llvm/lib/Target/X86/X86.td#L1459-L1513)): SSE to SSE4.2, SSSE3, POPCNT, LZCNT, BMI1, BMI2, MOVBE, CMPXCHG16B, LAHF/SAHF, AVX, AVX2, FMA, F16C, plus the OS's AVX state in XCR0. Logged only: SSE4A, CLZERO and SHA (`--to-intel` converts them) and the extensions compilers emit only for intrinsics or explicit prefetches (AES, PCLMULQDQ, RDRAND, RDSEED, ADX, CLFLUSHOPT, CLWB, RDPID, XSAVEOPT, XSAVEC, PREFETCHW). macOS is not checked: Rosetta runs AVX2, FMA, BMI1/2, F16C and MOVBE without reporting them through CPUID. Both limits are in TechnicalDebt. The CPUID brand-string reader moves from `SystemConfiguration.cpp` (hw.model) to `HostCpu.cpp` and is shared. ### Tested Linux, GCC, i9-14900KF: - `host_cpu` (new) feeds fake CPUID/XCR0 values to the comparison: a Zen 2 set and an AVX2 Intel set without the AMD-only and intrinsic-only extensions pass; clearing any one required bit (BMI2, BMI1, AVX2, MOVBE, FMA, F16C, POPCNT, SSE4.2, CMPXCHG16B, LZCNT, LAHF/SAHF) reports exactly that one; an AVX-only host reports LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA; XCR0 without YMM state or OSXSAVE clear reports the OS AVX state; the error names the CPU (trailing brand padding trimmed, empty brand as "unknown model"). - Full build with tests, `ctest`: 1107/1107 passed (the start-up line appears in every libkernel test's output). - Dreaming Sarah (PPSA02929) starts and renders as before; the first log line is `host CPU Intel(R) Core(TM) i9-14900KF: has SSE, ..., OS AVX state (XCR0); lacks SSE4A, CLZERO`. - Windows is built only by CI here. - `python tools/check_conventions.py --base origin/main` passed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5705
No description provided.