]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/sysdep.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / sysdep.h
1 /* Copyright (C) 1992-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.org>, August 1995.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _LINUX_I386_SYSDEP_H
20 #define _LINUX_I386_SYSDEP_H 1
21
22 /* There is some commonality. */
23 #include <sysdeps/unix/sysv/linux/sysdep.h>
24 #include <sysdeps/unix/i386/sysdep.h>
25 /* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
26 #include <dl-sysdep.h>
27 #include <tls.h>
28
29
30 /* For Linux we can use the system call table in the header file
31 /usr/include/asm/unistd.h
32 of the kernel. But these symbols do not follow the SYS_* syntax
33 so we have to redefine the `SYS_ify' macro here. */
34 #undef SYS_ify
35 #define SYS_ify(syscall_name) __NR_##syscall_name
36
37 #ifndef I386_USE_SYSENTER
38 # if defined USE_DL_SYSINFO \
39 && (IS_IN (libc) || IS_IN (libpthread))
40 # define I386_USE_SYSENTER 1
41 # else
42 # define I386_USE_SYSENTER 0
43 # endif
44 #endif
45
46 /* Since GCC 5 and above can properly spill %ebx with PIC when needed,
47 we can inline syscalls with 6 arguments if GCC 5 or above is used
48 to compile glibc. Disable GCC 5 optimization when compiling for
49 profiling or when -fno-omit-frame-pointer is used since asm ("ebp")
50 can't be used to put the 6th argument in %ebp for syscall. */
51 #if __GNUC_PREREQ (5,0) && !defined PROF && CAN_USE_REGISTER_ASM_EBP
52 # define OPTIMIZE_FOR_GCC_5
53 #endif
54
55 #ifdef __ASSEMBLER__
56
57 /* Linux uses a negative return value to indicate syscall errors,
58 unlike most Unices, which use the condition codes' carry flag.
59
60 Since version 2.1 the return value of a system call might be
61 negative even if the call succeeded. E.g., the `lseek' system call
62 might return a large offset. Therefore we must not anymore test
63 for < 0, but test for a real error by making sure the value in %eax
64 is a real error number. Linus said he will make sure the no syscall
65 returns a value in -1 .. -4095 as a valid result so we can savely
66 test with -4095. */
67
68 /* We don't want the label for the error handle to be global when we define
69 it here. */
70 #define SYSCALL_ERROR_LABEL __syscall_error
71
72 #undef PSEUDO
73 #define PSEUDO(name, syscall_name, args) \
74 .text; \
75 ENTRY (name) \
76 DO_CALL (syscall_name, args); \
77 cmpl $-4095, %eax; \
78 jae SYSCALL_ERROR_LABEL
79
80 #undef PSEUDO_END
81 #define PSEUDO_END(name) \
82 SYSCALL_ERROR_HANDLER \
83 END (name)
84
85 #undef PSEUDO_NOERRNO
86 #define PSEUDO_NOERRNO(name, syscall_name, args) \
87 .text; \
88 ENTRY (name) \
89 DO_CALL (syscall_name, args)
90
91 #undef PSEUDO_END_NOERRNO
92 #define PSEUDO_END_NOERRNO(name) \
93 END (name)
94
95 #define ret_NOERRNO ret
96
97 /* The function has to return the error code. */
98 #undef PSEUDO_ERRVAL
99 #define PSEUDO_ERRVAL(name, syscall_name, args) \
100 .text; \
101 ENTRY (name) \
102 DO_CALL (syscall_name, args); \
103 negl %eax
104
105 #undef PSEUDO_END_ERRVAL
106 #define PSEUDO_END_ERRVAL(name) \
107 END (name)
108
109 #define ret_ERRVAL ret
110
111 #define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.c is used. */
112
113 /* The original calling convention for system calls on Linux/i386 is
114 to use int $0x80. */
115 #if I386_USE_SYSENTER
116 # ifdef PIC
117 # define ENTER_KERNEL call *%gs:SYSINFO_OFFSET
118 # else
119 # define ENTER_KERNEL call *_dl_sysinfo
120 # endif
121 #else
122 # define ENTER_KERNEL int $0x80
123 #endif
124
125 /* Linux takes system call arguments in registers:
126
127 syscall number %eax call-clobbered
128 arg 1 %ebx call-saved
129 arg 2 %ecx call-clobbered
130 arg 3 %edx call-clobbered
131 arg 4 %esi call-saved
132 arg 5 %edi call-saved
133 arg 6 %ebp call-saved
134
135 The stack layout upon entering the function is:
136
137 24(%esp) Arg# 6
138 20(%esp) Arg# 5
139 16(%esp) Arg# 4
140 12(%esp) Arg# 3
141 8(%esp) Arg# 2
142 4(%esp) Arg# 1
143 (%esp) Return address
144
145 (Of course a function with say 3 arguments does not have entries for
146 arguments 4, 5, and 6.)
147
148 The following code tries hard to be optimal. A general assumption
149 (which is true according to the data books I have) is that
150
151 2 * xchg is more expensive than pushl + movl + popl
152
153 Beside this a neat trick is used. The calling conventions for Linux
154 tell that among the registers used for parameters %ecx and %edx need
155 not be saved. Beside this we may clobber this registers even when
156 they are not used for parameter passing.
157
158 As a result one can see below that we save the content of the %ebx
159 register in the %edx register when we have less than 3 arguments
160 (2 * movl is less expensive than pushl + popl).
161
162 Second unlike for the other registers we don't save the content of
163 %ecx and %edx when we have more than 1 and 2 registers resp.
164
165 The code below might look a bit long but we have to take care for
166 the pipelined processors (i586). Here the `pushl' and `popl'
167 instructions are marked as NP (not pairable) but the exception is
168 two consecutive of these instruction. This gives no penalty on
169 other processors though. */
170
171 #undef DO_CALL
172 #define DO_CALL(syscall_name, args) \
173 PUSHARGS_##args \
174 DOARGS_##args \
175 movl $SYS_ify (syscall_name), %eax; \
176 ENTER_KERNEL \
177 POPARGS_##args
178
179 #define PUSHARGS_0 /* No arguments to push. */
180 #define DOARGS_0 /* No arguments to frob. */
181 #define POPARGS_0 /* No arguments to pop. */
182 #define _PUSHARGS_0 /* No arguments to push. */
183 #define _DOARGS_0(n) /* No arguments to frob. */
184 #define _POPARGS_0 /* No arguments to pop. */
185
186 #define PUSHARGS_1 movl %ebx, %edx; L(SAVEBX1): PUSHARGS_0
187 #define DOARGS_1 _DOARGS_1 (4)
188 #define POPARGS_1 POPARGS_0; movl %edx, %ebx; L(RESTBX1):
189 #define _PUSHARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
190 cfi_rel_offset (ebx, 0); L(PUSHBX1): _PUSHARGS_0
191 #define _DOARGS_1(n) movl n(%esp), %ebx; _DOARGS_0(n-4)
192 #define _POPARGS_1 _POPARGS_0; popl %ebx; cfi_adjust_cfa_offset (-4); \
193 cfi_restore (ebx); L(POPBX1):
194
195 #define PUSHARGS_2 PUSHARGS_1
196 #define DOARGS_2 _DOARGS_2 (8)
197 #define POPARGS_2 POPARGS_1
198 #define _PUSHARGS_2 _PUSHARGS_1
199 #define _DOARGS_2(n) movl n(%esp), %ecx; _DOARGS_1 (n-4)
200 #define _POPARGS_2 _POPARGS_1
201
202 #define PUSHARGS_3 _PUSHARGS_2
203 #define DOARGS_3 _DOARGS_3 (16)
204 #define POPARGS_3 _POPARGS_3
205 #define _PUSHARGS_3 _PUSHARGS_2
206 #define _DOARGS_3(n) movl n(%esp), %edx; _DOARGS_2 (n-4)
207 #define _POPARGS_3 _POPARGS_2
208
209 #define PUSHARGS_4 _PUSHARGS_4
210 #define DOARGS_4 _DOARGS_4 (24)
211 #define POPARGS_4 _POPARGS_4
212 #define _PUSHARGS_4 pushl %esi; cfi_adjust_cfa_offset (4); \
213 cfi_rel_offset (esi, 0); L(PUSHSI1): _PUSHARGS_3
214 #define _DOARGS_4(n) movl n(%esp), %esi; _DOARGS_3 (n-4)
215 #define _POPARGS_4 _POPARGS_3; popl %esi; cfi_adjust_cfa_offset (-4); \
216 cfi_restore (esi); L(POPSI1):
217
218 #define PUSHARGS_5 _PUSHARGS_5
219 #define DOARGS_5 _DOARGS_5 (32)
220 #define POPARGS_5 _POPARGS_5
221 #define _PUSHARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
222 cfi_rel_offset (edi, 0); L(PUSHDI1): _PUSHARGS_4
223 #define _DOARGS_5(n) movl n(%esp), %edi; _DOARGS_4 (n-4)
224 #define _POPARGS_5 _POPARGS_4; popl %edi; cfi_adjust_cfa_offset (-4); \
225 cfi_restore (edi); L(POPDI1):
226
227 #define PUSHARGS_6 _PUSHARGS_6
228 #define DOARGS_6 _DOARGS_6 (40)
229 #define POPARGS_6 _POPARGS_6
230 #define _PUSHARGS_6 pushl %ebp; cfi_adjust_cfa_offset (4); \
231 cfi_rel_offset (ebp, 0); L(PUSHBP1): _PUSHARGS_5
232 #define _DOARGS_6(n) movl n(%esp), %ebp; _DOARGS_5 (n-4)
233 #define _POPARGS_6 _POPARGS_5; popl %ebp; cfi_adjust_cfa_offset (-4); \
234 cfi_restore (ebp); L(POPBP1):
235
236 #else /* !__ASSEMBLER__ */
237
238 extern int __syscall_error (int)
239 attribute_hidden __attribute__ ((__regparm__ (1)));
240
241 #ifndef OPTIMIZE_FOR_GCC_5
242 /* We need some help from the assembler to generate optimal code. We
243 define some macros here which later will be used. */
244 asm (".L__X'%ebx = 1\n\t"
245 ".L__X'%ecx = 2\n\t"
246 ".L__X'%edx = 2\n\t"
247 ".L__X'%eax = 3\n\t"
248 ".L__X'%esi = 3\n\t"
249 ".L__X'%edi = 3\n\t"
250 ".L__X'%ebp = 3\n\t"
251 ".L__X'%esp = 3\n\t"
252 ".macro bpushl name reg\n\t"
253 ".if 1 - \\name\n\t"
254 ".if 2 - \\name\n\t"
255 "error\n\t"
256 ".else\n\t"
257 "xchgl \\reg, %ebx\n\t"
258 ".endif\n\t"
259 ".endif\n\t"
260 ".endm\n\t"
261 ".macro bpopl name reg\n\t"
262 ".if 1 - \\name\n\t"
263 ".if 2 - \\name\n\t"
264 "error\n\t"
265 ".else\n\t"
266 "xchgl \\reg, %ebx\n\t"
267 ".endif\n\t"
268 ".endif\n\t"
269 ".endm\n\t");
270
271 /* Six-argument syscalls use an out-of-line helper, because an inline
272 asm using all registers apart from %esp cannot work reliably and
273 the assembler does not support describing an asm that saves and
274 restores %ebp itself as a separate stack frame. This structure
275 stores the arguments not passed in registers; %edi is passed with a
276 pointer to this structure. */
277 struct libc_do_syscall_args
278 {
279 int ebx, edi, ebp;
280 };
281 #endif
282
283 /* Define a macro which expands inline into the wrapper code for a system
284 call. */
285 #undef INLINE_SYSCALL
286 #if IS_IN (libc)
287 # define INLINE_SYSCALL(name, nr, args...) \
288 ({ \
289 unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
290 __glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, )) \
291 ? __syscall_error (-INTERNAL_SYSCALL_ERRNO (resultvar, )) \
292 : (int) resultvar; })
293 #else
294 # define INLINE_SYSCALL(name, nr, args...) \
295 ({ \
296 unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
297 if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
298 { \
299 __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
300 resultvar = 0xffffffff; \
301 } \
302 (int) resultvar; })
303 #endif
304
305 /* Set error number and return -1. Return the internal function,
306 __syscall_error, which sets errno from the negative error number
307 and returns -1, to avoid PIC. */
308 #undef INLINE_SYSCALL_ERROR_RETURN_VALUE
309 #define INLINE_SYSCALL_ERROR_RETURN_VALUE(resultvar) \
310 __syscall_error (-(resultvar))
311
312 /* List of system calls which are supported as vsyscalls. */
313 # define HAVE_CLOCK_GETTIME_VSYSCALL 1
314 # define HAVE_GETTIMEOFDAY_VSYSCALL 1
315
316 /* Define a macro which expands inline into the wrapper code for a system
317 call. This use is for internal calls that do not need to handle errors
318 normally. It will never touch errno. This returns just what the kernel
319 gave back.
320
321 The _NCS variant allows non-constant syscall numbers but it is not
322 possible to use more than four parameters. */
323 #undef INTERNAL_SYSCALL
324 #define INTERNAL_SYSCALL_MAIN_0(name, err, args...) \
325 INTERNAL_SYSCALL_MAIN_INLINE(name, err, 0, args)
326 #define INTERNAL_SYSCALL_MAIN_1(name, err, args...) \
327 INTERNAL_SYSCALL_MAIN_INLINE(name, err, 1, args)
328 #define INTERNAL_SYSCALL_MAIN_2(name, err, args...) \
329 INTERNAL_SYSCALL_MAIN_INLINE(name, err, 2, args)
330 #define INTERNAL_SYSCALL_MAIN_3(name, err, args...) \
331 INTERNAL_SYSCALL_MAIN_INLINE(name, err, 3, args)
332 #define INTERNAL_SYSCALL_MAIN_4(name, err, args...) \
333 INTERNAL_SYSCALL_MAIN_INLINE(name, err, 4, args)
334 #define INTERNAL_SYSCALL_MAIN_5(name, err, args...) \
335 INTERNAL_SYSCALL_MAIN_INLINE(name, err, 5, args)
336 /* Each object using 6-argument inline syscalls must include a
337 definition of __libc_do_syscall. */
338 #ifdef OPTIMIZE_FOR_GCC_5
339 # define INTERNAL_SYSCALL_MAIN_6(name, err, args...) \
340 INTERNAL_SYSCALL_MAIN_INLINE(name, err, 6, args)
341 #else /* GCC 5 */
342 # define INTERNAL_SYSCALL_MAIN_6(name, err, arg1, arg2, arg3, \
343 arg4, arg5, arg6) \
344 struct libc_do_syscall_args _xv = \
345 { \
346 (int) (arg1), \
347 (int) (arg5), \
348 (int) (arg6) \
349 }; \
350 asm volatile ( \
351 "movl %1, %%eax\n\t" \
352 "call __libc_do_syscall" \
353 : "=a" (resultvar) \
354 : "i" (__NR_##name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv) \
355 : "memory", "cc")
356 #endif /* GCC 5 */
357 #define INTERNAL_SYSCALL(name, err, nr, args...) \
358 ({ \
359 register unsigned int resultvar; \
360 INTERNAL_SYSCALL_MAIN_##nr (name, err, args); \
361 (int) resultvar; })
362 #if I386_USE_SYSENTER
363 # ifdef OPTIMIZE_FOR_GCC_5
364 # ifdef PIC
365 # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
366 LOADREGS_##nr(args) \
367 asm volatile ( \
368 "call *%%gs:%P2" \
369 : "=a" (resultvar) \
370 : "a" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \
371 ASMARGS_##nr(args) : "memory", "cc")
372 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
373 ({ \
374 register unsigned int resultvar; \
375 LOADREGS_##nr(args) \
376 asm volatile ( \
377 "call *%%gs:%P2" \
378 : "=a" (resultvar) \
379 : "a" (name), "i" (offsetof (tcbhead_t, sysinfo)) \
380 ASMARGS_##nr(args) : "memory", "cc"); \
381 (int) resultvar; })
382 # else
383 # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
384 LOADREGS_##nr(args) \
385 asm volatile ( \
386 "call *_dl_sysinfo" \
387 : "=a" (resultvar) \
388 : "a" (__NR_##name) ASMARGS_##nr(args) : "memory", "cc")
389 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
390 ({ \
391 register unsigned int resultvar; \
392 LOADREGS_##nr(args) \
393 asm volatile ( \
394 "call *_dl_sysinfo" \
395 : "=a" (resultvar) \
396 : "a" (name) ASMARGS_##nr(args) : "memory", "cc"); \
397 (int) resultvar; })
398 # endif
399 # else /* GCC 5 */
400 # ifdef PIC
401 # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
402 EXTRAVAR_##nr \
403 asm volatile ( \
404 LOADARGS_##nr \
405 "movl %1, %%eax\n\t" \
406 "call *%%gs:%P2\n\t" \
407 RESTOREARGS_##nr \
408 : "=a" (resultvar) \
409 : "i" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \
410 ASMFMT_##nr(args) : "memory", "cc")
411 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
412 ({ \
413 register unsigned int resultvar; \
414 EXTRAVAR_##nr \
415 asm volatile ( \
416 LOADARGS_##nr \
417 "call *%%gs:%P2\n\t" \
418 RESTOREARGS_##nr \
419 : "=a" (resultvar) \
420 : "0" (name), "i" (offsetof (tcbhead_t, sysinfo)) \
421 ASMFMT_##nr(args) : "memory", "cc"); \
422 (int) resultvar; })
423 # else
424 # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
425 EXTRAVAR_##nr \
426 asm volatile ( \
427 LOADARGS_##nr \
428 "movl %1, %%eax\n\t" \
429 "call *_dl_sysinfo\n\t" \
430 RESTOREARGS_##nr \
431 : "=a" (resultvar) \
432 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc")
433 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
434 ({ \
435 register unsigned int resultvar; \
436 EXTRAVAR_##nr \
437 asm volatile ( \
438 LOADARGS_##nr \
439 "call *_dl_sysinfo\n\t" \
440 RESTOREARGS_##nr \
441 : "=a" (resultvar) \
442 : "0" (name) ASMFMT_##nr(args) : "memory", "cc"); \
443 (int) resultvar; })
444 # endif
445 # endif /* GCC 5 */
446 #else
447 # ifdef OPTIMIZE_FOR_GCC_5
448 # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
449 LOADREGS_##nr(args) \
450 asm volatile ( \
451 "int $0x80" \
452 : "=a" (resultvar) \
453 : "a" (__NR_##name) ASMARGS_##nr(args) : "memory", "cc")
454 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
455 ({ \
456 register unsigned int resultvar; \
457 LOADREGS_##nr(args) \
458 asm volatile ( \
459 "int $0x80" \
460 : "=a" (resultvar) \
461 : "a" (name) ASMARGS_##nr(args) : "memory", "cc"); \
462 (int) resultvar; })
463 # else /* GCC 5 */
464 # define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
465 EXTRAVAR_##nr \
466 asm volatile ( \
467 LOADARGS_##nr \
468 "movl %1, %%eax\n\t" \
469 "int $0x80\n\t" \
470 RESTOREARGS_##nr \
471 : "=a" (resultvar) \
472 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc")
473 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
474 ({ \
475 register unsigned int resultvar; \
476 EXTRAVAR_##nr \
477 asm volatile ( \
478 LOADARGS_##nr \
479 "int $0x80\n\t" \
480 RESTOREARGS_##nr \
481 : "=a" (resultvar) \
482 : "0" (name) ASMFMT_##nr(args) : "memory", "cc"); \
483 (int) resultvar; })
484 # endif /* GCC 5 */
485 #endif
486
487 #undef INTERNAL_SYSCALL_DECL
488 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
489
490 #undef INTERNAL_SYSCALL_ERROR_P
491 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
492 ((unsigned int) (val) >= 0xfffff001u)
493
494 #undef INTERNAL_SYSCALL_ERRNO
495 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
496
497 #define LOADARGS_0
498 #ifdef __PIC__
499 # if I386_USE_SYSENTER && defined PIC
500 # define LOADARGS_1 \
501 "bpushl .L__X'%k3, %k3\n\t"
502 # define LOADARGS_5 \
503 "movl %%ebx, %4\n\t" \
504 "movl %3, %%ebx\n\t"
505 # else
506 # define LOADARGS_1 \
507 "bpushl .L__X'%k2, %k2\n\t"
508 # define LOADARGS_5 \
509 "movl %%ebx, %3\n\t" \
510 "movl %2, %%ebx\n\t"
511 # endif
512 # define LOADARGS_2 LOADARGS_1
513 # define LOADARGS_3 \
514 "xchgl %%ebx, %%edi\n\t"
515 # define LOADARGS_4 LOADARGS_3
516 #else
517 # define LOADARGS_1
518 # define LOADARGS_2
519 # define LOADARGS_3
520 # define LOADARGS_4
521 # define LOADARGS_5
522 #endif
523
524 #define RESTOREARGS_0
525 #ifdef __PIC__
526 # if I386_USE_SYSENTER && defined PIC
527 # define RESTOREARGS_1 \
528 "bpopl .L__X'%k3, %k3\n\t"
529 # define RESTOREARGS_5 \
530 "movl %4, %%ebx"
531 # else
532 # define RESTOREARGS_1 \
533 "bpopl .L__X'%k2, %k2\n\t"
534 # define RESTOREARGS_5 \
535 "movl %3, %%ebx"
536 # endif
537 # define RESTOREARGS_2 RESTOREARGS_1
538 # define RESTOREARGS_3 \
539 "xchgl %%edi, %%ebx\n\t"
540 # define RESTOREARGS_4 RESTOREARGS_3
541 #else
542 # define RESTOREARGS_1
543 # define RESTOREARGS_2
544 # define RESTOREARGS_3
545 # define RESTOREARGS_4
546 # define RESTOREARGS_5
547 #endif
548
549 #ifdef OPTIMIZE_FOR_GCC_5
550 # define LOADREGS_0()
551 # define ASMARGS_0()
552 # define LOADREGS_1(arg1) \
553 LOADREGS_0 ()
554 # define ASMARGS_1(arg1) \
555 ASMARGS_0 (), "b" ((unsigned int) (arg1))
556 # define LOADREGS_2(arg1, arg2) \
557 LOADREGS_1 (arg1)
558 # define ASMARGS_2(arg1, arg2) \
559 ASMARGS_1 (arg1), "c" ((unsigned int) (arg2))
560 # define LOADREGS_3(arg1, arg2, arg3) \
561 LOADREGS_2 (arg1, arg2)
562 # define ASMARGS_3(arg1, arg2, arg3) \
563 ASMARGS_2 (arg1, arg2), "d" ((unsigned int) (arg3))
564 # define LOADREGS_4(arg1, arg2, arg3, arg4) \
565 LOADREGS_3 (arg1, arg2, arg3)
566 # define ASMARGS_4(arg1, arg2, arg3, arg4) \
567 ASMARGS_3 (arg1, arg2, arg3), "S" ((unsigned int) (arg4))
568 # define LOADREGS_5(arg1, arg2, arg3, arg4, arg5) \
569 LOADREGS_4 (arg1, arg2, arg3, arg4)
570 # define ASMARGS_5(arg1, arg2, arg3, arg4, arg5) \
571 ASMARGS_4 (arg1, arg2, arg3, arg4), "D" ((unsigned int) (arg5))
572 # define LOADREGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
573 register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6); \
574 LOADREGS_5 (arg1, arg2, arg3, arg4, arg5)
575 # define ASMARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
576 ASMARGS_5 (arg1, arg2, arg3, arg4, arg5), "r" (_a6)
577 #endif /* GCC 5 */
578
579 #define ASMFMT_0()
580 #ifdef __PIC__
581 # define ASMFMT_1(arg1) \
582 , "cd" (arg1)
583 # define ASMFMT_2(arg1, arg2) \
584 , "d" (arg1), "c" (arg2)
585 # define ASMFMT_3(arg1, arg2, arg3) \
586 , "D" (arg1), "c" (arg2), "d" (arg3)
587 # define ASMFMT_4(arg1, arg2, arg3, arg4) \
588 , "D" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
589 # define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
590 , "0" (arg1), "m" (_xv), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
591 #else
592 # define ASMFMT_1(arg1) \
593 , "b" (arg1)
594 # define ASMFMT_2(arg1, arg2) \
595 , "b" (arg1), "c" (arg2)
596 # define ASMFMT_3(arg1, arg2, arg3) \
597 , "b" (arg1), "c" (arg2), "d" (arg3)
598 # define ASMFMT_4(arg1, arg2, arg3, arg4) \
599 , "b" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
600 # define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
601 , "b" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
602 #endif
603
604 #define EXTRAVAR_0
605 #define EXTRAVAR_1
606 #define EXTRAVAR_2
607 #define EXTRAVAR_3
608 #define EXTRAVAR_4
609 #ifdef __PIC__
610 # define EXTRAVAR_5 int _xv;
611 #else
612 # define EXTRAVAR_5
613 #endif
614
615 /* Consistency check for position-independent code. */
616 #if defined __PIC__ && !defined OPTIMIZE_FOR_GCC_5
617 # define check_consistency() \
618 ({ int __res; \
619 __asm__ __volatile__ \
620 (LOAD_PIC_REG_STR (cx) ";" \
621 "subl %%ebx, %%ecx;" \
622 "je 1f;" \
623 "ud2;" \
624 "1:\n" \
625 : "=c" (__res)); \
626 __res; })
627 #endif
628
629 #endif /* __ASSEMBLER__ */
630
631
632 /* Pointer mangling support. */
633 #if IS_IN (rtld)
634 /* We cannot use the thread descriptor because in ld.so we use setjmp
635 earlier than the descriptor is initialized. Using a global variable
636 is too complicated here since we have no PC-relative addressing mode. */
637 #else
638 # ifdef __ASSEMBLER__
639 # define PTR_MANGLE(reg) xorl %gs:POINTER_GUARD, reg; \
640 roll $9, reg
641 # define PTR_DEMANGLE(reg) rorl $9, reg; \
642 xorl %gs:POINTER_GUARD, reg
643 # else
644 # define PTR_MANGLE(var) asm ("xorl %%gs:%c2, %0\n" \
645 "roll $9, %0" \
646 : "=r" (var) \
647 : "0" (var), \
648 "i" (offsetof (tcbhead_t, \
649 pointer_guard)))
650 # define PTR_DEMANGLE(var) asm ("rorl $9, %0\n" \
651 "xorl %%gs:%c2, %0" \
652 : "=r" (var) \
653 : "0" (var), \
654 "i" (offsetof (tcbhead_t, \
655 pointer_guard)))
656 # endif
657 #endif
658
659 #endif /* linux/i386/sysdep.h */