rtrap_32.S 5.6 KB

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