Back to index

glibc  2.9
sysdep.h
Go to the documentation of this file.
00001 /* Assembler macros for x86-64.
00002    Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <sysdeps/generic/sysdep.h>
00021 
00022 #ifdef __ASSEMBLER__
00023 
00024 /* Syntactic details of assembler.  */
00025 
00026 #ifdef HAVE_ELF
00027 
00028 /* ELF uses byte-counts for .align, most others use log2 of count of bytes.  */
00029 #define ALIGNARG(log2) 1<<log2
00030 /* For ELF we need the `.type' directive to make shared libs work right.  */
00031 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
00032 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
00033 
00034 /* In ELF C symbols are asm symbols.  */
00035 #undef NO_UNDERSCORES
00036 #define NO_UNDERSCORES
00037 
00038 #else
00039 
00040 #define ALIGNARG(log2) log2
00041 #define ASM_TYPE_DIRECTIVE(name,type)     /* Nothing is specified.  */
00042 #define ASM_SIZE_DIRECTIVE(name)   /* Nothing is specified.  */
00043 
00044 #endif
00045 
00046 
00047 /* Define an entry point visible from C.  */
00048 #define       ENTRY(name)                                                   \
00049   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);                                 \
00050   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)                        \
00051   .align ALIGNARG(4);                                                       \
00052   C_LABEL(name)                                                             \
00053   cfi_startproc;                                                     \
00054   CALL_MCOUNT
00055 
00056 #undef END
00057 #define END(name)                                                    \
00058   cfi_endproc;                                                              \
00059   ASM_SIZE_DIRECTIVE(name)
00060 
00061 /* If compiled for profiling, call `mcount' at the start of each function.  */
00062 #ifdef PROF
00063 /* The mcount code relies on a normal frame pointer being on the stack
00064    to locate our caller, so push one just for its benefit.  */
00065 #define CALL_MCOUNT                                                          \
00066   pushq %rbp;                                                                \
00067   cfi_adjust_cfa_offset(8);                                                  \
00068   movq %rsp, %rbp;                                                           \
00069   cfi_def_cfa_register(%rbp);                                                \
00070   call JUMPTARGET(mcount);                                                   \
00071   popq %rbp;                                                                 \
00072   cfi_def_cfa(rsp,8);
00073 #else
00074 #define CALL_MCOUNT         /* Do nothing.  */
00075 #endif
00076 
00077 #ifdef NO_UNDERSCORES
00078 /* Since C identifiers are not normally prefixed with an underscore
00079    on this system, the asm identifier `syscall_error' intrudes on the
00080    C name space.  Make sure we use an innocuous name.  */
00081 #define       syscall_error __syscall_error
00082 #define mcount              _mcount
00083 #endif
00084 
00085 #define       PSEUDO(name, syscall_name, args)                              \
00086 lose:                                                                \
00087   jmp JUMPTARGET(syscall_error)                                             \
00088   .globl syscall_error;                                                     \
00089   ENTRY (name)                                                              \
00090   DO_CALL (syscall_name, args);                                             \
00091   jb lose
00092 
00093 #undef PSEUDO_END
00094 #define       PSEUDO_END(name)                                              \
00095   END (name)
00096 
00097 #undef JUMPTARGET
00098 #ifdef PIC
00099 #define JUMPTARGET(name)    name##@PLT
00100 #else
00101 #define JUMPTARGET(name)    name
00102 #endif
00103 
00104 /* Local label name for asm code. */
00105 #ifndef L
00106 # ifdef HAVE_ELF
00107 /* ELF-like local names start with `.L'.  */
00108 #  define L(name)    .L##name
00109 # else
00110 #  define L(name)    name
00111 # endif
00112 #endif
00113 
00114 #endif /* __ASSEMBLER__ */