rtrap_64.S 9.4 KB

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