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