]> oss.titaniummirror.com Git - msp430-binutils.git/blobdiff - gas/config/tc-mmix.c
Imported binutils-2.20
[msp430-binutils.git] / gas / config / tc-mmix.c
index b3b04586ff291ac6f0d0d530059396938e7c6521..245acefc8745406e494dda10d4d4ff851c59dedb 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation.
 
    This file is part of GAS, the GNU Assembler.
    Free Software Foundation.
 
    This file is part of GAS, the GNU Assembler.
@@ -1365,6 +1365,9 @@ md_assemble (char *str)
             pass expressions as symbols and use fix_new, not fix_new_exp.  */
          sym = make_expr_symbol (exp + 1);
 
             pass expressions as symbols and use fix_new, not fix_new_exp.  */
          sym = make_expr_symbol (exp + 1);
 
+         /* Mark the symbol as being OK for a reloc.  */
+         symbol_get_bfdsym (sym)->flags |= BSF_KEEP;
+
          /* Now we know it can be a "base address plus offset".  Add
             proper fixup types so we can handle this later, when we've
             parsed everything.  */
          /* Now we know it can be a "base address plus offset".  Add
             proper fixup types so we can handle this later, when we've
             parsed everything.  */
@@ -1670,7 +1673,10 @@ md_assemble (char *str)
       break;
 
     case mmix_operands_xyz_opt:
       break;
 
     case mmix_operands_xyz_opt:
-      /* SWYM, TRIP, TRAP: zero, one, two or three operands.  */
+      /* SWYM, TRIP, TRAP: zero, one, two or three operands.  It's
+        unspecified whether operands are registers or constants, but
+        when we find register syntax, we require operands to be literal and
+        within 0..255.  */
       if (n_operands == 0 && ! mmix_gnu_syntax)
        /* Zeros are in place - nothing needs to be done for zero
           operands.  We don't allow this in GNU syntax mode, because it
       if (n_operands == 0 && ! mmix_gnu_syntax)
        /* Zeros are in place - nothing needs to be done for zero
           operands.  We don't allow this in GNU syntax mode, because it
@@ -1681,7 +1687,7 @@ md_assemble (char *str)
        {
          if (exp[0].X_op == O_constant)
            {
        {
          if (exp[0].X_op == O_constant)
            {
-             if (exp[0].X_add_number > 255*255*255
+             if (exp[0].X_add_number > 255*256*256
                  || exp[0].X_add_number < 0)
                {
                  as_bad (_("invalid operands to opcode %s: `%s'"),
                  || exp[0].X_add_number < 0)
                {
                  as_bad (_("invalid operands to opcode %s: `%s'"),
@@ -1723,7 +1729,7 @@ md_assemble (char *str)
 
          if (exp[1].X_op == O_constant)
            {
 
          if (exp[1].X_op == O_constant)
            {
-             if (exp[1].X_add_number > 255*255
+             if (exp[1].X_add_number > 255*256
                  || exp[1].X_add_number < 0)
                {
                  as_bad (_("invalid operands to opcode %s: `%s'"),
                  || exp[1].X_add_number < 0)
                {
                  as_bad (_("invalid operands to opcode %s: `%s'"),
@@ -1795,12 +1801,15 @@ md_assemble (char *str)
            fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
                         1, exp + 2, 0, BFD_RELOC_8);
        }
            fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
                         1, exp + 2, 0, BFD_RELOC_8);
        }
-      else if (n_operands <= 3
-              && (strcmp (instruction->name, "trip") == 0
-                  || strcmp (instruction->name, "trap") == 0))
+      else
        {
        {
-         /* The meaning of operands to TRIP and TRAP are not defined, so
-            we add combinations not handled above here as we find them.  */
+         /* We can't get here for other cases.  */
+         gas_assert (n_operands <= 3);
+
+         /* The meaning of operands to TRIP and TRAP is not defined (and
+            SWYM operands aren't enforced in mmixal, so let's avoid
+            that).  We add combinations not handled above here as we find
+            them and as they're reported.  */
          if (n_operands == 3)
            {
              /* Don't require non-register operands.  Always generate
          if (n_operands == 3)
            {
              /* Don't require non-register operands.  Always generate
@@ -1808,49 +1817,48 @@ md_assemble (char *str)
                 maintenance problems.  TRIP is supposed to be a rare
                 instruction, so the overhead should not matter.  We
                 aren't allowed to fix_new_exp for an expression which is
                 maintenance problems.  TRIP is supposed to be a rare
                 instruction, so the overhead should not matter.  We
                 aren't allowed to fix_new_exp for an expression which is
-                an  O_register at this point, however.  */
+                an O_register at this point, however.
+
+                Don't use BFD_RELOC_MMIX_REG_OR_BYTE as that modifies
+                the insn for a register in the Z field and we want
+                consistency.  */
              if (exp[0].X_op == O_register)
                opcodep[1] = exp[0].X_add_number;
              else
                fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
              if (exp[0].X_op == O_register)
                opcodep[1] = exp[0].X_add_number;
              else
                fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
-                            1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+                            1, exp, 0, BFD_RELOC_8);
              if (exp[1].X_op == O_register)
                opcodep[2] = exp[1].X_add_number;
              else
                fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
              if (exp[1].X_op == O_register)
                opcodep[2] = exp[1].X_add_number;
              else
                fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
-                            1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+                            1, exp + 1, 0, BFD_RELOC_8);
              if (exp[2].X_op == O_register)
                opcodep[3] = exp[2].X_add_number;
              else
                fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
              if (exp[2].X_op == O_register)
                opcodep[3] = exp[2].X_add_number;
              else
                fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
-                            1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+                            1, exp + 2, 0, BFD_RELOC_8);
            }
          else if (n_operands == 2)
            {
              if (exp[0].X_op == O_register)
            }
          else if (n_operands == 2)
            {
              if (exp[0].X_op == O_register)
-               opcodep[2] = exp[0].X_add_number;
+               opcodep[1] = exp[0].X_add_number;
              else
              else
-               fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
-                            1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+               fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
+                            1, exp, 0, BFD_RELOC_8);
              if (exp[1].X_op == O_register)
                opcodep[3] = exp[1].X_add_number;
              else
              if (exp[1].X_op == O_register)
                opcodep[3] = exp[1].X_add_number;
              else
-               fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
-                            1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
+               fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
+                            2, exp + 1, 0, BFD_RELOC_16);
            }
          else
            {
            }
          else
            {
-             as_bad (_("unsupported operands to %s: `%s'"),
-                     instruction->name, operands);
-             return;
+             /* We can't get here for other cases.  */
+             gas_assert (n_operands == 1 && exp[0].X_op == O_register);
+
+             opcodep[3] = exp[0].X_add_number;
            }
        }
            }
        }
-      else
-       {
-         as_bad (_("invalid operands to opcode %s: `%s'"),
-                 instruction->name, operands);
-         return;
-       }
       break;
 
     case mmix_operands_resume:
       break;
 
     case mmix_operands_resume:
@@ -2239,42 +2247,14 @@ md_estimate_size_before_relax (fragS *fragP, segT segment)
 char *
 md_atof (int type, char *litP, int *sizeP)
 {
 char *
 md_atof (int type, char *litP, int *sizeP)
 {
-  int prec;
-  LITTLENUM_TYPE words[4];
-  char *t;
-  int i;
-
-  switch (type)
-    {
-      /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
-        problematic to also have a forward reference in an expression.
-        The testsuite wants it, and it's customary.
-        We'll deal with the real problems when they come; we share the
-        problem with most other ports.  */
-    case 'f':
-    case 'r':
-      prec = 2;
-      break;
-    case 'd':
-      prec = 4;
-      break;
-    default:
-      *sizeP = 0;
-      return _("bad call to md_atof");
-    }
-
-  t = atof_ieee (input_line_pointer, type, words);
-  if (t)
-    input_line_pointer = t;
-
-  *sizeP = prec * 2;
-
-  for (i = 0; i < prec; i++)
-    {
-      md_number_to_chars (litP, (valueT) words[i], 2);
-      litP += 2;
-    }
-  return NULL;
+  if (type == 'r')
+    type = 'f';
+  /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
+     problematic to also have a forward reference in an expression.
+     The testsuite wants it, and it's customary.
+     We'll deal with the real problems when they come; we share the
+     problem with most other ports.  */
+  return ieee_md_atof (type, litP, sizeP, TRUE);
 }
 
 /* Convert variable-sized frags into one or more fixups.  */
 }
 
 /* Convert variable-sized frags into one or more fixups.  */
@@ -2867,7 +2847,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
     }
 
   relP = (arelent *) xmalloc (sizeof (arelent));
     }
 
   relP = (arelent *) xmalloc (sizeof (arelent));
-  assert (relP != 0);
+  gas_assert (relP != 0);
   relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
   *relP->sym_ptr_ptr = baddsy;
   relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
   relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
   *relP->sym_ptr_ptr = baddsy;
   relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
@@ -3476,6 +3456,7 @@ mmix_md_end (void)
 {
   fragS *fragP;
   symbolS *mainsym;
 {
   fragS *fragP;
   symbolS *mainsym;
+  asection *regsec;
   int i;
 
   /* The first frag of GREG:s going into the register contents section.  */
   int i;
 
   /* The first frag of GREG:s going into the register contents section.  */
@@ -3540,9 +3521,9 @@ mmix_md_end (void)
         and the same allocation order (within a file) as mmixal.  */
       segT this_segment = now_seg;
       subsegT this_subsegment = now_subseg;
         and the same allocation order (within a file) as mmixal.  */
       segT this_segment = now_seg;
       subsegT this_subsegment = now_subseg;
-      asection *regsec
-       = bfd_make_section_old_way (stdoutput,
-                                   MMIX_REG_CONTENTS_SECTION_NAME);
+
+      regsec = bfd_make_section_old_way (stdoutput,
+                                        MMIX_REG_CONTENTS_SECTION_NAME);
       subseg_set (regsec, 0);
 
       /* Finally emit the initialization-value.  Emit a variable frag, which
       subseg_set (regsec, 0);
 
       /* Finally emit the initialization-value.  Emit a variable frag, which
@@ -3569,6 +3550,11 @@ mmix_md_end (void)
       subseg_set (this_segment, this_subsegment);
     }
 
       subseg_set (this_segment, this_subsegment);
     }
 
+  regsec = bfd_get_section_by_name (stdoutput, MMIX_REG_CONTENTS_SECTION_NAME);
+  /* Mark the section symbol as being OK for a reloc.  */
+  if (regsec != NULL)
+    regsec->symbol->flags |= BSF_KEEP;
+
   /* Iterate over frags resulting from GREGs and move those that evidently
      have the same value together and point one to another.
 
   /* Iterate over frags resulting from GREGs and move those that evidently
      have the same value together and point one to another.
 
@@ -3919,7 +3905,9 @@ s_loc (int ignore ATTRIBUTE_UNUSED)
 
       if (exp.X_add_number < ((offsetT) 0x20 << 56))
        {
 
       if (exp.X_add_number < ((offsetT) 0x20 << 56))
        {
-         /* Lower than Data_Segment - assume it's .text.  */
+         /* Lower than Data_Segment or in the reserved area (the
+            segment number is >= 0x80, appearing negative) - assume
+            it's .text.  */
          section = text_section;
 
          /* Save the lowest seen location, so we can pass on this
          section = text_section;
 
          /* Save the lowest seen location, so we can pass on this
@@ -3931,8 +3919,8 @@ s_loc (int ignore ATTRIBUTE_UNUSED)
             this one), we org at (this - lower).  There's an implicit
             "LOC 0" before any entered code.  FIXME: handled by spurious
             settings of text_has_contents.  */
             this one), we org at (this - lower).  There's an implicit
             "LOC 0" before any entered code.  FIXME: handled by spurious
             settings of text_has_contents.  */
-         if (exp.X_add_number < 0
-             || exp.X_add_number < (offsetT) lowest_text_loc)
+         if (lowest_text_loc != (bfd_vma) -1
+             && (bfd_vma) exp.X_add_number < lowest_text_loc)
            {
              as_bad (_("LOC expression stepping backwards is not supported"));
              exp.X_op = O_absent;
            {
              as_bad (_("LOC expression stepping backwards is not supported"));
              exp.X_op = O_absent;
@@ -3955,7 +3943,8 @@ s_loc (int ignore ATTRIBUTE_UNUSED)
        }
       else
        {
        }
       else
        {
-         /* Do the same for the .data section.  */
+         /* Do the same for the .data section, except we don't have
+            to worry about exp.X_add_number carrying a sign.  */
          section = data_section;
 
          if (exp.X_add_number < (offsetT) lowest_data_loc)
          section = data_section;
 
          if (exp.X_add_number < (offsetT) lowest_data_loc)