Skip to contentSkip to conversation

target/i386/tcg: do not leave non-arithmetic flags in CC_SRC after PUSHF

PATCH In review Paolo Bonzini 3 participants 3 messages Jan 7

lore
Share & tools
lore
#0 lore raw

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.

Fixes e661e2d7a37 ("target/i386/tcg: update cc_op after PUSHF", 2025-12-27)
---
 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
index 91e492196af..6ddd64fcb07 100644
@@ -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
index 0fde3d669d9..e55b65176fc 100644
@@ -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
Tested-by on v1 1/1
#1 lore raw
Quoted 33 lines · Paolo Bonzini

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.

Fixes e661e2d7a37 ("target/i386/tcg: update cc_op after PUSHF", 2025-12-27)
---
  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
index 91e492196af..6ddd64fcb07 100644
@@ -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
index 0fde3d669d9..e55b65176fc 100644

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.

#2 lore raw
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_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

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.

Fixes e661e2d7a37 ("target/i386/tcg: update cc_op after PUSHF", 2025-12-27)
---
  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
index 91e492196af..6ddd64fcb07 100644
@@ -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
index 0fde3d669d9..e55b65176fc 100644

target/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:

ATB,

Mark.