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