blob: 38219af0cd0e59b2faafb91a73945713637c928a [file] [log] [blame]
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001/*
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.
5 *
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.
10 *
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.
14 *
15 * Copyright IBM Corp. 2007
16 *
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18 */
19
20#include <linux/jiffies.h>
Alexander Graf544c6762009-11-02 12:02:31 +000021#include <linux/hrtimer.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050022#include <linux/types.h>
23#include <linux/string.h>
24#include <linux/kvm_host.h>
25
Hollis Blanchard75f74f02008-11-05 09:36:16 -060026#include <asm/reg.h>
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050027#include <asm/time.h>
28#include <asm/byteorder.h>
29#include <asm/kvm_ppc.h>
Hollis Blanchardc381a042008-11-05 09:36:15 -060030#include <asm/disassemble.h>
Hollis Blanchard73e75b42008-12-02 15:51:57 -060031#include "timing.h"
Marcelo Tosatti46f43c62009-06-18 11:47:27 -030032#include "trace.h"
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050033
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -060034#define OP_TRAP 3
Alexander Graf513579e2009-10-30 05:47:16 +000035#define OP_TRAP_64 2
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -060036
37#define OP_31_XOP_LWZX 23
38#define OP_31_XOP_LBZX 87
39#define OP_31_XOP_STWX 151
40#define OP_31_XOP_STBX 215
41#define OP_31_XOP_STBUX 247
42#define OP_31_XOP_LHZX 279
43#define OP_31_XOP_LHZUX 311
44#define OP_31_XOP_MFSPR 339
45#define OP_31_XOP_STHX 407
46#define OP_31_XOP_STHUX 439
47#define OP_31_XOP_MTSPR 467
48#define OP_31_XOP_DCBI 470
49#define OP_31_XOP_LWBRX 534
50#define OP_31_XOP_TLBSYNC 566
51#define OP_31_XOP_STWBRX 662
52#define OP_31_XOP_LHBRX 790
53#define OP_31_XOP_STHBRX 918
54
55#define OP_LWZ 32
56#define OP_LWZU 33
57#define OP_LBZ 34
58#define OP_LBZU 35
59#define OP_STW 36
60#define OP_STWU 37
61#define OP_STB 38
62#define OP_STBU 39
63#define OP_LHZ 40
64#define OP_LHZU 41
65#define OP_STH 44
66#define OP_STHU 45
67
Alexander Graf513579e2009-10-30 05:47:16 +000068#ifdef CONFIG_PPC64
69static int kvmppc_dec_enabled(struct kvm_vcpu *vcpu)
70{
71 return 1;
72}
73#else
74static int kvmppc_dec_enabled(struct kvm_vcpu *vcpu)
75{
76 return vcpu->arch.tcr & TCR_DIE;
77}
78#endif
79
Hollis Blanchard75f74f02008-11-05 09:36:16 -060080void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050081{
Alexander Graf544c6762009-11-02 12:02:31 +000082 unsigned long dec_nsec;
Alexander Graf9a7a9b02009-10-30 05:47:15 +000083
Alexander Graf544c6762009-11-02 12:02:31 +000084 pr_debug("mtDEC: %x\n", vcpu->arch.dec);
Alexander Graf513579e2009-10-30 05:47:16 +000085#ifdef CONFIG_PPC64
Alexander Graf7706664d2009-12-21 20:21:24 +010086 /* mtdec lowers the interrupt line when positive. */
87 kvmppc_core_dequeue_dec(vcpu);
88
Alexander Graf513579e2009-10-30 05:47:16 +000089 /* POWER4+ triggers a dec interrupt if the value is < 0 */
90 if (vcpu->arch.dec & 0x80000000) {
Alexander Graf544c6762009-11-02 12:02:31 +000091 hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
Alexander Graf513579e2009-10-30 05:47:16 +000092 kvmppc_core_queue_dec(vcpu);
93 return;
94 }
95#endif
96 if (kvmppc_dec_enabled(vcpu)) {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050097 /* The decrementer ticks at the same rate as the timebase, so
98 * that's how we convert the guest DEC value to the number of
99 * host ticks. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500100
Alexander Graf544c6762009-11-02 12:02:31 +0000101 hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
102 dec_nsec = vcpu->arch.dec;
103 dec_nsec *= 1000;
104 dec_nsec /= tb_ticks_per_usec;
105 hrtimer_start(&vcpu->arch.dec_timer, ktime_set(0, dec_nsec),
106 HRTIMER_MODE_REL);
Alexander Graf513579e2009-10-30 05:47:16 +0000107 vcpu->arch.dec_jiffies = get_tb();
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500108 } else {
Alexander Graf544c6762009-11-02 12:02:31 +0000109 hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500110 }
111}
112
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500113/* XXX to do:
114 * lhax
115 * lhaux
116 * lswx
117 * lswi
118 * stswx
119 * stswi
120 * lha
121 * lhau
122 * lmw
123 * stmw
124 *
125 * XXX is_bigendian should depend on MMU mapping or MSR[LE]
126 */
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600127/* XXX Should probably auto-generate instruction decoding for a particular core
128 * from opcode tables in the future. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500129int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
130{
131 u32 inst = vcpu->arch.last_inst;
132 u32 ea;
133 int ra;
134 int rb;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500135 int rs;
136 int rt;
137 int sprn;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500138 enum emulation_result emulated = EMULATE_DONE;
139 int advance = 1;
140
Hollis Blanchard73e75b42008-12-02 15:51:57 -0600141 /* this default type might be overwritten by subcategories */
142 kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
143
Alexander Graf513579e2009-10-30 05:47:16 +0000144 pr_debug(KERN_INFO "Emulating opcode %d / %d\n", get_op(inst), get_xop(inst));
145
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500146 switch (get_op(inst)) {
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600147 case OP_TRAP:
Alexander Graf513579e2009-10-30 05:47:16 +0000148#ifdef CONFIG_PPC64
149 case OP_TRAP_64:
150#else
Hollis Blanchardfcfdbd22008-11-05 09:36:24 -0600151 vcpu->arch.esr |= ESR_PTR;
Alexander Graf513579e2009-10-30 05:47:16 +0000152#endif
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600153 kvmppc_core_queue_program(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500154 advance = 0;
155 break;
156
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500157 case 31:
158 switch (get_xop(inst)) {
159
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600160 case OP_31_XOP_LWZX:
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500161 rt = get_rt(inst);
162 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
163 break;
164
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600165 case OP_31_XOP_LBZX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500166 rt = get_rt(inst);
167 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
168 break;
169
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600170 case OP_31_XOP_STWX:
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500171 rs = get_rs(inst);
172 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100173 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500174 4, 1);
175 break;
176
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600177 case OP_31_XOP_STBX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500178 rs = get_rs(inst);
179 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100180 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500181 1, 1);
182 break;
183
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600184 case OP_31_XOP_STBUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500185 rs = get_rs(inst);
186 ra = get_ra(inst);
187 rb = get_rb(inst);
188
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100189 ea = kvmppc_get_gpr(vcpu, rb);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500190 if (ra)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100191 ea += kvmppc_get_gpr(vcpu, ra);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500192
193 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100194 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500195 1, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100196 kvmppc_set_gpr(vcpu, rs, ea);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500197 break;
198
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600199 case OP_31_XOP_LHZX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500200 rt = get_rt(inst);
201 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
202 break;
203
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600204 case OP_31_XOP_LHZUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500205 rt = get_rt(inst);
206 ra = get_ra(inst);
207 rb = get_rb(inst);
208
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100209 ea = kvmppc_get_gpr(vcpu, rb);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500210 if (ra)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100211 ea += kvmppc_get_gpr(vcpu, ra);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500212
213 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100214 kvmppc_set_gpr(vcpu, ra, ea);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500215 break;
216
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600217 case OP_31_XOP_MFSPR:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500218 sprn = get_sprn(inst);
219 rt = get_rt(inst);
220
221 switch (sprn) {
222 case SPRN_SRR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100223 kvmppc_set_gpr(vcpu, rt, vcpu->arch.srr0); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500224 case SPRN_SRR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100225 kvmppc_set_gpr(vcpu, rt, vcpu->arch.srr1); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500226 case SPRN_PVR:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100227 kvmppc_set_gpr(vcpu, rt, vcpu->arch.pvr); break;
Liu Yu06579dd2009-06-05 14:54:31 +0800228 case SPRN_PIR:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100229 kvmppc_set_gpr(vcpu, rt, vcpu->vcpu_id); break;
Alexander Graf513579e2009-10-30 05:47:16 +0000230 case SPRN_MSSSR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100231 kvmppc_set_gpr(vcpu, rt, 0); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500232
233 /* Note: mftb and TBRL/TBWL are user-accessible, so
234 * the guest can always access the real TB anyways.
235 * In fact, we probably will never see these traps. */
236 case SPRN_TBWL:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100237 kvmppc_set_gpr(vcpu, rt, get_tb() >> 32); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500238 case SPRN_TBWU:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100239 kvmppc_set_gpr(vcpu, rt, get_tb()); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500240
241 case SPRN_SPRG0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100242 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg0); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500243 case SPRN_SPRG1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100244 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg1); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500245 case SPRN_SPRG2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100246 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg2); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500247 case SPRN_SPRG3:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100248 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg3); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500249 /* Note: SPRG4-7 are user-readable, so we don't get
250 * a trap. */
251
Alexander Graf9a7a9b02009-10-30 05:47:15 +0000252 case SPRN_DEC:
253 {
Alexander Graf513579e2009-10-30 05:47:16 +0000254 u64 jd = get_tb() - vcpu->arch.dec_jiffies;
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100255 kvmppc_set_gpr(vcpu, rt, vcpu->arch.dec - jd);
256 pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n",
257 vcpu->arch.dec, jd,
258 kvmppc_get_gpr(vcpu, rt));
Alexander Graf9a7a9b02009-10-30 05:47:15 +0000259 break;
260 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500261 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600262 emulated = kvmppc_core_emulate_mfspr(vcpu, sprn, rt);
263 if (emulated == EMULATE_FAIL) {
264 printk("mfspr: unknown spr %x\n", sprn);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100265 kvmppc_set_gpr(vcpu, rt, 0);
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600266 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500267 break;
268 }
269 break;
270
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600271 case OP_31_XOP_STHX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500272 rs = get_rs(inst);
273 ra = get_ra(inst);
274 rb = get_rb(inst);
275
276 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100277 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500278 2, 1);
279 break;
280
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600281 case OP_31_XOP_STHUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500282 rs = get_rs(inst);
283 ra = get_ra(inst);
284 rb = get_rb(inst);
285
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100286 ea = kvmppc_get_gpr(vcpu, rb);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500287 if (ra)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100288 ea += kvmppc_get_gpr(vcpu, ra);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500289
290 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100291 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500292 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100293 kvmppc_set_gpr(vcpu, ra, ea);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500294 break;
295
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600296 case OP_31_XOP_MTSPR:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500297 sprn = get_sprn(inst);
298 rs = get_rs(inst);
299 switch (sprn) {
300 case SPRN_SRR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100301 vcpu->arch.srr0 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500302 case SPRN_SRR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100303 vcpu->arch.srr1 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500304
305 /* XXX We need to context-switch the timebase for
306 * watchdog and FIT. */
307 case SPRN_TBWL: break;
308 case SPRN_TBWU: break;
309
Alexander Graf513579e2009-10-30 05:47:16 +0000310 case SPRN_MSSSR0: break;
311
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500312 case SPRN_DEC:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100313 vcpu->arch.dec = kvmppc_get_gpr(vcpu, rs);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500314 kvmppc_emulate_dec(vcpu);
315 break;
316
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500317 case SPRN_SPRG0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100318 vcpu->arch.sprg0 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500319 case SPRN_SPRG1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100320 vcpu->arch.sprg1 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500321 case SPRN_SPRG2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100322 vcpu->arch.sprg2 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500323 case SPRN_SPRG3:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100324 vcpu->arch.sprg3 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500325
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500326 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600327 emulated = kvmppc_core_emulate_mtspr(vcpu, sprn, rs);
328 if (emulated == EMULATE_FAIL)
329 printk("mtspr: unknown spr %x\n", sprn);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500330 break;
331 }
332 break;
333
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600334 case OP_31_XOP_DCBI:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500335 /* Do nothing. The guest is performing dcbi because
336 * hardware DMA is not snooped by the dcache, but
337 * emulated DMA either goes through the dcache as
338 * normal writes, or the host kernel has handled dcache
339 * coherence. */
340 break;
341
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600342 case OP_31_XOP_LWBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500343 rt = get_rt(inst);
344 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 0);
345 break;
346
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600347 case OP_31_XOP_TLBSYNC:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500348 break;
349
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600350 case OP_31_XOP_STWBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500351 rs = get_rs(inst);
352 ra = get_ra(inst);
353 rb = get_rb(inst);
354
355 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100356 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500357 4, 0);
358 break;
359
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600360 case OP_31_XOP_LHBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500361 rt = get_rt(inst);
362 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 0);
363 break;
364
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600365 case OP_31_XOP_STHBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500366 rs = get_rs(inst);
367 ra = get_ra(inst);
368 rb = get_rb(inst);
369
370 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100371 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500372 2, 0);
373 break;
374
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500375 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600376 /* Attempt core-specific emulation below. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500377 emulated = EMULATE_FAIL;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500378 }
379 break;
380
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600381 case OP_LWZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500382 rt = get_rt(inst);
383 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
384 break;
385
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600386 case OP_LWZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500387 ra = get_ra(inst);
388 rt = get_rt(inst);
389 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100390 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500391 break;
392
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600393 case OP_LBZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500394 rt = get_rt(inst);
395 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
396 break;
397
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600398 case OP_LBZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500399 ra = get_ra(inst);
400 rt = get_rt(inst);
401 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100402 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500403 break;
404
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600405 case OP_STW:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500406 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100407 emulated = kvmppc_handle_store(run, vcpu,
408 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500409 4, 1);
410 break;
411
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600412 case OP_STWU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500413 ra = get_ra(inst);
414 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100415 emulated = kvmppc_handle_store(run, vcpu,
416 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500417 4, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100418 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500419 break;
420
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600421 case OP_STB:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500422 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100423 emulated = kvmppc_handle_store(run, vcpu,
424 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500425 1, 1);
426 break;
427
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600428 case OP_STBU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500429 ra = get_ra(inst);
430 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100431 emulated = kvmppc_handle_store(run, vcpu,
432 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500433 1, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100434 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500435 break;
436
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600437 case OP_LHZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500438 rt = get_rt(inst);
439 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
440 break;
441
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600442 case OP_LHZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500443 ra = get_ra(inst);
444 rt = get_rt(inst);
445 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100446 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500447 break;
448
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600449 case OP_STH:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500450 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100451 emulated = kvmppc_handle_store(run, vcpu,
452 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500453 2, 1);
454 break;
455
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600456 case OP_STHU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500457 ra = get_ra(inst);
458 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100459 emulated = kvmppc_handle_store(run, vcpu,
460 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500461 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100462 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500463 break;
464
465 default:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500466 emulated = EMULATE_FAIL;
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600467 }
468
469 if (emulated == EMULATE_FAIL) {
470 emulated = kvmppc_core_emulate_op(run, vcpu, inst, &advance);
471 if (emulated == EMULATE_FAIL) {
472 advance = 0;
473 printk(KERN_ERR "Couldn't emulate instruction 0x%08x "
474 "(op %d xop %d)\n", inst, get_op(inst), get_xop(inst));
475 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500476 }
477
Marcelo Tosatti46f43c62009-06-18 11:47:27 -0300478 trace_kvm_ppc_instr(inst, vcpu->arch.pc, emulated);
Christian Ehrhardt3b4bd792008-07-14 14:00:04 +0200479
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500480 if (advance)
481 vcpu->arch.pc += 4; /* Advance past emulated instruction. */
482
483 return emulated;
484}