Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 1 | /* |
| 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 SUSE Linux Products GmbH 2009 |
| 16 | * |
| 17 | * Authors: Alexander Graf <agraf@suse.de> |
| 18 | */ |
| 19 | |
| 20 | #include <asm/kvm_ppc.h> |
| 21 | #include <asm/disassemble.h> |
| 22 | #include <asm/kvm_book3s.h> |
| 23 | #include <asm/reg.h> |
Benjamin Herrenschmidt | 95327d0 | 2012-04-01 17:35:53 +0000 | [diff] [blame] | 24 | #include <asm/switch_to.h> |
Paul Mackerras | b0a94d4 | 2012-11-04 18:15:43 +0000 | [diff] [blame] | 25 | #include <asm/time.h> |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 26 | |
| 27 | #define OP_19_XOP_RFID 18 |
| 28 | #define OP_19_XOP_RFI 50 |
| 29 | |
| 30 | #define OP_31_XOP_MFMSR 83 |
| 31 | #define OP_31_XOP_MTMSR 146 |
| 32 | #define OP_31_XOP_MTMSRD 178 |
Alexander Graf | 71db408 | 2010-02-19 11:00:37 +0100 | [diff] [blame] | 33 | #define OP_31_XOP_MTSR 210 |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 34 | #define OP_31_XOP_MTSRIN 242 |
| 35 | #define OP_31_XOP_TLBIEL 274 |
| 36 | #define OP_31_XOP_TLBIE 306 |
Alexander Graf | 50c7bb8 | 2012-12-14 23:42:05 +0100 | [diff] [blame] | 37 | /* Opcode is officially reserved, reuse it as sc 1 when sc 1 doesn't trap */ |
| 38 | #define OP_31_XOP_FAKE_SC1 308 |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 39 | #define OP_31_XOP_SLBMTE 402 |
| 40 | #define OP_31_XOP_SLBIE 434 |
| 41 | #define OP_31_XOP_SLBIA 498 |
Alexander Graf | c664876 | 2010-03-24 21:48:24 +0100 | [diff] [blame] | 42 | #define OP_31_XOP_MFSR 595 |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 43 | #define OP_31_XOP_MFSRIN 659 |
Alexander Graf | bd7cdbb | 2010-03-24 21:48:33 +0100 | [diff] [blame] | 44 | #define OP_31_XOP_DCBA 758 |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 45 | #define OP_31_XOP_SLBMFEV 851 |
| 46 | #define OP_31_XOP_EIOIO 854 |
| 47 | #define OP_31_XOP_SLBMFEE 915 |
| 48 | |
| 49 | /* DCBZ is actually 1014, but we patch it to 1010 so we get a trap */ |
| 50 | #define OP_31_XOP_DCBZ 1010 |
| 51 | |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 52 | #define OP_LFS 48 |
| 53 | #define OP_LFD 50 |
| 54 | #define OP_STFS 52 |
| 55 | #define OP_STFD 54 |
| 56 | |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 57 | #define SPRN_GQR0 912 |
| 58 | #define SPRN_GQR1 913 |
| 59 | #define SPRN_GQR2 914 |
| 60 | #define SPRN_GQR3 915 |
| 61 | #define SPRN_GQR4 916 |
| 62 | #define SPRN_GQR5 917 |
| 63 | #define SPRN_GQR6 918 |
| 64 | #define SPRN_GQR7 919 |
| 65 | |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 66 | /* Book3S_32 defines mfsrin(v) - but that messes up our abstract |
| 67 | * function pointers, so let's just disable the define. */ |
| 68 | #undef mfsrin |
| 69 | |
Alexander Graf | 317a8fa | 2011-08-08 16:07:16 +0200 | [diff] [blame] | 70 | enum priv_level { |
| 71 | PRIV_PROBLEM = 0, |
| 72 | PRIV_SUPER = 1, |
| 73 | PRIV_HYPER = 2, |
| 74 | }; |
| 75 | |
| 76 | static bool spr_allowed(struct kvm_vcpu *vcpu, enum priv_level level) |
| 77 | { |
| 78 | /* PAPR VMs only access supervisor SPRs */ |
| 79 | if (vcpu->arch.papr_enabled && (level > PRIV_SUPER)) |
| 80 | return false; |
| 81 | |
| 82 | /* Limit user space to its own small SPR set */ |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 83 | if ((kvmppc_get_msr(vcpu) & MSR_PR) && level > PRIV_PROBLEM) |
Alexander Graf | 317a8fa | 2011-08-08 16:07:16 +0200 | [diff] [blame] | 84 | return false; |
| 85 | |
| 86 | return true; |
| 87 | } |
| 88 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 89 | int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 90 | unsigned int inst, int *advance) |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 91 | { |
| 92 | int emulated = EMULATE_DONE; |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 93 | int rt = get_rt(inst); |
| 94 | int rs = get_rs(inst); |
| 95 | int ra = get_ra(inst); |
| 96 | int rb = get_rb(inst); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 97 | |
| 98 | switch (get_op(inst)) { |
| 99 | case 19: |
| 100 | switch (get_xop(inst)) { |
| 101 | case OP_19_XOP_RFID: |
| 102 | case OP_19_XOP_RFI: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 103 | kvmppc_set_pc(vcpu, kvmppc_get_srr0(vcpu)); |
| 104 | kvmppc_set_msr(vcpu, kvmppc_get_srr1(vcpu)); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 105 | *advance = 0; |
| 106 | break; |
| 107 | |
| 108 | default: |
| 109 | emulated = EMULATE_FAIL; |
| 110 | break; |
| 111 | } |
| 112 | break; |
| 113 | case 31: |
| 114 | switch (get_xop(inst)) { |
| 115 | case OP_31_XOP_MFMSR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 116 | kvmppc_set_gpr(vcpu, rt, kvmppc_get_msr(vcpu)); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 117 | break; |
| 118 | case OP_31_XOP_MTMSRD: |
| 119 | { |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 120 | ulong rs_val = kvmppc_get_gpr(vcpu, rs); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 121 | if (inst & 0x10000) { |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 122 | ulong new_msr = kvmppc_get_msr(vcpu); |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 123 | new_msr &= ~(MSR_RI | MSR_EE); |
| 124 | new_msr |= rs_val & (MSR_RI | MSR_EE); |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 125 | kvmppc_set_msr_fast(vcpu, new_msr); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 126 | } else |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 127 | kvmppc_set_msr(vcpu, rs_val); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | case OP_31_XOP_MTMSR: |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 131 | kvmppc_set_msr(vcpu, kvmppc_get_gpr(vcpu, rs)); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 132 | break; |
Alexander Graf | c664876 | 2010-03-24 21:48:24 +0100 | [diff] [blame] | 133 | case OP_31_XOP_MFSR: |
| 134 | { |
| 135 | int srnum; |
| 136 | |
| 137 | srnum = kvmppc_get_field(inst, 12 + 32, 15 + 32); |
| 138 | if (vcpu->arch.mmu.mfsrin) { |
| 139 | u32 sr; |
| 140 | sr = vcpu->arch.mmu.mfsrin(vcpu, srnum); |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 141 | kvmppc_set_gpr(vcpu, rt, sr); |
Alexander Graf | c664876 | 2010-03-24 21:48:24 +0100 | [diff] [blame] | 142 | } |
| 143 | break; |
| 144 | } |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 145 | case OP_31_XOP_MFSRIN: |
| 146 | { |
| 147 | int srnum; |
| 148 | |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 149 | srnum = (kvmppc_get_gpr(vcpu, rb) >> 28) & 0xf; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 150 | if (vcpu->arch.mmu.mfsrin) { |
| 151 | u32 sr; |
| 152 | sr = vcpu->arch.mmu.mfsrin(vcpu, srnum); |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 153 | kvmppc_set_gpr(vcpu, rt, sr); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 154 | } |
| 155 | break; |
| 156 | } |
Alexander Graf | 71db408 | 2010-02-19 11:00:37 +0100 | [diff] [blame] | 157 | case OP_31_XOP_MTSR: |
| 158 | vcpu->arch.mmu.mtsrin(vcpu, |
| 159 | (inst >> 16) & 0xf, |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 160 | kvmppc_get_gpr(vcpu, rs)); |
Alexander Graf | 71db408 | 2010-02-19 11:00:37 +0100 | [diff] [blame] | 161 | break; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 162 | case OP_31_XOP_MTSRIN: |
| 163 | vcpu->arch.mmu.mtsrin(vcpu, |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 164 | (kvmppc_get_gpr(vcpu, rb) >> 28) & 0xf, |
| 165 | kvmppc_get_gpr(vcpu, rs)); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 166 | break; |
| 167 | case OP_31_XOP_TLBIE: |
| 168 | case OP_31_XOP_TLBIEL: |
| 169 | { |
| 170 | bool large = (inst & 0x00200000) ? true : false; |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 171 | ulong addr = kvmppc_get_gpr(vcpu, rb); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 172 | vcpu->arch.mmu.tlbie(vcpu, addr, large); |
| 173 | break; |
| 174 | } |
Aneesh Kumar K.V | 2ba9f0d | 2013-10-07 22:17:59 +0530 | [diff] [blame] | 175 | #ifdef CONFIG_PPC_BOOK3S_64 |
Alexander Graf | 50c7bb8 | 2012-12-14 23:42:05 +0100 | [diff] [blame] | 176 | case OP_31_XOP_FAKE_SC1: |
| 177 | { |
| 178 | /* SC 1 papr hypercalls */ |
| 179 | ulong cmd = kvmppc_get_gpr(vcpu, 3); |
| 180 | int i; |
| 181 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 182 | if ((kvmppc_get_msr(vcpu) & MSR_PR) || |
Alexander Graf | 50c7bb8 | 2012-12-14 23:42:05 +0100 | [diff] [blame] | 183 | !vcpu->arch.papr_enabled) { |
| 184 | emulated = EMULATE_FAIL; |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | if (kvmppc_h_pr(vcpu, cmd) == EMULATE_DONE) |
| 189 | break; |
| 190 | |
| 191 | run->papr_hcall.nr = cmd; |
| 192 | for (i = 0; i < 9; ++i) { |
| 193 | ulong gpr = kvmppc_get_gpr(vcpu, 4 + i); |
| 194 | run->papr_hcall.args[i] = gpr; |
| 195 | } |
| 196 | |
Bharat Bhushan | 0f47f9b | 2013-04-08 00:32:14 +0000 | [diff] [blame] | 197 | run->exit_reason = KVM_EXIT_PAPR_HCALL; |
| 198 | vcpu->arch.hcall_needed = 1; |
Bharat Bhushan | c402a3f | 2013-04-08 00:32:13 +0000 | [diff] [blame] | 199 | emulated = EMULATE_EXIT_USER; |
Alexander Graf | 50c7bb8 | 2012-12-14 23:42:05 +0100 | [diff] [blame] | 200 | break; |
| 201 | } |
| 202 | #endif |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 203 | case OP_31_XOP_EIOIO: |
| 204 | break; |
| 205 | case OP_31_XOP_SLBMTE: |
| 206 | if (!vcpu->arch.mmu.slbmte) |
| 207 | return EMULATE_FAIL; |
| 208 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 209 | vcpu->arch.mmu.slbmte(vcpu, |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 210 | kvmppc_get_gpr(vcpu, rs), |
| 211 | kvmppc_get_gpr(vcpu, rb)); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 212 | break; |
| 213 | case OP_31_XOP_SLBIE: |
| 214 | if (!vcpu->arch.mmu.slbie) |
| 215 | return EMULATE_FAIL; |
| 216 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 217 | vcpu->arch.mmu.slbie(vcpu, |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 218 | kvmppc_get_gpr(vcpu, rb)); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 219 | break; |
| 220 | case OP_31_XOP_SLBIA: |
| 221 | if (!vcpu->arch.mmu.slbia) |
| 222 | return EMULATE_FAIL; |
| 223 | |
| 224 | vcpu->arch.mmu.slbia(vcpu); |
| 225 | break; |
| 226 | case OP_31_XOP_SLBMFEE: |
| 227 | if (!vcpu->arch.mmu.slbmfee) { |
| 228 | emulated = EMULATE_FAIL; |
| 229 | } else { |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 230 | ulong t, rb_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 231 | |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 232 | rb_val = kvmppc_get_gpr(vcpu, rb); |
| 233 | t = vcpu->arch.mmu.slbmfee(vcpu, rb_val); |
| 234 | kvmppc_set_gpr(vcpu, rt, t); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 235 | } |
| 236 | break; |
| 237 | case OP_31_XOP_SLBMFEV: |
| 238 | if (!vcpu->arch.mmu.slbmfev) { |
| 239 | emulated = EMULATE_FAIL; |
| 240 | } else { |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 241 | ulong t, rb_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 242 | |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 243 | rb_val = kvmppc_get_gpr(vcpu, rb); |
| 244 | t = vcpu->arch.mmu.slbmfev(vcpu, rb_val); |
| 245 | kvmppc_set_gpr(vcpu, rt, t); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 246 | } |
| 247 | break; |
Alexander Graf | bd7cdbb | 2010-03-24 21:48:33 +0100 | [diff] [blame] | 248 | case OP_31_XOP_DCBA: |
| 249 | /* Gets treated as NOP */ |
| 250 | break; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 251 | case OP_31_XOP_DCBZ: |
| 252 | { |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 253 | ulong rb_val = kvmppc_get_gpr(vcpu, rb); |
| 254 | ulong ra_val = 0; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 255 | ulong addr, vaddr; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 256 | u32 zeros[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 257 | u32 dsisr; |
| 258 | int r; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 259 | |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 260 | if (ra) |
| 261 | ra_val = kvmppc_get_gpr(vcpu, ra); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 262 | |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 263 | addr = (ra_val + rb_val) & ~31ULL; |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 264 | if (!(kvmppc_get_msr(vcpu) & MSR_SF)) |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 265 | addr &= 0xffffffff; |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 266 | vaddr = addr; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 267 | |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 268 | r = kvmppc_st(vcpu, &addr, 32, zeros, true); |
| 269 | if ((r == -ENOENT) || (r == -EPERM)) { |
| 270 | *advance = 0; |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 271 | kvmppc_set_dar(vcpu, vaddr); |
Paul Mackerras | a2d5602 | 2013-09-20 14:52:43 +1000 | [diff] [blame] | 272 | vcpu->arch.fault_dar = vaddr; |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 273 | |
| 274 | dsisr = DSISR_ISSTORE; |
| 275 | if (r == -ENOENT) |
| 276 | dsisr |= DSISR_NOHPTE; |
| 277 | else if (r == -EPERM) |
| 278 | dsisr |= DSISR_PROTFAULT; |
| 279 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 280 | kvmppc_set_dsisr(vcpu, dsisr); |
Paul Mackerras | a2d5602 | 2013-09-20 14:52:43 +1000 | [diff] [blame] | 281 | vcpu->arch.fault_dsisr = dsisr; |
Alexander Graf | 9fb244a | 2010-03-24 21:48:32 +0100 | [diff] [blame] | 282 | |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 283 | kvmppc_book3s_queue_irqprio(vcpu, |
| 284 | BOOK3S_INTERRUPT_DATA_STORAGE); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | break; |
| 288 | } |
| 289 | default: |
| 290 | emulated = EMULATE_FAIL; |
| 291 | } |
| 292 | break; |
| 293 | default: |
| 294 | emulated = EMULATE_FAIL; |
| 295 | } |
| 296 | |
Alexander Graf | 831317b | 2010-02-19 11:00:44 +0100 | [diff] [blame] | 297 | if (emulated == EMULATE_FAIL) |
| 298 | emulated = kvmppc_emulate_paired_single(run, vcpu); |
| 299 | |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 300 | return emulated; |
| 301 | } |
| 302 | |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 303 | void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, bool upper, |
| 304 | u32 val) |
| 305 | { |
| 306 | if (upper) { |
| 307 | /* Upper BAT */ |
| 308 | u32 bl = (val >> 2) & 0x7ff; |
| 309 | bat->bepi_mask = (~bl << 17); |
| 310 | bat->bepi = val & 0xfffe0000; |
| 311 | bat->vs = (val & 2) ? 1 : 0; |
| 312 | bat->vp = (val & 1) ? 1 : 0; |
| 313 | bat->raw = (bat->raw & 0xffffffff00000000ULL) | val; |
| 314 | } else { |
| 315 | /* Lower BAT */ |
| 316 | bat->brpn = val & 0xfffe0000; |
| 317 | bat->wimg = (val >> 3) & 0xf; |
| 318 | bat->pp = val & 3; |
| 319 | bat->raw = (bat->raw & 0x00000000ffffffffULL) | ((u64)val << 32); |
| 320 | } |
| 321 | } |
| 322 | |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 323 | static struct kvmppc_bat *kvmppc_find_bat(struct kvm_vcpu *vcpu, int sprn) |
Alexander Graf | c04a695 | 2010-03-24 21:48:25 +0100 | [diff] [blame] | 324 | { |
| 325 | struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu); |
| 326 | struct kvmppc_bat *bat; |
| 327 | |
| 328 | switch (sprn) { |
| 329 | case SPRN_IBAT0U ... SPRN_IBAT3L: |
| 330 | bat = &vcpu_book3s->ibat[(sprn - SPRN_IBAT0U) / 2]; |
| 331 | break; |
| 332 | case SPRN_IBAT4U ... SPRN_IBAT7L: |
| 333 | bat = &vcpu_book3s->ibat[4 + ((sprn - SPRN_IBAT4U) / 2)]; |
| 334 | break; |
| 335 | case SPRN_DBAT0U ... SPRN_DBAT3L: |
| 336 | bat = &vcpu_book3s->dbat[(sprn - SPRN_DBAT0U) / 2]; |
| 337 | break; |
| 338 | case SPRN_DBAT4U ... SPRN_DBAT7L: |
| 339 | bat = &vcpu_book3s->dbat[4 + ((sprn - SPRN_DBAT4U) / 2)]; |
| 340 | break; |
| 341 | default: |
| 342 | BUG(); |
| 343 | } |
| 344 | |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 345 | return bat; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 348 | int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 349 | { |
| 350 | int emulated = EMULATE_DONE; |
| 351 | |
| 352 | switch (sprn) { |
| 353 | case SPRN_SDR1: |
Alexander Graf | 317a8fa | 2011-08-08 16:07:16 +0200 | [diff] [blame] | 354 | if (!spr_allowed(vcpu, PRIV_HYPER)) |
| 355 | goto unprivileged; |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 356 | to_book3s(vcpu)->sdr1 = spr_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 357 | break; |
| 358 | case SPRN_DSISR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 359 | kvmppc_set_dsisr(vcpu, spr_val); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 360 | break; |
| 361 | case SPRN_DAR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 362 | kvmppc_set_dar(vcpu, spr_val); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 363 | break; |
| 364 | case SPRN_HIOR: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 365 | to_book3s(vcpu)->hior = spr_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 366 | break; |
| 367 | case SPRN_IBAT0U ... SPRN_IBAT3L: |
| 368 | case SPRN_IBAT4U ... SPRN_IBAT7L: |
| 369 | case SPRN_DBAT0U ... SPRN_DBAT3L: |
| 370 | case SPRN_DBAT4U ... SPRN_DBAT7L: |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 371 | { |
| 372 | struct kvmppc_bat *bat = kvmppc_find_bat(vcpu, sprn); |
| 373 | |
| 374 | kvmppc_set_bat(vcpu, bat, !(sprn % 2), (u32)spr_val); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 375 | /* BAT writes happen so rarely that we're ok to flush |
| 376 | * everything here */ |
| 377 | kvmppc_mmu_pte_flush(vcpu, 0, 0); |
Alexander Graf | c04a695 | 2010-03-24 21:48:25 +0100 | [diff] [blame] | 378 | kvmppc_mmu_flush_segments(vcpu); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 379 | break; |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 380 | } |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 381 | case SPRN_HID0: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 382 | to_book3s(vcpu)->hid[0] = spr_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 383 | break; |
| 384 | case SPRN_HID1: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 385 | to_book3s(vcpu)->hid[1] = spr_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 386 | break; |
| 387 | case SPRN_HID2: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 388 | to_book3s(vcpu)->hid[2] = spr_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 389 | break; |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 390 | case SPRN_HID2_GEKKO: |
| 391 | to_book3s(vcpu)->hid[2] = spr_val; |
| 392 | /* HID2.PSE controls paired single on gekko */ |
| 393 | switch (vcpu->arch.pvr) { |
| 394 | case 0x00080200: /* lonestar 2.0 */ |
| 395 | case 0x00088202: /* lonestar 2.2 */ |
| 396 | case 0x70000100: /* gekko 1.0 */ |
| 397 | case 0x00080100: /* gekko 2.0 */ |
| 398 | case 0x00083203: /* gekko 2.3a */ |
| 399 | case 0x00083213: /* gekko 2.3b */ |
| 400 | case 0x00083204: /* gekko 2.4 */ |
| 401 | case 0x00083214: /* gekko 2.4e (8SE) - retail HW2 */ |
Alexander Graf | b83d4a9 | 2010-04-20 02:49:54 +0200 | [diff] [blame] | 402 | case 0x00087200: /* broadway */ |
| 403 | if (vcpu->arch.hflags & BOOK3S_HFLAG_NATIVE_PS) { |
| 404 | /* Native paired singles */ |
| 405 | } else if (spr_val & (1 << 29)) { /* HID2.PSE */ |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 406 | vcpu->arch.hflags |= BOOK3S_HFLAG_PAIRED_SINGLE; |
| 407 | kvmppc_giveup_ext(vcpu, MSR_FP); |
| 408 | } else { |
| 409 | vcpu->arch.hflags &= ~BOOK3S_HFLAG_PAIRED_SINGLE; |
| 410 | } |
| 411 | break; |
| 412 | } |
| 413 | break; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 414 | case SPRN_HID4: |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 415 | case SPRN_HID4_GEKKO: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 416 | to_book3s(vcpu)->hid[4] = spr_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 417 | break; |
| 418 | case SPRN_HID5: |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 419 | to_book3s(vcpu)->hid[5] = spr_val; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 420 | /* guest HID5 set can change is_dcbz32 */ |
| 421 | if (vcpu->arch.mmu.is_dcbz32(vcpu) && |
| 422 | (mfmsr() & MSR_HV)) |
| 423 | vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32; |
| 424 | break; |
Paul Mackerras | b0a94d4 | 2012-11-04 18:15:43 +0000 | [diff] [blame] | 425 | case SPRN_PURR: |
| 426 | to_book3s(vcpu)->purr_offset = spr_val - get_tb(); |
| 427 | break; |
| 428 | case SPRN_SPURR: |
| 429 | to_book3s(vcpu)->spurr_offset = spr_val - get_tb(); |
| 430 | break; |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 431 | case SPRN_GQR0: |
| 432 | case SPRN_GQR1: |
| 433 | case SPRN_GQR2: |
| 434 | case SPRN_GQR3: |
| 435 | case SPRN_GQR4: |
| 436 | case SPRN_GQR5: |
| 437 | case SPRN_GQR6: |
| 438 | case SPRN_GQR7: |
| 439 | to_book3s(vcpu)->gqr[sprn - SPRN_GQR0] = spr_val; |
| 440 | break; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 441 | case SPRN_ICTC: |
| 442 | case SPRN_THRM1: |
| 443 | case SPRN_THRM2: |
| 444 | case SPRN_THRM3: |
| 445 | case SPRN_CTRLF: |
| 446 | case SPRN_CTRLT: |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 447 | case SPRN_L2CR: |
Paul Mackerras | b0a94d4 | 2012-11-04 18:15:43 +0000 | [diff] [blame] | 448 | case SPRN_DSCR: |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 449 | case SPRN_MMCR0_GEKKO: |
| 450 | case SPRN_MMCR1_GEKKO: |
| 451 | case SPRN_PMC1_GEKKO: |
| 452 | case SPRN_PMC2_GEKKO: |
| 453 | case SPRN_PMC3_GEKKO: |
| 454 | case SPRN_PMC4_GEKKO: |
| 455 | case SPRN_WPAR_GEKKO: |
Mihai Caraman | f2be655 | 2012-12-20 04:52:39 +0000 | [diff] [blame] | 456 | case SPRN_MSSSR0: |
Alexander Graf | f353202 | 2013-07-02 16:15:10 +0200 | [diff] [blame] | 457 | case SPRN_DABR: |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 458 | break; |
Alexander Graf | 317a8fa | 2011-08-08 16:07:16 +0200 | [diff] [blame] | 459 | unprivileged: |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 460 | default: |
| 461 | printk(KERN_INFO "KVM: invalid SPR write: %d\n", sprn); |
| 462 | #ifndef DEBUG_SPR |
| 463 | emulated = EMULATE_FAIL; |
| 464 | #endif |
| 465 | break; |
| 466 | } |
| 467 | |
| 468 | return emulated; |
| 469 | } |
| 470 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 471 | int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val) |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 472 | { |
| 473 | int emulated = EMULATE_DONE; |
| 474 | |
| 475 | switch (sprn) { |
Alexander Graf | c04a695 | 2010-03-24 21:48:25 +0100 | [diff] [blame] | 476 | case SPRN_IBAT0U ... SPRN_IBAT3L: |
| 477 | case SPRN_IBAT4U ... SPRN_IBAT7L: |
| 478 | case SPRN_DBAT0U ... SPRN_DBAT3L: |
| 479 | case SPRN_DBAT4U ... SPRN_DBAT7L: |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 480 | { |
| 481 | struct kvmppc_bat *bat = kvmppc_find_bat(vcpu, sprn); |
| 482 | |
| 483 | if (sprn % 2) |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 484 | *spr_val = bat->raw >> 32; |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 485 | else |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 486 | *spr_val = bat->raw; |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 487 | |
Alexander Graf | c04a695 | 2010-03-24 21:48:25 +0100 | [diff] [blame] | 488 | break; |
Alexander Graf | c1c88e2 | 2010-08-02 23:23:04 +0200 | [diff] [blame] | 489 | } |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 490 | case SPRN_SDR1: |
Alexander Graf | 317a8fa | 2011-08-08 16:07:16 +0200 | [diff] [blame] | 491 | if (!spr_allowed(vcpu, PRIV_HYPER)) |
| 492 | goto unprivileged; |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 493 | *spr_val = to_book3s(vcpu)->sdr1; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 494 | break; |
| 495 | case SPRN_DSISR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 496 | *spr_val = kvmppc_get_dsisr(vcpu); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 497 | break; |
| 498 | case SPRN_DAR: |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 499 | *spr_val = kvmppc_get_dar(vcpu); |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 500 | break; |
| 501 | case SPRN_HIOR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 502 | *spr_val = to_book3s(vcpu)->hior; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 503 | break; |
| 504 | case SPRN_HID0: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 505 | *spr_val = to_book3s(vcpu)->hid[0]; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 506 | break; |
| 507 | case SPRN_HID1: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 508 | *spr_val = to_book3s(vcpu)->hid[1]; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 509 | break; |
| 510 | case SPRN_HID2: |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 511 | case SPRN_HID2_GEKKO: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 512 | *spr_val = to_book3s(vcpu)->hid[2]; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 513 | break; |
| 514 | case SPRN_HID4: |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 515 | case SPRN_HID4_GEKKO: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 516 | *spr_val = to_book3s(vcpu)->hid[4]; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 517 | break; |
| 518 | case SPRN_HID5: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 519 | *spr_val = to_book3s(vcpu)->hid[5]; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 520 | break; |
Alexander Graf | aacf9aa | 2011-08-08 17:22:59 +0200 | [diff] [blame] | 521 | case SPRN_CFAR: |
Paul Mackerras | b0a94d4 | 2012-11-04 18:15:43 +0000 | [diff] [blame] | 522 | case SPRN_DSCR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 523 | *spr_val = 0; |
Alexander Graf | aacf9aa | 2011-08-08 17:22:59 +0200 | [diff] [blame] | 524 | break; |
Paul Mackerras | b0a94d4 | 2012-11-04 18:15:43 +0000 | [diff] [blame] | 525 | case SPRN_PURR: |
| 526 | *spr_val = get_tb() + to_book3s(vcpu)->purr_offset; |
| 527 | break; |
| 528 | case SPRN_SPURR: |
| 529 | *spr_val = get_tb() + to_book3s(vcpu)->purr_offset; |
| 530 | break; |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 531 | case SPRN_GQR0: |
| 532 | case SPRN_GQR1: |
| 533 | case SPRN_GQR2: |
| 534 | case SPRN_GQR3: |
| 535 | case SPRN_GQR4: |
| 536 | case SPRN_GQR5: |
| 537 | case SPRN_GQR6: |
| 538 | case SPRN_GQR7: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 539 | *spr_val = to_book3s(vcpu)->gqr[sprn - SPRN_GQR0]; |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 540 | break; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 541 | case SPRN_THRM1: |
| 542 | case SPRN_THRM2: |
| 543 | case SPRN_THRM3: |
| 544 | case SPRN_CTRLF: |
| 545 | case SPRN_CTRLT: |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 546 | case SPRN_L2CR: |
| 547 | case SPRN_MMCR0_GEKKO: |
| 548 | case SPRN_MMCR1_GEKKO: |
| 549 | case SPRN_PMC1_GEKKO: |
| 550 | case SPRN_PMC2_GEKKO: |
| 551 | case SPRN_PMC3_GEKKO: |
| 552 | case SPRN_PMC4_GEKKO: |
| 553 | case SPRN_WPAR_GEKKO: |
Mihai Caraman | f2be655 | 2012-12-20 04:52:39 +0000 | [diff] [blame] | 554 | case SPRN_MSSSR0: |
Alexander Graf | f353202 | 2013-07-02 16:15:10 +0200 | [diff] [blame] | 555 | case SPRN_DABR: |
Alexander Graf | 54771e6 | 2012-05-04 14:55:12 +0200 | [diff] [blame] | 556 | *spr_val = 0; |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 557 | break; |
| 558 | default: |
Alexander Graf | 317a8fa | 2011-08-08 16:07:16 +0200 | [diff] [blame] | 559 | unprivileged: |
Alexander Graf | c215c6e | 2009-10-30 05:47:14 +0000 | [diff] [blame] | 560 | printk(KERN_INFO "KVM: invalid SPR read: %d\n", sprn); |
| 561 | #ifndef DEBUG_SPR |
| 562 | emulated = EMULATE_FAIL; |
| 563 | #endif |
| 564 | break; |
| 565 | } |
| 566 | |
| 567 | return emulated; |
| 568 | } |
| 569 | |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 570 | u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst) |
| 571 | { |
| 572 | u32 dsisr = 0; |
| 573 | |
| 574 | /* |
| 575 | * This is what the spec says about DSISR bits (not mentioned = 0): |
| 576 | * |
| 577 | * 12:13 [DS] Set to bits 30:31 |
| 578 | * 15:16 [X] Set to bits 29:30 |
| 579 | * 17 [X] Set to bit 25 |
| 580 | * [D/DS] Set to bit 5 |
| 581 | * 18:21 [X] Set to bits 21:24 |
| 582 | * [D/DS] Set to bits 1:4 |
| 583 | * 22:26 Set to bits 6:10 (RT/RS/FRT/FRS) |
| 584 | * 27:31 Set to bits 11:15 (RA) |
| 585 | */ |
| 586 | |
| 587 | switch (get_op(inst)) { |
| 588 | /* D-form */ |
| 589 | case OP_LFS: |
| 590 | case OP_LFD: |
| 591 | case OP_STFD: |
| 592 | case OP_STFS: |
| 593 | dsisr |= (inst >> 12) & 0x4000; /* bit 17 */ |
| 594 | dsisr |= (inst >> 17) & 0x3c00; /* bits 18:21 */ |
| 595 | break; |
| 596 | /* X-form */ |
| 597 | case 31: |
| 598 | dsisr |= (inst << 14) & 0x18000; /* bits 15:16 */ |
| 599 | dsisr |= (inst << 8) & 0x04000; /* bit 17 */ |
| 600 | dsisr |= (inst << 3) & 0x03c00; /* bits 18:21 */ |
| 601 | break; |
| 602 | default: |
| 603 | printk(KERN_INFO "KVM: Unaligned instruction 0x%x\n", inst); |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | dsisr |= (inst >> 16) & 0x03ff; /* bits 22:31 */ |
| 608 | |
| 609 | return dsisr; |
| 610 | } |
| 611 | |
| 612 | ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst) |
| 613 | { |
| 614 | ulong dar = 0; |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 615 | ulong ra = get_ra(inst); |
| 616 | ulong rb = get_rb(inst); |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 617 | |
| 618 | switch (get_op(inst)) { |
| 619 | case OP_LFS: |
| 620 | case OP_LFD: |
| 621 | case OP_STFD: |
| 622 | case OP_STFS: |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 623 | if (ra) |
| 624 | dar = kvmppc_get_gpr(vcpu, ra); |
| 625 | dar += (s32)((s16)inst); |
| 626 | break; |
| 627 | case 31: |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 628 | if (ra) |
| 629 | dar = kvmppc_get_gpr(vcpu, ra); |
Alexander Graf | c46dc9a | 2012-05-04 14:01:33 +0200 | [diff] [blame] | 630 | dar += kvmppc_get_gpr(vcpu, rb); |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 631 | break; |
| 632 | default: |
| 633 | printk(KERN_INFO "KVM: Unaligned instruction 0x%x\n", inst); |
| 634 | break; |
| 635 | } |
| 636 | |
| 637 | return dar; |
| 638 | } |