Back to index

glibc  2.9
sysdep.h
Go to the documentation of this file.
00001 /* Assembler macros for i386.
00002    Copyright (C) 1991-93,95,96,98,2002,2003,2005,2006
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <sysdeps/generic/sysdep.h>
00022 
00023 #ifdef __ASSEMBLER__
00024 
00025 /* Syntactic details of assembler.  */
00026 
00027 #ifdef HAVE_ELF
00028 
00029 /* ELF uses byte-counts for .align, most others use log2 of count of bytes.  */
00030 #define ALIGNARG(log2) 1<<log2
00031 /* For ELF we need the `.type' directive to make shared libs work right.  */
00032 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
00033 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
00034 
00035 /* In ELF C symbols are asm symbols.  */
00036 #undef NO_UNDERSCORES
00037 #define NO_UNDERSCORES
00038 
00039 #else
00040 
00041 #define ALIGNARG(log2) log2
00042 #define ASM_TYPE_DIRECTIVE(name,type)     /* Nothing is specified.  */
00043 #define ASM_SIZE_DIRECTIVE(name)   /* Nothing is specified.  */
00044 
00045 #endif
00046 
00047 
00048 /* Define an entry point visible from C.
00049 
00050    There is currently a bug in gdb which prevents us from specifying
00051    incomplete stabs information.  Fake some entries here which specify
00052    the current source file.  */
00053 #define       ENTRY(name)                                                   \
00054   STABS_CURRENT_FILE1("")                                            \
00055   STABS_CURRENT_FILE(name)                                           \
00056   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);                                 \
00057   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)                        \
00058   .align ALIGNARG(4);                                                       \
00059   STABS_FUN(name)                                                    \
00060   C_LABEL(name)                                                             \
00061   cfi_startproc;                                                     \
00062   CALL_MCOUNT
00063 
00064 #undef END
00065 #define END(name)                                                    \
00066   cfi_endproc;                                                              \
00067   ASM_SIZE_DIRECTIVE(name)                                           \
00068   STABS_FUN_END(name)
00069 
00070 #ifdef HAVE_CPP_ASM_DEBUGINFO
00071 /* Disable that goop, because we just pass -g through to the assembler
00072    and it generates proper line number information directly.  */
00073 # define STABS_CURRENT_FILE1(name)
00074 # define STABS_CURRENT_FILE(name)
00075 # define STABS_FUN(name)
00076 # define STABS_FUN_END(name)
00077 #else
00078 /* Remove the following two lines once the gdb bug is fixed.  */
00079 #define STABS_CURRENT_FILE(name)                                     \
00080   STABS_CURRENT_FILE1 (#name)
00081 #define STABS_CURRENT_FILE1(name)                                    \
00082   1: .stabs name,100,0,0,1b;
00083 /* Emit stabs definition lines.  We use F(0,1) and define t(0,1) as `int',
00084    the same way gcc does it.  */
00085 #define STABS_FUN(name) STABS_FUN2(name, name##:F(0,1))
00086 #define STABS_FUN2(name, namestr)                                    \
00087   .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0;                    \
00088   .stabs #namestr,36,0,0,name;
00089 #define STABS_FUN_END(name)                                          \
00090   1: .stabs "",36,0,0,1b-name;
00091 #endif
00092 
00093 /* If compiled for profiling, call `mcount' at the start of each function.  */
00094 #ifdef PROF
00095 /* The mcount code relies on a normal frame pointer being on the stack
00096    to locate our caller, so push one just for its benefit.  */
00097 #define CALL_MCOUNT \
00098   pushl %ebp; cfi_adjust_cfa_offset (4); movl %esp, %ebp; \
00099   cfi_def_cfa_register (ebp); call JUMPTARGET(mcount); \
00100   popl %ebp; cfi_def_cfa (esp, 4);
00101 #else
00102 #define CALL_MCOUNT         /* Do nothing.  */
00103 #endif
00104 
00105 #ifdef NO_UNDERSCORES
00106 /* Since C identifiers are not normally prefixed with an underscore
00107    on this system, the asm identifier `syscall_error' intrudes on the
00108    C name space.  Make sure we use an innocuous name.  */
00109 #define       syscall_error __syscall_error
00110 #define mcount              _mcount
00111 #endif
00112 
00113 #define       PSEUDO(name, syscall_name, args)                              \
00114   .globl syscall_error;                                                     \
00115 lose: SYSCALL_PIC_SETUP                                                     \
00116   jmp JUMPTARGET(syscall_error);                                     \
00117   ENTRY (name)                                                              \
00118   DO_CALL (syscall_name, args);                                             \
00119   jb lose
00120 
00121 #undef PSEUDO_END
00122 #define       PSEUDO_END(name)                                              \
00123   END (name)
00124 
00125 #undef JUMPTARGET
00126 #ifdef PIC
00127 #define JUMPTARGET(name)    name##@PLT
00128 #define SYSCALL_PIC_SETUP \
00129     pushl %ebx;                                                             \
00130     cfi_adjust_cfa_offset (4);                                              \
00131     call 0f;                                                         \
00132 0:  popl %ebx;                                                              \
00133     cfi_adjust_cfa_offset (-4);                                             \
00134     addl $_GLOBAL_OFFSET_TABLE+[.-0b], %ebx;
00135 
00136 # define SETUP_PIC_REG(reg) \
00137   .ifndef __i686.get_pc_thunk.reg;                                   \
00138   .section .gnu.linkonce.t.__i686.get_pc_thunk.reg,"ax",@progbits;          \
00139   .globl __i686.get_pc_thunk.reg;                                    \
00140   .hidden __i686.get_pc_thunk.reg;                                   \
00141   .type __i686.get_pc_thunk.reg,@function;                                  \
00142 __i686.get_pc_thunk.reg:                                             \
00143   movl (%esp), %e##reg;                                                     \
00144   ret;                                                               \
00145   .size __i686.get_pc_thunk.reg, . - __i686.get_pc_thunk.reg;               \
00146   .previous;                                                         \
00147   .endif;                                                            \
00148   call __i686.get_pc_thunk.reg
00149 
00150 # define LOAD_PIC_REG(reg) \
00151   SETUP_PIC_REG(reg); addl $_GLOBAL_OFFSET_TABLE_, %e##reg
00152 
00153 #else
00154 #define JUMPTARGET(name)    name
00155 #define SYSCALL_PIC_SETUP   /* Nothing.  */
00156 #endif
00157 
00158 /* Local label name for asm code. */
00159 #ifndef L
00160 #ifdef HAVE_ELF
00161 #define L(name)             .L##name
00162 #else
00163 #define L(name)             name
00164 #endif
00165 #endif
00166 
00167 #endif /* __ASSEMBLER__ */