OSDN Git Service

(rs6000_output_load_toc_table): New function.
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.c
index cb05d88..c009eff 100644 (file)
@@ -1,5 +1,5 @@
 /* Subroutines used for code generation on IBM RS/6000.
-   Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1991, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
 
 This file is part of GNU CC.
@@ -36,6 +36,8 @@ Boston, MA 02111-1307, USA.  */
 #include "expr.h"
 #include "obstack.h"
 #include "tree.h"
+#include "except.h"
+#include "function.h"
 
 #ifndef TARGET_NO_PROTOTYPE
 #define TARGET_NO_PROTOTYPE 0
@@ -69,9 +71,9 @@ static int trunc_defined;
 
 /* Set to non-zero once AIX common-mode calls have been defined.  */
 static int common_mode_defined;
+
 /* Save information from a "cmpxx" operation until the branch or scc is
    emitted.  */
-
 rtx rs6000_compare_op0, rs6000_compare_op1;
 int rs6000_compare_fp_p;
 
@@ -79,115 +81,61 @@ int rs6000_compare_fp_p;
 /* Label number of label created for -mrelocatable, to call to so we can
    get the address of the GOT section */
 int rs6000_pic_labelno;
+
+/* Which abi to adhere to */
+char *rs6000_abi_name = RS6000_ABI_NAME;
+
+/* Semantics of the small data area */
+enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
+
+/* Which small data model to use */
+char *rs6000_sdata_name = (char *)0;
 #endif
 
 /* 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];
+/* Offset & size for fpmem stack locations used for converting between
+   float and integral types.  */
+int rs6000_fpmem_offset;
+int rs6000_fpmem_size;
 
 \f
-/* Print the options used in the assembly file.  */
-
-extern char *version_string, *language_string;
-
-struct asm_option
+/* Default register names.  */
+char rs6000_reg_names[][8] =
 {
-  char *string;
-  int *variable;
-  int on_value;
+      "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",
+      "8",  "9", "10", "11", "12", "13", "14", "15",
+     "16", "17", "18", "19", "20", "21", "22", "23",
+     "24", "25", "26", "27", "28", "29", "30", "31",
+      "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",
+      "8",  "9", "10", "11", "12", "13", "14", "15",
+     "16", "17", "18", "19", "20", "21", "22", "23",
+     "24", "25", "26", "27", "28", "29", "30", "31",
+     "mq", "lr", "ctr","ap",
+      "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",
+  "fpmem"
 };
 
-#define MAX_LINE 79
-
-static int
-output_option (file, type, name, pos)
-     FILE *file;
-     char *type;
-     char *name;
-     int pos;
+#ifdef TARGET_REGNAMES
+static char alt_reg_names[][8] =
 {
-  int type_len = strlen (type);
-  int name_len = strlen (name);
-
-  if (1 + type_len + name_len + pos > MAX_LINE)
-    {
-      fprintf (file, "\n # %s%s", type, name);
-      return 3 + type_len + name_len;
-    }
-  fprintf (file, " %s%s", type, name);
-  return pos + 1 + type_len + name_len;
-}
-
-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 asm_option *f_options;
-     int f_len;
-     struct asm_option *W_options;
-     int W_len;
-{
-  int j;
-  int flags = target_flags;
-  int pos = 32767;
-
-  fprintf (file, " # %s %s", language_string, version_string);
-
-  if (optimize)
-    {
-      char opt_string[20];
-      sprintf (opt_string, "%d", optimize);
-      pos = output_option (file, "-O", opt_string, pos);
-    }
-
-  if (profile_flag)
-    pos = output_option (file, "-p", "", pos);
-
-  if (profile_block_flag)
-    pos = output_option (file, "-a", "", pos);
-
-  if (inhibit_warnings)
-    pos = output_option (file, "-w", "", pos);
-
-  for (j = 0; j < f_len; j++)
-    {
-      if (*f_options[j].variable == f_options[j].on_value)
-       pos = output_option (file, "-f", f_options[j].string, pos);
-    }
-
-  for (j = 0; j < W_len; j++)
-    {
-      if (*W_options[j].variable == W_options[j].on_value)
-       pos = output_option (file, "-W", W_options[j].string, pos);
-    }
-
-  for (j = 0; j < sizeof m_options / sizeof m_options[0]; j++)
-    {
-      if (m_options[j].name[0] != '\0'
-         && m_options[j].value > 0
-         && ((m_options[j].value & flags) == m_options[j].value))
-       {
-         pos = output_option (file, "-m", m_options[j].name, pos);
-         flags &= ~ m_options[j].value;
-       }
-    }
-
-  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);
-}
-
+   "%r0",   "%r1",  "%r2",  "%r3",  "%r4",  "%r5",  "%r6",  "%r7",
+   "%r8",   "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
+  "%r16",  "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
+  "%r24",  "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
+   "%f0",   "%f1",  "%f2",  "%f3",  "%f4",  "%f5",  "%f6",  "%f7",
+   "%f8",   "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
+  "%f16",  "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
+  "%f24",  "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
+    "mq",    "lr",  "ctr",   "ap",
+  "%cr0",  "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
+ "fpmem"
+};
+#endif
 \f
 /* Override command line options.  Mostly we process the processor
    type and sometimes adjust other TARGET_ options.  */
@@ -249,7 +197,7 @@ rs6000_override_options (default_cpu)
         {"601", PROCESSOR_PPC601,
            MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
            MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
-        {"602", PROCESSOR_PPC602,
+        {"602", PROCESSOR_PPC603,
            MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
            POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
         {"603", PROCESSOR_PPC603,
@@ -261,12 +209,21 @@ rs6000_override_options (default_cpu)
         {"604", PROCESSOR_PPC604,
            MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
            POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
+        {"604e", PROCESSOR_PPC604,
+           MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
+           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},
+        {"801", PROCESSOR_MPCCORE,
+           MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
+           POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
         {"821", PROCESSOR_MPCCORE,
            MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
            POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
+        {"823", 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}};
@@ -335,11 +292,67 @@ rs6000_override_options (default_cpu)
        }
     }
 
+#ifdef TARGET_REGNAMES
+  /* If the user desires alternate register names, copy in the alternate names
+     now.  */
+  if (TARGET_REGNAMES)
+    bcopy ((char *)alt_reg_names, (char *)rs6000_reg_names, sizeof (rs6000_reg_names));
+#endif
+
 #ifdef SUBTARGET_OVERRIDE_OPTIONS
   SUBTARGET_OVERRIDE_OPTIONS;
 #endif
 }
 \f
+/* Do anything needed at the start of the asm file.  */
+
+void
+rs6000_file_start (file, default_cpu)
+     FILE *file;
+     char *default_cpu;
+{
+  int i;
+  char buffer[80];
+  char *start = buffer;
+  struct rs6000_cpu_select *ptr;
+
+  if (flag_verbose_asm)
+    {
+      sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
+      rs6000_select[0].string = default_cpu;
+
+      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')
+           {
+             fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
+             start = "";
+           }
+       }
+
+#ifdef USING_SVR4_H
+      switch (rs6000_sdata)
+       {
+       case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
+       case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
+       case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
+       case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
+       }
+
+      if (rs6000_sdata && g_switch_value)
+       {
+         fprintf (file, "%s -G %d", start, g_switch_value);
+         start = "";
+       }
+#endif
+
+      if (*start == '\0')
+       fputs ("\n", file);
+    }
+}
+
+\f
 /* Create a CONST_DOUBLE from a string.  */
 
 struct rtx_def *
@@ -414,6 +427,26 @@ int count_register_operand(op, mode)
   return 0;
 }
 
+/* Returns 1 if op is memory location for float/int conversions that masquerades
+   as a register.  */
+int fpmem_operand(op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  if (GET_CODE (op) != REG)
+    return 0;
+
+  if (FPMEM_REGNO_P (REGNO (op)))
+    return 1;
+
+#if 0
+  if (REGNO (op) > FIRST_PSEUDO_REGISTER)
+    return 1;
+#endif
+
+  return 0;
+}
+
 /* Return 1 if OP is a constant that can fit in a D field.  */
 
 int
@@ -422,7 +455,7 @@ short_cint_operand (op, mode)
      enum machine_mode mode;
 {
   return (GET_CODE (op) == CONST_INT
-         && (unsigned) (INTVAL (op) + 0x8000) < 0x10000);
+         && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) < 0x10000);
 }
 
 /* Similar for a unsigned D field.  */
@@ -443,7 +476,7 @@ non_short_cint_operand (op, mode)
      enum machine_mode mode;
 {
   return (GET_CODE (op) == CONST_INT
-         && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000);
+         && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
 }
 
 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
@@ -455,7 +488,9 @@ gpc_reg_operand (op, mode)
      enum machine_mode mode;
 {
   return (register_operand (op, mode)
-         && (GET_CODE (op) != REG || REGNO (op) >= 67 || REGNO (op) < 64));
+         && (GET_CODE (op) != REG
+             || (REGNO (op) >= 67 && !FPMEM_REGNO_P (REGNO (op)))
+             || REGNO (op) < 64));
 }
 
 /* Returns 1 if OP is either a pseudo-register or a register denoting a
@@ -524,6 +559,109 @@ reg_or_cint_operand (op, mode)
      return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode);
 }
 
+/* Return 1 if the operand is an operand that can be loaded via the GOT */
+
+int
+got_operand (op, mode)
+     register rtx op;
+     enum machine_mode mode;
+{
+  return (GET_CODE (op) == SYMBOL_REF
+         || GET_CODE (op) == CONST
+         || GET_CODE (op) == LABEL_REF);
+}
+
+/* Return the number of instructions it takes to form a constant in an
+   integer register.  */
+
+static int
+num_insns_constant_wide (value)
+     HOST_WIDE_INT value;
+{
+  /* signed constant loadable with {cal|addi} */
+  if (((unsigned HOST_WIDE_INT)value + 0x8000) < 0x10000)
+    return 1;
+
+#if HOST_BITS_PER_WIDE_INT == 32
+  /* constant loadable with {cau|addis} */
+  else if ((value & 0xffff) == 0)
+    return 1;
+
+#else
+  /* constant loadable with {cau|addis} */
+  else if ((value & 0xffff) == 0 && (value & ~0xffffffff) == 0)
+    return 1;
+
+  else if (TARGET_64BIT)
+    {
+      HOST_WIDE_INT low  = value & 0xffffffff;
+      HOST_WIDE_INT high = value >> 32;
+
+      if (high == 0 && (low & 0x80000000) == 0)
+       return 2;
+
+      else if (high == 0xffffffff && (low & 0x80000000) != 0)
+       return 2;
+
+      else if (!low)
+       return num_insns_constant_wide (high) + 1;
+
+      else
+       return (num_insns_constant_wide (high)
+               + num_insns_constant_wide (low) + 1);
+    }
+#endif
+
+  else
+    return 2;
+}
+
+int
+num_insns_constant (op, mode)
+     rtx op;
+     enum machine_mode mode;
+{
+  if (GET_CODE (op) == CONST_INT)
+    return num_insns_constant_wide (INTVAL (op));
+
+  else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
+    {
+      long l;
+      REAL_VALUE_TYPE rv;
+
+      REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
+      REAL_VALUE_TO_TARGET_SINGLE (rv, l);
+      return num_insns_constant_wide ((HOST_WIDE_INT)l);
+    }
+
+  else if (GET_CODE (op) == CONST_DOUBLE && TARGET_32BIT)
+    return (num_insns_constant_wide (CONST_DOUBLE_LOW (op))
+           + num_insns_constant_wide (CONST_DOUBLE_HIGH (op)));
+
+  else if (GET_CODE (op) == CONST_DOUBLE && TARGET_64BIT)
+    {
+      HOST_WIDE_INT low  = CONST_DOUBLE_LOW (op);
+      HOST_WIDE_INT high = CONST_DOUBLE_HIGH (op);
+
+      if (high == 0 && (low & 0x80000000) == 0)
+       return num_insns_constant_wide (low);
+
+      else if (((high & 0xffffffff) == 0xffffffff)
+              && ((low & 0x80000000) != 0))
+       return num_insns_constant_wide (low);
+
+      else if (low == 0)
+       return num_insns_constant_wide (high) + 1;
+
+      else
+       return (num_insns_constant_wide (high)
+               + num_insns_constant_wide (low) + 1);
+    }
+
+  else
+    abort ();
+}
+
 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register
    with one instruction per word.  We only do this if we can safely read
    CONST_DOUBLE_{LOW,HIGH}.  */
@@ -535,13 +673,23 @@ easy_fp_constant (op, mode)
 {
   if (GET_CODE (op) != CONST_DOUBLE
       || GET_MODE (op) != mode
-      || GET_MODE_CLASS (mode) != MODE_FLOAT)
+      || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
     return 0;
 
   /* Consider all constants with -msoft-float to be easy */
-  if (TARGET_SOFT_FLOAT)
+  if (TARGET_SOFT_FLOAT && mode != DImode)
     return 1;
 
+  /* If we are using V.4 style PIC, consider all constants to be hard */
+  if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
+    return 0;
+
+#ifdef TARGET_RELOCATABLE
+  /* Similarly if we are using -mrelocatable, consider all constants to be hard */
+  if (TARGET_RELOCATABLE)
+    return 0;
+#endif
+
   if (mode == DFmode)
     {
       long k[2];
@@ -550,10 +698,11 @@ easy_fp_constant (op, mode)
       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));
+      return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1
+             && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1);
     }
-  else
+
+  else if (mode == SFmode)
     {
       long l;
       REAL_VALUE_TYPE rv;
@@ -561,8 +710,14 @@ easy_fp_constant (op, mode)
       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
       REAL_VALUE_TO_TARGET_SINGLE (rv, l);
 
-      return ((unsigned) (l + 0x8000) < 0x10000 || (l & 0xffff) == 0);
+      return num_insns_constant_wide (l) == 1;
     }
+
+  else if (mode == DImode && TARGET_32BIT)
+    return num_insns_constant (op, DImode) == 2;
+
+  else
+    abort ();
 }
 
 /* Return 1 if the operand is in volatile memory.  Note that during the
@@ -604,22 +759,6 @@ offsettable_addr_operand (op, mode)
                                mode, op);
 }
 
-/* Return 1 if the operand is either a floating-point register, a pseudo
-   register, or memory.  */
-
-int
-fp_reg_or_mem_operand (op, mode)
-     register rtx op;
-     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
-                 || FP_REGNO_P (REGNO (op)))));
-}
-
 /* Return 1 if the operand is either an easy FP constant (see above) or
    memory.  */
 
@@ -651,7 +790,7 @@ non_add_cint_operand (op, mode)
      enum machine_mode mode;
 {
   return (GET_CODE (op) == CONST_INT
-         && (unsigned) (INTVAL (op) + 0x8000) >= 0x10000
+         && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000
          && (INTVAL (op) & 0xffff) != 0);
 }
 
@@ -821,6 +960,11 @@ input_operand (op, mode)
       && easy_fp_constant (op, mode))
     return 1;
 
+  /* Allow any integer constant.  */
+  if (GET_MODE_CLASS (mode) == MODE_INT
+      && (GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE))
+    return 1;
+
   /* For floating-point or multi-word mode, the only remaining valid type
      is a register.  */
   if (GET_MODE_CLASS (mode) == MODE_FLOAT
@@ -833,10 +977,6 @@ input_operand (op, mode)
   if (register_operand (op, mode))
     return 1;
 
-  /* 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;
@@ -849,7 +989,7 @@ input_operand (op, mode)
 
   /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
      to be valid.  */
-  if (DEFAULT_ABI == ABI_V4
+  if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
       && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
       && small_data_operand (op, Pmode))
     return 1;
@@ -864,14 +1004,13 @@ small_data_operand (op, mode)
      rtx op;
      enum machine_mode mode;
 {
+#ifdef TARGET_SDATA
   rtx sym_ref, const_part;
 
-#ifdef TARGET_SDATA
-  if (!TARGET_SDATA)
+  if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
     return 0;
-#endif
 
-  if (DEFAULT_ABI != ABI_V4)
+  if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
     return 0;
 
   if (GET_CODE (op) == SYMBOL_REF)
@@ -890,6 +1029,10 @@ small_data_operand (op, mode)
     return 0;
 
   return 1;
+
+#else
+  return 0;
+#endif
 }
 
 \f
@@ -898,7 +1041,7 @@ small_data_operand (op, mode)
    For a library call, FNTYPE is 0.
 
    For incoming args we set the number of arguments in the prototype large
-   so we never return an EXPR_LIST.  */
+   so we never return a PARALLEL.  */
 
 void
 init_cumulative_args (cum, fntype, libname, incoming)
@@ -918,8 +1061,8 @@ init_cumulative_args (cum, fntype, libname, incoming)
 
   if (incoming)
     {
-      cum->nargs_prototype = 1000;             /* don't return an EXPR_LIST */
-      if (abi == ABI_V4)
+      cum->nargs_prototype = 1000;             /* don't return a PARALLEL */
+      if (abi == ABI_V4 || abi == ABI_SOLARIS)
        cum->varargs_offset = RS6000_VARARGS_OFFSET;
     }
 
@@ -939,6 +1082,10 @@ init_cumulative_args (cum, fntype, libname, incoming)
       && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (fntype)))
     cum->call_cookie = CALL_NT_DLLIMPORT;
 
+  /* Also check for longcall's */
+  else if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)))
+    cum->call_cookie = CALL_LONG;
+
   if (TARGET_DEBUG_ARG)
     {
       fprintf (stderr, "\ninit_cumulative_args:");
@@ -949,12 +1096,15 @@ init_cumulative_args (cum, fntype, libname, incoming)
                   tree_code_name[ (int)TREE_CODE (ret_type) ]);
        }
 
-      if (abi == ABI_V4 && incoming)
+      if ((abi == ABI_V4 || abi == ABI_SOLARIS) && incoming)
        fprintf (stderr, " varargs = %d, ", cum->varargs_offset);
 
-      if (cum->call_cookie == CALL_NT_DLLIMPORT)
+      if (cum->call_cookie & CALL_NT_DLLIMPORT)
        fprintf (stderr, " dllimport,");
 
+      if (cum->call_cookie & CALL_LONG)
+       fprintf (stderr, " longcall,");
+
       fprintf (stderr, " proto = %d, nargs = %d\n",
               cum->prototype, cum->nargs_prototype);
     }
@@ -973,7 +1123,7 @@ function_arg_boundary (mode, type)
      enum machine_mode mode;
      tree type;
 {
-  if (DEFAULT_ABI == ABI_V4 && mode == DImode)
+  if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && mode == DImode)
     return 64;
 
   if (DEFAULT_ABI != ABI_NT || TARGET_64BIT)
@@ -1000,7 +1150,7 @@ function_arg_advance (cum, mode, type, named)
   cum->words += align;
   cum->nargs_prototype--;
 
-  if (DEFAULT_ABI == ABI_V4)
+  if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
     {
       /* Long longs must not be split between registers and stack */
       if ((GET_MODE_CLASS (mode) != MODE_FLOAT || TARGET_SOFT_FLOAT)
@@ -1060,7 +1210,7 @@ function_arg_advance (cum, mode, type, named)
    both an FP and integer register (or possibly FP reg and stack).  Library
    functions (when TYPE is zero) always have the proper types for args,
    so we can pass the FP value just in one register.  emit_library_function
-   doesn't support EXPR_LIST anyway.  */
+   doesn't support PARALLEL anyway.  */
 
 struct rtx_def *
 function_arg (cum, mode, type, named)
@@ -1084,17 +1234,15 @@ function_arg (cum, mode, type, named)
     {
       enum rs6000_abi abi = DEFAULT_ABI;
 
-      if (abi == ABI_V4
+      if ((abi == ABI_V4 || abi == ABI_SOLARIS)
          && TARGET_HARD_FLOAT
          && cum->nargs_prototype < 0
          && type && (cum->prototype || TARGET_NO_PROTOTYPE))
        {
-         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 (cum->call_cookie
+                         | ((cum->fregno == FP_ARG_MIN_REG)
+                            ? CALL_V4_SET_FP_ARGS
+                            : CALL_V4_CLEAR_FP_ARGS));
        }
 
       return GEN_INT (cum->call_cookie);
@@ -1102,7 +1250,7 @@ function_arg (cum, mode, type, named)
 
   if (!named)
     {
-      if (DEFAULT_ABI != ABI_V4)
+      if (DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
        return NULL_RTX;
     }
 
@@ -1111,20 +1259,41 @@ function_arg (cum, mode, type, named)
 
   if (USE_FP_FOR_ARG_P (*cum, mode, type))
     {
-      if ((cum->nargs_prototype > 0)
-         || (DEFAULT_ABI == ABI_V4)    /* V.4 never passes FP values in GP registers */
-         || !type)
+      if (DEFAULT_ABI == ABI_V4 /* V.4 never passes FP values in GP registers */
+         || DEFAULT_ABI == ABI_SOLARIS
+         || ! type
+         || ((cum->nargs_prototype > 0)
+             /* IBM AIX extended its linkage convention definition always to
+                require FP args after register save area hole on the stack.  */
+             && (DEFAULT_ABI != ABI_AIX
+                 || ! TARGET_XL_CALL
+                 || (align_words < GP_ARG_NUM_REG))))
        return gen_rtx (REG, mode, cum->fregno);
 
-      return gen_rtx (EXPR_LIST, VOIDmode,
-                     ((align_words < GP_ARG_NUM_REG)
-                      ? gen_rtx (REG, mode, GP_ARG_MIN_REG + align_words)
-                      : NULL_RTX),
-                     gen_rtx (REG, mode, cum->fregno));
+      return gen_rtx (PARALLEL, mode,
+                     gen_rtvec
+                     (2,
+                      gen_rtx (EXPR_LIST, VOIDmode,
+                               ((align_words >= GP_ARG_NUM_REG)
+                                ? NULL_RTX
+                                : (align_words
+                                   + RS6000_ARG_SIZE (mode, type, named)
+                                   > GP_ARG_NUM_REG
+                                   /* If this is partially on the stack, then
+                                      we only include the portion actually
+                                      in registers here.  */
+                                   ? gen_rtx (REG, SImode,
+                                              GP_ARG_MIN_REG + align_words)
+                                   : gen_rtx (REG, mode,
+                                              GP_ARG_MIN_REG + align_words))),
+                               const0_rtx),
+                      gen_rtx (EXPR_LIST, VOIDmode,
+                               gen_rtx (REG, mode, cum->fregno),
+                               const0_rtx)));
     }
 
   /* Long longs won't be split between register and stack */
-  else if (DEFAULT_ABI == ABI_V4 &&
+  else if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) &&
           align_words + RS6000_ARG_SIZE (mode, type, named) > GP_ARG_NUM_REG)
     {
       return NULL_RTX;
@@ -1150,7 +1319,7 @@ function_arg_partial_nregs (cum, mode, type, named)
   if (! named)
     return 0;
 
-  if (DEFAULT_ABI == ABI_V4)
+  if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
     return 0;
 
   if (USE_FP_FOR_ARG_P (*cum, mode, type))
@@ -1187,7 +1356,8 @@ function_arg_pass_by_reference (cum, mode, type, named)
      tree type;
      int named;
 {
-  if (DEFAULT_ABI == ABI_V4 && type && AGGREGATE_TYPE_P (type))
+  if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
+      && type && AGGREGATE_TYPE_P (type))
     {
       if (TARGET_DEBUG_ARG)
        fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
@@ -1230,7 +1400,7 @@ 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);
 
-  if (DEFAULT_ABI == ABI_V4 && !no_rtl)
+  if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && !no_rtl)
     {
       rs6000_sysv_varargs_p = 1;
       save_area = plus_constant (frame_pointer_rtx, RS6000_VARARGS_OFFSET);
@@ -1258,7 +1428,7 @@ setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
     }
 
   /* Save FP registers if needed.  */
-  if (DEFAULT_ABI == ABI_V4 && TARGET_HARD_FLOAT && !no_rtl)
+  if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS) && TARGET_HARD_FLOAT && !no_rtl)
     {
       int fregno     = cum->fregno;
       int num_fp_reg = FP_ARG_V4_MAX_REG + 1 - fregno;
@@ -1312,35 +1482,6 @@ expand_builtin_saveregs (args)
 }
 
 \f
-/* Allocate a stack temp.  Only allocate one stack temp per type for a
-   function.  */
-
-struct rtx_def *
-rs6000_stack_temp (mode, size)
-     enum machine_mode mode;
-     int size;
-{
-  rtx temp = stack_temps[ (int)mode ];
-  rtx addr;
-
-  if (temp == NULL_RTX)
-    {
-      temp = assign_stack_local (mode, size, 0);
-      addr = XEXP (temp, 0);
-
-      if ((size > 4 && !offsettable_address_p (0, mode, addr))
-         || (size <= 4 && !memory_address_p (mode, addr)))
-       {
-         XEXP (temp, 0) = copy_addr_to_reg (addr);
-       }
-
-      stack_temps[ (int)mode ] = temp;
-    }
-
-  return temp;
-}
-
-\f
 /* Generate a memory reference for expand_block_move, copying volatile,
    and other bits from an original memory reference.  */
 
@@ -1751,7 +1892,7 @@ includes_rshift_p (shiftop, andop)
      register rtx shiftop;
      register rtx andop;
 {
-  unsigned shift_mask = ~0;
+  unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
 
   shift_mask >>= INTVAL (shiftop);
 
@@ -1921,8 +2062,219 @@ ccr_bit (op, scc_p)
     }
 }
 \f
+/* Return the GOT register, creating it if needed.  */
+
+struct rtx_def *
+rs6000_got_register (value)
+     rtx value;
+{
+  if (!current_function_uses_pic_offset_table || !pic_offset_table_rtx)
+    {
+      if (reload_in_progress || reload_completed)
+       fatal_insn ("internal error -- needed new GOT register during reload phase to load:", value);
+
+      current_function_uses_pic_offset_table = 1;
+      pic_offset_table_rtx = gen_rtx (REG, Pmode, GOT_TOC_REGNUM);
+    }
+
+  return pic_offset_table_rtx;
+}
+
+\f
+/* Replace all occurances of register FROM with an new pseduo register in an insn X.
+   Store the pseudo register used in REG.
+   This is only safe during FINALIZE_PIC, since the registers haven't been setup
+   yet.  */
+
+static rtx
+rs6000_replace_regno (x, from, reg)
+     rtx x;
+     int from;
+     rtx *reg;
+{
+  register int i, j;
+  register char *fmt;
+
+  /* Allow this function to make replacements in EXPR_LISTs.  */
+  if (!x)
+    return x;
+
+  switch (GET_CODE (x))
+    {
+    case SCRATCH:
+    case PC:
+    case CC0:
+    case CONST_INT:
+    case CONST_DOUBLE:
+    case CONST:
+    case SYMBOL_REF:
+    case LABEL_REF:
+      return x;
+
+    case REG:
+      if (REGNO (x) == from)
+       {
+         if (! *reg)
+           *reg = pic_offset_table_rtx = gen_reg_rtx (Pmode);
+
+         return *reg;
+       }
+
+      return x;
+    }
+
+  fmt = GET_RTX_FORMAT (GET_CODE (x));
+  for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
+    {
+      if (fmt[i] == 'e')
+       XEXP (x, i) = rs6000_replace_regno (XEXP (x, i), from, reg);
+      else if (fmt[i] == 'E')
+       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
+         XVECEXP (x, i, j) = rs6000_replace_regno (XVECEXP (x, i, j), from, reg);
+    }
+
+  return x;
+}  
+
+\f
+/* By generating position-independent code, when two different
+   programs (A and B) share a common library (libC.a), the text of
+   the library can be shared whether or not the library is linked at
+   the same address for both programs.  In some of these
+   environments, position-independent code requires not only the use
+   of different addressing modes, but also special code to enable the
+   use of these addressing modes.
+
+   The `FINALIZE_PIC' macro serves as a hook to emit these special
+   codes once the function is being compiled into assembly code, but
+   not before.  (It is not done before, because in the case of
+   compiling an inline function, it would lead to multiple PIC
+   prologues being included in functions which used inline functions
+   and were compiled to assembly language.)  */
+
+void
+rs6000_finalize_pic ()
+{
+  /* Loop through all of the insns, replacing the special GOT_TOC_REGNUM
+     with an appropriate pseduo register.  If we find we need GOT/TOC,
+     add the appropriate init code.  */
+  if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
+    {
+      rtx insn = get_insns ();
+      rtx reg = NULL_RTX;
+      rtx first_insn;
+
+      if (GET_CODE (insn) == NOTE)
+       insn = next_nonnote_insn (insn);
+
+      first_insn = insn;
+      for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn))
+       {
+         if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
+           {
+             PATTERN (insn) = rs6000_replace_regno (PATTERN (insn),
+                                                    GOT_TOC_REGNUM,
+                                                    &reg);
+
+             if (REG_NOTES (insn))
+               REG_NOTES (insn) = rs6000_replace_regno (REG_NOTES (insn),
+                                                        GOT_TOC_REGNUM,
+                                                        &reg);
+           }
+       }
+
+      if (reg)
+       {
+         rtx init = gen_init_v4_pic (reg);
+         emit_insn_before (init, first_insn);
+       }
+    }
+}
+
+\f
+/* Search for any occurrance of the GOT_TOC register marker that should
+   have been eliminated, but may have crept back in.  */
+
+void
+rs6000_reorg (insn)
+     rtx insn;
+{
+  if (flag_pic && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
+    {
+      rtx got_reg = gen_rtx (REG, Pmode, GOT_TOC_REGNUM);
+      for ( ; insn != NULL_RTX; insn = NEXT_INSN (insn))
+       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
+           && reg_mentioned_p (got_reg, PATTERN (insn)))
+         fatal_insn ("GOT/TOC register marker not removed:", PATTERN (insn));
+    }
+}
+
+\f
+/* Define the structure for the machine field in struct function.  */
+struct machine_function
+{
+  int sysv_varargs_p;
+  int save_toc_p;
+  int fpmem_size;
+  int fpmem_offset;
+};
+
+/* Functions to save and restore rs6000_fpmem_size.
+   These will be called, via pointer variables,
+   from push_function_context and pop_function_context.  */
+
+void
+rs6000_save_machine_status (p)
+     struct function *p;
+{
+  struct machine_function *machine =
+    (struct machine_function *) xmalloc (sizeof (struct machine_function));
+
+  p->machine = machine;
+  machine->sysv_varargs_p = rs6000_sysv_varargs_p;
+  machine->fpmem_size     = rs6000_fpmem_size;
+  machine->fpmem_offset   = rs6000_fpmem_offset;
+}
+
+void
+rs6000_restore_machine_status (p)
+     struct function *p;
+{
+  struct machine_function *machine = p->machine;
+
+  rs6000_sysv_varargs_p = machine->sysv_varargs_p;
+  rs6000_fpmem_size     = machine->fpmem_size;
+  rs6000_fpmem_offset   = machine->fpmem_offset;
+
+  free (machine);
+  p->machine = (struct machine_function *)0;
+}
+
+/* Do anything needed before RTL is emitted for each function.  */
+
+void
+rs6000_init_expanders ()
+{
+  /* Reset varargs and save TOC indicator */
+  rs6000_sysv_varargs_p = 0;
+  rs6000_fpmem_size = 0;
+  rs6000_fpmem_offset = 0;
+  pic_offset_table_rtx = (rtx)0;
+
+  /* Arrange to save and restore machine status around nested functions.  */
+  save_machine_status = rs6000_save_machine_status;
+  restore_machine_status = rs6000_restore_machine_status;
+}
+
+\f
 /* Print an operand.  Recognize special options, documented below.  */
 
+#ifdef TARGET_SDATA
+#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
+#else
+#define SMALL_DATA_RELOC "sda21"
+#endif
+
 void
 print_operand (file, x, code)
     FILE *file;
@@ -1953,6 +2305,12 @@ print_operand (file, x, code)
       fputs (TARGET_MINIMAL_TOC ? reg_names[30] : reg_names[2], file);
       return;
 
+    case '$':
+      /* Write out either a '.' or '$' for the current location, depending
+        on whether this is Solaris or not.  */
+      putc ((DEFAULT_ABI == ABI_SOLARIS) ? '.' : '$', file);
+      return;
+
     case 'A':
       /* If X is a constant integer whose low-order 5 bits are zero,
         write 'l'.  Otherwise, write 'r'.  This is a kludge to fix a bug
@@ -2102,7 +2460,7 @@ print_operand (file, x, code)
       /* Write second word of DImode or DFmode reference.  Works on register
         or non-indexed memory only.  */
       if (GET_CODE (x) == REG)
-       fprintf (file, "%d", REGNO (x) + 1);
+       fprintf (file, "%s", reg_names[REGNO (x) + 1]);
       else if (GET_CODE (x) == MEM)
        {
          /* Handle possible auto-increment.  Since it is pre-increment and
@@ -2112,8 +2470,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]);
+         if (small_data_operand (x, GET_MODE (x)))
+           fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
        }
       return;
                            
@@ -2273,13 +2631,29 @@ print_operand (file, x, code)
       return;
       
     case 'u':
-      /* High-order 16 bits of constant.  */
+      /* High-order 16 bits of constant for use in unsigned operand.  */
       if (! INT_P (x))
        output_operand_lossage ("invalid %%u value");
 
       fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff);
       return;
 
+    case 'v':
+      /* High-order 16 bits of constant for use in signed operand.  */
+      if (! INT_P (x))
+       output_operand_lossage ("invalid %%v value");
+
+      {
+       int value = (INT_LOWPART (x) >> 16) & 0xffff;
+
+       /* Solaris assembler doesn't like lis 0,0x80000 */
+       if (DEFAULT_ABI == ABI_SOLARIS && (value & 0x8000) != 0)
+         fprintf (file, "%d", value | (~0 << 16));
+       else
+         fprintf (file, "0x%x", value);
+       return;
+      }
+
     case 'U':
       /* Print `u' if this has an auto-increment or auto-decrement.  */
       if (GET_CODE (x) == MEM
@@ -2316,7 +2690,7 @@ print_operand (file, x, code)
     case 'Y':
       /* Like 'L', for third word of TImode  */
       if (GET_CODE (x) == REG)
-       fprintf (file, "%d", REGNO (x) + 2);
+       fprintf (file, "%s", reg_names[REGNO (x) + 2]);
       else if (GET_CODE (x) == MEM)
        {
          if (GET_CODE (XEXP (x, 0)) == PRE_INC
@@ -2324,8 +2698,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]);
+         if (small_data_operand (x, GET_MODE (x)))
+           fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
        }
       return;
                            
@@ -2351,6 +2725,7 @@ print_operand (file, x, code)
 
            case ABI_V4:
            case ABI_AIX_NODESC:
+           case ABI_SOLARIS:
              break;
 
            case ABI_NT:
@@ -2364,7 +2739,7 @@ print_operand (file, x, code)
     case 'Z':
       /* Like 'L', for last word of TImode.  */
       if (GET_CODE (x) == REG)
-       fprintf (file, "%d", REGNO (x) + 3);
+       fprintf (file, "%s", reg_names[REGNO (x) + 3]);
       else if (GET_CODE (x) == MEM)
        {
          if (GET_CODE (XEXP (x, 0)) == PRE_INC
@@ -2372,8 +2747,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]);
+         if (small_data_operand (x, GET_MODE (x)))
+           fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
        }
       return;
                            
@@ -2411,11 +2786,11 @@ print_operand_address (file, x)
 {
   if (GET_CODE (x) == REG)
     fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
-  else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
+  else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST || GET_CODE (x) == LABEL_REF)
     {
       output_addr_const (file, x);
-      if (DEFAULT_ABI == ABI_V4 && small_data_operand (x, GET_MODE (x)))
-       fprintf (file, "@sda21(%s)", reg_names[0]);
+      if (small_data_operand (x, GET_MODE (x)))
+       fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, reg_names[0]);
 
 #ifdef TARGET_NO_TOC
       else if (TARGET_NO_TOC)
@@ -2462,7 +2837,7 @@ first_reg_to_save ()
       break;
 
   /* If profiling, then we must save/restore every register that contains
-     a parameter before/after the .mcount call.  Use registers from 30 down
+     a parameter before/after the .__mcount call.  Use registers from 30 down
      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.  */
@@ -2495,7 +2870,7 @@ rs6000_makes_calls ()
 {
   rtx insn;
 
-  /* If we are profiling, we will be making a call to mcount.  */
+  /* If we are profiling, we will be making a call to __mcount.  */
   if (profile_flag)
     return 1;
 
@@ -2532,9 +2907,11 @@ rs6000_makes_calls ()
                +---------------------------------------+
                | Local variable space (L)              | 24+P+A
                +---------------------------------------+
-               | Save area for GP registers (G)        | 24+P+A+L
+               | Float/int conversion temporary (X)    | 24+P+A+L
+               +---------------------------------------+
+               | Save area for GP registers (G)        | 24+P+A+X+L
                +---------------------------------------+
-               | Save area for FP registers (F)        | 24+P+A+L+G
+               | Save area for FP registers (F)        | 24+P+A+X+L+G
                +---------------------------------------+
        old SP->| back chain to caller's caller         |
                +---------------------------------------+
@@ -2549,16 +2926,18 @@ rs6000_makes_calls ()
                | Parameter save area (P)               | 8
                +---------------------------------------+
                | Alloca space (A)                      | 8+P
-               +---------------------------------------+
+               +---------------------------------------+    
                | Varargs save area (V)                 | 8+P+A
-               +---------------------------------------+
+               +---------------------------------------+    
                | Local variable space (L)              | 8+P+A+V
+               +---------------------------------------+    
+               | Float/int conversion temporary (X)    | 8+P+A+V+L
                +---------------------------------------+
-               | saved CR (C)                          | 8+P+A+V+L
-               +---------------------------------------+
-               | Save area for GP registers (G)        | 8+P+A+V+L+C
-               +---------------------------------------+
-               | Save area for FP registers (F)        | 8+P+A+V+L+C+G
+               | saved CR (C)                          | 8+P+A+V+L+X
+               +---------------------------------------+    
+               | Save area for GP registers (G)        | 8+P+A+V+L+X+C
+               +---------------------------------------+    
+               | Save area for FP registers (F)        | 8+P+A+V+L+X+C+G
                +---------------------------------------+
        old SP->| back chain to caller's caller         |
                +---------------------------------------+
@@ -2582,20 +2961,22 @@ rs6000_makes_calls ()
                | Parameter save area (P)               | 24
                +---------------------------------------+
                | Alloca space (A)                      | 24+P
-               +---------------------------------------+
+               +---------------------------------------+     
                | Local variable space (L)              | 24+P+A
+               +---------------------------------------+     
+               | Float/int conversion temporary (X)    | 24+P+A+L
                +---------------------------------------+
-               | 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
+               | Save area for FP registers (F)        | 24+P+A+L+X
+               +---------------------------------------+     
+               | Possible alignment area (Y)           | 24+P+A+L+X+F
+               +---------------------------------------+     
+               | Save area for GP registers (G)        | 24+P+A+L+X+F+Y
+               +---------------------------------------+     
+               | Save area for CR (C)                  | 24+P+A+L+X+F+Y+G
+               +---------------------------------------+     
+               | Save area for TOC (T)                 | 24+P+A+L+X+F+Y+G+C
+               +---------------------------------------+     
+               | Save area for LR (R)                  | 24+P+A+L+X+F+Y+G+C+T
                +---------------------------------------+
        old SP->| back chain to caller's caller         |
                +---------------------------------------+
@@ -2606,6 +2987,10 @@ rs6000_makes_calls ()
    old SP.  To support calls through pointers, we also allocate a
    fixed slot to store the TOC, -8 off the old SP.  */
 
+#ifndef ABI_STACK_BOUNDARY
+#define ABI_STACK_BOUNDARY STACK_BOUNDARY
+#endif
+
 rs6000_stack_t *
 rs6000_stack_info ()
 {
@@ -2631,40 +3016,49 @@ 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)
+  /* Allocate space to save the toc. */
+  if (abi == ABI_NT && info_ptr->calls_p)
     {
       info_ptr->toc_save_p = 1;
       info_ptr->toc_size = reg_size;
     }
 
+  /* Does this machine need the float/int conversion area? */
+  info_ptr->fpmem_p = regs_ever_live[FPMEM_REGNUM];
+
   /* 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)
+#ifdef TARGET_EABI
+  if (TARGET_EABI)
+#endif
     {
-      info_ptr->main_p = 1;
+      if (strcmp (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), "main") == 0)
+       {
+         info_ptr->main_p = 1;
 
 #ifdef NAME__MAIN
-      info_ptr->calls_p = 1;
+         info_ptr->calls_p = 1;
 
-      if (DECL_ARGUMENTS (current_function_decl))
-       {
-         int i;
-         tree arg;
+         if (DECL_ARGUMENTS (current_function_decl))
+           {
+             int i;
+             tree arg;
 
-         info_ptr->main_save_p = 1;
-         info_ptr->main_size = 0;
+             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;
+             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
@@ -2673,6 +3067,7 @@ rs6000_stack_info ()
       || (info_ptr->first_fp_reg_save != 64
          && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
       || (abi == ABI_V4 && current_function_calls_alloca)
+      || (abi == ABI_SOLARIS && current_function_calls_alloca)
       || info_ptr->calls_p)
     {
       info_ptr->lr_save_p = 1;
@@ -2685,7 +3080,7 @@ rs6000_stack_info ()
   if (regs_ever_live[70] || regs_ever_live[71] || regs_ever_live[72])
     {
       info_ptr->cr_save_p = 1;
-      if (abi == ABI_V4 || abi == ABI_NT)
+      if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
        info_ptr->cr_size = reg_size;
     }
 
@@ -2695,6 +3090,7 @@ 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->fpmem_size  = (info_ptr->fpmem_p) ? 8 : 0;
   info_ptr->save_size    = ALIGN (info_ptr->fp_size
                                  + info_ptr->gp_size
                                  + info_ptr->cr_size
@@ -2704,11 +3100,12 @@ rs6000_stack_info ()
 
   total_raw_size        = (info_ptr->vars_size
                            + info_ptr->parm_size
+                           + info_ptr->fpmem_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);
+  info_ptr->total_size   = ALIGN (total_raw_size, ABI_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
@@ -2721,7 +3118,7 @@ rs6000_stack_info ()
   if (info_ptr->calls_p)
     info_ptr->push_p = 1;
 
-  else if (abi == ABI_V4 || abi == ABI_NT)
+  else if (abi == ABI_V4 || abi == ABI_NT || abi == ABI_SOLARIS)
     info_ptr->push_p = (total_raw_size > info_ptr->fixed_size
                        || info_ptr->lr_save_p);
 
@@ -2747,11 +3144,12 @@ rs6000_stack_info ()
       break;
 
     case ABI_V4:
+    case ABI_SOLARIS:
       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->cr_save_offset   = info_ptr->gp_save_offset - info_ptr->cr_size;
+      info_ptr->toc_save_offset  = info_ptr->cr_save_offset - info_ptr->toc_size;
+      info_ptr->main_save_offset = info_ptr->toc_save_offset - info_ptr->main_size;
       info_ptr->lr_save_offset   = reg_size;
       break;
 
@@ -2768,6 +3166,9 @@ rs6000_stack_info ()
       break;
     }
 
+  if (info_ptr->fpmem_p)
+    info_ptr->fpmem_offset = STARTING_FRAME_OFFSET - info_ptr->total_size + info_ptr->vars_size;
+
   /* Zero offsets if we're not saving those registers */
   if (!info_ptr->fp_size)
     info_ptr->fp_save_offset = 0;
@@ -2787,6 +3188,14 @@ rs6000_stack_info ()
   if (!info_ptr->main_save_p)
     info_ptr->main_save_offset = 0;
 
+  if (!info_ptr->fpmem_p)
+    info_ptr->fpmem_offset = 0;
+  else
+    {
+      rs6000_fpmem_size   = info_ptr->fpmem_size;
+      rs6000_fpmem_offset = info_ptr->total_size + info_ptr->fpmem_offset;
+    }
+
   return info_ptr;
 }
 
@@ -2811,6 +3220,7 @@ debug_stack_info (info)
     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_SOLARIS:   abi_string = "Solaris";        break;
     case ABI_NT:        abi_string = "NT";             break;
     }
 
@@ -2843,6 +3253,9 @@ debug_stack_info (info)
   if (info->main_save_p)
     fprintf (stderr, "\tmain_save_p         = %5d\n", info->main_save_p);
 
+  if (info->fpmem_p)
+    fprintf (stderr, "\tfpmem_p             = %5d\n", info->fpmem_p);
+
   if (info->gp_save_offset)
     fprintf (stderr, "\tgp_save_offset      = %5d\n", info->gp_save_offset);
 
@@ -2864,6 +3277,9 @@ debug_stack_info (info)
   if (info->main_save_offset)
     fprintf (stderr, "\tmain_save_offset    = %5d\n", info->main_save_offset);
 
+  if (info->fpmem_offset)
+    fprintf (stderr, "\tfpmem_offset        = %5d\n", info->fpmem_offset);
+
   if (info->total_size)
     fprintf (stderr, "\ttotal_size          = %5d\n", info->total_size);
 
@@ -2876,6 +3292,9 @@ debug_stack_info (info)
   if (info->parm_size)
     fprintf (stderr, "\tparm_size           = %5d\n", info->parm_size);
 
+  if (info->fpmem_size)
+    fprintf (stderr, "\tfpmem_size          = %5d\n", info->fpmem_size);
+
   if (info->fixed_size)
     fprintf (stderr, "\tfixed_size          = %5d\n", info->fixed_size);
 
@@ -2905,8 +3324,76 @@ debug_stack_info (info)
 
   fprintf (stderr, "\n");
 }
-
 \f
+/* Write out an instruction to load the TOC_TABLE address into register 30.
+   This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
+   a constant pool.  */
+
+void
+rs6000_output_load_toc_table (file)
+     FILE *file;
+{
+  char buf[256];
+
+#ifdef USING_SVR4_H
+  if (TARGET_RELOCATABLE)
+    {
+      ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
+      fprintf (file, "\tbl ");
+      assemble_name (file, buf);
+      fprintf (file, "\n");
+
+      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");
+
+      fprintf (file, " %s,(", reg_names[0]);
+      ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
+      assemble_name (file, buf);
+      fprintf (file, "-");
+      ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
+      assemble_name (file, buf);
+      fprintf (file, ")(%s)\n", reg_names[30]);
+      asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
+                  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]);
+      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 ();
+
+#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 */
+}
+
 /* Write function prologue.  */
 void
 output_prolog (file, size)
@@ -2962,7 +3449,7 @@ output_prolog (file, size)
     }
 
   /* For V.4, update stack before we do any saving and set back pointer.  */
-  if (info->push_p && DEFAULT_ABI == ABI_V4)
+  if (info->push_p && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS))
     {
       if (info->total_size < 32767)
        {
@@ -3029,7 +3516,7 @@ output_prolog (file, size)
   if (info->main_save_p)
     {
       int regno;
-      int loc = info->main_save_offset;
+      int loc = info->main_save_offset + sp_offset;
       int size = info->main_size;
 
       for (regno = 3; size > 0; regno++, loc -= reg_size, size -= reg_size)
@@ -3057,10 +3544,6 @@ output_prolog (file, size)
                     reg_names[sp_reg]);
     }
 
-  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)
@@ -3093,7 +3576,7 @@ output_prolog (file, size)
          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);
+         ASM_GENERATE_INTERNAL_LABEL (buf, "LCprobe", probe_labelno++);
          fputs ("\tbdnz ", file);
          assemble_name (file, buf);
          fputs ("\n", file);
@@ -3101,7 +3584,7 @@ output_prolog (file, size)
     }
 
   /* 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->push_p && DEFAULT_ABI != ABI_V4 && DEFAULT_ABI != ABI_SOLARIS)
     {
       if (info->total_size < 32767)
        asm_fprintf (file,
@@ -3159,16 +3642,12 @@ output_prolog (file, 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);
-               }
+           {
+             int neg_size = info->main_save_offset - info->total_size;
+             loc = 0;
+             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]);
@@ -3184,72 +3663,7 @@ output_prolog (file, size)
   /* 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 TARGET_RELOCATABLE
-      if (TARGET_RELOCATABLE)
-       {
-         ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
-         fputs ("\tbl ", file);
-         assemble_name (file, buf);
-         putc ('\n', file);
-
-         ASM_OUTPUT_INTERNAL_LABEL (file, "LCF", rs6000_pic_labelno);
-         fprintf (file, "\tmflr %s\n", reg_names[30]);
-
-         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);
-         putc ('-', file);
-         ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
-         assemble_name (file, buf);
-         fprintf (file, ")(%s)\n", reg_names[30]);
-         asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
-                      reg_names[30], reg_names[0], reg_names[30]);
-         rs6000_pic_labelno++;
-       }
-      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, "(%s)\n", reg_names[2]);
-         break;
-       }
-    }
+    rs6000_output_load_toc_table (file);
 
   if (DEFAULT_ABI == ABI_NT)
     {
@@ -3272,10 +3686,6 @@ output_epilog (file, size)
   int sp_offset = 0;
   int i;
 
-  /* Forget about any temporaries created */
-  for (i = 0; i < NUM_MACHINE_MODES; i++)
-    stack_temps[i] = NULL_RTX;
-
   /* If the last insn was a BARRIER, we don't have to write anything except
      the trace table.  */
   if (GET_CODE (insn) == NOTE)
@@ -3290,14 +3700,14 @@ output_epilog (file, size)
        {
          /* Under V.4, don't reset the stack pointer until after we're done
             loading the saved registers.  */
-         if (DEFAULT_ABI == ABI_V4)
+         if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
            sp_reg = 11;
 
          asm_fprintf (file, load_reg, reg_names[sp_reg], 0, reg_names[1]);
        }
       else if (info->push_p)
        {
-         if (DEFAULT_ABI == ABI_V4)
+         if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
            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);
@@ -3567,10 +3977,6 @@ output_epilog (file, size)
        fputs ("\t.byte 31\n", file);
     }
 
-  /* 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));
@@ -3646,9 +4052,9 @@ output_toc (file, x, labelno)
       REAL_VALUE_TO_TARGET_SINGLE (rv, l);
 
       if (TARGET_MINIMAL_TOC)
-       fprintf (file, "\t.long %d\n", l);
+       fprintf (file, "\t.long %ld\n", l);
       else
-       fprintf (file, "\t.tc FS_%x[TC],%d\n", l, l);
+       fprintf (file, "\t.tc FS_%lx[TC],%ld\n", l, l);
       return;
     }
   else if (GET_MODE (x) == DImode
@@ -3677,10 +4083,10 @@ output_toc (file, x, labelno)
 #endif
 
       if (TARGET_MINIMAL_TOC)
-       fprintf (file, "\t.long %ld\n\t.long %ld\n", high, low);
+       fprintf (file, "\t.long %ld\n\t.long %ld\n", (long)high, (long)low);
       else
        fprintf (file, "\t.tc ID_%lx_%lx[TC],%ld,%ld\n",
-                high, low, high, low);
+                (long)high, (long)low, (long)high, (long)low);
       return;
     }
 
@@ -3699,11 +4105,11 @@ output_toc (file, x, labelno)
   else
     abort ();
 
+  STRIP_NAME_ENCODING (real_name, name);
   if (TARGET_MINIMAL_TOC)
     fputs ("\t.long ", file);
   else
     {
-      STRIP_NAME_ENCODING (real_name, name);
       fprintf (file, "\t.tc %s", real_name);
 
       if (offset < 0)
@@ -3713,7 +4119,23 @@ output_toc (file, x, labelno)
 
       fputs ("[TC],", file);
     }
-  output_addr_const (file, x);
+
+  /* Currently C++ toc references to vtables can be emitted before it
+     is decided whether the vtable is public or private.  If this is
+     the case, then the linker will eventually complain that there is
+     a TOC reference to an unknown section.  Thus, for vtables only,
+     we emit the TOC reference to reference the symbol and not the
+     section.  */
+  if (!strncmp ("_vt.", name, 4))
+    {
+      RS6000_OUTPUT_BASENAME (file, name);
+      if (offset < 0)
+       fprintf (file, "%d", offset);
+      else if (offset > 0)
+       fprintf (file, "+%d", offset);
+    }
+  else
+    output_addr_const (file, x);
   putc ('\n', file);
 }
 \f
@@ -3897,7 +4319,7 @@ output_function_profiler (file, labelno)
   ASM_GENERATE_INTERNAL_LABEL (buf, "LPC", labelno);
   asm_fprintf (file, "\t{l|lwz} %s,", reg_names[3]);
   assemble_name (file, buf);
-  asm_fprintf (file, "(%s)\n\tbl .mcount\n", reg_names[2]);
+  asm_fprintf (file, "(%s)\n\tbl %s\n", reg_names[2], RS6000_MCOUNT);
 
   /* Restore parameter registers.  */
 
@@ -3949,8 +4371,6 @@ int get_issue_rate()
     return 4;
   case CPU_PPC601:
     return 3;       /* ? */
-  case CPU_PPC602:
-    return 1; 
   case CPU_PPC603:
     return 2; 
   case CPU_PPC604:
@@ -3962,65 +4382,6 @@ int get_issue_rate()
   }
 }
 
-\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
@@ -4035,6 +4396,7 @@ rs6000_trampoline_template (file)
 {
   char *sc = reg_names[STATIC_CHAIN_REGNUM];
   char *r0 = reg_names[0];
+  char *r2 = reg_names[2];
 
   switch (DEFAULT_ABI)
     {
@@ -4046,64 +4408,38 @@ rs6000_trampoline_template (file)
        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_SOLARIS:
     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
-     need to have a 2 word area followed by the code to load up the
-     static chain.  */
+     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 || !TARGET_NEW_MNEMONICS || TARGET_64BIT)
+      if (STATIC_CHAIN_REGNUM == 0
+         || STATIC_CHAIN_REGNUM == 2
+         || TARGET_64BIT
+         || !TARGET_NEW_MNEMONICS)
        abort ();
 
-      fprintf (file, "\t.ualong 0,0\n");               /* offset  0 */
-      fprintf (file, "\tmflr %s\n", r0);               /* offset  8 */
-      fprintf (file, "\tbl .LTRAMP1\n");               /* offset 12 */
-      fprintf (file, "\t.ualong 0,0\n");               /* offset 16 */
-      fprintf (file, ".LTRAMP1:\n");
-      fprintf (file, "\tmflr %s\n", sc);               /* offset 28 */
-      fprintf (file, "\tmtlr %s\n", r0);               /* offset 32 */
-      fprintf (file, "\tlwz %s,0(%s)\n", r0, sc);      /* offset 36 */
-      fprintf (file, "\tlwz %s,4(%s)\n", sc, sc);      /* offset 40 */
-      fprintf (file, "\tmtctr %s\n", r0);              /* offset 44 */
-      fprintf (file, "\tbctr\n");                      /* offset 48 */
+      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..0:\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;
     }
 
@@ -4127,12 +4463,13 @@ rs6000_trampoline_size ()
       break;
 
     case ABI_V4:
+    case ABI_SOLARIS:
     case ABI_AIX_NODESC:
       ret = (TARGET_32BIT) ? 40 : 48;
       break;
 
     case ABI_NT:
-      ret = 52;
+      ret = 20;
       break;
     }
 
@@ -4149,64 +4486,63 @@ rs6000_initialize_trampoline (addr, fnaddr, cxt)
      rtx fnaddr;
      rtx cxt;
 {
-  rtx reg, reg2, reg3;
   enum machine_mode pmode = Pmode;
+  int regsize = (TARGET_32BIT) ? 4 : 8;
+  rtx ctx_reg = force_reg (pmode, cxt);
 
   switch (DEFAULT_ABI)
     {
     default:
       abort ();
 
+/* Macros to shorten the code expansions below.  */
+#define MEM_DEREF(addr) gen_rtx (MEM, pmode, memory_address (pmode, addr))
+#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 (gen_rtx (MEM, pmode,
-                              memory_address (pmode,
-                                              plus_constant ((addr), 4))),
-                     gen_rtx (MEM, pmode,
-                              memory_address (pmode,
-                                              plus_constant ((fnaddr), 4))));
-      emit_move_insn (gen_rtx (MEM, pmode,
-                              memory_address (pmode,
-                                              plus_constant ((addr), 8))),
-                     force_reg (pmode, (cxt)));
+      {
+       rtx fn_reg = gen_reg_rtx (pmode);
+       rtx toc_reg = gen_reg_rtx (pmode);
+       emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
+       emit_move_insn (toc_reg, MEM_PLUS (fnaddr, 4));
+       emit_move_insn (MEM_DEREF (addr), fn_reg);
+       emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
+       emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
+      }
       break;
 
-    /* Under V.4/eabi, update the two words after the bl to have the real
-       function address and the static chain.  */
+    /* Under V.4/eabi, call __trampoline_setup to do the real work.  */
     case ABI_V4:
+    case ABI_SOLARIS:
     case ABI_AIX_NODESC:
-      reg = gen_reg_rtx (pmode);
-
-      emit_move_insn (reg, fnaddr);
-      emit_move_insn (gen_rtx (MEM, pmode, plus_constant (addr, 8)), reg);
-      emit_move_insn (gen_rtx (MEM, pmode,
-                              plus_constant (addr, (TARGET_64BIT ? 16 : 12))),
-                     cxt);
-
-      rs6000_sync_trampoline (addr);
+      emit_library_call (gen_rtx (SYMBOL_REF, SImode, "__trampoline_setup"),
+                        FALSE, VOIDmode, 4,
+                        addr, pmode,
+                        GEN_INT (rs6000_trampoline_size ()), SImode,
+                        fnaddr, pmode,
+                        ctx_reg, pmode);
       break;
 
-    /* Under NT, update the first 2 words to look like a normal descriptor, and
-       then fill in the fields with the function address and static chain after
-       the bl instruction.  */
+    /* Under NT, update the first word to point to the ..LTRAMP1..0 header,
+       the 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:
-      reg  = gen_reg_rtx (pmode);
-      reg2 = gen_reg_rtx (pmode);
-      reg3 = gen_reg_rtx (pmode);
-
-      emit_move_insn (gen_rtx (MEM, pmode, plus_constant (addr, 4)),
-                     gen_rtx (REG, pmode, 2));
-      emit_move_insn (reg, fnaddr);
-      emit_move_insn (reg2, gen_rtx (MEM, pmode, reg));
-      emit_move_insn (reg3, plus_constant (addr, 8));
-      emit_move_insn (gen_rtx (MEM, pmode, plus_constant (addr, 16)), reg);
-      emit_move_insn (gen_rtx (MEM, pmode, addr), reg3);
-      emit_move_insn (gen_rtx (MEM, pmode, plus_constant (addr, 20)), cxt);
-      rs6000_sync_trampoline (addr);
+      {
+       rtx tramp_reg = gen_reg_rtx (pmode);
+       rtx fn_reg = gen_reg_rtx (pmode);
+       rtx toc_reg = gen_reg_rtx (pmode);
+
+       emit_move_insn (tramp_reg, gen_rtx (SYMBOL_REF, pmode, "..LTRAMP1..0"));
+       addr = force_reg (pmode, addr);
+       emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
+       emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
+       emit_move_insn (MEM_DEREF (addr), tramp_reg);
+       emit_move_insn (MEM_PLUS (addr, regsize), addr);
+       emit_move_insn (MEM_PLUS (addr, 2*regsize), fn_reg);
+       emit_move_insn (MEM_PLUS (addr, 3*regsize), ctx_reg);
+       emit_move_insn (MEM_PLUS (addr, 4*regsize), gen_rtx (REG, pmode, 2));
+      }
       break;
     }
 
@@ -4244,6 +4580,11 @@ rs6000_valid_type_attribute_p (type, attributes, identifier, args)
       && TREE_CODE (type) != TYPE_DECL)
     return 0;
 
+  /* Longcall attribute says that the function is not within 2**26 bytes
+     of the current function, and to do an indirect call.  */
+  if (is_attribute_p ("longcall", identifier))
+    return (args == NULL_TREE);
+
   if (DEFAULT_ABI == ABI_NT)
     {
       /* Stdcall attribute says callee is responsible for popping arguments
@@ -4264,6 +4605,29 @@ rs6000_valid_type_attribute_p (type, attributes, identifier, args)
         pointer.  */
       if (is_attribute_p ("dllexport", identifier))
        return (args == NULL_TREE);
+
+      /* Exception attribute allows the user to specify 1-2 strings or identifiers
+        that will fill in the 3rd and 4th fields of the structured exception
+        table.  */
+      if (is_attribute_p ("exception", identifier))
+       {
+         int i;
+
+         if (args == NULL_TREE)
+           return 0;
+
+         for (i = 0; i < 2 && args != NULL_TREE; i++)
+           {
+             tree this_arg = TREE_VALUE (args);
+             args = TREE_PURPOSE (args);
+
+             if (TREE_CODE (this_arg) != STRING_CST
+                 && TREE_CODE (this_arg) != IDENTIFIER_NODE)
+               return 0;
+           }
+
+         return (args == NULL_TREE);
+       }
     }
 
   return 0;
@@ -4320,6 +4684,34 @@ rs6000_dll_import_ref (call_ref)
   return reg2;
 }
 
+/* Return a reference suitable for calling a function with the longcall attribute.  */
+struct rtx_def *
+rs6000_longcall_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)
+    return call_ref;
+
+  /* System V adds '.' to the internal name, so skip them.  */
+  call_name = XSTR (call_ref, 0);
+  if (*call_name == '.')
+    {
+      while (*call_name == '.')
+       call_name++;
+
+      node = get_identifier (call_name);
+      call_ref = gen_rtx (SYMBOL_REF, VOIDmode, IDENTIFIER_POINTER (node));
+    }
+
+  return force_reg (Pmode, call_ref);
+}
+
 \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
@@ -4371,15 +4763,20 @@ rs6000_select_section (decl, reloc)
          || (DECL_INITIAL (decl) != error_mark_node
              && !TREE_CONSTANT (DECL_INITIAL (decl))))
        {
-         if (TARGET_SDATA && (size > 0) && (size <= g_switch_value))
+         if (rs6000_sdata != SDATA_NONE && (size > 0) && (size <= g_switch_value))
            sdata_section ();
          else
            data_section ();
        }
       else
        {
-         if (TARGET_SDATA && (size > 0) && (size <= g_switch_value))
-           sdata2_section ();
+         if (rs6000_sdata != SDATA_NONE && (size > 0) && (size <= g_switch_value))
+           {
+             if (rs6000_sdata == SDATA_EABI)
+               sdata2_section ();
+             else
+               sdata_section ();       /* System V doesn't have .sdata2/.sbss2 */
+           }
          else
            const_section ();
        }
@@ -4387,4 +4784,73 @@ rs6000_select_section (decl, reloc)
   else
     const_section ();
 }
+
+\f
+
+/* If we are referencing a function that is static or is known to be
+   in this file, make the SYMBOL_REF special.  We can use this to indicate
+   that we can branch to this function without emitting a no-op after the
+   call.  For real AIX and NT calling sequences, we also replace the
+   function name with the real name (1 or 2 leading .'s), rather than
+   the function descriptor name.  This saves a lot of overriding code
+   to readd the prefixes.  */
+
+void
+rs6000_encode_section_info (decl)
+     tree decl;
+{
+  if (TREE_CODE (decl) == FUNCTION_DECL)
+    {
+      rtx sym_ref = XEXP (DECL_RTL (decl), 0);
+      if (TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
+       SYMBOL_REF_FLAG (sym_ref) = 1;
+
+      if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
+       {
+         char *prefix = (DEFAULT_ABI == ABI_AIX) ? "." : "..";
+         char *str = permalloc (strlen (prefix) + 1
+                                + strlen (XSTR (sym_ref, 0)));
+         strcpy (str, prefix);
+         strcat (str, XSTR (sym_ref, 0));
+         XSTR (sym_ref, 0) = str;
+       }
+    }
+  else if (rs6000_sdata != SDATA_NONE
+          && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)
+          && TREE_CODE (decl) == VAR_DECL)
+    {
+      int size = int_size_in_bytes (TREE_TYPE (decl));
+      tree section_name = DECL_SECTION_NAME (decl);
+      char *name = (char *)0;
+      int len = 0;
+
+      if (section_name)
+       {
+         if (TREE_CODE (section_name) == STRING_CST)
+           {
+             name = TREE_STRING_POINTER (section_name);
+             len = TREE_STRING_LENGTH (section_name);
+           }
+         else
+           abort ();
+       }
+
+      if ((size > 0 && size <= g_switch_value)
+         || (name
+             && ((len == sizeof (".sdata")-1 && strcmp (name, ".sdata") == 0)
+                 || (len == sizeof (".sdata2")-1 && strcmp (name, ".sdata2") == 0)
+                 || (len == sizeof (".sbss")-1 && strcmp (name, ".sbss") == 0)
+                 || (len == sizeof (".sbss2")-1 && strcmp (name, ".sbss2") == 0)
+                 || (len == sizeof (".PPC.EMB.sdata0")-1 && strcmp (name, ".PPC.EMB.sdata0") == 0)
+                 || (len == sizeof (".PPC.EMB.sbss0")-1 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
+       {
+         rtx sym_ref = XEXP (DECL_RTL (decl), 0);
+         char *str = permalloc (2 + strlen (XSTR (sym_ref, 0)));
+         strcpy (str, "@");
+         strcat (str, XSTR (sym_ref, 0));
+         XSTR (sym_ref, 0) = str;
+       }
+    }
+}
+
 #endif /* USING_SVR4_H */