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-08-29 18:04:53.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.c 2007-08-29 18:06:12.000000000 +0200
@@ -488,20 +488,16 @@ static int read_descriptor(struct x86_em
}
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;
@@ -759,7 +755,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:
;
}
@@ -810,12 +806,6 @@ done_prefixes:
decode->op_bytes;
srcmem_common:
decode->src.type = OP_MEM;
- decode->src.ptr = (unsigned long *)cr2;
- 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;
@@ -848,7 +838,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)
@@ -877,8 +867,48 @@ done_prefixes:
break;
case DstMem:
decode->dst.type = OP_MEM;
- decode->dst.ptr = (unsigned long *)cr2;
decode->dst.bytes = (decode->d & ByteOp) ? 1 : decode->op_bytes;
+ break;
+ }
+ decode->dst.orig_val = decode->dst.val;
+
+done:
+ return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0;
+
+cannot_emulate:
+ DPRINTF("Cannot emulate %02x\n", decode->b);
+ return -1;
+}
+
+int
+x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
+{
+ struct decode_cache *decode = &ctxt->decode;
+ int rc;
+ int mode = ctxt->mode;
+ int no_wb = 0;
+ u64 msr_data;
+ unsigned long _eflags = ctxt->eflags;
+
+ rc = x86_decode_insn(ctxt, ops);
+ if (rc)
+ return rc;
+
+ if (decode->src.type == OP_MEM) {
+ decode->src.ptr = (unsigned long *)ctxt->cr2;
+ 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;
if (decode->d & BitOp) {
unsigned long mask = ~(decode->dst.bytes * 8 - 1);
@@ -891,9 +921,7 @@ done_prefixes:
&decode->dst.val,
decode->dst.bytes, ctxt->vcpu)) != 0))
goto done;
- break;
}
- decode->dst.orig_val = decode->dst.val;
if (decode->twobyte)
goto twobyte_insn;
@@ -1280,7 +1308,7 @@ special_insn:
case 0xaa ... 0xab: /* stos */
decode->dst.type = OP_MEM;
decode->dst.bytes = (decode->d & ByteOp) ? 1 : decode->op_bytes;
- decode->dst.ptr = (unsigned long *)cr2;
+ decode->dst.ptr = (unsigned long *)ctxt->cr2;
decode->dst.val = decode->regs[VCPU_REGS_RAX];
register_address_increment(decode->regs[VCPU_REGS_RDI],
(_eflags & EFLG_DF) ? -decode->dst.bytes :
@@ -1290,7 +1318,7 @@ special_insn:
decode->dst.type = OP_REG;
decode->dst.bytes = (decode->d & ByteOp) ? 1 : decode->op_bytes;
decode->dst.ptr = (unsigned long *)&decode->regs[VCPU_REGS_RAX];
- if ((rc = ops->read_emulated(cr2, &decode->dst.val,
+ if ((rc = ops->read_emulated(ctxt->cr2, &decode->dst.val,
decode->dst.bytes,
ctxt->vcpu)) != 0)
goto done;
@@ -1360,7 +1388,7 @@ twobyte_insn:
(u16)decode->modrm_val, &_eflags);
break;
case 7: /* invlpg*/
- emulate_invlpg(ctxt->vcpu, cr2);
+ emulate_invlpg(ctxt->vcpu, ctxt->cr2);
break;
default:
goto cannot_emulate;
@@ -1540,8 +1568,8 @@ twobyte_special_insn:
case 0xc7: /* Grp9 (cmpxchg8b) */
{
u64 old, new;
- if ((rc = ops->read_emulated(cr2, &old, 8, ctxt->vcpu))
- != 0)
+ if ((rc = ops->read_emulated(ctxt->cr2,
+ &old, 8, ctxt->vcpu)) != 0)
goto done;
if (((u32) (old >> 0) !=
(u32) decode->regs[VCPU_REGS_RAX]) ||
@@ -1553,7 +1581,7 @@ twobyte_special_insn:
} else {
new = ((u64)decode->regs[VCPU_REGS_RCX] << 32)
| (u32) decode->regs[VCPU_REGS_RBX];
- if ((rc = ops->cmpxchg_emulated(cr2, &old,
+ if ((rc = ops->cmpxchg_emulated(ctxt->cr2, &old,
&new, 8, ctxt->vcpu))
!= 0)
goto done;
_eflags |= EFLG_ZF;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel