Commit 7d9ddaed authored by Avi Kivity's avatar Avi Kivity

KVM: x86 emulator: clean up control flow in x86_emulate_insn()

x86_emulate_insn() is full of things like

    if (rc != X86EMUL_CONTINUE)
        goto done;
    break;

consolidate all of those at the end of the switch statement.
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent a4d4a7c1
...@@ -3098,8 +3098,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3098,8 +3098,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0x07: /* pop es */ case 0x07: /* pop es */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES); rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0x08 ... 0x0d: case 0x08 ... 0x0d:
or: /* or */ or: /* or */
...@@ -3117,8 +3115,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3117,8 +3115,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0x17: /* pop ss */ case 0x17: /* pop ss */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS); rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0x18 ... 0x1d: case 0x18 ... 0x1d:
sbb: /* sbb */ sbb: /* sbb */
...@@ -3129,8 +3125,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3129,8 +3125,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0x1f: /* pop ds */ case 0x1f: /* pop ds */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS); rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0x20 ... 0x25: case 0x20 ... 0x25:
and: /* and */ and: /* and */
...@@ -3157,18 +3151,12 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3157,18 +3151,12 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
case 0x58 ... 0x5f: /* pop reg */ case 0x58 ... 0x5f: /* pop reg */
pop_instruction: pop_instruction:
rc = emulate_pop(ctxt, ops, &c->dst.val, c->op_bytes); rc = emulate_pop(ctxt, ops, &c->dst.val, c->op_bytes);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0x60: /* pusha */ case 0x60: /* pusha */
rc = emulate_pusha(ctxt, ops); rc = emulate_pusha(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0x61: /* popa */ case 0x61: /* popa */
rc = emulate_popa(ctxt, ops); rc = emulate_popa(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0x63: /* movsxd */ case 0x63: /* movsxd */
if (ctxt->mode != X86EMUL_MODE_PROT64) if (ctxt->mode != X86EMUL_MODE_PROT64)
...@@ -3255,8 +3243,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3255,8 +3243,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
} }
case 0x8f: /* pop (sole member of Grp1a) */ case 0x8f: /* pop (sole member of Grp1a) */
rc = emulate_grp1a(ctxt, ops); rc = emulate_grp1a(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0x90 ... 0x97: /* nop / xchg reg, rax */ case 0x90 ... 0x97: /* nop / xchg reg, rax */
if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX]) if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX])
...@@ -3278,8 +3264,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3278,8 +3264,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
c->dst.addr.reg = &ctxt->eflags; c->dst.addr.reg = &ctxt->eflags;
c->dst.bytes = c->op_bytes; c->dst.bytes = c->op_bytes;
rc = emulate_popf(ctxt, ops, &c->dst.val, c->op_bytes); rc = emulate_popf(ctxt, ops, &c->dst.val, c->op_bytes);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xa6 ... 0xa7: /* cmps */ case 0xa6 ... 0xa7: /* cmps */
c->dst.type = OP_NONE; /* Disable writeback. */ c->dst.type = OP_NONE; /* Disable writeback. */
...@@ -3299,18 +3283,12 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3299,18 +3283,12 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
goto pop_instruction; goto pop_instruction;
case 0xc4: /* les */ case 0xc4: /* les */
rc = emulate_load_segment(ctxt, ops, VCPU_SREG_ES); rc = emulate_load_segment(ctxt, ops, VCPU_SREG_ES);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xc5: /* lds */ case 0xc5: /* lds */
rc = emulate_load_segment(ctxt, ops, VCPU_SREG_DS); rc = emulate_load_segment(ctxt, ops, VCPU_SREG_DS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xcb: /* ret far */ case 0xcb: /* ret far */
rc = emulate_ret_far(ctxt, ops); rc = emulate_ret_far(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xcc: /* int3 */ case 0xcc: /* int3 */
irq = 3; irq = 3;
...@@ -3319,8 +3297,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3319,8 +3297,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
irq = c->src.val; irq = c->src.val;
do_interrupt: do_interrupt:
rc = emulate_int(ctxt, ops, irq); rc = emulate_int(ctxt, ops, irq);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xce: /* into */ case 0xce: /* into */
if (ctxt->eflags & EFLG_OF) { if (ctxt->eflags & EFLG_OF) {
...@@ -3330,9 +3306,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3330,9 +3306,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0xcf: /* iret */ case 0xcf: /* iret */
rc = emulate_iret(ctxt, ops); rc = emulate_iret(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xd0 ... 0xd1: /* Grp2 */ case 0xd0 ... 0xd1: /* Grp2 */
emulate_grp2(ctxt); emulate_grp2(ctxt);
...@@ -3419,8 +3392,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3419,8 +3392,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0xf6 ... 0xf7: /* Grp3 */ case 0xf6 ... 0xf7: /* Grp3 */
rc = emulate_grp3(ctxt, ops); rc = emulate_grp3(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xf8: /* clc */ case 0xf8: /* clc */
ctxt->eflags &= ~EFLG_CF; ctxt->eflags &= ~EFLG_CF;
...@@ -3453,8 +3424,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3453,8 +3424,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
case 0xfe: /* Grp4 */ case 0xfe: /* Grp4 */
grp45: grp45:
rc = emulate_grp45(ctxt, ops); rc = emulate_grp45(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xff: /* Grp5 */ case 0xff: /* Grp5 */
if (c->modrm_reg == 5) if (c->modrm_reg == 5)
...@@ -3464,6 +3433,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3464,6 +3433,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
goto cannot_emulate; goto cannot_emulate;
} }
if (rc != X86EMUL_CONTINUE)
goto done;
writeback: writeback:
rc = writeback(ctxt, ops); rc = writeback(ctxt, ops);
if (rc != X86EMUL_CONTINUE) if (rc != X86EMUL_CONTINUE)
...@@ -3545,8 +3517,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3545,8 +3517,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
switch (c->modrm_rm) { switch (c->modrm_rm) {
case 1: case 1:
rc = kvm_fix_hypercall(ctxt->vcpu); rc = kvm_fix_hypercall(ctxt->vcpu);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
default: default:
goto cannot_emulate; goto cannot_emulate;
...@@ -3585,10 +3555,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3585,10 +3555,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0x05: /* syscall */ case 0x05: /* syscall */
rc = emulate_syscall(ctxt, ops); rc = emulate_syscall(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
else
goto writeback;
break; break;
case 0x06: case 0x06:
emulate_clts(ctxt->vcpu); emulate_clts(ctxt->vcpu);
...@@ -3665,17 +3631,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3665,17 +3631,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0x34: /* sysenter */ case 0x34: /* sysenter */
rc = emulate_sysenter(ctxt, ops); rc = emulate_sysenter(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
else
goto writeback;
break; break;
case 0x35: /* sysexit */ case 0x35: /* sysexit */
rc = emulate_sysexit(ctxt, ops); rc = emulate_sysexit(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
else
goto writeback;
break; break;
case 0x40 ... 0x4f: /* cmov */ case 0x40 ... 0x4f: /* cmov */
c->dst.val = c->dst.orig_val = c->src.val; c->dst.val = c->dst.orig_val = c->src.val;
...@@ -3694,8 +3652,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3694,8 +3652,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0xa1: /* pop fs */ case 0xa1: /* pop fs */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_FS); rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_FS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xa3: case 0xa3:
bt: /* bt */ bt: /* bt */
...@@ -3713,8 +3669,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3713,8 +3669,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0xa9: /* pop gs */ case 0xa9: /* pop gs */
rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_GS); rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_GS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xab: case 0xab:
bts: /* bts */ bts: /* bts */
...@@ -3745,8 +3699,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3745,8 +3699,6 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0xb2: /* lss */ case 0xb2: /* lss */
rc = emulate_load_segment(ctxt, ops, VCPU_SREG_SS); rc = emulate_load_segment(ctxt, ops, VCPU_SREG_SS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xb3: case 0xb3:
btr: /* btr */ btr: /* btr */
...@@ -3754,13 +3706,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3754,13 +3706,9 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0xb4: /* lfs */ case 0xb4: /* lfs */
rc = emulate_load_segment(ctxt, ops, VCPU_SREG_FS); rc = emulate_load_segment(ctxt, ops, VCPU_SREG_FS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xb5: /* lgs */ case 0xb5: /* lgs */
rc = emulate_load_segment(ctxt, ops, VCPU_SREG_GS); rc = emulate_load_segment(ctxt, ops, VCPU_SREG_GS);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
case 0xb6 ... 0xb7: /* movzx */ case 0xb6 ... 0xb7: /* movzx */
c->dst.bytes = c->op_bytes; c->dst.bytes = c->op_bytes;
...@@ -3825,12 +3773,14 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) ...@@ -3825,12 +3773,14 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
break; break;
case 0xc7: /* Grp9 (cmpxchg8b) */ case 0xc7: /* Grp9 (cmpxchg8b) */
rc = emulate_grp9(ctxt, ops); rc = emulate_grp9(ctxt, ops);
if (rc != X86EMUL_CONTINUE)
goto done;
break; break;
default: default:
goto cannot_emulate; goto cannot_emulate;
} }
if (rc != X86EMUL_CONTINUE)
goto done;
goto writeback; goto writeback;
cannot_emulate: cannot_emulate:
......
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