diff options
author | Avi Kivity <avi@redhat.com> | 2010-08-30 10:12:28 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-10-24 04:51:54 -0400 |
commit | 7d9ddaedd8a9d0442fda5b5a90f22a33becbd235 (patch) | |
tree | e1784c42c41e2a981378e3a24e5befc6c6fc9d79 /arch | |
parent | a4d4a7c1880db98a521bc27c15348185fa30c256 (diff) |
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: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/kvm/emulate.c | 64 |
1 files changed, 7 insertions, 57 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 9940d1661544..27d2c22b114e 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -3098,8 +3098,6 @@ special_insn: | |||
3098 | break; | 3098 | break; |
3099 | case 0x07: /* pop es */ | 3099 | case 0x07: /* pop es */ |
3100 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES); | 3100 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES); |
3101 | if (rc != X86EMUL_CONTINUE) | ||
3102 | goto done; | ||
3103 | break; | 3101 | break; |
3104 | case 0x08 ... 0x0d: | 3102 | case 0x08 ... 0x0d: |
3105 | or: /* or */ | 3103 | or: /* or */ |
@@ -3117,8 +3115,6 @@ special_insn: | |||
3117 | break; | 3115 | break; |
3118 | case 0x17: /* pop ss */ | 3116 | case 0x17: /* pop ss */ |
3119 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS); | 3117 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS); |
3120 | if (rc != X86EMUL_CONTINUE) | ||
3121 | goto done; | ||
3122 | break; | 3118 | break; |
3123 | case 0x18 ... 0x1d: | 3119 | case 0x18 ... 0x1d: |
3124 | sbb: /* sbb */ | 3120 | sbb: /* sbb */ |
@@ -3129,8 +3125,6 @@ special_insn: | |||
3129 | break; | 3125 | break; |
3130 | case 0x1f: /* pop ds */ | 3126 | case 0x1f: /* pop ds */ |
3131 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS); | 3127 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS); |
3132 | if (rc != X86EMUL_CONTINUE) | ||
3133 | goto done; | ||
3134 | break; | 3128 | break; |
3135 | case 0x20 ... 0x25: | 3129 | case 0x20 ... 0x25: |
3136 | and: /* and */ | 3130 | and: /* and */ |
@@ -3157,18 +3151,12 @@ special_insn: | |||
3157 | case 0x58 ... 0x5f: /* pop reg */ | 3151 | case 0x58 ... 0x5f: /* pop reg */ |
3158 | pop_instruction: | 3152 | pop_instruction: |
3159 | rc = emulate_pop(ctxt, ops, &c->dst.val, c->op_bytes); | 3153 | rc = emulate_pop(ctxt, ops, &c->dst.val, c->op_bytes); |
3160 | if (rc != X86EMUL_CONTINUE) | ||
3161 | goto done; | ||
3162 | break; | 3154 | break; |
3163 | case 0x60: /* pusha */ | 3155 | case 0x60: /* pusha */ |
3164 | rc = emulate_pusha(ctxt, ops); | 3156 | rc = emulate_pusha(ctxt, ops); |
3165 | if (rc != X86EMUL_CONTINUE) | ||
3166 | goto done; | ||
3167 | break; | 3157 | break; |
3168 | case 0x61: /* popa */ | 3158 | case 0x61: /* popa */ |
3169 | rc = emulate_popa(ctxt, ops); | 3159 | rc = emulate_popa(ctxt, ops); |
3170 | if (rc != X86EMUL_CONTINUE) | ||
3171 | goto done; | ||
3172 | break; | 3160 | break; |
3173 | case 0x63: /* movsxd */ | 3161 | case 0x63: /* movsxd */ |
3174 | if (ctxt->mode != X86EMUL_MODE_PROT64) | 3162 | if (ctxt->mode != X86EMUL_MODE_PROT64) |
@@ -3255,8 +3243,6 @@ special_insn: | |||
3255 | } | 3243 | } |
3256 | case 0x8f: /* pop (sole member of Grp1a) */ | 3244 | case 0x8f: /* pop (sole member of Grp1a) */ |
3257 | rc = emulate_grp1a(ctxt, ops); | 3245 | rc = emulate_grp1a(ctxt, ops); |
3258 | if (rc != X86EMUL_CONTINUE) | ||
3259 | goto done; | ||
3260 | break; | 3246 | break; |
3261 | case 0x90 ... 0x97: /* nop / xchg reg, rax */ | 3247 | case 0x90 ... 0x97: /* nop / xchg reg, rax */ |
3262 | if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX]) | 3248 | if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX]) |
@@ -3278,8 +3264,6 @@ special_insn: | |||
3278 | c->dst.addr.reg = &ctxt->eflags; | 3264 | c->dst.addr.reg = &ctxt->eflags; |
3279 | c->dst.bytes = c->op_bytes; | 3265 | c->dst.bytes = c->op_bytes; |
3280 | rc = emulate_popf(ctxt, ops, &c->dst.val, c->op_bytes); | 3266 | rc = emulate_popf(ctxt, ops, &c->dst.val, c->op_bytes); |
3281 | if (rc != X86EMUL_CONTINUE) | ||
3282 | goto done; | ||
3283 | break; | 3267 | break; |
3284 | case 0xa6 ... 0xa7: /* cmps */ | 3268 | case 0xa6 ... 0xa7: /* cmps */ |
3285 | c->dst.type = OP_NONE; /* Disable writeback. */ | 3269 | c->dst.type = OP_NONE; /* Disable writeback. */ |
@@ -3299,18 +3283,12 @@ special_insn: | |||
3299 | goto pop_instruction; | 3283 | goto pop_instruction; |
3300 | case 0xc4: /* les */ | 3284 | case 0xc4: /* les */ |
3301 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_ES); | 3285 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_ES); |
3302 | if (rc != X86EMUL_CONTINUE) | ||
3303 | goto done; | ||
3304 | break; | 3286 | break; |
3305 | case 0xc5: /* lds */ | 3287 | case 0xc5: /* lds */ |
3306 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_DS); | 3288 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_DS); |
3307 | if (rc != X86EMUL_CONTINUE) | ||
3308 | goto done; | ||
3309 | break; | 3289 | break; |
3310 | case 0xcb: /* ret far */ | 3290 | case 0xcb: /* ret far */ |
3311 | rc = emulate_ret_far(ctxt, ops); | 3291 | rc = emulate_ret_far(ctxt, ops); |
3312 | if (rc != X86EMUL_CONTINUE) | ||
3313 | goto done; | ||
3314 | break; | 3292 | break; |
3315 | case 0xcc: /* int3 */ | 3293 | case 0xcc: /* int3 */ |
3316 | irq = 3; | 3294 | irq = 3; |
@@ -3319,8 +3297,6 @@ special_insn: | |||
3319 | irq = c->src.val; | 3297 | irq = c->src.val; |
3320 | do_interrupt: | 3298 | do_interrupt: |
3321 | rc = emulate_int(ctxt, ops, irq); | 3299 | rc = emulate_int(ctxt, ops, irq); |
3322 | if (rc != X86EMUL_CONTINUE) | ||
3323 | goto done; | ||
3324 | break; | 3300 | break; |
3325 | case 0xce: /* into */ | 3301 | case 0xce: /* into */ |
3326 | if (ctxt->eflags & EFLG_OF) { | 3302 | if (ctxt->eflags & EFLG_OF) { |
@@ -3330,9 +3306,6 @@ special_insn: | |||
3330 | break; | 3306 | break; |
3331 | case 0xcf: /* iret */ | 3307 | case 0xcf: /* iret */ |
3332 | rc = emulate_iret(ctxt, ops); | 3308 | rc = emulate_iret(ctxt, ops); |
3333 | |||
3334 | if (rc != X86EMUL_CONTINUE) | ||
3335 | goto done; | ||
3336 | break; | 3309 | break; |
3337 | case 0xd0 ... 0xd1: /* Grp2 */ | 3310 | case 0xd0 ... 0xd1: /* Grp2 */ |
3338 | emulate_grp2(ctxt); | 3311 | emulate_grp2(ctxt); |
@@ -3419,8 +3392,6 @@ special_insn: | |||
3419 | break; | 3392 | break; |
3420 | case 0xf6 ... 0xf7: /* Grp3 */ | 3393 | case 0xf6 ... 0xf7: /* Grp3 */ |
3421 | rc = emulate_grp3(ctxt, ops); | 3394 | rc = emulate_grp3(ctxt, ops); |
3422 | if (rc != X86EMUL_CONTINUE) | ||
3423 | goto done; | ||
3424 | break; | 3395 | break; |
3425 | case 0xf8: /* clc */ | 3396 | case 0xf8: /* clc */ |
3426 | ctxt->eflags &= ~EFLG_CF; | 3397 | ctxt->eflags &= ~EFLG_CF; |
@@ -3453,8 +3424,6 @@ special_insn: | |||
3453 | case 0xfe: /* Grp4 */ | 3424 | case 0xfe: /* Grp4 */ |
3454 | grp45: | 3425 | grp45: |
3455 | rc = emulate_grp45(ctxt, ops); | 3426 | rc = emulate_grp45(ctxt, ops); |
3456 | if (rc != X86EMUL_CONTINUE) | ||
3457 | goto done; | ||
3458 | break; | 3427 | break; |
3459 | case 0xff: /* Grp5 */ | 3428 | case 0xff: /* Grp5 */ |
3460 | if (c->modrm_reg == 5) | 3429 | if (c->modrm_reg == 5) |
@@ -3464,6 +3433,9 @@ special_insn: | |||
3464 | goto cannot_emulate; | 3433 | goto cannot_emulate; |
3465 | } | 3434 | } |
3466 | 3435 | ||
3436 | if (rc != X86EMUL_CONTINUE) | ||
3437 | goto done; | ||
3438 | |||
3467 | writeback: | 3439 | writeback: |
3468 | rc = writeback(ctxt, ops); | 3440 | rc = writeback(ctxt, ops); |
3469 | if (rc != X86EMUL_CONTINUE) | 3441 | if (rc != X86EMUL_CONTINUE) |
@@ -3545,8 +3517,6 @@ twobyte_insn: | |||
3545 | switch (c->modrm_rm) { | 3517 | switch (c->modrm_rm) { |
3546 | case 1: | 3518 | case 1: |
3547 | rc = kvm_fix_hypercall(ctxt->vcpu); | 3519 | rc = kvm_fix_hypercall(ctxt->vcpu); |
3548 | if (rc != X86EMUL_CONTINUE) | ||
3549 | goto done; | ||
3550 | break; | 3520 | break; |
3551 | default: | 3521 | default: |
3552 | goto cannot_emulate; | 3522 | goto cannot_emulate; |
@@ -3585,10 +3555,6 @@ twobyte_insn: | |||
3585 | break; | 3555 | break; |
3586 | case 0x05: /* syscall */ | 3556 | case 0x05: /* syscall */ |
3587 | rc = emulate_syscall(ctxt, ops); | 3557 | rc = emulate_syscall(ctxt, ops); |
3588 | if (rc != X86EMUL_CONTINUE) | ||
3589 | goto done; | ||
3590 | else | ||
3591 | goto writeback; | ||
3592 | break; | 3558 | break; |
3593 | case 0x06: | 3559 | case 0x06: |
3594 | emulate_clts(ctxt->vcpu); | 3560 | emulate_clts(ctxt->vcpu); |
@@ -3665,17 +3631,9 @@ twobyte_insn: | |||
3665 | break; | 3631 | break; |
3666 | case 0x34: /* sysenter */ | 3632 | case 0x34: /* sysenter */ |
3667 | rc = emulate_sysenter(ctxt, ops); | 3633 | rc = emulate_sysenter(ctxt, ops); |
3668 | if (rc != X86EMUL_CONTINUE) | ||
3669 | goto done; | ||
3670 | else | ||
3671 | goto writeback; | ||
3672 | break; | 3634 | break; |
3673 | case 0x35: /* sysexit */ | 3635 | case 0x35: /* sysexit */ |
3674 | rc = emulate_sysexit(ctxt, ops); | 3636 | rc = emulate_sysexit(ctxt, ops); |
3675 | if (rc != X86EMUL_CONTINUE) | ||
3676 | goto done; | ||
3677 | else | ||
3678 | goto writeback; | ||
3679 | break; | 3637 | break; |
3680 | case 0x40 ... 0x4f: /* cmov */ | 3638 | case 0x40 ... 0x4f: /* cmov */ |
3681 | c->dst.val = c->dst.orig_val = c->src.val; | 3639 | c->dst.val = c->dst.orig_val = c->src.val; |
@@ -3694,8 +3652,6 @@ twobyte_insn: | |||
3694 | break; | 3652 | break; |
3695 | case 0xa1: /* pop fs */ | 3653 | case 0xa1: /* pop fs */ |
3696 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_FS); | 3654 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_FS); |
3697 | if (rc != X86EMUL_CONTINUE) | ||
3698 | goto done; | ||
3699 | break; | 3655 | break; |
3700 | case 0xa3: | 3656 | case 0xa3: |
3701 | bt: /* bt */ | 3657 | bt: /* bt */ |
@@ -3713,8 +3669,6 @@ twobyte_insn: | |||
3713 | break; | 3669 | break; |
3714 | case 0xa9: /* pop gs */ | 3670 | case 0xa9: /* pop gs */ |
3715 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_GS); | 3671 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_GS); |
3716 | if (rc != X86EMUL_CONTINUE) | ||
3717 | goto done; | ||
3718 | break; | 3672 | break; |
3719 | case 0xab: | 3673 | case 0xab: |
3720 | bts: /* bts */ | 3674 | bts: /* bts */ |
@@ -3745,8 +3699,6 @@ twobyte_insn: | |||
3745 | break; | 3699 | break; |
3746 | case 0xb2: /* lss */ | 3700 | case 0xb2: /* lss */ |
3747 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_SS); | 3701 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_SS); |
3748 | if (rc != X86EMUL_CONTINUE) | ||
3749 | goto done; | ||
3750 | break; | 3702 | break; |
3751 | case 0xb3: | 3703 | case 0xb3: |
3752 | btr: /* btr */ | 3704 | btr: /* btr */ |
@@ -3754,13 +3706,9 @@ twobyte_insn: | |||
3754 | break; | 3706 | break; |
3755 | case 0xb4: /* lfs */ | 3707 | case 0xb4: /* lfs */ |
3756 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_FS); | 3708 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_FS); |
3757 | if (rc != X86EMUL_CONTINUE) | ||
3758 | goto done; | ||
3759 | break; | 3709 | break; |
3760 | case 0xb5: /* lgs */ | 3710 | case 0xb5: /* lgs */ |
3761 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_GS); | 3711 | rc = emulate_load_segment(ctxt, ops, VCPU_SREG_GS); |
3762 | if (rc != X86EMUL_CONTINUE) | ||
3763 | goto done; | ||
3764 | break; | 3712 | break; |
3765 | case 0xb6 ... 0xb7: /* movzx */ | 3713 | case 0xb6 ... 0xb7: /* movzx */ |
3766 | c->dst.bytes = c->op_bytes; | 3714 | c->dst.bytes = c->op_bytes; |
@@ -3825,12 +3773,14 @@ twobyte_insn: | |||
3825 | break; | 3773 | break; |
3826 | case 0xc7: /* Grp9 (cmpxchg8b) */ | 3774 | case 0xc7: /* Grp9 (cmpxchg8b) */ |
3827 | rc = emulate_grp9(ctxt, ops); | 3775 | rc = emulate_grp9(ctxt, ops); |
3828 | if (rc != X86EMUL_CONTINUE) | ||
3829 | goto done; | ||
3830 | break; | 3776 | break; |
3831 | default: | 3777 | default: |
3832 | goto cannot_emulate; | 3778 | goto cannot_emulate; |
3833 | } | 3779 | } |
3780 | |||
3781 | if (rc != X86EMUL_CONTINUE) | ||
3782 | goto done; | ||
3783 | |||
3834 | goto writeback; | 3784 | goto writeback; |
3835 | 3785 | ||
3836 | cannot_emulate: | 3786 | cannot_emulate: |