All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Yongjun <yjwei@cn.fujitsu.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH 1/2] KVM: x86 emulator: put register operand write back to a function
Date: Thu, 12 Aug 2010 21:38:15 +0800	[thread overview]
Message-ID: <4C63F947.7020808@cn.fujitsu.com> (raw)

Introduce function write_register_operand() to write back the
register operand.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
---
 arch/x86/kvm/emulate.c |   53 +++++++++++++++++++----------------------------
 1 files changed, 22 insertions(+), 31 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c476a67..8bf80a9 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1020,6 +1020,26 @@ exception:
 	return X86EMUL_PROPAGATE_FAULT;
 }
 
+static void write_register_operand(struct operand *op, unsigned long val,
+				   unsigned int bytes)
+{
+	/* The 4-byte case *is* correct: in 64-bit mode we zero-extend. */
+	switch (bytes) {
+	case 1:
+		*(u8 *)op->addr.reg = (u8)val;
+		break;
+	case 2:
+		*(u16 *)op->addr.reg = (u16)val;
+		break;
+	case 4:
+		*op->addr.reg = (u32)val;
+		break;	/* 64b: zero-extend */
+	case 8:
+		*op->addr.reg = val;
+		break;
+	}
+}
+
 static inline int writeback(struct x86_emulate_ctxt *ctxt,
 			    struct x86_emulate_ops *ops)
 {
@@ -1029,23 +1049,7 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
 
 	switch (c->dst.type) {
 	case OP_REG:
-		/* The 4-byte case *is* correct:
-		 * in 64-bit mode we zero-extend.
-		 */
-		switch (c->dst.bytes) {
-		case 1:
-			*(u8 *)c->dst.addr.reg = (u8)c->dst.val;
-			break;
-		case 2:
-			*(u16 *)c->dst.addr.reg = (u16)c->dst.val;
-			break;
-		case 4:
-			*c->dst.addr.reg = (u32)c->dst.val;
-			break;	/* 64b: zero-ext */
-		case 8:
-			*c->dst.addr.reg = c->dst.val;
-			break;
-		}
+		write_register_operand(&c->dst, c->dst.val, c->dst.bytes);
 		break;
 	case OP_MEM:
 		if (c->lock_prefix)
@@ -2971,20 +2975,7 @@ special_insn:
 	case 0x86 ... 0x87:	/* xchg */
 	xchg:
 		/* Write back the register source. */
-		switch (c->dst.bytes) {
-		case 1:
-			*(u8 *) c->src.addr.reg = (u8) c->dst.val;
-			break;
-		case 2:
-			*(u16 *) c->src.addr.reg = (u16) c->dst.val;
-			break;
-		case 4:
-			*c->src.addr.reg = (u32) c->dst.val;
-			break;	/* 64b reg: zero-extend */
-		case 8:
-			*c->src.addr.reg = c->dst.val;
-			break;
-		}
+		write_register_operand(&c->src, c->dst.val, c->dst.bytes);
 		/*
 		 * Write back the memory destination with implicit LOCK
 		 * prefix.
-- 
1.7.0.4



             reply	other threads:[~2010-08-12 13:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-12 13:38 Wei Yongjun [this message]
2010-08-12 13:41 ` [PATCH 2/2] KVM: x86 emulator: add XADD instruction emulation Wei Yongjun
2010-08-12 15:34   ` Paolo Bonzini
2010-08-13  5:13     ` [PATCH 2/2 v2] " Wei Yongjun
2010-08-13  5:32       ` [PATCH 2/2 v3] " Wei Yongjun
2010-08-15 11:30 ` [PATCH 1/2] KVM: x86 emulator: put register operand write back to a function Avi Kivity
     [not found]   ` <4C689B56.4000405@cn.fujitsu.com>
2010-08-16  8:55     ` 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=4C63F947.7020808@cn.fujitsu.com \
    --to=yjwei@cn.fujitsu.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.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 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.