rtrap.S 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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_NOTIFY_RESUME | _TIF_SIGPENDING), %g0
  49. be,pt %xcc, __handle_user_windows_continue
  50. nop
  51. clr %o0
  52. mov %l5, %o2
  53. mov %l6, %o3
  54. add %sp, PTREGS_OFF, %o1
  55. mov %l0, %o4
  56. call do_notify_resume
  57. wrpr %g0, RTRAP_PSTATE, %pstate
  58. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  59. clr %l6
  60. /* Signal delivery can modify pt_regs tstate, so we must
  61. * reload it.
  62. */
  63. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  64. sethi %hi(0xf << 20), %l4
  65. and %l1, %l4, %l4
  66. ba,pt %xcc, __handle_user_windows_continue
  67. andn %l1, %l4, %l1
  68. __handle_perfctrs:
  69. call update_perfctrs
  70. wrpr %g0, RTRAP_PSTATE, %pstate
  71. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  72. ldub [%g6 + TI_WSAVED], %o2
  73. brz,pt %o2, 1f
  74. nop
  75. /* Redo userwin+sched+sig checks */
  76. call fault_in_user_windows
  77. wrpr %g0, RTRAP_PSTATE, %pstate
  78. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  79. ldx [%g6 + TI_FLAGS], %l0
  80. andcc %l0, _TIF_NEED_RESCHED, %g0
  81. be,pt %xcc, 1f
  82. nop
  83. call schedule
  84. wrpr %g0, RTRAP_PSTATE, %pstate
  85. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  86. ldx [%g6 + TI_FLAGS], %l0
  87. 1: andcc %l0, (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING), %g0
  88. be,pt %xcc, __handle_perfctrs_continue
  89. sethi %hi(TSTATE_PEF), %o0
  90. clr %o0
  91. mov %l5, %o2
  92. mov %l6, %o3
  93. add %sp, PTREGS_OFF, %o1
  94. mov %l0, %o4
  95. call do_notify_resume
  96. wrpr %g0, RTRAP_PSTATE, %pstate
  97. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  98. clr %l6
  99. /* Signal delivery can modify pt_regs tstate, so we must
  100. * reload it.
  101. */
  102. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  103. sethi %hi(0xf << 20), %l4
  104. and %l1, %l4, %l4
  105. andn %l1, %l4, %l1
  106. ba,pt %xcc, __handle_perfctrs_continue
  107. sethi %hi(TSTATE_PEF), %o0
  108. __handle_userfpu:
  109. rd %fprs, %l5
  110. andcc %l5, FPRS_FEF, %g0
  111. sethi %hi(TSTATE_PEF), %o0
  112. be,a,pn %icc, __handle_userfpu_continue
  113. andn %l1, %o0, %l1
  114. ba,a,pt %xcc, __handle_userfpu_continue
  115. __handle_signal:
  116. clr %o0
  117. mov %l5, %o2
  118. mov %l6, %o3
  119. add %sp, PTREGS_OFF, %o1
  120. mov %l0, %o4
  121. call do_notify_resume
  122. wrpr %g0, RTRAP_PSTATE, %pstate
  123. wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  124. clr %l6
  125. /* Signal delivery can modify pt_regs tstate, so we must
  126. * reload it.
  127. */
  128. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  129. sethi %hi(0xf << 20), %l4
  130. and %l1, %l4, %l4
  131. ba,pt %xcc, __handle_signal_continue
  132. andn %l1, %l4, %l1
  133. .align 64
  134. .globl rtrap_irq, rtrap_clr_l6, rtrap, irqsz_patchme, rtrap_xcall
  135. rtrap_irq:
  136. rtrap_clr_l6: clr %l6
  137. rtrap:
  138. ldub [%g6 + TI_CPU], %l0
  139. sethi %hi(irq_stat), %l2 ! &softirq_active
  140. or %l2, %lo(irq_stat), %l2 ! &softirq_active
  141. irqsz_patchme: sllx %l0, 0, %l0
  142. lduw [%l2 + %l0], %l1 ! softirq_pending
  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_NOTIFY_RESUME | _TIF_SIGPENDING), %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. mov TSB_REG, %g6
  204. brnz,a,pn %l3, 1f
  205. ldxa [%g6] ASI_IMMU, %g5
  206. 1: ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
  207. ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
  208. wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
  209. ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
  210. ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
  211. ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
  212. ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
  213. ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
  214. ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
  215. ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
  216. ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
  217. ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
  218. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
  219. ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
  220. wr %o3, %g0, %y
  221. srl %l4, 20, %l4
  222. wrpr %l4, 0x0, %pil
  223. wrpr %g0, 0x1, %tl
  224. wrpr %l1, %g0, %tstate
  225. wrpr %l2, %g0, %tpc
  226. wrpr %o2, %g0, %tnpc
  227. brnz,pn %l3, kern_rtt
  228. mov PRIMARY_CONTEXT, %l7
  229. ldxa [%l7 + %l7] ASI_DMMU, %l0
  230. cplus_rtrap_insn_1:
  231. sethi %hi(0), %l1
  232. sllx %l1, 32, %l1
  233. or %l0, %l1, %l0
  234. stxa %l0, [%l7] ASI_DMMU
  235. flush %g6
  236. rdpr %wstate, %l1
  237. rdpr %otherwin, %l2
  238. srl %l1, 3, %l1
  239. wrpr %l2, %g0, %canrestore
  240. wrpr %l1, %g0, %wstate
  241. wrpr %g0, %g0, %otherwin
  242. restore
  243. rdpr %canrestore, %g1
  244. wrpr %g1, 0x0, %cleanwin
  245. retry
  246. nop
  247. kern_rtt: restore
  248. retry
  249. to_kernel:
  250. #ifdef CONFIG_PREEMPT
  251. ldsw [%g6 + TI_PRE_COUNT], %l5
  252. brnz %l5, kern_fpucheck
  253. ldx [%g6 + TI_FLAGS], %l5
  254. andcc %l5, _TIF_NEED_RESCHED, %g0
  255. be,pt %xcc, kern_fpucheck
  256. srl %l4, 20, %l5
  257. cmp %l5, 0
  258. bne,pn %xcc, kern_fpucheck
  259. sethi %hi(PREEMPT_ACTIVE), %l6
  260. stw %l6, [%g6 + TI_PRE_COUNT]
  261. call schedule
  262. nop
  263. ba,pt %xcc, rtrap
  264. stw %g0, [%g6 + TI_PRE_COUNT]
  265. #endif
  266. kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
  267. brz,pt %l5, rt_continue
  268. srl %l5, 1, %o0
  269. add %g6, TI_FPSAVED, %l6
  270. ldub [%l6 + %o0], %l2
  271. sub %l5, 2, %l5
  272. add %g6, TI_GSR, %o1
  273. andcc %l2, (FPRS_FEF|FPRS_DU), %g0
  274. be,pt %icc, 2f
  275. and %l2, FPRS_DL, %l6
  276. andcc %l2, FPRS_FEF, %g0
  277. be,pn %icc, 5f
  278. sll %o0, 3, %o5
  279. rd %fprs, %g1
  280. wr %g1, FPRS_FEF, %fprs
  281. ldx [%o1 + %o5], %g1
  282. add %g6, TI_XFSR, %o1
  283. membar #StoreLoad | #LoadLoad
  284. sll %o0, 8, %o2
  285. add %g6, TI_FPREGS, %o3
  286. brz,pn %l6, 1f
  287. add %g6, TI_FPREGS+0x40, %o4
  288. ldda [%o3 + %o2] ASI_BLK_P, %f0
  289. ldda [%o4 + %o2] ASI_BLK_P, %f16
  290. 1: andcc %l2, FPRS_DU, %g0
  291. be,pn %icc, 1f
  292. wr %g1, 0, %gsr
  293. add %o2, 0x80, %o2
  294. ldda [%o3 + %o2] ASI_BLK_P, %f32
  295. ldda [%o4 + %o2] ASI_BLK_P, %f48
  296. 1: membar #Sync
  297. ldx [%o1 + %o5], %fsr
  298. 2: stb %l5, [%g6 + TI_FPDEPTH]
  299. ba,pt %xcc, rt_continue
  300. nop
  301. 5: wr %g0, FPRS_FEF, %fprs
  302. membar #StoreLoad | #LoadLoad
  303. sll %o0, 8, %o2
  304. add %g6, TI_FPREGS+0x80, %o3
  305. add %g6, TI_FPREGS+0xc0, %o4
  306. ldda [%o3 + %o2] ASI_BLK_P, %f32
  307. ldda [%o4 + %o2] ASI_BLK_P, %f48
  308. membar #Sync
  309. wr %g0, FPRS_DU, %fprs
  310. ba,pt %xcc, rt_continue
  311. stb %l5, [%g6 + TI_FPDEPTH]
  312. cplus_rinsn_1:
  313. sethi %uhi(CTX_CHEETAH_PLUS_NUC), %l1
  314. .globl cheetah_plus_patch_rtrap
  315. cheetah_plus_patch_rtrap:
  316. /* We configure the dTLB512_0 for 4MB pages and the
  317. * dTLB512_1 for 8K pages when in context zero.
  318. */
  319. sethi %hi(cplus_rinsn_1), %o0
  320. sethi %hi(cplus_rtrap_insn_1), %o2
  321. lduw [%o0 + %lo(cplus_rinsn_1)], %o1
  322. or %o2, %lo(cplus_rtrap_insn_1), %o2
  323. stw %o1, [%o2]
  324. flush %o2
  325. retl
  326. nop