]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gas/config/tc-tic4x.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / config / tc-tic4x.c
index fd6cec7f82ddbb4993e6382c2f51b04281068ca0..c456dffbbad1f611d7f6ab522195609ac270f2b3 100644 (file)
@@ -1,6 +1,5 @@
 /* tc-tic4x.c -- Assemble for the Texas Instruments TMS320C[34]x.
-   Copyright (C) 1997,1998, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010,
-   2012 Free Software Foundation. Inc.
+   Copyright (C) 1997-2021 Free Software Foundation, Inc.
 
    Contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)
 
 
    You should have received a copy of the GNU General Public License
    along with GAS; see the file COPYING.  If not, write to
-   the Free Software Foundation, 51 Franklin Street - Fifth Floor, 
+   the Free Software Foundation, 51 Franklin Street - Fifth Floor,
    Boston, MA 02110-1301, USA.  */
 /*
   TODOs:
   ------
-  
+
   o .align cannot handle fill-data-width larger than 0xFF/8-bits. It
     should be possible to define a 32-bits pattern.
 
-  o .align fills all section with NOP's when used regardless if has
-    been used in .text or .data. (However the .align is primarily
-    intended used in .text sections. If you require something else,
-    use .align <size>,0x00)
-
   o .align: Implement a 'bu' insn if the number of nop's exceeds 4
     within the align frag. if(fragsize>4words) insert bu fragend+1
     first.
   o Evaluation of constant floating point expressions (expr.c needs
     work!)
 
-  o Support 'abc' constants (that is 0x616263)
-*/
+  o Support 'abc' constants (that is 0x616263).  */
 
-#include "safe-ctype.h"
 #include "as.h"
+#include "safe-ctype.h"
 #include "opcode/tic4x.h"
 #include "subsegs.h"
-#include "obstack.h"
 
 /* OK, we accept a syntax similar to the other well known C30
    assembly tools.  With TIC4X_ALT_SYNTAX defined we are more
 
 #define TIC4X_ALT_SYNTAX
 
-/* Equal to MAX_PRECISION in atof-ieee.c.  */
-#define MAX_LITTLENUMS 6       /* (12 bytes) */
-
 /* Handle of the inst mnemonic hash table.  */
-static struct hash_control *tic4x_op_hash = NULL;
+static htab_t tic4x_op_hash = NULL;
 
 /* Handle asg pseudo.  */
-static struct hash_control *tic4x_asg_hash = NULL;
+static htab_t tic4x_asg_hash = NULL;
 
 static unsigned int tic4x_cpu = 0;        /* Default to TMS320C40.  */
 static unsigned int tic4x_revision = 0;   /* CPU revision */
@@ -88,7 +77,7 @@ static unsigned long tic4x_oplevel = 0;   /* Opcode level */
 #define OPTION_ENHANCED (OPTION_MD_BASE + 7)
 #define OPTION_REV      (OPTION_MD_BASE + 8)
 
-CONST char *md_shortopts = "bm:prs";
+const char *md_shortopts = "bm:prs";
 struct option md_longopts[] =
 {
   { "mcpu",   required_argument, NULL, OPTION_CPU },
@@ -132,7 +121,8 @@ typedef struct tic4x_insn
     unsigned int nchars;       /* This is always 4 for the C30.  */
     unsigned long opcode;      /* Opcode number.  */
     expressionS exp;           /* Expression required for relocation.  */
-    int reloc;                 /* Relocation type required.  */
+    /* Relocation type required.  */
+    bfd_reloc_code_real_type reloc;
     int pcrel;                 /* True if relocation PC relative.  */
     char *pname;               /* Name of instruction in parallel.  */
     unsigned int num_operands; /* Number of operands in total.  */
@@ -203,10 +193,10 @@ const char comment_chars[] = ";";
 
 /* This array holds the chars that only start a comment at the beginning of
    a line.  If the line seems to have the form '# 123 filename'
-   .line and .file directives will appear in the pre-processed output. 
+   .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 comments like this one will always work.  */
 const char line_comment_chars[] = "#*";
 
@@ -230,7 +220,7 @@ const char FLT_CHARS[] = "fFilsS";
 extern FLONUM_TYPE generic_floating_point_number;
 
 /* Precision in LittleNums.  */
-#define MAX_PRECISION (4)       /* Its a bit overkill for us, but the code
+#define MAX_PRECISION (4)       /* It's a bit overkill for us, but the code
                                    requires it... */
 #define S_PRECISION (1)                /* Short float constants 16-bit.  */
 #define F_PRECISION (2)                /* Float and double types 32-bit.  */
@@ -258,7 +248,7 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
      The code in this function is altered slightly to support floats
      with 31-bits mantissas, thus the documentation below may be a
      little bit inaccurate.
-     
+
      By Michael P. Hayes <m.hayes@elec.canterbury.ac.nz>
      Here is how a generic floating point number is stored using
      flonums (an extension of bignums) where p is a pointer to an
@@ -406,7 +396,7 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
       /* +INF:  Replace with maximum float.  */
       if (precision == S_PRECISION)
        words[0] = 0x77ff;
-      else 
+      else
        {
          words[0] = 0x7f7f;
          words[1] = 0xffff;
@@ -423,7 +413,7 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
       /* -INF:  Replace with maximum float.  */
       if (precision == S_PRECISION)
        words[0] = 0x7800;
-      else 
+      else
         words[0] = 0x7f80;
       if (precision == E_PRECISION)
         words[2] = 0x8000;
@@ -463,8 +453,8 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
   /* Store the mantissa data into smant and the roundbit into rbit */
   for (p = flonum.leader; p >= flonum.low && shift > -16; p--)
     {
-      tmp = shift >= 0 ? *p << shift : *p >> -shift;
-      rbit = shift < 0 ? ((*p >> (-shift-1)) & 0x1) : 0;
+      tmp = shift >= 0 ? (unsigned) *p << shift : (unsigned) *p >> -shift;
+      rbit = shift < 0 ? (((unsigned) *p >> (-shift-1)) & 0x1) : 0;
       smant |= tmp;
       shift -= 16;
     }
@@ -473,18 +463,14 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
   if(rbit)
     {
       /* If the mantissa is going to overflow when added, lets store
-         the extra bit in mover. -- A special case exists when
-         mantissa_bits is 31 (E_PRECISION). Then the first test cannot
-         be trusted, as result is host-dependent, thus the second
-         test. */
-      if( smant == ((unsigned)(1<<(mantissa_bits+1))-1)
-          || smant == (unsigned)-1 )  /* This is to catch E_PRECISION cases */
+        the extra bit in mover.  */
+      if (smant == (1u << mantissa_bits << 1) - 1)
         mover=1;
       smant++;
     }
 
   /* Get the scaled one value */
-  sone = (1 << (mantissa_bits));
+  sone = 1u << mantissa_bits;
 
   /* The number may be unnormalised so renormalise it...  */
   if(mover)
@@ -537,7 +523,7 @@ tic4x_gen_to_words (FLONUM_TYPE flonum, LITTLENUM_TYPE *words, int precision)
   else
     {
       /* Insert the exponent data into the word */
-      sfract |= exponent << (mantissa_bits+1);
+      sfract |= (unsigned) exponent << (mantissa_bits + 1);
 
       if (precision == S_PRECISION)
         words[0] = sfract;
@@ -625,29 +611,29 @@ tic4x_atof (char *str, char what_kind, LITTLENUM_TYPE *words)
   return return_value;
 }
 
-static void 
-tic4x_insert_reg (char *regname, int regnum)
+static void
+tic4x_insert_reg (const char *regname, int regnum)
 {
   char buf[32];
   int i;
 
-  symbol_table_insert (symbol_new (regname, reg_section, (valueT) regnum,
-                                  &zero_address_frag));
+  symbol_table_insert (symbol_new (regname, reg_section,
+                                  &zero_address_frag, regnum));
   for (i = 0; regname[i]; i++)
     buf[i] = ISLOWER (regname[i]) ? TOUPPER (regname[i]) : regname[i];
   buf[i] = '\0';
 
-  symbol_table_insert (symbol_new (buf, reg_section, (valueT) regnum,
-                                  &zero_address_frag));
+  symbol_table_insert (symbol_new (buf, reg_section,
+                                  &zero_address_frag, regnum));
 }
 
-static void 
-tic4x_insert_sym (char *symname, int value)
+static void
+tic4x_insert_sym (const char *symname, int value)
 {
   symbolS *symbolP;
 
   symbolP = symbol_new (symname, absolute_section,
-                       (valueT) value, &zero_address_frag);
+                       &zero_address_frag, value);
   SF_SET_LOCAL (symbolP);
   symbol_table_insert (symbolP);
 }
@@ -680,7 +666,7 @@ tic4x_expression_abs (char *str, offsetT *value)
   return s;
 }
 
-static void 
+static void
 tic4x_emit_char (char c, int b)
 {
   expressionS exp;
@@ -690,7 +676,7 @@ tic4x_emit_char (char c, int b)
   emit_expr (&exp, b);
 }
 
-static void 
+static void
 tic4x_seg_alloc (char *name ATTRIBUTE_UNUSED,
                 segT seg ATTRIBUTE_UNUSED,
                 int size,
@@ -715,13 +701,12 @@ tic4x_seg_alloc (char *name ATTRIBUTE_UNUSED,
 }
 
 /* .asg ["]character-string["], symbol */
-static void 
+static void
 tic4x_asg (int x ATTRIBUTE_UNUSED)
 {
   char c;
   char *name;
   char *str;
-  char *tmp;
 
   SKIP_WHITESPACE ();
   str = input_line_pointer;
@@ -735,24 +720,16 @@ tic4x_asg (int x ATTRIBUTE_UNUSED)
       return;
     }
   *input_line_pointer++ = '\0';
-  name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
-  tmp = xmalloc (strlen (str) + 1);
-  strcpy (tmp, str);
-  str = tmp;
-  tmp = xmalloc (strlen (name) + 1);
-  strcpy (tmp, name);
-  name = tmp;
-  if (hash_find (tic4x_asg_hash, name))
-    hash_replace (tic4x_asg_hash, name, (void *) str);
-  else
-    hash_insert (tic4x_asg_hash, name, (void *) str);
-  *input_line_pointer = c;
+  c = get_symbol_name (&name); /* Get terminator.  */
+  str = xstrdup (str);
+  name = xstrdup (name);
+  str_hash_insert (tic4x_asg_hash, name, str, 1);
+  (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
 }
 
 /* .bss symbol, size  */
-static void 
+static void
 tic4x_bss (int x ATTRIBUTE_UNUSED)
 {
   char c;
@@ -767,8 +744,9 @@ tic4x_bss (int x ATTRIBUTE_UNUSED)
   current_subseg = now_subseg; /* Save current subseg.  */
 
   SKIP_WHITESPACE ();
-  name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  c = get_symbol_name (&name); /* Get terminator.  */
+  if (c == '"')
+    c = * ++ input_line_pointer;
   if (c != ',')
     {
       as_bad (_(".bss size argument missing\n"));
@@ -815,11 +793,10 @@ tic4x_globl (int ignore ATTRIBUTE_UNUSED)
 
   do
     {
-      name = input_line_pointer;
-      c = get_symbol_end ();
+      c = get_symbol_name (&name);
       symbolP = symbol_find_or_make (name);
       *input_line_pointer = c;
-      SKIP_WHITESPACE ();
+      SKIP_WHITESPACE_AFTER_NAME ();
       S_SET_STORAGE_CLASS (symbolP, C_EXT);
       S_SET_EXTERNAL (symbolP);
       if (c == ',')
@@ -836,10 +813,10 @@ tic4x_globl (int ignore ATTRIBUTE_UNUSED)
 }
 
 /* Handle .byte, .word. .int, .long */
-static void 
+static void
 tic4x_cons (int bytes)
 {
-  register unsigned int c;
+  unsigned int c;
   do
     {
       SKIP_WHITESPACE ();
@@ -879,11 +856,11 @@ tic4x_cons (int bytes)
 }
 
 /* Handle .ascii, .asciz, .string */
-static void 
+static void
 tic4x_stringer (int append_zero)
 {
   int bytes;
-  register unsigned int c;
+  unsigned int c;
 
   bytes = 0;
   do
@@ -916,7 +893,7 @@ tic4x_stringer (int append_zero)
               as_bad (_("Non-constant symbols not allowed\n"));
               return;
             }
-          exp.X_add_number &= 255; /* Limit numeber to 8-bit */
+          exp.X_add_number &= 255; /* Limit number to 8-bit */
          emit_expr (&exp, 1);
           bytes++;
        }
@@ -932,7 +909,7 @@ tic4x_stringer (int append_zero)
 }
 
 /* .eval expression, symbol */
-static void 
+static void
 tic4x_eval (int x ATTRIBUTE_UNUSED)
 {
   char c;
@@ -947,15 +924,14 @@ tic4x_eval (int x ATTRIBUTE_UNUSED)
       as_bad (_("Symbol missing\n"));
       return;
     }
-  name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  c = get_symbol_name (&name); /* Get terminator.  */
   tic4x_insert_sym (name, value);
-  *input_line_pointer++ = c;
+  (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
 }
 
 /* Reset local labels.  */
-static void 
+static void
 tic4x_newblock (int x ATTRIBUTE_UNUSED)
 {
   dollar_label_clear ();
@@ -963,7 +939,7 @@ tic4x_newblock (int x ATTRIBUTE_UNUSED)
 
 /* .sect "section-name" [, value] */
 /* .sect ["]section-name[:subsection-name]["] [, value] */
-static void 
+static void
 tic4x_sect (int x ATTRIBUTE_UNUSED)
 {
   char c;
@@ -975,11 +951,11 @@ tic4x_sect (int x ATTRIBUTE_UNUSED)
   SKIP_WHITESPACE ();
   if (*input_line_pointer == '"')
     input_line_pointer++;
-  section_name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  c = get_symbol_name (&section_name); /* Get terminator.  */
+  if (c == '"')
+    c = * ++ input_line_pointer;
   input_line_pointer++;                /* Skip null symbol terminator.  */
-  name = xmalloc (input_line_pointer - section_name + 1);
-  strcpy (name, section_name);
+  name = xstrdup (section_name);
 
   /* TI C from version 5.0 allows a section name to contain a
      subsection name as well. The subsection name is separated by a
@@ -988,13 +964,16 @@ tic4x_sect (int x ATTRIBUTE_UNUSED)
      Volker Kuhlmann  <v.kuhlmann@elec.canterbury.ac.nz>.  */
   if (c == ':')
     {
-      c = get_symbol_end ();   /* Get terminator.  */
+      char *subname;
+      c = get_symbol_name (&subname);  /* Get terminator.  */
+      if (c == '"')
+       c = * ++ input_line_pointer;
       input_line_pointer++;    /* Skip null symbol terminator.  */
       as_warn (_(".sect: subsection name ignored"));
     }
 
   /* We might still have a '"' to discard, but the character after a
-     symbol name will be overwritten with a \0 by get_symbol_end()
+     symbol name will be overwritten with a \0 by get_symbol_name()
      [VK].  */
 
   if (c == ',')
@@ -1015,14 +994,14 @@ tic4x_sect (int x ATTRIBUTE_UNUSED)
       symbol_set_frag (line_label, frag_now);
     }
 
-  if (bfd_get_section_flags (stdoutput, seg) == SEC_NO_FLAGS)
+  if (bfd_section_flags (seg) == SEC_NO_FLAGS)
     {
-      if (!bfd_set_section_flags (stdoutput, seg, SEC_DATA))
+      if (!bfd_set_section_flags (seg, SEC_DATA))
        as_warn (_("Error setting flags for \"%s\": %s"), name,
                 bfd_errmsg (bfd_get_error ()));
     }
 
-  /* If the last character overwritten by get_symbol_end() was an
+  /* If the last character overwritten by get_symbol_name() was an
      end-of-line, we must restore it or the end of the line will not be
      recognised and scanning extends into the next line, stopping with
      an error (blame Volker Kuhlmann <v.kuhlmann@elec.canterbury.ac.nz>
@@ -1034,7 +1013,7 @@ tic4x_sect (int x ATTRIBUTE_UNUSED)
 }
 
 /* symbol[:] .set value  or  .set symbol, value */
-static void 
+static void
 tic4x_set (int x ATTRIBUTE_UNUSED)
 {
   symbolS *symbolP;
@@ -1045,8 +1024,9 @@ tic4x_set (int x ATTRIBUTE_UNUSED)
       char c;
       char *name;
 
-      name = input_line_pointer;
-      c = get_symbol_end ();   /* Get terminator.  */
+      c = get_symbol_name (&name);     /* Get terminator.  */
+      if (c == '"')
+       c = * ++ input_line_pointer;
       if (c != ',')
        {
          as_bad (_(".set syntax invalid\n"));
@@ -1064,7 +1044,7 @@ tic4x_set (int x ATTRIBUTE_UNUSED)
 }
 
 /* [symbol] .usect ["]section-name["], size-in-words [, alignment-flag] */
-static void 
+static void
 tic4x_usect (int x ATTRIBUTE_UNUSED)
 {
   char c;
@@ -1081,11 +1061,11 @@ tic4x_usect (int x ATTRIBUTE_UNUSED)
   SKIP_WHITESPACE ();
   if (*input_line_pointer == '"')
     input_line_pointer++;
-  section_name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  c = get_symbol_name (&section_name); /* Get terminator.  */
+  if (c == '"')
+    c = * ++ input_line_pointer;
   input_line_pointer++;                /* Skip null symbol terminator.  */
-  name = xmalloc (input_line_pointer - section_name + 1);
-  strcpy (name, section_name);
+  name = xstrdup (section_name);
 
   if (c == ',')
     input_line_pointer =
@@ -1117,7 +1097,7 @@ tic4x_usect (int x ATTRIBUTE_UNUSED)
       S_SET_VALUE (line_label, frag_now_fix ());
     }
   seg_info (seg)->bss = 1;     /* Uninitialised data.  */
-  if (!bfd_set_section_flags (stdoutput, seg, SEC_ALLOC))
+  if (!bfd_set_section_flags (seg, SEC_ALLOC))
     as_warn (_("Error setting flags for \"%s\": %s"), name,
             bfd_errmsg (bfd_get_error ()));
   tic4x_seg_alloc (name, seg, size, line_label);
@@ -1130,7 +1110,7 @@ tic4x_usect (int x ATTRIBUTE_UNUSED)
 }
 
 /* .version cpu-version.  */
-static void 
+static void
 tic4x_version (int x ATTRIBUTE_UNUSED)
 {
   offsetT temp;
@@ -1147,7 +1127,7 @@ tic4x_version (int x ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
 }
 
-static void 
+static void
 tic4x_init_regtable (void)
 {
   unsigned int i;
@@ -1165,7 +1145,7 @@ tic4x_init_regtable (void)
     }
 }
 
-static void 
+static void
 tic4x_init_symbols (void)
 {
   /* The TI tools accept case insensitive versions of these symbols,
@@ -1196,7 +1176,7 @@ tic4x_init_symbols (void)
      Source: TI: TMS320C3x/C4x Assembly Language Tools User's Guide,
      1997, SPRU035C, p. 3-17/3-18.  */
   tic4x_insert_sym (".REGPARM", tic4x_reg_args);
-  tic4x_insert_sym (".MEMPARM", !tic4x_reg_args);      
+  tic4x_insert_sym (".MEMPARM", !tic4x_reg_args);
   tic4x_insert_sym (".BIGMODEL", tic4x_big_model);
   tic4x_insert_sym (".C30INTERRUPT", 0);
   tic4x_insert_sym (".TMS320xx", tic4x_cpu == 0 ? 40 : tic4x_cpu);
@@ -1222,28 +1202,24 @@ tic4x_init_symbols (void)
 }
 
 /* Insert a new instruction template into hash table.  */
-static int 
+static void
 tic4x_inst_insert (const tic4x_inst_t *inst)
 {
   static char prev_name[16];
-  const char *retval = NULL;
 
   /* Only insert the first name if have several similar entries.  */
   if (!strcmp (inst->name, prev_name) || inst->name[0] == '\0')
-    return 1;
+    return;
 
-  retval = hash_insert (tic4x_op_hash, inst->name, (void *) inst);
-  if (retval != NULL)
-    fprintf (stderr, "internal error: can't hash `%s': %s\n",
-            inst->name, retval);
-  else
-    strcpy (prev_name, inst->name);
-  return retval == NULL;
+  if (str_hash_insert (tic4x_op_hash, inst->name, inst, 0) != NULL)
+    as_fatal (_("duplicate %s"), inst->name);
+
+  strcpy (prev_name, inst->name);
 }
 
 /* Make a new instruction template.  */
 static tic4x_inst_t *
-tic4x_inst_make (char *name, unsigned long opcode, char *args)
+tic4x_inst_make (const char *name, unsigned long opcode, const char *args)
 {
   static tic4x_inst_t *insts = NULL;
   static char *names = NULL;
@@ -1252,10 +1228,9 @@ tic4x_inst_make (char *name, unsigned long opcode, char *args)
   if (insts == NULL)
     {
       /* Allocate memory to store name strings.  */
-      names = (char *) xmalloc (sizeof (char) * 8192);
+      names = XNEWVEC (char, 8192);
       /* Allocate memory for additional insts.  */
-      insts = (tic4x_inst_t *)
-       xmalloc (sizeof (tic4x_inst_t) * 1024);
+      insts = XNEWVEC (tic4x_inst_t, 1024);
     }
   insts[iindex].name = names;
   insts[iindex].opcode = opcode;
@@ -1263,22 +1238,20 @@ tic4x_inst_make (char *name, unsigned long opcode, char *args)
   insts[iindex].args = args;
   iindex++;
 
-  do
+  while (*name)
     *names++ = *name++;
-  while (*name);
   *names++ = '\0';
 
   return &insts[iindex - 1];
 }
 
 /* Add instruction template, creating dynamic templates as required.  */
-static int 
+static void
 tic4x_inst_add (const tic4x_inst_t *insts)
 {
-  char *s = insts->name;
+  const char *s = insts->name;
   char *d;
   unsigned int i;
-  int ok = 1;
   char name[16];
 
   d = name;
@@ -1286,7 +1259,7 @@ tic4x_inst_add (const tic4x_inst_t *insts)
   /* We do not care about INSNs that is not a part of our
      oplevel setting.  */
   if ((insts->oplevel & tic4x_oplevel) == 0)
-    return ok;
+    return;
 
   while (1)
     {
@@ -1299,7 +1272,7 @@ tic4x_inst_add (const tic4x_inst_t *insts)
            {
              tic4x_inst_t *inst;
              int k = 0;
-             char *c = tic4x_conds[i].name;
+             const char *c = tic4x_conds[i].name;
              char *e = d;
 
              while (*c)
@@ -1310,8 +1283,8 @@ tic4x_inst_add (const tic4x_inst_t *insts)
              *e = '\0';
 
              /* If instruction found then have already processed it.  */
-             if (hash_find (tic4x_op_hash, name))
-               return 1;
+             if (str_hash_find (tic4x_op_hash, name))
+               return;
 
              do
                {
@@ -1320,18 +1293,17 @@ tic4x_inst_add (const tic4x_inst_t *insts)
                                         (*s == 'B' ? 16 : 23)),
                                        insts[k].args);
                  if (k == 0)   /* Save strcmp() with following func.  */
-                   ok &= tic4x_inst_insert (inst);
+                   tic4x_inst_insert (inst);
                  k++;
                }
              while (!strcmp (insts->name,
                              insts[k].name));
            }
-         return ok;
-         break;
+         return;
 
        case '\0':
-         return tic4x_inst_insert (insts);
-         break;
+         tic4x_inst_insert (insts);
+         return;
 
        default:
          *d++ = *s++;
@@ -1343,10 +1315,9 @@ tic4x_inst_add (const tic4x_inst_t *insts)
 /* 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 
+void
 md_begin (void)
 {
-  int ok = 1;
   unsigned int i;
 
   /* Setup the proper opcode level according to the
@@ -1378,21 +1349,18 @@ md_begin (void)
     tic4x_oplevel |= OP_IDLE2;
 
   /* Create hash table for mnemonics.  */
-  tic4x_op_hash = hash_new ();
+  tic4x_op_hash = str_htab_create ();
 
   /* Create hash table for asg pseudo.  */
-  tic4x_asg_hash = hash_new ();
+  tic4x_asg_hash = str_htab_create ();
 
   /* Add mnemonics to hash table, expanding conditional mnemonics on fly.  */
   for (i = 0; i < tic4x_num_insts; i++)
-    ok &= tic4x_inst_add (tic4x_insts + i);
+    tic4x_inst_add (tic4x_insts + i);
 
   /* Create dummy inst to avoid errors accessing end of table.  */
   tic4x_inst_make ("", 0, "");
 
-  if (!ok)
-    as_fatal ("Broken assembler.  No assembly attempted.");
-
   /* Add registers to symbol table.  */
   tic4x_init_regtable ();
 
@@ -1400,18 +1368,18 @@ md_begin (void)
   tic4x_init_symbols ();
 }
 
-void 
+void
 tic4x_end (void)
 {
-  bfd_set_arch_mach (stdoutput, bfd_arch_tic4x, 
+  bfd_set_arch_mach (stdoutput, bfd_arch_tic4x,
                     IS_CPU_TIC4X (tic4x_cpu) ? bfd_mach_tic4x : bfd_mach_tic3x);
 }
 
-static int 
+static int
 tic4x_indirect_parse (tic4x_operand_t *operand,
                      const tic4x_indirect_t *indirect)
 {
-  char *n = indirect->name;
+  const char *n = indirect->name;
   char *s = input_line_pointer;
   char *b;
   symbolS *symbolP;
@@ -1521,17 +1489,16 @@ tic4x_operand_parse (char *s, tic4x_operand_t *operand)
   input_line_pointer = s;
   SKIP_WHITESPACE ();
 
-  str = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  c = get_symbol_name (&str);  /* Get terminator.  */
   new_pointer = input_line_pointer;
-  if (strlen (str) && (entry = hash_find (tic4x_asg_hash, str)) != NULL)
+  if (strlen (str) && (entry = str_hash_find (tic4x_asg_hash, str)) != NULL)
     {
-      *input_line_pointer = c;
+      (void) restore_line_pointer (c);
       input_line_pointer = (char *) entry;
     }
   else
     {
-      *input_line_pointer = c;
+      (void) restore_line_pointer (c);
       input_line_pointer = str;
     }
 
@@ -1565,10 +1532,10 @@ tic4x_operand_parse (char *s, tic4x_operand_t *operand)
       /* Allow ori ^foo, ar0 to be equivalent to ldi .hi.foo, ar0  */
       /* WARNING : The TI C40 assembler cannot do this.  */
       else if (exp->X_op == O_symbol)
-       {
-         operand->mode = M_HI;
-         break;
-       }
+       operand->mode = M_HI;
+      else
+       as_bad (_("Expecting a constant value"));
+      break;
 
     case '#':
       input_line_pointer = tic4x_expression (++input_line_pointer, exp);
@@ -1588,14 +1555,11 @@ tic4x_operand_parse (char *s, tic4x_operand_t *operand)
       /* Allow ori foo, ar0 to be equivalent to ldi .lo.foo, ar0  */
       /* WARNING : The TI C40 assembler cannot do this.  */
       else if (exp->X_op == O_symbol)
-       {
-         operand->mode = M_IMMED;
-         break;
-       }
-
+       operand->mode = M_IMMED;
       else
        as_bad (_("Expecting a constant value"));
       break;
+
     case '\\':
 #endif
     case '@':
@@ -1670,7 +1634,7 @@ tic4x_operand_parse (char *s, tic4x_operand_t *operand)
   return new_pointer;
 }
 
-static int 
+static int
 tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
 {
   const char *args = inst->args;
@@ -1832,7 +1796,7 @@ tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
           if (!(operand->mode == M_REGISTER))
             break;
          reg = exp->X_add_number;
-         if ( (reg >= REG_R0 && reg <= REG_R7) 
+         if ( (reg >= REG_R0 && reg <= REG_R7)
                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
            INSERTU (opcode, reg, 7, 0);
          else
@@ -1872,7 +1836,7 @@ tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
          if (operand->mode != M_REGISTER)
            break;
          reg = exp->X_add_number;
-         if ( (reg >= REG_R0 && reg <= REG_R7) 
+         if ( (reg >= REG_R0 && reg <= REG_R7)
                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
            INSERTU (opcode, reg, 15, 8);
          else
@@ -2063,7 +2027,7 @@ tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
          if (operand->mode != M_REGISTER)
            break;
          reg = exp->X_add_number;
-         if ( (reg >= REG_R0 && reg <= REG_R7) 
+         if ( (reg >= REG_R0 && reg <= REG_R7)
                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
            INSERTU (opcode, reg, 15, 0);
          else
@@ -2085,7 +2049,7 @@ tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
          if (operand->mode != M_REGISTER)
            break;
          reg = exp->X_add_number;
-         if ( (reg >= REG_R0 && reg <= REG_R7) 
+         if ( (reg >= REG_R0 && reg <= REG_R7)
                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
            INSERTU (opcode, reg, 20, 16);
          else
@@ -2211,7 +2175,7 @@ tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
                }
              else if (exp->X_add_number < 32 && IS_CPU_TIC3X (tic4x_cpu))
                {
-                 INSERTU (opcode, exp->X_add_number | 0x20, 4, 0);
+                 INSERTU (opcode, exp->X_add_number | 0x20, 5, 0);
                  continue;
                }
              else
@@ -2344,7 +2308,7 @@ tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
 static void
 tic4x_insn_check (tic4x_insn_t *tinsn)
 {
-  
+
   if (!strcmp (tinsn->name, "lda"))
     {
       if (tinsn->num_operands < 2 || tinsn->num_operands > 2)
@@ -2362,17 +2326,17 @@ tic4x_insn_check (tic4x_insn_t *tinsn)
            || !strcmp (tinsn->name, "ldf1_ldf2")
            || !strcmp (tinsn->name, "ldf2_ldf1") )
     {
-      if (tinsn->num_operands < 4 && tinsn->num_operands > 5 )
+      if (tinsn->num_operands < 4 || tinsn->num_operands > 5)
         as_fatal ("Illegal internal %s insn definition", tinsn->name);
-      
+
       if (tinsn->operands[1].mode == M_REGISTER
          && tinsn->operands[tinsn->num_operands-1].mode == M_REGISTER
          && tinsn->operands[1].expr.X_add_number == tinsn->operands[tinsn->num_operands-1].expr.X_add_number )
-        as_warn (_("Equal parallell destination registers, one result will be discarded"));
+        as_warn (_("Equal parallel destination registers, one result will be discarded"));
     }
 }
 
-static void 
+static void
 tic4x_insn_output (tic4x_insn_t *tinsn)
 {
   char *dst;
@@ -2397,7 +2361,7 @@ tic4x_insn_output (tic4x_insn_t *tinsn)
 }
 
 /* Parse the operands.  */
-static int 
+static int
 tic4x_operands_parse (char *s, tic4x_operand_t *operands, int num_operands)
 {
   if (!*s)
@@ -2418,13 +2382,14 @@ tic4x_operands_parse (char *s, tic4x_operand_t *operands, int num_operands)
 /* Assemble a single instruction.  Its label has already been handled
    by the generic front end.  We just parse mnemonic and operands, and
    produce the bytes of data and relocation.  */
-void 
+void
 md_assemble (char *str)
 {
   int ok = 0;
   char *s;
   int i;
   int parsed = 0;
+  size_t len;
   tic4x_inst_t *inst;          /* Instruction template.  */
   tic4x_inst_t *first_inst;
 
@@ -2434,7 +2399,7 @@ md_assemble (char *str)
       s = str;
       while (*s && *s != '|')
         s++;
-      
+
       if (*s && s[1]=='|')
         {
           if(insn->parallel)
@@ -2444,7 +2409,7 @@ md_assemble (char *str)
               insn->in_use = 0;
               return;
             }
-          
+
           /* Lets take care of the first part of the parallel insn */
           *s++ = 0;
           md_assemble(str);
@@ -2453,7 +2418,7 @@ md_assemble (char *str)
           /* .. and let the second run though here */
         }
     }
-  
+
   if (str && insn->parallel)
     {
       /* Find mnemonic (second part of parallel instruction).  */
@@ -2461,10 +2426,10 @@ md_assemble (char *str)
       /* Skip past instruction mnemonic.  */
       while (*s && *s != ' ')
        s++;
-      if (*s)                  /* Null terminate for hash_find.  */
+      if (*s)                  /* Null terminate for str_hash_find.  */
        *s++ = '\0';            /* and skip past null.  */
-      strcat (insn->name, "_");
-      strncat (insn->name, str, TIC4X_NAME_MAX - strlen (insn->name));
+      len = strlen (insn->name);
+      snprintf (insn->name + len, TIC4X_NAME_MAX - len, "_%s", str);
 
       insn->operands[insn->num_operands++].mode = M_PARALLEL;
 
@@ -2482,7 +2447,7 @@ md_assemble (char *str)
   if (insn->in_use)
     {
       if ((insn->inst = (struct tic4x_inst *)
-          hash_find (tic4x_op_hash, insn->name)) == NULL)
+          str_hash_find (tic4x_op_hash, insn->name)) == NULL)
        {
          as_bad (_("Unknown opcode `%s'."), insn->name);
          insn->parallel = 0;
@@ -2501,7 +2466,8 @@ md_assemble (char *str)
                 first_inst = inst;
               ok = 0;
             }
-      } while (!ok && !strcmp (inst->name, inst[1].name) && inst++);
+       }
+      while (!ok && !strcmp (inst->name, inst[1].name) && inst++);
 
       if (ok > 0)
         {
@@ -2524,9 +2490,10 @@ md_assemble (char *str)
       s = str;
       while (*s && *s != ' ')  /* Skip past instruction mnemonic.  */
        s++;
-      if (*s)                  /* Null terminate for hash_find.  */
+      if (*s)                  /* Null terminate for str_hash_find.  */
        *s++ = '\0';            /* and skip past null.  */
-      strncpy (insn->name, str, TIC4X_NAME_MAX - 3);
+      strncpy (insn->name, str, TIC4X_NAME_MAX - 1);
+      insn->name[TIC4X_NAME_MAX - 1] = '\0';
 
       if ((i = tic4x_operands_parse (s, insn->operands, 0)) < 0)
        {
@@ -2555,7 +2522,7 @@ tic4x_cleanup (void)
    of chars emitted is stored in *sizeP.  An error message is
    returned, or NULL on OK.  */
 
-char *
+const char *
 md_atof (int type, char *litP, int *sizeP)
 {
   int prec;
@@ -2628,7 +2595,7 @@ md_atof (int type, char *litP, int *sizeP)
   return NULL;
 }
 
-void 
+void
 md_apply_fix (fixS *fixP, valueT *value, segT seg ATTRIBUTE_UNUSED)
 {
   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
@@ -2651,9 +2618,11 @@ md_apply_fix (fixS *fixP, valueT *value, segT seg ATTRIBUTE_UNUSED)
     {
     case BFD_RELOC_32:
       buf[3] = val >> 24;
+      /* Fall through.  */
     case BFD_RELOC_24:
     case BFD_RELOC_24_PCREL:
       buf[2] = val >> 16;
+      /* Fall through.  */
     case BFD_RELOC_16:
     case BFD_RELOC_16_PCREL:
     case BFD_RELOC_LO16:
@@ -2672,7 +2641,7 @@ md_apply_fix (fixS *fixP, valueT *value, segT seg ATTRIBUTE_UNUSED)
 }
 
 /* Should never be called for tic4x.  */
-void 
+void
 md_convert_frag (bfd *headers ATTRIBUTE_UNUSED,
                 segT sec ATTRIBUTE_UNUSED,
                 fragS *fragP ATTRIBUTE_UNUSED)
@@ -2713,7 +2682,7 @@ md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
 
 
 int
-md_parse_option (int c, char *arg)
+md_parse_option (int c, const char *arg)
 {
   switch (c)
     {
@@ -2731,24 +2700,28 @@ md_parse_option (int c, char *arg)
 
     case 'b':
       as_warn (_("Option -b is depreciated, please use -mbig"));
+      /* Fall through.  */
     case OPTION_BIG:             /* big model */
       tic4x_big_model = 1;
       break;
 
     case 'p':
       as_warn (_("Option -p is depreciated, please use -mmemparm"));
+      /* Fall through.  */
     case OPTION_MEMPARM:         /* push args */
       tic4x_reg_args = 0;
       break;
 
-    case 'r':                  
+    case 'r':
       as_warn (_("Option -r is depreciated, please use -mregparm"));
+      /* Fall through.  */
     case OPTION_REGPARM:        /* register args */
       tic4x_reg_args = 1;
       break;
 
     case 's':
       as_warn (_("Option -s is depreciated, please use -msmall"));
+      /* Fall through.  */
     case OPTION_SMALL:         /* small model */
       tic4x_big_model = 0;
       break;
@@ -2800,7 +2773,7 @@ md_show_usage (FILE *stream)
 /* This is called when a line is unrecognized.  This is used to handle
    definitions of TI C3x tools style local labels $n where n is a single
    decimal digit.  */
-int 
+int
 tic4x_unrecognized_line (int c)
 {
   int lab;
@@ -2877,7 +2850,7 @@ md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
   return size;                 /* Byte (i.e., 32-bit) alignment is fine?  */
 }
 
-static int 
+static int
 tic4x_pc_offset (unsigned int op)
 {
   /* Determine the PC offset for a C[34]x instruction.
@@ -2946,7 +2919,7 @@ md_pcrel_from (fixS *fixP)
   unsigned int op;
 
   buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
-  op = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+  op = ((unsigned) buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
 
   return ((fixP->fx_where + fixP->fx_frag->fr_address) >> 2) +
     tic4x_pc_offset (op);
@@ -2954,7 +2927,7 @@ md_pcrel_from (fixS *fixP)
 
 /* Fill the alignment area with NOP's on .text, unless fill-data
    was specified. */
-int 
+int
 tic4x_do_align (int alignment,
                const char *fill,
                int len,
@@ -2962,14 +2935,12 @@ tic4x_do_align (int alignment,
 {
   /* Because we are talking lwords, not bytes, adjust alignment to do words */
   alignment += 2;
-  
+
   if (alignment != 0 && !need_pass_2)
     {
       if (fill == NULL)
         {
-         /* FIXME: subseg_text_p tests SEC_CODE which isn't in allowed
-            section flags.  See bfd/coff-tic4x.c target vecs.  */
-          if (1 || subseg_text_p (now_seg))
+          if (subseg_text_p (now_seg))
            {
              char nop[4];
 
@@ -2984,13 +2955,13 @@ tic4x_do_align (int alignment,
       else
        frag_align_pattern (alignment, fill, len, max);
     }
-  
+
   /* Return 1 to skip the default alignment function */
   return 1;
 }
 
 /* Look for and remove parallel instruction operator ||.  */
-void 
+void
 tic4x_start_line (void)
 {
   char *s = input_line_pointer;
@@ -3023,9 +2994,9 @@ tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixP)
 {
   arelent *reloc;
 
-  reloc = (arelent *) xmalloc (sizeof (arelent));
+  reloc = XNEW (arelent);
 
-  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  reloc->sym_ptr_ptr = XNEW (asymbol *);
   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
   reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
   reloc->address /= OCTETS_PER_BYTE;