aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86_emulate.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2008-06-16 00:53:26 -0400
committerAvi Kivity <avi@qumranet.com>2008-07-20 05:42:33 -0400
commit84411d85dacdb6665578608c6a70fc8b819761a8 (patch)
tree9adcee7b8938b47f57fb964adb7d3939245f44fd /arch/x86/kvm/x86_emulate.c
parentdc71d0f1620790ec8e54101ca37e7b31e31208a8 (diff)
KVM: x86 emulator: simplify r/m decoding
Consolidate the duplicated code when not in any special case. 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.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index ca7ab2469a4..c3a823174f3 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -740,9 +740,7 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
740 c->modrm_ea = (u16)c->modrm_ea; 740 c->modrm_ea = (u16)c->modrm_ea;
741 } else { 741 } else {
742 /* 32/64-bit ModR/M decode. */ 742 /* 32/64-bit ModR/M decode. */
743 switch (c->modrm_rm) { 743 if ((c->modrm_rm & 7) == 4) {
744 case 4:
745 case 12:
746 sib = insn_fetch(u8, 1, c->eip); 744 sib = insn_fetch(u8, 1, c->eip);
747 index_reg |= (sib >> 3) & 7; 745 index_reg |= (sib >> 3) & 7;
748 base_reg |= sib & 7; 746 base_reg |= sib & 7;
@@ -754,18 +752,11 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
754 c->modrm_ea += c->regs[base_reg]; 752 c->modrm_ea += c->regs[base_reg];
755 if (index_reg != 4) 753 if (index_reg != 4)
756 c->modrm_ea += c->regs[index_reg] << scale; 754 c->modrm_ea += c->regs[index_reg] << scale;
757 break; 755 } else if ((c->modrm_rm & 7) == 5 && c->modrm_mod == 0) {
758 case 5: 756 if (ctxt->mode == X86EMUL_MODE_PROT64)
759 case 13:
760 if (c->modrm_mod != 0)
761 c->modrm_ea += c->regs[c->modrm_rm];
762 else if (ctxt->mode == X86EMUL_MODE_PROT64)
763 rip_relative = 1; 757 rip_relative = 1;
764 break; 758 } else
765 default:
766 c->modrm_ea += c->regs[c->modrm_rm]; 759 c->modrm_ea += c->regs[c->modrm_rm];
767 break;
768 }
769 switch (c->modrm_mod) { 760 switch (c->modrm_mod) {
770 case 0: 761 case 0:
771 if (c->modrm_rm == 5) 762 if (c->modrm_rm == 5)