1 /* tc-rx.c -- Assembler for the Renesas RX
2 Copyright (C) 2008-2015 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
);
110 md_parse_option (int c ATTRIBUTE_UNUSED
, char * arg ATTRIBUTE_UNUSED
)
115 target_big_endian
= 1;
119 target_big_endian
= 0;
122 case OPTION_32BIT_DOUBLES
:
123 elf_flags
&= ~ E_FLAG_RX_64BIT_DOUBLES
;
126 case OPTION_64BIT_DOUBLES
:
127 elf_flags
|= E_FLAG_RX_64BIT_DOUBLES
;
130 case OPTION_CONVENTIONAL_SECTION_NAMES
:
131 rx_use_conventional_section_names
= TRUE
;
134 case OPTION_RENESAS_SECTION_NAMES
:
135 rx_use_conventional_section_names
= FALSE
;
138 case OPTION_SMALL_DATA_LIMIT
:
139 rx_use_small_data_limit
= TRUE
;
148 elf_flags
|= E_FLAG_RX_PID
;
151 case OPTION_INT_REGS
:
152 rx_num_int_regs
= atoi (optarg
);
155 case OPTION_USES_GCC_ABI
:
156 elf_flags
&= ~ E_FLAG_RX_ABI
;
159 case OPTION_USES_RX_ABI
:
160 elf_flags
|= E_FLAG_RX_ABI
;
164 if (strcasecmp (arg
, "rx100") == 0)
166 else if (strcasecmp (arg
, "rx200") == 0)
168 else if (strcasecmp (arg
, "rx600") == 0)
170 else if (strcasecmp (arg
, "rx610") == 0)
174 as_warn (_("unrecognised RX CPU type %s"), arg
);
179 case OPTION_DISALLOW_STRING_INSNS
:
180 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
;
187 md_show_usage (FILE * stream
)
189 fprintf (stream
, _(" RX specific command line options:\n"));
190 fprintf (stream
, _(" --mbig-endian-data\n"));
191 fprintf (stream
, _(" --mlittle-endian-data [default]\n"));
192 fprintf (stream
, _(" --m32bit-doubles [default]\n"));
193 fprintf (stream
, _(" --m64bit-doubles\n"));
194 fprintf (stream
, _(" --muse-conventional-section-names\n"));
195 fprintf (stream
, _(" --muse-renesas-section-names [default]\n"));
196 fprintf (stream
, _(" --msmall-data-limit\n"));
197 fprintf (stream
, _(" --mrelax\n"));
198 fprintf (stream
, _(" --mpid\n"));
199 fprintf (stream
, _(" --mint-register=<value>\n"));
200 fprintf (stream
, _(" --mcpu=<rx100|rx200|rx600|rx610>\n"));
201 fprintf (stream
, _(" --mno-allow-string-insns"));
205 s_bss (int ignore ATTRIBUTE_UNUSED
)
209 temp
= get_absolute_expression ();
210 subseg_set (bss_section
, (subsegT
) temp
);
211 demand_empty_rest_of_line ();
215 rx_float_cons (int ignore ATTRIBUTE_UNUSED
)
217 if (elf_flags
& E_FLAG_RX_64BIT_DOUBLES
)
218 return float_cons ('d');
219 return float_cons ('f');
223 rx_strcasestr (const char *string
, const char *sub
)
229 return (char *)string
;
232 strl
= strlen (string
);
236 /* strncasecmp is in libiberty. */
237 if (strncasecmp (string
, sub
, subl
) == 0)
238 return (char *)string
;
247 rx_include (int ignore
)
252 char * current_filename
;
260 /* The RX version of the .INCLUDE pseudo-op does not
261 have to have the filename inside double quotes. */
263 if (*input_line_pointer
== '"')
265 /* Treat as the normal GAS .include pseudo-op. */
270 /* Get the filename. Spaces are allowed, NUL characters are not. */
271 filename
= input_line_pointer
;
272 last_char
= find_end_of_line (filename
, FALSE
);
273 input_line_pointer
= last_char
;
275 while (last_char
>= filename
&& (* last_char
== ' ' || * last_char
== '\n'))
277 end_char
= *(++ last_char
);
279 if (last_char
== filename
)
281 as_bad (_("no filename following .INCLUDE pseudo-op"));
282 * last_char
= end_char
;
286 as_where (& current_filename
, NULL
);
287 f
= (char *) xmalloc (strlen (current_filename
) + strlen (filename
) + 1);
289 /* Check the filename. If [@]..FILE[@] is found then replace
290 this with the current assembler source filename, stripped
291 of any directory prefixes or extensions. */
292 if ((p
= rx_strcasestr (filename
, "..file")) != NULL
)
296 len
= 6; /* strlen ("..file"); */
298 if (p
> filename
&& p
[-1] == '@')
304 for (d
= c
= current_filename
; *c
; c
++)
305 if (IS_DIR_SEPARATOR (* c
))
311 sprintf (f
, "%.*s%.*s%.*s", (int) (p
- filename
), filename
,
313 (int) (strlen (filename
) - ((p
+ len
) - filename
)),
317 strcpy (f
, filename
);
319 /* RX .INCLUDE semantics say that 'filename' is located by:
321 1. If filename is absolute, just try that. Otherwise...
323 2. If the current source file includes a directory component
324 then prepend that to the filename and try. Otherwise...
326 3. Try any directories specified by the -I command line
329 4 .Try a directory specifed by the INC100 environment variable. */
331 if (IS_ABSOLUTE_PATH (f
))
332 try = fopen (path
= f
, FOPEN_RT
);
335 char * env
= getenv ("INC100");
339 len
= strlen (current_filename
);
340 if ((size_t) include_dir_maxlen
> len
)
341 len
= include_dir_maxlen
;
342 if (env
&& strlen (env
) > len
)
345 path
= (char *) xmalloc (strlen (f
) + len
+ 5);
347 if (current_filename
!= NULL
)
349 for (d
= NULL
, p
= current_filename
; *p
; p
++)
350 if (IS_DIR_SEPARATOR (* p
))
355 sprintf (path
, "%.*s/%s", (int) (d
- current_filename
), current_filename
,
357 try = fopen (path
, FOPEN_RT
);
365 for (i
= 0; i
< include_dir_count
; i
++)
367 sprintf (path
, "%s/%s", include_dirs
[i
], f
);
368 if ((try = fopen (path
, FOPEN_RT
)) != NULL
)
373 if (try == NULL
&& env
!= NULL
)
375 sprintf (path
, "%s/%s", env
, f
);
376 try = fopen (path
, FOPEN_RT
);
384 as_bad (_("unable to locate include file: %s"), filename
);
390 register_dependency (path
);
391 input_scrub_insert_file (path
);
394 * last_char
= end_char
;
398 parse_rx_section (char * name
)
402 int attr
= SHF_ALLOC
| SHF_EXECINSTR
;
411 for (p
= input_line_pointer
; *p
&& strchr ("\n\t, =", *p
) == NULL
; p
++)
416 if (strcasecmp (input_line_pointer
, "ALIGN") == 0)
431 case '2': align
= 2; break;
432 case '4': align
= 4; break;
433 case '8': align
= 8; break;
435 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p
);
436 ignore_rest_of_line ();
444 else if (strcasecmp (input_line_pointer
, "CODE") == 0)
445 attr
= SHF_ALLOC
| SHF_EXECINSTR
;
446 else if (strcasecmp (input_line_pointer
, "DATA") == 0)
447 attr
= SHF_ALLOC
| SHF_WRITE
;
448 else if (strcasecmp (input_line_pointer
, "ROMDATA") == 0)
452 as_bad (_("unknown parameter following .SECTION directive: %s"),
456 input_line_pointer
= p
+ 1;
457 ignore_rest_of_line ();
462 input_line_pointer
= p
+ 1;
464 while (end_char
!= '\n' && end_char
!= 0);
466 if ((sec
= bfd_get_section_by_name (stdoutput
, name
)) == NULL
)
468 if (strcmp (name
, "B") && strcmp (name
, "B_1") && strcmp (name
, "B_2"))
473 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
475 else /* Try not to redefine a section, especially B_1. */
477 int flags
= sec
->flags
;
479 type
= elf_section_type (sec
);
481 attr
= ((flags
& SEC_READONLY
) ? 0 : SHF_WRITE
)
482 | ((flags
& SEC_ALLOC
) ? SHF_ALLOC
: 0)
483 | ((flags
& SEC_CODE
) ? SHF_EXECINSTR
: 0)
484 | ((flags
& SEC_MERGE
) ? SHF_MERGE
: 0)
485 | ((flags
& SEC_STRINGS
) ? SHF_STRINGS
: 0)
486 | ((flags
& SEC_THREAD_LOCAL
) ? SHF_TLS
: 0);
488 obj_elf_change_section (name
, type
, attr
, 0, NULL
, FALSE
, FALSE
);
491 bfd_set_section_alignment (stdoutput
, now_seg
, align
);
495 rx_section (int ignore
)
499 /* The as100 assembler supports a different syntax for the .section
500 pseudo-op. So check for it and handle it here if necessary. */
503 /* Peek past the section name to see if arguments follow. */
504 for (p
= input_line_pointer
; *p
; p
++)
505 if (*p
== ',' || *p
== '\n')
510 int len
= p
- input_line_pointer
;
512 while (ISSPACE (*++p
))
515 if (*p
!= '"' && *p
!= '#')
517 char * name
= (char *) xmalloc (len
+ 1);
519 strncpy (name
, input_line_pointer
, len
);
522 input_line_pointer
= p
;
523 parse_rx_section (name
);
528 obj_elf_section (ignore
);
532 rx_list (int ignore ATTRIBUTE_UNUSED
)
536 if (strncasecmp (input_line_pointer
, "OFF", 3))
538 else if (strncasecmp (input_line_pointer
, "ON", 2))
541 as_warn (_("expecting either ON or OFF after .list"));
544 /* Like the .rept pseudo op, but supports the
545 use of ..MACREP inside the repeated region. */
548 rx_rept (int ignore ATTRIBUTE_UNUSED
)
550 int count
= get_absolute_expression ();
552 do_repeat_with_expander (count
, "MREPEAT", "ENDR", "..MACREP");
555 /* Like cons() accept that strings are allowed. */
562 if (* input_line_pointer
== '"')
569 rx_nop (int ignore ATTRIBUTE_UNUSED
)
571 ignore_rest_of_line ();
577 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
578 md_pseudo_table
[idx
].poc_name
);
579 ignore_rest_of_line ();
582 /* The target specific pseudo-ops which we support. */
583 const pseudo_typeS md_pseudo_table
[] =
585 /* These are unimplemented. They're listed first so that we can use
586 the poc_value as the index into this array, to get the name of
587 the pseudo. So, keep these (1) first, and (2) in order, with (3)
588 the poc_value's in sequence. */
589 { "btglb", rx_unimp
, 0 },
590 { "call", rx_unimp
, 1 },
591 { "einsf", rx_unimp
, 2 },
592 { "fb", rx_unimp
, 3 },
593 { "fbsym", rx_unimp
, 4 },
594 { "id", rx_unimp
, 5 },
595 { "initsct", rx_unimp
, 6 },
596 { "insf", rx_unimp
, 7 },
597 { "instr", rx_unimp
, 8 },
598 { "lbba", rx_unimp
, 9 },
599 { "len", rx_unimp
, 10 },
600 { "optj", rx_unimp
, 11 },
601 { "rvector", rx_unimp
, 12 },
602 { "sb", rx_unimp
, 13 },
603 { "sbbit", rx_unimp
, 14 },
604 { "sbsym", rx_unimp
, 15 },
605 { "sbsym16", rx_unimp
, 16 },
607 /* These are the do-nothing pseudos. */
608 { "stk", rx_nop
, 0 },
609 /* The manual documents ".stk" but the compiler emits ".stack". */
610 { "stack", rx_nop
, 0 },
612 /* These are Renesas as100 assembler pseudo-ops that we do support. */
613 { "addr", rx_cons
, 3 },
614 { "align", s_align_bytes
, 2 },
615 { "byte", rx_cons
, 1 },
616 { "fixed", float_cons
, 'f' },
617 { "form", listing_psize
, 0 },
618 { "glb", s_globl
, 0 },
619 { "include", rx_include
, 0 },
620 { "list", rx_list
, 0 },
621 { "lword", rx_cons
, 4 },
622 { "mrepeat", rx_rept
, 0 },
623 { "section", rx_section
, 0 },
625 /* FIXME: The following pseudo-ops place their values (and associated
626 label if present) in the data section, regardless of whatever
627 section we are currently in. At the moment this code does not
628 implement that part of the semantics. */
629 { "blka", s_space
, 3 },
630 { "blkb", s_space
, 1 },
631 { "blkd", s_space
, 8 },
632 { "blkf", s_space
, 4 },
633 { "blkl", s_space
, 4 },
634 { "blkw", s_space
, 2 },
636 /* Our "standard" pseudos. */
637 { "double", rx_float_cons
, 0 },
639 { "3byte", cons
, 3 },
643 { "fetchalign", rx_fetchalign
, 0 },
645 /* End of list marker. */
649 static asymbol
* gp_symbol
;
650 static asymbol
* rx_pid_symbol
;
652 static symbolS
* rx_pidreg_symbol
;
653 static symbolS
* rx_gpreg_symbol
;
658 /* Make the __gp and __pid_base symbols now rather
659 than after the symbol table is frozen. We only do this
660 when supporting small data limits because otherwise we
661 pollute the symbol table. */
663 /* The meta-registers %pidreg and %gpreg depend on what other
664 options are specified. The __rx_*_defined symbols exist so we
665 can .ifdef asm code based on what options were passed to gas,
666 without needing a preprocessor */
670 rx_pid_register
= 13 - rx_num_int_regs
;
671 rx_pid_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
672 rx_pidreg_symbol
= symbol_find_or_make ("__rx_pidreg_defined");
673 S_SET_VALUE (rx_pidreg_symbol
, rx_pid_register
);
674 S_SET_SEGMENT (rx_pidreg_symbol
, absolute_section
);
677 if (rx_use_small_data_limit
)
680 rx_gp_register
= rx_pid_register
- 1;
682 rx_gp_register
= 13 - rx_num_int_regs
;
683 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
684 rx_gpreg_symbol
= symbol_find_or_make ("__rx_gpreg_defined");
685 S_SET_VALUE (rx_gpreg_symbol
, rx_gp_register
);
686 S_SET_SEGMENT (rx_gpreg_symbol
, absolute_section
);
693 /* These negative numbers are found in rx_bytesT.n_base for non-opcode
695 #define RX_NBASE_FETCHALIGN -1
697 typedef struct rx_bytesT
700 /* If this is negative, it's a special-purpose frag as per the defines above. */
709 char type
; /* RXREL_*. */
722 fixS
*link_relax_fixP
;
727 static rx_bytesT rx_bytes
;
728 /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
729 static rx_bytesT
*fetchalign_bytes
= NULL
;
732 rx_fetchalign (int ignore ATTRIBUTE_UNUSED
)
737 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
738 rx_bytes
.n_base
= RX_NBASE_FETCHALIGN
;
740 bytes
= frag_more (8);
741 frag_then
= frag_now
;
742 frag_variant (rs_machine_dependent
,
749 frag_then
->fr_opcode
= bytes
;
750 frag_then
->fr_subtype
= 0;
751 fetchalign_bytes
= frag_then
->tc_frag_data
;
755 rx_relax (int type
, int pos
)
757 rx_bytes
.relax
[rx_bytes
.n_relax
].type
= type
;
758 rx_bytes
.relax
[rx_bytes
.n_relax
].field_pos
= pos
;
759 rx_bytes
.relax
[rx_bytes
.n_relax
].val_ofs
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
764 rx_linkrelax_dsp (int pos
)
769 rx_bytes
.link_relax
|= RX_RELAXA_DSP4
;
772 rx_bytes
.link_relax
|= RX_RELAXA_DSP6
;
775 rx_bytes
.link_relax
|= RX_RELAXA_DSP14
;
781 rx_linkrelax_imm (int pos
)
786 rx_bytes
.link_relax
|= RX_RELAXA_IMM6
;
789 rx_bytes
.link_relax
|= RX_RELAXA_IMM12
;
795 rx_linkrelax_branch (void)
797 rx_bytes
.link_relax
|= RX_RELAXA_BRA
;
801 rx_fixup (expressionS exp
, int offsetbits
, int nbits
, int type
)
803 rx_bytes
.fixups
[rx_bytes
.n_fixups
].exp
= exp
;
804 rx_bytes
.fixups
[rx_bytes
.n_fixups
].offset
= offsetbits
;
805 rx_bytes
.fixups
[rx_bytes
.n_fixups
].nbits
= nbits
;
806 rx_bytes
.fixups
[rx_bytes
.n_fixups
].type
= type
;
807 rx_bytes
.fixups
[rx_bytes
.n_fixups
].reloc
= exp
.X_md
;
808 rx_bytes
.n_fixups
++;
811 #define rx_field_fixup(exp, offset, nbits, type) \
812 rx_fixup (exp, offset, nbits, type)
814 #define rx_op_fixup(exp, offset, nbits, type) \
815 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
820 rx_bytes
.base
[0] = b1
;
825 rx_base2 (int b1
, int b2
)
827 rx_bytes
.base
[0] = b1
;
828 rx_bytes
.base
[1] = b2
;
833 rx_base3 (int b1
, int b2
, int b3
)
835 rx_bytes
.base
[0] = b1
;
836 rx_bytes
.base
[1] = b2
;
837 rx_bytes
.base
[2] = b3
;
842 rx_base4 (int b1
, int b2
, int b3
, int b4
)
844 rx_bytes
.base
[0] = b1
;
845 rx_bytes
.base
[1] = b2
;
846 rx_bytes
.base
[2] = b3
;
847 rx_bytes
.base
[3] = b4
;
851 /* This gets complicated when the field spans bytes, because fields
852 are numbered from the MSB of the first byte as zero, and bits are
853 stored LSB towards the LSB of the byte. Thus, a simple four-bit
854 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
855 insertion of b'MXL at position 7 is like this:
857 - - - - - - - - - - - - - - - -
861 rx_field (int val
, int pos
, int sz
)
868 if (val
< 0 || val
>= (1 << sz
))
869 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val
, sz
);
874 if (val
< -(1 << (sz
- 1)) || val
>= (1 << (sz
- 1)))
875 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val
, sz
);
878 /* This code points at 'M' in the above example. */
882 while (bitp
+ sz
> 8)
887 svalm
= val
>> (sz
- ssz
);
888 svalm
= svalm
& ((1 << ssz
) - 1);
889 svalm
= svalm
<< (8 - bitp
- ssz
);
890 gas_assert (bytep
< rx_bytes
.n_base
);
891 rx_bytes
.base
[bytep
] |= svalm
;
897 valm
= val
& ((1 << sz
) - 1);
898 valm
= valm
<< (8 - bitp
- sz
);
899 gas_assert (bytep
< rx_bytes
.n_base
);
900 rx_bytes
.base
[bytep
] |= valm
;
903 /* Special case of the above, for 3-bit displacements of 2..9. */
906 rx_disp3 (expressionS exp
, int pos
)
908 rx_field_fixup (exp
, pos
, 3, RXREL_PCREL
);
911 /* Special case of the above, for split 5-bit displacements. Assumes
912 the displacement has been checked with rx_disp5op. */
913 /* ---- -432 1--- 0--- */
916 rx_field5s (expressionS exp
)
920 val
= exp
.X_add_number
;
921 rx_bytes
.base
[0] |= val
>> 2;
922 rx_bytes
.base
[1] |= (val
<< 6) & 0x80;
923 rx_bytes
.base
[1] |= (val
<< 3) & 0x08;
926 /* ---- ---- 4--- 3210 */
929 rx_field5s2 (expressionS exp
)
933 val
= exp
.X_add_number
;
934 rx_bytes
.base
[1] |= (val
<< 3) & 0x80;
935 rx_bytes
.base
[1] |= (val
) & 0x0f;
938 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
940 #define F_PRECISION 2
943 rx_op (expressionS exp
, int nbytes
, int type
)
947 if ((exp
.X_op
== O_constant
|| exp
.X_op
== O_big
)
948 && type
!= RXREL_PCREL
)
950 if (exp
.X_op
== O_big
&& exp
.X_add_number
<= 0)
953 char * ip
= rx_bytes
.ops
+ rx_bytes
.n_ops
;
955 gen_to_words (w
, F_PRECISION
, 8);
956 #if RX_OPCODE_BIG_ENDIAN
971 v
= exp
.X_add_number
;
974 #if RX_OPCODE_BIG_ENDIAN
975 OP ((v
>> (8 * (nbytes
- 1))) & 0xff);
986 rx_op_fixup (exp
, rx_bytes
.n_ops
* 8, nbytes
* 8, type
);
987 memset (rx_bytes
.ops
+ rx_bytes
.n_ops
, 0, nbytes
);
988 rx_bytes
.n_ops
+= nbytes
;
998 #define APPEND(B, N_B) \
1001 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
1002 idx += rx_bytes.N_B; \
1006 rx_frag_init (fragS
* fragP
)
1008 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
|| rx_bytes
.n_base
< 0)
1010 fragP
->tc_frag_data
= malloc (sizeof (rx_bytesT
));
1011 memcpy (fragP
->tc_frag_data
, & rx_bytes
, sizeof (rx_bytesT
));
1014 fragP
->tc_frag_data
= 0;
1017 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
1018 <symbol_name> .equ <expression> */
1021 rx_equ (char * name
, char * expression
)
1023 char saved_name_end_char
;
1027 while (ISSPACE (* name
))
1030 for (name_end
= name
+ 1; *name_end
; name_end
++)
1031 if (! ISALNUM (* name_end
))
1034 saved_name_end_char
= * name_end
;
1037 saved_ilp
= input_line_pointer
;
1038 input_line_pointer
= expression
;
1042 input_line_pointer
= saved_ilp
;
1043 * name_end
= saved_name_end_char
;
1046 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
1047 rather than at the start of a line. (eg .EQU or .DEFINE). If one
1048 is found, process it and return TRUE otherwise return FALSE. */
1051 scan_for_infix_rx_pseudo_ops (char * str
)
1055 char * dot
= strchr (str
, '.');
1057 if (dot
== NULL
|| dot
== str
)
1060 /* A real pseudo-op must be preceeded by whitespace. */
1061 if (dot
[-1] != ' ' && dot
[-1] != '\t')
1064 pseudo_op
= dot
+ 1;
1066 if (!ISALNUM (* pseudo_op
))
1069 for (p
= pseudo_op
+ 1; ISALNUM (* p
); p
++)
1072 if (strncasecmp ("EQU", pseudo_op
, p
- pseudo_op
) == 0)
1074 else if (strncasecmp ("DEFINE", pseudo_op
, p
- pseudo_op
) == 0)
1075 as_warn (_("The .DEFINE pseudo-op is not implemented"));
1076 else if (strncasecmp ("MACRO", pseudo_op
, p
- pseudo_op
) == 0)
1077 as_warn (_("The .MACRO pseudo-op is not implemented"));
1078 else if (strncasecmp ("BTEQU", pseudo_op
, p
- pseudo_op
) == 0)
1079 as_warn (_("The .BTEQU pseudo-op is not implemented."));
1087 md_assemble (char * str
)
1092 fragS
* frag_then
= frag_now
;
1095 memset (& rx_bytes
, 0, sizeof (rx_bytes
));
1097 rx_lex_init (str
, str
+ strlen (str
));
1098 if (scan_for_infix_rx_pseudo_ops (str
))
1102 /* This simplifies the relaxation code. */
1103 if (rx_bytes
.n_relax
|| rx_bytes
.link_relax
)
1105 /* We do it this way because we want the frag to have the
1106 rx_bytes in it, which we initialize above. */
1107 bytes
= frag_more (12);
1108 frag_then
= frag_now
;
1109 frag_variant (rs_machine_dependent
,
1116 frag_then
->fr_opcode
= bytes
;
1117 frag_then
->fr_fix
+= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
1118 frag_then
->fr_subtype
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
1122 bytes
= frag_more (rx_bytes
.n_base
+ rx_bytes
.n_ops
);
1123 frag_then
= frag_now
;
1124 if (fetchalign_bytes
)
1125 fetchalign_bytes
->n_ops
= rx_bytes
.n_base
+ rx_bytes
.n_ops
;
1128 fetchalign_bytes
= NULL
;
1130 APPEND (base
, n_base
);
1131 APPEND (ops
, n_ops
);
1133 if (rx_bytes
.link_relax
&& rx_bytes
.n_fixups
)
1137 f
= fix_new (frag_then
,
1138 (char *) bytes
- frag_then
->fr_literal
,
1141 rx_bytes
.link_relax
| rx_bytes
.n_fixups
,
1143 BFD_RELOC_RX_RELAX
);
1144 frag_then
->tc_frag_data
->link_relax_fixP
= f
;
1147 for (i
= 0; i
< rx_bytes
.n_fixups
; i
++)
1149 /* index: [nbytes][type] */
1150 static int reloc_map
[5][4] =
1152 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL
},
1153 { BFD_RELOC_8
, BFD_RELOC_RX_8U
, BFD_RELOC_RX_NEG8
, BFD_RELOC_8_PCREL
},
1154 { BFD_RELOC_RX_16_OP
, BFD_RELOC_RX_16U
, BFD_RELOC_RX_NEG16
, BFD_RELOC_16_PCREL
},
1155 { BFD_RELOC_RX_24_OP
, BFD_RELOC_RX_24U
, BFD_RELOC_RX_NEG24
, BFD_RELOC_24_PCREL
},
1156 { BFD_RELOC_RX_32_OP
, BFD_RELOC_32
, BFD_RELOC_RX_NEG32
, BFD_RELOC_32_PCREL
},
1160 idx
= rx_bytes
.fixups
[i
].offset
/ 8;
1161 rel
= reloc_map
[rx_bytes
.fixups
[i
].nbits
/ 8][(int) rx_bytes
.fixups
[i
].type
];
1163 if (rx_bytes
.fixups
[i
].reloc
)
1164 rel
= rx_bytes
.fixups
[i
].reloc
;
1166 if (frag_then
->tc_frag_data
)
1167 exp
= & frag_then
->tc_frag_data
->fixups
[i
].exp
;
1169 exp
= & rx_bytes
.fixups
[i
].exp
;
1171 f
= fix_new_exp (frag_then
,
1172 (char *) bytes
+ idx
- frag_then
->fr_literal
,
1173 rx_bytes
.fixups
[i
].nbits
/ 8,
1175 rx_bytes
.fixups
[i
].type
== RXREL_PCREL
? 1 : 0,
1177 if (frag_then
->tc_frag_data
)
1178 frag_then
->tc_frag_data
->fixups
[i
].fixP
= f
;
1181 dwarf2_emit_insn (idx
);
1189 /* Write a value out to the object file, using the appropriate endianness. */
1192 md_number_to_chars (char * buf
, valueT val
, int n
)
1194 if (target_big_endian
)
1195 number_to_chars_bigendian (buf
, val
, n
);
1197 number_to_chars_littleendian (buf
, val
, n
);
1207 { "gp", BFD_RELOC_GPREL16
},
1212 md_operand (expressionS
* exp ATTRIBUTE_UNUSED
)
1217 for (i
= 0; reloc_functions
[i
].fname
; i
++)
1219 int flen
= strlen (reloc_functions
[i
].fname
);
1221 if (input_line_pointer
[0] == '%'
1222 && strncasecmp (input_line_pointer
+ 1, reloc_functions
[i
].fname
, flen
) == 0
1223 && input_line_pointer
[flen
+ 1] == '(')
1225 reloc
= reloc_functions
[i
].reloc
;
1226 input_line_pointer
+= flen
+ 2;
1234 if (* input_line_pointer
== ')')
1235 input_line_pointer
++;
1241 md_section_align (segT segment
, valueT size
)
1243 int align
= bfd_get_section_alignment (stdoutput
, segment
);
1244 return ((size
+ (1 << align
) - 1) & (-1 << align
));
1248 static unsigned char nop_1
[] = { 0x03};
1249 /* MOV.L R0,R0 - 1 cycle */
1250 static unsigned char nop_2
[] = { 0xef, 0x00};
1251 /* MAX R0,R0 - 1 cycle */
1252 static unsigned char nop_3
[] = { 0xfc, 0x13, 0x00 };
1253 /* MUL #1,R0 - 1 cycle */
1254 static unsigned char nop_4
[] = { 0x76, 0x10, 0x01, 0x00 };
1255 /* MUL #1,R0 - 1 cycle */
1256 static unsigned char nop_5
[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
1257 /* MUL #1,R0 - 1 cycle */
1258 static unsigned char nop_6
[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
1259 /* BRA.S .+7 - 1 cycle */
1260 static unsigned char nop_7
[] = { 0x0F, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
1262 static unsigned char *nops
[] = { NULL
, nop_1
, nop_2
, nop_3
, nop_4
, nop_5
, nop_6
, nop_7
};
1263 #define BIGGEST_NOP 7
1265 /* When relaxing, we need to output a reloc for any .align directive
1266 so that we can retain this alignment as we adjust opcode sizes. */
1268 rx_handle_align (fragS
* frag
)
1270 /* If handling an alignment frag, use an optimal NOP pattern.
1271 Only do this if a fill value has not already been provided.
1272 FIXME: This test fails if the provided fill value is zero. */
1273 if ((frag
->fr_type
== rs_align
1274 || frag
->fr_type
== rs_align_code
)
1275 && subseg_text_p (now_seg
))
1277 int count
= (frag
->fr_next
->fr_address
1280 unsigned char *base
= (unsigned char *)frag
->fr_literal
+ frag
->fr_fix
;
1284 if (count
> BIGGEST_NOP
)
1292 memcpy (base
, nops
[count
], count
);
1293 frag
->fr_var
= count
;
1299 && (frag
->fr_type
== rs_align
1300 || frag
->fr_type
== rs_align_code
)
1301 && frag
->fr_address
+ frag
->fr_fix
> 0
1302 && frag
->fr_offset
> 0
1303 && now_seg
!= bss_section
)
1305 fix_new (frag
, frag
->fr_fix
, 0,
1306 &abs_symbol
, RX_RELAXA_ALIGN
+ frag
->fr_offset
,
1307 0, BFD_RELOC_RX_RELAX
);
1308 /* For the purposes of relaxation, this relocation is attached
1309 to the byte *after* the alignment - i.e. the byte that must
1311 fix_new (frag
->fr_next
, 0, 0,
1312 &abs_symbol
, RX_RELAXA_ELIGN
+ frag
->fr_offset
,
1313 0, BFD_RELOC_RX_RELAX
);
1318 md_atof (int type
, char * litP
, int * sizeP
)
1320 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
1324 md_undefined_symbol (char * name ATTRIBUTE_UNUSED
)
1329 /*----------------------------------------------------------------------*/
1330 /* To recap: we estimate everything based on md_estimate_size, then
1331 adjust based on rx_relax_frag. When it all settles, we call
1332 md_convert frag to update the bytes. The relaxation types and
1333 relocations are in fragP->tc_frag_data, which is a copy of that
1336 Our scheme is as follows: fr_fix has the size of the smallest
1337 opcode (like BRA.S). We store the number of total bytes we need in
1338 fr_subtype. When we're done relaxing, we use fr_subtype and the
1339 existing opcode bytes to figure out what actual opcode we need to
1340 put in there. If the fixup isn't resolvable now, we use the
1343 #define TRACE_RELAX 0
1344 #define tprintf if (TRACE_RELAX) printf
1356 /* We're looking for these types of relaxations:
1359 BRA.B 00101110 dspppppp
1360 BRA.W 00111000 dspppppp pppppppp
1361 BRA.A 00000100 dspppppp pppppppp pppppppp
1364 BEQ.B 00100000 dspppppp
1365 BEQ.W 00111010 dspppppp pppppppp
1368 BNE.B 00100001 dspppppp
1369 BNE.W 00111011 dspppppp pppppppp
1371 BSR.W 00111001 dspppppp pppppppp
1372 BSR.A 00000101 dspppppp pppppppp pppppppp
1374 Bcc.B 0010cond dspppppp
1376 Additionally, we can synthesize longer conditional branches using
1377 pairs of opcodes, one with an inverted conditional (flip LSB):
1379 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1380 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1381 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1382 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1384 /* Given the opcode bytes at OP, figure out which opcode it is and
1385 return the type of opcode. We use this to re-encode the opcode as
1386 a different size later. */
1389 rx_opcode_type (char * op
)
1391 unsigned char b
= (unsigned char) op
[0];
1395 case 0x08: return OT_bra
;
1396 case 0x10: return OT_beq
;
1397 case 0x18: return OT_bne
;
1402 case 0x2e: return OT_bra
;
1403 case 0x38: return OT_bra
;
1404 case 0x04: return OT_bra
;
1406 case 0x20: return OT_beq
;
1407 case 0x3a: return OT_beq
;
1409 case 0x21: return OT_bne
;
1410 case 0x3b: return OT_bne
;
1412 case 0x39: return OT_bsr
;
1413 case 0x05: return OT_bsr
;
1416 if ((b
& 0xf0) == 0x20)
1422 /* Returns zero if *addrP has the target address. Else returns nonzero
1423 if we cannot compute the target address yet. */
1426 rx_frag_fix_value (fragS
* fragP
,
1431 addressT
* sym_addr
)
1434 rx_bytesT
* b
= fragP
->tc_frag_data
;
1435 expressionS
* exp
= & b
->fixups
[which
].exp
;
1437 if (need_diff
&& exp
->X_op
!= O_subtract
)
1440 if (exp
->X_add_symbol
)
1442 if (S_FORCE_RELOC (exp
->X_add_symbol
, 1))
1444 if (S_GET_SEGMENT (exp
->X_add_symbol
) != segment
)
1446 addr
+= S_GET_VALUE (exp
->X_add_symbol
);
1449 if (exp
->X_op_symbol
)
1451 if (exp
->X_op
!= O_subtract
)
1453 if (S_FORCE_RELOC (exp
->X_op_symbol
, 1))
1455 if (S_GET_SEGMENT (exp
->X_op_symbol
) != segment
)
1457 addr
-= S_GET_VALUE (exp
->X_op_symbol
);
1461 addr
+= exp
->X_add_number
;
1466 /* Estimate how big the opcode is after this relax pass. The return
1467 value is the difference between fr_fix and the actual size. We
1468 compute the total size in rx_relax_frag and store it in fr_subtype,
1469 sowe only need to subtract fx_fix and return it. */
1472 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
, segT segment ATTRIBUTE_UNUSED
)
1477 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1478 (unsigned long) (fragP
->fr_address
1479 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1480 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1481 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
);
1483 /* This is the size of the opcode that's accounted for in fr_fix. */
1484 opfixsize
= fragP
->fr_fix
- (fragP
->fr_opcode
- fragP
->fr_literal
);
1485 /* This is the size of the opcode that isn't. */
1486 delta
= (fragP
->fr_subtype
- opfixsize
);
1488 tprintf (" -> opfixsize %d delta %d\n", opfixsize
, delta
);
1492 /* Given a frag FRAGP, return the "next" frag that contains an
1493 opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
1496 rx_next_opcode (fragS
*fragP
)
1499 fragP
= fragP
->fr_next
;
1500 } while (fragP
&& fragP
->fr_type
!= rs_machine_dependent
);
1504 /* Given the new addresses for this relax pass, figure out how big
1505 each opcode must be. We store the total number of bytes needed in
1506 fr_subtype. The return value is the difference between the size
1507 after the last pass and the size after this pass, so we use the old
1508 fr_subtype to calculate the difference. */
1511 rx_relax_frag (segT segment ATTRIBUTE_UNUSED
, fragS
* fragP
, long stretch
)
1513 addressT addr0
, sym_addr
;
1516 int oldsize
= fragP
->fr_subtype
;
1517 int newsize
= oldsize
;
1519 /* Index of relaxation we care about. */
1522 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",
1523 (unsigned long) (fragP
->fr_address
1524 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1525 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1526 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
, fragP
->fr_subtype
, stretch
);
1528 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1530 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1532 unsigned int next_size
;
1533 if (fragP
->fr_next
== NULL
)
1536 next_size
= fragP
->tc_frag_data
->n_ops
;
1539 fragS
*n
= rx_next_opcode (fragP
);
1540 next_size
= n
->fr_subtype
;
1543 fragP
->fr_subtype
= (8-(mypc
& 7)) & 7;
1544 tprintf("subtype %u\n", fragP
->fr_subtype
);
1545 if (fragP
->fr_subtype
>= next_size
)
1546 fragP
->fr_subtype
= 0;
1547 tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
1549 next_size
, fragP
->fr_subtype
, oldsize
, fragP
->fr_subtype
-oldsize
);
1551 newsize
= fragP
->fr_subtype
;
1553 return newsize
- oldsize
;
1556 optype
= rx_opcode_type (fragP
->fr_opcode
);
1558 /* In the one case where we have both a disp and imm relaxation, we want
1559 the imm relaxation here. */
1561 if (fragP
->tc_frag_data
->n_relax
> 1
1562 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1565 /* Try to get the target address. */
1566 if (rx_frag_fix_value (fragP
, segment
, ri
, & addr0
,
1567 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
,
1570 /* If we don't, we must use the maximum size for the linker.
1571 Note that we don't use synthetically expanded conditionals
1573 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1575 case RX_RELAX_BRANCH
:
1596 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
+ 4;
1599 fragP
->fr_subtype
= newsize
;
1600 tprintf (" -> new %d old %d delta %d (external)\n", newsize
, oldsize
, newsize
-oldsize
);
1601 return newsize
- oldsize
;
1604 if (sym_addr
> mypc
)
1607 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1609 case RX_RELAX_BRANCH
:
1610 tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
1611 (unsigned long) addr0
, (unsigned long) mypc
,
1612 (long) (addr0
- mypc
));
1613 disp
= (int) addr0
- (int) mypc
;
1618 if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1621 else if (disp
>= -32768 && (disp
- (oldsize
-5)) <= 32767)
1631 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1634 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1637 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1647 if ((disp
- (oldsize
-1)) >= 3 && (disp
- (oldsize
-1)) <= 10 && !linkrelax
)
1650 else if (disp
>= -128 && (disp
- (oldsize
-2)) <= 127)
1653 else if (disp
>= -32768 && (disp
- (oldsize
-3)) <= 32767)
1664 tprintf (" - newsize %d\n", newsize
);
1668 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
1669 (unsigned long) addr0
, (unsigned long) mypc
,
1670 fragP
->tc_frag_data
->relax
[ri
].field_pos
,
1671 fragP
->tc_frag_data
->relax
[ri
].val_ofs
);
1673 newsize
= fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
1675 if ((long) addr0
>= -128 && (long) addr0
<= 127)
1677 else if ((long) addr0
>= -32768 && (long) addr0
<= 32767)
1679 else if ((long) addr0
>= -8388608 && (long) addr0
<= 8388607)
1689 if (fragP
->tc_frag_data
->relax
[ri
].type
== RX_RELAX_BRANCH
)
1705 /* This prevents infinite loops in align-heavy sources. */
1706 if (newsize
< oldsize
)
1708 if (fragP
->tc_frag_data
->times_shrank
> 10
1709 && fragP
->tc_frag_data
->times_grown
> 10)
1711 if (fragP
->tc_frag_data
->times_shrank
< 20)
1712 fragP
->tc_frag_data
->times_shrank
++;
1714 else if (newsize
> oldsize
)
1716 if (fragP
->tc_frag_data
->times_grown
< 20)
1717 fragP
->tc_frag_data
->times_grown
++;
1720 fragP
->fr_subtype
= newsize
;
1721 tprintf (" -> new %d old %d delta %d\n", newsize
, oldsize
, newsize
-oldsize
);
1722 return newsize
- oldsize
;
1725 /* This lets us test for the opcode type and the desired size in a
1726 switch statement. */
1727 #define OPCODE(type,size) ((type) * 16 + (size))
1729 /* Given the opcode stored in fr_opcode and the number of bytes we
1730 think we need, encode a new opcode. We stored a pointer to the
1731 fixup for this opcode in the tc_frag_data structure. If we can do
1732 the fixup here, we change the relocation type to "none" (we test
1733 for that in tc_gen_reloc) else we change it to the right type for
1734 the new (biggest) opcode. */
1737 md_convert_frag (bfd
* abfd ATTRIBUTE_UNUSED
,
1738 segT segment ATTRIBUTE_UNUSED
,
1739 fragS
* fragP ATTRIBUTE_UNUSED
)
1741 rx_bytesT
* rxb
= fragP
->tc_frag_data
;
1742 addressT addr0
, mypc
;
1744 int reloc_type
, reloc_adjust
;
1745 char * op
= fragP
->fr_opcode
;
1748 int fi
= (rxb
->n_fixups
> 1) ? 1 : 0;
1749 fixS
* fix
= rxb
->fixups
[fi
].fixP
;
1751 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1752 (unsigned long) (fragP
->fr_address
1753 + (fragP
->fr_opcode
- fragP
->fr_literal
)),
1754 (long) fragP
->fr_fix
, (long) fragP
->fr_var
, (long) fragP
->fr_offset
,
1755 fragP
->fr_literal
, fragP
->fr_opcode
, fragP
->fr_type
,
1762 printf ("lit 0x%p opc 0x%p", fragP
->fr_literal
, fragP
->fr_opcode
);
1763 for (i
= 0; i
< 10; i
++)
1764 printf (" %02x", (unsigned char) (fragP
->fr_opcode
[i
]));
1769 if (fragP
->tc_frag_data
->n_base
== RX_NBASE_FETCHALIGN
)
1771 int count
= fragP
->fr_subtype
;
1774 else if (count
> BIGGEST_NOP
)
1781 memcpy (op
, nops
[count
], count
);
1785 /* In the one case where we have both a disp and imm relaxation, we want
1786 the imm relaxation here. */
1788 if (fragP
->tc_frag_data
->n_relax
> 1
1789 && fragP
->tc_frag_data
->relax
[0].type
== RX_RELAX_DISP
)
1792 /* We used a new frag for this opcode, so the opcode address should
1793 be the frag address. */
1794 mypc
= fragP
->fr_address
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
1796 /* Try to get the target address. If we fail here, we just use the
1798 if (rx_frag_fix_value (fragP
, segment
, 0, & addr0
,
1799 fragP
->tc_frag_data
->relax
[ri
].type
!= RX_RELAX_BRANCH
, 0))
1801 /* We don't know the target address. */
1808 /* We know the target address, and it's in addr0. */
1809 disp
= (int) addr0
- (int) mypc
;
1815 reloc_type
= BFD_RELOC_NONE
;
1818 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1819 rx_opcode_type (fragP
->fr_opcode
), disp
,
1820 (unsigned long) addr0
, (unsigned long) mypc
);
1821 switch (fragP
->tc_frag_data
->relax
[ri
].type
)
1823 case RX_RELAX_BRANCH
:
1824 switch (OPCODE (rx_opcode_type (fragP
->fr_opcode
), fragP
->fr_subtype
))
1826 case OPCODE (OT_bra
, 1): /* BRA.S - no change. */
1827 op
[0] = 0x08 + (disp
& 7);
1829 case OPCODE (OT_bra
, 2): /* BRA.B - 8 bit. */
1832 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1835 case OPCODE (OT_bra
, 3): /* BRA.W - 16 bit. */
1837 #if RX_OPCODE_BIG_ENDIAN
1838 op
[1] = (disp
>> 8) & 0xff;
1841 op
[2] = (disp
>> 8) & 0xff;
1845 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1847 case OPCODE (OT_bra
, 4): /* BRA.A - 24 bit. */
1849 #if RX_OPCODE_BIG_ENDIAN
1850 op
[1] = (disp
>> 16) & 0xff;
1851 op
[2] = (disp
>> 8) & 0xff;
1854 op
[3] = (disp
>> 16) & 0xff;
1855 op
[2] = (disp
>> 8) & 0xff;
1858 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1862 case OPCODE (OT_beq
, 1): /* BEQ.S - no change. */
1863 op
[0] = 0x10 + (disp
& 7);
1865 case OPCODE (OT_beq
, 2): /* BEQ.B - 8 bit. */
1869 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1871 case OPCODE (OT_beq
, 3): /* BEQ.W - 16 bit. */
1873 #if RX_OPCODE_BIG_ENDIAN
1874 op
[1] = (disp
>> 8) & 0xff;
1877 op
[2] = (disp
>> 8) & 0xff;
1880 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1883 case OPCODE (OT_beq
, 5): /* BEQ.A - synthetic. */
1884 op
[0] = 0x1d; /* bne.s .+5. */
1885 op
[1] = 0x04; /* bra.a dsp:24. */
1887 #if RX_OPCODE_BIG_ENDIAN
1888 op
[2] = (disp
>> 16) & 0xff;
1889 op
[3] = (disp
>> 8) & 0xff;
1892 op
[4] = (disp
>> 16) & 0xff;
1893 op
[3] = (disp
>> 8) & 0xff;
1896 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1900 case OPCODE (OT_bne
, 1): /* BNE.S - no change. */
1901 op
[0] = 0x18 + (disp
& 7);
1903 case OPCODE (OT_bne
, 2): /* BNE.B - 8 bit. */
1907 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1909 case OPCODE (OT_bne
, 3): /* BNE.W - 16 bit. */
1911 #if RX_OPCODE_BIG_ENDIAN
1912 op
[1] = (disp
>> 8) & 0xff;
1915 op
[2] = (disp
>> 8) & 0xff;
1918 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1921 case OPCODE (OT_bne
, 5): /* BNE.A - synthetic. */
1922 op
[0] = 0x15; /* beq.s .+5. */
1923 op
[1] = 0x04; /* bra.a dsp:24. */
1925 #if RX_OPCODE_BIG_ENDIAN
1926 op
[2] = (disp
>> 16) & 0xff;
1927 op
[3] = (disp
>> 8) & 0xff;
1930 op
[4] = (disp
>> 16) & 0xff;
1931 op
[3] = (disp
>> 8) & 0xff;
1934 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1938 case OPCODE (OT_bsr
, 3): /* BSR.W - 16 bit. */
1940 #if RX_OPCODE_BIG_ENDIAN
1941 op
[1] = (disp
>> 8) & 0xff;
1944 op
[2] = (disp
>> 8) & 0xff;
1947 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1950 case OPCODE (OT_bsr
, 4): /* BSR.A - 24 bit. */
1952 #if RX_OPCODE_BIG_ENDIAN
1953 op
[1] = (disp
>> 16) & 0xff;
1954 op
[2] = (disp
>> 8) & 0xff;
1957 op
[3] = (disp
>> 16) & 0xff;
1958 op
[2] = (disp
>> 8) & 0xff;
1961 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
1965 case OPCODE (OT_bcc
, 2): /* Bcond.B - 8 bit. */
1967 reloc_type
= keep_reloc
? BFD_RELOC_8_PCREL
: BFD_RELOC_NONE
;
1969 case OPCODE (OT_bcc
, 5): /* Bcond.W - synthetic. */
1970 op
[0] ^= 1; /* Invert condition. */
1971 op
[1] = 5; /* Displacement. */
1974 #if RX_OPCODE_BIG_ENDIAN
1975 op
[3] = (disp
>> 8) & 0xff;
1978 op
[4] = (disp
>> 8) & 0xff;
1981 reloc_type
= keep_reloc
? BFD_RELOC_16_PCREL
: BFD_RELOC_NONE
;
1984 case OPCODE (OT_bcc
, 6): /* Bcond.S - synthetic. */
1985 op
[0] ^= 1; /* Invert condition. */
1986 op
[1] = 6; /* Displacement. */
1989 #if RX_OPCODE_BIG_ENDIAN
1990 op
[3] = (disp
>> 16) & 0xff;
1991 op
[4] = (disp
>> 8) & 0xff;
1994 op
[5] = (disp
>> 16) & 0xff;
1995 op
[4] = (disp
>> 8) & 0xff;
1998 reloc_type
= keep_reloc
? BFD_RELOC_24_PCREL
: BFD_RELOC_NONE
;
2003 /* These are opcodes we'll relax in th linker, later. */
2005 reloc_type
= rxb
->fixups
[ri
].fixP
->fx_r_type
;
2012 int nbytes
= fragP
->fr_subtype
- fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2014 char * imm
= op
+ fragP
->tc_frag_data
->relax
[ri
].val_ofs
;
2021 reloc_type
= BFD_RELOC_8
;
2025 #if RX_OPCODE_BIG_ENDIAN
2027 imm
[0] = addr0
>> 8;
2030 imm
[1] = addr0
>> 8;
2032 reloc_type
= BFD_RELOC_RX_16_OP
;
2036 #if RX_OPCODE_BIG_ENDIAN
2038 imm
[1] = addr0
>> 8;
2039 imm
[0] = addr0
>> 16;
2042 imm
[1] = addr0
>> 8;
2043 imm
[2] = addr0
>> 16;
2045 reloc_type
= BFD_RELOC_RX_24_OP
;
2049 #if RX_OPCODE_BIG_ENDIAN
2051 imm
[2] = addr0
>> 8;
2052 imm
[1] = addr0
>> 16;
2053 imm
[0] = addr0
>> 24;
2056 imm
[1] = addr0
>> 8;
2057 imm
[2] = addr0
>> 16;
2058 imm
[3] = addr0
>> 24;
2060 reloc_type
= BFD_RELOC_RX_32_OP
;
2063 as_bad (_("invalid immediate size"));
2067 switch (fragP
->tc_frag_data
->relax
[ri
].field_pos
)
2082 as_bad (_("invalid immediate field position"));
2090 reloc_type
= fix
->fx_r_type
;
2099 fix
->fx_r_type
= reloc_type
;
2100 fix
->fx_where
+= reloc_adjust
;
2103 case BFD_RELOC_NONE
:
2109 case BFD_RELOC_16_PCREL
:
2110 case BFD_RELOC_RX_16_OP
:
2113 case BFD_RELOC_24_PCREL
:
2114 case BFD_RELOC_RX_24_OP
:
2117 case BFD_RELOC_RX_32_OP
:
2123 fragP
->fr_fix
= fragP
->fr_subtype
+ (fragP
->fr_opcode
- fragP
->fr_literal
);
2124 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP
->fr_fix
,
2125 fragP
->fr_subtype
, fragP
->fr_opcode
, fragP
->fr_literal
);
2128 if (fragP
->fr_next
!= NULL
2129 && ((offsetT
) (fragP
->fr_next
->fr_address
- fragP
->fr_address
)
2131 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP
,
2132 (long) fragP
->fr_fix
,
2133 (long) fragP
->fr_address
, (long) fragP
->fr_next
->fr_address
);
2139 rx_validate_fix_sub (struct fix
* f
)
2141 /* We permit the subtraction of two symbols in a few cases. */
2142 /* mov #sym1-sym2, R3 */
2143 if (f
->fx_r_type
== BFD_RELOC_RX_32_OP
)
2145 /* .long sym1-sym2 */
2146 if (f
->fx_r_type
== BFD_RELOC_RX_DIFF
2148 && (f
->fx_size
== 4 || f
->fx_size
== 2 || f
->fx_size
== 1))
2154 md_pcrel_from_section (fixS
* fixP
, segT sec
)
2158 if (fixP
->fx_addsy
!= NULL
2159 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2160 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
2161 /* The symbol is undefined (or is defined but not in this section).
2162 Let the linker figure it out. */
2165 rv
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2166 switch (fixP
->fx_r_type
)
2168 case BFD_RELOC_RX_DIR3U_PCREL
:
2176 rx_cons_fix_new (fragS
* frag
,
2180 bfd_reloc_code_real_type type
)
2188 type
= BFD_RELOC_16
;
2191 type
= BFD_RELOC_24
;
2194 type
= BFD_RELOC_32
;
2197 as_bad (_("unsupported constant size %d\n"), size
);
2201 if (exp
->X_op
== O_subtract
&& exp
->X_op_symbol
)
2203 if (size
!= 4 && size
!= 2 && size
!= 1)
2204 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2206 type
= BFD_RELOC_RX_DIFF
;
2209 fix_new_exp (frag
, where
, (int) size
, exp
, 0, type
);
2213 md_apply_fix (struct fix
* f ATTRIBUTE_UNUSED
,
2214 valueT
* t ATTRIBUTE_UNUSED
,
2215 segT s ATTRIBUTE_UNUSED
)
2217 /* Instruction bytes are always little endian. */
2221 if (f
->fx_addsy
&& S_FORCE_RELOC (f
->fx_addsy
, 1))
2223 if (f
->fx_subsy
&& S_FORCE_RELOC (f
->fx_subsy
, 1))
2226 #define OP2(x) op[target_big_endian ? 1-x : x]
2227 #define OP3(x) op[target_big_endian ? 2-x : x]
2228 #define OP4(x) op[target_big_endian ? 3-x : x]
2230 op
= f
->fx_frag
->fr_literal
+ f
->fx_where
;
2231 val
= (unsigned long) * t
;
2233 /* Opcode words are always the same endian. Data words are either
2234 big or little endian. */
2236 switch (f
->fx_r_type
)
2238 case BFD_RELOC_NONE
:
2241 case BFD_RELOC_RX_RELAX
:
2245 case BFD_RELOC_RX_DIR3U_PCREL
:
2246 if (val
< 3 || val
> 10)
2247 as_bad_where (f
->fx_file
, f
->fx_line
,
2248 _("jump not 3..10 bytes away (is %d)"), (int) val
);
2250 op
[0] |= val
& 0x07;
2254 case BFD_RELOC_8_PCREL
:
2255 case BFD_RELOC_RX_8U
:
2260 OP2(1) = val
& 0xff;
2261 OP2(0) = (val
>> 8) & 0xff;
2264 case BFD_RELOC_16_PCREL
:
2265 case BFD_RELOC_RX_16_OP
:
2266 case BFD_RELOC_RX_16U
:
2267 #if RX_OPCODE_BIG_ENDIAN
2269 op
[0] = (val
>> 8) & 0xff;
2272 op
[1] = (val
>> 8) & 0xff;
2277 OP3(0) = val
& 0xff;
2278 OP3(1) = (val
>> 8) & 0xff;
2279 OP3(2) = (val
>> 16) & 0xff;
2282 case BFD_RELOC_24_PCREL
:
2283 case BFD_RELOC_RX_24_OP
:
2284 case BFD_RELOC_RX_24U
:
2285 #if RX_OPCODE_BIG_ENDIAN
2287 op
[1] = (val
>> 8) & 0xff;
2288 op
[0] = (val
>> 16) & 0xff;
2291 op
[1] = (val
>> 8) & 0xff;
2292 op
[2] = (val
>> 16) & 0xff;
2296 case BFD_RELOC_RX_DIFF
:
2303 OP2(0) = val
& 0xff;
2304 OP2(1) = (val
>> 8) & 0xff;
2307 OP4(0) = val
& 0xff;
2308 OP4(1) = (val
>> 8) & 0xff;
2309 OP4(2) = (val
>> 16) & 0xff;
2310 OP4(3) = (val
>> 24) & 0xff;
2316 OP4(0) = val
& 0xff;
2317 OP4(1) = (val
>> 8) & 0xff;
2318 OP4(2) = (val
>> 16) & 0xff;
2319 OP4(3) = (val
>> 24) & 0xff;
2322 case BFD_RELOC_RX_32_OP
:
2323 #if RX_OPCODE_BIG_ENDIAN
2325 op
[2] = (val
>> 8) & 0xff;
2326 op
[1] = (val
>> 16) & 0xff;
2327 op
[0] = (val
>> 24) & 0xff;
2330 op
[1] = (val
>> 8) & 0xff;
2331 op
[2] = (val
>> 16) & 0xff;
2332 op
[3] = (val
>> 24) & 0xff;
2336 case BFD_RELOC_RX_NEG8
:
2340 case BFD_RELOC_RX_NEG16
:
2342 #if RX_OPCODE_BIG_ENDIAN
2344 op
[0] = (val
>> 8) & 0xff;
2347 op
[1] = (val
>> 8) & 0xff;
2351 case BFD_RELOC_RX_NEG24
:
2353 #if RX_OPCODE_BIG_ENDIAN
2355 op
[1] = (val
>> 8) & 0xff;
2356 op
[0] = (val
>> 16) & 0xff;
2359 op
[1] = (val
>> 8) & 0xff;
2360 op
[2] = (val
>> 16) & 0xff;
2364 case BFD_RELOC_RX_NEG32
:
2366 #if RX_OPCODE_BIG_ENDIAN
2368 op
[2] = (val
>> 8) & 0xff;
2369 op
[1] = (val
>> 16) & 0xff;
2370 op
[0] = (val
>> 24) & 0xff;
2373 op
[1] = (val
>> 8) & 0xff;
2374 op
[2] = (val
>> 16) & 0xff;
2375 op
[3] = (val
>> 24) & 0xff;
2379 case BFD_RELOC_RX_GPRELL
:
2381 case BFD_RELOC_RX_GPRELW
:
2383 case BFD_RELOC_RX_GPRELB
:
2384 #if RX_OPCODE_BIG_ENDIAN
2386 op
[0] = (val
>> 8) & 0xff;
2389 op
[1] = (val
>> 8) & 0xff;
2394 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2395 bfd_get_reloc_code_name (f
->fx_r_type
));
2399 if (f
->fx_addsy
== NULL
)
2404 tc_gen_reloc (asection
* sec ATTRIBUTE_UNUSED
, fixS
* fixp
)
2406 static arelent
* reloc
[5];
2407 bfd_boolean is_opcode
= FALSE
;
2409 if (fixp
->fx_r_type
== BFD_RELOC_NONE
)
2416 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2418 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2419 fixp
->fx_subsy
= NULL
;
2422 reloc
[0] = (arelent
*) xmalloc (sizeof (arelent
));
2423 reloc
[0]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2424 * reloc
[0]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2425 reloc
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2426 reloc
[0]->addend
= fixp
->fx_offset
;
2428 if (fixp
->fx_r_type
== BFD_RELOC_RX_32_OP
2431 fixp
->fx_r_type
= BFD_RELOC_RX_DIFF
;
2435 is_opcode
= sec
->flags
& SEC_CODE
;
2437 /* Certain BFD relocations cannot be translated directly into
2438 a single (non-Red Hat) RX relocation, but instead need
2439 multiple RX relocations - handle them here. */
2440 switch (fixp
->fx_r_type
)
2442 case BFD_RELOC_RX_DIFF
:
2443 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2445 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2446 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2447 * reloc
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
2448 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2449 reloc
[1]->addend
= 0;
2450 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2452 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2453 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2454 reloc
[2]->addend
= 0;
2455 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2456 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2458 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2459 switch (fixp
->fx_size
)
2462 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS8
);
2465 if (!is_opcode
&& target_big_endian
)
2466 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16_REV
);
2468 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2470 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16
);
2473 if (!is_opcode
&& target_big_endian
)
2474 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32_REV
);
2476 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2479 reloc
[3]->addend
= 0;
2480 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2481 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2486 case BFD_RELOC_RX_GPRELL
:
2487 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2489 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2490 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2491 if (gp_symbol
== NULL
)
2493 if (symbol_table_frozen
)
2497 gp
= symbol_find ("__gp");
2499 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2501 gp_symbol
= symbol_get_bfdsym (gp
);
2504 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2506 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2507 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2508 reloc
[1]->addend
= 0;
2509 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2511 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2512 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2513 reloc
[2]->addend
= 0;
2514 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2515 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2517 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2518 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UL
);
2519 reloc
[3]->addend
= 0;
2520 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2521 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2526 case BFD_RELOC_RX_GPRELW
:
2527 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2529 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2530 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2531 if (gp_symbol
== NULL
)
2533 if (symbol_table_frozen
)
2537 gp
= symbol_find ("__gp");
2539 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2541 gp_symbol
= symbol_get_bfdsym (gp
);
2544 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2546 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2547 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2548 reloc
[1]->addend
= 0;
2549 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2551 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2552 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2553 reloc
[2]->addend
= 0;
2554 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2555 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2557 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2558 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16UW
);
2559 reloc
[3]->addend
= 0;
2560 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2561 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2566 case BFD_RELOC_RX_GPRELB
:
2567 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2569 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2570 reloc
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2571 if (gp_symbol
== NULL
)
2573 if (symbol_table_frozen
)
2577 gp
= symbol_find ("__gp");
2579 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2581 gp_symbol
= symbol_get_bfdsym (gp
);
2584 gp_symbol
= symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2586 * reloc
[1]->sym_ptr_ptr
= gp_symbol
;
2587 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2588 reloc
[1]->addend
= 0;
2589 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2591 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2592 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_SUBTRACT
);
2593 reloc
[2]->addend
= 0;
2594 reloc
[2]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2595 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2597 reloc
[3] = (arelent
*) xmalloc (sizeof (arelent
));
2598 reloc
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS16U
);
2599 reloc
[3]->addend
= 0;
2600 reloc
[3]->sym_ptr_ptr
= reloc
[1]->sym_ptr_ptr
;
2601 reloc
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2606 case BFD_RELOC_RX_NEG32
:
2607 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_SYM
);
2609 reloc
[1] = (arelent
*) xmalloc (sizeof (arelent
));
2610 reloc
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_OP_NEG
);
2611 reloc
[1]->addend
= 0;
2612 reloc
[1]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2613 reloc
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2615 reloc
[2] = (arelent
*) xmalloc (sizeof (arelent
));
2616 reloc
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_RX_ABS32
);
2617 reloc
[2]->addend
= 0;
2618 reloc
[2]->sym_ptr_ptr
= reloc
[0]->sym_ptr_ptr
;
2619 reloc
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2625 reloc
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2634 rx_note_string_insn_use (void)
2636 if ((elf_flags
& E_FLAG_RX_SINSNS_MASK
) == (E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_NO
))
2637 as_bad (_("Use of an RX string instruction detected in a file being assembled without string instruction support"));
2638 elf_flags
|= E_FLAG_RX_SINSNS_SET
| E_FLAG_RX_SINSNS_YES
;
2641 /* Set the ELF specific flags. */
2644 rx_elf_final_processing (void)
2646 elf_elfheader (stdoutput
)->e_flags
|= elf_flags
;
2649 /* Scan the current input line for occurances of Renesas
2650 local labels and replace them with the GAS version. */
2653 rx_start_line (void)
2655 int in_double_quote
= 0;
2656 int in_single_quote
= 0;
2658 char * p
= input_line_pointer
;
2660 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2671 in_double_quote
= ! in_double_quote
;
2675 in_single_quote
= ! in_single_quote
;
2679 if (in_double_quote
|| in_single_quote
)
2684 else if (p
[1] == '+')
2689 else if (p
[1] == '-')