2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 * Copyright IBM Corp. 2008
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
20 #include <linux/kvm_host.h>
21 #include <asm/disassemble.h>
25 #define OP_19_XOP_RFI 50
27 #define OP_31_XOP_MFMSR 83
28 #define OP_31_XOP_WRTEE 131
29 #define OP_31_XOP_MTMSR 146
30 #define OP_31_XOP_WRTEEI 163
32 static void kvmppc_emul_rfi(struct kvm_vcpu
*vcpu
)
34 vcpu
->arch
.pc
= vcpu
->arch
.srr0
;
35 kvmppc_set_msr(vcpu
, vcpu
->arch
.srr1
);
38 int kvmppc_booke_emulate_op(struct kvm_run
*run
, struct kvm_vcpu
*vcpu
,
39 unsigned int inst
, int *advance
)
41 int emulated
= EMULATE_DONE
;
45 switch (get_op(inst
)) {
47 switch (get_xop(inst
)) {
49 kvmppc_emul_rfi(vcpu
);
50 kvmppc_set_exit_type(vcpu
, EMULATED_RFI_EXITS
);
55 emulated
= EMULATE_FAIL
;
61 switch (get_xop(inst
)) {
65 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.msr
);
66 kvmppc_set_exit_type(vcpu
, EMULATED_MFMSR_EXITS
);
71 kvmppc_set_exit_type(vcpu
, EMULATED_MTMSR_EXITS
);
72 kvmppc_set_msr(vcpu
, kvmppc_get_gpr(vcpu
, rs
));
77 vcpu
->arch
.msr
= (vcpu
->arch
.msr
& ~MSR_EE
)
78 | (kvmppc_get_gpr(vcpu
, rs
) & MSR_EE
);
79 kvmppc_set_exit_type(vcpu
, EMULATED_WRTEE_EXITS
);
82 case OP_31_XOP_WRTEEI
:
83 vcpu
->arch
.msr
= (vcpu
->arch
.msr
& ~MSR_EE
)
85 kvmppc_set_exit_type(vcpu
, EMULATED_WRTEE_EXITS
);
89 emulated
= EMULATE_FAIL
;
95 emulated
= EMULATE_FAIL
;
101 int kvmppc_booke_emulate_mtspr(struct kvm_vcpu
*vcpu
, int sprn
, int rs
)
103 int emulated
= EMULATE_DONE
;
104 ulong spr_val
= kvmppc_get_gpr(vcpu
, rs
);
108 vcpu
->arch
.dear
= spr_val
; break;
110 vcpu
->arch
.esr
= spr_val
; break;
112 vcpu
->arch
.dbcr0
= spr_val
; break;
114 vcpu
->arch
.dbcr1
= spr_val
; break;
116 vcpu
->arch
.dbsr
&= ~spr_val
; break;
118 vcpu
->arch
.tsr
&= ~spr_val
; break;
120 vcpu
->arch
.tcr
= spr_val
;
121 kvmppc_emulate_dec(vcpu
);
124 /* Note: SPRG4-7 are user-readable. These values are
125 * loaded into the real SPRGs when resuming the
128 vcpu
->arch
.sprg4
= spr_val
; break;
130 vcpu
->arch
.sprg5
= spr_val
; break;
132 vcpu
->arch
.sprg6
= spr_val
; break;
134 vcpu
->arch
.sprg7
= spr_val
; break;
137 vcpu
->arch
.ivpr
= spr_val
;
140 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_CRITICAL
] = spr_val
;
143 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_MACHINE_CHECK
] = spr_val
;
146 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DATA_STORAGE
] = spr_val
;
149 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_INST_STORAGE
] = spr_val
;
152 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_EXTERNAL
] = spr_val
;
155 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ALIGNMENT
] = spr_val
;
158 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PROGRAM
] = spr_val
;
161 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FP_UNAVAIL
] = spr_val
;
164 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SYSCALL
] = spr_val
;
167 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_AP_UNAVAIL
] = spr_val
;
170 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DECREMENTER
] = spr_val
;
173 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FIT
] = spr_val
;
176 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_WATCHDOG
] = spr_val
;
179 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DTLB_MISS
] = spr_val
;
182 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ITLB_MISS
] = spr_val
;
185 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DEBUG
] = spr_val
;
189 emulated
= EMULATE_FAIL
;
195 int kvmppc_booke_emulate_mfspr(struct kvm_vcpu
*vcpu
, int sprn
, int rt
)
197 int emulated
= EMULATE_DONE
;
201 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivpr
); break;
203 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.dear
); break;
205 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.esr
); break;
207 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.dbcr0
); break;
209 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.dbcr1
); break;
211 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.dbsr
); break;
214 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_CRITICAL
]);
217 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_MACHINE_CHECK
]);
220 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DATA_STORAGE
]);
223 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_INST_STORAGE
]);
226 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_EXTERNAL
]);
229 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ALIGNMENT
]);
232 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PROGRAM
]);
235 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FP_UNAVAIL
]);
238 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SYSCALL
]);
241 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_AP_UNAVAIL
]);
244 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DECREMENTER
]);
247 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FIT
]);
250 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_WATCHDOG
]);
253 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DTLB_MISS
]);
256 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ITLB_MISS
]);
259 kvmppc_set_gpr(vcpu
, rt
, vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DEBUG
]);
263 emulated
= EMULATE_FAIL
;