Commit 84411d85 authored by Avi Kivity's avatar Avi Kivity

KVM: x86 emulator: simplify r/m decoding

Consolidate the duplicated code when not in any special case.
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent dc71d0f1
...@@ -740,9 +740,7 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt, ...@@ -740,9 +740,7 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
c->modrm_ea = (u16)c->modrm_ea; c->modrm_ea = (u16)c->modrm_ea;
} else { } else {
/* 32/64-bit ModR/M decode. */ /* 32/64-bit ModR/M decode. */
switch (c->modrm_rm) { if ((c->modrm_rm & 7) == 4) {
case 4:
case 12:
sib = insn_fetch(u8, 1, c->eip); sib = insn_fetch(u8, 1, c->eip);
index_reg |= (sib >> 3) & 7; index_reg |= (sib >> 3) & 7;
base_reg |= sib & 7; base_reg |= sib & 7;
...@@ -754,18 +752,11 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt, ...@@ -754,18 +752,11 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
c->modrm_ea += c->regs[base_reg]; c->modrm_ea += c->regs[base_reg];
if (index_reg != 4) if (index_reg != 4)
c->modrm_ea += c->regs[index_reg] << scale; c->modrm_ea += c->regs[index_reg] << scale;
break; } else if ((c->modrm_rm & 7) == 5 && c->modrm_mod == 0) {
case 5: if (ctxt->mode == X86EMUL_MODE_PROT64)
case 13:
if (c->modrm_mod != 0)
c->modrm_ea += c->regs[c->modrm_rm];
else if (ctxt->mode == X86EMUL_MODE_PROT64)
rip_relative = 1; rip_relative = 1;
break; } else
default:
c->modrm_ea += c->regs[c->modrm_rm]; c->modrm_ea += c->regs[c->modrm_rm];
break;
}
switch (c->modrm_mod) { switch (c->modrm_mod) {
case 0: case 0:
if (c->modrm_rm == 5) if (c->modrm_rm == 5)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment