rtrap.S 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. #ifndef CONFIG_SMP
  139. sethi %hi(per_cpu____cpu_data), %l0
  140. lduw [%l0 + %lo(per_cpu____cpu_data)], %l1
  141. #else
  142. sethi %hi(per_cpu____cpu_data), %l0
  143. or %l0, %lo(per_cpu____cpu_data), %l0
  144. lduw [%l0 + %g5], %l1
  145. #endif
  146. cmp %l1, 0
  147. /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
  148. bne,pn %icc, __handle_softirq
  149. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  150. __handle_softirq_continue:
  151. rtrap_xcall:
  152. sethi %hi(0xf << 20), %l4
  153. andcc %l1, TSTATE_PRIV, %l3
  154. and %l1, %l4, %l4
  155. bne,pn %icc, to_kernel
  156. andn %l1, %l4, %l1
  157. /* We must hold IRQs off and atomically test schedule+signal
  158. * state, then hold them off all the way back to userspace.
  159. * If we are returning to kernel, none of this matters.
  160. *
  161. * If we do not do this, there is a window where we would do
  162. * the tests, later the signal/resched event arrives but we do
  163. * not process it since we are still in kernel mode. It would
  164. * take until the next local IRQ before the signal/resched
  165. * event would be handled.
  166. *
  167. * This also means that if we have to deal with performance
  168. * counters or user windows, we have to redo all of these
  169. * sched+signal checks with IRQs disabled.
  170. */
  171. to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
  172. wrpr 0, %pil
  173. __handle_preemption_continue:
  174. ldx [%g6 + TI_FLAGS], %l0
  175. sethi %hi(_TIF_USER_WORK_MASK), %o0
  176. or %o0, %lo(_TIF_USER_WORK_MASK), %o0
  177. andcc %l0, %o0, %g0
  178. sethi %hi(TSTATE_PEF), %o0
  179. be,pt %xcc, user_nowork
  180. andcc %l1, %o0, %g0
  181. andcc %l0, _TIF_NEED_RESCHED, %g0
  182. bne,pn %xcc, __handle_preemption
  183. andcc %l0, (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING), %g0
  184. bne,pn %xcc, __handle_signal
  185. __handle_signal_continue:
  186. ldub [%g6 + TI_WSAVED], %o2
  187. brnz,pn %o2, __handle_user_windows
  188. nop
  189. __handle_user_windows_continue:
  190. ldx [%g6 + TI_FLAGS], %l5
  191. andcc %l5, _TIF_PERFCTR, %g0
  192. sethi %hi(TSTATE_PEF), %o0
  193. bne,pn %xcc, __handle_perfctrs
  194. __handle_perfctrs_continue:
  195. andcc %l1, %o0, %g0
  196. /* This fpdepth clear is necessary for non-syscall rtraps only */
  197. user_nowork:
  198. bne,pn %xcc, __handle_userfpu
  199. stb %g0, [%g6 + TI_FPDEPTH]
  200. __handle_userfpu_continue:
  201. rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
  202. ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
  203. ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
  204. ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
  205. ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
  206. mov TSB_REG, %g6
  207. brnz,a,pn %l3, 1f
  208. ldxa [%g6] ASI_IMMU, %g5
  209. 1: ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
  210. ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
  211. wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
  212. ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
  213. ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
  214. ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
  215. ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
  216. ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
  217. ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
  218. ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
  219. ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
  220. ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
  221. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
  222. ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
  223. wr %o3, %g0, %y
  224. srl %l4, 20, %l4
  225. wrpr %l4, 0x0, %pil
  226. wrpr %g0, 0x1, %tl
  227. wrpr %l1, %g0, %tstate
  228. wrpr %l2, %g0, %tpc
  229. wrpr %o2, %g0, %tnpc
  230. brnz,pn %l3, kern_rtt
  231. mov PRIMARY_CONTEXT, %l7
  232. ldxa [%l7 + %l7] ASI_DMMU, %l0
  233. cplus_rtrap_insn_1:
  234. sethi %hi(0), %l1
  235. sllx %l1, 32, %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. membar #StoreLoad | #LoadLoad
  287. sll %o0, 8, %o2
  288. add %g6, TI_FPREGS, %o3
  289. brz,pn %l6, 1f
  290. add %g6, TI_FPREGS+0x40, %o4
  291. ldda [%o3 + %o2] ASI_BLK_P, %f0
  292. ldda [%o4 + %o2] ASI_BLK_P, %f16
  293. 1: andcc %l2, FPRS_DU, %g0
  294. be,pn %icc, 1f
  295. wr %g1, 0, %gsr
  296. add %o2, 0x80, %o2
  297. ldda [%o3 + %o2] ASI_BLK_P, %f32
  298. ldda [%o4 + %o2] ASI_BLK_P, %f48
  299. 1: membar #Sync
  300. ldx [%o1 + %o5], %fsr
  301. 2: stb %l5, [%g6 + TI_FPDEPTH]
  302. ba,pt %xcc, rt_continue
  303. nop
  304. 5: wr %g0, FPRS_FEF, %fprs
  305. membar #StoreLoad | #LoadLoad
  306. sll %o0, 8, %o2
  307. add %g6, TI_FPREGS+0x80, %o3
  308. add %g6, TI_FPREGS+0xc0, %o4
  309. ldda [%o3 + %o2] ASI_BLK_P, %f32
  310. ldda [%o4 + %o2] ASI_BLK_P, %f48
  311. membar #Sync
  312. wr %g0, FPRS_DU, %fprs
  313. ba,pt %xcc, rt_continue
  314. stb %l5, [%g6 + TI_FPDEPTH]
  315. cplus_rinsn_1:
  316. sethi %uhi(CTX_CHEETAH_PLUS_NUC), %l1
  317. .globl cheetah_plus_patch_rtrap
  318. cheetah_plus_patch_rtrap:
  319. /* We configure the dTLB512_0 for 4MB pages and the
  320. * dTLB512_1 for 8K pages when in context zero.
  321. */
  322. sethi %hi(cplus_rinsn_1), %o0
  323. sethi %hi(cplus_rtrap_insn_1), %o2
  324. lduw [%o0 + %lo(cplus_rinsn_1)], %o1
  325. or %o2, %lo(cplus_rtrap_insn_1), %o2
  326. stw %o1, [%o2]
  327. flush %o2
  328. retl
  329. nop