1 /* $Id: rtrap.S,v 1.53 2000/08/06 05:20:35 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)
17 #define RTRAP_PSTATE (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_IE)
18 #define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV)
19 #define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG)
22 #define RTRAP_CHECK call rtrap_check; add %sp, (STACK_BIAS+REGWIN_SZ), %o0;
33 ba,a,pt %xcc, __handle_softirq_continue
38 ba,pt %xcc, __handle_preemption_continue
40 __handle_user_windows:
41 wrpr %g0, RTRAP_PSTATE, %pstate
42 call fault_in_user_windows
44 ba,pt %xcc, __handle_user_windows_continue
47 /* Don't forget to preserve user window invariants. */
48 wrpr %g0, RTRAP_PSTATE, %pstate
51 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
52 ldub [%g6 + AOFF_task_thread + AOFF_thread_w_saved], %o2
53 brz,pt %o2, __handle_perfctrs_continue
54 sethi %hi(TSTATE_PEF), %l6
55 wrpr %g0, RTRAP_PSTATE, %pstate
57 call fault_in_user_windows
59 ba,pt %xcc, __handle_perfctrs_continue
63 andcc %l5, FPRS_FEF, %g0
64 be,a,pn %icc, __handle_userfpu_continue
66 ba,a,pt %xcc, __handle_userfpu_continue
72 add %sp, STACK_BIAS + REGWIN_SZ, %o1
75 /* Signal delivery can modify pt_regs tstate, so we must
78 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
79 sethi %hi(0xf << 20), %l4
81 ba,pt %xcc, __handle_signal_continue
85 .globl rtrap_clr_l6, rtrap
87 rtrap: lduw [%g6 + AOFF_task_processor], %l0
88 sethi %hi(irq_stat), %l2 ! &softirq_active
89 or %l2, %lo(irq_stat), %l2 ! &softirq_active
91 ldx [%l2 + %l0], %l1 ! softirq_active + softirq_mask
95 bne,pn %icc, __handle_softirq
96 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
97 __handle_softirq_continue:
98 sethi %hi(0xf << 20), %l4
99 andcc %l1, TSTATE_PRIV, %l3
101 bne,pn %icc, to_kernel
103 to_user: ldx [%g6 + AOFF_task_need_resched], %l0
105 brnz,pn %l0, __handle_preemption
106 __handle_preemption_continue:
107 lduw [%g6 + AOFF_task_sigpending], %l0
108 brnz,pn %l0, __handle_signal
110 __handle_signal_continue:
112 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
113 ldub [%g6 + AOFF_task_thread + AOFF_thread_w_saved], %o2
114 brnz,pn %o2, __handle_user_windows
115 sethi %hi(TSTATE_PEF), %l6
117 __handle_user_windows_continue:
119 ldub [%g6 + AOFF_task_thread + AOFF_thread_flags], %l5
120 andcc %l5, SPARC_FLAG_PERFCTR, %g0
121 bne,pn %xcc, __handle_perfctrs
122 __handle_perfctrs_continue:
124 bne,pn %xcc, __handle_userfpu
125 stb %g0, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth] ! This is neccessary for non-syscall rtraps only
126 __handle_userfpu_continue:
128 rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
129 ldx [%sp + PTREGS_OFF + PT_V9_G2], %g2
131 ldx [%sp + PTREGS_OFF + PT_V9_G3], %g3
132 ldx [%sp + PTREGS_OFF + PT_V9_G4], %g4
133 ldx [%sp + PTREGS_OFF + PT_V9_G5], %g5
134 ldx [%sp + PTREGS_OFF + PT_V9_G6], %g6
135 ldx [%sp + PTREGS_OFF + PT_V9_G7], %g7
136 wrpr %g0, RTRAP_PSTATE_AG_IRQOFF, %pstate
137 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
138 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
140 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
141 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
142 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
143 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
144 ldx [%sp + PTREGS_OFF + PT_V9_I6], %i6
145 ldx [%sp + PTREGS_OFF + PT_V9_I7], %i7
146 ldx [%sp + PTREGS_OFF + PT_V9_TPC], %l2
147 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %o2
149 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
154 wrpr %l1, %g0, %tstate
158 brnz,pn %l3, kern_rtt
159 mov PRIMARY_CONTEXT, %l7
160 ldxa [%l7 + %l7] ASI_DMMU, %l0
161 stxa %l0, [%l7] ASI_DMMU
167 wrpr %l2, %g0, %canrestore
168 wrpr %l1, %g0, %wstate
169 wrpr %g0, %g0, %otherwin
171 rdpr %canrestore, %g1
172 wrpr %g1, 0x0, %cleanwin
178 to_kernel: ldub [%g6 + AOFF_task_thread + AOFF_thread_fpdepth], %l5
179 brz,pt %l5, rt_continue
181 add %g6, AOFF_task_thread + AOFF_thread_fpsaved, %l6
182 ldub [%l6 + %o0], %l2
185 add %g6, AOFF_task_thread + AOFF_thread_gsr, %o1
186 andcc %l2, (FPRS_FEF|FPRS_DU), %g0
188 and %l2, FPRS_DL, %l6
189 andcc %l2, FPRS_FEF, %g0
194 wr %g5, FPRS_FEF, %fprs
195 ldub [%o1 + %o0], %g5
196 add %g6, AOFF_task_thread + AOFF_thread_xfsr, %o1
197 membar #StoreLoad | #LoadLoad
199 add %g6, AOFF_task_fpregs, %o3
201 add %g6, AOFF_task_fpregs+0x40, %o4
203 ldda [%o3 + %o2] ASI_BLK_P, %f0
204 ldda [%o4 + %o2] ASI_BLK_P, %f16
205 1: andcc %l2, FPRS_DU, %g0
209 ldda [%o3 + %o2] ASI_BLK_P, %f32
210 ldda [%o4 + %o2] ASI_BLK_P, %f48
213 ldx [%o1 + %o5], %fsr
214 2: stb %l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]
215 ba,pt %xcc, rt_continue
217 5: wr %g0, FPRS_FEF, %fprs
218 membar #StoreLoad | #LoadLoad
221 add %g6, AOFF_task_fpregs+0x80, %o3
222 add %g6, AOFF_task_fpregs+0xc0, %o4
223 ldda [%o3 + %o2] ASI_BLK_P, %f32
224 ldda [%o4 + %o2] ASI_BLK_P, %f48
226 wr %g0, FPRS_DU, %fprs
227 ba,pt %xcc, rt_continue
228 stb %l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]