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
36 andcc %g1, TSTATE_PRIV, %g0
39 sub %sp, STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS, %g2
40 wrpr %g0, 7, %cleanwin
42 sethi %hi(TASK_REGOFF), %g2
43 sethi %hi(TSTATE_PEF), %g3
44 or %g2, %lo(TASK_REGOFF), %g2
51 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
53 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
55 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
56 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
57 save %g2, -STACK_BIAS, %sp ! Ordering here is critical
61 mov PRIMARY_CONTEXT, %l4
64 wrpr %g0, 0, %canrestore
67 stb %l5, [%l6 + TI_FPDEPTH]
69 wrpr %g3, 0, %otherwin
71 sethi %hi(sparc64_kern_pri_context), %g2
72 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
73 stxa %g3, [%l4] ASI_DMMU
75 wr %g0, ASI_AIUS, %asi
81 wrpr %g0, ETRAP_PSTATE1, %pstate
82 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
83 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
84 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
85 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
86 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
87 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
89 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
90 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
91 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
92 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
93 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
94 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
95 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
97 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
98 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
99 wrpr %g0, ETRAP_PSTATE2, %pstate
103 ldxa [%g3] ASI_IMMU, %g5
106 ldx [%g6 + TI_TASK], %g4
108 3: ldub [%l6 + TI_FPDEPTH], %l5
109 add %l6, TI_FPSAVED + 1, %l4
112 stb %l5, [%l6 + TI_FPDEPTH]
117 etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
118 * We place this right after pt_regs on the trap stack.
128 sub %sp, ((4 * 8) * 4) + 8, %g2
133 stx %g3, [%g2 + STACK_BIAS + 0x00]
135 stx %g3, [%g2 + STACK_BIAS + 0x08]
137 stx %g3, [%g2 + STACK_BIAS + 0x10]
139 stx %g3, [%g2 + STACK_BIAS + 0x18]
143 stx %g3, [%g2 + STACK_BIAS + 0x20]
145 stx %g3, [%g2 + STACK_BIAS + 0x28]
147 stx %g3, [%g2 + STACK_BIAS + 0x30]
149 stx %g3, [%g2 + STACK_BIAS + 0x38]
153 stx %g3, [%g2 + STACK_BIAS + 0x40]
155 stx %g3, [%g2 + STACK_BIAS + 0x48]
157 stx %g3, [%g2 + STACK_BIAS + 0x50]
159 stx %g3, [%g2 + STACK_BIAS + 0x58]
163 stx %g3, [%g2 + STACK_BIAS + 0x60]
165 stx %g3, [%g2 + STACK_BIAS + 0x68]
167 stx %g3, [%g2 + STACK_BIAS + 0x70]
169 stx %g3, [%g2 + STACK_BIAS + 0x78]
172 stx %g1, [%g2 + STACK_BIAS + 0x80]
175 sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
177 andcc %g1, TSTATE_PRIV, %g0
181 scetrap: rdpr %pil, %g2
184 andcc %g1, TSTATE_PRIV, %g0
187 sub %sp, (STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS), %g2
188 wrpr %g0, 7, %cleanwin
191 sethi %hi(TASK_REGOFF), %g2
192 or %g2, %lo(TASK_REGOFF), %g2
197 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
200 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
201 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
202 save %g2, -STACK_BIAS, %sp ! Ordering here is critical
206 rdpr %canrestore, %g3
209 wrpr %g0, 0, %canrestore
211 mov PRIMARY_CONTEXT, %l4
212 wrpr %g3, 0, %otherwin
214 sethi %hi(sparc64_kern_pri_context), %g2
215 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
216 stxa %g3, [%l4] ASI_DMMU
223 wrpr %g0, ETRAP_PSTATE1, %pstate
224 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
225 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
228 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
230 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
231 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
232 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
233 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
235 sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
239 wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
240 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
241 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
242 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
243 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
244 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
246 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
247 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
249 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
252 ldxa [%g3] ASI_IMMU, %g5
254 ldx [%g6 + TI_TASK], %g4