aboutsummaryrefslogtreecommitdiffstats
path: root/arch/nios2/include
diff options
context:
space:
mode:
authorLey Foon Tan <lftan@altera.com>2014-11-06 02:19:57 -0500
committerLey Foon Tan <lftan@altera.com>2014-12-07 23:55:58 -0500
commit1000197d801329804d30094aef5dba0265204d17 (patch)
tree9c494ebb84afcfae63306c6d8fdcd56028cb80fc /arch/nios2/include
parent19f4c6b5afb92d405009cb8801bde3edc9205dc0 (diff)
nios2: System calls handling
This patch adds support for system calls from userspaces. It uses the asm-generic/unistd.h definitions with architecture spcific syscall. The sys_call_table is just an array defined in a C file and it contains pointers to the syscall functions. Signed-off-by: Ley Foon Tan <lftan@altera.com>
Diffstat (limited to 'arch/nios2/include')
-rw-r--r--arch/nios2/include/asm/syscall.h138
-rw-r--r--arch/nios2/include/asm/syscalls.h25
-rw-r--r--arch/nios2/include/uapi/asm/unistd.h25
3 files changed, 188 insertions, 0 deletions
diff --git a/arch/nios2/include/asm/syscall.h b/arch/nios2/include/asm/syscall.h
new file mode 100644
index 000000000000..9de220854c4a
--- /dev/null
+++ b/arch/nios2/include/asm/syscall.h
@@ -0,0 +1,138 @@
1/*
2 * Copyright Altera Corporation (C) <2014>. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __ASM_NIOS2_SYSCALL_H__
18#define __ASM_NIOS2_SYSCALL_H__
19
20#include <linux/err.h>
21#include <linux/sched.h>
22
23static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
24{
25 return regs->r2;
26}
27
28static inline void syscall_rollback(struct task_struct *task,
29 struct pt_regs *regs)
30{
31 regs->r2 = regs->orig_r2;
32 regs->r7 = regs->orig_r7;
33}
34
35static inline long syscall_get_error(struct task_struct *task,
36 struct pt_regs *regs)
37{
38 return regs->r7 ? regs->r2 : 0;
39}
40
41static inline long syscall_get_return_value(struct task_struct *task,
42 struct pt_regs *regs)
43{
44 return regs->r2;
45}
46
47static inline void syscall_set_return_value(struct task_struct *task,
48 struct pt_regs *regs, int error, long val)
49{
50 if (error) {
51 /* error < 0, but nios2 uses > 0 return value */
52 regs->r2 = -error;
53 regs->r7 = 1;
54 } else {
55 regs->r2 = val;
56 regs->r7 = 0;
57 }
58}
59
60static inline void syscall_get_arguments(struct task_struct *task,
61 struct pt_regs *regs, unsigned int i, unsigned int n,
62 unsigned long *args)
63{
64 BUG_ON(i + n > 6);
65
66 switch (i) {
67 case 0:
68 if (!n--)
69 break;
70 *args++ = regs->r4;
71 case 1:
72 if (!n--)
73 break;
74 *args++ = regs->r5;
75 case 2:
76 if (!n--)
77 break;
78 *args++ = regs->r6;
79 case 3:
80 if (!n--)
81 break;
82 *args++ = regs->r7;
83 case 4:
84 if (!n--)
85 break;
86 *args++ = regs->r8;
87 case 5:
88 if (!n--)
89 break;
90 *args++ = regs->r9;
91 case 6:
92 if (!n--)
93 break;
94 default:
95 BUG();
96 }
97}
98
99static inline void syscall_set_arguments(struct task_struct *task,
100 struct pt_regs *regs, unsigned int i, unsigned int n,
101 const unsigned long *args)
102{
103 BUG_ON(i + n > 6);
104
105 switch (i) {
106 case 0:
107 if (!n--)
108 break;
109 regs->r4 = *args++;
110 case 1:
111 if (!n--)
112 break;
113 regs->r5 = *args++;
114 case 2:
115 if (!n--)
116 break;
117 regs->r6 = *args++;
118 case 3:
119 if (!n--)
120 break;
121 regs->r7 = *args++;
122 case 4:
123 if (!n--)
124 break;
125 regs->r8 = *args++;
126 case 5:
127 if (!n--)
128 break;
129 regs->r9 = *args++;
130 case 6:
131 if (!n)
132 break;
133 default:
134 BUG();
135 }
136}
137
138#endif
diff --git a/arch/nios2/include/asm/syscalls.h b/arch/nios2/include/asm/syscalls.h
new file mode 100644
index 000000000000..0245d780351b
--- /dev/null
+++ b/arch/nios2/include/asm/syscalls.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright Altera Corporation (C) 2013. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#ifndef __ASM_NIOS2_SYSCALLS_H
18#define __ASM_NIOS2_SYSCALLS_H
19
20int sys_cacheflush(unsigned long addr, unsigned long len,
21 unsigned int op);
22
23#include <asm-generic/syscalls.h>
24
25#endif /* __ASM_NIOS2_SYSCALLS_H */
diff --git a/arch/nios2/include/uapi/asm/unistd.h b/arch/nios2/include/uapi/asm/unistd.h
new file mode 100644
index 000000000000..c4bf79510461
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/unistd.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 #define sys_mmap2 sys_mmap_pgoff
19
20/* Use the standard ABI for syscalls */
21#include <asm-generic/unistd.h>
22
23/* Additional Nios II specific syscalls. */
24#define __NR_cacheflush (__NR_arch_specific_syscall)
25__SYSCALL(__NR_cacheflush, sys_cacheflush)