OSDN Git Service

libpthread/nptl: core of the "Native Posix Threading Library" for uClibc
[uclinux-h8/uClibc.git] / libpthread / nptl / sysdeps / i386 / sysdep.h
1 /* Assembler macros for i386.
2    Copyright (C) 1991-93,95,96,98,2002,2003,2005,2006
3    Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
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.
10
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.
15
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
19    02111-1307 USA.  */
20
21 #include <sysdeps/generic/sysdep.h>
22
23 #ifdef  __ASSEMBLER__
24
25 /* Syntactic details of assembler.  */
26
27 /* ELF uses byte-counts for .align, most others use log2 of count of bytes.  */
28 #define ALIGNARG(log2) 1<<log2
29 /* For ELF we need the `.type' directive to make shared libs work right.  */
30 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
31 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
32
33 /* In ELF C symbols are asm symbols.  */
34 #undef  NO_UNDERSCORES
35 #define NO_UNDERSCORES
36
37 /* Define an entry point visible from C.
38
39    There is currently a bug in gdb which prevents us from specifying
40    incomplete stabs information.  Fake some entries here which specify
41    the current source file.  */
42 #define ENTRY(name)                                                           \
43   STABS_CURRENT_FILE1("")                                                     \
44   STABS_CURRENT_FILE(name)                                                    \
45   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);                                   \
46   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)                          \
47   .align ALIGNARG(4);                                                         \
48   STABS_FUN(name)                                                             \
49   C_LABEL(name)                                                               \
50   cfi_startproc;                                                              \
51   CALL_MCOUNT
52
53 #undef  END
54 #define END(name)                                                             \
55   cfi_endproc;                                                                \
56   ASM_SIZE_DIRECTIVE(name)                                                    \
57   STABS_FUN_END(name)
58
59 #ifdef HAVE_CPP_ASM_DEBUGINFO
60 /* Disable that goop, because we just pass -g through to the assembler
61    and it generates proper line number information directly.  */
62 # define STABS_CURRENT_FILE1(name)
63 # define STABS_CURRENT_FILE(name)
64 # define STABS_FUN(name)
65 # define STABS_FUN_END(name)
66 #else
67 /* Remove the following two lines once the gdb bug is fixed.  */
68 #define STABS_CURRENT_FILE(name)                                              \
69   STABS_CURRENT_FILE1 (#name)
70 #define STABS_CURRENT_FILE1(name)                                             \
71   1: .stabs name,100,0,0,1b;
72 /* Emit stabs definition lines.  We use F(0,1) and define t(0,1) as `int',
73    the same way gcc does it.  */
74 #define STABS_FUN(name) STABS_FUN2(name, name##:F(0,1))
75 #define STABS_FUN2(name, namestr)                                             \
76   .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0;               \
77   .stabs #namestr,36,0,0,name;
78 #define STABS_FUN_END(name)                                                   \
79   1: .stabs "",36,0,0,1b-name;
80 #endif
81
82 /* If compiled for profiling, call `mcount' at the start of each function.  */
83 #ifdef  PROF
84 /* The mcount code relies on a normal frame pointer being on the stack
85    to locate our caller, so push one just for its benefit.  */
86 #define CALL_MCOUNT \
87   pushl %ebp; cfi_adjust_cfa_offset (4); movl %esp, %ebp; \
88   cfi_def_cfa_register (ebp); call JUMPTARGET(mcount); \
89   popl %ebp; cfi_def_cfa (esp, 4);
90 #else
91 #define CALL_MCOUNT             /* Do nothing.  */
92 #endif
93
94 #ifdef  NO_UNDERSCORES
95 /* Since C identifiers are not normally prefixed with an underscore
96    on this system, the asm identifier `syscall_error' intrudes on the
97    C name space.  Make sure we use an innocuous name.  */
98 #define syscall_error   __syscall_error
99 #define mcount          _mcount
100 #endif
101
102 #define PSEUDO(name, syscall_name, args)                                      \
103   .globl syscall_error;                                                       \
104 lose: SYSCALL_PIC_SETUP                                                       \
105   jmp JUMPTARGET(syscall_error);                                              \
106   ENTRY (name)                                                                \
107   DO_CALL (syscall_name, args);                                               \
108   jb lose
109
110 #undef  PSEUDO_END
111 #define PSEUDO_END(name)                                                      \
112   END (name)
113
114 #undef JUMPTARGET
115 #ifdef PIC
116 #define JUMPTARGET(name)        name##@PLT
117 #define SYSCALL_PIC_SETUP \
118     pushl %ebx;                                                               \
119     cfi_adjust_cfa_offset (4);                                                \
120     call 0f;                                                                  \
121 0:  popl %ebx;                                                                \
122     cfi_adjust_cfa_offset (-4);                                               \
123     addl $_GLOBAL_OFFSET_TABLE+[.-0b], %ebx;
124
125 # define SETUP_PIC_REG(reg) \
126   .ifndef __i686.get_pc_thunk.reg;                                            \
127   .section .gnu.linkonce.t.__i686.get_pc_thunk.reg,"ax",@progbits;            \
128   .globl __i686.get_pc_thunk.reg;                                             \
129   .hidden __i686.get_pc_thunk.reg;                                            \
130   .type __i686.get_pc_thunk.reg,@function;                                    \
131 __i686.get_pc_thunk.reg:                                                      \
132   movl (%esp), %e##reg;                                                       \
133   ret;                                                                        \
134   .size __i686.get_pc_thunk.reg, . - __i686.get_pc_thunk.reg;                 \
135   .previous;                                                                  \
136   .endif;                                                                     \
137   call __i686.get_pc_thunk.reg
138
139 # define LOAD_PIC_REG(reg) \
140   SETUP_PIC_REG(reg); addl $_GLOBAL_OFFSET_TABLE_, %e##reg
141
142 #else
143 #define JUMPTARGET(name)        name
144 #define SYSCALL_PIC_SETUP       /* Nothing.  */
145 #endif
146
147 /* Local label name for asm code. */
148 #ifndef L
149 #ifdef HAVE_ELF
150 #define L(name)         .L##name
151 #else
152 #define L(name)         name
153 #endif
154 #endif
155
156 #endif  /* __ASSEMBLER__ */