rtrap_64.S 9.7 KB

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