1132718Skan/* Target definitions for GCC for Intel 80386 running Interix
2132718Skan   Parts Copyright (C) 1991, 1999, 2000, 2002, 2003, 2004
3132718Skan   Free Software Foundation, Inc.
452284Sobrien
552284Sobrien   Parts:
652284Sobrien     by Douglas B. Rupp (drupp@cs.washington.edu).
752284Sobrien     by Ron Guilmette (rfg@netcom.com).
852284Sobrien     by Donn Terry (donn@softway.com).
952284Sobrien     by Mumit Khan (khan@xraylith.wisc.edu).
1052284Sobrien
11132718SkanThis file is part of GCC.
1252284Sobrien
13132718SkanGCC is free software; you can redistribute it and/or modify
1452284Sobrienit under the terms of the GNU General Public License as published by
1552284Sobrienthe Free Software Foundation; either version 2, or (at your option)
1652284Sobrienany later version.
1752284Sobrien
18132718SkanGCC is distributed in the hope that it will be useful,
1952284Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
2052284SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2152284SobrienGNU General Public License for more details.
2252284Sobrien
2352284SobrienYou should have received a copy of the GNU General Public License
24132718Skanalong with GCC; see the file COPYING.  If not, write to
25169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
26169689SkanBoston, MA 02110-1301, USA.  */
2752284Sobrien
2890075Sobrien/* The rest must follow.  */
2952284Sobrien
30117395Skan#define DBX_DEBUGGING_INFO 1
31117395Skan#define SDB_DEBUGGING_INFO 1
3252284Sobrien#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
3352284Sobrien
34117395Skan#define HANDLE_SYSV_PRAGMA 1
3552284Sobrien#undef HANDLE_PRAGMA_WEAK  /* until the link format can handle it */
3652284Sobrien
3752284Sobrien/* By default, target has a 80387, uses IEEE compatible arithmetic,
3852284Sobrien   and returns float values in the 387 and needs stack probes
39132718Skan   We also align doubles to 64-bits for MSVC default compatibility
40132718Skan   We do bitfields MSVC-compatibly by default, too.  */
4190075Sobrien#undef TARGET_SUBTARGET_DEFAULT
4290075Sobrien#define TARGET_SUBTARGET_DEFAULT \
4352284Sobrien   (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_STACK_PROBE | \
44132718Skan    MASK_ALIGN_DOUBLE | MASK_MS_BITFIELD_LAYOUT)
4552284Sobrien
4652284Sobrien#undef TARGET_CPU_DEFAULT
4752284Sobrien#define TARGET_CPU_DEFAULT 2 /* 486 */
4852284Sobrien
4952284Sobrien#define WCHAR_TYPE_SIZE 16
5052284Sobrien#define WCHAR_TYPE "short unsigned int"
5152284Sobrien
5252284Sobrien/* WinNT (and thus Interix) use unsigned int */
5352284Sobrien#define SIZE_TYPE "unsigned int"
5452284Sobrien
5552284Sobrien#define ASM_LOAD_ADDR(loc, reg)   "     leal " #loc "," #reg "\n"
5652284Sobrien
57169689Skan#define TARGET_DECLSPEC 1
58169689Skan
5952284Sobrien/* cpp handles __STDC__ */
60117395Skan#define TARGET_OS_CPP_BUILTINS()					\
61117395Skan  do									\
62117395Skan    {									\
63117395Skan	builtin_define ("__INTERIX");					\
64117395Skan	builtin_define ("__OPENNT");					\
65117395Skan	builtin_define ("_M_IX86=300");					\
66117395Skan	builtin_define ("_X86_=1");					\
67117395Skan	builtin_define ("__stdcall=__attribute__((__stdcall__))");	\
68117395Skan	builtin_define ("__cdecl=__attribute__((__cdecl__))");		\
69117395Skan	builtin_assert ("system=unix");					\
70117395Skan	builtin_assert ("system=interix");				\
71117395Skan	if (preprocessing_asm_p ())					\
72117395Skan	  builtin_define_std ("LANGUAGE_ASSEMBLY");			\
73117395Skan	else								\
74117395Skan	  {								\
75117395Skan	     builtin_define_std ("LANGUAGE_C");				\
76132718Skan	     if (c_dialect_cxx ())					\
77117395Skan	       builtin_define_std ("LANGUAGE_C_PLUS_PLUS");		\
78132718Skan	     if (c_dialect_objc ())					\
79117395Skan	       builtin_define_std ("LANGUAGE_OBJECTIVE_C");		\
80117395Skan	  } 								\
81117395Skan    }									\
82117395Skan  while (0)
8352284Sobrien
8452284Sobrien#undef CPP_SPEC
8552284Sobrien/* Write out the correct language type definition for the header files.
8652284Sobrien   Unless we have assembler language, write out the symbols for C.
87169689Skan   mieee is an Alpha specific variant.  Cross pollination a bad idea.
8852284Sobrien   */
89117395Skan#define CPP_SPEC "-remap %{posix:-D_POSIX_SOURCE} \
9090075Sobrien-isystem %$INTERIX_ROOT/usr/include"
9152284Sobrien
9252284Sobrien#define TARGET_VERSION fprintf (stderr, " (i386 Interix)");
9352284Sobrien
9452284Sobrien/* The global __fltused is necessary to cause the printf/scanf routines
9552284Sobrien   for outputting/inputting floating point numbers to be loaded.  Since this
9690075Sobrien   is kind of hard to detect, we just do it all the time.  */
97132718Skan#undef X86_FILE_START_FLTUSED
98132718Skan#define X86_FILE_START_FLTUSED 1
9952284Sobrien
10052284Sobrien/* A table of bytes codes used by the ASM_OUTPUT_ASCII and
10152284Sobrien   ASM_OUTPUT_LIMITED_STRING macros.  Each byte in the table
10252284Sobrien   corresponds to a particular byte value [0..255].  For any
10352284Sobrien   given byte value, if the value in the corresponding table
10452284Sobrien   position is zero, the given character can be output directly.
10552284Sobrien   If the table value is 1, the byte must be output as a \ooo
10652284Sobrien   octal escape.  If the tables value is anything else, then the
10752284Sobrien   byte value should be output as a \ followed by the value
10852284Sobrien   in the table.  Note that we can use standard UN*X escape
10952284Sobrien   sequences for many control characters, but we don't use
11052284Sobrien   \a to represent BEL because some svr4 assemblers (e.g. on
11152284Sobrien   the i386) don't know about that.  Also, we don't use \v
11252284Sobrien   since some versions of gas, such as 2.2 did not accept it.  */
11352284Sobrien
11452284Sobrien#define ESCAPES \
11552284Sobrien"\1\1\1\1\1\1\1\1btn\1fr\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
11652284Sobrien\0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
11752284Sobrien\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0\
11852284Sobrien\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\
11952284Sobrien\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
12052284Sobrien\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
12152284Sobrien\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
12252284Sobrien\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"
12352284Sobrien
12452284Sobrien/* Some svr4 assemblers have a limit on the number of characters which
12552284Sobrien   can appear in the operand of a .string directive.  If your assembler
12652284Sobrien   has such a limitation, you should define STRING_LIMIT to reflect that
12752284Sobrien   limit.  Note that at least some svr4 assemblers have a limit on the
12852284Sobrien   actual number of bytes in the double-quoted string, and that they
12952284Sobrien   count each character in an escape sequence as one byte.  Thus, an
13052284Sobrien   escape sequence like \377 would count as four bytes.
13152284Sobrien
13252284Sobrien   If your target assembler doesn't support the .string directive, you
13352284Sobrien   should define this to zero.
13452284Sobrien*/
13552284Sobrien
13652284Sobrien#define STRING_LIMIT	((unsigned) 256)
13752284Sobrien
13890075Sobrien#define STRING_ASM_OP	"\t.string\t"
13952284Sobrien
14052284Sobrien/* The routine used to output NUL terminated strings.  We use a special
14152284Sobrien   version of this for most svr4 targets because doing so makes the
14252284Sobrien   generated assembly code more compact (and thus faster to assemble)
14352284Sobrien   as well as more readable, especially for targets like the i386
14452284Sobrien   (where the only alternative is to output character sequences as
145132718Skan   comma separated lists of numbers).  */
14652284Sobrien
14752284Sobrien#define ASM_OUTPUT_LIMITED_STRING(FILE, STR)				\
14852284Sobrien  do									\
14952284Sobrien    {									\
150132718Skan      const unsigned char *_limited_str =				\
15190075Sobrien        (const unsigned char *) (STR);					\
152132718Skan      unsigned ch;							\
15390075Sobrien      fprintf ((FILE), "%s\"", STRING_ASM_OP);				\
15452284Sobrien      for (; (ch = *_limited_str); _limited_str++)			\
15552284Sobrien        {								\
156132718Skan	  int escape = ESCAPES[ch];					\
15752284Sobrien	  switch (escape)						\
15852284Sobrien	    {								\
15952284Sobrien	    case 0:							\
16052284Sobrien	      putc (ch, (FILE));					\
16152284Sobrien	      break;							\
16252284Sobrien	    case 1:							\
16352284Sobrien	      fprintf ((FILE), "\\%03o", ch);				\
16452284Sobrien	      break;							\
16552284Sobrien	    default:							\
16652284Sobrien	      putc ('\\', (FILE));					\
16752284Sobrien	      putc (escape, (FILE));					\
16852284Sobrien	      break;							\
16952284Sobrien	    }								\
17052284Sobrien        }								\
17152284Sobrien      fprintf ((FILE), "\"\n");						\
17252284Sobrien    }									\
17352284Sobrien  while (0)
17452284Sobrien
17552284Sobrien/* The routine used to output sequences of byte values.  We use a special
17652284Sobrien   version of this for most svr4 targets because doing so makes the
17752284Sobrien   generated assembly code more compact (and thus faster to assemble)
17852284Sobrien   as well as more readable.  Note that if we find subparts of the
17952284Sobrien   character sequence which end with NUL (and which are shorter than
18052284Sobrien   STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING.  */
18152284Sobrien
18252284Sobrien#undef ASM_OUTPUT_ASCII
18352284Sobrien#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH)				\
18452284Sobrien  do									\
18552284Sobrien    {									\
186132718Skan      const unsigned char *_ascii_bytes =				\
18790075Sobrien        (const unsigned char *) (STR);					\
188132718Skan      const unsigned char *limit = _ascii_bytes + (LENGTH);		\
189132718Skan      unsigned bytes_in_chunk = 0;					\
19052284Sobrien      for (; _ascii_bytes < limit; _ascii_bytes++)			\
19152284Sobrien        {								\
192132718Skan	  const unsigned char *p;					\
19352284Sobrien	  if (bytes_in_chunk >= 64)					\
19452284Sobrien	    {								\
19552284Sobrien	      fputc ('\n', (FILE));					\
19652284Sobrien	      bytes_in_chunk = 0;					\
19752284Sobrien	    }								\
19852284Sobrien	  for (p = _ascii_bytes; p < limit && *p != '\0'; p++)		\
19952284Sobrien	    continue;							\
20090075Sobrien	  if (p < limit && (p - _ascii_bytes) <= (long) STRING_LIMIT)	\
20152284Sobrien	    {								\
20252284Sobrien	      if (bytes_in_chunk > 0)					\
20352284Sobrien		{							\
20452284Sobrien		  fputc ('\n', (FILE));					\
20552284Sobrien		  bytes_in_chunk = 0;					\
20652284Sobrien		}							\
20752284Sobrien	      ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes);		\
20852284Sobrien	      _ascii_bytes = p;						\
20952284Sobrien	    }								\
21052284Sobrien	  else								\
21152284Sobrien	    {								\
21252284Sobrien	      if (bytes_in_chunk == 0)					\
21352284Sobrien		fprintf ((FILE), "\t.byte\t");				\
21452284Sobrien	      else							\
21552284Sobrien		fputc (',', (FILE));					\
21652284Sobrien	      fprintf ((FILE), "0x%02x", *_ascii_bytes);		\
21752284Sobrien	      bytes_in_chunk += 5;					\
21852284Sobrien	    }								\
21952284Sobrien	}								\
22052284Sobrien      if (bytes_in_chunk > 0)						\
22152284Sobrien        fprintf ((FILE), "\n");						\
22252284Sobrien    }									\
22352284Sobrien  while (0)
22452284Sobrien
22552284Sobrien/* Emit code to check the stack when allocating more that 4000
22690075Sobrien   bytes in one go.  */
22752284Sobrien
22852284Sobrien#define CHECK_STACK_LIMIT 0x1000
22952284Sobrien
23052284Sobrien/* the following are OSF linker (not gld) specific... we don't want them */
23152284Sobrien#undef HAS_INIT_SECTION
23252284Sobrien#undef LD_INIT_SWITCH
23352284Sobrien#undef LD_FINI_SWITCH
23452284Sobrien
235117395Skan/* The following are needed for us to be able to use winnt.c, but are not
236117395Skan   otherwise meaningful to Interix.  (The functions that use these are
237117395Skan   never called because we don't do DLLs.) */
238117395Skan#define TARGET_NOP_FUN_DLLIMPORT 1
239117395Skan#define drectve_section()  /* nothing */
240117395Skan
241132718Skan/* Objective-C has its own packing rules...
242132718Skan   Objc tries to parallel the code in stor-layout.c at runtime
243132718Skan   (see libobjc/encoding.c).  This (compile-time) packing info isn't
244132718Skan   available at runtime, so it's hopeless to try.
245132718Skan
246132718Skan   And if the user tries to set the flag for objc, give an error
247132718Skan   so he has some clue.  */
248132718Skan
249132718Skan#undef  SUBTARGET_OVERRIDE_OPTIONS
250132718Skan#define SUBTARGET_OVERRIDE_OPTIONS					\
251132718Skando {									\
252132718Skan  if (strcmp (lang_hooks.name, "GNU Objective-C") == 0)			\
253132718Skan    {									\
254132718Skan      if ((target_flags & MASK_MS_BITFIELD_LAYOUT) != 0			\
255132718Skan	  && (target_flags_explicit & MASK_MS_BITFIELD_LAYOUT) != 0)	\
256132718Skan	{								\
257132718Skan	   error ("ms-bitfields not supported for objc");		\
258132718Skan	}								\
259132718Skan      target_flags &= ~MASK_MS_BITFIELD_LAYOUT;				\
260132718Skan    }									\
261132718Skan} while (0)
262132718Skan
26396263Sobrien#define EH_FRAME_IN_DATA_SECTION
26452284Sobrien
265117395Skan#define READONLY_DATA_SECTION_ASM_OP	"\t.section\t.rdata,\"r\""
26652284Sobrien
26752284Sobrien/* The MS compilers take alignment as a number of bytes, so we do as well */
26852284Sobrien#undef ASM_OUTPUT_ALIGN
26952284Sobrien#define ASM_OUTPUT_ALIGN(FILE,LOG) \
27052284Sobrien  if ((LOG)!=0) fprintf ((FILE), "\t.balign %d\n", 1<<(LOG))
27152284Sobrien
27252284Sobrien/* The linker will take care of this, and having them causes problems with
27390075Sobrien   ld -r (specifically -rU).  */
27452284Sobrien#define CTOR_LISTS_DEFINED_EXTERNALLY 1
27552284Sobrien
27690075Sobrien#define SET_ASM_OP	"\t.set\t"
27752284Sobrien/* Output a definition (implements alias) */
27852284Sobrien#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)				\
27952284Sobriendo									\
28052284Sobrien{									\
28190075Sobrien    fprintf ((FILE), "%s", SET_ASM_OP);					\
28252284Sobrien    assemble_name (FILE, LABEL1);					\
28352284Sobrien    fprintf (FILE, ",");						\
28452284Sobrien    assemble_name (FILE, LABEL2);					\
28552284Sobrien    fprintf (FILE, "\n");						\
28652284Sobrien    }									\
28752284Sobrienwhile (0)
28852284Sobrien
28952284Sobrien#define HOST_PTR_AS_INT unsigned long
29052284Sobrien
29152284Sobrien#define PCC_BITFIELD_TYPE_MATTERS 1
29252284Sobrien
29352284Sobrien/* The following two flags are usually "off" for i386, because some non-gnu
29452284Sobrien   tools (for the i386) don't handle them.  However, we don't have that
29590075Sobrien   problem, so....  */
29652284Sobrien
29752284Sobrien/* Forward references to tags are allowed.  */
29852284Sobrien#define SDB_ALLOW_FORWARD_REFERENCES
29952284Sobrien
30052284Sobrien/* Unknown tags are also allowed.  */
30152284Sobrien#define SDB_ALLOW_UNKNOWN_REFERENCES
30252284Sobrien
30352284Sobrien/* The integer half of this list needs to be constant.  However, there's
30452284Sobrien   a lot of disagreement about what the floating point adjustments should
30552284Sobrien   be.  We pick one that works with gdb.  (The underlying problem is
30652284Sobrien   what to do about the segment registers.  Since we have access to them
30752284Sobrien   from /proc, we'll allow them to be accessed in gdb, even tho the
30852284Sobrien   gcc compiler can't generate them.  (There's some evidence that
30952284Sobrien   MSVC does, but possibly only for certain special "canned" sequences.) */
31052284Sobrien
31152284Sobrien#undef DBX_REGISTER_NUMBER
31252284Sobrien#define DBX_REGISTER_NUMBER(n) \
31390075Sobrien(TARGET_64BIT ? dbx64_register_map[n] \
31490075Sobrien : (n) == 0 ? 0 \
31552284Sobrien : (n) == 1 ? 2 \
31652284Sobrien : (n) == 2 ? 1 \
31752284Sobrien : (n) == 3 ? 3 \
31852284Sobrien : (n) == 4 ? 6 \
31952284Sobrien : (n) == 5 ? 7 \
32052284Sobrien : (n) == 6 ? 5 \
32152284Sobrien : (n) == 7 ? 4 \
32252284Sobrien : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+8 \
32352284Sobrien : (-1))
32452284Sobrien
32552284Sobrien/* Define this macro if references to a symbol must be treated
32652284Sobrien   differently depending on something about the variable or
327117395Skan   function named by the symbol (such as what section it is in).  */
32852284Sobrien
329117395Skan#undef TARGET_ENCODE_SECTION_INFO
330117395Skan#define TARGET_ENCODE_SECTION_INFO i386_pe_encode_section_info
331117395Skan#undef  TARGET_STRIP_NAME_ENCODING
332117395Skan#define TARGET_STRIP_NAME_ENCODING  i386_pe_strip_name_encoding_full
33352284Sobrien
33452284Sobrien#if 0
33552284Sobrien/* Turn this back on when the linker is updated to handle grouped
33652284Sobrien   .data$ sections correctly. See corresponding note in i386/interix.c.
33790075Sobrien   MK.  */
33852284Sobrien
339169689Skan/* Interix uses explicit import from shared libraries.  */
340169689Skan#define MULTIPLE_SYMBOL_SPACES 1
34152284Sobrien
342132718Skanextern void i386_pe_unique_section (tree, int);
343117395Skan#define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
344169689Skan#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
34552284Sobrien
34652284Sobrien#define SUPPORTS_ONE_ONLY 1
34796263Sobrien#endif /* 0 */
34852284Sobrien
34990075Sobrien/* Switch into a generic section.  */
35090075Sobrien#define TARGET_ASM_NAMED_SECTION  default_pe_asm_named_section
35152284Sobrien
35290075Sobrien/* DWARF2 Unwinding doesn't work with exception handling yet.  */
35352284Sobrien#define DWARF2_UNWIND_INFO 0
35452284Sobrien
35590075Sobrien/* Don't assume anything about the header files.  */
35652284Sobrien#define NO_IMPLICIT_EXTERN_C
35752284Sobrien
358132718Skan/* MSVC returns structs of up to 8 bytes via registers.  */
35996263Sobrien
36096263Sobrien#define DEFAULT_PCC_STRUCT_RETURN 0
36196263Sobrien
36296263Sobrien#undef RETURN_IN_MEMORY
36396263Sobrien#define RETURN_IN_MEMORY(TYPE) \
36496263Sobrien  (TYPE_MODE (TYPE) == BLKmode || \
36596263Sobrien     (AGGREGATE_TYPE_P (TYPE) && int_size_in_bytes(TYPE) > 8 ))
366