1 /*
2  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
3  * ported from GNU C Library
4  */
5 
6 /* Copyright (C) 2000-2017 Free Software Foundation, Inc.
7 
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation; either version 2.1 of the
11 License, or (at your option) any later version.
12 
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>.  */
21 
22 #ifndef _BITS_SYSCALLS_H
23 #define _BITS_SYSCALLS_H
24 #ifndef _SYSCALL_H
25 # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
26 #endif
27 
28 #ifndef __ASSEMBLER__
29 
30 #define __SYSCALL_CLOBBERS						\
31 	"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",			\
32 	"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",		\
33 	"f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",		\
34 	"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",		\
35 	"f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",		\
36 	"f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",		\
37 	"cc", "memory"
38 
39 #define __SYSCALL_STRING						\
40 	"ta	0x6d;"							\
41 	"bcc,pt	%%xcc, 1f;"						\
42 	" mov	0, %%g1;"						\
43 	"sub	%%g0, %%o0, %%o0;"					\
44 	"mov	1, %%g1;"						\
45 	"1:"
46 
47 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) 		\
48 ({                                               		\
49             register long __o0 __asm__("o0");            	\
50 	    long err = name;					\
51             LOAD_ARGS_##nr(args)                           	\
52 								\
53             __asm__ __volatile__( __SYSCALL_STRING          	\
54                 : "=r" (err), "=r" (__o0)                   	\
55                 : "0" (err), "1" (__o0) ASM_ARGS_##nr       	\
56                 : __SYSCALL_CLOBBERS );	                    	\
57             __o0;					    	\
58 })
59 
60 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
61   ((unsigned int) (val) >= 0xfffff001u)
62 
63 #define INLINE_CLONE_SYSCALL(arg1,arg2,arg3,arg4,arg5)			\
64 ({									\
65 	register long __o0 __asm__ ("o0") = (long)(arg1);		\
66 	register long __o1 __asm__ ("o1") = (long)(arg2);		\
67 	register long __o2 __asm__ ("o2") = (long)(arg3);		\
68 	register long __o3 __asm__ ("o3") = (long)(arg4);		\
69 	register long __o4 __asm__ ("o4") = (long)(arg5);		\
70 	register long __g1 __asm__ ("g1") = __NR_clone;			\
71 	__asm __volatile (__SYSCALL_STRING :				\
72 			  "=r" (__g1), "=r" (__o0), "=r" (__o1)	:	\
73 			  "0" (__g1), "1" (__o0), "2" (__o1),		\
74 			  "r" (__o2), "r" (__o3), "r" (__o4) :		\
75 			  __SYSCALL_CLOBBERS);				\
76 	if (INTERNAL_SYSCALL_ERROR_P (__o0, __g1))			\
77 	  {		     			       		   	\
78 	    __set_errno (INTERNAL_SYSCALL_ERRNO (__o0, __g1));		\
79 	    __o0 = -1L;			    				\
80 	  } 	      							\
81 	else								\
82 	  { 	      							\
83 	    __o0 &= (__o1 - 1);						\
84 	  } 	    	    						\
85 	__o0;								\
86 })
87 
88 #define LOAD_ARGS_0()
89 #define ASM_ARGS_0
90 #define LOAD_ARGS_1(o0) \
91     __o0 = (long)o0;     \
92     LOAD_ARGS_0()
93 #define ASM_ARGS_1 ASM_ARGS_0, "r" (__o0)
94 #define LOAD_ARGS_2(o0, o1)			\
95   register long __o1 __asm__ ("o1") = (long) (o1);	\
96   LOAD_ARGS_1 (o0)
97 #define ASM_ARGS_2	ASM_ARGS_1, "r" (__o1)
98 #define LOAD_ARGS_3(o0, o1, o2)			\
99   register long __o2 __asm__ ("o2") = (long) (o2);	\
100   LOAD_ARGS_2 (o0, o1)
101 #define ASM_ARGS_3	ASM_ARGS_2, "r" (__o2)
102 #define LOAD_ARGS_4(o0, o1, o2, o3)		\
103   register long __o3 __asm__ ("o3") = (long) (o3);	\
104   LOAD_ARGS_3 (o0, o1, o2)
105 #define ASM_ARGS_4	ASM_ARGS_3, "r" (__o3)
106 #define LOAD_ARGS_5(o0, o1, o2, o3, o4)		\
107   register long __o4 __asm__ ("o4") = (long) (o4);	\
108   LOAD_ARGS_4 (o0, o1, o2, o3)
109 #define ASM_ARGS_5	ASM_ARGS_4, "r" (__o4)
110 #define LOAD_ARGS_6(o0, o1, o2, o3, o4, o5)	\
111   register long __o5 __asm__ ("o5") = (long) (o5);	\
112   LOAD_ARGS_5 (o0, o1, o2, o3, o4)
113 #define ASM_ARGS_6	ASM_ARGS_5, "r" (__o5)
114 
115 #endif /* __ASSEMBLER__ */
116 #endif /* _BITS_SYSCALLS_H */
117