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
6 * Copyright (C) 1995-99, 2000- 02, 06 Ralf Baechle <ralf@linux-mips.org>
7 * Copyright (C) 2001 MIPS Technologies, Inc.
8 * Copyright (C) 2004 Thiemo Seufer
9 * Copyright (C) 2014 Imagination Technologies Ltd.
11 #include <linux/errno.h>
13 #include <asm/asmmacro.h>
14 #include <asm/irqflags.h>
15 #include <asm/mipsregs.h>
16 #include <asm/regdef.h>
17 #include <asm/stackframe.h>
18 #include <asm/isadep.h>
19 #include <asm/sysmips.h>
20 #include <asm/thread_info.h>
21 #include <asm/unistd.h>
22 #include <asm/asm-offsets.h>
25 NESTED(handle_sys, PT_SIZE, sp)
32 lw t1, PT_EPC(sp) # skip syscall on return
34 addiu t1, 4 # skip to next instruction
37 sw a3, PT_R26(sp) # save a3 for syscall restarting
40 * More than four arguments. Try to deal with it by copying the
41 * stack arguments from the user stack to the kernel stack.
44 lw t0, PT_R29(sp) # get old user stack pointer
47 * We intentionally keep the kernel stack a little below the top of
48 * userspace so we don't have to do a slower byte accurate check here.
51 bltz t4, bad_stack # -> sp is bad
54 * Ok, copy the args from the luser stack to the kernel stack.
61 load_a4: user_lw(t5, 16(t0)) # argument #5 from usp
62 load_a5: user_lw(t6, 20(t0)) # argument #6 from usp
63 load_a6: user_lw(t7, 24(t0)) # argument #7 from usp
64 load_a7: user_lw(t8, 28(t0)) # argument #8 from usp
67 sw t5, 16(sp) # argument #5 to ksp
68 sw t6, 20(sp) # argument #6 to ksp
69 sw t7, 24(sp) # argument #7 to ksp
70 sw t8, 28(sp) # argument #8 to ksp
73 .section __ex_table,"a"
74 PTR_WD load_a4, bad_stack_a4
75 PTR_WD load_a5, bad_stack_a5
76 PTR_WD load_a6, bad_stack_a6
77 PTR_WD load_a7, bad_stack_a7
80 lw t0, TI_FLAGS($28) # syscall tracing enabled?
81 li t1, _TIF_WORK_SYSCALL_ENTRY
83 bnez t0, syscall_trace_entry # -> yes
85 subu v0, v0, __NR_O32_Linux # check syscall number
86 sltiu t0, v0, __NR_O32_Linux_syscalls
87 beqz t0, illegal_syscall
92 lw t2, (t1) # syscall routine
94 beqz t2, illegal_syscall
96 jalr t2 # Do The Real Thing (TM)
98 li t0, -EMAXERRNO - 1 # error?
100 sw t0, PT_R7(sp) # set error flag
103 lw t1, PT_R2(sp) # syscall number
105 sw t1, PT_R0(sp) # save it for syscall restarting
106 1: sw v0, PT_R2(sp) # result
109 j syscall_exit_partial
111 /* ------------------------------------------------------------------------ */
118 * syscall number is in v0 unless we called syscall(__NR_###)
119 * where the real syscall number is in a0
122 subu t2, v0, __NR_O32_Linux
123 bnez t2, 1f /* __NR_syscall at offset 0 */
126 1: jal syscall_trace_enter
128 bltz v0, 1f # seccomp failed? Skip syscall
131 lw v0, PT_R2(sp) # Restore syscall (maybe modified)
132 lw a0, PT_R4(sp) # Restore argument registers
140 /* ------------------------------------------------------------------------ */
143 * Our open-coded access area sanity test for the stack pointer
144 * failed. We probably should handle this case a bit more drastic.
149 li t0, 1 # set error flag
170 * The system call does not exist in this kernel
173 li v0, ENOSYS # error
175 li t0, 1 # set error flag
181 subu t0, a0, __NR_O32_Linux # check syscall number
182 sltiu v0, t0, __NR_O32_Linux_syscalls
183 beqz t0, einval # do not recurse
186 lw t2, sys_call_table(t1) # syscall routine
188 move a0, a1 # shift argument registers
201 einval: li v0, -ENOSYS
205 #ifdef CONFIG_MIPS_MT_FPAFF
207 * For FPU affinity scheduling on MIPS MT processors, we need to
208 * intercept sys_sched_xxxaffinity() calls until we get a proper hook
209 * in kernel/sched/core.c. Considered only temporary we only support
210 * these hooks for the 32-bit kernel - there is no MIPS64 MT processor
213 #define sys_sched_setaffinity mipsmt_sys_sched_setaffinity
214 #define sys_sched_getaffinity mipsmt_sys_sched_getaffinity
215 #endif /* CONFIG_MIPS_MT_FPAFF */
217 #define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native)
218 #define __SYSCALL(nr, entry) PTR_WD entry
220 .type sys_call_table, @object
221 EXPORT(sys_call_table)
222 #include <asm/syscall_table_o32.h>