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_hw0_last_got O_md9
161 #define O_hw1_last_got O_md10
163 #define O_hw0_tls_gd O_md12
164 #define O_hw0_last_tls_gd O_md13
165 #define O_hw1_last_tls_gd O_md14
166 #define O_hw0_tls_ie O_md15
167 #define O_hw0_last_tls_ie O_md16
168 #define O_hw1_last_tls_ie O_md17
169 #define O_hw0_tls_le O_md18
170 #define O_hw0_last_tls_le O_md19
171 #define O_hw1_last_tls_le O_md20
172 #define O_tls_gd_call O_md21
173 #define O_tls_gd_add O_md22
174 #define O_tls_ie_load O_md23
175 #define O_tls_add O_md24
177 static struct hash_control
*special_operator_hash
;
179 /* Hash tables for instruction mnemonic lookup. */
180 static struct hash_control
*op_hash
;
182 /* Hash table for spr lookup. */
183 static struct hash_control
*spr_hash
;
185 /* True temporarily while parsing an SPR expression. This changes the
186 * namespace to include SPR names. */
187 static int parsing_spr
;
189 /* Are we currently inside `{ ... }'? */
190 static int inside_bundle
;
192 struct tilegx_instruction
194 const struct tilegx_opcode
*opcode
;
195 tilegx_pipeline pipe
;
196 expressionS operand_values
[TILEGX_MAX_OPERANDS
];
199 /* This keeps track of the current bundle being built up. */
200 static struct tilegx_instruction current_bundle
[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
];
202 /* Index in current_bundle for the next instruction to parse. */
203 static int current_bundle_index
;
205 /* Allow 'r63' in addition to 'zero', etc. Normally we disallow this as
206 'zero' is not a real register, so using it accidentally would be a
207 nasty bug. For other registers, such as 'sp', code using multiple names
208 for the same physical register is excessively confusing.
210 The '.require_canonical_reg_names' pseudo-op turns this error on,
211 and the '.no_require_canonical_reg_names' pseudo-op turns this off.
212 By default the error is on. */
213 static int require_canonical_reg_names
;
215 /* Allow bundles that do undefined or suspicious things like write
216 two different values to the same register at the same time.
218 The '.no_allow_suspicious_bundles' pseudo-op turns this error on,
219 and the '.allow_suspicious_bundles' pseudo-op turns this off. */
220 static int allow_suspicious_bundles
;
223 /* A hash table of main processor registers, mapping each register name
226 Furthermore, if the register number is greater than the number
227 of registers for that processor, the user used an illegal alias
228 for that register (e.g. r63 instead of zero), so we should generate
229 a warning. The attempted register number can be found by clearing
230 NONCANONICAL_REG_NAME_FLAG. */
231 static struct hash_control
*main_reg_hash
;
234 /* We cannot unambiguously store a 0 in a hash table and look it up,
235 so we OR in this flag to every canonical register. */
236 #define CANONICAL_REG_NAME_FLAG 0x1000
238 /* By default we disallow register aliases like r63, but we record
239 them in the hash table in case the .no_require_canonical_reg_names
240 directive is used. Noncanonical names have this value added to them. */
241 #define NONCANONICAL_REG_NAME_FLAG 0x2000
243 /* Discards flags for register hash table entries and returns the
245 #define EXTRACT_REGNO(p) ((p) & 63)
247 /* This function is called once, at assembler startup time. It should
248 set up all the tables, etc., that the MD part of the assembler will
254 const struct tilegx_opcode
*op
;
256 int mach
= (tilegx_arch_size
== 64) ? bfd_mach_tilegx
: bfd_mach_tilegx32
;
258 if (! bfd_set_arch_mach (stdoutput
, bfd_arch_tilegx
, mach
))
259 as_warn (_("Could not set architecture and machine"));
261 /* Guarantee text section is aligned. */
262 bfd_set_section_alignment (stdoutput
, text_section
,
263 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
);
265 require_canonical_reg_names
= 1;
266 allow_suspicious_bundles
= 0;
267 current_bundle_index
= 0;
270 tilegx_cie_data_alignment
= (tilegx_arch_size
== 64 ? -8 : -4);
272 /* Initialize special operator hash table. */
273 special_operator_hash
= hash_new ();
274 #define INSERT_SPECIAL_OP(name) \
275 hash_insert (special_operator_hash, #name, (void *)O_##name)
277 INSERT_SPECIAL_OP (hw0
);
278 INSERT_SPECIAL_OP (hw1
);
279 INSERT_SPECIAL_OP (hw2
);
280 INSERT_SPECIAL_OP (hw3
);
281 INSERT_SPECIAL_OP (hw0_last
);
282 INSERT_SPECIAL_OP (hw1_last
);
283 INSERT_SPECIAL_OP (hw2_last
);
284 /* hw3_last is a convenience alias for the equivalent hw3. */
285 hash_insert (special_operator_hash
, "hw3_last", (void*)O_hw3
);
286 INSERT_SPECIAL_OP (hw0_got
);
287 INSERT_SPECIAL_OP (hw0_last_got
);
288 INSERT_SPECIAL_OP (hw1_last_got
);
289 INSERT_SPECIAL_OP(plt
);
290 INSERT_SPECIAL_OP (hw0_tls_gd
);
291 INSERT_SPECIAL_OP (hw0_last_tls_gd
);
292 INSERT_SPECIAL_OP (hw1_last_tls_gd
);
293 INSERT_SPECIAL_OP (hw0_tls_ie
);
294 INSERT_SPECIAL_OP (hw0_last_tls_ie
);
295 INSERT_SPECIAL_OP (hw1_last_tls_ie
);
296 INSERT_SPECIAL_OP (hw0_tls_le
);
297 INSERT_SPECIAL_OP (hw0_last_tls_le
);
298 INSERT_SPECIAL_OP (hw1_last_tls_le
);
299 INSERT_SPECIAL_OP (tls_gd_call
);
300 INSERT_SPECIAL_OP (tls_gd_add
);
301 INSERT_SPECIAL_OP (tls_ie_load
);
302 INSERT_SPECIAL_OP (tls_add
);
303 #undef INSERT_SPECIAL_OP
305 /* Initialize op_hash hash table. */
306 op_hash
= hash_new ();
307 for (op
= &tilegx_opcodes
[0]; op
->name
!= NULL
; op
++)
309 const char *hash_err
= hash_insert (op_hash
, op
->name
, (void *)op
);
310 if (hash_err
!= NULL
)
311 as_fatal (_("Internal Error: Can't hash %s: %s"), op
->name
, hash_err
);
314 /* Initialize the spr hash table. */
316 spr_hash
= hash_new ();
317 for (i
= 0; i
< tilegx_num_sprs
; i
++)
318 hash_insert (spr_hash
, tilegx_sprs
[i
].name
,
319 (void *) &tilegx_sprs
[i
]);
321 /* Set up the main_reg_hash table. We use this instead of
322 creating a symbol in the register section to avoid ambiguities
323 with labels that have the same names as registers. */
324 main_reg_hash
= hash_new ();
325 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
329 hash_insert (main_reg_hash
, tilegx_register_names
[i
],
330 (void *) (long) (i
| CANONICAL_REG_NAME_FLAG
));
332 /* See if we should insert a noncanonical alias, like r63. */
333 sprintf (buf
, "r%d", i
);
334 if (strcmp (buf
, tilegx_register_names
[i
]) != 0)
335 hash_insert (main_reg_hash
, xstrdup (buf
),
336 (void *) (long) (i
| NONCANONICAL_REG_NAME_FLAG
));
340 #define BUNDLE_TEMPLATE_MASK(p0, p1, p2) \
341 ((p0) | ((p1) << 8) | ((p2) << 16))
342 #define BUNDLE_TEMPLATE(p0, p1, p2) \
343 { { (p0), (p1), (p2) }, \
344 BUNDLE_TEMPLATE_MASK(1 << (p0), 1 << (p1), (1 << (p2))) \
347 #define NO_PIPELINE TILEGX_NUM_PIPELINE_ENCODINGS
349 struct bundle_template
351 tilegx_pipeline pipe
[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
];
352 unsigned int pipe_mask
;
355 static const struct bundle_template bundle_templates
[] =
357 /* In Y format we must always have something in Y2, since it has
358 no fnop, so this conveys that Y2 must always be used. */
359 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
, TILEGX_PIPELINE_Y2
, NO_PIPELINE
),
360 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
, TILEGX_PIPELINE_Y2
, NO_PIPELINE
),
361 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
, TILEGX_PIPELINE_Y0
, NO_PIPELINE
),
362 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
, TILEGX_PIPELINE_Y1
, NO_PIPELINE
),
364 /* Y format has three instructions. */
365 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y2
),
366 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y1
),
367 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y2
),
368 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y0
),
369 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y0
,TILEGX_PIPELINE_Y1
),
370 BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2
,TILEGX_PIPELINE_Y1
,TILEGX_PIPELINE_Y0
),
372 /* X format has only two instructions. */
373 BUNDLE_TEMPLATE(TILEGX_PIPELINE_X0
, TILEGX_PIPELINE_X1
, NO_PIPELINE
),
374 BUNDLE_TEMPLATE(TILEGX_PIPELINE_X1
, TILEGX_PIPELINE_X0
, NO_PIPELINE
)
379 prepend_nop_to_bundle (tilegx_mnemonic mnemonic
)
381 memmove (¤t_bundle
[1], ¤t_bundle
[0],
382 current_bundle_index
* sizeof current_bundle
[0]);
383 current_bundle
[0].opcode
= &tilegx_opcodes
[mnemonic
];
384 ++current_bundle_index
;
387 static tilegx_bundle_bits
388 insert_operand (tilegx_bundle_bits bits
,
389 const struct tilegx_operand
*operand
,
394 /* Range-check the immediate. */
395 int num_bits
= operand
->num_bits
;
397 operand_value
>>= operand
->rightshift
;
399 if (bfd_check_overflow (operand
->is_signed
400 ? complain_overflow_signed
401 : complain_overflow_unsigned
,
404 bfd_arch_bits_per_address (stdoutput
),
409 if (operand
->is_signed
)
411 min
= -(1 << (num_bits
- 1));
412 max
= (1 << (num_bits
- 1)) - 1;
417 max
= (1 << num_bits
) - 1;
419 as_bad_value_out_of_range (_("operand"), operand_value
, min
, max
,
423 /* Write out the bits for the immediate. */
424 return bits
| operand
->insert (operand_value
);
429 apply_special_operator (operatorT op
, offsetT num
, char *file
, unsigned lineno
)
432 int check_shift
= -1;
440 ret
= (signed short)num
;
447 ret
= (signed short)(num
>> 16);
454 ret
= (signed short)(num
>> 32);
458 ret
= (signed short)(num
>> 48);
466 if (check_shift
>= 0 && ret
!= (num
>> check_shift
))
468 as_bad_value_out_of_range (_("operand"), num
,
469 ~0ULL << (check_shift
+ 16 - 1),
470 ~0ULL >> (64 - (check_shift
+ 16 - 1)),
477 static tilegx_bundle_bits
478 emit_tilegx_instruction (tilegx_bundle_bits bits
,
480 const unsigned char *operands
,
481 expressionS
*operand_values
,
486 for (i
= 0; i
< num_operands
; i
++)
488 const struct tilegx_operand
*operand
=
489 &tilegx_operands
[operands
[i
]];
490 expressionS
*operand_exp
= &operand_values
[i
];
491 int is_pc_relative
= operand
->is_pc_relative
;
493 if (operand_exp
->X_op
== O_register
494 || (operand_exp
->X_op
== O_constant
&& !is_pc_relative
))
496 /* We know what the bits are right now, so insert them. */
497 bits
= insert_operand (bits
, operand
, operand_exp
->X_add_number
,
502 bfd_reloc_code_real_type reloc
= operand
->default_reloc
;
504 int die
= 0, use_subexp
= 0, require_symbol
= 0;
507 /* Take an expression like hw0(x) and turn it into x with
508 a different reloc type. */
509 switch (operand_exp
->X_op
)
511 #define HANDLE_OP16(suffix) \
514 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST: \
515 reloc = BFD_RELOC_TILEGX_IMM16_X0_##suffix; \
517 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST: \
518 reloc = BFD_RELOC_TILEGX_IMM16_X1_##suffix; \
543 HANDLE_OP16 (HW0_LAST
);
547 HANDLE_OP16 (HW1_LAST
);
551 HANDLE_OP16 (HW2_LAST
);
555 HANDLE_OP16 (HW0_GOT
);
560 HANDLE_OP16 (HW0_LAST_GOT
);
565 HANDLE_OP16 (HW1_LAST_GOT
);
570 HANDLE_OP16 (HW0_TLS_GD
);
574 case O_hw0_last_tls_gd
:
575 HANDLE_OP16 (HW0_LAST_TLS_GD
);
579 case O_hw1_last_tls_gd
:
580 HANDLE_OP16 (HW1_LAST_TLS_GD
);
585 HANDLE_OP16 (HW0_TLS_IE
);
589 case O_hw0_last_tls_ie
:
590 HANDLE_OP16 (HW0_LAST_TLS_IE
);
594 case O_hw1_last_tls_ie
:
595 HANDLE_OP16 (HW1_LAST_TLS_IE
);
600 HANDLE_OP16 (HW0_TLS_LE
);
604 case O_hw0_last_tls_le
:
605 HANDLE_OP16 (HW0_LAST_TLS_LE
);
609 case O_hw1_last_tls_le
:
610 HANDLE_OP16 (HW1_LAST_TLS_LE
);
619 case BFD_RELOC_TILEGX_JUMPOFF_X1
:
620 reloc
= BFD_RELOC_TILEGX_JUMPOFF_X1_PLT
;
633 case BFD_RELOC_TILEGX_JUMPOFF_X1
:
634 reloc
= BFD_RELOC_TILEGX_TLS_GD_CALL
;
647 case BFD_RELOC_TILEGX_IMM8_X0
:
648 reloc
= BFD_RELOC_TILEGX_IMM8_X0_TLS_GD_ADD
;
650 case BFD_RELOC_TILEGX_IMM8_X1
:
651 reloc
= BFD_RELOC_TILEGX_IMM8_X1_TLS_GD_ADD
;
653 case BFD_RELOC_TILEGX_IMM8_Y0
:
654 reloc
= BFD_RELOC_TILEGX_IMM8_Y0_TLS_GD_ADD
;
656 case BFD_RELOC_TILEGX_IMM8_Y1
:
657 reloc
= BFD_RELOC_TILEGX_IMM8_Y1_TLS_GD_ADD
;
670 case BFD_RELOC_TILEGX_IMM8_X1
:
671 reloc
= BFD_RELOC_TILEGX_TLS_IE_LOAD
;
684 case BFD_RELOC_TILEGX_IMM8_X0
:
685 reloc
= BFD_RELOC_TILEGX_IMM8_X0_TLS_ADD
;
687 case BFD_RELOC_TILEGX_IMM8_X1
:
688 reloc
= BFD_RELOC_TILEGX_IMM8_X1_TLS_ADD
;
690 case BFD_RELOC_TILEGX_IMM8_Y0
:
691 reloc
= BFD_RELOC_TILEGX_IMM8_Y0_TLS_ADD
;
693 case BFD_RELOC_TILEGX_IMM8_Y1
:
694 reloc
= BFD_RELOC_TILEGX_IMM8_Y1_TLS_ADD
;
711 as_bad (_("Invalid operator for operand."));
715 /* Now that we've changed the reloc, change ha16(x) into x,
718 if (operand_exp
->X_add_symbol
->sy_value
.X_md
)
720 /* HACK: We used X_md to mark this symbol as a fake wrapper
721 around a real expression. To unwrap it, we just grab its
723 operand_exp
= &operand_exp
->X_add_symbol
->sy_value
;
727 /* Look at the expression, and reject it if it's not a
729 if (operand_exp
->X_op
!= O_symbol
730 || operand_exp
->X_add_number
!= 0)
731 as_bad (_("Operator may only be applied to symbols."));
736 /* The value of this expression is an actual symbol, so
737 turn that into an expression. */
738 memset (&subexp
, 0, sizeof subexp
);
739 subexp
.X_op
= O_symbol
;
740 subexp
.X_add_symbol
= operand_exp
->X_add_symbol
;
741 operand_exp
= &subexp
;
745 /* Create a fixup to handle this later. */
746 fixP
= fix_new_exp (frag_now
,
747 bundle_start
- frag_now
->fr_literal
,
748 (operand
->num_bits
+ 7) >> 3,
752 fixP
->tc_fix_data
= operand
;
754 /* Don't do overflow checking if we are applying a function like
756 fixP
->fx_no_overflow
|= use_subexp
;
763 /* Detects and complains if two instructions in current_bundle write
764 to the same register, either implicitly or explicitly, or if a
765 read-only register is written. */
767 check_illegal_reg_writes (void)
769 BFD_HOST_U_64_BIT all_regs_written
= 0;
772 for (j
= 0; j
< current_bundle_index
; j
++)
774 const struct tilegx_instruction
*instr
= ¤t_bundle
[j
];
776 BFD_HOST_U_64_BIT regs
=
777 ((BFD_HOST_U_64_BIT
)1) << instr
->opcode
->implicitly_written_register
;
778 BFD_HOST_U_64_BIT conflict
;
780 for (k
= 0; k
< instr
->opcode
->num_operands
; k
++)
782 const struct tilegx_operand
*operand
=
783 &tilegx_operands
[instr
->opcode
->operands
[instr
->pipe
][k
]];
785 if (operand
->is_dest_reg
)
787 int regno
= instr
->operand_values
[k
].X_add_number
;
788 BFD_HOST_U_64_BIT mask
= ((BFD_HOST_U_64_BIT
)1) << regno
;
790 if ((mask
& ( (((BFD_HOST_U_64_BIT
)1) << TREG_IDN1
)
791 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN1
)
792 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN2
)
793 | (((BFD_HOST_U_64_BIT
)1) << TREG_UDN3
))) != 0
794 && !allow_suspicious_bundles
)
796 as_bad (_("Writes to register '%s' are not allowed."),
797 tilegx_register_names
[regno
]);
804 /* Writing to the zero register doesn't count. */
805 regs
&= ~(((BFD_HOST_U_64_BIT
)1) << TREG_ZERO
);
807 conflict
= all_regs_written
& regs
;
808 if (conflict
!= 0 && !allow_suspicious_bundles
)
810 /* Find which register caused the conflict. */
811 const char *conflicting_reg_name
= "???";
814 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
816 if (((conflict
>> i
) & 1) != 0)
818 conflicting_reg_name
= tilegx_register_names
[i
];
823 as_bad (_("Two instructions in the same bundle both write "
824 "to register %s, which is not allowed."),
825 conflicting_reg_name
);
828 all_regs_written
|= regs
;
834 tilegx_flush_bundle (void)
839 unsigned compatible_pipes
;
840 const struct bundle_template
*match
;
845 switch (current_bundle_index
)
848 /* No instructions. */
851 if (current_bundle
[0].opcode
->can_bundle
)
853 /* Simplify later logic by adding an explicit fnop. */
854 prepend_nop_to_bundle (TILEGX_OPC_FNOP
);
858 /* This instruction cannot be bundled with anything else.
859 Prepend an explicit 'nop', rather than an 'fnop', because
860 fnops can be replaced by later binary-processing tools while
862 prepend_nop_to_bundle (TILEGX_OPC_NOP
);
866 if (!allow_suspicious_bundles
)
868 /* Make sure all instructions can be bundled with other
870 const struct tilegx_opcode
*cannot_bundle
= NULL
;
871 bfd_boolean seen_non_nop
= FALSE
;
873 for (j
= 0; j
< current_bundle_index
; j
++)
875 const struct tilegx_opcode
*op
= current_bundle
[j
].opcode
;
877 if (!op
->can_bundle
&& cannot_bundle
== NULL
)
879 else if (op
->mnemonic
!= TILEGX_OPC_NOP
880 && op
->mnemonic
!= TILEGX_OPC_INFO
881 && op
->mnemonic
!= TILEGX_OPC_INFOL
)
885 if (cannot_bundle
!= NULL
&& seen_non_nop
)
887 current_bundle_index
= 0;
888 as_bad (_("'%s' may not be bundled with other instructions."),
889 cannot_bundle
->name
);
897 BUNDLE_TEMPLATE_MASK(current_bundle
[0].opcode
->pipes
,
898 current_bundle
[1].opcode
->pipes
,
899 (current_bundle_index
== 3
900 ? current_bundle
[2].opcode
->pipes
901 : (1 << NO_PIPELINE
)));
903 /* Find a template that works, if any. */
905 for (i
= 0; i
< sizeof bundle_templates
/ sizeof bundle_templates
[0]; i
++)
907 const struct bundle_template
*b
= &bundle_templates
[i
];
908 if ((b
->pipe_mask
& compatible_pipes
) == b
->pipe_mask
)
917 current_bundle_index
= 0;
918 as_bad (_("Invalid combination of instructions for bundle."));
922 /* If the section seems to have no alignment set yet, go ahead and
923 make it large enough to hold code. */
924 if (bfd_get_section_alignment (stdoutput
, now_seg
) == 0)
925 bfd_set_section_alignment (stdoutput
, now_seg
,
926 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
);
928 for (j
= 0; j
< current_bundle_index
; j
++)
929 current_bundle
[j
].pipe
= match
->pipe
[j
];
931 if (current_bundle_index
== 2 && !tilegx_is_x_pipeline (match
->pipe
[0]))
933 /* We are in Y mode with only two instructions, so add an FNOP. */
934 prepend_nop_to_bundle (TILEGX_OPC_FNOP
);
936 /* Figure out what pipe the fnop must be in via arithmetic.
937 * p0 + p1 + p2 must sum to the sum of TILEGX_PIPELINE_Y[012]. */
938 current_bundle
[0].pipe
=
939 (tilegx_pipeline
)((TILEGX_PIPELINE_Y0
941 + TILEGX_PIPELINE_Y2
) -
942 (current_bundle
[1].pipe
+ current_bundle
[2].pipe
));
945 check_illegal_reg_writes ();
947 f
= frag_more (TILEGX_BUNDLE_SIZE_IN_BYTES
);
949 /* Check to see if this bundle is at an offset that is a multiple of 8-bytes
950 from the start of the frag. */
951 addr_mod
= frag_now_fix () & (TILEGX_BUNDLE_ALIGNMENT_IN_BYTES
- 1);
952 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
953 as_bad (_("instruction address is not a multiple of 8"));
954 frag_now
->insn_addr
= addr_mod
;
955 frag_now
->has_code
= 1;
957 tilegx_bundle_bits bits
= 0;
958 for (j
= 0; j
< current_bundle_index
; j
++)
960 struct tilegx_instruction
*instr
= ¤t_bundle
[j
];
961 tilegx_pipeline pipeline
= instr
->pipe
;
962 const struct tilegx_opcode
*opcode
= instr
->opcode
;
964 bits
|= emit_tilegx_instruction (opcode
->fixed_bit_values
[pipeline
],
965 opcode
->num_operands
,
966 &opcode
->operands
[pipeline
][0],
967 instr
->operand_values
,
971 number_to_chars_littleendian (f
, bits
, 8);
972 current_bundle_index
= 0;
974 /* Emit DWARF2 debugging information. */
975 dwarf2_emit_insn (TILEGX_BUNDLE_SIZE_IN_BYTES
);
979 /* Extend the expression parser to handle hw0(label), etc.
980 as well as SPR names when in the context of parsing an SPR. */
983 tilegx_parse_name (char *name
, expressionS
*e
, char *nextcharP
)
985 operatorT op
= O_illegal
;
989 void* val
= hash_find (spr_hash
, name
);
993 memset (e
, 0, sizeof *e
);
994 e
->X_op
= O_constant
;
995 e
->X_add_number
= ((const struct tilegx_spr
*)val
)->number
;
999 if (*nextcharP
!= '(')
1001 /* hw0, etc. not followed by a paren is just a label with that name. */
1006 /* Look up the operator in our table. */
1007 void* val
= hash_find (special_operator_hash
, name
);
1010 op
= (operatorT
)(long)val
;
1013 /* Restore old '(' and skip it. */
1014 *input_line_pointer
= '(';
1015 ++input_line_pointer
;
1019 if (*input_line_pointer
!= ')')
1021 as_bad (_("Missing ')'"));
1022 *nextcharP
= *input_line_pointer
;
1026 ++input_line_pointer
;
1028 if (e
->X_op
== O_register
|| e
->X_op
== O_absent
)
1030 as_bad (_("Invalid expression."));
1031 e
->X_op
= O_constant
;
1032 e
->X_add_number
= 0;
1036 /* Wrap subexpression with a unary operator. */
1037 symbolS
*sym
= make_expr_symbol (e
);
1039 if (sym
!= e
->X_add_symbol
)
1041 /* HACK: mark this symbol as a temporary wrapper around a proper
1042 expression, so we can unwrap it later once we have communicated
1043 the relocation type. */
1044 sym
->sy_value
.X_md
= 1;
1047 memset (e
, 0, sizeof *e
);
1049 e
->X_add_symbol
= sym
;
1050 e
->X_add_number
= 0;
1053 *nextcharP
= *input_line_pointer
;
1058 /* Parses an expression which must be a register name. */
1061 parse_reg_expression (expressionS
* expression
)
1063 /* Zero everything to make sure we don't miss any flags. */
1064 memset (expression
, 0, sizeof *expression
);
1066 char* regname
= input_line_pointer
;
1067 char terminating_char
= get_symbol_end ();
1069 void* pval
= hash_find (main_reg_hash
, regname
);
1073 as_bad (_("Expected register, got '%s'."), regname
);
1076 int regno_and_flags
= (int)(size_t)pval
;
1077 int regno
= EXTRACT_REGNO(regno_and_flags
);
1079 if ((regno_and_flags
& NONCANONICAL_REG_NAME_FLAG
)
1080 && require_canonical_reg_names
)
1082 as_warn (_("Found use of non-canonical register name %s; "
1085 tilegx_register_names
[regno
]);
1088 /* Restore the old character following the register name. */
1089 *input_line_pointer
= terminating_char
;
1091 /* Fill in the expression fields to indicate it's a register. */
1092 expression
->X_op
= O_register
;
1093 expression
->X_add_number
= regno
;
1097 /* Parses and type-checks comma-separated operands in input_line_pointer. */
1100 parse_operands (const char *opcode_name
,
1101 const unsigned char *operands
,
1103 expressionS
*operand_values
)
1107 memset (operand_values
, 0, num_operands
* sizeof operand_values
[0]);
1110 for (i
= 0; i
< num_operands
; i
++)
1112 tilegx_operand_type type
= tilegx_operands
[operands
[i
]].type
;
1116 if (type
== TILEGX_OP_TYPE_REGISTER
)
1118 parse_reg_expression (&operand_values
[i
]);
1120 else if (*input_line_pointer
== '}')
1122 operand_values
[i
].X_op
= O_absent
;
1124 else if (type
== TILEGX_OP_TYPE_SPR
)
1126 /* Modify the expression parser to add SPRs to the namespace. */
1128 expression (&operand_values
[i
]);
1133 expression (&operand_values
[i
]);
1138 if (i
+ 1 < num_operands
)
1140 int separator
= (unsigned char)*input_line_pointer
++;
1142 if (is_end_of_line
[separator
] || (separator
== '}'))
1144 as_bad (_("Too few operands to '%s'."), opcode_name
);
1147 else if (separator
!= ',')
1149 as_bad (_("Unexpected character '%c' after operand %d to %s."),
1150 (char)separator
, i
+ 1, opcode_name
);
1155 /* Arbitrarily use the first valid pipe to get the operand type,
1156 since they are all the same. */
1157 switch (tilegx_operands
[operands
[i
]].type
)
1159 case TILEGX_OP_TYPE_REGISTER
:
1160 /* Handled in parse_reg_expression already. */
1162 case TILEGX_OP_TYPE_SPR
:
1164 case TILEGX_OP_TYPE_IMMEDIATE
:
1166 case TILEGX_OP_TYPE_ADDRESS
:
1167 if ( operand_values
[i
].X_op
== O_register
1168 || operand_values
[i
].X_op
== O_illegal
1169 || operand_values
[i
].X_op
== O_absent
)
1170 as_bad (_("Expected immediate expression"));
1177 if (!is_end_of_line
[(unsigned char)*input_line_pointer
])
1179 switch (*input_line_pointer
)
1183 as_bad (_("Found '}' when not bundling."));
1184 ++input_line_pointer
;
1186 demand_empty_rest_of_line ();
1190 as_bad (_("Too many operands"));
1194 /* Use default error for unrecognized garbage. */
1195 demand_empty_rest_of_line ();
1202 /* This is the guts of the machine-dependent assembler. STR points to a
1203 machine dependent instruction. This function is supposed to emit the
1204 frags/bytes it assembles to. */
1207 md_assemble (char *str
)
1211 char *old_input_line_pointer
;
1212 const struct tilegx_opcode
*op
;
1215 /* Split off the opcode and look it up. */
1216 opname_len
= strcspn (str
, " {}");
1217 old_char
= str
[opname_len
];
1218 str
[opname_len
] = '\0';
1220 op
= hash_find(op_hash
, str
);
1221 str
[opname_len
] = old_char
;
1224 as_bad (_("Unknown opcode `%.*s'."), (int)opname_len
, str
);
1228 /* Prepare to parse the operands. */
1229 old_input_line_pointer
= input_line_pointer
;
1230 input_line_pointer
= str
+ opname_len
;
1233 if (current_bundle_index
== TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
)
1235 as_bad (_("Too many instructions for bundle."));
1236 tilegx_flush_bundle ();
1239 /* Make sure we have room for the upcoming bundle before we
1240 create any fixups. Otherwise if we have to switch to a new
1241 frag the fixup dot_value fields will be wrong. */
1242 frag_grow (TILEGX_BUNDLE_SIZE_IN_BYTES
);
1244 /* Find a valid pipe for this opcode. */
1245 for (first_pipe
= 0; (op
->pipes
& (1 << first_pipe
)) == 0; first_pipe
++)
1248 /* Call the function that assembles this instruction. */
1249 current_bundle
[current_bundle_index
].opcode
= op
;
1250 parse_operands (op
->name
,
1251 &op
->operands
[first_pipe
][0],
1253 current_bundle
[current_bundle_index
].operand_values
);
1254 ++current_bundle_index
;
1256 /* Restore the saved value of input_line_pointer. */
1257 input_line_pointer
= old_input_line_pointer
;
1259 /* If we weren't inside curly braces, go ahead and emit
1260 this lone instruction as a bundle right now. */
1262 tilegx_flush_bundle ();
1267 s_require_canonical_reg_names (int require
)
1269 demand_empty_rest_of_line ();
1270 require_canonical_reg_names
= require
;
1274 s_allow_suspicious_bundles (int allow
)
1276 demand_empty_rest_of_line ();
1277 allow_suspicious_bundles
= allow
;
1280 const pseudo_typeS md_pseudo_table
[] =
1282 {"align", s_align_bytes
, 0}, /* Defaulting is invalid (0). */
1284 {"require_canonical_reg_names", s_require_canonical_reg_names
, 1 },
1285 {"no_require_canonical_reg_names", s_require_canonical_reg_names
, 0 },
1286 {"allow_suspicious_bundles", s_allow_suspicious_bundles
, 1 },
1287 {"no_allow_suspicious_bundles", s_allow_suspicious_bundles
, 0 },
1291 /* Equal to MAX_PRECISION in atof-ieee.c */
1292 #define MAX_LITTLENUMS 6
1295 md_number_to_chars (char * buf
, valueT val
, int n
)
1297 if (target_big_endian
)
1298 number_to_chars_bigendian (buf
, val
, n
);
1300 number_to_chars_littleendian (buf
, val
, n
);
1303 /* Turn the string pointed to by litP into a floating point constant
1304 of type TYPE, and emit the appropriate bytes. The number of
1305 LITTLENUMS emitted is stored in *SIZEP. An error message is
1306 returned, or NULL on OK. */
1309 md_atof (int type
, char *litP
, int *sizeP
)
1312 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
1313 LITTLENUM_TYPE
*wordP
;
1330 return _("Bad call to md_atof ()");
1332 t
= atof_ieee (input_line_pointer
, type
, words
);
1334 input_line_pointer
= t
;
1336 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
1337 /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
1338 the bigendian 386. */
1339 for (wordP
= words
+ prec
- 1; prec
--;)
1341 md_number_to_chars (litP
, (valueT
) (*wordP
--), sizeof (LITTLENUM_TYPE
));
1342 litP
+= sizeof (LITTLENUM_TYPE
);
1348 /* We have no need to default values of symbols. */
1351 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1358 tilegx_cons_fix_new (fragS
*frag
,
1364 bfd_reloc_code_real_type reloc
= BFD_RELOC_NONE
;
1365 int no_overflow
= 0;
1368 /* See if it's one of our special functions. */
1372 reloc
= BFD_RELOC_TILEGX_HW0
;
1376 reloc
= BFD_RELOC_TILEGX_HW1
;
1380 reloc
= BFD_RELOC_TILEGX_HW2
;
1384 reloc
= BFD_RELOC_TILEGX_HW3
;
1388 reloc
= BFD_RELOC_TILEGX_HW0_LAST
;
1391 reloc
= BFD_RELOC_TILEGX_HW1_LAST
;
1394 reloc
= BFD_RELOC_TILEGX_HW2_LAST
;
1402 if (reloc
!= BFD_RELOC_NONE
)
1406 as_bad (_("This operator only produces two byte values."));
1410 memset (&subexp
, 0, sizeof subexp
);
1411 subexp
.X_op
= O_symbol
;
1412 subexp
.X_add_symbol
= exp
->X_add_symbol
;
1420 reloc
= BFD_RELOC_8
;
1423 reloc
= BFD_RELOC_16
;
1426 reloc
= BFD_RELOC_32
;
1429 reloc
= BFD_RELOC_64
;
1432 as_bad (_("unsupported BFD relocation size %d"), nbytes
);
1433 reloc
= BFD_RELOC_64
;
1438 fixP
= fix_new_exp (frag
, where
, nbytes
, exp
, 0, reloc
);
1439 fixP
->tc_fix_data
= NULL
;
1440 fixP
->fx_no_overflow
|= no_overflow
;
1445 md_apply_fix (fixS
*fixP
, valueT
* valP
, segT seg ATTRIBUTE_UNUSED
)
1447 const struct tilegx_operand
*operand
;
1448 valueT value
= *valP
;
1452 /* Leave these for the linker. */
1453 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1454 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1457 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
1459 /* We can't actually support subtracting a symbol. */
1460 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
1463 /* Correct relocation types for pc-relativeness. */
1464 switch (fixP
->fx_r_type
)
1466 #define FIX_PCREL(rtype) \
1468 if (fixP->fx_pcrel) \
1469 fixP->fx_r_type = rtype##_PCREL; \
1472 case rtype##_PCREL: \
1473 if (!fixP->fx_pcrel) \
1474 fixP->fx_r_type = rtype; \
1477 FIX_PCREL (BFD_RELOC_8
);
1478 FIX_PCREL (BFD_RELOC_16
);
1479 FIX_PCREL (BFD_RELOC_32
);
1480 FIX_PCREL (BFD_RELOC_64
);
1481 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0
);
1482 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0
);
1483 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1
);
1484 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1
);
1485 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2
);
1486 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2
);
1487 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW3
);
1488 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW3
);
1489 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST
);
1490 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST
);
1491 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST
);
1492 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST
);
1493 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST
);
1494 FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST
);
1503 if (fixP
->fx_addsy
!= NULL
)
1506 switch (fixP
->fx_r_type
)
1508 case BFD_RELOC_TILEGX_IMM8_X0_TLS_ADD
:
1509 case BFD_RELOC_TILEGX_IMM8_X1_TLS_ADD
:
1510 case BFD_RELOC_TILEGX_IMM8_Y0_TLS_ADD
:
1511 case BFD_RELOC_TILEGX_IMM8_Y1_TLS_ADD
:
1512 case BFD_RELOC_TILEGX_IMM8_X0_TLS_GD_ADD
:
1513 case BFD_RELOC_TILEGX_IMM8_X1_TLS_GD_ADD
:
1514 case BFD_RELOC_TILEGX_IMM8_Y0_TLS_GD_ADD
:
1515 case BFD_RELOC_TILEGX_IMM8_Y1_TLS_GD_ADD
:
1516 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD
:
1517 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD
:
1518 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
:
1519 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
:
1520 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
:
1521 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
:
1522 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE
:
1523 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE
:
1524 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
:
1525 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
:
1526 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
:
1527 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
:
1528 case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_LE
:
1529 case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_LE
:
1530 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
:
1531 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
:
1532 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
:
1533 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
:
1534 case BFD_RELOC_TILEGX_TLS_GD_CALL
:
1535 case BFD_RELOC_TILEGX_TLS_IE_LOAD
:
1536 case BFD_RELOC_TILEGX_TLS_DTPMOD64
:
1537 case BFD_RELOC_TILEGX_TLS_DTPOFF64
:
1538 case BFD_RELOC_TILEGX_TLS_TPOFF64
:
1539 case BFD_RELOC_TILEGX_TLS_DTPMOD32
:
1540 case BFD_RELOC_TILEGX_TLS_DTPOFF32
:
1541 case BFD_RELOC_TILEGX_TLS_TPOFF32
:
1542 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
1553 /* Apply hw0, etc. */
1554 special
= O_illegal
;
1555 switch (fixP
->fx_r_type
)
1557 case BFD_RELOC_TILEGX_HW0
:
1558 case BFD_RELOC_TILEGX_IMM16_X0_HW0
:
1559 case BFD_RELOC_TILEGX_IMM16_X1_HW0
:
1560 case BFD_RELOC_TILEGX_IMM16_X0_HW0_PCREL
:
1561 case BFD_RELOC_TILEGX_IMM16_X1_HW0_PCREL
:
1565 case BFD_RELOC_TILEGX_HW0_LAST
:
1566 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST
:
1567 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST
:
1568 case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PCREL
:
1569 case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PCREL
:
1570 special
= O_hw0_last
;
1573 case BFD_RELOC_TILEGX_HW1
:
1574 case BFD_RELOC_TILEGX_IMM16_X0_HW1
:
1575 case BFD_RELOC_TILEGX_IMM16_X1_HW1
:
1576 case BFD_RELOC_TILEGX_IMM16_X0_HW1_PCREL
:
1577 case BFD_RELOC_TILEGX_IMM16_X1_HW1_PCREL
:
1581 case BFD_RELOC_TILEGX_HW1_LAST
:
1582 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST
:
1583 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST
:
1584 case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PCREL
:
1585 case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PCREL
:
1586 special
= O_hw1_last
;
1589 case BFD_RELOC_TILEGX_HW2
:
1590 case BFD_RELOC_TILEGX_IMM16_X0_HW2
:
1591 case BFD_RELOC_TILEGX_IMM16_X1_HW2
:
1592 case BFD_RELOC_TILEGX_IMM16_X0_HW2_PCREL
:
1593 case BFD_RELOC_TILEGX_IMM16_X1_HW2_PCREL
:
1597 case BFD_RELOC_TILEGX_HW2_LAST
:
1598 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST
:
1599 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST
:
1600 case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PCREL
:
1601 case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PCREL
:
1602 special
= O_hw2_last
;
1605 case BFD_RELOC_TILEGX_HW3
:
1606 case BFD_RELOC_TILEGX_IMM16_X0_HW3
:
1607 case BFD_RELOC_TILEGX_IMM16_X1_HW3
:
1608 case BFD_RELOC_TILEGX_IMM16_X0_HW3_PCREL
:
1609 case BFD_RELOC_TILEGX_IMM16_X1_HW3_PCREL
:
1618 if (special
!= O_illegal
)
1620 *valP
= value
= apply_special_operator (special
, value
,
1621 fixP
->fx_file
, fixP
->fx_line
);
1624 p
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
1626 operand
= fixP
->tc_fix_data
;
1627 if (operand
!= NULL
)
1629 /* It's an instruction operand. */
1630 tilegx_bundle_bits bits
=
1631 insert_operand (0, operand
, value
, fixP
->fx_file
, fixP
->fx_line
);
1633 /* Note that we might either be writing out bits for a bundle
1634 or a static network instruction, which are different sizes, so it's
1635 important to stop touching memory once we run out of bits.
1636 ORing in values is OK since we know the existing bits for
1637 this operand are zero. */
1638 for (; bits
!= 0; bits
>>= 8)
1643 /* Some other kind of relocation. */
1644 switch (fixP
->fx_r_type
)
1647 case BFD_RELOC_8_PCREL
:
1648 md_number_to_chars (p
, value
, 1);
1652 case BFD_RELOC_16_PCREL
:
1653 md_number_to_chars (p
, value
, 2);
1657 case BFD_RELOC_32_PCREL
:
1658 md_number_to_chars (p
, value
, 4);
1662 case BFD_RELOC_64_PCREL
:
1663 md_number_to_chars (p
, value
, 8);
1667 /* Leave it for the linker. */
1676 /* Generate the BFD reloc to be stuck in the object file from the
1677 fixup used internally in the assembler. */
1680 tc_gen_reloc (asection
*sec ATTRIBUTE_UNUSED
, fixS
*fixp
)
1684 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1685 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1686 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1687 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1689 /* Make sure none of our internal relocations make it this far.
1690 They'd better have been fully resolved by this point. */
1691 gas_assert ((int) fixp
->fx_r_type
> 0);
1693 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1694 if (reloc
->howto
== NULL
)
1696 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1697 _("cannot represent `%s' relocation in object file"),
1698 bfd_get_reloc_code_name (fixp
->fx_r_type
));
1702 if (!fixp
->fx_pcrel
!= !reloc
->howto
->pc_relative
)
1704 as_fatal (_("internal error? cannot generate `%s' relocation (%d, %d)"),
1705 bfd_get_reloc_code_name (fixp
->fx_r_type
),
1706 fixp
->fx_pcrel
, reloc
->howto
->pc_relative
);
1708 gas_assert (!fixp
->fx_pcrel
== !reloc
->howto
->pc_relative
);
1710 reloc
->addend
= fixp
->fx_offset
;
1716 /* The location from which a PC relative jump should be calculated,
1717 given a PC relative reloc. */
1720 md_pcrel_from (fixS
*fixP
)
1722 return fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1726 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
1727 a section symbol plus some offset. */
1729 tilegx_fix_adjustable (fixS
*fix
)
1731 /* Prevent all adjustments to global symbols */
1732 if (S_IS_EXTERNAL (fix
->fx_addsy
) || S_IS_WEAK (fix
->fx_addsy
))
1740 tilegx_unrecognized_line (int ch
)
1747 as_bad (_("Found '{' when already bundling."));
1752 current_bundle_index
= 0;
1759 as_bad (_("Found '}' when not bundling."));
1763 tilegx_flush_bundle ();
1766 /* Allow '{' to follow on the same line. We also allow ";;", but that
1767 happens automatically because ';' is an end of line marker. */
1769 if (input_line_pointer
[0] == '{')
1771 input_line_pointer
++;
1772 return tilegx_unrecognized_line ('{');
1775 demand_empty_rest_of_line ();
1782 /* Not a valid line. */
1787 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
1788 of an rs_align_code fragment. */
1791 tilegx_handle_align (fragS
*fragp
)
1793 addressT bytes
, fix
;
1796 if (fragp
->fr_type
!= rs_align_code
)
1799 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
1800 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
1803 /* Determine the bits for NOP. */
1804 const struct tilegx_opcode
*nop_opcode
=
1805 &tilegx_opcodes
[TILEGX_OPC_NOP
];
1806 tilegx_bundle_bits nop
=
1807 ( nop_opcode
->fixed_bit_values
[TILEGX_PIPELINE_X0
]
1808 | nop_opcode
->fixed_bit_values
[TILEGX_PIPELINE_X1
]);
1810 if ((bytes
& (TILEGX_BUNDLE_SIZE_IN_BYTES
- 1)) != 0)
1812 fix
= bytes
& (TILEGX_BUNDLE_SIZE_IN_BYTES
- 1);
1818 number_to_chars_littleendian (p
, nop
, 8);
1819 fragp
->fr_fix
+= fix
;
1820 fragp
->fr_var
= TILEGX_BUNDLE_SIZE_IN_BYTES
;
1823 /* Standard calling conventions leave the CFA at SP on entry. */
1825 tilegx_cfi_frame_initial_instructions (void)
1827 cfi_add_CFA_def_cfa_register (54);
1831 tc_tilegx_regname_to_dw2regnum (char *regname
)
1834 for (i
= 0; i
< TILEGX_NUM_REGISTERS
; i
++)
1836 if (!strcmp (regname
, tilegx_register_names
[i
]))