rtrap_64.S 8.8 KB

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