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 "elf32-tic6x.h"
29 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit
30 host gives identical results to a 32-bit host. */
31 #define TRUNC(X) ((valueT) (X) & 0xffffffffU)
32 #define SEXT(X) ((TRUNC (X) ^ 0x80000000U) - 0x80000000U)
34 const char comment_chars
[] = ";";
35 const char line_comment_chars
[] = "#*;";
36 const char line_separator_chars
[] = "@";
38 const char EXP_CHARS
[] = "eE";
39 const char FLT_CHARS
[] = "dDfF";
41 const char *md_shortopts
= "";
45 OPTION_MARCH
= OPTION_MD_BASE
,
49 OPTION_MLITTLE_ENDIAN
,
53 struct option md_longopts
[] =
55 { "march", required_argument
, NULL
, OPTION_MARCH
},
56 { "matomic", no_argument
, NULL
, OPTION_MATOMIC
},
57 { "mno-atomic", no_argument
, NULL
, OPTION_MNO_ATOMIC
},
58 { "mbig-endian", no_argument
, NULL
, OPTION_MBIG_ENDIAN
},
59 { "mlittle-endian", no_argument
, NULL
, OPTION_MLITTLE_ENDIAN
},
60 { "mgenerate-rel", no_argument
, NULL
, OPTION_MGENERATE_REL
},
61 { NULL
, no_argument
, NULL
, 0 }
63 size_t md_longopts_size
= sizeof (md_longopts
);
65 /* Whether to enable atomic instructions. 1 to enable them, 0 to
66 disable, -1 to default from architecture. */
67 static int tic6x_atomic
= -1;
69 /* The instructions enabled based only on the selected architecture
70 (all instructions, if no architecture specified). Atomic
71 instructions may be enabled or disabled separately. */
72 static unsigned short tic6x_arch_enable
= (TIC6X_INSN_C62X
80 /* The instructions enabled based on the current set of features
81 (architecture, as modified by other options). */
82 static unsigned short tic6x_features
;
84 /* The number of registers in each register file supported by the
85 current architecture. */
86 static unsigned int tic6x_num_registers
;
88 /* Whether predication on A0 is possible. */
89 static bfd_boolean tic6x_predicate_a0
;
91 /* Whether execute packets can cross fetch packet boundaries. */
92 static bfd_boolean tic6x_can_cross_fp_boundary
;
94 /* Whether there are constraints on simultaneous reads and writes of
96 static bfd_boolean tic6x_long_data_constraints
;
98 /* Whether compact instructions are available. */
99 static bfd_boolean tic6x_compact_insns
;
101 /* Whether to generate RELA relocations. */
102 static bfd_boolean tic6x_generate_rela
= TRUE
;
104 /* Table of supported architecture variants. */
108 unsigned short features
;
110 static const tic6x_arch_table tic6x_arches
[] =
112 { "c62x", TIC6X_INSN_C62X
},
113 { "c64x", TIC6X_INSN_C62X
| TIC6X_INSN_C64X
},
114 { "c64x+", TIC6X_INSN_C62X
| TIC6X_INSN_C64X
| TIC6X_INSN_C64XP
},
115 { "c67x", TIC6X_INSN_C62X
| TIC6X_INSN_C67X
},
116 { "c67x+", TIC6X_INSN_C62X
| TIC6X_INSN_C67X
| TIC6X_INSN_C67XP
},
117 { "c674x", (TIC6X_INSN_C62X
122 | TIC6X_INSN_C674X
) }
125 /* Update the selected architecture based on ARCH, giving an error if
126 ARCH is an invalid value. Does not call tic6x_update_features; the
127 caller must do that if necessary. */
130 tic6x_use_arch (const char *arch
)
134 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
135 if (strcmp (arch
, tic6x_arches
[i
].arch
) == 0)
137 tic6x_arch_enable
= tic6x_arches
[i
].features
;
141 as_bad (_("unknown architecture '%s'"), arch
);
144 /* Parse a target-specific option. */
147 md_parse_option (int c
, char *arg
)
152 tic6x_use_arch (arg
);
159 case OPTION_MNO_ATOMIC
:
163 case OPTION_MBIG_ENDIAN
:
164 target_big_endian
= 1;
167 case OPTION_MLITTLE_ENDIAN
:
168 target_big_endian
= 0;
171 case OPTION_MGENERATE_REL
:
172 tic6x_generate_rela
= FALSE
;
182 md_show_usage (FILE *stream ATTRIBUTE_UNUSED
)
186 fputc ('\n', stream
);
187 fprintf (stream
, _("TMS320C6000 options:\n"));
188 fprintf (stream
, _(" -march=ARCH enable instructions from architecture ARCH\n"));
189 fprintf (stream
, _(" -matomic enable atomic operation instructions\n"));
190 fprintf (stream
, _(" -mno-atomic disable atomic operation instructions\n"));
191 fprintf (stream
, _(" -mbig-endian generate big-endian code\n"));
192 fprintf (stream
, _(" -mlittle-endian generate little-endian code\n"));
193 /* -mgenerate-rel is only for testsuite use and is deliberately
196 fputc ('\n', stream
);
197 fprintf (stream
, _("Supported ARCH values are:"));
198 for (i
= 0; i
< ARRAY_SIZE (tic6x_arches
); i
++)
199 fprintf (stream
, " %s", tic6x_arches
[i
].arch
);
200 fputc ('\n', stream
);
203 /* Update enabled features based on the current architecture and
206 tic6x_update_features (void)
208 switch (tic6x_atomic
)
211 tic6x_features
= tic6x_arch_enable
;
215 tic6x_features
= tic6x_arch_enable
& ~TIC6X_INSN_ATOMIC
;
219 tic6x_features
= tic6x_arch_enable
| TIC6X_INSN_ATOMIC
;
227 = (tic6x_arch_enable
& (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? 32 : 16;
229 tic6x_predicate_a0
= (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? TRUE
: FALSE
;
231 tic6x_can_cross_fp_boundary
233 & (TIC6X_INSN_C64X
| TIC6X_INSN_C67XP
)) ? TRUE
: FALSE
;
235 tic6x_long_data_constraints
236 = (tic6x_arch_enable
& TIC6X_INSN_C64X
) ? FALSE
: TRUE
;
238 tic6x_compact_insns
= (tic6x_arch_enable
& TIC6X_INSN_C64XP
) ? TRUE
: FALSE
;
241 /* Do configuration after all options have been parsed. */
244 tic6x_after_parse_args (void)
246 tic6x_update_features ();
249 /* Parse a .arch directive. */
252 s_tic6x_arch (int ignored ATTRIBUTE_UNUSED
)
257 arch
= input_line_pointer
;
258 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
259 input_line_pointer
++;
260 c
= *input_line_pointer
;
261 *input_line_pointer
= 0;
263 tic6x_use_arch (arch
);
264 tic6x_update_features ();
265 *input_line_pointer
= c
;
266 demand_empty_rest_of_line ();
269 /* Parse a .atomic directive. */
272 s_tic6x_atomic (int ignored ATTRIBUTE_UNUSED
)
275 tic6x_update_features ();
276 demand_empty_rest_of_line ();
279 /* Parse a .noatomic directive. */
282 s_tic6x_noatomic (int ignored ATTRIBUTE_UNUSED
)
285 tic6x_update_features ();
286 demand_empty_rest_of_line ();
289 /* Parse a .nocmp directive. */
292 s_tic6x_nocmp (int ignored ATTRIBUTE_UNUSED
)
294 seg_info (now_seg
)->tc_segment_info_data
.nocmp
= TRUE
;
295 demand_empty_rest_of_line ();
298 const pseudo_typeS md_pseudo_table
[] =
300 { "arch", s_tic6x_arch
, 0 },
301 { "atomic", s_tic6x_atomic
, 0 },
302 { "noatomic", s_tic6x_noatomic
, 0 },
303 { "nocmp", s_tic6x_nocmp
, 0 },
308 /* Hash table of opcodes. For each opcode name, this stores a pointer
309 to a tic6x_opcode_list listing (in an arbitrary order) all opcode
310 table entries with that name. */
311 static struct hash_control
*opcode_hash
;
313 /* Initialize the assembler (called once at assembler startup). */
320 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, 0);
322 /* Insert opcodes into the hash table. */
323 opcode_hash
= hash_new ();
324 for (id
= 0; id
< tic6x_opcode_max
; id
++)
327 tic6x_opcode_list
*opc
= xmalloc (sizeof (tic6x_opcode_list
));
330 opc
->next
= hash_find (opcode_hash
, tic6x_opcode_table
[id
].name
);
331 if ((errmsg
= hash_jam (opcode_hash
, tic6x_opcode_table
[id
].name
, opc
))
333 as_fatal ("%s", _(errmsg
));
337 /* Whether the current line being parsed had the "||" parallel bars. */
338 static bfd_boolean tic6x_line_parallel
;
340 /* Whether the current line being parsed started "||^" to indicate an
341 SPMASKed parallel instruction. */
342 static bfd_boolean tic6x_line_spmask
;
344 /* If the current line being parsed had an instruction predicate, the
345 creg value for that predicate (which must be nonzero); otherwise
347 static unsigned int tic6x_line_creg
;
349 /* If the current line being parsed had an instruction predicate, the
350 z value for that predicate; otherwise 0. */
351 static unsigned int tic6x_line_z
;
353 /* Return 1 (updating input_line_pointer as appropriate) if the line
354 starting with C (immediately before input_line_pointer) starts with
355 pre-opcode text appropriate for this target, 0 otherwise. */
358 tic6x_unrecognized_line (int c
)
363 bfd_boolean bad_predicate
;
368 if (input_line_pointer
[0] == '|')
370 if (input_line_pointer
[1] == '^')
372 tic6x_line_spmask
= TRUE
;
373 input_line_pointer
+= 2;
376 input_line_pointer
+= 1;
377 if (tic6x_line_parallel
)
378 as_bad (_("multiple '||' on same line"));
379 tic6x_line_parallel
= TRUE
;
381 as_bad (_("'||' after predicate"));
387 /* If it doesn't look like a predicate at all, just return 0.
388 If it looks like one but not a valid one, give a better
390 p
= input_line_pointer
;
391 while (*p
!= ']' && !is_end_of_line
[(unsigned char) *p
])
396 p
= input_line_pointer
;
398 bad_predicate
= FALSE
;
404 if (*p
== 'A' || *p
== 'a')
406 else if (*p
== 'B' || *p
== 'b')
410 areg
= TRUE
; /* Avoid uninitialized warning. */
411 bad_predicate
= TRUE
;
416 if (*p
!= '0' && *p
!= '1' && *p
!= '2')
417 bad_predicate
= TRUE
;
418 else if (p
[1] != ']')
419 bad_predicate
= TRUE
;
421 input_line_pointer
= p
+ 2;
425 as_bad (_("multiple predicates on same line"));
431 as_bad (_("bad predicate '%s'"), input_line_pointer
- 1);
433 input_line_pointer
= endp
;
440 tic6x_line_creg
= (areg
? 6 : 1);
441 if (areg
&& !tic6x_predicate_a0
)
442 as_bad (_("predication on A0 not supported on this architecture"));
446 tic6x_line_creg
= (areg
? 4 : 2);
450 tic6x_line_creg
= (areg
? 5 : 3);
465 /* Do any target-specific handling of a label required. */
468 tic6x_frob_label (symbolS
*sym
)
470 segment_info_type
*si
;
471 tic6x_label_list
*list
;
473 if (tic6x_line_parallel
)
475 as_bad (_("label after '||'"));
476 tic6x_line_parallel
= FALSE
;
477 tic6x_line_spmask
= FALSE
;
481 as_bad (_("label after predicate"));
486 si
= seg_info (now_seg
);
487 list
= si
->tc_segment_info_data
.label_list
;
488 si
->tc_segment_info_data
.label_list
= xmalloc (sizeof (tic6x_label_list
));
489 si
->tc_segment_info_data
.label_list
->next
= list
;
490 si
->tc_segment_info_data
.label_list
->label
= sym
;
492 /* Defining tc_frob_label overrides the ELF definition of
493 obj_frob_label, so we need to apply its effects here. */
494 dwarf2_emit_label (sym
);
497 /* At end-of-line, give errors for start-of-line decorations that
498 needed an instruction but were not followed by one. */
501 tic6x_end_of_line (void)
503 if (tic6x_line_parallel
)
505 as_bad (_("'||' not followed by instruction"));
506 tic6x_line_parallel
= FALSE
;
507 tic6x_line_spmask
= FALSE
;
511 as_bad (_("predicate not followed by instruction"));
517 /* Do any target-specific handling of the start of a logical line. */
520 tic6x_start_line_hook (void)
522 tic6x_end_of_line ();
525 /* Do target-specific handling immediately after an input file from
526 the command line, and any other inputs it includes, have been
532 tic6x_end_of_line ();
535 /* Do target-specific initialization after arguments have been
536 processed and the output file created. */
539 tic6x_init_after_args (void)
541 elf32_tic6x_set_use_rela_p (stdoutput
, tic6x_generate_rela
);
544 /* Free LIST of labels (possibly NULL). */
547 tic6x_free_label_list (tic6x_label_list
*list
)
551 tic6x_label_list
*old
= list
;
558 /* Handle a data alignment of N bytes. */
561 tic6x_cons_align (int n ATTRIBUTE_UNUSED
)
563 segment_info_type
*seginfo
= seg_info (now_seg
);
565 /* Data means there is no current execute packet, and that any label
566 applies to that data rather than a subsequent instruction. */
567 tic6x_free_label_list (seginfo
->tc_segment_info_data
.label_list
);
568 seginfo
->tc_segment_info_data
.label_list
= NULL
;
569 seginfo
->tc_segment_info_data
.execute_packet_frag
= NULL
;
570 seginfo
->tc_segment_info_data
.last_insn_lsb
= NULL
;
571 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
574 /* Handle an alignment directive. Return TRUE if the
575 machine-independent frag generation should be skipped. */
578 tic6x_do_align (int n
, char *fill
, int len ATTRIBUTE_UNUSED
, int max
)
580 /* Given code alignments of 4, 8, 16 or 32 bytes, we try to handle
581 them in the md_end pass by inserting NOPs in parallel with
582 previous instructions. We only do this in sections containing
583 nothing but instructions. Code alignments of 1 or 2 bytes have
584 no effect in such sections (but we record them with
585 machine-dependent frags anyway so they can be skipped or
586 converted to machine-independent), while those of more than 64
587 bytes cannot reliably be handled in this way. */
593 && subseg_text_p (now_seg
))
601 /* Machine-independent code would generate a frag here, but we
602 wish to handle it in a machine-dependent way. */
603 if (frag_now_fix () != 0)
605 if (frag_now
->fr_type
!= rs_machine_dependent
)
606 frag_wane (frag_now
);
611 align_frag
= frag_now
;
612 p
= frag_var (rs_machine_dependent
, 32, 32, max
, NULL
, n
, NULL
);
613 /* This must be the same as the frag to which a pointer was just
615 if (p
!= align_frag
->fr_literal
)
617 align_frag
->tc_frag_data
.is_insns
= FALSE
;
624 /* Types of operand for parsing purposes. These are used as bit-masks
625 to tell tic6x_parse_operand what forms of operand are
627 #define TIC6X_OP_EXP 0x0001u
628 #define TIC6X_OP_REG 0x0002u
629 #define TIC6X_OP_REGPAIR 0x0004u
630 #define TIC6X_OP_IRP 0x0008u
631 #define TIC6X_OP_NRP 0x0010u
632 /* With TIC6X_OP_MEM_NOUNREG, the contents of a () offset are always
633 interpreted as an expression, which may be a symbol with the same
634 name as a register that ends up being implicitly DP-relative. With
635 TIC6X_OP_MEM_UNREG, the contents of a () offset are interpreted as
636 a register if they match one, and failing that as an expression,
637 which must be constant. */
638 #define TIC6X_OP_MEM_NOUNREG 0x0020u
639 #define TIC6X_OP_MEM_UNREG 0x0040u
640 #define TIC6X_OP_CTRL 0x0080u
641 #define TIC6X_OP_FUNC_UNIT 0x0100u
643 /* A register or register pair read by the assembler. */
646 /* The side the register is on (1 or 2). */
648 /* The register number (0 to 31). */
652 /* Types of modification of a base address. */
658 tic6x_mem_mod_preinc
,
659 tic6x_mem_mod_predec
,
660 tic6x_mem_mod_postinc
,
661 tic6x_mem_mod_postdec
664 /* Scaled [] or unscaled () nature of an offset. */
669 tic6x_offset_unscaled
672 /* A memory operand read by the assembler. */
675 /* The base register. */
676 tic6x_register base_reg
;
677 /* How the base register is modified. */
679 /* Whether there is an offset (required with plain "+" and "-"), and
680 whether it is scaled or unscaled if so. */
681 tic6x_mem_scaling scaled
;
682 /* Whether the offset is a register (TRUE) or an expression
684 bfd_boolean offset_is_reg
;
693 /* A functional unit in SPMASK operands read by the assembler. */
696 /* The basic unit. */
697 tic6x_func_unit_base base
;
698 /* The side (1 or 2). */
700 } tic6x_func_unit_operand
;
702 /* An operand read by the assembler. */
705 /* The syntactic form of the operand, as one of the bit-masks
708 /* The operand value. */
711 /* An expression: TIC6X_OP_EXP. */
713 /* A register: TIC6X_OP_REG, TIC6X_OP_REGPAIR. */
715 /* A memory reference: TIC6X_OP_MEM_NOUNREG,
716 TIC6X_OP_MEM_UNREG. */
718 /* A control register: TIC6X_OP_CTRL. */
720 /* A functional unit: TIC6X_OP_FUNC_UNIT. */
721 tic6x_func_unit_operand func_unit
;
725 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
727 /* Parse a register operand, or part of an operand, starting at *P.
728 If syntactically OK (including that the number is in the range 0 to
729 31, but not necessarily in range for this architecture), return
730 TRUE, putting the register side and number in *REG and update *P to
731 point immediately after the register number; otherwise return FALSE
732 without changing *P (but possibly changing *REG). Do not print any
736 tic6x_parse_register (char **p
, tic6x_register
*reg
)
757 if (*r
>= '0' && *r
<= '9')
765 if (reg
->num
> 0 && *r
>= '0' && *r
<= '9')
767 reg
->num
= reg
->num
* 10 + (*r
- '0');
771 if (*r
>= '0' && *r
<= '9')
780 /* Parse the initial two characters of a functional unit name starting
781 at *P. If OK, set *BASE and *SIDE and return TRUE; otherwise,
785 tic6x_parse_func_unit_base (char *p
, tic6x_func_unit_base
*base
,
788 bfd_boolean good_func_unit
= TRUE
;
789 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
790 unsigned int maybe_side
= 0;
796 maybe_base
= tic6x_func_unit_d
;
801 maybe_base
= tic6x_func_unit_l
;
806 maybe_base
= tic6x_func_unit_m
;
811 maybe_base
= tic6x_func_unit_s
;
815 good_func_unit
= FALSE
;
831 good_func_unit
= FALSE
;
841 return good_func_unit
;
844 /* Parse an operand starting at *P. If the operand parses OK, return
845 TRUE and store the value in *OP; otherwise return FALSE (possibly
846 changing *OP). In any case, update *P to point to the following
847 comma or end of line. The possible operand forms are given by
848 OP_FORMS. For diagnostics, this is operand OPNO of an opcode
849 starting at STR, length OPC_LEN. */
852 tic6x_parse_operand (char **p
, tic6x_operand
*op
, unsigned int op_forms
,
853 char *str
, int opc_len
, unsigned int opno
)
855 bfd_boolean operand_parsed
= FALSE
;
858 if ((op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
859 == (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
))
862 /* Check for functional unit names for SPMASK and SPMASKR. */
863 if (!operand_parsed
&& (op_forms
& TIC6X_OP_FUNC_UNIT
))
865 tic6x_func_unit_base base
= tic6x_func_unit_nfu
;
866 unsigned int side
= 0;
868 if (tic6x_parse_func_unit_base (q
, &base
, &side
))
872 skip_whitespace (rq
);
873 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
875 op
->form
= TIC6X_OP_FUNC_UNIT
;
876 op
->value
.func_unit
.base
= base
;
877 op
->value
.func_unit
.side
= side
;
878 operand_parsed
= TRUE
;
884 /* Check for literal "irp". */
885 if (!operand_parsed
&& (op_forms
& TIC6X_OP_IRP
))
887 if ((q
[0] == 'i' || q
[0] == 'I')
888 && (q
[1] == 'r' || q
[1] == 'R')
889 && (q
[2] == 'p' || q
[2] == 'P'))
893 skip_whitespace (rq
);
894 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
896 op
->form
= TIC6X_OP_IRP
;
897 operand_parsed
= TRUE
;
903 /* Check for literal "nrp". */
904 if (!operand_parsed
&& (op_forms
& TIC6X_OP_NRP
))
906 if ((q
[0] == 'n' || q
[0] == 'N')
907 && (q
[1] == 'r' || q
[1] == 'R')
908 && (q
[2] == 'p' || q
[2] == 'P'))
912 skip_whitespace (rq
);
913 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
915 op
->form
= TIC6X_OP_NRP
;
916 operand_parsed
= TRUE
;
922 /* Check for control register names. */
923 if (!operand_parsed
&& (op_forms
& TIC6X_OP_CTRL
))
927 for (crid
= 0; crid
< tic6x_ctrl_max
; crid
++)
929 size_t len
= strlen (tic6x_ctrl_table
[crid
].name
);
931 if (strncasecmp (tic6x_ctrl_table
[crid
].name
, q
, len
) == 0)
935 skip_whitespace (rq
);
936 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
938 op
->form
= TIC6X_OP_CTRL
;
939 op
->value
.ctrl
= crid
;
940 operand_parsed
= TRUE
;
942 if (!(tic6x_ctrl_table
[crid
].isa_variants
& tic6x_features
))
943 as_bad (_("control register '%s' not supported "
944 "on this architecture"),
945 tic6x_ctrl_table
[crid
].name
);
951 /* See if this looks like a memory reference. */
953 && (op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
)))
955 bfd_boolean mem_ok
= TRUE
;
957 tic6x_mem_mod mem_mod
= tic6x_mem_mod_none
;
958 tic6x_register base_reg
;
959 bfd_boolean require_offset
, permit_offset
;
960 tic6x_mem_scaling scaled
;
961 bfd_boolean offset_is_reg
;
962 expressionS offset_exp
;
963 tic6x_register offset_reg
;
972 skip_whitespace (mq
);
978 mem_mod
= tic6x_mem_mod_preinc
;
983 mem_mod
= tic6x_mem_mod_plus
;
991 mem_mod
= tic6x_mem_mod_predec
;
996 mem_mod
= tic6x_mem_mod_minus
;
1008 skip_whitespace (mq
);
1009 mem_ok
= tic6x_parse_register (&mq
, &base_reg
);
1012 if (mem_ok
&& mem_mod
== tic6x_mem_mod_none
)
1014 skip_whitespace (mq
);
1015 if (mq
[0] == '+' && mq
[1] == '+')
1017 mem_mod
= tic6x_mem_mod_postinc
;
1020 else if (mq
[0] == '-' && mq
[1] == '-')
1022 mem_mod
= tic6x_mem_mod_postdec
;
1027 if (mem_mod
== tic6x_mem_mod_none
)
1028 permit_offset
= FALSE
;
1030 permit_offset
= TRUE
;
1031 if (mem_mod
== tic6x_mem_mod_plus
|| mem_mod
== tic6x_mem_mod_minus
)
1032 require_offset
= TRUE
;
1034 require_offset
= FALSE
;
1035 scaled
= tic6x_offset_none
;
1036 offset_is_reg
= FALSE
;
1038 if (mem_ok
&& permit_offset
)
1042 skip_whitespace (mq
);
1046 scaled
= tic6x_offset_scaled
;
1052 scaled
= tic6x_offset_unscaled
;
1060 if (scaled
!= tic6x_offset_none
)
1062 skip_whitespace (mq
);
1063 if (scaled
== tic6x_offset_scaled
1064 || (op_forms
& TIC6X_OP_MEM_UNREG
))
1069 reg_ok
= tic6x_parse_register (&rq
, &offset_reg
);
1072 skip_whitespace (rq
);
1076 offset_is_reg
= TRUE
;
1082 char *save_input_line_pointer
;
1084 save_input_line_pointer
= input_line_pointer
;
1085 input_line_pointer
= mq
;
1086 expression (&offset_exp
);
1087 mq
= input_line_pointer
;
1088 input_line_pointer
= save_input_line_pointer
;
1090 skip_whitespace (mq
);
1098 if (mem_ok
&& require_offset
&& scaled
== tic6x_offset_none
)
1103 skip_whitespace (mq
);
1104 if (!is_end_of_line
[(unsigned char) *mq
] && *mq
!= ',')
1110 op
->form
= op_forms
& (TIC6X_OP_MEM_NOUNREG
| TIC6X_OP_MEM_UNREG
);
1111 op
->value
.mem
.base_reg
= base_reg
;
1112 op
->value
.mem
.mod
= mem_mod
;
1113 op
->value
.mem
.scaled
= scaled
;
1114 op
->value
.mem
.offset_is_reg
= offset_is_reg
;
1116 op
->value
.mem
.offset
.reg
= offset_reg
;
1118 op
->value
.mem
.offset
.exp
= offset_exp
;
1119 operand_parsed
= TRUE
;
1121 if (base_reg
.num
>= tic6x_num_registers
)
1122 as_bad (_("register number %u not supported on this architecture"),
1124 if (offset_is_reg
&& offset_reg
.num
>= tic6x_num_registers
)
1125 as_bad (_("register number %u not supported on this architecture"),
1130 /* See if this looks like a register or register pair. */
1131 if (!operand_parsed
&& (op_forms
& (TIC6X_OP_REG
| TIC6X_OP_REGPAIR
)))
1133 tic6x_register first_reg
, second_reg
;
1137 reg_ok
= tic6x_parse_register (&rq
, &first_reg
);
1141 if (*rq
== ':' && (op_forms
& TIC6X_OP_REGPAIR
))
1144 reg_ok
= tic6x_parse_register (&rq
, &second_reg
);
1147 skip_whitespace (rq
);
1148 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1150 if ((second_reg
.num
& 1)
1151 || (first_reg
.num
!= second_reg
.num
+ 1)
1152 || (first_reg
.side
!= second_reg
.side
))
1153 as_bad (_("register pair for operand %u of '%.*s'"
1154 " not a valid even/odd pair"), opno
,
1156 op
->form
= TIC6X_OP_REGPAIR
;
1157 op
->value
.reg
= second_reg
;
1158 operand_parsed
= TRUE
;
1163 else if (op_forms
& TIC6X_OP_REG
)
1165 skip_whitespace (rq
);
1166 if (is_end_of_line
[(unsigned char) *rq
] || *rq
== ',')
1168 op
->form
= TIC6X_OP_REG
;
1169 op
->value
.reg
= first_reg
;
1170 operand_parsed
= TRUE
;
1177 if (first_reg
.num
>= tic6x_num_registers
)
1178 as_bad (_("register number %u not supported on this architecture"),
1180 if (op
->form
== TIC6X_OP_REGPAIR
1181 && second_reg
.num
>= tic6x_num_registers
)
1182 as_bad (_("register number %u not supported on this architecture"),
1187 /* Otherwise, parse it as an expression. */
1188 if (!operand_parsed
&& (op_forms
& TIC6X_OP_EXP
))
1190 char *save_input_line_pointer
;
1192 save_input_line_pointer
= input_line_pointer
;
1193 input_line_pointer
= q
;
1194 op
->form
= TIC6X_OP_EXP
;
1195 expression (&op
->value
.exp
);
1196 q
= input_line_pointer
;
1197 input_line_pointer
= save_input_line_pointer
;
1198 operand_parsed
= TRUE
;
1203 /* Now the operand has been parsed, there must be nothing more
1204 before the comma or end of line. */
1205 skip_whitespace (q
);
1206 if (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1208 operand_parsed
= FALSE
;
1209 as_bad (_("junk after operand %u of '%.*s'"), opno
,
1211 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1217 /* This could not be parsed as any acceptable form of
1221 case TIC6X_OP_REG
| TIC6X_OP_REGPAIR
:
1222 as_bad (_("bad register or register pair for operand %u of '%.*s'"),
1223 opno
, opc_len
, str
);
1226 case TIC6X_OP_REG
| TIC6X_OP_CTRL
:
1228 as_bad (_("bad register for operand %u of '%.*s'"),
1229 opno
, opc_len
, str
);
1232 case TIC6X_OP_REGPAIR
:
1233 as_bad (_("bad register pair for operand %u of '%.*s'"),
1234 opno
, opc_len
, str
);
1237 case TIC6X_OP_FUNC_UNIT
:
1238 as_bad (_("bad functional unit for operand %u of '%.*s'"),
1239 opno
, opc_len
, str
);
1243 as_bad (_("bad operand %u of '%.*s'"),
1244 opno
, opc_len
, str
);
1248 while (!is_end_of_line
[(unsigned char) *q
] && *q
!= ',')
1252 return operand_parsed
;
1255 /* Table of assembler operators and associated O_* values. */
1260 } tic6x_operator_table
;
1261 static const tic6x_operator_table tic6x_operators
[] = {
1262 #define O_dsbt_index O_md1
1263 { "dsbt_index", O_dsbt_index
},
1266 #define O_dpr_got O_md3
1267 { "dpr_got", O_dpr_got
},
1268 #define O_dpr_byte O_md4
1269 { "dpr_byte", O_dpr_byte
},
1270 #define O_dpr_hword O_md5
1271 { "dpr_hword", O_dpr_hword
},
1272 #define O_dpr_word O_md6
1273 { "dpr_word", O_dpr_word
},
1276 /* Parse a name in some machine-specific way. Used on C6X to handle
1277 assembler operators. */
1280 tic6x_parse_name (const char *name
, expressionS
*exprP
,
1281 enum expr_mode mode ATTRIBUTE_UNUSED
, char *nextchar
)
1283 char *p
= input_line_pointer
;
1284 char c
, *name_start
, *name_end
;
1285 const char *inner_name
;
1287 operatorT op
= O_illegal
;
1293 for (i
= 0; i
< ARRAY_SIZE (tic6x_operators
); i
++)
1294 if (strcasecmp (name
+ 1, tic6x_operators
[i
].name
) == 0)
1296 op
= tic6x_operators
[i
].op
;
1300 if (op
== O_illegal
)
1303 *input_line_pointer
= *nextchar
;
1304 skip_whitespace (p
);
1308 *input_line_pointer
= 0;
1312 skip_whitespace (p
);
1314 if (!is_name_beginner (*p
))
1316 *input_line_pointer
= 0;
1322 while (is_part_of_name (*p
))
1325 skip_whitespace (p
);
1329 *input_line_pointer
= 0;
1333 input_line_pointer
= p
+ 1;
1334 *nextchar
= *input_line_pointer
;
1335 *input_line_pointer
= 0;
1339 inner_name
= name_start
;
1340 if (op
== O_dsbt_index
&& strcmp (inner_name
, "__c6xabi_DSBT_BASE") != 0)
1342 as_bad (_("$DSBT_INDEX must be used with __c6xabi_DSBT_BASE"));
1343 inner_name
= "__c6xabi_DSBT_BASE";
1345 sym
= symbol_find_or_make (inner_name
);
1349 exprP
->X_add_symbol
= sym
;
1350 exprP
->X_add_number
= 0;
1351 exprP
->X_op_symbol
= NULL
;
1357 /* Create a fixup for an expression. Same arguments as fix_new_exp,
1358 plus FIX_ADDA which is TRUE for ADDA instructions (to indicate that
1359 fixes resolving to constants should have those constants implicitly
1360 shifted) and FALSE otherwise, but look for C6X-specific expression
1361 types and adjust the relocations or give errors accordingly. */
1364 tic6x_fix_new_exp (fragS
*frag
, int where
, int size
, expressionS
*exp
,
1365 int pcrel
, bfd_reloc_code_real_type r_type
,
1366 bfd_boolean fix_adda
)
1368 bfd_reloc_code_real_type new_reloc
= BFD_RELOC_UNUSED
;
1376 case BFD_RELOC_C6000_SBR_U15_W
:
1377 new_reloc
= BFD_RELOC_C6000_DSBT_INDEX
;
1381 as_bad (_("$DSBT_INDEX not supported in this context"));
1389 case BFD_RELOC_C6000_SBR_U15_W
:
1390 new_reloc
= BFD_RELOC_C6000_SBR_GOT_U15_W
;
1394 as_bad (_("$GOT not supported in this context"));
1402 case BFD_RELOC_C6000_ABS_L16
:
1403 new_reloc
= BFD_RELOC_C6000_SBR_GOT_L16_W
;
1406 case BFD_RELOC_C6000_ABS_H16
:
1407 new_reloc
= BFD_RELOC_C6000_SBR_GOT_H16_W
;
1411 as_bad (_("$DPR_GOT not supported in this context"));
1419 case BFD_RELOC_C6000_ABS_S16
:
1420 new_reloc
= BFD_RELOC_C6000_SBR_S16
;
1423 case BFD_RELOC_C6000_ABS_L16
:
1424 new_reloc
= BFD_RELOC_C6000_SBR_L16_B
;
1427 case BFD_RELOC_C6000_ABS_H16
:
1428 new_reloc
= BFD_RELOC_C6000_SBR_H16_B
;
1432 as_bad (_("$DPR_BYTE not supported in this context"));
1440 case BFD_RELOC_C6000_ABS_L16
:
1441 new_reloc
= BFD_RELOC_C6000_SBR_L16_H
;
1444 case BFD_RELOC_C6000_ABS_H16
:
1445 new_reloc
= BFD_RELOC_C6000_SBR_H16_H
;
1449 as_bad (_("$DPR_HWORD not supported in this context"));
1457 case BFD_RELOC_C6000_ABS_L16
:
1458 new_reloc
= BFD_RELOC_C6000_SBR_L16_W
;
1461 case BFD_RELOC_C6000_ABS_H16
:
1462 new_reloc
= BFD_RELOC_C6000_SBR_H16_W
;
1466 as_bad (_("$DPR_WORD not supported in this context"));
1477 as_bad (_("invalid PC-relative operand"));
1483 if (new_reloc
== BFD_RELOC_UNUSED
)
1484 fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1486 fix
= fix_new (frag
, where
, size
, exp
->X_add_symbol
, exp
->X_add_number
,
1488 fix
->tc_fix_data
.fix_adda
= fix_adda
;
1491 /* Generate a fix for a constant (.word etc.). Needed to ensure these
1492 go through the error checking in tic6x_fix_new_exp. */
1495 tic6x_cons_fix_new (fragS
*frag
, int where
, int size
, expressionS
*exp
)
1497 bfd_reloc_code_real_type r_type
;
1502 r_type
= BFD_RELOC_8
;
1506 r_type
= BFD_RELOC_16
;
1510 r_type
= BFD_RELOC_32
;
1514 as_bad (_("no %d-byte relocations available"), size
);
1518 tic6x_fix_new_exp (frag
, where
, size
, exp
, 0, r_type
, FALSE
);
1521 /* Initialize target-specific fix data. */
1524 tic6x_init_fix_data (fixS
*fixP
)
1526 fixP
->tc_fix_data
.fix_adda
= FALSE
;
1529 /* Given the fine-grained form of an operand, return the coarse
1533 tic6x_coarse_operand_form (tic6x_operand_form form
)
1537 case tic6x_operand_asm_const
:
1538 case tic6x_operand_link_const
:
1539 return TIC6X_OP_EXP
;
1541 case tic6x_operand_reg
:
1542 case tic6x_operand_xreg
:
1543 case tic6x_operand_dreg
:
1544 case tic6x_operand_areg
:
1545 case tic6x_operand_retreg
:
1546 return TIC6X_OP_REG
;
1548 case tic6x_operand_regpair
:
1549 case tic6x_operand_xregpair
:
1550 case tic6x_operand_dregpair
:
1551 return TIC6X_OP_REGPAIR
;
1553 case tic6x_operand_irp
:
1554 return TIC6X_OP_IRP
;
1556 case tic6x_operand_nrp
:
1557 return TIC6X_OP_NRP
;
1559 case tic6x_operand_ctrl
:
1560 return TIC6X_OP_CTRL
;
1562 case tic6x_operand_mem_short
:
1563 case tic6x_operand_mem_long
:
1564 case tic6x_operand_mem_deref
:
1565 return TIC6X_OP_MEM_NOUNREG
;
1567 case tic6x_operand_mem_ndw
:
1568 return TIC6X_OP_MEM_UNREG
;
1570 case tic6x_operand_func_unit
:
1571 return TIC6X_OP_FUNC_UNIT
;
1578 /* How an operand may match or not match a desired form. If different
1579 instruction alternatives fail in different ways, the first failure
1580 in this list determines the diagnostic. */
1584 tic6x_match_matches
,
1585 /* Bad coarse form. */
1588 tic6x_match_non_const
,
1589 /* Register on wrong side. */
1590 tic6x_match_wrong_side
,
1591 /* Not a valid address register. */
1592 tic6x_match_bad_address
,
1593 /* Not a valid return address register. */
1594 tic6x_match_bad_return
,
1595 /* Control register not readable. */
1596 tic6x_match_ctrl_write_only
,
1597 /* Control register not writable. */
1598 tic6x_match_ctrl_read_only
,
1599 /* Not a valid memory reference for this instruction. */
1601 } tic6x_operand_match
;
1603 /* Return whether an operand matches the given fine-grained form and
1604 read/write usage, and, if it does not match, how it fails to match.
1605 The main functional unit side is SIDE; the cross-path side is CROSS
1606 (the same as SIDE if a cross path not used); the data side is
1608 static tic6x_operand_match
1609 tic6x_operand_matches_form (const tic6x_operand
*op
, tic6x_operand_form form
,
1610 tic6x_rw rw
, unsigned int side
, unsigned int cross
,
1611 unsigned int data_side
)
1613 unsigned int coarse
= tic6x_coarse_operand_form (form
);
1615 if (coarse
!= op
->form
)
1616 return tic6x_match_coarse
;
1620 case tic6x_operand_asm_const
:
1621 if (op
->value
.exp
.X_op
== O_constant
)
1622 return tic6x_match_matches
;
1624 return tic6x_match_non_const
;
1626 case tic6x_operand_link_const
:
1627 case tic6x_operand_irp
:
1628 case tic6x_operand_nrp
:
1629 case tic6x_operand_func_unit
:
1630 /* All expressions are link-time constants, although there may
1631 not be relocations to express them in the output file. "irp"
1632 and "nrp" are unique operand values. All parsed functional
1633 unit names are valid. */
1634 return tic6x_match_matches
;
1636 case tic6x_operand_reg
:
1637 case tic6x_operand_regpair
:
1638 if (op
->value
.reg
.side
== side
)
1639 return tic6x_match_matches
;
1641 return tic6x_match_wrong_side
;
1643 case tic6x_operand_xreg
:
1644 case tic6x_operand_xregpair
:
1645 if (op
->value
.reg
.side
== cross
)
1646 return tic6x_match_matches
;
1648 return tic6x_match_wrong_side
;
1650 case tic6x_operand_dreg
:
1651 case tic6x_operand_dregpair
:
1652 if (op
->value
.reg
.side
== data_side
)
1653 return tic6x_match_matches
;
1655 return tic6x_match_wrong_side
;
1657 case tic6x_operand_areg
:
1658 if (op
->value
.reg
.side
!= cross
)
1659 return tic6x_match_wrong_side
;
1660 else if (op
->value
.reg
.side
== 2
1661 && (op
->value
.reg
.num
== 14 || op
->value
.reg
.num
== 15))
1662 return tic6x_match_matches
;
1664 return tic6x_match_bad_address
;
1666 case tic6x_operand_retreg
:
1667 if (op
->value
.reg
.side
!= side
)
1668 return tic6x_match_wrong_side
;
1669 else if (op
->value
.reg
.num
!= 3)
1670 return tic6x_match_bad_return
;
1672 return tic6x_match_matches
;
1674 case tic6x_operand_ctrl
:
1678 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read
1679 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
1680 return tic6x_match_matches
;
1682 return tic6x_match_ctrl_write_only
;
1684 case tic6x_rw_write
:
1685 if (tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_write
1686 || tic6x_ctrl_table
[op
->value
.ctrl
].rw
== tic6x_rw_read_write
)
1687 return tic6x_match_matches
;
1689 return tic6x_match_ctrl_read_only
;
1695 case tic6x_operand_mem_deref
:
1696 if (op
->value
.mem
.mod
!= tic6x_mem_mod_none
)
1697 return tic6x_match_bad_mem
;
1698 else if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
1700 else if (op
->value
.mem
.base_reg
.side
!= side
)
1701 return tic6x_match_bad_mem
;
1703 return tic6x_match_matches
;
1705 case tic6x_operand_mem_short
:
1706 case tic6x_operand_mem_ndw
:
1707 if (op
->value
.mem
.base_reg
.side
!= side
)
1708 return tic6x_match_bad_mem
;
1709 if (op
->value
.mem
.mod
== tic6x_mem_mod_none
)
1711 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
1713 return tic6x_match_matches
;
1715 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
1717 if (op
->value
.mem
.mod
== tic6x_mem_mod_plus
1718 || op
->value
.mem
.mod
== tic6x_mem_mod_minus
)
1720 return tic6x_match_matches
;
1722 if (op
->value
.mem
.offset_is_reg
)
1724 if (op
->value
.mem
.scaled
== tic6x_offset_unscaled
1725 && form
!= tic6x_operand_mem_ndw
)
1727 if (op
->value
.mem
.offset
.reg
.side
== side
)
1728 return tic6x_match_matches
;
1730 return tic6x_match_bad_mem
;
1734 if (op
->value
.mem
.offset
.exp
.X_op
== O_constant
)
1735 return tic6x_match_matches
;
1737 return tic6x_match_bad_mem
;
1740 case tic6x_operand_mem_long
:
1741 if (op
->value
.mem
.base_reg
.side
== 2
1742 && (op
->value
.mem
.base_reg
.num
== 14
1743 || op
->value
.mem
.base_reg
.num
== 15))
1745 switch (op
->value
.mem
.mod
)
1747 case tic6x_mem_mod_none
:
1748 if (op
->value
.mem
.scaled
!= tic6x_offset_none
)
1750 return tic6x_match_matches
;
1752 case tic6x_mem_mod_plus
:
1753 if (op
->value
.mem
.scaled
== tic6x_offset_none
)
1755 if (op
->value
.mem
.offset_is_reg
)
1756 return tic6x_match_bad_mem
;
1757 else if (op
->value
.mem
.scaled
== tic6x_offset_scaled
1758 && op
->value
.mem
.offset
.exp
.X_op
!= O_constant
)
1759 return tic6x_match_bad_mem
;
1761 return tic6x_match_matches
;
1763 case tic6x_mem_mod_minus
:
1764 case tic6x_mem_mod_preinc
:
1765 case tic6x_mem_mod_predec
:
1766 case tic6x_mem_mod_postinc
:
1767 case tic6x_mem_mod_postdec
:
1768 return tic6x_match_bad_mem
;
1776 return tic6x_match_bad_mem
;
1783 /* Return the number of bits shift used with DP-relative coding method
1787 tic6x_dpr_shift (tic6x_coding_method coding
)
1791 case tic6x_coding_ulcst_dpr_byte
:
1794 case tic6x_coding_ulcst_dpr_half
:
1797 case tic6x_coding_ulcst_dpr_word
:
1805 /* Return the relocation used with DP-relative coding method
1808 static bfd_reloc_code_real_type
1809 tic6x_dpr_reloc (tic6x_coding_method coding
)
1813 case tic6x_coding_ulcst_dpr_byte
:
1814 return BFD_RELOC_C6000_SBR_U15_B
;
1816 case tic6x_coding_ulcst_dpr_half
:
1817 return BFD_RELOC_C6000_SBR_U15_H
;
1819 case tic6x_coding_ulcst_dpr_word
:
1820 return BFD_RELOC_C6000_SBR_U15_W
;
1827 /* Given a memory reference *MEM_REF as originally parsed, fill in
1828 defaults for missing offsets. */
1831 tic6x_default_mem_ref (tic6x_mem_ref
*mem_ref
)
1833 switch (mem_ref
->mod
)
1835 case tic6x_mem_mod_none
:
1836 if (mem_ref
->scaled
!= tic6x_offset_none
)
1838 mem_ref
->mod
= tic6x_mem_mod_plus
;
1839 mem_ref
->scaled
= tic6x_offset_unscaled
;
1840 mem_ref
->offset_is_reg
= FALSE
;
1841 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
1842 mem_ref
->offset
.exp
.X_op
= O_constant
;
1843 mem_ref
->offset
.exp
.X_add_number
= 0;
1844 mem_ref
->offset
.exp
.X_unsigned
= 0;
1847 case tic6x_mem_mod_plus
:
1848 case tic6x_mem_mod_minus
:
1849 if (mem_ref
->scaled
== tic6x_offset_none
)
1853 case tic6x_mem_mod_preinc
:
1854 case tic6x_mem_mod_predec
:
1855 case tic6x_mem_mod_postinc
:
1856 case tic6x_mem_mod_postdec
:
1857 if (mem_ref
->scaled
!= tic6x_offset_none
)
1859 mem_ref
->scaled
= tic6x_offset_scaled
;
1860 mem_ref
->offset_is_reg
= FALSE
;
1861 memset (&mem_ref
->offset
.exp
, 0, sizeof mem_ref
->offset
.exp
);
1862 mem_ref
->offset
.exp
.X_op
= O_constant
;
1863 mem_ref
->offset
.exp
.X_add_number
= 1;
1864 mem_ref
->offset
.exp
.X_unsigned
= 0;
1872 /* Return the encoding in the 8-bit field of an SPMASK or SPMASKR
1873 instruction of the specified UNIT, side SIDE. */
1876 tic6x_encode_spmask (tic6x_func_unit_base unit
, unsigned int side
)
1880 case tic6x_func_unit_l
:
1881 return 1 << (side
- 1);
1883 case tic6x_func_unit_s
:
1884 return 1 << (side
+ 1);
1886 case tic6x_func_unit_d
:
1887 return 1 << (side
+ 3);
1889 case tic6x_func_unit_m
:
1890 return 1 << (side
+ 5);
1897 /* Try to encode the instruction with opcode number ID and operands
1898 OPERANDS (number NUM_OPERANDS), creg value THIS_LINE_CREG and z
1899 value THIS_LINE_Z; FUNC_UNIT_SIDE, FUNC_UNIT_CROSS and
1900 FUNC_UNIT_DATA_SIDE describe the functional unit specification;
1901 SPLOOP_II is the ii value from the previous SPLOOP-family
1902 instruction, or 0 if not in such a loop; the only possible problems
1903 are operands being out of range (they already match the
1904 fine-grained form), and inappropriate predication. If this
1905 succeeds, return the encoding and set *OK to TRUE; otherwise return
1906 0 and set *OK to FALSE. If a fix is needed, set *FIX_NEEDED to
1907 true and fill in *FIX_EXP, *FIX_PCREL, *FX_R_TYPE and *FIX_ADDA.
1908 Print error messages for failure if PRINT_ERRORS is TRUE; the
1909 opcode starts at STR and has length OPC_LEN. */
1912 tic6x_try_encode (tic6x_opcode_id id
, tic6x_operand
*operands
,
1913 unsigned int num_operands
, unsigned int this_line_creg
,
1914 unsigned int this_line_z
, unsigned int func_unit_side
,
1915 unsigned int func_unit_cross
,
1916 unsigned int func_unit_data_side
, int sploop_ii
,
1917 expressionS
**fix_exp
, int *fix_pcrel
,
1918 bfd_reloc_code_real_type
*fx_r_type
, bfd_boolean
*fix_adda
,
1919 bfd_boolean
*fix_needed
, bfd_boolean
*ok
,
1920 bfd_boolean print_errors
, char *str
, int opc_len
)
1922 const tic6x_opcode
*opct
;
1923 const tic6x_insn_format
*fmt
;
1924 unsigned int opcode_value
;
1927 opct
= &tic6x_opcode_table
[id
];
1928 fmt
= &tic6x_insn_format_table
[opct
->format
];
1929 opcode_value
= fmt
->cst_bits
;
1931 for (fld
= 0; fld
< opct
->num_fixed_fields
; fld
++)
1933 if (opct
->fixed_fields
[fld
].min_val
== opct
->fixed_fields
[fld
].max_val
)
1935 const tic6x_insn_field
*fldd
;
1936 fldd
= tic6x_field_from_fmt (fmt
, opct
->fixed_fields
[fld
].field_id
);
1939 opcode_value
|= opct
->fixed_fields
[fld
].min_val
<< fldd
->low_pos
;
1943 for (fld
= 0; fld
< opct
->num_variable_fields
; fld
++)
1945 const tic6x_insn_field
*fldd
;
1951 unsigned int fcyc_bits
;
1956 fldd
= tic6x_field_from_fmt (fmt
, opct
->variable_fields
[fld
].field_id
);
1959 opno
= opct
->variable_fields
[fld
].operand_num
;
1960 switch (opct
->variable_fields
[fld
].coding_method
)
1962 case tic6x_coding_ucst
:
1963 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
1965 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
1967 ucexp
= operands
[opno
].value
.exp
;
1969 if (ucexp
.X_add_number
< 0
1970 || ucexp
.X_add_number
>= (1 << fldd
->width
))
1973 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
1978 value
= ucexp
.X_add_number
;
1981 case tic6x_coding_scst
:
1982 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
1984 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
1987 /* Opcode table should not permit non-constants without
1988 a known relocation for them. */
1989 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
1992 *fix_exp
= &operands
[opno
].value
.exp
;
1994 *fx_r_type
= BFD_RELOC_C6000_ABS_S16
;
1998 sign_value
= SEXT (operands
[opno
].value
.exp
.X_add_number
);
2000 if (sign_value
< -(1 << (fldd
->width
- 1))
2001 || (sign_value
>= (1 << (fldd
->width
- 1))))
2004 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2009 value
= sign_value
+ (1 << (fldd
->width
- 1));
2010 value
^= (1 << (fldd
->width
- 1));
2013 case tic6x_coding_ucst_minus_one
:
2014 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2016 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2018 if (operands
[opno
].value
.exp
.X_add_number
<= 0
2019 || operands
[opno
].value
.exp
.X_add_number
> (1 << fldd
->width
))
2022 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2027 value
= operands
[opno
].value
.exp
.X_add_number
- 1;
2030 case tic6x_coding_scst_negate
:
2031 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2033 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2035 sign_value
= SEXT (-operands
[opno
].value
.exp
.X_add_number
);
2036 goto signed_constant
;
2038 case tic6x_coding_ulcst_dpr_byte
:
2039 case tic6x_coding_ulcst_dpr_half
:
2040 case tic6x_coding_ulcst_dpr_word
:
2041 bits
= tic6x_dpr_shift (opct
->variable_fields
[fld
].coding_method
);
2042 switch (operands
[opno
].form
)
2045 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2047 ucexp
= operands
[opno
].value
.exp
;
2048 goto unsigned_constant
;
2050 expp
= &operands
[opno
].value
.exp
;
2053 case TIC6X_OP_MEM_NOUNREG
:
2054 mem
= operands
[opno
].value
.mem
;
2055 tic6x_default_mem_ref (&mem
);
2056 if (mem
.offset_is_reg
)
2058 if (mem
.offset
.exp
.X_op
== O_constant
)
2060 ucexp
= mem
.offset
.exp
;
2061 if (mem
.scaled
== tic6x_offset_unscaled
)
2063 if (ucexp
.X_add_number
& ((1 << bits
) - 1))
2066 as_bad (_("offset in operand %u of '%.*s' not "
2067 "divisible by %u"), opno
+ 1, opc_len
,
2072 ucexp
.X_add_number
>>= bits
;
2074 goto unsigned_constant
;
2076 if (mem
.scaled
!= tic6x_offset_unscaled
)
2078 if (operands
[opno
].value
.mem
.mod
== tic6x_mem_mod_none
2079 || operands
[opno
].value
.mem
.scaled
!= tic6x_offset_unscaled
2080 || operands
[opno
].value
.mem
.offset_is_reg
)
2082 expp
= &operands
[opno
].value
.mem
.offset
.exp
;
2089 /* Opcode table should not use this encoding without a known
2091 if (fldd
->low_pos
!= 8 || fldd
->width
!= 15)
2093 /* We do not check for offset divisibility here; such a
2094 check is not needed at this point to encode the value,
2095 and if there is eventually a problem it will be detected
2096 either in md_apply_fix or at link time. */
2101 = tic6x_dpr_reloc (opct
->variable_fields
[fld
].coding_method
);
2102 if (operands
[opno
].form
== TIC6X_OP_EXP
)
2108 case tic6x_coding_lcst_low16
:
2109 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2111 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2112 value
= operands
[opno
].value
.exp
.X_add_number
& 0xffff;
2116 /* Opcode table should not use this encoding without a
2117 known relocation. */
2118 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2121 *fix_exp
= &operands
[opno
].value
.exp
;
2123 *fx_r_type
= BFD_RELOC_C6000_ABS_L16
;
2128 case tic6x_coding_lcst_high16
:
2129 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2131 if (operands
[opno
].value
.exp
.X_op
== O_constant
)
2132 value
= (operands
[opno
].value
.exp
.X_add_number
>> 16) & 0xffff;
2136 /* Opcode table should not use this encoding without a
2137 known relocation. */
2138 if (fldd
->low_pos
!= 7 || fldd
->width
!= 16)
2141 *fix_exp
= &operands
[opno
].value
.exp
;
2143 *fx_r_type
= BFD_RELOC_C6000_ABS_H16
;
2148 case tic6x_coding_pcrel
:
2149 case tic6x_coding_pcrel_half
:
2150 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2154 *fix_exp
= &operands
[opno
].value
.exp
;
2156 if (fldd
->low_pos
== 7 && fldd
->width
== 21)
2157 *fx_r_type
= BFD_RELOC_C6000_PCR_S21
;
2158 else if (fldd
->low_pos
== 16 && fldd
->width
== 12)
2159 *fx_r_type
= BFD_RELOC_C6000_PCR_S12
;
2160 else if (fldd
->low_pos
== 13 && fldd
->width
== 10)
2161 *fx_r_type
= BFD_RELOC_C6000_PCR_S10
;
2162 else if (fldd
->low_pos
== 16 && fldd
->width
== 7)
2163 *fx_r_type
= BFD_RELOC_C6000_PCR_S7
;
2165 /* Opcode table should not use this encoding without a
2166 known relocation. */
2171 case tic6x_coding_reg
:
2172 switch (operands
[opno
].form
)
2175 case TIC6X_OP_REGPAIR
:
2176 value
= operands
[opno
].value
.reg
.num
;
2179 case TIC6X_OP_MEM_NOUNREG
:
2180 case TIC6X_OP_MEM_UNREG
:
2181 value
= operands
[opno
].value
.mem
.base_reg
.num
;
2189 case tic6x_coding_areg
:
2190 switch (operands
[opno
].form
)
2193 value
= (operands
[opno
].value
.reg
.num
== 15 ? 1 : 0);
2196 case TIC6X_OP_MEM_NOUNREG
:
2197 value
= (operands
[opno
].value
.mem
.base_reg
.num
== 15 ? 1 : 0);
2205 case tic6x_coding_crlo
:
2206 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2208 value
= tic6x_ctrl_table
[operands
[opno
].value
.ctrl
].crlo
;
2211 case tic6x_coding_crhi
:
2212 if (operands
[opno
].form
!= TIC6X_OP_CTRL
)
2217 case tic6x_coding_reg_shift
:
2218 if (operands
[opno
].form
!= TIC6X_OP_REGPAIR
)
2220 value
= operands
[opno
].value
.reg
.num
>> 1;
2223 case tic6x_coding_mem_offset
:
2224 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
)
2226 mem
= operands
[opno
].value
.mem
;
2227 tic6x_default_mem_ref (&mem
);
2228 if (mem
.offset_is_reg
)
2230 if (mem
.scaled
!= tic6x_offset_scaled
)
2232 value
= mem
.offset
.reg
.num
;
2238 if (mem
.offset
.exp
.X_op
!= O_constant
)
2242 case tic6x_offset_scaled
:
2246 case tic6x_offset_unscaled
:
2247 scale
= opct
->operand_info
[opno
].size
;
2248 if (scale
!= 1 && scale
!= 2 && scale
!= 4 && scale
!= 8)
2255 if (mem
.offset
.exp
.X_add_number
< 0
2256 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->width
) * scale
)
2259 as_bad (_("offset in operand %u of '%.*s' out of range"),
2260 opno
+ 1, opc_len
, str
);
2264 if (mem
.offset
.exp
.X_add_number
% scale
)
2267 as_bad (_("offset in operand %u of '%.*s' not "
2269 opno
+ 1, opc_len
, str
, scale
);
2273 value
= mem
.offset
.exp
.X_add_number
/ scale
;
2277 case tic6x_coding_mem_offset_noscale
:
2278 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2280 mem
= operands
[opno
].value
.mem
;
2281 tic6x_default_mem_ref (&mem
);
2282 if (mem
.offset_is_reg
)
2283 value
= mem
.offset
.reg
.num
;
2286 if (mem
.offset
.exp
.X_op
!= O_constant
)
2288 if (mem
.offset
.exp
.X_add_number
< 0
2289 || mem
.offset
.exp
.X_add_number
>= (1 << fldd
->width
))
2292 as_bad (_("offset in operand %u of '%.*s' out of range"),
2293 opno
+ 1, opc_len
, str
);
2297 value
= mem
.offset
.exp
.X_add_number
;
2301 case tic6x_coding_mem_mode
:
2302 if (operands
[opno
].form
!= TIC6X_OP_MEM_NOUNREG
2303 && operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2305 mem
= operands
[opno
].value
.mem
;
2306 tic6x_default_mem_ref (&mem
);
2309 case tic6x_mem_mod_plus
:
2313 case tic6x_mem_mod_minus
:
2317 case tic6x_mem_mod_preinc
:
2321 case tic6x_mem_mod_predec
:
2325 case tic6x_mem_mod_postinc
:
2329 case tic6x_mem_mod_postdec
:
2336 value
+= (mem
.offset_is_reg
? 4 : 0);
2339 case tic6x_coding_scaled
:
2340 if (operands
[opno
].form
!= TIC6X_OP_MEM_UNREG
)
2342 mem
= operands
[opno
].value
.mem
;
2343 tic6x_default_mem_ref (&mem
);
2346 case tic6x_offset_unscaled
:
2350 case tic6x_offset_scaled
:
2359 case tic6x_coding_spmask
:
2360 /* The position of such a field is hardcoded in the handling
2362 if (fldd
->low_pos
!= 18)
2365 for (opno
= 0; opno
< num_operands
; opno
++)
2369 v
= tic6x_encode_spmask (operands
[opno
].value
.func_unit
.base
,
2370 operands
[opno
].value
.func_unit
.side
);
2374 as_bad (_("functional unit already masked for operand "
2375 "%u of '%.*s'"), opno
+ 1, opc_len
, str
);
2383 case tic6x_coding_reg_unused
:
2384 /* This is a placeholder; correct handling goes along with
2385 resource constraint checks. */
2389 case tic6x_coding_fstg
:
2390 case tic6x_coding_fcyc
:
2391 if (operands
[opno
].form
!= TIC6X_OP_EXP
)
2393 if (operands
[opno
].value
.exp
.X_op
!= O_constant
)
2398 as_bad (_("'%.*s' instruction not in a software "
2407 else if (sploop_ii
<= 2)
2409 else if (sploop_ii
<= 4)
2411 else if (sploop_ii
<= 8)
2413 else if (sploop_ii
<= 14)
2417 if (fcyc_bits
> fldd
->width
)
2420 if (opct
->variable_fields
[fld
].coding_method
== tic6x_coding_fstg
)
2422 if (operands
[opno
].value
.exp
.X_add_number
< 0
2423 || (operands
[opno
].value
.exp
.X_add_number
2424 >= (1 << (fldd
->width
- fcyc_bits
))))
2427 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2432 value
= operands
[opno
].value
.exp
.X_add_number
<< fcyc_bits
;
2436 if (operands
[opno
].value
.exp
.X_add_number
< 0
2437 || (operands
[opno
].value
.exp
.X_add_number
>= sploop_ii
))
2440 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2445 value
= operands
[opno
].value
.exp
.X_add_number
;
2449 case tic6x_coding_fu
:
2450 value
= func_unit_side
== 2 ? 1 : 0;
2453 case tic6x_coding_data_fu
:
2454 value
= func_unit_data_side
== 2 ? 1 : 0;
2457 case tic6x_coding_xpath
:
2458 value
= func_unit_cross
;
2465 for (ffld
= 0; ffld
< opct
->num_fixed_fields
; ffld
++)
2466 if ((opct
->fixed_fields
[ffld
].field_id
2467 == opct
->variable_fields
[fld
].field_id
)
2468 && (value
< opct
->fixed_fields
[ffld
].min_val
2469 || value
> opct
->fixed_fields
[ffld
].max_val
))
2472 as_bad (_("operand %u of '%.*s' out of range"), opno
+ 1,
2478 opcode_value
|= value
<< fldd
->low_pos
;
2483 const tic6x_insn_field
*creg
;
2484 const tic6x_insn_field
*z
;
2486 creg
= tic6x_field_from_fmt (fmt
, tic6x_field_creg
);
2490 as_bad (_("instruction '%.*s' cannot be predicated"),
2495 z
= tic6x_field_from_fmt (fmt
, tic6x_field_z
);
2496 /* If there is a creg field, there must be a z field; otherwise
2497 there is an error in the format table. */
2501 opcode_value
|= this_line_creg
<< creg
->low_pos
;
2502 opcode_value
|= this_line_z
<< z
->low_pos
;
2506 return opcode_value
;
2509 /* Convert the target integer stored in N bytes in BUF to a host
2510 integer, returning that value. */
2513 md_chars_to_number (char *buf
, int n
)
2516 unsigned char *p
= (unsigned char *) buf
;
2518 if (target_big_endian
)
2523 result
|= (*p
++ & 0xff);
2531 result
|= (p
[n
] & 0xff);
2538 /* Assemble the instruction starting at STR (an opcode, with the
2539 opcode name all-lowercase). */
2542 md_assemble (char *str
)
2546 bfd_boolean this_line_parallel
;
2547 bfd_boolean this_line_spmask
;
2548 unsigned int this_line_creg
;
2549 unsigned int this_line_z
;
2550 tic6x_label_list
*this_insn_label_list
;
2551 segment_info_type
*seginfo
;
2552 tic6x_opcode_list
*opc_list
, *opc
;
2553 tic6x_func_unit_base func_unit_base
= tic6x_func_unit_nfu
;
2554 unsigned int func_unit_side
= 0;
2555 unsigned int func_unit_cross
= 0;
2556 unsigned int cross_side
= 0;
2557 unsigned int func_unit_data_side
= 0;
2558 unsigned int max_matching_opcodes
, num_matching_opcodes
;
2559 tic6x_opcode_id
*opcm
= NULL
;
2560 unsigned int opc_rank
[TIC6X_NUM_PREFER
];
2561 const tic6x_opcode
*opct
= NULL
;
2562 int min_rank
, try_rank
, max_rank
;
2563 bfd_boolean num_operands_permitted
[TIC6X_MAX_SOURCE_OPERANDS
+ 1]
2565 unsigned int operand_forms
[TIC6X_MAX_SOURCE_OPERANDS
] = { 0 };
2566 tic6x_operand operands
[TIC6X_MAX_SOURCE_OPERANDS
];
2567 unsigned int max_num_operands
;
2568 unsigned int num_operands_read
;
2569 bfd_boolean ok_this_arch
, ok_this_fu
, ok_this_arch_fu
;
2570 bfd_boolean bad_operands
= FALSE
;
2571 unsigned int opcode_value
;
2572 bfd_boolean encoded_ok
;
2573 bfd_boolean fix_needed
= FALSE
;
2574 expressionS
*fix_exp
= NULL
;
2576 bfd_reloc_code_real_type fx_r_type
= BFD_RELOC_UNUSED
;
2577 bfd_boolean fix_adda
= FALSE
;
2582 while (*p
&& !is_end_of_line
[(unsigned char) *p
] && *p
!= ' ')
2585 /* This function should only have been called when there is actually
2586 an instruction to assemble. */
2590 /* Reset global settings for parallel bars and predicates now to
2591 avoid extra errors if there are problems with this opcode. */
2592 this_line_parallel
= tic6x_line_parallel
;
2593 this_line_spmask
= tic6x_line_spmask
;
2594 this_line_creg
= tic6x_line_creg
;
2595 this_line_z
= tic6x_line_z
;
2596 tic6x_line_parallel
= FALSE
;
2597 tic6x_line_spmask
= FALSE
;
2598 tic6x_line_creg
= 0;
2600 seginfo
= seg_info (now_seg
);
2601 this_insn_label_list
= seginfo
->tc_segment_info_data
.label_list
;
2602 seginfo
->tc_segment_info_data
.label_list
= NULL
;
2604 opc_list
= hash_find_n (opcode_hash
, str
, p
- str
);
2605 if (opc_list
== NULL
)
2609 as_bad (_("unknown opcode '%s'"), str
);
2615 skip_whitespace (p
);
2617 /* See if there is something that looks like a functional unit
2621 bfd_boolean good_func_unit
;
2622 tic6x_func_unit_base maybe_base
= tic6x_func_unit_nfu
;
2623 unsigned int maybe_side
= 0;
2624 unsigned int maybe_cross
= 0;
2625 unsigned int maybe_data_side
= 0;
2627 good_func_unit
= tic6x_parse_func_unit_base (p
+ 1, &maybe_base
,
2632 if (p
[3] == ' ' || is_end_of_line
[(unsigned char) p
[3]])
2634 else if ((p
[3] == 'x' || p
[3] == 'X')
2635 && (p
[4] == ' ' || is_end_of_line
[(unsigned char) p
[4]]))
2640 else if (maybe_base
== tic6x_func_unit_d
2641 && (p
[3] == 't' || p
[3] == 'T')
2642 && (p
[4] == '1' || p
[4] == '2')
2643 && (p
[5] == ' ' || is_end_of_line
[(unsigned char) p
[5]]))
2645 maybe_data_side
= p
[4] - '0';
2649 good_func_unit
= FALSE
;
2654 func_unit_base
= maybe_base
;
2655 func_unit_side
= maybe_side
;
2656 func_unit_cross
= maybe_cross
;
2657 cross_side
= (func_unit_cross
? 3 - func_unit_side
: func_unit_side
);
2658 func_unit_data_side
= maybe_data_side
;
2661 skip_whitespace (p
);
2664 /* Determine which entries in the opcode table match, and the
2665 associated permitted forms of operands. */
2666 max_matching_opcodes
= 0;
2667 for (opc
= opc_list
; opc
; opc
= opc
->next
)
2668 max_matching_opcodes
++;
2669 num_matching_opcodes
= 0;
2670 opcm
= xmalloc (max_matching_opcodes
* sizeof (*opcm
));
2671 max_num_operands
= 0;
2672 ok_this_arch
= FALSE
;
2674 ok_this_arch_fu
= FALSE
;
2675 for (opc
= opc_list
; opc
; opc
= opc
->next
)
2677 unsigned int num_operands
;
2679 bfd_boolean this_opc_arch_ok
= TRUE
;
2680 bfd_boolean this_opc_fu_ok
= TRUE
;
2682 if (tic6x_insn_format_table
[tic6x_opcode_table
[opc
->id
].format
].num_bits
2685 if (!(tic6x_opcode_table
[opc
->id
].isa_variants
& tic6x_features
))
2686 this_opc_arch_ok
= FALSE
;
2687 if (tic6x_opcode_table
[opc
->id
].func_unit
!= func_unit_base
)
2688 this_opc_fu_ok
= FALSE
;
2689 if (func_unit_side
== 1
2690 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_B_ONLY
))
2691 this_opc_fu_ok
= FALSE
;
2693 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_NO_CROSS
))
2694 this_opc_fu_ok
= FALSE
;
2695 if (!func_unit_data_side
2696 && (tic6x_opcode_table
[opc
->id
].flags
2697 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
2698 this_opc_fu_ok
= FALSE
;
2699 if (func_unit_data_side
2700 && !(tic6x_opcode_table
[opc
->id
].flags
2701 & (TIC6X_FLAG_LOAD
| TIC6X_FLAG_STORE
)))
2702 this_opc_fu_ok
= FALSE
;
2703 if (func_unit_data_side
== 1
2704 && (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SIDE_T2_ONLY
))
2705 this_opc_fu_ok
= FALSE
;
2706 if (this_opc_arch_ok
)
2707 ok_this_arch
= TRUE
;
2710 if (!this_opc_arch_ok
|| !this_opc_fu_ok
)
2712 ok_this_arch_fu
= TRUE
;
2713 opcm
[num_matching_opcodes
] = opc
->id
;
2714 num_matching_opcodes
++;
2715 num_operands
= tic6x_opcode_table
[opc
->id
].num_operands
;
2717 if (tic6x_opcode_table
[opc
->id
].flags
& TIC6X_FLAG_SPMASK
)
2719 if (num_operands
!= 1
2720 || (tic6x_opcode_table
[opc
->id
].operand_info
[0].form
2721 != tic6x_operand_func_unit
))
2724 for (i
= 0; i
< num_operands
; i
++)
2727 |= tic6x_coarse_operand_form (tic6x_operand_func_unit
);
2728 num_operands_permitted
[i
] = TRUE
;
2733 for (i
= 0; i
< num_operands
; i
++)
2735 tic6x_operand_form f
2736 = tic6x_opcode_table
[opc
->id
].operand_info
[i
].form
;
2738 operand_forms
[i
] |= tic6x_coarse_operand_form (f
);
2741 num_operands_permitted
[num_operands
] = TRUE
;
2742 if (num_operands
> max_num_operands
)
2743 max_num_operands
= num_operands
;
2748 as_bad (_("'%.*s' instruction not supported on this architecture"),
2756 as_bad (_("'%.*s' instruction not supported on this functional unit"),
2762 if (!ok_this_arch_fu
)
2764 as_bad (_("'%.*s' instruction not supported on this functional unit"
2765 " for this architecture"),
2771 /* If there were no instructions matching the above availability
2772 checks, we should now have given an error and returned. */
2773 if (num_matching_opcodes
== 0)
2776 num_operands_read
= 0;
2779 skip_whitespace (p
);
2780 if (is_end_of_line
[(unsigned char) *p
])
2782 if (num_operands_read
> 0)
2784 as_bad (_("missing operand after comma"));
2785 bad_operands
= TRUE
;
2790 if (max_num_operands
== 0)
2792 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
2793 bad_operands
= TRUE
;
2797 if (!tic6x_parse_operand (&p
, &operands
[num_operands_read
],
2798 operand_forms
[num_operands_read
], str
, opc_len
,
2799 num_operands_read
+ 1))
2800 bad_operands
= TRUE
;
2801 num_operands_read
++;
2803 if (is_end_of_line
[(unsigned char) *p
])
2808 if (num_operands_read
== max_num_operands
)
2810 as_bad (_("too many operands to '%.*s'"), opc_len
, str
);
2811 bad_operands
= TRUE
;
2817 /* Operand parsing should consume whole operands. */
2821 if (!bad_operands
&& !num_operands_permitted
[num_operands_read
])
2823 as_bad (_("bad number of operands to '%.*s'"), opc_len
, str
);
2824 bad_operands
= TRUE
;
2829 /* Each operand is of the right syntactic form for some opcode
2830 choice, and the number of operands is valid. Check that each
2831 operand is OK in detail for some opcode choice with the right
2832 number of operands. */
2835 for (i
= 0; i
< num_operands_read
; i
++)
2837 bfd_boolean coarse_ok
= FALSE
;
2838 bfd_boolean fine_ok
= FALSE
;
2839 tic6x_operand_match fine_failure
= tic6x_match_matches
;
2842 for (j
= 0; j
< num_matching_opcodes
; j
++)
2844 tic6x_operand_form f
;
2847 tic6x_operand_match this_fine_failure
;
2849 if (tic6x_opcode_table
[opcm
[j
]].flags
& TIC6X_FLAG_SPMASK
)
2851 f
= tic6x_operand_func_unit
;
2856 if (tic6x_opcode_table
[opcm
[j
]].num_operands
2857 != num_operands_read
)
2860 f
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].form
;
2861 rw
= tic6x_opcode_table
[opcm
[j
]].operand_info
[i
].rw
;
2863 cf
= tic6x_coarse_operand_form (f
);
2865 if (operands
[i
].form
!= cf
)
2870 = tic6x_operand_matches_form (&operands
[i
], f
, rw
,
2873 func_unit_data_side
);
2874 if (this_fine_failure
== tic6x_match_matches
)
2879 if (fine_failure
== tic6x_match_matches
2880 || fine_failure
> this_fine_failure
)
2881 fine_failure
= this_fine_failure
;
2884 /* No instructions should have operand syntactic forms only
2885 acceptable with certain numbers of operands, so no
2886 diagnostic for this case. */
2892 switch (fine_failure
)
2894 case tic6x_match_non_const
:
2895 as_bad (_("operand %u of '%.*s' not constant"),
2896 i
+ 1, opc_len
, str
);
2899 case tic6x_match_wrong_side
:
2900 as_bad (_("operand %u of '%.*s' on wrong side"),
2901 i
+ 1, opc_len
, str
);
2904 case tic6x_match_bad_return
:
2905 as_bad (_("operand %u of '%.*s' not a valid return "
2906 "address register"),
2907 i
+ 1, opc_len
, str
);
2910 case tic6x_match_ctrl_write_only
:
2911 as_bad (_("operand %u of '%.*s' is write-only"),
2912 i
+ 1, opc_len
, str
);
2915 case tic6x_match_ctrl_read_only
:
2916 as_bad (_("operand %u of '%.*s' is read-only"),
2917 i
+ 1, opc_len
, str
);
2920 case tic6x_match_bad_mem
:
2921 as_bad (_("operand %u of '%.*s' not a valid memory "
2923 i
+ 1, opc_len
, str
);
2926 case tic6x_match_bad_address
:
2927 as_bad (_("operand %u of '%.*s' not a valid base "
2928 "address register"),
2929 i
+ 1, opc_len
, str
);
2935 bad_operands
= TRUE
;
2943 /* Each operand is OK for some opcode choice, and the number of
2944 operands is valid. Check whether there is an opcode choice
2945 for which all operands are simultaneously valid. */
2947 bfd_boolean found_match
= FALSE
;
2949 for (i
= 0; i
< TIC6X_NUM_PREFER
; i
++)
2950 opc_rank
[i
] = (unsigned int) -1;
2952 min_rank
= TIC6X_NUM_PREFER
- 1;
2955 for (i
= 0; i
< num_matching_opcodes
; i
++)
2958 bfd_boolean this_matches
= TRUE
;
2960 if (!(tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
2961 && tic6x_opcode_table
[opcm
[i
]].num_operands
!= num_operands_read
)
2964 for (j
= 0; j
< num_operands_read
; j
++)
2966 tic6x_operand_form f
;
2969 if (tic6x_opcode_table
[opcm
[i
]].flags
& TIC6X_FLAG_SPMASK
)
2971 f
= tic6x_operand_func_unit
;
2976 f
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].form
;
2977 rw
= tic6x_opcode_table
[opcm
[i
]].operand_info
[j
].rw
;
2979 if (tic6x_operand_matches_form (&operands
[j
], f
, rw
,
2982 func_unit_data_side
)
2983 != tic6x_match_matches
)
2985 this_matches
= FALSE
;
2992 int rank
= TIC6X_PREFER_VAL (tic6x_opcode_table
[opcm
[i
]].flags
);
2994 if (rank
< min_rank
)
2996 if (rank
> max_rank
)
2999 if (opc_rank
[rank
] == (unsigned int) -1)
3002 /* The opcode table should provide a total ordering
3003 for all cases where multiple matches may get
3013 as_bad (_("bad operand combination for '%.*s'"), opc_len
, str
);
3014 bad_operands
= TRUE
;
3026 for (try_rank
= max_rank
; try_rank
>= min_rank
; try_rank
--)
3030 if (opc_rank
[try_rank
] == (unsigned int) -1)
3033 opcode_value
= tic6x_try_encode (opcm
[opc_rank
[try_rank
]], operands
,
3034 num_operands_read
, this_line_creg
,
3035 this_line_z
, func_unit_side
,
3036 func_unit_cross
, func_unit_data_side
,
3037 seginfo
->tc_segment_info_data
.sploop_ii
,
3038 &fix_exp
, &fix_pcrel
, &fx_r_type
,
3039 &fix_adda
, &fix_needed
, &encoded_ok
,
3040 (try_rank
== min_rank
? TRUE
: FALSE
),
3044 opct
= &tic6x_opcode_table
[opcm
[opc_rank
[try_rank
]]];
3054 if (this_line_parallel
)
3056 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
;
3057 if (insn_frag
== NULL
)
3059 as_bad (_("parallel instruction not following another instruction"));
3063 if (insn_frag
->fr_fix
>= 32)
3065 as_bad (_("too many instructions in execute packet"));
3069 if (this_insn_label_list
!= NULL
)
3070 as_bad (_("label not at start of execute packet"));
3072 if (opct
->flags
& TIC6X_FLAG_FIRST
)
3073 as_bad (_("'%.*s' instruction not at start of execute packet"),
3076 *seginfo
->tc_segment_info_data
.last_insn_lsb
|= 0x1;
3077 output
= insn_frag
->fr_literal
+ insn_frag
->fr_fix
;
3081 tic6x_label_list
*l
;
3083 seginfo
->tc_segment_info_data
.spmask_addr
= NULL
;
3085 /* Start a new frag for this execute packet. */
3086 if (frag_now_fix () != 0)
3088 if (frag_now
->fr_type
!= rs_machine_dependent
)
3089 frag_wane (frag_now
);
3094 insn_frag
= seginfo
->tc_segment_info_data
.execute_packet_frag
= frag_now
;
3095 for (l
= this_insn_label_list
; l
; l
= l
->next
)
3097 symbol_set_frag (l
->label
, frag_now
);
3098 S_SET_VALUE (l
->label
, 0);
3099 S_SET_SEGMENT (l
->label
, now_seg
);
3101 tic6x_free_label_list (this_insn_label_list
);
3102 dwarf2_emit_insn (0);
3103 output
= frag_var (rs_machine_dependent
, 32, 32, 0, NULL
, 0, NULL
);
3104 /* This must be the same as the frag to which a pointer was just
3106 if (output
!= insn_frag
->fr_literal
)
3108 insn_frag
->tc_frag_data
.is_insns
= TRUE
;
3109 insn_frag
->tc_frag_data
.can_cross_fp_boundary
3110 = tic6x_can_cross_fp_boundary
;
3113 if (opct
->flags
& TIC6X_FLAG_SPLOOP
)
3115 if (seginfo
->tc_segment_info_data
.sploop_ii
)
3116 as_bad (_("nested software pipelined loop"));
3117 if (num_operands_read
!= 1
3118 || operands
[0].form
!= TIC6X_OP_EXP
3119 || operands
[0].value
.exp
.X_op
!= O_constant
)
3121 seginfo
->tc_segment_info_data
.sploop_ii
3122 = operands
[0].value
.exp
.X_add_number
;
3124 else if (opct
->flags
& TIC6X_FLAG_SPKERNEL
)
3126 if (!seginfo
->tc_segment_info_data
.sploop_ii
)
3127 as_bad (_("'%.*s' instruction not in a software pipelined loop"),
3129 seginfo
->tc_segment_info_data
.sploop_ii
= 0;
3132 if (this_line_spmask
)
3134 if (seginfo
->tc_segment_info_data
.spmask_addr
== NULL
)
3135 as_bad (_("'||^' without previous SPMASK"));
3136 else if (func_unit_base
== tic6x_func_unit_nfu
)
3137 as_bad (_("cannot mask instruction using no functional unit"));
3140 unsigned int spmask_opcode
;
3141 unsigned int mask_bit
;
3144 = md_chars_to_number (seginfo
->tc_segment_info_data
.spmask_addr
,
3146 mask_bit
= tic6x_encode_spmask (func_unit_base
, func_unit_side
);
3148 if (spmask_opcode
& mask_bit
)
3149 as_bad (_("functional unit already masked"));
3150 spmask_opcode
|= mask_bit
;
3151 md_number_to_chars (seginfo
->tc_segment_info_data
.spmask_addr
,
3156 record_alignment (now_seg
, 5);
3157 md_number_to_chars (output
, opcode_value
, 4);
3159 tic6x_fix_new_exp (insn_frag
, output
- insn_frag
->fr_literal
, 4, fix_exp
,
3160 fix_pcrel
, fx_r_type
, fix_adda
);
3161 insn_frag
->fr_fix
+= 4;
3162 insn_frag
->fr_var
-= 4;
3163 seginfo
->tc_segment_info_data
.last_insn_lsb
3164 = (target_big_endian
? output
+ 3 : output
);
3165 if (opct
->flags
& TIC6X_FLAG_SPMASK
)
3166 seginfo
->tc_segment_info_data
.spmask_addr
= output
;
3169 /* Modify NEWVAL (32-bit) by inserting VALUE, shifted right by SHIFT
3170 and the least significant BITS bits taken, at position POS. */
3171 #define MODIFY_VALUE(NEWVAL, VALUE, SHIFT, POS, BITS) \
3173 (NEWVAL) &= 0xffffffffU & ~(((1U << (BITS)) - 1) << (POS)); \
3174 (NEWVAL) |= (((VALUE) >> (SHIFT)) & ((1U << (BITS)) - 1)) << (POS); \
3177 /* Apply a fixup to the object file. */
3180 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3182 offsetT value
= *valP
;
3183 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3185 value
= SEXT (value
);
3188 fixP
->fx_offset
= SEXT (fixP
->fx_offset
);
3190 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3193 /* We do our own overflow checks. */
3194 fixP
->fx_no_overflow
= 1;
3196 switch (fixP
->fx_r_type
)
3198 case BFD_RELOC_NONE
:
3199 /* Force output to the object file. */
3204 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3205 md_number_to_chars (buf
, value
, 4);
3209 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3211 if (value
< -0x8000 || value
> 0xffff)
3212 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3213 _("value too large for 2-byte field"));
3214 md_number_to_chars (buf
, value
, 2);
3219 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3221 if (value
< -0x80 || value
> 0xff)
3222 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3223 _("value too large for 1-byte field"));
3224 md_number_to_chars (buf
, value
, 1);
3228 case BFD_RELOC_C6000_ABS_S16
:
3229 case BFD_RELOC_C6000_ABS_L16
:
3230 case BFD_RELOC_C6000_SBR_S16
:
3231 case BFD_RELOC_C6000_SBR_L16_B
:
3232 case BFD_RELOC_C6000_SBR_L16_H
:
3233 case BFD_RELOC_C6000_SBR_L16_W
:
3234 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3235 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3237 offsetT newval
= md_chars_to_number (buf
, 4);
3240 switch (fixP
->fx_r_type
)
3242 case BFD_RELOC_C6000_SBR_L16_H
:
3246 case BFD_RELOC_C6000_SBR_L16_W
:
3247 case BFD_RELOC_C6000_SBR_GOT_L16_W
:
3256 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3257 if ((value
< -0x8000 || value
> 0x7fff)
3258 && (fixP
->fx_r_type
== BFD_RELOC_C6000_ABS_S16
3259 || fixP
->fx_r_type
== BFD_RELOC_C6000_SBR_S16
))
3260 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3261 _("immediate offset out of range"));
3263 md_number_to_chars (buf
, newval
, 4);
3266 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_S16
3267 && fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_L16
)
3271 case BFD_RELOC_C6000_ABS_H16
:
3272 case BFD_RELOC_C6000_SBR_H16_B
:
3273 case BFD_RELOC_C6000_SBR_H16_H
:
3274 case BFD_RELOC_C6000_SBR_H16_W
:
3275 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3276 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3278 offsetT newval
= md_chars_to_number (buf
, 4);
3281 switch (fixP
->fx_r_type
)
3283 case BFD_RELOC_C6000_SBR_H16_H
:
3287 case BFD_RELOC_C6000_SBR_H16_W
:
3288 case BFD_RELOC_C6000_SBR_GOT_H16_W
:
3297 MODIFY_VALUE (newval
, value
, shift
, 7, 16);
3299 md_number_to_chars (buf
, newval
, 4);
3301 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_ABS_H16
)
3305 case BFD_RELOC_C6000_SBR_U15_B
:
3306 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3308 offsetT newval
= md_chars_to_number (buf
, 4);
3310 MODIFY_VALUE (newval
, value
, 0, 8, 15);
3311 if (value
< 0 || value
> 0x7fff)
3312 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3313 _("immediate offset out of range"));
3315 md_number_to_chars (buf
, newval
, 4);
3319 case BFD_RELOC_C6000_SBR_U15_H
:
3320 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3322 offsetT newval
= md_chars_to_number (buf
, 4);
3324 /* Constant ADDA operands, processed as constant when the
3325 instruction is parsed, are encoded as-is rather than
3326 shifted. If the operand of an ADDA instruction is now
3327 constant (for example, the difference between two labels
3328 found after the instruction), ensure it is encoded the
3329 same way it would have been if the constant value had
3330 been known when the instruction was parsed. */
3331 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3334 MODIFY_VALUE (newval
, value
, 1, 8, 15);
3336 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3337 _("immediate offset not 2-byte-aligned"));
3338 if (value
< 0 || value
> 0xfffe)
3339 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3340 _("immediate offset out of range"));
3342 md_number_to_chars (buf
, newval
, 4);
3346 case BFD_RELOC_C6000_SBR_U15_W
:
3347 case BFD_RELOC_C6000_SBR_GOT_U15_W
:
3348 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3350 offsetT newval
= md_chars_to_number (buf
, 4);
3352 /* Constant ADDA operands, processed as constant when the
3353 instruction is parsed, are encoded as-is rather than
3354 shifted. If the operand of an ADDA instruction is now
3355 constant (for example, the difference between two labels
3356 found after the instruction), ensure it is encoded the
3357 same way it would have been if the constant value had
3358 been known when the instruction was parsed. */
3359 if (fixP
->tc_fix_data
.fix_adda
&& fixP
->fx_done
)
3362 MODIFY_VALUE (newval
, value
, 2, 8, 15);
3364 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3365 _("immediate offset not 4-byte-aligned"));
3366 if (value
< 0 || value
> 0x1fffc)
3367 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3368 _("immediate offset out of range"));
3370 md_number_to_chars (buf
, newval
, 4);
3372 if (fixP
->fx_done
&& fixP
->fx_r_type
!= BFD_RELOC_C6000_SBR_U15_W
)
3376 case BFD_RELOC_C6000_DSBT_INDEX
:
3378 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3379 _("addend used with $DSBT_INDEX"));
3384 case BFD_RELOC_C6000_PCR_S21
:
3385 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3387 offsetT newval
= md_chars_to_number (buf
, 4);
3389 MODIFY_VALUE (newval
, value
, 2, 7, 21);
3392 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3393 _("PC-relative offset not 4-byte-aligned"));
3394 if (value
< -0x400000 || value
> 0x3ffffc)
3395 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3396 _("PC-relative offset out of range"));
3398 md_number_to_chars (buf
, newval
, 4);
3402 case BFD_RELOC_C6000_PCR_S12
:
3403 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3405 offsetT newval
= md_chars_to_number (buf
, 4);
3407 MODIFY_VALUE (newval
, value
, 2, 16, 12);
3410 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3411 _("PC-relative offset not 4-byte-aligned"));
3412 if (value
< -0x2000 || value
> 0x1ffc)
3413 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3414 _("PC-relative offset out of range"));
3416 md_number_to_chars (buf
, newval
, 4);
3420 case BFD_RELOC_C6000_PCR_S10
:
3421 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3423 offsetT newval
= md_chars_to_number (buf
, 4);
3425 MODIFY_VALUE (newval
, value
, 2, 13, 10);
3428 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3429 _("PC-relative offset not 4-byte-aligned"));
3430 if (value
< -0x800 || value
> 0x7fc)
3431 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3432 _("PC-relative offset out of range"));
3434 md_number_to_chars (buf
, newval
, 4);
3438 case BFD_RELOC_C6000_PCR_S7
:
3439 if (fixP
->fx_done
|| !seg
->use_rela_p
)
3441 offsetT newval
= md_chars_to_number (buf
, 4);
3443 MODIFY_VALUE (newval
, value
, 2, 16, 7);
3446 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3447 _("PC-relative offset not 4-byte-aligned"));
3448 if (value
< -0x100 || value
> 0xfc)
3449 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3450 _("PC-relative offset out of range"));
3452 md_number_to_chars (buf
, newval
, 4);
3461 /* Convert a floating-point number to target (IEEE) format. */
3464 md_atof (int type
, char *litP
, int *sizeP
)
3466 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
3469 /* Adjust the frags in SECTION (see tic6x_end). */
3472 tic6x_adjust_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT section
,
3473 void *dummy ATTRIBUTE_UNUSED
)
3475 segment_info_type
*info
;
3478 bfd_boolean have_code
= FALSE
;
3479 bfd_boolean have_non_code
= FALSE
;
3481 info
= seg_info (section
);
3485 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
3486 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
3487 switch (fragp
->fr_type
)
3489 case rs_machine_dependent
:
3490 if (fragp
->tc_frag_data
.is_insns
)
3496 if (fragp
->fr_fix
> 0)
3497 have_non_code
= TRUE
;
3501 have_non_code
= TRUE
;
3505 /* Process alignment requirements in a code-only section. */
3506 if (have_code
&& !have_non_code
)
3508 /* If we need to insert an odd number of instructions to meet an
3509 alignment requirement, there must have been an odd number of
3510 instructions since the last 8-byte-aligned execute packet
3511 boundary. So there must have been an execute packet with an
3512 odd number (and so a number fewer than 8) of instructions
3513 into which we can insert a NOP without breaking any previous
3516 If then we need to insert a number 2 mod 4 of instructions,
3517 the number of instructions since the last 16-byte-aligned
3518 execute packet boundary must be 2 mod 4. So between that
3519 boundary and the following 8-byte-aligned boundary there must
3520 either be at least one execute packet with 2-mod-4
3521 instructions, or at least two with an odd number of
3522 instructions; again, greedily inserting NOPs as soon as
3523 possible suffices to meet the alignment requirement.
3525 If then we need to insert 4 instructions, we look between the
3526 last 32-byte-aligned boundary and the following
3527 16-byte-aligned boundary. The sizes of the execute packets
3528 in this range total 4 instructions mod 8, so again there is
3529 room for greedy insertion of NOPs to meet the alignment
3530 requirement, and before any intermediate point with 8-byte
3531 (2-instruction) alignment requirement the sizes of execute
3532 packets (and so the room for NOPs) will total 2 instructions
3533 mod 4 so greedy insertion will not break such alignments.
3535 So we can always meet these alignment requirements by
3536 inserting NOPs in parallel with existing execute packets, and
3537 by induction the approach described above inserts the minimum
3538 number of such NOPs. */
3540 /* The number of NOPs we are currently looking to insert, if we
3541 have gone back to insert NOPs. */
3542 unsigned int want_insert
= 0;
3544 /* Out of that number, the number inserted so far in the current
3545 stage of the above algorithm. */
3546 unsigned int want_insert_done_so_far
= 0;
3548 /* The position mod 32 at the start of the current frag. */
3549 unsigned int pos
= 0;
3551 /* The locations in the frag chain of the most recent frags at
3552 the start of which there is the given alignment. */
3553 frchainS
*frchp_last32
, *frchp_last16
, *frchp_last8
;
3554 fragS
*fragp_last32
, *fragp_last16
, *fragp_last8
;
3555 unsigned int pos_last32
, pos_last16
, pos_last8
;
3557 frchp_last32
= frchp_last16
= frchp_last8
= info
->frchainP
;
3558 fragp_last32
= fragp_last16
= fragp_last8
= info
->frchainP
->frch_root
;
3559 pos_last32
= pos_last16
= pos_last8
= 0;
3561 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
3562 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
3565 bfd_boolean go_back
= FALSE
;
3566 frchainS
*frchp_next
;
3569 if (fragp
->fr_type
!= rs_machine_dependent
)
3572 if (fragp
->tc_frag_data
.is_insns
3573 && pos
+ fragp
->fr_fix
> 32
3574 && !fragp
->tc_frag_data
.can_cross_fp_boundary
)
3576 /* As described above, we should always have met an
3577 alignment requirement by the time we come back to
3584 want_insert
= (32 - pos
) >> 2;
3585 if (want_insert
> 7)
3587 want_insert_done_so_far
= 0;
3591 if (!fragp
->tc_frag_data
.is_insns
)
3593 unsigned int would_insert_bytes
;
3595 if (!(pos
& ((1 << fragp
->fr_offset
) - 1)))
3596 /* This alignment requirement is already met. */
3599 /* As described above, we should always have met an
3600 alignment requirement by the time we come back to
3605 /* We may not be able to meet this requirement within
3606 the given number of characters. */
3608 = ((1 << fragp
->fr_offset
)
3609 - (pos
& ((1 << fragp
->fr_offset
) - 1)));
3611 if (fragp
->fr_subtype
!= 0
3612 && would_insert_bytes
> fragp
->fr_subtype
)
3615 /* An unmet alignment must be 8, 16 or 32 bytes;
3616 smaller ones must always be met within code-only
3617 sections and larger ones cause the section not to
3619 if (fragp
->fr_offset
!= 3
3620 && fragp
->fr_offset
!= 4
3621 && fragp
->fr_offset
!= 5)
3624 if (would_insert_bytes
& 3)
3626 want_insert
= would_insert_bytes
>> 2;
3627 if (want_insert
> 7)
3629 want_insert_done_so_far
= 0;
3632 else if (want_insert
&& !go_back
)
3634 unsigned int num_insns
= fragp
->fr_fix
>> 2;
3635 unsigned int max_poss_nops
= 8 - num_insns
;
3639 unsigned int cur_want_nops
, max_want_nops
, do_nops
, i
;
3641 if (want_insert
& 1)
3643 else if (want_insert
& 2)
3645 else if (want_insert
& 4)
3650 max_want_nops
= cur_want_nops
- want_insert_done_so_far
;
3652 do_nops
= (max_poss_nops
< max_want_nops
3655 for (i
= 0; i
< do_nops
; i
++)
3657 md_number_to_chars (fragp
->fr_literal
+ fragp
->fr_fix
,
3659 if (target_big_endian
)
3660 fragp
->fr_literal
[fragp
->fr_fix
- 1] |= 0x1;
3662 fragp
->fr_literal
[fragp
->fr_fix
- 4] |= 0x1;
3666 want_insert_done_so_far
+= do_nops
;
3667 if (want_insert_done_so_far
== cur_want_nops
)
3669 want_insert
-= want_insert_done_so_far
;
3670 want_insert_done_so_far
= 0;
3678 if (want_insert
& 1)
3680 frchp
= frchp_last8
;
3681 fragp
= fragp_last8
;
3684 else if (want_insert
& 2)
3686 frchp
= frchp_last8
= frchp_last16
;
3687 fragp
= fragp_last8
= fragp_last16
;
3688 pos
= pos_last8
= pos_last16
;
3690 else if (want_insert
& 4)
3692 frchp
= frchp_last8
= frchp_last16
= frchp_last32
;
3693 fragp
= fragp_last8
= fragp_last16
= fragp_last32
;
3694 pos
= pos_last8
= pos_last16
= pos_last32
;
3702 /* Update current position for moving past a code
3704 pos
+= fragp
->fr_fix
;
3707 fragp_next
= fragp
->fr_next
;
3708 if (fragp_next
== NULL
)
3710 frchp_next
= frchp
->frch_next
;
3711 if (frchp_next
!= NULL
)
3712 fragp_next
= frchp_next
->frch_root
;
3716 frchp_last8
= frchp_next
;
3717 fragp_last8
= fragp_next
;
3722 frchp_last16
= frchp_next
;
3723 fragp_last16
= fragp_next
;
3728 frchp_last32
= frchp_next
;
3729 fragp_last32
= fragp_next
;
3735 /* Now convert the machine-dependent frags to machine-independent
3737 for (frchp
= info
->frchainP
; frchp
; frchp
= frchp
->frch_next
)
3738 for (fragp
= frchp
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
3740 if (fragp
->fr_type
== rs_machine_dependent
)
3742 if (fragp
->tc_frag_data
.is_insns
)
3746 fragp
->fr_type
= rs_align_code
;
3748 *fragp
->fr_literal
= 0;
3754 /* Initialize the machine-dependent parts of a frag. */
3757 tic6x_frag_init (fragS
*fragp
)
3759 fragp
->tc_frag_data
.is_insns
= FALSE
;
3760 fragp
->tc_frag_data
.can_cross_fp_boundary
= FALSE
;
3763 /* Do machine-dependent manipulations of the frag chains after all
3764 input has been read and before the machine-independent sizing and
3770 /* Meeting alignment requirements may require inserting NOPs in
3771 parallel in execute packets earlier in the segment. Future
3772 16-bit instruction generation involves whole-segment optimization
3773 to determine the best choice and ordering of 32-bit or 16-bit
3774 instructions. This doesn't fit will in the general relaxation
3775 framework, so handle alignment and 16-bit instruction generation
3777 bfd_map_over_sections (stdoutput
, tic6x_adjust_section
, NULL
);
3780 /* No machine-dependent frags at this stage; all converted in
3784 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT asec ATTRIBUTE_UNUSED
,
3785 fragS
*fragp ATTRIBUTE_UNUSED
)
3790 /* No machine-dependent frags at this stage; all converted in
3794 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
3795 segT seg ATTRIBUTE_UNUSED
)
3800 /* Put a number into target byte order. */
3803 md_number_to_chars (char *buf
, valueT val
, int n
)
3805 if (target_big_endian
)
3806 number_to_chars_bigendian (buf
, val
, n
);
3808 number_to_chars_littleendian (buf
, val
, n
);
3811 /* Machine-dependent operand parsing not currently needed. */
3814 md_operand (expressionS
*op ATTRIBUTE_UNUSED
)
3818 /* PC-relative operands are relative to the start of the fetch
3822 tic6x_pcrel_from_section (fixS
*fixp
, segT sec
)
3824 if (fixp
->fx_addsy
!= NULL
3825 && (!S_IS_DEFINED (fixp
->fx_addsy
)
3826 || S_GET_SEGMENT (fixp
->fx_addsy
) != sec
))
3828 return (fixp
->fx_where
+ fixp
->fx_frag
->fr_address
) & ~(long) 0x1f;
3831 /* Round up a section size to the appropriate boundary. */
3834 md_section_align (segT segment ATTRIBUTE_UNUSED
,
3837 /* Round up section sizes to ensure that text sections consist of
3838 whole fetch packets. */
3839 int align
= bfd_get_section_alignment (stdoutput
, segment
);
3840 return ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
3843 /* No special undefined symbol handling needed for now. */
3846 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
3851 /* Translate internal representation of relocation info to BFD target
3855 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
3858 bfd_reloc_code_real_type r_type
;
3860 reloc
= xmalloc (sizeof (arelent
));
3861 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
3862 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3863 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3864 reloc
->addend
= (tic6x_generate_rela
? fixp
->fx_offset
: 0);
3865 r_type
= fixp
->fx_r_type
;
3866 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
3868 if (reloc
->howto
== NULL
)
3870 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3871 _("Cannot represent relocation type %s"),
3872 bfd_get_reloc_code_name (r_type
));
3876 /* Correct for adjustments bfd_install_relocation will make. */
3877 if (reloc
->howto
->pcrel_offset
&& reloc
->howto
->partial_inplace
)
3878 reloc
->addend
+= reloc
->address
;