1 /* tc-rx.c -- Assembler for the Renesas RX
2 Copyright (C) 2008-2023 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";
45 bool rx_use_conventional_section_names
= false;
46 static int elf_flags
= E_FLAG_RX_ABI
;
48 bool rx_use_conventional_section_names
= true;
52 static bool rx_use_small_data_limit
= false;
53 static bool rx_pid_mode
= false;
54 static int rx_num_int_regs
= 0;
58 enum rx_cpu_types rx_cpu
= RX600
;
60 static void rx_fetchalign (int ignore ATTRIBUTE_UNUSED
);
64 OPTION_BIG
= OPTION_MD_BASE
,
68 OPTION_CONVENTIONAL_SECTION_NAMES
,
69 OPTION_RENESAS_SECTION_NAMES
,
70 OPTION_SMALL_DATA_LIMIT
,
77 OPTION_DISALLOW_STRING_INSNS
,
80 #define RX_SHORTOPTS ""
81 const char * md_shortopts
= RX_SHORTOPTS
;
83 /* Assembler options. */
84 struct option md_longopts
[] =
86 {"mbig-endian-data", no_argument
, NULL
, OPTION_BIG
},
87 {"mlittle-endian-data", no_argument
, NULL
, OPTION_LITTLE
},
88 /* The next two switches are here because the
89 generic parts of the linker testsuite uses them. */
90 {"EB", no_argument
, NULL
, OPTION_BIG
},
91 {"EL", no_argument
, NULL
, OPTION_LITTLE
},
92 {"m32bit-doubles", no_argument
, NULL
, OPTION_32BIT_DOUBLES
},
93 {"m64bit-doubles", no_argument
, NULL
, OPTION_64BIT_DOUBLES
},
94 /* This option is here mainly for the binutils testsuites,
95 as many of their tests assume conventional section naming. */
96 {"muse-conventional-section-names", no_argument
, NULL
, OPTION_CONVENTIONAL_SECTION_NAMES
},
97 {"muse-renesas-section-names", no_argument
, NULL
, OPTION_RENESAS_SECTION_NAMES
},
98 {"msmall-data-limit", no_argument
, NULL
, OPTION_SMALL_DATA_LIMIT
},
99 {"relax", no_argument
, NULL
, OPTION_RELAX
},
100 {"mpid", no_argument
, NULL
, OPTION_PID
},
101 {"mint-register", required_argument
, NULL
, OPTION_INT_REGS
},
102 {"mgcc-abi", no_argument
, NULL
, OPTION_USES_GCC_ABI
},
103 {"mrx-abi", no_argument
, NULL
, OPTION_USES_RX_ABI
},
104 {"mcpu", required_argument
, NULL
, OPTION_CPU
},
105 {"mno-allow-string-insns", no_argument
, NULL
, OPTION_DISALLOW_STRING_INSNS
},
106 {NULL
, no_argument
, NULL
, 0}
108 size_t md_longopts_size
= sizeof (md_longopts
);
112 const char *cpu_name
;
113 enum rx_cpu_types type
;
117 struct cpu_type cpu_type_list
[] =
123 {"rxv2", RXV2
, E_FLAG_RX_V2
},
124 {"rxv3", RXV3
, E_FLAG_RX_V3
},
125 {"rxv3-dfpu", RXV3FPU
, E_FLAG_RX_V3
},
129 md_parse_option (int c ATTRIBUTE_UNUSED
, const char * arg ATTRIBUTE_UNUSED
)
134 target_big_endian
= 1;
138 target_big_endian
= 0;
141 case OPTION_32BIT_DOUBLES
:
142 elf_flags
&= ~ E_FLAG_RX_64BIT_DOUBLES
;
145 case OPTION_64BIT_DOUBLES
:
146 elf_flags
|= E_FLAG_RX_64BIT_DOUBLES
;
149 case OPTION_CONVENTIONAL_SECTION_NAMES
:
150 rx_use_conventional_section_names
= true;
153 case OPTION_RENESAS_SECTION_NAMES
:
154 rx_use_conventional_section_names
= false;
157 case OPTION_SMALL_DATA_LIMIT
:
158 rx_use_small_data_limit
= true;
167 elf_flags
|= E_FLAG_RX_PID
;
170 case OPTION_INT_REGS
:
171 rx_num_int_regs
= atoi (optarg
);
174 case OPTION_USES_GCC_ABI
:
175 elf_flags
&= ~ E_FLAG_RX_ABI
;
178 case OPTION_USES_RX_ABI
:
179 elf_flags
|= E_FLAG_RX_ABI
;
185 for (i
= 0; i
< ARRAY_SIZE (cpu_type_list
); i
++)
187 if (strcasecmp (arg
, cpu_type_list
[i
].cpu_name
) == 0)
189 rx_cpu
= cpu_type_list
[i
].type
;
190 elf_flags
|= cpu_type_list
[i
].flag
;
194 as_warn (_("unrecognised RX CPU type %s"), arg
);
198 case OPTION_DISALLOW_STRING_INSNS
:
199 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
;
207 md_show_usage (FILE * stream
)
209 fprintf (stream
, _(" RX specific command line options:\n"));
210 fprintf (stream
, _(" --mbig-endian-data\n"));
211 fprintf (stream
, _(" --mlittle-endian-data [default]\n"));
212 fprintf (stream
, _(" --m32bit-doubles [default]\n"));
213 fprintf (stream
, _(" --m64bit-doubles\n"));
214 fprintf (stream
, _(" --muse-conventional-section-names\n"));
215 fprintf (stream
, _(" --muse-renesas-section-names [default]\n"));
216 fprintf (stream
, _(" --msmall-data-limit\n"));
217 fprintf (stream
, _(" --mrelax\n"));
218 fprintf (stream
, _(" --mpid\n"));
219 fprintf (stream
, _(" --mint-register=<value>\n"));
220 fprintf (stream
, _(" --mcpu=<rx100|rx200|rx600|rx610|rxv2|rxv3|rxv3-dfpu>\n"));
221 fprintf (stream
, _(" --mno-allow-string-insns"));
225 s_bss (int ignore ATTRIBUTE_UNUSED
)
229 temp
= get_absolute_expression ();
230 subseg_set (bss_section
, (subsegT
) temp
);
231 demand_empty_rest_of_line ();
235 rx_float_cons (int ignore ATTRIBUTE_UNUSED
)
237 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
238 return float_cons ('d');
239 return float_cons ('f');
243 rx_strcasestr (const char *string
, const char *sub
)
249 return (char *)string
;
252 strl
= strlen (string
);
256 /* strncasecmp is in libiberty. */
257 if (strncasecmp (string
, sub
, subl
) == 0)
258 return (char *)string
;
267 rx_include (int ignore
)
272 const char * current_filename
;
280 /* The RX version of the .INCLUDE pseudo-op does not
281 have to have the filename inside double quotes. */
283 if (*input_line_pointer
== '"')
285 /* Treat as the normal GAS .include pseudo-op. */
290 /* Get the filename. Spaces are allowed, NUL characters are not. */
291 filename
= input_line_pointer
;
292 last_char
= find_end_of_line (filename
, false);
293 input_line_pointer
= last_char
;
295 while (last_char
>= filename
&& (* last_char
== ' ' || * last_char
== '\n'))
297 end_char
= *(++ last_char
);
299 if (last_char
== filename
)
301 as_bad (_("no filename following .INCLUDE pseudo-op"));
302 * last_char
= end_char
;
306 current_filename
= as_where (NULL
);
307 f
= XNEWVEC (char, strlen (current_filename
) + strlen (filename
) + 1);
309 /* Check the filename. If [@]..FILE[@] is found then replace
310 this with the current assembler source filename, stripped
311 of any directory prefixes or extensions. */
312 if ((p
= rx_strcasestr (filename
, "..file")) != NULL
)
316 len
= 6; /* strlen ("..file"); */
318 if (p
> filename
&& p
[-1] == '@')
324 for (d
= c
= current_filename
; *c
; c
++)
325 if (IS_DIR_SEPARATOR (* c
))
331 sprintf (f
, "%.*s%.*s%.*s", (int) (p
- filename
), filename
,
333 (int) (strlen (filename
) - ((p
+ len
) - filename
)),
337 strcpy (f
, filename
);
339 /* RX .INCLUDE semantics say that 'filename' is located by:
341 1. If filename is absolute, just try that. Otherwise...
343 2. If the current source file includes a directory component
344 then prepend that to the filename and try. Otherwise...
346 3. Try any directories specified by the -I command line
349 4 .Try a directory specified by the INC100 environment variable. */
351 if (IS_ABSOLUTE_PATH (f
))
352 try = fopen (path
= f
, FOPEN_RT
);
355 char * env
= getenv ("INC100");
359 len
= strlen (current_filename
);
360 if ((size_t) include_dir_maxlen
> len
)
361 len
= include_dir_maxlen
;
362 if (env
&& strlen (env
) > len
)
365 path
= XNEWVEC (char, strlen (f
) + len
+ 5);
367 if (current_filename
!= NULL
)
369 for (d
= NULL
, p
= current_filename
; *p
; p
++)
370 if (IS_DIR_SEPARATOR (* p
))
375 sprintf (path
, "%.*s/%s", (int) (d
- current_filename
), current_filename
,
377 try = fopen (path
, FOPEN_RT
);
383 for (size_t i
= 0; i
< include_dir_count
; i
++)
385 sprintf (path
, "%s/%s", include_dirs
[i
], f
);
386 if ((try = fopen (path
, FOPEN_RT
)) != NULL
)
391 if (try == NULL
&& env
!= NULL
)
393 sprintf (path
, "%s/%s", env
, f
);
394 try = fopen (path
, FOPEN_RT
);
402 as_bad (_("unable to locate include file: %s"), filename
);
408 register_dependency (path
);
409 input_scrub_insert_file (path
);
412 * last_char
= end_char
;
416 parse_rx_section (char * name
)
420 int attr
= SHF_ALLOC
| SHF_EXECINSTR
;
429 for (p
= input_line_pointer
; *p
&& strchr ("\n\t, =", *p
) == NULL
; p
++)
434 if (strcasecmp (input_line_pointer
, "ALIGN") == 0)
449 case '2': align
= 1; break;
450 case '4': align
= 2; break;
451 case '8': align
= 3; break;
453 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p
);
454 ignore_rest_of_line ();
462 else if (strcasecmp (input_line_pointer
, "CODE") == 0)
463 attr
= SHF_ALLOC
| SHF_EXECINSTR
;
464 else if (strcasecmp (input_line_pointer
, "DATA") == 0)
465 attr
= SHF_ALLOC
| SHF_WRITE
;
466 else if (strcasecmp (input_line_pointer
, "ROMDATA") == 0)
470 as_bad (_("unknown parameter following .SECTION directive: %s"),
474 input_line_pointer
= p
+ 1;
475 ignore_rest_of_line ();
480 input_line_pointer
= p
+ 1;
482 while (end_char
!= '\n' && end_char
!= 0);
484 if ((sec
= bfd_get_section_by_name (stdoutput
, name
)) == NULL
)
486 if (strcmp (name
, "B") && strcmp (name
, "B_1") && strcmp (name
, "B_2"))
491 obj_elf_change_section (name
, type
, attr
, 0, NULL
, false, false);
493 else /* Try not to redefine a section, especially B_1. */
495 int flags
= sec
->flags
;
497 type
= elf_section_type (sec
);
499 attr
= ((flags
& SEC_READONLY
) ? 0 : SHF_WRITE
)
500 | ((flags
& SEC_ALLOC
) ? SHF_ALLOC
: 0)
501 | ((flags
& SEC_CODE
) ? SHF_EXECINSTR
: 0)
502 | ((flags
& SEC_MERGE
) ? SHF_MERGE
: 0)
503 | ((flags
& SEC_STRINGS
) ? SHF_STRINGS
: 0)
504 | ((flags
& SEC_THREAD_LOCAL
) ? SHF_TLS
: 0);
506 obj_elf_change_section (name
, type
, attr
, 0, NULL
, false, false);
509 bfd_set_section_alignment (now_seg
, align
);
513 rx_section (int ignore
)
517 /* The as100 assembler supports a different syntax for the .section
518 pseudo-op. So check for it and handle it here if necessary. */
521 /* Peek past the section name to see if arguments follow. */
522 for (p
= input_line_pointer
; *p
; p
++)
523 if (*p
== ',' || *p
== '\n')
528 int len
= p
- input_line_pointer
;
530 while (ISSPACE (*++p
))
533 if (*p
!= '"' && *p
!= '#')
535 char *name
= xmemdup0 (input_line_pointer
, len
);
537 input_line_pointer
= p
;
538 parse_rx_section (name
);
543 obj_elf_section (ignore
);
547 rx_list (int ignore ATTRIBUTE_UNUSED
)
551 if (strncasecmp (input_line_pointer
, "OFF", 3))
553 else if (strncasecmp (input_line_pointer
, "ON", 2))
556 as_warn (_("expecting either ON or OFF after .list"));
559 /* Like the .rept pseudo op, but supports the
560 use of ..MACREP inside the repeated region. */
563 rx_rept (int ignore ATTRIBUTE_UNUSED
)
565 size_t count
= get_absolute_expression ();
567 do_repeat (count
, "MREPEAT", "ENDR", "..MACREP");
570 /* Like cons() accept that strings are allowed. */
577 if (* input_line_pointer
== '"')
584 rx_nop (int ignore ATTRIBUTE_UNUSED
)
586 ignore_rest_of_line ();
592 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
593 md_pseudo_table
[idx
].poc_name
);
594 ignore_rest_of_line ();
597 /* The target specific pseudo-ops which we support. */
598 const pseudo_typeS md_pseudo_table
[] =
600 /* These are unimplemented. They're listed first so that we can use
601 the poc_value as the index into this array, to get the name of
602 the pseudo. So, keep these (1) first, and (2) in order, with (3)
603 the poc_value's in sequence. */
604 { "btglb", rx_unimp
, 0 },
605 { "call", rx_unimp
, 1 },
606 { "einsf", rx_unimp
, 2 },
607 { "fb", rx_unimp
, 3 },
608 { "fbsym", rx_unimp
, 4 },
609 { "id", rx_unimp
, 5 },
610 { "initsct", rx_unimp
, 6 },
611 { "insf", rx_unimp
, 7 },
612 { "instr", rx_unimp
, 8 },
613 { "lbba", rx_unimp
, 9 },
614 { "len", rx_unimp
, 10 },
615 { "optj", rx_unimp
, 11 },
616 { "rvector", rx_unimp
, 12 },
617 { "sb", rx_unimp
, 13 },
618 { "sbbit", rx_unimp
, 14 },
619 { "sbsym", rx_unimp
, 15 },
620 { "sbsym16", rx_unimp
, 16 },
622 /* These are the do-nothing pseudos. */
623 { "stk", rx_nop
, 0 },
624 /* The manual documents ".stk" but the compiler emits ".stack". */
625 { "stack", rx_nop
, 0 },
627 /* These are Renesas as100 assembler pseudo-ops that we do support. */
628 { "addr", rx_cons
, 3 },
629 { "align", s_align_bytes
, 2 },
630 { "byte", rx_cons
, 1 },
631 { "fixed", float_cons
, 'f' },
632 { "form", listing_psize
, 0 },
633 { "glb", s_globl
, 0 },
634 { "include", rx_include
, 0 },
635 { "list", rx_list
, 0 },
636 { "lword", rx_cons
, 4 },
637 { "mrepeat", rx_rept
, 0 },
638 { "section", rx_section
, 0 },
640 /* FIXME: The following pseudo-ops place their values (and associated
641 label if present) in the data section, regardless of whatever
642 section we are currently in. At the moment this code does not
643 implement that part of the semantics. */
644 { "blka", s_space
, 3 },
645 { "blkb", s_space
, 1 },
646 { "blkd", s_space
, 8 },
647 { "blkf", s_space
, 4 },
648 { "blkl", s_space
, 4 },
649 { "blkw", s_space
, 2 },
651 /* Our "standard" pseudos. */
652 { "double", rx_float_cons
, 0 },
654 { "3byte", cons
, 3 },
658 { "fetchalign", rx_fetchalign
, 0 },
660 /* End of list marker. */
664 static asymbol
* gp_symbol
;
665 static asymbol
* rx_pid_symbol
;
667 static symbolS
* rx_pidreg_symbol
;
668 static symbolS
* rx_gpreg_symbol
;
673 /* Make the __gp and __pid_base symbols now rather
674 than after the symbol table is frozen. We only do this
675 when supporting small data limits because otherwise we
676 pollute the symbol table. */
678 /* The meta-registers %pidreg and %gpreg depend on what other
679 options are specified. The __rx_*_defined symbols exist so we
680 can .ifdef asm code based on what options were passed to gas,
681 without needing a preprocessor */
685 rx_pid_register
= 13 - rx_num_int_regs
;
686 rx_pid_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
687 rx_pidreg_symbol
= symbol_find_or_make ("__rx_pidreg_defined");
688 S_SET_VALUE (rx_pidreg_symbol
, rx_pid_register
);
689 S_SET_SEGMENT (rx_pidreg_symbol
, absolute_section
);
692 if (rx_use_small_data_limit
)
695 rx_gp_register
= rx_pid_register
- 1;
697 rx_gp_register
= 13 - rx_num_int_regs
;
698 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
699 rx_gpreg_symbol
= symbol_find_or_make ("__rx_gpreg_defined");
700 S_SET_VALUE (rx_gpreg_symbol
, rx_gp_register
);
701 S_SET_SEGMENT (rx_gpreg_symbol
, absolute_section
);
708 /* These negative numbers are found in rx_bytesT.n_base for non-opcode
710 #define RX_NBASE_FETCHALIGN -1
712 typedef struct rx_bytesT
715 /* If this is negative, it's a special-purpose frag as per the defines above. */
724 char type
; /* RXREL_*. */
739 fixS
*link_relax_fixP
;
740 unsigned long times_grown
;
741 unsigned long times_shrank
;
744 static rx_bytesT rx_bytes
;
745 /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
746 static rx_bytesT
*fetchalign_bytes
= NULL
;
749 rx_fetchalign (int ignore ATTRIBUTE_UNUSED
)
754 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
755 rx_bytes
.n_base
= RX_NBASE_FETCHALIGN
;
757 bytes
= frag_more (8);
758 frag_then
= frag_now
;
759 frag_variant (rs_machine_dependent
,
766 frag_then
->fr_opcode
= bytes
;
767 frag_then
->fr_subtype
= 0;
768 fetchalign_bytes
= frag_then
->tc_frag_data
;
772 rx_relax (int type
, int pos
)
774 rx_bytes
.relax
[rx_bytes
.n_relax
].type
= type
;
775 rx_bytes
.relax
[rx_bytes
.n_relax
].field_pos
= pos
;
776 rx_bytes
.relax
[rx_bytes
.n_relax
].val_ofs
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
781 rx_linkrelax_dsp (int pos
)
786 rx_bytes
.link_relax
|= RX_RELAXA_DSP4
;
789 rx_bytes
.link_relax
|= RX_RELAXA_DSP6
;
792 rx_bytes
.link_relax
|= RX_RELAXA_DSP14
;
798 rx_linkrelax_imm (int pos
)
803 rx_bytes
.link_relax
|= RX_RELAXA_IMM6
;
806 rx_bytes
.link_relax
|= RX_RELAXA_IMM12
;
812 rx_linkrelax_branch (void)
814 rx_bytes
.link_relax
|= RX_RELAXA_BRA
;
818 rx_fixup (expressionS exp
, int offsetbits
, int nbits
, int type
)
820 rx_bytes
.fixups
[rx_bytes
.n_fixups
].exp
= exp
;
821 rx_bytes
.fixups
[rx_bytes
.n_fixups
].offset
= offsetbits
;
822 rx_bytes
.fixups
[rx_bytes
.n_fixups
].nbits
= nbits
;
823 rx_bytes
.fixups
[rx_bytes
.n_fixups
].type
= type
;
824 rx_bytes
.fixups
[rx_bytes
.n_fixups
].reloc
= exp
.X_md
;
825 rx_bytes
.n_fixups
++;
828 #define rx_field_fixup(exp, offset, nbits, type) \
829 rx_fixup (exp, offset, nbits, type)
831 #define rx_op_fixup(exp, offset, nbits, type) \
832 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
837 rx_bytes
.base
[0] = b1
;
842 rx_base2 (int b1
, int b2
)
844 rx_bytes
.base
[0] = b1
;
845 rx_bytes
.base
[1] = b2
;
850 rx_base3 (int b1
, int b2
, int b3
)
852 rx_bytes
.base
[0] = b1
;
853 rx_bytes
.base
[1] = b2
;
854 rx_bytes
.base
[2] = b3
;
859 rx_base4 (int b1
, int b2
, int b3
, int b4
)
861 rx_bytes
.base
[0] = b1
;
862 rx_bytes
.base
[1] = b2
;
863 rx_bytes
.base
[2] = b3
;
864 rx_bytes
.base
[3] = b4
;
868 /* This gets complicated when the field spans bytes, because fields
869 are numbered from the MSB of the first byte as zero, and bits are
870 stored LSB towards the LSB of the byte. Thus, a simple four-bit
871 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
872 insertion of b'MXL at position 7 is like this:
874 - - - - - - - - - - - - - - - -
878 rx_field (int val
, int pos
, int sz
)
885 if (val
< 0 || val
>= (1 << sz
))
886 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val
, sz
);
891 if (val
< -(1 << (sz
- 1)) || val
>= (1 << (sz
- 1)))
892 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val
, sz
);
895 /* This code points at 'M' in the above example. */
899 while (bitp
+ sz
> 8)
904 svalm
= val
>> (sz
- ssz
);
905 svalm
= svalm
& ((1 << ssz
) - 1);
906 svalm
= svalm
<< (8 - bitp
- ssz
);
907 gas_assert (bytep
< rx_bytes
.n_base
);
908 rx_bytes
.base
[bytep
] |= svalm
;
914 valm
= val
& ((1 << sz
) - 1);
915 valm
= valm
<< (8 - bitp
- sz
);
916 gas_assert (bytep
< rx_bytes
.n_base
);
917 rx_bytes
.base
[bytep
] |= valm
;
920 /* Special case of the above, for 3-bit displacements of 2..9. */
923 rx_disp3 (expressionS exp
, int pos
)
925 rx_field_fixup (exp
, pos
, 3, RXREL_PCREL
);
928 /* Special case of the above, for split 5-bit displacements. Assumes
929 the displacement has been checked with rx_disp5op. */
930 /* ---- -432 1--- 0--- */
933 rx_field5s (expressionS exp
)
937 val
= exp
.X_add_number
;
938 rx_bytes
.base
[0] |= val
>> 2;
939 rx_bytes
.base
[1] |= (val
<< 6) & 0x80;
940 rx_bytes
.base
[1] |= (val
<< 3) & 0x08;
943 /* ---- ---- 4--- 3210 */
946 rx_field5s2 (expressionS exp
)
950 val
= exp
.X_add_number
;
951 rx_bytes
.base
[1] |= (val
<< 3) & 0x80;
952 rx_bytes
.base
[1] |= (val
) & 0x0f;
956 rx_bfield(expressionS s
, expressionS d
, expressionS w
)
958 int slsb
= s
.X_add_number
;
959 int dlsb
= d
.X_add_number
;
960 int width
= w
.X_add_number
;
962 (((dlsb
+ width
) & 0x1f) << 10 | (dlsb
<< 5) |
963 ((dlsb
- slsb
) & 0x1f));
964 if ((slsb
+ width
) > 32)
965 as_warn (_("Value %d and %d out of range"), slsb
, width
);
966 if ((dlsb
+ width
) > 32)
967 as_warn (_("Value %d and %d out of range"), dlsb
, width
);
968 rx_bytes
.ops
[0] = imm
& 0xff;
969 rx_bytes
.ops
[1] = (imm
>> 8);
973 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
975 #define F_PRECISION 2
978 rx_op (expressionS exp
, int nbytes
, int type
)
982 if ((exp
.X_op
== O_constant
|| exp
.X_op
== O_big
)
983 && type
!= RXREL_PCREL
)
985 if (exp
.X_op
== O_big
)
987 if (exp
.X_add_number
== -1)
990 char * ip
= rx_bytes
.ops
+ rx_bytes
.n_ops
;
992 gen_to_words (w
, F_PRECISION
, 8);
993 #if RX_OPCODE_BIG_ENDIAN
1004 rx_bytes
.n_ops
+= 4;
1008 v
= ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
1009 | (generic_bignum
[0] & LITTLENUM_MASK
);
1013 v
= exp
.X_add_number
;
1017 #if RX_OPCODE_BIG_ENDIAN
1018 OP ((v
>> (8 * (nbytes
- 1))) & 0xff);
1028 rx_op_fixup (exp
, rx_bytes
.n_ops
* 8, nbytes
* 8, type
);
1029 memset (rx_bytes
.ops
+ rx_bytes
.n_ops
, 0, nbytes
);
1030 rx_bytes
.n_ops
+= nbytes
;
1034 void rx_post(char byte
)
1036 rx_bytes
.post
[rx_bytes
.n_post
++] = byte
;
1045 #define APPEND(B, N_B) \
1048 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
1049 idx += rx_bytes.N_B; \
1053 rx_frag_init (fragS
* fragP
)
1055 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
|| rx_bytes
.n_base
< 0)
1057 fragP
->tc_frag_data
= XNEW (rx_bytesT
);
1058 memcpy (fragP
->tc_frag_data
, & rx_bytes
, sizeof (rx_bytesT
));
1061 fragP
->tc_frag_data
= 0;
1064 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
1065 <symbol_name> .equ <expression> */
1068 rx_equ (char * name
, char * expression
)
1070 char saved_name_end_char
;
1074 while (ISSPACE (* name
))
1077 for (name_end
= name
+ 1; *name_end
; name_end
++)
1078 if (! ISALNUM (* name_end
))
1081 saved_name_end_char
= * name_end
;
1084 saved_ilp
= input_line_pointer
;
1085 input_line_pointer
= expression
;
1089 input_line_pointer
= saved_ilp
;
1090 * name_end
= saved_name_end_char
;
1093 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
1094 rather than at the start of a line. (eg .EQU or .DEFINE). If one
1095 is found, process it and return TRUE otherwise return FALSE. */
1098 scan_for_infix_rx_pseudo_ops (char * str
)
1102 char * dot
= strchr (str
, '.');
1104 if (dot
== NULL
|| dot
== str
)
1107 /* A real pseudo-op must be preceded by whitespace. */
1108 if (dot
[-1] != ' ' && dot
[-1] != '\t')
1111 pseudo_op
= dot
+ 1;
1113 if (!ISALNUM (* pseudo_op
))
1116 for (p
= pseudo_op
+ 1; ISALNUM (* p
); p
++)
1119 if (strncasecmp ("EQU", pseudo_op
, p
- pseudo_op
) == 0)
1121 else if (strncasecmp ("DEFINE", pseudo_op
, p
- pseudo_op
) == 0)
1122 as_warn (_("The .DEFINE pseudo-op is not implemented"));
1123 else if (strncasecmp ("MACRO", pseudo_op
, p
- pseudo_op
) == 0)
1124 as_warn (_("The .MACRO pseudo-op is not implemented"));
1125 else if (strncasecmp ("BTEQU", pseudo_op
, p
- pseudo_op
) == 0)
1126 as_warn (_("The .BTEQU pseudo-op is not implemented."));
1134 md_assemble (char * str
)
1139 fragS
* frag_then
= frag_now
;
1142 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
1144 rx_lex_init (str
, str
+ strlen (str
));
1145 if (scan_for_infix_rx_pseudo_ops (str
))
1149 /* This simplifies the relaxation code. */
1150 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
1152 /* We do it this way because we want the frag to have the
1153 rx_bytes in it, which we initialize above. */
1154 bytes
= frag_more (12);
1155 frag_then
= frag_now
;
1156 frag_variant (rs_machine_dependent
,
1163 frag_then
->fr_opcode
= bytes
;
1164 frag_then
->fr_fix
+= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1165 frag_then
->fr_subtype
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1169 bytes
= frag_more (rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
);
1170 frag_then
= frag_now
;
1171 if (fetchalign_bytes
)
1172 fetchalign_bytes
->n_ops
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1175 fetchalign_bytes
= NULL
;
1177 APPEND (base
, n_base
);
1178 APPEND (ops
, n_ops
);
1179 APPEND (post
, n_post
);
1181 if (rx_bytes
.link_relax
&& rx_bytes
.n_fixups
)
1185 f
= fix_new (frag_then
,
1186 (char *) bytes
- frag_then
->fr_literal
,
1189 rx_bytes
.link_relax
| rx_bytes
.n_fixups
,
1191 BFD_RELOC_RX_RELAX
);
1192 frag_then
->tc_frag_data
->link_relax_fixP
= f
;
1195 for (i
= 0; i
< rx_bytes
.n_fixups
; i
++)
1197 /* index: [nbytes][type] */
1198 static int reloc_map
[5][4] =
1200 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL
},
1201 { BFD_RELOC_8
, BFD_RELOC_RX_8U
, BFD_RELOC_RX_NEG8
, BFD_RELOC_8_PCREL
},
1202 { BFD_RELOC_RX_16_OP
, BFD_RELOC_RX_16U
, BFD_RELOC_RX_NEG16
, BFD_RELOC_16_PCREL
},
1203 { BFD_RELOC_RX_24_OP
, BFD_RELOC_RX_24U
, BFD_RELOC_RX_NEG24
, BFD_RELOC_24_PCREL
},
1204 { BFD_RELOC_RX_32_OP
, BFD_RELOC_32
, BFD_RELOC_RX_NEG32
, BFD_RELOC_32_PCREL
},
1208 idx
= rx_bytes
.fixups
[i
].offset
/ 8;
1209 rel
= reloc_map
[rx_bytes
.fixups
[i
].nbits
/ 8][(int) rx_bytes
.fixups
[i
].type
];
1211 if (rx_bytes
.fixups
[i
].reloc
)
1212 rel
= rx_bytes
.fixups
[i
].reloc
;
1214 if (frag_then
->tc_frag_data
)
1215 exp
= & frag_then
->tc_frag_data
->fixups
[i
].exp
;
1217 exp
= & rx_bytes
.fixups
[i
].exp
;
1219 f
= fix_new_exp (frag_then
,
1220 (char *) bytes
+ idx
- frag_then
->fr_literal
,
1221 rx_bytes
.fixups
[i
].nbits
/ 8,
1223 rx_bytes
.fixups
[i
].type
== RXREL_PCREL
? 1 : 0,
1225 if (frag_then
->tc_frag_data
)
1226 frag_then
->tc_frag_data
->fixups
[i
].fixP
= f
;
1228 dwarf2_emit_insn (idx
);
1236 /* Write a value out to the object file, using the appropriate endianness. */
1239 md_number_to_chars (char * buf
, valueT val
, int n
)
1241 if (target_big_endian
)
1242 number_to_chars_bigendian (buf
, val
, n
);
1244 number_to_chars_littleendian (buf
, val
, n
);
1254 { "gp", BFD_RELOC_GPREL16
},
1259 md_operand (expressionS
* exp ATTRIBUTE_UNUSED
)
1264 for (i
= 0; reloc_functions
[i
].fname
; i
++)
1266 int flen
= strlen (reloc_functions
[i
].fname
);
1268 if (input_line_pointer
[0] == '%'
1269 && strncasecmp (input_line_pointer
+ 1, reloc_functions
[i
].fname
, flen
) == 0
1270 && input_line_pointer
[flen
+ 1] == '(')
1272 reloc
= reloc_functions
[i
].reloc
;
1273 input_line_pointer
+= flen
+ 2;
1281 if (* input_line_pointer
== ')')
1282 input_line_pointer
++;
1288 md_section_align (segT segment
, valueT size
)
1290 int align
= bfd_section_alignment (segment
);
1291 return ((size
+ (1 << align
) - 1) & -(1 << align
));
1295 static unsigned char nop_1
[] = { 0x03};
1296 /* MOV.L R0,R0 - 1 cycle */
1297 static unsigned char nop_2
[] = { 0xef, 0x00};
1298 /* MAX R0,R0 - 1 cycle */
1299 static unsigned char nop_3
[] = { 0xfc, 0x13, 0x00 };
1300 /* MUL #1,R0 - 1 cycle */
1301 static unsigned char nop_4
[] = { 0x76, 0x10, 0x01, 0x00 };
1302 /* MUL #1,R0 - 1 cycle */
1303 static unsigned char nop_5
[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
1304 /* MUL #1,R0 - 1 cycle */
1305 static unsigned char nop_6
[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
1306 /* MAX 0x80000000,R0 - 1 cycle */
1307 static unsigned char nop_7
[] = { 0xFD, 0x70, 0x40, 0x00, 0x00, 0x00, 0x80 };
1309 static unsigned char *nops
[] = { NULL
, nop_1
, nop_2
, nop_3
, nop_4
, nop_5
, nop_6
, nop_7
};
1310 #define BIGGEST_NOP 7
1312 /* When relaxing, we need to output a reloc for any .align directive
1313 so that we can retain this alignment as we adjust opcode sizes. */
1315 rx_handle_align (fragS
* frag
)
1317 /* If handling an alignment frag, use an optimal NOP pattern.
1318 Only do this if a fill value has not already been provided.
1319 FIXME: This test fails if the provided fill value is zero. */
1320 if ((frag
->fr_type
== rs_align
1321 || frag
->fr_type
== rs_align_code
)
1322 && subseg_text_p (now_seg
))
1324 int count
= (frag
->fr_next
->fr_address
1327 unsigned char *base
= (unsigned char *)frag
->fr_literal
+ frag
->fr_fix
;
1331 if (count
> BIGGEST_NOP
)
1339 memcpy (base
, nops
[count
], count
);
1340 frag
->fr_var
= count
;
1346 && (frag
->fr_type
== rs_align
1347 || frag
->fr_type
== rs_align_code
)
1348 && frag
->fr_address
+ frag
->fr_fix
> 0
1349 && frag
->fr_offset
> 0
1350 && now_seg
!= bss_section
)
1352 fix_new (frag
, frag
->fr_fix
, 0,
1353 &abs_symbol
, RX_RELAXA_ALIGN
+ frag
->fr_offset
,
1354 0, BFD_RELOC_RX_RELAX
);
1355 /* For the purposes of relaxation, this relocation is attached
1356 to the byte *after* the alignment - i.e. the byte that must
1358 fix_new (frag
->fr_next
, 0, 0,
1359 &abs_symbol
, RX_RELAXA_ELIGN
+ frag
->fr_offset
,
1360 0, BFD_RELOC_RX_RELAX
);
1365 md_atof (int type
, char * litP
, int * sizeP
)
1367 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1371 md_undefined_symbol (char * name ATTRIBUTE_UNUSED
)
1376 /*----------------------------------------------------------------------*/
1377 /* To recap: we estimate everything based on md_estimate_size, then
1378 adjust based on rx_relax_frag. When it all settles, we call
1379 md_convert frag to update the bytes. The relaxation types and
1380 relocations are in fragP->tc_frag_data, which is a copy of that
1383 Our scheme is as follows: fr_fix has the size of the smallest
1384 opcode (like BRA.S). We store the number of total bytes we need in
1385 fr_subtype. When we're done relaxing, we use fr_subtype and the
1386 existing opcode bytes to figure out what actual opcode we need to
1387 put in there. If the fixup isn't resolvable now, we use the
1390 #define TRACE_RELAX 0
1391 #define tprintf if (TRACE_RELAX) printf
1403 /* We're looking for these types of relaxations:
1406 BRA.B 00101110 dspppppp
1407 BRA.W 00111000 dspppppp pppppppp
1408 BRA.A 00000100 dspppppp pppppppp pppppppp
1411 BEQ.B 00100000 dspppppp
1412 BEQ.W 00111010 dspppppp pppppppp
1415 BNE.B 00100001 dspppppp
1416 BNE.W 00111011 dspppppp pppppppp
1418 BSR.W 00111001 dspppppp pppppppp
1419 BSR.A 00000101 dspppppp pppppppp pppppppp
1421 Bcc.B 0010cond dspppppp
1423 Additionally, we can synthesize longer conditional branches using
1424 pairs of opcodes, one with an inverted conditional (flip LSB):
1426 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1427 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1428 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1429 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1431 /* Given the opcode bytes at OP, figure out which opcode it is and
1432 return the type of opcode. We use this to re-encode the opcode as
1433 a different size later. */
1436 rx_opcode_type (char * op
)
1438 unsigned char b
= (unsigned char) op
[0];
1442 case 0x08: return OT_bra
;
1443 case 0x10: return OT_beq
;
1444 case 0x18: return OT_bne
;
1449 case 0x2e: return OT_bra
;
1450 case 0x38: return OT_bra
;
1451 case 0x04: return OT_bra
;
1453 case 0x20: return OT_beq
;
1454 case 0x3a: return OT_beq
;
1456 case 0x21: return OT_bne
;
1457 case 0x3b: return OT_bne
;
1459 case 0x39: return OT_bsr
;
1460 case 0x05: return OT_bsr
;
1463 if ((b
& 0xf0) == 0x20)
1469 /* Returns zero if *addrP has the target address. Else returns nonzero
1470 if we cannot compute the target address yet. */
1473 rx_frag_fix_value (fragS
* fragP
,
1478 addressT
* sym_addr
)
1481 rx_bytesT
* b
= fragP
->tc_frag_data
;
1482 expressionS
* exp
= & b
->fixups
[which
].exp
;
1484 if (need_diff
&& exp
->X_op
!= O_subtract
)
1487 if (exp
->X_add_symbol
)
1489 if (S_FORCE_RELOC (exp
->X_add_symbol
, 1))
1491 if (S_GET_SEGMENT (exp
->X_add_symbol
) != segment
)
1493 addr
+= S_GET_VALUE (exp
->X_add_symbol
);
1496 if (exp
->X_op_symbol
)
1498 if (exp
->X_op
!= O_subtract
)
1500 if (S_FORCE_RELOC (exp
->X_op_symbol
, 1))
1502 if (S_GET_SEGMENT (exp
->X_op_symbol
) != segment
)
1504 addr
-= S_GET_VALUE (exp
->X_op_symbol
);
1508 addr
+= exp
->X_add_number
;
1513 /* Estimate how big the opcode is after this relax pass. The return
1514 value is the difference between fr_fix and the actual size. We
1515 compute the total size in rx_relax_frag and store it in fr_subtype,
1516 so we only need to subtract fx_fix and return it. */
1519 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
, segT segment ATTRIBUTE_UNUSED
)
1524 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1525 (unsigned long) (fragP
->fr_address
1526 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1527 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1528 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1530 /* This is the size of the opcode that's accounted for in fr_fix. */
1531 opfixsize
= fragP
->fr_fix
- (fragP
->fr_opcode
- fragP
->fr_literal
);
1532 /* This is the size of the opcode that isn't. */
1533 delta
= (fragP
->fr_subtype
- opfixsize
);
1535 tprintf (" -> opfixsize %d delta %d\n", opfixsize
, delta
);
1539 /* Given a frag FRAGP, return the "next" frag that contains an
1540 opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
1543 rx_next_opcode (fragS
*fragP
)
1546 fragP
= fragP
->fr_next
;
1547 } while (fragP
&& fragP
->fr_type
!= rs_machine_dependent
);
1551 /* Given the new addresses for this relax pass, figure out how big
1552 each opcode must be. We store the total number of bytes needed in
1553 fr_subtype. The return value is the difference between the size
1554 after the last pass and the size after this pass, so we use the old
1555 fr_subtype to calculate the difference. */
1558 rx_relax_frag (segT segment ATTRIBUTE_UNUSED
, fragS
* fragP
, long stretch
, unsigned long max_iterations
)
1560 addressT addr0
, sym_addr
;
1563 int oldsize
= fragP
->fr_subtype
;
1564 int newsize
= oldsize
;
1566 /* Index of relaxation we care about. */
1569 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",
1570 (unsigned long) (fragP
->fr_address
1571 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1572 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1573 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
, stretch
);
1575 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1577 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1579 unsigned int next_size
;
1580 if (fragP
->fr_next
== NULL
)
1583 next_size
= fragP
->tc_frag_data
->n_ops
;
1586 fragS
*n
= rx_next_opcode (fragP
);
1587 next_size
= n
->fr_subtype
;
1590 fragP
->fr_subtype
= (8-(mypc
& 7)) & 7;
1591 tprintf("subtype %u\n", fragP
->fr_subtype
);
1592 if (fragP
->fr_subtype
>= next_size
)
1593 fragP
->fr_subtype
= 0;
1594 tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
1595 (unsigned long) (mypc
& 7),
1596 next_size
, fragP
->fr_subtype
, oldsize
, fragP
->fr_subtype
-oldsize
);
1598 newsize
= fragP
->fr_subtype
;
1600 return newsize
- oldsize
;
1603 optype
= rx_opcode_type (fragP
->fr_opcode
);
1605 /* In the one case where we have both a disp and imm relaxation, we want
1606 the imm relaxation here. */
1608 if (fragP
->tc_frag_data
->n_relax
> 1
1609 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1612 /* Try to get the target address. */
1613 if (rx_frag_fix_value (fragP
, segment
, ri
, & addr0
,
1614 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
,
1617 /* If we don't, we must use the maximum size for the linker.
1618 Note that we don't use synthetically expanded conditionals
1620 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1622 case RX_RELAX_BRANCH
:
1643 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
+ 4;
1646 fragP
->fr_subtype
= newsize
;
1647 tprintf (" -> new %d old %d delta %d (external)\n", newsize
, oldsize
, newsize
-oldsize
);
1648 return newsize
- oldsize
;
1651 if (sym_addr
> mypc
)
1654 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1656 case RX_RELAX_BRANCH
:
1657 tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
1658 (unsigned long) addr0
, (unsigned long) mypc
,
1659 (long) (addr0
- mypc
));
1660 disp
= (int) addr0
- (int) mypc
;
1665 if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1668 else if (disp
>= -32768 && (disp
- (oldsize
-5)) <= 32767)
1678 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1681 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1684 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1694 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1697 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1700 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1711 tprintf (" - newsize %d\n", newsize
);
1715 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
1716 (unsigned long) addr0
, (unsigned long) mypc
,
1717 fragP
->tc_frag_data
->relax
[ri
].field_pos
,
1718 fragP
->tc_frag_data
->relax
[ri
].val_ofs
);
1720 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1722 if ((long) addr0
>= -128 && (long) addr0
<= 127)
1724 else if ((long) addr0
>= -32768 && (long) addr0
<= 32767)
1726 else if ((long) addr0
>= -8388608 && (long) addr0
<= 8388607)
1736 if (fragP
->tc_frag_data
->relax
[ri
].type
== RX_RELAX_BRANCH
)
1752 /* This prevents infinite loops in align-heavy sources. */
1753 if (newsize
< oldsize
)
1755 /* Make sure that our iteration limit is no bigger than the one being
1756 used inside write.c:relax_segment(). Otherwise we can end up
1757 iterating for too long, and triggering a fatal error there. See
1758 PR 24464 for more details. */
1759 unsigned long limit
= max_iterations
> 10 ? 10 : max_iterations
;
1761 if (fragP
->tc_frag_data
->times_shrank
> limit
1762 && fragP
->tc_frag_data
->times_grown
> limit
)
1765 if (fragP
->tc_frag_data
->times_shrank
< 20)
1766 fragP
->tc_frag_data
->times_shrank
++;
1768 else if (newsize
> oldsize
)
1770 if (fragP
->tc_frag_data
->times_grown
< 20)
1771 fragP
->tc_frag_data
->times_grown
++;
1774 fragP
->fr_subtype
= newsize
;
1775 tprintf (" -> new %d old %d delta %d\n", newsize
, oldsize
, newsize
-oldsize
);
1776 return newsize
- oldsize
;
1779 /* This lets us test for the opcode type and the desired size in a
1780 switch statement. */
1781 #define OPCODE(type,size) ((type) * 16 + (size))
1783 /* Given the opcode stored in fr_opcode and the number of bytes we
1784 think we need, encode a new opcode. We stored a pointer to the
1785 fixup for this opcode in the tc_frag_data structure. If we can do
1786 the fixup here, we change the relocation type to "none" (we test
1787 for that in tc_gen_reloc) else we change it to the right type for
1788 the new (biggest) opcode. */
1791 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1792 segT segment ATTRIBUTE_UNUSED
,
1793 fragS
* fragP ATTRIBUTE_UNUSED
)
1795 rx_bytesT
* rxb
= fragP
->tc_frag_data
;
1796 addressT addr0
, mypc
;
1799 bfd_reloc_code_real_type reloc_type
;
1800 char * op
= fragP
->fr_opcode
;
1803 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1804 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1806 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1807 (unsigned long) (fragP
->fr_address
1808 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1809 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1810 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
,
1817 printf ("lit 0x%p opc 0x%p", fragP
->fr_literal
, fragP
->fr_opcode
);
1818 for (i
= 0; i
< 10; i
++)
1819 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1824 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1826 int count
= fragP
->fr_subtype
;
1829 else if (count
> BIGGEST_NOP
)
1836 memcpy (op
, nops
[count
], count
);
1840 /* In the one case where we have both a disp and imm relaxation, we want
1841 the imm relaxation here. */
1843 if (fragP
->tc_frag_data
->n_relax
> 1
1844 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1847 /* We used a new frag for this opcode, so the opcode address should
1848 be the frag address. */
1849 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1851 /* Try to get the target address. If we fail here, we just use the
1853 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1854 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1856 /* We don't know the target address. */
1863 /* We know the target address, and it's in addr0. */
1864 disp
= (int) addr0
- (int) mypc
;
1870 reloc_type
= BFD_RELOC_NONE
;
1873 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1874 rx_opcode_type (fragP
->fr_opcode
), disp
,
1875 (unsigned long) addr0
, (unsigned long) mypc
);
1876 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1878 case RX_RELAX_BRANCH
:
1879 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1881 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1882 op
[0] = 0x08 + (disp
& 7);
1884 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1887 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1890 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1892 #if RX_OPCODE_BIG_ENDIAN
1893 op
[1] = (disp
>> 8) & 0xff;
1896 op
[2] = (disp
>> 8) & 0xff;
1900 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1902 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1904 #if RX_OPCODE_BIG_ENDIAN
1905 op
[1] = (disp
>> 16) & 0xff;
1906 op
[2] = (disp
>> 8) & 0xff;
1909 op
[3] = (disp
>> 16) & 0xff;
1910 op
[2] = (disp
>> 8) & 0xff;
1913 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1917 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1918 op
[0] = 0x10 + (disp
& 7);
1920 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1924 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1926 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1928 #if RX_OPCODE_BIG_ENDIAN
1929 op
[1] = (disp
>> 8) & 0xff;
1932 op
[2] = (disp
>> 8) & 0xff;
1935 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1938 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1939 op
[0] = 0x1d; /* bne.s .+5. */
1940 op
[1] = 0x04; /* bra.a dsp:24. */
1942 #if RX_OPCODE_BIG_ENDIAN
1943 op
[2] = (disp
>> 16) & 0xff;
1944 op
[3] = (disp
>> 8) & 0xff;
1947 op
[4] = (disp
>> 16) & 0xff;
1948 op
[3] = (disp
>> 8) & 0xff;
1951 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1955 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1956 op
[0] = 0x18 + (disp
& 7);
1958 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1962 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1964 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1966 #if RX_OPCODE_BIG_ENDIAN
1967 op
[1] = (disp
>> 8) & 0xff;
1970 op
[2] = (disp
>> 8) & 0xff;
1973 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1976 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1977 op
[0] = 0x15; /* beq.s .+5. */
1978 op
[1] = 0x04; /* bra.a dsp:24. */
1980 #if RX_OPCODE_BIG_ENDIAN
1981 op
[2] = (disp
>> 16) & 0xff;
1982 op
[3] = (disp
>> 8) & 0xff;
1985 op
[4] = (disp
>> 16) & 0xff;
1986 op
[3] = (disp
>> 8) & 0xff;
1989 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1993 case OPCODE (OT_bsr
, 3): /* BSR.W - 16 bit. */
1995 #if RX_OPCODE_BIG_ENDIAN
1996 op
[1] = (disp
>> 8) & 0xff;
1999 op
[2] = (disp
>> 8) & 0xff;
2002 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2005 case OPCODE (OT_bsr
, 4): /* BSR.A - 24 bit. */
2007 #if RX_OPCODE_BIG_ENDIAN
2008 op
[1] = (disp
>> 16) & 0xff;
2009 op
[2] = (disp
>> 8) & 0xff;
2012 op
[3] = (disp
>> 16) & 0xff;
2013 op
[2] = (disp
>> 8) & 0xff;
2016 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2020 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
2022 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
2024 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
2025 op
[0] ^= 1; /* Invert condition. */
2026 op
[1] = 5; /* Displacement. */
2029 #if RX_OPCODE_BIG_ENDIAN
2030 op
[3] = (disp
>> 8) & 0xff;
2033 op
[4] = (disp
>> 8) & 0xff;
2036 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2039 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
2040 op
[0] ^= 1; /* Invert condition. */
2041 op
[1] = 6; /* Displacement. */
2044 #if RX_OPCODE_BIG_ENDIAN
2045 op
[3] = (disp
>> 16) & 0xff;
2046 op
[4] = (disp
>> 8) & 0xff;
2049 op
[5] = (disp
>> 16) & 0xff;
2050 op
[4] = (disp
>> 8) & 0xff;
2053 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2058 /* These are opcodes we'll relax in th linker, later. */
2060 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
2067 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2069 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2076 reloc_type
= BFD_RELOC_8
;
2080 #if RX_OPCODE_BIG_ENDIAN
2082 imm
[0] = addr0
>> 8;
2085 imm
[1] = addr0
>> 8;
2087 reloc_type
= BFD_RELOC_RX_16_OP
;
2091 #if RX_OPCODE_BIG_ENDIAN
2093 imm
[1] = addr0
>> 8;
2094 imm
[0] = addr0
>> 16;
2097 imm
[1] = addr0
>> 8;
2098 imm
[2] = addr0
>> 16;
2100 reloc_type
= BFD_RELOC_RX_24_OP
;
2104 #if RX_OPCODE_BIG_ENDIAN
2106 imm
[2] = addr0
>> 8;
2107 imm
[1] = addr0
>> 16;
2108 imm
[0] = addr0
>> 24;
2111 imm
[1] = addr0
>> 8;
2112 imm
[2] = addr0
>> 16;
2113 imm
[3] = addr0
>> 24;
2115 reloc_type
= BFD_RELOC_RX_32_OP
;
2118 as_bad (_("invalid immediate size"));
2122 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
2137 as_bad (_("invalid immediate field position"));
2145 reloc_type
= fix
->fx_r_type
;
2154 fix
->fx_r_type
= reloc_type
;
2155 fix
->fx_where
+= reloc_adjust
;
2158 case BFD_RELOC_NONE
:
2164 case BFD_RELOC_16_PCREL
:
2165 case BFD_RELOC_RX_16_OP
:
2168 case BFD_RELOC_24_PCREL
:
2169 case BFD_RELOC_RX_24_OP
:
2172 case BFD_RELOC_RX_32_OP
:
2180 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
2181 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP
->fr_fix
,
2182 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
2185 if (fragP
->fr_next
!= NULL
2186 && fragP
->fr_next
->fr_address
- fragP
->fr_address
!= fragP
->fr_fix
)
2187 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
2188 (long) fragP
->fr_fix
,
2189 (long) fragP
->fr_address
, (long) fragP
->fr_next
->fr_address
);
2195 rx_validate_fix_sub (struct fix
* f
)
2197 /* We permit the subtraction of two symbols in a few cases. */
2198 /* mov #sym1-sym2, R3 */
2199 if (f
->fx_r_type
== BFD_RELOC_RX_32_OP
)
2201 /* .long sym1-sym2 */
2202 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
2204 && (f
->fx_size
== 4 || f
->fx_size
== 2 || f
->fx_size
== 1))
2210 md_pcrel_from_section (fixS
* fixP
, segT sec
)
2214 if (fixP
->fx_addsy
!= NULL
2215 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2216 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
2217 /* The symbol is undefined (or is defined but not in this section).
2218 Let the linker figure it out. */
2221 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2222 switch (fixP
->fx_r_type
)
2224 case BFD_RELOC_RX_DIR3U_PCREL
:
2232 rx_cons_fix_new (fragS
* frag
,
2236 bfd_reloc_code_real_type type
)
2244 type
= BFD_RELOC_16
;
2247 type
= BFD_RELOC_24
;
2250 type
= BFD_RELOC_32
;
2253 as_bad (_("unsupported constant size %d\n"), size
);
2257 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
2259 if (size
!= 4 && size
!= 2 && size
!= 1)
2260 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2262 type
= BFD_RELOC_RX_DIFF
;
2265 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
2269 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
2270 valueT
* t ATTRIBUTE_UNUSED
,
2271 segT s ATTRIBUTE_UNUSED
)
2273 /* Instruction bytes are always little endian. */
2277 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
2279 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
2282 #define OP2(x) op[target_big_endian ? 1-x : x]
2283 #define OP3(x) op[target_big_endian ? 2-x : x]
2284 #define OP4(x) op[target_big_endian ? 3-x : x]
2286 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
2287 val
= (unsigned long) * t
;
2289 /* Opcode words are always the same endian. Data words are either
2290 big or little endian. */
2292 switch (f
->fx_r_type
)
2294 case BFD_RELOC_NONE
:
2297 case BFD_RELOC_RX_RELAX
:
2301 case BFD_RELOC_RX_DIR3U_PCREL
:
2302 if (val
< 3 || val
> 10)
2303 as_bad_where (f
->fx_file
, f
->fx_line
,
2304 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2306 op
[0] |= val
& 0x07;
2310 case BFD_RELOC_8_PCREL
:
2311 case BFD_RELOC_RX_8U
:
2316 OP2(1) = val
& 0xff;
2317 OP2(0) = (val
>> 8) & 0xff;
2320 case BFD_RELOC_16_PCREL
:
2321 case BFD_RELOC_RX_16_OP
:
2322 case BFD_RELOC_RX_16U
:
2323 #if RX_OPCODE_BIG_ENDIAN
2325 op
[0] = (val
>> 8) & 0xff;
2328 op
[1] = (val
>> 8) & 0xff;
2333 OP3(0) = val
& 0xff;
2334 OP3(1) = (val
>> 8) & 0xff;
2335 OP3(2) = (val
>> 16) & 0xff;
2338 case BFD_RELOC_24_PCREL
:
2339 case BFD_RELOC_RX_24_OP
:
2340 case BFD_RELOC_RX_24U
:
2341 #if RX_OPCODE_BIG_ENDIAN
2343 op
[1] = (val
>> 8) & 0xff;
2344 op
[0] = (val
>> 16) & 0xff;
2347 op
[1] = (val
>> 8) & 0xff;
2348 op
[2] = (val
>> 16) & 0xff;
2352 case BFD_RELOC_RX_DIFF
:
2359 OP2(0) = val
& 0xff;
2360 OP2(1) = (val
>> 8) & 0xff;
2363 OP4(0) = val
& 0xff;
2364 OP4(1) = (val
>> 8) & 0xff;
2365 OP4(2) = (val
>> 16) & 0xff;
2366 OP4(3) = (val
>> 24) & 0xff;
2372 OP4(0) = val
& 0xff;
2373 OP4(1) = (val
>> 8) & 0xff;
2374 OP4(2) = (val
>> 16) & 0xff;
2375 OP4(3) = (val
>> 24) & 0xff;
2378 case BFD_RELOC_RX_32_OP
:
2379 #if RX_OPCODE_BIG_ENDIAN
2381 op
[2] = (val
>> 8) & 0xff;
2382 op
[1] = (val
>> 16) & 0xff;
2383 op
[0] = (val
>> 24) & 0xff;
2386 op
[1] = (val
>> 8) & 0xff;
2387 op
[2] = (val
>> 16) & 0xff;
2388 op
[3] = (val
>> 24) & 0xff;
2392 case BFD_RELOC_RX_NEG8
:
2396 case BFD_RELOC_RX_NEG16
:
2398 #if RX_OPCODE_BIG_ENDIAN
2400 op
[0] = (val
>> 8) & 0xff;
2403 op
[1] = (val
>> 8) & 0xff;
2407 case BFD_RELOC_RX_NEG24
:
2409 #if RX_OPCODE_BIG_ENDIAN
2411 op
[1] = (val
>> 8) & 0xff;
2412 op
[0] = (val
>> 16) & 0xff;
2415 op
[1] = (val
>> 8) & 0xff;
2416 op
[2] = (val
>> 16) & 0xff;
2420 case BFD_RELOC_RX_NEG32
:
2422 #if RX_OPCODE_BIG_ENDIAN
2424 op
[2] = (val
>> 8) & 0xff;
2425 op
[1] = (val
>> 16) & 0xff;
2426 op
[0] = (val
>> 24) & 0xff;
2429 op
[1] = (val
>> 8) & 0xff;
2430 op
[2] = (val
>> 16) & 0xff;
2431 op
[3] = (val
>> 24) & 0xff;
2435 case BFD_RELOC_RX_GPRELL
:
2438 case BFD_RELOC_RX_GPRELW
:
2441 case BFD_RELOC_RX_GPRELB
:
2442 #if RX_OPCODE_BIG_ENDIAN
2444 op
[0] = (val
>> 8) & 0xff;
2447 op
[1] = (val
>> 8) & 0xff;
2452 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2453 bfd_get_reloc_code_name (f
->fx_r_type
));
2457 if (f
->fx_addsy
== NULL
)
2462 tc_gen_reloc (asection
* sec ATTRIBUTE_UNUSED
, fixS
* fixp
)
2464 static arelent
* reloc
[5];
2465 bool is_opcode
= false;
2467 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2474 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2476 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2477 fixp
->fx_subsy
= NULL
;
2480 reloc
[0] = XNEW (arelent
);
2481 reloc
[0]->sym_ptr_ptr
= XNEW (asymbol
*);
2482 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2483 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2484 reloc
[0]->addend
= fixp
->fx_offset
;
2486 if (fixp
->fx_r_type
== BFD_RELOC_RX_32_OP
2489 fixp
->fx_r_type
= BFD_RELOC_RX_DIFF
;
2493 is_opcode
= sec
->flags
& SEC_CODE
;
2495 /* Certain BFD relocations cannot be translated directly into
2496 a single (non-Red Hat) RX relocation, but instead need
2497 multiple RX relocations - handle them here. */
2498 switch (fixp
->fx_r_type
)
2500 case BFD_RELOC_RX_DIFF
:
2501 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2503 reloc
[1] = XNEW (arelent
);
2504 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2505 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2506 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2507 reloc
[1]->addend
= 0;
2508 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2510 reloc
[2] = XNEW (arelent
);
2511 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2512 reloc
[2]->addend
= 0;
2513 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2514 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2516 reloc
[3] = XNEW (arelent
);
2517 switch (fixp
->fx_size
)
2520 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2523 if (!is_opcode
&& target_big_endian
)
2524 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16_REV
);
2526 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2528 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2531 if (!is_opcode
&& target_big_endian
)
2532 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32_REV
);
2534 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2537 reloc
[3]->addend
= 0;
2538 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2539 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2544 case BFD_RELOC_RX_GPRELL
:
2545 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2547 reloc
[1] = XNEW (arelent
);
2548 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2549 if (gp_symbol
== NULL
)
2551 if (symbol_table_frozen
)
2555 gp
= symbol_find ("__gp");
2557 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2559 gp_symbol
= symbol_get_bfdsym (gp
);
2562 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2564 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2565 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2566 reloc
[1]->addend
= 0;
2567 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2569 reloc
[2] = XNEW (arelent
);
2570 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2571 reloc
[2]->addend
= 0;
2572 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2573 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2575 reloc
[3] = XNEW (arelent
);
2576 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2577 reloc
[3]->addend
= 0;
2578 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2579 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2584 case BFD_RELOC_RX_GPRELW
:
2585 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2587 reloc
[1] = XNEW (arelent
);
2588 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2589 if (gp_symbol
== NULL
)
2591 if (symbol_table_frozen
)
2595 gp
= symbol_find ("__gp");
2597 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2599 gp_symbol
= symbol_get_bfdsym (gp
);
2602 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2604 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2605 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2606 reloc
[1]->addend
= 0;
2607 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2609 reloc
[2] = XNEW (arelent
);
2610 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2611 reloc
[2]->addend
= 0;
2612 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2613 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2615 reloc
[3] = XNEW (arelent
);
2616 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2617 reloc
[3]->addend
= 0;
2618 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2619 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2624 case BFD_RELOC_RX_GPRELB
:
2625 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2627 reloc
[1] = XNEW (arelent
);
2628 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2629 if (gp_symbol
== NULL
)
2631 if (symbol_table_frozen
)
2635 gp
= symbol_find ("__gp");
2637 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2639 gp_symbol
= symbol_get_bfdsym (gp
);
2642 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2644 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2645 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2646 reloc
[1]->addend
= 0;
2647 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2649 reloc
[2] = XNEW (arelent
);
2650 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2651 reloc
[2]->addend
= 0;
2652 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2653 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2655 reloc
[3] = XNEW (arelent
);
2656 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2657 reloc
[3]->addend
= 0;
2658 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2659 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2664 case BFD_RELOC_RX_NEG32
:
2665 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2667 reloc
[1] = XNEW (arelent
);
2668 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_NEG
);
2669 reloc
[1]->addend
= 0;
2670 reloc
[1]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2671 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2673 reloc
[2] = XNEW (arelent
);
2674 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2675 reloc
[2]->addend
= 0;
2676 reloc
[2]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2677 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2683 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2692 rx_note_string_insn_use (void)
2694 if ((elf_flags
& E_FLAG_RX_SINSNS_MASK
) == (E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
))
2695 as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
2696 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_YES
;
2699 /* Set the ELF specific flags. */
2702 rx_elf_final_processing (void)
2704 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2707 /* Scan the current input line for occurrences of Renesas
2708 local labels and replace them with the GAS version. */
2711 rx_start_line (void)
2713 int in_double_quote
= 0;
2714 int in_single_quote
= 0;
2716 char * p
= input_line_pointer
;
2719 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2730 /* Handle escaped double quote \" inside a string. */
2731 if (prev_char
!= '\\')
2732 in_double_quote
= ! in_double_quote
;
2736 in_single_quote
= ! in_single_quote
;
2740 if (in_double_quote
|| in_single_quote
)
2745 else if (p
[1] == '+')
2750 else if (p
[1] == '-')