2 Copyright (C) 2010-2024 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 bool 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 bool tic6x_predicate_a0
;
110 /* Whether execute packets can cross fetch packet boundaries. */
111 static bool tic6x_can_cross_fp_boundary
;
113 /* Whether there are constraints on simultaneous reads and writes of
115 static bool tic6x_long_data_constraints
;
117 /* Whether compact instructions are available. */
118 static bool tic6x_compact_insns
;
120 /* Whether to generate RELA relocations. */
121 static bool tic6x_generate_rela
= true;
123 /* Whether the code uses DSBT addressing. */
124 static bool 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 bool 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 (bool 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
) != 0;
355 tic6x_can_cross_fp_boundary
356 = (tic6x_arch_enable
& (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) != 0;
358 tic6x_long_data_constraints
= (tic6x_arch_enable
& TIC6X_INSN_C64X
) == 0;
360 tic6x_compact_insns
= (tic6x_arch_enable
& TIC6X_INSN_C64XP
) != 0;
363 /* Do configuration after all options have been parsed. */
366 tic6x_after_parse_args (void)
368 tic6x_update_features ();
371 /* Parse a .cantunwind directive. */
373 s_tic6x_cantunwind (int ignored ATTRIBUTE_UNUSED
)
375 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
377 /* GCC sometimes spits out superfluous .cantunwind directives, so ignore
379 if (unwind
->data_bytes
== 0)
382 if (unwind
->data_bytes
!= -1)
384 as_bad (_("unexpected .cantunwind directive"));
388 demand_empty_rest_of_line ();
390 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
391 as_bad (_("personality routine specified for cantunwind frame"));
393 unwind
->personality_index
= -2;
396 /* Parse a .handlerdata directive. */
398 s_tic6x_handlerdata (int ignored ATTRIBUTE_UNUSED
)
400 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
402 if (!unwind
->saved_seg
)
404 as_bad (_("unexpected .handlerdata directive"));
408 if (unwind
->table_entry
|| unwind
->personality_index
== -2)
410 as_bad (_("duplicate .handlerdata directive"));
414 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
416 as_bad (_("personality routine required before .handlerdata directive"));
420 tic6x_output_unwinding (true);
423 /* Parse a .endp directive. */
425 s_tic6x_endp (int ignored ATTRIBUTE_UNUSED
)
427 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
429 if (unwind
->data_bytes
!= 0)
431 /* Output a .exidx entry if we have not already done so.
432 Then switch back to the text section. */
433 if (!unwind
->table_entry
)
434 tic6x_output_unwinding (false);
436 subseg_set (unwind
->saved_seg
, unwind
->saved_subseg
);
439 unwind
->saved_seg
= NULL
;
440 unwind
->table_entry
= NULL
;
441 unwind
->data_bytes
= 0;
444 /* Parse a .personalityindex directive. */
446 s_tic6x_personalityindex (int ignored ATTRIBUTE_UNUSED
)
448 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
451 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
452 as_bad (_("duplicate .personalityindex directive"));
456 if (exp
.X_op
!= O_constant
457 || exp
.X_add_number
< 0 || exp
.X_add_number
> 15)
459 as_bad (_("bad personality routine number"));
460 ignore_rest_of_line ();
464 unwind
->personality_index
= exp
.X_add_number
;
466 demand_empty_rest_of_line ();
470 s_tic6x_personality (int ignored ATTRIBUTE_UNUSED
)
473 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
475 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
476 as_bad (_("duplicate .personality directive"));
478 c
= get_symbol_name (&name
);
479 unwind
->personality_routine
= symbol_find_or_make (name
);
480 (void) restore_line_pointer (c
);
481 demand_empty_rest_of_line ();
484 /* Parse a .arch directive. */
486 s_tic6x_arch (int ignored ATTRIBUTE_UNUSED
)
491 arch
= input_line_pointer
;
492 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
493 input_line_pointer
++;
494 c
= *input_line_pointer
;
495 *input_line_pointer
= 0;
497 tic6x_use_arch (arch
);
498 tic6x_update_features ();
499 *input_line_pointer
= c
;
500 demand_empty_rest_of_line ();
503 /* Parse a .ehtype directive. */
506 s_tic6x_ehtype (int ignored ATTRIBUTE_UNUSED
)
511 #ifdef md_flush_pending_output
512 md_flush_pending_output ();
515 if (is_it_end_of_statement ())
517 demand_empty_rest_of_line ();
528 if (exp
.X_op
!= O_symbol
)
530 as_bad (_("expected symbol"));
536 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4,
537 &exp
, 0, BFD_RELOC_C6000_EHTYPE
);
539 demand_empty_rest_of_line ();
542 /* Parse a .nocmp directive. */
545 s_tic6x_nocmp (int ignored ATTRIBUTE_UNUSED
)
547 seg_info (now_seg
)->tc_segment_info_data
.nocmp
= true;
548 demand_empty_rest_of_line ();
551 /* .scomm pseudo-op handler.
553 This is a new pseudo-op to handle putting objects in .scommon.
554 By doing this the linker won't need to do any work,
555 and more importantly it removes the implicit -G arg necessary to
556 correctly link the object file. */
559 s_tic6x_scomm (int ignore ATTRIBUTE_UNUSED
)
569 c
= get_symbol_name (&name
);
571 /* Just after name is now '\0'. */
572 p
= input_line_pointer
;
573 (void) restore_line_pointer (c
);
575 if (*input_line_pointer
!= ',')
577 as_bad (_("expected comma after symbol name"));
578 ignore_rest_of_line ();
583 input_line_pointer
++;
584 if ((size
= get_absolute_expression ()) < 0)
586 /* xgettext:c-format */
587 as_warn (_("invalid length for .scomm directive"));
588 ignore_rest_of_line ();
592 /* The third argument to .scomm is the alignment. */
593 if (*input_line_pointer
!= ',')
597 ++input_line_pointer
;
598 align
= get_absolute_expression ();
601 as_warn (_("alignment is not a positive number"));
606 /* Convert to a power of 2 alignment. */
609 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
)
613 as_bad (_("alignment is not a power of 2"));
614 ignore_rest_of_line ();
622 symbolP
= symbol_find_or_make (name
);
625 if (S_IS_DEFINED (symbolP
))
627 /* xgettext:c-format */
628 as_bad (_("attempt to re-define symbol `%s'"),
629 S_GET_NAME (symbolP
));
630 ignore_rest_of_line ();
634 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
636 /* xgettext:c-format */
637 as_bad (_("attempt to redefine `%s' with a different length"),
638 S_GET_NAME (symbolP
));
640 ignore_rest_of_line ();
644 if (symbol_get_obj (symbolP
)->local
)
646 segT old_sec
= now_seg
;
647 int old_subsec
= now_subseg
;
650 record_alignment (sbss_section
, align2
);
651 subseg_set (sbss_section
, 0);
654 frag_align (align2
, 0, 0);
656 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
657 symbol_get_frag (symbolP
)->fr_symbol
= 0;
659 symbol_set_frag (symbolP
, frag_now
);
661 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
664 S_SET_SIZE (symbolP
, size
);
665 S_SET_SEGMENT (symbolP
, sbss_section
);
666 S_CLEAR_EXTERNAL (symbolP
);
667 subseg_set (old_sec
, old_subsec
);
671 S_SET_VALUE (symbolP
, (valueT
) size
);
672 S_SET_ALIGN (symbolP
, 1 << align2
);
673 S_SET_EXTERNAL (symbolP
);
674 S_SET_SEGMENT (symbolP
, &scom_section
);
677 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
679 demand_empty_rest_of_line ();
682 /* Track for each attribute whether it has been set explicitly (and so
683 should not have a default value set by the assembler). */
684 static bool tic6x_attributes_set_explicitly
[NUM_KNOWN_OBJ_ATTRIBUTES
];
686 /* Parse a .c6xabi_attribute directive. */
689 s_tic6x_c6xabi_attribute (int ignored ATTRIBUTE_UNUSED
)
691 int tag
= obj_elf_vendor_attribute (OBJ_ATTR_PROC
);
693 if (tag
< NUM_KNOWN_OBJ_ATTRIBUTES
)
694 tic6x_attributes_set_explicitly
[tag
] = true;
701 } tic6x_attribute_table
;
703 static const tic6x_attribute_table tic6x_attributes
[] =
705 #define TAG(tag, value) { #tag, tag },
706 #include "elf/tic6x-attrs.h"
710 /* Convert an attribute name to a number. */
713 tic6x_convert_symbolic_attribute (const char *name
)
717 for (i
= 0; i
< ARRAY_SIZE (tic6x_attributes
); i
++)
718 if (strcmp (name
, tic6x_attributes
[i
].name
) == 0)
719 return tic6x_attributes
[i
].tag
;
724 const pseudo_typeS md_pseudo_table
[] =
726 { "arch", s_tic6x_arch
, 0 },
727 { "c6xabi_attribute", s_tic6x_c6xabi_attribute
, 0 },
728 { "nocmp", s_tic6x_nocmp
, 0 },
729 { "scomm", s_tic6x_scomm
, 0 },
731 { "ehtype", s_tic6x_ehtype
, 0 },
732 { "endp", s_tic6x_endp
, 0 },
733 { "handlerdata", s_tic6x_handlerdata
, 0 },
734 { "personalityindex", s_tic6x_personalityindex
, 0 },
735 { "personality", s_tic6x_personality
, 0 },
736 { "cantunwind", s_tic6x_cantunwind
, 0 },
740 /* Hash table of opcodes. For each opcode name, this stores a pointer
741 to a tic6x_opcode_list listing (in an arbitrary order) all opcode
742 table entries with that name. */
743 static htab_t opcode_hash
;
745 /* Initialize the assembler (called once at assembler startup). */
755 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, 0);
757 /* Insert opcodes into the hash table. */
758 opcode_hash
= str_htab_create ();
759 for (id
= 0; id
< tic6x_opcode_max
; id
++)
761 tic6x_opcode_list
*opc
= XNEW (tic6x_opcode_list
);
764 opc
->next
= str_hash_find (opcode_hash
, tic6x_opcode_table
[id
].name
);
765 str_hash_insert (opcode_hash
, tic6x_opcode_table
[id
].name
, opc
, 1);
768 /* Save the current subseg so we can restore it [it's the default one and
769 we don't want the initial section to be .sbss]. */
773 /* The sbss section is for local .scomm symbols. */
774 sbss_section
= subseg_new (".bss", 0);
775 seg_info (sbss_section
)->bss
= 1;
777 /* This is copied from perform_an_assembly_pass. */
778 applicable
= bfd_applicable_section_flags (stdoutput
);
779 bfd_set_section_flags (sbss_section
, applicable
& SEC_ALLOC
);
781 subseg_set (seg
, subseg
);
783 /* We must construct a fake section similar to bfd_com_section
784 but with the name .scommon. */
785 scom_section
= *bfd_com_section_ptr
;
786 scom_section
.name
= ".scommon";
787 scom_section
.output_section
= & scom_section
;
788 scom_section
.symbol
= & scom_symbol
;
789 scom_section
.symbol_ptr_ptr
= & scom_section
.symbol
;
790 scom_symbol
= * bfd_com_section_ptr
->symbol
;
791 scom_symbol
.name
= ".scommon";
792 scom_symbol
.section
= & scom_section
;
795 /* Whether the current line being parsed had the "||" parallel bars. */
796 static bool tic6x_line_parallel
;
798 /* Whether the current line being parsed started "||^" to indicate an
799 SPMASKed parallel instruction. */
800 static bool tic6x_line_spmask
;
802 /* If the current line being parsed had an instruction predicate, the
803 creg value for that predicate (which must be nonzero); otherwise
805 static unsigned int tic6x_line_creg
;
807 /* If the current line being parsed had an instruction predicate, the
808 z value for that predicate; otherwise 0. */
809 static unsigned int tic6x_line_z
;
811 /* Return 1 (updating input_line_pointer as appropriate) if the line
812 starting with C (immediately before input_line_pointer) starts with
813 pre-opcode text appropriate for this target, 0 otherwise. */
816 tic6x_unrecognized_line (int c
)
826 if (input_line_pointer
[0] == '|')
828 if (input_line_pointer
[1] == '^')
830 tic6x_line_spmask
= true;
831 input_line_pointer
+= 2;
834 input_line_pointer
+= 1;
835 if (tic6x_line_parallel
)
836 as_bad (_("multiple '||' on same line"));
837 tic6x_line_parallel
= true;
839 as_bad (_("'||' after predicate"));
845 /* If it doesn't look like a predicate at all, just return 0.
846 If it looks like one but not a valid one, give a better
848 p
= input_line_pointer
;
849 while (*p
!= ']' && !is_end_of_line
[(unsigned char) *p
])
854 p
= input_line_pointer
;
856 bad_predicate
= false;
862 if (*p
== 'A' || *p
== 'a')
864 else if (*p
== 'B' || *p
== 'b')
868 areg
= true; /* Avoid uninitialized warning. */
869 bad_predicate
= true;
874 if (*p
!= '0' && *p
!= '1' && *p
!= '2')
875 bad_predicate
= true;
876 else if (p
[1] != ']')
877 bad_predicate
= true;
879 input_line_pointer
= p
+ 2;
883 as_bad (_("multiple predicates on same line"));
889 as_bad (_("bad predicate '%s'"), input_line_pointer
- 1);
891 input_line_pointer
= endp
;
898 tic6x_line_creg
= (areg
? 6 : 1);
899 if (areg
&& !tic6x_predicate_a0
)
900 as_bad (_("predication on A0 not supported on this architecture"));
904 tic6x_line_creg
= (areg
? 4 : 2);
908 tic6x_line_creg
= (areg
? 5 : 3);
923 /* Do any target-specific handling of a label required. */
926 tic6x_frob_label (symbolS
*sym
)
928 segment_info_type
*si
;
929 tic6x_label_list
*list
;
931 if (tic6x_line_parallel
)
933 as_bad (_("label after '||'"));
934 tic6x_line_parallel
= false;
935 tic6x_line_spmask
= false;
939 as_bad (_("label after predicate"));
944 si
= seg_info (now_seg
);
945 list
= si
->tc_segment_info_data
.label_list
;
946 si
->tc_segment_info_data
.label_list
= XNEW (tic6x_label_list
);
947 si
->tc_segment_info_data
.label_list
->next
= list
;
948 si
->tc_segment_info_data
.label_list
->label
= sym
;
950 /* Defining tc_frob_label overrides the ELF definition of
951 obj_frob_label, so we need to apply its effects here. */
952 dwarf2_emit_label (sym
);
955 /* At end-of-line, give errors for start-of-line decorations that
956 needed an instruction but were not followed by one. */
959 tic6x_end_of_line (void)
961 if (tic6x_line_parallel
)
963 as_bad (_("'||' not followed by instruction"));
964 tic6x_line_parallel
= false;
965 tic6x_line_spmask
= false;
969 as_bad (_("predicate not followed by instruction"));
975 /* Do any target-specific handling of the start of a logical line. */
978 tic6x_start_line_hook (void)
980 tic6x_end_of_line ();
983 /* Do target-specific handling immediately after an input file from
984 the command line, and any other inputs it includes, have been
990 tic6x_end_of_line ();
993 /* Do target-specific initialization after arguments have been
994 processed and the output file created. */
997 tic6x_init_after_args (void)
999 elf32_tic6x_set_use_rela_p (stdoutput
, tic6x_generate_rela
);
1002 /* Free LIST of labels (possibly NULL). */
1005 tic6x_free_label_list (tic6x_label_list
*list
)
1009 tic6x_label_list
*old
= list
;
1016 /* Handle a data alignment of N bytes. */
1019 tic6x_cons_align (int n ATTRIBUTE_UNUSED
)
1021 segment_info_type
*seginfo
= seg_info (now_seg
);
1023 /* Data means there is no current execute packet, and that any label
1024 applies to that data rather than a subsequent instruction. */
1025 tic6x_free_label_list (seginfo
->tc_segment_info_data
.label_list
);
1026 seginfo
->tc_segment_info_data
.label_list
= NULL
;
1027 seginfo
->tc_segment_info_data
.execute_packet_frag
= NULL
;
1028 seginfo
->tc_segment_info_data
.last_insn_lsb
= NULL
;
1029 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
1030 seginfo
->tc_segment_info_data
.func_units_used
= 0;
1033 /* Handle an alignment directive. Return TRUE if the
1034 machine-independent frag generation should be skipped. */
1037 tic6x_do_align (int n
, char *fill
, int len ATTRIBUTE_UNUSED
, int max
)
1039 /* Given code alignments of 4, 8, 16 or 32 bytes, we try to handle
1040 them in the md_finish pass by inserting NOPs in parallel with
1041 previous instructions. We only do this in sections containing
1042 nothing but instructions. Code alignments of 1 or 2 bytes have
1043 no effect in such sections (but we record them with
1044 machine-dependent frags anyway so they can be skipped or
1045 converted to machine-independent), while those of more than 64
1046 bytes cannot reliably be handled in this way. */
1052 && subseg_text_p (now_seg
))
1060 /* Machine-independent code would generate a frag here, but we
1061 wish to handle it in a machine-dependent way. */
1062 if (frag_now_fix () != 0)
1064 if (frag_now
->fr_type
!= rs_machine_dependent
)
1065 frag_wane (frag_now
);
1070 align_frag
= frag_now
;
1071 p
= frag_var (rs_machine_dependent
, 32, 32, max
, NULL
, n
, NULL
);
1072 /* This must be the same as the frag to which a pointer was just
1074 if (p
!= align_frag
->fr_literal
)
1076 align_frag
->tc_frag_data
.is_insns
= false;
1083 /* Types of operand for parsing purposes. These are used as bit-masks
1084 to tell tic6x_parse_operand what forms of operand are
1086 #define TIC6X_OP_EXP 0x0001u
1087 #define TIC6X_OP_REG 0x0002u
1088 #define TIC6X_OP_REGPAIR 0x0004u
1089 #define TIC6X_OP_IRP 0x0008u
1090 #define TIC6X_OP_NRP 0x0010u
1091 /* With TIC6X_OP_MEM_NOUNREG, the contents of a () offset are always
1092 interpreted as an expression, which may be a symbol with the same
1093 name as a register that ends up being implicitly DP-relative. With
1094 TIC6X_OP_MEM_UNREG, the contents of a () offset are interpreted as
1095 a register if they match one, and failing that as an expression,
1096 which must be constant. */
1097 #define TIC6X_OP_MEM_NOUNREG 0x0020u
1098 #define TIC6X_OP_MEM_UNREG 0x0040u
1099 #define TIC6X_OP_CTRL 0x0080u
1100 #define TIC6X_OP_FUNC_UNIT 0x0100u
1102 /* A register or register pair read by the assembler. */
1105 /* The side the register is on (1 or 2). */
1107 /* The register number (0 to 31). */
1111 /* Types of modification of a base address. */
1116 tic6x_mem_mod_minus
,
1117 tic6x_mem_mod_preinc
,
1118 tic6x_mem_mod_predec
,
1119 tic6x_mem_mod_postinc
,
1120 tic6x_mem_mod_postdec
1123 /* Scaled [] or unscaled () nature of an offset. */
1127 tic6x_offset_scaled
,
1128 tic6x_offset_unscaled
1129 } tic6x_mem_scaling
;
1131 /* A memory operand read by the assembler. */
1134 /* The base register. */
1135 tic6x_register base_reg
;
1136 /* How the base register is modified. */
1138 /* Whether there is an offset (required with plain "+" and "-"), and
1139 whether it is scaled or unscaled if so. */
1140 tic6x_mem_scaling scaled
;
1141 /* Whether the offset is a register (TRUE) or an expression
1152 /* A functional unit in SPMASK operands read by the assembler. */
1155 /* The basic unit. */
1156 tic6x_func_unit_base base
;
1157 /* The side (1 or 2). */
1159 } tic6x_func_unit_operand
;
1161 /* An operand read by the assembler. */
1164 /* The syntactic form of the operand, as one of the bit-masks
1167 /* The operand value. */
1170 /* An expression: TIC6X_OP_EXP. */
1172 /* A register: TIC6X_OP_REG, TIC6X_OP_REGPAIR. */
1174 /* A memory reference: TIC6X_OP_MEM_NOUNREG,
1175 TIC6X_OP_MEM_UNREG. */
1177 /* A control register: TIC6X_OP_CTRL. */
1179 /* A functional unit: TIC6X_OP_FUNC_UNIT. */
1180 tic6x_func_unit_operand func_unit
;
1184 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1186 /* Parse a register operand, or part of an operand, starting at *P.
1187 If syntactically OK (including that the number is in the range 0 to
1188 31, but not necessarily in range for this architecture), return
1189 TRUE, putting the register side and number in *REG and update *P to
1190 point immediately after the register number; otherwise return FALSE
1191 without changing *P (but possibly changing *REG). Do not print any
1195 tic6x_parse_register (char **p
, tic6x_register
*reg
)
1216 if (*r
>= '0' && *r
<= '9')
1218 reg
->num
= *r
- '0';
1224 if (reg
->num
> 0 && *r
>= '0' && *r
<= '9')
1226 reg
->num
= reg
->num
* 10 + (*r
- '0');
1230 if (*r
>= '0' && *r
<= '9')
1239 /* Parse the initial two characters of a functional unit name starting
1240 at *P. If OK, set *BASE and *SIDE and return true; otherwise,
1244 tic6x_parse_func_unit_base (char *p
, tic6x_func_unit_base
*base
,
1247 bool good_func_unit
= true;
1248 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
1249 unsigned int maybe_side
= 0;
1255 maybe_base
= tic6x_func_unit_d
;
1260 maybe_base
= tic6x_func_unit_l
;
1265 maybe_base
= tic6x_func_unit_m
;
1270 maybe_base
= tic6x_func_unit_s
;
1274 good_func_unit
= false;
1290 good_func_unit
= false;
1300 return good_func_unit
;
1303 /* Parse an operand starting at *P. If the operand parses OK, return
1304 TRUE and store the value in *OP; otherwise return FALSE (possibly
1305 changing *OP). In any case, update *P to point to the following
1306 comma or end of line. The possible operand forms are given by
1307 OP_FORMS. For diagnostics, this is operand OPNO of an opcode
1308 starting at STR, length OPC_LEN. */
1311 tic6x_parse_operand (char **p
, tic6x_operand
*op
, unsigned int op_forms
,
1312 char *str
, int opc_len
, unsigned int opno
)
1314 bool operand_parsed
= false;
1317 if ((op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
1318 == (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
1321 /* Check for functional unit names for SPMASK and SPMASKR. */
1322 if (!operand_parsed
&& (op_forms
& TIC6X_OP_FUNC_UNIT
))
1324 tic6x_func_unit_base base
= tic6x_func_unit_nfu
;
1325 unsigned int side
= 0;
1327 if (tic6x_parse_func_unit_base (q
, &base
, &side
))
1331 skip_whitespace (rq
);
1332 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1334 op
->form
= TIC6X_OP_FUNC_UNIT
;
1335 op
->value
.func_unit
.base
= base
;
1336 op
->value
.func_unit
.side
= side
;
1337 operand_parsed
= true;
1343 /* Check for literal "irp". */
1344 if (!operand_parsed
&& (op_forms
& TIC6X_OP_IRP
))
1346 if ((q
[0] == 'i' || q
[0] == 'I')
1347 && (q
[1] == 'r' || q
[1] == 'R')
1348 && (q
[2] == 'p' || q
[2] == 'P'))
1352 skip_whitespace (rq
);
1353 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1355 op
->form
= TIC6X_OP_IRP
;
1356 operand_parsed
= true;
1362 /* Check for literal "nrp". */
1363 if (!operand_parsed
&& (op_forms
& TIC6X_OP_NRP
))
1365 if ((q
[0] == 'n' || q
[0] == 'N')
1366 && (q
[1] == 'r' || q
[1] == 'R')
1367 && (q
[2] == 'p' || q
[2] == 'P'))
1371 skip_whitespace (rq
);
1372 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1374 op
->form
= TIC6X_OP_NRP
;
1375 operand_parsed
= true;
1381 /* Check for control register names. */
1382 if (!operand_parsed
&& (op_forms
& TIC6X_OP_CTRL
))
1386 for (crid
= 0; crid
< tic6x_ctrl_max
; crid
++)
1388 size_t len
= strlen (tic6x_ctrl_table
[crid
].name
);
1390 if (strncasecmp (tic6x_ctrl_table
[crid
].name
, q
, len
) == 0)
1394 skip_whitespace (rq
);
1395 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1397 op
->form
= TIC6X_OP_CTRL
;
1398 op
->value
.ctrl
= crid
;
1399 operand_parsed
= true;
1401 if (!(tic6x_ctrl_table
[crid
].isa_variants
& tic6x_features
))
1402 as_bad (_("control register '%s' not supported "
1403 "on this architecture"),
1404 tic6x_ctrl_table
[crid
].name
);
1410 /* See if this looks like a memory reference. */
1412 && (op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
)))
1416 tic6x_mem_mod mem_mod
= tic6x_mem_mod_none
;
1417 tic6x_register base_reg
;
1418 bool require_offset
, permit_offset
;
1419 tic6x_mem_scaling scaled
;
1421 expressionS offset_exp
;
1422 tic6x_register offset_reg
;
1431 skip_whitespace (mq
);
1437 mem_mod
= tic6x_mem_mod_preinc
;
1442 mem_mod
= tic6x_mem_mod_plus
;
1450 mem_mod
= tic6x_mem_mod_predec
;
1455 mem_mod
= tic6x_mem_mod_minus
;
1467 skip_whitespace (mq
);
1468 mem_ok
= tic6x_parse_register (&mq
, &base_reg
);
1471 if (mem_ok
&& mem_mod
== tic6x_mem_mod_none
)
1473 skip_whitespace (mq
);
1474 if (mq
[0] == '+' && mq
[1] == '+')
1476 mem_mod
= tic6x_mem_mod_postinc
;
1479 else if (mq
[0] == '-' && mq
[1] == '-')
1481 mem_mod
= tic6x_mem_mod_postdec
;
1486 if (mem_mod
== tic6x_mem_mod_none
)
1487 permit_offset
= false;
1489 permit_offset
= true;
1490 if (mem_mod
== tic6x_mem_mod_plus
|| mem_mod
== tic6x_mem_mod_minus
)
1491 require_offset
= true;
1493 require_offset
= false;
1494 scaled
= tic6x_offset_none
;
1495 offset_is_reg
= false;
1497 if (mem_ok
&& permit_offset
)
1501 skip_whitespace (mq
);
1505 scaled
= tic6x_offset_scaled
;
1511 scaled
= tic6x_offset_unscaled
;
1519 if (scaled
!= tic6x_offset_none
)
1521 skip_whitespace (mq
);
1522 if (scaled
== tic6x_offset_scaled
1523 || (op_forms
& TIC6X_OP_MEM_UNREG
))
1528 reg_ok
= tic6x_parse_register (&rq
, &offset_reg
);
1531 skip_whitespace (rq
);
1535 offset_is_reg
= true;
1541 char *save_input_line_pointer
;
1543 save_input_line_pointer
= input_line_pointer
;
1544 input_line_pointer
= mq
;
1545 expression (&offset_exp
);
1546 mq
= input_line_pointer
;
1547 input_line_pointer
= save_input_line_pointer
;
1549 skip_whitespace (mq
);
1557 if (mem_ok
&& require_offset
&& scaled
== tic6x_offset_none
)
1562 skip_whitespace (mq
);
1563 if (!is_end_of_line
[(unsigned char) *mq
] && *mq
!= ',')
1569 op
->form
= op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
);
1570 op
->value
.mem
.base_reg
= base_reg
;
1571 op
->value
.mem
.mod
= mem_mod
;
1572 op
->value
.mem
.scaled
= scaled
;
1573 op
->value
.mem
.offset_is_reg
= offset_is_reg
;
1575 op
->value
.mem
.offset
.reg
= offset_reg
;
1577 op
->value
.mem
.offset
.exp
= offset_exp
;
1578 operand_parsed
= true;
1580 if (base_reg
.num
>= tic6x_num_registers
)
1581 as_bad (_("register number %u not supported on this architecture"),
1583 if (offset_is_reg
&& offset_reg
.num
>= tic6x_num_registers
)
1584 as_bad (_("register number %u not supported on this architecture"),
1589 /* See if this looks like a register or register pair. */
1590 if (!operand_parsed
&& (op_forms
& (TIC6X_OP_REG
| TIC6X_OP_REGPAIR
)))
1592 tic6x_register first_reg
, second_reg
;
1596 reg_ok
= tic6x_parse_register (&rq
, &first_reg
);
1600 if (*rq
== ':' && (op_forms
& TIC6X_OP_REGPAIR
))
1603 reg_ok
= tic6x_parse_register (&rq
, &second_reg
);
1606 skip_whitespace (rq
);
1607 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1609 if ((second_reg
.num
& 1)
1610 || (first_reg
.num
!= second_reg
.num
+ 1)
1611 || (first_reg
.side
!= second_reg
.side
))
1612 as_bad (_("register pair for operand %u of '%.*s'"
1613 " not a valid even/odd pair"), opno
,
1615 op
->form
= TIC6X_OP_REGPAIR
;
1616 op
->value
.reg
= second_reg
;
1617 operand_parsed
= true;
1622 else if (op_forms
& TIC6X_OP_REG
)
1624 skip_whitespace (rq
);
1625 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1627 op
->form
= TIC6X_OP_REG
;
1628 op
->value
.reg
= first_reg
;
1629 operand_parsed
= true;
1636 if (first_reg
.num
>= tic6x_num_registers
)
1637 as_bad (_("register number %u not supported on this architecture"),
1639 if (op
->form
== TIC6X_OP_REGPAIR
1640 && second_reg
.num
>= tic6x_num_registers
)
1641 as_bad (_("register number %u not supported on this architecture"),
1646 /* Otherwise, parse it as an expression. */
1647 if (!operand_parsed
&& (op_forms
& TIC6X_OP_EXP
))
1649 char *save_input_line_pointer
;
1651 save_input_line_pointer
= input_line_pointer
;
1652 input_line_pointer
= q
;
1653 op
->form
= TIC6X_OP_EXP
;
1654 expression (&op
->value
.exp
);
1655 q
= input_line_pointer
;
1656 input_line_pointer
= save_input_line_pointer
;
1657 operand_parsed
= true;
1662 /* Now the operand has been parsed, there must be nothing more
1663 before the comma or end of line. */
1664 skip_whitespace (q
);
1665 if (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1667 operand_parsed
= false;
1668 as_bad (_("junk after operand %u of '%.*s'"), opno
,
1670 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1676 /* This could not be parsed as any acceptable form of
1680 case TIC6X_OP_REG
| TIC6X_OP_REGPAIR
:
1681 as_bad (_("bad register or register pair for operand %u of '%.*s'"),
1682 opno
, opc_len
, str
);
1685 case TIC6X_OP_REG
| TIC6X_OP_CTRL
:
1687 as_bad (_("bad register for operand %u of '%.*s'"),
1688 opno
, opc_len
, str
);
1691 case TIC6X_OP_REGPAIR
:
1692 as_bad (_("bad register pair for operand %u of '%.*s'"),
1693 opno
, opc_len
, str
);
1696 case TIC6X_OP_FUNC_UNIT
:
1697 as_bad (_("bad functional unit for operand %u of '%.*s'"),
1698 opno
, opc_len
, str
);
1702 as_bad (_("bad operand %u of '%.*s'"),
1703 opno
, opc_len
, str
);
1707 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1711 return operand_parsed
;
1714 /* Table of assembler operators and associated O_* values. */
1719 } tic6x_operator_table
;
1720 static const tic6x_operator_table tic6x_operators
[] = {
1721 #define O_dsbt_index O_md1
1722 { "dsbt_index", O_dsbt_index
},
1725 #define O_dpr_got O_md3
1726 { "dpr_got", O_dpr_got
},
1727 #define O_dpr_byte O_md4
1728 { "dpr_byte", O_dpr_byte
},
1729 #define O_dpr_hword O_md5
1730 { "dpr_hword", O_dpr_hword
},
1731 #define O_dpr_word O_md6
1732 { "dpr_word", O_dpr_word
},
1733 #define O_pcr_offset O_md7
1734 { "pcr_offset", O_pcr_offset
}
1737 /* Parse a name in some machine-specific way. Used on C6X to handle
1738 assembler operators. */
1741 tic6x_parse_name (const char *name
, expressionS
*exprP
,
1742 enum expr_mode mode ATTRIBUTE_UNUSED
, char *nextchar
)
1744 char *p
= input_line_pointer
;
1745 char c
, *name_start
, *name_end
;
1746 const char *inner_name
;
1748 operatorT op
= O_illegal
;
1749 symbolS
*sym
, *op_sym
= NULL
;
1754 for (i
= 0; i
< ARRAY_SIZE (tic6x_operators
); i
++)
1755 if (strcasecmp (name
+ 1, tic6x_operators
[i
].name
) == 0)
1757 op
= tic6x_operators
[i
].op
;
1761 if (op
== O_illegal
)
1764 *input_line_pointer
= *nextchar
;
1765 skip_whitespace (p
);
1769 *input_line_pointer
= 0;
1773 skip_whitespace (p
);
1775 if (!is_name_beginner (*p
))
1777 *input_line_pointer
= 0;
1783 while (is_part_of_name (*p
))
1786 skip_whitespace (p
);
1788 if (op
== O_pcr_offset
)
1790 char *op_name_start
, *op_name_end
;
1794 *input_line_pointer
= 0;
1798 skip_whitespace (p
);
1800 if (!is_name_beginner (*p
))
1802 *input_line_pointer
= 0;
1808 while (is_part_of_name (*p
))
1811 skip_whitespace (p
);
1815 op_sym
= symbol_find_or_make (op_name_start
);
1821 *input_line_pointer
= 0;
1825 input_line_pointer
= p
+ 1;
1826 *nextchar
= *input_line_pointer
;
1827 *input_line_pointer
= 0;
1831 inner_name
= name_start
;
1832 if (op
== O_dsbt_index
&& strcmp (inner_name
, "__c6xabi_DSBT_BASE") != 0)
1834 as_bad (_("$DSBT_INDEX must be used with __c6xabi_DSBT_BASE"));
1835 inner_name
= "__c6xabi_DSBT_BASE";
1837 sym
= symbol_find_or_make (inner_name
);
1841 exprP
->X_add_symbol
= sym
;
1842 exprP
->X_add_number
= 0;
1843 exprP
->X_op_symbol
= op_sym
;
1849 /* Create a fixup for an expression. Same arguments as fix_new_exp,
1850 plus FIX_ADDA which is TRUE for ADDA instructions (to indicate that
1851 fixes resolving to constants should have those constants implicitly
1852 shifted) and FALSE otherwise, but look for C6X-specific expression
1853 types and adjust the relocations or give errors accordingly. */
1856 tic6x_fix_new_exp (fragS
*frag
, int where
, int size
, expressionS
*exp
,
1857 int pcrel
, bfd_reloc_code_real_type r_type
,
1860 bfd_reloc_code_real_type new_reloc
= BFD_RELOC_UNUSED
;
1861 symbolS
*subsy
= NULL
;
1869 case BFD_RELOC_C6000_SBR_U15_W
:
1870 new_reloc
= BFD_RELOC_C6000_DSBT_INDEX
;
1874 as_bad (_("$DSBT_INDEX not supported in this context"));
1882 case BFD_RELOC_C6000_SBR_U15_W
:
1883 new_reloc
= BFD_RELOC_C6000_SBR_GOT_U15_W
;
1887 as_bad (_("$GOT not supported in this context"));
1895 case BFD_RELOC_C6000_ABS_L16
:
1896 new_reloc
= BFD_RELOC_C6000_SBR_GOT_L16_W
;
1899 case BFD_RELOC_C6000_ABS_H16
:
1900 new_reloc
= BFD_RELOC_C6000_SBR_GOT_H16_W
;
1904 as_bad (_("$DPR_GOT not supported in this context"));
1912 case BFD_RELOC_C6000_ABS_S16
:
1913 new_reloc
= BFD_RELOC_C6000_SBR_S16
;
1916 case BFD_RELOC_C6000_ABS_L16
:
1917 new_reloc
= BFD_RELOC_C6000_SBR_L16_B
;
1920 case BFD_RELOC_C6000_ABS_H16
:
1921 new_reloc
= BFD_RELOC_C6000_SBR_H16_B
;
1925 as_bad (_("$DPR_BYTE not supported in this context"));
1933 case BFD_RELOC_C6000_ABS_L16
:
1934 new_reloc
= BFD_RELOC_C6000_SBR_L16_H
;
1937 case BFD_RELOC_C6000_ABS_H16
:
1938 new_reloc
= BFD_RELOC_C6000_SBR_H16_H
;
1942 as_bad (_("$DPR_HWORD not supported in this context"));
1950 case BFD_RELOC_C6000_ABS_L16
:
1951 new_reloc
= BFD_RELOC_C6000_SBR_L16_W
;
1954 case BFD_RELOC_C6000_ABS_H16
:
1955 new_reloc
= BFD_RELOC_C6000_SBR_H16_W
;
1959 as_bad (_("$DPR_WORD not supported in this context"));
1965 subsy
= exp
->X_op_symbol
;
1968 case BFD_RELOC_C6000_ABS_S16
:
1969 case BFD_RELOC_C6000_ABS_L16
:
1970 new_reloc
= BFD_RELOC_C6000_PCR_L16
;
1973 case BFD_RELOC_C6000_ABS_H16
:
1974 new_reloc
= BFD_RELOC_C6000_PCR_H16
;
1978 as_bad (_("$PCR_OFFSET not supported in this context"));
1989 as_bad (_("invalid PC-relative operand"));
1995 if (new_reloc
== BFD_RELOC_UNUSED
)
1996 fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1998 fix
= fix_new (frag
, where
, size
, exp
->X_add_symbol
, exp
->X_add_number
,
2000 fix
->tc_fix_data
.fix_subsy
= subsy
;
2001 fix
->tc_fix_data
.fix_adda
= fix_adda
;
2004 /* Generate a fix for a constant (.word etc.). Needed to ensure these
2005 go through the error checking in tic6x_fix_new_exp. */
2008 tic6x_cons_fix_new (fragS
*frag
, int where
, int size
, expressionS
*exp
,
2009 bfd_reloc_code_real_type r_type
)
2014 r_type
= BFD_RELOC_8
;
2018 r_type
= BFD_RELOC_16
;
2022 r_type
= BFD_RELOC_32
;
2026 as_bad (_("no %d-byte relocations available"), size
);
2030 tic6x_fix_new_exp (frag
, where
, size
, exp
, 0, r_type
, false);
2033 /* Initialize target-specific fix data. */
2036 tic6x_init_fix_data (fixS
*fixP
)
2038 fixP
->tc_fix_data
.fix_adda
= false;
2039 fixP
->tc_fix_data
.fix_subsy
= NULL
;
2042 /* Return true if the fix can be handled by GAS, false if it must
2043 be passed through to the linker. */
2046 tic6x_fix_adjustable (fixS
*fixP
)
2048 switch (fixP
->fx_r_type
)
2050 /* Adjust_reloc_syms doesn't know about the GOT. */
2051 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
2052 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
2053 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
2054 case BFD_RELOC_C6000_EHTYPE
:
2057 case BFD_RELOC_C6000_PREL31
:
2060 case BFD_RELOC_C6000_PCR_H16
:
2061 case BFD_RELOC_C6000_PCR_L16
:
2069 /* Given the fine-grained form of an operand, return the coarse
2073 tic6x_coarse_operand_form (tic6x_operand_form form
)
2077 case tic6x_operand_asm_const
:
2078 case tic6x_operand_link_const
:
2079 return TIC6X_OP_EXP
;
2081 case tic6x_operand_reg
:
2082 case tic6x_operand_xreg
:
2083 case tic6x_operand_dreg
:
2084 case tic6x_operand_areg
:
2085 case tic6x_operand_retreg
:
2086 return TIC6X_OP_REG
;
2088 case tic6x_operand_regpair
:
2089 case tic6x_operand_xregpair
:
2090 case tic6x_operand_dregpair
:
2091 return TIC6X_OP_REGPAIR
;
2093 case tic6x_operand_irp
:
2094 return TIC6X_OP_IRP
;
2096 case tic6x_operand_nrp
:
2097 return TIC6X_OP_NRP
;
2099 case tic6x_operand_ctrl
:
2100 return TIC6X_OP_CTRL
;
2102 case tic6x_operand_mem_short
:
2103 case tic6x_operand_mem_long
:
2104 case tic6x_operand_mem_deref
:
2105 return TIC6X_OP_MEM_NOUNREG
;
2107 case tic6x_operand_mem_ndw
:
2108 return TIC6X_OP_MEM_UNREG
;
2110 case tic6x_operand_func_unit
:
2111 return TIC6X_OP_FUNC_UNIT
;
2118 /* How an operand may match or not match a desired form. If different
2119 instruction alternatives fail in different ways, the first failure
2120 in this list determines the diagnostic. */
2124 tic6x_match_matches
,
2125 /* Bad coarse form. */
2128 tic6x_match_non_const
,
2129 /* Register on wrong side. */
2130 tic6x_match_wrong_side
,
2131 /* Not a valid address register. */
2132 tic6x_match_bad_address
,
2133 /* Not a valid return address register. */
2134 tic6x_match_bad_return
,
2135 /* Control register not readable. */
2136 tic6x_match_ctrl_write_only
,
2137 /* Control register not writable. */
2138 tic6x_match_ctrl_read_only
,
2139 /* Not a valid memory reference for this instruction. */
2141 } tic6x_operand_match
;
2143 /* Return whether an operand matches the given fine-grained form and
2144 read/write usage, and, if it does not match, how it fails to match.
2145 The main functional unit side is SIDE; the cross-path side is CROSS
2146 (the same as SIDE if a cross path not used); the data side is
2148 static tic6x_operand_match
2149 tic6x_operand_matches_form (const tic6x_operand
*op
, tic6x_operand_form form
,
2150 tic6x_rw rw
, unsigned int side
, unsigned int cross
,
2151 unsigned int data_side
)
2153 unsigned int coarse
= tic6x_coarse_operand_form (form
);
2155 if (coarse
!= op
->form
)
2156 return tic6x_match_coarse
;
2160 case tic6x_operand_asm_const
:
2161 if (op
->value
.exp
.X_op
== O_constant
)
2162 return tic6x_match_matches
;
2164 return tic6x_match_non_const
;
2166 case tic6x_operand_link_const
:
2167 case tic6x_operand_irp
:
2168 case tic6x_operand_nrp
:
2169 case tic6x_operand_func_unit
:
2170 /* All expressions are link-time constants, although there may
2171 not be relocations to express them in the output file. "irp"
2172 and "nrp" are unique operand values. All parsed functional
2173 unit names are valid. */
2174 return tic6x_match_matches
;
2176 case tic6x_operand_reg
:
2177 case tic6x_operand_regpair
:
2178 if (op
->value
.reg
.side
== side
)
2179 return tic6x_match_matches
;
2181 return tic6x_match_wrong_side
;
2183 case tic6x_operand_xreg
:
2184 case tic6x_operand_xregpair
:
2185 if (op
->value
.reg
.side
== cross
)
2186 return tic6x_match_matches
;
2188 return tic6x_match_wrong_side
;
2190 case tic6x_operand_dreg
:
2191 case tic6x_operand_dregpair
:
2192 if (op
->value
.reg
.side
== data_side
)
2193 return tic6x_match_matches
;
2195 return tic6x_match_wrong_side
;
2197 case tic6x_operand_areg
:
2198 if (op
->value
.reg
.side
!= cross
)
2199 return tic6x_match_wrong_side
;
2200 else if (op
->value
.reg
.side
== 2
2201 && (op
->value
.reg
.num
== 14 || op
->value
.reg
.num
== 15))
2202 return tic6x_match_matches
;
2204 return tic6x_match_bad_address
;
2206 case tic6x_operand_retreg
:
2207 if (op
->value
.reg
.side
!= side
)
2208 return tic6x_match_wrong_side
;
2209 else if (op
->value
.reg
.num
!= 3)
2210 return tic6x_match_bad_return
;
2212 return tic6x_match_matches
;
2214 case tic6x_operand_ctrl
:
2218 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read
2219 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
2220 return tic6x_match_matches
;
2222 return tic6x_match_ctrl_write_only
;
2224 case tic6x_rw_write
:
2225 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_write
2226 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
2227 return tic6x_match_matches
;
2229 return tic6x_match_ctrl_read_only
;
2235 case tic6x_operand_mem_deref
:
2236 if (op
->value
.mem
.mod
!= tic6x_mem_mod_none
)
2237 return tic6x_match_bad_mem
;
2238 else if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2240 else if (op
->value
.mem
.base_reg
.side
!= side
)
2241 return tic6x_match_bad_mem
;
2243 return tic6x_match_matches
;
2245 case tic6x_operand_mem_short
:
2246 case tic6x_operand_mem_ndw
:
2247 if (op
->value
.mem
.base_reg
.side
!= side
)
2248 return tic6x_match_bad_mem
;
2249 if (op
->value
.mem
.mod
== tic6x_mem_mod_none
)
2251 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2253 return tic6x_match_matches
;
2255 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
2257 if (op
->value
.mem
.mod
== tic6x_mem_mod_plus
2258 || op
->value
.mem
.mod
== tic6x_mem_mod_minus
)
2260 return tic6x_match_matches
;
2262 if (op
->value
.mem
.offset_is_reg
)
2264 if (op
->value
.mem
.scaled
== tic6x_offset_unscaled
2265 && form
!= tic6x_operand_mem_ndw
)
2267 if (op
->value
.mem
.offset
.reg
.side
== side
)
2268 return tic6x_match_matches
;
2270 return tic6x_match_bad_mem
;
2274 if (op
->value
.mem
.offset
.exp
.X_op
== O_constant
)
2275 return tic6x_match_matches
;
2277 return tic6x_match_bad_mem
;
2280 case tic6x_operand_mem_long
:
2281 if (op
->value
.mem
.base_reg
.side
== 2
2282 && (op
->value
.mem
.base_reg
.num
== 14
2283 || op
->value
.mem
.base_reg
.num
== 15))
2285 switch (op
->value
.mem
.mod
)
2287 case tic6x_mem_mod_none
:
2288 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2290 return tic6x_match_matches
;
2292 case tic6x_mem_mod_plus
:
2293 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
2295 if (op
->value
.mem
.offset_is_reg
)
2296 return tic6x_match_bad_mem
;
2297 else if (op
->value
.mem
.scaled
== tic6x_offset_scaled
2298 && op
->value
.mem
.offset
.exp
.X_op
!= O_constant
)
2299 return tic6x_match_bad_mem
;
2301 return tic6x_match_matches
;
2303 case tic6x_mem_mod_minus
:
2304 case tic6x_mem_mod_preinc
:
2305 case tic6x_mem_mod_predec
:
2306 case tic6x_mem_mod_postinc
:
2307 case tic6x_mem_mod_postdec
:
2308 return tic6x_match_bad_mem
;
2316 return tic6x_match_bad_mem
;
2323 /* Return the number of bits shift used with DP-relative coding method
2327 tic6x_dpr_shift (tic6x_coding_method coding
)
2331 case tic6x_coding_ulcst_dpr_byte
:
2334 case tic6x_coding_ulcst_dpr_half
:
2337 case tic6x_coding_ulcst_dpr_word
:
2345 /* Return the relocation used with DP-relative coding method
2348 static bfd_reloc_code_real_type
2349 tic6x_dpr_reloc (tic6x_coding_method coding
)
2353 case tic6x_coding_ulcst_dpr_byte
:
2354 return BFD_RELOC_C6000_SBR_U15_B
;
2356 case tic6x_coding_ulcst_dpr_half
:
2357 return BFD_RELOC_C6000_SBR_U15_H
;
2359 case tic6x_coding_ulcst_dpr_word
:
2360 return BFD_RELOC_C6000_SBR_U15_W
;
2367 /* Given a memory reference *MEM_REF as originally parsed, fill in
2368 defaults for missing offsets. */
2371 tic6x_default_mem_ref (tic6x_mem_ref
*mem_ref
)
2373 switch (mem_ref
->mod
)
2375 case tic6x_mem_mod_none
:
2376 if (mem_ref
->scaled
!= tic6x_offset_none
)
2378 mem_ref
->mod
= tic6x_mem_mod_plus
;
2379 mem_ref
->scaled
= tic6x_offset_unscaled
;
2380 mem_ref
->offset_is_reg
= false;
2381 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
2382 mem_ref
->offset
.exp
.X_op
= O_constant
;
2383 mem_ref
->offset
.exp
.X_add_number
= 0;
2384 mem_ref
->offset
.exp
.X_unsigned
= 0;
2387 case tic6x_mem_mod_plus
:
2388 case tic6x_mem_mod_minus
:
2389 if (mem_ref
->scaled
== tic6x_offset_none
)
2393 case tic6x_mem_mod_preinc
:
2394 case tic6x_mem_mod_predec
:
2395 case tic6x_mem_mod_postinc
:
2396 case tic6x_mem_mod_postdec
:
2397 if (mem_ref
->scaled
!= tic6x_offset_none
)
2399 mem_ref
->scaled
= tic6x_offset_scaled
;
2400 mem_ref
->offset_is_reg
= false;
2401 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
2402 mem_ref
->offset
.exp
.X_op
= O_constant
;
2403 mem_ref
->offset
.exp
.X_add_number
= 1;
2404 mem_ref
->offset
.exp
.X_unsigned
= 0;
2412 /* Return the encoding in the 8-bit field of an SPMASK or SPMASKR
2413 instruction of the specified UNIT, side SIDE. */
2416 tic6x_encode_spmask (tic6x_func_unit_base unit
, unsigned int side
)
2420 case tic6x_func_unit_l
:
2421 return 1 << (side
- 1);
2423 case tic6x_func_unit_s
:
2424 return 1 << (side
+ 1);
2426 case tic6x_func_unit_d
:
2427 return 1 << (side
+ 3);
2429 case tic6x_func_unit_m
:
2430 return 1 << (side
+ 5);
2437 /* Try to encode the instruction with opcode number ID and operands
2438 OPERANDS (number NUM_OPERANDS), creg value THIS_LINE_CREG and z
2439 value THIS_LINE_Z; FUNC_UNIT_SIDE, FUNC_UNIT_CROSS and
2440 FUNC_UNIT_DATA_SIDE describe the functional unit specification;
2441 SPLOOP_II is the ii value from the previous SPLOOP-family
2442 instruction, or 0 if not in such a loop; the only possible problems
2443 are operands being out of range (they already match the
2444 fine-grained form), and inappropriate predication. If this
2445 succeeds, return the encoding and set *OK to true; otherwise return
2446 0 and set *OK to FALSE. If a fix is needed, set *FIX_NEEDED to
2447 true and fill in *FIX_EXP, *FIX_PCREL, *FX_R_TYPE and *FIX_ADDA.
2448 Print error messages for failure if PRINT_ERRORS is true; the
2449 opcode starts at STR and has length OPC_LEN. */
2452 tic6x_try_encode (tic6x_opcode_id id
, tic6x_operand
*operands
,
2453 unsigned int num_operands
, unsigned int this_line_creg
,
2454 unsigned int this_line_z
, unsigned int func_unit_side
,
2455 unsigned int func_unit_cross
,
2456 unsigned int func_unit_data_side
, int sploop_ii
,
2457 expressionS
**fix_exp
, int *fix_pcrel
,
2458 bfd_reloc_code_real_type
*fx_r_type
, bool *fix_adda
,
2459 bool *fix_needed
, bool *ok
,
2460 bool print_errors
, char *str
, int opc_len
)
2462 const tic6x_opcode
*opct
;
2463 const tic6x_insn_format
*fmt
;
2464 unsigned int opcode_value
;
2467 opct
= &tic6x_opcode_table
[id
];
2468 fmt
= &tic6x_insn_format_table
[opct
->format
];
2469 opcode_value
= fmt
->cst_bits
;
2471 for (fld
= 0; fld
< opct
->num_fixed_fields
; fld
++)
2473 if (opct
->fixed_fields
[fld
].min_val
== opct
->fixed_fields
[fld
].max_val
)
2475 const tic6x_insn_field
*fldd
;
2476 fldd
= tic6x_field_from_fmt (fmt
, opct
->fixed_fields
[fld
].field_id
);
2479 opcode_value
|= opct
->fixed_fields
[fld
].min_val
<< fldd
->bitfields
[0].low_pos
;
2483 for (fld
= 0; fld
< opct
->num_variable_fields
; fld
++)
2485 const tic6x_insn_field
*fldd
;
2491 unsigned int fcyc_bits
;
2496 fldd
= tic6x_field_from_fmt (fmt
, opct
->variable_fields
[fld
].field_id
);
2499 opno
= opct
->variable_fields
[fld
].operand_num
;
2500 switch (opct
->variable_fields
[fld
].coding_method
)
2502 case tic6x_coding_ucst
:
2503 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2505 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2507 ucexp
= operands
[opno
].value
.exp
;
2509 if (ucexp
.X_add_number
< 0
2510 || ucexp
.X_add_number
>= (1 << fldd
->bitfields
[0].width
))
2513 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2518 value
= ucexp
.X_add_number
;
2521 case tic6x_coding_scst
:
2522 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2524 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2527 /* Opcode table should not permit non-constants without
2528 a known relocation for them. */
2529 if (fldd
->bitfields
[0].low_pos
!= 7 || fldd
->bitfields
[0].width
!= 16)
2532 *fix_exp
= &operands
[opno
].value
.exp
;
2534 *fx_r_type
= BFD_RELOC_C6000_ABS_S16
;
2538 sign_value
= SEXT (operands
[opno
].value
.exp
.X_add_number
);
2540 if (sign_value
< -(1 << (fldd
->bitfields
[0].width
- 1))
2541 || (sign_value
>= (1 << (fldd
->bitfields
[0].width
- 1))))
2544 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2549 value
= sign_value
+ (1 << (fldd
->bitfields
[0].width
- 1));
2550 value
^= (1 << (fldd
->bitfields
[0].width
- 1));
2553 case tic6x_coding_ucst_minus_one
:
2554 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2556 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2558 if (operands
[opno
].value
.exp
.X_add_number
<= 0
2559 || operands
[opno
].value
.exp
.X_add_number
> (1 << fldd
->bitfields
[0].width
))
2562 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2567 value
= operands
[opno
].value
.exp
.X_add_number
- 1;
2570 case tic6x_coding_scst_negate
:
2571 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2573 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2575 sign_value
= SEXT (-operands
[opno
].value
.exp
.X_add_number
);
2576 goto signed_constant
;
2578 case tic6x_coding_ulcst_dpr_byte
:
2579 case tic6x_coding_ulcst_dpr_half
:
2580 case tic6x_coding_ulcst_dpr_word
:
2581 bits
= tic6x_dpr_shift (opct
->variable_fields
[fld
].coding_method
);
2582 switch (operands
[opno
].form
)
2585 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2587 ucexp
= operands
[opno
].value
.exp
;
2588 goto unsigned_constant
;
2590 expp
= &operands
[opno
].value
.exp
;
2593 case TIC6X_OP_MEM_NOUNREG
:
2594 mem
= operands
[opno
].value
.mem
;
2595 tic6x_default_mem_ref (&mem
);
2596 if (mem
.offset_is_reg
)
2598 if (mem
.offset
.exp
.X_op
== O_constant
)
2600 ucexp
= mem
.offset
.exp
;
2601 if (mem
.scaled
== tic6x_offset_unscaled
)
2603 if (ucexp
.X_add_number
& ((1 << bits
) - 1))
2606 as_bad (_("offset in operand %u of '%.*s' not "
2607 "divisible by %u"), opno
+ 1, opc_len
,
2612 ucexp
.X_add_number
>>= bits
;
2614 goto unsigned_constant
;
2616 if (mem
.scaled
!= tic6x_offset_unscaled
)
2618 if (operands
[opno
].value
.mem
.mod
== tic6x_mem_mod_none
2619 || operands
[opno
].value
.mem
.scaled
!= tic6x_offset_unscaled
2620 || operands
[opno
].value
.mem
.offset_is_reg
)
2622 expp
= &operands
[opno
].value
.mem
.offset
.exp
;
2629 /* Opcode table should not use this encoding without a known
2631 if (fldd
->bitfields
[0].low_pos
!= 8 || fldd
->bitfields
[0].width
!= 15)
2633 /* We do not check for offset divisibility here; such a
2634 check is not needed at this point to encode the value,
2635 and if there is eventually a problem it will be detected
2636 either in md_apply_fix or at link time. */
2641 = tic6x_dpr_reloc (opct
->variable_fields
[fld
].coding_method
);
2642 if (operands
[opno
].form
== TIC6X_OP_EXP
)
2648 case tic6x_coding_lcst_low16
:
2649 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2651 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2652 value
= operands
[opno
].value
.exp
.X_add_number
& 0xffff;
2656 /* Opcode table should not use this encoding without a
2657 known relocation. */
2658 if (fldd
->bitfields
[0].low_pos
!= 7 || fldd
->bitfields
[0].width
!= 16)
2661 *fix_exp
= &operands
[opno
].value
.exp
;
2663 *fx_r_type
= BFD_RELOC_C6000_ABS_L16
;
2668 case tic6x_coding_lcst_high16
:
2669 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2671 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2672 value
= (operands
[opno
].value
.exp
.X_add_number
>> 16) & 0xffff;
2676 /* Opcode table should not use this encoding without a
2677 known relocation. */
2678 if (fldd
->bitfields
[0].low_pos
!= 7 || fldd
->bitfields
[0].width
!= 16)
2681 *fix_exp
= &operands
[opno
].value
.exp
;
2683 *fx_r_type
= BFD_RELOC_C6000_ABS_H16
;
2688 case tic6x_coding_pcrel
:
2689 case tic6x_coding_pcrel_half
:
2690 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2694 *fix_exp
= &operands
[opno
].value
.exp
;
2696 if (fldd
->bitfields
[0].low_pos
== 7 && fldd
->bitfields
[0].width
== 21)
2697 *fx_r_type
= BFD_RELOC_C6000_PCR_S21
;
2698 else if (fldd
->bitfields
[0].low_pos
== 16 && fldd
->bitfields
[0].width
== 12)
2699 *fx_r_type
= BFD_RELOC_C6000_PCR_S12
;
2700 else if (fldd
->bitfields
[0].low_pos
== 13 && fldd
->bitfields
[0].width
== 10)
2701 *fx_r_type
= BFD_RELOC_C6000_PCR_S10
;
2702 else if (fldd
->bitfields
[0].low_pos
== 16 && fldd
->bitfields
[0].width
== 7)
2703 *fx_r_type
= BFD_RELOC_C6000_PCR_S7
;
2705 /* Opcode table should not use this encoding without a
2706 known relocation. */
2711 case tic6x_coding_regpair_lsb
:
2712 switch (operands
[opno
].form
)
2714 case TIC6X_OP_REGPAIR
:
2715 value
= operands
[opno
].value
.reg
.num
;
2723 case tic6x_coding_regpair_msb
:
2724 switch (operands
[opno
].form
)
2726 case TIC6X_OP_REGPAIR
:
2727 value
= operands
[opno
].value
.reg
.num
+ 1;
2735 case tic6x_coding_reg
:
2736 switch (operands
[opno
].form
)
2739 case TIC6X_OP_REGPAIR
:
2740 value
= operands
[opno
].value
.reg
.num
;
2743 case TIC6X_OP_MEM_NOUNREG
:
2744 case TIC6X_OP_MEM_UNREG
:
2745 value
= operands
[opno
].value
.mem
.base_reg
.num
;
2753 case tic6x_coding_areg
:
2754 switch (operands
[opno
].form
)
2757 value
= (operands
[opno
].value
.reg
.num
== 15 ? 1 : 0);
2760 case TIC6X_OP_MEM_NOUNREG
:
2761 value
= (operands
[opno
].value
.mem
.base_reg
.num
== 15 ? 1 : 0);
2769 case tic6x_coding_crlo
:
2770 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2772 value
= tic6x_ctrl_table
[operands
[opno
].value
.ctrl
].crlo
;
2775 case tic6x_coding_crhi
:
2776 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2781 case tic6x_coding_reg_shift
:
2782 if (operands
[opno
].form
!= TIC6X_OP_REGPAIR
)
2784 value
= operands
[opno
].value
.reg
.num
>> 1;
2787 case tic6x_coding_mem_offset
:
2788 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
)
2790 mem
= operands
[opno
].value
.mem
;
2791 tic6x_default_mem_ref (&mem
);
2792 if (mem
.offset_is_reg
)
2794 if (mem
.scaled
!= tic6x_offset_scaled
)
2796 value
= mem
.offset
.reg
.num
;
2802 if (mem
.offset
.exp
.X_op
!= O_constant
)
2806 case tic6x_offset_scaled
:
2810 case tic6x_offset_unscaled
:
2811 scale
= opct
->operand_info
[opno
].size
;
2812 if (scale
!= 1 && scale
!= 2 && scale
!= 4 && scale
!= 8)
2819 if (mem
.offset
.exp
.X_add_number
< 0
2820 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->bitfields
[0].width
) * scale
)
2823 as_bad (_("offset in operand %u of '%.*s' out of range"),
2824 opno
+ 1, opc_len
, str
);
2828 if (mem
.offset
.exp
.X_add_number
% scale
)
2831 as_bad (_("offset in operand %u of '%.*s' not "
2833 opno
+ 1, opc_len
, str
, scale
);
2837 value
= mem
.offset
.exp
.X_add_number
/ scale
;
2841 case tic6x_coding_mem_offset_noscale
:
2842 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2844 mem
= operands
[opno
].value
.mem
;
2845 tic6x_default_mem_ref (&mem
);
2846 if (mem
.offset_is_reg
)
2847 value
= mem
.offset
.reg
.num
;
2850 if (mem
.offset
.exp
.X_op
!= O_constant
)
2852 if (mem
.offset
.exp
.X_add_number
< 0
2853 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->bitfields
[0].width
))
2856 as_bad (_("offset in operand %u of '%.*s' out of range"),
2857 opno
+ 1, opc_len
, str
);
2861 value
= mem
.offset
.exp
.X_add_number
;
2865 case tic6x_coding_mem_mode
:
2866 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
2867 && operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2869 mem
= operands
[opno
].value
.mem
;
2870 tic6x_default_mem_ref (&mem
);
2873 case tic6x_mem_mod_plus
:
2877 case tic6x_mem_mod_minus
:
2881 case tic6x_mem_mod_preinc
:
2885 case tic6x_mem_mod_predec
:
2889 case tic6x_mem_mod_postinc
:
2893 case tic6x_mem_mod_postdec
:
2900 value
+= (mem
.offset_is_reg
? 4 : 0);
2903 case tic6x_coding_scaled
:
2904 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2906 mem
= operands
[opno
].value
.mem
;
2907 tic6x_default_mem_ref (&mem
);
2910 case tic6x_offset_unscaled
:
2914 case tic6x_offset_scaled
:
2923 case tic6x_coding_spmask
:
2924 /* The position of such a field is hardcoded in the handling
2926 if (fldd
->bitfields
[0].low_pos
!= 18)
2929 for (opno
= 0; opno
< num_operands
; opno
++)
2933 v
= tic6x_encode_spmask (operands
[opno
].value
.func_unit
.base
,
2934 operands
[opno
].value
.func_unit
.side
);
2938 as_bad (_("functional unit already masked for operand "
2939 "%u of '%.*s'"), opno
+ 1, opc_len
, str
);
2947 case tic6x_coding_reg_unused
:
2948 /* This is a placeholder; correct handling goes along with
2949 resource constraint checks. */
2953 case tic6x_coding_fstg
:
2954 case tic6x_coding_fcyc
:
2955 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2957 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2962 as_bad (_("'%.*s' instruction not in a software "
2971 else if (sploop_ii
<= 2)
2973 else if (sploop_ii
<= 4)
2975 else if (sploop_ii
<= 8)
2977 else if (sploop_ii
<= 14)
2981 if (fcyc_bits
> fldd
->bitfields
[0].width
)
2984 if (opct
->variable_fields
[fld
].coding_method
== tic6x_coding_fstg
)
2987 if (operands
[opno
].value
.exp
.X_add_number
< 0
2988 || (operands
[opno
].value
.exp
.X_add_number
2989 >= (1 << (fldd
->bitfields
[0].width
- fcyc_bits
))))
2992 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2997 value
= operands
[opno
].value
.exp
.X_add_number
;
2998 for (t
= 0, i
= fcyc_bits
; i
< fldd
->bitfields
[0].width
; i
++)
3000 t
= (t
<< 1) | (value
& 1);
3003 value
= t
<< fcyc_bits
;
3007 if (operands
[opno
].value
.exp
.X_add_number
< 0
3008 || (operands
[opno
].value
.exp
.X_add_number
>= sploop_ii
))
3011 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
3016 value
= operands
[opno
].value
.exp
.X_add_number
;
3020 case tic6x_coding_fu
:
3021 value
= func_unit_side
== 2 ? 1 : 0;
3024 case tic6x_coding_data_fu
:
3025 value
= func_unit_data_side
== 2 ? 1 : 0;
3028 case tic6x_coding_xpath
:
3029 value
= func_unit_cross
;
3036 for (ffld
= 0; ffld
< opct
->num_fixed_fields
; ffld
++)
3037 if ((opct
->fixed_fields
[ffld
].field_id
3038 == opct
->variable_fields
[fld
].field_id
)
3039 && (value
< opct
->fixed_fields
[ffld
].min_val
3040 || value
> opct
->fixed_fields
[ffld
].max_val
))
3043 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
3049 opcode_value
|= value
<< fldd
->bitfields
[0].low_pos
;
3054 const tic6x_insn_field
*creg
;
3055 const tic6x_insn_field
*z
;
3057 creg
= tic6x_field_from_fmt (fmt
, tic6x_field_creg
);
3061 as_bad (_("instruction '%.*s' cannot be predicated"),
3066 z
= tic6x_field_from_fmt (fmt
, tic6x_field_z
);
3067 /* If there is a creg field, there must be a z field; otherwise
3068 there is an error in the format table. */
3072 opcode_value
|= this_line_creg
<< creg
->bitfields
[0].low_pos
;
3073 opcode_value
|= this_line_z
<< z
->bitfields
[0].low_pos
;
3077 return opcode_value
;
3080 /* Convert the target integer stored in N bytes in BUF to a host
3081 integer, returning that value. */
3084 md_chars_to_number (char *buf
, int n
)
3087 unsigned char *p
= (unsigned char *) buf
;
3089 if (target_big_endian
)
3094 result
|= (*p
++ & 0xff);
3102 result
|= (p
[n
] & 0xff);
3109 /* Assemble the instruction starting at STR (an opcode, with the
3110 opcode name all-lowercase). */
3113 md_assemble (char *str
)
3117 bool this_line_parallel
;
3118 bool this_line_spmask
;
3119 unsigned int this_line_creg
;
3120 unsigned int this_line_z
;
3121 tic6x_label_list
*this_insn_label_list
;
3122 segment_info_type
*seginfo
;
3123 tic6x_opcode_list
*opc_list
, *opc
;
3124 tic6x_func_unit_base func_unit_base
= tic6x_func_unit_nfu
;
3125 unsigned int func_unit_side
= 0;
3126 unsigned int func_unit_cross
= 0;
3127 unsigned int cross_side
= 0;
3128 unsigned int func_unit_data_side
= 0;
3129 unsigned int max_matching_opcodes
, num_matching_opcodes
;
3130 tic6x_opcode_id
*opcm
= NULL
;
3131 unsigned int opc_rank
[TIC6X_NUM_PREFER
];
3132 const tic6x_opcode
*opct
= NULL
;
3133 int min_rank
, try_rank
, max_rank
;
3134 bool num_operands_permitted
[TIC6X_MAX_SOURCE_OPERANDS
+ 1] = { false };
3135 unsigned int operand_forms
[TIC6X_MAX_SOURCE_OPERANDS
] = { 0 };
3136 tic6x_operand operands
[TIC6X_MAX_SOURCE_OPERANDS
];
3137 unsigned int max_num_operands
;
3138 unsigned int num_operands_read
;
3139 bool ok_this_arch
, ok_this_fu
, ok_this_arch_fu
;
3140 bool bad_operands
= false;
3141 unsigned int opcode_value
;
3143 bool fix_needed
= false;
3144 expressionS
*fix_exp
= NULL
;
3146 bfd_reloc_code_real_type fx_r_type
= BFD_RELOC_UNUSED
;
3147 bool fix_adda
= false;
3152 while (*p
&& !is_end_of_line
[(unsigned char) *p
] && *p
!= ' ')
3155 /* This function should only have been called when there is actually
3156 an instruction to assemble. */
3160 /* Now an instruction has been seen, architecture attributes from
3161 .arch directives merge with rather than overriding the previous
3163 tic6x_seen_insns
= true;
3164 /* If no .arch directives or -march options have been seen, we are
3165 assessing instruction validity based on the C674X default, so set
3166 the attribute accordingly. */
3167 if (tic6x_arch_attribute
== C6XABI_Tag_ISA_none
)
3168 tic6x_arch_attribute
= C6XABI_Tag_ISA_C674X
;
3170 /* Reset global settings for parallel bars and predicates now to
3171 avoid extra errors if there are problems with this opcode. */
3172 this_line_parallel
= tic6x_line_parallel
;
3173 this_line_spmask
= tic6x_line_spmask
;
3174 this_line_creg
= tic6x_line_creg
;
3175 this_line_z
= tic6x_line_z
;
3176 tic6x_line_parallel
= false;
3177 tic6x_line_spmask
= false;
3178 tic6x_line_creg
= 0;
3180 seginfo
= seg_info (now_seg
);
3181 this_insn_label_list
= seginfo
->tc_segment_info_data
.label_list
;
3182 seginfo
->tc_segment_info_data
.label_list
= NULL
;
3184 opc_list
= str_hash_find_n (opcode_hash
, str
, p
- str
);
3185 if (opc_list
== NULL
)
3189 as_bad (_("unknown opcode '%s'"), str
);
3195 skip_whitespace (p
);
3197 /* See if there is something that looks like a functional unit
3201 bool good_func_unit
;
3202 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
3203 unsigned int maybe_side
= 0;
3204 unsigned int maybe_cross
= 0;
3205 unsigned int maybe_data_side
= 0;
3207 good_func_unit
= tic6x_parse_func_unit_base (p
+ 1, &maybe_base
,
3212 if (p
[3] == ' ' || is_end_of_line
[(unsigned char) p
[3]])
3214 else if ((p
[3] == 'x' || p
[3] == 'X')
3215 && (p
[4] == ' ' || is_end_of_line
[(unsigned char) p
[4]]))
3220 else if (maybe_base
== tic6x_func_unit_d
3221 && (p
[3] == 't' || p
[3] == 'T')
3222 && (p
[4] == '1' || p
[4] == '2')
3223 && (p
[5] == ' ' || is_end_of_line
[(unsigned char) p
[5]]))
3225 maybe_data_side
= p
[4] - '0';
3229 good_func_unit
= false;
3234 func_unit_base
= maybe_base
;
3235 func_unit_side
= maybe_side
;
3236 func_unit_cross
= maybe_cross
;
3237 cross_side
= (func_unit_cross
? 3 - func_unit_side
: func_unit_side
);
3238 func_unit_data_side
= maybe_data_side
;
3241 skip_whitespace (p
);
3244 /* Determine which entries in the opcode table match, and the
3245 associated permitted forms of operands. */
3246 max_matching_opcodes
= 0;
3247 for (opc
= opc_list
; opc
; opc
= opc
->next
)
3248 max_matching_opcodes
++;
3249 num_matching_opcodes
= 0;
3250 opcm
= XNEWVEC (tic6x_opcode_id
, max_matching_opcodes
);
3251 max_num_operands
= 0;
3252 ok_this_arch
= false;
3254 ok_this_arch_fu
= false;
3255 for (opc
= opc_list
; opc
; opc
= opc
->next
)
3257 unsigned int num_operands
;
3259 bool this_opc_arch_ok
= true;
3260 bool this_opc_fu_ok
= true;
3262 if (tic6x_insn_format_table
[tic6x_opcode_table
[opc
->id
].format
].num_bits
3265 if (!(tic6x_opcode_table
[opc
->id
].isa_variants
& tic6x_features
))
3266 this_opc_arch_ok
= false;
3267 if (tic6x_opcode_table
[opc
->id
].func_unit
!= func_unit_base
)
3268 this_opc_fu_ok
= false;
3269 if (func_unit_side
== 1
3270 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_B_ONLY
))
3271 this_opc_fu_ok
= false;
3273 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_NO_CROSS
))
3274 this_opc_fu_ok
= false;
3275 if (!func_unit_data_side
3276 && (tic6x_opcode_table
[opc
->id
].flags
3277 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
3278 this_opc_fu_ok
= false;
3279 if (func_unit_data_side
3280 && !(tic6x_opcode_table
[opc
->id
].flags
3281 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
3282 this_opc_fu_ok
= false;
3283 if (func_unit_data_side
== 1
3284 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_T2_ONLY
))
3285 this_opc_fu_ok
= false;
3286 if (this_opc_arch_ok
)
3287 ok_this_arch
= true;
3290 if (!this_opc_arch_ok
|| !this_opc_fu_ok
)
3292 ok_this_arch_fu
= true;
3293 opcm
[num_matching_opcodes
] = opc
->id
;
3294 num_matching_opcodes
++;
3295 num_operands
= tic6x_opcode_table
[opc
->id
].num_operands
;
3297 if (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SPMASK
)
3299 if (num_operands
!= 1
3300 || (tic6x_opcode_table
[opc
->id
].operand_info
[0].form
3301 != tic6x_operand_func_unit
))
3304 for (i
= 0; i
< num_operands
; i
++)
3307 |= tic6x_coarse_operand_form (tic6x_operand_func_unit
);
3308 num_operands_permitted
[i
] = true;
3313 for (i
= 0; i
< num_operands
; i
++)
3315 tic6x_operand_form f
3316 = tic6x_opcode_table
[opc
->id
].operand_info
[i
].form
;
3318 operand_forms
[i
] |= tic6x_coarse_operand_form (f
);
3321 num_operands_permitted
[num_operands
] = true;
3322 if (num_operands
> max_num_operands
)
3323 max_num_operands
= num_operands
;
3328 as_bad (_("'%.*s' instruction not supported on this architecture"),
3336 as_bad (_("'%.*s' instruction not supported on this functional unit"),
3342 if (!ok_this_arch_fu
)
3344 as_bad (_("'%.*s' instruction not supported on this functional unit"
3345 " for this architecture"),
3351 /* If there were no instructions matching the above availability
3352 checks, we should now have given an error and returned. */
3353 if (num_matching_opcodes
== 0)
3356 num_operands_read
= 0;
3359 skip_whitespace (p
);
3360 if (is_end_of_line
[(unsigned char) *p
])
3362 if (num_operands_read
> 0)
3364 as_bad (_("missing operand after comma"));
3365 bad_operands
= true;
3370 if (max_num_operands
== 0)
3372 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
3373 bad_operands
= true;
3377 if (!tic6x_parse_operand (&p
, &operands
[num_operands_read
],
3378 operand_forms
[num_operands_read
], str
, opc_len
,
3379 num_operands_read
+ 1))
3380 bad_operands
= true;
3381 num_operands_read
++;
3383 if (is_end_of_line
[(unsigned char) *p
])
3388 if (num_operands_read
== max_num_operands
)
3390 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
3391 bad_operands
= true;
3397 /* Operand parsing should consume whole operands. */
3401 if (!bad_operands
&& !num_operands_permitted
[num_operands_read
])
3403 as_bad (_("bad number of operands to '%.*s'"), opc_len
, str
);
3404 bad_operands
= true;
3409 /* Each operand is of the right syntactic form for some opcode
3410 choice, and the number of operands is valid. Check that each
3411 operand is OK in detail for some opcode choice with the right
3412 number of operands. */
3415 for (i
= 0; i
< num_operands_read
; i
++)
3417 bool coarse_ok
= false;
3418 bool fine_ok
= false;
3419 tic6x_operand_match fine_failure
= tic6x_match_matches
;
3422 for (j
= 0; j
< num_matching_opcodes
; j
++)
3424 tic6x_operand_form f
;
3427 tic6x_operand_match this_fine_failure
;
3429 if (tic6x_opcode_table
[opcm
[j
]].flags
& TIC6X_FLAG_SPMASK
)
3431 f
= tic6x_operand_func_unit
;
3436 if (tic6x_opcode_table
[opcm
[j
]].num_operands
3437 != num_operands_read
)
3440 f
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].form
;
3441 rw
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].rw
;
3443 cf
= tic6x_coarse_operand_form (f
);
3445 if (operands
[i
].form
!= cf
)
3450 = tic6x_operand_matches_form (&operands
[i
], f
, rw
,
3453 func_unit_data_side
);
3454 if (this_fine_failure
== tic6x_match_matches
)
3459 if (fine_failure
== tic6x_match_matches
3460 || fine_failure
> this_fine_failure
)
3461 fine_failure
= this_fine_failure
;
3464 /* No instructions should have operand syntactic forms only
3465 acceptable with certain numbers of operands, so no
3466 diagnostic for this case. */
3472 switch (fine_failure
)
3474 case tic6x_match_non_const
:
3475 as_bad (_("operand %u of '%.*s' not constant"),
3476 i
+ 1, opc_len
, str
);
3479 case tic6x_match_wrong_side
:
3480 as_bad (_("operand %u of '%.*s' on wrong side"),
3481 i
+ 1, opc_len
, str
);
3484 case tic6x_match_bad_return
:
3485 as_bad (_("operand %u of '%.*s' not a valid return "
3486 "address register"),
3487 i
+ 1, opc_len
, str
);
3490 case tic6x_match_ctrl_write_only
:
3491 as_bad (_("operand %u of '%.*s' is write-only"),
3492 i
+ 1, opc_len
, str
);
3495 case tic6x_match_ctrl_read_only
:
3496 as_bad (_("operand %u of '%.*s' is read-only"),
3497 i
+ 1, opc_len
, str
);
3500 case tic6x_match_bad_mem
:
3501 as_bad (_("operand %u of '%.*s' not a valid memory "
3503 i
+ 1, opc_len
, str
);
3506 case tic6x_match_bad_address
:
3507 as_bad (_("operand %u of '%.*s' not a valid base "
3508 "address register"),
3509 i
+ 1, opc_len
, str
);
3515 bad_operands
= true;
3523 /* Each operand is OK for some opcode choice, and the number of
3524 operands is valid. Check whether there is an opcode choice
3525 for which all operands are simultaneously valid. */
3527 bool found_match
= false;
3529 for (i
= 0; i
< TIC6X_NUM_PREFER
; i
++)
3530 opc_rank
[i
] = (unsigned int) -1;
3532 min_rank
= TIC6X_NUM_PREFER
- 1;
3535 for (i
= 0; i
< num_matching_opcodes
; i
++)
3538 bool this_matches
= true;
3540 if (!(tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3541 && tic6x_opcode_table
[opcm
[i
]].num_operands
!= num_operands_read
)
3544 for (j
= 0; j
< num_operands_read
; j
++)
3546 tic6x_operand_form f
;
3549 if (tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3551 f
= tic6x_operand_func_unit
;
3556 f
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].form
;
3557 rw
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].rw
;
3559 if (tic6x_operand_matches_form (&operands
[j
], f
, rw
,
3562 func_unit_data_side
)
3563 != tic6x_match_matches
)
3565 this_matches
= false;
3572 int rank
= TIC6X_PREFER_VAL (tic6x_opcode_table
[opcm
[i
]].flags
);
3574 if (rank
< min_rank
)
3576 if (rank
> max_rank
)
3579 if (opc_rank
[rank
] == (unsigned int) -1)
3582 /* The opcode table should provide a total ordering
3583 for all cases where multiple matches may get
3593 as_bad (_("bad operand combination for '%.*s'"), opc_len
, str
);
3594 bad_operands
= true;
3606 for (try_rank
= max_rank
; try_rank
>= min_rank
; try_rank
--)
3610 if (opc_rank
[try_rank
] == (unsigned int) -1)
3613 opcode_value
= tic6x_try_encode (opcm
[opc_rank
[try_rank
]], operands
,
3614 num_operands_read
, this_line_creg
,
3615 this_line_z
, func_unit_side
,
3616 func_unit_cross
, func_unit_data_side
,
3617 seginfo
->tc_segment_info_data
.sploop_ii
,
3618 &fix_exp
, &fix_pcrel
, &fx_r_type
,
3619 &fix_adda
, &fix_needed
, &encoded_ok
,
3620 try_rank
== min_rank
,
3624 opct
= &tic6x_opcode_table
[opcm
[opc_rank
[try_rank
]]];
3634 if (this_line_parallel
)
3636 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
;
3637 if (insn_frag
== NULL
)
3639 as_bad (_("parallel instruction not following another instruction"));
3643 if (insn_frag
->fr_fix
>= 32)
3645 as_bad (_("too many instructions in execute packet"));
3649 if (this_insn_label_list
!= NULL
)
3650 as_bad (_("label not at start of execute packet"));
3652 if (opct
->flags
& TIC6X_FLAG_FIRST
)
3653 as_bad (_("'%.*s' instruction not at start of execute packet"),
3656 *seginfo
->tc_segment_info_data
.last_insn_lsb
|= 0x1;
3657 output
= insn_frag
->fr_literal
+ insn_frag
->fr_fix
;
3661 tic6x_label_list
*l
;
3663 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
3664 seginfo
->tc_segment_info_data
.func_units_used
= 0;
3666 /* Start a new frag for this execute packet. */
3667 if (frag_now_fix () != 0)
3669 if (frag_now
->fr_type
!= rs_machine_dependent
)
3670 frag_wane (frag_now
);
3675 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
= frag_now
;
3676 for (l
= this_insn_label_list
; l
; l
= l
->next
)
3678 symbol_set_frag (l
->label
, frag_now
);
3679 S_SET_VALUE (l
->label
, 0);
3680 S_SET_SEGMENT (l
->label
, now_seg
);
3682 tic6x_free_label_list (this_insn_label_list
);
3683 dwarf2_emit_insn (0);
3684 output
= frag_var (rs_machine_dependent
, 32, 32, 0, NULL
, 0, NULL
);
3685 /* This must be the same as the frag to which a pointer was just
3687 if (output
!= insn_frag
->fr_literal
)
3689 insn_frag
->tc_frag_data
.is_insns
= true;
3690 insn_frag
->tc_frag_data
.can_cross_fp_boundary
3691 = tic6x_can_cross_fp_boundary
;
3694 if (func_unit_base
!= tic6x_func_unit_nfu
)
3696 unsigned int func_unit_enc
;
3698 func_unit_enc
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3700 if (seginfo
->tc_segment_info_data
.func_units_used
& func_unit_enc
)
3701 as_bad (_("functional unit already used in this execute packet"));
3703 seginfo
->tc_segment_info_data
.func_units_used
|= func_unit_enc
;
3706 if (opct
->flags
& TIC6X_FLAG_SPLOOP
)
3708 if (seginfo
->tc_segment_info_data
.sploop_ii
)
3709 as_bad (_("nested software pipelined loop"));
3710 if (num_operands_read
!= 1
3711 || operands
[0].form
!= TIC6X_OP_EXP
3712 || operands
[0].value
.exp
.X_op
!= O_constant
)
3714 seginfo
->tc_segment_info_data
.sploop_ii
3715 = operands
[0].value
.exp
.X_add_number
;
3717 else if (opct
->flags
& TIC6X_FLAG_SPKERNEL
)
3719 if (!seginfo
->tc_segment_info_data
.sploop_ii
)
3720 as_bad (_("'%.*s' instruction not in a software pipelined loop"),
3722 seginfo
->tc_segment_info_data
.sploop_ii
= 0;
3725 if (this_line_spmask
)
3727 if (seginfo
->tc_segment_info_data
.spmask_addr
== NULL
)
3728 as_bad (_("'||^' without previous SPMASK"));
3729 else if (func_unit_base
== tic6x_func_unit_nfu
)
3730 as_bad (_("cannot mask instruction using no functional unit"));
3733 unsigned int spmask_opcode
;
3734 unsigned int mask_bit
;
3737 = md_chars_to_number (seginfo
->tc_segment_info_data
.spmask_addr
,
3739 mask_bit
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3741 if (spmask_opcode
& mask_bit
)
3742 as_bad (_("functional unit already masked"));
3743 spmask_opcode
|= mask_bit
;
3744 md_number_to_chars (seginfo
->tc_segment_info_data
.spmask_addr
,
3749 record_alignment (now_seg
, 5);
3750 md_number_to_chars (output
, opcode_value
, 4);
3752 tic6x_fix_new_exp (insn_frag
, output
- insn_frag
->fr_literal
, 4, fix_exp
,
3753 fix_pcrel
, fx_r_type
, fix_adda
);
3754 insn_frag
->fr_fix
+= 4;
3755 insn_frag
->fr_var
-= 4;
3756 seginfo
->tc_segment_info_data
.last_insn_lsb
3757 = (target_big_endian
? output
+ 3 : output
);
3758 if (opct
->flags
& TIC6X_FLAG_SPMASK
)
3759 seginfo
->tc_segment_info_data
.spmask_addr
= output
;
3762 /* Modify NEWVAL (32-bit) by inserting VALUE, shifted right by SHIFT
3763 and the least significant BITS bits taken, at position POS. */
3764 #define MODIFY_VALUE(NEWVAL, VALUE, SHIFT, POS, BITS) \
3766 (NEWVAL) &= 0xffffffffU & ~(((1U << (BITS)) - 1) << (POS)); \
3767 (NEWVAL) |= (((VALUE) >> (SHIFT)) & ((1U << (BITS)) - 1)) << (POS); \
3770 /* Apply a fixup to the object file. */
3773 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3775 valueT value
= *valP
;
3776 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3778 value
= SEXT (value
);
3781 fixP
->fx_offset
= SEXT (fixP
->fx_offset
);
3783 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3786 /* We do our own overflow checks. */
3787 fixP
->fx_no_overflow
= 1;
3789 switch (fixP
->fx_r_type
)
3791 case BFD_RELOC_NONE
:
3792 case BFD_RELOC_C6000_EHTYPE
:
3793 /* Force output to the object file. */
3798 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3799 md_number_to_chars (buf
, value
, 4);
3803 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3805 if (value
+ 0x8000 > 0xffff + 0x8000)
3806 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3807 _("value too large for 2-byte field"));
3808 md_number_to_chars (buf
, value
, 2);
3813 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3815 if (value
+ 0x80 > 0xff + 0x80)
3816 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3817 _("value too large for 1-byte field"));
3822 case BFD_RELOC_C6000_ABS_S16
:
3823 case BFD_RELOC_C6000_ABS_L16
:
3824 case BFD_RELOC_C6000_SBR_S16
:
3825 case BFD_RELOC_C6000_SBR_L16_B
:
3826 case BFD_RELOC_C6000_SBR_L16_H
:
3827 case BFD_RELOC_C6000_SBR_L16_W
:
3828 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3829 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3831 valueT newval
= md_chars_to_number (buf
, 4);
3834 switch (fixP
->fx_r_type
)
3836 case BFD_RELOC_C6000_SBR_L16_H
:
3840 case BFD_RELOC_C6000_SBR_L16_W
:
3841 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3850 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3851 if ((value
+ 0x8000 > 0x7fff + 0x8000)
3852 && (fixP
->fx_r_type
== BFD_RELOC_C6000_ABS_S16
3853 || fixP
->fx_r_type
== BFD_RELOC_C6000_SBR_S16
))
3854 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3855 _("immediate offset out of range"));
3857 md_number_to_chars (buf
, newval
, 4);
3860 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_S16
3861 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_L16
)
3865 case BFD_RELOC_C6000_ABS_H16
:
3866 case BFD_RELOC_C6000_SBR_H16_B
:
3867 case BFD_RELOC_C6000_SBR_H16_H
:
3868 case BFD_RELOC_C6000_SBR_H16_W
:
3869 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3870 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3872 valueT newval
= md_chars_to_number (buf
, 4);
3875 switch (fixP
->fx_r_type
)
3877 case BFD_RELOC_C6000_SBR_H16_H
:
3881 case BFD_RELOC_C6000_SBR_H16_W
:
3882 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3891 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3893 md_number_to_chars (buf
, newval
, 4);
3895 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_H16
)
3899 case BFD_RELOC_C6000_PCR_H16
:
3900 case BFD_RELOC_C6000_PCR_L16
:
3901 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3903 valueT newval
= md_chars_to_number (buf
, 4);
3904 int shift
= fixP
->fx_r_type
== BFD_RELOC_C6000_PCR_H16
? 16 : 0;
3906 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3908 md_number_to_chars (buf
, newval
, 4);
3912 case BFD_RELOC_C6000_SBR_U15_B
:
3913 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3915 valueT newval
= md_chars_to_number (buf
, 4);
3917 MODIFY_VALUE (newval
, value
, 0, 8, 15);
3919 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3920 _("immediate offset out of range"));
3922 md_number_to_chars (buf
, newval
, 4);
3926 case BFD_RELOC_C6000_SBR_U15_H
:
3927 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3929 valueT newval
= md_chars_to_number (buf
, 4);
3931 /* Constant ADDA operands, processed as constant when the
3932 instruction is parsed, are encoded as-is rather than
3933 shifted. If the operand of an ADDA instruction is now
3934 constant (for example, the difference between two labels
3935 found after the instruction), ensure it is encoded the
3936 same way it would have been if the constant value had
3937 been known when the instruction was parsed. */
3938 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3941 MODIFY_VALUE (newval
, value
, 1, 8, 15);
3943 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3944 _("immediate offset not 2-byte-aligned"));
3946 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3947 _("immediate offset out of range"));
3949 md_number_to_chars (buf
, newval
, 4);
3953 case BFD_RELOC_C6000_SBR_U15_W
:
3954 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
3955 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3957 valueT newval
= md_chars_to_number (buf
, 4);
3959 /* Constant ADDA operands, processed as constant when the
3960 instruction is parsed, are encoded as-is rather than
3961 shifted. If the operand of an ADDA instruction is now
3962 constant (for example, the difference between two labels
3963 found after the instruction), ensure it is encoded the
3964 same way it would have been if the constant value had
3965 been known when the instruction was parsed. */
3966 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3969 MODIFY_VALUE (newval
, value
, 2, 8, 15);
3971 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3972 _("immediate offset not 4-byte-aligned"));
3973 if (value
> 0x1fffc)
3974 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3975 _("immediate offset out of range"));
3977 md_number_to_chars (buf
, newval
, 4);
3979 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_SBR_U15_W
)
3983 case BFD_RELOC_C6000_DSBT_INDEX
:
3985 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3986 _("addend used with $DSBT_INDEX"));
3991 case BFD_RELOC_C6000_PCR_S21
:
3992 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3994 valueT newval
= md_chars_to_number (buf
, 4);
3996 MODIFY_VALUE (newval
, value
, 2, 7, 21);
3999 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4000 _("PC-relative offset not 4-byte-aligned"));
4001 if (value
+ 0x400000 > 0x3ffffc + 0x400000)
4002 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4003 _("PC-relative offset out of range"));
4005 md_number_to_chars (buf
, newval
, 4);
4009 case BFD_RELOC_C6000_PCR_S12
:
4010 if (fixP
->fx_done
|| !seg
->use_rela_p
)
4012 valueT newval
= md_chars_to_number (buf
, 4);
4014 MODIFY_VALUE (newval
, value
, 2, 16, 12);
4017 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4018 _("PC-relative offset not 4-byte-aligned"));
4019 if (value
+ 0x2000 > 0x1ffc + 0x2000)
4020 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4021 _("PC-relative offset out of range"));
4023 md_number_to_chars (buf
, newval
, 4);
4027 case BFD_RELOC_C6000_PCR_S10
:
4028 if (fixP
->fx_done
|| !seg
->use_rela_p
)
4030 valueT newval
= md_chars_to_number (buf
, 4);
4032 MODIFY_VALUE (newval
, value
, 2, 13, 10);
4035 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4036 _("PC-relative offset not 4-byte-aligned"));
4037 if (value
+ 0x800 > 0x7fc + 0x800)
4038 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4039 _("PC-relative offset out of range"));
4041 md_number_to_chars (buf
, newval
, 4);
4045 case BFD_RELOC_C6000_PCR_S7
:
4046 if (fixP
->fx_done
|| !seg
->use_rela_p
)
4048 valueT newval
= md_chars_to_number (buf
, 4);
4050 MODIFY_VALUE (newval
, value
, 2, 16, 7);
4053 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4054 _("PC-relative offset not 4-byte-aligned"));
4055 if (value
+ 0x100 > 0xfc + 0x100)
4056 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4057 _("PC-relative offset out of range"));
4059 md_number_to_chars (buf
, newval
, 4);
4063 case BFD_RELOC_C6000_PREL31
:
4064 /* Force output to the object file. */
4073 /* Convert a floating-point number to target (IEEE) format. */
4076 md_atof (int type
, char *litP
, int *sizeP
)
4078 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
4081 /* Adjust the frags in SECTION (see tic6x_md_finish). */
4084 tic6x_adjust_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT section
,
4085 void *dummy ATTRIBUTE_UNUSED
)
4087 segment_info_type
*info
;
4090 bool have_code
= false;
4091 bool have_non_code
= false;
4093 info
= seg_info (section
);
4097 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4098 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4099 switch (fragp
->fr_type
)
4101 case rs_machine_dependent
:
4102 if (fragp
->tc_frag_data
.is_insns
)
4108 if (fragp
->fr_fix
> 0)
4109 have_non_code
= true;
4113 have_non_code
= true;
4117 /* Process alignment requirements in a code-only section. */
4118 if (have_code
&& !have_non_code
)
4120 /* If we need to insert an odd number of instructions to meet an
4121 alignment requirement, there must have been an odd number of
4122 instructions since the last 8-byte-aligned execute packet
4123 boundary. So there must have been an execute packet with an
4124 odd number (and so a number fewer than 8) of instructions
4125 into which we can insert a NOP without breaking any previous
4128 If then we need to insert a number 2 mod 4 of instructions,
4129 the number of instructions since the last 16-byte-aligned
4130 execute packet boundary must be 2 mod 4. So between that
4131 boundary and the following 8-byte-aligned boundary there must
4132 either be at least one execute packet with 2-mod-4
4133 instructions, or at least two with an odd number of
4134 instructions; again, greedily inserting NOPs as soon as
4135 possible suffices to meet the alignment requirement.
4137 If then we need to insert 4 instructions, we look between the
4138 last 32-byte-aligned boundary and the following
4139 16-byte-aligned boundary. The sizes of the execute packets
4140 in this range total 4 instructions mod 8, so again there is
4141 room for greedy insertion of NOPs to meet the alignment
4142 requirement, and before any intermediate point with 8-byte
4143 (2-instruction) alignment requirement the sizes of execute
4144 packets (and so the room for NOPs) will total 2 instructions
4145 mod 4 so greedy insertion will not break such alignments.
4147 So we can always meet these alignment requirements by
4148 inserting NOPs in parallel with existing execute packets, and
4149 by induction the approach described above inserts the minimum
4150 number of such NOPs. */
4152 /* The number of NOPs we are currently looking to insert, if we
4153 have gone back to insert NOPs. */
4154 unsigned int want_insert
= 0;
4156 /* Out of that number, the number inserted so far in the current
4157 stage of the above algorithm. */
4158 unsigned int want_insert_done_so_far
= 0;
4160 /* The position mod 32 at the start of the current frag. */
4161 unsigned int pos
= 0;
4163 /* The locations in the frag chain of the most recent frags at
4164 the start of which there is the given alignment. */
4165 frchainS
*frchp_last32
, *frchp_last16
, *frchp_last8
;
4166 fragS
*fragp_last32
, *fragp_last16
, *fragp_last8
;
4167 unsigned int pos_last32
, pos_last16
, pos_last8
;
4169 frchp_last32
= frchp_last16
= frchp_last8
= info
->frchainP
;
4170 fragp_last32
= fragp_last16
= fragp_last8
= info
->frchainP
->frch_root
;
4171 pos_last32
= pos_last16
= pos_last8
= 0;
4173 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4174 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4177 bool go_back
= false;
4178 frchainS
*frchp_next
;
4181 if (fragp
->fr_type
!= rs_machine_dependent
)
4184 if (fragp
->tc_frag_data
.is_insns
4185 && pos
+ fragp
->fr_fix
> 32
4186 && !fragp
->tc_frag_data
.can_cross_fp_boundary
)
4188 /* As described above, we should always have met an
4189 alignment requirement by the time we come back to
4196 want_insert
= (32 - pos
) >> 2;
4197 if (want_insert
> 7)
4199 want_insert_done_so_far
= 0;
4203 if (!fragp
->tc_frag_data
.is_insns
)
4205 unsigned int would_insert_bytes
;
4207 if (!(pos
& ((1 << fragp
->fr_offset
) - 1)))
4208 /* This alignment requirement is already met. */
4211 /* As described above, we should always have met an
4212 alignment requirement by the time we come back to
4217 /* We may not be able to meet this requirement within
4218 the given number of characters. */
4220 = ((1 << fragp
->fr_offset
)
4221 - (pos
& ((1 << fragp
->fr_offset
) - 1)));
4223 if (fragp
->fr_subtype
!= 0
4224 && would_insert_bytes
> fragp
->fr_subtype
)
4227 /* An unmet alignment must be 8, 16 or 32 bytes;
4228 smaller ones must always be met within code-only
4229 sections and larger ones cause the section not to
4231 if (fragp
->fr_offset
!= 3
4232 && fragp
->fr_offset
!= 4
4233 && fragp
->fr_offset
!= 5)
4236 if (would_insert_bytes
& 3)
4238 want_insert
= would_insert_bytes
>> 2;
4239 if (want_insert
> 7)
4241 want_insert_done_so_far
= 0;
4244 else if (want_insert
&& !go_back
)
4246 unsigned int num_insns
= fragp
->fr_fix
>> 2;
4247 unsigned int max_poss_nops
= 8 - num_insns
;
4251 unsigned int cur_want_nops
, max_want_nops
, do_nops
, i
;
4253 if (want_insert
& 1)
4255 else if (want_insert
& 2)
4257 else if (want_insert
& 4)
4262 max_want_nops
= cur_want_nops
- want_insert_done_so_far
;
4264 do_nops
= (max_poss_nops
< max_want_nops
4267 for (i
= 0; i
< do_nops
; i
++)
4269 md_number_to_chars (fragp
->fr_literal
+ fragp
->fr_fix
,
4271 if (target_big_endian
)
4272 fragp
->fr_literal
[fragp
->fr_fix
- 1] |= 0x1;
4274 fragp
->fr_literal
[fragp
->fr_fix
- 4] |= 0x1;
4278 want_insert_done_so_far
+= do_nops
;
4279 if (want_insert_done_so_far
== cur_want_nops
)
4281 want_insert
-= want_insert_done_so_far
;
4282 want_insert_done_so_far
= 0;
4290 if (want_insert
& 1)
4292 frchp
= frchp_last8
;
4293 fragp
= fragp_last8
;
4296 else if (want_insert
& 2)
4298 frchp
= frchp_last8
= frchp_last16
;
4299 fragp
= fragp_last8
= fragp_last16
;
4300 pos
= pos_last8
= pos_last16
;
4302 else if (want_insert
& 4)
4304 frchp
= frchp_last8
= frchp_last16
= frchp_last32
;
4305 fragp
= fragp_last8
= fragp_last16
= fragp_last32
;
4306 pos
= pos_last8
= pos_last16
= pos_last32
;
4314 /* Update current position for moving past a code
4316 pos
+= fragp
->fr_fix
;
4319 fragp_next
= fragp
->fr_next
;
4320 if (fragp_next
== NULL
)
4322 frchp_next
= frchp
->frch_next
;
4323 if (frchp_next
!= NULL
)
4324 fragp_next
= frchp_next
->frch_root
;
4328 frchp_last8
= frchp_next
;
4329 fragp_last8
= fragp_next
;
4334 frchp_last16
= frchp_next
;
4335 fragp_last16
= fragp_next
;
4340 frchp_last32
= frchp_next
;
4341 fragp_last32
= fragp_next
;
4347 /* Now convert the machine-dependent frags to machine-independent
4349 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4350 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4352 if (fragp
->fr_type
== rs_machine_dependent
)
4354 if (fragp
->tc_frag_data
.is_insns
)
4358 fragp
->fr_type
= rs_align_code
;
4360 *fragp
->fr_literal
= 0;
4366 /* Initialize the machine-dependent parts of a frag. */
4369 tic6x_frag_init (fragS
*fragp
)
4371 fragp
->tc_frag_data
.is_insns
= false;
4372 fragp
->tc_frag_data
.can_cross_fp_boundary
= false;
4375 /* Set an attribute if it has not already been set by the user. */
4378 tic6x_set_attribute_int (int tag
, int value
)
4381 || tag
>= NUM_KNOWN_OBJ_ATTRIBUTES
)
4383 if (!tic6x_attributes_set_explicitly
[tag
])
4384 if (!bfd_elf_add_proc_attr_int (stdoutput
, tag
, value
))
4385 as_fatal (_("error adding attribute: %s"),
4386 bfd_errmsg (bfd_get_error ()));
4389 /* Set object attributes deduced from the input file and command line
4390 rather than given explicitly. */
4392 tic6x_set_attributes (void)
4394 if (tic6x_arch_attribute
== C6XABI_Tag_ISA_none
)
4395 tic6x_arch_attribute
= C6XABI_Tag_ISA_C674X
;
4397 tic6x_set_attribute_int (Tag_ISA
, tic6x_arch_attribute
);
4398 tic6x_set_attribute_int (Tag_ABI_DSBT
, tic6x_dsbt
);
4399 tic6x_set_attribute_int (Tag_ABI_PID
, tic6x_pid
);
4400 tic6x_set_attribute_int (Tag_ABI_PIC
, tic6x_pic
);
4403 /* Do machine-dependent manipulations of the frag chains after all
4404 input has been read and before the machine-independent sizing and
4408 tic6x_md_finish (void)
4410 /* Set object attributes at this point if not explicitly set. */
4411 tic6x_set_attributes ();
4413 /* Meeting alignment requirements may require inserting NOPs in
4414 parallel in execute packets earlier in the segment. Future
4415 16-bit instruction generation involves whole-segment optimization
4416 to determine the best choice and ordering of 32-bit or 16-bit
4417 instructions. This doesn't fit will in the general relaxation
4418 framework, so handle alignment and 16-bit instruction generation
4420 bfd_map_over_sections (stdoutput
, tic6x_adjust_section
, NULL
);
4423 /* No machine-dependent frags at this stage; all converted in
4427 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec ATTRIBUTE_UNUSED
,
4428 fragS
*fragp ATTRIBUTE_UNUSED
)
4433 /* No machine-dependent frags at this stage; all converted in
4437 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
4438 segT seg ATTRIBUTE_UNUSED
)
4443 /* Put a number into target byte order. */
4446 md_number_to_chars (char *buf
, valueT val
, int n
)
4448 if (target_big_endian
)
4449 number_to_chars_bigendian (buf
, val
, n
);
4451 number_to_chars_littleendian (buf
, val
, n
);
4454 /* Machine-dependent operand parsing not currently needed. */
4457 md_operand (expressionS
*op ATTRIBUTE_UNUSED
)
4461 /* PC-relative operands are relative to the start of the fetch
4465 tic6x_pcrel_from_section (fixS
*fixp
, segT sec
)
4467 if (fixp
->fx_addsy
!= NULL
4468 && (!S_IS_DEFINED (fixp
->fx_addsy
)
4469 || S_GET_SEGMENT (fixp
->fx_addsy
) != sec
))
4471 return (fixp
->fx_where
+ fixp
->fx_frag
->fr_address
) & ~(long) 0x1f;
4474 /* Round up a section size to the appropriate boundary. */
4477 md_section_align (segT segment ATTRIBUTE_UNUSED
,
4480 /* Round up section sizes to ensure that text sections consist of
4481 whole fetch packets. */
4482 int align
= bfd_section_alignment (segment
);
4483 return ((size
+ (1 << align
) - 1) & (-((valueT
) 1 << align
)));
4486 /* No special undefined symbol handling needed for now. */
4489 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
4494 /* Translate internal representation of relocation info to BFD target
4498 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
4502 bfd_reloc_code_real_type r_type
;
4504 reloc
= XNEW (arelent
);
4505 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
4506 symbol
= symbol_get_bfdsym (fixp
->fx_addsy
);
4507 *reloc
->sym_ptr_ptr
= symbol
;
4508 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4509 reloc
->addend
= (tic6x_generate_rela
? fixp
->fx_offset
: 0);
4510 r_type
= fixp
->fx_r_type
;
4511 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
4513 if (reloc
->howto
== NULL
)
4515 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4516 _("Cannot represent relocation type %s"),
4517 bfd_get_reloc_code_name (r_type
));
4521 /* Correct for adjustments bfd_install_relocation will make. */
4522 if (reloc
->howto
->pcrel_offset
&& reloc
->howto
->partial_inplace
)
4524 reloc
->addend
+= reloc
->address
;
4525 if (!bfd_is_com_section (bfd_asymbol_section (symbol
)))
4526 reloc
->addend
-= symbol
->value
;
4528 if (r_type
== BFD_RELOC_C6000_PCR_H16
4529 || r_type
== BFD_RELOC_C6000_PCR_L16
)
4531 symbolS
*t
= fixp
->tc_fix_data
.fix_subsy
;
4532 segT sub_symbol_segment
;
4534 resolve_symbol_value (t
);
4535 sub_symbol_segment
= S_GET_SEGMENT (t
);
4536 if (sub_symbol_segment
== undefined_section
)
4537 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4538 _("undefined symbol %s in PCR relocation"),
4542 reloc
->addend
= reloc
->address
& ~0x1F;
4543 reloc
->addend
-= S_GET_VALUE (t
);
4549 /* Convert REGNAME to a DWARF-2 register number. */
4552 tic6x_regname_to_dw2regnum (char *regname
)
4558 reg_ok
= tic6x_parse_register (&rq
, ®
);
4565 case 1: /* A regs. */
4568 else if (reg
.num
< 32)
4569 return (reg
.num
- 16) + 37;
4573 case 2: /* B regs. */
4575 return reg
.num
+ 16;
4576 else if (reg
.num
< 32)
4577 return (reg
.num
- 16) + 53;
4586 /* Initialize the DWARF-2 unwind information for this procedure. */
4589 tic6x_frame_initial_instructions (void)
4591 /* CFA is initial stack pointer (B15). */
4592 cfi_add_CFA_def_cfa (31, 0);
4595 /* Start an exception table entry. If idx is nonzero this is an index table
4599 tic6x_start_unwind_section (const segT text_seg
, int idx
)
4601 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4602 const char * text_name
;
4603 const char * prefix
;
4604 const char * prefix_once
;
4605 struct elf_section_match match
;
4609 size_t sec_name_len
;
4616 prefix
= ELF_STRING_C6000_unwind
;
4617 prefix_once
= ELF_STRING_C6000_unwind_once
;
4618 type
= SHT_C6000_UNWIND
;
4622 prefix
= ELF_STRING_C6000_unwind_info
;
4623 prefix_once
= ELF_STRING_C6000_unwind_info_once
;
4624 type
= SHT_PROGBITS
;
4627 text_name
= segment_name (text_seg
);
4628 if (streq (text_name
, ".text"))
4631 if (startswith (text_name
, ".gnu.linkonce.t."))
4633 prefix
= prefix_once
;
4634 text_name
+= strlen (".gnu.linkonce.t.");
4637 prefix_len
= strlen (prefix
);
4638 text_len
= strlen (text_name
);
4639 sec_name_len
= prefix_len
+ text_len
;
4640 sec_name
= XNEWVEC (char, sec_name_len
+ 1);
4641 memcpy (sec_name
, prefix
, prefix_len
);
4642 memcpy (sec_name
+ prefix_len
, text_name
, text_len
);
4643 sec_name
[prefix_len
+ text_len
] = '\0';
4647 memset (&match
, 0, sizeof (match
));
4649 /* Handle COMDAT group. */
4650 if (prefix
!= prefix_once
&& (text_seg
->flags
& SEC_LINK_ONCE
) != 0)
4652 match
.group_name
= elf_group_name (text_seg
);
4653 if (match
.group_name
== NULL
)
4655 as_bad (_("group section `%s' has no group signature"),
4656 segment_name (text_seg
));
4657 ignore_rest_of_line ();
4664 obj_elf_change_section (sec_name
, type
, flags
, 0, &match
,
4667 /* Set the section link for index tables. */
4669 elf_linked_to_section (now_seg
) = text_seg
;
4671 seg_info (now_seg
)->tc_segment_info_data
.text_unwind
= unwind
;
4676 tic6x_unwind_frame_regs
[TIC6X_NUM_UNWIND_REGS
] =
4677 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4678 { 15, 31, 30, 29, 28, 27, 26, 19, 14, 13, 12, 11, 10 };
4680 /* Register save offsets for __c6xabi_push_rts. */
4682 tic6x_pop_rts_offset_little
[TIC6X_NUM_UNWIND_REGS
] =
4683 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4684 { -1, 1, 0, -3, -4, -7, -8,-11, -2, -5, -6, -9,-10};
4687 tic6x_pop_rts_offset_big
[TIC6X_NUM_UNWIND_REGS
] =
4688 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4689 { -2, 1, 0, -4, -3, -8, -7,-12, -1, -6, -5,-10, -9};
4691 /* Map from dwarf register number to unwind frame register number. */
4693 tic6x_unwind_reg_from_dwarf (int dwarf
)
4697 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
4699 if (tic6x_unwind_frame_regs
[reg
] == dwarf
)
4706 /* Unwinding bytecode definitions. */
4707 #define UNWIND_OP_ADD_SP 0x00
4708 #define UNWIND_OP_ADD_SP2 0xd2
4709 #define UNWIND_OP2_POP 0x8000
4710 #define UNWIND_OP2_POP_COMPACT 0xa000
4711 #define UNWIND_OP_POP_REG 0xc0
4712 #define UNWIND_OP_MV_FP 0xd0
4713 #define UNWIND_OP_POP_RTS 0xd1
4714 #define UNWIND_OP_RET 0xe0
4716 /* Maximum stack adjustment for __c6xabi_unwind_cpp_pr3/4 */
4717 #define MAX_COMPACT_SP_OFFSET (0x7f << 3)
4720 tic6x_flush_unwind_word (valueT data
)
4722 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4725 /* Create EXTAB entry if it does not exist. */
4726 if (unwind
->table_entry
== NULL
)
4728 tic6x_start_unwind_section (unwind
->saved_seg
, 0);
4729 frag_align (2, 0, 0);
4730 record_alignment (now_seg
, 2);
4731 unwind
->table_entry
= expr_build_dot ();
4732 ptr
= frag_more (4);
4733 unwind
->frag_start
= ptr
;
4737 /* Append additional word of data. */
4738 ptr
= frag_more (4);
4741 md_number_to_chars (ptr
, data
, 4);
4744 /* Add a single byte of unwinding data. */
4747 tic6x_unwind_byte (int byte
)
4749 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4751 unwind
->data_bytes
++;
4752 /* Only flush the first word after we know multiple words are required. */
4753 if (unwind
->data_bytes
== 5)
4755 if (unwind
->personality_index
== -1)
4757 /* At this point we know we are too big for pr0. */
4758 unwind
->personality_index
= 1;
4759 tic6x_flush_unwind_word (0x81000000 | ((unwind
->data
>> 8) & 0xffff));
4760 unwind
->data
= ((unwind
->data
& 0xff) << 8) | byte
;
4761 unwind
->data_bytes
++;
4765 tic6x_flush_unwind_word (unwind
->data
);
4766 unwind
->data
= byte
;
4771 unwind
->data
= (unwind
->data
<< 8) | byte
;
4772 if ((unwind
->data_bytes
& 3) == 0 && unwind
->data_bytes
> 4)
4774 tic6x_flush_unwind_word (unwind
->data
);
4780 /* Add a two-byte unwinding opcode. */
4782 tic6x_unwind_2byte (int bytes
)
4784 tic6x_unwind_byte (bytes
>> 8);
4785 tic6x_unwind_byte (bytes
& 0xff);
4789 tic6x_unwind_uleb (offsetT offset
)
4791 while (offset
> 0x7f)
4793 tic6x_unwind_byte ((offset
& 0x7f) | 0x80);
4796 tic6x_unwind_byte (offset
);
4800 tic6x_cfi_startproc (void)
4802 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4804 unwind
->personality_index
= -1;
4805 unwind
->personality_routine
= NULL
;
4806 if (unwind
->table_entry
)
4807 as_bad (_("missing .endp before .cfi_startproc"));
4809 unwind
->table_entry
= NULL
;
4810 unwind
->data_bytes
= -1;
4814 tic6x_output_exidx_entry (void)
4818 unsigned int marked_pr_dependency
;
4821 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4824 old_subseg
= now_subseg
;
4826 /* Add index table entry. This is two words. */
4827 tic6x_start_unwind_section (unwind
->saved_seg
, 1);
4828 frag_align (2, 0, 0);
4829 record_alignment (now_seg
, 2);
4831 ptr
= frag_more (8);
4833 where
= frag_now_fix () - 8;
4835 /* Self relative offset of the function start. */
4836 fix_new (frag_now
, where
, 4, unwind
->function_start
, 0, 1,
4837 BFD_RELOC_C6000_PREL31
);
4839 /* Indicate dependency on ABI-defined personality routines to the
4840 linker, if it hasn't been done already. */
4841 marked_pr_dependency
4842 = seg_info (now_seg
)->tc_segment_info_data
.marked_pr_dependency
;
4843 if (unwind
->personality_index
>= 0 && unwind
->personality_index
< 5
4844 && !(marked_pr_dependency
& (1 << unwind
->personality_index
)))
4846 static const char *const name
[] =
4848 "__c6xabi_unwind_cpp_pr0",
4849 "__c6xabi_unwind_cpp_pr1",
4850 "__c6xabi_unwind_cpp_pr2",
4851 "__c6xabi_unwind_cpp_pr3",
4852 "__c6xabi_unwind_cpp_pr4"
4854 symbolS
*pr
= symbol_find_or_make (name
[unwind
->personality_index
]);
4855 fix_new (frag_now
, where
, 0, pr
, 0, 1, BFD_RELOC_NONE
);
4856 seg_info (now_seg
)->tc_segment_info_data
.marked_pr_dependency
4857 |= 1 << unwind
->personality_index
;
4860 if (unwind
->table_entry
)
4862 /* Self relative offset of the table entry. */
4863 fix_new (frag_now
, where
+ 4, 4, unwind
->table_entry
, 0, 1,
4864 BFD_RELOC_C6000_PREL31
);
4868 /* Inline exception table entry. */
4869 md_number_to_chars (ptr
+ 4, unwind
->data
, 4);
4872 /* Restore the original section. */
4873 subseg_set (old_seg
, old_subseg
);
4877 tic6x_output_unwinding (bool need_extab
)
4879 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4880 unsigned safe_mask
= unwind
->safe_mask
;
4881 unsigned compact_mask
= unwind
->compact_mask
;
4882 unsigned reg_saved_mask
= unwind
->reg_saved_mask
;
4883 offsetT cfa_offset
= unwind
->cfa_offset
;
4887 if (unwind
->personality_index
== -2)
4889 /* Function can not be unwound. */
4891 tic6x_output_exidx_entry ();
4895 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
4897 /* Auto-select a personality routine if none specified. */
4898 if (reg_saved_mask
|| cfa_offset
>= MAX_COMPACT_SP_OFFSET
)
4899 unwind
->personality_index
= -1;
4901 unwind
->personality_index
= 3;
4903 unwind
->personality_index
= 4;
4906 /* Calculate unwinding opcodes, and emit to EXTAB if necessary. */
4907 unwind
->table_entry
= NULL
;
4908 if (unwind
->personality_index
== 3 || unwind
->personality_index
== 4)
4910 if (cfa_offset
>= MAX_COMPACT_SP_OFFSET
)
4912 as_bad (_("stack pointer offset too large for personality routine"));
4916 || (unwind
->personality_index
== 3 && compact_mask
!= 0)
4917 || (unwind
->personality_index
== 4 && safe_mask
!= 0))
4919 as_bad (_("stack frame layout does not match personality routine"));
4923 unwind
->data
= (1u << 31) | (unwind
->personality_index
<< 24);
4924 if (unwind
->cfa_reg
== 15)
4925 unwind
->data
|= 0x7f << 17;
4927 unwind
->data
|= cfa_offset
<< (17 - 3);
4929 if (unwind
->personality_index
== 3)
4930 unwind
->data
|= safe_mask
<< 4;
4932 unwind
->data
|= compact_mask
<< 4;
4933 unwind
->data
|= unwind
->return_reg
;
4934 unwind
->data_bytes
= 4;
4938 if (unwind
->personality_routine
)
4941 unwind
->data_bytes
= 5;
4942 tic6x_flush_unwind_word (0);
4943 /* First word is personality routine. */
4944 where
= frag_now_fix () - 4;
4945 fix_new (frag_now
, where
, 4, unwind
->personality_routine
, 0, 1,
4946 BFD_RELOC_C6000_PREL31
);
4948 else if (unwind
->personality_index
> 0)
4950 unwind
->data
= 0x8000 | (unwind
->personality_index
<< 8);
4951 unwind
->data_bytes
= 2;
4953 else /* pr0 or undecided */
4955 unwind
->data
= 0x80;
4956 unwind
->data_bytes
= 1;
4959 if (unwind
->return_reg
!= UNWIND_B3
)
4961 tic6x_unwind_byte (UNWIND_OP_RET
| unwind
->return_reg
);
4964 if (unwind
->cfa_reg
== 15)
4966 tic6x_unwind_byte (UNWIND_OP_MV_FP
);
4968 else if (cfa_offset
!= 0)
4971 if (cfa_offset
> 0x80)
4973 tic6x_unwind_byte (UNWIND_OP_ADD_SP2
);
4974 tic6x_unwind_uleb (cfa_offset
- 0x81);
4976 else if (cfa_offset
> 0x40)
4978 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| 0x3f);
4979 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| (cfa_offset
- 0x40));
4983 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| (cfa_offset
- 1));
4988 tic6x_unwind_2byte (UNWIND_OP2_POP
| unwind
->safe_mask
);
4989 else if (unwind
->pop_rts
)
4990 tic6x_unwind_byte (UNWIND_OP_POP_RTS
);
4991 else if (compact_mask
)
4992 tic6x_unwind_2byte (UNWIND_OP2_POP_COMPACT
| unwind
->compact_mask
);
4993 else if (reg_saved_mask
)
4999 tic6x_unwind_byte (UNWIND_OP_POP_REG
| unwind
->saved_reg_count
);
5001 for (cur_offset
= 0; unwind
->saved_reg_count
> 0; cur_offset
-= 4)
5004 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5006 if (!unwind
->reg_saved
[reg
])
5009 if (unwind
->reg_offset
[reg
] == cur_offset
)
5011 unwind
->saved_reg_count
--;
5016 if ((cur_offset
& 4) == 4)
5017 tic6x_unwind_byte ((last_val
<< 4) | val
);
5021 if ((cur_offset
& 4) == 4)
5022 tic6x_unwind_byte ((last_val
<< 4) | 0xf);
5025 /* Pad with RETURN opcodes. */
5026 while ((unwind
->data_bytes
& 3) != 0)
5027 tic6x_unwind_byte (UNWIND_OP_RET
| UNWIND_B3
);
5029 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
5030 unwind
->personality_index
= 0;
5033 /* Force creation of an EXTAB entry if an LSDA is required. */
5034 if (need_extab
&& !unwind
->table_entry
)
5036 if (unwind
->data_bytes
!= 4)
5039 tic6x_flush_unwind_word (unwind
->data
);
5041 else if (unwind
->table_entry
&& !need_extab
)
5043 /* Add an empty descriptor if there is no user-specified data. */
5044 char *ptr
= frag_more (4);
5045 md_number_to_chars (ptr
, 0, 4);
5048 /* Fill in length of unwinding bytecode. */
5049 if (unwind
->table_entry
)
5052 if (unwind
->data_bytes
> 0x400)
5053 as_bad (_("too many unwinding instructions"));
5055 if (unwind
->personality_index
== -1)
5057 tmp
= md_chars_to_number (unwind
->frag_start
+ 4, 4);
5058 tmp
|= (valueT
) ((unwind
->data_bytes
- 8) >> 2) << 24;
5059 md_number_to_chars (unwind
->frag_start
+ 4, tmp
, 4);
5061 else if (unwind
->personality_index
== 1 || unwind
->personality_index
== 2)
5063 tmp
= md_chars_to_number (unwind
->frag_start
, 4);
5064 tmp
|= ((unwind
->data_bytes
- 4) >> 2) << 16;
5065 md_number_to_chars (unwind
->frag_start
, tmp
, 4);
5068 tic6x_output_exidx_entry ();
5071 /* FIXME: This will get horribly confused if cfi directives are emitted for
5072 function epilogue. */
5074 tic6x_cfi_endproc (struct fde_entry
*fde
)
5076 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
5077 struct cfi_insn_data
*insn
;
5079 unsigned safe_mask
= 0;
5080 unsigned compact_mask
= 0;
5081 unsigned reg_saved_mask
= 0;
5082 offsetT cfa_offset
= 0;
5083 offsetT save_offset
= 0;
5085 unwind
->cfa_reg
= 31;
5086 unwind
->return_reg
= UNWIND_B3
;
5087 unwind
->saved_reg_count
= 0;
5088 unwind
->pop_rts
= false;
5090 unwind
->saved_seg
= now_seg
;
5091 unwind
->saved_subseg
= now_subseg
;
5093 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5094 unwind
->reg_saved
[reg
] = false;
5096 /* Scan FDE instructions to build up stack frame layout. */
5097 for (insn
= fde
->data
; insn
; insn
= insn
->next
)
5101 case DW_CFA_advance_loc
:
5104 case DW_CFA_def_cfa
:
5105 unwind
->cfa_reg
= insn
->u
.ri
.reg
;
5106 cfa_offset
= insn
->u
.ri
.offset
;
5109 case DW_CFA_def_cfa_register
:
5110 unwind
->cfa_reg
= insn
->u
.r
;
5113 case DW_CFA_def_cfa_offset
:
5114 cfa_offset
= insn
->u
.i
;
5117 case DW_CFA_undefined
:
5118 case DW_CFA_same_value
:
5119 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.r
);
5121 unwind
->reg_saved
[reg
] = false;
5125 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.ri
.reg
);
5128 as_bad (_("unable to generate unwinding opcode for reg %d"),
5132 unwind
->reg_saved
[reg
] = true;
5133 unwind
->reg_offset
[reg
] = insn
->u
.ri
.offset
;
5134 if (insn
->u
.ri
.reg
== UNWIND_B3
)
5135 unwind
->return_reg
= UNWIND_B3
;
5138 case DW_CFA_register
:
5139 if (insn
->u
.rr
.reg1
!= 19)
5141 as_bad (_("unable to generate unwinding opcode for reg %d"),
5146 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.rr
.reg2
);
5149 as_bad (_("unable to generate unwinding opcode for reg %d"),
5154 unwind
->return_reg
= reg
;
5155 unwind
->reg_saved
[UNWIND_B3
] = false;
5156 if (unwind
->reg_saved
[reg
])
5158 as_bad (_("unable to restore return address from "
5159 "previously restored reg"));
5164 case DW_CFA_restore
:
5165 case DW_CFA_remember_state
:
5166 case DW_CFA_restore_state
:
5167 case DW_CFA_GNU_window_save
:
5169 case CFI_val_encoded_addr
:
5170 as_bad (_("unhandled CFA insn for unwinding (%d)"), insn
->insn
);
5178 if (unwind
->cfa_reg
!= 15 && unwind
->cfa_reg
!= 31)
5180 as_bad (_("unable to generate unwinding opcode for frame pointer reg %d"),
5185 if (unwind
->cfa_reg
== 15)
5187 if (cfa_offset
!= 0)
5189 as_bad (_("unable to generate unwinding opcode for "
5190 "frame pointer offset"));
5196 if ((cfa_offset
& 7) != 0)
5198 as_bad (_("unwound stack pointer not doubleword aligned"));
5203 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5205 if (unwind
->reg_saved
[reg
])
5206 reg_saved_mask
|= 1 << (TIC6X_NUM_UNWIND_REGS
- (reg
+ 1));
5209 /* Check for standard "safe debug" frame layout */
5213 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5215 if (!unwind
->reg_saved
[reg
])
5218 if (target_big_endian
5219 && reg
< TIC6X_NUM_UNWIND_REGS
- 1
5220 && unwind
->reg_saved
[reg
+ 1]
5221 && tic6x_unwind_frame_regs
[reg
]
5222 == tic6x_unwind_frame_regs
[reg
+ 1] + 1
5223 && (tic6x_unwind_frame_regs
[reg
] & 1) == 1
5224 && (save_offset
& 4) == 4)
5227 if (save_offset
!= unwind
->reg_offset
[reg
+ 1]
5228 || save_offset
- 4 != unwind
->reg_offset
[reg
])
5235 if (save_offset
!= unwind
->reg_offset
[reg
])
5240 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5242 safe_mask
= reg_saved_mask
;
5247 /* Check for compact frame layout. */
5251 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5255 if (!unwind
->reg_saved
[reg
])
5258 if (reg
< TIC6X_NUM_UNWIND_REGS
- 1)
5262 if (!unwind
->reg_saved
[reg2
]
5263 || tic6x_unwind_frame_regs
[reg
]
5264 != tic6x_unwind_frame_regs
[reg2
] + 1
5265 || (tic6x_unwind_frame_regs
[reg2
] & 1) != 0
5266 || save_offset
== 0)
5275 if (target_big_endian
)
5276 high_offset
= 4; /* lower address = positive stack offset. */
5280 if (save_offset
+ 4 - high_offset
!= unwind
->reg_offset
[reg
]
5281 || save_offset
+ high_offset
!= unwind
->reg_offset
[reg2
])
5289 if (save_offset
!= unwind
->reg_offset
[reg
])
5295 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5297 compact_mask
= reg_saved_mask
;
5302 /* Check for __c6xabi_pop_rts format */
5303 if (reg_saved_mask
== 0x17ff)
5305 const int *pop_rts_offset
= target_big_endian
5306 ? tic6x_pop_rts_offset_big
5307 : tic6x_pop_rts_offset_little
;
5310 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5312 if (reg
== UNWIND_B15
)
5315 if (unwind
->reg_offset
[reg
] != pop_rts_offset
[reg
] * 4)
5319 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5321 unwind
->pop_rts
= true;
5325 /* If all else fails then describe the frame manually. */
5330 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5332 if (!unwind
->reg_saved
[reg
])
5335 unwind
->saved_reg_count
++;
5336 /* Encoding uses 4 bits per word, so size of unwinding opcode data
5337 limits the save area size. The exact cap will be figured out
5338 later due to overflow, the 0x800 here is just a quick sanity
5339 check to weed out obviously excessive offsets. */
5340 if (unwind
->reg_offset
[reg
] > 0 || unwind
->reg_offset
[reg
] < -0x800
5341 || (unwind
->reg_offset
[reg
] & 3) != 0)
5343 as_bad (_("stack frame layout too complex for unwinder"));
5347 if (unwind
->reg_offset
[reg
] < save_offset
)
5348 save_offset
= unwind
->reg_offset
[reg
] - 4;
5352 /* Align to 8-byte boundary (stack grows towards negative offsets). */
5355 if (unwind
->cfa_reg
== 31 && !reg_saved_mask
)
5357 cfa_offset
+= save_offset
;
5360 as_bad (_("unwound frame has negative size"));
5365 unwind
->safe_mask
= safe_mask
;
5366 unwind
->compact_mask
= compact_mask
;
5367 unwind
->reg_saved_mask
= reg_saved_mask
;
5368 unwind
->cfa_offset
= cfa_offset
;
5369 unwind
->function_start
= fde
->start_address
;