summaryrefslogtreecommitdiffstats
path: root/arch/sparc64/kernel/rtrap.S
blob: d059a5a282b70459954bef926b901ec8f82a7289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* $Id: rtrap.S,v 1.48 2000/02/09 11:15:07 davem Exp $
 * rtrap.S: Preparing for return from trap on Sparc V9.
 *
 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
 */

#include <asm/asi.h>
#include <asm/pstate.h>
#include <asm/ptrace.h>
#include <asm/spitfire.h>
#include <asm/head.h>
#include <asm/visasm.h>
#include <asm/processor.h>

#define		PTREGS_OFF		(STACK_BIAS + REGWIN_SZ)

		.text
		.align			32
		.globl			rtrap_clr_l6, rtrap
rtrap_clr_l6:	clr			%l6
		/* Fall through */
rtrap:		lduw			[%g6 + AOFF_task_processor], %l0
		sethi			%hi(softirq_state), %l2
		or			%l2, %lo(softirq_state), %l2
		sllx			%l0, 6, %l0
		ldx			[%l2 + %l0], %l1
		srlx			%l1, 32, %l2

		andcc			%l1, %l2, %g0
		be,pt			%icc, 2f
		 nop
		call			do_softirq
		 nop
2:		ldx			[%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
		sethi			%hi(0xf << 20), %l4
		andcc			%l1, TSTATE_PRIV, %l3

		and			%l1, %l4, %l4
		rdpr			%pstate, %l7
		andn			%l1, %l4, %l1
		be,pt			%icc, to_user
		 andn			%l7, PSTATE_IE, %l7

		ldub			[%g6 + AOFF_task_thread + AOFF_thread_fpdepth], %l5
		brz,pt			%l5, rt_continue
		 srl			%l5, 1, %o0
		add			%g6, AOFF_task_thread + AOFF_thread_fpsaved, %l6
		ldub			[%l6 + %o0], %l2
		sub			%l5, 2, %l5
		add			%g6, AOFF_task_thread + AOFF_thread_gsr, %o1
		andcc			%l2, (FPRS_FEF|FPRS_DU), %g0
		be,pt			%icc, 2f
		 and			%l2, FPRS_DL, %l6
		andcc			%l2, FPRS_FEF, %g0
		be,pn			%icc, 5f
		 sll			%o0, 3, %o5
		rd			%fprs, %g5
		wr			%g5, FPRS_FEF, %fprs
		ldub			[%o1 + %o0], %g5
		add			%g6, AOFF_task_thread + AOFF_thread_xfsr, %o1
		membar			#StoreLoad | #LoadLoad
		sll			%o0, 8, %o2
		add			%g6, AOFF_task_fpregs, %o3
		brz,pn			%l6, 1f
		 add			%g6, AOFF_task_fpregs+0x40, %o4
		ldda			[%o3 + %o2] ASI_BLK_P, %f0
		ldda			[%o4 + %o2] ASI_BLK_P, %f16
1:		andcc			%l2, FPRS_DU, %g0
		be,pn			%icc, 1f
		 wr			%g5, 0, %gsr
		add			%o2, 0x80, %o2
		ldda			[%o3 + %o2] ASI_BLK_P, %f32
		ldda			[%o4 + %o2] ASI_BLK_P, %f48
1:		membar			#Sync
		ldx			[%o1 + %o5], %fsr
2:		stb			%l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]
rt_continue:	ldx			[%sp + PTREGS_OFF + PT_V9_G1], %g1
		ldx			[%sp + PTREGS_OFF + PT_V9_G2], %g2
		ldx			[%sp + PTREGS_OFF + PT_V9_G3], %g3
		mov			%g6, %o5
		ldx			[%sp + PTREGS_OFF + PT_V9_G4], %g4
		ldx			[%sp + PTREGS_OFF + PT_V9_G5], %g5
		ldx			[%sp + PTREGS_OFF + PT_V9_G6], %g6
		ldx			[%sp + PTREGS_OFF + PT_V9_G7], %g7

		wrpr			%l7, PSTATE_AG, %pstate
		ldx			[%sp + PTREGS_OFF + PT_V9_I0], %i0
		ldx			[%sp + PTREGS_OFF + PT_V9_I1], %i1
		ldx			[%sp + PTREGS_OFF + PT_V9_I2], %i2
		ldx			[%sp + PTREGS_OFF + PT_V9_I3], %i3
		ldx			[%sp + PTREGS_OFF + PT_V9_I4], %i4
		ldx			[%sp + PTREGS_OFF + PT_V9_I5], %i5
		ldx			[%sp + PTREGS_OFF + PT_V9_I6], %i6

		ldx			[%sp + PTREGS_OFF + PT_V9_I7], %i7
		ld			[%sp + PTREGS_OFF + PT_V9_Y], %o3
		ldx			[%sp + PTREGS_OFF + PT_V9_TPC], %l2
		ldx			[%sp + PTREGS_OFF + PT_V9_TNPC], %o2
		wr			%o3, %g0, %y
		srl			%l4, 20, %l4
		wrpr			%l4, 0x0, %pil
		wrpr			%g0, 0x1, %tl

		wrpr			%l1, %g0, %tstate
		wrpr			%l2, %g0, %tpc
		wrpr			%o2, %g0, %tnpc
		brnz,pn			%l3, kern_rtt
		 mov			PRIMARY_CONTEXT, %l7
		ldxa			[%l7 + %l7] ASI_DMMU, %l0
		stxa			%l0, [%l7] ASI_DMMU
		flush			%o5

		rdpr			%wstate, %l1
		rdpr			%otherwin, %l2
		srl			%l1, 3, %l1
		wrpr			%l2, %g0, %canrestore
		wrpr			%l1, %g0, %wstate
		wrpr			%g0, %g0, %otherwin
		restore
		rdpr			%canrestore, %g1

		wrpr			%g1, 0x0, %cleanwin
		retry
kern_rtt:	restore
		retry
to_user:	ldx			[%g6 + AOFF_task_need_resched], %l0
		wrpr			%l7, PSTATE_IE, %pstate
		orcc			%g0, %l0, %g0
		be,a,pt			%xcc, check_signal

		 lduw			[%g6 + AOFF_task_sigpending], %l0
		call			schedule
		 nop
		lduw			[%g6 + AOFF_task_sigpending], %l0
check_signal:	brz,a,pt		%l0, check_user_wins
		 nop
		clr			%o0
		mov			%l5, %o2  
		mov			%l6, %o3
		call			do_signal
		 add			%sp, STACK_BIAS + REGWIN_SZ, %o1
		clr			%l6

		/* We must not take any traps between here and the actual
		 * return to user-space.  If we do we risk having windows
		 * saved to the thread struct between the test and the
		 * actual return from trap.  --DaveM
		 */
check_user_wins:
		wrpr			%l7, 0x0, %pstate
		ldub			[%g6 + AOFF_task_thread + AOFF_thread_w_saved], %o2
		brz,pt			%o2, 1f
		 sethi			%hi(TSTATE_PEF), %l6

		wrpr			%l7, PSTATE_IE, %pstate
		call			fault_in_user_windows
		 add			%sp, STACK_BIAS + REGWIN_SZ, %o0
		/* It is OK to leave interrupts on now because if
		 * fault_in_user_windows has returned it has left us
		 * with a clean user stack state.
		 */
1:
#if 0
		call			rtrap_check
		 add			%sp, STACK_BIAS + REGWIN_SZ, %o0
#endif
		ldub			[%g6 + AOFF_task_thread + AOFF_thread_flags], %l5
		andcc			%l5, SPARC_FLAG_PERFCTR, %g0
		be,pt			%xcc, 1f
		 nop

		/* Don't forget to preserve user window invariants. */
		wrpr			%l7, PSTATE_IE, %pstate
		call			update_perfctrs
		 nop
		wrpr			%l7, 0x0, %pstate
		ldub			[%g6 + AOFF_task_thread + AOFF_thread_w_saved], %o2
		brz,pt			%o2, 1f
		 sethi			%hi(TSTATE_PEF), %l6
		wrpr			%l7, PSTATE_IE, %pstate
		call			fault_in_user_windows
		 add			%sp, STACK_BIAS + REGWIN_SZ, %o0

1:
		andcc			%l1, %l6, %g0
		be,pt			%xcc, rt_continue
		 stb			%g0, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth] ! This is neccessary for non-syscall rtraps only

		rd			%fprs, %l5
		andcc			%l5, FPRS_FEF, %g0
		be,a,pn			%icc, rt_continue
		 andn			%l1, %l6, %l1
		ba,pt			%xcc, rt_continue
		 nop

5:		wr			%g0, FPRS_FEF, %fprs
		membar			#StoreLoad | #LoadLoad
		sll			%o0, 8, %o2
		add			%g6, AOFF_task_fpregs+0x80, %o3
		add			%g6, AOFF_task_fpregs+0xc0, %o4
		ldda			[%o3 + %o2] ASI_BLK_P, %f32
		ldda			[%o4 + %o2] ASI_BLK_P, %f48
1:		membar			#Sync
		wr			%g0, FPRS_DU, %fprs
		ba,pt			%xcc, rt_continue
		 stb			%l5, [%g6 + AOFF_task_thread + AOFF_thread_fpdepth]

#undef PTREGS_OFF