aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86_emulate.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2008-01-18 05:38:59 -0500
committerAvi Kivity <avi@qumranet.com>2008-04-27 04:53:14 -0400
commite09d082c03e137015bc0a17ca77e4b9dca08a5d7 (patch)
treebde45c9b0015445a777f1a20a88048721d9387e3 /arch/x86/kvm/x86_emulate.c
parent1ae0a13def678876b9acfb5ac1e2cf7d5d45a60d (diff)
KVM: x86 emulator: add support for group decoding
Certain x86 instructions use bits 3:5 of the byte following the opcode as an opcode extension, with the decode sometimes depending on bits 6:7 as well. Add support for this in the main decoding table rather than an ad-hock adaptation per opcode. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'arch/x86/kvm/x86_emulate.c')
-rw-r--r--arch/x86/kvm/x86_emulate.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index 79586003397a..46ecf349a116 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -65,6 +65,9 @@
65#define MemAbs (1<<9) /* Memory operand is absolute displacement */ 65#define MemAbs (1<<9) /* Memory operand is absolute displacement */
66#define String (1<<10) /* String instruction (rep capable) */ 66#define String (1<<10) /* String instruction (rep capable) */
67#define Stack (1<<11) /* Stack instruction (push/pop) */ 67#define Stack (1<<11) /* Stack instruction (push/pop) */
68#define Group (1<<14) /* Bits 3:5 of modrm byte extend opcode */
69#define GroupDual (1<<15) /* Alternate decoding of mod == 3 */
70#define GroupMask 0xff /* Group number stored in bits 0:7 */
68 71
69static u16 opcode_table[256] = { 72static u16 opcode_table[256] = {
70 /* 0x00 - 0x07 */ 73 /* 0x00 - 0x07 */
@@ -229,6 +232,12 @@ static u16 twobyte_table[256] = {
229 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 232 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
230}; 233};
231 234
235static u16 group_table[] = {
236};
237
238static u16 group2_table[] = {
239};
240
232/* EFLAGS bit definitions. */ 241/* EFLAGS bit definitions. */
233#define EFLG_OF (1<<11) 242#define EFLG_OF (1<<11)
234#define EFLG_DF (1<<10) 243#define EFLG_DF (1<<10)
@@ -763,7 +772,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
763 struct decode_cache *c = &ctxt->decode; 772 struct decode_cache *c = &ctxt->decode;
764 int rc = 0; 773 int rc = 0;
765 int mode = ctxt->mode; 774 int mode = ctxt->mode;
766 int def_op_bytes, def_ad_bytes; 775 int def_op_bytes, def_ad_bytes, group;
767 776
768 /* Shadow copy of register state. Committed on successful emulation. */ 777 /* Shadow copy of register state. Committed on successful emulation. */
769 778
@@ -864,12 +873,24 @@ done_prefixes:
864 c->b = insn_fetch(u8, 1, c->eip); 873 c->b = insn_fetch(u8, 1, c->eip);
865 c->d = twobyte_table[c->b]; 874 c->d = twobyte_table[c->b];
866 } 875 }
876 }
867 877
868 /* Unrecognised? */ 878 if (c->d & Group) {
869 if (c->d == 0) { 879 group = c->d & GroupMask;
870 DPRINTF("Cannot emulate %02x\n", c->b); 880 c->modrm = insn_fetch(u8, 1, c->eip);
871 return -1; 881 --c->eip;
872 } 882
883 group = (group << 3) + ((c->modrm >> 3) & 7);
884 if ((c->d & GroupDual) && (c->modrm >> 6) == 3)
885 c->d = group2_table[group];
886 else
887 c->d = group_table[group];
888 }
889
890 /* Unrecognised? */
891 if (c->d == 0) {
892 DPRINTF("Cannot emulate %02x\n", c->b);
893 return -1;
873 } 894 }
874 895
875 if (mode == X86EMUL_MODE_PROT64 && (c->d & Stack)) 896 if (mode == X86EMUL_MODE_PROT64 && (c->d & Stack))