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