From: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH 3/5] move all decoding process to function x86_decode_insn().
Date: Wed, 29 Aug 2007 18:43:40 +0200 [thread overview]
Message-ID: <46D5A23C.5020504@bull.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 134 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: 5022 bytes --]
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;
[-- Attachment #3: Type: text/plain, Size: 315 bytes --]
-------------------------------------------------------------------------
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/
[-- 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-08-29 16:43 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=46D5A23C.5020504@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox