Skip to content

Commit 35d95e4

Browse files
bonzinirth7680
authored andcommitted
target/i386: hardcode R_EAX as destination register for LAHF/SAHF
When translating code that is using LAHF and SAHF in combination with the REX prefix, the instructions should not use any other register than AH; however, QEMU selects SPL (SP being register 4, just like AH) if the REX prefix is present. To fix this, use deposit directly without going through gen_op_mov_v_reg and gen_op_mov_reg_v. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/130 Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent d1bb978 commit 35d95e4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

target/i386/tcg/translate.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5230,7 +5230,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
52305230
case 0x9e: /* sahf */
52315231
if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM))
52325232
goto illegal_op;
5233-
gen_op_mov_v_reg(s, MO_8, s->T0, R_AH);
5233+
tcg_gen_shri_tl(s->T0, cpu_regs[R_EAX], 8);
52345234
gen_compute_eflags(s);
52355235
tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, CC_O);
52365236
tcg_gen_andi_tl(s->T0, s->T0, CC_S | CC_Z | CC_A | CC_P | CC_C);
@@ -5242,7 +5242,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
52425242
gen_compute_eflags(s);
52435243
/* Note: gen_compute_eflags() only gives the condition codes */
52445244
tcg_gen_ori_tl(s->T0, cpu_cc_src, 0x02);
5245-
gen_op_mov_reg_v(s, MO_8, R_AH, s->T0);
5245+
tcg_gen_deposit_tl(cpu_regs[R_EAX], cpu_regs[R_EAX], s->T0, 8, 8);
52465246
break;
52475247
case 0xf5: /* cmc */
52485248
gen_compute_eflags(s);

0 commit comments

Comments
 (0)