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