xref: /openbmc/linux/arch/s390/include/asm/syscall.h (revision fd589a8f)
1 /*
2  * Access to user system call parameters and results
3  *
4  *  Copyright IBM Corp. 2008
5  *  Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License (version 2 only)
9  * as published by the Free Software Foundation.
10  */
11 
12 #ifndef _ASM_SYSCALL_H
13 #define _ASM_SYSCALL_H	1
14 
15 #include <linux/sched.h>
16 #include <asm/ptrace.h>
17 
18 static inline long syscall_get_nr(struct task_struct *task,
19 				  struct pt_regs *regs)
20 {
21 	return regs->svcnr ? regs->svcnr : -1;
22 }
23 
24 static inline void syscall_rollback(struct task_struct *task,
25 				    struct pt_regs *regs)
26 {
27 	regs->gprs[2] = regs->orig_gpr2;
28 }
29 
30 static inline long syscall_get_error(struct task_struct *task,
31 				     struct pt_regs *regs)
32 {
33 	return (regs->gprs[2] >= -4096UL) ? -regs->gprs[2] : 0;
34 }
35 
36 static inline long syscall_get_return_value(struct task_struct *task,
37 					    struct pt_regs *regs)
38 {
39 	return regs->gprs[2];
40 }
41 
42 static inline void syscall_set_return_value(struct task_struct *task,
43 					    struct pt_regs *regs,
44 					    int error, long val)
45 {
46 	regs->gprs[2] = error ? -error : val;
47 }
48 
49 static inline void syscall_get_arguments(struct task_struct *task,
50 					 struct pt_regs *regs,
51 					 unsigned int i, unsigned int n,
52 					 unsigned long *args)
53 {
54 	unsigned long mask = -1UL;
55 
56 	BUG_ON(i + n > 6);
57 #ifdef CONFIG_COMPAT
58 	if (test_tsk_thread_flag(task, TIF_31BIT))
59 		mask = 0xffffffff;
60 #endif
61 	if (i + n == 6)
62 		args[--n] = regs->args[0] & mask;
63 	while (n-- > 0)
64 		if (i + n > 0)
65 			args[n] = regs->gprs[2 + i + n] & mask;
66 	if (i == 0)
67 		args[0] = regs->orig_gpr2 & mask;
68 }
69 
70 static inline void syscall_set_arguments(struct task_struct *task,
71 					 struct pt_regs *regs,
72 					 unsigned int i, unsigned int n,
73 					 const unsigned long *args)
74 {
75 	BUG_ON(i + n > 6);
76 	if (i + n == 6)
77 		regs->args[0] = args[--n];
78 	while (n-- > 0)
79 		if (i + n > 0)
80 			regs->gprs[2 + i + n] = args[n];
81 	if (i == 0)
82 		regs->orig_gpr2 = args[0];
83 }
84 
85 #endif	/* _ASM_SYSCALL_H */
86