login
Header Space

 
 

[PATCH 098/104] KVM: x86 emulator: imlpement jump conditional relative

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <kvm-devel@...>
Cc: <linux-kernel@...>, Nitin A Kamble <nitin.a.kamble@...>
Date: Monday, September 17, 2007 - 4:32 am

From: Nitin A Kamble <nitin.a.kamble@intel.com>

Implement emulation of instruction:
    jump conditional rel
    opcodes: 0x0f 0x80 - 0x0f 0x8f

Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/x86_emulate.c |   61 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index e4ce34c..ba53e59 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -188,7 +188,10 @@ static u16 twobyte_table[256] = {
 	/* 0x70 - 0x7F */
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	/* 0x80 - 0x8F */
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
+	ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
+	ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
+	ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
 	/* 0x90 - 0x9F */
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	/* 0xA0 - 0xA7 */
@@ -479,6 +482,41 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt,
 	return rc;
 }
 
+static int test_cc(unsigned int condition, unsigned int flags)
+{
+	int rc = 0;
+
+	switch ((condition & 15) >> 1) {
+	case 0: /* o */
+		rc |= (flags & EFLG_OF);
+		break;
+	case 1: /* b/c/nae */
+		rc |= (flags & EFLG_CF);
+		break;
+	case 2: /* z/e */
+		rc |= (flags & EFLG_ZF);
+		break;
+	case 3: /* be/na */
+		rc |= (flags & (EFLG_CF|EFLG_ZF));
+		break;
+	case 4: /* s */
+		rc |= (flags & EFLG_SF);
+		break;
+	case 5: /* p/pe */
+		rc |= (flags & EFLG_PF);
+		break;
+	case 7: /* le/ng */
+		rc |= (flags & EFLG_ZF);
+		/* fall through */
+	case 6: /* l/nge */
+		rc |= (!(flags & EFLG_SF) != !(flags & EFLG_OF));
+		break;
+	}
+
+	/* Odd condition identifiers (lsb == 1) have inverted sense. */
+	return (!!rc ^ (condition & 1));
+}
+
 int
 x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 {
@@ -1486,6 +1524,27 @@ twobyte_special_insn:
 		}
 		rc = X86EMUL_CONTINUE;
 		break;
+	case 0x80 ... 0x8f: /* jnz rel, etc*/ {
+		long int rel;
+
+		switch (op_bytes) {
+		case 2:
+			rel = insn_fetch(s16, 2, _eip);
+			break;
+		case 4:
+			rel = insn_fetch(s32, 4, _eip);
+			break;
+		case 8:
+			rel = insn_fetch(s64, 8, _eip);
+			break;
+		default:
+			DPRINTF("jnz: Invalid op_bytes\n");
+			goto cannot_emulate;
+		}
+		if (test_cc(b, _eflags))
+			JMP_REL(rel);
+		break;
+	}
 	case 0xc7:		/* Grp9 (cmpxchg8b) */
 		{
 			u64 old, new;
-- 
1.5.3

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
git-send-email creates duplicate Message-Id's, Adrian Bunk, (Mon Sep 17, 11:59 am)
Re: git-send-email creates duplicate Message-Id's, Junio C Hamano, (Mon Sep 17, 4:22 pm)
Re: git-send-email creates duplicate Message-Id's, Matti Aarnio, (Mon Sep 17, 4:47 pm)
[PATCH 023/104] KVM: load_pdptrs() cleanups, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 029/104] KVM: Convert vm lock to a mutex, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 036/104] KVM: Remove kvm_{read,write}_guest(), Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 046/104] KVM: Remove stat_set from debugfs, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 031/104] KVM: VMX: pass vcpu_vmx internally, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 074/104] KVM: pending irq save/restore, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 085/104] KVM: Keep control regs in sync, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 093/104] KVM: x86 emulator: push imm8, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 094/104] KVM: x86 emulator: call near, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 095/104] KVM: x86 emulator: pushf, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 103/104] KVM: x86 emulator: popf, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 098/104] KVM: x86 emulator: imlpement jump conditiona..., Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 100/104] KVM: x86 emulator: lea, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 101/104] KVM: x86 emulator: jmp abs, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 087/104] KVM: Simplify memory allocation, Avi Kivity, (Mon Sep 17, 4:32 am)
[PATCH 066/104] KVM: Emulate local APIC in kernel, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 061/104] KVM: Support more memory slots, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 067/104] KVM: In-kernel I/O APIC model, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 068/104] KVM: Emulate hlt in the kernel, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 025/104] KVM: Dynamically allocate vcpus, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 053/104] KVM: Clean up kvm_setup_pio(), Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 051/104] KVM: Remove useless assignment, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 033/104] KVM: SVM: de-containization, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 040/104] KVM: VMX: Add cpu consistency check, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 042/104] KVM: Cleanup mark_page_dirty, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 032/104] KVM: Remove three magic numbers, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 027/104] KVM: add hypercall nr to kvm_run, Avi Kivity, (Mon Sep 17, 4:31 am)
[PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Avi Kivity, (Mon Sep 17, 4:30 am)
Re: [PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Christoph Hellwig, (Mon Sep 17, 5:13 am)
Re: [PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Avi Kivity, (Mon Sep 17, 5:15 am)
Re: [PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Avi Kivity, (Mon Sep 17, 5:18 am)
Re: [PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Nick Piggin, (Sun Sep 16, 5:29 pm)
Re: [PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Avi Kivity, (Mon Sep 17, 2:19 pm)
Re: [PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Nick Piggin, (Mon Sep 17, 1:17 pm)
Re: [PATCH 001/104] KVM: Fix *nopage() in kvm_main.c, Avi Kivity, (Tue Sep 18, 6:44 am)
speck-geostationary