xref: /linux/arch/sparc/kernel/etrap_64.S (revision a88b5ba8bd8ac18aad65ee6c6a254e2e74876db3)
1*a88b5ba8SSam Ravnborg/*
2*a88b5ba8SSam Ravnborg * etrap.S: Preparing for entry into the kernel on Sparc V9.
3*a88b5ba8SSam Ravnborg *
4*a88b5ba8SSam Ravnborg * Copyright (C) 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5*a88b5ba8SSam Ravnborg * Copyright (C) 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
6*a88b5ba8SSam Ravnborg */
7*a88b5ba8SSam Ravnborg
8*a88b5ba8SSam Ravnborg
9*a88b5ba8SSam Ravnborg#include <asm/asi.h>
10*a88b5ba8SSam Ravnborg#include <asm/pstate.h>
11*a88b5ba8SSam Ravnborg#include <asm/ptrace.h>
12*a88b5ba8SSam Ravnborg#include <asm/page.h>
13*a88b5ba8SSam Ravnborg#include <asm/spitfire.h>
14*a88b5ba8SSam Ravnborg#include <asm/head.h>
15*a88b5ba8SSam Ravnborg#include <asm/processor.h>
16*a88b5ba8SSam Ravnborg#include <asm/mmu.h>
17*a88b5ba8SSam Ravnborg
18*a88b5ba8SSam Ravnborg#define		TASK_REGOFF		(THREAD_SIZE-TRACEREG_SZ-STACKFRAME_SZ)
19*a88b5ba8SSam Ravnborg#define		ETRAP_PSTATE1		(PSTATE_TSO | PSTATE_PRIV)
20*a88b5ba8SSam Ravnborg#define		ETRAP_PSTATE2		\
21*a88b5ba8SSam Ravnborg		(PSTATE_TSO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE)
22*a88b5ba8SSam Ravnborg
23*a88b5ba8SSam Ravnborg/*
24*a88b5ba8SSam Ravnborg * On entry, %g7 is return address - 0x4.
25*a88b5ba8SSam Ravnborg * %g4 and %g5 will be preserved %l4 and %l5 respectively.
26*a88b5ba8SSam Ravnborg */
27*a88b5ba8SSam Ravnborg
28*a88b5ba8SSam Ravnborg		.text
29*a88b5ba8SSam Ravnborg		.align	64
30*a88b5ba8SSam Ravnborg		.globl	etrap_syscall, etrap, etrap_irq, etraptl1
31*a88b5ba8SSam Ravnborgetrap:		rdpr	%pil, %g2
32*a88b5ba8SSam Ravnborgetrap_irq:	clr	%g3
33*a88b5ba8SSam Ravnborgetrap_syscall:	TRAP_LOAD_THREAD_REG(%g6, %g1)
34*a88b5ba8SSam Ravnborg		rdpr	%tstate, %g1
35*a88b5ba8SSam Ravnborg		or	%g1, %g3, %g1
36*a88b5ba8SSam Ravnborg		sllx	%g2, 20, %g3
37*a88b5ba8SSam Ravnborg		andcc	%g1, TSTATE_PRIV, %g0
38*a88b5ba8SSam Ravnborg		or	%g1, %g3, %g1
39*a88b5ba8SSam Ravnborg		bne,pn	%xcc, 1f
40*a88b5ba8SSam Ravnborg		 sub	%sp, STACKFRAME_SZ+TRACEREG_SZ-STACK_BIAS, %g2
41*a88b5ba8SSam Ravnborg		wrpr	%g0, 7, %cleanwin
42*a88b5ba8SSam Ravnborg
43*a88b5ba8SSam Ravnborg		sethi	%hi(TASK_REGOFF), %g2
44*a88b5ba8SSam Ravnborg		sethi	%hi(TSTATE_PEF), %g3
45*a88b5ba8SSam Ravnborg		or	%g2, %lo(TASK_REGOFF), %g2
46*a88b5ba8SSam Ravnborg		and	%g1, %g3, %g3
47*a88b5ba8SSam Ravnborg		brnz,pn	%g3, 1f
48*a88b5ba8SSam Ravnborg		 add	%g6, %g2, %g2
49*a88b5ba8SSam Ravnborg		wr	%g0, 0, %fprs
50*a88b5ba8SSam Ravnborg1:		rdpr	%tpc, %g3
51*a88b5ba8SSam Ravnborg
52*a88b5ba8SSam Ravnborg		stx	%g1, [%g2 + STACKFRAME_SZ + PT_V9_TSTATE]
53*a88b5ba8SSam Ravnborg		rdpr	%tnpc, %g1
54*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
55*a88b5ba8SSam Ravnborg		rd	%y, %g3
56*a88b5ba8SSam Ravnborg		stx	%g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
57*a88b5ba8SSam Ravnborg		rdpr	%tt, %g1
58*a88b5ba8SSam Ravnborg		st	%g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
59*a88b5ba8SSam Ravnborg		sethi	%hi(PT_REGS_MAGIC), %g3
60*a88b5ba8SSam Ravnborg		or	%g3, %g1, %g1
61*a88b5ba8SSam Ravnborg		st	%g1, [%g2 + STACKFRAME_SZ + PT_V9_MAGIC]
62*a88b5ba8SSam Ravnborg
63*a88b5ba8SSam Ravnborg		rdpr	%cansave, %g1
64*a88b5ba8SSam Ravnborg		brnz,pt %g1, etrap_save
65*a88b5ba8SSam Ravnborg		 nop
66*a88b5ba8SSam Ravnborg
67*a88b5ba8SSam Ravnborg		rdpr	%cwp, %g1
68*a88b5ba8SSam Ravnborg		add	%g1, 2, %g1
69*a88b5ba8SSam Ravnborg		wrpr	%g1, %cwp
70*a88b5ba8SSam Ravnborg		be,pt	%xcc, etrap_user_spill
71*a88b5ba8SSam Ravnborg		 mov	ASI_AIUP, %g3
72*a88b5ba8SSam Ravnborg
73*a88b5ba8SSam Ravnborg		rdpr	%otherwin, %g3
74*a88b5ba8SSam Ravnborg		brz	%g3, etrap_kernel_spill
75*a88b5ba8SSam Ravnborg		 mov	ASI_AIUS, %g3
76*a88b5ba8SSam Ravnborg
77*a88b5ba8SSam Ravnborgetrap_user_spill:
78*a88b5ba8SSam Ravnborg
79*a88b5ba8SSam Ravnborg		wr	%g3, 0x0, %asi
80*a88b5ba8SSam Ravnborg		ldx	[%g6 + TI_FLAGS], %g3
81*a88b5ba8SSam Ravnborg		and	%g3, _TIF_32BIT, %g3
82*a88b5ba8SSam Ravnborg		brnz,pt	%g3, etrap_user_spill_32bit
83*a88b5ba8SSam Ravnborg		 nop
84*a88b5ba8SSam Ravnborg		ba,a,pt	%xcc, etrap_user_spill_64bit
85*a88b5ba8SSam Ravnborg
86*a88b5ba8SSam Ravnborgetrap_save:	save	%g2, -STACK_BIAS, %sp
87*a88b5ba8SSam Ravnborg		mov	%g6, %l6
88*a88b5ba8SSam Ravnborg
89*a88b5ba8SSam Ravnborg		bne,pn	%xcc, 3f
90*a88b5ba8SSam Ravnborg		 mov	PRIMARY_CONTEXT, %l4
91*a88b5ba8SSam Ravnborg		rdpr	%canrestore, %g3
92*a88b5ba8SSam Ravnborg		rdpr	%wstate, %g2
93*a88b5ba8SSam Ravnborg		wrpr	%g0, 0, %canrestore
94*a88b5ba8SSam Ravnborg		sll	%g2, 3, %g2
95*a88b5ba8SSam Ravnborg		mov	1, %l5
96*a88b5ba8SSam Ravnborg		stb	%l5, [%l6 + TI_FPDEPTH]
97*a88b5ba8SSam Ravnborg
98*a88b5ba8SSam Ravnborg		wrpr	%g3, 0, %otherwin
99*a88b5ba8SSam Ravnborg		wrpr	%g2, 0, %wstate
100*a88b5ba8SSam Ravnborg		sethi	%hi(sparc64_kern_pri_context), %g2
101*a88b5ba8SSam Ravnborg		ldx	[%g2 + %lo(sparc64_kern_pri_context)], %g3
102*a88b5ba8SSam Ravnborg
103*a88b5ba8SSam Ravnborg661:		stxa	%g3, [%l4] ASI_DMMU
104*a88b5ba8SSam Ravnborg		.section .sun4v_1insn_patch, "ax"
105*a88b5ba8SSam Ravnborg		.word	661b
106*a88b5ba8SSam Ravnborg		stxa	%g3, [%l4] ASI_MMU
107*a88b5ba8SSam Ravnborg		.previous
108*a88b5ba8SSam Ravnborg
109*a88b5ba8SSam Ravnborg		sethi	%hi(KERNBASE), %l4
110*a88b5ba8SSam Ravnborg		flush	%l4
111*a88b5ba8SSam Ravnborg		mov	ASI_AIUS, %l7
112*a88b5ba8SSam Ravnborg2:		mov	%g4, %l4
113*a88b5ba8SSam Ravnborg		mov	%g5, %l5
114*a88b5ba8SSam Ravnborg		add	%g7, 4, %l2
115*a88b5ba8SSam Ravnborg
116*a88b5ba8SSam Ravnborg		/* Go to trap time globals so we can save them.  */
117*a88b5ba8SSam Ravnborg661:		wrpr	%g0, ETRAP_PSTATE1, %pstate
118*a88b5ba8SSam Ravnborg		.section .sun4v_1insn_patch, "ax"
119*a88b5ba8SSam Ravnborg		.word	661b
120*a88b5ba8SSam Ravnborg		SET_GL(0)
121*a88b5ba8SSam Ravnborg		.previous
122*a88b5ba8SSam Ravnborg
123*a88b5ba8SSam Ravnborg		stx	%g1, [%sp + PTREGS_OFF + PT_V9_G1]
124*a88b5ba8SSam Ravnborg		stx	%g2, [%sp + PTREGS_OFF + PT_V9_G2]
125*a88b5ba8SSam Ravnborg		sllx	%l7, 24, %l7
126*a88b5ba8SSam Ravnborg		stx	%g3, [%sp + PTREGS_OFF + PT_V9_G3]
127*a88b5ba8SSam Ravnborg		rdpr	%cwp, %l0
128*a88b5ba8SSam Ravnborg		stx	%g4, [%sp + PTREGS_OFF + PT_V9_G4]
129*a88b5ba8SSam Ravnborg		stx	%g5, [%sp + PTREGS_OFF + PT_V9_G5]
130*a88b5ba8SSam Ravnborg		stx	%g6, [%sp + PTREGS_OFF + PT_V9_G6]
131*a88b5ba8SSam Ravnborg		stx	%g7, [%sp + PTREGS_OFF + PT_V9_G7]
132*a88b5ba8SSam Ravnborg		or	%l7, %l0, %l7
133*a88b5ba8SSam Ravnborg		sethi	%hi(TSTATE_TSO | TSTATE_PEF), %l0
134*a88b5ba8SSam Ravnborg		or	%l7, %l0, %l7
135*a88b5ba8SSam Ravnborg		wrpr	%l2, %tnpc
136*a88b5ba8SSam Ravnborg		wrpr	%l7, (TSTATE_PRIV | TSTATE_IE), %tstate
137*a88b5ba8SSam Ravnborg		stx	%i0, [%sp + PTREGS_OFF + PT_V9_I0]
138*a88b5ba8SSam Ravnborg		stx	%i1, [%sp + PTREGS_OFF + PT_V9_I1]
139*a88b5ba8SSam Ravnborg		stx	%i2, [%sp + PTREGS_OFF + PT_V9_I2]
140*a88b5ba8SSam Ravnborg		stx	%i3, [%sp + PTREGS_OFF + PT_V9_I3]
141*a88b5ba8SSam Ravnborg		stx	%i4, [%sp + PTREGS_OFF + PT_V9_I4]
142*a88b5ba8SSam Ravnborg		stx	%i5, [%sp + PTREGS_OFF + PT_V9_I5]
143*a88b5ba8SSam Ravnborg		stx	%i6, [%sp + PTREGS_OFF + PT_V9_I6]
144*a88b5ba8SSam Ravnborg		mov	%l6, %g6
145*a88b5ba8SSam Ravnborg		stx	%i7, [%sp + PTREGS_OFF + PT_V9_I7]
146*a88b5ba8SSam Ravnborg		LOAD_PER_CPU_BASE(%g5, %g6, %g4, %g3, %l1)
147*a88b5ba8SSam Ravnborg		ldx	[%g6 + TI_TASK], %g4
148*a88b5ba8SSam Ravnborg		done
149*a88b5ba8SSam Ravnborg
150*a88b5ba8SSam Ravnborg3:		mov	ASI_P, %l7
151*a88b5ba8SSam Ravnborg		ldub	[%l6 + TI_FPDEPTH], %l5
152*a88b5ba8SSam Ravnborg		add	%l6, TI_FPSAVED + 1, %l4
153*a88b5ba8SSam Ravnborg		srl	%l5, 1, %l3
154*a88b5ba8SSam Ravnborg		add	%l5, 2, %l5
155*a88b5ba8SSam Ravnborg		stb	%l5, [%l6 + TI_FPDEPTH]
156*a88b5ba8SSam Ravnborg		ba,pt	%xcc, 2b
157*a88b5ba8SSam Ravnborg		 stb	%g0, [%l4 + %l3]
158*a88b5ba8SSam Ravnborg		nop
159*a88b5ba8SSam Ravnborg
160*a88b5ba8SSam Ravnborgetraptl1:	/* Save tstate/tpc/tnpc of TL 1-->4 and the tl register itself.
161*a88b5ba8SSam Ravnborg		 * We place this right after pt_regs on the trap stack.
162*a88b5ba8SSam Ravnborg		 * The layout is:
163*a88b5ba8SSam Ravnborg		 *	0x00	TL1's TSTATE
164*a88b5ba8SSam Ravnborg		 *	0x08	TL1's TPC
165*a88b5ba8SSam Ravnborg		 *	0x10	TL1's TNPC
166*a88b5ba8SSam Ravnborg		 *	0x18	TL1's TT
167*a88b5ba8SSam Ravnborg		 *	 ...
168*a88b5ba8SSam Ravnborg		 *	0x58	TL4's TT
169*a88b5ba8SSam Ravnborg		 *	0x60	TL
170*a88b5ba8SSam Ravnborg		 */
171*a88b5ba8SSam Ravnborg		TRAP_LOAD_THREAD_REG(%g6, %g1)
172*a88b5ba8SSam Ravnborg		sub	%sp, ((4 * 8) * 4) + 8, %g2
173*a88b5ba8SSam Ravnborg		rdpr	%tl, %g1
174*a88b5ba8SSam Ravnborg
175*a88b5ba8SSam Ravnborg		wrpr	%g0, 1, %tl
176*a88b5ba8SSam Ravnborg		rdpr	%tstate, %g3
177*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x00]
178*a88b5ba8SSam Ravnborg		rdpr	%tpc, %g3
179*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x08]
180*a88b5ba8SSam Ravnborg		rdpr	%tnpc, %g3
181*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x10]
182*a88b5ba8SSam Ravnborg		rdpr	%tt, %g3
183*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x18]
184*a88b5ba8SSam Ravnborg
185*a88b5ba8SSam Ravnborg		wrpr	%g0, 2, %tl
186*a88b5ba8SSam Ravnborg		rdpr	%tstate, %g3
187*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x20]
188*a88b5ba8SSam Ravnborg		rdpr	%tpc, %g3
189*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x28]
190*a88b5ba8SSam Ravnborg		rdpr	%tnpc, %g3
191*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x30]
192*a88b5ba8SSam Ravnborg		rdpr	%tt, %g3
193*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x38]
194*a88b5ba8SSam Ravnborg
195*a88b5ba8SSam Ravnborg		sethi	%hi(is_sun4v), %g3
196*a88b5ba8SSam Ravnborg		lduw	[%g3 + %lo(is_sun4v)], %g3
197*a88b5ba8SSam Ravnborg		brnz,pn	%g3, finish_tl1_capture
198*a88b5ba8SSam Ravnborg		 nop
199*a88b5ba8SSam Ravnborg
200*a88b5ba8SSam Ravnborg		wrpr	%g0, 3, %tl
201*a88b5ba8SSam Ravnborg		rdpr	%tstate, %g3
202*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x40]
203*a88b5ba8SSam Ravnborg		rdpr	%tpc, %g3
204*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x48]
205*a88b5ba8SSam Ravnborg		rdpr	%tnpc, %g3
206*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x50]
207*a88b5ba8SSam Ravnborg		rdpr	%tt, %g3
208*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x58]
209*a88b5ba8SSam Ravnborg
210*a88b5ba8SSam Ravnborg		wrpr	%g0, 4, %tl
211*a88b5ba8SSam Ravnborg		rdpr	%tstate, %g3
212*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x60]
213*a88b5ba8SSam Ravnborg		rdpr	%tpc, %g3
214*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x68]
215*a88b5ba8SSam Ravnborg		rdpr	%tnpc, %g3
216*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x70]
217*a88b5ba8SSam Ravnborg		rdpr	%tt, %g3
218*a88b5ba8SSam Ravnborg		stx	%g3, [%g2 + STACK_BIAS + 0x78]
219*a88b5ba8SSam Ravnborg
220*a88b5ba8SSam Ravnborg		stx	%g1, [%g2 + STACK_BIAS + 0x80]
221*a88b5ba8SSam Ravnborg
222*a88b5ba8SSam Ravnborgfinish_tl1_capture:
223*a88b5ba8SSam Ravnborg		wrpr	%g0, 1, %tl
224*a88b5ba8SSam Ravnborg661:		nop
225*a88b5ba8SSam Ravnborg		.section .sun4v_1insn_patch, "ax"
226*a88b5ba8SSam Ravnborg		.word	661b
227*a88b5ba8SSam Ravnborg		SET_GL(1)
228*a88b5ba8SSam Ravnborg		.previous
229*a88b5ba8SSam Ravnborg
230*a88b5ba8SSam Ravnborg		rdpr	%tstate, %g1
231*a88b5ba8SSam Ravnborg		sub	%g2, STACKFRAME_SZ + TRACEREG_SZ - STACK_BIAS, %g2
232*a88b5ba8SSam Ravnborg		ba,pt	%xcc, 1b
233*a88b5ba8SSam Ravnborg		 andcc	%g1, TSTATE_PRIV, %g0
234*a88b5ba8SSam Ravnborg
235*a88b5ba8SSam Ravnborg#undef TASK_REGOFF
236*a88b5ba8SSam Ravnborg#undef ETRAP_PSTATE1
237