(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / ia64 / sysdep.h
bloba4453ddcc77d324157d30b961c435c68d3e178ca
1 /* Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Jes Sorensen, <Jes.Sorensen@cern.ch>, April 1999.
4 Based on code originally written by David Mosberger-Tang
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
19 02111-1307 USA. */
21 #ifndef _LINUX_IA64_SYSDEP_H
22 #define _LINUX_IA64_SYSDEP_H 1
24 #include <sysdeps/unix/sysdep.h>
25 #include <sysdeps/ia64/sysdep.h>
26 #include <dl-sysdep.h>
27 #include <tls.h>
29 /* As of GAS v2.4.90.0.7, including a ".align" directive inside a
30 function will cause bad unwind info to be emitted (GAS doesn't know
31 how to account for the padding introduced by the .align directive).
32 Turning on this macro will work around this bug by introducing the
33 necessary padding explicitly. */
34 #define GAS_ALIGN_BREAKS_UNWIND_INFO
36 /* For Linux we can use the system call table in the header file
37 /usr/include/asm/unistd.h
38 of the kernel. But these symbols do not follow the SYS_* syntax
39 so we have to redefine the `SYS_ify' macro here. */
40 #undef SYS_ify
41 #ifdef __STDC__
42 # define SYS_ify(syscall_name) __NR_##syscall_name
43 #else
44 # define SYS_ify(syscall_name) __NR_/**/syscall_name
45 #endif
47 /* This is a kludge to make syscalls.list find these under the names
48 pread and pwrite, since some kernel headers define those names
49 and some define the *64 names for the same system calls. */
50 #if !defined __NR_pread && defined __NR_pread64
51 # define __NR_pread __NR_pread64
52 #endif
53 #if !defined __NR_pwrite && defined __NR_pwrite64
54 # define __NR_pwrite __NR_pwrite64
55 #endif
57 /* This is to help the old kernel headers where __NR_semtimedop is not
58 available. */
59 #ifndef __NR_semtimedop
60 # define __NR_semtimedop 1247
61 #endif
63 #if defined USE_DL_SYSINFO \
64 && (!defined NOT_IN_libc \
65 || defined IS_IN_libpthread || defined IS_IN_librt)
66 # define IA64_USE_NEW_STUB
67 #else
68 # undef IA64_USE_NEW_STUB
69 #endif
71 #ifdef __ASSEMBLER__
73 #undef CALL_MCOUNT
74 #ifdef PROF
75 # define CALL_MCOUNT \
76 .data; \
77 1: data8 0; /* XXX fixme: use .xdata8 once labels work */ \
78 .previous; \
79 .prologue; \
80 .save ar.pfs, r40; \
81 alloc out0 = ar.pfs, 8, 0, 4, 0; \
82 mov out1 = gp; \
83 .save rp, out2; \
84 mov out2 = rp; \
85 .body; \
86 ;; \
87 addl out3 = @ltoff(1b), gp; \
88 br.call.sptk.many rp = _mcount \
90 #else
91 # define CALL_MCOUNT /* Do nothing. */
92 #endif
94 /* Linux uses a negative return value to indicate syscall errors, unlike
95 most Unices, which use the condition codes' carry flag.
97 Since version 2.1 the return value of a system call might be negative
98 even if the call succeeded. E.g., the `lseek' system call might return
99 a large offset. Therefore we must not anymore test for < 0, but test
100 for a real error by making sure the value in %d0 is a real error
101 number. Linus said he will make sure the no syscall returns a value
102 in -1 .. -4095 as a valid result so we can savely test with -4095. */
104 /* We don't want the label for the error handler to be visible in the symbol
105 table when we define it here. */
106 #define SYSCALL_ERROR_LABEL __syscall_error
108 #undef PSEUDO
109 #define PSEUDO(name, syscall_name, args) \
110 ENTRY(name) \
111 DO_CALL (SYS_ify(syscall_name)); \
112 cmp.eq p6,p0=-1,r10; \
113 (p6) br.cond.spnt.few __syscall_error;
115 #define DO_CALL_VIA_BREAK(num) \
116 mov r15=num; \
117 break __BREAK_SYSCALL
119 #ifdef IA64_USE_NEW_STUB
120 # ifdef SHARED
121 # define DO_CALL(num) \
122 .prologue; \
123 adds r2 = SYSINFO_OFFSET, r13;; \
124 ld8 r2 = [r2]; \
125 .save ar.pfs, r11; \
126 mov r11 = ar.pfs;; \
127 .body; \
128 mov r15 = num; \
129 mov b7 = r2; \
130 br.call.sptk.many b6 = b7;; \
131 .restore sp; \
132 mov ar.pfs = r11; \
133 .prologue; \
134 .body
135 # else /* !SHARED */
136 # define DO_CALL(num) \
137 .prologue; \
138 mov r15 = num; \
139 movl r2 = _dl_sysinfo;; \
140 ld8 r2 = [r2]; \
141 .save ar.pfs, r11; \
142 mov r11 = ar.pfs;; \
143 .body; \
144 mov b7 = r2; \
145 br.call.sptk.many b6 = b7;; \
146 .restore sp; \
147 mov ar.pfs = r11; \
148 .prologue; \
149 .body
150 # endif
151 #else
152 # define DO_CALL(num) DO_CALL_VIA_BREAK(num)
153 #endif
155 #undef PSEUDO_END
156 #define PSEUDO_END(name) .endp C_SYMBOL_NAME(name);
158 #undef PSEUDO_NOERRNO
159 #define PSEUDO_NOERRNO(name, syscall_name, args) \
160 ENTRY(name) \
161 DO_CALL (SYS_ify(syscall_name));
163 #undef PSEUDO_END_NOERRNO
164 #define PSEUDO_END_NOERRNO(name) .endp C_SYMBOL_NAME(name);
166 #undef PSEUDO_ERRVAL
167 #define PSEUDO_ERRVAL(name, syscall_name, args) \
168 ENTRY(name) \
169 DO_CALL (SYS_ify(syscall_name)); \
170 cmp.eq p6,p0=-1,r10; \
171 (p6) mov r10=r8;
174 #undef PSEUDO_END_ERRVAL
175 #define PSEUDO_END_ERRVAL(name) .endp C_SYMBOL_NAME(name);
177 #undef END
178 #define END(name) \
179 .size C_SYMBOL_NAME(name), . - C_SYMBOL_NAME(name) ; \
180 .endp C_SYMBOL_NAME(name)
182 #define ret br.ret.sptk.few b0
183 #define ret_NOERRNO ret
184 #define ret_ERRVAL ret
186 #else /* not __ASSEMBLER__ */
188 #define BREAK_INSN_1(num) "break " #num ";;\n\t"
189 #define BREAK_INSN(num) BREAK_INSN_1(num)
191 /* On IA-64 we have stacked registers for passing arguments. The
192 "out" registers end up being the called function's "in"
193 registers.
195 Also, since we have plenty of registers we have two return values
196 from a syscall. r10 is set to -1 on error, whilst r8 contains the
197 (non-negative) errno on error or the return value on success.
200 #ifdef IA64_USE_NEW_STUB
202 # define DO_INLINE_SYSCALL_NCS(name, nr, args...) \
203 LOAD_ARGS_##nr (args) \
204 register long _r8 __asm ("r8"); \
205 register long _r10 __asm ("r10"); \
206 register long _r15 __asm ("r15") = name; \
207 register void *_b7 __asm ("b7") = ((tcbhead_t *) __thread_self)->private; \
208 long _retval; \
209 LOAD_REGS_##nr \
210 /* \
211 * Don't specify any unwind info here. We mark ar.pfs as \
212 * clobbered. This will force the compiler to save ar.pfs \
213 * somewhere and emit appropriate unwind info for that save. \
214 */ \
215 __asm __volatile ("br.call.sptk.many b6=%0;;\n" \
216 : "=b"(_b7), "=r" (_r8), "=r" (_r10), "=r" (_r15) \
217 ASM_OUTARGS_##nr \
218 : "0" (_b7), "3" (_r15) ASM_ARGS_##nr \
219 : "memory", "ar.pfs" ASM_CLOBBERS_##nr); \
220 _retval = _r8;
222 #else /* !IA64_USE_NEW_STUB */
224 # define DO_INLINE_SYSCALL_NCS(name, nr, args...) \
225 LOAD_ARGS_##nr (args) \
226 register long _r8 asm ("r8"); \
227 register long _r10 asm ("r10"); \
228 register long _r15 asm ("r15") = name; \
229 long _retval; \
230 LOAD_REGS_##nr \
231 __asm __volatile (BREAK_INSN (__BREAK_SYSCALL) \
232 : "=r" (_r8), "=r" (_r10), "=r" (_r15) \
233 ASM_OUTARGS_##nr \
234 : "2" (_r15) ASM_ARGS_##nr \
235 : "memory" ASM_CLOBBERS_##nr); \
236 _retval = _r8;
238 #endif /* !IA64_USE_NEW_STUB */
240 #define DO_INLINE_SYSCALL(name, nr, args...) \
241 DO_INLINE_SYSCALL_NCS (__NR_##name, nr, ##args)
243 #undef INLINE_SYSCALL
244 #define INLINE_SYSCALL(name, nr, args...) \
245 ({ \
246 DO_INLINE_SYSCALL_NCS (__NR_##name, nr, args) \
247 if (_r10 == -1) \
249 __set_errno (_retval); \
250 _retval = -1; \
252 _retval; })
254 #undef INTERNAL_SYSCALL_DECL
255 #define INTERNAL_SYSCALL_DECL(err) long int err
257 #undef INTERNAL_SYSCALL
258 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
259 ({ \
260 DO_INLINE_SYSCALL_NCS (name, nr, args) \
261 err = _r10; \
262 _retval; })
263 #define INTERNAL_SYSCALL(name, err, nr, args...) \
264 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
266 #undef INTERNAL_SYSCALL_ERROR_P
267 #define INTERNAL_SYSCALL_ERROR_P(val, err) (err == -1)
269 #undef INTERNAL_SYSCALL_ERRNO
270 #define INTERNAL_SYSCALL_ERRNO(val, err) (val)
272 #define LOAD_ARGS_0()
273 #define LOAD_REGS_0
274 #define LOAD_ARGS_1(a1) \
275 long _arg1 = (long) (a1); \
276 LOAD_ARGS_0 ()
277 #define LOAD_REGS_1 \
278 register long _out0 asm ("out0") = _arg1; \
279 LOAD_REGS_0
280 #define LOAD_ARGS_2(a1, a2) \
281 long _arg2 = (long) (a2); \
282 LOAD_ARGS_1 (a1)
283 #define LOAD_REGS_2 \
284 register long _out1 asm ("out1") = _arg2; \
285 LOAD_REGS_1
286 #define LOAD_ARGS_3(a1, a2, a3) \
287 long _arg3 = (long) (a3); \
288 LOAD_ARGS_2 (a1, a2)
289 #define LOAD_REGS_3 \
290 register long _out2 asm ("out2") = _arg3; \
291 LOAD_REGS_2
292 #define LOAD_ARGS_4(a1, a2, a3, a4) \
293 long _arg4 = (long) (a4); \
294 LOAD_ARGS_3 (a1, a2, a3)
295 #define LOAD_REGS_4 \
296 register long _out3 asm ("out3") = _arg4; \
297 LOAD_REGS_3
298 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
299 long _arg5 = (long) (a5); \
300 LOAD_ARGS_4 (a1, a2, a3, a4)
301 #define LOAD_REGS_5 \
302 register long _out4 asm ("out4") = _arg5; \
303 LOAD_REGS_4
304 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
305 long _arg6 = (long) (a6); \
306 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
307 #define LOAD_REGS_6 \
308 register long _out5 asm ("out5") = _arg6; \
309 LOAD_REGS_5
311 #define ASM_OUTARGS_0
312 #define ASM_OUTARGS_1 ASM_OUTARGS_0, "=r" (_out0)
313 #define ASM_OUTARGS_2 ASM_OUTARGS_1, "=r" (_out1)
314 #define ASM_OUTARGS_3 ASM_OUTARGS_2, "=r" (_out2)
315 #define ASM_OUTARGS_4 ASM_OUTARGS_3, "=r" (_out3)
316 #define ASM_OUTARGS_5 ASM_OUTARGS_4, "=r" (_out4)
317 #define ASM_OUTARGS_6 ASM_OUTARGS_5, "=r" (_out5)
319 #ifdef IA64_USE_NEW_STUB
320 #define ASM_ARGS_0
321 #define ASM_ARGS_1 ASM_ARGS_0, "4" (_out0)
322 #define ASM_ARGS_2 ASM_ARGS_1, "5" (_out1)
323 #define ASM_ARGS_3 ASM_ARGS_2, "6" (_out2)
324 #define ASM_ARGS_4 ASM_ARGS_3, "7" (_out3)
325 #define ASM_ARGS_5 ASM_ARGS_4, "8" (_out4)
326 #define ASM_ARGS_6 ASM_ARGS_5, "9" (_out5)
327 #else
328 #define ASM_ARGS_0
329 #define ASM_ARGS_1 ASM_ARGS_0, "3" (_out0)
330 #define ASM_ARGS_2 ASM_ARGS_1, "4" (_out1)
331 #define ASM_ARGS_3 ASM_ARGS_2, "5" (_out2)
332 #define ASM_ARGS_4 ASM_ARGS_3, "6" (_out3)
333 #define ASM_ARGS_5 ASM_ARGS_4, "7" (_out4)
334 #define ASM_ARGS_6 ASM_ARGS_5, "8" (_out5)
335 #endif
337 #define ASM_CLOBBERS_0 ASM_CLOBBERS_1, "out0"
338 #define ASM_CLOBBERS_1 ASM_CLOBBERS_2, "out1"
339 #define ASM_CLOBBERS_2 ASM_CLOBBERS_3, "out2"
340 #define ASM_CLOBBERS_3 ASM_CLOBBERS_4, "out3"
341 #define ASM_CLOBBERS_4 ASM_CLOBBERS_5, "out4"
342 #define ASM_CLOBBERS_5 ASM_CLOBBERS_6, "out5"
343 #define ASM_CLOBBERS_6_COMMON , "out6", "out7", \
344 /* Non-stacked integer registers, minus r8, r10, r15. */ \
345 "r2", "r3", "r9", "r11", "r12", "r13", "r14", "r16", "r17", "r18", \
346 "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
347 "r28", "r29", "r30", "r31", \
348 /* Predicate registers. */ \
349 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
350 /* Non-rotating fp registers. */ \
351 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
352 /* Branch registers. */ \
353 "b6"
355 #ifdef IA64_USE_NEW_STUB
356 # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON
357 #else
358 # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON , "b7"
359 #endif
361 #endif /* not __ASSEMBLER__ */
363 #endif /* linux/ia64/sysdep.h */