sparc64: Make %pil level 15 a pseudo-NMI.
[deliverable/linux.git] / arch / sparc64 / kernel / rtrap.S
CommitLineData
b00dc837 1/*
1da177e4
LT
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
1da177e4
LT
8
9#include <asm/asi.h>
10#include <asm/pstate.h>
11#include <asm/ptrace.h>
12#include <asm/spitfire.h>
13#include <asm/head.h>
14#include <asm/visasm.h>
15#include <asm/processor.h>
16
64f2dde3
DM
17#define RTRAP_PSTATE (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV|PSTATE_IE)
18#define RTRAP_PSTATE_IRQOFF (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV)
19#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_TSO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG)
1da177e4 20
1da177e4
LT
21 .text
22 .align 32
23__handle_softirq:
24 call do_softirq
25 nop
26 ba,a,pt %xcc, __handle_softirq_continue
27 nop
28__handle_preemption:
29 call schedule
30 wrpr %g0, RTRAP_PSTATE, %pstate
31 ba,pt %xcc, __handle_preemption_continue
32 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
33
34__handle_user_windows:
35 call fault_in_user_windows
36 wrpr %g0, RTRAP_PSTATE, %pstate
37 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
38 /* Redo sched+sig checks */
39 ldx [%g6 + TI_FLAGS], %l0
40 andcc %l0, _TIF_NEED_RESCHED, %g0
41
42 be,pt %xcc, 1f
43 nop
44 call schedule
45 wrpr %g0, RTRAP_PSTATE, %pstate
46 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
47 ldx [%g6 + TI_FLAGS], %l0
48
e35a8925 491: andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
1da177e4
LT
50 be,pt %xcc, __handle_user_windows_continue
51 nop
2d7d5f05 52 mov %l5, %o1
2d7d5f05 53 add %sp, PTREGS_OFF, %o0
7697daaa 54 mov %l0, %o2
1da177e4
LT
55
56 call do_notify_resume
57 wrpr %g0, RTRAP_PSTATE, %pstate
58 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
1da177e4
LT
59 /* Signal delivery can modify pt_regs tstate, so we must
60 * reload it.
61 */
62 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
63 sethi %hi(0xf << 20), %l4
64 and %l1, %l4, %l4
65 ba,pt %xcc, __handle_user_windows_continue
66
67 andn %l1, %l4, %l1
68__handle_perfctrs:
69 call update_perfctrs
70 wrpr %g0, RTRAP_PSTATE, %pstate
71 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
72 ldub [%g6 + TI_WSAVED], %o2
73 brz,pt %o2, 1f
74 nop
75 /* Redo userwin+sched+sig checks */
76 call fault_in_user_windows
77
78 wrpr %g0, RTRAP_PSTATE, %pstate
79 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
80 ldx [%g6 + TI_FLAGS], %l0
81 andcc %l0, _TIF_NEED_RESCHED, %g0
82 be,pt %xcc, 1f
83
84 nop
85 call schedule
86 wrpr %g0, RTRAP_PSTATE, %pstate
87 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
88 ldx [%g6 + TI_FLAGS], %l0
e35a8925 891: andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
1da177e4
LT
90
91 be,pt %xcc, __handle_perfctrs_continue
92 sethi %hi(TSTATE_PEF), %o0
2d7d5f05 93 mov %l5, %o1
2d7d5f05 94 add %sp, PTREGS_OFF, %o0
7697daaa 95 mov %l0, %o2
1da177e4
LT
96 call do_notify_resume
97
98 wrpr %g0, RTRAP_PSTATE, %pstate
99 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
1da177e4
LT
100 /* Signal delivery can modify pt_regs tstate, so we must
101 * reload it.
102 */
103 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
104 sethi %hi(0xf << 20), %l4
105 and %l1, %l4, %l4
106 andn %l1, %l4, %l1
107 ba,pt %xcc, __handle_perfctrs_continue
108
109 sethi %hi(TSTATE_PEF), %o0
110__handle_userfpu:
111 rd %fprs, %l5
112 andcc %l5, FPRS_FEF, %g0
113 sethi %hi(TSTATE_PEF), %o0
114 be,a,pn %icc, __handle_userfpu_continue
115 andn %l1, %o0, %l1
116 ba,a,pt %xcc, __handle_userfpu_continue
117
118__handle_signal:
2d7d5f05 119 mov %l5, %o1
2d7d5f05 120 add %sp, PTREGS_OFF, %o0
7697daaa 121 mov %l0, %o2
1da177e4
LT
122 call do_notify_resume
123 wrpr %g0, RTRAP_PSTATE, %pstate
124 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
1da177e4
LT
125
126 /* Signal delivery can modify pt_regs tstate, so we must
127 * reload it.
128 */
129 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
130 sethi %hi(0xf << 20), %l4
131 and %l1, %l4, %l4
132 ba,pt %xcc, __handle_signal_continue
133 andn %l1, %l4, %l1
134
135 .align 64
7697daaa 136 .globl rtrap_irq, rtrap, irqsz_patchme, rtrap_xcall
1da177e4 137rtrap_irq:
1da177e4 138rtrap:
d7ce78fd
DM
139#ifndef CONFIG_SMP
140 sethi %hi(per_cpu____cpu_data), %l0
141 lduw [%l0 + %lo(per_cpu____cpu_data)], %l1
142#else
143 sethi %hi(per_cpu____cpu_data), %l0
144 or %l0, %lo(per_cpu____cpu_data), %l0
145 lduw [%l0 + %g5], %l1
146#endif
1da177e4
LT
147 cmp %l1, 0
148
149 /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
150 bne,pn %icc, __handle_softirq
151 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
152__handle_softirq_continue:
153rtrap_xcall:
154 sethi %hi(0xf << 20), %l4
1da177e4 155 and %l1, %l4, %l4
10e26723
DM
156 andn %l1, %l4, %l1
157 srl %l4, 20, %l4
158#ifdef CONFIG_TRACE_IRQFLAGS
159 brnz,pn %l4, rtrap_no_irq_enable
160 nop
161 call trace_hardirqs_on
162 nop
163 wrpr %l4, %pil
164rtrap_no_irq_enable:
165#endif
166 andcc %l1, TSTATE_PRIV, %l3
1da177e4 167 bne,pn %icc, to_kernel
10e26723 168 nop
1da177e4
LT
169
170 /* We must hold IRQs off and atomically test schedule+signal
171 * state, then hold them off all the way back to userspace.
10e26723
DM
172 * If we are returning to kernel, none of this matters. Note
173 * that we are disabling interrupts via PSTATE_IE, not using
174 * %pil.
1da177e4
LT
175 *
176 * If we do not do this, there is a window where we would do
177 * the tests, later the signal/resched event arrives but we do
178 * not process it since we are still in kernel mode. It would
179 * take until the next local IRQ before the signal/resched
180 * event would be handled.
181 *
182 * This also means that if we have to deal with performance
183 * counters or user windows, we have to redo all of these
184 * sched+signal checks with IRQs disabled.
185 */
186to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
187 wrpr 0, %pil
188__handle_preemption_continue:
189 ldx [%g6 + TI_FLAGS], %l0
190 sethi %hi(_TIF_USER_WORK_MASK), %o0
191 or %o0, %lo(_TIF_USER_WORK_MASK), %o0
192 andcc %l0, %o0, %g0
193 sethi %hi(TSTATE_PEF), %o0
194 be,pt %xcc, user_nowork
195 andcc %l1, %o0, %g0
196 andcc %l0, _TIF_NEED_RESCHED, %g0
197 bne,pn %xcc, __handle_preemption
e35a8925 198 andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
1da177e4
LT
199 bne,pn %xcc, __handle_signal
200__handle_signal_continue:
201 ldub [%g6 + TI_WSAVED], %o2
202 brnz,pn %o2, __handle_user_windows
203 nop
204__handle_user_windows_continue:
205 ldx [%g6 + TI_FLAGS], %l5
206 andcc %l5, _TIF_PERFCTR, %g0
207 sethi %hi(TSTATE_PEF), %o0
208 bne,pn %xcc, __handle_perfctrs
209__handle_perfctrs_continue:
210 andcc %l1, %o0, %g0
211
212 /* This fpdepth clear is necessary for non-syscall rtraps only */
213user_nowork:
214 bne,pn %xcc, __handle_userfpu
215 stb %g0, [%g6 + TI_FPDEPTH]
216__handle_userfpu_continue:
217
218rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
219 ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
220
221 ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
222 ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
223 ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
56fb4df6 224 brz,pt %l3, 1f
314981ac
DM
225 mov %g6, %l2
226
56fb4df6 227 /* Must do this before thread reg is clobbered below. */
ffe483d5 228 LOAD_PER_CPU_BASE(%g5, %g6, %i0, %i1, %i2)
74bf4312
DM
2291:
230 ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
1da177e4 231 ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
936f482a
DM
232
233 /* Normal globals are restored, go to trap globals. */
234661: wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
af02bec6
DM
235 nop
236 .section .sun4v_2insn_patch, "ax"
936f482a 237 .word 661b
af02bec6 238 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
936f482a
DM
239 SET_GL(1)
240 .previous
241
314981ac
DM
242 mov %l2, %g6
243
1da177e4
LT
244 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
245 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
246
247 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
248 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
249 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
250 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
251 ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
252 ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
253 ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
254 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
255
256 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
257 wr %o3, %g0, %y
1da177e4
LT
258 wrpr %l4, 0x0, %pil
259 wrpr %g0, 0x1, %tl
28e61036 260 andn %l1, TSTATE_SYSCALL, %l1
1da177e4
LT
261 wrpr %l1, %g0, %tstate
262 wrpr %l2, %g0, %tpc
263 wrpr %o2, %g0, %tnpc
264
265 brnz,pn %l3, kern_rtt
266 mov PRIMARY_CONTEXT, %l7
8b11bd12
DM
267
268661: ldxa [%l7 + %l7] ASI_DMMU, %l0
269 .section .sun4v_1insn_patch, "ax"
270 .word 661b
271 ldxa [%l7 + %l7] ASI_MMU, %l0
272 .previous
273
0835ae0f
DM
274 sethi %hi(sparc64_kern_pri_nuc_bits), %l1
275 ldx [%l1 + %lo(sparc64_kern_pri_nuc_bits)], %l1
1da177e4 276 or %l0, %l1, %l0
8b11bd12
DM
277
278661: stxa %l0, [%l7] ASI_DMMU
279 .section .sun4v_1insn_patch, "ax"
280 .word 661b
281 stxa %l0, [%l7] ASI_MMU
282 .previous
283
4da808c3
DM
284 sethi %hi(KERNBASE), %l7
285 flush %l7
1da177e4
LT
286 rdpr %wstate, %l1
287 rdpr %otherwin, %l2
288 srl %l1, 3, %l1
289
290 wrpr %l2, %g0, %canrestore
291 wrpr %l1, %g0, %wstate
314ef685
DM
292 brnz,pt %l2, user_rtt_restore
293 wrpr %g0, %g0, %otherwin
294
295 ldx [%g6 + TI_FLAGS], %g3
296 wr %g0, ASI_AIUP, %asi
297 rdpr %cwp, %g1
298 andcc %g3, _TIF_32BIT, %g0
299 sub %g1, 1, %g1
300 bne,pt %xcc, user_rtt_fill_32bit
301 wrpr %g1, %cwp
302 ba,a,pt %xcc, user_rtt_fill_64bit
303
304user_rtt_fill_fixup:
305 rdpr %cwp, %g1
306 add %g1, 1, %g1
307 wrpr %g1, 0x0, %cwp
308
309 rdpr %wstate, %g2
310 sll %g2, 3, %g2
311 wrpr %g2, 0x0, %wstate
312
313 /* We know %canrestore and %otherwin are both zero. */
314
315 sethi %hi(sparc64_kern_pri_context), %g2
316 ldx [%g2 + %lo(sparc64_kern_pri_context)], %g2
317 mov PRIMARY_CONTEXT, %g1
8b11bd12
DM
318
319661: stxa %g2, [%g1] ASI_DMMU
320 .section .sun4v_1insn_patch, "ax"
321 .word 661b
322 stxa %g2, [%g1] ASI_MMU
323 .previous
324
314ef685
DM
325 sethi %hi(KERNBASE), %g1
326 flush %g1
327
328 or %g4, FAULT_CODE_WINFIXUP, %g4
329 stb %g4, [%g6 + TI_FAULT_CODE]
330 stx %g5, [%g6 + TI_FAULT_ADDR]
331
332 mov %g6, %l1
333 wrpr %g0, 0x0, %tl
936f482a
DM
334
335661: nop
df7d6aec 336 .section .sun4v_1insn_patch, "ax"
936f482a
DM
337 .word 661b
338 SET_GL(0)
339 .previous
340
fc504928
DM
341 wrpr %g0, RTRAP_PSTATE, %pstate
342
314ef685
DM
343 mov %l1, %g6
344 ldx [%g6 + TI_TASK], %g4
345 LOAD_PER_CPU_BASE(%g5, %g6, %g1, %g2, %g3)
346 call do_sparc64_fault
347 add %sp, PTREGS_OFF, %o0
348 ba,pt %xcc, rtrap
349 nop
350
351user_rtt_pre_restore:
352 add %g1, 1, %g1
353 wrpr %g1, 0x0, %cwp
354
355user_rtt_restore:
1da177e4
LT
356 restore
357 rdpr %canrestore, %g1
358 wrpr %g1, 0x0, %cleanwin
359 retry
360 nop
361
314ef685
DM
362kern_rtt: rdpr %canrestore, %g1
363 brz,pn %g1, kern_rtt_fill
364 nop
365kern_rtt_restore:
ada44a04 366 stw %g0, [%sp + PTREGS_OFF + PT_V9_MAGIC]
314ef685 367 restore
1da177e4 368 retry
314ef685 369
1da177e4
LT
370to_kernel:
371#ifdef CONFIG_PREEMPT
372 ldsw [%g6 + TI_PRE_COUNT], %l5
373 brnz %l5, kern_fpucheck
374 ldx [%g6 + TI_FLAGS], %l5
375 andcc %l5, _TIF_NEED_RESCHED, %g0
376 be,pt %xcc, kern_fpucheck
10e26723
DM
377 nop
378 cmp %l4, 0
1da177e4
LT
379 bne,pn %xcc, kern_fpucheck
380 sethi %hi(PREEMPT_ACTIVE), %l6
381 stw %l6, [%g6 + TI_PRE_COUNT]
382 call schedule
383 nop
384 ba,pt %xcc, rtrap
385 stw %g0, [%g6 + TI_PRE_COUNT]
386#endif
387kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
388 brz,pt %l5, rt_continue
389 srl %l5, 1, %o0
390 add %g6, TI_FPSAVED, %l6
391 ldub [%l6 + %o0], %l2
392 sub %l5, 2, %l5
393
394 add %g6, TI_GSR, %o1
395 andcc %l2, (FPRS_FEF|FPRS_DU), %g0
396 be,pt %icc, 2f
397 and %l2, FPRS_DL, %l6
398 andcc %l2, FPRS_FEF, %g0
399 be,pn %icc, 5f
400 sll %o0, 3, %o5
401 rd %fprs, %g1
402
403 wr %g1, FPRS_FEF, %fprs
404 ldx [%o1 + %o5], %g1
405 add %g6, TI_XFSR, %o1
1da177e4
LT
406 sll %o0, 8, %o2
407 add %g6, TI_FPREGS, %o3
408 brz,pn %l6, 1f
409 add %g6, TI_FPREGS+0x40, %o4
410
ba639933 411 membar #Sync
1da177e4
LT
412 ldda [%o3 + %o2] ASI_BLK_P, %f0
413 ldda [%o4 + %o2] ASI_BLK_P, %f16
ba639933 414 membar #Sync
1da177e4
LT
4151: andcc %l2, FPRS_DU, %g0
416 be,pn %icc, 1f
417 wr %g1, 0, %gsr
418 add %o2, 0x80, %o2
ba639933 419 membar #Sync
1da177e4
LT
420 ldda [%o3 + %o2] ASI_BLK_P, %f32
421 ldda [%o4 + %o2] ASI_BLK_P, %f48
1da177e4
LT
4221: membar #Sync
423 ldx [%o1 + %o5], %fsr
4242: stb %l5, [%g6 + TI_FPDEPTH]
425 ba,pt %xcc, rt_continue
426 nop
4275: wr %g0, FPRS_FEF, %fprs
1da177e4
LT
428 sll %o0, 8, %o2
429
430 add %g6, TI_FPREGS+0x80, %o3
431 add %g6, TI_FPREGS+0xc0, %o4
ba639933 432 membar #Sync
1da177e4
LT
433 ldda [%o3 + %o2] ASI_BLK_P, %f32
434 ldda [%o4 + %o2] ASI_BLK_P, %f48
435 membar #Sync
436 wr %g0, FPRS_DU, %fprs
437 ba,pt %xcc, rt_continue
438 stb %l5, [%g6 + TI_FPDEPTH]
This page took 2.034718 seconds and 5 git commands to generate.