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 if (target_big_endian
) {
76 return tilegx_arch_size
== 64 ? "elf64-tilegx-be" : "elf32-tilegx-be";
78 return tilegx_arch_size
== 64 ? "elf64-tilegx-le" : "elf32-tilegx-le";
83 #define OPTION_32 (OPTION_MD_BASE + 0)
84 #define OPTION_64 (OPTION_MD_BASE + 1)
85 #define OPTION_EB (OPTION_MD_BASE + 2)
86 #define OPTION_EL (OPTION_MD_BASE + 3)
88 const char *md_shortopts
= "VQ:";
90 struct option md_longopts
[] =
92 {"32", no_argument
, NULL
, OPTION_32
},
93 {"64", no_argument
, NULL
, OPTION_64
},
94 {"EB", no_argument
, NULL
, OPTION_EB
},
95 {"EL", no_argument
, NULL
, OPTION_EL
},
96 {NULL
, no_argument
, NULL
, 0}
99 size_t md_longopts_size
= sizeof (md_longopts
);
102 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
106 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
107 should be emitted or not. FIXME: Not implemented. */
111 /* -V: SVR4 argument to print version ID. */
117 tilegx_arch_size
= 32;
121 tilegx_arch_size
= 64;
125 target_big_endian
= 1;
129 target_big_endian
= 0;
140 md_show_usage (FILE *stream
)
142 fprintf (stream
, _("\
144 -V print assembler version number\n\
145 -EB/-EL generate big-endian/little-endian code\n\
146 --32/--64 generate 32bit/64bit code\n"));
150 /* Extra expression types. */
156 #define O_hw0_last O_md5
157 #define O_hw1_last O_md6
158 #define O_hw2_last O_md7
159 #define O_hw0_got O_md8
160 #define O_hw1_got O_md9
161 #define O_hw2_got O_md10
162 #define O_hw3_got O_md11
163 #define O_hw0_last_got O_md12
164 #define O_hw1_last_got O_md13
165 #define O_hw2_last_got O_md14
167 #define O_hw0_tls_gd O_md16
168 #define O_hw1_tls_gd O_md17
169 #define O_hw2_tls_gd O_md18
170 #define O_hw3_tls_gd O_md19
171 #define O_hw0_last_tls_gd O_md20
172 #define O_hw1_last_tls_gd O_md21
173 #define O_hw2_last_tls_gd O_md22
174 #define O_hw0_tls_ie O_md23
175 #define O_hw1_tls_ie O_md24
176 #define O_hw2_tls_ie O_md25
177 #define O_hw3_tls_ie O_md26
178 #define O_hw0_last_tls_ie O_md27
179 #define O_hw1_last_tls_ie O_md28
180 #define O_hw2_last_tls_ie O_md29
182 static struct hash_control
*special_operator_hash
;
184 /* Hash tables for instruction mnemonic lookup. */
185 static struct hash_control
*op_hash
;
187 /* Hash table for spr lookup. */
188 static struct hash_control
*spr_hash
;
190 /* True temporarily while parsing an SPR expression. This changes the
191 * namespace to include SPR names. */
192 static int parsing_spr
;
194 /* Are we currently inside `{ ... }'? */
195 static int inside_bundle
;
197 struct tilegx_instruction
199 const struct tilegx_opcode
*opcode
;
200 tilegx_pipeline pipe
;
201 expressionS operand_values
[TILEGX_MAX_OPERANDS
];
204 /* This keeps track of the current bundle being built up. */
205 static struct tilegx_instruction current_bundle
[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
];
207 /* Index in current_bundle for the next instruction to parse. */
208 static int current_bundle_index
;
210 /* Allow 'r63' in addition to 'zero', etc. Normally we disallow this as
211 'zero' is not a real register, so using it accidentally would be a
212 nasty bug. For other registers, such as 'sp', code using multiple names
213 for the same physical register is excessively confusing.
215 The '.require_canonical_reg_names' pseudo-op turns this error on,
216 and the '.no_require_canonical_reg_names' pseudo-op turns this off.
217 By default the error is on. */
218 static int require_canonical_reg_names
;
220 /* Allow bundles that do undefined or suspicious things like write
221 two different values to the same register at the same time.
223 The '.no_allow_suspicious_bundles' pseudo-op turns this error on,
224 and the '.allow_suspicious_bundles' pseudo-op turns this off. */
225 static int allow_suspicious_bundles
;
228 /* A hash table of main processor registers, mapping each register name
231 Furthermore, if the register number is greater than the number
232 of registers for that processor, the user used an illegal alias
233 for that register (e.g. r63 instead of zero), so we should generate
234 a warning. The attempted register number can be found by clearing
235 NONCANONICAL_REG_NAME_FLAG. */
236 static struct hash_control
*main_reg_hash
;
239 /* We cannot unambiguously store a 0 in a hash table and look it up,
240 so we OR in this flag to every canonical register. */
241 #define CANONICAL_REG_NAME_FLAG 0x1000
243 /* By default we disallow register aliases like r63, but we record
244 them in the hash table in case the .no_require_canonical_reg_names
245 directive is used. Noncanonical names have this value added to them. */
246 #define NONCANONICAL_REG_NAME_FLAG 0x2000
248 /* Discards flags for register hash table entries and returns the
250 #define EXTRACT_REGNO(p) ((p) & 63)
252 /* This function is called once, at assembler startup time. It should
253 set up all the tables, etc., that the MD part of the assembler will
259 const struct tilegx_opcode
*op
;
261 int mach
= (tilegx_arch_size
== 64) ? bfd_mach_tilegx
: bfd_mach_tilegx32
;
263 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_tilegx
, mach
))
264 as_warn (_("Could not set architecture and machine"));
266 /* Guarantee text section is aligned. */
267 bfd_set_section_alignment (stdoutput
, text_section
,
268 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
);
270 require_canonical_reg_names
= 1;
271 allow_suspicious_bundles
= 0;
272 current_bundle_index
= 0;
275 tilegx_cie_data_alignment
= (tilegx_arch_size
== 64 ? -8 : -4);
277 /* Initialize special operator hash table. */
278 special_operator_hash
= hash_new ();
279 #define INSERT_SPECIAL_OP(name) \
280 hash_insert (special_operator_hash, #name, (void *)O_##name)
282 INSERT_SPECIAL_OP (hw0
);
283 INSERT_SPECIAL_OP (hw1
);
284 INSERT_SPECIAL_OP (hw2
);
285 INSERT_SPECIAL_OP (hw3
);
286 INSERT_SPECIAL_OP (hw0_last
);
287 INSERT_SPECIAL_OP (hw1_last
);
288 INSERT_SPECIAL_OP (hw2_last
);
289 /* hw3_last is a convenience alias for the equivalent hw3. */
290 hash_insert (special_operator_hash
, "hw3_last", (void*)O_hw3
);
291 INSERT_SPECIAL_OP (hw0_got
);
292 INSERT_SPECIAL_OP (hw1_got
);
293 INSERT_SPECIAL_OP (hw2_got
);
294 INSERT_SPECIAL_OP (hw3_got
);
295 INSERT_SPECIAL_OP (hw0_last_got
);
296 INSERT_SPECIAL_OP (hw1_last_got
);
297 INSERT_SPECIAL_OP (hw2_last_got
);
298 INSERT_SPECIAL_OP(plt
);
299 INSERT_SPECIAL_OP (hw0_tls_gd
);
300 INSERT_SPECIAL_OP (hw1_tls_gd
);
301 INSERT_SPECIAL_OP (hw2_tls_gd
);
302 INSERT_SPECIAL_OP (hw3_tls_gd
);
303 INSERT_SPECIAL_OP (hw0_last_tls_gd
);
304 INSERT_SPECIAL_OP (hw1_last_tls_gd
);
305 INSERT_SPECIAL_OP (hw2_last_tls_gd
);
306 INSERT_SPECIAL_OP (hw0_tls_ie
);
307 INSERT_SPECIAL_OP (hw1_tls_ie
);
308 INSERT_SPECIAL_OP (hw2_tls_ie
);
309 INSERT_SPECIAL_OP (hw3_tls_ie
);
310 INSERT_SPECIAL_OP (hw0_last_tls_ie
);
311 INSERT_SPECIAL_OP (hw1_last_tls_ie
);
312 INSERT_SPECIAL_OP (hw2_last_tls_ie
);
313 #undef INSERT_SPECIAL_OP
315 /* Initialize op_hash hash table. */
316 op_hash
= hash_new ();
317 for (op
= &tilegx_opcodes
[0]; op
->name
!= NULL
; op
++)
319 const char *hash_err
= hash_insert (op_hash
, op
->name
, (void *)op
);
320 if (hash_err
!= NULL
)
321 as_fatal (_("Internal Error: Can't hash %s: %s"), op
->name
, hash_err
);
324 /* Initialize the spr hash table. */
326 spr_hash
= hash_new ();
327 for (i
= 0; i
< tilegx_num_sprs
; i
++)
328 hash_insert (spr_hash
, tilegx_sprs
[i
].name
,
329 (void *) &tilegx_sprs
[i
]);
331 /* Set up the main_reg_hash table. We use this instead of
332 creating a symbol in the register section to avoid ambiguities
333 with labels that have the same names as registers. */
334 main_reg_hash
= hash_new ();
335 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
339 hash_insert (main_reg_hash
, tilegx_register_names
[i
],
340 (void *) (long) (i
| CANONICAL_REG_NAME_FLAG
));
342 /* See if we should insert a noncanonical alias, like r63. */
343 sprintf (buf
, "r%d", i
);
344 if (strcmp (buf
, tilegx_register_names
[i
]) != 0)
345 hash_insert (main_reg_hash
, xstrdup (buf
),
346 (void *) (long) (i
| NONCANONICAL_REG_NAME_FLAG
));
350 #define BUNDLE_TEMPLATE_MASK(p0, p1, p2) \
351 ((p0) | ((p1) << 8) | ((p2) << 16))
352 #define BUNDLE_TEMPLATE(p0, p1, p2) \
353 { { (p0), (p1), (p2) }, \
354 BUNDLE_TEMPLATE_MASK(1 << (p0), 1 << (p1), (1 << (p2))) \
357 #define NO_PIPELINE TILEGX_NUM_PIPELINE_ENCODINGS
359 struct bundle_template
361 tilegx_pipeline pipe
[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
];
362 unsigned int pipe_mask
;
365 static const struct bundle_template bundle_templates
[] =
367 /* In Y format we must always have something in Y2, since it has
368 no fnop, so this conveys that Y2 must always be used. */
369 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
, TILEGX_PIPELINE_Y2
, NO_PIPELINE
),
370 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
, TILEGX_PIPELINE_Y2
, NO_PIPELINE
),
371 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
, TILEGX_PIPELINE_Y0
, NO_PIPELINE
),
372 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
, TILEGX_PIPELINE_Y1
, NO_PIPELINE
),
374 /* Y format has three instructions. */
375 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y2
),
376 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y1
),
377 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y2
),
378 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y0
),
379 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y1
),
380 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y0
),
382 /* X format has only two instructions. */
383 BUNDLE_TEMPLATE(TILEGX_PIPELINE_X0
, TILEGX_PIPELINE_X1
, NO_PIPELINE
),
384 BUNDLE_TEMPLATE(TILEGX_PIPELINE_X1
, TILEGX_PIPELINE_X0
, NO_PIPELINE
)
389 prepend_nop_to_bundle (tilegx_mnemonic mnemonic
)
391 memmove (¤t_bundle
[1], ¤t_bundle
[0],
392 current_bundle_index
* sizeof current_bundle
[0]);
393 current_bundle
[0].opcode
= &tilegx_opcodes
[mnemonic
];
394 ++current_bundle_index
;
397 static tilegx_bundle_bits
398 insert_operand (tilegx_bundle_bits bits
,
399 const struct tilegx_operand
*operand
,
404 /* Range-check the immediate. */
405 int num_bits
= operand
->num_bits
;
407 operand_value
>>= operand
->rightshift
;
409 if (bfd_check_overflow (operand
->is_signed
410 ? complain_overflow_signed
411 : complain_overflow_unsigned
,
414 bfd_arch_bits_per_address (stdoutput
),
419 if (operand
->is_signed
)
421 min
= -(1 << (num_bits
- 1));
422 max
= (1 << (num_bits
- 1)) - 1;
427 max
= (1 << num_bits
) - 1;
429 as_bad_value_out_of_range (_("operand"), operand_value
, min
, max
,
433 /* Write out the bits for the immediate. */
434 return bits
| operand
->insert (operand_value
);
439 apply_special_operator (operatorT op
, offsetT num
, char *file
, unsigned lineno
)
442 int check_shift
= -1;
446 case O_hw0_last_tls_gd
:
447 case O_hw0_last_tls_ie
:
454 ret
= (signed short)num
;
457 case O_hw1_last_tls_gd
:
458 case O_hw1_last_tls_ie
:
465 ret
= (signed short)(num
>> 16);
468 case O_hw2_last_tls_gd
:
469 case O_hw2_last_tls_ie
:
476 ret
= (signed short)(num
>> 32);
482 ret
= (signed short)(num
>> 48);
490 if (check_shift
>= 0 && ret
!= (num
>> check_shift
))
492 as_bad_value_out_of_range (_("operand"), num
,
493 ~0ULL << (check_shift
+ 16 - 1),
494 ~0ULL >> (64 - (check_shift
+ 16 - 1)),
501 static tilegx_bundle_bits
502 emit_tilegx_instruction (tilegx_bundle_bits bits
,
504 const unsigned char *operands
,
505 expressionS
*operand_values
,
510 for (i
= 0; i
< num_operands
; i
++)
512 const struct tilegx_operand
*operand
=
513 &tilegx_operands
[operands
[i
]];
514 expressionS
*operand_exp
= &operand_values
[i
];
515 int is_pc_relative
= operand
->is_pc_relative
;
517 if (operand_exp
->X_op
== O_register
518 || (operand_exp
->X_op
== O_constant
&& !is_pc_relative
))
520 /* We know what the bits are right now, so insert them. */
521 bits
= insert_operand (bits
, operand
, operand_exp
->X_add_number
,
526 bfd_reloc_code_real_type reloc
= operand
->default_reloc
;
528 int die
= 0, use_subexp
= 0, require_symbol
= 0;
531 /* Take an expression like hw0(x) and turn it into x with
532 a different reloc type. */
533 switch (operand_exp
->X_op
)
535 #define HANDLE_OP16(suffix) \
538 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST: \
539 reloc = BFD_RELOC_TILEGX_IMM16_X0_##suffix; \
541 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST: \
542 reloc = BFD_RELOC_TILEGX_IMM16_X1_##suffix; \
567 HANDLE_OP16 (HW0_LAST
);
571 HANDLE_OP16 (HW1_LAST
);
575 HANDLE_OP16 (HW2_LAST
);
579 HANDLE_OP16 (HW0_GOT
);
584 HANDLE_OP16 (HW1_GOT
);
589 HANDLE_OP16 (HW2_GOT
);
594 HANDLE_OP16 (HW3_GOT
);
599 HANDLE_OP16 (HW0_LAST_GOT
);
604 HANDLE_OP16 (HW1_LAST_GOT
);
609 HANDLE_OP16 (HW2_LAST_GOT
);
614 HANDLE_OP16 (HW0_TLS_GD
);
619 HANDLE_OP16 (HW1_TLS_GD
);
624 HANDLE_OP16 (HW2_TLS_GD
);
629 HANDLE_OP16 (HW3_TLS_GD
);
633 case O_hw0_last_tls_gd
:
634 HANDLE_OP16 (HW0_LAST_TLS_GD
);
638 case O_hw1_last_tls_gd
:
639 HANDLE_OP16 (HW1_LAST_TLS_GD
);
643 case O_hw2_last_tls_gd
:
644 HANDLE_OP16 (HW2_LAST_TLS_GD
);
649 HANDLE_OP16 (HW0_TLS_IE
);
654 HANDLE_OP16 (HW1_TLS_IE
);
659 HANDLE_OP16 (HW2_TLS_IE
);
664 HANDLE_OP16 (HW3_TLS_IE
);
668 case O_hw0_last_tls_ie
:
669 HANDLE_OP16 (HW0_LAST_TLS_IE
);
673 case O_hw1_last_tls_ie
:
674 HANDLE_OP16 (HW1_LAST_TLS_IE
);
678 case O_hw2_last_tls_ie
:
679 HANDLE_OP16 (HW2_LAST_TLS_IE
);
688 case BFD_RELOC_TILEGX_JUMPOFF_X1
:
689 reloc
= BFD_RELOC_TILEGX_JUMPOFF_X1_PLT
;
706 as_bad (_("Invalid operator for operand."));
710 /* Now that we've changed the reloc, change ha16(x) into x,
713 if (operand_exp
->X_add_symbol
->sy_value
.X_md
)
715 /* HACK: We used X_md to mark this symbol as a fake wrapper
716 around a real expression. To unwrap it, we just grab its
718 operand_exp
= &operand_exp
->X_add_symbol
->sy_value
;
722 /* Look at the expression, and reject it if it's not a
724 if (operand_exp
->X_op
!= O_symbol
725 || operand_exp
->X_add_number
!= 0)
726 as_bad (_("Operator may only be applied to symbols."));
731 /* The value of this expression is an actual symbol, so
732 turn that into an expression. */
733 memset (&subexp
, 0, sizeof subexp
);
734 subexp
.X_op
= O_symbol
;
735 subexp
.X_add_symbol
= operand_exp
->X_add_symbol
;
736 operand_exp
= &subexp
;
740 /* Create a fixup to handle this later. */
741 fixP
= fix_new_exp (frag_now
,
742 bundle_start
- frag_now
->fr_literal
,
743 (operand
->num_bits
+ 7) >> 3,
747 fixP
->tc_fix_data
= operand
;
749 /* Don't do overflow checking if we are applying a function like
751 fixP
->fx_no_overflow
|= use_subexp
;
758 /* Detects and complains if two instructions in current_bundle write
759 to the same register, either implicitly or explicitly, or if a
760 read-only register is written. */
762 check_illegal_reg_writes (void)
764 BFD_HOST_U_64_BIT all_regs_written
= 0;
767 for (j
= 0; j
< current_bundle_index
; j
++)
769 const struct tilegx_instruction
*instr
= ¤t_bundle
[j
];
771 BFD_HOST_U_64_BIT regs
=
772 ((BFD_HOST_U_64_BIT
)1) << instr
->opcode
->implicitly_written_register
;
773 BFD_HOST_U_64_BIT conflict
;
775 for (k
= 0; k
< instr
->opcode
->num_operands
; k
++)
777 const struct tilegx_operand
*operand
=
778 &tilegx_operands
[instr
->opcode
->operands
[instr
->pipe
][k
]];
780 if (operand
->is_dest_reg
)
782 int regno
= instr
->operand_values
[k
].X_add_number
;
783 BFD_HOST_U_64_BIT mask
= ((BFD_HOST_U_64_BIT
)1) << regno
;
785 if ((mask
& ( (((BFD_HOST_U_64_BIT
)1) << TREG_IDN1
)
786 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN1
)
787 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN2
)
788 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN3
))) != 0
789 && !allow_suspicious_bundles
)
791 as_bad (_("Writes to register '%s' are not allowed."),
792 tilegx_register_names
[regno
]);
799 /* Writing to the zero register doesn't count. */
800 regs
&= ~(((BFD_HOST_U_64_BIT
)1) << TREG_ZERO
);
802 conflict
= all_regs_written
& regs
;
803 if (conflict
!= 0 && !allow_suspicious_bundles
)
805 /* Find which register caused the conflict. */
806 const char *conflicting_reg_name
= "???";
809 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
811 if (((conflict
>> i
) & 1) != 0)
813 conflicting_reg_name
= tilegx_register_names
[i
];
818 as_bad (_("Two instructions in the same bundle both write "
819 "to register %s, which is not allowed."),
820 conflicting_reg_name
);
823 all_regs_written
|= regs
;
829 tilegx_flush_bundle (void)
834 unsigned compatible_pipes
;
835 const struct bundle_template
*match
;
840 switch (current_bundle_index
)
843 /* No instructions. */
846 if (current_bundle
[0].opcode
->can_bundle
)
848 /* Simplify later logic by adding an explicit fnop. */
849 prepend_nop_to_bundle (TILEGX_OPC_FNOP
);
853 /* This instruction cannot be bundled with anything else.
854 Prepend an explicit 'nop', rather than an 'fnop', because
855 fnops can be replaced by later binary-processing tools while
857 prepend_nop_to_bundle (TILEGX_OPC_NOP
);
861 if (!allow_suspicious_bundles
)
863 /* Make sure all instructions can be bundled with other
865 const struct tilegx_opcode
*cannot_bundle
= NULL
;
866 bfd_boolean seen_non_nop
= FALSE
;
868 for (j
= 0; j
< current_bundle_index
; j
++)
870 const struct tilegx_opcode
*op
= current_bundle
[j
].opcode
;
872 if (!op
->can_bundle
&& cannot_bundle
== NULL
)
874 else if (op
->mnemonic
!= TILEGX_OPC_NOP
875 && op
->mnemonic
!= TILEGX_OPC_INFO
876 && op
->mnemonic
!= TILEGX_OPC_INFOL
)
880 if (cannot_bundle
!= NULL
&& seen_non_nop
)
882 current_bundle_index
= 0;
883 as_bad (_("'%s' may not be bundled with other instructions."),
884 cannot_bundle
->name
);
892 BUNDLE_TEMPLATE_MASK(current_bundle
[0].opcode
->pipes
,
893 current_bundle
[1].opcode
->pipes
,
894 (current_bundle_index
== 3
895 ? current_bundle
[2].opcode
->pipes
896 : (1 << NO_PIPELINE
)));
898 /* Find a template that works, if any. */
900 for (i
= 0; i
< sizeof bundle_templates
/ sizeof bundle_templates
[0]; i
++)
902 const struct bundle_template
*b
= &bundle_templates
[i
];
903 if ((b
->pipe_mask
& compatible_pipes
) == b
->pipe_mask
)
912 current_bundle_index
= 0;
913 as_bad (_("Invalid combination of instructions for bundle."));
917 /* If the section seems to have no alignment set yet, go ahead and
918 make it large enough to hold code. */
919 if (bfd_get_section_alignment (stdoutput
, now_seg
) == 0)
920 bfd_set_section_alignment (stdoutput
, now_seg
,
921 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
);
923 for (j
= 0; j
< current_bundle_index
; j
++)
924 current_bundle
[j
].pipe
= match
->pipe
[j
];
926 if (current_bundle_index
== 2 && !tilegx_is_x_pipeline (match
->pipe
[0]))
928 /* We are in Y mode with only two instructions, so add an FNOP. */
929 prepend_nop_to_bundle (TILEGX_OPC_FNOP
);
931 /* Figure out what pipe the fnop must be in via arithmetic.
932 * p0 + p1 + p2 must sum to the sum of TILEGX_PIPELINE_Y[012]. */
933 current_bundle
[0].pipe
=
934 (tilegx_pipeline
)((TILEGX_PIPELINE_Y0
936 + TILEGX_PIPELINE_Y2
) -
937 (current_bundle
[1].pipe
+ current_bundle
[2].pipe
));
940 check_illegal_reg_writes ();
942 f
= frag_more (TILEGX_BUNDLE_SIZE_IN_BYTES
);
944 /* Check to see if this bundle is at an offset that is a multiple of 8-bytes
945 from the start of the frag. */
946 addr_mod
= frag_now_fix () & (TILEGX_BUNDLE_ALIGNMENT_IN_BYTES
- 1);
947 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
948 as_bad (_("instruction address is not a multiple of 8"));
949 frag_now
->insn_addr
= addr_mod
;
950 frag_now
->has_code
= 1;
952 tilegx_bundle_bits bits
= 0;
953 for (j
= 0; j
< current_bundle_index
; j
++)
955 struct tilegx_instruction
*instr
= ¤t_bundle
[j
];
956 tilegx_pipeline pipeline
= instr
->pipe
;
957 const struct tilegx_opcode
*opcode
= instr
->opcode
;
959 bits
|= emit_tilegx_instruction (opcode
->fixed_bit_values
[pipeline
],
960 opcode
->num_operands
,
961 &opcode
->operands
[pipeline
][0],
962 instr
->operand_values
,
966 number_to_chars_littleendian (f
, bits
, 8);
967 current_bundle_index
= 0;
969 /* Emit DWARF2 debugging information. */
970 dwarf2_emit_insn (TILEGX_BUNDLE_SIZE_IN_BYTES
);
974 /* Extend the expression parser to handle hw0(label), etc.
975 as well as SPR names when in the context of parsing an SPR. */
978 tilegx_parse_name (char *name
, expressionS
*e
, char *nextcharP
)
980 operatorT op
= O_illegal
;
984 void* val
= hash_find (spr_hash
, name
);
988 memset (e
, 0, sizeof *e
);
989 e
->X_op
= O_constant
;
990 e
->X_add_number
= ((const struct tilegx_spr
*)val
)->number
;
994 if (*nextcharP
!= '(')
996 /* hw0, etc. not followed by a paren is just a label with that name. */
1001 /* Look up the operator in our table. */
1002 void* val
= hash_find (special_operator_hash
, name
);
1005 op
= (operatorT
)(long)val
;
1008 /* Restore old '(' and skip it. */
1009 *input_line_pointer
= '(';
1010 ++input_line_pointer
;
1014 if (*input_line_pointer
!= ')')
1016 as_bad (_("Missing ')'"));
1017 *nextcharP
= *input_line_pointer
;
1021 ++input_line_pointer
;
1023 if (e
->X_op
== O_register
|| e
->X_op
== O_absent
)
1025 as_bad (_("Invalid expression."));
1026 e
->X_op
= O_constant
;
1027 e
->X_add_number
= 0;
1031 /* Wrap subexpression with a unary operator. */
1032 symbolS
*sym
= make_expr_symbol (e
);
1034 if (sym
!= e
->X_add_symbol
)
1036 /* HACK: mark this symbol as a temporary wrapper around a proper
1037 expression, so we can unwrap it later once we have communicated
1038 the relocation type. */
1039 sym
->sy_value
.X_md
= 1;
1042 memset (e
, 0, sizeof *e
);
1044 e
->X_add_symbol
= sym
;
1045 e
->X_add_number
= 0;
1048 *nextcharP
= *input_line_pointer
;
1053 /* Parses an expression which must be a register name. */
1056 parse_reg_expression (expressionS
* expression
)
1058 /* Zero everything to make sure we don't miss any flags. */
1059 memset (expression
, 0, sizeof *expression
);
1061 char* regname
= input_line_pointer
;
1062 char terminating_char
= get_symbol_end ();
1064 void* pval
= hash_find (main_reg_hash
, regname
);
1068 as_bad (_("Expected register, got '%s'."), regname
);
1071 int regno_and_flags
= (int)(size_t)pval
;
1072 int regno
= EXTRACT_REGNO(regno_and_flags
);
1074 if ((regno_and_flags
& NONCANONICAL_REG_NAME_FLAG
)
1075 && require_canonical_reg_names
)
1077 as_warn (_("Found use of non-canonical register name %s; "
1080 tilegx_register_names
[regno
]);
1083 /* Restore the old character following the register name. */
1084 *input_line_pointer
= terminating_char
;
1086 /* Fill in the expression fields to indicate it's a register. */
1087 expression
->X_op
= O_register
;
1088 expression
->X_add_number
= regno
;
1092 /* Parses and type-checks comma-separated operands in input_line_pointer. */
1095 parse_operands (const char *opcode_name
,
1096 const unsigned char *operands
,
1098 expressionS
*operand_values
)
1102 memset (operand_values
, 0, num_operands
* sizeof operand_values
[0]);
1105 for (i
= 0; i
< num_operands
; i
++)
1107 tilegx_operand_type type
= tilegx_operands
[operands
[i
]].type
;
1111 if (type
== TILEGX_OP_TYPE_REGISTER
)
1113 parse_reg_expression (&operand_values
[i
]);
1115 else if (*input_line_pointer
== '}')
1117 operand_values
[i
].X_op
= O_absent
;
1119 else if (type
== TILEGX_OP_TYPE_SPR
)
1121 /* Modify the expression parser to add SPRs to the namespace. */
1123 expression (&operand_values
[i
]);
1128 expression (&operand_values
[i
]);
1133 if (i
+ 1 < num_operands
)
1135 int separator
= (unsigned char)*input_line_pointer
++;
1137 if (is_end_of_line
[separator
] || (separator
== '}'))
1139 as_bad (_("Too few operands to '%s'."), opcode_name
);
1142 else if (separator
!= ',')
1144 as_bad (_("Unexpected character '%c' after operand %d to %s."),
1145 (char)separator
, i
+ 1, opcode_name
);
1150 /* Arbitrarily use the first valid pipe to get the operand type,
1151 since they are all the same. */
1152 switch (tilegx_operands
[operands
[i
]].type
)
1154 case TILEGX_OP_TYPE_REGISTER
:
1155 /* Handled in parse_reg_expression already. */
1157 case TILEGX_OP_TYPE_SPR
:
1159 case TILEGX_OP_TYPE_IMMEDIATE
:
1161 case TILEGX_OP_TYPE_ADDRESS
:
1162 if ( operand_values
[i
].X_op
== O_register
1163 || operand_values
[i
].X_op
== O_illegal
1164 || operand_values
[i
].X_op
== O_absent
)
1165 as_bad (_("Expected immediate expression"));
1172 if (!is_end_of_line
[(unsigned char)*input_line_pointer
])
1174 switch (*input_line_pointer
)
1178 as_bad (_("Found '}' when not bundling."));
1179 ++input_line_pointer
;
1181 demand_empty_rest_of_line ();
1185 as_bad (_("Too many operands"));
1189 /* Use default error for unrecognized garbage. */
1190 demand_empty_rest_of_line ();
1197 /* This is the guts of the machine-dependent assembler. STR points to a
1198 machine dependent instruction. This function is supposed to emit the
1199 frags/bytes it assembles to. */
1202 md_assemble (char *str
)
1206 char *old_input_line_pointer
;
1207 const struct tilegx_opcode
*op
;
1210 /* Split off the opcode and look it up. */
1211 opname_len
= strcspn (str
, " {}");
1212 old_char
= str
[opname_len
];
1213 str
[opname_len
] = '\0';
1215 op
= hash_find(op_hash
, str
);
1216 str
[opname_len
] = old_char
;
1219 as_bad (_("Unknown opcode `%.*s'."), (int)opname_len
, str
);
1223 /* Prepare to parse the operands. */
1224 old_input_line_pointer
= input_line_pointer
;
1225 input_line_pointer
= str
+ opname_len
;
1228 if (current_bundle_index
== TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
)
1230 as_bad (_("Too many instructions for bundle."));
1231 tilegx_flush_bundle ();
1234 /* Make sure we have room for the upcoming bundle before we
1235 create any fixups. Otherwise if we have to switch to a new
1236 frag the fixup dot_value fields will be wrong. */
1237 frag_grow (TILEGX_BUNDLE_SIZE_IN_BYTES
);
1239 /* Find a valid pipe for this opcode. */
1240 for (first_pipe
= 0; (op
->pipes
& (1 << first_pipe
)) == 0; first_pipe
++)
1243 /* Call the function that assembles this instruction. */
1244 current_bundle
[current_bundle_index
].opcode
= op
;
1245 parse_operands (op
->name
,
1246 &op
->operands
[first_pipe
][0],
1248 current_bundle
[current_bundle_index
].operand_values
);
1249 ++current_bundle_index
;
1251 /* Restore the saved value of input_line_pointer. */
1252 input_line_pointer
= old_input_line_pointer
;
1254 /* If we weren't inside curly braces, go ahead and emit
1255 this lone instruction as a bundle right now. */
1257 tilegx_flush_bundle ();
1262 s_require_canonical_reg_names (int require
)
1264 demand_empty_rest_of_line ();
1265 require_canonical_reg_names
= require
;
1269 s_allow_suspicious_bundles (int allow
)
1271 demand_empty_rest_of_line ();
1272 allow_suspicious_bundles
= allow
;
1275 const pseudo_typeS md_pseudo_table
[] =
1277 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0). */
1279 {"require_canonical_reg_names", s_require_canonical_reg_names
, 1 },
1280 {"no_require_canonical_reg_names", s_require_canonical_reg_names
, 0 },
1281 {"allow_suspicious_bundles", s_allow_suspicious_bundles
, 1 },
1282 {"no_allow_suspicious_bundles", s_allow_suspicious_bundles
, 0 },
1286 /* Equal to MAX_PRECISION in atof-ieee.c */
1287 #define MAX_LITTLENUMS 6
1290 md_number_to_chars (char * buf
, valueT val
, int n
)
1292 if (target_big_endian
)
1293 number_to_chars_bigendian (buf
, val
, n
);
1295 number_to_chars_littleendian (buf
, val
, n
);
1298 /* Turn the string pointed to by litP into a floating point constant
1299 of type TYPE, and emit the appropriate bytes. The number of
1300 LITTLENUMS emitted is stored in *SIZEP. An error message is
1301 returned, or NULL on OK. */
1304 md_atof (int type
, char *litP
, int *sizeP
)
1307 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1308 LITTLENUM_TYPE
*wordP
;
1325 return _("Bad call to md_atof ()");
1327 t
= atof_ieee (input_line_pointer
, type
, words
);
1329 input_line_pointer
= t
;
1331 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1332 /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
1333 the bigendian 386. */
1334 for (wordP
= words
+ prec
- 1; prec
--;)
1336 md_number_to_chars (litP
, (valueT
) (*wordP
--), sizeof (LITTLENUM_TYPE
));
1337 litP
+= sizeof (LITTLENUM_TYPE
);
1343 /* We have no need to default values of symbols. */
1346 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1353 tilegx_cons_fix_new (fragS
*frag
,
1359 bfd_reloc_code_real_type reloc
= BFD_RELOC_NONE
;
1360 int no_overflow
= 0;
1363 /* See if it's one of our special functions. */
1367 reloc
= BFD_RELOC_TILEGX_HW0
;
1371 reloc
= BFD_RELOC_TILEGX_HW1
;
1375 reloc
= BFD_RELOC_TILEGX_HW2
;
1379 reloc
= BFD_RELOC_TILEGX_HW3
;
1383 reloc
= BFD_RELOC_TILEGX_HW0_LAST
;
1386 reloc
= BFD_RELOC_TILEGX_HW1_LAST
;
1389 reloc
= BFD_RELOC_TILEGX_HW2_LAST
;
1397 if (reloc
!= BFD_RELOC_NONE
)
1401 as_bad (_("This operator only produces two byte values."));
1405 memset (&subexp
, 0, sizeof subexp
);
1406 subexp
.X_op
= O_symbol
;
1407 subexp
.X_add_symbol
= exp
->X_add_symbol
;
1415 reloc
= BFD_RELOC_8
;
1418 reloc
= BFD_RELOC_16
;
1421 reloc
= BFD_RELOC_32
;
1424 reloc
= BFD_RELOC_64
;
1427 as_bad (_("unsupported BFD relocation size %d"), nbytes
);
1428 reloc
= BFD_RELOC_64
;
1433 fixP
= fix_new_exp (frag
, where
, nbytes
, exp
, 0, reloc
);
1434 fixP
->tc_fix_data
= NULL
;
1435 fixP
->fx_no_overflow
|= no_overflow
;
1440 md_apply_fix (fixS
*fixP
, valueT
* valP
, segT seg ATTRIBUTE_UNUSED
)
1442 const struct tilegx_operand
*operand
;
1443 valueT value
= *valP
;
1447 /* Leave these for the linker. */
1448 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1449 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1452 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
1454 /* We can't actually support subtracting a symbol. */
1455 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
1458 /* Correct relocation types for pc-relativeness. */
1459 switch (fixP
->fx_r_type
)
1461 #define FIX_PCREL(rtype) \
1463 if (fixP->fx_pcrel) \
1464 fixP->fx_r_type = rtype##_PCREL; \
1467 case rtype##_PCREL: \
1468 if (!fixP->fx_pcrel) \
1469 fixP->fx_r_type = rtype; \
1472 FIX_PCREL (BFD_RELOC_8
);
1473 FIX_PCREL (BFD_RELOC_16
);
1474 FIX_PCREL (BFD_RELOC_32
);
1475 FIX_PCREL (BFD_RELOC_64
);
1476 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0
);
1477 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0
);
1478 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1
);
1479 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1
);
1480 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2
);
1481 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2
);
1482 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW3
);
1483 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW3
);
1484 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST
);
1485 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST
);
1486 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST
);
1487 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST
);
1488 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST
);
1489 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST
);
1498 if (fixP
->fx_addsy
!= NULL
)
1501 switch (fixP
->fx_r_type
)
1503 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD
:
1504 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD
:
1505 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE
:
1506 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE
:
1507 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
1508 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
1509 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
1510 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
1511 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_GD
:
1512 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_GD
:
1513 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_IE
:
1514 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_IE
:
1515 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
1516 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
1517 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
1518 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
1519 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_GD
:
1520 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_GD
:
1521 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_IE
:
1522 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_IE
:
1523 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
1524 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
1525 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
1526 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
1527 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_GD
:
1528 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_GD
:
1529 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_IE
:
1530 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_IE
:
1531 case BFD_RELOC_TILEGX_TLS_DTPMOD64
:
1532 case BFD_RELOC_TILEGX_TLS_DTPOFF64
:
1533 case BFD_RELOC_TILEGX_TLS_TPOFF64
:
1534 case BFD_RELOC_TILEGX_TLS_DTPMOD32
:
1535 case BFD_RELOC_TILEGX_TLS_DTPOFF32
:
1536 case BFD_RELOC_TILEGX_TLS_TPOFF32
:
1537 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
1548 /* Apply hw0, etc. */
1549 special
= O_illegal
;
1550 switch (fixP
->fx_r_type
)
1552 case BFD_RELOC_TILEGX_HW0
:
1553 case BFD_RELOC_TILEGX_IMM16_X0_HW0
:
1554 case BFD_RELOC_TILEGX_IMM16_X1_HW0
:
1555 case BFD_RELOC_TILEGX_IMM16_X0_HW0_PCREL
:
1556 case BFD_RELOC_TILEGX_IMM16_X1_HW0_PCREL
:
1557 case BFD_RELOC_TILEGX_IMM16_X0_HW0_GOT
:
1558 case BFD_RELOC_TILEGX_IMM16_X1_HW0_GOT
:
1559 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD
:
1560 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD
:
1561 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE
:
1562 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE
:
1566 case BFD_RELOC_TILEGX_HW0_LAST
:
1567 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST
:
1568 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST
:
1569 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
1570 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
1571 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_GOT
:
1572 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_GOT
:
1573 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
1574 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
1575 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
1576 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
1577 special
= O_hw0_last
;
1580 case BFD_RELOC_TILEGX_HW1
:
1581 case BFD_RELOC_TILEGX_IMM16_X0_HW1
:
1582 case BFD_RELOC_TILEGX_IMM16_X1_HW1
:
1583 case BFD_RELOC_TILEGX_IMM16_X0_HW1_PCREL
:
1584 case BFD_RELOC_TILEGX_IMM16_X1_HW1_PCREL
:
1585 case BFD_RELOC_TILEGX_IMM16_X0_HW1_GOT
:
1586 case BFD_RELOC_TILEGX_IMM16_X1_HW1_GOT
:
1587 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_GD
:
1588 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_GD
:
1589 case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_IE
:
1590 case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_IE
:
1594 case BFD_RELOC_TILEGX_HW1_LAST
:
1595 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST
:
1596 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST
:
1597 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
1598 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
1599 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_GOT
:
1600 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_GOT
:
1601 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
1602 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
1603 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
1604 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
1605 special
= O_hw1_last
;
1608 case BFD_RELOC_TILEGX_HW2
:
1609 case BFD_RELOC_TILEGX_IMM16_X0_HW2
:
1610 case BFD_RELOC_TILEGX_IMM16_X1_HW2
:
1611 case BFD_RELOC_TILEGX_IMM16_X0_HW2_PCREL
:
1612 case BFD_RELOC_TILEGX_IMM16_X1_HW2_PCREL
:
1613 case BFD_RELOC_TILEGX_IMM16_X0_HW2_GOT
:
1614 case BFD_RELOC_TILEGX_IMM16_X1_HW2_GOT
:
1615 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_GD
:
1616 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_GD
:
1617 case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_IE
:
1618 case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_IE
:
1622 case BFD_RELOC_TILEGX_HW2_LAST
:
1623 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST
:
1624 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST
:
1625 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
1626 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
1627 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_GOT
:
1628 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_GOT
:
1629 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_GD
:
1630 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_GD
:
1631 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_IE
:
1632 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_IE
:
1633 special
= O_hw2_last
;
1636 case BFD_RELOC_TILEGX_HW3
:
1637 case BFD_RELOC_TILEGX_IMM16_X0_HW3
:
1638 case BFD_RELOC_TILEGX_IMM16_X1_HW3
:
1639 case BFD_RELOC_TILEGX_IMM16_X0_HW3_PCREL
:
1640 case BFD_RELOC_TILEGX_IMM16_X1_HW3_PCREL
:
1641 case BFD_RELOC_TILEGX_IMM16_X0_HW3_GOT
:
1642 case BFD_RELOC_TILEGX_IMM16_X1_HW3_GOT
:
1643 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_GD
:
1644 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_GD
:
1645 case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_IE
:
1646 case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_IE
:
1655 if (special
!= O_illegal
)
1657 *valP
= value
= apply_special_operator (special
, value
,
1658 fixP
->fx_file
, fixP
->fx_line
);
1661 p
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1663 operand
= fixP
->tc_fix_data
;
1664 if (operand
!= NULL
)
1666 /* It's an instruction operand. */
1667 tilegx_bundle_bits bits
=
1668 insert_operand (0, operand
, value
, fixP
->fx_file
, fixP
->fx_line
);
1670 /* Note that we might either be writing out bits for a bundle
1671 or a static network instruction, which are different sizes, so it's
1672 important to stop touching memory once we run out of bits.
1673 ORing in values is OK since we know the existing bits for
1674 this operand are zero. */
1675 for (; bits
!= 0; bits
>>= 8)
1680 /* Some other kind of relocation. */
1681 switch (fixP
->fx_r_type
)
1684 case BFD_RELOC_8_PCREL
:
1685 md_number_to_chars (p
, value
, 1);
1689 case BFD_RELOC_16_PCREL
:
1690 md_number_to_chars (p
, value
, 2);
1694 case BFD_RELOC_32_PCREL
:
1695 md_number_to_chars (p
, value
, 4);
1699 case BFD_RELOC_64_PCREL
:
1700 md_number_to_chars (p
, value
, 8);
1704 /* Leave it for the linker. */
1713 /* Generate the BFD reloc to be stuck in the object file from the
1714 fixup used internally in the assembler. */
1717 tc_gen_reloc (asection
*sec ATTRIBUTE_UNUSED
, fixS
*fixp
)
1721 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1722 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1723 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1724 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1726 /* Make sure none of our internal relocations make it this far.
1727 They'd better have been fully resolved by this point. */
1728 gas_assert ((int) fixp
->fx_r_type
> 0);
1730 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1731 if (reloc
->howto
== NULL
)
1733 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1734 _("cannot represent `%s' relocation in object file"),
1735 bfd_get_reloc_code_name (fixp
->fx_r_type
));
1739 if (!fixp
->fx_pcrel
!= !reloc
->howto
->pc_relative
)
1741 as_fatal (_("internal error? cannot generate `%s' relocation (%d, %d)"),
1742 bfd_get_reloc_code_name (fixp
->fx_r_type
),
1743 fixp
->fx_pcrel
, reloc
->howto
->pc_relative
);
1745 gas_assert (!fixp
->fx_pcrel
== !reloc
->howto
->pc_relative
);
1747 reloc
->addend
= fixp
->fx_offset
;
1753 /* The location from which a PC relative jump should be calculated,
1754 given a PC relative reloc. */
1757 md_pcrel_from (fixS
*fixP
)
1759 return fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1763 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
1764 a section symbol plus some offset. */
1766 tilegx_fix_adjustable (fixS
*fix
)
1768 /* Prevent all adjustments to global symbols */
1769 if (S_IS_EXTERNAL (fix
->fx_addsy
) || S_IS_WEAK (fix
->fx_addsy
))
1777 tilegx_unrecognized_line (int ch
)
1784 as_bad (_("Found '{' when already bundling."));
1789 current_bundle_index
= 0;
1796 as_bad (_("Found '}' when not bundling."));
1800 tilegx_flush_bundle ();
1803 /* Allow '{' to follow on the same line. We also allow ";;", but that
1804 happens automatically because ';' is an end of line marker. */
1806 if (input_line_pointer
[0] == '{')
1808 input_line_pointer
++;
1809 return tilegx_unrecognized_line ('{');
1812 demand_empty_rest_of_line ();
1819 /* Not a valid line. */
1824 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
1825 of an rs_align_code fragment. */
1828 tilegx_handle_align (fragS
*fragp
)
1830 addressT bytes
, fix
;
1833 if (fragp
->fr_type
!= rs_align_code
)
1836 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
1837 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
1840 /* Determine the bits for NOP. */
1841 const struct tilegx_opcode
*nop_opcode
=
1842 &tilegx_opcodes
[TILEGX_OPC_NOP
];
1843 tilegx_bundle_bits nop
=
1844 ( nop_opcode
->fixed_bit_values
[TILEGX_PIPELINE_X0
]
1845 | nop_opcode
->fixed_bit_values
[TILEGX_PIPELINE_X1
]);
1847 if ((bytes
& (TILEGX_BUNDLE_SIZE_IN_BYTES
- 1)) != 0)
1849 fix
= bytes
& (TILEGX_BUNDLE_SIZE_IN_BYTES
- 1);
1855 number_to_chars_littleendian (p
, nop
, 8);
1856 fragp
->fr_fix
+= fix
;
1857 fragp
->fr_var
= TILEGX_BUNDLE_SIZE_IN_BYTES
;
1860 /* Standard calling conventions leave the CFA at SP on entry. */
1862 tilegx_cfi_frame_initial_instructions (void)
1864 cfi_add_CFA_def_cfa_register (54);
1868 tc_tilegx_regname_to_dw2regnum (char *regname
)
1871 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
1873 if (!strcmp (regname
, tilegx_register_names
[i
]))