unaligned_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * unaligned.c: Unaligned load/store trap handling with special
  3. * cases for the kernel to do them more quickly.
  4. *
  5. * Copyright (C) 1996,2008 David S. Miller (davem@davemloft.net)
  6. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  7. */
  8. #include <linux/jiffies.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/mm.h>
  12. #include <linux/module.h>
  13. #include <asm/asi.h>
  14. #include <asm/ptrace.h>
  15. #include <asm/pstate.h>
  16. #include <asm/processor.h>
  17. #include <asm/system.h>
  18. #include <asm/uaccess.h>
  19. #include <linux/smp.h>
  20. #include <linux/bitops.h>
  21. #include <linux/perf_event.h>
  22. #include <linux/ratelimit.h>
  23. #include <linux/bitops.h>
  24. #include <asm/fpumacro.h>
  25. enum direction {
  26. load, /* ld, ldd, ldh, ldsh */
  27. store, /* st, std, sth, stsh */
  28. both, /* Swap, ldstub, cas, ... */
  29. fpld,
  30. fpst,
  31. invalid,
  32. };
  33. static inline enum direction decode_direction(unsigned int insn)
  34. {
  35. unsigned long tmp = (insn >> 21) & 1;
  36. if (!tmp)
  37. return load;
  38. else {
  39. switch ((insn>>19)&0xf) {
  40. case 15: /* swap* */
  41. return both;
  42. default:
  43. return store;
  44. }
  45. }
  46. }
  47. /* 16 = double-word, 8 = extra-word, 4 = word, 2 = half-word */
  48. static inline int decode_access_size(struct pt_regs *regs, unsigned int insn)
  49. {
  50. unsigned int tmp;
  51. tmp = ((insn >> 19) & 0xf);
  52. if (tmp == 11 || tmp == 14) /* ldx/stx */
  53. return 8;
  54. tmp &= 3;
  55. if (!tmp)
  56. return 4;
  57. else if (tmp == 3)
  58. return 16; /* ldd/std - Although it is actually 8 */
  59. else if (tmp == 2)
  60. return 2;
  61. else {
  62. printk("Impossible unaligned trap. insn=%08x\n", insn);
  63. die_if_kernel("Byte sized unaligned access?!?!", regs);
  64. /* GCC should never warn that control reaches the end
  65. * of this function without returning a value because
  66. * die_if_kernel() is marked with attribute 'noreturn'.
  67. * Alas, some versions do...
  68. */
  69. return 0;
  70. }
  71. }
  72. static inline int decode_asi(unsigned int insn, struct pt_regs *regs)
  73. {
  74. if (insn & 0x800000) {
  75. if (insn & 0x2000)
  76. return (unsigned char)(regs->tstate >> 24); /* %asi */
  77. else
  78. return (unsigned char)(insn >> 5); /* imm_asi */
  79. } else
  80. return ASI_P;
  81. }
  82. /* 0x400000 = signed, 0 = unsigned */
  83. static inline int decode_signedness(unsigned int insn)
  84. {
  85. return (insn & 0x400000);
  86. }
  87. static inline void maybe_flush_windows(unsigned int rs1, unsigned int rs2,
  88. unsigned int rd, int from_kernel)
  89. {
  90. if (rs2 >= 16 || rs1 >= 16 || rd >= 16) {
  91. if (from_kernel != 0)
  92. __asm__ __volatile__("flushw");
  93. else
  94. flushw_user();
  95. }
  96. }
  97. static inline long sign_extend_imm13(long imm)
  98. {
  99. return imm << 51 >> 51;
  100. }
  101. static unsigned long fetch_reg(unsigned int reg, struct pt_regs *regs)
  102. {
  103. unsigned long value;
  104. if (reg < 16)
  105. return (!reg ? 0 : regs->u_regs[reg]);
  106. if (regs->tstate & TSTATE_PRIV) {
  107. struct reg_window *win;
  108. win = (struct reg_window *)(regs->u_regs[UREG_FP] + STACK_BIAS);
  109. value = win->locals[reg - 16];
  110. } else if (test_thread_flag(TIF_32BIT)) {
  111. struct reg_window32 __user *win32;
  112. win32 = (struct reg_window32 __user *)((unsigned long)((u32)regs->u_regs[UREG_FP]));
  113. get_user(value, &win32->locals[reg - 16]);
  114. } else {
  115. struct reg_window __user *win;
  116. win = (struct reg_window __user *)(regs->u_regs[UREG_FP] + STACK_BIAS);
  117. get_user(value, &win->locals[reg - 16]);
  118. }
  119. return value;
  120. }
  121. static unsigned long *fetch_reg_addr(unsigned int reg, struct pt_regs *regs)
  122. {
  123. if (reg < 16)
  124. return &regs->u_regs[reg];
  125. if (regs->tstate & TSTATE_PRIV) {
  126. struct reg_window *win;
  127. win = (struct reg_window *)(regs->u_regs[UREG_FP] + STACK_BIAS);
  128. return &win->locals[reg - 16];
  129. } else if (test_thread_flag(TIF_32BIT)) {
  130. struct reg_window32 *win32;
  131. win32 = (struct reg_window32 *)((unsigned long)((u32)regs->u_regs[UREG_FP]));
  132. return (unsigned long *)&win32->locals[reg - 16];
  133. } else {
  134. struct reg_window *win;
  135. win = (struct reg_window *)(regs->u_regs[UREG_FP] + STACK_BIAS);
  136. return &win->locals[reg - 16];
  137. }
  138. }
  139. unsigned long compute_effective_address(struct pt_regs *regs,
  140. unsigned int insn, unsigned int rd)
  141. {
  142. unsigned int rs1 = (insn >> 14) & 0x1f;
  143. unsigned int rs2 = insn & 0x1f;
  144. int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  145. if (insn & 0x2000) {
  146. maybe_flush_windows(rs1, 0, rd, from_kernel);
  147. return (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
  148. } else {
  149. maybe_flush_windows(rs1, rs2, rd, from_kernel);
  150. return (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
  151. }
  152. }
  153. /* This is just to make gcc think die_if_kernel does return... */
  154. static void __used unaligned_panic(char *str, struct pt_regs *regs)
  155. {
  156. die_if_kernel(str, regs);
  157. }
  158. extern int do_int_load(unsigned long *dest_reg, int size,
  159. unsigned long *saddr, int is_signed, int asi);
  160. extern int __do_int_store(unsigned long *dst_addr, int size,
  161. unsigned long src_val, int asi);
  162. static inline int do_int_store(int reg_num, int size, unsigned long *dst_addr,
  163. struct pt_regs *regs, int asi, int orig_asi)
  164. {
  165. unsigned long zero = 0;
  166. unsigned long *src_val_p = &zero;
  167. unsigned long src_val;
  168. if (size == 16) {
  169. size = 8;
  170. zero = (((long)(reg_num ?
  171. (unsigned)fetch_reg(reg_num, regs) : 0)) << 32) |
  172. (unsigned)fetch_reg(reg_num + 1, regs);
  173. } else if (reg_num) {
  174. src_val_p = fetch_reg_addr(reg_num, regs);
  175. }
  176. src_val = *src_val_p;
  177. if (unlikely(asi != orig_asi)) {
  178. switch (size) {
  179. case 2:
  180. src_val = swab16(src_val);
  181. break;
  182. case 4:
  183. src_val = swab32(src_val);
  184. break;
  185. case 8:
  186. src_val = swab64(src_val);
  187. break;
  188. case 16:
  189. default:
  190. BUG();
  191. break;
  192. }
  193. }
  194. return __do_int_store(dst_addr, size, src_val, asi);
  195. }
  196. static inline void advance(struct pt_regs *regs)
  197. {
  198. regs->tpc = regs->tnpc;
  199. regs->tnpc += 4;
  200. if (test_thread_flag(TIF_32BIT)) {
  201. regs->tpc &= 0xffffffff;
  202. regs->tnpc &= 0xffffffff;
  203. }
  204. }
  205. static inline int floating_point_load_or_store_p(unsigned int insn)
  206. {
  207. return (insn >> 24) & 1;
  208. }
  209. static inline int ok_for_kernel(unsigned int insn)
  210. {
  211. return !floating_point_load_or_store_p(insn);
  212. }
  213. static void kernel_mna_trap_fault(int fixup_tstate_asi)
  214. {
  215. struct pt_regs *regs = current_thread_info()->kern_una_regs;
  216. unsigned int insn = current_thread_info()->kern_una_insn;
  217. const struct exception_table_entry *entry;
  218. entry = search_exception_tables(regs->tpc);
  219. if (!entry) {
  220. unsigned long address;
  221. address = compute_effective_address(regs, insn,
  222. ((insn >> 25) & 0x1f));
  223. if (address < PAGE_SIZE) {
  224. printk(KERN_ALERT "Unable to handle kernel NULL "
  225. "pointer dereference in mna handler");
  226. } else
  227. printk(KERN_ALERT "Unable to handle kernel paging "
  228. "request in mna handler");
  229. printk(KERN_ALERT " at virtual address %016lx\n",address);
  230. printk(KERN_ALERT "current->{active_,}mm->context = %016lx\n",
  231. (current->mm ? CTX_HWBITS(current->mm->context) :
  232. CTX_HWBITS(current->active_mm->context)));
  233. printk(KERN_ALERT "current->{active_,}mm->pgd = %016lx\n",
  234. (current->mm ? (unsigned long) current->mm->pgd :
  235. (unsigned long) current->active_mm->pgd));
  236. die_if_kernel("Oops", regs);
  237. /* Not reached */
  238. }
  239. regs->tpc = entry->fixup;
  240. regs->tnpc = regs->tpc + 4;
  241. if (fixup_tstate_asi) {
  242. regs->tstate &= ~TSTATE_ASI;
  243. regs->tstate |= (ASI_AIUS << 24UL);
  244. }
  245. }
  246. static void log_unaligned(struct pt_regs *regs)
  247. {
  248. static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
  249. if (__ratelimit(&ratelimit)) {
  250. printk("Kernel unaligned access at TPC[%lx] %pS\n",
  251. regs->tpc, (void *) regs->tpc);
  252. }
  253. }
  254. asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
  255. {
  256. enum direction dir = decode_direction(insn);
  257. int size = decode_access_size(regs, insn);
  258. int orig_asi, asi;
  259. current_thread_info()->kern_una_regs = regs;
  260. current_thread_info()->kern_una_insn = insn;
  261. orig_asi = asi = decode_asi(insn, regs);
  262. /* If this is a {get,put}_user() on an unaligned userspace pointer,
  263. * just signal a fault and do not log the event.
  264. */
  265. if (asi == ASI_AIUS) {
  266. kernel_mna_trap_fault(0);
  267. return;
  268. }
  269. log_unaligned(regs);
  270. if (!ok_for_kernel(insn) || dir == both) {
  271. printk("Unsupported unaligned load/store trap for kernel "
  272. "at <%016lx>.\n", regs->tpc);
  273. unaligned_panic("Kernel does fpu/atomic "
  274. "unaligned load/store.", regs);
  275. kernel_mna_trap_fault(0);
  276. } else {
  277. unsigned long addr, *reg_addr;
  278. int err;
  279. addr = compute_effective_address(regs, insn,
  280. ((insn >> 25) & 0x1f));
  281. perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, 0, regs, addr);
  282. switch (asi) {
  283. case ASI_NL:
  284. case ASI_AIUPL:
  285. case ASI_AIUSL:
  286. case ASI_PL:
  287. case ASI_SL:
  288. case ASI_PNFL:
  289. case ASI_SNFL:
  290. asi &= ~0x08;
  291. break;
  292. }
  293. switch (dir) {
  294. case load:
  295. reg_addr = fetch_reg_addr(((insn>>25)&0x1f), regs);
  296. err = do_int_load(reg_addr, size,
  297. (unsigned long *) addr,
  298. decode_signedness(insn), asi);
  299. if (likely(!err) && unlikely(asi != orig_asi)) {
  300. unsigned long val_in = *reg_addr;
  301. switch (size) {
  302. case 2:
  303. val_in = swab16(val_in);
  304. break;
  305. case 4:
  306. val_in = swab32(val_in);
  307. break;
  308. case 8:
  309. val_in = swab64(val_in);
  310. break;
  311. case 16:
  312. default:
  313. BUG();
  314. break;
  315. }
  316. *reg_addr = val_in;
  317. }
  318. break;
  319. case store:
  320. err = do_int_store(((insn>>25)&0x1f), size,
  321. (unsigned long *) addr, regs,
  322. asi, orig_asi);
  323. break;
  324. default:
  325. panic("Impossible kernel unaligned trap.");
  326. /* Not reached... */
  327. }
  328. if (unlikely(err))
  329. kernel_mna_trap_fault(1);
  330. else
  331. advance(regs);
  332. }
  333. }
  334. int handle_popc(u32 insn, struct pt_regs *regs)
  335. {
  336. int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  337. int ret, rd = ((insn >> 25) & 0x1f);
  338. u64 value;
  339. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, 0, regs, 0);
  340. if (insn & 0x2000) {
  341. maybe_flush_windows(0, 0, rd, from_kernel);
  342. value = sign_extend_imm13(insn);
  343. } else {
  344. maybe_flush_windows(0, insn & 0x1f, rd, from_kernel);
  345. value = fetch_reg(insn & 0x1f, regs);
  346. }
  347. ret = hweight64(value);
  348. if (rd < 16) {
  349. if (rd)
  350. regs->u_regs[rd] = ret;
  351. } else {
  352. if (test_thread_flag(TIF_32BIT)) {
  353. struct reg_window32 __user *win32;
  354. win32 = (struct reg_window32 __user *)((unsigned long)((u32)regs->u_regs[UREG_FP]));
  355. put_user(ret, &win32->locals[rd - 16]);
  356. } else {
  357. struct reg_window __user *win;
  358. win = (struct reg_window __user *)(regs->u_regs[UREG_FP] + STACK_BIAS);
  359. put_user(ret, &win->locals[rd - 16]);
  360. }
  361. }
  362. advance(regs);
  363. return 1;
  364. }
  365. extern void do_fpother(struct pt_regs *regs);
  366. extern void do_privact(struct pt_regs *regs);
  367. extern void spitfire_data_access_exception(struct pt_regs *regs,
  368. unsigned long sfsr,
  369. unsigned long sfar);
  370. extern void sun4v_data_access_exception(struct pt_regs *regs,
  371. unsigned long addr,
  372. unsigned long type_ctx);
  373. int handle_ldf_stq(u32 insn, struct pt_regs *regs)
  374. {
  375. unsigned long addr = compute_effective_address(regs, insn, 0);
  376. int freg = ((insn >> 25) & 0x1e) | ((insn >> 20) & 0x20);
  377. struct fpustate *f = FPUSTATE;
  378. int asi = decode_asi(insn, regs);
  379. int flag = (freg < 32) ? FPRS_DL : FPRS_DU;
  380. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, 0, regs, 0);
  381. save_and_clear_fpu();
  382. current_thread_info()->xfsr[0] &= ~0x1c000;
  383. if (freg & 3) {
  384. current_thread_info()->xfsr[0] |= (6 << 14) /* invalid_fp_register */;
  385. do_fpother(regs);
  386. return 0;
  387. }
  388. if (insn & 0x200000) {
  389. /* STQ */
  390. u64 first = 0, second = 0;
  391. if (current_thread_info()->fpsaved[0] & flag) {
  392. first = *(u64 *)&f->regs[freg];
  393. second = *(u64 *)&f->regs[freg+2];
  394. }
  395. if (asi < 0x80) {
  396. do_privact(regs);
  397. return 1;
  398. }
  399. switch (asi) {
  400. case ASI_P:
  401. case ASI_S: break;
  402. case ASI_PL:
  403. case ASI_SL:
  404. {
  405. /* Need to convert endians */
  406. u64 tmp = __swab64p(&first);
  407. first = __swab64p(&second);
  408. second = tmp;
  409. break;
  410. }
  411. default:
  412. if (tlb_type == hypervisor)
  413. sun4v_data_access_exception(regs, addr, 0);
  414. else
  415. spitfire_data_access_exception(regs, 0, addr);
  416. return 1;
  417. }
  418. if (put_user (first >> 32, (u32 __user *)addr) ||
  419. __put_user ((u32)first, (u32 __user *)(addr + 4)) ||
  420. __put_user (second >> 32, (u32 __user *)(addr + 8)) ||
  421. __put_user ((u32)second, (u32 __user *)(addr + 12))) {
  422. if (tlb_type == hypervisor)
  423. sun4v_data_access_exception(regs, addr, 0);
  424. else
  425. spitfire_data_access_exception(regs, 0, addr);
  426. return 1;
  427. }
  428. } else {
  429. /* LDF, LDDF, LDQF */
  430. u32 data[4] __attribute__ ((aligned(8)));
  431. int size, i;
  432. int err;
  433. if (asi < 0x80) {
  434. do_privact(regs);
  435. return 1;
  436. } else if (asi > ASI_SNFL) {
  437. if (tlb_type == hypervisor)
  438. sun4v_data_access_exception(regs, addr, 0);
  439. else
  440. spitfire_data_access_exception(regs, 0, addr);
  441. return 1;
  442. }
  443. switch (insn & 0x180000) {
  444. case 0x000000: size = 1; break;
  445. case 0x100000: size = 4; break;
  446. default: size = 2; break;
  447. }
  448. for (i = 0; i < size; i++)
  449. data[i] = 0;
  450. err = get_user (data[0], (u32 __user *) addr);
  451. if (!err) {
  452. for (i = 1; i < size; i++)
  453. err |= __get_user (data[i], (u32 __user *)(addr + 4*i));
  454. }
  455. if (err && !(asi & 0x2 /* NF */)) {
  456. if (tlb_type == hypervisor)
  457. sun4v_data_access_exception(regs, addr, 0);
  458. else
  459. spitfire_data_access_exception(regs, 0, addr);
  460. return 1;
  461. }
  462. if (asi & 0x8) /* Little */ {
  463. u64 tmp;
  464. switch (size) {
  465. case 1: data[0] = le32_to_cpup(data + 0); break;
  466. default:*(u64 *)(data + 0) = le64_to_cpup((u64 *)(data + 0));
  467. break;
  468. case 4: tmp = le64_to_cpup((u64 *)(data + 0));
  469. *(u64 *)(data + 0) = le64_to_cpup((u64 *)(data + 2));
  470. *(u64 *)(data + 2) = tmp;
  471. break;
  472. }
  473. }
  474. if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) {
  475. current_thread_info()->fpsaved[0] = FPRS_FEF;
  476. current_thread_info()->gsr[0] = 0;
  477. }
  478. if (!(current_thread_info()->fpsaved[0] & flag)) {
  479. if (freg < 32)
  480. memset(f->regs, 0, 32*sizeof(u32));
  481. else
  482. memset(f->regs+32, 0, 32*sizeof(u32));
  483. }
  484. memcpy(f->regs + freg, data, size * 4);
  485. current_thread_info()->fpsaved[0] |= flag;
  486. }
  487. advance(regs);
  488. return 1;
  489. }
  490. void handle_ld_nf(u32 insn, struct pt_regs *regs)
  491. {
  492. int rd = ((insn >> 25) & 0x1f);
  493. int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  494. unsigned long *reg;
  495. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, 0, regs, 0);
  496. maybe_flush_windows(0, 0, rd, from_kernel);
  497. reg = fetch_reg_addr(rd, regs);
  498. if (from_kernel || rd < 16) {
  499. reg[0] = 0;
  500. if ((insn & 0x780000) == 0x180000)
  501. reg[1] = 0;
  502. } else if (test_thread_flag(TIF_32BIT)) {
  503. put_user(0, (int __user *) reg);
  504. if ((insn & 0x780000) == 0x180000)
  505. put_user(0, ((int __user *) reg) + 1);
  506. } else {
  507. put_user(0, (unsigned long __user *) reg);
  508. if ((insn & 0x780000) == 0x180000)
  509. put_user(0, (unsigned long __user *) reg + 1);
  510. }
  511. advance(regs);
  512. }
  513. void handle_lddfmna(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
  514. {
  515. unsigned long pc = regs->tpc;
  516. unsigned long tstate = regs->tstate;
  517. u32 insn;
  518. u64 value;
  519. u8 freg;
  520. int flag;
  521. struct fpustate *f = FPUSTATE;
  522. if (tstate & TSTATE_PRIV)
  523. die_if_kernel("lddfmna from kernel", regs);
  524. perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, 0, regs, sfar);
  525. if (test_thread_flag(TIF_32BIT))
  526. pc = (u32)pc;
  527. if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
  528. int asi = decode_asi(insn, regs);
  529. u32 first, second;
  530. int err;
  531. if ((asi > ASI_SNFL) ||
  532. (asi < ASI_P))
  533. goto daex;
  534. first = second = 0;
  535. err = get_user(first, (u32 __user *)sfar);
  536. if (!err)
  537. err = get_user(second, (u32 __user *)(sfar + 4));
  538. if (err) {
  539. if (!(asi & 0x2))
  540. goto daex;
  541. first = second = 0;
  542. }
  543. save_and_clear_fpu();
  544. freg = ((insn >> 25) & 0x1e) | ((insn >> 20) & 0x20);
  545. value = (((u64)first) << 32) | second;
  546. if (asi & 0x8) /* Little */
  547. value = __swab64p(&value);
  548. flag = (freg < 32) ? FPRS_DL : FPRS_DU;
  549. if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) {
  550. current_thread_info()->fpsaved[0] = FPRS_FEF;
  551. current_thread_info()->gsr[0] = 0;
  552. }
  553. if (!(current_thread_info()->fpsaved[0] & flag)) {
  554. if (freg < 32)
  555. memset(f->regs, 0, 32*sizeof(u32));
  556. else
  557. memset(f->regs+32, 0, 32*sizeof(u32));
  558. }
  559. *(u64 *)(f->regs + freg) = value;
  560. current_thread_info()->fpsaved[0] |= flag;
  561. } else {
  562. daex:
  563. if (tlb_type == hypervisor)
  564. sun4v_data_access_exception(regs, sfar, sfsr);
  565. else
  566. spitfire_data_access_exception(regs, sfsr, sfar);
  567. return;
  568. }
  569. advance(regs);
  570. }
  571. void handle_stdfmna(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
  572. {
  573. unsigned long pc = regs->tpc;
  574. unsigned long tstate = regs->tstate;
  575. u32 insn;
  576. u64 value;
  577. u8 freg;
  578. int flag;
  579. struct fpustate *f = FPUSTATE;
  580. if (tstate & TSTATE_PRIV)
  581. die_if_kernel("stdfmna from kernel", regs);
  582. perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, 0, regs, sfar);
  583. if (test_thread_flag(TIF_32BIT))
  584. pc = (u32)pc;
  585. if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
  586. int asi = decode_asi(insn, regs);
  587. freg = ((insn >> 25) & 0x1e) | ((insn >> 20) & 0x20);
  588. value = 0;
  589. flag = (freg < 32) ? FPRS_DL : FPRS_DU;
  590. if ((asi > ASI_SNFL) ||
  591. (asi < ASI_P))
  592. goto daex;
  593. save_and_clear_fpu();
  594. if (current_thread_info()->fpsaved[0] & flag)
  595. value = *(u64 *)&f->regs[freg];
  596. switch (asi) {
  597. case ASI_P:
  598. case ASI_S: break;
  599. case ASI_PL:
  600. case ASI_SL:
  601. value = __swab64p(&value); break;
  602. default: goto daex;
  603. }
  604. if (put_user (value >> 32, (u32 __user *) sfar) ||
  605. __put_user ((u32)value, (u32 __user *)(sfar + 4)))
  606. goto daex;
  607. } else {
  608. daex:
  609. if (tlb_type == hypervisor)
  610. sun4v_data_access_exception(regs, sfar, sfsr);
  611. else
  612. spitfire_data_access_exception(regs, sfsr, sfar);
  613. return;
  614. }
  615. advance(regs);
  616. }