1 /* tc-rx.c -- Assembler for the Renesas RX
2 Copyright (C) 2008-2022 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
);
385 for (i
= 0; i
< include_dir_count
; i
++)
387 sprintf (path
, "%s/%s", include_dirs
[i
], f
);
388 if ((try = fopen (path
, FOPEN_RT
)) != NULL
)
393 if (try == NULL
&& env
!= NULL
)
395 sprintf (path
, "%s/%s", env
, f
);
396 try = fopen (path
, FOPEN_RT
);
404 as_bad (_("unable to locate include file: %s"), filename
);
410 register_dependency (path
);
411 input_scrub_insert_file (path
);
414 * last_char
= end_char
;
418 parse_rx_section (char * name
)
422 int attr
= SHF_ALLOC
| SHF_EXECINSTR
;
431 for (p
= input_line_pointer
; *p
&& strchr ("\n\t, =", *p
) == NULL
; p
++)
436 if (strcasecmp (input_line_pointer
, "ALIGN") == 0)
451 case '2': align
= 1; break;
452 case '4': align
= 2; break;
453 case '8': align
= 3; break;
455 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p
);
456 ignore_rest_of_line ();
464 else if (strcasecmp (input_line_pointer
, "CODE") == 0)
465 attr
= SHF_ALLOC
| SHF_EXECINSTR
;
466 else if (strcasecmp (input_line_pointer
, "DATA") == 0)
467 attr
= SHF_ALLOC
| SHF_WRITE
;
468 else if (strcasecmp (input_line_pointer
, "ROMDATA") == 0)
472 as_bad (_("unknown parameter following .SECTION directive: %s"),
476 input_line_pointer
= p
+ 1;
477 ignore_rest_of_line ();
482 input_line_pointer
= p
+ 1;
484 while (end_char
!= '\n' && end_char
!= 0);
486 if ((sec
= bfd_get_section_by_name (stdoutput
, name
)) == NULL
)
488 if (strcmp (name
, "B") && strcmp (name
, "B_1") && strcmp (name
, "B_2"))
493 obj_elf_change_section (name
, type
, attr
, 0, NULL
, false, false);
495 else /* Try not to redefine a section, especially B_1. */
497 int flags
= sec
->flags
;
499 type
= elf_section_type (sec
);
501 attr
= ((flags
& SEC_READONLY
) ? 0 : SHF_WRITE
)
502 | ((flags
& SEC_ALLOC
) ? SHF_ALLOC
: 0)
503 | ((flags
& SEC_CODE
) ? SHF_EXECINSTR
: 0)
504 | ((flags
& SEC_MERGE
) ? SHF_MERGE
: 0)
505 | ((flags
& SEC_STRINGS
) ? SHF_STRINGS
: 0)
506 | ((flags
& SEC_THREAD_LOCAL
) ? SHF_TLS
: 0);
508 obj_elf_change_section (name
, type
, attr
, 0, NULL
, false, false);
511 bfd_set_section_alignment (now_seg
, align
);
515 rx_section (int ignore
)
519 /* The as100 assembler supports a different syntax for the .section
520 pseudo-op. So check for it and handle it here if necessary. */
523 /* Peek past the section name to see if arguments follow. */
524 for (p
= input_line_pointer
; *p
; p
++)
525 if (*p
== ',' || *p
== '\n')
530 int len
= p
- input_line_pointer
;
532 while (ISSPACE (*++p
))
535 if (*p
!= '"' && *p
!= '#')
537 char *name
= xmemdup0 (input_line_pointer
, len
);
539 input_line_pointer
= p
;
540 parse_rx_section (name
);
545 obj_elf_section (ignore
);
549 rx_list (int ignore ATTRIBUTE_UNUSED
)
553 if (strncasecmp (input_line_pointer
, "OFF", 3))
555 else if (strncasecmp (input_line_pointer
, "ON", 2))
558 as_warn (_("expecting either ON or OFF after .list"));
561 /* Like the .rept pseudo op, but supports the
562 use of ..MACREP inside the repeated region. */
565 rx_rept (int ignore ATTRIBUTE_UNUSED
)
567 size_t count
= get_absolute_expression ();
569 do_repeat (count
, "MREPEAT", "ENDR", "..MACREP");
572 /* Like cons() accept that strings are allowed. */
579 if (* input_line_pointer
== '"')
586 rx_nop (int ignore ATTRIBUTE_UNUSED
)
588 ignore_rest_of_line ();
594 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
595 md_pseudo_table
[idx
].poc_name
);
596 ignore_rest_of_line ();
599 /* The target specific pseudo-ops which we support. */
600 const pseudo_typeS md_pseudo_table
[] =
602 /* These are unimplemented. They're listed first so that we can use
603 the poc_value as the index into this array, to get the name of
604 the pseudo. So, keep these (1) first, and (2) in order, with (3)
605 the poc_value's in sequence. */
606 { "btglb", rx_unimp
, 0 },
607 { "call", rx_unimp
, 1 },
608 { "einsf", rx_unimp
, 2 },
609 { "fb", rx_unimp
, 3 },
610 { "fbsym", rx_unimp
, 4 },
611 { "id", rx_unimp
, 5 },
612 { "initsct", rx_unimp
, 6 },
613 { "insf", rx_unimp
, 7 },
614 { "instr", rx_unimp
, 8 },
615 { "lbba", rx_unimp
, 9 },
616 { "len", rx_unimp
, 10 },
617 { "optj", rx_unimp
, 11 },
618 { "rvector", rx_unimp
, 12 },
619 { "sb", rx_unimp
, 13 },
620 { "sbbit", rx_unimp
, 14 },
621 { "sbsym", rx_unimp
, 15 },
622 { "sbsym16", rx_unimp
, 16 },
624 /* These are the do-nothing pseudos. */
625 { "stk", rx_nop
, 0 },
626 /* The manual documents ".stk" but the compiler emits ".stack". */
627 { "stack", rx_nop
, 0 },
629 /* These are Renesas as100 assembler pseudo-ops that we do support. */
630 { "addr", rx_cons
, 3 },
631 { "align", s_align_bytes
, 2 },
632 { "byte", rx_cons
, 1 },
633 { "fixed", float_cons
, 'f' },
634 { "form", listing_psize
, 0 },
635 { "glb", s_globl
, 0 },
636 { "include", rx_include
, 0 },
637 { "list", rx_list
, 0 },
638 { "lword", rx_cons
, 4 },
639 { "mrepeat", rx_rept
, 0 },
640 { "section", rx_section
, 0 },
642 /* FIXME: The following pseudo-ops place their values (and associated
643 label if present) in the data section, regardless of whatever
644 section we are currently in. At the moment this code does not
645 implement that part of the semantics. */
646 { "blka", s_space
, 3 },
647 { "blkb", s_space
, 1 },
648 { "blkd", s_space
, 8 },
649 { "blkf", s_space
, 4 },
650 { "blkl", s_space
, 4 },
651 { "blkw", s_space
, 2 },
653 /* Our "standard" pseudos. */
654 { "double", rx_float_cons
, 0 },
656 { "3byte", cons
, 3 },
660 { "fetchalign", rx_fetchalign
, 0 },
662 /* End of list marker. */
666 static asymbol
* gp_symbol
;
667 static asymbol
* rx_pid_symbol
;
669 static symbolS
* rx_pidreg_symbol
;
670 static symbolS
* rx_gpreg_symbol
;
675 /* Make the __gp and __pid_base symbols now rather
676 than after the symbol table is frozen. We only do this
677 when supporting small data limits because otherwise we
678 pollute the symbol table. */
680 /* The meta-registers %pidreg and %gpreg depend on what other
681 options are specified. The __rx_*_defined symbols exist so we
682 can .ifdef asm code based on what options were passed to gas,
683 without needing a preprocessor */
687 rx_pid_register
= 13 - rx_num_int_regs
;
688 rx_pid_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
689 rx_pidreg_symbol
= symbol_find_or_make ("__rx_pidreg_defined");
690 S_SET_VALUE (rx_pidreg_symbol
, rx_pid_register
);
691 S_SET_SEGMENT (rx_pidreg_symbol
, absolute_section
);
694 if (rx_use_small_data_limit
)
697 rx_gp_register
= rx_pid_register
- 1;
699 rx_gp_register
= 13 - rx_num_int_regs
;
700 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
701 rx_gpreg_symbol
= symbol_find_or_make ("__rx_gpreg_defined");
702 S_SET_VALUE (rx_gpreg_symbol
, rx_gp_register
);
703 S_SET_SEGMENT (rx_gpreg_symbol
, absolute_section
);
710 /* These negative numbers are found in rx_bytesT.n_base for non-opcode
712 #define RX_NBASE_FETCHALIGN -1
714 typedef struct rx_bytesT
717 /* If this is negative, it's a special-purpose frag as per the defines above. */
726 char type
; /* RXREL_*. */
741 fixS
*link_relax_fixP
;
742 unsigned long times_grown
;
743 unsigned long times_shrank
;
746 static rx_bytesT rx_bytes
;
747 /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
748 static rx_bytesT
*fetchalign_bytes
= NULL
;
751 rx_fetchalign (int ignore ATTRIBUTE_UNUSED
)
756 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
757 rx_bytes
.n_base
= RX_NBASE_FETCHALIGN
;
759 bytes
= frag_more (8);
760 frag_then
= frag_now
;
761 frag_variant (rs_machine_dependent
,
768 frag_then
->fr_opcode
= bytes
;
769 frag_then
->fr_subtype
= 0;
770 fetchalign_bytes
= frag_then
->tc_frag_data
;
774 rx_relax (int type
, int pos
)
776 rx_bytes
.relax
[rx_bytes
.n_relax
].type
= type
;
777 rx_bytes
.relax
[rx_bytes
.n_relax
].field_pos
= pos
;
778 rx_bytes
.relax
[rx_bytes
.n_relax
].val_ofs
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
783 rx_linkrelax_dsp (int pos
)
788 rx_bytes
.link_relax
|= RX_RELAXA_DSP4
;
791 rx_bytes
.link_relax
|= RX_RELAXA_DSP6
;
794 rx_bytes
.link_relax
|= RX_RELAXA_DSP14
;
800 rx_linkrelax_imm (int pos
)
805 rx_bytes
.link_relax
|= RX_RELAXA_IMM6
;
808 rx_bytes
.link_relax
|= RX_RELAXA_IMM12
;
814 rx_linkrelax_branch (void)
816 rx_bytes
.link_relax
|= RX_RELAXA_BRA
;
820 rx_fixup (expressionS exp
, int offsetbits
, int nbits
, int type
)
822 rx_bytes
.fixups
[rx_bytes
.n_fixups
].exp
= exp
;
823 rx_bytes
.fixups
[rx_bytes
.n_fixups
].offset
= offsetbits
;
824 rx_bytes
.fixups
[rx_bytes
.n_fixups
].nbits
= nbits
;
825 rx_bytes
.fixups
[rx_bytes
.n_fixups
].type
= type
;
826 rx_bytes
.fixups
[rx_bytes
.n_fixups
].reloc
= exp
.X_md
;
827 rx_bytes
.n_fixups
++;
830 #define rx_field_fixup(exp, offset, nbits, type) \
831 rx_fixup (exp, offset, nbits, type)
833 #define rx_op_fixup(exp, offset, nbits, type) \
834 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
839 rx_bytes
.base
[0] = b1
;
844 rx_base2 (int b1
, int b2
)
846 rx_bytes
.base
[0] = b1
;
847 rx_bytes
.base
[1] = b2
;
852 rx_base3 (int b1
, int b2
, int b3
)
854 rx_bytes
.base
[0] = b1
;
855 rx_bytes
.base
[1] = b2
;
856 rx_bytes
.base
[2] = b3
;
861 rx_base4 (int b1
, int b2
, int b3
, int b4
)
863 rx_bytes
.base
[0] = b1
;
864 rx_bytes
.base
[1] = b2
;
865 rx_bytes
.base
[2] = b3
;
866 rx_bytes
.base
[3] = b4
;
870 /* This gets complicated when the field spans bytes, because fields
871 are numbered from the MSB of the first byte as zero, and bits are
872 stored LSB towards the LSB of the byte. Thus, a simple four-bit
873 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
874 insertion of b'MXL at position 7 is like this:
876 - - - - - - - - - - - - - - - -
880 rx_field (int val
, int pos
, int sz
)
887 if (val
< 0 || val
>= (1 << sz
))
888 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val
, sz
);
893 if (val
< -(1 << (sz
- 1)) || val
>= (1 << (sz
- 1)))
894 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val
, sz
);
897 /* This code points at 'M' in the above example. */
901 while (bitp
+ sz
> 8)
906 svalm
= val
>> (sz
- ssz
);
907 svalm
= svalm
& ((1 << ssz
) - 1);
908 svalm
= svalm
<< (8 - bitp
- ssz
);
909 gas_assert (bytep
< rx_bytes
.n_base
);
910 rx_bytes
.base
[bytep
] |= svalm
;
916 valm
= val
& ((1 << sz
) - 1);
917 valm
= valm
<< (8 - bitp
- sz
);
918 gas_assert (bytep
< rx_bytes
.n_base
);
919 rx_bytes
.base
[bytep
] |= valm
;
922 /* Special case of the above, for 3-bit displacements of 2..9. */
925 rx_disp3 (expressionS exp
, int pos
)
927 rx_field_fixup (exp
, pos
, 3, RXREL_PCREL
);
930 /* Special case of the above, for split 5-bit displacements. Assumes
931 the displacement has been checked with rx_disp5op. */
932 /* ---- -432 1--- 0--- */
935 rx_field5s (expressionS exp
)
939 val
= exp
.X_add_number
;
940 rx_bytes
.base
[0] |= val
>> 2;
941 rx_bytes
.base
[1] |= (val
<< 6) & 0x80;
942 rx_bytes
.base
[1] |= (val
<< 3) & 0x08;
945 /* ---- ---- 4--- 3210 */
948 rx_field5s2 (expressionS exp
)
952 val
= exp
.X_add_number
;
953 rx_bytes
.base
[1] |= (val
<< 3) & 0x80;
954 rx_bytes
.base
[1] |= (val
) & 0x0f;
958 rx_bfield(expressionS s
, expressionS d
, expressionS w
)
960 int slsb
= s
.X_add_number
;
961 int dlsb
= d
.X_add_number
;
962 int width
= w
.X_add_number
;
964 (((dlsb
+ width
) & 0x1f) << 10 | (dlsb
<< 5) |
965 ((dlsb
- slsb
) & 0x1f));
966 if ((slsb
+ width
) > 32)
967 as_warn (_("Value %d and %d out of range"), slsb
, width
);
968 if ((dlsb
+ width
) > 32)
969 as_warn (_("Value %d and %d out of range"), dlsb
, width
);
970 rx_bytes
.ops
[0] = imm
& 0xff;
971 rx_bytes
.ops
[1] = (imm
>> 8);
975 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
977 #define F_PRECISION 2
980 rx_op (expressionS exp
, int nbytes
, int type
)
984 if ((exp
.X_op
== O_constant
|| exp
.X_op
== O_big
)
985 && type
!= RXREL_PCREL
)
987 if (exp
.X_op
== O_big
)
989 if (exp
.X_add_number
== -1)
992 char * ip
= rx_bytes
.ops
+ rx_bytes
.n_ops
;
994 gen_to_words (w
, F_PRECISION
, 8);
995 #if RX_OPCODE_BIG_ENDIAN
1006 rx_bytes
.n_ops
+= 4;
1010 v
= ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
1011 | (generic_bignum
[0] & LITTLENUM_MASK
);
1015 v
= exp
.X_add_number
;
1019 #if RX_OPCODE_BIG_ENDIAN
1020 OP ((v
>> (8 * (nbytes
- 1))) & 0xff);
1030 rx_op_fixup (exp
, rx_bytes
.n_ops
* 8, nbytes
* 8, type
);
1031 memset (rx_bytes
.ops
+ rx_bytes
.n_ops
, 0, nbytes
);
1032 rx_bytes
.n_ops
+= nbytes
;
1036 void rx_post(char byte
)
1038 rx_bytes
.post
[rx_bytes
.n_post
++] = byte
;
1047 #define APPEND(B, N_B) \
1050 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
1051 idx += rx_bytes.N_B; \
1055 rx_frag_init (fragS
* fragP
)
1057 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
|| rx_bytes
.n_base
< 0)
1059 fragP
->tc_frag_data
= XNEW (rx_bytesT
);
1060 memcpy (fragP
->tc_frag_data
, & rx_bytes
, sizeof (rx_bytesT
));
1063 fragP
->tc_frag_data
= 0;
1066 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
1067 <symbol_name> .equ <expression> */
1070 rx_equ (char * name
, char * expression
)
1072 char saved_name_end_char
;
1076 while (ISSPACE (* name
))
1079 for (name_end
= name
+ 1; *name_end
; name_end
++)
1080 if (! ISALNUM (* name_end
))
1083 saved_name_end_char
= * name_end
;
1086 saved_ilp
= input_line_pointer
;
1087 input_line_pointer
= expression
;
1091 input_line_pointer
= saved_ilp
;
1092 * name_end
= saved_name_end_char
;
1095 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
1096 rather than at the start of a line. (eg .EQU or .DEFINE). If one
1097 is found, process it and return TRUE otherwise return FALSE. */
1100 scan_for_infix_rx_pseudo_ops (char * str
)
1104 char * dot
= strchr (str
, '.');
1106 if (dot
== NULL
|| dot
== str
)
1109 /* A real pseudo-op must be preceded by whitespace. */
1110 if (dot
[-1] != ' ' && dot
[-1] != '\t')
1113 pseudo_op
= dot
+ 1;
1115 if (!ISALNUM (* pseudo_op
))
1118 for (p
= pseudo_op
+ 1; ISALNUM (* p
); p
++)
1121 if (strncasecmp ("EQU", pseudo_op
, p
- pseudo_op
) == 0)
1123 else if (strncasecmp ("DEFINE", pseudo_op
, p
- pseudo_op
) == 0)
1124 as_warn (_("The .DEFINE pseudo-op is not implemented"));
1125 else if (strncasecmp ("MACRO", pseudo_op
, p
- pseudo_op
) == 0)
1126 as_warn (_("The .MACRO pseudo-op is not implemented"));
1127 else if (strncasecmp ("BTEQU", pseudo_op
, p
- pseudo_op
) == 0)
1128 as_warn (_("The .BTEQU pseudo-op is not implemented."));
1136 md_assemble (char * str
)
1141 fragS
* frag_then
= frag_now
;
1144 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
1146 rx_lex_init (str
, str
+ strlen (str
));
1147 if (scan_for_infix_rx_pseudo_ops (str
))
1151 /* This simplifies the relaxation code. */
1152 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
1154 /* We do it this way because we want the frag to have the
1155 rx_bytes in it, which we initialize above. */
1156 bytes
= frag_more (12);
1157 frag_then
= frag_now
;
1158 frag_variant (rs_machine_dependent
,
1165 frag_then
->fr_opcode
= bytes
;
1166 frag_then
->fr_fix
+= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1167 frag_then
->fr_subtype
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1171 bytes
= frag_more (rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
);
1172 frag_then
= frag_now
;
1173 if (fetchalign_bytes
)
1174 fetchalign_bytes
->n_ops
= rx_bytes
.n_base
+ rx_bytes
.n_ops
+ rx_bytes
.n_post
;
1177 fetchalign_bytes
= NULL
;
1179 APPEND (base
, n_base
);
1180 APPEND (ops
, n_ops
);
1181 APPEND (post
, n_post
);
1183 if (rx_bytes
.link_relax
&& rx_bytes
.n_fixups
)
1187 f
= fix_new (frag_then
,
1188 (char *) bytes
- frag_then
->fr_literal
,
1191 rx_bytes
.link_relax
| rx_bytes
.n_fixups
,
1193 BFD_RELOC_RX_RELAX
);
1194 frag_then
->tc_frag_data
->link_relax_fixP
= f
;
1197 for (i
= 0; i
< rx_bytes
.n_fixups
; i
++)
1199 /* index: [nbytes][type] */
1200 static int reloc_map
[5][4] =
1202 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL
},
1203 { BFD_RELOC_8
, BFD_RELOC_RX_8U
, BFD_RELOC_RX_NEG8
, BFD_RELOC_8_PCREL
},
1204 { BFD_RELOC_RX_16_OP
, BFD_RELOC_RX_16U
, BFD_RELOC_RX_NEG16
, BFD_RELOC_16_PCREL
},
1205 { BFD_RELOC_RX_24_OP
, BFD_RELOC_RX_24U
, BFD_RELOC_RX_NEG24
, BFD_RELOC_24_PCREL
},
1206 { BFD_RELOC_RX_32_OP
, BFD_RELOC_32
, BFD_RELOC_RX_NEG32
, BFD_RELOC_32_PCREL
},
1210 idx
= rx_bytes
.fixups
[i
].offset
/ 8;
1211 rel
= reloc_map
[rx_bytes
.fixups
[i
].nbits
/ 8][(int) rx_bytes
.fixups
[i
].type
];
1213 if (rx_bytes
.fixups
[i
].reloc
)
1214 rel
= rx_bytes
.fixups
[i
].reloc
;
1216 if (frag_then
->tc_frag_data
)
1217 exp
= & frag_then
->tc_frag_data
->fixups
[i
].exp
;
1219 exp
= & rx_bytes
.fixups
[i
].exp
;
1221 f
= fix_new_exp (frag_then
,
1222 (char *) bytes
+ idx
- frag_then
->fr_literal
,
1223 rx_bytes
.fixups
[i
].nbits
/ 8,
1225 rx_bytes
.fixups
[i
].type
== RXREL_PCREL
? 1 : 0,
1227 if (frag_then
->tc_frag_data
)
1228 frag_then
->tc_frag_data
->fixups
[i
].fixP
= f
;
1230 dwarf2_emit_insn (idx
);
1238 /* Write a value out to the object file, using the appropriate endianness. */
1241 md_number_to_chars (char * buf
, valueT val
, int n
)
1243 if (target_big_endian
)
1244 number_to_chars_bigendian (buf
, val
, n
);
1246 number_to_chars_littleendian (buf
, val
, n
);
1256 { "gp", BFD_RELOC_GPREL16
},
1261 md_operand (expressionS
* exp ATTRIBUTE_UNUSED
)
1266 for (i
= 0; reloc_functions
[i
].fname
; i
++)
1268 int flen
= strlen (reloc_functions
[i
].fname
);
1270 if (input_line_pointer
[0] == '%'
1271 && strncasecmp (input_line_pointer
+ 1, reloc_functions
[i
].fname
, flen
) == 0
1272 && input_line_pointer
[flen
+ 1] == '(')
1274 reloc
= reloc_functions
[i
].reloc
;
1275 input_line_pointer
+= flen
+ 2;
1283 if (* input_line_pointer
== ')')
1284 input_line_pointer
++;
1290 md_section_align (segT segment
, valueT size
)
1292 int align
= bfd_section_alignment (segment
);
1293 return ((size
+ (1 << align
) - 1) & -(1 << align
));
1297 static unsigned char nop_1
[] = { 0x03};
1298 /* MOV.L R0,R0 - 1 cycle */
1299 static unsigned char nop_2
[] = { 0xef, 0x00};
1300 /* MAX R0,R0 - 1 cycle */
1301 static unsigned char nop_3
[] = { 0xfc, 0x13, 0x00 };
1302 /* MUL #1,R0 - 1 cycle */
1303 static unsigned char nop_4
[] = { 0x76, 0x10, 0x01, 0x00 };
1304 /* MUL #1,R0 - 1 cycle */
1305 static unsigned char nop_5
[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
1306 /* MUL #1,R0 - 1 cycle */
1307 static unsigned char nop_6
[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
1308 /* MAX 0x80000000,R0 - 1 cycle */
1309 static unsigned char nop_7
[] = { 0xFD, 0x70, 0x40, 0x00, 0x00, 0x00, 0x80 };
1311 static unsigned char *nops
[] = { NULL
, nop_1
, nop_2
, nop_3
, nop_4
, nop_5
, nop_6
, nop_7
};
1312 #define BIGGEST_NOP 7
1314 /* When relaxing, we need to output a reloc for any .align directive
1315 so that we can retain this alignment as we adjust opcode sizes. */
1317 rx_handle_align (fragS
* frag
)
1319 /* If handling an alignment frag, use an optimal NOP pattern.
1320 Only do this if a fill value has not already been provided.
1321 FIXME: This test fails if the provided fill value is zero. */
1322 if ((frag
->fr_type
== rs_align
1323 || frag
->fr_type
== rs_align_code
)
1324 && subseg_text_p (now_seg
))
1326 int count
= (frag
->fr_next
->fr_address
1329 unsigned char *base
= (unsigned char *)frag
->fr_literal
+ frag
->fr_fix
;
1333 if (count
> BIGGEST_NOP
)
1341 memcpy (base
, nops
[count
], count
);
1342 frag
->fr_var
= count
;
1348 && (frag
->fr_type
== rs_align
1349 || frag
->fr_type
== rs_align_code
)
1350 && frag
->fr_address
+ frag
->fr_fix
> 0
1351 && frag
->fr_offset
> 0
1352 && now_seg
!= bss_section
)
1354 fix_new (frag
, frag
->fr_fix
, 0,
1355 &abs_symbol
, RX_RELAXA_ALIGN
+ frag
->fr_offset
,
1356 0, BFD_RELOC_RX_RELAX
);
1357 /* For the purposes of relaxation, this relocation is attached
1358 to the byte *after* the alignment - i.e. the byte that must
1360 fix_new (frag
->fr_next
, 0, 0,
1361 &abs_symbol
, RX_RELAXA_ELIGN
+ frag
->fr_offset
,
1362 0, BFD_RELOC_RX_RELAX
);
1367 md_atof (int type
, char * litP
, int * sizeP
)
1369 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1373 md_undefined_symbol (char * name ATTRIBUTE_UNUSED
)
1378 /*----------------------------------------------------------------------*/
1379 /* To recap: we estimate everything based on md_estimate_size, then
1380 adjust based on rx_relax_frag. When it all settles, we call
1381 md_convert frag to update the bytes. The relaxation types and
1382 relocations are in fragP->tc_frag_data, which is a copy of that
1385 Our scheme is as follows: fr_fix has the size of the smallest
1386 opcode (like BRA.S). We store the number of total bytes we need in
1387 fr_subtype. When we're done relaxing, we use fr_subtype and the
1388 existing opcode bytes to figure out what actual opcode we need to
1389 put in there. If the fixup isn't resolvable now, we use the
1392 #define TRACE_RELAX 0
1393 #define tprintf if (TRACE_RELAX) printf
1405 /* We're looking for these types of relaxations:
1408 BRA.B 00101110 dspppppp
1409 BRA.W 00111000 dspppppp pppppppp
1410 BRA.A 00000100 dspppppp pppppppp pppppppp
1413 BEQ.B 00100000 dspppppp
1414 BEQ.W 00111010 dspppppp pppppppp
1417 BNE.B 00100001 dspppppp
1418 BNE.W 00111011 dspppppp pppppppp
1420 BSR.W 00111001 dspppppp pppppppp
1421 BSR.A 00000101 dspppppp pppppppp pppppppp
1423 Bcc.B 0010cond dspppppp
1425 Additionally, we can synthesize longer conditional branches using
1426 pairs of opcodes, one with an inverted conditional (flip LSB):
1428 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1429 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1430 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1431 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1433 /* Given the opcode bytes at OP, figure out which opcode it is and
1434 return the type of opcode. We use this to re-encode the opcode as
1435 a different size later. */
1438 rx_opcode_type (char * op
)
1440 unsigned char b
= (unsigned char) op
[0];
1444 case 0x08: return OT_bra
;
1445 case 0x10: return OT_beq
;
1446 case 0x18: return OT_bne
;
1451 case 0x2e: return OT_bra
;
1452 case 0x38: return OT_bra
;
1453 case 0x04: return OT_bra
;
1455 case 0x20: return OT_beq
;
1456 case 0x3a: return OT_beq
;
1458 case 0x21: return OT_bne
;
1459 case 0x3b: return OT_bne
;
1461 case 0x39: return OT_bsr
;
1462 case 0x05: return OT_bsr
;
1465 if ((b
& 0xf0) == 0x20)
1471 /* Returns zero if *addrP has the target address. Else returns nonzero
1472 if we cannot compute the target address yet. */
1475 rx_frag_fix_value (fragS
* fragP
,
1480 addressT
* sym_addr
)
1483 rx_bytesT
* b
= fragP
->tc_frag_data
;
1484 expressionS
* exp
= & b
->fixups
[which
].exp
;
1486 if (need_diff
&& exp
->X_op
!= O_subtract
)
1489 if (exp
->X_add_symbol
)
1491 if (S_FORCE_RELOC (exp
->X_add_symbol
, 1))
1493 if (S_GET_SEGMENT (exp
->X_add_symbol
) != segment
)
1495 addr
+= S_GET_VALUE (exp
->X_add_symbol
);
1498 if (exp
->X_op_symbol
)
1500 if (exp
->X_op
!= O_subtract
)
1502 if (S_FORCE_RELOC (exp
->X_op_symbol
, 1))
1504 if (S_GET_SEGMENT (exp
->X_op_symbol
) != segment
)
1506 addr
-= S_GET_VALUE (exp
->X_op_symbol
);
1510 addr
+= exp
->X_add_number
;
1515 /* Estimate how big the opcode is after this relax pass. The return
1516 value is the difference between fr_fix and the actual size. We
1517 compute the total size in rx_relax_frag and store it in fr_subtype,
1518 so we only need to subtract fx_fix and return it. */
1521 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
, segT segment ATTRIBUTE_UNUSED
)
1526 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1527 (unsigned long) (fragP
->fr_address
1528 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1529 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1530 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1532 /* This is the size of the opcode that's accounted for in fr_fix. */
1533 opfixsize
= fragP
->fr_fix
- (fragP
->fr_opcode
- fragP
->fr_literal
);
1534 /* This is the size of the opcode that isn't. */
1535 delta
= (fragP
->fr_subtype
- opfixsize
);
1537 tprintf (" -> opfixsize %d delta %d\n", opfixsize
, delta
);
1541 /* Given a frag FRAGP, return the "next" frag that contains an
1542 opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
1545 rx_next_opcode (fragS
*fragP
)
1548 fragP
= fragP
->fr_next
;
1549 } while (fragP
&& fragP
->fr_type
!= rs_machine_dependent
);
1553 /* Given the new addresses for this relax pass, figure out how big
1554 each opcode must be. We store the total number of bytes needed in
1555 fr_subtype. The return value is the difference between the size
1556 after the last pass and the size after this pass, so we use the old
1557 fr_subtype to calculate the difference. */
1560 rx_relax_frag (segT segment ATTRIBUTE_UNUSED
, fragS
* fragP
, long stretch
, unsigned long max_iterations
)
1562 addressT addr0
, sym_addr
;
1565 int oldsize
= fragP
->fr_subtype
;
1566 int newsize
= oldsize
;
1568 /* Index of relaxation we care about. */
1571 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",
1572 (unsigned long) (fragP
->fr_address
1573 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1574 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1575 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
, stretch
);
1577 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1579 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1581 unsigned int next_size
;
1582 if (fragP
->fr_next
== NULL
)
1585 next_size
= fragP
->tc_frag_data
->n_ops
;
1588 fragS
*n
= rx_next_opcode (fragP
);
1589 next_size
= n
->fr_subtype
;
1592 fragP
->fr_subtype
= (8-(mypc
& 7)) & 7;
1593 tprintf("subtype %u\n", fragP
->fr_subtype
);
1594 if (fragP
->fr_subtype
>= next_size
)
1595 fragP
->fr_subtype
= 0;
1596 tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
1597 (unsigned long) (mypc
& 7),
1598 next_size
, fragP
->fr_subtype
, oldsize
, fragP
->fr_subtype
-oldsize
);
1600 newsize
= fragP
->fr_subtype
;
1602 return newsize
- oldsize
;
1605 optype
= rx_opcode_type (fragP
->fr_opcode
);
1607 /* In the one case where we have both a disp and imm relaxation, we want
1608 the imm relaxation here. */
1610 if (fragP
->tc_frag_data
->n_relax
> 1
1611 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1614 /* Try to get the target address. */
1615 if (rx_frag_fix_value (fragP
, segment
, ri
, & addr0
,
1616 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
,
1619 /* If we don't, we must use the maximum size for the linker.
1620 Note that we don't use synthetically expanded conditionals
1622 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1624 case RX_RELAX_BRANCH
:
1645 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
+ 4;
1648 fragP
->fr_subtype
= newsize
;
1649 tprintf (" -> new %d old %d delta %d (external)\n", newsize
, oldsize
, newsize
-oldsize
);
1650 return newsize
- oldsize
;
1653 if (sym_addr
> mypc
)
1656 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1658 case RX_RELAX_BRANCH
:
1659 tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
1660 (unsigned long) addr0
, (unsigned long) mypc
,
1661 (long) (addr0
- mypc
));
1662 disp
= (int) addr0
- (int) mypc
;
1667 if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1670 else if (disp
>= -32768 && (disp
- (oldsize
-5)) <= 32767)
1680 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1683 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1686 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1696 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1699 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1702 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1713 tprintf (" - newsize %d\n", newsize
);
1717 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
1718 (unsigned long) addr0
, (unsigned long) mypc
,
1719 fragP
->tc_frag_data
->relax
[ri
].field_pos
,
1720 fragP
->tc_frag_data
->relax
[ri
].val_ofs
);
1722 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1724 if ((long) addr0
>= -128 && (long) addr0
<= 127)
1726 else if ((long) addr0
>= -32768 && (long) addr0
<= 32767)
1728 else if ((long) addr0
>= -8388608 && (long) addr0
<= 8388607)
1738 if (fragP
->tc_frag_data
->relax
[ri
].type
== RX_RELAX_BRANCH
)
1754 /* This prevents infinite loops in align-heavy sources. */
1755 if (newsize
< oldsize
)
1757 /* Make sure that our iteration limit is no bigger than the one being
1758 used inside write.c:relax_segment(). Otherwise we can end up
1759 iterating for too long, and triggering a fatal error there. See
1760 PR 24464 for more details. */
1761 unsigned long limit
= max_iterations
> 10 ? 10 : max_iterations
;
1763 if (fragP
->tc_frag_data
->times_shrank
> limit
1764 && fragP
->tc_frag_data
->times_grown
> limit
)
1767 if (fragP
->tc_frag_data
->times_shrank
< 20)
1768 fragP
->tc_frag_data
->times_shrank
++;
1770 else if (newsize
> oldsize
)
1772 if (fragP
->tc_frag_data
->times_grown
< 20)
1773 fragP
->tc_frag_data
->times_grown
++;
1776 fragP
->fr_subtype
= newsize
;
1777 tprintf (" -> new %d old %d delta %d\n", newsize
, oldsize
, newsize
-oldsize
);
1778 return newsize
- oldsize
;
1781 /* This lets us test for the opcode type and the desired size in a
1782 switch statement. */
1783 #define OPCODE(type,size) ((type) * 16 + (size))
1785 /* Given the opcode stored in fr_opcode and the number of bytes we
1786 think we need, encode a new opcode. We stored a pointer to the
1787 fixup for this opcode in the tc_frag_data structure. If we can do
1788 the fixup here, we change the relocation type to "none" (we test
1789 for that in tc_gen_reloc) else we change it to the right type for
1790 the new (biggest) opcode. */
1793 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1794 segT segment ATTRIBUTE_UNUSED
,
1795 fragS
* fragP ATTRIBUTE_UNUSED
)
1797 rx_bytesT
* rxb
= fragP
->tc_frag_data
;
1798 addressT addr0
, mypc
;
1801 bfd_reloc_code_real_type reloc_type
;
1802 char * op
= fragP
->fr_opcode
;
1805 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1806 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1808 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1809 (unsigned long) (fragP
->fr_address
1810 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1811 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1812 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
,
1819 printf ("lit 0x%p opc 0x%p", fragP
->fr_literal
, fragP
->fr_opcode
);
1820 for (i
= 0; i
< 10; i
++)
1821 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1826 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1828 int count
= fragP
->fr_subtype
;
1831 else if (count
> BIGGEST_NOP
)
1838 memcpy (op
, nops
[count
], count
);
1842 /* In the one case where we have both a disp and imm relaxation, we want
1843 the imm relaxation here. */
1845 if (fragP
->tc_frag_data
->n_relax
> 1
1846 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1849 /* We used a new frag for this opcode, so the opcode address should
1850 be the frag address. */
1851 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1853 /* Try to get the target address. If we fail here, we just use the
1855 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1856 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1858 /* We don't know the target address. */
1865 /* We know the target address, and it's in addr0. */
1866 disp
= (int) addr0
- (int) mypc
;
1872 reloc_type
= BFD_RELOC_NONE
;
1875 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1876 rx_opcode_type (fragP
->fr_opcode
), disp
,
1877 (unsigned long) addr0
, (unsigned long) mypc
);
1878 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1880 case RX_RELAX_BRANCH
:
1881 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1883 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1884 op
[0] = 0x08 + (disp
& 7);
1886 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1889 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1892 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1894 #if RX_OPCODE_BIG_ENDIAN
1895 op
[1] = (disp
>> 8) & 0xff;
1898 op
[2] = (disp
>> 8) & 0xff;
1902 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1904 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1906 #if RX_OPCODE_BIG_ENDIAN
1907 op
[1] = (disp
>> 16) & 0xff;
1908 op
[2] = (disp
>> 8) & 0xff;
1911 op
[3] = (disp
>> 16) & 0xff;
1912 op
[2] = (disp
>> 8) & 0xff;
1915 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1919 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1920 op
[0] = 0x10 + (disp
& 7);
1922 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1926 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1928 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1930 #if RX_OPCODE_BIG_ENDIAN
1931 op
[1] = (disp
>> 8) & 0xff;
1934 op
[2] = (disp
>> 8) & 0xff;
1937 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1940 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1941 op
[0] = 0x1d; /* bne.s .+5. */
1942 op
[1] = 0x04; /* bra.a dsp:24. */
1944 #if RX_OPCODE_BIG_ENDIAN
1945 op
[2] = (disp
>> 16) & 0xff;
1946 op
[3] = (disp
>> 8) & 0xff;
1949 op
[4] = (disp
>> 16) & 0xff;
1950 op
[3] = (disp
>> 8) & 0xff;
1953 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1957 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1958 op
[0] = 0x18 + (disp
& 7);
1960 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1964 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1966 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1968 #if RX_OPCODE_BIG_ENDIAN
1969 op
[1] = (disp
>> 8) & 0xff;
1972 op
[2] = (disp
>> 8) & 0xff;
1975 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1978 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1979 op
[0] = 0x15; /* beq.s .+5. */
1980 op
[1] = 0x04; /* bra.a dsp:24. */
1982 #if RX_OPCODE_BIG_ENDIAN
1983 op
[2] = (disp
>> 16) & 0xff;
1984 op
[3] = (disp
>> 8) & 0xff;
1987 op
[4] = (disp
>> 16) & 0xff;
1988 op
[3] = (disp
>> 8) & 0xff;
1991 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1995 case OPCODE (OT_bsr
, 3): /* BSR.W - 16 bit. */
1997 #if RX_OPCODE_BIG_ENDIAN
1998 op
[1] = (disp
>> 8) & 0xff;
2001 op
[2] = (disp
>> 8) & 0xff;
2004 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2007 case OPCODE (OT_bsr
, 4): /* BSR.A - 24 bit. */
2009 #if RX_OPCODE_BIG_ENDIAN
2010 op
[1] = (disp
>> 16) & 0xff;
2011 op
[2] = (disp
>> 8) & 0xff;
2014 op
[3] = (disp
>> 16) & 0xff;
2015 op
[2] = (disp
>> 8) & 0xff;
2018 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2022 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
2024 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
2026 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
2027 op
[0] ^= 1; /* Invert condition. */
2028 op
[1] = 5; /* Displacement. */
2031 #if RX_OPCODE_BIG_ENDIAN
2032 op
[3] = (disp
>> 8) & 0xff;
2035 op
[4] = (disp
>> 8) & 0xff;
2038 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2041 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
2042 op
[0] ^= 1; /* Invert condition. */
2043 op
[1] = 6; /* Displacement. */
2046 #if RX_OPCODE_BIG_ENDIAN
2047 op
[3] = (disp
>> 16) & 0xff;
2048 op
[4] = (disp
>> 8) & 0xff;
2051 op
[5] = (disp
>> 16) & 0xff;
2052 op
[4] = (disp
>> 8) & 0xff;
2055 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2060 /* These are opcodes we'll relax in th linker, later. */
2062 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
2069 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2071 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2078 reloc_type
= BFD_RELOC_8
;
2082 #if RX_OPCODE_BIG_ENDIAN
2084 imm
[0] = addr0
>> 8;
2087 imm
[1] = addr0
>> 8;
2089 reloc_type
= BFD_RELOC_RX_16_OP
;
2093 #if RX_OPCODE_BIG_ENDIAN
2095 imm
[1] = addr0
>> 8;
2096 imm
[0] = addr0
>> 16;
2099 imm
[1] = addr0
>> 8;
2100 imm
[2] = addr0
>> 16;
2102 reloc_type
= BFD_RELOC_RX_24_OP
;
2106 #if RX_OPCODE_BIG_ENDIAN
2108 imm
[2] = addr0
>> 8;
2109 imm
[1] = addr0
>> 16;
2110 imm
[0] = addr0
>> 24;
2113 imm
[1] = addr0
>> 8;
2114 imm
[2] = addr0
>> 16;
2115 imm
[3] = addr0
>> 24;
2117 reloc_type
= BFD_RELOC_RX_32_OP
;
2120 as_bad (_("invalid immediate size"));
2124 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
2139 as_bad (_("invalid immediate field position"));
2147 reloc_type
= fix
->fx_r_type
;
2156 fix
->fx_r_type
= reloc_type
;
2157 fix
->fx_where
+= reloc_adjust
;
2160 case BFD_RELOC_NONE
:
2166 case BFD_RELOC_16_PCREL
:
2167 case BFD_RELOC_RX_16_OP
:
2170 case BFD_RELOC_24_PCREL
:
2171 case BFD_RELOC_RX_24_OP
:
2174 case BFD_RELOC_RX_32_OP
:
2182 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
2183 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP
->fr_fix
,
2184 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
2187 if (fragP
->fr_next
!= NULL
2188 && fragP
->fr_next
->fr_address
- fragP
->fr_address
!= fragP
->fr_fix
)
2189 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
2190 (long) fragP
->fr_fix
,
2191 (long) fragP
->fr_address
, (long) fragP
->fr_next
->fr_address
);
2197 rx_validate_fix_sub (struct fix
* f
)
2199 /* We permit the subtraction of two symbols in a few cases. */
2200 /* mov #sym1-sym2, R3 */
2201 if (f
->fx_r_type
== BFD_RELOC_RX_32_OP
)
2203 /* .long sym1-sym2 */
2204 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
2206 && (f
->fx_size
== 4 || f
->fx_size
== 2 || f
->fx_size
== 1))
2212 md_pcrel_from_section (fixS
* fixP
, segT sec
)
2216 if (fixP
->fx_addsy
!= NULL
2217 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2218 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
2219 /* The symbol is undefined (or is defined but not in this section).
2220 Let the linker figure it out. */
2223 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2224 switch (fixP
->fx_r_type
)
2226 case BFD_RELOC_RX_DIR3U_PCREL
:
2234 rx_cons_fix_new (fragS
* frag
,
2238 bfd_reloc_code_real_type type
)
2246 type
= BFD_RELOC_16
;
2249 type
= BFD_RELOC_24
;
2252 type
= BFD_RELOC_32
;
2255 as_bad (_("unsupported constant size %d\n"), size
);
2259 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
2261 if (size
!= 4 && size
!= 2 && size
!= 1)
2262 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2264 type
= BFD_RELOC_RX_DIFF
;
2267 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
2271 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
2272 valueT
* t ATTRIBUTE_UNUSED
,
2273 segT s ATTRIBUTE_UNUSED
)
2275 /* Instruction bytes are always little endian. */
2279 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
2281 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
2284 #define OP2(x) op[target_big_endian ? 1-x : x]
2285 #define OP3(x) op[target_big_endian ? 2-x : x]
2286 #define OP4(x) op[target_big_endian ? 3-x : x]
2288 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
2289 val
= (unsigned long) * t
;
2291 /* Opcode words are always the same endian. Data words are either
2292 big or little endian. */
2294 switch (f
->fx_r_type
)
2296 case BFD_RELOC_NONE
:
2299 case BFD_RELOC_RX_RELAX
:
2303 case BFD_RELOC_RX_DIR3U_PCREL
:
2304 if (val
< 3 || val
> 10)
2305 as_bad_where (f
->fx_file
, f
->fx_line
,
2306 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2308 op
[0] |= val
& 0x07;
2312 case BFD_RELOC_8_PCREL
:
2313 case BFD_RELOC_RX_8U
:
2318 OP2(1) = val
& 0xff;
2319 OP2(0) = (val
>> 8) & 0xff;
2322 case BFD_RELOC_16_PCREL
:
2323 case BFD_RELOC_RX_16_OP
:
2324 case BFD_RELOC_RX_16U
:
2325 #if RX_OPCODE_BIG_ENDIAN
2327 op
[0] = (val
>> 8) & 0xff;
2330 op
[1] = (val
>> 8) & 0xff;
2335 OP3(0) = val
& 0xff;
2336 OP3(1) = (val
>> 8) & 0xff;
2337 OP3(2) = (val
>> 16) & 0xff;
2340 case BFD_RELOC_24_PCREL
:
2341 case BFD_RELOC_RX_24_OP
:
2342 case BFD_RELOC_RX_24U
:
2343 #if RX_OPCODE_BIG_ENDIAN
2345 op
[1] = (val
>> 8) & 0xff;
2346 op
[0] = (val
>> 16) & 0xff;
2349 op
[1] = (val
>> 8) & 0xff;
2350 op
[2] = (val
>> 16) & 0xff;
2354 case BFD_RELOC_RX_DIFF
:
2361 OP2(0) = val
& 0xff;
2362 OP2(1) = (val
>> 8) & 0xff;
2365 OP4(0) = val
& 0xff;
2366 OP4(1) = (val
>> 8) & 0xff;
2367 OP4(2) = (val
>> 16) & 0xff;
2368 OP4(3) = (val
>> 24) & 0xff;
2374 OP4(0) = val
& 0xff;
2375 OP4(1) = (val
>> 8) & 0xff;
2376 OP4(2) = (val
>> 16) & 0xff;
2377 OP4(3) = (val
>> 24) & 0xff;
2380 case BFD_RELOC_RX_32_OP
:
2381 #if RX_OPCODE_BIG_ENDIAN
2383 op
[2] = (val
>> 8) & 0xff;
2384 op
[1] = (val
>> 16) & 0xff;
2385 op
[0] = (val
>> 24) & 0xff;
2388 op
[1] = (val
>> 8) & 0xff;
2389 op
[2] = (val
>> 16) & 0xff;
2390 op
[3] = (val
>> 24) & 0xff;
2394 case BFD_RELOC_RX_NEG8
:
2398 case BFD_RELOC_RX_NEG16
:
2400 #if RX_OPCODE_BIG_ENDIAN
2402 op
[0] = (val
>> 8) & 0xff;
2405 op
[1] = (val
>> 8) & 0xff;
2409 case BFD_RELOC_RX_NEG24
:
2411 #if RX_OPCODE_BIG_ENDIAN
2413 op
[1] = (val
>> 8) & 0xff;
2414 op
[0] = (val
>> 16) & 0xff;
2417 op
[1] = (val
>> 8) & 0xff;
2418 op
[2] = (val
>> 16) & 0xff;
2422 case BFD_RELOC_RX_NEG32
:
2424 #if RX_OPCODE_BIG_ENDIAN
2426 op
[2] = (val
>> 8) & 0xff;
2427 op
[1] = (val
>> 16) & 0xff;
2428 op
[0] = (val
>> 24) & 0xff;
2431 op
[1] = (val
>> 8) & 0xff;
2432 op
[2] = (val
>> 16) & 0xff;
2433 op
[3] = (val
>> 24) & 0xff;
2437 case BFD_RELOC_RX_GPRELL
:
2440 case BFD_RELOC_RX_GPRELW
:
2443 case BFD_RELOC_RX_GPRELB
:
2444 #if RX_OPCODE_BIG_ENDIAN
2446 op
[0] = (val
>> 8) & 0xff;
2449 op
[1] = (val
>> 8) & 0xff;
2454 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2455 bfd_get_reloc_code_name (f
->fx_r_type
));
2459 if (f
->fx_addsy
== NULL
)
2464 tc_gen_reloc (asection
* sec ATTRIBUTE_UNUSED
, fixS
* fixp
)
2466 static arelent
* reloc
[5];
2467 bool is_opcode
= false;
2469 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2476 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2478 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2479 fixp
->fx_subsy
= NULL
;
2482 reloc
[0] = XNEW (arelent
);
2483 reloc
[0]->sym_ptr_ptr
= XNEW (asymbol
*);
2484 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2485 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2486 reloc
[0]->addend
= fixp
->fx_offset
;
2488 if (fixp
->fx_r_type
== BFD_RELOC_RX_32_OP
2491 fixp
->fx_r_type
= BFD_RELOC_RX_DIFF
;
2495 is_opcode
= sec
->flags
& SEC_CODE
;
2497 /* Certain BFD relocations cannot be translated directly into
2498 a single (non-Red Hat) RX relocation, but instead need
2499 multiple RX relocations - handle them here. */
2500 switch (fixp
->fx_r_type
)
2502 case BFD_RELOC_RX_DIFF
:
2503 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2505 reloc
[1] = XNEW (arelent
);
2506 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2507 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2508 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2509 reloc
[1]->addend
= 0;
2510 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2512 reloc
[2] = XNEW (arelent
);
2513 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2514 reloc
[2]->addend
= 0;
2515 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2516 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2518 reloc
[3] = XNEW (arelent
);
2519 switch (fixp
->fx_size
)
2522 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2525 if (!is_opcode
&& target_big_endian
)
2526 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16_REV
);
2528 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2530 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2533 if (!is_opcode
&& target_big_endian
)
2534 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32_REV
);
2536 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2539 reloc
[3]->addend
= 0;
2540 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2541 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2546 case BFD_RELOC_RX_GPRELL
:
2547 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2549 reloc
[1] = XNEW (arelent
);
2550 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2551 if (gp_symbol
== NULL
)
2553 if (symbol_table_frozen
)
2557 gp
= symbol_find ("__gp");
2559 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2561 gp_symbol
= symbol_get_bfdsym (gp
);
2564 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2566 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2567 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2568 reloc
[1]->addend
= 0;
2569 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2571 reloc
[2] = XNEW (arelent
);
2572 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2573 reloc
[2]->addend
= 0;
2574 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2575 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2577 reloc
[3] = XNEW (arelent
);
2578 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2579 reloc
[3]->addend
= 0;
2580 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2581 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2586 case BFD_RELOC_RX_GPRELW
:
2587 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2589 reloc
[1] = XNEW (arelent
);
2590 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2591 if (gp_symbol
== NULL
)
2593 if (symbol_table_frozen
)
2597 gp
= symbol_find ("__gp");
2599 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2601 gp_symbol
= symbol_get_bfdsym (gp
);
2604 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2606 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2607 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2608 reloc
[1]->addend
= 0;
2609 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2611 reloc
[2] = XNEW (arelent
);
2612 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2613 reloc
[2]->addend
= 0;
2614 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2615 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2617 reloc
[3] = XNEW (arelent
);
2618 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2619 reloc
[3]->addend
= 0;
2620 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2621 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2626 case BFD_RELOC_RX_GPRELB
:
2627 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2629 reloc
[1] = XNEW (arelent
);
2630 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2631 if (gp_symbol
== NULL
)
2633 if (symbol_table_frozen
)
2637 gp
= symbol_find ("__gp");
2639 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2641 gp_symbol
= symbol_get_bfdsym (gp
);
2644 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2646 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2647 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2648 reloc
[1]->addend
= 0;
2649 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2651 reloc
[2] = XNEW (arelent
);
2652 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2653 reloc
[2]->addend
= 0;
2654 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2655 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2657 reloc
[3] = XNEW (arelent
);
2658 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2659 reloc
[3]->addend
= 0;
2660 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2661 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2666 case BFD_RELOC_RX_NEG32
:
2667 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2669 reloc
[1] = XNEW (arelent
);
2670 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_NEG
);
2671 reloc
[1]->addend
= 0;
2672 reloc
[1]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2673 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2675 reloc
[2] = XNEW (arelent
);
2676 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2677 reloc
[2]->addend
= 0;
2678 reloc
[2]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2679 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2685 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2694 rx_note_string_insn_use (void)
2696 if ((elf_flags
& E_FLAG_RX_SINSNS_MASK
) == (E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
))
2697 as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
2698 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_YES
;
2701 /* Set the ELF specific flags. */
2704 rx_elf_final_processing (void)
2706 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2709 /* Scan the current input line for occurrences of Renesas
2710 local labels and replace them with the GAS version. */
2713 rx_start_line (void)
2715 int in_double_quote
= 0;
2716 int in_single_quote
= 0;
2718 char * p
= input_line_pointer
;
2721 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2732 /* Handle escaped double quote \" inside a string. */
2733 if (prev_char
!= '\\')
2734 in_double_quote
= ! in_double_quote
;
2738 in_single_quote
= ! in_single_quote
;
2742 if (in_double_quote
|| in_single_quote
)
2747 else if (p
[1] == '+')
2752 else if (p
[1] == '-')