]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/tile/sysdep.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / tile / sysdep.h
1 /* Copyright (C) 2011-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <asm/unistd.h>
20 #include <sysdeps/tile/sysdep.h>
21 #include <sysdeps/unix/sysv/linux/generic/sysdep.h>
22 #include <sys/syscall.h>
23
24 #undef SYS_ify
25 #define SYS_ify(syscall_name) __NR_##syscall_name
26
27
28 #ifdef __ASSEMBLER__
29
30 /* The actual implementation of doing a syscall. */
31 #define DO_CALL(syscall_name, args) \
32 moveli TREG_SYSCALL_NR_NAME, SYS_ify(syscall_name); \
33 swint1
34
35 /* TILE Linux returns the result in r0 (or a negative errno).
36 The kernel "owns" the code to decide if a given value is an error,
37 and puts errno in r1 if so, or otherwise zero. */
38 #define PSEUDO(name, syscall_name, args) \
39 ENTRY (name); \
40 DO_CALL(syscall_name, args); \
41 BNEZ r1, 0f
42
43 #define ret jrp lr
44
45 #ifndef PIC
46 /* For static code, on error jump to __syscall_error directly. */
47 # define SYSCALL_ERROR_NAME __syscall_error
48 #elif IS_IN (libc) || IS_IN (libpthread)
49 /* Use the internal name for libc/libpthread shared objects. */
50 # define SYSCALL_ERROR_NAME __GI___syscall_error
51 #else
52 /* Otherwise, on error do a full PLT jump. */
53 # define SYSCALL_ERROR_NAME plt(__syscall_error)
54 #endif
55
56 #undef PSEUDO_END
57 #define PSEUDO_END(name) \
58 0: \
59 j SYSCALL_ERROR_NAME; \
60 END (name)
61
62 #undef PSEUDO_NOERRNO
63 #define PSEUDO_NOERRNO(name, syscall_name, args) \
64 ENTRY (name); \
65 DO_CALL(syscall_name, args)
66
67 #define ret_NOERRNO jrp lr
68
69 #undef PSEUDO_END_NOERRNO
70 #define PSEUDO_END_NOERRNO(name) \
71 END (name)
72
73 /* Convenience wrappers. */
74 #define SYSCALL__(name, args) PSEUDO (__##name, name, args)
75 #define SYSCALL(name, args) PSEUDO (name, name, args)
76
77 #else /* not __ASSEMBLER__ */
78
79 #include <errno.h>
80
81 /* Define a macro which expands inline into the wrapper code for a system
82 call. */
83 # undef INLINE_SYSCALL
84 # define INLINE_SYSCALL(name, nr, args...) \
85 ({ \
86 INTERNAL_SYSCALL_DECL (_sc_err); \
87 unsigned long _sc_val = INTERNAL_SYSCALL (name, _sc_err, nr, args); \
88 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sc_val, _sc_err), 0)) \
89 { \
90 __set_errno (INTERNAL_SYSCALL_ERRNO (_sc_val, _sc_err)); \
91 _sc_val = -1; \
92 } \
93 (long) _sc_val; \
94 })
95
96 #undef INTERNAL_SYSCALL
97 #define INTERNAL_SYSCALL(name, err, nr, args...) \
98 internal_syscall##nr (SYS_ify (name), err, args)
99
100 #undef INTERNAL_SYSCALL_NCS
101 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
102 internal_syscall##nr (number, err, args)
103
104 #undef INTERNAL_SYSCALL_DECL
105 #define INTERNAL_SYSCALL_DECL(err) int err
106
107 #undef INTERNAL_SYSCALL_ERROR_P
108 #define INTERNAL_SYSCALL_ERROR_P(val, err) ({ (void) (val); (err) != 0; })
109
110 #undef INTERNAL_SYSCALL_ERRNO
111 #define INTERNAL_SYSCALL_ERRNO(val, err) ({ (void) (val); (err); })
112
113 #define internal_syscall0(num, err, dummy...) \
114 ({ \
115 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
116 __asm__ __volatile__ ( \
117 "swint1" \
118 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
119 : "R10" (num) \
120 : __SYSCALL_CLOBBERS); \
121 _sys_result; \
122 })
123
124 #define internal_syscall1(num, err, arg0) \
125 ({ \
126 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
127 __asm__ __volatile__ ( \
128 "swint1" \
129 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
130 : "R10" (num), "R00" (arg0) \
131 : __SYSCALL_CLOBBERS); \
132 _sys_result; \
133 })
134
135 #define internal_syscall2(num, err, arg0, arg1) \
136 ({ \
137 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
138 __asm__ __volatile__ ( \
139 "swint1" \
140 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
141 : "R10" (num), "R00" (arg0), "R01" (arg1) \
142 : __SYSCALL_CLOBBERS); \
143 _sys_result; \
144 })
145
146 #define internal_syscall3(num, err, arg0, arg1, arg2) \
147 ({ \
148 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
149 __asm__ __volatile__ ( \
150 "swint1" \
151 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
152 : "R10" (num), "R00" (arg0), "R01" (arg1), "R02" (arg2) \
153 : __SYSCALL_CLOBBERS); \
154 _sys_result; \
155 })
156
157 #define internal_syscall4(num, err, arg0, arg1, arg2, arg3) \
158 ({ \
159 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
160 __asm__ __volatile__ ( \
161 "swint1" \
162 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
163 : "R10" (num), "R00" (arg0), "R01" (arg1), "R02" (arg2), \
164 "R03" (arg3) \
165 : __SYSCALL_CLOBBERS); \
166 _sys_result; \
167 })
168
169 #define internal_syscall5(num, err, arg0, arg1, arg2, arg3, arg4) \
170 ({ \
171 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
172 __asm__ __volatile__ ( \
173 "swint1" \
174 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
175 : "R10" (num), "R00" (arg0), "R01" (arg1), "R02" (arg2), \
176 "R03" (arg3), "R04" (arg4) \
177 : __SYSCALL_CLOBBERS); \
178 _sys_result; \
179 })
180
181 #define internal_syscall6(num, err, arg0, arg1, arg2, arg3, arg4, arg5) \
182 ({ \
183 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
184 __asm__ __volatile__ ( \
185 "swint1" \
186 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
187 : "R10" (num), "R00" (arg0), "R01" (arg1), "R02" (arg2), \
188 "R03" (arg3), "R04" (arg4), "R05" (arg5) \
189 : __SYSCALL_CLOBBERS); \
190 _sys_result; \
191 })
192
193 #undef __SYSCALL_CLOBBERS
194 #define __SYSCALL_CLOBBERS \
195 "r6", "r7", \
196 "r8", "r9", "r11", "r12", "r13", "r14", "r15", \
197 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", \
198 "r24", "r25", "r26", "r27", "r28", "r29", "memory"
199
200 /* gcc doesn't seem to allow an input operand to be clobbered, so we
201 fake it with dummy outputs. */
202 #define __SYSCALL_CLOBBER_DECLS \
203 _clobber_r2, _clobber_r3, _clobber_r4, _clobber_r5, _clobber_r10
204
205 #define __SYSCALL_CLOBBER_OUTPUTS \
206 "=R02" (_clobber_r2), "=R03" (_clobber_r3), "=R04" (_clobber_r4), \
207 "=R05" (_clobber_r5), "=R10" (_clobber_r10)
208
209
210 #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
211 ({ \
212 struct syscall_return_value _sc_rv = funcptr (args); \
213 err = _sc_rv.error; \
214 _sc_rv.value; \
215 })
216
217 /* List of system calls which are supported as vsyscalls. */
218 #define HAVE_CLOCK_GETTIME_VSYSCALL 1
219 #define HAVE_GETTIMEOFDAY_VSYSCALL 1
220
221 #endif /* __ASSEMBLER__ */
222
223 /* Pointer mangling support. */
224 #if IS_IN (rtld)
225 /* We cannot use the thread descriptor because in ld.so we use setjmp
226 earlier than the descriptor is initialized. */
227 #else
228 # ifdef __ASSEMBLER__
229 # define PTR_MANGLE(reg, tmpreg) \
230 ADDLI_PTR tmpreg, pt, POINTER_GUARD; \
231 LD tmpreg, tmpreg; \
232 xor reg, tmpreg, reg
233 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
234 # else
235 # define PTR_MANGLE(var) \
236 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
237 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
238 # endif
239 #endif