aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorMohammed Gamal <m.gamal005@gmail.com>2010-08-15 17:47:01 -0400
committerAvi Kivity <avi@redhat.com>2010-10-24 04:51:04 -0400
commit8ec4722dd2aab9b69befb919549ea0a5bfc9e670 (patch)
tree27001682b43f02ebc5a151d4cbfdc7ef1fb23f71 /arch/x86/kvm/x86.c
parentd9574a25afc3cd7ccd6a0bc05252bb84189e4021 (diff)
KVM: Separate emulation context initialization in a separate function
The code for initializing the emulation context is duplicated at two locations (emulate_instruction() and kvm_task_switch()). Separate it in a separate function and call it from there. Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 768197a34d3e..c0004eb354d3 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3931,6 +3931,28 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu)
3931 kvm_queue_exception(vcpu, ctxt->exception); 3931 kvm_queue_exception(vcpu, ctxt->exception);
3932} 3932}
3933 3933
3934static void init_emulate_ctxt(struct kvm_vcpu *vcpu)
3935{
3936 struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
3937 int cs_db, cs_l;
3938
3939 cache_all_regs(vcpu);
3940
3941 kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
3942
3943 vcpu->arch.emulate_ctxt.vcpu = vcpu;
3944 vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu);
3945 vcpu->arch.emulate_ctxt.eip = kvm_rip_read(vcpu);
3946 vcpu->arch.emulate_ctxt.mode =
3947 (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL :
3948 (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM)
3949 ? X86EMUL_MODE_VM86 : cs_l
3950 ? X86EMUL_MODE_PROT64 : cs_db
3951 ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
3952 memset(c, 0, sizeof(struct decode_cache));
3953 memcpy(c->regs, vcpu->arch.regs, sizeof c->regs);
3954}
3955
3934static int handle_emulation_failure(struct kvm_vcpu *vcpu) 3956static int handle_emulation_failure(struct kvm_vcpu *vcpu)
3935{ 3957{
3936 ++vcpu->stat.insn_emulation_fail; 3958 ++vcpu->stat.insn_emulation_fail;
@@ -3987,20 +4009,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
3987 cache_all_regs(vcpu); 4009 cache_all_regs(vcpu);
3988 4010
3989 if (!(emulation_type & EMULTYPE_NO_DECODE)) { 4011 if (!(emulation_type & EMULTYPE_NO_DECODE)) {
3990 int cs_db, cs_l; 4012 init_emulate_ctxt(vcpu);
3991 kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
3992
3993 vcpu->arch.emulate_ctxt.vcpu = vcpu;
3994 vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu);
3995 vcpu->arch.emulate_ctxt.eip = kvm_rip_read(vcpu);
3996 vcpu->arch.emulate_ctxt.mode =
3997 (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL :
3998 (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM)
3999 ? X86EMUL_MODE_VM86 : cs_l
4000 ? X86EMUL_MODE_PROT64 : cs_db
4001 ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
4002 memset(c, 0, sizeof(struct decode_cache));
4003 memcpy(c->regs, vcpu->arch.regs, sizeof c->regs);
4004 vcpu->arch.emulate_ctxt.interruptibility = 0; 4013 vcpu->arch.emulate_ctxt.interruptibility = 0;
4005 vcpu->arch.emulate_ctxt.exception = -1; 4014 vcpu->arch.emulate_ctxt.exception = -1;
4006 vcpu->arch.emulate_ctxt.perm_ok = false; 4015 vcpu->arch.emulate_ctxt.perm_ok = false;
@@ -5052,22 +5061,9 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason,
5052 bool has_error_code, u32 error_code) 5061 bool has_error_code, u32 error_code)
5053{ 5062{
5054 struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; 5063 struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
5055 int cs_db, cs_l, ret; 5064 int ret;
5056 cache_all_regs(vcpu);
5057
5058 kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
5059 5065
5060 vcpu->arch.emulate_ctxt.vcpu = vcpu; 5066 init_emulate_ctxt(vcpu);
5061 vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu);
5062 vcpu->arch.emulate_ctxt.eip = kvm_rip_read(vcpu);
5063 vcpu->arch.emulate_ctxt.mode =
5064 (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL :
5065 (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM)
5066 ? X86EMUL_MODE_VM86 : cs_l
5067 ? X86EMUL_MODE_PROT64 : cs_db
5068 ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
5069 memset(c, 0, sizeof(struct decode_cache));
5070 memcpy(c->regs, vcpu->arch.regs, sizeof c->regs);
5071 5067
5072 ret = emulator_task_switch(&vcpu->arch.emulate_ctxt, 5068 ret = emulator_task_switch(&vcpu->arch.emulate_ctxt,
5073 tss_selector, reason, has_error_code, 5069 tss_selector, reason, has_error_code,