etrap.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* $Id: etrap.S,v 1.46 2002/02/09 19:49:30 davem Exp $
  2. * etrap.S: Preparing for entry into the kernel on Sparc V9.
  3. *
  4. * Copyright (C) 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
  6. */
  7. #include <asm/asi.h>
  8. #include <asm/pstate.h>
  9. #include <asm/ptrace.h>
  10. #include <asm/page.h>
  11. #include <asm/spitfire.h>
  12. #include <asm/head.h>
  13. #include <asm/processor.h>
  14. #include <asm/mmu.h>
  15. #define TASK_REGOFF (THREAD_SIZE-TRACEREG_SZ-STACKFRAME_SZ)
  16. #define ETRAP_PSTATE1 (PSTATE_RMO | PSTATE_PRIV)
  17. #define ETRAP_PSTATE2 \
  18. (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE)
  19. /*
  20. * On entry, %g7 is return address - 0x4.
  21. * %g4 and %g5 will be preserved %l4 and %l5 respectively.
  22. */
  23. .text
  24. .align 64
  25. .globl etrap, etrap_irq, etraptl1
  26. etrap: rdpr %pil, %g2
  27. etrap_irq:
  28. TRAP_LOAD_THREAD_REG(%g6, %g1)
  29. rdpr %tstate, %g1
  30. sllx %g2, 20, %g3
  31. andcc %g1, TSTATE_PRIV, %g0
  32. or %g1, %g3, %g1
  33. bne,pn %xcc, 1f
  34. sub %sp, STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS, %g2
  35. wrpr %g0, 7, %cleanwin
  36. sethi %hi(TASK_REGOFF), %g2
  37. sethi %hi(TSTATE_PEF), %g3
  38. or %g2, %lo(TASK_REGOFF), %g2
  39. and %g1, %g3, %g3
  40. brnz,pn %g3, 1f
  41. add %g6, %g2, %g2
  42. wr %g0, 0, %fprs
  43. 1: rdpr %tpc, %g3
  44. stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
  45. rdpr %tnpc, %g1
  46. stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
  47. rd %y, %g3
  48. stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
  49. rdpr %tt, %g1
  50. st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
  51. sethi %hi(PT_REGS_MAGIC), %g3
  52. or %g3, %g1, %g1
  53. st %g1, [%g2 + STACKFRAME_SZ + PT_V9_MAGIC]
  54. rdpr %cansave, %g1
  55. brnz,pt %g1, etrap_save
  56. nop
  57. rdpr %cwp, %g1
  58. add %g1, 2, %g1
  59. wrpr %g1, %cwp
  60. be,pt %xcc, etrap_user_spill
  61. mov ASI_AIUP, %g3
  62. rdpr %otherwin, %g3
  63. brz %g3, etrap_kernel_spill
  64. mov ASI_AIUS, %g3
  65. etrap_user_spill:
  66. wr %g3, 0x0, %asi
  67. ldx [%g6 + TI_FLAGS], %g3
  68. and %g3, _TIF_32BIT, %g3
  69. brnz,pt %g3, etrap_user_spill_32bit
  70. nop
  71. ba,a,pt %xcc, etrap_user_spill_64bit
  72. etrap_save: save %g2, -STACK_BIAS, %sp
  73. mov %g6, %l6
  74. bne,pn %xcc, 3f
  75. mov PRIMARY_CONTEXT, %l4
  76. rdpr %canrestore, %g3
  77. rdpr %wstate, %g2
  78. wrpr %g0, 0, %canrestore
  79. sll %g2, 3, %g2
  80. mov 1, %l5
  81. stb %l5, [%l6 + TI_FPDEPTH]
  82. wrpr %g3, 0, %otherwin
  83. wrpr %g2, 0, %wstate
  84. sethi %hi(sparc64_kern_pri_context), %g2
  85. ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
  86. 661: stxa %g3, [%l4] ASI_DMMU
  87. .section .sun4v_1insn_patch, "ax"
  88. .word 661b
  89. stxa %g3, [%l4] ASI_MMU
  90. .previous
  91. sethi %hi(KERNBASE), %l4
  92. flush %l4
  93. mov ASI_AIUS, %l7
  94. 2: mov %g4, %l4
  95. mov %g5, %l5
  96. add %g7, 4, %l2
  97. /* Go to trap time globals so we can save them. */
  98. 661: wrpr %g0, ETRAP_PSTATE1, %pstate
  99. .section .sun4v_1insn_patch, "ax"
  100. .word 661b
  101. SET_GL(0)
  102. .previous
  103. stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
  104. stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
  105. sllx %l7, 24, %l7
  106. stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
  107. rdpr %cwp, %l0
  108. stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
  109. stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
  110. stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
  111. stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
  112. or %l7, %l0, %l7
  113. sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
  114. or %l7, %l0, %l7
  115. wrpr %l2, %tnpc
  116. wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
  117. stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
  118. stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
  119. stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
  120. stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
  121. stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
  122. stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
  123. stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
  124. mov %l6, %g6
  125. stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
  126. LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1)
  127. ldx [%g6 + TI_TASK], %g4
  128. done
  129. 3: mov ASI_P, %l7
  130. ldub [%l6 + TI_FPDEPTH], %l5
  131. add %l6, TI_FPSAVED + 1, %l4
  132. srl %l5, 1, %l3
  133. add %l5, 2, %l5
  134. stb %l5, [%l6 + TI_FPDEPTH]
  135. ba,pt %xcc, 2b
  136. stb %g0, [%l4 + %l3]
  137. nop
  138. etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
  139. * We place this right after pt_regs on the trap stack.
  140. * The layout is:
  141. * 0x00 TL1's TSTATE
  142. * 0x08 TL1's TPC
  143. * 0x10 TL1's TNPC
  144. * 0x18 TL1's TT
  145. * ...
  146. * 0x58 TL4's TT
  147. * 0x60 TL
  148. */
  149. TRAP_LOAD_THREAD_REG(%g6, %g1)
  150. sub %sp, ((4 * 8) * 4) + 8, %g2
  151. rdpr %tl, %g1
  152. wrpr %g0, 1, %tl
  153. rdpr %tstate, %g3
  154. stx %g3, [%g2 + STACK_BIAS + 0x00]
  155. rdpr %tpc, %g3
  156. stx %g3, [%g2 + STACK_BIAS + 0x08]
  157. rdpr %tnpc, %g3
  158. stx %g3, [%g2 + STACK_BIAS + 0x10]
  159. rdpr %tt, %g3
  160. stx %g3, [%g2 + STACK_BIAS + 0x18]
  161. wrpr %g0, 2, %tl
  162. rdpr %tstate, %g3
  163. stx %g3, [%g2 + STACK_BIAS + 0x20]
  164. rdpr %tpc, %g3
  165. stx %g3, [%g2 + STACK_BIAS + 0x28]
  166. rdpr %tnpc, %g3
  167. stx %g3, [%g2 + STACK_BIAS + 0x30]
  168. rdpr %tt, %g3
  169. stx %g3, [%g2 + STACK_BIAS + 0x38]
  170. sethi %hi(is_sun4v), %g3
  171. lduw [%g3 + %lo(is_sun4v)], %g3
  172. brnz,pn %g3, finish_tl1_capture
  173. nop
  174. wrpr %g0, 3, %tl
  175. rdpr %tstate, %g3
  176. stx %g3, [%g2 + STACK_BIAS + 0x40]
  177. rdpr %tpc, %g3
  178. stx %g3, [%g2 + STACK_BIAS + 0x48]
  179. rdpr %tnpc, %g3
  180. stx %g3, [%g2 + STACK_BIAS + 0x50]
  181. rdpr %tt, %g3
  182. stx %g3, [%g2 + STACK_BIAS + 0x58]
  183. wrpr %g0, 4, %tl
  184. rdpr %tstate, %g3
  185. stx %g3, [%g2 + STACK_BIAS + 0x60]
  186. rdpr %tpc, %g3
  187. stx %g3, [%g2 + STACK_BIAS + 0x68]
  188. rdpr %tnpc, %g3
  189. stx %g3, [%g2 + STACK_BIAS + 0x70]
  190. rdpr %tt, %g3
  191. stx %g3, [%g2 + STACK_BIAS + 0x78]
  192. stx %g1, [%g2 + STACK_BIAS + 0x80]
  193. finish_tl1_capture:
  194. wrpr %g0, 1, %tl
  195. 661: nop
  196. .section .sun4v_1insn_patch, "ax"
  197. .word 661b
  198. SET_GL(1)
  199. .previous
  200. rdpr %tstate, %g1
  201. sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
  202. ba,pt %xcc, 1b
  203. andcc %g1, TSTATE_PRIV, %g0
  204. #undef TASK_REGOFF
  205. #undef ETRAP_PSTATE1