* Removed sy_forward and replaced it with an undefined expression
[binutils-gdb.git] / gas / read.c
index 2b450a6feb5f57293c876566e3d29eab3b251b63..2a5dabee9eaf271be77d3135d8e2774f0f3cd26c 100644 (file)
@@ -27,6 +27,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
 #define MASK_CHAR ((int)(unsigned char)-1)
 #endif
 
+
 /* This is the largest known floating point format (for now). It will
    grow when we do 4361 style flonums. */
 
@@ -44,6 +45,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
 #endif
 
 #include "obstack.h"
+#include "listing.h"
+
+
+#ifndef TC_START_LABEL
+#define TC_START_LABEL(x,y) (x==':')
+#endif
 
 /* The NOP_OPCODE is for the alignment fill value.
  * fill it a nop instruction so that the disassembler does not choke
@@ -95,8 +102,13 @@ char is_end_of_line[256] =
   _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _,     /* @abcdefghijklmno */
 #endif
   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,      /* */
+#ifdef TC_HPPA
+  _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _,      /* _!"#$%&'()*+,-./ */
+  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,      /* 0123456789:;<=>? */
+#else
   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,      /* */
   _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _,     /* 0123456789:;<=>? */
+#endif
   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,      /* */
   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,      /* */
   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,      /* */
@@ -195,7 +207,8 @@ static const pseudo_typeS potable[] =
 /* err */
 /* extend */
   {"extern", s_ignore, 0},     /* We treat all undef as ext */
-  {"appfile", s_app_file, 0},
+  {"appfile", s_app_file, 1},
+  {"appline", s_app_line, 0},
   {"file", s_app_file, 0},
   {"fill", s_fill, 0},
   {"float", float_cons, 'f'},
@@ -322,7 +335,6 @@ read_a_source_file (name)
   register char c;
   register char *s;            /* string of symbol, '\0' appended */
   register int temp;
-  /* register struct frag * fragP; JF unused *//* a frag we just made */
   pseudo_typeS *pop;
 
   buffer = input_scrub_new_file (name);
@@ -405,7 +417,7 @@ read_a_source_file (name)
               *   [In case of pseudo-op, s->'.'.]
               * Input_line_pointer->'\0' where c was.
               */
-             if (c == ':')
+             if (TC_START_LABEL(c, input_line_pointer))
                {
                  colon (s);    /* user-defined label */
                  *input_line_pointer++ = ':';  /* Put ':' back for error messages' sake. */
@@ -714,6 +726,8 @@ s_align_bytes (arg)
   if (temp && !need_pass_2)
     frag_align (temp, (int) temp_fill);
 
+  record_alignment (now_seg, temp);
+
   demand_empty_rest_of_line ();
 }                              /* s_align_bytes() */
 
@@ -758,7 +772,7 @@ s_comm ()
   register char *name;
   register char c;
   register char *p;
-  register int temp;
+  valueT temp;
   register symbolS *symbolP;
 
   name = input_line_pointer;
@@ -828,8 +842,16 @@ s_data ()
   demand_empty_rest_of_line ();
 }
 
+/* Handle the .appfile pseudo-op.  This is automatically generated by
+   do_scrub_next_char when a preprocessor # line comment is seen with
+   a file name.  This default definition may be overridden by the
+   object or CPU specific pseudo-ops.  This function is also the
+   default definition for .file; the APPFILE argument is 1 for
+   .appfile, 0 for .file.  */
+
 void 
-s_app_file ()
+s_app_file (appfile)
+     int appfile;
 {
   register char *s;
   int length;
@@ -837,13 +859,43 @@ s_app_file ()
   /* Some assemblers tolerate immediately following '"' */
   if ((s = demand_copy_string (&length)) != 0)
     {
-      new_logical_line (s, -1);
+      /* If this is a fake .appfile, a fake newline was inserted into
+        the buffer.  Passing -2 to new_logical_line tells it to
+        account for it.  */
+      new_logical_line (s, appfile ? -2 : -1);
       demand_empty_rest_of_line ();
+#ifdef LISTING
+      if (listing)
+       listing_source_file (s);
+#endif
     }
 #ifdef OBJ_COFF
   c_dot_file_symbol (s);
 #endif /* OBJ_COFF */
-}                              /* s_app_file() */
+#ifdef OBJ_ELF
+  elf_file_symbol (s);
+#endif
+}
+
+/* Handle the .appline pseudo-op.  This is automatically generated by
+   do_scrub_next_char when a preprocessor # line comment is seen.
+   This default definition may be overridden by the object or CPU
+   specific pseudo-ops.  */
+
+void
+s_app_line ()
+{
+  int l;
+
+  /* The given number is that of the next line.  */
+  l = get_absolute_expression () - 1;
+  new_logical_line ((char *) NULL, l);
+#ifdef LISTING
+  if (listing)
+    listing_source_line (l);
+#endif
+  demand_empty_rest_of_line ();
+}
 
 void 
 s_fill ()
@@ -908,9 +960,9 @@ s_fill ()
 void 
 s_globl ()
 {
-  register char *name;
-  register int c;
-  register symbolS *symbolP;
+  char *name;
+  int c;
+  symbolS *symbolP;
 
   do
     {
@@ -930,7 +982,7 @@ s_globl ()
     }
   while (c == ',');
   demand_empty_rest_of_line ();
-}                              /* s_globl() */
+}
 
 void 
 s_lcomm (needs_align)
@@ -943,8 +995,11 @@ s_lcomm (needs_align)
   register char *p;
   register int temp;
   register symbolS *symbolP;
+  segT current_seg = now_seg;
+  subsegT current_subseg = now_subseg;
   const int max_alignment = 15;
   int align = 0;
+  segT bss_seg = bss_section;
 
   name = input_line_pointer;
   c = get_symbol_end ();
@@ -973,6 +1028,14 @@ s_lcomm (needs_align)
       return;
     }
 
+#ifdef TC_MIPS
+#ifdef OBJ_ECOFF
+  /* For MIPS ECOFF, small objects are put in .sbss.  */
+  if (temp <= bfd_get_gp_size (stdoutput))
+    bss_seg = subseg_new (".sbss", 1);
+#endif
+#endif
+
   if (needs_align)
     {
       align = 0;
@@ -1001,7 +1064,7 @@ s_lcomm (needs_align)
          align = 0;
          as_warn ("Alignment negative. 0 assumed.");
        }
-      record_alignment (bss_section, align);
+      record_alignment (bss_seg, align);
     }                          /* if needs align */
 
   *p = 0;
@@ -1013,23 +1076,21 @@ s_lcomm (needs_align)
        S_GET_OTHER (symbolP) == 0 &&
        S_GET_DESC (symbolP) == 0 &&
 #endif /* OBJ_AOUT or OBJ_BOUT */
-       (S_GET_SEGMENT (symbolP) == bss_section
+       (S_GET_SEGMENT (symbolP) == bss_seg
        || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
     {
       char *p;
-      segT current_seg = now_seg;
-      subsegT current_subseg = now_subseg;
 
 #ifdef BFD_ASSEMBLER
-      subseg_set (bss_section, 1);
+      subseg_set (bss_seg, 1);
 #else
-      subseg_new (bss_section, 1);
+      subseg_new (bss_seg, 1);
 #endif
 
       if (align)
        frag_align (align, 0);
                                        /* detach from old frag */
-      if (S_GET_SEGMENT (symbolP) == bss_section)
+      if (S_GET_SEGMENT (symbolP) == bss_seg)
        symbolP->sy_frag->fr_symbol = NULL;
 
       symbolP->sy_frag = frag_now;
@@ -1037,7 +1098,7 @@ s_lcomm (needs_align)
                    temp, (char *)0);
       *p = 0;
 
-      S_SET_SEGMENT (symbolP, bss_section);
+      S_SET_SEGMENT (symbolP, bss_seg);
 
 #ifdef OBJ_COFF
       /* The symbol may already have been created with a preceding
@@ -1048,19 +1109,19 @@ s_lcomm (needs_align)
          S_SET_STORAGE_CLASS (symbolP, C_STAT);
        }
 #endif /* OBJ_COFF */
-#ifdef BFD_ASSEMBLER
-      subseg_set (current_seg, current_subseg);
-#else
-      subseg_new (current_seg, current_subseg);
-#endif
     }
   else
     {
       as_bad ("Ignoring attempt to re-define symbol %s.", name);
     }
-  demand_empty_rest_of_line ();
 
-  return;
+#ifdef BFD_ASSEMBLER
+  subseg_set (current_seg, current_subseg);
+#else
+  subseg_new (current_seg, current_subseg);
+#endif
+
+  demand_empty_rest_of_line ();
 }                              /* s_lcomm() */
 
 void
@@ -1406,18 +1467,23 @@ pseudo_set (symbolP)
          && (S_GET_SEGMENT (exp.X_add_symbol) ==
              S_GET_SEGMENT (exp.X_subtract_symbol)))
        {
-         if (exp.X_add_symbol->sy_frag != exp.X_subtract_symbol->sy_frag)
+         if (exp.X_add_symbol->sy_frag == exp.X_subtract_symbol->sy_frag)
            {
-             as_bad ("Unknown expression: symbols %s and %s are in different frags.",
-                     S_GET_NAME (exp.X_add_symbol), S_GET_NAME (exp.X_subtract_symbol));
-             need_pass_2++;
+             exp.X_add_number += S_GET_VALUE (exp.X_add_symbol) -
+               S_GET_VALUE (exp.X_subtract_symbol);
+             goto abs;
            }
-         exp.X_add_number += S_GET_VALUE (exp.X_add_symbol) -
-           S_GET_VALUE (exp.X_subtract_symbol);
+         as_bad ("Invalid expression: separation between symbols `%s'",
+                 S_GET_NAME (exp.X_add_symbol));
+         as_bad (" and `%s' may not be constant",
+                 S_GET_NAME (exp.X_subtract_symbol));
+         need_pass_2++;
        }
       else
-       as_bad ("Complex expression. Absolute segment assumed.");
-      goto abs;
+       {
+         as_bad ("Complex expression. Absolute segment assumed.");
+         goto abs;
+       }
     }
   else if (segment == absolute_section)
     {
@@ -1433,13 +1499,19 @@ pseudo_set (symbolP)
     }
   else if (segment == pass1_section)
     {
-      symbolP->sy_forward = exp.X_add_symbol;
+      symbolP->sy_value.X_add_symbol = exp.X_add_symbol;
+      symbolP->sy_value.X_subtract_symbol = NULL;
+      symbolP->sy_value.X_add_number = 0;
+      symbolP->sy_value.X_seg = undefined_section;
       as_bad ("Unknown expression");
       know (need_pass_2 == 1);
     }
   else if (segment == undefined_section)
     {
-      symbolP->sy_forward = exp.X_add_symbol;
+      symbolP->sy_value.X_add_symbol = exp.X_add_symbol;
+      symbolP->sy_value.X_subtract_symbol = NULL;
+      symbolP->sy_value.X_add_number = 0;
+      symbolP->sy_value.X_seg = undefined_section;
     }
   else
     {
@@ -1490,6 +1562,39 @@ pseudo_set (symbolP)
  * in the case of a long. Not worth the crocks required to fix it.
  */
 
+/* Select a parser for cons expressions.  */
+
+/* Some targets need to parse the expression in various fancy ways.
+   You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
+   (for example, the HPPA does this).  Otherwise, you can define
+   BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
+   REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
+   are defined, which is the normal case, then only simple expressions
+   are permitted.  */
+
+#ifndef TC_PARSE_CONS_EXPRESSION
+#ifdef BITFIELD_CONS_EXPRESSIONS
+#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
+static void 
+parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
+#endif
+#ifdef MRI
+#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
+static void
+parse_mri_cons PARAMS ((expressionS *exp));
+#endif
+#ifdef REPEAT_CONS_EXPRESSIONS
+#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
+static void
+parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
+#endif
+
+/* If we haven't gotten one yet, just call expression.  */
+#ifndef TC_PARSE_CONS_EXPRESSION
+#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
+#endif
+#endif
+
 /* worker to do .byte etc statements */
 /* clobbers input_line_pointer, checks */
 /* end-of-line. */
@@ -1497,339 +1602,383 @@ void
 cons (nbytes)
      register unsigned int nbytes;     /* 1=.byte, 2=.word, 4=.long */
 {
-  register char c;
-  register long mask;          /* High-order bits we will left-truncate, */
-  /* but includes sign bit also. */
-  register long get;           /* what we get */
-  register long use;           /* get after truncation. */
-  register long unmask;                /* what bits we will store */
-  register char *p;
-  register segT segment;
   expressionS exp;
 
-  /*
-   * Input_line_pointer->1st char after pseudo-op-code and could legally
-   * be a end-of-line. (Or, less legally an eof - which we cope with.)
-   */
-  /* JF << of >= number of bits in the object is undefined.  In particular
-     SPARC (Sun 4) has problems */
-
-  if (nbytes >= sizeof (long))
+  if (is_it_end_of_statement ())
     {
-      mask = 0;
+      demand_empty_rest_of_line ();
+      return;
     }
-  else
+
+  do
     {
-      mask = ~0 << (BITS_PER_CHAR * nbytes);   /* Don't store these bits. */
-    }                          /* bigger than a long */
+      TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
+      emit_expr (&exp, nbytes);
+    }
+  while (*input_line_pointer++ == ',');
 
-  unmask = ~mask;              /* Do store these bits. */
+  input_line_pointer--;                /* Put terminator back into stream. */
+  demand_empty_rest_of_line ();
+}                              /* cons() */
 
-#ifdef NEVER
-  "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
-  mask = ~(unmask >> 1);       /* Includes sign bit now. */
-#endif
+/* Put the contents of expression EXP into the object file using
+   NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
 
-  /*
-   * The following awkward logic is to parse ZERO or more expressions,
-   * comma seperated. Recall an expression includes its leading &
-   * trailing blanks. We fake a leading ',' if there is (supposed to
-   * be) a 1st expression, and keep demanding 1 expression for each ','.
-   */
-  if (is_it_end_of_statement ())
+void
+emit_expr (exp, nbytes)
+     expressionS *exp;
+     unsigned int nbytes;
+{
+  segT segment;
+  register char *p;
+
+  /* Don't do anything if we are going to make another pass.  */
+  if (need_pass_2)
+    return;
+
+  segment = exp->X_seg;
+
+  /* Don't call this if we are going to junk this pass anyway! */
+  know (segment != pass1_section);
+
+  if (segment == diff_section && exp->X_add_symbol == NULL)
     {
-      c = 0;                   /* Skip loop. */
-      input_line_pointer++;    /* Matches end-of-loop 'correction'. */
+      as_bad ("Subtracting symbol \"%s\" (segment \"%s\") is too hard.  Absolute segment assumed.",
+             S_GET_NAME (exp->X_subtract_symbol),
+             segment_name (S_GET_SEGMENT (exp->X_subtract_symbol)));
+      segment = absolute_section;
+      /* Leave exp->X_add_number alone. */
     }
-  else
+  else if (segment == absent_section)
     {
-      c = ',';
-    }                          /* if the end else fake it */
-
-  /* Do loop. */
-  while (c == ',')
+      as_warn ("0 assumed for missing expression");
+      exp->X_add_number = 0;
+      know (exp->X_add_symbol == NULL);
+      segment = absolute_section;
+    }
+  else if (segment == big_section)
     {
-#ifdef WANT_BITFIELDS
-      unsigned int bits_available = BITS_PER_CHAR * nbytes;
-      /* used for error messages and rescanning */
-      char *hold = input_line_pointer;
-#endif /* WANT_BITFIELDS */
-#ifdef MRI
-      if (*input_line_pointer == '\'')
-       {
-         /* An MRI style string, cut into as many bytes as will fit
-          into a nbyte chunk, left justify if necessary, and sepatate
-          with commas so we can try again later */
-         int scan = 0;
-         unsigned int result = 0;
-         input_line_pointer++;
-         for (scan = 0; scan < nbytes; scan++)
-           {
-             if (*input_line_pointer == '\'')
-               {
-                 if (input_line_pointer[1] == '\'')
-                   {
-                     input_line_pointer++;
-                   }
-                 else
-                   break;
-               }
-             result = (result << 8) | (*input_line_pointer++);
-           }
+      as_bad ("%s number invalid.  Absolute 0 assumed.",
+             exp->X_add_number > 0 ? "Bignum" : "Floating-Point");
+      exp->X_add_number = 0;
+      segment = absolute_section;
+    }
 
-         /* Left justify */
-         while (scan < nbytes)
-           {
-             result <<= 8;
-             scan++;
-           }
-         /* Create correct expression */
-         exp.X_add_symbol = 0;
-         exp.X_add_number = result;
-         exp.X_seg = segment = absolute_section;
-         /* Fake it so that we can read the next char too */
-         if (input_line_pointer[0] != '\'' ||
-          (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
-           {
-             input_line_pointer -= 2;
-             input_line_pointer[0] = ',';
-             input_line_pointer[1] = '\'';
-           }
-         else
-           input_line_pointer++;
+  p = frag_more (nbytes);
 
-       }
-      else
+#ifndef WORKING_DOT_WORD
+  /* If we have the difference of two symbols in a word, save it on
+     the broken_words list.  See the code in write.c.  */
+  if (segment == diff_section && nbytes == 2)
+    {
+      struct broken_word *x;
+
+      x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
+      x->next_broken_word = broken_words;
+      broken_words = x;
+      x->frag = frag_now;
+      x->word_goes_here = p;
+      x->dispfrag = 0;
+      x->add = exp->X_add_symbol;
+      x->sub = exp->X_subtract_symbol;
+      x->addnum = exp->X_add_number;
+      x->added = 0;
+      new_broken_words++;
+      return;
+    }
 #endif
-       /* At least scan over the expression. */
-       segment = expression (&exp);
-
-#ifdef WANT_BITFIELDS
-      /* Some other assemblers, (eg, asm960), allow
-        bitfields after ".byte" as w:x,y:z, where w and
-        y are bitwidths and x and y are values.  They
-        then pack them all together. We do a little
-        better in that we allow them in words, longs,
-        etc. and we'll pack them in target byte order
-        for you.
-       
-        The rules are: pack least significat bit first,
-        if a field doesn't entirely fit, put it in the
-        next unit.  Overflowing the bitfield is
-        explicitly *not* even a warning.  The bitwidth
-        should be considered a "mask".
-       
-        FIXME-SOMEDAY: If this is considered generally
-        useful, this logic should probably be reworked.
-        xoxorich. */
-
-      if (*input_line_pointer == ':')
-       {                       /* bitfields */
-         long value = 0;
-
-         for (;;)
-           {
-             unsigned long width;
 
-             if (*input_line_pointer != ':')
-               {
-                 input_line_pointer = hold;
-                 break;
-               }               /* next piece is not a bitfield */
-
-             /* In the general case, we can't allow
-                full expressions with symbol
-                differences and such.  The relocation
-                entries for symbols not defined in this
-                assembly would require arbitrary field
-                widths, positions, and masks which most
-                of our current object formats don't
-                support.
-               
-                In the specific case where a symbol
-                *is* defined in this assembly, we
-                *could* build fixups and track it, but
-                this could lead to confusion for the
-                backends.  I'm lazy. I'll take any
-                SEG_ABSOLUTE. I think that means that
-                you can use a previous .set or
-                .equ type symbol.  xoxorich. */
-
-             if (segment == absent_section)
-               {
-                 as_warn ("Using a bit field width of zero.");
-                 exp.X_add_number = 0;
-                 segment = absolute_section;
-               }               /* implied zero width bitfield */
+  if (segment == absolute_section)
+    {
+      register long get;
+      register long use;
+      register long mask;
+      register long unmask;
 
-             if (segment != absolute_section)
-               {
-                 *input_line_pointer = '\0';
-                 as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold);
-                 *input_line_pointer = ':';
-                 demand_empty_rest_of_line ();
-                 return;
-               }               /* too complex */
+      /* JF << of >= number of bits in the object is undefined.  In
+        particular SPARC (Sun 4) has problems */
+      if (nbytes >= sizeof (long))
+       mask = 0;
+      else
+       mask = ~0 << (BITS_PER_CHAR * nbytes);  /* Don't store these bits. */
 
-             if ((width = exp.X_add_number) > (BITS_PER_CHAR * nbytes))
-               {
-                 as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
-                          width, nbytes, (BITS_PER_CHAR * nbytes));
-                 width = BITS_PER_CHAR * nbytes;
-               }               /* too big */
+      unmask = ~mask;          /* Do store these bits. */
 
-             if (width > bits_available)
-               {
-                 /* FIXME-SOMEDAY: backing up and
-                    reparsing is wasteful */
-                 input_line_pointer = hold;
-                 exp.X_add_number = value;
-                 break;
-               }               /* won't fit */
+#ifdef NEVER
+      "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
+      mask = ~(unmask >> 1);   /* Includes sign bit now. */
+#endif
 
-             hold = ++input_line_pointer;      /* skip ':' */
+      get = exp->X_add_number;
+      use = get & unmask;
+      if ((get & mask) != 0 && (get & mask) != mask)
+       {               /* Leading bits contain both 0s & 1s. */
+         as_warn ("Value 0x%x truncated to 0x%x.", get, use);
+       }
+      md_number_to_chars (p, use, nbytes);     /* put bytes in right order. */
+    }
+  else
+    {
+      md_number_to_chars (p, (long) 0, nbytes);
 
-             if ((segment = expression (&exp)) != absolute_section)
-               {
-                 char cache = *input_line_pointer;
+      /* Now we need to generate a fixS to record the symbol value.
+        This is easy for BFD.  For other targets it can be more
+        complex.  For very complex cases (currently, the HPPA and
+        NS32K), you can define TC_CONS_FIX_NEW to do whatever you
+        want.  For simpler cases, you can define TC_CONS_RELOC to be
+        the name of the reloc code that should be stored in the fixS.
+        If neither is defined, the code uses NO_RELOC if it is
+        defined, and otherwise uses 0.  */
 
-                 *input_line_pointer = '\0';
-                 as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold);
-                 *input_line_pointer = cache;
-                 demand_empty_rest_of_line ();
-                 return;
-               }               /* too complex */
+#ifdef BFD_ASSEMBLER
+      fix_new (frag_now, p - frag_now->fr_literal, nbytes,
+              exp->X_add_symbol, exp->X_subtract_symbol,
+              exp->X_add_number, 0,
+              /* @@ Should look at CPU word size.  */
+              BFD_RELOC_32);
+#else
+#ifdef TC_CONS_FIX_NEW
+      TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
+#else
+      /* Figure out which reloc number to use.  Use TC_CONS_RELOC if
+        it is defined, otherwise use NO_RELOC if it is defined,
+        otherwise use 0.  */
+#ifndef TC_CONS_RELOC
+#ifdef NO_RELOC
+#define TC_CONS_RELOC NO_RELOC
+#else
+#define TC_CONS_RELOC 0
+#endif
+#endif
+      fix_new (frag_now, p - frag_now->fr_literal, nbytes,
+              exp->X_add_symbol, exp->X_subtract_symbol,
+              exp->X_add_number, 0, TC_CONS_RELOC);
+#endif /* TC_CONS_FIX_NEW */
+#endif /* BFD_ASSEMBLER */
+    }
+}
+\f
+#ifdef BITFIELD_CONS_EXPRESSIONS
 
-             value |= (~(-1 << width) & exp.X_add_number)
-               << ((BITS_PER_CHAR * nbytes) - bits_available);
+/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
+   w:x,y:z, where w and y are bitwidths and x and y are values.  They
+   then pack them all together. We do a little better in that we allow
+   them in words, longs, etc. and we'll pack them in target byte order
+   for you.
 
-             if ((bits_available -= width) == 0
-                 || is_it_end_of_statement ()
-                 || *input_line_pointer != ',')
-               {
-                 break;
-               }               /* all the bitfields we're gonna get */
+   The rules are: pack least significat bit first, if a field doesn't
+   entirely fit, put it in the next unit.  Overflowing the bitfield is
+   explicitly *not* even a warning.  The bitwidth should be considered
+   a "mask".
 
-             hold = ++input_line_pointer;
-             segment = expression (&exp);
-           }                   /* forever loop */
+   To use this function the tc-XXX.h file should define
+   BITFIELD_CONS_EXPRESSIONS.  */
 
-         exp.X_add_number = value;
-         segment = absolute_section;
-       }                       /* if looks like a bitfield */
-#endif /* WANT_BITFIELDS */
+static void 
+parse_bitfield_cons (exp, nbytes)
+     expressionS *exp;
+     unsigned int nbytes;
+{
+  unsigned int bits_available = BITS_PER_CHAR * nbytes;
+  char *hold = input_line_pointer;
+  segT segment;
 
-      if (!need_pass_2)
-       {                       /* Still worthwhile making frags. */
+  segment = expression (exp);
 
-         /* Don't call this if we are going to junk this pass anyway! */
-         know (segment != pass1_section);
+  if (*input_line_pointer == ':')
+    {                  /* bitfields */
+      long value = 0;
 
-         if (segment == diff_section && exp.X_add_symbol == NULL)
+      for (;;)
+       {
+         unsigned long width;
+
+         if (*input_line_pointer != ':')
            {
-             as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
-                     S_GET_NAME (exp.X_subtract_symbol),
-                     segment_name (S_GET_SEGMENT (exp.X_subtract_symbol)));
+             input_line_pointer = hold;
+             break;
+           }                   /* next piece is not a bitfield */
+
+         /* In the general case, we can't allow
+            full expressions with symbol
+            differences and such.  The relocation
+            entries for symbols not defined in this
+            assembly would require arbitrary field
+            widths, positions, and masks which most
+            of our current object formats don't
+            support.
+            
+            In the specific case where a symbol
+            *is* defined in this assembly, we
+            *could* build fixups and track it, but
+            this could lead to confusion for the
+            backends.  I'm lazy. I'll take any
+            SEG_ABSOLUTE. I think that means that
+            you can use a previous .set or
+            .equ type symbol.  xoxorich. */
+
+         if (segment == absent_section)
+           {
+             as_warn ("Using a bit field width of zero.");
+             exp->X_add_number = 0;
              segment = absolute_section;
-             /* Leave exp . X_add_number alone. */
-           }
-         p = frag_more (nbytes);
-         if (segment == big_section)
+           }                   /* implied zero width bitfield */
+
+         if (segment != absolute_section)
            {
-             as_bad ("%s number invalid. Absolute 0 assumed.",
-                     exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
-             md_number_to_chars (p, (long) 0, nbytes);
-           }
-         else if (segment == absent_section)
+             *input_line_pointer = '\0';
+             as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold);
+             *input_line_pointer = ':';
+             demand_empty_rest_of_line ();
+             return;
+           }                   /* too complex */
+
+         if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
            {
-             as_warn ("0 assumed for missing expression");
-             exp.X_add_number = 0;
-             know (exp.X_add_symbol == NULL);
-             goto abs_sec;
-           }
-         else if (segment == absolute_section)
+             as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
+                      width, nbytes, (BITS_PER_CHAR * nbytes));
+             width = BITS_PER_CHAR * nbytes;
+           }                   /* too big */
+
+         if (width > bits_available)
            {
-           abs_sec:
-             get = exp.X_add_number;
-             use = get & unmask;
-             if ((get & mask) && (get & mask) != mask)
-               {               /* Leading bits contain both 0s & 1s. */
-                 as_warn ("Value 0x%x truncated to 0x%x.", get, use);
-               }
-             md_number_to_chars (p, use, nbytes);      /* put bytes in right order. */
-           }
-         else if (segment == diff_section)
+             /* FIXME-SOMEDAY: backing up and reparsing is wasteful.  */
+             input_line_pointer = hold;
+             exp->X_add_number = value;
+             break;
+           }                   /* won't fit */
+
+         hold = ++input_line_pointer; /* skip ':' */
+
+         if ((segment = expression (exp)) != absolute_section)
            {
-#ifndef WORKING_DOT_WORD
-             if (nbytes == 2)
+             char cache = *input_line_pointer;
+
+             *input_line_pointer = '\0';
+             as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold);
+             *input_line_pointer = cache;
+             demand_empty_rest_of_line ();
+             return;
+           }                   /* too complex */
+
+         value |= (~(-1 << width) & exp->X_add_number)
+           << ((BITS_PER_CHAR * nbytes) - bits_available);
+
+         if ((bits_available -= width) == 0
+             || is_it_end_of_statement ()
+             || *input_line_pointer != ',')
+           {
+             break;
+           }                   /* all the bitfields we're gonna get */
+
+         hold = ++input_line_pointer;
+         segment = expression (exp);
+       }                       /* forever loop */
+
+      exp->X_add_number = value;
+      exp->X_seg = absolute_section;
+    }                          /* if looks like a bitfield */
+}                              /* parse_bitfield_cons() */
+
+#endif /* BITFIELD_CONS_EXPRESSIONS */
+\f
+#ifdef MRI
+
+static void
+parse_mri_cons (exp, nbytes)
+     expressionS *exp;
+     unsigned int nbytes;
+{
+  if (*input_line_pointer == '\'')
+    {
+      /* An MRI style string, cut into as many bytes as will fit into
+        a nbyte chunk, left justify if necessary, and separate with
+        commas so we can try again later */
+      int scan = 0;
+      unsigned int result = 0;
+      input_line_pointer++;
+      for (scan = 0; scan < nbytes; scan++)
+       {
+         if (*input_line_pointer == '\'')
+           {
+             if (input_line_pointer[1] == '\'')
                {
-                 struct broken_word *x;
-
-                 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
-                 x->next_broken_word = broken_words;
-                 broken_words = x;
-                 x->frag = frag_now;
-                 x->word_goes_here = p;
-                 x->dispfrag = 0;
-                 x->add = exp.X_add_symbol;
-                 x->sub = exp.X_subtract_symbol;
-                 x->addnum = exp.X_add_number;
-                 x->added = 0;
-                 new_broken_words++;
-                 goto after_switch;
+                 input_line_pointer++;
                }
-#endif
-             goto defalt;
+             else
+               break;
            }
-         else
-           /* undefined_section, others */
-           {
-           defalt:
-#ifdef BFD_ASSEMBLER
-             fix_new (frag_now, p - frag_now->fr_literal, nbytes,
-                      exp.X_add_symbol, exp.X_subtract_symbol,
-                      exp.X_add_number, 0,
-                      /* @@ Should look at CPU word size.  */
-                      BFD_RELOC_32);
-#else
-#ifdef TC_NS32K
-             fix_new_ns32k (frag_now, p - frag_now->fr_literal, nbytes,
-                            exp.X_add_symbol, exp.X_subtract_symbol,
-                            exp.X_add_number, 0, 0, 2, 0, 0);
-#else
-#if defined(TC_SPARC) || defined(TC_A29K)
-             fix_new (frag_now, p - frag_now->fr_literal, nbytes,
-                      exp.X_add_symbol, exp.X_subtract_symbol,
-                      exp.X_add_number, 0, RELOC_32);
-#else
-#if defined(TC_H8300)
-             fix_new (frag_now, p - frag_now->fr_literal, nbytes,
-                      exp.X_add_symbol, exp.X_subtract_symbol,
-                      exp.X_add_number, 0, R_RELWORD);
+         result = (result << 8) | (*input_line_pointer++);
+       }
 
-#else
-#ifdef NO_RELOC
-             fix_new (frag_now, p - frag_now->fr_literal, nbytes,
-                      exp.X_add_symbol, exp.X_subtract_symbol,
-                      exp.X_add_number, 0, NO_RELOC);
-#else
-             fix_new (frag_now, p - frag_now->fr_literal, nbytes,
-                      exp.X_add_symbol, exp.X_subtract_symbol,
-                      exp.X_add_number, 0, 0);
-#endif /* NO_RELOC */
-#endif /* tc_h8300 */
-#endif /* tc_sparc|tc_a29k */
-#endif /* TC_NS32K */
-#endif /* BFD_ASSEMBLER */
-           }                   /* switch(segment) */
-       after_switch:
-         ;
-       }                       /* if (!need_pass_2) */
-      c = *input_line_pointer++;
-    }                          /* while(c==',') */
-  input_line_pointer--;                /* Put terminator back into stream. */
-  demand_empty_rest_of_line ();
-}                              /* cons() */
+      /* Left justify */
+      while (scan < nbytes)
+       {
+         result <<= 8;
+         scan++;
+       }
+      /* Create correct expression */
+      exp->X_add_symbol = 0;
+      exp->X_add_number = result;
+      exp->X_seg = absolute_section;
+      /* Fake it so that we can read the next char too */
+      if (input_line_pointer[0] != '\'' ||
+         (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
+       {
+         input_line_pointer -= 2;
+         input_line_pointer[0] = ',';
+         input_line_pointer[1] = '\'';
+       }
+      else
+       input_line_pointer++;
+    }
+  else
+    expression (&exp);
+}
+
+#endif /* MRI */
+\f
+#ifdef REPEAT_CONS_EXPRESSIONS
+
+/* Parse a repeat expression for cons.  This is used by the MIPS
+   assembler.  The format is NUMBER:COUNT; NUMBER appears in the
+   object file COUNT times.
+
+   To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
+
+static void
+parse_repeat_cons (exp, nbytes)
+     expressionS *exp;
+     unsigned int nbytes;
+{
+  expressionS count;
+  segT segment;
+  register int i;
+
+  expression (exp);
+
+  if (*input_line_pointer != ':')
+    {
+      /* No repeat count.  */
+      return;
+    }
+
+  ++input_line_pointer;
+  segment = expression (&count);
+  if (segment != absolute_section
+      || count.X_add_number <= 0)
+    {
+      as_warn ("Unresolvable or nonpositive repeat count; using 1");
+      return;
+    }
+
+  /* The cons function is going to output this expression once.  So we
+     output it count - 1 times.  */
+  for (i = count.X_add_number - 1; i > 0; i--)
+    emit_expr (exp, nbytes);
+}
+
+#endif /* REPEAT_CONS_EXPRESSIONS */
 \f
 /*
  *                     big_cons()
@@ -2051,7 +2200,7 @@ float_cons (float_type)           /* Worker to do .float etc statements. */
       err = md_atof (float_type, temp, &length);
       know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
       know (length > 0);
-      if (*err)
+      if (err && *err)
        {
          as_bad ("Bad floating literal: %s", err);
          ignore_rest_of_line ();