1 /* tc-rx.c -- Assembler for the Renesas RX
2 Copyright (C) 2008-2016 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 "struc-symbol.h"
23 #include "safe-ctype.h"
24 #include "dwarf2dbg.h"
26 #include "elf/common.h"
29 #include "filenames.h"
34 #define RX_OPCODE_BIG_ENDIAN 0
36 const char comment_chars
[] = ";";
37 /* Note that input_file.c hand checks for '#' at the beginning of the
38 first line of the input file. This is because the compiler outputs
39 #NO_APP at the beginning of its output. */
40 const char line_comment_chars
[] = "#";
41 const char line_separator_chars
[] = "!";
43 const char EXP_CHARS
[] = "eE";
44 const char FLT_CHARS
[] = "dD";
46 /* ELF flags to set in the output file header. */
47 static int elf_flags
= E_FLAG_RX_ABI
;
49 bfd_boolean rx_use_conventional_section_names
= FALSE
;
50 static bfd_boolean rx_use_small_data_limit
= FALSE
;
52 static bfd_boolean rx_pid_mode
= FALSE
;
53 static int rx_num_int_regs
= 0;
57 enum rx_cpu_types rx_cpu
= RX600
;
59 static void rx_fetchalign (int ignore ATTRIBUTE_UNUSED
);
63 OPTION_BIG
= OPTION_MD_BASE
,
67 OPTION_CONVENTIONAL_SECTION_NAMES
,
68 OPTION_RENESAS_SECTION_NAMES
,
69 OPTION_SMALL_DATA_LIMIT
,
76 OPTION_DISALLOW_STRING_INSNS
,
79 #define RX_SHORTOPTS ""
80 const char * md_shortopts
= RX_SHORTOPTS
;
82 /* Assembler options. */
83 struct option md_longopts
[] =
85 {"mbig-endian-data", no_argument
, NULL
, OPTION_BIG
},
86 {"mlittle-endian-data", no_argument
, NULL
, OPTION_LITTLE
},
87 /* The next two switches are here because the
88 generic parts of the linker testsuite uses them. */
89 {"EB", no_argument
, NULL
, OPTION_BIG
},
90 {"EL", no_argument
, NULL
, OPTION_LITTLE
},
91 {"m32bit-doubles", no_argument
, NULL
, OPTION_32BIT_DOUBLES
},
92 {"m64bit-doubles", no_argument
, NULL
, OPTION_64BIT_DOUBLES
},
93 /* This option is here mainly for the binutils testsuites,
94 as many of their tests assume conventional section naming. */
95 {"muse-conventional-section-names", no_argument
, NULL
, OPTION_CONVENTIONAL_SECTION_NAMES
},
96 {"muse-renesas-section-names", no_argument
, NULL
, OPTION_RENESAS_SECTION_NAMES
},
97 {"msmall-data-limit", no_argument
, NULL
, OPTION_SMALL_DATA_LIMIT
},
98 {"relax", no_argument
, NULL
, OPTION_RELAX
},
99 {"mpid", no_argument
, NULL
, OPTION_PID
},
100 {"mint-register", required_argument
, NULL
, OPTION_INT_REGS
},
101 {"mgcc-abi", no_argument
, NULL
, OPTION_USES_GCC_ABI
},
102 {"mrx-abi", no_argument
, NULL
, OPTION_USES_RX_ABI
},
103 {"mcpu", required_argument
, NULL
, OPTION_CPU
},
104 {"mno-allow-string-insns", no_argument
, NULL
, OPTION_DISALLOW_STRING_INSNS
},
105 {NULL
, no_argument
, NULL
, 0}
107 size_t md_longopts_size
= sizeof (md_longopts
);
111 const char *cpu_name
;
112 enum rx_cpu_types type
;
115 struct cpu_type cpu_type_list
[] =
125 md_parse_option (int c ATTRIBUTE_UNUSED
, const char * arg ATTRIBUTE_UNUSED
)
130 target_big_endian
= 1;
134 target_big_endian
= 0;
137 case OPTION_32BIT_DOUBLES
:
138 elf_flags
&= ~ E_FLAG_RX_64BIT_DOUBLES
;
141 case OPTION_64BIT_DOUBLES
:
142 elf_flags
|= E_FLAG_RX_64BIT_DOUBLES
;
145 case OPTION_CONVENTIONAL_SECTION_NAMES
:
146 rx_use_conventional_section_names
= TRUE
;
149 case OPTION_RENESAS_SECTION_NAMES
:
150 rx_use_conventional_section_names
= FALSE
;
153 case OPTION_SMALL_DATA_LIMIT
:
154 rx_use_small_data_limit
= TRUE
;
163 elf_flags
|= E_FLAG_RX_PID
;
166 case OPTION_INT_REGS
:
167 rx_num_int_regs
= atoi (optarg
);
170 case OPTION_USES_GCC_ABI
:
171 elf_flags
&= ~ E_FLAG_RX_ABI
;
174 case OPTION_USES_RX_ABI
:
175 elf_flags
|= E_FLAG_RX_ABI
;
181 for (i
= 0; i
< ARRAY_SIZE (cpu_type_list
); i
++)
183 if (strcasecmp (arg
, cpu_type_list
[i
].cpu_name
) == 0)
185 rx_cpu
= cpu_type_list
[i
].type
;
187 elf_flags
|= E_FLAG_RX_V2
;
191 as_warn (_("unrecognised RX CPU type %s"), arg
);
195 case OPTION_DISALLOW_STRING_INSNS
:
196 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
;
204 md_show_usage (FILE * stream
)
206 fprintf (stream
, _(" RX specific command line options:\n"));
207 fprintf (stream
, _(" --mbig-endian-data\n"));
208 fprintf (stream
, _(" --mlittle-endian-data [default]\n"));
209 fprintf (stream
, _(" --m32bit-doubles [default]\n"));
210 fprintf (stream
, _(" --m64bit-doubles\n"));
211 fprintf (stream
, _(" --muse-conventional-section-names\n"));
212 fprintf (stream
, _(" --muse-renesas-section-names [default]\n"));
213 fprintf (stream
, _(" --msmall-data-limit\n"));
214 fprintf (stream
, _(" --mrelax\n"));
215 fprintf (stream
, _(" --mpid\n"));
216 fprintf (stream
, _(" --mint-register=<value>\n"));
217 fprintf (stream
, _(" --mcpu=<rx100|rx200|rx600|rx610|rxv2>\n"));
218 fprintf (stream
, _(" --mno-allow-string-insns"));
222 s_bss (int ignore ATTRIBUTE_UNUSED
)
226 temp
= get_absolute_expression ();
227 subseg_set (bss_section
, (subsegT
) temp
);
228 demand_empty_rest_of_line ();
232 rx_float_cons (int ignore ATTRIBUTE_UNUSED
)
234 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
235 return float_cons ('d');
236 return float_cons ('f');
240 rx_strcasestr (const char *string
, const char *sub
)
246 return (char *)string
;
249 strl
= strlen (string
);
253 /* strncasecmp is in libiberty. */
254 if (strncasecmp (string
, sub
, subl
) == 0)
255 return (char *)string
;
264 rx_include (int ignore
)
269 const char * current_filename
;
277 /* The RX version of the .INCLUDE pseudo-op does not
278 have to have the filename inside double quotes. */
280 if (*input_line_pointer
== '"')
282 /* Treat as the normal GAS .include pseudo-op. */
287 /* Get the filename. Spaces are allowed, NUL characters are not. */
288 filename
= input_line_pointer
;
289 last_char
= find_end_of_line (filename
, FALSE
);
290 input_line_pointer
= last_char
;
292 while (last_char
>= filename
&& (* last_char
== ' ' || * last_char
== '\n'))
294 end_char
= *(++ last_char
);
296 if (last_char
== filename
)
298 as_bad (_("no filename following .INCLUDE pseudo-op"));
299 * last_char
= end_char
;
303 current_filename
= as_where (NULL
);
304 f
= XNEWVEC (char, strlen (current_filename
) + strlen (filename
) + 1);
306 /* Check the filename. If [@]..FILE[@] is found then replace
307 this with the current assembler source filename, stripped
308 of any directory prefixes or extensions. */
309 if ((p
= rx_strcasestr (filename
, "..file")) != NULL
)
313 len
= 6; /* strlen ("..file"); */
315 if (p
> filename
&& p
[-1] == '@')
321 for (d
= c
= current_filename
; *c
; c
++)
322 if (IS_DIR_SEPARATOR (* c
))
328 sprintf (f
, "%.*s%.*s%.*s", (int) (p
- filename
), filename
,
330 (int) (strlen (filename
) - ((p
+ len
) - filename
)),
334 strcpy (f
, filename
);
336 /* RX .INCLUDE semantics say that 'filename' is located by:
338 1. If filename is absolute, just try that. Otherwise...
340 2. If the current source file includes a directory component
341 then prepend that to the filename and try. Otherwise...
343 3. Try any directories specified by the -I command line
346 4 .Try a directory specifed by the INC100 environment variable. */
348 if (IS_ABSOLUTE_PATH (f
))
349 try = fopen (path
= f
, FOPEN_RT
);
352 char * env
= getenv ("INC100");
356 len
= strlen (current_filename
);
357 if ((size_t) include_dir_maxlen
> len
)
358 len
= include_dir_maxlen
;
359 if (env
&& strlen (env
) > len
)
362 path
= XNEWVEC (char, strlen (f
) + len
+ 5);
364 if (current_filename
!= NULL
)
366 for (d
= NULL
, p
= current_filename
; *p
; p
++)
367 if (IS_DIR_SEPARATOR (* p
))
372 sprintf (path
, "%.*s/%s", (int) (d
- current_filename
), current_filename
,
374 try = fopen (path
, FOPEN_RT
);
382 for (i
= 0; i
< include_dir_count
; i
++)
384 sprintf (path
, "%s/%s", include_dirs
[i
], f
);
385 if ((try = fopen (path
, FOPEN_RT
)) != NULL
)
390 if (try == NULL
&& env
!= NULL
)
392 sprintf (path
, "%s/%s", env
, f
);
393 try = fopen (path
, FOPEN_RT
);
401 as_bad (_("unable to locate include file: %s"), filename
);
407 register_dependency (path
);
408 input_scrub_insert_file (path
);
411 * last_char
= end_char
;
415 parse_rx_section (char * name
)
419 int attr
= SHF_ALLOC
| SHF_EXECINSTR
;
428 for (p
= input_line_pointer
; *p
&& strchr ("\n\t, =", *p
) == NULL
; p
++)
433 if (strcasecmp (input_line_pointer
, "ALIGN") == 0)
448 case '2': align
= 1; break;
449 case '4': align
= 2; break;
450 case '8': align
= 3; break;
452 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p
);
453 ignore_rest_of_line ();
461 else if (strcasecmp (input_line_pointer
, "CODE") == 0)
462 attr
= SHF_ALLOC
| SHF_EXECINSTR
;
463 else if (strcasecmp (input_line_pointer
, "DATA") == 0)
464 attr
= SHF_ALLOC
| SHF_WRITE
;
465 else if (strcasecmp (input_line_pointer
, "ROMDATA") == 0)
469 as_bad (_("unknown parameter following .SECTION directive: %s"),
473 input_line_pointer
= p
+ 1;
474 ignore_rest_of_line ();
479 input_line_pointer
= p
+ 1;
481 while (end_char
!= '\n' && end_char
!= 0);
483 if ((sec
= bfd_get_section_by_name (stdoutput
, name
)) == NULL
)
485 if (strcmp (name
, "B") && strcmp (name
, "B_1") && strcmp (name
, "B_2"))
490 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
492 else /* Try not to redefine a section, especially B_1. */
494 int flags
= sec
->flags
;
496 type
= elf_section_type (sec
);
498 attr
= ((flags
& SEC_READONLY
) ? 0 : SHF_WRITE
)
499 | ((flags
& SEC_ALLOC
) ? SHF_ALLOC
: 0)
500 | ((flags
& SEC_CODE
) ? SHF_EXECINSTR
: 0)
501 | ((flags
& SEC_MERGE
) ? SHF_MERGE
: 0)
502 | ((flags
& SEC_STRINGS
) ? SHF_STRINGS
: 0)
503 | ((flags
& SEC_THREAD_LOCAL
) ? SHF_TLS
: 0);
505 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
508 bfd_set_section_alignment (stdoutput
, now_seg
, align
);
512 rx_section (int ignore
)
516 /* The as100 assembler supports a different syntax for the .section
517 pseudo-op. So check for it and handle it here if necessary. */
520 /* Peek past the section name to see if arguments follow. */
521 for (p
= input_line_pointer
; *p
; p
++)
522 if (*p
== ',' || *p
== '\n')
527 int len
= p
- input_line_pointer
;
529 while (ISSPACE (*++p
))
532 if (*p
!= '"' && *p
!= '#')
534 char *name
= xmemdup0 (input_line_pointer
, len
);
536 input_line_pointer
= p
;
537 parse_rx_section (name
);
542 obj_elf_section (ignore
);
546 rx_list (int ignore ATTRIBUTE_UNUSED
)
550 if (strncasecmp (input_line_pointer
, "OFF", 3))
552 else if (strncasecmp (input_line_pointer
, "ON", 2))
555 as_warn (_("expecting either ON or OFF after .list"));
558 /* Like the .rept pseudo op, but supports the
559 use of ..MACREP inside the repeated region. */
562 rx_rept (int ignore ATTRIBUTE_UNUSED
)
564 int count
= get_absolute_expression ();
566 do_repeat_with_expander (count
, "MREPEAT", "ENDR", "..MACREP");
569 /* Like cons() accept that strings are allowed. */
576 if (* input_line_pointer
== '"')
583 rx_nop (int ignore ATTRIBUTE_UNUSED
)
585 ignore_rest_of_line ();
591 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
592 md_pseudo_table
[idx
].poc_name
);
593 ignore_rest_of_line ();
596 /* The target specific pseudo-ops which we support. */
597 const pseudo_typeS md_pseudo_table
[] =
599 /* These are unimplemented. They're listed first so that we can use
600 the poc_value as the index into this array, to get the name of
601 the pseudo. So, keep these (1) first, and (2) in order, with (3)
602 the poc_value's in sequence. */
603 { "btglb", rx_unimp
, 0 },
604 { "call", rx_unimp
, 1 },
605 { "einsf", rx_unimp
, 2 },
606 { "fb", rx_unimp
, 3 },
607 { "fbsym", rx_unimp
, 4 },
608 { "id", rx_unimp
, 5 },
609 { "initsct", rx_unimp
, 6 },
610 { "insf", rx_unimp
, 7 },
611 { "instr", rx_unimp
, 8 },
612 { "lbba", rx_unimp
, 9 },
613 { "len", rx_unimp
, 10 },
614 { "optj", rx_unimp
, 11 },
615 { "rvector", rx_unimp
, 12 },
616 { "sb", rx_unimp
, 13 },
617 { "sbbit", rx_unimp
, 14 },
618 { "sbsym", rx_unimp
, 15 },
619 { "sbsym16", rx_unimp
, 16 },
621 /* These are the do-nothing pseudos. */
622 { "stk", rx_nop
, 0 },
623 /* The manual documents ".stk" but the compiler emits ".stack". */
624 { "stack", rx_nop
, 0 },
626 /* These are Renesas as100 assembler pseudo-ops that we do support. */
627 { "addr", rx_cons
, 3 },
628 { "align", s_align_bytes
, 2 },
629 { "byte", rx_cons
, 1 },
630 { "fixed", float_cons
, 'f' },
631 { "form", listing_psize
, 0 },
632 { "glb", s_globl
, 0 },
633 { "include", rx_include
, 0 },
634 { "list", rx_list
, 0 },
635 { "lword", rx_cons
, 4 },
636 { "mrepeat", rx_rept
, 0 },
637 { "section", rx_section
, 0 },
639 /* FIXME: The following pseudo-ops place their values (and associated
640 label if present) in the data section, regardless of whatever
641 section we are currently in. At the moment this code does not
642 implement that part of the semantics. */
643 { "blka", s_space
, 3 },
644 { "blkb", s_space
, 1 },
645 { "blkd", s_space
, 8 },
646 { "blkf", s_space
, 4 },
647 { "blkl", s_space
, 4 },
648 { "blkw", s_space
, 2 },
650 /* Our "standard" pseudos. */
651 { "double", rx_float_cons
, 0 },
653 { "3byte", cons
, 3 },
657 { "fetchalign", rx_fetchalign
, 0 },
659 /* End of list marker. */
663 static asymbol
* gp_symbol
;
664 static asymbol
* rx_pid_symbol
;
666 static symbolS
* rx_pidreg_symbol
;
667 static symbolS
* rx_gpreg_symbol
;
672 /* Make the __gp and __pid_base symbols now rather
673 than after the symbol table is frozen. We only do this
674 when supporting small data limits because otherwise we
675 pollute the symbol table. */
677 /* The meta-registers %pidreg and %gpreg depend on what other
678 options are specified. The __rx_*_defined symbols exist so we
679 can .ifdef asm code based on what options were passed to gas,
680 without needing a preprocessor */
684 rx_pid_register
= 13 - rx_num_int_regs
;
685 rx_pid_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
686 rx_pidreg_symbol
= symbol_find_or_make ("__rx_pidreg_defined");
687 S_SET_VALUE (rx_pidreg_symbol
, rx_pid_register
);
688 S_SET_SEGMENT (rx_pidreg_symbol
, absolute_section
);
691 if (rx_use_small_data_limit
)
694 rx_gp_register
= rx_pid_register
- 1;
696 rx_gp_register
= 13 - rx_num_int_regs
;
697 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
698 rx_gpreg_symbol
= symbol_find_or_make ("__rx_gpreg_defined");
699 S_SET_VALUE (rx_gpreg_symbol
, rx_gp_register
);
700 S_SET_SEGMENT (rx_gpreg_symbol
, absolute_section
);
707 /* These negative numbers are found in rx_bytesT.n_base for non-opcode
709 #define RX_NBASE_FETCHALIGN -1
711 typedef struct rx_bytesT
714 /* If this is negative, it's a special-purpose frag as per the defines above. */
723 char type
; /* RXREL_*. */
736 fixS
*link_relax_fixP
;
741 static rx_bytesT rx_bytes
;
742 /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
743 static rx_bytesT
*fetchalign_bytes
= NULL
;
746 rx_fetchalign (int ignore ATTRIBUTE_UNUSED
)
751 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
752 rx_bytes
.n_base
= RX_NBASE_FETCHALIGN
;
754 bytes
= frag_more (8);
755 frag_then
= frag_now
;
756 frag_variant (rs_machine_dependent
,
763 frag_then
->fr_opcode
= bytes
;
764 frag_then
->fr_subtype
= 0;
765 fetchalign_bytes
= frag_then
->tc_frag_data
;
769 rx_relax (int type
, int pos
)
771 rx_bytes
.relax
[rx_bytes
.n_relax
].type
= type
;
772 rx_bytes
.relax
[rx_bytes
.n_relax
].field_pos
= pos
;
773 rx_bytes
.relax
[rx_bytes
.n_relax
].val_ofs
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
778 rx_linkrelax_dsp (int pos
)
783 rx_bytes
.link_relax
|= RX_RELAXA_DSP4
;
786 rx_bytes
.link_relax
|= RX_RELAXA_DSP6
;
789 rx_bytes
.link_relax
|= RX_RELAXA_DSP14
;
795 rx_linkrelax_imm (int pos
)
800 rx_bytes
.link_relax
|= RX_RELAXA_IMM6
;
803 rx_bytes
.link_relax
|= RX_RELAXA_IMM12
;
809 rx_linkrelax_branch (void)
811 rx_bytes
.link_relax
|= RX_RELAXA_BRA
;
815 rx_fixup (expressionS exp
, int offsetbits
, int nbits
, int type
)
817 rx_bytes
.fixups
[rx_bytes
.n_fixups
].exp
= exp
;
818 rx_bytes
.fixups
[rx_bytes
.n_fixups
].offset
= offsetbits
;
819 rx_bytes
.fixups
[rx_bytes
.n_fixups
].nbits
= nbits
;
820 rx_bytes
.fixups
[rx_bytes
.n_fixups
].type
= type
;
821 rx_bytes
.fixups
[rx_bytes
.n_fixups
].reloc
= exp
.X_md
;
822 rx_bytes
.n_fixups
++;
825 #define rx_field_fixup(exp, offset, nbits, type) \
826 rx_fixup (exp, offset, nbits, type)
828 #define rx_op_fixup(exp, offset, nbits, type) \
829 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
834 rx_bytes
.base
[0] = b1
;
839 rx_base2 (int b1
, int b2
)
841 rx_bytes
.base
[0] = b1
;
842 rx_bytes
.base
[1] = b2
;
847 rx_base3 (int b1
, int b2
, int b3
)
849 rx_bytes
.base
[0] = b1
;
850 rx_bytes
.base
[1] = b2
;
851 rx_bytes
.base
[2] = b3
;
856 rx_base4 (int b1
, int b2
, int b3
, int b4
)
858 rx_bytes
.base
[0] = b1
;
859 rx_bytes
.base
[1] = b2
;
860 rx_bytes
.base
[2] = b3
;
861 rx_bytes
.base
[3] = b4
;
865 /* This gets complicated when the field spans bytes, because fields
866 are numbered from the MSB of the first byte as zero, and bits are
867 stored LSB towards the LSB of the byte. Thus, a simple four-bit
868 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
869 insertion of b'MXL at position 7 is like this:
871 - - - - - - - - - - - - - - - -
875 rx_field (int val
, int pos
, int sz
)
882 if (val
< 0 || val
>= (1 << sz
))
883 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val
, sz
);
888 if (val
< -(1 << (sz
- 1)) || val
>= (1 << (sz
- 1)))
889 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val
, sz
);
892 /* This code points at 'M' in the above example. */
896 while (bitp
+ sz
> 8)
901 svalm
= val
>> (sz
- ssz
);
902 svalm
= svalm
& ((1 << ssz
) - 1);
903 svalm
= svalm
<< (8 - bitp
- ssz
);
904 gas_assert (bytep
< rx_bytes
.n_base
);
905 rx_bytes
.base
[bytep
] |= svalm
;
911 valm
= val
& ((1 << sz
) - 1);
912 valm
= valm
<< (8 - bitp
- sz
);
913 gas_assert (bytep
< rx_bytes
.n_base
);
914 rx_bytes
.base
[bytep
] |= valm
;
917 /* Special case of the above, for 3-bit displacements of 2..9. */
920 rx_disp3 (expressionS exp
, int pos
)
922 rx_field_fixup (exp
, pos
, 3, RXREL_PCREL
);
925 /* Special case of the above, for split 5-bit displacements. Assumes
926 the displacement has been checked with rx_disp5op. */
927 /* ---- -432 1--- 0--- */
930 rx_field5s (expressionS exp
)
934 val
= exp
.X_add_number
;
935 rx_bytes
.base
[0] |= val
>> 2;
936 rx_bytes
.base
[1] |= (val
<< 6) & 0x80;
937 rx_bytes
.base
[1] |= (val
<< 3) & 0x08;
940 /* ---- ---- 4--- 3210 */
943 rx_field5s2 (expressionS exp
)
947 val
= exp
.X_add_number
;
948 rx_bytes
.base
[1] |= (val
<< 3) & 0x80;
949 rx_bytes
.base
[1] |= (val
) & 0x0f;
952 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
954 #define F_PRECISION 2
957 rx_op (expressionS exp
, int nbytes
, int type
)
961 if ((exp
.X_op
== O_constant
|| exp
.X_op
== O_big
)
962 && type
!= RXREL_PCREL
)
964 if (exp
.X_op
== O_big
)
966 if (exp
.X_add_number
== -1)
969 char * ip
= rx_bytes
.ops
+ rx_bytes
.n_ops
;
971 gen_to_words (w
, F_PRECISION
, 8);
972 #if RX_OPCODE_BIG_ENDIAN
987 v
= ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
988 | (generic_bignum
[0] & LITTLENUM_MASK
);
992 v
= exp
.X_add_number
;
996 #if RX_OPCODE_BIG_ENDIAN
997 OP ((v
>> (8 * (nbytes
- 1))) & 0xff);
1007 rx_op_fixup (exp
, rx_bytes
.n_ops
* 8, nbytes
* 8, type
);
1008 memset (rx_bytes
.ops
+ rx_bytes
.n_ops
, 0, nbytes
);
1009 rx_bytes
.n_ops
+= nbytes
;
1019 #define APPEND(B, N_B) \
1022 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
1023 idx += rx_bytes.N_B; \
1027 rx_frag_init (fragS
* fragP
)
1029 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
|| rx_bytes
.n_base
< 0)
1031 fragP
->tc_frag_data
= XNEW (rx_bytesT
);
1032 memcpy (fragP
->tc_frag_data
, & rx_bytes
, sizeof (rx_bytesT
));
1035 fragP
->tc_frag_data
= 0;
1038 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
1039 <symbol_name> .equ <expression> */
1042 rx_equ (char * name
, char * expression
)
1044 char saved_name_end_char
;
1048 while (ISSPACE (* name
))
1051 for (name_end
= name
+ 1; *name_end
; name_end
++)
1052 if (! ISALNUM (* name_end
))
1055 saved_name_end_char
= * name_end
;
1058 saved_ilp
= input_line_pointer
;
1059 input_line_pointer
= expression
;
1063 input_line_pointer
= saved_ilp
;
1064 * name_end
= saved_name_end_char
;
1067 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
1068 rather than at the start of a line. (eg .EQU or .DEFINE). If one
1069 is found, process it and return TRUE otherwise return FALSE. */
1072 scan_for_infix_rx_pseudo_ops (char * str
)
1076 char * dot
= strchr (str
, '.');
1078 if (dot
== NULL
|| dot
== str
)
1081 /* A real pseudo-op must be preceeded by whitespace. */
1082 if (dot
[-1] != ' ' && dot
[-1] != '\t')
1085 pseudo_op
= dot
+ 1;
1087 if (!ISALNUM (* pseudo_op
))
1090 for (p
= pseudo_op
+ 1; ISALNUM (* p
); p
++)
1093 if (strncasecmp ("EQU", pseudo_op
, p
- pseudo_op
) == 0)
1095 else if (strncasecmp ("DEFINE", pseudo_op
, p
- pseudo_op
) == 0)
1096 as_warn (_("The .DEFINE pseudo-op is not implemented"));
1097 else if (strncasecmp ("MACRO", pseudo_op
, p
- pseudo_op
) == 0)
1098 as_warn (_("The .MACRO pseudo-op is not implemented"));
1099 else if (strncasecmp ("BTEQU", pseudo_op
, p
- pseudo_op
) == 0)
1100 as_warn (_("The .BTEQU pseudo-op is not implemented."));
1108 md_assemble (char * str
)
1113 fragS
* frag_then
= frag_now
;
1116 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
1118 rx_lex_init (str
, str
+ strlen (str
));
1119 if (scan_for_infix_rx_pseudo_ops (str
))
1123 /* This simplifies the relaxation code. */
1124 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
1126 /* We do it this way because we want the frag to have the
1127 rx_bytes in it, which we initialize above. */
1128 bytes
= frag_more (12);
1129 frag_then
= frag_now
;
1130 frag_variant (rs_machine_dependent
,
1137 frag_then
->fr_opcode
= bytes
;
1138 frag_then
->fr_fix
+= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
1139 frag_then
->fr_subtype
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
1143 bytes
= frag_more (rx_bytes
.n_base
+ rx_bytes
.n_ops
);
1144 frag_then
= frag_now
;
1145 if (fetchalign_bytes
)
1146 fetchalign_bytes
->n_ops
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
1149 fetchalign_bytes
= NULL
;
1151 APPEND (base
, n_base
);
1152 APPEND (ops
, n_ops
);
1154 if (rx_bytes
.link_relax
&& rx_bytes
.n_fixups
)
1158 f
= fix_new (frag_then
,
1159 (char *) bytes
- frag_then
->fr_literal
,
1162 rx_bytes
.link_relax
| rx_bytes
.n_fixups
,
1164 BFD_RELOC_RX_RELAX
);
1165 frag_then
->tc_frag_data
->link_relax_fixP
= f
;
1168 for (i
= 0; i
< rx_bytes
.n_fixups
; i
++)
1170 /* index: [nbytes][type] */
1171 static int reloc_map
[5][4] =
1173 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL
},
1174 { BFD_RELOC_8
, BFD_RELOC_RX_8U
, BFD_RELOC_RX_NEG8
, BFD_RELOC_8_PCREL
},
1175 { BFD_RELOC_RX_16_OP
, BFD_RELOC_RX_16U
, BFD_RELOC_RX_NEG16
, BFD_RELOC_16_PCREL
},
1176 { BFD_RELOC_RX_24_OP
, BFD_RELOC_RX_24U
, BFD_RELOC_RX_NEG24
, BFD_RELOC_24_PCREL
},
1177 { BFD_RELOC_RX_32_OP
, BFD_RELOC_32
, BFD_RELOC_RX_NEG32
, BFD_RELOC_32_PCREL
},
1181 idx
= rx_bytes
.fixups
[i
].offset
/ 8;
1182 rel
= reloc_map
[rx_bytes
.fixups
[i
].nbits
/ 8][(int) rx_bytes
.fixups
[i
].type
];
1184 if (rx_bytes
.fixups
[i
].reloc
)
1185 rel
= rx_bytes
.fixups
[i
].reloc
;
1187 if (frag_then
->tc_frag_data
)
1188 exp
= & frag_then
->tc_frag_data
->fixups
[i
].exp
;
1190 exp
= & rx_bytes
.fixups
[i
].exp
;
1192 f
= fix_new_exp (frag_then
,
1193 (char *) bytes
+ idx
- frag_then
->fr_literal
,
1194 rx_bytes
.fixups
[i
].nbits
/ 8,
1196 rx_bytes
.fixups
[i
].type
== RXREL_PCREL
? 1 : 0,
1198 if (frag_then
->tc_frag_data
)
1199 frag_then
->tc_frag_data
->fixups
[i
].fixP
= f
;
1202 dwarf2_emit_insn (idx
);
1210 /* Write a value out to the object file, using the appropriate endianness. */
1213 md_number_to_chars (char * buf
, valueT val
, int n
)
1215 if (target_big_endian
)
1216 number_to_chars_bigendian (buf
, val
, n
);
1218 number_to_chars_littleendian (buf
, val
, n
);
1228 { "gp", BFD_RELOC_GPREL16
},
1233 md_operand (expressionS
* exp ATTRIBUTE_UNUSED
)
1238 for (i
= 0; reloc_functions
[i
].fname
; i
++)
1240 int flen
= strlen (reloc_functions
[i
].fname
);
1242 if (input_line_pointer
[0] == '%'
1243 && strncasecmp (input_line_pointer
+ 1, reloc_functions
[i
].fname
, flen
) == 0
1244 && input_line_pointer
[flen
+ 1] == '(')
1246 reloc
= reloc_functions
[i
].reloc
;
1247 input_line_pointer
+= flen
+ 2;
1255 if (* input_line_pointer
== ')')
1256 input_line_pointer
++;
1262 md_section_align (segT segment
, valueT size
)
1264 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1265 return ((size
+ (1 << align
) - 1) & -(1 << align
));
1269 static unsigned char nop_1
[] = { 0x03};
1270 /* MOV.L R0,R0 - 1 cycle */
1271 static unsigned char nop_2
[] = { 0xef, 0x00};
1272 /* MAX R0,R0 - 1 cycle */
1273 static unsigned char nop_3
[] = { 0xfc, 0x13, 0x00 };
1274 /* MUL #1,R0 - 1 cycle */
1275 static unsigned char nop_4
[] = { 0x76, 0x10, 0x01, 0x00 };
1276 /* MUL #1,R0 - 1 cycle */
1277 static unsigned char nop_5
[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
1278 /* MUL #1,R0 - 1 cycle */
1279 static unsigned char nop_6
[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
1280 /* MAX 0x80000000,R0 - 1 cycle */
1281 static unsigned char nop_7
[] = { 0xFD, 0x70, 0x40, 0x00, 0x00, 0x00, 0x80 };
1283 static unsigned char *nops
[] = { NULL
, nop_1
, nop_2
, nop_3
, nop_4
, nop_5
, nop_6
, nop_7
};
1284 #define BIGGEST_NOP 7
1286 /* When relaxing, we need to output a reloc for any .align directive
1287 so that we can retain this alignment as we adjust opcode sizes. */
1289 rx_handle_align (fragS
* frag
)
1291 /* If handling an alignment frag, use an optimal NOP pattern.
1292 Only do this if a fill value has not already been provided.
1293 FIXME: This test fails if the provided fill value is zero. */
1294 if ((frag
->fr_type
== rs_align
1295 || frag
->fr_type
== rs_align_code
)
1296 && subseg_text_p (now_seg
))
1298 int count
= (frag
->fr_next
->fr_address
1301 unsigned char *base
= (unsigned char *)frag
->fr_literal
+ frag
->fr_fix
;
1305 if (count
> BIGGEST_NOP
)
1313 memcpy (base
, nops
[count
], count
);
1314 frag
->fr_var
= count
;
1320 && (frag
->fr_type
== rs_align
1321 || frag
->fr_type
== rs_align_code
)
1322 && frag
->fr_address
+ frag
->fr_fix
> 0
1323 && frag
->fr_offset
> 0
1324 && now_seg
!= bss_section
)
1326 fix_new (frag
, frag
->fr_fix
, 0,
1327 &abs_symbol
, RX_RELAXA_ALIGN
+ frag
->fr_offset
,
1328 0, BFD_RELOC_RX_RELAX
);
1329 /* For the purposes of relaxation, this relocation is attached
1330 to the byte *after* the alignment - i.e. the byte that must
1332 fix_new (frag
->fr_next
, 0, 0,
1333 &abs_symbol
, RX_RELAXA_ELIGN
+ frag
->fr_offset
,
1334 0, BFD_RELOC_RX_RELAX
);
1339 md_atof (int type
, char * litP
, int * sizeP
)
1341 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1345 md_undefined_symbol (char * name ATTRIBUTE_UNUSED
)
1350 /*----------------------------------------------------------------------*/
1351 /* To recap: we estimate everything based on md_estimate_size, then
1352 adjust based on rx_relax_frag. When it all settles, we call
1353 md_convert frag to update the bytes. The relaxation types and
1354 relocations are in fragP->tc_frag_data, which is a copy of that
1357 Our scheme is as follows: fr_fix has the size of the smallest
1358 opcode (like BRA.S). We store the number of total bytes we need in
1359 fr_subtype. When we're done relaxing, we use fr_subtype and the
1360 existing opcode bytes to figure out what actual opcode we need to
1361 put in there. If the fixup isn't resolvable now, we use the
1364 #define TRACE_RELAX 0
1365 #define tprintf if (TRACE_RELAX) printf
1377 /* We're looking for these types of relaxations:
1380 BRA.B 00101110 dspppppp
1381 BRA.W 00111000 dspppppp pppppppp
1382 BRA.A 00000100 dspppppp pppppppp pppppppp
1385 BEQ.B 00100000 dspppppp
1386 BEQ.W 00111010 dspppppp pppppppp
1389 BNE.B 00100001 dspppppp
1390 BNE.W 00111011 dspppppp pppppppp
1392 BSR.W 00111001 dspppppp pppppppp
1393 BSR.A 00000101 dspppppp pppppppp pppppppp
1395 Bcc.B 0010cond dspppppp
1397 Additionally, we can synthesize longer conditional branches using
1398 pairs of opcodes, one with an inverted conditional (flip LSB):
1400 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1401 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1402 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1403 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1405 /* Given the opcode bytes at OP, figure out which opcode it is and
1406 return the type of opcode. We use this to re-encode the opcode as
1407 a different size later. */
1410 rx_opcode_type (char * op
)
1412 unsigned char b
= (unsigned char) op
[0];
1416 case 0x08: return OT_bra
;
1417 case 0x10: return OT_beq
;
1418 case 0x18: return OT_bne
;
1423 case 0x2e: return OT_bra
;
1424 case 0x38: return OT_bra
;
1425 case 0x04: return OT_bra
;
1427 case 0x20: return OT_beq
;
1428 case 0x3a: return OT_beq
;
1430 case 0x21: return OT_bne
;
1431 case 0x3b: return OT_bne
;
1433 case 0x39: return OT_bsr
;
1434 case 0x05: return OT_bsr
;
1437 if ((b
& 0xf0) == 0x20)
1443 /* Returns zero if *addrP has the target address. Else returns nonzero
1444 if we cannot compute the target address yet. */
1447 rx_frag_fix_value (fragS
* fragP
,
1452 addressT
* sym_addr
)
1455 rx_bytesT
* b
= fragP
->tc_frag_data
;
1456 expressionS
* exp
= & b
->fixups
[which
].exp
;
1458 if (need_diff
&& exp
->X_op
!= O_subtract
)
1461 if (exp
->X_add_symbol
)
1463 if (S_FORCE_RELOC (exp
->X_add_symbol
, 1))
1465 if (S_GET_SEGMENT (exp
->X_add_symbol
) != segment
)
1467 addr
+= S_GET_VALUE (exp
->X_add_symbol
);
1470 if (exp
->X_op_symbol
)
1472 if (exp
->X_op
!= O_subtract
)
1474 if (S_FORCE_RELOC (exp
->X_op_symbol
, 1))
1476 if (S_GET_SEGMENT (exp
->X_op_symbol
) != segment
)
1478 addr
-= S_GET_VALUE (exp
->X_op_symbol
);
1482 addr
+= exp
->X_add_number
;
1487 /* Estimate how big the opcode is after this relax pass. The return
1488 value is the difference between fr_fix and the actual size. We
1489 compute the total size in rx_relax_frag and store it in fr_subtype,
1490 sowe only need to subtract fx_fix and return it. */
1493 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
, segT segment ATTRIBUTE_UNUSED
)
1498 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1499 (unsigned long) (fragP
->fr_address
1500 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1501 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1502 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1504 /* This is the size of the opcode that's accounted for in fr_fix. */
1505 opfixsize
= fragP
->fr_fix
- (fragP
->fr_opcode
- fragP
->fr_literal
);
1506 /* This is the size of the opcode that isn't. */
1507 delta
= (fragP
->fr_subtype
- opfixsize
);
1509 tprintf (" -> opfixsize %d delta %d\n", opfixsize
, delta
);
1513 /* Given a frag FRAGP, return the "next" frag that contains an
1514 opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
1517 rx_next_opcode (fragS
*fragP
)
1520 fragP
= fragP
->fr_next
;
1521 } while (fragP
&& fragP
->fr_type
!= rs_machine_dependent
);
1525 /* Given the new addresses for this relax pass, figure out how big
1526 each opcode must be. We store the total number of bytes needed in
1527 fr_subtype. The return value is the difference between the size
1528 after the last pass and the size after this pass, so we use the old
1529 fr_subtype to calculate the difference. */
1532 rx_relax_frag (segT segment ATTRIBUTE_UNUSED
, fragS
* fragP
, long stretch
)
1534 addressT addr0
, sym_addr
;
1537 int oldsize
= fragP
->fr_subtype
;
1538 int newsize
= oldsize
;
1540 /* Index of relaxation we care about. */
1543 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",
1544 (unsigned long) (fragP
->fr_address
1545 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1546 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1547 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
, stretch
);
1549 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1551 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1553 unsigned int next_size
;
1554 if (fragP
->fr_next
== NULL
)
1557 next_size
= fragP
->tc_frag_data
->n_ops
;
1560 fragS
*n
= rx_next_opcode (fragP
);
1561 next_size
= n
->fr_subtype
;
1564 fragP
->fr_subtype
= (8-(mypc
& 7)) & 7;
1565 tprintf("subtype %u\n", fragP
->fr_subtype
);
1566 if (fragP
->fr_subtype
>= next_size
)
1567 fragP
->fr_subtype
= 0;
1568 tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
1569 (unsigned long) (mypc
& 7),
1570 next_size
, fragP
->fr_subtype
, oldsize
, fragP
->fr_subtype
-oldsize
);
1572 newsize
= fragP
->fr_subtype
;
1574 return newsize
- oldsize
;
1577 optype
= rx_opcode_type (fragP
->fr_opcode
);
1579 /* In the one case where we have both a disp and imm relaxation, we want
1580 the imm relaxation here. */
1582 if (fragP
->tc_frag_data
->n_relax
> 1
1583 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1586 /* Try to get the target address. */
1587 if (rx_frag_fix_value (fragP
, segment
, ri
, & addr0
,
1588 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
,
1591 /* If we don't, we must use the maximum size for the linker.
1592 Note that we don't use synthetically expanded conditionals
1594 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1596 case RX_RELAX_BRANCH
:
1617 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
+ 4;
1620 fragP
->fr_subtype
= newsize
;
1621 tprintf (" -> new %d old %d delta %d (external)\n", newsize
, oldsize
, newsize
-oldsize
);
1622 return newsize
- oldsize
;
1625 if (sym_addr
> mypc
)
1628 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1630 case RX_RELAX_BRANCH
:
1631 tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
1632 (unsigned long) addr0
, (unsigned long) mypc
,
1633 (long) (addr0
- mypc
));
1634 disp
= (int) addr0
- (int) mypc
;
1639 if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1642 else if (disp
>= -32768 && (disp
- (oldsize
-5)) <= 32767)
1652 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1655 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1658 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1668 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1671 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1674 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1685 tprintf (" - newsize %d\n", newsize
);
1689 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
1690 (unsigned long) addr0
, (unsigned long) mypc
,
1691 fragP
->tc_frag_data
->relax
[ri
].field_pos
,
1692 fragP
->tc_frag_data
->relax
[ri
].val_ofs
);
1694 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1696 if ((long) addr0
>= -128 && (long) addr0
<= 127)
1698 else if ((long) addr0
>= -32768 && (long) addr0
<= 32767)
1700 else if ((long) addr0
>= -8388608 && (long) addr0
<= 8388607)
1710 if (fragP
->tc_frag_data
->relax
[ri
].type
== RX_RELAX_BRANCH
)
1726 /* This prevents infinite loops in align-heavy sources. */
1727 if (newsize
< oldsize
)
1729 if (fragP
->tc_frag_data
->times_shrank
> 10
1730 && fragP
->tc_frag_data
->times_grown
> 10)
1732 if (fragP
->tc_frag_data
->times_shrank
< 20)
1733 fragP
->tc_frag_data
->times_shrank
++;
1735 else if (newsize
> oldsize
)
1737 if (fragP
->tc_frag_data
->times_grown
< 20)
1738 fragP
->tc_frag_data
->times_grown
++;
1741 fragP
->fr_subtype
= newsize
;
1742 tprintf (" -> new %d old %d delta %d\n", newsize
, oldsize
, newsize
-oldsize
);
1743 return newsize
- oldsize
;
1746 /* This lets us test for the opcode type and the desired size in a
1747 switch statement. */
1748 #define OPCODE(type,size) ((type) * 16 + (size))
1750 /* Given the opcode stored in fr_opcode and the number of bytes we
1751 think we need, encode a new opcode. We stored a pointer to the
1752 fixup for this opcode in the tc_frag_data structure. If we can do
1753 the fixup here, we change the relocation type to "none" (we test
1754 for that in tc_gen_reloc) else we change it to the right type for
1755 the new (biggest) opcode. */
1758 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1759 segT segment ATTRIBUTE_UNUSED
,
1760 fragS
* fragP ATTRIBUTE_UNUSED
)
1762 rx_bytesT
* rxb
= fragP
->tc_frag_data
;
1763 addressT addr0
, mypc
;
1766 bfd_reloc_code_real_type reloc_type
;
1767 char * op
= fragP
->fr_opcode
;
1770 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1771 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1773 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1774 (unsigned long) (fragP
->fr_address
1775 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1776 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1777 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
,
1784 printf ("lit 0x%p opc 0x%p", fragP
->fr_literal
, fragP
->fr_opcode
);
1785 for (i
= 0; i
< 10; i
++)
1786 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1791 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1793 int count
= fragP
->fr_subtype
;
1796 else if (count
> BIGGEST_NOP
)
1803 memcpy (op
, nops
[count
], count
);
1807 /* In the one case where we have both a disp and imm relaxation, we want
1808 the imm relaxation here. */
1810 if (fragP
->tc_frag_data
->n_relax
> 1
1811 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1814 /* We used a new frag for this opcode, so the opcode address should
1815 be the frag address. */
1816 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1818 /* Try to get the target address. If we fail here, we just use the
1820 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1821 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1823 /* We don't know the target address. */
1830 /* We know the target address, and it's in addr0. */
1831 disp
= (int) addr0
- (int) mypc
;
1837 reloc_type
= BFD_RELOC_NONE
;
1840 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1841 rx_opcode_type (fragP
->fr_opcode
), disp
,
1842 (unsigned long) addr0
, (unsigned long) mypc
);
1843 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1845 case RX_RELAX_BRANCH
:
1846 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1848 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1849 op
[0] = 0x08 + (disp
& 7);
1851 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1854 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1857 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1859 #if RX_OPCODE_BIG_ENDIAN
1860 op
[1] = (disp
>> 8) & 0xff;
1863 op
[2] = (disp
>> 8) & 0xff;
1867 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1869 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1871 #if RX_OPCODE_BIG_ENDIAN
1872 op
[1] = (disp
>> 16) & 0xff;
1873 op
[2] = (disp
>> 8) & 0xff;
1876 op
[3] = (disp
>> 16) & 0xff;
1877 op
[2] = (disp
>> 8) & 0xff;
1880 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1884 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1885 op
[0] = 0x10 + (disp
& 7);
1887 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1891 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1893 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1895 #if RX_OPCODE_BIG_ENDIAN
1896 op
[1] = (disp
>> 8) & 0xff;
1899 op
[2] = (disp
>> 8) & 0xff;
1902 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1905 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1906 op
[0] = 0x1d; /* bne.s .+5. */
1907 op
[1] = 0x04; /* bra.a dsp:24. */
1909 #if RX_OPCODE_BIG_ENDIAN
1910 op
[2] = (disp
>> 16) & 0xff;
1911 op
[3] = (disp
>> 8) & 0xff;
1914 op
[4] = (disp
>> 16) & 0xff;
1915 op
[3] = (disp
>> 8) & 0xff;
1918 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1922 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1923 op
[0] = 0x18 + (disp
& 7);
1925 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1929 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1931 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1933 #if RX_OPCODE_BIG_ENDIAN
1934 op
[1] = (disp
>> 8) & 0xff;
1937 op
[2] = (disp
>> 8) & 0xff;
1940 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1943 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1944 op
[0] = 0x15; /* beq.s .+5. */
1945 op
[1] = 0x04; /* bra.a dsp:24. */
1947 #if RX_OPCODE_BIG_ENDIAN
1948 op
[2] = (disp
>> 16) & 0xff;
1949 op
[3] = (disp
>> 8) & 0xff;
1952 op
[4] = (disp
>> 16) & 0xff;
1953 op
[3] = (disp
>> 8) & 0xff;
1956 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1960 case OPCODE (OT_bsr
, 3): /* BSR.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_bsr
, 4): /* BSR.A - 24 bit. */
1974 #if RX_OPCODE_BIG_ENDIAN
1975 op
[1] = (disp
>> 16) & 0xff;
1976 op
[2] = (disp
>> 8) & 0xff;
1979 op
[3] = (disp
>> 16) & 0xff;
1980 op
[2] = (disp
>> 8) & 0xff;
1983 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1987 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
1989 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1991 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
1992 op
[0] ^= 1; /* Invert condition. */
1993 op
[1] = 5; /* Displacement. */
1996 #if RX_OPCODE_BIG_ENDIAN
1997 op
[3] = (disp
>> 8) & 0xff;
2000 op
[4] = (disp
>> 8) & 0xff;
2003 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2006 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
2007 op
[0] ^= 1; /* Invert condition. */
2008 op
[1] = 6; /* Displacement. */
2011 #if RX_OPCODE_BIG_ENDIAN
2012 op
[3] = (disp
>> 16) & 0xff;
2013 op
[4] = (disp
>> 8) & 0xff;
2016 op
[5] = (disp
>> 16) & 0xff;
2017 op
[4] = (disp
>> 8) & 0xff;
2020 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2025 /* These are opcodes we'll relax in th linker, later. */
2027 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
2034 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2036 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2043 reloc_type
= BFD_RELOC_8
;
2047 #if RX_OPCODE_BIG_ENDIAN
2049 imm
[0] = addr0
>> 8;
2052 imm
[1] = addr0
>> 8;
2054 reloc_type
= BFD_RELOC_RX_16_OP
;
2058 #if RX_OPCODE_BIG_ENDIAN
2060 imm
[1] = addr0
>> 8;
2061 imm
[0] = addr0
>> 16;
2064 imm
[1] = addr0
>> 8;
2065 imm
[2] = addr0
>> 16;
2067 reloc_type
= BFD_RELOC_RX_24_OP
;
2071 #if RX_OPCODE_BIG_ENDIAN
2073 imm
[2] = addr0
>> 8;
2074 imm
[1] = addr0
>> 16;
2075 imm
[0] = addr0
>> 24;
2078 imm
[1] = addr0
>> 8;
2079 imm
[2] = addr0
>> 16;
2080 imm
[3] = addr0
>> 24;
2082 reloc_type
= BFD_RELOC_RX_32_OP
;
2085 as_bad (_("invalid immediate size"));
2089 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
2104 as_bad (_("invalid immediate field position"));
2112 reloc_type
= fix
->fx_r_type
;
2121 fix
->fx_r_type
= reloc_type
;
2122 fix
->fx_where
+= reloc_adjust
;
2125 case BFD_RELOC_NONE
:
2131 case BFD_RELOC_16_PCREL
:
2132 case BFD_RELOC_RX_16_OP
:
2135 case BFD_RELOC_24_PCREL
:
2136 case BFD_RELOC_RX_24_OP
:
2139 case BFD_RELOC_RX_32_OP
:
2147 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
2148 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP
->fr_fix
,
2149 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
2152 if (fragP
->fr_next
!= NULL
2153 && ((offsetT
) (fragP
->fr_next
->fr_address
- fragP
->fr_address
)
2155 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
2156 (long) fragP
->fr_fix
,
2157 (long) fragP
->fr_address
, (long) fragP
->fr_next
->fr_address
);
2163 rx_validate_fix_sub (struct fix
* f
)
2165 /* We permit the subtraction of two symbols in a few cases. */
2166 /* mov #sym1-sym2, R3 */
2167 if (f
->fx_r_type
== BFD_RELOC_RX_32_OP
)
2169 /* .long sym1-sym2 */
2170 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
2172 && (f
->fx_size
== 4 || f
->fx_size
== 2 || f
->fx_size
== 1))
2178 md_pcrel_from_section (fixS
* fixP
, segT sec
)
2182 if (fixP
->fx_addsy
!= NULL
2183 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2184 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
2185 /* The symbol is undefined (or is defined but not in this section).
2186 Let the linker figure it out. */
2189 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2190 switch (fixP
->fx_r_type
)
2192 case BFD_RELOC_RX_DIR3U_PCREL
:
2200 rx_cons_fix_new (fragS
* frag
,
2204 bfd_reloc_code_real_type type
)
2212 type
= BFD_RELOC_16
;
2215 type
= BFD_RELOC_24
;
2218 type
= BFD_RELOC_32
;
2221 as_bad (_("unsupported constant size %d\n"), size
);
2225 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
2227 if (size
!= 4 && size
!= 2 && size
!= 1)
2228 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2230 type
= BFD_RELOC_RX_DIFF
;
2233 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
2237 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
2238 valueT
* t ATTRIBUTE_UNUSED
,
2239 segT s ATTRIBUTE_UNUSED
)
2241 /* Instruction bytes are always little endian. */
2245 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
2247 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
2250 #define OP2(x) op[target_big_endian ? 1-x : x]
2251 #define OP3(x) op[target_big_endian ? 2-x : x]
2252 #define OP4(x) op[target_big_endian ? 3-x : x]
2254 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
2255 val
= (unsigned long) * t
;
2257 /* Opcode words are always the same endian. Data words are either
2258 big or little endian. */
2260 switch (f
->fx_r_type
)
2262 case BFD_RELOC_NONE
:
2265 case BFD_RELOC_RX_RELAX
:
2269 case BFD_RELOC_RX_DIR3U_PCREL
:
2270 if (val
< 3 || val
> 10)
2271 as_bad_where (f
->fx_file
, f
->fx_line
,
2272 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2274 op
[0] |= val
& 0x07;
2278 case BFD_RELOC_8_PCREL
:
2279 case BFD_RELOC_RX_8U
:
2284 OP2(1) = val
& 0xff;
2285 OP2(0) = (val
>> 8) & 0xff;
2288 case BFD_RELOC_16_PCREL
:
2289 case BFD_RELOC_RX_16_OP
:
2290 case BFD_RELOC_RX_16U
:
2291 #if RX_OPCODE_BIG_ENDIAN
2293 op
[0] = (val
>> 8) & 0xff;
2296 op
[1] = (val
>> 8) & 0xff;
2301 OP3(0) = val
& 0xff;
2302 OP3(1) = (val
>> 8) & 0xff;
2303 OP3(2) = (val
>> 16) & 0xff;
2306 case BFD_RELOC_24_PCREL
:
2307 case BFD_RELOC_RX_24_OP
:
2308 case BFD_RELOC_RX_24U
:
2309 #if RX_OPCODE_BIG_ENDIAN
2311 op
[1] = (val
>> 8) & 0xff;
2312 op
[0] = (val
>> 16) & 0xff;
2315 op
[1] = (val
>> 8) & 0xff;
2316 op
[2] = (val
>> 16) & 0xff;
2320 case BFD_RELOC_RX_DIFF
:
2327 OP2(0) = val
& 0xff;
2328 OP2(1) = (val
>> 8) & 0xff;
2331 OP4(0) = val
& 0xff;
2332 OP4(1) = (val
>> 8) & 0xff;
2333 OP4(2) = (val
>> 16) & 0xff;
2334 OP4(3) = (val
>> 24) & 0xff;
2340 OP4(0) = val
& 0xff;
2341 OP4(1) = (val
>> 8) & 0xff;
2342 OP4(2) = (val
>> 16) & 0xff;
2343 OP4(3) = (val
>> 24) & 0xff;
2346 case BFD_RELOC_RX_32_OP
:
2347 #if RX_OPCODE_BIG_ENDIAN
2349 op
[2] = (val
>> 8) & 0xff;
2350 op
[1] = (val
>> 16) & 0xff;
2351 op
[0] = (val
>> 24) & 0xff;
2354 op
[1] = (val
>> 8) & 0xff;
2355 op
[2] = (val
>> 16) & 0xff;
2356 op
[3] = (val
>> 24) & 0xff;
2360 case BFD_RELOC_RX_NEG8
:
2364 case BFD_RELOC_RX_NEG16
:
2366 #if RX_OPCODE_BIG_ENDIAN
2368 op
[0] = (val
>> 8) & 0xff;
2371 op
[1] = (val
>> 8) & 0xff;
2375 case BFD_RELOC_RX_NEG24
:
2377 #if RX_OPCODE_BIG_ENDIAN
2379 op
[1] = (val
>> 8) & 0xff;
2380 op
[0] = (val
>> 16) & 0xff;
2383 op
[1] = (val
>> 8) & 0xff;
2384 op
[2] = (val
>> 16) & 0xff;
2388 case BFD_RELOC_RX_NEG32
:
2390 #if RX_OPCODE_BIG_ENDIAN
2392 op
[2] = (val
>> 8) & 0xff;
2393 op
[1] = (val
>> 16) & 0xff;
2394 op
[0] = (val
>> 24) & 0xff;
2397 op
[1] = (val
>> 8) & 0xff;
2398 op
[2] = (val
>> 16) & 0xff;
2399 op
[3] = (val
>> 24) & 0xff;
2403 case BFD_RELOC_RX_GPRELL
:
2405 case BFD_RELOC_RX_GPRELW
:
2407 case BFD_RELOC_RX_GPRELB
:
2408 #if RX_OPCODE_BIG_ENDIAN
2410 op
[0] = (val
>> 8) & 0xff;
2413 op
[1] = (val
>> 8) & 0xff;
2418 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2419 bfd_get_reloc_code_name (f
->fx_r_type
));
2423 if (f
->fx_addsy
== NULL
)
2428 tc_gen_reloc (asection
* sec ATTRIBUTE_UNUSED
, fixS
* fixp
)
2430 static arelent
* reloc
[5];
2431 bfd_boolean is_opcode
= FALSE
;
2433 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2440 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2442 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2443 fixp
->fx_subsy
= NULL
;
2446 reloc
[0] = XNEW (arelent
);
2447 reloc
[0]->sym_ptr_ptr
= XNEW (asymbol
*);
2448 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2449 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2450 reloc
[0]->addend
= fixp
->fx_offset
;
2452 if (fixp
->fx_r_type
== BFD_RELOC_RX_32_OP
2455 fixp
->fx_r_type
= BFD_RELOC_RX_DIFF
;
2459 is_opcode
= sec
->flags
& SEC_CODE
;
2461 /* Certain BFD relocations cannot be translated directly into
2462 a single (non-Red Hat) RX relocation, but instead need
2463 multiple RX relocations - handle them here. */
2464 switch (fixp
->fx_r_type
)
2466 case BFD_RELOC_RX_DIFF
:
2467 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2469 reloc
[1] = XNEW (arelent
);
2470 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2471 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2472 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2473 reloc
[1]->addend
= 0;
2474 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2476 reloc
[2] = XNEW (arelent
);
2477 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2478 reloc
[2]->addend
= 0;
2479 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2480 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2482 reloc
[3] = XNEW (arelent
);
2483 switch (fixp
->fx_size
)
2486 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2489 if (!is_opcode
&& target_big_endian
)
2490 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16_REV
);
2492 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2494 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2497 if (!is_opcode
&& target_big_endian
)
2498 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32_REV
);
2500 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2503 reloc
[3]->addend
= 0;
2504 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2505 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2510 case BFD_RELOC_RX_GPRELL
:
2511 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2513 reloc
[1] = XNEW (arelent
);
2514 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2515 if (gp_symbol
== NULL
)
2517 if (symbol_table_frozen
)
2521 gp
= symbol_find ("__gp");
2523 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2525 gp_symbol
= symbol_get_bfdsym (gp
);
2528 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2530 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2531 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2532 reloc
[1]->addend
= 0;
2533 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2535 reloc
[2] = XNEW (arelent
);
2536 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2537 reloc
[2]->addend
= 0;
2538 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2539 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2541 reloc
[3] = XNEW (arelent
);
2542 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2543 reloc
[3]->addend
= 0;
2544 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2545 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2550 case BFD_RELOC_RX_GPRELW
:
2551 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2553 reloc
[1] = XNEW (arelent
);
2554 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2555 if (gp_symbol
== NULL
)
2557 if (symbol_table_frozen
)
2561 gp
= symbol_find ("__gp");
2563 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2565 gp_symbol
= symbol_get_bfdsym (gp
);
2568 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2570 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2571 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2572 reloc
[1]->addend
= 0;
2573 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2575 reloc
[2] = XNEW (arelent
);
2576 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2577 reloc
[2]->addend
= 0;
2578 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2579 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2581 reloc
[3] = XNEW (arelent
);
2582 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2583 reloc
[3]->addend
= 0;
2584 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2585 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2590 case BFD_RELOC_RX_GPRELB
:
2591 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2593 reloc
[1] = XNEW (arelent
);
2594 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2595 if (gp_symbol
== NULL
)
2597 if (symbol_table_frozen
)
2601 gp
= symbol_find ("__gp");
2603 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2605 gp_symbol
= symbol_get_bfdsym (gp
);
2608 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2610 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2611 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2612 reloc
[1]->addend
= 0;
2613 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2615 reloc
[2] = XNEW (arelent
);
2616 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2617 reloc
[2]->addend
= 0;
2618 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2619 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2621 reloc
[3] = XNEW (arelent
);
2622 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2623 reloc
[3]->addend
= 0;
2624 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2625 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2630 case BFD_RELOC_RX_NEG32
:
2631 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2633 reloc
[1] = XNEW (arelent
);
2634 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_NEG
);
2635 reloc
[1]->addend
= 0;
2636 reloc
[1]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2637 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2639 reloc
[2] = XNEW (arelent
);
2640 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2641 reloc
[2]->addend
= 0;
2642 reloc
[2]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2643 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2649 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2658 rx_note_string_insn_use (void)
2660 if ((elf_flags
& E_FLAG_RX_SINSNS_MASK
) == (E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
))
2661 as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
2662 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_YES
;
2665 /* Set the ELF specific flags. */
2668 rx_elf_final_processing (void)
2670 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2673 /* Scan the current input line for occurances of Renesas
2674 local labels and replace them with the GAS version. */
2677 rx_start_line (void)
2679 int in_double_quote
= 0;
2680 int in_single_quote
= 0;
2682 char * p
= input_line_pointer
;
2684 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2695 in_double_quote
= ! in_double_quote
;
2699 in_single_quote
= ! in_single_quote
;
2703 if (in_double_quote
|| in_single_quote
)
2708 else if (p
[1] == '+')
2713 else if (p
[1] == '-')