1 /* Copyright (C) 1992,1993,1995-2000,2002,2003,2004
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper, <drepper@gnu.org>, August 1995.
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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #ifndef _FREEBSD_I386_SYSDEP_H
22 #define _FREEBSD_I386_SYSDEP_H 1
24 /* There is some commonality. */
25 #include <sysdeps/unix/i386/sysdep.h>
26 /* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
27 #include <dl-sysdep.h>
32 /* We don't want the label for the error handle to be global when we define
35 # define SYSCALL_ERROR_LABEL 0f
37 # define SYSCALL_ERROR_LABEL syscall_error
41 #define PSEUDO(name, syscall_name, args) \
44 DO_CALL (syscall_name, args); \
45 jb SYSCALL_ERROR_LABEL; \
49 #define PSEUDO_END(name) \
50 SYSCALL_ERROR_HANDLER \
54 #define PSEUDO_NOERRNO(name, syscall_name, args) \
57 DO_CALL (syscall_name, args)
59 #undef PSEUDO_END_NOERRNO
60 #define PSEUDO_END_NOERRNO(name) \
63 #define ret_NOERRNO ret
65 /* The function has to return the error code. */
67 #define PSEUDO_ERRVAL(name, syscall_name, args) \
70 DO_CALL (syscall_name, args); \
72 #undef PSEUDO_END_ERRVAL
73 #define PSEUDO_END_ERRVAL(name) \
76 #define ret_ERRVAL ret
79 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
82 # if RTLD_PRIVATE_ERRNO
83 # define SYSCALL_ERROR_HANDLER \
84 0:SETUP_PIC_REG(cx); \
85 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
86 movl %eax, rtld_errno@GOTOFF(%ecx); \
90 # elif defined _LIBC_REENTRANT
93 # define SYSCALL_ERROR_ERRNO __libc_errno
95 # define SYSCALL_ERROR_ERRNO errno
97 # define SYSCALL_ERROR_HANDLER \
98 0:SETUP_PIC_REG (cx); \
99 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
100 movl SYSCALL_ERROR_ERRNO@GOTNTPOFF(%ecx), %ecx; \
101 SYSCALL_ERROR_HANDLER_TLS_STORE (%eax, %ecx); \
104 # ifndef NO_TLS_DIRECT_SEG_REFS
105 # define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff) \
106 movl src, %gs:(destoff)
108 # define SYSCALL_ERROR_HANDLER_TLS_STORE(src, destoff) \
109 addl %gs:0, destoff; \
113 /* Store (%eax) into errno through the GOT. */
114 # define SYSCALL_ERROR_HANDLER \
115 0:SETUP_PIC_REG(cx); \
116 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
117 movl errno@GOT(%ecx), %ecx; \
121 # endif /* _LIBC_REENTRANT */
125 FreeBSD expects the system call arguments on the stack,
126 syscall number is in %eax.
127 return value is in %eax + %edx
128 error is signaled via cflags.
129 all other data registers are preserved
131 syscall number %eax call-clobbered
133 The stack layout upon entering the function is:
140 (%esp) Return address
142 (Of course a function with say 3 arguments does not have entries for
148 #define DO_CALL(syscall_name, args) \
149 movl $SYS_ify (syscall_name), %eax; \
152 #else /* !__ASSEMBLER__ */
154 #include <syscalls-inline.h>
156 /* Consistency check for position-independent code. */
157 #if defined __PIC__ && !__GNUC_PREREQ (5,0)
158 # define check_consistency() \
160 __asm__ __volatile__ \
161 (LOAD_PIC_REG_STR (cx) ";" \
162 "subl %%ebx, %%ecx;" \
170 #endif /* __ASSEMBLER__ */
173 /* Pointer mangling support. */
175 /* We cannot use the thread descriptor because in ld.so we use setjmp
176 earlier than the descriptor is initialized. Using a global variable
177 is too complicated here since we have no PC-relative addressing mode. */
179 # ifdef __ASSEMBLER__
180 # define PTR_MANGLE(reg) xorl %gs:POINTER_GUARD, reg; \
182 # define PTR_DEMANGLE(reg) rorl $9, reg; \
183 xorl %gs:POINTER_GUARD, reg
185 # define PTR_MANGLE(var) asm ("xorl %%gs:%c2, %0\n" \
189 "i" (offsetof (tcbhead_t, \
191 # define PTR_DEMANGLE(var) asm ("rorl $9, %0\n" \
192 "xorl %%gs:%c2, %0" \
195 "i" (offsetof (tcbhead_t, \
200 #endif /* _FREEBSD_I386_SYSDEP_H */