upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/main.cpp
diff options
context:
space:
mode:
authorKrashgamer <64923888+Krashgamer@users.noreply.github.com>2026-11-23 16:56:57 +0100
committerKrashgamer <64923888+Krashgamer@users.noreply.github.com>2026-11-23 16:57:59 +0100
commit62b410e75640c12a672f73552c754ca7945bf265 (patch)
treebb9c5a5dbe95cab58be91d000de7c8d0bf5527ba /runtime/src/main.cpp
parent2f9e1e3e3c32892a6145ac9f526b73274da7d040 (diff)
gta6rt: emulate the Zen 2 instructions a desktop CPU may lack (INSERTQ/EXTRQ, CLZERO, MONITORX/MWAITX, CLWB)
The executable uses SSE4a INSERTQ, CLZERO and MONITORX/MWAITX (AMD only) and CLWB (Intel since Ice Lake) without asking CPUID (docs/cpu_features.md). A host without one raises #UD there. src/cpu_emulation.h adds a vectored handler that recognises those encodings at the faulting RIP, does the same work on the CONTEXT and steps past the instruction; gta6rt installs it before any image code runs, after the startup trace's handler so it runs first. One [rt] line names what the host lacks, one more per instruction on first use. cpu_emulation_test checks the decoder on hand-written encodings, the bit-field helpers and apply() on a synthetic CONTEXT, then runs every form for real from an executable buffer: natively on a Zen host, through the handler on an Intel one, with the same expected values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
-rw-r--r--runtime/src/main.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp
index b75baf15f..5a9f7c76f 100644
--- a/runtime/src/main.cpp
+++ b/runtime/src/main.cpp
@@ -28,6 +28,7 @@
28 28
29#include "base_reservation.h" 29#include "base_reservation.h"
30#include "code_hooks.h" 30#include "code_hooks.h"
31#include "cpu_emulation.h"
31#include "mods.h" 32#include "mods.h"
32#include "pe_loader.h" 33#include "pe_loader.h"
33#include "../shims/d3d12_trace.h" 34#include "../shims/d3d12_trace.h"
@@ -151,6 +152,15 @@ int wmain(int argc, wchar_t** argv) {
151 : "error: cannot create the trace file\n"); 152 : "error: cannot create the trace file\n");
152 return 2; 153 return 2;
153 } 154 }
155 // The console's Zen 2 instructions this CPU may lack (docs/cpu_features.md): emulated on #UD. Installed after the
156 // trace's handler so it runs first, and an emulated instruction is not recorded as an exception.
157 if (const auto host = rt::cpu_emulation::detect_host(); !host.sse4a || !host.clzero || !host.monitorx || !host.clwb)
158 std::fprintf(stderr, "[rt] cpu: this CPU lacks%s%s%s%s; the game's uses are emulated (docs/cpu_features.md)\n",
159 host.sse4a ? "" : " SSE4a", host.clzero ? "" : " CLZERO", host.monitorx ? "" : " MONITORX",
160 host.clwb ? "" : " CLWB");
161 if (!rt::cpu_emulation::install())
162 std::fprintf(stderr, "[rt] cpu: AddVectoredExceptionHandler failed (error %lu); instructions this CPU lacks "
163 "will stop the game\n", GetLastError());
154 164
155 try { 165 try {
156 rt::Loader loader(game_dir); 166 rt::Loader loader(game_dir);