mips: define syscall_get_error()
[linux-2.6-block.git] / arch / mips / include / asm / syscall.h
CommitLineData
19e2e172 1/*
c0ff3c53
RB
2 * Access to user system call parameters and results
3 *
19e2e172
RB
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 *
c0ff3c53
RB
8 * See asm-generic/syscall.h for descriptions of what we must do here.
9 *
19e2e172
RB
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
f5179287 16#include <linux/compiler.h>
579ec9e1 17#include <uapi/linux/audit.h>
bec9b2b2 18#include <linux/elf-em.h>
c0ff3c53
RB
19#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/uaccess.h>
22#include <asm/ptrace.h>
4c21b8fd
MC
23#include <asm/unistd.h>
24
25#ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */
26#define __NR_syscall 4000
27#endif
c0ff3c53 28
de8cd0dc
JH
29static inline bool mips_syscall_is_indirect(struct task_struct *task,
30 struct pt_regs *regs)
31{
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);
36}
37
c0ff3c53
RB
38static inline long syscall_get_nr(struct task_struct *task,
39 struct pt_regs *regs)
40{
c2d9f177 41 return current_thread_info()->syscall;
c0ff3c53
RB
42}
43
de8cd0dc
JH
44static inline void mips_syscall_update_nr(struct task_struct *task,
45 struct pt_regs *regs)
46{
47 /*
48 * v0 is the system call number, except for O32 ABI syscall(), where it
49 * ends up in a0.
50 */
51 if (mips_syscall_is_indirect(task, regs))
52 task_thread_info(task)->syscall = regs->regs[4];
53 else
54 task_thread_info(task)->syscall = regs->regs[2];
55}
56
c0ff3c53
RB
57static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
58 struct task_struct *task, struct pt_regs *regs, unsigned int n)
59{
63238f2c 60 unsigned long usp __maybe_unused = regs->regs[29];
c0ff3c53
RB
61
62 switch (n) {
63 case 0: case 1: case 2: case 3:
64 *arg = regs->regs[4 + n];
65
66 return 0;
67
68#ifdef CONFIG_32BIT
69 case 4: case 5: case 6: case 7:
86ca57b5 70 return get_user(*arg, (int *)usp + n);
c0ff3c53
RB
71#endif
72
73#ifdef CONFIG_64BIT
74 case 4: case 5: case 6: case 7:
75#ifdef CONFIG_MIPS32_O32
c50cbd85 76 if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
86ca57b5 77 return get_user(*arg, (int *)usp + n);
c0ff3c53
RB
78 else
79#endif
80 *arg = regs->regs[4 + n];
81
82 return 0;
83#endif
84
85 default:
86 BUG();
87 }
f5179287
RB
88
89 unreachable();
c0ff3c53
RB
90}
91
ba849160
DL
92static inline long syscall_get_error(struct task_struct *task,
93 struct pt_regs *regs)
94{
95 return regs->regs[7] ? -regs->regs[2] : 0;
96}
97
1d7bf993
RB
98static inline long syscall_get_return_value(struct task_struct *task,
99 struct pt_regs *regs)
100{
101 return regs->regs[2];
102}
103
22feadbe
MC
104static inline void syscall_rollback(struct task_struct *task,
105 struct pt_regs *regs)
106{
107 /* Do nothing */
108}
109
1d7bf993
RB
110static inline void syscall_set_return_value(struct task_struct *task,
111 struct pt_regs *regs,
112 int error, long val)
113{
114 if (error) {
115 regs->regs[2] = -error;
becddba9 116 regs->regs[7] = 1;
1d7bf993
RB
117 } else {
118 regs->regs[2] = val;
119 regs->regs[7] = 0;
120 }
121}
122
c0ff3c53
RB
123static inline void syscall_get_arguments(struct task_struct *task,
124 struct pt_regs *regs,
c0ff3c53
RB
125 unsigned long *args)
126{
b35f549d
SRRH
127 unsigned int i = 0;
128 unsigned int n = 6;
c0ff3c53 129 int ret;
de8cd0dc
JH
130
131 /* O32 ABI syscall() */
132 if (mips_syscall_is_indirect(task, regs))
4c21b8fd 133 i++;
c0ff3c53
RB
134
135 while (n--)
a8031d2c 136 ret |= mips_get_syscall_arg(args++, task, regs, i++);
c0ff3c53
RB
137
138 /*
139 * No way to communicate an error because this is a void function.
140 */
141#if 0
142 return ret;
143#endif
144}
145
19e2e172
RB
146extern const unsigned long sys_call_table[];
147extern const unsigned long sys32_call_table[];
148extern const unsigned long sysn32_call_table[];
149
16add411 150static inline int syscall_get_arch(struct task_struct *task)
bec9b2b2 151{
ce5d1128 152 int arch = AUDIT_ARCH_MIPS;
bec9b2b2 153#ifdef CONFIG_64BIT
16add411 154 if (!test_tsk_thread_flag(task, TIF_32BIT_REGS)) {
6e345746 155 arch |= __AUDIT_ARCH_64BIT;
40381529 156 /* N32 sets only TIF_32BIT_ADDR */
16add411 157 if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
40381529
MC
158 arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
159 }
bec9b2b2
RB
160#endif
161#if defined(__LITTLE_ENDIAN)
162 arch |= __AUDIT_ARCH_LE;
163#endif
164 return arch;
165}
166
19e2e172 167#endif /* __ASM_MIPS_SYSCALL_H */