blob: 6d0b2bd54fb0a9ffef74f3bfb21b04fa34aa4ce7 [file] [log] [blame]
Hollis Blanchardbc8080c2009-01-03 16:23:10 -06001/*
Scott Wood5ce941e2011-04-27 17:24:21 -05002 * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
Hollis Blanchardbc8080c2009-01-03 16:23:10 -06003 *
4 * Author: Yu Liu, <yu.liu@freescale.com>
5 *
6 * Description:
7 * This file is derived from arch/powerpc/kvm/44x_emulate.c,
8 * by Hollis Blanchard <hollisb@us.ibm.com>.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License, version 2, as
12 * published by the Free Software Foundation.
13 */
14
15#include <asm/kvm_ppc.h>
16#include <asm/disassemble.h>
17#include <asm/kvm_e500.h>
18
19#include "booke.h"
20#include "e500_tlb.h"
21
22#define XOP_TLBIVAX 786
23#define XOP_TLBSX 914
24#define XOP_TLBRE 946
25#define XOP_TLBWE 978
26
27int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
28 unsigned int inst, int *advance)
29{
30 int emulated = EMULATE_DONE;
31 int ra;
32 int rb;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060033
34 switch (get_op(inst)) {
35 case 31:
36 switch (get_xop(inst)) {
37
38 case XOP_TLBRE:
39 emulated = kvmppc_e500_emul_tlbre(vcpu);
40 break;
41
42 case XOP_TLBWE:
43 emulated = kvmppc_e500_emul_tlbwe(vcpu);
44 break;
45
46 case XOP_TLBSX:
47 rb = get_rb(inst);
48 emulated = kvmppc_e500_emul_tlbsx(vcpu,rb);
49 break;
50
51 case XOP_TLBIVAX:
52 ra = get_ra(inst);
53 rb = get_rb(inst);
54 emulated = kvmppc_e500_emul_tlbivax(vcpu, ra, rb);
55 break;
56
57 default:
58 emulated = EMULATE_FAIL;
59 }
60
61 break;
62
63 default:
64 emulated = EMULATE_FAIL;
65 }
66
67 if (emulated == EMULATE_FAIL)
68 emulated = kvmppc_booke_emulate_op(run, vcpu, inst, advance);
69
70 return emulated;
71}
72
73int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
74{
75 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
76 int emulated = EMULATE_DONE;
Alexander Graf8e5b26b2010-01-08 02:58:01 +010077 ulong spr_val = kvmppc_get_gpr(vcpu, rs);
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060078
79 switch (sprn) {
80 case SPRN_PID:
Scott Wood5ce941e2011-04-27 17:24:21 -050081 kvmppc_set_pid(vcpu, spr_val);
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060082 break;
83 case SPRN_PID1:
Liu Yudd9ebf1f2011-06-14 18:35:14 -050084 if (spr_val != 0)
85 return EMULATE_FAIL;
Alexander Graf8e5b26b2010-01-08 02:58:01 +010086 vcpu_e500->pid[1] = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060087 case SPRN_PID2:
Liu Yudd9ebf1f2011-06-14 18:35:14 -050088 if (spr_val != 0)
89 return EMULATE_FAIL;
Alexander Graf8e5b26b2010-01-08 02:58:01 +010090 vcpu_e500->pid[2] = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060091 case SPRN_MAS0:
Scott Woodb5904972011-11-08 18:23:30 -060092 vcpu->arch.shared->mas0 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060093 case SPRN_MAS1:
Scott Woodb5904972011-11-08 18:23:30 -060094 vcpu->arch.shared->mas1 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060095 case SPRN_MAS2:
Scott Woodb5904972011-11-08 18:23:30 -060096 vcpu->arch.shared->mas2 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -060097 case SPRN_MAS3:
Scott Woodb5904972011-11-08 18:23:30 -060098 vcpu->arch.shared->mas7_3 &= ~(u64)0xffffffff;
99 vcpu->arch.shared->mas7_3 |= spr_val;
Scott Wooddc83b8b2011-08-18 15:25:21 -0500100 break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600101 case SPRN_MAS4:
Scott Woodb5904972011-11-08 18:23:30 -0600102 vcpu->arch.shared->mas4 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600103 case SPRN_MAS6:
Scott Woodb5904972011-11-08 18:23:30 -0600104 vcpu->arch.shared->mas6 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600105 case SPRN_MAS7:
Scott Woodb5904972011-11-08 18:23:30 -0600106 vcpu->arch.shared->mas7_3 &= (u64)0xffffffff;
107 vcpu->arch.shared->mas7_3 |= (u64)spr_val << 32;
Scott Wooddc83b8b2011-08-18 15:25:21 -0500108 break;
Liu Yud86be072010-01-22 18:50:29 +0800109 case SPRN_L1CSR0:
110 vcpu_e500->l1csr0 = spr_val;
111 vcpu_e500->l1csr0 &= ~(L1CSR0_DCFI | L1CSR0_CLFC);
112 break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600113 case SPRN_L1CSR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100114 vcpu_e500->l1csr1 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600115 case SPRN_HID0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100116 vcpu_e500->hid0 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600117 case SPRN_HID1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100118 vcpu_e500->hid1 = spr_val; break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600119
Liu Yub0a18352009-02-17 16:52:08 +0800120 case SPRN_MMUCSR0:
121 emulated = kvmppc_e500_emul_mt_mmucsr0(vcpu_e500,
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100122 spr_val);
Liu Yub0a18352009-02-17 16:52:08 +0800123 break;
124
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600125 /* extra exceptions */
126 case SPRN_IVOR32:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100127 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600128 break;
129 case SPRN_IVOR33:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100130 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600131 break;
132 case SPRN_IVOR34:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100133 vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600134 break;
135 case SPRN_IVOR35:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100136 vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR] = spr_val;
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600137 break;
138
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600139 default:
140 emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, rs);
141 }
142
143 return emulated;
144}
145
146int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
147{
148 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
149 int emulated = EMULATE_DONE;
Scott Woodb5904972011-11-08 18:23:30 -0600150 unsigned long val;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600151
152 switch (sprn) {
153 case SPRN_PID:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100154 kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[0]); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600155 case SPRN_PID1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100156 kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[1]); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600157 case SPRN_PID2:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100158 kvmppc_set_gpr(vcpu, rt, vcpu_e500->pid[2]); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600159 case SPRN_MAS0:
Scott Woodb5904972011-11-08 18:23:30 -0600160 kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas0); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600161 case SPRN_MAS1:
Scott Woodb5904972011-11-08 18:23:30 -0600162 kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas1); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600163 case SPRN_MAS2:
Scott Woodb5904972011-11-08 18:23:30 -0600164 kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas2); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600165 case SPRN_MAS3:
Scott Woodb5904972011-11-08 18:23:30 -0600166 val = (u32)vcpu->arch.shared->mas7_3;
167 kvmppc_set_gpr(vcpu, rt, val);
168 break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600169 case SPRN_MAS4:
Scott Woodb5904972011-11-08 18:23:30 -0600170 kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas4); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600171 case SPRN_MAS6:
Scott Woodb5904972011-11-08 18:23:30 -0600172 kvmppc_set_gpr(vcpu, rt, vcpu->arch.shared->mas6); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600173 case SPRN_MAS7:
Scott Woodb5904972011-11-08 18:23:30 -0600174 val = vcpu->arch.shared->mas7_3 >> 32;
175 kvmppc_set_gpr(vcpu, rt, val);
176 break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600177 case SPRN_TLB0CFG:
Liu Yuda15bf42010-01-22 19:36:53 +0800178 kvmppc_set_gpr(vcpu, rt, vcpu_e500->tlb0cfg); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600179 case SPRN_TLB1CFG:
Liu Yuda15bf42010-01-22 19:36:53 +0800180 kvmppc_set_gpr(vcpu, rt, vcpu_e500->tlb1cfg); break;
Liu Yud86be072010-01-22 18:50:29 +0800181 case SPRN_L1CSR0:
182 kvmppc_set_gpr(vcpu, rt, vcpu_e500->l1csr0); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600183 case SPRN_L1CSR1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100184 kvmppc_set_gpr(vcpu, rt, vcpu_e500->l1csr1); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600185 case SPRN_HID0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100186 kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid0); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600187 case SPRN_HID1:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100188 kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid1); break;
Scott Wood90d34b02011-03-29 16:49:10 -0500189 case SPRN_SVR:
190 kvmppc_set_gpr(vcpu, rt, vcpu_e500->svr); break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600191
Liu Yub0a18352009-02-17 16:52:08 +0800192 case SPRN_MMUCSR0:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100193 kvmppc_set_gpr(vcpu, rt, 0); break;
Liu Yub0a18352009-02-17 16:52:08 +0800194
Liu Yu06579dd2009-06-05 14:54:31 +0800195 case SPRN_MMUCFG:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100196 kvmppc_set_gpr(vcpu, rt, mfspr(SPRN_MMUCFG)); break;
Liu Yu06579dd2009-06-05 14:54:31 +0800197
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600198 /* extra exceptions */
199 case SPRN_IVOR32:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100200 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_UNAVAIL]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600201 break;
202 case SPRN_IVOR33:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100203 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_DATA]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600204 break;
205 case SPRN_IVOR34:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100206 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_SPE_FP_ROUND]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600207 break;
208 case SPRN_IVOR35:
Alexander Graf8e5b26b2010-01-08 02:58:01 +0100209 kvmppc_set_gpr(vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR]);
Hollis Blanchardbb3a8a12009-01-03 16:23:13 -0600210 break;
Hollis Blanchardbc8080c2009-01-03 16:23:10 -0600211 default:
212 emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, rt);
213 }
214
215 return emulated;
216}
217