linux.h revision 52284
1155408Srwatson/* Definitions for Intel 386 running Linux-based GNU systems with ELF format.
2155408Srwatson   Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3155408Srwatson   Contributed by Eric Youngdale.
4155408Srwatson   Modified for stabs-in-ELF by H.J. Lu.
5155408Srwatson
6155408SrwatsonThis file is part of GNU CC.
7155408Srwatson
8155408SrwatsonGNU CC is free software; you can redistribute it and/or modify
9155408Srwatsonit under the terms of the GNU General Public License as published by
10155408Srwatsonthe Free Software Foundation; either version 2, or (at your option)
11155408Srwatsonany later version.
12155408Srwatson
13155408SrwatsonGNU CC is distributed in the hope that it will be useful,
14155408Srwatsonbut WITHOUT ANY WARRANTY; without even the implied warranty of
15155408SrwatsonMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16155408SrwatsonGNU General Public License for more details.
17155408Srwatson
18155408SrwatsonYou should have received a copy of the GNU General Public License
19155408Srwatsonalong with GNU CC; see the file COPYING.  If not, write to
20155408Srwatsonthe Free Software Foundation, 59 Temple Place - Suite 330,
21155408SrwatsonBoston, MA 02111-1307, USA.  */
22155408Srwatson
23155408Srwatson#define LINUX_DEFAULT_ELF
24155408Srwatson
25155408Srwatson/* A lie, I guess, but the general idea behind linux/ELF is that we are
26155408Srwatson   supposed to be outputting something that will assemble under SVr4.
27155408Srwatson   This gets us pretty close.  */
28155408Srwatson#include <i386/i386.h>	/* Base i386 target machine definitions */
29155408Srwatson#include <i386/att.h>	/* Use the i386 AT&T assembler syntax */
30155408Srwatson#include <linux.h>	/* some common stuff */
31155408Srwatson
32155408Srwatson#undef TARGET_VERSION
33155408Srwatson#define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)");
34155408Srwatson
35155408Srwatson/* The svr4 ABI for the i386 says that records and unions are returned
36155408Srwatson   in memory.  */
37155408Srwatson#undef DEFAULT_PCC_STRUCT_RETURN
38155408Srwatson#define DEFAULT_PCC_STRUCT_RETURN 1
39155408Srwatson
40155408Srwatson#undef ASM_COMMENT_START
41155408Srwatson#define ASM_COMMENT_START "#"
42155408Srwatson
43155408Srwatson/* This is how to output an element of a case-vector that is relative.
44155408Srwatson   This is only used for PIC code.  See comments by the `casesi' insn in
45155408Srwatson   i386.md for an explanation of the expression this outputs. */
46155408Srwatson#undef ASM_OUTPUT_ADDR_DIFF_ELT
47155408Srwatson#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
48155408Srwatson  fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE)
49155408Srwatson
50155408Srwatson/* Indicate that jump tables go in the text section.  This is
51156880Srwatson   necessary when compiling PIC code.  */
52155408Srwatson#define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)
53155408Srwatson
54155408Srwatson/* Copy this from the svr4 specifications... */
55155408Srwatson/* Define the register numbers to be used in Dwarf debugging information.
56155408Srwatson   The SVR4 reference port C compiler uses the following register numbers
57155408Srwatson   in its Dwarf output code:
58155408Srwatson	0 for %eax (gnu regno = 0)
59155408Srwatson	1 for %ecx (gnu regno = 2)
60155408Srwatson	2 for %edx (gnu regno = 1)
61155408Srwatson	3 for %ebx (gnu regno = 3)
62155408Srwatson	4 for %esp (gnu regno = 7)
63155408Srwatson	5 for %ebp (gnu regno = 6)
64155408Srwatson	6 for %esi (gnu regno = 4)
65155408Srwatson	7 for %edi (gnu regno = 5)
66155408Srwatson   The following three DWARF register numbers are never generated by
67155408Srwatson   the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
68155408Srwatson   believes these numbers have these meanings.
69155408Srwatson	8  for %eip    (no gnu equivalent)
70155408Srwatson	9  for %eflags (no gnu equivalent)
71156883Srwatson	10 for %trapno (no gnu equivalent)
72156880Srwatson   It is not at all clear how we should number the FP stack registers
73155408Srwatson   for the x86 architecture.  If the version of SDB on x86/svr4 were
74155408Srwatson   a bit less brain dead with respect to floating-point then we would
75155408Srwatson   have a precedent to follow with respect to DWARF register numbers
76155408Srwatson   for x86 FP registers, but the SDB on x86/svr4 is so completely
77155408Srwatson   broken with respect to FP registers that it is hardly worth thinking
78155408Srwatson   of it as something to strive for compatibility with.
79155408Srwatson   The version of x86/svr4 SDB I have at the moment does (partially)
80155408Srwatson   seem to believe that DWARF register number 11 is associated with
81155408Srwatson   the x86 register %st(0), but that's about all.  Higher DWARF
82155408Srwatson   register numbers don't seem to be associated with anything in
83155408Srwatson   particular, and even for DWARF regno 11, SDB only seems to under-
84155408Srwatson   stand that it should say that a variable lives in %st(0) (when
85155408Srwatson   asked via an `=' command) if we said it was in DWARF regno 11,
86155408Srwatson   but SDB still prints garbage when asked for the value of the
87155408Srwatson   variable in question (via a `/' command).
88155408Srwatson   (Also note that the labels SDB prints for various FP stack regs
89155408Srwatson   when doing an `x' command are all wrong.)
90155408Srwatson   Note that these problems generally don't affect the native SVR4
91155408Srwatson   C compiler because it doesn't allow the use of -O with -g and
92155408Srwatson   because when it is *not* optimizing, it allocates a memory
93155408Srwatson   location for each floating-point variable, and the memory
94155408Srwatson   location is what gets described in the DWARF AT_location
95155408Srwatson   attribute for the variable in question.
96155408Srwatson   Regardless of the severe mental illness of the x86/svr4 SDB, we
97155408Srwatson   do something sensible here and we use the following DWARF
98155408Srwatson   register numbers.  Note that these are all stack-top-relative
99155408Srwatson   numbers.
100155408Srwatson	11 for %st(0) (gnu regno = 8)
101155408Srwatson	12 for %st(1) (gnu regno = 9)
102155408Srwatson	13 for %st(2) (gnu regno = 10)
103155408Srwatson	14 for %st(3) (gnu regno = 11)
104155408Srwatson	15 for %st(4) (gnu regno = 12)
105155408Srwatson	16 for %st(5) (gnu regno = 13)
106155408Srwatson	17 for %st(6) (gnu regno = 14)
107155408Srwatson	18 for %st(7) (gnu regno = 15)
108155408Srwatson*/
109155408Srwatson#undef DBX_REGISTER_NUMBER
110155408Srwatson#define DBX_REGISTER_NUMBER(n) \
111155408Srwatson((n) == 0 ? 0 \
112155408Srwatson : (n) == 1 ? 2 \
113155408Srwatson : (n) == 2 ? 1 \
114155408Srwatson : (n) == 3 ? 3 \
115155408Srwatson : (n) == 4 ? 6 \
116155408Srwatson : (n) == 5 ? 7 \
117155408Srwatson : (n) == 6 ? 5 \
118155408Srwatson : (n) == 7 ? 4 \
119155408Srwatson : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \
120155408Srwatson : (-1))
121155408Srwatson
122155408Srwatson/* Output assembler code to FILE to increment profiler label # LABELNO
123155408Srwatson   for profiling a function entry.  */
124155408Srwatson
125155408Srwatson#undef FUNCTION_PROFILER
126155408Srwatson#define FUNCTION_PROFILER(FILE, LABELNO)  \
127155408Srwatson{									\
128155408Srwatson  if (flag_pic)								\
129155408Srwatson    {									\
130155408Srwatson      fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n",		\
131155408Srwatson	       LPREFIX, (LABELNO));					\
132155408Srwatson      fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n");			\
133155408Srwatson    }									\
134155408Srwatson  else									\
135155408Srwatson    {									\
136155408Srwatson      fprintf (FILE, "\tmovl $%sP%d,%%edx\n", LPREFIX, (LABELNO));	\
137155408Srwatson      fprintf (FILE, "\tcall mcount\n");				\
138155408Srwatson    }									\
139155408Srwatson}
140155408Srwatson
141155408Srwatson#undef SIZE_TYPE
142155408Srwatson#define SIZE_TYPE "unsigned int"
143155408Srwatson
144155408Srwatson#undef PTRDIFF_TYPE
145155408Srwatson#define PTRDIFF_TYPE "int"
146155408Srwatson
147155408Srwatson#undef WCHAR_TYPE
148155408Srwatson#define WCHAR_TYPE "long int"
149155408Srwatson
150155408Srwatson#undef WCHAR_TYPE_SIZE
151155408Srwatson#define WCHAR_TYPE_SIZE BITS_PER_WORD
152155408Srwatson
153155408Srwatson#undef CPP_PREDEFINES
154155408Srwatson#define CPP_PREDEFINES "-D__ELF__ -Dunix -D__i386__ -Dlinux -Asystem(posix)"
155155408Srwatson
156155408Srwatson#undef CPP_SPEC
157155408Srwatson#ifdef USE_GNULIBC_1
158155408Srwatson#define CPP_SPEC "%(cpp_cpu) %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE}"
159155408Srwatson#else
160155408Srwatson#define CPP_SPEC "%(cpp_cpu) %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
161155408Srwatson#endif
162155408Srwatson
163155408Srwatson#undef CC1_SPEC
164155408Srwatson#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
165155408Srwatson
166155408Srwatson/* Provide a LINK_SPEC appropriate for Linux.  Here we provide support
167155408Srwatson   for the special GCC options -static and -shared, which allow us to
168155408Srwatson   link things in one of these three modes by applying the appropriate
169155408Srwatson   combinations of options at link-time. We like to support here for
170155408Srwatson   as many of the other GNU linker options as possible. But I don't
171155408Srwatson   have the time to search for those flags. I am sure how to add
172155408Srwatson   support for -soname shared_object_name. H.J.
173155408Srwatson
174155408Srwatson   I took out %{v:%{!V:-V}}. It is too much :-(. They can use
175155408Srwatson   -Wl,-V.
176155408Srwatson
177155408Srwatson   When the -shared link option is used a final link is not being
178155408Srwatson   done.  */
179155408Srwatson
180155408Srwatson/* If ELF is the default format, we should not use /lib/elf. */
181155408Srwatson
182155408Srwatson#undef	LINK_SPEC
183155408Srwatson#ifdef USE_GNULIBC_1
184155408Srwatson#ifndef LINUX_DEFAULT_ELF
185156292Srwatson#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
186155408Srwatson  %{!shared: \
187155408Srwatson    %{!ibcs: \
188155408Srwatson      %{!static: \
189155408Srwatson	%{rdynamic:-export-dynamic} \
190155408Srwatson	%{!dynamic-linker:-dynamic-linker /lib/elf/ld-linux.so.1} \
191155408Srwatson	%{!rpath:-rpath /lib/elf/}} %{static:-static}}}"
192155408Srwatson#else
193155408Srwatson#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
194155408Srwatson  %{!shared: \
195155408Srwatson    %{!ibcs: \
196155408Srwatson      %{!static: \
197155408Srwatson	%{rdynamic:-export-dynamic} \
198155408Srwatson	%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \
199155408Srwatson	%{static:-static}}}"
200155408Srwatson#endif
201155408Srwatson#else
202155408Srwatson#define LINK_SPEC "-m elf_i386 %{shared:-shared} \
203155408Srwatson  %{!shared: \
204155428Srwatson    %{!ibcs: \
205155408Srwatson      %{!static: \
206155408Srwatson	%{rdynamic:-export-dynamic} \
207155408Srwatson	%{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.2}} \
208155408Srwatson	%{static:-static}}}"
209155408Srwatson#endif
210155408Srwatson
211155408Srwatson/* Get perform_* macros to build libgcc.a.  */
212155408Srwatson#include "i386/perform.h"
213155408Srwatson
214155408Srwatson/* A C statement (sans semicolon) to output to the stdio stream
215155408Srwatson   FILE the assembler definition of uninitialized global DECL named
216155408Srwatson   NAME whose size is SIZE bytes and alignment is ALIGN bytes.
217155408Srwatson   Try to use asm_output_aligned_bss to implement this macro.  */
218155408Srwatson
219155408Srwatson#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
220155408Srwatson  asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
221155408Srwatson
222155408Srwatson/* A C statement to output to the stdio stream FILE an assembler
223155408Srwatson   command to advance the location counter to a multiple of 1<<LOG
224155408Srwatson   bytes if it is within MAX_SKIP bytes.
225155408Srwatson
226155408Srwatson   This is used to align code labels according to Intel recommendations.  */
227155408Srwatson
228155408Srwatson#ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
229155408Srwatson#define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP)			\
230155408Srwatson  do {									\
231155408Srwatson    if ((LOG) != 0) {							\
232155408Srwatson      if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG));	\
233155408Srwatson      else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP));	\
234155408Srwatson    }									\
235155408Srwatson  } while (0)
236155408Srwatson#endif
237155408Srwatson