@@ -337,3 +337,59 @@ index 63e10cc6df..1e1b553795 100644
337337- -
3383382.41.0
339339
340+ From 0f1d6606c28d0ae81a1b311972c5c54e5e867bf0 Mon Sep 17 00:00:00 2001
341+ From: Mark Cave-Ayland <
[email protected] >
342+ Date: Wed, 11 Jun 2025 14:03:15 +0100
343+ Subject: [PATCH] target/i386: fix TB exit logic in gen_movl_seg() when writing
344+ to SS
345+
346+ Before commit e54ef98c8a ("target/i386: do not trigger IRQ shadow for LSS"), any
347+ write to SS in gen_movl_seg() would cause a TB exit. The changes introduced by
348+ this commit were intended to restrict the DISAS_EOB_INHIBIT_IRQ exit to the case
349+ where inhibit_irq is true, but missed that a DISAS_EOB_NEXT exit can still be
350+ required when writing to SS and inhibit_irq is false.
351+
352+ Comparing the PE(s) && !VM86(s) section with the logic in x86_update_hflags(), we
353+ can see that the DISAS_EOB_NEXT exit is still required for the !CODE32 case when
354+ writing to SS in gen_movl_seg() because any change to the SS flags can affect
355+ hflags. Similarly we can see that the existing CODE32 case is still correct since
356+ a change to any of DS, ES and SS can affect hflags. Finally for the
357+ gen_op_movl_seg_real() case an explicit TB exit is not needed because the segment
358+ register selector does not affect hflags.
359+
360+ Update the logic in gen_movl_seg() so that a write to SS with inhibit_irq set to
361+ false where PE(s) && !VM86(s) will generate a DISAS_EOB_NEXT exit along with the
362+ inline comment. This has the effect of allowing Win98SE to boot in QEMU once
363+ again.
364+
365+ Signed-off-by: Mark Cave-Ayland <
[email protected] >
366+ Fixes: e54ef98c8a ("target/i386: do not trigger IRQ shadow for LSS")
367+ Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2987
368+ Link: https://lore.kernel.org/r/
[email protected] 369+ Reviewed-by: Peter Maydell <
[email protected] >
370+ Signed-off-by: Paolo Bonzini <
[email protected] >
371+ ---
372+ target/i386/tcg/translate.c | 7 +++++--
373+ 1 file changed, 5 insertions(+), 2 deletions(-)
374+
375+ diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
376+ index 0fcddc2ec0..0cb87d0201 100644
377+ --- a/target/i386/tcg/translate.c
378+ +++ b/target/i386/tcg/translate.c
379+ @@ -2033,8 +2033,11 @@ static void gen_movl_seg(DisasContext *s, X86Seg seg_reg, TCGv src, bool inhibit
380+ tcg_gen_trunc_tl_i32(sel, src);
381+ gen_helper_load_seg(tcg_env, tcg_constant_i32(seg_reg), sel);
382+
383+ - /* For move to DS/ES/SS, the addseg or ss32 flags may change. */
384+ - if (CODE32(s) && seg_reg < R_FS) {
385+ + /*
386+ + * For moves to SS, the SS32 flag may change. For CODE32 only, changes
387+ + * to SS, DS and ES may change the ADDSEG flags.
388+ + */
389+ + if (seg_reg == R_SS || (CODE32(s) && seg_reg < R_FS)) {
390+ s->base.is_jmp = DISAS_EOB_NEXT;
391+ }
392+ } else {
393+ - -
394+ 2.41.0
395+
0 commit comments