1 /* tc-tilegx.c -- Assemble for a Tile-Gx chip.
2 Copyright 2011 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 #include "struc-symbol.h"
25 #include "elf/tilegx.h"
26 #include "opcode/tilegx.h"
28 #include "dwarf2dbg.h"
29 #include "dw2gencfi.h"
31 #include "safe-ctype.h"
34 /* Special registers. */
44 /* Generic assembler global variables which must be defined by all
47 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
48 int tilegx_cie_data_alignment
;
50 /* Characters which always start a comment. */
51 const char comment_chars
[] = "#";
53 /* Characters which start a comment at the beginning of a line. */
54 const char line_comment_chars
[] = "#";
56 /* Characters which may be used to separate multiple commands on a
58 const char line_separator_chars
[] = ";";
60 /* Characters which are used to indicate an exponent in a floating
62 const char EXP_CHARS
[] = "eE";
64 /* Characters which mean that a number is a floating point constant,
66 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
68 /* Either 32 or 64. */
69 static int tilegx_arch_size
= 64;
73 tilegx_target_format (void)
75 return tilegx_arch_size
== 64 ? "elf64-tilegx" : "elf32-tilegx";
79 #define OPTION_32 (OPTION_MD_BASE + 0)
80 #define OPTION_64 (OPTION_MD_BASE + 1)
82 const char *md_shortopts
= "VQ:";
84 struct option md_longopts
[] =
86 {"32", no_argument
, NULL
, OPTION_32
},
87 {"64", no_argument
, NULL
, OPTION_64
},
88 {NULL
, no_argument
, NULL
, 0}
91 size_t md_longopts_size
= sizeof (md_longopts
);
94 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
98 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
99 should be emitted or not. FIXME: Not implemented. */
103 /* -V: SVR4 argument to print version ID. */
109 tilegx_arch_size
= 32;
113 tilegx_arch_size
= 64;
124 md_show_usage (FILE *stream
)
126 fprintf (stream
, _("\
128 -V print assembler version number\n\
129 --32/--64 generate 32bit/64bit code\n"));
133 /* Extra expression types. */
139 #define O_hw0_last O_md5
140 #define O_hw1_last O_md6
141 #define O_hw2_last O_md7
142 #define O_hw0_got O_md8
143 #define O_hw1_got O_md9
144 #define O_hw2_got O_md10
145 #define O_hw3_got O_md11
146 #define O_hw0_last_got O_md12
147 #define O_hw1_last_got O_md13
148 #define O_hw2_last_got O_md14
150 #define O_hw0_tls_gd O_md16
151 #define O_hw1_tls_gd O_md17
152 #define O_hw2_tls_gd O_md18
153 #define O_hw3_tls_gd O_md19
154 #define O_hw0_last_tls_gd O_md20
155 #define O_hw1_last_tls_gd O_md21
156 #define O_hw2_last_tls_gd O_md22
157 #define O_hw0_tls_ie O_md23
158 #define O_hw1_tls_ie O_md24
159 #define O_hw2_tls_ie O_md25
160 #define O_hw3_tls_ie O_md26
161 #define O_hw0_last_tls_ie O_md27
162 #define O_hw1_last_tls_ie O_md28
163 #define O_hw2_last_tls_ie O_md29
165 static struct hash_control
*special_operator_hash
;
167 /* Hash tables for instruction mnemonic lookup. */
168 static struct hash_control
*op_hash
;
170 /* Hash table for spr lookup. */
171 static struct hash_control
*spr_hash
;
173 /* True temporarily while parsing an SPR expression. This changes the
174 * namespace to include SPR names. */
175 static int parsing_spr
;
177 /* Are we currently inside `{ ... }'? */
178 static int inside_bundle
;
180 struct tilegx_instruction
182 const struct tilegx_opcode
*opcode
;
183 tilegx_pipeline pipe
;
184 expressionS operand_values
[TILEGX_MAX_OPERANDS
];
187 /* This keeps track of the current bundle being built up. */
188 static struct tilegx_instruction current_bundle
[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
];
190 /* Index in current_bundle for the next instruction to parse. */
191 static int current_bundle_index
;
193 /* Allow 'r63' in addition to 'zero', etc. Normally we disallow this as
194 'zero' is not a real register, so using it accidentally would be a
195 nasty bug. For other registers, such as 'sp', code using multiple names
196 for the same physical register is excessively confusing.
198 The '.require_canonical_reg_names' pseudo-op turns this error on,
199 and the '.no_require_canonical_reg_names' pseudo-op turns this off.
200 By default the error is on. */
201 static int require_canonical_reg_names
;
203 /* Allow bundles that do undefined or suspicious things like write
204 two different values to the same register at the same time.
206 The '.no_allow_suspicious_bundles' pseudo-op turns this error on,
207 and the '.allow_suspicious_bundles' pseudo-op turns this off. */
208 static int allow_suspicious_bundles
;
211 /* A hash table of main processor registers, mapping each register name
214 Furthermore, if the register number is greater than the number
215 of registers for that processor, the user used an illegal alias
216 for that register (e.g. r63 instead of zero), so we should generate
217 a warning. The attempted register number can be found by clearing
218 NONCANONICAL_REG_NAME_FLAG. */
219 static struct hash_control
*main_reg_hash
;
222 /* We cannot unambiguously store a 0 in a hash table and look it up,
223 so we OR in this flag to every canonical register. */
224 #define CANONICAL_REG_NAME_FLAG 0x1000
226 /* By default we disallow register aliases like r63, but we record
227 them in the hash table in case the .no_require_canonical_reg_names
228 directive is used. Noncanonical names have this value added to them. */
229 #define NONCANONICAL_REG_NAME_FLAG 0x2000
231 /* Discards flags for register hash table entries and returns the
233 #define EXTRACT_REGNO(p) ((p) & 63)
235 /* This function is called once, at assembler startup time. It should
236 set up all the tables, etc., that the MD part of the assembler will
242 const struct tilegx_opcode
*op
;
244 int mach
= (tilegx_arch_size
== 64) ? bfd_mach_tilegx
: bfd_mach_tilegx32
;
246 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_tilegx
, mach
))
247 as_warn (_("Could not set architecture and machine"));
249 /* Guarantee text section is aligned. */
250 bfd_set_section_alignment (stdoutput
, text_section
,
251 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
);
253 require_canonical_reg_names
= 1;
254 allow_suspicious_bundles
= 0;
255 current_bundle_index
= 0;
258 tilegx_cie_data_alignment
= (tilegx_arch_size
== 64 ? -8 : -4);
260 /* Initialize special operator hash table. */
261 special_operator_hash
= hash_new ();
262 #define INSERT_SPECIAL_OP(name) \
263 hash_insert (special_operator_hash, #name, (void *)O_##name)
265 INSERT_SPECIAL_OP (hw0
);
266 INSERT_SPECIAL_OP (hw1
);
267 INSERT_SPECIAL_OP (hw2
);
268 INSERT_SPECIAL_OP (hw3
);
269 INSERT_SPECIAL_OP (hw0_last
);
270 INSERT_SPECIAL_OP (hw1_last
);
271 INSERT_SPECIAL_OP (hw2_last
);
272 /* hw3_last is a convenience alias for the equivalent hw3. */
273 hash_insert (special_operator_hash
, "hw3_last", (void*)O_hw3
);
274 INSERT_SPECIAL_OP (hw0_got
);
275 INSERT_SPECIAL_OP (hw1_got
);
276 INSERT_SPECIAL_OP (hw2_got
);
277 INSERT_SPECIAL_OP (hw3_got
);
278 INSERT_SPECIAL_OP (hw0_last_got
);
279 INSERT_SPECIAL_OP (hw1_last_got
);
280 INSERT_SPECIAL_OP (hw2_last_got
);
281 INSERT_SPECIAL_OP(plt
);
282 INSERT_SPECIAL_OP (hw0_tls_gd
);
283 INSERT_SPECIAL_OP (hw1_tls_gd
);
284 INSERT_SPECIAL_OP (hw2_tls_gd
);
285 INSERT_SPECIAL_OP (hw3_tls_gd
);
286 INSERT_SPECIAL_OP (hw0_last_tls_gd
);
287 INSERT_SPECIAL_OP (hw1_last_tls_gd
);
288 INSERT_SPECIAL_OP (hw2_last_tls_gd
);
289 INSERT_SPECIAL_OP (hw0_tls_ie
);
290 INSERT_SPECIAL_OP (hw1_tls_ie
);
291 INSERT_SPECIAL_OP (hw2_tls_ie
);
292 INSERT_SPECIAL_OP (hw3_tls_ie
);
293 INSERT_SPECIAL_OP (hw0_last_tls_ie
);
294 INSERT_SPECIAL_OP (hw1_last_tls_ie
);
295 INSERT_SPECIAL_OP (hw2_last_tls_ie
);
296 #undef INSERT_SPECIAL_OP
298 /* Initialize op_hash hash table. */
299 op_hash
= hash_new ();
300 for (op
= &tilegx_opcodes
[0]; op
->name
!= NULL
; op
++)
302 const char *hash_err
= hash_insert (op_hash
, op
->name
, (void *)op
);
303 if (hash_err
!= NULL
)
304 as_fatal (_("Internal Error: Can't hash %s: %s"), op
->name
, hash_err
);
307 /* Initialize the spr hash table. */
309 spr_hash
= hash_new ();
310 for (i
= 0; i
< tilegx_num_sprs
; i
++)
311 hash_insert (spr_hash
, tilegx_sprs
[i
].name
,
312 (void *) &tilegx_sprs
[i
]);
314 /* Set up the main_reg_hash table. We use this instead of
315 creating a symbol in the register section to avoid ambiguities
316 with labels that have the same names as registers. */
317 main_reg_hash
= hash_new ();
318 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
322 hash_insert (main_reg_hash
, tilegx_register_names
[i
],
323 (void *) (long) (i
| CANONICAL_REG_NAME_FLAG
));
325 /* See if we should insert a noncanonical alias, like r63. */
326 sprintf (buf
, "r%d", i
);
327 if (strcmp (buf
, tilegx_register_names
[i
]) != 0)
328 hash_insert (main_reg_hash
, xstrdup (buf
),
329 (void *) (long) (i
| NONCANONICAL_REG_NAME_FLAG
));
333 #define BUNDLE_TEMPLATE_MASK(p0, p1, p2) \
334 ((p0) | ((p1) << 8) | ((p2) << 16))
335 #define BUNDLE_TEMPLATE(p0, p1, p2) \
336 { { (p0), (p1), (p2) }, \
337 BUNDLE_TEMPLATE_MASK(1 << (p0), 1 << (p1), (1 << (p2))) \
340 #define NO_PIPELINE TILEGX_NUM_PIPELINE_ENCODINGS
342 struct bundle_template
344 tilegx_pipeline pipe
[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
];
345 unsigned int pipe_mask
;
348 static const struct bundle_template bundle_templates
[] =
350 /* In Y format we must always have something in Y2, since it has
351 no fnop, so this conveys that Y2 must always be used. */
352 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
, TILEGX_PIPELINE_Y2
, NO_PIPELINE
),
353 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
, TILEGX_PIPELINE_Y2
, NO_PIPELINE
),
354 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
, TILEGX_PIPELINE_Y0
, NO_PIPELINE
),
355 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
, TILEGX_PIPELINE_Y1
, NO_PIPELINE
),
357 /* Y format has three instructions. */
358 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y2
),
359 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y1
),
360 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y2
),
361 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y0
),
362 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y1
),
363 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y0
),
365 /* X format has only two instructions. */
366 BUNDLE_TEMPLATE(TILEGX_PIPELINE_X0
, TILEGX_PIPELINE_X1
, NO_PIPELINE
),
367 BUNDLE_TEMPLATE(TILEGX_PIPELINE_X1
, TILEGX_PIPELINE_X0
, NO_PIPELINE
)
372 prepend_nop_to_bundle (tilegx_mnemonic mnemonic
)
374 memmove (¤t_bundle
[1], ¤t_bundle
[0],
375 current_bundle_index
* sizeof current_bundle
[0]);
376 current_bundle
[0].opcode
= &tilegx_opcodes
[mnemonic
];
377 ++current_bundle_index
;
380 static tilegx_bundle_bits
381 insert_operand (tilegx_bundle_bits bits
,
382 const struct tilegx_operand
*operand
,
387 /* Range-check the immediate. */
388 int num_bits
= operand
->num_bits
;
390 operand_value
>>= operand
->rightshift
;
392 if (bfd_check_overflow (operand
->is_signed
393 ? complain_overflow_signed
394 : complain_overflow_unsigned
,
397 bfd_arch_bits_per_address (stdoutput
),
402 if (operand
->is_signed
)
404 min
= -(1 << (num_bits
- 1));
405 max
= (1 << (num_bits
- 1)) - 1;
410 max
= (1 << num_bits
) - 1;
412 as_bad_value_out_of_range (_("operand"), operand_value
, min
, max
,
416 /* Write out the bits for the immediate. */
417 return bits
| operand
->insert (operand_value
);
422 apply_special_operator (operatorT op
, offsetT num
, char *file
, unsigned lineno
)
425 int check_shift
= -1;
429 case O_hw0_last_tls_gd
:
430 case O_hw0_last_tls_ie
:
437 ret
= (signed short)num
;
440 case O_hw1_last_tls_gd
:
441 case O_hw1_last_tls_ie
:
448 ret
= (signed short)(num
>> 16);
451 case O_hw2_last_tls_gd
:
452 case O_hw2_last_tls_ie
:
459 ret
= (signed short)(num
>> 32);
465 ret
= (signed short)(num
>> 48);
473 if (check_shift
>= 0 && ret
!= (num
>> check_shift
))
475 as_bad_value_out_of_range (_("operand"), num
,
476 ~0ULL << (check_shift
+ 16 - 1),
477 ~0ULL >> (64 - (check_shift
+ 16 - 1)),
484 static tilegx_bundle_bits
485 emit_tilegx_instruction (tilegx_bundle_bits bits
,
487 const unsigned char *operands
,
488 expressionS
*operand_values
,
493 for (i
= 0; i
< num_operands
; i
++)
495 const struct tilegx_operand
*operand
=
496 &tilegx_operands
[operands
[i
]];
497 expressionS
*operand_exp
= &operand_values
[i
];
498 int is_pc_relative
= operand
->is_pc_relative
;
500 if (operand_exp
->X_op
== O_register
501 || (operand_exp
->X_op
== O_constant
&& !is_pc_relative
))
503 /* We know what the bits are right now, so insert them. */
504 bits
= insert_operand (bits
, operand
, operand_exp
->X_add_number
,
509 bfd_reloc_code_real_type reloc
= operand
->default_reloc
;
511 int die
= 0, use_subexp
= 0, require_symbol
= 0;
514 /* Take an expression like hw0(x) and turn it into x with
515 a different reloc type. */
516 switch (operand_exp
->X_op
)
518 #define HANDLE_OP16(suffix) \
521 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST: \
522 reloc = BFD_RELOC_TILEGX_IMM16_X0_##suffix; \
524 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST: \
525 reloc = BFD_RELOC_TILEGX_IMM16_X1_##suffix; \
550 HANDLE_OP16 (HW0_LAST
);
554 HANDLE_OP16 (HW1_LAST
);
558 HANDLE_OP16 (HW2_LAST
);
562 HANDLE_OP16 (HW0_GOT
);
567 HANDLE_OP16 (HW1_GOT
);
572 HANDLE_OP16 (HW2_GOT
);
577 HANDLE_OP16 (HW3_GOT
);
582 HANDLE_OP16 (HW0_LAST_GOT
);
587 HANDLE_OP16 (HW1_LAST_GOT
);
592 HANDLE_OP16 (HW2_LAST_GOT
);
597 HANDLE_OP16 (HW0_TLS_GD
);
602 HANDLE_OP16 (HW1_TLS_GD
);
607 HANDLE_OP16 (HW2_TLS_GD
);
612 HANDLE_OP16 (HW3_TLS_GD
);
616 case O_hw0_last_tls_gd
:
617 HANDLE_OP16 (HW0_LAST_TLS_GD
);
621 case O_hw1_last_tls_gd
:
622 HANDLE_OP16 (HW1_LAST_TLS_GD
);
626 case O_hw2_last_tls_gd
:
627 HANDLE_OP16 (HW2_LAST_TLS_GD
);
632 HANDLE_OP16 (HW0_TLS_IE
);
637 HANDLE_OP16 (HW1_TLS_IE
);
642 HANDLE_OP16 (HW2_TLS_IE
);
647 HANDLE_OP16 (HW3_TLS_IE
);
651 case O_hw0_last_tls_ie
:
652 HANDLE_OP16 (HW0_LAST_TLS_IE
);
656 case O_hw1_last_tls_ie
:
657 HANDLE_OP16 (HW1_LAST_TLS_IE
);
661 case O_hw2_last_tls_ie
:
662 HANDLE_OP16 (HW2_LAST_TLS_IE
);
671 case BFD_RELOC_TILEGX_JUMPOFF_X1
:
672 reloc
= BFD_RELOC_TILEGX_JUMPOFF_X1_PLT
;
689 as_bad (_("Invalid operator for operand."));
693 /* Now that we've changed the reloc, change ha16(x) into x,
696 if (operand_exp
->X_add_symbol
->sy_value
.X_md
)
698 /* HACK: We used X_md to mark this symbol as a fake wrapper
699 around a real expression. To unwrap it, we just grab its
701 operand_exp
= &operand_exp
->X_add_symbol
->sy_value
;
705 /* Look at the expression, and reject it if it's not a
707 if (operand_exp
->X_op
!= O_symbol
708 || operand_exp
->X_add_number
!= 0)
709 as_bad (_("Operator may only be applied to symbols."));
714 /* The value of this expression is an actual symbol, so
715 turn that into an expression. */
716 memset (&subexp
, 0, sizeof subexp
);
717 subexp
.X_op
= O_symbol
;
718 subexp
.X_add_symbol
= operand_exp
->X_add_symbol
;
719 operand_exp
= &subexp
;
723 /* Create a fixup to handle this later. */
724 fixP
= fix_new_exp (frag_now
,
725 bundle_start
- frag_now
->fr_literal
,
726 (operand
->num_bits
+ 7) >> 3,
730 fixP
->tc_fix_data
= operand
;
732 /* Don't do overflow checking if we are applying a function like
734 fixP
->fx_no_overflow
|= use_subexp
;
741 /* Detects and complains if two instructions in current_bundle write
742 to the same register, either implicitly or explicitly, or if a
743 read-only register is written. */
745 check_illegal_reg_writes (void)
747 BFD_HOST_U_64_BIT all_regs_written
= 0;
750 for (j
= 0; j
< current_bundle_index
; j
++)
752 const struct tilegx_instruction
*instr
= ¤t_bundle
[j
];
754 BFD_HOST_U_64_BIT regs
=
755 ((BFD_HOST_U_64_BIT
)1) << instr
->opcode
->implicitly_written_register
;
756 BFD_HOST_U_64_BIT conflict
;
758 for (k
= 0; k
< instr
->opcode
->num_operands
; k
++)
760 const struct tilegx_operand
*operand
=
761 &tilegx_operands
[instr
->opcode
->operands
[instr
->pipe
][k
]];
763 if (operand
->is_dest_reg
)
765 int regno
= instr
->operand_values
[k
].X_add_number
;
766 BFD_HOST_U_64_BIT mask
= ((BFD_HOST_U_64_BIT
)1) << regno
;
768 if ((mask
& ( (((BFD_HOST_U_64_BIT
)1) << TREG_IDN1
)
769 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN1
)
770 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN2
)
771 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN3
))) != 0
772 && !allow_suspicious_bundles
)
774 as_bad (_("Writes to register '%s' are not allowed."),
775 tilegx_register_names
[regno
]);
782 /* Writing to the zero register doesn't count. */
783 regs
&= ~(((BFD_HOST_U_64_BIT
)1) << TREG_ZERO
);
785 conflict
= all_regs_written
& regs
;
786 if (conflict
!= 0 && !allow_suspicious_bundles
)
788 /* Find which register caused the conflict. */
789 const char *conflicting_reg_name
= "???";
792 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
794 if (((conflict
>> i
) & 1) != 0)
796 conflicting_reg_name
= tilegx_register_names
[i
];
801 as_bad (_("Two instructions in the same bundle both write "
802 "to register %s, which is not allowed."),
803 conflicting_reg_name
);
806 all_regs_written
|= regs
;
812 tilegx_flush_bundle (void)
817 unsigned compatible_pipes
;
818 const struct bundle_template
*match
;
823 switch (current_bundle_index
)
826 /* No instructions. */
829 if (current_bundle
[0].opcode
->can_bundle
)
831 /* Simplify later logic by adding an explicit fnop. */
832 prepend_nop_to_bundle (TILEGX_OPC_FNOP
);
836 /* This instruction cannot be bundled with anything else.
837 Prepend an explicit 'nop', rather than an 'fnop', because
838 fnops can be replaced by later binary-processing tools while
840 prepend_nop_to_bundle (TILEGX_OPC_NOP
);
844 if (!allow_suspicious_bundles
)
846 /* Make sure all instructions can be bundled with other
848 const struct tilegx_opcode
*cannot_bundle
= NULL
;
849 bfd_boolean seen_non_nop
= FALSE
;
851 for (j
= 0; j
< current_bundle_index
; j
++)
853 const struct tilegx_opcode
*op
= current_bundle
[j
].opcode
;
855 if (!op
->can_bundle
&& cannot_bundle
== NULL
)
857 else if (op
->mnemonic
!= TILEGX_OPC_NOP
858 && op
->mnemonic
!= TILEGX_OPC_INFO
859 && op
->mnemonic
!= TILEGX_OPC_INFOL
)
863 if (cannot_bundle
!= NULL
&& seen_non_nop
)
865 current_bundle_index
= 0;
866 as_bad (_("'%s' may not be bundled with other instructions."),
867 cannot_bundle
->name
);
875 BUNDLE_TEMPLATE_MASK(current_bundle
[0].opcode
->pipes
,
876 current_bundle
[1].opcode
->pipes
,
877 (current_bundle_index
== 3
878 ? current_bundle
[2].opcode
->pipes
879 : (1 << NO_PIPELINE
)));
881 /* Find a template that works, if any. */
883 for (i
= 0; i
< sizeof bundle_templates
/ sizeof bundle_templates
[0]; i
++)
885 const struct bundle_template
*b
= &bundle_templates
[i
];
886 if ((b
->pipe_mask
& compatible_pipes
) == b
->pipe_mask
)
895 current_bundle_index
= 0;
896 as_bad (_("Invalid combination of instructions for bundle."));
900 /* If the section seems to have no alignment set yet, go ahead and
901 make it large enough to hold code. */
902 if (bfd_get_section_alignment (stdoutput
, now_seg
) == 0)
903 bfd_set_section_alignment (stdoutput
, now_seg
,
904 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
);
906 for (j
= 0; j
< current_bundle_index
; j
++)
907 current_bundle
[j
].pipe
= match
->pipe
[j
];
909 if (current_bundle_index
== 2 && !tilegx_is_x_pipeline (match
->pipe
[0]))
911 /* We are in Y mode with only two instructions, so add an FNOP. */
912 prepend_nop_to_bundle (TILEGX_OPC_FNOP
);
914 /* Figure out what pipe the fnop must be in via arithmetic.
915 * p0 + p1 + p2 must sum to the sum of TILEGX_PIPELINE_Y[012]. */
916 current_bundle
[0].pipe
=
917 (tilegx_pipeline
)((TILEGX_PIPELINE_Y0
919 + TILEGX_PIPELINE_Y2
) -
920 (current_bundle
[1].pipe
+ current_bundle
[2].pipe
));
923 check_illegal_reg_writes ();
925 f
= frag_more (TILEGX_BUNDLE_SIZE_IN_BYTES
);
927 /* Check to see if this bundle is at an offset that is a multiple of 8-bytes
928 from the start of the frag. */
929 addr_mod
= frag_now_fix () & (TILEGX_BUNDLE_ALIGNMENT_IN_BYTES
- 1);
930 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
931 as_bad (_("instruction address is not a multiple of 8"));
932 frag_now
->insn_addr
= addr_mod
;
933 frag_now
->has_code
= 1;
935 tilegx_bundle_bits bits
= 0;
936 for (j
= 0; j
< current_bundle_index
; j
++)
938 struct tilegx_instruction
*instr
= ¤t_bundle
[j
];
939 tilegx_pipeline pipeline
= instr
->pipe
;
940 const struct tilegx_opcode
*opcode
= instr
->opcode
;
942 bits
|= emit_tilegx_instruction (opcode
->fixed_bit_values
[pipeline
],
943 opcode
->num_operands
,
944 &opcode
->operands
[pipeline
][0],
945 instr
->operand_values
,
949 number_to_chars_littleendian (f
, bits
, 8);
950 current_bundle_index
= 0;
952 /* Emit DWARF2 debugging information. */
953 dwarf2_emit_insn (TILEGX_BUNDLE_SIZE_IN_BYTES
);
957 /* Extend the expression parser to handle hw0(label), etc.
958 as well as SPR names when in the context of parsing an SPR. */
961 tilegx_parse_name (char *name
, expressionS
*e
, char *nextcharP
)
963 operatorT op
= O_illegal
;
967 void* val
= hash_find (spr_hash
, name
);
971 memset (e
, 0, sizeof *e
);
972 e
->X_op
= O_constant
;
973 e
->X_add_number
= ((const struct tilegx_spr
*)val
)->number
;
977 if (*nextcharP
!= '(')
979 /* hw0, etc. not followed by a paren is just a label with that name. */
984 /* Look up the operator in our table. */
985 void* val
= hash_find (special_operator_hash
, name
);
988 op
= (operatorT
)(long)val
;
991 /* Restore old '(' and skip it. */
992 *input_line_pointer
= '(';
993 ++input_line_pointer
;
997 if (*input_line_pointer
!= ')')
999 as_bad (_("Missing ')'"));
1000 *nextcharP
= *input_line_pointer
;
1004 ++input_line_pointer
;
1006 if (e
->X_op
== O_register
|| e
->X_op
== O_absent
)
1008 as_bad (_("Invalid expression."));
1009 e
->X_op
= O_constant
;
1010 e
->X_add_number
= 0;
1014 /* Wrap subexpression with a unary operator. */
1015 symbolS
*sym
= make_expr_symbol (e
);
1017 if (sym
!= e
->X_add_symbol
)
1019 /* HACK: mark this symbol as a temporary wrapper around a proper
1020 expression, so we can unwrap it later once we have communicated
1021 the relocation type. */
1022 sym
->sy_value
.X_md
= 1;
1025 memset (e
, 0, sizeof *e
);
1027 e
->X_add_symbol
= sym
;
1028 e
->X_add_number
= 0;
1031 *nextcharP
= *input_line_pointer
;
1036 /* Parses an expression which must be a register name. */
1039 parse_reg_expression (expressionS
* expression
)
1041 /* Zero everything to make sure we don't miss any flags. */
1042 memset (expression
, 0, sizeof *expression
);
1044 char* regname
= input_line_pointer
;
1045 char terminating_char
= get_symbol_end ();
1047 void* pval
= hash_find (main_reg_hash
, regname
);
1051 as_bad (_("Expected register, got '%s'."), regname
);
1054 int regno_and_flags
= (int)(size_t)pval
;
1055 int regno
= EXTRACT_REGNO(regno_and_flags
);
1057 if ((regno_and_flags
& NONCANONICAL_REG_NAME_FLAG
)
1058 && require_canonical_reg_names
)
1060 as_warn (_("Found use of non-canonical register name %s; "
1063 tilegx_register_names
[regno
]);
1066 /* Restore the old character following the register name. */
1067 *input_line_pointer
= terminating_char
;
1069 /* Fill in the expression fields to indicate it's a register. */
1070 expression
->X_op
= O_register
;
1071 expression
->X_add_number
= regno
;
1075 /* Parses and type-checks comma-separated operands in input_line_pointer. */
1078 parse_operands (const char *opcode_name
,
1079 const unsigned char *operands
,
1081 expressionS
*operand_values
)
1085 memset (operand_values
, 0, num_operands
* sizeof operand_values
[0]);
1088 for (i
= 0; i
< num_operands
; i
++)
1090 tilegx_operand_type type
= tilegx_operands
[operands
[i
]].type
;
1094 if (type
== TILEGX_OP_TYPE_REGISTER
)
1096 parse_reg_expression (&operand_values
[i
]);
1098 else if (*input_line_pointer
== '}')
1100 operand_values
[i
].X_op
= O_absent
;
1102 else if (type
== TILEGX_OP_TYPE_SPR
)
1104 /* Modify the expression parser to add SPRs to the namespace. */
1106 expression (&operand_values
[i
]);
1111 expression (&operand_values
[i
]);
1116 if (i
+ 1 < num_operands
)
1118 int separator
= (unsigned char)*input_line_pointer
++;
1120 if (is_end_of_line
[separator
] || (separator
== '}'))
1122 as_bad (_("Too few operands to '%s'."), opcode_name
);
1125 else if (separator
!= ',')
1127 as_bad (_("Unexpected character '%c' after operand %d to %s."),
1128 (char)separator
, i
+ 1, opcode_name
);
1133 /* Arbitrarily use the first valid pipe to get the operand type,
1134 since they are all the same. */
1135 switch (tilegx_operands
[operands
[i
]].type
)
1137 case TILEGX_OP_TYPE_REGISTER
:
1138 /* Handled in parse_reg_expression already. */
1140 case TILEGX_OP_TYPE_SPR
:
1142 case TILEGX_OP_TYPE_IMMEDIATE
:
1144 case TILEGX_OP_TYPE_ADDRESS
:
1145 if ( operand_values
[i
].X_op
== O_register
1146 || operand_values
[i
].X_op
== O_illegal
1147 || operand_values
[i
].X_op
== O_absent
)
1148 as_bad (_("Expected immediate expression"));
1155 if (!is_end_of_line
[(unsigned char)*input_line_pointer
])
1157 switch (*input_line_pointer
)
1161 as_bad (_("Found '}' when not bundling."));
1162 ++input_line_pointer
;
1164 demand_empty_rest_of_line ();
1168 as_bad (_("Too many operands"));
1172 /* Use default error for unrecognized garbage. */
1173 demand_empty_rest_of_line ();
1180 /* This is the guts of the machine-dependent assembler. STR points to a
1181 machine dependent instruction. This function is supposed to emit the
1182 frags/bytes it assembles to. */
1185 md_assemble (char *str
)
1189 char *old_input_line_pointer
;
1190 const struct tilegx_opcode
*op
;
1193 /* Split off the opcode and look it up. */
1194 opname_len
= strcspn (str
, " {}");
1195 old_char
= str
[opname_len
];
1196 str
[opname_len
] = '\0';
1198 op
= hash_find(op_hash
, str
);
1199 str
[opname_len
] = old_char
;
1202 as_bad (_("Unknown opcode `%.*s'."), (int)opname_len
, str
);
1206 /* Prepare to parse the operands. */
1207 old_input_line_pointer
= input_line_pointer
;
1208 input_line_pointer
= str
+ opname_len
;
1211 if (current_bundle_index
== TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
)
1213 as_bad (_("Too many instructions for bundle."));
1214 tilegx_flush_bundle ();
1217 /* Make sure we have room for the upcoming bundle before we
1218 create any fixups. Otherwise if we have to switch to a new
1219 frag the fixup dot_value fields will be wrong. */
1220 frag_grow (TILEGX_BUNDLE_SIZE_IN_BYTES
);
1222 /* Find a valid pipe for this opcode. */
1223 for (first_pipe
= 0; (op
->pipes
& (1 << first_pipe
)) == 0; first_pipe
++)
1226 /* Call the function that assembles this instruction. */
1227 current_bundle
[current_bundle_index
].opcode
= op
;
1228 parse_operands (op
->name
,
1229 &op
->operands
[first_pipe
][0],
1231 current_bundle
[current_bundle_index
].operand_values
);
1232 ++current_bundle_index
;
1234 /* Restore the saved value of input_line_pointer. */
1235 input_line_pointer
= old_input_line_pointer
;
1237 /* If we weren't inside curly braces, go ahead and emit
1238 this lone instruction as a bundle right now. */
1240 tilegx_flush_bundle ();
1245 s_require_canonical_reg_names (int require
)
1247 demand_empty_rest_of_line ();
1248 require_canonical_reg_names
= require
;
1252 s_allow_suspicious_bundles (int allow
)
1254 demand_empty_rest_of_line ();
1255 allow_suspicious_bundles
= allow
;
1258 const pseudo_typeS md_pseudo_table
[] =
1260 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0). */
1262 {"require_canonical_reg_names", s_require_canonical_reg_names
, 1 },
1263 {"no_require_canonical_reg_names", s_require_canonical_reg_names
, 0 },
1264 {"allow_suspicious_bundles", s_allow_suspicious_bundles
, 1 },
1265 {"no_allow_suspicious_bundles", s_allow_suspicious_bundles
, 0 },
1269 /* Equal to MAX_PRECISION in atof-ieee.c */
1270 #define MAX_LITTLENUMS 6
1272 /* Turn the string pointed to by litP into a floating point constant
1273 of type TYPE, and emit the appropriate bytes. The number of
1274 LITTLENUMS emitted is stored in *SIZEP. An error message is
1275 returned, or NULL on OK. */
1278 md_atof (int type
, char *litP
, int *sizeP
)
1281 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1282 LITTLENUM_TYPE
*wordP
;
1299 return _("Bad call to md_atof ()");
1301 t
= atof_ieee (input_line_pointer
, type
, words
);
1303 input_line_pointer
= t
;
1305 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1306 /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
1307 the bigendian 386. */
1308 for (wordP
= words
+ prec
- 1; prec
--;)
1310 md_number_to_chars (litP
, (valueT
) (*wordP
--), sizeof (LITTLENUM_TYPE
));
1311 litP
+= sizeof (LITTLENUM_TYPE
);
1317 /* We have no need to default values of symbols. */
1320 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1327 tilegx_cons_fix_new (fragS
*frag
,
1333 bfd_reloc_code_real_type reloc
= BFD_RELOC_NONE
;
1334 int no_overflow
= 0;
1337 /* See if it's one of our special functions. */
1341 reloc
= BFD_RELOC_TILEGX_HW0
;
1345 reloc
= BFD_RELOC_TILEGX_HW1
;
1349 reloc
= BFD_RELOC_TILEGX_HW2
;
1353 reloc
= BFD_RELOC_TILEGX_HW3
;
1357 reloc
= BFD_RELOC_TILEGX_HW0_LAST
;
1360 reloc
= BFD_RELOC_TILEGX_HW1_LAST
;
1363 reloc
= BFD_RELOC_TILEGX_HW2_LAST
;
1371 if (reloc
!= BFD_RELOC_NONE
)
1375 as_bad (_("This operator only produces two byte values."));
1379 memset (&subexp
, 0, sizeof subexp
);
1380 subexp
.X_op
= O_symbol
;
1381 subexp
.X_add_symbol
= exp
->X_add_symbol
;
1389 reloc
= BFD_RELOC_8
;
1392 reloc
= BFD_RELOC_16
;
1395 reloc
= BFD_RELOC_32
;
1398 reloc
= BFD_RELOC_64
;
1401 as_bad (_("unsupported BFD relocation size %d"), nbytes
);
1402 reloc
= BFD_RELOC_64
;
1407 fixP
= fix_new_exp (frag
, where
, nbytes
, exp
, 0, reloc
);
1408 fixP
->tc_fix_data
= NULL
;
1409 fixP
->fx_no_overflow
|= no_overflow
;
1414 md_apply_fix (fixS
*fixP
, valueT
* valP
, segT seg ATTRIBUTE_UNUSED
)
1416 const struct tilegx_operand
*operand
;
1417 valueT value
= *valP
;
1421 /* Leave these for the linker. */
1422 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1423 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1426 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
1428 /* We can't actually support subtracting a symbol. */
1429 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
1432 /* Correct relocation types for pc-relativeness. */
1433 switch (fixP
->fx_r_type
)
1435 #define FIX_PCREL(rtype) \
1437 if (fixP->fx_pcrel) \
1438 fixP->fx_r_type = rtype##_PCREL; \
1441 case rtype##_PCREL: \
1442 if (!fixP->fx_pcrel) \
1443 fixP->fx_r_type = rtype; \
1446 FIX_PCREL (BFD_RELOC_8
);
1447 FIX_PCREL (BFD_RELOC_16
);
1448 FIX_PCREL (BFD_RELOC_32
);
1449 FIX_PCREL (BFD_RELOC_64
);
1450 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0
);
1451 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0
);
1452 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1
);
1453 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1
);
1454 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2
);
1455 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2
);
1456 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW3
);
1457 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW3
);
1458 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST
);
1459 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST
);
1460 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST
);
1461 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST
);
1462 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST
);
1463 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST
);
1472 if (fixP
->fx_addsy
!= NULL
)
1475 switch (fixP
->fx_r_type
)
1477 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD
:
1478 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD
:
1479 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE
:
1480 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE
:
1481 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
1482 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
1483 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
1484 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
1485 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_GD
:
1486 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_GD
:
1487 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_IE
:
1488 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_IE
:
1489 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
1490 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
1491 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
1492 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
1493 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_GD
:
1494 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_GD
:
1495 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_IE
:
1496 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_IE
:
1497 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
1498 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
1499 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
1500 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
1501 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_GD
:
1502 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_GD
:
1503 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_IE
:
1504 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_IE
:
1505 case BFD_RELOC_TILEGX_TLS_DTPMOD64
:
1506 case BFD_RELOC_TILEGX_TLS_DTPOFF64
:
1507 case BFD_RELOC_TILEGX_TLS_TPOFF64
:
1508 case BFD_RELOC_TILEGX_TLS_DTPMOD32
:
1509 case BFD_RELOC_TILEGX_TLS_DTPOFF32
:
1510 case BFD_RELOC_TILEGX_TLS_TPOFF32
:
1511 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
1522 /* Apply hw0, etc. */
1523 special
= O_illegal
;
1524 switch (fixP
->fx_r_type
)
1526 case BFD_RELOC_TILEGX_HW0
:
1527 case BFD_RELOC_TILEGX_IMM16_X0_HW0
:
1528 case BFD_RELOC_TILEGX_IMM16_X1_HW0
:
1529 case BFD_RELOC_TILEGX_IMM16_X0_HW0_PCREL
:
1530 case BFD_RELOC_TILEGX_IMM16_X1_HW0_PCREL
:
1531 case BFD_RELOC_TILEGX_IMM16_X0_HW0_GOT
:
1532 case BFD_RELOC_TILEGX_IMM16_X1_HW0_GOT
:
1533 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD
:
1534 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD
:
1535 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE
:
1536 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE
:
1540 case BFD_RELOC_TILEGX_HW0_LAST
:
1541 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST
:
1542 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST
:
1543 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
1544 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
1545 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_GOT
:
1546 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_GOT
:
1547 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
1548 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
1549 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
1550 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
1551 special
= O_hw0_last
;
1554 case BFD_RELOC_TILEGX_HW1
:
1555 case BFD_RELOC_TILEGX_IMM16_X0_HW1
:
1556 case BFD_RELOC_TILEGX_IMM16_X1_HW1
:
1557 case BFD_RELOC_TILEGX_IMM16_X0_HW1_PCREL
:
1558 case BFD_RELOC_TILEGX_IMM16_X1_HW1_PCREL
:
1559 case BFD_RELOC_TILEGX_IMM16_X0_HW1_GOT
:
1560 case BFD_RELOC_TILEGX_IMM16_X1_HW1_GOT
:
1561 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_GD
:
1562 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_GD
:
1563 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_IE
:
1564 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_IE
:
1568 case BFD_RELOC_TILEGX_HW1_LAST
:
1569 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST
:
1570 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST
:
1571 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
1572 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
1573 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_GOT
:
1574 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_GOT
:
1575 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
1576 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
1577 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
1578 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
1579 special
= O_hw1_last
;
1582 case BFD_RELOC_TILEGX_HW2
:
1583 case BFD_RELOC_TILEGX_IMM16_X0_HW2
:
1584 case BFD_RELOC_TILEGX_IMM16_X1_HW2
:
1585 case BFD_RELOC_TILEGX_IMM16_X0_HW2_PCREL
:
1586 case BFD_RELOC_TILEGX_IMM16_X1_HW2_PCREL
:
1587 case BFD_RELOC_TILEGX_IMM16_X0_HW2_GOT
:
1588 case BFD_RELOC_TILEGX_IMM16_X1_HW2_GOT
:
1589 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_GD
:
1590 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_GD
:
1591 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_IE
:
1592 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_IE
:
1596 case BFD_RELOC_TILEGX_HW2_LAST
:
1597 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST
:
1598 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST
:
1599 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
1600 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
1601 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_GOT
:
1602 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_GOT
:
1603 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
1604 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
1605 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
1606 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
1607 special
= O_hw2_last
;
1610 case BFD_RELOC_TILEGX_HW3
:
1611 case BFD_RELOC_TILEGX_IMM16_X0_HW3
:
1612 case BFD_RELOC_TILEGX_IMM16_X1_HW3
:
1613 case BFD_RELOC_TILEGX_IMM16_X0_HW3_PCREL
:
1614 case BFD_RELOC_TILEGX_IMM16_X1_HW3_PCREL
:
1615 case BFD_RELOC_TILEGX_IMM16_X0_HW3_GOT
:
1616 case BFD_RELOC_TILEGX_IMM16_X1_HW3_GOT
:
1617 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_GD
:
1618 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_GD
:
1619 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_IE
:
1620 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_IE
:
1629 if (special
!= O_illegal
)
1631 *valP
= value
= apply_special_operator (special
, value
,
1632 fixP
->fx_file
, fixP
->fx_line
);
1635 p
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1637 operand
= fixP
->tc_fix_data
;
1638 if (operand
!= NULL
)
1640 /* It's an instruction operand. */
1641 tilegx_bundle_bits bits
=
1642 insert_operand (0, operand
, value
, fixP
->fx_file
, fixP
->fx_line
);
1644 /* Note that we might either be writing out bits for a bundle
1645 or a static network instruction, which are different sizes, so it's
1646 important to stop touching memory once we run out of bits.
1647 ORing in values is OK since we know the existing bits for
1648 this operand are zero. */
1649 for (; bits
!= 0; bits
>>= 8)
1654 /* Some other kind of relocation. */
1655 switch (fixP
->fx_r_type
)
1658 case BFD_RELOC_8_PCREL
:
1659 md_number_to_chars (p
, value
, 1);
1663 case BFD_RELOC_16_PCREL
:
1664 md_number_to_chars (p
, value
, 2);
1668 case BFD_RELOC_32_PCREL
:
1669 md_number_to_chars (p
, value
, 4);
1673 case BFD_RELOC_64_PCREL
:
1674 md_number_to_chars (p
, value
, 8);
1678 /* Leave it for the linker. */
1687 /* Generate the BFD reloc to be stuck in the object file from the
1688 fixup used internally in the assembler. */
1691 tc_gen_reloc (asection
*sec ATTRIBUTE_UNUSED
, fixS
*fixp
)
1695 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1696 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1697 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1698 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1700 /* Make sure none of our internal relocations make it this far.
1701 They'd better have been fully resolved by this point. */
1702 gas_assert ((int) fixp
->fx_r_type
> 0);
1704 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1705 if (reloc
->howto
== NULL
)
1707 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1708 _("cannot represent `%s' relocation in object file"),
1709 bfd_get_reloc_code_name (fixp
->fx_r_type
));
1713 if (!fixp
->fx_pcrel
!= !reloc
->howto
->pc_relative
)
1715 as_fatal (_("internal error? cannot generate `%s' relocation (%d, %d)"),
1716 bfd_get_reloc_code_name (fixp
->fx_r_type
),
1717 fixp
->fx_pcrel
, reloc
->howto
->pc_relative
);
1719 gas_assert (!fixp
->fx_pcrel
== !reloc
->howto
->pc_relative
);
1721 reloc
->addend
= fixp
->fx_offset
;
1727 /* The location from which a PC relative jump should be calculated,
1728 given a PC relative reloc. */
1731 md_pcrel_from (fixS
*fixP
)
1733 return fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1737 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
1738 a section symbol plus some offset. */
1740 tilegx_fix_adjustable (fixS
*fix
)
1742 /* Prevent all adjustments to global symbols */
1743 if (S_IS_EXTERNAL (fix
->fx_addsy
) || S_IS_WEAK (fix
->fx_addsy
))
1751 tilegx_unrecognized_line (int ch
)
1758 as_bad (_("Found '{' when already bundling."));
1763 current_bundle_index
= 0;
1770 as_bad (_("Found '}' when not bundling."));
1774 tilegx_flush_bundle ();
1777 /* Allow '{' to follow on the same line. We also allow ";;", but that
1778 happens automatically because ';' is an end of line marker. */
1780 if (input_line_pointer
[0] == '{')
1782 input_line_pointer
++;
1783 return tilegx_unrecognized_line ('{');
1786 demand_empty_rest_of_line ();
1793 /* Not a valid line. */
1798 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
1799 of an rs_align_code fragment. */
1802 tilegx_handle_align (fragS
*fragp
)
1804 addressT bytes
, fix
;
1807 if (fragp
->fr_type
!= rs_align_code
)
1810 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
1811 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
1814 /* Determine the bits for NOP. */
1815 const struct tilegx_opcode
*nop_opcode
=
1816 &tilegx_opcodes
[TILEGX_OPC_NOP
];
1817 tilegx_bundle_bits nop
=
1818 ( nop_opcode
->fixed_bit_values
[TILEGX_PIPELINE_X0
]
1819 | nop_opcode
->fixed_bit_values
[TILEGX_PIPELINE_X1
]);
1821 if ((bytes
& (TILEGX_BUNDLE_SIZE_IN_BYTES
- 1)) != 0)
1823 fix
= bytes
& (TILEGX_BUNDLE_SIZE_IN_BYTES
- 1);
1829 number_to_chars_littleendian (p
, nop
, 8);
1830 fragp
->fr_fix
+= fix
;
1831 fragp
->fr_var
= TILEGX_BUNDLE_SIZE_IN_BYTES
;
1834 /* Standard calling conventions leave the CFA at SP on entry. */
1836 tilegx_cfi_frame_initial_instructions (void)
1838 cfi_add_CFA_def_cfa_register (54);
1842 tc_tilegx_regname_to_dw2regnum (char *regname
)
1845 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
1847 if (!strcmp (regname
, tilegx_register_names
[i
]))