Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpcodeDispatcher: Mark CF as being possibly set after inverting #4163

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FEXCore/Source/Interface/Core/OpcodeDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,7 @@ class OpDispatchBuilder final : public IREmitter {
}

CFInverted ^= true;
PossiblySetNZCVBits |= 1u << IndexNZCV(FEXCore::X86State::RFLAG_CF_RAW_LOC);
}

LOGMAN_THROW_AA_FMT(CFInverted == RequiredInvert, "post condition");
Expand Down
27 changes: 27 additions & 0 deletions unittests/32Bit_ASM/FEX_bugs/InvertedCarrySet.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%ifdef CONFIG
{
"RegData": {
"RAX": "1"
},
"Mode": "32BIT"
}
%endif

; FEX had a bug where inverting CF to match the ABI when flushing the register cache didn't mark CF as possibly being set.
; This caused accesses relying on that flag to be set correctly to return wrong values.

mov esp, 0xe0000020
mov al, 3
mov cl, 2
mov ecx, 1
mov eax, 1

and al, cl ; Zeros CF, non-inverted
push ecx ; Triggers a register cache flush
inc eax ; Tries to preserve CF, but would encounter the bug and set it instead
jnb succ
mov eax, 0
hlt
succ:
mov eax, 1
hlt
Loading