blob: 0b21042ab181bcfa00688131ae29adfead8bd2ee [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Adrian Bunkb00dc832008-05-19 16:52:27 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * rtrap.S: Preparing for return from trap on Sparc V9.
4 *
5 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
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
Kirill Tkhai812cb832013-09-14 16:02:11 +040018#ifdef CONFIG_CONTEXT_TRACKING
19# define SCHEDULE_USER schedule_user
20#else
21# define SCHEDULE_USER schedule
22#endif
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 .text
25 .align 32
Linus Torvalds1da177e2005-04-16 15:20:36 -070026__handle_preemption:
Kirill Tkhai812cb832013-09-14 16:02:11 +040027 call SCHEDULE_USER
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 wrpr %g0, RTRAP_PSTATE, %pstate
29 ba,pt %xcc, __handle_preemption_continue
30 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
31
32__handle_user_windows:
33 call fault_in_user_windows
34 wrpr %g0, RTRAP_PSTATE, %pstate
Al Virocaebf912010-09-23 21:52:52 -070035 ba,pt %xcc, __handle_preemption_continue
36 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038__handle_userfpu:
39 rd %fprs, %l5
40 andcc %l5, FPRS_FEF, %g0
41 sethi %hi(TSTATE_PEF), %o0
42 be,a,pn %icc, __handle_userfpu_continue
43 andn %l1, %o0, %l1
44 ba,a,pt %xcc, __handle_userfpu_continue
45
46__handle_signal:
David S. Miller2d7d5f02006-01-19 02:42:49 -080047 mov %l5, %o1
David S. Miller2d7d5f02006-01-19 02:42:49 -080048 add %sp, PTREGS_OFF, %o0
David S. Miller7697daa2008-04-24 03:15:22 -070049 mov %l0, %o2
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 call do_notify_resume
51 wrpr %g0, RTRAP_PSTATE, %pstate
52 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 /* Signal delivery can modify pt_regs tstate, so we must
55 * reload it.
56 */
57 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
58 sethi %hi(0xf << 20), %l4
59 and %l1, %l4, %l4
Al Virocaebf912010-09-23 21:52:52 -070060 ba,pt %xcc, __handle_preemption_continue
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 andn %l1, %l4, %l1
62
David S. Miller55657362008-11-25 22:24:59 -080063 /* When returning from a NMI (%pil==15) interrupt we want to
64 * avoid running softirqs, doing IRQ tracing, preempting, etc.
65 */
66 .globl rtrap_nmi
67rtrap_nmi: ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
68 sethi %hi(0xf << 20), %l4
69 and %l1, %l4, %l4
70 andn %l1, %l4, %l1
71 srl %l4, 20, %l4
72 ba,pt %xcc, rtrap_no_irq_enable
Rob Gardner1ca04a42015-12-21 21:48:03 -070073 nop
74 /* Do not actually set the %pil here. We will do that
75 * below after we clear PSTATE_IE in the %pstate register.
76 * If we re-enable interrupts here, we can recurse down
77 * the hardirq stack potentially endlessly, causing a
78 * stack overflow.
79 */
David S. Miller55657362008-11-25 22:24:59 -080080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 .align 64
David S. Miller7697daa2008-04-24 03:15:22 -070082 .globl rtrap_irq, rtrap, irqsz_patchme, rtrap_xcall
Linus Torvalds1da177e2005-04-16 15:20:36 -070083rtrap_irq:
Linus Torvalds1da177e2005-04-16 15:20:36 -070084rtrap:
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 /* mm/ultra.S:xcall_report_regs KNOWS about this load. */
David S. Miller78b7e3d2012-04-13 13:56:46 -070086 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
Linus Torvalds1da177e2005-04-16 15:20:36 -070087rtrap_xcall:
88 sethi %hi(0xf << 20), %l4
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 and %l1, %l4, %l4
David S. Miller10e26722006-11-16 13:38:57 -080090 andn %l1, %l4, %l1
91 srl %l4, 20, %l4
92#ifdef CONFIG_TRACE_IRQFLAGS
93 brnz,pn %l4, rtrap_no_irq_enable
94 nop
95 call trace_hardirqs_on
96 nop
David S. Miller28a1f532010-04-20 00:48:37 -070097 /* Do not actually set the %pil here. We will do that
98 * below after we clear PSTATE_IE in the %pstate register.
99 * If we re-enable interrupts here, we can recurse down
100 * the hardirq stack potentially endlessly, causing a
101 * stack overflow.
102 *
103 * It is tempting to put this test and trace_hardirqs_on
104 * call at the 'rt_continue' label, but that will not work
105 * as that path hits unconditionally and we do not want to
106 * execute this in NMI return paths, for example.
107 */
David S. Miller10e26722006-11-16 13:38:57 -0800108#endif
David S. Miller55657362008-11-25 22:24:59 -0800109rtrap_no_irq_enable:
David S. Miller10e26722006-11-16 13:38:57 -0800110 andcc %l1, TSTATE_PRIV, %l3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 bne,pn %icc, to_kernel
David S. Miller10e26722006-11-16 13:38:57 -0800112 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 /* We must hold IRQs off and atomically test schedule+signal
115 * state, then hold them off all the way back to userspace.
David S. Miller10e26722006-11-16 13:38:57 -0800116 * If we are returning to kernel, none of this matters. Note
117 * that we are disabling interrupts via PSTATE_IE, not using
118 * %pil.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 *
120 * If we do not do this, there is a window where we would do
121 * the tests, later the signal/resched event arrives but we do
122 * not process it since we are still in kernel mode. It would
123 * take until the next local IRQ before the signal/resched
124 * event would be handled.
125 *
David S. Millerc7d5a002010-03-03 08:08:49 -0800126 * This also means that if we have to deal with user
127 * windows, we have to redo all of these sched+signal checks
128 * with IRQs disabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 */
130to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
131 wrpr 0, %pil
132__handle_preemption_continue:
133 ldx [%g6 + TI_FLAGS], %l0
134 sethi %hi(_TIF_USER_WORK_MASK), %o0
135 or %o0, %lo(_TIF_USER_WORK_MASK), %o0
136 andcc %l0, %o0, %g0
137 sethi %hi(TSTATE_PEF), %o0
138 be,pt %xcc, user_nowork
139 andcc %l1, %o0, %g0
140 andcc %l0, _TIF_NEED_RESCHED, %g0
141 bne,pn %xcc, __handle_preemption
Roland McGrathe35a8922008-04-20 15:06:49 -0700142 andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 bne,pn %xcc, __handle_signal
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 ldub [%g6 + TI_WSAVED], %o2
145 brnz,pn %o2, __handle_user_windows
146 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 sethi %hi(TSTATE_PEF), %o0
David S. Millerc7d5a002010-03-03 08:08:49 -0800148 andcc %l1, %o0, %g0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 /* This fpdepth clear is necessary for non-syscall rtraps only */
151user_nowork:
152 bne,pn %xcc, __handle_userfpu
153 stb %g0, [%g6 + TI_FPDEPTH]
154__handle_userfpu_continue:
155
156rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
157 ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
158
159 ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
160 ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
161 ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
David S. Miller56fb4df2006-02-26 23:24:22 -0800162 brz,pt %l3, 1f
David S. Miller314981a2006-02-05 21:59:03 -0800163 mov %g6, %l2
164
David S. Miller56fb4df2006-02-26 23:24:22 -0800165 /* Must do this before thread reg is clobbered below. */
David S. Millerffe483d2006-02-02 21:55:10 -0800166 LOAD_PER_CPU_BASE(%g5, %g6, %i0, %i1, %i2)
David S. Miller74bf4312006-01-31 18:29:18 -08001671:
168 ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
David S. Miller936f4822006-02-05 21:29:28 -0800170
171 /* Normal globals are restored, go to trap globals. */
172661: wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
David S. Milleraf02bec2006-02-16 16:23:45 -0800173 nop
174 .section .sun4v_2insn_patch, "ax"
David S. Miller936f4822006-02-05 21:29:28 -0800175 .word 661b
David S. Milleraf02bec2006-02-16 16:23:45 -0800176 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
David S. Miller936f4822006-02-05 21:29:28 -0800177 SET_GL(1)
178 .previous
179
David S. Miller314981a2006-02-05 21:59:03 -0800180 mov %l2, %g6
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
183 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
184
185 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
186 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
187 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
188 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
189 ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
190 ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
191 ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
192 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
193
194 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
195 wr %o3, %g0, %y
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 wrpr %l4, 0x0, %pil
197 wrpr %g0, 0x1, %tl
David S. Miller28e61032008-05-11 02:07:19 -0700198 andn %l1, TSTATE_SYSCALL, %l1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 wrpr %l1, %g0, %tstate
200 wrpr %l2, %g0, %tpc
201 wrpr %o2, %g0, %tnpc
202
203 brnz,pn %l3, kern_rtt
204 mov PRIMARY_CONTEXT, %l7
David S. Miller8b11bd12006-02-07 22:13:05 -0800205
206661: ldxa [%l7 + %l7] ASI_DMMU, %l0
207 .section .sun4v_1insn_patch, "ax"
208 .word 661b
209 ldxa [%l7 + %l7] ASI_MMU, %l0
210 .previous
211
David S. Miller0835ae02005-10-04 15:23:20 -0700212 sethi %hi(sparc64_kern_pri_nuc_bits), %l1
213 ldx [%l1 + %lo(sparc64_kern_pri_nuc_bits)], %l1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 or %l0, %l1, %l0
David S. Miller8b11bd12006-02-07 22:13:05 -0800215
216661: stxa %l0, [%l7] ASI_DMMU
217 .section .sun4v_1insn_patch, "ax"
218 .word 661b
219 stxa %l0, [%l7] ASI_MMU
220 .previous
221
David S. Miller4da808c2006-01-31 18:33:00 -0800222 sethi %hi(KERNBASE), %l7
223 flush %l7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 rdpr %wstate, %l1
225 rdpr %otherwin, %l2
226 srl %l1, 3, %l1
227
Anthony Yznagaa7159a82017-08-18 12:40:36 -0700228661: wrpr %l2, %g0, %canrestore
229 .section .fast_win_ctrl_1insn_patch, "ax"
230 .word 661b
231 .word 0x89880000 ! normalw
232 .previous
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 wrpr %l1, %g0, %wstate
David S. Miller314ef682006-02-04 00:10:01 -0800235 brnz,pt %l2, user_rtt_restore
Anthony Yznagaa7159a82017-08-18 12:40:36 -0700236661: wrpr %g0, %g0, %otherwin
237 .section .fast_win_ctrl_1insn_patch, "ax"
238 .word 661b
239 nop
240 .previous
David S. Miller314ef682006-02-04 00:10:01 -0800241
242 ldx [%g6 + TI_FLAGS], %g3
243 wr %g0, ASI_AIUP, %asi
244 rdpr %cwp, %g1
245 andcc %g3, _TIF_32BIT, %g0
246 sub %g1, 1, %g1
247 bne,pt %xcc, user_rtt_fill_32bit
248 wrpr %g1, %cwp
249 ba,a,pt %xcc, user_rtt_fill_64bit
Babu Moger0ae2d262017-03-17 14:52:21 -0600250 nop
David S. Miller314ef682006-02-04 00:10:01 -0800251
David S. Miller7cafc0b2016-05-28 20:41:12 -0700252user_rtt_fill_fixup_dax:
253 ba,pt %xcc, user_rtt_fill_fixup_common
254 mov 1, %g3
255
256user_rtt_fill_fixup_mna:
257 ba,pt %xcc, user_rtt_fill_fixup_common
258 mov 2, %g3
259
David S. Miller314ef682006-02-04 00:10:01 -0800260user_rtt_fill_fixup:
David S. Miller7cafc0b2016-05-28 20:41:12 -0700261 ba,pt %xcc, user_rtt_fill_fixup_common
262 clr %g3
David S. Miller314ef682006-02-04 00:10:01 -0800263
264user_rtt_pre_restore:
265 add %g1, 1, %g1
266 wrpr %g1, 0x0, %cwp
267
268user_rtt_restore:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 restore
270 rdpr %canrestore, %g1
271 wrpr %g1, 0x0, %cleanwin
272 retry
273 nop
274
David S. Miller314ef682006-02-04 00:10:01 -0800275kern_rtt: rdpr %canrestore, %g1
276 brz,pn %g1, kern_rtt_fill
277 nop
278kern_rtt_restore:
David S. Millerada44a02008-05-21 21:50:01 -0700279 stw %g0, [%sp + PTREGS_OFF + PT_V9_MAGIC]
David S. Miller314ef682006-02-04 00:10:01 -0800280 restore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 retry
David S. Miller314ef682006-02-04 00:10:01 -0800282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283to_kernel:
284#ifdef CONFIG_PREEMPT
285 ldsw [%g6 + TI_PRE_COUNT], %l5
286 brnz %l5, kern_fpucheck
287 ldx [%g6 + TI_FLAGS], %l5
288 andcc %l5, _TIF_NEED_RESCHED, %g0
289 be,pt %xcc, kern_fpucheck
David S. Miller10e26722006-11-16 13:38:57 -0800290 nop
291 cmp %l4, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 bne,pn %xcc, kern_fpucheck
Thomas Gleixner9385d942013-09-17 18:53:08 +0000293 nop
294 call preempt_schedule_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 nop
296 ba,pt %xcc, rtrap
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#endif
298kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5
299 brz,pt %l5, rt_continue
300 srl %l5, 1, %o0
301 add %g6, TI_FPSAVED, %l6
302 ldub [%l6 + %o0], %l2
303 sub %l5, 2, %l5
304
305 add %g6, TI_GSR, %o1
306 andcc %l2, (FPRS_FEF|FPRS_DU), %g0
307 be,pt %icc, 2f
308 and %l2, FPRS_DL, %l6
309 andcc %l2, FPRS_FEF, %g0
310 be,pn %icc, 5f
311 sll %o0, 3, %o5
312 rd %fprs, %g1
313
314 wr %g1, FPRS_FEF, %fprs
315 ldx [%o1 + %o5], %g1
316 add %g6, TI_XFSR, %o1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 sll %o0, 8, %o2
318 add %g6, TI_FPREGS, %o3
319 brz,pn %l6, 1f
320 add %g6, TI_FPREGS+0x40, %o4
321
David S. Millerba6399332005-10-07 13:30:49 -0700322 membar #Sync
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 ldda [%o3 + %o2] ASI_BLK_P, %f0
324 ldda [%o4 + %o2] ASI_BLK_P, %f16
David S. Millerba6399332005-10-07 13:30:49 -0700325 membar #Sync
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261: andcc %l2, FPRS_DU, %g0
327 be,pn %icc, 1f
328 wr %g1, 0, %gsr
329 add %o2, 0x80, %o2
David S. Millerba6399332005-10-07 13:30:49 -0700330 membar #Sync
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 ldda [%o3 + %o2] ASI_BLK_P, %f32
332 ldda [%o4 + %o2] ASI_BLK_P, %f48
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331: membar #Sync
334 ldx [%o1 + %o5], %fsr
3352: stb %l5, [%g6 + TI_FPDEPTH]
336 ba,pt %xcc, rt_continue
337 nop
3385: wr %g0, FPRS_FEF, %fprs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 sll %o0, 8, %o2
340
341 add %g6, TI_FPREGS+0x80, %o3
342 add %g6, TI_FPREGS+0xc0, %o4
David S. Millerba6399332005-10-07 13:30:49 -0700343 membar #Sync
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 ldda [%o3 + %o2] ASI_BLK_P, %f32
345 ldda [%o4 + %o2] ASI_BLK_P, %f48
346 membar #Sync
347 wr %g0, FPRS_DU, %fprs
348 ba,pt %xcc, rt_continue
349 stb %l5, [%g6 + TI_FPDEPTH]