All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Mohammed Gamal <m.gamal005@gmail.com>
Cc: mtosatti@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] x86 emulator: Add unary mul, imul, div, and idiv instructions
Date: Sun, 08 Aug 2010 07:34:48 -0400	[thread overview]
Message-ID: <4C5E9658.6070803@redhat.com> (raw)
In-Reply-To: <1281234459-9248-1-git-send-email-m.gamal005@gmail.com>

  On 08/08/2010 05:27 AM, Mohammed Gamal wrote:
> This adds unary mul, imul, div, and idiv instructions (group 3 r/m 4-7).
>
> Signed-off-by: Mohammed Gamal<m.gamal005@gmail.com>
> ---
>   arch/x86/kvm/emulate.c |   41 ++++++++++++++++++++++++++++++++++++++++-
>   1 files changed, 40 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 7d78832..6d1ec53 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -315,6 +315,31 @@ struct group_dual {
>   		}							\
>   	} while (0)
>
> +#define __emulate_1op_src(_op, _src, _ax, _dx, _eflags, _suffix)		\

Not just 1op - add rax_rdx to the name to indicate these are implicit 
operands.

> +	do {								\
> +		unsigned long _tmp;					\
> +									\
> +		__asm__ __volatile__ (					\
> +			_PRE_EFLAGS("0", "4", "1")			\
> +			_op _suffix " %5; "				\
> +			_POST_EFLAGS("0", "4", "1")			\
> +			: "=m" (_eflags), "=&r" (_tmp),			\
> +			  "=a" (_ax), "=d" (_dx)			\
> +			: "i" (EFLAGS_MASK), "m" ((_src).val),		\
> +			  "a" (_ax), "d" (_dx));			\
> +	} while (0)							

The byte form of the instruction doesn't update dx, and the word form 
doesn't update edx[16:31].  So the "=a" and "=d" operands need to be 
"+a" and "+d" so the compiler loads them before the operation is started.

Please add a test to the effect, for example start with eax=0x12345678, 
and multiply (byte size) 0x80 by 0x40, and observe that the upper 16 
bits of eax are preserved (and that rdx is not modified).

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


  parent reply	other threads:[~2010-08-08 11:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-08  2:27 [PATCH 1/2] x86 emulator: Add unary mul, imul, div, and idiv instructions Mohammed Gamal
2010-08-08  2:27 ` [PATCH 2/2] x86 emulator: Fix emulate_grp3 return values Mohammed Gamal
2010-08-08 11:34 ` Avi Kivity [this message]
2010-08-08 11:53   ` [PATCH 1/2] x86 emulator: Add unary mul, imul, div, and idiv instructions Mohammed Gamal
2010-08-08 20:27     ` Avi Kivity
2010-08-08 21:19       ` Mohammed Gamal

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=4C5E9658.6070803@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=m.gamal005@gmail.com \
    --cc=mtosatti@redhat.com \
    /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.