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.
4 * Copyright (C) 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
8 #include <linux/config.h>
11 #include <asm/pstate.h>
12 #include <asm/ptrace.h>
14 #include <asm/spitfire.h>
16 #include <asm/processor.h>
19 #define TASK_REGOFF (THREAD_SIZE-TRACEREG_SZ-STACKFRAME_SZ)
20 #define ETRAP_PSTATE1 (PSTATE_RMO | PSTATE_PRIV)
21 #define ETRAP_PSTATE2 \
22 (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE)
25 * On entry, %g7 is return address - 0x4.
26 * %g4 and %g5 will be preserved %l4 and %l5 respectively.
31 .globl etrap, etrap_irq, etraptl1
34 TRAP_LOAD_THREAD_REG(%g6, %g1)
37 andcc %g1, TSTATE_PRIV, %g0
40 sub %sp, STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS, %g2
41 wrpr %g0, 7, %cleanwin
43 sethi %hi(TASK_REGOFF), %g2
44 sethi %hi(TSTATE_PEF), %g3
45 or %g2, %lo(TASK_REGOFF), %g2
52 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
54 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
56 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
57 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
60 brnz,pt %g1, etrap_save
66 be,pt %xcc, etrap_user_spill
70 brz %g3, etrap_kernel_spill
76 ldx [%g6 + TI_FLAGS], %g3
77 and %g3, _TIF_32BIT, %g3
78 brnz,pt %g3, etrap_user_spill_32bit
80 ba,a,pt %xcc, etrap_user_spill_64bit
82 etrap_save: save %g2, -STACK_BIAS, %sp
86 mov PRIMARY_CONTEXT, %l4
89 wrpr %g0, 0, %canrestore
92 stb %l5, [%l6 + TI_FPDEPTH]
94 wrpr %g3, 0, %otherwin
96 sethi %hi(sparc64_kern_pri_context), %g2
97 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
99 661: stxa %g3, [%l4] ASI_DMMU
100 .section .sun4v_1insn_patch, "ax"
102 stxa %g3, [%l4] ASI_MMU
105 sethi %hi(KERNBASE), %l4
112 /* Go to trap time globals so we can save them. */
113 661: wrpr %g0, ETRAP_PSTATE1, %pstate
114 .section .sun4v_1insn_patch, "ax"
119 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
120 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
122 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
124 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
125 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
126 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
127 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
129 sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
132 wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
133 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
134 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
135 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
136 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
137 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
138 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
139 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
141 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
142 LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1)
143 ldx [%g6 + TI_TASK], %g4
147 ldub [%l6 + TI_FPDEPTH], %l5
148 add %l6, TI_FPSAVED + 1, %l4
151 stb %l5, [%l6 + TI_FPDEPTH]
156 etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
157 * We place this right after pt_regs on the trap stack.
167 TRAP_LOAD_THREAD_REG(%g6, %g1)
168 sub %sp, ((4 * 8) * 4) + 8, %g2
173 stx %g3, [%g2 + STACK_BIAS + 0x00]
175 stx %g3, [%g2 + STACK_BIAS + 0x08]
177 stx %g3, [%g2 + STACK_BIAS + 0x10]
179 stx %g3, [%g2 + STACK_BIAS + 0x18]
183 stx %g3, [%g2 + STACK_BIAS + 0x20]
185 stx %g3, [%g2 + STACK_BIAS + 0x28]
187 stx %g3, [%g2 + STACK_BIAS + 0x30]
189 stx %g3, [%g2 + STACK_BIAS + 0x38]
193 stx %g3, [%g2 + STACK_BIAS + 0x40]
195 stx %g3, [%g2 + STACK_BIAS + 0x48]
197 stx %g3, [%g2 + STACK_BIAS + 0x50]
199 stx %g3, [%g2 + STACK_BIAS + 0x58]
203 stx %g3, [%g2 + STACK_BIAS + 0x60]
205 stx %g3, [%g2 + STACK_BIAS + 0x68]
207 stx %g3, [%g2 + STACK_BIAS + 0x70]
209 stx %g3, [%g2 + STACK_BIAS + 0x78]
211 stx %g1, [%g2 + STACK_BIAS + 0x80]
215 .section .sun4v_1insn_patch, "ax"
221 sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
223 andcc %g1, TSTATE_PRIV, %g0