rtrap.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /*
  2. * rtrap.S: Preparing for return from trap on Sparc V9.
  3. *
  4. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  5. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  6. */
  7. #include <asm/asi.h>
  8. #include <asm/pstate.h>
  9. #include <asm/ptrace.h>
  10. #include <asm/spitfire.h>
  11. #include <asm/head.h>
  12. #include <asm/visasm.h>
  13. #include <asm/processor.h>
  14. #define RTRAP_PSTATE (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_IE)
  15. #define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV)
  16. #define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG)
  17. .text
  18. .align 32
  19. __handle_softirq:
  20. call do_softirq
  21. nop
  22. ba,a,pt %xcc, __handle_softirq_continue
  23. nop
  24. __handle_preemption:
  25. call schedule
  26. wrpr %g0, RTRAP_PSTATE, %pstate
  27. ba,pt %xcc, __handle_preemption_continue
  28. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  29. __handle_user_windows:
  30. call fault_in_user_windows
  31. wrpr %g0, RTRAP_PSTATE, %pstate
  32. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  33. /* Redo sched+sig checks */
  34. ldx [%g6 + TI_FLAGS], %l0
  35. andcc %l0, _TIF_NEED_RESCHED, %g0
  36. be,pt %xcc, 1f
  37. nop
  38. call schedule
  39. wrpr %g0, RTRAP_PSTATE, %pstate
  40. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  41. ldx [%g6 + TI_FLAGS], %l0
  42. 1: andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
  43. be,pt %xcc, __handle_user_windows_continue
  44. nop
  45. mov %l5, %o1
  46. add %sp, PTREGS_OFF, %o0
  47. mov %l0, %o2
  48. call do_notify_resume
  49. wrpr %g0, RTRAP_PSTATE, %pstate
  50. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  51. /* Signal delivery can modify pt_regs tstate, so we must
  52. * reload it.
  53. */
  54. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  55. sethi %hi(0xf << 20), %l4
  56. and %l1, %l4, %l4
  57. ba,pt %xcc, __handle_user_windows_continue
  58. andn %l1, %l4, %l1
  59. __handle_perfctrs:
  60. call update_perfctrs
  61. wrpr %g0, RTRAP_PSTATE, %pstate
  62. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  63. ldub [%g6 + TI_WSAVED], %o2
  64. brz,pt %o2, 1f
  65. nop
  66. /* Redo userwin+sched+sig checks */
  67. call fault_in_user_windows
  68. wrpr %g0, RTRAP_PSTATE, %pstate
  69. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  70. ldx [%g6 + TI_FLAGS], %l0
  71. andcc %l0, _TIF_NEED_RESCHED, %g0
  72. be,pt %xcc, 1f
  73. nop
  74. call schedule
  75. wrpr %g0, RTRAP_PSTATE, %pstate
  76. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  77. ldx [%g6 + TI_FLAGS], %l0
  78. 1: andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
  79. be,pt %xcc, __handle_perfctrs_continue
  80. sethi %hi(TSTATE_PEF), %o0
  81. mov %l5, %o1
  82. add %sp, PTREGS_OFF, %o0
  83. mov %l0, %o2
  84. call do_notify_resume
  85. wrpr %g0, RTRAP_PSTATE, %pstate
  86. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  87. /* Signal delivery can modify pt_regs tstate, so we must
  88. * reload it.
  89. */
  90. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  91. sethi %hi(0xf << 20), %l4
  92. and %l1, %l4, %l4
  93. andn %l1, %l4, %l1
  94. ba,pt %xcc, __handle_perfctrs_continue
  95. sethi %hi(TSTATE_PEF), %o0
  96. __handle_userfpu:
  97. rd %fprs, %l5
  98. andcc %l5, FPRS_FEF, %g0
  99. sethi %hi(TSTATE_PEF), %o0
  100. be,a,pn %icc, __handle_userfpu_continue
  101. andn %l1, %o0, %l1
  102. ba,a,pt %xcc, __handle_userfpu_continue
  103. __handle_signal:
  104. mov %l5, %o1
  105. add %sp, PTREGS_OFF, %o0
  106. mov %l0, %o2
  107. call do_notify_resume
  108. wrpr %g0, RTRAP_PSTATE, %pstate
  109. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  110. /* Signal delivery can modify pt_regs tstate, so we must
  111. * reload it.
  112. */
  113. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  114. sethi %hi(0xf << 20), %l4
  115. and %l1, %l4, %l4
  116. ba,pt %xcc, __handle_signal_continue
  117. andn %l1, %l4, %l1
  118. .align 64
  119. .globl rtrap_irq, rtrap, irqsz_patchme, rtrap_xcall
  120. rtrap_irq:
  121. rtrap:
  122. #ifndef CONFIG_SMP
  123. sethi %hi(per_cpu____cpu_data), %l0
  124. lduw [%l0 + %lo(per_cpu____cpu_data)], %l1
  125. #else
  126. sethi %hi(per_cpu____cpu_data), %l0
  127. or %l0, %lo(per_cpu____cpu_data), %l0
  128. lduw [%l0 + %g5], %l1
  129. #endif
  130. cmp %l1, 0
  131. /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
  132. bne,pn %icc, __handle_softirq
  133. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  134. __handle_softirq_continue:
  135. rtrap_xcall:
  136. sethi %hi(0xf << 20), %l4
  137. and %l1, %l4, %l4
  138. andn %l1, %l4, %l1
  139. srl %l4, 20, %l4
  140. #ifdef CONFIG_TRACE_IRQFLAGS
  141. brnz,pn %l4, rtrap_no_irq_enable
  142. nop
  143. call trace_hardirqs_on
  144. nop
  145. wrpr %l4, %pil
  146. rtrap_no_irq_enable:
  147. #endif
  148. andcc %l1, TSTATE_PRIV, %l3
  149. bne,pn %icc, to_kernel
  150. nop
  151. /* We must hold IRQs off and atomically test schedule+signal
  152. * state, then hold them off all the way back to userspace.
  153. * If we are returning to kernel, none of this matters. Note
  154. * that we are disabling interrupts via PSTATE_IE, not using
  155. * %pil.
  156. *
  157. * If we do not do this, there is a window where we would do
  158. * the tests, later the signal/resched event arrives but we do
  159. * not process it since we are still in kernel mode. It would
  160. * take until the next local IRQ before the signal/resched
  161. * event would be handled.
  162. *
  163. * This also means that if we have to deal with performance
  164. * counters or user windows, we have to redo all of these
  165. * sched+signal checks with IRQs disabled.
  166. */
  167. to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  168. wrpr 0, %pil
  169. __handle_preemption_continue:
  170. ldx [%g6 + TI_FLAGS], %l0
  171. sethi %hi(_TIF_USER_WORK_MASK), %o0
  172. or %o0, %lo(_TIF_USER_WORK_MASK), %o0
  173. andcc %l0, %o0, %g0
  174. sethi %hi(TSTATE_PEF), %o0
  175. be,pt %xcc, user_nowork
  176. andcc %l1, %o0, %g0
  177. andcc %l0, _TIF_NEED_RESCHED, %g0
  178. bne,pn %xcc, __handle_preemption
  179. andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
  180. bne,pn %xcc, __handle_signal
  181. __handle_signal_continue:
  182. ldub [%g6 + TI_WSAVED], %o2
  183. brnz,pn %o2, __handle_user_windows
  184. nop
  185. __handle_user_windows_continue:
  186. ldx [%g6 + TI_FLAGS], %l5
  187. andcc %l5, _TIF_PERFCTR, %g0
  188. sethi %hi(TSTATE_PEF), %o0
  189. bne,pn %xcc, __handle_perfctrs
  190. __handle_perfctrs_continue:
  191. andcc %l1, %o0, %g0
  192. /* This fpdepth clear is necessary for non-syscall rtraps only */
  193. user_nowork:
  194. bne,pn %xcc, __handle_userfpu
  195. stb %g0, [%g6 + TI_FPDEPTH]
  196. __handle_userfpu_continue:
  197. rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
  198. ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
  199. ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
  200. ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
  201. ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
  202. brz,pt %l3, 1f
  203. mov %g6, %l2
  204. /* Must do this before thread reg is clobbered below. */
  205. LOAD_PER_CPU_BASE(%g5, %g6, %i0, %i1, %i2)
  206. 1:
  207. ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
  208. ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
  209. /* Normal globals are restored, go to trap globals. */
  210. 661: wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
  211. nop
  212. .section .sun4v_2insn_patch, "ax"
  213. .word 661b
  214. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  215. SET_GL(1)
  216. .previous
  217. mov %l2, %g6
  218. ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
  219. ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
  220. ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
  221. ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
  222. ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
  223. ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
  224. ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
  225. ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
  226. ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
  227. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
  228. ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
  229. wr %o3, %g0, %y
  230. wrpr %l4, 0x0, %pil
  231. wrpr %g0, 0x1, %tl
  232. andn %l1, TSTATE_SYSCALL, %l1
  233. wrpr %l1, %g0, %tstate
  234. wrpr %l2, %g0, %tpc
  235. wrpr %o2, %g0, %tnpc
  236. brnz,pn %l3, kern_rtt
  237. mov PRIMARY_CONTEXT, %l7
  238. 661: ldxa [%l7 + %l7] ASI_DMMU, %l0
  239. .section .sun4v_1insn_patch, "ax"
  240. .word 661b
  241. ldxa [%l7 + %l7] ASI_MMU, %l0
  242. .previous
  243. sethi %hi(sparc64_kern_pri_nuc_bits), %l1
  244. ldx [%l1 + %lo(sparc64_kern_pri_nuc_bits)], %l1
  245. or %l0, %l1, %l0
  246. 661: stxa %l0, [%l7] ASI_DMMU
  247. .section .sun4v_1insn_patch, "ax"
  248. .word 661b
  249. stxa %l0, [%l7] ASI_MMU
  250. .previous
  251. sethi %hi(KERNBASE), %l7
  252. flush %l7
  253. rdpr %wstate, %l1
  254. rdpr %otherwin, %l2
  255. srl %l1, 3, %l1
  256. wrpr %l2, %g0, %canrestore
  257. wrpr %l1, %g0, %wstate
  258. brnz,pt %l2, user_rtt_restore
  259. wrpr %g0, %g0, %otherwin
  260. ldx [%g6 + TI_FLAGS], %g3
  261. wr %g0, ASI_AIUP, %asi
  262. rdpr %cwp, %g1
  263. andcc %g3, _TIF_32BIT, %g0
  264. sub %g1, 1, %g1
  265. bne,pt %xcc, user_rtt_fill_32bit
  266. wrpr %g1, %cwp
  267. ba,a,pt %xcc, user_rtt_fill_64bit
  268. user_rtt_fill_fixup:
  269. rdpr %cwp, %g1
  270. add %g1, 1, %g1
  271. wrpr %g1, 0x0, %cwp
  272. rdpr %wstate, %g2
  273. sll %g2, 3, %g2
  274. wrpr %g2, 0x0, %wstate
  275. /* We know %canrestore and %otherwin are both zero. */
  276. sethi %hi(sparc64_kern_pri_context), %g2
  277. ldx [%g2 + %lo(sparc64_kern_pri_context)], %g2
  278. mov PRIMARY_CONTEXT, %g1
  279. 661: stxa %g2, [%g1] ASI_DMMU
  280. .section .sun4v_1insn_patch, "ax"
  281. .word 661b
  282. stxa %g2, [%g1] ASI_MMU
  283. .previous
  284. sethi %hi(KERNBASE), %g1
  285. flush %g1
  286. or %g4, FAULT_CODE_WINFIXUP, %g4
  287. stb %g4, [%g6 + TI_FAULT_CODE]
  288. stx %g5, [%g6 + TI_FAULT_ADDR]
  289. mov %g6, %l1
  290. wrpr %g0, 0x0, %tl
  291. 661: nop
  292. .section .sun4v_1insn_patch, "ax"
  293. .word 661b
  294. SET_GL(0)
  295. .previous
  296. wrpr %g0, RTRAP_PSTATE, %pstate
  297. mov %l1, %g6
  298. ldx [%g6 + TI_TASK], %g4
  299. LOAD_PER_CPU_BASE(%g5, %g6, %g1, %g2, %g3)
  300. call do_sparc64_fault
  301. add %sp, PTREGS_OFF, %o0
  302. ba,pt %xcc, rtrap
  303. nop
  304. user_rtt_pre_restore:
  305. add %g1, 1, %g1
  306. wrpr %g1, 0x0, %cwp
  307. user_rtt_restore:
  308. restore
  309. rdpr %canrestore, %g1
  310. wrpr %g1, 0x0, %cleanwin
  311. retry
  312. nop
  313. kern_rtt: rdpr %canrestore, %g1
  314. brz,pn %g1, kern_rtt_fill
  315. nop
  316. kern_rtt_restore:
  317. stw %g0, [%sp + PTREGS_OFF + PT_V9_MAGIC]
  318. restore
  319. retry
  320. to_kernel:
  321. #ifdef CONFIG_PREEMPT
  322. ldsw [%g6 + TI_PRE_COUNT], %l5
  323. brnz %l5, kern_fpucheck
  324. ldx [%g6 + TI_FLAGS], %l5
  325. andcc %l5, _TIF_NEED_RESCHED, %g0
  326. be,pt %xcc, kern_fpucheck
  327. nop
  328. cmp %l4, 0
  329. bne,pn %xcc, kern_fpucheck
  330. sethi %hi(PREEMPT_ACTIVE), %l6
  331. stw %l6, [%g6 + TI_PRE_COUNT]
  332. call schedule
  333. nop
  334. ba,pt %xcc, rtrap
  335. stw %g0, [%g6 + TI_PRE_COUNT]
  336. #endif
  337. kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
  338. brz,pt %l5, rt_continue
  339. srl %l5, 1, %o0
  340. add %g6, TI_FPSAVED, %l6
  341. ldub [%l6 + %o0], %l2
  342. sub %l5, 2, %l5
  343. add %g6, TI_GSR, %o1
  344. andcc %l2, (FPRS_FEF|FPRS_DU), %g0
  345. be,pt %icc, 2f
  346. and %l2, FPRS_DL, %l6
  347. andcc %l2, FPRS_FEF, %g0
  348. be,pn %icc, 5f
  349. sll %o0, 3, %o5
  350. rd %fprs, %g1
  351. wr %g1, FPRS_FEF, %fprs
  352. ldx [%o1 + %o5], %g1
  353. add %g6, TI_XFSR, %o1
  354. sll %o0, 8, %o2
  355. add %g6, TI_FPREGS, %o3
  356. brz,pn %l6, 1f
  357. add %g6, TI_FPREGS+0x40, %o4
  358. membar #Sync
  359. ldda [%o3 + %o2] ASI_BLK_P, %f0
  360. ldda [%o4 + %o2] ASI_BLK_P, %f16
  361. membar #Sync
  362. 1: andcc %l2, FPRS_DU, %g0
  363. be,pn %icc, 1f
  364. wr %g1, 0, %gsr
  365. add %o2, 0x80, %o2
  366. membar #Sync
  367. ldda [%o3 + %o2] ASI_BLK_P, %f32
  368. ldda [%o4 + %o2] ASI_BLK_P, %f48
  369. 1: membar #Sync
  370. ldx [%o1 + %o5], %fsr
  371. 2: stb %l5, [%g6 + TI_FPDEPTH]
  372. ba,pt %xcc, rt_continue
  373. nop
  374. 5: wr %g0, FPRS_FEF, %fprs
  375. sll %o0, 8, %o2
  376. add %g6, TI_FPREGS+0x80, %o3
  377. add %g6, TI_FPREGS+0xc0, %o4
  378. membar #Sync
  379. ldda [%o3 + %o2] ASI_BLK_P, %f32
  380. ldda [%o4 + %o2] ASI_BLK_P, %f48
  381. membar #Sync
  382. wr %g0, FPRS_DU, %fprs
  383. ba,pt %xcc, rt_continue
  384. stb %l5, [%g6 + TI_FPDEPTH]