blob: 1ec5e07b81eb939f05334e66b42442ca1d20d75b [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>
21#include <linux/timer.h>
22#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 Graf9a7a9b02009-10-30 05:47:15 +000082 unsigned long nr_jiffies;
83
Alexander Graf513579e2009-10-30 05:47:16 +000084#ifdef CONFIG_PPC64
85 /* POWER4+ triggers a dec interrupt if the value is < 0 */
86 if (vcpu->arch.dec & 0x80000000) {
87 del_timer(&vcpu->arch.dec_timer);
88 kvmppc_core_queue_dec(vcpu);
89 return;
90 }
91#endif
92 if (kvmppc_dec_enabled(vcpu)) {
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050093 /* The decrementer ticks at the same rate as the timebase, so
94 * that's how we convert the guest DEC value to the number of
95 * host ticks. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050096
Alexander Graf513579e2009-10-30 05:47:16 +000097 vcpu->arch.dec_jiffies = get_tb();
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050098 nr_jiffies = vcpu->arch.dec / tb_ticks_per_jiffy;
99 mod_timer(&vcpu->arch.dec_timer,
100 get_jiffies_64() + nr_jiffies);
101 } else {
102 del_timer(&vcpu->arch.dec_timer);
103 }
104}
105
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500106/* XXX to do:
107 * lhax
108 * lhaux
109 * lswx
110 * lswi
111 * stswx
112 * stswi
113 * lha
114 * lhau
115 * lmw
116 * stmw
117 *
118 * XXX is_bigendian should depend on MMU mapping or MSR[LE]
119 */
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600120/* XXX Should probably auto-generate instruction decoding for a particular core
121 * from opcode tables in the future. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500122int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
123{
124 u32 inst = vcpu->arch.last_inst;
125 u32 ea;
126 int ra;
127 int rb;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500128 int rs;
129 int rt;
130 int sprn;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500131 enum emulation_result emulated = EMULATE_DONE;
132 int advance = 1;
133
Hollis Blanchard73e75b42008-12-02 15:51:57 -0600134 /* this default type might be overwritten by subcategories */
135 kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
136
Alexander Graf513579e2009-10-30 05:47:16 +0000137 pr_debug(KERN_INFO "Emulating opcode %d / %d\n", get_op(inst), get_xop(inst));
138
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500139 switch (get_op(inst)) {
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600140 case OP_TRAP:
Alexander Graf513579e2009-10-30 05:47:16 +0000141#ifdef CONFIG_PPC64
142 case OP_TRAP_64:
143#else
Hollis Blanchardfcfdbd22008-11-05 09:36:24 -0600144 vcpu->arch.esr |= ESR_PTR;
Alexander Graf513579e2009-10-30 05:47:16 +0000145#endif
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600146 kvmppc_core_queue_program(vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500147 advance = 0;
148 break;
149
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500150 case 31:
151 switch (get_xop(inst)) {
152
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600153 case OP_31_XOP_LWZX:
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500154 rt = get_rt(inst);
155 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
156 break;
157
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600158 case OP_31_XOP_LBZX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500159 rt = get_rt(inst);
160 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
161 break;
162
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600163 case OP_31_XOP_STWX:
Hollis Blanchardac3cd342008-05-21 18:22:52 -0500164 rs = get_rs(inst);
165 emulated = kvmppc_handle_store(run, vcpu,
166 vcpu->arch.gpr[rs],
167 4, 1);
168 break;
169
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600170 case OP_31_XOP_STBX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500171 rs = get_rs(inst);
172 emulated = kvmppc_handle_store(run, vcpu,
173 vcpu->arch.gpr[rs],
174 1, 1);
175 break;
176
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600177 case OP_31_XOP_STBUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500178 rs = get_rs(inst);
179 ra = get_ra(inst);
180 rb = get_rb(inst);
181
182 ea = vcpu->arch.gpr[rb];
183 if (ra)
184 ea += vcpu->arch.gpr[ra];
185
186 emulated = kvmppc_handle_store(run, vcpu,
187 vcpu->arch.gpr[rs],
188 1, 1);
189 vcpu->arch.gpr[rs] = ea;
190 break;
191
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600192 case OP_31_XOP_LHZX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500193 rt = get_rt(inst);
194 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
195 break;
196
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600197 case OP_31_XOP_LHZUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500198 rt = get_rt(inst);
199 ra = get_ra(inst);
200 rb = get_rb(inst);
201
202 ea = vcpu->arch.gpr[rb];
203 if (ra)
204 ea += vcpu->arch.gpr[ra];
205
206 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
207 vcpu->arch.gpr[ra] = ea;
208 break;
209
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600210 case OP_31_XOP_MFSPR:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500211 sprn = get_sprn(inst);
212 rt = get_rt(inst);
213
214 switch (sprn) {
215 case SPRN_SRR0:
216 vcpu->arch.gpr[rt] = vcpu->arch.srr0; break;
217 case SPRN_SRR1:
218 vcpu->arch.gpr[rt] = vcpu->arch.srr1; break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500219 case SPRN_PVR:
Alexander Graf513579e2009-10-30 05:47:16 +0000220 vcpu->arch.gpr[rt] = vcpu->arch.pvr; break;
Liu Yu06579dd2009-06-05 14:54:31 +0800221 case SPRN_PIR:
Alexander Graf513579e2009-10-30 05:47:16 +0000222 vcpu->arch.gpr[rt] = vcpu->vcpu_id; break;
223 case SPRN_MSSSR0:
224 vcpu->arch.gpr[rt] = 0; break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500225
226 /* Note: mftb and TBRL/TBWL are user-accessible, so
227 * the guest can always access the real TB anyways.
228 * In fact, we probably will never see these traps. */
229 case SPRN_TBWL:
Alexander Graf513579e2009-10-30 05:47:16 +0000230 vcpu->arch.gpr[rt] = get_tb() >> 32; break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500231 case SPRN_TBWU:
Alexander Graf513579e2009-10-30 05:47:16 +0000232 vcpu->arch.gpr[rt] = get_tb(); break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500233
234 case SPRN_SPRG0:
235 vcpu->arch.gpr[rt] = vcpu->arch.sprg0; break;
236 case SPRN_SPRG1:
237 vcpu->arch.gpr[rt] = vcpu->arch.sprg1; break;
238 case SPRN_SPRG2:
239 vcpu->arch.gpr[rt] = vcpu->arch.sprg2; break;
240 case SPRN_SPRG3:
241 vcpu->arch.gpr[rt] = vcpu->arch.sprg3; break;
242 /* Note: SPRG4-7 are user-readable, so we don't get
243 * a trap. */
244
Alexander Graf9a7a9b02009-10-30 05:47:15 +0000245 case SPRN_DEC:
246 {
Alexander Graf513579e2009-10-30 05:47:16 +0000247 u64 jd = get_tb() - vcpu->arch.dec_jiffies;
Alexander Graf9a7a9b02009-10-30 05:47:15 +0000248 vcpu->arch.gpr[rt] = vcpu->arch.dec - jd;
Alexander Graf513579e2009-10-30 05:47:16 +0000249 pr_debug(KERN_INFO "mfDEC: %x - %llx = %lx\n", vcpu->arch.dec, jd, vcpu->arch.gpr[rt]);
Alexander Graf9a7a9b02009-10-30 05:47:15 +0000250 break;
251 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500252 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600253 emulated = kvmppc_core_emulate_mfspr(vcpu, sprn, rt);
254 if (emulated == EMULATE_FAIL) {
255 printk("mfspr: unknown spr %x\n", sprn);
256 vcpu->arch.gpr[rt] = 0;
257 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500258 break;
259 }
260 break;
261
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600262 case OP_31_XOP_STHX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500263 rs = get_rs(inst);
264 ra = get_ra(inst);
265 rb = get_rb(inst);
266
267 emulated = kvmppc_handle_store(run, vcpu,
268 vcpu->arch.gpr[rs],
269 2, 1);
270 break;
271
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600272 case OP_31_XOP_STHUX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500273 rs = get_rs(inst);
274 ra = get_ra(inst);
275 rb = get_rb(inst);
276
277 ea = vcpu->arch.gpr[rb];
278 if (ra)
279 ea += vcpu->arch.gpr[ra];
280
281 emulated = kvmppc_handle_store(run, vcpu,
282 vcpu->arch.gpr[rs],
283 2, 1);
284 vcpu->arch.gpr[ra] = ea;
285 break;
286
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600287 case OP_31_XOP_MTSPR:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500288 sprn = get_sprn(inst);
289 rs = get_rs(inst);
290 switch (sprn) {
291 case SPRN_SRR0:
292 vcpu->arch.srr0 = vcpu->arch.gpr[rs]; break;
293 case SPRN_SRR1:
294 vcpu->arch.srr1 = vcpu->arch.gpr[rs]; break;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500295
296 /* XXX We need to context-switch the timebase for
297 * watchdog and FIT. */
298 case SPRN_TBWL: break;
299 case SPRN_TBWU: break;
300
Alexander Graf513579e2009-10-30 05:47:16 +0000301 case SPRN_MSSSR0: break;
302
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500303 case SPRN_DEC:
304 vcpu->arch.dec = vcpu->arch.gpr[rs];
305 kvmppc_emulate_dec(vcpu);
306 break;
307
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500308 case SPRN_SPRG0:
309 vcpu->arch.sprg0 = vcpu->arch.gpr[rs]; break;
310 case SPRN_SPRG1:
311 vcpu->arch.sprg1 = vcpu->arch.gpr[rs]; break;
312 case SPRN_SPRG2:
313 vcpu->arch.sprg2 = vcpu->arch.gpr[rs]; break;
314 case SPRN_SPRG3:
315 vcpu->arch.sprg3 = vcpu->arch.gpr[rs]; break;
316
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500317 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600318 emulated = kvmppc_core_emulate_mtspr(vcpu, sprn, rs);
319 if (emulated == EMULATE_FAIL)
320 printk("mtspr: unknown spr %x\n", sprn);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500321 break;
322 }
323 break;
324
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600325 case OP_31_XOP_DCBI:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500326 /* Do nothing. The guest is performing dcbi because
327 * hardware DMA is not snooped by the dcache, but
328 * emulated DMA either goes through the dcache as
329 * normal writes, or the host kernel has handled dcache
330 * coherence. */
331 break;
332
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600333 case OP_31_XOP_LWBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500334 rt = get_rt(inst);
335 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 0);
336 break;
337
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600338 case OP_31_XOP_TLBSYNC:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500339 break;
340
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600341 case OP_31_XOP_STWBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500342 rs = get_rs(inst);
343 ra = get_ra(inst);
344 rb = get_rb(inst);
345
346 emulated = kvmppc_handle_store(run, vcpu,
347 vcpu->arch.gpr[rs],
348 4, 0);
349 break;
350
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600351 case OP_31_XOP_LHBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500352 rt = get_rt(inst);
353 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 0);
354 break;
355
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600356 case OP_31_XOP_STHBRX:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500357 rs = get_rs(inst);
358 ra = get_ra(inst);
359 rb = get_rb(inst);
360
361 emulated = kvmppc_handle_store(run, vcpu,
362 vcpu->arch.gpr[rs],
363 2, 0);
364 break;
365
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500366 default:
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600367 /* Attempt core-specific emulation below. */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500368 emulated = EMULATE_FAIL;
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500369 }
370 break;
371
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600372 case OP_LWZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500373 rt = get_rt(inst);
374 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
375 break;
376
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600377 case OP_LWZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500378 ra = get_ra(inst);
379 rt = get_rt(inst);
380 emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
381 vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed;
382 break;
383
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600384 case OP_LBZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500385 rt = get_rt(inst);
386 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
387 break;
388
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600389 case OP_LBZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500390 ra = get_ra(inst);
391 rt = get_rt(inst);
392 emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
393 vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed;
394 break;
395
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600396 case OP_STW:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500397 rs = get_rs(inst);
398 emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs],
399 4, 1);
400 break;
401
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600402 case OP_STWU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500403 ra = get_ra(inst);
404 rs = get_rs(inst);
405 emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs],
406 4, 1);
407 vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed;
408 break;
409
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600410 case OP_STB:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500411 rs = get_rs(inst);
412 emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs],
413 1, 1);
414 break;
415
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600416 case OP_STBU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500417 ra = get_ra(inst);
418 rs = get_rs(inst);
419 emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs],
420 1, 1);
421 vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed;
422 break;
423
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600424 case OP_LHZ:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500425 rt = get_rt(inst);
426 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
427 break;
428
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600429 case OP_LHZU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500430 ra = get_ra(inst);
431 rt = get_rt(inst);
432 emulated = kvmppc_handle_load(run, vcpu, rt, 2, 1);
433 vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed;
434 break;
435
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600436 case OP_STH:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500437 rs = get_rs(inst);
438 emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs],
439 2, 1);
440 break;
441
Hollis Blanchardcea5d8c2009-01-03 16:23:05 -0600442 case OP_STHU:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500443 ra = get_ra(inst);
444 rs = get_rs(inst);
445 emulated = kvmppc_handle_store(run, vcpu, vcpu->arch.gpr[rs],
446 2, 1);
447 vcpu->arch.gpr[ra] = vcpu->arch.paddr_accessed;
448 break;
449
450 default:
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500451 emulated = EMULATE_FAIL;
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600452 }
453
454 if (emulated == EMULATE_FAIL) {
455 emulated = kvmppc_core_emulate_op(run, vcpu, inst, &advance);
456 if (emulated == EMULATE_FAIL) {
457 advance = 0;
458 printk(KERN_ERR "Couldn't emulate instruction 0x%08x "
459 "(op %d xop %d)\n", inst, get_op(inst), get_xop(inst));
460 }
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500461 }
462
Marcelo Tosatti46f43c62009-06-18 11:47:27 -0300463 trace_kvm_ppc_instr(inst, vcpu->arch.pc, emulated);
Christian Ehrhardt3b4bd792008-07-14 14:00:04 +0200464
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500465 if (advance)
466 vcpu->arch.pc += 4; /* Advance past emulated instruction. */
467
468 return emulated;
469}