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 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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, 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 md_reloc_size; */
129 int sh_relax
; /* set if -relax seen */
131 /* Whether -small was seen. */
135 /* Flag to generate relocations against symbol values for local symbols. */
137 static int dont_adjust_reloc_32
;
139 /* preset architecture set, if given; zero otherwise. */
141 static unsigned int preset_target_arch
;
143 /* The bit mask of architectures that could
144 accommodate the insns seen so far. */
145 static unsigned int valid_arch
;
147 const char EXP_CHARS
[] = "eE";
149 /* Chars that mean this number is a floating point constant. */
152 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
154 #define C(a,b) ENCODE_RELAX(a,b)
156 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
157 #define GET_WHAT(x) ((x>>4))
159 /* These are the three types of relaxable instruction. */
160 /* These are the types of relaxable instructions; except for END which is
163 #define COND_JUMP_DELAY 2
164 #define UNCOND_JUMP 3
168 /* A 16-bit (times four) pc-relative operand, at most expanded to 32 bits. */
169 #define SH64PCREL16_32 4
170 /* A 16-bit (times four) pc-relative operand, at most expanded to 64 bits. */
171 #define SH64PCREL16_64 5
173 /* Variants of the above for adjusting the insn to PTA or PTB according to
175 #define SH64PCREL16PT_32 6
176 #define SH64PCREL16PT_64 7
178 /* A MOVI expansion, expanding to at most 32 or 64 bits. */
179 #define MOVI_IMM_32 8
180 #define MOVI_IMM_32_PCREL 9
181 #define MOVI_IMM_64 10
182 #define MOVI_IMM_64_PCREL 11
185 #else /* HAVE_SH64 */
189 #endif /* HAVE_SH64 */
195 #define UNDEF_WORD_DISP 4
201 #define UNDEF_SH64PCREL 0
202 #define SH64PCREL16 1
203 #define SH64PCREL32 2
204 #define SH64PCREL48 3
205 #define SH64PCREL64 4
206 #define SH64PCRELPLT 5
214 #define MOVI_GOTOFF 6
216 #endif /* HAVE_SH64 */
218 /* Branch displacements are from the address of the branch plus
219 four, thus all minimum and maximum values have 4 added to them. */
222 #define COND8_LENGTH 2
224 /* There is one extra instruction before the branch, so we must add
225 two more bytes to account for it. */
226 #define COND12_F 4100
227 #define COND12_M -4090
228 #define COND12_LENGTH 6
230 #define COND12_DELAY_LENGTH 4
232 /* ??? The minimum and maximum values are wrong, but this does not matter
233 since this relocation type is not supported yet. */
234 #define COND32_F (1<<30)
235 #define COND32_M -(1<<30)
236 #define COND32_LENGTH 14
238 #define UNCOND12_F 4098
239 #define UNCOND12_M -4092
240 #define UNCOND12_LENGTH 2
242 /* ??? The minimum and maximum values are wrong, but this does not matter
243 since this relocation type is not supported yet. */
244 #define UNCOND32_F (1<<30)
245 #define UNCOND32_M -(1<<30)
246 #define UNCOND32_LENGTH 14
249 /* The trivial expansion of a SH64PCREL16 relaxation is just a "PT label,
250 TRd" as is the current insn, so no extra length. Note that the "reach"
251 is calculated from the address *after* that insn, but the offset in the
252 insn is calculated from the beginning of the insn. We also need to
253 take into account the implicit 1 coded as the "A" in PTA when counting
254 forward. If PTB reaches an odd address, we trap that as an error
255 elsewhere, so we don't have to have different relaxation entries. We
256 don't add a one to the negative range, since PTB would then have the
257 farthest backward-reaching value skipped, not generated at relaxation. */
258 #define SH64PCREL16_F (32767 * 4 - 4 + 1)
259 #define SH64PCREL16_M (-32768 * 4 - 4)
260 #define SH64PCREL16_LENGTH 0
262 /* The next step is to change that PT insn into
263 MOVI ((label - datalabel Ln) >> 16) & 65535, R25
264 SHORI (label - datalabel Ln) & 65535, R25
267 which means two extra insns, 8 extra bytes. This is the limit for the
270 The expressions look a bit bad since we have to adjust this to avoid overflow on a
272 #define SH64PCREL32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
273 #define SH64PCREL32_LENGTH (2 * 4)
275 /* Similarly, we just change the MOVI and add a SHORI for the 48-bit
277 #if BFD_HOST_64BIT_LONG
278 /* The "reach" type is long, so we can only do this for a 64-bit-long
280 #define SH64PCREL32_M (((long) -1 << 30) * 2 - 4)
281 #define SH64PCREL48_F ((((long) 1 << 47) - 1) - 4)
282 #define SH64PCREL48_M (((long) -1 << 47) - 4)
283 #define SH64PCREL48_LENGTH (3 * 4)
285 /* If the host does not have 64-bit longs, just make this state identical
286 in reach to the 32-bit state. Note that we have a slightly incorrect
287 reach, but the correct one above will overflow a 32-bit number. */
288 #define SH64PCREL32_M (((long) -1 << 30) * 2)
289 #define SH64PCREL48_F SH64PCREL32_F
290 #define SH64PCREL48_M SH64PCREL32_M
291 #define SH64PCREL48_LENGTH (3 * 4)
292 #endif /* BFD_HOST_64BIT_LONG */
294 /* And similarly for the 64-bit expansion; a MOVI + SHORI + SHORI + SHORI
296 #define SH64PCREL64_LENGTH (4 * 4)
298 /* For MOVI, we make the MOVI + SHORI... expansion you can see in the
299 SH64PCREL expansions. The PCREL one is similar, but the other has no
300 pc-relative reach; it must be fully expanded in
301 shmedia_md_estimate_size_before_relax. */
302 #define MOVI_16_LENGTH 0
303 #define MOVI_16_F (32767 - 4)
304 #define MOVI_16_M (-32768 - 4)
305 #define MOVI_32_LENGTH 4
306 #define MOVI_32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
307 #define MOVI_48_LENGTH 8
309 #if BFD_HOST_64BIT_LONG
310 /* The "reach" type is long, so we can only do this for a 64-bit-long
312 #define MOVI_32_M (((long) -1 << 30) * 2 - 4)
313 #define MOVI_48_F ((((long) 1 << 47) - 1) - 4)
314 #define MOVI_48_M (((long) -1 << 47) - 4)
316 /* If the host does not have 64-bit longs, just make this state identical
317 in reach to the 32-bit state. Note that we have a slightly incorrect
318 reach, but the correct one above will overflow a 32-bit number. */
319 #define MOVI_32_M (((long) -1 << 30) * 2)
320 #define MOVI_48_F MOVI_32_F
321 #define MOVI_48_M MOVI_32_M
322 #endif /* BFD_HOST_64BIT_LONG */
324 #define MOVI_64_LENGTH 12
325 #endif /* HAVE_SH64 */
327 #define EMPTY { 0, 0, 0, 0 }
329 const relax_typeS md_relax_table
[C (END
, 0)] = {
330 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
331 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
334 /* C (COND_JUMP, COND8) */
335 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP
, COND12
) },
336 /* C (COND_JUMP, COND12) */
337 { COND12_F
, COND12_M
, COND12_LENGTH
, C (COND_JUMP
, COND32
), },
338 /* C (COND_JUMP, COND32) */
339 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
340 /* C (COND_JUMP, UNDEF_WORD_DISP) */
341 { 0, 0, COND32_LENGTH
, 0, },
343 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
346 /* C (COND_JUMP_DELAY, COND8) */
347 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP_DELAY
, COND12
) },
348 /* C (COND_JUMP_DELAY, COND12) */
349 { COND12_F
, COND12_M
, COND12_DELAY_LENGTH
, C (COND_JUMP_DELAY
, COND32
), },
350 /* C (COND_JUMP_DELAY, COND32) */
351 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
352 /* C (COND_JUMP_DELAY, UNDEF_WORD_DISP) */
353 { 0, 0, COND32_LENGTH
, 0, },
355 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
358 /* C (UNCOND_JUMP, UNCOND12) */
359 { UNCOND12_F
, UNCOND12_M
, UNCOND12_LENGTH
, C (UNCOND_JUMP
, UNCOND32
), },
360 /* C (UNCOND_JUMP, UNCOND32) */
361 { UNCOND32_F
, UNCOND32_M
, UNCOND32_LENGTH
, 0, },
363 /* C (UNCOND_JUMP, UNDEF_WORD_DISP) */
364 { 0, 0, UNCOND32_LENGTH
, 0, },
366 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
369 /* C (SH64PCREL16_32, SH64PCREL16) */
371 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16_32
, SH64PCREL32
) },
372 /* C (SH64PCREL16_32, SH64PCREL32) */
373 { 0, 0, SH64PCREL32_LENGTH
, 0 },
375 /* C (SH64PCREL16_32, SH64PCRELPLT) */
376 { 0, 0, SH64PCREL32_LENGTH
, 0 },
378 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
380 /* C (SH64PCREL16_64, SH64PCREL16) */
382 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16_64
, SH64PCREL32
) },
383 /* C (SH64PCREL16_64, SH64PCREL32) */
384 { SH64PCREL32_F
, SH64PCREL32_M
, SH64PCREL32_LENGTH
, C (SH64PCREL16_64
, SH64PCREL48
) },
385 /* C (SH64PCREL16_64, SH64PCREL48) */
386 { SH64PCREL48_F
, SH64PCREL48_M
, SH64PCREL48_LENGTH
, C (SH64PCREL16_64
, SH64PCREL64
) },
387 /* C (SH64PCREL16_64, SH64PCREL64) */
388 { 0, 0, SH64PCREL64_LENGTH
, 0 },
389 /* C (SH64PCREL16_64, SH64PCRELPLT) */
390 { 0, 0, SH64PCREL64_LENGTH
, 0 },
392 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
394 /* C (SH64PCREL16PT_32, SH64PCREL16) */
396 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16PT_32
, SH64PCREL32
) },
397 /* C (SH64PCREL16PT_32, SH64PCREL32) */
398 { 0, 0, SH64PCREL32_LENGTH
, 0 },
400 /* C (SH64PCREL16PT_32, SH64PCRELPLT) */
401 { 0, 0, SH64PCREL32_LENGTH
, 0 },
403 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
405 /* C (SH64PCREL16PT_64, SH64PCREL16) */
407 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16PT_64
, SH64PCREL32
) },
408 /* C (SH64PCREL16PT_64, SH64PCREL32) */
412 C (SH64PCREL16PT_64
, SH64PCREL48
) },
413 /* C (SH64PCREL16PT_64, SH64PCREL48) */
414 { SH64PCREL48_F
, SH64PCREL48_M
, SH64PCREL48_LENGTH
, C (SH64PCREL16PT_64
, SH64PCREL64
) },
415 /* C (SH64PCREL16PT_64, SH64PCREL64) */
416 { 0, 0, SH64PCREL64_LENGTH
, 0 },
417 /* C (SH64PCREL16PT_64, SH64PCRELPLT) */
418 { 0, 0, SH64PCREL64_LENGTH
, 0},
420 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
422 /* C (MOVI_IMM_32, UNDEF_MOVI) */
423 { 0, 0, MOVI_32_LENGTH
, 0 },
424 /* C (MOVI_IMM_32, MOVI_16) */
425 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_32
, MOVI_32
) },
426 /* C (MOVI_IMM_32, MOVI_32) */
427 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, 0 },
429 /* C (MOVI_IMM_32, MOVI_GOTOFF) */
430 { 0, 0, MOVI_32_LENGTH
, 0 },
431 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
433 /* C (MOVI_IMM_32_PCREL, MOVI_16) */
435 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_32_PCREL
, MOVI_32
) },
436 /* C (MOVI_IMM_32_PCREL, MOVI_32) */
437 { 0, 0, MOVI_32_LENGTH
, 0 },
439 /* C (MOVI_IMM_32_PCREL, MOVI_PLT) */
440 { 0, 0, MOVI_32_LENGTH
, 0 },
442 /* C (MOVI_IMM_32_PCREL, MOVI_GOTPC) */
443 { 0, 0, MOVI_32_LENGTH
, 0 },
444 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
446 /* C (MOVI_IMM_64, UNDEF_MOVI) */
447 { 0, 0, MOVI_64_LENGTH
, 0 },
448 /* C (MOVI_IMM_64, MOVI_16) */
449 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_64
, MOVI_32
) },
450 /* C (MOVI_IMM_64, MOVI_32) */
451 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, C (MOVI_IMM_64
, MOVI_48
) },
452 /* C (MOVI_IMM_64, MOVI_48) */
453 { MOVI_48_F
, MOVI_48_M
, MOVI_48_LENGTH
, C (MOVI_IMM_64
, MOVI_64
) },
454 /* C (MOVI_IMM_64, MOVI_64) */
455 { 0, 0, MOVI_64_LENGTH
, 0 },
457 /* C (MOVI_IMM_64, MOVI_GOTOFF) */
458 { 0, 0, MOVI_64_LENGTH
, 0 },
459 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
461 /* C (MOVI_IMM_64_PCREL, MOVI_16) */
463 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_32
) },
464 /* C (MOVI_IMM_64_PCREL, MOVI_32) */
465 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_48
) },
466 /* C (MOVI_IMM_64_PCREL, MOVI_48) */
467 { MOVI_48_F
, MOVI_48_M
, MOVI_48_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_64
) },
468 /* C (MOVI_IMM_64_PCREL, MOVI_64) */
469 { 0, 0, MOVI_64_LENGTH
, 0 },
470 /* C (MOVI_IMM_64_PCREL, MOVI_PLT) */
471 { 0, 0, MOVI_64_LENGTH
, 0 },
473 /* C (MOVI_IMM_64_PCREL, MOVI_GOTPC) */
474 { 0, 0, MOVI_64_LENGTH
, 0 },
475 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
477 #endif /* HAVE_SH64 */
483 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics */
487 /* Determinet whether the symbol needs any kind of PIC relocation. */
490 sh_PIC_related_p (symbolS
*sym
)
497 if (sym
== GOT_symbol
)
501 if (sh_PIC_related_p (*symbol_get_tc (sym
)))
505 exp
= symbol_get_value_expression (sym
);
507 return (exp
->X_op
== O_PIC_reloc
508 || sh_PIC_related_p (exp
->X_add_symbol
)
509 || sh_PIC_related_p (exp
->X_op_symbol
));
512 /* Determine the relocation type to be used to represent the
513 expression, that may be rearranged. */
516 sh_check_fixup (expressionS
*main_exp
, bfd_reloc_code_real_type
*r_type_p
)
518 expressionS
*exp
= main_exp
;
520 /* This is here for backward-compatibility only. GCC used to generated:
522 f@PLT + . - (.LPCS# + 2)
524 but we'd rather be able to handle this as a PIC-related reference
525 plus/minus a symbol. However, gas' parser gives us:
527 O_subtract (O_add (f@PLT, .), .LPCS#+2)
529 so we attempt to transform this into:
531 O_subtract (f@PLT, O_subtract (.LPCS#+2, .))
533 which we can handle simply below. */
534 if (exp
->X_op
== O_subtract
)
536 if (sh_PIC_related_p (exp
->X_op_symbol
))
539 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
541 if (exp
&& sh_PIC_related_p (exp
->X_op_symbol
))
544 if (exp
&& exp
->X_op
== O_add
545 && sh_PIC_related_p (exp
->X_add_symbol
))
547 symbolS
*sym
= exp
->X_add_symbol
;
549 exp
->X_op
= O_subtract
;
550 exp
->X_add_symbol
= main_exp
->X_op_symbol
;
552 main_exp
->X_op_symbol
= main_exp
->X_add_symbol
;
553 main_exp
->X_add_symbol
= sym
;
555 main_exp
->X_add_number
+= exp
->X_add_number
;
556 exp
->X_add_number
= 0;
561 else if (exp
->X_op
== O_add
&& sh_PIC_related_p (exp
->X_op_symbol
))
564 if (exp
->X_op
== O_symbol
|| exp
->X_op
== O_add
|| exp
->X_op
== O_subtract
)
567 if (exp
->X_add_symbol
568 && (exp
->X_add_symbol
== GOT_symbol
570 && *symbol_get_tc (exp
->X_add_symbol
) == GOT_symbol
)))
574 case BFD_RELOC_SH_IMM_LOW16
:
575 *r_type_p
= BFD_RELOC_SH_GOTPC_LOW16
;
578 case BFD_RELOC_SH_IMM_MEDLOW16
:
579 *r_type_p
= BFD_RELOC_SH_GOTPC_MEDLOW16
;
582 case BFD_RELOC_SH_IMM_MEDHI16
:
583 *r_type_p
= BFD_RELOC_SH_GOTPC_MEDHI16
;
586 case BFD_RELOC_SH_IMM_HI16
:
587 *r_type_p
= BFD_RELOC_SH_GOTPC_HI16
;
591 case BFD_RELOC_UNUSED
:
592 *r_type_p
= BFD_RELOC_SH_GOTPC
;
601 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
603 *r_type_p
= BFD_RELOC_SH_GOTPC
;
607 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
612 if (exp
->X_op
== O_PIC_reloc
)
618 case BFD_RELOC_UNUSED
:
619 *r_type_p
= exp
->X_md
;
622 case BFD_RELOC_SH_IMM_LOW16
:
625 case BFD_RELOC_32_GOTOFF
:
626 *r_type_p
= BFD_RELOC_SH_GOTOFF_LOW16
;
629 case BFD_RELOC_SH_GOTPLT32
:
630 *r_type_p
= BFD_RELOC_SH_GOTPLT_LOW16
;
633 case BFD_RELOC_32_GOT_PCREL
:
634 *r_type_p
= BFD_RELOC_SH_GOT_LOW16
;
637 case BFD_RELOC_32_PLT_PCREL
:
638 *r_type_p
= BFD_RELOC_SH_PLT_LOW16
;
646 case BFD_RELOC_SH_IMM_MEDLOW16
:
649 case BFD_RELOC_32_GOTOFF
:
650 *r_type_p
= BFD_RELOC_SH_GOTOFF_MEDLOW16
;
653 case BFD_RELOC_SH_GOTPLT32
:
654 *r_type_p
= BFD_RELOC_SH_GOTPLT_MEDLOW16
;
657 case BFD_RELOC_32_GOT_PCREL
:
658 *r_type_p
= BFD_RELOC_SH_GOT_MEDLOW16
;
661 case BFD_RELOC_32_PLT_PCREL
:
662 *r_type_p
= BFD_RELOC_SH_PLT_MEDLOW16
;
670 case BFD_RELOC_SH_IMM_MEDHI16
:
673 case BFD_RELOC_32_GOTOFF
:
674 *r_type_p
= BFD_RELOC_SH_GOTOFF_MEDHI16
;
677 case BFD_RELOC_SH_GOTPLT32
:
678 *r_type_p
= BFD_RELOC_SH_GOTPLT_MEDHI16
;
681 case BFD_RELOC_32_GOT_PCREL
:
682 *r_type_p
= BFD_RELOC_SH_GOT_MEDHI16
;
685 case BFD_RELOC_32_PLT_PCREL
:
686 *r_type_p
= BFD_RELOC_SH_PLT_MEDHI16
;
694 case BFD_RELOC_SH_IMM_HI16
:
697 case BFD_RELOC_32_GOTOFF
:
698 *r_type_p
= BFD_RELOC_SH_GOTOFF_HI16
;
701 case BFD_RELOC_SH_GOTPLT32
:
702 *r_type_p
= BFD_RELOC_SH_GOTPLT_HI16
;
705 case BFD_RELOC_32_GOT_PCREL
:
706 *r_type_p
= BFD_RELOC_SH_GOT_HI16
;
709 case BFD_RELOC_32_PLT_PCREL
:
710 *r_type_p
= BFD_RELOC_SH_PLT_HI16
;
722 *r_type_p
= exp
->X_md
;
725 exp
->X_op
= O_symbol
;
728 main_exp
->X_add_symbol
= exp
->X_add_symbol
;
729 main_exp
->X_add_number
+= exp
->X_add_number
;
733 return (sh_PIC_related_p (exp
->X_add_symbol
)
734 || sh_PIC_related_p (exp
->X_op_symbol
));
739 /* Add expression EXP of SIZE bytes to offset OFF of fragment FRAG. */
742 sh_cons_fix_new (fragS
*frag
, int off
, int size
, expressionS
*exp
)
744 bfd_reloc_code_real_type r_type
= BFD_RELOC_UNUSED
;
746 if (sh_check_fixup (exp
, &r_type
))
747 as_bad (_("Invalid PIC expression."));
749 if (r_type
== BFD_RELOC_UNUSED
)
753 r_type
= BFD_RELOC_8
;
757 r_type
= BFD_RELOC_16
;
761 r_type
= BFD_RELOC_32
;
766 r_type
= BFD_RELOC_64
;
776 as_bad (_("unsupported BFD relocation size %u"), size
);
777 r_type
= BFD_RELOC_UNUSED
;
780 fix_new_exp (frag
, off
, size
, exp
, 0, r_type
);
783 /* The regular cons() function, that reads constants, doesn't support
784 suffixes such as @GOT, @GOTOFF and @PLT, that generate
785 machine-specific relocation types. So we must define it here. */
786 /* Clobbers input_line_pointer, checks end-of-line. */
787 /* NBYTES 1=.byte, 2=.word, 4=.long */
789 sh_elf_cons (register int nbytes
)
795 /* Update existing range to include a previous insn, if there was one. */
796 sh64_update_contents_mark (TRUE
);
798 /* We need to make sure the contents type is set to data. */
801 #endif /* HAVE_SH64 */
803 if (is_it_end_of_statement ())
805 demand_empty_rest_of_line ();
810 md_cons_align (nbytes
);
816 emit_expr (&exp
, (unsigned int) nbytes
);
818 while (*input_line_pointer
++ == ',');
820 input_line_pointer
--; /* Put terminator back into stream. */
821 if (*input_line_pointer
== '#' || *input_line_pointer
== '!')
823 while (! is_end_of_line
[(unsigned char) *input_line_pointer
++]);
826 demand_empty_rest_of_line ();
831 /* This function is called once, at assembler startup time. This should
832 set up all the tables, etc that the MD part of the assembler needs. */
837 const sh_opcode_info
*opcode
;
838 char *prev_name
= "";
839 unsigned int target_arch
;
842 = preset_target_arch
? preset_target_arch
: arch_sh1_up
& ~arch_sh_has_dsp
;
843 valid_arch
= target_arch
;
849 opcode_hash_control
= hash_new ();
851 /* Insert unique names into hash table. */
852 for (opcode
= sh_table
; opcode
->name
; opcode
++)
854 if (strcmp (prev_name
, opcode
->name
) != 0)
856 if (!SH_MERGE_ARCH_SET_VALID (opcode
->arch
, target_arch
))
858 prev_name
= opcode
->name
;
859 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
866 static int reg_x
, reg_y
;
870 #define IDENT_CHAR(c) (ISALNUM (c) || (c) == '_')
872 /* Try to parse a reg name. Return the number of chars consumed. */
875 parse_reg (char *src
, int *mode
, int *reg
)
877 char l0
= TOLOWER (src
[0]);
878 char l1
= l0
? TOLOWER (src
[1]) : 0;
880 /* We use ! IDENT_CHAR for the next character after the register name, to
881 make sure that we won't accidentally recognize a symbol name such as
882 'sram' or sr_ram as being a reference to the register 'sr'. */
888 if (src
[2] >= '0' && src
[2] <= '5'
889 && ! IDENT_CHAR ((unsigned char) src
[3]))
892 *reg
= 10 + src
[2] - '0';
896 if (l1
>= '0' && l1
<= '9'
897 && ! IDENT_CHAR ((unsigned char) src
[2]))
903 if (l1
>= '0' && l1
<= '7' && strncasecmp (&src
[2], "_bank", 5) == 0
904 && ! IDENT_CHAR ((unsigned char) src
[7]))
911 if (l1
== 'e' && ! IDENT_CHAR ((unsigned char) src
[2]))
916 if (l1
== 's' && ! IDENT_CHAR ((unsigned char) src
[2]))
927 if (! IDENT_CHAR ((unsigned char) src
[2]))
933 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
942 if (! IDENT_CHAR ((unsigned char) src
[2]))
948 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
956 if (l1
== 'x' && src
[2] >= '0' && src
[2] <= '1'
957 && ! IDENT_CHAR ((unsigned char) src
[3]))
960 *reg
= 4 + (l1
- '0');
963 if (l1
== 'y' && src
[2] >= '0' && src
[2] <= '1'
964 && ! IDENT_CHAR ((unsigned char) src
[3]))
967 *reg
= 6 + (l1
- '0');
970 if (l1
== 's' && src
[2] >= '0' && src
[2] <= '3'
971 && ! IDENT_CHAR ((unsigned char) src
[3]))
976 *reg
= n
| ((~n
& 2) << 1);
981 if (l0
== 'i' && l1
&& ! IDENT_CHAR ((unsigned char) src
[2]))
1003 if (l0
== 'x' && l1
>= '0' && l1
<= '1'
1004 && ! IDENT_CHAR ((unsigned char) src
[2]))
1007 *reg
= A_X0_NUM
+ l1
- '0';
1011 if (l0
== 'y' && l1
>= '0' && l1
<= '1'
1012 && ! IDENT_CHAR ((unsigned char) src
[2]))
1015 *reg
= A_Y0_NUM
+ l1
- '0';
1019 if (l0
== 'm' && l1
>= '0' && l1
<= '1'
1020 && ! IDENT_CHAR ((unsigned char) src
[2]))
1023 *reg
= l1
== '0' ? A_M0_NUM
: A_M1_NUM
;
1029 && TOLOWER (src
[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[3]))
1035 if (l0
== 's' && l1
== 'p' && TOLOWER (src
[2]) == 'c'
1036 && ! IDENT_CHAR ((unsigned char) src
[3]))
1042 if (l0
== 's' && l1
== 'g' && TOLOWER (src
[2]) == 'r'
1043 && ! IDENT_CHAR ((unsigned char) src
[3]))
1049 if (l0
== 'd' && l1
== 's' && TOLOWER (src
[2]) == 'r'
1050 && ! IDENT_CHAR ((unsigned char) src
[3]))
1056 if (l0
== 'd' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1057 && ! IDENT_CHAR ((unsigned char) src
[3]))
1063 if (l0
== 's' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
1069 if (l0
== 's' && l1
== 'p' && ! IDENT_CHAR ((unsigned char) src
[2]))
1076 if (l0
== 'p' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
1081 if (l0
== 'p' && l1
== 'c' && ! IDENT_CHAR ((unsigned char) src
[2]))
1083 /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
1084 and use an uninitialized immediate. */
1088 if (l0
== 'g' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1089 && ! IDENT_CHAR ((unsigned char) src
[3]))
1094 if (l0
== 'v' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1095 && ! IDENT_CHAR ((unsigned char) src
[3]))
1101 if (l0
== 'm' && l1
== 'a' && TOLOWER (src
[2]) == 'c'
1102 && ! IDENT_CHAR ((unsigned char) src
[4]))
1104 if (TOLOWER (src
[3]) == 'l')
1109 if (TOLOWER (src
[3]) == 'h')
1115 if (l0
== 'm' && l1
== 'o' && TOLOWER (src
[2]) == 'd'
1116 && ! IDENT_CHAR ((unsigned char) src
[3]))
1121 if (l0
== 'f' && l1
== 'r')
1125 if (src
[3] >= '0' && src
[3] <= '5'
1126 && ! IDENT_CHAR ((unsigned char) src
[4]))
1129 *reg
= 10 + src
[3] - '0';
1133 if (src
[2] >= '0' && src
[2] <= '9'
1134 && ! IDENT_CHAR ((unsigned char) src
[3]))
1137 *reg
= (src
[2] - '0');
1141 if (l0
== 'd' && l1
== 'r')
1145 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
1146 && ! IDENT_CHAR ((unsigned char) src
[4]))
1149 *reg
= 10 + src
[3] - '0';
1153 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
1154 && ! IDENT_CHAR ((unsigned char) src
[3]))
1157 *reg
= (src
[2] - '0');
1161 if (l0
== 'x' && l1
== 'd')
1165 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
1166 && ! IDENT_CHAR ((unsigned char) src
[4]))
1169 *reg
= 11 + src
[3] - '0';
1173 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
1174 && ! IDENT_CHAR ((unsigned char) src
[3]))
1177 *reg
= (src
[2] - '0') + 1;
1181 if (l0
== 'f' && l1
== 'v')
1183 if (src
[2] == '1'&& src
[3] == '2' && ! IDENT_CHAR ((unsigned char) src
[4]))
1189 if ((src
[2] == '0' || src
[2] == '4' || src
[2] == '8')
1190 && ! IDENT_CHAR ((unsigned char) src
[3]))
1193 *reg
= (src
[2] - '0');
1197 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 'u'
1198 && TOLOWER (src
[3]) == 'l'
1199 && ! IDENT_CHAR ((unsigned char) src
[4]))
1205 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 's'
1206 && TOLOWER (src
[3]) == 'c'
1207 && TOLOWER (src
[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[5]))
1213 if (l0
== 'x' && l1
== 'm' && TOLOWER (src
[2]) == 't'
1214 && TOLOWER (src
[3]) == 'r'
1215 && TOLOWER (src
[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src
[5]))
1225 parse_exp (char *s
, sh_operand_info
*op
)
1230 save
= input_line_pointer
;
1231 input_line_pointer
= s
;
1232 expression (&op
->immediate
);
1233 if (op
->immediate
.X_op
== O_absent
)
1234 as_bad (_("missing operand"));
1236 else if (op
->immediate
.X_op
== O_PIC_reloc
1237 || sh_PIC_related_p (op
->immediate
.X_add_symbol
)
1238 || sh_PIC_related_p (op
->immediate
.X_op_symbol
))
1239 as_bad (_("misplaced PIC operand"));
1241 new = input_line_pointer
;
1242 input_line_pointer
= save
;
1246 /* The many forms of operand:
1249 @Rn Register indirect
1262 pr, gbr, vbr, macl, mach
1266 parse_at (char *src
, sh_operand_info
*op
)
1273 /* Must be predecrement. */
1276 len
= parse_reg (src
, &mode
, &(op
->reg
));
1277 if (mode
!= A_REG_N
)
1278 as_bad (_("illegal register after @-"));
1283 else if (src
[0] == '(')
1285 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
1288 len
= parse_reg (src
, &mode
, &(op
->reg
));
1289 if (len
&& mode
== A_REG_N
)
1294 as_bad (_("must be @(r0,...)"));
1299 /* Now can be rn or gbr. */
1300 len
= parse_reg (src
, &mode
, &(op
->reg
));
1310 op
->type
= A_R0_GBR
;
1312 else if (mode
== A_REG_N
)
1314 op
->type
= A_IND_R0_REG_N
;
1318 as_bad (_("syntax error in @(r0,...)"));
1323 as_bad (_("syntax error in @(r0...)"));
1328 /* Must be an @(disp,.. thing). */
1329 src
= parse_exp (src
, op
);
1332 /* Now can be rn, gbr or pc. */
1333 len
= parse_reg (src
, &mode
, &op
->reg
);
1336 if (mode
== A_REG_N
)
1338 op
->type
= A_DISP_REG_N
;
1340 else if (mode
== A_GBR
)
1342 op
->type
= A_DISP_GBR
;
1344 else if (mode
== A_PC
)
1346 /* We want @(expr, pc) to uniformly address . + expr,
1347 no matter if expr is a constant, or a more complex
1348 expression, e.g. sym-. or sym1-sym2.
1349 However, we also used to accept @(sym,pc)
1350 as addressing sym, i.e. meaning the same as plain sym.
1351 Some existing code does use the @(sym,pc) syntax, so
1352 we give it the old semantics for now, but warn about
1353 its use, so that users have some time to fix their code.
1355 Note that due to this backward compatibility hack,
1356 we'll get unexpected results when @(offset, pc) is used,
1357 and offset is a symbol that is set later to an an address
1358 difference, or an external symbol that is set to an
1359 address difference in another source file, so we want to
1360 eventually remove it. */
1361 if (op
->immediate
.X_op
== O_symbol
)
1363 op
->type
= A_DISP_PC
;
1364 as_warn (_("Deprecated syntax."));
1368 op
->type
= A_DISP_PC_ABS
;
1369 /* Such operands don't get corrected for PC==.+4, so
1370 make the correction here. */
1371 op
->immediate
.X_add_number
-= 4;
1376 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1381 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1386 as_bad (_("expecting )"));
1392 src
+= parse_reg (src
, &mode
, &(op
->reg
));
1393 if (mode
!= A_REG_N
)
1394 as_bad (_("illegal register after @"));
1401 l0
= TOLOWER (src
[0]);
1402 l1
= TOLOWER (src
[1]);
1404 if ((l0
== 'r' && l1
== '8')
1405 || (l0
== 'i' && (l1
== 'x' || l1
== 's')))
1408 op
->type
= AX_PMOD_N
;
1410 else if ( (l0
== 'r' && l1
== '9')
1411 || (l0
== 'i' && l1
== 'y'))
1414 op
->type
= AY_PMOD_N
;
1426 get_operand (char **ptr
, sh_operand_info
*op
)
1435 *ptr
= parse_exp (src
, op
);
1440 else if (src
[0] == '@')
1442 *ptr
= parse_at (src
, op
);
1445 len
= parse_reg (src
, &mode
, &(op
->reg
));
1454 /* Not a reg, the only thing left is a displacement. */
1455 *ptr
= parse_exp (src
, op
);
1456 op
->type
= A_DISP_PC
;
1462 get_operands (sh_opcode_info
*info
, char *args
, sh_operand_info
*operand
)
1467 /* The pre-processor will eliminate whitespace in front of '@'
1468 after the first argument; we may be called multiple times
1469 from assemble_ppi, so don't insist on finding whitespace here. */
1473 get_operand (&ptr
, operand
+ 0);
1480 get_operand (&ptr
, operand
+ 1);
1481 /* ??? Hack: psha/pshl have a varying operand number depending on
1482 the type of the first operand. We handle this by having the
1483 three-operand version first and reducing the number of operands
1484 parsed to two if we see that the first operand is an immediate.
1485 This works because no insn with three operands has an immediate
1486 as first operand. */
1487 if (info
->arg
[2] && operand
[0].type
!= A_IMM
)
1493 get_operand (&ptr
, operand
+ 2);
1497 operand
[2].type
= 0;
1502 operand
[1].type
= 0;
1503 operand
[2].type
= 0;
1508 operand
[0].type
= 0;
1509 operand
[1].type
= 0;
1510 operand
[2].type
= 0;
1515 /* Passed a pointer to a list of opcodes which use different
1516 addressing modes, return the opcode which matches the opcodes
1519 static sh_opcode_info
*
1520 get_specific (sh_opcode_info
*opcode
, sh_operand_info
*operands
)
1522 sh_opcode_info
*this_try
= opcode
;
1523 char *name
= opcode
->name
;
1526 while (opcode
->name
)
1528 this_try
= opcode
++;
1529 if ((this_try
->name
!= name
) && (strcmp (this_try
->name
, name
) != 0))
1531 /* We've looked so far down the table that we've run out of
1532 opcodes with the same name. */
1536 /* Look at both operands needed by the opcodes and provided by
1537 the user - since an arg test will often fail on the same arg
1538 again and again, we'll try and test the last failing arg the
1539 first on each opcode try. */
1540 for (n
= 0; this_try
->arg
[n
]; n
++)
1542 sh_operand_info
*user
= operands
+ n
;
1543 sh_arg_type arg
= this_try
->arg
[n
];
1548 if (user
->type
== A_DISP_PC_ABS
)
1558 if (user
->type
!= arg
)
1562 /* opcode needs r0 */
1563 if (user
->type
!= A_REG_N
|| user
->reg
!= 0)
1567 if (user
->type
!= A_R0_GBR
|| user
->reg
!= 0)
1571 if (user
->type
!= F_REG_N
|| user
->reg
!= 0)
1579 case A_IND_R0_REG_N
:
1588 /* Opcode needs rn */
1589 if (user
->type
!= arg
)
1594 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1609 if (user
->type
!= arg
)
1614 if (user
->type
!= arg
)
1623 case A_IND_R0_REG_M
:
1626 /* Opcode needs rn */
1627 if (user
->type
!= arg
- A_REG_M
+ A_REG_N
)
1633 if (user
->type
!= A_DEC_N
)
1635 if (user
->reg
< 2 || user
->reg
> 5)
1641 if (user
->type
!= A_INC_N
)
1643 if (user
->reg
< 2 || user
->reg
> 5)
1649 if (user
->type
!= A_IND_N
)
1651 if (user
->reg
< 2 || user
->reg
> 5)
1657 if (user
->type
!= AX_PMOD_N
)
1659 if (user
->reg
< 2 || user
->reg
> 5)
1665 if (user
->type
!= A_INC_N
)
1667 if (user
->reg
< 4 || user
->reg
> 5)
1673 if (user
->type
!= A_IND_N
)
1675 if (user
->reg
< 4 || user
->reg
> 5)
1681 if (user
->type
!= AX_PMOD_N
)
1683 if (user
->reg
< 4 || user
->reg
> 5)
1689 if (user
->type
!= A_INC_N
)
1691 if ((user
->reg
< 4 || user
->reg
> 5)
1692 && (user
->reg
< 0 || user
->reg
> 1))
1698 if (user
->type
!= A_IND_N
)
1700 if ((user
->reg
< 4 || user
->reg
> 5)
1701 && (user
->reg
< 0 || user
->reg
> 1))
1707 if (user
->type
!= AX_PMOD_N
)
1709 if ((user
->reg
< 4 || user
->reg
> 5)
1710 && (user
->reg
< 0 || user
->reg
> 1))
1716 if (user
->type
!= A_INC_N
)
1718 if (user
->reg
< 6 || user
->reg
> 7)
1724 if (user
->type
!= A_IND_N
)
1726 if (user
->reg
< 6 || user
->reg
> 7)
1732 if (user
->type
!= AY_PMOD_N
)
1734 if (user
->reg
< 6 || user
->reg
> 7)
1740 if (user
->type
!= A_INC_N
)
1742 if ((user
->reg
< 6 || user
->reg
> 7)
1743 && (user
->reg
< 2 || user
->reg
> 3))
1749 if (user
->type
!= A_IND_N
)
1751 if ((user
->reg
< 6 || user
->reg
> 7)
1752 && (user
->reg
< 2 || user
->reg
> 3))
1758 if (user
->type
!= AY_PMOD_N
)
1760 if ((user
->reg
< 6 || user
->reg
> 7)
1761 && (user
->reg
< 2 || user
->reg
> 3))
1767 if (user
->type
!= DSP_REG_N
)
1769 if (user
->reg
!= A_A0_NUM
1770 && user
->reg
!= A_A1_NUM
)
1776 if (user
->type
!= DSP_REG_N
)
1798 if (user
->type
!= DSP_REG_N
)
1820 if (user
->type
!= DSP_REG_N
)
1842 if (user
->type
!= DSP_REG_N
)
1864 if (user
->type
!= DSP_REG_N
)
1886 if (user
->type
!= DSP_REG_N
)
1908 if (user
->type
!= DSP_REG_N
)
1930 if (user
->type
!= DSP_REG_N
)
1952 if (user
->type
!= DSP_REG_N
)
1974 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_A0_NUM
)
1978 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X0_NUM
)
1982 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X1_NUM
)
1986 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y0_NUM
)
1990 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y1_NUM
)
2000 /* Opcode needs rn */
2001 if (user
->type
!= arg
- F_REG_M
+ F_REG_N
)
2006 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
2011 if (user
->type
!= XMTRX_M4
)
2017 printf (_("unhandled %d\n"), arg
);
2021 if ( !SH_MERGE_ARCH_SET_VALID (valid_arch
, this_try
->arch
))
2023 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, this_try
->arch
);
2033 insert (char *where
, int how
, int pcrel
, sh_operand_info
*op
)
2035 fix_new_exp (frag_now
,
2036 where
- frag_now
->fr_literal
,
2044 build_relax (sh_opcode_info
*opcode
, sh_operand_info
*op
)
2046 int high_byte
= target_big_endian
? 0 : 1;
2049 if (opcode
->arg
[0] == A_BDISP8
)
2051 int what
= (opcode
->nibbles
[1] & 4) ? COND_JUMP_DELAY
: COND_JUMP
;
2052 p
= frag_var (rs_machine_dependent
,
2053 md_relax_table
[C (what
, COND32
)].rlx_length
,
2054 md_relax_table
[C (what
, COND8
)].rlx_length
,
2056 op
->immediate
.X_add_symbol
,
2057 op
->immediate
.X_add_number
,
2059 p
[high_byte
] = (opcode
->nibbles
[0] << 4) | (opcode
->nibbles
[1]);
2061 else if (opcode
->arg
[0] == A_BDISP12
)
2063 p
= frag_var (rs_machine_dependent
,
2064 md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
,
2065 md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
,
2067 op
->immediate
.X_add_symbol
,
2068 op
->immediate
.X_add_number
,
2070 p
[high_byte
] = (opcode
->nibbles
[0] << 4);
2075 /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
2078 insert_loop_bounds (char *output
, sh_operand_info
*operand
)
2083 /* Since the low byte of the opcode will be overwritten by the reloc, we
2084 can just stash the high byte into both bytes and ignore endianness. */
2087 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
2088 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
2092 static int count
= 0;
2094 /* If the last loop insn is a two-byte-insn, it is in danger of being
2095 swapped with the insn after it. To prevent this, create a new
2096 symbol - complete with SH_LABEL reloc - after the last loop insn.
2097 If the last loop insn is four bytes long, the symbol will be
2098 right in the middle, but four byte insns are not swapped anyways. */
2099 /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
2100 Hence a 9 digit number should be enough to count all REPEATs. */
2102 sprintf (name
, "_R%x", count
++ & 0x3fffffff);
2103 end_sym
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
2104 /* Make this a local symbol. */
2106 SF_SET_LOCAL (end_sym
);
2107 #endif /* OBJ_COFF */
2108 symbol_table_insert (end_sym
);
2109 end_sym
->sy_value
= operand
[1].immediate
;
2110 end_sym
->sy_value
.X_add_number
+= 2;
2111 fix_new (frag_now
, frag_now_fix (), 2, end_sym
, 0, 1, BFD_RELOC_SH_LABEL
);
2114 output
= frag_more (2);
2117 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
2118 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
2120 return frag_more (2);
2123 /* Now we know what sort of opcodes it is, let's build the bytes. */
2126 build_Mytes (sh_opcode_info
*opcode
, sh_operand_info
*operand
)
2130 char *output
= frag_more (2);
2131 unsigned int size
= 2;
2132 int low_byte
= target_big_endian
? 1 : 0;
2138 for (index
= 0; index
< 4; index
++)
2140 sh_nibble_type i
= opcode
->nibbles
[index
];
2151 nbuf
[index
] = reg_n
;
2154 nbuf
[index
] = reg_m
;
2157 if (reg_n
< 2 || reg_n
> 5)
2158 as_bad (_("Invalid register: 'r%d'"), reg_n
);
2159 nbuf
[index
] = (reg_n
& 3) | 4;
2162 nbuf
[index
] = reg_n
| (reg_m
>> 2);
2165 nbuf
[index
] = reg_b
| 0x08;
2168 nbuf
[index
] = reg_n
| 0x01;
2171 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
);
2174 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
);
2177 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
);
2180 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
+ 1);
2183 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
+ 1);
2186 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
+ 1);
2189 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
);
2192 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
);
2195 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
);
2198 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
+ 1);
2201 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
+ 1);
2204 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
+ 1);
2207 insert (output
, BFD_RELOC_SH_PCRELIMM8BY4
,
2208 operand
->type
!= A_DISP_PC_ABS
, operand
);
2211 insert (output
, BFD_RELOC_SH_PCRELIMM8BY2
,
2212 operand
->type
!= A_DISP_PC_ABS
, operand
);
2215 output
= insert_loop_bounds (output
, operand
);
2216 nbuf
[index
] = opcode
->nibbles
[3];
2220 printf (_("failed for %d\n"), i
);
2224 if (!target_big_endian
)
2226 output
[1] = (nbuf
[0] << 4) | (nbuf
[1]);
2227 output
[0] = (nbuf
[2] << 4) | (nbuf
[3]);
2231 output
[0] = (nbuf
[0] << 4) | (nbuf
[1]);
2232 output
[1] = (nbuf
[2] << 4) | (nbuf
[3]);
2237 /* Find an opcode at the start of *STR_P in the hash table, and set
2238 *STR_P to the first character after the last one read. */
2240 static sh_opcode_info
*
2241 find_cooked_opcode (char **str_p
)
2244 unsigned char *op_start
;
2245 unsigned char *op_end
;
2249 /* Drop leading whitespace. */
2253 /* Find the op code end.
2254 The pre-processor will eliminate whitespace in front of
2255 any '@' after the first argument; we may be called from
2256 assemble_ppi, so the opcode might be terminated by an '@'. */
2257 for (op_start
= op_end
= (unsigned char *) (str
);
2260 && !is_end_of_line
[*op_end
] && *op_end
!= ' ' && *op_end
!= '@';
2263 unsigned char c
= op_start
[nlen
];
2265 /* The machine independent code will convert CMP/EQ into cmp/EQ
2266 because it thinks the '/' is the end of the symbol. Moreover,
2267 all but the first sub-insn is a parallel processing insn won't
2268 be capitalized. Instead of hacking up the machine independent
2269 code, we just deal with it here. */
2279 as_bad (_("can't find opcode "));
2281 return (sh_opcode_info
*) hash_find (opcode_hash_control
, name
);
2284 /* Assemble a parallel processing insn. */
2285 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
2288 assemble_ppi (char *op_end
, sh_opcode_info
*opcode
)
2300 sh_operand_info operand
[3];
2302 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
2303 Make sure we encode a defined insn pattern. */
2308 if (opcode
->arg
[0] != A_END
)
2309 op_end
= get_operands (opcode
, op_end
, operand
);
2311 opcode
= get_specific (opcode
, operand
);
2314 /* Couldn't find an opcode which matched the operands. */
2315 char *where
= frag_more (2);
2320 as_bad (_("invalid operands for opcode"));
2324 if (opcode
->nibbles
[0] != PPI
)
2325 as_bad (_("insn can't be combined with parallel processing insn"));
2327 switch (opcode
->nibbles
[1])
2332 as_bad (_("multiple movx specifications"));
2337 as_bad (_("multiple movy specifications"));
2343 as_bad (_("multiple movx specifications"));
2344 if ((reg_n
< 4 || reg_n
> 5)
2345 && (reg_n
< 0 || reg_n
> 1))
2346 as_bad (_("invalid movx address register"));
2347 if (movy
&& movy
!= DDT_BASE
)
2348 as_bad (_("insn cannot be combined with non-nopy"));
2349 movx
= ((((reg_n
& 1) != 0) << 9)
2350 + (((reg_n
& 4) == 0) << 8)
2352 + (opcode
->nibbles
[2] << 4)
2353 + opcode
->nibbles
[3]
2359 as_bad (_("multiple movy specifications"));
2360 if ((reg_n
< 6 || reg_n
> 7)
2361 && (reg_n
< 2 || reg_n
> 3))
2362 as_bad (_("invalid movy address register"));
2363 if (movx
&& movx
!= DDT_BASE
)
2364 as_bad (_("insn cannot be combined with non-nopx"));
2365 movy
= ((((reg_n
& 1) != 0) << 8)
2366 + (((reg_n
& 4) == 0) << 9)
2368 + (opcode
->nibbles
[2] << 4)
2369 + opcode
->nibbles
[3]
2375 as_bad (_("multiple movx specifications"));
2377 as_bad (_("previous movy requires nopx"));
2378 if (reg_n
< 4 || reg_n
> 5)
2379 as_bad (_("invalid movx address register"));
2380 if (opcode
->nibbles
[2] & 8)
2382 if (reg_m
== A_A1_NUM
)
2384 else if (reg_m
!= A_A0_NUM
)
2385 as_bad (_("invalid movx dsp register"));
2390 as_bad (_("invalid movx dsp register"));
2393 movx
+= ((reg_n
- 4) << 9) + (opcode
->nibbles
[2] << 2) + DDT_BASE
;
2398 as_bad (_("multiple movy specifications"));
2400 as_bad (_("previous movx requires nopy"));
2401 if (opcode
->nibbles
[2] & 8)
2403 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
2406 if (reg_m
== A_A1_NUM
)
2408 else if (reg_m
!= A_A0_NUM
)
2409 as_bad (_("invalid movy dsp register"));
2414 as_bad (_("invalid movy dsp register"));
2417 if (reg_n
< 6 || reg_n
> 7)
2418 as_bad (_("invalid movy address register"));
2419 movy
+= ((reg_n
- 6) << 8) + opcode
->nibbles
[2] + DDT_BASE
;
2423 if (operand
[0].immediate
.X_op
!= O_constant
)
2424 as_bad (_("dsp immediate shift value not constant"));
2425 field_b
= ((opcode
->nibbles
[2] << 12)
2426 | (operand
[0].immediate
.X_add_number
& 127) << 4
2433 goto try_another_opcode
;
2438 as_bad (_("multiple parallel processing specifications"));
2439 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2440 + (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2441 switch (opcode
->nibbles
[4])
2449 field_b
+= opcode
->nibbles
[4] << 4;
2457 as_bad (_("multiple condition specifications"));
2458 cond
= opcode
->nibbles
[2] << 8;
2460 goto skip_cond_check
;
2464 as_bad (_("multiple parallel processing specifications"));
2465 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2466 + cond
+ (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2468 switch (opcode
->nibbles
[4])
2476 field_b
+= opcode
->nibbles
[4] << 4;
2485 if ((field_b
& 0xef00) == 0xa100)
2487 /* pclr Dz pmuls Se,Sf,Dg */
2488 else if ((field_b
& 0xff00) == 0x8d00
2489 && (SH_MERGE_ARCH_SET_VALID (valid_arch
, arch_sh4al_dsp_up
)))
2491 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, arch_sh4al_dsp_up
);
2495 as_bad (_("insn cannot be combined with pmuls"));
2496 switch (field_b
& 0xf)
2499 field_b
+= 0 - A_X0_NUM
;
2502 field_b
+= 1 - A_Y0_NUM
;
2505 field_b
+= 2 - A_A0_NUM
;
2508 field_b
+= 3 - A_A1_NUM
;
2511 as_bad (_("bad combined pmuls output operand"));
2513 /* Generate warning if the destination register for padd / psub
2514 and pmuls is the same ( only for A0 or A1 ).
2515 If the last nibble is 1010 then A0 is used in both
2516 padd / psub and pmuls. If it is 1111 then A1 is used
2517 as destination register in both padd / psub and pmuls. */
2519 if ((((field_b
| reg_efg
) & 0x000F) == 0x000A)
2520 || (((field_b
| reg_efg
) & 0x000F) == 0x000F))
2521 as_warn (_("destination register is same for parallel insns"));
2523 field_b
+= 0x4000 + reg_efg
;
2530 as_bad (_("condition not followed by conditionalizable insn"));
2536 opcode
= find_cooked_opcode (&op_end
);
2540 (_("unrecognized characters at end of parallel processing insn")));
2545 move_code
= movx
| movy
;
2548 /* Parallel processing insn. */
2549 unsigned long ppi_code
= (movx
| movy
| 0xf800) << 16 | field_b
;
2551 output
= frag_more (4);
2553 if (! target_big_endian
)
2555 output
[3] = ppi_code
>> 8;
2556 output
[2] = ppi_code
;
2560 output
[2] = ppi_code
>> 8;
2561 output
[3] = ppi_code
;
2563 move_code
|= 0xf800;
2567 /* Just a double data transfer. */
2568 output
= frag_more (2);
2571 if (! target_big_endian
)
2573 output
[1] = move_code
>> 8;
2574 output
[0] = move_code
;
2578 output
[0] = move_code
>> 8;
2579 output
[1] = move_code
;
2584 /* This is the guts of the machine-dependent assembler. STR points to a
2585 machine dependent instruction. This function is supposed to emit
2586 the frags/bytes it assembles to. */
2589 md_assemble (char *str
)
2591 unsigned char *op_end
;
2592 sh_operand_info operand
[3];
2593 sh_opcode_info
*opcode
;
2594 unsigned int size
= 0;
2595 char *initial_str
= str
;
2598 if (sh64_isa_mode
== sh64_isa_shmedia
)
2600 shmedia_md_assemble (str
);
2605 /* If we've seen pseudo-directives, make sure any emitted data or
2606 frags are marked as data. */
2609 sh64_update_contents_mark (TRUE
);
2610 sh64_set_contents_type (CRT_SH5_ISA16
);
2615 #endif /* HAVE_SH64 */
2617 opcode
= find_cooked_opcode (&str
);
2622 /* The opcode is not in the hash table.
2623 This means we definately have an assembly failure,
2624 but the instruction may be valid in another CPU variant.
2625 In this case emit something better than 'unknown opcode'.
2626 Search the full table in sh-opc.h to check. */
2628 char *name
= initial_str
;
2629 int name_length
= 0;
2630 const sh_opcode_info
*op
;
2633 /* identify opcode in string */
2634 while (isspace (*name
))
2638 while (!isspace (name
[name_length
]))
2643 /* search for opcode in full list */
2644 for (op
= sh_table
; op
->name
; op
++)
2646 if (strncasecmp (op
->name
, name
, name_length
) == 0
2647 && op
->name
[name_length
] == '\0')
2656 as_bad (_("opcode not valid for this cpu variant"));
2660 as_bad (_("unknown opcode"));
2666 && ! seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2668 /* Output a CODE reloc to tell the linker that the following
2669 bytes are instructions, not data. */
2670 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2672 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 1;
2675 if (opcode
->nibbles
[0] == PPI
)
2677 size
= assemble_ppi (op_end
, opcode
);
2681 if (opcode
->arg
[0] == A_BDISP12
2682 || opcode
->arg
[0] == A_BDISP8
)
2684 /* Since we skip get_specific here, we have to check & update
2686 if (SH_MERGE_ARCH_SET_VALID (valid_arch
, opcode
->arch
))
2687 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, opcode
->arch
);
2689 as_bad (_("Delayed branches not available on SH1"));
2690 parse_exp (op_end
+ 1, &operand
[0]);
2691 build_relax (opcode
, &operand
[0]);
2695 if (opcode
->arg
[0] == A_END
)
2697 /* Ignore trailing whitespace. If there is any, it has already
2698 been compressed to a single space. */
2704 op_end
= get_operands (opcode
, op_end
, operand
);
2706 opcode
= get_specific (opcode
, operand
);
2710 /* Couldn't find an opcode which matched the operands. */
2711 char *where
= frag_more (2);
2716 as_bad (_("invalid operands for opcode"));
2721 as_bad (_("excess operands: '%s'"), op_end
);
2723 size
= build_Mytes (opcode
, operand
);
2728 #ifdef BFD_ASSEMBLER
2729 dwarf2_emit_insn (size
);
2733 /* This routine is called each time a label definition is seen. It
2734 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
2737 sh_frob_label (void)
2739 static fragS
*last_label_frag
;
2740 static int last_label_offset
;
2743 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2747 offset
= frag_now_fix ();
2748 if (frag_now
!= last_label_frag
2749 || offset
!= last_label_offset
)
2751 fix_new (frag_now
, offset
, 2, &abs_symbol
, 0, 0, BFD_RELOC_SH_LABEL
);
2752 last_label_frag
= frag_now
;
2753 last_label_offset
= offset
;
2758 /* This routine is called when the assembler is about to output some
2759 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
2762 sh_flush_pending_output (void)
2765 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2767 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2769 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 0;
2774 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2780 #ifndef BFD_ASSEMBLER
2783 tc_crawl_symbol_chain (object_headers
*headers ATTRIBUTE_UNUSED
)
2785 printf (_("call to tc_crawl_symbol_chain \n"));
2789 tc_headers_hook (object_headers
*headers ATTRIBUTE_UNUSED
)
2791 printf (_("call to tc_headers_hook \n"));
2797 /* Various routines to kill one day. */
2798 /* Equal to MAX_PRECISION in atof-ieee.c. */
2799 #define MAX_LITTLENUMS 6
2801 /* Turn a string in input_line_pointer into a floating point constant
2802 of type TYPE, and store the appropriate bytes in *LITP. The number
2803 of LITTLENUMS emitted is stored in *SIZEP . An error message is
2804 returned, or NULL on OK. */
2807 md_atof (int type
, char *litP
, int *sizeP
)
2810 LITTLENUM_TYPE words
[4];
2826 return _("bad call to md_atof");
2829 t
= atof_ieee (input_line_pointer
, type
, words
);
2831 input_line_pointer
= t
;
2835 if (! target_big_endian
)
2837 for (i
= prec
- 1; i
>= 0; i
--)
2839 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2845 for (i
= 0; i
< prec
; i
++)
2847 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2855 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
2856 call instruction. It refers to a label of the instruction which
2857 loads the register which the call uses. We use it to generate a
2858 special reloc for the linker. */
2861 s_uses (int ignore ATTRIBUTE_UNUSED
)
2866 as_warn (_(".uses pseudo-op seen when not relaxing"));
2870 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
2872 as_bad (_("bad .uses format"));
2873 ignore_rest_of_line ();
2877 fix_new_exp (frag_now
, frag_now_fix (), 2, &ex
, 1, BFD_RELOC_SH_USES
);
2879 demand_empty_rest_of_line ();
2882 const char *md_shortopts
= "";
2883 struct option md_longopts
[] =
2885 #define OPTION_RELAX (OPTION_MD_BASE)
2886 #define OPTION_BIG (OPTION_MD_BASE + 1)
2887 #define OPTION_LITTLE (OPTION_BIG + 1)
2888 #define OPTION_SMALL (OPTION_LITTLE + 1)
2889 #define OPTION_DSP (OPTION_SMALL + 1)
2890 #define OPTION_ISA (OPTION_DSP + 1)
2891 #define OPTION_RENESAS (OPTION_ISA + 1)
2893 {"relax", no_argument
, NULL
, OPTION_RELAX
},
2894 {"big", no_argument
, NULL
, OPTION_BIG
},
2895 {"little", no_argument
, NULL
, OPTION_LITTLE
},
2896 {"small", no_argument
, NULL
, OPTION_SMALL
},
2897 {"dsp", no_argument
, NULL
, OPTION_DSP
},
2898 {"isa", required_argument
, NULL
, OPTION_ISA
},
2899 {"renesas", no_argument
, NULL
, OPTION_RENESAS
},
2902 #define OPTION_ABI (OPTION_RENESAS + 1)
2903 #define OPTION_NO_MIX (OPTION_ABI + 1)
2904 #define OPTION_SHCOMPACT_CONST_CRANGE (OPTION_NO_MIX + 1)
2905 #define OPTION_NO_EXPAND (OPTION_SHCOMPACT_CONST_CRANGE + 1)
2906 #define OPTION_PT32 (OPTION_NO_EXPAND + 1)
2907 {"abi", required_argument
, NULL
, OPTION_ABI
},
2908 {"no-mix", no_argument
, NULL
, OPTION_NO_MIX
},
2909 {"shcompact-const-crange", no_argument
, NULL
, OPTION_SHCOMPACT_CONST_CRANGE
},
2910 {"no-expand", no_argument
, NULL
, OPTION_NO_EXPAND
},
2911 {"expand-pt32", no_argument
, NULL
, OPTION_PT32
},
2912 #endif /* HAVE_SH64 */
2914 {NULL
, no_argument
, NULL
, 0}
2916 size_t md_longopts_size
= sizeof (md_longopts
);
2919 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
2928 target_big_endian
= 1;
2932 target_big_endian
= 0;
2940 preset_target_arch
= arch_sh1_up
& ~(arch_sh_sp_fpu
|arch_sh_dp_fpu
);
2943 case OPTION_RENESAS
:
2944 dont_adjust_reloc_32
= 1;
2948 if (strcasecmp (arg
, "sh4") == 0)
2949 preset_target_arch
= arch_sh4
;
2950 else if (strcasecmp (arg
, "sh4-nofpu") == 0)
2951 preset_target_arch
= arch_sh4_nofpu
;
2952 else if (strcasecmp (arg
, "sh4-nommu-nofpu") == 0)
2953 preset_target_arch
= arch_sh4_nommu_nofpu
;
2954 else if (strcasecmp (arg
, "sh4a") == 0)
2955 preset_target_arch
= arch_sh4a
;
2956 else if (strcasecmp (arg
, "dsp") == 0)
2957 preset_target_arch
= arch_sh1_up
& ~(arch_sh_sp_fpu
|arch_sh_dp_fpu
);
2958 else if (strcasecmp (arg
, "fp") == 0)
2959 preset_target_arch
= arch_sh1_up
& ~arch_sh_has_dsp
;
2960 else if (strcasecmp (arg
, "any") == 0)
2961 preset_target_arch
= arch_sh1_up
;
2963 else if (strcasecmp (arg
, "shmedia") == 0)
2965 if (sh64_isa_mode
== sh64_isa_shcompact
)
2966 as_bad (_("Invalid combination: --isa=SHcompact with --isa=SHmedia"));
2967 sh64_isa_mode
= sh64_isa_shmedia
;
2969 else if (strcasecmp (arg
, "shcompact") == 0)
2971 if (sh64_isa_mode
== sh64_isa_shmedia
)
2972 as_bad (_("Invalid combination: --isa=SHmedia with --isa=SHcompact"));
2973 if (sh64_abi
== sh64_abi_64
)
2974 as_bad (_("Invalid combination: --abi=64 with --isa=SHcompact"));
2975 sh64_isa_mode
= sh64_isa_shcompact
;
2977 #endif /* HAVE_SH64 */
2980 extern const bfd_arch_info_type bfd_sh_arch
;
2981 extern unsigned int sh_ef_archset_table
[];
2982 bfd_arch_info_type
*bfd_arch
= &bfd_sh_arch
;
2983 preset_target_arch
= 0;
2984 for (; bfd_arch
; bfd_arch
=bfd_arch
->next
)
2986 int len
= strlen(bfd_arch
->printable_name
);
2988 if (bfd_arch
->mach
== bfd_mach_sh5
)
2991 if (strncasecmp (bfd_arch
->printable_name
, arg
, len
) != 0)
2994 if (arg
[len
] == '\0')
2995 preset_target_arch
=
2996 sh_get_arch_from_bfd_mach (bfd_arch
->mach
);
2997 else if (strcasecmp(&arg
[len
], "-up") == 0)
2998 preset_target_arch
=
2999 sh_get_arch_up_from_bfd_mach (bfd_arch
->mach
);
3005 if (!preset_target_arch
)
3006 as_bad ("Invalid argument to --isa option: %s", arg
);
3012 if (strcmp (arg
, "32") == 0)
3014 if (sh64_abi
== sh64_abi_64
)
3015 as_bad (_("Invalid combination: --abi=32 with --abi=64"));
3016 sh64_abi
= sh64_abi_32
;
3018 else if (strcmp (arg
, "64") == 0)
3020 if (sh64_abi
== sh64_abi_32
)
3021 as_bad (_("Invalid combination: --abi=64 with --abi=32"));
3022 if (sh64_isa_mode
== sh64_isa_shcompact
)
3023 as_bad (_("Invalid combination: --isa=SHcompact with --abi=64"));
3024 sh64_abi
= sh64_abi_64
;
3027 as_bad ("Invalid argument to --abi option: %s", arg
);
3034 case OPTION_SHCOMPACT_CONST_CRANGE
:
3035 sh64_shcompact_const_crange
= TRUE
;
3038 case OPTION_NO_EXPAND
:
3039 sh64_expand
= FALSE
;
3045 #endif /* HAVE_SH64 */
3055 md_show_usage (FILE *stream
)
3057 fprintf (stream
, _("\
3059 -little generate little endian code\n\
3060 -big generate big endian code\n\
3061 -relax alter jump instructions for long displacements\n\
3062 -renesas disable optimization with section symbol for\n\
3063 compatibility with Renesas assembler.\n\
3064 -small align sections to 4 byte boundaries, not 16\n\
3065 -dsp enable sh-dsp insns, and disable floating-point ISAs.\n\
3066 -isa=[any use most appropriate isa\n\
3067 | dsp same as '-dsp'\n\
3070 extern const bfd_arch_info_type bfd_sh_arch
;
3071 bfd_arch_info_type
*bfd_arch
= &bfd_sh_arch
;
3072 for (; bfd_arch
; bfd_arch
=bfd_arch
->next
)
3073 if (bfd_arch
->mach
!= bfd_mach_sh5
)
3075 fprintf (stream
, "\n | %s", bfd_arch
->printable_name
);
3076 fprintf (stream
, "\n | %s-up", bfd_arch
->printable_name
);
3079 fprintf (stream
, "]\n");
3081 fprintf (stream
, _("\
3082 -isa=[shmedia set as the default instruction set for SH64\n\
3086 fprintf (stream
, _("\
3087 -abi=[32|64] set size of expanded SHmedia operands and object\n\
3089 -shcompact-const-crange emit code-range descriptors for constants in\n\
3090 SHcompact code sections\n\
3091 -no-mix disallow SHmedia code in the same section as\n\
3092 constants and SHcompact code\n\
3093 -no-expand do not expand MOVI, PT, PTA or PTB instructions\n\
3094 -expand-pt32 with -abi=64, expand PT, PTA and PTB instructions\n\
3095 to 32 bits only\n"));
3096 #endif /* HAVE_SH64 */
3099 /* This struct is used to pass arguments to sh_count_relocs through
3100 bfd_map_over_sections. */
3102 struct sh_count_relocs
3104 /* Symbol we are looking for. */
3106 /* Count of relocs found. */
3110 /* Count the number of fixups in a section which refer to a particular
3111 symbol. When using BFD_ASSEMBLER, this is called via
3112 bfd_map_over_sections. */
3115 sh_count_relocs (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec
, void *data
)
3117 struct sh_count_relocs
*info
= (struct sh_count_relocs
*) data
;
3118 segment_info_type
*seginfo
;
3122 seginfo
= seg_info (sec
);
3123 if (seginfo
== NULL
)
3127 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
3129 if (fix
->fx_addsy
== sym
)
3137 /* Handle the count relocs for a particular section. When using
3138 BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
3141 sh_frob_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec
,
3142 void *ignore ATTRIBUTE_UNUSED
)
3144 segment_info_type
*seginfo
;
3147 seginfo
= seg_info (sec
);
3148 if (seginfo
== NULL
)
3151 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
3156 struct sh_count_relocs info
;
3158 if (fix
->fx_r_type
!= BFD_RELOC_SH_USES
)
3161 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
3162 symbol in the same section. */
3163 sym
= fix
->fx_addsy
;
3165 || fix
->fx_subsy
!= NULL
3166 || fix
->fx_addnumber
!= 0
3167 || S_GET_SEGMENT (sym
) != sec
3168 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
3169 || S_GET_STORAGE_CLASS (sym
) == C_EXT
3171 || S_IS_EXTERNAL (sym
))
3173 as_warn_where (fix
->fx_file
, fix
->fx_line
,
3174 _(".uses does not refer to a local symbol in the same section"));
3178 /* Look through the fixups again, this time looking for one
3179 at the same location as sym. */
3180 val
= S_GET_VALUE (sym
);
3181 for (fscan
= seginfo
->fix_root
;
3183 fscan
= fscan
->fx_next
)
3184 if (val
== fscan
->fx_frag
->fr_address
+ fscan
->fx_where
3185 && fscan
->fx_r_type
!= BFD_RELOC_SH_ALIGN
3186 && fscan
->fx_r_type
!= BFD_RELOC_SH_CODE
3187 && fscan
->fx_r_type
!= BFD_RELOC_SH_DATA
3188 && fscan
->fx_r_type
!= BFD_RELOC_SH_LABEL
)
3192 as_warn_where (fix
->fx_file
, fix
->fx_line
,
3193 _("can't find fixup pointed to by .uses"));
3197 if (fscan
->fx_tcbit
)
3199 /* We've already done this one. */
3203 /* The variable fscan should also be a fixup to a local symbol
3204 in the same section. */
3205 sym
= fscan
->fx_addsy
;
3207 || fscan
->fx_subsy
!= NULL
3208 || fscan
->fx_addnumber
!= 0
3209 || S_GET_SEGMENT (sym
) != sec
3210 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
3211 || S_GET_STORAGE_CLASS (sym
) == C_EXT
3213 || S_IS_EXTERNAL (sym
))
3215 as_warn_where (fix
->fx_file
, fix
->fx_line
,
3216 _(".uses target does not refer to a local symbol in the same section"));
3220 /* Now we look through all the fixups of all the sections,
3221 counting the number of times we find a reference to sym. */
3224 #ifdef BFD_ASSEMBLER
3225 bfd_map_over_sections (stdoutput
, sh_count_relocs
, &info
);
3230 for (iscan
= SEG_E0
; iscan
< SEG_UNKNOWN
; iscan
++)
3231 sh_count_relocs ((bfd
*) NULL
, iscan
, &info
);
3238 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
3239 We have already adjusted the value of sym to include the
3240 fragment address, so we undo that adjustment here. */
3241 subseg_change (sec
, 0);
3242 fix_new (fscan
->fx_frag
,
3243 S_GET_VALUE (sym
) - fscan
->fx_frag
->fr_address
,
3244 4, &abs_symbol
, info
.count
, 0, BFD_RELOC_SH_COUNT
);
3248 /* This function is called after the symbol table has been completed,
3249 but before the relocs or section contents have been written out.
3250 If we have seen any .uses pseudo-ops, they point to an instruction
3251 which loads a register with the address of a function. We look
3252 through the fixups to find where the function address is being
3253 loaded from. We then generate a COUNT reloc giving the number of
3254 times that function address is referred to. The linker uses this
3255 information when doing relaxing, to decide when it can eliminate
3256 the stored function address entirely. */
3262 shmedia_frob_file_before_adjust ();
3268 #ifdef BFD_ASSEMBLER
3269 bfd_map_over_sections (stdoutput
, sh_frob_section
, NULL
);
3274 for (iseg
= SEG_E0
; iseg
< SEG_UNKNOWN
; iseg
++)
3275 sh_frob_section ((bfd
*) NULL
, iseg
, NULL
);
3280 /* Called after relaxing. Set the correct sizes of the fragments, and
3281 create relocs so that md_apply_fix3 will fill in the correct values. */
3284 #ifdef BFD_ASSEMBLER
3285 md_convert_frag (bfd
*headers ATTRIBUTE_UNUSED
, segT seg
, fragS
*fragP
)
3287 md_convert_frag (object_headers
*headers ATTRIBUTE_UNUSED
, segT seg
,
3293 switch (fragP
->fr_subtype
)
3295 case C (COND_JUMP
, COND8
):
3296 case C (COND_JUMP_DELAY
, COND8
):
3297 subseg_change (seg
, 0);
3298 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
3299 1, BFD_RELOC_SH_PCDISP8BY2
);
3304 case C (UNCOND_JUMP
, UNCOND12
):
3305 subseg_change (seg
, 0);
3306 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
3307 1, BFD_RELOC_SH_PCDISP12BY2
);
3312 case C (UNCOND_JUMP
, UNCOND32
):
3313 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
3314 if (fragP
->fr_symbol
== NULL
)
3315 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3316 _("displacement overflows 12-bit field"));
3317 else if (S_IS_DEFINED (fragP
->fr_symbol
))
3318 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3319 _("displacement to defined symbol %s overflows 12-bit field"),
3320 S_GET_NAME (fragP
->fr_symbol
));
3322 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3323 _("displacement to undefined symbol %s overflows 12-bit field"),
3324 S_GET_NAME (fragP
->fr_symbol
));
3325 /* Stabilize this frag, so we don't trip an assert. */
3326 fragP
->fr_fix
+= fragP
->fr_var
;
3330 case C (COND_JUMP
, COND12
):
3331 case C (COND_JUMP_DELAY
, COND12
):
3332 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
3333 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
3334 was due to gas incorrectly relaxing an out-of-range conditional
3335 branch with delay slot. It turned:
3336 bf.s L6 (slot mov.l r12,@(44,r0))
3339 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
3341 32: 10 cb mov.l r12,@(44,r0)
3342 Therefore, branches with delay slots have to be handled
3343 differently from ones without delay slots. */
3345 unsigned char *buffer
=
3346 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
3347 int highbyte
= target_big_endian
? 0 : 1;
3348 int lowbyte
= target_big_endian
? 1 : 0;
3349 int delay
= fragP
->fr_subtype
== C (COND_JUMP_DELAY
, COND12
);
3351 /* Toggle the true/false bit of the bcond. */
3352 buffer
[highbyte
] ^= 0x2;
3354 /* If this is a delayed branch, we may not put the bra in the
3355 slot. So we change it to a non-delayed branch, like that:
3356 b! cond slot_label; bra disp; slot_label: slot_insn
3357 ??? We should try if swapping the conditional branch and
3358 its delay-slot insn already makes the branch reach. */
3360 /* Build a relocation to six / four bytes farther on. */
3361 subseg_change (seg
, 0);
3362 fix_new (fragP
, fragP
->fr_fix
, 2,
3363 #ifdef BFD_ASSEMBLER
3364 section_symbol (seg
),
3366 seg_info (seg
)->dot
,
3368 fragP
->fr_address
+ fragP
->fr_fix
+ (delay
? 4 : 6),
3369 1, BFD_RELOC_SH_PCDISP8BY2
);
3371 /* Set up a jump instruction. */
3372 buffer
[highbyte
+ 2] = 0xa0;
3373 buffer
[lowbyte
+ 2] = 0;
3374 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
3375 fragP
->fr_offset
, 1, BFD_RELOC_SH_PCDISP12BY2
);
3379 buffer
[highbyte
] &= ~0x4; /* Removes delay slot from branch. */
3384 /* Fill in a NOP instruction. */
3385 buffer
[highbyte
+ 4] = 0x0;
3386 buffer
[lowbyte
+ 4] = 0x9;
3395 case C (COND_JUMP
, COND32
):
3396 case C (COND_JUMP_DELAY
, COND32
):
3397 case C (COND_JUMP
, UNDEF_WORD_DISP
):
3398 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
3399 if (fragP
->fr_symbol
== NULL
)
3400 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3401 _("displacement overflows 8-bit field"));
3402 else if (S_IS_DEFINED (fragP
->fr_symbol
))
3403 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3404 _("displacement to defined symbol %s overflows 8-bit field"),
3405 S_GET_NAME (fragP
->fr_symbol
));
3407 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3408 _("displacement to undefined symbol %s overflows 8-bit field "),
3409 S_GET_NAME (fragP
->fr_symbol
));
3410 /* Stabilize this frag, so we don't trip an assert. */
3411 fragP
->fr_fix
+= fragP
->fr_var
;
3417 shmedia_md_convert_frag (headers
, seg
, fragP
, TRUE
);
3423 if (donerelax
&& !sh_relax
)
3424 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
3425 _("overflow in branch to %s; converted into longer instruction sequence"),
3426 (fragP
->fr_symbol
!= NULL
3427 ? S_GET_NAME (fragP
->fr_symbol
)
3432 md_section_align (segT seg ATTRIBUTE_UNUSED
, valueT size
)
3434 #ifdef BFD_ASSEMBLER
3437 #else /* ! OBJ_ELF */
3438 return ((size
+ (1 << bfd_get_section_alignment (stdoutput
, seg
)) - 1)
3439 & (-1 << bfd_get_section_alignment (stdoutput
, seg
)));
3440 #endif /* ! OBJ_ELF */
3441 #else /* ! BFD_ASSEMBLER */
3442 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
3443 & (-1 << section_alignment
[(int) seg
]));
3444 #endif /* ! BFD_ASSEMBLER */
3447 /* This static variable is set by s_uacons to tell sh_cons_align that
3448 the expression does not need to be aligned. */
3450 static int sh_no_align_cons
= 0;
3452 /* This handles the unaligned space allocation pseudo-ops, such as
3453 .uaword. .uaword is just like .word, but the value does not need
3457 s_uacons (int bytes
)
3459 /* Tell sh_cons_align not to align this value. */
3460 sh_no_align_cons
= 1;
3464 /* If a .word, et. al., pseud-op is seen, warn if the value is not
3465 aligned correctly. Note that this can cause warnings to be issued
3466 when assembling initialized structured which were declared with the
3467 packed attribute. FIXME: Perhaps we should require an option to
3468 enable this warning? */
3471 sh_cons_align (int nbytes
)
3476 if (sh_no_align_cons
)
3478 /* This is an unaligned pseudo-op. */
3479 sh_no_align_cons
= 0;
3484 while ((nbytes
& 1) == 0)
3493 if (now_seg
== absolute_section
)
3495 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
3496 as_warn (_("misaligned data"));
3500 p
= frag_var (rs_align_test
, 1, 1, (relax_substateT
) 0,
3501 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
3503 record_alignment (now_seg
, nalign
);
3506 /* When relaxing, we need to output a reloc for any .align directive
3507 that requests alignment to a four byte boundary or larger. This is
3508 also where we check for misaligned data. */
3511 sh_handle_align (fragS
*frag
)
3513 int bytes
= frag
->fr_next
->fr_address
- frag
->fr_address
- frag
->fr_fix
;
3515 if (frag
->fr_type
== rs_align_code
)
3517 static const unsigned char big_nop_pattern
[] = { 0x00, 0x09 };
3518 static const unsigned char little_nop_pattern
[] = { 0x09, 0x00 };
3520 char *p
= frag
->fr_literal
+ frag
->fr_fix
;
3529 if (target_big_endian
)
3531 memcpy (p
, big_nop_pattern
, sizeof big_nop_pattern
);
3532 frag
->fr_var
= sizeof big_nop_pattern
;
3536 memcpy (p
, little_nop_pattern
, sizeof little_nop_pattern
);
3537 frag
->fr_var
= sizeof little_nop_pattern
;
3540 else if (frag
->fr_type
== rs_align_test
)
3543 as_warn_where (frag
->fr_file
, frag
->fr_line
, _("misaligned data"));
3547 && (frag
->fr_type
== rs_align
3548 || frag
->fr_type
== rs_align_code
)
3549 && frag
->fr_address
+ frag
->fr_fix
> 0
3550 && frag
->fr_offset
> 1
3551 && now_seg
!= bss_section
)
3552 fix_new (frag
, frag
->fr_fix
, 2, &abs_symbol
, frag
->fr_offset
, 0,
3553 BFD_RELOC_SH_ALIGN
);
3556 /* See whether the relocation should be resolved locally. */
3559 sh_local_pcrel (fixS
*fix
)
3562 && (fix
->fx_r_type
== BFD_RELOC_SH_PCDISP8BY2
3563 || fix
->fx_r_type
== BFD_RELOC_SH_PCDISP12BY2
3564 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY2
3565 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY4
3566 || fix
->fx_r_type
== BFD_RELOC_8_PCREL
3567 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH16
3568 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH32
));
3571 /* See whether we need to force a relocation into the output file.
3572 This is used to force out switch and PC relative relocations when
3576 sh_force_relocation (fixS
*fix
)
3578 /* These relocations can't make it into a DSO, so no use forcing
3579 them for global symbols. */
3580 if (sh_local_pcrel (fix
))
3583 /* Make sure some relocations get emitted. */
3584 if (fix
->fx_r_type
== BFD_RELOC_SH_LOOP_START
3585 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_END
3586 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_GD_32
3587 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LD_32
3588 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_IE_32
3589 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LDO_32
3590 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LE_32
3591 || generic_force_reloc (fix
))
3597 return (fix
->fx_pcrel
3598 || SWITCH_TABLE (fix
)
3599 || fix
->fx_r_type
== BFD_RELOC_SH_COUNT
3600 || fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
3601 || fix
->fx_r_type
== BFD_RELOC_SH_CODE
3602 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
3604 || fix
->fx_r_type
== BFD_RELOC_SH_SHMEDIA_CODE
3606 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
);
3611 sh_fix_adjustable (fixS
*fixP
)
3613 if (fixP
->fx_r_type
== BFD_RELOC_32_PLT_PCREL
3614 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
3615 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTPC
3616 || ((fixP
->fx_r_type
== BFD_RELOC_32
) && dont_adjust_reloc_32
)
3617 || fixP
->fx_r_type
== BFD_RELOC_RVA
)
3620 /* We need the symbol name for the VTABLE entries */
3621 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3622 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
3629 sh_elf_final_processing (void)
3633 /* Set file-specific flags to indicate if this code needs
3634 a processor with the sh-dsp / sh2e ISA to execute. */
3636 /* SH5 and above don't know about the valid_arch arch_sh* bits defined
3637 in sh-opc.h, so check SH64 mode before checking valid_arch. */
3638 if (sh64_isa_mode
!= sh64_isa_unspecified
)
3641 #endif /* HAVE_SH64 */
3642 val
= sh_find_elf_flags (valid_arch
);
3644 elf_elfheader (stdoutput
)->e_flags
&= ~EF_SH_MACH_MASK
;
3645 elf_elfheader (stdoutput
)->e_flags
|= val
;
3649 /* Apply a fixup to the object file. */
3652 md_apply_fix3 (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3654 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3655 int lowbyte
= target_big_endian
? 1 : 0;
3656 int highbyte
= target_big_endian
? 0 : 1;
3657 long val
= (long) *valP
;
3661 #ifdef BFD_ASSEMBLER
3662 /* A difference between two symbols, the second of which is in the
3663 current section, is transformed in a PC-relative relocation to
3664 the other symbol. We have to adjust the relocation type here. */
3667 switch (fixP
->fx_r_type
)
3673 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
3676 /* Currently, we only support 32-bit PCREL relocations.
3677 We'd need a new reloc type to handle 16_PCREL, and
3678 8_PCREL is already taken for R_SH_SWITCH8, which
3679 apparently does something completely different than what
3682 bfd_set_error (bfd_error_bad_value
);
3686 bfd_set_error (bfd_error_bad_value
);
3691 /* The function adjust_reloc_syms won't convert a reloc against a weak
3692 symbol into a reloc against a section, but bfd_install_relocation
3693 will screw up if the symbol is defined, so we have to adjust val here
3694 to avoid the screw up later.
3696 For ordinary relocs, this does not happen for ELF, since for ELF,
3697 bfd_install_relocation uses the "special function" field of the
3698 howto, and does not execute the code that needs to be undone, as long
3699 as the special function does not return bfd_reloc_continue.
3700 It can happen for GOT- and PLT-type relocs the way they are
3701 described in elf32-sh.c as they use bfd_elf_generic_reloc, but it
3702 doesn't matter here since those relocs don't use VAL; see below. */
3703 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
3704 && fixP
->fx_addsy
!= NULL
3705 && S_IS_WEAK (fixP
->fx_addsy
))
3706 val
-= S_GET_VALUE (fixP
->fx_addsy
);
3709 #ifdef BFD_ASSEMBLER
3710 if (SWITCH_TABLE (fixP
))
3711 val
-= S_GET_VALUE (fixP
->fx_subsy
);
3713 if (fixP
->fx_r_type
== 0)
3715 if (fixP
->fx_size
== 2)
3716 fixP
->fx_r_type
= BFD_RELOC_16
;
3717 else if (fixP
->fx_size
== 4)
3718 fixP
->fx_r_type
= BFD_RELOC_32
;
3719 else if (fixP
->fx_size
== 1)
3720 fixP
->fx_r_type
= BFD_RELOC_8
;
3728 switch (fixP
->fx_r_type
)
3730 case BFD_RELOC_SH_IMM4
:
3732 *buf
= (*buf
& 0xf0) | (val
& 0xf);
3735 case BFD_RELOC_SH_IMM4BY2
:
3738 *buf
= (*buf
& 0xf0) | ((val
>> 1) & 0xf);
3741 case BFD_RELOC_SH_IMM4BY4
:
3744 *buf
= (*buf
& 0xf0) | ((val
>> 2) & 0xf);
3747 case BFD_RELOC_SH_IMM8BY2
:
3753 case BFD_RELOC_SH_IMM8BY4
:
3760 case BFD_RELOC_SH_IMM8
:
3761 /* Sometimes the 8 bit value is sign extended (e.g., add) and
3762 sometimes it is not (e.g., and). We permit any 8 bit value.
3763 Note that adding further restrictions may invalidate
3764 reasonable looking assembly code, such as ``and -0x1,r0''. */
3770 case BFD_RELOC_SH_PCRELIMM8BY4
:
3771 /* The lower two bits of the PC are cleared before the
3772 displacement is added in. We can assume that the destination
3773 is on a 4 byte boundary. If this instruction is also on a 4
3774 byte boundary, then we want
3776 and target - here is a multiple of 4.
3777 Otherwise, we are on a 2 byte boundary, and we want
3778 (target - (here - 2)) / 4
3779 and target - here is not a multiple of 4. Computing
3780 (target - (here - 2)) / 4 == (target - here + 2) / 4
3781 works for both cases, since in the first case the addition of
3782 2 will be removed by the division. target - here is in the
3784 val
= (val
+ 2) / 4;
3786 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3790 case BFD_RELOC_SH_PCRELIMM8BY2
:
3793 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3797 case BFD_RELOC_SH_PCDISP8BY2
:
3799 if (val
< -0x80 || val
> 0x7f)
3800 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3804 case BFD_RELOC_SH_PCDISP12BY2
:
3806 if (val
< -0x800 || val
> 0x7ff)
3807 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3808 buf
[lowbyte
] = val
& 0xff;
3809 buf
[highbyte
] |= (val
>> 8) & 0xf;
3813 case BFD_RELOC_32_PCREL
:
3814 md_number_to_chars (buf
, val
, 4);
3818 md_number_to_chars (buf
, val
, 2);
3821 case BFD_RELOC_SH_USES
:
3822 /* Pass the value into sh_coff_reloc_mangle. */
3823 fixP
->fx_addnumber
= val
;
3826 case BFD_RELOC_SH_COUNT
:
3827 case BFD_RELOC_SH_ALIGN
:
3828 case BFD_RELOC_SH_CODE
:
3829 case BFD_RELOC_SH_DATA
:
3830 case BFD_RELOC_SH_LABEL
:
3831 /* Nothing to do here. */
3834 case BFD_RELOC_SH_LOOP_START
:
3835 case BFD_RELOC_SH_LOOP_END
:
3837 case BFD_RELOC_VTABLE_INHERIT
:
3838 case BFD_RELOC_VTABLE_ENTRY
:
3843 case BFD_RELOC_32_PLT_PCREL
:
3844 /* Make the jump instruction point to the address of the operand. At
3845 runtime we merely add the offset to the actual PLT entry. */
3846 * valP
= 0xfffffffc;
3847 val
= fixP
->fx_offset
;
3849 val
-= S_GET_VALUE (fixP
->fx_subsy
);
3850 fixP
->fx_addnumber
= val
;
3851 md_number_to_chars (buf
, val
, 4);
3854 case BFD_RELOC_SH_GOTPC
:
3855 /* This is tough to explain. We end up with this one if we have
3856 operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
3857 The goal here is to obtain the absolute address of the GOT,
3858 and it is strongly preferable from a performance point of
3859 view to avoid using a runtime relocation for this. There are
3860 cases where you have something like:
3862 .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
3864 and here no correction would be required. Internally in the
3865 assembler we treat operands of this form as not being pcrel
3866 since the '.' is explicitly mentioned, and I wonder whether
3867 it would simplify matters to do it this way. Who knows. In
3868 earlier versions of the PIC patches, the pcrel_adjust field
3869 was used to store the correction, but since the expression is
3870 not pcrel, I felt it would be confusing to do it this way. */
3872 md_number_to_chars (buf
, val
, 4);
3875 case BFD_RELOC_SH_TLS_GD_32
:
3876 case BFD_RELOC_SH_TLS_LD_32
:
3877 case BFD_RELOC_SH_TLS_IE_32
:
3878 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
3880 case BFD_RELOC_32_GOT_PCREL
:
3881 case BFD_RELOC_SH_GOTPLT32
:
3882 * valP
= 0; /* Fully resolved at runtime. No addend. */
3883 md_number_to_chars (buf
, 0, 4);
3886 case BFD_RELOC_SH_TLS_LDO_32
:
3887 case BFD_RELOC_SH_TLS_LE_32
:
3888 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
3890 case BFD_RELOC_32_GOTOFF
:
3891 md_number_to_chars (buf
, val
, 4);
3897 shmedia_md_apply_fix3 (fixP
, valP
);
3906 if ((val
& ((1 << shift
) - 1)) != 0)
3907 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("misaligned offset"));
3911 val
= ((val
>> shift
)
3912 | ((long) -1 & ~ ((long) -1 >> shift
)));
3914 if (max
!= 0 && (val
< min
|| val
> max
))
3915 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("offset out of range"));
3917 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3921 /* Called just before address relaxation. Return the length
3922 by which a fragment must grow to reach it's destination. */
3925 md_estimate_size_before_relax (fragS
*fragP
, segT segment_type
)
3929 switch (fragP
->fr_subtype
)
3933 return shmedia_md_estimate_size_before_relax (fragP
, segment_type
);
3939 case C (UNCOND_JUMP
, UNDEF_DISP
):
3940 /* Used to be a branch to somewhere which was unknown. */
3941 if (!fragP
->fr_symbol
)
3943 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3945 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3947 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3951 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNDEF_WORD_DISP
);
3955 case C (COND_JUMP
, UNDEF_DISP
):
3956 case C (COND_JUMP_DELAY
, UNDEF_DISP
):
3957 what
= GET_WHAT (fragP
->fr_subtype
);
3958 /* Used to be a branch to somewhere which was unknown. */
3959 if (fragP
->fr_symbol
3960 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3962 /* Got a symbol and it's defined in this segment, become byte
3963 sized - maybe it will fix up. */
3964 fragP
->fr_subtype
= C (what
, COND8
);
3966 else if (fragP
->fr_symbol
)
3968 /* Its got a segment, but its not ours, so it will always be long. */
3969 fragP
->fr_subtype
= C (what
, UNDEF_WORD_DISP
);
3973 /* We know the abs value. */
3974 fragP
->fr_subtype
= C (what
, COND8
);
3978 case C (UNCOND_JUMP
, UNCOND12
):
3979 case C (UNCOND_JUMP
, UNCOND32
):
3980 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
3981 case C (COND_JUMP
, COND8
):
3982 case C (COND_JUMP
, COND12
):
3983 case C (COND_JUMP
, COND32
):
3984 case C (COND_JUMP
, UNDEF_WORD_DISP
):
3985 case C (COND_JUMP_DELAY
, COND8
):
3986 case C (COND_JUMP_DELAY
, COND12
):
3987 case C (COND_JUMP_DELAY
, COND32
):
3988 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
3989 /* When relaxing a section for the second time, we don't need to
3990 do anything besides return the current size. */
3994 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
3995 return fragP
->fr_var
;
3998 /* Put number into target byte order. */
4001 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
4004 /* We might need to set the contents type to data. */
4005 sh64_flag_output ();
4008 if (! target_big_endian
)
4009 number_to_chars_littleendian (ptr
, use
, nbytes
);
4011 number_to_chars_bigendian (ptr
, use
, nbytes
);
4014 /* This version is used in obj-coff.c when not using BFD_ASSEMBLER.
4015 eg for the sh-hms target. */
4018 md_pcrel_from (fixS
*fixP
)
4020 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
+ 2;
4024 md_pcrel_from_section (fixS
*fixP
, segT sec
)
4026 if (! sh_local_pcrel (fixP
)
4027 && fixP
->fx_addsy
!= (symbolS
*) NULL
4028 && (generic_force_reloc (fixP
)
4029 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
4031 /* The symbol is undefined (or is defined but not in this section,
4032 or we're not sure about it being the final definition). Let the
4033 linker figure it out. We need to adjust the subtraction of a
4034 symbol to the position of the relocated data, though. */
4035 return fixP
->fx_subsy
? fixP
->fx_where
+ fixP
->fx_frag
->fr_address
: 0;
4038 return md_pcrel_from (fixP
);
4044 tc_coff_sizemachdep (fragS
*frag
)
4046 return md_relax_table
[frag
->fr_subtype
].rlx_length
;
4049 #endif /* OBJ_COFF */
4051 #ifndef BFD_ASSEMBLER
4054 /* Map BFD relocs to SH COFF relocs. */
4058 bfd_reloc_code_real_type bfd_reloc
;
4062 static const struct reloc_map coff_reloc_map
[] =
4064 { BFD_RELOC_32
, R_SH_IMM32
},
4065 { BFD_RELOC_16
, R_SH_IMM16
},
4066 { BFD_RELOC_8
, R_SH_IMM8
},
4067 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_PCDISP8BY2
},
4068 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_PCDISP
},
4069 { BFD_RELOC_SH_IMM4
, R_SH_IMM4
},
4070 { BFD_RELOC_SH_IMM4BY2
, R_SH_IMM4BY2
},
4071 { BFD_RELOC_SH_IMM4BY4
, R_SH_IMM4BY4
},
4072 { BFD_RELOC_SH_IMM8
, R_SH_IMM8
},
4073 { BFD_RELOC_SH_IMM8BY2
, R_SH_IMM8BY2
},
4074 { BFD_RELOC_SH_IMM8BY4
, R_SH_IMM8BY4
},
4075 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_PCRELIMM8BY2
},
4076 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_PCRELIMM8BY4
},
4077 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
4078 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
4079 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
4080 { BFD_RELOC_SH_USES
, R_SH_USES
},
4081 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
4082 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
4083 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
4084 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
4085 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
4086 { BFD_RELOC_UNUSED
, 0 }
4089 /* Adjust a reloc for the SH. This is similar to the generic code,
4090 but does some minor tweaking. */
4093 sh_coff_reloc_mangle (segment_info_type
*seg
, fixS
*fix
,
4094 struct internal_reloc
*intr
, unsigned int paddr
)
4096 symbolS
*symbol_ptr
= fix
->fx_addsy
;
4099 intr
->r_vaddr
= paddr
+ fix
->fx_frag
->fr_address
+ fix
->fx_where
;
4101 if (! SWITCH_TABLE (fix
))
4103 const struct reloc_map
*rm
;
4105 for (rm
= coff_reloc_map
; rm
->bfd_reloc
!= BFD_RELOC_UNUSED
; rm
++)
4106 if (rm
->bfd_reloc
== (bfd_reloc_code_real_type
) fix
->fx_r_type
)
4108 if (rm
->bfd_reloc
== BFD_RELOC_UNUSED
)
4109 as_bad_where (fix
->fx_file
, fix
->fx_line
,
4110 _("Can not represent %s relocation in this object file format"),
4111 bfd_get_reloc_code_name (fix
->fx_r_type
));
4112 intr
->r_type
= rm
->sh_reloc
;
4119 if (fix
->fx_r_type
== BFD_RELOC_16
)
4120 intr
->r_type
= R_SH_SWITCH16
;
4121 else if (fix
->fx_r_type
== BFD_RELOC_8
)
4122 intr
->r_type
= R_SH_SWITCH8
;
4123 else if (fix
->fx_r_type
== BFD_RELOC_32
)
4124 intr
->r_type
= R_SH_SWITCH32
;
4128 /* For a switch reloc, we set r_offset to the difference between
4129 the reloc address and the subtrahend. When the linker is
4130 doing relaxing, it can use the determine the starting and
4131 ending points of the switch difference expression. */
4132 intr
->r_offset
= intr
->r_vaddr
- S_GET_VALUE (fix
->fx_subsy
);
4135 /* PC relative relocs are always against the current section. */
4136 if (symbol_ptr
== NULL
)
4138 switch (fix
->fx_r_type
)
4140 case BFD_RELOC_SH_PCRELIMM8BY2
:
4141 case BFD_RELOC_SH_PCRELIMM8BY4
:
4142 case BFD_RELOC_SH_PCDISP8BY2
:
4143 case BFD_RELOC_SH_PCDISP12BY2
:
4144 case BFD_RELOC_SH_USES
:
4145 symbol_ptr
= seg
->dot
;
4152 if (fix
->fx_r_type
== BFD_RELOC_SH_USES
)
4154 /* We can't store the offset in the object file, since this
4155 reloc does not take up any space, so we store it in r_offset.
4156 The fx_addnumber field was set in md_apply_fix3. */
4157 intr
->r_offset
= fix
->fx_addnumber
;
4159 else if (fix
->fx_r_type
== BFD_RELOC_SH_COUNT
)
4161 /* We can't store the count in the object file, since this reloc
4162 does not take up any space, so we store it in r_offset. The
4163 fx_offset field was set when the fixup was created in
4164 sh_coff_frob_file. */
4165 intr
->r_offset
= fix
->fx_offset
;
4166 /* This reloc is always absolute. */
4169 else if (fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
)
4171 /* Store the alignment in the r_offset field. */
4172 intr
->r_offset
= fix
->fx_offset
;
4173 /* This reloc is always absolute. */
4176 else if (fix
->fx_r_type
== BFD_RELOC_SH_CODE
4177 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
4178 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
)
4180 /* These relocs are always absolute. */
4184 /* Turn the segment of the symbol into an offset. */
4185 if (symbol_ptr
!= NULL
)
4187 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
4189 intr
->r_symndx
= dot
->sy_number
;
4191 intr
->r_symndx
= symbol_ptr
->sy_number
;
4194 intr
->r_symndx
= -1;
4197 #endif /* OBJ_COFF */
4198 #endif /* ! BFD_ASSEMBLER */
4200 #ifdef BFD_ASSEMBLER
4202 /* Create a reloc. */
4205 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
4208 bfd_reloc_code_real_type r_type
;
4210 rel
= (arelent
*) xmalloc (sizeof (arelent
));
4211 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
4212 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
4213 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
4215 r_type
= fixp
->fx_r_type
;
4217 if (SWITCH_TABLE (fixp
))
4219 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
4221 if (r_type
== BFD_RELOC_16
)
4222 r_type
= BFD_RELOC_SH_SWITCH16
;
4223 else if (r_type
== BFD_RELOC_8
)
4224 r_type
= BFD_RELOC_8_PCREL
;
4225 else if (r_type
== BFD_RELOC_32
)
4226 r_type
= BFD_RELOC_SH_SWITCH32
;
4230 else if (r_type
== BFD_RELOC_SH_USES
)
4231 rel
->addend
= fixp
->fx_addnumber
;
4232 else if (r_type
== BFD_RELOC_SH_COUNT
)
4233 rel
->addend
= fixp
->fx_offset
;
4234 else if (r_type
== BFD_RELOC_SH_ALIGN
)
4235 rel
->addend
= fixp
->fx_offset
;
4236 else if (r_type
== BFD_RELOC_VTABLE_INHERIT
4237 || r_type
== BFD_RELOC_VTABLE_ENTRY
)
4238 rel
->addend
= fixp
->fx_offset
;
4239 else if (r_type
== BFD_RELOC_SH_LOOP_START
4240 || r_type
== BFD_RELOC_SH_LOOP_END
)
4241 rel
->addend
= fixp
->fx_offset
;
4242 else if (r_type
== BFD_RELOC_SH_LABEL
&& fixp
->fx_pcrel
)
4245 rel
->address
= rel
->addend
= fixp
->fx_offset
;
4248 else if (shmedia_init_reloc (rel
, fixp
))
4251 else if (fixp
->fx_pcrel
)
4252 rel
->addend
= fixp
->fx_addnumber
;
4253 else if (r_type
== BFD_RELOC_32
|| r_type
== BFD_RELOC_32_GOTOFF
)
4254 rel
->addend
= fixp
->fx_addnumber
;
4258 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
4260 if (rel
->howto
== NULL
)
4262 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
4263 _("Cannot represent relocation type %s"),
4264 bfd_get_reloc_code_name (r_type
));
4265 /* Set howto to a garbage value so that we can keep going. */
4266 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
4267 assert (rel
->howto
!= NULL
);
4270 else if (rel
->howto
->type
== R_SH_IND12W
)
4271 rel
->addend
+= fixp
->fx_offset
- 4;
4278 inline static char *
4279 sh_end_of_match (char *cont
, char *what
)
4281 int len
= strlen (what
);
4283 if (strncasecmp (cont
, what
, strlen (what
)) == 0
4284 && ! is_part_of_name (cont
[len
]))
4291 sh_parse_name (char const *name
, expressionS
*exprP
, char *nextcharP
)
4293 char *next
= input_line_pointer
;
4298 exprP
->X_op_symbol
= NULL
;
4300 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
4303 GOT_symbol
= symbol_find_or_make (name
);
4305 exprP
->X_add_symbol
= GOT_symbol
;
4307 /* If we have an absolute symbol or a reg, then we know its
4309 segment
= S_GET_SEGMENT (exprP
->X_add_symbol
);
4310 if (segment
== absolute_section
)
4312 exprP
->X_op
= O_constant
;
4313 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
4314 exprP
->X_add_symbol
= NULL
;
4316 else if (segment
== reg_section
)
4318 exprP
->X_op
= O_register
;
4319 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
4320 exprP
->X_add_symbol
= NULL
;
4324 exprP
->X_op
= O_symbol
;
4325 exprP
->X_add_number
= 0;
4331 exprP
->X_add_symbol
= symbol_find_or_make (name
);
4333 if (*nextcharP
!= '@')
4335 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTOFF")))
4336 reloc_type
= BFD_RELOC_32_GOTOFF
;
4337 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTPLT")))
4338 reloc_type
= BFD_RELOC_SH_GOTPLT32
;
4339 else if ((next_end
= sh_end_of_match (next
+ 1, "GOT")))
4340 reloc_type
= BFD_RELOC_32_GOT_PCREL
;
4341 else if ((next_end
= sh_end_of_match (next
+ 1, "PLT")))
4342 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
4343 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSGD")))
4344 reloc_type
= BFD_RELOC_SH_TLS_GD_32
;
4345 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSLDM")))
4346 reloc_type
= BFD_RELOC_SH_TLS_LD_32
;
4347 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTTPOFF")))
4348 reloc_type
= BFD_RELOC_SH_TLS_IE_32
;
4349 else if ((next_end
= sh_end_of_match (next
+ 1, "TPOFF")))
4350 reloc_type
= BFD_RELOC_SH_TLS_LE_32
;
4351 else if ((next_end
= sh_end_of_match (next
+ 1, "DTPOFF")))
4352 reloc_type
= BFD_RELOC_SH_TLS_LDO_32
;
4356 *input_line_pointer
= *nextcharP
;
4357 input_line_pointer
= next_end
;
4358 *nextcharP
= *input_line_pointer
;
4359 *input_line_pointer
= '\0';
4361 exprP
->X_op
= O_PIC_reloc
;
4362 exprP
->X_add_number
= 0;
4363 exprP
->X_md
= reloc_type
;
4370 sh_cfi_frame_initial_instructions (void)
4372 cfi_add_CFA_def_cfa (15, 0);
4376 sh_regname_to_dw2regnum (const char *regname
)
4378 unsigned int regnum
= -1;
4382 static struct { char *name
; int dw2regnum
; } regnames
[] =
4384 { "pr", 17 }, { "t", 18 }, { "gbr", 19 }, { "mach", 20 },
4385 { "macl", 21 }, { "fpul", 23 }
4388 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
4389 if (strcmp (regnames
[i
].name
, regname
) == 0)
4390 return regnames
[i
].dw2regnum
;
4392 if (regname
[0] == 'r')
4395 regnum
= strtoul (p
, &q
, 10);
4396 if (p
== q
|| *q
|| regnum
>= 16)
4399 else if (regname
[0] == 'f' && regname
[1] == 'r')
4402 regnum
= strtoul (p
, &q
, 10);
4403 if (p
== q
|| *q
|| regnum
>= 16)
4407 else if (regname
[0] == 'x' && regname
[1] == 'd')
4410 regnum
= strtoul (p
, &q
, 10);
4411 if (p
== q
|| *q
|| regnum
>= 8)
4417 #endif /* BFD_ASSEMBLER */