2 * Access to user system call parameters and results
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * See asm-generic/syscall.h for descriptions of what we must do here.
13 #ifndef __ASM_MIPS_SYSCALL_H
14 #define __ASM_MIPS_SYSCALL_H
16 #include <linux/compiler.h>
17 #include <uapi/linux/audit.h>
18 #include <linux/elf-em.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/uaccess.h>
22 #include <asm/ptrace.h>
23 #include <asm/unistd.h>
25 #ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */
26 #define __NR_syscall 4000
29 static inline bool mips_syscall_is_indirect(struct task_struct *task,
32 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
33 return (IS_ENABLED(CONFIG_32BIT) ||
34 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
35 (regs->regs[2] == __NR_syscall);
38 static inline long syscall_get_nr(struct task_struct *task,
41 return current_thread_info()->syscall;
44 static inline void mips_syscall_update_nr(struct task_struct *task,
48 * v0 is the system call number, except for O32 ABI syscall(), where it
51 if (mips_syscall_is_indirect(task, regs))
52 task_thread_info(task)->syscall = regs->regs[4];
54 task_thread_info(task)->syscall = regs->regs[2];
57 static inline void mips_get_syscall_arg(unsigned long *arg,
58 struct task_struct *task, struct pt_regs *regs, unsigned int n)
60 unsigned long usp __maybe_unused = regs->regs[29];
63 case 0: case 1: case 2: case 3:
64 *arg = regs->regs[4 + n];
69 case 4: case 5: case 6: case 7:
70 get_user(*arg, (int *)usp + n);
75 case 4: case 5: case 6: case 7:
76 #ifdef CONFIG_MIPS32_O32
77 if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
78 get_user(*arg, (int *)usp + n);
81 *arg = regs->regs[4 + n];
93 static inline long syscall_get_error(struct task_struct *task,
96 return regs->regs[7] ? -regs->regs[2] : 0;
99 static inline long syscall_get_return_value(struct task_struct *task,
100 struct pt_regs *regs)
102 return regs->regs[2];
105 static inline void syscall_rollback(struct task_struct *task,
106 struct pt_regs *regs)
111 static inline void syscall_set_return_value(struct task_struct *task,
112 struct pt_regs *regs,
116 regs->regs[2] = -error;
124 static inline void syscall_get_arguments(struct task_struct *task,
125 struct pt_regs *regs,
131 /* O32 ABI syscall() */
132 if (mips_syscall_is_indirect(task, regs))
136 mips_get_syscall_arg(args++, task, regs, i++);
139 extern const unsigned long sys_call_table[];
140 extern const unsigned long sys32_call_table[];
141 extern const unsigned long sysn32_call_table[];
143 static inline int syscall_get_arch(struct task_struct *task)
145 int arch = AUDIT_ARCH_MIPS;
147 if (!test_tsk_thread_flag(task, TIF_32BIT_REGS)) {
148 arch |= __AUDIT_ARCH_64BIT;
149 /* N32 sets only TIF_32BIT_ADDR */
150 if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
151 arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
154 #if defined(__LITTLE_ENDIAN)
155 arch |= __AUDIT_ARCH_LE;
160 #endif /* __ASM_MIPS_SYSCALL_H */