Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 215635
b: refs/heads/master
c: 120df89
h: refs/heads/master
i:
  215633: f945ca6
  215631: 9a31039
v: v3
  • Loading branch information
Avi Kivity committed Oct 24, 2010
1 parent 21da72f commit b2c222a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 793d5a8d6baad9062b0a03e034944b31e50dfe5c
refs/heads/master: 120df8902dbe91cc1b3b7886481e350fae7334fe
47 changes: 38 additions & 9 deletions trunk/arch/x86/kvm/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,21 @@ enum {

struct opcode {
u32 flags;
union {
struct opcode *group;
struct group_dual *gdual;
} u;
};

struct group_dual {
struct opcode mod012[8];
struct opcode mod3[8];
};

#define D(_y) { .flags = (_y) }
#define N D(0)
#define G(_f, _g) { .flags = ((_f) | Group), .u.group = (_g) }
#define GD(_f, _g) { .flags = ((_f) | Group | GroupDual), .u.gdual = (_g) }

static struct opcode group_table[] = {
[Group1*8] =
Expand Down Expand Up @@ -331,6 +342,8 @@ static struct opcode twobyte_table[256] = {

#undef D
#undef N
#undef G
#undef GD

/* EFLAGS bit definitions. */
#define EFLG_ID (1<<21)
Expand Down Expand Up @@ -930,8 +943,8 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
struct decode_cache *c = &ctxt->decode;
int rc = X86EMUL_CONTINUE;
int mode = ctxt->mode;
int def_op_bytes, def_ad_bytes, group, dual;

int def_op_bytes, def_ad_bytes, group, dual, goffset;
struct opcode opcode, *g_mod012, *g_mod3;

/* we cannot decode insn before we complete previous rep insn */
WARN_ON(ctxt->restart);
Expand Down Expand Up @@ -1018,28 +1031,44 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
c->op_bytes = 8; /* REX.W */

/* Opcode byte(s). */
c->d = opcode_table[c->b].flags;
if (c->d == 0) {
opcode = opcode_table[c->b];
if (opcode.flags == 0) {
/* Two-byte opcode? */
if (c->b == 0x0f) {
c->twobyte = 1;
c->b = insn_fetch(u8, 1, c->eip);
c->d = twobyte_table[c->b].flags;
opcode = twobyte_table[c->b];
}
}
c->d = opcode.flags;

if (c->d & Group) {
group = c->d & GroupMask;
dual = c->d & GroupDual;
c->modrm = insn_fetch(u8, 1, c->eip);
--c->eip;

group = (group << 3) + ((c->modrm >> 3) & 7);
if (group) {
g_mod012 = g_mod3 = &group_table[group * 8];
if (c->d & GroupDual)
g_mod3 = &group2_table[group * 8];
} else {
if (c->d & GroupDual) {
g_mod012 = opcode.u.gdual->mod012;
g_mod3 = opcode.u.gdual->mod3;
} else
g_mod012 = g_mod3 = opcode.u.group;
}

c->d &= ~(Group | GroupDual | GroupMask);
if (dual && (c->modrm >> 6) == 3)
c->d |= group2_table[group].flags;

goffset = (c->modrm >> 3) & 7;

if ((c->modrm >> 6) == 3)
opcode = g_mod3[goffset];
else
c->d |= group_table[group].flags;
opcode = g_mod012[goffset];
c->d |= opcode.flags;
}

/* Unrecognised? */
Expand Down

0 comments on commit b2c222a

Please sign in to comment.