xref: /openbmc/linux/arch/nios2/include/asm/syscall.h (revision 2874c5fd)
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 <uapi/linux/audit.h>
21 #include <linux/err.h>
22 #include <linux/sched.h>
23 
24 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
25 {
26 	return regs->r2;
27 }
28 
29 static inline void syscall_rollback(struct task_struct *task,
30 				struct pt_regs *regs)
31 {
32 	regs->r2 = regs->orig_r2;
33 	regs->r7 = regs->orig_r7;
34 }
35 
36 static inline long syscall_get_error(struct task_struct *task,
37 				struct pt_regs *regs)
38 {
39 	return regs->r7 ? regs->r2 : 0;
40 }
41 
42 static inline long syscall_get_return_value(struct task_struct *task,
43 	struct pt_regs *regs)
44 {
45 	return regs->r2;
46 }
47 
48 static inline void syscall_set_return_value(struct task_struct *task,
49 	struct pt_regs *regs, int error, long val)
50 {
51 	if (error) {
52 		/* error < 0, but nios2 uses > 0 return value */
53 		regs->r2 = -error;
54 		regs->r7 = 1;
55 	} else {
56 		regs->r2 = val;
57 		regs->r7 = 0;
58 	}
59 }
60 
61 static inline void syscall_get_arguments(struct task_struct *task,
62 	struct pt_regs *regs, unsigned long *args)
63 {
64 	*args++ = regs->r4;
65 	*args++ = regs->r5;
66 	*args++ = regs->r6;
67 	*args++ = regs->r7;
68 	*args++ = regs->r8;
69 	*args   = regs->r9;
70 }
71 
72 static inline void syscall_set_arguments(struct task_struct *task,
73 	struct pt_regs *regs, const unsigned long *args)
74 {
75 	regs->r4 = *args++;
76 	regs->r5 = *args++;
77 	regs->r6 = *args++;
78 	regs->r7 = *args++;
79 	regs->r8 = *args++;
80 	regs->r9 = *args;
81 }
82 
83 static inline int syscall_get_arch(struct task_struct *task)
84 {
85 	return AUDIT_ARCH_NIOS2;
86 }
87 
88 #endif
89