]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/i386/sysdep.h
Use glibc_likely instead __builtin_expect.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / sysdep.h
CommitLineData
d4697bc9 1/* Copyright (C) 1992-2014 Free Software Foundation, Inc.
bfbc5754 2 This file is part of the GNU C Library.
44129238 3 Contributed by Ulrich Drepper, <drepper@gnu.org>, August 1995.
bfbc5754
UD
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
bfbc5754
UD
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
41bdb6e2 13 Lesser General Public License for more details.
bfbc5754 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
d2f5be2a 18
ec4b0518
UD
19#ifndef _LINUX_I386_SYSDEP_H
20#define _LINUX_I386_SYSDEP_H 1
21
d2f5be2a
UD
22/* There is some commonality. */
23#include <sysdeps/unix/i386/sysdep.h>
131fd126 24/* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
5f5843e3 25#include <dl-sysdep.h>
739d440d 26#include <tls.h>
d2f5be2a 27
ce460d04 28
d2f5be2a
UD
29/* For Linux we can use the system call table in the header file
30 /usr/include/asm/unistd.h
31 of the kernel. But these symbols do not follow the SYS_* syntax
32 so we have to redefine the `SYS_ify' macro here. */
33#undef SYS_ify
6ed0492f 34#define SYS_ify(syscall_name) __NR_##syscall_name
d2f5be2a 35
131fd126
UD
36#if defined USE_DL_SYSINFO \
37 && (!defined NOT_IN_libc || defined IS_IN_libpthread)
5f5843e3
UD
38# define I386_USE_SYSENTER 1
39#else
40# undef I386_USE_SYSENTER
41#endif
42
c2afe833
RM
43#ifdef __ASSEMBLER__
44
cccda09f
UD
45/* Linux uses a negative return value to indicate syscall errors,
46 unlike most Unices, which use the condition codes' carry flag.
47
48 Since version 2.1 the return value of a system call might be
49 negative even if the call succeeded. E.g., the `lseek' system call
50 might return a large offset. Therefore we must not anymore test
51 for < 0, but test for a real error by making sure the value in %eax
b5791037
UD
52 is a real error number. Linus said he will make sure the no syscall
53 returns a value in -1 .. -4095 as a valid result so we can savely
54 test with -4095. */
c0fb8a56
UD
55
56/* We don't want the label for the error handle to be global when we define
57 it here. */
58#ifdef PIC
59# define SYSCALL_ERROR_LABEL 0f
60#else
61# define SYSCALL_ERROR_LABEL syscall_error
62#endif
63
d2f5be2a
UD
64#undef PSEUDO
65#define PSEUDO(name, syscall_name, args) \
66 .text; \
d2f5be2a 67 ENTRY (name) \
ffa8d2a0 68 DO_CALL (syscall_name, args); \
b5791037 69 cmpl $-4095, %eax; \
842a39cd 70 jae SYSCALL_ERROR_LABEL
d2f5be2a 71
6ed0492f
UD
72#undef PSEUDO_END
73#define PSEUDO_END(name) \
74 SYSCALL_ERROR_HANDLER \
75 END (name)
76
9eb88290
UD
77#undef PSEUDO_NOERRNO
78#define PSEUDO_NOERRNO(name, syscall_name, args) \
79 .text; \
80 ENTRY (name) \
81 DO_CALL (syscall_name, args)
82
83#undef PSEUDO_END_NOERRNO
84#define PSEUDO_END_NOERRNO(name) \
85 END (name)
86
87#define ret_NOERRNO ret
88
bfef9264
UD
89/* The function has to return the error code. */
90#undef PSEUDO_ERRVAL
91#define PSEUDO_ERRVAL(name, syscall_name, args) \
92 .text; \
93 ENTRY (name) \
94 DO_CALL (syscall_name, args); \
95 negl %eax
96
97#undef PSEUDO_END_ERRVAL
98#define PSEUDO_END_ERRVAL(name) \
99 END (name)
100
101#define ret_ERRVAL ret
102
edf5b2d7 103#ifndef PIC
739d440d 104# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
03a75825 105#else
9bd64602 106
ce460d04
RM
107# if RTLD_PRIVATE_ERRNO
108# define SYSCALL_ERROR_HANDLER \
1090:SETUP_PIC_REG(cx); \
110 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
f63d5db6
L
111 negl %eax; \
112 movl %eax, rtld_errno@GOTOFF(%ecx); \
ce460d04 113 orl $-1, %eax; \
5e292e4f 114 ret;
739d440d 115
ce460d04
RM
116# elif defined _LIBC_REENTRANT
117
d063d164
UD
118# ifndef NOT_IN_libc
119# define SYSCALL_ERROR_ERRNO __libc_errno
120# else
121# define SYSCALL_ERROR_ERRNO errno
122# endif
123# define SYSCALL_ERROR_HANDLER \
739d440d
UD
1240:SETUP_PIC_REG (cx); \
125 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
ac2dc598 126 movl SYSCALL_ERROR_ERRNO@GOTNTPOFF(%ecx), %ecx; \
f63d5db6
L
127 negl %eax; \
128 SYSCALL_ERROR_HANDLER_TLS_STORE (%eax, %ecx); \
739d440d 129 orl $-1, %eax; \
5e292e4f 130 ret;
d063d164
UD
131# ifndef NO_TLS_DIRECT_SEG_REFS
132# define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff) \
24992143 133 movl src, %gs:(destoff)
d063d164
UD
134# else
135# define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff) \
70a8119b
RM
136 addl %gs:0, destoff; \
137 movl src, (destoff)
739d440d 138# endif
9bd64602 139# else
ce460d04 140/* Store (- %eax) into errno through the GOT. */
739d440d 141# define SYSCALL_ERROR_HANDLER \
09d65ff3 1420:SETUP_PIC_REG(cx); \
b44e3016 143 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
f63d5db6 144 negl %eax; \
03a75825 145 movl errno@GOT(%ecx), %ecx; \
f63d5db6 146 movl %eax, (%ecx); \
b259e746 147 orl $-1, %eax; \
5e292e4f 148 ret;
739d440d 149# endif /* _LIBC_REENTRANT */
edf5b2d7 150#endif /* PIC */
03a75825 151
f051627f
UD
152
153/* The original calling convention for system calls on Linux/i386 is
154 to use int $0x80. */
5f5843e3
UD
155#ifdef I386_USE_SYSENTER
156# ifdef SHARED
157# define ENTER_KERNEL call *%gs:SYSINFO_OFFSET
158# else
159# define ENTER_KERNEL call *_dl_sysinfo
160# endif
161#else
162# define ENTER_KERNEL int $0x80
163#endif
f051627f 164
d2f5be2a
UD
165/* Linux takes system call arguments in registers:
166
167 syscall number %eax call-clobbered
168 arg 1 %ebx call-saved
169 arg 2 %ecx call-clobbered
170 arg 3 %edx call-clobbered
171 arg 4 %esi call-saved
172 arg 5 %edi call-saved
b2bcd249 173 arg 6 %ebp call-saved
d2f5be2a
UD
174
175 The stack layout upon entering the function is:
176
b2bcd249 177 24(%esp) Arg# 6
d2f5be2a
UD
178 20(%esp) Arg# 5
179 16(%esp) Arg# 4
180 12(%esp) Arg# 3
181 8(%esp) Arg# 2
182 4(%esp) Arg# 1
183 (%esp) Return address
184
185 (Of course a function with say 3 arguments does not have entries for
b2bcd249 186 arguments 4, 5, and 6.)
d2f5be2a 187
6ed0492f 188 The following code tries hard to be optimal. A general assumption
03a75825 189 (which is true according to the data books I have) is that
d2f5be2a
UD
190
191 2 * xchg is more expensive than pushl + movl + popl
192
193 Beside this a neat trick is used. The calling conventions for Linux
194 tell that among the registers used for parameters %ecx and %edx need
195 not be saved. Beside this we may clobber this registers even when
196 they are not used for parameter passing.
197
198 As a result one can see below that we save the content of the %ebx
199 register in the %edx register when we have less than 3 arguments
200 (2 * movl is less expensive than pushl + popl).
201
202 Second unlike for the other registers we don't save the content of
6ed0492f 203 %ecx and %edx when we have more than 1 and 2 registers resp.
8f5ca04b
RM
204
205 The code below might look a bit long but we have to take care for
63bda0c1 206 the pipelined processors (i586). Here the `pushl' and `popl'
8f5ca04b
RM
207 instructions are marked as NP (not pairable) but the exception is
208 two consecutive of these instruction. This gives no penalty on
63bda0c1 209 other processors though. */
d2f5be2a
UD
210
211#undef DO_CALL
ffa8d2a0 212#define DO_CALL(syscall_name, args) \
8f5ca04b 213 PUSHARGS_##args \
d2f5be2a 214 DOARGS_##args \
c14e4c32 215 movl $SYS_ify (syscall_name), %eax; \
f051627f 216 ENTER_KERNEL \
8f5ca04b 217 POPARGS_##args
d2f5be2a 218
8f5ca04b 219#define PUSHARGS_0 /* No arguments to push. */
d2f5be2a 220#define DOARGS_0 /* No arguments to frob. */
8f5ca04b
RM
221#define POPARGS_0 /* No arguments to pop. */
222#define _PUSHARGS_0 /* No arguments to push. */
223#define _DOARGS_0(n) /* No arguments to frob. */
224#define _POPARGS_0 /* No arguments to pop. */
225
bd4f43b4 226#define PUSHARGS_1 movl %ebx, %edx; L(SAVEBX1): PUSHARGS_0
8f5ca04b 227#define DOARGS_1 _DOARGS_1 (4)
bd4f43b4 228#define POPARGS_1 POPARGS_0; movl %edx, %ebx; L(RESTBX1):
62d01985
UD
229#define _PUSHARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
230 cfi_rel_offset (ebx, 0); L(PUSHBX1): _PUSHARGS_0
8f5ca04b 231#define _DOARGS_1(n) movl n(%esp), %ebx; _DOARGS_0(n-4)
62d01985
UD
232#define _POPARGS_1 _POPARGS_0; popl %ebx; cfi_adjust_cfa_offset (-4); \
233 cfi_restore (ebx); L(POPBX1):
8f5ca04b
RM
234
235#define PUSHARGS_2 PUSHARGS_1
236#define DOARGS_2 _DOARGS_2 (8)
237#define POPARGS_2 POPARGS_1
238#define _PUSHARGS_2 _PUSHARGS_1
d2f5be2a 239#define _DOARGS_2(n) movl n(%esp), %ecx; _DOARGS_1 (n-4)
8f5ca04b 240#define _POPARGS_2 _POPARGS_1
d2f5be2a 241
8f5ca04b
RM
242#define PUSHARGS_3 _PUSHARGS_2
243#define DOARGS_3 _DOARGS_3 (16)
244#define POPARGS_3 _POPARGS_3
245#define _PUSHARGS_3 _PUSHARGS_2
d2f5be2a 246#define _DOARGS_3(n) movl n(%esp), %edx; _DOARGS_2 (n-4)
8f5ca04b
RM
247#define _POPARGS_3 _POPARGS_2
248
249#define PUSHARGS_4 _PUSHARGS_4
250#define DOARGS_4 _DOARGS_4 (24)
251#define POPARGS_4 _POPARGS_4
62d01985
UD
252#define _PUSHARGS_4 pushl %esi; cfi_adjust_cfa_offset (4); \
253 cfi_rel_offset (esi, 0); L(PUSHSI1): _PUSHARGS_3
8f5ca04b 254#define _DOARGS_4(n) movl n(%esp), %esi; _DOARGS_3 (n-4)
62d01985
UD
255#define _POPARGS_4 _POPARGS_3; popl %esi; cfi_adjust_cfa_offset (-4); \
256 cfi_restore (esi); L(POPSI1):
8f5ca04b
RM
257
258#define PUSHARGS_5 _PUSHARGS_5
259#define DOARGS_5 _DOARGS_5 (32)
260#define POPARGS_5 _POPARGS_5
62d01985
UD
261#define _PUSHARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
262 cfi_rel_offset (edi, 0); L(PUSHDI1): _PUSHARGS_4
8f5ca04b 263#define _DOARGS_5(n) movl n(%esp), %edi; _DOARGS_4 (n-4)
62d01985
UD
264#define _POPARGS_5 _POPARGS_4; popl %edi; cfi_adjust_cfa_offset (-4); \
265 cfi_restore (edi); L(POPDI1):
d2f5be2a 266
0da7bcc5 267#define PUSHARGS_6 _PUSHARGS_6
46c38bd7 268#define DOARGS_6 _DOARGS_6 (40)
0da7bcc5 269#define POPARGS_6 _POPARGS_6
62d01985
UD
270#define _PUSHARGS_6 pushl %ebp; cfi_adjust_cfa_offset (4); \
271 cfi_rel_offset (ebp, 0); L(PUSHBP1): _PUSHARGS_5
0da7bcc5 272#define _DOARGS_6(n) movl n(%esp), %ebp; _DOARGS_5 (n-4)
62d01985
UD
273#define _POPARGS_6 _POPARGS_5; popl %ebp; cfi_adjust_cfa_offset (-4); \
274 cfi_restore (ebp); L(POPBP1):
0da7bcc5 275
adcb550c
UD
276#else /* !__ASSEMBLER__ */
277
78e5779b
UD
278/* We need some help from the assembler to generate optimal code. We
279 define some macros here which later will be used. */
e3e35cfc
UD
280asm (".L__X'%ebx = 1\n\t"
281 ".L__X'%ecx = 2\n\t"
282 ".L__X'%edx = 2\n\t"
283 ".L__X'%eax = 3\n\t"
284 ".L__X'%esi = 3\n\t"
285 ".L__X'%edi = 3\n\t"
286 ".L__X'%ebp = 3\n\t"
287 ".L__X'%esp = 3\n\t"
78e5779b
UD
288 ".macro bpushl name reg\n\t"
289 ".if 1 - \\name\n\t"
290 ".if 2 - \\name\n\t"
7a114794 291 "error\n\t"
78e5779b
UD
292 ".else\n\t"
293 "xchgl \\reg, %ebx\n\t"
294 ".endif\n\t"
295 ".endif\n\t"
296 ".endm\n\t"
297 ".macro bpopl name reg\n\t"
298 ".if 1 - \\name\n\t"
299 ".if 2 - \\name\n\t"
7a114794 300 "error\n\t"
78e5779b
UD
301 ".else\n\t"
302 "xchgl \\reg, %ebx\n\t"
303 ".endif\n\t"
304 ".endif\n\t"
78e5779b
UD
305 ".endm\n\t");
306
adcb550c
UD
307/* Define a macro which expands inline into the wrapper code for a system
308 call. */
309#undef INLINE_SYSCALL
310#define INLINE_SYSCALL(name, nr, args...) \
ce460d04 311 ({ \
6aca81bb 312 unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
a1ffb40e 313 if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (resultvar, ))) \
ce460d04 314 { \
6aca81bb 315 __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
ce460d04
RM
316 resultvar = 0xffffffff; \
317 } \
318 (int) resultvar; })
319
320/* Define a macro which expands inline into the wrapper code for a system
321 call. This use is for internal calls that do not need to handle errors
322 normally. It will never touch errno. This returns just what the kernel
2edb61e3
UD
323 gave back.
324
325 The _NCS variant allows non-constant syscall numbers but it is not
326 possible to use more than four parameters. */
ce460d04 327#undef INTERNAL_SYSCALL
5f5843e3
UD
328#ifdef I386_USE_SYSENTER
329# ifdef SHARED
6aca81bb 330# define INTERNAL_SYSCALL(name, err, nr, args...) \
5f5843e3 331 ({ \
7a114794
UD
332 register unsigned int resultvar; \
333 EXTRAVAR_##nr \
5f5843e3
UD
334 asm volatile ( \
335 LOADARGS_##nr \
336 "movl %1, %%eax\n\t" \
337 "call *%%gs:%P2\n\t" \
338 RESTOREARGS_##nr \
339 : "=a" (resultvar) \
340 : "i" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \
341 ASMFMT_##nr(args) : "memory", "cc"); \
342 (int) resultvar; })
2edb61e3
UD
343# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
344 ({ \
345 register unsigned int resultvar; \
346 EXTRAVAR_##nr \
347 asm volatile ( \
348 LOADARGS_##nr \
349 "call *%%gs:%P2\n\t" \
350 RESTOREARGS_##nr \
351 : "=a" (resultvar) \
352 : "0" (name), "i" (offsetof (tcbhead_t, sysinfo)) \
353 ASMFMT_##nr(args) : "memory", "cc"); \
354 (int) resultvar; })
5f5843e3 355# else
6aca81bb 356# define INTERNAL_SYSCALL(name, err, nr, args...) \
adcb550c 357 ({ \
7a114794
UD
358 register unsigned int resultvar; \
359 EXTRAVAR_##nr \
adcb550c 360 asm volatile ( \
44129238 361 LOADARGS_##nr \
78e5779b 362 "movl %1, %%eax\n\t" \
5f5843e3 363 "call *_dl_sysinfo\n\t" \
44129238 364 RESTOREARGS_##nr \
adcb550c 365 : "=a" (resultvar) \
78e5779b 366 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
adcb550c 367 (int) resultvar; })
2edb61e3
UD
368# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
369 ({ \
370 register unsigned int resultvar; \
371 EXTRAVAR_##nr \
372 asm volatile ( \
373 LOADARGS_##nr \
374 "call *_dl_sysinfo\n\t" \
375 RESTOREARGS_##nr \
376 : "=a" (resultvar) \
377 : "0" (name) ASMFMT_##nr(args) : "memory", "cc"); \
378 (int) resultvar; })
5f5843e3
UD
379# endif
380#else
6aca81bb 381# define INTERNAL_SYSCALL(name, err, nr, args...) \
5f5843e3 382 ({ \
7a114794
UD
383 register unsigned int resultvar; \
384 EXTRAVAR_##nr \
5f5843e3
UD
385 asm volatile ( \
386 LOADARGS_##nr \
387 "movl %1, %%eax\n\t" \
7a114794 388 "int $0x80\n\t" \
5f5843e3
UD
389 RESTOREARGS_##nr \
390 : "=a" (resultvar) \
391 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
392 (int) resultvar; })
2edb61e3
UD
393# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
394 ({ \
395 register unsigned int resultvar; \
396 EXTRAVAR_##nr \
397 asm volatile ( \
398 LOADARGS_##nr \
399 "int $0x80\n\t" \
400 RESTOREARGS_##nr \
401 : "=a" (resultvar) \
402 : "0" (name) ASMFMT_##nr(args) : "memory", "cc"); \
403 (int) resultvar; })
5f5843e3 404#endif
adcb550c 405
6aca81bb
UD
406#undef INTERNAL_SYSCALL_DECL
407#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
408
f4447671 409#undef INTERNAL_SYSCALL_ERROR_P
6aca81bb
UD
410#define INTERNAL_SYSCALL_ERROR_P(val, err) \
411 ((unsigned int) (val) >= 0xfffff001u)
f4447671
UD
412
413#undef INTERNAL_SYSCALL_ERRNO
6aca81bb 414#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
f4447671 415
44129238 416#define LOADARGS_0
7a114794 417#ifdef __PIC__
a44cffaa 418# if defined I386_USE_SYSENTER && defined SHARED
7a114794
UD
419# define LOADARGS_1 \
420 "bpushl .L__X'%k3, %k3\n\t"
421# define LOADARGS_5 \
422 "movl %%ebx, %4\n\t" \
423 "movl %3, %%ebx\n\t"
424# else
425# define LOADARGS_1 \
426 "bpushl .L__X'%k2, %k2\n\t"
427# define LOADARGS_5 \
428 "movl %%ebx, %3\n\t" \
429 "movl %2, %%ebx\n\t"
430# endif
431# define LOADARGS_2 LOADARGS_1
432# define LOADARGS_3 \
433 "xchgl %%ebx, %%edi\n\t"
434# define LOADARGS_4 LOADARGS_3
5f5843e3 435#else
7a114794
UD
436# define LOADARGS_1
437# define LOADARGS_2
438# define LOADARGS_3
439# define LOADARGS_4
440# define LOADARGS_5
5f5843e3 441#endif
44129238
UD
442
443#define RESTOREARGS_0
7a114794
UD
444#ifdef __PIC__
445# if defined I386_USE_SYSENTER && defined SHARED
446# define RESTOREARGS_1 \
5f5843e3 447 "bpopl .L__X'%k3, %k3\n\t"
7a114794
UD
448# define RESTOREARGS_5 \
449 "movl %4, %%ebx"
450# else
451# define RESTOREARGS_1 \
44129238 452 "bpopl .L__X'%k2, %k2\n\t"
7a114794
UD
453# define RESTOREARGS_5 \
454 "movl %3, %%ebx"
455# endif
456# define RESTOREARGS_2 RESTOREARGS_1
457# define RESTOREARGS_3 \
458 "xchgl %%edi, %%ebx\n\t"
459# define RESTOREARGS_4 RESTOREARGS_3
460#else
461# define RESTOREARGS_1
462# define RESTOREARGS_2
463# define RESTOREARGS_3
464# define RESTOREARGS_4
465# define RESTOREARGS_5
5f5843e3 466#endif
44129238 467
7bb38c70 468#define ASMFMT_0()
7a114794
UD
469#ifdef __PIC__
470# define ASMFMT_1(arg1) \
471 , "cd" (arg1)
472# define ASMFMT_2(arg1, arg2) \
3a370de8 473 , "d" (arg1), "c" (arg2)
7a114794
UD
474# define ASMFMT_3(arg1, arg2, arg3) \
475 , "D" (arg1), "c" (arg2), "d" (arg3)
476# define ASMFMT_4(arg1, arg2, arg3, arg4) \
477 , "D" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
478# define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
479 , "0" (arg1), "m" (_xv), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
480#else
481# define ASMFMT_1(arg1) \
482 , "b" (arg1)
483# define ASMFMT_2(arg1, arg2) \
484 , "b" (arg1), "c" (arg2)
485# define ASMFMT_3(arg1, arg2, arg3) \
486 , "b" (arg1), "c" (arg2), "d" (arg3)
487# define ASMFMT_4(arg1, arg2, arg3, arg4) \
488 , "b" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
489# define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
490 , "b" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
491#endif
492
493#define EXTRAVAR_0
494#define EXTRAVAR_1
495#define EXTRAVAR_2
496#define EXTRAVAR_3
497#define EXTRAVAR_4
498#ifdef __PIC__
499# define EXTRAVAR_5 int _xv;
500#else
501# define EXTRAVAR_5
502#endif
adcb550c 503
dbfc1e02
UD
504/* Consistency check for position-independent code. */
505#ifdef __PIC__
506# define check_consistency() \
507 ({ int __res; \
508 __asm__ __volatile__ \
d8e0ca50 509 (LOAD_PIC_REG_STR (cx) ";" \
dbfc1e02
UD
510 "subl %%ebx, %%ecx;" \
511 "je 1f;" \
512 "ud2;" \
513 "1:\n" \
dbfc1e02
UD
514 : "=c" (__res)); \
515 __res; })
516#endif
517
66715f83 518#endif /* __ASSEMBLER__ */
ec4b0518 519
827b7087
UD
520
521/* Pointer mangling support. */
522#if defined NOT_IN_libc && defined IS_IN_rtld
523/* We cannot use the thread descriptor because in ld.so we use setjmp
524 earlier than the descriptor is initialized. Using a global variable
525 is too complicated here since we have no PC-relative addressing mode. */
526#else
3467f5c3 527# ifdef __ASSEMBLER__
4a44ce79
UD
528# define PTR_MANGLE(reg) xorl %gs:POINTER_GUARD, reg; \
529 roll $9, reg
530# define PTR_DEMANGLE(reg) rorl $9, reg; \
531 xorl %gs:POINTER_GUARD, reg
3467f5c3 532# else
4a44ce79
UD
533# define PTR_MANGLE(var) asm ("xorl %%gs:%c2, %0\n" \
534 "roll $9, %0" \
535 : "=r" (var) \
536 : "0" (var), \
537 "i" (offsetof (tcbhead_t, \
538 pointer_guard)))
539# define PTR_DEMANGLE(var) asm ("rorl $9, %0\n" \
540 "xorl %%gs:%c2, %0" \
3467f5c3
UD
541 : "=r" (var) \
542 : "0" (var), \
543 "i" (offsetof (tcbhead_t, \
544 pointer_guard)))
3467f5c3 545# endif
827b7087
UD
546#endif
547
ec4b0518 548#endif /* linux/i386/sysdep.h */