diff options
author | Avi Kivity <avi@redhat.com> | 2011-06-01 08:34:25 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-07-12 06:16:09 -0400 |
commit | 9dac77fa4011bdb4b541a8db087eac96a602faec (patch) | |
tree | 13305ebc63f91513d9ff579748fd73385603c8dd /arch/x86/kvm/x86.c | |
parent | 36dd9bb5ce32bc39e25a5fcc61415f13e3ed5d17 (diff) |
KVM: x86 emulator: fold decode_cache into x86_emulate_ctxt
This saves a lot of pointless casts x86_emulate_ctxt and decode_cache.
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7e452fe31e40..694538a043e7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -4507,24 +4507,24 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu) | |||
4507 | kvm_queue_exception(vcpu, ctxt->exception.vector); | 4507 | kvm_queue_exception(vcpu, ctxt->exception.vector); |
4508 | } | 4508 | } |
4509 | 4509 | ||
4510 | static void init_decode_cache(struct decode_cache *c, | 4510 | static void init_decode_cache(struct x86_emulate_ctxt *ctxt, |
4511 | const unsigned long *regs) | 4511 | const unsigned long *regs) |
4512 | { | 4512 | { |
4513 | memset(c, 0, offsetof(struct decode_cache, regs)); | 4513 | memset(&ctxt->twobyte, 0, |
4514 | memcpy(c->regs, regs, sizeof(c->regs)); | 4514 | (void *)&ctxt->regs - (void *)&ctxt->twobyte); |
4515 | memcpy(ctxt->regs, regs, sizeof(ctxt->regs)); | ||
4515 | 4516 | ||
4516 | c->fetch.start = 0; | 4517 | ctxt->fetch.start = 0; |
4517 | c->fetch.end = 0; | 4518 | ctxt->fetch.end = 0; |
4518 | c->io_read.pos = 0; | 4519 | ctxt->io_read.pos = 0; |
4519 | c->io_read.end = 0; | 4520 | ctxt->io_read.end = 0; |
4520 | c->mem_read.pos = 0; | 4521 | ctxt->mem_read.pos = 0; |
4521 | c->mem_read.end = 0; | 4522 | ctxt->mem_read.end = 0; |
4522 | } | 4523 | } |
4523 | 4524 | ||
4524 | static void init_emulate_ctxt(struct kvm_vcpu *vcpu) | 4525 | static void init_emulate_ctxt(struct kvm_vcpu *vcpu) |
4525 | { | 4526 | { |
4526 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; | 4527 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; |
4527 | struct decode_cache *c = &ctxt->decode; | ||
4528 | int cs_db, cs_l; | 4528 | int cs_db, cs_l; |
4529 | 4529 | ||
4530 | /* | 4530 | /* |
@@ -4546,28 +4546,27 @@ static void init_emulate_ctxt(struct kvm_vcpu *vcpu) | |||
4546 | X86EMUL_MODE_PROT16; | 4546 | X86EMUL_MODE_PROT16; |
4547 | ctxt->guest_mode = is_guest_mode(vcpu); | 4547 | ctxt->guest_mode = is_guest_mode(vcpu); |
4548 | 4548 | ||
4549 | init_decode_cache(c, vcpu->arch.regs); | 4549 | init_decode_cache(ctxt, vcpu->arch.regs); |
4550 | vcpu->arch.emulate_regs_need_sync_from_vcpu = false; | 4550 | vcpu->arch.emulate_regs_need_sync_from_vcpu = false; |
4551 | } | 4551 | } |
4552 | 4552 | ||
4553 | int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip) | 4553 | int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip) |
4554 | { | 4554 | { |
4555 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; | 4555 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; |
4556 | struct decode_cache *c = &ctxt->decode; | ||
4557 | int ret; | 4556 | int ret; |
4558 | 4557 | ||
4559 | init_emulate_ctxt(vcpu); | 4558 | init_emulate_ctxt(vcpu); |
4560 | 4559 | ||
4561 | c->op_bytes = 2; | 4560 | ctxt->op_bytes = 2; |
4562 | c->ad_bytes = 2; | 4561 | ctxt->ad_bytes = 2; |
4563 | c->_eip = ctxt->eip + inc_eip; | 4562 | ctxt->_eip = ctxt->eip + inc_eip; |
4564 | ret = emulate_int_real(ctxt, irq); | 4563 | ret = emulate_int_real(ctxt, irq); |
4565 | 4564 | ||
4566 | if (ret != X86EMUL_CONTINUE) | 4565 | if (ret != X86EMUL_CONTINUE) |
4567 | return EMULATE_FAIL; | 4566 | return EMULATE_FAIL; |
4568 | 4567 | ||
4569 | ctxt->eip = c->_eip; | 4568 | ctxt->eip = ctxt->_eip; |
4570 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); | 4569 | memcpy(vcpu->arch.regs, ctxt->regs, sizeof ctxt->regs); |
4571 | kvm_rip_write(vcpu, ctxt->eip); | 4570 | kvm_rip_write(vcpu, ctxt->eip); |
4572 | kvm_set_rflags(vcpu, ctxt->eflags); | 4571 | kvm_set_rflags(vcpu, ctxt->eflags); |
4573 | 4572 | ||
@@ -4631,7 +4630,6 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, | |||
4631 | { | 4630 | { |
4632 | int r; | 4631 | int r; |
4633 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; | 4632 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; |
4634 | struct decode_cache *c = &ctxt->decode; | ||
4635 | bool writeback = true; | 4633 | bool writeback = true; |
4636 | 4634 | ||
4637 | kvm_clear_exception_queue(vcpu); | 4635 | kvm_clear_exception_queue(vcpu); |
@@ -4661,7 +4659,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, | |||
4661 | } | 4659 | } |
4662 | 4660 | ||
4663 | if (emulation_type & EMULTYPE_SKIP) { | 4661 | if (emulation_type & EMULTYPE_SKIP) { |
4664 | kvm_rip_write(vcpu, c->_eip); | 4662 | kvm_rip_write(vcpu, ctxt->_eip); |
4665 | return EMULATE_DONE; | 4663 | return EMULATE_DONE; |
4666 | } | 4664 | } |
4667 | 4665 | ||
@@ -4669,7 +4667,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, | |||
4669 | changes registers values during IO operation */ | 4667 | changes registers values during IO operation */ |
4670 | if (vcpu->arch.emulate_regs_need_sync_from_vcpu) { | 4668 | if (vcpu->arch.emulate_regs_need_sync_from_vcpu) { |
4671 | vcpu->arch.emulate_regs_need_sync_from_vcpu = false; | 4669 | vcpu->arch.emulate_regs_need_sync_from_vcpu = false; |
4672 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); | 4670 | memcpy(ctxt->regs, vcpu->arch.regs, sizeof ctxt->regs); |
4673 | } | 4671 | } |
4674 | 4672 | ||
4675 | restart: | 4673 | restart: |
@@ -4707,7 +4705,7 @@ restart: | |||
4707 | toggle_interruptibility(vcpu, ctxt->interruptibility); | 4705 | toggle_interruptibility(vcpu, ctxt->interruptibility); |
4708 | kvm_set_rflags(vcpu, ctxt->eflags); | 4706 | kvm_set_rflags(vcpu, ctxt->eflags); |
4709 | kvm_make_request(KVM_REQ_EVENT, vcpu); | 4707 | kvm_make_request(KVM_REQ_EVENT, vcpu); |
4710 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); | 4708 | memcpy(vcpu->arch.regs, ctxt->regs, sizeof ctxt->regs); |
4711 | vcpu->arch.emulate_regs_need_sync_to_vcpu = false; | 4709 | vcpu->arch.emulate_regs_need_sync_to_vcpu = false; |
4712 | kvm_rip_write(vcpu, ctxt->eip); | 4710 | kvm_rip_write(vcpu, ctxt->eip); |
4713 | } else | 4711 | } else |
@@ -5718,8 +5716,8 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) | |||
5718 | * that usually, but some bad designed PV devices (vmware | 5716 | * that usually, but some bad designed PV devices (vmware |
5719 | * backdoor interface) need this to work | 5717 | * backdoor interface) need this to work |
5720 | */ | 5718 | */ |
5721 | struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; | 5719 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; |
5722 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); | 5720 | memcpy(vcpu->arch.regs, ctxt->regs, sizeof ctxt->regs); |
5723 | vcpu->arch.emulate_regs_need_sync_to_vcpu = false; | 5721 | vcpu->arch.emulate_regs_need_sync_to_vcpu = false; |
5724 | } | 5722 | } |
5725 | regs->rax = kvm_register_read(vcpu, VCPU_REGS_RAX); | 5723 | regs->rax = kvm_register_read(vcpu, VCPU_REGS_RAX); |
@@ -5849,7 +5847,6 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason, | |||
5849 | bool has_error_code, u32 error_code) | 5847 | bool has_error_code, u32 error_code) |
5850 | { | 5848 | { |
5851 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; | 5849 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; |
5852 | struct decode_cache *c = &ctxt->decode; | ||
5853 | int ret; | 5850 | int ret; |
5854 | 5851 | ||
5855 | init_emulate_ctxt(vcpu); | 5852 | init_emulate_ctxt(vcpu); |
@@ -5860,7 +5857,7 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason, | |||
5860 | if (ret) | 5857 | if (ret) |
5861 | return EMULATE_FAIL; | 5858 | return EMULATE_FAIL; |
5862 | 5859 | ||
5863 | memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); | 5860 | memcpy(vcpu->arch.regs, ctxt->regs, sizeof ctxt->regs); |
5864 | kvm_rip_write(vcpu, ctxt->eip); | 5861 | kvm_rip_write(vcpu, ctxt->eip); |
5865 | kvm_set_rflags(vcpu, ctxt->eflags); | 5862 | kvm_set_rflags(vcpu, ctxt->eflags); |
5866 | kvm_make_request(KVM_REQ_EVENT, vcpu); | 5863 | kvm_make_request(KVM_REQ_EVENT, vcpu); |