Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / ia64 / sysdep.h
blob4b732632d69892c6176f10e17b36f49536f3d861
1 /* Copyright (C) 1999-2014 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, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _LINUX_IA64_SYSDEP_H
21 #define _LINUX_IA64_SYSDEP_H 1
23 #include <sysdeps/unix/sysdep.h>
24 #include <sysdeps/ia64/sysdep.h>
25 #include <dl-sysdep.h>
26 #include <tls.h>
28 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
29 #ifndef __ASSEMBLER__
30 #include <errno.h>
31 #endif
33 /* As of GAS v2.4.90.0.7, including a ".align" directive inside a
34 function will cause bad unwind info to be emitted (GAS doesn't know
35 how to account for the padding introduced by the .align directive).
36 Turning on this macro will work around this bug by introducing the
37 necessary padding explicitly. */
38 #define GAS_ALIGN_BREAKS_UNWIND_INFO
40 /* For Linux we can use the system call table in the header file
41 /usr/include/asm/unistd.h
42 of the kernel. But these symbols do not follow the SYS_* syntax
43 so we have to redefine the `SYS_ify' macro here. */
44 #undef SYS_ify
45 #define SYS_ify(syscall_name) __NR_##syscall_name
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 __attribute__ ((unused))
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) \
268 ({ (void) (val); \
269 (err == -1); \
272 #undef INTERNAL_SYSCALL_ERRNO
273 #define INTERNAL_SYSCALL_ERRNO(val, err) (val)
275 #define LOAD_ARGS_0()
276 #define LOAD_REGS_0
277 #define LOAD_ARGS_1(a1) \
278 long _arg1 = (long) (a1); \
279 LOAD_ARGS_0 ()
280 #define LOAD_REGS_1 \
281 register long _out0 asm ("out0") = _arg1; \
282 LOAD_REGS_0
283 #define LOAD_ARGS_2(a1, a2) \
284 long _arg2 = (long) (a2); \
285 LOAD_ARGS_1 (a1)
286 #define LOAD_REGS_2 \
287 register long _out1 asm ("out1") = _arg2; \
288 LOAD_REGS_1
289 #define LOAD_ARGS_3(a1, a2, a3) \
290 long _arg3 = (long) (a3); \
291 LOAD_ARGS_2 (a1, a2)
292 #define LOAD_REGS_3 \
293 register long _out2 asm ("out2") = _arg3; \
294 LOAD_REGS_2
295 #define LOAD_ARGS_4(a1, a2, a3, a4) \
296 long _arg4 = (long) (a4); \
297 LOAD_ARGS_3 (a1, a2, a3)
298 #define LOAD_REGS_4 \
299 register long _out3 asm ("out3") = _arg4; \
300 LOAD_REGS_3
301 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
302 long _arg5 = (long) (a5); \
303 LOAD_ARGS_4 (a1, a2, a3, a4)
304 #define LOAD_REGS_5 \
305 register long _out4 asm ("out4") = _arg5; \
306 LOAD_REGS_4
307 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
308 long _arg6 = (long) (a6); \
309 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
310 #define LOAD_REGS_6 \
311 register long _out5 asm ("out5") = _arg6; \
312 LOAD_REGS_5
314 #define ASM_OUTARGS_0
315 #define ASM_OUTARGS_1 ASM_OUTARGS_0, "=r" (_out0)
316 #define ASM_OUTARGS_2 ASM_OUTARGS_1, "=r" (_out1)
317 #define ASM_OUTARGS_3 ASM_OUTARGS_2, "=r" (_out2)
318 #define ASM_OUTARGS_4 ASM_OUTARGS_3, "=r" (_out3)
319 #define ASM_OUTARGS_5 ASM_OUTARGS_4, "=r" (_out4)
320 #define ASM_OUTARGS_6 ASM_OUTARGS_5, "=r" (_out5)
322 #ifdef IA64_USE_NEW_STUB
323 #define ASM_ARGS_0
324 #define ASM_ARGS_1 ASM_ARGS_0, "4" (_out0)
325 #define ASM_ARGS_2 ASM_ARGS_1, "5" (_out1)
326 #define ASM_ARGS_3 ASM_ARGS_2, "6" (_out2)
327 #define ASM_ARGS_4 ASM_ARGS_3, "7" (_out3)
328 #define ASM_ARGS_5 ASM_ARGS_4, "8" (_out4)
329 #define ASM_ARGS_6 ASM_ARGS_5, "9" (_out5)
330 #else
331 #define ASM_ARGS_0
332 #define ASM_ARGS_1 ASM_ARGS_0, "3" (_out0)
333 #define ASM_ARGS_2 ASM_ARGS_1, "4" (_out1)
334 #define ASM_ARGS_3 ASM_ARGS_2, "5" (_out2)
335 #define ASM_ARGS_4 ASM_ARGS_3, "6" (_out3)
336 #define ASM_ARGS_5 ASM_ARGS_4, "7" (_out4)
337 #define ASM_ARGS_6 ASM_ARGS_5, "8" (_out5)
338 #endif
340 #define ASM_CLOBBERS_0 ASM_CLOBBERS_1, "out0"
341 #define ASM_CLOBBERS_1 ASM_CLOBBERS_2, "out1"
342 #define ASM_CLOBBERS_2 ASM_CLOBBERS_3, "out2"
343 #define ASM_CLOBBERS_3 ASM_CLOBBERS_4, "out3"
344 #define ASM_CLOBBERS_4 ASM_CLOBBERS_5, "out4"
345 #define ASM_CLOBBERS_5 ASM_CLOBBERS_6, "out5"
346 #define ASM_CLOBBERS_6_COMMON , "out6", "out7", \
347 /* Non-stacked integer registers, minus r8, r10, r15. */ \
348 "r2", "r3", "r9", "r11", "r12", "r13", "r14", "r16", "r17", "r18", \
349 "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
350 "r28", "r29", "r30", "r31", \
351 /* Predicate registers. */ \
352 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
353 /* Non-rotating fp registers. */ \
354 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
355 /* Branch registers. */ \
356 "b6"
358 #ifdef IA64_USE_NEW_STUB
359 # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON
360 #else
361 # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON , "b7"
362 #endif
364 #endif /* not __ASSEMBLER__ */
366 /* Pointer mangling support. */
367 #if defined NOT_IN_libc && defined IS_IN_rtld
368 /* We cannot use the thread descriptor because in ld.so we use setjmp
369 earlier than the descriptor is initialized. */
370 #else
371 # ifdef __ASSEMBLER__
372 # define PTR_MANGLE(reg, tmpreg) \
373 add tmpreg=-16,r13 \
374 ;; \
375 ld8 tmpreg=[tmpreg] \
376 ;; \
377 xor reg=reg, tmpreg
378 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
379 # else
380 # define PTR_MANGLE(var) \
381 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
382 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
383 # endif
384 #endif
386 #endif /* linux/ia64/sysdep.h */