1 /* tc-sh64.c -- Assemble code for the SuperH SH SHcompact and SHmedia.
2 Copyright (C) 2000-2014 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* This file defines SHmedia ISA-specific functions and includes tc-sh.c.
22 The SHcompact ISA is in all useful aspects the "old" sh4 as implemented
23 in tc-sh.c. Not making this file part of tc-sh.c makes it easier to
24 keep a leaner sh[1-4]-only implementation. */
29 #include "safe-ctype.h"
30 #include "opcodes/sh64-opc.h"
33 #error This file assumes object output is in the ELF format
36 /* Suffix used when we make "datalabel" symbol copies. It must not
37 collide with anything that can normally appear in a symbol, "faked
38 symbol" or local symbol. */
39 #define DATALABEL_SUFFIX " DL"
41 /* See shmedia_md_apply_fix and shmedia_md_pcrel_from_section for usage. */
42 #define SHMEDIA_MD_PCREL_FROM_FIX(FIXP) \
43 ((FIXP)->fx_size + (FIXP)->fx_where + (FIXP)->fx_frag->fr_address - 4)
45 /* We use this internally to see which one is PT and which is a PTA/PTB
46 that should be error-checked. We give it a better name here (but not
47 one that looks official). Adding it to reloc.c would make it look too
48 much of a real reloc; it is just used temporarily as a fixup-type. */
49 #define SHMEDIA_BFD_RELOC_PT BFD_RELOC_12_PCREL
53 shmedia_arg_type type
;
55 /* These could go into a union, but that would uglify the code. */
57 expressionS immediate
;
59 /* If IMMEDIATE was a shift-expression, like "(S >> N) & 65535", where
60 N = 0, 16, 32, 48, used to extract a certain 16-bit-field to make up
61 a MOVI or SHORI relocation for a symbol, then we put the
62 corresponding reloc-type here and modify the "immediate" expression
63 to S. Otherwise, this is just BFD_RELOC_NONE. */
64 bfd_reloc_code_real_type reloctype
;
65 } shmedia_operand_info
;
67 /* Frag containing last base instruction. This is put in the TC field in
68 a frag, so we can emit fixups for fr_opcode without needing to make
69 sure that the opcode is in the same frag as any variant operand. */
70 fragS
*sh64_last_insn_frag
= NULL
;
74 shmedia_operand_info operands
[3];
75 unsigned long ops_val
;
76 } shmedia_operands_info
;
79 { sh64_abi_unspecified
, sh64_abi_32
, sh64_abi_64
};
81 /* What ISA are we assembling code for? */
82 enum sh64_isa_values sh64_isa_mode
= sh64_isa_unspecified
;
84 /* What ABI was specified, if any (implicitly or explicitly)? */
85 static enum sh64_abi_values sh64_abi
= sh64_abi_unspecified
;
87 /* A note that says if we're in a sequence of insns without label
88 settings, segment or ISA mode changes or emitted data. */
89 static bfd_boolean seen_insn
= FALSE
;
91 /* This is set to TRUE in shmedia_md_end, so that we don't emit any
92 .cranges entries when the assembler calls output functions while
93 grinding along after all input is seen. */
94 static bfd_boolean sh64_end_of_assembly
= FALSE
;
96 /* Controlled by the option -no-mix, this invalidates mixing SHcompact and
97 SHmedia code in the same section, and also invalidates mixing data and
98 SHmedia code in the same section. No .cranges will therefore be
99 emitted, unless -shcompact-const-crange is specified and there is a
100 constant pool in SHcompact code. */
101 static bfd_boolean sh64_mix
= TRUE
;
103 static bfd_boolean sh64_shcompact_const_crange
= FALSE
;
105 /* Controlled by the option -no-expand, this says whether or not we expand
106 MOVI and PT/PTA/PTB. When we do not expand these insns to fit an
107 operand, we will emit errors for operands out of range and generate the
108 basic instruction and reloc for an external symbol. */
109 static bfd_boolean sh64_expand
= TRUE
;
111 /* Controlled by the option -expand-pt32, this says whether we expand
112 PT/PTA/PTB of an external symbol to (only) 32 or (the full) 64 bits
113 when -abi=64 is in effect. */
114 static bfd_boolean sh64_pt32
= FALSE
;
116 /* When emitting a .cranges descriptor, we want to avoid getting recursive
117 calls through emit_expr. */
118 static bfd_boolean emitting_crange
= FALSE
;
120 /* SHmedia mnemonics. */
121 static struct hash_control
*shmedia_opcode_hash_control
= NULL
;
123 static const unsigned char shmedia_big_nop_pattern
[4] =
125 (SHMEDIA_NOP_OPC
>> 24) & 255, (SHMEDIA_NOP_OPC
>> 16) & 255,
126 (SHMEDIA_NOP_OPC
>> 8) & 255, SHMEDIA_NOP_OPC
& 255
129 static const unsigned char shmedia_little_nop_pattern
[4] =
131 SHMEDIA_NOP_OPC
& 255, (SHMEDIA_NOP_OPC
>> 8) & 255,
132 (SHMEDIA_NOP_OPC
>> 16) & 255, (SHMEDIA_NOP_OPC
>> 24) & 255
135 static void shmedia_md_begin (void);
136 static int shmedia_parse_reg (char *, int *, int *, shmedia_arg_type
);
137 static void shmedia_md_assemble (char *);
138 static void shmedia_md_apply_fix (fixS
*, valueT
*);
139 static int shmedia_md_estimate_size_before_relax (fragS
*, segT
);
140 static int shmedia_init_reloc (arelent
*, fixS
*);
141 static char *shmedia_get_operands (shmedia_opcode_info
*, char *,
142 shmedia_operands_info
*);
143 static void s_sh64_mode (int);
144 static void s_sh64_abi (int);
145 static void shmedia_md_convert_frag (bfd
*, segT
, fragS
*, bfd_boolean
);
146 static void shmedia_check_limits (offsetT
*, bfd_reloc_code_real_type
,
148 static void sh64_set_contents_type (enum sh64_elf_cr_type
);
149 static void shmedia_get_operand (char **, shmedia_operand_info
*,
151 static unsigned long shmedia_immediate_op (char *, shmedia_operand_info
*,
152 int, bfd_reloc_code_real_type
);
153 static char *shmedia_parse_exp (char *, shmedia_operand_info
*);
154 static void shmedia_frob_file_before_adjust (void);
155 static void sh64_emit_crange (symbolS
*, symbolS
*, enum sh64_elf_cr_type
);
156 static void sh64_flush_last_crange (bfd
*, asection
*, void *);
157 static void sh64_flag_output (void);
158 static void sh64_update_contents_mark (bfd_boolean
);
159 static void sh64_vtable_entry (int);
160 static void sh64_vtable_inherit (int);
161 static char *strip_datalabels (void);
162 static int shmedia_build_Mytes (shmedia_opcode_info
*,
163 shmedia_operands_info
*);
164 static shmedia_opcode_info
*shmedia_find_cooked_opcode (char **);
165 static unsigned long shmedia_mask_number (unsigned long,
166 bfd_reloc_code_real_type
);
171 shmedia_md_end (void)
175 /* First, update the last range to include whatever data was last
177 sh64_update_contents_mark (TRUE
);
179 /* Make sure frags generated after this point are not marked with the
180 wrong ISA; make them easily spottable. We still want to distinguish
181 it from sh64_isa_unspecified when we compile for SHcompact or
183 if (sh64_isa_mode
!= sh64_isa_unspecified
)
184 sh64_isa_mode
= sh64_isa_sh5_guard
;
186 sh64_end_of_assembly
= TRUE
;
188 bfd_map_over_sections (stdoutput
, sh64_flush_last_crange
, NULL
);
190 /* Iterate over segments and emit the last .cranges descriptor. */
191 for (symp
= symbol_rootP
; symp
!= NULL
; symp
= symp
->sy_next
)
193 symbolS
*mainsym
= *symbol_get_tc (symp
);
195 /* Is this a datalabel symbol; does it have a pointer to the main
199 /* If the datalabel symbol is undefined, check if the main
200 symbol has changed in that respect. */
201 if (S_GET_SEGMENT (symp
) == undefined_section
)
205 symseg
= S_GET_SEGMENT (mainsym
);
207 /* If the symbol is now defined to something that is not
208 global and without STO_SH5_ISA32, we just equate the
209 datalabel symbol to the main symbol, and the lack of
210 STO_SH5_ISA32 will handle the datalabelness. */
211 if (symseg
!= undefined_section
)
213 if (S_GET_OTHER (mainsym
) != STO_SH5_ISA32
)
215 symp
->sy_value
.X_op
= O_symbol
;
216 symp
->sy_value
.X_add_symbol
= mainsym
;
217 symp
->sy_value
.X_op_symbol
= NULL
;
218 symp
->sy_value
.X_add_number
= 0;
219 S_SET_SEGMENT (symp
, S_GET_SEGMENT (mainsym
));
220 symbol_set_frag (symp
, &zero_address_frag
);
221 copy_symbol_attributes (symp
, mainsym
);
225 /* An undefined symbol has since we saw it at
226 "datalabel", been defined to a BranchTarget
227 symbol. What we need to do here is very similar
228 to when we find the "datalabel" for a defined
229 symbol. FIXME: Break out to common function. */
230 symbol_set_value_expression (symp
,
231 symbol_get_value_expression
233 S_SET_SEGMENT (symp
, symseg
);
234 symbol_set_frag (symp
, symbol_get_frag (mainsym
));
235 copy_symbol_attributes (symp
, mainsym
);
237 /* Unset the BranchTarget mark that can be set at
238 attribute-copying. */
240 S_GET_OTHER (symp
) & ~STO_SH5_ISA32
);
242 /* The GLOBAL and WEAK attributes are not copied
243 over by copy_symbol_attributes. Do it here. */
244 if (S_IS_WEAK (mainsym
))
246 else if (S_IS_EXTERNAL (mainsym
))
247 S_SET_EXTERNAL (symp
);
252 /* A symbol that was defined at the time we saw
253 "datalabel" can since have been attributed with being
255 if (S_IS_WEAK (mainsym
))
257 else if (S_IS_EXTERNAL (mainsym
))
258 S_SET_EXTERNAL (symp
);
264 for (symp
= symbol_rootP
; symp
!= NULL
; symp
= symp
->sy_next
)
265 if (S_GET_OTHER (symp
) & STO_SH5_ISA32
)
266 symp
->sy_value
.X_add_number
++;
269 /* When resolving symbols, the main assembler has done us a misfavour. It
270 has removed the equation to the main symbol for a datalabel reference
271 that should be equal to the main symbol, e.g. when it's a global or
272 weak symbol and is a non-BranchTarget symbol anyway. We change that
273 back, so that relocs are against the main symbol, not the local "section
277 shmedia_frob_file_before_adjust (void)
280 for (symp
= symbol_rootP
; symp
!= NULL
; symp
= symp
->sy_next
)
282 symbolS
*mainsym
= *symbol_get_tc (symp
);
285 && S_GET_OTHER (mainsym
) != STO_SH5_ISA32
286 && (S_IS_EXTERNAL (mainsym
) || S_IS_WEAK (mainsym
)))
288 symp
->sy_value
.X_op
= O_symbol
;
289 symp
->sy_value
.X_add_symbol
= mainsym
;
290 symp
->sy_value
.X_op_symbol
= NULL
;
291 symp
->sy_value
.X_add_number
= 0;
293 /* For the "equation trick" to work, we have to set the section
295 S_SET_SEGMENT (symp
, undefined_section
);
296 symbol_set_frag (symp
, &zero_address_frag
);
297 copy_symbol_attributes (symp
, mainsym
);
299 /* Don't forget to remove the STO_SH5_ISA32 attribute after
300 copying the other attributes. */
301 S_SET_OTHER (symp
, S_GET_OTHER (symp
) & ~STO_SH5_ISA32
);
306 /* We need to mark the current location after the alignment. This is
307 copied code the caller, do_align. We mark the frag location before and
308 after as we need and arrange to skip the same code in do_align.
310 An alternative to code duplication is to call the do_align recursively,
311 arranging to fall through into do_align if we're already here. That
312 would require do_align as an incoming function parameter, since it's
313 static in read.c. That solution was discarded a too kludgy. */
316 sh64_do_align (int n
, const char *fill
, int len
, int max
)
318 /* Update region, or put a data region in front. */
319 sh64_update_contents_mark (TRUE
);
321 /* Only make a frag if we HAVE to... */
322 if (n
!= 0 && !need_pass_2
)
326 if (subseg_text_p (now_seg
))
327 frag_align_code (n
, max
);
329 frag_align (n
, 0, max
);
332 frag_align (n
, *fill
, max
);
334 frag_align_pattern (n
, fill
, len
, max
);
337 /* Update mark for current region with current type. */
338 sh64_update_contents_mark (FALSE
);
341 /* The MAX_MEM_FOR_RS_ALIGN_CODE worker. We have to find out the ISA of
342 the current segment at this position. We can't look just at
343 sh64_isa_shmedia, and we can't look at frag_now. This is brittle:
344 callers are currently frag_align_code from subsegs_finish in write.c
345 (end of assembly) and frag_align_code from do_align in read.c (during
349 sh64_max_mem_for_rs_align_code (void)
351 segment_info_type
*seginfo
;
352 fragS
*mode_start_frag
;
353 seginfo
= seg_info (now_seg
);
355 /* We don't use the contents type we find at the tc_segment_info_data,
356 since that does not give us absolute information about the ISA; the
357 contents type can presumably be CRT_DATA and we'd be none the wiser.
358 Instead we use the information stored at the frag of the symbol at
359 the start of this range. If any information is missing or NULL,
362 /* If the current ISA mode is SHmedia, that's the mode that we're
363 going to assign to the new frag, so request enough memory for
364 it, even if we switch modes afterwards, otherwise we may
365 allocate too little memory and end up overflowing our buffer. */
366 (sh64_isa_mode
== sh64_isa_shmedia
367 || (sh64_isa_mode
!= sh64_isa_unspecified
369 && seginfo
->tc_segment_info_data
.mode_start_symbol
!= NULL
372 (seginfo
->tc_segment_info_data
.mode_start_symbol
)))
374 && mode_start_frag
->tc_frag_data
.isa
== sh64_isa_shmedia
))
378 /* Put in SHmedia NOP:s if the alignment was created when in SHmedia mode. */
381 sh64_handle_align (fragS
* frag
)
383 int bytes
= frag
->fr_next
->fr_address
- frag
->fr_address
- frag
->fr_fix
;
384 char * p
= frag
->fr_literal
+ frag
->fr_fix
;
386 if (frag
->tc_frag_data
.isa
== sh64_isa_shmedia
387 && frag
->fr_type
== rs_align_code
)
396 if (target_big_endian
)
398 memcpy (p
, shmedia_big_nop_pattern
,
399 sizeof shmedia_big_nop_pattern
);
400 frag
->fr_var
= sizeof shmedia_big_nop_pattern
;
404 memcpy (p
, shmedia_little_nop_pattern
,
405 sizeof shmedia_little_nop_pattern
);
406 frag
->fr_var
= sizeof shmedia_little_nop_pattern
;
410 /* Punt to SHcompact function. */
411 sh_handle_align (frag
);
414 /* Set SEC_SH64_ISA32 for SHmedia sections. */
417 shmedia_frob_section_type (asection
*sec
)
419 segment_info_type
*seginfo
;
420 seginfo
= seg_info (sec
);
422 /* This and elf32-sh64.c:sh64_elf_fake_sections are the only places
423 where we use anything else than ELF header flags to communicate the
424 section as containing SHmedia or other contents. BFD SEC_* section
425 flags are running out and should not be overloaded with
426 target-specific semantics. This target is ELF only (semantics not
427 defined for other formats), so we use the target-specific pointer
428 field of the ELF section data. */
429 if (seginfo
&& sh64_abi
== sh64_abi_32
)
431 struct sh64_section_data
*sec_elf_data
;
432 flagword sec_type
= 0;
434 if (seginfo
->tc_segment_info_data
.emitted_ranges
!= 0)
435 sec_type
= SHF_SH5_ISA32_MIXED
;
436 else if (seginfo
->tc_segment_info_data
.contents_type
== CRT_SH5_ISA32
)
437 sec_type
= SHF_SH5_ISA32
;
439 sec_elf_data
= sh64_elf_section_data (sec
)->sh64_info
;
440 if (sec_elf_data
== NULL
)
442 sec_elf_data
= xcalloc (1, sizeof (*sec_elf_data
));
443 sh64_elf_section_data (sec
)->sh64_info
= sec_elf_data
;
446 sec_elf_data
->contents_flags
= sec_type
;
450 /* This function is called by write_object_file right before the symbol
451 table is written. We subtract 1 from all symbols marked STO_SH5_ISA32,
452 as their values are temporarily incremented in shmedia_md_end, before
453 symbols values are used by relocs and fixups.
455 To increment all symbols and then decrement here is admittedly a
456 hackish solution. The alternative is to add infrastructure and hooks
457 to symbol evaluation that evaluates symbols differently internally to
458 the value output into the object file, but at the moment that just
459 seems too much for little benefit. */
462 sh64_adjust_symtab (void)
466 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
468 symbolS
*main_symbol
= *symbol_get_tc (symp
);
472 char *sym_name
= (char *) S_GET_NAME (symp
);
474 /* All datalabels not used in relocs should be gone by now.
476 We change those remaining to have the name of the main
477 symbol, and we set the ELF type of the symbol of the reloc to
479 sym_name
[strlen (sym_name
) - strlen (DATALABEL_SUFFIX
)] = 0;
480 elf_symbol (symbol_get_bfdsym (symp
))->internal_elf_sym
.st_info
483 /* Also set this symbol to "undefined", so we'll have only one
485 S_SET_SEGMENT (symp
, undefined_section
);
487 else if (S_GET_OTHER (symp
) & STO_SH5_ISA32
)
489 /* It's important to change the BFD symbol value, since it is now
490 set to the GAS symbolS value. */
493 /* Note that we do *not* adjust symp->sy_value.X_add_number. If
494 you do this, the test case in sh/sh64/immexpr2.s will fail.
495 This is because *after* symbols have been output but before
496 relocs are output, fixups are inspected one more time, and
497 some leftover expressions are resolved. To resolve to the
498 same values, those expressions must have the same GAS symbol
499 values before as after symbols have been output. We could
500 "symp->sy_value.X_add_number++" on the STO_SH5_ISA32 symbols
501 through tc_frob_file after symbols have been output, but that
502 would be too gross. */
507 /* Fill-in an allocated arelent. */
510 shmedia_init_reloc (arelent
*rel
, fixS
*fixP
)
512 /* Adjust parts of *relp according to *fixp, and tell that it has been
513 done, so default initializations will not happen. */
514 switch (fixP
->fx_r_type
)
517 case BFD_RELOC_64_PCREL
:
518 case BFD_RELOC_SH_IMM_LOW16
:
519 case BFD_RELOC_SH_IMM_MEDLOW16
:
520 case BFD_RELOC_SH_IMM_MEDHI16
:
521 case BFD_RELOC_SH_IMM_HI16
:
522 case BFD_RELOC_SH_IMM_LOW16_PCREL
:
523 case BFD_RELOC_SH_IMM_MEDLOW16_PCREL
:
524 case BFD_RELOC_SH_IMM_MEDHI16_PCREL
:
525 case BFD_RELOC_SH_IMM_HI16_PCREL
:
526 case BFD_RELOC_SH_IMMU5
:
527 case BFD_RELOC_SH_IMMU6
:
528 case BFD_RELOC_SH_IMMS6
:
529 case BFD_RELOC_SH_IMMS10
:
530 case BFD_RELOC_SH_IMMS10BY2
:
531 case BFD_RELOC_SH_IMMS10BY4
:
532 case BFD_RELOC_SH_IMMS10BY8
:
533 case BFD_RELOC_SH_IMMS16
:
534 case BFD_RELOC_SH_IMMU16
:
535 case BFD_RELOC_SH_PT_16
:
536 case BFD_RELOC_SH_GOT_LOW16
:
537 case BFD_RELOC_SH_GOT_MEDLOW16
:
538 case BFD_RELOC_SH_GOT_MEDHI16
:
539 case BFD_RELOC_SH_GOT_HI16
:
540 case BFD_RELOC_SH_GOT10BY4
:
541 case BFD_RELOC_SH_GOT10BY8
:
542 case BFD_RELOC_SH_GOTPLT_LOW16
:
543 case BFD_RELOC_SH_GOTPLT_MEDLOW16
:
544 case BFD_RELOC_SH_GOTPLT_MEDHI16
:
545 case BFD_RELOC_SH_GOTPLT_HI16
:
546 case BFD_RELOC_SH_GOTPLT10BY4
:
547 case BFD_RELOC_SH_GOTPLT10BY8
:
548 case BFD_RELOC_SH_GOTOFF_LOW16
:
549 case BFD_RELOC_SH_GOTOFF_MEDLOW16
:
550 case BFD_RELOC_SH_GOTOFF_MEDHI16
:
551 case BFD_RELOC_SH_GOTOFF_HI16
:
552 case BFD_RELOC_SH_GOTPC_LOW16
:
553 case BFD_RELOC_SH_GOTPC_MEDLOW16
:
554 case BFD_RELOC_SH_GOTPC_MEDHI16
:
555 case BFD_RELOC_SH_GOTPC_HI16
:
556 case BFD_RELOC_SH_PLT_LOW16
:
557 case BFD_RELOC_SH_PLT_MEDLOW16
:
558 case BFD_RELOC_SH_PLT_MEDHI16
:
559 case BFD_RELOC_SH_PLT_HI16
:
560 rel
->addend
= fixP
->fx_addnumber
+ fixP
->fx_offset
;
563 case BFD_RELOC_SH_IMMS6BY32
:
564 /* This must be resolved in assembly; we do not support it as a
565 reloc in an object file. */
566 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
567 _("This operand must be constant at assembly time"));
570 /* There are valid cases where we get here for other than SHmedia
571 relocs, so don't make a BAD_CASE out of this. */
579 /* Hook called from md_apply_fix in tc-sh.c. */
582 shmedia_md_apply_fix (fixS
*fixP
, valueT
*valp
)
585 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
587 = target_big_endian
? bfd_getb32 (buf
) : bfd_getl32 (buf
);
588 bfd_reloc_code_real_type orig_fx_r_type
= fixP
->fx_r_type
;
590 /* Change a 64-bit pc-relative reloc into the correct type, just like
591 tc-sh.c:md_apply_fix. */
594 switch (orig_fx_r_type
)
597 case BFD_RELOC_SH_IMM_LOW16
:
598 case BFD_RELOC_SH_IMM_MEDLOW16
:
599 case BFD_RELOC_SH_IMM_MEDHI16
:
600 case BFD_RELOC_SH_IMM_HI16
:
601 /* Because write.c calls MD_PCREL_FROM_SECTION twice, we need to
602 undo one of the adjustments, if the relocation is not
603 actually for a symbol within the same segment (which we
604 cannot check, because we're not called from md_apply_fix, so
605 we have to keep the reloc). FIXME: This is a bug in
606 write.c:fixup_segment affecting most targets that change
607 ordinary relocs to pcrel relocs in md_apply_fix. */
609 = *valp
+ SHMEDIA_MD_PCREL_FROM_FIX (fixP
);
612 case BFD_RELOC_SH_PLT_LOW16
:
613 case BFD_RELOC_SH_PLT_MEDLOW16
:
614 case BFD_RELOC_SH_PLT_MEDHI16
:
615 case BFD_RELOC_SH_PLT_HI16
:
616 case BFD_RELOC_SH_GOTPC_LOW16
:
617 case BFD_RELOC_SH_GOTPC_MEDLOW16
:
618 case BFD_RELOC_SH_GOTPC_MEDHI16
:
619 case BFD_RELOC_SH_GOTPC_HI16
:
627 /* We might need to change some relocs into the corresponding
629 switch (orig_fx_r_type
)
632 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
635 case BFD_RELOC_SH_IMM_LOW16
:
636 fixP
->fx_r_type
= BFD_RELOC_SH_IMM_LOW16_PCREL
;
639 case BFD_RELOC_SH_IMM_MEDLOW16
:
640 fixP
->fx_r_type
= BFD_RELOC_SH_IMM_MEDLOW16_PCREL
;
643 case BFD_RELOC_SH_IMM_MEDHI16
:
644 fixP
->fx_r_type
= BFD_RELOC_SH_IMM_MEDHI16_PCREL
;
647 case BFD_RELOC_SH_IMM_HI16
:
648 fixP
->fx_r_type
= BFD_RELOC_SH_IMM_HI16_PCREL
;
651 case SHMEDIA_BFD_RELOC_PT
:
652 /* This is how we see a difference between PT and PTA when not
653 expanding (in which case we handle it in
654 shmedia_md_convert_frag). Note that we don't see a
655 difference after the reloc is emitted. */
656 fixP
->fx_r_type
= BFD_RELOC_SH_PT_16
;
659 case BFD_RELOC_SH_PT_16
:
660 /* This tells us there was a PTA or PTB insn explicitly
661 expressed as such (not as PT). We "or" in a 1 into the
662 lowest bit in the (unused) destination field to tell the
663 linker that it should check the right ISA type of the
664 destination and not just change a PTA to PTB (if necessary). */
665 md_number_to_chars (buf
, insn
| (1 << 10), 4);
668 case BFD_RELOC_64_PCREL
:
669 case BFD_RELOC_SH_IMM_LOW16_PCREL
:
670 case BFD_RELOC_SH_IMM_MEDLOW16_PCREL
:
671 case BFD_RELOC_SH_IMM_MEDHI16_PCREL
:
672 case BFD_RELOC_SH_IMM_HI16_PCREL
:
673 /* Already handled. */
677 /* Everything else that changes into a pc-relative relocation is
679 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
680 _("Invalid operand expression"));
687 /* If an expression looked like it was PC-relative, but was completely
688 resolvable, we end up here with the result only in *VALP, and no
689 relocation will be emitted. */
690 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
692 /* Emit error for an out-of-range value. */
693 shmedia_check_limits ((offsetT
*) valp
, fixP
->fx_r_type
, fixP
);
695 switch (fixP
->fx_r_type
)
697 case BFD_RELOC_SH_IMM_LOW16
:
698 md_number_to_chars (buf
, insn
| ((val
& 65535) << 10), 4);
701 case BFD_RELOC_SH_IMM_MEDLOW16
:
702 md_number_to_chars (buf
,
704 | ((valueT
) (val
& ((valueT
) 65535 << 16))
708 case BFD_RELOC_SH_IMM_MEDHI16
:
709 md_number_to_chars (buf
,
711 | ((valueT
) (val
& ((valueT
) 65535 << 32))
715 case BFD_RELOC_SH_IMM_HI16
:
716 md_number_to_chars (buf
,
718 | ((valueT
) (val
& ((valueT
) 65535 << 48))
722 case BFD_RELOC_SH_IMMS16
:
723 case BFD_RELOC_SH_IMMU16
:
724 md_number_to_chars (buf
, insn
| ((val
& 65535) << 10), 4);
727 case BFD_RELOC_SH_IMMS10
:
728 md_number_to_chars (buf
, insn
| ((val
& 0x3ff) << 10), 4);
731 case BFD_RELOC_SH_IMMS10BY2
:
732 md_number_to_chars (buf
,
733 insn
| ((val
& (0x3ff << 1)) << (10 - 1)), 4);
736 case BFD_RELOC_SH_IMMS10BY4
:
737 md_number_to_chars (buf
,
738 insn
| ((val
& (0x3ff << 2)) << (10 - 2)), 4);
741 case BFD_RELOC_SH_IMMS10BY8
:
742 md_number_to_chars (buf
,
743 insn
| ((val
& (0x3ff << 3)) << (10 - 3)), 4);
746 case BFD_RELOC_SH_SHMEDIA_CODE
:
747 /* We just ignore and remove this one for the moment. FIXME:
748 Use it when implementing relaxing. */
752 md_number_to_chars (buf
, val
, 8);
755 case SHMEDIA_BFD_RELOC_PT
:
756 /* Change a PT to PTB if the operand turned out to be SHcompact.
757 The basic opcode specified with PT is equivalent to PTA. */
759 insn
|= SHMEDIA_PTB_BIT
;
762 case BFD_RELOC_SH_PT_16
:
763 if (! sh64_expand
|| sh_relax
)
765 /* Check if the operand of a PTA or PTB was for the "wrong"
766 ISA. A PT had an incoming fixup of SHMEDIA_BFD_RELOC_PT,
767 which we have changed to the right type above. */
768 if (orig_fx_r_type
!= SHMEDIA_BFD_RELOC_PT
)
770 if ((insn
& SHMEDIA_PTB_BIT
) != 0 && (val
& 1) != 0)
771 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
772 _("PTB operand is a SHmedia symbol"));
773 else if ((insn
& SHMEDIA_PTB_BIT
) == 0 && (val
& 1) == 0)
774 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
775 _("PTA operand is a SHcompact symbol"));
778 md_number_to_chars (buf
,
779 insn
| ((val
& (0xffff << 2))
787 /* This isn't a BAD_CASE, because presumably we can get here
788 from unexpected operands. Since we don't handle them, make
789 them syntax errors. */
790 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
791 _("invalid expression in operand"));
797 /* Hook called from md_convert_frag in tc-sh.c. */
800 shmedia_md_convert_frag (bfd
*output_bfd ATTRIBUTE_UNUSED
,
801 segT seg ATTRIBUTE_UNUSED
, fragS
*fragP
,
804 /* Pointer to first byte in variable-sized part of the frag. */
807 /* Pointer to first opcode byte in frag. */
810 /* Pointer to frag of opcode. */
811 fragS
*opc_fragP
= fragP
->tc_frag_data
.opc_frag
;
813 /* Size in bytes of variable-sized part of frag. */
814 int var_part_size
= 0;
816 /* This is part of *fragP. It contains all information about addresses
817 and offsets to varying parts. */
818 symbolS
*symbolP
= fragP
->fr_symbol
;
820 bfd_boolean reloc_needed
824 || ! S_IS_DEFINED (symbolP
)
825 || S_IS_EXTERNAL (symbolP
)
826 || S_IS_WEAK (symbolP
)
827 || (S_GET_SEGMENT (fragP
->fr_symbol
) != absolute_section
828 && S_GET_SEGMENT (fragP
->fr_symbol
) != seg
));
830 bfd_reloc_code_real_type reloctype
= BFD_RELOC_NONE
;
832 unsigned long var_part_offset
;
834 /* Where, in file space, does addr point? */
835 bfd_vma target_address
;
836 bfd_vma opcode_address
;
838 /* What was the insn? */
840 know (fragP
->fr_type
== rs_machine_dependent
);
842 var_part_offset
= fragP
->fr_fix
;
843 var_partp
= fragP
->fr_literal
+ var_part_offset
;
844 opcodep
= fragP
->fr_opcode
;
846 insn
= target_big_endian
? bfd_getb32 (opcodep
) : bfd_getl32 (opcodep
);
849 = ((symbolP
&& final
&& ! sh_relax
? S_GET_VALUE (symbolP
) : 0)
852 /* The opcode that would be extended is the last four "fixed" bytes. */
853 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
855 switch (fragP
->fr_subtype
)
857 case C (SH64PCREL16PT_64
, SH64PCREL16
):
858 case C (SH64PCREL16PT_32
, SH64PCREL16
):
859 /* We can get a PT to a relaxed SHcompact address if it is in the
860 same section; a mixed-ISA section. Change the opcode to PTB if
862 if ((target_address
& 1) == 0)
863 insn
|= SHMEDIA_PTB_BIT
;
866 case C (SH64PCREL16_32
, SH64PCREL16
):
867 case C (SH64PCREL16_64
, SH64PCREL16
):
868 /* Check that a PTA or PTB points to the right type of target. We
869 can get here for a SHcompact target if we are in a mixed-ISA
871 if (((target_address
& 1) == 0) && ((insn
& SHMEDIA_PTB_BIT
) == 0))
872 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
873 _("PTA operand is a SHcompact symbol"));
874 if (((target_address
& 1) != 0) && ((insn
& SHMEDIA_PTB_BIT
) != 0))
875 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
876 _("PTB operand is a SHmedia symbol"));
878 /* When relaxing, we do not output the address in the insn, but
879 instead a 1 into the low bit. This matches what the linker
880 expects to find for a BFD_RELOC_SH_PT_16 reloc, when it checks
881 correctness for PTA/PTB insn; used when the target address is
882 unknown (which is not the case here). */
883 md_number_to_chars (opcodep
,
886 ? 1 : ((target_address
- opcode_address
) / 4))
887 & ((1 << 16) - 1)) << 10),
890 /* Note that we do not emit info that this was originally a PT since
891 we have resolved to which one of PTA or PTB it will be. */
893 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
894 fragP
->fr_symbol
, fragP
->fr_offset
, 1, BFD_RELOC_SH_PT_16
);
898 case C (SH64PCREL16_32
, SH64PCRELPLT
):
899 case C (SH64PCREL16PT_32
, SH64PCRELPLT
):
900 reloctype
= BFD_RELOC_32_PLT_PCREL
;
904 case C (SH64PCREL16_32
, SH64PCREL32
):
905 case C (SH64PCREL16_64
, SH64PCREL32
):
906 case C (SH64PCREL16PT_32
, SH64PCREL32
):
907 case C (SH64PCREL16PT_64
, SH64PCREL32
):
908 /* In the fixed bit, put in a MOVI. */
909 md_number_to_chars (opcodep
,
911 | (SHMEDIA_TEMP_REG
<< 4)
913 ? 0 : (target_address
- (opcode_address
+ 8))
914 ) >> 16) & 65535) << 10),
917 /* Fill in a SHORI for the low part. */
918 md_number_to_chars (var_partp
,
920 | (SHMEDIA_TEMP_REG
<< 4)
922 ? 0 : (target_address
- (opcode_address
+ 8)))
926 /* End with a "PTREL R25,TRd". */
927 md_number_to_chars (var_partp
+ 4,
928 SHMEDIA_PTREL_OPC
| (insn
& SHMEDIA_LIKELY_BIT
)
929 | (SHMEDIA_TEMP_REG
<< 10)
933 /* We need relocs only if the target symbol was undefined or if
937 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
938 fragP
->fr_symbol
, fragP
->fr_offset
- 8, 1,
939 reloctype
== BFD_RELOC_32_PLT_PCREL
940 ? BFD_RELOC_SH_PLT_MEDLOW16
941 : BFD_RELOC_SH_IMM_MEDLOW16_PCREL
);
942 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
943 fragP
->fr_offset
- 4, 1,
944 reloctype
== BFD_RELOC_32_PLT_PCREL
945 ? BFD_RELOC_SH_PLT_LOW16
946 : BFD_RELOC_SH_IMM_LOW16_PCREL
);
952 case C (SH64PCREL16_64
, SH64PCREL48
):
953 case C (SH64PCREL16PT_64
, SH64PCREL48
):
954 /* In the fixed bit, put in a MOVI. */
955 md_number_to_chars (opcodep
,
957 | (SHMEDIA_TEMP_REG
<< 4)
959 ? 0 : (target_address
- (opcode_address
+ 12))
960 ) >> 32) & 65535) << 10),
963 /* The first SHORI, for the medium part. */
964 md_number_to_chars (var_partp
,
966 | (SHMEDIA_TEMP_REG
<< 4)
968 ? 0 : (target_address
- (opcode_address
+ 12))
969 ) >> 16) & 65535) << 10),
972 /* Fill in a SHORI for the low part. */
973 md_number_to_chars (var_partp
+ 4,
975 | (SHMEDIA_TEMP_REG
<< 4)
977 ? 0 : (target_address
- (opcode_address
+ 12)))
981 /* End with a "PTREL R25,TRd". */
982 md_number_to_chars (var_partp
+ 8,
983 SHMEDIA_PTREL_OPC
| (insn
& SHMEDIA_LIKELY_BIT
)
984 | (SHMEDIA_TEMP_REG
<< 10)
988 /* We need relocs only if the target symbol was undefined or if
992 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
993 fragP
->fr_symbol
, fragP
->fr_offset
- 12, 1,
994 reloctype
== BFD_RELOC_32_PLT_PCREL
995 ? BFD_RELOC_SH_PLT_MEDHI16
996 : BFD_RELOC_SH_IMM_MEDHI16_PCREL
);
997 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
998 fragP
->fr_offset
- 8, 1,
999 reloctype
== BFD_RELOC_32_PLT_PCREL
1000 ? BFD_RELOC_SH_PLT_MEDLOW16
1001 : BFD_RELOC_SH_IMM_MEDLOW16_PCREL
);
1002 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 4, 4, fragP
->fr_symbol
,
1003 fragP
->fr_offset
- 4, 1,
1004 reloctype
== BFD_RELOC_32_PLT_PCREL
1005 ? BFD_RELOC_SH_PLT_LOW16
1006 : BFD_RELOC_SH_IMM_LOW16_PCREL
);
1012 case C (SH64PCREL16_64
, SH64PCRELPLT
):
1013 case C (SH64PCREL16PT_64
, SH64PCRELPLT
):
1014 reloctype
= BFD_RELOC_32_PLT_PCREL
;
1018 case C (SH64PCREL16_64
, SH64PCREL64
):
1019 case C (SH64PCREL16PT_64
, SH64PCREL64
):
1020 /* In the fixed bit, put in a MOVI. */
1021 md_number_to_chars (opcodep
,
1023 | (SHMEDIA_TEMP_REG
<< 4)
1025 ? 0 : (target_address
- (opcode_address
+ 16))
1026 ) >> 48) & 65535) << 10),
1029 /* The first SHORI, for the medium-high part. */
1030 md_number_to_chars (var_partp
,
1032 | (SHMEDIA_TEMP_REG
<< 4)
1034 ? 0 : (target_address
- (opcode_address
+ 16))
1035 ) >> 32) & 65535) << 10),
1038 /* A SHORI, for the medium-low part. */
1039 md_number_to_chars (var_partp
+ 4,
1041 | (SHMEDIA_TEMP_REG
<< 4)
1043 ? 0 : (target_address
- (opcode_address
+ 16))
1044 ) >> 16) & 65535) << 10),
1047 /* Fill in a SHORI for the low part. */
1048 md_number_to_chars (var_partp
+ 8,
1050 | (SHMEDIA_TEMP_REG
<< 4)
1052 ? 0 : (target_address
- (opcode_address
+ 16)))
1056 /* End with a "PTREL R25,TRd". */
1057 md_number_to_chars (var_partp
+ 12,
1058 SHMEDIA_PTREL_OPC
| (insn
& SHMEDIA_LIKELY_BIT
)
1059 | (SHMEDIA_TEMP_REG
<< 10)
1060 | (insn
& (7 << 4)),
1063 /* We need relocs only if the target symbol was undefined or if
1067 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1068 fragP
->fr_symbol
, fragP
->fr_offset
- 16, 1,
1069 reloctype
== BFD_RELOC_32_PLT_PCREL
1070 ? BFD_RELOC_SH_PLT_HI16
1071 : BFD_RELOC_SH_IMM_HI16_PCREL
);
1072 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
1073 fragP
->fr_offset
- 12, 1,
1074 reloctype
== BFD_RELOC_32_PLT_PCREL
1075 ? BFD_RELOC_SH_PLT_MEDHI16
1076 : BFD_RELOC_SH_IMM_MEDHI16_PCREL
);
1077 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 4, 4, fragP
->fr_symbol
,
1078 fragP
->fr_offset
- 8, 1,
1079 reloctype
== BFD_RELOC_32_PLT_PCREL
1080 ? BFD_RELOC_SH_PLT_MEDLOW16
1081 : BFD_RELOC_SH_IMM_MEDLOW16_PCREL
);
1082 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 8, 4, fragP
->fr_symbol
,
1083 fragP
->fr_offset
- 4, 1,
1084 reloctype
== BFD_RELOC_32_PLT_PCREL
1085 ? BFD_RELOC_SH_PLT_LOW16
1086 : BFD_RELOC_SH_IMM_LOW16_PCREL
);
1092 case C (MOVI_IMM_64
, MOVI_GOTOFF
):
1093 reloctype
= BFD_RELOC_32_GOTOFF
;
1097 case C (MOVI_IMM_64
, UNDEF_MOVI
):
1098 case C (MOVI_IMM_64
, MOVI_64
):
1100 /* We only get here for undefined symbols, so we can simplify
1101 handling compared to those above; we have 0 in the parts that
1102 will be filled with the symbol parts. */
1104 int reg
= (insn
>> 4) & 0x3f;
1106 /* In the fixed bit, put in a MOVI. */
1107 md_number_to_chars (opcodep
, SHMEDIA_MOVI_OPC
| (reg
<< 4), 4);
1108 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1109 fragP
->fr_symbol
, fragP
->fr_offset
, 0,
1110 reloctype
== BFD_RELOC_NONE
1111 ? BFD_RELOC_SH_IMM_HI16
1112 : reloctype
== BFD_RELOC_32_GOTOFF
1113 ? BFD_RELOC_SH_GOTOFF_HI16
1114 : (abort (), BFD_RELOC_SH_IMM_HI16
));
1116 /* The first SHORI, for the medium-high part. */
1117 md_number_to_chars (var_partp
, SHMEDIA_SHORI_OPC
| (reg
<< 4), 4);
1118 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
1119 fragP
->fr_offset
, 0,
1120 reloctype
== BFD_RELOC_NONE
1121 ? BFD_RELOC_SH_IMM_MEDHI16
1122 : reloctype
== BFD_RELOC_32_GOTOFF
1123 ? BFD_RELOC_SH_GOTOFF_MEDHI16
1124 : (abort (), BFD_RELOC_SH_IMM_MEDHI16
));
1126 /* A SHORI, for the medium-low part. */
1127 md_number_to_chars (var_partp
+ 4,
1128 SHMEDIA_SHORI_OPC
| (reg
<< 4), 4);
1129 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 4, 4, fragP
->fr_symbol
,
1130 fragP
->fr_offset
, 0,
1131 reloctype
== BFD_RELOC_NONE
1132 ? BFD_RELOC_SH_IMM_MEDLOW16
1133 : reloctype
== BFD_RELOC_32_GOTOFF
1134 ? BFD_RELOC_SH_GOTOFF_MEDLOW16
1135 : (abort (), BFD_RELOC_SH_IMM_MEDLOW16
));
1137 /* Fill in a SHORI for the low part. */
1138 md_number_to_chars (var_partp
+ 8,
1139 SHMEDIA_SHORI_OPC
| (reg
<< 4), 4);
1140 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 8, 4, fragP
->fr_symbol
,
1141 fragP
->fr_offset
, 0,
1142 reloctype
== BFD_RELOC_NONE
1143 ? BFD_RELOC_SH_IMM_LOW16
1144 : reloctype
== BFD_RELOC_32_GOTOFF
1145 ? BFD_RELOC_SH_GOTOFF_LOW16
1146 : (abort (), BFD_RELOC_SH_IMM_LOW16
));
1152 case C (MOVI_IMM_32
, MOVI_GOTOFF
):
1153 reloctype
= BFD_RELOC_32_GOTOFF
;
1157 case C (MOVI_IMM_32
, UNDEF_MOVI
):
1158 case C (MOVI_IMM_32
, MOVI_32
):
1160 /* Note that we only get here for undefined symbols. */
1162 int reg
= (insn
>> 4) & 0x3f;
1164 /* A MOVI, for the high part. */
1165 md_number_to_chars (opcodep
, SHMEDIA_MOVI_OPC
| (reg
<< 4), 4);
1166 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1167 fragP
->fr_symbol
, fragP
->fr_offset
, 0,
1168 reloctype
== BFD_RELOC_NONE
1169 ? BFD_RELOC_SH_IMM_MEDLOW16
1170 : reloctype
== BFD_RELOC_32_GOTOFF
1171 ? BFD_RELOC_SH_GOTOFF_MEDLOW16
1172 : reloctype
== BFD_RELOC_SH_GOTPC
1173 ? BFD_RELOC_SH_GOTPC_MEDLOW16
1174 : reloctype
== BFD_RELOC_32_PLT_PCREL
1175 ? BFD_RELOC_SH_PLT_MEDLOW16
1176 : (abort (), BFD_RELOC_SH_IMM_MEDLOW16
));
1178 /* Fill in a SHORI for the low part. */
1179 md_number_to_chars (var_partp
,
1180 SHMEDIA_SHORI_OPC
| (reg
<< 4), 4);
1181 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
1182 fragP
->fr_offset
, 0,
1183 reloctype
== BFD_RELOC_NONE
1184 ? BFD_RELOC_SH_IMM_LOW16
1185 : reloctype
== BFD_RELOC_32_GOTOFF
1186 ? BFD_RELOC_SH_GOTOFF_LOW16
1187 : reloctype
== BFD_RELOC_SH_GOTPC
1188 ? BFD_RELOC_SH_GOTPC_LOW16
1189 : reloctype
== BFD_RELOC_32_PLT_PCREL
1190 ? BFD_RELOC_SH_PLT_LOW16
1191 : (abort (), BFD_RELOC_SH_IMM_LOW16
));
1197 case C (MOVI_IMM_32_PCREL
, MOVI_16
):
1198 case C (MOVI_IMM_64_PCREL
, MOVI_16
):
1199 md_number_to_chars (opcodep
,
1202 ? 0 : (target_address
- opcode_address
))
1206 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1207 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
1208 BFD_RELOC_SH_IMM_LOW16_PCREL
);
1212 case C (MOVI_IMM_32
, MOVI_16
):
1213 case C (MOVI_IMM_64
, MOVI_16
):
1214 md_number_to_chars (opcodep
,
1216 | (((reloc_needed
? 0 : target_address
)
1224 case C (MOVI_IMM_32_PCREL
, MOVI_PLT
):
1225 reloctype
= BFD_RELOC_32_PLT_PCREL
;
1226 goto movi_imm_32_pcrel_reloc_needed
;
1228 case C (MOVI_IMM_32_PCREL
, MOVI_GOTPC
):
1229 reloctype
= BFD_RELOC_SH_GOTPC
;
1232 movi_imm_32_pcrel_reloc_needed
:
1236 case C (MOVI_IMM_32_PCREL
, MOVI_32
):
1237 case C (MOVI_IMM_64_PCREL
, MOVI_32
):
1239 int reg
= (insn
>> 4) & 0x3f;
1241 md_number_to_chars (opcodep
,
1244 ? 0 : (target_address
- opcode_address
)))
1245 >> 16) & 65535) << 10), 4);
1247 /* A SHORI, for the low part. */
1248 md_number_to_chars (var_partp
,
1252 ? 0 : (target_address
- opcode_address
))
1253 & 65535) << 10), 4);
1256 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1257 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
1258 reloctype
== BFD_RELOC_NONE
1259 ? BFD_RELOC_SH_IMM_MEDLOW16_PCREL
1260 : reloctype
== BFD_RELOC_SH_GOTPC
1261 ? BFD_RELOC_SH_GOTPC_MEDLOW16
1262 : reloctype
== BFD_RELOC_32_PLT_PCREL
1263 ? BFD_RELOC_SH_PLT_MEDLOW16
1264 : (abort (), BFD_RELOC_SH_IMM_MEDLOW16_PCREL
));
1265 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
1266 fragP
->fr_offset
+ 4, 1,
1267 reloctype
== BFD_RELOC_NONE
1268 ? BFD_RELOC_SH_IMM_LOW16_PCREL
1269 : reloctype
== BFD_RELOC_SH_GOTPC
1270 ? BFD_RELOC_SH_GOTPC_LOW16
1271 : reloctype
== BFD_RELOC_32_PLT_PCREL
1272 ? BFD_RELOC_SH_PLT_LOW16
1273 : (abort (), BFD_RELOC_SH_IMM_LOW16_PCREL
));
1279 case C (MOVI_IMM_32_PCREL
, MOVI_48
):
1280 case C (MOVI_IMM_64_PCREL
, MOVI_48
):
1282 int reg
= (insn
>> 4) & 0x3f;
1284 md_number_to_chars (opcodep
,
1287 ? 0 : (target_address
- opcode_address
)))
1288 >> 32) & 65535) << 10), 4);
1290 /* A SHORI, for the medium part. */
1291 md_number_to_chars (var_partp
,
1295 ? 0 : (target_address
- opcode_address
))
1296 >> 16) & 65535) << 10), 4);
1298 /* A SHORI, for the low part. */
1299 md_number_to_chars (var_partp
+ 4,
1303 ? 0 : (target_address
- opcode_address
))
1304 & 65535) << 10), 4);
1307 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1308 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
1309 BFD_RELOC_SH_IMM_MEDHI16_PCREL
);
1310 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
1311 fragP
->fr_offset
+ 4, 1, BFD_RELOC_SH_IMM_MEDLOW16_PCREL
);
1312 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 4, 4, fragP
->fr_symbol
,
1313 fragP
->fr_offset
+ 8, 1, BFD_RELOC_SH_IMM_LOW16_PCREL
);
1319 case C (MOVI_IMM_64_PCREL
, MOVI_PLT
):
1320 reloctype
= BFD_RELOC_32_PLT_PCREL
;
1321 goto movi_imm_64_pcrel_reloc_needed
;
1323 case C (MOVI_IMM_64_PCREL
, MOVI_GOTPC
):
1324 reloctype
= BFD_RELOC_SH_GOTPC
;
1327 movi_imm_64_pcrel_reloc_needed
:
1331 case C (MOVI_IMM_32_PCREL
, MOVI_64
):
1332 case C (MOVI_IMM_64_PCREL
, MOVI_64
):
1334 int reg
= (insn
>> 4) & 0x3f;
1336 md_number_to_chars (opcodep
,
1339 ? 0 : (target_address
- opcode_address
)))
1340 >> 48) & 65535) << 10), 4);
1342 /* A SHORI, for the medium-high part. */
1343 md_number_to_chars (var_partp
,
1347 ? 0 : (target_address
- opcode_address
))
1348 >> 32) & 65535) << 10), 4);
1350 /* A SHORI, for the medium-low part. */
1351 md_number_to_chars (var_partp
+ 4,
1355 ? 0 : (target_address
- opcode_address
))
1356 >> 16) & 65535) << 10), 4);
1358 /* A SHORI, for the low part. */
1359 md_number_to_chars (var_partp
+ 8,
1363 ? 0 : (target_address
- opcode_address
))
1364 & 65535) << 10), 4);
1367 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1368 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
1369 reloctype
== BFD_RELOC_NONE
1370 ? BFD_RELOC_SH_IMM_HI16_PCREL
1371 : reloctype
== BFD_RELOC_SH_GOTPC
1372 ? BFD_RELOC_SH_GOTPC_HI16
1373 : reloctype
== BFD_RELOC_32_PLT_PCREL
1374 ? BFD_RELOC_SH_PLT_HI16
1375 : (abort (), BFD_RELOC_SH_IMM_HI16_PCREL
));
1376 fix_new (fragP
, var_partp
- fragP
->fr_literal
, 4, fragP
->fr_symbol
,
1377 fragP
->fr_offset
+ 4, 1,
1378 reloctype
== BFD_RELOC_NONE
1379 ? BFD_RELOC_SH_IMM_MEDHI16_PCREL
1380 : reloctype
== BFD_RELOC_SH_GOTPC
1381 ? BFD_RELOC_SH_GOTPC_MEDHI16
1382 : reloctype
== BFD_RELOC_32_PLT_PCREL
1383 ? BFD_RELOC_SH_PLT_MEDHI16
1384 : (abort (), BFD_RELOC_SH_IMM_MEDHI16_PCREL
));
1385 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 4, 4,
1387 fragP
->fr_offset
+ 8, 1,
1388 reloctype
== BFD_RELOC_NONE
1389 ? BFD_RELOC_SH_IMM_MEDLOW16_PCREL
1390 : reloctype
== BFD_RELOC_SH_GOTPC
1391 ? BFD_RELOC_SH_GOTPC_MEDLOW16
1392 : reloctype
== BFD_RELOC_32_PLT_PCREL
1393 ? BFD_RELOC_SH_PLT_MEDLOW16
1394 : (abort (), BFD_RELOC_SH_IMM_MEDLOW16_PCREL
));
1395 fix_new (fragP
, var_partp
- fragP
->fr_literal
+ 8, 4,
1397 fragP
->fr_offset
+ 12, 1,
1398 reloctype
== BFD_RELOC_NONE
1399 ? BFD_RELOC_SH_IMM_LOW16_PCREL
1400 : reloctype
== BFD_RELOC_SH_GOTPC
1401 ? BFD_RELOC_SH_GOTPC_LOW16
1402 : reloctype
== BFD_RELOC_32_PLT_PCREL
1403 ? BFD_RELOC_SH_PLT_LOW16
1404 : (abort (), BFD_RELOC_SH_IMM_LOW16_PCREL
));
1411 BAD_CASE (fragP
->fr_subtype
);
1414 fragP
->fr_fix
+= var_part_size
;
1418 /* Mask NUMBER (originating from a signed number) corresponding to the HOW
1421 static unsigned long
1422 shmedia_mask_number (unsigned long number
, bfd_reloc_code_real_type how
)
1426 case BFD_RELOC_SH_IMMU5
:
1427 number
&= (1 << 5) - 1;
1430 case BFD_RELOC_SH_IMMS6
:
1431 case BFD_RELOC_SH_IMMU6
:
1432 number
&= (1 << 6) - 1;
1435 case BFD_RELOC_SH_IMMS6BY32
:
1436 number
= (number
& ((1 << (6 + 5)) - 1)) >> 5;
1439 case BFD_RELOC_SH_IMMS10
:
1440 number
&= (1 << 10) - 1;
1443 case BFD_RELOC_SH_IMMS10BY2
:
1444 number
= (number
& ((1 << (10 + 1)) - 1)) >> 1;
1447 case BFD_RELOC_SH_IMMS10BY4
:
1448 number
= (number
& ((1 << (10 + 2)) - 1)) >> 2;
1451 case BFD_RELOC_SH_IMMS10BY8
:
1452 number
= (number
& ((1 << (10 + 3)) - 1)) >> 3;
1455 case BFD_RELOC_SH_IMMS16
:
1456 case BFD_RELOC_SH_IMMU16
:
1457 number
&= (1 << 16) - 1;
1467 /* Emit errors for values out-of-range, using as_bad_where if FRAGP is
1468 non-NULL, as_bad otherwise. */
1471 shmedia_check_limits (offsetT
*valp
, bfd_reloc_code_real_type reloc
,
1474 offsetT val
= *valp
;
1480 case BFD_RELOC_SH_IMMU5
:
1481 if (val
< 0 || val
> (1 << 5) - 1)
1482 msg
= _("invalid operand, not a 5-bit unsigned value: %d");
1485 case BFD_RELOC_SH_IMMS6
:
1486 if (val
< -(1 << 5) || val
> (1 << 5) - 1)
1487 msg
= _("invalid operand, not a 6-bit signed value: %d");
1490 case BFD_RELOC_SH_IMMU6
:
1491 if (val
< 0 || val
> (1 << 6) - 1)
1492 msg
= _("invalid operand, not a 6-bit unsigned value: %d");
1495 case BFD_RELOC_SH_IMMS6BY32
:
1496 if (val
< -(1 << 10) || val
> (1 << 10) - 1)
1497 msg
= _("invalid operand, not a 11-bit signed value: %d");
1499 msg
= _("invalid operand, not a multiple of 32: %d");
1502 case BFD_RELOC_SH_IMMS10
:
1503 if (val
< -(1 << 9) || val
> (1 << 9) - 1)
1504 msg
= _("invalid operand, not a 10-bit signed value: %d");
1507 case BFD_RELOC_SH_IMMS10BY2
:
1508 if (val
< -(1 << 10) || val
> (1 << 10) - 1)
1509 msg
= _("invalid operand, not a 11-bit signed value: %d");
1511 msg
= _("invalid operand, not an even value: %d");
1514 case BFD_RELOC_SH_IMMS10BY4
:
1515 if (val
< -(1 << 11) || val
> (1 << 11) - 1)
1516 msg
= _("invalid operand, not a 12-bit signed value: %d");
1518 msg
= _("invalid operand, not a multiple of 4: %d");
1521 case BFD_RELOC_SH_IMMS10BY8
:
1522 if (val
< -(1 << 12) || val
> (1 << 12) - 1)
1523 msg
= _("invalid operand, not a 13-bit signed value: %d");
1525 msg
= _("invalid operand, not a multiple of 8: %d");
1528 case BFD_RELOC_SH_IMMS16
:
1529 if (val
< -(1 << 15) || val
> (1 << 15) - 1)
1530 msg
= _("invalid operand, not a 16-bit signed value: %d");
1533 case BFD_RELOC_SH_IMMU16
:
1534 if (val
< 0 || val
> (1 << 16) - 1)
1535 msg
= _("invalid operand, not a 16-bit unsigned value: %d");
1538 case BFD_RELOC_SH_PT_16
:
1539 case SHMEDIA_BFD_RELOC_PT
:
1540 if (val
< -(1 << 15) * 4 || val
> ((1 << 15) - 1) * 4 + 1)
1541 msg
= _("operand out of range for PT, PTA and PTB");
1542 else if ((val
% 4) != 0 && ((val
- 1) % 4) != 0)
1543 msg
= _("operand not a multiple of 4 for PT, PTA or PTB: %d");
1546 /* These have no limits; they take a 16-bit slice of a 32- or 64-bit
1548 case BFD_RELOC_SH_IMM_HI16
:
1549 case BFD_RELOC_SH_IMM_MEDHI16
:
1550 case BFD_RELOC_SH_IMM_MEDLOW16
:
1551 case BFD_RELOC_SH_IMM_LOW16
:
1552 case BFD_RELOC_SH_IMM_HI16_PCREL
:
1553 case BFD_RELOC_SH_IMM_MEDHI16_PCREL
:
1554 case BFD_RELOC_SH_IMM_MEDLOW16_PCREL
:
1555 case BFD_RELOC_SH_IMM_LOW16_PCREL
:
1557 case BFD_RELOC_SH_SHMEDIA_CODE
:
1560 /* This one has limits out of our reach. */
1571 as_bad_where (fixp
->fx_file
, fixp
->fx_line
, msg
, val
);
1577 /* Handle an immediate operand by checking limits and noting it for later
1578 evaluation if not computable yet, and return a bitfield suitable to
1579 "or" into the opcode (non-zero if the value was a constant number). */
1581 static unsigned long
1582 shmedia_immediate_op (char *where
, shmedia_operand_info
*op
, int pcrel
,
1583 bfd_reloc_code_real_type how
)
1585 unsigned long retval
= 0;
1587 /* If this is not an absolute number, make it a fixup. A constant in
1588 place of a pc-relative operand also needs a fixup. */
1589 if (op
->immediate
.X_op
!= O_constant
|| pcrel
)
1590 fix_new_exp (frag_now
,
1591 where
- frag_now
->fr_literal
,
1598 /* Check that the number is within limits as represented by the
1599 reloc, and return the number. */
1600 shmedia_check_limits (&op
->immediate
.X_add_number
, how
, NULL
);
1603 = shmedia_mask_number ((unsigned long) op
->immediate
.X_add_number
,
1607 return retval
<< 10;
1610 /* Try and parse a register name case-insensitively, return the number of
1614 shmedia_parse_reg (char *src
, int *mode
, int *reg
, shmedia_arg_type argtype
)
1616 int l0
= TOLOWER (src
[0]);
1617 int l1
= l0
? TOLOWER (src
[1]) : 0;
1621 if (src
[1] >= '1' && src
[1] <= '5')
1623 if (src
[2] >= '0' && src
[2] <= '9'
1624 && ! IDENT_CHAR ((unsigned char) src
[3]))
1627 *reg
= 10 * (src
[1] - '0') + src
[2] - '0';
1634 if (src
[2] >= '0' && src
[2] <= '3'
1635 && ! IDENT_CHAR ((unsigned char) src
[3]))
1638 *reg
= 60 + src
[2] - '0';
1643 if (src
[1] >= '0' && src
[1] <= '9'
1644 && ! IDENT_CHAR ((unsigned char) src
[2]))
1647 *reg
= (src
[1] - '0');
1652 if (l0
== 't' && l1
== 'r')
1654 if (src
[2] >= '0' && src
[2] <= '7'
1655 && ! IDENT_CHAR ((unsigned char) src
[3]))
1658 *reg
= (src
[2] - '0');
1663 if (l0
== 'f' && l1
== 'r')
1665 if (src
[2] >= '1' && src
[2] <= '5')
1667 if (src
[3] >= '0' && src
[3] <= '9'
1668 && ! IDENT_CHAR ((unsigned char) src
[4]))
1671 *reg
= 10 * (src
[2] - '0') + src
[3] - '0';
1677 if (src
[3] >= '0' && src
[3] <= '3'
1678 && ! IDENT_CHAR ((unsigned char) src
[4]))
1681 *reg
= 60 + src
[3] - '0';
1685 if (src
[2] >= '0' && src
[2] <= '9'
1686 && ! IDENT_CHAR ((unsigned char) src
[3]))
1689 *reg
= (src
[2] - '0');
1694 if (l0
== 'f' && l1
== 'v')
1696 if (src
[2] >= '1' && src
[2] <= '5')
1698 if (src
[3] >= '0' && src
[3] <= '9'
1699 && ((10 * (src
[2] - '0') + src
[3] - '0') % 4) == 0
1700 && ! IDENT_CHAR ((unsigned char) src
[4]))
1703 *reg
= 10 * (src
[2] - '0') + src
[3] - '0';
1710 && ! IDENT_CHAR ((unsigned char) src
[4]))
1713 *reg
= 60 + src
[3] - '0';
1717 if (src
[2] >= '0' && src
[2] <= '9'
1718 && ((src
[2] - '0') % 4) == 0
1719 && ! IDENT_CHAR ((unsigned char) src
[3]))
1722 *reg
= (src
[2] - '0');
1727 if (l0
== 'd' && l1
== 'r')
1729 if (src
[2] >= '1' && src
[2] <= '5')
1731 if (src
[3] >= '0' && src
[3] <= '9'
1732 && ((src
[3] - '0') % 2) == 0
1733 && ! IDENT_CHAR ((unsigned char) src
[4]))
1736 *reg
= 10 * (src
[2] - '0') + src
[3] - '0';
1743 if ((src
[3] == '0' || src
[3] == '2')
1744 && ! IDENT_CHAR ((unsigned char) src
[4]))
1747 *reg
= 60 + src
[3] - '0';
1752 if (src
[2] >= '0' && src
[2] <= '9'
1753 && ((src
[2] - '0') % 2) == 0
1754 && ! IDENT_CHAR ((unsigned char) src
[3]))
1757 *reg
= (src
[2] - '0');
1762 if (l0
== 'f' && l1
== 'p')
1764 if (src
[2] >= '1' && src
[2] <= '5')
1766 if (src
[3] >= '0' && src
[3] <= '9'
1767 && ((src
[3] - '0') % 2) == 0
1768 && ! IDENT_CHAR ((unsigned char) src
[4]))
1771 *reg
= 10 * (src
[2] - '0') + src
[3] - '0';
1778 if ((src
[3] == '0' || src
[3] == '2')
1779 && ! IDENT_CHAR ((unsigned char) src
[4]))
1782 *reg
= 60 + src
[3] - '0';
1787 if (src
[2] >= '0' && src
[2] <= '9'
1788 && ((src
[2] - '0') % 2) == 0
1789 && ! IDENT_CHAR ((unsigned char) src
[3]))
1792 *reg
= (src
[2] - '0');
1797 if (l0
== 'm' && strncasecmp (src
, "mtrx", 4) == 0)
1799 if (src
[4] == '0' && ! IDENT_CHAR ((unsigned char) src
[5]))
1806 if (src
[4] == '1' && src
[5] == '6'
1807 && ! IDENT_CHAR ((unsigned char) src
[6]))
1814 if (src
[4] == '3' && src
[5] == '2'
1815 && ! IDENT_CHAR ((unsigned char) src
[6]))
1822 if (src
[4] == '4' && src
[5] == '8'
1823 && ! IDENT_CHAR ((unsigned char) src
[6]))
1831 if (l0
== 'c' && l1
== 'r')
1833 if (src
[2] >= '1' && src
[2] <= '5')
1835 if (src
[3] >= '0' && src
[3] <= '9'
1836 && ! IDENT_CHAR ((unsigned char) src
[4]))
1839 *reg
= 10 * (src
[2] - '0') + src
[3] - '0';
1845 if (src
[3] >= '0' && src
[3] <= '3'
1846 && ! IDENT_CHAR ((unsigned char) src
[4]))
1849 *reg
= 60 + src
[3] - '0';
1853 if (src
[2] >= '0' && src
[2] <= '9'
1854 && ! IDENT_CHAR ((unsigned char) src
[3]))
1857 *reg
= (src
[2] - '0');
1862 /* We either have an error, a symbol or a control register by predefined
1863 name. To keep things simple but still fast for normal cases, we do
1864 linear search in the (not to big) table of predefined control
1865 registers. We only do this when we *expect* a control register.
1866 Those instructions should be rare enough that linear searching is ok.
1867 Or just read them into a hash-table in shmedia_md_begin. Since they
1868 cannot be specified in the same place of symbol operands, don't add
1869 them there to the *main* symbol table as being in "reg_section". */
1870 if (argtype
== A_CREG_J
|| argtype
== A_CREG_K
)
1872 const shmedia_creg_info
*cregp
;
1875 for (cregp
= shmedia_creg_table
; cregp
->name
!= NULL
; cregp
++)
1877 len
= strlen (cregp
->name
);
1878 if (strncasecmp (cregp
->name
, src
, len
) == 0
1879 && ! IDENT_CHAR (src
[len
]))
1883 if (cregp
->name
!= NULL
)
1886 *reg
= cregp
->cregno
;
1894 /* Called from md_estimate_size_before_relax in tc-sh.c */
1897 shmedia_md_estimate_size_before_relax (fragS
*fragP
,
1898 segT segment_type ATTRIBUTE_UNUSED
)
1903 /* For ELF, we can't relax externally visible symbols; see tc-i386.c. */
1904 bfd_boolean sym_relaxable
1906 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
1907 && ! S_IS_EXTERNAL (fragP
->fr_symbol
)
1908 && ! S_IS_WEAK (fragP
->fr_symbol
));
1910 old_fr_fix
= fragP
->fr_fix
;
1912 switch (fragP
->fr_subtype
)
1914 case C (SH64PCREL16_32
, UNDEF_SH64PCREL
):
1915 case C (SH64PCREL16PT_32
, UNDEF_SH64PCREL
):
1916 /* Used to be to somewhere which was unknown. */
1919 int what
= GET_WHAT (fragP
->fr_subtype
);
1921 /* In this segment, so head for shortest. */
1922 fragP
->fr_subtype
= C (what
, SH64PCREL16
);
1926 int what
= GET_WHAT (fragP
->fr_subtype
);
1927 /* We know the abs value, but we don't know where we will be
1928 linked, so we must make it the longest. Presumably we could
1929 switch to a non-pcrel representation, but having absolute
1930 values in PT operands should be rare enough not to be worth
1931 adding that code. */
1932 fragP
->fr_subtype
= C (what
, SH64PCREL32
);
1934 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
1937 case C (SH64PCREL16_64
, UNDEF_SH64PCREL
):
1938 case C (SH64PCREL16PT_64
, UNDEF_SH64PCREL
):
1939 /* Used to be to somewhere which was unknown. */
1942 int what
= GET_WHAT (fragP
->fr_subtype
);
1944 /* In this segment, so head for shortest. */
1945 fragP
->fr_subtype
= C (what
, SH64PCREL16
);
1949 int what
= GET_WHAT (fragP
->fr_subtype
);
1950 /* We know the abs value, but we don't know where we will be
1951 linked, so we must make it the longest. Presumably we could
1952 switch to a non-pcrel representation, but having absolute
1953 values in PT operands should be rare enough not to be worth
1954 adding that code. */
1955 fragP
->fr_subtype
= C (what
, SH64PCREL64
);
1957 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
1960 case C (MOVI_IMM_64
, UNDEF_MOVI
):
1961 case C (MOVI_IMM_32
, UNDEF_MOVI
):
1964 /* Look inside the "symbol". If we find a PC-relative expression,
1965 change this to a PC-relative, relaxable expression. */
1966 if (fragP
->fr_symbol
!= NULL
1967 && (exp
= symbol_get_value_expression (fragP
->fr_symbol
)) != NULL
1968 && exp
->X_op
== O_subtract
1969 && exp
->X_op_symbol
!= NULL
1970 && S_GET_SEGMENT (exp
->X_op_symbol
) == segment_type
)
1972 int what
= GET_WHAT (fragP
->fr_subtype
);
1973 int what_high
= what
== MOVI_IMM_32
? MOVI_32
: MOVI_64
;
1975 = symbol_get_value_expression (exp
->X_op_symbol
);
1977 = symbol_get_value_expression (exp
->X_add_symbol
);
1979 /* Change the MOVI expression to the "X" in "X - Y" and subtract
1980 Y:s offset to this location from X. Note that we can only
1981 allow an Y which is offset from this frag. */
1984 && opexp
->X_op
== O_constant
1985 && fragP
== symbol_get_frag (exp
->X_op_symbol
))
1987 /* At this point, before relaxing, the add-number of opexp
1988 is the offset from the fr_fix part. */
1990 = (exp
->X_add_number
1991 - (opexp
->X_add_number
- (fragP
->fr_fix
- 4)));
1992 fragP
->fr_symbol
= exp
->X_add_symbol
;
1994 what
= what
== MOVI_IMM_32
1995 ? MOVI_IMM_32_PCREL
: MOVI_IMM_64_PCREL
;
1997 /* Check the "X" symbol to estimate the size of this
1998 PC-relative expression. */
1999 if (S_GET_SEGMENT (exp
->X_add_symbol
) == segment_type
2000 && ! S_IS_EXTERNAL (exp
->X_add_symbol
)
2001 && ! S_IS_WEAK (exp
->X_add_symbol
))
2002 fragP
->fr_subtype
= C (what
, MOVI_16
);
2004 fragP
->fr_subtype
= C (what
, what_high
);
2006 /* This is now a PC-relative expression, fit to be relaxed. */
2009 fragP
->fr_subtype
= C (what
, what_high
);
2011 else if (fragP
->fr_symbol
== NULL
2012 || (S_GET_SEGMENT (fragP
->fr_symbol
) == absolute_section
2013 && exp
->X_op
== O_constant
))
2016 = (target_big_endian
2017 ? bfd_getb32 (fragP
->fr_opcode
)
2018 : bfd_getl32 (fragP
->fr_opcode
));
2019 offsetT one
= (offsetT
) 1;
2020 offsetT value
= fragP
->fr_offset
2021 + (fragP
->fr_symbol
== NULL
? 0 : S_GET_VALUE (fragP
->fr_symbol
));
2023 if (value
>= ((offsetT
) -1 << 15) && value
< ((offsetT
) 1 << 15))
2025 /* Fits in 16-bit signed number. */
2026 int what
= GET_WHAT (fragP
->fr_subtype
);
2027 fragP
->fr_subtype
= C (what
, MOVI_16
);
2029 /* Just "or" in the value. */
2030 md_number_to_chars (fragP
->fr_opcode
,
2031 insn
| ((value
& ((1 << 16) - 1)) << 10),
2034 else if (value
>= -(one
<< 31)
2035 && (value
< (one
<< 31)
2036 || (sh64_abi
== sh64_abi_32
&& value
< (one
<< 32))))
2038 /* The value fits in a 32-bit signed number. */
2039 int reg
= (insn
>> 4) & 0x3f;
2041 /* Just "or" in the high bits of the value, making the first
2043 md_number_to_chars (fragP
->fr_opcode
,
2045 | (((value
>> 16) & ((1 << 16) - 1)) << 10),
2048 /* Add a SHORI with the low bits. Note that this insn lives
2049 in the variable fragment part. */
2050 md_number_to_chars (fragP
->fr_literal
+ old_fr_fix
,
2053 | ((value
& ((1 << 16) - 1)) << 10),
2056 /* We took a piece of the variable part. */
2059 else if (GET_WHAT (fragP
->fr_subtype
) == MOVI_IMM_32
)
2061 /* Value out of range. */
2062 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2063 _("MOVI operand is not a 32-bit signed value: 0x%8x%08x"),
2064 ((unsigned int) (value
>> 32)
2065 & (unsigned int) 0xffffffff),
2066 (unsigned int) value
& (unsigned int) 0xffffffff);
2068 /* Must advance size, or we will get internal inconsistency
2069 and fall into an assert. */
2072 /* Now we know we are allowed to expand to 48- and 64-bit values. */
2073 else if (value
>= -(one
<< 47) && value
< (one
<< 47))
2075 /* The value fits in a 48-bit signed number. */
2076 int reg
= (insn
>> 4) & 0x3f;
2078 /* Just "or" in the high bits of the value, making the first
2080 md_number_to_chars (fragP
->fr_opcode
,
2082 | (((value
>> 32) & ((1 << 16) - 1)) << 10),
2085 /* Add a SHORI with the middle bits. Note that this insn lives
2086 in the variable fragment part. */
2087 md_number_to_chars (fragP
->fr_literal
+ old_fr_fix
,
2090 | (((value
>> 16) & ((1 << 16) - 1)) << 10),
2093 /* Add a SHORI with the low bits. */
2094 md_number_to_chars (fragP
->fr_literal
+ old_fr_fix
+ 4,
2097 | ((value
& ((1 << 16) - 1)) << 10),
2100 /* We took a piece of the variable part. */
2105 /* A 64-bit number. */
2106 int reg
= (insn
>> 4) & 0x3f;
2108 /* Just "or" in the high bits of the value, making the first
2110 md_number_to_chars (fragP
->fr_opcode
,
2112 | (((value
>> 48) & ((1 << 16) - 1)) << 10),
2115 /* Add a SHORI with the midhigh bits. Note that this insn lives
2116 in the variable fragment part. */
2117 md_number_to_chars (fragP
->fr_literal
+ old_fr_fix
,
2120 | (((value
>> 32) & ((1 << 16) - 1)) << 10),
2123 /* Add a SHORI with the midlow bits. */
2124 md_number_to_chars (fragP
->fr_literal
+ old_fr_fix
+ 4,
2127 | (((value
>> 16) & ((1 << 16) - 1)) << 10),
2130 /* Add a SHORI with the low bits. */
2131 md_number_to_chars (fragP
->fr_literal
+ old_fr_fix
+ 8,
2134 | ((value
& ((1 << 16) - 1)) << 10), 4);
2135 /* We took all of the variable part. */
2136 fragP
->fr_fix
+= 12;
2139 /* MOVI expansions that get here have not been converted to
2140 PC-relative frags, but instead expanded by
2141 md_number_to_chars or by calling shmedia_md_convert_frag
2142 with final == FALSE. We must not have them around as
2143 frags anymore; symbols would be prematurely evaluated
2144 when relaxing. We will not need to have md_convert_frag
2145 called again with them; any further handling is through
2146 the already emitted fixups. */
2150 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2153 /* For relaxation states that remain unchanged, report the
2154 estimated length. */
2155 case C (SH64PCREL16_32
, SH64PCREL16
):
2156 case C (SH64PCREL16PT_32
, SH64PCREL16
):
2157 case C (SH64PCREL16_32
, SH64PCREL32
):
2158 case C (SH64PCREL16PT_32
, SH64PCREL32
):
2159 case C (SH64PCREL16_32
, SH64PCRELPLT
):
2160 case C (SH64PCREL16PT_32
, SH64PCRELPLT
):
2161 case C (SH64PCREL16_64
, SH64PCREL16
):
2162 case C (SH64PCREL16PT_64
, SH64PCREL16
):
2163 case C (SH64PCREL16_64
, SH64PCREL32
):
2164 case C (SH64PCREL16PT_64
, SH64PCREL32
):
2165 case C (SH64PCREL16_64
, SH64PCREL48
):
2166 case C (SH64PCREL16PT_64
, SH64PCREL48
):
2167 case C (SH64PCREL16_64
, SH64PCREL64
):
2168 case C (SH64PCREL16PT_64
, SH64PCREL64
):
2169 case C (SH64PCREL16_64
, SH64PCRELPLT
):
2170 case C (SH64PCREL16PT_64
, SH64PCRELPLT
):
2171 case C (MOVI_IMM_32
, MOVI_16
):
2172 case C (MOVI_IMM_32
, MOVI_32
):
2173 case C (MOVI_IMM_32
, MOVI_GOTOFF
):
2174 case C (MOVI_IMM_32_PCREL
, MOVI_16
):
2175 case C (MOVI_IMM_32_PCREL
, MOVI_32
):
2176 case C (MOVI_IMM_32_PCREL
, MOVI_PLT
):
2177 case C (MOVI_IMM_32_PCREL
, MOVI_GOTPC
):
2178 case C (MOVI_IMM_64
, MOVI_16
):
2179 case C (MOVI_IMM_64
, MOVI_32
):
2180 case C (MOVI_IMM_64
, MOVI_48
):
2181 case C (MOVI_IMM_64
, MOVI_64
):
2182 case C (MOVI_IMM_64
, MOVI_GOTOFF
):
2183 case C (MOVI_IMM_64_PCREL
, MOVI_16
):
2184 case C (MOVI_IMM_64_PCREL
, MOVI_32
):
2185 case C (MOVI_IMM_64_PCREL
, MOVI_48
):
2186 case C (MOVI_IMM_64_PCREL
, MOVI_64
):
2187 case C (MOVI_IMM_64_PCREL
, MOVI_PLT
):
2188 case C (MOVI_IMM_64_PCREL
, MOVI_GOTPC
):
2189 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
2196 return fragP
->fr_var
+ (fragP
->fr_fix
- old_fr_fix
);
2199 /* Parse an expression, SH64-style. Copied from tc-sh.c, but with
2200 datatypes adjusted. */
2203 shmedia_parse_exp (char *s
, shmedia_operand_info
*op
)
2208 save
= input_line_pointer
;
2209 input_line_pointer
= s
;
2210 expression (&op
->immediate
);
2211 if (op
->immediate
.X_op
== O_absent
)
2212 as_bad (_("missing operand"));
2213 new_pointer
= input_line_pointer
;
2214 input_line_pointer
= save
;
2218 /* Parse an operand. Store pointer to next character in *PTR. */
2221 shmedia_get_operand (char **ptr
, shmedia_operand_info
*op
,
2222 shmedia_arg_type argtype
)
2228 len
= shmedia_parse_reg (src
, &mode
, &(op
->reg
), argtype
);
2236 /* Not a reg, so it must be a displacement. */
2237 *ptr
= shmedia_parse_exp (src
, op
);
2240 /* This is just an initialization; shmedia_get_operands will change
2242 op
->reloctype
= BFD_RELOC_NONE
;
2246 /* Parse the operands for this insn; return NULL if invalid, else return
2247 how much text was consumed. */
2250 shmedia_get_operands (shmedia_opcode_info
*info
, char *args
,
2251 shmedia_operands_info
*operands
)
2259 for (i
= 0; info
->arg
[i
] != 0; i
++)
2261 memset (operands
->operands
+ i
, 0, sizeof (operands
->operands
[0]));
2263 /* No operand to get for these fields. */
2264 if (info
->arg
[i
] == A_REUSE_PREV
)
2267 shmedia_get_operand (&ptr
, &operands
->operands
[i
], info
->arg
[i
]);
2269 /* Check operands type match. */
2270 switch (info
->arg
[i
])
2275 if (operands
->operands
[i
].type
!= A_GREG_M
)
2282 if (operands
->operands
[i
].type
!= A_FREG_G
)
2289 if (operands
->operands
[i
].type
!= A_FVREG_G
)
2296 if (operands
->operands
[i
].type
!= A_FMREG_G
)
2303 if (operands
->operands
[i
].type
!= A_FPREG_G
)
2310 if (operands
->operands
[i
].type
!= A_DREG_G
)
2316 if (operands
->operands
[i
].type
!= A_TREG_B
)
2322 if (operands
->operands
[i
].type
!= A_CREG_K
)
2328 /* Check for an expression that looks like S & 65535 or
2329 (S >> N) & 65535, where N = 0, 16, 32, 48.
2331 Get the S and put at operands->operands[i].immediate, and
2332 adjust operands->operands[i].reloctype. */
2334 expressionS
*imm_expr
= &operands
->operands
[i
].immediate
;
2335 expressionS
*right_expr
;
2337 if (operands
->operands
[i
].type
== A_IMMM
2338 && imm_expr
->X_op
== O_bit_and
2339 && imm_expr
->X_op_symbol
!= NULL
2341 = symbol_get_value_expression (imm_expr
->X_op_symbol
))
2342 ->X_op
== O_constant
)
2343 && right_expr
->X_add_number
== 0xffff)
2345 symbolS
*inner
= imm_expr
->X_add_symbol
;
2346 bfd_reloc_code_real_type reloctype
= BFD_RELOC_SH_IMM_LOW16
;
2347 expressionS
*inner_expr
2348 = symbol_get_value_expression (inner
);
2350 if (inner_expr
->X_op
== O_right_shift
)
2352 expressionS
*inner_right
;
2354 if (inner_expr
->X_op_symbol
!= NULL
2356 = symbol_get_value_expression (inner_expr
2358 ->X_op
== O_constant
))
2361 = inner_right
->X_add_number
;
2363 if (addnum
== 0 || addnum
== 16 || addnum
== 32
2368 ? BFD_RELOC_SH_IMM_LOW16
2370 ? BFD_RELOC_SH_IMM_MEDLOW16
2372 ? BFD_RELOC_SH_IMM_MEDHI16
2373 : BFD_RELOC_SH_IMM_HI16
)));
2375 inner
= inner_expr
->X_add_symbol
;
2376 inner_expr
= symbol_get_value_expression (inner
);
2381 /* I'm not sure I understand the logic, but evidently the
2382 inner expression of a lone symbol is O_constant, with
2383 the actual symbol in expr_section. For a constant, the
2384 section would be absolute_section. For sym+offset,
2385 it's O_symbol as always. See expr.c:make_expr_symbol,
2386 first statements. */
2388 if (inner_expr
->X_op
== O_constant
2389 && S_GET_SEGMENT (inner
) != absolute_section
)
2391 operands
->operands
[i
].immediate
.X_op
= O_symbol
;
2392 operands
->operands
[i
].immediate
.X_add_symbol
= inner
;
2393 operands
->operands
[i
].immediate
.X_add_number
= 0;
2396 operands
->operands
[i
].immediate
2397 = *symbol_get_value_expression (inner
);
2399 operands
->operands
[i
].reloctype
= reloctype
;
2411 case A_PCIMMS16BY4_PT
:
2414 if (operands
->operands
[i
].type
!= A_IMMM
)
2417 if (sh_check_fixup (&operands
->operands
[i
].immediate
,
2418 &operands
->operands
[i
].reloctype
))
2420 as_bad (_("invalid PIC reference"));
2427 BAD_CASE (info
->arg
[i
]);
2430 if (*ptr
== ',' && info
->arg
[i
+ 1])
2437 /* Find an opcode at the start of *STR_P in the hash table, and set
2438 *STR_P to the first character after the last one read. */
2440 static shmedia_opcode_info
*
2441 shmedia_find_cooked_opcode (char **str_p
)
2447 unsigned int nlen
= 0;
2449 /* Drop leading whitespace. */
2453 /* Find the op code end. */
2454 for (op_start
= op_end
= str
;
2456 && nlen
< sizeof (name
) - 1
2457 && ! is_end_of_line
[(unsigned char) *op_end
]
2458 && ! ISSPACE ((unsigned char) *op_end
);
2461 unsigned char c
= op_start
[nlen
];
2463 /* The machine independent code will convert CMP/EQ into cmp/EQ
2464 because it thinks the '/' is the end of the symbol. Moreover,
2465 all but the first sub-insn is a parallel processing insn won't
2466 be capitalized. Instead of hacking up the machine independent
2467 code, we just deal with it here. */
2477 as_bad (_("can't find opcode"));
2480 (shmedia_opcode_info
*) hash_find (shmedia_opcode_hash_control
, name
);
2483 /* Build up an instruction, including allocating the frag. */
2486 shmedia_build_Mytes (shmedia_opcode_info
*opcode
,
2487 shmedia_operands_info
*operands
)
2489 unsigned long insn
= opcode
->opcode_base
;
2491 char *insn_loc
= frag_more (4);
2493 /* The parameter to dwarf2_emit_insn is actually the offset to the start
2494 of the insn from the fix piece of instruction that was emitted.
2495 Since we want .debug_line addresses to record (address | 1) for
2496 SHmedia insns, we get the wanted effect by taking one off the size,
2497 knowing it's a multiple of 4. We count from the first fix piece of
2498 the insn. There must be no frags changes (frag_more or frag_var)
2499 calls in-between the frag_more call we account for, and this
2500 dwarf2_emit_insn call. */
2501 dwarf2_emit_insn (3);
2503 /* This is stored into any frag_var operand. */
2504 sh64_last_insn_frag
= frag_now
;
2506 /* Loop over opcode info, emit an instruction. */
2507 for (i
= 0, j
= 0; opcode
->arg
[i
]; i
++)
2509 shmedia_arg_type argtype
= opcode
->arg
[i
];
2510 shmedia_operand_info
*opjp
= &operands
->operands
[j
];
2535 /* Six-bit register fields. They just get filled with the
2536 parsed register number. */
2537 insn
|= (opjp
->reg
<< opcode
->nibbles
[i
]);
2542 /* Copy the register for the previous operand to this position. */
2543 insn
|= (operands
->operands
[j
- 1].reg
<< opcode
->nibbles
[i
]);
2548 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2549 BFD_RELOC_SH_IMMS6
);
2554 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2555 BFD_RELOC_SH_IMMS6BY32
);
2561 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2562 BFD_RELOC_SH_IMMS10
);
2567 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2568 BFD_RELOC_SH_IMMS10BY2
);
2573 if (opjp
->reloctype
== BFD_RELOC_NONE
)
2574 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2575 BFD_RELOC_SH_IMMS10BY4
);
2576 else if (opjp
->reloctype
== BFD_RELOC_SH_GOTPLT32
)
2577 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2578 BFD_RELOC_SH_GOTPLT10BY4
);
2579 else if (opjp
->reloctype
== BFD_RELOC_32_GOT_PCREL
)
2580 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2581 BFD_RELOC_SH_GOT10BY4
);
2583 as_bad (_("invalid PIC reference"));
2588 if (opjp
->reloctype
== BFD_RELOC_NONE
)
2589 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2590 BFD_RELOC_SH_IMMS10BY8
);
2591 else if (opjp
->reloctype
== BFD_RELOC_SH_GOTPLT32
)
2592 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2593 BFD_RELOC_SH_GOTPLT10BY8
);
2594 else if (opjp
->reloctype
== BFD_RELOC_32_GOT_PCREL
)
2595 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2596 BFD_RELOC_SH_GOT10BY8
);
2598 as_bad (_("invalid PIC reference"));
2603 /* Sneak a peek if this is the MOVI insn. If so, check if we
2604 should expand it. */
2605 if (opjp
->reloctype
== BFD_RELOC_32_GOT_PCREL
)
2606 opjp
->reloctype
= BFD_RELOC_SH_GOT_LOW16
;
2607 else if (opjp
->reloctype
== BFD_RELOC_SH_GOTPLT32
)
2608 opjp
->reloctype
= BFD_RELOC_SH_GOTPLT_LOW16
;
2610 if ((opjp
->reloctype
== BFD_RELOC_NONE
2611 || opjp
->reloctype
== BFD_RELOC_32_GOTOFF
2612 || opjp
->reloctype
== BFD_RELOC_32_PLT_PCREL
2613 || opjp
->reloctype
== BFD_RELOC_SH_GOTPC
)
2614 && opcode
->opcode_base
== SHMEDIA_MOVI_OPC
2615 && (opjp
->immediate
.X_op
!= O_constant
2616 || opjp
->immediate
.X_add_number
< -32768
2617 || opjp
->immediate
.X_add_number
> 32767)
2619 || opjp
->reloctype
== BFD_RELOC_32_GOTOFF
2620 || opjp
->reloctype
== BFD_RELOC_32_PLT_PCREL
2621 || opjp
->reloctype
== BFD_RELOC_SH_GOTPC
))
2623 int what
= sh64_abi
== sh64_abi_64
? MOVI_IMM_64
: MOVI_IMM_32
;
2624 offsetT max
= sh64_abi
== sh64_abi_64
? MOVI_64
: MOVI_32
;
2625 offsetT min
= MOVI_16
;
2626 offsetT init
= UNDEF_MOVI
;
2628 = opjp
->immediate
.X_op_symbol
!= NULL
2629 ? 0 : opjp
->immediate
.X_add_number
;
2631 = opjp
->immediate
.X_op_symbol
!= NULL
2632 ? make_expr_symbol (&opjp
->immediate
)
2633 : opjp
->immediate
.X_add_symbol
;
2635 if (opjp
->reloctype
== BFD_RELOC_32_GOTOFF
)
2636 init
= max
= min
= MOVI_GOTOFF
;
2637 else if (opjp
->reloctype
== BFD_RELOC_32_PLT_PCREL
)
2639 init
= max
= min
= MOVI_PLT
;
2640 what
= (sh64_abi
== sh64_abi_64
2642 : MOVI_IMM_32_PCREL
);
2644 else if (opjp
->reloctype
== BFD_RELOC_SH_GOTPC
)
2646 init
= max
= min
= MOVI_GOTPC
;
2647 what
= (sh64_abi
== sh64_abi_64
2649 : MOVI_IMM_32_PCREL
);
2652 frag_var (rs_machine_dependent
,
2653 md_relax_table
[C (what
, max
)].rlx_length
,
2654 md_relax_table
[C (what
, min
)].rlx_length
,
2655 C (what
, init
), sym
, addvalue
, insn_loc
);
2658 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2661 ? BFD_RELOC_SH_IMMS16
2669 = ((sh64_abi
== sh64_abi_64
&& ! sh64_pt32
)
2670 ? SH64PCREL16_64
: SH64PCREL16_32
);
2672 = ((sh64_abi
== sh64_abi_64
&& ! sh64_pt32
)
2673 ? SH64PCREL64
: SH64PCREL32
);
2674 offsetT min
= SH64PCREL16
;
2675 offsetT init
= UNDEF_SH64PCREL
;
2677 /* Don't allow complex expressions here. */
2678 if (opjp
->immediate
.X_op_symbol
!= NULL
)
2680 as_bad (_("invalid operand: expression in PT target"));
2684 if (opjp
->reloctype
== BFD_RELOC_32_PLT_PCREL
)
2685 init
= max
= min
= SH64PCRELPLT
;
2687 /* If we're not expanding, then just emit a fixup. */
2688 if (sh64_expand
|| opjp
->reloctype
!= BFD_RELOC_NONE
)
2689 frag_var (rs_machine_dependent
,
2690 md_relax_table
[C (what
, max
)].rlx_length
,
2691 md_relax_table
[C (what
, min
)].rlx_length
,
2693 opjp
->immediate
.X_add_symbol
,
2694 opjp
->immediate
.X_add_number
,
2697 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 1,
2698 opjp
->reloctype
== BFD_RELOC_NONE
2699 ? BFD_RELOC_SH_PT_16
2706 case A_PCIMMS16BY4_PT
:
2709 = ((sh64_abi
== sh64_abi_64
&& ! sh64_pt32
)
2710 ? SH64PCREL16PT_64
: SH64PCREL16PT_32
);
2712 = ((sh64_abi
== sh64_abi_64
&& ! sh64_pt32
)
2713 ? SH64PCREL64
: SH64PCREL32
);
2714 offsetT min
= SH64PCREL16
;
2715 offsetT init
= UNDEF_SH64PCREL
;
2717 /* Don't allow complex expressions here. */
2718 if (opjp
->immediate
.X_op_symbol
!= NULL
)
2720 as_bad (_("invalid operand: expression in PT target"));
2724 if (opjp
->reloctype
== BFD_RELOC_32_PLT_PCREL
)
2725 init
= max
= min
= SH64PCRELPLT
;
2727 /* If we're not expanding, then just emit a fixup. */
2728 if (sh64_expand
|| opjp
->reloctype
!= BFD_RELOC_NONE
)
2729 frag_var (rs_machine_dependent
,
2730 md_relax_table
[C (what
, max
)].rlx_length
,
2731 md_relax_table
[C (what
, min
)].rlx_length
,
2733 opjp
->immediate
.X_add_symbol
,
2734 opjp
->immediate
.X_add_number
,
2737 /* This reloc-type is just temporary, so we can distinguish
2738 PTA from PT. It is changed in shmedia_md_apply_fix to
2739 BFD_RELOC_SH_PT_16. */
2740 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 1,
2741 opjp
->reloctype
== BFD_RELOC_NONE
2742 ? SHMEDIA_BFD_RELOC_PT
2750 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2751 BFD_RELOC_SH_IMMU5
);
2756 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2757 BFD_RELOC_SH_IMMU6
);
2762 insn
|= shmedia_immediate_op (insn_loc
, opjp
, 0,
2765 ? BFD_RELOC_SH_IMMU16
2775 md_number_to_chars (insn_loc
, insn
, 4);
2779 /* Assemble a SHmedia instruction. */
2782 shmedia_md_assemble (char *str
)
2785 shmedia_opcode_info
*opcode
;
2786 shmedia_operands_info operands
;
2789 opcode
= shmedia_find_cooked_opcode (&str
);
2794 as_bad (_("unknown opcode"));
2798 /* Start a SHmedia code region, if there has been pseudoinsns or similar
2799 seen since the last one. */
2802 sh64_update_contents_mark (TRUE
);
2803 sh64_set_contents_type (CRT_SH5_ISA32
);
2807 op_end
= shmedia_get_operands (opcode
, op_end
, &operands
);
2811 as_bad (_("invalid operands to %s"), opcode
->name
);
2817 as_bad (_("excess operands to %s"), opcode
->name
);
2821 size
= shmedia_build_Mytes (opcode
, &operands
);
2826 /* Hook called from md_begin in tc-sh.c. */
2829 shmedia_md_begin (void)
2831 const shmedia_opcode_info
*shmedia_opcode
;
2832 shmedia_opcode_hash_control
= hash_new ();
2834 /* Create opcode table for SHmedia mnemonics. */
2835 for (shmedia_opcode
= shmedia_table
;
2836 shmedia_opcode
->name
;
2838 hash_insert (shmedia_opcode_hash_control
, shmedia_opcode
->name
,
2839 (char *) shmedia_opcode
);
2842 /* Switch instruction set. Only valid if one of the --isa or --abi
2843 options was specified. */
2846 s_sh64_mode (int ignore ATTRIBUTE_UNUSED
)
2848 char *name
= input_line_pointer
, ch
;
2850 /* Make sure data up to this location is handled according to the
2852 sh64_update_contents_mark (TRUE
);
2854 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2855 input_line_pointer
++;
2856 ch
= *input_line_pointer
;
2857 *input_line_pointer
= '\0';
2859 /* If the mode was not set before, explicitly or implicitly, then we're
2860 not emitting SH64 code, so this pseudo is invalid. */
2861 if (sh64_isa_mode
== sh64_isa_unspecified
)
2862 as_bad (_("The `.mode %s' directive is not valid with this architecture"),
2865 if (strcasecmp (name
, "shcompact") == 0)
2866 sh64_isa_mode
= sh64_isa_shcompact
;
2867 else if (strcasecmp (name
, "shmedia") == 0)
2868 sh64_isa_mode
= sh64_isa_shmedia
;
2870 as_bad (_("Invalid argument to .mode: %s"), name
);
2872 /* Make a new frag, marking it with the supposedly-changed ISA. */
2873 frag_wane (frag_now
);
2876 /* Contents type up to this new point is the same as before; don't add a
2877 data region just because the new frag we created. */
2878 sh64_update_contents_mark (FALSE
);
2880 *input_line_pointer
= ch
;
2881 demand_empty_rest_of_line ();
2884 /* Check that the right ABI is used. Only valid if one of the --isa or
2885 --abi options was specified. */
2888 s_sh64_abi (int ignore ATTRIBUTE_UNUSED
)
2890 char *name
= input_line_pointer
, ch
;
2892 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2893 input_line_pointer
++;
2894 ch
= *input_line_pointer
;
2895 *input_line_pointer
= '\0';
2897 /* If the mode was not set before, explicitly or implicitly, then we're
2898 not emitting SH64 code, so this pseudo is invalid. */
2899 if (sh64_abi
== sh64_abi_unspecified
)
2900 as_bad (_("The `.abi %s' directive is not valid with this architecture"),
2903 if (strcmp (name
, "64") == 0)
2905 if (sh64_abi
!= sh64_abi_64
)
2906 as_bad (_("`.abi 64' but command-line options do not specify 64-bit ABI"));
2908 else if (strcmp (name
, "32") == 0)
2910 if (sh64_abi
!= sh64_abi_32
)
2911 as_bad (_("`.abi 32' but command-line options do not specify 32-bit ABI"));
2914 as_bad (_("Invalid argument to .abi: %s"), name
);
2916 *input_line_pointer
= ch
;
2917 demand_empty_rest_of_line ();
2920 /* This function is the first target-specific function called after
2921 parsing command-line options. Therefore we set default values from
2922 command-line options here and do some sanity checking we couldn't do
2923 when options were being parsed. */
2926 sh64_target_format (void)
2929 /* For NetBSD, if the ISA is unspecified, always use SHmedia. */
2930 if (preset_target_arch
== 0 && sh64_isa_mode
== sh64_isa_unspecified
)
2931 sh64_isa_mode
= sh64_isa_shmedia
;
2933 /* If the ABI is unspecified, select a default: based on how
2934 we were configured: sh64 == sh64_abi_64, else sh64_abi_32. */
2935 if (sh64_abi
== sh64_abi_unspecified
)
2937 if (preset_target_arch
!= 0 || sh64_isa_mode
== sh64_isa_shcompact
)
2938 sh64_abi
= sh64_abi_32
;
2939 else if (strncmp (TARGET_CPU
, "sh64", 4) == 0)
2940 sh64_abi
= sh64_abi_64
;
2942 sh64_abi
= sh64_abi_32
;
2947 if (preset_target_arch
== 0 && sh64_isa_mode
== sh64_isa_unspecified
)
2948 sh64_isa_mode
= sh64_isa_shmedia
;
2950 if (sh64_abi
== sh64_abi_unspecified
)
2951 sh64_abi
= sh64_abi_32
;
2954 if (sh64_abi
== sh64_abi_64
&& sh64_isa_mode
== sh64_isa_unspecified
)
2955 sh64_isa_mode
= sh64_isa_shmedia
;
2957 if (sh64_abi
== sh64_abi_32
&& sh64_isa_mode
== sh64_isa_unspecified
)
2958 sh64_isa_mode
= sh64_isa_shcompact
;
2960 if (sh64_isa_mode
== sh64_isa_shcompact
2961 && sh64_abi
== sh64_abi_unspecified
)
2962 sh64_abi
= sh64_abi_32
;
2964 if (sh64_isa_mode
== sh64_isa_shmedia
2965 && sh64_abi
== sh64_abi_unspecified
)
2966 sh64_abi
= sh64_abi_64
;
2968 if (sh64_isa_mode
== sh64_isa_unspecified
&& ! sh64_mix
)
2969 as_bad (_("-no-mix is invalid without specifying SHcompact or SHmedia"));
2971 if ((sh64_isa_mode
== sh64_isa_unspecified
2972 || sh64_isa_mode
== sh64_isa_shmedia
)
2973 && sh64_shcompact_const_crange
)
2974 as_bad (_("-shcompact-const-crange is invalid without SHcompact"));
2976 if (sh64_pt32
&& sh64_abi
!= sh64_abi_64
)
2977 as_bad (_("-expand-pt32 only valid with -abi=64"));
2979 if (! sh64_expand
&& sh64_isa_mode
== sh64_isa_unspecified
)
2980 as_bad (_("-no-expand only valid with SHcompact or SHmedia"));
2982 if (sh64_pt32
&& ! sh64_expand
)
2983 as_bad (_("-expand-pt32 invalid together with -no-expand"));
2986 if (sh64_abi
== sh64_abi_64
)
2987 return (target_big_endian
? "elf64-sh64-nbsd" : "elf64-sh64l-nbsd");
2989 return (target_big_endian
? "elf32-sh64-nbsd" : "elf32-sh64l-nbsd");
2990 #elif defined (TE_LINUX)
2991 if (sh64_abi
== sh64_abi_64
)
2992 return (target_big_endian
? "elf64-sh64big-linux" : "elf64-sh64-linux");
2994 return (target_big_endian
? "elf32-sh64big-linux" : "elf32-sh64-linux");
2996 /* When the ISA is not one of SHmedia or SHcompact, use the old SH
2998 if (sh64_isa_mode
== sh64_isa_unspecified
)
2999 return (target_big_endian
? "elf32-sh" : "elf32-shl");
3000 else if (sh64_abi
== sh64_abi_64
)
3001 return (target_big_endian
? "elf64-sh64" : "elf64-sh64l");
3003 return (target_big_endian
? "elf32-sh64" : "elf32-sh64l");
3007 /* The worker function of TARGET_MACH. */
3010 sh64_target_mach (void)
3012 /* We need to explicitly set bfd_mach_sh5 instead of the default 0. But
3013 we only do this for the 64-bit ABI: if we do it for the 32-bit ABI,
3014 the SH5 info in the bfd_arch_info structure will be selected.
3015 However correct, as the machine has 64-bit addresses, functions
3016 expected to emit 32-bit data for addresses will start failing. For
3017 example, the dwarf2dbg.c functions will emit 64-bit debugging format,
3018 and we don't want that in the 32-bit ABI.
3020 We could have two bfd_arch_info structures for SH64; one for the
3021 32-bit ABI and one for the rest (64-bit ABI). But that would be a
3022 bigger kludge: it's a flaw in the BFD design, and we need to just
3023 work around it by having the default machine set here in the
3024 assembler. For everything else but the assembler, the various bfd
3025 functions will set the machine type right to bfd_mach_sh5 from object
3026 file header flags regardless of the 0 here. */
3028 return (sh64_abi
== sh64_abi_64
) ? bfd_mach_sh5
: 0;
3031 /* This is MD_PCREL_FROM_SECTION, we we define so it is called instead of
3032 md_pcrel_from (in tc-sh.c). */
3035 shmedia_md_pcrel_from_section (struct fix
*fixP
, segT sec ATTRIBUTE_UNUSED
)
3037 /* Use the ISA for the instruction to decide which offset to use. We
3038 can glean it from the fisup type. */
3039 switch (fixP
->fx_r_type
)
3041 case BFD_RELOC_SH_IMM_LOW16
:
3042 case BFD_RELOC_SH_IMM_MEDLOW16
:
3043 case BFD_RELOC_SH_IMM_MEDHI16
:
3044 case BFD_RELOC_SH_IMM_HI16
:
3045 case BFD_RELOC_SH_IMM_LOW16_PCREL
:
3046 case BFD_RELOC_SH_IMM_MEDLOW16_PCREL
:
3047 case BFD_RELOC_SH_IMM_MEDHI16_PCREL
:
3048 case BFD_RELOC_SH_IMM_HI16_PCREL
:
3049 case BFD_RELOC_SH_IMMU5
:
3050 case BFD_RELOC_SH_IMMU6
:
3051 case BFD_RELOC_SH_IMMS6
:
3052 case BFD_RELOC_SH_IMMS10
:
3053 case BFD_RELOC_SH_IMMS10BY2
:
3054 case BFD_RELOC_SH_IMMS10BY4
:
3055 case BFD_RELOC_SH_IMMS10BY8
:
3056 case BFD_RELOC_SH_IMMS16
:
3057 case BFD_RELOC_SH_IMMU16
:
3058 case BFD_RELOC_SH_PT_16
:
3059 case SHMEDIA_BFD_RELOC_PT
:
3060 /* PC-relative relocs are relative to the address of the last generated
3061 instruction, i.e. fx_size - 4. */
3062 return SHMEDIA_MD_PCREL_FROM_FIX (fixP
);
3065 case BFD_RELOC_64_PCREL
:
3069 /* If section was SHcompact, use its function. */
3070 return (valueT
) md_pcrel_from_section (fixP
, sec
);
3073 know (0 /* Shouldn't get here. */);
3077 /* Create one .cranges descriptor from two symbols, STARTSYM marking begin
3078 and ENDSYM marking end, and CR_TYPE specifying the type. */
3081 sh64_emit_crange (symbolS
*startsym
, symbolS
*endsym
,
3082 enum sh64_elf_cr_type cr_type
)
3085 segT current_seg
= now_seg
;
3086 subsegT current_subseg
= now_subseg
;
3089 = bfd_make_section_old_way (stdoutput
,
3090 SH64_CRANGES_SECTION_NAME
);
3092 /* Temporarily change to the .cranges section. */
3093 subseg_set (cranges
, 0);
3095 /* Emit the cr_addr part. */
3096 exp
.X_op
= O_symbol
;
3097 exp
.X_add_number
= 0;
3098 exp
.X_op_symbol
= NULL
;
3099 exp
.X_add_symbol
= startsym
;
3100 emit_expr (&exp
, 4);
3102 /* Emit the cr_size part. */
3103 exp
.X_op
= O_subtract
;
3104 exp
.X_add_number
= 0;
3105 exp
.X_add_symbol
= endsym
;
3106 exp
.X_op_symbol
= startsym
;
3107 emit_expr (&exp
, 4);
3109 /* Emit the cr_size part. */
3110 exp
.X_op
= O_constant
;
3111 exp
.X_add_number
= cr_type
;
3112 exp
.X_add_symbol
= NULL
;
3113 exp
.X_op_symbol
= NULL
;
3114 emit_expr (&exp
, 2);
3116 /* Now back to our regular program. */
3117 subseg_set (current_seg
, current_subseg
);
3120 /* Called when the assembler is about to emit contents of some type into
3121 SEG, so it is *known* that the type of that new contents is in
3122 NEW_CONTENTS_TYPE. If just switching back and forth between different
3123 contents types (for example, with consecutive .mode pseudos), then this
3124 function isn't called. */
3127 sh64_set_contents_type (enum sh64_elf_cr_type new_contents_type
)
3129 segment_info_type
*seginfo
;
3131 /* We will not be called when emitting .cranges output, since callers
3132 stop that. Validize that assumption. */
3133 know (!emitting_crange
);
3135 seginfo
= seg_info (now_seg
);
3139 symbolS
*symp
= seginfo
->tc_segment_info_data
.last_contents_mark
;
3141 enum sh64_elf_cr_type contents_type
3142 = seginfo
->tc_segment_info_data
.contents_type
;
3144 /* If it was just SHcompact switching between code and constant
3145 pool, don't change contents type. Just make sure we don't set
3146 the contents type to data, as that would join with a data-region
3148 if (sh64_isa_mode
== sh64_isa_shcompact
3149 && ! sh64_shcompact_const_crange
)
3150 new_contents_type
= CRT_SH5_ISA16
;
3152 /* If nothing changed, stop here. */
3153 if (contents_type
== new_contents_type
)
3156 /* If we're in 64-bit ABI mode, we do not emit .cranges, as it is
3157 only specified for 32-bit addresses. It could presumably be
3158 extended, but in 64-bit ABI mode we don't have SHcompact code, so
3159 we would only use it to mark code and data. */
3160 if (sh64_abi
== sh64_abi_64
)
3162 /* Make the code type "sticky". We don't want to set the
3163 sections contents type to data if there's any code in it as
3164 we don't have .cranges in 64-bit mode to notice the
3166 seginfo
->tc_segment_info_data
.contents_type
3167 = (new_contents_type
== CRT_SH5_ISA32
3168 || contents_type
== CRT_SH5_ISA32
)
3169 ? CRT_SH5_ISA32
: new_contents_type
;
3173 /* If none was marked, create a start symbol for this range and
3174 perhaps as a closing symbol for the old one. */
3176 symp
= symbol_new (FAKE_LABEL_NAME
, now_seg
, (valueT
) frag_now_fix (),
3179 /* We will use this symbol, so don't leave a pointer behind. */
3180 seginfo
->tc_segment_info_data
.last_contents_mark
= NULL
;
3182 /* We'll be making only datalabel references to it, if we emit a
3183 .cranges descriptor, so remove any code flag. */
3184 S_SET_OTHER (symp
, S_GET_OTHER (symp
) & ~STO_SH5_ISA32
);
3186 /* If we have already marked the start of a range, we need to close
3187 and emit it before marking a new one, so emit a new .cranges
3188 descriptor into the .cranges section. */
3189 if (seginfo
->tc_segment_info_data
.mode_start_symbol
)
3191 /* If we're not supposed to emit mixed-mode sections, make it an
3192 error, but continue processing. */
3194 && (new_contents_type
== CRT_SH5_ISA32
3195 || contents_type
== CRT_SH5_ISA32
))
3197 _("SHmedia code not allowed in same section as constants and SHcompact code"));
3199 emitting_crange
= TRUE
;
3200 sh64_emit_crange (seginfo
->tc_segment_info_data
.mode_start_symbol
,
3201 symp
, contents_type
);
3202 emitting_crange
= FALSE
;
3203 seginfo
->tc_segment_info_data
.emitted_ranges
++;
3206 seginfo
->tc_segment_info_data
.mode_start_symbol
= symp
;
3207 seginfo
->tc_segment_info_data
.mode_start_subseg
= now_subseg
;
3208 seginfo
->tc_segment_info_data
.contents_type
= new_contents_type
;
3210 /* Always reset this, so the SHcompact code will emit a reloc when
3211 it prepares to relax. */
3212 seginfo
->tc_segment_info_data
.in_code
= 0;
3215 as_bad (_("No segment info for current section"));
3218 /* Hook when defining symbols and labels. We set the ST_OTHER field if
3219 the symbol is "shmedia" (with "bitor 1" automatically applied). Simple
3220 semantics for a label being "shmedia" : It was defined when .mode
3221 SHmedia was in effect, and it was defined in a code section. It
3222 doesn't matter whether or not an assembled opcode is nearby. */
3225 sh64_frob_label (symbolS
*symp
)
3227 segT seg
= S_GET_SEGMENT (symp
);
3228 static const symbolS
*null
= NULL
;
3230 /* Reset the tc marker for all newly created symbols. */
3231 symbol_set_tc (symp
, (symbolS
**) &null
);
3233 if (seg
!= NULL
&& sh64_isa_mode
== sh64_isa_shmedia
&& subseg_text_p (seg
))
3234 S_SET_OTHER (symp
, S_GET_OTHER (symp
) | STO_SH5_ISA32
);
3237 /* Handle the "datalabel" qualifier. We need to call "operand", but it's
3238 static, so a function pointer is passed here instead. FIXME: A target
3239 hook for qualifiers is needed; we currently use the md_parse_name
3243 sh64_consume_datalabel (const char *name
, expressionS
*exp
,
3244 enum expr_mode mode
, char *cp
,
3245 segT (*operandf
) (expressionS
*, enum expr_mode
))
3247 static int parsing_datalabel
= 0;
3249 if (strcasecmp (name
, "datalabel") == 0)
3251 int save_parsing_datalabel
= parsing_datalabel
;
3253 if (parsing_datalabel
)
3254 as_bad (_("duplicate datalabel operator ignored"));
3256 *input_line_pointer
= *cp
;
3257 parsing_datalabel
= 1;
3258 (*operandf
) (exp
, expr_normal
);
3259 parsing_datalabel
= save_parsing_datalabel
;
3261 if (exp
->X_op
== O_symbol
|| exp
->X_op
== O_PIC_reloc
)
3263 symbolS
*symp
= exp
->X_add_symbol
;
3264 segT symseg
= S_GET_SEGMENT (symp
);
3266 /* If the symbol is defined to something that is already a
3267 datalabel, we don't need to bother with any special handling. */
3268 if (symseg
!= undefined_section
3269 && S_GET_OTHER (symp
) != STO_SH5_ISA32
)
3275 const char * sname
= S_GET_NAME (symp
);
3277 = xmalloc (strlen (sname
) + sizeof (DATALABEL_SUFFIX
));
3279 /* Now we copy the datalabel-qualified symbol into a symbol
3280 with the same name, but with " DL" appended. We mark the
3281 symbol using the TC_SYMFIELD_TYPE field with a pointer to
3282 the main symbol, so we don't have to inspect all symbol
3283 names. Note that use of "datalabel" is not expected to
3284 be a common case. */
3285 strcpy (dl_name
, sname
);
3286 strcat (dl_name
, DATALABEL_SUFFIX
);
3288 /* A FAKE_LABEL_NAME marks "$" or ".". There can be any
3289 number of them and all have the same (faked) name; we
3290 must make a new one each time. */
3291 if (strcmp (sname
, FAKE_LABEL_NAME
) == 0)
3292 dl_symp
= symbol_make (dl_name
);
3294 dl_symp
= symbol_find_or_make (dl_name
);
3297 symbol_set_value_expression (dl_symp
,
3298 symbol_get_value_expression (symp
));
3299 S_SET_SEGMENT (dl_symp
, symseg
);
3300 symbol_set_frag (dl_symp
, symbol_get_frag (symp
));
3301 symbol_set_tc (dl_symp
, &symp
);
3302 copy_symbol_attributes (dl_symp
, symp
);
3303 exp
->X_add_symbol
= dl_symp
;
3305 /* Unset the BranchTarget mark that can be set at symbol
3306 creation or attributes copying. */
3307 S_SET_OTHER (dl_symp
, S_GET_OTHER (dl_symp
) & ~STO_SH5_ISA32
);
3309 /* The GLOBAL and WEAK attributes are not copied over by
3310 copy_symbol_attributes. Do it here. */
3311 if (S_IS_WEAK (symp
))
3312 S_SET_WEAK (dl_symp
);
3313 else if (S_IS_EXTERNAL (symp
))
3314 S_SET_EXTERNAL (dl_symp
);
3317 /* Complain about other types of operands than symbol, unless they
3318 have already been complained about. A constant is always a
3319 datalabel. Removing the low bit would therefore be wrong.
3320 Complaining about it would also be wrong. */
3321 else if (exp
->X_op
!= O_illegal
3322 && exp
->X_op
!= O_absent
3323 && exp
->X_op
!= O_constant
)
3324 as_bad (_("Invalid DataLabel expression"));
3326 *cp
= *input_line_pointer
;
3331 return sh_parse_name (name
, exp
, mode
, cp
);
3334 /* This function is called just before symbols are being output. It
3335 returns zero when a symbol must be output, non-zero otherwise.
3336 Datalabel references that were fully resolved to local symbols are not
3337 necessary to output. We also do not want to output undefined symbols
3338 that are not used in relocs. For symbols that are used in a reloc, it
3339 does not matter what we set here. If it is *not* used in a reloc, then
3340 it was probably the datalabel counterpart that was used in a reloc;
3341 then we need not output the main symbol. */
3344 sh64_exclude_symbol (symbolS
*symp
)
3346 symbolS
*main_symbol
= *symbol_get_tc (symp
);
3348 return main_symbol
!= NULL
|| ! S_IS_DEFINED (symp
);
3351 /* If we haven't seen an insn since the last update, and location
3352 indicators have moved (a new frag, new location within frag) we have
3353 emitted data, so change contents type to data. Forget that we have
3354 seen a sequence of insns and store the current location so we can mark
3355 a new region if needed. */
3358 sh64_update_contents_mark (bfd_boolean update_type
)
3360 segment_info_type
*seginfo
;
3361 seginfo
= seg_info (now_seg
);
3363 if (seginfo
!= NULL
)
3365 symbolS
*symp
= seginfo
->tc_segment_info_data
.last_contents_mark
;
3369 symp
= symbol_new (FAKE_LABEL_NAME
, now_seg
,
3370 (valueT
) frag_now_fix (), frag_now
);
3371 seginfo
->tc_segment_info_data
.last_contents_mark
= symp
;
3375 /* If we have moved location since last flush, we need to emit a
3376 data range. The previous contents type ended at the location
3377 of the last update. */
3378 if ((S_GET_VALUE (symp
) != frag_now_fix ()
3379 || symbol_get_frag (symp
) != frag_now
))
3381 enum sh64_elf_cr_type contents_type
3382 = seginfo
->tc_segment_info_data
.contents_type
;
3385 && contents_type
!= CRT_DATA
3386 && contents_type
!= CRT_NONE
3389 sh64_set_contents_type (CRT_DATA
);
3390 symp
= seginfo
->tc_segment_info_data
.last_contents_mark
;
3393 /* If the symbol wasn't used up to make up a new range
3394 descriptor, update it to this new location. */
3397 S_SET_VALUE (symp
, (valueT
) frag_now_fix ());
3398 symbol_set_frag (symp
, frag_now
);
3407 /* Called when the assembler is about to output some data, or maybe it's
3408 just switching segments. */
3411 sh64_flush_pending_output (void)
3413 sh64_update_contents_mark (TRUE
);
3414 sh_flush_pending_output ();
3417 /* Flush out the last crange descriptor after all insns have been emitted. */
3420 sh64_flush_last_crange (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*seg
,
3421 void *countparg ATTRIBUTE_UNUSED
)
3423 segment_info_type
*seginfo
;
3425 seginfo
= seg_info (seg
);
3428 /* Only emit .cranges descriptors if we would make it more than one. */
3429 && seginfo
->tc_segment_info_data
.emitted_ranges
!= 0)
3433 /* We need a closing symbol, so switch to the indicated section and
3436 /* Change to the section we're about to handle. */
3437 subseg_set (seg
, seginfo
->tc_segment_info_data
.mode_start_subseg
);
3439 symp
= symbol_new (FAKE_LABEL_NAME
, now_seg
, (valueT
) frag_now_fix (),
3442 /* We'll be making a datalabel reference to it, so remove any code
3444 S_SET_OTHER (symp
, S_GET_OTHER (symp
) & ~STO_SH5_ISA32
);
3446 sh64_emit_crange (seginfo
->tc_segment_info_data
.mode_start_symbol
,
3448 seginfo
->tc_segment_info_data
.contents_type
);
3452 /* If and only if we see a call to md_number_to_chars without flagging the
3453 start of an insn, we set the contents type to CRT_DATA, and only when
3454 in SHmedia mode. Note that by default we don't bother changing when
3455 going from SHcompact to data, as the constant pools in GCC-generated
3456 SHcompact code would create an inordinate amount of .cranges
3460 sh64_flag_output (void)
3462 if (sh64_isa_mode
!= sh64_isa_unspecified
3464 && !sh64_end_of_assembly
3465 && !emitting_crange
)
3467 md_flush_pending_output ();
3468 sh64_set_contents_type (CRT_DATA
);
3472 /* Vtables don't need "datalabel" but we allow it by simply deleting
3476 strip_datalabels (void)
3478 char *src
, *dest
, *start
=input_line_pointer
;
3480 for (src
=input_line_pointer
, dest
=input_line_pointer
; *src
!= '\n'; )
3482 if (strncasecmp (src
, "datalabel", 9) == 0
3484 && (src
== start
|| !(ISALNUM (src
[-1])) || src
[-1] == '_'))
3496 sh64_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
3498 char *eol
= strip_datalabels ();
3500 obj_elf_vtable_entry (0);
3501 input_line_pointer
= eol
;
3505 sh64_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
3507 char *eol
= strip_datalabels ();
3509 obj_elf_vtable_inherit (0);
3510 input_line_pointer
= eol
;
3514 sh64_fake_label (const char *name
)
3518 if (strcmp (name
, FAKE_LABEL_NAME
) == 0)
3521 len
= strlen (name
);
3522 if (len
>= (sizeof (DATALABEL_SUFFIX
) - 1))
3523 return strcmp (&name
[len
- sizeof (DATALABEL_SUFFIX
) + 1],
3524 DATALABEL_SUFFIX
) == 0;