/* TI C6X assembler.
- Copyright 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 2010-2020 Free Software Foundation, Inc.
Contributed by Joseph Myers <joseph@codesourcery.com>
Bernd Schmidt <bernds@codesourcery.com>
if (unwind)
return unwind;
- unwind = (tic6x_unwind_info *)xmalloc (sizeof (tic6x_unwind_info));
+ unwind =XNEW (tic6x_unwind_info);
seg_info (now_seg)->tc_segment_info_data.unwind = unwind;
memset (unwind, 0, sizeof (*unwind));
return unwind;
/* Parse a target-specific option. */
int
-md_parse_option (int c, char *arg)
+md_parse_option (int c, const char *arg)
{
switch (c)
{
static void
s_tic6x_personality (int ignored ATTRIBUTE_UNUSED)
{
- char *name, *p, c;
+ char *name, c;
tic6x_unwind_info *unwind = tic6x_get_unwind ();
if (unwind->personality_routine || unwind->personality_index != -1)
as_bad (_("duplicate .personality directive"));
- name = input_line_pointer;
- c = get_symbol_end ();
- p = input_line_pointer;
+ c = get_symbol_name (&name);
unwind->personality_routine = symbol_find_or_make (name);
- *p = c;
+ (void) restore_line_pointer (c);
demand_empty_rest_of_line ();
}
}
p = frag_more (4);
+ memset (p, 0, 4);
fix_new_exp (frag_now, p - frag_now->fr_literal, 4,
&exp, 0, BFD_RELOC_C6000_EHTYPE);
offsetT align;
int align2;
- name = input_line_pointer;
- c = get_symbol_end ();
+ c = get_symbol_name (&name);
/* Just after name is now '\0'. */
p = input_line_pointer;
- *p = c;
+ (void) restore_line_pointer (c);
SKIP_WHITESPACE ();
if (*input_line_pointer != ',')
{
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;
for (id = 0; id < tic6x_opcode_max; id++)
{
const char *errmsg;
- tic6x_opcode_list *opc = xmalloc (sizeof (tic6x_opcode_list));
+ tic6x_opcode_list *opc = XNEW (tic6x_opcode_list);
opc->id = id;
opc->next = hash_find (opcode_hash, tic6x_opcode_table[id].name);
/* This is copied from perform_an_assembly_pass. */
applicable = bfd_applicable_section_flags (stdoutput);
- bfd_set_section_flags (stdoutput, sbss_section, applicable & SEC_ALLOC);
+ bfd_set_section_flags (sbss_section, applicable & SEC_ALLOC);
subseg_set (seg, subseg);
/* 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;
}
si = seg_info (now_seg);
list = si->tc_segment_info_data.label_list;
- si->tc_segment_info_data.label_list = xmalloc (sizeof (tic6x_label_list));
+ si->tc_segment_info_data.label_list = XNEW (tic6x_label_list);
si->tc_segment_info_data.label_list->next = list;
si->tc_segment_info_data.label_list->label = sym;
{ "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
const char *inner_name;
unsigned int i;
operatorT op = O_illegal;
- symbolS *sym;
+ symbolS *sym, *op_sym = NULL;
if (*name != '$')
return 0;
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;
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;
bfd_boolean fix_adda)
{
bfd_reloc_code_real_type new_reloc = BFD_RELOC_UNUSED;
+ symbolS *subsy = NULL;
fixS *fix;
switch (exp->X_op)
}
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;
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;
}
go through the error checking in tic6x_fix_new_exp. */
void
-tic6x_cons_fix_new (fragS *frag, int where, int size, expressionS *exp)
+tic6x_cons_fix_new (fragS *frag, int where, int size, expressionS *exp,
+ bfd_reloc_code_real_type r_type)
{
- bfd_reloc_code_real_type r_type;
-
switch (size)
{
case 1:
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
case BFD_RELOC_C6000_PREL31:
return 0;
+ case BFD_RELOC_C6000_PCR_H16:
+ case BFD_RELOC_C6000_PCR_L16:
+ return 0;
+
default:
return 1;
}
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;
}
}
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,
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;
}
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,
*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:
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,
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,
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;
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;
*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
*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)
{
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"),
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"),
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++)
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)
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,
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;
return 0;
}
- opcode_value |= value << fldd->low_pos;
+ opcode_value |= value << fldd->bitfields[0].low_pos;
}
if (this_line_creg)
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;
for (opc = opc_list; opc; opc = opc->next)
max_matching_opcodes++;
num_matching_opcodes = 0;
- opcm = xmalloc (max_matching_opcodes * sizeof (*opcm));
+ opcm = XNEWVEC (tic6x_opcode_id, max_matching_opcodes);
max_num_operands = 0;
ok_this_arch = FALSE;
ok_this_fu = FALSE;
if (value < -0x80 || value > 0xff)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("value too large for 1-byte field"));
- md_number_to_chars (buf, value, 1);
+ *buf = value;
}
break;
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)
{
/* Convert a floating-point number to target (IEEE) format. */
-char *
+const char *
md_atof (int type, char *litP, int *sizeP)
{
return ieee_md_atof (type, litP, sizeP, target_big_endian);
{
/* Round up section sizes to ensure that text sections consist of
whole fetch packets. */
- int align = bfd_get_section_alignment (stdoutput, segment);
- return ((size + (1 << align) - 1) & ((valueT) -1 << align));
+ int align = bfd_section_alignment (segment);
+ return ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
}
/* No special undefined symbol handling needed for now. */
asymbol *symbol;
bfd_reloc_code_real_type r_type;
- reloc = xmalloc (sizeof (arelent));
- reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
+ reloc = XNEW (arelent);
+ reloc->sym_ptr_ptr = XNEW (asymbol *);
symbol = symbol_get_bfdsym (fixp->fx_addsy);
*reloc->sym_ptr_ptr = symbol;
reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
if (reloc->howto->pcrel_offset && reloc->howto->partial_inplace)
{
reloc->addend += reloc->address;
- if (!bfd_is_com_section (symbol))
+ if (!bfd_is_com_section (bfd_asymbol_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;
}
const char * text_name;
const char * prefix;
const char * prefix_once;
- const char * group_name;
+ struct elf_section_match match;
size_t prefix_len;
size_t text_len;
char * sec_name;
prefix_len = strlen (prefix);
text_len = strlen (text_name);
sec_name_len = prefix_len + text_len;
- sec_name = (char *) xmalloc (sec_name_len + 1);
+ sec_name = XNEWVEC (char, sec_name_len + 1);
memcpy (sec_name, prefix, prefix_len);
memcpy (sec_name + prefix_len, text_name, text_len);
sec_name[prefix_len + text_len] = '\0';
flags = SHF_ALLOC;
linkonce = 0;
- group_name = 0;
+ memset (&match, 0, sizeof (match));
/* Handle COMDAT group. */
if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
{
- group_name = elf_group_name (text_seg);
- if (group_name == NULL)
+ match.group_name = elf_group_name (text_seg);
+ if (match.group_name == NULL)
{
as_bad (_("group section `%s' has no group signature"),
segment_name (text_seg));
linkonce = 1;
}
- obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
+ obj_elf_change_section (sec_name, type, flags, 0, &match,
+ linkonce, 0);
/* Set the section link for index tables. */
if (idx)
static const int
-tic6x_unwind_frame_regs[TIC6X_NUM_UNWIND_REGS] =
+tic6x_unwind_frame_regs[TIC6X_NUM_UNWIND_REGS] =
/* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
{ 15, 31, 30, 29, 28, 27, 26, 19, 14, 13, 12, 11, 10 };
/* Register save offsets for __c6xabi_push_rts. */
static const int
-tic6x_pop_rts_offset_little[TIC6X_NUM_UNWIND_REGS] =
+tic6x_pop_rts_offset_little[TIC6X_NUM_UNWIND_REGS] =
/* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
{ -1, 1, 0, -3, -4, -7, -8,-11, -2, -5, -6, -9,-10};
static const int
-tic6x_pop_rts_offset_big[TIC6X_NUM_UNWIND_REGS] =
+tic6x_pop_rts_offset_big[TIC6X_NUM_UNWIND_REGS] =
/* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
{ -2, 1, 0, -4, -3, -8, -7,-12, -1, -6, -5,-10, -9};
record_alignment (now_seg, 2);
ptr = frag_more (8);
+ memset (ptr, 0, 8);
where = frag_now_fix () - 8;
/* Self relative offset of the function start. */
if (unwind->personality_index == -1)
{
tmp = md_chars_to_number (unwind->frag_start + 4, 4);
- tmp |= ((unwind->data_bytes - 8) >> 2) << 24;
+ tmp |= (valueT) ((unwind->data_bytes - 8) >> 2) << 24;
md_number_to_chars (unwind->frag_start + 4, tmp, 4);
}
else if (unwind->personality_index == 1 || unwind->personality_index == 2)
continue;
unwind->saved_reg_count++;
- /* Encoding uses 4 bits per word, so size of unwinding opcode data
+ /* Encoding uses 4 bits per word, so size of unwinding opcode data
limits the save area size. The exact cap will be figured out
later due to overflow, the 0x800 here is just a quick sanity
check to weed out obviously excessive offsets. */