3 #include "config-host.h"
5 extern int kvm_allowed
;
6 extern int kvm_irqchip
;
14 #include "helper_regs.h"
19 #include <sys/utsname.h>
21 extern kvm_context_t kvm_context
;
23 void cpu_reset(CPUState
*env
)
29 int kvm_arch_qemu_create_context(void)
34 void kvm_arch_load_regs(CPUState
*env
)
39 rc
= kvm_get_regs(kvm_context
, env
->cpu_index
, ®s
);
41 perror("kvm_get_regs FAILED");
43 /* cr is untouched in qemu and not existant in CPUState fr ppr */
44 /* hflags is a morphed to MSR on ppc, no need to sync that down to kvm */
50 regs
.xer
= ppc_load_xer(env
);
53 regs
.srr0
= env
->spr
[SPR_SRR0
];
54 regs
.srr1
= env
->spr
[SPR_SRR1
];
56 regs
.sprg0
= env
->spr
[SPR_SPRG0
];
57 regs
.sprg1
= env
->spr
[SPR_SPRG1
];
58 regs
.sprg2
= env
->spr
[SPR_SPRG2
];
59 regs
.sprg3
= env
->spr
[SPR_SPRG3
];
60 regs
.sprg4
= env
->spr
[SPR_SPRG4
];
61 regs
.sprg5
= env
->spr
[SPR_SPRG5
];
62 regs
.sprg6
= env
->spr
[SPR_SPRG6
];
63 regs
.sprg7
= env
->spr
[SPR_SPRG7
];
65 for (i
= 0;i
< 32; i
++){
66 regs
.gpr
[i
] = env
->gpr
[i
];
67 regs
.fpr
[i
] = env
->fpr
[i
];
70 rc
= kvm_set_regs(kvm_context
, env
->cpu_index
, ®s
);
72 perror("kvm_set_regs FAILED");
76 void kvm_arch_save_regs(CPUState
*env
)
81 rc
= kvm_get_regs(kvm_context
, env
->cpu_index
, ®s
);
83 perror("kvm_get_regs FAILED");
87 ppc_store_xer(env
,regs
.xer
);
89 /* calculate hflags based on the current msr using the ppc qemu helper */
90 hreg_compute_hflags(env
);
94 env
->spr
[SPR_SRR0
] = regs
.srr0
;
95 env
->spr
[SPR_SRR1
] = regs
.srr1
;
97 env
->spr
[SPR_SPRG0
] = regs
.sprg0
;
98 env
->spr
[SPR_SPRG1
] = regs
.sprg1
;
99 env
->spr
[SPR_SPRG2
] = regs
.sprg2
;
100 env
->spr
[SPR_SPRG3
] = regs
.sprg3
;
101 env
->spr
[SPR_SPRG4
] = regs
.sprg4
;
102 env
->spr
[SPR_SPRG5
] = regs
.sprg5
;
103 env
->spr
[SPR_SPRG6
] = regs
.sprg6
;
104 env
->spr
[SPR_SPRG7
] = regs
.sprg7
;
106 for (i
= 0;i
< 32; i
++){
107 env
->gpr
[i
] = regs
.gpr
[i
];
108 env
->fpr
[i
] = regs
.fpr
[i
];
113 int kvm_arch_qemu_init_env(CPUState
*cenv
)
118 int kvm_arch_halt(void *opaque
, int vcpu
)
120 CPUState
*env
= cpu_single_env
;
122 if (!(env
->interrupt_request
& CPU_INTERRUPT_HARD
)
126 env
->exception_index
= EXCP_HLT
;
131 void kvm_arch_pre_kvm_run(void *opaque
, int vcpu
)
136 void kvm_arch_post_kvm_run(void *opaque
, int vcpu
)
138 CPUState
*env
= qemu_kvm_cpu_env(vcpu
);
139 cpu_single_env
= env
;
140 env
->ready_for_interrupt_injection
= \
141 kvm_is_ready_for_interrupt_injection(kvm_context
, vcpu
);
144 int kvm_arch_has_work(CPUState
*env
)
146 if ((env
->interrupt_request
& (CPU_INTERRUPT_HARD
| CPU_INTERRUPT_EXIT
)) &&
152 int kvm_arch_try_push_interrupts(void *opaque
)
154 CPUState
*env
= cpu_single_env
;
158 if (env
->ready_for_interrupt_injection
&&
159 (env
->interrupt_request
& CPU_INTERRUPT_HARD
))
161 env
->interrupt_request
&= ~CPU_INTERRUPT_HARD
;
163 /* For now KVM disregards the 'irq' argument. However, in the
164 * future KVM could cache it in-kernel to avoid a heavyweight exit
165 * when reading the UIC.
169 r
= kvm_inject_irq(kvm_context
, env
->cpu_index
, irq
);
171 printf("cpu %d fail inject %x\n", env
->cpu_index
, irq
);
174 return (env
->interrupt_request
& CPU_INTERRUPT_HARD
) != 0;
177 void kvm_arch_update_regs_for_sipi(CPUState
*env
)
179 printf("%s: no kvm-powerpc multi processor support yet!\n", __func__
);
182 /* map dcr access to existing qemu dcr emulation */
183 int handle_powerpc_dcr_read(int vcpu
, uint32_t dcrn
, uint32_t *data
)
185 CPUState
*env
= cpu_single_env
;
186 ppc_dcr_read(env
->dcr_env
, dcrn
, data
);
187 return 0; /* XXX ignore failed DCR ops */
190 int handle_powerpc_dcr_write(int vcpu
, uint32_t dcrn
, uint32_t data
)
192 CPUState
*env
= cpu_single_env
;
193 ppc_dcr_write(env
->dcr_env
, dcrn
, data
);
194 return 0; /* XXX ignore failed DCR ops */