Commit | Line | Data |
---|---|---|
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 | |
812cb83a KT |
21 | #ifdef CONFIG_CONTEXT_TRACKING |
22 | # define SCHEDULE_USER schedule_user | |
23 | #else | |
24 | # define SCHEDULE_USER schedule | |
25 | #endif | |
26 | ||
1da177e4 LT |
27 | .text |
28 | .align 32 | |
1da177e4 | 29 | __handle_preemption: |
812cb83a | 30 | call SCHEDULE_USER |
1da177e4 LT |
31 | wrpr %g0, RTRAP_PSTATE, %pstate |
32 | ba,pt %xcc, __handle_preemption_continue | |
33 | wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate | |
34 | ||
35 | __handle_user_windows: | |
36 | call fault_in_user_windows | |
37 | wrpr %g0, RTRAP_PSTATE, %pstate | |
caebf910 AV |
38 | ba,pt %xcc, __handle_preemption_continue |
39 | wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate | |
1da177e4 | 40 | |
1da177e4 LT |
41 | __handle_userfpu: |
42 | rd %fprs, %l5 | |
43 | andcc %l5, FPRS_FEF, %g0 | |
44 | sethi %hi(TSTATE_PEF), %o0 | |
45 | be,a,pn %icc, __handle_userfpu_continue | |
46 | andn %l1, %o0, %l1 | |
47 | ba,a,pt %xcc, __handle_userfpu_continue | |
48 | ||
49 | __handle_signal: | |
2d7d5f05 | 50 | mov %l5, %o1 |
2d7d5f05 | 51 | add %sp, PTREGS_OFF, %o0 |
7697daaa | 52 | mov %l0, %o2 |
1da177e4 LT |
53 | call do_notify_resume |
54 | wrpr %g0, RTRAP_PSTATE, %pstate | |
55 | wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate | |
1da177e4 LT |
56 | |
57 | /* Signal delivery can modify pt_regs tstate, so we must | |
58 | * reload it. | |
59 | */ | |
60 | ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 | |
61 | sethi %hi(0xf << 20), %l4 | |
62 | and %l1, %l4, %l4 | |
caebf910 | 63 | ba,pt %xcc, __handle_preemption_continue |
1da177e4 LT |
64 | andn %l1, %l4, %l1 |
65 | ||
5565736e DM |
66 | /* When returning from a NMI (%pil==15) interrupt we want to |
67 | * avoid running softirqs, doing IRQ tracing, preempting, etc. | |
68 | */ | |
69 | .globl rtrap_nmi | |
70 | rtrap_nmi: ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 | |
71 | sethi %hi(0xf << 20), %l4 | |
72 | and %l1, %l4, %l4 | |
73 | andn %l1, %l4, %l1 | |
74 | srl %l4, 20, %l4 | |
75 | ba,pt %xcc, rtrap_no_irq_enable | |
76 | wrpr %l4, %pil | |
77 | ||
1da177e4 | 78 | .align 64 |
7697daaa | 79 | .globl rtrap_irq, rtrap, irqsz_patchme, rtrap_xcall |
1da177e4 | 80 | rtrap_irq: |
1da177e4 | 81 | rtrap: |
1da177e4 | 82 | /* mm/ultra.S:xcall_report_regs KNOWS about this load. */ |
78b7e3d0 | 83 | ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 |
1da177e4 LT |
84 | rtrap_xcall: |
85 | sethi %hi(0xf << 20), %l4 | |
1da177e4 | 86 | and %l1, %l4, %l4 |
10e26723 DM |
87 | andn %l1, %l4, %l1 |
88 | srl %l4, 20, %l4 | |
89 | #ifdef CONFIG_TRACE_IRQFLAGS | |
90 | brnz,pn %l4, rtrap_no_irq_enable | |
91 | nop | |
92 | call trace_hardirqs_on | |
93 | nop | |
28a1f533 DM |
94 | /* Do not actually set the %pil here. We will do that |
95 | * below after we clear PSTATE_IE in the %pstate register. | |
96 | * If we re-enable interrupts here, we can recurse down | |
97 | * the hardirq stack potentially endlessly, causing a | |
98 | * stack overflow. | |
99 | * | |
100 | * It is tempting to put this test and trace_hardirqs_on | |
101 | * call at the 'rt_continue' label, but that will not work | |
102 | * as that path hits unconditionally and we do not want to | |
103 | * execute this in NMI return paths, for example. | |
104 | */ | |
10e26723 | 105 | #endif |
5565736e | 106 | rtrap_no_irq_enable: |
10e26723 | 107 | andcc %l1, TSTATE_PRIV, %l3 |
1da177e4 | 108 | bne,pn %icc, to_kernel |
10e26723 | 109 | nop |
1da177e4 LT |
110 | |
111 | /* We must hold IRQs off and atomically test schedule+signal | |
112 | * state, then hold them off all the way back to userspace. | |
10e26723 DM |
113 | * If we are returning to kernel, none of this matters. Note |
114 | * that we are disabling interrupts via PSTATE_IE, not using | |
115 | * %pil. | |
1da177e4 LT |
116 | * |
117 | * If we do not do this, there is a window where we would do | |
118 | * the tests, later the signal/resched event arrives but we do | |
119 | * not process it since we are still in kernel mode. It would | |
120 | * take until the next local IRQ before the signal/resched | |
121 | * event would be handled. | |
122 | * | |
c7d5a005 DM |
123 | * This also means that if we have to deal with user |
124 | * windows, we have to redo all of these sched+signal checks | |
125 | * with IRQs disabled. | |
1da177e4 LT |
126 | */ |
127 | to_user: wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate | |
128 | wrpr 0, %pil | |
129 | __handle_preemption_continue: | |
130 | ldx [%g6 + TI_FLAGS], %l0 | |
131 | sethi %hi(_TIF_USER_WORK_MASK), %o0 | |
132 | or %o0, %lo(_TIF_USER_WORK_MASK), %o0 | |
133 | andcc %l0, %o0, %g0 | |
134 | sethi %hi(TSTATE_PEF), %o0 | |
135 | be,pt %xcc, user_nowork | |
136 | andcc %l1, %o0, %g0 | |
137 | andcc %l0, _TIF_NEED_RESCHED, %g0 | |
138 | bne,pn %xcc, __handle_preemption | |
e35a8925 | 139 | andcc %l0, _TIF_DO_NOTIFY_RESUME_MASK, %g0 |
1da177e4 | 140 | bne,pn %xcc, __handle_signal |
1da177e4 LT |
141 | ldub [%g6 + TI_WSAVED], %o2 |
142 | brnz,pn %o2, __handle_user_windows | |
143 | nop | |
1da177e4 | 144 | sethi %hi(TSTATE_PEF), %o0 |
c7d5a005 | 145 | andcc %l1, %o0, %g0 |
1da177e4 LT |
146 | |
147 | /* This fpdepth clear is necessary for non-syscall rtraps only */ | |
148 | user_nowork: | |
149 | bne,pn %xcc, __handle_userfpu | |
150 | stb %g0, [%g6 + TI_FPDEPTH] | |
151 | __handle_userfpu_continue: | |
152 | ||
153 | rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1 | |
154 | ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2 | |
155 | ||
156 | ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3 | |
157 | ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4 | |
158 | ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5 | |
56fb4df6 | 159 | brz,pt %l3, 1f |
314981ac DM |
160 | mov %g6, %l2 |
161 | ||
56fb4df6 | 162 | /* Must do this before thread reg is clobbered below. */ |
ffe483d5 | 163 | LOAD_PER_CPU_BASE(%g5, %g6, %i0, %i1, %i2) |
74bf4312 DM |
164 | 1: |
165 | ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6 | |
1da177e4 | 166 | ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7 |
936f482a DM |
167 | |
168 | /* Normal globals are restored, go to trap globals. */ | |
169 | 661: wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate | |
af02bec6 DM |
170 | nop |
171 | .section .sun4v_2insn_patch, "ax" | |
936f482a | 172 | .word 661b |
af02bec6 | 173 | wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate |
936f482a DM |
174 | SET_GL(1) |
175 | .previous | |
176 | ||
314981ac DM |
177 | mov %l2, %g6 |
178 | ||
1da177e4 LT |
179 | ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0 |
180 | ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1 | |
181 | ||
182 | ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2 | |
183 | ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3 | |
184 | ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4 | |
185 | ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5 | |
186 | ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6 | |
187 | ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7 | |
188 | ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2 | |
189 | ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2 | |
190 | ||
191 | ld [%sp + PTREGS_OFF + PT_V9_Y], %o3 | |
192 | wr %o3, %g0, %y | |
1da177e4 LT |
193 | wrpr %l4, 0x0, %pil |
194 | wrpr %g0, 0x1, %tl | |
28e61036 | 195 | andn %l1, TSTATE_SYSCALL, %l1 |
1da177e4 LT |
196 | wrpr %l1, %g0, %tstate |
197 | wrpr %l2, %g0, %tpc | |
198 | wrpr %o2, %g0, %tnpc | |
199 | ||
200 | brnz,pn %l3, kern_rtt | |
201 | mov PRIMARY_CONTEXT, %l7 | |
8b11bd12 DM |
202 | |
203 | 661: ldxa [%l7 + %l7] ASI_DMMU, %l0 | |
204 | .section .sun4v_1insn_patch, "ax" | |
205 | .word 661b | |
206 | ldxa [%l7 + %l7] ASI_MMU, %l0 | |
207 | .previous | |
208 | ||
0835ae0f DM |
209 | sethi %hi(sparc64_kern_pri_nuc_bits), %l1 |
210 | ldx [%l1 + %lo(sparc64_kern_pri_nuc_bits)], %l1 | |
1da177e4 | 211 | or %l0, %l1, %l0 |
8b11bd12 DM |
212 | |
213 | 661: stxa %l0, [%l7] ASI_DMMU | |
214 | .section .sun4v_1insn_patch, "ax" | |
215 | .word 661b | |
216 | stxa %l0, [%l7] ASI_MMU | |
217 | .previous | |
218 | ||
4da808c3 DM |
219 | sethi %hi(KERNBASE), %l7 |
220 | flush %l7 | |
1da177e4 LT |
221 | rdpr %wstate, %l1 |
222 | rdpr %otherwin, %l2 | |
223 | srl %l1, 3, %l1 | |
224 | ||
225 | wrpr %l2, %g0, %canrestore | |
226 | wrpr %l1, %g0, %wstate | |
314ef685 DM |
227 | brnz,pt %l2, user_rtt_restore |
228 | wrpr %g0, %g0, %otherwin | |
229 | ||
230 | ldx [%g6 + TI_FLAGS], %g3 | |
231 | wr %g0, ASI_AIUP, %asi | |
232 | rdpr %cwp, %g1 | |
233 | andcc %g3, _TIF_32BIT, %g0 | |
234 | sub %g1, 1, %g1 | |
235 | bne,pt %xcc, user_rtt_fill_32bit | |
236 | wrpr %g1, %cwp | |
237 | ba,a,pt %xcc, user_rtt_fill_64bit | |
238 | ||
239 | user_rtt_fill_fixup: | |
240 | rdpr %cwp, %g1 | |
241 | add %g1, 1, %g1 | |
242 | wrpr %g1, 0x0, %cwp | |
243 | ||
244 | rdpr %wstate, %g2 | |
245 | sll %g2, 3, %g2 | |
246 | wrpr %g2, 0x0, %wstate | |
247 | ||
248 | /* We know %canrestore and %otherwin are both zero. */ | |
249 | ||
250 | sethi %hi(sparc64_kern_pri_context), %g2 | |
251 | ldx [%g2 + %lo(sparc64_kern_pri_context)], %g2 | |
252 | mov PRIMARY_CONTEXT, %g1 | |
8b11bd12 DM |
253 | |
254 | 661: stxa %g2, [%g1] ASI_DMMU | |
255 | .section .sun4v_1insn_patch, "ax" | |
256 | .word 661b | |
257 | stxa %g2, [%g1] ASI_MMU | |
258 | .previous | |
259 | ||
314ef685 DM |
260 | sethi %hi(KERNBASE), %g1 |
261 | flush %g1 | |
262 | ||
263 | or %g4, FAULT_CODE_WINFIXUP, %g4 | |
264 | stb %g4, [%g6 + TI_FAULT_CODE] | |
265 | stx %g5, [%g6 + TI_FAULT_ADDR] | |
266 | ||
267 | mov %g6, %l1 | |
268 | wrpr %g0, 0x0, %tl | |
936f482a DM |
269 | |
270 | 661: nop | |
df7d6aec | 271 | .section .sun4v_1insn_patch, "ax" |
936f482a DM |
272 | .word 661b |
273 | SET_GL(0) | |
274 | .previous | |
275 | ||
fc504928 DM |
276 | wrpr %g0, RTRAP_PSTATE, %pstate |
277 | ||
314ef685 DM |
278 | mov %l1, %g6 |
279 | ldx [%g6 + TI_TASK], %g4 | |
280 | LOAD_PER_CPU_BASE(%g5, %g6, %g1, %g2, %g3) | |
281 | call do_sparc64_fault | |
282 | add %sp, PTREGS_OFF, %o0 | |
283 | ba,pt %xcc, rtrap | |
284 | nop | |
285 | ||
286 | user_rtt_pre_restore: | |
287 | add %g1, 1, %g1 | |
288 | wrpr %g1, 0x0, %cwp | |
289 | ||
290 | user_rtt_restore: | |
1da177e4 LT |
291 | restore |
292 | rdpr %canrestore, %g1 | |
293 | wrpr %g1, 0x0, %cleanwin | |
294 | retry | |
295 | nop | |
296 | ||
314ef685 DM |
297 | kern_rtt: rdpr %canrestore, %g1 |
298 | brz,pn %g1, kern_rtt_fill | |
299 | nop | |
300 | kern_rtt_restore: | |
ada44a04 | 301 | stw %g0, [%sp + PTREGS_OFF + PT_V9_MAGIC] |
314ef685 | 302 | restore |
1da177e4 | 303 | retry |
314ef685 | 304 | |
1da177e4 LT |
305 | to_kernel: |
306 | #ifdef CONFIG_PREEMPT | |
307 | ldsw [%g6 + TI_PRE_COUNT], %l5 | |
308 | brnz %l5, kern_fpucheck | |
309 | ldx [%g6 + TI_FLAGS], %l5 | |
310 | andcc %l5, _TIF_NEED_RESCHED, %g0 | |
311 | be,pt %xcc, kern_fpucheck | |
10e26723 DM |
312 | nop |
313 | cmp %l4, 0 | |
1da177e4 LT |
314 | bne,pn %xcc, kern_fpucheck |
315 | sethi %hi(PREEMPT_ACTIVE), %l6 | |
316 | stw %l6, [%g6 + TI_PRE_COUNT] | |
317 | call schedule | |
318 | nop | |
319 | ba,pt %xcc, rtrap | |
320 | stw %g0, [%g6 + TI_PRE_COUNT] | |
321 | #endif | |
322 | kern_fpucheck: ldub [%g6 + TI_FPDEPTH], %l5 | |
323 | brz,pt %l5, rt_continue | |
324 | srl %l5, 1, %o0 | |
325 | add %g6, TI_FPSAVED, %l6 | |
326 | ldub [%l6 + %o0], %l2 | |
327 | sub %l5, 2, %l5 | |
328 | ||
329 | add %g6, TI_GSR, %o1 | |
330 | andcc %l2, (FPRS_FEF|FPRS_DU), %g0 | |
331 | be,pt %icc, 2f | |
332 | and %l2, FPRS_DL, %l6 | |
333 | andcc %l2, FPRS_FEF, %g0 | |
334 | be,pn %icc, 5f | |
335 | sll %o0, 3, %o5 | |
336 | rd %fprs, %g1 | |
337 | ||
338 | wr %g1, FPRS_FEF, %fprs | |
339 | ldx [%o1 + %o5], %g1 | |
340 | add %g6, TI_XFSR, %o1 | |
1da177e4 LT |
341 | sll %o0, 8, %o2 |
342 | add %g6, TI_FPREGS, %o3 | |
343 | brz,pn %l6, 1f | |
344 | add %g6, TI_FPREGS+0x40, %o4 | |
345 | ||
ba639933 | 346 | membar #Sync |
1da177e4 LT |
347 | ldda [%o3 + %o2] ASI_BLK_P, %f0 |
348 | ldda [%o4 + %o2] ASI_BLK_P, %f16 | |
ba639933 | 349 | membar #Sync |
1da177e4 LT |
350 | 1: andcc %l2, FPRS_DU, %g0 |
351 | be,pn %icc, 1f | |
352 | wr %g1, 0, %gsr | |
353 | add %o2, 0x80, %o2 | |
ba639933 | 354 | membar #Sync |
1da177e4 LT |
355 | ldda [%o3 + %o2] ASI_BLK_P, %f32 |
356 | ldda [%o4 + %o2] ASI_BLK_P, %f48 | |
1da177e4 LT |
357 | 1: membar #Sync |
358 | ldx [%o1 + %o5], %fsr | |
359 | 2: stb %l5, [%g6 + TI_FPDEPTH] | |
360 | ba,pt %xcc, rt_continue | |
361 | nop | |
362 | 5: wr %g0, FPRS_FEF, %fprs | |
1da177e4 LT |
363 | sll %o0, 8, %o2 |
364 | ||
365 | add %g6, TI_FPREGS+0x80, %o3 | |
366 | add %g6, TI_FPREGS+0xc0, %o4 | |
ba639933 | 367 | membar #Sync |
1da177e4 LT |
368 | ldda [%o3 + %o2] ASI_BLK_P, %f32 |
369 | ldda [%o4 + %o2] ASI_BLK_P, %f48 | |
370 | membar #Sync | |
371 | wr %g0, FPRS_DU, %fprs | |
372 | ba,pt %xcc, rt_continue | |
373 | stb %l5, [%g6 + TI_FPDEPTH] |