rtrap_64.S 9.4 KB

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