2001-04-07 Steven J. Hill <sjhill@cotw.com>
[deliverable/binutils-gdb.git] / gas / config / tc-mips.c
index f98a332790f67d6fc94817d1eae739dba7a3a80b..6c2f3173140f883ecc8e5b851a19468b79c9f147 100644 (file)
@@ -1,5 +1,6 @@
 /* tc-mips.c -- assemble code for a MIPS chip.
-   Copyright (C) 1993, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
+   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Free Software Foundation, Inc.
    Contributed by the OSF and Ralph Campbell.
    Written by Keith Knowles and Ralph Campbell, working independently.
    Modified for ECOFF and R4000 support by Ian Lance Taylor of Cygnus
@@ -109,6 +110,7 @@ extern int target_big_endian;
 static int mips_64;
 
 /* The default target format to use.  */
+
 const char *
 mips_target_format ()
 {
@@ -118,10 +120,19 @@ mips_target_format ()
       return target_big_endian ? "a.out-mips-big" : "a.out-mips-little";
     case bfd_target_ecoff_flavour:
       return target_big_endian ? "ecoff-bigmips" : ECOFF_LITTLE_FORMAT;
+    case bfd_target_coff_flavour:
+      return "pe-mips";
     case bfd_target_elf_flavour:
+#ifdef TE_TMIPS
+      /* This is traditional mips */
+      return (target_big_endian
+             ? (mips_64 ? "elf64-tradbigmips" : "elf32-tradbigmips")
+             : (mips_64 ? "elf64-tradlittlemips" : "elf32-tradlittlemips"));
+#else
       return (target_big_endian
              ? (mips_64 ? "elf64-bigmips" : "elf32-bigmips")
              : (mips_64 ? "elf64-littlemips" : "elf32-littlemips"));
+#endif
     default:
       abort ();
       return NULL;
@@ -133,6 +144,8 @@ mips_target_format ()
                            ? ".data" \
                            : OUTPUT_FLAVOR == bfd_target_ecoff_flavour \
                            ? ".rdata" \
+                           : OUTPUT_FLAVOR == bfd_target_coff_flavour \
+                           ? ".rdata" \
                            : OUTPUT_FLAVOR == bfd_target_elf_flavour \
                            ? ".rodata" \
                            : (abort (), ""))
@@ -176,10 +189,13 @@ struct mips_set_options
 };
 
 /* This is the struct we use to hold the current set of options.  Note
-   that we must set the isa and mips16 fields to -1 to indicate that
-   they have not been initialized.  */
+   that we must set the isa field to ISA_UNKNOWN and the mips16 field to
+   -1 to indicate that they have not been initialized.  */
 
-static struct mips_set_options mips_opts = { -1, -1 };
+static struct mips_set_options mips_opts =
+{
+  ISA_UNKNOWN, -1, 0, 0, 0, 0, 0, 0
+};
 
 /* These variables are filled in with the masks of registers used.
    The object format code reads them and puts them in the appropriate
@@ -188,42 +204,47 @@ unsigned long mips_gprmask;
 unsigned long mips_cprmask[4];
 
 /* MIPS ISA we are using for this output file.  */
-static int file_mips_isa;
+static int file_mips_isa = ISA_UNKNOWN;
 
-/* The CPU type as a number: 2000, 3000, 4000, 4400, etc.  */
-static int mips_cpu = -1;
+/* The CPU type we are using for this output file.  */
+static int mips_cpu = CPU_UNKNOWN;
 
-/* The argument of the -mabi= flag. */
-static char* mips_abi_string = 0;
+/* The argument of the -mabi= flag.  */
+static char * mips_abi_string = 0;
 
-/* Wether we should mark the file EABI64 or EABI32. */
+/* Wether we should mark the file EABI64 or EABI32.  */
 static int mips_eabi64 = 0;
 
 /* If they asked for mips1 or mips2 and a cpu that is
-   mips3 or greater, then mark the object file 32BITMODE. */
+   mips3 or greater, then mark the object file 32BITMODE.  */
 static int mips_32bitmode = 0;
 
+/* True if -mgp32 was passed.  */
+static int mips_gp32 = 0;
+
 /* Some ISA's have delay slots for instructions which read or write
    from a coprocessor (eg. mips1-mips3); some don't (eg mips4).
-   Return true if instructions marked INSN_LOAD_COPROC_DELAY, 
+   Return true if instructions marked INSN_LOAD_COPROC_DELAY,
    INSN_COPROC_MOVE_DELAY, or INSN_WRITE_COND_CODE actually have a
    delay slot in this ISA.  The uses of this macro assume that any
    ISA that has delay slots for one of these, has them for all.  They
    also assume that ISAs which don't have delays for these insns, don't
-   have delays for the INSN_LOAD_MEMORY_DELAY instructions either. */
+   have delays for the INSN_LOAD_MEMORY_DELAY instructions either.  */
 #define ISA_HAS_COPROC_DELAYS(ISA) (        \
-   (ISA) == 1                               \
-   || (ISA) == 2                            \
-   || (ISA) == 3                            \
+   (ISA) == ISA_MIPS1                       \
+   || (ISA) == ISA_MIPS2                    \
+   || (ISA) == ISA_MIPS3                    \
    )
 
-/*  Return true if ISA supports 64 bit gp register instructions. */
+/*  Return true if ISA supports 64 bit gp register instructions.  */
 #define ISA_HAS_64BIT_REGS(ISA) (    \
-   (ISA) == 3                        \
-   || (ISA) == 4                     \
+   (ISA) == ISA_MIPS3                \
+   || (ISA) == ISA_MIPS4             \
+   || (ISA) == ISA_MIPS5             \
+   || (ISA) == ISA_MIPS32            \
    )
 
-/* Whether the processor uses hardware interlocks to protect 
+/* Whether the processor uses hardware interlocks to protect
    reads from the HI and LO registers, and thus does not
    require nops to be inserted.
 
@@ -250,21 +271,25 @@ static int mips_32bitmode = 0;
 
    -- Jim Blandy <jimb@cygnus.com> */
 
-#define hilo_interlocks (mips_cpu == 4010                           \
+#define hilo_interlocks (mips_cpu == CPU_R4010                       \
                          )
 
 /* Whether the processor uses hardware interlocks to protect reads
    from the GPRs, and thus does not require nops to be inserted.  */
 #define gpr_interlocks \
-  (mips_opts.isa != 1  \
-   || mips_cpu == 3900)
+  (mips_opts.isa != ISA_MIPS1  \
+   || mips_cpu == CPU_R3900)
 
 /* As with other "interlocks" this is used by hardware that has FP
    (co-processor) interlocks.  */
-/* Itbl support may require additional care here. */
-#define cop_interlocks (mips_cpu == 4300                            \
+/* Itbl support may require additional care here.  */
+#define cop_interlocks (mips_cpu == CPU_R4300                        \
                        )
 
+/* Is this a mfhi or mflo instruction?  */
+#define MF_HILO_INSN(PINFO) \
+          ((PINFO & INSN_READ_HI) || (PINFO & INSN_READ_LO))
+
 /* MIPS PIC level.  */
 
 enum mips_pic_level
@@ -296,12 +321,24 @@ static int mips_big_got;
    instructions.  */
 static int mips_trap;
 
+/* 1 if double width floating point constants should not be constructed
+   by a assembling two single width halves into two single width floating
+   point registers which just happen to alias the double width destination
+   register.  On some architectures this aliasing can be disabled by a bit
+   in the status register, and the setting of this bit cannot be determined
+   automatically at assemble time.  */
+static int mips_disable_float_construction;
+
 /* Non-zero if any .set noreorder directives were used.  */
 
 static int mips_any_noreorder;
 
+/* Non-zero if nops should be inserted when the register referenced in
+   an mfhi/mflo instruction is read in the next two instructions.  */
+static int mips_7000_hilo_fix;
+
 /* The size of the small data section.  */
-static int g_switch_value = 8;
+static unsigned int g_switch_value = 8;
 /* Whether the -G option was used.  */
 static int g_switch_seen = 0;
 
@@ -337,12 +374,12 @@ const char comment_chars[] = "#";
    .line and .file directives will appear in the pre-processed output */
 /* Note that input_file.c hand checks for '#' at the beginning of the
    first line of the input file.  This is because the compiler outputs
-   #NO_APP at the beginning of its output. */
+   #NO_APP at the beginning of its output.  */
 /* Also note that C style comments are always supported.  */
 const char line_comment_chars[] = "#";
 
-/* This array holds machine specific line separator characters. */
-const char line_separator_chars[] = "";
+/* This array holds machine specific line separator characters.  */
+const char line_separator_chars[] = ";";
 
 /* Chars that can be used to separate mant from exp in floating point nums */
 const char EXP_CHARS[] = "eE";
@@ -392,7 +429,7 @@ static struct mips_cl_insn prev_prev_insn;
 
 /* If we don't want information for prev_insn or prev_prev_insn, we
    point the insn_mo field at this dummy integer.  */
-static const struct mips_opcode dummy_opcode = { 0 };
+static const struct mips_opcode dummy_opcode = { NULL, NULL, 0, 0, 0, 0 };
 
 /* Non-zero if prev_insn is valid.  */
 static int prev_insn_valid;
@@ -433,7 +470,7 @@ static fragS *prev_nop_frag;
 static int prev_nop_frag_holds;
 
 /* The number of nop instructions that we know we need in
-   prev_nop_frag. */
+   prev_nop_frag.  */
 static int prev_nop_frag_required;
 
 /* The number of instructions we've seen since prev_nop_frag.  */
@@ -448,7 +485,7 @@ static int prev_nop_frag_since;
 
    In order to implement this, we keep track of each unmatched HI
    relocation.  We then sort them so that they immediately precede the
-   corresponding LO relocation. */
+   corresponding LO relocation.  */
 
 struct mips_hi_fixup
 {
@@ -478,7 +515,7 @@ static const int mips32_to_16_reg_map[] =
 
 /* Map mips16 register numbers to normal MIPS register numbers.  */
 
-static const int mips16_to_32_reg_map[] =
+static const unsigned int mips16_to_32_reg_map[] =
 {
   16, 17, 2, 3, 4, 5, 6, 7
 };
@@ -554,8 +591,8 @@ static const int mips16_to_32_reg_map[] =
     | ((warn) ? 1 : 0)))
 #define RELAX_OLD(i) (((i) >> 23) & 0x7f)
 #define RELAX_NEW(i) (((i) >> 16) & 0x7f)
-#define RELAX_RELOC1(i) ((bfd_vma)(((i) >> 9) & 0x7f) - 64)
-#define RELAX_RELOC2(i) ((bfd_vma)(((i) >> 2) & 0x7f) - 64)
+#define RELAX_RELOC1(i) ((bfd_vma) (((i) >> 9) & 0x7f) - 64)
+#define RELAX_RELOC2(i) ((bfd_vma) (((i) >> 2) & 0x7f) - 64)
 #define RELAX_RELOC3(i) (((i) >> 1) & 1)
 #define RELAX_WARN(i) ((i) & 1)
 
@@ -612,7 +649,7 @@ enum mips_regclass { MIPS_GR_REG, MIPS_FP_REG, MIPS16_REG };
 
 static int insn_uses_reg PARAMS ((struct mips_cl_insn *ip,
                                  unsigned int reg, enum mips_regclass class));
-static int reg_needs_delay PARAMS ((int));
+static int reg_needs_delay PARAMS ((unsigned int));
 static void mips16_mark_labels PARAMS ((void));
 static void append_insn PARAMS ((char *place,
                                 struct mips_cl_insn * ip,
@@ -676,9 +713,24 @@ static void s_mips_stab PARAMS ((int));
 static void s_mips_weakext PARAMS ((int));
 static void s_file PARAMS ((int));
 static int mips16_extended_frag PARAMS ((fragS *, asection *, long));
+static const char *mips_isa_to_str PARAMS ((int));
+static const char *mips_cpu_to_str PARAMS ((int));
+static int validate_mips_insn PARAMS ((const struct mips_opcode *));
 
+/* Table and functions used to map between CPU/ISA names, and
+   ISA levels, and CPU numbers.  */
 
-static int validate_mips_insn PARAMS ((const struct mips_opcode *));
+struct mips_cpu_info
+{
+  const char *name;           /* CPU or ISA name.  */
+  int is_isa;                 /* Is this an ISA?  (If 0, a CPU.) */
+  int isa;                    /* ISA level.  */
+  int cpu;                    /* CPU number (default CPU if ISA).  */
+};
+
+static const struct mips_cpu_info *mips_cpu_info_from_name PARAMS ((const char *));
+static const struct mips_cpu_info *mips_cpu_info_from_isa PARAMS ((int));
+static const struct mips_cpu_info *mips_cpu_info_from_cpu PARAMS ((int));
 \f
 /* Pseudo-op table.
 
@@ -700,7 +752,7 @@ static int validate_mips_insn PARAMS ((const struct mips_opcode *));
 
 static const pseudo_typeS mips_pseudo_table[] =
 {
- /* MIPS specific pseudo-ops.  */
 /* MIPS specific pseudo-ops.  */
   {"option", s_option, 0},
   {"set", s_mipsset, 0},
   {"rdata", s_change_sec, 'r'},
@@ -713,7 +765,7 @@ static const pseudo_typeS mips_pseudo_table[] =
   {"cpadd", s_cpadd, 0},
   {"insn", s_insn, 0},
 
- /* Relatively generic pseudo-ops that happen to be used on MIPS
 /* Relatively generic pseudo-ops that happen to be used on MIPS
      chips.  */
   {"asciiz", stringer, 1},
   {"bss", s_change_sec, 'b'},
@@ -722,7 +774,7 @@ static const pseudo_typeS mips_pseudo_table[] =
   {"dword", s_cons, 3},
   {"weakext", s_mips_weakext, 0},
 
- /* These pseudo-ops are defined in read.c, but must be overridden
 /* These pseudo-ops are defined in read.c, but must be overridden
      here for one reason or another.  */
   {"align", s_align, 0},
   {"byte", s_cons, 0},
@@ -741,12 +793,13 @@ static const pseudo_typeS mips_pseudo_table[] =
   {"stabn", s_mips_stab, 'n'},
   {"text", s_change_sec, 't'},
   {"word", s_cons, 2},
-  { 0 },
+  { NULL, NULL, 0 },
 };
 
-static const pseudo_typeS mips_nonecoff_pseudo_table[] = {
- /* These pseudo-ops should be defined by the object file format.
-    However, a.out doesn't support them, so we have versions here.  */
+static const pseudo_typeS mips_nonecoff_pseudo_table[] =
+{
+  /* These pseudo-ops should be defined by the object file format.
+     However, a.out doesn't support them, so we have versions here.  */
   {"aent", s_mips_ent, 1},
   {"bgnb", s_ignore, 0},
   {"end", s_mips_end, 0},
@@ -758,7 +811,7 @@ static const pseudo_typeS mips_nonecoff_pseudo_table[] = {
   {"loc", s_ignore, 0},
   {"mask", s_mips_mask, 'R'},
   {"verstamp", s_ignore, 0},
-  { 0 },
+  { NULL, NULL, 0 },
 };
 
 extern void pop_insert PARAMS ((const pseudo_typeS *));
@@ -822,20 +875,59 @@ static boolean mips16_small, mips16_ext;
 static segT pdr_seg;
 #endif
 
-/*
- * This function is called once, at assembler startup time.  It should
- * set up all the tables, etc. that the MD part of the assembler will need.
- */
+static const char *
+mips_isa_to_str (isa)
+     int isa;
+{
+  const struct mips_cpu_info *ci;
+  static char s[20];
+
+  ci = mips_cpu_info_from_isa (isa);
+  if (ci != NULL)
+    return (ci->name);
+
+  sprintf (s, "ISA#%d", isa);
+  return s;
+}
+
+static const char *
+mips_cpu_to_str (cpu)
+     int cpu;
+{
+  const struct mips_cpu_info *ci;
+  static char s[16];
+
+  ci = mips_cpu_info_from_cpu (cpu);
+  if (ci != NULL)
+    return (ci->name);
+
+  sprintf (s, "CPU#%d", cpu);
+  return s;
+}
+
+/* This function is called once, at assembler startup time.  It should
+   set up all the tables, etc. that the MD part of the assembler will need.  */
+
 void
 md_begin ()
 {
-  boolean ok = false;
   register const char *retval = NULL;
-  register unsigned int i = 0;
+  int i = 0;
   const char *cpu;
   char *a = NULL;
   int broken = 0;
   int mips_isa_from_cpu;
+  int target_cpu_had_mips16 = 0;
+  const struct mips_cpu_info *ci;
+
+  /* GP relative stuff not working for PE */
+  if (strncmp (TARGET_OS, "pe", 2) == 0
+      && g_switch_value != 0)
+    {
+      if (g_switch_seen)
+       as_bad (_("-G not supported in this configuration."));
+      g_switch_value = 0;
+    }
 
   cpu = TARGET_CPU;
   if (strcmp (cpu + (sizeof TARGET_CPU) - 3, "el") == 0)
@@ -846,179 +938,80 @@ md_begin ()
       cpu = a;
     }
 
-  if (mips_cpu < 0)
+  if (strncmp (cpu, "mips16", sizeof "mips16" - 1) == 0)
     {
-      /* Set mips_cpu based on TARGET_CPU, unless TARGET_CPU is
-         just the generic 'mips', in which case set mips_cpu based
-         on the given ISA, if any. */
-
-      if (strcmp (cpu, "mips") == 0)
-        {
-         if (mips_opts.isa < 0)
-           mips_cpu = 3000;   
-
-         else if (mips_opts.isa == 2)
-            mips_cpu = 6000;
-
-          else if (mips_opts.isa == 3)
-            mips_cpu = 4000;
-
-          else if (mips_opts.isa == 4)
-            mips_cpu = 8000;
-
-          else 
-            mips_cpu = 3000;
-        }
-      
-      else if (strcmp (cpu, "r3900") == 0
-               || strcmp (cpu, "mipstx39") == 0
-               )
-        mips_cpu = 3900;
-
-      else if (strcmp (cpu, "r6000") == 0
-              || strcmp (cpu, "mips2") == 0)
-        mips_cpu = 6000;
-
-      else if (strcmp (cpu, "mips64") == 0
-              || strcmp (cpu, "r4000") == 0
-              || strcmp (cpu, "mips3") == 0)
-        mips_cpu = 4000;
-
-      else if (strcmp (cpu, "r4400") == 0)
-        mips_cpu = 4400;
-
-      else if (strcmp (cpu, "mips64orion") == 0
-              || strcmp (cpu, "r4600") == 0)
-        mips_cpu = 4600;
-
-      else if (strcmp (cpu, "r4650") == 0)
-        mips_cpu = 4650;
-
-      else if (strcmp (cpu, "mips64vr4300") == 0)
-        mips_cpu = 4300;
-
-      else if (strcmp (cpu, "mips64vr4111") == 0)
-        mips_cpu = 4111;
-
-      else if (strcmp (cpu, "mips64vr4100") == 0)
-        mips_cpu = 4100;
-
-      else if (strcmp (cpu, "r4010") == 0)
-        mips_cpu = 4010;
-
-
-      else if (strcmp (cpu, "r5000") == 0
-              || strcmp (cpu, "mips64vr5000") == 0)
-        mips_cpu = 5000;
-
-
-
-      else if (strcmp (cpu, "r8000") == 0
-              || strcmp (cpu, "mips4") == 0)
-        mips_cpu = 8000;
-      
-      else if (strcmp (cpu, "r10000") == 0)
-        mips_cpu = 10000;
-
-      else if (strcmp (cpu, "mips16") == 0)
-        mips_cpu = 0; /* FIXME */
-
-      else
-        mips_cpu = 3000;
+      target_cpu_had_mips16 = 1;
+      cpu += sizeof "mips16" - 1;
     }
 
-  if (mips_cpu == 3000
-      || mips_cpu == 3900)
-    mips_isa_from_cpu = 1;
-
-  else if (mips_cpu == 6000
-          || mips_cpu == 4010)
-    mips_isa_from_cpu = 2;
-
-  else if (mips_cpu == 4000
-          || mips_cpu == 4100
-          || mips_cpu == 4111
-          || mips_cpu == 4400
-          || mips_cpu == 4300
-          || mips_cpu == 4600
-          || mips_cpu == 4650)
-    mips_isa_from_cpu = 3;
-
-  else if (mips_cpu == 5000
-          || mips_cpu == 8000
-               || mips_cpu == 10000)
-    mips_isa_from_cpu = 4;
-
-  else
-    mips_isa_from_cpu = -1;
+  if (mips_opts.mips16 < 0)
+    mips_opts.mips16 = target_cpu_had_mips16;
 
-  if (mips_opts.isa == -1)
+  /* At this point, mips_cpu will either be CPU_UNKNOWN if no CPU was
+     specified on the command line, or some other value if one was.
+     Similarly, mips_opts.isa will be ISA_UNKNOWN if not specified on
+     the command line, or will be set otherwise if one was.  */
+  if (mips_cpu != CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
     {
-      if (mips_isa_from_cpu != -1)
-       mips_opts.isa = mips_isa_from_cpu;
-      else
-       mips_opts.isa = 1;
+      /* We have it all.  There's nothing to do.  */
     }
-
-  if (mips_opts.mips16 < 0)
+  else if (mips_cpu != CPU_UNKNOWN && mips_opts.isa == ISA_UNKNOWN)
     {
-      if (strncmp (TARGET_CPU, "mips16", sizeof "mips16" - 1) == 0)
-       mips_opts.mips16 = 1;
-      else
-       mips_opts.mips16 = 0;
+      /* We have CPU, we need ISA.  */
+      ci = mips_cpu_info_from_cpu (mips_cpu);
+      assert (ci != NULL);
+      mips_opts.isa = ci->isa;
+    }
+  else if (mips_cpu == CPU_UNKNOWN && mips_opts.isa != ISA_UNKNOWN)
+    {
+      /* We have ISA, we need default CPU.  */
+      ci = mips_cpu_info_from_isa (mips_opts.isa);
+      assert (ci != NULL);
+      mips_cpu = ci->cpu;
+    }
+  else
+    {
+      /* We need to set both ISA and CPU from target cpu.  */
+      ci = mips_cpu_info_from_name (cpu);
+      if (ci == NULL)
+       ci = mips_cpu_info_from_cpu (CPU_R3000);
+      assert (ci != NULL);
+      mips_opts.isa = ci->isa;
+      mips_cpu = ci->cpu;
     }
 
+  ci = mips_cpu_info_from_cpu (mips_cpu);
+  assert (ci != NULL);
+  mips_isa_from_cpu = ci->isa;
+
   /* End of TARGET_CPU processing, get rid of malloced memory
-     if necessary. */
+     if necessary.  */
   cpu = NULL;
   if (a != NULL)
     {
-    free (a);
-    a = NULL;
+      free (a);
+      a = NULL;
     }
 
-  if (mips_opts.isa == 1 && mips_trap)
+  if (mips_opts.isa == ISA_MIPS1 && mips_trap)
     as_bad (_("trap exception not supported at ISA 1"));
 
   /* Set the EABI kind based on the ISA before the user gets
      to change the ISA with directives.  This isn't really
-     the best, but then neither is basing the abi on the isa. */     
+     the best, but then neither is basing the abi on the isa.  */
   if (ISA_HAS_64BIT_REGS (mips_opts.isa)
       && mips_abi_string
-      && 0 == strcmp (mips_abi_string,"eabi"))
+      && 0 == strcmp (mips_abi_string, "eabi"))
     mips_eabi64 = 1;
 
-  if (mips_cpu != 0 && mips_cpu != -1)
-    {
-      ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_cpu);
-      
-      /* If they asked for mips1 or mips2 and a cpu that is
-        mips3 or greater, then mark the object file 32BITMODE. */
-      if (mips_isa_from_cpu != -1
-         && ! ISA_HAS_64BIT_REGS (mips_opts.isa) 
-         && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
-       mips_32bitmode = 1;
-    }
-  else
-    {
-      switch (mips_opts.isa)
-       {
-       case 1:
-         ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 3000);
-         break;
-       case 2:
-         ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 6000);
-         break;
-       case 3:
-         ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 4000);
-         break;
-       case 4:
-         ok = bfd_set_arch_mach (stdoutput, bfd_arch_mips, 8000);
-         break;
-       }
-    }
+  /* If they asked for mips1 or mips2 and a cpu that is
+     mips3 or greater, then mark the object file 32BITMODE.  */
+  if (mips_isa_from_cpu != ISA_UNKNOWN
+      && ! ISA_HAS_64BIT_REGS (mips_opts.isa)
+      && ISA_HAS_64BIT_REGS (mips_isa_from_cpu))
+    mips_32bitmode = 1;
 
-  if (! ok)
+  if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, mips_cpu))
     as_warn (_("Could not set architecture and machine"));
 
   file_mips_isa = mips_opts.isa;
@@ -1152,10 +1145,9 @@ md_begin ()
          {
            sec = subseg_new (".reginfo", (subsegT) 0);
 
-
            (void) bfd_set_section_flags (stdoutput, sec, flags);
            (void) bfd_set_section_alignment (stdoutput, sec, 2);
-       
+
 #ifdef OBJ_ELF
            mips_regmask_frag = frag_more (sizeof (Elf32_External_RegInfo));
 #endif
@@ -1235,8 +1227,8 @@ md_assemble (str)
   else
     {
       mips_ip (str, &insn);
-      DBG((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"), 
-               str, insn.insn_opcode));
+      DBG ((_("returned from mips_ip(%s) insn_opcode = 0x%x\n"),
+           str, insn.insn_opcode));
     }
 
   if (insn_error)
@@ -1349,7 +1341,7 @@ insn_uses_reg (ip, reg, class)
 
 static int
 reg_needs_delay (reg)
-     int reg;
+     unsigned int reg;
 {
   unsigned long prev_pinfo;
 
@@ -1364,7 +1356,7 @@ reg_needs_delay (reg)
         delays delay the use of general register rt for one
         instruction on the r3000.  The r6000 and r4000 use
         interlocks.  */
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       know (prev_pinfo & INSN_WRITE_GPR_T);
       if (reg == ((prev_insn.insn_opcode >> OP_SH_RT) & OP_MASK_RT))
        return 1;
@@ -1468,7 +1460,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
             delays delay the use of general register rt for one
             instruction on the r3000.  The r6000 and r4000 use
             interlocks.  */
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          know (prev_pinfo & INSN_WRITE_GPR_T);
          if (mips_optimize == 0
              || insn_uses_reg (ip,
@@ -1480,8 +1472,8 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
       else if (! mips_opts.mips16
               && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
               && (((prev_pinfo & INSN_COPROC_MOVE_DELAY)
-                    && ! cop_interlocks)
-                  || (mips_opts.isa == 1
+                   && ! cop_interlocks)
+                  || (mips_opts.isa == ISA_MIPS1
                       && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))))
        {
          /* A generic coprocessor delay.  The previous instruction
@@ -1499,7 +1491,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
             than the floating point unit are not distinguished at
             all.  */
           /* Itbl support may require additional care here. FIXME!
-             Need to modify this to include knowledge about 
+             Need to modify this to include knowledge about
              user specified delays!  */
          if (prev_pinfo & INSN_WRITE_FPR_T)
            {
@@ -1527,7 +1519,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
                 instruction may set the condition codes, and the
                 current instruction uses them, we must insert two
                 NOPS.  */
-              /* Itbl support may require additional care here. */
+              /* Itbl support may require additional care here.  */
              if (mips_optimize == 0
                  || ((prev_pinfo & INSN_WRITE_COND_CODE)
                      && (pinfo & INSN_READ_COND_CODE)))
@@ -1546,22 +1538,52 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
             (this means it is a floating point comparison
             instruction).  If this instruction uses the condition
             codes, we need to insert a single NOP.  */
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          if (mips_optimize == 0
              || (pinfo & INSN_READ_COND_CODE))
            ++nops;
        }
+
+      /* If we're fixing up mfhi/mflo for the r7000 and the
+        previous insn was an mfhi/mflo and the current insn
+        reads the register that the mfhi/mflo wrote to, then
+        insert two nops.  */
+
+      else if (mips_7000_hilo_fix
+              && MF_HILO_INSN (prev_pinfo)
+              && insn_uses_reg (ip, ((prev_insn.insn_opcode >> OP_SH_RD)
+                                     & OP_MASK_RD),
+                                MIPS_GR_REG))
+       {
+         nops += 2;
+       }
+
+      /* If we're fixing up mfhi/mflo for the r7000 and the
+        2nd previous insn was an mfhi/mflo and the current insn
+        reads the register that the mfhi/mflo wrote to, then
+        insert one nop.  */
+
+      else if (mips_7000_hilo_fix
+              && MF_HILO_INSN (prev_prev_insn.insn_opcode)
+              && insn_uses_reg (ip, ((prev_prev_insn.insn_opcode >> OP_SH_RD)
+                                       & OP_MASK_RD),
+                                    MIPS_GR_REG))
+
+       {
+         nops += 1;
+       }
+
       else if (prev_pinfo & INSN_READ_LO)
        {
          /* The previous instruction reads the LO register; if the
             current instruction writes to the LO register, we must
-            insert two NOPS.  Some newer processors have interlocks. 
-            Also the tx39's multiply instructions can be exectuted 
+            insert two NOPS.  Some newer processors have interlocks.
+            Also the tx39's multiply instructions can be exectuted
              immediatly after a read from HI/LO (without the delay),
-             though the tx39's divide insns still do require the 
-            delay. */
+             though the tx39's divide insns still do require the
+            delay.  */
          if (! (hilo_interlocks
-                || (mips_cpu == 3900 && (pinfo & INSN_MULT)))
+                || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT)))
              && (mips_optimize == 0
                  || (pinfo & INSN_WRITE_LO)))
            nops += 2;
@@ -1570,7 +1592,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
             to a write to LO we have a read followed by a write
             less than 2 insns away.  We assume the target of
             a branch might be a write to LO, and insert a nop
-            between a read and an immediately following branch. */
+            between a read and an immediately following branch.  */
          else if (mips_opts.mips16
                   && (mips_optimize == 0
                       || (pinfo & MIPS16_INSN_BRANCH)))
@@ -1581,9 +1603,9 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
          /* The previous instruction reads the HI register; if the
             current instruction writes to the HI register, we must
             insert a NOP.  Some newer processors have interlocks.
-            Also the note tx39's multiply above. */
+            Also the note tx39's multiply above.  */
          if (! (hilo_interlocks
-                || (mips_cpu == 3900 && (pinfo & INSN_MULT)))
+                || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT)))
              && (mips_optimize == 0
                  || (pinfo & INSN_WRITE_HI)))
            nops += 2;
@@ -1592,7 +1614,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
             to a write to HI we have a read followed by a write
             less than 2 insns away.  We assume the target of
             a branch might be a write to HI, and insert a nop
-            between a read and an immediately following branch. */
+            between a read and an immediately following branch.  */
          else if (mips_opts.mips16
                   && (mips_optimize == 0
                       || (pinfo & MIPS16_INSN_BRANCH)))
@@ -1601,7 +1623,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
 
       /* If the previous instruction was in a noreorder section, then
          we don't want to insert the nop after all.  */
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       if (prev_insn_unreordered)
        nops = 0;
 
@@ -1622,11 +1644,11 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
          || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_LO)
              && (pinfo & INSN_WRITE_LO)
              && ! (hilo_interlocks
-                   || (mips_cpu == 3900 && (pinfo & INSN_MULT))))
+                   || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT))))
          || ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
              && (pinfo & INSN_WRITE_HI)
              && ! (hilo_interlocks
-                   || (mips_cpu == 3900 && (pinfo & INSN_MULT)))))
+                   || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT)))))
        prev_prev_nop = 1;
       else
        prev_prev_nop = 0;
@@ -1643,7 +1665,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
         to 0.  */
       if (nops > 0
          && ! mips_opts.noreorder
-         && ip->insn_opcode == (mips_opts.mips16 ? 0x6500 : 0))
+         && ip->insn_opcode == (unsigned) (mips_opts.mips16 ? 0x6500 : 0))
        --nops;
 
       /* Now emit the right number of NOP instructions.  */
@@ -1694,7 +1716,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
          /* We have a frag holding nops we may be able to remove.  If
              we don't need any nops, we can decrease the size of
              prev_nop_frag by the size of one instruction.  If we do
-             need some nops, we count them in prev_nops_required. */
+             need some nops, we count them in prev_nops_required.  */
          if (prev_nop_frag_since == 0)
            {
              if (nops == 0)
@@ -1795,7 +1817,6 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
                 | ((address_expr->X_add_number & 0x3fffc) >> 2));
              break;
 
-
            case BFD_RELOC_16_PCREL_S2:
              goto need_reloc;
 
@@ -1868,13 +1889,13 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
        mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FR) & OP_MASK_FR);
       if (pinfo & INSN_COP)
        {
-         /* We don't keep enough information to sort these cases out. 
-            The itbl support does keep this information however, although 
-            we currently don't support itbl fprmats as part of the cop 
-            instruction.  May want to add this support in the future. */
+         /* We don't keep enough information to sort these cases out.
+            The itbl support does keep this information however, although
+            we currently don't support itbl fprmats as part of the cop
+            instruction.  May want to add this support in the future.  */
        }
       /* Never set the bit for $0, which is always zero.  */
-      mips_gprmask &=1 << 0;
+      mips_gprmask &= ~1 << 0;
     }
   else
     {
@@ -1921,7 +1942,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
                 already know we can not swap.  */
              || nops != 0
              /* If we don't even know the previous insn, we can not
-                swap. */
+                swap.  */
              || ! prev_insn_valid
              /* If the previous insn is already in a branch delay
                 slot, then we can not swap.  */
@@ -1972,12 +1993,12 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
              || (! mips_opts.mips16
                  && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
                  && (prev_pinfo
-              /* Itbl support may require additional care here. */
+              /* Itbl support may require additional care here.  */
                      & (INSN_LOAD_COPROC_DELAY
                         | INSN_COPROC_MOVE_DELAY
                         | INSN_WRITE_COND_CODE)))
              || (! (hilo_interlocks
-                    || (mips_cpu == 3900 && (pinfo & INSN_MULT)))
+                    || (mips_cpu == CPU_R3900 && (pinfo & INSN_MULT)))
                  && (prev_pinfo
                      & (INSN_READ_LO
                         | INSN_READ_HI)))
@@ -1985,8 +2006,8 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
                  && ! gpr_interlocks
                  && (prev_pinfo & INSN_LOAD_MEMORY_DELAY))
              || (! mips_opts.mips16
-                 && mips_opts.isa == 1
-                  /* Itbl support may require additional care here. */
+                 && mips_opts.isa == ISA_MIPS1
+                  /* Itbl support may require additional care here.  */
                  && (prev_pinfo & INSN_COPROC_MEMORY_DELAY))
              /* We can not swap with a branch instruction.  */
              || (prev_pinfo
@@ -2091,7 +2112,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
                 can not swap.  */
              || (! mips_opts.mips16
                  && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
-              /* Itbl support may require additional care here. */
+              /* Itbl support may require additional care here.  */
                  && ((prev_prev_insn.insn_mo->pinfo & INSN_LOAD_COPROC_DELAY)
                      || (! gpr_interlocks
                          && (prev_prev_insn.insn_mo->pinfo
@@ -2117,8 +2138,8 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
                  mode, we can not swap.  This normally means that the
                  previous instruction was a 4 byte branch anyhow.  */
              || (mips_opts.mips16 && prev_insn_fixp)
-             /* If the previous instruction is a sync, sync.l, or 
-                sync.p, we can not swap. */
+             /* If the previous instruction is a sync, sync.l, or
+                sync.p, we can not swap.  */
              || (prev_pinfo & INSN_SYNC))
            {
              /* We could do even better for unconditional branches to
@@ -2266,7 +2287,7 @@ append_insn (place, ip, address_expr, reloc_type, unmatched_hi)
 
 /* This function forgets that there was any previous instruction or
    label.  If PRESERVE is non-zero, it remembers enough information to
-   know whether nops are needed before a noreorder section. */
+   know whether nops are needed before a noreorder section.  */
 
 static void
 mips_no_prev_insn (preserve)
@@ -2294,7 +2315,7 @@ mips_no_prev_insn (preserve)
    something other than instructions.  It inserts any NOPS which might
    be needed by the previous instruction, and clears the information
    kept for the previous instructions.  The INSNS parameter is true if
-   instructions are to follow. */
+   instructions are to follow.  */
 
 static void
 mips_emit_delays (insns)
@@ -2318,14 +2339,14 @@ mips_emit_delays (insns)
                     | INSN_READ_HI)))
          || (! mips_opts.mips16
              && ! gpr_interlocks
-             && (prev_insn.insn_mo->pinfo 
+             && (prev_insn.insn_mo->pinfo
                   & INSN_LOAD_MEMORY_DELAY))
          || (! mips_opts.mips16
-             && mips_opts.isa == 1
+             && mips_opts.isa == ISA_MIPS1
              && (prev_insn.insn_mo->pinfo
                  & INSN_COPROC_MEMORY_DELAY)))
        {
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          ++nops;
          if ((! mips_opts.mips16
               && ISA_HAS_COPROC_DELAYS (mips_opts.isa)
@@ -2347,7 +2368,7 @@ mips_emit_delays (insns)
                   && ((prev_prev_insn.insn_mo->pinfo & INSN_READ_HI)
                       || (prev_prev_insn.insn_mo->pinfo & INSN_READ_LO))))
        {
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          if (! prev_prev_insn_unreordered)
            ++nops;
        }
@@ -2373,7 +2394,7 @@ mips_emit_delays (insns)
          if (insns)
            {
              /* Move on to a new frag, so that it is safe to simply
-                 decrease the size of prev_nop_frag. */
+                 decrease the size of prev_nop_frag.  */
              frag_wane (frag_now);
              frag_new (0);
            }
@@ -2424,7 +2445,6 @@ macro_build (place, counter, ep, name, fmt, va_alist)
   struct mips_cl_insn insn;
   bfd_reloc_code_real_type r;
   va_list args;
-  int insn_isa;
 
 #ifdef USE_STDARG
   va_start (args, fmt);
@@ -2458,32 +2478,11 @@ macro_build (place, counter, ep, name, fmt, va_alist)
   /* Search until we get a match for NAME.  */
   while (1)
     {
-      insn_isa = 0;
-
-      if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA1)
-       insn_isa = 1;
-      else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA2)
-       insn_isa = 2;
-      else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA3)
-       insn_isa = 3;
-      else if ((insn.insn_mo->membership & INSN_ISA) == INSN_ISA4)
-       insn_isa = 4;
-
       if (strcmp (fmt, insn.insn_mo->args) == 0
          && insn.insn_mo->pinfo != INSN_MACRO
-         && ((insn_isa != 0
-              && insn_isa <= mips_opts.isa)
-             || (mips_cpu == 4650
-                 && (insn.insn_mo->membership & INSN_4650) != 0)
-             || (mips_cpu == 4010
-                 && (insn.insn_mo->membership & INSN_4010) != 0)
-             || ((mips_cpu == 4100
-                  || mips_cpu == 4111
-                  )
-                 && (insn.insn_mo->membership & INSN_4100) != 0)
-             || (mips_cpu == 3900
-                 && (insn.insn_mo->membership & INSN_3900) != 0))
-         && (mips_cpu != 4650 || (insn.insn_mo->pinfo & FP_D) == 0))
+         && OPCODE_IS_MEMBER (insn.insn_mo, mips_opts.isa, mips_cpu,
+                              mips_gp32)
+         && (mips_cpu != CPU_R4650 || (insn.insn_mo->pinfo & FP_D) == 0))
        break;
 
       ++insn.insn_mo;
@@ -2521,6 +2520,15 @@ macro_build (place, counter, ep, name, fmt, va_alist)
          insn.insn_opcode |= va_arg (args, int) << 11;
          continue;
 
+       case 'U':
+         {
+           int tmp = va_arg (args, int);
+
+           insn.insn_opcode |= tmp << 16;
+           insn.insn_opcode |= tmp << 11;
+           continue;
+         }
+
        case 'V':
        case 'S':
          insn.insn_opcode |= va_arg (args, int) << 11;
@@ -2541,6 +2549,10 @@ macro_build (place, counter, ep, name, fmt, va_alist)
          insn.insn_opcode |= va_arg (args, int) << 6;
          continue;
 
+       case 'J':
+         insn.insn_opcode |= va_arg (args, int) << 6;
+         continue;
+
        case 'q':
          insn.insn_opcode |= va_arg (args, int) << 6;
          continue;
@@ -2564,7 +2576,6 @@ macro_build (place, counter, ep, name, fmt, va_alist)
                  || r == BFD_RELOC_MIPS_GOT_LO16
                  || r == BFD_RELOC_MIPS_CALL_LO16
                  || (ep->X_op == O_subtract
-                     && now_seg == text_section
                      && r == BFD_RELOC_PCREL_LO16));
          continue;
 
@@ -2578,7 +2589,6 @@ macro_build (place, counter, ep, name, fmt, va_alist)
                              || r == BFD_RELOC_MIPS_GOT_HI16
                              || r == BFD_RELOC_MIPS_CALL_HI16))
                      || (ep->X_op == O_subtract
-                         && now_seg == text_section
                          && r == BFD_RELOC_PCREL_HI16_S)));
          if (ep->X_op == O_constant)
            {
@@ -2629,7 +2639,7 @@ macro_build (place, counter, ep, name, fmt, va_alist)
 static void
 mips16_macro_build (place, counter, ep, name, fmt, args)
      char *place;
-     int *counter;
+     int *counter ATTRIBUTE_UNUSED;
      expressionS *ep;
      const char *name;
      const char *fmt;
@@ -3039,63 +3049,65 @@ load_register (counter, reg, ep, dbl)
       unsigned long hi, lo;
 
       if (hi32.X_add_number == 0xffffffff)
-        {
-          if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
-            {
-              macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
+       {
+         if ((lo32.X_add_number & 0xffff8000) == 0xffff8000)
+           {
+             macro_build ((char *) NULL, counter, &lo32, "addiu", "t,r,j",
                           reg, 0, (int) BFD_RELOC_LO16);
-              return;
-            }
-          if (lo32.X_add_number & 0x80000000)
-            {
-              macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
-                           (int) BFD_RELOC_HI16);
+             return;
+           }
+         if (lo32.X_add_number & 0x80000000)
+           {
+             macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
+                          (int) BFD_RELOC_HI16);
              if (lo32.X_add_number & 0xffff)
                macro_build ((char *) NULL, counter, &lo32, "ori", "t,r,i",
                             reg, reg, (int) BFD_RELOC_LO16);
-              return;
-            }
-        }
+             return;
+           }
+       }
 
       /* Check for 16bit shifted constant.  We know that hi32 is
          non-zero, so start the mask on the first bit of the hi32
          value.  */
       shift = 17;
       do
-       {
-        unsigned long himask, lomask;
-
-        if (shift < 32)
-          {
-            himask = 0xffff >> (32 - shift);
-            lomask = (0xffff << shift) & 0xffffffff;
-          }
-        else
-          {
-            himask = 0xffff << (shift - 32);
-            lomask = 0;
-          }
-        if ((hi32.X_add_number & ~ (offsetT) himask) == 0
-            && (lo32.X_add_number & ~ (offsetT) lomask) == 0)
-          {
-            expressionS tmp;
-
-            tmp.X_op = O_constant;
-            if (shift < 32)
-              tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
-                                  | (lo32.X_add_number >> shift));
-            else
-              tmp.X_add_number = hi32.X_add_number >> (shift - 32);
-            macro_build ((char *) NULL, counter, &tmp, "ori", "t,r,i", reg, 0,
-                         (int) BFD_RELOC_LO16);
-            macro_build ((char *) NULL, counter, NULL,
-                         (shift >= 32) ? "dsll32" : "dsll",
-                         "d,w,<", reg, reg,
-                         (shift >= 32) ? shift - 32 : shift);
-            return;
-          }
-         shift++;
-       } while (shift <= (64 - 16));
+       {
+         unsigned long himask, lomask;
+
+         if (shift < 32)
+           {
+             himask = 0xffff >> (32 - shift);
+             lomask = (0xffff << shift) & 0xffffffff;
+           }
+         else
+           {
+             himask = 0xffff << (shift - 32);
+             lomask = 0;
+           }
+         if ((hi32.X_add_number & ~(offsetT) himask) == 0
+             && (lo32.X_add_number & ~(offsetT) lomask) == 0)
+           {
+             expressionS tmp;
+
+             tmp.X_op = O_constant;
+             if (shift < 32)
+               tmp.X_add_number = ((hi32.X_add_number << (32 - shift))
+                                   | (lo32.X_add_number >> shift));
+             else
+               tmp.X_add_number = hi32.X_add_number >> (shift - 32);
+             macro_build ((char *) NULL, counter, &tmp,
+                          "ori", "t,r,i", reg, 0,
+                          (int) BFD_RELOC_LO16);
+             macro_build ((char *) NULL, counter, NULL,
+                          (shift >= 32) ? "dsll32" : "dsll",
+                          "d,w,<", reg, reg,
+                          (shift >= 32) ? shift - 32 : shift);
+             return;
+           }
+         shift++;
+       }
+      while (shift <= (64 - 16));
 
       /* Find the bit number of the lowest one bit, and store the
          shifted value in hi/lo.  */
@@ -3127,38 +3139,38 @@ load_register (counter, reg, ep, dbl)
       /* Optimize if the shifted value is a (power of 2) - 1.  */
       if ((hi == 0 && ((lo + 1) & lo) == 0)
          || (lo == 0xffffffff && ((hi + 1) & hi) == 0))
-        {
-          shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
+       {
+         shift = COUNT_TOP_ZEROES ((unsigned int) hi32.X_add_number);
          if (shift != 0)
-            {
+           {
              expressionS tmp;
 
              /* This instruction will set the register to be all
                  ones.  */
-              tmp.X_op = O_constant;
-              tmp.X_add_number = (offsetT) -1;
-              macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
+             tmp.X_op = O_constant;
+             tmp.X_add_number = (offsetT) -1;
+             macro_build ((char *) NULL, counter, &tmp, "addiu", "t,r,j",
                           reg, 0, (int) BFD_RELOC_LO16);
-              if (bit != 0)
-                {
-                  bit += shift;
-                  macro_build ((char *) NULL, counter, NULL,
-                               (bit >= 32) ? "dsll32" : "dsll",
-                               "d,w,<", reg, reg,
-                               (bit >= 32) ? bit - 32 : bit);
-                }
-              macro_build ((char *) NULL, counter, NULL,
+             if (bit != 0)
+               {
+                 bit += shift;
+                 macro_build ((char *) NULL, counter, NULL,
+                              (bit >= 32) ? "dsll32" : "dsll",
+                              "d,w,<", reg, reg,
+                              (bit >= 32) ? bit - 32 : bit);
+               }
+             macro_build ((char *) NULL, counter, NULL,
                           (shift >= 32) ? "dsrl32" : "dsrl",
-                           "d,w,<", reg, reg,
+                          "d,w,<", reg, reg,
                           (shift >= 32) ? shift - 32 : shift);
-              return;
-            }
-        }
+             return;
+           }
+       }
 
       /* Sign extend hi32 before calling load_register, because we can
          generally get better code when we load a sign extended value.  */
       if ((hi32.X_add_number & 0x80000000) != 0)
-       hi32.X_add_number |= ~ (offsetT) 0xffffffff;
+       hi32.X_add_number |= ~(offsetT) 0xffffffff;
       load_register (counter, reg, &hi32, 0);
       freg = reg;
     }
@@ -3176,13 +3188,13 @@ load_register (counter, reg, ep, dbl)
       expressionS mid16;
 
       if ((freg == 0) && (lo32.X_add_number == 0xffffffff))
-        {
+       {
          macro_build ((char *) NULL, counter, &lo32, "lui", "t,u", reg,
                       (int) BFD_RELOC_HI16);
-          macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg,
-                       reg, 0);
-          return;
-        }
+         macro_build ((char *) NULL, counter, NULL, "dsrl32", "d,w,<", reg,
+                      reg, 0);
+         return;
+       }
 
       if (freg != 0)
        {
@@ -3235,7 +3247,7 @@ load_address (counter, reg, ep)
           addiu        $reg,$reg,<sym>         (BFD_RELOC_LO16)
         If we have an addend, we always use the latter form.  */
       if ((valueT) ep->X_add_number >= MAX_GPREL_OFFSET
-          || nopic_need_relax (ep->X_add_symbol, 1))
+         || nopic_need_relax (ep->X_add_symbol, 1))
        p = NULL;
       else
        {
@@ -3412,7 +3424,7 @@ macro (ip)
   int tempreg;
   int mask;
   int icnt = 0;
-  int used_at;
+  int used_at = 0;
   expressionS expr1;
   const char *s;
   const char *s2;
@@ -3925,7 +3937,7 @@ macro (ip)
          if (mips_trap)
            macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
          else
-             macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
+           macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
          return;
        }
 
@@ -3946,7 +3958,7 @@ macro (ip)
          macro_build ((char *) NULL, &icnt, NULL,
                       dbl ? "ddiv" : "div",
                       "z,s,t", sreg, treg);
-           macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
+         macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
        }
       expr1.X_add_number = -1;
       macro_build ((char *) NULL, &icnt, &expr1,
@@ -3985,7 +3997,7 @@ macro (ip)
             that later insns are available for delay slot filling.  */
          --mips_opts.noreorder;
 
-           macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
+         macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
        }
       macro_build ((char *) NULL, &icnt, NULL, s, "d", dreg);
       break;
@@ -4032,7 +4044,7 @@ macro (ip)
          if (mips_trap)
            macro_build ((char *) NULL, &icnt, NULL, "teq", "s,t", 0, 0);
          else
-             macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
+           macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
          return;
        }
       if (imm_expr.X_op == O_constant && imm_expr.X_add_number == 1)
@@ -4103,7 +4115,7 @@ macro (ip)
          /* We want to close the noreorder block as soon as possible, so
             that later insns are available for delay slot filling.  */
          --mips_opts.noreorder;
-           macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
+         macro_build ((char *) NULL, &icnt, NULL, "break", "c", 7);
        }
       macro_build ((char *) NULL, &icnt, NULL, s2, "d", dreg);
       return;
@@ -4117,23 +4129,23 @@ macro (ip)
       /* When generating embedded PIC code, we permit expressions of
         the form
           la   $4,foo-bar
-        where bar is an address in the .text section.  These are used
+        where bar is an address in the current section.  These are used
         when getting the addresses of functions.  We don't permit
         X_add_number to be non-zero, because if the symbol is
         external the relaxing code needs to know that any addend is
         purely the offset to X_op_symbol.  */
       if (mips_pic == EMBEDDED_PIC
          && offset_expr.X_op == O_subtract
-         && now_seg == text_section
          && (symbol_constant_p (offset_expr.X_op_symbol)
-             ? S_GET_SEGMENT (offset_expr.X_op_symbol) == text_section
+             ? S_GET_SEGMENT (offset_expr.X_op_symbol) == now_seg
              : (symbol_equated_p (offset_expr.X_op_symbol)
                 && (S_GET_SEGMENT
                     (symbol_get_value_expression (offset_expr.X_op_symbol)
                      ->X_add_symbol)
-                    == text_section)))
+                    == now_seg)))
          && breg == 0
-         && offset_expr.X_add_number == 0)
+         && (offset_expr.X_add_number == 0
+             || OUTPUT_FLAVOR == bfd_target_elf_flavour))
        {
          macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
                       treg, (int) BFD_RELOC_PCREL_HI16_S);
@@ -4202,9 +4214,13 @@ macro (ip)
        }
       else if (mips_pic == SVR4_PIC && ! mips_big_got)
        {
+         int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT16;
+
          /* If this is a reference to an external symbol, and there
             is no constant, we want
               lw       $tempreg,<sym>($gp)     (BFD_RELOC_MIPS_GOT16)
+            or if tempreg is PIC_CALL_REG
+              lw       $tempreg,<sym>($gp)     (BFD_RELOC_MIPS_CALL16)
             For a local symbol, we want
               lw       $tempreg,<sym>($gp)     (BFD_RELOC_MIPS_GOT16)
               nop
@@ -4231,9 +4247,11 @@ macro (ip)
          expr1.X_add_number = offset_expr.X_add_number;
          offset_expr.X_add_number = 0;
          frag_grow (32);
+         if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
+           lw_reloc_type = (int) BFD_RELOC_MIPS_CALL16;
          macro_build ((char *) NULL, &icnt, &offset_expr,
                       dbl ? "ld" : "lw",
-                      "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
+                      "t,o(b)", tempreg, lw_reloc_type, GP);
          if (expr1.X_add_number == 0)
            {
              int off;
@@ -4339,12 +4357,18 @@ macro (ip)
       else if (mips_pic == SVR4_PIC)
        {
          int gpdel;
+         int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
+         int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
 
          /* This is the large GOT case.  If this is a reference to an
             external symbol, and there is no constant, we want
               lui      $tempreg,<sym>          (BFD_RELOC_MIPS_GOT_HI16)
               addu     $tempreg,$tempreg,$gp
               lw       $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_GOT_LO16)
+            or if tempreg is PIC_CALL_REG
+              lui      $tempreg,<sym>          (BFD_RELOC_MIPS_CALL_HI16)
+              addu     $tempreg,$tempreg,$gp
+              lw       $tempreg,<sym>($tempreg) (BFD_RELOC_MIPS_CALL_LO16)
             For a local symbol, we want
               lw       $tempreg,<sym>($gp)     (BFD_RELOC_MIPS_GOT16)
               nop
@@ -4383,8 +4407,13 @@ macro (ip)
            gpdel = 4;
          else
            gpdel = 0;
+         if (expr1.X_add_number == 0 && tempreg == PIC_CALL_REG)
+           {
+             lui_reloc_type = (int) BFD_RELOC_MIPS_CALL_HI16;
+             lw_reloc_type = (int) BFD_RELOC_MIPS_CALL_LO16;
+           }
          macro_build ((char *) NULL, &icnt, &offset_expr, "lui", "t,u",
-                      tempreg, (int) BFD_RELOC_MIPS_GOT_HI16);
+                      tempreg, lui_reloc_type);
          macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
                       ((bfd_arch_bits_per_address (stdoutput) == 32
                         || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
@@ -4392,8 +4421,7 @@ macro (ip)
                       "d,v,t", tempreg, tempreg, GP);
          macro_build ((char *) NULL, &icnt, &offset_expr,
                       dbl ? "ld" : "lw",
-                      "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT_LO16,
-                      tempreg);
+                      "t,o(b)", tempreg, lw_reloc_type, tempreg);
          if (expr1.X_add_number == 0)
            {
              int off;
@@ -4613,7 +4641,7 @@ macro (ip)
        {
          if (sreg != PIC_CALL_REG)
            as_warn (_("MIPS PIC call to register other than $25"));
-      
+
          macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "jalr",
                       "d,s", dreg, sreg);
          if (mips_cprestore_offset < 0)
@@ -4719,7 +4747,7 @@ macro (ip)
              p += 4;
              macro_build (p, &icnt, (expressionS *) NULL, "nop", "");
              p += 4;
-           }                      
+           }
          macro_build (p, &icnt, &offset_expr,
                       ((bfd_arch_bits_per_address (stdoutput) == 32
                         || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
@@ -4773,22 +4801,22 @@ macro (ip)
       goto ld;
     case M_LWC0_AB:
       s = "lwc0";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ld;
     case M_LWC1_AB:
       s = "lwc1";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ld;
     case M_LWC2_AB:
       s = "lwc2";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ld;
     case M_LWC3_AB:
       s = "lwc3";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ld;
     case M_LWL_AB:
@@ -4800,23 +4828,23 @@ macro (ip)
       lr = 1;
       goto ld;
     case M_LDC1_AB:
-      if (mips_cpu == 4650)
+      if (mips_cpu == CPU_R4650)
        {
          as_bad (_("opcode not supported on this processor"));
          return;
        }
       s = "ldc1";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ld;
     case M_LDC2_AB:
       s = "ldc2";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ld;
     case M_LDC3_AB:
       s = "ldc3";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ld;
     case M_LDL_AB:
@@ -4858,22 +4886,22 @@ macro (ip)
       goto st;
     case M_SWC0_AB:
       s = "swc0";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto st;
     case M_SWC1_AB:
       s = "swc1";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto st;
     case M_SWC2_AB:
       s = "swc2";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto st;
     case M_SWC3_AB:
       s = "swc3";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto st;
     case M_SWL_AB:
@@ -4889,23 +4917,23 @@ macro (ip)
       s = "scd";
       goto st;
     case M_SDC1_AB:
-      if (mips_cpu == 4650)
+      if (mips_cpu == CPU_R4650)
        {
          as_bad (_("opcode not supported on this processor"));
          return;
        }
       s = "sdc1";
       coproc = 1;
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       goto st;
     case M_SDC2_AB:
       s = "sdc2";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto st;
     case M_SDC3_AB:
       s = "sdc3";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto st;
     case M_SDL_AB:
@@ -4917,7 +4945,7 @@ macro (ip)
       tempreg = AT;
       used_at = 1;
     ld_st:
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       if (mask == M_LWC1_AB
          || mask == M_SWC1_AB
          || mask == M_LDC1_AB
@@ -5049,7 +5077,7 @@ macro (ip)
                        ? "lw" : "ld"),
                       "t,o(b)", tempreg, (int) BFD_RELOC_MIPS_GOT16, GP);
          macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
-         p = frag_var (rs_machine_dependent, 4, 0, 
+         p = frag_var (rs_machine_dependent, 4, 0,
                        RELAX_ENCODE (0, 4, -8, 0, 0, 0),
                        offset_expr.X_add_symbol, (offsetT) 0,
                        (char *) NULL);
@@ -5274,7 +5302,7 @@ macro (ip)
        }
       else
        abort ();
-       
+
       /* Now we load the register(s).  */
       if (ISA_HAS_64BIT_REGS (mips_opts.isa))
        macro_build ((char *) NULL, &icnt, &offset_expr, "ld", "t,o(b)",
@@ -5334,7 +5362,7 @@ macro (ip)
       s = segment_name (S_GET_SEGMENT (offset_expr.X_add_symbol));
       if (strcmp (s, ".lit8") == 0)
        {
-         if (mips_opts.isa != 1)
+         if (mips_opts.isa != ISA_MIPS1)
            {
              macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
                           "T,o(b)", treg, (int) BFD_RELOC_MIPS_LITERAL, GP);
@@ -5358,8 +5386,8 @@ macro (ip)
              /* FIXME: This won't work for a 64 bit address.  */
              macro_build_lui ((char *) NULL, &icnt, &offset_expr, AT);
            }
-             
-         if (mips_opts.isa != 1)
+
+         if (mips_opts.isa != ISA_MIPS1)
            {
              macro_build ((char *) NULL, &icnt, &offset_expr, "ldc1",
                           "T,o(b)", treg, (int) BFD_RELOC_LO16, AT);
@@ -5377,7 +5405,7 @@ macro (ip)
        }
 
     case M_L_DOB:
-      if (mips_cpu == 4650)
+      if (mips_cpu == CPU_R4650)
        {
          as_bad (_("opcode not supported on this processor"));
          return;
@@ -5386,7 +5414,7 @@ macro (ip)
         to adjust when loading from memory.  */
       r = BFD_RELOC_LO16;
     dob:
-      assert (mips_opts.isa == 1);
+      assert (mips_opts.isa == ISA_MIPS1);
       macro_build ((char *) NULL, &icnt, &offset_expr, "lwc1", "T,o(b)",
                   target_big_endian ? treg + 1 : treg,
                   (int) r, breg);
@@ -5418,14 +5446,14 @@ macro (ip)
        * But, the resulting address is the same after relocation so why
        * generate the extra instruction?
        */
-      if (mips_cpu == 4650)
+      if (mips_cpu == CPU_R4650)
        {
          as_bad (_("opcode not supported on this processor"));
          return;
        }
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
-      if (mips_opts.isa != 1)
+      if (mips_opts.isa != ISA_MIPS1)
        {
          s = "ldc1";
          goto ld;
@@ -5436,13 +5464,13 @@ macro (ip)
       goto ldd_std;
 
     case M_S_DAB:
-      if (mips_cpu == 4650)
+      if (mips_cpu == CPU_R4650)
        {
          as_bad (_("opcode not supported on this processor"));
          return;
        }
 
-      if (mips_opts.isa != 1)
+      if (mips_opts.isa != ISA_MIPS1)
        {
          s = "sdc1";
          goto st;
@@ -5450,7 +5478,7 @@ macro (ip)
 
       s = "swc1";
       fmt = "T,o(b)";
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       coproc = 1;
       goto ldd_std;
 
@@ -5486,7 +5514,7 @@ macro (ip)
       /* Even on a big endian machine $fn comes before $fn+1.  We have
         to adjust when loading from memory.  We set coproc if we must
         load $fn+1 first.  */
-      /* Itbl support may require additional care here. */
+      /* Itbl support may require additional care here.  */
       if (! target_big_endian)
        coproc = 0;
 
@@ -5537,7 +5565,7 @@ macro (ip)
                  used_at = 1;
                }
 
-              /* Itbl support may require additional care here. */
+             /* Itbl support may require additional care here.  */
              macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
                           coproc ? treg + 1 : treg,
                           (int) BFD_RELOC_MIPS_GPREL, tempreg);
@@ -5547,7 +5575,7 @@ macro (ip)
                  undesired nop.  */
              hold_mips_optimize = mips_optimize;
              mips_optimize = 2;
-              /* Itbl support may require additional care here. */
+             /* Itbl support may require additional care here.  */
              macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
                           coproc ? treg : treg + 1,
                           (int) BFD_RELOC_MIPS_GPREL, tempreg);
@@ -5593,7 +5621,7 @@ macro (ip)
              if (p != NULL)
                p += 4;
            }
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build (p, &icnt, &offset_expr, s, fmt,
                       coproc ? treg + 1 : treg,
                       (int) BFD_RELOC_LO16, AT);
@@ -5601,11 +5629,11 @@ macro (ip)
            p += 4;
          /* FIXME: How do we handle overflow here?  */
          offset_expr.X_add_number += 4;
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build (p, &icnt, &offset_expr, s, fmt,
                       coproc ? treg : treg + 1,
                       (int) BFD_RELOC_LO16, AT);
-       }         
+       }
       else if (mips_pic == SVR4_PIC && ! mips_big_got)
        {
          int off;
@@ -5646,7 +5674,7 @@ macro (ip)
                           || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
                          ? "addu" : "daddu"),
                         "d,v,t", AT, breg, AT);
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
                       coproc ? treg + 1 : treg,
                       (int) BFD_RELOC_LO16, AT);
@@ -5656,7 +5684,7 @@ macro (ip)
              nop.  */
          hold_mips_optimize = mips_optimize;
          mips_optimize = 2;
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
                       coproc ? treg : treg + 1,
                       (int) BFD_RELOC_LO16, AT);
@@ -5720,7 +5748,7 @@ macro (ip)
                           || ! ISA_HAS_64BIT_REGS (mips_opts.isa))
                          ? "addu" : "daddu"),
                         "d,v,t", AT, breg, AT);
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
                       coproc ? treg + 1 : treg,
                       (int) BFD_RELOC_LO16, AT);
@@ -5730,7 +5758,7 @@ macro (ip)
              nop.  */
          hold_mips_optimize = mips_optimize;
          mips_optimize = 2;
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build ((char *) NULL, &icnt, &expr1, s, fmt,
                       coproc ? treg : treg + 1,
                       (int) BFD_RELOC_LO16, AT);
@@ -5764,7 +5792,7 @@ macro (ip)
                           "d,v,t", AT, breg, AT);
              p += 4;
            }
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build (p, &icnt, &expr1, s, fmt,
                       coproc ? treg + 1 : treg,
                       (int) BFD_RELOC_LO16, AT);
@@ -5775,7 +5803,7 @@ macro (ip)
              nop.  */
          hold_mips_optimize = mips_optimize;
          mips_optimize = 2;
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build (p, &icnt, &expr1, s, fmt,
                       coproc ? treg : treg + 1,
                       (int) BFD_RELOC_LO16, AT);
@@ -5807,12 +5835,12 @@ macro (ip)
              used_at = 1;
            }
 
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
                       coproc ? treg + 1 : treg,
                       (int) BFD_RELOC_MIPS_GPREL, tempreg);
          offset_expr.X_add_number += 4;
-          /* Itbl support may require additional care here. */
+         /* Itbl support may require additional care here.  */
          macro_build ((char *) NULL, &icnt, &offset_expr, s, fmt,
                       coproc ? treg : treg + 1,
                       (int) BFD_RELOC_MIPS_GPREL, tempreg);
@@ -5831,7 +5859,7 @@ macro (ip)
     case M_SD_OB:
       s = "sw";
     sd_ob:
-      assert (bfd_arch_bits_per_address (stdoutput) == 32 
+      assert (bfd_arch_bits_per_address (stdoutput) == 32
              || ! ISA_HAS_64BIT_REGS (mips_opts.isa));
       macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
                   (int) BFD_RELOC_LO16, breg);
@@ -5852,10 +5880,10 @@ macro (ip)
       What are the side-effects of the cop instruction?
       What cache support might we have and what are its effects?
       Both coprocessor & memory require delays. how long???
-      What registers are read/set/modified? 
+      What registers are read/set/modified?
 
       If an itbl is provided to interpret cop instructions,
-      this knowledge can be encoded in the itbl spec. */
+      this knowledge can be encoded in the itbl spec.  */
 
     case M_COP0:
       s = "c0";
@@ -5881,26 +5909,26 @@ macro (ip)
          This code builds table entries out of the macros in mip_opcodes.
          FIXME: For now we just assemble the expression and pass it's
          value along as a 32-bit immediate.
-         We may want to have the assembler assemble this value, 
+         We may want to have the assembler assemble this value,
          so that we gain the assembler's knowledge of delay slots,
          symbols, etc.
          Would it be more efficient to use mask (id) here? */
-      if (itbl_have_entries 
+      if (itbl_have_entries
          && (immed_expr = itbl_assemble (ip->insn_mo->name, "")))
-        {
+       {
          s = ip->insn_mo->name;
          s2 = "cop3";
          coproc = ITBL_DECODE_PNUM (immed_expr);;
          macro_build ((char *) NULL, &icnt, &immed_expr, s, "C");
          return;
-        }
+       }
       macro2 (ip);
       return;
     }
   if (mips_opts.noat)
     as_warn (_("Macro used $at after \".set noat\""));
 }
-          
+
 static void
 macro2 (ip)
      struct mips_cl_insn *ip;
@@ -5923,17 +5951,17 @@ macro2 (ip)
   offsetT maxnum;
   bfd_reloc_code_real_type r;
   char *p;
-          
+
   treg = (ip->insn_opcode >> 16) & 0x1f;
   dreg = (ip->insn_opcode >> 11) & 0x1f;
   sreg = breg = (ip->insn_opcode >> 21) & 0x1f;
   mask = ip->insn_mo->mask;
-          
+
   expr1.X_op = O_constant;
   expr1.X_op_symbol = NULL;
   expr1.X_add_symbol = NULL;
   expr1.X_add_number = 1;
-          
+
   switch (mask)
     {
 #endif /* LOSING_COMPILER */
@@ -5990,7 +6018,7 @@ macro2 (ip)
          expr1.X_add_number = 8;
          macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", dreg, AT);
          macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
-           macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
+         macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
        }
       --mips_opts.noreorder;
       macro_build ((char *) NULL, &icnt, NULL, "mflo", "d", dreg);
@@ -6023,7 +6051,7 @@ macro2 (ip)
          expr1.X_add_number = 8;
          macro_build ((char *) NULL, &icnt, &expr1, "beq", "s,t,p", AT, 0);
          macro_build ((char *) NULL, &icnt, NULL, "nop", "", 0);
-           macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
+         macro_build ((char *) NULL, &icnt, NULL, "break", "c", 6);
        }
       --mips_opts.noreorder;
       break;
@@ -6065,12 +6093,12 @@ macro2 (ip)
       break;
 
     case M_S_DOB:
-      if (mips_cpu == 4650)
+      if (mips_cpu == CPU_R4650)
        {
          as_bad (_("opcode not supported on this processor"));
          return;
        }
-      assert (mips_opts.isa == 1);
+      assert (mips_opts.isa == ISA_MIPS1);
       /* Even on a big endian machine $fn comes before $fn+1.  We have
         to adjust when storing to memory.  */
       macro_build ((char *) NULL, &icnt, &offset_expr, "swc1", "T,o(b)",
@@ -6377,9 +6405,9 @@ macro2 (ip)
       macro_build ((char *) NULL, &icnt, NULL, s, "s,t", sreg, AT);
       break;
 
-    case M_TRUNCWD:
     case M_TRUNCWS:
-      assert (mips_opts.isa == 1);
+    case M_TRUNCWD:
+      assert (mips_opts.isa == ISA_MIPS1);
       sreg = (ip->insn_opcode >> 11) & 0x1f;   /* floating reg */
       dreg = (ip->insn_opcode >> 06) & 0x1f;   /* floating reg */
 
@@ -6617,7 +6645,7 @@ macro2 (ip)
 
     default:
       /* FIXME: Check if this is one of the itbl macros, since they
-        are added dynamically. */
+        are added dynamically.  */
       as_bad (_("Macro %s not implemented yet"), ip->insn_mo->name);
       break;
     }
@@ -6676,8 +6704,8 @@ mips16_macro (ip)
                   "0,x,y", xreg, yreg);
       expr1.X_add_number = 2;
       macro_build ((char *) NULL, &icnt, &expr1, "bnez", "x,p", yreg);
-       macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
-      
+      macro_build ((char *) NULL, &icnt, NULL, "break", "6", 7);
+
       /* FIXME: The normal code checks for of -1 / -0x80000000 here,
          since that causes an overflow.  We should do that as well,
          but I don't see how to do the comparisons without a temporary
@@ -6902,13 +6930,15 @@ validate_mips_insn (opc)
       case '<': USE_BITS (OP_MASK_SHAMT,       OP_SH_SHAMT);   break;
       case '>':        USE_BITS (OP_MASK_SHAMT,        OP_SH_SHAMT);   break;
       case 'A': break;
-      case 'B':        USE_BITS (OP_MASK_SYSCALL,      OP_SH_SYSCALL); break;
+      case 'B': USE_BITS (OP_MASK_CODE20,       OP_SH_CODE20);  break;
       case 'C':        USE_BITS (OP_MASK_COPZ,         OP_SH_COPZ);    break;
       case 'D':        USE_BITS (OP_MASK_FD,           OP_SH_FD);      break;
       case 'E':        USE_BITS (OP_MASK_RT,           OP_SH_RT);      break;
       case 'F': break;
       case 'G':        USE_BITS (OP_MASK_RD,           OP_SH_RD);      break;
+      case 'H': USE_BITS (OP_MASK_SEL,         OP_SH_SEL);     break;
       case 'I': break;
+      case 'J': USE_BITS (OP_MASK_CODE19,       OP_SH_CODE19);  break;
       case 'L': break;
       case 'M':        USE_BITS (OP_MASK_CCC,          OP_SH_CCC);     break;
       case 'N':        USE_BITS (OP_MASK_BCC,          OP_SH_BCC);     break;
@@ -6939,6 +6969,8 @@ validate_mips_insn (opc)
       case 'x': break;
       case 'z': break;
       case 'P': USE_BITS (OP_MASK_PERFREG,     OP_SH_PERFREG); break;
+      case 'U': USE_BITS (OP_MASK_RD,           OP_SH_RD);
+               USE_BITS (OP_MASK_RT,           OP_SH_RT);      break;
       default:
        as_bad (_("internal: bad mips opcode (unknown operand type `%c'): %s %s"),
                c, opc->name, opc->args);
@@ -6966,7 +6998,7 @@ mips_ip (str, ip)
 {
   char *s;
   const char *args;
-  char c;
+  char c = 0;
   struct mips_opcode *insn;
   char *argsStart;
   unsigned int regno;
@@ -6991,7 +7023,7 @@ mips_ip (str, ip)
       save_c = *s;
       *s++ = '\0';
     }
-       
+
   insn = (struct mips_opcode *) hash_find (op_hash, str);
 
   /* If we didn't find the instruction in the opcode table, try again, but
@@ -6999,7 +7031,7 @@ mips_ip (str, ip)
      first '.'.  */
   if (insn == NULL)
     {
-      /* Restore the character we overwrite above (if any).  */ 
+      /* Restore the character we overwrite above (if any).  */
       if (save_c)
        *(--s) = save_c;
 
@@ -7028,40 +7060,18 @@ mips_ip (str, ip)
   argsStart = s;
   for (;;)
     {
-      int insn_isa;
       boolean ok;
 
       assert (strcmp (insn->name, str) == 0);
 
-      insn_isa = 0;
-      if ((insn->membership & INSN_ISA) == INSN_ISA1)
-       insn_isa = 1;
-      else if ((insn->membership & INSN_ISA) == INSN_ISA2)
-       insn_isa = 2;
-      else if ((insn->membership & INSN_ISA) == INSN_ISA3)
-       insn_isa = 3;
-      else if ((insn->membership & INSN_ISA) == INSN_ISA4)
-       insn_isa = 4;
-
-      if (insn_isa != 0 
-         && insn_isa <= mips_opts.isa)
-       ok = true;
-      else if (insn->pinfo == INSN_MACRO)
-       ok = false;
-      else if ((mips_cpu == 4650 && (insn->membership & INSN_4650) != 0)
-              || (mips_cpu == 4010 && (insn->membership & INSN_4010) != 0)
-              || ((mips_cpu == 4100
-                   || mips_cpu == 4111
-                   )
-                  && (insn->membership & INSN_4100) != 0)
-              || (mips_cpu == 3900 && (insn->membership & INSN_3900) != 0))
+      if (OPCODE_IS_MEMBER (insn, mips_opts.isa, mips_cpu, mips_gp32))
        ok = true;
       else
        ok = false;
 
       if (insn->pinfo != INSN_MACRO)
        {
-         if (mips_cpu == 4650 && (insn->pinfo & FP_D) != 0)
+         if (mips_cpu == CPU_R4650 && (insn->pinfo & FP_D) != 0)
            ok = false;
        }
 
@@ -7073,18 +7083,17 @@ mips_ip (str, ip)
              ++insn;
              continue;
            }
-
-         if (insn_isa == 0
-              || insn_isa <= mips_opts.isa)
-           insn_error = _("opcode not supported on this processor");
          else
            {
              static char buf[100];
+             sprintf (buf,
+                      _("opcode not supported on this processor: %s (%s)"),
+                      mips_cpu_to_str (mips_cpu),
+                      mips_isa_to_str (mips_opts.isa));
 
-             sprintf (buf, _("opcode requires -mips%d or greater"), insn_isa);
              insn_error = buf;
+             return;
            }
-         return;
        }
 
       ip->insn_mo = insn;
@@ -7125,7 +7134,7 @@ mips_ip (str, ip)
            case '(':
              /* Handle optional base register.
                 Either the base register is omitted or
-                we must have a left paren. */
+                we must have a left paren.  */
              /* This is dependent on the next operand specifier
                 is a base register specification.  */
              assert (args[1] == 'b' || args[1] == '5'
@@ -7169,7 +7178,6 @@ mips_ip (str, ip)
              s = expr_end;
              continue;
 
-
            case 'k':           /* cache code */
            case 'h':           /* prefx code */
              my_getExpression (&imm_expr, s);
@@ -7217,11 +7225,11 @@ mips_ip (str, ip)
              s = expr_end;
              continue;
 
-           case 'B':           /* syscall code */
+           case 'B':           /* 20-bit syscall/break code.  */
              my_getExpression (&imm_expr, s);
              check_absolute_expr (ip, &imm_expr);
              if ((unsigned) imm_expr.X_add_number > 0xfffff)
-               as_warn (_("Illegal syscall code (%ld)"),
+               as_warn (_("Illegal 20-bit code (%ld)"),
                         (long) imm_expr.X_add_number);
              ip->insn_opcode |= imm_expr.X_add_number << 6;
              imm_expr.X_op = O_absent;
@@ -7229,32 +7237,43 @@ mips_ip (str, ip)
              continue;
 
             case 'C':           /* Coprocessor code */
-              my_getExpression (&imm_expr, s);
+             my_getExpression (&imm_expr, s);
              check_absolute_expr (ip, &imm_expr);
-              if ((unsigned long) imm_expr.X_add_number >= (1<<25))
+             if ((unsigned long) imm_expr.X_add_number >= (1<<25))
                {
-                  as_warn (_("Coproccesor code > 25 bits (%ld)"),
+                 as_warn (_("Coproccesor code > 25 bits (%ld)"),
                           (long) imm_expr.X_add_number);
-                  imm_expr.X_add_number &= ((1<<25) - 1);
+                 imm_expr.X_add_number &= ((1<<25) - 1);
                }
-              ip->insn_opcode |= imm_expr.X_add_number;
-              imm_expr.X_op = O_absent;
-              s = expr_end;
-              continue;
+             ip->insn_opcode |= imm_expr.X_add_number;
+             imm_expr.X_op = O_absent;
+             s = expr_end;
+             continue;
+
+           case 'J':           /* 19-bit wait code.  */
+             my_getExpression (&imm_expr, s);
+             check_absolute_expr (ip, &imm_expr);
+             if ((unsigned) imm_expr.X_add_number > 0x7ffff)
+               as_warn (_("Illegal 19-bit code (%ld)"),
+                        (long) imm_expr.X_add_number);
+             ip->insn_opcode |= imm_expr.X_add_number << 6;
+             imm_expr.X_op = O_absent;
+             s = expr_end;
+             continue;
 
            case 'P':           /* Performance register */
-              my_getExpression (&imm_expr, s);
+             my_getExpression (&imm_expr, s);
              check_absolute_expr (ip, &imm_expr);
-              if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
+             if (imm_expr.X_add_number != 0 && imm_expr.X_add_number != 1)
                {
-                  as_warn (_("Invalidate performance regster (%ld)"),
+                 as_warn (_("Invalidate performance regster (%ld)"),
                           (long) imm_expr.X_add_number);
-                  imm_expr.X_add_number &= 1;
+                 imm_expr.X_add_number &= 1;
                }
-              ip->insn_opcode |= (imm_expr.X_add_number << 1);
-              imm_expr.X_op = O_absent;
-              s = expr_end;
-              continue;
+             ip->insn_opcode |= (imm_expr.X_add_number << 1);
+             imm_expr.X_op = O_absent;
+             s = expr_end;
+             continue;
 
            case 'b':           /* base register */
            case 'd':           /* destination register */
@@ -7267,6 +7286,7 @@ mips_ip (str, ip)
            case 'G':           /* coprocessor destination register */
            case 'x':           /* ignore register name */
            case 'z':           /* must be zero register */
+           case 'U':           /* destination register (clo/clz).  */
              s_reset = s;
              if (s[0] == '$')
                {
@@ -7334,15 +7354,15 @@ mips_ip (str, ip)
                              /* Get_field advances to the start of
                                 the next field, so we need to back
                                 rack to the end of the last field.  */
-                             if (p) 
+                             if (p)
                                s = p - 1;
-                             else 
+                             else
                                s = strchr (s, '\0');
                              regno = r;
                            }
                          else
                            goto notreg;
-                         }
+                       }
                      else
                        goto notreg;
                    }
@@ -7367,8 +7387,8 @@ mips_ip (str, ip)
                  if (c == 'z' && regno != 0)
                    break;
 
-       /* Now that we have assembled one operand, we use the args string 
-        * to figure out where it goes in the instruction. */
+       /* Now that we have assembled one operand, we use the args string
+        * to figure out where it goes in the instruction.  */
                  switch (c)
                    {
                    case 'r':
@@ -7381,6 +7401,10 @@ mips_ip (str, ip)
                    case 'G':
                      ip->insn_opcode |= regno << 11;
                      break;
+                   case 'U':
+                     ip->insn_opcode |= regno << 11;
+                     ip->insn_opcode |= regno << 16;
+                     break;
                    case 'w':
                    case 't':
                    case 'E':
@@ -7489,7 +7513,6 @@ mips_ip (str, ip)
                  continue;
                }
 
-
              switch (*args++)
                {
                case 'V':
@@ -7571,7 +7594,7 @@ mips_ip (str, ip)
                    length = f64 ? 8 : 4;
                  }
 
-               assert (length == (f64 ? 8 : 4));
+               assert (length == (unsigned) (f64 ? 8 : 4));
 
                if (*args == 'f'
                    || (*args == 'l'
@@ -7588,6 +7611,7 @@ mips_ip (str, ip)
                      imm_expr.X_add_number = bfd_getb32 (temp);
                  }
                else if (length > 4
+                        && ! mips_disable_float_construction
                         && ((temp[0] == 0 && temp[1] == 0)
                             || (temp[2] == 0 && temp[3] == 0))
                         && ((temp[4] == 0 && temp[5] == 0)
@@ -7657,11 +7681,15 @@ mips_ip (str, ip)
                      default: /* unused default case avoids warnings.  */
                      case 'L':
                        newname = RDATA_SECTION_NAME;
-                       if (USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
+                       if ((USE_GLOBAL_POINTER_OPT && g_switch_value >= 8)
+                           || mips_pic == EMBEDDED_PIC)
                          newname = ".lit8";
                        break;
                      case 'F':
-                       newname = RDATA_SECTION_NAME;
+                       if (mips_pic == EMBEDDED_PIC)
+                         newname = ".lit8";
+                       else
+                         newname = RDATA_SECTION_NAME;
                        break;
                      case 'l':
                        assert (!USE_GLOBAL_POINTER_OPT
@@ -7729,16 +7757,14 @@ mips_ip (str, ip)
                {
                  if ((c == '\0' && imm_expr.X_op != O_constant)
                      || ((imm_expr.X_add_number < 0
-                           || imm_expr.X_add_number >= 0x10000)
-                          && imm_expr.X_op == O_constant))
+                          || imm_expr.X_add_number >= 0x10000)
+                         && imm_expr.X_op == O_constant))
                    {
                      if (insn + 1 < &mips_opcodes[NUMOPCODES] &&
                          !strcmp (insn->name, insn[1].name))
                        break;
-                     if (imm_expr.X_op != O_constant
-                         && imm_expr.X_op != O_big)
-                       insn_error = _("absolute expression required");
-                     else
+                     if (imm_expr.X_op == O_constant
+                         || imm_expr.X_op == O_big)
                        as_bad (_("16 bit expression not in range 0..65535"));
                    }
                }
@@ -7764,8 +7790,8 @@ mips_ip (str, ip)
                    max = 0x10000;
                  if ((c == '\0' && imm_expr.X_op != O_constant)
                      || ((imm_expr.X_add_number < -0x8000
-                           || imm_expr.X_add_number >= max)
-                          && imm_expr.X_op == O_constant)
+                          || imm_expr.X_add_number >= max)
+                         && imm_expr.X_op == O_constant)
                      || (more
                          && imm_expr.X_add_number < 0
                          && ISA_HAS_64BIT_REGS (mips_opts.isa)
@@ -7774,10 +7800,8 @@ mips_ip (str, ip)
                    {
                      if (more)
                        break;
-                     if (imm_expr.X_op != O_constant
-                         && imm_expr.X_op != O_big)
-                       insn_error = _("absolute expression required");
-                     else
+                     if (imm_expr.X_op == O_constant
+                         || imm_expr.X_op == O_big)
                        as_bad (_("16 bit expression not in range -32768..32767"));
                    }
                }
@@ -7804,9 +7828,8 @@ mips_ip (str, ip)
                      || offset_expr.X_add_number < -0x8000)
                  && (mips_pic != EMBEDDED_PIC
                      || offset_expr.X_op != O_subtract
-                     || now_seg != text_section
-                     || (S_GET_SEGMENT (offset_expr.X_op_symbol)
-                         != text_section)))
+                     || (S_GET_SEGMENT (offset_expr.X_add_symbol)
+                         != S_GET_SEGMENT (offset_expr.X_op_symbol))))
                break;
 
              if (c == 'h' || c == 'H')
@@ -7879,7 +7902,29 @@ mips_ip (str, ip)
                ip->insn_opcode |= regno << OP_SH_BCC;
              else
                ip->insn_opcode |= regno << OP_SH_CCC;
-              continue;
+             continue;
+
+           case 'H':
+             if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
+               s += 2;
+             if (isdigit ((unsigned char) *s))
+               {
+                 c = 0;
+                 do
+                   {
+                     c *= 10;
+                     c += *s - '0';
+                     ++s;
+                   }
+                 while (isdigit ((unsigned char) *s));
+               }
+             else
+               c = 8; /* Invalid sel value.  */
+
+             if (c > 7)
+               as_bad (_("invalid coprocessor sub-selection value (0-7)"));
+             ip->insn_opcode |= c;
+             continue;
 
            default:
              as_bad (_("bad char = '%c'\n"), *args);
@@ -8558,7 +8603,8 @@ mips16_immed (file, line, type, val, warn, small, ext, insn, use_extend,
     needext = false;
 
   if (warn && ext && ! needext)
-    as_warn_where (file, line, _("extended operand requested but not required"));
+    as_warn_where (file, line,
+                  _("extended operand requested but not required"));
   if (small && needext)
     as_bad_where (file, line, _("invalid unextended operand value"));
 
@@ -8730,8 +8776,8 @@ my_getExpression (ep, str)
 }
 
 /* Turn a string in input_line_pointer into a floating point constant
-   of type type, and store the appropriate bytes in *litP.  The number
-   of LITTLENUMS emitted is stored in *sizeP .  An error message is
+   of type TYPE, and store the appropriate bytes in *LITP.  The number
+   of LITTLENUMS emitted is stored in *SIZEP.  An error message is
    returned, or NULL on OK.  */
 
 char *
@@ -8782,7 +8828,7 @@ md_atof (type, litP, sizeP)
          litP += 2;
        }
     }
-     
+
   return NULL;
 }
 
@@ -8800,7 +8846,8 @@ md_number_to_chars (buf, val, n)
 \f
 CONST char *md_shortopts = "O::g::G:";
 
-struct option md_longopts[] = {
+struct option md_longopts[] =
+{
 #define OPTION_MIPS1 (OPTION_MD_BASE + 1)
   {"mips0", no_argument, NULL, OPTION_MIPS1},
   {"mips1", no_argument, NULL, OPTION_MIPS1},
@@ -8814,58 +8861,74 @@ struct option md_longopts[] = {
   {"mcpu", required_argument, NULL, OPTION_MCPU},
 #define OPTION_MEMBEDDED_PIC (OPTION_MD_BASE + 6)
   {"membedded-pic", no_argument, NULL, OPTION_MEMBEDDED_PIC},
-#define OPTION_TRAP (OPTION_MD_BASE + 9)
+#define OPTION_TRAP (OPTION_MD_BASE + 7)
   {"trap", no_argument, NULL, OPTION_TRAP},
   {"no-break", no_argument, NULL, OPTION_TRAP},
-#define OPTION_BREAK (OPTION_MD_BASE + 10)
+#define OPTION_BREAK (OPTION_MD_BASE + 8)
   {"break", no_argument, NULL, OPTION_BREAK},
   {"no-trap", no_argument, NULL, OPTION_BREAK},
-#define OPTION_EB (OPTION_MD_BASE + 11)
+#define OPTION_EB (OPTION_MD_BASE + 9)
   {"EB", no_argument, NULL, OPTION_EB},
-#define OPTION_EL (OPTION_MD_BASE + 12)
+#define OPTION_EL (OPTION_MD_BASE + 10)
   {"EL", no_argument, NULL, OPTION_EL},
-#define OPTION_M4650 (OPTION_MD_BASE + 13)
+#define OPTION_M4650 (OPTION_MD_BASE + 11)
   {"m4650", no_argument, NULL, OPTION_M4650},
-#define OPTION_NO_M4650 (OPTION_MD_BASE + 14)
+#define OPTION_NO_M4650 (OPTION_MD_BASE + 12)
   {"no-m4650", no_argument, NULL, OPTION_NO_M4650},
-#define OPTION_M4010 (OPTION_MD_BASE + 15)
+#define OPTION_M4010 (OPTION_MD_BASE + 13)
   {"m4010", no_argument, NULL, OPTION_M4010},
-#define OPTION_NO_M4010 (OPTION_MD_BASE + 16)
+#define OPTION_NO_M4010 (OPTION_MD_BASE + 14)
   {"no-m4010", no_argument, NULL, OPTION_NO_M4010},
-#define OPTION_M4100 (OPTION_MD_BASE + 17)
+#define OPTION_M4100 (OPTION_MD_BASE + 15)
   {"m4100", no_argument, NULL, OPTION_M4100},
-#define OPTION_NO_M4100 (OPTION_MD_BASE + 18)
+#define OPTION_NO_M4100 (OPTION_MD_BASE + 16)
   {"no-m4100", no_argument, NULL, OPTION_NO_M4100},
-#define OPTION_MIPS16 (OPTION_MD_BASE + 22)
+#define OPTION_MIPS16 (OPTION_MD_BASE + 17)
   {"mips16", no_argument, NULL, OPTION_MIPS16},
-#define OPTION_NO_MIPS16 (OPTION_MD_BASE + 23)
+#define OPTION_NO_MIPS16 (OPTION_MD_BASE + 18)
   {"no-mips16", no_argument, NULL, OPTION_NO_MIPS16},
-#define OPTION_M3900 (OPTION_MD_BASE + 26)
+#define OPTION_M3900 (OPTION_MD_BASE + 19)
   {"m3900", no_argument, NULL, OPTION_M3900},
-#define OPTION_NO_M3900 (OPTION_MD_BASE + 27)
+#define OPTION_NO_M3900 (OPTION_MD_BASE + 20)
   {"no-m3900", no_argument, NULL, OPTION_NO_M3900},
-
-
-#define OPTION_MABI (OPTION_MD_BASE + 38)
+#define OPTION_MABI (OPTION_MD_BASE + 21)
   {"mabi", required_argument, NULL, OPTION_MABI},
-
-#define OPTION_CALL_SHARED (OPTION_MD_BASE + 7)
-#define OPTION_NON_SHARED (OPTION_MD_BASE + 8)
-#define OPTION_XGOT (OPTION_MD_BASE + 19)
-#define OPTION_32 (OPTION_MD_BASE + 20)
-#define OPTION_64 (OPTION_MD_BASE + 21)
+#define OPTION_M7000_HILO_FIX (OPTION_MD_BASE + 22)
+  {"mfix7000", no_argument, NULL, OPTION_M7000_HILO_FIX},
+#define OPTION_NO_M7000_HILO_FIX (OPTION_MD_BASE + 23)
+  {"no-fix-7000", no_argument, NULL, OPTION_NO_M7000_HILO_FIX},
+#define OPTION_GP32 (OPTION_MD_BASE + 24)
+  {"mgp32", no_argument, NULL, OPTION_GP32},
+#define OPTION_GP64 (OPTION_MD_BASE + 25)
+  {"mgp64", no_argument, NULL, OPTION_GP64},
+#define OPTION_CONSTRUCT_FLOATS (OPTION_MD_BASE + 26)
+  {"construct-floats", no_argument, NULL, OPTION_CONSTRUCT_FLOATS},
+#define OPTION_NO_CONSTRUCT_FLOATS (OPTION_MD_BASE + 27)
+  {"no-construct-floats", no_argument, NULL, OPTION_NO_CONSTRUCT_FLOATS},
+#define OPTION_MIPS32 (OPTION_MD_BASE + 28)
+  {"mips32", no_argument, NULL, OPTION_MIPS32},
+#define OPTION_MIPS5 (OPTION_MD_BASE + 29)
+  {"mips5", no_argument, NULL, OPTION_MIPS5},
+#define OPTION_MIPS64 (OPTION_MD_BASE + 30)
+  {"mips64", no_argument, NULL, OPTION_MIPS64},
 #ifdef OBJ_ELF
-  {"KPIC", no_argument, NULL, OPTION_CALL_SHARED},
-  {"xgot", no_argument, NULL, OPTION_XGOT},
+#define OPTION_ELF_BASE    (OPTION_MD_BASE + 35)
+#define OPTION_CALL_SHARED (OPTION_ELF_BASE + 0)
+#define OPTION_NON_SHARED  (OPTION_ELF_BASE + 1)
+#define OPTION_XGOT        (OPTION_ELF_BASE + 2)
+#define OPTION_32         (OPTION_ELF_BASE + 3)
+#define OPTION_64          (OPTION_ELF_BASE + 4)
+  {"KPIC",        no_argument, NULL, OPTION_CALL_SHARED},
   {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
-  {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
-  {"32", no_argument, NULL, OPTION_32},
-  {"64", no_argument, NULL, OPTION_64},
+  {"non_shared",  no_argument, NULL, OPTION_NON_SHARED},
+  {"xgot",        no_argument, NULL, OPTION_XGOT},
+  {"32",          no_argument, NULL, OPTION_32},
+  {"64",          no_argument, NULL, OPTION_64},
 #endif
 
   {NULL, no_argument, NULL, 0}
 };
-size_t md_longopts_size = sizeof(md_longopts);
+size_t md_longopts_size = sizeof (md_longopts);
 
 int
 md_parse_option (c, arg)
@@ -8874,6 +8937,14 @@ md_parse_option (c, arg)
 {
   switch (c)
     {
+    case OPTION_CONSTRUCT_FLOATS:
+      mips_disable_float_construction = 0;
+      break;
+
+    case OPTION_NO_CONSTRUCT_FLOATS:
+      mips_disable_float_construction = 1;
+      break;
+
     case OPTION_TRAP:
       mips_trap = 1;
       break;
@@ -8910,164 +8981,76 @@ md_parse_option (c, arg)
       break;
 
     case OPTION_MIPS1:
-      mips_opts.isa = 1;
+      mips_opts.isa = ISA_MIPS1;
       break;
 
     case OPTION_MIPS2:
-      mips_opts.isa = 2;
+      mips_opts.isa = ISA_MIPS2;
       break;
 
     case OPTION_MIPS3:
-      mips_opts.isa = 3;
+      mips_opts.isa = ISA_MIPS3;
       break;
 
     case OPTION_MIPS4:
-      mips_opts.isa = 4;
+      mips_opts.isa = ISA_MIPS4;
+      break;
+
+    case OPTION_MIPS5:
+      mips_opts.isa = ISA_MIPS5;
+      break;
+
+    case OPTION_MIPS32:
+      mips_opts.isa = ISA_MIPS32;
+      break;
+
+    case OPTION_MIPS64:
+      mips_opts.isa = ISA_MIPS64;
       break;
 
     case OPTION_MCPU:
       {
-       char *p;
-
-       /* Identify the processor type */
-       p = arg;
-       if (strcmp (p, "default") == 0
-           || strcmp (p, "DEFAULT") == 0)
-         mips_cpu = -1;
+       /* Identify the processor type.  */
+       if (strcasecmp (arg, "default") == 0)
+         mips_cpu = CPU_UNKNOWN;
        else
          {
-           int sv = 0;
+           const struct mips_cpu_info *ci;
 
-           /* We need to cope with the various "vr" prefixes for the 4300
-              processor.  */
-           if (*p == 'v' || *p == 'V')
-             {
-               sv = 1;
-               p++;
-             }
-
-           if (*p == 'r' || *p == 'R')
-             p++;
-
-           mips_cpu = -1;
-           switch (*p)
-             {
-             case '1':
-               if (strcmp (p, "10000") == 0
-                   || strcmp (p, "10k") == 0
-                   || strcmp (p, "10K") == 0)
-                 mips_cpu = 10000;
-               break;
-
-             case '2':
-               if (strcmp (p, "2000") == 0
-                   || strcmp (p, "2k") == 0
-                   || strcmp (p, "2K") == 0)
-                 mips_cpu = 2000;
-               break;
-
-             case '3':
-               if (strcmp (p, "3000") == 0
-                   || strcmp (p, "3k") == 0
-                   || strcmp (p, "3K") == 0)
-                 mips_cpu = 3000;
-                else if (strcmp (p, "3900") == 0)
-                  mips_cpu = 3900;
-               break;
-
-             case '4':
-               if (strcmp (p, "4000") == 0
-                   || strcmp (p, "4k") == 0
-                   || strcmp (p, "4K") == 0)
-                 mips_cpu = 4000;
-               else if (strcmp (p, "4100") == 0)
-                    mips_cpu = 4100;
-               else if (strcmp (p, "4111") == 0)
-                    mips_cpu = 4111;
-               else if (strcmp (p, "4300") == 0)
-                 mips_cpu = 4300;
-               else if (strcmp (p, "4400") == 0)
-                 mips_cpu = 4400;
-               else if (strcmp (p, "4600") == 0)
-                 mips_cpu = 4600;
-               else if (strcmp (p, "4650") == 0)
-                   mips_cpu = 4650;
-               else if (strcmp (p, "4010") == 0)
-                  mips_cpu = 4010;
-               break;
-
-             case '5':
-               if (strcmp (p, "5000") == 0
-                   || strcmp (p, "5k") == 0
-                   || strcmp (p, "5K") == 0)
-                 mips_cpu = 5000;
-               break;
-
-             case '6':
-               if (strcmp (p, "6000") == 0
-                   || strcmp (p, "6k") == 0
-                   || strcmp (p, "6K") == 0)
-                 mips_cpu = 6000;
-               break;
-
-             case '8':
-               if (strcmp (p, "8000") == 0
-                   || strcmp (p, "8k") == 0
-                   || strcmp (p, "8K") == 0)
-                 mips_cpu = 8000;
-               break;
-
-             case 'o':
-               if (strcmp (p, "orion") == 0)
-                 mips_cpu = 4600;
-               break;
-             }
-
-           if (sv
-               && (mips_cpu != 4300
-                   && mips_cpu != 4100
-                   && mips_cpu != 4111
-                   && mips_cpu != 5000))
-             {
-               as_bad (_("ignoring invalid leading 'v' in -mcpu=%s switch"), arg);
-               return 0;
-             }
-
-           if (mips_cpu == -1)
-             {
-               as_bad (_("invalid architecture -mcpu=%s"), arg);
-               return 0;
-             }
+           ci = mips_cpu_info_from_name (arg);
+           if (ci == NULL || ci->is_isa)
+             as_bad (_("invalid architecture -mcpu=%s"), arg);
+           else
+             mips_cpu = ci->cpu;
          }
       }
       break;
 
     case OPTION_M4650:
-      mips_cpu = 4650;
+      mips_cpu = CPU_R4650;
       break;
 
     case OPTION_NO_M4650:
       break;
 
     case OPTION_M4010:
-      mips_cpu = 4010;
+      mips_cpu = CPU_R4010;
       break;
 
     case OPTION_NO_M4010:
       break;
 
     case OPTION_M4100:
-      mips_cpu = 4100;
+      mips_cpu = CPU_VR4100;
       break;
 
     case OPTION_NO_M4100:
       break;
 
-
     case OPTION_M3900:
-      mips_cpu = 3900;
+      mips_cpu = CPU_R3900;
       break;
-      
+
     case OPTION_NO_M3900:
       break;
 
@@ -9091,6 +9074,7 @@ md_parse_option (c, arg)
       g_switch_value = 0x7fffffff;
       break;
 
+#ifdef OBJ_ELF
       /* When generating ELF code, we permit -KPIC and -call_shared to
         select SVR4_PIC, and -non_shared to select no PIC.  This is
         intended to be compatible with Irix 5.  */
@@ -9124,6 +9108,7 @@ md_parse_option (c, arg)
     case OPTION_XGOT:
       mips_big_got = 1;
       break;
+#endif /* OBJ_ELF */
 
     case 'G':
       if (! USE_GLOBAL_POINTER_OPT)
@@ -9141,6 +9126,7 @@ md_parse_option (c, arg)
       g_switch_seen = 1;
       break;
 
+#ifdef OBJ_ELF
       /* The -32 and -64 options tell the assembler to output the 32
          bit or the 64 bit MIPS ELF format.  */
     case OPTION_32:
@@ -9162,17 +9148,51 @@ md_parse_option (c, arg)
        mips_64 = 1;
       }
       break;
+#endif /* OBJ_ELF */
+
+    case OPTION_GP32:
+      mips_gp32 = 1;
+      mips_64 = 0;
+
+      /* We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
+        flag in object files because to do so would make it
+        impossible to link with libraries compiled without "-gp32".
+        This is unnecessarily restrictive.
+
+        We could solve this problem by adding "-gp32" multilibs to
+        gcc, but to set this flag before gcc is built with such
+        multilibs will break too many systems.  */
+
+#if 0
+      mips_32bitmode = 1;
+#endif
+      break;
 
+    case OPTION_GP64:
+      mips_gp32 = 0;
+      mips_64 = 1;
+#if 0
+      mips_32bitmode = 0;
+#endif
+      break;
 
     case OPTION_MABI:
-      if (strcmp (arg,"32") == 0
-         || strcmp (arg,"n32") == 0
-         || strcmp (arg,"64") == 0
-         || strcmp (arg,"o64") == 0
-         || strcmp (arg,"eabi") == 0)
+      if (strcmp (arg, "32") == 0
+         || strcmp (arg, "n32") == 0
+         || strcmp (arg, "64") == 0
+         || strcmp (arg, "o64") == 0
+         || strcmp (arg, "eabi") == 0)
        mips_abi_string = arg;
       break;
 
+    case OPTION_M7000_HILO_FIX:
+      mips_7000_hilo_fix = true;
+      break;
+
+    case OPTION_NO_M7000_HILO_FIX:
+      mips_7000_hilo_fix = false;
+      break;
+
     default:
       return 0;
     }
@@ -9180,7 +9200,6 @@ md_parse_option (c, arg)
   return 1;
 }
 
-
 static void
 show (stream, string, col_p, first_p)
      FILE *stream;
@@ -9211,14 +9230,13 @@ show (stream, string, col_p, first_p)
   *first_p = 0;
 }
 
-
 void
 md_show_usage (stream)
      FILE *stream;
 {
   int column, first;
 
-  fprintf(stream, _("\
+  fprintf (stream, _("\
 MIPS options:\n\
 -membedded-pic         generate embedded position independent code\n\
 -EB                    generate big endian output\n\
@@ -9226,11 +9244,14 @@ MIPS options:\n\
 -g, -g2                        do not remove uneeded NOPs or swap branches\n\
 -G NUM                 allow referencing objects up to NUM bytes\n\
                        implicitly with the gp register [default 8]\n"));
-  fprintf(stream, _("\
+  fprintf (stream, _("\
 -mips1                 generate MIPS ISA I instructions\n\
 -mips2                 generate MIPS ISA II instructions\n\
 -mips3                 generate MIPS ISA III instructions\n\
 -mips4                 generate MIPS ISA IV instructions\n\
+-mips5                  generate MIPS ISA V instructions\n\
+-mips32                 generate MIPS32 ISA instructions\n\
+-mips64                 generate MIPS64 ISA instructions\n\
 -mcpu=CPU              generate code for CPU, where CPU is one of:\n"));
 
   first = 1;
@@ -9250,6 +9271,8 @@ MIPS options:\n\
   show (stream, "6000", &column, &first);
   show (stream, "8000", &column, &first);
   show (stream, "10000", &column, &first);
+  show (stream, "mips32-4k", &column, &first);
+  show (stream, "sb-1", &column, &first);
   fputc ('\n', stream);
 
   fprintf (stream, _("\
@@ -9265,16 +9288,17 @@ MIPS options:\n\
   show (stream, "4650", &column, &first);
   fputc ('\n', stream);
 
-  fprintf(stream, _("\
+  fprintf (stream, _("\
 -mips16                        generate mips16 instructions\n\
 -no-mips16             do not generate mips16 instructions\n"));
-  fprintf(stream, _("\
+  fprintf (stream, _("\
 -O0                    remove unneeded NOPs, do not swap branches\n\
 -O                     remove unneeded NOPs and swap branches\n\
+--[no-]construct-floats [dis]allow floating point values to be constructed\n\
 --trap, --no-break     trap exception on div by 0 and mult overflow\n\
 --break, --no-trap     break exception on div by 0 and mult overflow\n"));
 #ifdef OBJ_ELF
-  fprintf(stream, _("\
+  fprintf (stream, _("\
 -KPIC, -call_shared    generate SVR4 position independent code\n\
 -non_shared            do not generate position independent code\n\
 -xgot                  assume a 32 bit GOT\n\
@@ -9288,7 +9312,7 @@ mips_init_after_args ()
 {
   /* initialize opcodes */
   bfd_mips_num_opcodes = bfd_mips_num_builtin_opcodes;
-  mips_opcodes = (struct mips_opcode*) mips_builtin_opcodes;
+  mips_opcodes = (struct mips_opcode *) mips_builtin_opcodes;
 }
 
 long
@@ -9314,7 +9338,7 @@ md_pcrel_from (fixP)
 
 void
 cons_fix_new_mips (frag, where, nbytes, exp)
-     fragS *frag;
+     fragS *frag ATTRIBUTE_UNUSED;
      int where;
      unsigned int nbytes;
      expressionS *exp;
@@ -9447,6 +9471,7 @@ mips_frob_file ()
    fixup requires the special reloc.  */
 #define SWITCH_TABLE(fixp) \
   ((fixp)->fx_r_type == BFD_RELOC_32 \
+   && OUTPUT_FLAVOR != bfd_target_elf_flavour \
    && (fixp)->fx_addsy != NULL \
    && (fixp)->fx_subsy != NULL \
    && S_GET_SEGMENT ((fixp)->fx_addsy) == text_section \
@@ -9456,7 +9481,6 @@ mips_frob_file ()
    relocations, in case the linker has to relax a call.  We also need
    to keep relocations for switch table entries.  */
 
-/*ARGSUSED*/
 int
 mips_force_relocation (fixp)
      fixS *fixp;
@@ -9494,15 +9518,16 @@ md_apply_fix (fixP, valueP)
      symbol, we need to adjust the value.  */
 #ifdef OBJ_ELF
   if (fixP->fx_addsy != NULL && OUTPUT_FLAVOR == bfd_target_elf_flavour)
-    if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16 
+    {
+    if (S_GET_OTHER (fixP->fx_addsy) == STO_MIPS16
         || S_IS_WEAK (fixP->fx_addsy)
         || (symbol_used_in_reloc_p (fixP->fx_addsy)
             && (((bfd_get_section_flags (stdoutput,
-                                        S_GET_SEGMENT (fixP->fx_addsy))
-                 & SEC_LINK_ONCE) != 0)
-               || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
-                            ".gnu.linkonce",
-                            sizeof (".gnu.linkonce") - 1))))
+                                         S_GET_SEGMENT (fixP->fx_addsy))
+                  & SEC_LINK_ONCE) != 0)
+                || !strncmp (segment_name (S_GET_SEGMENT (fixP->fx_addsy)),
+                             ".gnu.linkonce",
+                             sizeof (".gnu.linkonce") - 1))))
 
       {
         value -= S_GET_VALUE (fixP->fx_addsy);
@@ -9510,12 +9535,29 @@ md_apply_fix (fixP, valueP)
           {
             /* In this case, the bfd_install_relocation routine will
                incorrectly add the symbol value back in.  We just want
-               the addend to appear in the object file.  */
+               the addend to appear in the object file.
+              FIXME: If this makes VALUE zero, we're toast.  */
             value -= S_GET_VALUE (fixP->fx_addsy);
           }
       }
-#endif
 
+      /* This code was generated using trial and error and so is
+        fragile and not trustworthy.  If you change it, you should
+        rerun the elf-rel, elf-rel2, and empic testcases and ensure
+        they still pass.  */
+      if (fixP->fx_pcrel || fixP->fx_subsy != NULL)
+       {
+         value += fixP->fx_frag->fr_address + fixP->fx_where;
+
+         /* BFD's REL handling, for MIPS, is _very_ weird.
+            This gives the right results, but it can't possibly
+            be the way things are supposed to work.  */
+         if (fixP->fx_r_type != BFD_RELOC_16_PCREL_S2
+             || S_GET_SEGMENT (fixP->fx_addsy) != undefined_section)
+           value += fixP->fx_frag->fr_address + fixP->fx_where;
+       }
+    }
+#endif
 
   fixP->fx_addnumber = value;  /* Remember value for tc_gen_reloc */
 
@@ -9553,7 +9595,12 @@ md_apply_fix (fixP, valueP)
     case BFD_RELOC_PCREL_HI16_S:
       /* The addend for this is tricky if it is internal, so we just
         do everything here rather than in bfd_install_relocation.  */
-      if ((symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
+      if (OUTPUT_FLAVOR == bfd_target_elf_flavour
+         && !fixP->fx_done
+         && value != 0)
+       break;
+      if (fixP->fx_addsy
+         && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
        {
          /* For an external symbol adjust by the address to make it
             pcrel_offset.  We use the address of the RELLO reloc
@@ -9573,7 +9620,12 @@ md_apply_fix (fixP, valueP)
     case BFD_RELOC_PCREL_LO16:
       /* The addend for this is tricky if it is internal, so we just
         do everything here rather than in bfd_install_relocation.  */
-      if ((symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
+      if (OUTPUT_FLAVOR == bfd_target_elf_flavour
+         && !fixP->fx_done
+         && value != 0)
+       break;
+      if (fixP->fx_addsy
+         && (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_SECTION_SYM) == 0)
        value += fixP->fx_frag->fr_address + fixP->fx_where;
       buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
       if (target_big_endian)
@@ -9610,6 +9662,7 @@ md_apply_fix (fixP, valueP)
        }
       break;
 
+    case BFD_RELOC_RVA:
     case BFD_RELOC_32:
       /* If we are deleting this reloc entry, we must fill in the
         value now.  This can happen if we have a .word which is not
@@ -9655,6 +9708,15 @@ md_apply_fix (fixP, valueP)
       if ((value & 0x3) != 0)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Branch to odd address (%lx)"), value);
+
+      if (!fixP->fx_done && value != 0)
+       break;
+      /* If 'value' is zero, the remaining reloc code won't actually
+        do the store, so it must be done here.  This is probably
+        a bug somewhere.  */
+      if (!fixP->fx_done)
+       value -= fixP->fx_frag->fr_address + fixP->fx_where;
+
       value >>= 2;
 
       /* update old instruction data */
@@ -9852,7 +9914,7 @@ mips_align (to, fill, label)
 
 static void
 s_align (x)
-     int x;
+     int x ATTRIBUTE_UNUSED;
 {
   register int temp;
   register long temp_fill;
@@ -9957,7 +10019,7 @@ s_change_sec (sec)
                                      | SEC_RELOC
                                      | SEC_DATA));
              if (strcmp (TARGET_OS, "elf") != 0)
-               bfd_set_section_alignment (stdoutput, seg, 4);
+               record_alignment (seg, 4);
            }
          demand_empty_rest_of_line ();
        }
@@ -9979,7 +10041,7 @@ s_change_sec (sec)
                                     SEC_ALLOC | SEC_LOAD | SEC_RELOC
                                     | SEC_DATA);
              if (strcmp (TARGET_OS, "elf") != 0)
-               bfd_set_section_alignment (stdoutput, seg, 4);
+               record_alignment (seg, 4);
            }
          demand_empty_rest_of_line ();
          break;
@@ -10046,7 +10108,7 @@ s_float_cons (type)
 
 static void
 s_mips_globl (x)
-     int x;
+     int x ATTRIBUTE_UNUSED;
 {
   char *name;
   int c;
@@ -10087,7 +10149,7 @@ s_mips_globl (x)
 
 static void
 s_option (x)
-     int x;
+     int x ATTRIBUTE_UNUSED;
 {
   char *opt;
   char c;
@@ -10140,7 +10202,7 @@ static struct mips_option_stack *mips_opts_stack;
 
 static void
 s_mipsset (x)
-     int x;
+     int x ATTRIBUTE_UNUSED;
 {
   char *name = input_line_pointer, ch;
 
@@ -10155,7 +10217,7 @@ s_mipsset (x)
        {
          /* If we still have pending nops, we can discard them.  The
             usual nop handling will insert any that are still
-            needed. */
+            needed.  */
          prev_nop_frag->fr_fix -= (prev_nop_frag_holds
                                    * (mips_opts.mips16 ? 2 : 4));
          prev_nop_frag = NULL;
@@ -10215,12 +10277,18 @@ s_mipsset (x)
       /* Permit the user to change the ISA on the fly.  Needless to
         say, misuse can cause serious problems.  */
       isa = atoi (name + 4);
-      if (isa == 0)
-       mips_opts.isa = file_mips_isa;
-      else if (isa < 1 || isa > 4)
-       as_bad (_("unknown ISA level"));
-      else
-       mips_opts.isa = isa;
+      switch (isa)
+      {
+      case  0: mips_opts.isa = file_mips_isa;   break;
+      case  1: mips_opts.isa = ISA_MIPS1;       break;
+      case  2: mips_opts.isa = ISA_MIPS2;       break;
+      case  3: mips_opts.isa = ISA_MIPS3;       break;
+      case  5: mips_opts.isa = ISA_MIPS5;       break;
+      case  4: mips_opts.isa = ISA_MIPS4;       break;
+      case 32: mips_opts.isa = ISA_MIPS32;      break;
+      case 64: mips_opts.isa = ISA_MIPS64;      break;
+      default: as_bad (_("unknown ISA level")); break;
+      }
     }
   else if (strcmp (name, "autoextend") == 0)
     mips_opts.noautoextend = 0;
@@ -10276,7 +10344,7 @@ s_mipsset (x)
 
 static void
 s_abicalls (ignore)
-     int ignore;
+     int ignore ATTRIBUTE_UNUSED;
 {
   mips_pic = SVR4_PIC;
   if (USE_GLOBAL_POINTER_OPT)
@@ -10301,7 +10369,7 @@ s_abicalls (ignore)
 
 static void
 s_cpload (ignore)
-     int ignore;
+     int ignore ATTRIBUTE_UNUSED;
 {
   expressionS ex;
   int icnt = 0;
@@ -10341,7 +10409,7 @@ s_cpload (ignore)
 
 static void
 s_cprestore (ignore)
-     int ignore;
+     int ignore ATTRIBUTE_UNUSED;
 {
   expressionS ex;
   int icnt = 0;
@@ -10374,7 +10442,7 @@ s_cprestore (ignore)
 
 static void
 s_gpword (ignore)
-     int ignore;
+     int ignore ATTRIBUTE_UNUSED;
 {
   symbolS *label;
   expressionS ex;
@@ -10414,7 +10482,7 @@ s_gpword (ignore)
 
 static void
 s_cpadd (ignore)
-     int ignore;
+     int ignore ATTRIBUTE_UNUSED;
 {
   int icnt = 0;
   int reg;
@@ -10434,7 +10502,7 @@ s_cpadd (ignore)
                ? "addu" : "daddu"),
               "d,v,t", reg, reg, GP);
 
-  demand_empty_rest_of_line ();  
+  demand_empty_rest_of_line ();
 }
 
 /* Handle the .insn pseudo-op.  This marks instruction labels in
@@ -10448,7 +10516,7 @@ s_cpadd (ignore)
 
 static void
 s_insn (ignore)
-     int ignore;
+     int ignore ATTRIBUTE_UNUSED;
 {
   if (mips_opts.mips16)
     mips16_mark_labels ();
@@ -10477,7 +10545,7 @@ s_mips_stab (type)
 
 static void
 s_mips_weakext (ignore)
-     int ignore;
+     int ignore ATTRIBUTE_UNUSED;
 {
   char *name;
   int c;
@@ -10501,13 +10569,13 @@ s_mips_weakext (ignore)
          ignore_rest_of_line ();
          return;
        }
-      
+
       if (*input_line_pointer == ',')
        {
          ++input_line_pointer;
          SKIP_WHITESPACE ();
        }
-      
+
       expression (&exp);
       if (exp.X_op != O_symbol)
        {
@@ -10812,7 +10880,7 @@ mips16_extended_frag (fragp, sec, stretch)
 
          /* If we are currently assuming that this frag should be
             extended, then, the current address is two bytes
-            higher. */
+            higher.  */
          if (RELAX_MIPS16_EXTENDED (fragp->fr_subtype))
            addr += 2;
 
@@ -10881,13 +10949,13 @@ mips16_extended_frag (fragp, sec, stretch)
    encoded in the subtype information.  For the mips16, we have to
    decide whether we are using an extended opcode or not.  */
 
-/*ARGSUSED*/
 int
 md_estimate_size_before_relax (fragp, segtype)
      fragS *fragp;
      asection *segtype;
 {
-  int change;
+  int change = 0;
+  boolean linkonce = false;
 
   if (RELAX_MIPS16_P (fragp->fr_subtype))
     {
@@ -10930,10 +10998,31 @@ md_estimate_size_before_relax (fragp, segtype)
 
       symsec = S_GET_SEGMENT (sym);
 
+      /* duplicate the test for LINK_ONCE sections as in adjust_reloc_syms */
+      if (symsec != segtype && ! S_IS_LOCAL (sym))
+       {
+         if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
+             != 0)
+           linkonce = true;
+
+         /* The GNU toolchain uses an extension for ELF: a section
+            beginning with the magic string .gnu.linkonce is a linkonce
+            section.  */
+         if (strncmp (segment_name (symsec), ".gnu.linkonce",
+                      sizeof ".gnu.linkonce" - 1) == 0)
+           linkonce = true;
+       }
+
       /* This must duplicate the test in adjust_reloc_syms.  */
       change = (symsec != &bfd_und_section
                && symsec != &bfd_abs_section
-               && ! bfd_is_com_section (symsec));
+               && ! bfd_is_com_section (symsec)
+               && !linkonce
+#ifdef OBJ_ELF
+               /* A weak symbol is treated as external.  */
+               && ! S_IS_WEAK (sym)
+#endif
+               );
     }
   else
     abort ();
@@ -10990,7 +11079,7 @@ mips_fix_adjustable (fixp)
 
 arelent **
 tc_gen_reloc (section, fixp)
-     asection *section;
+     asection *section ATTRIBUTE_UNUSED;
      fixS *fixp;
 {
   static arelent *retval[4];
@@ -11015,6 +11104,8 @@ tc_gen_reloc (section, fixp)
        as_fatal (_("Double check fx_r_type in tc-mips.c:tc_gen_reloc"));
       fixp->fx_r_type = BFD_RELOC_GPREL32;
     }
+  else if (fixp->fx_pcrel == 0 || OUTPUT_FLAVOR == bfd_target_elf_flavour)
+    reloc->addend = fixp->fx_addnumber;
   else if (fixp->fx_r_type == BFD_RELOC_PCREL_LO16)
     {
       /* We use a special addend for an internal RELLO reloc.  */
@@ -11039,8 +11130,6 @@ tc_gen_reloc (section, fixp)
                         + fixp->fx_next->fx_frag->fr_address
                         + fixp->fx_next->fx_where);
     }
-  else if (fixp->fx_pcrel == 0)
-    reloc->addend = fixp->fx_addnumber;
   else
     {
       if (OUTPUT_FLAVOR != bfd_target_aout_flavour)
@@ -11179,7 +11268,8 @@ tc_gen_reloc (section, fixp)
   /* To support a PC relative reloc when generating embedded PIC code
      for ECOFF, we use a Cygnus extension.  We check for that here to
      make sure that we don't let such a reloc escape normally.  */
-  if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
+  if ((OUTPUT_FLAVOR == bfd_target_ecoff_flavour
+       || OUTPUT_FLAVOR == bfd_target_elf_flavour)
       && code == BFD_RELOC_16_PCREL_S2
       && mips_pic != EMBEDDED_PIC)
     reloc->howto = NULL;
@@ -11230,7 +11320,7 @@ mips_relax_frag (fragp, stretch)
 
 void
 md_convert_frag (abfd, asec, fragp)
-     bfd *abfd;
+     bfd *abfd ATTRIBUTE_UNUSED;
      segT asec;
      fragS *fragp;
 {
@@ -11264,7 +11354,7 @@ md_convert_frag (abfd, asec, fragp)
          ext = false;
        }
 
-      resolve_symbol_value (fragp->fr_symbol, 1);
+      resolve_symbol_value (fragp->fr_symbol, finalize_syms);
       val = S_GET_VALUE (fragp->fr_symbol);
       if (op->pcrel)
        {
@@ -11445,14 +11535,14 @@ mips_elf_final_processing ()
   if (mips_pic != NO_PIC)
     elf_elfheader (stdoutput)->e_flags |= EF_MIPS_PIC;
 
-  /* Set the MIPS ELF ABI flags. */
+  /* Set the MIPS ELF ABI flags.  */
   if (mips_abi_string == 0)
     ;
-  else if (strcmp (mips_abi_string,"32") == 0)
+  else if (strcmp (mips_abi_string, "32") == 0)
     elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O32;
-  else if (strcmp (mips_abi_string,"o64") == 0)
+  else if (strcmp (mips_abi_string, "o64") == 0)
     elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_O64;
-  else if (strcmp (mips_abi_string,"eabi") == 0)
+  else if (strcmp (mips_abi_string, "eabi") == 0)
     {
       if (mips_eabi64)
        elf_elfheader (stdoutput)->e_flags |= E_MIPS_ABI_EABI64;
@@ -11466,23 +11556,54 @@ mips_elf_final_processing ()
 
 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */
 \f
-typedef struct proc
-  {
-    symbolS *isym;
-    unsigned long reg_mask;
-    unsigned long reg_offset;
-    unsigned long fpreg_mask;
-    unsigned long fpreg_offset;
-    unsigned long frame_offset;
-    unsigned long frame_reg;
-    unsigned long pc_reg;
-  }
-procS;
+typedef struct proc {
+  symbolS *isym;
+  unsigned long reg_mask;
+  unsigned long reg_offset;
+  unsigned long fpreg_mask;
+  unsigned long fpreg_offset;
+  unsigned long frame_offset;
+  unsigned long frame_reg;
+  unsigned long pc_reg;
+} procS;
 
 static procS cur_proc;
 static procS *cur_proc_ptr;
 static int numprocs;
 
+/* Fill in an rs_align_code fragment.  */
+
+void
+mips_handle_align (fragp)
+     fragS *fragp;
+{
+  if (fragp->fr_type != rs_align_code)
+    return;
+
+  if (mips_opts.mips16)
+    {
+      static const unsigned char be_nop[] = { 0x65, 0x00 };
+      static const unsigned char le_nop[] = { 0x00, 0x65 };
+
+      int bytes;
+      char *p;
+
+      bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
+      p = fragp->fr_literal + fragp->fr_fix;
+
+      if (bytes & 1)
+       {
+         *p++ = 0;
+         fragp->fr_fix += 1;
+       }
+
+      memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
+      fragp->fr_var = 2;
+    }
+
+  /* For mips32, a nop is a zero, which we trivially get by doing nothing.  */
+}
+
 static void
 md_obj_begin ()
 {
@@ -11552,7 +11673,7 @@ get_number ()
 
 static void
 s_file (x)
-     int x;
+     int x ATTRIBUTE_UNUSED;
 {
   int line;
 
@@ -11560,12 +11681,11 @@ s_file (x)
   s_app_file (0);
 }
 
-
 /* The .end directive.  */
 
 static void
 s_mips_end (x)
-     int x;
+     int x ATTRIBUTE_UNUSED;
 {
   symbolS *p;
   int maybe_text;
@@ -11628,21 +11748,21 @@ s_mips_end (x)
     assert (pdr_seg);
     subseg_set (pdr_seg, 0);
 
-    /* Write the symbol */
+    /* Write the symbol */
     exp.X_op = O_symbol;
     exp.X_add_symbol = p;
     exp.X_add_number = 0;
     emit_expr (&exp, 4);
 
-    fragp = frag_more (7*4);
+    fragp = frag_more (7 * 4);
 
-    md_number_to_chars (fragp,     (valueT) cur_proc_ptr->reg_mask, 4);
-    md_number_to_chars (fragp + 4, (valueT) cur_proc_ptr->reg_offset, 4);
-    md_number_to_chars (fragp + 8, (valueT) cur_proc_ptr->fpreg_mask, 4);
-    md_number_to_chars (fragp +12, (valueT) cur_proc_ptr->fpreg_offset, 4);
-    md_number_to_chars (fragp +16, (valueT) cur_proc_ptr->frame_offset, 4);
-    md_number_to_chars (fragp +20, (valueT) cur_proc_ptr->frame_reg, 4);
-    md_number_to_chars (fragp +24, (valueT) cur_proc_ptr->pc_reg, 4);
+    md_number_to_chars (fragp,      (valueT) cur_proc_ptr->reg_mask, 4);
+    md_number_to_chars (fragp +  4, (valueT) cur_proc_ptr->reg_offset, 4);
+    md_number_to_chars (fragp +  8, (valueT) cur_proc_ptr->fpreg_mask, 4);
+    md_number_to_chars (fragp + 12, (valueT) cur_proc_ptr->fpreg_offset, 4);
+    md_number_to_chars (fragp + 16, (valueT) cur_proc_ptr->frame_offset, 4);
+    md_number_to_chars (fragp + 20, (valueT) cur_proc_ptr->frame_reg, 4);
+    md_number_to_chars (fragp + 24, (valueT) cur_proc_ptr->pc_reg, 4);
 
     subseg_set (saved_seg, saved_subseg);
   }
@@ -11703,9 +11823,9 @@ s_mips_ent (aent)
 }
 
 /* The .frame directive. If the mdebug section is present (IRIX 5 native)
-   then ecoff.c (ecoff_directive_frame) is used. For embedded targets, 
+   then ecoff.c (ecoff_directive_frame) is used. For embedded targets,
    s_mips_frame is used so that we can set the PDR information correctly.
-   We can't use the ecoff routines because they make reference to the ecoff 
+   We can't use the ecoff routines because they make reference to the ecoff
    symbol table (in the mdebug section).  */
 
 static void
@@ -11716,7 +11836,7 @@ s_mips_frame (ignore)
 
   long val;
 
-  if (cur_proc_ptr ==  (procS *) NULL)
+  if (cur_proc_ptr == (procS *) NULL)
     {
       as_warn (_(".frame outside of .ent"));
       demand_empty_rest_of_line ();
@@ -11744,10 +11864,10 @@ s_mips_frame (ignore)
 #endif /* MIPS_STABS_ELF */
 }
 
-/* The .fmask and .mask directives. If the mdebug section is present 
-   (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For 
+/* The .fmask and .mask directives. If the mdebug section is present
+   (IRIX 5 native) then ecoff.c (ecoff_directive_mask) is used. For
    embedded targets, s_mips_mask is used so that we can set the PDR
-   information correctly. We can't use the ecoff routines because they 
+   information correctly. We can't use the ecoff routines because they
    make reference to the ecoff symbol table (in the mdebug section).  */
 
 static void
@@ -11756,7 +11876,7 @@ s_mips_mask (reg_type)
 {
 #ifdef MIPS_STABS_ELF
   long mask, off;
-  
+
   if (cur_proc_ptr == (procS *) NULL)
     {
       as_warn (_(".mask/.fmask outside of .ent"));
@@ -11815,5 +11935,195 @@ s_loc (x)
 }
 #endif
 
+/* CPU name/ISA/number mapping table.
+
+   Entries are grouped by type.  The first matching CPU or ISA entry
+   gets chosen by CPU or ISA, so it should be the 'canonical' name
+   for that type.  Entries after that within the type are sorted
+   alphabetically.
+
+   Case is ignored in comparison, so put the canonical entry in the
+   appropriate case but everything else in lower case to ease eye pain.  */
+static const struct mips_cpu_info mips_cpu_info_table[] =
+{
+  /* MIPS1 ISA */
+  { "MIPS1",          1,      ISA_MIPS1,      CPU_R3000, },
+  { "mips",           1,      ISA_MIPS1,      CPU_R3000, },
+
+  /* MIPS2 ISA */
+  { "MIPS2",          1,      ISA_MIPS2,      CPU_R6000, },
+
+  /* MIPS3 ISA */
+  { "MIPS3",          1,      ISA_MIPS3,      CPU_R4000, },
+
+  /* MIPS4 ISA */
+  { "MIPS4",          1,      ISA_MIPS4,      CPU_R8000, },
+
+  /* MIPS5 ISA */
+  { "MIPS5",          1,      ISA_MIPS5,      CPU_MIPS5, },
+  { "Generic-MIPS5",  0,      ISA_MIPS5,      CPU_MIPS5, },
+
+  /* MIPS32 ISA */
+  { "MIPS32",         1,      ISA_MIPS32,     CPU_MIPS32, },
+  { "Generic-MIPS32", 0,      ISA_MIPS32,     CPU_MIPS32, },
+
+#if 1
+  /* XXX for now, MIPS64 -> MIPS3 because of history */
+  { "MIPS64",         1,      ISA_MIPS3,      CPU_R4000 }, /* XXX! */
+#else
+  /* MIPS64 ISA */
+  { "MIPS64",         1,      ISA_MIPS64,     CPU_MIPS64 },
+#endif
+  { "mips64isa",      1,      ISA_MIPS64,     CPU_MIPS64 },
+  { "Generic-MIPS64", 0,      ISA_MIPS64,     CPU_MIPS64, },
+
+  /* R2000 CPU */
+  { "R2000",          0,      ISA_MIPS1,      CPU_R2000, },
+  { "2000",           0,      ISA_MIPS1,      CPU_R2000, },
+  { "2k",             0,      ISA_MIPS1,      CPU_R2000, },
+  { "r2k",            0,      ISA_MIPS1,      CPU_R2000, },
+
+  /* R3000 CPU */
+  { "R3000",          0,      ISA_MIPS1,      CPU_R3000, },
+  { "3000",           0,      ISA_MIPS1,      CPU_R3000, },
+  { "3k",             0,      ISA_MIPS1,      CPU_R3000, },
+  { "r3k",            0,      ISA_MIPS1,      CPU_R3000, },
+
+  /* TX3900 CPU */
+  { "R3900",          0,      ISA_MIPS1,      CPU_R3900, },
+  { "3900",           0,      ISA_MIPS1,      CPU_R3900, },
+  { "mipstx39",       0,      ISA_MIPS1,      CPU_R3900, },
+
+  /* R4000 CPU */
+  { "R4000",          0,      ISA_MIPS3,      CPU_R4000, },
+  { "4000",           0,      ISA_MIPS3,      CPU_R4000, },
+  { "4k",             0,      ISA_MIPS3,      CPU_R4000, },   /* beware */
+  { "r4k",            0,      ISA_MIPS3,      CPU_R4000, },
+
+  /* R4010 CPU */
+  { "R4010",          0,      ISA_MIPS2,      CPU_R4010, },
+  { "4010",           0,      ISA_MIPS2,      CPU_R4010, },
+
+  /* R4400 CPU */
+  { "R4400",          0,      ISA_MIPS3,      CPU_R4400, },
+  { "4400",           0,      ISA_MIPS3,      CPU_R4400, },
+
+  /* R4600 CPU */
+  { "R4600",          0,      ISA_MIPS3,      CPU_R4600, },
+  { "4600",           0,      ISA_MIPS3,      CPU_R4600, },
+  { "mips64orion",    0,      ISA_MIPS3,      CPU_R4600, },
+  { "orion",          0,      ISA_MIPS3,      CPU_R4600, },
+
+  /* R4650 CPU */
+  { "R4650",          0,      ISA_MIPS3,      CPU_R4650, },
+  { "4650",           0,      ISA_MIPS3,      CPU_R4650, },
+
+  /* R6000 CPU */
+  { "R6000",          0,      ISA_MIPS2,      CPU_R6000, },
+  { "6000",           0,      ISA_MIPS2,      CPU_R6000, },
+  { "6k",             0,      ISA_MIPS2,      CPU_R6000, },
+  { "r6k",            0,      ISA_MIPS2,      CPU_R6000, },
+
+  /* R8000 CPU */
+  { "R8000",          0,      ISA_MIPS4,      CPU_R8000, },
+  { "8000",           0,      ISA_MIPS4,      CPU_R8000, },
+  { "8k",             0,      ISA_MIPS4,      CPU_R8000, },
+  { "r8k",            0,      ISA_MIPS4,      CPU_R8000, },
+
+  /* R10000 CPU */
+  { "R10000",         0,      ISA_MIPS4,      CPU_R10000, },
+  { "10000",          0,      ISA_MIPS4,      CPU_R10000, },
+  { "10k",            0,      ISA_MIPS4,      CPU_R10000, },
+  { "r10k",           0,      ISA_MIPS4,      CPU_R10000, },
+
+  /* VR4100 CPU */
+  { "VR4100",         0,      ISA_MIPS3,      CPU_VR4100, },
+  { "4100",           0,      ISA_MIPS3,      CPU_VR4100, },
+  { "mips64vr4100",   0,      ISA_MIPS3,      CPU_VR4100, },
+  { "r4100",          0,      ISA_MIPS3,      CPU_VR4100, },
+
+  /* VR4111 CPU */
+  { "VR4111",         0,      ISA_MIPS3,      CPU_R4111, },
+  { "4111",           0,      ISA_MIPS3,      CPU_R4111, },
+  { "mips64vr4111",   0,      ISA_MIPS3,      CPU_R4111, },
+  { "r4111",          0,      ISA_MIPS3,      CPU_R4111, },
+
+  /* VR4300 CPU */
+  { "VR4300",         0,      ISA_MIPS3,      CPU_R4300, },
+  { "4300",           0,      ISA_MIPS3,      CPU_R4300, },
+  { "mips64vr4300",   0,      ISA_MIPS3,      CPU_R4300, },
+  { "r4300",          0,      ISA_MIPS3,      CPU_R4300, },
+
+  /* VR5000 CPU */
+  { "VR5000",         0,      ISA_MIPS4,      CPU_R5000, },
+  { "5000",           0,      ISA_MIPS4,      CPU_R5000, },
+  { "5k",             0,      ISA_MIPS4,      CPU_R5000, },
+  { "mips64vr5000",   0,      ISA_MIPS4,      CPU_R5000, },
+  { "r5000",          0,      ISA_MIPS4,      CPU_R5000, },
+  { "r5200",          0,      ISA_MIPS4,      CPU_R5000, },
+  { "r5230",          0,      ISA_MIPS4,      CPU_R5000, },
+  { "r5231",          0,      ISA_MIPS4,      CPU_R5000, },
+  { "r5261",          0,      ISA_MIPS4,      CPU_R5000, },
+  { "r5721",          0,      ISA_MIPS4,      CPU_R5000, },
+  { "r5k",            0,      ISA_MIPS4,      CPU_R5000, },
+  { "r7000",          0,      ISA_MIPS4,      CPU_R5000, },
+
+  /* MIPS32 4K CPU */
+  { "MIPS32-4K",      0,      ISA_MIPS32,     CPU_MIPS32_4K, },
+  { "4kc",            0,      ISA_MIPS32,     CPU_MIPS32_4K, },
+  { "4km",            0,      ISA_MIPS32,     CPU_MIPS32_4K, },
+  { "4kp",            0,      ISA_MIPS32,     CPU_MIPS32_4K, },
+  { "mips32-4kc",     0,      ISA_MIPS32,     CPU_MIPS32_4K, },
+  { "mips32-4km",     0,      ISA_MIPS32,     CPU_MIPS32_4K, },
+  { "mips32-4kp",     0,      ISA_MIPS32,     CPU_MIPS32_4K, },
+
+  /* SiByte SB-1 CPU */
+  { "SB-1",           0,      ISA_MIPS64,     CPU_SB1, },
+  { "sb-1250",        0,      ISA_MIPS64,     CPU_SB1, },
+  { "sb1",            0,      ISA_MIPS64,     CPU_SB1, },
+  { "sb1250",         0,      ISA_MIPS64,     CPU_SB1, },
+
+  /* End marker.  */
+  { NULL, 0, 0, 0, },
+};
+
+static const struct mips_cpu_info *
+mips_cpu_info_from_name (name)
+     const char *name;
+{
+  int i;
+
+  for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
+    if (strcasecmp (name, mips_cpu_info_table[i].name) == 0)
+      return (&mips_cpu_info_table[i]);
+
+  return NULL;
+}
+
+static const struct mips_cpu_info *
+mips_cpu_info_from_isa (isa)
+     int isa;
+{
+  int i;
+
+  for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
+    if (mips_cpu_info_table[i].is_isa
+      && isa == mips_cpu_info_table[i].isa)
+      return (&mips_cpu_info_table[i]);
+
+  return NULL;
+}
 
-  
+static const struct mips_cpu_info *
+mips_cpu_info_from_cpu (cpu)
+     int cpu;
+{
+  int i;
+
+  for (i = 0; mips_cpu_info_table[i].name != NULL; i++)
+    if (!mips_cpu_info_table[i].is_isa
+      && cpu == mips_cpu_info_table[i].cpu)
+      return (&mips_cpu_info_table[i]);
+
+  return NULL;
+}
This page took 0.092235 seconds and 4 git commands to generate.