1 /* $Id: rtrap.S,v 1.55 2000/08/05 10:48:40 davem Exp $
2 * rtrap.S: Return from Sparc trap low-level code.
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7 #include <asm/cprefix.h>
9 #include <asm/ptrace.h>
13 #include <asm/contregs.h>
14 #include <asm/winmacro.h>
15 #include <asm/asmmacro.h>
25 /* 7 WINDOW SPARC PATCH INSTRUCTIONS */
26 .globl rtrap_7win_patch1, rtrap_7win_patch2, rtrap_7win_patch3
27 .globl rtrap_7win_patch4, rtrap_7win_patch5
28 rtrap_7win_patch1: srl %t_wim, 0x6, %glob_tmp
29 rtrap_7win_patch2: and %glob_tmp, 0x7f, %glob_tmp
30 rtrap_7win_patch3: srl %g1, 7, %g2
31 rtrap_7win_patch4: srl %g2, 6, %g2
32 rtrap_7win_patch5: and %g1, 0x7f, %g1
33 /* END OF PATCH INSTRUCTIONS */
35 /* We need to check for a few things which are:
36 * 1) The need to call schedule() because this
37 * processes quantum is up.
38 * 2) Pending signals for this process, if any
39 * exist we need to call do_signal() to do
42 * Else we just check if the rett would land us
43 * in an invalid window, if so we need to grab
44 * it off the user/kernel stack first.
47 .globl ret_trap_entry, rtrap_patch1, rtrap_patch2
48 .globl rtrap_patch3, rtrap_patch4, rtrap_patch5
49 .globl C_LABEL(ret_trap_lockless_ipi)
51 ld [%curptr + AOFF_task_processor], %l3
53 sethi %hi(C_LABEL(irq_stat)), %l4 ! &softirq_active
55 ld [%l4 + %lo(C_LABEL(irq_stat))], %g5 ! softirq_active
56 ld [%l4 + %lo(C_LABEL(irq_stat) + 4)], %g4 ! softirq_mask
58 be C_LABEL(ret_trap_lockless_ipi)
60 call C_LABEL(do_softirq)
63 C_LABEL(ret_trap_lockless_ipi):
64 andcc %t_psr, PSR_PS, %g0
73 ld [%curptr + AOFF_task_need_resched], %g2
76 ld [%curptr + AOFF_task_sigpending], %g2
78 call C_LABEL(schedule)
81 ld [%curptr + AOFF_task_sigpending], %g2
84 bz,a ret_trap_continue
85 ld [%sp + REGWIN_SZ + PT_PSR], %t_psr
90 call C_LABEL(do_signal)
91 add %sp, REGWIN_SZ, %o1 ! pt_regs ptr
94 ld [%sp + REGWIN_SZ + PT_PSR], %t_psr
100 ld [%curptr + AOFF_task_thread + AOFF_thread_w_saved], %twin_tmp1
101 orcc %g0, %twin_tmp1, %g0
102 be ret_trap_nobufwins
105 wr %t_psr, PSR_ET, %psr
109 call C_LABEL(try_to_clear_window_buffer)
110 add %sp, REGWIN_SZ, %o0
113 ld [%curptr + AOFF_task_sigpending], %g2
116 /* Load up the user's out registers so we can pull
117 * a window from the stack, if necessary.
121 /* If there are already live user windows in the
122 * set we can return from trap safely.
124 ld [%curptr + AOFF_task_thread + AOFF_thread_uwinmask], %twin_tmp1
125 orcc %g0, %twin_tmp1, %g0
126 bne ret_trap_userwins_ok
129 /* Calculate new %wim, we have to pull a register
130 * window from the users stack.
132 ret_trap_pull_one_window:
134 sll %t_wim, 0x1, %twin_tmp1
135 rtrap_patch1: srl %t_wim, 0x7, %glob_tmp
136 or %glob_tmp, %twin_tmp1, %glob_tmp
137 rtrap_patch2: and %glob_tmp, 0xff, %glob_tmp
139 wr %glob_tmp, 0x0, %wim
141 /* Here comes the architecture specific
142 * branch to the user stack checking routine
143 * for return from traps.
145 .globl C_LABEL(rtrap_mmu_patchme)
146 C_LABEL(rtrap_mmu_patchme): b C_LABEL(sun4c_rett_stackchk)
149 ret_trap_userwins_ok:
150 LOAD_PT_PRIV(sp, t_psr, t_pc, t_npc)
151 or %t_pc, %t_npc, %g2
156 b ret_trap_unaligned_pc
157 add %sp, REGWIN_SZ, %o0
169 ret_trap_unaligned_pc:
170 ld [%sp + REGWIN_SZ + PT_PC], %o1
171 ld [%sp + REGWIN_SZ + PT_NPC], %o2
172 ld [%sp + REGWIN_SZ + PT_PSR], %o3
174 wr %t_wim, 0x0, %wim ! or else...
176 wr %t_psr, PSR_ET, %psr
179 call C_LABEL(do_memaccess_unaligned)
183 ld [%curptr + AOFF_task_sigpending], %g2
186 /* Will the rett land us in the invalid window? */
189 rtrap_patch3: srl %g1, 8, %g2
193 be 1f ! Nope, just return from the trap
196 /* We have to grab a window before returning. */
197 rtrap_patch4: srl %g2, 7, %g2
199 rtrap_patch5: and %g1, 0xff, %g1
203 /* Grrr, make sure we load from the right %sp... */
204 LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
206 restore %g0, %g0, %g0
211 /* Reload the entire frame in case this is from a
212 * kernel system call or whatever...
215 LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
223 ret_trap_user_stack_is_bolixed:
226 wr %t_psr, PSR_ET, %psr
229 call C_LABEL(window_ret_fault)
230 add %sp, REGWIN_SZ, %o0
233 ld [%curptr + AOFF_task_sigpending], %g2
235 .globl C_LABEL(sun4c_rett_stackchk)
236 C_LABEL(sun4c_rett_stackchk):
238 and %fp, 0xfff, %g1 ! delay slot
240 b ret_trap_user_stack_is_bolixed + 0x4
243 /* See if we have to check the sanity of one page or two */
250 andncc %g1, 0xff8, %g0
252 /* %sp is in vma hole, yuck */
253 b ret_trap_user_stack_is_bolixed + 0x4
257 be sun4c_rett_onepage /* Only one page to check */
258 lda [%fp] ASI_PTE, %g2
266 lda [%g1] ASI_PTE, %g2
268 /* Second page is in vma hole */
269 b ret_trap_user_stack_is_bolixed + 0x4
275 bne sun4c_rett_onepage
276 lda [%fp] ASI_PTE, %g2
278 /* Second page has bad perms */
279 b ret_trap_user_stack_is_bolixed + 0x4
286 restore %g0, %g0, %g0
288 /* A page had bad page permissions, losing... */
289 b ret_trap_user_stack_is_bolixed + 0x4
292 /* Whee, things are ok, load the window and continue. */
296 b ret_trap_userwins_ok
299 .globl C_LABEL(srmmu_rett_stackchk)
300 C_LABEL(srmmu_rett_stackchk):
301 bne ret_trap_user_stack_is_bolixed
302 sethi %hi(PAGE_OFFSET), %g1
304 bleu ret_trap_user_stack_is_bolixed
306 lda [%g1] ASI_M_MMUREGS, %g0
308 lda [%g0] ASI_M_MMUREGS, %g1
310 sta %g1, [%g0] ASI_M_MMUREGS
312 restore %g0, %g0, %g0
319 sta %g1, [%g0] ASI_M_MMUREGS
322 lda [%g2] ASI_M_MMUREGS, %g2
325 lda [%g1] ASI_M_MMUREGS, %g1
327 be ret_trap_userwins_ok
330 b,a ret_trap_user_stack_is_bolixed