1 /* Assembler macros for x86-64. 2 Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 5 The GNU C Library is free software; you can redistribute it and/or 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. 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 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library; if not, write to the Free 17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 02111-1307 USA. */ 19 20 #include_next <sysdep.h> 21 22 #ifdef __ASSEMBLER__ 23 24 /* Syntactic details of assembler. */ 25 26 #define cfi_startproc .cfi_startproc 27 #define cfi_endproc .cfi_endproc 28 #define cfi_def_cfa(reg, off) .cfi_def_cfa reg, off 29 #define cfi_def_cfa_register(reg) .cfi_def_cfa_register reg 30 #define cfi_def_cfa_offset(off) .cfi_def_cfa_offset off 31 #define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off 32 #define cfi_offset(reg, off) .cfi_offset reg, off 33 #define cfi_rel_offset(reg, off) .cfi_rel_offset reg, off 34 #define cfi_register(r1, r2) .cfi_register r1, r2 35 #define cfi_return_column(reg) .cfi_return_column reg 36 #define cfi_restore(reg) .cfi_restore reg 37 #define cfi_same_value(reg) .cfi_same_value reg 38 #define cfi_undefined(reg) .cfi_undefined reg 39 #define cfi_remember_state .cfi_remember_state 40 #define cfi_restore_state .cfi_restore_state 41 #define cfi_window_save .cfi_window_save 42 43 #ifdef HAVE_ELF 44 45 /* ELF uses byte-counts for .align, most others use log2 of count of bytes. */ 46 #define ALIGNARG(log2) 1<<log2 47 /* For ELF we need the `.type' directive to make shared libs work right. */ 48 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg; 49 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name; 50 51 /* In ELF C symbols are asm symbols. */ 52 #undef NO_UNDERSCORES 53 #define NO_UNDERSCORES 54 55 #else 56 57 #define ALIGNARG(log2) log2 58 #define ASM_TYPE_DIRECTIVE(name,type) /* Nothing is specified. */ 59 #define ASM_SIZE_DIRECTIVE(name) /* Nothing is specified. */ 60 61 #endif 62 63 64 /* Define an entry point visible from C. */ 65 #define ENTRY(name) \ 66 ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \ 67 ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \ 68 .align ALIGNARG(4); \ 69 C_LABEL(name) \ 70 cfi_startproc; \ 71 CALL_MCOUNT 72 73 #undef END 74 #define END(name) \ 75 cfi_endproc; \ 76 ASM_SIZE_DIRECTIVE(name) 77 78 /* If compiled for profiling, call `mcount' at the start of each function. */ 79 #ifdef PROF 80 /* The mcount code relies on a normal frame pointer being on the stack 81 to locate our caller, so push one just for its benefit. */ 82 #define CALL_MCOUNT \ 83 pushq %rbp; \ 84 cfi_adjust_cfa_offset(8); \ 85 movq %rsp, %rbp; \ 86 cfi_def_cfa_register(%rbp); \ 87 call JUMPTARGET(mcount); \ 88 popq %rbp; \ 89 cfi_def_cfa(rsp,8); 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 lose: \ 104 jmp JUMPTARGET(syscall_error) \ 105 .globl 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 #else 118 #define JUMPTARGET(name) name 119 #endif 120 121 /* Local label name for asm code. */ 122 #ifndef L 123 # ifdef HAVE_ELF 124 /* ELF-like local names start with `.L'. */ 125 # define L(name) .L##name 126 # else 127 # define L(name) name 128 # endif 129 #endif 130 131 #endif /* __ASSEMBLER__ */ 132