rtrap_64.S 10 KB

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