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"); \
245 register long _tmp_16 = (long) (arg1); \
249 __asm__ __volatile__ \
250 ("callsys # %0 %1 <= %2 %3" \
251 : inline_syscall_r0_out_constraint (_sc_0), \
252 "=r"(_sc_19), "=r"(_sc_16) \
253 : "0"(_sc_0), "2"(_sc_16) \
254 : inline_syscall_clobbers, \
255 "$17", "$18", "$20", "$21"); \
256 _sc_ret = _sc_0, _sc_err = _sc_19; \
259 #define inline_syscall2(name,arg1,arg2) \
261 register long _sc_0 inline_syscall_r0_asm; \
262 register long _sc_16 __asm__("$16"); \
263 register long _sc_17 __asm__("$17"); \
264 register long _sc_19 __asm__("$19"); \
265 register long _tmp_16 = (long) (arg1); \
266 register long _tmp_17 = (long) (arg2); \
271 __asm__ __volatile__ \
272 ("callsys # %0 %1 <= %2 %3 %4" \
273 : inline_syscall_r0_out_constraint (_sc_0), \
274 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17) \
275 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17) \
276 : inline_syscall_clobbers, \
277 "$18", "$20", "$21"); \
278 _sc_ret = _sc_0, _sc_err = _sc_19; \
281 #define inline_syscall3(name,arg1,arg2,arg3) \
283 register long _sc_0 inline_syscall_r0_asm; \
284 register long _sc_16 __asm__("$16"); \
285 register long _sc_17 __asm__("$17"); \
286 register long _sc_18 __asm__("$18"); \
287 register long _sc_19 __asm__("$19"); \
288 register long _tmp_16 = (long) (arg1); \
289 register long _tmp_17 = (long) (arg2); \
290 register long _tmp_18 = (long) (arg3); \
296 __asm__ __volatile__ \
297 ("callsys # %0 %1 <= %2 %3 %4 %5" \
298 : inline_syscall_r0_out_constraint (_sc_0), \
299 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
301 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
303 : inline_syscall_clobbers, "$20", "$21"); \
304 _sc_ret = _sc_0, _sc_err = _sc_19; \
307 #define inline_syscall4(name,arg1,arg2,arg3,arg4) \
309 register long _sc_0 inline_syscall_r0_asm; \
310 register long _sc_16 __asm__("$16"); \
311 register long _sc_17 __asm__("$17"); \
312 register long _sc_18 __asm__("$18"); \
313 register long _sc_19 __asm__("$19"); \
314 register long _tmp_16 = (long) (arg1); \
315 register long _tmp_17 = (long) (arg2); \
316 register long _tmp_18 = (long) (arg3); \
317 register long _tmp_19 = (long) (arg4); \
324 __asm__ __volatile__ \
325 ("callsys # %0 %1 <= %2 %3 %4 %5 %6" \
326 : inline_syscall_r0_out_constraint (_sc_0), \
327 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
329 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
330 "4"(_sc_18), "1"(_sc_19) \
331 : inline_syscall_clobbers, "$20", "$21"); \
332 _sc_ret = _sc_0, _sc_err = _sc_19; \
335 #define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
337 register long _sc_0 inline_syscall_r0_asm; \
338 register long _sc_16 __asm__("$16"); \
339 register long _sc_17 __asm__("$17"); \
340 register long _sc_18 __asm__("$18"); \
341 register long _sc_19 __asm__("$19"); \
342 register long _sc_20 __asm__("$20"); \
343 register long _tmp_16 = (long) (arg1); \
344 register long _tmp_17 = (long) (arg2); \
345 register long _tmp_18 = (long) (arg3); \
346 register long _tmp_19 = (long) (arg4); \
347 register long _tmp_20 = (long) (arg5); \
355 __asm__ __volatile__ \
356 ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \
357 : inline_syscall_r0_out_constraint (_sc_0), \
358 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
359 "=r"(_sc_18), "=r"(_sc_20) \
360 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), \
361 "4"(_sc_18), "1"(_sc_19), "5"(_sc_20) \
362 : inline_syscall_clobbers, "$21"); \
363 _sc_ret = _sc_0, _sc_err = _sc_19; \
366 #define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
368 register long _sc_0 inline_syscall_r0_asm; \
369 register long _sc_16 __asm__("$16"); \
370 register long _sc_17 __asm__("$17"); \
371 register long _sc_18 __asm__("$18"); \
372 register long _sc_19 __asm__("$19"); \
373 register long _sc_20 __asm__("$20"); \
374 register long _sc_21 __asm__("$21"); \
375 register long _tmp_16 = (long) (arg1); \
376 register long _tmp_17 = (long) (arg2); \
377 register long _tmp_18 = (long) (arg3); \
378 register long _tmp_19 = (long) (arg4); \
379 register long _tmp_20 = (long) (arg5); \
380 register long _tmp_21 = (long) (arg6); \
389 __asm__ __volatile__ \
390 ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \
391 : inline_syscall_r0_out_constraint (_sc_0), \
392 "=r"(_sc_19), "=r"(_sc_16), "=r"(_sc_17), \
393 "=r"(_sc_18), "=r"(_sc_20), "=r"(_sc_21) \
394 : "0"(_sc_0), "2"(_sc_16), "3"(_sc_17), "4"(_sc_18), \
395 "1"(_sc_19), "5"(_sc_20), "6"(_sc_21) \
396 : inline_syscall_clobbers); \
397 _sc_ret = _sc_0, _sc_err = _sc_19; \
400 #endif /* ASSEMBLER */