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
53 sethi %hi(PSR_SYSCALL), %g1
55 andn %t_psr, %g1, %t_psr
62 ld [%curptr + TI_FLAGS], %g2
63 andcc %g2, (_TIF_NEED_RESCHED), %g0
70 ld [%curptr + TI_FLAGS], %g2
72 andcc %g2, (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK), %g0
73 bz,a ret_trap_continue
74 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
84 sethi %hi(PSR_SYSCALL), %g1
85 andn %t_psr, %g1, %t_psr
89 ld [%curptr + TI_W_SAVED], %twin_tmp1
90 orcc %g0, %twin_tmp1, %g0
94 wr %t_psr, PSR_ET, %psr
98 call try_to_clear_window_buffer
99 add %sp, STACKFRAME_SZ, %o0
102 ld [%curptr + TI_FLAGS], %g2
105 /* Load up the user's out registers so we can pull
106 * a window from the stack, if necessary.
110 /* If there are already live user windows in the
111 * set we can return from trap safely.
113 ld [%curptr + TI_UWINMASK], %twin_tmp1
114 orcc %g0, %twin_tmp1, %g0
115 bne ret_trap_userwins_ok
118 /* Calculate new %wim, we have to pull a register
119 * window from the users stack.
121 ret_trap_pull_one_window:
123 sll %t_wim, 0x1, %twin_tmp1
124 rtrap_patch1: srl %t_wim, 0x7, %glob_tmp
125 or %glob_tmp, %twin_tmp1, %glob_tmp
126 rtrap_patch2: and %glob_tmp, 0xff, %glob_tmp
128 wr %glob_tmp, 0x0, %wim
130 /* Here comes the architecture specific
131 * branch to the user stack checking routine
132 * for return from traps.
134 .globl rtrap_mmu_patchme
135 rtrap_mmu_patchme: b sun4c_rett_stackchk
138 ret_trap_userwins_ok:
139 LOAD_PT_PRIV(sp, t_psr, t_pc, t_npc)
140 or %t_pc, %t_npc, %g2
142 sethi %hi(PSR_SYSCALL), %g2
144 andn %t_psr, %g2, %t_psr
146 b ret_trap_unaligned_pc
147 add %sp, STACKFRAME_SZ, %o0
159 ret_trap_unaligned_pc:
160 ld [%sp + STACKFRAME_SZ + PT_PC], %o1
161 ld [%sp + STACKFRAME_SZ + PT_NPC], %o2
162 ld [%sp + STACKFRAME_SZ + PT_PSR], %o3
164 wr %t_wim, 0x0, %wim ! or else...
166 wr %t_psr, PSR_ET, %psr
169 call do_memaccess_unaligned
173 ld [%curptr + TI_FLAGS], %g2
176 /* Will the rett land us in the invalid window? */
179 rtrap_patch3: srl %g1, 8, %g2
183 be 1f ! Nope, just return from the trap
186 /* We have to grab a window before returning. */
187 rtrap_patch4: srl %g2, 7, %g2
189 rtrap_patch5: and %g1, 0xff, %g1
193 /* Grrr, make sure we load from the right %sp... */
194 LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
196 restore %g0, %g0, %g0
201 /* Reload the entire frame in case this is from a
202 * kernel system call or whatever...
205 LOAD_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
207 sethi %hi(PSR_SYSCALL), %twin_tmp1
208 andn %t_psr, %twin_tmp1, %t_psr
215 ret_trap_user_stack_is_bolixed:
218 wr %t_psr, PSR_ET, %psr
221 call window_ret_fault
222 add %sp, STACKFRAME_SZ, %o0
225 ld [%curptr + TI_FLAGS], %g2
229 and %fp, 0xfff, %g1 ! delay slot
231 b ret_trap_user_stack_is_bolixed + 0x4
234 /* See if we have to check the sanity of one page or two */
241 andncc %g1, 0xff8, %g0
243 /* %sp is in vma hole, yuck */
244 b ret_trap_user_stack_is_bolixed + 0x4
248 be sun4c_rett_onepage /* Only one page to check */
249 lda [%fp] ASI_PTE, %g2
257 lda [%g1] ASI_PTE, %g2
259 /* Second page is in vma hole */
260 b ret_trap_user_stack_is_bolixed + 0x4
266 bne sun4c_rett_onepage
267 lda [%fp] ASI_PTE, %g2
269 /* Second page has bad perms */
270 b ret_trap_user_stack_is_bolixed + 0x4
277 restore %g0, %g0, %g0
279 /* A page had bad page permissions, losing... */
280 b ret_trap_user_stack_is_bolixed + 0x4
283 /* Whee, things are ok, load the window and continue. */
287 b ret_trap_userwins_ok
290 .globl srmmu_rett_stackchk
292 bne ret_trap_user_stack_is_bolixed
293 sethi %hi(PAGE_OFFSET), %g1
295 bleu ret_trap_user_stack_is_bolixed
297 lda [%g1] ASI_M_MMUREGS, %g0
299 lda [%g0] ASI_M_MMUREGS, %g1
301 sta %g1, [%g0] ASI_M_MMUREGS
303 restore %g0, %g0, %g0
310 sta %g1, [%g0] ASI_M_MMUREGS
313 lda [%g2] ASI_M_MMUREGS, %g2
316 lda [%g1] ASI_M_MMUREGS, %g1
318 be ret_trap_userwins_ok
321 b,a ret_trap_user_stack_is_bolixed