Commit | Line | Data |
---|---|---|
aa137e4d NC |
1 | /* tc-tilegx.c -- Assemble for a Tile-Gx chip. |
2 | Copyright 2011 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
20 | ||
21 | #include "as.h" | |
22 | #include "struc-symbol.h" | |
23 | #include "subsegs.h" | |
24 | ||
25 | #include "elf/tilegx.h" | |
26 | #include "opcode/tilegx.h" | |
27 | ||
28 | #include "dwarf2dbg.h" | |
29 | #include "dw2gencfi.h" | |
30 | ||
31 | #include "safe-ctype.h" | |
32 | ||
33 | ||
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 | |
42 | ||
43 | ||
44 | /* Generic assembler global variables which must be defined by all | |
45 | targets. */ | |
46 | ||
47 | /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */ | |
48 | int tilegx_cie_data_alignment; | |
49 | ||
50 | /* Characters which always start a comment. */ | |
51 | const char comment_chars[] = "#"; | |
52 | ||
53 | /* Characters which start a comment at the beginning of a line. */ | |
54 | const char line_comment_chars[] = "#"; | |
55 | ||
56 | /* Characters which may be used to separate multiple commands on a | |
57 | single line. */ | |
58 | const char line_separator_chars[] = ";"; | |
59 | ||
60 | /* Characters which are used to indicate an exponent in a floating | |
61 | point number. */ | |
62 | const char EXP_CHARS[] = "eE"; | |
63 | ||
64 | /* Characters which mean that a number is a floating point constant, | |
65 | as in 0d1.0. */ | |
66 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
67 | ||
68 | /* Either 32 or 64. */ | |
69 | static int tilegx_arch_size = 64; | |
70 | ||
71 | ||
72 | const char * | |
73 | tilegx_target_format (void) | |
74 | { | |
fb6cedde WL |
75 | if (target_big_endian) { |
76 | return tilegx_arch_size == 64 ? "elf64-tilegx-be" : "elf32-tilegx-be"; | |
77 | } else { | |
78 | return tilegx_arch_size == 64 ? "elf64-tilegx-le" : "elf32-tilegx-le"; | |
79 | } | |
aa137e4d NC |
80 | } |
81 | ||
82 | ||
83 | #define OPTION_32 (OPTION_MD_BASE + 0) | |
84 | #define OPTION_64 (OPTION_MD_BASE + 1) | |
fb6cedde WL |
85 | #define OPTION_EB (OPTION_MD_BASE + 2) |
86 | #define OPTION_EL (OPTION_MD_BASE + 3) | |
aa137e4d NC |
87 | |
88 | const char *md_shortopts = "VQ:"; | |
89 | ||
90 | struct option md_longopts[] = | |
91 | { | |
92 | {"32", no_argument, NULL, OPTION_32}, | |
93 | {"64", no_argument, NULL, OPTION_64}, | |
fb6cedde WL |
94 | {"EB", no_argument, NULL, OPTION_EB }, |
95 | {"EL", no_argument, NULL, OPTION_EL }, | |
aa137e4d NC |
96 | {NULL, no_argument, NULL, 0} |
97 | }; | |
98 | ||
99 | size_t md_longopts_size = sizeof (md_longopts); | |
100 | ||
101 | int | |
102 | md_parse_option (int c, char *arg ATTRIBUTE_UNUSED) | |
103 | { | |
104 | switch (c) | |
105 | { | |
106 | /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section | |
107 | should be emitted or not. FIXME: Not implemented. */ | |
108 | case 'Q': | |
109 | break; | |
110 | ||
111 | /* -V: SVR4 argument to print version ID. */ | |
112 | case 'V': | |
113 | print_version_id (); | |
114 | break; | |
115 | ||
116 | case OPTION_32: | |
117 | tilegx_arch_size = 32; | |
118 | break; | |
119 | ||
120 | case OPTION_64: | |
121 | tilegx_arch_size = 64; | |
122 | break; | |
123 | ||
fb6cedde WL |
124 | case OPTION_EB: |
125 | target_big_endian = 1; | |
126 | break; | |
127 | ||
128 | case OPTION_EL: | |
129 | target_big_endian = 0; | |
130 | break; | |
131 | ||
aa137e4d NC |
132 | default: |
133 | return 0; | |
134 | } | |
135 | ||
136 | return 1; | |
137 | } | |
138 | ||
139 | void | |
140 | md_show_usage (FILE *stream) | |
141 | { | |
142 | fprintf (stream, _("\ | |
143 | -Q ignored\n\ | |
144 | -V print assembler version number\n\ | |
fb6cedde | 145 | -EB/-EL generate big-endian/little-endian code\n\ |
aa137e4d NC |
146 | --32/--64 generate 32bit/64bit code\n")); |
147 | } | |
148 | ||
149 | ||
150 | /* Extra expression types. */ | |
151 | ||
152 | #define O_hw0 O_md1 | |
153 | #define O_hw1 O_md2 | |
154 | #define O_hw2 O_md3 | |
155 | #define O_hw3 O_md4 | |
156 | #define O_hw0_last O_md5 | |
157 | #define O_hw1_last O_md6 | |
158 | #define O_hw2_last O_md7 | |
159 | #define O_hw0_got O_md8 | |
160 | #define O_hw1_got O_md9 | |
161 | #define O_hw2_got O_md10 | |
162 | #define O_hw3_got O_md11 | |
163 | #define O_hw0_last_got O_md12 | |
164 | #define O_hw1_last_got O_md13 | |
165 | #define O_hw2_last_got O_md14 | |
166 | #define O_plt O_md15 | |
167 | #define O_hw0_tls_gd O_md16 | |
168 | #define O_hw1_tls_gd O_md17 | |
169 | #define O_hw2_tls_gd O_md18 | |
170 | #define O_hw3_tls_gd O_md19 | |
171 | #define O_hw0_last_tls_gd O_md20 | |
172 | #define O_hw1_last_tls_gd O_md21 | |
173 | #define O_hw2_last_tls_gd O_md22 | |
174 | #define O_hw0_tls_ie O_md23 | |
175 | #define O_hw1_tls_ie O_md24 | |
176 | #define O_hw2_tls_ie O_md25 | |
177 | #define O_hw3_tls_ie O_md26 | |
178 | #define O_hw0_last_tls_ie O_md27 | |
179 | #define O_hw1_last_tls_ie O_md28 | |
180 | #define O_hw2_last_tls_ie O_md29 | |
181 | ||
182 | static struct hash_control *special_operator_hash; | |
183 | ||
184 | /* Hash tables for instruction mnemonic lookup. */ | |
185 | static struct hash_control *op_hash; | |
186 | ||
187 | /* Hash table for spr lookup. */ | |
188 | static struct hash_control *spr_hash; | |
189 | ||
190 | /* True temporarily while parsing an SPR expression. This changes the | |
191 | * namespace to include SPR names. */ | |
192 | static int parsing_spr; | |
193 | ||
194 | /* Are we currently inside `{ ... }'? */ | |
195 | static int inside_bundle; | |
196 | ||
197 | struct tilegx_instruction | |
198 | { | |
199 | const struct tilegx_opcode *opcode; | |
200 | tilegx_pipeline pipe; | |
201 | expressionS operand_values[TILEGX_MAX_OPERANDS]; | |
202 | }; | |
203 | ||
204 | /* This keeps track of the current bundle being built up. */ | |
205 | static struct tilegx_instruction current_bundle[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; | |
206 | ||
207 | /* Index in current_bundle for the next instruction to parse. */ | |
208 | static int current_bundle_index; | |
209 | ||
210 | /* Allow 'r63' in addition to 'zero', etc. Normally we disallow this as | |
211 | 'zero' is not a real register, so using it accidentally would be a | |
212 | nasty bug. For other registers, such as 'sp', code using multiple names | |
213 | for the same physical register is excessively confusing. | |
214 | ||
215 | The '.require_canonical_reg_names' pseudo-op turns this error on, | |
216 | and the '.no_require_canonical_reg_names' pseudo-op turns this off. | |
217 | By default the error is on. */ | |
218 | static int require_canonical_reg_names; | |
219 | ||
220 | /* Allow bundles that do undefined or suspicious things like write | |
221 | two different values to the same register at the same time. | |
222 | ||
223 | The '.no_allow_suspicious_bundles' pseudo-op turns this error on, | |
224 | and the '.allow_suspicious_bundles' pseudo-op turns this off. */ | |
225 | static int allow_suspicious_bundles; | |
226 | ||
227 | ||
228 | /* A hash table of main processor registers, mapping each register name | |
229 | to its index. | |
230 | ||
231 | Furthermore, if the register number is greater than the number | |
232 | of registers for that processor, the user used an illegal alias | |
233 | for that register (e.g. r63 instead of zero), so we should generate | |
234 | a warning. The attempted register number can be found by clearing | |
235 | NONCANONICAL_REG_NAME_FLAG. */ | |
236 | static struct hash_control *main_reg_hash; | |
237 | ||
238 | ||
239 | /* We cannot unambiguously store a 0 in a hash table and look it up, | |
240 | so we OR in this flag to every canonical register. */ | |
241 | #define CANONICAL_REG_NAME_FLAG 0x1000 | |
242 | ||
243 | /* By default we disallow register aliases like r63, but we record | |
244 | them in the hash table in case the .no_require_canonical_reg_names | |
245 | directive is used. Noncanonical names have this value added to them. */ | |
246 | #define NONCANONICAL_REG_NAME_FLAG 0x2000 | |
247 | ||
248 | /* Discards flags for register hash table entries and returns the | |
249 | reg number. */ | |
250 | #define EXTRACT_REGNO(p) ((p) & 63) | |
251 | ||
252 | /* This function is called once, at assembler startup time. It should | |
253 | set up all the tables, etc., that the MD part of the assembler will | |
254 | need. */ | |
255 | ||
256 | void | |
257 | md_begin (void) | |
258 | { | |
259 | const struct tilegx_opcode *op; | |
260 | int i; | |
82590249 WL |
261 | int mach = (tilegx_arch_size == 64) ? bfd_mach_tilegx : bfd_mach_tilegx32; |
262 | ||
263 | if (! bfd_set_arch_mach (stdoutput, bfd_arch_tilegx, mach)) | |
264 | as_warn (_("Could not set architecture and machine")); | |
aa137e4d NC |
265 | |
266 | /* Guarantee text section is aligned. */ | |
267 | bfd_set_section_alignment (stdoutput, text_section, | |
268 | TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES); | |
269 | ||
270 | require_canonical_reg_names = 1; | |
271 | allow_suspicious_bundles = 0; | |
272 | current_bundle_index = 0; | |
273 | inside_bundle = 0; | |
274 | ||
275 | tilegx_cie_data_alignment = (tilegx_arch_size == 64 ? -8 : -4); | |
276 | ||
277 | /* Initialize special operator hash table. */ | |
278 | special_operator_hash = hash_new (); | |
279 | #define INSERT_SPECIAL_OP(name) \ | |
280 | hash_insert (special_operator_hash, #name, (void *)O_##name) | |
281 | ||
282 | INSERT_SPECIAL_OP (hw0); | |
283 | INSERT_SPECIAL_OP (hw1); | |
284 | INSERT_SPECIAL_OP (hw2); | |
285 | INSERT_SPECIAL_OP (hw3); | |
286 | INSERT_SPECIAL_OP (hw0_last); | |
287 | INSERT_SPECIAL_OP (hw1_last); | |
288 | INSERT_SPECIAL_OP (hw2_last); | |
289 | /* hw3_last is a convenience alias for the equivalent hw3. */ | |
290 | hash_insert (special_operator_hash, "hw3_last", (void*)O_hw3); | |
291 | INSERT_SPECIAL_OP (hw0_got); | |
292 | INSERT_SPECIAL_OP (hw1_got); | |
293 | INSERT_SPECIAL_OP (hw2_got); | |
294 | INSERT_SPECIAL_OP (hw3_got); | |
295 | INSERT_SPECIAL_OP (hw0_last_got); | |
296 | INSERT_SPECIAL_OP (hw1_last_got); | |
297 | INSERT_SPECIAL_OP (hw2_last_got); | |
298 | INSERT_SPECIAL_OP(plt); | |
299 | INSERT_SPECIAL_OP (hw0_tls_gd); | |
300 | INSERT_SPECIAL_OP (hw1_tls_gd); | |
301 | INSERT_SPECIAL_OP (hw2_tls_gd); | |
302 | INSERT_SPECIAL_OP (hw3_tls_gd); | |
303 | INSERT_SPECIAL_OP (hw0_last_tls_gd); | |
304 | INSERT_SPECIAL_OP (hw1_last_tls_gd); | |
305 | INSERT_SPECIAL_OP (hw2_last_tls_gd); | |
306 | INSERT_SPECIAL_OP (hw0_tls_ie); | |
307 | INSERT_SPECIAL_OP (hw1_tls_ie); | |
308 | INSERT_SPECIAL_OP (hw2_tls_ie); | |
309 | INSERT_SPECIAL_OP (hw3_tls_ie); | |
310 | INSERT_SPECIAL_OP (hw0_last_tls_ie); | |
311 | INSERT_SPECIAL_OP (hw1_last_tls_ie); | |
312 | INSERT_SPECIAL_OP (hw2_last_tls_ie); | |
313 | #undef INSERT_SPECIAL_OP | |
314 | ||
315 | /* Initialize op_hash hash table. */ | |
316 | op_hash = hash_new (); | |
317 | for (op = &tilegx_opcodes[0]; op->name != NULL; op++) | |
318 | { | |
319 | const char *hash_err = hash_insert (op_hash, op->name, (void *)op); | |
320 | if (hash_err != NULL) | |
321 | as_fatal (_("Internal Error: Can't hash %s: %s"), op->name, hash_err); | |
322 | } | |
323 | ||
324 | /* Initialize the spr hash table. */ | |
325 | parsing_spr = 0; | |
326 | spr_hash = hash_new (); | |
327 | for (i = 0; i < tilegx_num_sprs; i++) | |
328 | hash_insert (spr_hash, tilegx_sprs[i].name, | |
329 | (void *) &tilegx_sprs[i]); | |
330 | ||
331 | /* Set up the main_reg_hash table. We use this instead of | |
332 | creating a symbol in the register section to avoid ambiguities | |
333 | with labels that have the same names as registers. */ | |
334 | main_reg_hash = hash_new (); | |
335 | for (i = 0; i < TILEGX_NUM_REGISTERS; i++) | |
336 | { | |
337 | char buf[64]; | |
338 | ||
339 | hash_insert (main_reg_hash, tilegx_register_names[i], | |
340 | (void *) (long) (i | CANONICAL_REG_NAME_FLAG)); | |
341 | ||
342 | /* See if we should insert a noncanonical alias, like r63. */ | |
343 | sprintf (buf, "r%d", i); | |
344 | if (strcmp (buf, tilegx_register_names[i]) != 0) | |
345 | hash_insert (main_reg_hash, xstrdup (buf), | |
346 | (void *) (long) (i | NONCANONICAL_REG_NAME_FLAG)); | |
347 | } | |
348 | } | |
349 | ||
350 | #define BUNDLE_TEMPLATE_MASK(p0, p1, p2) \ | |
351 | ((p0) | ((p1) << 8) | ((p2) << 16)) | |
352 | #define BUNDLE_TEMPLATE(p0, p1, p2) \ | |
353 | { { (p0), (p1), (p2) }, \ | |
354 | BUNDLE_TEMPLATE_MASK(1 << (p0), 1 << (p1), (1 << (p2))) \ | |
355 | } | |
356 | ||
357 | #define NO_PIPELINE TILEGX_NUM_PIPELINE_ENCODINGS | |
358 | ||
359 | struct bundle_template | |
360 | { | |
361 | tilegx_pipeline pipe[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; | |
362 | unsigned int pipe_mask; | |
363 | }; | |
364 | ||
365 | static const struct bundle_template bundle_templates[] = | |
366 | { | |
367 | /* In Y format we must always have something in Y2, since it has | |
368 | no fnop, so this conveys that Y2 must always be used. */ | |
369 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0, TILEGX_PIPELINE_Y2, NO_PIPELINE), | |
370 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1, TILEGX_PIPELINE_Y2, NO_PIPELINE), | |
371 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2, TILEGX_PIPELINE_Y0, NO_PIPELINE), | |
372 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2, TILEGX_PIPELINE_Y1, NO_PIPELINE), | |
373 | ||
374 | /* Y format has three instructions. */ | |
375 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y2), | |
376 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y1), | |
377 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y2), | |
378 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y0), | |
379 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y0,TILEGX_PIPELINE_Y1), | |
380 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_Y2,TILEGX_PIPELINE_Y1,TILEGX_PIPELINE_Y0), | |
381 | ||
382 | /* X format has only two instructions. */ | |
383 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_X0, TILEGX_PIPELINE_X1, NO_PIPELINE), | |
384 | BUNDLE_TEMPLATE(TILEGX_PIPELINE_X1, TILEGX_PIPELINE_X0, NO_PIPELINE) | |
385 | }; | |
386 | ||
387 | ||
388 | static void | |
389 | prepend_nop_to_bundle (tilegx_mnemonic mnemonic) | |
390 | { | |
391 | memmove (¤t_bundle[1], ¤t_bundle[0], | |
392 | current_bundle_index * sizeof current_bundle[0]); | |
393 | current_bundle[0].opcode = &tilegx_opcodes[mnemonic]; | |
394 | ++current_bundle_index; | |
395 | } | |
396 | ||
397 | static tilegx_bundle_bits | |
398 | insert_operand (tilegx_bundle_bits bits, | |
399 | const struct tilegx_operand *operand, | |
400 | int operand_value, | |
401 | char *file, | |
402 | unsigned lineno) | |
403 | { | |
404 | /* Range-check the immediate. */ | |
405 | int num_bits = operand->num_bits; | |
406 | ||
407 | operand_value >>= operand->rightshift; | |
408 | ||
409 | if (bfd_check_overflow (operand->is_signed | |
410 | ? complain_overflow_signed | |
411 | : complain_overflow_unsigned, | |
412 | num_bits, | |
413 | 0, | |
414 | bfd_arch_bits_per_address (stdoutput), | |
415 | operand_value) | |
416 | != bfd_reloc_ok) | |
417 | { | |
418 | offsetT min, max; | |
419 | if (operand->is_signed) | |
420 | { | |
421 | min = -(1 << (num_bits - 1)); | |
422 | max = (1 << (num_bits - 1)) - 1; | |
423 | } | |
424 | else | |
425 | { | |
426 | min = 0; | |
427 | max = (1 << num_bits) - 1; | |
428 | } | |
429 | as_bad_value_out_of_range (_("operand"), operand_value, min, max, | |
430 | file, lineno); | |
431 | } | |
432 | ||
433 | /* Write out the bits for the immediate. */ | |
434 | return bits | operand->insert (operand_value); | |
435 | } | |
436 | ||
437 | ||
438 | static int | |
439 | apply_special_operator (operatorT op, offsetT num, char *file, unsigned lineno) | |
440 | { | |
441 | int ret; | |
442 | int check_shift = -1; | |
443 | ||
444 | switch (op) | |
445 | { | |
446 | case O_hw0_last_tls_gd: | |
447 | case O_hw0_last_tls_ie: | |
448 | case O_hw0_last: | |
449 | check_shift = 0; | |
450 | /* Fall through. */ | |
451 | case O_hw0_tls_gd: | |
452 | case O_hw0_tls_ie: | |
453 | case O_hw0: | |
454 | ret = (signed short)num; | |
455 | break; | |
456 | ||
457 | case O_hw1_last_tls_gd: | |
458 | case O_hw1_last_tls_ie: | |
459 | case O_hw1_last: | |
460 | check_shift = 16; | |
461 | /* Fall through. */ | |
462 | case O_hw1_tls_gd: | |
463 | case O_hw1_tls_ie: | |
464 | case O_hw1: | |
465 | ret = (signed short)(num >> 16); | |
466 | break; | |
467 | ||
468 | case O_hw2_last_tls_gd: | |
469 | case O_hw2_last_tls_ie: | |
470 | case O_hw2_last: | |
471 | check_shift = 32; | |
472 | /* Fall through. */ | |
473 | case O_hw2_tls_gd: | |
474 | case O_hw2_tls_ie: | |
475 | case O_hw2: | |
476 | ret = (signed short)(num >> 32); | |
477 | break; | |
478 | ||
479 | case O_hw3_tls_gd: | |
480 | case O_hw3_tls_ie: | |
481 | case O_hw3: | |
482 | ret = (signed short)(num >> 48); | |
483 | break; | |
484 | ||
485 | default: | |
486 | abort (); | |
487 | break; | |
488 | } | |
489 | ||
490 | if (check_shift >= 0 && ret != (num >> check_shift)) | |
491 | { | |
492 | as_bad_value_out_of_range (_("operand"), num, | |
493 | ~0ULL << (check_shift + 16 - 1), | |
494 | ~0ULL >> (64 - (check_shift + 16 - 1)), | |
495 | file, lineno); | |
496 | } | |
497 | ||
498 | return ret; | |
499 | } | |
500 | ||
501 | static tilegx_bundle_bits | |
502 | emit_tilegx_instruction (tilegx_bundle_bits bits, | |
503 | int num_operands, | |
504 | const unsigned char *operands, | |
505 | expressionS *operand_values, | |
506 | char *bundle_start) | |
507 | { | |
508 | int i; | |
509 | ||
510 | for (i = 0; i < num_operands; i++) | |
511 | { | |
512 | const struct tilegx_operand *operand = | |
513 | &tilegx_operands[operands[i]]; | |
514 | expressionS *operand_exp = &operand_values[i]; | |
515 | int is_pc_relative = operand->is_pc_relative; | |
516 | ||
517 | if (operand_exp->X_op == O_register | |
518 | || (operand_exp->X_op == O_constant && !is_pc_relative)) | |
519 | { | |
520 | /* We know what the bits are right now, so insert them. */ | |
521 | bits = insert_operand (bits, operand, operand_exp->X_add_number, | |
522 | NULL, 0); | |
523 | } | |
524 | else | |
525 | { | |
526 | bfd_reloc_code_real_type reloc = operand->default_reloc; | |
527 | expressionS subexp; | |
528 | int die = 0, use_subexp = 0, require_symbol = 0; | |
529 | fixS *fixP; | |
530 | ||
531 | /* Take an expression like hw0(x) and turn it into x with | |
532 | a different reloc type. */ | |
533 | switch (operand_exp->X_op) | |
534 | { | |
535 | #define HANDLE_OP16(suffix) \ | |
536 | switch (reloc) \ | |
537 | { \ | |
538 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST: \ | |
539 | reloc = BFD_RELOC_TILEGX_IMM16_X0_##suffix; \ | |
540 | break; \ | |
541 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST: \ | |
542 | reloc = BFD_RELOC_TILEGX_IMM16_X1_##suffix; \ | |
543 | break; \ | |
544 | default: \ | |
545 | die = 1; \ | |
546 | break; \ | |
547 | } \ | |
548 | use_subexp = 1 | |
549 | ||
550 | case O_hw0: | |
551 | HANDLE_OP16 (HW0); | |
552 | break; | |
553 | ||
554 | case O_hw1: | |
555 | HANDLE_OP16 (HW1); | |
556 | break; | |
557 | ||
558 | case O_hw2: | |
559 | HANDLE_OP16 (HW2); | |
560 | break; | |
561 | ||
562 | case O_hw3: | |
563 | HANDLE_OP16 (HW3); | |
564 | break; | |
565 | ||
566 | case O_hw0_last: | |
567 | HANDLE_OP16 (HW0_LAST); | |
568 | break; | |
569 | ||
570 | case O_hw1_last: | |
571 | HANDLE_OP16 (HW1_LAST); | |
572 | break; | |
573 | ||
574 | case O_hw2_last: | |
575 | HANDLE_OP16 (HW2_LAST); | |
576 | break; | |
577 | ||
578 | case O_hw0_got: | |
579 | HANDLE_OP16 (HW0_GOT); | |
580 | require_symbol = 1; | |
581 | break; | |
582 | ||
583 | case O_hw1_got: | |
584 | HANDLE_OP16 (HW1_GOT); | |
585 | require_symbol = 1; | |
586 | break; | |
587 | ||
588 | case O_hw2_got: | |
589 | HANDLE_OP16 (HW2_GOT); | |
590 | require_symbol = 1; | |
591 | break; | |
592 | ||
593 | case O_hw3_got: | |
594 | HANDLE_OP16 (HW3_GOT); | |
595 | require_symbol = 1; | |
596 | break; | |
597 | ||
598 | case O_hw0_last_got: | |
599 | HANDLE_OP16 (HW0_LAST_GOT); | |
600 | require_symbol = 1; | |
601 | break; | |
602 | ||
603 | case O_hw1_last_got: | |
604 | HANDLE_OP16 (HW1_LAST_GOT); | |
605 | require_symbol = 1; | |
606 | break; | |
607 | ||
608 | case O_hw2_last_got: | |
609 | HANDLE_OP16 (HW2_LAST_GOT); | |
610 | require_symbol = 1; | |
611 | break; | |
612 | ||
613 | case O_hw0_tls_gd: | |
614 | HANDLE_OP16 (HW0_TLS_GD); | |
615 | require_symbol = 1; | |
616 | break; | |
617 | ||
618 | case O_hw1_tls_gd: | |
619 | HANDLE_OP16 (HW1_TLS_GD); | |
620 | require_symbol = 1; | |
621 | break; | |
622 | ||
623 | case O_hw2_tls_gd: | |
624 | HANDLE_OP16 (HW2_TLS_GD); | |
625 | require_symbol = 1; | |
626 | break; | |
627 | ||
628 | case O_hw3_tls_gd: | |
629 | HANDLE_OP16 (HW3_TLS_GD); | |
630 | require_symbol = 1; | |
631 | break; | |
632 | ||
633 | case O_hw0_last_tls_gd: | |
634 | HANDLE_OP16 (HW0_LAST_TLS_GD); | |
635 | require_symbol = 1; | |
636 | break; | |
637 | ||
638 | case O_hw1_last_tls_gd: | |
639 | HANDLE_OP16 (HW1_LAST_TLS_GD); | |
640 | require_symbol = 1; | |
641 | break; | |
642 | ||
643 | case O_hw2_last_tls_gd: | |
644 | HANDLE_OP16 (HW2_LAST_TLS_GD); | |
645 | require_symbol = 1; | |
646 | break; | |
647 | ||
648 | case O_hw0_tls_ie: | |
649 | HANDLE_OP16 (HW0_TLS_IE); | |
650 | require_symbol = 1; | |
651 | break; | |
652 | ||
653 | case O_hw1_tls_ie: | |
654 | HANDLE_OP16 (HW1_TLS_IE); | |
655 | require_symbol = 1; | |
656 | break; | |
657 | ||
658 | case O_hw2_tls_ie: | |
659 | HANDLE_OP16 (HW2_TLS_IE); | |
660 | require_symbol = 1; | |
661 | break; | |
662 | ||
663 | case O_hw3_tls_ie: | |
664 | HANDLE_OP16 (HW3_TLS_IE); | |
665 | require_symbol = 1; | |
666 | break; | |
667 | ||
668 | case O_hw0_last_tls_ie: | |
669 | HANDLE_OP16 (HW0_LAST_TLS_IE); | |
670 | require_symbol = 1; | |
671 | break; | |
672 | ||
673 | case O_hw1_last_tls_ie: | |
674 | HANDLE_OP16 (HW1_LAST_TLS_IE); | |
675 | require_symbol = 1; | |
676 | break; | |
677 | ||
678 | case O_hw2_last_tls_ie: | |
679 | HANDLE_OP16 (HW2_LAST_TLS_IE); | |
680 | require_symbol = 1; | |
681 | break; | |
682 | ||
683 | #undef HANDLE_OP16 | |
684 | ||
685 | case O_plt: | |
686 | switch (reloc) | |
687 | { | |
688 | case BFD_RELOC_TILEGX_JUMPOFF_X1: | |
689 | reloc = BFD_RELOC_TILEGX_JUMPOFF_X1_PLT; | |
690 | break; | |
691 | default: | |
692 | die = 1; | |
693 | break; | |
694 | } | |
695 | use_subexp = 1; | |
696 | require_symbol = 1; | |
697 | break; | |
698 | ||
699 | default: | |
700 | /* Do nothing. */ | |
701 | break; | |
702 | } | |
703 | ||
704 | if (die) | |
705 | { | |
706 | as_bad (_("Invalid operator for operand.")); | |
707 | } | |
708 | else if (use_subexp) | |
709 | { | |
710 | /* Now that we've changed the reloc, change ha16(x) into x, | |
711 | etc. */ | |
712 | ||
713 | if (operand_exp->X_add_symbol->sy_value.X_md) | |
714 | { | |
aa137e4d NC |
715 | /* HACK: We used X_md to mark this symbol as a fake wrapper |
716 | around a real expression. To unwrap it, we just grab its | |
717 | value here. */ | |
718 | operand_exp = &operand_exp->X_add_symbol->sy_value; | |
e8b9f508 WL |
719 | |
720 | if (require_symbol) | |
721 | { | |
722 | /* Look at the expression, and reject it if it's not a | |
723 | plain symbol. */ | |
724 | if (operand_exp->X_op != O_symbol | |
725 | || operand_exp->X_add_number != 0) | |
726 | as_bad (_("Operator may only be applied to symbols.")); | |
727 | } | |
aa137e4d NC |
728 | } |
729 | else | |
730 | { | |
731 | /* The value of this expression is an actual symbol, so | |
732 | turn that into an expression. */ | |
733 | memset (&subexp, 0, sizeof subexp); | |
734 | subexp.X_op = O_symbol; | |
735 | subexp.X_add_symbol = operand_exp->X_add_symbol; | |
736 | operand_exp = &subexp; | |
737 | } | |
738 | } | |
739 | ||
740 | /* Create a fixup to handle this later. */ | |
741 | fixP = fix_new_exp (frag_now, | |
742 | bundle_start - frag_now->fr_literal, | |
743 | (operand->num_bits + 7) >> 3, | |
744 | operand_exp, | |
745 | is_pc_relative, | |
746 | reloc); | |
747 | fixP->tc_fix_data = operand; | |
748 | ||
749 | /* Don't do overflow checking if we are applying a function like | |
750 | ha16. */ | |
751 | fixP->fx_no_overflow |= use_subexp; | |
752 | } | |
753 | } | |
754 | return bits; | |
755 | } | |
756 | ||
757 | ||
758 | /* Detects and complains if two instructions in current_bundle write | |
759 | to the same register, either implicitly or explicitly, or if a | |
760 | read-only register is written. */ | |
761 | static void | |
762 | check_illegal_reg_writes (void) | |
763 | { | |
764 | BFD_HOST_U_64_BIT all_regs_written = 0; | |
765 | int j; | |
766 | ||
767 | for (j = 0; j < current_bundle_index; j++) | |
768 | { | |
769 | const struct tilegx_instruction *instr = ¤t_bundle[j]; | |
770 | int k; | |
771 | BFD_HOST_U_64_BIT regs = | |
772 | ((BFD_HOST_U_64_BIT)1) << instr->opcode->implicitly_written_register; | |
773 | BFD_HOST_U_64_BIT conflict; | |
774 | ||
775 | for (k = 0; k < instr->opcode->num_operands; k++) | |
776 | { | |
777 | const struct tilegx_operand *operand = | |
778 | &tilegx_operands[instr->opcode->operands[instr->pipe][k]]; | |
779 | ||
780 | if (operand->is_dest_reg) | |
781 | { | |
782 | int regno = instr->operand_values[k].X_add_number; | |
783 | BFD_HOST_U_64_BIT mask = ((BFD_HOST_U_64_BIT)1) << regno; | |
784 | ||
785 | if ((mask & ( (((BFD_HOST_U_64_BIT)1) << TREG_IDN1) | |
786 | | (((BFD_HOST_U_64_BIT)1) << TREG_UDN1) | |
787 | | (((BFD_HOST_U_64_BIT)1) << TREG_UDN2) | |
788 | | (((BFD_HOST_U_64_BIT)1) << TREG_UDN3))) != 0 | |
789 | && !allow_suspicious_bundles) | |
790 | { | |
791 | as_bad (_("Writes to register '%s' are not allowed."), | |
792 | tilegx_register_names[regno]); | |
793 | } | |
794 | ||
795 | regs |= mask; | |
796 | } | |
797 | } | |
798 | ||
799 | /* Writing to the zero register doesn't count. */ | |
800 | regs &= ~(((BFD_HOST_U_64_BIT)1) << TREG_ZERO); | |
801 | ||
802 | conflict = all_regs_written & regs; | |
803 | if (conflict != 0 && !allow_suspicious_bundles) | |
804 | { | |
805 | /* Find which register caused the conflict. */ | |
806 | const char *conflicting_reg_name = "???"; | |
807 | int i; | |
808 | ||
809 | for (i = 0; i < TILEGX_NUM_REGISTERS; i++) | |
810 | { | |
811 | if (((conflict >> i) & 1) != 0) | |
812 | { | |
813 | conflicting_reg_name = tilegx_register_names[i]; | |
814 | break; | |
815 | } | |
816 | } | |
817 | ||
818 | as_bad (_("Two instructions in the same bundle both write " | |
819 | "to register %s, which is not allowed."), | |
820 | conflicting_reg_name); | |
821 | } | |
822 | ||
823 | all_regs_written |= regs; | |
824 | } | |
825 | } | |
826 | ||
827 | ||
828 | static void | |
829 | tilegx_flush_bundle (void) | |
830 | { | |
831 | unsigned i; | |
832 | int j; | |
833 | addressT addr_mod; | |
834 | unsigned compatible_pipes; | |
835 | const struct bundle_template *match; | |
836 | char *f; | |
837 | ||
838 | inside_bundle = 0; | |
839 | ||
840 | switch (current_bundle_index) | |
841 | { | |
842 | case 0: | |
843 | /* No instructions. */ | |
844 | return; | |
845 | case 1: | |
846 | if (current_bundle[0].opcode->can_bundle) | |
847 | { | |
848 | /* Simplify later logic by adding an explicit fnop. */ | |
849 | prepend_nop_to_bundle (TILEGX_OPC_FNOP); | |
850 | } | |
851 | else | |
852 | { | |
853 | /* This instruction cannot be bundled with anything else. | |
854 | Prepend an explicit 'nop', rather than an 'fnop', because | |
855 | fnops can be replaced by later binary-processing tools while | |
856 | nops cannot. */ | |
857 | prepend_nop_to_bundle (TILEGX_OPC_NOP); | |
858 | } | |
859 | break; | |
860 | default: | |
861 | if (!allow_suspicious_bundles) | |
862 | { | |
863 | /* Make sure all instructions can be bundled with other | |
864 | instructions. */ | |
865 | const struct tilegx_opcode *cannot_bundle = NULL; | |
866 | bfd_boolean seen_non_nop = FALSE; | |
867 | ||
868 | for (j = 0; j < current_bundle_index; j++) | |
869 | { | |
870 | const struct tilegx_opcode *op = current_bundle[j].opcode; | |
871 | ||
872 | if (!op->can_bundle && cannot_bundle == NULL) | |
873 | cannot_bundle = op; | |
874 | else if (op->mnemonic != TILEGX_OPC_NOP | |
875 | && op->mnemonic != TILEGX_OPC_INFO | |
876 | && op->mnemonic != TILEGX_OPC_INFOL) | |
877 | seen_non_nop = TRUE; | |
878 | } | |
879 | ||
880 | if (cannot_bundle != NULL && seen_non_nop) | |
881 | { | |
882 | current_bundle_index = 0; | |
883 | as_bad (_("'%s' may not be bundled with other instructions."), | |
884 | cannot_bundle->name); | |
885 | return; | |
886 | } | |
887 | } | |
888 | break; | |
889 | } | |
890 | ||
891 | compatible_pipes = | |
892 | BUNDLE_TEMPLATE_MASK(current_bundle[0].opcode->pipes, | |
893 | current_bundle[1].opcode->pipes, | |
894 | (current_bundle_index == 3 | |
895 | ? current_bundle[2].opcode->pipes | |
896 | : (1 << NO_PIPELINE))); | |
897 | ||
898 | /* Find a template that works, if any. */ | |
899 | match = NULL; | |
900 | for (i = 0; i < sizeof bundle_templates / sizeof bundle_templates[0]; i++) | |
901 | { | |
902 | const struct bundle_template *b = &bundle_templates[i]; | |
903 | if ((b->pipe_mask & compatible_pipes) == b->pipe_mask) | |
904 | { | |
905 | match = b; | |
906 | break; | |
907 | } | |
908 | } | |
909 | ||
910 | if (match == NULL) | |
911 | { | |
912 | current_bundle_index = 0; | |
913 | as_bad (_("Invalid combination of instructions for bundle.")); | |
914 | return; | |
915 | } | |
916 | ||
917 | /* If the section seems to have no alignment set yet, go ahead and | |
918 | make it large enough to hold code. */ | |
919 | if (bfd_get_section_alignment (stdoutput, now_seg) == 0) | |
920 | bfd_set_section_alignment (stdoutput, now_seg, | |
921 | TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES); | |
922 | ||
923 | for (j = 0; j < current_bundle_index; j++) | |
924 | current_bundle[j].pipe = match->pipe[j]; | |
925 | ||
926 | if (current_bundle_index == 2 && !tilegx_is_x_pipeline (match->pipe[0])) | |
927 | { | |
928 | /* We are in Y mode with only two instructions, so add an FNOP. */ | |
929 | prepend_nop_to_bundle (TILEGX_OPC_FNOP); | |
930 | ||
931 | /* Figure out what pipe the fnop must be in via arithmetic. | |
932 | * p0 + p1 + p2 must sum to the sum of TILEGX_PIPELINE_Y[012]. */ | |
933 | current_bundle[0].pipe = | |
934 | (tilegx_pipeline)((TILEGX_PIPELINE_Y0 | |
935 | + TILEGX_PIPELINE_Y1 | |
936 | + TILEGX_PIPELINE_Y2) - | |
937 | (current_bundle[1].pipe + current_bundle[2].pipe)); | |
938 | } | |
939 | ||
940 | check_illegal_reg_writes (); | |
941 | ||
942 | f = frag_more (TILEGX_BUNDLE_SIZE_IN_BYTES); | |
943 | ||
944 | /* Check to see if this bundle is at an offset that is a multiple of 8-bytes | |
945 | from the start of the frag. */ | |
946 | addr_mod = frag_now_fix () & (TILEGX_BUNDLE_ALIGNMENT_IN_BYTES - 1); | |
947 | if (frag_now->has_code && frag_now->insn_addr != addr_mod) | |
948 | as_bad (_("instruction address is not a multiple of 8")); | |
949 | frag_now->insn_addr = addr_mod; | |
950 | frag_now->has_code = 1; | |
951 | ||
952 | tilegx_bundle_bits bits = 0; | |
953 | for (j = 0; j < current_bundle_index; j++) | |
954 | { | |
955 | struct tilegx_instruction *instr = ¤t_bundle[j]; | |
956 | tilegx_pipeline pipeline = instr->pipe; | |
957 | const struct tilegx_opcode *opcode = instr->opcode; | |
958 | ||
959 | bits |= emit_tilegx_instruction (opcode->fixed_bit_values[pipeline], | |
960 | opcode->num_operands, | |
961 | &opcode->operands[pipeline][0], | |
962 | instr->operand_values, | |
963 | f); | |
964 | } | |
965 | ||
966 | number_to_chars_littleendian (f, bits, 8); | |
967 | current_bundle_index = 0; | |
968 | ||
969 | /* Emit DWARF2 debugging information. */ | |
970 | dwarf2_emit_insn (TILEGX_BUNDLE_SIZE_IN_BYTES); | |
971 | } | |
972 | ||
973 | ||
974 | /* Extend the expression parser to handle hw0(label), etc. | |
975 | as well as SPR names when in the context of parsing an SPR. */ | |
976 | ||
977 | int | |
978 | tilegx_parse_name (char *name, expressionS *e, char *nextcharP) | |
979 | { | |
980 | operatorT op = O_illegal; | |
981 | ||
982 | if (parsing_spr) | |
983 | { | |
984 | void* val = hash_find (spr_hash, name); | |
985 | if (val == NULL) | |
986 | return 0; | |
987 | ||
988 | memset (e, 0, sizeof *e); | |
989 | e->X_op = O_constant; | |
990 | e->X_add_number = ((const struct tilegx_spr *)val)->number; | |
991 | return 1; | |
992 | } | |
993 | ||
994 | if (*nextcharP != '(') | |
995 | { | |
996 | /* hw0, etc. not followed by a paren is just a label with that name. */ | |
997 | return 0; | |
998 | } | |
999 | else | |
1000 | { | |
1001 | /* Look up the operator in our table. */ | |
1002 | void* val = hash_find (special_operator_hash, name); | |
1003 | if (val == 0) | |
1004 | return 0; | |
1005 | op = (operatorT)(long)val; | |
1006 | } | |
1007 | ||
1008 | /* Restore old '(' and skip it. */ | |
1009 | *input_line_pointer = '('; | |
1010 | ++input_line_pointer; | |
1011 | ||
1012 | expression (e); | |
1013 | ||
1014 | if (*input_line_pointer != ')') | |
1015 | { | |
1016 | as_bad (_("Missing ')'")); | |
1017 | *nextcharP = *input_line_pointer; | |
1018 | return 0; | |
1019 | } | |
1020 | /* Skip ')'. */ | |
1021 | ++input_line_pointer; | |
1022 | ||
1023 | if (e->X_op == O_register || e->X_op == O_absent) | |
1024 | { | |
1025 | as_bad (_("Invalid expression.")); | |
1026 | e->X_op = O_constant; | |
1027 | e->X_add_number = 0; | |
1028 | } | |
1029 | else | |
1030 | { | |
1031 | /* Wrap subexpression with a unary operator. */ | |
1032 | symbolS *sym = make_expr_symbol (e); | |
1033 | ||
1034 | if (sym != e->X_add_symbol) | |
1035 | { | |
1036 | /* HACK: mark this symbol as a temporary wrapper around a proper | |
1037 | expression, so we can unwrap it later once we have communicated | |
1038 | the relocation type. */ | |
1039 | sym->sy_value.X_md = 1; | |
1040 | } | |
1041 | ||
1042 | memset (e, 0, sizeof *e); | |
1043 | e->X_op = op; | |
1044 | e->X_add_symbol = sym; | |
1045 | e->X_add_number = 0; | |
1046 | } | |
1047 | ||
1048 | *nextcharP = *input_line_pointer; | |
1049 | return 1; | |
1050 | } | |
1051 | ||
1052 | ||
1053 | /* Parses an expression which must be a register name. */ | |
1054 | ||
1055 | static void | |
1056 | parse_reg_expression (expressionS* expression) | |
1057 | { | |
1058 | /* Zero everything to make sure we don't miss any flags. */ | |
1059 | memset (expression, 0, sizeof *expression); | |
1060 | ||
1061 | char* regname = input_line_pointer; | |
1062 | char terminating_char = get_symbol_end (); | |
1063 | ||
1064 | void* pval = hash_find (main_reg_hash, regname); | |
1065 | ||
1066 | if (pval == NULL) | |
1067 | { | |
1068 | as_bad (_("Expected register, got '%s'."), regname); | |
1069 | } | |
1070 | ||
1071 | int regno_and_flags = (int)(size_t)pval; | |
1072 | int regno = EXTRACT_REGNO(regno_and_flags); | |
1073 | ||
1074 | if ((regno_and_flags & NONCANONICAL_REG_NAME_FLAG) | |
1075 | && require_canonical_reg_names) | |
1076 | { | |
1077 | as_warn (_("Found use of non-canonical register name %s; " | |
1078 | "use %s instead."), | |
1079 | regname, | |
1080 | tilegx_register_names[regno]); | |
1081 | } | |
1082 | ||
1083 | /* Restore the old character following the register name. */ | |
1084 | *input_line_pointer = terminating_char; | |
1085 | ||
1086 | /* Fill in the expression fields to indicate it's a register. */ | |
1087 | expression->X_op = O_register; | |
1088 | expression->X_add_number = regno; | |
1089 | } | |
1090 | ||
1091 | ||
1092 | /* Parses and type-checks comma-separated operands in input_line_pointer. */ | |
1093 | ||
1094 | static void | |
1095 | parse_operands (const char *opcode_name, | |
1096 | const unsigned char *operands, | |
1097 | int num_operands, | |
1098 | expressionS *operand_values) | |
1099 | { | |
1100 | int i; | |
1101 | ||
1102 | memset (operand_values, 0, num_operands * sizeof operand_values[0]); | |
1103 | ||
1104 | SKIP_WHITESPACE (); | |
1105 | for (i = 0; i < num_operands; i++) | |
1106 | { | |
1107 | tilegx_operand_type type = tilegx_operands[operands[i]].type; | |
1108 | ||
1109 | SKIP_WHITESPACE (); | |
1110 | ||
1111 | if (type == TILEGX_OP_TYPE_REGISTER) | |
1112 | { | |
1113 | parse_reg_expression (&operand_values[i]); | |
1114 | } | |
1115 | else if (*input_line_pointer == '}') | |
1116 | { | |
1117 | operand_values[i].X_op = O_absent; | |
1118 | } | |
1119 | else if (type == TILEGX_OP_TYPE_SPR) | |
1120 | { | |
1121 | /* Modify the expression parser to add SPRs to the namespace. */ | |
1122 | parsing_spr = 1; | |
1123 | expression (&operand_values[i]); | |
1124 | parsing_spr = 0; | |
1125 | } | |
1126 | else | |
1127 | { | |
1128 | expression (&operand_values[i]); | |
1129 | } | |
1130 | ||
1131 | SKIP_WHITESPACE (); | |
1132 | ||
1133 | if (i + 1 < num_operands) | |
1134 | { | |
1135 | int separator = (unsigned char)*input_line_pointer++; | |
1136 | ||
1137 | if (is_end_of_line[separator] || (separator == '}')) | |
1138 | { | |
1139 | as_bad (_("Too few operands to '%s'."), opcode_name); | |
1140 | return; | |
1141 | } | |
1142 | else if (separator != ',') | |
1143 | { | |
1144 | as_bad (_("Unexpected character '%c' after operand %d to %s."), | |
1145 | (char)separator, i + 1, opcode_name); | |
1146 | return; | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | /* Arbitrarily use the first valid pipe to get the operand type, | |
1151 | since they are all the same. */ | |
1152 | switch (tilegx_operands[operands[i]].type) | |
1153 | { | |
1154 | case TILEGX_OP_TYPE_REGISTER: | |
1155 | /* Handled in parse_reg_expression already. */ | |
1156 | break; | |
1157 | case TILEGX_OP_TYPE_SPR: | |
1158 | /* Fall through */ | |
1159 | case TILEGX_OP_TYPE_IMMEDIATE: | |
1160 | /* Fall through */ | |
1161 | case TILEGX_OP_TYPE_ADDRESS: | |
1162 | if ( operand_values[i].X_op == O_register | |
1163 | || operand_values[i].X_op == O_illegal | |
1164 | || operand_values[i].X_op == O_absent) | |
1165 | as_bad (_("Expected immediate expression")); | |
1166 | break; | |
1167 | default: | |
1168 | abort(); | |
1169 | } | |
1170 | } | |
1171 | ||
1172 | if (!is_end_of_line[(unsigned char)*input_line_pointer]) | |
1173 | { | |
1174 | switch (*input_line_pointer) | |
1175 | { | |
1176 | case '}': | |
1177 | if (!inside_bundle) | |
1178 | as_bad (_("Found '}' when not bundling.")); | |
1179 | ++input_line_pointer; | |
1180 | inside_bundle = 0; | |
1181 | demand_empty_rest_of_line (); | |
1182 | break; | |
1183 | ||
1184 | case ',': | |
1185 | as_bad (_("Too many operands")); | |
1186 | break; | |
1187 | ||
1188 | default: | |
1189 | /* Use default error for unrecognized garbage. */ | |
1190 | demand_empty_rest_of_line (); | |
1191 | break; | |
1192 | } | |
1193 | } | |
1194 | } | |
1195 | ||
1196 | ||
1197 | /* This is the guts of the machine-dependent assembler. STR points to a | |
1198 | machine dependent instruction. This function is supposed to emit the | |
1199 | frags/bytes it assembles to. */ | |
1200 | ||
1201 | void | |
1202 | md_assemble (char *str) | |
1203 | { | |
1204 | char old_char; | |
1205 | size_t opname_len; | |
1206 | char *old_input_line_pointer; | |
1207 | const struct tilegx_opcode *op; | |
1208 | int first_pipe; | |
1209 | ||
1210 | /* Split off the opcode and look it up. */ | |
1211 | opname_len = strcspn (str, " {}"); | |
1212 | old_char = str[opname_len]; | |
1213 | str[opname_len] = '\0'; | |
1214 | ||
1215 | op = hash_find(op_hash, str); | |
1216 | str[opname_len] = old_char; | |
1217 | if (op == NULL) | |
1218 | { | |
1219 | as_bad (_("Unknown opcode `%.*s'."), (int)opname_len, str); | |
1220 | return; | |
1221 | } | |
1222 | ||
1223 | /* Prepare to parse the operands. */ | |
1224 | old_input_line_pointer = input_line_pointer; | |
1225 | input_line_pointer = str + opname_len; | |
1226 | SKIP_WHITESPACE (); | |
1227 | ||
1228 | if (current_bundle_index == TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE) | |
1229 | { | |
1230 | as_bad (_("Too many instructions for bundle.")); | |
1231 | tilegx_flush_bundle (); | |
1232 | } | |
1233 | ||
1234 | /* Make sure we have room for the upcoming bundle before we | |
1235 | create any fixups. Otherwise if we have to switch to a new | |
1236 | frag the fixup dot_value fields will be wrong. */ | |
1237 | frag_grow (TILEGX_BUNDLE_SIZE_IN_BYTES); | |
1238 | ||
1239 | /* Find a valid pipe for this opcode. */ | |
1240 | for (first_pipe = 0; (op->pipes & (1 << first_pipe)) == 0; first_pipe++) | |
1241 | ; | |
1242 | ||
1243 | /* Call the function that assembles this instruction. */ | |
1244 | current_bundle[current_bundle_index].opcode = op; | |
1245 | parse_operands (op->name, | |
1246 | &op->operands[first_pipe][0], | |
1247 | op->num_operands, | |
1248 | current_bundle[current_bundle_index].operand_values); | |
1249 | ++current_bundle_index; | |
1250 | ||
1251 | /* Restore the saved value of input_line_pointer. */ | |
1252 | input_line_pointer = old_input_line_pointer; | |
1253 | ||
1254 | /* If we weren't inside curly braces, go ahead and emit | |
1255 | this lone instruction as a bundle right now. */ | |
1256 | if (!inside_bundle) | |
1257 | tilegx_flush_bundle (); | |
1258 | } | |
1259 | ||
1260 | ||
1261 | static void | |
1262 | s_require_canonical_reg_names (int require) | |
1263 | { | |
1264 | demand_empty_rest_of_line (); | |
1265 | require_canonical_reg_names = require; | |
1266 | } | |
1267 | ||
1268 | static void | |
1269 | s_allow_suspicious_bundles (int allow) | |
1270 | { | |
1271 | demand_empty_rest_of_line (); | |
1272 | allow_suspicious_bundles = allow; | |
1273 | } | |
1274 | ||
1275 | const pseudo_typeS md_pseudo_table[] = | |
1276 | { | |
1277 | {"align", s_align_bytes, 0}, /* Defaulting is invalid (0). */ | |
1278 | {"word", cons, 4}, | |
1279 | {"require_canonical_reg_names", s_require_canonical_reg_names, 1 }, | |
1280 | {"no_require_canonical_reg_names", s_require_canonical_reg_names, 0 }, | |
1281 | {"allow_suspicious_bundles", s_allow_suspicious_bundles, 1 }, | |
1282 | {"no_allow_suspicious_bundles", s_allow_suspicious_bundles, 0 }, | |
1283 | { NULL, 0, 0 } | |
1284 | }; | |
1285 | ||
1286 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
1287 | #define MAX_LITTLENUMS 6 | |
1288 | ||
fb6cedde WL |
1289 | void |
1290 | md_number_to_chars (char * buf, valueT val, int n) | |
1291 | { | |
1292 | if (target_big_endian) | |
1293 | number_to_chars_bigendian (buf, val, n); | |
1294 | else | |
1295 | number_to_chars_littleendian (buf, val, n); | |
1296 | } | |
1297 | ||
aa137e4d NC |
1298 | /* Turn the string pointed to by litP into a floating point constant |
1299 | of type TYPE, and emit the appropriate bytes. The number of | |
1300 | LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1301 | returned, or NULL on OK. */ | |
1302 | ||
1303 | char * | |
1304 | md_atof (int type, char *litP, int *sizeP) | |
1305 | { | |
1306 | int prec; | |
1307 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1308 | LITTLENUM_TYPE *wordP; | |
1309 | char *t; | |
1310 | ||
1311 | switch (type) | |
1312 | { | |
1313 | case 'f': | |
1314 | case 'F': | |
1315 | prec = 2; | |
1316 | break; | |
1317 | ||
1318 | case 'd': | |
1319 | case 'D': | |
1320 | prec = 4; | |
1321 | break; | |
1322 | ||
1323 | default: | |
1324 | *sizeP = 0; | |
1325 | return _("Bad call to md_atof ()"); | |
1326 | } | |
1327 | t = atof_ieee (input_line_pointer, type, words); | |
1328 | if (t) | |
1329 | input_line_pointer = t; | |
1330 | ||
1331 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
1332 | /* This loops outputs the LITTLENUMs in REVERSE order; in accord with | |
1333 | the bigendian 386. */ | |
1334 | for (wordP = words + prec - 1; prec--;) | |
1335 | { | |
1336 | md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE)); | |
1337 | litP += sizeof (LITTLENUM_TYPE); | |
1338 | } | |
1339 | return 0; | |
1340 | } | |
1341 | ||
1342 | ||
1343 | /* We have no need to default values of symbols. */ | |
1344 | ||
1345 | symbolS * | |
1346 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) | |
1347 | { | |
1348 | return NULL; | |
1349 | } | |
1350 | ||
1351 | ||
1352 | void | |
1353 | tilegx_cons_fix_new (fragS *frag, | |
1354 | int where, | |
1355 | int nbytes, | |
1356 | expressionS *exp) | |
1357 | { | |
1358 | expressionS subexp; | |
1359 | bfd_reloc_code_real_type reloc = BFD_RELOC_NONE; | |
1360 | int no_overflow = 0; | |
1361 | fixS *fixP; | |
1362 | ||
1363 | /* See if it's one of our special functions. */ | |
1364 | switch (exp->X_op) | |
1365 | { | |
1366 | case O_hw0: | |
1367 | reloc = BFD_RELOC_TILEGX_HW0; | |
1368 | no_overflow = 1; | |
1369 | break; | |
1370 | case O_hw1: | |
1371 | reloc = BFD_RELOC_TILEGX_HW1; | |
1372 | no_overflow = 1; | |
1373 | break; | |
1374 | case O_hw2: | |
1375 | reloc = BFD_RELOC_TILEGX_HW2; | |
1376 | no_overflow = 1; | |
1377 | break; | |
1378 | case O_hw3: | |
1379 | reloc = BFD_RELOC_TILEGX_HW3; | |
1380 | no_overflow = 1; | |
1381 | break; | |
1382 | case O_hw0_last: | |
1383 | reloc = BFD_RELOC_TILEGX_HW0_LAST; | |
1384 | break; | |
1385 | case O_hw1_last: | |
1386 | reloc = BFD_RELOC_TILEGX_HW1_LAST; | |
1387 | break; | |
1388 | case O_hw2_last: | |
1389 | reloc = BFD_RELOC_TILEGX_HW2_LAST; | |
1390 | break; | |
1391 | ||
1392 | default: | |
1393 | /* Do nothing. */ | |
1394 | break; | |
1395 | } | |
1396 | ||
1397 | if (reloc != BFD_RELOC_NONE) | |
1398 | { | |
1399 | if (nbytes != 2) | |
1400 | { | |
1401 | as_bad (_("This operator only produces two byte values.")); | |
1402 | nbytes = 2; | |
1403 | } | |
1404 | ||
1405 | memset (&subexp, 0, sizeof subexp); | |
1406 | subexp.X_op = O_symbol; | |
1407 | subexp.X_add_symbol = exp->X_add_symbol; | |
1408 | exp = &subexp; | |
1409 | } | |
1410 | else | |
1411 | { | |
1412 | switch (nbytes) | |
1413 | { | |
1414 | case 1: | |
1415 | reloc = BFD_RELOC_8; | |
1416 | break; | |
1417 | case 2: | |
1418 | reloc = BFD_RELOC_16; | |
1419 | break; | |
1420 | case 4: | |
1421 | reloc = BFD_RELOC_32; | |
1422 | break; | |
1423 | case 8: | |
1424 | reloc = BFD_RELOC_64; | |
1425 | break; | |
1426 | default: | |
1427 | as_bad (_("unsupported BFD relocation size %d"), nbytes); | |
1428 | reloc = BFD_RELOC_64; | |
1429 | break; | |
1430 | } | |
1431 | } | |
1432 | ||
1433 | fixP = fix_new_exp (frag, where, nbytes, exp, 0, reloc); | |
1434 | fixP->tc_fix_data = NULL; | |
1435 | fixP->fx_no_overflow |= no_overflow; | |
1436 | } | |
1437 | ||
1438 | ||
1439 | void | |
1440 | md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED) | |
1441 | { | |
1442 | const struct tilegx_operand *operand; | |
1443 | valueT value = *valP; | |
1444 | operatorT special; | |
1445 | char *p; | |
1446 | ||
1447 | /* Leave these for the linker. */ | |
1448 | if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
1449 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
1450 | return; | |
1451 | ||
1452 | if (fixP->fx_subsy != (symbolS *) NULL) | |
1453 | { | |
1454 | /* We can't actually support subtracting a symbol. */ | |
1455 | as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex")); | |
1456 | } | |
1457 | ||
1458 | /* Correct relocation types for pc-relativeness. */ | |
1459 | switch (fixP->fx_r_type) | |
1460 | { | |
1461 | #define FIX_PCREL(rtype) \ | |
1462 | case rtype: \ | |
1463 | if (fixP->fx_pcrel) \ | |
1464 | fixP->fx_r_type = rtype##_PCREL; \ | |
1465 | break; \ | |
1466 | \ | |
1467 | case rtype##_PCREL: \ | |
1468 | if (!fixP->fx_pcrel) \ | |
1469 | fixP->fx_r_type = rtype; \ | |
1470 | break | |
1471 | ||
1472 | FIX_PCREL (BFD_RELOC_8); | |
1473 | FIX_PCREL (BFD_RELOC_16); | |
1474 | FIX_PCREL (BFD_RELOC_32); | |
1475 | FIX_PCREL (BFD_RELOC_64); | |
1476 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0); | |
1477 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0); | |
1478 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1); | |
1479 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1); | |
1480 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2); | |
1481 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2); | |
1482 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW3); | |
1483 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW3); | |
1484 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST); | |
1485 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST); | |
1486 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST); | |
1487 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST); | |
1488 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST); | |
1489 | FIX_PCREL (BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST); | |
1490 | ||
1491 | #undef FIX_PCREL | |
1492 | ||
1493 | default: | |
1494 | /* Do nothing */ | |
1495 | break; | |
1496 | } | |
1497 | ||
1498 | if (fixP->fx_addsy != NULL) | |
1499 | { | |
1500 | #ifdef OBJ_ELF | |
1501 | switch (fixP->fx_r_type) | |
1502 | { | |
1503 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD: | |
1504 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD: | |
1505 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE: | |
1506 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE: | |
1507 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD: | |
1508 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD: | |
1509 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE: | |
1510 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE: | |
1511 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_GD: | |
1512 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_GD: | |
1513 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_IE: | |
1514 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_IE: | |
1515 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD: | |
1516 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD: | |
1517 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE: | |
1518 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE: | |
1519 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_GD: | |
1520 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_GD: | |
1521 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_IE: | |
1522 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_IE: | |
1523 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_GD: | |
1524 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_GD: | |
1525 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_IE: | |
1526 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_IE: | |
1527 | case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_GD: | |
1528 | case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_GD: | |
1529 | case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_IE: | |
1530 | case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_IE: | |
1531 | case BFD_RELOC_TILEGX_TLS_DTPMOD64: | |
1532 | case BFD_RELOC_TILEGX_TLS_DTPOFF64: | |
1533 | case BFD_RELOC_TILEGX_TLS_TPOFF64: | |
1534 | case BFD_RELOC_TILEGX_TLS_DTPMOD32: | |
1535 | case BFD_RELOC_TILEGX_TLS_DTPOFF32: | |
1536 | case BFD_RELOC_TILEGX_TLS_TPOFF32: | |
1537 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
1538 | break; | |
1539 | ||
1540 | default: | |
1541 | /* Do nothing */ | |
1542 | break; | |
1543 | } | |
1544 | #endif | |
1545 | return; | |
1546 | } | |
1547 | ||
1548 | /* Apply hw0, etc. */ | |
1549 | special = O_illegal; | |
1550 | switch (fixP->fx_r_type) | |
1551 | { | |
1552 | case BFD_RELOC_TILEGX_HW0: | |
1553 | case BFD_RELOC_TILEGX_IMM16_X0_HW0: | |
1554 | case BFD_RELOC_TILEGX_IMM16_X1_HW0: | |
1555 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_PCREL: | |
1556 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_PCREL: | |
1557 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_GOT: | |
1558 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_GOT: | |
1559 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_GD: | |
1560 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_GD: | |
1561 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_TLS_IE: | |
1562 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_TLS_IE: | |
1563 | special = O_hw0; | |
1564 | break; | |
1565 | ||
1566 | case BFD_RELOC_TILEGX_HW0_LAST: | |
1567 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST: | |
1568 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST: | |
1569 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_PCREL: | |
1570 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_PCREL: | |
1571 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_GOT: | |
1572 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_GOT: | |
1573 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_GD: | |
1574 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_GD: | |
1575 | case BFD_RELOC_TILEGX_IMM16_X0_HW0_LAST_TLS_IE: | |
1576 | case BFD_RELOC_TILEGX_IMM16_X1_HW0_LAST_TLS_IE: | |
1577 | special = O_hw0_last; | |
1578 | break; | |
1579 | ||
1580 | case BFD_RELOC_TILEGX_HW1: | |
1581 | case BFD_RELOC_TILEGX_IMM16_X0_HW1: | |
1582 | case BFD_RELOC_TILEGX_IMM16_X1_HW1: | |
1583 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_PCREL: | |
1584 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_PCREL: | |
1585 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_GOT: | |
1586 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_GOT: | |
1587 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_GD: | |
1588 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_GD: | |
1589 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_TLS_IE: | |
1590 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_TLS_IE: | |
1591 | special = O_hw1; | |
1592 | break; | |
1593 | ||
1594 | case BFD_RELOC_TILEGX_HW1_LAST: | |
1595 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST: | |
1596 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST: | |
1597 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_PCREL: | |
1598 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_PCREL: | |
1599 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_GOT: | |
1600 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_GOT: | |
1601 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_GD: | |
1602 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_GD: | |
1603 | case BFD_RELOC_TILEGX_IMM16_X0_HW1_LAST_TLS_IE: | |
1604 | case BFD_RELOC_TILEGX_IMM16_X1_HW1_LAST_TLS_IE: | |
1605 | special = O_hw1_last; | |
1606 | break; | |
1607 | ||
1608 | case BFD_RELOC_TILEGX_HW2: | |
1609 | case BFD_RELOC_TILEGX_IMM16_X0_HW2: | |
1610 | case BFD_RELOC_TILEGX_IMM16_X1_HW2: | |
1611 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_PCREL: | |
1612 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_PCREL: | |
1613 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_GOT: | |
1614 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_GOT: | |
1615 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_GD: | |
1616 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_GD: | |
1617 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_TLS_IE: | |
1618 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_TLS_IE: | |
1619 | special = O_hw2; | |
1620 | break; | |
1621 | ||
1622 | case BFD_RELOC_TILEGX_HW2_LAST: | |
1623 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST: | |
1624 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST: | |
1625 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_PCREL: | |
1626 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_PCREL: | |
1627 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_GOT: | |
1628 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_GOT: | |
1629 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_GD: | |
1630 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_GD: | |
1631 | case BFD_RELOC_TILEGX_IMM16_X0_HW2_LAST_TLS_IE: | |
1632 | case BFD_RELOC_TILEGX_IMM16_X1_HW2_LAST_TLS_IE: | |
1633 | special = O_hw2_last; | |
1634 | break; | |
1635 | ||
1636 | case BFD_RELOC_TILEGX_HW3: | |
1637 | case BFD_RELOC_TILEGX_IMM16_X0_HW3: | |
1638 | case BFD_RELOC_TILEGX_IMM16_X1_HW3: | |
1639 | case BFD_RELOC_TILEGX_IMM16_X0_HW3_PCREL: | |
1640 | case BFD_RELOC_TILEGX_IMM16_X1_HW3_PCREL: | |
1641 | case BFD_RELOC_TILEGX_IMM16_X0_HW3_GOT: | |
1642 | case BFD_RELOC_TILEGX_IMM16_X1_HW3_GOT: | |
1643 | case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_GD: | |
1644 | case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_GD: | |
1645 | case BFD_RELOC_TILEGX_IMM16_X0_HW3_TLS_IE: | |
1646 | case BFD_RELOC_TILEGX_IMM16_X1_HW3_TLS_IE: | |
1647 | special = O_hw3; | |
1648 | break; | |
1649 | ||
1650 | default: | |
1651 | /* Do nothing */ | |
1652 | break; | |
1653 | } | |
1654 | ||
1655 | if (special != O_illegal) | |
1656 | { | |
1657 | *valP = value = apply_special_operator (special, value, | |
1658 | fixP->fx_file, fixP->fx_line); | |
1659 | } | |
1660 | ||
1661 | p = fixP->fx_frag->fr_literal + fixP->fx_where; | |
1662 | ||
1663 | operand = fixP->tc_fix_data; | |
1664 | if (operand != NULL) | |
1665 | { | |
1666 | /* It's an instruction operand. */ | |
1667 | tilegx_bundle_bits bits = | |
1668 | insert_operand (0, operand, value, fixP->fx_file, fixP->fx_line); | |
1669 | ||
1670 | /* Note that we might either be writing out bits for a bundle | |
1671 | or a static network instruction, which are different sizes, so it's | |
1672 | important to stop touching memory once we run out of bits. | |
1673 | ORing in values is OK since we know the existing bits for | |
1674 | this operand are zero. */ | |
1675 | for (; bits != 0; bits >>= 8) | |
1676 | *p++ |= (char)bits; | |
1677 | } | |
1678 | else | |
1679 | { | |
1680 | /* Some other kind of relocation. */ | |
1681 | switch (fixP->fx_r_type) | |
1682 | { | |
1683 | case BFD_RELOC_8: | |
1684 | case BFD_RELOC_8_PCREL: | |
1685 | md_number_to_chars (p, value, 1); | |
1686 | break; | |
1687 | ||
1688 | case BFD_RELOC_16: | |
1689 | case BFD_RELOC_16_PCREL: | |
1690 | md_number_to_chars (p, value, 2); | |
1691 | break; | |
1692 | ||
1693 | case BFD_RELOC_32: | |
1694 | case BFD_RELOC_32_PCREL: | |
1695 | md_number_to_chars (p, value, 4); | |
1696 | break; | |
1697 | ||
1698 | case BFD_RELOC_64: | |
1699 | case BFD_RELOC_64_PCREL: | |
1700 | md_number_to_chars (p, value, 8); | |
1701 | break; | |
1702 | ||
1703 | default: | |
1704 | /* Leave it for the linker. */ | |
1705 | return; | |
1706 | } | |
1707 | } | |
1708 | ||
1709 | fixP->fx_done = 1; | |
1710 | } | |
1711 | ||
1712 | ||
1713 | /* Generate the BFD reloc to be stuck in the object file from the | |
1714 | fixup used internally in the assembler. */ | |
1715 | ||
1716 | arelent * | |
1717 | tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp) | |
1718 | { | |
1719 | arelent *reloc; | |
1720 | ||
1721 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
1722 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
1723 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
1724 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
1725 | ||
1726 | /* Make sure none of our internal relocations make it this far. | |
1727 | They'd better have been fully resolved by this point. */ | |
1728 | gas_assert ((int) fixp->fx_r_type > 0); | |
1729 | ||
1730 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
1731 | if (reloc->howto == NULL) | |
1732 | { | |
1733 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1734 | _("cannot represent `%s' relocation in object file"), | |
1735 | bfd_get_reloc_code_name (fixp->fx_r_type)); | |
1736 | return NULL; | |
1737 | } | |
1738 | ||
1739 | if (!fixp->fx_pcrel != !reloc->howto->pc_relative) | |
1740 | { | |
1741 | as_fatal (_("internal error? cannot generate `%s' relocation (%d, %d)"), | |
1742 | bfd_get_reloc_code_name (fixp->fx_r_type), | |
1743 | fixp->fx_pcrel, reloc->howto->pc_relative); | |
1744 | } | |
1745 | gas_assert (!fixp->fx_pcrel == !reloc->howto->pc_relative); | |
1746 | ||
1747 | reloc->addend = fixp->fx_offset; | |
1748 | ||
1749 | return reloc; | |
1750 | } | |
1751 | ||
1752 | ||
1753 | /* The location from which a PC relative jump should be calculated, | |
1754 | given a PC relative reloc. */ | |
1755 | ||
1756 | long | |
1757 | md_pcrel_from (fixS *fixP) | |
1758 | { | |
1759 | return fixP->fx_frag->fr_address + fixP->fx_where; | |
1760 | } | |
1761 | ||
1762 | ||
1763 | /* Return 1 if it's OK to adjust a reloc by replacing the symbol with | |
1764 | a section symbol plus some offset. */ | |
1765 | int | |
1766 | tilegx_fix_adjustable (fixS *fix) | |
1767 | { | |
1768 | /* Prevent all adjustments to global symbols */ | |
1769 | if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy)) | |
1770 | return 0; | |
1771 | ||
1772 | return 1; | |
1773 | } | |
1774 | ||
1775 | ||
1776 | int | |
1777 | tilegx_unrecognized_line (int ch) | |
1778 | { | |
1779 | switch (ch) | |
1780 | { | |
1781 | case '{': | |
1782 | if (inside_bundle) | |
1783 | { | |
1784 | as_bad (_("Found '{' when already bundling.")); | |
1785 | } | |
1786 | else | |
1787 | { | |
1788 | inside_bundle = 1; | |
1789 | current_bundle_index = 0; | |
1790 | } | |
1791 | return 1; | |
1792 | ||
1793 | case '}': | |
1794 | if (!inside_bundle) | |
1795 | { | |
1796 | as_bad (_("Found '}' when not bundling.")); | |
1797 | } | |
1798 | else | |
1799 | { | |
1800 | tilegx_flush_bundle (); | |
1801 | } | |
1802 | ||
1803 | /* Allow '{' to follow on the same line. We also allow ";;", but that | |
1804 | happens automatically because ';' is an end of line marker. */ | |
1805 | SKIP_WHITESPACE (); | |
1806 | if (input_line_pointer[0] == '{') | |
1807 | { | |
1808 | input_line_pointer++; | |
1809 | return tilegx_unrecognized_line ('{'); | |
1810 | } | |
1811 | ||
1812 | demand_empty_rest_of_line (); | |
1813 | return 1; | |
1814 | ||
1815 | default: | |
1816 | break; | |
1817 | } | |
1818 | ||
1819 | /* Not a valid line. */ | |
1820 | return 0; | |
1821 | } | |
1822 | ||
1823 | ||
1824 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents | |
1825 | of an rs_align_code fragment. */ | |
1826 | ||
1827 | void | |
1828 | tilegx_handle_align (fragS *fragp) | |
1829 | { | |
1830 | addressT bytes, fix; | |
1831 | char *p; | |
1832 | ||
1833 | if (fragp->fr_type != rs_align_code) | |
1834 | return; | |
1835 | ||
1836 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; | |
1837 | p = fragp->fr_literal + fragp->fr_fix; | |
1838 | fix = 0; | |
1839 | ||
1840 | /* Determine the bits for NOP. */ | |
1841 | const struct tilegx_opcode *nop_opcode = | |
1842 | &tilegx_opcodes[TILEGX_OPC_NOP]; | |
1843 | tilegx_bundle_bits nop = | |
1844 | ( nop_opcode->fixed_bit_values[TILEGX_PIPELINE_X0] | |
1845 | | nop_opcode->fixed_bit_values[TILEGX_PIPELINE_X1]); | |
1846 | ||
1847 | if ((bytes & (TILEGX_BUNDLE_SIZE_IN_BYTES - 1)) != 0) | |
1848 | { | |
1849 | fix = bytes & (TILEGX_BUNDLE_SIZE_IN_BYTES - 1); | |
1850 | memset (p, 0, fix); | |
1851 | p += fix; | |
1852 | bytes -= fix; | |
1853 | } | |
1854 | ||
1855 | number_to_chars_littleendian (p, nop, 8); | |
1856 | fragp->fr_fix += fix; | |
1857 | fragp->fr_var = TILEGX_BUNDLE_SIZE_IN_BYTES; | |
1858 | } | |
1859 | ||
1860 | /* Standard calling conventions leave the CFA at SP on entry. */ | |
1861 | void | |
1862 | tilegx_cfi_frame_initial_instructions (void) | |
1863 | { | |
1864 | cfi_add_CFA_def_cfa_register (54); | |
1865 | } | |
1866 | ||
1867 | int | |
1868 | tc_tilegx_regname_to_dw2regnum (char *regname) | |
1869 | { | |
1870 | int i; | |
1871 | for (i = 0; i < TILEGX_NUM_REGISTERS; i++) | |
1872 | { | |
1873 | if (!strcmp (regname, tilegx_register_names[i])) | |
1874 | return i; | |
1875 | } | |
1876 | ||
1877 | return -1; | |
1878 | } |