1 /* tc-rx.c -- Assembler for the Renesas RX
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "struc-symbol.h"
25 #include "safe-ctype.h"
26 #include "dwarf2dbg.h"
28 #include "elf/common.h"
31 #include "filenames.h"
36 #define RX_OPCODE_BIG_ENDIAN 0
38 const char comment_chars
[] = ";";
39 /* Note that input_file.c hand checks for '#' at the beginning of the
40 first line of the input file. This is because the compiler outputs
41 #NO_APP at the beginning of its output. */
42 const char line_comment_chars
[] = "#";
43 const char line_separator_chars
[] = "!";
45 const char EXP_CHARS
[] = "eE";
46 const char FLT_CHARS
[] = "dD";
48 /* ELF flags to set in the output file header. */
49 static int elf_flags
= 0;
51 bfd_boolean rx_use_conventional_section_names
= FALSE
;
52 static bfd_boolean rx_use_small_data_limit
= FALSE
;
56 OPTION_BIG
= OPTION_MD_BASE
,
60 OPTION_CONVENTIONAL_SECTION_NAMES
,
61 OPTION_RENESAS_SECTION_NAMES
,
62 OPTION_SMALL_DATA_LIMIT
,
66 #define RX_SHORTOPTS ""
67 const char * md_shortopts
= RX_SHORTOPTS
;
69 /* Assembler options. */
70 struct option md_longopts
[] =
72 {"mbig-endian-data", no_argument
, NULL
, OPTION_BIG
},
73 {"mlittle-endian-data", no_argument
, NULL
, OPTION_LITTLE
},
74 /* The next two switches are here because the
75 generic parts of the linker testsuite uses them. */
76 {"EB", no_argument
, NULL
, OPTION_BIG
},
77 {"EL", no_argument
, NULL
, OPTION_LITTLE
},
78 {"m32bit-doubles", no_argument
, NULL
, OPTION_32BIT_DOUBLES
},
79 {"m64bit-doubles", no_argument
, NULL
, OPTION_64BIT_DOUBLES
},
80 /* This option is here mainly for the binutils testsuites,
81 as many of their tests assume conventional section naming. */
82 {"muse-conventional-section-names", no_argument
, NULL
, OPTION_CONVENTIONAL_SECTION_NAMES
},
83 {"muse-renesas-section-names", no_argument
, NULL
, OPTION_RENESAS_SECTION_NAMES
},
84 {"msmall-data-limit", no_argument
, NULL
, OPTION_SMALL_DATA_LIMIT
},
85 {"relax", no_argument
, NULL
, OPTION_RELAX
},
86 {NULL
, no_argument
, NULL
, 0}
88 size_t md_longopts_size
= sizeof (md_longopts
);
91 md_parse_option (int c ATTRIBUTE_UNUSED
, char * arg ATTRIBUTE_UNUSED
)
96 target_big_endian
= 1;
100 target_big_endian
= 0;
103 case OPTION_32BIT_DOUBLES
:
104 elf_flags
&= ~ E_FLAG_RX_64BIT_DOUBLES
;
107 case OPTION_64BIT_DOUBLES
:
108 elf_flags
|= E_FLAG_RX_64BIT_DOUBLES
;
111 case OPTION_CONVENTIONAL_SECTION_NAMES
:
112 rx_use_conventional_section_names
= TRUE
;
115 case OPTION_RENESAS_SECTION_NAMES
:
116 rx_use_conventional_section_names
= FALSE
;
119 case OPTION_SMALL_DATA_LIMIT
:
120 rx_use_small_data_limit
= TRUE
;
131 md_show_usage (FILE * stream
)
133 fprintf (stream
, _(" RX specific command line options:\n"));
134 fprintf (stream
, _(" --mbig-endian-data\n"));
135 fprintf (stream
, _(" --mlittle-endian-data [default]\n"));
136 fprintf (stream
, _(" --m32bit-doubles [default]\n"));
137 fprintf (stream
, _(" --m64bit-doubles\n"));
138 fprintf (stream
, _(" --muse-conventional-section-names\n"));
139 fprintf (stream
, _(" --muse-renesas-section-names [default]\n"));
140 fprintf (stream
, _(" --msmall-data-limit\n"));
144 s_bss (int ignore ATTRIBUTE_UNUSED
)
148 temp
= get_absolute_expression ();
149 subseg_set (bss_section
, (subsegT
) temp
);
150 demand_empty_rest_of_line ();
154 rx_float_cons (int ignore ATTRIBUTE_UNUSED
)
156 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
157 return float_cons ('d');
158 return float_cons ('f');
162 rx_strcasestr (const char *string
, const char *sub
)
168 return (char *)string
;
171 strl
= strlen (string
);
175 /* strncasecmp is in libiberty. */
176 if (strncasecmp (string
, sub
, subl
) == 0)
177 return (char *)string
;
186 rx_include (int ignore
)
191 char * current_filename
;
199 /* The RX version of the .INCLUDE pseudo-op does not
200 have to have the filename inside double quotes. */
202 if (*input_line_pointer
== '"')
204 /* Treat as the normal GAS .include pseudo-op. */
209 /* Get the filename. Spaces are allowed, NUL characters are not. */
210 filename
= input_line_pointer
;
211 eof
= find_end_of_line (filename
, FALSE
);
212 input_line_pointer
= eof
;
214 while (eof
>= filename
&& (* eof
== ' ' || * eof
== '\n'))
216 end_char
= *(++ eof
);
220 as_bad (_("no filename following .INCLUDE pseudo-op"));
225 as_where (& current_filename
, NULL
);
226 f
= (char *) xmalloc (strlen (current_filename
) + strlen (filename
) + 1);
228 /* Check the filename. If [@]..FILE[@] is found then replace
229 this with the current assembler source filename, stripped
230 of any directory prefixes or extensions. */
231 if ((p
= rx_strcasestr (filename
, "..file")) != NULL
)
235 len
= 6; /* strlen ("..file"); */
237 if (p
> filename
&& p
[-1] == '@')
243 for (d
= c
= current_filename
; *c
; c
++)
244 if (IS_DIR_SEPARATOR (* c
))
250 sprintf (f
, "%.*s%.*s%.*s", (int) (p
- filename
), filename
,
252 (int) (strlen (filename
) - ((p
+ len
) - filename
)),
256 strcpy (f
, filename
);
258 /* RX .INCLUDE semantics say that 'filename' is located by:
260 1. If filename is absolute, just try that. Otherwise...
262 2. If the current source file includes a directory component
263 then prepend that to the filename and try. Otherwise...
265 3. Try any directories specified by the -I command line
268 4 .Try a directory specifed by the INC100 environment variable. */
270 if (IS_ABSOLUTE_PATH (f
))
271 try = fopen (path
= f
, FOPEN_RT
);
274 char * env
= getenv ("INC100");
278 len
= strlen (current_filename
);
279 if ((size_t) include_dir_maxlen
> len
)
280 len
= include_dir_maxlen
;
281 if (env
&& strlen (env
) > len
)
284 path
= (char *) xmalloc (strlen (f
) + len
+ 5);
286 if (current_filename
!= NULL
)
288 for (d
= NULL
, p
= current_filename
; *p
; p
++)
289 if (IS_DIR_SEPARATOR (* p
))
294 sprintf (path
, "%.*s/%s", (int) (d
- current_filename
), current_filename
,
296 try = fopen (path
, FOPEN_RT
);
304 for (i
= 0; i
< include_dir_count
; i
++)
306 sprintf (path
, "%s/%s", include_dirs
[i
], f
);
307 if ((try = fopen (path
, FOPEN_RT
)) != NULL
)
312 if (try == NULL
&& env
!= NULL
)
314 sprintf (path
, "%s/%s", env
, f
);
315 try = fopen (path
, FOPEN_RT
);
323 as_bad (_("unable to locate include file: %s"), filename
);
329 register_dependency (path
);
330 input_scrub_insert_file (path
);
337 parse_rx_section (char * name
)
341 int attr
= SHF_ALLOC
| SHF_EXECINSTR
;
350 for (p
= input_line_pointer
; *p
&& strchr ("\n\t, =", *p
) == NULL
; p
++)
355 if (strcasecmp (input_line_pointer
, "ALIGN") == 0)
370 case '2': align
= 2; break;
371 case '4': align
= 4; break;
372 case '8': align
= 8; break;
374 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p
);
375 ignore_rest_of_line ();
383 else if (strcasecmp (input_line_pointer
, "CODE") == 0)
384 attr
= SHF_ALLOC
| SHF_EXECINSTR
;
385 else if (strcasecmp (input_line_pointer
, "DATA") == 0)
386 attr
= SHF_ALLOC
| SHF_WRITE
;
387 else if (strcasecmp (input_line_pointer
, "ROMDATA") == 0)
391 as_bad (_("unknown parameter following .SECTION directive: %s"),
395 input_line_pointer
= p
+ 1;
396 ignore_rest_of_line ();
401 input_line_pointer
= p
+ 1;
403 while (end_char
!= '\n' && end_char
!= 0);
405 if ((sec
= bfd_get_section_by_name (stdoutput
, name
)) == NULL
)
407 if (strcmp (name
, "B") && strcmp (name
, "B_1") && strcmp (name
, "B_2"))
412 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
414 else /* Try not to redefine a section, especially B_1. */
416 int flags
= sec
->flags
;
418 type
= elf_section_type (sec
);
420 attr
= ((flags
& SEC_READONLY
) ? 0 : SHF_WRITE
)
421 | ((flags
& SEC_ALLOC
) ? SHF_ALLOC
: 0)
422 | ((flags
& SEC_CODE
) ? SHF_EXECINSTR
: 0)
423 | ((flags
& SEC_MERGE
) ? SHF_MERGE
: 0)
424 | ((flags
& SEC_STRINGS
) ? SHF_STRINGS
: 0)
425 | ((flags
& SEC_THREAD_LOCAL
) ? SHF_TLS
: 0);
427 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
430 bfd_set_section_alignment (stdoutput
, now_seg
, align
);
434 rx_section (int ignore
)
438 /* The as100 assembler supports a different syntax for the .section
439 pseudo-op. So check for it and handle it here if necessary. */
442 /* Peek past the section name to see if arguments follow. */
443 for (p
= input_line_pointer
; *p
; p
++)
444 if (*p
== ',' || *p
== '\n')
449 int len
= p
- input_line_pointer
;
451 while (ISSPACE (*++p
))
454 if (*p
!= '"' && *p
!= '#')
456 char * name
= (char *) xmalloc (len
+ 1);
458 strncpy (name
, input_line_pointer
, len
);
461 input_line_pointer
= p
;
462 parse_rx_section (name
);
467 obj_elf_section (ignore
);
471 rx_list (int ignore ATTRIBUTE_UNUSED
)
475 if (strncasecmp (input_line_pointer
, "OFF", 3))
477 else if (strncasecmp (input_line_pointer
, "ON", 2))
480 as_warn (_("expecting either ON or OFF after .list"));
483 /* Like the .rept pseudo op, but supports the
484 use of ..MACREP inside the repeated region. */
487 rx_rept (int ignore ATTRIBUTE_UNUSED
)
489 int count
= get_absolute_expression ();
491 do_repeat_with_expander (count
, "MREPEAT", "ENDR", "..MACREP");
494 /* Like cons() accept that strings are allowed. */
501 if (* input_line_pointer
== '"')
508 rx_nop (int ignore ATTRIBUTE_UNUSED
)
510 ignore_rest_of_line ();
516 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
517 md_pseudo_table
[idx
].poc_name
);
518 ignore_rest_of_line ();
521 /* The target specific pseudo-ops which we support. */
522 const pseudo_typeS md_pseudo_table
[] =
524 /* These are unimplemented. They're listed first so that we can use
525 the poc_value as the index into this array, to get the name of
526 the pseudo. So, keep these (1) first, and (2) in order, with (3)
527 the poc_value's in sequence. */
528 { "btglb", rx_unimp
, 0 },
529 { "call", rx_unimp
, 1 },
530 { "einsf", rx_unimp
, 2 },
531 { "fb", rx_unimp
, 3 },
532 { "fbsym", rx_unimp
, 4 },
533 { "id", rx_unimp
, 5 },
534 { "initsct", rx_unimp
, 6 },
535 { "insf", rx_unimp
, 7 },
536 { "instr", rx_unimp
, 8 },
537 { "lbba", rx_unimp
, 9 },
538 { "len", rx_unimp
, 10 },
539 { "optj", rx_unimp
, 11 },
540 { "rvector", rx_unimp
, 12 },
541 { "sb", rx_unimp
, 13 },
542 { "sbbit", rx_unimp
, 14 },
543 { "sbsym", rx_unimp
, 15 },
544 { "sbsym16", rx_unimp
, 16 },
546 /* These are the do-nothing pseudos. */
547 { "stk", rx_nop
, 0 },
548 /* The manual documents ".stk" but the compiler emits ".stack". */
549 { "stack", rx_nop
, 0 },
551 /* Theae are Renesas as100 assembler pseudo-ops that we do support. */
552 { "addr", rx_cons
, 3 },
553 { "align", s_align_bytes
, 2 },
554 { "byte", rx_cons
, 1 },
555 { "fixed", float_cons
, 'f' },
556 { "form", listing_psize
, 0 },
557 { "glb", s_globl
, 0 },
558 { "include", rx_include
, 0 },
559 { "list", rx_list
, 0 },
560 { "lword", rx_cons
, 4 },
561 { "mrepeat", rx_rept
, 0 },
562 { "section", rx_section
, 0 },
564 /* FIXME: The following pseudo-ops place their values (and associated
565 label if present) in the data section, regardless of whatever
566 section we are currently in. At the moment this code does not
567 implement that part of the semantics. */
568 { "blka", s_space
, 3 },
569 { "blkb", s_space
, 1 },
570 { "blkd", s_space
, 8 },
571 { "blkf", s_space
, 4 },
572 { "blkl", s_space
, 4 },
573 { "blkw", s_space
, 2 },
575 /* Our "standard" pseudos. */
576 { "double", rx_float_cons
, 0 },
578 { "3byte", cons
, 3 },
582 /* End of list marker. */
586 static asymbol
* gp_symbol
;
591 if (rx_use_small_data_limit
)
592 /* Make the __gp symbol now rather
593 than after the symbol table is frozen. We only do this
594 when supporting small data limits because otherwise we
595 pollute the symbol table. */
596 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
602 typedef struct rx_bytesT
613 char type
; /* RXREL_*. */
626 fixS
*link_relax_fixP
;
631 static rx_bytesT rx_bytes
;
634 rx_relax (int type
, int pos
)
636 rx_bytes
.relax
[rx_bytes
.n_relax
].type
= type
;
637 rx_bytes
.relax
[rx_bytes
.n_relax
].field_pos
= pos
;
638 rx_bytes
.relax
[rx_bytes
.n_relax
].val_ofs
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
643 rx_linkrelax_dsp (int pos
)
648 rx_bytes
.link_relax
|= RX_RELAXA_DSP4
;
651 rx_bytes
.link_relax
|= RX_RELAXA_DSP6
;
654 rx_bytes
.link_relax
|= RX_RELAXA_DSP14
;
660 rx_linkrelax_imm (int pos
)
665 rx_bytes
.link_relax
|= RX_RELAXA_IMM6
;
668 rx_bytes
.link_relax
|= RX_RELAXA_IMM12
;
674 rx_linkrelax_branch (void)
676 rx_bytes
.link_relax
|= RX_RELAXA_BRA
;
680 rx_fixup (expressionS exp
, int offsetbits
, int nbits
, int type
)
682 rx_bytes
.fixups
[rx_bytes
.n_fixups
].exp
= exp
;
683 rx_bytes
.fixups
[rx_bytes
.n_fixups
].offset
= offsetbits
;
684 rx_bytes
.fixups
[rx_bytes
.n_fixups
].nbits
= nbits
;
685 rx_bytes
.fixups
[rx_bytes
.n_fixups
].type
= type
;
686 rx_bytes
.fixups
[rx_bytes
.n_fixups
].reloc
= exp
.X_md
;
687 rx_bytes
.n_fixups
++;
690 #define rx_field_fixup(exp, offset, nbits, type) \
691 rx_fixup (exp, offset, nbits, type)
693 #define rx_op_fixup(exp, offset, nbits, type) \
694 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
699 rx_bytes
.base
[0] = b1
;
704 rx_base2 (int b1
, int b2
)
706 rx_bytes
.base
[0] = b1
;
707 rx_bytes
.base
[1] = b2
;
712 rx_base3 (int b1
, int b2
, int b3
)
714 rx_bytes
.base
[0] = b1
;
715 rx_bytes
.base
[1] = b2
;
716 rx_bytes
.base
[2] = b3
;
721 rx_base4 (int b1
, int b2
, int b3
, int b4
)
723 rx_bytes
.base
[0] = b1
;
724 rx_bytes
.base
[1] = b2
;
725 rx_bytes
.base
[2] = b3
;
726 rx_bytes
.base
[3] = b4
;
730 /* This gets complicated when the field spans bytes, because fields
731 are numbered from the MSB of the first byte as zero, and bits are
732 stored LSB towards the LSB of the byte. Thus, a simple four-bit
733 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
734 insertion of b'MXL at position 7 is like this:
736 - - - - - - - - - - - - - - - -
740 rx_field (int val
, int pos
, int sz
)
747 if (val
< 0 || val
>= (1 << sz
))
748 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val
, sz
);
753 if (val
< -(1 << (sz
- 1)) || val
>= (1 << (sz
- 1)))
754 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val
, sz
);
757 /* This code points at 'M' in the above example. */
761 while (bitp
+ sz
> 8)
766 svalm
= val
>> (sz
- ssz
);
767 svalm
= svalm
& ((1 << ssz
) - 1);
768 svalm
= svalm
<< (8 - bitp
- ssz
);
769 gas_assert (bytep
< rx_bytes
.n_base
);
770 rx_bytes
.base
[bytep
] |= svalm
;
776 valm
= val
& ((1 << sz
) - 1);
777 valm
= valm
<< (8 - bitp
- sz
);
778 gas_assert (bytep
< rx_bytes
.n_base
);
779 rx_bytes
.base
[bytep
] |= valm
;
782 /* Special case of the above, for 3-bit displacements of 2..9. */
785 rx_disp3 (expressionS exp
, int pos
)
787 rx_field_fixup (exp
, pos
, 3, RXREL_PCREL
);
790 /* Special case of the above, for split 5-bit displacements. Assumes
791 the displacement has been checked with rx_disp5op. */
792 /* ---- -432 1--- 0--- */
795 rx_field5s (expressionS exp
)
799 val
= exp
.X_add_number
;
800 rx_bytes
.base
[0] |= val
>> 2;
801 rx_bytes
.base
[1] |= (val
<< 6) & 0x80;
802 rx_bytes
.base
[1] |= (val
<< 3) & 0x08;
805 /* ---- ---- 4--- 3210 */
808 rx_field5s2 (expressionS exp
)
812 val
= exp
.X_add_number
;
813 rx_bytes
.base
[1] |= (val
<< 3) & 0x80;
814 rx_bytes
.base
[1] |= (val
) & 0x0f;
817 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
819 #define F_PRECISION 2
822 rx_op (expressionS exp
, int nbytes
, int type
)
826 if ((exp
.X_op
== O_constant
|| exp
.X_op
== O_big
)
827 && type
!= RXREL_PCREL
)
829 if (exp
.X_op
== O_big
&& exp
.X_add_number
<= 0)
832 char * ip
= rx_bytes
.ops
+ rx_bytes
.n_ops
;
834 gen_to_words (w
, F_PRECISION
, 8);
835 #if RX_OPCODE_BIG_ENDIAN
850 v
= exp
.X_add_number
;
853 #if RX_OPCODE_BIG_ENDIAN
854 OP ((v
>> (8 * (nbytes
- 1))) & 0xff);
865 rx_op_fixup (exp
, rx_bytes
.n_ops
* 8, nbytes
* 8, type
);
866 memset (rx_bytes
.ops
+ rx_bytes
.n_ops
, 0, nbytes
);
867 rx_bytes
.n_ops
+= nbytes
;
877 #define APPEND(B, N_B) \
880 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
881 idx += rx_bytes.N_B; \
885 rx_frag_init (fragS
* fragP
)
887 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
889 fragP
->tc_frag_data
= malloc (sizeof (rx_bytesT
));
890 memcpy (fragP
->tc_frag_data
, & rx_bytes
, sizeof (rx_bytesT
));
893 fragP
->tc_frag_data
= 0;
896 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
897 <symbol_name> .equ <expression> */
900 rx_equ (char * name
, char * expression
)
902 char saved_name_end_char
;
906 while (ISSPACE (* name
))
909 for (name_end
= name
+ 1; *name_end
; name_end
++)
910 if (! ISALNUM (* name_end
))
913 saved_name_end_char
= * name_end
;
916 saved_ilp
= input_line_pointer
;
917 input_line_pointer
= expression
;
921 input_line_pointer
= saved_ilp
;
922 * name_end
= saved_name_end_char
;
925 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
926 rather than at the start of a line. (eg .EQU or .DEFINE). If one
927 is found, process it and return TRUE otherwise return FALSE. */
930 scan_for_infix_rx_pseudo_ops (char * str
)
934 char * dot
= strchr (str
, '.');
936 if (dot
== NULL
|| dot
== str
)
939 /* A real pseudo-op must be preceeded by whitespace. */
940 if (dot
[-1] != ' ' && dot
[-1] != '\t')
945 if (!ISALNUM (* pseudo_op
))
948 for (p
= pseudo_op
+ 1; ISALNUM (* p
); p
++)
951 if (strncasecmp ("EQU", pseudo_op
, p
- pseudo_op
) == 0)
953 else if (strncasecmp ("DEFINE", pseudo_op
, p
- pseudo_op
) == 0)
954 as_warn (_("The .DEFINE pseudo-op is not implemented"));
955 else if (strncasecmp ("MACRO", pseudo_op
, p
- pseudo_op
) == 0)
956 as_warn (_("The .MACRO pseudo-op is not implemented"));
957 else if (strncasecmp ("BTEQU", pseudo_op
, p
- pseudo_op
) == 0)
958 as_warn (_("The .BTEQU pseudo-op is not implemented."));
966 md_assemble (char * str
)
971 fragS
* frag_then
= frag_now
;
974 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
976 rx_lex_init (str
, str
+ strlen (str
));
977 if (scan_for_infix_rx_pseudo_ops (str
))
981 /* This simplifies the relaxation code. */
982 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
984 /* We do it this way because we want the frag to have the
985 rx_bytes in it, which we initialize above. */
986 bytes
= frag_more (12);
987 frag_then
= frag_now
;
988 frag_variant (rs_machine_dependent
,
995 frag_then
->fr_opcode
= bytes
;
996 frag_then
->fr_fix
+= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
997 frag_then
->fr_subtype
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
1001 bytes
= frag_more (rx_bytes
.n_base
+ rx_bytes
.n_ops
);
1002 frag_then
= frag_now
;
1005 APPEND (base
, n_base
);
1006 APPEND (ops
, n_ops
);
1008 if (rx_bytes
.link_relax
&& rx_bytes
.n_fixups
)
1012 f
= fix_new (frag_then
,
1013 (char *) bytes
- frag_then
->fr_literal
,
1016 rx_bytes
.link_relax
| rx_bytes
.n_fixups
,
1018 BFD_RELOC_RX_RELAX
);
1019 frag_then
->tc_frag_data
->link_relax_fixP
= f
;
1022 for (i
= 0; i
< rx_bytes
.n_fixups
; i
++)
1024 /* index: [nbytes][type] */
1025 static int reloc_map
[5][4] =
1027 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL
},
1028 { BFD_RELOC_8
, BFD_RELOC_RX_8U
, BFD_RELOC_RX_NEG8
, BFD_RELOC_8_PCREL
},
1029 { BFD_RELOC_RX_16_OP
, BFD_RELOC_RX_16U
, BFD_RELOC_RX_NEG16
, BFD_RELOC_16_PCREL
},
1030 { BFD_RELOC_RX_24_OP
, BFD_RELOC_RX_24U
, BFD_RELOC_RX_NEG24
, BFD_RELOC_24_PCREL
},
1031 { BFD_RELOC_RX_32_OP
, BFD_RELOC_32
, BFD_RELOC_RX_NEG32
, BFD_RELOC_32_PCREL
},
1035 idx
= rx_bytes
.fixups
[i
].offset
/ 8;
1036 rel
= reloc_map
[rx_bytes
.fixups
[i
].nbits
/ 8][(int) rx_bytes
.fixups
[i
].type
];
1038 if (rx_bytes
.fixups
[i
].reloc
)
1039 rel
= rx_bytes
.fixups
[i
].reloc
;
1041 if (frag_then
->tc_frag_data
)
1042 exp
= & frag_then
->tc_frag_data
->fixups
[i
].exp
;
1044 exp
= & rx_bytes
.fixups
[i
].exp
;
1046 f
= fix_new_exp (frag_then
,
1047 (char *) bytes
+ idx
- frag_then
->fr_literal
,
1048 rx_bytes
.fixups
[i
].nbits
/ 8,
1050 rx_bytes
.fixups
[i
].type
== RXREL_PCREL
? 1 : 0,
1052 if (frag_then
->tc_frag_data
)
1053 frag_then
->tc_frag_data
->fixups
[i
].fixP
= f
;
1056 dwarf2_emit_insn (idx
);
1064 /* Write a value out to the object file, using the appropriate endianness. */
1067 md_number_to_chars (char * buf
, valueT val
, int n
)
1069 if (target_big_endian
)
1070 number_to_chars_bigendian (buf
, val
, n
);
1072 number_to_chars_littleendian (buf
, val
, n
);
1082 { "gp", BFD_RELOC_GPREL16
},
1087 md_operand (expressionS
* exp ATTRIBUTE_UNUSED
)
1092 for (i
= 0; reloc_functions
[i
].fname
; i
++)
1094 int flen
= strlen (reloc_functions
[i
].fname
);
1096 if (input_line_pointer
[0] == '%'
1097 && strncasecmp (input_line_pointer
+ 1, reloc_functions
[i
].fname
, flen
) == 0
1098 && input_line_pointer
[flen
+ 1] == '(')
1100 reloc
= reloc_functions
[i
].reloc
;
1101 input_line_pointer
+= flen
+ 2;
1109 if (* input_line_pointer
== ')')
1110 input_line_pointer
++;
1116 md_section_align (segT segment
, valueT size
)
1118 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1119 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1122 /* When relaxing, we need to output a reloc for any .align directive
1123 so that we can retain this alignment as we adjust opcode sizes. */
1125 rx_handle_align (fragS
* frag
)
1128 && (frag
->fr_type
== rs_align
1129 || frag
->fr_type
== rs_align_code
)
1130 && frag
->fr_address
+ frag
->fr_fix
> 0
1131 && frag
->fr_offset
> 0
1132 && now_seg
!= bss_section
)
1134 fix_new (frag
, frag
->fr_fix
, 0,
1135 &abs_symbol
, RX_RELAXA_ALIGN
+ frag
->fr_offset
,
1136 0, BFD_RELOC_RX_RELAX
);
1137 /* For the purposes of relaxation, this relocation is attached
1138 to the byte *after* the alignment - i.e. the byte that must
1140 fix_new (frag
->fr_next
, 0, 0,
1141 &abs_symbol
, RX_RELAXA_ELIGN
+ frag
->fr_offset
,
1142 0, BFD_RELOC_RX_RELAX
);
1147 md_atof (int type
, char * litP
, int * sizeP
)
1149 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1153 md_undefined_symbol (char * name ATTRIBUTE_UNUSED
)
1158 /*----------------------------------------------------------------------*/
1159 /* To recap: we estimate everything based on md_estimate_size, then
1160 adjust based on rx_relax_frag. When it all settles, we call
1161 md_convert frag to update the bytes. The relaxation types and
1162 relocations are in fragP->tc_frag_data, which is a copy of that
1165 Our scheme is as follows: fr_fix has the size of the smallest
1166 opcode (like BRA.S). We store the number of total bytes we need in
1167 fr_subtype. When we're done relaxing, we use fr_subtype and the
1168 existing opcode bytes to figure out what actual opcode we need to
1169 put in there. If the fixup isn't resolvable now, we use the
1172 #define TRACE_RELAX 0
1173 #define tprintf if (TRACE_RELAX) printf
1185 /* We're looking for these types of relaxations:
1188 BRA.B 00101110 dspppppp
1189 BRA.W 00111000 dspppppp pppppppp
1190 BRA.A 00000100 dspppppp pppppppp pppppppp
1193 BEQ.B 00100000 dspppppp
1194 BEQ.W 00111010 dspppppp pppppppp
1197 BNE.B 00100001 dspppppp
1198 BNE.W 00111011 dspppppp pppppppp
1200 BSR.W 00111001 dspppppp pppppppp
1201 BSR.A 00000101 dspppppp pppppppp pppppppp
1203 Bcc.B 0010cond dspppppp
1205 Additionally, we can synthesize longer conditional branches using
1206 pairs of opcodes, one with an inverted conditional (flip LSB):
1208 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1209 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1210 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1211 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1213 /* Given the opcode bytes at OP, figure out which opcode it is and
1214 return the type of opcode. We use this to re-encode the opcode as
1215 a different size later. */
1218 rx_opcode_type (char * op
)
1220 unsigned char b
= (unsigned char) op
[0];
1224 case 0x08: return OT_bra
;
1225 case 0x10: return OT_beq
;
1226 case 0x18: return OT_bne
;
1231 case 0x2e: return OT_bra
;
1232 case 0x38: return OT_bra
;
1233 case 0x04: return OT_bra
;
1235 case 0x20: return OT_beq
;
1236 case 0x3a: return OT_beq
;
1238 case 0x21: return OT_bne
;
1239 case 0x3b: return OT_bne
;
1241 case 0x39: return OT_bsr
;
1242 case 0x05: return OT_bsr
;
1245 if ((b
& 0xf0) == 0x20)
1251 /* Returns zero if *addrP has the target address. Else returns nonzero
1252 if we cannot compute the target address yet. */
1255 rx_frag_fix_value (fragS
* fragP
,
1260 addressT
* sym_addr
)
1263 rx_bytesT
* b
= fragP
->tc_frag_data
;
1264 expressionS
* exp
= & b
->fixups
[which
].exp
;
1266 if (need_diff
&& exp
->X_op
!= O_subtract
)
1269 if (exp
->X_add_symbol
)
1271 if (S_FORCE_RELOC (exp
->X_add_symbol
, 1))
1273 if (S_GET_SEGMENT (exp
->X_add_symbol
) != segment
)
1275 addr
+= S_GET_VALUE (exp
->X_add_symbol
);
1278 if (exp
->X_op_symbol
)
1280 if (exp
->X_op
!= O_subtract
)
1282 if (S_FORCE_RELOC (exp
->X_op_symbol
, 1))
1284 if (S_GET_SEGMENT (exp
->X_op_symbol
) != segment
)
1286 addr
-= S_GET_VALUE (exp
->X_op_symbol
);
1290 addr
+= exp
->X_add_number
;
1295 /* Estimate how big the opcode is after this relax pass. The return
1296 value is the difference between fr_fix and the actual size. We
1297 compute the total size in rx_relax_frag and store it in fr_subtype,
1298 sowe only need to subtract fx_fix and return it. */
1301 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
, segT segment ATTRIBUTE_UNUSED
)
1306 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1307 fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
),
1308 fragP
->fr_fix
, fragP
->fr_var
, fragP
->fr_offset
,
1309 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1311 /* This is the size of the opcode that's accounted for in fr_fix. */
1312 opfixsize
= fragP
->fr_fix
- (fragP
->fr_opcode
- fragP
->fr_literal
);
1313 /* This is the size of the opcode that isn't. */
1314 delta
= (fragP
->fr_subtype
- opfixsize
);
1316 tprintf (" -> opfixsize %d delta %d\n", opfixsize
, delta
);
1320 /* Given the new addresses for this relax pass, figure out how big
1321 each opcode must be. We store the total number of bytes needed in
1322 fr_subtype. The return value is the difference between the size
1323 after the last pass and the size after this pass, so we use the old
1324 fr_subtype to calculate the difference. */
1327 rx_relax_frag (segT segment ATTRIBUTE_UNUSED
, fragS
* fragP
, long stretch
)
1329 addressT addr0
, sym_addr
;
1332 int oldsize
= fragP
->fr_subtype
;
1333 int newsize
= oldsize
;
1335 /* Index of relaxation we care about. */
1338 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",
1339 fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
),
1340 fragP
->fr_fix
, fragP
->fr_var
, fragP
->fr_offset
,
1341 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
, stretch
);
1343 optype
= rx_opcode_type (fragP
->fr_opcode
);
1345 /* In the one case where we have both a disp and imm relaxation, we want
1346 the imm relaxation here. */
1348 if (fragP
->tc_frag_data
->n_relax
> 1
1349 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1352 /* Try to get the target address. */
1353 if (rx_frag_fix_value (fragP
, segment
, ri
, & addr0
,
1354 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
,
1357 /* If we don't, we must use the maximum size for the linker.
1358 Note that we don't use synthetically expanded conditionals
1360 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1362 case RX_RELAX_BRANCH
:
1383 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
+ 4;
1386 fragP
->fr_subtype
= newsize
;
1387 tprintf (" -> new %d old %d delta %d (external)\n", newsize
, oldsize
, newsize
-oldsize
);
1388 return newsize
- oldsize
;
1391 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1392 if (sym_addr
> mypc
)
1395 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1397 case RX_RELAX_BRANCH
:
1398 tprintf ("branch, addr %08lx pc %08lx disp %ld\n", addr0
, mypc
, addr0
-mypc
);
1399 disp
= (int) addr0
- (int) mypc
;
1404 if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1407 else if (disp
>= -32768 && (disp
- (oldsize
-5)) <= 32767)
1417 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1420 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1423 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1433 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1436 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1439 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1450 tprintf (" - newsize %d\n", newsize
);
1454 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n", addr0
, mypc
,
1455 fragP
->tc_frag_data
->relax
[ri
].field_pos
,
1456 fragP
->tc_frag_data
->relax
[ri
].val_ofs
);
1458 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1460 if ((long) addr0
>= -128 && (long) addr0
<= 127)
1462 else if ((long) addr0
>= -32768 && (long) addr0
<= 32767)
1464 else if ((long) addr0
>= -8388608 && (long) addr0
<= 8388607)
1474 if (fragP
->tc_frag_data
->relax
[ri
].type
== RX_RELAX_BRANCH
)
1490 /* This prevents infinite loops in align-heavy sources. */
1491 if (newsize
< oldsize
)
1493 if (fragP
->tc_frag_data
->times_shrank
> 10
1494 && fragP
->tc_frag_data
->times_grown
> 10)
1496 if (fragP
->tc_frag_data
->times_shrank
< 20)
1497 fragP
->tc_frag_data
->times_shrank
++;
1499 else if (newsize
> oldsize
)
1501 if (fragP
->tc_frag_data
->times_grown
< 20)
1502 fragP
->tc_frag_data
->times_grown
++;
1505 fragP
->fr_subtype
= newsize
;
1506 tprintf (" -> new %d old %d delta %d\n", newsize
, oldsize
, newsize
-oldsize
);
1507 return newsize
- oldsize
;
1510 /* This lets us test for the opcode type and the desired size in a
1511 switch statement. */
1512 #define OPCODE(type,size) ((type) * 16 + (size))
1514 /* Given the opcode stored in fr_opcode and the number of bytes we
1515 think we need, encode a new opcode. We stored a pointer to the
1516 fixup for this opcode in the tc_frag_data structure. If we can do
1517 the fixup here, we change the relocation type to "none" (we test
1518 for that in tc_gen_reloc) else we change it to the right type for
1519 the new (biggest) opcode. */
1522 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1523 segT segment ATTRIBUTE_UNUSED
,
1524 fragS
* fragP ATTRIBUTE_UNUSED
)
1526 rx_bytesT
* rxb
= fragP
->tc_frag_data
;
1527 addressT addr0
, mypc
;
1529 int reloc_type
, reloc_adjust
;
1530 char * op
= fragP
->fr_opcode
;
1533 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1534 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1536 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1537 fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
),
1538 fragP
->fr_fix
, fragP
->fr_var
, fragP
->fr_offset
,
1539 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1545 printf ("lit %08x opc %08x", (int) fragP
->fr_literal
, (int) fragP
->fr_opcode
);
1546 for (i
= 0; i
< 10; i
++)
1547 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1552 /* In the one case where we have both a disp and imm relaxation, we want
1553 the imm relaxation here. */
1555 if (fragP
->tc_frag_data
->n_relax
> 1
1556 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1559 /* Try to get the target address. If we fail here, we just use the
1561 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1562 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1568 /* We used a new frag for this opcode, so the opcode address should
1569 be the frag address. */
1570 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1571 disp
= (int) addr0
- (int) mypc
;
1573 reloc_type
= BFD_RELOC_NONE
;
1576 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n", rx_opcode_type (fragP
->fr_opcode
), disp
, addr0
, mypc
);
1577 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1579 case RX_RELAX_BRANCH
:
1580 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1582 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1583 op
[0] = 0x08 + (disp
& 7);
1585 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1588 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1591 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1593 #if RX_OPCODE_BIG_ENDIAN
1594 op
[1] = (disp
>> 8) & 0xff;
1597 op
[2] = (disp
>> 8) & 0xff;
1601 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1603 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1605 #if RX_OPCODE_BIG_ENDIAN
1606 op
[1] = (disp
>> 16) & 0xff;
1607 op
[2] = (disp
>> 8) & 0xff;
1610 op
[3] = (disp
>> 16) & 0xff;
1611 op
[2] = (disp
>> 8) & 0xff;
1614 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1618 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1619 op
[0] = 0x10 + (disp
& 7);
1621 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1625 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1627 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1629 #if RX_OPCODE_BIG_ENDIAN
1630 op
[1] = (disp
>> 8) & 0xff;
1633 op
[2] = (disp
>> 8) & 0xff;
1636 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1639 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1640 op
[0] = 0x1e; /* bne.s .+4. */
1641 op
[1] = 0x04; /* bra.a dsp:24. */
1643 #if RX_OPCODE_BIG_ENDIAN
1644 op
[2] = (disp
>> 16) & 0xff;
1645 op
[3] = (disp
>> 8) & 0xff;
1648 op
[4] = (disp
>> 16) & 0xff;
1649 op
[3] = (disp
>> 8) & 0xff;
1652 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1656 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1657 op
[0] = 0x18 + (disp
& 7);
1659 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1663 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1665 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1667 #if RX_OPCODE_BIG_ENDIAN
1668 op
[1] = (disp
>> 8) & 0xff;
1671 op
[2] = (disp
>> 8) & 0xff;
1674 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1677 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1678 op
[0] = 0x15; /* beq.s .+4. */
1679 op
[1] = 0x04; /* bra.a dsp:24. */
1681 #if RX_OPCODE_BIG_ENDIAN
1682 op
[2] = (disp
>> 16) & 0xff;
1683 op
[3] = (disp
>> 8) & 0xff;
1686 op
[4] = (disp
>> 16) & 0xff;
1687 op
[3] = (disp
>> 8) & 0xff;
1690 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1694 case OPCODE (OT_bsr
, 3): /* BSR.W - 16 bit. */
1696 #if RX_OPCODE_BIG_ENDIAN
1697 op
[1] = (disp
>> 8) & 0xff;
1700 op
[2] = (disp
>> 8) & 0xff;
1703 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1706 case OPCODE (OT_bsr
, 4): /* BSR.A - 24 bit. */
1708 #if RX_OPCODE_BIG_ENDIAN
1709 op
[1] = (disp
>> 16) & 0xff;
1710 op
[2] = (disp
>> 8) & 0xff;
1713 op
[3] = (disp
>> 16) & 0xff;
1714 op
[2] = (disp
>> 8) & 0xff;
1717 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1721 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
1723 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1725 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
1726 op
[0] ^= 1; /* Invert condition. */
1727 op
[1] = 5; /* Displacement. */
1730 #if RX_OPCODE_BIG_ENDIAN
1731 op
[3] = (disp
>> 8) & 0xff;
1734 op
[4] = (disp
>> 8) & 0xff;
1737 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1740 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
1741 op
[0] ^= 1; /* Invert condition. */
1742 op
[1] = 6; /* Displacement. */
1745 #if RX_OPCODE_BIG_ENDIAN
1746 op
[3] = (disp
>> 16) & 0xff;
1747 op
[4] = (disp
>> 8) & 0xff;
1750 op
[5] = (disp
>> 16) & 0xff;
1751 op
[4] = (disp
>> 8) & 0xff;
1754 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1759 /* These are opcodes we'll relax in th linker, later. */
1761 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
1768 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1770 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1777 reloc_type
= BFD_RELOC_8
;
1781 #if RX_OPCODE_BIG_ENDIAN
1783 imm
[0] = addr0
>> 8;
1786 imm
[1] = addr0
>> 8;
1788 reloc_type
= BFD_RELOC_RX_16_OP
;
1792 #if RX_OPCODE_BIG_ENDIAN
1794 imm
[1] = addr0
>> 8;
1795 imm
[0] = addr0
>> 16;
1798 imm
[1] = addr0
>> 8;
1799 imm
[2] = addr0
>> 16;
1801 reloc_type
= BFD_RELOC_RX_24_OP
;
1805 #if RX_OPCODE_BIG_ENDIAN
1807 imm
[2] = addr0
>> 8;
1808 imm
[1] = addr0
>> 16;
1809 imm
[0] = addr0
>> 24;
1812 imm
[1] = addr0
>> 8;
1813 imm
[2] = addr0
>> 16;
1814 imm
[3] = addr0
>> 24;
1816 reloc_type
= BFD_RELOC_RX_32_OP
;
1819 as_bad (_("invalid immediate size"));
1823 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
1838 as_bad (_("invalid immediate field position"));
1846 reloc_type
= fix
->fx_r_type
;
1855 fix
->fx_r_type
= reloc_type
;
1856 fix
->fx_where
+= reloc_adjust
;
1859 case BFD_RELOC_NONE
:
1865 case BFD_RELOC_16_PCREL
:
1866 case BFD_RELOC_RX_16_OP
:
1869 case BFD_RELOC_24_PCREL
:
1870 case BFD_RELOC_RX_24_OP
:
1873 case BFD_RELOC_RX_32_OP
:
1879 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1880 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", fragP
->fr_fix
,
1881 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
1884 if (fragP
->fr_next
!= NULL
1885 && ((offsetT
) (fragP
->fr_next
->fr_address
- fragP
->fr_address
)
1887 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
1888 fragP
->fr_fix
, fragP
->fr_address
, fragP
->fr_next
->fr_address
);
1894 rx_validate_fix_sub (struct fix
* f
)
1896 /* We permit the subtraction of two symbols as a 32-bit relocation. */
1897 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
1905 md_pcrel_from_section (fixS
* fixP
, segT sec
)
1909 if (fixP
->fx_addsy
!= NULL
1910 && (! S_IS_DEFINED (fixP
->fx_addsy
)
1911 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
1912 /* The symbol is undefined (or is defined but not in this section).
1913 Let the linker figure it out. */
1916 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
1917 switch (fixP
->fx_r_type
)
1919 case BFD_RELOC_RX_DIR3U_PCREL
:
1927 rx_cons_fix_new (fragS
* frag
,
1932 bfd_reloc_code_real_type type
;
1940 type
= BFD_RELOC_16
;
1943 type
= BFD_RELOC_24
;
1946 type
= BFD_RELOC_32
;
1949 as_bad (_("unsupported constant size %d\n"), size
);
1953 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
1955 if (size
!= 4 && size
!= 2 && size
!= 1)
1956 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
1958 type
= BFD_RELOC_RX_DIFF
;
1961 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
1965 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
1966 valueT
* t ATTRIBUTE_UNUSED
,
1967 segT s ATTRIBUTE_UNUSED
)
1969 /* Instruction bytes are always little endian. */
1973 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
1975 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
1978 #define OP2(x) op[target_big_endian ? 1-x : x]
1979 #define OP3(x) op[target_big_endian ? 2-x : x]
1980 #define OP4(x) op[target_big_endian ? 3-x : x]
1982 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
1983 val
= (unsigned long) * t
;
1985 /* Opcode words are always the same endian. Data words are either
1986 big or little endian. */
1988 switch (f
->fx_r_type
)
1990 case BFD_RELOC_NONE
:
1993 case BFD_RELOC_RX_RELAX
:
1997 case BFD_RELOC_RX_DIR3U_PCREL
:
1998 if (val
< 3 || val
> 10)
1999 as_bad_where (f
->fx_file
, f
->fx_line
,
2000 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2002 op
[0] |= val
& 0x07;
2006 case BFD_RELOC_8_PCREL
:
2007 case BFD_RELOC_RX_8U
:
2012 OP2(1) = val
& 0xff;
2013 OP2(0) = (val
>> 8) & 0xff;
2016 case BFD_RELOC_16_PCREL
:
2017 case BFD_RELOC_RX_16_OP
:
2018 case BFD_RELOC_RX_16U
:
2019 #if RX_OPCODE_BIG_ENDIAN
2021 op
[0] = (val
>> 8) & 0xff;
2024 op
[1] = (val
>> 8) & 0xff;
2029 OP3(0) = val
& 0xff;
2030 OP3(1) = (val
>> 8) & 0xff;
2031 OP3(2) = (val
>> 16) & 0xff;
2034 case BFD_RELOC_24_PCREL
:
2035 case BFD_RELOC_RX_24_OP
:
2036 case BFD_RELOC_RX_24U
:
2037 #if RX_OPCODE_BIG_ENDIAN
2039 op
[1] = (val
>> 8) & 0xff;
2040 op
[0] = (val
>> 16) & 0xff;
2043 op
[1] = (val
>> 8) & 0xff;
2044 op
[2] = (val
>> 16) & 0xff;
2048 case BFD_RELOC_RX_DIFF
:
2055 OP2(0) = val
& 0xff;
2056 OP2(1) = (val
>> 8) & 0xff;
2059 OP4(0) = val
& 0xff;
2060 OP4(1) = (val
>> 8) & 0xff;
2061 OP4(2) = (val
>> 16) & 0xff;
2062 OP4(3) = (val
>> 24) & 0xff;
2068 OP4(0) = val
& 0xff;
2069 OP4(1) = (val
>> 8) & 0xff;
2070 OP4(2) = (val
>> 16) & 0xff;
2071 OP4(3) = (val
>> 24) & 0xff;
2074 case BFD_RELOC_RX_32_OP
:
2075 #if RX_OPCODE_BIG_ENDIAN
2077 op
[2] = (val
>> 8) & 0xff;
2078 op
[1] = (val
>> 16) & 0xff;
2079 op
[0] = (val
>> 24) & 0xff;
2082 op
[1] = (val
>> 8) & 0xff;
2083 op
[2] = (val
>> 16) & 0xff;
2084 op
[3] = (val
>> 24) & 0xff;
2088 case BFD_RELOC_RX_NEG8
:
2092 case BFD_RELOC_RX_NEG16
:
2094 #if RX_OPCODE_BIG_ENDIAN
2096 op
[0] = (val
>> 8) & 0xff;
2099 op
[1] = (val
>> 8) & 0xff;
2103 case BFD_RELOC_RX_NEG24
:
2105 #if RX_OPCODE_BIG_ENDIAN
2107 op
[1] = (val
>> 8) & 0xff;
2108 op
[0] = (val
>> 16) & 0xff;
2111 op
[1] = (val
>> 8) & 0xff;
2112 op
[2] = (val
>> 16) & 0xff;
2116 case BFD_RELOC_RX_NEG32
:
2118 #if RX_OPCODE_BIG_ENDIAN
2120 op
[2] = (val
>> 8) & 0xff;
2121 op
[1] = (val
>> 16) & 0xff;
2122 op
[0] = (val
>> 24) & 0xff;
2125 op
[1] = (val
>> 8) & 0xff;
2126 op
[2] = (val
>> 16) & 0xff;
2127 op
[3] = (val
>> 24) & 0xff;
2131 case BFD_RELOC_RX_GPRELL
:
2133 case BFD_RELOC_RX_GPRELW
:
2135 case BFD_RELOC_RX_GPRELB
:
2136 #if RX_OPCODE_BIG_ENDIAN
2138 op
[0] = (val
>> 8) & 0xff;
2141 op
[1] = (val
>> 8) & 0xff;
2146 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2147 bfd_get_reloc_code_name (f
->fx_r_type
));
2151 if (f
->fx_addsy
== NULL
)
2156 tc_gen_reloc (asection
* seg ATTRIBUTE_UNUSED
, fixS
* fixp
)
2158 static arelent
* reloc
[5];
2160 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2167 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2169 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2170 fixp
->fx_subsy
= NULL
;
2173 reloc
[0] = (arelent
*) xmalloc (sizeof (arelent
));
2174 reloc
[0]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2175 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2176 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2177 reloc
[0]->addend
= fixp
->fx_offset
;
2179 /* Certain BFD relocations cannot be translated directly into
2180 a single (non-Red Hat) RX relocation, but instead need
2181 multiple RX relocations - handle them here. */
2182 switch (fixp
->fx_r_type
)
2184 case BFD_RELOC_RX_DIFF
:
2185 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2187 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2188 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2189 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2190 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2191 reloc
[1]->addend
= 0;
2192 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2194 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2195 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2196 reloc
[2]->addend
= 0;
2197 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2198 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2200 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2201 switch (fixp
->fx_size
)
2204 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2207 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2210 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2213 reloc
[3]->addend
= 0;
2214 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2215 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2220 case BFD_RELOC_RX_GPRELL
:
2221 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2223 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2224 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2225 if (gp_symbol
== NULL
)
2227 if (symbol_table_frozen
)
2231 gp
= symbol_find ("__gp");
2233 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2235 gp_symbol
= symbol_get_bfdsym (gp
);
2238 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2240 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2241 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2242 reloc
[1]->addend
= 0;
2243 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2245 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2246 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2247 reloc
[2]->addend
= 0;
2248 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2249 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2251 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2252 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2253 reloc
[3]->addend
= 0;
2254 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2255 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2260 case BFD_RELOC_RX_GPRELW
:
2261 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2263 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2264 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2265 if (gp_symbol
== NULL
)
2267 if (symbol_table_frozen
)
2271 gp
= symbol_find ("__gp");
2273 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2275 gp_symbol
= symbol_get_bfdsym (gp
);
2278 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2280 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2281 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2282 reloc
[1]->addend
= 0;
2283 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2285 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2286 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2287 reloc
[2]->addend
= 0;
2288 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2289 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2291 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2292 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2293 reloc
[3]->addend
= 0;
2294 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2295 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2300 case BFD_RELOC_RX_GPRELB
:
2301 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2303 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2304 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2305 if (gp_symbol
== NULL
)
2307 if (symbol_table_frozen
)
2311 gp
= symbol_find ("__gp");
2313 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2315 gp_symbol
= symbol_get_bfdsym (gp
);
2318 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2320 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2321 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2322 reloc
[1]->addend
= 0;
2323 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2325 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2326 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2327 reloc
[2]->addend
= 0;
2328 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2329 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2331 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2332 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2333 reloc
[3]->addend
= 0;
2334 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2335 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2341 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2349 /* Set the ELF specific flags. */
2352 rx_elf_final_processing (void)
2354 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2357 /* Scan the current input line for occurances of Renesas
2358 local labels and replace them with the GAS version. */
2361 rx_start_line (void)
2363 int in_double_quote
= 0;
2364 int in_single_quote
= 0;
2366 char * p
= input_line_pointer
;
2368 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2379 in_double_quote
= ! in_double_quote
;
2383 in_single_quote
= ! in_single_quote
;
2387 if (in_double_quote
|| in_single_quote
)
2392 else if (p
[1] == '+')
2397 else if (p
[1] == '-')