rtrap_64.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * rtrap.S: Preparing for return from trap on Sparc V9.
  4. *
  5. * Copyright (C) 1997,1998 Jakub Jelinek ([email protected])
  6. * Copyright (C) 1997 David S. Miller ([email protected])
  7. */
  8. #include <asm/asi.h>
  9. #include <asm/pstate.h>
  10. #include <asm/ptrace.h>
  11. #include <asm/spitfire.h>
  12. #include <asm/head.h>
  13. #include <asm/visasm.h>
  14. #include <asm/processor.h>
  15. #ifdef CONFIG_CONTEXT_TRACKING_USER
  16. # define SCHEDULE_USER schedule_user
  17. #else
  18. # define SCHEDULE_USER schedule
  19. #endif
  20. .text
  21. .align 32
  22. __handle_preemption:
  23. call SCHEDULE_USER
  24. 661: wrpr %g0, RTRAP_PSTATE, %pstate
  25. /* If userspace is using ADI, it could potentially pass
  26. * a pointer with version tag embedded in it. To maintain
  27. * the ADI security, we must re-enable PSTATE.mcde before
  28. * we continue execution in the kernel for another thread.
  29. */
  30. .section .sun_m7_1insn_patch, "ax"
  31. .word 661b
  32. wrpr %g0, RTRAP_PSTATE|PSTATE_MCDE, %pstate
  33. .previous
  34. ba,pt %xcc, __handle_preemption_continue
  35. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  36. __handle_user_windows:
  37. add %sp, PTREGS_OFF, %o0
  38. call fault_in_user_windows
  39. 661: wrpr %g0, RTRAP_PSTATE, %pstate
  40. /* If userspace is using ADI, it could potentially pass
  41. * a pointer with version tag embedded in it. To maintain
  42. * the ADI security, we must re-enable PSTATE.mcde before
  43. * we continue execution in the kernel for another thread.
  44. */
  45. .section .sun_m7_1insn_patch, "ax"
  46. .word 661b
  47. wrpr %g0, RTRAP_PSTATE|PSTATE_MCDE, %pstate
  48. .previous
  49. ba,pt %xcc, __handle_preemption_continue
  50. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  51. __handle_userfpu:
  52. rd %fprs, %l5
  53. andcc %l5, FPRS_FEF, %g0
  54. sethi %hi(TSTATE_PEF), %o0
  55. be,a,pn %icc, __handle_userfpu_continue
  56. andn %l1, %o0, %l1
  57. ba,a,pt %xcc, __handle_userfpu_continue
  58. __handle_signal:
  59. mov %l5, %o1
  60. add %sp, PTREGS_OFF, %o0
  61. mov %l0, %o2
  62. call do_notify_resume
  63. 661: wrpr %g0, RTRAP_PSTATE, %pstate
  64. /* If userspace is using ADI, it could potentially pass
  65. * a pointer with version tag embedded in it. To maintain
  66. * the ADI security, we must re-enable PSTATE.mcde before
  67. * we continue execution in the kernel for another thread.
  68. */
  69. .section .sun_m7_1insn_patch, "ax"
  70. .word 661b
  71. wrpr %g0, RTRAP_PSTATE|PSTATE_MCDE, %pstate
  72. .previous
  73. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  74. /* Signal delivery can modify pt_regs tstate, so we must
  75. * reload it.
  76. */
  77. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  78. sethi %hi(0xf << 20), %l4
  79. and %l1, %l4, %l4
  80. andn %l1, %l4, %l1
  81. ba,pt %xcc, __handle_preemption_continue
  82. srl %l4, 20, %l4
  83. /* When returning from a NMI (%pil==15) interrupt we want to
  84. * avoid running softirqs, doing IRQ tracing, preempting, etc.
  85. */
  86. .globl rtrap_nmi
  87. rtrap_nmi: ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  88. sethi %hi(0xf << 20), %l4
  89. and %l1, %l4, %l4
  90. andn %l1, %l4, %l1
  91. srl %l4, 20, %l4
  92. ba,pt %xcc, rtrap_no_irq_enable
  93. nop
  94. /* Do not actually set the %pil here. We will do that
  95. * below after we clear PSTATE_IE in the %pstate register.
  96. * If we re-enable interrupts here, we can recurse down
  97. * the hardirq stack potentially endlessly, causing a
  98. * stack overflow.
  99. */
  100. .align 64
  101. .globl rtrap_irq, rtrap, irqsz_patchme, rtrap_xcall
  102. rtrap_irq:
  103. rtrap:
  104. /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
  105. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  106. rtrap_xcall:
  107. sethi %hi(0xf << 20), %l4
  108. and %l1, %l4, %l4
  109. andn %l1, %l4, %l1
  110. srl %l4, 20, %l4
  111. #ifdef CONFIG_TRACE_IRQFLAGS
  112. brnz,pn %l4, rtrap_no_irq_enable
  113. nop
  114. call trace_hardirqs_on
  115. nop
  116. /* Do not actually set the %pil here. We will do that
  117. * below after we clear PSTATE_IE in the %pstate register.
  118. * If we re-enable interrupts here, we can recurse down
  119. * the hardirq stack potentially endlessly, causing a
  120. * stack overflow.
  121. *
  122. * It is tempting to put this test and trace_hardirqs_on
  123. * call at the 'rt_continue' label, but that will not work
  124. * as that path hits unconditionally and we do not want to
  125. * execute this in NMI return paths, for example.
  126. */
  127. #endif
  128. rtrap_no_irq_enable:
  129. andcc %l1, TSTATE_PRIV, %l3
  130. bne,pn %icc, to_kernel
  131. nop
  132. /* We must hold IRQs off and atomically test schedule+signal
  133. * state, then hold them off all the way back to userspace.
  134. * If we are returning to kernel, none of this matters. Note
  135. * that we are disabling interrupts via PSTATE_IE, not using
  136. * %pil.
  137. *
  138. * If we do not do this, there is a window where we would do
  139. * the tests, later the signal/resched event arrives but we do
  140. * not process it since we are still in kernel mode. It would
  141. * take until the next local IRQ before the signal/resched
  142. * event would be handled.
  143. *
  144. * This also means that if we have to deal with user
  145. * windows, we have to redo all of these sched+signal checks
  146. * with IRQs disabled.
  147. */
  148. to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  149. wrpr 0, %pil
  150. __handle_preemption_continue:
  151. ldx [%g6 + TI_FLAGS], %l0
  152. sethi %hi(_TIF_USER_WORK_MASK), %o0
  153. or %o0, %lo(_TIF_USER_WORK_MASK), %o0
  154. andcc %l0, %o0, %g0
  155. sethi %hi(TSTATE_PEF), %o0
  156. be,pt %xcc, user_nowork
  157. andcc %l1, %o0, %g0
  158. andcc %l0, _TIF_NEED_RESCHED, %g0
  159. bne,pn %xcc, __handle_preemption
  160. andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
  161. bne,pn %xcc, __handle_signal
  162. ldub [%g6 + TI_WSAVED], %o2
  163. brnz,pn %o2, __handle_user_windows
  164. nop
  165. sethi %hi(TSTATE_PEF), %o0
  166. andcc %l1, %o0, %g0
  167. /* This fpdepth clear is necessary for non-syscall rtraps only */
  168. user_nowork:
  169. bne,pn %xcc, __handle_userfpu
  170. stb %g0, [%g6 + TI_FPDEPTH]
  171. __handle_userfpu_continue:
  172. rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
  173. ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
  174. ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
  175. ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
  176. ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
  177. brz,pt %l3, 1f
  178. mov %g6, %l2
  179. /* Must do this before thread reg is clobbered below. */
  180. LOAD_PER_CPU_BASE(%g5, %g6, %i0, %i1, %i2)
  181. 1:
  182. ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
  183. ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
  184. /* Normal globals are restored, go to trap globals. */
  185. 661: wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
  186. nop
  187. .section .sun4v_2insn_patch, "ax"
  188. .word 661b
  189. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  190. SET_GL(1)
  191. .previous
  192. mov %l2, %g6
  193. ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
  194. ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
  195. ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
  196. ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
  197. ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
  198. ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
  199. ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
  200. ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
  201. ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
  202. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
  203. ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
  204. wr %o3, %g0, %y
  205. wrpr %l4, 0x0, %pil
  206. wrpr %g0, 0x1, %tl
  207. andn %l1, TSTATE_SYSCALL, %l1
  208. wrpr %l1, %g0, %tstate
  209. wrpr %l2, %g0, %tpc
  210. wrpr %o2, %g0, %tnpc
  211. brnz,pn %l3, kern_rtt
  212. mov PRIMARY_CONTEXT, %l7
  213. 661: ldxa [%l7 + %l7] ASI_DMMU, %l0
  214. .section .sun4v_1insn_patch, "ax"
  215. .word 661b
  216. ldxa [%l7 + %l7] ASI_MMU, %l0
  217. .previous
  218. sethi %hi(sparc64_kern_pri_nuc_bits), %l1
  219. ldx [%l1 + %lo(sparc64_kern_pri_nuc_bits)], %l1
  220. or %l0, %l1, %l0
  221. 661: stxa %l0, [%l7] ASI_DMMU
  222. .section .sun4v_1insn_patch, "ax"
  223. .word 661b
  224. stxa %l0, [%l7] ASI_MMU
  225. .previous
  226. sethi %hi(KERNBASE), %l7
  227. flush %l7
  228. rdpr %wstate, %l1
  229. rdpr %otherwin, %l2
  230. srl %l1, 3, %l1
  231. 661: wrpr %l2, %g0, %canrestore
  232. .section .fast_win_ctrl_1insn_patch, "ax"
  233. .word 661b
  234. .word 0x89880000 ! normalw
  235. .previous
  236. wrpr %l1, %g0, %wstate
  237. brnz,pt %l2, user_rtt_restore
  238. 661: wrpr %g0, %g0, %otherwin
  239. .section .fast_win_ctrl_1insn_patch, "ax"
  240. .word 661b
  241. nop
  242. .previous
  243. ldx [%g6 + TI_FLAGS], %g3
  244. wr %g0, ASI_AIUP, %asi
  245. rdpr %cwp, %g1
  246. andcc %g3, _TIF_32BIT, %g0
  247. sub %g1, 1, %g1
  248. bne,pt %xcc, user_rtt_fill_32bit
  249. wrpr %g1, %cwp
  250. ba,a,pt %xcc, user_rtt_fill_64bit
  251. nop
  252. user_rtt_fill_fixup_dax:
  253. ba,pt %xcc, user_rtt_fill_fixup_common
  254. mov 1, %g3
  255. user_rtt_fill_fixup_mna:
  256. ba,pt %xcc, user_rtt_fill_fixup_common
  257. mov 2, %g3
  258. user_rtt_fill_fixup:
  259. ba,pt %xcc, user_rtt_fill_fixup_common
  260. clr %g3
  261. user_rtt_pre_restore:
  262. add %g1, 1, %g1
  263. wrpr %g1, 0x0, %cwp
  264. user_rtt_restore:
  265. restore
  266. rdpr %canrestore, %g1
  267. wrpr %g1, 0x0, %cleanwin
  268. retry
  269. nop
  270. kern_rtt: rdpr %canrestore, %g1
  271. brz,pn %g1, kern_rtt_fill
  272. nop
  273. kern_rtt_restore:
  274. stw %g0, [%sp + PTREGS_OFF + PT_V9_MAGIC]
  275. restore
  276. retry
  277. to_kernel:
  278. #ifdef CONFIG_PREEMPTION
  279. ldsw [%g6 + TI_PRE_COUNT], %l5
  280. brnz %l5, kern_fpucheck
  281. ldx [%g6 + TI_FLAGS], %l5
  282. andcc %l5, _TIF_NEED_RESCHED, %g0
  283. be,pt %xcc, kern_fpucheck
  284. nop
  285. cmp %l4, 0
  286. bne,pn %xcc, kern_fpucheck
  287. nop
  288. call preempt_schedule_irq
  289. nop
  290. ba,pt %xcc, rtrap
  291. #endif
  292. kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
  293. brz,pt %l5, rt_continue
  294. srl %l5, 1, %o0
  295. add %g6, TI_FPSAVED, %l6
  296. ldub [%l6 + %o0], %l2
  297. sub %l5, 2, %l5
  298. add %g6, TI_GSR, %o1
  299. andcc %l2, (FPRS_FEF|FPRS_DU), %g0
  300. be,pt %icc, 2f
  301. and %l2, FPRS_DL, %l6
  302. andcc %l2, FPRS_FEF, %g0
  303. be,pn %icc, 5f
  304. sll %o0, 3, %o5
  305. rd %fprs, %g1
  306. wr %g1, FPRS_FEF, %fprs
  307. ldx [%o1 + %o5], %g1
  308. add %g6, TI_XFSR, %o1
  309. sll %o0, 8, %o2
  310. add %g6, TI_FPREGS, %o3
  311. brz,pn %l6, 1f
  312. add %g6, TI_FPREGS+0x40, %o4
  313. membar #Sync
  314. ldda [%o3 + %o2] ASI_BLK_P, %f0
  315. ldda [%o4 + %o2] ASI_BLK_P, %f16
  316. membar #Sync
  317. 1: andcc %l2, FPRS_DU, %g0
  318. be,pn %icc, 1f
  319. wr %g1, 0, %gsr
  320. add %o2, 0x80, %o2
  321. membar #Sync
  322. ldda [%o3 + %o2] ASI_BLK_P, %f32
  323. ldda [%o4 + %o2] ASI_BLK_P, %f48
  324. 1: membar #Sync
  325. ldx [%o1 + %o5], %fsr
  326. 2: stb %l5, [%g6 + TI_FPDEPTH]
  327. ba,pt %xcc, rt_continue
  328. nop
  329. 5: wr %g0, FPRS_FEF, %fprs
  330. sll %o0, 8, %o2
  331. add %g6, TI_FPREGS+0x80, %o3
  332. add %g6, TI_FPREGS+0xc0, %o4
  333. membar #Sync
  334. ldda [%o3 + %o2] ASI_BLK_P, %f32
  335. ldda [%o4 + %o2] ASI_BLK_P, %f48
  336. membar #Sync
  337. wr %g0, FPRS_DU, %fprs
  338. ba,pt %xcc, rt_continue
  339. stb %l5, [%g6 + TI_FPDEPTH]