etrap_64.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. /* Set TI_SYS_FPDEPTH to 1 and clear TI_SYS_NOERROR. */
  82. mov 1, %l5
  83. sth %l5, [%l6 + TI_SYS_NOERROR]
  84. wrpr %g3, 0, %otherwin
  85. wrpr %g2, 0, %wstate
  86. sethi %hi(sparc64_kern_pri_context), %g2
  87. ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
  88. 661: stxa %g3, [%l4] ASI_DMMU
  89. .section .sun4v_1insn_patch, "ax"
  90. .word 661b
  91. stxa %g3, [%l4] ASI_MMU
  92. .previous
  93. sethi %hi(KERNBASE), %l4
  94. flush %l4
  95. mov ASI_AIUS, %l7
  96. 2: mov %g4, %l4
  97. mov %g5, %l5
  98. add %g7, 4, %l2
  99. /* Go to trap time globals so we can save them. */
  100. 661: wrpr %g0, ETRAP_PSTATE1, %pstate
  101. .section .sun4v_1insn_patch, "ax"
  102. .word 661b
  103. SET_GL(0)
  104. .previous
  105. stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
  106. stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
  107. sllx %l7, 24, %l7
  108. stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
  109. rdpr %cwp, %l0
  110. stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
  111. stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
  112. stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
  113. stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
  114. or %l7, %l0, %l7
  115. sethi %hi(TSTATE_TSO | TSTATE_PEF), %l0
  116. or %l7, %l0, %l7
  117. wrpr %l2, %tnpc
  118. wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
  119. stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
  120. stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
  121. stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
  122. stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
  123. stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
  124. stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
  125. stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
  126. mov %l6, %g6
  127. stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
  128. LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1)
  129. ldx [%g6 + TI_TASK], %g4
  130. done
  131. 3: mov ASI_P, %l7
  132. ldub [%l6 + TI_FPDEPTH], %l5
  133. add %l6, TI_FPSAVED + 1, %l4
  134. srl %l5, 1, %l3
  135. add %l5, 2, %l5
  136. /* Set TI_SYS_FPDEPTH to %l5 and clear TI_SYS_NOERROR. */
  137. sth %l5, [%l6 + TI_SYS_NOERROR]
  138. ba,pt %xcc, 2b
  139. stb %g0, [%l4 + %l3]
  140. nop
  141. etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
  142. * We place this right after pt_regs on the trap stack.
  143. * The layout is:
  144. * 0x00 TL1's TSTATE
  145. * 0x08 TL1's TPC
  146. * 0x10 TL1's TNPC
  147. * 0x18 TL1's TT
  148. * ...
  149. * 0x58 TL4's TT
  150. * 0x60 TL
  151. */
  152. TRAP_LOAD_THREAD_REG(%g6, %g1)
  153. sub %sp, ((4 * 8) * 4) + 8, %g2
  154. rdpr %tl, %g1
  155. wrpr %g0, 1, %tl
  156. rdpr %tstate, %g3
  157. stx %g3, [%g2 + STACK_BIAS + 0x00]
  158. rdpr %tpc, %g3
  159. stx %g3, [%g2 + STACK_BIAS + 0x08]
  160. rdpr %tnpc, %g3
  161. stx %g3, [%g2 + STACK_BIAS + 0x10]
  162. rdpr %tt, %g3
  163. stx %g3, [%g2 + STACK_BIAS + 0x18]
  164. wrpr %g0, 2, %tl
  165. rdpr %tstate, %g3
  166. stx %g3, [%g2 + STACK_BIAS + 0x20]
  167. rdpr %tpc, %g3
  168. stx %g3, [%g2 + STACK_BIAS + 0x28]
  169. rdpr %tnpc, %g3
  170. stx %g3, [%g2 + STACK_BIAS + 0x30]
  171. rdpr %tt, %g3
  172. stx %g3, [%g2 + STACK_BIAS + 0x38]
  173. sethi %hi(is_sun4v), %g3
  174. lduw [%g3 + %lo(is_sun4v)], %g3
  175. brnz,pn %g3, finish_tl1_capture
  176. nop
  177. wrpr %g0, 3, %tl
  178. rdpr %tstate, %g3
  179. stx %g3, [%g2 + STACK_BIAS + 0x40]
  180. rdpr %tpc, %g3
  181. stx %g3, [%g2 + STACK_BIAS + 0x48]
  182. rdpr %tnpc, %g3
  183. stx %g3, [%g2 + STACK_BIAS + 0x50]
  184. rdpr %tt, %g3
  185. stx %g3, [%g2 + STACK_BIAS + 0x58]
  186. wrpr %g0, 4, %tl
  187. rdpr %tstate, %g3
  188. stx %g3, [%g2 + STACK_BIAS + 0x60]
  189. rdpr %tpc, %g3
  190. stx %g3, [%g2 + STACK_BIAS + 0x68]
  191. rdpr %tnpc, %g3
  192. stx %g3, [%g2 + STACK_BIAS + 0x70]
  193. rdpr %tt, %g3
  194. stx %g3, [%g2 + STACK_BIAS + 0x78]
  195. stx %g1, [%g2 + STACK_BIAS + 0x80]
  196. finish_tl1_capture:
  197. wrpr %g0, 1, %tl
  198. 661: nop
  199. .section .sun4v_1insn_patch, "ax"
  200. .word 661b
  201. SET_GL(1)
  202. .previous
  203. rdpr %tstate, %g1
  204. sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
  205. ba,pt %xcc, 1b
  206. andcc %g1, TSTATE_PRIV, %g0
  207. #undef TASK_REGOFF
  208. #undef ETRAP_PSTATE1