1 /* $Id: rtrap.S,v 1.58 2002/01/31 03:30:05 davem Exp $
2 * rtrap.S: Return from Sparc trap low-level code.
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
8 #include <asm/ptrace.h>
12 #include <asm/contregs.h>
13 #include <asm/winmacro.h>
14 #include <asm/asmmacro.h>
15 #include <asm/thread_info.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 ret_trap_lockless_ipi
51 ret_trap_lockless_ipi:
52 andcc %t_psr, PSR_PS, %g0
61 ld [%curptr + TI_FLAGS], %g2
62 andcc %g2, (_TIF_NEED_RESCHED), %g0
69 ld [%curptr + TI_FLAGS], %g2
71 andcc %g2, (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK), %g0
72 bz,a ret_trap_continue
73 ld [%sp + STACKFRAME_SZ + PT_PSR], %t_psr
78 add %sp, STACKFRAME_SZ, %o0 ! pt_regs ptr
81 ld [%sp + STACKFRAME_SZ + PT_PSR], %t_psr
87 ld [%curptr + TI_W_SAVED], %twin_tmp1
88 orcc %g0, %twin_tmp1, %g0
92 wr %t_psr, PSR_ET, %psr
96 call try_to_clear_window_buffer
97 add %sp, STACKFRAME_SZ, %o0
100 ld [%curptr + TI_FLAGS], %g2
103 /* Load up the user's out registers so we can pull
104 * a window from the stack, if necessary.
108 /* If there are already live user windows in the
109 * set we can return from trap safely.
111 ld [%curptr + TI_UWINMASK], %twin_tmp1
112 orcc %g0, %twin_tmp1, %g0
113 bne ret_trap_userwins_ok
116 /* Calculate new %wim, we have to pull a register
117 * window from the users stack.
119 ret_trap_pull_one_window:
121 sll %t_wim, 0x1, %twin_tmp1
122 rtrap_patch1: srl %t_wim, 0x7, %glob_tmp
123 or %glob_tmp, %twin_tmp1, %glob_tmp
124 rtrap_patch2: and %glob_tmp, 0xff, %glob_tmp
126 wr %glob_tmp, 0x0, %wim
128 /* Here comes the architecture specific
129 * branch to the user stack checking routine
130 * for return from traps.
132 .globl rtrap_mmu_patchme
133 rtrap_mmu_patchme: b sun4c_rett_stackchk
136 ret_trap_userwins_ok:
137 LOAD_PT_PRIV(sp, t_psr, t_pc, t_npc)
138 or %t_pc, %t_npc, %g2
143 b ret_trap_unaligned_pc
144 add %sp, STACKFRAME_SZ, %o0
156 ret_trap_unaligned_pc:
157 ld [%sp + STACKFRAME_SZ + PT_PC], %o1
158 ld [%sp + STACKFRAME_SZ + PT_NPC], %o2
159 ld [%sp + STACKFRAME_SZ + PT_PSR], %o3
161 wr %t_wim, 0x0, %wim ! or else...
163 wr %t_psr, PSR_ET, %psr
166 call do_memaccess_unaligned
170 ld [%curptr + TI_FLAGS], %g2
173 /* Will the rett land us in the invalid window? */
176 rtrap_patch3: srl %g1, 8, %g2
180 be 1f ! Nope, just return from the trap
183 /* We have to grab a window before returning. */
184 rtrap_patch4: srl %g2, 7, %g2
186 rtrap_patch5: and %g1, 0xff, %g1
190 /* Grrr, make sure we load from the right %sp... */
191 LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
193 restore %g0, %g0, %g0
198 /* Reload the entire frame in case this is from a
199 * kernel system call or whatever...
202 LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
210 ret_trap_user_stack_is_bolixed:
213 wr %t_psr, PSR_ET, %psr
216 call window_ret_fault
217 add %sp, STACKFRAME_SZ, %o0
220 ld [%curptr + TI_FLAGS], %g2
223 .globl sun4c_rett_stackchk
226 and %fp, 0xfff, %g1 ! delay slot
228 b ret_trap_user_stack_is_bolixed + 0x4
231 /* See if we have to check the sanity of one page or two */
238 andncc %g1, 0xff8, %g0
240 /* %sp is in vma hole, yuck */
241 b ret_trap_user_stack_is_bolixed + 0x4
245 be sun4c_rett_onepage /* Only one page to check */
246 lda [%fp] ASI_PTE, %g2
254 lda [%g1] ASI_PTE, %g2
256 /* Second page is in vma hole */
257 b ret_trap_user_stack_is_bolixed + 0x4
263 bne sun4c_rett_onepage
264 lda [%fp] ASI_PTE, %g2
266 /* Second page has bad perms */
267 b ret_trap_user_stack_is_bolixed + 0x4
274 restore %g0, %g0, %g0
276 /* A page had bad page permissions, losing... */
277 b ret_trap_user_stack_is_bolixed + 0x4
280 /* Whee, things are ok, load the window and continue. */
284 b ret_trap_userwins_ok
287 .globl srmmu_rett_stackchk
289 bne ret_trap_user_stack_is_bolixed
290 sethi %hi(PAGE_OFFSET), %g1
292 bleu ret_trap_user_stack_is_bolixed
294 lda [%g1] ASI_M_MMUREGS, %g0
296 lda [%g0] ASI_M_MMUREGS, %g1
298 sta %g1, [%g0] ASI_M_MMUREGS
300 restore %g0, %g0, %g0
307 sta %g1, [%g0] ASI_M_MMUREGS
310 lda [%g2] ASI_M_MMUREGS, %g2
313 lda [%g1] ASI_M_MMUREGS, %g1
315 be ret_trap_userwins_ok
318 b,a ret_trap_user_stack_is_bolixed