]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/sparc64/kernel/rtrap.S
[SPARC64]: Fix incorrect TSB lock bit handling.
[net-next-2.6.git] / arch / sparc64 / kernel / rtrap.S
CommitLineData
1da177e4
LT
1/* $Id: rtrap.S,v 1.61 2002/02/09 19:49:31 davem Exp $
2 * rtrap.S: Preparing for return from trap on Sparc V9.
3 *
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
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/spitfire.h>
14#include <asm/head.h>
15#include <asm/visasm.h>
16#include <asm/processor.h>
17
18#define RTRAP_PSTATE (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_IE)
19#define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV)
20#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG)
21
22 /* Register %l6 keeps track of whether we are returning
23 * from a system call or not. It is cleared if we call
24 * do_notify_resume, and it must not be otherwise modified
25 * until we fully commit to returning to userspace.
26 */
27
28 .text
29 .align 32
30__handle_softirq:
31 call do_softirq
32 nop
33 ba,a,pt %xcc, __handle_softirq_continue
34 nop
35__handle_preemption:
36 call schedule
37 wrpr %g0, RTRAP_PSTATE, %pstate
38 ba,pt %xcc, __handle_preemption_continue
39 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
40
41__handle_user_windows:
42 call fault_in_user_windows
43 wrpr %g0, RTRAP_PSTATE, %pstate
44 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
45 /* Redo sched+sig checks */
46 ldx [%g6 + TI_FLAGS], %l0
47 andcc %l0, _TIF_NEED_RESCHED, %g0
48
49 be,pt %xcc, 1f
50 nop
51 call schedule
52 wrpr %g0, RTRAP_PSTATE, %pstate
53 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
54 ldx [%g6 + TI_FLAGS], %l0
55
2d7d5f05 561: andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
1da177e4
LT
57 be,pt %xcc, __handle_user_windows_continue
58 nop
2d7d5f05
DM
59 mov %l5, %o1
60 mov %l6, %o2
61 add %sp, PTREGS_OFF, %o0
62 mov %l0, %o3
1da177e4
LT
63
64 call do_notify_resume
65 wrpr %g0, RTRAP_PSTATE, %pstate
66 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
67 clr %l6
68 /* Signal delivery can modify pt_regs tstate, so we must
69 * reload it.
70 */
71 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
72 sethi %hi(0xf << 20), %l4
73 and %l1, %l4, %l4
74 ba,pt %xcc, __handle_user_windows_continue
75
76 andn %l1, %l4, %l1
77__handle_perfctrs:
78 call update_perfctrs
79 wrpr %g0, RTRAP_PSTATE, %pstate
80 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
81 ldub [%g6 + TI_WSAVED], %o2
82 brz,pt %o2, 1f
83 nop
84 /* Redo userwin+sched+sig checks */
85 call fault_in_user_windows
86
87 wrpr %g0, RTRAP_PSTATE, %pstate
88 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
89 ldx [%g6 + TI_FLAGS], %l0
90 andcc %l0, _TIF_NEED_RESCHED, %g0
91 be,pt %xcc, 1f
92
93 nop
94 call schedule
95 wrpr %g0, RTRAP_PSTATE, %pstate
96 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
97 ldx [%g6 + TI_FLAGS], %l0
2d7d5f05 981: andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
1da177e4
LT
99
100 be,pt %xcc, __handle_perfctrs_continue
101 sethi %hi(TSTATE_PEF), %o0
2d7d5f05
DM
102 mov %l5, %o1
103 mov %l6, %o2
104 add %sp, PTREGS_OFF, %o0
105 mov %l0, %o3
1da177e4
LT
106 call do_notify_resume
107
108 wrpr %g0, RTRAP_PSTATE, %pstate
109 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
110 clr %l6
111 /* Signal delivery can modify pt_regs tstate, so we must
112 * reload it.
113 */
114 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
115 sethi %hi(0xf << 20), %l4
116 and %l1, %l4, %l4
117 andn %l1, %l4, %l1
118 ba,pt %xcc, __handle_perfctrs_continue
119
120 sethi %hi(TSTATE_PEF), %o0
121__handle_userfpu:
122 rd %fprs, %l5
123 andcc %l5, FPRS_FEF, %g0
124 sethi %hi(TSTATE_PEF), %o0
125 be,a,pn %icc, __handle_userfpu_continue
126 andn %l1, %o0, %l1
127 ba,a,pt %xcc, __handle_userfpu_continue
128
129__handle_signal:
2d7d5f05
DM
130 mov %l5, %o1
131 mov %l6, %o2
132 add %sp, PTREGS_OFF, %o0
133 mov %l0, %o3
1da177e4
LT
134 call do_notify_resume
135 wrpr %g0, RTRAP_PSTATE, %pstate
136 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
137 clr %l6
138
139 /* Signal delivery can modify pt_regs tstate, so we must
140 * reload it.
141 */
142 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
143 sethi %hi(0xf << 20), %l4
144 and %l1, %l4, %l4
145 ba,pt %xcc, __handle_signal_continue
146 andn %l1, %l4, %l1
147
148 .align 64
149 .globl rtrap_irq, rtrap_clr_l6, rtrap, irqsz_patchme, rtrap_xcall
150rtrap_irq:
151rtrap_clr_l6: clr %l6
152rtrap:
d7ce78fd
DM
153#ifndef CONFIG_SMP
154 sethi %hi(per_cpu____cpu_data), %l0
155 lduw [%l0 + %lo(per_cpu____cpu_data)], %l1
156#else
157 sethi %hi(per_cpu____cpu_data), %l0
158 or %l0, %lo(per_cpu____cpu_data), %l0
159 lduw [%l0 + %g5], %l1
160#endif
1da177e4
LT
161 cmp %l1, 0
162
163 /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
164 bne,pn %icc, __handle_softirq
165 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
166__handle_softirq_continue:
167rtrap_xcall:
168 sethi %hi(0xf << 20), %l4
169 andcc %l1, TSTATE_PRIV, %l3
170 and %l1, %l4, %l4
171 bne,pn %icc, to_kernel
172 andn %l1, %l4, %l1
173
174 /* We must hold IRQs off and atomically test schedule+signal
175 * state, then hold them off all the way back to userspace.
176 * If we are returning to kernel, none of this matters.
177 *
178 * If we do not do this, there is a window where we would do
179 * the tests, later the signal/resched event arrives but we do
180 * not process it since we are still in kernel mode. It would
181 * take until the next local IRQ before the signal/resched
182 * event would be handled.
183 *
184 * This also means that if we have to deal with performance
185 * counters or user windows, we have to redo all of these
186 * sched+signal checks with IRQs disabled.
187 */
188to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
189 wrpr 0, %pil
190__handle_preemption_continue:
191 ldx [%g6 + TI_FLAGS], %l0
192 sethi %hi(_TIF_USER_WORK_MASK), %o0
193 or %o0, %lo(_TIF_USER_WORK_MASK), %o0
194 andcc %l0, %o0, %g0
195 sethi %hi(TSTATE_PEF), %o0
196 be,pt %xcc, user_nowork
197 andcc %l1, %o0, %g0
198 andcc %l0, _TIF_NEED_RESCHED, %g0
199 bne,pn %xcc, __handle_preemption
2d7d5f05 200 andcc %l0, (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), %g0
1da177e4
LT
201 bne,pn %xcc, __handle_signal
202__handle_signal_continue:
203 ldub [%g6 + TI_WSAVED], %o2
204 brnz,pn %o2, __handle_user_windows
205 nop
206__handle_user_windows_continue:
207 ldx [%g6 + TI_FLAGS], %l5
208 andcc %l5, _TIF_PERFCTR, %g0
209 sethi %hi(TSTATE_PEF), %o0
210 bne,pn %xcc, __handle_perfctrs
211__handle_perfctrs_continue:
212 andcc %l1, %o0, %g0
213
214 /* This fpdepth clear is necessary for non-syscall rtraps only */
215user_nowork:
216 bne,pn %xcc, __handle_userfpu
217 stb %g0, [%g6 + TI_FPDEPTH]
218__handle_userfpu_continue:
219
220rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
221 ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
222
223 ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
224 ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
225 ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
56fb4df6
DM
226 brz,pt %l3, 1f
227 nop
228 /* Must do this before thread reg is clobbered below. */
229 LOAD_PER_CPU_BASE(%g6, %g7)
74bf4312
DM
2301:
231 ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
1da177e4
LT
232 ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
233 wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
234 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
235 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
236
237 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
238 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
239 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
240 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
241 ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
242 ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
243 ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
244 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
245
246 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
247 wr %o3, %g0, %y
248 srl %l4, 20, %l4
249 wrpr %l4, 0x0, %pil
250 wrpr %g0, 0x1, %tl
251 wrpr %l1, %g0, %tstate
252 wrpr %l2, %g0, %tpc
253 wrpr %o2, %g0, %tnpc
254
255 brnz,pn %l3, kern_rtt
256 mov PRIMARY_CONTEXT, %l7
257 ldxa [%l7 + %l7] ASI_DMMU, %l0
0835ae0f
DM
258 sethi %hi(sparc64_kern_pri_nuc_bits), %l1
259 ldx [%l1 + %lo(sparc64_kern_pri_nuc_bits)], %l1
1da177e4
LT
260 or %l0, %l1, %l0
261 stxa %l0, [%l7] ASI_DMMU
262 flush %g6
263 rdpr %wstate, %l1
264 rdpr %otherwin, %l2
265 srl %l1, 3, %l1
266
267 wrpr %l2, %g0, %canrestore
268 wrpr %l1, %g0, %wstate
269 wrpr %g0, %g0, %otherwin
270 restore
271 rdpr %canrestore, %g1
272 wrpr %g1, 0x0, %cleanwin
273 retry
274 nop
275
276kern_rtt: restore
277 retry
278to_kernel:
279#ifdef CONFIG_PREEMPT
280 ldsw [%g6 + TI_PRE_COUNT], %l5
281 brnz %l5, kern_fpucheck
282 ldx [%g6 + TI_FLAGS], %l5
283 andcc %l5, _TIF_NEED_RESCHED, %g0
284 be,pt %xcc, kern_fpucheck
285 srl %l4, 20, %l5
286 cmp %l5, 0
287 bne,pn %xcc, kern_fpucheck
288 sethi %hi(PREEMPT_ACTIVE), %l6
289 stw %l6, [%g6 + TI_PRE_COUNT]
290 call schedule
291 nop
292 ba,pt %xcc, rtrap
293 stw %g0, [%g6 + TI_PRE_COUNT]
294#endif
295kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
296 brz,pt %l5, rt_continue
297 srl %l5, 1, %o0
298 add %g6, TI_FPSAVED, %l6
299 ldub [%l6 + %o0], %l2
300 sub %l5, 2, %l5
301
302 add %g6, TI_GSR, %o1
303 andcc %l2, (FPRS_FEF|FPRS_DU), %g0
304 be,pt %icc, 2f
305 and %l2, FPRS_DL, %l6
306 andcc %l2, FPRS_FEF, %g0
307 be,pn %icc, 5f
308 sll %o0, 3, %o5
309 rd %fprs, %g1
310
311 wr %g1, FPRS_FEF, %fprs
312 ldx [%o1 + %o5], %g1
313 add %g6, TI_XFSR, %o1
1da177e4
LT
314 sll %o0, 8, %o2
315 add %g6, TI_FPREGS, %o3
316 brz,pn %l6, 1f
317 add %g6, TI_FPREGS+0x40, %o4
318
ba639933 319 membar #Sync
1da177e4
LT
320 ldda [%o3 + %o2] ASI_BLK_P, %f0
321 ldda [%o4 + %o2] ASI_BLK_P, %f16
ba639933 322 membar #Sync
1da177e4
LT
3231: andcc %l2, FPRS_DU, %g0
324 be,pn %icc, 1f
325 wr %g1, 0, %gsr
326 add %o2, 0x80, %o2
ba639933 327 membar #Sync
1da177e4
LT
328 ldda [%o3 + %o2] ASI_BLK_P, %f32
329 ldda [%o4 + %o2] ASI_BLK_P, %f48
1da177e4
LT
3301: membar #Sync
331 ldx [%o1 + %o5], %fsr
3322: stb %l5, [%g6 + TI_FPDEPTH]
333 ba,pt %xcc, rt_continue
334 nop
3355: wr %g0, FPRS_FEF, %fprs
1da177e4
LT
336 sll %o0, 8, %o2
337
338 add %g6, TI_FPREGS+0x80, %o3
339 add %g6, TI_FPREGS+0xc0, %o4
ba639933 340 membar #Sync
1da177e4
LT
341 ldda [%o3 + %o2] ASI_BLK_P, %f32
342 ldda [%o4 + %o2] ASI_BLK_P, %f48
343 membar #Sync
344 wr %g0, FPRS_DU, %fprs
345 ba,pt %xcc, rt_continue
346 stb %l5, [%g6 + TI_FPDEPTH]