From: Laszlo Ersek <lersek@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH] i386/translate: ignore 0x67 (PREFIX_ADR) on TARGET_X86_64 && CODE64()
Date: Mon, 27 May 2013 01:45:18 +0200 [thread overview]
Message-ID: <51A29E8E.10109@redhat.com> (raw)
In-Reply-To: <51A1C8DF.506@redhat.com>
On 05/26/13 10:33, Paolo Bonzini wrote:
> Il 26/05/2013 01:23, Richard Henderson ha scritto:
>> On 2013-05-24 14:37, Laszlo Ersek wrote:
>>> @@ -4813,7 +4813,11 @@ static target_ulong disas_insn(CPUX86State
>>> *env, DisasContext *s,
>>> /* 0x66 is ignored if rex.w is set */
>>> dflag = 2;
>>> }
>>> - if (!(prefixes & PREFIX_ADR)) {
>>> + if (prefixes & PREFIX_ADR) {
>>> + /* flip it back, 0x67 should have no effect */
>>> + aflag ^= 1;
>>> + }
>>> + else {
>>> aflag = 2;
>>> }
>>> }
>>>
>>
>> Agreed that there's a bug here. I'm thinking it would be clearer to not
>> write this as yet another flip, but understand that unlike dflag, aflag
>> can only be either 1 or 2 in 64-bit mode.
>>
>> I'm thinking of something more like this:
>>
>> diff --git a/target-i386/translate.c b/target-i386/translate.c
>> index 0aeccdb..bf772aa 100644
>> --- a/target-i386/translate.c
>> +++ b/target-i386/translate.c
>> @@ -4813,9 +4813,8 @@ static target_ulong disas_insn(CPUX86State *env,
>> DisasContext *s,
>> /* 0x66 is ignored if rex.w is set */
>> dflag = 2;
>> }
>> - if (!(prefixes & PREFIX_ADR)) {
>> - aflag = 2;
>> - }
>> + /* 0x67 toggles between 64-bit and 32-bit addressing. */
>> + aflag = (prefixes & PREFIX_ADR ? 1 : 2);
>
> Isn't that just "aflag++"? Needs a comment of course ("toggle between
> 32- and 64-bit, not 16- and 32-bit.").
I finally looked up in the SDM what the 0x67 (address-size override)
prefix does. Apparently,
2.1.1 Instruction Prefixes
[...] The address-size override prefix (67H) allows programs to
switch between 16- and 32-bit addressing. Either size can be the
default; the prefix selects the non-default size. [...]
CMPS/CMPSB/CMPSW/CMPSD/CMPSQ -- Compare String Operands
[...] In 64-bit mode, the instruction's default address size is 64
bits, 32 bit address size is supported using the prefix 67H. [...]
Assuming that
- aflag==0 means 16-bit address,
- aflag==1 means 32-bit address,
- aflag==2 means 64-bit address,
- and bit0 in "s->code32" carries "aflag" corresponding to the default
address size in 32-bit mode,
I think Richard's patch is correct (my approach was only to restore the
pre-patch logic without having any clue about the variables' contents).
I believe aflag++ is incorrect if the current default address size for
32-bit is 16-bit (ie. (s->code32 & 1) == 0). In this case the first XOR
(seeing the 0x67 prefix) flips it to 1, and the increment would change
it to 2. aflag==2 corresponds to 64-bit address, but in 64-bit mode with
the 0x67 prefix we must choose 32-bit.
(IOW in 32-bit mode the meaning of the 0x67 prefix is not absolute but
relative.)
Laszlo
next prev parent reply other threads:[~2013-05-26 23:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-24 21:37 [Qemu-devel] [PATCH] i386/translate: ignore 0x67 (PREFIX_ADR) on TARGET_X86_64 && CODE64() Laszlo Ersek
2013-05-25 23:23 ` Richard Henderson
2013-05-26 8:33 ` Paolo Bonzini
2013-05-26 23:45 ` Laszlo Ersek [this message]
2013-05-27 6:29 ` 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=51A29E8E.10109@redhat.com \
--to=lersek@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.