From 543a435b9f526580e51a336c74a4f8e5551b62ab Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 2 Jan 2026 21:35:12 -0800 Subject: [PATCH] unittests/ASM: Adds test for flags clobber in `TelemetrySetValue` Showcases the bug that #5192 fixed. This would have failed prior to that PR's change. --- .../32Bit_ASM/FEX_bugs/TelemetryFlags.asm | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 unittests/32Bit_ASM/FEX_bugs/TelemetryFlags.asm diff --git a/unittests/32Bit_ASM/FEX_bugs/TelemetryFlags.asm b/unittests/32Bit_ASM/FEX_bugs/TelemetryFlags.asm new file mode 100644 index 000000000..cdc7ba29e --- /dev/null +++ b/unittests/32Bit_ASM/FEX_bugs/TelemetryFlags.asm @@ -0,0 +1,38 @@ +%ifdef CONFIG +{ + "RegData": { + "RAX": "0x0000000000011000", + "RCX": "0x0000000051529654", + "RDX": "0x0000000061626303" + }, + "Mode": "32BIT" +} +%endif + +; FEX-Emu had a bug with its `TelemetrySetValue` IR operation where it would corrupt host flags at an inopportune time. +; The IR operation does `cmp+cset`, but even with `ImplicitFlagClobber` set, this happened at a invalid time for flag handling. +; To test this: +; - btr -> Sets CF +; - adc with `ss:` -> Adds to register with carry, but `ss:` causes `TelemetrySetValue`. +; - Host flags are corrupted after the `TelemetrySetValue`, before the `adc` was able to operate. + +mov ecx, 0x51525354 +mov edx, 0x61626303 + +lea eax, [.data] +lea esp, [.data_flags] +popf + +and word [eax], dx +btr cx, dx +adc cx, ss:[eax] + +hlt + +align 4096 + +.data: +dd 0x41424344 + +.data_flags: +dd 0xfeff