blob: f2556146a735c4f577afe1a96bc66e85ddf77069 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $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.
3 *
4 * Copyright (C) 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
6 */
7
8#include <linux/config.h>
9
10#include <asm/asi.h>
11#include <asm/pstate.h>
12#include <asm/ptrace.h>
13#include <asm/page.h>
14#include <asm/spitfire.h>
15#include <asm/head.h>
16#include <asm/processor.h>
17#include <asm/mmu.h>
18
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)
23
24/*
25 * On entry, %g7 is return address - 0x4.
26 * %g4 and %g5 will be preserved %l4 and %l5 respectively.
27 */
28
29 .text
30 .align 64
31 .globl etrap, etrap_irq, etraptl1
32etrap: rdpr %pil, %g2
33etrap_irq:
David S. Millerffe483d2006-02-02 21:55:10 -080034 TRAP_LOAD_THREAD_REG(%g6, %g1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 rdpr %tstate, %g1
36 sllx %g2, 20, %g3
37 andcc %g1, TSTATE_PRIV, %g0
38 or %g1, %g3, %g1
39 bne,pn %xcc, 1f
40 sub %sp, STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS, %g2
41 wrpr %g0, 7, %cleanwin
42
43 sethi %hi(TASK_REGOFF), %g2
44 sethi %hi(TSTATE_PEF), %g3
45 or %g2, %lo(TASK_REGOFF), %g2
46 and %g1, %g3, %g3
47 brnz,pn %g3, 1f
48 add %g6, %g2, %g2
49 wr %g0, 0, %fprs
501: rdpr %tpc, %g3
51
52 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
53 rdpr %tnpc, %g1
54 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
55 rd %y, %g3
56 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
57 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
David S. Miller314ef682006-02-04 00:10:01 -080058
59 rdpr %cansave, %g1
60 brnz,pt %g1, etrap_save
61 nop
62
63 rdpr %cwp, %g1
64 add %g1, 2, %g1
65 wrpr %g1, %cwp
66 be,pt %xcc, etrap_user_spill
67 mov ASI_AIUP, %g3
68
69 rdpr %otherwin, %g3
70 brz %g3, etrap_kernel_spill
71 mov ASI_AIUS, %g3
72
73etrap_user_spill:
74
75 wr %g3, 0x0, %asi
76 ldx [%g6 + TI_FLAGS], %g3
77 and %g3, _TIF_32BIT, %g3
78 brnz,pt %g3, etrap_user_spill_32bit
79 nop
80 ba,a,pt %xcc, etrap_user_spill_64bit
81
82etrap_save: save %g2, -STACK_BIAS, %sp
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 mov %g6, %l6
84
85 bne,pn %xcc, 3f
86 mov PRIMARY_CONTEXT, %l4
87 rdpr %canrestore, %g3
88 rdpr %wstate, %g2
89 wrpr %g0, 0, %canrestore
90 sll %g2, 3, %g2
91 mov 1, %l5
92 stb %l5, [%l6 + TI_FPDEPTH]
93
94 wrpr %g3, 0, %otherwin
95 wrpr %g2, 0, %wstate
David S. Miller0835ae02005-10-04 15:23:20 -070096 sethi %hi(sparc64_kern_pri_context), %g2
97 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g3
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 stxa %g3, [%l4] ASI_DMMU
David S. Miller4da808c2006-01-31 18:33:00 -080099 sethi %hi(KERNBASE), %l4
100 flush %l4
David S. Miller6e024932006-02-05 20:47:26 -0800101 mov ASI_AIUS, %l7
1022: mov %g4, %l4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 mov %g5, %l5
David S. Miller6e024932006-02-05 20:47:26 -0800104 add %g7, 4, %l2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 wrpr %g0, ETRAP_PSTATE1, %pstate
106 stx %g1, [%sp + PTREGS_OFF + PT_V9_G1]
107 stx %g2, [%sp + PTREGS_OFF + PT_V9_G2]
David S. Miller6e024932006-02-05 20:47:26 -0800108 sllx %l7, 24, %l7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 stx %g3, [%sp + PTREGS_OFF + PT_V9_G3]
David S. Miller6e024932006-02-05 20:47:26 -0800110 rdpr %cwp, %l0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 stx %g4, [%sp + PTREGS_OFF + PT_V9_G4]
112 stx %g5, [%sp + PTREGS_OFF + PT_V9_G5]
113 stx %g6, [%sp + PTREGS_OFF + PT_V9_G6]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 stx %g7, [%sp + PTREGS_OFF + PT_V9_G7]
David S. Miller6e024932006-02-05 20:47:26 -0800115 or %l7, %l0, %l7
116 sethi %hi(TSTATE_RMO | TSTATE_PEF), %l0
117 or %l7, %l0, %l7
118 wrpr %l2, %tnpc
119 wrpr %l7, (TSTATE_PRIV | TSTATE_IE), %tstate
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 stx %i0, [%sp + PTREGS_OFF + PT_V9_I0]
121 stx %i1, [%sp + PTREGS_OFF + PT_V9_I1]
122 stx %i2, [%sp + PTREGS_OFF + PT_V9_I2]
123 stx %i3, [%sp + PTREGS_OFF + PT_V9_I3]
124 stx %i4, [%sp + PTREGS_OFF + PT_V9_I4]
125 stx %i5, [%sp + PTREGS_OFF + PT_V9_I5]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 stx %i6, [%sp + PTREGS_OFF + PT_V9_I6]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 mov %l6, %g6
David S. Miller6e024932006-02-05 20:47:26 -0800128 stx %i7, [%sp + PTREGS_OFF + PT_V9_I7]
David S. Millerffe483d2006-02-02 21:55:10 -0800129 LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1)
David S. Miller6e024932006-02-05 20:47:26 -0800130 ldx [%g6 + TI_TASK], %g4
131 done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
David S. Miller6e024932006-02-05 20:47:26 -08001333: mov ASI_P, %l7
134 ldub [%l6 + TI_FPDEPTH], %l5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 add %l6, TI_FPSAVED + 1, %l4
136 srl %l5, 1, %l3
137 add %l5, 2, %l5
138 stb %l5, [%l6 + TI_FPDEPTH]
139 ba,pt %xcc, 2b
140 stb %g0, [%l4 + %l3]
141 nop
142
143etraptl1: /* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
144 * We place this right after pt_regs on the trap stack.
145 * The layout is:
146 * 0x00 TL1's TSTATE
147 * 0x08 TL1's TPC
148 * 0x10 TL1's TNPC
149 * 0x18 TL1's TT
150 * ...
151 * 0x58 TL4's TT
152 * 0x60 TL
153 */
David S. Millerffe483d2006-02-02 21:55:10 -0800154 TRAP_LOAD_THREAD_REG(%g6, %g1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 sub %sp, ((4 * 8) * 4) + 8, %g2
156 rdpr %tl, %g1
157
158 wrpr %g0, 1, %tl
159 rdpr %tstate, %g3
160 stx %g3, [%g2 + STACK_BIAS + 0x00]
161 rdpr %tpc, %g3
162 stx %g3, [%g2 + STACK_BIAS + 0x08]
163 rdpr %tnpc, %g3
164 stx %g3, [%g2 + STACK_BIAS + 0x10]
165 rdpr %tt, %g3
166 stx %g3, [%g2 + STACK_BIAS + 0x18]
167
168 wrpr %g0, 2, %tl
169 rdpr %tstate, %g3
170 stx %g3, [%g2 + STACK_BIAS + 0x20]
171 rdpr %tpc, %g3
172 stx %g3, [%g2 + STACK_BIAS + 0x28]
173 rdpr %tnpc, %g3
174 stx %g3, [%g2 + STACK_BIAS + 0x30]
175 rdpr %tt, %g3
176 stx %g3, [%g2 + STACK_BIAS + 0x38]
177
178 wrpr %g0, 3, %tl
179 rdpr %tstate, %g3
180 stx %g3, [%g2 + STACK_BIAS + 0x40]
181 rdpr %tpc, %g3
182 stx %g3, [%g2 + STACK_BIAS + 0x48]
183 rdpr %tnpc, %g3
184 stx %g3, [%g2 + STACK_BIAS + 0x50]
185 rdpr %tt, %g3
186 stx %g3, [%g2 + STACK_BIAS + 0x58]
187
188 wrpr %g0, 4, %tl
189 rdpr %tstate, %g3
190 stx %g3, [%g2 + STACK_BIAS + 0x60]
191 rdpr %tpc, %g3
192 stx %g3, [%g2 + STACK_BIAS + 0x68]
193 rdpr %tnpc, %g3
194 stx %g3, [%g2 + STACK_BIAS + 0x70]
195 rdpr %tt, %g3
196 stx %g3, [%g2 + STACK_BIAS + 0x78]
197
198 wrpr %g1, %tl
199 stx %g1, [%g2 + STACK_BIAS + 0x80]
200
201 rdpr %tstate, %g1
202 sub %g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
203 ba,pt %xcc, 1b
204 andcc %g1, TSTATE_PRIV, %g0
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#undef TASK_REGOFF
207#undef ETRAP_PSTATE1