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
77 stxa %g3, [%l4] ASI_DMMU
79 wr %g0, ASI_AIUS, %asi
85 wrpr %g0, ETRAP_PSTATE1, %pstate
86 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
87 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
88 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
89 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
90 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
91 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
93 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
94 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
95 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
96 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
97 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
98 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
99 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
101 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
102 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
103 wrpr %g0, ETRAP_PSTATE2, %pstate
107 ldxa [%g3] ASI_IMMU, %g5
110 ldx [%g6 + TI_TASK], %g4
112 3: ldub [%l6 + TI_FPDEPTH], %l5
113 add %l6, TI_FPSAVED + 1, %l4
116 stb %l5, [%l6 + TI_FPDEPTH]
121 etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
122 * We place this right after pt_regs on the trap stack.
132 sub %sp, ((4 * 8) * 4) + 8, %g2
137 stx %g3, [%g2 + STACK_BIAS + 0x00]
139 stx %g3, [%g2 + STACK_BIAS + 0x08]
141 stx %g3, [%g2 + STACK_BIAS + 0x10]
143 stx %g3, [%g2 + STACK_BIAS + 0x18]
147 stx %g3, [%g2 + STACK_BIAS + 0x20]
149 stx %g3, [%g2 + STACK_BIAS + 0x28]
151 stx %g3, [%g2 + STACK_BIAS + 0x30]
153 stx %g3, [%g2 + STACK_BIAS + 0x38]
157 stx %g3, [%g2 + STACK_BIAS + 0x40]
159 stx %g3, [%g2 + STACK_BIAS + 0x48]
161 stx %g3, [%g2 + STACK_BIAS + 0x50]
163 stx %g3, [%g2 + STACK_BIAS + 0x58]
167 stx %g3, [%g2 + STACK_BIAS + 0x60]
169 stx %g3, [%g2 + STACK_BIAS + 0x68]
171 stx %g3, [%g2 + STACK_BIAS + 0x70]
173 stx %g3, [%g2 + STACK_BIAS + 0x78]
176 stx %g1, [%g2 + STACK_BIAS + 0x80]
179 sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
181 andcc %g1, TSTATE_PRIV, %g0
185 scetrap: rdpr %pil, %g2
188 andcc %g1, TSTATE_PRIV, %g0
191 sub %sp, (STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS), %g2
192 wrpr %g0, 7, %cleanwin
195 sethi %hi(TASK_REGOFF), %g2
196 or %g2, %lo(TASK_REGOFF), %g2
201 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
204 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
205 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
206 save %g2, -STACK_BIAS, %sp ! Ordering here is critical
210 rdpr %canrestore, %g3
213 wrpr %g0, 0, %canrestore
215 mov PRIMARY_CONTEXT, %l4
216 wrpr %g3, 0, %otherwin
224 stxa %g3, [%l4] ASI_DMMU
231 wrpr %g0, ETRAP_PSTATE1, %pstate
232 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
233 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
236 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
238 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
239 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
240 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
241 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
243 sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
247 wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
248 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
249 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
250 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
251 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
252 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
254 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
255 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
257 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
260 ldxa [%g3] ASI_IMMU, %g5
262 ldx [%g6 + TI_TASK], %g4
269 sethi %uhi(CTX_CHEETAH_PLUS_NUC), %g3
271 sethi %hi(CTX_CHEETAH_PLUS_CTX0), %g2
273 .globl cheetah_plus_patch_etrap
274 cheetah_plus_patch_etrap:
275 /* We configure the dTLB512_0 for 4MB pages and the
276 * dTLB512_1 for 8K pages when in context zero.
278 sethi %hi(cplus_einsn_1), %o0
279 sethi %hi(cplus_etrap_insn_1), %o2
280 lduw [%o0 + %lo(cplus_einsn_1)], %o1
281 or %o2, %lo(cplus_etrap_insn_1), %o2
284 sethi %hi(cplus_etrap_insn_3), %o2
285 or %o2, %lo(cplus_etrap_insn_3), %o2
289 sethi %hi(cplus_einsn_2), %o0
290 sethi %hi(cplus_etrap_insn_2), %o2
291 lduw [%o0 + %lo(cplus_einsn_2)], %o1
292 or %o2, %lo(cplus_etrap_insn_2), %o2
295 sethi %hi(cplus_etrap_insn_4), %o2
296 or %o2, %lo(cplus_etrap_insn_4), %o2