sysv4.h revision 50397
155714Skris/* Target definitions for GNU compiler for Intel 80386 running System V.4
255714Skris   Copyright (C) 1991 Free Software Foundation, Inc.
355714Skris
455714Skris   Written by Ron Guilmette (rfg@netcom.com).
555714Skris
655714SkrisThis file is part of GNU CC.
755714Skris
855714SkrisGNU CC is free software; you can redistribute it and/or modify
955714Skrisit under the terms of the GNU General Public License as published by
1055714Skristhe Free Software Foundation; either version 2, or (at your option)
1155714Skrisany later version.
1255714Skris
1355714SkrisGNU CC is distributed in the hope that it will be useful,
1455714Skrisbut WITHOUT ANY WARRANTY; without even the implied warranty of
1555714SkrisMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1655714SkrisGNU General Public License for more details.
1755714Skris
1855714SkrisYou should have received a copy of the GNU General Public License
1955714Skrisalong with GNU CC; see the file COPYING.  If not, write to
2055714Skristhe Free Software Foundation, 59 Temple Place - Suite 330,
2155714SkrisBoston, MA 02111-1307, USA.  */
2255714Skris
2355714Skris#include "i386/i386.h"	/* Base i386 target machine definitions */
2455714Skris#include "i386/att.h"	/* Use the i386 AT&T assembler syntax */
2555714Skris#include "svr4.h"	/* Definitions common to all SVR4 targets */
2655714Skris
2755714Skris#undef TARGET_VERSION
2855714Skris#define TARGET_VERSION fprintf (stderr, " (i386 System V Release 4)");
2955714Skris
3055714Skris/* The svr4 ABI for the i386 says that records and unions are returned
3155714Skris   in memory.  */
3255714Skris
3355714Skris#undef RETURN_IN_MEMORY
3455714Skris#define RETURN_IN_MEMORY(TYPE) \
3555714Skris  (TYPE_MODE (TYPE) == BLKmode)
3655714Skris
3755714Skris/* Define which macros to predefine.  __svr4__ is our extension.  */
3855714Skris/* This used to define X86, but james@bigtex.cactus.org says that
3955714Skris   is supposed to be defined optionally by user programs--not by default.  */
4055714Skris#define CPP_PREDEFINES \
4155714Skris  "-Di386 -Dunix -D__svr4__ -Asystem(unix) -Asystem(svr4) -Acpu(i386) -Amachine(i386)"
4255714Skris
4355714Skris/* This is how to output assembly code to define a `float' constant.
4455714Skris   We always have to use a .long pseudo-op to do this because the native
4555714Skris   SVR4 ELF assembler is buggy and it generates incorrect values when we
4655714Skris   try to use the .float pseudo-op instead.  */
4755714Skris
4855714Skris#undef ASM_OUTPUT_FLOAT
4955714Skris#define ASM_OUTPUT_FLOAT(FILE,VALUE)					\
5055714Skrisdo { long value;							\
5155714Skris     REAL_VALUE_TO_TARGET_SINGLE ((VALUE), value);			\
5255714Skris     if (sizeof (int) == sizeof (long))					\
5355714Skris         fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value);		\
5455714Skris     else								\
5555714Skris         fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value);		\
5655714Skris   } while (0)
5755714Skris
5855714Skris/* This is how to output assembly code to define a `double' constant.
5955714Skris   We always have to use a pair of .long pseudo-ops to do this because
6055714Skris   the native SVR4 ELF assembler is buggy and it generates incorrect
6155714Skris   values when we try to use the .double pseudo-op instead.  */
6255714Skris
6355714Skris#undef ASM_OUTPUT_DOUBLE
6455714Skris#define ASM_OUTPUT_DOUBLE(FILE,VALUE)					\
6555714Skrisdo { long value[2];							\
6655714Skris     REAL_VALUE_TO_TARGET_DOUBLE ((VALUE), value);			\
6755714Skris     if (sizeof (int) == sizeof (long))					\
6855714Skris       {								\
6955714Skris         fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[0]);		\
7055714Skris         fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[1]);		\
7155714Skris       }								\
7255714Skris     else								\
7355714Skris       {								\
7455714Skris         fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[0]);		\
7555714Skris         fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[1]);		\
7655714Skris       }								\
7755714Skris   } while (0)
7855714Skris
7955714Skris
8055714Skris#undef ASM_OUTPUT_LONG_DOUBLE
8155714Skris#define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE)				\
8255714Skrisdo { long value[3];							\
8355714Skris     REAL_VALUE_TO_TARGET_LONG_DOUBLE ((VALUE), value);			\
8455714Skris     if (sizeof (int) == sizeof (long))					\
8555714Skris       {								\
8655714Skris         fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[0]);		\
8755714Skris         fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[1]);		\
8855714Skris         fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[2]);		\
8955714Skris       }								\
9055714Skris     else								\
9155714Skris       {								\
9255714Skris         fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[0]);		\
9355714Skris         fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[1]);		\
9455714Skris         fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[2]);		\
9555714Skris       }								\
9655714Skris   } while (0)
9755714Skris
9855714Skris/* Output at beginning of assembler file.  */
9955714Skris/* The .file command should always begin the output.  */
10055714Skris
10155714Skris#undef ASM_FILE_START
10255714Skris#define ASM_FILE_START(FILE)						\
10355714Skris  do {									\
10455714Skris	output_file_directive (FILE, main_input_filename);		\
10555714Skris	fprintf (FILE, "\t.version\t\"01.01\"\n");			\
10655714Skris  } while (0)
10755714Skris
10855714Skris/* Define the register numbers to be used in Dwarf debugging information.
10955714Skris   The SVR4 reference port C compiler uses the following register numbers
11055714Skris   in its Dwarf output code:
11155714Skris
11255714Skris	0 for %eax (gnu regno = 0)
11355714Skris	1 for %ecx (gnu regno = 2)
11455714Skris	2 for %edx (gnu regno = 1)
11555714Skris	3 for %ebx (gnu regno = 3)
11655714Skris	4 for %esp (gnu regno = 7)
11755714Skris	5 for %ebp (gnu regno = 6)
11855714Skris	6 for %esi (gnu regno = 4)
11955714Skris	7 for %edi (gnu regno = 5)
12055714Skris
12155714Skris   The following three DWARF register numbers are never generated by
12255714Skris   the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
12355714Skris   believes these numbers have these meanings.
12455714Skris
12555714Skris	8  for %eip    (no gnu equivalent)
12655714Skris	9  for %eflags (no gnu equivalent)
12755714Skris	10 for %trapno (no gnu equivalent)
12855714Skris
12955714Skris   It is not at all clear how we should number the FP stack registers
13055714Skris   for the x86 architecture.  If the version of SDB on x86/svr4 were
13155714Skris   a bit less brain dead with respect to floating-point then we would
13255714Skris   have a precedent to follow with respect to DWARF register numbers
13355714Skris   for x86 FP registers, but the SDB on x86/svr4 is so completely
13455714Skris   broken with respect to FP registers that it is hardly worth thinking
13555714Skris   of it as something to strive for compatibility with.
13655714Skris
13755714Skris   The version of x86/svr4 SDB I have at the moment does (partially)
13855714Skris   seem to believe that DWARF register number 11 is associated with
13955714Skris   the x86 register %st(0), but that's about all.  Higher DWARF
14055714Skris   register numbers don't seem to be associated with anything in
14155714Skris   particular, and even for DWARF regno 11, SDB only seems to under-
14255714Skris   stand that it should say that a variable lives in %st(0) (when
14355714Skris   asked via an `=' command) if we said it was in DWARF regno 11,
14455714Skris   but SDB still prints garbage when asked for the value of the
14555714Skris   variable in question (via a `/' command).
14655714Skris
14755714Skris   (Also note that the labels SDB prints for various FP stack regs
14855714Skris   when doing an `x' command are all wrong.)
14955714Skris
15055714Skris   Note that these problems generally don't affect the native SVR4
15155714Skris   C compiler because it doesn't allow the use of -O with -g and
15255714Skris   because when it is *not* optimizing, it allocates a memory
15355714Skris   location for each floating-point variable, and the memory
15455714Skris   location is what gets described in the DWARF AT_location
15555714Skris   attribute for the variable in question.
15655714Skris
15755714Skris   Regardless of the severe mental illness of the x86/svr4 SDB, we
15855714Skris   do something sensible here and we use the following DWARF
15955714Skris   register numbers.  Note that these are all stack-top-relative
16055714Skris   numbers.
16155714Skris
16255714Skris	11 for %st(0) (gnu regno = 8)
16355714Skris	12 for %st(1) (gnu regno = 9)
16455714Skris	13 for %st(2) (gnu regno = 10)
16555714Skris	14 for %st(3) (gnu regno = 11)
16655714Skris	15 for %st(4) (gnu regno = 12)
16755714Skris	16 for %st(5) (gnu regno = 13)
16855714Skris	17 for %st(6) (gnu regno = 14)
16955714Skris	18 for %st(7) (gnu regno = 15)
17055714Skris*/
17155714Skris
17255714Skris#undef DBX_REGISTER_NUMBER
17355714Skris#define DBX_REGISTER_NUMBER(n) \
17455714Skris((n) == 0 ? 0 \
17555714Skris : (n) == 1 ? 2 \
17655714Skris : (n) == 2 ? 1 \
17755714Skris : (n) == 3 ? 3 \
17855714Skris : (n) == 4 ? 6 \
17955714Skris : (n) == 5 ? 7 \
18055714Skris : (n) == 6 ? 5 \
18155714Skris : (n) == 7 ? 4 \
18255714Skris : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \
18355714Skris : (-1))
18455714Skris
18555714Skris/* The routine used to output sequences of byte values.  We use a special
18655714Skris   version of this for most svr4 targets because doing so makes the
18755714Skris   generated assembly code more compact (and thus faster to assemble)
18855714Skris   as well as more readable.  Note that if we find subparts of the
18955714Skris   character sequence which end with NUL (and which are shorter than
19055714Skris   STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING.  */
19155714Skris
19255714Skris#undef ASM_OUTPUT_ASCII
19355714Skris#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH)				\
19455714Skris  do									\
19555714Skris    {									\
19655714Skris      register unsigned char *_ascii_bytes = (unsigned char *) (STR);	\
19755714Skris      register unsigned char *limit = _ascii_bytes + (LENGTH);		\
19855714Skris      register unsigned bytes_in_chunk = 0;				\
19955714Skris      for (; _ascii_bytes < limit; _ascii_bytes++)			\
20055714Skris        {								\
20155714Skris	  register unsigned char *p;					\
20255714Skris	  if (bytes_in_chunk >= 64)					\
20355714Skris	    {								\
20455714Skris	      fputc ('\n', (FILE));					\
20555714Skris	      bytes_in_chunk = 0;					\
20655714Skris	    }								\
20755714Skris	  for (p = _ascii_bytes; p < limit && *p != '\0'; p++)		\
20855714Skris	    continue;							\
20955714Skris	  if (p < limit && (p - _ascii_bytes) <= STRING_LIMIT)		\
21055714Skris	    {								\
21155714Skris	      if (bytes_in_chunk > 0)					\
21255714Skris		{							\
21355714Skris		  fputc ('\n', (FILE));					\
21455714Skris		  bytes_in_chunk = 0;					\
21555714Skris		}							\
21655714Skris	      ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes);		\
21755714Skris	      _ascii_bytes = p;						\
21855714Skris	    }								\
21955714Skris	  else								\
22055714Skris	    {								\
22155714Skris	      if (bytes_in_chunk == 0)					\
22255714Skris		fprintf ((FILE), "\t.byte\t");				\
22355714Skris	      else							\
22455714Skris		fputc (',', (FILE));					\
22555714Skris	      fprintf ((FILE), "0x%02x", *_ascii_bytes);		\
22655714Skris	      bytes_in_chunk += 5;					\
22755714Skris	    }								\
22855714Skris	}								\
22955714Skris      if (bytes_in_chunk > 0)						\
23055714Skris        fprintf ((FILE), "\n");						\
23155714Skris    }									\
23255714Skris  while (0)
23355714Skris
23455714Skris/* This is how to output an element of a case-vector that is relative.
23555714Skris   This is only used for PIC code.  See comments by the `casesi' insn in
23655714Skris   i386.md for an explanation of the expression this outputs. */
23755714Skris
23855714Skris#undef ASM_OUTPUT_ADDR_DIFF_ELT
23955714Skris#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \
24055714Skris  fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE)
24155714Skris
24255714Skris/* Indicate that jump tables go in the text section.  This is
24355714Skris   necessary when compiling PIC code.  */
24455714Skris
24555714Skris#define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)
24655714Skris
24755714Skris/* A C statement (sans semicolon) to output to the stdio stream
24855714Skris   FILE the assembler definition of uninitialized global DECL named
24955714Skris   NAME whose size is SIZE bytes and alignment is ALIGN bytes.
25055714Skris   Try to use asm_output_aligned_bss to implement this macro.  */
25155714Skris
25255714Skris#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
25355714Skris  asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
25455714Skris