1 /*
2 * Access to user system call parameters and results
3 *
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
6 * for more details.
7 *
8 * See asm-generic/syscall.h for descriptions of what we must do here.
9 *
10 * Copyright (C) 2012 Ralf Baechle <ralf@linux-mips.org>
11 */
12
13 #ifndef __ASM_MIPS_SYSCALL_H
14 #define __ASM_MIPS_SYSCALL_H
15
16 #include <linux/audit.h>
17 #include <linux/elf-em.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/uaccess.h>
21 #include <asm/ptrace.h>
22 #include <asm/unistd.h>
23
24 #ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */
25 #define __NR_syscall 4000
26 #endif
27
syscall_get_nr(struct task_struct * task,struct pt_regs * regs)28 static inline long syscall_get_nr(struct task_struct *task,
29 struct pt_regs *regs)
30 {
31 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
32 if ((config_enabled(CONFIG_32BIT) ||
33 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
34 (regs->regs[2] == __NR_syscall))
35 return regs->regs[4];
36 else
37 return regs->regs[2];
38 }
39
mips_get_syscall_arg(unsigned long * arg,struct task_struct * task,struct pt_regs * regs,unsigned int n)40 static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
41 struct task_struct *task, struct pt_regs *regs, unsigned int n)
42 {
43 unsigned long usp = regs->regs[29];
44
45 switch (n) {
46 case 0: case 1: case 2: case 3:
47 *arg = regs->regs[4 + n];
48
49 return 0;
50
51 #ifdef CONFIG_32BIT
52 case 4: case 5: case 6: case 7:
53 return get_user(*arg, (int *)usp + 4 * n);
54 #endif
55
56 #ifdef CONFIG_64BIT
57 case 4: case 5: case 6: case 7:
58 #ifdef CONFIG_MIPS32_O32
59 if (test_thread_flag(TIF_32BIT_REGS))
60 return get_user(*arg, (int *)usp + 4 * n);
61 else
62 #endif
63 *arg = regs->regs[4 + n];
64
65 return 0;
66 #endif
67
68 default:
69 BUG();
70 }
71 }
72
syscall_get_return_value(struct task_struct * task,struct pt_regs * regs)73 static inline long syscall_get_return_value(struct task_struct *task,
74 struct pt_regs *regs)
75 {
76 return regs->regs[2];
77 }
78
syscall_rollback(struct task_struct * task,struct pt_regs * regs)79 static inline void syscall_rollback(struct task_struct *task,
80 struct pt_regs *regs)
81 {
82 /* Do nothing */
83 }
84
syscall_set_return_value(struct task_struct * task,struct pt_regs * regs,int error,long val)85 static inline void syscall_set_return_value(struct task_struct *task,
86 struct pt_regs *regs,
87 int error, long val)
88 {
89 if (error) {
90 regs->regs[2] = -error;
91 regs->regs[7] = -1;
92 } else {
93 regs->regs[2] = val;
94 regs->regs[7] = 0;
95 }
96 }
97
syscall_get_arguments(struct task_struct * task,struct pt_regs * regs,unsigned int i,unsigned int n,unsigned long * args)98 static inline void syscall_get_arguments(struct task_struct *task,
99 struct pt_regs *regs,
100 unsigned int i, unsigned int n,
101 unsigned long *args)
102 {
103 unsigned long arg;
104 int ret;
105 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
106 if ((config_enabled(CONFIG_32BIT) ||
107 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
108 (regs->regs[2] == __NR_syscall)) {
109 i++;
110 n++;
111 }
112
113 while (n--)
114 ret |= mips_get_syscall_arg(&arg, task, regs, i++);
115
116 /*
117 * No way to communicate an error because this is a void function.
118 */
119 #if 0
120 return ret;
121 #endif
122 }
123
124 extern const unsigned long sys_call_table[];
125 extern const unsigned long sys32_call_table[];
126 extern const unsigned long sysn32_call_table[];
127
syscall_get_arch(struct task_struct * task,struct pt_regs * regs)128 static inline int syscall_get_arch(struct task_struct *task,
129 struct pt_regs *regs)
130 {
131 int arch = EM_MIPS;
132 #ifdef CONFIG_64BIT
133 if (!test_tsk_thread_flag(task, TIF_32BIT_REGS))
134 arch |= __AUDIT_ARCH_64BIT;
135 #endif
136 #if defined(__LITTLE_ENDIAN)
137 arch |= __AUDIT_ARCH_LE;
138 #endif
139 return arch;
140 }
141
142 #endif /* __ASM_MIPS_SYSCALL_H */
143