1 /* tc-rx.c -- Assembler for the Renesas RX
2 Copyright (C) 2008-2020 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. */
48 bfd_boolean rx_use_conventional_section_names
= FALSE
;
50 bfd_boolean rx_use_conventional_section_names
= TRUE
;
53 static bfd_boolean rx_use_small_data_limit
= FALSE
;
55 static bfd_boolean rx_pid_mode
= FALSE
;
56 static int rx_num_int_regs
= 0;
60 enum rx_cpu_types rx_cpu
= RX600
;
62 static void rx_fetchalign (int ignore ATTRIBUTE_UNUSED
);
66 OPTION_BIG
= OPTION_MD_BASE
,
70 OPTION_CONVENTIONAL_SECTION_NAMES
,
71 OPTION_RENESAS_SECTION_NAMES
,
72 OPTION_SMALL_DATA_LIMIT
,
79 OPTION_DISALLOW_STRING_INSNS
,
82 #define RX_SHORTOPTS ""
83 const char * md_shortopts
= RX_SHORTOPTS
;
85 /* Assembler options. */
86 struct option md_longopts
[] =
88 {"mbig-endian-data", no_argument
, NULL
, OPTION_BIG
},
89 {"mlittle-endian-data", no_argument
, NULL
, OPTION_LITTLE
},
90 /* The next two switches are here because the
91 generic parts of the linker testsuite uses them. */
92 {"EB", no_argument
, NULL
, OPTION_BIG
},
93 {"EL", no_argument
, NULL
, OPTION_LITTLE
},
94 {"m32bit-doubles", no_argument
, NULL
, OPTION_32BIT_DOUBLES
},
95 {"m64bit-doubles", no_argument
, NULL
, OPTION_64BIT_DOUBLES
},
96 /* This option is here mainly for the binutils testsuites,
97 as many of their tests assume conventional section naming. */
98 {"muse-conventional-section-names", no_argument
, NULL
, OPTION_CONVENTIONAL_SECTION_NAMES
},
99 {"muse-renesas-section-names", no_argument
, NULL
, OPTION_RENESAS_SECTION_NAMES
},
100 {"msmall-data-limit", no_argument
, NULL
, OPTION_SMALL_DATA_LIMIT
},
101 {"relax", no_argument
, NULL
, OPTION_RELAX
},
102 {"mpid", no_argument
, NULL
, OPTION_PID
},
103 {"mint-register", required_argument
, NULL
, OPTION_INT_REGS
},
104 {"mgcc-abi", no_argument
, NULL
, OPTION_USES_GCC_ABI
},
105 {"mrx-abi", no_argument
, NULL
, OPTION_USES_RX_ABI
},
106 {"mcpu", required_argument
, NULL
, OPTION_CPU
},
107 {"mno-allow-string-insns", no_argument
, NULL
, OPTION_DISALLOW_STRING_INSNS
},
108 {NULL
, no_argument
, NULL
, 0}
110 size_t md_longopts_size
= sizeof (md_longopts
);
114 const char *cpu_name
;
115 enum rx_cpu_types type
;
119 struct cpu_type cpu_type_list
[] =
125 {"rxv2", RXV2
, E_FLAG_RX_V2
},
126 {"rxv3", RXV3
, E_FLAG_RX_V3
},
127 {"rxv3-dfpu", RXV3FPU
, E_FLAG_RX_V3
},
131 md_parse_option (int c ATTRIBUTE_UNUSED
, const char * arg ATTRIBUTE_UNUSED
)
134 elf_flags
= E_FLAG_RX_ABI
;
139 target_big_endian
= 1;
143 target_big_endian
= 0;
146 case OPTION_32BIT_DOUBLES
:
147 elf_flags
&= ~ E_FLAG_RX_64BIT_DOUBLES
;
150 case OPTION_64BIT_DOUBLES
:
151 elf_flags
|= E_FLAG_RX_64BIT_DOUBLES
;
154 case OPTION_CONVENTIONAL_SECTION_NAMES
:
155 rx_use_conventional_section_names
= TRUE
;
158 case OPTION_RENESAS_SECTION_NAMES
:
159 rx_use_conventional_section_names
= FALSE
;
162 case OPTION_SMALL_DATA_LIMIT
:
163 rx_use_small_data_limit
= TRUE
;
172 elf_flags
|= E_FLAG_RX_PID
;
175 case OPTION_INT_REGS
:
176 rx_num_int_regs
= atoi (optarg
);
179 case OPTION_USES_GCC_ABI
:
180 elf_flags
&= ~ E_FLAG_RX_ABI
;
183 case OPTION_USES_RX_ABI
:
184 elf_flags
|= E_FLAG_RX_ABI
;
190 for (i
= 0; i
< ARRAY_SIZE (cpu_type_list
); i
++)
192 if (strcasecmp (arg
, cpu_type_list
[i
].cpu_name
) == 0)
194 rx_cpu
= cpu_type_list
[i
].type
;
195 elf_flags
|= cpu_type_list
[i
].flag
;
199 as_warn (_("unrecognised RX CPU type %s"), arg
);
203 case OPTION_DISALLOW_STRING_INSNS
:
204 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
;
212 md_show_usage (FILE * stream
)
214 fprintf (stream
, _(" RX specific command line options:\n"));
215 fprintf (stream
, _(" --mbig-endian-data\n"));
216 fprintf (stream
, _(" --mlittle-endian-data [default]\n"));
217 fprintf (stream
, _(" --m32bit-doubles [default]\n"));
218 fprintf (stream
, _(" --m64bit-doubles\n"));
219 fprintf (stream
, _(" --muse-conventional-section-names\n"));
220 fprintf (stream
, _(" --muse-renesas-section-names [default]\n"));
221 fprintf (stream
, _(" --msmall-data-limit\n"));
222 fprintf (stream
, _(" --mrelax\n"));
223 fprintf (stream
, _(" --mpid\n"));
224 fprintf (stream
, _(" --mint-register=<value>\n"));
225 fprintf (stream
, _(" --mcpu=<rx100|rx200|rx600|rx610|rxv2|rxv3|rxv3-dfpu>\n"));
226 fprintf (stream
, _(" --mno-allow-string-insns"));
230 s_bss (int ignore ATTRIBUTE_UNUSED
)
234 temp
= get_absolute_expression ();
235 subseg_set (bss_section
, (subsegT
) temp
);
236 demand_empty_rest_of_line ();
240 rx_float_cons (int ignore ATTRIBUTE_UNUSED
)
242 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
243 return float_cons ('d');
244 return float_cons ('f');
248 rx_strcasestr (const char *string
, const char *sub
)
254 return (char *)string
;
257 strl
= strlen (string
);
261 /* strncasecmp is in libiberty. */
262 if (strncasecmp (string
, sub
, subl
) == 0)
263 return (char *)string
;
272 rx_include (int ignore
)
277 const char * current_filename
;
285 /* The RX version of the .INCLUDE pseudo-op does not
286 have to have the filename inside double quotes. */
288 if (*input_line_pointer
== '"')
290 /* Treat as the normal GAS .include pseudo-op. */
295 /* Get the filename. Spaces are allowed, NUL characters are not. */
296 filename
= input_line_pointer
;
297 last_char
= find_end_of_line (filename
, FALSE
);
298 input_line_pointer
= last_char
;
300 while (last_char
>= filename
&& (* last_char
== ' ' || * last_char
== '\n'))
302 end_char
= *(++ last_char
);
304 if (last_char
== filename
)
306 as_bad (_("no filename following .INCLUDE pseudo-op"));
307 * last_char
= end_char
;
311 current_filename
= as_where (NULL
);
312 f
= XNEWVEC (char, strlen (current_filename
) + strlen (filename
) + 1);
314 /* Check the filename. If [@]..FILE[@] is found then replace
315 this with the current assembler source filename, stripped
316 of any directory prefixes or extensions. */
317 if ((p
= rx_strcasestr (filename
, "..file")) != NULL
)
321 len
= 6; /* strlen ("..file"); */
323 if (p
> filename
&& p
[-1] == '@')
329 for (d
= c
= current_filename
; *c
; c
++)
330 if (IS_DIR_SEPARATOR (* c
))
336 sprintf (f
, "%.*s%.*s%.*s", (int) (p
- filename
), filename
,
338 (int) (strlen (filename
) - ((p
+ len
) - filename
)),
342 strcpy (f
, filename
);
344 /* RX .INCLUDE semantics say that 'filename' is located by:
346 1. If filename is absolute, just try that. Otherwise...
348 2. If the current source file includes a directory component
349 then prepend that to the filename and try. Otherwise...
351 3. Try any directories specified by the -I command line
354 4 .Try a directory specified by the INC100 environment variable. */
356 if (IS_ABSOLUTE_PATH (f
))
357 try = fopen (path
= f
, FOPEN_RT
);
360 char * env
= getenv ("INC100");
364 len
= strlen (current_filename
);
365 if ((size_t) include_dir_maxlen
> len
)
366 len
= include_dir_maxlen
;
367 if (env
&& strlen (env
) > len
)
370 path
= XNEWVEC (char, strlen (f
) + len
+ 5);
372 if (current_filename
!= NULL
)
374 for (d
= NULL
, p
= current_filename
; *p
; p
++)
375 if (IS_DIR_SEPARATOR (* p
))
380 sprintf (path
, "%.*s/%s", (int) (d
- current_filename
), current_filename
,
382 try = fopen (path
, FOPEN_RT
);
390 for (i
= 0; i
< include_dir_count
; i
++)
392 sprintf (path
, "%s/%s", include_dirs
[i
], f
);
393 if ((try = fopen (path
, FOPEN_RT
)) != NULL
)
398 if (try == NULL
&& env
!= NULL
)
400 sprintf (path
, "%s/%s", env
, f
);
401 try = fopen (path
, FOPEN_RT
);
409 as_bad (_("unable to locate include file: %s"), filename
);
415 register_dependency (path
);
416 input_scrub_insert_file (path
);
419 * last_char
= end_char
;
423 parse_rx_section (char * name
)
427 int attr
= SHF_ALLOC
| SHF_EXECINSTR
;
436 for (p
= input_line_pointer
; *p
&& strchr ("\n\t, =", *p
) == NULL
; p
++)
441 if (strcasecmp (input_line_pointer
, "ALIGN") == 0)
456 case '2': align
= 1; break;
457 case '4': align
= 2; break;
458 case '8': align
= 3; break;
460 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p
);
461 ignore_rest_of_line ();
469 else if (strcasecmp (input_line_pointer
, "CODE") == 0)
470 attr
= SHF_ALLOC
| SHF_EXECINSTR
;
471 else if (strcasecmp (input_line_pointer
, "DATA") == 0)
472 attr
= SHF_ALLOC
| SHF_WRITE
;
473 else if (strcasecmp (input_line_pointer
, "ROMDATA") == 0)
477 as_bad (_("unknown parameter following .SECTION directive: %s"),
481 input_line_pointer
= p
+ 1;
482 ignore_rest_of_line ();
487 input_line_pointer
= p
+ 1;
489 while (end_char
!= '\n' && end_char
!= 0);
491 if ((sec
= bfd_get_section_by_name (stdoutput
, name
)) == NULL
)
493 if (strcmp (name
, "B") && strcmp (name
, "B_1") && strcmp (name
, "B_2"))
498 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
500 else /* Try not to redefine a section, especially B_1. */
502 int flags
= sec
->flags
;
504 type
= elf_section_type (sec
);
506 attr
= ((flags
& SEC_READONLY
) ? 0 : SHF_WRITE
)
507 | ((flags
& SEC_ALLOC
) ? SHF_ALLOC
: 0)
508 | ((flags
& SEC_CODE
) ? SHF_EXECINSTR
: 0)
509 | ((flags
& SEC_MERGE
) ? SHF_MERGE
: 0)
510 | ((flags
& SEC_STRINGS
) ? SHF_STRINGS
: 0)
511 | ((flags
& SEC_THREAD_LOCAL
) ? SHF_TLS
: 0);
513 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
516 bfd_set_section_alignment (now_seg
, align
);
520 rx_section (int ignore
)
524 /* The as100 assembler supports a different syntax for the .section
525 pseudo-op. So check for it and handle it here if necessary. */
528 /* Peek past the section name to see if arguments follow. */
529 for (p
= input_line_pointer
; *p
; p
++)
530 if (*p
== ',' || *p
== '\n')
535 int len
= p
- input_line_pointer
;
537 while (ISSPACE (*++p
))
540 if (*p
!= '"' && *p
!= '#')
542 char *name
= xmemdup0 (input_line_pointer
, len
);
544 input_line_pointer
= p
;
545 parse_rx_section (name
);
550 obj_elf_section (ignore
);
554 rx_list (int ignore ATTRIBUTE_UNUSED
)
558 if (strncasecmp (input_line_pointer
, "OFF", 3))
560 else if (strncasecmp (input_line_pointer
, "ON", 2))
563 as_warn (_("expecting either ON or OFF after .list"));
566 /* Like the .rept pseudo op, but supports the
567 use of ..MACREP inside the repeated region. */
570 rx_rept (int ignore ATTRIBUTE_UNUSED
)
572 size_t count
= get_absolute_expression ();
574 do_repeat_with_expander (count
, "MREPEAT", "ENDR", "..MACREP");
577 /* Like cons() accept that strings are allowed. */
584 if (* input_line_pointer
== '"')
591 rx_nop (int ignore ATTRIBUTE_UNUSED
)
593 ignore_rest_of_line ();
599 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
600 md_pseudo_table
[idx
].poc_name
);
601 ignore_rest_of_line ();
604 /* The target specific pseudo-ops which we support. */
605 const pseudo_typeS md_pseudo_table
[] =
607 /* These are unimplemented. They're listed first so that we can use
608 the poc_value as the index into this array, to get the name of
609 the pseudo. So, keep these (1) first, and (2) in order, with (3)
610 the poc_value's in sequence. */
611 { "btglb", rx_unimp
, 0 },
612 { "call", rx_unimp
, 1 },
613 { "einsf", rx_unimp
, 2 },
614 { "fb", rx_unimp
, 3 },
615 { "fbsym", rx_unimp
, 4 },
616 { "id", rx_unimp
, 5 },
617 { "initsct", rx_unimp
, 6 },
618 { "insf", rx_unimp
, 7 },
619 { "instr", rx_unimp
, 8 },
620 { "lbba", rx_unimp
, 9 },
621 { "len", rx_unimp
, 10 },
622 { "optj", rx_unimp
, 11 },
623 { "rvector", rx_unimp
, 12 },
624 { "sb", rx_unimp
, 13 },
625 { "sbbit", rx_unimp
, 14 },
626 { "sbsym", rx_unimp
, 15 },
627 { "sbsym16", rx_unimp
, 16 },
629 /* These are the do-nothing pseudos. */
630 { "stk", rx_nop
, 0 },
631 /* The manual documents ".stk" but the compiler emits ".stack". */
632 { "stack", rx_nop
, 0 },
634 /* These are Renesas as100 assembler pseudo-ops that we do support. */
635 { "addr", rx_cons
, 3 },
636 { "align", s_align_bytes
, 2 },
637 { "byte", rx_cons
, 1 },
638 { "fixed", float_cons
, 'f' },
639 { "form", listing_psize
, 0 },
640 { "glb", s_globl
, 0 },
641 { "include", rx_include
, 0 },
642 { "list", rx_list
, 0 },
643 { "lword", rx_cons
, 4 },
644 { "mrepeat", rx_rept
, 0 },
645 { "section", rx_section
, 0 },
647 /* FIXME: The following pseudo-ops place their values (and associated
648 label if present) in the data section, regardless of whatever
649 section we are currently in. At the moment this code does not
650 implement that part of the semantics. */
651 { "blka", s_space
, 3 },
652 { "blkb", s_space
, 1 },
653 { "blkd", s_space
, 8 },
654 { "blkf", s_space
, 4 },
655 { "blkl", s_space
, 4 },
656 { "blkw", s_space
, 2 },
658 /* Our "standard" pseudos. */
659 { "double", rx_float_cons
, 0 },
661 { "3byte", cons
, 3 },
665 { "fetchalign", rx_fetchalign
, 0 },
667 /* End of list marker. */
671 static asymbol
* gp_symbol
;
672 static asymbol
* rx_pid_symbol
;
674 static symbolS
* rx_pidreg_symbol
;
675 static symbolS
* rx_gpreg_symbol
;
680 /* Make the __gp and __pid_base symbols now rather
681 than after the symbol table is frozen. We only do this
682 when supporting small data limits because otherwise we
683 pollute the symbol table. */
685 /* The meta-registers %pidreg and %gpreg depend on what other
686 options are specified. The __rx_*_defined symbols exist so we
687 can .ifdef asm code based on what options were passed to gas,
688 without needing a preprocessor */
692 rx_pid_register
= 13 - rx_num_int_regs
;
693 rx_pid_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
694 rx_pidreg_symbol
= symbol_find_or_make ("__rx_pidreg_defined");
695 S_SET_VALUE (rx_pidreg_symbol
, rx_pid_register
);
696 S_SET_SEGMENT (rx_pidreg_symbol
, absolute_section
);
699 if (rx_use_small_data_limit
)
702 rx_gp_register
= rx_pid_register
- 1;
704 rx_gp_register
= 13 - rx_num_int_regs
;
705 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
706 rx_gpreg_symbol
= symbol_find_or_make ("__rx_gpreg_defined");
707 S_SET_VALUE (rx_gpreg_symbol
, rx_gp_register
);
708 S_SET_SEGMENT (rx_gpreg_symbol
, absolute_section
);
715 /* These negative numbers are found in rx_bytesT.n_base for non-opcode
717 #define RX_NBASE_FETCHALIGN -1
719 typedef struct rx_bytesT
722 /* If this is negative, it's a special-purpose frag as per the defines above. */
731 char type
; /* RXREL_*. */
746 fixS
*link_relax_fixP
;
747 unsigned long times_grown
;
748 unsigned long times_shrank
;
751 static rx_bytesT rx_bytes
;
752 /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
753 static rx_bytesT
*fetchalign_bytes
= NULL
;
756 rx_fetchalign (int ignore ATTRIBUTE_UNUSED
)
761 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
762 rx_bytes
.n_base
= RX_NBASE_FETCHALIGN
;
764 bytes
= frag_more (8);
765 frag_then
= frag_now
;
766 frag_variant (rs_machine_dependent
,
773 frag_then
->fr_opcode
= bytes
;
774 frag_then
->fr_subtype
= 0;
775 fetchalign_bytes
= frag_then
->tc_frag_data
;
779 rx_relax (int type
, int pos
)
781 rx_bytes
.relax
[rx_bytes
.n_relax
].type
= type
;
782 rx_bytes
.relax
[rx_bytes
.n_relax
].field_pos
= pos
;
783 rx_bytes
.relax
[rx_bytes
.n_relax
].val_ofs
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
788 rx_linkrelax_dsp (int pos
)
793 rx_bytes
.link_relax
|= RX_RELAXA_DSP4
;
796 rx_bytes
.link_relax
|= RX_RELAXA_DSP6
;
799 rx_bytes
.link_relax
|= RX_RELAXA_DSP14
;
805 rx_linkrelax_imm (int pos
)
810 rx_bytes
.link_relax
|= RX_RELAXA_IMM6
;
813 rx_bytes
.link_relax
|= RX_RELAXA_IMM12
;
819 rx_linkrelax_branch (void)
821 rx_bytes
.link_relax
|= RX_RELAXA_BRA
;
825 rx_fixup (expressionS exp
, int offsetbits
, int nbits
, int type
)
827 rx_bytes
.fixups
[rx_bytes
.n_fixups
].exp
= exp
;
828 rx_bytes
.fixups
[rx_bytes
.n_fixups
].offset
= offsetbits
;
829 rx_bytes
.fixups
[rx_bytes
.n_fixups
].nbits
= nbits
;
830 rx_bytes
.fixups
[rx_bytes
.n_fixups
].type
= type
;
831 rx_bytes
.fixups
[rx_bytes
.n_fixups
].reloc
= exp
.X_md
;
832 rx_bytes
.n_fixups
++;
835 #define rx_field_fixup(exp, offset, nbits, type) \
836 rx_fixup (exp, offset, nbits, type)
838 #define rx_op_fixup(exp, offset, nbits, type) \
839 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
844 rx_bytes
.base
[0] = b1
;
849 rx_base2 (int b1
, int b2
)
851 rx_bytes
.base
[0] = b1
;
852 rx_bytes
.base
[1] = b2
;
857 rx_base3 (int b1
, int b2
, int b3
)
859 rx_bytes
.base
[0] = b1
;
860 rx_bytes
.base
[1] = b2
;
861 rx_bytes
.base
[2] = b3
;
866 rx_base4 (int b1
, int b2
, int b3
, int b4
)
868 rx_bytes
.base
[0] = b1
;
869 rx_bytes
.base
[1] = b2
;
870 rx_bytes
.base
[2] = b3
;
871 rx_bytes
.base
[3] = b4
;
875 /* This gets complicated when the field spans bytes, because fields
876 are numbered from the MSB of the first byte as zero, and bits are
877 stored LSB towards the LSB of the byte. Thus, a simple four-bit
878 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
879 insertion of b'MXL at position 7 is like this:
881 - - - - - - - - - - - - - - - -
885 rx_field (int val
, int pos
, int sz
)
892 if (val
< 0 || val
>= (1 << sz
))
893 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val
, sz
);
898 if (val
< -(1 << (sz
- 1)) || val
>= (1 << (sz
- 1)))
899 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val
, sz
);
902 /* This code points at 'M' in the above example. */
906 while (bitp
+ sz
> 8)
911 svalm
= val
>> (sz
- ssz
);
912 svalm
= svalm
& ((1 << ssz
) - 1);
913 svalm
= svalm
<< (8 - bitp
- ssz
);
914 gas_assert (bytep
< rx_bytes
.n_base
);
915 rx_bytes
.base
[bytep
] |= svalm
;
921 valm
= val
& ((1 << sz
) - 1);
922 valm
= valm
<< (8 - bitp
- sz
);
923 gas_assert (bytep
< rx_bytes
.n_base
);
924 rx_bytes
.base
[bytep
] |= valm
;
927 /* Special case of the above, for 3-bit displacements of 2..9. */
930 rx_disp3 (expressionS exp
, int pos
)
932 rx_field_fixup (exp
, pos
, 3, RXREL_PCREL
);
935 /* Special case of the above, for split 5-bit displacements. Assumes
936 the displacement has been checked with rx_disp5op. */
937 /* ---- -432 1--- 0--- */
940 rx_field5s (expressionS exp
)
944 val
= exp
.X_add_number
;
945 rx_bytes
.base
[0] |= val
>> 2;
946 rx_bytes
.base
[1] |= (val
<< 6) & 0x80;
947 rx_bytes
.base
[1] |= (val
<< 3) & 0x08;
950 /* ---- ---- 4--- 3210 */
953 rx_field5s2 (expressionS exp
)
957 val
= exp
.X_add_number
;
958 rx_bytes
.base
[1] |= (val
<< 3) & 0x80;
959 rx_bytes
.base
[1] |= (val
) & 0x0f;
963 rx_bfield(expressionS s
, expressionS d
, expressionS w
)
965 int slsb
= s
.X_add_number
;
966 int dlsb
= d
.X_add_number
;
967 int width
= w
.X_add_number
;
969 (((dlsb
+ width
) & 0x1f) << 10 | (dlsb
<< 5) |
970 ((dlsb
- slsb
) & 0x1f));
971 if ((slsb
+ width
) > 32)
972 as_warn (_("Value %d and %d out of range"), slsb
, width
);
973 if ((dlsb
+ width
) > 32)
974 as_warn (_("Value %d and %d out of range"), dlsb
, width
);
975 rx_bytes
.ops
[0] = imm
& 0xff;
976 rx_bytes
.ops
[1] = (imm
>> 8);
980 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
982 #define F_PRECISION 2
985 rx_op (expressionS exp
, int nbytes
, int type
)
989 if ((exp
.X_op
== O_constant
|| exp
.X_op
== O_big
)
990 && type
!= RXREL_PCREL
)
992 if (exp
.X_op
== O_big
)
994 if (exp
.X_add_number
== -1)
997 char * ip
= rx_bytes
.ops
+ rx_bytes
.n_ops
;
999 gen_to_words (w
, F_PRECISION
, 8);
1000 #if RX_OPCODE_BIG_ENDIAN
1011 rx_bytes
.n_ops
+= 4;
1015 v
= ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
1016 | (generic_bignum
[0] & LITTLENUM_MASK
);
1020 v
= exp
.X_add_number
;
1024 #if RX_OPCODE_BIG_ENDIAN
1025 OP ((v
>> (8 * (nbytes
- 1))) & 0xff);
1035 rx_op_fixup (exp
, rx_bytes
.n_ops
* 8, nbytes
* 8, type
);
1036 memset (rx_bytes
.ops
+ rx_bytes
.n_ops
, 0, nbytes
);
1037 rx_bytes
.n_ops
+= nbytes
;
1041 void rx_post(char byte
)
1043 rx_bytes
.post
[rx_bytes
.n_post
++] = byte
;
1052 #define APPEND(B, N_B) \
1055 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
1056 idx += rx_bytes.N_B; \
1060 rx_frag_init (fragS
* fragP
)
1062 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
|| rx_bytes
.n_base
< 0)
1064 fragP
->tc_frag_data
= XNEW (rx_bytesT
);
1065 memcpy (fragP
->tc_frag_data
, & rx_bytes
, sizeof (rx_bytesT
));
1068 fragP
->tc_frag_data
= 0;
1071 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
1072 <symbol_name> .equ <expression> */
1075 rx_equ (char * name
, char * expression
)
1077 char saved_name_end_char
;
1081 while (ISSPACE (* name
))
1084 for (name_end
= name
+ 1; *name_end
; name_end
++)
1085 if (! ISALNUM (* name_end
))
1088 saved_name_end_char
= * name_end
;
1091 saved_ilp
= input_line_pointer
;
1092 input_line_pointer
= expression
;
1096 input_line_pointer
= saved_ilp
;
1097 * name_end
= saved_name_end_char
;
1100 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
1101 rather than at the start of a line. (eg .EQU or .DEFINE). If one
1102 is found, process it and return TRUE otherwise return FALSE. */
1105 scan_for_infix_rx_pseudo_ops (char * str
)
1109 char * dot
= strchr (str
, '.');
1111 if (dot
== NULL
|| dot
== str
)
1114 /* A real pseudo-op must be preceded by whitespace. */
1115 if (dot
[-1] != ' ' && dot
[-1] != '\t')
1118 pseudo_op
= dot
+ 1;
1120 if (!ISALNUM (* pseudo_op
))
1123 for (p
= pseudo_op
+ 1; ISALNUM (* p
); p
++)
1126 if (strncasecmp ("EQU", pseudo_op
, p
- pseudo_op
) == 0)
1128 else if (strncasecmp ("DEFINE", pseudo_op
, p
- pseudo_op
) == 0)
1129 as_warn (_("The .DEFINE pseudo-op is not implemented"));
1130 else if (strncasecmp ("MACRO", pseudo_op
, p
- pseudo_op
) == 0)
1131 as_warn (_("The .MACRO pseudo-op is not implemented"));
1132 else if (strncasecmp ("BTEQU", pseudo_op
, p
- pseudo_op
) == 0)
1133 as_warn (_("The .BTEQU pseudo-op is not implemented."));
1141 md_assemble (char * str
)
1146 fragS
* frag_then
= frag_now
;
1149 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
1151 rx_lex_init (str
, str
+ strlen (str
));
1152 if (scan_for_infix_rx_pseudo_ops (str
))
1156 /* This simplifies the relaxation code. */
1157 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
1159 /* We do it this way because we want the frag to have the
1160 rx_bytes in it, which we initialize above. */
1161 bytes
= frag_more (12);
1162 frag_then
= frag_now
;
1163 frag_variant (rs_machine_dependent
,
1170 frag_then
->fr_opcode
= bytes
;
1171 frag_then
->fr_fix
+= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1172 frag_then
->fr_subtype
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1176 bytes
= frag_more (rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
);
1177 frag_then
= frag_now
;
1178 if (fetchalign_bytes
)
1179 fetchalign_bytes
->n_ops
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1182 fetchalign_bytes
= NULL
;
1184 APPEND (base
, n_base
);
1185 APPEND (ops
, n_ops
);
1186 APPEND (post
, n_post
);
1188 if (rx_bytes
.link_relax
&& rx_bytes
.n_fixups
)
1192 f
= fix_new (frag_then
,
1193 (char *) bytes
- frag_then
->fr_literal
,
1196 rx_bytes
.link_relax
| rx_bytes
.n_fixups
,
1198 BFD_RELOC_RX_RELAX
);
1199 frag_then
->tc_frag_data
->link_relax_fixP
= f
;
1202 for (i
= 0; i
< rx_bytes
.n_fixups
; i
++)
1204 /* index: [nbytes][type] */
1205 static int reloc_map
[5][4] =
1207 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL
},
1208 { BFD_RELOC_8
, BFD_RELOC_RX_8U
, BFD_RELOC_RX_NEG8
, BFD_RELOC_8_PCREL
},
1209 { BFD_RELOC_RX_16_OP
, BFD_RELOC_RX_16U
, BFD_RELOC_RX_NEG16
, BFD_RELOC_16_PCREL
},
1210 { BFD_RELOC_RX_24_OP
, BFD_RELOC_RX_24U
, BFD_RELOC_RX_NEG24
, BFD_RELOC_24_PCREL
},
1211 { BFD_RELOC_RX_32_OP
, BFD_RELOC_32
, BFD_RELOC_RX_NEG32
, BFD_RELOC_32_PCREL
},
1215 idx
= rx_bytes
.fixups
[i
].offset
/ 8;
1216 rel
= reloc_map
[rx_bytes
.fixups
[i
].nbits
/ 8][(int) rx_bytes
.fixups
[i
].type
];
1218 if (rx_bytes
.fixups
[i
].reloc
)
1219 rel
= rx_bytes
.fixups
[i
].reloc
;
1221 if (frag_then
->tc_frag_data
)
1222 exp
= & frag_then
->tc_frag_data
->fixups
[i
].exp
;
1224 exp
= & rx_bytes
.fixups
[i
].exp
;
1226 f
= fix_new_exp (frag_then
,
1227 (char *) bytes
+ idx
- frag_then
->fr_literal
,
1228 rx_bytes
.fixups
[i
].nbits
/ 8,
1230 rx_bytes
.fixups
[i
].type
== RXREL_PCREL
? 1 : 0,
1232 if (frag_then
->tc_frag_data
)
1233 frag_then
->tc_frag_data
->fixups
[i
].fixP
= f
;
1235 dwarf2_emit_insn (idx
);
1243 /* Write a value out to the object file, using the appropriate endianness. */
1246 md_number_to_chars (char * buf
, valueT val
, int n
)
1248 if (target_big_endian
)
1249 number_to_chars_bigendian (buf
, val
, n
);
1251 number_to_chars_littleendian (buf
, val
, n
);
1261 { "gp", BFD_RELOC_GPREL16
},
1266 md_operand (expressionS
* exp ATTRIBUTE_UNUSED
)
1271 for (i
= 0; reloc_functions
[i
].fname
; i
++)
1273 int flen
= strlen (reloc_functions
[i
].fname
);
1275 if (input_line_pointer
[0] == '%'
1276 && strncasecmp (input_line_pointer
+ 1, reloc_functions
[i
].fname
, flen
) == 0
1277 && input_line_pointer
[flen
+ 1] == '(')
1279 reloc
= reloc_functions
[i
].reloc
;
1280 input_line_pointer
+= flen
+ 2;
1288 if (* input_line_pointer
== ')')
1289 input_line_pointer
++;
1295 md_section_align (segT segment
, valueT size
)
1297 int align
= bfd_section_alignment (segment
);
1298 return ((size
+ (1 << align
) - 1) & -(1 << align
));
1302 static unsigned char nop_1
[] = { 0x03};
1303 /* MOV.L R0,R0 - 1 cycle */
1304 static unsigned char nop_2
[] = { 0xef, 0x00};
1305 /* MAX R0,R0 - 1 cycle */
1306 static unsigned char nop_3
[] = { 0xfc, 0x13, 0x00 };
1307 /* MUL #1,R0 - 1 cycle */
1308 static unsigned char nop_4
[] = { 0x76, 0x10, 0x01, 0x00 };
1309 /* MUL #1,R0 - 1 cycle */
1310 static unsigned char nop_5
[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
1311 /* MUL #1,R0 - 1 cycle */
1312 static unsigned char nop_6
[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
1313 /* MAX 0x80000000,R0 - 1 cycle */
1314 static unsigned char nop_7
[] = { 0xFD, 0x70, 0x40, 0x00, 0x00, 0x00, 0x80 };
1316 static unsigned char *nops
[] = { NULL
, nop_1
, nop_2
, nop_3
, nop_4
, nop_5
, nop_6
, nop_7
};
1317 #define BIGGEST_NOP 7
1319 /* When relaxing, we need to output a reloc for any .align directive
1320 so that we can retain this alignment as we adjust opcode sizes. */
1322 rx_handle_align (fragS
* frag
)
1324 /* If handling an alignment frag, use an optimal NOP pattern.
1325 Only do this if a fill value has not already been provided.
1326 FIXME: This test fails if the provided fill value is zero. */
1327 if ((frag
->fr_type
== rs_align
1328 || frag
->fr_type
== rs_align_code
)
1329 && subseg_text_p (now_seg
))
1331 int count
= (frag
->fr_next
->fr_address
1334 unsigned char *base
= (unsigned char *)frag
->fr_literal
+ frag
->fr_fix
;
1338 if (count
> BIGGEST_NOP
)
1346 memcpy (base
, nops
[count
], count
);
1347 frag
->fr_var
= count
;
1353 && (frag
->fr_type
== rs_align
1354 || frag
->fr_type
== rs_align_code
)
1355 && frag
->fr_address
+ frag
->fr_fix
> 0
1356 && frag
->fr_offset
> 0
1357 && now_seg
!= bss_section
)
1359 fix_new (frag
, frag
->fr_fix
, 0,
1360 &abs_symbol
, RX_RELAXA_ALIGN
+ frag
->fr_offset
,
1361 0, BFD_RELOC_RX_RELAX
);
1362 /* For the purposes of relaxation, this relocation is attached
1363 to the byte *after* the alignment - i.e. the byte that must
1365 fix_new (frag
->fr_next
, 0, 0,
1366 &abs_symbol
, RX_RELAXA_ELIGN
+ frag
->fr_offset
,
1367 0, BFD_RELOC_RX_RELAX
);
1372 md_atof (int type
, char * litP
, int * sizeP
)
1374 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1378 md_undefined_symbol (char * name ATTRIBUTE_UNUSED
)
1383 /*----------------------------------------------------------------------*/
1384 /* To recap: we estimate everything based on md_estimate_size, then
1385 adjust based on rx_relax_frag. When it all settles, we call
1386 md_convert frag to update the bytes. The relaxation types and
1387 relocations are in fragP->tc_frag_data, which is a copy of that
1390 Our scheme is as follows: fr_fix has the size of the smallest
1391 opcode (like BRA.S). We store the number of total bytes we need in
1392 fr_subtype. When we're done relaxing, we use fr_subtype and the
1393 existing opcode bytes to figure out what actual opcode we need to
1394 put in there. If the fixup isn't resolvable now, we use the
1397 #define TRACE_RELAX 0
1398 #define tprintf if (TRACE_RELAX) printf
1410 /* We're looking for these types of relaxations:
1413 BRA.B 00101110 dspppppp
1414 BRA.W 00111000 dspppppp pppppppp
1415 BRA.A 00000100 dspppppp pppppppp pppppppp
1418 BEQ.B 00100000 dspppppp
1419 BEQ.W 00111010 dspppppp pppppppp
1422 BNE.B 00100001 dspppppp
1423 BNE.W 00111011 dspppppp pppppppp
1425 BSR.W 00111001 dspppppp pppppppp
1426 BSR.A 00000101 dspppppp pppppppp pppppppp
1428 Bcc.B 0010cond dspppppp
1430 Additionally, we can synthesize longer conditional branches using
1431 pairs of opcodes, one with an inverted conditional (flip LSB):
1433 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1434 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1435 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1436 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1438 /* Given the opcode bytes at OP, figure out which opcode it is and
1439 return the type of opcode. We use this to re-encode the opcode as
1440 a different size later. */
1443 rx_opcode_type (char * op
)
1445 unsigned char b
= (unsigned char) op
[0];
1449 case 0x08: return OT_bra
;
1450 case 0x10: return OT_beq
;
1451 case 0x18: return OT_bne
;
1456 case 0x2e: return OT_bra
;
1457 case 0x38: return OT_bra
;
1458 case 0x04: return OT_bra
;
1460 case 0x20: return OT_beq
;
1461 case 0x3a: return OT_beq
;
1463 case 0x21: return OT_bne
;
1464 case 0x3b: return OT_bne
;
1466 case 0x39: return OT_bsr
;
1467 case 0x05: return OT_bsr
;
1470 if ((b
& 0xf0) == 0x20)
1476 /* Returns zero if *addrP has the target address. Else returns nonzero
1477 if we cannot compute the target address yet. */
1480 rx_frag_fix_value (fragS
* fragP
,
1485 addressT
* sym_addr
)
1488 rx_bytesT
* b
= fragP
->tc_frag_data
;
1489 expressionS
* exp
= & b
->fixups
[which
].exp
;
1491 if (need_diff
&& exp
->X_op
!= O_subtract
)
1494 if (exp
->X_add_symbol
)
1496 if (S_FORCE_RELOC (exp
->X_add_symbol
, 1))
1498 if (S_GET_SEGMENT (exp
->X_add_symbol
) != segment
)
1500 addr
+= S_GET_VALUE (exp
->X_add_symbol
);
1503 if (exp
->X_op_symbol
)
1505 if (exp
->X_op
!= O_subtract
)
1507 if (S_FORCE_RELOC (exp
->X_op_symbol
, 1))
1509 if (S_GET_SEGMENT (exp
->X_op_symbol
) != segment
)
1511 addr
-= S_GET_VALUE (exp
->X_op_symbol
);
1515 addr
+= exp
->X_add_number
;
1520 /* Estimate how big the opcode is after this relax pass. The return
1521 value is the difference between fr_fix and the actual size. We
1522 compute the total size in rx_relax_frag and store it in fr_subtype,
1523 so we only need to subtract fx_fix and return it. */
1526 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
, segT segment ATTRIBUTE_UNUSED
)
1531 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1532 (unsigned long) (fragP
->fr_address
1533 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1534 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1535 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1537 /* This is the size of the opcode that's accounted for in fr_fix. */
1538 opfixsize
= fragP
->fr_fix
- (fragP
->fr_opcode
- fragP
->fr_literal
);
1539 /* This is the size of the opcode that isn't. */
1540 delta
= (fragP
->fr_subtype
- opfixsize
);
1542 tprintf (" -> opfixsize %d delta %d\n", opfixsize
, delta
);
1546 /* Given a frag FRAGP, return the "next" frag that contains an
1547 opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
1550 rx_next_opcode (fragS
*fragP
)
1553 fragP
= fragP
->fr_next
;
1554 } while (fragP
&& fragP
->fr_type
!= rs_machine_dependent
);
1558 /* Given the new addresses for this relax pass, figure out how big
1559 each opcode must be. We store the total number of bytes needed in
1560 fr_subtype. The return value is the difference between the size
1561 after the last pass and the size after this pass, so we use the old
1562 fr_subtype to calculate the difference. */
1565 rx_relax_frag (segT segment ATTRIBUTE_UNUSED
, fragS
* fragP
, long stretch
, unsigned long max_iterations
)
1567 addressT addr0
, sym_addr
;
1570 int oldsize
= fragP
->fr_subtype
;
1571 int newsize
= oldsize
;
1573 /* Index of relaxation we care about. */
1576 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",
1577 (unsigned long) (fragP
->fr_address
1578 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1579 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1580 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
, stretch
);
1582 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1584 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1586 unsigned int next_size
;
1587 if (fragP
->fr_next
== NULL
)
1590 next_size
= fragP
->tc_frag_data
->n_ops
;
1593 fragS
*n
= rx_next_opcode (fragP
);
1594 next_size
= n
->fr_subtype
;
1597 fragP
->fr_subtype
= (8-(mypc
& 7)) & 7;
1598 tprintf("subtype %u\n", fragP
->fr_subtype
);
1599 if (fragP
->fr_subtype
>= next_size
)
1600 fragP
->fr_subtype
= 0;
1601 tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
1602 (unsigned long) (mypc
& 7),
1603 next_size
, fragP
->fr_subtype
, oldsize
, fragP
->fr_subtype
-oldsize
);
1605 newsize
= fragP
->fr_subtype
;
1607 return newsize
- oldsize
;
1610 optype
= rx_opcode_type (fragP
->fr_opcode
);
1612 /* In the one case where we have both a disp and imm relaxation, we want
1613 the imm relaxation here. */
1615 if (fragP
->tc_frag_data
->n_relax
> 1
1616 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1619 /* Try to get the target address. */
1620 if (rx_frag_fix_value (fragP
, segment
, ri
, & addr0
,
1621 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
,
1624 /* If we don't, we must use the maximum size for the linker.
1625 Note that we don't use synthetically expanded conditionals
1627 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1629 case RX_RELAX_BRANCH
:
1650 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
+ 4;
1653 fragP
->fr_subtype
= newsize
;
1654 tprintf (" -> new %d old %d delta %d (external)\n", newsize
, oldsize
, newsize
-oldsize
);
1655 return newsize
- oldsize
;
1658 if (sym_addr
> mypc
)
1661 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1663 case RX_RELAX_BRANCH
:
1664 tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
1665 (unsigned long) addr0
, (unsigned long) mypc
,
1666 (long) (addr0
- mypc
));
1667 disp
= (int) addr0
- (int) mypc
;
1672 if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1675 else if (disp
>= -32768 && (disp
- (oldsize
-5)) <= 32767)
1685 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1688 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1691 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1701 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1704 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1707 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1718 tprintf (" - newsize %d\n", newsize
);
1722 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
1723 (unsigned long) addr0
, (unsigned long) mypc
,
1724 fragP
->tc_frag_data
->relax
[ri
].field_pos
,
1725 fragP
->tc_frag_data
->relax
[ri
].val_ofs
);
1727 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1729 if ((long) addr0
>= -128 && (long) addr0
<= 127)
1731 else if ((long) addr0
>= -32768 && (long) addr0
<= 32767)
1733 else if ((long) addr0
>= -8388608 && (long) addr0
<= 8388607)
1743 if (fragP
->tc_frag_data
->relax
[ri
].type
== RX_RELAX_BRANCH
)
1759 /* This prevents infinite loops in align-heavy sources. */
1760 if (newsize
< oldsize
)
1762 /* Make sure that our iteration limit is no bigger than the one being
1763 used inside write.c:relax_segment(). Otherwise we can end up
1764 iterating for too long, and triggering a fatal error there. See
1765 PR 24464 for more details. */
1766 unsigned long limit
= max_iterations
> 10 ? 10 : max_iterations
;
1768 if (fragP
->tc_frag_data
->times_shrank
> limit
1769 && fragP
->tc_frag_data
->times_grown
> limit
)
1772 if (fragP
->tc_frag_data
->times_shrank
< 20)
1773 fragP
->tc_frag_data
->times_shrank
++;
1775 else if (newsize
> oldsize
)
1777 if (fragP
->tc_frag_data
->times_grown
< 20)
1778 fragP
->tc_frag_data
->times_grown
++;
1781 fragP
->fr_subtype
= newsize
;
1782 tprintf (" -> new %d old %d delta %d\n", newsize
, oldsize
, newsize
-oldsize
);
1783 return newsize
- oldsize
;
1786 /* This lets us test for the opcode type and the desired size in a
1787 switch statement. */
1788 #define OPCODE(type,size) ((type) * 16 + (size))
1790 /* Given the opcode stored in fr_opcode and the number of bytes we
1791 think we need, encode a new opcode. We stored a pointer to the
1792 fixup for this opcode in the tc_frag_data structure. If we can do
1793 the fixup here, we change the relocation type to "none" (we test
1794 for that in tc_gen_reloc) else we change it to the right type for
1795 the new (biggest) opcode. */
1798 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1799 segT segment ATTRIBUTE_UNUSED
,
1800 fragS
* fragP ATTRIBUTE_UNUSED
)
1802 rx_bytesT
* rxb
= fragP
->tc_frag_data
;
1803 addressT addr0
, mypc
;
1806 bfd_reloc_code_real_type reloc_type
;
1807 char * op
= fragP
->fr_opcode
;
1810 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1811 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1813 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1814 (unsigned long) (fragP
->fr_address
1815 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1816 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1817 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
,
1824 printf ("lit 0x%p opc 0x%p", fragP
->fr_literal
, fragP
->fr_opcode
);
1825 for (i
= 0; i
< 10; i
++)
1826 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1831 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1833 int count
= fragP
->fr_subtype
;
1836 else if (count
> BIGGEST_NOP
)
1843 memcpy (op
, nops
[count
], count
);
1847 /* In the one case where we have both a disp and imm relaxation, we want
1848 the imm relaxation here. */
1850 if (fragP
->tc_frag_data
->n_relax
> 1
1851 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1854 /* We used a new frag for this opcode, so the opcode address should
1855 be the frag address. */
1856 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1858 /* Try to get the target address. If we fail here, we just use the
1860 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1861 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1863 /* We don't know the target address. */
1870 /* We know the target address, and it's in addr0. */
1871 disp
= (int) addr0
- (int) mypc
;
1877 reloc_type
= BFD_RELOC_NONE
;
1880 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1881 rx_opcode_type (fragP
->fr_opcode
), disp
,
1882 (unsigned long) addr0
, (unsigned long) mypc
);
1883 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1885 case RX_RELAX_BRANCH
:
1886 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1888 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1889 op
[0] = 0x08 + (disp
& 7);
1891 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1894 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1897 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1899 #if RX_OPCODE_BIG_ENDIAN
1900 op
[1] = (disp
>> 8) & 0xff;
1903 op
[2] = (disp
>> 8) & 0xff;
1907 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1909 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1911 #if RX_OPCODE_BIG_ENDIAN
1912 op
[1] = (disp
>> 16) & 0xff;
1913 op
[2] = (disp
>> 8) & 0xff;
1916 op
[3] = (disp
>> 16) & 0xff;
1917 op
[2] = (disp
>> 8) & 0xff;
1920 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1924 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1925 op
[0] = 0x10 + (disp
& 7);
1927 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1931 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1933 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1935 #if RX_OPCODE_BIG_ENDIAN
1936 op
[1] = (disp
>> 8) & 0xff;
1939 op
[2] = (disp
>> 8) & 0xff;
1942 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1945 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1946 op
[0] = 0x1d; /* bne.s .+5. */
1947 op
[1] = 0x04; /* bra.a dsp:24. */
1949 #if RX_OPCODE_BIG_ENDIAN
1950 op
[2] = (disp
>> 16) & 0xff;
1951 op
[3] = (disp
>> 8) & 0xff;
1954 op
[4] = (disp
>> 16) & 0xff;
1955 op
[3] = (disp
>> 8) & 0xff;
1958 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1962 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1963 op
[0] = 0x18 + (disp
& 7);
1965 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1969 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1971 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1973 #if RX_OPCODE_BIG_ENDIAN
1974 op
[1] = (disp
>> 8) & 0xff;
1977 op
[2] = (disp
>> 8) & 0xff;
1980 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1983 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1984 op
[0] = 0x15; /* beq.s .+5. */
1985 op
[1] = 0x04; /* bra.a dsp:24. */
1987 #if RX_OPCODE_BIG_ENDIAN
1988 op
[2] = (disp
>> 16) & 0xff;
1989 op
[3] = (disp
>> 8) & 0xff;
1992 op
[4] = (disp
>> 16) & 0xff;
1993 op
[3] = (disp
>> 8) & 0xff;
1996 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2000 case OPCODE (OT_bsr
, 3): /* BSR.W - 16 bit. */
2002 #if RX_OPCODE_BIG_ENDIAN
2003 op
[1] = (disp
>> 8) & 0xff;
2006 op
[2] = (disp
>> 8) & 0xff;
2009 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2012 case OPCODE (OT_bsr
, 4): /* BSR.A - 24 bit. */
2014 #if RX_OPCODE_BIG_ENDIAN
2015 op
[1] = (disp
>> 16) & 0xff;
2016 op
[2] = (disp
>> 8) & 0xff;
2019 op
[3] = (disp
>> 16) & 0xff;
2020 op
[2] = (disp
>> 8) & 0xff;
2023 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2027 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
2029 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
2031 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
2032 op
[0] ^= 1; /* Invert condition. */
2033 op
[1] = 5; /* Displacement. */
2036 #if RX_OPCODE_BIG_ENDIAN
2037 op
[3] = (disp
>> 8) & 0xff;
2040 op
[4] = (disp
>> 8) & 0xff;
2043 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2046 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
2047 op
[0] ^= 1; /* Invert condition. */
2048 op
[1] = 6; /* Displacement. */
2051 #if RX_OPCODE_BIG_ENDIAN
2052 op
[3] = (disp
>> 16) & 0xff;
2053 op
[4] = (disp
>> 8) & 0xff;
2056 op
[5] = (disp
>> 16) & 0xff;
2057 op
[4] = (disp
>> 8) & 0xff;
2060 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2065 /* These are opcodes we'll relax in th linker, later. */
2067 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
2074 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2076 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2083 reloc_type
= BFD_RELOC_8
;
2087 #if RX_OPCODE_BIG_ENDIAN
2089 imm
[0] = addr0
>> 8;
2092 imm
[1] = addr0
>> 8;
2094 reloc_type
= BFD_RELOC_RX_16_OP
;
2098 #if RX_OPCODE_BIG_ENDIAN
2100 imm
[1] = addr0
>> 8;
2101 imm
[0] = addr0
>> 16;
2104 imm
[1] = addr0
>> 8;
2105 imm
[2] = addr0
>> 16;
2107 reloc_type
= BFD_RELOC_RX_24_OP
;
2111 #if RX_OPCODE_BIG_ENDIAN
2113 imm
[2] = addr0
>> 8;
2114 imm
[1] = addr0
>> 16;
2115 imm
[0] = addr0
>> 24;
2118 imm
[1] = addr0
>> 8;
2119 imm
[2] = addr0
>> 16;
2120 imm
[3] = addr0
>> 24;
2122 reloc_type
= BFD_RELOC_RX_32_OP
;
2125 as_bad (_("invalid immediate size"));
2129 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
2144 as_bad (_("invalid immediate field position"));
2152 reloc_type
= fix
->fx_r_type
;
2161 fix
->fx_r_type
= reloc_type
;
2162 fix
->fx_where
+= reloc_adjust
;
2165 case BFD_RELOC_NONE
:
2171 case BFD_RELOC_16_PCREL
:
2172 case BFD_RELOC_RX_16_OP
:
2175 case BFD_RELOC_24_PCREL
:
2176 case BFD_RELOC_RX_24_OP
:
2179 case BFD_RELOC_RX_32_OP
:
2187 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
2188 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP
->fr_fix
,
2189 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
2192 if (fragP
->fr_next
!= NULL
2193 && fragP
->fr_next
->fr_address
- fragP
->fr_address
!= fragP
->fr_fix
)
2194 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
2195 (long) fragP
->fr_fix
,
2196 (long) fragP
->fr_address
, (long) fragP
->fr_next
->fr_address
);
2202 rx_validate_fix_sub (struct fix
* f
)
2204 /* We permit the subtraction of two symbols in a few cases. */
2205 /* mov #sym1-sym2, R3 */
2206 if (f
->fx_r_type
== BFD_RELOC_RX_32_OP
)
2208 /* .long sym1-sym2 */
2209 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
2211 && (f
->fx_size
== 4 || f
->fx_size
== 2 || f
->fx_size
== 1))
2217 md_pcrel_from_section (fixS
* fixP
, segT sec
)
2221 if (fixP
->fx_addsy
!= NULL
2222 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2223 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
2224 /* The symbol is undefined (or is defined but not in this section).
2225 Let the linker figure it out. */
2228 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2229 switch (fixP
->fx_r_type
)
2231 case BFD_RELOC_RX_DIR3U_PCREL
:
2239 rx_cons_fix_new (fragS
* frag
,
2243 bfd_reloc_code_real_type type
)
2251 type
= BFD_RELOC_16
;
2254 type
= BFD_RELOC_24
;
2257 type
= BFD_RELOC_32
;
2260 as_bad (_("unsupported constant size %d\n"), size
);
2264 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
2266 if (size
!= 4 && size
!= 2 && size
!= 1)
2267 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2269 type
= BFD_RELOC_RX_DIFF
;
2272 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
2276 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
2277 valueT
* t ATTRIBUTE_UNUSED
,
2278 segT s ATTRIBUTE_UNUSED
)
2280 /* Instruction bytes are always little endian. */
2284 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
2286 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
2289 #define OP2(x) op[target_big_endian ? 1-x : x]
2290 #define OP3(x) op[target_big_endian ? 2-x : x]
2291 #define OP4(x) op[target_big_endian ? 3-x : x]
2293 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
2294 val
= (unsigned long) * t
;
2296 /* Opcode words are always the same endian. Data words are either
2297 big or little endian. */
2299 switch (f
->fx_r_type
)
2301 case BFD_RELOC_NONE
:
2304 case BFD_RELOC_RX_RELAX
:
2308 case BFD_RELOC_RX_DIR3U_PCREL
:
2309 if (val
< 3 || val
> 10)
2310 as_bad_where (f
->fx_file
, f
->fx_line
,
2311 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2313 op
[0] |= val
& 0x07;
2317 case BFD_RELOC_8_PCREL
:
2318 case BFD_RELOC_RX_8U
:
2323 OP2(1) = val
& 0xff;
2324 OP2(0) = (val
>> 8) & 0xff;
2327 case BFD_RELOC_16_PCREL
:
2328 case BFD_RELOC_RX_16_OP
:
2329 case BFD_RELOC_RX_16U
:
2330 #if RX_OPCODE_BIG_ENDIAN
2332 op
[0] = (val
>> 8) & 0xff;
2335 op
[1] = (val
>> 8) & 0xff;
2340 OP3(0) = val
& 0xff;
2341 OP3(1) = (val
>> 8) & 0xff;
2342 OP3(2) = (val
>> 16) & 0xff;
2345 case BFD_RELOC_24_PCREL
:
2346 case BFD_RELOC_RX_24_OP
:
2347 case BFD_RELOC_RX_24U
:
2348 #if RX_OPCODE_BIG_ENDIAN
2350 op
[1] = (val
>> 8) & 0xff;
2351 op
[0] = (val
>> 16) & 0xff;
2354 op
[1] = (val
>> 8) & 0xff;
2355 op
[2] = (val
>> 16) & 0xff;
2359 case BFD_RELOC_RX_DIFF
:
2366 OP2(0) = val
& 0xff;
2367 OP2(1) = (val
>> 8) & 0xff;
2370 OP4(0) = val
& 0xff;
2371 OP4(1) = (val
>> 8) & 0xff;
2372 OP4(2) = (val
>> 16) & 0xff;
2373 OP4(3) = (val
>> 24) & 0xff;
2379 OP4(0) = val
& 0xff;
2380 OP4(1) = (val
>> 8) & 0xff;
2381 OP4(2) = (val
>> 16) & 0xff;
2382 OP4(3) = (val
>> 24) & 0xff;
2385 case BFD_RELOC_RX_32_OP
:
2386 #if RX_OPCODE_BIG_ENDIAN
2388 op
[2] = (val
>> 8) & 0xff;
2389 op
[1] = (val
>> 16) & 0xff;
2390 op
[0] = (val
>> 24) & 0xff;
2393 op
[1] = (val
>> 8) & 0xff;
2394 op
[2] = (val
>> 16) & 0xff;
2395 op
[3] = (val
>> 24) & 0xff;
2399 case BFD_RELOC_RX_NEG8
:
2403 case BFD_RELOC_RX_NEG16
:
2405 #if RX_OPCODE_BIG_ENDIAN
2407 op
[0] = (val
>> 8) & 0xff;
2410 op
[1] = (val
>> 8) & 0xff;
2414 case BFD_RELOC_RX_NEG24
:
2416 #if RX_OPCODE_BIG_ENDIAN
2418 op
[1] = (val
>> 8) & 0xff;
2419 op
[0] = (val
>> 16) & 0xff;
2422 op
[1] = (val
>> 8) & 0xff;
2423 op
[2] = (val
>> 16) & 0xff;
2427 case BFD_RELOC_RX_NEG32
:
2429 #if RX_OPCODE_BIG_ENDIAN
2431 op
[2] = (val
>> 8) & 0xff;
2432 op
[1] = (val
>> 16) & 0xff;
2433 op
[0] = (val
>> 24) & 0xff;
2436 op
[1] = (val
>> 8) & 0xff;
2437 op
[2] = (val
>> 16) & 0xff;
2438 op
[3] = (val
>> 24) & 0xff;
2442 case BFD_RELOC_RX_GPRELL
:
2445 case BFD_RELOC_RX_GPRELW
:
2448 case BFD_RELOC_RX_GPRELB
:
2449 #if RX_OPCODE_BIG_ENDIAN
2451 op
[0] = (val
>> 8) & 0xff;
2454 op
[1] = (val
>> 8) & 0xff;
2459 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2460 bfd_get_reloc_code_name (f
->fx_r_type
));
2464 if (f
->fx_addsy
== NULL
)
2469 tc_gen_reloc (asection
* sec ATTRIBUTE_UNUSED
, fixS
* fixp
)
2471 static arelent
* reloc
[5];
2472 bfd_boolean is_opcode
= FALSE
;
2474 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2481 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2483 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2484 fixp
->fx_subsy
= NULL
;
2487 reloc
[0] = XNEW (arelent
);
2488 reloc
[0]->sym_ptr_ptr
= XNEW (asymbol
*);
2489 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2490 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2491 reloc
[0]->addend
= fixp
->fx_offset
;
2493 if (fixp
->fx_r_type
== BFD_RELOC_RX_32_OP
2496 fixp
->fx_r_type
= BFD_RELOC_RX_DIFF
;
2500 is_opcode
= sec
->flags
& SEC_CODE
;
2502 /* Certain BFD relocations cannot be translated directly into
2503 a single (non-Red Hat) RX relocation, but instead need
2504 multiple RX relocations - handle them here. */
2505 switch (fixp
->fx_r_type
)
2507 case BFD_RELOC_RX_DIFF
:
2508 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2510 reloc
[1] = XNEW (arelent
);
2511 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2512 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2513 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2514 reloc
[1]->addend
= 0;
2515 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2517 reloc
[2] = XNEW (arelent
);
2518 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2519 reloc
[2]->addend
= 0;
2520 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2521 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2523 reloc
[3] = XNEW (arelent
);
2524 switch (fixp
->fx_size
)
2527 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2530 if (!is_opcode
&& target_big_endian
)
2531 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16_REV
);
2533 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2535 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2538 if (!is_opcode
&& target_big_endian
)
2539 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32_REV
);
2541 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2544 reloc
[3]->addend
= 0;
2545 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2546 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2551 case BFD_RELOC_RX_GPRELL
:
2552 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2554 reloc
[1] = XNEW (arelent
);
2555 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2556 if (gp_symbol
== NULL
)
2558 if (symbol_table_frozen
)
2562 gp
= symbol_find ("__gp");
2564 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2566 gp_symbol
= symbol_get_bfdsym (gp
);
2569 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2571 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2572 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2573 reloc
[1]->addend
= 0;
2574 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2576 reloc
[2] = XNEW (arelent
);
2577 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2578 reloc
[2]->addend
= 0;
2579 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2580 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2582 reloc
[3] = XNEW (arelent
);
2583 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2584 reloc
[3]->addend
= 0;
2585 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2586 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2591 case BFD_RELOC_RX_GPRELW
:
2592 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2594 reloc
[1] = XNEW (arelent
);
2595 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2596 if (gp_symbol
== NULL
)
2598 if (symbol_table_frozen
)
2602 gp
= symbol_find ("__gp");
2604 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2606 gp_symbol
= symbol_get_bfdsym (gp
);
2609 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2611 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2612 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2613 reloc
[1]->addend
= 0;
2614 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2616 reloc
[2] = XNEW (arelent
);
2617 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2618 reloc
[2]->addend
= 0;
2619 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2620 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2622 reloc
[3] = XNEW (arelent
);
2623 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2624 reloc
[3]->addend
= 0;
2625 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2626 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2631 case BFD_RELOC_RX_GPRELB
:
2632 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2634 reloc
[1] = XNEW (arelent
);
2635 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2636 if (gp_symbol
== NULL
)
2638 if (symbol_table_frozen
)
2642 gp
= symbol_find ("__gp");
2644 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2646 gp_symbol
= symbol_get_bfdsym (gp
);
2649 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2651 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2652 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2653 reloc
[1]->addend
= 0;
2654 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2656 reloc
[2] = XNEW (arelent
);
2657 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2658 reloc
[2]->addend
= 0;
2659 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2660 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2662 reloc
[3] = XNEW (arelent
);
2663 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2664 reloc
[3]->addend
= 0;
2665 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2666 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2671 case BFD_RELOC_RX_NEG32
:
2672 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2674 reloc
[1] = XNEW (arelent
);
2675 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_NEG
);
2676 reloc
[1]->addend
= 0;
2677 reloc
[1]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2678 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2680 reloc
[2] = XNEW (arelent
);
2681 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2682 reloc
[2]->addend
= 0;
2683 reloc
[2]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2684 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2690 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2699 rx_note_string_insn_use (void)
2701 if ((elf_flags
& E_FLAG_RX_SINSNS_MASK
) == (E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
))
2702 as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
2703 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_YES
;
2706 /* Set the ELF specific flags. */
2709 rx_elf_final_processing (void)
2711 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2714 /* Scan the current input line for occurrences of Renesas
2715 local labels and replace them with the GAS version. */
2718 rx_start_line (void)
2720 int in_double_quote
= 0;
2721 int in_single_quote
= 0;
2723 char * p
= input_line_pointer
;
2726 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2737 /* Handle escaped double quote \" inside a string. */
2738 if (prev_char
!= '\\')
2739 in_double_quote
= ! in_double_quote
;
2743 in_single_quote
= ! in_single_quote
;
2747 if (in_double_quote
|| in_single_quote
)
2752 else if (p
[1] == '+')
2757 else if (p
[1] == '-')