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
;
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
= (char *) xmalloc (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
= (char *) xmalloc (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
;
1765 int reloc_type
, reloc_adjust
;
1766 char * op
= fragP
->fr_opcode
;
1769 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1770 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1772 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1773 (unsigned long) (fragP
->fr_address
1774 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1775 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1776 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
,
1783 printf ("lit 0x%p opc 0x%p", fragP
->fr_literal
, fragP
->fr_opcode
);
1784 for (i
= 0; i
< 10; i
++)
1785 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1790 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1792 int count
= fragP
->fr_subtype
;
1795 else if (count
> BIGGEST_NOP
)
1802 memcpy (op
, nops
[count
], count
);
1806 /* In the one case where we have both a disp and imm relaxation, we want
1807 the imm relaxation here. */
1809 if (fragP
->tc_frag_data
->n_relax
> 1
1810 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1813 /* We used a new frag for this opcode, so the opcode address should
1814 be the frag address. */
1815 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1817 /* Try to get the target address. If we fail here, we just use the
1819 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1820 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1822 /* We don't know the target address. */
1829 /* We know the target address, and it's in addr0. */
1830 disp
= (int) addr0
- (int) mypc
;
1836 reloc_type
= BFD_RELOC_NONE
;
1839 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1840 rx_opcode_type (fragP
->fr_opcode
), disp
,
1841 (unsigned long) addr0
, (unsigned long) mypc
);
1842 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1844 case RX_RELAX_BRANCH
:
1845 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1847 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1848 op
[0] = 0x08 + (disp
& 7);
1850 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1853 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1856 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1858 #if RX_OPCODE_BIG_ENDIAN
1859 op
[1] = (disp
>> 8) & 0xff;
1862 op
[2] = (disp
>> 8) & 0xff;
1866 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1868 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1870 #if RX_OPCODE_BIG_ENDIAN
1871 op
[1] = (disp
>> 16) & 0xff;
1872 op
[2] = (disp
>> 8) & 0xff;
1875 op
[3] = (disp
>> 16) & 0xff;
1876 op
[2] = (disp
>> 8) & 0xff;
1879 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1883 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1884 op
[0] = 0x10 + (disp
& 7);
1886 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1890 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1892 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1894 #if RX_OPCODE_BIG_ENDIAN
1895 op
[1] = (disp
>> 8) & 0xff;
1898 op
[2] = (disp
>> 8) & 0xff;
1901 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1904 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1905 op
[0] = 0x1d; /* bne.s .+5. */
1906 op
[1] = 0x04; /* bra.a dsp:24. */
1908 #if RX_OPCODE_BIG_ENDIAN
1909 op
[2] = (disp
>> 16) & 0xff;
1910 op
[3] = (disp
>> 8) & 0xff;
1913 op
[4] = (disp
>> 16) & 0xff;
1914 op
[3] = (disp
>> 8) & 0xff;
1917 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1921 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1922 op
[0] = 0x18 + (disp
& 7);
1924 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1928 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1930 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1932 #if RX_OPCODE_BIG_ENDIAN
1933 op
[1] = (disp
>> 8) & 0xff;
1936 op
[2] = (disp
>> 8) & 0xff;
1939 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1942 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1943 op
[0] = 0x15; /* beq.s .+5. */
1944 op
[1] = 0x04; /* bra.a dsp:24. */
1946 #if RX_OPCODE_BIG_ENDIAN
1947 op
[2] = (disp
>> 16) & 0xff;
1948 op
[3] = (disp
>> 8) & 0xff;
1951 op
[4] = (disp
>> 16) & 0xff;
1952 op
[3] = (disp
>> 8) & 0xff;
1955 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1959 case OPCODE (OT_bsr
, 3): /* BSR.W - 16 bit. */
1961 #if RX_OPCODE_BIG_ENDIAN
1962 op
[1] = (disp
>> 8) & 0xff;
1965 op
[2] = (disp
>> 8) & 0xff;
1968 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1971 case OPCODE (OT_bsr
, 4): /* BSR.A - 24 bit. */
1973 #if RX_OPCODE_BIG_ENDIAN
1974 op
[1] = (disp
>> 16) & 0xff;
1975 op
[2] = (disp
>> 8) & 0xff;
1978 op
[3] = (disp
>> 16) & 0xff;
1979 op
[2] = (disp
>> 8) & 0xff;
1982 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1986 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
1988 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1990 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
1991 op
[0] ^= 1; /* Invert condition. */
1992 op
[1] = 5; /* Displacement. */
1995 #if RX_OPCODE_BIG_ENDIAN
1996 op
[3] = (disp
>> 8) & 0xff;
1999 op
[4] = (disp
>> 8) & 0xff;
2002 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
2005 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
2006 op
[0] ^= 1; /* Invert condition. */
2007 op
[1] = 6; /* Displacement. */
2010 #if RX_OPCODE_BIG_ENDIAN
2011 op
[3] = (disp
>> 16) & 0xff;
2012 op
[4] = (disp
>> 8) & 0xff;
2015 op
[5] = (disp
>> 16) & 0xff;
2016 op
[4] = (disp
>> 8) & 0xff;
2019 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2024 /* These are opcodes we'll relax in th linker, later. */
2026 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
2033 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2035 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2042 reloc_type
= BFD_RELOC_8
;
2046 #if RX_OPCODE_BIG_ENDIAN
2048 imm
[0] = addr0
>> 8;
2051 imm
[1] = addr0
>> 8;
2053 reloc_type
= BFD_RELOC_RX_16_OP
;
2057 #if RX_OPCODE_BIG_ENDIAN
2059 imm
[1] = addr0
>> 8;
2060 imm
[0] = addr0
>> 16;
2063 imm
[1] = addr0
>> 8;
2064 imm
[2] = addr0
>> 16;
2066 reloc_type
= BFD_RELOC_RX_24_OP
;
2070 #if RX_OPCODE_BIG_ENDIAN
2072 imm
[2] = addr0
>> 8;
2073 imm
[1] = addr0
>> 16;
2074 imm
[0] = addr0
>> 24;
2077 imm
[1] = addr0
>> 8;
2078 imm
[2] = addr0
>> 16;
2079 imm
[3] = addr0
>> 24;
2081 reloc_type
= BFD_RELOC_RX_32_OP
;
2084 as_bad (_("invalid immediate size"));
2088 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
2103 as_bad (_("invalid immediate field position"));
2111 reloc_type
= fix
->fx_r_type
;
2120 fix
->fx_r_type
= reloc_type
;
2121 fix
->fx_where
+= reloc_adjust
;
2124 case BFD_RELOC_NONE
:
2130 case BFD_RELOC_16_PCREL
:
2131 case BFD_RELOC_RX_16_OP
:
2134 case BFD_RELOC_24_PCREL
:
2135 case BFD_RELOC_RX_24_OP
:
2138 case BFD_RELOC_RX_32_OP
:
2144 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
2145 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP
->fr_fix
,
2146 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
2149 if (fragP
->fr_next
!= NULL
2150 && ((offsetT
) (fragP
->fr_next
->fr_address
- fragP
->fr_address
)
2152 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
2153 (long) fragP
->fr_fix
,
2154 (long) fragP
->fr_address
, (long) fragP
->fr_next
->fr_address
);
2160 rx_validate_fix_sub (struct fix
* f
)
2162 /* We permit the subtraction of two symbols in a few cases. */
2163 /* mov #sym1-sym2, R3 */
2164 if (f
->fx_r_type
== BFD_RELOC_RX_32_OP
)
2166 /* .long sym1-sym2 */
2167 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
2169 && (f
->fx_size
== 4 || f
->fx_size
== 2 || f
->fx_size
== 1))
2175 md_pcrel_from_section (fixS
* fixP
, segT sec
)
2179 if (fixP
->fx_addsy
!= NULL
2180 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2181 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
2182 /* The symbol is undefined (or is defined but not in this section).
2183 Let the linker figure it out. */
2186 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2187 switch (fixP
->fx_r_type
)
2189 case BFD_RELOC_RX_DIR3U_PCREL
:
2197 rx_cons_fix_new (fragS
* frag
,
2201 bfd_reloc_code_real_type type
)
2209 type
= BFD_RELOC_16
;
2212 type
= BFD_RELOC_24
;
2215 type
= BFD_RELOC_32
;
2218 as_bad (_("unsupported constant size %d\n"), size
);
2222 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
2224 if (size
!= 4 && size
!= 2 && size
!= 1)
2225 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2227 type
= BFD_RELOC_RX_DIFF
;
2230 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
2234 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
2235 valueT
* t ATTRIBUTE_UNUSED
,
2236 segT s ATTRIBUTE_UNUSED
)
2238 /* Instruction bytes are always little endian. */
2242 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
2244 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
2247 #define OP2(x) op[target_big_endian ? 1-x : x]
2248 #define OP3(x) op[target_big_endian ? 2-x : x]
2249 #define OP4(x) op[target_big_endian ? 3-x : x]
2251 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
2252 val
= (unsigned long) * t
;
2254 /* Opcode words are always the same endian. Data words are either
2255 big or little endian. */
2257 switch (f
->fx_r_type
)
2259 case BFD_RELOC_NONE
:
2262 case BFD_RELOC_RX_RELAX
:
2266 case BFD_RELOC_RX_DIR3U_PCREL
:
2267 if (val
< 3 || val
> 10)
2268 as_bad_where (f
->fx_file
, f
->fx_line
,
2269 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2271 op
[0] |= val
& 0x07;
2275 case BFD_RELOC_8_PCREL
:
2276 case BFD_RELOC_RX_8U
:
2281 OP2(1) = val
& 0xff;
2282 OP2(0) = (val
>> 8) & 0xff;
2285 case BFD_RELOC_16_PCREL
:
2286 case BFD_RELOC_RX_16_OP
:
2287 case BFD_RELOC_RX_16U
:
2288 #if RX_OPCODE_BIG_ENDIAN
2290 op
[0] = (val
>> 8) & 0xff;
2293 op
[1] = (val
>> 8) & 0xff;
2298 OP3(0) = val
& 0xff;
2299 OP3(1) = (val
>> 8) & 0xff;
2300 OP3(2) = (val
>> 16) & 0xff;
2303 case BFD_RELOC_24_PCREL
:
2304 case BFD_RELOC_RX_24_OP
:
2305 case BFD_RELOC_RX_24U
:
2306 #if RX_OPCODE_BIG_ENDIAN
2308 op
[1] = (val
>> 8) & 0xff;
2309 op
[0] = (val
>> 16) & 0xff;
2312 op
[1] = (val
>> 8) & 0xff;
2313 op
[2] = (val
>> 16) & 0xff;
2317 case BFD_RELOC_RX_DIFF
:
2324 OP2(0) = val
& 0xff;
2325 OP2(1) = (val
>> 8) & 0xff;
2328 OP4(0) = val
& 0xff;
2329 OP4(1) = (val
>> 8) & 0xff;
2330 OP4(2) = (val
>> 16) & 0xff;
2331 OP4(3) = (val
>> 24) & 0xff;
2337 OP4(0) = val
& 0xff;
2338 OP4(1) = (val
>> 8) & 0xff;
2339 OP4(2) = (val
>> 16) & 0xff;
2340 OP4(3) = (val
>> 24) & 0xff;
2343 case BFD_RELOC_RX_32_OP
:
2344 #if RX_OPCODE_BIG_ENDIAN
2346 op
[2] = (val
>> 8) & 0xff;
2347 op
[1] = (val
>> 16) & 0xff;
2348 op
[0] = (val
>> 24) & 0xff;
2351 op
[1] = (val
>> 8) & 0xff;
2352 op
[2] = (val
>> 16) & 0xff;
2353 op
[3] = (val
>> 24) & 0xff;
2357 case BFD_RELOC_RX_NEG8
:
2361 case BFD_RELOC_RX_NEG16
:
2363 #if RX_OPCODE_BIG_ENDIAN
2365 op
[0] = (val
>> 8) & 0xff;
2368 op
[1] = (val
>> 8) & 0xff;
2372 case BFD_RELOC_RX_NEG24
:
2374 #if RX_OPCODE_BIG_ENDIAN
2376 op
[1] = (val
>> 8) & 0xff;
2377 op
[0] = (val
>> 16) & 0xff;
2380 op
[1] = (val
>> 8) & 0xff;
2381 op
[2] = (val
>> 16) & 0xff;
2385 case BFD_RELOC_RX_NEG32
:
2387 #if RX_OPCODE_BIG_ENDIAN
2389 op
[2] = (val
>> 8) & 0xff;
2390 op
[1] = (val
>> 16) & 0xff;
2391 op
[0] = (val
>> 24) & 0xff;
2394 op
[1] = (val
>> 8) & 0xff;
2395 op
[2] = (val
>> 16) & 0xff;
2396 op
[3] = (val
>> 24) & 0xff;
2400 case BFD_RELOC_RX_GPRELL
:
2402 case BFD_RELOC_RX_GPRELW
:
2404 case BFD_RELOC_RX_GPRELB
:
2405 #if RX_OPCODE_BIG_ENDIAN
2407 op
[0] = (val
>> 8) & 0xff;
2410 op
[1] = (val
>> 8) & 0xff;
2415 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2416 bfd_get_reloc_code_name (f
->fx_r_type
));
2420 if (f
->fx_addsy
== NULL
)
2425 tc_gen_reloc (asection
* sec ATTRIBUTE_UNUSED
, fixS
* fixp
)
2427 static arelent
* reloc
[5];
2428 bfd_boolean is_opcode
= FALSE
;
2430 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2437 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2439 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2440 fixp
->fx_subsy
= NULL
;
2443 reloc
[0] = XNEW (arelent
);
2444 reloc
[0]->sym_ptr_ptr
= XNEW (asymbol
*);
2445 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2446 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2447 reloc
[0]->addend
= fixp
->fx_offset
;
2449 if (fixp
->fx_r_type
== BFD_RELOC_RX_32_OP
2452 fixp
->fx_r_type
= BFD_RELOC_RX_DIFF
;
2456 is_opcode
= sec
->flags
& SEC_CODE
;
2458 /* Certain BFD relocations cannot be translated directly into
2459 a single (non-Red Hat) RX relocation, but instead need
2460 multiple RX relocations - handle them here. */
2461 switch (fixp
->fx_r_type
)
2463 case BFD_RELOC_RX_DIFF
:
2464 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2466 reloc
[1] = XNEW (arelent
);
2467 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2468 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2469 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2470 reloc
[1]->addend
= 0;
2471 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2473 reloc
[2] = XNEW (arelent
);
2474 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2475 reloc
[2]->addend
= 0;
2476 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2477 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2479 reloc
[3] = XNEW (arelent
);
2480 switch (fixp
->fx_size
)
2483 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2486 if (!is_opcode
&& target_big_endian
)
2487 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16_REV
);
2489 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2491 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2494 if (!is_opcode
&& target_big_endian
)
2495 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32_REV
);
2497 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2500 reloc
[3]->addend
= 0;
2501 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2502 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2507 case BFD_RELOC_RX_GPRELL
:
2508 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2510 reloc
[1] = XNEW (arelent
);
2511 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2512 if (gp_symbol
== NULL
)
2514 if (symbol_table_frozen
)
2518 gp
= symbol_find ("__gp");
2520 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2522 gp_symbol
= symbol_get_bfdsym (gp
);
2525 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2527 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2528 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2529 reloc
[1]->addend
= 0;
2530 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2532 reloc
[2] = XNEW (arelent
);
2533 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2534 reloc
[2]->addend
= 0;
2535 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2536 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2538 reloc
[3] = XNEW (arelent
);
2539 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2540 reloc
[3]->addend
= 0;
2541 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2542 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2547 case BFD_RELOC_RX_GPRELW
:
2548 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2550 reloc
[1] = XNEW (arelent
);
2551 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2552 if (gp_symbol
== NULL
)
2554 if (symbol_table_frozen
)
2558 gp
= symbol_find ("__gp");
2560 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2562 gp_symbol
= symbol_get_bfdsym (gp
);
2565 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2567 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2568 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2569 reloc
[1]->addend
= 0;
2570 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2572 reloc
[2] = XNEW (arelent
);
2573 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2574 reloc
[2]->addend
= 0;
2575 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2576 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2578 reloc
[3] = XNEW (arelent
);
2579 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2580 reloc
[3]->addend
= 0;
2581 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2582 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2587 case BFD_RELOC_RX_GPRELB
:
2588 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2590 reloc
[1] = XNEW (arelent
);
2591 reloc
[1]->sym_ptr_ptr
= XNEW (asymbol
*);
2592 if (gp_symbol
== NULL
)
2594 if (symbol_table_frozen
)
2598 gp
= symbol_find ("__gp");
2600 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2602 gp_symbol
= symbol_get_bfdsym (gp
);
2605 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2607 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2608 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2609 reloc
[1]->addend
= 0;
2610 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2612 reloc
[2] = XNEW (arelent
);
2613 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2614 reloc
[2]->addend
= 0;
2615 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2616 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2618 reloc
[3] = XNEW (arelent
);
2619 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2620 reloc
[3]->addend
= 0;
2621 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2622 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2627 case BFD_RELOC_RX_NEG32
:
2628 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2630 reloc
[1] = XNEW (arelent
);
2631 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_NEG
);
2632 reloc
[1]->addend
= 0;
2633 reloc
[1]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2634 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2636 reloc
[2] = XNEW (arelent
);
2637 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2638 reloc
[2]->addend
= 0;
2639 reloc
[2]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2640 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2646 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2655 rx_note_string_insn_use (void)
2657 if ((elf_flags
& E_FLAG_RX_SINSNS_MASK
) == (E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
))
2658 as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
2659 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_YES
;
2662 /* Set the ELF specific flags. */
2665 rx_elf_final_processing (void)
2667 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2670 /* Scan the current input line for occurances of Renesas
2671 local labels and replace them with the GAS version. */
2674 rx_start_line (void)
2676 int in_double_quote
= 0;
2677 int in_single_quote
= 0;
2679 char * p
= input_line_pointer
;
2681 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2692 in_double_quote
= ! in_double_quote
;
2696 in_single_quote
= ! in_single_quote
;
2700 if (in_double_quote
|| in_single_quote
)
2705 else if (p
[1] == '+')
2710 else if (p
[1] == '-')