3 Free Software Foundation, Inc.
4 Contributed by Joseph Myers <joseph@codesourcery.com>
5 Bernd Schmidt <bernds@codesourcery.com>
7 This file is part of GAS, the GNU Assembler.
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to the Free
21 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
25 #include "dwarf2dbg.h"
26 #include "dw2gencfi.h"
27 #include "safe-ctype.h"
29 #include "opcode/tic6x.h"
30 #include "elf/tic6x.h"
31 #include "elf32-tic6x.h"
33 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit
34 host gives identical results to a 32-bit host. */
35 #define TRUNC(X) ((valueT) (X) & 0xffffffffU)
36 #define SEXT(X) ((TRUNC (X) ^ 0x80000000U) - 0x80000000U)
38 #define streq(a, b) (strcmp (a, b) == 0)
40 /* Stuff for .scomm symbols. */
41 static segT sbss_section
;
42 static asection scom_section
;
43 static asymbol scom_symbol
;
45 const char comment_chars
[] = ";";
46 const char line_comment_chars
[] = "#*;";
47 const char line_separator_chars
[] = "@";
49 const char EXP_CHARS
[] = "eE";
50 const char FLT_CHARS
[] = "dDfF";
52 const char *md_shortopts
= "";
56 OPTION_MARCH
= OPTION_MD_BASE
,
58 OPTION_MLITTLE_ENDIAN
,
67 struct option md_longopts
[] =
69 { "march", required_argument
, NULL
, OPTION_MARCH
},
70 { "mbig-endian", no_argument
, NULL
, OPTION_MBIG_ENDIAN
},
71 { "mlittle-endian", no_argument
, NULL
, OPTION_MLITTLE_ENDIAN
},
72 { "mdsbt", no_argument
, NULL
, OPTION_MDSBT
},
73 { "mno-dsbt", no_argument
, NULL
, OPTION_MNO_DSBT
},
74 { "mpid", required_argument
, NULL
, OPTION_MPID
},
75 { "mpic", no_argument
, NULL
, OPTION_MPIC
},
76 { "mno-pic", no_argument
, NULL
, OPTION_MNO_PIC
},
77 { "mgenerate-rel", no_argument
, NULL
, OPTION_MGENERATE_REL
},
78 { NULL
, no_argument
, NULL
, 0 }
80 size_t md_longopts_size
= sizeof (md_longopts
);
82 /* The instructions enabled based only on the selected architecture
83 (all instructions, if no architecture specified). */
84 static unsigned short tic6x_arch_enable
= (TIC6X_INSN_C62X
91 /* The instructions enabled based on the current set of features
92 (architecture, as modified by other options). */
93 static unsigned short tic6x_features
;
95 /* The architecture attribute value, or C6XABI_Tag_ISA_none if
97 static int tic6x_arch_attribute
= C6XABI_Tag_ISA_none
;
99 /* Whether any instructions at all have been seen. Once any
100 instructions have been seen, architecture attributes merge into the
101 previous attribute value rather than replacing it. */
102 static bfd_boolean tic6x_seen_insns
= FALSE
;
104 /* The number of registers in each register file supported by the
105 current architecture. */
106 static unsigned int tic6x_num_registers
;
108 /* Whether predication on A0 is possible. */
109 static bfd_boolean tic6x_predicate_a0
;
111 /* Whether execute packets can cross fetch packet boundaries. */
112 static bfd_boolean tic6x_can_cross_fp_boundary
;
114 /* Whether there are constraints on simultaneous reads and writes of
116 static bfd_boolean tic6x_long_data_constraints
;
118 /* Whether compact instructions are available. */
119 static bfd_boolean tic6x_compact_insns
;
121 /* Whether to generate RELA relocations. */
122 static bfd_boolean tic6x_generate_rela
= TRUE
;
124 /* Whether the code uses DSBT addressing. */
125 static bfd_boolean tic6x_dsbt
;
127 /* Types of position-independent data (attribute values for
136 /* The type of data addressing used in this code. */
137 static tic6x_pid_type tic6x_pid
;
139 /* Whether the code uses position-independent code. */
140 static bfd_boolean tic6x_pic
;
142 /* Table of supported architecture variants. */
147 unsigned short features
;
149 static const tic6x_arch_table tic6x_arches
[] =
151 { "c62x", C6XABI_Tag_ISA_C62X
, TIC6X_INSN_C62X
},
152 { "c64x", C6XABI_Tag_ISA_C64X
, TIC6X_INSN_C62X
| TIC6X_INSN_C64X
},
153 { "c64x+", C6XABI_Tag_ISA_C64XP
, (TIC6X_INSN_C62X
155 | TIC6X_INSN_C64XP
) },
156 { "c67x", C6XABI_Tag_ISA_C67X
, TIC6X_INSN_C62X
| TIC6X_INSN_C67X
},
157 { "c67x+", C6XABI_Tag_ISA_C67XP
, (TIC6X_INSN_C62X
159 | TIC6X_INSN_C67XP
) },
160 { "c674x", C6XABI_Tag_ISA_C674X
, (TIC6X_INSN_C62X
165 | TIC6X_INSN_C674X
) }
168 /* Caller saved register encodings. The standard frame layout uses this
169 order, starting from the highest address. There must be
170 TIC6X_NUM_UNWIND_REGS values. */
188 static void tic6x_output_unwinding (bfd_boolean need_extab
);
190 /* Return the frame unwind state for the current function, allocating
193 static tic6x_unwind_info
*tic6x_get_unwind (void)
195 tic6x_unwind_info
*unwind
;
197 unwind
= seg_info (now_seg
)->tc_segment_info_data
.unwind
;
201 unwind
= seg_info (now_seg
)->tc_segment_info_data
.text_unwind
;
205 unwind
= (tic6x_unwind_info
*)xmalloc (sizeof (tic6x_unwind_info
));
206 seg_info (now_seg
)->tc_segment_info_data
.unwind
= unwind
;
207 memset (unwind
, 0, sizeof (*unwind
));
211 /* Update the selected architecture based on ARCH, giving an error if
212 ARCH is an invalid value. Does not call tic6x_update_features; the
213 caller must do that if necessary. */
216 tic6x_use_arch (const char *arch
)
220 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
221 if (strcmp (arch
, tic6x_arches
[i
].arch
) == 0)
223 tic6x_arch_enable
= tic6x_arches
[i
].features
;
224 if (tic6x_seen_insns
)
226 = elf32_tic6x_merge_arch_attributes (tic6x_arch_attribute
,
227 tic6x_arches
[i
].attr
);
229 tic6x_arch_attribute
= tic6x_arches
[i
].attr
;
233 as_bad (_("unknown architecture '%s'"), arch
);
236 /* Table of supported -mpid arguments. */
241 } tic6x_pid_type_table
;
242 static const tic6x_pid_type_table tic6x_pid_types
[] =
244 { "no", tic6x_pid_no
},
245 { "near", tic6x_pid_near
},
246 { "far", tic6x_pid_far
}
249 /* Handle -mpid=ARG. */
252 tic6x_use_pid (const char *arg
)
256 for (i
= 0; i
< ARRAY_SIZE (tic6x_pid_types
); i
++)
257 if (strcmp (arg
, tic6x_pid_types
[i
].arg
) == 0)
259 tic6x_pid
= tic6x_pid_types
[i
].attr
;
263 as_bad (_("unknown -mpid= argument '%s'"), arg
);
266 /* Parse a target-specific option. */
269 md_parse_option (int c
, char *arg
)
274 tic6x_use_arch (arg
);
277 case OPTION_MBIG_ENDIAN
:
278 target_big_endian
= 1;
281 case OPTION_MLITTLE_ENDIAN
:
282 target_big_endian
= 0;
289 case OPTION_MNO_DSBT
:
305 case OPTION_MGENERATE_REL
:
306 tic6x_generate_rela
= FALSE
;
316 md_show_usage (FILE *stream ATTRIBUTE_UNUSED
)
320 fputc ('\n', stream
);
321 fprintf (stream
, _("TMS320C6000 options:\n"));
322 fprintf (stream
, _(" -march=ARCH enable instructions from architecture ARCH\n"));
323 fprintf (stream
, _(" -mbig-endian generate big-endian code\n"));
324 fprintf (stream
, _(" -mlittle-endian generate little-endian code\n"));
325 fprintf (stream
, _(" -mdsbt code uses DSBT addressing\n"));
326 fprintf (stream
, _(" -mno-dsbt code does not use DSBT addressing\n"));
327 fprintf (stream
, _(" -mpid=no code uses position-dependent data addressing\n"));
328 fprintf (stream
, _(" -mpid=near code uses position-independent data addressing,\n"
329 " GOT accesses use near DP addressing\n"));
330 fprintf (stream
, _(" -mpid=far code uses position-independent data addressing,\n"
331 " GOT accesses use far DP addressing\n"));
332 fprintf (stream
, _(" -mpic code addressing is position-independent\n"));
333 fprintf (stream
, _(" -mno-pic code addressing is position-dependent\n"));
334 /* -mgenerate-rel is only for testsuite use and is deliberately
337 fputc ('\n', stream
);
338 fprintf (stream
, _("Supported ARCH values are:"));
339 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
340 fprintf (stream
, " %s", tic6x_arches
[i
].arch
);
341 fputc ('\n', stream
);
344 /* Update enabled features based on the current architecture and
347 tic6x_update_features (void)
349 tic6x_features
= tic6x_arch_enable
;
352 = (tic6x_arch_enable
& (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? 32 : 16;
354 tic6x_predicate_a0
= (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? TRUE
: FALSE
;
356 tic6x_can_cross_fp_boundary
358 & (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? TRUE
: FALSE
;
360 tic6x_long_data_constraints
361 = (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? FALSE
: TRUE
;
363 tic6x_compact_insns
= (tic6x_arch_enable
& TIC6X_INSN_C64XP
) ? TRUE
: FALSE
;
366 /* Do configuration after all options have been parsed. */
369 tic6x_after_parse_args (void)
371 tic6x_update_features ();
374 /* Parse a .cantunwind directive. */
376 s_tic6x_cantunwind (int ignored ATTRIBUTE_UNUSED
)
378 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
380 /* GCC sometimes spits out superfluous .cantunwind directives, so ignore
382 if (unwind
->data_bytes
== 0)
385 if (unwind
->data_bytes
!= -1)
387 as_bad (_("unexpected .cantunwind directive"));
391 demand_empty_rest_of_line ();
393 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
394 as_bad (_("personality routine specified for cantunwind frame"));
396 unwind
->personality_index
= -2;
399 /* Parse a .handlerdata directive. */
401 s_tic6x_handlerdata (int ignored ATTRIBUTE_UNUSED
)
403 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
405 if (!unwind
->saved_seg
)
407 as_bad (_("unexpected .handlerdata directive"));
411 if (unwind
->table_entry
|| unwind
->personality_index
== -2)
413 as_bad (_("duplicate .handlerdata directive"));
417 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
419 as_bad (_("personality routine required before .handlerdata directive"));
423 tic6x_output_unwinding (TRUE
);
426 /* Parse a .endp directive. */
428 s_tic6x_endp (int ignored ATTRIBUTE_UNUSED
)
430 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
432 if (unwind
->data_bytes
!= 0)
434 /* Output a .exidx entry if we have not already done so.
435 Then switch back to the text section. */
436 if (!unwind
->table_entry
)
437 tic6x_output_unwinding (FALSE
);
439 subseg_set (unwind
->saved_seg
, unwind
->saved_subseg
);
442 unwind
->saved_seg
= NULL
;
443 unwind
->table_entry
= NULL
;
444 unwind
->data_bytes
= 0;
447 /* Parse a .personalityindex directive. */
449 s_tic6x_personalityindex (int ignored ATTRIBUTE_UNUSED
)
451 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
454 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
455 as_bad (_("duplicate .personalityindex directive"));
459 if (exp
.X_op
!= O_constant
460 || exp
.X_add_number
< 0 || exp
.X_add_number
> 15)
462 as_bad (_("bad personality routine number"));
463 ignore_rest_of_line ();
467 unwind
->personality_index
= exp
.X_add_number
;
469 demand_empty_rest_of_line ();
473 s_tic6x_personality (int ignored ATTRIBUTE_UNUSED
)
476 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
478 if (unwind
->personality_routine
|| unwind
->personality_index
!= -1)
479 as_bad (_("duplicate .personality directive"));
481 name
= input_line_pointer
;
482 c
= get_symbol_end ();
483 p
= input_line_pointer
;
484 unwind
->personality_routine
= symbol_find_or_make (name
);
486 demand_empty_rest_of_line ();
489 /* Parse a .arch directive. */
491 s_tic6x_arch (int ignored ATTRIBUTE_UNUSED
)
496 arch
= input_line_pointer
;
497 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
498 input_line_pointer
++;
499 c
= *input_line_pointer
;
500 *input_line_pointer
= 0;
502 tic6x_use_arch (arch
);
503 tic6x_update_features ();
504 *input_line_pointer
= c
;
505 demand_empty_rest_of_line ();
508 /* Parse a .ehtype directive. */
511 s_tic6x_ehtype (int ignored ATTRIBUTE_UNUSED
)
516 #ifdef md_flush_pending_output
517 md_flush_pending_output ();
520 if (is_it_end_of_statement ())
522 demand_empty_rest_of_line ();
533 if (exp
.X_op
!= O_symbol
)
535 as_bad (_("expected symbol"));
540 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 4,
541 &exp
, 0, BFD_RELOC_C6000_EHTYPE
);
543 demand_empty_rest_of_line ();
546 /* Parse a .nocmp directive. */
549 s_tic6x_nocmp (int ignored ATTRIBUTE_UNUSED
)
551 seg_info (now_seg
)->tc_segment_info_data
.nocmp
= TRUE
;
552 demand_empty_rest_of_line ();
555 /* .scomm pseudo-op handler.
557 This is a new pseudo-op to handle putting objects in .scommon.
558 By doing this the linker won't need to do any work,
559 and more importantly it removes the implicit -G arg necessary to
560 correctly link the object file. */
563 s_tic6x_scomm (int ignore ATTRIBUTE_UNUSED
)
573 name
= input_line_pointer
;
574 c
= get_symbol_end ();
576 /* Just after name is now '\0'. */
577 p
= input_line_pointer
;
580 if (*input_line_pointer
!= ',')
582 as_bad (_("expected comma after symbol name"));
583 ignore_rest_of_line ();
588 input_line_pointer
++;
589 if ((size
= get_absolute_expression ()) < 0)
591 /* xgettext:c-format */
592 as_warn (_("invalid length for .scomm directive"));
593 ignore_rest_of_line ();
597 /* The third argument to .scomm is the alignment. */
598 if (*input_line_pointer
!= ',')
602 ++input_line_pointer
;
603 align
= get_absolute_expression ();
606 as_warn (_("alignment is not a positive number"));
611 /* Convert to a power of 2 alignment. */
614 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
)
618 as_bad (_("alignment is not a power of 2"));
619 ignore_rest_of_line ();
627 symbolP
= symbol_find_or_make (name
);
630 if (S_IS_DEFINED (symbolP
))
632 /* xgettext:c-format */
633 as_bad (_("attempt to re-define symbol `%s'"),
634 S_GET_NAME (symbolP
));
635 ignore_rest_of_line ();
639 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
641 /* xgettext:c-format */
642 as_bad (_("attempt to redefine `%s' with a different length"),
643 S_GET_NAME (symbolP
));
645 ignore_rest_of_line ();
649 if (symbol_get_obj (symbolP
)->local
)
651 segT old_sec
= now_seg
;
652 int old_subsec
= now_subseg
;
655 record_alignment (sbss_section
, align2
);
656 subseg_set (sbss_section
, 0);
659 frag_align (align2
, 0, 0);
661 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
662 symbol_get_frag (symbolP
)->fr_symbol
= 0;
664 symbol_set_frag (symbolP
, frag_now
);
666 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
669 S_SET_SIZE (symbolP
, size
);
670 S_SET_SEGMENT (symbolP
, sbss_section
);
671 S_CLEAR_EXTERNAL (symbolP
);
672 subseg_set (old_sec
, old_subsec
);
676 S_SET_VALUE (symbolP
, (valueT
) size
);
677 S_SET_ALIGN (symbolP
, 1 << align2
);
678 S_SET_EXTERNAL (symbolP
);
679 S_SET_SEGMENT (symbolP
, &scom_section
);
682 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
684 demand_empty_rest_of_line ();
687 /* Track for each attribute whether it has been set explicitly (and so
688 should not have a default value set by the assembler). */
689 static bfd_boolean tic6x_attributes_set_explicitly
[NUM_KNOWN_OBJ_ATTRIBUTES
];
691 /* Parse a .c6xabi_attribute directive. */
694 s_tic6x_c6xabi_attribute (int ignored ATTRIBUTE_UNUSED
)
696 int tag
= s_vendor_attribute (OBJ_ATTR_PROC
);
698 if (tag
< NUM_KNOWN_OBJ_ATTRIBUTES
)
699 tic6x_attributes_set_explicitly
[tag
] = TRUE
;
706 } tic6x_attribute_table
;
708 static const tic6x_attribute_table tic6x_attributes
[] =
710 #define TAG(tag, value) { #tag, tag },
711 #include "elf/tic6x-attrs.h"
715 /* Convert an attribute name to a number. */
718 tic6x_convert_symbolic_attribute (const char *name
)
722 for (i
= 0; i
< ARRAY_SIZE (tic6x_attributes
); i
++)
723 if (strcmp (name
, tic6x_attributes
[i
].name
) == 0)
724 return tic6x_attributes
[i
].tag
;
729 const pseudo_typeS md_pseudo_table
[] =
731 { "arch", s_tic6x_arch
, 0 },
732 { "c6xabi_attribute", s_tic6x_c6xabi_attribute
, 0 },
733 { "nocmp", s_tic6x_nocmp
, 0 },
734 { "scomm", s_tic6x_scomm
, 0 },
736 { "ehtype", s_tic6x_ehtype
, 0 },
737 { "endp", s_tic6x_endp
, 0 },
738 { "handlerdata", s_tic6x_handlerdata
, 0 },
739 { "personalityindex", s_tic6x_personalityindex
, 0 },
740 { "personality", s_tic6x_personality
, 0 },
741 { "cantunwind", s_tic6x_cantunwind
, 0 },
745 /* Hash table of opcodes. For each opcode name, this stores a pointer
746 to a tic6x_opcode_list listing (in an arbitrary order) all opcode
747 table entries with that name. */
748 static struct hash_control
*opcode_hash
;
750 /* Initialize the assembler (called once at assembler startup). */
760 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, 0);
762 /* Insert opcodes into the hash table. */
763 opcode_hash
= hash_new ();
764 for (id
= 0; id
< tic6x_opcode_max
; id
++)
767 tic6x_opcode_list
*opc
= xmalloc (sizeof (tic6x_opcode_list
));
770 opc
->next
= hash_find (opcode_hash
, tic6x_opcode_table
[id
].name
);
771 if ((errmsg
= hash_jam (opcode_hash
, tic6x_opcode_table
[id
].name
, opc
))
773 as_fatal ("%s", _(errmsg
));
776 /* Save the current subseg so we can restore it [it's the default one and
777 we don't want the initial section to be .sbss]. */
781 /* The sbss section is for local .scomm symbols. */
782 sbss_section
= subseg_new (".bss", 0);
783 seg_info (sbss_section
)->bss
= 1;
785 /* This is copied from perform_an_assembly_pass. */
786 applicable
= bfd_applicable_section_flags (stdoutput
);
787 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
& SEC_ALLOC
);
789 subseg_set (seg
, subseg
);
791 /* We must construct a fake section similar to bfd_com_section
792 but with the name .scommon. */
793 scom_section
= bfd_com_section
;
794 scom_section
.name
= ".scommon";
795 scom_section
.output_section
= & scom_section
;
796 scom_section
.symbol
= & scom_symbol
;
797 scom_section
.symbol_ptr_ptr
= & scom_section
.symbol
;
798 scom_symbol
= * bfd_com_section
.symbol
;
799 scom_symbol
.name
= ".scommon";
800 scom_symbol
.section
= & scom_section
;
803 /* Whether the current line being parsed had the "||" parallel bars. */
804 static bfd_boolean tic6x_line_parallel
;
806 /* Whether the current line being parsed started "||^" to indicate an
807 SPMASKed parallel instruction. */
808 static bfd_boolean tic6x_line_spmask
;
810 /* If the current line being parsed had an instruction predicate, the
811 creg value for that predicate (which must be nonzero); otherwise
813 static unsigned int tic6x_line_creg
;
815 /* If the current line being parsed had an instruction predicate, the
816 z value for that predicate; otherwise 0. */
817 static unsigned int tic6x_line_z
;
819 /* Return 1 (updating input_line_pointer as appropriate) if the line
820 starting with C (immediately before input_line_pointer) starts with
821 pre-opcode text appropriate for this target, 0 otherwise. */
824 tic6x_unrecognized_line (int c
)
829 bfd_boolean bad_predicate
;
834 if (input_line_pointer
[0] == '|')
836 if (input_line_pointer
[1] == '^')
838 tic6x_line_spmask
= TRUE
;
839 input_line_pointer
+= 2;
842 input_line_pointer
+= 1;
843 if (tic6x_line_parallel
)
844 as_bad (_("multiple '||' on same line"));
845 tic6x_line_parallel
= TRUE
;
847 as_bad (_("'||' after predicate"));
853 /* If it doesn't look like a predicate at all, just return 0.
854 If it looks like one but not a valid one, give a better
856 p
= input_line_pointer
;
857 while (*p
!= ']' && !is_end_of_line
[(unsigned char) *p
])
862 p
= input_line_pointer
;
864 bad_predicate
= FALSE
;
870 if (*p
== 'A' || *p
== 'a')
872 else if (*p
== 'B' || *p
== 'b')
876 areg
= TRUE
; /* Avoid uninitialized warning. */
877 bad_predicate
= TRUE
;
882 if (*p
!= '0' && *p
!= '1' && *p
!= '2')
883 bad_predicate
= TRUE
;
884 else if (p
[1] != ']')
885 bad_predicate
= TRUE
;
887 input_line_pointer
= p
+ 2;
891 as_bad (_("multiple predicates on same line"));
897 as_bad (_("bad predicate '%s'"), input_line_pointer
- 1);
899 input_line_pointer
= endp
;
906 tic6x_line_creg
= (areg
? 6 : 1);
907 if (areg
&& !tic6x_predicate_a0
)
908 as_bad (_("predication on A0 not supported on this architecture"));
912 tic6x_line_creg
= (areg
? 4 : 2);
916 tic6x_line_creg
= (areg
? 5 : 3);
931 /* Do any target-specific handling of a label required. */
934 tic6x_frob_label (symbolS
*sym
)
936 segment_info_type
*si
;
937 tic6x_label_list
*list
;
939 if (tic6x_line_parallel
)
941 as_bad (_("label after '||'"));
942 tic6x_line_parallel
= FALSE
;
943 tic6x_line_spmask
= FALSE
;
947 as_bad (_("label after predicate"));
952 si
= seg_info (now_seg
);
953 list
= si
->tc_segment_info_data
.label_list
;
954 si
->tc_segment_info_data
.label_list
= xmalloc (sizeof (tic6x_label_list
));
955 si
->tc_segment_info_data
.label_list
->next
= list
;
956 si
->tc_segment_info_data
.label_list
->label
= sym
;
958 /* Defining tc_frob_label overrides the ELF definition of
959 obj_frob_label, so we need to apply its effects here. */
960 dwarf2_emit_label (sym
);
963 /* At end-of-line, give errors for start-of-line decorations that
964 needed an instruction but were not followed by one. */
967 tic6x_end_of_line (void)
969 if (tic6x_line_parallel
)
971 as_bad (_("'||' not followed by instruction"));
972 tic6x_line_parallel
= FALSE
;
973 tic6x_line_spmask
= FALSE
;
977 as_bad (_("predicate not followed by instruction"));
983 /* Do any target-specific handling of the start of a logical line. */
986 tic6x_start_line_hook (void)
988 tic6x_end_of_line ();
991 /* Do target-specific handling immediately after an input file from
992 the command line, and any other inputs it includes, have been
998 tic6x_end_of_line ();
1001 /* Do target-specific initialization after arguments have been
1002 processed and the output file created. */
1005 tic6x_init_after_args (void)
1007 elf32_tic6x_set_use_rela_p (stdoutput
, tic6x_generate_rela
);
1010 /* Free LIST of labels (possibly NULL). */
1013 tic6x_free_label_list (tic6x_label_list
*list
)
1017 tic6x_label_list
*old
= list
;
1024 /* Handle a data alignment of N bytes. */
1027 tic6x_cons_align (int n ATTRIBUTE_UNUSED
)
1029 segment_info_type
*seginfo
= seg_info (now_seg
);
1031 /* Data means there is no current execute packet, and that any label
1032 applies to that data rather than a subsequent instruction. */
1033 tic6x_free_label_list (seginfo
->tc_segment_info_data
.label_list
);
1034 seginfo
->tc_segment_info_data
.label_list
= NULL
;
1035 seginfo
->tc_segment_info_data
.execute_packet_frag
= NULL
;
1036 seginfo
->tc_segment_info_data
.last_insn_lsb
= NULL
;
1037 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
1038 seginfo
->tc_segment_info_data
.func_units_used
= 0;
1041 /* Handle an alignment directive. Return TRUE if the
1042 machine-independent frag generation should be skipped. */
1045 tic6x_do_align (int n
, char *fill
, int len ATTRIBUTE_UNUSED
, int max
)
1047 /* Given code alignments of 4, 8, 16 or 32 bytes, we try to handle
1048 them in the md_end pass by inserting NOPs in parallel with
1049 previous instructions. We only do this in sections containing
1050 nothing but instructions. Code alignments of 1 or 2 bytes have
1051 no effect in such sections (but we record them with
1052 machine-dependent frags anyway so they can be skipped or
1053 converted to machine-independent), while those of more than 64
1054 bytes cannot reliably be handled in this way. */
1060 && subseg_text_p (now_seg
))
1068 /* Machine-independent code would generate a frag here, but we
1069 wish to handle it in a machine-dependent way. */
1070 if (frag_now_fix () != 0)
1072 if (frag_now
->fr_type
!= rs_machine_dependent
)
1073 frag_wane (frag_now
);
1078 align_frag
= frag_now
;
1079 p
= frag_var (rs_machine_dependent
, 32, 32, max
, NULL
, n
, NULL
);
1080 /* This must be the same as the frag to which a pointer was just
1082 if (p
!= align_frag
->fr_literal
)
1084 align_frag
->tc_frag_data
.is_insns
= FALSE
;
1091 /* Types of operand for parsing purposes. These are used as bit-masks
1092 to tell tic6x_parse_operand what forms of operand are
1094 #define TIC6X_OP_EXP 0x0001u
1095 #define TIC6X_OP_REG 0x0002u
1096 #define TIC6X_OP_REGPAIR 0x0004u
1097 #define TIC6X_OP_IRP 0x0008u
1098 #define TIC6X_OP_NRP 0x0010u
1099 /* With TIC6X_OP_MEM_NOUNREG, the contents of a () offset are always
1100 interpreted as an expression, which may be a symbol with the same
1101 name as a register that ends up being implicitly DP-relative. With
1102 TIC6X_OP_MEM_UNREG, the contents of a () offset are interpreted as
1103 a register if they match one, and failing that as an expression,
1104 which must be constant. */
1105 #define TIC6X_OP_MEM_NOUNREG 0x0020u
1106 #define TIC6X_OP_MEM_UNREG 0x0040u
1107 #define TIC6X_OP_CTRL 0x0080u
1108 #define TIC6X_OP_FUNC_UNIT 0x0100u
1110 /* A register or register pair read by the assembler. */
1113 /* The side the register is on (1 or 2). */
1115 /* The register number (0 to 31). */
1119 /* Types of modification of a base address. */
1124 tic6x_mem_mod_minus
,
1125 tic6x_mem_mod_preinc
,
1126 tic6x_mem_mod_predec
,
1127 tic6x_mem_mod_postinc
,
1128 tic6x_mem_mod_postdec
1131 /* Scaled [] or unscaled () nature of an offset. */
1135 tic6x_offset_scaled
,
1136 tic6x_offset_unscaled
1137 } tic6x_mem_scaling
;
1139 /* A memory operand read by the assembler. */
1142 /* The base register. */
1143 tic6x_register base_reg
;
1144 /* How the base register is modified. */
1146 /* Whether there is an offset (required with plain "+" and "-"), and
1147 whether it is scaled or unscaled if so. */
1148 tic6x_mem_scaling scaled
;
1149 /* Whether the offset is a register (TRUE) or an expression
1151 bfd_boolean offset_is_reg
;
1160 /* A functional unit in SPMASK operands read by the assembler. */
1163 /* The basic unit. */
1164 tic6x_func_unit_base base
;
1165 /* The side (1 or 2). */
1167 } tic6x_func_unit_operand
;
1169 /* An operand read by the assembler. */
1172 /* The syntactic form of the operand, as one of the bit-masks
1175 /* The operand value. */
1178 /* An expression: TIC6X_OP_EXP. */
1180 /* A register: TIC6X_OP_REG, TIC6X_OP_REGPAIR. */
1182 /* A memory reference: TIC6X_OP_MEM_NOUNREG,
1183 TIC6X_OP_MEM_UNREG. */
1185 /* A control register: TIC6X_OP_CTRL. */
1187 /* A functional unit: TIC6X_OP_FUNC_UNIT. */
1188 tic6x_func_unit_operand func_unit
;
1192 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1194 /* Parse a register operand, or part of an operand, starting at *P.
1195 If syntactically OK (including that the number is in the range 0 to
1196 31, but not necessarily in range for this architecture), return
1197 TRUE, putting the register side and number in *REG and update *P to
1198 point immediately after the register number; otherwise return FALSE
1199 without changing *P (but possibly changing *REG). Do not print any
1203 tic6x_parse_register (char **p
, tic6x_register
*reg
)
1224 if (*r
>= '0' && *r
<= '9')
1226 reg
->num
= *r
- '0';
1232 if (reg
->num
> 0 && *r
>= '0' && *r
<= '9')
1234 reg
->num
= reg
->num
* 10 + (*r
- '0');
1238 if (*r
>= '0' && *r
<= '9')
1247 /* Parse the initial two characters of a functional unit name starting
1248 at *P. If OK, set *BASE and *SIDE and return TRUE; otherwise,
1252 tic6x_parse_func_unit_base (char *p
, tic6x_func_unit_base
*base
,
1255 bfd_boolean good_func_unit
= TRUE
;
1256 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
1257 unsigned int maybe_side
= 0;
1263 maybe_base
= tic6x_func_unit_d
;
1268 maybe_base
= tic6x_func_unit_l
;
1273 maybe_base
= tic6x_func_unit_m
;
1278 maybe_base
= tic6x_func_unit_s
;
1282 good_func_unit
= FALSE
;
1298 good_func_unit
= FALSE
;
1308 return good_func_unit
;
1311 /* Parse an operand starting at *P. If the operand parses OK, return
1312 TRUE and store the value in *OP; otherwise return FALSE (possibly
1313 changing *OP). In any case, update *P to point to the following
1314 comma or end of line. The possible operand forms are given by
1315 OP_FORMS. For diagnostics, this is operand OPNO of an opcode
1316 starting at STR, length OPC_LEN. */
1319 tic6x_parse_operand (char **p
, tic6x_operand
*op
, unsigned int op_forms
,
1320 char *str
, int opc_len
, unsigned int opno
)
1322 bfd_boolean operand_parsed
= FALSE
;
1325 if ((op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
1326 == (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
1329 /* Check for functional unit names for SPMASK and SPMASKR. */
1330 if (!operand_parsed
&& (op_forms
& TIC6X_OP_FUNC_UNIT
))
1332 tic6x_func_unit_base base
= tic6x_func_unit_nfu
;
1333 unsigned int side
= 0;
1335 if (tic6x_parse_func_unit_base (q
, &base
, &side
))
1339 skip_whitespace (rq
);
1340 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1342 op
->form
= TIC6X_OP_FUNC_UNIT
;
1343 op
->value
.func_unit
.base
= base
;
1344 op
->value
.func_unit
.side
= side
;
1345 operand_parsed
= TRUE
;
1351 /* Check for literal "irp". */
1352 if (!operand_parsed
&& (op_forms
& TIC6X_OP_IRP
))
1354 if ((q
[0] == 'i' || q
[0] == 'I')
1355 && (q
[1] == 'r' || q
[1] == 'R')
1356 && (q
[2] == 'p' || q
[2] == 'P'))
1360 skip_whitespace (rq
);
1361 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1363 op
->form
= TIC6X_OP_IRP
;
1364 operand_parsed
= TRUE
;
1370 /* Check for literal "nrp". */
1371 if (!operand_parsed
&& (op_forms
& TIC6X_OP_NRP
))
1373 if ((q
[0] == 'n' || q
[0] == 'N')
1374 && (q
[1] == 'r' || q
[1] == 'R')
1375 && (q
[2] == 'p' || q
[2] == 'P'))
1379 skip_whitespace (rq
);
1380 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1382 op
->form
= TIC6X_OP_NRP
;
1383 operand_parsed
= TRUE
;
1389 /* Check for control register names. */
1390 if (!operand_parsed
&& (op_forms
& TIC6X_OP_CTRL
))
1394 for (crid
= 0; crid
< tic6x_ctrl_max
; crid
++)
1396 size_t len
= strlen (tic6x_ctrl_table
[crid
].name
);
1398 if (strncasecmp (tic6x_ctrl_table
[crid
].name
, q
, len
) == 0)
1402 skip_whitespace (rq
);
1403 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1405 op
->form
= TIC6X_OP_CTRL
;
1406 op
->value
.ctrl
= crid
;
1407 operand_parsed
= TRUE
;
1409 if (!(tic6x_ctrl_table
[crid
].isa_variants
& tic6x_features
))
1410 as_bad (_("control register '%s' not supported "
1411 "on this architecture"),
1412 tic6x_ctrl_table
[crid
].name
);
1418 /* See if this looks like a memory reference. */
1420 && (op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
)))
1422 bfd_boolean mem_ok
= TRUE
;
1424 tic6x_mem_mod mem_mod
= tic6x_mem_mod_none
;
1425 tic6x_register base_reg
;
1426 bfd_boolean require_offset
, permit_offset
;
1427 tic6x_mem_scaling scaled
;
1428 bfd_boolean offset_is_reg
;
1429 expressionS offset_exp
;
1430 tic6x_register offset_reg
;
1439 skip_whitespace (mq
);
1445 mem_mod
= tic6x_mem_mod_preinc
;
1450 mem_mod
= tic6x_mem_mod_plus
;
1458 mem_mod
= tic6x_mem_mod_predec
;
1463 mem_mod
= tic6x_mem_mod_minus
;
1475 skip_whitespace (mq
);
1476 mem_ok
= tic6x_parse_register (&mq
, &base_reg
);
1479 if (mem_ok
&& mem_mod
== tic6x_mem_mod_none
)
1481 skip_whitespace (mq
);
1482 if (mq
[0] == '+' && mq
[1] == '+')
1484 mem_mod
= tic6x_mem_mod_postinc
;
1487 else if (mq
[0] == '-' && mq
[1] == '-')
1489 mem_mod
= tic6x_mem_mod_postdec
;
1494 if (mem_mod
== tic6x_mem_mod_none
)
1495 permit_offset
= FALSE
;
1497 permit_offset
= TRUE
;
1498 if (mem_mod
== tic6x_mem_mod_plus
|| mem_mod
== tic6x_mem_mod_minus
)
1499 require_offset
= TRUE
;
1501 require_offset
= FALSE
;
1502 scaled
= tic6x_offset_none
;
1503 offset_is_reg
= FALSE
;
1505 if (mem_ok
&& permit_offset
)
1509 skip_whitespace (mq
);
1513 scaled
= tic6x_offset_scaled
;
1519 scaled
= tic6x_offset_unscaled
;
1527 if (scaled
!= tic6x_offset_none
)
1529 skip_whitespace (mq
);
1530 if (scaled
== tic6x_offset_scaled
1531 || (op_forms
& TIC6X_OP_MEM_UNREG
))
1536 reg_ok
= tic6x_parse_register (&rq
, &offset_reg
);
1539 skip_whitespace (rq
);
1543 offset_is_reg
= TRUE
;
1549 char *save_input_line_pointer
;
1551 save_input_line_pointer
= input_line_pointer
;
1552 input_line_pointer
= mq
;
1553 expression (&offset_exp
);
1554 mq
= input_line_pointer
;
1555 input_line_pointer
= save_input_line_pointer
;
1557 skip_whitespace (mq
);
1565 if (mem_ok
&& require_offset
&& scaled
== tic6x_offset_none
)
1570 skip_whitespace (mq
);
1571 if (!is_end_of_line
[(unsigned char) *mq
] && *mq
!= ',')
1577 op
->form
= op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
);
1578 op
->value
.mem
.base_reg
= base_reg
;
1579 op
->value
.mem
.mod
= mem_mod
;
1580 op
->value
.mem
.scaled
= scaled
;
1581 op
->value
.mem
.offset_is_reg
= offset_is_reg
;
1583 op
->value
.mem
.offset
.reg
= offset_reg
;
1585 op
->value
.mem
.offset
.exp
= offset_exp
;
1586 operand_parsed
= TRUE
;
1588 if (base_reg
.num
>= tic6x_num_registers
)
1589 as_bad (_("register number %u not supported on this architecture"),
1591 if (offset_is_reg
&& offset_reg
.num
>= tic6x_num_registers
)
1592 as_bad (_("register number %u not supported on this architecture"),
1597 /* See if this looks like a register or register pair. */
1598 if (!operand_parsed
&& (op_forms
& (TIC6X_OP_REG
| TIC6X_OP_REGPAIR
)))
1600 tic6x_register first_reg
, second_reg
;
1604 reg_ok
= tic6x_parse_register (&rq
, &first_reg
);
1608 if (*rq
== ':' && (op_forms
& TIC6X_OP_REGPAIR
))
1611 reg_ok
= tic6x_parse_register (&rq
, &second_reg
);
1614 skip_whitespace (rq
);
1615 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1617 if ((second_reg
.num
& 1)
1618 || (first_reg
.num
!= second_reg
.num
+ 1)
1619 || (first_reg
.side
!= second_reg
.side
))
1620 as_bad (_("register pair for operand %u of '%.*s'"
1621 " not a valid even/odd pair"), opno
,
1623 op
->form
= TIC6X_OP_REGPAIR
;
1624 op
->value
.reg
= second_reg
;
1625 operand_parsed
= TRUE
;
1630 else if (op_forms
& TIC6X_OP_REG
)
1632 skip_whitespace (rq
);
1633 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1635 op
->form
= TIC6X_OP_REG
;
1636 op
->value
.reg
= first_reg
;
1637 operand_parsed
= TRUE
;
1644 if (first_reg
.num
>= tic6x_num_registers
)
1645 as_bad (_("register number %u not supported on this architecture"),
1647 if (op
->form
== TIC6X_OP_REGPAIR
1648 && second_reg
.num
>= tic6x_num_registers
)
1649 as_bad (_("register number %u not supported on this architecture"),
1654 /* Otherwise, parse it as an expression. */
1655 if (!operand_parsed
&& (op_forms
& TIC6X_OP_EXP
))
1657 char *save_input_line_pointer
;
1659 save_input_line_pointer
= input_line_pointer
;
1660 input_line_pointer
= q
;
1661 op
->form
= TIC6X_OP_EXP
;
1662 expression (&op
->value
.exp
);
1663 q
= input_line_pointer
;
1664 input_line_pointer
= save_input_line_pointer
;
1665 operand_parsed
= TRUE
;
1670 /* Now the operand has been parsed, there must be nothing more
1671 before the comma or end of line. */
1672 skip_whitespace (q
);
1673 if (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1675 operand_parsed
= FALSE
;
1676 as_bad (_("junk after operand %u of '%.*s'"), opno
,
1678 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1684 /* This could not be parsed as any acceptable form of
1688 case TIC6X_OP_REG
| TIC6X_OP_REGPAIR
:
1689 as_bad (_("bad register or register pair for operand %u of '%.*s'"),
1690 opno
, opc_len
, str
);
1693 case TIC6X_OP_REG
| TIC6X_OP_CTRL
:
1695 as_bad (_("bad register for operand %u of '%.*s'"),
1696 opno
, opc_len
, str
);
1699 case TIC6X_OP_REGPAIR
:
1700 as_bad (_("bad register pair for operand %u of '%.*s'"),
1701 opno
, opc_len
, str
);
1704 case TIC6X_OP_FUNC_UNIT
:
1705 as_bad (_("bad functional unit for operand %u of '%.*s'"),
1706 opno
, opc_len
, str
);
1710 as_bad (_("bad operand %u of '%.*s'"),
1711 opno
, opc_len
, str
);
1715 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1719 return operand_parsed
;
1722 /* Table of assembler operators and associated O_* values. */
1727 } tic6x_operator_table
;
1728 static const tic6x_operator_table tic6x_operators
[] = {
1729 #define O_dsbt_index O_md1
1730 { "dsbt_index", O_dsbt_index
},
1733 #define O_dpr_got O_md3
1734 { "dpr_got", O_dpr_got
},
1735 #define O_dpr_byte O_md4
1736 { "dpr_byte", O_dpr_byte
},
1737 #define O_dpr_hword O_md5
1738 { "dpr_hword", O_dpr_hword
},
1739 #define O_dpr_word O_md6
1740 { "dpr_word", O_dpr_word
},
1743 /* Parse a name in some machine-specific way. Used on C6X to handle
1744 assembler operators. */
1747 tic6x_parse_name (const char *name
, expressionS
*exprP
,
1748 enum expr_mode mode ATTRIBUTE_UNUSED
, char *nextchar
)
1750 char *p
= input_line_pointer
;
1751 char c
, *name_start
, *name_end
;
1752 const char *inner_name
;
1754 operatorT op
= O_illegal
;
1760 for (i
= 0; i
< ARRAY_SIZE (tic6x_operators
); i
++)
1761 if (strcasecmp (name
+ 1, tic6x_operators
[i
].name
) == 0)
1763 op
= tic6x_operators
[i
].op
;
1767 if (op
== O_illegal
)
1770 *input_line_pointer
= *nextchar
;
1771 skip_whitespace (p
);
1775 *input_line_pointer
= 0;
1779 skip_whitespace (p
);
1781 if (!is_name_beginner (*p
))
1783 *input_line_pointer
= 0;
1789 while (is_part_of_name (*p
))
1792 skip_whitespace (p
);
1796 *input_line_pointer
= 0;
1800 input_line_pointer
= p
+ 1;
1801 *nextchar
= *input_line_pointer
;
1802 *input_line_pointer
= 0;
1806 inner_name
= name_start
;
1807 if (op
== O_dsbt_index
&& strcmp (inner_name
, "__c6xabi_DSBT_BASE") != 0)
1809 as_bad (_("$DSBT_INDEX must be used with __c6xabi_DSBT_BASE"));
1810 inner_name
= "__c6xabi_DSBT_BASE";
1812 sym
= symbol_find_or_make (inner_name
);
1816 exprP
->X_add_symbol
= sym
;
1817 exprP
->X_add_number
= 0;
1818 exprP
->X_op_symbol
= NULL
;
1824 /* Create a fixup for an expression. Same arguments as fix_new_exp,
1825 plus FIX_ADDA which is TRUE for ADDA instructions (to indicate that
1826 fixes resolving to constants should have those constants implicitly
1827 shifted) and FALSE otherwise, but look for C6X-specific expression
1828 types and adjust the relocations or give errors accordingly. */
1831 tic6x_fix_new_exp (fragS
*frag
, int where
, int size
, expressionS
*exp
,
1832 int pcrel
, bfd_reloc_code_real_type r_type
,
1833 bfd_boolean fix_adda
)
1835 bfd_reloc_code_real_type new_reloc
= BFD_RELOC_UNUSED
;
1843 case BFD_RELOC_C6000_SBR_U15_W
:
1844 new_reloc
= BFD_RELOC_C6000_DSBT_INDEX
;
1848 as_bad (_("$DSBT_INDEX not supported in this context"));
1856 case BFD_RELOC_C6000_SBR_U15_W
:
1857 new_reloc
= BFD_RELOC_C6000_SBR_GOT_U15_W
;
1861 as_bad (_("$GOT not supported in this context"));
1869 case BFD_RELOC_C6000_ABS_L16
:
1870 new_reloc
= BFD_RELOC_C6000_SBR_GOT_L16_W
;
1873 case BFD_RELOC_C6000_ABS_H16
:
1874 new_reloc
= BFD_RELOC_C6000_SBR_GOT_H16_W
;
1878 as_bad (_("$DPR_GOT not supported in this context"));
1886 case BFD_RELOC_C6000_ABS_S16
:
1887 new_reloc
= BFD_RELOC_C6000_SBR_S16
;
1890 case BFD_RELOC_C6000_ABS_L16
:
1891 new_reloc
= BFD_RELOC_C6000_SBR_L16_B
;
1894 case BFD_RELOC_C6000_ABS_H16
:
1895 new_reloc
= BFD_RELOC_C6000_SBR_H16_B
;
1899 as_bad (_("$DPR_BYTE not supported in this context"));
1907 case BFD_RELOC_C6000_ABS_L16
:
1908 new_reloc
= BFD_RELOC_C6000_SBR_L16_H
;
1911 case BFD_RELOC_C6000_ABS_H16
:
1912 new_reloc
= BFD_RELOC_C6000_SBR_H16_H
;
1916 as_bad (_("$DPR_HWORD not supported in this context"));
1924 case BFD_RELOC_C6000_ABS_L16
:
1925 new_reloc
= BFD_RELOC_C6000_SBR_L16_W
;
1928 case BFD_RELOC_C6000_ABS_H16
:
1929 new_reloc
= BFD_RELOC_C6000_SBR_H16_W
;
1933 as_bad (_("$DPR_WORD not supported in this context"));
1944 as_bad (_("invalid PC-relative operand"));
1950 if (new_reloc
== BFD_RELOC_UNUSED
)
1951 fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1953 fix
= fix_new (frag
, where
, size
, exp
->X_add_symbol
, exp
->X_add_number
,
1955 fix
->tc_fix_data
.fix_adda
= fix_adda
;
1958 /* Generate a fix for a constant (.word etc.). Needed to ensure these
1959 go through the error checking in tic6x_fix_new_exp. */
1962 tic6x_cons_fix_new (fragS
*frag
, int where
, int size
, expressionS
*exp
)
1964 bfd_reloc_code_real_type r_type
;
1969 r_type
= BFD_RELOC_8
;
1973 r_type
= BFD_RELOC_16
;
1977 r_type
= BFD_RELOC_32
;
1981 as_bad (_("no %d-byte relocations available"), size
);
1985 tic6x_fix_new_exp (frag
, where
, size
, exp
, 0, r_type
, FALSE
);
1988 /* Initialize target-specific fix data. */
1991 tic6x_init_fix_data (fixS
*fixP
)
1993 fixP
->tc_fix_data
.fix_adda
= FALSE
;
1996 /* Return true if the fix can be handled by GAS, false if it must
1997 be passed through to the linker. */
2000 tic6x_fix_adjustable (fixS
*fixP
)
2002 switch (fixP
->fx_r_type
)
2004 /* Adjust_reloc_syms doesn't know about the GOT. */
2005 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
2006 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
2007 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
2008 case BFD_RELOC_C6000_EHTYPE
:
2011 case BFD_RELOC_C6000_PREL31
:
2019 /* Given the fine-grained form of an operand, return the coarse
2023 tic6x_coarse_operand_form (tic6x_operand_form form
)
2027 case tic6x_operand_asm_const
:
2028 case tic6x_operand_link_const
:
2029 return TIC6X_OP_EXP
;
2031 case tic6x_operand_reg
:
2032 case tic6x_operand_xreg
:
2033 case tic6x_operand_dreg
:
2034 case tic6x_operand_areg
:
2035 case tic6x_operand_retreg
:
2036 return TIC6X_OP_REG
;
2038 case tic6x_operand_regpair
:
2039 case tic6x_operand_xregpair
:
2040 case tic6x_operand_dregpair
:
2041 return TIC6X_OP_REGPAIR
;
2043 case tic6x_operand_irp
:
2044 return TIC6X_OP_IRP
;
2046 case tic6x_operand_nrp
:
2047 return TIC6X_OP_NRP
;
2049 case tic6x_operand_ctrl
:
2050 return TIC6X_OP_CTRL
;
2052 case tic6x_operand_mem_short
:
2053 case tic6x_operand_mem_long
:
2054 case tic6x_operand_mem_deref
:
2055 return TIC6X_OP_MEM_NOUNREG
;
2057 case tic6x_operand_mem_ndw
:
2058 return TIC6X_OP_MEM_UNREG
;
2060 case tic6x_operand_func_unit
:
2061 return TIC6X_OP_FUNC_UNIT
;
2068 /* How an operand may match or not match a desired form. If different
2069 instruction alternatives fail in different ways, the first failure
2070 in this list determines the diagnostic. */
2074 tic6x_match_matches
,
2075 /* Bad coarse form. */
2078 tic6x_match_non_const
,
2079 /* Register on wrong side. */
2080 tic6x_match_wrong_side
,
2081 /* Not a valid address register. */
2082 tic6x_match_bad_address
,
2083 /* Not a valid return address register. */
2084 tic6x_match_bad_return
,
2085 /* Control register not readable. */
2086 tic6x_match_ctrl_write_only
,
2087 /* Control register not writable. */
2088 tic6x_match_ctrl_read_only
,
2089 /* Not a valid memory reference for this instruction. */
2091 } tic6x_operand_match
;
2093 /* Return whether an operand matches the given fine-grained form and
2094 read/write usage, and, if it does not match, how it fails to match.
2095 The main functional unit side is SIDE; the cross-path side is CROSS
2096 (the same as SIDE if a cross path not used); the data side is
2098 static tic6x_operand_match
2099 tic6x_operand_matches_form (const tic6x_operand
*op
, tic6x_operand_form form
,
2100 tic6x_rw rw
, unsigned int side
, unsigned int cross
,
2101 unsigned int data_side
)
2103 unsigned int coarse
= tic6x_coarse_operand_form (form
);
2105 if (coarse
!= op
->form
)
2106 return tic6x_match_coarse
;
2110 case tic6x_operand_asm_const
:
2111 if (op
->value
.exp
.X_op
== O_constant
)
2112 return tic6x_match_matches
;
2114 return tic6x_match_non_const
;
2116 case tic6x_operand_link_const
:
2117 case tic6x_operand_irp
:
2118 case tic6x_operand_nrp
:
2119 case tic6x_operand_func_unit
:
2120 /* All expressions are link-time constants, although there may
2121 not be relocations to express them in the output file. "irp"
2122 and "nrp" are unique operand values. All parsed functional
2123 unit names are valid. */
2124 return tic6x_match_matches
;
2126 case tic6x_operand_reg
:
2127 case tic6x_operand_regpair
:
2128 if (op
->value
.reg
.side
== side
)
2129 return tic6x_match_matches
;
2131 return tic6x_match_wrong_side
;
2133 case tic6x_operand_xreg
:
2134 case tic6x_operand_xregpair
:
2135 if (op
->value
.reg
.side
== cross
)
2136 return tic6x_match_matches
;
2138 return tic6x_match_wrong_side
;
2140 case tic6x_operand_dreg
:
2141 case tic6x_operand_dregpair
:
2142 if (op
->value
.reg
.side
== data_side
)
2143 return tic6x_match_matches
;
2145 return tic6x_match_wrong_side
;
2147 case tic6x_operand_areg
:
2148 if (op
->value
.reg
.side
!= cross
)
2149 return tic6x_match_wrong_side
;
2150 else if (op
->value
.reg
.side
== 2
2151 && (op
->value
.reg
.num
== 14 || op
->value
.reg
.num
== 15))
2152 return tic6x_match_matches
;
2154 return tic6x_match_bad_address
;
2156 case tic6x_operand_retreg
:
2157 if (op
->value
.reg
.side
!= side
)
2158 return tic6x_match_wrong_side
;
2159 else if (op
->value
.reg
.num
!= 3)
2160 return tic6x_match_bad_return
;
2162 return tic6x_match_matches
;
2164 case tic6x_operand_ctrl
:
2168 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read
2169 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
2170 return tic6x_match_matches
;
2172 return tic6x_match_ctrl_write_only
;
2174 case tic6x_rw_write
:
2175 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_write
2176 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
2177 return tic6x_match_matches
;
2179 return tic6x_match_ctrl_read_only
;
2185 case tic6x_operand_mem_deref
:
2186 if (op
->value
.mem
.mod
!= tic6x_mem_mod_none
)
2187 return tic6x_match_bad_mem
;
2188 else if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2190 else if (op
->value
.mem
.base_reg
.side
!= side
)
2191 return tic6x_match_bad_mem
;
2193 return tic6x_match_matches
;
2195 case tic6x_operand_mem_short
:
2196 case tic6x_operand_mem_ndw
:
2197 if (op
->value
.mem
.base_reg
.side
!= side
)
2198 return tic6x_match_bad_mem
;
2199 if (op
->value
.mem
.mod
== tic6x_mem_mod_none
)
2201 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2203 return tic6x_match_matches
;
2205 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
2207 if (op
->value
.mem
.mod
== tic6x_mem_mod_plus
2208 || op
->value
.mem
.mod
== tic6x_mem_mod_minus
)
2210 return tic6x_match_matches
;
2212 if (op
->value
.mem
.offset_is_reg
)
2214 if (op
->value
.mem
.scaled
== tic6x_offset_unscaled
2215 && form
!= tic6x_operand_mem_ndw
)
2217 if (op
->value
.mem
.offset
.reg
.side
== side
)
2218 return tic6x_match_matches
;
2220 return tic6x_match_bad_mem
;
2224 if (op
->value
.mem
.offset
.exp
.X_op
== O_constant
)
2225 return tic6x_match_matches
;
2227 return tic6x_match_bad_mem
;
2230 case tic6x_operand_mem_long
:
2231 if (op
->value
.mem
.base_reg
.side
== 2
2232 && (op
->value
.mem
.base_reg
.num
== 14
2233 || op
->value
.mem
.base_reg
.num
== 15))
2235 switch (op
->value
.mem
.mod
)
2237 case tic6x_mem_mod_none
:
2238 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
2240 return tic6x_match_matches
;
2242 case tic6x_mem_mod_plus
:
2243 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
2245 if (op
->value
.mem
.offset_is_reg
)
2246 return tic6x_match_bad_mem
;
2247 else if (op
->value
.mem
.scaled
== tic6x_offset_scaled
2248 && op
->value
.mem
.offset
.exp
.X_op
!= O_constant
)
2249 return tic6x_match_bad_mem
;
2251 return tic6x_match_matches
;
2253 case tic6x_mem_mod_minus
:
2254 case tic6x_mem_mod_preinc
:
2255 case tic6x_mem_mod_predec
:
2256 case tic6x_mem_mod_postinc
:
2257 case tic6x_mem_mod_postdec
:
2258 return tic6x_match_bad_mem
;
2266 return tic6x_match_bad_mem
;
2273 /* Return the number of bits shift used with DP-relative coding method
2277 tic6x_dpr_shift (tic6x_coding_method coding
)
2281 case tic6x_coding_ulcst_dpr_byte
:
2284 case tic6x_coding_ulcst_dpr_half
:
2287 case tic6x_coding_ulcst_dpr_word
:
2295 /* Return the relocation used with DP-relative coding method
2298 static bfd_reloc_code_real_type
2299 tic6x_dpr_reloc (tic6x_coding_method coding
)
2303 case tic6x_coding_ulcst_dpr_byte
:
2304 return BFD_RELOC_C6000_SBR_U15_B
;
2306 case tic6x_coding_ulcst_dpr_half
:
2307 return BFD_RELOC_C6000_SBR_U15_H
;
2309 case tic6x_coding_ulcst_dpr_word
:
2310 return BFD_RELOC_C6000_SBR_U15_W
;
2317 /* Given a memory reference *MEM_REF as originally parsed, fill in
2318 defaults for missing offsets. */
2321 tic6x_default_mem_ref (tic6x_mem_ref
*mem_ref
)
2323 switch (mem_ref
->mod
)
2325 case tic6x_mem_mod_none
:
2326 if (mem_ref
->scaled
!= tic6x_offset_none
)
2328 mem_ref
->mod
= tic6x_mem_mod_plus
;
2329 mem_ref
->scaled
= tic6x_offset_unscaled
;
2330 mem_ref
->offset_is_reg
= FALSE
;
2331 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
2332 mem_ref
->offset
.exp
.X_op
= O_constant
;
2333 mem_ref
->offset
.exp
.X_add_number
= 0;
2334 mem_ref
->offset
.exp
.X_unsigned
= 0;
2337 case tic6x_mem_mod_plus
:
2338 case tic6x_mem_mod_minus
:
2339 if (mem_ref
->scaled
== tic6x_offset_none
)
2343 case tic6x_mem_mod_preinc
:
2344 case tic6x_mem_mod_predec
:
2345 case tic6x_mem_mod_postinc
:
2346 case tic6x_mem_mod_postdec
:
2347 if (mem_ref
->scaled
!= tic6x_offset_none
)
2349 mem_ref
->scaled
= tic6x_offset_scaled
;
2350 mem_ref
->offset_is_reg
= FALSE
;
2351 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
2352 mem_ref
->offset
.exp
.X_op
= O_constant
;
2353 mem_ref
->offset
.exp
.X_add_number
= 1;
2354 mem_ref
->offset
.exp
.X_unsigned
= 0;
2362 /* Return the encoding in the 8-bit field of an SPMASK or SPMASKR
2363 instruction of the specified UNIT, side SIDE. */
2366 tic6x_encode_spmask (tic6x_func_unit_base unit
, unsigned int side
)
2370 case tic6x_func_unit_l
:
2371 return 1 << (side
- 1);
2373 case tic6x_func_unit_s
:
2374 return 1 << (side
+ 1);
2376 case tic6x_func_unit_d
:
2377 return 1 << (side
+ 3);
2379 case tic6x_func_unit_m
:
2380 return 1 << (side
+ 5);
2387 /* Try to encode the instruction with opcode number ID and operands
2388 OPERANDS (number NUM_OPERANDS), creg value THIS_LINE_CREG and z
2389 value THIS_LINE_Z; FUNC_UNIT_SIDE, FUNC_UNIT_CROSS and
2390 FUNC_UNIT_DATA_SIDE describe the functional unit specification;
2391 SPLOOP_II is the ii value from the previous SPLOOP-family
2392 instruction, or 0 if not in such a loop; the only possible problems
2393 are operands being out of range (they already match the
2394 fine-grained form), and inappropriate predication. If this
2395 succeeds, return the encoding and set *OK to TRUE; otherwise return
2396 0 and set *OK to FALSE. If a fix is needed, set *FIX_NEEDED to
2397 true and fill in *FIX_EXP, *FIX_PCREL, *FX_R_TYPE and *FIX_ADDA.
2398 Print error messages for failure if PRINT_ERRORS is TRUE; the
2399 opcode starts at STR and has length OPC_LEN. */
2402 tic6x_try_encode (tic6x_opcode_id id
, tic6x_operand
*operands
,
2403 unsigned int num_operands
, unsigned int this_line_creg
,
2404 unsigned int this_line_z
, unsigned int func_unit_side
,
2405 unsigned int func_unit_cross
,
2406 unsigned int func_unit_data_side
, int sploop_ii
,
2407 expressionS
**fix_exp
, int *fix_pcrel
,
2408 bfd_reloc_code_real_type
*fx_r_type
, bfd_boolean
*fix_adda
,
2409 bfd_boolean
*fix_needed
, bfd_boolean
*ok
,
2410 bfd_boolean print_errors
, char *str
, int opc_len
)
2412 const tic6x_opcode
*opct
;
2413 const tic6x_insn_format
*fmt
;
2414 unsigned int opcode_value
;
2417 opct
= &tic6x_opcode_table
[id
];
2418 fmt
= &tic6x_insn_format_table
[opct
->format
];
2419 opcode_value
= fmt
->cst_bits
;
2421 for (fld
= 0; fld
< opct
->num_fixed_fields
; fld
++)
2423 if (opct
->fixed_fields
[fld
].min_val
== opct
->fixed_fields
[fld
].max_val
)
2425 const tic6x_insn_field
*fldd
;
2426 fldd
= tic6x_field_from_fmt (fmt
, opct
->fixed_fields
[fld
].field_id
);
2429 opcode_value
|= opct
->fixed_fields
[fld
].min_val
<< fldd
->low_pos
;
2433 for (fld
= 0; fld
< opct
->num_variable_fields
; fld
++)
2435 const tic6x_insn_field
*fldd
;
2441 unsigned int fcyc_bits
;
2446 fldd
= tic6x_field_from_fmt (fmt
, opct
->variable_fields
[fld
].field_id
);
2449 opno
= opct
->variable_fields
[fld
].operand_num
;
2450 switch (opct
->variable_fields
[fld
].coding_method
)
2452 case tic6x_coding_ucst
:
2453 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2455 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2457 ucexp
= operands
[opno
].value
.exp
;
2459 if (ucexp
.X_add_number
< 0
2460 || ucexp
.X_add_number
>= (1 << fldd
->width
))
2463 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2468 value
= ucexp
.X_add_number
;
2471 case tic6x_coding_scst
:
2472 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2474 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2477 /* Opcode table should not permit non-constants without
2478 a known relocation for them. */
2479 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2482 *fix_exp
= &operands
[opno
].value
.exp
;
2484 *fx_r_type
= BFD_RELOC_C6000_ABS_S16
;
2488 sign_value
= SEXT (operands
[opno
].value
.exp
.X_add_number
);
2490 if (sign_value
< -(1 << (fldd
->width
- 1))
2491 || (sign_value
>= (1 << (fldd
->width
- 1))))
2494 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2499 value
= sign_value
+ (1 << (fldd
->width
- 1));
2500 value
^= (1 << (fldd
->width
- 1));
2503 case tic6x_coding_ucst_minus_one
:
2504 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2506 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2508 if (operands
[opno
].value
.exp
.X_add_number
<= 0
2509 || operands
[opno
].value
.exp
.X_add_number
> (1 << fldd
->width
))
2512 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2517 value
= operands
[opno
].value
.exp
.X_add_number
- 1;
2520 case tic6x_coding_scst_negate
:
2521 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2523 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2525 sign_value
= SEXT (-operands
[opno
].value
.exp
.X_add_number
);
2526 goto signed_constant
;
2528 case tic6x_coding_ulcst_dpr_byte
:
2529 case tic6x_coding_ulcst_dpr_half
:
2530 case tic6x_coding_ulcst_dpr_word
:
2531 bits
= tic6x_dpr_shift (opct
->variable_fields
[fld
].coding_method
);
2532 switch (operands
[opno
].form
)
2535 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2537 ucexp
= operands
[opno
].value
.exp
;
2538 goto unsigned_constant
;
2540 expp
= &operands
[opno
].value
.exp
;
2543 case TIC6X_OP_MEM_NOUNREG
:
2544 mem
= operands
[opno
].value
.mem
;
2545 tic6x_default_mem_ref (&mem
);
2546 if (mem
.offset_is_reg
)
2548 if (mem
.offset
.exp
.X_op
== O_constant
)
2550 ucexp
= mem
.offset
.exp
;
2551 if (mem
.scaled
== tic6x_offset_unscaled
)
2553 if (ucexp
.X_add_number
& ((1 << bits
) - 1))
2556 as_bad (_("offset in operand %u of '%.*s' not "
2557 "divisible by %u"), opno
+ 1, opc_len
,
2562 ucexp
.X_add_number
>>= bits
;
2564 goto unsigned_constant
;
2566 if (mem
.scaled
!= tic6x_offset_unscaled
)
2568 if (operands
[opno
].value
.mem
.mod
== tic6x_mem_mod_none
2569 || operands
[opno
].value
.mem
.scaled
!= tic6x_offset_unscaled
2570 || operands
[opno
].value
.mem
.offset_is_reg
)
2572 expp
= &operands
[opno
].value
.mem
.offset
.exp
;
2579 /* Opcode table should not use this encoding without a known
2581 if (fldd
->low_pos
!= 8 || fldd
->width
!= 15)
2583 /* We do not check for offset divisibility here; such a
2584 check is not needed at this point to encode the value,
2585 and if there is eventually a problem it will be detected
2586 either in md_apply_fix or at link time. */
2591 = tic6x_dpr_reloc (opct
->variable_fields
[fld
].coding_method
);
2592 if (operands
[opno
].form
== TIC6X_OP_EXP
)
2598 case tic6x_coding_lcst_low16
:
2599 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2601 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2602 value
= operands
[opno
].value
.exp
.X_add_number
& 0xffff;
2606 /* Opcode table should not use this encoding without a
2607 known relocation. */
2608 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2611 *fix_exp
= &operands
[opno
].value
.exp
;
2613 *fx_r_type
= BFD_RELOC_C6000_ABS_L16
;
2618 case tic6x_coding_lcst_high16
:
2619 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2621 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2622 value
= (operands
[opno
].value
.exp
.X_add_number
>> 16) & 0xffff;
2626 /* Opcode table should not use this encoding without a
2627 known relocation. */
2628 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2631 *fix_exp
= &operands
[opno
].value
.exp
;
2633 *fx_r_type
= BFD_RELOC_C6000_ABS_H16
;
2638 case tic6x_coding_pcrel
:
2639 case tic6x_coding_pcrel_half
:
2640 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2644 *fix_exp
= &operands
[opno
].value
.exp
;
2646 if (fldd
->low_pos
== 7 && fldd
->width
== 21)
2647 *fx_r_type
= BFD_RELOC_C6000_PCR_S21
;
2648 else if (fldd
->low_pos
== 16 && fldd
->width
== 12)
2649 *fx_r_type
= BFD_RELOC_C6000_PCR_S12
;
2650 else if (fldd
->low_pos
== 13 && fldd
->width
== 10)
2651 *fx_r_type
= BFD_RELOC_C6000_PCR_S10
;
2652 else if (fldd
->low_pos
== 16 && fldd
->width
== 7)
2653 *fx_r_type
= BFD_RELOC_C6000_PCR_S7
;
2655 /* Opcode table should not use this encoding without a
2656 known relocation. */
2661 case tic6x_coding_reg
:
2662 switch (operands
[opno
].form
)
2665 case TIC6X_OP_REGPAIR
:
2666 value
= operands
[opno
].value
.reg
.num
;
2669 case TIC6X_OP_MEM_NOUNREG
:
2670 case TIC6X_OP_MEM_UNREG
:
2671 value
= operands
[opno
].value
.mem
.base_reg
.num
;
2679 case tic6x_coding_areg
:
2680 switch (operands
[opno
].form
)
2683 value
= (operands
[opno
].value
.reg
.num
== 15 ? 1 : 0);
2686 case TIC6X_OP_MEM_NOUNREG
:
2687 value
= (operands
[opno
].value
.mem
.base_reg
.num
== 15 ? 1 : 0);
2695 case tic6x_coding_crlo
:
2696 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2698 value
= tic6x_ctrl_table
[operands
[opno
].value
.ctrl
].crlo
;
2701 case tic6x_coding_crhi
:
2702 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2707 case tic6x_coding_reg_shift
:
2708 if (operands
[opno
].form
!= TIC6X_OP_REGPAIR
)
2710 value
= operands
[opno
].value
.reg
.num
>> 1;
2713 case tic6x_coding_mem_offset
:
2714 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
)
2716 mem
= operands
[opno
].value
.mem
;
2717 tic6x_default_mem_ref (&mem
);
2718 if (mem
.offset_is_reg
)
2720 if (mem
.scaled
!= tic6x_offset_scaled
)
2722 value
= mem
.offset
.reg
.num
;
2728 if (mem
.offset
.exp
.X_op
!= O_constant
)
2732 case tic6x_offset_scaled
:
2736 case tic6x_offset_unscaled
:
2737 scale
= opct
->operand_info
[opno
].size
;
2738 if (scale
!= 1 && scale
!= 2 && scale
!= 4 && scale
!= 8)
2745 if (mem
.offset
.exp
.X_add_number
< 0
2746 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->width
) * scale
)
2749 as_bad (_("offset in operand %u of '%.*s' out of range"),
2750 opno
+ 1, opc_len
, str
);
2754 if (mem
.offset
.exp
.X_add_number
% scale
)
2757 as_bad (_("offset in operand %u of '%.*s' not "
2759 opno
+ 1, opc_len
, str
, scale
);
2763 value
= mem
.offset
.exp
.X_add_number
/ scale
;
2767 case tic6x_coding_mem_offset_noscale
:
2768 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2770 mem
= operands
[opno
].value
.mem
;
2771 tic6x_default_mem_ref (&mem
);
2772 if (mem
.offset_is_reg
)
2773 value
= mem
.offset
.reg
.num
;
2776 if (mem
.offset
.exp
.X_op
!= O_constant
)
2778 if (mem
.offset
.exp
.X_add_number
< 0
2779 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->width
))
2782 as_bad (_("offset in operand %u of '%.*s' out of range"),
2783 opno
+ 1, opc_len
, str
);
2787 value
= mem
.offset
.exp
.X_add_number
;
2791 case tic6x_coding_mem_mode
:
2792 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
2793 && operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2795 mem
= operands
[opno
].value
.mem
;
2796 tic6x_default_mem_ref (&mem
);
2799 case tic6x_mem_mod_plus
:
2803 case tic6x_mem_mod_minus
:
2807 case tic6x_mem_mod_preinc
:
2811 case tic6x_mem_mod_predec
:
2815 case tic6x_mem_mod_postinc
:
2819 case tic6x_mem_mod_postdec
:
2826 value
+= (mem
.offset_is_reg
? 4 : 0);
2829 case tic6x_coding_scaled
:
2830 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2832 mem
= operands
[opno
].value
.mem
;
2833 tic6x_default_mem_ref (&mem
);
2836 case tic6x_offset_unscaled
:
2840 case tic6x_offset_scaled
:
2849 case tic6x_coding_spmask
:
2850 /* The position of such a field is hardcoded in the handling
2852 if (fldd
->low_pos
!= 18)
2855 for (opno
= 0; opno
< num_operands
; opno
++)
2859 v
= tic6x_encode_spmask (operands
[opno
].value
.func_unit
.base
,
2860 operands
[opno
].value
.func_unit
.side
);
2864 as_bad (_("functional unit already masked for operand "
2865 "%u of '%.*s'"), opno
+ 1, opc_len
, str
);
2873 case tic6x_coding_reg_unused
:
2874 /* This is a placeholder; correct handling goes along with
2875 resource constraint checks. */
2879 case tic6x_coding_fstg
:
2880 case tic6x_coding_fcyc
:
2881 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2883 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2888 as_bad (_("'%.*s' instruction not in a software "
2897 else if (sploop_ii
<= 2)
2899 else if (sploop_ii
<= 4)
2901 else if (sploop_ii
<= 8)
2903 else if (sploop_ii
<= 14)
2907 if (fcyc_bits
> fldd
->width
)
2910 if (opct
->variable_fields
[fld
].coding_method
== tic6x_coding_fstg
)
2913 if (operands
[opno
].value
.exp
.X_add_number
< 0
2914 || (operands
[opno
].value
.exp
.X_add_number
2915 >= (1 << (fldd
->width
- fcyc_bits
))))
2918 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2923 value
= operands
[opno
].value
.exp
.X_add_number
;
2924 for (t
= 0, i
= fcyc_bits
; i
< fldd
->width
; i
++)
2926 t
= (t
<< 1) | (value
& 1);
2929 value
= t
<< fcyc_bits
;
2933 if (operands
[opno
].value
.exp
.X_add_number
< 0
2934 || (operands
[opno
].value
.exp
.X_add_number
>= sploop_ii
))
2937 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2942 value
= operands
[opno
].value
.exp
.X_add_number
;
2946 case tic6x_coding_fu
:
2947 value
= func_unit_side
== 2 ? 1 : 0;
2950 case tic6x_coding_data_fu
:
2951 value
= func_unit_data_side
== 2 ? 1 : 0;
2954 case tic6x_coding_xpath
:
2955 value
= func_unit_cross
;
2962 for (ffld
= 0; ffld
< opct
->num_fixed_fields
; ffld
++)
2963 if ((opct
->fixed_fields
[ffld
].field_id
2964 == opct
->variable_fields
[fld
].field_id
)
2965 && (value
< opct
->fixed_fields
[ffld
].min_val
2966 || value
> opct
->fixed_fields
[ffld
].max_val
))
2969 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2975 opcode_value
|= value
<< fldd
->low_pos
;
2980 const tic6x_insn_field
*creg
;
2981 const tic6x_insn_field
*z
;
2983 creg
= tic6x_field_from_fmt (fmt
, tic6x_field_creg
);
2987 as_bad (_("instruction '%.*s' cannot be predicated"),
2992 z
= tic6x_field_from_fmt (fmt
, tic6x_field_z
);
2993 /* If there is a creg field, there must be a z field; otherwise
2994 there is an error in the format table. */
2998 opcode_value
|= this_line_creg
<< creg
->low_pos
;
2999 opcode_value
|= this_line_z
<< z
->low_pos
;
3003 return opcode_value
;
3006 /* Convert the target integer stored in N bytes in BUF to a host
3007 integer, returning that value. */
3010 md_chars_to_number (char *buf
, int n
)
3013 unsigned char *p
= (unsigned char *) buf
;
3015 if (target_big_endian
)
3020 result
|= (*p
++ & 0xff);
3028 result
|= (p
[n
] & 0xff);
3035 /* Assemble the instruction starting at STR (an opcode, with the
3036 opcode name all-lowercase). */
3039 md_assemble (char *str
)
3043 bfd_boolean this_line_parallel
;
3044 bfd_boolean this_line_spmask
;
3045 unsigned int this_line_creg
;
3046 unsigned int this_line_z
;
3047 tic6x_label_list
*this_insn_label_list
;
3048 segment_info_type
*seginfo
;
3049 tic6x_opcode_list
*opc_list
, *opc
;
3050 tic6x_func_unit_base func_unit_base
= tic6x_func_unit_nfu
;
3051 unsigned int func_unit_side
= 0;
3052 unsigned int func_unit_cross
= 0;
3053 unsigned int cross_side
= 0;
3054 unsigned int func_unit_data_side
= 0;
3055 unsigned int max_matching_opcodes
, num_matching_opcodes
;
3056 tic6x_opcode_id
*opcm
= NULL
;
3057 unsigned int opc_rank
[TIC6X_NUM_PREFER
];
3058 const tic6x_opcode
*opct
= NULL
;
3059 int min_rank
, try_rank
, max_rank
;
3060 bfd_boolean num_operands_permitted
[TIC6X_MAX_SOURCE_OPERANDS
+ 1]
3062 unsigned int operand_forms
[TIC6X_MAX_SOURCE_OPERANDS
] = { 0 };
3063 tic6x_operand operands
[TIC6X_MAX_SOURCE_OPERANDS
];
3064 unsigned int max_num_operands
;
3065 unsigned int num_operands_read
;
3066 bfd_boolean ok_this_arch
, ok_this_fu
, ok_this_arch_fu
;
3067 bfd_boolean bad_operands
= FALSE
;
3068 unsigned int opcode_value
;
3069 bfd_boolean encoded_ok
;
3070 bfd_boolean fix_needed
= FALSE
;
3071 expressionS
*fix_exp
= NULL
;
3073 bfd_reloc_code_real_type fx_r_type
= BFD_RELOC_UNUSED
;
3074 bfd_boolean fix_adda
= FALSE
;
3079 while (*p
&& !is_end_of_line
[(unsigned char) *p
] && *p
!= ' ')
3082 /* This function should only have been called when there is actually
3083 an instruction to assemble. */
3087 /* Now an instruction has been seen, architecture attributes from
3088 .arch directives merge with rather than overriding the previous
3090 tic6x_seen_insns
= TRUE
;
3091 /* If no .arch directives or -march options have been seen, we are
3092 assessing instruction validity based on the C674X default, so set
3093 the attribute accordingly. */
3094 if (tic6x_arch_attribute
== C6XABI_Tag_ISA_none
)
3095 tic6x_arch_attribute
= C6XABI_Tag_ISA_C674X
;
3097 /* Reset global settings for parallel bars and predicates now to
3098 avoid extra errors if there are problems with this opcode. */
3099 this_line_parallel
= tic6x_line_parallel
;
3100 this_line_spmask
= tic6x_line_spmask
;
3101 this_line_creg
= tic6x_line_creg
;
3102 this_line_z
= tic6x_line_z
;
3103 tic6x_line_parallel
= FALSE
;
3104 tic6x_line_spmask
= FALSE
;
3105 tic6x_line_creg
= 0;
3107 seginfo
= seg_info (now_seg
);
3108 this_insn_label_list
= seginfo
->tc_segment_info_data
.label_list
;
3109 seginfo
->tc_segment_info_data
.label_list
= NULL
;
3111 opc_list
= hash_find_n (opcode_hash
, str
, p
- str
);
3112 if (opc_list
== NULL
)
3116 as_bad (_("unknown opcode '%s'"), str
);
3122 skip_whitespace (p
);
3124 /* See if there is something that looks like a functional unit
3128 bfd_boolean good_func_unit
;
3129 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
3130 unsigned int maybe_side
= 0;
3131 unsigned int maybe_cross
= 0;
3132 unsigned int maybe_data_side
= 0;
3134 good_func_unit
= tic6x_parse_func_unit_base (p
+ 1, &maybe_base
,
3139 if (p
[3] == ' ' || is_end_of_line
[(unsigned char) p
[3]])
3141 else if ((p
[3] == 'x' || p
[3] == 'X')
3142 && (p
[4] == ' ' || is_end_of_line
[(unsigned char) p
[4]]))
3147 else if (maybe_base
== tic6x_func_unit_d
3148 && (p
[3] == 't' || p
[3] == 'T')
3149 && (p
[4] == '1' || p
[4] == '2')
3150 && (p
[5] == ' ' || is_end_of_line
[(unsigned char) p
[5]]))
3152 maybe_data_side
= p
[4] - '0';
3156 good_func_unit
= FALSE
;
3161 func_unit_base
= maybe_base
;
3162 func_unit_side
= maybe_side
;
3163 func_unit_cross
= maybe_cross
;
3164 cross_side
= (func_unit_cross
? 3 - func_unit_side
: func_unit_side
);
3165 func_unit_data_side
= maybe_data_side
;
3168 skip_whitespace (p
);
3171 /* Determine which entries in the opcode table match, and the
3172 associated permitted forms of operands. */
3173 max_matching_opcodes
= 0;
3174 for (opc
= opc_list
; opc
; opc
= opc
->next
)
3175 max_matching_opcodes
++;
3176 num_matching_opcodes
= 0;
3177 opcm
= xmalloc (max_matching_opcodes
* sizeof (*opcm
));
3178 max_num_operands
= 0;
3179 ok_this_arch
= FALSE
;
3181 ok_this_arch_fu
= FALSE
;
3182 for (opc
= opc_list
; opc
; opc
= opc
->next
)
3184 unsigned int num_operands
;
3186 bfd_boolean this_opc_arch_ok
= TRUE
;
3187 bfd_boolean this_opc_fu_ok
= TRUE
;
3189 if (tic6x_insn_format_table
[tic6x_opcode_table
[opc
->id
].format
].num_bits
3192 if (!(tic6x_opcode_table
[opc
->id
].isa_variants
& tic6x_features
))
3193 this_opc_arch_ok
= FALSE
;
3194 if (tic6x_opcode_table
[opc
->id
].func_unit
!= func_unit_base
)
3195 this_opc_fu_ok
= FALSE
;
3196 if (func_unit_side
== 1
3197 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_B_ONLY
))
3198 this_opc_fu_ok
= FALSE
;
3200 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_NO_CROSS
))
3201 this_opc_fu_ok
= FALSE
;
3202 if (!func_unit_data_side
3203 && (tic6x_opcode_table
[opc
->id
].flags
3204 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
3205 this_opc_fu_ok
= FALSE
;
3206 if (func_unit_data_side
3207 && !(tic6x_opcode_table
[opc
->id
].flags
3208 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
3209 this_opc_fu_ok
= FALSE
;
3210 if (func_unit_data_side
== 1
3211 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_T2_ONLY
))
3212 this_opc_fu_ok
= FALSE
;
3213 if (this_opc_arch_ok
)
3214 ok_this_arch
= TRUE
;
3217 if (!this_opc_arch_ok
|| !this_opc_fu_ok
)
3219 ok_this_arch_fu
= TRUE
;
3220 opcm
[num_matching_opcodes
] = opc
->id
;
3221 num_matching_opcodes
++;
3222 num_operands
= tic6x_opcode_table
[opc
->id
].num_operands
;
3224 if (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SPMASK
)
3226 if (num_operands
!= 1
3227 || (tic6x_opcode_table
[opc
->id
].operand_info
[0].form
3228 != tic6x_operand_func_unit
))
3231 for (i
= 0; i
< num_operands
; i
++)
3234 |= tic6x_coarse_operand_form (tic6x_operand_func_unit
);
3235 num_operands_permitted
[i
] = TRUE
;
3240 for (i
= 0; i
< num_operands
; i
++)
3242 tic6x_operand_form f
3243 = tic6x_opcode_table
[opc
->id
].operand_info
[i
].form
;
3245 operand_forms
[i
] |= tic6x_coarse_operand_form (f
);
3248 num_operands_permitted
[num_operands
] = TRUE
;
3249 if (num_operands
> max_num_operands
)
3250 max_num_operands
= num_operands
;
3255 as_bad (_("'%.*s' instruction not supported on this architecture"),
3263 as_bad (_("'%.*s' instruction not supported on this functional unit"),
3269 if (!ok_this_arch_fu
)
3271 as_bad (_("'%.*s' instruction not supported on this functional unit"
3272 " for this architecture"),
3278 /* If there were no instructions matching the above availability
3279 checks, we should now have given an error and returned. */
3280 if (num_matching_opcodes
== 0)
3283 num_operands_read
= 0;
3286 skip_whitespace (p
);
3287 if (is_end_of_line
[(unsigned char) *p
])
3289 if (num_operands_read
> 0)
3291 as_bad (_("missing operand after comma"));
3292 bad_operands
= TRUE
;
3297 if (max_num_operands
== 0)
3299 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
3300 bad_operands
= TRUE
;
3304 if (!tic6x_parse_operand (&p
, &operands
[num_operands_read
],
3305 operand_forms
[num_operands_read
], str
, opc_len
,
3306 num_operands_read
+ 1))
3307 bad_operands
= TRUE
;
3308 num_operands_read
++;
3310 if (is_end_of_line
[(unsigned char) *p
])
3315 if (num_operands_read
== max_num_operands
)
3317 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
3318 bad_operands
= TRUE
;
3324 /* Operand parsing should consume whole operands. */
3328 if (!bad_operands
&& !num_operands_permitted
[num_operands_read
])
3330 as_bad (_("bad number of operands to '%.*s'"), opc_len
, str
);
3331 bad_operands
= TRUE
;
3336 /* Each operand is of the right syntactic form for some opcode
3337 choice, and the number of operands is valid. Check that each
3338 operand is OK in detail for some opcode choice with the right
3339 number of operands. */
3342 for (i
= 0; i
< num_operands_read
; i
++)
3344 bfd_boolean coarse_ok
= FALSE
;
3345 bfd_boolean fine_ok
= FALSE
;
3346 tic6x_operand_match fine_failure
= tic6x_match_matches
;
3349 for (j
= 0; j
< num_matching_opcodes
; j
++)
3351 tic6x_operand_form f
;
3354 tic6x_operand_match this_fine_failure
;
3356 if (tic6x_opcode_table
[opcm
[j
]].flags
& TIC6X_FLAG_SPMASK
)
3358 f
= tic6x_operand_func_unit
;
3363 if (tic6x_opcode_table
[opcm
[j
]].num_operands
3364 != num_operands_read
)
3367 f
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].form
;
3368 rw
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].rw
;
3370 cf
= tic6x_coarse_operand_form (f
);
3372 if (operands
[i
].form
!= cf
)
3377 = tic6x_operand_matches_form (&operands
[i
], f
, rw
,
3380 func_unit_data_side
);
3381 if (this_fine_failure
== tic6x_match_matches
)
3386 if (fine_failure
== tic6x_match_matches
3387 || fine_failure
> this_fine_failure
)
3388 fine_failure
= this_fine_failure
;
3391 /* No instructions should have operand syntactic forms only
3392 acceptable with certain numbers of operands, so no
3393 diagnostic for this case. */
3399 switch (fine_failure
)
3401 case tic6x_match_non_const
:
3402 as_bad (_("operand %u of '%.*s' not constant"),
3403 i
+ 1, opc_len
, str
);
3406 case tic6x_match_wrong_side
:
3407 as_bad (_("operand %u of '%.*s' on wrong side"),
3408 i
+ 1, opc_len
, str
);
3411 case tic6x_match_bad_return
:
3412 as_bad (_("operand %u of '%.*s' not a valid return "
3413 "address register"),
3414 i
+ 1, opc_len
, str
);
3417 case tic6x_match_ctrl_write_only
:
3418 as_bad (_("operand %u of '%.*s' is write-only"),
3419 i
+ 1, opc_len
, str
);
3422 case tic6x_match_ctrl_read_only
:
3423 as_bad (_("operand %u of '%.*s' is read-only"),
3424 i
+ 1, opc_len
, str
);
3427 case tic6x_match_bad_mem
:
3428 as_bad (_("operand %u of '%.*s' not a valid memory "
3430 i
+ 1, opc_len
, str
);
3433 case tic6x_match_bad_address
:
3434 as_bad (_("operand %u of '%.*s' not a valid base "
3435 "address register"),
3436 i
+ 1, opc_len
, str
);
3442 bad_operands
= TRUE
;
3450 /* Each operand is OK for some opcode choice, and the number of
3451 operands is valid. Check whether there is an opcode choice
3452 for which all operands are simultaneously valid. */
3454 bfd_boolean found_match
= FALSE
;
3456 for (i
= 0; i
< TIC6X_NUM_PREFER
; i
++)
3457 opc_rank
[i
] = (unsigned int) -1;
3459 min_rank
= TIC6X_NUM_PREFER
- 1;
3462 for (i
= 0; i
< num_matching_opcodes
; i
++)
3465 bfd_boolean this_matches
= TRUE
;
3467 if (!(tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3468 && tic6x_opcode_table
[opcm
[i
]].num_operands
!= num_operands_read
)
3471 for (j
= 0; j
< num_operands_read
; j
++)
3473 tic6x_operand_form f
;
3476 if (tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3478 f
= tic6x_operand_func_unit
;
3483 f
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].form
;
3484 rw
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].rw
;
3486 if (tic6x_operand_matches_form (&operands
[j
], f
, rw
,
3489 func_unit_data_side
)
3490 != tic6x_match_matches
)
3492 this_matches
= FALSE
;
3499 int rank
= TIC6X_PREFER_VAL (tic6x_opcode_table
[opcm
[i
]].flags
);
3501 if (rank
< min_rank
)
3503 if (rank
> max_rank
)
3506 if (opc_rank
[rank
] == (unsigned int) -1)
3509 /* The opcode table should provide a total ordering
3510 for all cases where multiple matches may get
3520 as_bad (_("bad operand combination for '%.*s'"), opc_len
, str
);
3521 bad_operands
= TRUE
;
3533 for (try_rank
= max_rank
; try_rank
>= min_rank
; try_rank
--)
3537 if (opc_rank
[try_rank
] == (unsigned int) -1)
3540 opcode_value
= tic6x_try_encode (opcm
[opc_rank
[try_rank
]], operands
,
3541 num_operands_read
, this_line_creg
,
3542 this_line_z
, func_unit_side
,
3543 func_unit_cross
, func_unit_data_side
,
3544 seginfo
->tc_segment_info_data
.sploop_ii
,
3545 &fix_exp
, &fix_pcrel
, &fx_r_type
,
3546 &fix_adda
, &fix_needed
, &encoded_ok
,
3547 (try_rank
== min_rank
? TRUE
: FALSE
),
3551 opct
= &tic6x_opcode_table
[opcm
[opc_rank
[try_rank
]]];
3561 if (this_line_parallel
)
3563 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
;
3564 if (insn_frag
== NULL
)
3566 as_bad (_("parallel instruction not following another instruction"));
3570 if (insn_frag
->fr_fix
>= 32)
3572 as_bad (_("too many instructions in execute packet"));
3576 if (this_insn_label_list
!= NULL
)
3577 as_bad (_("label not at start of execute packet"));
3579 if (opct
->flags
& TIC6X_FLAG_FIRST
)
3580 as_bad (_("'%.*s' instruction not at start of execute packet"),
3583 *seginfo
->tc_segment_info_data
.last_insn_lsb
|= 0x1;
3584 output
= insn_frag
->fr_literal
+ insn_frag
->fr_fix
;
3588 tic6x_label_list
*l
;
3590 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
3591 seginfo
->tc_segment_info_data
.func_units_used
= 0;
3593 /* Start a new frag for this execute packet. */
3594 if (frag_now_fix () != 0)
3596 if (frag_now
->fr_type
!= rs_machine_dependent
)
3597 frag_wane (frag_now
);
3602 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
= frag_now
;
3603 for (l
= this_insn_label_list
; l
; l
= l
->next
)
3605 symbol_set_frag (l
->label
, frag_now
);
3606 S_SET_VALUE (l
->label
, 0);
3607 S_SET_SEGMENT (l
->label
, now_seg
);
3609 tic6x_free_label_list (this_insn_label_list
);
3610 dwarf2_emit_insn (0);
3611 output
= frag_var (rs_machine_dependent
, 32, 32, 0, NULL
, 0, NULL
);
3612 /* This must be the same as the frag to which a pointer was just
3614 if (output
!= insn_frag
->fr_literal
)
3616 insn_frag
->tc_frag_data
.is_insns
= TRUE
;
3617 insn_frag
->tc_frag_data
.can_cross_fp_boundary
3618 = tic6x_can_cross_fp_boundary
;
3621 if (func_unit_base
!= tic6x_func_unit_nfu
)
3623 unsigned int func_unit_enc
;
3625 func_unit_enc
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3627 if (seginfo
->tc_segment_info_data
.func_units_used
& func_unit_enc
)
3628 as_bad (_("functional unit already used in this execute packet"));
3630 seginfo
->tc_segment_info_data
.func_units_used
|= func_unit_enc
;
3633 if (opct
->flags
& TIC6X_FLAG_SPLOOP
)
3635 if (seginfo
->tc_segment_info_data
.sploop_ii
)
3636 as_bad (_("nested software pipelined loop"));
3637 if (num_operands_read
!= 1
3638 || operands
[0].form
!= TIC6X_OP_EXP
3639 || operands
[0].value
.exp
.X_op
!= O_constant
)
3641 seginfo
->tc_segment_info_data
.sploop_ii
3642 = operands
[0].value
.exp
.X_add_number
;
3644 else if (opct
->flags
& TIC6X_FLAG_SPKERNEL
)
3646 if (!seginfo
->tc_segment_info_data
.sploop_ii
)
3647 as_bad (_("'%.*s' instruction not in a software pipelined loop"),
3649 seginfo
->tc_segment_info_data
.sploop_ii
= 0;
3652 if (this_line_spmask
)
3654 if (seginfo
->tc_segment_info_data
.spmask_addr
== NULL
)
3655 as_bad (_("'||^' without previous SPMASK"));
3656 else if (func_unit_base
== tic6x_func_unit_nfu
)
3657 as_bad (_("cannot mask instruction using no functional unit"));
3660 unsigned int spmask_opcode
;
3661 unsigned int mask_bit
;
3664 = md_chars_to_number (seginfo
->tc_segment_info_data
.spmask_addr
,
3666 mask_bit
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3668 if (spmask_opcode
& mask_bit
)
3669 as_bad (_("functional unit already masked"));
3670 spmask_opcode
|= mask_bit
;
3671 md_number_to_chars (seginfo
->tc_segment_info_data
.spmask_addr
,
3676 record_alignment (now_seg
, 5);
3677 md_number_to_chars (output
, opcode_value
, 4);
3679 tic6x_fix_new_exp (insn_frag
, output
- insn_frag
->fr_literal
, 4, fix_exp
,
3680 fix_pcrel
, fx_r_type
, fix_adda
);
3681 insn_frag
->fr_fix
+= 4;
3682 insn_frag
->fr_var
-= 4;
3683 seginfo
->tc_segment_info_data
.last_insn_lsb
3684 = (target_big_endian
? output
+ 3 : output
);
3685 if (opct
->flags
& TIC6X_FLAG_SPMASK
)
3686 seginfo
->tc_segment_info_data
.spmask_addr
= output
;
3689 /* Modify NEWVAL (32-bit) by inserting VALUE, shifted right by SHIFT
3690 and the least significant BITS bits taken, at position POS. */
3691 #define MODIFY_VALUE(NEWVAL, VALUE, SHIFT, POS, BITS) \
3693 (NEWVAL) &= 0xffffffffU & ~(((1U << (BITS)) - 1) << (POS)); \
3694 (NEWVAL) |= (((VALUE) >> (SHIFT)) & ((1U << (BITS)) - 1)) << (POS); \
3697 /* Apply a fixup to the object file. */
3700 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3702 offsetT value
= *valP
;
3703 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3705 value
= SEXT (value
);
3708 fixP
->fx_offset
= SEXT (fixP
->fx_offset
);
3710 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3713 /* We do our own overflow checks. */
3714 fixP
->fx_no_overflow
= 1;
3716 switch (fixP
->fx_r_type
)
3718 case BFD_RELOC_NONE
:
3719 case BFD_RELOC_C6000_EHTYPE
:
3720 /* Force output to the object file. */
3725 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3726 md_number_to_chars (buf
, value
, 4);
3730 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3732 if (value
< -0x8000 || value
> 0xffff)
3733 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3734 _("value too large for 2-byte field"));
3735 md_number_to_chars (buf
, value
, 2);
3740 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3742 if (value
< -0x80 || value
> 0xff)
3743 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3744 _("value too large for 1-byte field"));
3745 md_number_to_chars (buf
, value
, 1);
3749 case BFD_RELOC_C6000_ABS_S16
:
3750 case BFD_RELOC_C6000_ABS_L16
:
3751 case BFD_RELOC_C6000_SBR_S16
:
3752 case BFD_RELOC_C6000_SBR_L16_B
:
3753 case BFD_RELOC_C6000_SBR_L16_H
:
3754 case BFD_RELOC_C6000_SBR_L16_W
:
3755 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3756 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3758 offsetT newval
= md_chars_to_number (buf
, 4);
3761 switch (fixP
->fx_r_type
)
3763 case BFD_RELOC_C6000_SBR_L16_H
:
3767 case BFD_RELOC_C6000_SBR_L16_W
:
3768 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3777 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3778 if ((value
< -0x8000 || value
> 0x7fff)
3779 && (fixP
->fx_r_type
== BFD_RELOC_C6000_ABS_S16
3780 || fixP
->fx_r_type
== BFD_RELOC_C6000_SBR_S16
))
3781 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3782 _("immediate offset out of range"));
3784 md_number_to_chars (buf
, newval
, 4);
3787 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_S16
3788 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_L16
)
3792 case BFD_RELOC_C6000_ABS_H16
:
3793 case BFD_RELOC_C6000_SBR_H16_B
:
3794 case BFD_RELOC_C6000_SBR_H16_H
:
3795 case BFD_RELOC_C6000_SBR_H16_W
:
3796 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3797 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3799 offsetT newval
= md_chars_to_number (buf
, 4);
3802 switch (fixP
->fx_r_type
)
3804 case BFD_RELOC_C6000_SBR_H16_H
:
3808 case BFD_RELOC_C6000_SBR_H16_W
:
3809 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3818 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3820 md_number_to_chars (buf
, newval
, 4);
3822 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_H16
)
3826 case BFD_RELOC_C6000_SBR_U15_B
:
3827 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3829 offsetT newval
= md_chars_to_number (buf
, 4);
3831 MODIFY_VALUE (newval
, value
, 0, 8, 15);
3832 if (value
< 0 || value
> 0x7fff)
3833 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3834 _("immediate offset out of range"));
3836 md_number_to_chars (buf
, newval
, 4);
3840 case BFD_RELOC_C6000_SBR_U15_H
:
3841 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3843 offsetT newval
= md_chars_to_number (buf
, 4);
3845 /* Constant ADDA operands, processed as constant when the
3846 instruction is parsed, are encoded as-is rather than
3847 shifted. If the operand of an ADDA instruction is now
3848 constant (for example, the difference between two labels
3849 found after the instruction), ensure it is encoded the
3850 same way it would have been if the constant value had
3851 been known when the instruction was parsed. */
3852 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3855 MODIFY_VALUE (newval
, value
, 1, 8, 15);
3857 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3858 _("immediate offset not 2-byte-aligned"));
3859 if (value
< 0 || value
> 0xfffe)
3860 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3861 _("immediate offset out of range"));
3863 md_number_to_chars (buf
, newval
, 4);
3867 case BFD_RELOC_C6000_SBR_U15_W
:
3868 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
3869 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3871 offsetT newval
= md_chars_to_number (buf
, 4);
3873 /* Constant ADDA operands, processed as constant when the
3874 instruction is parsed, are encoded as-is rather than
3875 shifted. If the operand of an ADDA instruction is now
3876 constant (for example, the difference between two labels
3877 found after the instruction), ensure it is encoded the
3878 same way it would have been if the constant value had
3879 been known when the instruction was parsed. */
3880 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3883 MODIFY_VALUE (newval
, value
, 2, 8, 15);
3885 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3886 _("immediate offset not 4-byte-aligned"));
3887 if (value
< 0 || value
> 0x1fffc)
3888 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3889 _("immediate offset out of range"));
3891 md_number_to_chars (buf
, newval
, 4);
3893 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_SBR_U15_W
)
3897 case BFD_RELOC_C6000_DSBT_INDEX
:
3899 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3900 _("addend used with $DSBT_INDEX"));
3905 case BFD_RELOC_C6000_PCR_S21
:
3906 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3908 offsetT newval
= md_chars_to_number (buf
, 4);
3910 MODIFY_VALUE (newval
, value
, 2, 7, 21);
3913 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3914 _("PC-relative offset not 4-byte-aligned"));
3915 if (value
< -0x400000 || value
> 0x3ffffc)
3916 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3917 _("PC-relative offset out of range"));
3919 md_number_to_chars (buf
, newval
, 4);
3923 case BFD_RELOC_C6000_PCR_S12
:
3924 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3926 offsetT newval
= md_chars_to_number (buf
, 4);
3928 MODIFY_VALUE (newval
, value
, 2, 16, 12);
3931 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3932 _("PC-relative offset not 4-byte-aligned"));
3933 if (value
< -0x2000 || value
> 0x1ffc)
3934 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3935 _("PC-relative offset out of range"));
3937 md_number_to_chars (buf
, newval
, 4);
3941 case BFD_RELOC_C6000_PCR_S10
:
3942 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3944 offsetT newval
= md_chars_to_number (buf
, 4);
3946 MODIFY_VALUE (newval
, value
, 2, 13, 10);
3949 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3950 _("PC-relative offset not 4-byte-aligned"));
3951 if (value
< -0x800 || value
> 0x7fc)
3952 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3953 _("PC-relative offset out of range"));
3955 md_number_to_chars (buf
, newval
, 4);
3959 case BFD_RELOC_C6000_PCR_S7
:
3960 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3962 offsetT newval
= md_chars_to_number (buf
, 4);
3964 MODIFY_VALUE (newval
, value
, 2, 16, 7);
3967 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3968 _("PC-relative offset not 4-byte-aligned"));
3969 if (value
< -0x100 || value
> 0xfc)
3970 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3971 _("PC-relative offset out of range"));
3973 md_number_to_chars (buf
, newval
, 4);
3977 case BFD_RELOC_C6000_PREL31
:
3978 /* Force output to the object file. */
3987 /* Convert a floating-point number to target (IEEE) format. */
3990 md_atof (int type
, char *litP
, int *sizeP
)
3992 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
3995 /* Adjust the frags in SECTION (see tic6x_end). */
3998 tic6x_adjust_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT section
,
3999 void *dummy ATTRIBUTE_UNUSED
)
4001 segment_info_type
*info
;
4004 bfd_boolean have_code
= FALSE
;
4005 bfd_boolean have_non_code
= FALSE
;
4007 info
= seg_info (section
);
4011 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4012 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4013 switch (fragp
->fr_type
)
4015 case rs_machine_dependent
:
4016 if (fragp
->tc_frag_data
.is_insns
)
4022 if (fragp
->fr_fix
> 0)
4023 have_non_code
= TRUE
;
4027 have_non_code
= TRUE
;
4031 /* Process alignment requirements in a code-only section. */
4032 if (have_code
&& !have_non_code
)
4034 /* If we need to insert an odd number of instructions to meet an
4035 alignment requirement, there must have been an odd number of
4036 instructions since the last 8-byte-aligned execute packet
4037 boundary. So there must have been an execute packet with an
4038 odd number (and so a number fewer than 8) of instructions
4039 into which we can insert a NOP without breaking any previous
4042 If then we need to insert a number 2 mod 4 of instructions,
4043 the number of instructions since the last 16-byte-aligned
4044 execute packet boundary must be 2 mod 4. So between that
4045 boundary and the following 8-byte-aligned boundary there must
4046 either be at least one execute packet with 2-mod-4
4047 instructions, or at least two with an odd number of
4048 instructions; again, greedily inserting NOPs as soon as
4049 possible suffices to meet the alignment requirement.
4051 If then we need to insert 4 instructions, we look between the
4052 last 32-byte-aligned boundary and the following
4053 16-byte-aligned boundary. The sizes of the execute packets
4054 in this range total 4 instructions mod 8, so again there is
4055 room for greedy insertion of NOPs to meet the alignment
4056 requirement, and before any intermediate point with 8-byte
4057 (2-instruction) alignment requirement the sizes of execute
4058 packets (and so the room for NOPs) will total 2 instructions
4059 mod 4 so greedy insertion will not break such alignments.
4061 So we can always meet these alignment requirements by
4062 inserting NOPs in parallel with existing execute packets, and
4063 by induction the approach described above inserts the minimum
4064 number of such NOPs. */
4066 /* The number of NOPs we are currently looking to insert, if we
4067 have gone back to insert NOPs. */
4068 unsigned int want_insert
= 0;
4070 /* Out of that number, the number inserted so far in the current
4071 stage of the above algorithm. */
4072 unsigned int want_insert_done_so_far
= 0;
4074 /* The position mod 32 at the start of the current frag. */
4075 unsigned int pos
= 0;
4077 /* The locations in the frag chain of the most recent frags at
4078 the start of which there is the given alignment. */
4079 frchainS
*frchp_last32
, *frchp_last16
, *frchp_last8
;
4080 fragS
*fragp_last32
, *fragp_last16
, *fragp_last8
;
4081 unsigned int pos_last32
, pos_last16
, pos_last8
;
4083 frchp_last32
= frchp_last16
= frchp_last8
= info
->frchainP
;
4084 fragp_last32
= fragp_last16
= fragp_last8
= info
->frchainP
->frch_root
;
4085 pos_last32
= pos_last16
= pos_last8
= 0;
4087 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4088 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4091 bfd_boolean go_back
= FALSE
;
4092 frchainS
*frchp_next
;
4095 if (fragp
->fr_type
!= rs_machine_dependent
)
4098 if (fragp
->tc_frag_data
.is_insns
4099 && pos
+ fragp
->fr_fix
> 32
4100 && !fragp
->tc_frag_data
.can_cross_fp_boundary
)
4102 /* As described above, we should always have met an
4103 alignment requirement by the time we come back to
4110 want_insert
= (32 - pos
) >> 2;
4111 if (want_insert
> 7)
4113 want_insert_done_so_far
= 0;
4117 if (!fragp
->tc_frag_data
.is_insns
)
4119 unsigned int would_insert_bytes
;
4121 if (!(pos
& ((1 << fragp
->fr_offset
) - 1)))
4122 /* This alignment requirement is already met. */
4125 /* As described above, we should always have met an
4126 alignment requirement by the time we come back to
4131 /* We may not be able to meet this requirement within
4132 the given number of characters. */
4134 = ((1 << fragp
->fr_offset
)
4135 - (pos
& ((1 << fragp
->fr_offset
) - 1)));
4137 if (fragp
->fr_subtype
!= 0
4138 && would_insert_bytes
> fragp
->fr_subtype
)
4141 /* An unmet alignment must be 8, 16 or 32 bytes;
4142 smaller ones must always be met within code-only
4143 sections and larger ones cause the section not to
4145 if (fragp
->fr_offset
!= 3
4146 && fragp
->fr_offset
!= 4
4147 && fragp
->fr_offset
!= 5)
4150 if (would_insert_bytes
& 3)
4152 want_insert
= would_insert_bytes
>> 2;
4153 if (want_insert
> 7)
4155 want_insert_done_so_far
= 0;
4158 else if (want_insert
&& !go_back
)
4160 unsigned int num_insns
= fragp
->fr_fix
>> 2;
4161 unsigned int max_poss_nops
= 8 - num_insns
;
4165 unsigned int cur_want_nops
, max_want_nops
, do_nops
, i
;
4167 if (want_insert
& 1)
4169 else if (want_insert
& 2)
4171 else if (want_insert
& 4)
4176 max_want_nops
= cur_want_nops
- want_insert_done_so_far
;
4178 do_nops
= (max_poss_nops
< max_want_nops
4181 for (i
= 0; i
< do_nops
; i
++)
4183 md_number_to_chars (fragp
->fr_literal
+ fragp
->fr_fix
,
4185 if (target_big_endian
)
4186 fragp
->fr_literal
[fragp
->fr_fix
- 1] |= 0x1;
4188 fragp
->fr_literal
[fragp
->fr_fix
- 4] |= 0x1;
4192 want_insert_done_so_far
+= do_nops
;
4193 if (want_insert_done_so_far
== cur_want_nops
)
4195 want_insert
-= want_insert_done_so_far
;
4196 want_insert_done_so_far
= 0;
4204 if (want_insert
& 1)
4206 frchp
= frchp_last8
;
4207 fragp
= fragp_last8
;
4210 else if (want_insert
& 2)
4212 frchp
= frchp_last8
= frchp_last16
;
4213 fragp
= fragp_last8
= fragp_last16
;
4214 pos
= pos_last8
= pos_last16
;
4216 else if (want_insert
& 4)
4218 frchp
= frchp_last8
= frchp_last16
= frchp_last32
;
4219 fragp
= fragp_last8
= fragp_last16
= fragp_last32
;
4220 pos
= pos_last8
= pos_last16
= pos_last32
;
4228 /* Update current position for moving past a code
4230 pos
+= fragp
->fr_fix
;
4233 fragp_next
= fragp
->fr_next
;
4234 if (fragp_next
== NULL
)
4236 frchp_next
= frchp
->frch_next
;
4237 if (frchp_next
!= NULL
)
4238 fragp_next
= frchp_next
->frch_root
;
4242 frchp_last8
= frchp_next
;
4243 fragp_last8
= fragp_next
;
4248 frchp_last16
= frchp_next
;
4249 fragp_last16
= fragp_next
;
4254 frchp_last32
= frchp_next
;
4255 fragp_last32
= fragp_next
;
4261 /* Now convert the machine-dependent frags to machine-independent
4263 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
4264 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
4266 if (fragp
->fr_type
== rs_machine_dependent
)
4268 if (fragp
->tc_frag_data
.is_insns
)
4272 fragp
->fr_type
= rs_align_code
;
4274 *fragp
->fr_literal
= 0;
4280 /* Initialize the machine-dependent parts of a frag. */
4283 tic6x_frag_init (fragS
*fragp
)
4285 fragp
->tc_frag_data
.is_insns
= FALSE
;
4286 fragp
->tc_frag_data
.can_cross_fp_boundary
= FALSE
;
4289 /* Set an attribute if it has not already been set by the user. */
4292 tic6x_set_attribute_int (int tag
, int value
)
4295 || tag
>= NUM_KNOWN_OBJ_ATTRIBUTES
)
4297 if (!tic6x_attributes_set_explicitly
[tag
])
4298 bfd_elf_add_proc_attr_int (stdoutput
, tag
, value
);
4301 /* Set object attributes deduced from the input file and command line
4302 rather than given explicitly. */
4304 tic6x_set_attributes (void)
4306 if (tic6x_arch_attribute
== C6XABI_Tag_ISA_none
)
4307 tic6x_arch_attribute
= C6XABI_Tag_ISA_C674X
;
4309 tic6x_set_attribute_int (Tag_ISA
, tic6x_arch_attribute
);
4310 tic6x_set_attribute_int (Tag_ABI_DSBT
, tic6x_dsbt
);
4311 tic6x_set_attribute_int (Tag_ABI_PID
, tic6x_pid
);
4312 tic6x_set_attribute_int (Tag_ABI_PIC
, tic6x_pic
);
4315 /* Do machine-dependent manipulations of the frag chains after all
4316 input has been read and before the machine-independent sizing and
4322 /* Set object attributes at this point if not explicitly set. */
4323 tic6x_set_attributes ();
4325 /* Meeting alignment requirements may require inserting NOPs in
4326 parallel in execute packets earlier in the segment. Future
4327 16-bit instruction generation involves whole-segment optimization
4328 to determine the best choice and ordering of 32-bit or 16-bit
4329 instructions. This doesn't fit will in the general relaxation
4330 framework, so handle alignment and 16-bit instruction generation
4332 bfd_map_over_sections (stdoutput
, tic6x_adjust_section
, NULL
);
4335 /* No machine-dependent frags at this stage; all converted in
4339 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec ATTRIBUTE_UNUSED
,
4340 fragS
*fragp ATTRIBUTE_UNUSED
)
4345 /* No machine-dependent frags at this stage; all converted in
4349 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
4350 segT seg ATTRIBUTE_UNUSED
)
4355 /* Put a number into target byte order. */
4358 md_number_to_chars (char *buf
, valueT val
, int n
)
4360 if (target_big_endian
)
4361 number_to_chars_bigendian (buf
, val
, n
);
4363 number_to_chars_littleendian (buf
, val
, n
);
4366 /* Machine-dependent operand parsing not currently needed. */
4369 md_operand (expressionS
*op ATTRIBUTE_UNUSED
)
4373 /* PC-relative operands are relative to the start of the fetch
4377 tic6x_pcrel_from_section (fixS
*fixp
, segT sec
)
4379 if (fixp
->fx_addsy
!= NULL
4380 && (!S_IS_DEFINED (fixp
->fx_addsy
)
4381 || S_GET_SEGMENT (fixp
->fx_addsy
) != sec
))
4383 return (fixp
->fx_where
+ fixp
->fx_frag
->fr_address
) & ~(long) 0x1f;
4386 /* Round up a section size to the appropriate boundary. */
4389 md_section_align (segT segment ATTRIBUTE_UNUSED
,
4392 /* Round up section sizes to ensure that text sections consist of
4393 whole fetch packets. */
4394 int align
= bfd_get_section_alignment (stdoutput
, segment
);
4395 return ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
4398 /* No special undefined symbol handling needed for now. */
4401 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
4406 /* Translate internal representation of relocation info to BFD target
4410 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
4414 bfd_reloc_code_real_type r_type
;
4416 reloc
= xmalloc (sizeof (arelent
));
4417 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
4418 symbol
= symbol_get_bfdsym (fixp
->fx_addsy
);
4419 *reloc
->sym_ptr_ptr
= symbol
;
4420 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4421 reloc
->addend
= (tic6x_generate_rela
? fixp
->fx_offset
: 0);
4422 r_type
= fixp
->fx_r_type
;
4423 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
4425 if (reloc
->howto
== NULL
)
4427 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4428 _("Cannot represent relocation type %s"),
4429 bfd_get_reloc_code_name (r_type
));
4433 /* Correct for adjustments bfd_install_relocation will make. */
4434 if (reloc
->howto
->pcrel_offset
&& reloc
->howto
->partial_inplace
)
4436 reloc
->addend
+= reloc
->address
;
4437 if (!bfd_is_com_section (symbol
))
4438 reloc
->addend
-= symbol
->value
;
4444 /* Convert REGNAME to a DWARF-2 register number. */
4447 tic6x_regname_to_dw2regnum (char *regname
)
4453 reg_ok
= tic6x_parse_register (&rq
, ®
);
4460 case 1: /* A regs. */
4463 else if (reg
.num
< 32)
4464 return (reg
.num
- 16) + 37;
4468 case 2: /* B regs. */
4470 return reg
.num
+ 16;
4471 else if (reg
.num
< 32)
4472 return (reg
.num
- 16) + 53;
4481 /* Initialize the DWARF-2 unwind information for this procedure. */
4484 tic6x_frame_initial_instructions (void)
4486 /* CFA is initial stack pointer (B15). */
4487 cfi_add_CFA_def_cfa (31, 0);
4490 /* Start an exception table entry. If idx is nonzero this is an index table
4494 tic6x_start_unwind_section (const segT text_seg
, int idx
)
4496 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4497 const char * text_name
;
4498 const char * prefix
;
4499 const char * prefix_once
;
4500 const char * group_name
;
4504 size_t sec_name_len
;
4511 prefix
= ELF_STRING_C6000_unwind
;
4512 prefix_once
= ELF_STRING_C6000_unwind_once
;
4513 type
= SHT_C6000_UNWIND
;
4517 prefix
= ELF_STRING_C6000_unwind_info
;
4518 prefix_once
= ELF_STRING_C6000_unwind_info_once
;
4519 type
= SHT_PROGBITS
;
4522 text_name
= segment_name (text_seg
);
4523 if (streq (text_name
, ".text"))
4526 if (strncmp (text_name
, ".gnu.linkonce.t.",
4527 strlen (".gnu.linkonce.t.")) == 0)
4529 prefix
= prefix_once
;
4530 text_name
+= strlen (".gnu.linkonce.t.");
4533 prefix_len
= strlen (prefix
);
4534 text_len
= strlen (text_name
);
4535 sec_name_len
= prefix_len
+ text_len
;
4536 sec_name
= (char *) xmalloc (sec_name_len
+ 1);
4537 memcpy (sec_name
, prefix
, prefix_len
);
4538 memcpy (sec_name
+ prefix_len
, text_name
, text_len
);
4539 sec_name
[prefix_len
+ text_len
] = '\0';
4545 /* Handle COMDAT group. */
4546 if (prefix
!= prefix_once
&& (text_seg
->flags
& SEC_LINK_ONCE
) != 0)
4548 group_name
= elf_group_name (text_seg
);
4549 if (group_name
== NULL
)
4551 as_bad (_("group section `%s' has no group signature"),
4552 segment_name (text_seg
));
4553 ignore_rest_of_line ();
4560 obj_elf_change_section (sec_name
, type
, flags
, 0, group_name
, linkonce
, 0);
4562 /* Set the section link for index tables. */
4564 elf_linked_to_section (now_seg
) = text_seg
;
4566 seg_info (now_seg
)->tc_segment_info_data
.text_unwind
= unwind
;
4571 tic6x_unwind_frame_regs
[TIC6X_NUM_UNWIND_REGS
] =
4572 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4573 { 15, 31, 30, 29, 28, 27, 26, 19, 14, 13, 12, 11, 10 };
4575 /* Register save offsets for __c6xabi_push_rts. */
4577 tic6x_pop_rts_offset_little
[TIC6X_NUM_UNWIND_REGS
] =
4578 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4579 { -1, 1, 0, -3, -4, -7, -8,-11, -2, -5, -6, -9,-10};
4582 tic6x_pop_rts_offset_big
[TIC6X_NUM_UNWIND_REGS
] =
4583 /* A15 B15 B14 B13 B12 B11 B10 B3 A14 A13 A12 A11 A10. */
4584 { -2, 1, 0, -4, -3, -8, -7,-12, -1, -6, -5,-10, -9};
4586 /* Map from dwarf register number to unwind frame register number. */
4588 tic6x_unwind_reg_from_dwarf (int dwarf
)
4592 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
4594 if (tic6x_unwind_frame_regs
[reg
] == dwarf
)
4601 /* Unwinding bytecode definitions. */
4602 #define UNWIND_OP_ADD_SP 0x00
4603 #define UNWIND_OP_ADD_SP2 0xd2
4604 #define UNWIND_OP2_POP 0x8000
4605 #define UNWIND_OP2_POP_COMPACT 0xa000
4606 #define UNWIND_OP_POP_REG 0xc0
4607 #define UNWIND_OP_MV_FP 0xd0
4608 #define UNWIND_OP_POP_RTS 0xd1
4609 #define UNWIND_OP_RET 0xe0
4611 /* Maximum stack adjustment for __c6xabi_unwind_cpp_pr3/4 */
4612 #define MAX_COMPACT_SP_OFFSET (0x7f << 3)
4615 tic6x_flush_unwind_word (valueT data
)
4617 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4620 /* Create EXTAB entry if it does not exist. */
4621 if (unwind
->table_entry
== NULL
)
4623 tic6x_start_unwind_section (unwind
->saved_seg
, 0);
4624 frag_align (2, 0, 0);
4625 record_alignment (now_seg
, 2);
4626 unwind
->table_entry
= expr_build_dot ();
4627 ptr
= frag_more (4);
4628 unwind
->frag_start
= ptr
;
4632 /* Append additional word of data. */
4633 ptr
= frag_more (4);
4636 md_number_to_chars (ptr
, data
, 4);
4639 /* Add a single byte of unwinding data. */
4642 tic6x_unwind_byte (int byte
)
4644 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4646 unwind
->data_bytes
++;
4647 /* Only flush the first word after we know multiple words are required. */
4648 if (unwind
->data_bytes
== 5)
4650 if (unwind
->personality_index
== -1)
4652 /* At this point we know we are too big for pr0. */
4653 unwind
->personality_index
= 1;
4654 tic6x_flush_unwind_word (0x81000000 | ((unwind
->data
>> 8) & 0xffff));
4655 unwind
->data
= ((unwind
->data
& 0xff) << 8) | byte
;
4656 unwind
->data_bytes
++;
4660 tic6x_flush_unwind_word (unwind
->data
);
4661 unwind
->data
= byte
;
4666 unwind
->data
= (unwind
->data
<< 8) | byte
;
4667 if ((unwind
->data_bytes
& 3) == 0 && unwind
->data_bytes
> 4)
4669 tic6x_flush_unwind_word (unwind
->data
);
4675 /* Add a two-byte unwinding opcode. */
4677 tic6x_unwind_2byte (int bytes
)
4679 tic6x_unwind_byte (bytes
>> 8);
4680 tic6x_unwind_byte (bytes
& 0xff);
4684 tic6x_unwind_uleb (offsetT offset
)
4686 while (offset
> 0x7f)
4688 tic6x_unwind_byte ((offset
& 0x7f) | 0x80);
4691 tic6x_unwind_byte (offset
);
4695 tic6x_cfi_startproc (void)
4697 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4699 unwind
->personality_index
= -1;
4700 unwind
->personality_routine
= NULL
;
4701 if (unwind
->table_entry
)
4702 as_bad (_("missing .endp before .cfi_startproc"));
4704 unwind
->table_entry
= NULL
;
4705 unwind
->data_bytes
= -1;
4709 tic6x_output_exidx_entry (void)
4713 unsigned int marked_pr_dependency
;
4716 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4719 old_subseg
= now_subseg
;
4721 /* Add index table entry. This is two words. */
4722 tic6x_start_unwind_section (unwind
->saved_seg
, 1);
4723 frag_align (2, 0, 0);
4724 record_alignment (now_seg
, 2);
4726 ptr
= frag_more (8);
4727 where
= frag_now_fix () - 8;
4729 /* Self relative offset of the function start. */
4730 fix_new (frag_now
, where
, 4, unwind
->function_start
, 0, 1,
4731 BFD_RELOC_C6000_PREL31
);
4733 /* Indicate dependency on ABI-defined personality routines to the
4734 linker, if it hasn't been done already. */
4735 marked_pr_dependency
4736 = seg_info (now_seg
)->tc_segment_info_data
.marked_pr_dependency
;
4737 if (unwind
->personality_index
>= 0 && unwind
->personality_index
< 5
4738 && !(marked_pr_dependency
& (1 << unwind
->personality_index
)))
4740 static const char *const name
[] =
4742 "__c6xabi_unwind_cpp_pr0",
4743 "__c6xabi_unwind_cpp_pr1",
4744 "__c6xabi_unwind_cpp_pr2",
4745 "__c6xabi_unwind_cpp_pr3",
4746 "__c6xabi_unwind_cpp_pr4"
4748 symbolS
*pr
= symbol_find_or_make (name
[unwind
->personality_index
]);
4749 fix_new (frag_now
, where
, 0, pr
, 0, 1, BFD_RELOC_NONE
);
4750 seg_info (now_seg
)->tc_segment_info_data
.marked_pr_dependency
4751 |= 1 << unwind
->personality_index
;
4754 if (unwind
->table_entry
)
4756 /* Self relative offset of the table entry. */
4757 fix_new (frag_now
, where
+ 4, 4, unwind
->table_entry
, 0, 1,
4758 BFD_RELOC_C6000_PREL31
);
4762 /* Inline exception table entry. */
4763 md_number_to_chars (ptr
+ 4, unwind
->data
, 4);
4766 /* Restore the original section. */
4767 subseg_set (old_seg
, old_subseg
);
4771 tic6x_output_unwinding (bfd_boolean need_extab
)
4773 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4774 unsigned safe_mask
= unwind
->safe_mask
;
4775 unsigned compact_mask
= unwind
->compact_mask
;
4776 unsigned reg_saved_mask
= unwind
->reg_saved_mask
;
4777 offsetT cfa_offset
= unwind
->cfa_offset
;
4781 if (unwind
->personality_index
== -2)
4783 /* Function can not be unwound. */
4785 tic6x_output_exidx_entry ();
4789 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
4791 /* Auto-select a personality routine if none specified. */
4792 if (reg_saved_mask
|| cfa_offset
>= MAX_COMPACT_SP_OFFSET
)
4793 unwind
->personality_index
= -1;
4795 unwind
->personality_index
= 3;
4797 unwind
->personality_index
= 4;
4800 /* Calculate unwinding opcodes, and emit to EXTAB if necessary. */
4801 unwind
->table_entry
= NULL
;
4802 if (unwind
->personality_index
== 3 || unwind
->personality_index
== 4)
4804 if (cfa_offset
>= MAX_COMPACT_SP_OFFSET
)
4806 as_bad (_("stack pointer offset too large for personality routine"));
4810 || (unwind
->personality_index
== 3 && compact_mask
!= 0)
4811 || (unwind
->personality_index
== 4 && safe_mask
!= 0))
4813 as_bad (_("stack frame layout does not match personality routine"));
4817 unwind
->data
= (1u << 31) | (unwind
->personality_index
<< 24);
4818 if (unwind
->cfa_reg
== 15)
4819 unwind
->data
|= 0x7f << 17;
4821 unwind
->data
|= cfa_offset
<< (17 - 3);
4823 if (unwind
->personality_index
== 3)
4824 unwind
->data
|= safe_mask
<< 4;
4826 unwind
->data
|= compact_mask
<< 4;
4827 unwind
->data
|= unwind
->return_reg
;
4828 unwind
->data_bytes
= 4;
4832 if (unwind
->personality_routine
)
4835 unwind
->data_bytes
= 5;
4836 tic6x_flush_unwind_word (0);
4837 /* First word is personality routine. */
4838 where
= frag_now_fix () - 4;
4839 fix_new (frag_now
, where
, 4, unwind
->personality_routine
, 0, 1,
4840 BFD_RELOC_C6000_PREL31
);
4842 else if (unwind
->personality_index
> 0)
4844 unwind
->data
= 0x8000 | (unwind
->personality_index
<< 8);
4845 unwind
->data_bytes
= 2;
4847 else /* pr0 or undecided */
4849 unwind
->data
= 0x80;
4850 unwind
->data_bytes
= 1;
4853 if (unwind
->return_reg
!= UNWIND_B3
)
4855 tic6x_unwind_byte (UNWIND_OP_RET
| unwind
->return_reg
);
4858 if (unwind
->cfa_reg
== 15)
4860 tic6x_unwind_byte (UNWIND_OP_MV_FP
);
4862 else if (cfa_offset
!= 0)
4865 if (cfa_offset
> 0x80)
4867 tic6x_unwind_byte (UNWIND_OP_ADD_SP2
);
4868 tic6x_unwind_uleb (cfa_offset
- 0x81);
4870 else if (cfa_offset
> 0x40)
4872 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| 0x3f);
4873 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| (cfa_offset
- 0x40));
4877 tic6x_unwind_byte (UNWIND_OP_ADD_SP
| (cfa_offset
- 1));
4882 tic6x_unwind_2byte (UNWIND_OP2_POP
| unwind
->safe_mask
);
4883 else if (unwind
->pop_rts
)
4884 tic6x_unwind_byte (UNWIND_OP_POP_RTS
);
4885 else if (compact_mask
)
4886 tic6x_unwind_2byte (UNWIND_OP2_POP_COMPACT
| unwind
->compact_mask
);
4887 else if (reg_saved_mask
)
4893 tic6x_unwind_byte (UNWIND_OP_POP_REG
| unwind
->saved_reg_count
);
4895 for (cur_offset
= 0; unwind
->saved_reg_count
> 0; cur_offset
-= 4)
4898 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
4900 if (!unwind
->reg_saved
[reg
])
4903 if (unwind
->reg_offset
[reg
] == cur_offset
)
4905 unwind
->saved_reg_count
--;
4910 if ((cur_offset
& 4) == 4)
4911 tic6x_unwind_byte ((last_val
<< 4) | val
);
4915 if ((cur_offset
& 4) == 4)
4916 tic6x_unwind_byte ((last_val
<< 4) | 0xf);
4919 /* Pad with RETURN opcodes. */
4920 while ((unwind
->data_bytes
& 3) != 0)
4921 tic6x_unwind_byte (UNWIND_OP_RET
| UNWIND_B3
);
4923 if (unwind
->personality_index
== -1 && unwind
->personality_routine
== NULL
)
4924 unwind
->personality_index
= 0;
4927 /* Force creation of an EXTAB entry if an LSDA is required. */
4928 if (need_extab
&& !unwind
->table_entry
)
4930 if (unwind
->data_bytes
!= 4)
4933 tic6x_flush_unwind_word (unwind
->data
);
4935 else if (unwind
->table_entry
&& !need_extab
)
4937 /* Add an empty descriptor if there is no user-specified data. */
4938 char *ptr
= frag_more (4);
4939 md_number_to_chars (ptr
, 0, 4);
4942 /* Fill in length of unwinding bytecode. */
4943 if (unwind
->table_entry
)
4946 if (unwind
->data_bytes
> 0x400)
4947 as_bad (_("too many unwinding instructions"));
4949 if (unwind
->personality_index
== -1)
4951 tmp
= md_chars_to_number (unwind
->frag_start
+ 4, 4);
4952 tmp
|= ((unwind
->data_bytes
- 8) >> 2) << 24;
4953 md_number_to_chars (unwind
->frag_start
+ 4, tmp
, 4);
4955 else if (unwind
->personality_index
== 1 || unwind
->personality_index
== 2)
4957 tmp
= md_chars_to_number (unwind
->frag_start
, 4);
4958 tmp
|= ((unwind
->data_bytes
- 4) >> 2) << 16;
4959 md_number_to_chars (unwind
->frag_start
, tmp
, 4);
4962 tic6x_output_exidx_entry ();
4965 /* FIXME: This will get horribly confused if cfi directives are emitted for
4966 function epilogue. */
4968 tic6x_cfi_endproc (struct fde_entry
*fde
)
4970 tic6x_unwind_info
*unwind
= tic6x_get_unwind ();
4971 struct cfi_insn_data
*insn
;
4973 unsigned safe_mask
= 0;
4974 unsigned compact_mask
= 0;
4975 unsigned reg_saved_mask
= 0;
4976 offsetT cfa_offset
= 0;
4977 offsetT save_offset
= 0;
4979 unwind
->cfa_reg
= 31;
4980 unwind
->return_reg
= UNWIND_B3
;
4981 unwind
->saved_reg_count
= 0;
4982 unwind
->pop_rts
= FALSE
;
4984 unwind
->saved_seg
= now_seg
;
4985 unwind
->saved_subseg
= now_subseg
;
4987 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
4988 unwind
->reg_saved
[reg
] = FALSE
;
4990 /* Scan FDE instructions to build up stack frame layout. */
4991 for (insn
= fde
->data
; insn
; insn
= insn
->next
)
4995 case DW_CFA_advance_loc
:
4998 case DW_CFA_def_cfa
:
4999 unwind
->cfa_reg
= insn
->u
.ri
.reg
;
5000 cfa_offset
= insn
->u
.ri
.offset
;
5003 case DW_CFA_def_cfa_register
:
5004 unwind
->cfa_reg
= insn
->u
.r
;
5007 case DW_CFA_def_cfa_offset
:
5008 cfa_offset
= insn
->u
.i
;
5011 case DW_CFA_undefined
:
5012 case DW_CFA_same_value
:
5013 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.r
);
5015 unwind
->reg_saved
[reg
] = FALSE
;
5019 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.ri
.reg
);
5022 as_bad (_("unable to generate unwinding opcode for reg %d"),
5026 unwind
->reg_saved
[reg
] = TRUE
;
5027 unwind
->reg_offset
[reg
] = insn
->u
.ri
.offset
;
5028 if (insn
->u
.ri
.reg
== UNWIND_B3
)
5029 unwind
->return_reg
= UNWIND_B3
;
5032 case DW_CFA_register
:
5033 if (insn
->u
.rr
.reg1
!= 19)
5035 as_bad (_("unable to generate unwinding opcode for reg %d"),
5040 reg
= tic6x_unwind_reg_from_dwarf (insn
->u
.rr
.reg2
);
5043 as_bad (_("unable to generate unwinding opcode for reg %d"),
5048 unwind
->return_reg
= reg
;
5049 unwind
->reg_saved
[UNWIND_B3
] = FALSE
;
5050 if (unwind
->reg_saved
[reg
])
5052 as_bad (_("unable to restore return address from "
5053 "previously restored reg"));
5058 case DW_CFA_restore
:
5059 case DW_CFA_remember_state
:
5060 case DW_CFA_restore_state
:
5061 case DW_CFA_GNU_window_save
:
5063 case CFI_val_encoded_addr
:
5064 as_bad (_("unhandled CFA insn for unwinding (%d)"), insn
->insn
);
5072 if (unwind
->cfa_reg
!= 15 && unwind
->cfa_reg
!= 31)
5074 as_bad (_("unable to generate unwinding opcode for frame pointer reg %d"),
5079 if (unwind
->cfa_reg
== 15)
5081 if (cfa_offset
!= 0)
5083 as_bad (_("unable to generate unwinding opcode for "
5084 "frame pointer offset"));
5090 if ((cfa_offset
& 7) != 0)
5092 as_bad (_("unwound stack pointer not doubleword aligned"));
5097 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5099 if (unwind
->reg_saved
[reg
])
5100 reg_saved_mask
|= 1 << (TIC6X_NUM_UNWIND_REGS
- (reg
+ 1));
5103 /* Check for standard "safe debug" frame layout */
5107 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5109 if (!unwind
->reg_saved
[reg
])
5112 if (target_big_endian
5113 && reg
< TIC6X_NUM_UNWIND_REGS
- 1
5114 && unwind
->reg_saved
[reg
+ 1]
5115 && tic6x_unwind_frame_regs
[reg
]
5116 == tic6x_unwind_frame_regs
[reg
+ 1] + 1
5117 && (tic6x_unwind_frame_regs
[reg
] & 1) == 1
5118 && (save_offset
& 4) == 4)
5121 if (save_offset
!= unwind
->reg_offset
[reg
+ 1]
5122 || save_offset
- 4 != unwind
->reg_offset
[reg
])
5129 if (save_offset
!= unwind
->reg_offset
[reg
])
5134 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5136 safe_mask
= reg_saved_mask
;
5141 /* Check for compact frame layout. */
5145 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5149 if (!unwind
->reg_saved
[reg
])
5152 if (reg
< TIC6X_NUM_UNWIND_REGS
- 1)
5156 if (!unwind
->reg_saved
[reg2
]
5157 || tic6x_unwind_frame_regs
[reg
]
5158 != tic6x_unwind_frame_regs
[reg2
] + 1
5159 || (tic6x_unwind_frame_regs
[reg2
] & 1) != 0
5160 || save_offset
== 0)
5169 if (target_big_endian
)
5170 high_offset
= 4; /* lower address = positive stack offset. */
5174 if (save_offset
+ 4 - high_offset
!= unwind
->reg_offset
[reg
]
5175 || save_offset
+ high_offset
!= unwind
->reg_offset
[reg2
])
5183 if (save_offset
!= unwind
->reg_offset
[reg
])
5189 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5191 compact_mask
= reg_saved_mask
;
5196 /* Check for __c6xabi_pop_rts format */
5197 if (reg_saved_mask
== 0x17ff)
5199 const int *pop_rts_offset
= target_big_endian
5200 ? tic6x_pop_rts_offset_big
5201 : tic6x_pop_rts_offset_little
;
5204 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5206 if (reg
== UNWIND_B15
)
5209 if (unwind
->reg_offset
[reg
] != pop_rts_offset
[reg
] * 4)
5213 if (reg
== TIC6X_NUM_UNWIND_REGS
)
5215 unwind
->pop_rts
= TRUE
;
5219 /* If all else fails then describe the frame manually. */
5224 for (reg
= 0; reg
< TIC6X_NUM_UNWIND_REGS
; reg
++)
5226 if (!unwind
->reg_saved
[reg
])
5229 unwind
->saved_reg_count
++;
5230 /* Encoding uses 4 bits per word, so size of unwinding opcode data
5231 limits the save area size. The exact cap will be figured out
5232 later due to overflow, the 0x800 here is just a quick sanity
5233 check to weed out obviously excessive offsets. */
5234 if (unwind
->reg_offset
[reg
] > 0 || unwind
->reg_offset
[reg
] < -0x800
5235 || (unwind
->reg_offset
[reg
] & 3) != 0)
5237 as_bad (_("stack frame layout too complex for unwinder"));
5241 if (unwind
->reg_offset
[reg
] < save_offset
)
5242 save_offset
= unwind
->reg_offset
[reg
] - 4;
5246 /* Align to 8-byte boundary (stack grows towards negative offsets). */
5249 if (unwind
->cfa_reg
== 31 && !reg_saved_mask
)
5251 cfa_offset
+= save_offset
;
5254 as_bad (_("unwound frame has negative size"));
5259 unwind
->safe_mask
= safe_mask
;
5260 unwind
->compact_mask
= compact_mask
;
5261 unwind
->reg_saved_mask
= reg_saved_mask
;
5262 unwind
->cfa_offset
= cfa_offset
;
5263 unwind
->function_start
= fde
->start_address
;