rtrap.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /* $Id: rtrap.S,v 1.58 2002/01/31 03:30:05 davem Exp $
  2. * rtrap.S: Return from Sparc trap low-level code.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <asm/page.h>
  7. #include <asm/ptrace.h>
  8. #include <asm/psr.h>
  9. #include <asm/asi.h>
  10. #include <asm/smp.h>
  11. #include <asm/contregs.h>
  12. #include <asm/winmacro.h>
  13. #include <asm/asmmacro.h>
  14. #include <asm/thread_info.h>
  15. #define t_psr l0
  16. #define t_pc l1
  17. #define t_npc l2
  18. #define t_wim l3
  19. #define twin_tmp1 l4
  20. #define glob_tmp g4
  21. #define curptr g6
  22. /* 7 WINDOW SPARC PATCH INSTRUCTIONS */
  23. .globl rtrap_7win_patch1, rtrap_7win_patch2, rtrap_7win_patch3
  24. .globl rtrap_7win_patch4, rtrap_7win_patch5
  25. rtrap_7win_patch1: srl %t_wim, 0x6, %glob_tmp
  26. rtrap_7win_patch2: and %glob_tmp, 0x7f, %glob_tmp
  27. rtrap_7win_patch3: srl %g1, 7, %g2
  28. rtrap_7win_patch4: srl %g2, 6, %g2
  29. rtrap_7win_patch5: and %g1, 0x7f, %g1
  30. /* END OF PATCH INSTRUCTIONS */
  31. /* We need to check for a few things which are:
  32. * 1) The need to call schedule() because this
  33. * processes quantum is up.
  34. * 2) Pending signals for this process, if any
  35. * exist we need to call do_signal() to do
  36. * the needy.
  37. *
  38. * Else we just check if the rett would land us
  39. * in an invalid window, if so we need to grab
  40. * it off the user/kernel stack first.
  41. */
  42. .globl ret_trap_entry, rtrap_patch1, rtrap_patch2
  43. .globl rtrap_patch3, rtrap_patch4, rtrap_patch5
  44. .globl ret_trap_lockless_ipi
  45. ret_trap_entry:
  46. ret_trap_lockless_ipi:
  47. andcc %t_psr, PSR_PS, %g0
  48. be 1f
  49. nop
  50. wr %t_psr, 0x0, %psr
  51. b ret_trap_kernel
  52. nop
  53. 1:
  54. ld [%curptr + TI_FLAGS], %g2
  55. andcc %g2, (_TIF_NEED_RESCHED), %g0
  56. be signal_p
  57. nop
  58. call schedule
  59. nop
  60. ld [%curptr + TI_FLAGS], %g2
  61. signal_p:
  62. andcc %g2, (_TIF_NOTIFY_RESUME|_TIF_SIGPENDING), %g0
  63. bz,a ret_trap_continue
  64. ld [%sp + STACKFRAME_SZ + PT_PSR], %t_psr
  65. clr %o0
  66. mov %l5, %o2
  67. mov %l6, %o3
  68. call do_signal
  69. add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
  70. /* Fall through. */
  71. ld [%sp + STACKFRAME_SZ + PT_PSR], %t_psr
  72. clr %l6
  73. ret_trap_continue:
  74. wr %t_psr, 0x0, %psr
  75. WRITE_PAUSE
  76. ld [%curptr + TI_W_SAVED], %twin_tmp1
  77. orcc %g0, %twin_tmp1, %g0
  78. be ret_trap_nobufwins
  79. nop
  80. wr %t_psr, PSR_ET, %psr
  81. WRITE_PAUSE
  82. mov 1, %o1
  83. call try_to_clear_window_buffer
  84. add %sp, STACKFRAME_SZ, %o0
  85. b signal_p
  86. ld [%curptr + TI_FLAGS], %g2
  87. ret_trap_nobufwins:
  88. /* Load up the user's out registers so we can pull
  89. * a window from the stack, if necessary.
  90. */
  91. LOAD_PT_INS(sp)
  92. /* If there are already live user windows in the
  93. * set we can return from trap safely.
  94. */
  95. ld [%curptr + TI_UWINMASK], %twin_tmp1
  96. orcc %g0, %twin_tmp1, %g0
  97. bne ret_trap_userwins_ok
  98. nop
  99. /* Calculate new %wim, we have to pull a register
  100. * window from the users stack.
  101. */
  102. ret_trap_pull_one_window:
  103. rd %wim, %t_wim
  104. sll %t_wim, 0x1, %twin_tmp1
  105. rtrap_patch1: srl %t_wim, 0x7, %glob_tmp
  106. or %glob_tmp, %twin_tmp1, %glob_tmp
  107. rtrap_patch2: and %glob_tmp, 0xff, %glob_tmp
  108. wr %glob_tmp, 0x0, %wim
  109. /* Here comes the architecture specific
  110. * branch to the user stack checking routine
  111. * for return from traps.
  112. */
  113. .globl rtrap_mmu_patchme
  114. rtrap_mmu_patchme: b sun4c_rett_stackchk
  115. andcc %fp, 0x7, %g0
  116. ret_trap_userwins_ok:
  117. LOAD_PT_PRIV(sp, t_psr, t_pc, t_npc)
  118. or %t_pc, %t_npc, %g2
  119. andcc %g2, 0x3, %g0
  120. be 1f
  121. nop
  122. b ret_trap_unaligned_pc
  123. add %sp, STACKFRAME_SZ, %o0
  124. 1:
  125. LOAD_PT_YREG(sp, g1)
  126. LOAD_PT_GLOBALS(sp)
  127. wr %t_psr, 0x0, %psr
  128. WRITE_PAUSE
  129. jmp %t_pc
  130. rett %t_npc
  131. ret_trap_unaligned_pc:
  132. ld [%sp + STACKFRAME_SZ + PT_PC], %o1
  133. ld [%sp + STACKFRAME_SZ + PT_NPC], %o2
  134. ld [%sp + STACKFRAME_SZ + PT_PSR], %o3
  135. wr %t_wim, 0x0, %wim ! or else...
  136. wr %t_psr, PSR_ET, %psr
  137. WRITE_PAUSE
  138. call do_memaccess_unaligned
  139. nop
  140. b signal_p
  141. ld [%curptr + TI_FLAGS], %g2
  142. ret_trap_kernel:
  143. /* Will the rett land us in the invalid window? */
  144. mov 2, %g1
  145. sll %g1, %t_psr, %g1
  146. rtrap_patch3: srl %g1, 8, %g2
  147. or %g1, %g2, %g1
  148. rd %wim, %g2
  149. andcc %g2, %g1, %g0
  150. be 1f ! Nope, just return from the trap
  151. sll %g2, 0x1, %g1
  152. /* We have to grab a window before returning. */
  153. rtrap_patch4: srl %g2, 7, %g2
  154. or %g1, %g2, %g1
  155. rtrap_patch5: and %g1, 0xff, %g1
  156. wr %g1, 0x0, %wim
  157. /* Grrr, make sure we load from the right %sp... */
  158. LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
  159. restore %g0, %g0, %g0
  160. LOAD_WINDOW(sp)
  161. b 2f
  162. save %g0, %g0, %g0
  163. /* Reload the entire frame in case this is from a
  164. * kernel system call or whatever...
  165. */
  166. 1:
  167. LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
  168. 2:
  169. wr %t_psr, 0x0, %psr
  170. WRITE_PAUSE
  171. jmp %t_pc
  172. rett %t_npc
  173. ret_trap_user_stack_is_bolixed:
  174. wr %t_wim, 0x0, %wim
  175. wr %t_psr, PSR_ET, %psr
  176. WRITE_PAUSE
  177. call window_ret_fault
  178. add %sp, STACKFRAME_SZ, %o0
  179. b signal_p
  180. ld [%curptr + TI_FLAGS], %g2
  181. .globl sun4c_rett_stackchk
  182. sun4c_rett_stackchk:
  183. be 1f
  184. and %fp, 0xfff, %g1 ! delay slot
  185. b ret_trap_user_stack_is_bolixed + 0x4
  186. wr %t_wim, 0x0, %wim
  187. /* See if we have to check the sanity of one page or two */
  188. 1:
  189. add %g1, 0x38, %g1
  190. sra %fp, 29, %g2
  191. add %g2, 0x1, %g2
  192. andncc %g2, 0x1, %g0
  193. be 1f
  194. andncc %g1, 0xff8, %g0
  195. /* %sp is in vma hole, yuck */
  196. b ret_trap_user_stack_is_bolixed + 0x4
  197. wr %t_wim, 0x0, %wim
  198. 1:
  199. be sun4c_rett_onepage /* Only one page to check */
  200. lda [%fp] ASI_PTE, %g2
  201. sun4c_rett_twopages:
  202. add %fp, 0x38, %g1
  203. sra %g1, 29, %g2
  204. add %g2, 0x1, %g2
  205. andncc %g2, 0x1, %g0
  206. be 1f
  207. lda [%g1] ASI_PTE, %g2
  208. /* Second page is in vma hole */
  209. b ret_trap_user_stack_is_bolixed + 0x4
  210. wr %t_wim, 0x0, %wim
  211. 1:
  212. srl %g2, 29, %g2
  213. andcc %g2, 0x4, %g0
  214. bne sun4c_rett_onepage
  215. lda [%fp] ASI_PTE, %g2
  216. /* Second page has bad perms */
  217. b ret_trap_user_stack_is_bolixed + 0x4
  218. wr %t_wim, 0x0, %wim
  219. sun4c_rett_onepage:
  220. srl %g2, 29, %g2
  221. andcc %g2, 0x4, %g0
  222. bne,a 1f
  223. restore %g0, %g0, %g0
  224. /* A page had bad page permissions, losing... */
  225. b ret_trap_user_stack_is_bolixed + 0x4
  226. wr %t_wim, 0x0, %wim
  227. /* Whee, things are ok, load the window and continue. */
  228. 1:
  229. LOAD_WINDOW(sp)
  230. b ret_trap_userwins_ok
  231. save %g0, %g0, %g0
  232. .globl srmmu_rett_stackchk
  233. srmmu_rett_stackchk:
  234. bne ret_trap_user_stack_is_bolixed
  235. sethi %hi(PAGE_OFFSET), %g1
  236. cmp %g1, %fp
  237. bleu ret_trap_user_stack_is_bolixed
  238. mov AC_M_SFSR, %g1
  239. lda [%g1] ASI_M_MMUREGS, %g0
  240. lda [%g0] ASI_M_MMUREGS, %g1
  241. or %g1, 0x2, %g1
  242. sta %g1, [%g0] ASI_M_MMUREGS
  243. restore %g0, %g0, %g0
  244. LOAD_WINDOW(sp)
  245. save %g0, %g0, %g0
  246. andn %g1, 0x2, %g1
  247. sta %g1, [%g0] ASI_M_MMUREGS
  248. mov AC_M_SFAR, %g2
  249. lda [%g2] ASI_M_MMUREGS, %g2
  250. mov AC_M_SFSR, %g1
  251. lda [%g1] ASI_M_MMUREGS, %g1
  252. andcc %g1, 0x2, %g0
  253. be ret_trap_userwins_ok
  254. nop
  255. b,a ret_trap_user_stack_is_bolixed