syscall.h revision 579ec9e1ab0bdca2dbc3c942aa1a530a6ec8c349
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 <uapi/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
23static inline long syscall_get_nr(struct task_struct *task,
24				  struct pt_regs *regs)
25{
26	return regs->regs[2];
27}
28
29static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
30	struct task_struct *task, struct pt_regs *regs, unsigned int n)
31{
32	unsigned long usp = regs->regs[29];
33
34	switch (n) {
35	case 0: case 1: case 2: case 3:
36		*arg = regs->regs[4 + n];
37
38		return 0;
39
40#ifdef CONFIG_32BIT
41	case 4: case 5: case 6: case 7:
42		return get_user(*arg, (int *)usp + 4 * n);
43#endif
44
45#ifdef CONFIG_64BIT
46	case 4: case 5: case 6: case 7:
47#ifdef CONFIG_MIPS32_O32
48		if (test_thread_flag(TIF_32BIT_REGS))
49			return get_user(*arg, (int *)usp + 4 * n);
50		else
51#endif
52			*arg = regs->regs[4 + n];
53
54		return 0;
55#endif
56
57	default:
58		BUG();
59	}
60}
61
62static inline long syscall_get_return_value(struct task_struct *task,
63					    struct pt_regs *regs)
64{
65	return regs->regs[2];
66}
67
68static inline void syscall_set_return_value(struct task_struct *task,
69					    struct pt_regs *regs,
70					    int error, long val)
71{
72	if (error) {
73		regs->regs[2] = -error;
74		regs->regs[7] = -1;
75	} else {
76		regs->regs[2] = val;
77		regs->regs[7] = 0;
78	}
79}
80
81static inline void syscall_get_arguments(struct task_struct *task,
82					 struct pt_regs *regs,
83					 unsigned int i, unsigned int n,
84					 unsigned long *args)
85{
86	unsigned long arg;
87	int ret;
88
89	while (n--)
90		ret |= mips_get_syscall_arg(&arg, task, regs, i++);
91
92	/*
93	 * No way to communicate an error because this is a void function.
94	 */
95#if 0
96	return ret;
97#endif
98}
99
100extern const unsigned long sys_call_table[];
101extern const unsigned long sys32_call_table[];
102extern const unsigned long sysn32_call_table[];
103
104static inline int syscall_get_arch(void)
105{
106	int arch = EM_MIPS;
107#ifdef CONFIG_64BIT
108	arch |=  __AUDIT_ARCH_64BIT;
109#endif
110#if defined(__LITTLE_ENDIAN)
111	arch |=  __AUDIT_ARCH_LE;
112#endif
113	return arch;
114}
115
116#endif	/* __ASM_MIPS_SYSCALL_H */
117