From: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH 3/5][RESEND] move all decoding process to function x86_decode_insn().
Date: Tue, 18 Sep 2007 11:27:19 +0200 [thread overview]
Message-ID: <46EF99F7.6010205@bull.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 135 bytes --]
move all decoding process to function x86_decode_insn().
Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
[-- Attachment #2: x86_emulate-decode_insn --]
[-- Type: text/plain, Size: 4274 bytes --]
Index: kvm/drivers/kvm/x86_emulate.c
===================================================================
--- kvm.orig/drivers/kvm/x86_emulate.c 2007-09-18 10:41:06.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.c 2007-09-18 10:41:40.000000000 +0200
@@ -518,20 +518,16 @@ static int test_cc(unsigned int conditio
}
int
-x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
+x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
{
struct decode_cache *decode = &ctxt->decode;
u8 sib, rex_prefix = 0;
unsigned int i;
int rc = 0;
- unsigned long cr2 = ctxt->cr2;
int mode = ctxt->mode;
int index_reg = 0, base_reg = 0, scale, rip_relative = 0;
- int no_wb = 0;
- u64 msr_data;
/* Shadow copy of register state. Committed on successful emulation. */
- unsigned long _eflags = ctxt->eflags;
memset(decode, 0, sizeof(struct decode_cache));
decode->eip = ctxt->vcpu->rip;
@@ -624,8 +620,10 @@ done_prefixes:
}
/* Unrecognised? */
- if (decode->d == 0)
- goto cannot_emulate;
+ if (decode->d == 0) {
+ DPRINTF("Cannot emulate %02x\n", decode->b);
+ return -1;
+ }
}
/* ModRM and SIB bytes. */
@@ -789,7 +787,7 @@ done_prefixes:
}
if (decode->ad_bytes != 8)
decode->modrm_ea = (u32)decode->modrm_ea;
- cr2 = decode->modrm_ea;
+ ctxt->cr2 = decode->modrm_ea;
modrm_done:
;
}
@@ -844,13 +842,6 @@ done_prefixes:
break;
srcmem_common:
decode->src.type = OP_MEM;
- decode->src.ptr = (unsigned long *)cr2;
- decode->src.val = 0;
- if ((rc = ops->read_emulated((unsigned long)decode->src.ptr,
- &decode->src.val,
- decode->src.bytes, ctxt->vcpu)) != 0)
- goto done;
- decode->src.orig_val = decode->src.val;
break;
case SrcImm:
decode->src.type = OP_IMM;
@@ -883,7 +874,7 @@ done_prefixes:
switch (decode->d & DstMask) {
case ImplicitOps:
/* Special instructions do their own operand decoding. */
- goto special_insn;
+ return 0;
case DstReg:
decode->dst.type = OP_REG;
if ((decode->d & ByteOp)
@@ -912,7 +903,44 @@ done_prefixes:
break;
case DstMem:
decode->dst.type = OP_MEM;
- decode->dst.ptr = (unsigned long *)cr2;
+ break;
+ }
+
+done:
+ return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0;
+}
+
+int
+x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
+{
+ unsigned long cr2 = ctxt->cr2;
+ int no_wb = 0;
+ u64 msr_data;
+ unsigned long _eflags = ctxt->eflags;
+ struct decode_cache *decode = &ctxt->decode;
+ int rc;
+
+ rc = x86_decode_insn(ctxt, ops);
+ if (rc)
+ return rc;
+
+ if (decode->src.type == OP_MEM) {
+ decode->src.ptr = (unsigned long *)ctxt->cr2;
+ decode->src.val = 0;
+ if ((rc = ops->read_emulated((unsigned long)decode->src.ptr,
+ &decode->src.val,
+ decode->src.bytes,
+ ctxt->vcpu)) != 0)
+ goto done;
+ decode->src.orig_val = decode->src.val;
+ }
+
+ if ((decode->d & DstMask) == ImplicitOps)
+ goto special_insn;
+
+
+ if (decode->dst.type == OP_MEM) {
+ decode->dst.ptr = (unsigned long *)ctxt->cr2;
decode->dst.bytes = (decode->d & ByteOp) ? 1 : decode->op_bytes;
decode->dst.val = 0;
if (decode->d & BitOp) {
@@ -927,7 +955,6 @@ done_prefixes:
&decode->dst.val,
decode->dst.bytes, ctxt->vcpu)) != 0))
goto done;
- break;
}
decode->dst.orig_val = decode->dst.val;
@@ -985,7 +1012,7 @@ done_prefixes:
emulate_2op_SrcV("cmp", decode->src, decode->dst, _eflags);
break;
case 0x63: /* movsxd */
- if (mode != X86EMUL_MODE_PROT64)
+ if (ctxt->mode != X86EMUL_MODE_PROT64)
goto cannot_emulate;
decode->dst.val = (s32) decode->src.val;
break;
@@ -1056,7 +1083,7 @@ push:
break;
case 0x8f: /* pop (sole member of Grp1a) */
/* 64-bit mode: POP always pops a 64-bit operand. */
- if (mode == X86EMUL_MODE_PROT64)
+ if (ctxt->mode == X86EMUL_MODE_PROT64)
decode->dst.bytes = 8;
if ((rc = ops->read_std(register_address(
ctxt->ss_base,
@@ -1202,7 +1229,7 @@ push:
break;
case 6: /* push */
/* 64-bit mode: PUSH always pushes a 64-bit operand. */
- if (mode == X86EMUL_MODE_PROT64) {
+ if (ctxt->mode == X86EMUL_MODE_PROT64) {
decode->dst.bytes = 8;
if ((rc = ops->read_std(
(unsigned long)decode->dst.ptr,
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
reply other threads:[~2007-09-18 9:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=46EF99F7.6010205@bull.net \
--to=laurent.vivier-6ktuutfb/bm@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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.