1 /* tc-rx.c -- Assembler for the Renesas RX
2 Copyright (C) 2008-2019 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 the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "safe-ctype.h"
23 #include "dwarf2dbg.h"
24 #include "elf/common.h"
27 #include "filenames.h"
32 #define RX_OPCODE_BIG_ENDIAN 0
34 const char comment_chars
[] = ";";
35 /* Note that input_file.c hand checks for '#' at the beginning of the
36 first line of the input file. This is because the compiler outputs
37 #NO_APP at the beginning of its output. */
38 const char line_comment_chars
[] = "#";
39 const char line_separator_chars
[] = "!";
41 const char EXP_CHARS
[] = "eE";
42 const char FLT_CHARS
[] = "dD";
44 /* ELF flags to set in the output file header. */
45 static int elf_flags
= E_FLAG_RX_ABI
;
48 bfd_boolean rx_use_conventional_section_names
= FALSE
;
50 bfd_boolean rx_use_conventional_section_names
= TRUE
;
52 static bfd_boolean rx_use_small_data_limit
= FALSE
;
54 static bfd_boolean rx_pid_mode
= FALSE
;
55 static int rx_num_int_regs
= 0;
59 enum rx_cpu_types rx_cpu
= RX600
;
61 static void rx_fetchalign (int ignore ATTRIBUTE_UNUSED
);
65 OPTION_BIG
= OPTION_MD_BASE
,
69 OPTION_CONVENTIONAL_SECTION_NAMES
,
70 OPTION_RENESAS_SECTION_NAMES
,
71 OPTION_SMALL_DATA_LIMIT
,
78 OPTION_DISALLOW_STRING_INSNS
,
81 #define RX_SHORTOPTS ""
82 const char * md_shortopts
= RX_SHORTOPTS
;
84 /* Assembler options. */
85 struct option md_longopts
[] =
87 {"mbig-endian-data", no_argument
, NULL
, OPTION_BIG
},
88 {"mlittle-endian-data", no_argument
, NULL
, OPTION_LITTLE
},
89 /* The next two switches are here because the
90 generic parts of the linker testsuite uses them. */
91 {"EB", no_argument
, NULL
, OPTION_BIG
},
92 {"EL", no_argument
, NULL
, OPTION_LITTLE
},
93 {"m32bit-doubles", no_argument
, NULL
, OPTION_32BIT_DOUBLES
},
94 {"m64bit-doubles", no_argument
, NULL
, OPTION_64BIT_DOUBLES
},
95 /* This option is here mainly for the binutils testsuites,
96 as many of their tests assume conventional section naming. */
97 {"muse-conventional-section-names", no_argument
, NULL
, OPTION_CONVENTIONAL_SECTION_NAMES
},
98 {"muse-renesas-section-names", no_argument
, NULL
, OPTION_RENESAS_SECTION_NAMES
},
99 {"msmall-data-limit", no_argument
, NULL
, OPTION_SMALL_DATA_LIMIT
},
100 {"relax", no_argument
, NULL
, OPTION_RELAX
},
101 {"mpid", no_argument
, NULL
, OPTION_PID
},
102 {"mint-register", required_argument
, NULL
, OPTION_INT_REGS
},
103 {"mgcc-abi", no_argument
, NULL
, OPTION_USES_GCC_ABI
},
104 {"mrx-abi", no_argument
, NULL
, OPTION_USES_RX_ABI
},
105 {"mcpu", required_argument
, NULL
, OPTION_CPU
},
106 {"mno-allow-string-insns", no_argument
, NULL
, OPTION_DISALLOW_STRING_INSNS
},
107 {NULL
, no_argument
, NULL
, 0}
109 size_t md_longopts_size
= sizeof (md_longopts
);
113 const char *cpu_name
;
114 enum rx_cpu_types type
;
118 struct cpu_type cpu_type_list
[] =
124 {"rxv2", RXV2
, E_FLAG_RX_V2
},
125 {"rxv3", RXV3
, E_FLAG_RX_V3
},
126 {"rxv3-dfpu", RXV3FPU
, E_FLAG_RX_V3
},
130 md_parse_option (int c ATTRIBUTE_UNUSED
, const char * arg ATTRIBUTE_UNUSED
)
135 target_big_endian
= 1;
139 target_big_endian
= 0;
142 case OPTION_32BIT_DOUBLES
:
143 elf_flags
&= ~ E_FLAG_RX_64BIT_DOUBLES
;
146 case OPTION_64BIT_DOUBLES
:
147 elf_flags
|= E_FLAG_RX_64BIT_DOUBLES
;
150 case OPTION_CONVENTIONAL_SECTION_NAMES
:
151 rx_use_conventional_section_names
= TRUE
;
154 case OPTION_RENESAS_SECTION_NAMES
:
155 rx_use_conventional_section_names
= FALSE
;
158 case OPTION_SMALL_DATA_LIMIT
:
159 rx_use_small_data_limit
= TRUE
;
168 elf_flags
|= E_FLAG_RX_PID
;
171 case OPTION_INT_REGS
:
172 rx_num_int_regs
= atoi (optarg
);
175 case OPTION_USES_GCC_ABI
:
176 elf_flags
&= ~ E_FLAG_RX_ABI
;
179 case OPTION_USES_RX_ABI
:
180 elf_flags
|= E_FLAG_RX_ABI
;
186 for (i
= 0; i
< ARRAY_SIZE (cpu_type_list
); i
++)
188 if (strcasecmp (arg
, cpu_type_list
[i
].cpu_name
) == 0)
190 rx_cpu
= cpu_type_list
[i
].type
;
191 elf_flags
|= cpu_type_list
[i
].flag
;
195 as_warn (_("unrecognised RX CPU type %s"), arg
);
199 case OPTION_DISALLOW_STRING_INSNS
:
200 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
;
208 md_show_usage (FILE * stream
)
210 fprintf (stream
, _(" RX specific command line options:\n"));
211 fprintf (stream
, _(" --mbig-endian-data\n"));
212 fprintf (stream
, _(" --mlittle-endian-data [default]\n"));
213 fprintf (stream
, _(" --m32bit-doubles [default]\n"));
214 fprintf (stream
, _(" --m64bit-doubles\n"));
215 fprintf (stream
, _(" --muse-conventional-section-names\n"));
216 fprintf (stream
, _(" --muse-renesas-section-names [default]\n"));
217 fprintf (stream
, _(" --msmall-data-limit\n"));
218 fprintf (stream
, _(" --mrelax\n"));
219 fprintf (stream
, _(" --mpid\n"));
220 fprintf (stream
, _(" --mint-register=<value>\n"));
221 fprintf (stream
, _(" --mcpu=<rx100|rx200|rx600|rx610|rxv2|rxv3|rxv3-dfpu>\n"));
222 fprintf (stream
, _(" --mno-allow-string-insns"));
226 s_bss (int ignore ATTRIBUTE_UNUSED
)
230 temp
= get_absolute_expression ();
231 subseg_set (bss_section
, (subsegT
) temp
);
232 demand_empty_rest_of_line ();
236 rx_float_cons (int ignore ATTRIBUTE_UNUSED
)
238 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
239 return float_cons ('d');
240 return float_cons ('f');
244 rx_strcasestr (const char *string
, const char *sub
)
250 return (char *)string
;
253 strl
= strlen (string
);
257 /* strncasecmp is in libiberty. */
258 if (strncasecmp (string
, sub
, subl
) == 0)
259 return (char *)string
;
268 rx_include (int ignore
)
273 const char * current_filename
;
281 /* The RX version of the .INCLUDE pseudo-op does not
282 have to have the filename inside double quotes. */
284 if (*input_line_pointer
== '"')
286 /* Treat as the normal GAS .include pseudo-op. */
291 /* Get the filename. Spaces are allowed, NUL characters are not. */
292 filename
= input_line_pointer
;
293 last_char
= find_end_of_line (filename
, FALSE
);
294 input_line_pointer
= last_char
;
296 while (last_char
>= filename
&& (* last_char
== ' ' || * last_char
== '\n'))
298 end_char
= *(++ last_char
);
300 if (last_char
== filename
)
302 as_bad (_("no filename following .INCLUDE pseudo-op"));
303 * last_char
= end_char
;
307 current_filename
= as_where (NULL
);
308 f
= XNEWVEC (char, strlen (current_filename
) + strlen (filename
) + 1);
310 /* Check the filename. If [@]..FILE[@] is found then replace
311 this with the current assembler source filename, stripped
312 of any directory prefixes or extensions. */
313 if ((p
= rx_strcasestr (filename
, "..file")) != NULL
)
317 len
= 6; /* strlen ("..file"); */
319 if (p
> filename
&& p
[-1] == '@')
325 for (d
= c
= current_filename
; *c
; c
++)
326 if (IS_DIR_SEPARATOR (* c
))
332 sprintf (f
, "%.*s%.*s%.*s", (int) (p
- filename
), filename
,
334 (int) (strlen (filename
) - ((p
+ len
) - filename
)),
338 strcpy (f
, filename
);
340 /* RX .INCLUDE semantics say that 'filename' is located by:
342 1. If filename is absolute, just try that. Otherwise...
344 2. If the current source file includes a directory component
345 then prepend that to the filename and try. Otherwise...
347 3. Try any directories specified by the -I command line
350 4 .Try a directory specified by the INC100 environment variable. */
352 if (IS_ABSOLUTE_PATH (f
))
353 try = fopen (path
= f
, FOPEN_RT
);
356 char * env
= getenv ("INC100");
360 len
= strlen (current_filename
);
361 if ((size_t) include_dir_maxlen
> len
)
362 len
= include_dir_maxlen
;
363 if (env
&& strlen (env
) > len
)
366 path
= XNEWVEC (char, strlen (f
) + len
+ 5);
368 if (current_filename
!= NULL
)
370 for (d
= NULL
, p
= current_filename
; *p
; p
++)
371 if (IS_DIR_SEPARATOR (* p
))
376 sprintf (path
, "%.*s/%s", (int) (d
- current_filename
), current_filename
,
378 try = fopen (path
, FOPEN_RT
);
386 for (i
= 0; i
< include_dir_count
; i
++)
388 sprintf (path
, "%s/%s", include_dirs
[i
], f
);
389 if ((try = fopen (path
, FOPEN_RT
)) != NULL
)
394 if (try == NULL
&& env
!= NULL
)
396 sprintf (path
, "%s/%s", env
, f
);
397 try = fopen (path
, FOPEN_RT
);
405 as_bad (_("unable to locate include file: %s"), filename
);
411 register_dependency (path
);
412 input_scrub_insert_file (path
);
415 * last_char
= end_char
;
419 parse_rx_section (char * name
)
423 int attr
= SHF_ALLOC
| SHF_EXECINSTR
;
432 for (p
= input_line_pointer
; *p
&& strchr ("\n\t, =", *p
) == NULL
; p
++)
437 if (strcasecmp (input_line_pointer
, "ALIGN") == 0)
452 case '2': align
= 1; break;
453 case '4': align
= 2; break;
454 case '8': align
= 3; break;
456 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p
);
457 ignore_rest_of_line ();
465 else if (strcasecmp (input_line_pointer
, "CODE") == 0)
466 attr
= SHF_ALLOC
| SHF_EXECINSTR
;
467 else if (strcasecmp (input_line_pointer
, "DATA") == 0)
468 attr
= SHF_ALLOC
| SHF_WRITE
;
469 else if (strcasecmp (input_line_pointer
, "ROMDATA") == 0)
473 as_bad (_("unknown parameter following .SECTION directive: %s"),
477 input_line_pointer
= p
+ 1;
478 ignore_rest_of_line ();
483 input_line_pointer
= p
+ 1;
485 while (end_char
!= '\n' && end_char
!= 0);
487 if ((sec
= bfd_get_section_by_name (stdoutput
, name
)) == NULL
)
489 if (strcmp (name
, "B") && strcmp (name
, "B_1") && strcmp (name
, "B_2"))
494 obj_elf_change_section (name
, type
, 0, attr
, 0, NULL
, FALSE
, FALSE
);
496 else /* Try not to redefine a section, especially B_1. */
498 int flags
= sec
->flags
;
500 type
= elf_section_type (sec
);
502 attr
= ((flags
& SEC_READONLY
) ? 0 : SHF_WRITE
)
503 | ((flags
& SEC_ALLOC
) ? SHF_ALLOC
: 0)
504 | ((flags
& SEC_CODE
) ? SHF_EXECINSTR
: 0)
505 | ((flags
& SEC_MERGE
) ? SHF_MERGE
: 0)
506 | ((flags
& SEC_STRINGS
) ? SHF_STRINGS
: 0)
507 | ((flags
& SEC_THREAD_LOCAL
) ? SHF_TLS
: 0);
509 obj_elf_change_section (name
, type
, 0, attr
, 0, NULL
, FALSE
, FALSE
);
512 bfd_set_section_alignment (stdoutput
, now_seg
, align
);
516 rx_section (int ignore
)
520 /* The as100 assembler supports a different syntax for the .section
521 pseudo-op. So check for it and handle it here if necessary. */
524 /* Peek past the section name to see if arguments follow. */
525 for (p
= input_line_pointer
; *p
; p
++)
526 if (*p
== ',' || *p
== '\n')
531 int len
= p
- input_line_pointer
;
533 while (ISSPACE (*++p
))
536 if (*p
!= '"' && *p
!= '#')
538 char *name
= xmemdup0 (input_line_pointer
, len
);
540 input_line_pointer
= p
;
541 parse_rx_section (name
);
546 obj_elf_section (ignore
);
550 rx_list (int ignore ATTRIBUTE_UNUSED
)
554 if (strncasecmp (input_line_pointer
, "OFF", 3))
556 else if (strncasecmp (input_line_pointer
, "ON", 2))
559 as_warn (_("expecting either ON or OFF after .list"));
562 /* Like the .rept pseudo op, but supports the
563 use of ..MACREP inside the repeated region. */
566 rx_rept (int ignore ATTRIBUTE_UNUSED
)
568 size_t count
= get_absolute_expression ();
570 do_repeat_with_expander (count
, "MREPEAT", "ENDR", "..MACREP");
573 /* Like cons() accept that strings are allowed. */
580 if (* input_line_pointer
== '"')
587 rx_nop (int ignore ATTRIBUTE_UNUSED
)
589 ignore_rest_of_line ();
595 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
596 md_pseudo_table
[idx
].poc_name
);
597 ignore_rest_of_line ();
600 /* The target specific pseudo-ops which we support. */
601 const pseudo_typeS md_pseudo_table
[] =
603 /* These are unimplemented. They're listed first so that we can use
604 the poc_value as the index into this array, to get the name of
605 the pseudo. So, keep these (1) first, and (2) in order, with (3)
606 the poc_value's in sequence. */
607 { "btglb", rx_unimp
, 0 },
608 { "call", rx_unimp
, 1 },
609 { "einsf", rx_unimp
, 2 },
610 { "fb", rx_unimp
, 3 },
611 { "fbsym", rx_unimp
, 4 },
612 { "id", rx_unimp
, 5 },
613 { "initsct", rx_unimp
, 6 },
614 { "insf", rx_unimp
, 7 },
615 { "instr", rx_unimp
, 8 },
616 { "lbba", rx_unimp
, 9 },
617 { "len", rx_unimp
, 10 },
618 { "optj", rx_unimp
, 11 },
619 { "rvector", rx_unimp
, 12 },
620 { "sb", rx_unimp
, 13 },
621 { "sbbit", rx_unimp
, 14 },
622 { "sbsym", rx_unimp
, 15 },
623 { "sbsym16", rx_unimp
, 16 },
625 /* These are the do-nothing pseudos. */
626 { "stk", rx_nop
, 0 },
627 /* The manual documents ".stk" but the compiler emits ".stack". */
628 { "stack", rx_nop
, 0 },
630 /* These are Renesas as100 assembler pseudo-ops that we do support. */
631 { "addr", rx_cons
, 3 },
632 { "align", s_align_bytes
, 2 },
633 { "byte", rx_cons
, 1 },
634 { "fixed", float_cons
, 'f' },
635 { "form", listing_psize
, 0 },
636 { "glb", s_globl
, 0 },
637 { "include", rx_include
, 0 },
638 { "list", rx_list
, 0 },
639 { "lword", rx_cons
, 4 },
640 { "mrepeat", rx_rept
, 0 },
641 { "section", rx_section
, 0 },
643 /* FIXME: The following pseudo-ops place their values (and associated
644 label if present) in the data section, regardless of whatever
645 section we are currently in. At the moment this code does not
646 implement that part of the semantics. */
647 { "blka", s_space
, 3 },
648 { "blkb", s_space
, 1 },
649 { "blkd", s_space
, 8 },
650 { "blkf", s_space
, 4 },
651 { "blkl", s_space
, 4 },
652 { "blkw", s_space
, 2 },
654 /* Our "standard" pseudos. */
655 { "double", rx_float_cons
, 0 },
657 { "3byte", cons
, 3 },
661 { "fetchalign", rx_fetchalign
, 0 },
663 /* End of list marker. */
667 static asymbol
* gp_symbol
;
668 static asymbol
* rx_pid_symbol
;
670 static symbolS
* rx_pidreg_symbol
;
671 static symbolS
* rx_gpreg_symbol
;
676 /* Make the __gp and __pid_base symbols now rather
677 than after the symbol table is frozen. We only do this
678 when supporting small data limits because otherwise we
679 pollute the symbol table. */
681 /* The meta-registers %pidreg and %gpreg depend on what other
682 options are specified. The __rx_*_defined symbols exist so we
683 can .ifdef asm code based on what options were passed to gas,
684 without needing a preprocessor */
688 rx_pid_register
= 13 - rx_num_int_regs
;
689 rx_pid_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
690 rx_pidreg_symbol
= symbol_find_or_make ("__rx_pidreg_defined");
691 S_SET_VALUE (rx_pidreg_symbol
, rx_pid_register
);
692 S_SET_SEGMENT (rx_pidreg_symbol
, absolute_section
);
695 if (rx_use_small_data_limit
)
698 rx_gp_register
= rx_pid_register
- 1;
700 rx_gp_register
= 13 - rx_num_int_regs
;
701 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
702 rx_gpreg_symbol
= symbol_find_or_make ("__rx_gpreg_defined");
703 S_SET_VALUE (rx_gpreg_symbol
, rx_gp_register
);
704 S_SET_SEGMENT (rx_gpreg_symbol
, absolute_section
);
711 /* These negative numbers are found in rx_bytesT.n_base for non-opcode
713 #define RX_NBASE_FETCHALIGN -1
715 typedef struct rx_bytesT
718 /* If this is negative, it's a special-purpose frag as per the defines above. */
727 char type
; /* RXREL_*. */
742 fixS
*link_relax_fixP
;
743 unsigned long times_grown
;
744 unsigned long times_shrank
;
747 static rx_bytesT rx_bytes
;
748 /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
749 static rx_bytesT
*fetchalign_bytes
= NULL
;
752 rx_fetchalign (int ignore ATTRIBUTE_UNUSED
)
757 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
758 rx_bytes
.n_base
= RX_NBASE_FETCHALIGN
;
760 bytes
= frag_more (8);
761 frag_then
= frag_now
;
762 frag_variant (rs_machine_dependent
,
769 frag_then
->fr_opcode
= bytes
;
770 frag_then
->fr_subtype
= 0;
771 fetchalign_bytes
= frag_then
->tc_frag_data
;
775 rx_relax (int type
, int pos
)
777 rx_bytes
.relax
[rx_bytes
.n_relax
].type
= type
;
778 rx_bytes
.relax
[rx_bytes
.n_relax
].field_pos
= pos
;
779 rx_bytes
.relax
[rx_bytes
.n_relax
].val_ofs
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
784 rx_linkrelax_dsp (int pos
)
789 rx_bytes
.link_relax
|= RX_RELAXA_DSP4
;
792 rx_bytes
.link_relax
|= RX_RELAXA_DSP6
;
795 rx_bytes
.link_relax
|= RX_RELAXA_DSP14
;
801 rx_linkrelax_imm (int pos
)
806 rx_bytes
.link_relax
|= RX_RELAXA_IMM6
;
809 rx_bytes
.link_relax
|= RX_RELAXA_IMM12
;
815 rx_linkrelax_branch (void)
817 rx_bytes
.link_relax
|= RX_RELAXA_BRA
;
821 rx_fixup (expressionS exp
, int offsetbits
, int nbits
, int type
)
823 rx_bytes
.fixups
[rx_bytes
.n_fixups
].exp
= exp
;
824 rx_bytes
.fixups
[rx_bytes
.n_fixups
].offset
= offsetbits
;
825 rx_bytes
.fixups
[rx_bytes
.n_fixups
].nbits
= nbits
;
826 rx_bytes
.fixups
[rx_bytes
.n_fixups
].type
= type
;
827 rx_bytes
.fixups
[rx_bytes
.n_fixups
].reloc
= exp
.X_md
;
828 rx_bytes
.n_fixups
++;
831 #define rx_field_fixup(exp, offset, nbits, type) \
832 rx_fixup (exp, offset, nbits, type)
834 #define rx_op_fixup(exp, offset, nbits, type) \
835 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
840 rx_bytes
.base
[0] = b1
;
845 rx_base2 (int b1
, int b2
)
847 rx_bytes
.base
[0] = b1
;
848 rx_bytes
.base
[1] = b2
;
853 rx_base3 (int b1
, int b2
, int b3
)
855 rx_bytes
.base
[0] = b1
;
856 rx_bytes
.base
[1] = b2
;
857 rx_bytes
.base
[2] = b3
;
862 rx_base4 (int b1
, int b2
, int b3
, int b4
)
864 rx_bytes
.base
[0] = b1
;
865 rx_bytes
.base
[1] = b2
;
866 rx_bytes
.base
[2] = b3
;
867 rx_bytes
.base
[3] = b4
;
871 /* This gets complicated when the field spans bytes, because fields
872 are numbered from the MSB of the first byte as zero, and bits are
873 stored LSB towards the LSB of the byte. Thus, a simple four-bit
874 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
875 insertion of b'MXL at position 7 is like this:
877 - - - - - - - - - - - - - - - -
881 rx_field (int val
, int pos
, int sz
)
888 if (val
< 0 || val
>= (1 << sz
))
889 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val
, sz
);
894 if (val
< -(1 << (sz
- 1)) || val
>= (1 << (sz
- 1)))
895 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val
, sz
);
898 /* This code points at 'M' in the above example. */
902 while (bitp
+ sz
> 8)
907 svalm
= val
>> (sz
- ssz
);
908 svalm
= svalm
& ((1 << ssz
) - 1);
909 svalm
= svalm
<< (8 - bitp
- ssz
);
910 gas_assert (bytep
< rx_bytes
.n_base
);
911 rx_bytes
.base
[bytep
] |= svalm
;
917 valm
= val
& ((1 << sz
) - 1);
918 valm
= valm
<< (8 - bitp
- sz
);
919 gas_assert (bytep
< rx_bytes
.n_base
);
920 rx_bytes
.base
[bytep
] |= valm
;
923 /* Special case of the above, for 3-bit displacements of 2..9. */
926 rx_disp3 (expressionS exp
, int pos
)
928 rx_field_fixup (exp
, pos
, 3, RXREL_PCREL
);
931 /* Special case of the above, for split 5-bit displacements. Assumes
932 the displacement has been checked with rx_disp5op. */
933 /* ---- -432 1--- 0--- */
936 rx_field5s (expressionS exp
)
940 val
= exp
.X_add_number
;
941 rx_bytes
.base
[0] |= val
>> 2;
942 rx_bytes
.base
[1] |= (val
<< 6) & 0x80;
943 rx_bytes
.base
[1] |= (val
<< 3) & 0x08;
946 /* ---- ---- 4--- 3210 */
949 rx_field5s2 (expressionS exp
)
953 val
= exp
.X_add_number
;
954 rx_bytes
.base
[1] |= (val
<< 3) & 0x80;
955 rx_bytes
.base
[1] |= (val
) & 0x0f;
959 rx_bfield(expressionS s
, expressionS d
, expressionS w
)
961 int slsb
= s
.X_add_number
;
962 int dlsb
= d
.X_add_number
;
963 int width
= w
.X_add_number
;
965 (((dlsb
+ width
) & 0x1f) << 10 | (dlsb
<< 5) |
966 ((dlsb
- slsb
) & 0x1f));
967 if ((slsb
+ width
) > 32)
968 as_warn (_("Value %d and %d out of range"), slsb
, width
);
969 if ((dlsb
+ width
) > 32)
970 as_warn (_("Value %d and %d out of range"), dlsb
, width
);
971 rx_bytes
.ops
[0] = imm
& 0xff;
972 rx_bytes
.ops
[1] = (imm
>> 8);
976 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
978 #define F_PRECISION 2
981 rx_op (expressionS exp
, int nbytes
, int type
)
985 if ((exp
.X_op
== O_constant
|| exp
.X_op
== O_big
)
986 && type
!= RXREL_PCREL
)
988 if (exp
.X_op
== O_big
)
990 if (exp
.X_add_number
== -1)
993 char * ip
= rx_bytes
.ops
+ rx_bytes
.n_ops
;
995 gen_to_words (w
, F_PRECISION
, 8);
996 #if RX_OPCODE_BIG_ENDIAN
1007 rx_bytes
.n_ops
+= 4;
1011 v
= ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
1012 | (generic_bignum
[0] & LITTLENUM_MASK
);
1016 v
= exp
.X_add_number
;
1020 #if RX_OPCODE_BIG_ENDIAN
1021 OP ((v
>> (8 * (nbytes
- 1))) & 0xff);
1031 rx_op_fixup (exp
, rx_bytes
.n_ops
* 8, nbytes
* 8, type
);
1032 memset (rx_bytes
.ops
+ rx_bytes
.n_ops
, 0, nbytes
);
1033 rx_bytes
.n_ops
+= nbytes
;
1037 void rx_post(char byte
)
1039 rx_bytes
.post
[rx_bytes
.n_post
++] = byte
;
1048 #define APPEND(B, N_B) \
1051 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
1052 idx += rx_bytes.N_B; \
1056 rx_frag_init (fragS
* fragP
)
1058 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
|| rx_bytes
.n_base
< 0)
1060 fragP
->tc_frag_data
= XNEW (rx_bytesT
);
1061 memcpy (fragP
->tc_frag_data
, & rx_bytes
, sizeof (rx_bytesT
));
1064 fragP
->tc_frag_data
= 0;
1067 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
1068 <symbol_name> .equ <expression> */
1071 rx_equ (char * name
, char * expression
)
1073 char saved_name_end_char
;
1077 while (ISSPACE (* name
))
1080 for (name_end
= name
+ 1; *name_end
; name_end
++)
1081 if (! ISALNUM (* name_end
))
1084 saved_name_end_char
= * name_end
;
1087 saved_ilp
= input_line_pointer
;
1088 input_line_pointer
= expression
;
1092 input_line_pointer
= saved_ilp
;
1093 * name_end
= saved_name_end_char
;
1096 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
1097 rather than at the start of a line. (eg .EQU or .DEFINE). If one
1098 is found, process it and return TRUE otherwise return FALSE. */
1101 scan_for_infix_rx_pseudo_ops (char * str
)
1105 char * dot
= strchr (str
, '.');
1107 if (dot
== NULL
|| dot
== str
)
1110 /* A real pseudo-op must be preceded by whitespace. */
1111 if (dot
[-1] != ' ' && dot
[-1] != '\t')
1114 pseudo_op
= dot
+ 1;
1116 if (!ISALNUM (* pseudo_op
))
1119 for (p
= pseudo_op
+ 1; ISALNUM (* p
); p
++)
1122 if (strncasecmp ("EQU", pseudo_op
, p
- pseudo_op
) == 0)
1124 else if (strncasecmp ("DEFINE", pseudo_op
, p
- pseudo_op
) == 0)
1125 as_warn (_("The .DEFINE pseudo-op is not implemented"));
1126 else if (strncasecmp ("MACRO", pseudo_op
, p
- pseudo_op
) == 0)
1127 as_warn (_("The .MACRO pseudo-op is not implemented"));
1128 else if (strncasecmp ("BTEQU", pseudo_op
, p
- pseudo_op
) == 0)
1129 as_warn (_("The .BTEQU pseudo-op is not implemented."));
1137 md_assemble (char * str
)
1142 fragS
* frag_then
= frag_now
;
1145 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
1147 rx_lex_init (str
, str
+ strlen (str
));
1148 if (scan_for_infix_rx_pseudo_ops (str
))
1152 /* This simplifies the relaxation code. */
1153 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
1155 /* We do it this way because we want the frag to have the
1156 rx_bytes in it, which we initialize above. */
1157 bytes
= frag_more (12);
1158 frag_then
= frag_now
;
1159 frag_variant (rs_machine_dependent
,
1166 frag_then
->fr_opcode
= bytes
;
1167 frag_then
->fr_fix
+= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1168 frag_then
->fr_subtype
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1172 bytes
= frag_more (rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
);
1173 frag_then
= frag_now
;
1174 if (fetchalign_bytes
)
1175 fetchalign_bytes
->n_ops
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1178 fetchalign_bytes
= NULL
;
1180 APPEND (base
, n_base
);
1181 APPEND (ops
, n_ops
);
1182 APPEND (post
, n_post
);
1184 if (rx_bytes
.link_relax
&& rx_bytes
.n_fixups
)
1188 f
= fix_new (frag_then
,
1189 (char *) bytes
- frag_then
->fr_literal
,
1192 rx_bytes
.link_relax
| rx_bytes
.n_fixups
,
1194 BFD_RELOC_RX_RELAX
);
1195 frag_then
->tc_frag_data
->link_relax_fixP
= f
;
1198 for (i
= 0; i
< rx_bytes
.n_fixups
; i
++)
1200 /* index: [nbytes][type] */
1201 static int reloc_map
[5][4] =
1203 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL
},
1204 { BFD_RELOC_8
, BFD_RELOC_RX_8U
, BFD_RELOC_RX_NEG8
, BFD_RELOC_8_PCREL
},
1205 { BFD_RELOC_RX_16_OP
, BFD_RELOC_RX_16U
, BFD_RELOC_RX_NEG16
, BFD_RELOC_16_PCREL
},
1206 { BFD_RELOC_RX_24_OP
, BFD_RELOC_RX_24U
, BFD_RELOC_RX_NEG24
, BFD_RELOC_24_PCREL
},
1207 { BFD_RELOC_RX_32_OP
, BFD_RELOC_32
, BFD_RELOC_RX_NEG32
, BFD_RELOC_32_PCREL
},
1211 idx
= rx_bytes
.fixups
[i
].offset
/ 8;
1212 rel
= reloc_map
[rx_bytes
.fixups
[i
].nbits
/ 8][(int) rx_bytes
.fixups
[i
].type
];
1214 if (rx_bytes
.fixups
[i
].reloc
)
1215 rel
= rx_bytes
.fixups
[i
].reloc
;
1217 if (frag_then
->tc_frag_data
)
1218 exp
= & frag_then
->tc_frag_data
->fixups
[i
].exp
;
1220 exp
= & rx_bytes
.fixups
[i
].exp
;
1222 f
= fix_new_exp (frag_then
,
1223 (char *) bytes
+ idx
- frag_then
->fr_literal
,
1224 rx_bytes
.fixups
[i
].nbits
/ 8,
1226 rx_bytes
.fixups
[i
].type
== RXREL_PCREL
? 1 : 0,
1228 if (frag_then
->tc_frag_data
)
1229 frag_then
->tc_frag_data
->fixups
[i
].fixP
= f
;
1231 dwarf2_emit_insn (idx
);
1239 /* Write a value out to the object file, using the appropriate endianness. */
1242 md_number_to_chars (char * buf
, valueT val
, int n
)
1244 if (target_big_endian
)
1245 number_to_chars_bigendian (buf
, val
, n
);
1247 number_to_chars_littleendian (buf
, val
, n
);
1257 { "gp", BFD_RELOC_GPREL16
},
1262 md_operand (expressionS
* exp ATTRIBUTE_UNUSED
)
1267 for (i
= 0; reloc_functions
[i
].fname
; i
++)
1269 int flen
= strlen (reloc_functions
[i
].fname
);
1271 if (input_line_pointer
[0] == '%'
1272 && strncasecmp (input_line_pointer
+ 1, reloc_functions
[i
].fname
, flen
) == 0
1273 && input_line_pointer
[flen
+ 1] == '(')
1275 reloc
= reloc_functions
[i
].reloc
;
1276 input_line_pointer
+= flen
+ 2;
1284 if (* input_line_pointer
== ')')
1285 input_line_pointer
++;
1291 md_section_align (segT segment
, valueT size
)
1293 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1294 return ((size
+ (1 << align
) - 1) & -(1 << align
));
1298 static unsigned char nop_1
[] = { 0x03};
1299 /* MOV.L R0,R0 - 1 cycle */
1300 static unsigned char nop_2
[] = { 0xef, 0x00};
1301 /* MAX R0,R0 - 1 cycle */
1302 static unsigned char nop_3
[] = { 0xfc, 0x13, 0x00 };
1303 /* MUL #1,R0 - 1 cycle */
1304 static unsigned char nop_4
[] = { 0x76, 0x10, 0x01, 0x00 };
1305 /* MUL #1,R0 - 1 cycle */
1306 static unsigned char nop_5
[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
1307 /* MUL #1,R0 - 1 cycle */
1308 static unsigned char nop_6
[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
1309 /* MAX 0x80000000,R0 - 1 cycle */
1310 static unsigned char nop_7
[] = { 0xFD, 0x70, 0x40, 0x00, 0x00, 0x00, 0x80 };
1312 static unsigned char *nops
[] = { NULL
, nop_1
, nop_2
, nop_3
, nop_4
, nop_5
, nop_6
, nop_7
};
1313 #define BIGGEST_NOP 7
1315 /* When relaxing, we need to output a reloc for any .align directive
1316 so that we can retain this alignment as we adjust opcode sizes. */
1318 rx_handle_align (fragS
* frag
)
1320 /* If handling an alignment frag, use an optimal NOP pattern.
1321 Only do this if a fill value has not already been provided.
1322 FIXME: This test fails if the provided fill value is zero. */
1323 if ((frag
->fr_type
== rs_align
1324 || frag
->fr_type
== rs_align_code
)
1325 && subseg_text_p (now_seg
))
1327 int count
= (frag
->fr_next
->fr_address
1330 unsigned char *base
= (unsigned char *)frag
->fr_literal
+ frag
->fr_fix
;
1334 if (count
> BIGGEST_NOP
)
1342 memcpy (base
, nops
[count
], count
);
1343 frag
->fr_var
= count
;
1349 && (frag
->fr_type
== rs_align
1350 || frag
->fr_type
== rs_align_code
)
1351 && frag
->fr_address
+ frag
->fr_fix
> 0
1352 && frag
->fr_offset
> 0
1353 && now_seg
!= bss_section
)
1355 fix_new (frag
, frag
->fr_fix
, 0,
1356 &abs_symbol
, RX_RELAXA_ALIGN
+ frag
->fr_offset
,
1357 0, BFD_RELOC_RX_RELAX
);
1358 /* For the purposes of relaxation, this relocation is attached
1359 to the byte *after* the alignment - i.e. the byte that must
1361 fix_new (frag
->fr_next
, 0, 0,
1362 &abs_symbol
, RX_RELAXA_ELIGN
+ frag
->fr_offset
,
1363 0, BFD_RELOC_RX_RELAX
);
1368 md_atof (int type
, char * litP
, int * sizeP
)
1370 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1374 md_undefined_symbol (char * name ATTRIBUTE_UNUSED
)
1379 /*----------------------------------------------------------------------*/
1380 /* To recap: we estimate everything based on md_estimate_size, then
1381 adjust based on rx_relax_frag. When it all settles, we call
1382 md_convert frag to update the bytes. The relaxation types and
1383 relocations are in fragP->tc_frag_data, which is a copy of that
1386 Our scheme is as follows: fr_fix has the size of the smallest
1387 opcode (like BRA.S). We store the number of total bytes we need in
1388 fr_subtype. When we're done relaxing, we use fr_subtype and the
1389 existing opcode bytes to figure out what actual opcode we need to
1390 put in there. If the fixup isn't resolvable now, we use the
1393 #define TRACE_RELAX 0
1394 #define tprintf if (TRACE_RELAX) printf
1406 /* We're looking for these types of relaxations:
1409 BRA.B 00101110 dspppppp
1410 BRA.W 00111000 dspppppp pppppppp
1411 BRA.A 00000100 dspppppp pppppppp pppppppp
1414 BEQ.B 00100000 dspppppp
1415 BEQ.W 00111010 dspppppp pppppppp
1418 BNE.B 00100001 dspppppp
1419 BNE.W 00111011 dspppppp pppppppp
1421 BSR.W 00111001 dspppppp pppppppp
1422 BSR.A 00000101 dspppppp pppppppp pppppppp
1424 Bcc.B 0010cond dspppppp
1426 Additionally, we can synthesize longer conditional branches using
1427 pairs of opcodes, one with an inverted conditional (flip LSB):
1429 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1430 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1431 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1432 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1434 /* Given the opcode bytes at OP, figure out which opcode it is and
1435 return the type of opcode. We use this to re-encode the opcode as
1436 a different size later. */
1439 rx_opcode_type (char * op
)
1441 unsigned char b
= (unsigned char) op
[0];
1445 case 0x08: return OT_bra
;
1446 case 0x10: return OT_beq
;
1447 case 0x18: return OT_bne
;
1452 case 0x2e: return OT_bra
;
1453 case 0x38: return OT_bra
;
1454 case 0x04: return OT_bra
;
1456 case 0x20: return OT_beq
;
1457 case 0x3a: return OT_beq
;
1459 case 0x21: return OT_bne
;
1460 case 0x3b: return OT_bne
;
1462 case 0x39: return OT_bsr
;
1463 case 0x05: return OT_bsr
;
1466 if ((b
& 0xf0) == 0x20)
1472 /* Returns zero if *addrP has the target address. Else returns nonzero
1473 if we cannot compute the target address yet. */
1476 rx_frag_fix_value (fragS
* fragP
,
1481 addressT
* sym_addr
)
1484 rx_bytesT
* b
= fragP
->tc_frag_data
;
1485 expressionS
* exp
= & b
->fixups
[which
].exp
;
1487 if (need_diff
&& exp
->X_op
!= O_subtract
)
1490 if (exp
->X_add_symbol
)
1492 if (S_FORCE_RELOC (exp
->X_add_symbol
, 1))
1494 if (S_GET_SEGMENT (exp
->X_add_symbol
) != segment
)
1496 addr
+= S_GET_VALUE (exp
->X_add_symbol
);
1499 if (exp
->X_op_symbol
)
1501 if (exp
->X_op
!= O_subtract
)
1503 if (S_FORCE_RELOC (exp
->X_op_symbol
, 1))
1505 if (S_GET_SEGMENT (exp
->X_op_symbol
) != segment
)
1507 addr
-= S_GET_VALUE (exp
->X_op_symbol
);
1511 addr
+= exp
->X_add_number
;
1516 /* Estimate how big the opcode is after this relax pass. The return
1517 value is the difference between fr_fix and the actual size. We
1518 compute the total size in rx_relax_frag and store it in fr_subtype,
1519 so we only need to subtract fx_fix and return it. */
1522 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
, segT segment ATTRIBUTE_UNUSED
)
1527 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1528 (unsigned long) (fragP
->fr_address
1529 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1530 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1531 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1533 /* This is the size of the opcode that's accounted for in fr_fix. */
1534 opfixsize
= fragP
->fr_fix
- (fragP
->fr_opcode
- fragP
->fr_literal
);
1535 /* This is the size of the opcode that isn't. */
1536 delta
= (fragP
->fr_subtype
- opfixsize
);
1538 tprintf (" -> opfixsize %d delta %d\n", opfixsize
, delta
);
1542 /* Given a frag FRAGP, return the "next" frag that contains an
1543 opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
1546 rx_next_opcode (fragS
*fragP
)
1549 fragP
= fragP
->fr_next
;
1550 } while (fragP
&& fragP
->fr_type
!= rs_machine_dependent
);
1554 /* Given the new addresses for this relax pass, figure out how big
1555 each opcode must be. We store the total number of bytes needed in
1556 fr_subtype. The return value is the difference between the size
1557 after the last pass and the size after this pass, so we use the old
1558 fr_subtype to calculate the difference. */
1561 rx_relax_frag (segT segment ATTRIBUTE_UNUSED
, fragS
* fragP
, long stretch
, unsigned long max_iterations
)
1563 addressT addr0
, sym_addr
;
1566 int oldsize
= fragP
->fr_subtype
;
1567 int newsize
= oldsize
;
1569 /* Index of relaxation we care about. */
1572 tprintf ("\033[36mrelax frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d str %ld\033[0m\n",
1573 (unsigned long) (fragP
->fr_address
1574 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1575 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1576 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
, stretch
);
1578 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1580 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1582 unsigned int next_size
;
1583 if (fragP
->fr_next
== NULL
)
1586 next_size
= fragP
->tc_frag_data
->n_ops
;
1589 fragS
*n
= rx_next_opcode (fragP
);
1590 next_size
= n
->fr_subtype
;
1593 fragP
->fr_subtype
= (8-(mypc
& 7)) & 7;
1594 tprintf("subtype %u\n", fragP
->fr_subtype
);
1595 if (fragP
->fr_subtype
>= next_size
)
1596 fragP
->fr_subtype
= 0;
1597 tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
1598 (unsigned long) (mypc
& 7),
1599 next_size
, fragP
->fr_subtype
, oldsize
, fragP
->fr_subtype
-oldsize
);
1601 newsize
= fragP
->fr_subtype
;
1603 return newsize
- oldsize
;
1606 optype
= rx_opcode_type (fragP
->fr_opcode
);
1608 /* In the one case where we have both a disp and imm relaxation, we want
1609 the imm relaxation here. */
1611 if (fragP
->tc_frag_data
->n_relax
> 1
1612 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1615 /* Try to get the target address. */
1616 if (rx_frag_fix_value (fragP
, segment
, ri
, & addr0
,
1617 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
,
1620 /* If we don't, we must use the maximum size for the linker.
1621 Note that we don't use synthetically expanded conditionals
1623 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1625 case RX_RELAX_BRANCH
:
1646 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
+ 4;
1649 fragP
->fr_subtype
= newsize
;
1650 tprintf (" -> new %d old %d delta %d (external)\n", newsize
, oldsize
, newsize
-oldsize
);
1651 return newsize
- oldsize
;
1654 if (sym_addr
> mypc
)
1657 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1659 case RX_RELAX_BRANCH
:
1660 tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
1661 (unsigned long) addr0
, (unsigned long) mypc
,
1662 (long) (addr0
- mypc
));
1663 disp
= (int) addr0
- (int) mypc
;
1668 if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1671 else if (disp
>= -32768 && (disp
- (oldsize
-5)) <= 32767)
1681 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1684 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1687 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1697 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1700 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1703 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1714 tprintf (" - newsize %d\n", newsize
);
1718 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
1719 (unsigned long) addr0
, (unsigned long) mypc
,
1720 fragP
->tc_frag_data
->relax
[ri
].field_pos
,
1721 fragP
->tc_frag_data
->relax
[ri
].val_ofs
);
1723 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1725 if ((long) addr0
>= -128 && (long) addr0
<= 127)
1727 else if ((long) addr0
>= -32768 && (long) addr0
<= 32767)
1729 else if ((long) addr0
>= -8388608 && (long) addr0
<= 8388607)
1739 if (fragP
->tc_frag_data
->relax
[ri
].type
== RX_RELAX_BRANCH
)
1755 /* This prevents infinite loops in align-heavy sources. */
1756 if (newsize
< oldsize
)
1758 /* Make sure that our iteration limit is no bigger than the one being
1759 used inside write.c:relax_segment(). Otherwise we can end up
1760 iterating for too long, and triggering a fatal error there. See
1761 PR 24464 for more details. */
1762 unsigned long limit
= max_iterations
> 10 ? 10 : max_iterations
;
1764 if (fragP
->tc_frag_data
->times_shrank
> limit
1765 && fragP
->tc_frag_data
->times_grown
> limit
)
1768 if (fragP
->tc_frag_data
->times_shrank
< 20)
1769 fragP
->tc_frag_data
->times_shrank
++;
1771 else if (newsize
> oldsize
)
1773 if (fragP
->tc_frag_data
->times_grown
< 20)
1774 fragP
->tc_frag_data
->times_grown
++;
1777 fragP
->fr_subtype
= newsize
;
1778 tprintf (" -> new %d old %d delta %d\n", newsize
, oldsize
, newsize
-oldsize
);
1779 return newsize
- oldsize
;
1782 /* This lets us test for the opcode type and the desired size in a
1783 switch statement. */
1784 #define OPCODE(type,size) ((type) * 16 + (size))
1786 /* Given the opcode stored in fr_opcode and the number of bytes we
1787 think we need, encode a new opcode. We stored a pointer to the
1788 fixup for this opcode in the tc_frag_data structure. If we can do
1789 the fixup here, we change the relocation type to "none" (we test
1790 for that in tc_gen_reloc) else we change it to the right type for
1791 the new (biggest) opcode. */
1794 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1795 segT segment ATTRIBUTE_UNUSED
,
1796 fragS
* fragP ATTRIBUTE_UNUSED
)
1798 rx_bytesT
* rxb
= fragP
->tc_frag_data
;
1799 addressT addr0
, mypc
;
1802 bfd_reloc_code_real_type reloc_type
;
1803 char * op
= fragP
->fr_opcode
;
1806 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1807 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1809 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1810 (unsigned long) (fragP
->fr_address
1811 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1812 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1813 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
,
1820 printf ("lit 0x%p opc 0x%p", fragP
->fr_literal
, fragP
->fr_opcode
);
1821 for (i
= 0; i
< 10; i
++)
1822 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1827 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1829 int count
= fragP
->fr_subtype
;
1832 else if (count
> BIGGEST_NOP
)
1839 memcpy (op
, nops
[count
], count
);
1843 /* In the one case where we have both a disp and imm relaxation, we want
1844 the imm relaxation here. */
1846 if (fragP
->tc_frag_data
->n_relax
> 1
1847 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1850 /* We used a new frag for this opcode, so the opcode address should
1851 be the frag address. */
1852 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1854 /* Try to get the target address. If we fail here, we just use the
1856 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1857 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1859 /* We don't know the target address. */
1866 /* We know the target address, and it's in addr0. */
1867 disp
= (int) addr0
- (int) mypc
;
1873 reloc_type
= BFD_RELOC_NONE
;
1876 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1877 rx_opcode_type (fragP
->fr_opcode
), disp
,
1878 (unsigned long) addr0
, (unsigned long) mypc
);
1879 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1881 case RX_RELAX_BRANCH
:
1882 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1884 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1885 op
[0] = 0x08 + (disp
& 7);
1887 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1890 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1893 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1895 #if RX_OPCODE_BIG_ENDIAN
1896 op
[1] = (disp
>> 8) & 0xff;
1899 op
[2] = (disp
>> 8) & 0xff;
1903 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1905 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1907 #if RX_OPCODE_BIG_ENDIAN
1908 op
[1] = (disp
>> 16) & 0xff;
1909 op
[2] = (disp
>> 8) & 0xff;
1912 op
[3] = (disp
>> 16) & 0xff;
1913 op
[2] = (disp
>> 8) & 0xff;
1916 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1920 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1921 op
[0] = 0x10 + (disp
& 7);
1923 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1927 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1929 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1931 #if RX_OPCODE_BIG_ENDIAN
1932 op
[1] = (disp
>> 8) & 0xff;
1935 op
[2] = (disp
>> 8) & 0xff;
1938 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1941 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1942 op
[0] = 0x1d; /* bne.s .+5. */
1943 op
[1] = 0x04; /* bra.a dsp:24. */
1945 #if RX_OPCODE_BIG_ENDIAN
1946 op
[2] = (disp
>> 16) & 0xff;
1947 op
[3] = (disp
>> 8) & 0xff;
1950 op
[4] = (disp
>> 16) & 0xff;
1951 op
[3] = (disp
>> 8) & 0xff;
1954 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1958 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1959 op
[0] = 0x18 + (disp
& 7);
1961 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1965 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1967 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1969 #if RX_OPCODE_BIG_ENDIAN
1970 op
[1] = (disp
>> 8) & 0xff;
1973 op
[2] = (disp
>> 8) & 0xff;
1976 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1979 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1980 op
[0] = 0x15; /* beq.s .+5. */
1981 op
[1] = 0x04; /* bra.a dsp:24. */
1983 #if RX_OPCODE_BIG_ENDIAN
1984 op
[2] = (disp
>> 16) & 0xff;
1985 op
[3] = (disp
>> 8) & 0xff;
1988 op
[4] = (disp
>> 16) & 0xff;
1989 op
[3] = (disp
>> 8) & 0xff;
1992 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1996 case OPCODE (OT_bsr
, 3): /* BSR.W - 16 bit. */
1998 #if RX_OPCODE_BIG_ENDIAN
1999 op
[1] = (disp
>> 8) & 0xff;
2002 op
[2] = (disp
>> 8) & 0xff;
2005 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2008 case OPCODE (OT_bsr
, 4): /* BSR.A - 24 bit. */
2010 #if RX_OPCODE_BIG_ENDIAN
2011 op
[1] = (disp
>> 16) & 0xff;
2012 op
[2] = (disp
>> 8) & 0xff;
2015 op
[3] = (disp
>> 16) & 0xff;
2016 op
[2] = (disp
>> 8) & 0xff;
2019 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2023 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
2025 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
2027 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
2028 op
[0] ^= 1; /* Invert condition. */
2029 op
[1] = 5; /* Displacement. */
2032 #if RX_OPCODE_BIG_ENDIAN
2033 op
[3] = (disp
>> 8) & 0xff;
2036 op
[4] = (disp
>> 8) & 0xff;
2039 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2042 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
2043 op
[0] ^= 1; /* Invert condition. */
2044 op
[1] = 6; /* Displacement. */
2047 #if RX_OPCODE_BIG_ENDIAN
2048 op
[3] = (disp
>> 16) & 0xff;
2049 op
[4] = (disp
>> 8) & 0xff;
2052 op
[5] = (disp
>> 16) & 0xff;
2053 op
[4] = (disp
>> 8) & 0xff;
2056 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2061 /* These are opcodes we'll relax in th linker, later. */
2063 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
2070 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2072 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2079 reloc_type
= BFD_RELOC_8
;
2083 #if RX_OPCODE_BIG_ENDIAN
2085 imm
[0] = addr0
>> 8;
2088 imm
[1] = addr0
>> 8;
2090 reloc_type
= BFD_RELOC_RX_16_OP
;
2094 #if RX_OPCODE_BIG_ENDIAN
2096 imm
[1] = addr0
>> 8;
2097 imm
[0] = addr0
>> 16;
2100 imm
[1] = addr0
>> 8;
2101 imm
[2] = addr0
>> 16;
2103 reloc_type
= BFD_RELOC_RX_24_OP
;
2107 #if RX_OPCODE_BIG_ENDIAN
2109 imm
[2] = addr0
>> 8;
2110 imm
[1] = addr0
>> 16;
2111 imm
[0] = addr0
>> 24;
2114 imm
[1] = addr0
>> 8;
2115 imm
[2] = addr0
>> 16;
2116 imm
[3] = addr0
>> 24;
2118 reloc_type
= BFD_RELOC_RX_32_OP
;
2121 as_bad (_("invalid immediate size"));
2125 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
2140 as_bad (_("invalid immediate field position"));
2148 reloc_type
= fix
->fx_r_type
;
2157 fix
->fx_r_type
= reloc_type
;
2158 fix
->fx_where
+= reloc_adjust
;
2161 case BFD_RELOC_NONE
:
2167 case BFD_RELOC_16_PCREL
:
2168 case BFD_RELOC_RX_16_OP
:
2171 case BFD_RELOC_24_PCREL
:
2172 case BFD_RELOC_RX_24_OP
:
2175 case BFD_RELOC_RX_32_OP
:
2183 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
2184 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP
->fr_fix
,
2185 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
2188 if (fragP
->fr_next
!= NULL
2189 && fragP
->fr_next
->fr_address
- fragP
->fr_address
!= fragP
->fr_fix
)
2190 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
2191 (long) fragP
->fr_fix
,
2192 (long) fragP
->fr_address
, (long) fragP
->fr_next
->fr_address
);
2198 rx_validate_fix_sub (struct fix
* f
)
2200 /* We permit the subtraction of two symbols in a few cases. */
2201 /* mov #sym1-sym2, R3 */
2202 if (f
->fx_r_type
== BFD_RELOC_RX_32_OP
)
2204 /* .long sym1-sym2 */
2205 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
2207 && (f
->fx_size
== 4 || f
->fx_size
== 2 || f
->fx_size
== 1))
2213 md_pcrel_from_section (fixS
* fixP
, segT sec
)
2217 if (fixP
->fx_addsy
!= NULL
2218 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2219 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
2220 /* The symbol is undefined (or is defined but not in this section).
2221 Let the linker figure it out. */
2224 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2225 switch (fixP
->fx_r_type
)
2227 case BFD_RELOC_RX_DIR3U_PCREL
:
2235 rx_cons_fix_new (fragS
* frag
,
2239 bfd_reloc_code_real_type type
)
2247 type
= BFD_RELOC_16
;
2250 type
= BFD_RELOC_24
;
2253 type
= BFD_RELOC_32
;
2256 as_bad (_("unsupported constant size %d\n"), size
);
2260 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
2262 if (size
!= 4 && size
!= 2 && size
!= 1)
2263 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2265 type
= BFD_RELOC_RX_DIFF
;
2268 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
2272 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
2273 valueT
* t ATTRIBUTE_UNUSED
,
2274 segT s ATTRIBUTE_UNUSED
)
2276 /* Instruction bytes are always little endian. */
2280 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
2282 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
2285 #define OP2(x) op[target_big_endian ? 1-x : x]
2286 #define OP3(x) op[target_big_endian ? 2-x : x]
2287 #define OP4(x) op[target_big_endian ? 3-x : x]
2289 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
2290 val
= (unsigned long) * t
;
2292 /* Opcode words are always the same endian. Data words are either
2293 big or little endian. */
2295 switch (f
->fx_r_type
)
2297 case BFD_RELOC_NONE
:
2300 case BFD_RELOC_RX_RELAX
:
2304 case BFD_RELOC_RX_DIR3U_PCREL
:
2305 if (val
< 3 || val
> 10)
2306 as_bad_where (f
->fx_file
, f
->fx_line
,
2307 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2309 op
[0] |= val
& 0x07;
2313 case BFD_RELOC_8_PCREL
:
2314 case BFD_RELOC_RX_8U
:
2319 OP2(1) = val
& 0xff;
2320 OP2(0) = (val
>> 8) & 0xff;
2323 case BFD_RELOC_16_PCREL
:
2324 case BFD_RELOC_RX_16_OP
:
2325 case BFD_RELOC_RX_16U
:
2326 #if RX_OPCODE_BIG_ENDIAN
2328 op
[0] = (val
>> 8) & 0xff;
2331 op
[1] = (val
>> 8) & 0xff;
2336 OP3(0) = val
& 0xff;
2337 OP3(1) = (val
>> 8) & 0xff;
2338 OP3(2) = (val
>> 16) & 0xff;
2341 case BFD_RELOC_24_PCREL
:
2342 case BFD_RELOC_RX_24_OP
:
2343 case BFD_RELOC_RX_24U
:
2344 #if RX_OPCODE_BIG_ENDIAN
2346 op
[1] = (val
>> 8) & 0xff;
2347 op
[0] = (val
>> 16) & 0xff;
2350 op
[1] = (val
>> 8) & 0xff;
2351 op
[2] = (val
>> 16) & 0xff;
2355 case BFD_RELOC_RX_DIFF
:
2362 OP2(0) = val
& 0xff;
2363 OP2(1) = (val
>> 8) & 0xff;
2366 OP4(0) = val
& 0xff;
2367 OP4(1) = (val
>> 8) & 0xff;
2368 OP4(2) = (val
>> 16) & 0xff;
2369 OP4(3) = (val
>> 24) & 0xff;
2375 OP4(0) = val
& 0xff;
2376 OP4(1) = (val
>> 8) & 0xff;
2377 OP4(2) = (val
>> 16) & 0xff;
2378 OP4(3) = (val
>> 24) & 0xff;
2381 case BFD_RELOC_RX_32_OP
:
2382 #if RX_OPCODE_BIG_ENDIAN
2384 op
[2] = (val
>> 8) & 0xff;
2385 op
[1] = (val
>> 16) & 0xff;
2386 op
[0] = (val
>> 24) & 0xff;
2389 op
[1] = (val
>> 8) & 0xff;
2390 op
[2] = (val
>> 16) & 0xff;
2391 op
[3] = (val
>> 24) & 0xff;
2395 case BFD_RELOC_RX_NEG8
:
2399 case BFD_RELOC_RX_NEG16
:
2401 #if RX_OPCODE_BIG_ENDIAN
2403 op
[0] = (val
>> 8) & 0xff;
2406 op
[1] = (val
>> 8) & 0xff;
2410 case BFD_RELOC_RX_NEG24
:
2412 #if RX_OPCODE_BIG_ENDIAN
2414 op
[1] = (val
>> 8) & 0xff;
2415 op
[0] = (val
>> 16) & 0xff;
2418 op
[1] = (val
>> 8) & 0xff;
2419 op
[2] = (val
>> 16) & 0xff;
2423 case BFD_RELOC_RX_NEG32
:
2425 #if RX_OPCODE_BIG_ENDIAN
2427 op
[2] = (val
>> 8) & 0xff;
2428 op
[1] = (val
>> 16) & 0xff;
2429 op
[0] = (val
>> 24) & 0xff;
2432 op
[1] = (val
>> 8) & 0xff;
2433 op
[2] = (val
>> 16) & 0xff;
2434 op
[3] = (val
>> 24) & 0xff;
2438 case BFD_RELOC_RX_GPRELL
:
2441 case BFD_RELOC_RX_GPRELW
:
2444 case BFD_RELOC_RX_GPRELB
:
2445 #if RX_OPCODE_BIG_ENDIAN
2447 op
[0] = (val
>> 8) & 0xff;
2450 op
[1] = (val
>> 8) & 0xff;
2455 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2456 bfd_get_reloc_code_name (f
->fx_r_type
));
2460 if (f
->fx_addsy
== NULL
)
2465 tc_gen_reloc (asection
* sec ATTRIBUTE_UNUSED
, fixS
* fixp
)
2467 static arelent
* reloc
[5];
2468 bfd_boolean is_opcode
= FALSE
;
2470 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2477 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2479 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2480 fixp
->fx_subsy
= NULL
;
2483 reloc
[0] = XNEW (arelent
);
2484 reloc
[0]->sym_ptr_ptr
= XNEW (asymbol
*);
2485 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2486 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2487 reloc
[0]->addend
= fixp
->fx_offset
;
2489 if (fixp
->fx_r_type
== BFD_RELOC_RX_32_OP
2492 fixp
->fx_r_type
= BFD_RELOC_RX_DIFF
;
2496 is_opcode
= sec
->flags
& SEC_CODE
;
2498 /* Certain BFD relocations cannot be translated directly into
2499 a single (non-Red Hat) RX relocation, but instead need
2500 multiple RX relocations - handle them here. */
2501 switch (fixp
->fx_r_type
)
2503 case BFD_RELOC_RX_DIFF
:
2504 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2506 reloc
[1] = XNEW (arelent
);
2507 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2508 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2509 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2510 reloc
[1]->addend
= 0;
2511 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2513 reloc
[2] = XNEW (arelent
);
2514 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2515 reloc
[2]->addend
= 0;
2516 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2517 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2519 reloc
[3] = XNEW (arelent
);
2520 switch (fixp
->fx_size
)
2523 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2526 if (!is_opcode
&& target_big_endian
)
2527 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16_REV
);
2529 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2531 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2534 if (!is_opcode
&& target_big_endian
)
2535 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32_REV
);
2537 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2540 reloc
[3]->addend
= 0;
2541 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2542 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2547 case BFD_RELOC_RX_GPRELL
:
2548 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2550 reloc
[1] = XNEW (arelent
);
2551 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2552 if (gp_symbol
== NULL
)
2554 if (symbol_table_frozen
)
2558 gp
= symbol_find ("__gp");
2560 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2562 gp_symbol
= symbol_get_bfdsym (gp
);
2565 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2567 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2568 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2569 reloc
[1]->addend
= 0;
2570 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2572 reloc
[2] = XNEW (arelent
);
2573 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2574 reloc
[2]->addend
= 0;
2575 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2576 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2578 reloc
[3] = XNEW (arelent
);
2579 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2580 reloc
[3]->addend
= 0;
2581 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2582 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2587 case BFD_RELOC_RX_GPRELW
:
2588 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2590 reloc
[1] = XNEW (arelent
);
2591 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2592 if (gp_symbol
== NULL
)
2594 if (symbol_table_frozen
)
2598 gp
= symbol_find ("__gp");
2600 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2602 gp_symbol
= symbol_get_bfdsym (gp
);
2605 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2607 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2608 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2609 reloc
[1]->addend
= 0;
2610 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2612 reloc
[2] = XNEW (arelent
);
2613 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2614 reloc
[2]->addend
= 0;
2615 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2616 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2618 reloc
[3] = XNEW (arelent
);
2619 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2620 reloc
[3]->addend
= 0;
2621 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2622 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2627 case BFD_RELOC_RX_GPRELB
:
2628 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2630 reloc
[1] = XNEW (arelent
);
2631 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2632 if (gp_symbol
== NULL
)
2634 if (symbol_table_frozen
)
2638 gp
= symbol_find ("__gp");
2640 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2642 gp_symbol
= symbol_get_bfdsym (gp
);
2645 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2647 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2648 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2649 reloc
[1]->addend
= 0;
2650 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2652 reloc
[2] = XNEW (arelent
);
2653 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2654 reloc
[2]->addend
= 0;
2655 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2656 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2658 reloc
[3] = XNEW (arelent
);
2659 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2660 reloc
[3]->addend
= 0;
2661 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2662 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2667 case BFD_RELOC_RX_NEG32
:
2668 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2670 reloc
[1] = XNEW (arelent
);
2671 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_NEG
);
2672 reloc
[1]->addend
= 0;
2673 reloc
[1]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2674 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2676 reloc
[2] = XNEW (arelent
);
2677 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2678 reloc
[2]->addend
= 0;
2679 reloc
[2]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2680 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2686 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2695 rx_note_string_insn_use (void)
2697 if ((elf_flags
& E_FLAG_RX_SINSNS_MASK
) == (E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
))
2698 as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
2699 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_YES
;
2702 /* Set the ELF specific flags. */
2705 rx_elf_final_processing (void)
2707 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2710 /* Scan the current input line for occurrences of Renesas
2711 local labels and replace them with the GAS version. */
2714 rx_start_line (void)
2716 int in_double_quote
= 0;
2717 int in_single_quote
= 0;
2719 char * p
= input_line_pointer
;
2722 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2733 /* Handle escaped double quote \" inside a string. */
2734 if (prev_char
!= '\\')
2735 in_double_quote
= ! in_double_quote
;
2739 in_single_quote
= ! in_single_quote
;
2743 if (in_double_quote
|| in_single_quote
)
2748 else if (p
[1] == '+')
2753 else if (p
[1] == '-')