]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/ia64/sysdep.h
1 /* Copyright (C) 1999-2021 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 <https://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/unix/sysv/linux/sysdep.h>
25 #include <sysdeps/ia64/sysdep.h>
26 #include <dl-sysdep.h>
28 #include <asm/break.h>
30 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
35 /* As of GAS v2.4.90.0.7, including a ".align" directive inside a
36 function will cause bad unwind info to be emitted (GAS doesn't know
37 how to account for the padding introduced by the .align directive).
38 Turning on this macro will work around this bug by introducing the
39 necessary padding explicitly. */
40 #define GAS_ALIGN_BREAKS_UNWIND_INFO
42 /* For Linux we can use the system call table in the header file
43 /usr/include/asm/unistd.h
44 of the kernel. But these symbols do not follow the SYS_* syntax
45 so we have to redefine the `SYS_ify' macro here. */
47 #define SYS_ify(syscall_name) __NR_##syscall_name
49 #if defined USE_DL_SYSINFO \
51 || IS_IN (libpthread) || IS_IN (librt))
52 # define IA64_USE_NEW_STUB
54 # undef IA64_USE_NEW_STUB
61 # define CALL_MCOUNT \
63 1: data8 0; /* XXX fixme: use .xdata8 once labels work */ \
67 alloc out0 = ar.pfs, 8, 0, 4, 0; \
73 addl out3 = @ltoff(1b), gp; \
74 br.call.sptk.many rp = _mcount \
77 # define CALL_MCOUNT /* Do nothing. */
80 /* Linux uses a negative return value to indicate syscall errors, unlike
81 most Unices, which use the condition codes' carry flag.
83 Since version 2.1 the return value of a system call might be negative
84 even if the call succeeded. E.g., the `lseek' system call might return
85 a large offset. Therefore we must not anymore test for < 0, but test
86 for a real error by making sure the value in %d0 is a real error
87 number. Linus said he will make sure the no syscall returns a value
88 in -1 .. -4095 as a valid result so we can savely test with -4095. */
90 /* We don't want the label for the error handler to be visible in the symbol
91 table when we define it here. */
92 #undef SYSCALL_ERROR_LABEL
93 #define SYSCALL_ERROR_LABEL __syscall_error
96 #define PSEUDO(name, syscall_name, args) \
98 DO_CALL (SYS_ify(syscall_name)); \
99 cmp.eq p6,p0=-1,r10; \
100 (p6) br.cond.spnt.few __syscall_error;
102 #define DO_CALL_VIA_BREAK(num) \
104 break __IA64_BREAK_SYSCALL
106 #ifdef IA64_USE_NEW_STUB
108 # define DO_CALL(num) \
110 adds r2 = SYSINFO_OFFSET, r13;; \
117 br.call.sptk.many b6 = b7;; \
123 # define DO_CALL(num) \
126 movl r2 = _dl_sysinfo;; \
132 br.call.sptk.many b6 = b7;; \
139 # define DO_CALL(num) DO_CALL_VIA_BREAK(num)
143 #define PSEUDO_END(name) .endp C_SYMBOL_NAME(name);
145 #undef PSEUDO_NOERRNO
146 #define PSEUDO_NOERRNO(name, syscall_name, args) \
148 DO_CALL (SYS_ify(syscall_name));
150 #undef PSEUDO_END_NOERRNO
151 #define PSEUDO_END_NOERRNO(name) .endp C_SYMBOL_NAME(name);
154 #define PSEUDO_ERRVAL(name, syscall_name, args) \
156 DO_CALL (SYS_ify(syscall_name)); \
157 cmp.eq p6,p0=-1,r10; \
161 #undef PSEUDO_END_ERRVAL
162 #define PSEUDO_END_ERRVAL(name) .endp C_SYMBOL_NAME(name);
166 .size C_SYMBOL_NAME(name), . - C_SYMBOL_NAME(name) ; \
167 .endp C_SYMBOL_NAME(name)
169 #define ret br.ret.sptk.few b0
170 #define ret_NOERRNO ret
171 #define ret_ERRVAL ret
173 #else /* not __ASSEMBLER__ */
175 #undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
176 #define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
178 #define BREAK_INSN_1(num) "break " #num ";;\n\t"
179 #define BREAK_INSN(num) BREAK_INSN_1(num)
181 /* On IA-64 we have stacked registers for passing arguments. The
182 "out" registers end up being the called function's "in"
185 Also, since we have plenty of registers we have two return values
186 from a syscall. r10 is set to -1 on error, whilst r8 contains the
187 (non-negative) errno on error or the return value on success.
190 #ifdef IA64_USE_NEW_STUB
192 # define INTERNAL_SYSCALL_NCS(name, nr, args...) \
194 LOAD_ARGS_##nr (args) \
195 register long _r8 __asm ("r8"); \
196 register long _r10 __asm ("r10"); \
197 register long _r15 __asm ("r15") = name; \
198 register void *_b7 __asm ("b7") = ((tcbhead_t *)__thread_self)->__private;\
201 * Don't specify any unwind info here. We mark ar.pfs as \
202 * clobbered. This will force the compiler to save ar.pfs \
203 * somewhere and emit appropriate unwind info for that save. \
205 __asm __volatile ("br.call.sptk.many b6=%0;;\n" \
206 : "=b"(_b7), "=r" (_r8), "=r" (_r10), "=r" (_r15) \
208 : "0" (_b7), "3" (_r15) ASM_ARGS_##nr \
209 : "memory", "ar.pfs" ASM_CLOBBERS_##nr); \
210 _r10 == -1 ? -_r8 : _r8; \
213 #else /* !IA64_USE_NEW_STUB */
215 # define INTERNAL_SYSCALL_NCS(name, nr, args...) \
217 LOAD_ARGS_##nr (args) \
218 register long _r8 asm ("r8"); \
219 register long _r10 asm ("r10"); \
220 register long _r15 asm ("r15") = name; \
222 __asm __volatile (BREAK_INSN (__IA64_BREAK_SYSCALL) \
223 : "=r" (_r8), "=r" (_r10), "=r" (_r15) \
225 : "2" (_r15) ASM_ARGS_##nr \
226 : "memory" ASM_CLOBBERS_##nr); \
227 _r10 == -1 ? -_r8 : _r8; \
230 #endif /* !IA64_USE_NEW_STUB */
232 #define INTERNAL_SYSCALL(name, nr, args...) \
233 INTERNAL_SYSCALL_NCS (__NR_##name, nr, ##args)
235 #define LOAD_ARGS_0()
237 #define LOAD_ARGS_1(a1) \
238 long _arg1 = (long) (a1); \
240 #define LOAD_REGS_1 \
241 register long _out0 asm ("out0") = _arg1; \
243 #define LOAD_ARGS_2(a1, a2) \
244 long _arg2 = (long) (a2); \
246 #define LOAD_REGS_2 \
247 register long _out1 asm ("out1") = _arg2; \
249 #define LOAD_ARGS_3(a1, a2, a3) \
250 long _arg3 = (long) (a3); \
252 #define LOAD_REGS_3 \
253 register long _out2 asm ("out2") = _arg3; \
255 #define LOAD_ARGS_4(a1, a2, a3, a4) \
256 long _arg4 = (long) (a4); \
257 LOAD_ARGS_3 (a1, a2, a3)
258 #define LOAD_REGS_4 \
259 register long _out3 asm ("out3") = _arg4; \
261 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
262 long _arg5 = (long) (a5); \
263 LOAD_ARGS_4 (a1, a2, a3, a4)
264 #define LOAD_REGS_5 \
265 register long _out4 asm ("out4") = _arg5; \
267 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
268 long _arg6 = (long) (a6); \
269 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
270 #define LOAD_REGS_6 \
271 register long _out5 asm ("out5") = _arg6; \
274 #define ASM_OUTARGS_0
275 #define ASM_OUTARGS_1 ASM_OUTARGS_0, "=r" (_out0)
276 #define ASM_OUTARGS_2 ASM_OUTARGS_1, "=r" (_out1)
277 #define ASM_OUTARGS_3 ASM_OUTARGS_2, "=r" (_out2)
278 #define ASM_OUTARGS_4 ASM_OUTARGS_3, "=r" (_out3)
279 #define ASM_OUTARGS_5 ASM_OUTARGS_4, "=r" (_out4)
280 #define ASM_OUTARGS_6 ASM_OUTARGS_5, "=r" (_out5)
282 #ifdef IA64_USE_NEW_STUB
284 #define ASM_ARGS_1 ASM_ARGS_0, "4" (_out0)
285 #define ASM_ARGS_2 ASM_ARGS_1, "5" (_out1)
286 #define ASM_ARGS_3 ASM_ARGS_2, "6" (_out2)
287 #define ASM_ARGS_4 ASM_ARGS_3, "7" (_out3)
288 #define ASM_ARGS_5 ASM_ARGS_4, "8" (_out4)
289 #define ASM_ARGS_6 ASM_ARGS_5, "9" (_out5)
292 #define ASM_ARGS_1 ASM_ARGS_0, "3" (_out0)
293 #define ASM_ARGS_2 ASM_ARGS_1, "4" (_out1)
294 #define ASM_ARGS_3 ASM_ARGS_2, "5" (_out2)
295 #define ASM_ARGS_4 ASM_ARGS_3, "6" (_out3)
296 #define ASM_ARGS_5 ASM_ARGS_4, "7" (_out4)
297 #define ASM_ARGS_6 ASM_ARGS_5, "8" (_out5)
300 #define ASM_CLOBBERS_0 ASM_CLOBBERS_1, "out0"
301 #define ASM_CLOBBERS_1 ASM_CLOBBERS_2, "out1"
302 #define ASM_CLOBBERS_2 ASM_CLOBBERS_3, "out2"
303 #define ASM_CLOBBERS_3 ASM_CLOBBERS_4, "out3"
304 #define ASM_CLOBBERS_4 ASM_CLOBBERS_5, "out4"
305 #define ASM_CLOBBERS_5 ASM_CLOBBERS_6, "out5"
306 #define ASM_CLOBBERS_6_COMMON , "out6", "out7", \
307 /* Non-stacked integer registers, minus r8, r10, r15. */ \
308 "r2", "r3", "r9", "r11", "r13", "r14", "r16", "r17", "r18", \
309 "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", \
310 "r28", "r29", "r30", "r31", \
311 /* Predicate registers. */ \
312 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
313 /* Non-rotating fp registers. */ \
314 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
315 /* Branch registers. */ \
318 #ifdef IA64_USE_NEW_STUB
319 # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON
321 # define ASM_CLOBBERS_6 ASM_CLOBBERS_6_COMMON , "b7"
324 #endif /* not __ASSEMBLER__ */
326 /* Pointer mangling support. */
328 /* We cannot use the thread descriptor because in ld.so we use setjmp
329 earlier than the descriptor is initialized. */
331 # ifdef __ASSEMBLER__
332 # define PTR_MANGLE(reg, tmpreg) \
335 ld8 tmpreg=[tmpreg] \
338 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
340 # define PTR_MANGLE(var) \
341 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
342 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
346 #endif /* linux/ia64/sysdep.h */