1 /* tc-sh.c -- Assemble code for the Renesas / SuperH SH
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 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"
43 expressionS immediate
;
47 const char comment_chars
[] = "!";
48 const char line_separator_chars
[] = ";";
49 const char line_comment_chars
[] = "!#";
51 static void s_uses
PARAMS ((int));
53 static void sh_count_relocs
PARAMS ((bfd
*, segT
, PTR
));
54 static void sh_frob_section
PARAMS ((bfd
*, segT
, PTR
));
56 static void s_uacons
PARAMS ((int));
57 static sh_opcode_info
*find_cooked_opcode
PARAMS ((char **));
58 static unsigned int assemble_ppi
PARAMS ((char *, sh_opcode_info
*));
59 static void little
PARAMS ((int));
60 static void big
PARAMS ((int));
61 static int parse_reg
PARAMS ((char *, int *, int *));
62 static char *parse_exp
PARAMS ((char *, sh_operand_info
*));
63 static char *parse_at
PARAMS ((char *, sh_operand_info
*));
64 static void get_operand
PARAMS ((char **, sh_operand_info
*));
65 static char *get_operands
66 PARAMS ((sh_opcode_info
*, char *, sh_operand_info
*));
67 static sh_opcode_info
*get_specific
68 PARAMS ((sh_opcode_info
*, sh_operand_info
*));
69 static void insert
PARAMS ((char *, int, int, sh_operand_info
*));
70 static void build_relax
PARAMS ((sh_opcode_info
*, sh_operand_info
*));
71 static char *insert_loop_bounds
PARAMS ((char *, sh_operand_info
*));
72 static unsigned int build_Mytes
73 PARAMS ((sh_opcode_info
*, sh_operand_info
*));
74 static bfd_boolean sh_local_pcrel
PARAMS ((fixS
*fix
));
77 static void sh_elf_cons
PARAMS ((int));
79 inline static int sh_PIC_related_p
PARAMS ((symbolS
*));
80 static int sh_check_fixup
PARAMS ((expressionS
*, bfd_reloc_code_real_type
*));
81 inline static char *sh_end_of_match
PARAMS ((char *, char *));
83 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
88 int ignore ATTRIBUTE_UNUSED
;
90 if (! target_big_endian
)
91 as_bad (_("directive .big encountered when option -big required"));
93 /* Stop further messages. */
94 target_big_endian
= 1;
99 int ignore ATTRIBUTE_UNUSED
;
101 if (target_big_endian
)
102 as_bad (_("directive .little encountered when option -little required"));
104 /* Stop further messages. */
105 target_big_endian
= 0;
108 /* This table describes all the machine specific pseudo-ops the assembler
109 has to support. The fields are:
110 pseudo-op name without dot
111 function to call to execute this pseudo-op
112 Integer arg to pass to the function. */
114 const pseudo_typeS md_pseudo_table
[] =
117 {"long", sh_elf_cons
, 4},
118 {"int", sh_elf_cons
, 4},
119 {"word", sh_elf_cons
, 2},
120 {"short", sh_elf_cons
, 2},
126 {"form", listing_psize
, 0},
127 {"little", little
, 0},
128 {"heading", listing_title
, 0},
129 {"import", s_ignore
, 0},
130 {"page", listing_eject
, 0},
131 {"program", s_ignore
, 0},
133 {"uaword", s_uacons
, 2},
134 {"ualong", s_uacons
, 4},
135 {"uaquad", s_uacons
, 8},
136 {"2byte", s_uacons
, 2},
137 {"4byte", s_uacons
, 4},
138 {"8byte", s_uacons
, 8},
140 {"mode", s_sh64_mode
, 0 },
142 /* Have the old name too. */
143 {"isa", s_sh64_mode
, 0 },
145 /* Assert that the right ABI is used. */
146 {"abi", s_sh64_abi
, 0 },
148 { "vtable_inherit", sh64_vtable_inherit
, 0 },
149 { "vtable_entry", sh64_vtable_entry
, 0 },
150 #endif /* HAVE_SH64 */
154 /*int md_reloc_size; */
156 int sh_relax
; /* set if -relax seen */
158 /* Whether -small was seen. */
162 /* preset architecture set, if given; zero otherwise. */
164 static int preset_target_arch
;
166 /* The bit mask of architectures that could
167 accomodate the insns seen so far. */
168 static int valid_arch
;
170 const char EXP_CHARS
[] = "eE";
172 /* Chars that mean this number is a floating point constant. */
175 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
177 #define C(a,b) ENCODE_RELAX(a,b)
179 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
180 #define GET_WHAT(x) ((x>>4))
182 /* These are the three types of relaxable instrction. */
183 /* These are the types of relaxable instructions; except for END which is
186 #define COND_JUMP_DELAY 2
187 #define UNCOND_JUMP 3
191 /* A 16-bit (times four) pc-relative operand, at most expanded to 32 bits. */
192 #define SH64PCREL16_32 4
193 /* A 16-bit (times four) pc-relative operand, at most expanded to 64 bits. */
194 #define SH64PCREL16_64 5
196 /* Variants of the above for adjusting the insn to PTA or PTB according to
198 #define SH64PCREL16PT_32 6
199 #define SH64PCREL16PT_64 7
201 /* A MOVI expansion, expanding to at most 32 or 64 bits. */
202 #define MOVI_IMM_32 8
203 #define MOVI_IMM_32_PCREL 9
204 #define MOVI_IMM_64 10
205 #define MOVI_IMM_64_PCREL 11
208 #else /* HAVE_SH64 */
212 #endif /* HAVE_SH64 */
218 #define UNDEF_WORD_DISP 4
224 #define UNDEF_SH64PCREL 0
225 #define SH64PCREL16 1
226 #define SH64PCREL32 2
227 #define SH64PCREL48 3
228 #define SH64PCREL64 4
229 #define SH64PCRELPLT 5
237 #define MOVI_GOTOFF 6
239 #endif /* HAVE_SH64 */
241 /* Branch displacements are from the address of the branch plus
242 four, thus all minimum and maximum values have 4 added to them. */
245 #define COND8_LENGTH 2
247 /* There is one extra instruction before the branch, so we must add
248 two more bytes to account for it. */
249 #define COND12_F 4100
250 #define COND12_M -4090
251 #define COND12_LENGTH 6
253 #define COND12_DELAY_LENGTH 4
255 /* ??? The minimum and maximum values are wrong, but this does not matter
256 since this relocation type is not supported yet. */
257 #define COND32_F (1<<30)
258 #define COND32_M -(1<<30)
259 #define COND32_LENGTH 14
261 #define UNCOND12_F 4098
262 #define UNCOND12_M -4092
263 #define UNCOND12_LENGTH 2
265 /* ??? The minimum and maximum values are wrong, but this does not matter
266 since this relocation type is not supported yet. */
267 #define UNCOND32_F (1<<30)
268 #define UNCOND32_M -(1<<30)
269 #define UNCOND32_LENGTH 14
272 /* The trivial expansion of a SH64PCREL16 relaxation is just a "PT label,
273 TRd" as is the current insn, so no extra length. Note that the "reach"
274 is calculated from the address *after* that insn, but the offset in the
275 insn is calculated from the beginning of the insn. We also need to
276 take into account the implicit 1 coded as the "A" in PTA when counting
277 forward. If PTB reaches an odd address, we trap that as an error
278 elsewhere, so we don't have to have different relaxation entries. We
279 don't add a one to the negative range, since PTB would then have the
280 farthest backward-reaching value skipped, not generated at relaxation. */
281 #define SH64PCREL16_F (32767 * 4 - 4 + 1)
282 #define SH64PCREL16_M (-32768 * 4 - 4)
283 #define SH64PCREL16_LENGTH 0
285 /* The next step is to change that PT insn into
286 MOVI ((label - datalabel Ln) >> 16) & 65535, R25
287 SHORI (label - datalabel Ln) & 65535, R25
290 which means two extra insns, 8 extra bytes. This is the limit for the
293 The expressions look a bit bad since we have to adjust this to avoid overflow on a
295 #define SH64PCREL32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
296 #define SH64PCREL32_LENGTH (2 * 4)
298 /* Similarly, we just change the MOVI and add a SHORI for the 48-bit
300 #if BFD_HOST_64BIT_LONG
301 /* The "reach" type is long, so we can only do this for a 64-bit-long
303 #define SH64PCREL32_M (((long) -1 << 30) * 2 - 4)
304 #define SH64PCREL48_F ((((long) 1 << 47) - 1) - 4)
305 #define SH64PCREL48_M (((long) -1 << 47) - 4)
306 #define SH64PCREL48_LENGTH (3 * 4)
308 /* If the host does not have 64-bit longs, just make this state identical
309 in reach to the 32-bit state. Note that we have a slightly incorrect
310 reach, but the correct one above will overflow a 32-bit number. */
311 #define SH64PCREL32_M (((long) -1 << 30) * 2)
312 #define SH64PCREL48_F SH64PCREL32_F
313 #define SH64PCREL48_M SH64PCREL32_M
314 #define SH64PCREL48_LENGTH (3 * 4)
315 #endif /* BFD_HOST_64BIT_LONG */
317 /* And similarly for the 64-bit expansion; a MOVI + SHORI + SHORI + SHORI
319 #define SH64PCREL64_LENGTH (4 * 4)
321 /* For MOVI, we make the MOVI + SHORI... expansion you can see in the
322 SH64PCREL expansions. The PCREL one is similar, but the other has no
323 pc-relative reach; it must be fully expanded in
324 shmedia_md_estimate_size_before_relax. */
325 #define MOVI_16_LENGTH 0
326 #define MOVI_16_F (32767 - 4)
327 #define MOVI_16_M (-32768 - 4)
328 #define MOVI_32_LENGTH 4
329 #define MOVI_32_F ((((long) 1 << 30) - 1) * 2 + 1 - 4)
330 #define MOVI_48_LENGTH 8
332 #if BFD_HOST_64BIT_LONG
333 /* The "reach" type is long, so we can only do this for a 64-bit-long
335 #define MOVI_32_M (((long) -1 << 30) * 2 - 4)
336 #define MOVI_48_F ((((long) 1 << 47) - 1) - 4)
337 #define MOVI_48_M (((long) -1 << 47) - 4)
339 /* If the host does not have 64-bit longs, just make this state identical
340 in reach to the 32-bit state. Note that we have a slightly incorrect
341 reach, but the correct one above will overflow a 32-bit number. */
342 #define MOVI_32_M (((long) -1 << 30) * 2)
343 #define MOVI_48_F MOVI_32_F
344 #define MOVI_48_M MOVI_32_M
345 #endif /* BFD_HOST_64BIT_LONG */
347 #define MOVI_64_LENGTH 12
348 #endif /* HAVE_SH64 */
350 #define EMPTY { 0, 0, 0, 0 }
352 const relax_typeS md_relax_table
[C (END
, 0)] = {
353 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
354 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
357 /* C (COND_JUMP, COND8) */
358 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP
, COND12
) },
359 /* C (COND_JUMP, COND12) */
360 { COND12_F
, COND12_M
, COND12_LENGTH
, C (COND_JUMP
, COND32
), },
361 /* C (COND_JUMP, COND32) */
362 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
363 /* C (COND_JUMP, UNDEF_WORD_DISP) */
364 { 0, 0, COND32_LENGTH
, 0, },
366 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
369 /* C (COND_JUMP_DELAY, COND8) */
370 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP_DELAY
, COND12
) },
371 /* C (COND_JUMP_DELAY, COND12) */
372 { COND12_F
, COND12_M
, COND12_DELAY_LENGTH
, C (COND_JUMP_DELAY
, COND32
), },
373 /* C (COND_JUMP_DELAY, COND32) */
374 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
375 /* C (COND_JUMP_DELAY, UNDEF_WORD_DISP) */
376 { 0, 0, COND32_LENGTH
, 0, },
378 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
381 /* C (UNCOND_JUMP, UNCOND12) */
382 { UNCOND12_F
, UNCOND12_M
, UNCOND12_LENGTH
, C (UNCOND_JUMP
, UNCOND32
), },
383 /* C (UNCOND_JUMP, UNCOND32) */
384 { UNCOND32_F
, UNCOND32_M
, UNCOND32_LENGTH
, 0, },
386 /* C (UNCOND_JUMP, UNDEF_WORD_DISP) */
387 { 0, 0, UNCOND32_LENGTH
, 0, },
389 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
392 /* C (SH64PCREL16_32, SH64PCREL16) */
394 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16_32
, SH64PCREL32
) },
395 /* C (SH64PCREL16_32, SH64PCREL32) */
396 { 0, 0, SH64PCREL32_LENGTH
, 0 },
398 /* C (SH64PCREL16_32, SH64PCRELPLT) */
399 { 0, 0, SH64PCREL32_LENGTH
, 0 },
401 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
403 /* C (SH64PCREL16_64, SH64PCREL16) */
405 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16_64
, SH64PCREL32
) },
406 /* C (SH64PCREL16_64, SH64PCREL32) */
407 { SH64PCREL32_F
, SH64PCREL32_M
, SH64PCREL32_LENGTH
, C (SH64PCREL16_64
, SH64PCREL48
) },
408 /* C (SH64PCREL16_64, SH64PCREL48) */
409 { SH64PCREL48_F
, SH64PCREL48_M
, SH64PCREL48_LENGTH
, C (SH64PCREL16_64
, SH64PCREL64
) },
410 /* C (SH64PCREL16_64, SH64PCREL64) */
411 { 0, 0, SH64PCREL64_LENGTH
, 0 },
412 /* C (SH64PCREL16_64, SH64PCRELPLT) */
413 { 0, 0, SH64PCREL64_LENGTH
, 0 },
415 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
417 /* C (SH64PCREL16PT_32, SH64PCREL16) */
419 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16PT_32
, SH64PCREL32
) },
420 /* C (SH64PCREL16PT_32, SH64PCREL32) */
421 { 0, 0, SH64PCREL32_LENGTH
, 0 },
423 /* C (SH64PCREL16PT_32, SH64PCRELPLT) */
424 { 0, 0, SH64PCREL32_LENGTH
, 0 },
426 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
428 /* C (SH64PCREL16PT_64, SH64PCREL16) */
430 { SH64PCREL16_F
, SH64PCREL16_M
, SH64PCREL16_LENGTH
, C (SH64PCREL16PT_64
, SH64PCREL32
) },
431 /* C (SH64PCREL16PT_64, SH64PCREL32) */
435 C (SH64PCREL16PT_64
, SH64PCREL48
) },
436 /* C (SH64PCREL16PT_64, SH64PCREL48) */
437 { SH64PCREL48_F
, SH64PCREL48_M
, SH64PCREL48_LENGTH
, C (SH64PCREL16PT_64
, SH64PCREL64
) },
438 /* C (SH64PCREL16PT_64, SH64PCREL64) */
439 { 0, 0, SH64PCREL64_LENGTH
, 0 },
440 /* C (SH64PCREL16PT_64, SH64PCRELPLT) */
441 { 0, 0, SH64PCREL64_LENGTH
, 0},
443 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
445 /* C (MOVI_IMM_32, UNDEF_MOVI) */
446 { 0, 0, MOVI_32_LENGTH
, 0 },
447 /* C (MOVI_IMM_32, MOVI_16) */
448 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_32
, MOVI_32
) },
449 /* C (MOVI_IMM_32, MOVI_32) */
450 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, 0 },
452 /* C (MOVI_IMM_32, MOVI_GOTOFF) */
453 { 0, 0, MOVI_32_LENGTH
, 0 },
454 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
456 /* C (MOVI_IMM_32_PCREL, MOVI_16) */
458 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_32_PCREL
, MOVI_32
) },
459 /* C (MOVI_IMM_32_PCREL, MOVI_32) */
460 { 0, 0, MOVI_32_LENGTH
, 0 },
462 /* C (MOVI_IMM_32_PCREL, MOVI_PLT) */
463 { 0, 0, MOVI_32_LENGTH
, 0 },
465 /* C (MOVI_IMM_32_PCREL, MOVI_GOTPC) */
466 { 0, 0, MOVI_32_LENGTH
, 0 },
467 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
469 /* C (MOVI_IMM_64, UNDEF_MOVI) */
470 { 0, 0, MOVI_64_LENGTH
, 0 },
471 /* C (MOVI_IMM_64, MOVI_16) */
472 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_64
, MOVI_32
) },
473 /* C (MOVI_IMM_64, MOVI_32) */
474 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, C (MOVI_IMM_64
, MOVI_48
) },
475 /* C (MOVI_IMM_64, MOVI_48) */
476 { MOVI_48_F
, MOVI_48_M
, MOVI_48_LENGTH
, C (MOVI_IMM_64
, MOVI_64
) },
477 /* C (MOVI_IMM_64, MOVI_64) */
478 { 0, 0, MOVI_64_LENGTH
, 0 },
480 /* C (MOVI_IMM_64, MOVI_GOTOFF) */
481 { 0, 0, MOVI_64_LENGTH
, 0 },
482 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
484 /* C (MOVI_IMM_64_PCREL, MOVI_16) */
486 { MOVI_16_F
, MOVI_16_M
, MOVI_16_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_32
) },
487 /* C (MOVI_IMM_64_PCREL, MOVI_32) */
488 { MOVI_32_F
, MOVI_32_M
, MOVI_32_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_48
) },
489 /* C (MOVI_IMM_64_PCREL, MOVI_48) */
490 { MOVI_48_F
, MOVI_48_M
, MOVI_48_LENGTH
, C (MOVI_IMM_64_PCREL
, MOVI_64
) },
491 /* C (MOVI_IMM_64_PCREL, MOVI_64) */
492 { 0, 0, MOVI_64_LENGTH
, 0 },
493 /* C (MOVI_IMM_64_PCREL, MOVI_PLT) */
494 { 0, 0, MOVI_64_LENGTH
, 0 },
496 /* C (MOVI_IMM_64_PCREL, MOVI_GOTPC) */
497 { 0, 0, MOVI_64_LENGTH
, 0 },
498 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
500 #endif /* HAVE_SH64 */
506 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics */
510 /* Determinet whether the symbol needs any kind of PIC relocation. */
513 sh_PIC_related_p (sym
)
521 if (sym
== GOT_symbol
)
525 if (sh_PIC_related_p (*symbol_get_tc (sym
)))
529 exp
= symbol_get_value_expression (sym
);
531 return (exp
->X_op
== O_PIC_reloc
532 || sh_PIC_related_p (exp
->X_add_symbol
)
533 || sh_PIC_related_p (exp
->X_op_symbol
));
536 /* Determine the relocation type to be used to represent the
537 expression, that may be rearranged. */
540 sh_check_fixup (main_exp
, r_type_p
)
541 expressionS
*main_exp
;
542 bfd_reloc_code_real_type
*r_type_p
;
544 expressionS
*exp
= main_exp
;
546 /* This is here for backward-compatibility only. GCC used to generated:
548 f@PLT + . - (.LPCS# + 2)
550 but we'd rather be able to handle this as a PIC-related reference
551 plus/minus a symbol. However, gas' parser gives us:
553 O_subtract (O_add (f@PLT, .), .LPCS#+2)
555 so we attempt to transform this into:
557 O_subtract (f@PLT, O_subtract (.LPCS#+2, .))
559 which we can handle simply below. */
560 if (exp
->X_op
== O_subtract
)
562 if (sh_PIC_related_p (exp
->X_op_symbol
))
565 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
567 if (exp
&& sh_PIC_related_p (exp
->X_op_symbol
))
570 if (exp
&& exp
->X_op
== O_add
571 && sh_PIC_related_p (exp
->X_add_symbol
))
573 symbolS
*sym
= exp
->X_add_symbol
;
575 exp
->X_op
= O_subtract
;
576 exp
->X_add_symbol
= main_exp
->X_op_symbol
;
578 main_exp
->X_op_symbol
= main_exp
->X_add_symbol
;
579 main_exp
->X_add_symbol
= sym
;
581 main_exp
->X_add_number
+= exp
->X_add_number
;
582 exp
->X_add_number
= 0;
587 else if (exp
->X_op
== O_add
&& sh_PIC_related_p (exp
->X_op_symbol
))
590 if (exp
->X_op
== O_symbol
|| exp
->X_op
== O_add
|| exp
->X_op
== O_subtract
)
593 if (exp
->X_add_symbol
594 && (exp
->X_add_symbol
== GOT_symbol
596 && *symbol_get_tc (exp
->X_add_symbol
) == GOT_symbol
)))
600 case BFD_RELOC_SH_IMM_LOW16
:
601 *r_type_p
= BFD_RELOC_SH_GOTPC_LOW16
;
604 case BFD_RELOC_SH_IMM_MEDLOW16
:
605 *r_type_p
= BFD_RELOC_SH_GOTPC_MEDLOW16
;
608 case BFD_RELOC_SH_IMM_MEDHI16
:
609 *r_type_p
= BFD_RELOC_SH_GOTPC_MEDHI16
;
612 case BFD_RELOC_SH_IMM_HI16
:
613 *r_type_p
= BFD_RELOC_SH_GOTPC_HI16
;
617 case BFD_RELOC_UNUSED
:
618 *r_type_p
= BFD_RELOC_SH_GOTPC
;
627 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
629 *r_type_p
= BFD_RELOC_SH_GOTPC
;
633 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
638 if (exp
->X_op
== O_PIC_reloc
)
644 case BFD_RELOC_UNUSED
:
645 *r_type_p
= exp
->X_md
;
648 case BFD_RELOC_SH_IMM_LOW16
:
651 case BFD_RELOC_32_GOTOFF
:
652 *r_type_p
= BFD_RELOC_SH_GOTOFF_LOW16
;
655 case BFD_RELOC_SH_GOTPLT32
:
656 *r_type_p
= BFD_RELOC_SH_GOTPLT_LOW16
;
659 case BFD_RELOC_32_GOT_PCREL
:
660 *r_type_p
= BFD_RELOC_SH_GOT_LOW16
;
663 case BFD_RELOC_32_PLT_PCREL
:
664 *r_type_p
= BFD_RELOC_SH_PLT_LOW16
;
672 case BFD_RELOC_SH_IMM_MEDLOW16
:
675 case BFD_RELOC_32_GOTOFF
:
676 *r_type_p
= BFD_RELOC_SH_GOTOFF_MEDLOW16
;
679 case BFD_RELOC_SH_GOTPLT32
:
680 *r_type_p
= BFD_RELOC_SH_GOTPLT_MEDLOW16
;
683 case BFD_RELOC_32_GOT_PCREL
:
684 *r_type_p
= BFD_RELOC_SH_GOT_MEDLOW16
;
687 case BFD_RELOC_32_PLT_PCREL
:
688 *r_type_p
= BFD_RELOC_SH_PLT_MEDLOW16
;
696 case BFD_RELOC_SH_IMM_MEDHI16
:
699 case BFD_RELOC_32_GOTOFF
:
700 *r_type_p
= BFD_RELOC_SH_GOTOFF_MEDHI16
;
703 case BFD_RELOC_SH_GOTPLT32
:
704 *r_type_p
= BFD_RELOC_SH_GOTPLT_MEDHI16
;
707 case BFD_RELOC_32_GOT_PCREL
:
708 *r_type_p
= BFD_RELOC_SH_GOT_MEDHI16
;
711 case BFD_RELOC_32_PLT_PCREL
:
712 *r_type_p
= BFD_RELOC_SH_PLT_MEDHI16
;
720 case BFD_RELOC_SH_IMM_HI16
:
723 case BFD_RELOC_32_GOTOFF
:
724 *r_type_p
= BFD_RELOC_SH_GOTOFF_HI16
;
727 case BFD_RELOC_SH_GOTPLT32
:
728 *r_type_p
= BFD_RELOC_SH_GOTPLT_HI16
;
731 case BFD_RELOC_32_GOT_PCREL
:
732 *r_type_p
= BFD_RELOC_SH_GOT_HI16
;
735 case BFD_RELOC_32_PLT_PCREL
:
736 *r_type_p
= BFD_RELOC_SH_PLT_HI16
;
748 *r_type_p
= exp
->X_md
;
751 exp
->X_op
= O_symbol
;
754 main_exp
->X_add_symbol
= exp
->X_add_symbol
;
755 main_exp
->X_add_number
+= exp
->X_add_number
;
759 return (sh_PIC_related_p (exp
->X_add_symbol
)
760 || sh_PIC_related_p (exp
->X_op_symbol
));
765 /* Add expression EXP of SIZE bytes to offset OFF of fragment FRAG. */
768 sh_cons_fix_new (frag
, off
, size
, exp
)
773 bfd_reloc_code_real_type r_type
= BFD_RELOC_UNUSED
;
775 if (sh_check_fixup (exp
, &r_type
))
776 as_bad (_("Invalid PIC expression."));
778 if (r_type
== BFD_RELOC_UNUSED
)
782 r_type
= BFD_RELOC_8
;
786 r_type
= BFD_RELOC_16
;
790 r_type
= BFD_RELOC_32
;
795 r_type
= BFD_RELOC_64
;
805 as_bad (_("unsupported BFD relocation size %u"), size
);
806 r_type
= BFD_RELOC_UNUSED
;
809 fix_new_exp (frag
, off
, size
, exp
, 0, r_type
);
812 /* The regular cons() function, that reads constants, doesn't support
813 suffixes such as @GOT, @GOTOFF and @PLT, that generate
814 machine-specific relocation types. So we must define it here. */
815 /* Clobbers input_line_pointer, checks end-of-line. */
818 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
824 /* Update existing range to include a previous insn, if there was one. */
825 sh64_update_contents_mark (TRUE
);
827 /* We need to make sure the contents type is set to data. */
830 #endif /* HAVE_SH64 */
832 if (is_it_end_of_statement ())
834 demand_empty_rest_of_line ();
841 emit_expr (&exp
, (unsigned int) nbytes
);
843 while (*input_line_pointer
++ == ',');
845 input_line_pointer
--; /* Put terminator back into stream. */
846 if (*input_line_pointer
== '#' || *input_line_pointer
== '!')
848 while (! is_end_of_line
[(unsigned char) *input_line_pointer
++]);
851 demand_empty_rest_of_line ();
856 /* This function is called once, at assembler startup time. This should
857 set up all the tables, etc that the MD part of the assembler needs. */
862 const sh_opcode_info
*opcode
;
863 char *prev_name
= "";
867 = preset_target_arch
? preset_target_arch
: arch_sh1_up
& ~arch_sh_dsp_up
;
868 valid_arch
= target_arch
;
874 opcode_hash_control
= hash_new ();
876 /* Insert unique names into hash table. */
877 for (opcode
= sh_table
; opcode
->name
; opcode
++)
879 if (strcmp (prev_name
, opcode
->name
) != 0)
881 if (! (opcode
->arch
& target_arch
))
883 prev_name
= opcode
->name
;
884 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
891 static int reg_x
, reg_y
;
895 #define IDENT_CHAR(c) (ISALNUM (c) || (c) == '_')
897 /* Try to parse a reg name. Return the number of chars consumed. */
900 parse_reg (src
, mode
, reg
)
905 char l0
= TOLOWER (src
[0]);
906 char l1
= l0
? TOLOWER (src
[1]) : 0;
908 /* We use ! IDENT_CHAR for the next character after the register name, to
909 make sure that we won't accidentally recognize a symbol name such as
910 'sram' or sr_ram as being a reference to the register 'sr'. */
916 if (src
[2] >= '0' && src
[2] <= '5'
917 && ! IDENT_CHAR ((unsigned char) src
[3]))
920 *reg
= 10 + src
[2] - '0';
924 if (l1
>= '0' && l1
<= '9'
925 && ! IDENT_CHAR ((unsigned char) src
[2]))
931 if (l1
>= '0' && l1
<= '7' && strncasecmp (&src
[2], "_bank", 5) == 0
932 && ! IDENT_CHAR ((unsigned char) src
[7]))
939 if (l1
== 'e' && ! IDENT_CHAR ((unsigned char) src
[2]))
944 if (l1
== 's' && ! IDENT_CHAR ((unsigned char) src
[2]))
955 if (! IDENT_CHAR ((unsigned char) src
[2]))
961 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
970 if (! IDENT_CHAR ((unsigned char) src
[2]))
976 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
984 if (l1
== 'x' && src
[2] >= '0' && src
[2] <= '1'
985 && ! IDENT_CHAR ((unsigned char) src
[3]))
988 *reg
= 4 + (l1
- '0');
991 if (l1
== 'y' && src
[2] >= '0' && src
[2] <= '1'
992 && ! IDENT_CHAR ((unsigned char) src
[3]))
995 *reg
= 6 + (l1
- '0');
998 if (l1
== 's' && src
[2] >= '0' && src
[2] <= '3'
999 && ! IDENT_CHAR ((unsigned char) src
[3]))
1004 *reg
= n
| ((~n
& 2) << 1);
1009 if (l0
== 'i' && l1
&& ! IDENT_CHAR ((unsigned char) src
[2]))
1031 if (l0
== 'x' && l1
>= '0' && l1
<= '1'
1032 && ! IDENT_CHAR ((unsigned char) src
[2]))
1035 *reg
= A_X0_NUM
+ l1
- '0';
1039 if (l0
== 'y' && l1
>= '0' && l1
<= '1'
1040 && ! IDENT_CHAR ((unsigned char) src
[2]))
1043 *reg
= A_Y0_NUM
+ l1
- '0';
1047 if (l0
== 'm' && l1
>= '0' && l1
<= '1'
1048 && ! IDENT_CHAR ((unsigned char) src
[2]))
1051 *reg
= l1
== '0' ? A_M0_NUM
: A_M1_NUM
;
1057 && TOLOWER (src
[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[3]))
1063 if (l0
== 's' && l1
== 'p' && TOLOWER (src
[2]) == 'c'
1064 && ! IDENT_CHAR ((unsigned char) src
[3]))
1070 if (l0
== 's' && l1
== 'g' && TOLOWER (src
[2]) == 'r'
1071 && ! IDENT_CHAR ((unsigned char) src
[3]))
1077 if (l0
== 'd' && l1
== 's' && TOLOWER (src
[2]) == 'r'
1078 && ! IDENT_CHAR ((unsigned char) src
[3]))
1084 if (l0
== 'd' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1085 && ! IDENT_CHAR ((unsigned char) src
[3]))
1091 if (l0
== 's' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
1097 if (l0
== 's' && l1
== 'p' && ! IDENT_CHAR ((unsigned char) src
[2]))
1104 if (l0
== 'p' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
1109 if (l0
== 'p' && l1
== 'c' && ! IDENT_CHAR ((unsigned char) src
[2]))
1111 /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
1112 and use an uninitialized immediate. */
1116 if (l0
== 'g' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1117 && ! IDENT_CHAR ((unsigned char) src
[3]))
1122 if (l0
== 'v' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
1123 && ! IDENT_CHAR ((unsigned char) src
[3]))
1129 if (l0
== 'm' && l1
== 'a' && TOLOWER (src
[2]) == 'c'
1130 && ! IDENT_CHAR ((unsigned char) src
[4]))
1132 if (TOLOWER (src
[3]) == 'l')
1137 if (TOLOWER (src
[3]) == 'h')
1143 if (l0
== 'm' && l1
== 'o' && TOLOWER (src
[2]) == 'd'
1144 && ! IDENT_CHAR ((unsigned char) src
[3]))
1149 if (l0
== 'f' && l1
== 'r')
1153 if (src
[3] >= '0' && src
[3] <= '5'
1154 && ! IDENT_CHAR ((unsigned char) src
[4]))
1157 *reg
= 10 + src
[3] - '0';
1161 if (src
[2] >= '0' && src
[2] <= '9'
1162 && ! IDENT_CHAR ((unsigned char) src
[3]))
1165 *reg
= (src
[2] - '0');
1169 if (l0
== 'd' && l1
== 'r')
1173 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
1174 && ! IDENT_CHAR ((unsigned char) src
[4]))
1177 *reg
= 10 + 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');
1189 if (l0
== 'x' && l1
== 'd')
1193 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
1194 && ! IDENT_CHAR ((unsigned char) src
[4]))
1197 *reg
= 11 + src
[3] - '0';
1201 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
1202 && ! IDENT_CHAR ((unsigned char) src
[3]))
1205 *reg
= (src
[2] - '0') + 1;
1209 if (l0
== 'f' && l1
== 'v')
1211 if (src
[2] == '1'&& src
[3] == '2' && ! IDENT_CHAR ((unsigned char) src
[4]))
1217 if ((src
[2] == '0' || src
[2] == '4' || src
[2] == '8')
1218 && ! IDENT_CHAR ((unsigned char) src
[3]))
1221 *reg
= (src
[2] - '0');
1225 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 'u'
1226 && TOLOWER (src
[3]) == 'l'
1227 && ! IDENT_CHAR ((unsigned char) src
[4]))
1233 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 's'
1234 && TOLOWER (src
[3]) == 'c'
1235 && TOLOWER (src
[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[5]))
1241 if (l0
== 'x' && l1
== 'm' && TOLOWER (src
[2]) == 't'
1242 && TOLOWER (src
[3]) == 'r'
1243 && TOLOWER (src
[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src
[5]))
1255 sh_operand_info
*op
;
1260 save
= input_line_pointer
;
1261 input_line_pointer
= s
;
1262 expression (&op
->immediate
);
1263 if (op
->immediate
.X_op
== O_absent
)
1264 as_bad (_("missing operand"));
1266 else if (op
->immediate
.X_op
== O_PIC_reloc
1267 || sh_PIC_related_p (op
->immediate
.X_add_symbol
)
1268 || sh_PIC_related_p (op
->immediate
.X_op_symbol
))
1269 as_bad (_("misplaced PIC operand"));
1271 new = input_line_pointer
;
1272 input_line_pointer
= save
;
1276 /* The many forms of operand:
1279 @Rn Register indirect
1292 pr, gbr, vbr, macl, mach
1298 sh_operand_info
*op
;
1305 /* Must be predecrement. */
1308 len
= parse_reg (src
, &mode
, &(op
->reg
));
1309 if (mode
!= A_REG_N
)
1310 as_bad (_("illegal register after @-"));
1315 else if (src
[0] == '(')
1317 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
1320 len
= parse_reg (src
, &mode
, &(op
->reg
));
1321 if (len
&& mode
== A_REG_N
)
1326 as_bad (_("must be @(r0,...)"));
1331 /* Now can be rn or gbr. */
1332 len
= parse_reg (src
, &mode
, &(op
->reg
));
1342 op
->type
= A_R0_GBR
;
1344 else if (mode
== A_REG_N
)
1346 op
->type
= A_IND_R0_REG_N
;
1350 as_bad (_("syntax error in @(r0,...)"));
1355 as_bad (_("syntax error in @(r0...)"));
1360 /* Must be an @(disp,.. thing). */
1361 src
= parse_exp (src
, op
);
1364 /* Now can be rn, gbr or pc. */
1365 len
= parse_reg (src
, &mode
, &op
->reg
);
1368 if (mode
== A_REG_N
)
1370 op
->type
= A_DISP_REG_N
;
1372 else if (mode
== A_GBR
)
1374 op
->type
= A_DISP_GBR
;
1376 else if (mode
== A_PC
)
1378 /* We want @(expr, pc) to uniformly address . + expr,
1379 no matter if expr is a constant, or a more complex
1380 expression, e.g. sym-. or sym1-sym2.
1381 However, we also used to accept @(sym,pc)
1382 as adressing sym, i.e. meaning the same as plain sym.
1383 Some existing code does use the @(sym,pc) syntax, so
1384 we give it the old semantics for now, but warn about
1385 its use, so that users have some time to fix their code.
1387 Note that due to this backward compatibility hack,
1388 we'll get unexpected results when @(offset, pc) is used,
1389 and offset is a symbol that is set later to an an address
1390 difference, or an external symbol that is set to an
1391 address difference in another source file, so we want to
1392 eventually remove it. */
1393 if (op
->immediate
.X_op
== O_symbol
)
1395 op
->type
= A_DISP_PC
;
1396 as_warn (_("Deprecated syntax."));
1400 op
->type
= A_DISP_PC_ABS
;
1401 /* Such operands don't get corrected for PC==.+4, so
1402 make the correction here. */
1403 op
->immediate
.X_add_number
-= 4;
1408 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1413 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1418 as_bad (_("expecting )"));
1424 src
+= parse_reg (src
, &mode
, &(op
->reg
));
1425 if (mode
!= A_REG_N
)
1426 as_bad (_("illegal register after @"));
1433 l0
= TOLOWER (src
[0]);
1434 l1
= TOLOWER (src
[1]);
1436 if ((l0
== 'r' && l1
== '8')
1437 || (l0
== 'i' && (l1
== 'x' || l1
== 's')))
1440 op
->type
= A_PMOD_N
;
1442 else if ( (l0
== 'r' && l1
== '9')
1443 || (l0
== 'i' && l1
== 'y'))
1446 op
->type
= A_PMODY_N
;
1458 get_operand (ptr
, op
)
1460 sh_operand_info
*op
;
1469 *ptr
= parse_exp (src
, op
);
1474 else if (src
[0] == '@')
1476 *ptr
= parse_at (src
, op
);
1479 len
= parse_reg (src
, &mode
, &(op
->reg
));
1488 /* Not a reg, the only thing left is a displacement. */
1489 *ptr
= parse_exp (src
, op
);
1490 op
->type
= A_DISP_PC
;
1496 get_operands (info
, args
, operand
)
1497 sh_opcode_info
*info
;
1499 sh_operand_info
*operand
;
1504 /* The pre-processor will eliminate whitespace in front of '@'
1505 after the first argument; we may be called multiple times
1506 from assemble_ppi, so don't insist on finding whitespace here. */
1510 get_operand (&ptr
, operand
+ 0);
1517 get_operand (&ptr
, operand
+ 1);
1518 /* ??? Hack: psha/pshl have a varying operand number depending on
1519 the type of the first operand. We handle this by having the
1520 three-operand version first and reducing the number of operands
1521 parsed to two if we see that the first operand is an immediate.
1522 This works because no insn with three operands has an immediate
1523 as first operand. */
1524 if (info
->arg
[2] && operand
[0].type
!= A_IMM
)
1530 get_operand (&ptr
, operand
+ 2);
1534 operand
[2].type
= 0;
1539 operand
[1].type
= 0;
1540 operand
[2].type
= 0;
1545 operand
[0].type
= 0;
1546 operand
[1].type
= 0;
1547 operand
[2].type
= 0;
1552 /* Passed a pointer to a list of opcodes which use different
1553 addressing modes, return the opcode which matches the opcodes
1556 static sh_opcode_info
*
1557 get_specific (opcode
, operands
)
1558 sh_opcode_info
*opcode
;
1559 sh_operand_info
*operands
;
1561 sh_opcode_info
*this_try
= opcode
;
1562 char *name
= opcode
->name
;
1565 while (opcode
->name
)
1567 this_try
= opcode
++;
1568 if ((this_try
->name
!= name
) && (strcmp (this_try
->name
, name
) != 0))
1570 /* We've looked so far down the table that we've run out of
1571 opcodes with the same name. */
1575 /* Look at both operands needed by the opcodes and provided by
1576 the user - since an arg test will often fail on the same arg
1577 again and again, we'll try and test the last failing arg the
1578 first on each opcode try. */
1579 for (n
= 0; this_try
->arg
[n
]; n
++)
1581 sh_operand_info
*user
= operands
+ n
;
1582 sh_arg_type arg
= this_try
->arg
[n
];
1587 if (user
->type
== A_DISP_PC_ABS
)
1597 if (user
->type
!= arg
)
1601 /* opcode needs r0 */
1602 if (user
->type
!= A_REG_N
|| user
->reg
!= 0)
1606 if (user
->type
!= A_R0_GBR
|| user
->reg
!= 0)
1610 if (user
->type
!= F_REG_N
|| user
->reg
!= 0)
1618 case A_IND_R0_REG_N
:
1629 /* Opcode needs rn */
1630 if (user
->type
!= arg
)
1635 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1650 if (user
->type
!= arg
)
1655 if (user
->type
!= arg
)
1664 case A_IND_R0_REG_M
:
1667 /* Opcode needs rn */
1668 if (user
->type
!= arg
- A_REG_M
+ A_REG_N
)
1674 if (user
->type
!= DSP_REG_N
)
1696 if (user
->type
!= DSP_REG_N
)
1718 if (user
->type
!= DSP_REG_N
)
1740 if (user
->type
!= DSP_REG_N
)
1762 if (user
->type
!= DSP_REG_N
)
1784 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_A0_NUM
)
1788 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X0_NUM
)
1792 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X1_NUM
)
1796 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y0_NUM
)
1800 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y1_NUM
)
1810 /* Opcode needs rn */
1811 if (user
->type
!= arg
- F_REG_M
+ F_REG_N
)
1816 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1821 if (user
->type
!= XMTRX_M4
)
1827 printf (_("unhandled %d\n"), arg
);
1831 if ( !(valid_arch
& this_try
->arch
))
1833 valid_arch
&= this_try
->arch
;
1843 insert (where
, how
, pcrel
, op
)
1847 sh_operand_info
*op
;
1849 fix_new_exp (frag_now
,
1850 where
- frag_now
->fr_literal
,
1858 build_relax (opcode
, op
)
1859 sh_opcode_info
*opcode
;
1860 sh_operand_info
*op
;
1862 int high_byte
= target_big_endian
? 0 : 1;
1865 if (opcode
->arg
[0] == A_BDISP8
)
1867 int what
= (opcode
->nibbles
[1] & 4) ? COND_JUMP_DELAY
: COND_JUMP
;
1868 p
= frag_var (rs_machine_dependent
,
1869 md_relax_table
[C (what
, COND32
)].rlx_length
,
1870 md_relax_table
[C (what
, COND8
)].rlx_length
,
1872 op
->immediate
.X_add_symbol
,
1873 op
->immediate
.X_add_number
,
1875 p
[high_byte
] = (opcode
->nibbles
[0] << 4) | (opcode
->nibbles
[1]);
1877 else if (opcode
->arg
[0] == A_BDISP12
)
1879 p
= frag_var (rs_machine_dependent
,
1880 md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
,
1881 md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
,
1883 op
->immediate
.X_add_symbol
,
1884 op
->immediate
.X_add_number
,
1886 p
[high_byte
] = (opcode
->nibbles
[0] << 4);
1891 /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
1894 insert_loop_bounds (output
, operand
)
1896 sh_operand_info
*operand
;
1901 /* Since the low byte of the opcode will be overwritten by the reloc, we
1902 can just stash the high byte into both bytes and ignore endianness. */
1905 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1906 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1910 static int count
= 0;
1912 /* If the last loop insn is a two-byte-insn, it is in danger of being
1913 swapped with the insn after it. To prevent this, create a new
1914 symbol - complete with SH_LABEL reloc - after the last loop insn.
1915 If the last loop insn is four bytes long, the symbol will be
1916 right in the middle, but four byte insns are not swapped anyways. */
1917 /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
1918 Hence a 9 digit number should be enough to count all REPEATs. */
1920 sprintf (name
, "_R%x", count
++ & 0x3fffffff);
1921 end_sym
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1922 /* Make this a local symbol. */
1924 SF_SET_LOCAL (end_sym
);
1925 #endif /* OBJ_COFF */
1926 symbol_table_insert (end_sym
);
1927 end_sym
->sy_value
= operand
[1].immediate
;
1928 end_sym
->sy_value
.X_add_number
+= 2;
1929 fix_new (frag_now
, frag_now_fix (), 2, end_sym
, 0, 1, BFD_RELOC_SH_LABEL
);
1932 output
= frag_more (2);
1935 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1936 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1938 return frag_more (2);
1941 /* Now we know what sort of opcodes it is, let's build the bytes. */
1944 build_Mytes (opcode
, operand
)
1945 sh_opcode_info
*opcode
;
1946 sh_operand_info
*operand
;
1950 char *output
= frag_more (2);
1951 unsigned int size
= 2;
1952 int low_byte
= target_big_endian
? 1 : 0;
1958 for (index
= 0; index
< 4; index
++)
1960 sh_nibble_type i
= opcode
->nibbles
[index
];
1970 nbuf
[index
] = reg_n
;
1973 nbuf
[index
] = reg_m
;
1976 if (reg_n
< 2 || reg_n
> 5)
1977 as_bad (_("Invalid register: 'r%d'"), reg_n
);
1978 nbuf
[index
] = (reg_n
& 3) | 4;
1981 nbuf
[index
] = reg_n
| (reg_m
>> 2);
1984 nbuf
[index
] = reg_b
| 0x08;
1987 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
);
1990 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
);
1993 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
);
1996 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
+ 1);
1999 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
+ 1);
2002 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
+ 1);
2005 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
);
2008 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
);
2011 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
);
2014 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
+ 1);
2017 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
+ 1);
2020 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
+ 1);
2023 insert (output
, BFD_RELOC_SH_PCRELIMM8BY4
,
2024 operand
->type
!= A_DISP_PC_ABS
, operand
);
2027 insert (output
, BFD_RELOC_SH_PCRELIMM8BY2
,
2028 operand
->type
!= A_DISP_PC_ABS
, operand
);
2031 output
= insert_loop_bounds (output
, operand
);
2032 nbuf
[index
] = opcode
->nibbles
[3];
2036 printf (_("failed for %d\n"), i
);
2040 if (!target_big_endian
)
2042 output
[1] = (nbuf
[0] << 4) | (nbuf
[1]);
2043 output
[0] = (nbuf
[2] << 4) | (nbuf
[3]);
2047 output
[0] = (nbuf
[0] << 4) | (nbuf
[1]);
2048 output
[1] = (nbuf
[2] << 4) | (nbuf
[3]);
2053 /* Find an opcode at the start of *STR_P in the hash table, and set
2054 *STR_P to the first character after the last one read. */
2056 static sh_opcode_info
*
2057 find_cooked_opcode (str_p
)
2061 unsigned char *op_start
;
2062 unsigned char *op_end
;
2066 /* Drop leading whitespace. */
2070 /* Find the op code end.
2071 The pre-processor will eliminate whitespace in front of
2072 any '@' after the first argument; we may be called from
2073 assemble_ppi, so the opcode might be terminated by an '@'. */
2074 for (op_start
= op_end
= (unsigned char *) (str
);
2077 && !is_end_of_line
[*op_end
] && *op_end
!= ' ' && *op_end
!= '@';
2080 unsigned char c
= op_start
[nlen
];
2082 /* The machine independent code will convert CMP/EQ into cmp/EQ
2083 because it thinks the '/' is the end of the symbol. Moreover,
2084 all but the first sub-insn is a parallel processing insn won't
2085 be capitalized. Instead of hacking up the machine independent
2086 code, we just deal with it here. */
2096 as_bad (_("can't find opcode "));
2098 return (sh_opcode_info
*) hash_find (opcode_hash_control
, name
);
2101 /* Assemble a parallel processing insn. */
2102 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
2105 assemble_ppi (op_end
, opcode
)
2107 sh_opcode_info
*opcode
;
2119 sh_operand_info operand
[3];
2121 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
2122 Make sure we encode a defined insn pattern. */
2127 if (opcode
->arg
[0] != A_END
)
2128 op_end
= get_operands (opcode
, op_end
, operand
);
2129 opcode
= get_specific (opcode
, operand
);
2132 /* Couldn't find an opcode which matched the operands. */
2133 char *where
= frag_more (2);
2138 as_bad (_("invalid operands for opcode"));
2142 if (opcode
->nibbles
[0] != PPI
)
2143 as_bad (_("insn can't be combined with parallel processing insn"));
2145 switch (opcode
->nibbles
[1])
2150 as_bad (_("multiple movx specifications"));
2155 as_bad (_("multiple movy specifications"));
2161 as_bad (_("multiple movx specifications"));
2162 if (reg_n
< 4 || reg_n
> 5)
2163 as_bad (_("invalid movx address register"));
2164 if (opcode
->nibbles
[2] & 8)
2166 if (reg_m
== A_A1_NUM
)
2168 else if (reg_m
!= A_A0_NUM
)
2169 as_bad (_("invalid movx dsp register"));
2174 as_bad (_("invalid movx dsp register"));
2177 movx
+= ((reg_n
- 4) << 9) + (opcode
->nibbles
[2] << 2) + DDT_BASE
;
2182 as_bad (_("multiple movy specifications"));
2183 if (opcode
->nibbles
[2] & 8)
2185 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
2188 if (reg_m
== A_A1_NUM
)
2190 else if (reg_m
!= A_A0_NUM
)
2191 as_bad (_("invalid movy dsp register"));
2196 as_bad (_("invalid movy dsp register"));
2199 if (reg_n
< 6 || reg_n
> 7)
2200 as_bad (_("invalid movy address register"));
2201 movy
+= ((reg_n
- 6) << 8) + opcode
->nibbles
[2] + DDT_BASE
;
2205 if (operand
[0].immediate
.X_op
!= O_constant
)
2206 as_bad (_("dsp immediate shift value not constant"));
2207 field_b
= ((opcode
->nibbles
[2] << 12)
2208 | (operand
[0].immediate
.X_add_number
& 127) << 4
2213 as_bad (_("multiple parallel processing specifications"));
2214 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2215 + (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2219 as_bad (_("multiple condition specifications"));
2220 cond
= opcode
->nibbles
[2] << 8;
2222 goto skip_cond_check
;
2226 as_bad (_("multiple parallel processing specifications"));
2227 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2228 + cond
+ (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2234 if ((field_b
& 0xef00) != 0xa100)
2235 as_bad (_("insn cannot be combined with pmuls"));
2237 switch (field_b
& 0xf)
2240 field_b
+= 0 - A_X0_NUM
;
2243 field_b
+= 1 - A_Y0_NUM
;
2246 field_b
+= 2 - A_A0_NUM
;
2249 field_b
+= 3 - A_A1_NUM
;
2252 as_bad (_("bad padd / psub pmuls output operand"));
2254 /* Generate warning if the destination register for padd / psub
2255 and pmuls is the same ( only for A0 or A1 ).
2256 If the last nibble is 1010 then A0 is used in both
2257 padd / psub and pmuls. If it is 1111 then A1 is used
2258 as destination register in both padd / psub and pmuls. */
2260 if ((((field_b
| reg_efg
) & 0x000F) == 0x000A)
2261 || (((field_b
| reg_efg
) & 0x000F) == 0x000F))
2262 as_warn (_("destination register is same for parallel insns"));
2264 field_b
+= 0x4000 + reg_efg
;
2271 as_bad (_("condition not followed by conditionalizable insn"));
2277 opcode
= find_cooked_opcode (&op_end
);
2281 (_("unrecognized characters at end of parallel processing insn")));
2286 move_code
= movx
| movy
;
2289 /* Parallel processing insn. */
2290 unsigned long ppi_code
= (movx
| movy
| 0xf800) << 16 | field_b
;
2292 output
= frag_more (4);
2294 if (! target_big_endian
)
2296 output
[3] = ppi_code
>> 8;
2297 output
[2] = ppi_code
;
2301 output
[2] = ppi_code
>> 8;
2302 output
[3] = ppi_code
;
2304 move_code
|= 0xf800;
2308 /* Just a double data transfer. */
2309 output
= frag_more (2);
2312 if (! target_big_endian
)
2314 output
[1] = move_code
>> 8;
2315 output
[0] = move_code
;
2319 output
[0] = move_code
>> 8;
2320 output
[1] = move_code
;
2325 /* This is the guts of the machine-dependent assembler. STR points to a
2326 machine dependent instruction. This function is supposed to emit
2327 the frags/bytes it assembles to. */
2333 unsigned char *op_end
;
2334 sh_operand_info operand
[3];
2335 sh_opcode_info
*opcode
;
2336 unsigned int size
= 0;
2339 if (sh64_isa_mode
== sh64_isa_shmedia
)
2341 shmedia_md_assemble (str
);
2346 /* If we've seen pseudo-directives, make sure any emitted data or
2347 frags are marked as data. */
2350 sh64_update_contents_mark (TRUE
);
2351 sh64_set_contents_type (CRT_SH5_ISA16
);
2356 #endif /* HAVE_SH64 */
2358 opcode
= find_cooked_opcode (&str
);
2363 as_bad (_("unknown opcode"));
2368 && ! seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2370 /* Output a CODE reloc to tell the linker that the following
2371 bytes are instructions, not data. */
2372 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2374 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 1;
2377 if (opcode
->nibbles
[0] == PPI
)
2379 size
= assemble_ppi (op_end
, opcode
);
2383 if (opcode
->arg
[0] == A_BDISP12
2384 || opcode
->arg
[0] == A_BDISP8
)
2386 parse_exp (op_end
+ 1, &operand
[0]);
2387 build_relax (opcode
, &operand
[0]);
2391 if (opcode
->arg
[0] == A_END
)
2393 /* Ignore trailing whitespace. If there is any, it has already
2394 been compressed to a single space. */
2400 op_end
= get_operands (opcode
, op_end
, operand
);
2402 opcode
= get_specific (opcode
, operand
);
2406 /* Couldn't find an opcode which matched the operands. */
2407 char *where
= frag_more (2);
2412 as_bad (_("invalid operands for opcode"));
2417 as_bad (_("excess operands: '%s'"), op_end
);
2419 size
= build_Mytes (opcode
, operand
);
2424 #ifdef BFD_ASSEMBLER
2425 dwarf2_emit_insn (size
);
2429 /* This routine is called each time a label definition is seen. It
2430 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
2435 static fragS
*last_label_frag
;
2436 static int last_label_offset
;
2439 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2443 offset
= frag_now_fix ();
2444 if (frag_now
!= last_label_frag
2445 || offset
!= last_label_offset
)
2447 fix_new (frag_now
, offset
, 2, &abs_symbol
, 0, 0, BFD_RELOC_SH_LABEL
);
2448 last_label_frag
= frag_now
;
2449 last_label_offset
= offset
;
2454 /* This routine is called when the assembler is about to output some
2455 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
2458 sh_flush_pending_output ()
2461 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2463 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2465 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 0;
2470 md_undefined_symbol (name
)
2471 char *name ATTRIBUTE_UNUSED
;
2477 #ifndef BFD_ASSEMBLER
2480 tc_crawl_symbol_chain (headers
)
2481 object_headers
*headers ATTRIBUTE_UNUSED
;
2483 printf (_("call to tc_crawl_symbol_chain \n"));
2487 tc_headers_hook (headers
)
2488 object_headers
*headers ATTRIBUTE_UNUSED
;
2490 printf (_("call to tc_headers_hook \n"));
2496 /* Various routines to kill one day. */
2497 /* Equal to MAX_PRECISION in atof-ieee.c. */
2498 #define MAX_LITTLENUMS 6
2500 /* Turn a string in input_line_pointer into a floating point constant
2501 of type TYPE, and store the appropriate bytes in *LITP. The number
2502 of LITTLENUMS emitted is stored in *SIZEP . An error message is
2503 returned, or NULL on OK. */
2506 md_atof (type
, litP
, sizeP
)
2512 LITTLENUM_TYPE words
[4];
2528 return _("bad call to md_atof");
2531 t
= atof_ieee (input_line_pointer
, type
, words
);
2533 input_line_pointer
= t
;
2537 if (! target_big_endian
)
2539 for (i
= prec
- 1; i
>= 0; i
--)
2541 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2547 for (i
= 0; i
< prec
; i
++)
2549 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2557 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
2558 call instruction. It refers to a label of the instruction which
2559 loads the register which the call uses. We use it to generate a
2560 special reloc for the linker. */
2564 int ignore ATTRIBUTE_UNUSED
;
2569 as_warn (_(".uses pseudo-op seen when not relaxing"));
2573 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
2575 as_bad (_("bad .uses format"));
2576 ignore_rest_of_line ();
2580 fix_new_exp (frag_now
, frag_now_fix (), 2, &ex
, 1, BFD_RELOC_SH_USES
);
2582 demand_empty_rest_of_line ();
2585 const char *md_shortopts
= "";
2586 struct option md_longopts
[] =
2588 #define OPTION_RELAX (OPTION_MD_BASE)
2589 #define OPTION_BIG (OPTION_MD_BASE + 1)
2590 #define OPTION_LITTLE (OPTION_BIG + 1)
2591 #define OPTION_SMALL (OPTION_LITTLE + 1)
2592 #define OPTION_DSP (OPTION_SMALL + 1)
2593 #define OPTION_ISA (OPTION_DSP + 1)
2595 {"relax", no_argument
, NULL
, OPTION_RELAX
},
2596 {"big", no_argument
, NULL
, OPTION_BIG
},
2597 {"little", no_argument
, NULL
, OPTION_LITTLE
},
2598 {"small", no_argument
, NULL
, OPTION_SMALL
},
2599 {"dsp", no_argument
, NULL
, OPTION_DSP
},
2600 {"isa", required_argument
, NULL
, OPTION_ISA
},
2602 #define OPTION_ABI (OPTION_ISA + 1)
2603 #define OPTION_NO_MIX (OPTION_ABI + 1)
2604 #define OPTION_SHCOMPACT_CONST_CRANGE (OPTION_NO_MIX + 1)
2605 #define OPTION_NO_EXPAND (OPTION_SHCOMPACT_CONST_CRANGE + 1)
2606 #define OPTION_PT32 (OPTION_NO_EXPAND + 1)
2607 {"abi", required_argument
, NULL
, OPTION_ABI
},
2608 {"no-mix", no_argument
, NULL
, OPTION_NO_MIX
},
2609 {"shcompact-const-crange", no_argument
, NULL
, OPTION_SHCOMPACT_CONST_CRANGE
},
2610 {"no-expand", no_argument
, NULL
, OPTION_NO_EXPAND
},
2611 {"expand-pt32", no_argument
, NULL
, OPTION_PT32
},
2612 #endif /* HAVE_SH64 */
2614 {NULL
, no_argument
, NULL
, 0}
2616 size_t md_longopts_size
= sizeof (md_longopts
);
2619 md_parse_option (c
, arg
)
2621 char *arg ATTRIBUTE_UNUSED
;
2630 target_big_endian
= 1;
2634 target_big_endian
= 0;
2642 preset_target_arch
= arch_sh1_up
& ~arch_sh3e_up
;
2646 if (strcasecmp (arg
, "sh4") == 0)
2647 preset_target_arch
= arch_sh4
;
2648 else if (strcasecmp (arg
, "any") == 0)
2649 preset_target_arch
= arch_sh1_up
;
2651 else if (strcasecmp (arg
, "shmedia") == 0)
2653 if (sh64_isa_mode
== sh64_isa_shcompact
)
2654 as_bad (_("Invalid combination: --isa=SHcompact with --isa=SHmedia"));
2655 sh64_isa_mode
= sh64_isa_shmedia
;
2657 else if (strcasecmp (arg
, "shcompact") == 0)
2659 if (sh64_isa_mode
== sh64_isa_shmedia
)
2660 as_bad (_("Invalid combination: --isa=SHmedia with --isa=SHcompact"));
2661 if (sh64_abi
== sh64_abi_64
)
2662 as_bad (_("Invalid combination: --abi=64 with --isa=SHcompact"));
2663 sh64_isa_mode
= sh64_isa_shcompact
;
2665 #endif /* HAVE_SH64 */
2667 as_bad ("Invalid argument to --isa option: %s", arg
);
2672 if (strcmp (arg
, "32") == 0)
2674 if (sh64_abi
== sh64_abi_64
)
2675 as_bad (_("Invalid combination: --abi=32 with --abi=64"));
2676 sh64_abi
= sh64_abi_32
;
2678 else if (strcmp (arg
, "64") == 0)
2680 if (sh64_abi
== sh64_abi_32
)
2681 as_bad (_("Invalid combination: --abi=64 with --abi=32"));
2682 if (sh64_isa_mode
== sh64_isa_shcompact
)
2683 as_bad (_("Invalid combination: --isa=SHcompact with --abi=64"));
2684 sh64_abi
= sh64_abi_64
;
2687 as_bad ("Invalid argument to --abi option: %s", arg
);
2694 case OPTION_SHCOMPACT_CONST_CRANGE
:
2695 sh64_shcompact_const_crange
= TRUE
;
2698 case OPTION_NO_EXPAND
:
2699 sh64_expand
= FALSE
;
2705 #endif /* HAVE_SH64 */
2715 md_show_usage (stream
)
2718 fprintf (stream
, _("\
2720 -little generate little endian code\n\
2721 -big generate big endian code\n\
2722 -relax alter jump instructions for long displacements\n\
2723 -small align sections to 4 byte boundaries, not 16\n\
2724 -dsp enable sh-dsp insns, and disable sh2e/sh3e/sh4 insns.\n"));
2726 fprintf (stream
, _("\
2727 -isa=[shmedia set default instruction set for SH64\n\
2731 -abi=[32|64] set size of expanded SHmedia operands and object\n\
2733 -shcompact-const-crange emit code-range descriptors for constants in\n\
2734 SHcompact code sections\n\
2735 -no-mix disallow SHmedia code in the same section as\n\
2736 constants and SHcompact code\n\
2737 -no-expand do not expand MOVI, PT, PTA or PTB instructions\n\
2738 -expand-pt32 with -abi=64, expand PT, PTA and PTB instructions\n\
2740 #endif /* HAVE_SH64 */
2743 /* This struct is used to pass arguments to sh_count_relocs through
2744 bfd_map_over_sections. */
2746 struct sh_count_relocs
2748 /* Symbol we are looking for. */
2750 /* Count of relocs found. */
2754 /* Count the number of fixups in a section which refer to a particular
2755 symbol. When using BFD_ASSEMBLER, this is called via
2756 bfd_map_over_sections. */
2759 sh_count_relocs (abfd
, sec
, data
)
2760 bfd
*abfd ATTRIBUTE_UNUSED
;
2764 struct sh_count_relocs
*info
= (struct sh_count_relocs
*) data
;
2765 segment_info_type
*seginfo
;
2769 seginfo
= seg_info (sec
);
2770 if (seginfo
== NULL
)
2774 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2776 if (fix
->fx_addsy
== sym
)
2784 /* Handle the count relocs for a particular section. When using
2785 BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
2788 sh_frob_section (abfd
, sec
, ignore
)
2789 bfd
*abfd ATTRIBUTE_UNUSED
;
2791 PTR ignore ATTRIBUTE_UNUSED
;
2793 segment_info_type
*seginfo
;
2796 seginfo
= seg_info (sec
);
2797 if (seginfo
== NULL
)
2800 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2805 struct sh_count_relocs info
;
2807 if (fix
->fx_r_type
!= BFD_RELOC_SH_USES
)
2810 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
2811 symbol in the same section. */
2812 sym
= fix
->fx_addsy
;
2814 || fix
->fx_subsy
!= NULL
2815 || fix
->fx_addnumber
!= 0
2816 || S_GET_SEGMENT (sym
) != sec
2817 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2818 || S_GET_STORAGE_CLASS (sym
) == C_EXT
2820 || S_IS_EXTERNAL (sym
))
2822 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2823 _(".uses does not refer to a local symbol in the same section"));
2827 /* Look through the fixups again, this time looking for one
2828 at the same location as sym. */
2829 val
= S_GET_VALUE (sym
);
2830 for (fscan
= seginfo
->fix_root
;
2832 fscan
= fscan
->fx_next
)
2833 if (val
== fscan
->fx_frag
->fr_address
+ fscan
->fx_where
2834 && fscan
->fx_r_type
!= BFD_RELOC_SH_ALIGN
2835 && fscan
->fx_r_type
!= BFD_RELOC_SH_CODE
2836 && fscan
->fx_r_type
!= BFD_RELOC_SH_DATA
2837 && fscan
->fx_r_type
!= BFD_RELOC_SH_LABEL
)
2841 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2842 _("can't find fixup pointed to by .uses"));
2846 if (fscan
->fx_tcbit
)
2848 /* We've already done this one. */
2852 /* The variable fscan should also be a fixup to a local symbol
2853 in the same section. */
2854 sym
= fscan
->fx_addsy
;
2856 || fscan
->fx_subsy
!= NULL
2857 || fscan
->fx_addnumber
!= 0
2858 || S_GET_SEGMENT (sym
) != sec
2859 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2860 || S_GET_STORAGE_CLASS (sym
) == C_EXT
2862 || S_IS_EXTERNAL (sym
))
2864 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2865 _(".uses target does not refer to a local symbol in the same section"));
2869 /* Now we look through all the fixups of all the sections,
2870 counting the number of times we find a reference to sym. */
2873 #ifdef BFD_ASSEMBLER
2874 bfd_map_over_sections (stdoutput
, sh_count_relocs
, (PTR
) &info
);
2879 for (iscan
= SEG_E0
; iscan
< SEG_UNKNOWN
; iscan
++)
2880 sh_count_relocs ((bfd
*) NULL
, iscan
, (PTR
) &info
);
2887 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
2888 We have already adjusted the value of sym to include the
2889 fragment address, so we undo that adjustment here. */
2890 subseg_change (sec
, 0);
2891 fix_new (fscan
->fx_frag
,
2892 S_GET_VALUE (sym
) - fscan
->fx_frag
->fr_address
,
2893 4, &abs_symbol
, info
.count
, 0, BFD_RELOC_SH_COUNT
);
2897 /* This function is called after the symbol table has been completed,
2898 but before the relocs or section contents have been written out.
2899 If we have seen any .uses pseudo-ops, they point to an instruction
2900 which loads a register with the address of a function. We look
2901 through the fixups to find where the function address is being
2902 loaded from. We then generate a COUNT reloc giving the number of
2903 times that function address is referred to. The linker uses this
2904 information when doing relaxing, to decide when it can eliminate
2905 the stored function address entirely. */
2911 shmedia_frob_file_before_adjust ();
2917 #ifdef BFD_ASSEMBLER
2918 bfd_map_over_sections (stdoutput
, sh_frob_section
, (PTR
) NULL
);
2923 for (iseg
= SEG_E0
; iseg
< SEG_UNKNOWN
; iseg
++)
2924 sh_frob_section ((bfd
*) NULL
, iseg
, (PTR
) NULL
);
2929 /* Called after relaxing. Set the correct sizes of the fragments, and
2930 create relocs so that md_apply_fix3 will fill in the correct values. */
2933 md_convert_frag (headers
, seg
, fragP
)
2934 #ifdef BFD_ASSEMBLER
2935 bfd
*headers ATTRIBUTE_UNUSED
;
2937 object_headers
*headers ATTRIBUTE_UNUSED
;
2944 switch (fragP
->fr_subtype
)
2946 case C (COND_JUMP
, COND8
):
2947 case C (COND_JUMP_DELAY
, COND8
):
2948 subseg_change (seg
, 0);
2949 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
2950 1, BFD_RELOC_SH_PCDISP8BY2
);
2955 case C (UNCOND_JUMP
, UNCOND12
):
2956 subseg_change (seg
, 0);
2957 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
2958 1, BFD_RELOC_SH_PCDISP12BY2
);
2963 case C (UNCOND_JUMP
, UNCOND32
):
2964 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
2965 if (fragP
->fr_symbol
== NULL
)
2966 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2967 _("displacement overflows 12-bit field"));
2968 else if (S_IS_DEFINED (fragP
->fr_symbol
))
2969 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2970 _("displacement to defined symbol %s overflows 12-bit field"),
2971 S_GET_NAME (fragP
->fr_symbol
));
2973 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2974 _("displacement to undefined symbol %s overflows 12-bit field"),
2975 S_GET_NAME (fragP
->fr_symbol
));
2976 /* Stabilize this frag, so we don't trip an assert. */
2977 fragP
->fr_fix
+= fragP
->fr_var
;
2981 case C (COND_JUMP
, COND12
):
2982 case C (COND_JUMP_DELAY
, COND12
):
2983 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
2984 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
2985 was due to gas incorrectly relaxing an out-of-range conditional
2986 branch with delay slot. It turned:
2987 bf.s L6 (slot mov.l r12,@(44,r0))
2990 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
2992 32: 10 cb mov.l r12,@(44,r0)
2993 Therefore, branches with delay slots have to be handled
2994 differently from ones without delay slots. */
2996 unsigned char *buffer
=
2997 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
2998 int highbyte
= target_big_endian
? 0 : 1;
2999 int lowbyte
= target_big_endian
? 1 : 0;
3000 int delay
= fragP
->fr_subtype
== C (COND_JUMP_DELAY
, COND12
);
3002 /* Toggle the true/false bit of the bcond. */
3003 buffer
[highbyte
] ^= 0x2;
3005 /* If this is a delayed branch, we may not put the bra in the
3006 slot. So we change it to a non-delayed branch, like that:
3007 b! cond slot_label; bra disp; slot_label: slot_insn
3008 ??? We should try if swapping the conditional branch and
3009 its delay-slot insn already makes the branch reach. */
3011 /* Build a relocation to six / four bytes farther on. */
3012 subseg_change (seg
, 0);
3013 fix_new (fragP
, fragP
->fr_fix
, 2,
3014 #ifdef BFD_ASSEMBLER
3015 section_symbol (seg
),
3017 seg_info (seg
)->dot
,
3019 fragP
->fr_address
+ fragP
->fr_fix
+ (delay
? 4 : 6),
3020 1, BFD_RELOC_SH_PCDISP8BY2
);
3022 /* Set up a jump instruction. */
3023 buffer
[highbyte
+ 2] = 0xa0;
3024 buffer
[lowbyte
+ 2] = 0;
3025 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
3026 fragP
->fr_offset
, 1, BFD_RELOC_SH_PCDISP12BY2
);
3030 buffer
[highbyte
] &= ~0x4; /* Removes delay slot from branch. */
3035 /* Fill in a NOP instruction. */
3036 buffer
[highbyte
+ 4] = 0x0;
3037 buffer
[lowbyte
+ 4] = 0x9;
3046 case C (COND_JUMP
, COND32
):
3047 case C (COND_JUMP_DELAY
, COND32
):
3048 case C (COND_JUMP
, UNDEF_WORD_DISP
):
3049 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
3050 if (fragP
->fr_symbol
== NULL
)
3051 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3052 _("displacement overflows 8-bit field"));
3053 else if (S_IS_DEFINED (fragP
->fr_symbol
))
3054 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3055 _("displacement to defined symbol %s overflows 8-bit field"),
3056 S_GET_NAME (fragP
->fr_symbol
));
3058 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3059 _("displacement to undefined symbol %s overflows 8-bit field "),
3060 S_GET_NAME (fragP
->fr_symbol
));
3061 /* Stabilize this frag, so we don't trip an assert. */
3062 fragP
->fr_fix
+= fragP
->fr_var
;
3068 shmedia_md_convert_frag (headers
, seg
, fragP
, TRUE
);
3074 if (donerelax
&& !sh_relax
)
3075 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
3076 _("overflow in branch to %s; converted into longer instruction sequence"),
3077 (fragP
->fr_symbol
!= NULL
3078 ? S_GET_NAME (fragP
->fr_symbol
)
3083 md_section_align (seg
, size
)
3084 segT seg ATTRIBUTE_UNUSED
;
3087 #ifdef BFD_ASSEMBLER
3090 #else /* ! OBJ_ELF */
3091 return ((size
+ (1 << bfd_get_section_alignment (stdoutput
, seg
)) - 1)
3092 & (-1 << bfd_get_section_alignment (stdoutput
, seg
)));
3093 #endif /* ! OBJ_ELF */
3094 #else /* ! BFD_ASSEMBLER */
3095 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
3096 & (-1 << section_alignment
[(int) seg
]));
3097 #endif /* ! BFD_ASSEMBLER */
3100 /* This static variable is set by s_uacons to tell sh_cons_align that
3101 the expession does not need to be aligned. */
3103 static int sh_no_align_cons
= 0;
3105 /* This handles the unaligned space allocation pseudo-ops, such as
3106 .uaword. .uaword is just like .word, but the value does not need
3113 /* Tell sh_cons_align not to align this value. */
3114 sh_no_align_cons
= 1;
3118 /* If a .word, et. al., pseud-op is seen, warn if the value is not
3119 aligned correctly. Note that this can cause warnings to be issued
3120 when assembling initialized structured which were declared with the
3121 packed attribute. FIXME: Perhaps we should require an option to
3122 enable this warning? */
3125 sh_cons_align (nbytes
)
3131 if (sh_no_align_cons
)
3133 /* This is an unaligned pseudo-op. */
3134 sh_no_align_cons
= 0;
3139 while ((nbytes
& 1) == 0)
3148 if (now_seg
== absolute_section
)
3150 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
3151 as_warn (_("misaligned data"));
3155 p
= frag_var (rs_align_test
, 1, 1, (relax_substateT
) 0,
3156 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
3158 record_alignment (now_seg
, nalign
);
3161 /* When relaxing, we need to output a reloc for any .align directive
3162 that requests alignment to a four byte boundary or larger. This is
3163 also where we check for misaligned data. */
3166 sh_handle_align (frag
)
3169 int bytes
= frag
->fr_next
->fr_address
- frag
->fr_address
- frag
->fr_fix
;
3171 if (frag
->fr_type
== rs_align_code
)
3173 static const unsigned char big_nop_pattern
[] = { 0x00, 0x09 };
3174 static const unsigned char little_nop_pattern
[] = { 0x09, 0x00 };
3176 char *p
= frag
->fr_literal
+ frag
->fr_fix
;
3185 if (target_big_endian
)
3187 memcpy (p
, big_nop_pattern
, sizeof big_nop_pattern
);
3188 frag
->fr_var
= sizeof big_nop_pattern
;
3192 memcpy (p
, little_nop_pattern
, sizeof little_nop_pattern
);
3193 frag
->fr_var
= sizeof little_nop_pattern
;
3196 else if (frag
->fr_type
== rs_align_test
)
3199 as_warn_where (frag
->fr_file
, frag
->fr_line
, _("misaligned data"));
3203 && (frag
->fr_type
== rs_align
3204 || frag
->fr_type
== rs_align_code
)
3205 && frag
->fr_address
+ frag
->fr_fix
> 0
3206 && frag
->fr_offset
> 1
3207 && now_seg
!= bss_section
)
3208 fix_new (frag
, frag
->fr_fix
, 2, &abs_symbol
, frag
->fr_offset
, 0,
3209 BFD_RELOC_SH_ALIGN
);
3212 /* See whether the relocation should be resolved locally. */
3215 sh_local_pcrel (fix
)
3219 && (fix
->fx_r_type
== BFD_RELOC_SH_PCDISP8BY2
3220 || fix
->fx_r_type
== BFD_RELOC_SH_PCDISP12BY2
3221 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY2
3222 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY4
3223 || fix
->fx_r_type
== BFD_RELOC_8_PCREL
3224 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH16
3225 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH32
));
3228 /* See whether we need to force a relocation into the output file.
3229 This is used to force out switch and PC relative relocations when
3233 sh_force_relocation (fix
)
3236 /* These relocations can't make it into a DSO, so no use forcing
3237 them for global symbols. */
3238 if (sh_local_pcrel (fix
))
3241 /* Make sure some relocations get emitted. */
3242 if (fix
->fx_r_type
== BFD_RELOC_SH_LOOP_START
3243 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_END
3244 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_GD_32
3245 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LD_32
3246 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_IE_32
3247 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LDO_32
3248 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LE_32
3249 || generic_force_reloc (fix
))
3255 return (fix
->fx_pcrel
3256 || SWITCH_TABLE (fix
)
3257 || fix
->fx_r_type
== BFD_RELOC_SH_COUNT
3258 || fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
3259 || fix
->fx_r_type
== BFD_RELOC_SH_CODE
3260 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
3262 || fix
->fx_r_type
== BFD_RELOC_SH_SHMEDIA_CODE
3264 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
);
3269 sh_fix_adjustable (fixP
)
3272 if (fixP
->fx_r_type
== BFD_RELOC_32_PLT_PCREL
3273 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
3274 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTPC
3275 || fixP
->fx_r_type
== BFD_RELOC_RVA
)
3278 /* We need the symbol name for the VTABLE entries */
3279 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3280 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
3287 sh_elf_final_processing ()
3291 /* Set file-specific flags to indicate if this code needs
3292 a processor with the sh-dsp / sh3e ISA to execute. */
3294 /* SH5 and above don't know about the valid_arch arch_sh* bits defined
3295 in sh-opc.h, so check SH64 mode before checking valid_arch. */
3296 if (sh64_isa_mode
!= sh64_isa_unspecified
)
3299 #endif /* HAVE_SH64 */
3300 if (valid_arch
& arch_sh1
)
3302 else if (valid_arch
& arch_sh2
)
3304 else if (valid_arch
& arch_sh2e
)
3306 else if (valid_arch
& arch_sh_dsp
)
3308 else if (valid_arch
& arch_sh3
)
3310 else if (valid_arch
& arch_sh3_dsp
)
3312 else if (valid_arch
& arch_sh3e
)
3314 else if (valid_arch
& arch_sh4
)
3319 elf_elfheader (stdoutput
)->e_flags
&= ~EF_SH_MACH_MASK
;
3320 elf_elfheader (stdoutput
)->e_flags
|= val
;
3324 /* Apply a fixup to the object file. */
3327 md_apply_fix3 (fixP
, valP
, seg
)
3330 segT seg ATTRIBUTE_UNUSED
;
3332 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3333 int lowbyte
= target_big_endian
? 1 : 0;
3334 int highbyte
= target_big_endian
? 0 : 1;
3335 long val
= (long) *valP
;
3339 #ifdef BFD_ASSEMBLER
3340 /* A difference between two symbols, the second of which is in the
3341 current section, is transformed in a PC-relative relocation to
3342 the other symbol. We have to adjust the relocation type here. */
3345 switch (fixP
->fx_r_type
)
3351 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
3354 /* Currently, we only support 32-bit PCREL relocations.
3355 We'd need a new reloc type to handle 16_PCREL, and
3356 8_PCREL is already taken for R_SH_SWITCH8, which
3357 apparently does something completely different than what
3360 bfd_set_error (bfd_error_bad_value
);
3364 bfd_set_error (bfd_error_bad_value
);
3369 /* The function adjust_reloc_syms won't convert a reloc against a weak
3370 symbol into a reloc against a section, but bfd_install_relocation
3371 will screw up if the symbol is defined, so we have to adjust val here
3372 to avoid the screw up later.
3374 For ordinary relocs, this does not happen for ELF, since for ELF,
3375 bfd_install_relocation uses the "special function" field of the
3376 howto, and does not execute the code that needs to be undone, as long
3377 as the special function does not return bfd_reloc_continue.
3378 It can happen for GOT- and PLT-type relocs the way they are
3379 described in elf32-sh.c as they use bfd_elf_generic_reloc, but it
3380 doesn't matter here since those relocs don't use VAL; see below. */
3381 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
3382 && fixP
->fx_addsy
!= NULL
3383 && S_IS_WEAK (fixP
->fx_addsy
))
3384 val
-= S_GET_VALUE (fixP
->fx_addsy
);
3387 #ifdef BFD_ASSEMBLER
3388 if (SWITCH_TABLE (fixP
))
3389 val
-= S_GET_VALUE (fixP
->fx_subsy
);
3391 if (fixP
->fx_r_type
== 0)
3393 if (fixP
->fx_size
== 2)
3394 fixP
->fx_r_type
= BFD_RELOC_16
;
3395 else if (fixP
->fx_size
== 4)
3396 fixP
->fx_r_type
= BFD_RELOC_32
;
3397 else if (fixP
->fx_size
== 1)
3398 fixP
->fx_r_type
= BFD_RELOC_8
;
3406 switch (fixP
->fx_r_type
)
3408 case BFD_RELOC_SH_IMM4
:
3410 *buf
= (*buf
& 0xf0) | (val
& 0xf);
3413 case BFD_RELOC_SH_IMM4BY2
:
3416 *buf
= (*buf
& 0xf0) | ((val
>> 1) & 0xf);
3419 case BFD_RELOC_SH_IMM4BY4
:
3422 *buf
= (*buf
& 0xf0) | ((val
>> 2) & 0xf);
3425 case BFD_RELOC_SH_IMM8BY2
:
3431 case BFD_RELOC_SH_IMM8BY4
:
3438 case BFD_RELOC_SH_IMM8
:
3439 /* Sometimes the 8 bit value is sign extended (e.g., add) and
3440 sometimes it is not (e.g., and). We permit any 8 bit value.
3441 Note that adding further restrictions may invalidate
3442 reasonable looking assembly code, such as ``and -0x1,r0''. */
3448 case BFD_RELOC_SH_PCRELIMM8BY4
:
3449 /* The lower two bits of the PC are cleared before the
3450 displacement is added in. We can assume that the destination
3451 is on a 4 byte bounday. If this instruction is also on a 4
3452 byte boundary, then we want
3454 and target - here is a multiple of 4.
3455 Otherwise, we are on a 2 byte boundary, and we want
3456 (target - (here - 2)) / 4
3457 and target - here is not a multiple of 4. Computing
3458 (target - (here - 2)) / 4 == (target - here + 2) / 4
3459 works for both cases, since in the first case the addition of
3460 2 will be removed by the division. target - here is in the
3462 val
= (val
+ 2) / 4;
3464 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3468 case BFD_RELOC_SH_PCRELIMM8BY2
:
3471 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3475 case BFD_RELOC_SH_PCDISP8BY2
:
3477 if (val
< -0x80 || val
> 0x7f)
3478 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3482 case BFD_RELOC_SH_PCDISP12BY2
:
3484 if (val
< -0x800 || val
> 0x7ff)
3485 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3486 buf
[lowbyte
] = val
& 0xff;
3487 buf
[highbyte
] |= (val
>> 8) & 0xf;
3491 case BFD_RELOC_32_PCREL
:
3492 md_number_to_chars (buf
, val
, 4);
3496 md_number_to_chars (buf
, val
, 2);
3499 case BFD_RELOC_SH_USES
:
3500 /* Pass the value into sh_coff_reloc_mangle. */
3501 fixP
->fx_addnumber
= val
;
3504 case BFD_RELOC_SH_COUNT
:
3505 case BFD_RELOC_SH_ALIGN
:
3506 case BFD_RELOC_SH_CODE
:
3507 case BFD_RELOC_SH_DATA
:
3508 case BFD_RELOC_SH_LABEL
:
3509 /* Nothing to do here. */
3512 case BFD_RELOC_SH_LOOP_START
:
3513 case BFD_RELOC_SH_LOOP_END
:
3515 case BFD_RELOC_VTABLE_INHERIT
:
3516 case BFD_RELOC_VTABLE_ENTRY
:
3521 case BFD_RELOC_32_PLT_PCREL
:
3522 /* Make the jump instruction point to the address of the operand. At
3523 runtime we merely add the offset to the actual PLT entry. */
3524 * valP
= 0xfffffffc;
3525 val
= fixP
->fx_offset
;
3527 val
-= S_GET_VALUE (fixP
->fx_subsy
);
3528 fixP
->fx_addnumber
= val
;
3529 md_number_to_chars (buf
, val
, 4);
3532 case BFD_RELOC_SH_GOTPC
:
3533 /* This is tough to explain. We end up with this one if we have
3534 operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
3535 The goal here is to obtain the absolute address of the GOT,
3536 and it is strongly preferable from a performance point of
3537 view to avoid using a runtime relocation for this. There are
3538 cases where you have something like:
3540 .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
3542 and here no correction would be required. Internally in the
3543 assembler we treat operands of this form as not being pcrel
3544 since the '.' is explicitly mentioned, and I wonder whether
3545 it would simplify matters to do it this way. Who knows. In
3546 earlier versions of the PIC patches, the pcrel_adjust field
3547 was used to store the correction, but since the expression is
3548 not pcrel, I felt it would be confusing to do it this way. */
3550 md_number_to_chars (buf
, val
, 4);
3553 case BFD_RELOC_SH_TLS_GD_32
:
3554 case BFD_RELOC_SH_TLS_LD_32
:
3555 case BFD_RELOC_SH_TLS_IE_32
:
3556 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
3558 case BFD_RELOC_32_GOT_PCREL
:
3559 case BFD_RELOC_SH_GOTPLT32
:
3560 * valP
= 0; /* Fully resolved at runtime. No addend. */
3561 md_number_to_chars (buf
, 0, 4);
3564 case BFD_RELOC_SH_TLS_LDO_32
:
3565 case BFD_RELOC_SH_TLS_LE_32
:
3566 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
3568 case BFD_RELOC_32_GOTOFF
:
3569 md_number_to_chars (buf
, val
, 4);
3575 shmedia_md_apply_fix3 (fixP
, valP
);
3584 if ((val
& ((1 << shift
) - 1)) != 0)
3585 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("misaligned offset"));
3589 val
= ((val
>> shift
)
3590 | ((long) -1 & ~ ((long) -1 >> shift
)));
3592 if (max
!= 0 && (val
< min
|| val
> max
))
3593 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("offset out of range"));
3595 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3599 /* Called just before address relaxation. Return the length
3600 by which a fragment must grow to reach it's destination. */
3603 md_estimate_size_before_relax (fragP
, segment_type
)
3604 register fragS
*fragP
;
3605 register segT segment_type
;
3609 switch (fragP
->fr_subtype
)
3613 return shmedia_md_estimate_size_before_relax (fragP
, segment_type
);
3619 case C (UNCOND_JUMP
, UNDEF_DISP
):
3620 /* Used to be a branch to somewhere which was unknown. */
3621 if (!fragP
->fr_symbol
)
3623 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3625 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3627 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3631 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNDEF_WORD_DISP
);
3635 case C (COND_JUMP
, UNDEF_DISP
):
3636 case C (COND_JUMP_DELAY
, UNDEF_DISP
):
3637 what
= GET_WHAT (fragP
->fr_subtype
);
3638 /* Used to be a branch to somewhere which was unknown. */
3639 if (fragP
->fr_symbol
3640 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3642 /* Got a symbol and it's defined in this segment, become byte
3643 sized - maybe it will fix up. */
3644 fragP
->fr_subtype
= C (what
, COND8
);
3646 else if (fragP
->fr_symbol
)
3648 /* Its got a segment, but its not ours, so it will always be long. */
3649 fragP
->fr_subtype
= C (what
, UNDEF_WORD_DISP
);
3653 /* We know the abs value. */
3654 fragP
->fr_subtype
= C (what
, COND8
);
3658 case C (UNCOND_JUMP
, UNCOND12
):
3659 case C (UNCOND_JUMP
, UNCOND32
):
3660 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
3661 case C (COND_JUMP
, COND8
):
3662 case C (COND_JUMP
, COND12
):
3663 case C (COND_JUMP
, COND32
):
3664 case C (COND_JUMP
, UNDEF_WORD_DISP
):
3665 case C (COND_JUMP_DELAY
, COND8
):
3666 case C (COND_JUMP_DELAY
, COND12
):
3667 case C (COND_JUMP_DELAY
, COND32
):
3668 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
3669 /* When relaxing a section for the second time, we don't need to
3670 do anything besides return the current size. */
3674 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
3675 return fragP
->fr_var
;
3678 /* Put number into target byte order. */
3681 md_number_to_chars (ptr
, use
, nbytes
)
3687 /* We might need to set the contents type to data. */
3688 sh64_flag_output ();
3691 if (! target_big_endian
)
3692 number_to_chars_littleendian (ptr
, use
, nbytes
);
3694 number_to_chars_bigendian (ptr
, use
, nbytes
);
3697 /* This version is used in obj-coff.c when not using BFD_ASSEMBLER.
3698 eg for the sh-hms target. */
3701 md_pcrel_from (fixP
)
3704 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
+ 2;
3708 md_pcrel_from_section (fixP
, sec
)
3712 if (! sh_local_pcrel (fixP
)
3713 && fixP
->fx_addsy
!= (symbolS
*) NULL
3714 && (generic_force_reloc (fixP
)
3715 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3717 /* The symbol is undefined (or is defined but not in this section,
3718 or we're not sure about it being the final definition). Let the
3719 linker figure it out. We need to adjust the subtraction of a
3720 symbol to the position of the relocated data, though. */
3721 return fixP
->fx_subsy
? fixP
->fx_where
+ fixP
->fx_frag
->fr_address
: 0;
3724 return md_pcrel_from (fixP
);
3730 tc_coff_sizemachdep (frag
)
3733 return md_relax_table
[frag
->fr_subtype
].rlx_length
;
3736 #endif /* OBJ_COFF */
3738 #ifndef BFD_ASSEMBLER
3741 /* Map BFD relocs to SH COFF relocs. */
3745 bfd_reloc_code_real_type bfd_reloc
;
3749 static const struct reloc_map coff_reloc_map
[] =
3751 { BFD_RELOC_32
, R_SH_IMM32
},
3752 { BFD_RELOC_16
, R_SH_IMM16
},
3753 { BFD_RELOC_8
, R_SH_IMM8
},
3754 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_PCDISP8BY2
},
3755 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_PCDISP
},
3756 { BFD_RELOC_SH_IMM4
, R_SH_IMM4
},
3757 { BFD_RELOC_SH_IMM4BY2
, R_SH_IMM4BY2
},
3758 { BFD_RELOC_SH_IMM4BY4
, R_SH_IMM4BY4
},
3759 { BFD_RELOC_SH_IMM8
, R_SH_IMM8
},
3760 { BFD_RELOC_SH_IMM8BY2
, R_SH_IMM8BY2
},
3761 { BFD_RELOC_SH_IMM8BY4
, R_SH_IMM8BY4
},
3762 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_PCRELIMM8BY2
},
3763 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_PCRELIMM8BY4
},
3764 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
3765 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
3766 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
3767 { BFD_RELOC_SH_USES
, R_SH_USES
},
3768 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
3769 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
3770 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
3771 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
3772 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
3773 { BFD_RELOC_UNUSED
, 0 }
3776 /* Adjust a reloc for the SH. This is similar to the generic code,
3777 but does some minor tweaking. */
3780 sh_coff_reloc_mangle (seg
, fix
, intr
, paddr
)
3781 segment_info_type
*seg
;
3783 struct internal_reloc
*intr
;
3786 symbolS
*symbol_ptr
= fix
->fx_addsy
;
3789 intr
->r_vaddr
= paddr
+ fix
->fx_frag
->fr_address
+ fix
->fx_where
;
3791 if (! SWITCH_TABLE (fix
))
3793 const struct reloc_map
*rm
;
3795 for (rm
= coff_reloc_map
; rm
->bfd_reloc
!= BFD_RELOC_UNUSED
; rm
++)
3796 if (rm
->bfd_reloc
== (bfd_reloc_code_real_type
) fix
->fx_r_type
)
3798 if (rm
->bfd_reloc
== BFD_RELOC_UNUSED
)
3799 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3800 _("Can not represent %s relocation in this object file format"),
3801 bfd_get_reloc_code_name (fix
->fx_r_type
));
3802 intr
->r_type
= rm
->sh_reloc
;
3809 if (fix
->fx_r_type
== BFD_RELOC_16
)
3810 intr
->r_type
= R_SH_SWITCH16
;
3811 else if (fix
->fx_r_type
== BFD_RELOC_8
)
3812 intr
->r_type
= R_SH_SWITCH8
;
3813 else if (fix
->fx_r_type
== BFD_RELOC_32
)
3814 intr
->r_type
= R_SH_SWITCH32
;
3818 /* For a switch reloc, we set r_offset to the difference between
3819 the reloc address and the subtrahend. When the linker is
3820 doing relaxing, it can use the determine the starting and
3821 ending points of the switch difference expression. */
3822 intr
->r_offset
= intr
->r_vaddr
- S_GET_VALUE (fix
->fx_subsy
);
3825 /* PC relative relocs are always against the current section. */
3826 if (symbol_ptr
== NULL
)
3828 switch (fix
->fx_r_type
)
3830 case BFD_RELOC_SH_PCRELIMM8BY2
:
3831 case BFD_RELOC_SH_PCRELIMM8BY4
:
3832 case BFD_RELOC_SH_PCDISP8BY2
:
3833 case BFD_RELOC_SH_PCDISP12BY2
:
3834 case BFD_RELOC_SH_USES
:
3835 symbol_ptr
= seg
->dot
;
3842 if (fix
->fx_r_type
== BFD_RELOC_SH_USES
)
3844 /* We can't store the offset in the object file, since this
3845 reloc does not take up any space, so we store it in r_offset.
3846 The fx_addnumber field was set in md_apply_fix3. */
3847 intr
->r_offset
= fix
->fx_addnumber
;
3849 else if (fix
->fx_r_type
== BFD_RELOC_SH_COUNT
)
3851 /* We can't store the count in the object file, since this reloc
3852 does not take up any space, so we store it in r_offset. The
3853 fx_offset field was set when the fixup was created in
3854 sh_coff_frob_file. */
3855 intr
->r_offset
= fix
->fx_offset
;
3856 /* This reloc is always absolute. */
3859 else if (fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
)
3861 /* Store the alignment in the r_offset field. */
3862 intr
->r_offset
= fix
->fx_offset
;
3863 /* This reloc is always absolute. */
3866 else if (fix
->fx_r_type
== BFD_RELOC_SH_CODE
3867 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
3868 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
)
3870 /* These relocs are always absolute. */
3874 /* Turn the segment of the symbol into an offset. */
3875 if (symbol_ptr
!= NULL
)
3877 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
3879 intr
->r_symndx
= dot
->sy_number
;
3881 intr
->r_symndx
= symbol_ptr
->sy_number
;
3884 intr
->r_symndx
= -1;
3887 #endif /* OBJ_COFF */
3888 #endif /* ! BFD_ASSEMBLER */
3890 #ifdef BFD_ASSEMBLER
3892 /* Create a reloc. */
3895 tc_gen_reloc (section
, fixp
)
3896 asection
*section ATTRIBUTE_UNUSED
;
3900 bfd_reloc_code_real_type r_type
;
3902 rel
= (arelent
*) xmalloc (sizeof (arelent
));
3903 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3904 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3905 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3907 r_type
= fixp
->fx_r_type
;
3909 if (SWITCH_TABLE (fixp
))
3911 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
3913 if (r_type
== BFD_RELOC_16
)
3914 r_type
= BFD_RELOC_SH_SWITCH16
;
3915 else if (r_type
== BFD_RELOC_8
)
3916 r_type
= BFD_RELOC_8_PCREL
;
3917 else if (r_type
== BFD_RELOC_32
)
3918 r_type
= BFD_RELOC_SH_SWITCH32
;
3922 else if (r_type
== BFD_RELOC_SH_USES
)
3923 rel
->addend
= fixp
->fx_addnumber
;
3924 else if (r_type
== BFD_RELOC_SH_COUNT
)
3925 rel
->addend
= fixp
->fx_offset
;
3926 else if (r_type
== BFD_RELOC_SH_ALIGN
)
3927 rel
->addend
= fixp
->fx_offset
;
3928 else if (r_type
== BFD_RELOC_VTABLE_INHERIT
3929 || r_type
== BFD_RELOC_VTABLE_ENTRY
)
3930 rel
->addend
= fixp
->fx_offset
;
3931 else if (r_type
== BFD_RELOC_SH_LOOP_START
3932 || r_type
== BFD_RELOC_SH_LOOP_END
)
3933 rel
->addend
= fixp
->fx_offset
;
3934 else if (r_type
== BFD_RELOC_SH_LABEL
&& fixp
->fx_pcrel
)
3937 rel
->address
= rel
->addend
= fixp
->fx_offset
;
3940 else if (shmedia_init_reloc (rel
, fixp
))
3943 else if (fixp
->fx_pcrel
)
3944 rel
->addend
= fixp
->fx_addnumber
;
3945 else if (r_type
== BFD_RELOC_32
|| r_type
== BFD_RELOC_32_GOTOFF
)
3946 rel
->addend
= fixp
->fx_addnumber
;
3950 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
3951 if (rel
->howto
->type
== R_SH_IND12W
)
3952 rel
->addend
+= fixp
->fx_offset
- 4;
3953 if (rel
->howto
== NULL
)
3955 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3956 _("Cannot represent relocation type %s"),
3957 bfd_get_reloc_code_name (r_type
));
3958 /* Set howto to a garbage value so that we can keep going. */
3959 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
3960 assert (rel
->howto
!= NULL
);
3967 inline static char *
3968 sh_end_of_match (cont
, what
)
3971 int len
= strlen (what
);
3973 if (strncasecmp (cont
, what
, strlen (what
)) == 0
3974 && ! is_part_of_name (cont
[len
]))
3981 sh_parse_name (name
, exprP
, nextcharP
)
3986 char *next
= input_line_pointer
;
3991 exprP
->X_op_symbol
= NULL
;
3993 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
3996 GOT_symbol
= symbol_find_or_make (name
);
3998 exprP
->X_add_symbol
= GOT_symbol
;
4000 /* If we have an absolute symbol or a reg, then we know its
4002 segment
= S_GET_SEGMENT (exprP
->X_add_symbol
);
4003 if (segment
== absolute_section
)
4005 exprP
->X_op
= O_constant
;
4006 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
4007 exprP
->X_add_symbol
= NULL
;
4009 else if (segment
== reg_section
)
4011 exprP
->X_op
= O_register
;
4012 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
4013 exprP
->X_add_symbol
= NULL
;
4017 exprP
->X_op
= O_symbol
;
4018 exprP
->X_add_number
= 0;
4024 exprP
->X_add_symbol
= symbol_find_or_make (name
);
4026 if (*nextcharP
!= '@')
4028 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTOFF")))
4029 reloc_type
= BFD_RELOC_32_GOTOFF
;
4030 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTPLT")))
4031 reloc_type
= BFD_RELOC_SH_GOTPLT32
;
4032 else if ((next_end
= sh_end_of_match (next
+ 1, "GOT")))
4033 reloc_type
= BFD_RELOC_32_GOT_PCREL
;
4034 else if ((next_end
= sh_end_of_match (next
+ 1, "PLT")))
4035 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
4036 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSGD")))
4037 reloc_type
= BFD_RELOC_SH_TLS_GD_32
;
4038 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSLDM")))
4039 reloc_type
= BFD_RELOC_SH_TLS_LD_32
;
4040 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTTPOFF")))
4041 reloc_type
= BFD_RELOC_SH_TLS_IE_32
;
4042 else if ((next_end
= sh_end_of_match (next
+ 1, "TPOFF")))
4043 reloc_type
= BFD_RELOC_SH_TLS_LE_32
;
4044 else if ((next_end
= sh_end_of_match (next
+ 1, "DTPOFF")))
4045 reloc_type
= BFD_RELOC_SH_TLS_LDO_32
;
4049 *input_line_pointer
= *nextcharP
;
4050 input_line_pointer
= next_end
;
4051 *nextcharP
= *input_line_pointer
;
4052 *input_line_pointer
= '\0';
4054 exprP
->X_op
= O_PIC_reloc
;
4055 exprP
->X_add_number
= 0;
4056 exprP
->X_md
= reloc_type
;
4061 #endif /* BFD_ASSEMBLER */