xref: /openbmc/linux/arch/csky/include/asm/syscall.h (revision ac8b6f14)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __ASM_SYSCALL_H
4 #define __ASM_SYSCALL_H
5 
6 #include <linux/sched.h>
7 #include <linux/err.h>
8 #include <abi/regdef.h>
9 
10 static inline int
11 syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
12 {
13 	return regs_syscallid(regs);
14 }
15 
16 static inline void
17 syscall_rollback(struct task_struct *task, struct pt_regs *regs)
18 {
19 	regs->a0 = regs->orig_a0;
20 }
21 
22 static inline long
23 syscall_get_error(struct task_struct *task, struct pt_regs *regs)
24 {
25 	unsigned long error = regs->a0;
26 
27 	return IS_ERR_VALUE(error) ? error : 0;
28 }
29 
30 static inline long
31 syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
32 {
33 	return regs->a0;
34 }
35 
36 static inline void
37 syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
38 		int error, long val)
39 {
40 	regs->a0 = (long) error ?: val;
41 }
42 
43 static inline void
44 syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
45 		      unsigned int i, unsigned int n, unsigned long *args)
46 {
47 	BUG_ON(i + n > 6);
48 	if (i == 0) {
49 		args[0] = regs->orig_a0;
50 		args++;
51 		i++;
52 		n--;
53 	}
54 	memcpy(args, &regs->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
55 }
56 
57 static inline void
58 syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
59 		      unsigned int i, unsigned int n, const unsigned long *args)
60 {
61 	BUG_ON(i + n > 6);
62 	if (i == 0) {
63 		regs->orig_a0 = args[0];
64 		args++;
65 		i++;
66 		n--;
67 	}
68 	memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
69 }
70 
71 #endif	/* __ASM_SYSCALL_H */
72