]>
Commit | Line | Data |
---|---|---|
e75154a6 | 1 | /* Assembler macros for i386. |
0269750c | 2 | Copyright (C) 1991-93,95,96,98,2002,2003,2005,2006,2011,2012 |
11bf311e | 3 | Free Software Foundation, Inc. |
2c6fe0bd UD |
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 | |
41bdb6e2 AJ |
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. | |
2c6fe0bd UD |
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 | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
2c6fe0bd | 15 | |
41bdb6e2 AJ |
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. */ | |
e75154a6 RM |
20 | |
21 | #include <sysdeps/generic/sysdep.h> | |
22 | ||
314054ea JM |
23 | #include <features.h> /* For __GNUC_PREREQ. */ |
24 | ||
25 | /* It is desirable that the names of PIC thunks match those used by | |
d4a54ac6 JM |
26 | GCC so that multiple copies are eliminated by the linker. Because |
27 | GCC 4.6 and earlier use __i686 in the names, it is necessary to | |
28 | override that predefined macro. */ | |
29 | #if defined __i686 && defined __ASSEMBLER__ | |
30 | #undef __i686 | |
31 | #define __i686 __i686 | |
32 | #endif | |
314054ea JM |
33 | |
34 | #ifdef __ASSEMBLER__ | |
35 | # if __GNUC_PREREQ (4, 7) | |
36 | # define GET_PC_THUNK(reg) __x86.get_pc_thunk.reg | |
37 | # else | |
38 | # define GET_PC_THUNK(reg) __i686.get_pc_thunk.reg | |
39 | # endif | |
b1da7dd9 | 40 | #else |
314054ea JM |
41 | # if __GNUC_PREREQ (4, 7) |
42 | # define GET_PC_THUNK_STR(reg) "__x86.get_pc_thunk." #reg | |
43 | # else | |
44 | # define GET_PC_THUNK_STR(reg) "__i686.get_pc_thunk." #reg | |
45 | # endif | |
b1da7dd9 JM |
46 | #endif |
47 | ||
66715f83 | 48 | #ifdef __ASSEMBLER__ |
e75154a6 RM |
49 | |
50 | /* Syntactic details of assembler. */ | |
51 | ||
e75154a6 RM |
52 | /* ELF uses byte-counts for .align, most others use log2 of count of bytes. */ |
53 | #define ALIGNARG(log2) 1<<log2 | |
54 | /* For ELF we need the `.type' directive to make shared libs work right. */ | |
55 | #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg; | |
ae828bc6 | 56 | #define ASM_SIZE_DIRECTIVE(name) .size name,.-name; |
e75154a6 | 57 | |
e75154a6 | 58 | |
ae828bc6 UD |
59 | /* Define an entry point visible from C. |
60 | ||
61 | There is currently a bug in gdb which prevents us from specifying | |
62 | incomplete stabs information. Fake some entries here which specify | |
63 | the current source file. */ | |
e75154a6 | 64 | #define ENTRY(name) \ |
ae828bc6 UD |
65 | STABS_CURRENT_FILE1("") \ |
66 | STABS_CURRENT_FILE(name) \ | |
e75154a6 RM |
67 | ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \ |
68 | ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \ | |
69 | .align ALIGNARG(4); \ | |
ae828bc6 | 70 | STABS_FUN(name) \ |
e75154a6 | 71 | C_LABEL(name) \ |
62d01985 | 72 | cfi_startproc; \ |
e75154a6 RM |
73 | CALL_MCOUNT |
74 | ||
6ed0492f UD |
75 | #undef END |
76 | #define END(name) \ | |
62d01985 | 77 | cfi_endproc; \ |
ae828bc6 UD |
78 | ASM_SIZE_DIRECTIVE(name) \ |
79 | STABS_FUN_END(name) | |
80 | ||
3af48cbd L |
81 | #define ENTRY_CHK(name) ENTRY (name) |
82 | #define END_CHK(name) END (name) | |
83 | ||
e48f9638 RM |
84 | #ifdef HAVE_CPP_ASM_DEBUGINFO |
85 | /* Disable that goop, because we just pass -g through to the assembler | |
86 | and it generates proper line number information directly. */ | |
87 | # define STABS_CURRENT_FILE1(name) | |
88 | # define STABS_CURRENT_FILE(name) | |
89 | # define STABS_FUN(name) | |
90 | # define STABS_FUN_END(name) | |
91 | #else | |
ae828bc6 UD |
92 | /* Remove the following two lines once the gdb bug is fixed. */ |
93 | #define STABS_CURRENT_FILE(name) \ | |
94 | STABS_CURRENT_FILE1 (#name) | |
95 | #define STABS_CURRENT_FILE1(name) \ | |
96 | 1: .stabs name,100,0,0,1b; | |
97 | /* Emit stabs definition lines. We use F(0,1) and define t(0,1) as `int', | |
98 | the same way gcc does it. */ | |
99 | #define STABS_FUN(name) STABS_FUN2(name, name##:F(0,1)) | |
100 | #define STABS_FUN2(name, namestr) \ | |
101 | .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0; \ | |
102 | .stabs #namestr,36,0,0,name; | |
103 | #define STABS_FUN_END(name) \ | |
104 | 1: .stabs "",36,0,0,1b-name; | |
e48f9638 | 105 | #endif |
6ed0492f | 106 | |
e75154a6 RM |
107 | /* If compiled for profiling, call `mcount' at the start of each function. */ |
108 | #ifdef PROF | |
109 | /* The mcount code relies on a normal frame pointer being on the stack | |
110 | to locate our caller, so push one just for its benefit. */ | |
111 | #define CALL_MCOUNT \ | |
cb8d9c93 | 112 | pushl %ebp; cfi_adjust_cfa_offset (4); movl %esp, %ebp; \ |
62d01985 UD |
113 | cfi_def_cfa_register (ebp); call JUMPTARGET(mcount); \ |
114 | popl %ebp; cfi_def_cfa (esp, 4); | |
e75154a6 RM |
115 | #else |
116 | #define CALL_MCOUNT /* Do nothing. */ | |
117 | #endif | |
118 | ||
e75154a6 RM |
119 | /* Since C identifiers are not normally prefixed with an underscore |
120 | on this system, the asm identifier `syscall_error' intrudes on the | |
121 | C name space. Make sure we use an innocuous name. */ | |
122 | #define syscall_error __syscall_error | |
123 | #define mcount _mcount | |
e75154a6 RM |
124 | |
125 | #define PSEUDO(name, syscall_name, args) \ | |
e75154a6 | 126 | .globl syscall_error; \ |
ffa8d2a0 RM |
127 | lose: SYSCALL_PIC_SETUP \ |
128 | jmp JUMPTARGET(syscall_error); \ | |
e75154a6 RM |
129 | ENTRY (name) \ |
130 | DO_CALL (syscall_name, args); \ | |
131 | jb lose | |
132 | ||
cccda09f UD |
133 | #undef PSEUDO_END |
134 | #define PSEUDO_END(name) \ | |
6ed0492f | 135 | END (name) |
cccda09f | 136 | |
11bf311e | 137 | # define SETUP_PIC_REG(reg) \ |
b1da7dd9 JM |
138 | .ifndef GET_PC_THUNK(reg); \ |
139 | .section .gnu.linkonce.t.GET_PC_THUNK(reg),"ax",@progbits; \ | |
140 | .globl GET_PC_THUNK(reg); \ | |
141 | .hidden GET_PC_THUNK(reg); \ | |
9a1d9254 | 142 | .p2align 4; \ |
b1da7dd9 JM |
143 | .type GET_PC_THUNK(reg),@function; \ |
144 | GET_PC_THUNK(reg): \ | |
1f708405 RM |
145 | movl (%esp), %e##reg; \ |
146 | ret; \ | |
b1da7dd9 | 147 | .size GET_PC_THUNK(reg), . - GET_PC_THUNK(reg); \ |
1f708405 RM |
148 | .previous; \ |
149 | .endif; \ | |
b1da7dd9 | 150 | call GET_PC_THUNK(reg) |
1f708405 RM |
151 | |
152 | # define LOAD_PIC_REG(reg) \ | |
153 | SETUP_PIC_REG(reg); addl $_GLOBAL_OFFSET_TABLE_, %e##reg | |
154 | ||
9a1d9254 JM |
155 | #undef JUMPTARGET |
156 | #ifdef PIC | |
157 | #define JUMPTARGET(name) name##@PLT | |
158 | #define SYSCALL_PIC_SETUP \ | |
159 | pushl %ebx; \ | |
160 | cfi_adjust_cfa_offset (4); \ | |
161 | call 0f; \ | |
162 | 0: popl %ebx; \ | |
163 | cfi_adjust_cfa_offset (-4); \ | |
164 | addl $_GLOBAL_OFFSET_TABLE+[.-0b], %ebx; | |
165 | ||
e75154a6 RM |
166 | #else |
167 | #define JUMPTARGET(name) name | |
168 | #define SYSCALL_PIC_SETUP /* Nothing. */ | |
169 | #endif | |
170 | ||
ac16e905 UD |
171 | /* Local label name for asm code. */ |
172 | #ifndef L | |
ffa8d2a0 | 173 | #define L(name) .L##name |
ffa8d2a0 | 174 | #endif |
ac16e905 | 175 | |
ceaa0c5d UD |
176 | #define atom_text_section .section ".text.atom", "ax" |
177 | ||
d8e0ca50 JM |
178 | #else /* __ASSEMBLER__ */ |
179 | ||
180 | # define SETUP_PIC_REG_STR(reg) \ | |
181 | ".ifndef " GET_PC_THUNK_STR (reg) "\n" \ | |
182 | ".section .gnu.linkonce.t." GET_PC_THUNK_STR (reg) ",\"ax\",@progbits\n" \ | |
183 | ".globl " GET_PC_THUNK_STR (reg) "\n" \ | |
184 | ".hidden " GET_PC_THUNK_STR (reg) "\n" \ | |
185 | ".p2align 4\n" \ | |
186 | ".type " GET_PC_THUNK_STR (reg) ",@function\n" \ | |
187 | GET_PC_THUNK_STR (reg) ":" \ | |
188 | "movl (%%esp), %%e" #reg "\n" \ | |
189 | "ret\n" \ | |
190 | ".size " GET_PC_THUNK_STR (reg) ", . - " GET_PC_THUNK_STR (reg) "\n" \ | |
191 | ".previous\n" \ | |
192 | ".endif\n" \ | |
193 | "call " GET_PC_THUNK_STR (reg) | |
194 | ||
195 | # define LOAD_PIC_REG_STR(reg) \ | |
196 | SETUP_PIC_REG_STR (reg) "\naddl $_GLOBAL_OFFSET_TABLE_, %%e" #reg | |
197 | ||
66715f83 | 198 | #endif /* __ASSEMBLER__ */ |