rtrap.S 11 KB

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