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 vcpu
->arch
.gpr
[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
, vcpu
->arch
.gpr
[rs
]);
77 vcpu
->arch
.msr
= (vcpu
->arch
.msr
& ~MSR_EE
)
78 | (vcpu
->arch
.gpr
[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
;
107 vcpu
->arch
.dear
= vcpu
->arch
.gpr
[rs
]; break;
109 vcpu
->arch
.esr
= vcpu
->arch
.gpr
[rs
]; break;
111 vcpu
->arch
.dbcr0
= vcpu
->arch
.gpr
[rs
]; break;
113 vcpu
->arch
.dbcr1
= vcpu
->arch
.gpr
[rs
]; break;
115 vcpu
->arch
.dbsr
&= ~vcpu
->arch
.gpr
[rs
]; break;
117 vcpu
->arch
.tsr
&= ~vcpu
->arch
.gpr
[rs
]; break;
119 vcpu
->arch
.tcr
= vcpu
->arch
.gpr
[rs
];
120 kvmppc_emulate_dec(vcpu
);
123 /* Note: SPRG4-7 are user-readable. These values are
124 * loaded into the real SPRGs when resuming the
127 vcpu
->arch
.sprg4
= vcpu
->arch
.gpr
[rs
]; break;
129 vcpu
->arch
.sprg5
= vcpu
->arch
.gpr
[rs
]; break;
131 vcpu
->arch
.sprg6
= vcpu
->arch
.gpr
[rs
]; break;
133 vcpu
->arch
.sprg7
= vcpu
->arch
.gpr
[rs
]; break;
136 vcpu
->arch
.ivpr
= vcpu
->arch
.gpr
[rs
];
139 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_CRITICAL
] = vcpu
->arch
.gpr
[rs
];
142 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_MACHINE_CHECK
] = vcpu
->arch
.gpr
[rs
];
145 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DATA_STORAGE
] = vcpu
->arch
.gpr
[rs
];
148 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_INST_STORAGE
] = vcpu
->arch
.gpr
[rs
];
151 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_EXTERNAL
] = vcpu
->arch
.gpr
[rs
];
154 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ALIGNMENT
] = vcpu
->arch
.gpr
[rs
];
157 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PROGRAM
] = vcpu
->arch
.gpr
[rs
];
160 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FP_UNAVAIL
] = vcpu
->arch
.gpr
[rs
];
163 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SYSCALL
] = vcpu
->arch
.gpr
[rs
];
166 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_AP_UNAVAIL
] = vcpu
->arch
.gpr
[rs
];
169 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DECREMENTER
] = vcpu
->arch
.gpr
[rs
];
172 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FIT
] = vcpu
->arch
.gpr
[rs
];
175 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_WATCHDOG
] = vcpu
->arch
.gpr
[rs
];
178 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DTLB_MISS
] = vcpu
->arch
.gpr
[rs
];
181 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ITLB_MISS
] = vcpu
->arch
.gpr
[rs
];
184 vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DEBUG
] = vcpu
->arch
.gpr
[rs
];
188 emulated
= EMULATE_FAIL
;
194 int kvmppc_booke_emulate_mfspr(struct kvm_vcpu
*vcpu
, int sprn
, int rt
)
196 int emulated
= EMULATE_DONE
;
200 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivpr
; break;
202 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.dear
; break;
204 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.esr
; break;
206 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.dbcr0
; break;
208 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.dbcr1
; break;
210 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.dbsr
; break;
213 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_CRITICAL
];
216 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_MACHINE_CHECK
];
219 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DATA_STORAGE
];
222 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_INST_STORAGE
];
225 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_EXTERNAL
];
228 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ALIGNMENT
];
231 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_PROGRAM
];
234 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FP_UNAVAIL
];
237 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_SYSCALL
];
240 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_AP_UNAVAIL
];
243 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DECREMENTER
];
246 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_FIT
];
249 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_WATCHDOG
];
252 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DTLB_MISS
];
255 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_ITLB_MISS
];
258 vcpu
->arch
.gpr
[rt
] = vcpu
->arch
.ivor
[BOOKE_IRQPRIO_DEBUG
];
262 emulated
= EMULATE_FAIL
;