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
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]
58 save %g2, -STACK_BIAS, %sp ! Ordering here is critical
62 mov PRIMARY_CONTEXT, %l4
65 wrpr %g0, 0, %canrestore
68 stb %l5, [%l6 + TI_FPDEPTH]
70 wrpr %g3, 0, %otherwin
72 sethi %hi(sparc64_kern_pri_context), %g2
73 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
74 stxa %g3, [%l4] ASI_DMMU
76 wr %g0, ASI_AIUS, %asi
82 wrpr %g0, ETRAP_PSTATE1, %pstate
83 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
84 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
85 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
86 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
87 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
88 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
90 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
91 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
92 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
93 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
94 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
95 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
96 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
98 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
99 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
100 wrpr %g0, ETRAP_PSTATE2, %pstate
102 LOAD_PER_CPU_BASE(%g4, %g3)
104 ldx [%g6 + TI_TASK], %g4
106 3: ldub [%l6 + TI_FPDEPTH], %l5
107 add %l6, TI_FPSAVED + 1, %l4
110 stb %l5, [%l6 + TI_FPDEPTH]
115 etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
116 * We place this right after pt_regs on the trap stack.
127 sub %sp, ((4 * 8) * 4) + 8, %g2
132 stx %g3, [%g2 + STACK_BIAS + 0x00]
134 stx %g3, [%g2 + STACK_BIAS + 0x08]
136 stx %g3, [%g2 + STACK_BIAS + 0x10]
138 stx %g3, [%g2 + STACK_BIAS + 0x18]
142 stx %g3, [%g2 + STACK_BIAS + 0x20]
144 stx %g3, [%g2 + STACK_BIAS + 0x28]
146 stx %g3, [%g2 + STACK_BIAS + 0x30]
148 stx %g3, [%g2 + STACK_BIAS + 0x38]
152 stx %g3, [%g2 + STACK_BIAS + 0x40]
154 stx %g3, [%g2 + STACK_BIAS + 0x48]
156 stx %g3, [%g2 + STACK_BIAS + 0x50]
158 stx %g3, [%g2 + STACK_BIAS + 0x58]
162 stx %g3, [%g2 + STACK_BIAS + 0x60]
164 stx %g3, [%g2 + STACK_BIAS + 0x68]
166 stx %g3, [%g2 + STACK_BIAS + 0x70]
168 stx %g3, [%g2 + STACK_BIAS + 0x78]
171 stx %g1, [%g2 + STACK_BIAS + 0x80]
174 sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
176 andcc %g1, TSTATE_PRIV, %g0
185 andcc %g1, TSTATE_PRIV, %g0
188 sub %sp, (STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS), %g2
189 wrpr %g0, 7, %cleanwin
192 sethi %hi(TASK_REGOFF), %g2
193 or %g2, %lo(TASK_REGOFF), %g2
198 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
201 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
202 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
203 save %g2, -STACK_BIAS, %sp ! Ordering here is critical
207 rdpr %canrestore, %g3
210 wrpr %g0, 0, %canrestore
212 mov PRIMARY_CONTEXT, %l4
213 wrpr %g3, 0, %otherwin
215 sethi %hi(sparc64_kern_pri_context), %g2
216 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
217 stxa %g3, [%l4] ASI_DMMU
224 wrpr %g0, ETRAP_PSTATE1, %pstate
225 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
226 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
229 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
231 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
232 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
233 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
234 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
236 sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
240 wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
241 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
242 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
243 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
244 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
245 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
247 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
248 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
250 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
251 LOAD_PER_CPU_BASE(%g4, %g3)
252 ldx [%g6 + TI_TASK], %g4