Don't include libbfd.h outside of bfd, part 1
[deliverable/binutils-gdb.git] / gas / config / tc-bfin.c
index d9888907d0a80bd079f235211a071adf85d0bcc1..1dc88fce0667f0b0db18fd5b295a6a87308f0bd0 100644 (file)
@@ -1,6 +1,5 @@
 /* tc-bfin.c -- Assembler for the ADI Blackfin.
-   Copyright 2005, 2006, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 2005-2016 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -27,7 +26,6 @@
 #ifdef OBJ_ELF
 #include "dwarf2dbg.h"
 #endif
-#include "libbfd.h"
 #include "elf/common.h"
 #include "elf/bfin.h"
 
@@ -85,7 +83,7 @@ bfin_pic_ptr (int nbytes)
   do
     {
       bfd_reloc_code_real_type reloc_type = BFD_RELOC_BFIN_FUNCDESC;
-      
+
       if (strncasecmp (input_line_pointer, "funcdesc(", 9) == 0)
        {
          input_line_pointer += 9;
@@ -112,7 +110,7 @@ bfin_pic_ptr (int nbytes)
 static void
 bfin_s_bss (int ignore ATTRIBUTE_UNUSED)
 {
-  register int temp;
+  int temp;
 
   temp = get_absolute_expression ();
   subseg_set (bss_section, (subsegT) temp);
@@ -136,7 +134,7 @@ const pseudo_typeS md_pseudo_table[] = {
 };
 
 /* Characters that are used to denote comments and line separators. */
-const char comment_chars[] = "";
+const char comment_chars[] = "#";
 const char line_comment_chars[] = "#";
 const char line_separator_chars[] = ";";
 
@@ -151,6 +149,8 @@ const char FLT_CHARS[] = "fFdDxX";
 typedef enum bfin_cpu_type
 {
   BFIN_CPU_UNKNOWN,
+  BFIN_CPU_BF504,
+  BFIN_CPU_BF506,
   BFIN_CPU_BF512,
   BFIN_CPU_BF514,
   BFIN_CPU_BF516,
@@ -179,7 +179,8 @@ typedef enum bfin_cpu_type
   BFIN_CPU_BF548M,
   BFIN_CPU_BF549,
   BFIN_CPU_BF549M,
-  BFIN_CPU_BF561
+  BFIN_CPU_BF561,
+  BFIN_CPU_BF592,
 } bfin_cpu_t;
 
 bfin_cpu_t bfin_cpu_type = BFIN_CPU_UNKNOWN;
@@ -200,15 +201,23 @@ struct bfin_cpu
 
 struct bfin_cpu bfin_cpus[] =
 {
+  {"bf504", BFIN_CPU_BF504, 0x0000, AC_05000074},
+
+  {"bf506", BFIN_CPU_BF506, 0x0000, AC_05000074},
+
+  {"bf512", BFIN_CPU_BF512, 0x0002, AC_05000074},
   {"bf512", BFIN_CPU_BF512, 0x0001, AC_05000074},
   {"bf512", BFIN_CPU_BF512, 0x0000, AC_05000074},
 
+  {"bf514", BFIN_CPU_BF514, 0x0002, AC_05000074},
   {"bf514", BFIN_CPU_BF514, 0x0001, AC_05000074},
   {"bf514", BFIN_CPU_BF514, 0x0000, AC_05000074},
 
+  {"bf516", BFIN_CPU_BF516, 0x0002, AC_05000074},
   {"bf516", BFIN_CPU_BF516, 0x0001, AC_05000074},
   {"bf516", BFIN_CPU_BF516, 0x0000, AC_05000074},
 
+  {"bf518", BFIN_CPU_BF518, 0x0002, AC_05000074},
   {"bf518", BFIN_CPU_BF518, 0x0001, AC_05000074},
   {"bf518", BFIN_CPU_BF518, 0x0000, AC_05000074},
 
@@ -275,30 +284,35 @@ struct bfin_cpu bfin_cpus[] =
 
   {"bf542m", BFIN_CPU_BF542M, 0x0003, AC_05000074},
 
+  {"bf542", BFIN_CPU_BF542, 0x0004, AC_05000074},
   {"bf542", BFIN_CPU_BF542, 0x0002, AC_05000074},
   {"bf542", BFIN_CPU_BF542, 0x0001, AC_05000074},
   {"bf542", BFIN_CPU_BF542, 0x0000, AC_05000074},
 
   {"bf544m", BFIN_CPU_BF544M, 0x0003, AC_05000074},
 
+  {"bf544", BFIN_CPU_BF544, 0x0004, AC_05000074},
   {"bf544", BFIN_CPU_BF544, 0x0002, AC_05000074},
   {"bf544", BFIN_CPU_BF544, 0x0001, AC_05000074},
   {"bf544", BFIN_CPU_BF544, 0x0000, AC_05000074},
 
   {"bf547m", BFIN_CPU_BF547M, 0x0003, AC_05000074},
 
+  {"bf547", BFIN_CPU_BF547, 0x0004, AC_05000074},
   {"bf547", BFIN_CPU_BF547, 0x0002, AC_05000074},
   {"bf547", BFIN_CPU_BF547, 0x0001, AC_05000074},
   {"bf547", BFIN_CPU_BF547, 0x0000, AC_05000074},
 
   {"bf548m", BFIN_CPU_BF548M, 0x0003, AC_05000074},
 
+  {"bf548", BFIN_CPU_BF548, 0x0004, AC_05000074},
   {"bf548", BFIN_CPU_BF548, 0x0002, AC_05000074},
   {"bf548", BFIN_CPU_BF548, 0x0001, AC_05000074},
   {"bf548", BFIN_CPU_BF548, 0x0000, AC_05000074},
 
   {"bf549m", BFIN_CPU_BF549M, 0x0003, AC_05000074},
 
+  {"bf549", BFIN_CPU_BF549, 0x0004, AC_05000074},
   {"bf549", BFIN_CPU_BF549, 0x0002, AC_05000074},
   {"bf549", BFIN_CPU_BF549, 0x0001, AC_05000074},
   {"bf549", BFIN_CPU_BF549, 0x0000, AC_05000074},
@@ -307,7 +321,8 @@ struct bfin_cpu bfin_cpus[] =
   {"bf561", BFIN_CPU_BF561, 0x0003, AC_05000074},
   {"bf561", BFIN_CPU_BF561, 0x0002, AC_05000074},
 
-  {NULL, 0, 0, 0}
+  {"bf592", BFIN_CPU_BF592, 0x0001, AC_05000074},
+  {"bf592", BFIN_CPU_BF592, 0x0000, AC_05000074},
 };
 
 /* Define bfin-specific command-line options (there are none). */
@@ -330,7 +345,7 @@ size_t md_longopts_size = sizeof (md_longopts);
 
 
 int
-md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
+md_parse_option (int c ATTRIBUTE_UNUSED, const char *arg ATTRIBUTE_UNUSED)
 {
   switch (c)
     {
@@ -339,23 +354,22 @@ md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
 
     case OPTION_MCPU:
       {
-       const char *p, *q;
-       int i;
+       const char *q;
+       unsigned int i;
 
-       i = 0;
-       while ((p = bfin_cpus[i].name) != NULL)
+       for (i = 0; i < ARRAY_SIZE (bfin_cpus); i++)
          {
+           const char *p = bfin_cpus[i].name;
            if (strncmp (arg, p, strlen (p)) == 0)
              break;
-           i++;
          }
 
-       if (p == NULL)
+       if (i == ARRAY_SIZE (bfin_cpus))
          as_fatal ("-mcpu=%s is not valid", arg);
 
        bfin_cpu_type = bfin_cpus[i].type;
 
-       q = arg + strlen (p);
+       q = arg + strlen (bfin_cpus[i].name);
 
        if (*q == '\0')
          {
@@ -367,7 +381,8 @@ md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
        else if (strcmp (q, "-any") == 0)
          {
            bfin_si_revision = 0xffff;
-           while (bfin_cpus[i].type == bfin_cpu_type)
+           while (i < ARRAY_SIZE (bfin_cpus)
+                  && bfin_cpus[i].type == bfin_cpu_type)
              {
                bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
                i++;
@@ -390,11 +405,13 @@ md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
 
            bfin_si_revision = (si_major << 8) | si_minor;
 
-           while (bfin_cpus[i].type == bfin_cpu_type
+           while (i < ARRAY_SIZE (bfin_cpus)
+                  && bfin_cpus[i].type == bfin_cpu_type
                   && bfin_cpus[i].si_revision != bfin_si_revision)
              i++;
 
-           if (bfin_cpus[i].type != bfin_cpu_type)
+           if (i == ARRAY_SIZE (bfin_cpus)
+               || bfin_cpus[i].type != bfin_cpu_type)
              goto invalid_silicon_revision;
 
            bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
@@ -418,14 +435,17 @@ md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
 }
 
 void
-md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
+md_show_usage (FILE * stream)
 {
-  fprintf (stream, _(" BFIN specific command line options:\n"));
+  fprintf (stream, _(" Blackfin specific assembler options:\n"));
+  fprintf (stream, _("  -mcpu=<cpu[-sirevision]> specify the name of the target CPU\n"));
+  fprintf (stream, _("  -mfdpic                  assemble for the FDPIC ABI\n"));
+  fprintf (stream, _("  -mno-fdpic/-mnopic       disable -mfdpic\n"));
 }
 
 /* Perform machine-specific initializations.  */
 void
-md_begin ()
+md_begin (void)
 {
   /* Set the ELF flags if desired. */
   if (bfin_flags)
@@ -438,7 +458,7 @@ md_begin ()
   /* Ensure that lines can begin with '(', for multiple
      register stack pops. */
   lex_type ['('] = LEX_BEGIN_NAME;
-  
+
 #ifdef OBJ_ELF
   record_alignment (text_section, 2);
   record_alignment (data_section, 2);
@@ -451,7 +471,7 @@ md_begin ()
 #ifdef DEBUG
   extern int debug_codeselection;
   debug_codeselection = 1;
-#endif 
+#endif
 
   last_insn_size = 0;
 }
@@ -464,20 +484,18 @@ void
 md_assemble (char *line)
 {
   char *toP = 0;
-  extern char *current_inputline;
   int size, insn_size;
   struct bfin_insn *tmp_insn;
   size_t len;
   static size_t buffer_len = 0;
+  static char *current_inputline;
   parse_state state;
 
   len = strlen (line);
   if (len + 2 > buffer_len)
     {
-      if (buffer_len > 0)
-       free (current_inputline);
       buffer_len = len + 40;
-      current_inputline = xmalloc (buffer_len);
+      current_inputline = XRESIZEVEC (char, current_inputline, buffer_len);
     }
   memcpy (current_inputline, line, len);
   current_inputline[len] = ';';
@@ -770,16 +788,14 @@ md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED)
 
 /* Round up a section size to the appropriate boundary.  */
 valueT
-md_section_align (segment, size)
-     segT segment;
-     valueT size;
+md_section_align (segT segment, valueT size)
 {
   int boundary = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << boundary) - 1) & (-1 << boundary));
+  return ((size + (1 << boundary) - 1) & -(1 << boundary));
 }
 
 
-char *
+const char *
 md_atof (int type, char * litP, int * sizeP)
 {
   return ieee_md_atof (type, litP, sizeP, FALSE);
@@ -790,14 +806,12 @@ md_atof (int type, char * litP, int * sizeP)
    then it is done here.  */
 
 arelent *
-tc_gen_reloc (seg, fixp)
-     asection *seg ATTRIBUTE_UNUSED;
-     fixS *fixp;
+tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
 {
   arelent *reloc;
 
-  reloc                      = (arelent *) xmalloc (sizeof (arelent));
-  reloc->sym_ptr_ptr  = (asymbol **) xmalloc (sizeof (asymbol *));
+  reloc                      = XNEW (arelent);
+  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;
 
@@ -823,9 +837,7 @@ tc_gen_reloc (seg, fixp)
     given a PC relative reloc.  */
 
 long
-md_pcrel_from_section (fixP, sec)
-     fixS *fixP;
-     segT sec;
+md_pcrel_from_section (fixS *fixP, segT sec)
 {
   if (fixP->fx_addsy != (symbolS *) NULL
       && (!S_IS_DEFINED (fixP->fx_addsy)
@@ -841,11 +853,11 @@ md_pcrel_from_section (fixP, sec)
 /* Return true if the fix can be handled by GAS, false if it must
    be passed through to the linker.  */
 
-bfd_boolean  
+bfd_boolean
 bfin_fix_adjustable (fixS *fixP)
-{         
+{
   switch (fixP->fx_r_type)
-    {     
+    {
   /* Adjust_reloc_syms doesn't know about the GOT.  */
     case BFD_RELOC_BFIN_GOT:
     case BFD_RELOC_BFIN_PLTPC:
@@ -853,10 +865,10 @@ bfin_fix_adjustable (fixS *fixP)
     case BFD_RELOC_VTABLE_INHERIT:
     case BFD_RELOC_VTABLE_ENTRY:
       return 0;
-        
+
     default:
       return 1;
-    }     
+    }
 }
 
 /* Special extra functions that help bfin-parse.y perform its job.  */
@@ -916,7 +928,7 @@ note_reloc2 (INSTR_T code, const char *symbol, int reloc, int value, int pcrel)
 INSTR_T
 gencode (unsigned long x)
 {
-  INSTR_T cell = obstack_alloc (&mempool, sizeof (struct bfin_insn));
+  INSTR_T cell = XOBNEW (&mempool, struct bfin_insn);
   memset (cell, 0, sizeof (struct bfin_insn));
   cell->value = (x);
   return cell;
@@ -927,7 +939,7 @@ int ninsns;
 int count_insns;
 
 static void *
-allocate (int n)
+allocate (size_t n)
 {
   return obstack_alloc (&mempool, n);
 }
@@ -1803,6 +1815,16 @@ bfin_gen_pseudodbg_assert (int dbgop, REG_T regtest, int expected)
   return GEN_OPCODE32 ();
 }
 
+INSTR_T
+bfin_gen_pseudochr (int ch)
+{
+  INIT (PseudoChr);
+
+  ASSIGN (ch);
+
+  return GEN_OPCODE16 ();
+}
+
 /* Multiple instruction generation.  */
 
 INSTR_T
@@ -1847,6 +1869,7 @@ bfin_gen_loop (Expr_Node *exp, REG_T reg, int rop, REG_T preg)
   char *lbeginsym, *lendsym;
   Expr_Node_Value lbeginval, lendval;
   Expr_Node *lbegin, *lend;
+  symbolS *sym;
 
   loopsym = exp->value.s_value;
   lbeginsym = (char *) xmalloc (strlen (loopsym) + strlen ("__BEGIN") + 5);
@@ -1869,9 +1892,20 @@ bfin_gen_loop (Expr_Node *exp, REG_T reg, int rop, REG_T preg)
   lbegin = Expr_Node_Create (Expr_Node_Reloc, lbeginval, NULL, NULL);
   lend   = Expr_Node_Create (Expr_Node_Reloc, lendval, NULL, NULL);
 
-  symbol_remove (symbol_find (loopsym), &symbol_rootP, &symbol_lastP);
+  sym = symbol_find(loopsym);
+  if (!S_IS_LOCAL (sym) || (S_IS_LOCAL (sym) && !symbol_used_p (sym)))
+    symbol_remove (sym, &symbol_rootP, &symbol_lastP);
 
-  return bfin_gen_loopsetup(lbegin, reg, rop, lend, preg);
+  return bfin_gen_loopsetup (lbegin, reg, rop, lend, preg);
+}
+
+void
+bfin_loop_attempt_create_label (Expr_Node *exp, int is_begin)
+{
+  char *name;
+  name = fb_label_name (exp->value.i_value, is_begin);
+  exp->value.s_value = xstrdup (name);
+  exp->type = Expr_Node_Reloc;
 }
 
 void
@@ -1927,9 +1961,9 @@ bfin_eol_in_insn (char *line)
 }
 
 bfd_boolean
-bfin_start_label (char *s, char *ptr)
+bfin_start_label (char *s)
 {
-  while (s != ptr)
+  while (*s != 0)
     {
       if (*s == '(' || *s == '[')
        return FALSE;
@@ -1937,7 +1971,7 @@ bfin_start_label (char *s, char *ptr)
     }
 
   return TRUE;
-} 
+}
 
 int
 bfin_force_relocation (struct fix *fixp)
@@ -2430,7 +2464,7 @@ decode_dsp32alu_0 (int iw0, int iw1)
 
   else if (aop == 0 && aopcde == 24)
     return DREG_MASK (dst0);
-  else if (aop == 1 && aopcde == 24) 
+  else if (aop == 1 && aopcde == 24)
     return DREG_MASK (dst0) | DREG_MASK (dst1);
   else if (aopcde == 13)
     return DREG_MASK (dst0) | DREG_MASK (dst1);
This page took 0.028986 seconds and 4 git commands to generate.