book3s_emulate.c 16 KB

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