From: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH 3/5] extract prefix decoding part from x86_emulate_memop() to x86_decode_prefix()
Date: Wed, 01 Aug 2007 11:16:06 +0200 [thread overview]
Message-ID: <46B04F56.60607@bull.net> (raw)
In-Reply-To: <46B04EB9.5010103-6ktuUTfB/bM@public.gmane.org>
[-- Attachment #1.1.1: Type: text/plain, Size: 283 bytes --]
Extract prefix decoding part from x86_emulate_memop() to x86_decode_prefix().
Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
--
------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org --------------
"Software is hard" - Donald Knuth
[-- Attachment #1.1.2: x86_decode_prefix --]
[-- Type: text/plain, Size: 5811 bytes --]
Index: kvm/drivers/kvm/x86_emulate.c
===================================================================
--- kvm.orig/drivers/kvm/x86_emulate.c 2007-07-31 17:44:35.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.c 2007-07-31 18:23:39.000000000 +0200
@@ -480,43 +480,24 @@
}
int
-x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
+x86_decode_prefix(int mode, u8 *inst, struct x86_prefix *prefix)
{
- unsigned d;
- u8 b, sib, twobyte = 0;
- u8 modrm, modrm_mod = 0;
- unsigned int i;
- int rc = 0;
- struct operand src, dst;
- unsigned long cr2 = ctxt->cr2;
- int mode = ctxt->mode;
- unsigned long modrm_ea;
- int use_modrm_ea, scale, rip_relative = 0;
- int no_wb = 0;
- u64 msr_data;
- struct x86_prefix prefix;
-
- /* Shadow copy of register state. Committed on successful emulation. */
- unsigned long _regs[NR_VCPU_REGS];
- unsigned long _eip = ctxt->vcpu->rip, _eflags = ctxt->eflags;
- unsigned long modrm_val = 0;
-
- memcpy(_regs, ctxt->vcpu->regs, sizeof _regs);
- memset(&prefix, 0, sizeof(prefix));
- prefix.override_base = -1;
+ unsigned int op_bytes, ad_bytes;
+ int i;
+ u8 b;
switch (mode) {
case X86EMUL_MODE_REAL:
case X86EMUL_MODE_PROT16:
- prefix.op_bytes = prefix.ad_bytes = 2;
+ op_bytes = ad_bytes = 2;
break;
case X86EMUL_MODE_PROT32:
- prefix.op_bytes = prefix.ad_bytes = 4;
+ op_bytes = ad_bytes = 4;
break;
#ifdef CONFIG_X86_64
case X86EMUL_MODE_PROT64:
- prefix.op_bytes = 4;
- prefix.ad_bytes = 8;
+ op_bytes = 4;
+ ad_bytes = 8;
break;
#endif
default:
@@ -525,39 +506,39 @@
/* Legacy prefixes. */
for (i = 0; i < 8; i++) {
- switch (b = insn_fetch(u8, 1, _eip)) {
+ switch (b = inst[i]) {
case 0x66: /* operand-size override */
- prefix.op_bytes ^= 6; /* switch between 2/4 bytes */
+ op_bytes ^= 6; /* switch between 2/4 bytes */
break;
case 0x67: /* address-size override */
if (mode == X86EMUL_MODE_PROT64)
- prefix.ad_bytes ^= 12; /* switch between 4/8 bytes */
+ ad_bytes ^= 12; /* switch between 4/8 bytes */
else
- prefix.ad_bytes ^= 6; /* switch between 2/4 bytes */
+ ad_bytes ^= 6; /* switch between 2/4 bytes */
break;
case 0x2e: /* CS override */
- prefix.override_base = X86EMUL_BASE_CS;
+ prefix->override_base = X86EMUL_BASE_CS;
break;
case 0x3e: /* DS override */
- prefix.override_base = X86EMUL_BASE_DS;
+ prefix->override_base = X86EMUL_BASE_DS;
break;
case 0x26: /* ES override */
- prefix.override_base = X86EMUL_BASE_ES;
+ prefix->override_base = X86EMUL_BASE_ES;
break;
case 0x64: /* FS override */
- prefix.override_base = X86EMUL_BASE_FS;
+ prefix->override_base = X86EMUL_BASE_FS;
break;
case 0x65: /* GS override */
- prefix.override_base = X86EMUL_BASE_GS;
+ prefix->override_base = X86EMUL_BASE_GS;
break;
case 0x36: /* SS override */
- prefix.override_base = X86EMUL_BASE_SS;
+ prefix->override_base = X86EMUL_BASE_SS;
break;
case 0xf0: /* LOCK */
- prefix.lock = 1;
+ prefix->lock = 1;
break;
case 0xf3: /* REP/REPE/REPZ */
- prefix.rep = 1;
+ prefix->rep = 1;
break;
case 0xf2: /* REPNE/REPNZ */
break;
@@ -570,15 +551,62 @@
/* REX prefix. */
if ((mode == X86EMUL_MODE_PROT64) && ((b & 0xf0) == 0x40)) {
- prefix.rex = b;
+ prefix->rex = b;
if (b & 8)
- prefix.op_bytes = 8; /* REX.W */
- prefix.modrm_reg = (b & 4) << 1; /* REX.R */
- prefix.index_reg = (b & 2) << 2; /* REX.X */
- prefix.modrm_rm = prefix.base_reg = (b & 1) << 3; /* REG.B */
- b = insn_fetch(u8, 1, _eip);
+ op_bytes = 8; /* REX.W */
+ prefix->modrm_reg = (b & 4) << 1; /* REX.R */
+ prefix->index_reg = (b & 2) << 2; /* REX.X */
+ prefix->modrm_rm = prefix->base_reg = (b & 1) << 3; /* REG.B */
+ i++;
}
+ prefix->op_bytes = op_bytes;
+ prefix->ad_bytes = ad_bytes;
+
+ return i;
+}
+EXPORT_SYMBOL_GPL(x86_decode_prefix);
+
+int
+x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
+{
+ unsigned d;
+ u8 b, sib, twobyte = 0;
+ u8 modrm, modrm_mod = 0;
+ int rc = 0;
+ struct operand src, dst;
+ unsigned long cr2 = ctxt->cr2;
+ int mode = ctxt->mode;
+ unsigned long modrm_ea;
+ int use_modrm_ea, scale, rip_relative = 0;
+ int no_wb = 0;
+ u64 msr_data, inst;
+ struct x86_prefix prefix;
+ int count;
+
+ /* Shadow copy of register state. Committed on successful emulation. */
+ unsigned long _regs[NR_VCPU_REGS];
+ unsigned long _eip = ctxt->vcpu->rip, _eflags = ctxt->eflags;
+ unsigned long modrm_val = 0;
+
+ memcpy(_regs, ctxt->vcpu->regs, sizeof _regs);
+
+ /* decode prefixes */
+
+ rc = ops->read_std(_eip + ctxt->base[X86EMUL_BASE_CS],
+ &inst, sizeof(inst), ctxt->vcpu);
+ if ( rc != 0 )
+ goto done;
+
+ memset(&prefix, 0, sizeof(prefix));
+ prefix.override_base = -1;
+
+ count = x86_decode_prefix(mode, (u8*)&inst, &prefix);
+ if (count == -1)
+ return -1;
+ _eip += count;
+ b = insn_fetch(u8, 1, _eip);
+
/* Opcode byte(s). */
d = opcode_table[b];
if (d == 0) {
Index: kvm/drivers/kvm/x86_emulate.h
===================================================================
--- kvm.orig/drivers/kvm/x86_emulate.h 2007-07-31 18:00:51.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.h 2007-07-31 18:01:53.000000000 +0200
@@ -164,6 +164,13 @@
#endif
/*
+ * x86_decode_prefix: Decode instruction prefixes
+ * Returns -1 on failure, 0 on success.
+ */
+int
+x86_decode_prefix(int mode, u8 *inst, struct x86_prefix *prefix);
+
+/*
* x86_emulate_memop: Emulate an instruction that faulted attempting to
* read/write a 'special' memory area.
* Returns -1 on failure, 0 on success.
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
[-- Attachment #2: 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 #3: 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
next prev parent reply other threads:[~2007-08-01 9:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-01 9:05 PATCH 0/5] Consolidate the insb/outsb emulation into x86_emulate.c Laurent Vivier
[not found] ` <46B04CCA.2010503-6ktuUTfB/bM@public.gmane.org>
2007-08-01 9:09 ` [PATCH 1/5] change ctxt.*_base to an array ctxt.base[X86EMUL_BASE_*] Laurent Vivier
[not found] ` <46B04DD6.7010702-6ktuUTfB/bM@public.gmane.org>
2007-08-01 9:13 ` [PATCH 2/5] group all prefix decoding results in a structure called x86_prefix Laurent Vivier
[not found] ` <46B04EB9.5010103-6ktuUTfB/bM@public.gmane.org>
2007-08-01 9:16 ` Laurent Vivier [this message]
[not found] ` <46B04F56.60607-6ktuUTfB/bM@public.gmane.org>
2007-08-01 9:19 ` [PATCH 4/5] vmx.c uses x86_decode_prefix() instead of get_io_count() Laurent Vivier
[not found] ` <46B0501C.6060409-6ktuUTfB/bM@public.gmane.org>
2007-08-01 9:22 ` [PATCH 5/5] svm.c uses x86_decode_prefix() instead of io_address() and io_get_override() Laurent Vivier
2007-08-02 8:48 ` [PATCH 4/5] vmx.c uses x86_decode_prefix() instead of get_io_count() Avi Kivity
[not found] ` <46B19A7B.2030109-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-02 9:34 ` Laurent Vivier
[not found] ` <46B1A51C.2040104-6ktuUTfB/bM@public.gmane.org>
2007-08-02 9:41 ` Avi Kivity
[not found] ` <46B1A6B8.7020404-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-02 16:46 ` Laurent Vivier
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=46B04F56.60607@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.