[PATCH 5/57][Arm][GAS] Add support for MVE instructions: vmull{b,t}
[binutils-gdb.git] / gas / config / tc-tilepro.c
blob146e270f7de609ae93710ba35b7fe793629eb55c
1 /* tc-tilepro.c -- Assemble for a TILEPro chip.
2 Copyright (C) 2011-2019 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. */
21 #include "as.h"
22 #include "subsegs.h"
24 #include "elf/tilepro.h"
25 #include "opcode/tilepro.h"
27 #include "dwarf2dbg.h"
28 #include "dw2gencfi.h"
30 #include "safe-ctype.h"
33 /* Special registers. */
34 #define TREG_IDN0 57
35 #define TREG_IDN1 58
36 #define TREG_UDN0 59
37 #define TREG_UDN1 60
38 #define TREG_UDN2 61
39 #define TREG_UDN3 62
40 #define TREG_ZERO 63
43 /* Generic assembler global variables which must be defined by all
44 targets. */
46 /* Characters which always start a comment. */
47 const char comment_chars[] = "#";
49 /* Characters which start a comment at the beginning of a line. */
50 const char line_comment_chars[] = "#";
52 /* Characters which may be used to separate multiple commands on a
53 single line. */
54 const char line_separator_chars[] = ";";
56 /* Characters which are used to indicate an exponent in a floating
57 point number. */
58 const char EXP_CHARS[] = "eE";
60 /* Characters which mean that a number is a floating point constant,
61 as in 0d1.0. */
62 const char FLT_CHARS[] = "rRsSfFdDxXpP";
64 const char *md_shortopts = "VQ:";
66 struct option md_longopts[] =
68 {NULL, no_argument, NULL, 0}
71 size_t md_longopts_size = sizeof (md_longopts);
73 int
74 md_parse_option (int c, const char *arg ATTRIBUTE_UNUSED)
76 switch (c)
78 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
79 should be emitted or not. FIXME: Not implemented. */
80 case 'Q':
81 break;
83 /* -V: SVR4 argument to print version ID. */
84 case 'V':
85 print_version_id ();
86 break;
88 default:
89 return 0;
92 return 1;
95 void
96 md_show_usage (FILE *stream)
98 fprintf (stream, _("\
99 -Q ignored\n\
100 -V print assembler version number\n"));
103 /* Extra expression types. */
105 #define O_lo16 O_md1
106 #define O_hi16 O_md2
107 #define O_ha16 O_md3
108 #define O_got O_md4
109 #define O_got_lo16 O_md5
110 #define O_got_hi16 O_md6
111 #define O_got_ha16 O_md7
112 #define O_plt O_md8
113 #define O_tls_gd O_md9
114 #define O_tls_gd_lo16 O_md10
115 #define O_tls_gd_hi16 O_md11
116 #define O_tls_gd_ha16 O_md12
117 #define O_tls_ie O_md13
118 #define O_tls_ie_lo16 O_md14
119 #define O_tls_ie_hi16 O_md15
120 #define O_tls_ie_ha16 O_md16
121 #define O_tls_le O_md17
122 #define O_tls_le_lo16 O_md18
123 #define O_tls_le_hi16 O_md19
124 #define O_tls_le_ha16 O_md20
125 #define O_tls_gd_call O_md21
126 #define O_tls_gd_add O_md22
127 #define O_tls_ie_load O_md23
129 static struct hash_control *special_operator_hash;
131 /* Hash tables for instruction mnemonic lookup. */
132 static struct hash_control *op_hash;
134 /* Hash table for spr lookup. */
135 static struct hash_control *spr_hash;
137 /* True temporarily while parsing an SPR expression. This changes the
138 * namespace to include SPR names. */
139 static int parsing_spr;
141 /* Are we currently inside `{ ... }'? */
142 static int inside_bundle;
144 struct tilepro_instruction
146 const struct tilepro_opcode *opcode;
147 tilepro_pipeline pipe;
148 expressionS operand_values[TILEPRO_MAX_OPERANDS];
151 /* This keeps track of the current bundle being built up. */
152 static struct tilepro_instruction
153 current_bundle[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
155 /* Index in current_bundle for the next instruction to parse. */
156 static int current_bundle_index;
158 /* Allow 'r63' in addition to 'zero', etc. Normally we disallow this as
159 'zero' is not a real register, so using it accidentally would be a
160 nasty bug. For other registers, such as 'sp', code using multiple names
161 for the same physical register is excessively confusing.
163 The '.require_canonical_reg_names' pseudo-op turns this error on,
164 and the '.no_require_canonical_reg_names' pseudo-op turns this off.
165 By default the error is on. */
166 static int require_canonical_reg_names;
168 /* Allow bundles that do undefined or suspicious things like write
169 two different values to the same register at the same time.
171 The '.no_allow_suspicious_bundles' pseudo-op turns this error on,
172 and the '.allow_suspicious_bundles' pseudo-op turns this off. */
173 static int allow_suspicious_bundles;
176 /* A hash table of main processor registers, mapping each register name
177 to its index.
179 Furthermore, if the register number is greater than the number
180 of registers for that processor, the user used an illegal alias
181 for that register (e.g. r63 instead of zero), so we should generate
182 a warning. The attempted register number can be found by clearing
183 NONCANONICAL_REG_NAME_FLAG. */
184 static struct hash_control *main_reg_hash;
187 /* We cannot unambiguously store a 0 in a hash table and look it up,
188 so we OR in this flag to every canonical register. */
189 #define CANONICAL_REG_NAME_FLAG 0x1000
191 /* By default we disallow register aliases like r63, but we record
192 them in the hash table in case the .no_require_canonical_reg_names
193 directive is used. Noncanonical names have this value added to them. */
194 #define NONCANONICAL_REG_NAME_FLAG 0x2000
196 /* Discards flags for register hash table entries and returns the
197 reg number. */
198 #define EXTRACT_REGNO(p) ((p) & 63)
200 /* This function is called once, at assembler startup time. It should
201 set up all the tables, etc., that the MD part of the assembler will
202 need. */
203 void
204 md_begin (void)
206 const struct tilepro_opcode *op;
207 int i;
209 /* Guarantee text section is aligned. */
210 bfd_set_section_alignment (stdoutput, text_section,
211 TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
213 require_canonical_reg_names = 1;
214 allow_suspicious_bundles = 0;
215 current_bundle_index = 0;
216 inside_bundle = 0;
218 /* Initialize special operator hash table. */
219 special_operator_hash = hash_new ();
220 #define INSERT_SPECIAL_OP(name) \
221 hash_insert (special_operator_hash, #name, (void *)O_##name)
223 INSERT_SPECIAL_OP(lo16);
224 INSERT_SPECIAL_OP(hi16);
225 INSERT_SPECIAL_OP(ha16);
226 INSERT_SPECIAL_OP(got);
227 INSERT_SPECIAL_OP(got_lo16);
228 INSERT_SPECIAL_OP(got_hi16);
229 INSERT_SPECIAL_OP(got_ha16);
230 INSERT_SPECIAL_OP(plt);
231 INSERT_SPECIAL_OP(tls_gd);
232 INSERT_SPECIAL_OP(tls_gd_lo16);
233 INSERT_SPECIAL_OP(tls_gd_hi16);
234 INSERT_SPECIAL_OP(tls_gd_ha16);
235 INSERT_SPECIAL_OP(tls_ie);
236 INSERT_SPECIAL_OP(tls_ie_lo16);
237 INSERT_SPECIAL_OP(tls_ie_hi16);
238 INSERT_SPECIAL_OP(tls_ie_ha16);
239 INSERT_SPECIAL_OP(tls_le);
240 INSERT_SPECIAL_OP(tls_le_lo16);
241 INSERT_SPECIAL_OP(tls_le_hi16);
242 INSERT_SPECIAL_OP(tls_le_ha16);
243 INSERT_SPECIAL_OP(tls_gd_call);
244 INSERT_SPECIAL_OP(tls_gd_add);
245 INSERT_SPECIAL_OP(tls_ie_load);
246 #undef INSERT_SPECIAL_OP
248 /* Initialize op_hash hash table. */
249 op_hash = hash_new ();
250 for (op = &tilepro_opcodes[0]; op->name != NULL; op++)
252 const char *hash_err = hash_insert (op_hash, op->name, (void *)op);
253 if (hash_err != NULL)
255 as_fatal (_("Internal Error: Can't hash %s: %s"),
256 op->name, hash_err);
260 /* Initialize the spr hash table. */
261 parsing_spr = 0;
262 spr_hash = hash_new ();
263 for (i = 0; i < tilepro_num_sprs; i++)
264 hash_insert (spr_hash, tilepro_sprs[i].name,
265 (void *) &tilepro_sprs[i]);
267 /* Set up the main_reg_hash table. We use this instead of
268 * creating a symbol in the register section to avoid ambiguities
269 * with labels that have the same names as registers. */
270 main_reg_hash = hash_new ();
271 for (i = 0; i < TILEPRO_NUM_REGISTERS; i++)
273 char buf[64];
275 hash_insert (main_reg_hash, tilepro_register_names[i],
276 (void *) (long)(i | CANONICAL_REG_NAME_FLAG));
278 /* See if we should insert a noncanonical alias, like r63. */
279 sprintf (buf, "r%d", i);
280 if (strcmp (buf, tilepro_register_names[i]) != 0)
281 hash_insert (main_reg_hash, xstrdup (buf),
282 (void *) (long)(i | NONCANONICAL_REG_NAME_FLAG));
285 /* Insert obsolete backwards-compatibility register names. */
286 hash_insert (main_reg_hash, "io0",
287 (void *) (long) (TREG_IDN0 | CANONICAL_REG_NAME_FLAG));
288 hash_insert (main_reg_hash, "io1",
289 (void *) (long) (TREG_IDN1 | CANONICAL_REG_NAME_FLAG));
290 hash_insert (main_reg_hash, "us0",
291 (void *) (long) (TREG_UDN0 | CANONICAL_REG_NAME_FLAG));
292 hash_insert (main_reg_hash, "us1",
293 (void *) (long) (TREG_UDN1 | CANONICAL_REG_NAME_FLAG));
294 hash_insert (main_reg_hash, "us2",
295 (void *) (long) (TREG_UDN2 | CANONICAL_REG_NAME_FLAG));
296 hash_insert (main_reg_hash, "us3",
297 (void *) (long) (TREG_UDN3 | CANONICAL_REG_NAME_FLAG));
302 #define BUNDLE_TEMPLATE_MASK(p0, p1, p2) \
303 ((p0) | ((p1) << 8) | ((p2) << 16))
304 #define BUNDLE_TEMPLATE(p0, p1, p2) \
305 { { (p0), (p1), (p2) }, \
306 BUNDLE_TEMPLATE_MASK(1 << (p0), 1 << (p1), (1 << (p2))) \
309 #define NO_PIPELINE TILEPRO_NUM_PIPELINE_ENCODINGS
311 struct bundle_template
313 tilepro_pipeline pipe[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
314 unsigned int pipe_mask;
317 static const struct bundle_template bundle_templates[] =
319 /* In Y format we must always have something in Y2, since it has
320 * no fnop, so this conveys that Y2 must always be used. */
321 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y2, NO_PIPELINE),
322 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y2, NO_PIPELINE),
323 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y0, NO_PIPELINE),
324 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y1, NO_PIPELINE),
326 /* Y format has three instructions. */
327 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y2),
328 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y1),
329 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y2),
330 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y0),
331 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y1),
332 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y0),
334 /* X format has only two instructions. */
335 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_X0, TILEPRO_PIPELINE_X1, NO_PIPELINE),
336 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_X1, TILEPRO_PIPELINE_X0, NO_PIPELINE)
340 static void
341 prepend_nop_to_bundle (tilepro_mnemonic mnemonic)
343 memmove (&current_bundle[1], &current_bundle[0],
344 current_bundle_index * sizeof current_bundle[0]);
345 current_bundle[0].opcode = &tilepro_opcodes[mnemonic];
346 ++current_bundle_index;
350 static tilepro_bundle_bits
351 insert_operand (tilepro_bundle_bits bits,
352 const struct tilepro_operand *operand,
353 int operand_value,
354 const char *file,
355 unsigned lineno)
357 /* Range-check the immediate. */
358 int num_bits = operand->num_bits;
360 operand_value >>= operand->rightshift;
362 if (bfd_check_overflow (operand->is_signed
363 ? complain_overflow_signed
364 : complain_overflow_unsigned,
365 num_bits,
367 bfd_arch_bits_per_address (stdoutput),
368 operand_value)
369 != bfd_reloc_ok)
371 offsetT min, max;
372 if (operand->is_signed)
374 min = -(1 << (num_bits - 1));
375 max = (1 << (num_bits - 1)) - 1;
377 else
379 min = 0;
380 max = (1 << num_bits) - 1;
382 as_bad_value_out_of_range (_("operand"), operand_value, min, max,
383 file, lineno);
386 /* Write out the bits for the immediate. */
387 return bits | operand->insert (operand_value);
391 static int
392 apply_special_operator (operatorT op, int num)
394 switch (op)
396 case O_lo16:
397 return (signed short)num;
399 case O_hi16:
400 return (signed short)(num >> 16);
402 case O_ha16:
403 return (signed short)((num + 0x8000) >> 16);
405 default:
406 abort ();
411 static tilepro_bundle_bits
412 emit_tilepro_instruction (tilepro_bundle_bits bits,
413 int num_operands,
414 const unsigned char *operands,
415 expressionS *operand_values,
416 char *bundle_start)
418 int i;
420 for (i = 0; i < num_operands; i++)
422 const struct tilepro_operand *operand =
423 &tilepro_operands[operands[i]];
424 expressionS *operand_exp = &operand_values[i];
425 int is_pc_relative = operand->is_pc_relative;
427 if (operand_exp->X_op == O_register
428 || (operand_exp->X_op == O_constant && !is_pc_relative))
430 /* We know what the bits are right now, so insert them. */
431 bits = insert_operand (bits, operand, operand_exp->X_add_number,
432 NULL, 0);
434 else
436 bfd_reloc_code_real_type reloc = operand->default_reloc;
437 expressionS subexp;
438 int die = 0, use_subexp = 0, require_symbol = 0;
439 fixS *fixP;
441 /* Take an expression like hi16(x) and turn it into x with
442 a different reloc type. */
443 switch (operand_exp->X_op)
445 #define HANDLE_OP16(suffix) \
446 switch (reloc) \
448 case BFD_RELOC_TILEPRO_IMM16_X0: \
449 reloc = BFD_RELOC_TILEPRO_IMM16_X0_##suffix; \
450 break; \
451 case BFD_RELOC_TILEPRO_IMM16_X1: \
452 reloc = BFD_RELOC_TILEPRO_IMM16_X1_##suffix; \
453 break; \
454 default: \
455 die = 1; \
456 break; \
458 use_subexp = 1
460 case O_lo16:
461 HANDLE_OP16 (LO);
462 break;
464 case O_hi16:
465 HANDLE_OP16 (HI);
466 break;
468 case O_ha16:
469 HANDLE_OP16 (HA);
470 break;
472 case O_got:
473 HANDLE_OP16 (GOT);
474 require_symbol = 1;
475 break;
477 case O_got_lo16:
478 HANDLE_OP16 (GOT_LO);
479 require_symbol = 1;
480 break;
482 case O_got_hi16:
483 HANDLE_OP16 (GOT_HI);
484 require_symbol = 1;
485 break;
487 case O_got_ha16:
488 HANDLE_OP16 (GOT_HA);
489 require_symbol = 1;
490 break;
492 case O_tls_gd:
493 HANDLE_OP16 (TLS_GD);
494 require_symbol = 1;
495 break;
497 case O_tls_gd_lo16:
498 HANDLE_OP16 (TLS_GD_LO);
499 require_symbol = 1;
500 break;
502 case O_tls_gd_hi16:
503 HANDLE_OP16 (TLS_GD_HI);
504 require_symbol = 1;
505 break;
507 case O_tls_gd_ha16:
508 HANDLE_OP16 (TLS_GD_HA);
509 require_symbol = 1;
510 break;
512 case O_tls_ie:
513 HANDLE_OP16 (TLS_IE);
514 require_symbol = 1;
515 break;
517 case O_tls_ie_lo16:
518 HANDLE_OP16 (TLS_IE_LO);
519 require_symbol = 1;
520 break;
522 case O_tls_ie_hi16:
523 HANDLE_OP16 (TLS_IE_HI);
524 require_symbol = 1;
525 break;
527 case O_tls_ie_ha16:
528 HANDLE_OP16 (TLS_IE_HA);
529 require_symbol = 1;
530 break;
532 case O_tls_le:
533 HANDLE_OP16 (TLS_LE);
534 require_symbol = 1;
535 break;
537 case O_tls_le_lo16:
538 HANDLE_OP16 (TLS_LE_LO);
539 require_symbol = 1;
540 break;
542 case O_tls_le_hi16:
543 HANDLE_OP16 (TLS_LE_HI);
544 require_symbol = 1;
545 break;
547 case O_tls_le_ha16:
548 HANDLE_OP16 (TLS_LE_HA);
549 require_symbol = 1;
550 break;
552 #undef HANDLE_OP16
554 case O_plt:
555 switch (reloc)
557 case BFD_RELOC_TILEPRO_JOFFLONG_X1:
558 reloc = BFD_RELOC_TILEPRO_JOFFLONG_X1_PLT;
559 break;
560 default:
561 die = 1;
562 break;
564 use_subexp = 1;
565 require_symbol = 1;
566 break;
568 case O_tls_gd_call:
569 switch (reloc)
571 case BFD_RELOC_TILEPRO_JOFFLONG_X1:
572 reloc = BFD_RELOC_TILEPRO_TLS_GD_CALL;
573 break;
574 default:
575 die = 1;
576 break;
578 use_subexp = 1;
579 require_symbol = 1;
580 break;
582 case O_tls_gd_add:
583 switch (reloc)
585 case BFD_RELOC_TILEPRO_IMM8_X0:
586 reloc = BFD_RELOC_TILEPRO_IMM8_X0_TLS_GD_ADD;
587 break;
588 case BFD_RELOC_TILEPRO_IMM8_X1:
589 reloc = BFD_RELOC_TILEPRO_IMM8_X1_TLS_GD_ADD;
590 break;
591 case BFD_RELOC_TILEPRO_IMM8_Y0:
592 reloc = BFD_RELOC_TILEPRO_IMM8_Y0_TLS_GD_ADD;
593 break;
594 case BFD_RELOC_TILEPRO_IMM8_Y1:
595 reloc = BFD_RELOC_TILEPRO_IMM8_Y1_TLS_GD_ADD;
596 break;
597 default:
598 die = 1;
599 break;
601 use_subexp = 1;
602 require_symbol = 1;
603 break;
605 case O_tls_ie_load:
606 switch (reloc)
608 case BFD_RELOC_TILEPRO_IMM8_X1:
609 reloc = BFD_RELOC_TILEPRO_TLS_IE_LOAD;
610 break;
611 default:
612 die = 1;
613 break;
615 use_subexp = 1;
616 require_symbol = 1;
617 break;
619 default:
620 /* Do nothing. */
621 break;
624 if (die)
626 as_bad (_("Invalid operator for operand."));
628 else if (use_subexp)
630 expressionS *sval = NULL;
631 /* Now that we've changed the reloc, change ha16(x) into x,
632 etc. */
634 if (symbol_symbolS (operand_exp->X_add_symbol))
635 sval = symbol_get_value_expression (operand_exp->X_add_symbol);
636 if (sval && sval->X_md)
638 /* HACK: We used X_md to mark this symbol as a fake wrapper
639 around a real expression. To unwrap it, we just grab its
640 value here. */
641 operand_exp = sval;
643 if (require_symbol)
645 /* Look at the expression, and reject it if it's not a
646 plain symbol. */
647 if (operand_exp->X_op != O_symbol
648 || operand_exp->X_add_number != 0)
649 as_bad (_("Operator may only be applied to symbols."));
652 else
654 /* The value of this expression is an actual symbol, so
655 turn that into an expression. */
656 memset (&subexp, 0, sizeof subexp);
657 subexp.X_op = O_symbol;
658 subexp.X_add_symbol = operand_exp->X_add_symbol;
659 operand_exp = &subexp;
663 /* Create a fixup to handle this later. */
664 fixP = fix_new_exp (frag_now,
665 bundle_start - frag_now->fr_literal,
666 (operand->num_bits + 7) >> 3,
667 operand_exp,
668 is_pc_relative,
669 reloc);
670 fixP->tc_fix_data = operand;
672 /* Don't do overflow checking if we are applying a function like
673 ha16. */
674 fixP->fx_no_overflow |= use_subexp;
677 return bits;
681 /* Detects and complains if two instructions in current_bundle write
682 to the same register, either implicitly or explicitly, or if a
683 read-only register is written. */
684 static void
685 check_illegal_reg_writes (void)
687 BFD_HOST_U_64_BIT all_regs_written = 0;
688 int j;
690 for (j = 0; j < current_bundle_index; j++)
692 const struct tilepro_instruction *instr = &current_bundle[j];
693 int k;
694 BFD_HOST_U_64_BIT regs =
695 ((BFD_HOST_U_64_BIT)1) << instr->opcode->implicitly_written_register;
696 BFD_HOST_U_64_BIT conflict;
698 for (k = 0; k < instr->opcode->num_operands; k++)
700 const struct tilepro_operand *operand =
701 &tilepro_operands[instr->opcode->operands[instr->pipe][k]];
703 if (operand->is_dest_reg)
705 int regno = instr->operand_values[k].X_add_number;
706 BFD_HOST_U_64_BIT mask = ((BFD_HOST_U_64_BIT)1) << regno;
708 if ((mask & ( (((BFD_HOST_U_64_BIT)1) << TREG_IDN1)
709 | (((BFD_HOST_U_64_BIT)1) << TREG_UDN1)
710 | (((BFD_HOST_U_64_BIT)1) << TREG_UDN2)
711 | (((BFD_HOST_U_64_BIT)1) << TREG_UDN3))) != 0
712 && !allow_suspicious_bundles)
714 as_bad (_("Writes to register '%s' are not allowed."),
715 tilepro_register_names[regno]);
718 regs |= mask;
722 /* Writing to the zero register doesn't count. */
723 regs &= ~(((BFD_HOST_U_64_BIT)1) << TREG_ZERO);
725 conflict = all_regs_written & regs;
726 if (conflict != 0 && !allow_suspicious_bundles)
728 /* Find which register caused the conflict. */
729 const char *conflicting_reg_name = "???";
730 int i;
732 for (i = 0; i < TILEPRO_NUM_REGISTERS; i++)
734 if (((conflict >> i) & 1) != 0)
736 conflicting_reg_name = tilepro_register_names[i];
737 break;
741 as_bad (_("Two instructions in the same bundle both write "
742 "to register %s, which is not allowed."),
743 conflicting_reg_name);
746 all_regs_written |= regs;
751 static void
752 tilepro_flush_bundle (void)
754 unsigned i;
755 int j, addr_mod;
756 unsigned compatible_pipes;
757 const struct bundle_template *match;
758 char *f;
760 inside_bundle = 0;
762 switch (current_bundle_index)
764 case 0:
765 /* No instructions. */
766 return;
767 case 1:
768 if (current_bundle[0].opcode->can_bundle)
770 /* Simplify later logic by adding an explicit fnop. */
771 prepend_nop_to_bundle (TILEPRO_OPC_FNOP);
773 else
775 /* This instruction cannot be bundled with anything else.
776 Prepend an explicit 'nop', rather than an 'fnop', because
777 fnops can be replaced by later binary-processing tools
778 while nops cannot. */
779 prepend_nop_to_bundle (TILEPRO_OPC_NOP);
781 break;
782 default:
783 if (!allow_suspicious_bundles)
785 /* Make sure all instructions can be bundled with other
786 instructions. */
787 const struct tilepro_opcode *cannot_bundle = NULL;
788 bfd_boolean seen_non_nop = FALSE;
790 for (j = 0; j < current_bundle_index; j++)
792 const struct tilepro_opcode *op = current_bundle[j].opcode;
794 if (!op->can_bundle && cannot_bundle == NULL)
795 cannot_bundle = op;
796 else if (op->mnemonic != TILEPRO_OPC_NOP
797 && op->mnemonic != TILEPRO_OPC_INFO
798 && op->mnemonic != TILEPRO_OPC_INFOL)
799 seen_non_nop = TRUE;
802 if (cannot_bundle != NULL && seen_non_nop)
804 current_bundle_index = 0;
805 as_bad (_("'%s' may not be bundled with other instructions."),
806 cannot_bundle->name);
807 return;
810 break;
813 compatible_pipes =
814 BUNDLE_TEMPLATE_MASK(current_bundle[0].opcode->pipes,
815 current_bundle[1].opcode->pipes,
816 (current_bundle_index == 3
817 ? current_bundle[2].opcode->pipes
818 : (1 << NO_PIPELINE)));
820 /* Find a template that works, if any. */
821 match = NULL;
822 for (i = 0; i < sizeof bundle_templates / sizeof bundle_templates[0]; i++)
824 const struct bundle_template *b = &bundle_templates[i];
825 if ((b->pipe_mask & compatible_pipes) == b->pipe_mask)
827 match = b;
828 break;
832 if (match == NULL)
834 current_bundle_index = 0;
835 as_bad (_("Invalid combination of instructions for bundle."));
836 return;
839 /* If the section seems to have no alignment set yet, go ahead and
840 make it large enough to hold code. */
841 if (bfd_get_section_alignment (stdoutput, now_seg) == 0)
842 bfd_set_section_alignment (stdoutput, now_seg,
843 TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
845 for (j = 0; j < current_bundle_index; j++)
846 current_bundle[j].pipe = match->pipe[j];
848 if (current_bundle_index == 2 && !tilepro_is_x_pipeline(match->pipe[0]))
850 /* We are in Y mode with only two instructions, so add an FNOP. */
851 prepend_nop_to_bundle (TILEPRO_OPC_FNOP);
853 /* Figure out what pipe the fnop must be in via arithmetic.
854 * p0 + p1 + p2 must sum to the sum of TILEPRO_PIPELINE_Y[012]. */
855 current_bundle[0].pipe =
856 (tilepro_pipeline)((TILEPRO_PIPELINE_Y0
857 + TILEPRO_PIPELINE_Y1
858 + TILEPRO_PIPELINE_Y2) -
859 (current_bundle[1].pipe + current_bundle[2].pipe));
862 check_illegal_reg_writes ();
864 f = frag_more (TILEPRO_BUNDLE_SIZE_IN_BYTES);
866 /* Check to see if this bundle is at an offset that is a multiple of 8-bytes
867 from the start of the frag. */
868 addr_mod = frag_now_fix () & (TILEPRO_BUNDLE_ALIGNMENT_IN_BYTES - 1);
869 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
870 as_bad (_("instruction address is not a multiple of 8"));
871 frag_now->insn_addr = addr_mod;
872 frag_now->has_code = 1;
874 tilepro_bundle_bits bits = 0;
875 for (j = 0; j < current_bundle_index; j++)
877 struct tilepro_instruction *instr = &current_bundle[j];
878 tilepro_pipeline pipeline = instr->pipe;
879 const struct tilepro_opcode *opcode = instr->opcode;
881 bits |= emit_tilepro_instruction (opcode->fixed_bit_values[pipeline],
882 opcode->num_operands,
883 &opcode->operands[pipeline][0],
884 instr->operand_values,
888 number_to_chars_littleendian (f, (unsigned int)bits, 4);
889 number_to_chars_littleendian (f + 4, (unsigned int)(bits >> 32), 4);
890 current_bundle_index = 0;
892 /* Emit DWARF2 debugging information. */
893 dwarf2_emit_insn (TILEPRO_BUNDLE_SIZE_IN_BYTES);
897 /* Extend the expression parser to handle hi16(label), etc.
898 as well as SPR names when in the context of parsing an SPR. */
900 tilepro_parse_name (char *name, expressionS *e, char *nextcharP)
902 operatorT op = O_illegal;
904 if (parsing_spr)
906 void *val = hash_find (spr_hash, name);
907 if (val == NULL)
908 return 0;
910 memset (e, 0, sizeof *e);
911 e->X_op = O_constant;
912 e->X_add_number = ((const struct tilepro_spr *)val)->number;
913 return 1;
916 if (*nextcharP != '(')
918 /* hi16, etc. not followed by a paren is just a label with that
919 name. */
920 return 0;
922 else
924 /* Look up the operator in our table. */
925 void *val = hash_find (special_operator_hash, name);
926 if (val == 0)
927 return 0;
928 op = (operatorT)(long)val;
931 /* Restore old '(' and skip it. */
932 *input_line_pointer = '(';
933 ++input_line_pointer;
935 expression (e);
937 if (*input_line_pointer != ')')
939 as_bad (_("Missing ')'"));
940 *nextcharP = *input_line_pointer;
941 return 0;
943 /* Skip ')'. */
944 ++input_line_pointer;
946 if (e->X_op == O_register || e->X_op == O_absent)
948 as_bad (_("Invalid expression."));
949 e->X_op = O_constant;
950 e->X_add_number = 0;
952 else
954 /* Wrap subexpression with a unary operator. */
955 symbolS *sym = make_expr_symbol (e);
957 if (sym != e->X_add_symbol)
959 /* HACK: mark this symbol as a temporary wrapper around a proper
960 expression, so we can unwrap it later once we have communicated
961 the relocation type. */
962 symbol_get_value_expression (sym)->X_md = 1;
965 memset (e, 0, sizeof *e);
966 e->X_op = op;
967 e->X_add_symbol = sym;
968 e->X_add_number = 0;
971 *nextcharP = *input_line_pointer;
972 return 1;
976 /* Parses an expression which must be a register name. */
978 static void
979 parse_reg_expression (expressionS* expression)
981 /* Zero everything to make sure we don't miss any flags. */
982 memset (expression, 0, sizeof *expression);
984 char *regname;
985 char terminating_char = get_symbol_name (&regname);
987 void* pval = hash_find (main_reg_hash, regname);
989 if (pval == NULL)
990 as_bad (_("Expected register, got '%s'."), regname);
992 int regno_and_flags = (int)(size_t)pval;
993 int regno = EXTRACT_REGNO(regno_and_flags);
995 if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG)
996 && require_canonical_reg_names)
997 as_warn (_("Found use of non-canonical register name %s; "
998 "use %s instead."),
999 regname, tilepro_register_names[regno]);
1001 /* Restore the old character following the register name. */
1002 (void) restore_line_pointer (terminating_char);
1004 /* Fill in the expression fields to indicate it's a register. */
1005 expression->X_op = O_register;
1006 expression->X_add_number = regno;
1010 /* Parses and type-checks comma-separated operands in input_line_pointer. */
1011 static void
1012 parse_operands (const char *opcode_name,
1013 const unsigned char *operands,
1014 int num_operands,
1015 expressionS *operand_values)
1017 int i;
1019 memset (operand_values, 0, num_operands * sizeof operand_values[0]);
1021 SKIP_WHITESPACE ();
1022 for (i = 0; i < num_operands; i++)
1024 tilepro_operand_type type = tilepro_operands[operands[i]].type;
1026 SKIP_WHITESPACE ();
1028 if (type == TILEPRO_OP_TYPE_REGISTER)
1030 parse_reg_expression (&operand_values[i]);
1032 else if (*input_line_pointer == '}')
1034 operand_values[i].X_op = O_absent;
1036 else if (type == TILEPRO_OP_TYPE_SPR)
1038 /* Modify the expression parser to add SPRs to the namespace. */
1039 parsing_spr = 1;
1040 expression (&operand_values[i]);
1041 parsing_spr = 0;
1043 else
1045 expression (&operand_values[i]);
1048 SKIP_WHITESPACE ();
1050 if (i + 1 < num_operands)
1052 int separator = (unsigned char)*input_line_pointer++;
1054 if (is_end_of_line[separator] || (separator == '}'))
1056 as_bad (_("Too few operands to '%s'."), opcode_name);
1057 return;
1059 else if (separator != ',')
1061 as_bad (_("Unexpected character '%c' after operand %d to %s."),
1062 (char)separator, i + 1, opcode_name);
1063 return;
1067 /* Arbitrarily use the first valid pipe to get the operand type,
1068 since they are all the same. */
1069 switch (tilepro_operands[operands[i]].type)
1071 case TILEPRO_OP_TYPE_REGISTER:
1072 /* Handled in parse_reg_expression already. */
1073 break;
1074 case TILEPRO_OP_TYPE_SPR:
1075 /* Fall through */
1076 case TILEPRO_OP_TYPE_IMMEDIATE:
1077 /* Fall through */
1078 case TILEPRO_OP_TYPE_ADDRESS:
1079 if ( operand_values[i].X_op == O_register
1080 || operand_values[i].X_op == O_illegal
1081 || operand_values[i].X_op == O_absent)
1082 as_bad (_("Expected immediate expression"));
1083 break;
1084 default:
1085 abort ();
1089 if (!is_end_of_line[(unsigned char)*input_line_pointer])
1091 switch (*input_line_pointer)
1093 case '}':
1094 if (!inside_bundle)
1095 as_bad (_("Found '}' when not bundling."));
1096 ++input_line_pointer;
1097 inside_bundle = 0;
1098 demand_empty_rest_of_line ();
1099 break;
1101 case ',':
1102 as_bad (_("Too many operands"));
1103 break;
1105 default:
1106 /* Use default error for unrecognized garbage. */
1107 demand_empty_rest_of_line ();
1108 break;
1114 /* This is the guts of the machine-dependent assembler. STR points to a
1115 machine dependent instruction. This function is supposed to emit
1116 the frags/bytes it assembles to. */
1117 void
1118 md_assemble (char *str)
1120 char old_char;
1121 size_t opname_len;
1122 char *old_input_line_pointer;
1123 const struct tilepro_opcode *op;
1124 int first_pipe;
1126 /* Split off the opcode and look it up. */
1127 opname_len = strcspn (str, " {}");
1128 old_char = str[opname_len];
1129 str[opname_len] = '\0';
1131 op = hash_find(op_hash, str);
1132 str[opname_len] = old_char;
1133 if (op == NULL)
1135 as_bad (_("Unknown opcode `%.*s'."), (int)opname_len, str);
1136 return;
1139 /* Prepare to parse the operands. */
1140 old_input_line_pointer = input_line_pointer;
1141 input_line_pointer = str + opname_len;
1142 SKIP_WHITESPACE ();
1144 if (current_bundle_index == TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE)
1146 as_bad (_("Too many instructions for bundle."));
1147 tilepro_flush_bundle ();
1150 /* Make sure we have room for the upcoming bundle before we
1151 create any fixups. Otherwise if we have to switch to a new
1152 frag the fixup dot_value fields will be wrong. */
1153 frag_grow (TILEPRO_BUNDLE_SIZE_IN_BYTES);
1155 /* Find a valid pipe for this opcode. */
1156 for (first_pipe = 0; (op->pipes & (1 << first_pipe)) == 0; first_pipe++)
1159 /* Call the function that assembles this instruction. */
1160 current_bundle[current_bundle_index].opcode = op;
1161 parse_operands (op->name,
1162 &op->operands[first_pipe][0],
1163 op->num_operands,
1164 current_bundle[current_bundle_index].operand_values);
1165 ++current_bundle_index;
1167 /* Restore the saved value of input_line_pointer. */
1168 input_line_pointer = old_input_line_pointer;
1170 /* If we weren't inside curly braces, go ahead and emit
1171 this lone instruction as a bundle right now. */
1172 if (!inside_bundle)
1173 tilepro_flush_bundle ();
1176 static void
1177 s_require_canonical_reg_names (int require)
1179 demand_empty_rest_of_line ();
1180 require_canonical_reg_names = require;
1183 static void
1184 s_allow_suspicious_bundles (int allow)
1186 demand_empty_rest_of_line ();
1187 allow_suspicious_bundles = allow;
1190 const pseudo_typeS md_pseudo_table[] =
1192 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0). */
1193 {"word", cons, 4},
1194 {"require_canonical_reg_names", s_require_canonical_reg_names, 1 },
1195 {"no_require_canonical_reg_names", s_require_canonical_reg_names, 0 },
1196 {"allow_suspicious_bundles", s_allow_suspicious_bundles, 1 },
1197 {"no_allow_suspicious_bundles", s_allow_suspicious_bundles, 0 },
1198 { NULL, 0, 0 }
1201 /* Turn the string pointed to by litP into a floating point constant
1202 of type TYPE, and emit the appropriate bytes. The number of
1203 LITTLENUMS emitted is stored in *SIZEP. An error message is
1204 returned, or NULL on OK. */
1206 const char *
1207 md_atof (int type, char *litP, int *sizeP)
1209 int prec;
1210 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1211 LITTLENUM_TYPE *wordP;
1212 char *t;
1214 switch (type)
1216 case 'f':
1217 case 'F':
1218 prec = 2;
1219 break;
1221 case 'd':
1222 case 'D':
1223 prec = 4;
1224 break;
1226 default:
1227 *sizeP = 0;
1228 return _("Bad call to md_atof ()");
1230 t = atof_ieee (input_line_pointer, type, words);
1231 if (t)
1232 input_line_pointer = t;
1234 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1235 /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
1236 the bigendian 386. */
1237 for (wordP = words + prec - 1; prec--;)
1239 md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
1240 litP += sizeof (LITTLENUM_TYPE);
1242 return 0;
1246 /* We have no need to default values of symbols. */
1248 symbolS *
1249 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1251 return NULL;
1255 void
1256 tilepro_cons_fix_new (fragS *frag,
1257 int where,
1258 int nbytes,
1259 expressionS *exp)
1261 expressionS subexp;
1262 bfd_reloc_code_real_type reloc = BFD_RELOC_NONE;
1263 int no_overflow = 0;
1264 fixS *fixP;
1266 /* See if it's one of our special functions. */
1267 switch (exp->X_op)
1269 case O_lo16:
1270 reloc = BFD_RELOC_LO16;
1271 no_overflow = 1;
1272 break;
1273 case O_hi16:
1274 reloc = BFD_RELOC_HI16;
1275 no_overflow = 1;
1276 break;
1277 case O_ha16:
1278 reloc = BFD_RELOC_HI16_S;
1279 no_overflow = 1;
1280 break;
1282 default:
1283 /* Do nothing. */
1284 break;
1287 if (reloc != BFD_RELOC_NONE)
1289 if (nbytes != 2)
1291 as_bad (_("This operator only produces two byte values."));
1292 nbytes = 2;
1295 memset (&subexp, 0, sizeof subexp);
1296 subexp.X_op = O_symbol;
1297 subexp.X_add_symbol = exp->X_add_symbol;
1298 exp = &subexp;
1300 else
1302 switch (nbytes)
1304 case 1:
1305 reloc = BFD_RELOC_8;
1306 break;
1307 case 2:
1308 reloc = BFD_RELOC_16;
1309 break;
1310 case 4:
1311 reloc = BFD_RELOC_32;
1312 break;
1313 case 8:
1314 reloc = BFD_RELOC_64;
1315 break;
1316 default:
1317 as_bad (_("unsupported BFD relocation size %d"), nbytes);
1318 reloc = BFD_RELOC_32;
1319 break;
1323 fixP = fix_new_exp (frag, where, nbytes, exp, 0, reloc);
1324 fixP->tc_fix_data = NULL;
1325 fixP->fx_no_overflow |= no_overflow;
1329 void
1330 md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
1332 const struct tilepro_operand *operand;
1333 valueT value = *valP;
1334 char *p;
1336 /* Leave these for the linker. */
1337 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
1338 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1339 return;
1341 if (fixP->fx_subsy != (symbolS *) NULL)
1343 /* We can't actually support subtracting a symbol. */
1344 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
1347 /* Correct relocation types for pc-relativeness. */
1348 switch (fixP->fx_r_type)
1350 #define FIX_PCREL(rtype) \
1351 case rtype: \
1352 if (fixP->fx_pcrel) \
1353 fixP->fx_r_type = rtype##_PCREL; \
1354 break; \
1356 case rtype##_PCREL: \
1357 if (!fixP->fx_pcrel) \
1358 fixP->fx_r_type = rtype; \
1359 break
1361 FIX_PCREL (BFD_RELOC_8);
1362 FIX_PCREL (BFD_RELOC_16);
1363 FIX_PCREL (BFD_RELOC_32);
1364 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0);
1365 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1);
1366 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0_LO);
1367 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1_LO);
1368 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0_HI);
1369 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1_HI);
1370 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0_HA);
1371 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1_HA);
1373 #undef FIX_PCREL
1375 default:
1376 /* Do nothing */
1377 break;
1380 if (fixP->fx_addsy != NULL)
1382 #ifdef OBJ_ELF
1383 switch (fixP->fx_r_type)
1385 case BFD_RELOC_TILEPRO_IMM8_X0_TLS_GD_ADD:
1386 case BFD_RELOC_TILEPRO_IMM8_X1_TLS_GD_ADD:
1387 case BFD_RELOC_TILEPRO_IMM8_Y0_TLS_GD_ADD:
1388 case BFD_RELOC_TILEPRO_IMM8_Y1_TLS_GD_ADD:
1389 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD:
1390 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD:
1391 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_LO:
1392 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_LO:
1393 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HI:
1394 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HI:
1395 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HA:
1396 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HA:
1397 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE:
1398 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE:
1399 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_LO:
1400 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_LO:
1401 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HI:
1402 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HI:
1403 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HA:
1404 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HA:
1405 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE:
1406 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE:
1407 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_LO:
1408 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_LO:
1409 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_HI:
1410 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_HI:
1411 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_HA:
1412 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_HA:
1413 case BFD_RELOC_TILEPRO_TLS_GD_CALL:
1414 case BFD_RELOC_TILEPRO_TLS_IE_LOAD:
1415 case BFD_RELOC_TILEPRO_TLS_DTPMOD32:
1416 case BFD_RELOC_TILEPRO_TLS_DTPOFF32:
1417 case BFD_RELOC_TILEPRO_TLS_TPOFF32:
1418 S_SET_THREAD_LOCAL (fixP->fx_addsy);
1419 break;
1421 default:
1422 /* Do nothing */
1423 break;
1425 #endif
1426 return;
1429 /* Apply lo16, hi16, ha16, etc. munging. */
1430 switch (fixP->fx_r_type)
1432 case BFD_RELOC_LO16:
1433 case BFD_RELOC_TILEPRO_IMM16_X0_LO:
1434 case BFD_RELOC_TILEPRO_IMM16_X1_LO:
1435 case BFD_RELOC_TILEPRO_IMM16_X0_LO_PCREL:
1436 case BFD_RELOC_TILEPRO_IMM16_X1_LO_PCREL:
1437 *valP = value = apply_special_operator (O_lo16, value);
1438 break;
1440 case BFD_RELOC_HI16:
1441 case BFD_RELOC_TILEPRO_IMM16_X0_HI:
1442 case BFD_RELOC_TILEPRO_IMM16_X1_HI:
1443 case BFD_RELOC_TILEPRO_IMM16_X0_HI_PCREL:
1444 case BFD_RELOC_TILEPRO_IMM16_X1_HI_PCREL:
1445 *valP = value = apply_special_operator (O_hi16, value);
1446 break;
1448 case BFD_RELOC_HI16_S:
1449 case BFD_RELOC_TILEPRO_IMM16_X0_HA:
1450 case BFD_RELOC_TILEPRO_IMM16_X1_HA:
1451 case BFD_RELOC_TILEPRO_IMM16_X0_HA_PCREL:
1452 case BFD_RELOC_TILEPRO_IMM16_X1_HA_PCREL:
1453 *valP = value = apply_special_operator (O_ha16, value);
1454 break;
1456 default:
1457 /* Do nothing */
1458 break;
1461 p = fixP->fx_frag->fr_literal + fixP->fx_where;
1463 operand = fixP->tc_fix_data;
1464 if (operand != NULL)
1466 /* It's an instruction operand. */
1467 tilepro_bundle_bits bits =
1468 insert_operand (0, operand, value, fixP->fx_file, fixP->fx_line);
1470 /* Note that we might either be writing out bits for a bundle or a
1471 static network instruction, which are different sizes, so it's
1472 important to stop touching memory once we run out of bits. ORing in
1473 values is OK since we know the existing bits for this operand are
1474 zero. */
1475 for (; bits != 0; bits >>= 8)
1476 *p++ |= (char)bits;
1478 else
1480 /* Some other kind of relocation. */
1481 switch (fixP->fx_r_type)
1483 case BFD_RELOC_8:
1484 case BFD_RELOC_8_PCREL:
1485 md_number_to_chars (p, value, 1);
1486 break;
1488 case BFD_RELOC_16:
1489 case BFD_RELOC_16_PCREL:
1490 md_number_to_chars (p, value, 2);
1491 break;
1493 case BFD_RELOC_32:
1494 case BFD_RELOC_32_PCREL:
1495 md_number_to_chars (p, value, 4);
1496 break;
1498 default:
1499 /* Leave it for the linker. */
1500 return;
1504 fixP->fx_done = 1;
1508 /* Generate the BFD reloc to be stuck in the object file from the
1509 fixup used internally in the assembler. */
1511 arelent *
1512 tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp)
1514 arelent *reloc;
1516 reloc = XNEW (arelent);
1517 reloc->sym_ptr_ptr = XNEW (asymbol *);
1518 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1519 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1521 /* Make sure none of our internal relocations make it this far.
1522 They'd better have been fully resolved by this point. */
1523 gas_assert ((int) fixp->fx_r_type > 0);
1525 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1526 if (reloc->howto == NULL)
1528 as_bad_where (fixp->fx_file, fixp->fx_line,
1529 _("cannot represent `%s' relocation in object file"),
1530 bfd_get_reloc_code_name (fixp->fx_r_type));
1531 return NULL;
1534 if (!fixp->fx_pcrel != !reloc->howto->pc_relative)
1536 as_fatal (_("internal error? cannot generate `%s' relocation (%d, %d)"),
1537 bfd_get_reloc_code_name (fixp->fx_r_type),
1538 fixp->fx_pcrel, reloc->howto->pc_relative);
1540 gas_assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
1542 reloc->addend = fixp->fx_offset;
1544 return reloc;
1548 /* The location from which a PC relative jump should be calculated,
1549 given a PC relative reloc. */
1551 long
1552 md_pcrel_from (fixS *fixP)
1554 return fixP->fx_frag->fr_address + fixP->fx_where;
1558 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
1559 a section symbol plus some offset. */
1561 tilepro_fix_adjustable (fixS *fix)
1563 /* Prevent all adjustments to global symbols */
1564 if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
1565 return 0;
1567 return 1;
1572 tilepro_unrecognized_line (int ch)
1574 switch (ch)
1576 case '{':
1577 if (inside_bundle)
1579 as_bad (_("Found '{' when already bundling."));
1581 else
1583 inside_bundle = 1;
1584 current_bundle_index = 0;
1586 return 1;
1588 case '}':
1589 if (!inside_bundle)
1591 as_bad (_("Found '}' when not bundling."));
1593 else
1595 tilepro_flush_bundle ();
1598 /* Allow '{' to follow on the same line. We also allow ";;", but that
1599 happens automatically because ';' is an end of line marker. */
1600 SKIP_WHITESPACE ();
1601 if (input_line_pointer[0] == '{')
1603 input_line_pointer++;
1604 return tilepro_unrecognized_line ('{');
1607 demand_empty_rest_of_line ();
1608 return 1;
1610 default:
1611 break;
1614 /* Not a valid line. */
1615 return 0;
1619 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
1620 of an rs_align_code fragment. */
1622 void
1623 tilepro_handle_align (fragS *fragp)
1625 int bytes, fix;
1626 char *p;
1628 if (fragp->fr_type != rs_align_code)
1629 return;
1631 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
1632 p = fragp->fr_literal + fragp->fr_fix;
1633 fix = 0;
1635 /* Determine the bits for NOP. */
1636 const struct tilepro_opcode *nop_opcode =
1637 &tilepro_opcodes[TILEPRO_OPC_NOP];
1638 tilepro_bundle_bits nop =
1639 ( nop_opcode->fixed_bit_values[TILEPRO_PIPELINE_X0]
1640 | nop_opcode->fixed_bit_values[TILEPRO_PIPELINE_X1]);
1642 if ((bytes & (TILEPRO_BUNDLE_SIZE_IN_BYTES - 1)) != 0)
1644 fix = bytes & (TILEPRO_BUNDLE_SIZE_IN_BYTES - 1);
1645 memset (p, 0, fix);
1646 p += fix;
1647 bytes -= fix;
1650 number_to_chars_littleendian (p, (unsigned int)nop, 4);
1651 number_to_chars_littleendian (p + 4, (unsigned int)(nop >> 32), 4);
1652 fragp->fr_fix += fix;
1653 fragp->fr_var = TILEPRO_BUNDLE_SIZE_IN_BYTES;
1656 /* Standard calling conventions leave the CFA at SP on entry. */
1657 void
1658 tilepro_cfi_frame_initial_instructions (void)
1660 cfi_add_CFA_def_cfa_register (54);
1664 tc_tilepro_regname_to_dw2regnum (char *regname)
1666 int i;
1668 for (i = 0; i < TILEPRO_NUM_REGISTERS; i++)
1670 if (!strcmp (regname, tilepro_register_names[i]))
1671 return i;
1674 return -1;