Add desktop PowerPC specific emulation
Subsystems (2)
PATCH 16/27 Add desktop PowerPC specific emulation
Little opcodes behave differently on desktop and embedded PowerPC cores. In order to reflect those differences, let's add some #ifdef code to emulate.c.
We could probably also handle them in the core specific emulation files, but I would prefer to reuse as much code as possible.
--- arch/powerpc/kvm/emulate.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)
arch/powerpc/kvm/emulate.c +30 -0
@@ -32,6 +32,7 @@#include "trace.h" #define OP_TRAP 3 +#define OP_TRAP_64 2#define OP_31_XOP_LWZX 23#define OP_31_XOP_LBZX 87
@@ -68,7 +69,19 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) {unsigned long nr_jiffies; +#ifdef CONFIG_PPC64 +#ifdef DEBUG_EMUL +printk (KERN_INFO "mtDEC: %x\n" , vcpu->arch.dec); +#endif +/* POWER4+ triggers a dec interrupt if the value is < 0 */ +if (vcpu->arch.dec &0x80000000 ) { +del_timer (&vcpu->arch.dec_timer); +kvmppc_core_queue_dec (vcpu); + } +else if (true) { +#else if (vcpu->arch.tcr &TCR_DIE ) { +#endif /* The decrementer ticks at the same rate as the timebase, so * that's how we convert the guest DEC value to the number of * host ticks. */
@@ -113,9 +126,16 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)/* this default type might be overwritten by subcategories */ kvmppc_set_exit_type (vcpu,EMULATED_INST_EXITS ); +#ifdef DEBUG_EMUL +printk (KERN_INFO "Emulating opcode %d / %d\n" ,get_op (inst),get_xop (inst)); +#endif switch (get_op (inst)) {case OP_TRAP : +#ifdef CONFIG_PPC64 +case OP_TRAP_64 : +#else vcpu->arch.esr |=ESR_PTR ; +#endif kvmppc_core_queue_program (vcpu); advance =0 ;break ;
@@ -189,6 +209,13 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) vcpu->arch.gpr[rt] = vcpu->arch.srr0;break ;case SPRN_SRR1 : vcpu->arch.gpr[rt] = vcpu->arch.srr1;break ; +#ifdef CONFIG_PPC64 +case SPRN_PVR : + vcpu->arch.gpr[rt] = vcpu->arch.pvr;break ; +case SPRN_PIR : +case SPRN_MSSSR0 : + vcpu->arch.gpr[rt] =0 ;break ; +#else case SPRN_PVR : vcpu->arch.gpr[rt] =mfspr (SPRN_PVR );break ;case SPRN_PIR :
@@ -201,6 +228,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) vcpu->arch.gpr[rt] =mftbl ();break ;case SPRN_TBWU : vcpu->arch.gpr[rt] =mftbu ();break ; +#endif case SPRN_SPRG0 : vcpu->arch.gpr[rt] = vcpu->arch.sprg0;break ;
@@ -271,6 +299,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)case SPRN_TBWL :break ;case SPRN_TBWU :break ; +case SPRN_MSSSR0 :break ; +case SPRN_DEC : vcpu->arch.dec = vcpu->arch.gpr[rs];kvmppc_emulate_dec (vcpu);
Signature · 1 line
1.6.0.2
Quoted 33 lines · Alexander Graf
Little opcodes behave differently on desktop and embedded PowerPC cores. In order to reflect those differences, let's add some #ifdef code to
emulate.c.We could probably also handle them in the core specific emulation files, but I would prefer to reuse as much code as possible.
Signed-off-by Alexander Graf <[email protected]>--- arch/powerpc/kvm/emulate.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)arch/powerpc/kvm/emulate.c +7
-0@@ -32,6 +32,7 @@#include "trace.h" #define OP_TRAP 3 +#define OP_TRAP_64 2#define OP_31_XOP_LWZX 23#define OP_31_XOP_LBZX 87@@ -68,7 +69,19 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) {unsigned long nr_jiffies; +#ifdef CONFIG_PPC64 +#ifdef DEBUG_EMUL +printk (KERN_INFO "mtDEC: %x\n" , vcpu->arch.dec); +#endif +/* POWER4+ triggers a dec interrupt if the value is < 0 */ +if (vcpu->arch.dec &0x80000000 ) {
arch/powerpc/kvm/emulate.c void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) · line 87
Quoted 10 lines
arch/powerpc/kvm/emulate.c +6
-0+del_timer (&vcpu->arch.dec_timer); + kvmppc_core_queue_dec(vcpu); + } +else if (true) { +#else if (vcpu->arch.tcr &TCR_DIE ) { +#endif /* The decrementer ticks at the same rate as the timebase, so * that's how we convert the guest DEC value to the number of * host ticks. */
Ifdefs through the middle of control syntax makes my head hurt. :)
Instead, let's do this:
#ifdef CONFIG_PPC64
static int kvmppc_dec_enabled(struct kvm_vcpu *vcpu) { return 1; } #else
static int kvmppc_dec_enabled(struct kvm_vcpu *vcpu)
{
return vcpu->arch.tcr & TCR_DIE;
}#endif
Then kvmppc_emulate_dec() becomes:
#ifdef CONFIG_PPC64
/* POWER4+ triggers a dec interrupt if the value is < 0 */
if (vcpu->arch.dec & 0x80000000) {
del_timer(&vcpu->arch.dec_timer);
kvmppc_core_queue_dec(vcpu);
goto out;
}
#endif
if (kvmppc_dec_enabled(vcpu)) {
...out:
}
arch/powerpc/kvm/emulate.c int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) · line 131
Quoted 7 lines
arch/powerpc/kvm/emulate.c +3
-0@@ -113,9 +126,16 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)/* this default type might be overwritten by subcategories */ kvmppc_set_exit_type (vcpu,EMULATED_INST_EXITS ); +#ifdef DEBUG_EMUL +printk (KERN_INFO "Emulating opcode %d / %d\n" ,get_op (inst),get_xop (inst)); +#endif
We definitely need to use pr_debug() here. (All over, not just this patch.)
Quoted 14 lines
arch/powerpc/kvm/emulate.c +4
-0switch (get_op (inst)) {case OP_TRAP : +#ifdef CONFIG_PPC64 +case OP_TRAP_64 : +#else vcpu->arch.esr |=ESR_PTR ; +#endif kvmppc_core_queue_program (vcpu); advance =0 ;break ;@@ -189,6 +209,13 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) vcpu->arch.gpr[rt] = vcpu->arch.srr0;break ;case SPRN_SRR1 : vcpu->arch.gpr[rt] = vcpu->arch.srr1;break ;
arch/powerpc/kvm/emulate.c int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) · line 221
Quoted 10 lines
arch/powerpc/kvm/emulate.c +7
-0+#ifdef CONFIG_PPC64 +case SPRN_PVR : + vcpu->arch.gpr[rt] = vcpu->arch.pvr;break ; +case SPRN_PIR : +case SPRN_MSSSR0 : + vcpu->arch.gpr[rt] =0 ;break ; +#else case SPRN_PVR : vcpu->arch.gpr[rt] =mfspr (SPRN_PVR );break ;case SPRN_PIR :
Let's not split the PVR handling here. As discussed elsewhere, ppc32 should also use vcpu->arch.pvr. (Obviously you can't test that part, but just make the code right and we'll sort it out.)
Better idea for PIR: return vcpu->vcpu_id.
Quoted 17 lines
arch/powerpc/kvm/emulate.c +3
-0@@ -201,6 +228,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) vcpu->arch.gpr[rt] =mftbl ();break ;case SPRN_TBWU : vcpu->arch.gpr[rt] =mftbu ();break ; +#endif case SPRN_SPRG0 : vcpu->arch.gpr[rt] = vcpu->arch.sprg0;break ;@@ -271,6 +299,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)case SPRN_TBWL :break ;case SPRN_TBWU :break ; +case SPRN_MSSSR0 :break ; +case SPRN_DEC : vcpu->arch.dec = vcpu->arch.gpr[rs];kvmppc_emulate_dec (vcpu);
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
Quoted 10 lines · Hollis Blanchard
Quoted 10 lines
arch/powerpc/kvm/emulate.c +10
-0+#ifdef CONFIG_PPC64 +#ifdef DEBUG_EMUL +printk (KERN_INFO "mtDEC: %x\n" , vcpu->arch.dec); +#endif +/* POWER4+ triggers a dec interrupt if the value is < 0 */ +if (vcpu->arch.dec &0x80000000 ) { +del_timer (&vcpu->arch.dec_timer); +kvmppc_core_queue_dec (vcpu); + } +else if (true) {
Quoted 8 lines
arch/powerpc/kvm/emulate.c void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) · line 87
Quoted 6 lines
arch/powerpc/kvm/emulate.c +2
-0+#else if (vcpu->arch.tcr &TCR_DIE ) { +#endif /* The decrementer ticks at the same rate as the timebase, so * that's how we convert the guest DEC value to the number of * host ticks. */ Ifdefs through the middle of control syntax makes my head hurt. :)
Note that your original BookE DEC emulation looks fishy :-)
I may have missed something in your code... but I don't think it emulates the expected HW behaviour:
Basically, when the BookE DEC hits the 1 -> 0 transition it latches an event in TSE:DIS always, whether TCR:DIE is set or not. If DIE is not set, the interrupt is sent. It will then stop counting if auto-reload isn't enabled.
That means that if TSR:DIS is set from a previous event while TCR:DIE is clear, then setting TCR:DIE (with MSR:EE enabled of course) will trigger a DEC interrupt on BookE.
The BookE DEC interrupt is basically a level sensitive thing sourced from to (TSR:DIS && TCR:DIE), and TSR:DIS remains set until explicitely cleared.
Cheers,
Ben.