xref: /linux/arch/sparc/kernel/syscalls.S (revision c6bd5bcc4983f1a2d2f87a3769bf309482ee8c04)
1	/* SunOS's execv() call only specifies the argv argument, the
2	 * environment settings are the same as the calling processes.
3	 */
4sys_execve:
5	sethi	%hi(sparc_execve), %g1
6	ba,pt	%xcc, execve_merge
7	 or	%g1, %lo(sparc_execve), %g1
8
9#ifdef CONFIG_COMPAT
10sunos_execv:
11	stx	%g0, [%sp + PTREGS_OFF + PT_V9_I2]
12sys32_execve:
13	sethi	%hi(sparc32_execve), %g1
14	or	%g1, %lo(sparc32_execve), %g1
15#endif
16
17execve_merge:
18	flushw
19	jmpl	%g1, %g0
20	 add	%sp, PTREGS_OFF, %o0
21
22	.align	32
23sys_sparc_pipe:
24	ba,pt	%xcc, sys_sparc_pipe_real
25	 add	%sp, PTREGS_OFF, %o0
26sys_nis_syscall:
27	ba,pt	%xcc, c_sys_nis_syscall
28	 add	%sp, PTREGS_OFF, %o0
29sys_memory_ordering:
30	ba,pt	%xcc, sparc_memory_ordering
31	 add	%sp, PTREGS_OFF, %o1
32sys_sigaltstack:
33	ba,pt	%xcc, do_sigaltstack
34	 add	%i6, STACK_BIAS, %o2
35#ifdef CONFIG_COMPAT
36sys32_sigstack:
37	ba,pt	%xcc, do_sys32_sigstack
38	 mov	%i6, %o2
39sys32_sigaltstack:
40	ba,pt	%xcc, do_sys32_sigaltstack
41	 mov	%i6, %o2
42#endif
43	.align	32
44#ifdef CONFIG_COMPAT
45sys32_sigreturn:
46	add	%sp, PTREGS_OFF, %o0
47	call	do_sigreturn32
48	 add	%o7, 1f-.-4, %o7
49	nop
50#endif
51sys_rt_sigreturn:
52	add	%sp, PTREGS_OFF, %o0
53	call	do_rt_sigreturn
54	 add	%o7, 1f-.-4, %o7
55	nop
56#ifdef CONFIG_COMPAT
57sys32_rt_sigreturn:
58	add	%sp, PTREGS_OFF, %o0
59	call	do_rt_sigreturn32
60	 add	%o7, 1f-.-4, %o7
61	nop
62#endif
63	.align	32
641:	ldx	[%g6 + TI_FLAGS], %l5
65	andcc	%l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
66	be,pt	%icc, rtrap
67	 nop
68	call	syscall_trace_leave
69	 add	%sp, PTREGS_OFF, %o0
70	ba,pt	%xcc, rtrap
71	 nop
72
73	/* This is how fork() was meant to be done, 8 instruction entry.
74	 *
75	 * I questioned the following code briefly, let me clear things
76	 * up so you must not reason on it like I did.
77	 *
78	 * Know the fork_kpsr etc. we use in the sparc32 port?  We don't
79	 * need it here because the only piece of window state we copy to
80	 * the child is the CWP register.  Even if the parent sleeps,
81	 * we are safe because we stuck it into pt_regs of the parent
82	 * so it will not change.
83	 *
84	 * XXX This raises the question, whether we can do the same on
85	 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim.  The
86	 * XXX answer is yes.  We stick fork_kpsr in UREG_G0 and
87	 * XXX fork_kwim in UREG_G1 (global registers are considered
88	 * XXX volatile across a system call in the sparc ABI I think
89	 * XXX if it isn't we can use regs->y instead, anyone who depends
90	 * XXX upon the Y register being preserved across a fork deserves
91	 * XXX to lose).
92	 *
93	 * In fact we should take advantage of that fact for other things
94	 * during system calls...
95	 */
96	.align	32
97sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
98	sethi	%hi(0x4000 | 0x0100 | SIGCHLD), %o0
99	or	%o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
100	ba,pt	%xcc, sys_clone
101sys_fork:
102	 clr	%o1
103	mov	SIGCHLD, %o0
104sys_clone:
105	flushw
106	movrz	%o1, %fp, %o1
107	mov	0, %o3
108	ba,pt	%xcc, sparc_do_fork
109	 add	%sp, PTREGS_OFF, %o2
110
111	.globl	ret_from_syscall
112ret_from_syscall:
113	/* Clear current_thread_info()->new_child. */
114	stb	%g0, [%g6 + TI_NEW_CHILD]
115	ldx	[%g6 + TI_FLAGS], %l0
116	call	schedule_tail
117	 mov	%g7, %o0
118	ba,pt	%xcc, ret_sys_call
119	 ldx	[%sp + PTREGS_OFF + PT_V9_I0], %o0
120
121	.globl	sparc_exit_group
122	.type	sparc_exit_group,#function
123sparc_exit_group:
124	sethi	%hi(sys_exit_group), %g7
125	ba,pt	%xcc, 1f
126	 or	%g7, %lo(sys_exit_group), %g7
127	.size	sparc_exit_group,.-sparc_exit_group
128
129	.globl	sparc_exit
130	.type	sparc_exit,#function
131sparc_exit:
132	sethi	%hi(sys_exit), %g7
133	or	%g7, %lo(sys_exit), %g7
1341:	rdpr	%pstate, %g2
135	wrpr	%g2, PSTATE_IE, %pstate
136	rdpr	%otherwin, %g1
137	rdpr	%cansave, %g3
138	add	%g3, %g1, %g3
139	wrpr	%g3, 0x0, %cansave
140	wrpr	%g0, 0x0, %otherwin
141	wrpr	%g2, 0x0, %pstate
142	jmpl	%g7, %g0
143	 stb	%g0, [%g6 + TI_WSAVED]
144	.size	sparc_exit,.-sparc_exit
145
146linux_sparc_ni_syscall:
147	sethi	%hi(sys_ni_syscall), %l7
148	ba,pt	%xcc, 4f
149	 or	%l7, %lo(sys_ni_syscall), %l7
150
151linux_syscall_trace32:
152	call	syscall_trace_enter
153	 add	%sp, PTREGS_OFF, %o0
154	brnz,pn	%o0, 3f
155	 mov	-ENOSYS, %o0
156	srl	%i0, 0, %o0
157	srl	%i4, 0, %o4
158	srl	%i1, 0, %o1
159	srl	%i2, 0, %o2
160	ba,pt	%xcc, 2f
161	 srl	%i3, 0, %o3
162
163linux_syscall_trace:
164	call	syscall_trace_enter
165	 add	%sp, PTREGS_OFF, %o0
166	brnz,pn	%o0, 3f
167	 mov	-ENOSYS, %o0
168	mov	%i0, %o0
169	mov	%i1, %o1
170	mov	%i2, %o2
171	mov	%i3, %o3
172	b,pt	%xcc, 2f
173	 mov	%i4, %o4
174
175
176	/* Linux 32-bit system calls enter here... */
177	.align	32
178	.globl	linux_sparc_syscall32
179linux_sparc_syscall32:
180	/* Direct access to user regs, much faster. */
181	cmp	%g1, NR_syscalls			! IEU1	Group
182	bgeu,pn	%xcc, linux_sparc_ni_syscall		! CTI
183	 srl	%i0, 0, %o0				! IEU0
184	sll	%g1, 2, %l4				! IEU0	Group
185	srl	%i4, 0, %o4				! IEU1
186	lduw	[%l7 + %l4], %l7			! Load
187	srl	%i1, 0, %o1				! IEU0	Group
188	ldx	[%g6 + TI_FLAGS], %l0		! Load
189
190	srl	%i5, 0, %o5				! IEU1
191	srl	%i2, 0, %o2				! IEU0	Group
192	andcc	%l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
193	bne,pn	%icc, linux_syscall_trace32		! CTI
194	 mov	%i0, %l5				! IEU1
195	call	%l7					! CTI	Group brk forced
196	 srl	%i3, 0, %o3				! IEU0
197	ba,a,pt	%xcc, 3f
198
199	/* Linux native system calls enter here... */
200	.align	32
201	.globl	linux_sparc_syscall
202linux_sparc_syscall:
203	/* Direct access to user regs, much faster. */
204	cmp	%g1, NR_syscalls			! IEU1	Group
205	bgeu,pn	%xcc, linux_sparc_ni_syscall		! CTI
206	 mov	%i0, %o0				! IEU0
207	sll	%g1, 2, %l4				! IEU0	Group
208	mov	%i1, %o1				! IEU1
209	lduw	[%l7 + %l4], %l7			! Load
2104:	mov	%i2, %o2				! IEU0	Group
211	ldx	[%g6 + TI_FLAGS], %l0		! Load
212
213	mov	%i3, %o3				! IEU1
214	mov	%i4, %o4				! IEU0	Group
215	andcc	%l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
216	bne,pn	%icc, linux_syscall_trace		! CTI	Group
217	 mov	%i0, %l5				! IEU0
2182:	call	%l7					! CTI	Group brk forced
219	 mov	%i5, %o5				! IEU0
220	nop
221
2223:	stx	%o0, [%sp + PTREGS_OFF + PT_V9_I0]
223ret_sys_call:
224	ldx	[%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
225	sra	%o0, 0, %o0
226	mov	%ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
227	sllx	%g2, 32, %g2
228
229	cmp	%o0, -ERESTART_RESTARTBLOCK
230	bgeu,pn	%xcc, 1f
231	 andcc	%l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
232	ldx	[%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
233
2342:
235	stb	%g0, [%g6 + TI_SYS_NOERROR]
236	/* System call success, clear Carry condition code. */
237	andn	%g3, %g2, %g3
2383:
239	stx	%g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
240	bne,pn	%icc, linux_syscall_trace2
241	 add	%l1, 0x4, %l2			! npc = npc+4
242	stx	%l1, [%sp + PTREGS_OFF + PT_V9_TPC]
243	ba,pt	%xcc, rtrap
244	 stx	%l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
245
2461:
247	/* Check if force_successful_syscall_return()
248	 * was invoked.
249	 */
250	ldub	[%g6 + TI_SYS_NOERROR], %l2
251	brnz,pn %l2, 2b
252	 ldx	[%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
253	/* System call failure, set Carry condition code.
254	 * Also, get abs(errno) to return to the process.
255	 */
256	sub	%g0, %o0, %o0
257	stx	%o0, [%sp + PTREGS_OFF + PT_V9_I0]
258	ba,pt	%xcc, 3b
259	 or	%g3, %g2, %g3
260
261linux_syscall_trace2:
262	call	syscall_trace_leave
263	 add	%sp, PTREGS_OFF, %o0
264	stx	%l1, [%sp + PTREGS_OFF + PT_V9_TPC]
265	ba,pt	%xcc, rtrap
266	 stx	%l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
267