1 /* Copyright (C) 1992, 1995, 1996, 2000, 2003, 2004
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Brendan Kehoe (brendan@zen.org).
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <sysdeps/unix/sysdep.h>
26 # include <alpha/regdef.h>
31 #include <tls.h> /* Defines USE___THREAD. */
34 # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
39 #define __LABEL(x) x##:
41 #define __LABEL(x) x/**/:
44 #define LEAF(name, framesize) \
49 .frame sp, framesize, ra
58 /* Mark the end of function SYM. */
60 #define END(sym) .end sym
63 # define PSEUDO_PROLOGUE \
68 jsr AT,(AT),_mcount; \
72 # define PSEUDO_PROLOGUE \
76 # define PSEUDO_PROLOGUE \
82 #if RTLD_PRIVATE_ERRNO
83 # define SYSCALL_ERROR_LABEL $syscall_error
84 # define SYSCALL_ERROR_HANDLER \
85 stl v0, rtld_errno(gp) !gprel; \
89 # define SYSCALL_ERROR_LABEL __syscall_error
90 # define SYSCALL_ERROR_HANDLER \
91 br $31, __syscall_error !samegp
93 # define SYSCALL_ERROR_LABEL $syscall_error
94 # define SYSCALL_ERROR_HANDLER \
95 jmp $31, __syscall_error
96 #endif /* RTLD_PRIVATE_ERRNO */
98 /* Overridden by specific syscalls. */
99 #undef PSEUDO_PREPARE_ARGS
100 #define PSEUDO_PREPARE_ARGS /* Nothing. */
102 #define PSEUDO(name, syscall_name, args) \
108 PSEUDO_PREPARE_ARGS \
109 lda v0, SYS_ify(syscall_name); \
110 call_pal PAL_callsys; \
111 bne a3, SYSCALL_ERROR_LABEL
114 #if defined(PIC) && !RTLD_PRIVATE_ERRNO
115 # define PSEUDO_END(sym) END(sym)
117 # define PSEUDO_END(sym) \
119 SYSCALL_ERROR_HANDLER; \
123 #define PSEUDO_NOERRNO(name, syscall_name, args) \
129 PSEUDO_PREPARE_ARGS \
130 lda v0, SYS_ify(syscall_name); \
131 call_pal PAL_callsys;
133 #undef PSEUDO_END_NOERRNO
134 #define PSEUDO_END_NOERRNO(sym) END(sym)
136 #define ret_NOERRNO ret
138 #define PSEUDO_ERRVAL(name, syscall_name, args) \
144 PSEUDO_PREPARE_ARGS \
145 lda v0, SYS_ify(syscall_name); \
146 call_pal PAL_callsys;
148 #undef PSEUDO_END_ERRVAL
149 #define PSEUDO_END_ERRVAL(sym) END(sym)
151 #define ret_ERRVAL ret
156 #define MOVE(x,y) mov x,y
158 #else /* !ASSEMBLER */
160 /* ??? Linux needs to be able to override INLINE_SYSCALL for one
161 particular special case. Make this easy. */
163 #undef INLINE_SYSCALL
164 #define INLINE_SYSCALL(name, nr, args...) \
165 INLINE_SYSCALL1(name, nr, args)
167 #define INLINE_SYSCALL1(name, nr, args...) \
169 long _sc_ret, _sc_err; \
170 inline_syscall##nr(__NR_##name, args); \
171 if (__builtin_expect (_sc_err, 0)) \
173 __set_errno (_sc_ret); \
179 #define INTERNAL_SYSCALL(name, err_out, nr, args...) \
180 INTERNAL_SYSCALL1(name, err_out, nr, args)
182 #define INTERNAL_SYSCALL1(name, err_out, nr, args...) \
183 INTERNAL_SYSCALL_NCS(__NR_##name, err_out, nr, args)
185 #define INTERNAL_SYSCALL_NCS(name, err_out, nr, args...) \
187 long _sc_ret, _sc_err; \
188 inline_syscall##nr(name, args); \
193 #define INTERNAL_SYSCALL_DECL(err) long int err
194 #define INTERNAL_SYSCALL_ERROR_P(val, err) err
195 #define INTERNAL_SYSCALL_ERRNO(val, err) val
197 #define inline_syscall_clobbers \
198 "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
199 "$22", "$23", "$24", "$25", "$27", "$28", "memory"
201 /* If TLS is in use, we have a conflict between the PAL_rduniq primitive,
202 as modeled within GCC, and explicit use of the R0 register. If we use
203 the register via the asm, the scheduler may place the PAL_rduniq insn
204 before we've copied the data from R0 into _sc_ret. If this happens
205 we'll get a reload abort, since R0 is live at the same time it is
206 needed for the PAL_rduniq.
208 Solve this by using the "v" constraint instead of an asm for the syscall
209 output. We don't do this unconditionally to allow compilation with
213 #define inline_syscall_r0_asm
214 #define inline_syscall_r0_out_constraint "=v"
216 #define inline_syscall_r0_asm __asm__("$0")
217 #define inline_syscall_r0_out_constraint "=r"
220 /* It is moderately important optimization-wise to limit the lifetime
221 of the hard-register variables as much as possible. Thus we copy
222 in/out as close to the asm as possible. */
224 #define inline_syscall0(name, args...) \
226 register long _sc_0 inline_syscall_r0_asm; \
227 register long _sc_19 __asm__("$19"); \
230 __asm__ __volatile__ \
231 ("callsys # %0 %1 <= %2" \
232 : inline_syscall_r0_out_constraint (_sc_0), \
235 : inline_syscall_clobbers, \
236 "$16", "$17", "$18", "$20", "$21"); \
237 _sc_ret = _sc_0, _sc_err = _sc_19; \
240 #define inline_syscall1(name,arg1) \
242 register long _sc_0 inline_syscall_r0_asm; \
243 register long _sc_16 __asm__("$16"); \
244 register long _sc_19 __asm__("$19"); \
247 _sc_16 = (long) (arg1); \
248 __asm__ __volatile__ \
249 ("callsys # %0 %1 <= %2 %3" \
250 : inline_syscall_r0_out_constraint (_sc_0), \
251 "=r"(_sc_19), "=r"(_sc_16) \
252 : "0"(_sc_0), "2"(_sc_16) \
253 : inline_syscall_clobbers, \
254 "$17", "$18", "$20", "$21"); \
255 _sc_ret = _sc_0, _sc_err = _sc_19; \
258 #define inline_syscall2(name,arg1,arg2) \
260 register long _sc_0 inline_syscall_r0_asm; \
261 register long _sc_16 __asm__("$16"); \
262 register long _sc_17 __asm__("$17"); \
263 register long _sc_19 __asm__("$19"); \
266 _sc_16 = (long) (arg1); \
267 _sc_17 = (long) (arg2); \
268 __asm__ __volatile__ \
269 ("callsys # %0 %1 <= %2 %3 %4" \
270 : inline_syscall_r0_out_constraint (_sc_0), \
271 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17) \
272 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17) \
273 : inline_syscall_clobbers, \
274 "$18", "$20", "$21"); \
275 _sc_ret = _sc_0, _sc_err = _sc_19; \
278 #define inline_syscall3(name,arg1,arg2,arg3) \
280 register long _sc_0 inline_syscall_r0_asm; \
281 register long _sc_16 __asm__("$16"); \
282 register long _sc_17 __asm__("$17"); \
283 register long _sc_18 __asm__("$18"); \
284 register long _sc_19 __asm__("$19"); \
287 _sc_16 = (long) (arg1); \
288 _sc_17 = (long) (arg2); \
289 _sc_18 = (long) (arg3); \
290 __asm__ __volatile__ \
291 ("callsys # %0 %1 <= %2 %3 %4 %5" \
292 : inline_syscall_r0_out_constraint (_sc_0), \
293 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
295 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
297 : inline_syscall_clobbers, "$20", "$21"); \
298 _sc_ret = _sc_0, _sc_err = _sc_19; \
301 #define inline_syscall4(name,arg1,arg2,arg3,arg4) \
303 register long _sc_0 inline_syscall_r0_asm; \
304 register long _sc_16 __asm__("$16"); \
305 register long _sc_17 __asm__("$17"); \
306 register long _sc_18 __asm__("$18"); \
307 register long _sc_19 __asm__("$19"); \
310 _sc_16 = (long) (arg1); \
311 _sc_17 = (long) (arg2); \
312 _sc_18 = (long) (arg3); \
313 _sc_19 = (long) (arg4); \
314 __asm__ __volatile__ \
315 ("callsys # %0 %1 <= %2 %3 %4 %5 %6" \
316 : inline_syscall_r0_out_constraint (_sc_0), \
317 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
319 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
320 "4"(_sc_18), "1"(_sc_19) \
321 : inline_syscall_clobbers, "$20", "$21"); \
322 _sc_ret = _sc_0, _sc_err = _sc_19; \
325 #define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
327 register long _sc_0 inline_syscall_r0_asm; \
328 register long _sc_16 __asm__("$16"); \
329 register long _sc_17 __asm__("$17"); \
330 register long _sc_18 __asm__("$18"); \
331 register long _sc_19 __asm__("$19"); \
332 register long _sc_20 __asm__("$20"); \
335 _sc_16 = (long) (arg1); \
336 _sc_17 = (long) (arg2); \
337 _sc_18 = (long) (arg3); \
338 _sc_19 = (long) (arg4); \
339 _sc_20 = (long) (arg5); \
340 __asm__ __volatile__ \
341 ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \
342 : inline_syscall_r0_out_constraint (_sc_0), \
343 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
344 "=r"(_sc_18), "=r"(_sc_20) \
345 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
346 "4"(_sc_18), "1"(_sc_19), "5"(_sc_20) \
347 : inline_syscall_clobbers, "$21"); \
348 _sc_ret = _sc_0, _sc_err = _sc_19; \
351 #define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
353 register long _sc_0 inline_syscall_r0_asm; \
354 register long _sc_16 __asm__("$16"); \
355 register long _sc_17 __asm__("$17"); \
356 register long _sc_18 __asm__("$18"); \
357 register long _sc_19 __asm__("$19"); \
358 register long _sc_20 __asm__("$20"); \
359 register long _sc_21 __asm__("$21"); \
362 _sc_16 = (long) (arg1); \
363 _sc_17 = (long) (arg2); \
364 _sc_18 = (long) (arg3); \
365 _sc_19 = (long) (arg4); \
366 _sc_20 = (long) (arg5); \
367 _sc_21 = (long) (arg6); \
368 __asm__ __volatile__ \
369 ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \
370 : inline_syscall_r0_out_constraint (_sc_0), \
371 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
372 "=r"(_sc_18), "=r"(_sc_20), "=r"(_sc_21) \
373 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), "4"(_sc_18), \
374 "1"(_sc_19), "5"(_sc_20), "6"(_sc_21) \
375 : inline_syscall_clobbers); \
376 _sc_ret = _sc_0, _sc_err = _sc_19; \
379 #endif /* ASSEMBLER */