cpu: lower SGDT, SIDT, SLDT, SMSW, and STR under opt-in host-CPU profile #2057
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2064"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T23:51:46Z.
Change
Add an opt-in
--host-cpu(HOST_CPU) bounded Windows x64 AOT lifter (tools/cpu_sysdesc_aot.py), source-built MASM fixture (tests/cpu/sysdesc.asm,tests/cpu/sysdesc.def), differential verification harness (tests/cpu/sysdesc_check.py), and CTest registration (cpu_aot_sysdescinCMakeLists.txt) covering the five system-descriptor / machine-status store mnemonics indocs/coverage/x64_zen2.tsv(Integer):sgdt m16&64(0F 01 /0): stores 10-byte canonical Windows x64 kernel GDTR (limit+base) without modifying buffer guard bytes[10..15].sidt m16&64(0F 01 /1): stores 10-byte live host IDTR via MSVC__sidt()without modifying guard bytes[10..15].sldt r/m16, r32, r64(0F 00 /0): stores 16-bit LDTR selector (0x0000on Windows x64).str r/m16, r32, r64(0F 00 /1): stores 16-bit TR selector (0x0040,KGDT64_SYS_TSS).smsw r/m16, r32, r64(0F 01 /4): storesCR0[15:0](m16/r16) orCR0[31:0]zero-extended (r32/r64).Key semantics and safety guarantees:
--host-cpu; the default profile rejects every one withValueError.SLDT/STR/SMSWpreserve[63:16]onr16, zero-extend to 64 bits onr32/r64, store exactly 2 bytes onm16, and leaveRFLAGSuntouched.std::atomic_signal_fence(std::memory_order_seq_cst)+volatilewrites so/O2never eliminates or reorders faulting stores.LGDT/LIDT/LLDT/LMSW/LTR), RIP-relative and SIB-indexed addressing, clobbered pointer bases, nonvolatile and high-byte GPRs, non-leaf branches/calls, memory destinations forXOR/ADD, and undefined GPR/flag reads.tests/cpu/sysdesc_check.pyqueriesCPUID.07H:ECX[2](UMIP), pins thread affinity per logical CPU when comparing liveSIDT, and exits cleanly with77(SKIP_RETURN_CODE) if native execution traps (0xC0000096/0xC000001D) or runs on a non-standard host state.Verification
Tested on commit
7fa4a686(rebased ontoupstream/main127f5f80, Windows x64, MSVC 14.50,devDebug andrelease/O2):cmake --build --preset dev --target cpu_sysdesc_original cpu_sysdesc_original_lifted cpu_sysdesc_altered cpu_sysdesc_altered_liftedcmake --build --preset release --target cpu_sysdesc_original cpu_sysdesc_original_lifted cpu_sysdesc_altered cpu_sysdesc_altered_liftedctest --preset dev -R "^cpu_aot_sysdesc$" --output-on-failure -V1/1 Test #636: cpu_aot_sysdesc .................. Passed(rejections passed: 5 default-profile PE + 5 default IR + 6 raw + 26 IR + 8 PE-patched + 3 CLI;sysdesc passed (UMIP_CPUID=1, cpus=[0, 1, 2, 3]): 212 lifted + 212 /O2 cases across 22 exports; ALTER_IMM diverged on ['op_sgdt', 'op_sidt', 'op_sldt_r16', 'op_sldt_m16', 'op_str_r16', 'op_smsw_r16', 'op_sysdesc_flags_preserve']). Capability skips: none (exits77if native traps or host state is non-standard).ctest --preset release -R "^cpu_aot_sysdesc$" --output-on-failure1/1 Test #636: cpu_aot_sysdesc .................. Passed.FORM_COVERAGE_RECORD(out/build/dev/form_coverage/cpu_aot_sysdesc.txtandrelease):add, mov, ret, setb, sete, seto, setp, sets, sgdt, sidt, sldt, smsw, str..\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.pyform coverage checks passed(exit 0)..\out\pe-env\Scripts\python.exe -B tests/docs_links_check.pySelf-test passed. Checked 18 Markdown files and 391 links.(exit 0)..\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.pySelf-test passed. Checked 1411 tracked source, script and build/CI files: no bidirectional controls.(exit 0).Evidence and follow-up
tests/cpu/sysdesc.asmandtests/cpu/sysdesc.defare original, source-built synthetic MASM test fixtures under the repository MIT license; no external binaries or game files are used.--host-cpu), 6 raw excluded-encoding checks, 26 IR rejections (including privilegedLGDT/LIDT/LLDT/LMSW/LTR), 8 PE-patched rejections, 3 CLI non-traceback / zero-leftover-file checks, 7ALTER_IMMmutant exports verifying divergence, andNULL-pointer store-fault checks under/O2.SGDT,SLDT,STR, andSMSWmodel standard Windows x64 user-mode host state whileSIDTqueries live__sidt(); hosts where UMIP traps native user-mode execution or host state differs skip cleanly with exit code77.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:49:23Z.
Review: COMMENTED
Review of head
7fa4a686627b723506f100e1991c169870b2acde(SGDT/SIDT/SLDT/SMSW/STR under opt-in host-CPU profile).Commands executed:
git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.gh pr checks 2064: Linux Python, Windows build/test, gfx1013 fixtures pass.git diff --check origin/main...HEAD: clean.python3 tests/bidi_controls_check.py: pass.python3 tests/docs_links_check.py: pass.python3 -B tests/cpu/sysdesc_check.pyon Linux: cannot run,iced_x86is not installed locally (not a PR defect).python3 x2w_pipe.py win2025 2064 --wait 900(Win2025, MSVC 14.44): Debugcpu_aot_sysdesc1/1 passed; Release /O2cpu_aot_sysdesc1/1 passed.tools/cpu_sysdesc_aot.pychanged the SMSW helper constant0x80050033uto0x80050031u, ran on Win2025 via patch:cpu_aot_sysdescFAILED (killed). Reverted withgit checkout -- ..Findings:
tests/cpu/sysdesc_check.py:362-383: the native-vs-lifted comparison exits 77 (skip) when the host SLDT/STR/SMSW values differ from the hard-coded0x0000/0x0040/0x80050033, or when UMIP traps. On such hosts the whole test silently skips, including the lifted-only checks. Consider running the lifted and rejection checks before the skip, and skipping only the native comparison.tools/cpu_sysdesc_aot.py:222-252: SGDT, SLDT, STR and SMSW return canned Windows x64 constants, while SIDT reads the live host IDTR. This is documented in the module docstring, but the mixed model (canned vs live) is worth a note in docs for whoever enables--host-cpu.No blocking issues found.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:11:43Z.
APPROVED. Opt-in host-CPU profile for SGDT/SIDT/SLDT/SMSW/STR AOT lifter. Solid system descriptor extension.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:23:51Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
6f79651886b34b52f1f398d5e0081efcf6c74c01:--preset dev):cmake --build --preset dev --target cpu_sysdesc_altered cpu_sysdesc_altered_lifted cpu_sysdesc_original cpu_sysdesc_original_lifted -- -j 2):3.17s(configure1.65s)ctest --preset dev -R '^cpu_aot_sysdesc$' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (1.31s:cpu_aot_sysdesc1.21s)/O2(--preset release):cmake --build --preset release --target cpu_sysdesc_altered cpu_sysdesc_altered_lifted cpu_sysdesc_original cpu_sysdesc_original_lifted -- -j 2):1.32s(configure1.64s)ctest --preset release -R '^cpu_aot_sysdesc$' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (1.23s:cpu_aot_sysdesc1.14s)sccache: 4/4 hits; wall15.1sAI-assisted; commands listed were executed locally.
upstream-sync referenced this pull request2026-11-26 00:00:47 +00:00