1 /* $Id: rtrap.S,v 1.47 1999/07/30 09:35:23 davem Exp $
2 * rtrap.S: Preparing for return from trap on Sparc V9.
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
9 #include <asm/pstate.h>
10 #include <asm/ptrace.h>
11 #include <asm/spitfire.h>
13 #include <asm/visasm.h>
14 #include <asm/processor.h>
16 #define PTREGS_OFF (STACK_BIAS + REGWIN_SZ)
20 .globl rtrap_clr_l6, rtrap
23 rtrap: sethi %hi(bh_active), %l2
24 sethi %hi(bh_mask), %l1
25 ldx [%l2 + %lo(bh_active)], %l4
26 ldx [%l1 + %lo(bh_mask)], %l7
33 2: ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
34 sethi %hi(0xf << 20), %l4
35 andcc %l1, TSTATE_PRIV, %l3
41 andn %l7, PSTATE_IE, %l7
43 ldub [%g6 + AOFF_task_thread + AOFF_thread_fpdepth], %l5
44 brz,pt %l5, rt_continue
46 add %g6, AOFF_task_thread + AOFF_thread_fpsaved, %l6
49 add %g6, AOFF_task_thread + AOFF_thread_gsr, %o1
50 andcc %l2, (FPRS_FEF|FPRS_DU), %g0
53 andcc %l2, FPRS_FEF, %g0
57 wr %g5, FPRS_FEF, %fprs
59 add %g6, AOFF_task_thread + AOFF_thread_xfsr, %o1
60 membar #StoreLoad | #LoadLoad
62 add %g6, AOFF_task_fpregs, %o3
64 add %g6, AOFF_task_fpregs+0x40, %o4
65 ldda [%o3 + %o2] ASI_BLK_P, %f0
66 ldda [%o4 + %o2] ASI_BLK_P, %f16
67 1: andcc %l2, FPRS_DU, %g0
71 ldda [%o3 + %o2] ASI_BLK_P, %f32
72 ldda [%o4 + %o2] ASI_BLK_P, %f48
75 2: stb %l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]
76 rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
77 ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
78 ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
80 ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
81 ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
82 ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
83 ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
85 wrpr %l7, PSTATE_AG, %pstate
86 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
87 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
88 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
89 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
90 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
91 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
92 ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
94 ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
95 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
96 ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
97 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
103 wrpr %l1, %g0, %tstate
106 brnz,pn %l3, kern_rtt
107 mov PRIMARY_CONTEXT, %l7
108 ldxa [%l7 + %l7] ASI_DMMU, %l0
109 stxa %l0, [%l7] ASI_DMMU
115 wrpr %l2, %g0, %canrestore
116 wrpr %l1, %g0, %wstate
117 wrpr %g0, %g0, %otherwin
119 rdpr %canrestore, %g1
121 wrpr %g1, 0x0, %cleanwin
125 to_user: ldx [%g6 + AOFF_task_need_resched], %l0
126 wrpr %l7, PSTATE_IE, %pstate
128 be,a,pt %xcc, check_signal
130 lduw [%g6 + AOFF_task_sigpending], %l0
133 lduw [%g6 + AOFF_task_sigpending], %l0
134 check_signal: brz,a,pt %l0, check_user_wins
140 add %sp, STACK_BIAS + REGWIN_SZ, %o1
143 /* We must not take any traps between here and the actual
144 * return to user-space. If we do we risk having windows
145 * saved to the thread struct between the test and the
146 * actual return from trap. --DaveM
149 wrpr %l7, 0x0, %pstate
150 ldub [%g6 + AOFF_task_thread + AOFF_thread_w_saved], %o2
152 sethi %hi(TSTATE_PEF), %l6
154 wrpr %l7, PSTATE_IE, %pstate
155 call fault_in_user_windows
156 add %sp, STACK_BIAS + REGWIN_SZ, %o0
157 /* It is OK to leave interrupts on now because if
158 * fault_in_user_windows has returned it has left us
159 * with a clean user stack state.
164 add %sp, STACK_BIAS + REGWIN_SZ, %o0
166 ldub [%g6 + AOFF_task_thread + AOFF_thread_flags], %l5
167 andcc %l5, SPARC_FLAG_PERFCTR, %g0
171 /* Don't forget to preserve user window invariants. */
172 wrpr %l7, PSTATE_IE, %pstate
175 wrpr %l7, 0x0, %pstate
176 ldub [%g6 + AOFF_task_thread + AOFF_thread_w_saved], %o2
178 sethi %hi(TSTATE_PEF), %l6
179 wrpr %l7, PSTATE_IE, %pstate
180 call fault_in_user_windows
181 add %sp, STACK_BIAS + REGWIN_SZ, %o0
185 be,pt %xcc, rt_continue
186 stb %g0, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth] ! This is neccessary for non-syscall rtraps only
189 andcc %l5, FPRS_FEF, %g0
190 be,a,pn %icc, rt_continue
192 ba,pt %xcc, rt_continue
195 5: wr %g0, FPRS_FEF, %fprs
196 membar #StoreLoad | #LoadLoad
198 add %g6, AOFF_task_fpregs+0x80, %o3
199 add %g6, AOFF_task_fpregs+0xc0, %o4
200 ldda [%o3 + %o2] ASI_BLK_P, %f32
201 ldda [%o4 + %o2] ASI_BLK_P, %f48
203 wr %g0, FPRS_DU, %fprs
204 ba,pt %xcc, rt_continue
205 stb %l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]