target/i386/tcg: do not leave non-arithmetic flags in CC_SRC after PUSHF
PATCH 1/1 target/i386/tcg: do not leave non-arithmetic flags in CC_SRC after PUSHF
The value that is pushed by PUSHF is the full EFLAGS, while CC_OP_EFLAGS only wants arithmetic flags in CC_SRC. To avoid this, follow what other helpers to and set CC_SRC/CC_OP directly in helper_read_eflags. This is basically free and fixes an issue booting Windows 3.11.
--- target/i386/tcg/cc_helper.c | 4 +++- target/i386/tcg/emit.c.inc | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-)
target/i386/tcg/cc_helper.c +3 -1
@@ -414,7 +414,9 @@ target_ulong helper_read_eflags(CPUX86State *env) {uint32_t eflags; - eflags =cpu_cc_compute_all (env); +CC_SRC = eflags =cpu_cc_compute_all (env); +CC_OP =CC_OP_EFLAGS ; + eflags |= (env->df &DF_MASK ); eflags |= env->eflags & ~(VM_MASK |RF_MASK );return eflags;
target/i386/tcg/emit.c.inc +1 -2
@@ -3253,8 +3253,7 @@ static void gen_PUSHF(DisasContext *s, X86DecodedInsn *decode) gen_update_cc_op(s); gen_helper_read_eflags(s->T0, tcg_env); gen_push_v(s, s->T0); - decode->cc_src = s->T0; - decode->cc_op = CC_OP_EFLAGS; + assume_cc_op(s, CC_OP_EFLAGS); } static MemOp gen_shift_count(DisasContext *s, X86DecodedInsn *decode,
Signature · 1 line
2.52.0
Quoted 33 lines · Paolo Bonzini
The value that is pushed by PUSHF is the full EFLAGS, while
CC_OP_EFLAGSonly wants arithmetic flags inCC_SRC. To avoid this, follow what other helpers to and set CC_SRC/CC_OP directly inhelper_read_eflags. This is basically free and fixes an issue booting Windows 3.11.Reported-by Mark Cave-Ayland <[email protected]>Fixes e661e2d7a37 ("target/i386/tcg: update cc_op after PUSHF", 2025-12-27)Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/tcg/cc_helper.c | 4 +++- target/i386/tcg/emit.c.inc | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-)target/i386/tcg/cc_helper.c +3
-1@@ -414,7 +414,9 @@ target_ulong helper_read_eflags(CPUX86State *env) {uint32_t eflags; - eflags =cpu_cc_compute_all (env); +CC_SRC = eflags =cpu_cc_compute_all (env); +CC_OP =CC_OP_EFLAGS ; + eflags |= (env->df &DF_MASK ); eflags |= env->eflags & ~(VM_MASK |RF_MASK );return eflags;target/i386/tcg/emit.c.inc +0
-0
target/i386/tcg/emit.c.inc static void gen_PUSHF(DisasContext *s, X86DecodedInsn *decode) · line 3259
Quoted 9 lines
target/i386/tcg/emit.c.inc +1
-2@@ -3253,8 +3253,7 @@ static void gen_PUSHF(DisasContext *s, X86DecodedInsn *decode) gen_update_cc_op(s); gen_helper_read_eflags(s->T0, tcg_env); gen_push_v(s, s->T0); - decode->cc_src = s->T0; - decode->cc_op = CC_OP_EFLAGS; + assume_cc_op(s, CC_OP_EFLAGS); } static MemOp gen_shift_count(DisasContext *s, X86DecodedInsn *decode,
Thanks Paolo! I've given this a quick test and it fixes the issue here:
ATB,
Mark.
Quoted 5 lines · Mark Cave-Ayland
Quoted 3 lines · Paolo Bonzini
The value that is pushed by PUSHF is the full EFLAGS, while
CC_OP_EFLAGSonly wants arithmetic flags inCC_SRC. To avoid this, follow what other helpers to and set CC_SRC/CC_OP directly inhelper_read_eflags. This
Small typo: other helpers do
Regards,
BALATON Zoltan
Quoted 50 lines
Quoted 29 lines
is basically free and fixes an issue booting Windows 3.11.
Reported-by Mark Cave-Ayland <[email protected]>Fixes e661e2d7a37 ("target/i386/tcg: update cc_op after PUSHF", 2025-12-27)Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/tcg/cc_helper.c | 4 +++- target/i386/tcg/emit.c.inc | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-)target/i386/tcg/cc_helper.c +3
-0@@ -414,7 +414,9 @@ target_ulong helper_read_eflags(CPUX86State *env) {uint32_t eflags; - eflags =cpu_cc_compute_all (env); +CC_SRC = eflags =cpu_cc_compute_all (env); +CC_OP =CC_OP_EFLAGS ; + eflags |= (env->df &DF_MASK ); eflags |= env->eflags & ~(VM_MASK |RF_MASK );return eflags;target/i386/tcg/emit.c.inc +0
-0target/i386/tcg/emit.c.inc static void gen_PUSHF(DisasContext *s, X86DecodedInsn · line 3259
Quoted 9 lines
target/i386/tcg/emit.c.inc +1
-2@@ -3253,8 +3253,7 @@ static void gen_PUSHF(DisasContext *s, X86DecodedInsn *decode) gen_update_cc_op(s); gen_helper_read_eflags(s->T0, tcg_env); gen_push_v(s, s->T0); - decode->cc_src = s->T0; - decode->cc_op = CC_OP_EFLAGS; + assume_cc_op(s, CC_OP_EFLAGS); } static MemOp gen_shift_count(DisasContext *s, X86DecodedInsn *decode,Thanks Paolo! I've given this a quick test and it fixes the issue here:
Tested-by Mark Cave-Ayland <[email protected]>ATB,
Mark.