etrap_64.S 5.5 KB

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