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.
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
8 #include <linux/config.h>
11 #include <asm/pstate.h>
12 #include <asm/ptrace.h>
13 #include <asm/spitfire.h>
15 #include <asm/visasm.h>
16 #include <asm/processor.h>
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)
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.
33 ba,a,pt %xcc, __handle_softirq_continue
37 wrpr %g0, RTRAP_PSTATE, %pstate
38 ba,pt %xcc, __handle_preemption_continue
39 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
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
52 wrpr %g0, RTRAP_PSTATE, %pstate
53 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
54 ldx [%g6 + TI_FLAGS], %l0
56 1: andcc %l0, (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING), %g0
57 be,pt %xcc, __handle_user_windows_continue
62 add %sp, PTREGS_OFF, %o1
66 wrpr %g0, RTRAP_PSTATE, %pstate
67 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
69 /* Signal delivery can modify pt_regs tstate, so we must
72 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
73 sethi %hi(0xf << 20), %l4
75 ba,pt %xcc, __handle_user_windows_continue
80 wrpr %g0, RTRAP_PSTATE, %pstate
81 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
82 ldub [%g6 + TI_WSAVED], %o2
85 /* Redo userwin+sched+sig checks */
86 call fault_in_user_windows
88 wrpr %g0, RTRAP_PSTATE, %pstate
89 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
90 ldx [%g6 + TI_FLAGS], %l0
91 andcc %l0, _TIF_NEED_RESCHED, %g0
96 wrpr %g0, RTRAP_PSTATE, %pstate
97 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
98 ldx [%g6 + TI_FLAGS], %l0
99 1: andcc %l0, (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING), %g0
101 be,pt %xcc, __handle_perfctrs_continue
102 sethi %hi(TSTATE_PEF), %o0
106 add %sp, PTREGS_OFF, %o1
108 call do_notify_resume
110 wrpr %g0, RTRAP_PSTATE, %pstate
111 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
113 /* Signal delivery can modify pt_regs tstate, so we must
116 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
117 sethi %hi(0xf << 20), %l4
120 ba,pt %xcc, __handle_perfctrs_continue
122 sethi %hi(TSTATE_PEF), %o0
125 andcc %l5, FPRS_FEF, %g0
126 sethi %hi(TSTATE_PEF), %o0
127 be,a,pn %icc, __handle_userfpu_continue
129 ba,a,pt %xcc, __handle_userfpu_continue
135 add %sp, PTREGS_OFF, %o1
137 call do_notify_resume
138 wrpr %g0, RTRAP_PSTATE, %pstate
139 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
142 /* Signal delivery can modify pt_regs tstate, so we must
145 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
146 sethi %hi(0xf << 20), %l4
148 ba,pt %xcc, __handle_signal_continue
152 .globl rtrap_irq, rtrap_clr_l6, rtrap, irqsz_patchme, rtrap_xcall
154 rtrap_clr_l6: clr %l6
157 sethi %hi(per_cpu____cpu_data), %l0
158 lduw [%l0 + %lo(per_cpu____cpu_data)], %l1
160 sethi %hi(per_cpu____cpu_data), %l0
161 or %l0, %lo(per_cpu____cpu_data), %l0
162 lduw [%l0 + %g5], %l1
166 /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
167 bne,pn %icc, __handle_softirq
168 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
169 __handle_softirq_continue:
171 sethi %hi(0xf << 20), %l4
172 andcc %l1, TSTATE_PRIV, %l3
174 bne,pn %icc, to_kernel
177 /* We must hold IRQs off and atomically test schedule+signal
178 * state, then hold them off all the way back to userspace.
179 * If we are returning to kernel, none of this matters.
181 * If we do not do this, there is a window where we would do
182 * the tests, later the signal/resched event arrives but we do
183 * not process it since we are still in kernel mode. It would
184 * take until the next local IRQ before the signal/resched
185 * event would be handled.
187 * This also means that if we have to deal with performance
188 * counters or user windows, we have to redo all of these
189 * sched+signal checks with IRQs disabled.
191 to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
193 __handle_preemption_continue:
194 ldx [%g6 + TI_FLAGS], %l0
195 sethi %hi(_TIF_USER_WORK_MASK), %o0
196 or %o0, %lo(_TIF_USER_WORK_MASK), %o0
198 sethi %hi(TSTATE_PEF), %o0
199 be,pt %xcc, user_nowork
201 andcc %l0, _TIF_NEED_RESCHED, %g0
202 bne,pn %xcc, __handle_preemption
203 andcc %l0, (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING), %g0
204 bne,pn %xcc, __handle_signal
205 __handle_signal_continue:
206 ldub [%g6 + TI_WSAVED], %o2
207 brnz,pn %o2, __handle_user_windows
209 __handle_user_windows_continue:
210 ldx [%g6 + TI_FLAGS], %l5
211 andcc %l5, _TIF_PERFCTR, %g0
212 sethi %hi(TSTATE_PEF), %o0
213 bne,pn %xcc, __handle_perfctrs
214 __handle_perfctrs_continue:
217 /* This fpdepth clear is necessary for non-syscall rtraps only */
219 bne,pn %xcc, __handle_userfpu
220 stb %g0, [%g6 + TI_FPDEPTH]
221 __handle_userfpu_continue:
223 rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
224 ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
226 ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
227 ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
228 ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
231 ldxa [%g6] ASI_IMMU, %g5
232 1: ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
233 ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
234 wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
235 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
236 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
238 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
239 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
240 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
241 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
242 ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
243 ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
244 ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
245 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
247 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
252 wrpr %l1, %g0, %tstate
256 brnz,pn %l3, kern_rtt
257 mov PRIMARY_CONTEXT, %l7
258 ldxa [%l7 + %l7] ASI_DMMU, %l0
263 stxa %l0, [%l7] ASI_DMMU
269 wrpr %l2, %g0, %canrestore
270 wrpr %l1, %g0, %wstate
271 wrpr %g0, %g0, %otherwin
273 rdpr %canrestore, %g1
274 wrpr %g1, 0x0, %cleanwin
281 #ifdef CONFIG_PREEMPT
282 ldsw [%g6 + TI_PRE_COUNT], %l5
283 brnz %l5, kern_fpucheck
284 ldx [%g6 + TI_FLAGS], %l5
285 andcc %l5, _TIF_NEED_RESCHED, %g0
286 be,pt %xcc, kern_fpucheck
289 bne,pn %xcc, kern_fpucheck
290 sethi %hi(PREEMPT_ACTIVE), %l6
291 stw %l6, [%g6 + TI_PRE_COUNT]
295 stw %g0, [%g6 + TI_PRE_COUNT]
297 kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
298 brz,pt %l5, rt_continue
300 add %g6, TI_FPSAVED, %l6
301 ldub [%l6 + %o0], %l2
305 andcc %l2, (FPRS_FEF|FPRS_DU), %g0
307 and %l2, FPRS_DL, %l6
308 andcc %l2, FPRS_FEF, %g0
313 wr %g1, FPRS_FEF, %fprs
315 add %g6, TI_XFSR, %o1
316 membar #StoreLoad | #LoadLoad
318 add %g6, TI_FPREGS, %o3
320 add %g6, TI_FPREGS+0x40, %o4
322 ldda [%o3 + %o2] ASI_BLK_P, %f0
323 ldda [%o4 + %o2] ASI_BLK_P, %f16
324 1: andcc %l2, FPRS_DU, %g0
328 ldda [%o3 + %o2] ASI_BLK_P, %f32
329 ldda [%o4 + %o2] ASI_BLK_P, %f48
332 ldx [%o1 + %o5], %fsr
333 2: stb %l5, [%g6 + TI_FPDEPTH]
334 ba,pt %xcc, rt_continue
336 5: wr %g0, FPRS_FEF, %fprs
337 membar #StoreLoad | #LoadLoad
340 add %g6, TI_FPREGS+0x80, %o3
341 add %g6, TI_FPREGS+0xc0, %o4
342 ldda [%o3 + %o2] ASI_BLK_P, %f32
343 ldda [%o4 + %o2] ASI_BLK_P, %f48
345 wr %g0, FPRS_DU, %fprs
346 ba,pt %xcc, rt_continue
347 stb %l5, [%g6 + TI_FPDEPTH]
350 sethi %uhi(CTX_CHEETAH_PLUS_NUC), %l1
352 .globl cheetah_plus_patch_rtrap
353 cheetah_plus_patch_rtrap:
354 /* We configure the dTLB512_0 for 4MB pages and the
355 * dTLB512_1 for 8K pages when in context zero.
357 sethi %hi(cplus_rinsn_1), %o0
358 sethi %hi(cplus_rtrap_insn_1), %o2
359 lduw [%o0 + %lo(cplus_rinsn_1)], %o1
360 or %o2, %lo(cplus_rtrap_insn_1), %o2