]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/mips/include/asm/syscall.h
MIPS: Fix build with binutils 2.24.51+
[mirror_ubuntu-bionic-kernel.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
RB
28
29static inline long syscall_get_nr(struct task_struct *task,
30 struct pt_regs *regs)
31{
4c21b8fd
MC
32 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
33 if ((config_enabled(CONFIG_32BIT) ||
34 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
35 (regs->regs[2] == __NR_syscall))
36 return regs->regs[4];
37 else
38 return regs->regs[2];
c0ff3c53
RB
39}
40
41static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
42 struct task_struct *task, struct pt_regs *regs, unsigned int n)
43{
63238f2c 44 unsigned long usp __maybe_unused = regs->regs[29];
c0ff3c53
RB
45
46 switch (n) {
47 case 0: case 1: case 2: case 3:
48 *arg = regs->regs[4 + n];
49
50 return 0;
51
52#ifdef CONFIG_32BIT
53 case 4: case 5: case 6: case 7:
86ca57b5 54 return get_user(*arg, (int *)usp + n);
c0ff3c53
RB
55#endif
56
57#ifdef CONFIG_64BIT
58 case 4: case 5: case 6: case 7:
59#ifdef CONFIG_MIPS32_O32
60 if (test_thread_flag(TIF_32BIT_REGS))
86ca57b5 61 return get_user(*arg, (int *)usp + n);
c0ff3c53
RB
62 else
63#endif
64 *arg = regs->regs[4 + n];
65
66 return 0;
67#endif
68
69 default:
70 BUG();
71 }
f5179287
RB
72
73 unreachable();
c0ff3c53
RB
74}
75
1d7bf993
RB
76static inline long syscall_get_return_value(struct task_struct *task,
77 struct pt_regs *regs)
78{
79 return regs->regs[2];
80}
81
22feadbe
MC
82static inline void syscall_rollback(struct task_struct *task,
83 struct pt_regs *regs)
84{
85 /* Do nothing */
86}
87
1d7bf993
RB
88static inline void syscall_set_return_value(struct task_struct *task,
89 struct pt_regs *regs,
90 int error, long val)
91{
92 if (error) {
93 regs->regs[2] = -error;
94 regs->regs[7] = -1;
95 } else {
96 regs->regs[2] = val;
97 regs->regs[7] = 0;
98 }
99}
100
c0ff3c53
RB
101static inline void syscall_get_arguments(struct task_struct *task,
102 struct pt_regs *regs,
103 unsigned int i, unsigned int n,
104 unsigned long *args)
105{
c0ff3c53 106 int ret;
4c21b8fd
MC
107 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
108 if ((config_enabled(CONFIG_32BIT) ||
109 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
110 (regs->regs[2] == __NR_syscall)) {
111 i++;
112 n++;
113 }
c0ff3c53
RB
114
115 while (n--)
a8031d2c 116 ret |= mips_get_syscall_arg(args++, task, regs, i++);
c0ff3c53
RB
117
118 /*
119 * No way to communicate an error because this is a void function.
120 */
121#if 0
122 return ret;
123#endif
124}
125
19e2e172
RB
126extern const unsigned long sys_call_table[];
127extern const unsigned long sys32_call_table[];
128extern const unsigned long sysn32_call_table[];
129
5e937a9a 130static inline int syscall_get_arch(void)
bec9b2b2 131{
ce5d1128 132 int arch = AUDIT_ARCH_MIPS;
bec9b2b2 133#ifdef CONFIG_64BIT
40381529 134 if (!test_thread_flag(TIF_32BIT_REGS)) {
6e345746 135 arch |= __AUDIT_ARCH_64BIT;
40381529
MC
136 /* N32 sets only TIF_32BIT_ADDR */
137 if (test_thread_flag(TIF_32BIT_ADDR))
138 arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
139 }
bec9b2b2
RB
140#endif
141#if defined(__LITTLE_ENDIAN)
142 arch |= __AUDIT_ARCH_LE;
143#endif
144 return arch;
145}
146
19e2e172 147#endif /* __ASM_MIPS_SYSCALL_H */