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