]>
git.ipfire.org Git - thirdparty/glibc.git/blob - 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.
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.
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.
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/>. */
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>
25 #define SYS_ify(syscall_name) __NR_##syscall_name
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); \
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) \
40 DO_CALL(syscall_name, args); \
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
52 /* Otherwise, on error do a full PLT jump. */
53 # define SYSCALL_ERROR_NAME plt(__syscall_error)
57 #define PSEUDO_END(name) \
59 j SYSCALL_ERROR_NAME; \
63 #define PSEUDO_NOERRNO(name, syscall_name, args) \
65 DO_CALL(syscall_name, args)
67 #define ret_NOERRNO jrp lr
69 #undef PSEUDO_END_NOERRNO
70 #define PSEUDO_END_NOERRNO(name) \
73 /* Convenience wrappers. */
74 #define SYSCALL__(name, args) PSEUDO (__##name, name, args)
75 #define SYSCALL(name, args) PSEUDO (name, name, args)
77 #else /* not __ASSEMBLER__ */
81 /* Define a macro which expands inline into the wrapper code for a system
83 # undef INLINE_SYSCALL
84 # define INLINE_SYSCALL(name, nr, args...) \
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)) \
90 __set_errno (INTERNAL_SYSCALL_ERRNO (_sc_val, _sc_err)); \
96 #undef INTERNAL_SYSCALL
97 #define INTERNAL_SYSCALL(name, err, nr, args...) \
98 internal_syscall##nr (SYS_ify (name), err, args)
100 #undef INTERNAL_SYSCALL_NCS
101 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
102 internal_syscall##nr (number, err, args)
104 #undef INTERNAL_SYSCALL_DECL
105 #define INTERNAL_SYSCALL_DECL(err) int err
107 #undef INTERNAL_SYSCALL_ERROR_P
108 #define INTERNAL_SYSCALL_ERROR_P(val, err) ({ (void) (val); (err) != 0; })
110 #undef INTERNAL_SYSCALL_ERRNO
111 #define INTERNAL_SYSCALL_ERRNO(val, err) ({ (void) (val); (err); })
113 #define internal_syscall0(num, err, dummy...) \
115 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
116 __asm__ __volatile__ ( \
118 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
120 : __SYSCALL_CLOBBERS); \
124 #define internal_syscall1(num, err, arg0) \
126 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
127 __asm__ __volatile__ ( \
129 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
130 : "R10" (num), "R00" (arg0) \
131 : __SYSCALL_CLOBBERS); \
135 #define internal_syscall2(num, err, arg0, arg1) \
137 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
138 __asm__ __volatile__ ( \
140 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
141 : "R10" (num), "R00" (arg0), "R01" (arg1) \
142 : __SYSCALL_CLOBBERS); \
146 #define internal_syscall3(num, err, arg0, arg1, arg2) \
148 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
149 __asm__ __volatile__ ( \
151 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
152 : "R10" (num), "R00" (arg0), "R01" (arg1), "R02" (arg2) \
153 : __SYSCALL_CLOBBERS); \
157 #define internal_syscall4(num, err, arg0, arg1, arg2, arg3) \
159 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
160 __asm__ __volatile__ ( \
162 : "=R00" (_sys_result), "=R01" (err), __SYSCALL_CLOBBER_OUTPUTS \
163 : "R10" (num), "R00" (arg0), "R01" (arg1), "R02" (arg2), \
165 : __SYSCALL_CLOBBERS); \
169 #define internal_syscall5(num, err, arg0, arg1, arg2, arg3, arg4) \
171 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
172 __asm__ __volatile__ ( \
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); \
181 #define internal_syscall6(num, err, arg0, arg1, arg2, arg3, arg4, arg5) \
183 long _sys_result, __SYSCALL_CLOBBER_DECLS; \
184 __asm__ __volatile__ ( \
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); \
193 #undef __SYSCALL_CLOBBERS
194 #define __SYSCALL_CLOBBERS \
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"
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
205 #define __SYSCALL_CLOBBER_OUTPUTS \
206 "=R02" (_clobber_r2), "=R03" (_clobber_r3), "=R04" (_clobber_r4), \
207 "=R05" (_clobber_r5), "=R10" (_clobber_r10)
210 #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
212 struct syscall_return_value _sc_rv = funcptr (args); \
213 err = _sc_rv.error; \
217 /* List of system calls which are supported as vsyscalls. */
218 #define HAVE_CLOCK_GETTIME_VSYSCALL 1
219 #define HAVE_GETTIMEOFDAY_VSYSCALL 1
221 #endif /* __ASSEMBLER__ */
223 /* Pointer mangling support. */
225 /* We cannot use the thread descriptor because in ld.so we use setjmp
226 earlier than the descriptor is initialized. */
228 # ifdef __ASSEMBLER__
229 # define PTR_MANGLE(reg, tmpreg) \
230 ADDLI_PTR tmpreg, pt, POINTER_GUARD; \
233 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
235 # define PTR_MANGLE(var) \
236 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
237 # define PTR_DEMANGLE(var) PTR_MANGLE (var)