xref: /openbmc/linux/arch/sparc/kernel/syscalls.S (revision ca55b2fe)
1	/* SunOS's execv() call only specifies the argv argument, the
2	 * environment settings are the same as the calling processes.
3	 */
4sys64_execve:
5	set	sys_execve, %g1
6	jmpl	%g1, %g0
7	 flushw
8
9sys64_execveat:
10	set	sys_execveat, %g1
11	jmpl	%g1, %g0
12	 flushw
13
14#ifdef CONFIG_COMPAT
15sunos_execv:
16	mov	%g0, %o2
17sys32_execve:
18	set	compat_sys_execve, %g1
19	jmpl	%g1, %g0
20	 flushw
21
22sys32_execveat:
23	set	compat_sys_execveat, %g1
24	jmpl	%g1, %g0
25	 flushw
26#endif
27
28	.align	32
29sys_sparc_pipe:
30	ba,pt	%xcc, sys_sparc_pipe_real
31	 add	%sp, PTREGS_OFF, %o0
32sys_nis_syscall:
33	ba,pt	%xcc, c_sys_nis_syscall
34	 add	%sp, PTREGS_OFF, %o0
35sys_memory_ordering:
36	ba,pt	%xcc, sparc_memory_ordering
37	 add	%sp, PTREGS_OFF, %o1
38#ifdef CONFIG_COMPAT
39sys32_sigstack:
40	ba,pt	%xcc, do_sys32_sigstack
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|_TIF_NOHZ), %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_fork
112ret_from_fork:
113	/* Clear current_thread_info()->new_child. */
114	stb	%g0, [%g6 + TI_NEW_CHILD]
115	call	schedule_tail
116	 mov	%g7, %o0
117	ldx	[%sp + PTREGS_OFF + PT_V9_I0], %o0
118	brnz,pt	%o0, ret_sys_call
119	 ldx	[%g6 + TI_FLAGS], %l0
120	ldx	[%sp + PTREGS_OFF + PT_V9_G1], %l1
121	call	%l1
122	 ldx	[%sp + PTREGS_OFF + PT_V9_G2], %o0
123	ba,pt	%xcc, ret_sys_call
124	 mov	0, %o0
125
126	.globl	sparc_exit_group
127	.type	sparc_exit_group,#function
128sparc_exit_group:
129	sethi	%hi(sys_exit_group), %g7
130	ba,pt	%xcc, 1f
131	 or	%g7, %lo(sys_exit_group), %g7
132	.size	sparc_exit_group,.-sparc_exit_group
133
134	.globl	sparc_exit
135	.type	sparc_exit,#function
136sparc_exit:
137	sethi	%hi(sys_exit), %g7
138	or	%g7, %lo(sys_exit), %g7
1391:	rdpr	%pstate, %g2
140	wrpr	%g2, PSTATE_IE, %pstate
141	rdpr	%otherwin, %g1
142	rdpr	%cansave, %g3
143	add	%g3, %g1, %g3
144	wrpr	%g3, 0x0, %cansave
145	wrpr	%g0, 0x0, %otherwin
146	wrpr	%g2, 0x0, %pstate
147	jmpl	%g7, %g0
148	 stb	%g0, [%g6 + TI_WSAVED]
149	.size	sparc_exit,.-sparc_exit
150
151linux_sparc_ni_syscall:
152	sethi	%hi(sys_ni_syscall), %l7
153	ba,pt	%xcc, 4f
154	 or	%l7, %lo(sys_ni_syscall), %l7
155
156linux_syscall_trace32:
157	call	syscall_trace_enter
158	 add	%sp, PTREGS_OFF, %o0
159	brnz,pn	%o0, 3f
160	 mov	-ENOSYS, %o0
161	srl	%i0, 0, %o0
162	srl	%i4, 0, %o4
163	srl	%i1, 0, %o1
164	srl	%i2, 0, %o2
165	ba,pt	%xcc, 5f
166	 srl	%i3, 0, %o3
167
168linux_syscall_trace:
169	call	syscall_trace_enter
170	 add	%sp, PTREGS_OFF, %o0
171	brnz,pn	%o0, 3f
172	 mov	-ENOSYS, %o0
173	mov	%i0, %o0
174	mov	%i1, %o1
175	mov	%i2, %o2
176	mov	%i3, %o3
177	b,pt	%xcc, 2f
178	 mov	%i4, %o4
179
180
181	/* Linux 32-bit system calls enter here... */
182	.align	32
183	.globl	linux_sparc_syscall32
184linux_sparc_syscall32:
185	/* Direct access to user regs, much faster. */
186	cmp	%g1, NR_syscalls			! IEU1	Group
187	bgeu,pn	%xcc, linux_sparc_ni_syscall		! CTI
188	 srl	%i0, 0, %o0				! IEU0
189	sll	%g1, 2, %l4				! IEU0	Group
190	srl	%i4, 0, %o4				! IEU1
191	lduw	[%l7 + %l4], %l7			! Load
192	srl	%i1, 0, %o1				! IEU0	Group
193	ldx	[%g6 + TI_FLAGS], %l0		! Load
194
195	srl	%i3, 0, %o3				! IEU0
196	srl	%i2, 0, %o2				! IEU0	Group
197	andcc	%l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
198	bne,pn	%icc, linux_syscall_trace32		! CTI
199	 mov	%i0, %l5				! IEU1
2005:	call	%l7					! CTI	Group brk forced
201	 srl	%i5, 0, %o5				! IEU1
202	ba,pt	%xcc, 3f
203	 sra	%o0, 0, %o0
204
205	/* Linux native system calls enter here... */
206	.align	32
207	.globl	linux_sparc_syscall
208linux_sparc_syscall:
209	/* Direct access to user regs, much faster. */
210	cmp	%g1, NR_syscalls			! IEU1	Group
211	bgeu,pn	%xcc, linux_sparc_ni_syscall		! CTI
212	 mov	%i0, %o0				! IEU0
213	sll	%g1, 2, %l4				! IEU0	Group
214	mov	%i1, %o1				! IEU1
215	lduw	[%l7 + %l4], %l7			! Load
2164:	mov	%i2, %o2				! IEU0	Group
217	ldx	[%g6 + TI_FLAGS], %l0		! Load
218
219	mov	%i3, %o3				! IEU1
220	mov	%i4, %o4				! IEU0	Group
221	andcc	%l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
222	bne,pn	%icc, linux_syscall_trace		! CTI	Group
223	 mov	%i0, %l5				! IEU0
2242:	call	%l7					! CTI	Group brk forced
225	 mov	%i5, %o5				! IEU0
226	nop
227
2283:	stx	%o0, [%sp + PTREGS_OFF + PT_V9_I0]
229ret_sys_call:
230	ldx	[%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
231	mov	%ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
232	sllx	%g2, 32, %g2
233
234	cmp	%o0, -ERESTART_RESTARTBLOCK
235	bgeu,pn	%xcc, 1f
236	 andcc	%l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
237	ldx	[%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
238
2392:
240	/* System call success, clear Carry condition code. */
241	andn	%g3, %g2, %g3
2423:
243	stx	%g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
244	bne,pn	%icc, linux_syscall_trace2
245	 add	%l1, 0x4, %l2			! npc = npc+4
246	stx	%l1, [%sp + PTREGS_OFF + PT_V9_TPC]
247	ba,pt	%xcc, rtrap
248	 stx	%l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
249
2501:
251	/* Check if force_successful_syscall_return()
252	 * was invoked.
253	 */
254	ldub	[%g6 + TI_SYS_NOERROR], %l2
255	brnz,pn %l2, 2b
256	 ldx	[%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
257	/* System call failure, set Carry condition code.
258	 * Also, get abs(errno) to return to the process.
259	 */
260	sub	%g0, %o0, %o0
261	stx	%o0, [%sp + PTREGS_OFF + PT_V9_I0]
262	ba,pt	%xcc, 3b
263	 or	%g3, %g2, %g3
264
265linux_syscall_trace2:
266	call	syscall_trace_leave
267	 add	%sp, PTREGS_OFF, %o0
268	stx	%l1, [%sp + PTREGS_OFF + PT_V9_TPC]
269	ba,pt	%xcc, rtrap
270	 stx	%l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
271