1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License.  See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1995, 96, 97, 98, 99, 2000, 01, 02 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
9 */
10#include <linux/errno.h>
11#include <asm/asm.h>
12#include <asm/asmmacro.h>
13#include <asm/irqflags.h>
14#include <asm/mipsregs.h>
15#include <asm/regdef.h>
16#include <asm/stackframe.h>
17#include <asm/asm-offsets.h>
18#include <asm/sysmips.h>
19#include <asm/thread_info.h>
20#include <asm/unistd.h>
21#include <asm/war.h>
22
23#ifndef CONFIG_BINFMT_ELF32
24/* Neither O32 nor N32, so define handle_sys here */
25#define handle_sys64 handle_sys
26#endif
27
28	.align	5
29NESTED(handle_sys64, PT_SIZE, sp)
30#if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32)
31	/*
32	 * When 32-bit compatibility is configured scall_o32.S
33	 * already did this.
34	 */
35	.set	noat
36	SAVE_SOME
37	TRACE_IRQS_ON_RELOAD
38	STI
39	.set	at
40#endif
41
42#if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32)
43	ld	t1, PT_EPC(sp)		# skip syscall on return
44	daddiu	t1, 4			# skip to next instruction
45	sd	t1, PT_EPC(sp)
46#endif
47
48	sd	a3, PT_R26(sp)		# save a3 for syscall restarting
49
50	li	t1, _TIF_WORK_SYSCALL_ENTRY
51	LONG_L	t0, TI_FLAGS($28)	# syscall tracing enabled?
52	and	t0, t1, t0
53	bnez	t0, syscall_trace_entry
54
55syscall_common:
56	dsubu	t2, v0, __NR_64_Linux
57	sltiu   t0, t2, __NR_64_Linux_syscalls + 1
58	beqz	t0, illegal_syscall
59
60	dsll	t0, t2, 3		# offset into table
61	dla	t2, sys_call_table
62	daddu	t0, t2, t0
63	ld	t2, (t0)		# syscall routine
64	beqz	t2, illegal_syscall
65
66	jalr	t2			# Do The Real Thing (TM)
67
68	li	t0, -EMAXERRNO - 1	# error?
69	sltu	t0, t0, v0
70	sd	t0, PT_R7(sp)		# set error flag
71	beqz	t0, 1f
72
73	ld	t1, PT_R2(sp)		# syscall number
74	dnegu	v0			# error
75	sd	t1, PT_R0(sp)		# save it for syscall restarting
761:	sd	v0, PT_R2(sp)		# result
77
78n64_syscall_exit:
79	j	syscall_exit_partial
80
81/* ------------------------------------------------------------------------ */
82
83syscall_trace_entry:
84	SAVE_STATIC
85	move	a0, sp
86	move	a1, v0
87	jal	syscall_trace_enter
88
89	bltz	v0, 1f			# seccomp failed? Skip syscall
90
91	RESTORE_STATIC
92	ld	v0, PT_R2(sp)		# Restore syscall (maybe modified)
93	ld	a0, PT_R4(sp)		# Restore argument registers
94	ld	a1, PT_R5(sp)
95	ld	a2, PT_R6(sp)
96	ld	a3, PT_R7(sp)
97	ld	a4, PT_R8(sp)
98	ld	a5, PT_R9(sp)
99	j	syscall_common
100
1011:	j	syscall_exit
102
103illegal_syscall:
104	/* This also isn't a 64-bit syscall, throw an error.  */
105	li	v0, ENOSYS			# error
106	sd	v0, PT_R2(sp)
107	li	t0, 1				# set error flag
108	sd	t0, PT_R7(sp)
109	j	n64_syscall_exit
110	END(handle_sys64)
111
112	.align	3
113	.type	sys_call_table, @object
114EXPORT(sys_call_table)
115	PTR	sys_read			/* 5000 */
116	PTR	sys_write
117	PTR	sys_open
118	PTR	sys_close
119	PTR	sys_newstat
120	PTR	sys_newfstat			/* 5005 */
121	PTR	sys_newlstat
122	PTR	sys_poll
123	PTR	sys_lseek
124	PTR	sys_mips_mmap
125	PTR	sys_mprotect			/* 5010 */
126	PTR	sys_munmap
127	PTR	sys_brk
128	PTR	sys_rt_sigaction
129	PTR	sys_rt_sigprocmask
130	PTR	sys_ioctl			/* 5015 */
131	PTR	sys_pread64
132	PTR	sys_pwrite64
133	PTR	sys_readv
134	PTR	sys_writev
135	PTR	sys_access			/* 5020 */
136	PTR	sysm_pipe
137	PTR	sys_select
138	PTR	sys_sched_yield
139	PTR	sys_mremap
140	PTR	sys_msync			/* 5025 */
141	PTR	sys_mincore
142	PTR	sys_madvise
143	PTR	sys_shmget
144	PTR	sys_shmat
145	PTR	sys_shmctl			/* 5030 */
146	PTR	sys_dup
147	PTR	sys_dup2
148	PTR	sys_pause
149	PTR	sys_nanosleep
150	PTR	sys_getitimer			/* 5035 */
151	PTR	sys_setitimer
152	PTR	sys_alarm
153	PTR	sys_getpid
154	PTR	sys_sendfile64
155	PTR	sys_socket			/* 5040 */
156	PTR	sys_connect
157	PTR	sys_accept
158	PTR	sys_sendto
159	PTR	sys_recvfrom
160	PTR	sys_sendmsg			/* 5045 */
161	PTR	sys_recvmsg
162	PTR	sys_shutdown
163	PTR	sys_bind
164	PTR	sys_listen
165	PTR	sys_getsockname			/* 5050 */
166	PTR	sys_getpeername
167	PTR	sys_socketpair
168	PTR	sys_setsockopt
169	PTR	sys_getsockopt
170	PTR	__sys_clone			/* 5055 */
171	PTR	__sys_fork
172	PTR	sys_execve
173	PTR	sys_exit
174	PTR	sys_wait4
175	PTR	sys_kill			/* 5060 */
176	PTR	sys_newuname
177	PTR	sys_semget
178	PTR	sys_semop
179	PTR	sys_semctl
180	PTR	sys_shmdt			/* 5065 */
181	PTR	sys_msgget
182	PTR	sys_msgsnd
183	PTR	sys_msgrcv
184	PTR	sys_msgctl
185	PTR	sys_fcntl			/* 5070 */
186	PTR	sys_flock
187	PTR	sys_fsync
188	PTR	sys_fdatasync
189	PTR	sys_truncate
190	PTR	sys_ftruncate			/* 5075 */
191	PTR	sys_getdents
192	PTR	sys_getcwd
193	PTR	sys_chdir
194	PTR	sys_fchdir
195	PTR	sys_rename			/* 5080 */
196	PTR	sys_mkdir
197	PTR	sys_rmdir
198	PTR	sys_creat
199	PTR	sys_link
200	PTR	sys_unlink			/* 5085 */
201	PTR	sys_symlink
202	PTR	sys_readlink
203	PTR	sys_chmod
204	PTR	sys_fchmod
205	PTR	sys_chown			/* 5090 */
206	PTR	sys_fchown
207	PTR	sys_lchown
208	PTR	sys_umask
209	PTR	sys_gettimeofday
210	PTR	sys_getrlimit			/* 5095 */
211	PTR	sys_getrusage
212	PTR	sys_sysinfo
213	PTR	sys_times
214	PTR	sys_ptrace
215	PTR	sys_getuid			/* 5100 */
216	PTR	sys_syslog
217	PTR	sys_getgid
218	PTR	sys_setuid
219	PTR	sys_setgid
220	PTR	sys_geteuid			/* 5105 */
221	PTR	sys_getegid
222	PTR	sys_setpgid
223	PTR	sys_getppid
224	PTR	sys_getpgrp
225	PTR	sys_setsid			/* 5110 */
226	PTR	sys_setreuid
227	PTR	sys_setregid
228	PTR	sys_getgroups
229	PTR	sys_setgroups
230	PTR	sys_setresuid			/* 5115 */
231	PTR	sys_getresuid
232	PTR	sys_setresgid
233	PTR	sys_getresgid
234	PTR	sys_getpgid
235	PTR	sys_setfsuid			/* 5120 */
236	PTR	sys_setfsgid
237	PTR	sys_getsid
238	PTR	sys_capget
239	PTR	sys_capset
240	PTR	sys_rt_sigpending		/* 5125 */
241	PTR	sys_rt_sigtimedwait
242	PTR	sys_rt_sigqueueinfo
243	PTR	sys_rt_sigsuspend
244	PTR	sys_sigaltstack
245	PTR	sys_utime			/* 5130 */
246	PTR	sys_mknod
247	PTR	sys_personality
248	PTR	sys_ustat
249	PTR	sys_statfs
250	PTR	sys_fstatfs			/* 5135 */
251	PTR	sys_sysfs
252	PTR	sys_getpriority
253	PTR	sys_setpriority
254	PTR	sys_sched_setparam
255	PTR	sys_sched_getparam		/* 5140 */
256	PTR	sys_sched_setscheduler
257	PTR	sys_sched_getscheduler
258	PTR	sys_sched_get_priority_max
259	PTR	sys_sched_get_priority_min
260	PTR	sys_sched_rr_get_interval	/* 5145 */
261	PTR	sys_mlock
262	PTR	sys_munlock
263	PTR	sys_mlockall
264	PTR	sys_munlockall
265	PTR	sys_vhangup			/* 5150 */
266	PTR	sys_pivot_root
267	PTR	sys_sysctl
268	PTR	sys_prctl
269	PTR	sys_adjtimex
270	PTR	sys_setrlimit			/* 5155 */
271	PTR	sys_chroot
272	PTR	sys_sync
273	PTR	sys_acct
274	PTR	sys_settimeofday
275	PTR	sys_mount			/* 5160 */
276	PTR	sys_umount
277	PTR	sys_swapon
278	PTR	sys_swapoff
279	PTR	sys_reboot
280	PTR	sys_sethostname			/* 5165 */
281	PTR	sys_setdomainname
282	PTR	sys_ni_syscall			/* was create_module */
283	PTR	sys_init_module
284	PTR	sys_delete_module
285	PTR	sys_ni_syscall			/* 5170, was get_kernel_syms */
286	PTR	sys_ni_syscall			/* was query_module */
287	PTR	sys_quotactl
288	PTR	sys_ni_syscall			/* was nfsservctl */
289	PTR	sys_ni_syscall			/* res. for getpmsg */
290	PTR	sys_ni_syscall			/* 5175	 for putpmsg */
291	PTR	sys_ni_syscall			/* res. for afs_syscall */
292	PTR	sys_ni_syscall			/* res. for security */
293	PTR	sys_gettid
294	PTR	sys_readahead
295	PTR	sys_setxattr			/* 5180 */
296	PTR	sys_lsetxattr
297	PTR	sys_fsetxattr
298	PTR	sys_getxattr
299	PTR	sys_lgetxattr
300	PTR	sys_fgetxattr			/* 5185 */
301	PTR	sys_listxattr
302	PTR	sys_llistxattr
303	PTR	sys_flistxattr
304	PTR	sys_removexattr
305	PTR	sys_lremovexattr		/* 5190 */
306	PTR	sys_fremovexattr
307	PTR	sys_tkill
308	PTR	sys_ni_syscall
309	PTR	sys_futex
310	PTR	sys_sched_setaffinity		/* 5195 */
311	PTR	sys_sched_getaffinity
312	PTR	sys_cacheflush
313	PTR	sys_cachectl
314	PTR	__sys_sysmips
315	PTR	sys_io_setup			/* 5200 */
316	PTR	sys_io_destroy
317	PTR	sys_io_getevents
318	PTR	sys_io_submit
319	PTR	sys_io_cancel
320	PTR	sys_exit_group			/* 5205 */
321	PTR	sys_lookup_dcookie
322	PTR	sys_epoll_create
323	PTR	sys_epoll_ctl
324	PTR	sys_epoll_wait
325	PTR	sys_remap_file_pages		/* 5210 */
326	PTR	sys_rt_sigreturn
327	PTR	sys_set_tid_address
328	PTR	sys_restart_syscall
329	PTR	sys_semtimedop
330	PTR	sys_fadvise64_64		/* 5215 */
331	PTR	sys_timer_create
332	PTR	sys_timer_settime
333	PTR	sys_timer_gettime
334	PTR	sys_timer_getoverrun
335	PTR	sys_timer_delete		/* 5220 */
336	PTR	sys_clock_settime
337	PTR	sys_clock_gettime
338	PTR	sys_clock_getres
339	PTR	sys_clock_nanosleep
340	PTR	sys_tgkill			/* 5225 */
341	PTR	sys_utimes
342	PTR	sys_mbind
343	PTR	sys_get_mempolicy
344	PTR	sys_set_mempolicy
345	PTR	sys_mq_open			/* 5230 */
346	PTR	sys_mq_unlink
347	PTR	sys_mq_timedsend
348	PTR	sys_mq_timedreceive
349	PTR	sys_mq_notify
350	PTR	sys_mq_getsetattr		/* 5235 */
351	PTR	sys_ni_syscall			/* sys_vserver */
352	PTR	sys_waitid
353	PTR	sys_ni_syscall			/* available, was setaltroot */
354	PTR	sys_add_key
355	PTR	sys_request_key			/* 5240 */
356	PTR	sys_keyctl
357	PTR	sys_set_thread_area
358	PTR	sys_inotify_init
359	PTR	sys_inotify_add_watch
360	PTR	sys_inotify_rm_watch		/* 5245 */
361	PTR	sys_migrate_pages
362	PTR	sys_openat
363	PTR	sys_mkdirat
364	PTR	sys_mknodat
365	PTR	sys_fchownat			/* 5250 */
366	PTR	sys_futimesat
367	PTR	sys_newfstatat
368	PTR	sys_unlinkat
369	PTR	sys_renameat
370	PTR	sys_linkat			/* 5255 */
371	PTR	sys_symlinkat
372	PTR	sys_readlinkat
373	PTR	sys_fchmodat
374	PTR	sys_faccessat
375	PTR	sys_pselect6			/* 5260 */
376	PTR	sys_ppoll
377	PTR	sys_unshare
378	PTR	sys_splice
379	PTR	sys_sync_file_range
380	PTR	sys_tee				/* 5265 */
381	PTR	sys_vmsplice
382	PTR	sys_move_pages
383	PTR	sys_set_robust_list
384	PTR	sys_get_robust_list
385	PTR	sys_kexec_load			/* 5270 */
386	PTR	sys_getcpu
387	PTR	sys_epoll_pwait
388	PTR	sys_ioprio_set
389	PTR	sys_ioprio_get
390	PTR	sys_utimensat			/* 5275 */
391	PTR	sys_signalfd
392	PTR	sys_ni_syscall			/* was timerfd */
393	PTR	sys_eventfd
394	PTR	sys_fallocate
395	PTR	sys_timerfd_create		/* 5280 */
396	PTR	sys_timerfd_gettime
397	PTR	sys_timerfd_settime
398	PTR	sys_signalfd4
399	PTR	sys_eventfd2
400	PTR	sys_epoll_create1		/* 5285 */
401	PTR	sys_dup3
402	PTR	sys_pipe2
403	PTR	sys_inotify_init1
404	PTR	sys_preadv
405	PTR	sys_pwritev			/* 5290 */
406	PTR	sys_rt_tgsigqueueinfo
407	PTR	sys_perf_event_open
408	PTR	sys_accept4
409	PTR	sys_recvmmsg
410	PTR	sys_fanotify_init		/* 5295 */
411	PTR	sys_fanotify_mark
412	PTR	sys_prlimit64
413	PTR	sys_name_to_handle_at
414	PTR	sys_open_by_handle_at
415	PTR	sys_clock_adjtime		/* 5300 */
416	PTR	sys_syncfs
417	PTR	sys_sendmmsg
418	PTR	sys_setns
419	PTR	sys_process_vm_readv
420	PTR	sys_process_vm_writev		/* 5305 */
421	PTR	sys_kcmp
422	PTR	sys_finit_module
423	PTR	sys_getdents64
424	PTR	sys_sched_setattr
425	PTR	sys_sched_getattr		/* 5310 */
426	PTR	sys_renameat2
427	PTR	sys_seccomp
428	PTR	sys_getrandom
429	PTR	sys_memfd_create
430	PTR	sys_bpf				/* 5315 */
431	PTR	sys_execveat
432	PTR	sys_userfaultfd
433	PTR	sys_membarrier
434	PTR	sys_mlock2
435	PTR	sys_copy_file_range		/* 5320 */
436	PTR	sys_preadv2
437	PTR	sys_pwritev2
438	PTR	sys_pkey_mprotect
439	PTR	sys_pkey_alloc
440	PTR	sys_pkey_free			/* 5325 */
441	PTR	sys_statx
442	PTR	sys_rseq
443	PTR	sys_io_pgetevents
444	.size	sys_call_table,.-sys_call_table
445