2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
3 Contributed by Joseph Myers <joseph@codesourcery.com>
4 Bernd Schmidt <bernds@codesourcery.com>
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "dwarf2dbg.h"
25 #include "dw2gencfi.h"
26 #include "safe-ctype.h"
28 #include "opcode/tic6x.h"
29 #include "elf/tic6x.h"
30 #include "elf32-tic6x.h"
32 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit
33 host gives identical results to a 32-bit host. */
34 #define TRUNC(X) ((valueT) (X) & 0xffffffffU)
35 #define SEXT(X) ((TRUNC (X) ^ 0x80000000U) - 0x80000000U)
37 #define streq(a, b) (strcmp (a, b) == 0)
39 /* Stuff for .scomm symbols. */
40 static segT sbss_section
;
41 static asection scom_section
;
42 static asymbol scom_symbol
;
44 const char comment_chars
[] = ";";
45 const char line_comment_chars
[] = "#*;";
46 const char line_separator_chars
[] = "@";
48 const char EXP_CHARS
[] = "eE";
49 const char FLT_CHARS
[] = "dDfF";
51 const char *md_shortopts
= "";
55 OPTION_MARCH
= OPTION_MD_BASE
,
57 OPTION_MLITTLE_ENDIAN
,
66 struct option md_longopts
[] =
68 { "march", required_argument
, NULL
, OPTION_MARCH
},
69 { "mbig-endian", no_argument
, NULL
, OPTION_MBIG_ENDIAN
},
70 { "mlittle-endian", no_argument
, NULL
, OPTION_MLITTLE_ENDIAN
},
71 { "mdsbt", no_argument
, NULL
, OPTION_MDSBT
},
72 { "mno-dsbt", no_argument
, NULL
, OPTION_MNO_DSBT
},
73 { "mpid", required_argument
, NULL
, OPTION_MPID
},
74 { "mpic", no_argument
, NULL
, OPTION_MPIC
},
75 { "mno-pic", no_argument
, NULL
, OPTION_MNO_PIC
},
76 { "mgenerate-rel", no_argument
, NULL
, OPTION_MGENERATE_REL
},
77 { NULL
, no_argument
, NULL
, 0 }
79 size_t md_longopts_size
= sizeof (md_longopts
);
81 /* The instructions enabled based only on the selected architecture
82 (all instructions, if no architecture specified). */
83 static unsigned short tic6x_arch_enable
= (TIC6X_INSN_C62X
90 /* The instructions enabled based on the current set of features
91 (architecture, as modified by other options). */
92 static unsigned short tic6x_features
;
94 /* The architecture attribute value, or C6XABI_Tag_ISA_none if
96 static int tic6x_arch_attribute
= C6XABI_Tag_ISA_none
;
98 /* Whether any instructions at all have been seen. Once any
99 instructions have been seen, architecture attributes merge into the
100 previous attribute value rather than replacing it. */
101 static bfd_boolean tic6x_seen_insns
= FALSE
;
103 /* The number of registers in each register file supported by the
104 current architecture. */
105 static unsigned int tic6x_num_registers
;
107 /* Whether predication on A0 is possible. */
108 static bfd_boolean tic6x_predicate_a0
;
110 /* Whether execute packets can cross fetch packet boundaries. */
111 static bfd_boolean tic6x_can_cross_fp_boundary
;
113 /* Whether there are constraints on simultaneous reads and writes of
115 static bfd_boolean tic6x_long_data_constraints
;
117 /* Whether compact instructions are available. */
118 static bfd_boolean tic6x_compact_insns
;
120 /* Whether to generate RELA relocations. */
121 static bfd_boolean tic6x_generate_rela
= TRUE
;
123 /* Whether the code uses DSBT addressing. */
124 static bfd_boolean tic6x_dsbt
;
126 /* Types of position-independent data (attribute values for
135 /* The type of data addressing used in this code. */
136 static tic6x_pid_type tic6x_pid
;
138 /* Whether the code uses position-independent code. */
139 static bfd_boolean tic6x_pic
;
141 /* Table of supported architecture variants. */
146 unsigned short features
;
148 static const tic6x_arch_table tic6x_arches
[] =
150 { "c62x", C6XABI_Tag_ISA_C62X
, TIC6X_INSN_C62X
},
151 { "c64x", C6XABI_Tag_ISA_C64X
, TIC6X_INSN_C62X
| TIC6X_INSN_C64X
},
152 { "c64x+", C6XABI_Tag_ISA_C64XP
, (TIC6X_INSN_C62X
154 | TIC6X_INSN_C64XP
) },
155 { "c67x", C6XABI_Tag_ISA_C67X
, TIC6X_INSN_C62X
| TIC6X_INSN_C67X
},
156 { "c67x+", C6XABI_Tag_ISA_C67XP
, (TIC6X_INSN_C62X
158 | TIC6X_INSN_C67XP
) },
159 { "c674x", C6XABI_Tag_ISA_C674X
, (TIC6X_INSN_C62X
164 | TIC6X_INSN_C674X
) }
167 /* Caller saved register encodings. The standard frame layout uses this
168 order, starting from the highest address. There must be
169 TIC6X_NUM_UNWIND_REGS values. */
187 static void tic6x_output_unwinding (bfd_boolean need_extab
);
189 /* Return the frame unwind state for the current function, allocating
192 static tic6x_unwind_info
*tic6x_get_unwind (void)
194 tic6x_unwind_info
*unwind
;
196 unwind
= seg_info (now_seg
)->tc_segment_info_data
.unwind
;
200 unwind
= seg_info (now_seg
)->tc_segment_info_data
.text_unwind
;
204 unwind
=XNEW (tic6x_unwind_info
);
205 seg_info (now_seg
)->tc_segment_info_data
.unwind
= unwind
;
206 memset (unwind
, 0, sizeof (*unwind
));
210 /* Update the selected architecture based on ARCH, giving an error if
211 ARCH is an invalid value. Does not call tic6x_update_features; the
212 caller must do that if necessary. */
215 tic6x_use_arch (const char *arch
)
219 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
220 if (strcmp (arch
, tic6x_arches
[i
].arch
) == 0)
222 tic6x_arch_enable
= tic6x_arches
[i
].features
;
223 if (tic6x_seen_insns
)
225 = elf32_tic6x_merge_arch_attributes (tic6x_arch_attribute
,
226 tic6x_arches
[i
].attr
);
228 tic6x_arch_attribute
= tic6x_arches
[i
].attr
;
232 as_bad (_("unknown architecture '%s'"), arch
);
235 /* Table of supported -mpid arguments. */
240 } tic6x_pid_type_table
;
241 static const tic6x_pid_type_table tic6x_pid_types
[] =
243 { "no", tic6x_pid_no
},
244 { "near", tic6x_pid_near
},
245 { "far", tic6x_pid_far
}
248 /* Handle -mpid=ARG. */
251 tic6x_use_pid (const char *arg
)
255 for (i
= 0; i
< ARRAY_SIZE (tic6x_pid_types
); i
++)
256 if (strcmp (arg
, tic6x_pid_types
[i
].arg
) == 0)
258 tic6x_pid
= tic6x_pid_types
[i
].attr
;
262 as_bad (_("unknown -mpid= argument '%s'"), arg
);
265 /* Parse a target-specific option. */
268 md_parse_option (int c
, const char *arg
)
273 tic6x_use_arch (arg
);
276 case OPTION_MBIG_ENDIAN
:
277 target_big_endian
= 1;
280 case OPTION_MLITTLE_ENDIAN
:
281 target_big_endian
= 0;
288 case OPTION_MNO_DSBT
:
304 case OPTION_MGENERATE_REL
:
305 tic6x_generate_rela
= FALSE
;
315 md_show_usage (FILE *stream ATTRIBUTE_UNUSED
)
319 fputc ('\n', stream
);
320 fprintf (stream
, _("TMS320C6000 options:\n"));
321 fprintf (stream
, _(" -march=ARCH enable instructions from architecture ARCH\n"));
322 fprintf (stream
, _(" -mbig-endian generate big-endian code\n"));
323 fprintf (stream
, _(" -mlittle-endian generate little-endian code\n"));
324 fprintf (stream
, _(" -mdsbt code uses DSBT addressing\n"));
325 fprintf (stream
, _(" -mno-dsbt code does not use DSBT addressing\n"));
326 fprintf (stream
, _(" -mpid=no code uses position-dependent data addressing\n"));
327 fprintf (stream
, _(" -mpid=near code uses position-independent data addressing,\n"
328 " GOT accesses use near DP addressing\n"));
329 fprintf (stream
, _(" -mpid=far code uses position-independent data addressing,\n"
330 " GOT accesses use far DP addressing\n"));
331 fprintf (stream
, _(" -mpic code addressing is position-independent\n"));
332 fprintf (stream
, _(" -mno-pic code addressing is position-dependent\n"));
333 /* -mgenerate-rel is only for testsuite use and is deliberately
336 fputc ('\n', stream
);
337 fprintf (stream
, _("Supported ARCH values are:"));
338 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
339 fprintf (stream
, " %s", tic6x_arches
[i
].arch
);
340 fputc ('\n', stream
);
343 /* Update enabled features based on the current architecture and
346 tic6x_update_features (void)
348 tic6x_features
= tic6x_arch_enable
;
351 = (tic6x_arch_enable
& (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? 32 : 16;
353 tic6x_predicate_a0
= (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? TRUE
: FALSE
;
355 tic6x_can_cross_fp_boundary
357 & (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? TRUE
: FALSE
;
359 tic6x_long_data_constraints
360 = (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? FALSE
: TRUE
;
362 tic6x_compact_insns
= (tic6x_arch_enable
& TIC6X_INSN_C64XP
) ? TRUE
: FALSE
;
365 /* Do configuration after all options have been parsed. */
368 tic6x_after_parse_args (void)
370 tic6x_update_features ();
373 /* Parse a .cantunwind directive. */
375 s_tic6x_cantunwind (int ignored ATTRIBUTE_UNUSED
)
377 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
379 /* GCC sometimes spits out superfluous .cantunwind directives, so ignore
381 if (unwind
->data_bytes
== 0)
384 if (unwind
->data_bytes
!= -1)
386 as_bad (_("unexpected .cantunwind directive"));
390 demand_empty_rest_of_line ();
392 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
393 as_bad (_("personality routine specified for cantunwind frame"));
395 unwind
->personality_index
= -2;
398 /* Parse a .handlerdata directive. */
400 s_tic6x_handlerdata (int ignored ATTRIBUTE_UNUSED
)
402 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
404 if (!unwind
->saved_seg
)
406 as_bad (_("unexpected .handlerdata directive"));
410 if (unwind
->table_entry
|| unwind
->personality_index
== -2)
412 as_bad (_("duplicate .handlerdata directive"));
416 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
418 as_bad (_("personality routine required before .handlerdata directive"));
422 tic6x_output_unwinding (TRUE
);
425 /* Parse a .endp directive. */
427 s_tic6x_endp (int ignored ATTRIBUTE_UNUSED
)
429 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
431 if (unwind
->data_bytes
!= 0)
433 /* Output a .exidx entry if we have not already done so.
434 Then switch back to the text section. */
435 if (!unwind
->table_entry
)
436 tic6x_output_unwinding (FALSE
);
438 subseg_set (unwind
->saved_seg
, unwind
->saved_subseg
);
441 unwind
->saved_seg
= NULL
;
442 unwind
->table_entry
= NULL
;
443 unwind
->data_bytes
= 0;
446 /* Parse a .personalityindex directive. */
448 s_tic6x_personalityindex (int ignored ATTRIBUTE_UNUSED
)
450 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
453 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
454 as_bad (_("duplicate .personalityindex directive"));
458 if (exp
.X_op
!= O_constant
459 || exp
.X_add_number
< 0 || exp
.X_add_number
> 15)
461 as_bad (_("bad personality routine number"));
462 ignore_rest_of_line ();
466 unwind
->personality_index
= exp
.X_add_number
;
468 demand_empty_rest_of_line ();
472 s_tic6x_personality (int ignored ATTRIBUTE_UNUSED
)
475 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
477 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
478 as_bad (_("duplicate .personality directive"));
480 c
= get_symbol_name (&name
);
481 unwind
->personality_routine
= symbol_find_or_make (name
);
482 (void) restore_line_pointer (c
);
483 demand_empty_rest_of_line ();
486 /* Parse a .arch directive. */
488 s_tic6x_arch (int ignored ATTRIBUTE_UNUSED
)
493 arch
= input_line_pointer
;
494 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
495 input_line_pointer
++;
496 c
= *input_line_pointer
;
497 *input_line_pointer
= 0;
499 tic6x_use_arch (arch
);
500 tic6x_update_features ();
501 *input_line_pointer
= c
;
502 demand_empty_rest_of_line ();
505 /* Parse a .ehtype directive. */
508 s_tic6x_ehtype (int ignored ATTRIBUTE_UNUSED
)
513 #ifdef md_flush_pending_output
514 md_flush_pending_output ();
517 if (is_it_end_of_statement ())
519 demand_empty_rest_of_line ();
530 if (exp
.X_op
!= O_symbol
)
532 as_bad (_("expected symbol"));
538 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4,
539 &exp
, 0, BFD_RELOC_C6000_EHTYPE
);
541 demand_empty_rest_of_line ();
544 /* Parse a .nocmp directive. */
547 s_tic6x_nocmp (int ignored ATTRIBUTE_UNUSED
)
549 seg_info (now_seg
)->tc_segment_info_data
.nocmp
= TRUE
;
550 demand_empty_rest_of_line ();
553 /* .scomm pseudo-op handler.
555 This is a new pseudo-op to handle putting objects in .scommon.
556 By doing this the linker won't need to do any work,
557 and more importantly it removes the implicit -G arg necessary to
558 correctly link the object file. */
561 s_tic6x_scomm (int ignore ATTRIBUTE_UNUSED
)
571 c
= get_symbol_name (&name
);
573 /* Just after name is now '\0'. */
574 p
= input_line_pointer
;
575 (void) restore_line_pointer (c
);
577 if (*input_line_pointer
!= ',')
579 as_bad (_("expected comma after symbol name"));
580 ignore_rest_of_line ();
585 input_line_pointer
++;
586 if ((size
= get_absolute_expression ()) < 0)
588 /* xgettext:c-format */
589 as_warn (_("invalid length for .scomm directive"));
590 ignore_rest_of_line ();
594 /* The third argument to .scomm is the alignment. */
595 if (*input_line_pointer
!= ',')
599 ++input_line_pointer
;
600 align
= get_absolute_expression ();
603 as_warn (_("alignment is not a positive number"));
608 /* Convert to a power of 2 alignment. */
611 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
)
615 as_bad (_("alignment is not a power of 2"));
616 ignore_rest_of_line ();
624 symbolP
= symbol_find_or_make (name
);
627 if (S_IS_DEFINED (symbolP
))
629 /* xgettext:c-format */
630 as_bad (_("attempt to re-define symbol `%s'"),
631 S_GET_NAME (symbolP
));
632 ignore_rest_of_line ();
636 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
638 /* xgettext:c-format */
639 as_bad (_("attempt to redefine `%s' with a different length"),
640 S_GET_NAME (symbolP
));
642 ignore_rest_of_line ();
646 if (symbol_get_obj (symbolP
)->local
)
648 segT old_sec
= now_seg
;
649 int old_subsec
= now_subseg
;
652 record_alignment (sbss_section
, align2
);
653 subseg_set (sbss_section
, 0);
656 frag_align (align2
, 0, 0);
658 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
659 symbol_get_frag (symbolP
)->fr_symbol
= 0;
661 symbol_set_frag (symbolP
, frag_now
);
663 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
666 S_SET_SIZE (symbolP
, size
);
667 S_SET_SEGMENT (symbolP
, sbss_section
);
668 S_CLEAR_EXTERNAL (symbolP
);
669 subseg_set (old_sec
, old_subsec
);
673 S_SET_VALUE (symbolP
, (valueT
) size
);
674 S_SET_ALIGN (symbolP
, 1 << align2
);
675 S_SET_EXTERNAL (symbolP
);
676 S_SET_SEGMENT (symbolP
, &scom_section
);
679 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
681 demand_empty_rest_of_line ();
684 /* Track for each attribute whether it has been set explicitly (and so
685 should not have a default value set by the assembler). */
686 static bfd_boolean tic6x_attributes_set_explicitly
[NUM_KNOWN_OBJ_ATTRIBUTES
];
688 /* Parse a .c6xabi_attribute directive. */
691 s_tic6x_c6xabi_attribute (int ignored ATTRIBUTE_UNUSED
)
693 int tag
= obj_elf_vendor_attribute (OBJ_ATTR_PROC
);
695 if (tag
< NUM_KNOWN_OBJ_ATTRIBUTES
)
696 tic6x_attributes_set_explicitly
[tag
] = TRUE
;
703 } tic6x_attribute_table
;
705 static const tic6x_attribute_table tic6x_attributes
[] =
707 #define TAG(tag, value) { #tag, tag },
708 #include "elf/tic6x-attrs.h"
712 /* Convert an attribute name to a number. */
715 tic6x_convert_symbolic_attribute (const char *name
)
719 for (i
= 0; i
< ARRAY_SIZE (tic6x_attributes
); i
++)
720 if (strcmp (name
, tic6x_attributes
[i
].name
) == 0)
721 return tic6x_attributes
[i
].tag
;
726 const pseudo_typeS md_pseudo_table
[] =
728 { "arch", s_tic6x_arch
, 0 },
729 { "c6xabi_attribute", s_tic6x_c6xabi_attribute
, 0 },
730 { "nocmp", s_tic6x_nocmp
, 0 },
731 { "scomm", s_tic6x_scomm
, 0 },
733 { "ehtype", s_tic6x_ehtype
, 0 },
734 { "endp", s_tic6x_endp
, 0 },
735 { "handlerdata", s_tic6x_handlerdata
, 0 },
736 { "personalityindex", s_tic6x_personalityindex
, 0 },
737 { "personality", s_tic6x_personality
, 0 },
738 { "cantunwind", s_tic6x_cantunwind
, 0 },
742 /* Hash table of opcodes. For each opcode name, this stores a pointer
743 to a tic6x_opcode_list listing (in an arbitrary order) all opcode
744 table entries with that name. */
745 static htab_t opcode_hash
;
747 /* Initialize the assembler (called once at assembler startup). */
757 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, 0);
759 /* Insert opcodes into the hash table. */
760 opcode_hash
= str_htab_create ();
761 for (id
= 0; id
< tic6x_opcode_max
; id
++)
763 tic6x_opcode_list
*opc
= XNEW (tic6x_opcode_list
);
766 opc
->next
= str_hash_find (opcode_hash
, tic6x_opcode_table
[id
].name
);
767 str_hash_insert (opcode_hash
, tic6x_opcode_table
[id
].name
, opc
);
770 /* Save the current subseg so we can restore it [it's the default one and
771 we don't want the initial section to be .sbss]. */
775 /* The sbss section is for local .scomm symbols. */
776 sbss_section
= subseg_new (".bss", 0);
777 seg_info (sbss_section
)->bss
= 1;
779 /* This is copied from perform_an_assembly_pass. */
780 applicable
= bfd_applicable_section_flags (stdoutput
);
781 bfd_set_section_flags (sbss_section
, applicable
& SEC_ALLOC
);
783 subseg_set (seg
, subseg
);
785 /* We must construct a fake section similar to bfd_com_section
786 but with the name .scommon. */
787 scom_section
= *bfd_com_section_ptr
;
788 scom_section
.name
= ".scommon";
789 scom_section
.output_section
= & scom_section
;
790 scom_section
.symbol
= & scom_symbol
;
791 scom_section
.symbol_ptr_ptr
= & scom_section
.symbol
;
792 scom_symbol
= * bfd_com_section_ptr
->symbol
;
793 scom_symbol
.name
= ".scommon";
794 scom_symbol
.section
= & scom_section
;
797 /* Whether the current line being parsed had the "||" parallel bars. */
798 static bfd_boolean tic6x_line_parallel
;
800 /* Whether the current line being parsed started "||^" to indicate an
801 SPMASKed parallel instruction. */
802 static bfd_boolean tic6x_line_spmask
;
804 /* If the current line being parsed had an instruction predicate, the
805 creg value for that predicate (which must be nonzero); otherwise
807 static unsigned int tic6x_line_creg
;
809 /* If the current line being parsed had an instruction predicate, the
810 z value for that predicate; otherwise 0. */
811 static unsigned int tic6x_line_z
;
813 /* Return 1 (updating input_line_pointer as appropriate) if the line
814 starting with C (immediately before input_line_pointer) starts with
815 pre-opcode text appropriate for this target, 0 otherwise. */
818 tic6x_unrecognized_line (int c
)
823 bfd_boolean bad_predicate
;
828 if (input_line_pointer
[0] == '|')
830 if (input_line_pointer
[1] == '^')
832 tic6x_line_spmask
= TRUE
;
833 input_line_pointer
+= 2;
836 input_line_pointer
+= 1;
837 if (tic6x_line_parallel
)
838 as_bad (_("multiple '||' on same line"));
839 tic6x_line_parallel
= TRUE
;
841 as_bad (_("'||' after predicate"));
847 /* If it doesn't look like a predicate at all, just return 0.
848 If it looks like one but not a valid one, give a better
850 p
= input_line_pointer
;
851 while (*p
!= ']' && !is_end_of_line
[(unsigned char) *p
])
856 p
= input_line_pointer
;
858 bad_predicate
= FALSE
;
864 if (*p
== 'A' || *p
== 'a')
866 else if (*p
== 'B' || *p
== 'b')
870 areg
= TRUE
; /* Avoid uninitialized warning. */
871 bad_predicate
= TRUE
;
876 if (*p
!= '0' && *p
!= '1' && *p
!= '2')
877 bad_predicate
= TRUE
;
878 else if (p
[1] != ']')
879 bad_predicate
= TRUE
;
881 input_line_pointer
= p
+ 2;
885 as_bad (_("multiple predicates on same line"));
891 as_bad (_("bad predicate '%s'"), input_line_pointer
- 1);
893 input_line_pointer
= endp
;
900 tic6x_line_creg
= (areg
? 6 : 1);
901 if (areg
&& !tic6x_predicate_a0
)
902 as_bad (_("predication on A0 not supported on this architecture"));
906 tic6x_line_creg
= (areg
? 4 : 2);
910 tic6x_line_creg
= (areg
? 5 : 3);
925 /* Do any target-specific handling of a label required. */
928 tic6x_frob_label (symbolS
*sym
)
930 segment_info_type
*si
;
931 tic6x_label_list
*list
;
933 if (tic6x_line_parallel
)
935 as_bad (_("label after '||'"));
936 tic6x_line_parallel
= FALSE
;
937 tic6x_line_spmask
= FALSE
;
941 as_bad (_("label after predicate"));
946 si
= seg_info (now_seg
);
947 list
= si
->tc_segment_info_data
.label_list
;
948 si
->tc_segment_info_data
.label_list
= XNEW (tic6x_label_list
);
949 si
->tc_segment_info_data
.label_list
->next
= list
;
950 si
->tc_segment_info_data
.label_list
->label
= sym
;
952 /* Defining tc_frob_label overrides the ELF definition of
953 obj_frob_label, so we need to apply its effects here. */
954 dwarf2_emit_label (sym
);
957 /* At end-of-line, give errors for start-of-line decorations that
958 needed an instruction but were not followed by one. */
961 tic6x_end_of_line (void)
963 if (tic6x_line_parallel
)
965 as_bad (_("'||' not followed by instruction"));
966 tic6x_line_parallel
= FALSE
;
967 tic6x_line_spmask
= FALSE
;
971 as_bad (_("predicate not followed by instruction"));
977 /* Do any target-specific handling of the start of a logical line. */
980 tic6x_start_line_hook (void)
982 tic6x_end_of_line ();
985 /* Do target-specific handling immediately after an input file from
986 the command line, and any other inputs it includes, have been
992 tic6x_end_of_line ();
995 /* Do target-specific initialization after arguments have been
996 processed and the output file created. */
999 tic6x_init_after_args (void)
1001 elf32_tic6x_set_use_rela_p (stdoutput
, tic6x_generate_rela
);
1004 /* Free LIST of labels (possibly NULL). */
1007 tic6x_free_label_list (tic6x_label_list
*list
)
1011 tic6x_label_list
*old
= list
;
1018 /* Handle a data alignment of N bytes. */
1021 tic6x_cons_align (int n ATTRIBUTE_UNUSED
)
1023 segment_info_type
*seginfo
= seg_info (now_seg
);
1025 /* Data means there is no current execute packet, and that any label
1026 applies to that data rather than a subsequent instruction. */
1027 tic6x_free_label_list (seginfo
->tc_segment_info_data
.label_list
);
1028 seginfo
->tc_segment_info_data
.label_list
= NULL
;
1029 seginfo
->tc_segment_info_data
.execute_packet_frag
= NULL
;
1030 seginfo
->tc_segment_info_data
.last_insn_lsb
= NULL
;
1031 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
1032 seginfo
->tc_segment_info_data
.func_units_used
= 0;
1035 /* Handle an alignment directive. Return TRUE if the
1036 machine-independent frag generation should be skipped. */
1039 tic6x_do_align (int n
, char *fill
, int len ATTRIBUTE_UNUSED
, int max
)
1041 /* Given code alignments of 4, 8, 16 or 32 bytes, we try to handle
1042 them in the md_end pass by inserting NOPs in parallel with
1043 previous instructions. We only do this in sections containing
1044 nothing but instructions. Code alignments of 1 or 2 bytes have
1045 no effect in such sections (but we record them with
1046 machine-dependent frags anyway so they can be skipped or
1047 converted to machine-independent), while those of more than 64
1048 bytes cannot reliably be handled in this way. */
1054 && subseg_text_p (now_seg
))
1062 /* Machine-independent code would generate a frag here, but we
1063 wish to handle it in a machine-dependent way. */
1064 if (frag_now_fix () != 0)
1066 if (frag_now
->fr_type
!= rs_machine_dependent
)
1067 frag_wane (frag_now
);
1072 align_frag
= frag_now
;
1073 p
= frag_var (rs_machine_dependent
, 32, 32, max
, NULL
, n
, NULL
);
1074 /* This must be the same as the frag to which a pointer was just
1076 if (p
!= align_frag
->fr_literal
)
1078 align_frag
->tc_frag_data
.is_insns
= FALSE
;
1085 /* Types of operand for parsing purposes. These are used as bit-masks
1086 to tell tic6x_parse_operand what forms of operand are
1088 #define TIC6X_OP_EXP 0x0001u
1089 #define TIC6X_OP_REG 0x0002u
1090 #define TIC6X_OP_REGPAIR 0x0004u
1091 #define TIC6X_OP_IRP 0x0008u
1092 #define TIC6X_OP_NRP 0x0010u
1093 /* With TIC6X_OP_MEM_NOUNREG, the contents of a () offset are always
1094 interpreted as an expression, which may be a symbol with the same
1095 name as a register that ends up being implicitly DP-relative. With
1096 TIC6X_OP_MEM_UNREG, the contents of a () offset are interpreted as
1097 a register if they match one, and failing that as an expression,
1098 which must be constant. */
1099 #define TIC6X_OP_MEM_NOUNREG 0x0020u
1100 #define TIC6X_OP_MEM_UNREG 0x0040u
1101 #define TIC6X_OP_CTRL 0x0080u
1102 #define TIC6X_OP_FUNC_UNIT 0x0100u
1104 /* A register or register pair read by the assembler. */
1107 /* The side the register is on (1 or 2). */
1109 /* The register number (0 to 31). */
1113 /* Types of modification of a base address. */
1118 tic6x_mem_mod_minus
,
1119 tic6x_mem_mod_preinc
,
1120 tic6x_mem_mod_predec
,
1121 tic6x_mem_mod_postinc
,
1122 tic6x_mem_mod_postdec
1125 /* Scaled [] or unscaled () nature of an offset. */
1129 tic6x_offset_scaled
,
1130 tic6x_offset_unscaled
1131 } tic6x_mem_scaling
;
1133 /* A memory operand read by the assembler. */
1136 /* The base register. */
1137 tic6x_register base_reg
;
1138 /* How the base register is modified. */
1140 /* Whether there is an offset (required with plain "+" and "-"), and
1141 whether it is scaled or unscaled if so. */
1142 tic6x_mem_scaling scaled
;
1143 /* Whether the offset is a register (TRUE) or an expression
1145 bfd_boolean offset_is_reg
;
1154 /* A functional unit in SPMASK operands read by the assembler. */
1157 /* The basic unit. */
1158 tic6x_func_unit_base base
;
1159 /* The side (1 or 2). */
1161 } tic6x_func_unit_operand
;
1163 /* An operand read by the assembler. */
1166 /* The syntactic form of the operand, as one of the bit-masks
1169 /* The operand value. */
1172 /* An expression: TIC6X_OP_EXP. */
1174 /* A register: TIC6X_OP_REG, TIC6X_OP_REGPAIR. */
1176 /* A memory reference: TIC6X_OP_MEM_NOUNREG,
1177 TIC6X_OP_MEM_UNREG. */
1179 /* A control register: TIC6X_OP_CTRL. */
1181 /* A functional unit: TIC6X_OP_FUNC_UNIT. */
1182 tic6x_func_unit_operand func_unit
;
1186 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1188 /* Parse a register operand, or part of an operand, starting at *P.
1189 If syntactically OK (including that the number is in the range 0 to
1190 31, but not necessarily in range for this architecture), return
1191 TRUE, putting the register side and number in *REG and update *P to
1192 point immediately after the register number; otherwise return FALSE
1193 without changing *P (but possibly changing *REG). Do not print any
1197 tic6x_parse_register (char **p
, tic6x_register
*reg
)
1218 if (*r
>= '0' && *r
<= '9')
1220 reg
->num
= *r
- '0';
1226 if (reg
->num
> 0 && *r
>= '0' && *r
<= '9')
1228 reg
->num
= reg
->num
* 10 + (*r
- '0');
1232 if (*r
>= '0' && *r
<= '9')
1241 /* Parse the initial two characters of a functional unit name starting
1242 at *P. If OK, set *BASE and *SIDE and return TRUE; otherwise,
1246 tic6x_parse_func_unit_base (char *p
, tic6x_func_unit_base
*base
,
1249 bfd_boolean good_func_unit
= TRUE
;
1250 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
1251 unsigned int maybe_side
= 0;
1257 maybe_base
= tic6x_func_unit_d
;
1262 maybe_base
= tic6x_func_unit_l
;
1267 maybe_base
= tic6x_func_unit_m
;
1272 maybe_base
= tic6x_func_unit_s
;
1276 good_func_unit
= FALSE
;
1292 good_func_unit
= FALSE
;
1302 return good_func_unit
;
1305 /* Parse an operand starting at *P. If the operand parses OK, return
1306 TRUE and store the value in *OP; otherwise return FALSE (possibly
1307 changing *OP). In any case, update *P to point to the following
1308 comma or end of line. The possible operand forms are given by
1309 OP_FORMS. For diagnostics, this is operand OPNO of an opcode
1310 starting at STR, length OPC_LEN. */
1313 tic6x_parse_operand (char **p
, tic6x_operand
*op
, unsigned int op_forms
,
1314 char *str
, int opc_len
, unsigned int opno
)
1316 bfd_boolean operand_parsed
= FALSE
;
1319 if ((op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
1320 == (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
1323 /* Check for functional unit names for SPMASK and SPMASKR. */
1324 if (!operand_parsed
&& (op_forms
& TIC6X_OP_FUNC_UNIT
))
1326 tic6x_func_unit_base base
= tic6x_func_unit_nfu
;
1327 unsigned int side
= 0;
1329 if (tic6x_parse_func_unit_base (q
, &base
, &side
))
1333 skip_whitespace (rq
);
1334 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1336 op
->form
= TIC6X_OP_FUNC_UNIT
;
1337 op
->value
.func_unit
.base
= base
;
1338 op
->value
.func_unit
.side
= side
;
1339 operand_parsed
= TRUE
;
1345 /* Check for literal "irp". */
1346 if (!operand_parsed
&& (op_forms
& TIC6X_OP_IRP
))
1348 if ((q
[0] == 'i' || q
[0] == 'I')
1349 && (q
[1] == 'r' || q
[1] == 'R')
1350 && (q
[2] == 'p' || q
[2] == 'P'))
1354 skip_whitespace (rq
);
1355 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1357 op
->form
= TIC6X_OP_IRP
;
1358 operand_parsed
= TRUE
;
1364 /* Check for literal "nrp". */
1365 if (!operand_parsed
&& (op_forms
& TIC6X_OP_NRP
))
1367 if ((q
[0] == 'n' || q
[0] == 'N')
1368 && (q
[1] == 'r' || q
[1] == 'R')
1369 && (q
[2] == 'p' || q
[2] == 'P'))
1373 skip_whitespace (rq
);
1374 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1376 op
->form
= TIC6X_OP_NRP
;
1377 operand_parsed
= TRUE
;
1383 /* Check for control register names. */
1384 if (!operand_parsed
&& (op_forms
& TIC6X_OP_CTRL
))
1388 for (crid
= 0; crid
< tic6x_ctrl_max
; crid
++)
1390 size_t len
= strlen (tic6x_ctrl_table
[crid
].name
);
1392 if (strncasecmp (tic6x_ctrl_table
[crid
].name
, q
, len
) == 0)
1396 skip_whitespace (rq
);
1397 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1399 op
->form
= TIC6X_OP_CTRL
;
1400 op
->value
.ctrl
= crid
;
1401 operand_parsed
= TRUE
;
1403 if (!(tic6x_ctrl_table
[crid
].isa_variants
& tic6x_features
))
1404 as_bad (_("control register '%s' not supported "
1405 "on this architecture"),
1406 tic6x_ctrl_table
[crid
].name
);
1412 /* See if this looks like a memory reference. */
1414 && (op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
)))
1416 bfd_boolean mem_ok
= TRUE
;
1418 tic6x_mem_mod mem_mod
= tic6x_mem_mod_none
;
1419 tic6x_register base_reg
;
1420 bfd_boolean require_offset
, permit_offset
;
1421 tic6x_mem_scaling scaled
;
1422 bfd_boolean offset_is_reg
;
1423 expressionS offset_exp
;
1424 tic6x_register offset_reg
;
1433 skip_whitespace (mq
);
1439 mem_mod
= tic6x_mem_mod_preinc
;
1444 mem_mod
= tic6x_mem_mod_plus
;
1452 mem_mod
= tic6x_mem_mod_predec
;
1457 mem_mod
= tic6x_mem_mod_minus
;
1469 skip_whitespace (mq
);
1470 mem_ok
= tic6x_parse_register (&mq
, &base_reg
);
1473 if (mem_ok
&& mem_mod
== tic6x_mem_mod_none
)
1475 skip_whitespace (mq
);
1476 if (mq
[0] == '+' && mq
[1] == '+')
1478 mem_mod
= tic6x_mem_mod_postinc
;
1481 else if (mq
[0] == '-' && mq
[1] == '-')
1483 mem_mod
= tic6x_mem_mod_postdec
;
1488 if (mem_mod
== tic6x_mem_mod_none
)
1489 permit_offset
= FALSE
;
1491 permit_offset
= TRUE
;
1492 if (mem_mod
== tic6x_mem_mod_plus
|| mem_mod
== tic6x_mem_mod_minus
)
1493 require_offset
= TRUE
;
1495 require_offset
= FALSE
;
1496 scaled
= tic6x_offset_none
;
1497 offset_is_reg
= FALSE
;
1499 if (mem_ok
&& permit_offset
)
1503 skip_whitespace (mq
);
1507 scaled
= tic6x_offset_scaled
;
1513 scaled
= tic6x_offset_unscaled
;
1521 if (scaled
!= tic6x_offset_none
)
1523 skip_whitespace (mq
);
1524 if (scaled
== tic6x_offset_scaled
1525 || (op_forms
& TIC6X_OP_MEM_UNREG
))
1530 reg_ok
= tic6x_parse_register (&rq
, &offset_reg
);
1533 skip_whitespace (rq
);
1537 offset_is_reg
= TRUE
;
1543 char *save_input_line_pointer
;
1545 save_input_line_pointer
= input_line_pointer
;
1546 input_line_pointer
= mq
;
1547 expression (&offset_exp
);
1548 mq
= input_line_pointer
;
1549 input_line_pointer
= save_input_line_pointer
;
1551 skip_whitespace (mq
);
1559 if (mem_ok
&& require_offset
&& scaled
== tic6x_offset_none
)
1564 skip_whitespace (mq
);
1565 if (!is_end_of_line
[(unsigned char) *mq
] && *mq
!= ',')
1571 op
->form
= op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
);
1572 op
->value
.mem
.base_reg
= base_reg
;
1573 op
->value
.mem
.mod
= mem_mod
;
1574 op
->value
.mem
.scaled
= scaled
;
1575 op
->value
.mem
.offset_is_reg
= offset_is_reg
;
1577 op
->value
.mem
.offset
.reg
= offset_reg
;
1579 op
->value
.mem
.offset
.exp
= offset_exp
;
1580 operand_parsed
= TRUE
;
1582 if (base_reg
.num
>= tic6x_num_registers
)
1583 as_bad (_("register number %u not supported on this architecture"),
1585 if (offset_is_reg
&& offset_reg
.num
>= tic6x_num_registers
)
1586 as_bad (_("register number %u not supported on this architecture"),
1591 /* See if this looks like a register or register pair. */
1592 if (!operand_parsed
&& (op_forms
& (TIC6X_OP_REG
| TIC6X_OP_REGPAIR
)))
1594 tic6x_register first_reg
, second_reg
;
1598 reg_ok
= tic6x_parse_register (&rq
, &first_reg
);
1602 if (*rq
== ':' && (op_forms
& TIC6X_OP_REGPAIR
))
1605 reg_ok
= tic6x_parse_register (&rq
, &second_reg
);
1608 skip_whitespace (rq
);
1609 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1611 if ((second_reg
.num
& 1)
1612 || (first_reg
.num
!= second_reg
.num
+ 1)
1613 || (first_reg
.side
!= second_reg
.side
))
1614 as_bad (_("register pair for operand %u of '%.*s'"
1615 " not a valid even/odd pair"), opno
,
1617 op
->form
= TIC6X_OP_REGPAIR
;
1618 op
->value
.reg
= second_reg
;
1619 operand_parsed
= TRUE
;
1624 else if (op_forms
& TIC6X_OP_REG
)
1626 skip_whitespace (rq
);
1627 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1629 op
->form
= TIC6X_OP_REG
;
1630 op
->value
.reg
= first_reg
;
1631 operand_parsed
= TRUE
;
1638 if (first_reg
.num
>= tic6x_num_registers
)
1639 as_bad (_("register number %u not supported on this architecture"),
1641 if (op
->form
== TIC6X_OP_REGPAIR
1642 && second_reg
.num
>= tic6x_num_registers
)
1643 as_bad (_("register number %u not supported on this architecture"),
1648 /* Otherwise, parse it as an expression. */
1649 if (!operand_parsed
&& (op_forms
& TIC6X_OP_EXP
))
1651 char *save_input_line_pointer
;
1653 save_input_line_pointer
= input_line_pointer
;
1654 input_line_pointer
= q
;
1655 op
->form
= TIC6X_OP_EXP
;
1656 expression (&op
->value
.exp
);
1657 q
= input_line_pointer
;
1658 input_line_pointer
= save_input_line_pointer
;
1659 operand_parsed
= TRUE
;
1664 /* Now the operand has been parsed, there must be nothing more
1665 before the comma or end of line. */
1666 skip_whitespace (q
);
1667 if (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1669 operand_parsed
= FALSE
;
1670 as_bad (_("junk after operand %u of '%.*s'"), opno
,
1672 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1678 /* This could not be parsed as any acceptable form of
1682 case TIC6X_OP_REG
| TIC6X_OP_REGPAIR
:
1683 as_bad (_("bad register or register pair for operand %u of '%.*s'"),
1684 opno
, opc_len
, str
);
1687 case TIC6X_OP_REG
| TIC6X_OP_CTRL
:
1689 as_bad (_("bad register for operand %u of '%.*s'"),
1690 opno
, opc_len
, str
);
1693 case TIC6X_OP_REGPAIR
:
1694 as_bad (_("bad register pair for operand %u of '%.*s'"),
1695 opno
, opc_len
, str
);
1698 case TIC6X_OP_FUNC_UNIT
:
1699 as_bad (_("bad functional unit for operand %u of '%.*s'"),
1700 opno
, opc_len
, str
);
1704 as_bad (_("bad operand %u of '%.*s'"),
1705 opno
, opc_len
, str
);
1709 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1713 return operand_parsed
;
1716 /* Table of assembler operators and associated O_* values. */
1721 } tic6x_operator_table
;
1722 static const tic6x_operator_table tic6x_operators
[] = {
1723 #define O_dsbt_index O_md1
1724 { "dsbt_index", O_dsbt_index
},
1727 #define O_dpr_got O_md3
1728 { "dpr_got", O_dpr_got
},
1729 #define O_dpr_byte O_md4
1730 { "dpr_byte", O_dpr_byte
},
1731 #define O_dpr_hword O_md5
1732 { "dpr_hword", O_dpr_hword
},
1733 #define O_dpr_word O_md6
1734 { "dpr_word", O_dpr_word
},
1735 #define O_pcr_offset O_md7
1736 { "pcr_offset", O_pcr_offset
}
1739 /* Parse a name in some machine-specific way. Used on C6X to handle
1740 assembler operators. */
1743 tic6x_parse_name (const char *name
, expressionS
*exprP
,
1744 enum expr_mode mode ATTRIBUTE_UNUSED
, char *nextchar
)
1746 char *p
= input_line_pointer
;
1747 char c
, *name_start
, *name_end
;
1748 const char *inner_name
;
1750 operatorT op
= O_illegal
;
1751 symbolS
*sym
, *op_sym
= NULL
;
1756 for (i
= 0; i
< ARRAY_SIZE (tic6x_operators
); i
++)
1757 if (strcasecmp (name
+ 1, tic6x_operators
[i
].name
) == 0)
1759 op
= tic6x_operators
[i
].op
;
1763 if (op
== O_illegal
)
1766 *input_line_pointer
= *nextchar
;
1767 skip_whitespace (p
);
1771 *input_line_pointer
= 0;
1775 skip_whitespace (p
);
1777 if (!is_name_beginner (*p
))
1779 *input_line_pointer
= 0;
1785 while (is_part_of_name (*p
))
1788 skip_whitespace (p
);
1790 if (op
== O_pcr_offset
)
1792 char *op_name_start
, *op_name_end
;
1796 *input_line_pointer
= 0;
1800 skip_whitespace (p
);
1802 if (!is_name_beginner (*p
))
1804 *input_line_pointer
= 0;
1810 while (is_part_of_name (*p
))
1813 skip_whitespace (p
);
1817 op_sym
= symbol_find_or_make (op_name_start
);
1823 *input_line_pointer
= 0;
1827 input_line_pointer
= p
+ 1;
1828 *nextchar
= *input_line_pointer
;
1829 *input_line_pointer
= 0;
1833 inner_name
= name_start
;
1834 if (op
== O_dsbt_index
&& strcmp (inner_name
, "__c6xabi_DSBT_BASE") != 0)
1836 as_bad (_("$DSBT_INDEX must be used with __c6xabi_DSBT_BASE"));
1837 inner_name
= "__c6xabi_DSBT_BASE";
1839 sym
= symbol_find_or_make (inner_name
);
1843 exprP
->X_add_symbol
= sym
;
1844 exprP
->X_add_number
= 0;
1845 exprP
->X_op_symbol
= op_sym
;
1851 /* Create a fixup for an expression. Same arguments as fix_new_exp,
1852 plus FIX_ADDA which is TRUE for ADDA instructions (to indicate that
1853 fixes resolving to constants should have those constants implicitly
1854 shifted) and FALSE otherwise, but look for C6X-specific expression
1855 types and adjust the relocations or give errors accordingly. */
1858 tic6x_fix_new_exp (fragS
*frag
, int where
, int size
, expressionS
*exp
,
1859 int pcrel
, bfd_reloc_code_real_type r_type
,
1860 bfd_boolean fix_adda
)
1862 bfd_reloc_code_real_type new_reloc
= BFD_RELOC_UNUSED
;
1863 symbolS
*subsy
= NULL
;
1871 case BFD_RELOC_C6000_SBR_U15_W
:
1872 new_reloc
= BFD_RELOC_C6000_DSBT_INDEX
;
1876 as_bad (_("$DSBT_INDEX not supported in this context"));
1884 case BFD_RELOC_C6000_SBR_U15_W
:
1885 new_reloc
= BFD_RELOC_C6000_SBR_GOT_U15_W
;
1889 as_bad (_("$GOT not supported in this context"));
1897 case BFD_RELOC_C6000_ABS_L16
:
1898 new_reloc
= BFD_RELOC_C6000_SBR_GOT_L16_W
;
1901 case BFD_RELOC_C6000_ABS_H16
:
1902 new_reloc
= BFD_RELOC_C6000_SBR_GOT_H16_W
;
1906 as_bad (_("$DPR_GOT not supported in this context"));
1914 case BFD_RELOC_C6000_ABS_S16
:
1915 new_reloc
= BFD_RELOC_C6000_SBR_S16
;
1918 case BFD_RELOC_C6000_ABS_L16
:
1919 new_reloc
= BFD_RELOC_C6000_SBR_L16_B
;
1922 case BFD_RELOC_C6000_ABS_H16
:
1923 new_reloc
= BFD_RELOC_C6000_SBR_H16_B
;
1927 as_bad (_("$DPR_BYTE not supported in this context"));
1935 case BFD_RELOC_C6000_ABS_L16
:
1936 new_reloc
= BFD_RELOC_C6000_SBR_L16_H
;
1939 case BFD_RELOC_C6000_ABS_H16
:
1940 new_reloc
= BFD_RELOC_C6000_SBR_H16_H
;
1944 as_bad (_("$DPR_HWORD not supported in this context"));
1952 case BFD_RELOC_C6000_ABS_L16
:
1953 new_reloc
= BFD_RELOC_C6000_SBR_L16_W
;
1956 case BFD_RELOC_C6000_ABS_H16
:
1957 new_reloc
= BFD_RELOC_C6000_SBR_H16_W
;
1961 as_bad (_("$DPR_WORD not supported in this context"));
1967 subsy
= exp
->X_op_symbol
;
1970 case BFD_RELOC_C6000_ABS_S16
:
1971 case BFD_RELOC_C6000_ABS_L16
:
1972 new_reloc
= BFD_RELOC_C6000_PCR_L16
;
1975 case BFD_RELOC_C6000_ABS_H16
:
1976 new_reloc
= BFD_RELOC_C6000_PCR_H16
;
1980 as_bad (_("$PCR_OFFSET not supported in this context"));
1991 as_bad (_("invalid PC-relative operand"));
1997 if (new_reloc
== BFD_RELOC_UNUSED
)
1998 fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
2000 fix
= fix_new (frag
, where
, size
, exp
->X_add_symbol
, exp
->X_add_number
,
2002 fix
->tc_fix_data
.fix_subsy
= subsy
;
2003 fix
->tc_fix_data
.fix_adda
= fix_adda
;
2006 /* Generate a fix for a constant (.word etc.). Needed to ensure these
2007 go through the error checking in tic6x_fix_new_exp. */
2010 tic6x_cons_fix_new (fragS
*frag
, int where
, int size
, expressionS
*exp
,
2011 bfd_reloc_code_real_type r_type
)
2016 r_type
= BFD_RELOC_8
;
2020 r_type
= BFD_RELOC_16
;
2024 r_type
= BFD_RELOC_32
;
2028 as_bad (_("no %d-byte relocations available"), size
);
2032 tic6x_fix_new_exp (frag
, where
, size
, exp
, 0, r_type
, FALSE
);
2035 /* Initialize target-specific fix data. */
2038 tic6x_init_fix_data (fixS
*fixP
)
2040 fixP
->tc_fix_data
.fix_adda
= FALSE
;
2041 fixP
->tc_fix_data
.fix_subsy
= NULL
;
2044 /* Return true if the fix can be handled by GAS, false if it must
2045 be passed through to the linker. */
2048 tic6x_fix_adjustable (fixS
*fixP
)
2050 switch (fixP
->fx_r_type
)
2052 /* Adjust_reloc_syms doesn't know about the GOT. */
2053 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
2054 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
2055 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
2056 case BFD_RELOC_C6000_EHTYPE
:
2059 case BFD_RELOC_C6000_PREL31
:
2062 case BFD_RELOC_C6000_PCR_H16
:
2063 case BFD_RELOC_C6000_PCR_L16
:
2071 /* Given the fine-grained form of an operand, return the coarse
2075 tic6x_coarse_operand_form (tic6x_operand_form form
)
2079 case tic6x_operand_asm_const
:
2080 case tic6x_operand_link_const
:
2081 return TIC6X_OP_EXP
;
2083 case tic6x_operand_reg
:
2084 case tic6x_operand_xreg
:
2085 case tic6x_operand_dreg
:
2086 case tic6x_operand_areg
:
2087 case tic6x_operand_retreg
:
2088 return TIC6X_OP_REG
;
2090 case tic6x_operand_regpair
:
2091 case tic6x_operand_xregpair
:
2092 case tic6x_operand_dregpair
:
2093 return TIC6X_OP_REGPAIR
;
2095 case tic6x_operand_irp
:
2096 return TIC6X_OP_IRP
;
2098 case tic6x_operand_nrp
:
2099 return TIC6X_OP_NRP
;
2101 case tic6x_operand_ctrl
:
2102 return TIC6X_OP_CTRL
;
2104 case tic6x_operand_mem_short
:
2105 case tic6x_operand_mem_long
:
2106 case tic6x_operand_mem_deref
:
2107 return TIC6X_OP_MEM_NOUNREG
;
2109 case tic6x_operand_mem_ndw
:
2110 return TIC6X_OP_MEM_UNREG
;
2112 case tic6x_operand_func_unit
:
2113 return TIC6X_OP_FUNC_UNIT
;
2120 /* How an operand may match or not match a desired form. If different
2121 instruction alternatives fail in different ways, the first failure
2122 in this list determines the diagnostic. */
2126 tic6x_match_matches
,
2127 /* Bad coarse form. */
2130 tic6x_match_non_const
,
2131 /* Register on wrong side. */
2132 tic6x_match_wrong_side
,
2133 /* Not a valid address register. */
2134 tic6x_match_bad_address
,
2135 /* Not a valid return address register. */
2136 tic6x_match_bad_return
,
2137 /* Control register not readable. */
2138 tic6x_match_ctrl_write_only
,
2139 /* Control register not writable. */
2140 tic6x_match_ctrl_read_only
,
2141 /* Not a valid memory reference for this instruction. */
2143 } tic6x_operand_match
;
2145 /* Return whether an operand matches the given fine-grained form and
2146 read/write usage, and, if it does not match, how it fails to match.
2147 The main functional unit side is SIDE; the cross-path side is CROSS
2148 (the same as SIDE if a cross path not used); the data side is
2150 static tic6x_operand_match
2151 tic6x_operand_matches_form (const tic6x_operand
*op
, tic6x_operand_form form
,
2152 tic6x_rw rw
, unsigned int side
, unsigned int cross
,
2153 unsigned int data_side
)
2155 unsigned int coarse
= tic6x_coarse_operand_form (form
);
2157 if (coarse
!= op
->form
)
2158 return tic6x_match_coarse
;
2162 case tic6x_operand_asm_const
:
2163 if (op
->value
.exp
.X_op
== O_constant
)
2164 return tic6x_match_matches
;
2166 return tic6x_match_non_const
;
2168 case tic6x_operand_link_const
:
2169 case tic6x_operand_irp
:
2170 case tic6x_operand_nrp
:
2171 case tic6x_operand_func_unit
:
2172 /* All expressions are link-time constants, although there may
2173 not be relocations to express them in the output file. "irp"
2174 and "nrp" are unique operand values. All parsed functional
2175 unit names are valid. */
2176 return tic6x_match_matches
;
2178 case tic6x_operand_reg
:
2179 case tic6x_operand_regpair
:
2180 if (op
->value
.reg
.side
== side
)
2181 return tic6x_match_matches
;
2183 return tic6x_match_wrong_side
;
2185 case tic6x_operand_xreg
:
2186 case tic6x_operand_xregpair
:
2187 if (op
->value
.reg
.side
== cross
)
2188 return tic6x_match_matches
;
2190 return tic6x_match_wrong_side
;
2192 case tic6x_operand_dreg
:
2193 case tic6x_operand_dregpair
:
2194 if (op
->value
.reg
.side
== data_side
)
2195 return tic6x_match_matches
;
2197 return tic6x_match_wrong_side
;
2199 case tic6x_operand_areg
:
2200 if (op
->value
.reg
.side
!= cross
)
2201 return tic6x_match_wrong_side
;
2202 else if (op
->value
.reg
.side
== 2
2203 && (op
->value
.reg
.num
== 14 || op
->value
.reg
.num
== 15))
2204 return tic6x_match_matches
;
2206 return tic6x_match_bad_address
;
2208 case tic6x_operand_retreg
:
2209 if (op
->value
.reg
.side
!= side
)
2210 return tic6x_match_wrong_side
;
2211 else if (op
->value
.reg
.num
!= 3)
2212 return tic6x_match_bad_return
;
2214 return tic6x_match_matches
;
2216 case tic6x_operand_ctrl
:
2220 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read
2221 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
2222 return tic6x_match_matches
;
2224 return tic6x_match_ctrl_write_only
;
2226 case tic6x_rw_write
:
2227 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_write
2228 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
2229 return tic6x_match_matches
;
2231 return tic6x_match_ctrl_read_only
;
2237 case tic6x_operand_mem_deref
:
2238 if (op
->value
.mem
.mod
!= tic6x_mem_mod_none
)
2239 return tic6x_match_bad_mem
;
2240 else if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2242 else if (op
->value
.mem
.base_reg
.side
!= side
)
2243 return tic6x_match_bad_mem
;
2245 return tic6x_match_matches
;
2247 case tic6x_operand_mem_short
:
2248 case tic6x_operand_mem_ndw
:
2249 if (op
->value
.mem
.base_reg
.side
!= side
)
2250 return tic6x_match_bad_mem
;
2251 if (op
->value
.mem
.mod
== tic6x_mem_mod_none
)
2253 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2255 return tic6x_match_matches
;
2257 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
2259 if (op
->value
.mem
.mod
== tic6x_mem_mod_plus
2260 || op
->value
.mem
.mod
== tic6x_mem_mod_minus
)
2262 return tic6x_match_matches
;
2264 if (op
->value
.mem
.offset_is_reg
)
2266 if (op
->value
.mem
.scaled
== tic6x_offset_unscaled
2267 && form
!= tic6x_operand_mem_ndw
)
2269 if (op
->value
.mem
.offset
.reg
.side
== side
)
2270 return tic6x_match_matches
;
2272 return tic6x_match_bad_mem
;
2276 if (op
->value
.mem
.offset
.exp
.X_op
== O_constant
)
2277 return tic6x_match_matches
;
2279 return tic6x_match_bad_mem
;
2282 case tic6x_operand_mem_long
:
2283 if (op
->value
.mem
.base_reg
.side
== 2
2284 && (op
->value
.mem
.base_reg
.num
== 14
2285 || op
->value
.mem
.base_reg
.num
== 15))
2287 switch (op
->value
.mem
.mod
)
2289 case tic6x_mem_mod_none
:
2290 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2292 return tic6x_match_matches
;
2294 case tic6x_mem_mod_plus
:
2295 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
2297 if (op
->value
.mem
.offset_is_reg
)
2298 return tic6x_match_bad_mem
;
2299 else if (op
->value
.mem
.scaled
== tic6x_offset_scaled
2300 && op
->value
.mem
.offset
.exp
.X_op
!= O_constant
)
2301 return tic6x_match_bad_mem
;
2303 return tic6x_match_matches
;
2305 case tic6x_mem_mod_minus
:
2306 case tic6x_mem_mod_preinc
:
2307 case tic6x_mem_mod_predec
:
2308 case tic6x_mem_mod_postinc
:
2309 case tic6x_mem_mod_postdec
:
2310 return tic6x_match_bad_mem
;
2318 return tic6x_match_bad_mem
;
2325 /* Return the number of bits shift used with DP-relative coding method
2329 tic6x_dpr_shift (tic6x_coding_method coding
)
2333 case tic6x_coding_ulcst_dpr_byte
:
2336 case tic6x_coding_ulcst_dpr_half
:
2339 case tic6x_coding_ulcst_dpr_word
:
2347 /* Return the relocation used with DP-relative coding method
2350 static bfd_reloc_code_real_type
2351 tic6x_dpr_reloc (tic6x_coding_method coding
)
2355 case tic6x_coding_ulcst_dpr_byte
:
2356 return BFD_RELOC_C6000_SBR_U15_B
;
2358 case tic6x_coding_ulcst_dpr_half
:
2359 return BFD_RELOC_C6000_SBR_U15_H
;
2361 case tic6x_coding_ulcst_dpr_word
:
2362 return BFD_RELOC_C6000_SBR_U15_W
;
2369 /* Given a memory reference *MEM_REF as originally parsed, fill in
2370 defaults for missing offsets. */
2373 tic6x_default_mem_ref (tic6x_mem_ref
*mem_ref
)
2375 switch (mem_ref
->mod
)
2377 case tic6x_mem_mod_none
:
2378 if (mem_ref
->scaled
!= tic6x_offset_none
)
2380 mem_ref
->mod
= tic6x_mem_mod_plus
;
2381 mem_ref
->scaled
= tic6x_offset_unscaled
;
2382 mem_ref
->offset_is_reg
= FALSE
;
2383 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
2384 mem_ref
->offset
.exp
.X_op
= O_constant
;
2385 mem_ref
->offset
.exp
.X_add_number
= 0;
2386 mem_ref
->offset
.exp
.X_unsigned
= 0;
2389 case tic6x_mem_mod_plus
:
2390 case tic6x_mem_mod_minus
:
2391 if (mem_ref
->scaled
== tic6x_offset_none
)
2395 case tic6x_mem_mod_preinc
:
2396 case tic6x_mem_mod_predec
:
2397 case tic6x_mem_mod_postinc
:
2398 case tic6x_mem_mod_postdec
:
2399 if (mem_ref
->scaled
!= tic6x_offset_none
)
2401 mem_ref
->scaled
= tic6x_offset_scaled
;
2402 mem_ref
->offset_is_reg
= FALSE
;
2403 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
2404 mem_ref
->offset
.exp
.X_op
= O_constant
;
2405 mem_ref
->offset
.exp
.X_add_number
= 1;
2406 mem_ref
->offset
.exp
.X_unsigned
= 0;
2414 /* Return the encoding in the 8-bit field of an SPMASK or SPMASKR
2415 instruction of the specified UNIT, side SIDE. */
2418 tic6x_encode_spmask (tic6x_func_unit_base unit
, unsigned int side
)
2422 case tic6x_func_unit_l
:
2423 return 1 << (side
- 1);
2425 case tic6x_func_unit_s
:
2426 return 1 << (side
+ 1);
2428 case tic6x_func_unit_d
:
2429 return 1 << (side
+ 3);
2431 case tic6x_func_unit_m
:
2432 return 1 << (side
+ 5);
2439 /* Try to encode the instruction with opcode number ID and operands
2440 OPERANDS (number NUM_OPERANDS), creg value THIS_LINE_CREG and z
2441 value THIS_LINE_Z; FUNC_UNIT_SIDE, FUNC_UNIT_CROSS and
2442 FUNC_UNIT_DATA_SIDE describe the functional unit specification;
2443 SPLOOP_II is the ii value from the previous SPLOOP-family
2444 instruction, or 0 if not in such a loop; the only possible problems
2445 are operands being out of range (they already match the
2446 fine-grained form), and inappropriate predication. If this
2447 succeeds, return the encoding and set *OK to TRUE; otherwise return
2448 0 and set *OK to FALSE. If a fix is needed, set *FIX_NEEDED to
2449 true and fill in *FIX_EXP, *FIX_PCREL, *FX_R_TYPE and *FIX_ADDA.
2450 Print error messages for failure if PRINT_ERRORS is TRUE; the
2451 opcode starts at STR and has length OPC_LEN. */
2454 tic6x_try_encode (tic6x_opcode_id id
, tic6x_operand
*operands
,
2455 unsigned int num_operands
, unsigned int this_line_creg
,
2456 unsigned int this_line_z
, unsigned int func_unit_side
,
2457 unsigned int func_unit_cross
,
2458 unsigned int func_unit_data_side
, int sploop_ii
,
2459 expressionS
**fix_exp
, int *fix_pcrel
,
2460 bfd_reloc_code_real_type
*fx_r_type
, bfd_boolean
*fix_adda
,
2461 bfd_boolean
*fix_needed
, bfd_boolean
*ok
,
2462 bfd_boolean print_errors
, char *str
, int opc_len
)
2464 const tic6x_opcode
*opct
;
2465 const tic6x_insn_format
*fmt
;
2466 unsigned int opcode_value
;
2469 opct
= &tic6x_opcode_table
[id
];
2470 fmt
= &tic6x_insn_format_table
[opct
->format
];
2471 opcode_value
= fmt
->cst_bits
;
2473 for (fld
= 0; fld
< opct
->num_fixed_fields
; fld
++)
2475 if (opct
->fixed_fields
[fld
].min_val
== opct
->fixed_fields
[fld
].max_val
)
2477 const tic6x_insn_field
*fldd
;
2478 fldd
= tic6x_field_from_fmt (fmt
, opct
->fixed_fields
[fld
].field_id
);
2481 opcode_value
|= opct
->fixed_fields
[fld
].min_val
<< fldd
->bitfields
[0].low_pos
;
2485 for (fld
= 0; fld
< opct
->num_variable_fields
; fld
++)
2487 const tic6x_insn_field
*fldd
;
2493 unsigned int fcyc_bits
;
2498 fldd
= tic6x_field_from_fmt (fmt
, opct
->variable_fields
[fld
].field_id
);
2501 opno
= opct
->variable_fields
[fld
].operand_num
;
2502 switch (opct
->variable_fields
[fld
].coding_method
)
2504 case tic6x_coding_ucst
:
2505 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2507 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2509 ucexp
= operands
[opno
].value
.exp
;
2511 if (ucexp
.X_add_number
< 0
2512 || ucexp
.X_add_number
>= (1 << fldd
->bitfields
[0].width
))
2515 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2520 value
= ucexp
.X_add_number
;
2523 case tic6x_coding_scst
:
2524 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2526 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2529 /* Opcode table should not permit non-constants without
2530 a known relocation for them. */
2531 if (fldd
->bitfields
[0].low_pos
!= 7 || fldd
->bitfields
[0].width
!= 16)
2534 *fix_exp
= &operands
[opno
].value
.exp
;
2536 *fx_r_type
= BFD_RELOC_C6000_ABS_S16
;
2540 sign_value
= SEXT (operands
[opno
].value
.exp
.X_add_number
);
2542 if (sign_value
< -(1 << (fldd
->bitfields
[0].width
- 1))
2543 || (sign_value
>= (1 << (fldd
->bitfields
[0].width
- 1))))
2546 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2551 value
= sign_value
+ (1 << (fldd
->bitfields
[0].width
- 1));
2552 value
^= (1 << (fldd
->bitfields
[0].width
- 1));
2555 case tic6x_coding_ucst_minus_one
:
2556 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2558 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2560 if (operands
[opno
].value
.exp
.X_add_number
<= 0
2561 || operands
[opno
].value
.exp
.X_add_number
> (1 << fldd
->bitfields
[0].width
))
2564 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2569 value
= operands
[opno
].value
.exp
.X_add_number
- 1;
2572 case tic6x_coding_scst_negate
:
2573 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2575 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2577 sign_value
= SEXT (-operands
[opno
].value
.exp
.X_add_number
);
2578 goto signed_constant
;
2580 case tic6x_coding_ulcst_dpr_byte
:
2581 case tic6x_coding_ulcst_dpr_half
:
2582 case tic6x_coding_ulcst_dpr_word
:
2583 bits
= tic6x_dpr_shift (opct
->variable_fields
[fld
].coding_method
);
2584 switch (operands
[opno
].form
)
2587 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2589 ucexp
= operands
[opno
].value
.exp
;
2590 goto unsigned_constant
;
2592 expp
= &operands
[opno
].value
.exp
;
2595 case TIC6X_OP_MEM_NOUNREG
:
2596 mem
= operands
[opno
].value
.mem
;
2597 tic6x_default_mem_ref (&mem
);
2598 if (mem
.offset_is_reg
)
2600 if (mem
.offset
.exp
.X_op
== O_constant
)
2602 ucexp
= mem
.offset
.exp
;
2603 if (mem
.scaled
== tic6x_offset_unscaled
)
2605 if (ucexp
.X_add_number
& ((1 << bits
) - 1))
2608 as_bad (_("offset in operand %u of '%.*s' not "
2609 "divisible by %u"), opno
+ 1, opc_len
,
2614 ucexp
.X_add_number
>>= bits
;
2616 goto unsigned_constant
;
2618 if (mem
.scaled
!= tic6x_offset_unscaled
)
2620 if (operands
[opno
].value
.mem
.mod
== tic6x_mem_mod_none
2621 || operands
[opno
].value
.mem
.scaled
!= tic6x_offset_unscaled
2622 || operands
[opno
].value
.mem
.offset_is_reg
)
2624 expp
= &operands
[opno
].value
.mem
.offset
.exp
;
2631 /* Opcode table should not use this encoding without a known
2633 if (fldd
->bitfields
[0].low_pos
!= 8 || fldd
->bitfields
[0].width
!= 15)
2635 /* We do not check for offset divisibility here; such a
2636 check is not needed at this point to encode the value,
2637 and if there is eventually a problem it will be detected
2638 either in md_apply_fix or at link time. */
2643 = tic6x_dpr_reloc (opct
->variable_fields
[fld
].coding_method
);
2644 if (operands
[opno
].form
== TIC6X_OP_EXP
)
2650 case tic6x_coding_lcst_low16
:
2651 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2653 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2654 value
= operands
[opno
].value
.exp
.X_add_number
& 0xffff;
2658 /* Opcode table should not use this encoding without a
2659 known relocation. */
2660 if (fldd
->bitfields
[0].low_pos
!= 7 || fldd
->bitfields
[0].width
!= 16)
2663 *fix_exp
= &operands
[opno
].value
.exp
;
2665 *fx_r_type
= BFD_RELOC_C6000_ABS_L16
;
2670 case tic6x_coding_lcst_high16
:
2671 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2673 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2674 value
= (operands
[opno
].value
.exp
.X_add_number
>> 16) & 0xffff;
2678 /* Opcode table should not use this encoding without a
2679 known relocation. */
2680 if (fldd
->bitfields
[0].low_pos
!= 7 || fldd
->bitfields
[0].width
!= 16)
2683 *fix_exp
= &operands
[opno
].value
.exp
;
2685 *fx_r_type
= BFD_RELOC_C6000_ABS_H16
;
2690 case tic6x_coding_pcrel
:
2691 case tic6x_coding_pcrel_half
:
2692 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2696 *fix_exp
= &operands
[opno
].value
.exp
;
2698 if (fldd
->bitfields
[0].low_pos
== 7 && fldd
->bitfields
[0].width
== 21)
2699 *fx_r_type
= BFD_RELOC_C6000_PCR_S21
;
2700 else if (fldd
->bitfields
[0].low_pos
== 16 && fldd
->bitfields
[0].width
== 12)
2701 *fx_r_type
= BFD_RELOC_C6000_PCR_S12
;
2702 else if (fldd
->bitfields
[0].low_pos
== 13 && fldd
->bitfields
[0].width
== 10)
2703 *fx_r_type
= BFD_RELOC_C6000_PCR_S10
;
2704 else if (fldd
->bitfields
[0].low_pos
== 16 && fldd
->bitfields
[0].width
== 7)
2705 *fx_r_type
= BFD_RELOC_C6000_PCR_S7
;
2707 /* Opcode table should not use this encoding without a
2708 known relocation. */
2713 case tic6x_coding_regpair_lsb
:
2714 switch (operands
[opno
].form
)
2716 case TIC6X_OP_REGPAIR
:
2717 value
= operands
[opno
].value
.reg
.num
;
2725 case tic6x_coding_regpair_msb
:
2726 switch (operands
[opno
].form
)
2728 case TIC6X_OP_REGPAIR
:
2729 value
= operands
[opno
].value
.reg
.num
+ 1;
2737 case tic6x_coding_reg
:
2738 switch (operands
[opno
].form
)
2741 case TIC6X_OP_REGPAIR
:
2742 value
= operands
[opno
].value
.reg
.num
;
2745 case TIC6X_OP_MEM_NOUNREG
:
2746 case TIC6X_OP_MEM_UNREG
:
2747 value
= operands
[opno
].value
.mem
.base_reg
.num
;
2755 case tic6x_coding_areg
:
2756 switch (operands
[opno
].form
)
2759 value
= (operands
[opno
].value
.reg
.num
== 15 ? 1 : 0);
2762 case TIC6X_OP_MEM_NOUNREG
:
2763 value
= (operands
[opno
].value
.mem
.base_reg
.num
== 15 ? 1 : 0);
2771 case tic6x_coding_crlo
:
2772 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2774 value
= tic6x_ctrl_table
[operands
[opno
].value
.ctrl
].crlo
;
2777 case tic6x_coding_crhi
:
2778 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2783 case tic6x_coding_reg_shift
:
2784 if (operands
[opno
].form
!= TIC6X_OP_REGPAIR
)
2786 value
= operands
[opno
].value
.reg
.num
>> 1;
2789 case tic6x_coding_mem_offset
:
2790 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
)
2792 mem
= operands
[opno
].value
.mem
;
2793 tic6x_default_mem_ref (&mem
);
2794 if (mem
.offset_is_reg
)
2796 if (mem
.scaled
!= tic6x_offset_scaled
)
2798 value
= mem
.offset
.reg
.num
;
2804 if (mem
.offset
.exp
.X_op
!= O_constant
)
2808 case tic6x_offset_scaled
:
2812 case tic6x_offset_unscaled
:
2813 scale
= opct
->operand_info
[opno
].size
;
2814 if (scale
!= 1 && scale
!= 2 && scale
!= 4 && scale
!= 8)
2821 if (mem
.offset
.exp
.X_add_number
< 0
2822 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->bitfields
[0].width
) * scale
)
2825 as_bad (_("offset in operand %u of '%.*s' out of range"),
2826 opno
+ 1, opc_len
, str
);
2830 if (mem
.offset
.exp
.X_add_number
% scale
)
2833 as_bad (_("offset in operand %u of '%.*s' not "
2835 opno
+ 1, opc_len
, str
, scale
);
2839 value
= mem
.offset
.exp
.X_add_number
/ scale
;
2843 case tic6x_coding_mem_offset_noscale
:
2844 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2846 mem
= operands
[opno
].value
.mem
;
2847 tic6x_default_mem_ref (&mem
);
2848 if (mem
.offset_is_reg
)
2849 value
= mem
.offset
.reg
.num
;
2852 if (mem
.offset
.exp
.X_op
!= O_constant
)
2854 if (mem
.offset
.exp
.X_add_number
< 0
2855 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->bitfields
[0].width
))
2858 as_bad (_("offset in operand %u of '%.*s' out of range"),
2859 opno
+ 1, opc_len
, str
);
2863 value
= mem
.offset
.exp
.X_add_number
;
2867 case tic6x_coding_mem_mode
:
2868 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
2869 && operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2871 mem
= operands
[opno
].value
.mem
;
2872 tic6x_default_mem_ref (&mem
);
2875 case tic6x_mem_mod_plus
:
2879 case tic6x_mem_mod_minus
:
2883 case tic6x_mem_mod_preinc
:
2887 case tic6x_mem_mod_predec
:
2891 case tic6x_mem_mod_postinc
:
2895 case tic6x_mem_mod_postdec
:
2902 value
+= (mem
.offset_is_reg
? 4 : 0);
2905 case tic6x_coding_scaled
:
2906 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2908 mem
= operands
[opno
].value
.mem
;
2909 tic6x_default_mem_ref (&mem
);
2912 case tic6x_offset_unscaled
:
2916 case tic6x_offset_scaled
:
2925 case tic6x_coding_spmask
:
2926 /* The position of such a field is hardcoded in the handling
2928 if (fldd
->bitfields
[0].low_pos
!= 18)
2931 for (opno
= 0; opno
< num_operands
; opno
++)
2935 v
= tic6x_encode_spmask (operands
[opno
].value
.func_unit
.base
,
2936 operands
[opno
].value
.func_unit
.side
);
2940 as_bad (_("functional unit already masked for operand "
2941 "%u of '%.*s'"), opno
+ 1, opc_len
, str
);
2949 case tic6x_coding_reg_unused
:
2950 /* This is a placeholder; correct handling goes along with
2951 resource constraint checks. */
2955 case tic6x_coding_fstg
:
2956 case tic6x_coding_fcyc
:
2957 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2959 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2964 as_bad (_("'%.*s' instruction not in a software "
2973 else if (sploop_ii
<= 2)
2975 else if (sploop_ii
<= 4)
2977 else if (sploop_ii
<= 8)
2979 else if (sploop_ii
<= 14)
2983 if (fcyc_bits
> fldd
->bitfields
[0].width
)
2986 if (opct
->variable_fields
[fld
].coding_method
== tic6x_coding_fstg
)
2989 if (operands
[opno
].value
.exp
.X_add_number
< 0
2990 || (operands
[opno
].value
.exp
.X_add_number
2991 >= (1 << (fldd
->bitfields
[0].width
- fcyc_bits
))))
2994 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2999 value
= operands
[opno
].value
.exp
.X_add_number
;
3000 for (t
= 0, i
= fcyc_bits
; i
< fldd
->bitfields
[0].width
; i
++)
3002 t
= (t
<< 1) | (value
& 1);
3005 value
= t
<< fcyc_bits
;
3009 if (operands
[opno
].value
.exp
.X_add_number
< 0
3010 || (operands
[opno
].value
.exp
.X_add_number
>= sploop_ii
))
3013 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
3018 value
= operands
[opno
].value
.exp
.X_add_number
;
3022 case tic6x_coding_fu
:
3023 value
= func_unit_side
== 2 ? 1 : 0;
3026 case tic6x_coding_data_fu
:
3027 value
= func_unit_data_side
== 2 ? 1 : 0;
3030 case tic6x_coding_xpath
:
3031 value
= func_unit_cross
;
3038 for (ffld
= 0; ffld
< opct
->num_fixed_fields
; ffld
++)
3039 if ((opct
->fixed_fields
[ffld
].field_id
3040 == opct
->variable_fields
[fld
].field_id
)
3041 && (value
< opct
->fixed_fields
[ffld
].min_val
3042 || value
> opct
->fixed_fields
[ffld
].max_val
))
3045 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
3051 opcode_value
|= value
<< fldd
->bitfields
[0].low_pos
;
3056 const tic6x_insn_field
*creg
;
3057 const tic6x_insn_field
*z
;
3059 creg
= tic6x_field_from_fmt (fmt
, tic6x_field_creg
);
3063 as_bad (_("instruction '%.*s' cannot be predicated"),
3068 z
= tic6x_field_from_fmt (fmt
, tic6x_field_z
);
3069 /* If there is a creg field, there must be a z field; otherwise
3070 there is an error in the format table. */
3074 opcode_value
|= this_line_creg
<< creg
->bitfields
[0].low_pos
;
3075 opcode_value
|= this_line_z
<< z
->bitfields
[0].low_pos
;
3079 return opcode_value
;
3082 /* Convert the target integer stored in N bytes in BUF to a host
3083 integer, returning that value. */
3086 md_chars_to_number (char *buf
, int n
)
3089 unsigned char *p
= (unsigned char *) buf
;
3091 if (target_big_endian
)
3096 result
|= (*p
++ & 0xff);
3104 result
|= (p
[n
] & 0xff);
3111 /* Assemble the instruction starting at STR (an opcode, with the
3112 opcode name all-lowercase). */
3115 md_assemble (char *str
)
3119 bfd_boolean this_line_parallel
;
3120 bfd_boolean this_line_spmask
;
3121 unsigned int this_line_creg
;
3122 unsigned int this_line_z
;
3123 tic6x_label_list
*this_insn_label_list
;
3124 segment_info_type
*seginfo
;
3125 tic6x_opcode_list
*opc_list
, *opc
;
3126 tic6x_func_unit_base func_unit_base
= tic6x_func_unit_nfu
;
3127 unsigned int func_unit_side
= 0;
3128 unsigned int func_unit_cross
= 0;
3129 unsigned int cross_side
= 0;
3130 unsigned int func_unit_data_side
= 0;
3131 unsigned int max_matching_opcodes
, num_matching_opcodes
;
3132 tic6x_opcode_id
*opcm
= NULL
;
3133 unsigned int opc_rank
[TIC6X_NUM_PREFER
];
3134 const tic6x_opcode
*opct
= NULL
;
3135 int min_rank
, try_rank
, max_rank
;
3136 bfd_boolean num_operands_permitted
[TIC6X_MAX_SOURCE_OPERANDS
+ 1]
3138 unsigned int operand_forms
[TIC6X_MAX_SOURCE_OPERANDS
] = { 0 };
3139 tic6x_operand operands
[TIC6X_MAX_SOURCE_OPERANDS
];
3140 unsigned int max_num_operands
;
3141 unsigned int num_operands_read
;
3142 bfd_boolean ok_this_arch
, ok_this_fu
, ok_this_arch_fu
;
3143 bfd_boolean bad_operands
= FALSE
;
3144 unsigned int opcode_value
;
3145 bfd_boolean encoded_ok
;
3146 bfd_boolean fix_needed
= FALSE
;
3147 expressionS
*fix_exp
= NULL
;
3149 bfd_reloc_code_real_type fx_r_type
= BFD_RELOC_UNUSED
;
3150 bfd_boolean fix_adda
= FALSE
;
3155 while (*p
&& !is_end_of_line
[(unsigned char) *p
] && *p
!= ' ')
3158 /* This function should only have been called when there is actually
3159 an instruction to assemble. */
3163 /* Now an instruction has been seen, architecture attributes from
3164 .arch directives merge with rather than overriding the previous
3166 tic6x_seen_insns
= TRUE
;
3167 /* If no .arch directives or -march options have been seen, we are
3168 assessing instruction validity based on the C674X default, so set
3169 the attribute accordingly. */
3170 if (tic6x_arch_attribute
== C6XABI_Tag_ISA_none
)
3171 tic6x_arch_attribute
= C6XABI_Tag_ISA_C674X
;
3173 /* Reset global settings for parallel bars and predicates now to
3174 avoid extra errors if there are problems with this opcode. */
3175 this_line_parallel
= tic6x_line_parallel
;
3176 this_line_spmask
= tic6x_line_spmask
;
3177 this_line_creg
= tic6x_line_creg
;
3178 this_line_z
= tic6x_line_z
;
3179 tic6x_line_parallel
= FALSE
;
3180 tic6x_line_spmask
= FALSE
;
3181 tic6x_line_creg
= 0;
3183 seginfo
= seg_info (now_seg
);
3184 this_insn_label_list
= seginfo
->tc_segment_info_data
.label_list
;
3185 seginfo
->tc_segment_info_data
.label_list
= NULL
;
3187 opc_list
= str_hash_find_n (opcode_hash
, str
, p
- str
);
3188 if (opc_list
== NULL
)
3192 as_bad (_("unknown opcode '%s'"), str
);
3198 skip_whitespace (p
);
3200 /* See if there is something that looks like a functional unit
3204 bfd_boolean good_func_unit
;
3205 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
3206 unsigned int maybe_side
= 0;
3207 unsigned int maybe_cross
= 0;
3208 unsigned int maybe_data_side
= 0;
3210 good_func_unit
= tic6x_parse_func_unit_base (p
+ 1, &maybe_base
,
3215 if (p
[3] == ' ' || is_end_of_line
[(unsigned char) p
[3]])
3217 else if ((p
[3] == 'x' || p
[3] == 'X')
3218 && (p
[4] == ' ' || is_end_of_line
[(unsigned char) p
[4]]))
3223 else if (maybe_base
== tic6x_func_unit_d
3224 && (p
[3] == 't' || p
[3] == 'T')
3225 && (p
[4] == '1' || p
[4] == '2')
3226 && (p
[5] == ' ' || is_end_of_line
[(unsigned char) p
[5]]))
3228 maybe_data_side
= p
[4] - '0';
3232 good_func_unit
= FALSE
;
3237 func_unit_base
= maybe_base
;
3238 func_unit_side
= maybe_side
;
3239 func_unit_cross
= maybe_cross
;
3240 cross_side
= (func_unit_cross
? 3 - func_unit_side
: func_unit_side
);
3241 func_unit_data_side
= maybe_data_side
;
3244 skip_whitespace (p
);
3247 /* Determine which entries in the opcode table match, and the
3248 associated permitted forms of operands. */
3249 max_matching_opcodes
= 0;
3250 for (opc
= opc_list
; opc
; opc
= opc
->next
)
3251 max_matching_opcodes
++;
3252 num_matching_opcodes
= 0;
3253 opcm
= XNEWVEC (tic6x_opcode_id
, max_matching_opcodes
);
3254 max_num_operands
= 0;
3255 ok_this_arch
= FALSE
;
3257 ok_this_arch_fu
= FALSE
;
3258 for (opc
= opc_list
; opc
; opc
= opc
->next
)
3260 unsigned int num_operands
;
3262 bfd_boolean this_opc_arch_ok
= TRUE
;
3263 bfd_boolean this_opc_fu_ok
= TRUE
;
3265 if (tic6x_insn_format_table
[tic6x_opcode_table
[opc
->id
].format
].num_bits
3268 if (!(tic6x_opcode_table
[opc
->id
].isa_variants
& tic6x_features
))
3269 this_opc_arch_ok
= FALSE
;
3270 if (tic6x_opcode_table
[opc
->id
].func_unit
!= func_unit_base
)
3271 this_opc_fu_ok
= FALSE
;
3272 if (func_unit_side
== 1
3273 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_B_ONLY
))
3274 this_opc_fu_ok
= FALSE
;
3276 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_NO_CROSS
))
3277 this_opc_fu_ok
= FALSE
;
3278 if (!func_unit_data_side
3279 && (tic6x_opcode_table
[opc
->id
].flags
3280 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
3281 this_opc_fu_ok
= FALSE
;
3282 if (func_unit_data_side
3283 && !(tic6x_opcode_table
[opc
->id
].flags
3284 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
3285 this_opc_fu_ok
= FALSE
;
3286 if (func_unit_data_side
== 1
3287 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_T2_ONLY
))
3288 this_opc_fu_ok
= FALSE
;
3289 if (this_opc_arch_ok
)
3290 ok_this_arch
= TRUE
;
3293 if (!this_opc_arch_ok
|| !this_opc_fu_ok
)
3295 ok_this_arch_fu
= TRUE
;
3296 opcm
[num_matching_opcodes
] = opc
->id
;
3297 num_matching_opcodes
++;
3298 num_operands
= tic6x_opcode_table
[opc
->id
].num_operands
;
3300 if (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SPMASK
)
3302 if (num_operands
!= 1
3303 || (tic6x_opcode_table
[opc
->id
].operand_info
[0].form
3304 != tic6x_operand_func_unit
))
3307 for (i
= 0; i
< num_operands
; i
++)
3310 |= tic6x_coarse_operand_form (tic6x_operand_func_unit
);
3311 num_operands_permitted
[i
] = TRUE
;
3316 for (i
= 0; i
< num_operands
; i
++)
3318 tic6x_operand_form f
3319 = tic6x_opcode_table
[opc
->id
].operand_info
[i
].form
;
3321 operand_forms
[i
] |= tic6x_coarse_operand_form (f
);
3324 num_operands_permitted
[num_operands
] = TRUE
;
3325 if (num_operands
> max_num_operands
)
3326 max_num_operands
= num_operands
;
3331 as_bad (_("'%.*s' instruction not supported on this architecture"),
3339 as_bad (_("'%.*s' instruction not supported on this functional unit"),
3345 if (!ok_this_arch_fu
)
3347 as_bad (_("'%.*s' instruction not supported on this functional unit"
3348 " for this architecture"),
3354 /* If there were no instructions matching the above availability
3355 checks, we should now have given an error and returned. */
3356 if (num_matching_opcodes
== 0)
3359 num_operands_read
= 0;
3362 skip_whitespace (p
);
3363 if (is_end_of_line
[(unsigned char) *p
])
3365 if (num_operands_read
> 0)
3367 as_bad (_("missing operand after comma"));
3368 bad_operands
= TRUE
;
3373 if (max_num_operands
== 0)
3375 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
3376 bad_operands
= TRUE
;
3380 if (!tic6x_parse_operand (&p
, &operands
[num_operands_read
],
3381 operand_forms
[num_operands_read
], str
, opc_len
,
3382 num_operands_read
+ 1))
3383 bad_operands
= TRUE
;
3384 num_operands_read
++;
3386 if (is_end_of_line
[(unsigned char) *p
])
3391 if (num_operands_read
== max_num_operands
)
3393 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
3394 bad_operands
= TRUE
;
3400 /* Operand parsing should consume whole operands. */
3404 if (!bad_operands
&& !num_operands_permitted
[num_operands_read
])
3406 as_bad (_("bad number of operands to '%.*s'"), opc_len
, str
);
3407 bad_operands
= TRUE
;
3412 /* Each operand is of the right syntactic form for some opcode
3413 choice, and the number of operands is valid. Check that each
3414 operand is OK in detail for some opcode choice with the right
3415 number of operands. */
3418 for (i
= 0; i
< num_operands_read
; i
++)
3420 bfd_boolean coarse_ok
= FALSE
;
3421 bfd_boolean fine_ok
= FALSE
;
3422 tic6x_operand_match fine_failure
= tic6x_match_matches
;
3425 for (j
= 0; j
< num_matching_opcodes
; j
++)
3427 tic6x_operand_form f
;
3430 tic6x_operand_match this_fine_failure
;
3432 if (tic6x_opcode_table
[opcm
[j
]].flags
& TIC6X_FLAG_SPMASK
)
3434 f
= tic6x_operand_func_unit
;
3439 if (tic6x_opcode_table
[opcm
[j
]].num_operands
3440 != num_operands_read
)
3443 f
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].form
;
3444 rw
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].rw
;
3446 cf
= tic6x_coarse_operand_form (f
);
3448 if (operands
[i
].form
!= cf
)
3453 = tic6x_operand_matches_form (&operands
[i
], f
, rw
,
3456 func_unit_data_side
);
3457 if (this_fine_failure
== tic6x_match_matches
)
3462 if (fine_failure
== tic6x_match_matches
3463 || fine_failure
> this_fine_failure
)
3464 fine_failure
= this_fine_failure
;
3467 /* No instructions should have operand syntactic forms only
3468 acceptable with certain numbers of operands, so no
3469 diagnostic for this case. */
3475 switch (fine_failure
)
3477 case tic6x_match_non_const
:
3478 as_bad (_("operand %u of '%.*s' not constant"),
3479 i
+ 1, opc_len
, str
);
3482 case tic6x_match_wrong_side
:
3483 as_bad (_("operand %u of '%.*s' on wrong side"),
3484 i
+ 1, opc_len
, str
);
3487 case tic6x_match_bad_return
:
3488 as_bad (_("operand %u of '%.*s' not a valid return "
3489 "address register"),
3490 i
+ 1, opc_len
, str
);
3493 case tic6x_match_ctrl_write_only
:
3494 as_bad (_("operand %u of '%.*s' is write-only"),
3495 i
+ 1, opc_len
, str
);
3498 case tic6x_match_ctrl_read_only
:
3499 as_bad (_("operand %u of '%.*s' is read-only"),
3500 i
+ 1, opc_len
, str
);
3503 case tic6x_match_bad_mem
:
3504 as_bad (_("operand %u of '%.*s' not a valid memory "
3506 i
+ 1, opc_len
, str
);
3509 case tic6x_match_bad_address
:
3510 as_bad (_("operand %u of '%.*s' not a valid base "
3511 "address register"),
3512 i
+ 1, opc_len
, str
);
3518 bad_operands
= TRUE
;
3526 /* Each operand is OK for some opcode choice, and the number of
3527 operands is valid. Check whether there is an opcode choice
3528 for which all operands are simultaneously valid. */
3530 bfd_boolean found_match
= FALSE
;
3532 for (i
= 0; i
< TIC6X_NUM_PREFER
; i
++)
3533 opc_rank
[i
] = (unsigned int) -1;
3535 min_rank
= TIC6X_NUM_PREFER
- 1;
3538 for (i
= 0; i
< num_matching_opcodes
; i
++)
3541 bfd_boolean this_matches
= TRUE
;
3543 if (!(tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3544 && tic6x_opcode_table
[opcm
[i
]].num_operands
!= num_operands_read
)
3547 for (j
= 0; j
< num_operands_read
; j
++)
3549 tic6x_operand_form f
;
3552 if (tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3554 f
= tic6x_operand_func_unit
;
3559 f
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].form
;
3560 rw
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].rw
;
3562 if (tic6x_operand_matches_form (&operands
[j
], f
, rw
,
3565 func_unit_data_side
)
3566 != tic6x_match_matches
)
3568 this_matches
= FALSE
;
3575 int rank
= TIC6X_PREFER_VAL (tic6x_opcode_table
[opcm
[i
]].flags
);
3577 if (rank
< min_rank
)
3579 if (rank
> max_rank
)
3582 if (opc_rank
[rank
] == (unsigned int) -1)
3585 /* The opcode table should provide a total ordering
3586 for all cases where multiple matches may get
3596 as_bad (_("bad operand combination for '%.*s'"), opc_len
, str
);
3597 bad_operands
= TRUE
;
3609 for (try_rank
= max_rank
; try_rank
>= min_rank
; try_rank
--)
3613 if (opc_rank
[try_rank
] == (unsigned int) -1)
3616 opcode_value
= tic6x_try_encode (opcm
[opc_rank
[try_rank
]], operands
,
3617 num_operands_read
, this_line_creg
,
3618 this_line_z
, func_unit_side
,
3619 func_unit_cross
, func_unit_data_side
,
3620 seginfo
->tc_segment_info_data
.sploop_ii
,
3621 &fix_exp
, &fix_pcrel
, &fx_r_type
,
3622 &fix_adda
, &fix_needed
, &encoded_ok
,
3623 (try_rank
== min_rank
? TRUE
: FALSE
),
3627 opct
= &tic6x_opcode_table
[opcm
[opc_rank
[try_rank
]]];
3637 if (this_line_parallel
)
3639 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
;
3640 if (insn_frag
== NULL
)
3642 as_bad (_("parallel instruction not following another instruction"));
3646 if (insn_frag
->fr_fix
>= 32)
3648 as_bad (_("too many instructions in execute packet"));
3652 if (this_insn_label_list
!= NULL
)
3653 as_bad (_("label not at start of execute packet"));
3655 if (opct
->flags
& TIC6X_FLAG_FIRST
)
3656 as_bad (_("'%.*s' instruction not at start of execute packet"),
3659 *seginfo
->tc_segment_info_data
.last_insn_lsb
|= 0x1;
3660 output
= insn_frag
->fr_literal
+ insn_frag
->fr_fix
;
3664 tic6x_label_list
*l
;
3666 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
3667 seginfo
->tc_segment_info_data
.func_units_used
= 0;
3669 /* Start a new frag for this execute packet. */
3670 if (frag_now_fix () != 0)
3672 if (frag_now
->fr_type
!= rs_machine_dependent
)
3673 frag_wane (frag_now
);
3678 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
= frag_now
;
3679 for (l
= this_insn_label_list
; l
; l
= l
->next
)
3681 symbol_set_frag (l
->label
, frag_now
);
3682 S_SET_VALUE (l
->label
, 0);
3683 S_SET_SEGMENT (l
->label
, now_seg
);
3685 tic6x_free_label_list (this_insn_label_list
);
3686 dwarf2_emit_insn (0);
3687 output
= frag_var (rs_machine_dependent
, 32, 32, 0, NULL
, 0, NULL
);
3688 /* This must be the same as the frag to which a pointer was just
3690 if (output
!= insn_frag
->fr_literal
)
3692 insn_frag
->tc_frag_data
.is_insns
= TRUE
;
3693 insn_frag
->tc_frag_data
.can_cross_fp_boundary
3694 = tic6x_can_cross_fp_boundary
;
3697 if (func_unit_base
!= tic6x_func_unit_nfu
)
3699 unsigned int func_unit_enc
;
3701 func_unit_enc
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3703 if (seginfo
->tc_segment_info_data
.func_units_used
& func_unit_enc
)
3704 as_bad (_("functional unit already used in this execute packet"));
3706 seginfo
->tc_segment_info_data
.func_units_used
|= func_unit_enc
;
3709 if (opct
->flags
& TIC6X_FLAG_SPLOOP
)
3711 if (seginfo
->tc_segment_info_data
.sploop_ii
)
3712 as_bad (_("nested software pipelined loop"));
3713 if (num_operands_read
!= 1
3714 || operands
[0].form
!= TIC6X_OP_EXP
3715 || operands
[0].value
.exp
.X_op
!= O_constant
)
3717 seginfo
->tc_segment_info_data
.sploop_ii
3718 = operands
[0].value
.exp
.X_add_number
;
3720 else if (opct
->flags
& TIC6X_FLAG_SPKERNEL
)
3722 if (!seginfo
->tc_segment_info_data
.sploop_ii
)
3723 as_bad (_("'%.*s' instruction not in a software pipelined loop"),
3725 seginfo
->tc_segment_info_data
.sploop_ii
= 0;
3728 if (this_line_spmask
)
3730 if (seginfo
->tc_segment_info_data
.spmask_addr
== NULL
)
3731 as_bad (_("'||^' without previous SPMASK"));
3732 else if (func_unit_base
== tic6x_func_unit_nfu
)
3733 as_bad (_("cannot mask instruction using no functional unit"));
3736 unsigned int spmask_opcode
;
3737 unsigned int mask_bit
;
3740 = md_chars_to_number (seginfo
->tc_segment_info_data
.spmask_addr
,
3742 mask_bit
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3744 if (spmask_opcode
& mask_bit
)
3745 as_bad (_("functional unit already masked"));
3746 spmask_opcode
|= mask_bit
;
3747 md_number_to_chars (seginfo
->tc_segment_info_data
.spmask_addr
,
3752 record_alignment (now_seg
, 5);
3753 md_number_to_chars (output
, opcode_value
, 4);
3755 tic6x_fix_new_exp (insn_frag
, output
- insn_frag
->fr_literal
, 4, fix_exp
,
3756 fix_pcrel
, fx_r_type
, fix_adda
);
3757 insn_frag
->fr_fix
+= 4;
3758 insn_frag
->fr_var
-= 4;
3759 seginfo
->tc_segment_info_data
.last_insn_lsb
3760 = (target_big_endian
? output
+ 3 : output
);
3761 if (opct
->flags
& TIC6X_FLAG_SPMASK
)
3762 seginfo
->tc_segment_info_data
.spmask_addr
= output
;
3765 /* Modify NEWVAL (32-bit) by inserting VALUE, shifted right by SHIFT
3766 and the least significant BITS bits taken, at position POS. */
3767 #define MODIFY_VALUE(NEWVAL, VALUE, SHIFT, POS, BITS) \
3769 (NEWVAL) &= 0xffffffffU & ~(((1U << (BITS)) - 1) << (POS)); \
3770 (NEWVAL) |= (((VALUE) >> (SHIFT)) & ((1U << (BITS)) - 1)) << (POS); \
3773 /* Apply a fixup to the object file. */
3776 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3778 offsetT value
= *valP
;
3779 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3781 value
= SEXT (value
);
3784 fixP
->fx_offset
= SEXT (fixP
->fx_offset
);
3786 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3789 /* We do our own overflow checks. */
3790 fixP
->fx_no_overflow
= 1;
3792 switch (fixP
->fx_r_type
)
3794 case BFD_RELOC_NONE
:
3795 case BFD_RELOC_C6000_EHTYPE
:
3796 /* Force output to the object file. */
3801 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3802 md_number_to_chars (buf
, value
, 4);
3806 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3808 if (value
< -0x8000 || value
> 0xffff)
3809 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3810 _("value too large for 2-byte field"));
3811 md_number_to_chars (buf
, value
, 2);
3816 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3818 if (value
< -0x80 || value
> 0xff)
3819 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3820 _("value too large for 1-byte field"));
3825 case BFD_RELOC_C6000_ABS_S16
:
3826 case BFD_RELOC_C6000_ABS_L16
:
3827 case BFD_RELOC_C6000_SBR_S16
:
3828 case BFD_RELOC_C6000_SBR_L16_B
:
3829 case BFD_RELOC_C6000_SBR_L16_H
:
3830 case BFD_RELOC_C6000_SBR_L16_W
:
3831 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3832 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3834 offsetT newval
= md_chars_to_number (buf
, 4);
3837 switch (fixP
->fx_r_type
)
3839 case BFD_RELOC_C6000_SBR_L16_H
:
3843 case BFD_RELOC_C6000_SBR_L16_W
:
3844 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3853 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3854 if ((value
< -0x8000 || value
> 0x7fff)
3855 && (fixP
->fx_r_type
== BFD_RELOC_C6000_ABS_S16
3856 || fixP
->fx_r_type
== BFD_RELOC_C6000_SBR_S16
))
3857 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3858 _("immediate offset out of range"));
3860 md_number_to_chars (buf
, newval
, 4);
3863 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_S16
3864 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_L16
)
3868 case BFD_RELOC_C6000_ABS_H16
:
3869 case BFD_RELOC_C6000_SBR_H16_B
:
3870 case BFD_RELOC_C6000_SBR_H16_H
:
3871 case BFD_RELOC_C6000_SBR_H16_W
:
3872 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3873 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3875 offsetT newval
= md_chars_to_number (buf
, 4);
3878 switch (fixP
->fx_r_type
)
3880 case BFD_RELOC_C6000_SBR_H16_H
:
3884 case BFD_RELOC_C6000_SBR_H16_W
:
3885 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3894 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3896 md_number_to_chars (buf
, newval
, 4);
3898 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_H16
)
3902 case BFD_RELOC_C6000_PCR_H16
:
3903 case BFD_RELOC_C6000_PCR_L16
:
3904 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3906 offsetT newval
= md_chars_to_number (buf
, 4);
3907 int shift
= fixP
->fx_r_type
== BFD_RELOC_C6000_PCR_H16
? 16 : 0;
3909 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3911 md_number_to_chars (buf
, newval
, 4);
3915 case BFD_RELOC_C6000_SBR_U15_B
:
3916 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3918 offsetT newval
= md_chars_to_number (buf
, 4);
3920 MODIFY_VALUE (newval
, value
, 0, 8, 15);
3921 if (value
< 0 || value
> 0x7fff)
3922 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3923 _("immediate offset out of range"));
3925 md_number_to_chars (buf
, newval
, 4);
3929 case BFD_RELOC_C6000_SBR_U15_H
:
3930 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3932 offsetT newval
= md_chars_to_number (buf
, 4);
3934 /* Constant ADDA operands, processed as constant when the
3935 instruction is parsed, are encoded as-is rather than
3936 shifted. If the operand of an ADDA instruction is now
3937 constant (for example, the difference between two labels
3938 found after the instruction), ensure it is encoded the
3939 same way it would have been if the constant value had
3940 been known when the instruction was parsed. */
3941 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3944 MODIFY_VALUE (newval
, value
, 1, 8, 15);
3946 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3947 _("immediate offset not 2-byte-aligned"));
3948 if (value
< 0 || value
> 0xfffe)
3949 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3950 _("immediate offset out of range"));
3952 md_number_to_chars (buf
, newval
, 4);
3956 case BFD_RELOC_C6000_SBR_U15_W
:
3957 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
3958 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3960 offsetT newval
= md_chars_to_number (buf
, 4);
3962 /* Constant ADDA operands, processed as constant when the
3963 instruction is parsed, are encoded as-is rather than
3964 shifted. If the operand of an ADDA instruction is now
3965 constant (for example, the difference between two labels
3966 found after the instruction), ensure it is encoded the
3967 same way it would have been if the constant value had
3968 been known when the instruction was parsed. */
3969 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3972 MODIFY_VALUE (newval
, value
, 2, 8, 15);
3974 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3975 _("immediate offset not 4-byte-aligned"));
3976 if (value
< 0 || value
> 0x1fffc)
3977 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3978 _("immediate offset out of range"));
3980 md_number_to_chars (buf
, newval
, 4);
3982 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_SBR_U15_W
)
3986 case BFD_RELOC_C6000_DSBT_INDEX
:
3988 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3989 _("addend used with $DSBT_INDEX"));
3994 case BFD_RELOC_C6000_PCR_S21
:
3995 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3997 offsetT newval
= md_chars_to_number (buf
, 4);
3999 MODIFY_VALUE (newval
, value
, 2, 7, 21);
4002 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4003 _("PC-relative offset not 4-byte-aligned"));
4004 if (value
< -0x400000 || value
> 0x3ffffc)
4005 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4006 _("PC-relative offset out of range"));
4008 md_number_to_chars (buf
, newval
, 4);
4012 case BFD_RELOC_C6000_PCR_S12
:
4013 if (fixP
->fx_done
|| !seg
->use_rela_p
)
4015 offsetT newval
= md_chars_to_number (buf
, 4);
4017 MODIFY_VALUE (newval
, value
, 2, 16, 12);
4020 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4021 _("PC-relative offset not 4-byte-aligned"));
4022 if (value
< -0x2000 || value
> 0x1ffc)
4023 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4024 _("PC-relative offset out of range"));
4026 md_number_to_chars (buf
, newval
, 4);
4030 case BFD_RELOC_C6000_PCR_S10
:
4031 if (fixP
->fx_done
|| !seg
->use_rela_p
)
4033 offsetT newval
= md_chars_to_number (buf
, 4);
4035 MODIFY_VALUE (newval
, value
, 2, 13, 10);
4038 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4039 _("PC-relative offset not 4-byte-aligned"));
4040 if (value
< -0x800 || value
> 0x7fc)
4041 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4042 _("PC-relative offset out of range"));
4044 md_number_to_chars (buf
, newval
, 4);
4048 case BFD_RELOC_C6000_PCR_S7
:
4049 if (fixP
->fx_done
|| !seg
->use_rela_p
)
4051 offsetT newval
= md_chars_to_number (buf
, 4);
4053 MODIFY_VALUE (newval
, value
, 2, 16, 7);
4056 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4057 _("PC-relative offset not 4-byte-aligned"));
4058 if (value
< -0x100 || value
> 0xfc)
4059 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4060 _("PC-relative offset out of range"));
4062 md_number_to_chars (buf
, newval
, 4);
4066 case BFD_RELOC_C6000_PREL31
:
4067 /* Force output to the object file. */
4076 /* Convert a floating-point number to target (IEEE) format. */
4079 md_atof (int type
, char *litP
, int *sizeP
)
4081 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
4084 /* Adjust the frags in SECTION (see tic6x_end). */
4087 tic6x_adjust_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT section
,
4088 void *dummy ATTRIBUTE_UNUSED
)
4090 segment_info_type
*info
;
4093 bfd_boolean have_code
= FALSE
;
4094 bfd_boolean have_non_code
= FALSE
;
4096 info
= seg_info (section
);
4100 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4101 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4102 switch (fragp
->fr_type
)
4104 case rs_machine_dependent
:
4105 if (fragp
->tc_frag_data
.is_insns
)
4111 if (fragp
->fr_fix
> 0)
4112 have_non_code
= TRUE
;
4116 have_non_code
= TRUE
;
4120 /* Process alignment requirements in a code-only section. */
4121 if (have_code
&& !have_non_code
)
4123 /* If we need to insert an odd number of instructions to meet an
4124 alignment requirement, there must have been an odd number of
4125 instructions since the last 8-byte-aligned execute packet
4126 boundary. So there must have been an execute packet with an
4127 odd number (and so a number fewer than 8) of instructions
4128 into which we can insert a NOP without breaking any previous
4131 If then we need to insert a number 2 mod 4 of instructions,
4132 the number of instructions since the last 16-byte-aligned
4133 execute packet boundary must be 2 mod 4. So between that
4134 boundary and the following 8-byte-aligned boundary there must
4135 either be at least one execute packet with 2-mod-4
4136 instructions, or at least two with an odd number of
4137 instructions; again, greedily inserting NOPs as soon as
4138 possible suffices to meet the alignment requirement.
4140 If then we need to insert 4 instructions, we look between the
4141 last 32-byte-aligned boundary and the following
4142 16-byte-aligned boundary. The sizes of the execute packets
4143 in this range total 4 instructions mod 8, so again there is
4144 room for greedy insertion of NOPs to meet the alignment
4145 requirement, and before any intermediate point with 8-byte
4146 (2-instruction) alignment requirement the sizes of execute
4147 packets (and so the room for NOPs) will total 2 instructions
4148 mod 4 so greedy insertion will not break such alignments.
4150 So we can always meet these alignment requirements by
4151 inserting NOPs in parallel with existing execute packets, and
4152 by induction the approach described above inserts the minimum
4153 number of such NOPs. */
4155 /* The number of NOPs we are currently looking to insert, if we
4156 have gone back to insert NOPs. */
4157 unsigned int want_insert
= 0;
4159 /* Out of that number, the number inserted so far in the current
4160 stage of the above algorithm. */
4161 unsigned int want_insert_done_so_far
= 0;
4163 /* The position mod 32 at the start of the current frag. */
4164 unsigned int pos
= 0;
4166 /* The locations in the frag chain of the most recent frags at
4167 the start of which there is the given alignment. */
4168 frchainS
*frchp_last32
, *frchp_last16
, *frchp_last8
;
4169 fragS
*fragp_last32
, *fragp_last16
, *fragp_last8
;
4170 unsigned int pos_last32
, pos_last16
, pos_last8
;
4172 frchp_last32
= frchp_last16
= frchp_last8
= info
->frchainP
;
4173 fragp_last32
= fragp_last16
= fragp_last8
= info
->frchainP
->frch_root
;
4174 pos_last32
= pos_last16
= pos_last8
= 0;
4176 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4177 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4180 bfd_boolean go_back
= FALSE
;
4181 frchainS
*frchp_next
;
4184 if (fragp
->fr_type
!= rs_machine_dependent
)
4187 if (fragp
->tc_frag_data
.is_insns
4188 && pos
+ fragp
->fr_fix
> 32
4189 && !fragp
->tc_frag_data
.can_cross_fp_boundary
)
4191 /* As described above, we should always have met an
4192 alignment requirement by the time we come back to
4199 want_insert
= (32 - pos
) >> 2;
4200 if (want_insert
> 7)
4202 want_insert_done_so_far
= 0;
4206 if (!fragp
->tc_frag_data
.is_insns
)
4208 unsigned int would_insert_bytes
;
4210 if (!(pos
& ((1 << fragp
->fr_offset
) - 1)))
4211 /* This alignment requirement is already met. */
4214 /* As described above, we should always have met an
4215 alignment requirement by the time we come back to
4220 /* We may not be able to meet this requirement within
4221 the given number of characters. */
4223 = ((1 << fragp
->fr_offset
)
4224 - (pos
& ((1 << fragp
->fr_offset
) - 1)));
4226 if (fragp
->fr_subtype
!= 0
4227 && would_insert_bytes
> fragp
->fr_subtype
)
4230 /* An unmet alignment must be 8, 16 or 32 bytes;
4231 smaller ones must always be met within code-only
4232 sections and larger ones cause the section not to
4234 if (fragp
->fr_offset
!= 3
4235 && fragp
->fr_offset
!= 4
4236 && fragp
->fr_offset
!= 5)
4239 if (would_insert_bytes
& 3)
4241 want_insert
= would_insert_bytes
>> 2;
4242 if (want_insert
> 7)
4244 want_insert_done_so_far
= 0;
4247 else if (want_insert
&& !go_back
)
4249 unsigned int num_insns
= fragp
->fr_fix
>> 2;
4250 unsigned int max_poss_nops
= 8 - num_insns
;
4254 unsigned int cur_want_nops
, max_want_nops
, do_nops
, i
;
4256 if (want_insert
& 1)
4258 else if (want_insert
& 2)
4260 else if (want_insert
& 4)
4265 max_want_nops
= cur_want_nops
- want_insert_done_so_far
;
4267 do_nops
= (max_poss_nops
< max_want_nops
4270 for (i
= 0; i
< do_nops
; i
++)
4272 md_number_to_chars (fragp
->fr_literal
+ fragp
->fr_fix
,
4274 if (target_big_endian
)
4275 fragp
->fr_literal
[fragp
->fr_fix
- 1] |= 0x1;
4277 fragp
->fr_literal
[fragp
->fr_fix
- 4] |= 0x1;
4281 want_insert_done_so_far
+= do_nops
;
4282 if (want_insert_done_so_far
== cur_want_nops
)
4284 want_insert
-= want_insert_done_so_far
;
4285 want_insert_done_so_far
= 0;
4293 if (want_insert
& 1)
4295 frchp
= frchp_last8
;
4296 fragp
= fragp_last8
;
4299 else if (want_insert
& 2)
4301 frchp
= frchp_last8
= frchp_last16
;
4302 fragp
= fragp_last8
= fragp_last16
;
4303 pos
= pos_last8
= pos_last16
;
4305 else if (want_insert
& 4)
4307 frchp
= frchp_last8
= frchp_last16
= frchp_last32
;
4308 fragp
= fragp_last8
= fragp_last16
= fragp_last32
;
4309 pos
= pos_last8
= pos_last16
= pos_last32
;
4317 /* Update current position for moving past a code
4319 pos
+= fragp
->fr_fix
;
4322 fragp_next
= fragp
->fr_next
;
4323 if (fragp_next
== NULL
)
4325 frchp_next
= frchp
->frch_next
;
4326 if (frchp_next
!= NULL
)
4327 fragp_next
= frchp_next
->frch_root
;
4331 frchp_last8
= frchp_next
;
4332 fragp_last8
= fragp_next
;
4337 frchp_last16
= frchp_next
;
4338 fragp_last16
= fragp_next
;
4343 frchp_last32
= frchp_next
;
4344 fragp_last32
= fragp_next
;
4350 /* Now convert the machine-dependent frags to machine-independent
4352 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4353 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4355 if (fragp
->fr_type
== rs_machine_dependent
)
4357 if (fragp
->tc_frag_data
.is_insns
)
4361 fragp
->fr_type
= rs_align_code
;
4363 *fragp
->fr_literal
= 0;
4369 /* Initialize the machine-dependent parts of a frag. */
4372 tic6x_frag_init (fragS
*fragp
)
4374 fragp
->tc_frag_data
.is_insns
= FALSE
;
4375 fragp
->tc_frag_data
.can_cross_fp_boundary
= FALSE
;
4378 /* Set an attribute if it has not already been set by the user. */
4381 tic6x_set_attribute_int (int tag
, int value
)
4384 || tag
>= NUM_KNOWN_OBJ_ATTRIBUTES
)
4386 if (!tic6x_attributes_set_explicitly
[tag
])
4387 bfd_elf_add_proc_attr_int (stdoutput
, tag
, value
);
4390 /* Set object attributes deduced from the input file and command line
4391 rather than given explicitly. */
4393 tic6x_set_attributes (void)
4395 if (tic6x_arch_attribute
== C6XABI_Tag_ISA_none
)
4396 tic6x_arch_attribute
= C6XABI_Tag_ISA_C674X
;
4398 tic6x_set_attribute_int (Tag_ISA
, tic6x_arch_attribute
);
4399 tic6x_set_attribute_int (Tag_ABI_DSBT
, tic6x_dsbt
);
4400 tic6x_set_attribute_int (Tag_ABI_PID
, tic6x_pid
);
4401 tic6x_set_attribute_int (Tag_ABI_PIC
, tic6x_pic
);
4404 /* Do machine-dependent manipulations of the frag chains after all
4405 input has been read and before the machine-independent sizing and
4411 /* Set object attributes at this point if not explicitly set. */
4412 tic6x_set_attributes ();
4414 /* Meeting alignment requirements may require inserting NOPs in
4415 parallel in execute packets earlier in the segment. Future
4416 16-bit instruction generation involves whole-segment optimization
4417 to determine the best choice and ordering of 32-bit or 16-bit
4418 instructions. This doesn't fit will in the general relaxation
4419 framework, so handle alignment and 16-bit instruction generation
4421 bfd_map_over_sections (stdoutput
, tic6x_adjust_section
, NULL
);
4424 /* No machine-dependent frags at this stage; all converted in
4428 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec ATTRIBUTE_UNUSED
,
4429 fragS
*fragp ATTRIBUTE_UNUSED
)
4434 /* No machine-dependent frags at this stage; all converted in
4438 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
4439 segT seg ATTRIBUTE_UNUSED
)
4444 /* Put a number into target byte order. */
4447 md_number_to_chars (char *buf
, valueT val
, int n
)
4449 if (target_big_endian
)
4450 number_to_chars_bigendian (buf
, val
, n
);
4452 number_to_chars_littleendian (buf
, val
, n
);
4455 /* Machine-dependent operand parsing not currently needed. */
4458 md_operand (expressionS
*op ATTRIBUTE_UNUSED
)
4462 /* PC-relative operands are relative to the start of the fetch
4466 tic6x_pcrel_from_section (fixS
*fixp
, segT sec
)
4468 if (fixp
->fx_addsy
!= NULL
4469 && (!S_IS_DEFINED (fixp
->fx_addsy
)
4470 || S_GET_SEGMENT (fixp
->fx_addsy
) != sec
))
4472 return (fixp
->fx_where
+ fixp
->fx_frag
->fr_address
) & ~(long) 0x1f;
4475 /* Round up a section size to the appropriate boundary. */
4478 md_section_align (segT segment ATTRIBUTE_UNUSED
,
4481 /* Round up section sizes to ensure that text sections consist of
4482 whole fetch packets. */
4483 int align
= bfd_section_alignment (segment
);
4484 return ((size
+ (1 << align
) - 1) & (-((valueT
) 1 << align
)));
4487 /* No special undefined symbol handling needed for now. */
4490 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
4495 /* Translate internal representation of relocation info to BFD target
4499 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
4503 bfd_reloc_code_real_type r_type
;
4505 reloc
= XNEW (arelent
);
4506 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
4507 symbol
= symbol_get_bfdsym (fixp
->fx_addsy
);
4508 *reloc
->sym_ptr_ptr
= symbol
;
4509 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4510 reloc
->addend
= (tic6x_generate_rela
? fixp
->fx_offset
: 0);
4511 r_type
= fixp
->fx_r_type
;
4512 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
4514 if (reloc
->howto
== NULL
)
4516 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4517 _("Cannot represent relocation type %s"),
4518 bfd_get_reloc_code_name (r_type
));
4522 /* Correct for adjustments bfd_install_relocation will make. */
4523 if (reloc
->howto
->pcrel_offset
&& reloc
->howto
->partial_inplace
)
4525 reloc
->addend
+= reloc
->address
;
4526 if (!bfd_is_com_section (bfd_asymbol_section (symbol
)))
4527 reloc
->addend
-= symbol
->value
;
4529 if (r_type
== BFD_RELOC_C6000_PCR_H16
4530 || r_type
== BFD_RELOC_C6000_PCR_L16
)
4532 symbolS
*t
= fixp
->tc_fix_data
.fix_subsy
;
4533 segT sub_symbol_segment
;
4535 resolve_symbol_value (t
);
4536 sub_symbol_segment
= S_GET_SEGMENT (t
);
4537 if (sub_symbol_segment
== undefined_section
)
4538 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4539 _("undefined symbol %s in PCR relocation"),
4543 reloc
->addend
= reloc
->address
& ~0x1F;
4544 reloc
->addend
-= S_GET_VALUE (t
);
4550 /* Convert REGNAME to a DWARF-2 register number. */
4553 tic6x_regname_to_dw2regnum (char *regname
)
4559 reg_ok
= tic6x_parse_register (&rq
, ®
);
4566 case 1: /* A regs. */
4569 else if (reg
.num
< 32)
4570 return (reg
.num
- 16) + 37;
4574 case 2: /* B regs. */
4576 return reg
.num
+ 16;
4577 else if (reg
.num
< 32)
4578 return (reg
.num
- 16) + 53;
4587 /* Initialize the DWARF-2 unwind information for this procedure. */
4590 tic6x_frame_initial_instructions (void)
4592 /* CFA is initial stack pointer (B15). */
4593 cfi_add_CFA_def_cfa (31, 0);
4596 /* Start an exception table entry. If idx is nonzero this is an index table
4600 tic6x_start_unwind_section (const segT text_seg
, int idx
)
4602 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4603 const char * text_name
;
4604 const char * prefix
;
4605 const char * prefix_once
;
4606 struct elf_section_match match
;
4610 size_t sec_name_len
;
4617 prefix
= ELF_STRING_C6000_unwind
;
4618 prefix_once
= ELF_STRING_C6000_unwind_once
;
4619 type
= SHT_C6000_UNWIND
;
4623 prefix
= ELF_STRING_C6000_unwind_info
;
4624 prefix_once
= ELF_STRING_C6000_unwind_info_once
;
4625 type
= SHT_PROGBITS
;
4628 text_name
= segment_name (text_seg
);
4629 if (streq (text_name
, ".text"))
4632 if (strncmp (text_name
, ".gnu.linkonce.t.",
4633 strlen (".gnu.linkonce.t.")) == 0)
4635 prefix
= prefix_once
;
4636 text_name
+= strlen (".gnu.linkonce.t.");
4639 prefix_len
= strlen (prefix
);
4640 text_len
= strlen (text_name
);
4641 sec_name_len
= prefix_len
+ text_len
;
4642 sec_name
= XNEWVEC (char, sec_name_len
+ 1);
4643 memcpy (sec_name
, prefix
, prefix_len
);
4644 memcpy (sec_name
+ prefix_len
, text_name
, text_len
);
4645 sec_name
[prefix_len
+ text_len
] = '\0';
4649 memset (&match
, 0, sizeof (match
));
4651 /* Handle COMDAT group. */
4652 if (prefix
!= prefix_once
&& (text_seg
->flags
& SEC_LINK_ONCE
) != 0)
4654 match
.group_name
= elf_group_name (text_seg
);
4655 if (match
.group_name
== NULL
)
4657 as_bad (_("group section `%s' has no group signature"),
4658 segment_name (text_seg
));
4659 ignore_rest_of_line ();
4666 obj_elf_change_section (sec_name
, type
, flags
, 0, &match
,
4669 /* Set the section link for index tables. */
4671 elf_linked_to_section (now_seg
) = text_seg
;
4673 seg_info (now_seg
)->tc_segment_info_data
.text_unwind
= unwind
;
4678 tic6x_unwind_frame_regs
[TIC6X_NUM_UNWIND_REGS
] =
4679 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4680 { 15, 31, 30, 29, 28, 27, 26, 19, 14, 13, 12, 11, 10 };
4682 /* Register save offsets for __c6xabi_push_rts. */
4684 tic6x_pop_rts_offset_little
[TIC6X_NUM_UNWIND_REGS
] =
4685 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4686 { -1, 1, 0, -3, -4, -7, -8,-11, -2, -5, -6, -9,-10};
4689 tic6x_pop_rts_offset_big
[TIC6X_NUM_UNWIND_REGS
] =
4690 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4691 { -2, 1, 0, -4, -3, -8, -7,-12, -1, -6, -5,-10, -9};
4693 /* Map from dwarf register number to unwind frame register number. */
4695 tic6x_unwind_reg_from_dwarf (int dwarf
)
4699 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
4701 if (tic6x_unwind_frame_regs
[reg
] == dwarf
)
4708 /* Unwinding bytecode definitions. */
4709 #define UNWIND_OP_ADD_SP 0x00
4710 #define UNWIND_OP_ADD_SP2 0xd2
4711 #define UNWIND_OP2_POP 0x8000
4712 #define UNWIND_OP2_POP_COMPACT 0xa000
4713 #define UNWIND_OP_POP_REG 0xc0
4714 #define UNWIND_OP_MV_FP 0xd0
4715 #define UNWIND_OP_POP_RTS 0xd1
4716 #define UNWIND_OP_RET 0xe0
4718 /* Maximum stack adjustment for __c6xabi_unwind_cpp_pr3/4 */
4719 #define MAX_COMPACT_SP_OFFSET (0x7f << 3)
4722 tic6x_flush_unwind_word (valueT data
)
4724 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4727 /* Create EXTAB entry if it does not exist. */
4728 if (unwind
->table_entry
== NULL
)
4730 tic6x_start_unwind_section (unwind
->saved_seg
, 0);
4731 frag_align (2, 0, 0);
4732 record_alignment (now_seg
, 2);
4733 unwind
->table_entry
= expr_build_dot ();
4734 ptr
= frag_more (4);
4735 unwind
->frag_start
= ptr
;
4739 /* Append additional word of data. */
4740 ptr
= frag_more (4);
4743 md_number_to_chars (ptr
, data
, 4);
4746 /* Add a single byte of unwinding data. */
4749 tic6x_unwind_byte (int byte
)
4751 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4753 unwind
->data_bytes
++;
4754 /* Only flush the first word after we know multiple words are required. */
4755 if (unwind
->data_bytes
== 5)
4757 if (unwind
->personality_index
== -1)
4759 /* At this point we know we are too big for pr0. */
4760 unwind
->personality_index
= 1;
4761 tic6x_flush_unwind_word (0x81000000 | ((unwind
->data
>> 8) & 0xffff));
4762 unwind
->data
= ((unwind
->data
& 0xff) << 8) | byte
;
4763 unwind
->data_bytes
++;
4767 tic6x_flush_unwind_word (unwind
->data
);
4768 unwind
->data
= byte
;
4773 unwind
->data
= (unwind
->data
<< 8) | byte
;
4774 if ((unwind
->data_bytes
& 3) == 0 && unwind
->data_bytes
> 4)
4776 tic6x_flush_unwind_word (unwind
->data
);
4782 /* Add a two-byte unwinding opcode. */
4784 tic6x_unwind_2byte (int bytes
)
4786 tic6x_unwind_byte (bytes
>> 8);
4787 tic6x_unwind_byte (bytes
& 0xff);
4791 tic6x_unwind_uleb (offsetT offset
)
4793 while (offset
> 0x7f)
4795 tic6x_unwind_byte ((offset
& 0x7f) | 0x80);
4798 tic6x_unwind_byte (offset
);
4802 tic6x_cfi_startproc (void)
4804 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4806 unwind
->personality_index
= -1;
4807 unwind
->personality_routine
= NULL
;
4808 if (unwind
->table_entry
)
4809 as_bad (_("missing .endp before .cfi_startproc"));
4811 unwind
->table_entry
= NULL
;
4812 unwind
->data_bytes
= -1;
4816 tic6x_output_exidx_entry (void)
4820 unsigned int marked_pr_dependency
;
4823 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4826 old_subseg
= now_subseg
;
4828 /* Add index table entry. This is two words. */
4829 tic6x_start_unwind_section (unwind
->saved_seg
, 1);
4830 frag_align (2, 0, 0);
4831 record_alignment (now_seg
, 2);
4833 ptr
= frag_more (8);
4835 where
= frag_now_fix () - 8;
4837 /* Self relative offset of the function start. */
4838 fix_new (frag_now
, where
, 4, unwind
->function_start
, 0, 1,
4839 BFD_RELOC_C6000_PREL31
);
4841 /* Indicate dependency on ABI-defined personality routines to the
4842 linker, if it hasn't been done already. */
4843 marked_pr_dependency
4844 = seg_info (now_seg
)->tc_segment_info_data
.marked_pr_dependency
;
4845 if (unwind
->personality_index
>= 0 && unwind
->personality_index
< 5
4846 && !(marked_pr_dependency
& (1 << unwind
->personality_index
)))
4848 static const char *const name
[] =
4850 "__c6xabi_unwind_cpp_pr0",
4851 "__c6xabi_unwind_cpp_pr1",
4852 "__c6xabi_unwind_cpp_pr2",
4853 "__c6xabi_unwind_cpp_pr3",
4854 "__c6xabi_unwind_cpp_pr4"
4856 symbolS
*pr
= symbol_find_or_make (name
[unwind
->personality_index
]);
4857 fix_new (frag_now
, where
, 0, pr
, 0, 1, BFD_RELOC_NONE
);
4858 seg_info (now_seg
)->tc_segment_info_data
.marked_pr_dependency
4859 |= 1 << unwind
->personality_index
;
4862 if (unwind
->table_entry
)
4864 /* Self relative offset of the table entry. */
4865 fix_new (frag_now
, where
+ 4, 4, unwind
->table_entry
, 0, 1,
4866 BFD_RELOC_C6000_PREL31
);
4870 /* Inline exception table entry. */
4871 md_number_to_chars (ptr
+ 4, unwind
->data
, 4);
4874 /* Restore the original section. */
4875 subseg_set (old_seg
, old_subseg
);
4879 tic6x_output_unwinding (bfd_boolean need_extab
)
4881 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4882 unsigned safe_mask
= unwind
->safe_mask
;
4883 unsigned compact_mask
= unwind
->compact_mask
;
4884 unsigned reg_saved_mask
= unwind
->reg_saved_mask
;
4885 offsetT cfa_offset
= unwind
->cfa_offset
;
4889 if (unwind
->personality_index
== -2)
4891 /* Function can not be unwound. */
4893 tic6x_output_exidx_entry ();
4897 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
4899 /* Auto-select a personality routine if none specified. */
4900 if (reg_saved_mask
|| cfa_offset
>= MAX_COMPACT_SP_OFFSET
)
4901 unwind
->personality_index
= -1;
4903 unwind
->personality_index
= 3;
4905 unwind
->personality_index
= 4;
4908 /* Calculate unwinding opcodes, and emit to EXTAB if necessary. */
4909 unwind
->table_entry
= NULL
;
4910 if (unwind
->personality_index
== 3 || unwind
->personality_index
== 4)
4912 if (cfa_offset
>= MAX_COMPACT_SP_OFFSET
)
4914 as_bad (_("stack pointer offset too large for personality routine"));
4918 || (unwind
->personality_index
== 3 && compact_mask
!= 0)
4919 || (unwind
->personality_index
== 4 && safe_mask
!= 0))
4921 as_bad (_("stack frame layout does not match personality routine"));
4925 unwind
->data
= (1u << 31) | (unwind
->personality_index
<< 24);
4926 if (unwind
->cfa_reg
== 15)
4927 unwind
->data
|= 0x7f << 17;
4929 unwind
->data
|= cfa_offset
<< (17 - 3);
4931 if (unwind
->personality_index
== 3)
4932 unwind
->data
|= safe_mask
<< 4;
4934 unwind
->data
|= compact_mask
<< 4;
4935 unwind
->data
|= unwind
->return_reg
;
4936 unwind
->data_bytes
= 4;
4940 if (unwind
->personality_routine
)
4943 unwind
->data_bytes
= 5;
4944 tic6x_flush_unwind_word (0);
4945 /* First word is personality routine. */
4946 where
= frag_now_fix () - 4;
4947 fix_new (frag_now
, where
, 4, unwind
->personality_routine
, 0, 1,
4948 BFD_RELOC_C6000_PREL31
);
4950 else if (unwind
->personality_index
> 0)
4952 unwind
->data
= 0x8000 | (unwind
->personality_index
<< 8);
4953 unwind
->data_bytes
= 2;
4955 else /* pr0 or undecided */
4957 unwind
->data
= 0x80;
4958 unwind
->data_bytes
= 1;
4961 if (unwind
->return_reg
!= UNWIND_B3
)
4963 tic6x_unwind_byte (UNWIND_OP_RET
| unwind
->return_reg
);
4966 if (unwind
->cfa_reg
== 15)
4968 tic6x_unwind_byte (UNWIND_OP_MV_FP
);
4970 else if (cfa_offset
!= 0)
4973 if (cfa_offset
> 0x80)
4975 tic6x_unwind_byte (UNWIND_OP_ADD_SP2
);
4976 tic6x_unwind_uleb (cfa_offset
- 0x81);
4978 else if (cfa_offset
> 0x40)
4980 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| 0x3f);
4981 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| (cfa_offset
- 0x40));
4985 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| (cfa_offset
- 1));
4990 tic6x_unwind_2byte (UNWIND_OP2_POP
| unwind
->safe_mask
);
4991 else if (unwind
->pop_rts
)
4992 tic6x_unwind_byte (UNWIND_OP_POP_RTS
);
4993 else if (compact_mask
)
4994 tic6x_unwind_2byte (UNWIND_OP2_POP_COMPACT
| unwind
->compact_mask
);
4995 else if (reg_saved_mask
)
5001 tic6x_unwind_byte (UNWIND_OP_POP_REG
| unwind
->saved_reg_count
);
5003 for (cur_offset
= 0; unwind
->saved_reg_count
> 0; cur_offset
-= 4)
5006 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5008 if (!unwind
->reg_saved
[reg
])
5011 if (unwind
->reg_offset
[reg
] == cur_offset
)
5013 unwind
->saved_reg_count
--;
5018 if ((cur_offset
& 4) == 4)
5019 tic6x_unwind_byte ((last_val
<< 4) | val
);
5023 if ((cur_offset
& 4) == 4)
5024 tic6x_unwind_byte ((last_val
<< 4) | 0xf);
5027 /* Pad with RETURN opcodes. */
5028 while ((unwind
->data_bytes
& 3) != 0)
5029 tic6x_unwind_byte (UNWIND_OP_RET
| UNWIND_B3
);
5031 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
5032 unwind
->personality_index
= 0;
5035 /* Force creation of an EXTAB entry if an LSDA is required. */
5036 if (need_extab
&& !unwind
->table_entry
)
5038 if (unwind
->data_bytes
!= 4)
5041 tic6x_flush_unwind_word (unwind
->data
);
5043 else if (unwind
->table_entry
&& !need_extab
)
5045 /* Add an empty descriptor if there is no user-specified data. */
5046 char *ptr
= frag_more (4);
5047 md_number_to_chars (ptr
, 0, 4);
5050 /* Fill in length of unwinding bytecode. */
5051 if (unwind
->table_entry
)
5054 if (unwind
->data_bytes
> 0x400)
5055 as_bad (_("too many unwinding instructions"));
5057 if (unwind
->personality_index
== -1)
5059 tmp
= md_chars_to_number (unwind
->frag_start
+ 4, 4);
5060 tmp
|= (valueT
) ((unwind
->data_bytes
- 8) >> 2) << 24;
5061 md_number_to_chars (unwind
->frag_start
+ 4, tmp
, 4);
5063 else if (unwind
->personality_index
== 1 || unwind
->personality_index
== 2)
5065 tmp
= md_chars_to_number (unwind
->frag_start
, 4);
5066 tmp
|= ((unwind
->data_bytes
- 4) >> 2) << 16;
5067 md_number_to_chars (unwind
->frag_start
, tmp
, 4);
5070 tic6x_output_exidx_entry ();
5073 /* FIXME: This will get horribly confused if cfi directives are emitted for
5074 function epilogue. */
5076 tic6x_cfi_endproc (struct fde_entry
*fde
)
5078 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
5079 struct cfi_insn_data
*insn
;
5081 unsigned safe_mask
= 0;
5082 unsigned compact_mask
= 0;
5083 unsigned reg_saved_mask
= 0;
5084 offsetT cfa_offset
= 0;
5085 offsetT save_offset
= 0;
5087 unwind
->cfa_reg
= 31;
5088 unwind
->return_reg
= UNWIND_B3
;
5089 unwind
->saved_reg_count
= 0;
5090 unwind
->pop_rts
= FALSE
;
5092 unwind
->saved_seg
= now_seg
;
5093 unwind
->saved_subseg
= now_subseg
;
5095 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5096 unwind
->reg_saved
[reg
] = FALSE
;
5098 /* Scan FDE instructions to build up stack frame layout. */
5099 for (insn
= fde
->data
; insn
; insn
= insn
->next
)
5103 case DW_CFA_advance_loc
:
5106 case DW_CFA_def_cfa
:
5107 unwind
->cfa_reg
= insn
->u
.ri
.reg
;
5108 cfa_offset
= insn
->u
.ri
.offset
;
5111 case DW_CFA_def_cfa_register
:
5112 unwind
->cfa_reg
= insn
->u
.r
;
5115 case DW_CFA_def_cfa_offset
:
5116 cfa_offset
= insn
->u
.i
;
5119 case DW_CFA_undefined
:
5120 case DW_CFA_same_value
:
5121 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.r
);
5123 unwind
->reg_saved
[reg
] = FALSE
;
5127 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.ri
.reg
);
5130 as_bad (_("unable to generate unwinding opcode for reg %d"),
5134 unwind
->reg_saved
[reg
] = TRUE
;
5135 unwind
->reg_offset
[reg
] = insn
->u
.ri
.offset
;
5136 if (insn
->u
.ri
.reg
== UNWIND_B3
)
5137 unwind
->return_reg
= UNWIND_B3
;
5140 case DW_CFA_register
:
5141 if (insn
->u
.rr
.reg1
!= 19)
5143 as_bad (_("unable to generate unwinding opcode for reg %d"),
5148 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.rr
.reg2
);
5151 as_bad (_("unable to generate unwinding opcode for reg %d"),
5156 unwind
->return_reg
= reg
;
5157 unwind
->reg_saved
[UNWIND_B3
] = FALSE
;
5158 if (unwind
->reg_saved
[reg
])
5160 as_bad (_("unable to restore return address from "
5161 "previously restored reg"));
5166 case DW_CFA_restore
:
5167 case DW_CFA_remember_state
:
5168 case DW_CFA_restore_state
:
5169 case DW_CFA_GNU_window_save
:
5171 case CFI_val_encoded_addr
:
5172 as_bad (_("unhandled CFA insn for unwinding (%d)"), insn
->insn
);
5180 if (unwind
->cfa_reg
!= 15 && unwind
->cfa_reg
!= 31)
5182 as_bad (_("unable to generate unwinding opcode for frame pointer reg %d"),
5187 if (unwind
->cfa_reg
== 15)
5189 if (cfa_offset
!= 0)
5191 as_bad (_("unable to generate unwinding opcode for "
5192 "frame pointer offset"));
5198 if ((cfa_offset
& 7) != 0)
5200 as_bad (_("unwound stack pointer not doubleword aligned"));
5205 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5207 if (unwind
->reg_saved
[reg
])
5208 reg_saved_mask
|= 1 << (TIC6X_NUM_UNWIND_REGS
- (reg
+ 1));
5211 /* Check for standard "safe debug" frame layout */
5215 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5217 if (!unwind
->reg_saved
[reg
])
5220 if (target_big_endian
5221 && reg
< TIC6X_NUM_UNWIND_REGS
- 1
5222 && unwind
->reg_saved
[reg
+ 1]
5223 && tic6x_unwind_frame_regs
[reg
]
5224 == tic6x_unwind_frame_regs
[reg
+ 1] + 1
5225 && (tic6x_unwind_frame_regs
[reg
] & 1) == 1
5226 && (save_offset
& 4) == 4)
5229 if (save_offset
!= unwind
->reg_offset
[reg
+ 1]
5230 || save_offset
- 4 != unwind
->reg_offset
[reg
])
5237 if (save_offset
!= unwind
->reg_offset
[reg
])
5242 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5244 safe_mask
= reg_saved_mask
;
5249 /* Check for compact frame layout. */
5253 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5257 if (!unwind
->reg_saved
[reg
])
5260 if (reg
< TIC6X_NUM_UNWIND_REGS
- 1)
5264 if (!unwind
->reg_saved
[reg2
]
5265 || tic6x_unwind_frame_regs
[reg
]
5266 != tic6x_unwind_frame_regs
[reg2
] + 1
5267 || (tic6x_unwind_frame_regs
[reg2
] & 1) != 0
5268 || save_offset
== 0)
5277 if (target_big_endian
)
5278 high_offset
= 4; /* lower address = positive stack offset. */
5282 if (save_offset
+ 4 - high_offset
!= unwind
->reg_offset
[reg
]
5283 || save_offset
+ high_offset
!= unwind
->reg_offset
[reg2
])
5291 if (save_offset
!= unwind
->reg_offset
[reg
])
5297 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5299 compact_mask
= reg_saved_mask
;
5304 /* Check for __c6xabi_pop_rts format */
5305 if (reg_saved_mask
== 0x17ff)
5307 const int *pop_rts_offset
= target_big_endian
5308 ? tic6x_pop_rts_offset_big
5309 : tic6x_pop_rts_offset_little
;
5312 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5314 if (reg
== UNWIND_B15
)
5317 if (unwind
->reg_offset
[reg
] != pop_rts_offset
[reg
] * 4)
5321 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5323 unwind
->pop_rts
= TRUE
;
5327 /* If all else fails then describe the frame manually. */
5332 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5334 if (!unwind
->reg_saved
[reg
])
5337 unwind
->saved_reg_count
++;
5338 /* Encoding uses 4 bits per word, so size of unwinding opcode data
5339 limits the save area size. The exact cap will be figured out
5340 later due to overflow, the 0x800 here is just a quick sanity
5341 check to weed out obviously excessive offsets. */
5342 if (unwind
->reg_offset
[reg
] > 0 || unwind
->reg_offset
[reg
] < -0x800
5343 || (unwind
->reg_offset
[reg
] & 3) != 0)
5345 as_bad (_("stack frame layout too complex for unwinder"));
5349 if (unwind
->reg_offset
[reg
] < save_offset
)
5350 save_offset
= unwind
->reg_offset
[reg
] - 4;
5354 /* Align to 8-byte boundary (stack grows towards negative offsets). */
5357 if (unwind
->cfa_reg
== 31 && !reg_saved_mask
)
5359 cfa_offset
+= save_offset
;
5362 as_bad (_("unwound frame has negative size"));
5367 unwind
->safe_mask
= safe_mask
;
5368 unwind
->compact_mask
= compact_mask
;
5369 unwind
->reg_saved_mask
= reg_saved_mask
;
5370 unwind
->cfa_offset
= cfa_offset
;
5371 unwind
->function_start
= fde
->start_address
;