rtrap.S 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /* $Id: rtrap.S,v 1.61 2002/02/09 19:49:31 davem Exp $
  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 <linux/config.h>
  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. #define RTRAP_PSTATE (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_IE)
  16. #define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV)
  17. #define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG)
  18. /* Register %l6 keeps track of whether we are returning
  19. * from a system call or not. It is cleared if we call
  20. * do_notify_resume, and it must not be otherwise modified
  21. * until we fully commit to returning to userspace.
  22. */
  23. .text
  24. .align 32
  25. __handle_softirq:
  26. call do_softirq
  27. nop
  28. ba,a,pt %xcc, __handle_softirq_continue
  29. nop
  30. __handle_preemption:
  31. call schedule
  32. wrpr %g0, RTRAP_PSTATE, %pstate
  33. ba,pt %xcc, __handle_preemption_continue
  34. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  35. __handle_user_windows:
  36. call fault_in_user_windows
  37. wrpr %g0, RTRAP_PSTATE, %pstate
  38. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  39. /* Redo sched+sig checks */
  40. ldx [%g6 + TI_FLAGS], %l0
  41. andcc %l0, _TIF_NEED_RESCHED, %g0
  42. be,pt %xcc, 1f
  43. nop
  44. call schedule
  45. wrpr %g0, RTRAP_PSTATE, %pstate
  46. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  47. ldx [%g6 + TI_FLAGS], %l0
  48. 1: andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
  49. be,pt %xcc, __handle_user_windows_continue
  50. nop
  51. mov %l5, %o1
  52. mov %l6, %o2
  53. add %sp, PTREGS_OFF, %o0
  54. mov %l0, %o3
  55. call do_notify_resume
  56. wrpr %g0, RTRAP_PSTATE, %pstate
  57. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  58. clr %l6
  59. /* Signal delivery can modify pt_regs tstate, so we must
  60. * reload it.
  61. */
  62. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  63. sethi %hi(0xf << 20), %l4
  64. and %l1, %l4, %l4
  65. ba,pt %xcc, __handle_user_windows_continue
  66. andn %l1, %l4, %l1
  67. __handle_perfctrs:
  68. call update_perfctrs
  69. wrpr %g0, RTRAP_PSTATE, %pstate
  70. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  71. ldub [%g6 + TI_WSAVED], %o2
  72. brz,pt %o2, 1f
  73. nop
  74. /* Redo userwin+sched+sig checks */
  75. call fault_in_user_windows
  76. wrpr %g0, RTRAP_PSTATE, %pstate
  77. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  78. ldx [%g6 + TI_FLAGS], %l0
  79. andcc %l0, _TIF_NEED_RESCHED, %g0
  80. be,pt %xcc, 1f
  81. nop
  82. call schedule
  83. wrpr %g0, RTRAP_PSTATE, %pstate
  84. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  85. ldx [%g6 + TI_FLAGS], %l0
  86. 1: andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
  87. be,pt %xcc, __handle_perfctrs_continue
  88. sethi %hi(TSTATE_PEF), %o0
  89. mov %l5, %o1
  90. mov %l6, %o2
  91. add %sp, PTREGS_OFF, %o0
  92. mov %l0, %o3
  93. call do_notify_resume
  94. wrpr %g0, RTRAP_PSTATE, %pstate
  95. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  96. clr %l6
  97. /* Signal delivery can modify pt_regs tstate, so we must
  98. * reload it.
  99. */
  100. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  101. sethi %hi(0xf << 20), %l4
  102. and %l1, %l4, %l4
  103. andn %l1, %l4, %l1
  104. ba,pt %xcc, __handle_perfctrs_continue
  105. sethi %hi(TSTATE_PEF), %o0
  106. __handle_userfpu:
  107. rd %fprs, %l5
  108. andcc %l5, FPRS_FEF, %g0
  109. sethi %hi(TSTATE_PEF), %o0
  110. be,a,pn %icc, __handle_userfpu_continue
  111. andn %l1, %o0, %l1
  112. ba,a,pt %xcc, __handle_userfpu_continue
  113. __handle_signal:
  114. mov %l5, %o1
  115. mov %l6, %o2
  116. add %sp, PTREGS_OFF, %o0
  117. mov %l0, %o3
  118. call do_notify_resume
  119. wrpr %g0, RTRAP_PSTATE, %pstate
  120. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  121. clr %l6
  122. /* Signal delivery can modify pt_regs tstate, so we must
  123. * reload it.
  124. */
  125. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  126. sethi %hi(0xf << 20), %l4
  127. and %l1, %l4, %l4
  128. ba,pt %xcc, __handle_signal_continue
  129. andn %l1, %l4, %l1
  130. .align 64
  131. .globl rtrap_irq, rtrap_clr_l6, rtrap, irqsz_patchme, rtrap_xcall
  132. rtrap_irq:
  133. rtrap_clr_l6: clr %l6
  134. rtrap:
  135. #ifndef CONFIG_SMP
  136. sethi %hi(per_cpu____cpu_data), %l0
  137. lduw [%l0 + %lo(per_cpu____cpu_data)], %l1
  138. #else
  139. sethi %hi(per_cpu____cpu_data), %l0
  140. or %l0, %lo(per_cpu____cpu_data), %l0
  141. lduw [%l0 + %g5], %l1
  142. #endif
  143. cmp %l1, 0
  144. /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
  145. bne,pn %icc, __handle_softirq
  146. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  147. __handle_softirq_continue:
  148. rtrap_xcall:
  149. sethi %hi(0xf << 20), %l4
  150. andcc %l1, TSTATE_PRIV, %l3
  151. and %l1, %l4, %l4
  152. bne,pn %icc, to_kernel
  153. andn %l1, %l4, %l1
  154. /* We must hold IRQs off and atomically test schedule+signal
  155. * state, then hold them off all the way back to userspace.
  156. * If we are returning to kernel, none of this matters.
  157. *
  158. * If we do not do this, there is a window where we would do
  159. * the tests, later the signal/resched event arrives but we do
  160. * not process it since we are still in kernel mode. It would
  161. * take until the next local IRQ before the signal/resched
  162. * event would be handled.
  163. *
  164. * This also means that if we have to deal with performance
  165. * counters or user windows, we have to redo all of these
  166. * sched+signal checks with IRQs disabled.
  167. */
  168. to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  169. wrpr 0, %pil
  170. __handle_preemption_continue:
  171. ldx [%g6 + TI_FLAGS], %l0
  172. sethi %hi(_TIF_USER_WORK_MASK), %o0
  173. or %o0, %lo(_TIF_USER_WORK_MASK), %o0
  174. andcc %l0, %o0, %g0
  175. sethi %hi(TSTATE_PEF), %o0
  176. be,pt %xcc, user_nowork
  177. andcc %l1, %o0, %g0
  178. andcc %l0, _TIF_NEED_RESCHED, %g0
  179. bne,pn %xcc, __handle_preemption
  180. andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
  181. bne,pn %xcc, __handle_signal
  182. __handle_signal_continue:
  183. ldub [%g6 + TI_WSAVED], %o2
  184. brnz,pn %o2, __handle_user_windows
  185. nop
  186. __handle_user_windows_continue:
  187. ldx [%g6 + TI_FLAGS], %l5
  188. andcc %l5, _TIF_PERFCTR, %g0
  189. sethi %hi(TSTATE_PEF), %o0
  190. bne,pn %xcc, __handle_perfctrs
  191. __handle_perfctrs_continue:
  192. andcc %l1, %o0, %g0
  193. /* This fpdepth clear is necessary for non-syscall rtraps only */
  194. user_nowork:
  195. bne,pn %xcc, __handle_userfpu
  196. stb %g0, [%g6 + TI_FPDEPTH]
  197. __handle_userfpu_continue:
  198. rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
  199. ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
  200. ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
  201. ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
  202. ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
  203. #ifdef CONFIG_SMP
  204. #error IMMU TSB usage must be fixed
  205. mov TSB_REG, %g6
  206. brnz,a,pn %l3, 1f
  207. ldxa [%g6] ASI_IMMU, %g5
  208. #endif
  209. 1:
  210. ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
  211. ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
  212. wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
  213. ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
  214. ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
  215. ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
  216. ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
  217. ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
  218. ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
  219. ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
  220. ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
  221. ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
  222. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
  223. ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
  224. wr %o3, %g0, %y
  225. srl %l4, 20, %l4
  226. wrpr %l4, 0x0, %pil
  227. wrpr %g0, 0x1, %tl
  228. wrpr %l1, %g0, %tstate
  229. wrpr %l2, %g0, %tpc
  230. wrpr %o2, %g0, %tnpc
  231. brnz,pn %l3, kern_rtt
  232. mov PRIMARY_CONTEXT, %l7
  233. ldxa [%l7 + %l7] ASI_DMMU, %l0
  234. sethi %hi(sparc64_kern_pri_nuc_bits), %l1
  235. ldx [%l1 + %lo(sparc64_kern_pri_nuc_bits)], %l1
  236. or %l0, %l1, %l0
  237. stxa %l0, [%l7] ASI_DMMU
  238. flush %g6
  239. rdpr %wstate, %l1
  240. rdpr %otherwin, %l2
  241. srl %l1, 3, %l1
  242. wrpr %l2, %g0, %canrestore
  243. wrpr %l1, %g0, %wstate
  244. wrpr %g0, %g0, %otherwin
  245. restore
  246. rdpr %canrestore, %g1
  247. wrpr %g1, 0x0, %cleanwin
  248. retry
  249. nop
  250. kern_rtt: restore
  251. retry
  252. to_kernel:
  253. #ifdef CONFIG_PREEMPT
  254. ldsw [%g6 + TI_PRE_COUNT], %l5
  255. brnz %l5, kern_fpucheck
  256. ldx [%g6 + TI_FLAGS], %l5
  257. andcc %l5, _TIF_NEED_RESCHED, %g0
  258. be,pt %xcc, kern_fpucheck
  259. srl %l4, 20, %l5
  260. cmp %l5, 0
  261. bne,pn %xcc, kern_fpucheck
  262. sethi %hi(PREEMPT_ACTIVE), %l6
  263. stw %l6, [%g6 + TI_PRE_COUNT]
  264. call schedule
  265. nop
  266. ba,pt %xcc, rtrap
  267. stw %g0, [%g6 + TI_PRE_COUNT]
  268. #endif
  269. kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
  270. brz,pt %l5, rt_continue
  271. srl %l5, 1, %o0
  272. add %g6, TI_FPSAVED, %l6
  273. ldub [%l6 + %o0], %l2
  274. sub %l5, 2, %l5
  275. add %g6, TI_GSR, %o1
  276. andcc %l2, (FPRS_FEF|FPRS_DU), %g0
  277. be,pt %icc, 2f
  278. and %l2, FPRS_DL, %l6
  279. andcc %l2, FPRS_FEF, %g0
  280. be,pn %icc, 5f
  281. sll %o0, 3, %o5
  282. rd %fprs, %g1
  283. wr %g1, FPRS_FEF, %fprs
  284. ldx [%o1 + %o5], %g1
  285. add %g6, TI_XFSR, %o1
  286. sll %o0, 8, %o2
  287. add %g6, TI_FPREGS, %o3
  288. brz,pn %l6, 1f
  289. add %g6, TI_FPREGS+0x40, %o4
  290. membar #Sync
  291. ldda [%o3 + %o2] ASI_BLK_P, %f0
  292. ldda [%o4 + %o2] ASI_BLK_P, %f16
  293. membar #Sync
  294. 1: andcc %l2, FPRS_DU, %g0
  295. be,pn %icc, 1f
  296. wr %g1, 0, %gsr
  297. add %o2, 0x80, %o2
  298. membar #Sync
  299. ldda [%o3 + %o2] ASI_BLK_P, %f32
  300. ldda [%o4 + %o2] ASI_BLK_P, %f48
  301. 1: membar #Sync
  302. ldx [%o1 + %o5], %fsr
  303. 2: stb %l5, [%g6 + TI_FPDEPTH]
  304. ba,pt %xcc, rt_continue
  305. nop
  306. 5: wr %g0, FPRS_FEF, %fprs
  307. sll %o0, 8, %o2
  308. add %g6, TI_FPREGS+0x80, %o3
  309. add %g6, TI_FPREGS+0xc0, %o4
  310. membar #Sync
  311. ldda [%o3 + %o2] ASI_BLK_P, %f32
  312. ldda [%o4 + %o2] ASI_BLK_P, %f48
  313. membar #Sync
  314. wr %g0, FPRS_DU, %fprs
  315. ba,pt %xcc, rt_continue
  316. stb %l5, [%g6 + TI_FPDEPTH]