OSDN Git Service

try to fix NT trampolines
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.c
index ad7872d..20c72d2 100644 (file)
@@ -1,5 +1,5 @@
 /* Subroutines used for code generation on IBM RS/6000.
-   Copyright (C) 1991, 1993, 1994, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
 
 This file is part of GNU CC.
@@ -37,6 +37,10 @@ Boston, MA 02111-1307, USA.  */
 #include "obstack.h"
 #include "tree.h"
 
+#ifndef TARGET_NO_PROTOTYPE
+#define TARGET_NO_PROTOTYPE 0
+#endif
+
 extern char *language_string;
 extern int profile_block_flag;
 
@@ -46,7 +50,13 @@ extern int profile_block_flag;
 /* Target cpu type */
 
 enum processor_type rs6000_cpu;
-char *rs6000_cpu_string;
+struct rs6000_cpu_select rs6000_select[3] =
+{
+  /* switch    name,                   tune    arch */
+  { (char *)0, "--with-cpu=",          1,      1 },
+  { (char *)0, "-mcpu=",               1,      1 },
+  { (char *)0, "-mtune=",              1,      0 },
+};
 
 /* Set to non-zero by "fix" operation to indicate that itrunc and
    uitrunc must be defined.  */
@@ -74,6 +84,12 @@ int rs6000_pic_labelno;
 /* Whether a System V.4 varargs area was created.  */
 int rs6000_sysv_varargs_p;
 
+/* Whether we need to save the TOC register.  */
+int rs6000_save_toc_p;
+
+/* ABI enumeration available for subtarget to use.  */
+enum rs6000_abi rs6000_current_abi;
+
 /* Temporary memory used to convert integer -> float */
 static rtx stack_temps[NUM_MACHINE_MODES];
 
@@ -82,7 +98,7 @@ static rtx stack_temps[NUM_MACHINE_MODES];
 
 extern char *version_string, *language_string;
 
-struct option
+struct asm_option
 {
   char *string;
   int *variable;
@@ -115,9 +131,9 @@ static struct { char *name; int value; } m_options[] = TARGET_SWITCHES;
 void
 output_options (file, f_options, f_len, W_options, W_len)
      FILE *file;
-     struct option *f_options;
+     struct asm_option *f_options;
      int f_len;
-     struct option *W_options;
+     struct asm_option *W_options;
      int W_len;
 {
   int j;
@@ -165,8 +181,9 @@ output_options (file, f_options, f_len, W_options, W_len)
        }
     }
 
-  if (rs6000_cpu_string != (char *)0)
-    pos = output_option (file, "-mcpu=", rs6000_cpu_string, pos);
+  for (j = 0; j < sizeof (rs6000_select) / sizeof(rs6000_select[0]); j++)
+    if (rs6000_select[j].string != (char *)0)
+      pos = output_option (file, rs6000_select[j].name, rs6000_select[j].string, pos);
 
   fputs ("\n\n", file);
 }
@@ -176,9 +193,11 @@ output_options (file, f_options, f_len, W_options, W_len)
    type and sometimes adjust other TARGET_ options.  */
 
 void
-rs6000_override_options ()
+rs6000_override_options (default_cpu)
+     char *default_cpu;
 {
-  int i;
+  int i, j;
+  struct rs6000_cpu_select *ptr;
 
   /* Simplify the entries below by making a mask for any POWER
      variant and any PowerPC variant.  */
@@ -195,10 +214,14 @@ rs6000_override_options ()
       int target_enable;       /* Target flags to enable.  */
       int target_disable;      /* Target flags to disable.  */
     } processor_target_table[]
-      = {{"common", PROCESSOR_COMMON, 0, POWER_MASKS | POWERPC_MASKS},
+      = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
+           POWER_MASKS | POWERPC_MASKS},
         {"power", PROCESSOR_POWER,
            MASK_POWER | MASK_MULTIPLE | MASK_STRING,
            MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
+        {"power2", PROCESSOR_POWER,
+           MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
+           POWERPC_MASKS | MASK_NEW_MNEMONICS},
         {"powerpc", PROCESSOR_POWERPC,
            MASK_POWERPC | MASK_NEW_MNEMONICS,
            POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
@@ -220,15 +243,33 @@ rs6000_override_options ()
         {"403", PROCESSOR_PPC403,
            MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
            POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
+        {"505", PROCESSOR_MPCCORE,
+           MASK_POWERPC | MASK_NEW_MNEMONICS,
+           POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
         {"601", PROCESSOR_PPC601,
            MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
            MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
+        {"602", PROCESSOR_PPC602,
+           MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
+           POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
         {"603", PROCESSOR_PPC603,
            MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
            POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
+        {"603e", PROCESSOR_PPC603,
+           MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
+           POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
         {"604", PROCESSOR_PPC604,
            MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
-           POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}};
+           POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
+        {"620", PROCESSOR_PPC620,
+           MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
+           POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
+        {"821", PROCESSOR_MPCCORE,
+           MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
+           POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
+        {"860", PROCESSOR_MPCCORE,
+           MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
+           POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
 
   int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
 
@@ -238,24 +279,30 @@ rs6000_override_options ()
   profile_block_flag = 0;
 
   /* Identify the processor type */
-  if (rs6000_cpu_string == 0)
-    rs6000_cpu = PROCESSOR_DEFAULT;
-  else
-    {
-      for (i = 0; i < ptt_size; i++)
-       if (! strcmp (rs6000_cpu_string, processor_target_table[i].name))
-         {
-           rs6000_cpu = processor_target_table[i].processor;
-           target_flags |= processor_target_table[i].target_enable;
-           target_flags &= ~processor_target_table[i].target_disable;
-           break;
-         }
+  rs6000_select[0].string = default_cpu;
+  rs6000_cpu = PROCESSOR_DEFAULT;
 
-      if (i == ptt_size)
+  for (i = 0; i < sizeof (rs6000_select) / sizeof (rs6000_select[0]); i++)
+    {
+      ptr = &rs6000_select[i];
+      if (ptr->string != (char *)0 && ptr->string[0] != '\0')
        {
-         error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string);
-         rs6000_cpu_string = "default";
-         rs6000_cpu = PROCESSOR_DEFAULT;
+         for (j = 0; j < ptt_size; j++)
+           if (! strcmp (ptr->string, processor_target_table[j].name))
+             {
+               if (ptr->set_tune_p)
+                 rs6000_cpu = processor_target_table[j].processor;
+
+               if (ptr->set_arch_p)
+                 {
+                   target_flags |= processor_target_table[j].target_enable;
+                   target_flags &= ~processor_target_table[j].target_disable;
+                 }
+               break;
+             }
+
+         if (i == ptt_size)
+           error ("bad value (%s) for %s switch", ptr->string, ptr->name);
        }
     }
 
@@ -350,6 +397,23 @@ any_operand (op, mode)
   return 1;
 }
 
+/* Returns 1 if op is the count register */
+int count_register_operand(op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  if (GET_CODE (op) != REG)
+    return 0;
+
+  if (REGNO (op) == COUNT_REGISTER_REGNUM)
+    return 1;
+
+  if (REGNO (op) > FIRST_PSEUDO_REGISTER)
+    return 1;
+
+  return 0;
+}
+
 /* Return 1 if OP is a constant that can fit in a D field.  */
 
 int
@@ -469,21 +533,64 @@ easy_fp_constant (op, mode)
      register rtx op;
      register enum machine_mode mode;
 {
-  rtx low, high;
-
   if (GET_CODE (op) != CONST_DOUBLE
       || GET_MODE (op) != mode
       || GET_MODE_CLASS (mode) != MODE_FLOAT)
     return 0;
 
-  high = operand_subword (op, 0, 0, mode);
-  low = operand_subword (op, 1, 0, mode);
+  /* Consider all constants with -msoft-float to be easy */
+  if (TARGET_SOFT_FLOAT)
+    return 1;
+
+  if (mode == DFmode)
+    {
+      long k[2];
+      REAL_VALUE_TYPE rv;
+
+      REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
+      REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
+
+      return (((unsigned) (k[0] + 0x8000) < 0x10000 || (k[0] & 0xffff) == 0)
+             && ((unsigned) (k[1] + 0x8000) < 0x10000 || (k[1] & 0xffff) == 0));
+    }
+  else
+    {
+      long l;
+      REAL_VALUE_TYPE rv;
+
+      REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
+      REAL_VALUE_TO_TARGET_SINGLE (rv, l);
+
+      return ((unsigned) (l + 0x8000) < 0x10000 || (l & 0xffff) == 0);
+    }
+}
+
+/* Return 1 if the operand is in volatile memory.  Note that during the
+   RTL generation phase, memory_operand does not return TRUE for
+   volatile memory references.  So this function allows us to
+   recognize volatile references where its safe.  */
+
+int
+volatile_mem_operand (op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  if (GET_CODE (op) != MEM)
+    return 0;
+
+  if (!MEM_VOLATILE_P (op))
+    return 0;
 
-  if (high == 0 || ! input_operand (high, word_mode))
+  if (mode != GET_MODE (op))
     return 0;
 
-  return (mode == SFmode
-         || (low != 0 && input_operand (low, word_mode)));
+  if (reload_completed)
+    return memory_operand (op, mode);
+
+  if (reload_in_progress)
+    return strict_memory_address_p (mode, XEXP (op, 0));
+
+  return memory_address_p (mode, XEXP (op, 0));
 }
 
 /* Return 1 if the operand is an offsettable memory address.  */
@@ -506,6 +613,7 @@ fp_reg_or_mem_operand (op, mode)
      enum machine_mode mode;
 {
   return (memory_operand (op, mode)
+         || volatile_mem_operand (op, mode)
          || (register_operand (op, mode)
              && (GET_CODE (op) != REG
                  || REGNO (op) >= FIRST_PSEUDO_REGISTER
@@ -640,7 +748,9 @@ reg_or_mem_operand (op, mode)
      register rtx op;
      register enum machine_mode mode;
 {
-  return gpc_reg_operand (op, mode) || memory_operand (op, mode);
+  return (gpc_reg_operand (op, mode)
+         || memory_operand (op, mode)
+         || volatile_mem_operand (op, mode));
 }
 
 /* Return 1 if the operand is a general register or memory operand without
@@ -723,19 +833,65 @@ input_operand (op, mode)
   if (register_operand (op, mode))
     return 1;
 
-  /* For HImode and QImode, any constant is valid. */
-  if ((mode == HImode || mode == QImode)
-      && GET_CODE (op) == CONST_INT)
+  /* For integer modes, any constant is ok.  */
+  if (GET_CODE (op) == CONST_INT)
     return 1;
 
   /* A SYMBOL_REF referring to the TOC is valid.  */
   if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
     return 1;
 
-  /* Otherwise, we will be doing this SET with an add, so anything valid
-     for an add will be valid.  */
-  return add_operand (op, mode);
+  /* Windows NT allows SYMBOL_REFs and LABEL_REFs against the TOC
+     directly in the instruction stream */
+  if (DEFAULT_ABI == ABI_NT
+      && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF))
+    return 1;
+
+  /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
+     to be valid.  */
+  if (DEFAULT_ABI == ABI_V4
+      && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
+      && small_data_operand (op, Pmode))
+    return 1;
+
+  return 0;
+}
+
+/* Return 1 for an operand in small memory on V.4/eabi */
+
+int
+small_data_operand (op, mode)
+     rtx op;
+     enum machine_mode mode;
+{
+  rtx sym_ref, const_part;
+
+#ifdef TARGET_SDATA
+  if (!TARGET_SDATA)
+    return 0;
+#endif
+
+  if (DEFAULT_ABI != ABI_V4)
+    return 0;
+
+  if (GET_CODE (op) == SYMBOL_REF)
+    sym_ref = op;
+
+  else if (GET_CODE (op) != CONST
+          || GET_CODE (XEXP (op, 0)) != PLUS
+          || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
+          || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
+    return 0;
+
+  else
+    sym_ref = XEXP (XEXP (op, 0), 0);
+
+  if (*XSTR (sym_ref, 0) != '@')
+    return 0;
+
+  return 1;
 }
+
 \f
 /* Initialize a variable CUM of type CUMULATIVE_ARGS
    for a call to a function whose data type is FNTYPE.
@@ -752,19 +908,19 @@ init_cumulative_args (cum, fntype, libname, incoming)
      int incoming;
 {
   static CUMULATIVE_ARGS zero_cumulative;
+  enum rs6000_abi abi = DEFAULT_ABI;
 
   *cum = zero_cumulative;
   cum->words = 0;
   cum->fregno = FP_ARG_MIN_REG;
   cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
+  cum->call_cookie = CALL_NORMAL;
 
   if (incoming)
     {
       cum->nargs_prototype = 1000;             /* don't return an EXPR_LIST */
-#ifdef TARGET_V4_CALLS
-      if (TARGET_V4_CALLS)
+      if (abi == ABI_V4)
        cum->varargs_offset = RS6000_VARARGS_OFFSET;
-#endif
     }
 
   else if (cum->prototype)
@@ -776,6 +932,13 @@ init_cumulative_args (cum, fntype, libname, incoming)
     cum->nargs_prototype = 0;
 
   cum->orig_nargs = cum->nargs_prototype;
+
+  /* Check for DLL import functions */
+  if (abi == ABI_NT
+      && fntype
+      && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (fntype)))
+    cum->call_cookie = CALL_NT_DLLIMPORT;
+
   if (TARGET_DEBUG_ARG)
     {
       fprintf (stderr, "\ninit_cumulative_args:");
@@ -786,16 +949,42 @@ init_cumulative_args (cum, fntype, libname, incoming)
                   tree_code_name[ (int)TREE_CODE (ret_type) ]);
        }
 
-#ifdef TARGET_V4_CALLS
-      if (TARGET_V4_CALLS && incoming)
+      if (abi == ABI_V4 && incoming)
        fprintf (stderr, " varargs = %d, ", cum->varargs_offset);
-#endif
+
+      if (cum->call_cookie == CALL_NT_DLLIMPORT)
+       fprintf (stderr, " dllimport,");
 
       fprintf (stderr, " proto = %d, nargs = %d\n",
               cum->prototype, cum->nargs_prototype);
     }
 }
 \f
+/* If defined, a C expression that gives the alignment boundary, in bits,
+   of an argument with the specified mode and type.  If it is not defined, 
+   PARM_BOUNDARY is used for all arguments.
+   
+   Windows NT wants anything >= 8 bytes to be double word aligned.
+
+   V.4 wants long longs to be double word aligned.  */
+
+int
+function_arg_boundary (mode, type)
+     enum machine_mode mode;
+     tree type;
+{
+  if (DEFAULT_ABI == ABI_V4 && mode == DImode)
+    return 64;
+
+  if (DEFAULT_ABI != ABI_NT || TARGET_64BIT)
+    return PARM_BOUNDARY;
+
+  if (mode != BLKmode)
+    return (GET_MODE_SIZE (mode)) >= 8 ? 64 : 32;
+
+  return (int_size_in_bytes (type) >= 8) ? 64 : 32;
+}
+\f
 /* Update the data in CUM to advance over an argument
    of mode MODE and data type TYPE.
    (TYPE is null for libcalls where that information may not be available.)  */
@@ -807,10 +996,11 @@ function_arg_advance (cum, mode, type, named)
      tree type;
      int named;
 {
+  int align = ((cum->words & 1) != 0 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
+  cum->words += align;
   cum->nargs_prototype--;
 
-#ifdef TARGET_V4_CALLS
-  if (TARGET_V4_CALLS)
+  if (DEFAULT_ABI == ABI_V4)
     {
       /* Long longs must not be split between registers and stack */
       if ((GET_MODE_CLASS (mode) != MODE_FLOAT || TARGET_SOFT_FLOAT)
@@ -836,7 +1026,6 @@ function_arg_advance (cum, mode, type, named)
        cum->words += RS6000_ARG_SIZE (mode, type, 1);
     }
   else
-#endif
     if (named)
       {
        cum->words += RS6000_ARG_SIZE (mode, type, named);
@@ -846,8 +1035,8 @@ function_arg_advance (cum, mode, type, named)
 
   if (TARGET_DEBUG_ARG)
     fprintf (stderr,
-            "function_adv: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d\n",
-            cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named);
+            "function_adv: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
+            cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
 }
 \f
 /* Determine where to put an argument to a function.
@@ -880,30 +1069,40 @@ function_arg (cum, mode, type, named)
      tree type;
      int named;
 {
+  int align = ((cum->words & 1) != 0 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
+  int align_words = cum->words + align;
+
   if (TARGET_DEBUG_ARG)
     fprintf (stderr,
-            "function_arg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d\n",
-            cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named);
+            "function_arg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, named = %d, align = %d\n",
+            cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), named, align);
 
   /* Return a marker to indicate whether CR1 needs to set or clear the bit that V.4
      uses to say fp args were passed in registers.  Assume that we don't need the
      marker for software floating point, or compiler generated library calls.  */
   if (mode == VOIDmode)
     {
-#ifdef TARGET_V4_CALLS
-      if (TARGET_V4_CALLS && TARGET_HARD_FLOAT && cum->nargs_prototype < 0
+      enum rs6000_abi abi = DEFAULT_ABI;
+
+      if (abi == ABI_V4
+         && TARGET_HARD_FLOAT
+         && cum->nargs_prototype < 0
          && type && (cum->prototype || TARGET_NO_PROTOTYPE))
-       return GEN_INT ((cum->fregno == FP_ARG_MIN_REG) ? -1 : 1);
-#endif
+       {
+         if (cum->call_cookie != CALL_NORMAL)
+           abort ();
+
+         return GEN_INT ((cum->fregno == FP_ARG_MIN_REG)
+                         ? CALL_V4_SET_FP_ARGS
+                         : CALL_V4_CLEAR_FP_ARGS);
+       }
 
-      return GEN_INT (0);
+      return GEN_INT (cum->call_cookie);
     }
 
   if (!named)
     {
-#ifdef TARGET_V4_CALLS
-      if (!TARGET_V4_CALLS)
-#endif
+      if (DEFAULT_ABI != ABI_V4)
        return NULL_RTX;
     }
 
@@ -913,30 +1112,26 @@ function_arg (cum, mode, type, named)
   if (USE_FP_FOR_ARG_P (*cum, mode, type))
     {
       if ((cum->nargs_prototype > 0)
-#ifdef TARGET_V4_CALLS
-         || TARGET_V4_CALLS    /* V.4 never passes FP values in GP registers */
-#endif
+         || (DEFAULT_ABI == ABI_V4)    /* V.4 never passes FP values in GP registers */
          || !type)
        return gen_rtx (REG, mode, cum->fregno);
 
       return gen_rtx (EXPR_LIST, VOIDmode,
-                     ((cum->words < GP_ARG_NUM_REG)
-                      ? gen_rtx (REG, mode, GP_ARG_MIN_REG + cum->words)
+                     ((align_words < GP_ARG_NUM_REG)
+                      ? gen_rtx (REG, mode, GP_ARG_MIN_REG + align_words)
                       : NULL_RTX),
                      gen_rtx (REG, mode, cum->fregno));
     }
 
-#ifdef TARGET_V4_CALLS
   /* Long longs won't be split between register and stack */
-  else if (TARGET_V4_CALLS &&
-          cum->words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
+  else if (DEFAULT_ABI == ABI_V4 &&
+          align_words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
     {
       return NULL_RTX;
     }
-#endif
 
-  else if (cum->words < GP_ARG_NUM_REG)
-    return gen_rtx (REG, mode, GP_ARG_MIN_REG + cum->words);
+  else if (align_words < GP_ARG_NUM_REG)
+    return gen_rtx (REG, mode, GP_ARG_MIN_REG + align_words);
 
   return NULL_RTX;
 }
@@ -955,10 +1150,8 @@ function_arg_partial_nregs (cum, mode, type, named)
   if (! named)
     return 0;
 
-#ifdef TARGET_V4_CALLS
-  if (TARGET_V4_CALLS)
+  if (DEFAULT_ABI == ABI_V4)
     return 0;
-#endif
 
   if (USE_FP_FOR_ARG_P (*cum, mode, type))
     {
@@ -994,15 +1187,13 @@ function_arg_pass_by_reference (cum, mode, type, named)
      tree type;
      int named;
 {
-#ifdef TARGET_V4_CALLS
-  if (TARGET_V4_CALLS && type && AGGREGATE_TYPE_P (type))
+  if (DEFAULT_ABI == ABI_V4 && type && AGGREGATE_TYPE_P (type))
     {
       if (TARGET_DEBUG_ARG)
        fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
 
       return 1;
     }
-#endif
 
   return 0;
 }
@@ -1039,13 +1230,11 @@ setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
             "setup_vararg: words = %2d, fregno = %2d, nargs = %4d, proto = %d, mode = %4s, no_rtl= %d\n",
             cum->words, cum->fregno, cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode), no_rtl);
 
-#ifdef TARGET_V4_CALLS
-  if (TARGET_V4_CALLS && !no_rtl)
+  if (DEFAULT_ABI == ABI_V4 && !no_rtl)
     {
       rs6000_sysv_varargs_p = 1;
       save_area = plus_constant (frame_pointer_rtx, RS6000_VARARGS_OFFSET);
     }
-#endif
 
   if (cum->words < 8)
     {
@@ -1068,9 +1257,8 @@ setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
       *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD;
     }
 
-#ifdef TARGET_V4_CALLS
   /* Save FP registers if needed.  */
-  if (TARGET_V4_CALLS && TARGET_HARD_FLOAT && !no_rtl)
+  if (DEFAULT_ABI == ABI_V4 && TARGET_HARD_FLOAT && !no_rtl)
     {
       int fregno     = cum->fregno;
       int num_fp_reg = FP_ARG_V4_MAX_REG + 1 - fregno;
@@ -1098,7 +1286,6 @@ setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
          emit_label (lab);
        }
     }
-#endif
 }
 \f
 /* If defined, is a C expression that produces the machine-specific
@@ -1164,11 +1351,13 @@ expand_block_move_mem (mode, addr, orig_mem)
      rtx orig_mem;
 {
   rtx mem = gen_rtx (MEM, mode, addr);
+
+  RTX_UNCHANGING_P (mem) = RTX_UNCHANGING_P (orig_mem);
   MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (orig_mem);
   MEM_IN_STRUCT_P (mem) = MEM_IN_STRUCT_P (orig_mem);
-  /* CYGNUS LOCAL unaligned-pointers */
+#ifdef MEM_UNALIGNED_P
   MEM_UNALIGNED_P (mem) = MEM_UNALIGNED_P (orig_mem);
-  /* END CYGNUS LOCAL unaligned-pointers */
+#endif
   return mem;
 }
 
@@ -1186,6 +1375,8 @@ int
 expand_block_move (operands)
      rtx operands[];
 {
+  rtx orig_dest = operands[0];
+  rtx orig_src = operands[1];
   rtx bytes_rtx        = operands[2];
   rtx align_rtx = operands[3];
   int constp   = (GET_CODE (bytes_rtx) == CONST_INT);
@@ -1227,8 +1418,8 @@ expand_block_move (operands)
     return 0;
 
   /* Move the address into scratch registers.  */
-  dest_reg = copy_addr_to_reg (XEXP (operands[0], 0));
-  src_reg  = copy_addr_to_reg (XEXP (operands[1], 0));
+  dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
+  src_reg  = copy_addr_to_reg (XEXP (orig_src,  0));
 
   if (TARGET_STRING)   /* string instructions are available */
     {
@@ -1245,8 +1436,8 @@ expand_block_move (operands)
              && !fixed_regs[12])
            {
              move_bytes = (bytes > 32) ? 32 : bytes;
-             emit_insn (gen_movstrsi_8reg (dest_reg,
-                                           src_reg,
+             emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
+                                           expand_block_move_mem (BLKmode, src_reg, orig_src),
                                            GEN_INT ((move_bytes == 32) ? 0 : move_bytes),
                                            align_rtx));
            }
@@ -1259,8 +1450,8 @@ expand_block_move (operands)
                   && !fixed_regs[12])
            {
              move_bytes = (bytes > 24) ? 24 : bytes;
-             emit_insn (gen_movstrsi_6reg (dest_reg,
-                                           src_reg,
+             emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
+                                           expand_block_move_mem (BLKmode, src_reg, orig_src),
                                            GEN_INT (move_bytes),
                                            align_rtx));
            }
@@ -1271,16 +1462,16 @@ expand_block_move (operands)
                   && !fixed_regs[12])
            {
              move_bytes = (bytes > 16) ? 16 : bytes;
-             emit_insn (gen_movstrsi_4reg (dest_reg,
-                                           src_reg,
+             emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
+                                           expand_block_move_mem (BLKmode, src_reg, orig_src),
                                            GEN_INT (move_bytes),
                                            align_rtx));
            }
          else if (bytes > 4 && !TARGET_64BIT)
            {                   /* move up to 8 bytes at a time */
              move_bytes = (bytes > 8) ? 8 : bytes;
-             emit_insn (gen_movstrsi_2reg (dest_reg,
-                                           src_reg,
+             emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
+                                           expand_block_move_mem (BLKmode, src_reg, orig_src),
                                            GEN_INT (move_bytes),
                                            align_rtx));
            }
@@ -1288,28 +1479,28 @@ expand_block_move (operands)
            {                   /* move 4 bytes */
              move_bytes = 4;
              tmp_reg = gen_reg_rtx (SImode);
-             emit_move_insn (tmp_reg, gen_rtx (MEM, SImode, src_reg));
-             emit_move_insn (gen_rtx (MEM, SImode, dest_reg), tmp_reg);
+             emit_move_insn (tmp_reg, expand_block_move_mem (SImode, src_reg, orig_src));
+             emit_move_insn (expand_block_move_mem (SImode, dest_reg, orig_dest), tmp_reg);
            }
          else if (bytes == 2 && (align >= 2 || !STRICT_ALIGNMENT))
            {                   /* move 2 bytes */
              move_bytes = 2;
              tmp_reg = gen_reg_rtx (HImode);
-             emit_move_insn (tmp_reg, gen_rtx (MEM, HImode, src_reg));
-             emit_move_insn (gen_rtx (MEM, HImode, dest_reg), tmp_reg);
+             emit_move_insn (tmp_reg, expand_block_move_mem (HImode, src_reg, orig_src));
+             emit_move_insn (expand_block_move_mem (HImode, dest_reg, orig_dest), tmp_reg);
            }
          else if (bytes == 1)  /* move 1 byte */
            {
              move_bytes = 1;
              tmp_reg = gen_reg_rtx (QImode);
-             emit_move_insn (tmp_reg, gen_rtx (MEM, QImode, src_reg));
-             emit_move_insn (gen_rtx (MEM, QImode, dest_reg), tmp_reg);
+             emit_move_insn (tmp_reg, expand_block_move_mem (QImode, src_reg, orig_src));
+             emit_move_insn (expand_block_move_mem (QImode, dest_reg, orig_dest), tmp_reg);
            }
          else
            {                   /* move up to 4 bytes at a time */
              move_bytes = (bytes > 4) ? 4 : bytes;
-             emit_insn (gen_movstrsi_1reg (dest_reg,
-                                           src_reg,
+             emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode, dest_reg, orig_dest),
+                                           expand_block_move_mem (BLKmode, src_reg, orig_src),
                                            GEN_INT (move_bytes),
                                            align_rtx));
            }
@@ -1340,26 +1531,33 @@ expand_block_move (operands)
            }
 
          /* Generate the appropriate load and store, saving the stores for later */
-         if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
+         if (bytes >= 8 && TARGET_64BIT && (align >= 8 || !STRICT_ALIGNMENT))
+           {
+             move_bytes = 8;
+             tmp_reg = gen_reg_rtx (DImode);
+             emit_insn (gen_movdi (tmp_reg, expand_block_move_mem (DImode, src_addr, orig_src)));
+             stores[ num_reg++ ] = gen_movdi (expand_block_move_mem (DImode, dest_addr, orig_dest), tmp_reg);
+           }
+         else if (bytes >= 4 && (align >= 4 || !STRICT_ALIGNMENT))
            {
              move_bytes = 4;
              tmp_reg = gen_reg_rtx (SImode);
-             emit_insn (gen_movsi (tmp_reg, gen_rtx (MEM, SImode, src_addr)));
-             stores[ num_reg++ ] = gen_movsi (gen_rtx (MEM, SImode, dest_addr), tmp_reg);
+             emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (SImode, src_addr, orig_src)));
+             stores[ num_reg++ ] = gen_movsi (expand_block_move_mem (SImode, dest_addr, orig_dest), tmp_reg);
            }
          else if (bytes >= 2 && (align >= 2 || !STRICT_ALIGNMENT))
            {
              move_bytes = 2;
              tmp_reg = gen_reg_rtx (HImode);
-             emit_insn (gen_movhi (tmp_reg, gen_rtx (MEM, HImode, src_addr)));
-             stores[ num_reg++ ] = gen_movhi (gen_rtx (MEM, HImode, dest_addr), tmp_reg);
+             emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (HImode, src_addr, orig_src)));
+             stores[ num_reg++ ] = gen_movhi (expand_block_move_mem (HImode, dest_addr, orig_dest), tmp_reg);
            }
          else
            {
              move_bytes = 1;
              tmp_reg = gen_reg_rtx (QImode);
-             emit_insn (gen_movqi (tmp_reg, gen_rtx (MEM, QImode, src_addr)));
-             stores[ num_reg++ ] = gen_movqi (gen_rtx (MEM, QImode, dest_addr), tmp_reg);
+             emit_insn (gen_movsi (tmp_reg, expand_block_move_mem (QImode, src_addr, orig_src)));
+             stores[ num_reg++ ] = gen_movqi (expand_block_move_mem (QImode, dest_addr, orig_dest), tmp_reg);
            }
 
          if (num_reg >= MAX_MOVE_REG)
@@ -1370,11 +1568,8 @@ expand_block_move (operands)
            }
        }
 
-      if (num_reg > 0)
-       {
-         for (i = 0; i < num_reg; i++)
-           emit_insn (stores[i]);
-       }
+      for (i = 0; i < num_reg; i++)
+       emit_insn (stores[i]);
     }
 
   return 1;
@@ -1859,6 +2054,15 @@ print_operand (file, x, code)
        print_operand (file, x, 0);
       return;
 
+    case 'H':
+      /* If constant, output low-order six bits.  Otherwise,
+        write normally. */
+      if (INT_P (x))
+       fprintf (file, "%d", INT_LOWPART (x) & 63);
+      else
+       print_operand (file, x, 0);
+      return;
+
     case 'I':
       /* Print `i' if this is a constant, else nothing.  */
       if (INT_P (x))
@@ -1908,6 +2112,8 @@ print_operand (file, x, code)
            output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
          else
            output_address (plus_constant (XEXP (x, 0), 4));
+         if (DEFAULT_ABI == ABI_V4 && small_data_operand (x, GET_MODE (x)))
+           fprintf (file, "@sda21(%s)", reg_names[0]);
        }
       return;
                            
@@ -1923,7 +2129,7 @@ print_operand (file, x, code)
         the left.  */
       if (val < 0 && (val & 1) == 0)
        {
-         fprintf (file, "0");
+         putc ('0', file);
          return;
        }
       else if (val >= 0)
@@ -2118,6 +2324,8 @@ print_operand (file, x, code)
            output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
          else
            output_address (plus_constant (XEXP (x, 0), 8));
+         if (DEFAULT_ABI == ABI_V4 && small_data_operand (x, GET_MODE (x)))
+           fprintf (file, "@sda21(%s)", reg_names[0]);
        }
       return;
                            
@@ -2130,9 +2338,26 @@ print_operand (file, x, code)
       if (GET_CODE (x) != SYMBOL_REF)
        abort ();
 
-#ifndef USING_SVR4_H
-      putc ('.', file);
-#endif
+      if (XSTR (x, 0)[0] != '.')
+       {
+         switch (DEFAULT_ABI)
+           {
+           default:
+             abort ();
+
+           case ABI_AIX:
+             putc ('.', file);
+             break;
+
+           case ABI_V4:
+           case ABI_AIX_NODESC:
+             break;
+
+           case ABI_NT:
+             fputs ("..", file);
+             break;
+           }
+       }
       RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
       return;
 
@@ -2147,6 +2372,8 @@ print_operand (file, x, code)
            output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
          else
            output_address (plus_constant (XEXP (x, 0), 12));
+         if (DEFAULT_ABI == ABI_V4 && small_data_operand (x, GET_MODE (x)))
+           fprintf (file, "@sda21(%s)", reg_names[0]);
        }
       return;
                            
@@ -2187,13 +2414,14 @@ print_operand_address (file, x)
   else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
     {
       output_addr_const (file, x);
-      /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead
-        of the toc pointer.  */
+      if (DEFAULT_ABI == ABI_V4 && small_data_operand (x, GET_MODE (x)))
+       fprintf (file, "@sda21(%s)", reg_names[0]);
+
 #ifdef TARGET_NO_TOC
-      if (TARGET_NO_TOC)
+      else if (TARGET_NO_TOC)
        ;
-      else
 #endif
+      else
        fprintf (file, "(%s)", reg_names[ TARGET_MINIMAL_TOC ? 30 : 2 ]);
     }
   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
@@ -2238,11 +2466,9 @@ first_reg_to_save ()
      to 23 to do this.  Don't use the frame pointer in reg 31.
 
      For now, save enough room for all of the parameter registers.  */
-#ifndef USING_SVR4_H
-  if (profile_flag)
+  if (DEFAULT_ABI == ABI_AIX && profile_flag)
     if (first_reg > 23)
       first_reg = 23;
-#endif
 
   return first_reg;
 }
@@ -2336,7 +2562,49 @@ rs6000_makes_calls ()
                +---------------------------------------+
        old SP->| back chain to caller's caller         |
                +---------------------------------------+
-*/
+
+
+   A PowerPC Windows/NT frame looks like:
+
+       SP----> +---------------------------------------+
+               | back chain to caller                  | 0
+               +---------------------------------------+
+               | reserved                              | 4
+               +---------------------------------------+
+               | reserved                              | 8
+               +---------------------------------------+
+               | reserved                              | 12
+               +---------------------------------------+
+               | reserved                              | 16
+               +---------------------------------------+
+               | reserved                              | 20
+               +---------------------------------------+
+               | Parameter save area (P)               | 24
+               +---------------------------------------+
+               | Alloca space (A)                      | 24+P
+               +---------------------------------------+
+               | Local variable space (L)              | 24+P+A
+               +---------------------------------------+
+               | Save area for FP registers (F)        | 24+P+A+L
+               +---------------------------------------+
+               | Possible alignment area (X)           | 24+P+A+L+F
+               +---------------------------------------+
+               | Save area for GP registers (G)        | 24+P+A+L+F+X
+               +---------------------------------------+
+               | Save area for CR (C)                  | 24+P+A+L+F+X+G
+               +---------------------------------------+
+               | Save area for TOC (T)                 | 24+P+A+L+F+X+G+C
+               +---------------------------------------+
+               | Save area for LR (R)                  | 24+P+A+L+F+X+G+C+T
+               +---------------------------------------+
+       old SP->| back chain to caller's caller         |
+               +---------------------------------------+
+
+   For NT, there is no specific order to save the registers, but in
+   order to support __builtin_return_address, the save area for the
+   link register needs to be in a known place, so we use -4 off of the
+   old SP.  To support calls through pointers, we also allocate a
+   fixed slot to store the TOC, -8 off the old SP.  */
 
 rs6000_stack_t *
 rs6000_stack_info ()
@@ -2345,19 +2613,13 @@ rs6000_stack_info ()
   rs6000_stack_t *info_ptr = &info;
   int reg_size = TARGET_64BIT ? 8 : 4;
   enum rs6000_abi abi;
+  int total_raw_size;
 
   /* Zero all fields portably */
   info = zero_info;
 
   /* Select which calling sequence */
-#ifdef TARGET_V4_CALLS
-  if (TARGET_V4_CALLS)
-    abi = ABI_V4;
-  else
-#endif
-    abi = ABI_AIX;
-
-  info_ptr->abi = abi;
+  info_ptr->abi = abi = DEFAULT_ABI;
 
   /* Calculate which registers need to be saved & save area size */
   info_ptr->first_gp_reg_save = first_reg_to_save ();
@@ -2369,6 +2631,40 @@ rs6000_stack_info ()
   /* Does this function call anything? */
   info_ptr->calls_p = rs6000_makes_calls ();
 
+  /* Do we need to allocate space to save the toc? */
+  if (rs6000_save_toc_p)
+    {
+      info_ptr->toc_save_p = 1;
+      info_ptr->toc_size = reg_size;
+    }
+
+  /* If this is main and we need to call a function to set things up,
+     save main's arguments around the call.  */
+  if (strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), "main") == 0)
+    {
+      info_ptr->main_p = 1;
+
+#ifdef NAME__MAIN
+      info_ptr->calls_p = 1;
+
+      if (DECL_ARGUMENTS (current_function_decl))
+       {
+         int i;
+         tree arg;
+
+         info_ptr->main_save_p = 1;
+         info_ptr->main_size = 0;
+
+         for ((i = 0), (arg = DECL_ARGUMENTS (current_function_decl));
+              arg != NULL_TREE && i < 8;
+              (arg = TREE_CHAIN (arg)), i++)
+           {
+             info_ptr->main_size += reg_size;
+           }
+       }
+#endif
+    }
+
   /* Determine if we need to save the link register */
   if (regs_ever_live[65] || profile_flag
 #ifdef TARGET_RELOCATABLE
@@ -2381,13 +2677,15 @@ rs6000_stack_info ()
     {
       info_ptr->lr_save_p = 1;
       regs_ever_live[65] = 1;
+      if (abi == ABI_NT)
+       info_ptr->lr_size = reg_size;
     }
 
   /* Determine if we need to save the condition code registers */
   if (regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72])
     {
       info_ptr->cr_save_p = 1;
-      if (abi == ABI_V4)
+      if (abi == ABI_V4 || abi == ABI_NT)
        info_ptr->cr_size = reg_size;
     }
 
@@ -2397,12 +2695,20 @@ rs6000_stack_info ()
   info_ptr->varargs_size = RS6000_VARARGS_AREA;
   info_ptr->vars_size    = ALIGN (get_frame_size (), 8);
   info_ptr->parm_size    = ALIGN (current_function_outgoing_args_size, 8);
-  info_ptr->save_size    = ALIGN (info_ptr->fp_size + info_ptr->gp_size + info_ptr->cr_size, 8);
-  info_ptr->total_size   = ALIGN (info_ptr->vars_size
-                                 + info_ptr->parm_size
-                                 + info_ptr->save_size
-                                 + info_ptr->varargs_size
-                                 + info_ptr->fixed_size, STACK_BOUNDARY / BITS_PER_UNIT);
+  info_ptr->save_size    = ALIGN (info_ptr->fp_size
+                                 + info_ptr->gp_size
+                                 + info_ptr->cr_size
+                                 + info_ptr->lr_size
+                                 + info_ptr->toc_size
+                                 + info_ptr->main_size, 8);
+
+  total_raw_size        = (info_ptr->vars_size
+                           + info_ptr->parm_size
+                           + info_ptr->save_size
+                           + info_ptr->varargs_size
+                           + info_ptr->fixed_size);
+
+  info_ptr->total_size   = ALIGN (total_raw_size, STACK_BOUNDARY / BITS_PER_UNIT);
 
   /* Determine if we need to allocate any stack frame.
      For AIX We need to push the stack if a frame pointer is needed (because
@@ -2415,8 +2721,8 @@ rs6000_stack_info ()
   if (info_ptr->calls_p)
     info_ptr->push_p = 1;
 
-  else if (abi == ABI_V4)
-    info_ptr->push_p = (info_ptr->total_size > info_ptr->fixed_size
+  else if (abi == ABI_V4 || abi == ABI_NT)
+    info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
                        || info_ptr->lr_save_p);
 
   else
@@ -2425,18 +2731,40 @@ rs6000_stack_info ()
                        || info_ptr->total_size > 220);
 
   /* Calculate the offsets */
-  info_ptr->fp_save_offset = - info_ptr->fp_size;
-  info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
   switch (abi)
     {
+    case ABI_NONE:
     default:
-      info_ptr->cr_save_offset = 4;
-      info_ptr->lr_save_offset = 8;
+      abort ();
+
+    case ABI_AIX:
+    case ABI_AIX_NODESC:
+      info_ptr->fp_save_offset   = - info_ptr->fp_size;
+      info_ptr->gp_save_offset   = info_ptr->fp_save_offset - info_ptr->gp_size;
+      info_ptr->main_save_offset = info_ptr->gp_save_offset - info_ptr->main_size;
+      info_ptr->cr_save_offset   = 4;
+      info_ptr->lr_save_offset   = 8;
       break;
 
     case ABI_V4:
-      info_ptr->cr_save_offset = info_ptr->gp_save_offset - reg_size;
-      info_ptr->lr_save_offset = reg_size;
+      info_ptr->fp_save_offset   = - info_ptr->fp_size;
+      info_ptr->gp_save_offset   = info_ptr->fp_save_offset - info_ptr->gp_size;
+      info_ptr->cr_save_offset   = info_ptr->gp_save_offset - reg_size;
+      info_ptr->toc_save_offset  = info_ptr->cr_save_offset - info_ptr->cr_size;
+      info_ptr->main_save_offset = info_ptr->toc_save_offset - info_ptr->toc_size;
+      info_ptr->lr_save_offset   = reg_size;
+      break;
+
+    case ABI_NT:
+      info_ptr->lr_save_offset    = -4;
+      info_ptr->toc_save_offset   = info_ptr->lr_save_offset - info_ptr->lr_size;
+      info_ptr->cr_save_offset    = info_ptr->toc_save_offset - info_ptr->toc_size;
+      info_ptr->gp_save_offset    = info_ptr->cr_save_offset - info_ptr->cr_size - info_ptr->gp_size + reg_size;
+      info_ptr->fp_save_offset    = info_ptr->gp_save_offset - info_ptr->fp_size;
+      if (info_ptr->fp_size && ((- info_ptr->fp_save_offset) % 8) != 0)
+       info_ptr->fp_save_offset -= 4;
+
+      info_ptr->main_save_offset = info_ptr->fp_save_offset - info_ptr->main_size;
       break;
     }
 
@@ -2453,6 +2781,12 @@ rs6000_stack_info ()
   if (!info_ptr->cr_save_p)
     info_ptr->cr_save_offset = 0;
 
+  if (!info_ptr->toc_save_p)
+    info_ptr->toc_save_offset = 0;
+
+  if (!info_ptr->main_save_p)
+    info_ptr->main_save_offset = 0;
+
   return info_ptr;
 }
 
@@ -2472,10 +2806,12 @@ debug_stack_info (info)
 
   switch (info->abi)
     {
-    default:      abi_string = "Unknown";      break;
-    case ABI_NONE: abi_string = "NONE";                break;
-    case ABI_AIX:  abi_string = "AIX";         break;
-    case ABI_V4:   abi_string = "V.4";         break;
+    default:            abi_string = "Unknown";        break;
+    case ABI_NONE:      abi_string = "NONE";           break;
+    case ABI_AIX:       abi_string = "AIX";            break;
+    case ABI_AIX_NODESC: abi_string = "AIX";           break;
+    case ABI_V4:        abi_string = "V.4";            break;
+    case ABI_NT:        abi_string = "NT";             break;
     }
 
   fprintf (stderr, "\tABI                 = %5s\n", abi_string);
@@ -2492,12 +2828,21 @@ debug_stack_info (info)
   if (info->cr_save_p)
     fprintf (stderr, "\tcr_save_p           = %5d\n", info->cr_save_p);
 
+  if (info->toc_save_p)
+    fprintf (stderr, "\ttoc_save_p          = %5d\n", info->toc_save_p);
+
   if (info->push_p)
     fprintf (stderr, "\tpush_p              = %5d\n", info->push_p);
 
   if (info->calls_p)
     fprintf (stderr, "\tcalls_p             = %5d\n", info->calls_p);
 
+  if (info->main_p)
+    fprintf (stderr, "\tmain_p              = %5d\n", info->main_p);
+
+  if (info->main_save_p)
+    fprintf (stderr, "\tmain_save_p         = %5d\n", info->main_save_p);
+
   if (info->gp_save_offset)
     fprintf (stderr, "\tgp_save_offset      = %5d\n", info->gp_save_offset);
 
@@ -2510,9 +2855,15 @@ debug_stack_info (info)
   if (info->cr_save_offset)
     fprintf (stderr, "\tcr_save_offset      = %5d\n", info->cr_save_offset);
 
+  if (info->toc_save_offset)
+    fprintf (stderr, "\ttoc_save_offset     = %5d\n", info->toc_save_offset);
+
   if (info->varargs_save_offset)
     fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
 
+  if (info->main_save_offset)
+    fprintf (stderr, "\tmain_save_offset    = %5d\n", info->main_save_offset);
+
   if (info->total_size)
     fprintf (stderr, "\ttotal_size          = %5d\n", info->total_size);
 
@@ -2534,9 +2885,18 @@ debug_stack_info (info)
   if (info->fp_size)
     fprintf (stderr, "\tfp_size             = %5d\n", info->fp_size);
 
+ if (info->lr_size)
+    fprintf (stderr, "\tlr_size             = %5d\n", info->cr_size);
+
   if (info->cr_size)
     fprintf (stderr, "\tcr_size             = %5d\n", info->cr_size);
 
+ if (info->toc_size)
+    fprintf (stderr, "\ttoc_size            = %5d\n", info->toc_size);
+
+ if (info->main_size)
+    fprintf (stderr, "\tmain_size           = %5d\n", info->main_size);
+
   if (info->save_size)
     fprintf (stderr, "\tsave_size           = %5d\n", info->save_size);
 
@@ -2547,65 +2907,6 @@ debug_stack_info (info)
 }
 
 \f
-
-#ifdef USING_SVR4_H
-/* Write out a System V.4 style traceback table before the prologue
-
-   At present, only emit the basic tag table (ie, do not emit tag_types other
-   than 0, which might use more than 1 tag word).
-
-   The first tag word looks like:
-
-    0                  1                   2                   3
-    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-   |         0 |ver| tag |e|s| alloca  | # fprs  | # gprs  |s|l|c|f|
-   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
-*/
-
-void
-svr4_traceback (file, name, decl)
-     FILE *file;
-     tree name, decl;
-{
-  rs6000_stack_t *info = rs6000_stack_info ();
-  long tag;
-  long version         = 0;                            /* version number */
-  long tag_type                = 0;                            /* function type */
-  long extended_tag    = 0;                            /* additional tag words needed */
-  long spare           = 0;                            /* reserved for future use */
-  long fpscr_max       = 0;                            /* 1 if the function has a FPSCR save word */
-  long fpr_max         = 64 - info->first_fp_reg_save; /* # of floating point registers saved */
-  long gpr_max         = 32 - info->first_gp_reg_save; /* # of general purpose registers saved */
-  long alloca_reg;                                     /* stack/frame register */
-
-  if (frame_pointer_needed)
-    alloca_reg = 31;
-
-  else if (info->push_p != 0)
-    alloca_reg = 1;
-
-  else
-    alloca_reg = 0;
-
-  tag = ((version << 24)
-        | (tag_type << 21)
-        | (extended_tag << 20)
-        | (spare << 19)
-        | (alloca_reg << 14)
-        | (fpr_max << 9)
-        | (gpr_max << 4)
-        | (info->push_p << 3)
-        | (info->lr_save_p << 2)
-        | (info->cr_save_p << 1)
-        | (fpscr_max << 0));
-          
-  fprintf (file, "\t.long 0x%lx\n", tag);
-}
-
-#endif /* USING_SVR4_H */
-\f
 /* Write function prologue.  */
 void
 output_prolog (file, size)
@@ -2613,19 +2914,32 @@ output_prolog (file, size)
      int size;
 {
   rs6000_stack_t *info = rs6000_stack_info ();
-  char *store_reg = (TARGET_64BIT) ? "\tstd %s,%d(%s)" : "\t{st|stw} %s,%d(%s)\n";
+  int reg_size = info->reg_size;
+  char *store_reg;
+  char *load_reg;
+  int sp_reg = 1;
+  int sp_offset = 0;
+
+  if (TARGET_32BIT)
+    {
+      store_reg = "\t{st|stw} %s,%d(%s)\n";
+      load_reg = "\t{l|lwz} %s,%d(%s)\n";
+    }
+  else
+    {
+      store_reg = "\tstd %s,%d(%s)\n";
+      load_reg = "\tlld %s,%d(%s)\n";
+    }
 
   if (TARGET_DEBUG_STACK)
     debug_stack_info (info);
 
   /* Write .extern for any function we will call to save and restore fp
      values.  */
-#ifndef USING_SVR4_H
-  if (info->first_fp_reg_save < 62)
+  if (info->first_fp_reg_save < 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
     fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
             SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
             RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
-#endif
 
   /* Write .extern for truncation routines, if needed.  */
   if (rs6000_trunc_used && ! trunc_defined)
@@ -2647,24 +2961,48 @@ output_prolog (file, size)
       common_mode_defined = 1;
     }
 
-  /* If we use the link register, get it into r0.  */
-  if (info->lr_save_p)
-    asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
-
-  /* If we need to save CR, put it into r12.  */
-  if (info->cr_save_p)
-    asm_fprintf (file, "\tmfcr %s\n", reg_names[12]);
-
+  /* For V.4, update stack before we do any saving and set back pointer.  */
+  if (info->push_p && DEFAULT_ABI == ABI_V4)
+    {
+      if (info->total_size < 32767)
+       {
+         asm_fprintf (file,
+                      (TARGET_32BIT) ? "\t{stu|stwu} %s,%d(%s)\n" : "\tstdu %s,%d(%s)\n",
+                      reg_names[1], - info->total_size, reg_names[1]);
+         sp_offset = info->total_size;
+       }
+      else
+       {
+         int neg_size = - info->total_size;
+         sp_reg = 12;
+         asm_fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
+         asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
+                      reg_names[0], (neg_size >> 16) & 0xffff,
+                      reg_names[0], reg_names[0], neg_size & 0xffff);
+         asm_fprintf (file,
+                      (TARGET_32BIT) ? "\t{stux|stwux} %s,%s,%s\n" : "\tstdux %s,%s,%s\n",
+                      reg_names[1], reg_names[1], reg_names[0]);
+       }
+    }
+
+  /* If we use the link register, get it into r0.  */
+  if (info->lr_save_p)
+    asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
+
+  /* If we need to save CR, put it into r12.  */
+  if (info->cr_save_p && sp_reg != 12)
+    asm_fprintf (file, "\tmfcr %s\n", reg_names[12]);
+
   /* Do any required saving of fpr's.  If only one or two to save, do it
      ourself.  Otherwise, call function.  Note that since they are statically
      linked, we do not need a nop following them.  */
   if (FP_SAVE_INLINE (info->first_fp_reg_save))
     {
       int regno = info->first_fp_reg_save;
-      int loc   = info->fp_save_offset;
+      int loc   = info->fp_save_offset + sp_offset;
 
       for ( ; regno < 64; regno++, loc += 8)
-       asm_fprintf (file, "\tstfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[1]);
+       asm_fprintf (file, "\tstfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
     }
   else if (info->first_fp_reg_save != 64)
     asm_fprintf (file, "\tbl %s%d%s\n", SAVE_FP_PREFIX,
@@ -2674,33 +3012,100 @@ output_prolog (file, size)
   if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
     {
       int regno    = info->first_gp_reg_save;
-      int loc      = info->gp_save_offset;
-      int reg_size = (TARGET_64BIT) ? 8 : 4;
+      int loc      = info->gp_save_offset + sp_offset;
 
       for ( ; regno < 32; regno++, loc += reg_size)
-       asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[1]);
+       asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
     }
 
   else if (info->first_gp_reg_save != 32)
     asm_fprintf (file, "\t{stm|stmw} %s,%d(%s)\n",
                 reg_names[info->first_gp_reg_save],
-                info->gp_save_offset,
-                reg_names[1]);
+                info->gp_save_offset + sp_offset,
+                reg_names[sp_reg]);
+
+  /* Save main's arguments if we need to call a function */
+#ifdef NAME__MAIN
+  if (info->main_save_p)
+    {
+      int regno;
+      int loc = info->main_save_offset;
+      int size = info->main_size;
+
+      for (regno = 3; size > 0; regno++, loc -= reg_size, size -= reg_size)
+       asm_fprintf (file, store_reg, reg_names[regno], loc, reg_names[sp_reg]);
+    }
+#endif
 
   /* Save lr if we used it.  */
   if (info->lr_save_p)
-    asm_fprintf (file, store_reg, reg_names[0], info->lr_save_offset, reg_names[1]);
+    asm_fprintf (file, store_reg, reg_names[0], info->lr_save_offset + sp_offset,
+                reg_names[sp_reg]);
 
   /* Save CR if we use any that must be preserved.  */
   if (info->cr_save_p)
-    asm_fprintf (file, store_reg, reg_names[12], info->cr_save_offset, reg_names[1]);
+    {
+      if (sp_reg == 12)        /* If r12 is used to hold the original sp, copy cr now */
+       {
+         asm_fprintf (file, "\tmfcr %s\n", reg_names[0]);
+         asm_fprintf (file, store_reg, reg_names[0],
+                      info->cr_save_offset + sp_offset,
+                      reg_names[sp_reg]);
+       }
+      else
+       asm_fprintf (file, store_reg, reg_names[12], info->cr_save_offset + sp_offset,
+                    reg_names[sp_reg]);
+    }
 
-  /* Update stack and set back pointer.  */
-  if (info->push_p)
+  if (info->toc_save_p)
+    asm_fprintf (file, store_reg, reg_names[2], info->toc_save_offset + sp_offset,
+                reg_names[sp_reg]);
+
+  /* NT needs us to probe the stack frame every 4k pages for large frames, so
+     do it here.  */
+  if (DEFAULT_ABI == ABI_NT && info->total_size > 4096)
+    {
+      if (info->total_size < 32768)
+       {
+         int probe_offset = 4096;
+         while (probe_offset < info->total_size)
+           {
+             asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n", reg_names[0], -probe_offset, reg_names[1]);
+             probe_offset += 4096;
+           }
+       }
+      else
+       {
+         int probe_iterations = info->total_size / 4096;
+         static int probe_labelno = 0;
+         char buf[256];
+
+         if (probe_iterations < 32768)
+           asm_fprintf (file, "\tli %s,%d\n", reg_names[12], probe_iterations);
+         else
+           {
+             asm_fprintf (file, "\tlis %s,%d\n", reg_names[12], probe_iterations >> 16);
+             if (probe_iterations & 0xffff)
+               asm_fprintf (file, "\tori %s,%s,%d\n", reg_names[12], reg_names[12],
+                            probe_iterations & 0xffff);
+           }
+         asm_fprintf (file, "\tmtctr %s\n", reg_names[12]);
+         asm_fprintf (file, "\tmr %s,%s\n", reg_names[12], reg_names[1]);
+         ASM_OUTPUT_INTERNAL_LABEL (file, "LCprobe", probe_labelno);
+         asm_fprintf (file, "\t{lu|lwzu} %s,-4096(%s)\n", reg_names[0], reg_names[12]);
+         ASM_GENERATE_INTERNAL_LABEL (buf, "LCprobe", probe_labelno);
+         fputs ("\tbdnz ", file);
+         assemble_name (file, buf);
+         fputs ("\n", file);
+       }
+    }
+
+  /* Update stack and set back pointer and we have already done so for V.4.  */
+  if (info->push_p && DEFAULT_ABI != ABI_V4)
     {
       if (info->total_size < 32767)
        asm_fprintf (file,
-                    (TARGET_64BIT) ? "\tstdu %s,%d(%s)\n" : "\t{stu|stwu} %s,%d(%s)\n",
+                    (TARGET_32BIT) ? "\t{stu|stwu} %s,%d(%s)\n" : "\tstdu %s,%d(%s)\n",
                     reg_names[1], - info->total_size, reg_names[1]);
       else
        {
@@ -2709,7 +3114,7 @@ output_prolog (file, size)
                       reg_names[0], (neg_size >> 16) & 0xffff,
                       reg_names[0], reg_names[0], neg_size & 0xffff);
          asm_fprintf (file,
-                      (TARGET_64BIT) ? "\tstdux %s,%s,%s\n" : "\t{stux|stwux} %s,%s,%s\n",
+                      (TARGET_32BIT) ? "\t{stux|stwux} %s,%s,%s\n" : "\tstdux %s,%s,%s\n",
                       reg_names[1], reg_names[1], reg_names[0]);
        }
     }
@@ -2718,34 +3123,86 @@ output_prolog (file, size)
   if (frame_pointer_needed)
     asm_fprintf (file, "\tmr %s,%s\n", reg_names[31], reg_names[1]);
 
+#ifdef NAME__MAIN
+  /* If we need to call a function to set things up for main, do so now
+     before dealing with the TOC.  */
+  if (info->main_p)
+    {
+      char *prefix = "";
+
+      switch (DEFAULT_ABI)
+       {
+       case ABI_AIX:   prefix = ".";   break;
+       case ABI_NT:    prefix = "..";  break;
+       }
+
+      fprintf (file, "\tbl %s%s\n", prefix, NAME__MAIN);
+#ifdef RS6000_CALL_GLUE2
+      fprintf (file, "\t%s%s%s\n", RS6000_CALL_GLUE2, prefix, NAME_MAIN);
+#else
+#ifdef RS6000_CALL_GLUE
+      if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
+       fprintf (file, "\t%s\n", RS6000_CALL_GLUE);
+#endif
+#endif
+
+      if (info->main_save_p)
+       {
+         int regno;
+         int loc;
+         int size = info->main_size;
+
+         if (info->total_size < 32767)
+           {
+             loc = info->total_size + info->main_save_offset;
+             for (regno = 3; size > 0; regno++, size -= reg_size, loc -= reg_size)
+               asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]);
+           }
+         else
+           {                   /* for large AIX/NT frames, reg 0 above contains -frame size */
+                               /* for V.4, we need to reload -frame size */
+             loc = info->main_save_offset;
+             if (DEFAULT_ABI == ABI_V4 && info->total_size > 32767)
+               {
+                 int neg_size = - info->total_size;
+                 asm_fprintf (file, "\t{liu|lis} %s,%d\n\t{oril|ori} %s,%s,%d\n",
+                              reg_names[0], (neg_size >> 16) & 0xffff,
+                              reg_names[0], reg_names[0], neg_size & 0xffff);
+               }
+
+             asm_fprintf (file, "\t{sf|subf} %s,%s,%s\n", reg_names[0], reg_names[0],
+                          reg_names[1]);
+
+             for (regno = 3; size > 0; regno++, size -= reg_size, loc -= reg_size)
+               asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[0]);
+           }
+       }
+    }
+#endif
+
+
   /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the
      TOC_TABLE address into register 30.  */
   if (TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
     {
       char buf[256];
 
-#ifdef USING_SVR4_H
+#ifdef TARGET_RELOCATABLE
       if (TARGET_RELOCATABLE)
        {
          ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
-         fprintf (file, "\tbl ");
+         fputs ("\tbl ", file);
          assemble_name (file, buf);
-         fprintf (file, "\n");
+         putc ('\n', file);
 
          ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
          fprintf (file, "\tmflr %s\n", reg_names[30]);
 
-         if (TARGET_POWERPC64)
-           fprintf (file, "\tld");
-         else if (TARGET_NEW_MNEMONICS)
-           fprintf (file, "\tlwz");
-         else
-           fprintf (file, "\tl");
-
+         asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz}" : "\tld");
          fprintf (file, " %s,(", reg_names[0]);
          ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
          assemble_name (file, buf);
-         fprintf (file, "-");
+         putc ('-', file);
          ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
          assemble_name (file, buf);
          fprintf (file, ")(%s)\n", reg_names[30]);
@@ -2753,34 +3210,51 @@ output_prolog (file, size)
                       reg_names[30], reg_names[0], reg_names[30]);
          rs6000_pic_labelno++;
        }
-      else if (!TARGET_64BIT)
-       {
-         ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
-         asm_fprintf (file, "\t{cau|addis} %s,%s,", reg_names[30], reg_names[0]);
+      else
+#endif
+
+       switch (DEFAULT_ABI)
+         {
+         case ABI_V4:
+         case ABI_AIX_NODESC:
+           if (TARGET_32BIT)
+             {
+               ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
+               asm_fprintf (file, "\t{cau|addis} %s,%s,", reg_names[30], reg_names[0]);
+               assemble_name (file, buf);
+               asm_fprintf (file, "@ha\n");
+               if (TARGET_NEW_MNEMONICS)
+                 {
+                   asm_fprintf (file, "\taddi %s,%s,", reg_names[30], reg_names[30]);
+                   assemble_name (file, buf);
+                   asm_fprintf (file, "@l\n");
+                 }
+               else
+                 {
+                   asm_fprintf (file, "\tcal %s,", reg_names[30]);
+                   assemble_name (file, buf);
+                   asm_fprintf (file, "@l(%s)\n", reg_names[30]);
+                 }
+             }
+           else
+             abort ();
+
+         break;
+
+       case ABI_NT:
+       case ABI_AIX:
+         ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
+         asm_fprintf (file, "\t{l|lwz} %s,", reg_names[30]);
          assemble_name (file, buf);
-         asm_fprintf (file, "@ha\n");
-         if (TARGET_NEW_MNEMONICS)
-           {
-             asm_fprintf (file, "\taddi %s,%s,", reg_names[30], reg_names[30]);
-             assemble_name (file, buf);
-             asm_fprintf (file, "@l\n");
-           }
-         else
-           {
-             asm_fprintf (file, "\tcal %s,", reg_names[30]);
-             assemble_name (file, buf);
-             asm_fprintf (file, "@l(%s)\n", reg_names[30]);
-           }
+         asm_fprintf (file, "(%s)\n", reg_names[2]);
+         break;
        }
-      else
-       abort ();
+    }
 
-#else  /* !USING_SVR4_H */
-      ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 0);
-      asm_fprintf (file, "\t{l|lwz} %s,", reg_names[30]);
-      assemble_name (file, buf);
-      asm_fprintf (file, "(%s)\n", reg_names[2]);
-#endif /* USING_SVR4_H */
+  if (DEFAULT_ABI == ABI_NT)
+    {
+      assemble_name (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
+      fputs (".b:\n", file);
     }
 }
 
@@ -2792,8 +3266,10 @@ output_epilog (file, size)
      int size;
 {
   rs6000_stack_t *info = rs6000_stack_info ();
-  char *load_reg = (TARGET_64BIT) ? "\tld %s,%d(%s)" : "\t{l|lwz} %s,%d(%s)\n";
+  char *load_reg = (TARGET_32BIT) ? "\t{l|lwz} %s,%d(%s)\n" : "\tld %s,%d(%s)\n";
   rtx insn = get_last_insn ();
+  int sp_reg = 1;
+  int sp_offset = 0;
   int i;
 
   /* Forget about any temporaries created */
@@ -2811,10 +3287,19 @@ output_epilog (file, size)
         we know what size to update it with.  */
       if (frame_pointer_needed || current_function_calls_alloca
          || info->total_size > 32767)
-       asm_fprintf (file, load_reg, reg_names[1], 0, reg_names[1]);
+       {
+         /* Under V.4, don't reset the stack pointer until after we're done
+            loading the saved registers.  */
+         if (DEFAULT_ABI == ABI_V4)
+           sp_reg = 11;
+
+         asm_fprintf (file, load_reg, reg_names[sp_reg], 0, reg_names[1]);
+       }
       else if (info->push_p)
        {
-         if (TARGET_NEW_MNEMONICS)
+         if (DEFAULT_ABI == ABI_V4)
+           sp_offset = info->total_size;
+         else if (TARGET_NEW_MNEMONICS)
            asm_fprintf (file, "\taddi %s,%s,%d\n", reg_names[1], reg_names[1], info->total_size);
          else
            asm_fprintf (file, "\tcal %s,%d(%s)\n", reg_names[1], info->total_size, reg_names[1]);
@@ -2822,11 +3307,11 @@ output_epilog (file, size)
 
       /* Get the old lr if we saved it.  */
       if (info->lr_save_p)
-       asm_fprintf (file, load_reg, reg_names[0], info->lr_save_offset, reg_names[1]);
+       asm_fprintf (file, load_reg, reg_names[0], info->lr_save_offset + sp_offset, reg_names[sp_reg]);
 
       /* Get the old cr if we saved it.  */
       if (info->cr_save_p)
-       asm_fprintf (file, load_reg, reg_names[12], info->cr_save_offset, reg_names[1]);
+       asm_fprintf (file, load_reg, reg_names[12], info->cr_save_offset + sp_offset, reg_names[sp_reg]);
 
       /* Set LR here to try to overlap restores below.  */
       if (info->lr_save_p)
@@ -2836,27 +3321,27 @@ output_epilog (file, size)
       if (! TARGET_MULTIPLE || info->first_gp_reg_save == 31 || TARGET_64BIT)
        {
          int regno    = info->first_gp_reg_save;
-         int loc      = info->gp_save_offset;
-         int reg_size = (TARGET_64BIT) ? 8 : 4;
+         int loc      = info->gp_save_offset + sp_offset;
+         int reg_size = (TARGET_32BIT) ? 4 : 8;
 
          for ( ; regno < 32; regno++, loc += reg_size)
-           asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[1]);
+           asm_fprintf (file, load_reg, reg_names[regno], loc, reg_names[sp_reg]);
        }
 
       else if (info->first_gp_reg_save != 32)
        asm_fprintf (file, "\t{lm|lmw} %s,%d(%s)\n",
                     reg_names[info->first_gp_reg_save],
-                    info->gp_save_offset,
-                    reg_names[1]);
+                    info->gp_save_offset + sp_offset,
+                    reg_names[sp_reg]);
 
       /* Restore fpr's if we can do it without calling a function.  */
       if (FP_SAVE_INLINE (info->first_fp_reg_save))
        {
          int regno = info->first_fp_reg_save;
-         int loc   = info->fp_save_offset;
+         int loc   = info->fp_save_offset + sp_offset;
 
          for ( ; regno < 64; regno++, loc += 8)
-           asm_fprintf (file, "\tlfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[1]);
+           asm_fprintf (file, "\tlfd %s,%d(%s)\n", reg_names[regno], loc, reg_names[sp_reg]);
        }
 
       /* If we saved cr, restore it here.  Just those of cr2, cr3, and cr4
@@ -2867,6 +3352,17 @@ output_epilog (file, size)
                     + (regs_ever_live[71] != 0) * 0x10
                     + (regs_ever_live[72] != 0) * 0x8, reg_names[12]);
 
+      /* If this is V.4, unwind the stack pointer after all of the loads have been done */
+      if (sp_offset)
+       {
+         if (TARGET_NEW_MNEMONICS)
+           asm_fprintf (file, "\taddi %s,%s,%d\n", reg_names[1], reg_names[1], sp_offset);
+         else
+           asm_fprintf (file, "\tcal %s,%d(%s)\n", reg_names[1], sp_offset, reg_names[1]);
+       }
+      else if (sp_reg != 1)
+       asm_fprintf (file, "\tmr %s,%s\n", reg_names[1], reg_names[sp_reg]);
+
       /* If we have to restore more than two FP registers, branch to the
         restore function.  It will return to our caller.  */
       if (info->first_fp_reg_save != 64 && !FP_SAVE_INLINE (info->first_fp_reg_save))
@@ -2889,14 +3385,16 @@ output_epilog (file, size)
      traceback table itself.
 
      System V.4 Powerpc's (and the embedded ABI derived from it) use a
-     different traceback table located before the prologue.  */
-#ifndef USING_SVR4_H
-  if (! flag_inhibit_size_directive)
+     different traceback table.  */
+  if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive)
     {
       char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
       int fixed_parms, float_parms, parm_info;
       int i;
 
+      while (*fname == '.')    /* V.4 encodes . in the name */
+       fname++;
+
       /* Need label immediately before tbtab, so we can compute its offset
         from the function start.  */
       if (*fname == '*')
@@ -2915,10 +3413,10 @@ output_epilog (file, size)
       /* An all-zero word flags the start of the tbtab, for debuggers
         that have to find it by searching forward from the entry
         point or from the current pc.  */
-      fprintf (file, "\t.long 0\n");
+      fputs ("\t.long 0\n", file);
 
       /* Tbtab format type.  Use format type 0.  */
-      fprintf (file, "\t.byte 0,");
+      fputs ("\t.byte 0,", file);
 
       /* Language type.  Unfortunately, there doesn't seem to be any
         official way to get this info, so we use language_string.  C
@@ -3040,12 +3538,12 @@ output_epilog (file, size)
        fprintf (file, "\t.long %d\n", parm_info);
 
       /* Offset from start of code to tb table.  */
-      fprintf (file, "\t.long ");
+      fputs ("\t.long ", file);
       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
       RS6000_OUTPUT_BASENAME (file, fname);
-      fprintf (file, "-.");
+      fputs ("-.", file);
       RS6000_OUTPUT_BASENAME (file, fname);
-      fprintf (file, "\n");
+      putc ('\n', file);
 
       /* Interrupt handler mask.  */
       /* Omit this long, since we never set the interrupt handler bit
@@ -3066,12 +3564,20 @@ output_epilog (file, size)
       /* Register for alloca automatic storage; this is always reg 31.
         Only emit this if the alloca bit was set above.  */
       if (frame_pointer_needed)
-       fprintf (file, "\t.byte 31\n");
+       fputs ("\t.byte 31\n", file);
     }
-#endif /* !USING_SVR4_H */
 
-  /* Reset varargs indicator */
+  /* Reset varargs and save TOC indicator */
   rs6000_sysv_varargs_p = 0;
+  rs6000_save_toc_p = 0;
+
+  if (DEFAULT_ABI == ABI_NT)
+    {
+      RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
+      fputs (".e:\nFE_MOT_RESVD..", file);
+      RS6000_OUTPUT_BASENAME (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
+      fputs (":\n", file);
+    }
 }
 \f
 /* Output a TOC entry.  We derive the entry name from what is
@@ -3085,6 +3591,7 @@ output_toc (file, x, labelno)
 {
   char buf[256];
   char *name = buf;
+  char *real_name;
   rtx base = x;
   int offset = 0;
 
@@ -3101,49 +3608,79 @@ output_toc (file, x, labelno)
   }
 
 
-#ifdef USING_SVR4_H
-  if (TARGET_MINIMAL_TOC)
+  if (TARGET_ELF && TARGET_MINIMAL_TOC)
     {
       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
       fprintf (file, "%d = .-", labelno);
       ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCTOC");
-      fprintf (file, "1\n");
+      fputs ("1\n", file);
     }
   else
-#endif /* USING_SVR4_H */
     ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno);
 
   /* Handle FP constants specially.  Note that if we have a minimal
      TOC, things we put here aren't actually in the TOC, so we can allow
      FP constants.  */
-  if (GET_CODE (x) == CONST_DOUBLE
-      && GET_MODE (x) == DFmode
+  if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode
       && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
     {
-      REAL_VALUE_TYPE r;
-      long l[2];
+      REAL_VALUE_TYPE rv;
+      long k[2];
 
-      REAL_VALUE_FROM_CONST_DOUBLE (r, x);
-      REAL_VALUE_TO_TARGET_DOUBLE (r, l);
+      REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
+      REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
       if (TARGET_MINIMAL_TOC)
-       fprintf (file, "\t.long %ld\n\t.long %ld\n", l[0], l[1]);
+       fprintf (file, "\t.long %ld\n\t.long %ld\n", k[0], k[1]);
       else
        fprintf (file, "\t.tc FD_%lx_%lx[TC],%ld,%ld\n",
-                l[0], l[1], l[0], l[1]);
+                k[0], k[1], k[0], k[1]);
       return;
     }
   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode
           && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
     {
-      rtx val = operand_subword (x, 0, 0, SFmode);
+      REAL_VALUE_TYPE rv;
+      long l;
 
-      if (val == 0 || GET_CODE (val) != CONST_INT)
-       abort ();
+      REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
+      REAL_VALUE_TO_TARGET_SINGLE (rv, l);
 
       if (TARGET_MINIMAL_TOC)
-       fprintf (file, "\t.long %d\n", INTVAL (val));
+       fprintf (file, "\t.long %d\n", l);
       else
-       fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val));
+       fprintf (file, "\t.tc FS_%x[TC],%d\n", l, l);
+      return;
+    }
+  else if (GET_MODE (x) == DImode
+          && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
+          && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC))
+    {
+      HOST_WIDE_INT low;
+      HOST_WIDE_INT high;
+
+      if (GET_CODE (x) == CONST_DOUBLE)
+       {
+         low = CONST_DOUBLE_LOW (x);
+         high = CONST_DOUBLE_HIGH (x);
+       }
+      else
+#if HOST_BITS_PER_WIDE_INT == 32
+       {
+         low = INTVAL (x);
+         high = (low < 0) ? ~0 : 0;
+       }
+#else
+       {
+          low = INTVAL (x) & 0xffffffff;
+          high = (HOST_WIDE_INT) INTVAL (x) >> 32;
+       }
+#endif
+
+      if (TARGET_MINIMAL_TOC)
+       fprintf (file, "\t.long %ld\n\t.long %ld\n", high, low);
+      else
+       fprintf (file, "\t.tc ID_%lx_%lx[TC],%ld,%ld\n",
+                high, low, high, low);
       return;
     }
 
@@ -3163,21 +3700,21 @@ output_toc (file, x, labelno)
     abort ();
 
   if (TARGET_MINIMAL_TOC)
-    fprintf (file, "\t.long ");
+    fputs ("\t.long ", file);
   else
     {
-      fprintf (file, "\t.tc ");
-      RS6000_OUTPUT_BASENAME (file, name);
+      STRIP_NAME_ENCODING (real_name, name);
+      fprintf (file, "\t.tc %s", real_name);
 
       if (offset < 0)
        fprintf (file, ".N%d", - offset);
       else if (offset)
        fprintf (file, ".P%d", offset);
 
-      fprintf (file, "[TC],");
+      fputs ("[TC],", file);
     }
   output_addr_const (file, x);
-  fprintf (file, "\n");
+  putc ('\n', file);
 }
 \f
 /* Output an assembler pseudo-op to write an ASCII string of N characters
@@ -3312,31 +3849,31 @@ output_function_profiler (file, labelno)
   FILE *file;
   int labelno;
 {
-#ifdef USING_SVR4_H
-  abort ();
-#else
   /* The last used parameter register.  */
   int last_parm_reg;
   int i, j;
   char buf[100];
 
+  if (DEFAULT_ABI != ABI_AIX)
+    abort ();
+
   /* Set up a TOC entry for the profiler label.  */
   toc_section ();
   ASM_OUTPUT_INTERNAL_LABEL (file, "LPC", labelno);
   ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
   if (TARGET_MINIMAL_TOC)
     {
-      fprintf (file, "\t.long ");
+      fputs ("\t.long ", file);
       assemble_name (file, buf);
-      fprintf (file, "\n");
+      putc ('\n', file);
     }
   else
     {
-      fprintf (file, "\t.tc\t");
+      fputs ("\t.tc\t", file);
       assemble_name (file, buf);
-      fprintf (file, "[TC],");
+      fputs ("[TC],", file);
       assemble_name (file, buf);
-      fprintf (file, "\n");
+      putc ('\n', file);
     }
   text_section ();
 
@@ -3353,20 +3890,19 @@ output_function_profiler (file, labelno)
      it might be set up as the frame pointer.  */
 
   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
-    fprintf (file, "\tai %d,%d,0\n", j, i);
+    asm_fprintf (file, "\tmr %d,%d\n", j, i);
 
   /* Load location address into r3, and call mcount.  */
 
   ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
-  fprintf (file, "\tl 3,");
+  asm_fprintf (file, "\t{l|lwz} %s,", reg_names[3]);
   assemble_name (file, buf);
-  fprintf (file, "(2)\n\tbl .mcount\n");
+  asm_fprintf (file, "(%s)\n\tbl .mcount\n", reg_names[2]);
 
   /* Restore parameter registers.  */
 
   for (i = 3, j = 30; i <= last_parm_reg; i++, j--)
-    fprintf (file, "\tai %d,%d,0\n", i, j);
-#endif
+    asm_fprintf (file, "\tmr %d,%d\n", i, j);
 }
 
 /* Adjust the cost of a scheduling dependency.  Return the new cost of
@@ -3402,3 +3938,446 @@ rs6000_adjust_cost (insn, link, dep_insn, cost)
 
   return cost;
 }
+
+/* Return how many instructions the machine can issue per cycle */
+int get_issue_rate()
+{
+  switch (rs6000_cpu_attr) {
+  case CPU_RIOS1:
+    return 3;       /* ? */
+  case CPU_RIOS2:
+    return 4;
+  case CPU_PPC601:
+    return 3;       /* ? */
+  case CPU_PPC602:
+    return 1; 
+  case CPU_PPC603:
+    return 2; 
+  case CPU_PPC604:
+    return 4;
+  case CPU_PPC620:
+    return 4;
+  default:
+    return 1;
+  }
+}
+
+\f
+/* Output insns to flush the {data|instruction} caches after building a
+   trampoline. */
+
+static void
+rs6000_sync_trampoline (addr)
+     rtx addr;
+{
+  enum machine_mode pmode = Pmode;
+  rtx reg = gen_reg_rtx (pmode);
+  rtx mem2;
+  rtx mem1;
+  int size = rs6000_trampoline_size ();
+  rtx (*sub_fcn) PROTO ((rtx, rtx, rtx));
+  rtx (*cmp_fcn) PROTO ((rtx, rtx));
+  rtx label;
+
+  if (TARGET_32BIT)
+    {
+      sub_fcn = gen_subsi3;
+      cmp_fcn = gen_cmpsi;
+    }
+  else
+    {
+      sub_fcn = gen_subdi3;
+      cmp_fcn = gen_cmpdi;
+    }
+
+  addr = force_reg (pmode, addr);
+  mem2 = gen_rtx (MEM, pmode, gen_rtx (PLUS, pmode, addr, reg));
+  mem1 = gen_rtx (MEM, pmode, addr);
+
+  /* Issue a loop of dcbst's to flush the data cache */
+  emit_move_insn (reg, GEN_INT (size-4));
+  label = gen_label_rtx ();
+  emit_label (label);
+  emit_insn (gen_dcbst (mem2, addr, reg));
+  emit_insn ((*sub_fcn) (reg, reg, GEN_INT (4)));
+  emit_insn ((*cmp_fcn) (reg, const0_rtx));
+  emit_jump_insn (gen_bgt (label));
+
+  /* Issue a sync after the dcbst's to let things settle down */
+  emit_insn (gen_sync (mem1));
+
+  /* Issue a loop of icbi's to flush the instruction cache */
+  emit_move_insn (reg, GEN_INT (size-4));
+  label = gen_label_rtx ();
+  emit_label (label);
+  emit_insn (gen_icbi (mem2, addr, reg));
+  emit_insn ((*sub_fcn) (reg, reg, GEN_INT (4)));
+  emit_insn ((*cmp_fcn) (reg, const0_rtx));
+  emit_jump_insn (gen_bgt (label));
+
+  /* Issue a sync after the icbi's to let things settle down */
+  emit_insn (gen_sync (mem1));
+
+  /* Finally issue an isync to synchronize the icache */
+  emit_insn (gen_isync (mem1));
+}
+
+\f
+/* Output assembler code for a block containing the constant parts
+   of a trampoline, leaving space for the variable parts.
+
+   The trampoline should set the static chain pointer to value placed
+   into the trampoline and should branch to the specified routine.  */
+
+void
+rs6000_trampoline_template (file)
+     FILE *file;
+{
+  char *sc = reg_names[STATIC_CHAIN_REGNUM];
+  char *r0 = reg_names[0];
+  char *r2 = reg_names[2];
+
+  switch (DEFAULT_ABI)
+    {
+    default:
+      abort ();
+
+    /* Under AIX, this is not code at all, but merely a data area,
+       since that is the way all functions are called.  The first word is
+       the address of the function, the second word is the TOC pointer (r2),
+       and the third word is the static chain value.  */
+    case ABI_AIX:
+      fprintf (file, "\t.long %s\n", (TARGET_32BIT) ? "0,0,0" : "0,0,0,0,0,0");
+      break;
+
+
+    /* V.4/eabi function pointers are just a single pointer, so we need to
+       do the full gory code to load up the static chain.  */
+    case ABI_V4:
+    case ABI_AIX_NODESC:
+      if (STATIC_CHAIN_REGNUM == 0 || !TARGET_NEW_MNEMONICS)
+       abort ();
+
+      if (TARGET_32BIT)
+       {
+         fprintf (file, "\tmflr %s\n", r0);            /* offset  0 */
+         fprintf (file, "\tbl .LTRAMP1\n");            /* offset  4 */
+         fprintf (file, "\t.long 0,0\n");              /* offset  8 */
+         fprintf (file, ".LTRAMP1:\n");
+         fprintf (file, "\tmflr %s\n", sc);            /* offset 20 */
+         fprintf (file, "\tmtlr %s\n", r0);            /* offset 24 */
+         fprintf (file, "\tlwz %s,0(%s)\n", r0, sc);   /* offset 28 */
+         fprintf (file, "\tlwz %s,4(%s)\n", sc, sc);   /* offset 32 */
+         fprintf (file, "\tmtctr %s\n", r0);           /* offset 36 */
+         fprintf (file, "\tbctr\n");                   /* offset 40 */
+       }
+      else
+       {
+         fprintf (file, "\tmflr %s\n", r0);            /* offset  0 */
+         fprintf (file, "\tbl .LTRAMP1\n");            /* offset  4 */
+         fprintf (file, "\t.long 0,0,0,0\n");          /* offset  8 */
+         fprintf (file, ".LTRAMP1:\n");
+         fprintf (file, "\tmflr %s\n", sc);            /* offset 28 */
+         fprintf (file, "\tmtlr %s\n", r0);            /* offset 32 */
+         fprintf (file, "\tld %s,0(%s)\n", r0, sc);    /* offset 36 */
+         fprintf (file, "\tld %s,8(%s)\n", sc, sc);    /* offset 40 */
+         fprintf (file, "\tmtctr %s\n", r0);           /* offset 44 */
+         fprintf (file, "\tbctr\n");                   /* offset 48 */
+       }
+      break;
+
+  /* NT function pointers point to a two word area (real address, TOC)
+     which unfortunately does not include a static chain field.  So we
+     use the function field to point to ..LTRAMP1 and the toc field
+     to point to the whole table.  */
+    case ABI_NT:
+      if (STATIC_CHAIN_REGNUM == 0
+         || STATIC_CHAIN_REGNUM == 2
+         || TARGET_64BIT
+         || !TARGET_NEW_MNEMONICS)
+       abort ();
+
+      fprintf (file, "\t.ualong 0\n");                 /* offset  0 */
+      fprintf (file, "\t.ualong 0\n");                 /* offset  4 */
+      fprintf (file, "\t.ualong 0\n");                 /* offset  8 */
+      fprintf (file, "\t.ualong 0\n");                 /* offset 12 */
+      fprintf (file, "\t.ualong 0\n");                 /* offset 16 */
+      fprintf (file, "..LTRAMP1:\n");                  /* offset 20 */
+      fprintf (file, "\tlwz %s,8(%s)\n", r0, r2);      /* offset 24 */
+      fprintf (file, "\tlwz %s,12(%s)\n", sc, r2);     /* offset 28 */
+      fprintf (file, "\tmtctr %s\n", r0);              /* offset 32 */
+      fprintf (file, "\tlwz %s,16(%s)\n", r2, r2);     /* offset 36 */
+      fprintf (file, "\tbctr\n");                      /* offset 40 */
+      break;
+    }
+
+  return;
+}
+
+/* Length in units of the trampoline for entering a nested function.  */
+
+int
+rs6000_trampoline_size ()
+{
+  int ret = 0;
+
+  switch (DEFAULT_ABI)
+    {
+    default:
+      abort ();
+
+    case ABI_AIX:
+      ret = (TARGET_32BIT) ? 12 : 24;
+      break;
+
+    case ABI_V4:
+    case ABI_AIX_NODESC:
+      ret = (TARGET_32BIT) ? 40 : 48;
+      break;
+
+    case ABI_NT:
+      ret = 20;
+      break;
+    }
+
+  return ret;
+}
+
+/* Emit RTL insns to initialize the variable parts of a trampoline.
+   FNADDR is an RTX for the address of the function's pure code.
+   CXT is an RTX for the static chain value for the function.  */
+
+void
+rs6000_initialize_trampoline (addr, fnaddr, cxt)
+     rtx addr;
+     rtx fnaddr;
+     rtx cxt;
+{
+  rtx reg, reg2, reg3;
+  enum machine_mode pmode = Pmode;
+
+  switch (DEFAULT_ABI)
+    {
+    default:
+      abort ();
+
+#define MEM_PLUS(addr,offset) gen_rtx (MEM, pmode, memory_address (pmode, plus_constant (addr, offset)))
+
+    /* Under AIX, just build the 3 word function descriptor */
+    case ABI_AIX:
+      emit_move_insn (gen_rtx (MEM, pmode, memory_address (pmode, addr)),
+                     gen_rtx (MEM, pmode, memory_address (pmode, fnaddr)));
+
+      emit_move_insn (MEM_PLUS (addr, 4), MEM_PLUS (fnaddr, 4));
+      emit_move_insn (MEM_PLUS (addr, 8), force_reg (pmode, cxt));
+      break;
+
+    /* Under V.4/eabi, update the two words after the bl to have the real
+       function address and the static chain.  */
+    case ABI_V4:
+    case ABI_AIX_NODESC:
+      reg = gen_reg_rtx (pmode);
+
+      emit_move_insn (reg, fnaddr);
+      emit_move_insn (MEM_PLUS (addr, 8), reg);
+      emit_move_insn (MEM_PLUS (addr, (TARGET_64BIT ? 16 : 12)), cxt);
+
+      rs6000_sync_trampoline (addr);
+      break;
+
+    /* Under NT, update the first word to point to the ..LTRAMP1 header,
+       second word will point to the whole trampoline, third-fifth words
+       will then have the real address, static chain, and toc value.  */
+    case ABI_NT:
+      addr = force_reg (pmode, addr);
+      reg = gen_reg_rtx (pmode);
+      reg2 = gen_reg_rtx (pmode);
+      emit_move_insn (reg, gen_rtx (SYMBOL_REF, pmode, "..LTRAMP1"));
+      emit_move_insn (reg2, fnaddr);
+      reg3 = force_reg (pmode, cxt);
+      emit_move_insn (MEM_PLUS (addr, 4), addr);
+      emit_move_insn (gen_rtx (MEM, pmode, addr), reg);
+      emit_move_insn (MEM_PLUS (addr, 8), reg2);
+      emit_move_insn (MEM_PLUS (addr, 12), reg3);
+      emit_move_insn (MEM_PLUS (addr, 16), gen_rtx (REG, pmode, 2));
+      break;
+    }
+
+  return;
+}
+
+\f
+/* If defined, a C expression whose value is nonzero if IDENTIFIER
+   with arguments ARGS is a valid machine specific attribute for DECL.
+   The attributes in ATTRIBUTES have previously been assigned to DECL.  */
+
+int
+rs6000_valid_decl_attribute_p (decl, attributes, identifier, args)
+     tree decl;
+     tree attributes;
+     tree identifier;
+     tree args;
+{
+  return 0;
+}
+
+/* If defined, a C expression whose value is nonzero if IDENTIFIER
+   with arguments ARGS is a valid machine specific attribute for TYPE.
+   The attributes in ATTRIBUTES have previously been assigned to TYPE.  */
+
+int
+rs6000_valid_type_attribute_p (type, attributes, identifier, args)
+     tree type;
+     tree attributes;
+     tree identifier;
+     tree args;
+{
+  if (TREE_CODE (type) != FUNCTION_TYPE
+      && TREE_CODE (type) != FIELD_DECL
+      && TREE_CODE (type) != TYPE_DECL)
+    return 0;
+
+  if (DEFAULT_ABI == ABI_NT)
+    {
+      /* Stdcall attribute says callee is responsible for popping arguments
+        if they are not variable.  */
+      if (is_attribute_p ("stdcall", identifier))
+       return (args == NULL_TREE);
+
+      /* Cdecl attribute says the callee is a normal C declaration */
+      if (is_attribute_p ("cdecl", identifier))
+       return (args == NULL_TREE);
+
+      /* Dllimport attribute says says the caller is to call the function
+        indirectly through a __imp_<name> pointer.  */
+      if (is_attribute_p ("dllimport", identifier))
+       return (args == NULL_TREE);
+
+      /* Dllexport attribute says says the callee is to create a __imp_<name>
+        pointer.  */
+      if (is_attribute_p ("dllexport", identifier))
+       return (args == NULL_TREE);
+    }
+
+  return 0;
+}
+
+/* If defined, a C expression whose value is zero if the attributes on
+   TYPE1 and TYPE2 are incompatible, one if they are compatible, and
+   two if they are nearly compatible (which causes a warning to be
+   generated).  */
+
+int
+rs6000_comp_type_attributes (type1, type2)
+     tree type1;
+     tree type2;
+{
+  return 1;
+}
+
+/* If defined, a C statement that assigns default attributes to newly
+   defined TYPE.  */
+
+void
+rs6000_set_default_type_attributes (type)
+     tree type;
+{
+}
+
+/* Return a dll import reference corresponding to to a call's SYMBOL_REF */
+struct rtx_def *
+rs6000_dll_import_ref (call_ref)
+     rtx call_ref;
+{
+  char *call_name;
+  int len;
+  char *p;
+  rtx reg1, reg2;
+  tree node;
+
+  if (GET_CODE (call_ref) != SYMBOL_REF)
+    abort ();
+
+  call_name = XSTR (call_ref, 0);
+  len = sizeof ("__imp_") + strlen (call_name);
+  p = alloca (len);
+  reg2 = gen_reg_rtx (Pmode);
+
+  strcpy (p, "__imp_");
+  strcat (p, call_name);
+  node = get_identifier (p);
+
+  reg1 = force_reg (Pmode, gen_rtx (SYMBOL_REF, VOIDmode, IDENTIFIER_POINTER (node)));
+  emit_move_insn (reg2, gen_rtx (MEM, Pmode, reg1));
+
+  return reg2;
+}
+
+\f
+/* A C statement or statements to switch to the appropriate section
+   for output of RTX in mode MODE.  You can assume that RTX is some
+   kind of constant in RTL.  The argument MODE is redundant except in
+   the case of a `const_int' rtx.  Select the section by calling
+   `text_section' or one of the alternatives for other sections.
+
+   Do not define this macro if you put all constants in the read-only
+   data section.  */
+
+#ifdef USING_SVR4_H
+
+void
+rs6000_select_rtx_section (mode, x)
+     enum machine_mode mode;
+     rtx x;
+{
+  if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x))
+    toc_section ();
+  else
+    const_section ();
+}
+
+/* A C statement or statements to switch to the appropriate
+   section for output of DECL.  DECL is either a `VAR_DECL' node
+   or a constant of some sort.  RELOC indicates whether forming
+   the initial value of DECL requires link-time relocations.  */
+
+void
+rs6000_select_section (decl, reloc)
+     tree decl;
+     int reloc;
+{
+  int size = int_size_in_bytes (TREE_TYPE (decl));
+
+  if (TREE_CODE (decl) == STRING_CST)
+    {
+      if (! flag_writable_strings)
+       const_section ();
+      else
+       data_section ();
+    }
+  else if (TREE_CODE (decl) == VAR_DECL)
+    {
+      if ((flag_pic && reloc)
+         || !TREE_READONLY (decl)
+         || TREE_SIDE_EFFECTS (decl)
+         || !DECL_INITIAL (decl)
+         || (DECL_INITIAL (decl) != error_mark_node
+             && !TREE_CONSTANT (DECL_INITIAL (decl))))
+       {
+         if (TARGET_SDATA && (size > 0) && (size <= g_switch_value))
+           sdata_section ();
+         else
+           data_section ();
+       }
+      else
+       {
+         if (TARGET_SDATA && (size > 0) && (size <= g_switch_value))
+           sdata2_section ();
+         else
+           const_section ();
+       }
+    }
+  else
+    const_section ();
+}
+#endif /* USING_SVR4_H */