xref: /openbmc/linux/arch/nios2/include/asm/syscall.h (revision 3213486f)
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 
23 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
24 {
25 	return regs->r2;
26 }
27 
28 static 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 
35 static inline long syscall_get_error(struct task_struct *task,
36 				struct pt_regs *regs)
37 {
38 	return regs->r7 ? regs->r2 : 0;
39 }
40 
41 static inline long syscall_get_return_value(struct task_struct *task,
42 	struct pt_regs *regs)
43 {
44 	return regs->r2;
45 }
46 
47 static 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 
60 static inline void syscall_get_arguments(struct task_struct *task,
61 	struct pt_regs *regs, unsigned long *args)
62 {
63 	*args++ = regs->r4;
64 	*args++ = regs->r5;
65 	*args++ = regs->r6;
66 	*args++ = regs->r7;
67 	*args++ = regs->r8;
68 	*args   = regs->r9;
69 }
70 
71 static inline void syscall_set_arguments(struct task_struct *task,
72 	struct pt_regs *regs, const unsigned long *args)
73 {
74 	regs->r4 = *args++;
75 	regs->r5 = *args++;
76 	regs->r6 = *args++;
77 	regs->r7 = *args++;
78 	regs->r8 = *args++;
79 	regs->r9 = *args;
80 }
81 
82 #endif
83