3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "dwarf2dbg.h"
24 #include "safe-ctype.h"
26 #include "opcode/tic6x.h"
27 #include "elf/tic6x.h"
28 #include "elf32-tic6x.h"
30 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit
31 host gives identical results to a 32-bit host. */
32 #define TRUNC(X) ((valueT) (X) & 0xffffffffU)
33 #define SEXT(X) ((TRUNC (X) ^ 0x80000000U) - 0x80000000U)
35 const char comment_chars
[] = ";";
36 const char line_comment_chars
[] = "#*;";
37 const char line_separator_chars
[] = "@";
39 const char EXP_CHARS
[] = "eE";
40 const char FLT_CHARS
[] = "dDfF";
42 const char *md_shortopts
= "";
46 OPTION_MARCH
= OPTION_MD_BASE
,
50 OPTION_MLITTLE_ENDIAN
,
54 struct option md_longopts
[] =
56 { "march", required_argument
, NULL
, OPTION_MARCH
},
57 { "matomic", no_argument
, NULL
, OPTION_MATOMIC
},
58 { "mno-atomic", no_argument
, NULL
, OPTION_MNO_ATOMIC
},
59 { "mbig-endian", no_argument
, NULL
, OPTION_MBIG_ENDIAN
},
60 { "mlittle-endian", no_argument
, NULL
, OPTION_MLITTLE_ENDIAN
},
61 { "mgenerate-rel", no_argument
, NULL
, OPTION_MGENERATE_REL
},
62 { NULL
, no_argument
, NULL
, 0 }
64 size_t md_longopts_size
= sizeof (md_longopts
);
66 /* Whether to enable atomic instructions. 1 to enable them, 0 to
67 disable, -1 to default from architecture. */
68 static int tic6x_atomic
= -1;
70 /* The instructions enabled based only on the selected architecture
71 (all instructions, if no architecture specified). Atomic
72 instructions may be enabled or disabled separately. */
73 static unsigned short tic6x_arch_enable
= (TIC6X_INSN_C62X
81 /* The instructions enabled based on the current set of features
82 (architecture, as modified by other options). */
83 static unsigned short tic6x_features
;
85 /* The architecture attribute value, or C6XABI_Tag_CPU_arch_none if
87 static int tic6x_arch_attribute
= C6XABI_Tag_CPU_arch_none
;
89 /* Whether any instructions at all have been seen. Once any
90 instructions have been seen, architecture attributes merge into the
91 previous attribute value rather than replacing it. */
92 static bfd_boolean tic6x_seen_insns
= FALSE
;
94 /* The number of registers in each register file supported by the
95 current architecture. */
96 static unsigned int tic6x_num_registers
;
98 /* Whether predication on A0 is possible. */
99 static bfd_boolean tic6x_predicate_a0
;
101 /* Whether execute packets can cross fetch packet boundaries. */
102 static bfd_boolean tic6x_can_cross_fp_boundary
;
104 /* Whether there are constraints on simultaneous reads and writes of
106 static bfd_boolean tic6x_long_data_constraints
;
108 /* Whether compact instructions are available. */
109 static bfd_boolean tic6x_compact_insns
;
111 /* Whether to generate RELA relocations. */
112 static bfd_boolean tic6x_generate_rela
= TRUE
;
114 /* Table of supported architecture variants. */
119 unsigned short features
;
121 static const tic6x_arch_table tic6x_arches
[] =
123 { "c62x", C6XABI_Tag_CPU_arch_C62X
, TIC6X_INSN_C62X
},
124 { "c64x", C6XABI_Tag_CPU_arch_C64X
, TIC6X_INSN_C62X
| TIC6X_INSN_C64X
},
125 { "c64x+", C6XABI_Tag_CPU_arch_C64XP
, (TIC6X_INSN_C62X
127 | TIC6X_INSN_C64XP
) },
128 { "c67x", C6XABI_Tag_CPU_arch_C67X
, TIC6X_INSN_C62X
| TIC6X_INSN_C67X
},
129 { "c67x+", C6XABI_Tag_CPU_arch_C67XP
, (TIC6X_INSN_C62X
131 | TIC6X_INSN_C67XP
) },
132 { "c674x", C6XABI_Tag_CPU_arch_C674X
, (TIC6X_INSN_C62X
137 | TIC6X_INSN_C674X
) }
140 /* Update the selected architecture based on ARCH, giving an error if
141 ARCH is an invalid value. Does not call tic6x_update_features; the
142 caller must do that if necessary. */
145 tic6x_use_arch (const char *arch
)
149 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
150 if (strcmp (arch
, tic6x_arches
[i
].arch
) == 0)
152 tic6x_arch_enable
= tic6x_arches
[i
].features
;
153 if (tic6x_seen_insns
)
155 = elf32_tic6x_merge_arch_attributes (tic6x_arch_attribute
,
156 tic6x_arches
[i
].attr
);
158 tic6x_arch_attribute
= tic6x_arches
[i
].attr
;
162 as_bad (_("unknown architecture '%s'"), arch
);
165 /* Parse a target-specific option. */
168 md_parse_option (int c
, char *arg
)
173 tic6x_use_arch (arg
);
180 case OPTION_MNO_ATOMIC
:
184 case OPTION_MBIG_ENDIAN
:
185 target_big_endian
= 1;
188 case OPTION_MLITTLE_ENDIAN
:
189 target_big_endian
= 0;
192 case OPTION_MGENERATE_REL
:
193 tic6x_generate_rela
= FALSE
;
203 md_show_usage (FILE *stream ATTRIBUTE_UNUSED
)
207 fputc ('\n', stream
);
208 fprintf (stream
, _("TMS320C6000 options:\n"));
209 fprintf (stream
, _(" -march=ARCH enable instructions from architecture ARCH\n"));
210 fprintf (stream
, _(" -matomic enable atomic operation instructions\n"));
211 fprintf (stream
, _(" -mno-atomic disable atomic operation instructions\n"));
212 fprintf (stream
, _(" -mbig-endian generate big-endian code\n"));
213 fprintf (stream
, _(" -mlittle-endian generate little-endian code\n"));
214 /* -mgenerate-rel is only for testsuite use and is deliberately
217 fputc ('\n', stream
);
218 fprintf (stream
, _("Supported ARCH values are:"));
219 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
220 fprintf (stream
, " %s", tic6x_arches
[i
].arch
);
221 fputc ('\n', stream
);
224 /* Update enabled features based on the current architecture and
227 tic6x_update_features (void)
229 switch (tic6x_atomic
)
232 tic6x_features
= tic6x_arch_enable
;
236 tic6x_features
= tic6x_arch_enable
& ~TIC6X_INSN_ATOMIC
;
240 tic6x_features
= tic6x_arch_enable
| TIC6X_INSN_ATOMIC
;
248 = (tic6x_arch_enable
& (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? 32 : 16;
250 tic6x_predicate_a0
= (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? TRUE
: FALSE
;
252 tic6x_can_cross_fp_boundary
254 & (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? TRUE
: FALSE
;
256 tic6x_long_data_constraints
257 = (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? FALSE
: TRUE
;
259 tic6x_compact_insns
= (tic6x_arch_enable
& TIC6X_INSN_C64XP
) ? TRUE
: FALSE
;
262 /* Do configuration after all options have been parsed. */
265 tic6x_after_parse_args (void)
267 tic6x_update_features ();
270 /* Parse a .arch directive. */
273 s_tic6x_arch (int ignored ATTRIBUTE_UNUSED
)
278 arch
= input_line_pointer
;
279 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
280 input_line_pointer
++;
281 c
= *input_line_pointer
;
282 *input_line_pointer
= 0;
284 tic6x_use_arch (arch
);
285 tic6x_update_features ();
286 *input_line_pointer
= c
;
287 demand_empty_rest_of_line ();
290 /* Parse a .atomic directive. */
293 s_tic6x_atomic (int ignored ATTRIBUTE_UNUSED
)
296 tic6x_update_features ();
297 demand_empty_rest_of_line ();
300 /* Parse a .noatomic directive. */
303 s_tic6x_noatomic (int ignored ATTRIBUTE_UNUSED
)
306 tic6x_update_features ();
307 demand_empty_rest_of_line ();
310 /* Parse a .nocmp directive. */
313 s_tic6x_nocmp (int ignored ATTRIBUTE_UNUSED
)
315 seg_info (now_seg
)->tc_segment_info_data
.nocmp
= TRUE
;
316 demand_empty_rest_of_line ();
319 /* Track for each attribute whether it has been set explicitly (and so
320 should not have a default value set by the assembler). */
321 static bfd_boolean tic6x_attributes_set_explicitly
[NUM_KNOWN_OBJ_ATTRIBUTES
];
323 /* Parse a .c6xabi_attribute directive. */
326 s_tic6x_c6xabi_attribute (int ignored ATTRIBUTE_UNUSED
)
328 int tag
= s_vendor_attribute (OBJ_ATTR_PROC
);
330 if (tag
< NUM_KNOWN_OBJ_ATTRIBUTES
)
331 tic6x_attributes_set_explicitly
[tag
] = TRUE
;
338 } tic6x_attribute_table
;
340 static const tic6x_attribute_table tic6x_attributes
[] =
342 #define TAG(tag, value) { #tag, tag }
343 #include "elf/tic6x-attrs.h"
347 /* Convert an attribute name to a number. */
350 tic6x_convert_symbolic_attribute (const char *name
)
354 for (i
= 0; i
< ARRAY_SIZE (tic6x_attributes
); i
++)
355 if (strcmp (name
, tic6x_attributes
[i
].name
) == 0)
356 return tic6x_attributes
[i
].tag
;
361 const pseudo_typeS md_pseudo_table
[] =
363 { "arch", s_tic6x_arch
, 0 },
364 { "atomic", s_tic6x_atomic
, 0 },
365 { "c6xabi_attribute", s_tic6x_c6xabi_attribute
, 0 },
366 { "noatomic", s_tic6x_noatomic
, 0 },
367 { "nocmp", s_tic6x_nocmp
, 0 },
372 /* Hash table of opcodes. For each opcode name, this stores a pointer
373 to a tic6x_opcode_list listing (in an arbitrary order) all opcode
374 table entries with that name. */
375 static struct hash_control
*opcode_hash
;
377 /* Initialize the assembler (called once at assembler startup). */
384 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, 0);
386 /* Insert opcodes into the hash table. */
387 opcode_hash
= hash_new ();
388 for (id
= 0; id
< tic6x_opcode_max
; id
++)
391 tic6x_opcode_list
*opc
= xmalloc (sizeof (tic6x_opcode_list
));
394 opc
->next
= hash_find (opcode_hash
, tic6x_opcode_table
[id
].name
);
395 if ((errmsg
= hash_jam (opcode_hash
, tic6x_opcode_table
[id
].name
, opc
))
397 as_fatal ("%s", _(errmsg
));
401 /* Whether the current line being parsed had the "||" parallel bars. */
402 static bfd_boolean tic6x_line_parallel
;
404 /* Whether the current line being parsed started "||^" to indicate an
405 SPMASKed parallel instruction. */
406 static bfd_boolean tic6x_line_spmask
;
408 /* If the current line being parsed had an instruction predicate, the
409 creg value for that predicate (which must be nonzero); otherwise
411 static unsigned int tic6x_line_creg
;
413 /* If the current line being parsed had an instruction predicate, the
414 z value for that predicate; otherwise 0. */
415 static unsigned int tic6x_line_z
;
417 /* Return 1 (updating input_line_pointer as appropriate) if the line
418 starting with C (immediately before input_line_pointer) starts with
419 pre-opcode text appropriate for this target, 0 otherwise. */
422 tic6x_unrecognized_line (int c
)
427 bfd_boolean bad_predicate
;
432 if (input_line_pointer
[0] == '|')
434 if (input_line_pointer
[1] == '^')
436 tic6x_line_spmask
= TRUE
;
437 input_line_pointer
+= 2;
440 input_line_pointer
+= 1;
441 if (tic6x_line_parallel
)
442 as_bad (_("multiple '||' on same line"));
443 tic6x_line_parallel
= TRUE
;
445 as_bad (_("'||' after predicate"));
451 /* If it doesn't look like a predicate at all, just return 0.
452 If it looks like one but not a valid one, give a better
454 p
= input_line_pointer
;
455 while (*p
!= ']' && !is_end_of_line
[(unsigned char) *p
])
460 p
= input_line_pointer
;
462 bad_predicate
= FALSE
;
468 if (*p
== 'A' || *p
== 'a')
470 else if (*p
== 'B' || *p
== 'b')
474 areg
= TRUE
; /* Avoid uninitialized warning. */
475 bad_predicate
= TRUE
;
480 if (*p
!= '0' && *p
!= '1' && *p
!= '2')
481 bad_predicate
= TRUE
;
482 else if (p
[1] != ']')
483 bad_predicate
= TRUE
;
485 input_line_pointer
= p
+ 2;
489 as_bad (_("multiple predicates on same line"));
495 as_bad (_("bad predicate '%s'"), input_line_pointer
- 1);
497 input_line_pointer
= endp
;
504 tic6x_line_creg
= (areg
? 6 : 1);
505 if (areg
&& !tic6x_predicate_a0
)
506 as_bad (_("predication on A0 not supported on this architecture"));
510 tic6x_line_creg
= (areg
? 4 : 2);
514 tic6x_line_creg
= (areg
? 5 : 3);
529 /* Do any target-specific handling of a label required. */
532 tic6x_frob_label (symbolS
*sym
)
534 segment_info_type
*si
;
535 tic6x_label_list
*list
;
537 if (tic6x_line_parallel
)
539 as_bad (_("label after '||'"));
540 tic6x_line_parallel
= FALSE
;
541 tic6x_line_spmask
= FALSE
;
545 as_bad (_("label after predicate"));
550 si
= seg_info (now_seg
);
551 list
= si
->tc_segment_info_data
.label_list
;
552 si
->tc_segment_info_data
.label_list
= xmalloc (sizeof (tic6x_label_list
));
553 si
->tc_segment_info_data
.label_list
->next
= list
;
554 si
->tc_segment_info_data
.label_list
->label
= sym
;
556 /* Defining tc_frob_label overrides the ELF definition of
557 obj_frob_label, so we need to apply its effects here. */
558 dwarf2_emit_label (sym
);
561 /* At end-of-line, give errors for start-of-line decorations that
562 needed an instruction but were not followed by one. */
565 tic6x_end_of_line (void)
567 if (tic6x_line_parallel
)
569 as_bad (_("'||' not followed by instruction"));
570 tic6x_line_parallel
= FALSE
;
571 tic6x_line_spmask
= FALSE
;
575 as_bad (_("predicate not followed by instruction"));
581 /* Do any target-specific handling of the start of a logical line. */
584 tic6x_start_line_hook (void)
586 tic6x_end_of_line ();
589 /* Do target-specific handling immediately after an input file from
590 the command line, and any other inputs it includes, have been
596 tic6x_end_of_line ();
599 /* Do target-specific initialization after arguments have been
600 processed and the output file created. */
603 tic6x_init_after_args (void)
605 elf32_tic6x_set_use_rela_p (stdoutput
, tic6x_generate_rela
);
608 /* Free LIST of labels (possibly NULL). */
611 tic6x_free_label_list (tic6x_label_list
*list
)
615 tic6x_label_list
*old
= list
;
622 /* Handle a data alignment of N bytes. */
625 tic6x_cons_align (int n ATTRIBUTE_UNUSED
)
627 segment_info_type
*seginfo
= seg_info (now_seg
);
629 /* Data means there is no current execute packet, and that any label
630 applies to that data rather than a subsequent instruction. */
631 tic6x_free_label_list (seginfo
->tc_segment_info_data
.label_list
);
632 seginfo
->tc_segment_info_data
.label_list
= NULL
;
633 seginfo
->tc_segment_info_data
.execute_packet_frag
= NULL
;
634 seginfo
->tc_segment_info_data
.last_insn_lsb
= NULL
;
635 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
636 seginfo
->tc_segment_info_data
.func_units_used
= 0;
639 /* Handle an alignment directive. Return TRUE if the
640 machine-independent frag generation should be skipped. */
643 tic6x_do_align (int n
, char *fill
, int len ATTRIBUTE_UNUSED
, int max
)
645 /* Given code alignments of 4, 8, 16 or 32 bytes, we try to handle
646 them in the md_end pass by inserting NOPs in parallel with
647 previous instructions. We only do this in sections containing
648 nothing but instructions. Code alignments of 1 or 2 bytes have
649 no effect in such sections (but we record them with
650 machine-dependent frags anyway so they can be skipped or
651 converted to machine-independent), while those of more than 64
652 bytes cannot reliably be handled in this way. */
658 && subseg_text_p (now_seg
))
666 /* Machine-independent code would generate a frag here, but we
667 wish to handle it in a machine-dependent way. */
668 if (frag_now_fix () != 0)
670 if (frag_now
->fr_type
!= rs_machine_dependent
)
671 frag_wane (frag_now
);
676 align_frag
= frag_now
;
677 p
= frag_var (rs_machine_dependent
, 32, 32, max
, NULL
, n
, NULL
);
678 /* This must be the same as the frag to which a pointer was just
680 if (p
!= align_frag
->fr_literal
)
682 align_frag
->tc_frag_data
.is_insns
= FALSE
;
689 /* Types of operand for parsing purposes. These are used as bit-masks
690 to tell tic6x_parse_operand what forms of operand are
692 #define TIC6X_OP_EXP 0x0001u
693 #define TIC6X_OP_REG 0x0002u
694 #define TIC6X_OP_REGPAIR 0x0004u
695 #define TIC6X_OP_IRP 0x0008u
696 #define TIC6X_OP_NRP 0x0010u
697 /* With TIC6X_OP_MEM_NOUNREG, the contents of a () offset are always
698 interpreted as an expression, which may be a symbol with the same
699 name as a register that ends up being implicitly DP-relative. With
700 TIC6X_OP_MEM_UNREG, the contents of a () offset are interpreted as
701 a register if they match one, and failing that as an expression,
702 which must be constant. */
703 #define TIC6X_OP_MEM_NOUNREG 0x0020u
704 #define TIC6X_OP_MEM_UNREG 0x0040u
705 #define TIC6X_OP_CTRL 0x0080u
706 #define TIC6X_OP_FUNC_UNIT 0x0100u
708 /* A register or register pair read by the assembler. */
711 /* The side the register is on (1 or 2). */
713 /* The register number (0 to 31). */
717 /* Types of modification of a base address. */
723 tic6x_mem_mod_preinc
,
724 tic6x_mem_mod_predec
,
725 tic6x_mem_mod_postinc
,
726 tic6x_mem_mod_postdec
729 /* Scaled [] or unscaled () nature of an offset. */
734 tic6x_offset_unscaled
737 /* A memory operand read by the assembler. */
740 /* The base register. */
741 tic6x_register base_reg
;
742 /* How the base register is modified. */
744 /* Whether there is an offset (required with plain "+" and "-"), and
745 whether it is scaled or unscaled if so. */
746 tic6x_mem_scaling scaled
;
747 /* Whether the offset is a register (TRUE) or an expression
749 bfd_boolean offset_is_reg
;
758 /* A functional unit in SPMASK operands read by the assembler. */
761 /* The basic unit. */
762 tic6x_func_unit_base base
;
763 /* The side (1 or 2). */
765 } tic6x_func_unit_operand
;
767 /* An operand read by the assembler. */
770 /* The syntactic form of the operand, as one of the bit-masks
773 /* The operand value. */
776 /* An expression: TIC6X_OP_EXP. */
778 /* A register: TIC6X_OP_REG, TIC6X_OP_REGPAIR. */
780 /* A memory reference: TIC6X_OP_MEM_NOUNREG,
781 TIC6X_OP_MEM_UNREG. */
783 /* A control register: TIC6X_OP_CTRL. */
785 /* A functional unit: TIC6X_OP_FUNC_UNIT. */
786 tic6x_func_unit_operand func_unit
;
790 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
792 /* Parse a register operand, or part of an operand, starting at *P.
793 If syntactically OK (including that the number is in the range 0 to
794 31, but not necessarily in range for this architecture), return
795 TRUE, putting the register side and number in *REG and update *P to
796 point immediately after the register number; otherwise return FALSE
797 without changing *P (but possibly changing *REG). Do not print any
801 tic6x_parse_register (char **p
, tic6x_register
*reg
)
822 if (*r
>= '0' && *r
<= '9')
830 if (reg
->num
> 0 && *r
>= '0' && *r
<= '9')
832 reg
->num
= reg
->num
* 10 + (*r
- '0');
836 if (*r
>= '0' && *r
<= '9')
845 /* Parse the initial two characters of a functional unit name starting
846 at *P. If OK, set *BASE and *SIDE and return TRUE; otherwise,
850 tic6x_parse_func_unit_base (char *p
, tic6x_func_unit_base
*base
,
853 bfd_boolean good_func_unit
= TRUE
;
854 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
855 unsigned int maybe_side
= 0;
861 maybe_base
= tic6x_func_unit_d
;
866 maybe_base
= tic6x_func_unit_l
;
871 maybe_base
= tic6x_func_unit_m
;
876 maybe_base
= tic6x_func_unit_s
;
880 good_func_unit
= FALSE
;
896 good_func_unit
= FALSE
;
906 return good_func_unit
;
909 /* Parse an operand starting at *P. If the operand parses OK, return
910 TRUE and store the value in *OP; otherwise return FALSE (possibly
911 changing *OP). In any case, update *P to point to the following
912 comma or end of line. The possible operand forms are given by
913 OP_FORMS. For diagnostics, this is operand OPNO of an opcode
914 starting at STR, length OPC_LEN. */
917 tic6x_parse_operand (char **p
, tic6x_operand
*op
, unsigned int op_forms
,
918 char *str
, int opc_len
, unsigned int opno
)
920 bfd_boolean operand_parsed
= FALSE
;
923 if ((op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
924 == (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
927 /* Check for functional unit names for SPMASK and SPMASKR. */
928 if (!operand_parsed
&& (op_forms
& TIC6X_OP_FUNC_UNIT
))
930 tic6x_func_unit_base base
= tic6x_func_unit_nfu
;
931 unsigned int side
= 0;
933 if (tic6x_parse_func_unit_base (q
, &base
, &side
))
937 skip_whitespace (rq
);
938 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
940 op
->form
= TIC6X_OP_FUNC_UNIT
;
941 op
->value
.func_unit
.base
= base
;
942 op
->value
.func_unit
.side
= side
;
943 operand_parsed
= TRUE
;
949 /* Check for literal "irp". */
950 if (!operand_parsed
&& (op_forms
& TIC6X_OP_IRP
))
952 if ((q
[0] == 'i' || q
[0] == 'I')
953 && (q
[1] == 'r' || q
[1] == 'R')
954 && (q
[2] == 'p' || q
[2] == 'P'))
958 skip_whitespace (rq
);
959 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
961 op
->form
= TIC6X_OP_IRP
;
962 operand_parsed
= TRUE
;
968 /* Check for literal "nrp". */
969 if (!operand_parsed
&& (op_forms
& TIC6X_OP_NRP
))
971 if ((q
[0] == 'n' || q
[0] == 'N')
972 && (q
[1] == 'r' || q
[1] == 'R')
973 && (q
[2] == 'p' || q
[2] == 'P'))
977 skip_whitespace (rq
);
978 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
980 op
->form
= TIC6X_OP_NRP
;
981 operand_parsed
= TRUE
;
987 /* Check for control register names. */
988 if (!operand_parsed
&& (op_forms
& TIC6X_OP_CTRL
))
992 for (crid
= 0; crid
< tic6x_ctrl_max
; crid
++)
994 size_t len
= strlen (tic6x_ctrl_table
[crid
].name
);
996 if (strncasecmp (tic6x_ctrl_table
[crid
].name
, q
, len
) == 0)
1000 skip_whitespace (rq
);
1001 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1003 op
->form
= TIC6X_OP_CTRL
;
1004 op
->value
.ctrl
= crid
;
1005 operand_parsed
= TRUE
;
1007 if (!(tic6x_ctrl_table
[crid
].isa_variants
& tic6x_features
))
1008 as_bad (_("control register '%s' not supported "
1009 "on this architecture"),
1010 tic6x_ctrl_table
[crid
].name
);
1016 /* See if this looks like a memory reference. */
1018 && (op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
)))
1020 bfd_boolean mem_ok
= TRUE
;
1022 tic6x_mem_mod mem_mod
= tic6x_mem_mod_none
;
1023 tic6x_register base_reg
;
1024 bfd_boolean require_offset
, permit_offset
;
1025 tic6x_mem_scaling scaled
;
1026 bfd_boolean offset_is_reg
;
1027 expressionS offset_exp
;
1028 tic6x_register offset_reg
;
1037 skip_whitespace (mq
);
1043 mem_mod
= tic6x_mem_mod_preinc
;
1048 mem_mod
= tic6x_mem_mod_plus
;
1056 mem_mod
= tic6x_mem_mod_predec
;
1061 mem_mod
= tic6x_mem_mod_minus
;
1073 skip_whitespace (mq
);
1074 mem_ok
= tic6x_parse_register (&mq
, &base_reg
);
1077 if (mem_ok
&& mem_mod
== tic6x_mem_mod_none
)
1079 skip_whitespace (mq
);
1080 if (mq
[0] == '+' && mq
[1] == '+')
1082 mem_mod
= tic6x_mem_mod_postinc
;
1085 else if (mq
[0] == '-' && mq
[1] == '-')
1087 mem_mod
= tic6x_mem_mod_postdec
;
1092 if (mem_mod
== tic6x_mem_mod_none
)
1093 permit_offset
= FALSE
;
1095 permit_offset
= TRUE
;
1096 if (mem_mod
== tic6x_mem_mod_plus
|| mem_mod
== tic6x_mem_mod_minus
)
1097 require_offset
= TRUE
;
1099 require_offset
= FALSE
;
1100 scaled
= tic6x_offset_none
;
1101 offset_is_reg
= FALSE
;
1103 if (mem_ok
&& permit_offset
)
1107 skip_whitespace (mq
);
1111 scaled
= tic6x_offset_scaled
;
1117 scaled
= tic6x_offset_unscaled
;
1125 if (scaled
!= tic6x_offset_none
)
1127 skip_whitespace (mq
);
1128 if (scaled
== tic6x_offset_scaled
1129 || (op_forms
& TIC6X_OP_MEM_UNREG
))
1134 reg_ok
= tic6x_parse_register (&rq
, &offset_reg
);
1137 skip_whitespace (rq
);
1141 offset_is_reg
= TRUE
;
1147 char *save_input_line_pointer
;
1149 save_input_line_pointer
= input_line_pointer
;
1150 input_line_pointer
= mq
;
1151 expression (&offset_exp
);
1152 mq
= input_line_pointer
;
1153 input_line_pointer
= save_input_line_pointer
;
1155 skip_whitespace (mq
);
1163 if (mem_ok
&& require_offset
&& scaled
== tic6x_offset_none
)
1168 skip_whitespace (mq
);
1169 if (!is_end_of_line
[(unsigned char) *mq
] && *mq
!= ',')
1175 op
->form
= op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
);
1176 op
->value
.mem
.base_reg
= base_reg
;
1177 op
->value
.mem
.mod
= mem_mod
;
1178 op
->value
.mem
.scaled
= scaled
;
1179 op
->value
.mem
.offset_is_reg
= offset_is_reg
;
1181 op
->value
.mem
.offset
.reg
= offset_reg
;
1183 op
->value
.mem
.offset
.exp
= offset_exp
;
1184 operand_parsed
= TRUE
;
1186 if (base_reg
.num
>= tic6x_num_registers
)
1187 as_bad (_("register number %u not supported on this architecture"),
1189 if (offset_is_reg
&& offset_reg
.num
>= tic6x_num_registers
)
1190 as_bad (_("register number %u not supported on this architecture"),
1195 /* See if this looks like a register or register pair. */
1196 if (!operand_parsed
&& (op_forms
& (TIC6X_OP_REG
| TIC6X_OP_REGPAIR
)))
1198 tic6x_register first_reg
, second_reg
;
1202 reg_ok
= tic6x_parse_register (&rq
, &first_reg
);
1206 if (*rq
== ':' && (op_forms
& TIC6X_OP_REGPAIR
))
1209 reg_ok
= tic6x_parse_register (&rq
, &second_reg
);
1212 skip_whitespace (rq
);
1213 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1215 if ((second_reg
.num
& 1)
1216 || (first_reg
.num
!= second_reg
.num
+ 1)
1217 || (first_reg
.side
!= second_reg
.side
))
1218 as_bad (_("register pair for operand %u of '%.*s'"
1219 " not a valid even/odd pair"), opno
,
1221 op
->form
= TIC6X_OP_REGPAIR
;
1222 op
->value
.reg
= second_reg
;
1223 operand_parsed
= TRUE
;
1228 else if (op_forms
& TIC6X_OP_REG
)
1230 skip_whitespace (rq
);
1231 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1233 op
->form
= TIC6X_OP_REG
;
1234 op
->value
.reg
= first_reg
;
1235 operand_parsed
= TRUE
;
1242 if (first_reg
.num
>= tic6x_num_registers
)
1243 as_bad (_("register number %u not supported on this architecture"),
1245 if (op
->form
== TIC6X_OP_REGPAIR
1246 && second_reg
.num
>= tic6x_num_registers
)
1247 as_bad (_("register number %u not supported on this architecture"),
1252 /* Otherwise, parse it as an expression. */
1253 if (!operand_parsed
&& (op_forms
& TIC6X_OP_EXP
))
1255 char *save_input_line_pointer
;
1257 save_input_line_pointer
= input_line_pointer
;
1258 input_line_pointer
= q
;
1259 op
->form
= TIC6X_OP_EXP
;
1260 expression (&op
->value
.exp
);
1261 q
= input_line_pointer
;
1262 input_line_pointer
= save_input_line_pointer
;
1263 operand_parsed
= TRUE
;
1268 /* Now the operand has been parsed, there must be nothing more
1269 before the comma or end of line. */
1270 skip_whitespace (q
);
1271 if (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1273 operand_parsed
= FALSE
;
1274 as_bad (_("junk after operand %u of '%.*s'"), opno
,
1276 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1282 /* This could not be parsed as any acceptable form of
1286 case TIC6X_OP_REG
| TIC6X_OP_REGPAIR
:
1287 as_bad (_("bad register or register pair for operand %u of '%.*s'"),
1288 opno
, opc_len
, str
);
1291 case TIC6X_OP_REG
| TIC6X_OP_CTRL
:
1293 as_bad (_("bad register for operand %u of '%.*s'"),
1294 opno
, opc_len
, str
);
1297 case TIC6X_OP_REGPAIR
:
1298 as_bad (_("bad register pair for operand %u of '%.*s'"),
1299 opno
, opc_len
, str
);
1302 case TIC6X_OP_FUNC_UNIT
:
1303 as_bad (_("bad functional unit for operand %u of '%.*s'"),
1304 opno
, opc_len
, str
);
1308 as_bad (_("bad operand %u of '%.*s'"),
1309 opno
, opc_len
, str
);
1313 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1317 return operand_parsed
;
1320 /* Table of assembler operators and associated O_* values. */
1325 } tic6x_operator_table
;
1326 static const tic6x_operator_table tic6x_operators
[] = {
1327 #define O_dsbt_index O_md1
1328 { "dsbt_index", O_dsbt_index
},
1331 #define O_dpr_got O_md3
1332 { "dpr_got", O_dpr_got
},
1333 #define O_dpr_byte O_md4
1334 { "dpr_byte", O_dpr_byte
},
1335 #define O_dpr_hword O_md5
1336 { "dpr_hword", O_dpr_hword
},
1337 #define O_dpr_word O_md6
1338 { "dpr_word", O_dpr_word
},
1341 /* Parse a name in some machine-specific way. Used on C6X to handle
1342 assembler operators. */
1345 tic6x_parse_name (const char *name
, expressionS
*exprP
,
1346 enum expr_mode mode ATTRIBUTE_UNUSED
, char *nextchar
)
1348 char *p
= input_line_pointer
;
1349 char c
, *name_start
, *name_end
;
1350 const char *inner_name
;
1352 operatorT op
= O_illegal
;
1358 for (i
= 0; i
< ARRAY_SIZE (tic6x_operators
); i
++)
1359 if (strcasecmp (name
+ 1, tic6x_operators
[i
].name
) == 0)
1361 op
= tic6x_operators
[i
].op
;
1365 if (op
== O_illegal
)
1368 *input_line_pointer
= *nextchar
;
1369 skip_whitespace (p
);
1373 *input_line_pointer
= 0;
1377 skip_whitespace (p
);
1379 if (!is_name_beginner (*p
))
1381 *input_line_pointer
= 0;
1387 while (is_part_of_name (*p
))
1390 skip_whitespace (p
);
1394 *input_line_pointer
= 0;
1398 input_line_pointer
= p
+ 1;
1399 *nextchar
= *input_line_pointer
;
1400 *input_line_pointer
= 0;
1404 inner_name
= name_start
;
1405 if (op
== O_dsbt_index
&& strcmp (inner_name
, "__c6xabi_DSBT_BASE") != 0)
1407 as_bad (_("$DSBT_INDEX must be used with __c6xabi_DSBT_BASE"));
1408 inner_name
= "__c6xabi_DSBT_BASE";
1410 sym
= symbol_find_or_make (inner_name
);
1414 exprP
->X_add_symbol
= sym
;
1415 exprP
->X_add_number
= 0;
1416 exprP
->X_op_symbol
= NULL
;
1422 /* Create a fixup for an expression. Same arguments as fix_new_exp,
1423 plus FIX_ADDA which is TRUE for ADDA instructions (to indicate that
1424 fixes resolving to constants should have those constants implicitly
1425 shifted) and FALSE otherwise, but look for C6X-specific expression
1426 types and adjust the relocations or give errors accordingly. */
1429 tic6x_fix_new_exp (fragS
*frag
, int where
, int size
, expressionS
*exp
,
1430 int pcrel
, bfd_reloc_code_real_type r_type
,
1431 bfd_boolean fix_adda
)
1433 bfd_reloc_code_real_type new_reloc
= BFD_RELOC_UNUSED
;
1441 case BFD_RELOC_C6000_SBR_U15_W
:
1442 new_reloc
= BFD_RELOC_C6000_DSBT_INDEX
;
1446 as_bad (_("$DSBT_INDEX not supported in this context"));
1454 case BFD_RELOC_C6000_SBR_U15_W
:
1455 new_reloc
= BFD_RELOC_C6000_SBR_GOT_U15_W
;
1459 as_bad (_("$GOT not supported in this context"));
1467 case BFD_RELOC_C6000_ABS_L16
:
1468 new_reloc
= BFD_RELOC_C6000_SBR_GOT_L16_W
;
1471 case BFD_RELOC_C6000_ABS_H16
:
1472 new_reloc
= BFD_RELOC_C6000_SBR_GOT_H16_W
;
1476 as_bad (_("$DPR_GOT not supported in this context"));
1484 case BFD_RELOC_C6000_ABS_S16
:
1485 new_reloc
= BFD_RELOC_C6000_SBR_S16
;
1488 case BFD_RELOC_C6000_ABS_L16
:
1489 new_reloc
= BFD_RELOC_C6000_SBR_L16_B
;
1492 case BFD_RELOC_C6000_ABS_H16
:
1493 new_reloc
= BFD_RELOC_C6000_SBR_H16_B
;
1497 as_bad (_("$DPR_BYTE not supported in this context"));
1505 case BFD_RELOC_C6000_ABS_L16
:
1506 new_reloc
= BFD_RELOC_C6000_SBR_L16_H
;
1509 case BFD_RELOC_C6000_ABS_H16
:
1510 new_reloc
= BFD_RELOC_C6000_SBR_H16_H
;
1514 as_bad (_("$DPR_HWORD not supported in this context"));
1522 case BFD_RELOC_C6000_ABS_L16
:
1523 new_reloc
= BFD_RELOC_C6000_SBR_L16_W
;
1526 case BFD_RELOC_C6000_ABS_H16
:
1527 new_reloc
= BFD_RELOC_C6000_SBR_H16_W
;
1531 as_bad (_("$DPR_WORD not supported in this context"));
1542 as_bad (_("invalid PC-relative operand"));
1548 if (new_reloc
== BFD_RELOC_UNUSED
)
1549 fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1551 fix
= fix_new (frag
, where
, size
, exp
->X_add_symbol
, exp
->X_add_number
,
1553 fix
->tc_fix_data
.fix_adda
= fix_adda
;
1556 /* Generate a fix for a constant (.word etc.). Needed to ensure these
1557 go through the error checking in tic6x_fix_new_exp. */
1560 tic6x_cons_fix_new (fragS
*frag
, int where
, int size
, expressionS
*exp
)
1562 bfd_reloc_code_real_type r_type
;
1567 r_type
= BFD_RELOC_8
;
1571 r_type
= BFD_RELOC_16
;
1575 r_type
= BFD_RELOC_32
;
1579 as_bad (_("no %d-byte relocations available"), size
);
1583 tic6x_fix_new_exp (frag
, where
, size
, exp
, 0, r_type
, FALSE
);
1586 /* Initialize target-specific fix data. */
1589 tic6x_init_fix_data (fixS
*fixP
)
1591 fixP
->tc_fix_data
.fix_adda
= FALSE
;
1594 /* Return true if the fix can be handled by GAS, false if it must
1595 be passed through to the linker. */
1598 tic6x_fix_adjustable (fixS
*fixP
)
1600 switch (fixP
->fx_r_type
)
1602 /* Adjust_reloc_syms doesn't know about the GOT. */
1603 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
1604 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
1605 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
1613 /* Given the fine-grained form of an operand, return the coarse
1617 tic6x_coarse_operand_form (tic6x_operand_form form
)
1621 case tic6x_operand_asm_const
:
1622 case tic6x_operand_link_const
:
1623 return TIC6X_OP_EXP
;
1625 case tic6x_operand_reg
:
1626 case tic6x_operand_xreg
:
1627 case tic6x_operand_dreg
:
1628 case tic6x_operand_areg
:
1629 case tic6x_operand_retreg
:
1630 return TIC6X_OP_REG
;
1632 case tic6x_operand_regpair
:
1633 case tic6x_operand_xregpair
:
1634 case tic6x_operand_dregpair
:
1635 return TIC6X_OP_REGPAIR
;
1637 case tic6x_operand_irp
:
1638 return TIC6X_OP_IRP
;
1640 case tic6x_operand_nrp
:
1641 return TIC6X_OP_NRP
;
1643 case tic6x_operand_ctrl
:
1644 return TIC6X_OP_CTRL
;
1646 case tic6x_operand_mem_short
:
1647 case tic6x_operand_mem_long
:
1648 case tic6x_operand_mem_deref
:
1649 return TIC6X_OP_MEM_NOUNREG
;
1651 case tic6x_operand_mem_ndw
:
1652 return TIC6X_OP_MEM_UNREG
;
1654 case tic6x_operand_func_unit
:
1655 return TIC6X_OP_FUNC_UNIT
;
1662 /* How an operand may match or not match a desired form. If different
1663 instruction alternatives fail in different ways, the first failure
1664 in this list determines the diagnostic. */
1668 tic6x_match_matches
,
1669 /* Bad coarse form. */
1672 tic6x_match_non_const
,
1673 /* Register on wrong side. */
1674 tic6x_match_wrong_side
,
1675 /* Not a valid address register. */
1676 tic6x_match_bad_address
,
1677 /* Not a valid return address register. */
1678 tic6x_match_bad_return
,
1679 /* Control register not readable. */
1680 tic6x_match_ctrl_write_only
,
1681 /* Control register not writable. */
1682 tic6x_match_ctrl_read_only
,
1683 /* Not a valid memory reference for this instruction. */
1685 } tic6x_operand_match
;
1687 /* Return whether an operand matches the given fine-grained form and
1688 read/write usage, and, if it does not match, how it fails to match.
1689 The main functional unit side is SIDE; the cross-path side is CROSS
1690 (the same as SIDE if a cross path not used); the data side is
1692 static tic6x_operand_match
1693 tic6x_operand_matches_form (const tic6x_operand
*op
, tic6x_operand_form form
,
1694 tic6x_rw rw
, unsigned int side
, unsigned int cross
,
1695 unsigned int data_side
)
1697 unsigned int coarse
= tic6x_coarse_operand_form (form
);
1699 if (coarse
!= op
->form
)
1700 return tic6x_match_coarse
;
1704 case tic6x_operand_asm_const
:
1705 if (op
->value
.exp
.X_op
== O_constant
)
1706 return tic6x_match_matches
;
1708 return tic6x_match_non_const
;
1710 case tic6x_operand_link_const
:
1711 case tic6x_operand_irp
:
1712 case tic6x_operand_nrp
:
1713 case tic6x_operand_func_unit
:
1714 /* All expressions are link-time constants, although there may
1715 not be relocations to express them in the output file. "irp"
1716 and "nrp" are unique operand values. All parsed functional
1717 unit names are valid. */
1718 return tic6x_match_matches
;
1720 case tic6x_operand_reg
:
1721 case tic6x_operand_regpair
:
1722 if (op
->value
.reg
.side
== side
)
1723 return tic6x_match_matches
;
1725 return tic6x_match_wrong_side
;
1727 case tic6x_operand_xreg
:
1728 case tic6x_operand_xregpair
:
1729 if (op
->value
.reg
.side
== cross
)
1730 return tic6x_match_matches
;
1732 return tic6x_match_wrong_side
;
1734 case tic6x_operand_dreg
:
1735 case tic6x_operand_dregpair
:
1736 if (op
->value
.reg
.side
== data_side
)
1737 return tic6x_match_matches
;
1739 return tic6x_match_wrong_side
;
1741 case tic6x_operand_areg
:
1742 if (op
->value
.reg
.side
!= cross
)
1743 return tic6x_match_wrong_side
;
1744 else if (op
->value
.reg
.side
== 2
1745 && (op
->value
.reg
.num
== 14 || op
->value
.reg
.num
== 15))
1746 return tic6x_match_matches
;
1748 return tic6x_match_bad_address
;
1750 case tic6x_operand_retreg
:
1751 if (op
->value
.reg
.side
!= side
)
1752 return tic6x_match_wrong_side
;
1753 else if (op
->value
.reg
.num
!= 3)
1754 return tic6x_match_bad_return
;
1756 return tic6x_match_matches
;
1758 case tic6x_operand_ctrl
:
1762 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read
1763 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
1764 return tic6x_match_matches
;
1766 return tic6x_match_ctrl_write_only
;
1768 case tic6x_rw_write
:
1769 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_write
1770 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
1771 return tic6x_match_matches
;
1773 return tic6x_match_ctrl_read_only
;
1779 case tic6x_operand_mem_deref
:
1780 if (op
->value
.mem
.mod
!= tic6x_mem_mod_none
)
1781 return tic6x_match_bad_mem
;
1782 else if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
1784 else if (op
->value
.mem
.base_reg
.side
!= side
)
1785 return tic6x_match_bad_mem
;
1787 return tic6x_match_matches
;
1789 case tic6x_operand_mem_short
:
1790 case tic6x_operand_mem_ndw
:
1791 if (op
->value
.mem
.base_reg
.side
!= side
)
1792 return tic6x_match_bad_mem
;
1793 if (op
->value
.mem
.mod
== tic6x_mem_mod_none
)
1795 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
1797 return tic6x_match_matches
;
1799 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
1801 if (op
->value
.mem
.mod
== tic6x_mem_mod_plus
1802 || op
->value
.mem
.mod
== tic6x_mem_mod_minus
)
1804 return tic6x_match_matches
;
1806 if (op
->value
.mem
.offset_is_reg
)
1808 if (op
->value
.mem
.scaled
== tic6x_offset_unscaled
1809 && form
!= tic6x_operand_mem_ndw
)
1811 if (op
->value
.mem
.offset
.reg
.side
== side
)
1812 return tic6x_match_matches
;
1814 return tic6x_match_bad_mem
;
1818 if (op
->value
.mem
.offset
.exp
.X_op
== O_constant
)
1819 return tic6x_match_matches
;
1821 return tic6x_match_bad_mem
;
1824 case tic6x_operand_mem_long
:
1825 if (op
->value
.mem
.base_reg
.side
== 2
1826 && (op
->value
.mem
.base_reg
.num
== 14
1827 || op
->value
.mem
.base_reg
.num
== 15))
1829 switch (op
->value
.mem
.mod
)
1831 case tic6x_mem_mod_none
:
1832 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
1834 return tic6x_match_matches
;
1836 case tic6x_mem_mod_plus
:
1837 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
1839 if (op
->value
.mem
.offset_is_reg
)
1840 return tic6x_match_bad_mem
;
1841 else if (op
->value
.mem
.scaled
== tic6x_offset_scaled
1842 && op
->value
.mem
.offset
.exp
.X_op
!= O_constant
)
1843 return tic6x_match_bad_mem
;
1845 return tic6x_match_matches
;
1847 case tic6x_mem_mod_minus
:
1848 case tic6x_mem_mod_preinc
:
1849 case tic6x_mem_mod_predec
:
1850 case tic6x_mem_mod_postinc
:
1851 case tic6x_mem_mod_postdec
:
1852 return tic6x_match_bad_mem
;
1860 return tic6x_match_bad_mem
;
1867 /* Return the number of bits shift used with DP-relative coding method
1871 tic6x_dpr_shift (tic6x_coding_method coding
)
1875 case tic6x_coding_ulcst_dpr_byte
:
1878 case tic6x_coding_ulcst_dpr_half
:
1881 case tic6x_coding_ulcst_dpr_word
:
1889 /* Return the relocation used with DP-relative coding method
1892 static bfd_reloc_code_real_type
1893 tic6x_dpr_reloc (tic6x_coding_method coding
)
1897 case tic6x_coding_ulcst_dpr_byte
:
1898 return BFD_RELOC_C6000_SBR_U15_B
;
1900 case tic6x_coding_ulcst_dpr_half
:
1901 return BFD_RELOC_C6000_SBR_U15_H
;
1903 case tic6x_coding_ulcst_dpr_word
:
1904 return BFD_RELOC_C6000_SBR_U15_W
;
1911 /* Given a memory reference *MEM_REF as originally parsed, fill in
1912 defaults for missing offsets. */
1915 tic6x_default_mem_ref (tic6x_mem_ref
*mem_ref
)
1917 switch (mem_ref
->mod
)
1919 case tic6x_mem_mod_none
:
1920 if (mem_ref
->scaled
!= tic6x_offset_none
)
1922 mem_ref
->mod
= tic6x_mem_mod_plus
;
1923 mem_ref
->scaled
= tic6x_offset_unscaled
;
1924 mem_ref
->offset_is_reg
= FALSE
;
1925 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
1926 mem_ref
->offset
.exp
.X_op
= O_constant
;
1927 mem_ref
->offset
.exp
.X_add_number
= 0;
1928 mem_ref
->offset
.exp
.X_unsigned
= 0;
1931 case tic6x_mem_mod_plus
:
1932 case tic6x_mem_mod_minus
:
1933 if (mem_ref
->scaled
== tic6x_offset_none
)
1937 case tic6x_mem_mod_preinc
:
1938 case tic6x_mem_mod_predec
:
1939 case tic6x_mem_mod_postinc
:
1940 case tic6x_mem_mod_postdec
:
1941 if (mem_ref
->scaled
!= tic6x_offset_none
)
1943 mem_ref
->scaled
= tic6x_offset_scaled
;
1944 mem_ref
->offset_is_reg
= FALSE
;
1945 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
1946 mem_ref
->offset
.exp
.X_op
= O_constant
;
1947 mem_ref
->offset
.exp
.X_add_number
= 1;
1948 mem_ref
->offset
.exp
.X_unsigned
= 0;
1956 /* Return the encoding in the 8-bit field of an SPMASK or SPMASKR
1957 instruction of the specified UNIT, side SIDE. */
1960 tic6x_encode_spmask (tic6x_func_unit_base unit
, unsigned int side
)
1964 case tic6x_func_unit_l
:
1965 return 1 << (side
- 1);
1967 case tic6x_func_unit_s
:
1968 return 1 << (side
+ 1);
1970 case tic6x_func_unit_d
:
1971 return 1 << (side
+ 3);
1973 case tic6x_func_unit_m
:
1974 return 1 << (side
+ 5);
1981 /* Try to encode the instruction with opcode number ID and operands
1982 OPERANDS (number NUM_OPERANDS), creg value THIS_LINE_CREG and z
1983 value THIS_LINE_Z; FUNC_UNIT_SIDE, FUNC_UNIT_CROSS and
1984 FUNC_UNIT_DATA_SIDE describe the functional unit specification;
1985 SPLOOP_II is the ii value from the previous SPLOOP-family
1986 instruction, or 0 if not in such a loop; the only possible problems
1987 are operands being out of range (they already match the
1988 fine-grained form), and inappropriate predication. If this
1989 succeeds, return the encoding and set *OK to TRUE; otherwise return
1990 0 and set *OK to FALSE. If a fix is needed, set *FIX_NEEDED to
1991 true and fill in *FIX_EXP, *FIX_PCREL, *FX_R_TYPE and *FIX_ADDA.
1992 Print error messages for failure if PRINT_ERRORS is TRUE; the
1993 opcode starts at STR and has length OPC_LEN. */
1996 tic6x_try_encode (tic6x_opcode_id id
, tic6x_operand
*operands
,
1997 unsigned int num_operands
, unsigned int this_line_creg
,
1998 unsigned int this_line_z
, unsigned int func_unit_side
,
1999 unsigned int func_unit_cross
,
2000 unsigned int func_unit_data_side
, int sploop_ii
,
2001 expressionS
**fix_exp
, int *fix_pcrel
,
2002 bfd_reloc_code_real_type
*fx_r_type
, bfd_boolean
*fix_adda
,
2003 bfd_boolean
*fix_needed
, bfd_boolean
*ok
,
2004 bfd_boolean print_errors
, char *str
, int opc_len
)
2006 const tic6x_opcode
*opct
;
2007 const tic6x_insn_format
*fmt
;
2008 unsigned int opcode_value
;
2011 opct
= &tic6x_opcode_table
[id
];
2012 fmt
= &tic6x_insn_format_table
[opct
->format
];
2013 opcode_value
= fmt
->cst_bits
;
2015 for (fld
= 0; fld
< opct
->num_fixed_fields
; fld
++)
2017 if (opct
->fixed_fields
[fld
].min_val
== opct
->fixed_fields
[fld
].max_val
)
2019 const tic6x_insn_field
*fldd
;
2020 fldd
= tic6x_field_from_fmt (fmt
, opct
->fixed_fields
[fld
].field_id
);
2023 opcode_value
|= opct
->fixed_fields
[fld
].min_val
<< fldd
->low_pos
;
2027 for (fld
= 0; fld
< opct
->num_variable_fields
; fld
++)
2029 const tic6x_insn_field
*fldd
;
2035 unsigned int fcyc_bits
;
2040 fldd
= tic6x_field_from_fmt (fmt
, opct
->variable_fields
[fld
].field_id
);
2043 opno
= opct
->variable_fields
[fld
].operand_num
;
2044 switch (opct
->variable_fields
[fld
].coding_method
)
2046 case tic6x_coding_ucst
:
2047 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2049 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2051 ucexp
= operands
[opno
].value
.exp
;
2053 if (ucexp
.X_add_number
< 0
2054 || ucexp
.X_add_number
>= (1 << fldd
->width
))
2057 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2062 value
= ucexp
.X_add_number
;
2065 case tic6x_coding_scst
:
2066 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2068 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2071 /* Opcode table should not permit non-constants without
2072 a known relocation for them. */
2073 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2076 *fix_exp
= &operands
[opno
].value
.exp
;
2078 *fx_r_type
= BFD_RELOC_C6000_ABS_S16
;
2082 sign_value
= SEXT (operands
[opno
].value
.exp
.X_add_number
);
2084 if (sign_value
< -(1 << (fldd
->width
- 1))
2085 || (sign_value
>= (1 << (fldd
->width
- 1))))
2088 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2093 value
= sign_value
+ (1 << (fldd
->width
- 1));
2094 value
^= (1 << (fldd
->width
- 1));
2097 case tic6x_coding_ucst_minus_one
:
2098 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2100 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2102 if (operands
[opno
].value
.exp
.X_add_number
<= 0
2103 || operands
[opno
].value
.exp
.X_add_number
> (1 << fldd
->width
))
2106 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2111 value
= operands
[opno
].value
.exp
.X_add_number
- 1;
2114 case tic6x_coding_scst_negate
:
2115 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2117 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2119 sign_value
= SEXT (-operands
[opno
].value
.exp
.X_add_number
);
2120 goto signed_constant
;
2122 case tic6x_coding_ulcst_dpr_byte
:
2123 case tic6x_coding_ulcst_dpr_half
:
2124 case tic6x_coding_ulcst_dpr_word
:
2125 bits
= tic6x_dpr_shift (opct
->variable_fields
[fld
].coding_method
);
2126 switch (operands
[opno
].form
)
2129 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2131 ucexp
= operands
[opno
].value
.exp
;
2132 goto unsigned_constant
;
2134 expp
= &operands
[opno
].value
.exp
;
2137 case TIC6X_OP_MEM_NOUNREG
:
2138 mem
= operands
[opno
].value
.mem
;
2139 tic6x_default_mem_ref (&mem
);
2140 if (mem
.offset_is_reg
)
2142 if (mem
.offset
.exp
.X_op
== O_constant
)
2144 ucexp
= mem
.offset
.exp
;
2145 if (mem
.scaled
== tic6x_offset_unscaled
)
2147 if (ucexp
.X_add_number
& ((1 << bits
) - 1))
2150 as_bad (_("offset in operand %u of '%.*s' not "
2151 "divisible by %u"), opno
+ 1, opc_len
,
2156 ucexp
.X_add_number
>>= bits
;
2158 goto unsigned_constant
;
2160 if (mem
.scaled
!= tic6x_offset_unscaled
)
2162 if (operands
[opno
].value
.mem
.mod
== tic6x_mem_mod_none
2163 || operands
[opno
].value
.mem
.scaled
!= tic6x_offset_unscaled
2164 || operands
[opno
].value
.mem
.offset_is_reg
)
2166 expp
= &operands
[opno
].value
.mem
.offset
.exp
;
2173 /* Opcode table should not use this encoding without a known
2175 if (fldd
->low_pos
!= 8 || fldd
->width
!= 15)
2177 /* We do not check for offset divisibility here; such a
2178 check is not needed at this point to encode the value,
2179 and if there is eventually a problem it will be detected
2180 either in md_apply_fix or at link time. */
2185 = tic6x_dpr_reloc (opct
->variable_fields
[fld
].coding_method
);
2186 if (operands
[opno
].form
== TIC6X_OP_EXP
)
2192 case tic6x_coding_lcst_low16
:
2193 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2195 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2196 value
= operands
[opno
].value
.exp
.X_add_number
& 0xffff;
2200 /* Opcode table should not use this encoding without a
2201 known relocation. */
2202 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2205 *fix_exp
= &operands
[opno
].value
.exp
;
2207 *fx_r_type
= BFD_RELOC_C6000_ABS_L16
;
2212 case tic6x_coding_lcst_high16
:
2213 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2215 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2216 value
= (operands
[opno
].value
.exp
.X_add_number
>> 16) & 0xffff;
2220 /* Opcode table should not use this encoding without a
2221 known relocation. */
2222 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2225 *fix_exp
= &operands
[opno
].value
.exp
;
2227 *fx_r_type
= BFD_RELOC_C6000_ABS_H16
;
2232 case tic6x_coding_pcrel
:
2233 case tic6x_coding_pcrel_half
:
2234 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2238 *fix_exp
= &operands
[opno
].value
.exp
;
2240 if (fldd
->low_pos
== 7 && fldd
->width
== 21)
2241 *fx_r_type
= BFD_RELOC_C6000_PCR_S21
;
2242 else if (fldd
->low_pos
== 16 && fldd
->width
== 12)
2243 *fx_r_type
= BFD_RELOC_C6000_PCR_S12
;
2244 else if (fldd
->low_pos
== 13 && fldd
->width
== 10)
2245 *fx_r_type
= BFD_RELOC_C6000_PCR_S10
;
2246 else if (fldd
->low_pos
== 16 && fldd
->width
== 7)
2247 *fx_r_type
= BFD_RELOC_C6000_PCR_S7
;
2249 /* Opcode table should not use this encoding without a
2250 known relocation. */
2255 case tic6x_coding_reg
:
2256 switch (operands
[opno
].form
)
2259 case TIC6X_OP_REGPAIR
:
2260 value
= operands
[opno
].value
.reg
.num
;
2263 case TIC6X_OP_MEM_NOUNREG
:
2264 case TIC6X_OP_MEM_UNREG
:
2265 value
= operands
[opno
].value
.mem
.base_reg
.num
;
2273 case tic6x_coding_areg
:
2274 switch (operands
[opno
].form
)
2277 value
= (operands
[opno
].value
.reg
.num
== 15 ? 1 : 0);
2280 case TIC6X_OP_MEM_NOUNREG
:
2281 value
= (operands
[opno
].value
.mem
.base_reg
.num
== 15 ? 1 : 0);
2289 case tic6x_coding_crlo
:
2290 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2292 value
= tic6x_ctrl_table
[operands
[opno
].value
.ctrl
].crlo
;
2295 case tic6x_coding_crhi
:
2296 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2301 case tic6x_coding_reg_shift
:
2302 if (operands
[opno
].form
!= TIC6X_OP_REGPAIR
)
2304 value
= operands
[opno
].value
.reg
.num
>> 1;
2307 case tic6x_coding_mem_offset
:
2308 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
)
2310 mem
= operands
[opno
].value
.mem
;
2311 tic6x_default_mem_ref (&mem
);
2312 if (mem
.offset_is_reg
)
2314 if (mem
.scaled
!= tic6x_offset_scaled
)
2316 value
= mem
.offset
.reg
.num
;
2322 if (mem
.offset
.exp
.X_op
!= O_constant
)
2326 case tic6x_offset_scaled
:
2330 case tic6x_offset_unscaled
:
2331 scale
= opct
->operand_info
[opno
].size
;
2332 if (scale
!= 1 && scale
!= 2 && scale
!= 4 && scale
!= 8)
2339 if (mem
.offset
.exp
.X_add_number
< 0
2340 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->width
) * scale
)
2343 as_bad (_("offset in operand %u of '%.*s' out of range"),
2344 opno
+ 1, opc_len
, str
);
2348 if (mem
.offset
.exp
.X_add_number
% scale
)
2351 as_bad (_("offset in operand %u of '%.*s' not "
2353 opno
+ 1, opc_len
, str
, scale
);
2357 value
= mem
.offset
.exp
.X_add_number
/ scale
;
2361 case tic6x_coding_mem_offset_noscale
:
2362 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2364 mem
= operands
[opno
].value
.mem
;
2365 tic6x_default_mem_ref (&mem
);
2366 if (mem
.offset_is_reg
)
2367 value
= mem
.offset
.reg
.num
;
2370 if (mem
.offset
.exp
.X_op
!= O_constant
)
2372 if (mem
.offset
.exp
.X_add_number
< 0
2373 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->width
))
2376 as_bad (_("offset in operand %u of '%.*s' out of range"),
2377 opno
+ 1, opc_len
, str
);
2381 value
= mem
.offset
.exp
.X_add_number
;
2385 case tic6x_coding_mem_mode
:
2386 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
2387 && operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2389 mem
= operands
[opno
].value
.mem
;
2390 tic6x_default_mem_ref (&mem
);
2393 case tic6x_mem_mod_plus
:
2397 case tic6x_mem_mod_minus
:
2401 case tic6x_mem_mod_preinc
:
2405 case tic6x_mem_mod_predec
:
2409 case tic6x_mem_mod_postinc
:
2413 case tic6x_mem_mod_postdec
:
2420 value
+= (mem
.offset_is_reg
? 4 : 0);
2423 case tic6x_coding_scaled
:
2424 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2426 mem
= operands
[opno
].value
.mem
;
2427 tic6x_default_mem_ref (&mem
);
2430 case tic6x_offset_unscaled
:
2434 case tic6x_offset_scaled
:
2443 case tic6x_coding_spmask
:
2444 /* The position of such a field is hardcoded in the handling
2446 if (fldd
->low_pos
!= 18)
2449 for (opno
= 0; opno
< num_operands
; opno
++)
2453 v
= tic6x_encode_spmask (operands
[opno
].value
.func_unit
.base
,
2454 operands
[opno
].value
.func_unit
.side
);
2458 as_bad (_("functional unit already masked for operand "
2459 "%u of '%.*s'"), opno
+ 1, opc_len
, str
);
2467 case tic6x_coding_reg_unused
:
2468 /* This is a placeholder; correct handling goes along with
2469 resource constraint checks. */
2473 case tic6x_coding_fstg
:
2474 case tic6x_coding_fcyc
:
2475 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2477 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2482 as_bad (_("'%.*s' instruction not in a software "
2491 else if (sploop_ii
<= 2)
2493 else if (sploop_ii
<= 4)
2495 else if (sploop_ii
<= 8)
2497 else if (sploop_ii
<= 14)
2501 if (fcyc_bits
> fldd
->width
)
2504 if (opct
->variable_fields
[fld
].coding_method
== tic6x_coding_fstg
)
2507 if (operands
[opno
].value
.exp
.X_add_number
< 0
2508 || (operands
[opno
].value
.exp
.X_add_number
2509 >= (1 << (fldd
->width
- fcyc_bits
))))
2512 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2517 value
= operands
[opno
].value
.exp
.X_add_number
;
2518 for (t
= 0, i
= fcyc_bits
; i
< fldd
->width
; i
++)
2520 t
= (t
<< 1) | (value
& 1);
2523 value
= t
<< fcyc_bits
;
2527 if (operands
[opno
].value
.exp
.X_add_number
< 0
2528 || (operands
[opno
].value
.exp
.X_add_number
>= sploop_ii
))
2531 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2536 value
= operands
[opno
].value
.exp
.X_add_number
;
2540 case tic6x_coding_fu
:
2541 value
= func_unit_side
== 2 ? 1 : 0;
2544 case tic6x_coding_data_fu
:
2545 value
= func_unit_data_side
== 2 ? 1 : 0;
2548 case tic6x_coding_xpath
:
2549 value
= func_unit_cross
;
2556 for (ffld
= 0; ffld
< opct
->num_fixed_fields
; ffld
++)
2557 if ((opct
->fixed_fields
[ffld
].field_id
2558 == opct
->variable_fields
[fld
].field_id
)
2559 && (value
< opct
->fixed_fields
[ffld
].min_val
2560 || value
> opct
->fixed_fields
[ffld
].max_val
))
2563 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2569 opcode_value
|= value
<< fldd
->low_pos
;
2574 const tic6x_insn_field
*creg
;
2575 const tic6x_insn_field
*z
;
2577 creg
= tic6x_field_from_fmt (fmt
, tic6x_field_creg
);
2581 as_bad (_("instruction '%.*s' cannot be predicated"),
2586 z
= tic6x_field_from_fmt (fmt
, tic6x_field_z
);
2587 /* If there is a creg field, there must be a z field; otherwise
2588 there is an error in the format table. */
2592 opcode_value
|= this_line_creg
<< creg
->low_pos
;
2593 opcode_value
|= this_line_z
<< z
->low_pos
;
2597 return opcode_value
;
2600 /* Convert the target integer stored in N bytes in BUF to a host
2601 integer, returning that value. */
2604 md_chars_to_number (char *buf
, int n
)
2607 unsigned char *p
= (unsigned char *) buf
;
2609 if (target_big_endian
)
2614 result
|= (*p
++ & 0xff);
2622 result
|= (p
[n
] & 0xff);
2629 /* Assemble the instruction starting at STR (an opcode, with the
2630 opcode name all-lowercase). */
2633 md_assemble (char *str
)
2637 bfd_boolean this_line_parallel
;
2638 bfd_boolean this_line_spmask
;
2639 unsigned int this_line_creg
;
2640 unsigned int this_line_z
;
2641 tic6x_label_list
*this_insn_label_list
;
2642 segment_info_type
*seginfo
;
2643 tic6x_opcode_list
*opc_list
, *opc
;
2644 tic6x_func_unit_base func_unit_base
= tic6x_func_unit_nfu
;
2645 unsigned int func_unit_side
= 0;
2646 unsigned int func_unit_cross
= 0;
2647 unsigned int cross_side
= 0;
2648 unsigned int func_unit_data_side
= 0;
2649 unsigned int max_matching_opcodes
, num_matching_opcodes
;
2650 tic6x_opcode_id
*opcm
= NULL
;
2651 unsigned int opc_rank
[TIC6X_NUM_PREFER
];
2652 const tic6x_opcode
*opct
= NULL
;
2653 int min_rank
, try_rank
, max_rank
;
2654 bfd_boolean num_operands_permitted
[TIC6X_MAX_SOURCE_OPERANDS
+ 1]
2656 unsigned int operand_forms
[TIC6X_MAX_SOURCE_OPERANDS
] = { 0 };
2657 tic6x_operand operands
[TIC6X_MAX_SOURCE_OPERANDS
];
2658 unsigned int max_num_operands
;
2659 unsigned int num_operands_read
;
2660 bfd_boolean ok_this_arch
, ok_this_fu
, ok_this_arch_fu
;
2661 bfd_boolean bad_operands
= FALSE
;
2662 unsigned int opcode_value
;
2663 bfd_boolean encoded_ok
;
2664 bfd_boolean fix_needed
= FALSE
;
2665 expressionS
*fix_exp
= NULL
;
2667 bfd_reloc_code_real_type fx_r_type
= BFD_RELOC_UNUSED
;
2668 bfd_boolean fix_adda
= FALSE
;
2673 while (*p
&& !is_end_of_line
[(unsigned char) *p
] && *p
!= ' ')
2676 /* This function should only have been called when there is actually
2677 an instruction to assemble. */
2681 /* Now an instruction has been seen, architecture attributes from
2682 .arch directives merge with rather than overriding the previous
2684 tic6x_seen_insns
= TRUE
;
2685 /* If no .arch directives or -march options have been seen, we are
2686 assessing instruction validity based on the C674X default, so set
2687 the attribute accordingly. */
2688 if (tic6x_arch_attribute
== C6XABI_Tag_CPU_arch_none
)
2689 tic6x_arch_attribute
= C6XABI_Tag_CPU_arch_C674X
;
2691 /* Reset global settings for parallel bars and predicates now to
2692 avoid extra errors if there are problems with this opcode. */
2693 this_line_parallel
= tic6x_line_parallel
;
2694 this_line_spmask
= tic6x_line_spmask
;
2695 this_line_creg
= tic6x_line_creg
;
2696 this_line_z
= tic6x_line_z
;
2697 tic6x_line_parallel
= FALSE
;
2698 tic6x_line_spmask
= FALSE
;
2699 tic6x_line_creg
= 0;
2701 seginfo
= seg_info (now_seg
);
2702 this_insn_label_list
= seginfo
->tc_segment_info_data
.label_list
;
2703 seginfo
->tc_segment_info_data
.label_list
= NULL
;
2705 opc_list
= hash_find_n (opcode_hash
, str
, p
- str
);
2706 if (opc_list
== NULL
)
2710 as_bad (_("unknown opcode '%s'"), str
);
2716 skip_whitespace (p
);
2718 /* See if there is something that looks like a functional unit
2722 bfd_boolean good_func_unit
;
2723 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
2724 unsigned int maybe_side
= 0;
2725 unsigned int maybe_cross
= 0;
2726 unsigned int maybe_data_side
= 0;
2728 good_func_unit
= tic6x_parse_func_unit_base (p
+ 1, &maybe_base
,
2733 if (p
[3] == ' ' || is_end_of_line
[(unsigned char) p
[3]])
2735 else if ((p
[3] == 'x' || p
[3] == 'X')
2736 && (p
[4] == ' ' || is_end_of_line
[(unsigned char) p
[4]]))
2741 else if (maybe_base
== tic6x_func_unit_d
2742 && (p
[3] == 't' || p
[3] == 'T')
2743 && (p
[4] == '1' || p
[4] == '2')
2744 && (p
[5] == ' ' || is_end_of_line
[(unsigned char) p
[5]]))
2746 maybe_data_side
= p
[4] - '0';
2750 good_func_unit
= FALSE
;
2755 func_unit_base
= maybe_base
;
2756 func_unit_side
= maybe_side
;
2757 func_unit_cross
= maybe_cross
;
2758 cross_side
= (func_unit_cross
? 3 - func_unit_side
: func_unit_side
);
2759 func_unit_data_side
= maybe_data_side
;
2762 skip_whitespace (p
);
2765 /* Determine which entries in the opcode table match, and the
2766 associated permitted forms of operands. */
2767 max_matching_opcodes
= 0;
2768 for (opc
= opc_list
; opc
; opc
= opc
->next
)
2769 max_matching_opcodes
++;
2770 num_matching_opcodes
= 0;
2771 opcm
= xmalloc (max_matching_opcodes
* sizeof (*opcm
));
2772 max_num_operands
= 0;
2773 ok_this_arch
= FALSE
;
2775 ok_this_arch_fu
= FALSE
;
2776 for (opc
= opc_list
; opc
; opc
= opc
->next
)
2778 unsigned int num_operands
;
2780 bfd_boolean this_opc_arch_ok
= TRUE
;
2781 bfd_boolean this_opc_fu_ok
= TRUE
;
2783 if (tic6x_insn_format_table
[tic6x_opcode_table
[opc
->id
].format
].num_bits
2786 if (!(tic6x_opcode_table
[opc
->id
].isa_variants
& tic6x_features
))
2787 this_opc_arch_ok
= FALSE
;
2788 if (tic6x_opcode_table
[opc
->id
].func_unit
!= func_unit_base
)
2789 this_opc_fu_ok
= FALSE
;
2790 if (func_unit_side
== 1
2791 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_B_ONLY
))
2792 this_opc_fu_ok
= FALSE
;
2794 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_NO_CROSS
))
2795 this_opc_fu_ok
= FALSE
;
2796 if (!func_unit_data_side
2797 && (tic6x_opcode_table
[opc
->id
].flags
2798 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
2799 this_opc_fu_ok
= FALSE
;
2800 if (func_unit_data_side
2801 && !(tic6x_opcode_table
[opc
->id
].flags
2802 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
2803 this_opc_fu_ok
= FALSE
;
2804 if (func_unit_data_side
== 1
2805 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_T2_ONLY
))
2806 this_opc_fu_ok
= FALSE
;
2807 if (this_opc_arch_ok
)
2808 ok_this_arch
= TRUE
;
2811 if (!this_opc_arch_ok
|| !this_opc_fu_ok
)
2813 ok_this_arch_fu
= TRUE
;
2814 opcm
[num_matching_opcodes
] = opc
->id
;
2815 num_matching_opcodes
++;
2816 num_operands
= tic6x_opcode_table
[opc
->id
].num_operands
;
2818 if (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SPMASK
)
2820 if (num_operands
!= 1
2821 || (tic6x_opcode_table
[opc
->id
].operand_info
[0].form
2822 != tic6x_operand_func_unit
))
2825 for (i
= 0; i
< num_operands
; i
++)
2828 |= tic6x_coarse_operand_form (tic6x_operand_func_unit
);
2829 num_operands_permitted
[i
] = TRUE
;
2834 for (i
= 0; i
< num_operands
; i
++)
2836 tic6x_operand_form f
2837 = tic6x_opcode_table
[opc
->id
].operand_info
[i
].form
;
2839 operand_forms
[i
] |= tic6x_coarse_operand_form (f
);
2842 num_operands_permitted
[num_operands
] = TRUE
;
2843 if (num_operands
> max_num_operands
)
2844 max_num_operands
= num_operands
;
2849 as_bad (_("'%.*s' instruction not supported on this architecture"),
2857 as_bad (_("'%.*s' instruction not supported on this functional unit"),
2863 if (!ok_this_arch_fu
)
2865 as_bad (_("'%.*s' instruction not supported on this functional unit"
2866 " for this architecture"),
2872 /* If there were no instructions matching the above availability
2873 checks, we should now have given an error and returned. */
2874 if (num_matching_opcodes
== 0)
2877 num_operands_read
= 0;
2880 skip_whitespace (p
);
2881 if (is_end_of_line
[(unsigned char) *p
])
2883 if (num_operands_read
> 0)
2885 as_bad (_("missing operand after comma"));
2886 bad_operands
= TRUE
;
2891 if (max_num_operands
== 0)
2893 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
2894 bad_operands
= TRUE
;
2898 if (!tic6x_parse_operand (&p
, &operands
[num_operands_read
],
2899 operand_forms
[num_operands_read
], str
, opc_len
,
2900 num_operands_read
+ 1))
2901 bad_operands
= TRUE
;
2902 num_operands_read
++;
2904 if (is_end_of_line
[(unsigned char) *p
])
2909 if (num_operands_read
== max_num_operands
)
2911 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
2912 bad_operands
= TRUE
;
2918 /* Operand parsing should consume whole operands. */
2922 if (!bad_operands
&& !num_operands_permitted
[num_operands_read
])
2924 as_bad (_("bad number of operands to '%.*s'"), opc_len
, str
);
2925 bad_operands
= TRUE
;
2930 /* Each operand is of the right syntactic form for some opcode
2931 choice, and the number of operands is valid. Check that each
2932 operand is OK in detail for some opcode choice with the right
2933 number of operands. */
2936 for (i
= 0; i
< num_operands_read
; i
++)
2938 bfd_boolean coarse_ok
= FALSE
;
2939 bfd_boolean fine_ok
= FALSE
;
2940 tic6x_operand_match fine_failure
= tic6x_match_matches
;
2943 for (j
= 0; j
< num_matching_opcodes
; j
++)
2945 tic6x_operand_form f
;
2948 tic6x_operand_match this_fine_failure
;
2950 if (tic6x_opcode_table
[opcm
[j
]].flags
& TIC6X_FLAG_SPMASK
)
2952 f
= tic6x_operand_func_unit
;
2957 if (tic6x_opcode_table
[opcm
[j
]].num_operands
2958 != num_operands_read
)
2961 f
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].form
;
2962 rw
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].rw
;
2964 cf
= tic6x_coarse_operand_form (f
);
2966 if (operands
[i
].form
!= cf
)
2971 = tic6x_operand_matches_form (&operands
[i
], f
, rw
,
2974 func_unit_data_side
);
2975 if (this_fine_failure
== tic6x_match_matches
)
2980 if (fine_failure
== tic6x_match_matches
2981 || fine_failure
> this_fine_failure
)
2982 fine_failure
= this_fine_failure
;
2985 /* No instructions should have operand syntactic forms only
2986 acceptable with certain numbers of operands, so no
2987 diagnostic for this case. */
2993 switch (fine_failure
)
2995 case tic6x_match_non_const
:
2996 as_bad (_("operand %u of '%.*s' not constant"),
2997 i
+ 1, opc_len
, str
);
3000 case tic6x_match_wrong_side
:
3001 as_bad (_("operand %u of '%.*s' on wrong side"),
3002 i
+ 1, opc_len
, str
);
3005 case tic6x_match_bad_return
:
3006 as_bad (_("operand %u of '%.*s' not a valid return "
3007 "address register"),
3008 i
+ 1, opc_len
, str
);
3011 case tic6x_match_ctrl_write_only
:
3012 as_bad (_("operand %u of '%.*s' is write-only"),
3013 i
+ 1, opc_len
, str
);
3016 case tic6x_match_ctrl_read_only
:
3017 as_bad (_("operand %u of '%.*s' is read-only"),
3018 i
+ 1, opc_len
, str
);
3021 case tic6x_match_bad_mem
:
3022 as_bad (_("operand %u of '%.*s' not a valid memory "
3024 i
+ 1, opc_len
, str
);
3027 case tic6x_match_bad_address
:
3028 as_bad (_("operand %u of '%.*s' not a valid base "
3029 "address register"),
3030 i
+ 1, opc_len
, str
);
3036 bad_operands
= TRUE
;
3044 /* Each operand is OK for some opcode choice, and the number of
3045 operands is valid. Check whether there is an opcode choice
3046 for which all operands are simultaneously valid. */
3048 bfd_boolean found_match
= FALSE
;
3050 for (i
= 0; i
< TIC6X_NUM_PREFER
; i
++)
3051 opc_rank
[i
] = (unsigned int) -1;
3053 min_rank
= TIC6X_NUM_PREFER
- 1;
3056 for (i
= 0; i
< num_matching_opcodes
; i
++)
3059 bfd_boolean this_matches
= TRUE
;
3061 if (!(tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3062 && tic6x_opcode_table
[opcm
[i
]].num_operands
!= num_operands_read
)
3065 for (j
= 0; j
< num_operands_read
; j
++)
3067 tic6x_operand_form f
;
3070 if (tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
3072 f
= tic6x_operand_func_unit
;
3077 f
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].form
;
3078 rw
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].rw
;
3080 if (tic6x_operand_matches_form (&operands
[j
], f
, rw
,
3083 func_unit_data_side
)
3084 != tic6x_match_matches
)
3086 this_matches
= FALSE
;
3093 int rank
= TIC6X_PREFER_VAL (tic6x_opcode_table
[opcm
[i
]].flags
);
3095 if (rank
< min_rank
)
3097 if (rank
> max_rank
)
3100 if (opc_rank
[rank
] == (unsigned int) -1)
3103 /* The opcode table should provide a total ordering
3104 for all cases where multiple matches may get
3114 as_bad (_("bad operand combination for '%.*s'"), opc_len
, str
);
3115 bad_operands
= TRUE
;
3127 for (try_rank
= max_rank
; try_rank
>= min_rank
; try_rank
--)
3131 if (opc_rank
[try_rank
] == (unsigned int) -1)
3134 opcode_value
= tic6x_try_encode (opcm
[opc_rank
[try_rank
]], operands
,
3135 num_operands_read
, this_line_creg
,
3136 this_line_z
, func_unit_side
,
3137 func_unit_cross
, func_unit_data_side
,
3138 seginfo
->tc_segment_info_data
.sploop_ii
,
3139 &fix_exp
, &fix_pcrel
, &fx_r_type
,
3140 &fix_adda
, &fix_needed
, &encoded_ok
,
3141 (try_rank
== min_rank
? TRUE
: FALSE
),
3145 opct
= &tic6x_opcode_table
[opcm
[opc_rank
[try_rank
]]];
3155 if (this_line_parallel
)
3157 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
;
3158 if (insn_frag
== NULL
)
3160 as_bad (_("parallel instruction not following another instruction"));
3164 if (insn_frag
->fr_fix
>= 32)
3166 as_bad (_("too many instructions in execute packet"));
3170 if (this_insn_label_list
!= NULL
)
3171 as_bad (_("label not at start of execute packet"));
3173 if (opct
->flags
& TIC6X_FLAG_FIRST
)
3174 as_bad (_("'%.*s' instruction not at start of execute packet"),
3177 *seginfo
->tc_segment_info_data
.last_insn_lsb
|= 0x1;
3178 output
= insn_frag
->fr_literal
+ insn_frag
->fr_fix
;
3182 tic6x_label_list
*l
;
3184 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
3185 seginfo
->tc_segment_info_data
.func_units_used
= 0;
3187 /* Start a new frag for this execute packet. */
3188 if (frag_now_fix () != 0)
3190 if (frag_now
->fr_type
!= rs_machine_dependent
)
3191 frag_wane (frag_now
);
3196 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
= frag_now
;
3197 for (l
= this_insn_label_list
; l
; l
= l
->next
)
3199 symbol_set_frag (l
->label
, frag_now
);
3200 S_SET_VALUE (l
->label
, 0);
3201 S_SET_SEGMENT (l
->label
, now_seg
);
3203 tic6x_free_label_list (this_insn_label_list
);
3204 dwarf2_emit_insn (0);
3205 output
= frag_var (rs_machine_dependent
, 32, 32, 0, NULL
, 0, NULL
);
3206 /* This must be the same as the frag to which a pointer was just
3208 if (output
!= insn_frag
->fr_literal
)
3210 insn_frag
->tc_frag_data
.is_insns
= TRUE
;
3211 insn_frag
->tc_frag_data
.can_cross_fp_boundary
3212 = tic6x_can_cross_fp_boundary
;
3215 if (func_unit_base
!= tic6x_func_unit_nfu
)
3217 unsigned int func_unit_enc
;
3219 func_unit_enc
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3221 if (seginfo
->tc_segment_info_data
.func_units_used
& func_unit_enc
)
3222 as_bad (_("functional unit already used in this execute packet"));
3224 seginfo
->tc_segment_info_data
.func_units_used
|= func_unit_enc
;
3227 if (opct
->flags
& TIC6X_FLAG_SPLOOP
)
3229 if (seginfo
->tc_segment_info_data
.sploop_ii
)
3230 as_bad (_("nested software pipelined loop"));
3231 if (num_operands_read
!= 1
3232 || operands
[0].form
!= TIC6X_OP_EXP
3233 || operands
[0].value
.exp
.X_op
!= O_constant
)
3235 seginfo
->tc_segment_info_data
.sploop_ii
3236 = operands
[0].value
.exp
.X_add_number
;
3238 else if (opct
->flags
& TIC6X_FLAG_SPKERNEL
)
3240 if (!seginfo
->tc_segment_info_data
.sploop_ii
)
3241 as_bad (_("'%.*s' instruction not in a software pipelined loop"),
3243 seginfo
->tc_segment_info_data
.sploop_ii
= 0;
3246 if (this_line_spmask
)
3248 if (seginfo
->tc_segment_info_data
.spmask_addr
== NULL
)
3249 as_bad (_("'||^' without previous SPMASK"));
3250 else if (func_unit_base
== tic6x_func_unit_nfu
)
3251 as_bad (_("cannot mask instruction using no functional unit"));
3254 unsigned int spmask_opcode
;
3255 unsigned int mask_bit
;
3258 = md_chars_to_number (seginfo
->tc_segment_info_data
.spmask_addr
,
3260 mask_bit
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3262 if (spmask_opcode
& mask_bit
)
3263 as_bad (_("functional unit already masked"));
3264 spmask_opcode
|= mask_bit
;
3265 md_number_to_chars (seginfo
->tc_segment_info_data
.spmask_addr
,
3270 record_alignment (now_seg
, 5);
3271 md_number_to_chars (output
, opcode_value
, 4);
3273 tic6x_fix_new_exp (insn_frag
, output
- insn_frag
->fr_literal
, 4, fix_exp
,
3274 fix_pcrel
, fx_r_type
, fix_adda
);
3275 insn_frag
->fr_fix
+= 4;
3276 insn_frag
->fr_var
-= 4;
3277 seginfo
->tc_segment_info_data
.last_insn_lsb
3278 = (target_big_endian
? output
+ 3 : output
);
3279 if (opct
->flags
& TIC6X_FLAG_SPMASK
)
3280 seginfo
->tc_segment_info_data
.spmask_addr
= output
;
3283 /* Modify NEWVAL (32-bit) by inserting VALUE, shifted right by SHIFT
3284 and the least significant BITS bits taken, at position POS. */
3285 #define MODIFY_VALUE(NEWVAL, VALUE, SHIFT, POS, BITS) \
3287 (NEWVAL) &= 0xffffffffU & ~(((1U << (BITS)) - 1) << (POS)); \
3288 (NEWVAL) |= (((VALUE) >> (SHIFT)) & ((1U << (BITS)) - 1)) << (POS); \
3291 /* Apply a fixup to the object file. */
3294 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3296 offsetT value
= *valP
;
3297 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3299 value
= SEXT (value
);
3302 fixP
->fx_offset
= SEXT (fixP
->fx_offset
);
3304 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3307 /* We do our own overflow checks. */
3308 fixP
->fx_no_overflow
= 1;
3310 switch (fixP
->fx_r_type
)
3312 case BFD_RELOC_NONE
:
3313 /* Force output to the object file. */
3318 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3319 md_number_to_chars (buf
, value
, 4);
3323 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3325 if (value
< -0x8000 || value
> 0xffff)
3326 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3327 _("value too large for 2-byte field"));
3328 md_number_to_chars (buf
, value
, 2);
3333 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3335 if (value
< -0x80 || value
> 0xff)
3336 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3337 _("value too large for 1-byte field"));
3338 md_number_to_chars (buf
, value
, 1);
3342 case BFD_RELOC_C6000_ABS_S16
:
3343 case BFD_RELOC_C6000_ABS_L16
:
3344 case BFD_RELOC_C6000_SBR_S16
:
3345 case BFD_RELOC_C6000_SBR_L16_B
:
3346 case BFD_RELOC_C6000_SBR_L16_H
:
3347 case BFD_RELOC_C6000_SBR_L16_W
:
3348 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3349 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3351 offsetT newval
= md_chars_to_number (buf
, 4);
3354 switch (fixP
->fx_r_type
)
3356 case BFD_RELOC_C6000_SBR_L16_H
:
3360 case BFD_RELOC_C6000_SBR_L16_W
:
3361 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3370 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3371 if ((value
< -0x8000 || value
> 0x7fff)
3372 && (fixP
->fx_r_type
== BFD_RELOC_C6000_ABS_S16
3373 || fixP
->fx_r_type
== BFD_RELOC_C6000_SBR_S16
))
3374 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3375 _("immediate offset out of range"));
3377 md_number_to_chars (buf
, newval
, 4);
3380 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_S16
3381 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_L16
)
3385 case BFD_RELOC_C6000_ABS_H16
:
3386 case BFD_RELOC_C6000_SBR_H16_B
:
3387 case BFD_RELOC_C6000_SBR_H16_H
:
3388 case BFD_RELOC_C6000_SBR_H16_W
:
3389 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3390 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3392 offsetT newval
= md_chars_to_number (buf
, 4);
3395 switch (fixP
->fx_r_type
)
3397 case BFD_RELOC_C6000_SBR_H16_H
:
3401 case BFD_RELOC_C6000_SBR_H16_W
:
3402 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3411 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3413 md_number_to_chars (buf
, newval
, 4);
3415 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_H16
)
3419 case BFD_RELOC_C6000_SBR_U15_B
:
3420 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3422 offsetT newval
= md_chars_to_number (buf
, 4);
3424 MODIFY_VALUE (newval
, value
, 0, 8, 15);
3425 if (value
< 0 || value
> 0x7fff)
3426 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3427 _("immediate offset out of range"));
3429 md_number_to_chars (buf
, newval
, 4);
3433 case BFD_RELOC_C6000_SBR_U15_H
:
3434 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3436 offsetT newval
= md_chars_to_number (buf
, 4);
3438 /* Constant ADDA operands, processed as constant when the
3439 instruction is parsed, are encoded as-is rather than
3440 shifted. If the operand of an ADDA instruction is now
3441 constant (for example, the difference between two labels
3442 found after the instruction), ensure it is encoded the
3443 same way it would have been if the constant value had
3444 been known when the instruction was parsed. */
3445 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3448 MODIFY_VALUE (newval
, value
, 1, 8, 15);
3450 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3451 _("immediate offset not 2-byte-aligned"));
3452 if (value
< 0 || value
> 0xfffe)
3453 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3454 _("immediate offset out of range"));
3456 md_number_to_chars (buf
, newval
, 4);
3460 case BFD_RELOC_C6000_SBR_U15_W
:
3461 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
3462 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3464 offsetT newval
= md_chars_to_number (buf
, 4);
3466 /* Constant ADDA operands, processed as constant when the
3467 instruction is parsed, are encoded as-is rather than
3468 shifted. If the operand of an ADDA instruction is now
3469 constant (for example, the difference between two labels
3470 found after the instruction), ensure it is encoded the
3471 same way it would have been if the constant value had
3472 been known when the instruction was parsed. */
3473 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3476 MODIFY_VALUE (newval
, value
, 2, 8, 15);
3478 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3479 _("immediate offset not 4-byte-aligned"));
3480 if (value
< 0 || value
> 0x1fffc)
3481 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3482 _("immediate offset out of range"));
3484 md_number_to_chars (buf
, newval
, 4);
3486 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_SBR_U15_W
)
3490 case BFD_RELOC_C6000_DSBT_INDEX
:
3492 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3493 _("addend used with $DSBT_INDEX"));
3498 case BFD_RELOC_C6000_PCR_S21
:
3499 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3501 offsetT newval
= md_chars_to_number (buf
, 4);
3503 MODIFY_VALUE (newval
, value
, 2, 7, 21);
3506 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3507 _("PC-relative offset not 4-byte-aligned"));
3508 if (value
< -0x400000 || value
> 0x3ffffc)
3509 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3510 _("PC-relative offset out of range"));
3512 md_number_to_chars (buf
, newval
, 4);
3516 case BFD_RELOC_C6000_PCR_S12
:
3517 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3519 offsetT newval
= md_chars_to_number (buf
, 4);
3521 MODIFY_VALUE (newval
, value
, 2, 16, 12);
3524 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3525 _("PC-relative offset not 4-byte-aligned"));
3526 if (value
< -0x2000 || value
> 0x1ffc)
3527 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3528 _("PC-relative offset out of range"));
3530 md_number_to_chars (buf
, newval
, 4);
3534 case BFD_RELOC_C6000_PCR_S10
:
3535 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3537 offsetT newval
= md_chars_to_number (buf
, 4);
3539 MODIFY_VALUE (newval
, value
, 2, 13, 10);
3542 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3543 _("PC-relative offset not 4-byte-aligned"));
3544 if (value
< -0x800 || value
> 0x7fc)
3545 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3546 _("PC-relative offset out of range"));
3548 md_number_to_chars (buf
, newval
, 4);
3552 case BFD_RELOC_C6000_PCR_S7
:
3553 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3555 offsetT newval
= md_chars_to_number (buf
, 4);
3557 MODIFY_VALUE (newval
, value
, 2, 16, 7);
3560 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3561 _("PC-relative offset not 4-byte-aligned"));
3562 if (value
< -0x100 || value
> 0xfc)
3563 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3564 _("PC-relative offset out of range"));
3566 md_number_to_chars (buf
, newval
, 4);
3575 /* Convert a floating-point number to target (IEEE) format. */
3578 md_atof (int type
, char *litP
, int *sizeP
)
3580 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
3583 /* Adjust the frags in SECTION (see tic6x_end). */
3586 tic6x_adjust_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT section
,
3587 void *dummy ATTRIBUTE_UNUSED
)
3589 segment_info_type
*info
;
3592 bfd_boolean have_code
= FALSE
;
3593 bfd_boolean have_non_code
= FALSE
;
3595 info
= seg_info (section
);
3599 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
3600 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
3601 switch (fragp
->fr_type
)
3603 case rs_machine_dependent
:
3604 if (fragp
->tc_frag_data
.is_insns
)
3610 if (fragp
->fr_fix
> 0)
3611 have_non_code
= TRUE
;
3615 have_non_code
= TRUE
;
3619 /* Process alignment requirements in a code-only section. */
3620 if (have_code
&& !have_non_code
)
3622 /* If we need to insert an odd number of instructions to meet an
3623 alignment requirement, there must have been an odd number of
3624 instructions since the last 8-byte-aligned execute packet
3625 boundary. So there must have been an execute packet with an
3626 odd number (and so a number fewer than 8) of instructions
3627 into which we can insert a NOP without breaking any previous
3630 If then we need to insert a number 2 mod 4 of instructions,
3631 the number of instructions since the last 16-byte-aligned
3632 execute packet boundary must be 2 mod 4. So between that
3633 boundary and the following 8-byte-aligned boundary there must
3634 either be at least one execute packet with 2-mod-4
3635 instructions, or at least two with an odd number of
3636 instructions; again, greedily inserting NOPs as soon as
3637 possible suffices to meet the alignment requirement.
3639 If then we need to insert 4 instructions, we look between the
3640 last 32-byte-aligned boundary and the following
3641 16-byte-aligned boundary. The sizes of the execute packets
3642 in this range total 4 instructions mod 8, so again there is
3643 room for greedy insertion of NOPs to meet the alignment
3644 requirement, and before any intermediate point with 8-byte
3645 (2-instruction) alignment requirement the sizes of execute
3646 packets (and so the room for NOPs) will total 2 instructions
3647 mod 4 so greedy insertion will not break such alignments.
3649 So we can always meet these alignment requirements by
3650 inserting NOPs in parallel with existing execute packets, and
3651 by induction the approach described above inserts the minimum
3652 number of such NOPs. */
3654 /* The number of NOPs we are currently looking to insert, if we
3655 have gone back to insert NOPs. */
3656 unsigned int want_insert
= 0;
3658 /* Out of that number, the number inserted so far in the current
3659 stage of the above algorithm. */
3660 unsigned int want_insert_done_so_far
= 0;
3662 /* The position mod 32 at the start of the current frag. */
3663 unsigned int pos
= 0;
3665 /* The locations in the frag chain of the most recent frags at
3666 the start of which there is the given alignment. */
3667 frchainS
*frchp_last32
, *frchp_last16
, *frchp_last8
;
3668 fragS
*fragp_last32
, *fragp_last16
, *fragp_last8
;
3669 unsigned int pos_last32
, pos_last16
, pos_last8
;
3671 frchp_last32
= frchp_last16
= frchp_last8
= info
->frchainP
;
3672 fragp_last32
= fragp_last16
= fragp_last8
= info
->frchainP
->frch_root
;
3673 pos_last32
= pos_last16
= pos_last8
= 0;
3675 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
3676 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
3679 bfd_boolean go_back
= FALSE
;
3680 frchainS
*frchp_next
;
3683 if (fragp
->fr_type
!= rs_machine_dependent
)
3686 if (fragp
->tc_frag_data
.is_insns
3687 && pos
+ fragp
->fr_fix
> 32
3688 && !fragp
->tc_frag_data
.can_cross_fp_boundary
)
3690 /* As described above, we should always have met an
3691 alignment requirement by the time we come back to
3698 want_insert
= (32 - pos
) >> 2;
3699 if (want_insert
> 7)
3701 want_insert_done_so_far
= 0;
3705 if (!fragp
->tc_frag_data
.is_insns
)
3707 unsigned int would_insert_bytes
;
3709 if (!(pos
& ((1 << fragp
->fr_offset
) - 1)))
3710 /* This alignment requirement is already met. */
3713 /* As described above, we should always have met an
3714 alignment requirement by the time we come back to
3719 /* We may not be able to meet this requirement within
3720 the given number of characters. */
3722 = ((1 << fragp
->fr_offset
)
3723 - (pos
& ((1 << fragp
->fr_offset
) - 1)));
3725 if (fragp
->fr_subtype
!= 0
3726 && would_insert_bytes
> fragp
->fr_subtype
)
3729 /* An unmet alignment must be 8, 16 or 32 bytes;
3730 smaller ones must always be met within code-only
3731 sections and larger ones cause the section not to
3733 if (fragp
->fr_offset
!= 3
3734 && fragp
->fr_offset
!= 4
3735 && fragp
->fr_offset
!= 5)
3738 if (would_insert_bytes
& 3)
3740 want_insert
= would_insert_bytes
>> 2;
3741 if (want_insert
> 7)
3743 want_insert_done_so_far
= 0;
3746 else if (want_insert
&& !go_back
)
3748 unsigned int num_insns
= fragp
->fr_fix
>> 2;
3749 unsigned int max_poss_nops
= 8 - num_insns
;
3753 unsigned int cur_want_nops
, max_want_nops
, do_nops
, i
;
3755 if (want_insert
& 1)
3757 else if (want_insert
& 2)
3759 else if (want_insert
& 4)
3764 max_want_nops
= cur_want_nops
- want_insert_done_so_far
;
3766 do_nops
= (max_poss_nops
< max_want_nops
3769 for (i
= 0; i
< do_nops
; i
++)
3771 md_number_to_chars (fragp
->fr_literal
+ fragp
->fr_fix
,
3773 if (target_big_endian
)
3774 fragp
->fr_literal
[fragp
->fr_fix
- 1] |= 0x1;
3776 fragp
->fr_literal
[fragp
->fr_fix
- 4] |= 0x1;
3780 want_insert_done_so_far
+= do_nops
;
3781 if (want_insert_done_so_far
== cur_want_nops
)
3783 want_insert
-= want_insert_done_so_far
;
3784 want_insert_done_so_far
= 0;
3792 if (want_insert
& 1)
3794 frchp
= frchp_last8
;
3795 fragp
= fragp_last8
;
3798 else if (want_insert
& 2)
3800 frchp
= frchp_last8
= frchp_last16
;
3801 fragp
= fragp_last8
= fragp_last16
;
3802 pos
= pos_last8
= pos_last16
;
3804 else if (want_insert
& 4)
3806 frchp
= frchp_last8
= frchp_last16
= frchp_last32
;
3807 fragp
= fragp_last8
= fragp_last16
= fragp_last32
;
3808 pos
= pos_last8
= pos_last16
= pos_last32
;
3816 /* Update current position for moving past a code
3818 pos
+= fragp
->fr_fix
;
3821 fragp_next
= fragp
->fr_next
;
3822 if (fragp_next
== NULL
)
3824 frchp_next
= frchp
->frch_next
;
3825 if (frchp_next
!= NULL
)
3826 fragp_next
= frchp_next
->frch_root
;
3830 frchp_last8
= frchp_next
;
3831 fragp_last8
= fragp_next
;
3836 frchp_last16
= frchp_next
;
3837 fragp_last16
= fragp_next
;
3842 frchp_last32
= frchp_next
;
3843 fragp_last32
= fragp_next
;
3849 /* Now convert the machine-dependent frags to machine-independent
3851 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
3852 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
3854 if (fragp
->fr_type
== rs_machine_dependent
)
3856 if (fragp
->tc_frag_data
.is_insns
)
3860 fragp
->fr_type
= rs_align_code
;
3862 *fragp
->fr_literal
= 0;
3868 /* Initialize the machine-dependent parts of a frag. */
3871 tic6x_frag_init (fragS
*fragp
)
3873 fragp
->tc_frag_data
.is_insns
= FALSE
;
3874 fragp
->tc_frag_data
.can_cross_fp_boundary
= FALSE
;
3877 /* Set an attribute if it has not already been set by the user. */
3880 tic6x_set_attribute_int (int tag
, int value
)
3883 || tag
>= NUM_KNOWN_OBJ_ATTRIBUTES
)
3885 if (!tic6x_attributes_set_explicitly
[tag
])
3886 bfd_elf_add_proc_attr_int (stdoutput
, tag
, value
);
3889 /* Set object attributes deduced from the input file and command line
3890 rather than given explicitly. */
3892 tic6x_set_attributes (void)
3894 if (tic6x_arch_attribute
== C6XABI_Tag_CPU_arch_none
)
3895 tic6x_arch_attribute
= C6XABI_Tag_CPU_arch_C674X
;
3897 tic6x_set_attribute_int (Tag_C6XABI_Tag_CPU_arch
, tic6x_arch_attribute
);
3900 /* Do machine-dependent manipulations of the frag chains after all
3901 input has been read and before the machine-independent sizing and
3907 /* Set object attributes at this point if not explicitly set. */
3908 tic6x_set_attributes ();
3910 /* Meeting alignment requirements may require inserting NOPs in
3911 parallel in execute packets earlier in the segment. Future
3912 16-bit instruction generation involves whole-segment optimization
3913 to determine the best choice and ordering of 32-bit or 16-bit
3914 instructions. This doesn't fit will in the general relaxation
3915 framework, so handle alignment and 16-bit instruction generation
3917 bfd_map_over_sections (stdoutput
, tic6x_adjust_section
, NULL
);
3920 /* No machine-dependent frags at this stage; all converted in
3924 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec ATTRIBUTE_UNUSED
,
3925 fragS
*fragp ATTRIBUTE_UNUSED
)
3930 /* No machine-dependent frags at this stage; all converted in
3934 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
3935 segT seg ATTRIBUTE_UNUSED
)
3940 /* Put a number into target byte order. */
3943 md_number_to_chars (char *buf
, valueT val
, int n
)
3945 if (target_big_endian
)
3946 number_to_chars_bigendian (buf
, val
, n
);
3948 number_to_chars_littleendian (buf
, val
, n
);
3951 /* Machine-dependent operand parsing not currently needed. */
3954 md_operand (expressionS
*op ATTRIBUTE_UNUSED
)
3958 /* PC-relative operands are relative to the start of the fetch
3962 tic6x_pcrel_from_section (fixS
*fixp
, segT sec
)
3964 if (fixp
->fx_addsy
!= NULL
3965 && (!S_IS_DEFINED (fixp
->fx_addsy
)
3966 || S_GET_SEGMENT (fixp
->fx_addsy
) != sec
))
3968 return (fixp
->fx_where
+ fixp
->fx_frag
->fr_address
) & ~(long) 0x1f;
3971 /* Round up a section size to the appropriate boundary. */
3974 md_section_align (segT segment ATTRIBUTE_UNUSED
,
3977 /* Round up section sizes to ensure that text sections consist of
3978 whole fetch packets. */
3979 int align
= bfd_get_section_alignment (stdoutput
, segment
);
3980 return ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
3983 /* No special undefined symbol handling needed for now. */
3986 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
3991 /* Translate internal representation of relocation info to BFD target
3995 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
3998 bfd_reloc_code_real_type r_type
;
4000 reloc
= xmalloc (sizeof (arelent
));
4001 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
4002 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
4003 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4004 reloc
->addend
= (tic6x_generate_rela
? fixp
->fx_offset
: 0);
4005 r_type
= fixp
->fx_r_type
;
4006 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
4008 if (reloc
->howto
== NULL
)
4010 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4011 _("Cannot represent relocation type %s"),
4012 bfd_get_reloc_code_name (r_type
));
4016 /* Correct for adjustments bfd_install_relocation will make. */
4017 if (reloc
->howto
->pcrel_offset
&& reloc
->howto
->partial_inplace
)
4018 reloc
->addend
+= reloc
->address
;