move all decoding process to function x86_decode_insn().
Signed-off-by: Laurent Vivier <[EMAIL PROTECTED]>
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,
-------------------------------------------------------------------------
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/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel