- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / arch / sparc64 / kernel / rtrap.S
blob729ecd9117586bb4793f79b93ecd73aa34a311bc
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.
3  *
4  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5  * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
6  */
8 #include <asm/asi.h>
9 #include <asm/pstate.h>
10 #include <asm/ptrace.h>
11 #include <asm/spitfire.h>
12 #include <asm/head.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)
21 #if 0
22 #define         RTRAP_CHECK             call rtrap_check;  add %sp, (STACK_BIAS+REGWIN_SZ), %o0;
23 #else
24 #define         RTRAP_CHECK
25 #endif
27                 .text
29                 .align                  32
30 __handle_softirq:
31                 call                    do_softirq
32                  nop
33                 ba,a,pt                 %xcc, __handle_softirq_continue
34                  nop
35 __handle_preemption:
36                 call                    schedule
37                  nop
38                 ba,pt                   %xcc, __handle_preemption_continue
39                  nop
40 __handle_user_windows:
41                 wrpr                    %g0, RTRAP_PSTATE, %pstate
42                 call                    fault_in_user_windows
43                  nop
44                 ba,pt                   %xcc, __handle_user_windows_continue
45                  nop
46 __handle_perfctrs:
47                 /* Don't forget to preserve user window invariants. */
48                 wrpr                    %g0, RTRAP_PSTATE, %pstate
49                 call                    update_perfctrs
50                  nop
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
58                  nop
59                 ba,pt                   %xcc, __handle_perfctrs_continue
60                  nop
61 __handle_userfpu:
62                 rd                      %fprs, %l5
63                 andcc                   %l5, FPRS_FEF, %g0
64                 be,a,pn                 %icc, __handle_userfpu_continue
65                  andn                   %l1, %l6, %l1
66                 ba,a,pt                 %xcc, __handle_userfpu_continue
67 __handle_signal:
68                 clr                     %o0
69                 mov                     %l5, %o2
70                 mov                     %l6, %o3
71                 call                    do_signal
72                  add                    %sp, STACK_BIAS + REGWIN_SZ, %o1
73                 clr                     %l6
75                 /* Signal delivery can modify pt_regs tstate, so we must
76                  * reload it.
77                  */
78                 ldx                     [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
79                 sethi                   %hi(0xf << 20), %l4
80                 and                     %l1, %l4, %l4
81                 ba,pt                   %xcc, __handle_signal_continue
82                  andn                   %l1, %l4, %l1
84                 .align                  64
85                 .globl                  rtrap_clr_l6, rtrap
86 rtrap_clr_l6:   clr                     %l6
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
90                 sllx                    %l0, 6, %l0
91                 ldx                     [%l2 + %l0], %l1        ! softirq_active + softirq_mask
92                 srlx                    %l1, 32, %l2
93                 andcc                   %l1, %l2, %g0
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
100                 and                     %l1, %l4, %l4
101                 bne,pn                  %icc, to_kernel
102                  andn                   %l1, %l4, %l1
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
109                  nop
110 __handle_signal_continue:
111 check_user_wins:
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:
118                 RTRAP_CHECK
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:
123                  andcc                  %l1, %l6, %g0
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
150                 wr                      %o3, %g0, %y
151                 srl                     %l4, 20, %l4
152                 wrpr                    %l4, 0x0, %pil
153                 wrpr                    %g0, 0x1, %tl
154                 wrpr                    %l1, %g0, %tstate
155                 wrpr                    %l2, %g0, %tpc
156                 wrpr                    %o2, %g0, %tnpc
158                 brnz,pn                 %l3, kern_rtt
159                  mov                    PRIMARY_CONTEXT, %l7
160                 ldxa                    [%l7 + %l7] ASI_DMMU, %l0
161                 stxa                    %l0, [%l7] ASI_DMMU
162                 flush                   %g6
163                 rdpr                    %wstate, %l1
164                 rdpr                    %otherwin, %l2
165                 srl                     %l1, 3, %l1
167                 wrpr                    %l2, %g0, %canrestore
168                 wrpr                    %l1, %g0, %wstate
169                 wrpr                    %g0, %g0, %otherwin
170                 restore
171                 rdpr                    %canrestore, %g1
172                 wrpr                    %g1, 0x0, %cleanwin
173                 retry
174                 nop
176 kern_rtt:       restore
177                 retry
178 to_kernel:      ldub                    [%g6 + AOFF_task_thread + AOFF_thread_fpdepth], %l5
179                 brz,pt                  %l5, rt_continue
180                  srl                    %l5, 1, %o0
181                 add                     %g6, AOFF_task_thread + AOFF_thread_fpsaved, %l6
182                 ldub                    [%l6 + %o0], %l2
183                 sub                     %l5, 2, %l5
185                 add                     %g6, AOFF_task_thread + AOFF_thread_gsr, %o1
186                 andcc                   %l2, (FPRS_FEF|FPRS_DU), %g0
187                 be,pt                   %icc, 2f
188                  and                    %l2, FPRS_DL, %l6
189                 andcc                   %l2, FPRS_FEF, %g0
190                 be,pn                   %icc, 5f
191                  sll                    %o0, 3, %o5
192                 rd                      %fprs, %g5
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
198                 sll                     %o0, 8, %o2
199                 add                     %g6, AOFF_task_fpregs, %o3
200                 brz,pn                  %l6, 1f
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
206                 be,pn                   %icc, 1f
207                  wr                     %g5, 0, %gsr
208                 add                     %o2, 0x80, %o2
209                 ldda                    [%o3 + %o2] ASI_BLK_P, %f32
210                 ldda                    [%o4 + %o2] ASI_BLK_P, %f48
212 1:              membar                  #Sync
213                 ldx                     [%o1 + %o5], %fsr
214 2:              stb                     %l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]
215                 ba,pt                   %xcc, rt_continue
216                  nop
217 5:              wr                      %g0, FPRS_FEF, %fprs
218                 membar                  #StoreLoad | #LoadLoad
219                 sll                     %o0, 8, %o2
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
225                 membar                  #Sync
226                 wr                      %g0, FPRS_DU, %fprs
227                 ba,pt                   %xcc, rt_continue
228                  stb                    %l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]
230 #undef PTREGS_OFF