Commit 54771e62 authored by Alexander Graf's avatar Alexander Graf

KVM: PPC: Emulator: clean up SPR reads and writes

When reading and writing SPRs, every SPR emulation piece had to read
or write the respective GPR the value was read from or stored in itself.

This approach is pretty prone to failure. What if we accidentally
implement mfspr emulation where we just do "break" and nothing else?
Suddenly we would get a random value in the return register - which is
always a bad idea.

So let's consolidate the generic code paths and only give the core
specific SPR handling code readily made variables to read/write from/to.

Functionally, this patch doesn't change anything, but it increases the
readability of the code and makes is less prone to bugs.
Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
parent c46dc9a8
...@@ -107,8 +107,10 @@ extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu, ...@@ -107,8 +107,10 @@ extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, extern int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int op, int *advance); unsigned int op, int *advance);
extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs); extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn,
extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt); ulong val);
extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn,
ulong *val);
extern int kvmppc_booke_init(void); extern int kvmppc_booke_init(void);
extern void kvmppc_booke_exit(void); extern void kvmppc_booke_exit(void);
......
...@@ -128,41 +128,41 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, ...@@ -128,41 +128,41 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
return emulated; return emulated;
} }
int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
{ {
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
switch (sprn) { switch (sprn) {
case SPRN_PID: case SPRN_PID:
kvmppc_set_pid(vcpu, kvmppc_get_gpr(vcpu, rs)); break; kvmppc_set_pid(vcpu, spr_val); break;
case SPRN_MMUCR: case SPRN_MMUCR:
vcpu->arch.mmucr = kvmppc_get_gpr(vcpu, rs); break; vcpu->arch.mmucr = spr_val; break;
case SPRN_CCR0: case SPRN_CCR0:
vcpu->arch.ccr0 = kvmppc_get_gpr(vcpu, rs); break; vcpu->arch.ccr0 = spr_val; break;
case SPRN_CCR1: case SPRN_CCR1:
vcpu->arch.ccr1 = kvmppc_get_gpr(vcpu, rs); break; vcpu->arch.ccr1 = spr_val; break;
default: default:
emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, rs); emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, spr_val);
} }
return emulated; return emulated;
} }
int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
{ {
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
switch (sprn) { switch (sprn) {
case SPRN_PID: case SPRN_PID:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.pid); break; *spr_val = vcpu->arch.pid; break;
case SPRN_MMUCR: case SPRN_MMUCR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.mmucr); break; *spr_val = vcpu->arch.mmucr; break;
case SPRN_CCR0: case SPRN_CCR0:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ccr0); break; *spr_val = vcpu->arch.ccr0; break;
case SPRN_CCR1: case SPRN_CCR1:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ccr1); break; *spr_val = vcpu->arch.ccr1; break;
default: default:
emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, rt); emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, spr_val);
} }
return emulated; return emulated;
......
...@@ -318,10 +318,9 @@ static struct kvmppc_bat *kvmppc_find_bat(struct kvm_vcpu *vcpu, int sprn) ...@@ -318,10 +318,9 @@ static struct kvmppc_bat *kvmppc_find_bat(struct kvm_vcpu *vcpu, int sprn)
return bat; return bat;
} }
int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
{ {
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
ulong spr_val = kvmppc_get_gpr(vcpu, rs);
switch (sprn) { switch (sprn) {
case SPRN_SDR1: case SPRN_SDR1:
...@@ -433,7 +432,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) ...@@ -433,7 +432,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
return emulated; return emulated;
} }
int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
{ {
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
...@@ -446,46 +445,46 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) ...@@ -446,46 +445,46 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
struct kvmppc_bat *bat = kvmppc_find_bat(vcpu, sprn); struct kvmppc_bat *bat = kvmppc_find_bat(vcpu, sprn);
if (sprn % 2) if (sprn % 2)
kvmppc_set_gpr(vcpu, rt, bat->raw >> 32); *spr_val = bat->raw >> 32;
else else
kvmppc_set_gpr(vcpu, rt, bat->raw); *spr_val = bat->raw;
break; break;
} }
case SPRN_SDR1: case SPRN_SDR1:
if (!spr_allowed(vcpu, PRIV_HYPER)) if (!spr_allowed(vcpu, PRIV_HYPER))
goto unprivileged; goto unprivileged;
kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->sdr1); *spr_val = to_book3s(vcpu)->sdr1;
break; break;
case SPRN_DSISR: case SPRN_DSISR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->dsisr); *spr_val = vcpu->arch.shared->dsisr;
break; break;
case SPRN_DAR: case SPRN_DAR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->dar); *spr_val = vcpu->arch.shared->dar;
break; break;
case SPRN_HIOR: case SPRN_HIOR:
kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->hior); *spr_val = to_book3s(vcpu)->hior;
break; break;
case SPRN_HID0: case SPRN_HID0:
kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->hid[0]); *spr_val = to_book3s(vcpu)->hid[0];
break; break;
case SPRN_HID1: case SPRN_HID1:
kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->hid[1]); *spr_val = to_book3s(vcpu)->hid[1];
break; break;
case SPRN_HID2: case SPRN_HID2:
case SPRN_HID2_GEKKO: case SPRN_HID2_GEKKO:
kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->hid[2]); *spr_val = to_book3s(vcpu)->hid[2];
break; break;
case SPRN_HID4: case SPRN_HID4:
case SPRN_HID4_GEKKO: case SPRN_HID4_GEKKO:
kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->hid[4]); *spr_val = to_book3s(vcpu)->hid[4];
break; break;
case SPRN_HID5: case SPRN_HID5:
kvmppc_set_gpr(vcpu, rt, to_book3s(vcpu)->hid[5]); *spr_val = to_book3s(vcpu)->hid[5];
break; break;
case SPRN_CFAR: case SPRN_CFAR:
case SPRN_PURR: case SPRN_PURR:
kvmppc_set_gpr(vcpu, rt, 0); *spr_val = 0;
break; break;
case SPRN_GQR0: case SPRN_GQR0:
case SPRN_GQR1: case SPRN_GQR1:
...@@ -495,8 +494,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) ...@@ -495,8 +494,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
case SPRN_GQR5: case SPRN_GQR5:
case SPRN_GQR6: case SPRN_GQR6:
case SPRN_GQR7: case SPRN_GQR7:
kvmppc_set_gpr(vcpu, rt, *spr_val = to_book3s(vcpu)->gqr[sprn - SPRN_GQR0];
to_book3s(vcpu)->gqr[sprn - SPRN_GQR0]);
break; break;
case SPRN_THRM1: case SPRN_THRM1:
case SPRN_THRM2: case SPRN_THRM2:
...@@ -511,7 +509,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) ...@@ -511,7 +509,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
case SPRN_PMC3_GEKKO: case SPRN_PMC3_GEKKO:
case SPRN_PMC4_GEKKO: case SPRN_PMC4_GEKKO:
case SPRN_WPAR_GEKKO: case SPRN_WPAR_GEKKO:
kvmppc_set_gpr(vcpu, rt, 0); *spr_val = 0;
break; break;
default: default:
unprivileged: unprivileged:
......
...@@ -1505,12 +1505,12 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, ...@@ -1505,12 +1505,12 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
return EMULATE_FAIL; return EMULATE_FAIL;
} }
int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
{ {
return EMULATE_FAIL; return EMULATE_FAIL;
} }
int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
{ {
return EMULATE_FAIL; return EMULATE_FAIL;
} }
......
...@@ -75,8 +75,8 @@ void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits); ...@@ -75,8 +75,8 @@ void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int inst, int *advance); unsigned int inst, int *advance);
int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt); int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs); int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
/* low-level asm code to transfer guest state */ /* low-level asm code to transfer guest state */
void kvmppc_load_guest_spe(struct kvm_vcpu *vcpu); void kvmppc_load_guest_spe(struct kvm_vcpu *vcpu);
......
...@@ -102,22 +102,26 @@ int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, ...@@ -102,22 +102,26 @@ int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
* will return the wrong result if called for them in another context * will return the wrong result if called for them in another context
* (such as debugging). * (such as debugging).
*/ */
int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
{ {
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
ulong spr_val = kvmppc_get_gpr(vcpu, rs);
switch (sprn) { switch (sprn) {
case SPRN_DEAR: case SPRN_DEAR:
vcpu->arch.shared->dar = spr_val; break; vcpu->arch.shared->dar = spr_val;
break;
case SPRN_ESR: case SPRN_ESR:
vcpu->arch.shared->esr = spr_val; break; vcpu->arch.shared->esr = spr_val;
break;
case SPRN_DBCR0: case SPRN_DBCR0:
vcpu->arch.dbcr0 = spr_val; break; vcpu->arch.dbcr0 = spr_val;
break;
case SPRN_DBCR1: case SPRN_DBCR1:
vcpu->arch.dbcr1 = spr_val; break; vcpu->arch.dbcr1 = spr_val;
break;
case SPRN_DBSR: case SPRN_DBSR:
vcpu->arch.dbsr &= ~spr_val; break; vcpu->arch.dbsr &= ~spr_val;
break;
case SPRN_TSR: case SPRN_TSR:
kvmppc_clr_tsr_bits(vcpu, spr_val); kvmppc_clr_tsr_bits(vcpu, spr_val);
break; break;
...@@ -131,13 +135,17 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) ...@@ -131,13 +135,17 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
* guest (PR-mode only). * guest (PR-mode only).
*/ */
case SPRN_SPRG4: case SPRN_SPRG4:
vcpu->arch.shared->sprg4 = spr_val; break; vcpu->arch.shared->sprg4 = spr_val;
break;
case SPRN_SPRG5: case SPRN_SPRG5:
vcpu->arch.shared->sprg5 = spr_val; break; vcpu->arch.shared->sprg5 = spr_val;
break;
case SPRN_SPRG6: case SPRN_SPRG6:
vcpu->arch.shared->sprg6 = spr_val; break; vcpu->arch.shared->sprg6 = spr_val;
break;
case SPRN_SPRG7: case SPRN_SPRG7:
vcpu->arch.shared->sprg7 = spr_val; break; vcpu->arch.shared->sprg7 = spr_val;
break;
case SPRN_IVPR: case SPRN_IVPR:
vcpu->arch.ivpr = spr_val; vcpu->arch.ivpr = spr_val;
...@@ -207,75 +215,83 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) ...@@ -207,75 +215,83 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
return emulated; return emulated;
} }
int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
{ {
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
switch (sprn) { switch (sprn) {
case SPRN_IVPR: case SPRN_IVPR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivpr); break; *spr_val = vcpu->arch.ivpr;
break;
case SPRN_DEAR: case SPRN_DEAR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->dar); break; *spr_val = vcpu->arch.shared->dar;
break;
case SPRN_ESR: case SPRN_ESR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->esr); break; *spr_val = vcpu->arch.shared->esr;
break;
case SPRN_DBCR0: case SPRN_DBCR0:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.dbcr0); break; *spr_val = vcpu->arch.dbcr0;
break;
case SPRN_DBCR1: case SPRN_DBCR1:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.dbcr1); break; *spr_val = vcpu->arch.dbcr1;
break;
case SPRN_DBSR: case SPRN_DBSR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.dbsr); break; *spr_val = vcpu->arch.dbsr;
break;
case SPRN_TSR: case SPRN_TSR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.tsr); break; *spr_val = vcpu->arch.tsr;
break;
case SPRN_TCR: case SPRN_TCR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.tcr); break; *spr_val = vcpu->arch.tcr;
break;
case SPRN_IVOR0: case SPRN_IVOR0:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL];
break; break;
case SPRN_IVOR1: case SPRN_IVOR1:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_MACHINE_CHECK];
break; break;
case SPRN_IVOR2: case SPRN_IVOR2:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE];
break; break;
case SPRN_IVOR3: case SPRN_IVOR3:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE];
break; break;
case SPRN_IVOR4: case SPRN_IVOR4:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_EXTERNAL];
break; break;
case SPRN_IVOR5: case SPRN_IVOR5:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_ALIGNMENT];
break; break;
case SPRN_IVOR6: case SPRN_IVOR6:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_PROGRAM];
break; break;
case SPRN_IVOR7: case SPRN_IVOR7:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_FP_UNAVAIL];
break; break;
case SPRN_IVOR8: case SPRN_IVOR8:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL];
break; break;
case SPRN_IVOR9: case SPRN_IVOR9:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL];
break; break;
case SPRN_IVOR10: case SPRN_IVOR10:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DECREMENTER];
break; break;
case SPRN_IVOR11: case SPRN_IVOR11:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_FIT]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_FIT];
break; break;
case SPRN_IVOR12: case SPRN_IVOR12:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_WATCHDOG];
break; break;
case SPRN_IVOR13: case SPRN_IVOR13:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DTLB_MISS];
break; break;
case SPRN_IVOR14: case SPRN_IVOR14:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_ITLB_MISS];
break; break;
case SPRN_IVOR15: case SPRN_IVOR15:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DEBUG];
break; break;
default: default:
......
...@@ -140,11 +140,10 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, ...@@ -140,11 +140,10 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
return emulated; return emulated;
} }
int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
{ {
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
ulong spr_val = kvmppc_get_gpr(vcpu, rs);
switch (sprn) { switch (sprn) {
#ifndef CONFIG_KVM_BOOKE_HV #ifndef CONFIG_KVM_BOOKE_HV
...@@ -154,25 +153,32 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) ...@@ -154,25 +153,32 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
case SPRN_PID1: case SPRN_PID1:
if (spr_val != 0) if (spr_val != 0)
return EMULATE_FAIL; return EMULATE_FAIL;
vcpu_e500->pid[1] = spr_val; break; vcpu_e500->pid[1] = spr_val;
break;
case SPRN_PID2: case SPRN_PID2:
if (spr_val != 0) if (spr_val != 0)
return EMULATE_FAIL; return EMULATE_FAIL;
vcpu_e500->pid[2] = spr_val; break; vcpu_e500->pid[2] = spr_val;
break;
case SPRN_MAS0: case SPRN_MAS0:
vcpu->arch.shared->mas0 = spr_val; break; vcpu->arch.shared->mas0 = spr_val;
break;
case SPRN_MAS1: case SPRN_MAS1:
vcpu->arch.shared->mas1 = spr_val; break; vcpu->arch.shared->mas1 = spr_val;
break;
case SPRN_MAS2: case SPRN_MAS2:
vcpu->arch.shared->mas2 = spr_val; break; vcpu->arch.shared->mas2 = spr_val;
break;
case SPRN_MAS3: case SPRN_MAS3:
vcpu->arch.shared->mas7_3 &= ~(u64)0xffffffff; vcpu->arch.shared->mas7_3 &= ~(u64)0xffffffff;
vcpu->arch.shared->mas7_3 |= spr_val; vcpu->arch.shared->mas7_3 |= spr_val;
break; break;
case SPRN_MAS4: case SPRN_MAS4:
vcpu->arch.shared->mas4 = spr_val; break; vcpu->arch.shared->mas4 = spr_val;
break;
case SPRN_MAS6: case SPRN_MAS6:
vcpu->arch.shared->mas6 = spr_val; break; vcpu->arch.shared->mas6 = spr_val;
break;
case SPRN_MAS7: case SPRN_MAS7:
vcpu->arch.shared->mas7_3 &= (u64)0xffffffff; vcpu->arch.shared->mas7_3 &= (u64)0xffffffff;
vcpu->arch.shared->mas7_3 |= (u64)spr_val << 32; vcpu->arch.shared->mas7_3 |= (u64)spr_val << 32;
...@@ -183,11 +189,14 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) ...@@ -183,11 +189,14 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
vcpu_e500->l1csr0 &= ~(L1CSR0_DCFI | L1CSR0_CLFC); vcpu_e500->l1csr0 &= ~(L1CSR0_DCFI | L1CSR0_CLFC);
break; break;
case SPRN_L1CSR1: case SPRN_L1CSR1:
vcpu_e500->l1csr1 = spr_val; break; vcpu_e500->l1csr1 = spr_val;
break;
case SPRN_HID0: case SPRN_HID0:
vcpu_e500->hid0 = spr_val; break; vcpu_e500->hid0 = spr_val;
break;
case SPRN_HID1: case SPRN_HID1:
vcpu_e500->hid1 = spr_val; break; vcpu_e500->hid1 = spr_val;
break;
case SPRN_MMUCSR0: case SPRN_MMUCSR0:
emulated = kvmppc_e500_emul_mt_mmucsr0(vcpu_e500, emulated = kvmppc_e500_emul_mt_mmucsr0(vcpu_e500,
...@@ -216,90 +225,103 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) ...@@ -216,90 +225,103 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
break; break;
#endif #endif
default: default:
emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, rs); emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, spr_val);
} }
return emulated; return emulated;
} }
int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
{ {
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu); struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
int emulated = EMULATE_DONE; int emulated = EMULATE_DONE;
switch (sprn) { switch (sprn) {
#ifndef CONFIG_KVM_BOOKE_HV #ifndef CONFIG_KVM_BOOKE_HV
unsigned long val;
case SPRN_PID: case SPRN_PID:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[0]); break; *spr_val = vcpu_e500->pid[0];
break;
case SPRN_PID1: case SPRN_PID1:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[1]); break; *spr_val = vcpu_e500->pid[1];
break;
case SPRN_PID2: case SPRN_PID2:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[2]); break; *spr_val = vcpu_e500->pid[2];
break;
case SPRN_MAS0: case SPRN_MAS0:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas0); break; *spr_val = vcpu->arch.shared->mas0;
break;
case SPRN_MAS1: case SPRN_MAS1:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas1); break; *spr_val = vcpu->arch.shared->mas1;
break;
case SPRN_MAS2: case SPRN_MAS2:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas2); break; *spr_val = vcpu->arch.shared->mas2;
break;
case SPRN_MAS3: case SPRN_MAS3:
val = (u32)vcpu->arch.shared->mas7_3; *spr_val = (u32)vcpu->arch.shared->mas7_3;
kvmppc_set_gpr(vcpu, rt, val);
break; break;
case SPRN_MAS4: case SPRN_MAS4:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas4); break; *spr_val = vcpu->arch.shared->mas4;
break;
case SPRN_MAS6: case SPRN_MAS6:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas6); break; *spr_val = vcpu->arch.shared->mas6;
break;
case SPRN_MAS7: case SPRN_MAS7:
val = vcpu->arch.shared->mas7_3 >> 32; *spr_val = vcpu->arch.shared->mas7_3 >> 32;
kvmppc_set_gpr(vcpu, rt, val);
break; break;
#endif #endif
case SPRN_TLB0CFG: case SPRN_TLB0CFG:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.tlbcfg[0]); break; *spr_val = vcpu->arch.tlbcfg[0];
break;
case SPRN_TLB1CFG: case SPRN_TLB1CFG:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.tlbcfg[1]); break; *spr_val = vcpu->arch.tlbcfg[1];
break;
case SPRN_L1CSR0: case SPRN_L1CSR0:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->l1csr0); break; *spr_val = vcpu_e500->l1csr0;
break;
case SPRN_L1CSR1: case SPRN_L1CSR1:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->l1csr1); break; *spr_val = vcpu_e500->l1csr1;
break;
case SPRN_HID0: case SPRN_HID0:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid0); break; *spr_val = vcpu_e500->hid0;
break;
case SPRN_HID1: case SPRN_HID1:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid1); break; *spr_val = vcpu_e500->hid1;
break;
case SPRN_SVR: case SPRN_SVR:
kvmppc_set_gpr(vcpu, rt, vcpu_e500->svr); break; *spr_val = vcpu_e500->svr;
break;
case SPRN_MMUCSR0: case SPRN_MMUCSR0:
kvmppc_set_gpr(vcpu, rt, 0); break; *spr_val = 0;
break;
case SPRN_MMUCFG: case SPRN_MMUCFG:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.mmucfg); break; *spr_val = vcpu->arch.mmucfg;
break;
/* extra exceptions */ /* extra exceptions */
case SPRN_IVOR32: case SPRN_IVOR32:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL];
break; break;
case SPRN_IVOR33: case SPRN_IVOR33:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA];
break; break;
case SPRN_IVOR34: case SPRN_IVOR34:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND];
break; break;
case SPRN_IVOR35: case SPRN_IVOR35:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR];
break; break;
#ifdef CONFIG_KVM_BOOKE_HV #ifdef CONFIG_KVM_BOOKE_HV
case SPRN_IVOR36: case SPRN_IVOR36:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL];
break; break;
case SPRN_IVOR37: case SPRN_IVOR37:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT]); *spr_val = vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT];
break; break;
#endif #endif
default: default:
emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, rt); emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, spr_val);
} }
return emulated; return emulated;
......
...@@ -154,6 +154,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ...@@ -154,6 +154,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
int sprn = get_sprn(inst); int sprn = get_sprn(inst);
enum emulation_result emulated = EMULATE_DONE; enum emulation_result emulated = EMULATE_DONE;
int advance = 1; int advance = 1;
ulong spr_val = 0;
/* this default type might be overwritten by subcategories */ /* this default type might be overwritten by subcategories */
kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS); kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
...@@ -235,55 +236,59 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ...@@ -235,55 +236,59 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case OP_31_XOP_MFSPR: case OP_31_XOP_MFSPR:
switch (sprn) { switch (sprn) {
case SPRN_SRR0: case SPRN_SRR0:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->srr0); spr_val = vcpu->arch.shared->srr0;
break; break;
case SPRN_SRR1: case SPRN_SRR1:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->srr1); spr_val = vcpu->arch.shared->srr1;
break; break;
case SPRN_PVR: case SPRN_PVR:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.pvr); break; spr_val = vcpu->arch.pvr;
break;
case SPRN_PIR: case SPRN_PIR:
kvmppc_set_gpr(vcpu, rt, vcpu->vcpu_id); break; spr_val = vcpu->vcpu_id;
break;
case SPRN_MSSSR0: case SPRN_MSSSR0:
kvmppc_set_gpr(vcpu, rt, 0); break; spr_val = 0;
break;
/* Note: mftb and TBRL/TBWL are user-accessible, so /* Note: mftb and TBRL/TBWL are user-accessible, so
* the guest can always access the real TB anyways. * the guest can always access the real TB anyways.
* In fact, we probably will never see these traps. */ * In fact, we probably will never see these traps. */
case SPRN_TBWL: case SPRN_TBWL:
kvmppc_set_gpr(vcpu, rt, get_tb() >> 32); break; spr_val = get_tb() >> 32;
break;
case SPRN_TBWU: case SPRN_TBWU:
kvmppc_set_gpr(vcpu, rt, get_tb()); break; spr_val = get_tb();
break;
case SPRN_SPRG0: case SPRN_SPRG0:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->sprg0); spr_val = vcpu->arch.shared->sprg0;
break; break;
case SPRN_SPRG1: case SPRN_SPRG1:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->sprg1); spr_val = vcpu->arch.shared->sprg1;
break; break;
case SPRN_SPRG2: case SPRN_SPRG2:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->sprg2); spr_val = vcpu->arch.shared->sprg2;
break; break;
case SPRN_SPRG3: case SPRN_SPRG3:
kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->sprg3); spr_val = vcpu->arch.shared->sprg3;
break; break;
/* Note: SPRG4-7 are user-readable, so we don't get /* Note: SPRG4-7 are user-readable, so we don't get
* a trap. */ * a trap. */
case SPRN_DEC: case SPRN_DEC:
{ spr_val = kvmppc_get_dec(vcpu, get_tb());
kvmppc_set_gpr(vcpu, rt,
kvmppc_get_dec(vcpu, get_tb()));
break; break;
}
default: default:
emulated = kvmppc_core_emulate_mfspr(vcpu, sprn, rt); emulated = kvmppc_core_emulate_mfspr(vcpu, sprn,
if (emulated == EMULATE_FAIL) { &spr_val);
printk("mfspr: unknown spr %x\n", sprn); if (unlikely(emulated == EMULATE_FAIL)) {
kvmppc_set_gpr(vcpu, rt, 0); printk(KERN_INFO "mfspr: unknown spr "
"0x%x\n", sprn);
} }
break; break;
} }
kvmppc_set_gpr(vcpu, rt, spr_val);
kvmppc_set_exit_type(vcpu, EMULATED_MFSPR_EXITS); kvmppc_set_exit_type(vcpu, EMULATED_MFSPR_EXITS);
break; break;
...@@ -301,12 +306,13 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ...@@ -301,12 +306,13 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
break; break;
case OP_31_XOP_MTSPR: case OP_31_XOP_MTSPR:
spr_val = kvmppc_get_gpr(vcpu, rs);
switch (sprn) { switch (sprn) {
case SPRN_SRR0: case SPRN_SRR0:
vcpu->arch.shared->srr0 = kvmppc_get_gpr(vcpu, rs); vcpu->arch.shared->srr0 = spr_val;
break; break;
case SPRN_SRR1: case SPRN_SRR1:
vcpu->arch.shared->srr1 = kvmppc_get_gpr(vcpu, rs); vcpu->arch.shared->srr1 = spr_val;
break; break;
/* XXX We need to context-switch the timebase for /* XXX We need to context-switch the timebase for
...@@ -317,27 +323,29 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ...@@ -317,27 +323,29 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
case SPRN_MSSSR0: break; case SPRN_MSSSR0: break;
case SPRN_DEC: case SPRN_DEC:
vcpu->arch.dec = kvmppc_get_gpr(vcpu, rs); vcpu->arch.dec = spr_val;
kvmppc_emulate_dec(vcpu); kvmppc_emulate_dec(vcpu);
break; break;
case SPRN_SPRG0: case SPRN_SPRG0:
vcpu->arch.shared->sprg0 = kvmppc_get_gpr(vcpu, rs); vcpu->arch.shared->sprg0 = spr_val;
break; break;
case SPRN_SPRG1: case SPRN_SPRG1:
vcpu->arch.shared->sprg1 = kvmppc_get_gpr(vcpu, rs); vcpu->arch.shared->sprg1 = spr_val;
break; break;
case SPRN_SPRG2: case SPRN_SPRG2:
vcpu->arch.shared->sprg2 = kvmppc_get_gpr(vcpu, rs); vcpu->arch.shared->sprg2 = spr_val;
break; break;
case SPRN_SPRG3: case SPRN_SPRG3:
vcpu->arch.shared->sprg3 = kvmppc_get_gpr(vcpu, rs); vcpu->arch.shared->sprg3 = spr_val;
break; break;
default: default:
emulated = kvmppc_core_emulate_mtspr(vcpu, sprn, rs); emulated = kvmppc_core_emulate_mtspr(vcpu, sprn,
spr_val);
if (emulated == EMULATE_FAIL) if (emulated == EMULATE_FAIL)
printk("mtspr: unknown spr %x\n", sprn); printk(KERN_INFO "mtspr: unknown spr "
"0x%x\n", sprn);
break; break;
} }
kvmppc_set_exit_type(vcpu, EMULATED_MTSPR_EXITS); kvmppc_set_exit_type(vcpu, EMULATED_MTSPR_EXITS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment