unaligned_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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/uaccess.h>
  18. #include <linux/smp.h>
  19. #include <linux/bitops.h>
  20. #include <linux/perf_event.h>
  21. #include <linux/ratelimit.h>
  22. #include <linux/bitops.h>
  23. #include <asm/fpumacro.h>
  24. #include <asm/cacheflush.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. int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  143. unsigned int rs1 = (insn >> 14) & 0x1f;
  144. unsigned int rs2 = insn & 0x1f;
  145. unsigned long addr;
  146. if (insn & 0x2000) {
  147. maybe_flush_windows(rs1, 0, rd, from_kernel);
  148. addr = (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
  149. } else {
  150. maybe_flush_windows(rs1, rs2, rd, from_kernel);
  151. addr = (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
  152. }
  153. if (!from_kernel && test_thread_flag(TIF_32BIT))
  154. addr &= 0xffffffff;
  155. return addr;
  156. }
  157. /* This is just to make gcc think die_if_kernel does return... */
  158. static void __used unaligned_panic(char *str, struct pt_regs *regs)
  159. {
  160. die_if_kernel(str, regs);
  161. }
  162. extern int do_int_load(unsigned long *dest_reg, int size,
  163. unsigned long *saddr, int is_signed, int asi);
  164. extern int __do_int_store(unsigned long *dst_addr, int size,
  165. unsigned long src_val, int asi);
  166. static inline int do_int_store(int reg_num, int size, unsigned long *dst_addr,
  167. struct pt_regs *regs, int asi, int orig_asi)
  168. {
  169. unsigned long zero = 0;
  170. unsigned long *src_val_p = &zero;
  171. unsigned long src_val;
  172. if (size == 16) {
  173. size = 8;
  174. zero = (((long)(reg_num ?
  175. (unsigned)fetch_reg(reg_num, regs) : 0)) << 32) |
  176. (unsigned)fetch_reg(reg_num + 1, regs);
  177. } else if (reg_num) {
  178. src_val_p = fetch_reg_addr(reg_num, regs);
  179. }
  180. src_val = *src_val_p;
  181. if (unlikely(asi != orig_asi)) {
  182. switch (size) {
  183. case 2:
  184. src_val = swab16(src_val);
  185. break;
  186. case 4:
  187. src_val = swab32(src_val);
  188. break;
  189. case 8:
  190. src_val = swab64(src_val);
  191. break;
  192. case 16:
  193. default:
  194. BUG();
  195. break;
  196. }
  197. }
  198. return __do_int_store(dst_addr, size, src_val, asi);
  199. }
  200. static inline void advance(struct pt_regs *regs)
  201. {
  202. regs->tpc = regs->tnpc;
  203. regs->tnpc += 4;
  204. if (test_thread_flag(TIF_32BIT)) {
  205. regs->tpc &= 0xffffffff;
  206. regs->tnpc &= 0xffffffff;
  207. }
  208. }
  209. static inline int floating_point_load_or_store_p(unsigned int insn)
  210. {
  211. return (insn >> 24) & 1;
  212. }
  213. static inline int ok_for_kernel(unsigned int insn)
  214. {
  215. return !floating_point_load_or_store_p(insn);
  216. }
  217. static void kernel_mna_trap_fault(int fixup_tstate_asi)
  218. {
  219. struct pt_regs *regs = current_thread_info()->kern_una_regs;
  220. unsigned int insn = current_thread_info()->kern_una_insn;
  221. const struct exception_table_entry *entry;
  222. entry = search_exception_tables(regs->tpc);
  223. if (!entry) {
  224. unsigned long address;
  225. address = compute_effective_address(regs, insn,
  226. ((insn >> 25) & 0x1f));
  227. if (address < PAGE_SIZE) {
  228. printk(KERN_ALERT "Unable to handle kernel NULL "
  229. "pointer dereference in mna handler");
  230. } else
  231. printk(KERN_ALERT "Unable to handle kernel paging "
  232. "request in mna handler");
  233. printk(KERN_ALERT " at virtual address %016lx\n",address);
  234. printk(KERN_ALERT "current->{active_,}mm->context = %016lx\n",
  235. (current->mm ? CTX_HWBITS(current->mm->context) :
  236. CTX_HWBITS(current->active_mm->context)));
  237. printk(KERN_ALERT "current->{active_,}mm->pgd = %016lx\n",
  238. (current->mm ? (unsigned long) current->mm->pgd :
  239. (unsigned long) current->active_mm->pgd));
  240. die_if_kernel("Oops", regs);
  241. /* Not reached */
  242. }
  243. regs->tpc = entry->fixup;
  244. regs->tnpc = regs->tpc + 4;
  245. if (fixup_tstate_asi) {
  246. regs->tstate &= ~TSTATE_ASI;
  247. regs->tstate |= (ASI_AIUS << 24UL);
  248. }
  249. }
  250. static void log_unaligned(struct pt_regs *regs)
  251. {
  252. static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
  253. if (__ratelimit(&ratelimit)) {
  254. printk("Kernel unaligned access at TPC[%lx] %pS\n",
  255. regs->tpc, (void *) regs->tpc);
  256. }
  257. }
  258. asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
  259. {
  260. enum direction dir = decode_direction(insn);
  261. int size = decode_access_size(regs, insn);
  262. int orig_asi, asi;
  263. current_thread_info()->kern_una_regs = regs;
  264. current_thread_info()->kern_una_insn = insn;
  265. orig_asi = asi = decode_asi(insn, regs);
  266. /* If this is a {get,put}_user() on an unaligned userspace pointer,
  267. * just signal a fault and do not log the event.
  268. */
  269. if (asi == ASI_AIUS) {
  270. kernel_mna_trap_fault(0);
  271. return;
  272. }
  273. log_unaligned(regs);
  274. if (!ok_for_kernel(insn) || dir == both) {
  275. printk("Unsupported unaligned load/store trap for kernel "
  276. "at <%016lx>.\n", regs->tpc);
  277. unaligned_panic("Kernel does fpu/atomic "
  278. "unaligned load/store.", regs);
  279. kernel_mna_trap_fault(0);
  280. } else {
  281. unsigned long addr, *reg_addr;
  282. int err;
  283. addr = compute_effective_address(regs, insn,
  284. ((insn >> 25) & 0x1f));
  285. perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, addr);
  286. switch (asi) {
  287. case ASI_NL:
  288. case ASI_AIUPL:
  289. case ASI_AIUSL:
  290. case ASI_PL:
  291. case ASI_SL:
  292. case ASI_PNFL:
  293. case ASI_SNFL:
  294. asi &= ~0x08;
  295. break;
  296. }
  297. switch (dir) {
  298. case load:
  299. reg_addr = fetch_reg_addr(((insn>>25)&0x1f), regs);
  300. err = do_int_load(reg_addr, size,
  301. (unsigned long *) addr,
  302. decode_signedness(insn), asi);
  303. if (likely(!err) && unlikely(asi != orig_asi)) {
  304. unsigned long val_in = *reg_addr;
  305. switch (size) {
  306. case 2:
  307. val_in = swab16(val_in);
  308. break;
  309. case 4:
  310. val_in = swab32(val_in);
  311. break;
  312. case 8:
  313. val_in = swab64(val_in);
  314. break;
  315. case 16:
  316. default:
  317. BUG();
  318. break;
  319. }
  320. *reg_addr = val_in;
  321. }
  322. break;
  323. case store:
  324. err = do_int_store(((insn>>25)&0x1f), size,
  325. (unsigned long *) addr, regs,
  326. asi, orig_asi);
  327. break;
  328. default:
  329. panic("Impossible kernel unaligned trap.");
  330. /* Not reached... */
  331. }
  332. if (unlikely(err))
  333. kernel_mna_trap_fault(1);
  334. else
  335. advance(regs);
  336. }
  337. }
  338. int handle_popc(u32 insn, struct pt_regs *regs)
  339. {
  340. int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  341. int ret, rd = ((insn >> 25) & 0x1f);
  342. u64 value;
  343. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
  344. if (insn & 0x2000) {
  345. maybe_flush_windows(0, 0, rd, from_kernel);
  346. value = sign_extend_imm13(insn);
  347. } else {
  348. maybe_flush_windows(0, insn & 0x1f, rd, from_kernel);
  349. value = fetch_reg(insn & 0x1f, regs);
  350. }
  351. ret = hweight64(value);
  352. if (rd < 16) {
  353. if (rd)
  354. regs->u_regs[rd] = ret;
  355. } else {
  356. if (test_thread_flag(TIF_32BIT)) {
  357. struct reg_window32 __user *win32;
  358. win32 = (struct reg_window32 __user *)((unsigned long)((u32)regs->u_regs[UREG_FP]));
  359. put_user(ret, &win32->locals[rd - 16]);
  360. } else {
  361. struct reg_window __user *win;
  362. win = (struct reg_window __user *)(regs->u_regs[UREG_FP] + STACK_BIAS);
  363. put_user(ret, &win->locals[rd - 16]);
  364. }
  365. }
  366. advance(regs);
  367. return 1;
  368. }
  369. extern void do_fpother(struct pt_regs *regs);
  370. extern void do_privact(struct pt_regs *regs);
  371. extern void spitfire_data_access_exception(struct pt_regs *regs,
  372. unsigned long sfsr,
  373. unsigned long sfar);
  374. extern void sun4v_data_access_exception(struct pt_regs *regs,
  375. unsigned long addr,
  376. unsigned long type_ctx);
  377. int handle_ldf_stq(u32 insn, struct pt_regs *regs)
  378. {
  379. unsigned long addr = compute_effective_address(regs, insn, 0);
  380. int freg = ((insn >> 25) & 0x1e) | ((insn >> 20) & 0x20);
  381. struct fpustate *f = FPUSTATE;
  382. int asi = decode_asi(insn, regs);
  383. int flag = (freg < 32) ? FPRS_DL : FPRS_DU;
  384. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
  385. save_and_clear_fpu();
  386. current_thread_info()->xfsr[0] &= ~0x1c000;
  387. if (freg & 3) {
  388. current_thread_info()->xfsr[0] |= (6 << 14) /* invalid_fp_register */;
  389. do_fpother(regs);
  390. return 0;
  391. }
  392. if (insn & 0x200000) {
  393. /* STQ */
  394. u64 first = 0, second = 0;
  395. if (current_thread_info()->fpsaved[0] & flag) {
  396. first = *(u64 *)&f->regs[freg];
  397. second = *(u64 *)&f->regs[freg+2];
  398. }
  399. if (asi < 0x80) {
  400. do_privact(regs);
  401. return 1;
  402. }
  403. switch (asi) {
  404. case ASI_P:
  405. case ASI_S: break;
  406. case ASI_PL:
  407. case ASI_SL:
  408. {
  409. /* Need to convert endians */
  410. u64 tmp = __swab64p(&first);
  411. first = __swab64p(&second);
  412. second = tmp;
  413. break;
  414. }
  415. default:
  416. if (tlb_type == hypervisor)
  417. sun4v_data_access_exception(regs, addr, 0);
  418. else
  419. spitfire_data_access_exception(regs, 0, addr);
  420. return 1;
  421. }
  422. if (put_user (first >> 32, (u32 __user *)addr) ||
  423. __put_user ((u32)first, (u32 __user *)(addr + 4)) ||
  424. __put_user (second >> 32, (u32 __user *)(addr + 8)) ||
  425. __put_user ((u32)second, (u32 __user *)(addr + 12))) {
  426. if (tlb_type == hypervisor)
  427. sun4v_data_access_exception(regs, addr, 0);
  428. else
  429. spitfire_data_access_exception(regs, 0, addr);
  430. return 1;
  431. }
  432. } else {
  433. /* LDF, LDDF, LDQF */
  434. u32 data[4] __attribute__ ((aligned(8)));
  435. int size, i;
  436. int err;
  437. if (asi < 0x80) {
  438. do_privact(regs);
  439. return 1;
  440. } else if (asi > ASI_SNFL) {
  441. if (tlb_type == hypervisor)
  442. sun4v_data_access_exception(regs, addr, 0);
  443. else
  444. spitfire_data_access_exception(regs, 0, addr);
  445. return 1;
  446. }
  447. switch (insn & 0x180000) {
  448. case 0x000000: size = 1; break;
  449. case 0x100000: size = 4; break;
  450. default: size = 2; break;
  451. }
  452. for (i = 0; i < size; i++)
  453. data[i] = 0;
  454. err = get_user (data[0], (u32 __user *) addr);
  455. if (!err) {
  456. for (i = 1; i < size; i++)
  457. err |= __get_user (data[i], (u32 __user *)(addr + 4*i));
  458. }
  459. if (err && !(asi & 0x2 /* NF */)) {
  460. if (tlb_type == hypervisor)
  461. sun4v_data_access_exception(regs, addr, 0);
  462. else
  463. spitfire_data_access_exception(regs, 0, addr);
  464. return 1;
  465. }
  466. if (asi & 0x8) /* Little */ {
  467. u64 tmp;
  468. switch (size) {
  469. case 1: data[0] = le32_to_cpup(data + 0); break;
  470. default:*(u64 *)(data + 0) = le64_to_cpup((u64 *)(data + 0));
  471. break;
  472. case 4: tmp = le64_to_cpup((u64 *)(data + 0));
  473. *(u64 *)(data + 0) = le64_to_cpup((u64 *)(data + 2));
  474. *(u64 *)(data + 2) = tmp;
  475. break;
  476. }
  477. }
  478. if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) {
  479. current_thread_info()->fpsaved[0] = FPRS_FEF;
  480. current_thread_info()->gsr[0] = 0;
  481. }
  482. if (!(current_thread_info()->fpsaved[0] & flag)) {
  483. if (freg < 32)
  484. memset(f->regs, 0, 32*sizeof(u32));
  485. else
  486. memset(f->regs+32, 0, 32*sizeof(u32));
  487. }
  488. memcpy(f->regs + freg, data, size * 4);
  489. current_thread_info()->fpsaved[0] |= flag;
  490. }
  491. advance(regs);
  492. return 1;
  493. }
  494. void handle_ld_nf(u32 insn, struct pt_regs *regs)
  495. {
  496. int rd = ((insn >> 25) & 0x1f);
  497. int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
  498. unsigned long *reg;
  499. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
  500. maybe_flush_windows(0, 0, rd, from_kernel);
  501. reg = fetch_reg_addr(rd, regs);
  502. if (from_kernel || rd < 16) {
  503. reg[0] = 0;
  504. if ((insn & 0x780000) == 0x180000)
  505. reg[1] = 0;
  506. } else if (test_thread_flag(TIF_32BIT)) {
  507. put_user(0, (int __user *) reg);
  508. if ((insn & 0x780000) == 0x180000)
  509. put_user(0, ((int __user *) reg) + 1);
  510. } else {
  511. put_user(0, (unsigned long __user *) reg);
  512. if ((insn & 0x780000) == 0x180000)
  513. put_user(0, (unsigned long __user *) reg + 1);
  514. }
  515. advance(regs);
  516. }
  517. void handle_lddfmna(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
  518. {
  519. unsigned long pc = regs->tpc;
  520. unsigned long tstate = regs->tstate;
  521. u32 insn;
  522. u64 value;
  523. u8 freg;
  524. int flag;
  525. struct fpustate *f = FPUSTATE;
  526. if (tstate & TSTATE_PRIV)
  527. die_if_kernel("lddfmna from kernel", regs);
  528. perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, sfar);
  529. if (test_thread_flag(TIF_32BIT))
  530. pc = (u32)pc;
  531. if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
  532. int asi = decode_asi(insn, regs);
  533. u32 first, second;
  534. int err;
  535. if ((asi > ASI_SNFL) ||
  536. (asi < ASI_P))
  537. goto daex;
  538. first = second = 0;
  539. err = get_user(first, (u32 __user *)sfar);
  540. if (!err)
  541. err = get_user(second, (u32 __user *)(sfar + 4));
  542. if (err) {
  543. if (!(asi & 0x2))
  544. goto daex;
  545. first = second = 0;
  546. }
  547. save_and_clear_fpu();
  548. freg = ((insn >> 25) & 0x1e) | ((insn >> 20) & 0x20);
  549. value = (((u64)first) << 32) | second;
  550. if (asi & 0x8) /* Little */
  551. value = __swab64p(&value);
  552. flag = (freg < 32) ? FPRS_DL : FPRS_DU;
  553. if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) {
  554. current_thread_info()->fpsaved[0] = FPRS_FEF;
  555. current_thread_info()->gsr[0] = 0;
  556. }
  557. if (!(current_thread_info()->fpsaved[0] & flag)) {
  558. if (freg < 32)
  559. memset(f->regs, 0, 32*sizeof(u32));
  560. else
  561. memset(f->regs+32, 0, 32*sizeof(u32));
  562. }
  563. *(u64 *)(f->regs + freg) = value;
  564. current_thread_info()->fpsaved[0] |= flag;
  565. } else {
  566. daex:
  567. if (tlb_type == hypervisor)
  568. sun4v_data_access_exception(regs, sfar, sfsr);
  569. else
  570. spitfire_data_access_exception(regs, sfsr, sfar);
  571. return;
  572. }
  573. advance(regs);
  574. }
  575. void handle_stdfmna(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
  576. {
  577. unsigned long pc = regs->tpc;
  578. unsigned long tstate = regs->tstate;
  579. u32 insn;
  580. u64 value;
  581. u8 freg;
  582. int flag;
  583. struct fpustate *f = FPUSTATE;
  584. if (tstate & TSTATE_PRIV)
  585. die_if_kernel("stdfmna from kernel", regs);
  586. perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, sfar);
  587. if (test_thread_flag(TIF_32BIT))
  588. pc = (u32)pc;
  589. if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
  590. int asi = decode_asi(insn, regs);
  591. freg = ((insn >> 25) & 0x1e) | ((insn >> 20) & 0x20);
  592. value = 0;
  593. flag = (freg < 32) ? FPRS_DL : FPRS_DU;
  594. if ((asi > ASI_SNFL) ||
  595. (asi < ASI_P))
  596. goto daex;
  597. save_and_clear_fpu();
  598. if (current_thread_info()->fpsaved[0] & flag)
  599. value = *(u64 *)&f->regs[freg];
  600. switch (asi) {
  601. case ASI_P:
  602. case ASI_S: break;
  603. case ASI_PL:
  604. case ASI_SL:
  605. value = __swab64p(&value); break;
  606. default: goto daex;
  607. }
  608. if (put_user (value >> 32, (u32 __user *) sfar) ||
  609. __put_user ((u32)value, (u32 __user *)(sfar + 4)))
  610. goto daex;
  611. } else {
  612. daex:
  613. if (tlb_type == hypervisor)
  614. sun4v_data_access_exception(regs, sfar, sfsr);
  615. else
  616. spitfire_data_access_exception(regs, sfsr, sfar);
  617. return;
  618. }
  619. advance(regs);
  620. }