From: Richard Henderson <richard.henderson@linaro.org>
To: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
pbonzini@redhat.com, eduardo@habkost.net, qemu-devel@nongnu.org
Subject: Re: [PATCH] target/i386/translate.c: always write 32-bits for SGDT and SIDT
Date: Fri, 19 Apr 2024 18:21:22 -0700 [thread overview]
Message-ID: <fefb7b6b-29fc-42ee-b62e-059512e881e4@linaro.org> (raw)
In-Reply-To: <20240419195147.434894-1-mark.cave-ayland@ilande.co.uk>
On 4/19/24 12:51, Mark Cave-Ayland wrote:
> The various Intel CPU manuals claim that SGDT and SIDT can write either 24-bits
> or 32-bits depending upon the operand size, but this is incorrect. Not only do
> the Intel CPU manuals give contradictory information between processor
> revisions, but this information doesn't even match real-life behaviour.
>
> In fact, tests on real hardware show that the CPU always writes 32-bits for SGDT
> and SIDT, and this behaviour is required for at least OS/2 Warp and WFW 3.11 with
> Win32s to function correctly. Remove the masking applied due to the operand size
> for SGDT and SIDT so that the TCG behaviour matches the behaviour on real
> hardware.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2198
>
> --
> MCA: Whilst I don't have a copy of OS/2 Warp handy, I've confirmed that this
> patch fixes the issue in WFW 3.11 with Win32s. For more technical information I
> highly recommend the excellent write-up at
> https://www.os2museum.com/wp/sgdtsidt-fiction-and-reality/.
> ---
> target/i386/tcg/translate.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
> index 76a42c679c..3026eb6774 100644
> --- a/target/i386/tcg/translate.c
> +++ b/target/i386/tcg/translate.c
> @@ -5846,9 +5846,10 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
> gen_op_st_v(s, MO_16, s->T0, s->A0);
> gen_add_A0_im(s, 2);
> tcg_gen_ld_tl(s->T0, tcg_env, offsetof(CPUX86State, gdt.base));
> - if (dflag == MO_16) {
> - tcg_gen_andi_tl(s->T0, s->T0, 0xffffff);
> - }
> + /*
> + * NB: Despite claims to the contrary in Intel CPU documentation,
> + * all 32-bits are written regardless of operand size.
> + */
Current documentation agrees that all 32 bits are written, so I don't think you need this
comment:
IF OperandSize =16 or OperandSize = 32 (* Legacy or Compatibility Mode *)
THEN
DEST[0:15] := GDTR(Limit);
DEST[16:47] := GDTR(Base); (* Full 32-bit base address stored *)
FI;
Anyway,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
next prev parent reply other threads:[~2024-04-20 1:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 19:51 [PATCH] target/i386/translate.c: always write 32-bits for SGDT and SIDT Mark Cave-Ayland
2024-04-20 1:21 ` Richard Henderson [this message]
2024-04-20 5:40 ` Mark Cave-Ayland
2024-04-22 19:03 ` Volker Rümelin
2024-04-23 8:15 ` Philippe Mathieu-Daudé
2024-04-23 8:24 ` Daniel P. Berrangé
2024-04-23 9:18 ` Paolo Bonzini
2024-04-23 20:42 ` Mark Cave-Ayland
2024-04-26 5:46 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fefb7b6b-29fc-42ee-b62e-059512e881e4@linaro.org \
--to=richard.henderson@linaro.org \
--cc=eduardo@habkost.net \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).