public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: kvm@vger.kernel.org, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [PATCH 05/15] KVM: x86 emulator: put register operand fetch into a function
Date: Sun,  1 Aug 2010 17:23:23 +0300	[thread overview]
Message-ID: <1280672613-14026-6-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1280672613-14026-1-git-send-email-avi@redhat.com>

The code is repeated three times, put it into fetch_register_operand()

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/kvm/emulate.c |   61 ++++++++++++++++-------------------------------
 1 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 4d510c3..063c96a 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -539,6 +539,24 @@ static int test_cc(unsigned int condition, unsigned int flags)
 	return (!!rc ^ (condition & 1));
 }
 
+static void fetch_register_operand(struct operand *op)
+{
+	switch (op->bytes) {
+	case 1:
+		op->val = *(u8 *)op->addr.reg;
+		break;
+	case 2:
+		op->val = *(u16 *)op->addr.reg;
+		break;
+	case 4:
+		op->val = *(u32 *)op->addr.reg;
+		break;
+	case 8:
+		op->val = *(u64 *)op->addr.reg;
+		break;
+	}
+}
+
 static void decode_register_operand(struct operand *op,
 				    struct decode_cache *c,
 				    int inhibit_bytereg)
@@ -551,23 +569,12 @@ static void decode_register_operand(struct operand *op,
 	op->type = OP_REG;
 	if ((c->d & ByteOp) && !inhibit_bytereg) {
 		op->addr.reg = decode_register(reg, c->regs, highbyte_regs);
-		op->val = *(u8 *)op->addr.reg;
 		op->bytes = 1;
 	} else {
 		op->addr.reg = decode_register(reg, c->regs, 0);
 		op->bytes = c->op_bytes;
-		switch (op->bytes) {
-		case 2:
-			op->val = *(u16 *)op->addr.reg;
-			break;
-		case 4:
-			op->val = *(u32 *)op->addr.reg;
-			break;
-		case 8:
-			op->val = *(u64 *) op->addr.reg;
-			break;
-		}
 	}
+	fetch_register_operand(op);
 	op->orig_val = op->val;
 }
 
@@ -2502,20 +2509,7 @@ done_prefixes:
 		c->src.type = OP_REG;
 		c->src.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
 		c->src.addr.reg = &c->regs[VCPU_REGS_RAX];
-		switch (c->src.bytes) {
-			case 1:
-				c->src.val = *(u8 *)c->src.addr.reg;
-				break;
-			case 2:
-				c->src.val = *(u16 *)c->src.addr.reg;
-				break;
-			case 4:
-				c->src.val = *(u32 *)c->src.addr.reg;
-				break;
-			case 8:
-				c->src.val = *(u64 *)c->src.addr.reg;
-				break;
-		}
+		fetch_register_operand(&c->src);
 		break;
 	case SrcOne:
 		c->src.bytes = 1;
@@ -2601,20 +2595,7 @@ done_prefixes:
 		c->dst.type = OP_REG;
 		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
 		c->dst.addr.reg = &c->regs[VCPU_REGS_RAX];
-		switch (c->dst.bytes) {
-			case 1:
-				c->dst.val = *(u8 *)c->dst.addr.reg;
-				break;
-			case 2:
-				c->dst.val = *(u16 *)c->dst.addr.reg;
-				break;
-			case 4:
-				c->dst.val = *(u32 *)c->dst.addr.reg;
-				break;
-			case 8:
-				c->dst.val = *(u64 *)c->dst.addr.reg;
-				break;
-		}
+		fetch_register_operand(&c->dst);
 		c->dst.orig_val = c->dst.val;
 		break;
 	case DstDI:
-- 
1.7.1


  parent reply	other threads:[~2010-08-01 14:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-01 14:23 [PATCH 00/15] More emulator cleanups Avi Kivity
2010-08-01 14:23 ` [PATCH 01/15] KVM: x86 emulator: push segment override out of decode_modrm() Avi Kivity
2010-08-01 14:23 ` [PATCH 02/15] KVM: x86 emulator: use correct type for memory address in operands Avi Kivity
2010-08-01 14:23 ` [PATCH 03/15] KVM: x86 emulator: simplify xchg decode tables Avi Kivity
2010-08-01 14:23 ` [PATCH 04/15] KVM: x86 emulator: use SrcAcc to simplify xchg decoding Avi Kivity
2010-08-01 14:23 ` Avi Kivity [this message]
2010-08-01 14:23 ` [PATCH 06/15] KVM: x86 emulator: drop use_modrm_ea Avi Kivity
2010-08-01 14:23 ` [PATCH 07/15] KVM: x86 emulator: simplify REX.W check Avi Kivity
2010-08-01 14:23 ` [PATCH 08/15] KVM: x86 emulator: introduce Force64 for forcing operand size to 64 bits Avi Kivity
2010-08-01 14:23 ` [PATCH 09/15] KVM: x86 emulator: mark mov cr and mov dr as 64-bit instructions in long mode Avi Kivity
2010-08-02  7:37   ` Avi Kivity
2010-08-01 14:23 ` [PATCH 10/15] KVM: x86 emulator: use struct operand for mov reg,cr and mov cr,reg for reg op Avi Kivity
2010-08-01 14:23 ` [PATCH 11/15] KVM: x86 emulator: use struct operand for mov reg,dr and mov dr,reg " Avi Kivity
2010-08-01 14:23 ` [PATCH 12/15] KVM: x86 emulator: add NoAccess flag for memory instructions that skip access Avi Kivity
2010-08-01 14:23 ` [PATCH 13/15] KVM: x86 emulator: switch LEA to use SrcMem decoding Avi Kivity
2010-08-01 14:23 ` [PATCH 14/15] KVM: x86 emulator: change invlpg emulation to use src.mem.addr Avi Kivity
2010-08-01 14:23 ` [PATCH 15/15] KVM: x86 emulator: Decode memory operands directly into a 'struct operand' Avi Kivity
2010-08-02  7:28   ` Paolo Bonzini
2010-08-02  7:36     ` 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=1280672613-14026-6-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox