@@ -606,6 +606,7 @@ typedef struct CPUX86State {
SegmentCache idt; /* only base and limit are used */
target_ulong cr[5]; /* NOTE: cr1 is unused */
+ target_ulong cr8;
int32_t a20_mask;
/* FPU state */
@@ -338,6 +338,19 @@ static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs)
| (rhs->avl * DESC_AVL_MASK);
}
+static void kvm_set_apic_base(CPUState *env, uint64_t val)
+{
+ if (!kvm_irqchip_in_kernel())
+ cpu_set_apic_base(env, val);
+}
+
+static uint64_t kvm_get_apic_base(CPUState *env)
+{
+ if (!kvm_irqchip_in_kernel())
+ return cpu_get_apic_base(env);
+ return 0;
+}
+
static void kvm_getput_reg(__u64 *kvm_reg, target_ulong *qemu_reg, int set)
{
if (set)
@@ -447,8 +460,8 @@ static int kvm_put_sregs(CPUState *env)
sregs.cr3 = env->cr[3];
sregs.cr4 = env->cr[4];
- sregs.cr8 = cpu_get_apic_tpr(env);
- sregs.apic_base = cpu_get_apic_base(env);
+ sregs.cr8 = env->cr8;
+ sregs.apic_base = kvm_get_apic_base(env);
sregs.efer = env->efer;
@@ -546,7 +559,7 @@ static int kvm_get_sregs(CPUState *env)
env->cr[3] = sregs.cr3;
env->cr[4] = sregs.cr4;
- cpu_set_apic_base(env, sregs.apic_base);
+ kvm_set_apic_base(env, sregs.apic_base);
env->efer = sregs.efer;
//cpu_set_apic_tpr(env, sregs.cr8);
@@ -742,7 +755,7 @@ int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
run->request_interrupt_window = 0;
dprintf("setting tpr\n");
- run->cr8 = cpu_get_apic_tpr(env);
+ run->cr8 = env->cr8;
return 0;
}
@@ -754,8 +767,8 @@ int kvm_arch_post_run(CPUState *env, struct kvm_run *run)
else
env->eflags &= ~IF_MASK;
- cpu_set_apic_tpr(env, run->cr8);
- cpu_set_apic_base(env, run->apic_base);
+ env->cr8 = run->cr8;
+ kvm_set_apic_base(env, run->apic_base);
return 0;
}
It is actually not necessary to call a tpr function to save and load cr8, as cr8 is part of the processor state, and thus, it is much easier to just add it to CPUState. As for apic base, wrap kvm usages, so we can call either the qemu device, or the in kernel version. Signed-off-by: Glauber Costa <glommer@redhat.com> --- target-i386/cpu.h | 1 + target-i386/kvm.c | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-)