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)
10 #include <asm/pstate.h>
11 #include <asm/ptrace.h>
13 #include <asm/spitfire.h>
15 #include <asm/processor.h>
18 #define TASK_REGOFF (THREAD_SIZE-TRACEREG_SZ-STACKFRAME_SZ)
19 #define ETRAP_PSTATE1 (PSTATE_RMO | PSTATE_PRIV)
20 #define ETRAP_PSTATE2 \
21 (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE)
24 * On entry, %g7 is return address - 0x4.
25 * %g4 and %g5 will be preserved %l4 and %l5 respectively.
30 .globl etrap, etrap_irq, etraptl1
33 TRAP_LOAD_THREAD_REG(%g6, %g1)
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]
57 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
58 sethi %hi(PT_REGS_MAGIC), %g3
60 st %g1, [%g2 + STACKFRAME_SZ + PT_V9_MAGIC]
63 brnz,pt %g1, etrap_save
69 be,pt %xcc, etrap_user_spill
73 brz %g3, etrap_kernel_spill
79 ldx [%g6 + TI_FLAGS], %g3
80 and %g3, _TIF_32BIT, %g3
81 brnz,pt %g3, etrap_user_spill_32bit
83 ba,a,pt %xcc, etrap_user_spill_64bit
85 etrap_save: save %g2, -STACK_BIAS, %sp
89 mov PRIMARY_CONTEXT, %l4
92 wrpr %g0, 0, %canrestore
95 stb %l5, [%l6 + TI_FPDEPTH]
97 wrpr %g3, 0, %otherwin
99 sethi %hi(sparc64_kern_pri_context), %g2
100 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
102 661: stxa %g3, [%l4] ASI_DMMU
103 .section .sun4v_1insn_patch, "ax"
105 stxa %g3, [%l4] ASI_MMU
108 sethi %hi(KERNBASE), %l4
115 /* Go to trap time globals so we can save them. */
116 661: wrpr %g0, ETRAP_PSTATE1, %pstate
117 .section .sun4v_1insn_patch, "ax"
122 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
123 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
125 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
127 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
128 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
129 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
130 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
132 sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
135 wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
136 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
137 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
138 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
139 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
140 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
141 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
142 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
144 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
145 LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1)
146 ldx [%g6 + TI_TASK], %g4
150 ldub [%l6 + TI_FPDEPTH], %l5
151 add %l6, TI_FPSAVED + 1, %l4
154 stb %l5, [%l6 + TI_FPDEPTH]
159 etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
160 * We place this right after pt_regs on the trap stack.
170 TRAP_LOAD_THREAD_REG(%g6, %g1)
171 sub %sp, ((4 * 8) * 4) + 8, %g2
176 stx %g3, [%g2 + STACK_BIAS + 0x00]
178 stx %g3, [%g2 + STACK_BIAS + 0x08]
180 stx %g3, [%g2 + STACK_BIAS + 0x10]
182 stx %g3, [%g2 + STACK_BIAS + 0x18]
186 stx %g3, [%g2 + STACK_BIAS + 0x20]
188 stx %g3, [%g2 + STACK_BIAS + 0x28]
190 stx %g3, [%g2 + STACK_BIAS + 0x30]
192 stx %g3, [%g2 + STACK_BIAS + 0x38]
194 sethi %hi(is_sun4v), %g3
195 lduw [%g3 + %lo(is_sun4v)], %g3
196 brnz,pn %g3, finish_tl1_capture
201 stx %g3, [%g2 + STACK_BIAS + 0x40]
203 stx %g3, [%g2 + STACK_BIAS + 0x48]
205 stx %g3, [%g2 + STACK_BIAS + 0x50]
207 stx %g3, [%g2 + STACK_BIAS + 0x58]
211 stx %g3, [%g2 + STACK_BIAS + 0x60]
213 stx %g3, [%g2 + STACK_BIAS + 0x68]
215 stx %g3, [%g2 + STACK_BIAS + 0x70]
217 stx %g3, [%g2 + STACK_BIAS + 0x78]
219 stx %g1, [%g2 + STACK_BIAS + 0x80]
224 .section .sun4v_1insn_patch, "ax"
230 sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
232 andcc %g1, TSTATE_PRIV, %g0