public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Guillaume Thouvenin
	<guillaume.thouvenin-Z51IpKcfGtLk1uMJSBkQmQ@public.gmane.org>
Cc: "kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org"
	<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: [patch 2 of 2] Emulate CMPS instruction
Date: Fri, 23 Nov 2007 19:54:46 +0200	[thread overview]
Message-ID: <474713E6.10507@qumranet.com> (raw)
In-Reply-To: <20071123135743.288070e8-okVqAf2pJUEUMgAS9GT5UVaPQRlvutdw@public.gmane.org>

Guillaume Thouvenin wrote:
> This patch emulates the CMPS instruction.
>
> Signed-off-by: Guillaume Thouvenin <guillaume.thouvenin-Z51IpKcfGtLk1uMJSBkQmQ@public.gmane.org>
> ---
>
>  drivers/kvm/x86_emulate.c |   54 +++++++++++++++++++++++++++++++++++++++++++--
>  1 files changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
> index cee60eb..db744cf 100644
> --- a/drivers/kvm/x86_emulate.c
> +++ b/drivers/kvm/x86_emulate.c
> @@ -445,6 +445,29 @@ static u16 twobyte_table[256] = {
>  		register_address_increment(c->eip, rel);		\
>  	} while (0)
>  
> +/* Test if the repeat string operation prefix is REPE/REPZ or
> + * REPNE/REPNZ and if it's the case it tests the corresponding
> + * termination condition according to:
> + *     - if REPE/REPZ and ZF = 0 then done
> + *     - if REPNE/REPNZ and ZF = 1 then done
> + */
> +#define handle_rep_prefix(c)                                            \
> +	do {								\
> +		if ((c->b == 0xa6) || (c->b == 0xa7) ||			\
> +				(c->b == 0xae) || (c->b == 0xaf)) {	\
> +			if ((c->rep_prefix == REPE_PREFIX) &&		\
> +				((ctxt->eflags & EFLG_ZF) == 0)) {	\
> +				ctxt->vcpu->rip = c->eip;		\
> +				goto done;				\
> +			}						\
> +			if ((c->rep_prefix == REPNE_PREFIX) &&		\
> +				((ctxt->eflags & EFLG_ZF) == EFLG_ZF)) {\
> +				ctxt->vcpu->rip = c->eip;		\
> +				goto done;				\
> +			}						\
> +		}							\
> +	} while (0)
> +
>   

No new macros in the emulator please. Just inline it at the callsite.

>  static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
>  			      struct x86_emulate_ops *ops,
>  			      unsigned long linear, u8 *dest)
> @@ -1540,10 +1563,15 @@ special_insn:
>  		break;
>  	}
>  	if (c->rep_prefix) {
> +		/* All REP prefixes have the same first termination condition */
>  		if (c->regs[VCPU_REGS_RCX] == 0) {
>  			ctxt->vcpu->rip = c->eip;
>  			goto done;
>  		}
> +		/* The second termination condition only applies for REPE
> +		 * and REPNE. handle_rep_prefix() macro deals with that. 
> +		 */
> +		handle_rep_prefix(c);
>  		c->regs[VCPU_REGS_RCX]--;
>  		c->eip = ctxt->vcpu->rip;
>  	}
> @@ -1570,8 +1598,30 @@ special_insn:
>  							   : c->dst.bytes);
>  		break;
>  	case 0xa6 ... 0xa7:	/* cmps */
> -		DPRINTF("Urk! I don't handle CMPS.\n");
> -		goto cannot_emulate;
> +		c->src.type = OP_NONE;
>   

Shouldn't this be OP_MEM?

> +		c->src.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
> +		c->src.ptr = (unsigned long *)register_address(
> +						   ctxt->ds_base,
> +						   c->regs[VCPU_REGS_RDI]);
> +
> +		c->dst.type = OP_NONE;
>   

And here?

> +		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
> +		c->dst.ptr = (unsigned long *)register_address(
> +						   ctxt->es_base,
> +						   c->regs[VCPU_REGS_RSI]);
> +
> +		DPRINTF("cmps: mem1=0x%p mem2=0x%p\n", c->src.ptr, c->dst.ptr);
> +		
>   

Where is the actual memory access?

> +		emulate_2op_SrcV("cmp", c->src, c->dst, ctxt->eflags);
> +
> +		register_address_increment(c->regs[VCPU_REGS_RDI],
> +				       (ctxt->eflags & EFLG_DF) ? -c->dst.bytes
> +				       			  : c->dst.bytes);
> +
> +		register_address_increment(c->regs[VCPU_REGS_RSI],
> +				       (ctxt->eflags & EFLG_DF) ? -c->dst.bytes
> +				       			  : c->dst.bytes);
> +		break;
>  	case 0xaa ... 0xab:	/* stos */
>  		c->dst.type = OP_MEM;
>  		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> kvm-devel mailing list
> kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
>   


-- 
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  parent reply	other threads:[~2007-11-23 17:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-23 12:53 [patch 0 of 2] Emulate CMPS instruction Guillaume Thouvenin
     [not found] ` <20071123135332.514d46e7-okVqAf2pJUEUMgAS9GT5UVaPQRlvutdw@public.gmane.org>
2007-11-23 12:56   ` [patch 1 of 2] Rename REP prefixes Guillaume Thouvenin
2007-11-23 12:57   ` [patch 2 of 2] Emulate CMPS instruction Guillaume Thouvenin
     [not found]     ` <20071123135743.288070e8-okVqAf2pJUEUMgAS9GT5UVaPQRlvutdw@public.gmane.org>
2007-11-23 17:54       ` Avi Kivity [this message]
     [not found]         ` <474713E6.10507-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-26  9:58           ` Guillaume Thouvenin
2007-11-26 12:49           ` [patch 2 of 2][rewritten] " Guillaume Thouvenin
     [not found]             ` <20071126134909.5fe49ad6-okVqAf2pJUEUMgAS9GT5UVaPQRlvutdw@public.gmane.org>
2007-11-26 15:13               ` Avi Kivity

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=474713E6.10507@qumranet.com \
    --to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
    --cc=guillaume.thouvenin-Z51IpKcfGtLk1uMJSBkQmQ@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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