PR gas/12848
[binutils.git] / gas / config / tc-tilepro.c
blobc198b2c4fa6941e04e63970633e83c1e43290081
1 /* tc-tilepro.c -- Assemble for a TILEPro 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. */
21 #include "as.h"
22 #include "struc-symbol.h"
23 #include "subsegs.h"
25 #include "elf/tilepro.h"
26 #include "opcode/tilepro.h"
28 #include "dwarf2dbg.h"
29 #include "dw2gencfi.h"
31 #include "safe-ctype.h"
34 /* Special registers. */
35 #define TREG_IDN0 57
36 #define TREG_IDN1 58
37 #define TREG_UDN0 59
38 #define TREG_UDN1 60
39 #define TREG_UDN2 61
40 #define TREG_UDN3 62
41 #define TREG_ZERO 63
44 /* Generic assembler global variables which must be defined by all
45 targets. */
47 /* Characters which always start a comment. */
48 const char comment_chars[] = "#";
50 /* Characters which start a comment at the beginning of a line. */
51 const char line_comment_chars[] = "#";
53 /* Characters which may be used to separate multiple commands on a
54 single line. */
55 const char line_separator_chars[] = ";";
57 /* Characters which are used to indicate an exponent in a floating
58 point number. */
59 const char EXP_CHARS[] = "eE";
61 /* Characters which mean that a number is a floating point constant,
62 as in 0d1.0. */
63 const char FLT_CHARS[] = "rRsSfFdDxXpP";
65 const char *md_shortopts = "VQ:";
67 struct option md_longopts[] =
69 {NULL, no_argument, NULL, 0}
72 size_t md_longopts_size = sizeof (md_longopts);
74 int
75 md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
77 switch (c)
79 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
80 should be emitted or not. FIXME: Not implemented. */
81 case 'Q':
82 break;
84 /* -V: SVR4 argument to print version ID. */
85 case 'V':
86 print_version_id ();
87 break;
89 default:
90 return 0;
93 return 1;
96 void
97 md_show_usage (FILE *stream)
99 fprintf (stream, _("\
100 -Q ignored\n\
101 -V print assembler version number\n"));
104 /* Extra expression types. */
106 #define O_lo16 O_md1
107 #define O_hi16 O_md2
108 #define O_ha16 O_md3
109 #define O_got O_md4
110 #define O_got_lo16 O_md5
111 #define O_got_hi16 O_md6
112 #define O_got_ha16 O_md7
113 #define O_plt O_md8
114 #define O_tls_gd O_md9
115 #define O_tls_gd_lo16 O_md10
116 #define O_tls_gd_hi16 O_md11
117 #define O_tls_gd_ha16 O_md12
118 #define O_tls_ie O_md13
119 #define O_tls_ie_lo16 O_md14
120 #define O_tls_ie_hi16 O_md15
121 #define O_tls_ie_ha16 O_md16
123 static struct hash_control *special_operator_hash;
125 /* Hash tables for instruction mnemonic lookup. */
126 static struct hash_control *op_hash;
128 /* Hash table for spr lookup. */
129 static struct hash_control *spr_hash;
131 /* True temporarily while parsing an SPR expression. This changes the
132 * namespace to include SPR names. */
133 static int parsing_spr;
135 /* Are we currently inside `{ ... }'? */
136 static int inside_bundle;
138 struct tilepro_instruction
140 const struct tilepro_opcode *opcode;
141 tilepro_pipeline pipe;
142 expressionS operand_values[TILEPRO_MAX_OPERANDS];
145 /* This keeps track of the current bundle being built up. */
146 static struct tilepro_instruction
147 current_bundle[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
149 /* Index in current_bundle for the next instruction to parse. */
150 static int current_bundle_index;
152 /* Allow 'r63' in addition to 'zero', etc. Normally we disallow this as
153 'zero' is not a real register, so using it accidentally would be a
154 nasty bug. For other registers, such as 'sp', code using multiple names
155 for the same physical register is excessively confusing.
157 The '.require_canonical_reg_names' pseudo-op turns this error on,
158 and the '.no_require_canonical_reg_names' pseudo-op turns this off.
159 By default the error is on. */
160 static int require_canonical_reg_names;
162 /* Allow bundles that do undefined or suspicious things like write
163 two different values to the same register at the same time.
165 The '.no_allow_suspicious_bundles' pseudo-op turns this error on,
166 and the '.allow_suspicious_bundles' pseudo-op turns this off. */
167 static int allow_suspicious_bundles;
170 /* A hash table of main processor registers, mapping each register name
171 to its index.
173 Furthermore, if the register number is greater than the number
174 of registers for that processor, the user used an illegal alias
175 for that register (e.g. r63 instead of zero), so we should generate
176 a warning. The attempted register number can be found by clearing
177 NONCANONICAL_REG_NAME_FLAG. */
178 static struct hash_control *main_reg_hash;
181 /* We cannot unambiguously store a 0 in a hash table and look it up,
182 so we OR in this flag to every canonical register. */
183 #define CANONICAL_REG_NAME_FLAG 0x1000
185 /* By default we disallow register aliases like r63, but we record
186 them in the hash table in case the .no_require_canonical_reg_names
187 directive is used. Noncanonical names have this value added to them. */
188 #define NONCANONICAL_REG_NAME_FLAG 0x2000
190 /* Discards flags for register hash table entries and returns the
191 reg number. */
192 #define EXTRACT_REGNO(p) ((p) & 63)
194 /* This function is called once, at assembler startup time. It should
195 set up all the tables, etc., that the MD part of the assembler will
196 need. */
197 void
198 md_begin (void)
200 const struct tilepro_opcode *op;
201 int i;
203 /* Guarantee text section is aligned. */
204 bfd_set_section_alignment (stdoutput, text_section,
205 TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
207 require_canonical_reg_names = 1;
208 allow_suspicious_bundles = 0;
209 current_bundle_index = 0;
210 inside_bundle = 0;
212 /* Initialize special operator hash table. */
213 special_operator_hash = hash_new ();
214 #define INSERT_SPECIAL_OP(name) \
215 hash_insert (special_operator_hash, #name, (void *)O_##name)
217 INSERT_SPECIAL_OP(lo16);
218 INSERT_SPECIAL_OP(hi16);
219 INSERT_SPECIAL_OP(ha16);
220 INSERT_SPECIAL_OP(got);
221 INSERT_SPECIAL_OP(got_lo16);
222 INSERT_SPECIAL_OP(got_hi16);
223 INSERT_SPECIAL_OP(got_ha16);
224 INSERT_SPECIAL_OP(plt);
225 INSERT_SPECIAL_OP(tls_gd);
226 INSERT_SPECIAL_OP(tls_gd_lo16);
227 INSERT_SPECIAL_OP(tls_gd_hi16);
228 INSERT_SPECIAL_OP(tls_gd_ha16);
229 INSERT_SPECIAL_OP(tls_ie);
230 INSERT_SPECIAL_OP(tls_ie_lo16);
231 INSERT_SPECIAL_OP(tls_ie_hi16);
232 INSERT_SPECIAL_OP(tls_ie_ha16);
233 #undef INSERT_SPECIAL_OP
235 /* Initialize op_hash hash table. */
236 op_hash = hash_new ();
237 for (op = &tilepro_opcodes[0]; op->name != NULL; op++)
239 const char *hash_err = hash_insert (op_hash, op->name, (void *)op);
240 if (hash_err != NULL)
242 as_fatal (_("Internal Error: Can't hash %s: %s"),
243 op->name, hash_err);
247 /* Initialize the spr hash table. */
248 parsing_spr = 0;
249 spr_hash = hash_new ();
250 for (i = 0; i < tilepro_num_sprs; i++)
251 hash_insert (spr_hash, tilepro_sprs[i].name,
252 (void *) &tilepro_sprs[i]);
254 /* Set up the main_reg_hash table. We use this instead of
255 * creating a symbol in the register section to avoid ambiguities
256 * with labels that have the same names as registers. */
257 main_reg_hash = hash_new ();
258 for (i = 0; i < TILEPRO_NUM_REGISTERS; i++)
260 char buf[64];
262 hash_insert (main_reg_hash, tilepro_register_names[i],
263 (void *) (long)(i | CANONICAL_REG_NAME_FLAG));
265 /* See if we should insert a noncanonical alias, like r63. */
266 sprintf (buf, "r%d", i);
267 if (strcmp (buf, tilepro_register_names[i]) != 0)
268 hash_insert (main_reg_hash, xstrdup (buf),
269 (void *) (long)(i | NONCANONICAL_REG_NAME_FLAG));
272 /* Insert obsolete backwards-compatibility register names. */
273 hash_insert (main_reg_hash, "io0",
274 (void *) (long) (TREG_IDN0 | CANONICAL_REG_NAME_FLAG));
275 hash_insert (main_reg_hash, "io1",
276 (void *) (long) (TREG_IDN1 | CANONICAL_REG_NAME_FLAG));
277 hash_insert (main_reg_hash, "us0",
278 (void *) (long) (TREG_UDN0 | CANONICAL_REG_NAME_FLAG));
279 hash_insert (main_reg_hash, "us1",
280 (void *) (long) (TREG_UDN1 | CANONICAL_REG_NAME_FLAG));
281 hash_insert (main_reg_hash, "us2",
282 (void *) (long) (TREG_UDN2 | CANONICAL_REG_NAME_FLAG));
283 hash_insert (main_reg_hash, "us3",
284 (void *) (long) (TREG_UDN3 | CANONICAL_REG_NAME_FLAG));
289 #define BUNDLE_TEMPLATE_MASK(p0, p1, p2) \
290 ((p0) | ((p1) << 8) | ((p2) << 16))
291 #define BUNDLE_TEMPLATE(p0, p1, p2) \
292 { { (p0), (p1), (p2) }, \
293 BUNDLE_TEMPLATE_MASK(1 << (p0), 1 << (p1), (1 << (p2))) \
296 #define NO_PIPELINE TILEPRO_NUM_PIPELINE_ENCODINGS
298 struct bundle_template
300 tilepro_pipeline pipe[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
301 unsigned int pipe_mask;
304 static const struct bundle_template bundle_templates[] =
306 /* In Y format we must always have something in Y2, since it has
307 * no fnop, so this conveys that Y2 must always be used. */
308 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y2, NO_PIPELINE),
309 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y2, NO_PIPELINE),
310 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y0, NO_PIPELINE),
311 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y1, NO_PIPELINE),
313 /* Y format has three instructions. */
314 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y2),
315 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y1),
316 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y2),
317 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y0),
318 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y0, TILEPRO_PIPELINE_Y1),
319 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_Y2, TILEPRO_PIPELINE_Y1, TILEPRO_PIPELINE_Y0),
321 /* X format has only two instructions. */
322 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_X0, TILEPRO_PIPELINE_X1, NO_PIPELINE),
323 BUNDLE_TEMPLATE(TILEPRO_PIPELINE_X1, TILEPRO_PIPELINE_X0, NO_PIPELINE)
327 static void
328 prepend_nop_to_bundle (tilepro_mnemonic mnemonic)
330 memmove (&current_bundle[1], &current_bundle[0],
331 current_bundle_index * sizeof current_bundle[0]);
332 current_bundle[0].opcode = &tilepro_opcodes[mnemonic];
333 ++current_bundle_index;
337 static tilepro_bundle_bits
338 insert_operand (tilepro_bundle_bits bits,
339 const struct tilepro_operand *operand,
340 int operand_value,
341 char *file,
342 unsigned lineno)
344 /* Range-check the immediate. */
345 int num_bits = operand->num_bits;
347 operand_value >>= operand->rightshift;
349 if (bfd_check_overflow (operand->is_signed
350 ? complain_overflow_signed
351 : complain_overflow_unsigned,
352 num_bits,
354 bfd_arch_bits_per_address (stdoutput),
355 operand_value)
356 != bfd_reloc_ok)
358 offsetT min, max;
359 if (operand->is_signed)
361 min = -(1 << (num_bits - 1));
362 max = (1 << (num_bits - 1)) - 1;
364 else
366 min = 0;
367 max = (1 << num_bits) - 1;
369 as_bad_value_out_of_range (_("operand"), operand_value, min, max,
370 file, lineno);
373 /* Write out the bits for the immediate. */
374 return bits | operand->insert (operand_value);
378 static int
379 apply_special_operator (operatorT op, int num)
381 switch (op)
383 case O_lo16:
384 case O_got:
385 case O_got_lo16:
386 case O_tls_gd:
387 case O_tls_gd_lo16:
388 case O_tls_ie:
389 case O_tls_ie_lo16:
390 return (signed short)num;
392 case O_hi16:
393 case O_got_hi16:
394 case O_tls_gd_hi16:
395 case O_tls_ie_hi16:
396 return (signed short)(num >> 16);
398 case O_ha16:
399 case O_got_ha16:
400 case O_tls_gd_ha16:
401 case O_tls_ie_ha16:
402 return (signed short)((num + 0x8000) >> 16);
404 default:
405 abort ();
410 static tilepro_bundle_bits
411 emit_tilepro_instruction (tilepro_bundle_bits bits,
412 int num_operands,
413 const unsigned char *operands,
414 expressionS *operand_values,
415 char *bundle_start)
417 int i;
419 for (i = 0; i < num_operands; i++)
421 const struct tilepro_operand *operand =
422 &tilepro_operands[operands[i]];
423 expressionS *operand_exp = &operand_values[i];
424 int is_pc_relative = operand->is_pc_relative;
426 if (operand_exp->X_op == O_register
427 || (operand_exp->X_op == O_constant && !is_pc_relative))
429 /* We know what the bits are right now, so insert them. */
430 bits = insert_operand (bits, operand, operand_exp->X_add_number,
431 NULL, 0);
433 else
435 bfd_reloc_code_real_type reloc = operand->default_reloc;
436 expressionS subexp;
437 int die = 0, use_subexp = 0, require_symbol = 0;
438 fixS *fixP;
440 /* Take an expression like hi16(x) and turn it into x with
441 a different reloc type. */
442 switch (operand_exp->X_op)
444 #define HANDLE_OP16(suffix) \
445 switch (reloc) \
447 case BFD_RELOC_TILEPRO_IMM16_X0: \
448 reloc = BFD_RELOC_TILEPRO_IMM16_X0_##suffix; \
449 break; \
450 case BFD_RELOC_TILEPRO_IMM16_X1: \
451 reloc = BFD_RELOC_TILEPRO_IMM16_X1_##suffix; \
452 break; \
453 default: \
454 die = 1; \
455 break; \
457 use_subexp = 1
459 case O_lo16:
460 HANDLE_OP16 (LO);
461 break;
463 case O_hi16:
464 HANDLE_OP16 (HI);
465 break;
467 case O_ha16:
468 HANDLE_OP16 (HA);
469 break;
471 case O_got:
472 HANDLE_OP16 (GOT);
473 require_symbol = 1;
474 break;
476 case O_got_lo16:
477 HANDLE_OP16 (GOT_LO);
478 require_symbol = 1;
479 break;
481 case O_got_hi16:
482 HANDLE_OP16 (GOT_HI);
483 require_symbol = 1;
484 break;
486 case O_got_ha16:
487 HANDLE_OP16 (GOT_HA);
488 require_symbol = 1;
489 break;
491 case O_tls_gd:
492 HANDLE_OP16 (TLS_GD);
493 require_symbol = 1;
494 break;
496 case O_tls_gd_lo16:
497 HANDLE_OP16 (TLS_GD_LO);
498 require_symbol = 1;
499 break;
501 case O_tls_gd_hi16:
502 HANDLE_OP16 (TLS_GD_HI);
503 require_symbol = 1;
504 break;
506 case O_tls_gd_ha16:
507 HANDLE_OP16 (TLS_GD_HA);
508 require_symbol = 1;
509 break;
511 case O_tls_ie:
512 HANDLE_OP16 (TLS_IE);
513 require_symbol = 1;
514 break;
516 case O_tls_ie_lo16:
517 HANDLE_OP16 (TLS_IE_LO);
518 require_symbol = 1;
519 break;
521 case O_tls_ie_hi16:
522 HANDLE_OP16 (TLS_IE_HI);
523 require_symbol = 1;
524 break;
526 case O_tls_ie_ha16:
527 HANDLE_OP16 (TLS_IE_HA);
528 require_symbol = 1;
529 break;
531 #undef HANDLE_OP16
533 case O_plt:
534 switch (reloc)
536 case BFD_RELOC_TILEPRO_JOFFLONG_X1:
537 reloc = BFD_RELOC_TILEPRO_JOFFLONG_X1_PLT;
538 break;
539 default:
540 die = 1;
541 break;
543 use_subexp = 1;
544 require_symbol = 1;
545 break;
547 default:
548 /* Do nothing. */
549 break;
552 if (die)
554 as_bad (_("Invalid operator for operand."));
556 else if (use_subexp)
558 /* Now that we've changed the reloc, change ha16(x) into x,
559 etc. */
561 if (operand_exp->X_add_symbol->sy_value.X_md)
563 if (require_symbol)
565 as_bad (_("Operator may only be applied to symbols."));
568 /* HACK: We used X_md to mark this symbol as a fake wrapper
569 around a real expression. To unwrap it, we just grab its
570 value here. */
571 operand_exp = &operand_exp->X_add_symbol->sy_value;
573 else
575 /* The value of this expression is an actual symbol, so
576 turn that into an expression. */
577 memset (&subexp, 0, sizeof subexp);
578 subexp.X_op = O_symbol;
579 subexp.X_add_symbol = operand_exp->X_add_symbol;
580 operand_exp = &subexp;
584 /* Create a fixup to handle this later. */
585 fixP = fix_new_exp (frag_now,
586 bundle_start - frag_now->fr_literal,
587 (operand->num_bits + 7) >> 3,
588 operand_exp,
589 is_pc_relative,
590 reloc);
591 fixP->tc_fix_data = operand;
593 /* Don't do overflow checking if we are applying a function like
594 ha16. */
595 fixP->fx_no_overflow |= use_subexp;
598 return bits;
602 /* Detects and complains if two instructions in current_bundle write
603 to the same register, either implicitly or explicitly, or if a
604 read-only register is written. */
605 static void
606 check_illegal_reg_writes (void)
608 BFD_HOST_U_64_BIT all_regs_written = 0;
609 int j;
611 for (j = 0; j < current_bundle_index; j++)
613 const struct tilepro_instruction *instr = &current_bundle[j];
614 int k;
615 BFD_HOST_U_64_BIT regs =
616 ((BFD_HOST_U_64_BIT)1) << instr->opcode->implicitly_written_register;
617 BFD_HOST_U_64_BIT conflict;
619 for (k = 0; k < instr->opcode->num_operands; k++)
621 const struct tilepro_operand *operand =
622 &tilepro_operands[instr->opcode->operands[instr->pipe][k]];
624 if (operand->is_dest_reg)
626 int regno = instr->operand_values[k].X_add_number;
627 BFD_HOST_U_64_BIT mask = ((BFD_HOST_U_64_BIT)1) << regno;
629 if ((mask & ( (((BFD_HOST_U_64_BIT)1) << TREG_IDN1)
630 | (((BFD_HOST_U_64_BIT)1) << TREG_UDN1)
631 | (((BFD_HOST_U_64_BIT)1) << TREG_UDN2)
632 | (((BFD_HOST_U_64_BIT)1) << TREG_UDN3))) != 0
633 && !allow_suspicious_bundles)
635 as_bad (_("Writes to register '%s' are not allowed."),
636 tilepro_register_names[regno]);
639 regs |= mask;
643 /* Writing to the zero register doesn't count. */
644 regs &= ~(((BFD_HOST_U_64_BIT)1) << TREG_ZERO);
646 conflict = all_regs_written & regs;
647 if (conflict != 0 && !allow_suspicious_bundles)
649 /* Find which register caused the conflict. */
650 const char *conflicting_reg_name = "???";
651 int i;
653 for (i = 0; i < TILEPRO_NUM_REGISTERS; i++)
655 if (((conflict >> i) & 1) != 0)
657 conflicting_reg_name = tilepro_register_names[i];
658 break;
662 as_bad (_("Two instructions in the same bundle both write "
663 "to register %s, which is not allowed."),
664 conflicting_reg_name);
667 all_regs_written |= regs;
672 static void
673 tilepro_flush_bundle (void)
675 unsigned i;
676 int j, addr_mod;
677 unsigned compatible_pipes;
678 const struct bundle_template *match;
679 char *f;
681 inside_bundle = 0;
683 switch (current_bundle_index)
685 case 0:
686 /* No instructions. */
687 return;
688 case 1:
689 if (current_bundle[0].opcode->can_bundle)
691 /* Simplify later logic by adding an explicit fnop. */
692 prepend_nop_to_bundle (TILEPRO_OPC_FNOP);
694 else
696 /* This instruction cannot be bundled with anything else.
697 Prepend an explicit 'nop', rather than an 'fnop', because
698 fnops can be replaced by later binary-processing tools
699 while nops cannot. */
700 prepend_nop_to_bundle (TILEPRO_OPC_NOP);
702 break;
703 default:
704 if (!allow_suspicious_bundles)
706 /* Make sure all instructions can be bundled with other
707 instructions. */
708 const struct tilepro_opcode *cannot_bundle = NULL;
709 bfd_boolean seen_non_nop = FALSE;
711 for (j = 0; j < current_bundle_index; j++)
713 const struct tilepro_opcode *op = current_bundle[j].opcode;
715 if (!op->can_bundle && cannot_bundle == NULL)
716 cannot_bundle = op;
717 else if (op->mnemonic != TILEPRO_OPC_NOP
718 && op->mnemonic != TILEPRO_OPC_INFO
719 && op->mnemonic != TILEPRO_OPC_INFOL)
720 seen_non_nop = TRUE;
723 if (cannot_bundle != NULL && seen_non_nop)
725 current_bundle_index = 0;
726 as_bad (_("'%s' may not be bundled with other instructions."),
727 cannot_bundle->name);
728 return;
731 break;
734 compatible_pipes =
735 BUNDLE_TEMPLATE_MASK(current_bundle[0].opcode->pipes,
736 current_bundle[1].opcode->pipes,
737 (current_bundle_index == 3
738 ? current_bundle[2].opcode->pipes
739 : (1 << NO_PIPELINE)));
741 /* Find a template that works, if any. */
742 match = NULL;
743 for (i = 0; i < sizeof bundle_templates / sizeof bundle_templates[0]; i++)
745 const struct bundle_template *b = &bundle_templates[i];
746 if ((b->pipe_mask & compatible_pipes) == b->pipe_mask)
748 match = b;
749 break;
753 if (match == NULL)
755 current_bundle_index = 0;
756 as_bad (_("Invalid combination of instructions for bundle."));
757 return;
760 /* If the section seems to have no alignment set yet, go ahead and
761 make it large enough to hold code. */
762 if (bfd_get_section_alignment (stdoutput, now_seg) == 0)
763 bfd_set_section_alignment (stdoutput, now_seg,
764 TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES);
766 for (j = 0; j < current_bundle_index; j++)
767 current_bundle[j].pipe = match->pipe[j];
769 if (current_bundle_index == 2 && !tilepro_is_x_pipeline(match->pipe[0]))
771 /* We are in Y mode with only two instructions, so add an FNOP. */
772 prepend_nop_to_bundle (TILEPRO_OPC_FNOP);
774 /* Figure out what pipe the fnop must be in via arithmetic.
775 * p0 + p1 + p2 must sum to the sum of TILEPRO_PIPELINE_Y[012]. */
776 current_bundle[0].pipe =
777 (tilepro_pipeline)((TILEPRO_PIPELINE_Y0
778 + TILEPRO_PIPELINE_Y1
779 + TILEPRO_PIPELINE_Y2) -
780 (current_bundle[1].pipe + current_bundle[2].pipe));
783 check_illegal_reg_writes ();
785 f = frag_more (TILEPRO_BUNDLE_SIZE_IN_BYTES);
787 /* Check to see if this bundle is at an offset that is a multiple of 8-bytes
788 from the start of the frag. */
789 addr_mod = frag_now_fix () & (TILEPRO_BUNDLE_ALIGNMENT_IN_BYTES - 1);
790 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
791 as_bad (_("instruction address is not a multiple of 8"));
792 frag_now->insn_addr = addr_mod;
793 frag_now->has_code = 1;
795 tilepro_bundle_bits bits = 0;
796 for (j = 0; j < current_bundle_index; j++)
798 struct tilepro_instruction *instr = &current_bundle[j];
799 tilepro_pipeline pipeline = instr->pipe;
800 const struct tilepro_opcode *opcode = instr->opcode;
802 bits |= emit_tilepro_instruction (opcode->fixed_bit_values[pipeline],
803 opcode->num_operands,
804 &opcode->operands[pipeline][0],
805 instr->operand_values,
809 number_to_chars_littleendian (f, (unsigned int)bits, 4);
810 number_to_chars_littleendian (f + 4, (unsigned int)(bits >> 32), 4);
811 current_bundle_index = 0;
813 /* Emit DWARF2 debugging information. */
814 dwarf2_emit_insn (TILEPRO_BUNDLE_SIZE_IN_BYTES);
818 /* Extend the expression parser to handle hi16(label), etc.
819 as well as SPR names when in the context of parsing an SPR. */
821 tilepro_parse_name (char *name, expressionS *e, char *nextcharP)
823 operatorT op = O_illegal;
825 if (parsing_spr)
827 void *val = hash_find (spr_hash, name);
828 if (val == NULL)
829 return 0;
831 memset (e, 0, sizeof *e);
832 e->X_op = O_constant;
833 e->X_add_number = ((const struct tilepro_spr *)val)->number;
834 return 1;
837 if (*nextcharP != '(')
839 /* hi16, etc. not followed by a paren is just a label with that
840 name. */
841 return 0;
843 else
845 /* Look up the operator in our table. */
846 void *val = hash_find (special_operator_hash, name);
847 if (val == 0)
848 return 0;
849 op = (operatorT)(long)val;
852 /* Restore old '(' and skip it. */
853 *input_line_pointer = '(';
854 ++input_line_pointer;
856 expression (e);
858 if (*input_line_pointer != ')')
860 as_bad (_("Missing ')'"));
861 *nextcharP = *input_line_pointer;
862 return 0;
864 /* Skip ')'. */
865 ++input_line_pointer;
867 if (e->X_op == O_register || e->X_op == O_absent)
869 as_bad (_("Invalid expression."));
870 e->X_op = O_constant;
871 e->X_add_number = 0;
873 else
875 /* Wrap subexpression with a unary operator. */
876 symbolS *sym = make_expr_symbol (e);
878 if (sym != e->X_add_symbol)
880 /* HACK: mark this symbol as a temporary wrapper around a proper
881 expression, so we can unwrap it later once we have communicated
882 the relocation type. */
883 sym->sy_value.X_md = 1;
886 memset (e, 0, sizeof *e);
887 e->X_op = op;
888 e->X_add_symbol = sym;
889 e->X_add_number = 0;
892 *nextcharP = *input_line_pointer;
893 return 1;
897 /* Parses an expression which must be a register name. */
899 static void
900 parse_reg_expression (expressionS* expression)
902 /* Zero everything to make sure we don't miss any flags. */
903 memset (expression, 0, sizeof *expression);
905 char* regname = input_line_pointer;
906 char terminating_char = get_symbol_end ();
908 void* pval = hash_find (main_reg_hash, regname);
910 if (pval == NULL)
911 as_bad (_("Expected register, got '%s'."), regname);
913 int regno_and_flags = (int)(size_t)pval;
914 int regno = EXTRACT_REGNO(regno_and_flags);
916 if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG)
917 && require_canonical_reg_names)
918 as_warn (_("Found use of non-canonical register name %s; "
919 "use %s instead."),
920 regname, tilepro_register_names[regno]);
922 /* Restore the old character following the register name. */
923 *input_line_pointer = terminating_char;
925 /* Fill in the expression fields to indicate it's a register. */
926 expression->X_op = O_register;
927 expression->X_add_number = regno;
931 /* Parses and type-checks comma-separated operands in input_line_pointer. */
932 static void
933 parse_operands (const char *opcode_name,
934 const unsigned char *operands,
935 int num_operands,
936 expressionS *operand_values)
938 int i;
940 memset (operand_values, 0, num_operands * sizeof operand_values[0]);
942 SKIP_WHITESPACE ();
943 for (i = 0; i < num_operands; i++)
945 tilepro_operand_type type = tilepro_operands[operands[i]].type;
947 SKIP_WHITESPACE ();
949 if (type == TILEPRO_OP_TYPE_REGISTER)
951 parse_reg_expression (&operand_values[i]);
953 else if (*input_line_pointer == '}')
955 operand_values[i].X_op = O_absent;
957 else if (type == TILEPRO_OP_TYPE_SPR)
959 /* Modify the expression parser to add SPRs to the namespace. */
960 parsing_spr = 1;
961 expression (&operand_values[i]);
962 parsing_spr = 0;
964 else
966 expression (&operand_values[i]);
969 SKIP_WHITESPACE ();
971 if (i + 1 < num_operands)
973 int separator = (unsigned char)*input_line_pointer++;
975 if (is_end_of_line[separator] || (separator == '}'))
977 as_bad (_("Too few operands to '%s'."), opcode_name);
978 return;
980 else if (separator != ',')
982 as_bad (_("Unexpected character '%c' after operand %d to %s."),
983 (char)separator, i + 1, opcode_name);
984 return;
988 /* Arbitrarily use the first valid pipe to get the operand type,
989 since they are all the same. */
990 switch (tilepro_operands[operands[i]].type)
992 case TILEPRO_OP_TYPE_REGISTER:
993 /* Handled in parse_reg_expression already. */
994 break;
995 case TILEPRO_OP_TYPE_SPR:
996 /* Fall through */
997 case TILEPRO_OP_TYPE_IMMEDIATE:
998 /* Fall through */
999 case TILEPRO_OP_TYPE_ADDRESS:
1000 if ( operand_values[i].X_op == O_register
1001 || operand_values[i].X_op == O_illegal
1002 || operand_values[i].X_op == O_absent)
1003 as_bad (_("Expected immediate expression"));
1004 break;
1005 default:
1006 abort ();
1010 if (!is_end_of_line[(unsigned char)*input_line_pointer])
1012 switch (*input_line_pointer)
1014 case '}':
1015 if (!inside_bundle)
1016 as_bad (_("Found '}' when not bundling."));
1017 ++input_line_pointer;
1018 inside_bundle = 0;
1019 demand_empty_rest_of_line ();
1020 break;
1022 case ',':
1023 as_bad (_("Too many operands"));
1024 break;
1026 default:
1027 /* Use default error for unrecognized garbage. */
1028 demand_empty_rest_of_line ();
1029 break;
1035 /* This is the guts of the machine-dependent assembler. STR points to a
1036 machine dependent instruction. This function is supposed to emit
1037 the frags/bytes it assembles to. */
1038 void
1039 md_assemble (char *str)
1041 char old_char;
1042 size_t opname_len;
1043 char *old_input_line_pointer;
1044 const struct tilepro_opcode *op;
1045 int first_pipe;
1047 /* Split off the opcode and look it up. */
1048 opname_len = strcspn (str, " {}");
1049 old_char = str[opname_len];
1050 str[opname_len] = '\0';
1052 op = hash_find(op_hash, str);
1053 str[opname_len] = old_char;
1054 if (op == NULL)
1056 as_bad (_("Unknown opcode `%.*s'."), (int)opname_len, str);
1057 return;
1060 /* Prepare to parse the operands. */
1061 old_input_line_pointer = input_line_pointer;
1062 input_line_pointer = str + opname_len;
1063 SKIP_WHITESPACE ();
1065 if (current_bundle_index == TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE)
1067 as_bad (_("Too many instructions for bundle."));
1068 tilepro_flush_bundle ();
1071 /* Make sure we have room for the upcoming bundle before we
1072 create any fixups. Otherwise if we have to switch to a new
1073 frag the fixup dot_value fields will be wrong. */
1074 frag_grow (TILEPRO_BUNDLE_SIZE_IN_BYTES);
1076 /* Find a valid pipe for this opcode. */
1077 for (first_pipe = 0; (op->pipes & (1 << first_pipe)) == 0; first_pipe++)
1080 /* Call the function that assembles this instruction. */
1081 current_bundle[current_bundle_index].opcode = op;
1082 parse_operands (op->name,
1083 &op->operands[first_pipe][0],
1084 op->num_operands,
1085 current_bundle[current_bundle_index].operand_values);
1086 ++current_bundle_index;
1088 /* Restore the saved value of input_line_pointer. */
1089 input_line_pointer = old_input_line_pointer;
1091 /* If we weren't inside curly braces, go ahead and emit
1092 this lone instruction as a bundle right now. */
1093 if (!inside_bundle)
1094 tilepro_flush_bundle ();
1097 static void
1098 s_require_canonical_reg_names (int require)
1100 demand_empty_rest_of_line ();
1101 require_canonical_reg_names = require;
1104 static void
1105 s_allow_suspicious_bundles (int allow)
1107 demand_empty_rest_of_line ();
1108 allow_suspicious_bundles = allow;
1111 const pseudo_typeS md_pseudo_table[] =
1113 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0). */
1114 {"word", cons, 4},
1115 {"require_canonical_reg_names", s_require_canonical_reg_names, 1 },
1116 {"no_require_canonical_reg_names", s_require_canonical_reg_names, 0 },
1117 {"allow_suspicious_bundles", s_allow_suspicious_bundles, 1 },
1118 {"no_allow_suspicious_bundles", s_allow_suspicious_bundles, 0 },
1119 { NULL, 0, 0 }
1122 /* Equal to MAX_PRECISION in atof-ieee.c */
1123 #define MAX_LITTLENUMS 6
1125 /* Turn the string pointed to by litP into a floating point constant
1126 of type TYPE, and emit the appropriate bytes. The number of
1127 LITTLENUMS emitted is stored in *SIZEP. An error message is
1128 returned, or NULL on OK. */
1130 char *
1131 md_atof (int type, char *litP, int *sizeP)
1133 int prec;
1134 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1135 LITTLENUM_TYPE *wordP;
1136 char *t;
1138 switch (type)
1140 case 'f':
1141 case 'F':
1142 prec = 2;
1143 break;
1145 case 'd':
1146 case 'D':
1147 prec = 4;
1148 break;
1150 default:
1151 *sizeP = 0;
1152 return _("Bad call to md_atof ()");
1154 t = atof_ieee (input_line_pointer, type, words);
1155 if (t)
1156 input_line_pointer = t;
1158 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1159 /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
1160 the bigendian 386. */
1161 for (wordP = words + prec - 1; prec--;)
1163 md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
1164 litP += sizeof (LITTLENUM_TYPE);
1166 return 0;
1170 /* We have no need to default values of symbols. */
1172 symbolS *
1173 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1175 return NULL;
1179 void
1180 tilepro_cons_fix_new (fragS *frag,
1181 int where,
1182 int nbytes,
1183 expressionS *exp)
1185 expressionS subexp;
1186 bfd_reloc_code_real_type reloc = BFD_RELOC_NONE;
1187 int no_overflow = 0;
1188 fixS *fixP;
1190 /* See if it's one of our special functions. */
1191 switch (exp->X_op)
1193 case O_lo16:
1194 reloc = BFD_RELOC_LO16;
1195 no_overflow = 1;
1196 break;
1197 case O_hi16:
1198 reloc = BFD_RELOC_HI16;
1199 no_overflow = 1;
1200 break;
1201 case O_ha16:
1202 reloc = BFD_RELOC_HI16_S;
1203 no_overflow = 1;
1204 break;
1206 default:
1207 /* Do nothing. */
1208 break;
1211 if (reloc != BFD_RELOC_NONE)
1213 if (nbytes != 2)
1215 as_bad (_("This operator only produces two byte values."));
1216 nbytes = 2;
1219 memset (&subexp, 0, sizeof subexp);
1220 subexp.X_op = O_symbol;
1221 subexp.X_add_symbol = exp->X_add_symbol;
1222 exp = &subexp;
1224 else
1226 switch (nbytes)
1228 case 1:
1229 reloc = BFD_RELOC_8;
1230 break;
1231 case 2:
1232 reloc = BFD_RELOC_16;
1233 break;
1234 case 4:
1235 reloc = BFD_RELOC_32;
1236 break;
1237 case 8:
1238 reloc = BFD_RELOC_64;
1239 break;
1240 default:
1241 as_bad (_("unsupported BFD relocation size %d"), nbytes);
1242 reloc = BFD_RELOC_32;
1243 break;
1247 fixP = fix_new_exp (frag, where, nbytes, exp, 0, reloc);
1248 fixP->tc_fix_data = NULL;
1249 fixP->fx_no_overflow |= no_overflow;
1253 void
1254 md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
1256 const struct tilepro_operand *operand;
1257 valueT value = *valP;
1258 char *p;
1260 /* Leave these for the linker. */
1261 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
1262 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1263 return;
1265 if (fixP->fx_subsy != (symbolS *) NULL)
1267 /* We can't actually support subtracting a symbol. */
1268 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
1271 /* Correct relocation types for pc-relativeness. */
1272 switch (fixP->fx_r_type)
1274 #define FIX_PCREL(rtype) \
1275 case rtype: \
1276 if (fixP->fx_pcrel) \
1277 fixP->fx_r_type = rtype##_PCREL; \
1278 break; \
1280 case rtype##_PCREL: \
1281 if (!fixP->fx_pcrel) \
1282 fixP->fx_r_type = rtype; \
1283 break
1285 FIX_PCREL (BFD_RELOC_8);
1286 FIX_PCREL (BFD_RELOC_16);
1287 FIX_PCREL (BFD_RELOC_32);
1288 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0);
1289 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1);
1290 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0_LO);
1291 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1_LO);
1292 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0_HI);
1293 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1_HI);
1294 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X0_HA);
1295 FIX_PCREL (BFD_RELOC_TILEPRO_IMM16_X1_HA);
1297 #undef FIX_PCREL
1299 default:
1300 /* Do nothing */
1301 break;
1304 if (fixP->fx_addsy != NULL)
1306 #ifdef OBJ_ELF
1307 switch (fixP->fx_r_type)
1309 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD:
1310 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD:
1311 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE:
1312 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE:
1313 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_LO:
1314 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_LO:
1315 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_LO:
1316 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_LO:
1317 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HI:
1318 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HI:
1319 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HI:
1320 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HI:
1321 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HA:
1322 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HA:
1323 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HA:
1324 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HA:
1325 case BFD_RELOC_TILEPRO_TLS_DTPMOD32:
1326 case BFD_RELOC_TILEPRO_TLS_DTPOFF32:
1327 case BFD_RELOC_TILEPRO_TLS_TPOFF32:
1328 S_SET_THREAD_LOCAL (fixP->fx_addsy);
1329 break;
1331 default:
1332 /* Do nothing */
1333 break;
1335 #endif
1336 return;
1339 /* Apply lo16, hi16, ha16, etc. munging. */
1340 switch (fixP->fx_r_type)
1342 case BFD_RELOC_TILEPRO_IMM16_X0_GOT:
1343 case BFD_RELOC_TILEPRO_IMM16_X1_GOT:
1344 *valP = value = apply_special_operator (O_got, value);
1345 break;
1347 case BFD_RELOC_TILEPRO_IMM16_X0_GOT_LO:
1348 case BFD_RELOC_TILEPRO_IMM16_X1_GOT_LO:
1349 *valP = value = apply_special_operator (O_got_lo16, value);
1350 break;
1352 case BFD_RELOC_TILEPRO_IMM16_X0_GOT_HI:
1353 case BFD_RELOC_TILEPRO_IMM16_X1_GOT_HI:
1354 *valP = value = apply_special_operator (O_got_hi16, value);
1355 break;
1357 case BFD_RELOC_TILEPRO_IMM16_X0_GOT_HA:
1358 case BFD_RELOC_TILEPRO_IMM16_X1_GOT_HA:
1359 *valP = value = apply_special_operator (O_got_ha16, value);
1360 break;
1362 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD:
1363 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD:
1364 *valP = value = apply_special_operator (O_tls_gd, value);
1365 break;
1367 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE:
1368 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE:
1369 *valP = value = apply_special_operator (O_tls_ie, value);
1370 break;
1372 case BFD_RELOC_LO16:
1373 case BFD_RELOC_TILEPRO_IMM16_X0_LO:
1374 case BFD_RELOC_TILEPRO_IMM16_X1_LO:
1375 case BFD_RELOC_TILEPRO_IMM16_X0_LO_PCREL:
1376 case BFD_RELOC_TILEPRO_IMM16_X1_LO_PCREL:
1377 *valP = value = apply_special_operator (O_lo16, value);
1378 break;
1380 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_LO:
1381 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_LO:
1382 *valP = value = apply_special_operator (O_tls_gd_lo16, value);
1383 break;
1385 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_LO:
1386 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_LO:
1387 *valP = value = apply_special_operator (O_tls_ie_lo16, value);
1388 break;
1390 case BFD_RELOC_HI16:
1391 case BFD_RELOC_TILEPRO_IMM16_X0_HI:
1392 case BFD_RELOC_TILEPRO_IMM16_X1_HI:
1393 case BFD_RELOC_TILEPRO_IMM16_X0_HI_PCREL:
1394 case BFD_RELOC_TILEPRO_IMM16_X1_HI_PCREL:
1395 *valP = value = apply_special_operator (O_hi16, value);
1396 break;
1398 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HI:
1399 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HI:
1400 *valP = value = apply_special_operator (O_tls_gd_hi16, value);
1401 break;
1403 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HI:
1404 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HI:
1405 *valP = value = apply_special_operator (O_tls_ie_hi16, value);
1406 break;
1408 case BFD_RELOC_HI16_S:
1409 case BFD_RELOC_TILEPRO_IMM16_X0_HA:
1410 case BFD_RELOC_TILEPRO_IMM16_X1_HA:
1411 case BFD_RELOC_TILEPRO_IMM16_X0_HA_PCREL:
1412 case BFD_RELOC_TILEPRO_IMM16_X1_HA_PCREL:
1413 *valP = value = apply_special_operator (O_ha16, value);
1414 break;
1416 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HA:
1417 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HA:
1418 *valP = value = apply_special_operator (O_tls_gd_ha16, value);
1419 break;
1421 case BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HA:
1422 case BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HA:
1423 *valP = value = apply_special_operator (O_tls_ie_ha16, value);
1424 break;
1426 default:
1427 /* Do nothing */
1428 break;
1431 p = fixP->fx_frag->fr_literal + fixP->fx_where;
1433 operand = fixP->tc_fix_data;
1434 if (operand != NULL)
1436 /* It's an instruction operand. */
1437 tilepro_bundle_bits bits =
1438 insert_operand (0, operand, value, fixP->fx_file, fixP->fx_line);
1440 /* Note that we might either be writing out bits for a bundle or a
1441 static network instruction, which are different sizes, so it's
1442 important to stop touching memory once we run out of bits. ORing in
1443 values is OK since we know the existing bits for this operand are
1444 zero. */
1445 for (; bits != 0; bits >>= 8)
1446 *p++ |= (char)bits;
1448 else
1450 /* Some other kind of relocation. */
1451 switch (fixP->fx_r_type)
1453 case BFD_RELOC_8:
1454 case BFD_RELOC_8_PCREL:
1455 md_number_to_chars (p, value, 1);
1456 break;
1458 case BFD_RELOC_16:
1459 case BFD_RELOC_16_PCREL:
1460 md_number_to_chars (p, value, 2);
1461 break;
1463 case BFD_RELOC_32:
1464 case BFD_RELOC_32_PCREL:
1465 md_number_to_chars (p, value, 4);
1466 break;
1468 default:
1469 /* Leave it for the linker. */
1470 return;
1474 fixP->fx_done = 1;
1478 /* Generate the BFD reloc to be stuck in the object file from the
1479 fixup used internally in the assembler. */
1481 arelent *
1482 tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp)
1484 arelent *reloc;
1486 reloc = (arelent *) xmalloc (sizeof (arelent));
1487 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1488 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1489 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1491 /* Make sure none of our internal relocations make it this far.
1492 They'd better have been fully resolved by this point. */
1493 gas_assert ((int) fixp->fx_r_type > 0);
1495 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1496 if (reloc->howto == NULL)
1498 as_bad_where (fixp->fx_file, fixp->fx_line,
1499 _("cannot represent `%s' relocation in object file"),
1500 bfd_get_reloc_code_name (fixp->fx_r_type));
1501 return NULL;
1504 if (!fixp->fx_pcrel != !reloc->howto->pc_relative)
1506 as_fatal (_("internal error? cannot generate `%s' relocation (%d, %d)"),
1507 bfd_get_reloc_code_name (fixp->fx_r_type),
1508 fixp->fx_pcrel, reloc->howto->pc_relative);
1510 gas_assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
1512 reloc->addend = fixp->fx_offset;
1514 return reloc;
1518 /* The location from which a PC relative jump should be calculated,
1519 given a PC relative reloc. */
1521 long
1522 md_pcrel_from (fixS *fixP)
1524 return fixP->fx_frag->fr_address + fixP->fx_where;
1528 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
1529 a section symbol plus some offset. */
1531 tilepro_fix_adjustable (fixS *fix)
1533 /* Prevent all adjustments to global symbols */
1534 if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
1535 return 0;
1537 return 1;
1542 tilepro_unrecognized_line (int ch)
1544 switch (ch)
1546 case '{':
1547 if (inside_bundle)
1549 as_bad (_("Found '{' when already bundling."));
1551 else
1553 inside_bundle = 1;
1554 current_bundle_index = 0;
1556 return 1;
1558 case '}':
1559 if (!inside_bundle)
1561 as_bad (_("Found '}' when not bundling."));
1563 else
1565 tilepro_flush_bundle ();
1568 /* Allow '{' to follow on the same line. We also allow ";;", but that
1569 happens automatically because ';' is an end of line marker. */
1570 SKIP_WHITESPACE ();
1571 if (input_line_pointer[0] == '{')
1573 input_line_pointer++;
1574 return tilepro_unrecognized_line ('{');
1577 demand_empty_rest_of_line ();
1578 return 1;
1580 default:
1581 break;
1584 /* Not a valid line. */
1585 return 0;
1589 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
1590 of an rs_align_code fragment. */
1592 void
1593 tilepro_handle_align (fragS *fragp)
1595 int bytes, fix;
1596 char *p;
1598 if (fragp->fr_type != rs_align_code)
1599 return;
1601 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
1602 p = fragp->fr_literal + fragp->fr_fix;
1603 fix = 0;
1605 /* Determine the bits for NOP. */
1606 const struct tilepro_opcode *nop_opcode =
1607 &tilepro_opcodes[TILEPRO_OPC_NOP];
1608 tilepro_bundle_bits nop =
1609 ( nop_opcode->fixed_bit_values[TILEPRO_PIPELINE_X0]
1610 | nop_opcode->fixed_bit_values[TILEPRO_PIPELINE_X1]);
1612 if ((bytes & (TILEPRO_BUNDLE_SIZE_IN_BYTES - 1)) != 0)
1614 fix = bytes & (TILEPRO_BUNDLE_SIZE_IN_BYTES - 1);
1615 memset (p, 0, fix);
1616 p += fix;
1617 bytes -= fix;
1620 number_to_chars_littleendian (p, (unsigned int)nop, 4);
1621 number_to_chars_littleendian (p + 4, (unsigned int)(nop >> 32), 4);
1622 fragp->fr_fix += fix;
1623 fragp->fr_var = TILEPRO_BUNDLE_SIZE_IN_BYTES;
1626 /* Standard calling conventions leave the CFA at SP on entry. */
1627 void
1628 tilepro_cfi_frame_initial_instructions (void)
1630 cfi_add_CFA_def_cfa_register (54);
1634 tc_tilepro_regname_to_dw2regnum (char *regname)
1636 int i;
1638 for (i = 0; i < TILEPRO_NUM_REGISTERS; i++)
1640 if (!strcmp (regname, tilepro_register_names[i]))
1641 return i;
1644 return -1;