All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: [PATCH 02/14] KVM: x86 emulator: convert group 3 instructions to direct decode
Date: Tue, 13 Sep 2011 10:45:39 +0300	[thread overview]
Message-ID: <1315899951-2357-3-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1315899951-2357-1-git-send-email-avi@redhat.com>

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

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index af06539..ed819bd 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1663,37 +1663,49 @@ static int em_grp2(struct x86_emulate_ctxt *ctxt)
 	return X86EMUL_CONTINUE;
 }
 
-static int em_grp3(struct x86_emulate_ctxt *ctxt)
+static int em_not(struct x86_emulate_ctxt *ctxt)
+{
+	ctxt->dst.val = ~ctxt->dst.val;
+	return X86EMUL_CONTINUE;
+}
+
+static int em_neg(struct x86_emulate_ctxt *ctxt)
+{
+	emulate_1op(ctxt, "neg");
+	return X86EMUL_CONTINUE;
+}
+
+static int em_mul_ex(struct x86_emulate_ctxt *ctxt)
+{
+	u8 ex = 0;
+
+	emulate_1op_rax_rdx(ctxt, "mul", ex);
+	return X86EMUL_CONTINUE;
+}
+
+static int em_imul_ex(struct x86_emulate_ctxt *ctxt)
+{
+	u8 ex = 0;
+
+	emulate_1op_rax_rdx(ctxt, "imul", ex);
+	return X86EMUL_CONTINUE;
+}
+
+static int em_div_ex(struct x86_emulate_ctxt *ctxt)
 {
 	u8 de = 0;
 
-	switch (ctxt->modrm_reg) {
-	case 0 ... 1:	/* test */
-		emulate_2op_SrcV(ctxt, "test");
-		/* Disable writeback. */
-		ctxt->dst.type = OP_NONE;
-		break;
-	case 2:	/* not */
-		ctxt->dst.val = ~ctxt->dst.val;
-		break;
-	case 3:	/* neg */
-		emulate_1op(ctxt, "neg");
-		break;
-	case 4: /* mul */
-		emulate_1op_rax_rdx(ctxt, "mul", de);
-		break;
-	case 5: /* imul */
-		emulate_1op_rax_rdx(ctxt, "imul", de);
-		break;
-	case 6: /* div */
-		emulate_1op_rax_rdx(ctxt, "div", de);
-		break;
-	case 7: /* idiv */
-		emulate_1op_rax_rdx(ctxt, "idiv", de);
-		break;
-	default:
-		return X86EMUL_UNHANDLEABLE;
-	}
+	emulate_1op_rax_rdx(ctxt, "div", de);
+	if (de)
+		return emulate_de(ctxt);
+	return X86EMUL_CONTINUE;
+}
+
+static int em_idiv_ex(struct x86_emulate_ctxt *ctxt)
+{
+	u8 de = 0;
+
+	emulate_1op_rax_rdx(ctxt, "idiv", de);
 	if (de)
 		return emulate_de(ctxt);
 	return X86EMUL_CONTINUE;
@@ -2989,9 +3001,14 @@ static int check_perm_out(struct x86_emulate_ctxt *ctxt)
 };
 
 static struct opcode group3[] = {
-	D(DstMem | SrcImm | ModRM), D(DstMem | SrcImm | ModRM),
-	D(DstMem | SrcNone | ModRM | Lock), D(DstMem | SrcNone | ModRM | Lock),
-	X4(D(SrcMem | ModRM)),
+	I(DstMem | SrcImm | ModRM, em_test),
+	I(DstMem | SrcImm | ModRM, em_test),
+	I(DstMem | SrcNone | ModRM | Lock, em_not),
+	I(DstMem | SrcNone | ModRM | Lock, em_neg),
+	I(SrcMem | ModRM, em_mul_ex),
+	I(SrcMem | ModRM, em_imul_ex),
+	I(SrcMem | ModRM, em_div_ex),
+	I(SrcMem | ModRM, em_idiv_ex),
 };
 
 static struct opcode group4[] = {
@@ -3917,9 +3934,6 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
 		/* complement carry flag from eflags reg */
 		ctxt->eflags ^= EFLG_CF;
 		break;
-	case 0xf6 ... 0xf7:	/* Grp3 */
-		rc = em_grp3(ctxt);
-		break;
 	case 0xf8: /* clc */
 		ctxt->eflags &= ~EFLG_CF;
 		break;
-- 
1.7.6.1


  parent reply	other threads:[~2011-09-13  7:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-13  7:45 [PATCH 00/14] Emulator decode generalization Avi Kivity
2011-09-13  7:45 ` [PATCH 01/14] KVM: x86 emulator: fix Src2CL decode Avi Kivity
2011-09-13  7:45 ` Avi Kivity [this message]
2011-09-13  7:45 ` [PATCH 03/14] KVM: x86 emulator: move memop, memopp into emulation context Avi Kivity
2011-09-14 10:41   ` Takuya Yoshikawa
2011-09-14 11:37     ` Avi Kivity
2011-09-14 15:21       ` Takuya Yoshikawa
2011-09-14 15:25         ` Avi Kivity
2011-09-13  7:45 ` [PATCH 04/14] KVM: x86 emulator: split dst decode to a generic decode_operand() Avi Kivity
2011-09-13  7:45 ` [PATCH 05/14] KVM: x86 emulator: expand decode flags to 64 bits Avi Kivity
2011-09-13  7:45 ` [PATCH 06/14] KVM: x86 emulator: switch src2 to generic decode_operand() Avi Kivity
2011-09-13  7:45 ` [PATCH 07/14] KVM: x86 emulator: free up some flag bits near src, dst Avi Kivity
2011-09-13  7:45 ` [PATCH 08/14] KVM: x86 emulator: switch OpImmUByte decode to decode_imm() Avi Kivity
2011-09-13  7:45 ` [PATCH 09/14] KVM: x86 emulator: qualify OpReg inhibit_byte_regs hack Avi Kivity
2011-09-13  7:45 ` [PATCH 10/14] KVM: x86 emulator: switch src decode to decode_operand() Avi Kivity
2011-09-13  7:45 ` [PATCH 11/14] KVM: x86 emulator: simplify OpMem64 decode Avi Kivity
2011-09-13  7:45 ` [PATCH 12/14] KVM: x86 emulator: streamline decode of segment registers Avi Kivity
2011-09-13  7:45 ` [PATCH 13/14] KVM: x86 emulator: switch lds/les/lss/lfs/lgs to direct decode Avi Kivity
2011-09-13  7:45 ` [PATCH 14/14] KVM: x86 emulator: convert push %sreg/pop %sreg " Avi Kivity
2011-09-14 11:12 ` [PATCH 00/14] Emulator decode generalization Marcelo Tosatti

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=1315899951-2357-3-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 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.