rtrap_64.S 9.0 KB

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