blob: 04e317c1bbeef239e88ff7e70d6c02bf0c6c41f5 [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
Alexander Grafb4433a72010-01-08 02:58:04 +0100146 /* Try again next time */
147 if (inst == KVM_INST_FETCH_FAILED)
148 return EMULATE_DONE;
149
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500150 switch (get_op(inst)) {
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600151 case OP_TRAP:
Alexander Graf513579e2009-10-30 05:47:16 +0000152#ifdef CONFIG_PPC64
153 case OP_TRAP_64:
154#else
Hollis Blanchardfcfdbd22008-11-05 09:36:24 -0600155 vcpu->arch.esr |= ESR_PTR;
Alexander Graf513579e2009-10-30 05:47:16 +0000156#endif
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600157 kvmppc_core_queue_program(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500158 advance = 0;
159 break;
160
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500161 case 31:
162 switch (get_xop(inst)) {
163
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600164 case OP_31_XOP_LWZX:
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500165 rt = get_rt(inst);
166 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
167 break;
168
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600169 case OP_31_XOP_LBZX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500170 rt = get_rt(inst);
171 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
172 break;
173
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600174 case OP_31_XOP_STWX:
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500175 rs = get_rs(inst);
176 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100177 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500178 4, 1);
179 break;
180
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600181 case OP_31_XOP_STBX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500182 rs = get_rs(inst);
183 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100184 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500185 1, 1);
186 break;
187
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600188 case OP_31_XOP_STBUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500189 rs = get_rs(inst);
190 ra = get_ra(inst);
191 rb = get_rb(inst);
192
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100193 ea = kvmppc_get_gpr(vcpu, rb);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500194 if (ra)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100195 ea += kvmppc_get_gpr(vcpu, ra);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500196
197 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100198 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500199 1, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100200 kvmppc_set_gpr(vcpu, rs, ea);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500201 break;
202
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600203 case OP_31_XOP_LHZX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500204 rt = get_rt(inst);
205 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
206 break;
207
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600208 case OP_31_XOP_LHZUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500209 rt = get_rt(inst);
210 ra = get_ra(inst);
211 rb = get_rb(inst);
212
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100213 ea = kvmppc_get_gpr(vcpu, rb);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500214 if (ra)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100215 ea += kvmppc_get_gpr(vcpu, ra);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500216
217 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100218 kvmppc_set_gpr(vcpu, ra, ea);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500219 break;
220
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600221 case OP_31_XOP_MFSPR:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500222 sprn = get_sprn(inst);
223 rt = get_rt(inst);
224
225 switch (sprn) {
226 case SPRN_SRR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100227 kvmppc_set_gpr(vcpu, rt, vcpu->arch.srr0); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500228 case SPRN_SRR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100229 kvmppc_set_gpr(vcpu, rt, vcpu->arch.srr1); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500230 case SPRN_PVR:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100231 kvmppc_set_gpr(vcpu, rt, vcpu->arch.pvr); break;
Liu Yu06579dd2009-06-05 14:54:31 +0800232 case SPRN_PIR:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100233 kvmppc_set_gpr(vcpu, rt, vcpu->vcpu_id); break;
Alexander Graf513579e2009-10-30 05:47:16 +0000234 case SPRN_MSSSR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100235 kvmppc_set_gpr(vcpu, rt, 0); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500236
237 /* Note: mftb and TBRL/TBWL are user-accessible, so
238 * the guest can always access the real TB anyways.
239 * In fact, we probably will never see these traps. */
240 case SPRN_TBWL:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100241 kvmppc_set_gpr(vcpu, rt, get_tb() >> 32); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500242 case SPRN_TBWU:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100243 kvmppc_set_gpr(vcpu, rt, get_tb()); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500244
245 case SPRN_SPRG0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100246 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg0); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500247 case SPRN_SPRG1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100248 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg1); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500249 case SPRN_SPRG2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100250 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg2); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500251 case SPRN_SPRG3:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100252 kvmppc_set_gpr(vcpu, rt, vcpu->arch.sprg3); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500253 /* Note: SPRG4-7 are user-readable, so we don't get
254 * a trap. */
255
Alexander Graf9a7a9b02009-10-30 05:47:15 +0000256 case SPRN_DEC:
257 {
Alexander Graf513579e2009-10-30 05:47:16 +0000258 u64 jd = get_tb() - vcpu->arch.dec_jiffies;
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100259 kvmppc_set_gpr(vcpu, rt, vcpu->arch.dec - jd);
260 pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n",
261 vcpu->arch.dec, jd,
262 kvmppc_get_gpr(vcpu, rt));
Alexander Graf9a7a9b02009-10-30 05:47:15 +0000263 break;
264 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500265 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600266 emulated = kvmppc_core_emulate_mfspr(vcpu, sprn, rt);
267 if (emulated == EMULATE_FAIL) {
268 printk("mfspr: unknown spr %x\n", sprn);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100269 kvmppc_set_gpr(vcpu, rt, 0);
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600270 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500271 break;
272 }
273 break;
274
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600275 case OP_31_XOP_STHX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500276 rs = get_rs(inst);
277 ra = get_ra(inst);
278 rb = get_rb(inst);
279
280 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100281 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500282 2, 1);
283 break;
284
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600285 case OP_31_XOP_STHUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500286 rs = get_rs(inst);
287 ra = get_ra(inst);
288 rb = get_rb(inst);
289
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100290 ea = kvmppc_get_gpr(vcpu, rb);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500291 if (ra)
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100292 ea += kvmppc_get_gpr(vcpu, ra);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500293
294 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100295 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500296 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100297 kvmppc_set_gpr(vcpu, ra, ea);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500298 break;
299
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600300 case OP_31_XOP_MTSPR:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500301 sprn = get_sprn(inst);
302 rs = get_rs(inst);
303 switch (sprn) {
304 case SPRN_SRR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100305 vcpu->arch.srr0 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500306 case SPRN_SRR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100307 vcpu->arch.srr1 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500308
309 /* XXX We need to context-switch the timebase for
310 * watchdog and FIT. */
311 case SPRN_TBWL: break;
312 case SPRN_TBWU: break;
313
Alexander Graf513579e2009-10-30 05:47:16 +0000314 case SPRN_MSSSR0: break;
315
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500316 case SPRN_DEC:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100317 vcpu->arch.dec = kvmppc_get_gpr(vcpu, rs);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500318 kvmppc_emulate_dec(vcpu);
319 break;
320
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500321 case SPRN_SPRG0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100322 vcpu->arch.sprg0 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500323 case SPRN_SPRG1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100324 vcpu->arch.sprg1 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500325 case SPRN_SPRG2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100326 vcpu->arch.sprg2 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500327 case SPRN_SPRG3:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100328 vcpu->arch.sprg3 = kvmppc_get_gpr(vcpu, rs); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500329
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500330 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600331 emulated = kvmppc_core_emulate_mtspr(vcpu, sprn, rs);
332 if (emulated == EMULATE_FAIL)
333 printk("mtspr: unknown spr %x\n", sprn);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500334 break;
335 }
336 break;
337
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600338 case OP_31_XOP_DCBI:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500339 /* Do nothing. The guest is performing dcbi because
340 * hardware DMA is not snooped by the dcache, but
341 * emulated DMA either goes through the dcache as
342 * normal writes, or the host kernel has handled dcache
343 * coherence. */
344 break;
345
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600346 case OP_31_XOP_LWBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500347 rt = get_rt(inst);
348 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 0);
349 break;
350
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600351 case OP_31_XOP_TLBSYNC:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500352 break;
353
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600354 case OP_31_XOP_STWBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500355 rs = get_rs(inst);
356 ra = get_ra(inst);
357 rb = get_rb(inst);
358
359 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100360 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500361 4, 0);
362 break;
363
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600364 case OP_31_XOP_LHBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500365 rt = get_rt(inst);
366 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 0);
367 break;
368
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600369 case OP_31_XOP_STHBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500370 rs = get_rs(inst);
371 ra = get_ra(inst);
372 rb = get_rb(inst);
373
374 emulated = kvmppc_handle_store(run, vcpu,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100375 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500376 2, 0);
377 break;
378
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500379 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600380 /* Attempt core-specific emulation below. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500381 emulated = EMULATE_FAIL;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500382 }
383 break;
384
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600385 case OP_LWZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500386 rt = get_rt(inst);
387 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
388 break;
389
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600390 case OP_LWZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500391 ra = get_ra(inst);
392 rt = get_rt(inst);
393 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100394 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500395 break;
396
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600397 case OP_LBZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500398 rt = get_rt(inst);
399 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
400 break;
401
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600402 case OP_LBZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500403 ra = get_ra(inst);
404 rt = get_rt(inst);
405 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100406 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500407 break;
408
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600409 case OP_STW:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500410 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100411 emulated = kvmppc_handle_store(run, vcpu,
412 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500413 4, 1);
414 break;
415
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600416 case OP_STWU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500417 ra = get_ra(inst);
418 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100419 emulated = kvmppc_handle_store(run, vcpu,
420 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500421 4, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100422 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500423 break;
424
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600425 case OP_STB:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500426 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100427 emulated = kvmppc_handle_store(run, vcpu,
428 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500429 1, 1);
430 break;
431
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600432 case OP_STBU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500433 ra = get_ra(inst);
434 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100435 emulated = kvmppc_handle_store(run, vcpu,
436 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500437 1, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100438 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500439 break;
440
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600441 case OP_LHZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500442 rt = get_rt(inst);
443 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
444 break;
445
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600446 case OP_LHZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500447 ra = get_ra(inst);
448 rt = get_rt(inst);
449 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100450 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500451 break;
452
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600453 case OP_STH:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500454 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100455 emulated = kvmppc_handle_store(run, vcpu,
456 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500457 2, 1);
458 break;
459
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600460 case OP_STHU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500461 ra = get_ra(inst);
462 rs = get_rs(inst);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100463 emulated = kvmppc_handle_store(run, vcpu,
464 kvmppc_get_gpr(vcpu, rs),
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500465 2, 1);
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100466 kvmppc_set_gpr(vcpu, ra, vcpu->arch.paddr_accessed);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500467 break;
468
469 default:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500470 emulated = EMULATE_FAIL;
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600471 }
472
473 if (emulated == EMULATE_FAIL) {
474 emulated = kvmppc_core_emulate_op(run, vcpu, inst, &advance);
475 if (emulated == EMULATE_FAIL) {
476 advance = 0;
477 printk(KERN_ERR "Couldn't emulate instruction 0x%08x "
478 "(op %d xop %d)\n", inst, get_op(inst), get_xop(inst));
479 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500480 }
481
Marcelo Tosatti46f43c62009-06-18 11:47:27 -0300482 trace_kvm_ppc_instr(inst, vcpu->arch.pc, emulated);
Christian Ehrhardt3b4bd792008-07-14 14:00:04 +0200483
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500484 if (advance)
485 vcpu->arch.pc += 4; /* Advance past emulated instruction. */
486
487 return emulated;
488}