* [PATCH 16/27] Add desktop PowerPC specific emulation
@ 2009-09-29 8:18 Alexander Graf
2009-10-09 20:57 ` Hollis Blanchard
2009-10-10 23:14 ` Benjamin Herrenschmidt
0 siblings, 2 replies; 8+ messages in thread
From: Alexander Graf @ 2009-09-29 8:18 UTC (permalink / raw)
To: kvm-ppc
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 <agraf@suse.de>
---
arch/powerpc/kvm/emulate.c | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 50d411d..665fa83 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -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);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 16/27] Add desktop PowerPC specific emulation
2009-09-29 8:18 [PATCH 16/27] Add desktop PowerPC specific emulation Alexander Graf
@ 2009-10-09 20:57 ` Hollis Blanchard
2009-10-10 23:14 ` Benjamin Herrenschmidt
1 sibling, 0 replies; 8+ messages in thread
From: Hollis Blanchard @ 2009-10-09 20:57 UTC (permalink / raw)
To: kvm-ppc
On Tue, 2009-09-29 at 10:18 +0200, Alexander Graf wrote:
> 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 <agraf@suse.de>
> ---
> arch/powerpc/kvm/emulate.c | 30 ++++++++++++++++++++++++++++++
> 1 files changed, 30 insertions(+), 0 deletions(-)
>
> diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
> index 50d411d..665fa83 100644
> --- a/arch/powerpc/kvm/emulate.c
> +++ b/arch/powerpc/kvm/emulate.c
> @@ -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. */
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:
}
> @@ -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.)
> 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:
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.
> @@ -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);
--
Hollis Blanchard
IBM Linux Technology Center
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 16/27] Add desktop PowerPC specific emulation
2009-09-29 8:18 [PATCH 16/27] Add desktop PowerPC specific emulation Alexander Graf
2009-10-09 20:57 ` Hollis Blanchard
@ 2009-10-10 23:14 ` Benjamin Herrenschmidt
1 sibling, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2009-10-10 23:14 UTC (permalink / raw)
To: kvm-ppc
On Fri, 2009-10-09 at 13:57 -0700, Hollis Blanchard wrote:
> > +#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. */
>
> 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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 16/27] Add desktop PowerPC specific emulation
[not found] ` <1256137413-15256-16-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
@ 2009-10-21 15:03 ` Alexander Graf
0 siblings, 0 replies; 8+ messages in thread
From: Alexander Graf @ 2009-10-21 15:03 UTC (permalink / raw)
To: kvm-u79uwXL29TY76Z2rM5mHXA
Cc: Avi Kivity, kvm-ppc, Hollis Blanchard, Arnd Bergmann,
Benjamin Herrenschmidt, Kevin Wolf, bphilips-l3A5Bk7waGM,
Marcelo Tosatti
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 <agraf@suse.de>
---
v4 -> v5:
- use get_tb instead of mftb
- make ppc32 and ppc64 emulation share more code
---
arch/powerpc/kvm/emulate.c | 49 +++++++++++++++++++++++++++++++++++---------
1 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 50d411d..1ec5e07 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -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
@@ -64,16 +65,36 @@
#define OP_STH 44
#define OP_STHU 45
+#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
+
void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
{
unsigned long nr_jiffies;
- if (vcpu->arch.tcr & TCR_DIE) {
+#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);
+ return;
+ }
+#endif
+ if (kvmppc_dec_enabled(vcpu)) {
/* 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. */
- vcpu->arch.dec_jiffies = mftb();
+ vcpu->arch.dec_jiffies = get_tb();
nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy;
mod_timer(&vcpu->arch.dec_timer,
get_jiffies_64() + nr_jiffies);
@@ -113,9 +134,15 @@ 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);
+ pr_debug(KERN_INFO "Emulating opcode %d / %d\n", get_op(inst), get_xop(inst));
+
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;
@@ -190,17 +217,19 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_SRR1:
vcpu->arch.gpr[rt] = vcpu->arch.srr1; break;
case SPRN_PVR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PVR); break;
+ vcpu->arch.gpr[rt] = vcpu->arch.pvr; break;
case SPRN_PIR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PIR); break;
+ vcpu->arch.gpr[rt] = vcpu->vcpu_id; break;
+ case SPRN_MSSSR0:
+ vcpu->arch.gpr[rt] = 0; break;
/* Note: mftb and TBRL/TBWL are user-accessible, so
* the guest can always access the real TB anyways.
* In fact, we probably will never see these traps. */
case SPRN_TBWL:
- vcpu->arch.gpr[rt] = mftbl(); break;
+ vcpu->arch.gpr[rt] = get_tb() >> 32; break;
case SPRN_TBWU:
- vcpu->arch.gpr[rt] = mftbu(); break;
+ vcpu->arch.gpr[rt] = get_tb(); break;
case SPRN_SPRG0:
vcpu->arch.gpr[rt] = vcpu->arch.sprg0; break;
@@ -215,11 +244,9 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_DEC:
{
- u64 jd = mftb() - vcpu->arch.dec_jiffies;
+ u64 jd = get_tb() - vcpu->arch.dec_jiffies;
vcpu->arch.gpr[rt] = vcpu->arch.dec - jd;
-#ifdef DEBUG_EMUL
- printk(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
-#endif
+ pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
break;
}
default:
@@ -271,6 +298,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);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 16/27] Add desktop PowerPC specific emulation
@ 2009-10-21 15:03 ` Alexander Graf
0 siblings, 0 replies; 8+ messages in thread
From: Alexander Graf @ 2009-10-21 15:03 UTC (permalink / raw)
To: kvm-u79uwXL29TY76Z2rM5mHXA
Cc: Avi Kivity, kvm-ppc, Hollis Blanchard, Arnd Bergmann,
Benjamin Herrenschmidt, Kevin Wolf, bphilips-l3A5Bk7waGM,
Marcelo Tosatti
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 <agraf-l3A5Bk7waGM@public.gmane.org>
---
v4 -> v5:
- use get_tb instead of mftb
- make ppc32 and ppc64 emulation share more code
---
arch/powerpc/kvm/emulate.c | 49 +++++++++++++++++++++++++++++++++++---------
1 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 50d411d..1ec5e07 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -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
@@ -64,16 +65,36 @@
#define OP_STH 44
#define OP_STHU 45
+#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
+
void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
{
unsigned long nr_jiffies;
- if (vcpu->arch.tcr & TCR_DIE) {
+#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);
+ return;
+ }
+#endif
+ if (kvmppc_dec_enabled(vcpu)) {
/* 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. */
- vcpu->arch.dec_jiffies = mftb();
+ vcpu->arch.dec_jiffies = get_tb();
nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy;
mod_timer(&vcpu->arch.dec_timer,
get_jiffies_64() + nr_jiffies);
@@ -113,9 +134,15 @@ 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);
+ pr_debug(KERN_INFO "Emulating opcode %d / %d\n", get_op(inst), get_xop(inst));
+
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;
@@ -190,17 +217,19 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_SRR1:
vcpu->arch.gpr[rt] = vcpu->arch.srr1; break;
case SPRN_PVR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PVR); break;
+ vcpu->arch.gpr[rt] = vcpu->arch.pvr; break;
case SPRN_PIR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PIR); break;
+ vcpu->arch.gpr[rt] = vcpu->vcpu_id; break;
+ case SPRN_MSSSR0:
+ vcpu->arch.gpr[rt] = 0; break;
/* Note: mftb and TBRL/TBWL are user-accessible, so
* the guest can always access the real TB anyways.
* In fact, we probably will never see these traps. */
case SPRN_TBWL:
- vcpu->arch.gpr[rt] = mftbl(); break;
+ vcpu->arch.gpr[rt] = get_tb() >> 32; break;
case SPRN_TBWU:
- vcpu->arch.gpr[rt] = mftbu(); break;
+ vcpu->arch.gpr[rt] = get_tb(); break;
case SPRN_SPRG0:
vcpu->arch.gpr[rt] = vcpu->arch.sprg0; break;
@@ -215,11 +244,9 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_DEC:
{
- u64 jd = mftb() - vcpu->arch.dec_jiffies;
+ u64 jd = get_tb() - vcpu->arch.dec_jiffies;
vcpu->arch.gpr[rt] = vcpu->arch.dec - jd;
-#ifdef DEBUG_EMUL
- printk(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
-#endif
+ pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
break;
}
default:
@@ -271,6 +298,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);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 16/27] Add desktop PowerPC specific emulation
2009-10-30 15:47 [PATCH 00/27] Add KVM support for Book3s_64 (PPC64) hosts v6 Alexander Graf
[not found] ` <1256917647-6200-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
@ 2009-10-30 15:47 ` Alexander Graf
0 siblings, 0 replies; 8+ messages in thread
From: Alexander Graf @ 2009-10-30 15:47 UTC (permalink / raw)
To: kvm-u79uwXL29TY76Z2rM5mHXA
Cc: Avi Kivity, kvm-ppc, Hollis Blanchard, Arnd Bergmann,
Benjamin Herrenschmidt, Kevin Wolf, bphilips-l3A5Bk7waGM,
Marcelo Tosatti, Olof Johansson,
linuxppc-dev-mnsaURCQ41sdnm+yROfE0A
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 <agraf@suse.de>
---
v4 -> v5:
- use get_tb instead of mftb
- make ppc32 and ppc64 emulation share more code
---
arch/powerpc/kvm/emulate.c | 49 +++++++++++++++++++++++++++++++++++---------
1 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 50d411d..1ec5e07 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -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
@@ -64,16 +65,36 @@
#define OP_STH 44
#define OP_STHU 45
+#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
+
void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
{
unsigned long nr_jiffies;
- if (vcpu->arch.tcr & TCR_DIE) {
+#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);
+ return;
+ }
+#endif
+ if (kvmppc_dec_enabled(vcpu)) {
/* 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. */
- vcpu->arch.dec_jiffies = mftb();
+ vcpu->arch.dec_jiffies = get_tb();
nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy;
mod_timer(&vcpu->arch.dec_timer,
get_jiffies_64() + nr_jiffies);
@@ -113,9 +134,15 @@ 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);
+ pr_debug(KERN_INFO "Emulating opcode %d / %d\n", get_op(inst), get_xop(inst));
+
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;
@@ -190,17 +217,19 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_SRR1:
vcpu->arch.gpr[rt] = vcpu->arch.srr1; break;
case SPRN_PVR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PVR); break;
+ vcpu->arch.gpr[rt] = vcpu->arch.pvr; break;
case SPRN_PIR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PIR); break;
+ vcpu->arch.gpr[rt] = vcpu->vcpu_id; break;
+ case SPRN_MSSSR0:
+ vcpu->arch.gpr[rt] = 0; break;
/* Note: mftb and TBRL/TBWL are user-accessible, so
* the guest can always access the real TB anyways.
* In fact, we probably will never see these traps. */
case SPRN_TBWL:
- vcpu->arch.gpr[rt] = mftbl(); break;
+ vcpu->arch.gpr[rt] = get_tb() >> 32; break;
case SPRN_TBWU:
- vcpu->arch.gpr[rt] = mftbu(); break;
+ vcpu->arch.gpr[rt] = get_tb(); break;
case SPRN_SPRG0:
vcpu->arch.gpr[rt] = vcpu->arch.sprg0; break;
@@ -215,11 +244,9 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_DEC:
{
- u64 jd = mftb() - vcpu->arch.dec_jiffies;
+ u64 jd = get_tb() - vcpu->arch.dec_jiffies;
vcpu->arch.gpr[rt] = vcpu->arch.dec - jd;
-#ifdef DEBUG_EMUL
- printk(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
-#endif
+ pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
break;
}
default:
@@ -271,6 +298,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);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 16/27] Add desktop PowerPC specific emulation
@ 2009-10-30 15:47 ` Alexander Graf
0 siblings, 0 replies; 8+ messages in thread
From: Alexander Graf @ 2009-10-30 15:47 UTC (permalink / raw)
To: kvm
Cc: Kevin Wolf, Arnd Bergmann, Hollis Blanchard, Marcelo Tosatti,
kvm-ppc, linuxppc-dev, Avi Kivity, bphilips, Olof Johansson
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 <agraf@suse.de>
---
v4 -> v5:
- use get_tb instead of mftb
- make ppc32 and ppc64 emulation share more code
---
arch/powerpc/kvm/emulate.c | 49 +++++++++++++++++++++++++++++++++++---------
1 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 50d411d..1ec5e07 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -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
@@ -64,16 +65,36 @@
#define OP_STH 44
#define OP_STHU 45
+#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
+
void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
{
unsigned long nr_jiffies;
- if (vcpu->arch.tcr & TCR_DIE) {
+#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);
+ return;
+ }
+#endif
+ if (kvmppc_dec_enabled(vcpu)) {
/* 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. */
- vcpu->arch.dec_jiffies = mftb();
+ vcpu->arch.dec_jiffies = get_tb();
nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy;
mod_timer(&vcpu->arch.dec_timer,
get_jiffies_64() + nr_jiffies);
@@ -113,9 +134,15 @@ 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);
+ pr_debug(KERN_INFO "Emulating opcode %d / %d\n", get_op(inst), get_xop(inst));
+
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;
@@ -190,17 +217,19 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_SRR1:
vcpu->arch.gpr[rt] = vcpu->arch.srr1; break;
case SPRN_PVR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PVR); break;
+ vcpu->arch.gpr[rt] = vcpu->arch.pvr; break;
case SPRN_PIR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PIR); break;
+ vcpu->arch.gpr[rt] = vcpu->vcpu_id; break;
+ case SPRN_MSSSR0:
+ vcpu->arch.gpr[rt] = 0; break;
/* Note: mftb and TBRL/TBWL are user-accessible, so
* the guest can always access the real TB anyways.
* In fact, we probably will never see these traps. */
case SPRN_TBWL:
- vcpu->arch.gpr[rt] = mftbl(); break;
+ vcpu->arch.gpr[rt] = get_tb() >> 32; break;
case SPRN_TBWU:
- vcpu->arch.gpr[rt] = mftbu(); break;
+ vcpu->arch.gpr[rt] = get_tb(); break;
case SPRN_SPRG0:
vcpu->arch.gpr[rt] = vcpu->arch.sprg0; break;
@@ -215,11 +244,9 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_DEC:
{
- u64 jd = mftb() - vcpu->arch.dec_jiffies;
+ u64 jd = get_tb() - vcpu->arch.dec_jiffies;
vcpu->arch.gpr[rt] = vcpu->arch.dec - jd;
-#ifdef DEBUG_EMUL
- printk(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
-#endif
+ pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
break;
}
default:
@@ -271,6 +298,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);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 16/27] Add desktop PowerPC specific emulation
@ 2009-10-30 15:47 ` Alexander Graf
0 siblings, 0 replies; 8+ messages in thread
From: Alexander Graf @ 2009-10-30 15:47 UTC (permalink / raw)
To: kvm-u79uwXL29TY76Z2rM5mHXA
Cc: Avi Kivity, kvm-ppc, Hollis Blanchard, Arnd Bergmann,
Benjamin Herrenschmidt, Kevin Wolf, bphilips-l3A5Bk7waGM,
Marcelo Tosatti, Olof Johansson,
linuxppc-dev-mnsaURCQ41sdnm+yROfE0A
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 <agraf-l3A5Bk7waGM@public.gmane.org>
---
v4 -> v5:
- use get_tb instead of mftb
- make ppc32 and ppc64 emulation share more code
---
arch/powerpc/kvm/emulate.c | 49 +++++++++++++++++++++++++++++++++++---------
1 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 50d411d..1ec5e07 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -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
@@ -64,16 +65,36 @@
#define OP_STH 44
#define OP_STHU 45
+#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
+
void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
{
unsigned long nr_jiffies;
- if (vcpu->arch.tcr & TCR_DIE) {
+#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);
+ return;
+ }
+#endif
+ if (kvmppc_dec_enabled(vcpu)) {
/* 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. */
- vcpu->arch.dec_jiffies = mftb();
+ vcpu->arch.dec_jiffies = get_tb();
nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy;
mod_timer(&vcpu->arch.dec_timer,
get_jiffies_64() + nr_jiffies);
@@ -113,9 +134,15 @@ 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);
+ pr_debug(KERN_INFO "Emulating opcode %d / %d\n", get_op(inst), get_xop(inst));
+
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;
@@ -190,17 +217,19 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_SRR1:
vcpu->arch.gpr[rt] = vcpu->arch.srr1; break;
case SPRN_PVR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PVR); break;
+ vcpu->arch.gpr[rt] = vcpu->arch.pvr; break;
case SPRN_PIR:
- vcpu->arch.gpr[rt] = mfspr(SPRN_PIR); break;
+ vcpu->arch.gpr[rt] = vcpu->vcpu_id; break;
+ case SPRN_MSSSR0:
+ vcpu->arch.gpr[rt] = 0; break;
/* Note: mftb and TBRL/TBWL are user-accessible, so
* the guest can always access the real TB anyways.
* In fact, we probably will never see these traps. */
case SPRN_TBWL:
- vcpu->arch.gpr[rt] = mftbl(); break;
+ vcpu->arch.gpr[rt] = get_tb() >> 32; break;
case SPRN_TBWU:
- vcpu->arch.gpr[rt] = mftbu(); break;
+ vcpu->arch.gpr[rt] = get_tb(); break;
case SPRN_SPRG0:
vcpu->arch.gpr[rt] = vcpu->arch.sprg0; break;
@@ -215,11 +244,9 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_DEC:
{
- u64 jd = mftb() - vcpu->arch.dec_jiffies;
+ u64 jd = get_tb() - vcpu->arch.dec_jiffies;
vcpu->arch.gpr[rt] = vcpu->arch.dec - jd;
-#ifdef DEBUG_EMUL
- printk(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
-#endif
+ pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
break;
}
default:
@@ -271,6 +298,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);
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-10-30 15:47 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-29 8:18 [PATCH 16/27] Add desktop PowerPC specific emulation Alexander Graf
2009-10-09 20:57 ` Hollis Blanchard
2009-10-10 23:14 ` Benjamin Herrenschmidt
-- strict thread matches above, loose matches on Subject: below --
2009-10-21 15:03 [PATCH 00/27] Add KVM support for Book3s_64 (PPC64) hosts v5 Alexander Graf
2009-10-21 15:03 ` [PATCH 01/27] Move dirty logging code to sub-arch Alexander Graf
2009-10-21 15:03 ` [PATCH 02/27] Pass PVR in sregs Alexander Graf
2009-10-21 15:03 ` [PATCH 03/27] Add Book3s definitions Alexander Graf
2009-10-21 15:03 ` [PATCH 04/27] Add Book3s fields to vcpu structs Alexander Graf
2009-10-21 15:03 ` [PATCH 05/27] Add asm/kvm_book3s.h Alexander Graf
2009-10-21 15:03 ` [PATCH 06/27] Add Book3s_64 intercept helpers Alexander Graf
2009-10-21 15:03 ` [PATCH 07/27] Add book3s_64 highmem asm code Alexander Graf
2009-10-21 15:03 ` [PATCH 08/27] Add SLB switching code for entry/exit Alexander Graf
2009-10-21 15:03 ` [PATCH 09/27] Add interrupt handling code Alexander Graf
2009-10-21 15:03 ` [PATCH 10/27] Add book3s.c Alexander Graf
2009-10-21 15:03 ` [PATCH 11/27] Add book3s_64 Host MMU handling Alexander Graf
2009-10-21 15:03 ` [PATCH 12/27] Add book3s_64 guest MMU Alexander Graf
2009-10-21 15:03 ` [PATCH 13/27] Add book3s_32 " Alexander Graf
2009-10-21 15:03 ` [PATCH 14/27] Add book3s_64 specific opcode emulation Alexander Graf
2009-10-21 15:03 ` [PATCH 15/27] Add mfdec emulation Alexander Graf
[not found] ` <1256137413-15256-16-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2009-10-21 15:03 ` [PATCH 16/27] Add desktop PowerPC specific emulation Alexander Graf
2009-10-21 15:03 ` Alexander Graf
2009-10-30 15:47 [PATCH 00/27] Add KVM support for Book3s_64 (PPC64) hosts v6 Alexander Graf
[not found] ` <1256917647-6200-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2009-10-30 15:47 ` [PATCH 16/27] Add desktop PowerPC specific emulation Alexander Graf
2009-10-30 15:47 ` Alexander Graf
2009-10-30 15:47 ` Alexander Graf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.