Update copyright years
[deliverable/binutils-gdb.git] / gas / config / tc-tic6x.c
index 73bea632651156797341b8c2fc5f954394292ea7..1ffbb685fbd52e55c887ec8fbb6e2852555157c2 100644 (file)
@@ -1,6 +1,5 @@
 /* TI C6X assembler.
-   Copyright 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 2010-2014 Free Software Foundation, Inc.
    Contributed by Joseph Myers <joseph@codesourcery.com>
                  Bernd Schmidt  <bernds@codesourcery.com>
 
@@ -693,7 +692,7 @@ static bfd_boolean tic6x_attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
 static void
 s_tic6x_c6xabi_attribute (int ignored ATTRIBUTE_UNUSED)
 {
-  int tag = s_vendor_attribute (OBJ_ATTR_PROC);
+  int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
 
   if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
     tic6x_attributes_set_explicitly[tag] = TRUE;
@@ -790,12 +789,12 @@ md_begin (void)
 
   /* We must construct a fake section similar to bfd_com_section
      but with the name .scommon.  */
-  scom_section                = bfd_com_section;
+  scom_section                = *bfd_com_section_ptr;
   scom_section.name           = ".scommon";
   scom_section.output_section = & scom_section;
   scom_section.symbol         = & scom_symbol;
   scom_section.symbol_ptr_ptr = & scom_section.symbol;
-  scom_symbol                 = * bfd_com_section.symbol;
+  scom_symbol                 = * bfd_com_section_ptr->symbol;
   scom_symbol.name            = ".scommon";
   scom_symbol.section         = & scom_section;
 }
@@ -1738,6 +1737,8 @@ static const tic6x_operator_table tic6x_operators[] = {
   { "dpr_hword", O_dpr_hword },
 #define O_dpr_word O_md6
   { "dpr_word", O_dpr_word },
+#define O_pcr_offset O_md7
+  { "pcr_offset", O_pcr_offset }
 };
 
 /* Parse a name in some machine-specific way.  Used on C6X to handle
@@ -1752,7 +1753,7 @@ tic6x_parse_name (const char *name, expressionS *exprP,
   const char *inner_name;
   unsigned int i;
   operatorT op = O_illegal;
-  symbolS *sym;
+  symbolS *sym, *op_sym = NULL;
 
   if (*name != '$')
     return 0;
@@ -1791,6 +1792,37 @@ tic6x_parse_name (const char *name, expressionS *exprP,
   name_end = p;
   skip_whitespace (p);
 
+  if (op == O_pcr_offset)
+    {
+      char *op_name_start, *op_name_end;
+
+      if (*p != ',')
+       {
+         *input_line_pointer = 0;
+         return 0;
+       }
+      p++;
+      skip_whitespace (p);
+
+      if (!is_name_beginner (*p))
+       {
+         *input_line_pointer = 0;
+         return 0;
+       }
+
+      op_name_start = p;
+      p++;
+      while (is_part_of_name (*p))
+       p++;
+      op_name_end = p;
+      skip_whitespace (p);
+
+      c = *op_name_end;
+      *op_name_end = 0;
+      op_sym = symbol_find_or_make (op_name_start);
+      *op_name_end = c;
+    }
+
   if (*p != ')')
     {
       *input_line_pointer = 0;
@@ -1815,7 +1847,7 @@ tic6x_parse_name (const char *name, expressionS *exprP,
   exprP->X_op = op;
   exprP->X_add_symbol = sym;
   exprP->X_add_number = 0;
-  exprP->X_op_symbol = NULL;
+  exprP->X_op_symbol = op_sym;
   exprP->X_md = 0;
 
   return 1;
@@ -1833,6 +1865,7 @@ tic6x_fix_new_exp (fragS *frag, int where, int size, expressionS *exp,
                   bfd_boolean fix_adda)
 {
   bfd_reloc_code_real_type new_reloc = BFD_RELOC_UNUSED;
+  symbolS *subsy = NULL;
   fixS *fix;
 
   switch (exp->X_op)
@@ -1935,6 +1968,25 @@ tic6x_fix_new_exp (fragS *frag, int where, int size, expressionS *exp,
        }
       break;
 
+    case O_pcr_offset:
+      subsy = exp->X_op_symbol;
+      switch (r_type)
+       {
+       case BFD_RELOC_C6000_ABS_S16:
+       case BFD_RELOC_C6000_ABS_L16:
+         new_reloc = BFD_RELOC_C6000_PCR_L16;
+         break;
+
+       case BFD_RELOC_C6000_ABS_H16:
+         new_reloc = BFD_RELOC_C6000_PCR_H16;
+         break;
+
+       default:
+         as_bad (_("$PCR_OFFSET not supported in this context"));
+         return;
+       }
+      break;
+
     case O_symbol:
       break;
 
@@ -1952,6 +2004,7 @@ tic6x_fix_new_exp (fragS *frag, int where, int size, expressionS *exp,
   else
     fix = fix_new (frag, where, size, exp->X_add_symbol, exp->X_add_number,
                   pcrel, new_reloc);
+  fix->tc_fix_data.fix_subsy = subsy;
   fix->tc_fix_data.fix_adda = fix_adda;
 }
 
@@ -1991,6 +2044,7 @@ void
 tic6x_init_fix_data (fixS *fixP)
 {
   fixP->tc_fix_data.fix_adda = FALSE;
+  fixP->tc_fix_data.fix_subsy = NULL;
 }
 
 /* Return true if the fix can be handled by GAS, false if it must
@@ -2011,6 +2065,10 @@ tic6x_fix_adjustable (fixS *fixP)
     case BFD_RELOC_C6000_PREL31:
       return 0;
 
+    case BFD_RELOC_C6000_PCR_H16:
+    case BFD_RELOC_C6000_PCR_L16:
+      return 0;
+      
     default:
       return 1;
     }
@@ -2426,7 +2484,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
          fldd = tic6x_field_from_fmt (fmt, opct->fixed_fields[fld].field_id);
          if (fldd == NULL)
            abort ();
-         opcode_value |= opct->fixed_fields[fld].min_val << fldd->low_pos;
+         opcode_value |= opct->fixed_fields[fld].min_val << fldd->bitfields[0].low_pos;
        }
     }
 
@@ -2457,7 +2515,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
          ucexp = operands[opno].value.exp;
        unsigned_constant:
          if (ucexp.X_add_number < 0
-             || ucexp.X_add_number >= (1 << fldd->width))
+             || ucexp.X_add_number >= (1 << fldd->bitfields[0].width))
            {
              if (print_errors)
                as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
@@ -2476,7 +2534,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
              value = 0;
              /* Opcode table should not permit non-constants without
                 a known relocation for them.  */
-             if (fldd->low_pos != 7 || fldd->width != 16)
+             if (fldd->bitfields[0].low_pos != 7 || fldd->bitfields[0].width != 16)
                abort ();
              *fix_needed = TRUE;
              *fix_exp = &operands[opno].value.exp;
@@ -2487,8 +2545,8 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
            }
          sign_value = SEXT (operands[opno].value.exp.X_add_number);
        signed_constant:
-         if (sign_value < -(1 << (fldd->width - 1))
-             || (sign_value >= (1 << (fldd->width - 1))))
+         if (sign_value < -(1 << (fldd->bitfields[0].width - 1))
+             || (sign_value >= (1 << (fldd->bitfields[0].width - 1))))
            {
              if (print_errors)
                as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
@@ -2496,8 +2554,8 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
              *ok = FALSE;
              return 0;
            }
-         value = sign_value + (1 << (fldd->width - 1));
-         value ^= (1 << (fldd->width - 1));
+         value = sign_value + (1 << (fldd->bitfields[0].width - 1));
+         value ^= (1 << (fldd->bitfields[0].width - 1));
          break;
 
        case tic6x_coding_ucst_minus_one:
@@ -2506,7 +2564,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
          if (operands[opno].value.exp.X_op != O_constant)
            abort ();
          if (operands[opno].value.exp.X_add_number <= 0
-             || operands[opno].value.exp.X_add_number > (1 << fldd->width))
+             || operands[opno].value.exp.X_add_number > (1 << fldd->bitfields[0].width))
            {
              if (print_errors)
                as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
@@ -2578,7 +2636,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
          value = 0;
          /* Opcode table should not use this encoding without a known
             relocation.  */
-         if (fldd->low_pos != 8 || fldd->width != 15)
+         if (fldd->bitfields[0].low_pos != 8 || fldd->bitfields[0].width != 15)
            abort ();
          /* We do not check for offset divisibility here; such a
             check is not needed at this point to encode the value,
@@ -2605,7 +2663,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
              value = 0;
              /* Opcode table should not use this encoding without a
                 known relocation.  */
-             if (fldd->low_pos != 7 || fldd->width != 16)
+             if (fldd->bitfields[0].low_pos != 7 || fldd->bitfields[0].width != 16)
                abort ();
              *fix_needed = TRUE;
              *fix_exp = &operands[opno].value.exp;
@@ -2625,7 +2683,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
              value = 0;
              /* Opcode table should not use this encoding without a
                 known relocation.  */
-             if (fldd->low_pos != 7 || fldd->width != 16)
+             if (fldd->bitfields[0].low_pos != 7 || fldd->bitfields[0].width != 16)
                abort ();
              *fix_needed = TRUE;
              *fix_exp = &operands[opno].value.exp;
@@ -2643,13 +2701,13 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
          *fix_needed = TRUE;
          *fix_exp = &operands[opno].value.exp;
          *fix_pcrel = 1;
-         if (fldd->low_pos == 7 && fldd->width == 21)
+         if (fldd->bitfields[0].low_pos == 7 && fldd->bitfields[0].width == 21)
            *fx_r_type = BFD_RELOC_C6000_PCR_S21;
-         else if (fldd->low_pos == 16 && fldd->width == 12)
+         else if (fldd->bitfields[0].low_pos == 16 && fldd->bitfields[0].width == 12)
            *fx_r_type = BFD_RELOC_C6000_PCR_S12;
-         else if (fldd->low_pos == 13 && fldd->width == 10)
+         else if (fldd->bitfields[0].low_pos == 13 && fldd->bitfields[0].width == 10)
            *fx_r_type = BFD_RELOC_C6000_PCR_S10;
-         else if (fldd->low_pos == 16 && fldd->width == 7)
+         else if (fldd->bitfields[0].low_pos == 16 && fldd->bitfields[0].width == 7)
            *fx_r_type = BFD_RELOC_C6000_PCR_S7;
          else
            /* Opcode table should not use this encoding without a
@@ -2658,6 +2716,30 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
          *fix_adda = FALSE;
          break;
 
+       case tic6x_coding_regpair_lsb:
+         switch (operands[opno].form)
+           {
+           case TIC6X_OP_REGPAIR:
+             value = operands[opno].value.reg.num;
+             break;
+
+           default:
+             abort ();
+           }
+         break;
+
+       case tic6x_coding_regpair_msb:
+         switch (operands[opno].form)
+           {
+           case TIC6X_OP_REGPAIR:
+             value = operands[opno].value.reg.num + 1;
+             break;
+
+           default:
+             abort ();
+           }
+         break;
+
        case tic6x_coding_reg:
          switch (operands[opno].form)
            {
@@ -2743,7 +2825,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
                  abort ();
                }
              if (mem.offset.exp.X_add_number < 0
-                 || mem.offset.exp.X_add_number >= (1 << fldd->width) * scale)
+                 || mem.offset.exp.X_add_number >= (1 << fldd->bitfields[0].width) * scale)
                {
                  if (print_errors)
                    as_bad (_("offset in operand %u of '%.*s' out of range"),
@@ -2776,7 +2858,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
              if (mem.offset.exp.X_op != O_constant)
                abort ();
              if (mem.offset.exp.X_add_number < 0
-                 || mem.offset.exp.X_add_number >= (1 << fldd->width))
+                 || mem.offset.exp.X_add_number >= (1 << fldd->bitfields[0].width))
                {
                  if (print_errors)
                    as_bad (_("offset in operand %u of '%.*s' out of range"),
@@ -2849,7 +2931,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
        case tic6x_coding_spmask:
          /* The position of such a field is hardcoded in the handling
             of "||^".  */
-         if (fldd->low_pos != 18)
+         if (fldd->bitfields[0].low_pos != 18)
            abort ();
          value = 0;
          for (opno = 0; opno < num_operands; opno++)
@@ -2904,7 +2986,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
            fcyc_bits = 4;
          else
            abort ();
-         if (fcyc_bits > fldd->width)
+         if (fcyc_bits > fldd->bitfields[0].width)
            abort ();
 
          if (opct->variable_fields[fld].coding_method == tic6x_coding_fstg)
@@ -2912,7 +2994,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
              int i, t;
              if (operands[opno].value.exp.X_add_number < 0
                  || (operands[opno].value.exp.X_add_number
-                     >= (1 << (fldd->width - fcyc_bits))))
+                     >= (1 << (fldd->bitfields[0].width - fcyc_bits))))
                {
                  if (print_errors)
                    as_bad (_("operand %u of '%.*s' out of range"), opno + 1,
@@ -2921,7 +3003,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
                  return 0;
                }
              value = operands[opno].value.exp.X_add_number;
-             for (t = 0, i = fcyc_bits; i < fldd->width; i++)
+             for (t = 0, i = fcyc_bits; i < fldd->bitfields[0].width; i++)
                {
                  t = (t << 1) | (value & 1);
                  value >>= 1;
@@ -2972,7 +3054,7 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
            return 0;
          }
 
-      opcode_value |= value << fldd->low_pos;
+      opcode_value |= value << fldd->bitfields[0].low_pos;
     }
 
   if (this_line_creg)
@@ -2995,8 +3077,8 @@ tic6x_try_encode (tic6x_opcode_id id, tic6x_operand *operands,
       if (z == NULL)
        abort ();
 
-      opcode_value |= this_line_creg << creg->low_pos;
-      opcode_value |= this_line_z << z->low_pos;
+      opcode_value |= this_line_creg << creg->bitfields[0].low_pos;
+      opcode_value |= this_line_z << z->bitfields[0].low_pos;
     }
 
   *ok = TRUE;
@@ -3823,6 +3905,19 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
        abort ();
       break;
 
+    case BFD_RELOC_C6000_PCR_H16:
+    case BFD_RELOC_C6000_PCR_L16:
+      if (fixP->fx_done || !seg->use_rela_p)
+       {
+         offsetT newval = md_chars_to_number (buf, 4);
+         int shift = fixP->fx_r_type == BFD_RELOC_C6000_PCR_H16 ? 16 : 0;
+
+         MODIFY_VALUE (newval, value, shift, 7, 16);
+
+         md_number_to_chars (buf, newval, 4);
+       }
+      break;
+
     case BFD_RELOC_C6000_SBR_U15_B:
       if (fixP->fx_done || !seg->use_rela_p)
        {
@@ -4437,7 +4532,24 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
       if (!bfd_is_com_section (symbol))
        reloc->addend -= symbol->value;
     }
-
+  if (r_type == BFD_RELOC_C6000_PCR_H16
+      || r_type == BFD_RELOC_C6000_PCR_L16)
+    {
+      symbolS *t = fixp->tc_fix_data.fix_subsy;
+      segT sub_symbol_segment;
+
+      resolve_symbol_value (t);
+      sub_symbol_segment = S_GET_SEGMENT (t);
+      if (sub_symbol_segment == undefined_section)
+       as_bad_where (fixp->fx_file, fixp->fx_line,
+                     _("undefined symbol %s in PCR relocation"),
+                     S_GET_NAME (t));
+      else
+       {
+         reloc->addend = reloc->address & ~0x1F;
+         reloc->addend -= S_GET_VALUE (t);
+       }
+    }
   return reloc;
 }
 
This page took 0.032958 seconds and 4 git commands to generate.