1 /* tc-sh.c -- Assemble code for the Renesas / SuperH SH
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Written By Steve Chamberlain <sac@cygnus.com> */
29 #include "opcodes/sh-opc.h"
30 #include "safe-ctype.h"
31 #include "struc-symbol.h"
37 #include "dwarf2dbg.h"
38 #include "dw2gencfi.h"
44 expressionS immediate
;
48 const char comment_chars
[] = "!";
49 const char line_separator_chars
[] = ";";
50 const char line_comment_chars
[] = "!#";
52 static void s_uses (int);
53 static void s_uacons (int);
56 static void sh_elf_cons (int);
58 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
62 big (int ignore ATTRIBUTE_UNUSED
)
64 if (! target_big_endian
)
65 as_bad (_("directive .big encountered when option -big required"));
67 /* Stop further messages. */
68 target_big_endian
= 1;
72 little (int ignore ATTRIBUTE_UNUSED
)
74 if (target_big_endian
)
75 as_bad (_("directive .little encountered when option -little required"));
77 /* Stop further messages. */
78 target_big_endian
= 0;
81 /* This table describes all the machine specific pseudo-ops the assembler
82 has to support. The fields are:
83 pseudo-op name without dot
84 function to call to execute this pseudo-op
85 Integer arg to pass to the function. */
87 const pseudo_typeS md_pseudo_table
[] =
90 {"long", sh_elf_cons
, 4},
91 {"int", sh_elf_cons
, 4},
92 {"word", sh_elf_cons
, 2},
93 {"short", sh_elf_cons
, 2},
99 {"form", listing_psize
, 0},
100 {"little", little
, 0},
101 {"heading", listing_title
, 0},
102 {"import", s_ignore
, 0},
103 {"page", listing_eject
, 0},
104 {"program", s_ignore
, 0},
106 {"uaword", s_uacons
, 2},
107 {"ualong", s_uacons
, 4},
108 {"uaquad", s_uacons
, 8},
109 {"2byte", s_uacons
, 2},
110 {"4byte", s_uacons
, 4},
111 {"8byte", s_uacons
, 8},
113 {"mode", s_sh64_mode
, 0 },
115 /* Have the old name too. */
116 {"isa", s_sh64_mode
, 0 },
118 /* Assert that the right ABI is used. */
119 {"abi", s_sh64_abi
, 0 },
121 { "vtable_inherit", sh64_vtable_inherit
, 0 },
122 { "vtable_entry", sh64_vtable_entry
, 0 },
123 #endif /* HAVE_SH64 */
127 int sh_relax
; /* set if -relax seen */
129 /* Whether -small was seen. */
133 /* Flag to generate relocations against symbol values for local symbols. */
135 static int dont_adjust_reloc_32
;
137 /* Flag to indicate that '$' is allowed as a register prefix. */
139 static int allow_dollar_register_prefix
;
141 /* Preset architecture set, if given; zero otherwise. */
143 static unsigned int preset_target_arch
;
145 /* The bit mask of architectures that could
146 accommodate the insns seen so far. */
147 static unsigned int valid_arch
;
149 const char EXP_CHARS
[] = "eE";
151 /* Chars that mean this number is a floating point constant. */
154 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
156 #define C(a,b) ENCODE_RELAX(a,b)
158 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
159 #define GET_WHAT(x) ((x>>4))
161 /* These are the three types of relaxable instruction. */
162 /* These are the types of relaxable instructions; except for END which is
165 #define COND_JUMP_DELAY 2
166 #define UNCOND_JUMP 3
170 /* A 16-bit (times four) pc-relative operand, at most expanded to 32 bits. */
171 #define SH64PCREL16_32 4
172 /* A 16-bit (times four) pc-relative operand, at most expanded to 64 bits. */
173 #define SH64PCREL16_64 5
175 /* Variants of the above for adjusting the insn to PTA or PTB according to
177 #define SH64PCREL16PT_32 6
178 #define SH64PCREL16PT_64 7
180 /* A MOVI expansion, expanding to at most 32 or 64 bits. */
181 #define MOVI_IMM_32 8
182 #define MOVI_IMM_32_PCREL 9
183 #define MOVI_IMM_64 10
184 #define MOVI_IMM_64_PCREL 11
187 #else /* HAVE_SH64 */
191 #endif /* HAVE_SH64 */
197 #define UNDEF_WORD_DISP 4
203 #define UNDEF_SH64PCREL 0
204 #define SH64PCREL16 1
205 #define SH64PCREL32 2
206 #define SH64PCREL48 3
207 #define SH64PCREL64 4
208 #define SH64PCRELPLT 5
216 #define MOVI_GOTOFF 6
218 #endif /* HAVE_SH64 */
220 /* Branch displacements are from the address of the branch plus
221 four, thus all minimum and maximum values have 4 added to them. */
224 #define COND8_LENGTH 2
226 /* There is one extra instruction before the branch, so we must add
227 two more bytes to account for it. */
228 #define COND12_F 4100
229 #define COND12_M -4090
230 #define COND12_LENGTH 6
232 #define COND12_DELAY_LENGTH 4
234 /* ??? The minimum and maximum values are wrong, but this does not matter
235 since this relocation type is not supported yet. */
236 #define COND32_F (1<<30)
237 #define COND32_M -(1<<30)
238 #define COND32_LENGTH 14
240 #define UNCOND12_F 4098
241 #define UNCOND12_M -4092
242 #define UNCOND12_LENGTH 2
244 /* ??? The minimum and maximum values are wrong, but this does not matter
245 since this relocation type is not supported yet. */
246 #define UNCOND32_F (1<<30)
247 #define UNCOND32_M -(1<<30)
248 #define UNCOND32_LENGTH 14
251 /* The trivial expansion of a SH64PCREL16 relaxation is just a "PT label,
252 TRd" as is the current insn, so no extra length. Note that the "reach"
253 is calculated from the address *after* that insn, but the offset in the
254 insn is calculated from the beginning of the insn. We also need to
255 take into account the implicit 1 coded as the "A" in PTA when counting
256 forward. If PTB reaches an odd address, we trap that as an error
257 elsewhere, so we don't have to have different relaxation entries. We
258 don't add a one to the negative range, since PTB would then have the
259 farthest backward-reaching value skipped, not generated at relaxation. */
260 #define SH64PCREL16_F (32767 * 4 - 4 + 1)
261 #define SH64PCREL16_M (-32768 * 4 - 4)
262 #define SH64PCREL16_LENGTH 0
264 /* The next step is to change that PT insn into
265 MOVI ((label - datalabel Ln) >> 16) & 65535, R25
266 SHORI (label - datalabel Ln) & 65535, R25
269 which means two extra insns, 8 extra bytes. This is the limit for the
272 The expressions look a bit bad since we have to adjust this to avoid overflow on a
274 #define SH64PCREL32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
275 #define SH64PCREL32_LENGTH (2 * 4)
277 /* Similarly, we just change the MOVI and add a SHORI for the 48-bit
279 #if BFD_HOST_64BIT_LONG
280 /* The "reach" type is long, so we can only do this for a 64-bit-long
282 #define SH64PCREL32_M (((long) -1 << 30) * 2 - 4)
283 #define SH64PCREL48_F ((((long) 1 << 47) - 1) - 4)
284 #define SH64PCREL48_M (((long) -1 << 47) - 4)
285 #define SH64PCREL48_LENGTH (3 * 4)
287 /* If the host does not have 64-bit longs, just make this state identical
288 in reach to the 32-bit state. Note that we have a slightly incorrect
289 reach, but the correct one above will overflow a 32-bit number. */
290 #define SH64PCREL32_M (((long) -1 << 30) * 2)
291 #define SH64PCREL48_F SH64PCREL32_F
292 #define SH64PCREL48_M SH64PCREL32_M
293 #define SH64PCREL48_LENGTH (3 * 4)
294 #endif /* BFD_HOST_64BIT_LONG */
296 /* And similarly for the 64-bit expansion; a MOVI + SHORI + SHORI + SHORI
298 #define SH64PCREL64_LENGTH (4 * 4)
300 /* For MOVI, we make the MOVI + SHORI... expansion you can see in the
301 SH64PCREL expansions. The PCREL one is similar, but the other has no
302 pc-relative reach; it must be fully expanded in
303 shmedia_md_estimate_size_before_relax. */
304 #define MOVI_16_LENGTH 0
305 #define MOVI_16_F (32767 - 4)
306 #define MOVI_16_M (-32768 - 4)
307 #define MOVI_32_LENGTH 4
308 #define MOVI_32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
309 #define MOVI_48_LENGTH 8
311 #if BFD_HOST_64BIT_LONG
312 /* The "reach" type is long, so we can only do this for a 64-bit-long
314 #define MOVI_32_M (((long) -1 << 30) * 2 - 4)
315 #define MOVI_48_F ((((long) 1 << 47) - 1) - 4)
316 #define MOVI_48_M (((long) -1 << 47) - 4)
318 /* If the host does not have 64-bit longs, just make this state identical
319 in reach to the 32-bit state. Note that we have a slightly incorrect
320 reach, but the correct one above will overflow a 32-bit number. */
321 #define MOVI_32_M (((long) -1 << 30) * 2)
322 #define MOVI_48_F MOVI_32_F
323 #define MOVI_48_M MOVI_32_M
324 #endif /* BFD_HOST_64BIT_LONG */
326 #define MOVI_64_LENGTH 12
327 #endif /* HAVE_SH64 */
329 #define EMPTY { 0, 0, 0, 0 }
331 const relax_typeS md_relax_table
[C (END
, 0)] = {
332 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
333 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
336 /* C (COND_JUMP, COND8) */
337 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP
, COND12
) },
338 /* C (COND_JUMP, COND12) */
339 { COND12_F
, COND12_M
, COND12_LENGTH
, C (COND_JUMP
, COND32
), },
340 /* C (COND_JUMP, COND32) */
341 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
342 /* C (COND_JUMP, UNDEF_WORD_DISP) */
343 { 0, 0, COND32_LENGTH
, 0, },
345 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
348 /* C (COND_JUMP_DELAY, COND8) */
349 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP_DELAY
, COND12
) },
350 /* C (COND_JUMP_DELAY, COND12) */
351 { COND12_F
, COND12_M
, COND12_DELAY_LENGTH
, C (COND_JUMP_DELAY
, COND32
), },
352 /* C (COND_JUMP_DELAY, COND32) */
353 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
354 /* C (COND_JUMP_DELAY, UNDEF_WORD_DISP) */
355 { 0, 0, COND32_LENGTH
, 0, },
357 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
360 /* C (UNCOND_JUMP, UNCOND12) */
361 { UNCOND12_F
, UNCOND12_M
, UNCOND12_LENGTH
, C (UNCOND_JUMP
, UNCOND32
), },
362 /* C (UNCOND_JUMP, UNCOND32) */
363 { UNCOND32_F
, UNCOND32_M
, UNCOND32_LENGTH
, 0, },
365 /* C (UNCOND_JUMP, UNDEF_WORD_DISP) */
366 { 0, 0, UNCOND32_LENGTH
, 0, },
368 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
371 /* C (SH64PCREL16_32, SH64PCREL16) */
373 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16_32
, SH64PCREL32
) },
374 /* C (SH64PCREL16_32, SH64PCREL32) */
375 { 0, 0, SH64PCREL32_LENGTH
, 0 },
377 /* C (SH64PCREL16_32, SH64PCRELPLT) */
378 { 0, 0, SH64PCREL32_LENGTH
, 0 },
380 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
382 /* C (SH64PCREL16_64, SH64PCREL16) */
384 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16_64
, SH64PCREL32
) },
385 /* C (SH64PCREL16_64, SH64PCREL32) */
386 { SH64PCREL32_F
, SH64PCREL32_M
, SH64PCREL32_LENGTH
, C (SH64PCREL16_64
, SH64PCREL48
) },
387 /* C (SH64PCREL16_64, SH64PCREL48) */
388 { SH64PCREL48_F
, SH64PCREL48_M
, SH64PCREL48_LENGTH
, C (SH64PCREL16_64
, SH64PCREL64
) },
389 /* C (SH64PCREL16_64, SH64PCREL64) */
390 { 0, 0, SH64PCREL64_LENGTH
, 0 },
391 /* C (SH64PCREL16_64, SH64PCRELPLT) */
392 { 0, 0, SH64PCREL64_LENGTH
, 0 },
394 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
396 /* C (SH64PCREL16PT_32, SH64PCREL16) */
398 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16PT_32
, SH64PCREL32
) },
399 /* C (SH64PCREL16PT_32, SH64PCREL32) */
400 { 0, 0, SH64PCREL32_LENGTH
, 0 },
402 /* C (SH64PCREL16PT_32, SH64PCRELPLT) */
403 { 0, 0, SH64PCREL32_LENGTH
, 0 },
405 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
407 /* C (SH64PCREL16PT_64, SH64PCREL16) */
409 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16PT_64
, SH64PCREL32
) },
410 /* C (SH64PCREL16PT_64, SH64PCREL32) */
414 C (SH64PCREL16PT_64
, SH64PCREL48
) },
415 /* C (SH64PCREL16PT_64, SH64PCREL48) */
416 { SH64PCREL48_F
, SH64PCREL48_M
, SH64PCREL48_LENGTH
, C (SH64PCREL16PT_64
, SH64PCREL64
) },
417 /* C (SH64PCREL16PT_64, SH64PCREL64) */
418 { 0, 0, SH64PCREL64_LENGTH
, 0 },
419 /* C (SH64PCREL16PT_64, SH64PCRELPLT) */
420 { 0, 0, SH64PCREL64_LENGTH
, 0},
422 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
424 /* C (MOVI_IMM_32, UNDEF_MOVI) */
425 { 0, 0, MOVI_32_LENGTH
, 0 },
426 /* C (MOVI_IMM_32, MOVI_16) */
427 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_32
, MOVI_32
) },
428 /* C (MOVI_IMM_32, MOVI_32) */
429 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, 0 },
431 /* C (MOVI_IMM_32, MOVI_GOTOFF) */
432 { 0, 0, MOVI_32_LENGTH
, 0 },
433 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
435 /* C (MOVI_IMM_32_PCREL, MOVI_16) */
437 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_32_PCREL
, MOVI_32
) },
438 /* C (MOVI_IMM_32_PCREL, MOVI_32) */
439 { 0, 0, MOVI_32_LENGTH
, 0 },
441 /* C (MOVI_IMM_32_PCREL, MOVI_PLT) */
442 { 0, 0, MOVI_32_LENGTH
, 0 },
444 /* C (MOVI_IMM_32_PCREL, MOVI_GOTPC) */
445 { 0, 0, MOVI_32_LENGTH
, 0 },
446 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
448 /* C (MOVI_IMM_64, UNDEF_MOVI) */
449 { 0, 0, MOVI_64_LENGTH
, 0 },
450 /* C (MOVI_IMM_64, MOVI_16) */
451 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_64
, MOVI_32
) },
452 /* C (MOVI_IMM_64, MOVI_32) */
453 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, C (MOVI_IMM_64
, MOVI_48
) },
454 /* C (MOVI_IMM_64, MOVI_48) */
455 { MOVI_48_F
, MOVI_48_M
, MOVI_48_LENGTH
, C (MOVI_IMM_64
, MOVI_64
) },
456 /* C (MOVI_IMM_64, MOVI_64) */
457 { 0, 0, MOVI_64_LENGTH
, 0 },
459 /* C (MOVI_IMM_64, MOVI_GOTOFF) */
460 { 0, 0, MOVI_64_LENGTH
, 0 },
461 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
463 /* C (MOVI_IMM_64_PCREL, MOVI_16) */
465 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_32
) },
466 /* C (MOVI_IMM_64_PCREL, MOVI_32) */
467 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_48
) },
468 /* C (MOVI_IMM_64_PCREL, MOVI_48) */
469 { MOVI_48_F
, MOVI_48_M
, MOVI_48_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_64
) },
470 /* C (MOVI_IMM_64_PCREL, MOVI_64) */
471 { 0, 0, MOVI_64_LENGTH
, 0 },
472 /* C (MOVI_IMM_64_PCREL, MOVI_PLT) */
473 { 0, 0, MOVI_64_LENGTH
, 0 },
475 /* C (MOVI_IMM_64_PCREL, MOVI_GOTPC) */
476 { 0, 0, MOVI_64_LENGTH
, 0 },
477 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
479 #endif /* HAVE_SH64 */
485 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics */
489 /* Determinet whether the symbol needs any kind of PIC relocation. */
492 sh_PIC_related_p (symbolS
*sym
)
499 if (sym
== GOT_symbol
)
503 if (sh_PIC_related_p (*symbol_get_tc (sym
)))
507 exp
= symbol_get_value_expression (sym
);
509 return (exp
->X_op
== O_PIC_reloc
510 || sh_PIC_related_p (exp
->X_add_symbol
)
511 || sh_PIC_related_p (exp
->X_op_symbol
));
514 /* Determine the relocation type to be used to represent the
515 expression, that may be rearranged. */
518 sh_check_fixup (expressionS
*main_exp
, bfd_reloc_code_real_type
*r_type_p
)
520 expressionS
*exp
= main_exp
;
522 /* This is here for backward-compatibility only. GCC used to generated:
524 f@PLT + . - (.LPCS# + 2)
526 but we'd rather be able to handle this as a PIC-related reference
527 plus/minus a symbol. However, gas' parser gives us:
529 O_subtract (O_add (f@PLT, .), .LPCS#+2)
531 so we attempt to transform this into:
533 O_subtract (f@PLT, O_subtract (.LPCS#+2, .))
535 which we can handle simply below. */
536 if (exp
->X_op
== O_subtract
)
538 if (sh_PIC_related_p (exp
->X_op_symbol
))
541 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
543 if (exp
&& sh_PIC_related_p (exp
->X_op_symbol
))
546 if (exp
&& exp
->X_op
== O_add
547 && sh_PIC_related_p (exp
->X_add_symbol
))
549 symbolS
*sym
= exp
->X_add_symbol
;
551 exp
->X_op
= O_subtract
;
552 exp
->X_add_symbol
= main_exp
->X_op_symbol
;
554 main_exp
->X_op_symbol
= main_exp
->X_add_symbol
;
555 main_exp
->X_add_symbol
= sym
;
557 main_exp
->X_add_number
+= exp
->X_add_number
;
558 exp
->X_add_number
= 0;
563 else if (exp
->X_op
== O_add
&& sh_PIC_related_p (exp
->X_op_symbol
))
566 if (exp
->X_op
== O_symbol
|| exp
->X_op
== O_add
|| exp
->X_op
== O_subtract
)
569 if (exp
->X_add_symbol
570 && (exp
->X_add_symbol
== GOT_symbol
572 && *symbol_get_tc (exp
->X_add_symbol
) == GOT_symbol
)))
576 case BFD_RELOC_SH_IMM_LOW16
:
577 *r_type_p
= BFD_RELOC_SH_GOTPC_LOW16
;
580 case BFD_RELOC_SH_IMM_MEDLOW16
:
581 *r_type_p
= BFD_RELOC_SH_GOTPC_MEDLOW16
;
584 case BFD_RELOC_SH_IMM_MEDHI16
:
585 *r_type_p
= BFD_RELOC_SH_GOTPC_MEDHI16
;
588 case BFD_RELOC_SH_IMM_HI16
:
589 *r_type_p
= BFD_RELOC_SH_GOTPC_HI16
;
593 case BFD_RELOC_UNUSED
:
594 *r_type_p
= BFD_RELOC_SH_GOTPC
;
603 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
605 *r_type_p
= BFD_RELOC_SH_GOTPC
;
609 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
614 if (exp
->X_op
== O_PIC_reloc
)
620 case BFD_RELOC_UNUSED
:
621 *r_type_p
= exp
->X_md
;
624 case BFD_RELOC_SH_IMM_LOW16
:
627 case BFD_RELOC_32_GOTOFF
:
628 *r_type_p
= BFD_RELOC_SH_GOTOFF_LOW16
;
631 case BFD_RELOC_SH_GOTPLT32
:
632 *r_type_p
= BFD_RELOC_SH_GOTPLT_LOW16
;
635 case BFD_RELOC_32_GOT_PCREL
:
636 *r_type_p
= BFD_RELOC_SH_GOT_LOW16
;
639 case BFD_RELOC_32_PLT_PCREL
:
640 *r_type_p
= BFD_RELOC_SH_PLT_LOW16
;
648 case BFD_RELOC_SH_IMM_MEDLOW16
:
651 case BFD_RELOC_32_GOTOFF
:
652 *r_type_p
= BFD_RELOC_SH_GOTOFF_MEDLOW16
;
655 case BFD_RELOC_SH_GOTPLT32
:
656 *r_type_p
= BFD_RELOC_SH_GOTPLT_MEDLOW16
;
659 case BFD_RELOC_32_GOT_PCREL
:
660 *r_type_p
= BFD_RELOC_SH_GOT_MEDLOW16
;
663 case BFD_RELOC_32_PLT_PCREL
:
664 *r_type_p
= BFD_RELOC_SH_PLT_MEDLOW16
;
672 case BFD_RELOC_SH_IMM_MEDHI16
:
675 case BFD_RELOC_32_GOTOFF
:
676 *r_type_p
= BFD_RELOC_SH_GOTOFF_MEDHI16
;
679 case BFD_RELOC_SH_GOTPLT32
:
680 *r_type_p
= BFD_RELOC_SH_GOTPLT_MEDHI16
;
683 case BFD_RELOC_32_GOT_PCREL
:
684 *r_type_p
= BFD_RELOC_SH_GOT_MEDHI16
;
687 case BFD_RELOC_32_PLT_PCREL
:
688 *r_type_p
= BFD_RELOC_SH_PLT_MEDHI16
;
696 case BFD_RELOC_SH_IMM_HI16
:
699 case BFD_RELOC_32_GOTOFF
:
700 *r_type_p
= BFD_RELOC_SH_GOTOFF_HI16
;
703 case BFD_RELOC_SH_GOTPLT32
:
704 *r_type_p
= BFD_RELOC_SH_GOTPLT_HI16
;
707 case BFD_RELOC_32_GOT_PCREL
:
708 *r_type_p
= BFD_RELOC_SH_GOT_HI16
;
711 case BFD_RELOC_32_PLT_PCREL
:
712 *r_type_p
= BFD_RELOC_SH_PLT_HI16
;
724 *r_type_p
= exp
->X_md
;
727 exp
->X_op
= O_symbol
;
730 main_exp
->X_add_symbol
= exp
->X_add_symbol
;
731 main_exp
->X_add_number
+= exp
->X_add_number
;
735 return (sh_PIC_related_p (exp
->X_add_symbol
)
736 || sh_PIC_related_p (exp
->X_op_symbol
));
741 /* Add expression EXP of SIZE bytes to offset OFF of fragment FRAG. */
744 sh_cons_fix_new (fragS
*frag
, int off
, int size
, expressionS
*exp
)
746 bfd_reloc_code_real_type r_type
= BFD_RELOC_UNUSED
;
748 if (sh_check_fixup (exp
, &r_type
))
749 as_bad (_("Invalid PIC expression."));
751 if (r_type
== BFD_RELOC_UNUSED
)
755 r_type
= BFD_RELOC_8
;
759 r_type
= BFD_RELOC_16
;
763 r_type
= BFD_RELOC_32
;
768 r_type
= BFD_RELOC_64
;
778 as_bad (_("unsupported BFD relocation size %u"), size
);
779 r_type
= BFD_RELOC_UNUSED
;
782 fix_new_exp (frag
, off
, size
, exp
, 0, r_type
);
785 /* The regular cons() function, that reads constants, doesn't support
786 suffixes such as @GOT, @GOTOFF and @PLT, that generate
787 machine-specific relocation types. So we must define it here. */
788 /* Clobbers input_line_pointer, checks end-of-line. */
789 /* NBYTES 1=.byte, 2=.word, 4=.long */
791 sh_elf_cons (register int nbytes
)
797 /* Update existing range to include a previous insn, if there was one. */
798 sh64_update_contents_mark (TRUE
);
800 /* We need to make sure the contents type is set to data. */
803 #endif /* HAVE_SH64 */
805 if (is_it_end_of_statement ())
807 demand_empty_rest_of_line ();
812 md_cons_align (nbytes
);
818 emit_expr (&exp
, (unsigned int) nbytes
);
820 while (*input_line_pointer
++ == ',');
822 input_line_pointer
--; /* Put terminator back into stream. */
823 if (*input_line_pointer
== '#' || *input_line_pointer
== '!')
825 while (! is_end_of_line
[(unsigned char) *input_line_pointer
++]);
828 demand_empty_rest_of_line ();
833 /* This function is called once, at assembler startup time. This should
834 set up all the tables, etc that the MD part of the assembler needs. */
839 const sh_opcode_info
*opcode
;
840 char *prev_name
= "";
841 unsigned int target_arch
;
844 = preset_target_arch
? preset_target_arch
: arch_sh_up
& ~arch_sh_has_dsp
;
845 valid_arch
= target_arch
;
851 opcode_hash_control
= hash_new ();
853 /* Insert unique names into hash table. */
854 for (opcode
= sh_table
; opcode
->name
; opcode
++)
856 if (strcmp (prev_name
, opcode
->name
) != 0)
858 if (!SH_MERGE_ARCH_SET_VALID (opcode
->arch
, target_arch
))
860 prev_name
= opcode
->name
;
861 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
868 static int reg_x
, reg_y
;
872 #define IDENT_CHAR(c) (ISALNUM (c) || (c) == '_')
874 /* Try to parse a reg name. Return the number of chars consumed. */
877 parse_reg_without_prefix (char *src
, int *mode
, int *reg
)
879 char l0
= TOLOWER (src
[0]);
880 char l1
= l0
? TOLOWER (src
[1]) : 0;
882 /* We use ! IDENT_CHAR for the next character after the register name, to
883 make sure that we won't accidentally recognize a symbol name such as
884 'sram' or sr_ram as being a reference to the register 'sr'. */
890 if (src
[2] >= '0' && src
[2] <= '5'
891 && ! IDENT_CHAR ((unsigned char) src
[3]))
894 *reg
= 10 + src
[2] - '0';
898 if (l1
>= '0' && l1
<= '9'
899 && ! IDENT_CHAR ((unsigned char) src
[2]))
905 if (l1
>= '0' && l1
<= '7' && strncasecmp (&src
[2], "_bank", 5) == 0
906 && ! IDENT_CHAR ((unsigned char) src
[7]))
913 if (l1
== 'e' && ! IDENT_CHAR ((unsigned char) src
[2]))
918 if (l1
== 's' && ! IDENT_CHAR ((unsigned char) src
[2]))
929 if (! IDENT_CHAR ((unsigned char) src
[2]))
935 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
944 if (! IDENT_CHAR ((unsigned char) src
[2]))
950 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
958 if (l1
== 'x' && src
[2] >= '0' && src
[2] <= '1'
959 && ! IDENT_CHAR ((unsigned char) src
[3]))
962 *reg
= 4 + (l1
- '0');
965 if (l1
== 'y' && src
[2] >= '0' && src
[2] <= '1'
966 && ! IDENT_CHAR ((unsigned char) src
[3]))
969 *reg
= 6 + (l1
- '0');
972 if (l1
== 's' && src
[2] >= '0' && src
[2] <= '3'
973 && ! IDENT_CHAR ((unsigned char) src
[3]))
978 *reg
= n
| ((~n
& 2) << 1);
983 if (l0
== 'i' && l1
&& ! IDENT_CHAR ((unsigned char) src
[2]))
1005 if (l0
== 'x' && l1
>= '0' && l1
<= '1'
1006 && ! IDENT_CHAR ((unsigned char) src
[2]))
1009 *reg
= A_X0_NUM
+ l1
- '0';
1013 if (l0
== 'y' && l1
>= '0' && l1
<= '1'
1014 && ! IDENT_CHAR ((unsigned char) src
[2]))
1017 *reg
= A_Y0_NUM
+ l1
- '0';
1021 if (l0
== 'm' && l1
>= '0' && l1
<= '1'
1022 && ! IDENT_CHAR ((unsigned char) src
[2]))
1025 *reg
= l1
== '0' ? A_M0_NUM
: A_M1_NUM
;
1031 && TOLOWER (src
[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[3]))
1037 if (l0
== 's' && l1
== 'p' && TOLOWER (src
[2]) == 'c'
1038 && ! IDENT_CHAR ((unsigned char) src
[3]))
1044 if (l0
== 's' && l1
== 'g' && TOLOWER (src
[2]) == 'r'
1045 && ! IDENT_CHAR ((unsigned char) src
[3]))
1051 if (l0
== 'd' && l1
== 's' && TOLOWER (src
[2]) == 'r'
1052 && ! IDENT_CHAR ((unsigned char) src
[3]))
1058 if (l0
== 'd' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1059 && ! IDENT_CHAR ((unsigned char) src
[3]))
1065 if (l0
== 's' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
1071 if (l0
== 's' && l1
== 'p' && ! IDENT_CHAR ((unsigned char) src
[2]))
1078 if (l0
== 'p' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
1083 if (l0
== 'p' && l1
== 'c' && ! IDENT_CHAR ((unsigned char) src
[2]))
1085 /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
1086 and use an uninitialized immediate. */
1090 if (l0
== 'g' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1091 && ! IDENT_CHAR ((unsigned char) src
[3]))
1096 if (l0
== 'v' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1097 && ! IDENT_CHAR ((unsigned char) src
[3]))
1103 if (l0
== 't' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1104 && ! IDENT_CHAR ((unsigned char) src
[3]))
1109 if (l0
== 'm' && l1
== 'a' && TOLOWER (src
[2]) == 'c'
1110 && ! IDENT_CHAR ((unsigned char) src
[4]))
1112 if (TOLOWER (src
[3]) == 'l')
1117 if (TOLOWER (src
[3]) == 'h')
1123 if (l0
== 'm' && l1
== 'o' && TOLOWER (src
[2]) == 'd'
1124 && ! IDENT_CHAR ((unsigned char) src
[3]))
1129 if (l0
== 'f' && l1
== 'r')
1133 if (src
[3] >= '0' && src
[3] <= '5'
1134 && ! IDENT_CHAR ((unsigned char) src
[4]))
1137 *reg
= 10 + src
[3] - '0';
1141 if (src
[2] >= '0' && src
[2] <= '9'
1142 && ! IDENT_CHAR ((unsigned char) src
[3]))
1145 *reg
= (src
[2] - '0');
1149 if (l0
== 'd' && l1
== 'r')
1153 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
1154 && ! IDENT_CHAR ((unsigned char) src
[4]))
1157 *reg
= 10 + src
[3] - '0';
1161 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
1162 && ! IDENT_CHAR ((unsigned char) src
[3]))
1165 *reg
= (src
[2] - '0');
1169 if (l0
== 'x' && l1
== 'd')
1173 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
1174 && ! IDENT_CHAR ((unsigned char) src
[4]))
1177 *reg
= 11 + src
[3] - '0';
1181 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
1182 && ! IDENT_CHAR ((unsigned char) src
[3]))
1185 *reg
= (src
[2] - '0') + 1;
1189 if (l0
== 'f' && l1
== 'v')
1191 if (src
[2] == '1'&& src
[3] == '2' && ! IDENT_CHAR ((unsigned char) src
[4]))
1197 if ((src
[2] == '0' || src
[2] == '4' || src
[2] == '8')
1198 && ! IDENT_CHAR ((unsigned char) src
[3]))
1201 *reg
= (src
[2] - '0');
1205 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 'u'
1206 && TOLOWER (src
[3]) == 'l'
1207 && ! IDENT_CHAR ((unsigned char) src
[4]))
1213 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 's'
1214 && TOLOWER (src
[3]) == 'c'
1215 && TOLOWER (src
[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[5]))
1221 if (l0
== 'x' && l1
== 'm' && TOLOWER (src
[2]) == 't'
1222 && TOLOWER (src
[3]) == 'r'
1223 && TOLOWER (src
[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src
[5]))
1232 /* Like parse_reg_without_prefix, but this version supports
1233 $-prefixed register names if enabled by the user. */
1236 parse_reg (char *src
, int *mode
, int *reg
)
1238 unsigned int prefix
;
1239 unsigned int consumed
;
1243 if (allow_dollar_register_prefix
)
1254 consumed
= parse_reg_without_prefix (src
, mode
, reg
);
1259 return consumed
+ prefix
;
1263 parse_exp (char *s
, sh_operand_info
*op
)
1268 save
= input_line_pointer
;
1269 input_line_pointer
= s
;
1270 expression (&op
->immediate
);
1271 if (op
->immediate
.X_op
== O_absent
)
1272 as_bad (_("missing operand"));
1274 else if (op
->immediate
.X_op
== O_PIC_reloc
1275 || sh_PIC_related_p (op
->immediate
.X_add_symbol
)
1276 || sh_PIC_related_p (op
->immediate
.X_op_symbol
))
1277 as_bad (_("misplaced PIC operand"));
1279 new = input_line_pointer
;
1280 input_line_pointer
= save
;
1284 /* The many forms of operand:
1287 @Rn Register indirect
1300 pr, gbr, vbr, macl, mach
1304 parse_at (char *src
, sh_operand_info
*op
)
1311 src
= parse_at (src
, op
);
1312 if (op
->type
== A_DISP_TBR
)
1313 op
->type
= A_DISP2_TBR
;
1315 as_bad (_("illegal double indirection"));
1317 else if (src
[0] == '-')
1319 /* Must be predecrement. */
1322 len
= parse_reg (src
, &mode
, &(op
->reg
));
1323 if (mode
!= A_REG_N
)
1324 as_bad (_("illegal register after @-"));
1329 else if (src
[0] == '(')
1331 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
1334 len
= parse_reg (src
, &mode
, &(op
->reg
));
1335 if (len
&& mode
== A_REG_N
)
1340 as_bad (_("must be @(r0,...)"));
1345 /* Now can be rn or gbr. */
1346 len
= parse_reg (src
, &mode
, &(op
->reg
));
1356 op
->type
= A_R0_GBR
;
1358 else if (mode
== A_REG_N
)
1360 op
->type
= A_IND_R0_REG_N
;
1364 as_bad (_("syntax error in @(r0,...)"));
1369 as_bad (_("syntax error in @(r0...)"));
1374 /* Must be an @(disp,.. thing). */
1375 src
= parse_exp (src
, op
);
1378 /* Now can be rn, gbr or pc. */
1379 len
= parse_reg (src
, &mode
, &op
->reg
);
1382 if (mode
== A_REG_N
)
1384 op
->type
= A_DISP_REG_N
;
1386 else if (mode
== A_GBR
)
1388 op
->type
= A_DISP_GBR
;
1390 else if (mode
== A_TBR
)
1392 op
->type
= A_DISP_TBR
;
1394 else if (mode
== A_PC
)
1396 /* We want @(expr, pc) to uniformly address . + expr,
1397 no matter if expr is a constant, or a more complex
1398 expression, e.g. sym-. or sym1-sym2.
1399 However, we also used to accept @(sym,pc)
1400 as addressing sym, i.e. meaning the same as plain sym.
1401 Some existing code does use the @(sym,pc) syntax, so
1402 we give it the old semantics for now, but warn about
1403 its use, so that users have some time to fix their code.
1405 Note that due to this backward compatibility hack,
1406 we'll get unexpected results when @(offset, pc) is used,
1407 and offset is a symbol that is set later to an an address
1408 difference, or an external symbol that is set to an
1409 address difference in another source file, so we want to
1410 eventually remove it. */
1411 if (op
->immediate
.X_op
== O_symbol
)
1413 op
->type
= A_DISP_PC
;
1414 as_warn (_("Deprecated syntax."));
1418 op
->type
= A_DISP_PC_ABS
;
1419 /* Such operands don't get corrected for PC==.+4, so
1420 make the correction here. */
1421 op
->immediate
.X_add_number
-= 4;
1426 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1431 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1436 as_bad (_("expecting )"));
1442 src
+= parse_reg (src
, &mode
, &(op
->reg
));
1443 if (mode
!= A_REG_N
)
1444 as_bad (_("illegal register after @"));
1451 l0
= TOLOWER (src
[0]);
1452 l1
= TOLOWER (src
[1]);
1454 if ((l0
== 'r' && l1
== '8')
1455 || (l0
== 'i' && (l1
== 'x' || l1
== 's')))
1458 op
->type
= AX_PMOD_N
;
1460 else if ( (l0
== 'r' && l1
== '9')
1461 || (l0
== 'i' && l1
== 'y'))
1464 op
->type
= AY_PMOD_N
;
1476 get_operand (char **ptr
, sh_operand_info
*op
)
1485 *ptr
= parse_exp (src
, op
);
1490 else if (src
[0] == '@')
1492 *ptr
= parse_at (src
, op
);
1495 len
= parse_reg (src
, &mode
, &(op
->reg
));
1504 /* Not a reg, the only thing left is a displacement. */
1505 *ptr
= parse_exp (src
, op
);
1506 op
->type
= A_DISP_PC
;
1512 get_operands (sh_opcode_info
*info
, char *args
, sh_operand_info
*operand
)
1517 /* The pre-processor will eliminate whitespace in front of '@'
1518 after the first argument; we may be called multiple times
1519 from assemble_ppi, so don't insist on finding whitespace here. */
1523 get_operand (&ptr
, operand
+ 0);
1530 get_operand (&ptr
, operand
+ 1);
1531 /* ??? Hack: psha/pshl have a varying operand number depending on
1532 the type of the first operand. We handle this by having the
1533 three-operand version first and reducing the number of operands
1534 parsed to two if we see that the first operand is an immediate.
1535 This works because no insn with three operands has an immediate
1536 as first operand. */
1537 if (info
->arg
[2] && operand
[0].type
!= A_IMM
)
1543 get_operand (&ptr
, operand
+ 2);
1547 operand
[2].type
= 0;
1552 operand
[1].type
= 0;
1553 operand
[2].type
= 0;
1558 operand
[0].type
= 0;
1559 operand
[1].type
= 0;
1560 operand
[2].type
= 0;
1565 /* Passed a pointer to a list of opcodes which use different
1566 addressing modes, return the opcode which matches the opcodes
1569 static sh_opcode_info
*
1570 get_specific (sh_opcode_info
*opcode
, sh_operand_info
*operands
)
1572 sh_opcode_info
*this_try
= opcode
;
1573 char *name
= opcode
->name
;
1576 while (opcode
->name
)
1578 this_try
= opcode
++;
1579 if ((this_try
->name
!= name
) && (strcmp (this_try
->name
, name
) != 0))
1581 /* We've looked so far down the table that we've run out of
1582 opcodes with the same name. */
1586 /* Look at both operands needed by the opcodes and provided by
1587 the user - since an arg test will often fail on the same arg
1588 again and again, we'll try and test the last failing arg the
1589 first on each opcode try. */
1590 for (n
= 0; this_try
->arg
[n
]; n
++)
1592 sh_operand_info
*user
= operands
+ n
;
1593 sh_arg_type arg
= this_try
->arg
[n
];
1595 if (SH_MERGE_ARCH_SET_VALID (valid_arch
, arch_sh2a_nofpu_up
)
1596 && ( arg
== A_DISP_REG_M
1597 || arg
== A_DISP_REG_N
))
1599 /* Check a few key IMM* fields for overflow. */
1601 long val
= user
->immediate
.X_add_number
;
1603 for (opf
= 0; opf
< 4; opf
++)
1604 switch (this_try
->nibbles
[opf
])
1608 if (val
< 0 || val
> 15)
1613 if (val
< 0 || val
> 15 * 2)
1618 if (val
< 0 || val
> 15 * 4)
1628 if (user
->type
== A_DISP_PC_ABS
)
1639 if (user
->type
!= arg
)
1643 /* opcode needs r0 */
1644 if (user
->type
!= A_REG_N
|| user
->reg
!= 0)
1648 if (user
->type
!= A_R0_GBR
|| user
->reg
!= 0)
1652 if (user
->type
!= F_REG_N
|| user
->reg
!= 0)
1660 case A_IND_R0_REG_N
:
1669 /* Opcode needs rn */
1670 if (user
->type
!= arg
)
1675 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1691 if (user
->type
!= arg
)
1696 if (user
->type
!= arg
)
1702 if (user
->type
!= A_INC_N
)
1704 if (user
->reg
!= 15)
1710 if (user
->type
!= A_DEC_N
)
1712 if (user
->reg
!= 15)
1721 case A_IND_R0_REG_M
:
1724 /* Opcode needs rn */
1725 if (user
->type
!= arg
- A_REG_M
+ A_REG_N
)
1731 if (user
->type
!= A_DEC_N
)
1733 if (user
->reg
< 2 || user
->reg
> 5)
1739 if (user
->type
!= A_INC_N
)
1741 if (user
->reg
< 2 || user
->reg
> 5)
1747 if (user
->type
!= A_IND_N
)
1749 if (user
->reg
< 2 || user
->reg
> 5)
1755 if (user
->type
!= AX_PMOD_N
)
1757 if (user
->reg
< 2 || user
->reg
> 5)
1763 if (user
->type
!= A_INC_N
)
1765 if (user
->reg
< 4 || user
->reg
> 5)
1771 if (user
->type
!= A_IND_N
)
1773 if (user
->reg
< 4 || user
->reg
> 5)
1779 if (user
->type
!= AX_PMOD_N
)
1781 if (user
->reg
< 4 || user
->reg
> 5)
1787 if (user
->type
!= A_INC_N
)
1789 if ((user
->reg
< 4 || user
->reg
> 5)
1790 && (user
->reg
< 0 || user
->reg
> 1))
1796 if (user
->type
!= A_IND_N
)
1798 if ((user
->reg
< 4 || user
->reg
> 5)
1799 && (user
->reg
< 0 || user
->reg
> 1))
1805 if (user
->type
!= AX_PMOD_N
)
1807 if ((user
->reg
< 4 || user
->reg
> 5)
1808 && (user
->reg
< 0 || user
->reg
> 1))
1814 if (user
->type
!= A_INC_N
)
1816 if (user
->reg
< 6 || user
->reg
> 7)
1822 if (user
->type
!= A_IND_N
)
1824 if (user
->reg
< 6 || user
->reg
> 7)
1830 if (user
->type
!= AY_PMOD_N
)
1832 if (user
->reg
< 6 || user
->reg
> 7)
1838 if (user
->type
!= A_INC_N
)
1840 if ((user
->reg
< 6 || user
->reg
> 7)
1841 && (user
->reg
< 2 || user
->reg
> 3))
1847 if (user
->type
!= A_IND_N
)
1849 if ((user
->reg
< 6 || user
->reg
> 7)
1850 && (user
->reg
< 2 || user
->reg
> 3))
1856 if (user
->type
!= AY_PMOD_N
)
1858 if ((user
->reg
< 6 || user
->reg
> 7)
1859 && (user
->reg
< 2 || user
->reg
> 3))
1865 if (user
->type
!= DSP_REG_N
)
1867 if (user
->reg
!= A_A0_NUM
1868 && user
->reg
!= A_A1_NUM
)
1874 if (user
->type
!= DSP_REG_N
)
1896 if (user
->type
!= DSP_REG_N
)
1918 if (user
->type
!= DSP_REG_N
)
1940 if (user
->type
!= DSP_REG_N
)
1962 if (user
->type
!= DSP_REG_N
)
1984 if (user
->type
!= DSP_REG_N
)
2006 if (user
->type
!= DSP_REG_N
)
2028 if (user
->type
!= DSP_REG_N
)
2050 if (user
->type
!= DSP_REG_N
)
2072 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_A0_NUM
)
2076 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X0_NUM
)
2080 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X1_NUM
)
2084 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y0_NUM
)
2088 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y1_NUM
)
2098 /* Opcode needs rn */
2099 if (user
->type
!= arg
- F_REG_M
+ F_REG_N
)
2104 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
2109 if (user
->type
!= XMTRX_M4
)
2115 printf (_("unhandled %d\n"), arg
);
2119 if ( !SH_MERGE_ARCH_SET_VALID (valid_arch
, this_try
->arch
))
2121 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, this_try
->arch
);
2131 insert (char *where
, int how
, int pcrel
, sh_operand_info
*op
)
2133 fix_new_exp (frag_now
,
2134 where
- frag_now
->fr_literal
,
2142 insert4 (char * where
, int how
, int pcrel
, sh_operand_info
* op
)
2144 fix_new_exp (frag_now
,
2145 where
- frag_now
->fr_literal
,
2152 build_relax (sh_opcode_info
*opcode
, sh_operand_info
*op
)
2154 int high_byte
= target_big_endian
? 0 : 1;
2157 if (opcode
->arg
[0] == A_BDISP8
)
2159 int what
= (opcode
->nibbles
[1] & 4) ? COND_JUMP_DELAY
: COND_JUMP
;
2160 p
= frag_var (rs_machine_dependent
,
2161 md_relax_table
[C (what
, COND32
)].rlx_length
,
2162 md_relax_table
[C (what
, COND8
)].rlx_length
,
2164 op
->immediate
.X_add_symbol
,
2165 op
->immediate
.X_add_number
,
2167 p
[high_byte
] = (opcode
->nibbles
[0] << 4) | (opcode
->nibbles
[1]);
2169 else if (opcode
->arg
[0] == A_BDISP12
)
2171 p
= frag_var (rs_machine_dependent
,
2172 md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
,
2173 md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
,
2175 op
->immediate
.X_add_symbol
,
2176 op
->immediate
.X_add_number
,
2178 p
[high_byte
] = (opcode
->nibbles
[0] << 4);
2183 /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
2186 insert_loop_bounds (char *output
, sh_operand_info
*operand
)
2191 /* Since the low byte of the opcode will be overwritten by the reloc, we
2192 can just stash the high byte into both bytes and ignore endianness. */
2195 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
2196 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
2200 static int count
= 0;
2202 /* If the last loop insn is a two-byte-insn, it is in danger of being
2203 swapped with the insn after it. To prevent this, create a new
2204 symbol - complete with SH_LABEL reloc - after the last loop insn.
2205 If the last loop insn is four bytes long, the symbol will be
2206 right in the middle, but four byte insns are not swapped anyways. */
2207 /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
2208 Hence a 9 digit number should be enough to count all REPEATs. */
2210 sprintf (name
, "_R%x", count
++ & 0x3fffffff);
2211 end_sym
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
2212 /* Make this a local symbol. */
2214 SF_SET_LOCAL (end_sym
);
2215 #endif /* OBJ_COFF */
2216 symbol_table_insert (end_sym
);
2217 end_sym
->sy_value
= operand
[1].immediate
;
2218 end_sym
->sy_value
.X_add_number
+= 2;
2219 fix_new (frag_now
, frag_now_fix (), 2, end_sym
, 0, 1, BFD_RELOC_SH_LABEL
);
2222 output
= frag_more (2);
2225 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
2226 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
2228 return frag_more (2);
2231 /* Now we know what sort of opcodes it is, let's build the bytes. */
2234 build_Mytes (sh_opcode_info
*opcode
, sh_operand_info
*operand
)
2239 unsigned int size
= 2;
2240 int low_byte
= target_big_endian
? 1 : 0;
2252 if (SH_MERGE_ARCH_SET (opcode
->arch
, arch_op32
))
2254 output
= frag_more (4);
2259 output
= frag_more (2);
2261 for (index
= 0; index
< max_index
; index
++)
2263 sh_nibble_type i
= opcode
->nibbles
[index
];
2274 nbuf
[index
] = reg_n
;
2277 nbuf
[index
] = reg_m
;
2280 if (reg_n
< 2 || reg_n
> 5)
2281 as_bad (_("Invalid register: 'r%d'"), reg_n
);
2282 nbuf
[index
] = (reg_n
& 3) | 4;
2285 nbuf
[index
] = reg_n
| (reg_m
>> 2);
2288 nbuf
[index
] = reg_b
| 0x08;
2291 nbuf
[index
] = reg_n
| 0x01;
2294 nbuf
[index
] |= 0x08;
2296 insert (output
+ low_byte
, BFD_RELOC_SH_IMM3
, 0, operand
);
2299 nbuf
[index
] |= 0x80;
2301 insert (output
+ low_byte
, BFD_RELOC_SH_IMM3U
, 0, operand
);
2304 insert (output
+ 2, BFD_RELOC_SH_DISP12
, 0, operand
);
2307 insert (output
+ 2, BFD_RELOC_SH_DISP12BY2
, 0, operand
);
2310 insert (output
+ 2, BFD_RELOC_SH_DISP12BY4
, 0, operand
);
2313 insert (output
+ 2, BFD_RELOC_SH_DISP12BY8
, 0, operand
);
2316 insert (output
+ 2, BFD_RELOC_SH_DISP12
, 0, operand
+1);
2319 insert (output
+ 2, BFD_RELOC_SH_DISP12BY2
, 0, operand
+1);
2322 insert (output
+ 2, BFD_RELOC_SH_DISP12BY4
, 0, operand
+1);
2325 insert (output
+ 2, BFD_RELOC_SH_DISP12BY8
, 0, operand
+1);
2330 insert4 (output
, BFD_RELOC_SH_DISP20
, 0, operand
);
2333 insert4 (output
, BFD_RELOC_SH_DISP20BY8
, 0, operand
);
2336 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
);
2339 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
);
2342 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
);
2345 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
+ 1);
2348 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
+ 1);
2351 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
+ 1);
2354 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
);
2357 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
);
2360 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
);
2363 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
+ 1);
2366 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
+ 1);
2369 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
+ 1);
2372 insert (output
, BFD_RELOC_SH_PCRELIMM8BY4
,
2373 operand
->type
!= A_DISP_PC_ABS
, operand
);
2376 insert (output
, BFD_RELOC_SH_PCRELIMM8BY2
,
2377 operand
->type
!= A_DISP_PC_ABS
, operand
);
2380 output
= insert_loop_bounds (output
, operand
);
2381 nbuf
[index
] = opcode
->nibbles
[3];
2385 printf (_("failed for %d\n"), i
);
2389 if (!target_big_endian
)
2391 output
[1] = (nbuf
[0] << 4) | (nbuf
[1]);
2392 output
[0] = (nbuf
[2] << 4) | (nbuf
[3]);
2396 output
[0] = (nbuf
[0] << 4) | (nbuf
[1]);
2397 output
[1] = (nbuf
[2] << 4) | (nbuf
[3]);
2399 if (SH_MERGE_ARCH_SET (opcode
->arch
, arch_op32
))
2401 if (!target_big_endian
)
2403 output
[3] = (nbuf
[4] << 4) | (nbuf
[5]);
2404 output
[2] = (nbuf
[6] << 4) | (nbuf
[7]);
2408 output
[2] = (nbuf
[4] << 4) | (nbuf
[5]);
2409 output
[3] = (nbuf
[6] << 4) | (nbuf
[7]);
2415 /* Find an opcode at the start of *STR_P in the hash table, and set
2416 *STR_P to the first character after the last one read. */
2418 static sh_opcode_info
*
2419 find_cooked_opcode (char **str_p
)
2422 unsigned char *op_start
;
2423 unsigned char *op_end
;
2427 /* Drop leading whitespace. */
2431 /* Find the op code end.
2432 The pre-processor will eliminate whitespace in front of
2433 any '@' after the first argument; we may be called from
2434 assemble_ppi, so the opcode might be terminated by an '@'. */
2435 for (op_start
= op_end
= (unsigned char *) str
;
2438 && !is_end_of_line
[*op_end
] && *op_end
!= ' ' && *op_end
!= '@';
2441 unsigned char c
= op_start
[nlen
];
2443 /* The machine independent code will convert CMP/EQ into cmp/EQ
2444 because it thinks the '/' is the end of the symbol. Moreover,
2445 all but the first sub-insn is a parallel processing insn won't
2446 be capitalized. Instead of hacking up the machine independent
2447 code, we just deal with it here. */
2454 *str_p
= (char *) op_end
;
2457 as_bad (_("can't find opcode "));
2459 return (sh_opcode_info
*) hash_find (opcode_hash_control
, name
);
2462 /* Assemble a parallel processing insn. */
2463 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
2466 assemble_ppi (char *op_end
, sh_opcode_info
*opcode
)
2478 sh_operand_info operand
[3];
2480 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
2481 Make sure we encode a defined insn pattern. */
2486 if (opcode
->arg
[0] != A_END
)
2487 op_end
= get_operands (opcode
, op_end
, operand
);
2489 opcode
= get_specific (opcode
, operand
);
2492 /* Couldn't find an opcode which matched the operands. */
2493 char *where
= frag_more (2);
2498 as_bad (_("invalid operands for opcode"));
2502 if (opcode
->nibbles
[0] != PPI
)
2503 as_bad (_("insn can't be combined with parallel processing insn"));
2505 switch (opcode
->nibbles
[1])
2510 as_bad (_("multiple movx specifications"));
2515 as_bad (_("multiple movy specifications"));
2521 as_bad (_("multiple movx specifications"));
2522 if ((reg_n
< 4 || reg_n
> 5)
2523 && (reg_n
< 0 || reg_n
> 1))
2524 as_bad (_("invalid movx address register"));
2525 if (movy
&& movy
!= DDT_BASE
)
2526 as_bad (_("insn cannot be combined with non-nopy"));
2527 movx
= ((((reg_n
& 1) != 0) << 9)
2528 + (((reg_n
& 4) == 0) << 8)
2530 + (opcode
->nibbles
[2] << 4)
2531 + opcode
->nibbles
[3]
2537 as_bad (_("multiple movy specifications"));
2538 if ((reg_n
< 6 || reg_n
> 7)
2539 && (reg_n
< 2 || reg_n
> 3))
2540 as_bad (_("invalid movy address register"));
2541 if (movx
&& movx
!= DDT_BASE
)
2542 as_bad (_("insn cannot be combined with non-nopx"));
2543 movy
= ((((reg_n
& 1) != 0) << 8)
2544 + (((reg_n
& 4) == 0) << 9)
2546 + (opcode
->nibbles
[2] << 4)
2547 + opcode
->nibbles
[3]
2553 as_bad (_("multiple movx specifications"));
2555 as_bad (_("previous movy requires nopx"));
2556 if (reg_n
< 4 || reg_n
> 5)
2557 as_bad (_("invalid movx address register"));
2558 if (opcode
->nibbles
[2] & 8)
2560 if (reg_m
== A_A1_NUM
)
2562 else if (reg_m
!= A_A0_NUM
)
2563 as_bad (_("invalid movx dsp register"));
2568 as_bad (_("invalid movx dsp register"));
2571 movx
+= ((reg_n
- 4) << 9) + (opcode
->nibbles
[2] << 2) + DDT_BASE
;
2576 as_bad (_("multiple movy specifications"));
2578 as_bad (_("previous movx requires nopy"));
2579 if (opcode
->nibbles
[2] & 8)
2581 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
2584 if (reg_m
== A_A1_NUM
)
2586 else if (reg_m
!= A_A0_NUM
)
2587 as_bad (_("invalid movy dsp register"));
2592 as_bad (_("invalid movy dsp register"));
2595 if (reg_n
< 6 || reg_n
> 7)
2596 as_bad (_("invalid movy address register"));
2597 movy
+= ((reg_n
- 6) << 8) + opcode
->nibbles
[2] + DDT_BASE
;
2601 if (operand
[0].immediate
.X_op
!= O_constant
)
2602 as_bad (_("dsp immediate shift value not constant"));
2603 field_b
= ((opcode
->nibbles
[2] << 12)
2604 | (operand
[0].immediate
.X_add_number
& 127) << 4
2611 goto try_another_opcode
;
2616 as_bad (_("multiple parallel processing specifications"));
2617 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2618 + (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2619 switch (opcode
->nibbles
[4])
2627 field_b
+= opcode
->nibbles
[4] << 4;
2635 as_bad (_("multiple condition specifications"));
2636 cond
= opcode
->nibbles
[2] << 8;
2638 goto skip_cond_check
;
2642 as_bad (_("multiple parallel processing specifications"));
2643 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2644 + cond
+ (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2646 switch (opcode
->nibbles
[4])
2654 field_b
+= opcode
->nibbles
[4] << 4;
2663 if ((field_b
& 0xef00) == 0xa100)
2665 /* pclr Dz pmuls Se,Sf,Dg */
2666 else if ((field_b
& 0xff00) == 0x8d00
2667 && (SH_MERGE_ARCH_SET_VALID (valid_arch
, arch_sh4al_dsp_up
)))
2669 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, arch_sh4al_dsp_up
);
2673 as_bad (_("insn cannot be combined with pmuls"));
2674 switch (field_b
& 0xf)
2677 field_b
+= 0 - A_X0_NUM
;
2680 field_b
+= 1 - A_Y0_NUM
;
2683 field_b
+= 2 - A_A0_NUM
;
2686 field_b
+= 3 - A_A1_NUM
;
2689 as_bad (_("bad combined pmuls output operand"));
2691 /* Generate warning if the destination register for padd / psub
2692 and pmuls is the same ( only for A0 or A1 ).
2693 If the last nibble is 1010 then A0 is used in both
2694 padd / psub and pmuls. If it is 1111 then A1 is used
2695 as destination register in both padd / psub and pmuls. */
2697 if ((((field_b
| reg_efg
) & 0x000F) == 0x000A)
2698 || (((field_b
| reg_efg
) & 0x000F) == 0x000F))
2699 as_warn (_("destination register is same for parallel insns"));
2701 field_b
+= 0x4000 + reg_efg
;
2708 as_bad (_("condition not followed by conditionalizable insn"));
2714 opcode
= find_cooked_opcode (&op_end
);
2718 (_("unrecognized characters at end of parallel processing insn")));
2723 move_code
= movx
| movy
;
2726 /* Parallel processing insn. */
2727 unsigned long ppi_code
= (movx
| movy
| 0xf800) << 16 | field_b
;
2729 output
= frag_more (4);
2731 if (! target_big_endian
)
2733 output
[3] = ppi_code
>> 8;
2734 output
[2] = ppi_code
;
2738 output
[2] = ppi_code
>> 8;
2739 output
[3] = ppi_code
;
2741 move_code
|= 0xf800;
2745 /* Just a double data transfer. */
2746 output
= frag_more (2);
2749 if (! target_big_endian
)
2751 output
[1] = move_code
>> 8;
2752 output
[0] = move_code
;
2756 output
[0] = move_code
>> 8;
2757 output
[1] = move_code
;
2762 /* This is the guts of the machine-dependent assembler. STR points to a
2763 machine dependent instruction. This function is supposed to emit
2764 the frags/bytes it assembles to. */
2767 md_assemble (char *str
)
2770 sh_operand_info operand
[3];
2771 sh_opcode_info
*opcode
;
2772 unsigned int size
= 0;
2773 char *initial_str
= str
;
2776 if (sh64_isa_mode
== sh64_isa_shmedia
)
2778 shmedia_md_assemble (str
);
2783 /* If we've seen pseudo-directives, make sure any emitted data or
2784 frags are marked as data. */
2787 sh64_update_contents_mark (TRUE
);
2788 sh64_set_contents_type (CRT_SH5_ISA16
);
2793 #endif /* HAVE_SH64 */
2795 opcode
= find_cooked_opcode (&str
);
2800 /* The opcode is not in the hash table.
2801 This means we definately have an assembly failure,
2802 but the instruction may be valid in another CPU variant.
2803 In this case emit something better than 'unknown opcode'.
2804 Search the full table in sh-opc.h to check. */
2806 char *name
= initial_str
;
2807 int name_length
= 0;
2808 const sh_opcode_info
*op
;
2811 /* identify opcode in string */
2812 while (ISSPACE (*name
))
2816 while (!ISSPACE (name
[name_length
]))
2821 /* search for opcode in full list */
2822 for (op
= sh_table
; op
->name
; op
++)
2824 if (strncasecmp (op
->name
, name
, name_length
) == 0
2825 && op
->name
[name_length
] == '\0')
2834 as_bad (_("opcode not valid for this cpu variant"));
2838 as_bad (_("unknown opcode"));
2844 && ! seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2846 /* Output a CODE reloc to tell the linker that the following
2847 bytes are instructions, not data. */
2848 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2850 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 1;
2853 if (opcode
->nibbles
[0] == PPI
)
2855 size
= assemble_ppi (op_end
, opcode
);
2859 if (opcode
->arg
[0] == A_BDISP12
2860 || opcode
->arg
[0] == A_BDISP8
)
2862 /* Since we skip get_specific here, we have to check & update
2864 if (SH_MERGE_ARCH_SET_VALID (valid_arch
, opcode
->arch
))
2865 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, opcode
->arch
);
2867 as_bad (_("Delayed branches not available on SH1"));
2868 parse_exp (op_end
+ 1, &operand
[0]);
2869 build_relax (opcode
, &operand
[0]);
2873 if (opcode
->arg
[0] == A_END
)
2875 /* Ignore trailing whitespace. If there is any, it has already
2876 been compressed to a single space. */
2882 op_end
= get_operands (opcode
, op_end
, operand
);
2884 opcode
= get_specific (opcode
, operand
);
2888 /* Couldn't find an opcode which matched the operands. */
2889 char *where
= frag_more (2);
2894 as_bad (_("invalid operands for opcode"));
2899 as_bad (_("excess operands: '%s'"), op_end
);
2901 size
= build_Mytes (opcode
, operand
);
2906 dwarf2_emit_insn (size
);
2909 /* This routine is called each time a label definition is seen. It
2910 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
2913 sh_frob_label (symbolS
*sym
)
2915 static fragS
*last_label_frag
;
2916 static int last_label_offset
;
2919 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2923 offset
= frag_now_fix ();
2924 if (frag_now
!= last_label_frag
2925 || offset
!= last_label_offset
)
2927 fix_new (frag_now
, offset
, 2, &abs_symbol
, 0, 0, BFD_RELOC_SH_LABEL
);
2928 last_label_frag
= frag_now
;
2929 last_label_offset
= offset
;
2933 dwarf2_emit_label (sym
);
2936 /* This routine is called when the assembler is about to output some
2937 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
2940 sh_flush_pending_output (void)
2943 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2945 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2947 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 0;
2952 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2957 /* Various routines to kill one day. */
2958 /* Equal to MAX_PRECISION in atof-ieee.c. */
2959 #define MAX_LITTLENUMS 6
2961 /* Turn a string in input_line_pointer into a floating point constant
2962 of type TYPE, and store the appropriate bytes in *LITP. The number
2963 of LITTLENUMS emitted is stored in *SIZEP . An error message is
2964 returned, or NULL on OK. */
2967 md_atof (int type
, char *litP
, int *sizeP
)
2970 LITTLENUM_TYPE words
[4];
2986 return _("bad call to md_atof");
2989 t
= atof_ieee (input_line_pointer
, type
, words
);
2991 input_line_pointer
= t
;
2995 if (! target_big_endian
)
2997 for (i
= prec
- 1; i
>= 0; i
--)
2999 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
3005 for (i
= 0; i
< prec
; i
++)
3007 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
3015 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
3016 call instruction. It refers to a label of the instruction which
3017 loads the register which the call uses. We use it to generate a
3018 special reloc for the linker. */
3021 s_uses (int ignore ATTRIBUTE_UNUSED
)
3026 as_warn (_(".uses pseudo-op seen when not relaxing"));
3030 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
3032 as_bad (_("bad .uses format"));
3033 ignore_rest_of_line ();
3037 fix_new_exp (frag_now
, frag_now_fix (), 2, &ex
, 1, BFD_RELOC_SH_USES
);
3039 demand_empty_rest_of_line ();
3044 OPTION_RELAX
= OPTION_MD_BASE
,
3051 OPTION_ALLOW_REG_PREFIX
,
3055 OPTION_SHCOMPACT_CONST_CRANGE
,
3059 OPTION_DUMMY
/* Not used. This is just here to make it easy to add and subtract options from this enum. */
3062 const char *md_shortopts
= "";
3063 struct option md_longopts
[] =
3065 {"relax", no_argument
, NULL
, OPTION_RELAX
},
3066 {"big", no_argument
, NULL
, OPTION_BIG
},
3067 {"little", no_argument
, NULL
, OPTION_LITTLE
},
3068 {"small", no_argument
, NULL
, OPTION_SMALL
},
3069 {"dsp", no_argument
, NULL
, OPTION_DSP
},
3070 {"isa", required_argument
, NULL
, OPTION_ISA
},
3071 {"renesas", no_argument
, NULL
, OPTION_RENESAS
},
3072 {"allow-reg-prefix", no_argument
, NULL
, OPTION_ALLOW_REG_PREFIX
},
3075 {"abi", required_argument
, NULL
, OPTION_ABI
},
3076 {"no-mix", no_argument
, NULL
, OPTION_NO_MIX
},
3077 {"shcompact-const-crange", no_argument
, NULL
, OPTION_SHCOMPACT_CONST_CRANGE
},
3078 {"no-expand", no_argument
, NULL
, OPTION_NO_EXPAND
},
3079 {"expand-pt32", no_argument
, NULL
, OPTION_PT32
},
3080 #endif /* HAVE_SH64 */
3082 {NULL
, no_argument
, NULL
, 0}
3084 size_t md_longopts_size
= sizeof (md_longopts
);
3087 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
3096 target_big_endian
= 1;
3100 target_big_endian
= 0;
3108 preset_target_arch
= arch_sh_up
& ~(arch_sh_sp_fpu
|arch_sh_dp_fpu
);
3111 case OPTION_RENESAS
:
3112 dont_adjust_reloc_32
= 1;
3115 case OPTION_ALLOW_REG_PREFIX
:
3116 allow_dollar_register_prefix
= 1;
3120 if (strcasecmp (arg
, "dsp") == 0)
3121 preset_target_arch
= arch_sh_up
& ~(arch_sh_sp_fpu
|arch_sh_dp_fpu
);
3122 else if (strcasecmp (arg
, "fp") == 0)
3123 preset_target_arch
= arch_sh_up
& ~arch_sh_has_dsp
;
3124 else if (strcasecmp (arg
, "any") == 0)
3125 preset_target_arch
= arch_sh_up
;
3127 else if (strcasecmp (arg
, "shmedia") == 0)
3129 if (sh64_isa_mode
== sh64_isa_shcompact
)
3130 as_bad (_("Invalid combination: --isa=SHcompact with --isa=SHmedia"));
3131 sh64_isa_mode
= sh64_isa_shmedia
;
3133 else if (strcasecmp (arg
, "shcompact") == 0)
3135 if (sh64_isa_mode
== sh64_isa_shmedia
)
3136 as_bad (_("Invalid combination: --isa=SHmedia with --isa=SHcompact"));
3137 if (sh64_abi
== sh64_abi_64
)
3138 as_bad (_("Invalid combination: --abi=64 with --isa=SHcompact"));
3139 sh64_isa_mode
= sh64_isa_shcompact
;
3141 #endif /* HAVE_SH64 */
3144 extern const bfd_arch_info_type bfd_sh_arch
;
3145 bfd_arch_info_type
const *bfd_arch
= &bfd_sh_arch
;
3147 preset_target_arch
= 0;
3148 for (; bfd_arch
; bfd_arch
=bfd_arch
->next
)
3150 int len
= strlen(bfd_arch
->printable_name
);
3152 if (bfd_arch
->mach
== bfd_mach_sh5
)
3155 if (strncasecmp (bfd_arch
->printable_name
, arg
, len
) != 0)
3158 if (arg
[len
] == '\0')
3159 preset_target_arch
=
3160 sh_get_arch_from_bfd_mach (bfd_arch
->mach
);
3161 else if (strcasecmp(&arg
[len
], "-up") == 0)
3162 preset_target_arch
=
3163 sh_get_arch_up_from_bfd_mach (bfd_arch
->mach
);
3169 if (!preset_target_arch
)
3170 as_bad ("Invalid argument to --isa option: %s", arg
);
3176 if (strcmp (arg
, "32") == 0)
3178 if (sh64_abi
== sh64_abi_64
)
3179 as_bad (_("Invalid combination: --abi=32 with --abi=64"));
3180 sh64_abi
= sh64_abi_32
;
3182 else if (strcmp (arg
, "64") == 0)
3184 if (sh64_abi
== sh64_abi_32
)
3185 as_bad (_("Invalid combination: --abi=64 with --abi=32"));
3186 if (sh64_isa_mode
== sh64_isa_shcompact
)
3187 as_bad (_("Invalid combination: --isa=SHcompact with --abi=64"));
3188 sh64_abi
= sh64_abi_64
;
3191 as_bad ("Invalid argument to --abi option: %s", arg
);
3198 case OPTION_SHCOMPACT_CONST_CRANGE
:
3199 sh64_shcompact_const_crange
= TRUE
;
3202 case OPTION_NO_EXPAND
:
3203 sh64_expand
= FALSE
;
3209 #endif /* HAVE_SH64 */
3219 md_show_usage (FILE *stream
)
3221 fprintf (stream
, _("\
3223 --little generate little endian code\n\
3224 --big generate big endian code\n\
3225 --relax alter jump instructions for long displacements\n\
3226 --renesas disable optimization with section symbol for\n\
3227 compatibility with Renesas assembler.\n\
3228 --small align sections to 4 byte boundaries, not 16\n\
3229 --dsp enable sh-dsp insns, and disable floating-point ISAs.\n\
3230 --allow-reg-prefix allow '$' as a register name prefix.\n\
3231 --isa=[any use most appropriate isa\n\
3232 | dsp same as '-dsp'\n\
3235 extern const bfd_arch_info_type bfd_sh_arch
;
3236 bfd_arch_info_type
const *bfd_arch
= &bfd_sh_arch
;
3238 for (; bfd_arch
; bfd_arch
=bfd_arch
->next
)
3239 if (bfd_arch
->mach
!= bfd_mach_sh5
)
3241 fprintf (stream
, "\n | %s", bfd_arch
->printable_name
);
3242 fprintf (stream
, "\n | %s-up", bfd_arch
->printable_name
);
3245 fprintf (stream
, "]\n");
3247 fprintf (stream
, _("\
3248 --isa=[shmedia set as the default instruction set for SH64\n\
3252 fprintf (stream
, _("\
3253 --abi=[32|64] set size of expanded SHmedia operands and object\n\
3255 --shcompact-const-crange emit code-range descriptors for constants in\n\
3256 SHcompact code sections\n\
3257 --no-mix disallow SHmedia code in the same section as\n\
3258 constants and SHcompact code\n\
3259 --no-expand do not expand MOVI, PT, PTA or PTB instructions\n\
3260 --expand-pt32 with -abi=64, expand PT, PTA and PTB instructions\n\
3261 to 32 bits only\n"));
3262 #endif /* HAVE_SH64 */
3265 /* This struct is used to pass arguments to sh_count_relocs through
3266 bfd_map_over_sections. */
3268 struct sh_count_relocs
3270 /* Symbol we are looking for. */
3272 /* Count of relocs found. */
3276 /* Count the number of fixups in a section which refer to a particular
3277 symbol. This is called via bfd_map_over_sections. */
3280 sh_count_relocs (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec
, void *data
)
3282 struct sh_count_relocs
*info
= (struct sh_count_relocs
*) data
;
3283 segment_info_type
*seginfo
;
3287 seginfo
= seg_info (sec
);
3288 if (seginfo
== NULL
)
3292 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
3294 if (fix
->fx_addsy
== sym
)
3302 /* Handle the count relocs for a particular section.
3303 This is called via bfd_map_over_sections. */
3306 sh_frob_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec
,
3307 void *ignore ATTRIBUTE_UNUSED
)
3309 segment_info_type
*seginfo
;
3312 seginfo
= seg_info (sec
);
3313 if (seginfo
== NULL
)
3316 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
3321 struct sh_count_relocs info
;
3323 if (fix
->fx_r_type
!= BFD_RELOC_SH_USES
)
3326 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
3327 symbol in the same section. */
3328 sym
= fix
->fx_addsy
;
3330 || fix
->fx_subsy
!= NULL
3331 || fix
->fx_addnumber
!= 0
3332 || S_GET_SEGMENT (sym
) != sec
3333 || S_IS_EXTERNAL (sym
))
3335 as_warn_where (fix
->fx_file
, fix
->fx_line
,
3336 _(".uses does not refer to a local symbol in the same section"));
3340 /* Look through the fixups again, this time looking for one
3341 at the same location as sym. */
3342 val
= S_GET_VALUE (sym
);
3343 for (fscan
= seginfo
->fix_root
;
3345 fscan
= fscan
->fx_next
)
3346 if (val
== fscan
->fx_frag
->fr_address
+ fscan
->fx_where
3347 && fscan
->fx_r_type
!= BFD_RELOC_SH_ALIGN
3348 && fscan
->fx_r_type
!= BFD_RELOC_SH_CODE
3349 && fscan
->fx_r_type
!= BFD_RELOC_SH_DATA
3350 && fscan
->fx_r_type
!= BFD_RELOC_SH_LABEL
)
3354 as_warn_where (fix
->fx_file
, fix
->fx_line
,
3355 _("can't find fixup pointed to by .uses"));
3359 if (fscan
->fx_tcbit
)
3361 /* We've already done this one. */
3365 /* The variable fscan should also be a fixup to a local symbol
3366 in the same section. */
3367 sym
= fscan
->fx_addsy
;
3369 || fscan
->fx_subsy
!= NULL
3370 || fscan
->fx_addnumber
!= 0
3371 || S_GET_SEGMENT (sym
) != sec
3372 || S_IS_EXTERNAL (sym
))
3374 as_warn_where (fix
->fx_file
, fix
->fx_line
,
3375 _(".uses target does not refer to a local symbol in the same section"));
3379 /* Now we look through all the fixups of all the sections,
3380 counting the number of times we find a reference to sym. */
3383 bfd_map_over_sections (stdoutput
, sh_count_relocs
, &info
);
3388 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
3389 We have already adjusted the value of sym to include the
3390 fragment address, so we undo that adjustment here. */
3391 subseg_change (sec
, 0);
3392 fix_new (fscan
->fx_frag
,
3393 S_GET_VALUE (sym
) - fscan
->fx_frag
->fr_address
,
3394 4, &abs_symbol
, info
.count
, 0, BFD_RELOC_SH_COUNT
);
3398 /* This function is called after the symbol table has been completed,
3399 but before the relocs or section contents have been written out.
3400 If we have seen any .uses pseudo-ops, they point to an instruction
3401 which loads a register with the address of a function. We look
3402 through the fixups to find where the function address is being
3403 loaded from. We then generate a COUNT reloc giving the number of
3404 times that function address is referred to. The linker uses this
3405 information when doing relaxing, to decide when it can eliminate
3406 the stored function address entirely. */
3412 shmedia_frob_file_before_adjust ();
3418 bfd_map_over_sections (stdoutput
, sh_frob_section
, NULL
);
3421 /* Called after relaxing. Set the correct sizes of the fragments, and
3422 create relocs so that md_apply_fix will fill in the correct values. */
3425 md_convert_frag (bfd
*headers ATTRIBUTE_UNUSED
, segT seg
, fragS
*fragP
)
3429 switch (fragP
->fr_subtype
)
3431 case C (COND_JUMP
, COND8
):
3432 case C (COND_JUMP_DELAY
, COND8
):
3433 subseg_change (seg
, 0);
3434 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
3435 1, BFD_RELOC_SH_PCDISP8BY2
);
3440 case C (UNCOND_JUMP
, UNCOND12
):
3441 subseg_change (seg
, 0);
3442 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
3443 1, BFD_RELOC_SH_PCDISP12BY2
);
3448 case C (UNCOND_JUMP
, UNCOND32
):
3449 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
3450 if (fragP
->fr_symbol
== NULL
)
3451 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3452 _("displacement overflows 12-bit field"));
3453 else if (S_IS_DEFINED (fragP
->fr_symbol
))
3454 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3455 _("displacement to defined symbol %s overflows 12-bit field"),
3456 S_GET_NAME (fragP
->fr_symbol
));
3458 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3459 _("displacement to undefined symbol %s overflows 12-bit field"),
3460 S_GET_NAME (fragP
->fr_symbol
));
3461 /* Stabilize this frag, so we don't trip an assert. */
3462 fragP
->fr_fix
+= fragP
->fr_var
;
3466 case C (COND_JUMP
, COND12
):
3467 case C (COND_JUMP_DELAY
, COND12
):
3468 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
3469 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
3470 was due to gas incorrectly relaxing an out-of-range conditional
3471 branch with delay slot. It turned:
3472 bf.s L6 (slot mov.l r12,@(44,r0))
3475 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
3477 32: 10 cb mov.l r12,@(44,r0)
3478 Therefore, branches with delay slots have to be handled
3479 differently from ones without delay slots. */
3481 unsigned char *buffer
=
3482 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
3483 int highbyte
= target_big_endian
? 0 : 1;
3484 int lowbyte
= target_big_endian
? 1 : 0;
3485 int delay
= fragP
->fr_subtype
== C (COND_JUMP_DELAY
, COND12
);
3487 /* Toggle the true/false bit of the bcond. */
3488 buffer
[highbyte
] ^= 0x2;
3490 /* If this is a delayed branch, we may not put the bra in the
3491 slot. So we change it to a non-delayed branch, like that:
3492 b! cond slot_label; bra disp; slot_label: slot_insn
3493 ??? We should try if swapping the conditional branch and
3494 its delay-slot insn already makes the branch reach. */
3496 /* Build a relocation to six / four bytes farther on. */
3497 subseg_change (seg
, 0);
3498 fix_new (fragP
, fragP
->fr_fix
, 2, section_symbol (seg
),
3499 fragP
->fr_address
+ fragP
->fr_fix
+ (delay
? 4 : 6),
3500 1, BFD_RELOC_SH_PCDISP8BY2
);
3502 /* Set up a jump instruction. */
3503 buffer
[highbyte
+ 2] = 0xa0;
3504 buffer
[lowbyte
+ 2] = 0;
3505 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
3506 fragP
->fr_offset
, 1, BFD_RELOC_SH_PCDISP12BY2
);
3510 buffer
[highbyte
] &= ~0x4; /* Removes delay slot from branch. */
3515 /* Fill in a NOP instruction. */
3516 buffer
[highbyte
+ 4] = 0x0;
3517 buffer
[lowbyte
+ 4] = 0x9;
3526 case C (COND_JUMP
, COND32
):
3527 case C (COND_JUMP_DELAY
, COND32
):
3528 case C (COND_JUMP
, UNDEF_WORD_DISP
):
3529 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
3530 if (fragP
->fr_symbol
== NULL
)
3531 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3532 _("displacement overflows 8-bit field"));
3533 else if (S_IS_DEFINED (fragP
->fr_symbol
))
3534 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3535 _("displacement to defined symbol %s overflows 8-bit field"),
3536 S_GET_NAME (fragP
->fr_symbol
));
3538 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3539 _("displacement to undefined symbol %s overflows 8-bit field "),
3540 S_GET_NAME (fragP
->fr_symbol
));
3541 /* Stabilize this frag, so we don't trip an assert. */
3542 fragP
->fr_fix
+= fragP
->fr_var
;
3548 shmedia_md_convert_frag (headers
, seg
, fragP
, TRUE
);
3554 if (donerelax
&& !sh_relax
)
3555 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
3556 _("overflow in branch to %s; converted into longer instruction sequence"),
3557 (fragP
->fr_symbol
!= NULL
3558 ? S_GET_NAME (fragP
->fr_symbol
)
3563 md_section_align (segT seg ATTRIBUTE_UNUSED
, valueT size
)
3567 #else /* ! OBJ_ELF */
3568 return ((size
+ (1 << bfd_get_section_alignment (stdoutput
, seg
)) - 1)
3569 & (-1 << bfd_get_section_alignment (stdoutput
, seg
)));
3570 #endif /* ! OBJ_ELF */
3573 /* This static variable is set by s_uacons to tell sh_cons_align that
3574 the expression does not need to be aligned. */
3576 static int sh_no_align_cons
= 0;
3578 /* This handles the unaligned space allocation pseudo-ops, such as
3579 .uaword. .uaword is just like .word, but the value does not need
3583 s_uacons (int bytes
)
3585 /* Tell sh_cons_align not to align this value. */
3586 sh_no_align_cons
= 1;
3590 /* If a .word, et. al., pseud-op is seen, warn if the value is not
3591 aligned correctly. Note that this can cause warnings to be issued
3592 when assembling initialized structured which were declared with the
3593 packed attribute. FIXME: Perhaps we should require an option to
3594 enable this warning? */
3597 sh_cons_align (int nbytes
)
3602 if (sh_no_align_cons
)
3604 /* This is an unaligned pseudo-op. */
3605 sh_no_align_cons
= 0;
3610 while ((nbytes
& 1) == 0)
3619 if (now_seg
== absolute_section
)
3621 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
3622 as_warn (_("misaligned data"));
3626 p
= frag_var (rs_align_test
, 1, 1, (relax_substateT
) 0,
3627 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
3629 record_alignment (now_seg
, nalign
);
3632 /* When relaxing, we need to output a reloc for any .align directive
3633 that requests alignment to a four byte boundary or larger. This is
3634 also where we check for misaligned data. */
3637 sh_handle_align (fragS
*frag
)
3639 int bytes
= frag
->fr_next
->fr_address
- frag
->fr_address
- frag
->fr_fix
;
3641 if (frag
->fr_type
== rs_align_code
)
3643 static const unsigned char big_nop_pattern
[] = { 0x00, 0x09 };
3644 static const unsigned char little_nop_pattern
[] = { 0x09, 0x00 };
3646 char *p
= frag
->fr_literal
+ frag
->fr_fix
;
3655 if (target_big_endian
)
3657 memcpy (p
, big_nop_pattern
, sizeof big_nop_pattern
);
3658 frag
->fr_var
= sizeof big_nop_pattern
;
3662 memcpy (p
, little_nop_pattern
, sizeof little_nop_pattern
);
3663 frag
->fr_var
= sizeof little_nop_pattern
;
3666 else if (frag
->fr_type
== rs_align_test
)
3669 as_warn_where (frag
->fr_file
, frag
->fr_line
, _("misaligned data"));
3673 && (frag
->fr_type
== rs_align
3674 || frag
->fr_type
== rs_align_code
)
3675 && frag
->fr_address
+ frag
->fr_fix
> 0
3676 && frag
->fr_offset
> 1
3677 && now_seg
!= bss_section
)
3678 fix_new (frag
, frag
->fr_fix
, 2, &abs_symbol
, frag
->fr_offset
, 0,
3679 BFD_RELOC_SH_ALIGN
);
3682 /* See whether the relocation should be resolved locally. */
3685 sh_local_pcrel (fixS
*fix
)
3688 && (fix
->fx_r_type
== BFD_RELOC_SH_PCDISP8BY2
3689 || fix
->fx_r_type
== BFD_RELOC_SH_PCDISP12BY2
3690 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY2
3691 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY4
3692 || fix
->fx_r_type
== BFD_RELOC_8_PCREL
3693 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH16
3694 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH32
));
3697 /* See whether we need to force a relocation into the output file.
3698 This is used to force out switch and PC relative relocations when
3702 sh_force_relocation (fixS
*fix
)
3704 /* These relocations can't make it into a DSO, so no use forcing
3705 them for global symbols. */
3706 if (sh_local_pcrel (fix
))
3709 /* Make sure some relocations get emitted. */
3710 if (fix
->fx_r_type
== BFD_RELOC_SH_LOOP_START
3711 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_END
3712 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_GD_32
3713 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LD_32
3714 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_IE_32
3715 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LDO_32
3716 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LE_32
3717 || generic_force_reloc (fix
))
3723 return (fix
->fx_pcrel
3724 || SWITCH_TABLE (fix
)
3725 || fix
->fx_r_type
== BFD_RELOC_SH_COUNT
3726 || fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
3727 || fix
->fx_r_type
== BFD_RELOC_SH_CODE
3728 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
3730 || fix
->fx_r_type
== BFD_RELOC_SH_SHMEDIA_CODE
3732 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
);
3737 sh_fix_adjustable (fixS
*fixP
)
3739 if (fixP
->fx_r_type
== BFD_RELOC_32_PLT_PCREL
3740 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
3741 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTPC
3742 || ((fixP
->fx_r_type
== BFD_RELOC_32
) && dont_adjust_reloc_32
)
3743 || fixP
->fx_r_type
== BFD_RELOC_RVA
)
3746 /* We need the symbol name for the VTABLE entries */
3747 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3748 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
3755 sh_elf_final_processing (void)
3759 /* Set file-specific flags to indicate if this code needs
3760 a processor with the sh-dsp / sh2e ISA to execute. */
3762 /* SH5 and above don't know about the valid_arch arch_sh* bits defined
3763 in sh-opc.h, so check SH64 mode before checking valid_arch. */
3764 if (sh64_isa_mode
!= sh64_isa_unspecified
)
3767 #elif defined TARGET_SYMBIAN
3770 extern int sh_symbian_find_elf_flags (unsigned int);
3772 val
= sh_symbian_find_elf_flags (valid_arch
);
3775 #endif /* HAVE_SH64 */
3776 val
= sh_find_elf_flags (valid_arch
);
3778 elf_elfheader (stdoutput
)->e_flags
&= ~EF_SH_MACH_MASK
;
3779 elf_elfheader (stdoutput
)->e_flags
|= val
;
3783 /* Apply a fixup to the object file. */
3786 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3788 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3789 int lowbyte
= target_big_endian
? 1 : 0;
3790 int highbyte
= target_big_endian
? 0 : 1;
3791 long val
= (long) *valP
;
3795 /* A difference between two symbols, the second of which is in the
3796 current section, is transformed in a PC-relative relocation to
3797 the other symbol. We have to adjust the relocation type here. */
3800 switch (fixP
->fx_r_type
)
3806 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
3809 /* Currently, we only support 32-bit PCREL relocations.
3810 We'd need a new reloc type to handle 16_PCREL, and
3811 8_PCREL is already taken for R_SH_SWITCH8, which
3812 apparently does something completely different than what
3815 bfd_set_error (bfd_error_bad_value
);
3819 bfd_set_error (bfd_error_bad_value
);
3824 /* The function adjust_reloc_syms won't convert a reloc against a weak
3825 symbol into a reloc against a section, but bfd_install_relocation
3826 will screw up if the symbol is defined, so we have to adjust val here
3827 to avoid the screw up later.
3829 For ordinary relocs, this does not happen for ELF, since for ELF,
3830 bfd_install_relocation uses the "special function" field of the
3831 howto, and does not execute the code that needs to be undone, as long
3832 as the special function does not return bfd_reloc_continue.
3833 It can happen for GOT- and PLT-type relocs the way they are
3834 described in elf32-sh.c as they use bfd_elf_generic_reloc, but it
3835 doesn't matter here since those relocs don't use VAL; see below. */
3836 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
3837 && fixP
->fx_addsy
!= NULL
3838 && S_IS_WEAK (fixP
->fx_addsy
))
3839 val
-= S_GET_VALUE (fixP
->fx_addsy
);
3841 if (SWITCH_TABLE (fixP
))
3842 val
-= S_GET_VALUE (fixP
->fx_subsy
);
3846 switch (fixP
->fx_r_type
)
3848 case BFD_RELOC_SH_IMM3
:
3850 * buf
= (* buf
& 0xf8) | (val
& 0x7);
3852 case BFD_RELOC_SH_IMM3U
:
3854 * buf
= (* buf
& 0x8f) | ((val
& 0x7) << 4);
3856 case BFD_RELOC_SH_DISP12
:
3858 buf
[lowbyte
] = val
& 0xff;
3859 buf
[highbyte
] |= (val
>> 8) & 0x0f;
3861 case BFD_RELOC_SH_DISP12BY2
:
3864 buf
[lowbyte
] = (val
>> 1) & 0xff;
3865 buf
[highbyte
] |= (val
>> 9) & 0x0f;
3867 case BFD_RELOC_SH_DISP12BY4
:
3870 buf
[lowbyte
] = (val
>> 2) & 0xff;
3871 buf
[highbyte
] |= (val
>> 10) & 0x0f;
3873 case BFD_RELOC_SH_DISP12BY8
:
3876 buf
[lowbyte
] = (val
>> 3) & 0xff;
3877 buf
[highbyte
] |= (val
>> 11) & 0x0f;
3879 case BFD_RELOC_SH_DISP20
:
3880 if (! target_big_endian
)
3884 buf
[1] = (buf
[1] & 0x0f) | ((val
>> 12) & 0xf0);
3885 buf
[2] = (val
>> 8) & 0xff;
3886 buf
[3] = val
& 0xff;
3888 case BFD_RELOC_SH_DISP20BY8
:
3889 if (!target_big_endian
)
3894 buf
[1] = (buf
[1] & 0x0f) | ((val
>> 20) & 0xf0);
3895 buf
[2] = (val
>> 16) & 0xff;
3896 buf
[3] = (val
>> 8) & 0xff;
3899 case BFD_RELOC_SH_IMM4
:
3901 *buf
= (*buf
& 0xf0) | (val
& 0xf);
3904 case BFD_RELOC_SH_IMM4BY2
:
3907 *buf
= (*buf
& 0xf0) | ((val
>> 1) & 0xf);
3910 case BFD_RELOC_SH_IMM4BY4
:
3913 *buf
= (*buf
& 0xf0) | ((val
>> 2) & 0xf);
3916 case BFD_RELOC_SH_IMM8BY2
:
3922 case BFD_RELOC_SH_IMM8BY4
:
3929 case BFD_RELOC_SH_IMM8
:
3930 /* Sometimes the 8 bit value is sign extended (e.g., add) and
3931 sometimes it is not (e.g., and). We permit any 8 bit value.
3932 Note that adding further restrictions may invalidate
3933 reasonable looking assembly code, such as ``and -0x1,r0''. */
3939 case BFD_RELOC_SH_PCRELIMM8BY4
:
3940 /* The lower two bits of the PC are cleared before the
3941 displacement is added in. We can assume that the destination
3942 is on a 4 byte boundary. If this instruction is also on a 4
3943 byte boundary, then we want
3945 and target - here is a multiple of 4.
3946 Otherwise, we are on a 2 byte boundary, and we want
3947 (target - (here - 2)) / 4
3948 and target - here is not a multiple of 4. Computing
3949 (target - (here - 2)) / 4 == (target - here + 2) / 4
3950 works for both cases, since in the first case the addition of
3951 2 will be removed by the division. target - here is in the
3953 val
= (val
+ 2) / 4;
3955 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3959 case BFD_RELOC_SH_PCRELIMM8BY2
:
3962 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3966 case BFD_RELOC_SH_PCDISP8BY2
:
3968 if (val
< -0x80 || val
> 0x7f)
3969 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3973 case BFD_RELOC_SH_PCDISP12BY2
:
3975 if (val
< -0x800 || val
> 0x7ff)
3976 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3977 buf
[lowbyte
] = val
& 0xff;
3978 buf
[highbyte
] |= (val
>> 8) & 0xf;
3982 case BFD_RELOC_32_PCREL
:
3983 md_number_to_chars (buf
, val
, 4);
3987 md_number_to_chars (buf
, val
, 2);
3990 case BFD_RELOC_SH_USES
:
3991 /* Pass the value into sh_reloc(). */
3992 fixP
->fx_addnumber
= val
;
3995 case BFD_RELOC_SH_COUNT
:
3996 case BFD_RELOC_SH_ALIGN
:
3997 case BFD_RELOC_SH_CODE
:
3998 case BFD_RELOC_SH_DATA
:
3999 case BFD_RELOC_SH_LABEL
:
4000 /* Nothing to do here. */
4003 case BFD_RELOC_SH_LOOP_START
:
4004 case BFD_RELOC_SH_LOOP_END
:
4006 case BFD_RELOC_VTABLE_INHERIT
:
4007 case BFD_RELOC_VTABLE_ENTRY
:
4012 case BFD_RELOC_32_PLT_PCREL
:
4013 /* Make the jump instruction point to the address of the operand. At
4014 runtime we merely add the offset to the actual PLT entry. */
4015 * valP
= 0xfffffffc;
4016 val
= fixP
->fx_offset
;
4018 val
-= S_GET_VALUE (fixP
->fx_subsy
);
4019 fixP
->fx_addnumber
= val
;
4020 md_number_to_chars (buf
, val
, 4);
4023 case BFD_RELOC_SH_GOTPC
:
4024 /* This is tough to explain. We end up with this one if we have
4025 operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
4026 The goal here is to obtain the absolute address of the GOT,
4027 and it is strongly preferable from a performance point of
4028 view to avoid using a runtime relocation for this. There are
4029 cases where you have something like:
4031 .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
4033 and here no correction would be required. Internally in the
4034 assembler we treat operands of this form as not being pcrel
4035 since the '.' is explicitly mentioned, and I wonder whether
4036 it would simplify matters to do it this way. Who knows. In
4037 earlier versions of the PIC patches, the pcrel_adjust field
4038 was used to store the correction, but since the expression is
4039 not pcrel, I felt it would be confusing to do it this way. */
4041 md_number_to_chars (buf
, val
, 4);
4044 case BFD_RELOC_SH_TLS_GD_32
:
4045 case BFD_RELOC_SH_TLS_LD_32
:
4046 case BFD_RELOC_SH_TLS_IE_32
:
4047 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
4049 case BFD_RELOC_32_GOT_PCREL
:
4050 case BFD_RELOC_SH_GOTPLT32
:
4051 * valP
= 0; /* Fully resolved at runtime. No addend. */
4052 md_number_to_chars (buf
, 0, 4);
4055 case BFD_RELOC_SH_TLS_LDO_32
:
4056 case BFD_RELOC_SH_TLS_LE_32
:
4057 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
4059 case BFD_RELOC_32_GOTOFF
:
4060 md_number_to_chars (buf
, val
, 4);
4066 shmedia_md_apply_fix (fixP
, valP
);
4075 if ((val
& ((1 << shift
) - 1)) != 0)
4076 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("misaligned offset"));
4080 val
= ((val
>> shift
)
4081 | ((long) -1 & ~ ((long) -1 >> shift
)));
4083 if (max
!= 0 && (val
< min
|| val
> max
))
4084 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("offset out of range"));
4086 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
4090 /* Called just before address relaxation. Return the length
4091 by which a fragment must grow to reach it's destination. */
4094 md_estimate_size_before_relax (fragS
*fragP
, segT segment_type
)
4098 switch (fragP
->fr_subtype
)
4102 return shmedia_md_estimate_size_before_relax (fragP
, segment_type
);
4108 case C (UNCOND_JUMP
, UNDEF_DISP
):
4109 /* Used to be a branch to somewhere which was unknown. */
4110 if (!fragP
->fr_symbol
)
4112 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
4114 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
4116 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
4120 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNDEF_WORD_DISP
);
4124 case C (COND_JUMP
, UNDEF_DISP
):
4125 case C (COND_JUMP_DELAY
, UNDEF_DISP
):
4126 what
= GET_WHAT (fragP
->fr_subtype
);
4127 /* Used to be a branch to somewhere which was unknown. */
4128 if (fragP
->fr_symbol
4129 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
4131 /* Got a symbol and it's defined in this segment, become byte
4132 sized - maybe it will fix up. */
4133 fragP
->fr_subtype
= C (what
, COND8
);
4135 else if (fragP
->fr_symbol
)
4137 /* Its got a segment, but its not ours, so it will always be long. */
4138 fragP
->fr_subtype
= C (what
, UNDEF_WORD_DISP
);
4142 /* We know the abs value. */
4143 fragP
->fr_subtype
= C (what
, COND8
);
4147 case C (UNCOND_JUMP
, UNCOND12
):
4148 case C (UNCOND_JUMP
, UNCOND32
):
4149 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
4150 case C (COND_JUMP
, COND8
):
4151 case C (COND_JUMP
, COND12
):
4152 case C (COND_JUMP
, COND32
):
4153 case C (COND_JUMP
, UNDEF_WORD_DISP
):
4154 case C (COND_JUMP_DELAY
, COND8
):
4155 case C (COND_JUMP_DELAY
, COND12
):
4156 case C (COND_JUMP_DELAY
, COND32
):
4157 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
4158 /* When relaxing a section for the second time, we don't need to
4159 do anything besides return the current size. */
4163 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
4164 return fragP
->fr_var
;
4167 /* Put number into target byte order. */
4170 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
4173 /* We might need to set the contents type to data. */
4174 sh64_flag_output ();
4177 if (! target_big_endian
)
4178 number_to_chars_littleendian (ptr
, use
, nbytes
);
4180 number_to_chars_bigendian (ptr
, use
, nbytes
);
4183 /* This version is used in obj-coff.c eg. for the sh-hms target. */
4186 md_pcrel_from (fixS
*fixP
)
4188 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
+ 2;
4192 md_pcrel_from_section (fixS
*fixP
, segT sec
)
4194 if (! sh_local_pcrel (fixP
)
4195 && fixP
->fx_addsy
!= (symbolS
*) NULL
4196 && (generic_force_reloc (fixP
)
4197 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
4199 /* The symbol is undefined (or is defined but not in this section,
4200 or we're not sure about it being the final definition). Let the
4201 linker figure it out. We need to adjust the subtraction of a
4202 symbol to the position of the relocated data, though. */
4203 return fixP
->fx_subsy
? fixP
->fx_where
+ fixP
->fx_frag
->fr_address
: 0;
4206 return md_pcrel_from (fixP
);
4209 /* Create a reloc. */
4212 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
4215 bfd_reloc_code_real_type r_type
;
4217 rel
= (arelent
*) xmalloc (sizeof (arelent
));
4218 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
4219 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
4220 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4222 r_type
= fixp
->fx_r_type
;
4224 if (SWITCH_TABLE (fixp
))
4226 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
4228 if (r_type
== BFD_RELOC_16
)
4229 r_type
= BFD_RELOC_SH_SWITCH16
;
4230 else if (r_type
== BFD_RELOC_8
)
4231 r_type
= BFD_RELOC_8_PCREL
;
4232 else if (r_type
== BFD_RELOC_32
)
4233 r_type
= BFD_RELOC_SH_SWITCH32
;
4237 else if (r_type
== BFD_RELOC_SH_USES
)
4238 rel
->addend
= fixp
->fx_addnumber
;
4239 else if (r_type
== BFD_RELOC_SH_COUNT
)
4240 rel
->addend
= fixp
->fx_offset
;
4241 else if (r_type
== BFD_RELOC_SH_ALIGN
)
4242 rel
->addend
= fixp
->fx_offset
;
4243 else if (r_type
== BFD_RELOC_VTABLE_INHERIT
4244 || r_type
== BFD_RELOC_VTABLE_ENTRY
)
4245 rel
->addend
= fixp
->fx_offset
;
4246 else if (r_type
== BFD_RELOC_SH_LOOP_START
4247 || r_type
== BFD_RELOC_SH_LOOP_END
)
4248 rel
->addend
= fixp
->fx_offset
;
4249 else if (r_type
== BFD_RELOC_SH_LABEL
&& fixp
->fx_pcrel
)
4252 rel
->address
= rel
->addend
= fixp
->fx_offset
;
4255 else if (shmedia_init_reloc (rel
, fixp
))
4258 else if (fixp
->fx_pcrel
)
4259 rel
->addend
= fixp
->fx_addnumber
;
4260 else if (r_type
== BFD_RELOC_32
|| r_type
== BFD_RELOC_32_GOTOFF
)
4261 rel
->addend
= fixp
->fx_addnumber
;
4265 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
4267 if (rel
->howto
== NULL
)
4269 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4270 _("Cannot represent relocation type %s"),
4271 bfd_get_reloc_code_name (r_type
));
4272 /* Set howto to a garbage value so that we can keep going. */
4273 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
4274 assert (rel
->howto
!= NULL
);
4277 else if (rel
->howto
->type
== R_SH_IND12W
)
4278 rel
->addend
+= fixp
->fx_offset
- 4;
4285 inline static char *
4286 sh_end_of_match (char *cont
, char *what
)
4288 int len
= strlen (what
);
4290 if (strncasecmp (cont
, what
, strlen (what
)) == 0
4291 && ! is_part_of_name (cont
[len
]))
4298 sh_parse_name (char const *name
,
4300 enum expr_mode mode
,
4303 char *next
= input_line_pointer
;
4308 exprP
->X_op_symbol
= NULL
;
4310 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
4313 GOT_symbol
= symbol_find_or_make (name
);
4315 exprP
->X_add_symbol
= GOT_symbol
;
4317 /* If we have an absolute symbol or a reg, then we know its
4319 segment
= S_GET_SEGMENT (exprP
->X_add_symbol
);
4320 if (mode
!= expr_defer
&& segment
== absolute_section
)
4322 exprP
->X_op
= O_constant
;
4323 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
4324 exprP
->X_add_symbol
= NULL
;
4326 else if (mode
!= expr_defer
&& segment
== reg_section
)
4328 exprP
->X_op
= O_register
;
4329 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
4330 exprP
->X_add_symbol
= NULL
;
4334 exprP
->X_op
= O_symbol
;
4335 exprP
->X_add_number
= 0;
4341 exprP
->X_add_symbol
= symbol_find_or_make (name
);
4343 if (*nextcharP
!= '@')
4345 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTOFF")))
4346 reloc_type
= BFD_RELOC_32_GOTOFF
;
4347 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTPLT")))
4348 reloc_type
= BFD_RELOC_SH_GOTPLT32
;
4349 else if ((next_end
= sh_end_of_match (next
+ 1, "GOT")))
4350 reloc_type
= BFD_RELOC_32_GOT_PCREL
;
4351 else if ((next_end
= sh_end_of_match (next
+ 1, "PLT")))
4352 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
4353 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSGD")))
4354 reloc_type
= BFD_RELOC_SH_TLS_GD_32
;
4355 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSLDM")))
4356 reloc_type
= BFD_RELOC_SH_TLS_LD_32
;
4357 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTTPOFF")))
4358 reloc_type
= BFD_RELOC_SH_TLS_IE_32
;
4359 else if ((next_end
= sh_end_of_match (next
+ 1, "TPOFF")))
4360 reloc_type
= BFD_RELOC_SH_TLS_LE_32
;
4361 else if ((next_end
= sh_end_of_match (next
+ 1, "DTPOFF")))
4362 reloc_type
= BFD_RELOC_SH_TLS_LDO_32
;
4366 *input_line_pointer
= *nextcharP
;
4367 input_line_pointer
= next_end
;
4368 *nextcharP
= *input_line_pointer
;
4369 *input_line_pointer
= '\0';
4371 exprP
->X_op
= O_PIC_reloc
;
4372 exprP
->X_add_number
= 0;
4373 exprP
->X_md
= reloc_type
;
4379 sh_cfi_frame_initial_instructions (void)
4381 cfi_add_CFA_def_cfa (15, 0);
4385 sh_regname_to_dw2regnum (const char *regname
)
4387 unsigned int regnum
= -1;
4391 static struct { char *name
; int dw2regnum
; } regnames
[] =
4393 { "pr", 17 }, { "t", 18 }, { "gbr", 19 }, { "mach", 20 },
4394 { "macl", 21 }, { "fpul", 23 }
4397 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
4398 if (strcmp (regnames
[i
].name
, regname
) == 0)
4399 return regnames
[i
].dw2regnum
;
4401 if (regname
[0] == 'r')
4404 regnum
= strtoul (p
, &q
, 10);
4405 if (p
== q
|| *q
|| regnum
>= 16)
4408 else if (regname
[0] == 'f' && regname
[1] == 'r')
4411 regnum
= strtoul (p
, &q
, 10);
4412 if (p
== q
|| *q
|| regnum
>= 16)
4416 else if (regname
[0] == 'x' && regname
[1] == 'd')
4419 regnum
= strtoul (p
, &q
, 10);
4420 if (p
== q
|| *q
|| regnum
>= 8)
4426 #endif /* OBJ_ELF */