public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86_emulate: Use DstReg when emulating xchg instructions
@ 2008-06-15 16:37 Mohammed Gamal
  2008-06-16  4:10 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Mohammed Gamal @ 2008-06-15 16:37 UTC (permalink / raw)
  To: kvm; +Cc: avi, riel

As per Avi's recommendation, this patch uses DstReg to autodecode destination
registers when emulating xchg instructions

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
 arch/x86/kvm/x86_emulate.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index b90857c..d88a4ca 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -140,9 +140,12 @@ static u16 opcode_table[256] = {
 	ByteOp | DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
 	DstMem | SrcReg | ModRM | Mov, ModRM | DstReg,
 	DstReg | SrcMem | ModRM | Mov, Group | Group1A,
-	/* 0x90 - 0x9F */
-	0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, ImplicitOps | Stack, ImplicitOps | Stack, 0, 0,
+	/* 0x90 - 0x97 */
+	DstReg, DstReg, DstReg, DstReg,
+	DstReg, DstReg, DstReg, DstReg,
+	/* 0x98 - 0x9F */
+	0, 0, 0, 0,
+	ImplicitOps | Stack, ImplicitOps | Stack, 0, 0,
 	/* 0xA0 - 0xA7 */
 	ByteOp | DstReg | SrcMem | Mov | MemAbs, DstReg | SrcMem | Mov | MemAbs,
 	ByteOp | DstMem | SrcReg | Mov | MemAbs, DstMem | SrcReg | Mov | MemAbs,
@@ -1493,6 +1496,7 @@ special_insn:
 		emulate_2op_SrcV("test", c->src, c->dst, ctxt->eflags);
 		break;
 	case 0x86 ... 0x87:	/* xchg */
+	xchg:
 		/* Write back the register source. */
 		switch (c->dst.bytes) {
 		case 1:
@@ -1560,6 +1564,18 @@ special_insn:
 		if (rc != 0)
 			goto done;
 		break;
+	case 0x90: /* nop / xchg r8,rax */
+		if (! (c->rex_prefix & 1) ) /* nop */
+		{
+			c->dst.type = OP_NONE;
+			break;
+		}
+	case 0x91 ... 0x97: /* xchg reg,rax */
+		c->src.type = c->dst.type = OP_REG;
+		c->src.bytes = c->dst.bytes = c->op_bytes;
+		c->src.ptr = (unsigned long *) &c->regs[VCPU_REGS_RAX];
+		c->src.val = *(c->src.ptr);
+		goto xchg;		
 	case 0x9c: /* pushf */
 		c->src.val =  (unsigned long) ctxt->eflags;
 		emulate_push(ctxt);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86_emulate: Use DstReg when emulating xchg instructions
  2008-06-15 16:37 [PATCH] x86_emulate: Use DstReg when emulating xchg instructions Mohammed Gamal
@ 2008-06-16  4:10 ` Avi Kivity
  0 siblings, 0 replies; 2+ messages in thread
From: Avi Kivity @ 2008-06-16  4:10 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: kvm, riel

Mohammed Gamal wrote:
> As per Avi's recommendation, this patch uses DstReg to autodecode destination
> registers when emulating xchg instructions
>
>   

Applied, thanks.  I had to fix some coding style errors, please read 
Documentation/CodingStyle (or just follow the style in the surrounding 
code).

> +	case 0x91 ... 0x97: /* xchg reg,rax */
> +		c->src.type = c->dst.type = OP_REG;
> +		c->src.bytes = c->dst.bytes = c->op_bytes;
> +		c->src.ptr = (unsigned long *) &c->regs[VCPU_REGS_RAX];
> +		c->src.val = *(c->src.ptr);
> +		goto xchg;		
>   

How about SrcAcc and DstAcc so this code doesn't have to be repeated?  
There are many potential use cases.

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-06-16  4:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-15 16:37 [PATCH] x86_emulate: Use DstReg when emulating xchg instructions Mohammed Gamal
2008-06-16  4:10 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox