xref: /openbmc/linux/arch/sparc/kernel/winfixup.S (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
2a88b5ba8SSam Ravnborg/* winfixup.S: Handle cases where user stack pointer is found to be bogus.
3a88b5ba8SSam Ravnborg *
4a88b5ba8SSam Ravnborg * Copyright (C) 1997, 2006 David S. Miller (davem@davemloft.net)
5a88b5ba8SSam Ravnborg */
6a88b5ba8SSam Ravnborg
7a88b5ba8SSam Ravnborg#include <asm/asi.h>
8a88b5ba8SSam Ravnborg#include <asm/head.h>
9a88b5ba8SSam Ravnborg#include <asm/page.h>
10a88b5ba8SSam Ravnborg#include <asm/ptrace.h>
11a88b5ba8SSam Ravnborg#include <asm/processor.h>
12a88b5ba8SSam Ravnborg#include <asm/spitfire.h>
13a88b5ba8SSam Ravnborg#include <asm/thread_info.h>
14a88b5ba8SSam Ravnborg
15a88b5ba8SSam Ravnborg	.text
16a88b5ba8SSam Ravnborg
17a88b5ba8SSam Ravnborg	/* It used to be the case that these register window fault
18a88b5ba8SSam Ravnborg	 * handlers could run via the save and restore instructions
19a88b5ba8SSam Ravnborg	 * done by the trap entry and exit code.  They now do the
20a88b5ba8SSam Ravnborg	 * window spill/fill by hand, so that case no longer can occur.
21a88b5ba8SSam Ravnborg	 */
22a88b5ba8SSam Ravnborg
23a88b5ba8SSam Ravnborg	.align	32
24a88b5ba8SSam Ravnborgfill_fixup:
25a88b5ba8SSam Ravnborg	TRAP_LOAD_THREAD_REG(%g6, %g1)
26a88b5ba8SSam Ravnborg	rdpr	%tstate, %g1
27a88b5ba8SSam Ravnborg	and	%g1, TSTATE_CWP, %g1
28a88b5ba8SSam Ravnborg	or	%g4, FAULT_CODE_WINFIXUP, %g4
29a88b5ba8SSam Ravnborg	stb	%g4, [%g6 + TI_FAULT_CODE]
30a88b5ba8SSam Ravnborg	stx	%g5, [%g6 + TI_FAULT_ADDR]
31a88b5ba8SSam Ravnborg	wrpr	%g1, %cwp
32a88b5ba8SSam Ravnborg	ba,pt	%xcc, etrap
33a88b5ba8SSam Ravnborg	 rd	%pc, %g7
34a88b5ba8SSam Ravnborg	call	do_sparc64_fault
35a88b5ba8SSam Ravnborg	 add	%sp, PTREGS_OFF, %o0
3649fa5230SDavid S. Miller	ba,a,pt	%xcc, rtrap
37a88b5ba8SSam Ravnborg
38a88b5ba8SSam Ravnborg	/* Be very careful about usage of the trap globals here.
39a88b5ba8SSam Ravnborg	 * You cannot touch %g5 as that has the fault information.
40a88b5ba8SSam Ravnborg	 */
41a88b5ba8SSam Ravnborgspill_fixup:
42a88b5ba8SSam Ravnborgspill_fixup_mna:
43a88b5ba8SSam Ravnborgspill_fixup_dax:
44a88b5ba8SSam Ravnborg	TRAP_LOAD_THREAD_REG(%g6, %g1)
45a88b5ba8SSam Ravnborg	ldx	[%g6 + TI_FLAGS], %g1
46517ffce4SDavid S. Miller	andcc	%sp, 0x1, %g0
47517ffce4SDavid S. Miller	movne	%icc, 0, %g1
48a88b5ba8SSam Ravnborg	andcc	%g1, _TIF_32BIT, %g0
49a88b5ba8SSam Ravnborg	ldub	[%g6 + TI_WSAVED], %g1
50a88b5ba8SSam Ravnborg	sll	%g1, 3, %g3
51a88b5ba8SSam Ravnborg	add	%g6, %g3, %g3
52a88b5ba8SSam Ravnborg	stx	%sp, [%g3 + TI_RWIN_SPTRS]
53a88b5ba8SSam Ravnborg	sll	%g1, 7, %g3
54a88b5ba8SSam Ravnborg	bne,pt	%xcc, 1f
55a88b5ba8SSam Ravnborg	 add	%g6, %g3, %g3
56a88b5ba8SSam Ravnborg	stx	%l0, [%g3 + TI_REG_WINDOW + 0x00]
57a88b5ba8SSam Ravnborg	stx	%l1, [%g3 + TI_REG_WINDOW + 0x08]
58a88b5ba8SSam Ravnborg	stx	%l2, [%g3 + TI_REG_WINDOW + 0x10]
59a88b5ba8SSam Ravnborg	stx	%l3, [%g3 + TI_REG_WINDOW + 0x18]
60a88b5ba8SSam Ravnborg	stx	%l4, [%g3 + TI_REG_WINDOW + 0x20]
61a88b5ba8SSam Ravnborg	stx	%l5, [%g3 + TI_REG_WINDOW + 0x28]
62a88b5ba8SSam Ravnborg	stx	%l6, [%g3 + TI_REG_WINDOW + 0x30]
63a88b5ba8SSam Ravnborg	stx	%l7, [%g3 + TI_REG_WINDOW + 0x38]
64a88b5ba8SSam Ravnborg	stx	%i0, [%g3 + TI_REG_WINDOW + 0x40]
65a88b5ba8SSam Ravnborg	stx	%i1, [%g3 + TI_REG_WINDOW + 0x48]
66a88b5ba8SSam Ravnborg	stx	%i2, [%g3 + TI_REG_WINDOW + 0x50]
67a88b5ba8SSam Ravnborg	stx	%i3, [%g3 + TI_REG_WINDOW + 0x58]
68a88b5ba8SSam Ravnborg	stx	%i4, [%g3 + TI_REG_WINDOW + 0x60]
69a88b5ba8SSam Ravnborg	stx	%i5, [%g3 + TI_REG_WINDOW + 0x68]
70a88b5ba8SSam Ravnborg	stx	%i6, [%g3 + TI_REG_WINDOW + 0x70]
71a88b5ba8SSam Ravnborg	ba,pt	%xcc, 2f
72a88b5ba8SSam Ravnborg	 stx	%i7, [%g3 + TI_REG_WINDOW + 0x78]
73a88b5ba8SSam Ravnborg1:	stw	%l0, [%g3 + TI_REG_WINDOW + 0x00]
74a88b5ba8SSam Ravnborg	stw	%l1, [%g3 + TI_REG_WINDOW + 0x04]
75a88b5ba8SSam Ravnborg	stw	%l2, [%g3 + TI_REG_WINDOW + 0x08]
76a88b5ba8SSam Ravnborg	stw	%l3, [%g3 + TI_REG_WINDOW + 0x0c]
77a88b5ba8SSam Ravnborg	stw	%l4, [%g3 + TI_REG_WINDOW + 0x10]
78a88b5ba8SSam Ravnborg	stw	%l5, [%g3 + TI_REG_WINDOW + 0x14]
79a88b5ba8SSam Ravnborg	stw	%l6, [%g3 + TI_REG_WINDOW + 0x18]
80a88b5ba8SSam Ravnborg	stw	%l7, [%g3 + TI_REG_WINDOW + 0x1c]
81a88b5ba8SSam Ravnborg	stw	%i0, [%g3 + TI_REG_WINDOW + 0x20]
82a88b5ba8SSam Ravnborg	stw	%i1, [%g3 + TI_REG_WINDOW + 0x24]
83a88b5ba8SSam Ravnborg	stw	%i2, [%g3 + TI_REG_WINDOW + 0x28]
84a88b5ba8SSam Ravnborg	stw	%i3, [%g3 + TI_REG_WINDOW + 0x2c]
85a88b5ba8SSam Ravnborg	stw	%i4, [%g3 + TI_REG_WINDOW + 0x30]
86a88b5ba8SSam Ravnborg	stw	%i5, [%g3 + TI_REG_WINDOW + 0x34]
87a88b5ba8SSam Ravnborg	stw	%i6, [%g3 + TI_REG_WINDOW + 0x38]
88a88b5ba8SSam Ravnborg	stw	%i7, [%g3 + TI_REG_WINDOW + 0x3c]
89a88b5ba8SSam Ravnborg2:	add	%g1, 1, %g1
90a88b5ba8SSam Ravnborg	stb	%g1, [%g6 + TI_WSAVED]
91a88b5ba8SSam Ravnborg	rdpr	%tstate, %g1
92a88b5ba8SSam Ravnborg	andcc	%g1, TSTATE_PRIV, %g0
93a88b5ba8SSam Ravnborg	saved
94a88b5ba8SSam Ravnborg	be,pn	%xcc, 1f
95a88b5ba8SSam Ravnborg	 and	%g1, TSTATE_CWP, %g1
96a88b5ba8SSam Ravnborg	retry
97a88b5ba8SSam Ravnborg1:	mov	FAULT_CODE_WRITE | FAULT_CODE_DTLB | FAULT_CODE_WINFIXUP, %g4
98a88b5ba8SSam Ravnborg	stb	%g4, [%g6 + TI_FAULT_CODE]
99a88b5ba8SSam Ravnborg	stx	%g5, [%g6 + TI_FAULT_ADDR]
100a88b5ba8SSam Ravnborg	wrpr	%g1, %cwp
101a88b5ba8SSam Ravnborg	ba,pt	%xcc, etrap
102a88b5ba8SSam Ravnborg	 rd	%pc, %g7
103a88b5ba8SSam Ravnborg	call	do_sparc64_fault
104a88b5ba8SSam Ravnborg	 add	%sp, PTREGS_OFF, %o0
105a88b5ba8SSam Ravnborg	ba,a,pt	%xcc, rtrap
106a88b5ba8SSam Ravnborg
107a88b5ba8SSam Ravnborgwinfix_mna:
108a88b5ba8SSam Ravnborg	andn	%g3, 0x7f, %g3
109a88b5ba8SSam Ravnborg	add	%g3, 0x78, %g3
110a88b5ba8SSam Ravnborg	wrpr	%g3, %tnpc
111a88b5ba8SSam Ravnborg	done
112a88b5ba8SSam Ravnborg
113a88b5ba8SSam Ravnborgfill_fixup_mna:
114a88b5ba8SSam Ravnborg	rdpr	%tstate, %g1
115a88b5ba8SSam Ravnborg	and	%g1, TSTATE_CWP, %g1
116a88b5ba8SSam Ravnborg	wrpr	%g1, %cwp
117a88b5ba8SSam Ravnborg	ba,pt	%xcc, etrap
118a88b5ba8SSam Ravnborg	 rd	%pc, %g7
119a88b5ba8SSam Ravnborg	sethi	%hi(tlb_type), %g1
120a88b5ba8SSam Ravnborg	lduw	[%g1 + %lo(tlb_type)], %g1
121a88b5ba8SSam Ravnborg	cmp	%g1, 3
122a88b5ba8SSam Ravnborg	bne,pt	%icc, 1f
123a88b5ba8SSam Ravnborg	 add	%sp, PTREGS_OFF, %o0
124a88b5ba8SSam Ravnborg	mov	%l4, %o2
125a88b5ba8SSam Ravnborg	call	sun4v_do_mna
126a88b5ba8SSam Ravnborg	 mov	%l5, %o1
127a88b5ba8SSam Ravnborg	ba,a,pt	%xcc, rtrap
128a88b5ba8SSam Ravnborg1:	mov	%l4, %o1
129a88b5ba8SSam Ravnborg	mov	%l5, %o2
130a88b5ba8SSam Ravnborg	call	mem_address_unaligned
131a88b5ba8SSam Ravnborg	 nop
132a88b5ba8SSam Ravnborg	ba,a,pt	%xcc, rtrap
133a88b5ba8SSam Ravnborg
134a88b5ba8SSam Ravnborgwinfix_dax:
135a88b5ba8SSam Ravnborg	andn	%g3, 0x7f, %g3
136a88b5ba8SSam Ravnborg	add	%g3, 0x74, %g3
137a88b5ba8SSam Ravnborg	wrpr	%g3, %tnpc
138a88b5ba8SSam Ravnborg	done
139a88b5ba8SSam Ravnborg
140a88b5ba8SSam Ravnborgfill_fixup_dax:
141a88b5ba8SSam Ravnborg	rdpr	%tstate, %g1
142a88b5ba8SSam Ravnborg	and	%g1, TSTATE_CWP, %g1
143a88b5ba8SSam Ravnborg	wrpr	%g1, %cwp
144a88b5ba8SSam Ravnborg	ba,pt	%xcc, etrap
145a88b5ba8SSam Ravnborg	 rd	%pc, %g7
146a88b5ba8SSam Ravnborg	sethi	%hi(tlb_type), %g1
147a88b5ba8SSam Ravnborg	mov	%l4, %o1
148a88b5ba8SSam Ravnborg	lduw	[%g1 + %lo(tlb_type)], %g1
149a88b5ba8SSam Ravnborg	mov	%l5, %o2
150a88b5ba8SSam Ravnborg	cmp	%g1, 3
151a88b5ba8SSam Ravnborg	bne,pt	%icc, 1f
152a88b5ba8SSam Ravnborg	 add	%sp, PTREGS_OFF, %o0
153a88b5ba8SSam Ravnborg	call	sun4v_data_access_exception
154a88b5ba8SSam Ravnborg	 nop
155a88b5ba8SSam Ravnborg	ba,a,pt	%xcc, rtrap
1560ae2d26fSBabu Moger	 nop
157a88b5ba8SSam Ravnborg1:	call	spitfire_data_access_exception
158a88b5ba8SSam Ravnborg	 nop
159a88b5ba8SSam Ravnborg	ba,a,pt	%xcc, rtrap
1600ae2d26fSBabu Moger	 nop
161