1 /* tc-rx.c -- Assembler for the Renesas RX
2 Copyright 2008-2013 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"
24 #include "safe-ctype.h"
25 #include "dwarf2dbg.h"
27 #include "elf/common.h"
30 #include "filenames.h"
35 #define RX_OPCODE_BIG_ENDIAN 0
37 const char comment_chars[] = ";";
38 /* Note that input_file.c hand checks for '#' at the beginning of the
39 first line of the input file. This is because the compiler outputs
40 #NO_APP at the beginning of its output. */
41 const char line_comment_chars[] = "#";
42 const char line_separator_chars[] = "!";
44 const char EXP_CHARS[] = "eE";
45 const char FLT_CHARS[] = "dD";
47 /* ELF flags to set in the output file header. */
48 static int elf_flags = E_FLAG_RX_ABI;
50 bfd_boolean rx_use_conventional_section_names = FALSE;
51 static bfd_boolean rx_use_small_data_limit = FALSE;
53 static bfd_boolean rx_pid_mode = FALSE;
54 static int rx_num_int_regs = 0;
58 enum rx_cpu_types rx_cpu = RX600;
60 static void rx_fetchalign (int ignore ATTRIBUTE_UNUSED);
64 OPTION_BIG = OPTION_MD_BASE,
68 OPTION_CONVENTIONAL_SECTION_NAMES,
69 OPTION_RENESAS_SECTION_NAMES,
70 OPTION_SMALL_DATA_LIMIT,
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 {NULL, no_argument, NULL, 0}
106 size_t md_longopts_size = sizeof (md_longopts);
109 md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED)
114 target_big_endian = 1;
118 target_big_endian = 0;
121 case OPTION_32BIT_DOUBLES:
122 elf_flags &= ~ E_FLAG_RX_64BIT_DOUBLES;
125 case OPTION_64BIT_DOUBLES:
126 elf_flags |= E_FLAG_RX_64BIT_DOUBLES;
129 case OPTION_CONVENTIONAL_SECTION_NAMES:
130 rx_use_conventional_section_names = TRUE;
133 case OPTION_RENESAS_SECTION_NAMES:
134 rx_use_conventional_section_names = FALSE;
137 case OPTION_SMALL_DATA_LIMIT:
138 rx_use_small_data_limit = TRUE;
147 elf_flags |= E_FLAG_RX_PID;
150 case OPTION_INT_REGS:
151 rx_num_int_regs = atoi (optarg);
154 case OPTION_USES_GCC_ABI:
155 elf_flags &= ~ E_FLAG_RX_ABI;
158 case OPTION_USES_RX_ABI:
159 elf_flags |= E_FLAG_RX_ABI;
163 if (strcasecmp (arg, "rx100") == 0)
165 else if (strcasecmp (arg, "rx200") == 0)
167 else if (strcasecmp (arg, "rx600") == 0)
169 else if (strcasecmp (arg, "rx610") == 0)
173 as_warn (_("unrecognised RX CPU type %s"), arg);
182 md_show_usage (FILE * stream)
184 fprintf (stream, _(" RX specific command line options:\n"));
185 fprintf (stream, _(" --mbig-endian-data\n"));
186 fprintf (stream, _(" --mlittle-endian-data [default]\n"));
187 fprintf (stream, _(" --m32bit-doubles [default]\n"));
188 fprintf (stream, _(" --m64bit-doubles\n"));
189 fprintf (stream, _(" --muse-conventional-section-names\n"));
190 fprintf (stream, _(" --muse-renesas-section-names [default]\n"));
191 fprintf (stream, _(" --msmall-data-limit\n"));
192 fprintf (stream, _(" --mrelax\n"));
193 fprintf (stream, _(" --mpid\n"));
194 fprintf (stream, _(" --mint-register=<value>\n"));
195 fprintf (stream, _(" --mcpu=<rx100|rx200|rx600|rx610>\n"));
199 s_bss (int ignore ATTRIBUTE_UNUSED)
203 temp = get_absolute_expression ();
204 subseg_set (bss_section, (subsegT) temp);
205 demand_empty_rest_of_line ();
209 rx_float_cons (int ignore ATTRIBUTE_UNUSED)
211 if (elf_flags & E_FLAG_RX_64BIT_DOUBLES)
212 return float_cons ('d');
213 return float_cons ('f');
217 rx_strcasestr (const char *string, const char *sub)
223 return (char *)string;
226 strl = strlen (string);
230 /* strncasecmp is in libiberty. */
231 if (strncasecmp (string, sub, subl) == 0)
232 return (char *)string;
241 rx_include (int ignore)
246 char * current_filename;
254 /* The RX version of the .INCLUDE pseudo-op does not
255 have to have the filename inside double quotes. */
257 if (*input_line_pointer == '"')
259 /* Treat as the normal GAS .include pseudo-op. */
264 /* Get the filename. Spaces are allowed, NUL characters are not. */
265 filename = input_line_pointer;
266 last_char = find_end_of_line (filename, FALSE);
267 input_line_pointer = last_char;
269 while (last_char >= filename && (* last_char == ' ' || * last_char == '\n'))
271 end_char = *(++ last_char);
273 if (last_char == filename)
275 as_bad (_("no filename following .INCLUDE pseudo-op"));
276 * last_char = end_char;
280 as_where (& current_filename, NULL);
281 f = (char *) xmalloc (strlen (current_filename) + strlen (filename) + 1);
283 /* Check the filename. If [@]..FILE[@] is found then replace
284 this with the current assembler source filename, stripped
285 of any directory prefixes or extensions. */
286 if ((p = rx_strcasestr (filename, "..file")) != NULL)
290 len = 6; /* strlen ("..file"); */
292 if (p > filename && p[-1] == '@')
298 for (d = c = current_filename; *c; c++)
299 if (IS_DIR_SEPARATOR (* c))
305 sprintf (f, "%.*s%.*s%.*s", (int) (p - filename), filename,
307 (int) (strlen (filename) - ((p + len) - filename)),
311 strcpy (f, filename);
313 /* RX .INCLUDE semantics say that 'filename' is located by:
315 1. If filename is absolute, just try that. Otherwise...
317 2. If the current source file includes a directory component
318 then prepend that to the filename and try. Otherwise...
320 3. Try any directories specified by the -I command line
323 4 .Try a directory specifed by the INC100 environment variable. */
325 if (IS_ABSOLUTE_PATH (f))
326 try = fopen (path = f, FOPEN_RT);
329 char * env = getenv ("INC100");
333 len = strlen (current_filename);
334 if ((size_t) include_dir_maxlen > len)
335 len = include_dir_maxlen;
336 if (env && strlen (env) > len)
339 path = (char *) xmalloc (strlen (f) + len + 5);
341 if (current_filename != NULL)
343 for (d = NULL, p = current_filename; *p; p++)
344 if (IS_DIR_SEPARATOR (* p))
349 sprintf (path, "%.*s/%s", (int) (d - current_filename), current_filename,
351 try = fopen (path, FOPEN_RT);
359 for (i = 0; i < include_dir_count; i++)
361 sprintf (path, "%s/%s", include_dirs[i], f);
362 if ((try = fopen (path, FOPEN_RT)) != NULL)
367 if (try == NULL && env != NULL)
369 sprintf (path, "%s/%s", env, f);
370 try = fopen (path, FOPEN_RT);
378 as_bad (_("unable to locate include file: %s"), filename);
384 register_dependency (path);
385 input_scrub_insert_file (path);
388 * last_char = end_char;
392 parse_rx_section (char * name)
396 int attr = SHF_ALLOC | SHF_EXECINSTR;
405 for (p = input_line_pointer; *p && strchr ("\n\t, =", *p) == NULL; p++)
410 if (strcasecmp (input_line_pointer, "ALIGN") == 0)
425 case '2': align = 2; break;
426 case '4': align = 4; break;
427 case '8': align = 8; break;
429 as_bad (_("unrecognised alignment value in .SECTION directive: %s"), p);
430 ignore_rest_of_line ();
438 else if (strcasecmp (input_line_pointer, "CODE") == 0)
439 attr = SHF_ALLOC | SHF_EXECINSTR;
440 else if (strcasecmp (input_line_pointer, "DATA") == 0)
441 attr = SHF_ALLOC | SHF_WRITE;
442 else if (strcasecmp (input_line_pointer, "ROMDATA") == 0)
446 as_bad (_("unknown parameter following .SECTION directive: %s"),
450 input_line_pointer = p + 1;
451 ignore_rest_of_line ();
456 input_line_pointer = p + 1;
458 while (end_char != '\n' && end_char != 0);
460 if ((sec = bfd_get_section_by_name (stdoutput, name)) == NULL)
462 if (strcmp (name, "B") && strcmp (name, "B_1") && strcmp (name, "B_2"))
467 obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
469 else /* Try not to redefine a section, especially B_1. */
471 int flags = sec->flags;
473 type = elf_section_type (sec);
475 attr = ((flags & SEC_READONLY) ? 0 : SHF_WRITE)
476 | ((flags & SEC_ALLOC) ? SHF_ALLOC : 0)
477 | ((flags & SEC_CODE) ? SHF_EXECINSTR : 0)
478 | ((flags & SEC_MERGE) ? SHF_MERGE : 0)
479 | ((flags & SEC_STRINGS) ? SHF_STRINGS : 0)
480 | ((flags & SEC_THREAD_LOCAL) ? SHF_TLS : 0);
482 obj_elf_change_section (name, type, attr, 0, NULL, FALSE, FALSE);
485 bfd_set_section_alignment (stdoutput, now_seg, align);
489 rx_section (int ignore)
493 /* The as100 assembler supports a different syntax for the .section
494 pseudo-op. So check for it and handle it here if necessary. */
497 /* Peek past the section name to see if arguments follow. */
498 for (p = input_line_pointer; *p; p++)
499 if (*p == ',' || *p == '\n')
504 int len = p - input_line_pointer;
506 while (ISSPACE (*++p))
509 if (*p != '"' && *p != '#')
511 char * name = (char *) xmalloc (len + 1);
513 strncpy (name, input_line_pointer, len);
516 input_line_pointer = p;
517 parse_rx_section (name);
522 obj_elf_section (ignore);
526 rx_list (int ignore ATTRIBUTE_UNUSED)
530 if (strncasecmp (input_line_pointer, "OFF", 3))
532 else if (strncasecmp (input_line_pointer, "ON", 2))
535 as_warn (_("expecting either ON or OFF after .list"));
538 /* Like the .rept pseudo op, but supports the
539 use of ..MACREP inside the repeated region. */
542 rx_rept (int ignore ATTRIBUTE_UNUSED)
544 int count = get_absolute_expression ();
546 do_repeat_with_expander (count, "MREPEAT", "ENDR", "..MACREP");
549 /* Like cons() accept that strings are allowed. */
556 if (* input_line_pointer == '"')
563 rx_nop (int ignore ATTRIBUTE_UNUSED)
565 ignore_rest_of_line ();
571 as_warn (_("The \".%s\" pseudo-op is not implemented\n"),
572 md_pseudo_table[idx].poc_name);
573 ignore_rest_of_line ();
576 /* The target specific pseudo-ops which we support. */
577 const pseudo_typeS md_pseudo_table[] =
579 /* These are unimplemented. They're listed first so that we can use
580 the poc_value as the index into this array, to get the name of
581 the pseudo. So, keep these (1) first, and (2) in order, with (3)
582 the poc_value's in sequence. */
583 { "btglb", rx_unimp, 0 },
584 { "call", rx_unimp, 1 },
585 { "einsf", rx_unimp, 2 },
586 { "fb", rx_unimp, 3 },
587 { "fbsym", rx_unimp, 4 },
588 { "id", rx_unimp, 5 },
589 { "initsct", rx_unimp, 6 },
590 { "insf", rx_unimp, 7 },
591 { "instr", rx_unimp, 8 },
592 { "lbba", rx_unimp, 9 },
593 { "len", rx_unimp, 10 },
594 { "optj", rx_unimp, 11 },
595 { "rvector", rx_unimp, 12 },
596 { "sb", rx_unimp, 13 },
597 { "sbbit", rx_unimp, 14 },
598 { "sbsym", rx_unimp, 15 },
599 { "sbsym16", rx_unimp, 16 },
601 /* These are the do-nothing pseudos. */
602 { "stk", rx_nop, 0 },
603 /* The manual documents ".stk" but the compiler emits ".stack". */
604 { "stack", rx_nop, 0 },
606 /* These are Renesas as100 assembler pseudo-ops that we do support. */
607 { "addr", rx_cons, 3 },
608 { "align", s_align_bytes, 2 },
609 { "byte", rx_cons, 1 },
610 { "fixed", float_cons, 'f' },
611 { "form", listing_psize, 0 },
612 { "glb", s_globl, 0 },
613 { "include", rx_include, 0 },
614 { "list", rx_list, 0 },
615 { "lword", rx_cons, 4 },
616 { "mrepeat", rx_rept, 0 },
617 { "section", rx_section, 0 },
619 /* FIXME: The following pseudo-ops place their values (and associated
620 label if present) in the data section, regardless of whatever
621 section we are currently in. At the moment this code does not
622 implement that part of the semantics. */
623 { "blka", s_space, 3 },
624 { "blkb", s_space, 1 },
625 { "blkd", s_space, 8 },
626 { "blkf", s_space, 4 },
627 { "blkl", s_space, 4 },
628 { "blkw", s_space, 2 },
630 /* Our "standard" pseudos. */
631 { "double", rx_float_cons, 0 },
633 { "3byte", cons, 3 },
637 { "fetchalign", rx_fetchalign, 0 },
639 /* End of list marker. */
643 static asymbol * gp_symbol;
644 static asymbol * rx_pid_symbol;
646 static symbolS * rx_pidreg_symbol;
647 static symbolS * rx_gpreg_symbol;
652 /* Make the __gp and __pid_base symbols now rather
653 than after the symbol table is frozen. We only do this
654 when supporting small data limits because otherwise we
655 pollute the symbol table. */
657 /* The meta-registers %pidreg and %gpreg depend on what other
658 options are specified. The __rx_*_defined symbols exist so we
659 can .ifdef asm code based on what options were passed to gas,
660 without needing a preprocessor */
664 rx_pid_register = 13 - rx_num_int_regs;
665 rx_pid_symbol = symbol_get_bfdsym (symbol_find_or_make ("__pid_base"));
666 rx_pidreg_symbol = symbol_find_or_make ("__rx_pidreg_defined");
667 S_SET_VALUE (rx_pidreg_symbol, rx_pid_register);
668 S_SET_SEGMENT (rx_pidreg_symbol, absolute_section);
671 if (rx_use_small_data_limit)
674 rx_gp_register = rx_pid_register - 1;
676 rx_gp_register = 13 - rx_num_int_regs;
677 gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
678 rx_gpreg_symbol = symbol_find_or_make ("__rx_gpreg_defined");
679 S_SET_VALUE (rx_gpreg_symbol, rx_gp_register);
680 S_SET_SEGMENT (rx_gpreg_symbol, absolute_section);
687 /* These negative numbers are found in rx_bytesT.n_base for non-opcode
689 #define RX_NBASE_FETCHALIGN -1
691 typedef struct rx_bytesT
694 /* If this is negative, it's a special-purpose frag as per the defines above. */
703 char type; /* RXREL_*. */
716 fixS *link_relax_fixP;
721 static rx_bytesT rx_bytes;
722 /* We set n_ops to be "size of next opcode" if the next opcode doesn't relax. */
723 static rx_bytesT *fetchalign_bytes = NULL;
726 rx_fetchalign (int ignore ATTRIBUTE_UNUSED)
731 memset (& rx_bytes, 0, sizeof (rx_bytes));
732 rx_bytes.n_base = RX_NBASE_FETCHALIGN;
734 bytes = frag_more (8);
735 frag_then = frag_now;
736 frag_variant (rs_machine_dependent,
743 frag_then->fr_opcode = bytes;
744 frag_then->fr_subtype = 0;
745 fetchalign_bytes = frag_then->tc_frag_data;
749 rx_relax (int type, int pos)
751 rx_bytes.relax[rx_bytes.n_relax].type = type;
752 rx_bytes.relax[rx_bytes.n_relax].field_pos = pos;
753 rx_bytes.relax[rx_bytes.n_relax].val_ofs = rx_bytes.n_base + rx_bytes.n_ops;
758 rx_linkrelax_dsp (int pos)
763 rx_bytes.link_relax |= RX_RELAXA_DSP4;
766 rx_bytes.link_relax |= RX_RELAXA_DSP6;
769 rx_bytes.link_relax |= RX_RELAXA_DSP14;
775 rx_linkrelax_imm (int pos)
780 rx_bytes.link_relax |= RX_RELAXA_IMM6;
783 rx_bytes.link_relax |= RX_RELAXA_IMM12;
789 rx_linkrelax_branch (void)
791 rx_bytes.link_relax |= RX_RELAXA_BRA;
795 rx_fixup (expressionS exp, int offsetbits, int nbits, int type)
797 rx_bytes.fixups[rx_bytes.n_fixups].exp = exp;
798 rx_bytes.fixups[rx_bytes.n_fixups].offset = offsetbits;
799 rx_bytes.fixups[rx_bytes.n_fixups].nbits = nbits;
800 rx_bytes.fixups[rx_bytes.n_fixups].type = type;
801 rx_bytes.fixups[rx_bytes.n_fixups].reloc = exp.X_md;
802 rx_bytes.n_fixups ++;
805 #define rx_field_fixup(exp, offset, nbits, type) \
806 rx_fixup (exp, offset, nbits, type)
808 #define rx_op_fixup(exp, offset, nbits, type) \
809 rx_fixup (exp, offset + 8 * rx_bytes.n_base, nbits, type)
814 rx_bytes.base[0] = b1;
819 rx_base2 (int b1, int b2)
821 rx_bytes.base[0] = b1;
822 rx_bytes.base[1] = b2;
827 rx_base3 (int b1, int b2, int b3)
829 rx_bytes.base[0] = b1;
830 rx_bytes.base[1] = b2;
831 rx_bytes.base[2] = b3;
836 rx_base4 (int b1, int b2, int b3, int b4)
838 rx_bytes.base[0] = b1;
839 rx_bytes.base[1] = b2;
840 rx_bytes.base[2] = b3;
841 rx_bytes.base[3] = b4;
845 /* This gets complicated when the field spans bytes, because fields
846 are numbered from the MSB of the first byte as zero, and bits are
847 stored LSB towards the LSB of the byte. Thus, a simple four-bit
848 insertion of 12 at position 4 of 0x00 yields: 0x0b. A three-bit
849 insertion of b'MXL at position 7 is like this:
851 - - - - - - - - - - - - - - - -
855 rx_field (int val, int pos, int sz)
862 if (val < 0 || val >= (1 << sz))
863 as_bad (_("Value %d doesn't fit in unsigned %d-bit field"), val, sz);
868 if (val < -(1 << (sz - 1)) || val >= (1 << (sz - 1)))
869 as_bad (_("Value %d doesn't fit in signed %d-bit field"), val, sz);
872 /* This code points at 'M' in the above example. */
876 while (bitp + sz > 8)
881 svalm = val >> (sz - ssz);
882 svalm = svalm & ((1 << ssz) - 1);
883 svalm = svalm << (8 - bitp - ssz);
884 gas_assert (bytep < rx_bytes.n_base);
885 rx_bytes.base[bytep] |= svalm;
891 valm = val & ((1 << sz) - 1);
892 valm = valm << (8 - bitp - sz);
893 gas_assert (bytep < rx_bytes.n_base);
894 rx_bytes.base[bytep] |= valm;
897 /* Special case of the above, for 3-bit displacements of 2..9. */
900 rx_disp3 (expressionS exp, int pos)
902 rx_field_fixup (exp, pos, 3, RXREL_PCREL);
905 /* Special case of the above, for split 5-bit displacements. Assumes
906 the displacement has been checked with rx_disp5op. */
907 /* ---- -432 1--- 0--- */
910 rx_field5s (expressionS exp)
914 val = exp.X_add_number;
915 rx_bytes.base[0] |= val >> 2;
916 rx_bytes.base[1] |= (val << 6) & 0x80;
917 rx_bytes.base[1] |= (val << 3) & 0x08;
920 /* ---- ---- 4--- 3210 */
923 rx_field5s2 (expressionS exp)
927 val = exp.X_add_number;
928 rx_bytes.base[1] |= (val << 3) & 0x80;
929 rx_bytes.base[1] |= (val ) & 0x0f;
932 #define OP(x) rx_bytes.ops[rx_bytes.n_ops++] = (x)
934 #define F_PRECISION 2
937 rx_op (expressionS exp, int nbytes, int type)
941 if ((exp.X_op == O_constant || exp.X_op == O_big)
942 && type != RXREL_PCREL)
944 if (exp.X_op == O_big && exp.X_add_number <= 0)
947 char * ip = rx_bytes.ops + rx_bytes.n_ops;
949 gen_to_words (w, F_PRECISION, 8);
950 #if RX_OPCODE_BIG_ENDIAN
965 v = exp.X_add_number;
968 #if RX_OPCODE_BIG_ENDIAN
969 OP ((v >> (8 * (nbytes - 1))) & 0xff);
980 rx_op_fixup (exp, rx_bytes.n_ops * 8, nbytes * 8, type);
981 memset (rx_bytes.ops + rx_bytes.n_ops, 0, nbytes);
982 rx_bytes.n_ops += nbytes;
992 #define APPEND(B, N_B) \
995 memcpy (bytes + idx, rx_bytes.B, rx_bytes.N_B); \
996 idx += rx_bytes.N_B; \
1000 rx_frag_init (fragS * fragP)
1002 if (rx_bytes.n_relax || rx_bytes.link_relax || rx_bytes.n_base < 0)
1004 fragP->tc_frag_data = malloc (sizeof (rx_bytesT));
1005 memcpy (fragP->tc_frag_data, & rx_bytes, sizeof (rx_bytesT));
1008 fragP->tc_frag_data = 0;
1011 /* Handle the as100's version of the .equ pseudo-op. It has the syntax:
1012 <symbol_name> .equ <expression> */
1015 rx_equ (char * name, char * expression)
1017 char saved_name_end_char;
1021 while (ISSPACE (* name))
1024 for (name_end = name + 1; *name_end; name_end ++)
1025 if (! ISALNUM (* name_end))
1028 saved_name_end_char = * name_end;
1031 saved_ilp = input_line_pointer;
1032 input_line_pointer = expression;
1036 input_line_pointer = saved_ilp;
1037 * name_end = saved_name_end_char;
1040 /* Look for Renesas as100 pseudo-ops that occur after a symbol name
1041 rather than at the start of a line. (eg .EQU or .DEFINE). If one
1042 is found, process it and return TRUE otherwise return FALSE. */
1045 scan_for_infix_rx_pseudo_ops (char * str)
1049 char * dot = strchr (str, '.');
1051 if (dot == NULL || dot == str)
1054 /* A real pseudo-op must be preceeded by whitespace. */
1055 if (dot[-1] != ' ' && dot[-1] != '\t')
1058 pseudo_op = dot + 1;
1060 if (!ISALNUM (* pseudo_op))
1063 for (p = pseudo_op + 1; ISALNUM (* p); p++)
1066 if (strncasecmp ("EQU", pseudo_op, p - pseudo_op) == 0)
1068 else if (strncasecmp ("DEFINE", pseudo_op, p - pseudo_op) == 0)
1069 as_warn (_("The .DEFINE pseudo-op is not implemented"));
1070 else if (strncasecmp ("MACRO", pseudo_op, p - pseudo_op) == 0)
1071 as_warn (_("The .MACRO pseudo-op is not implemented"));
1072 else if (strncasecmp ("BTEQU", pseudo_op, p - pseudo_op) == 0)
1073 as_warn (_("The .BTEQU pseudo-op is not implemented."));
1081 md_assemble (char * str)
1086 fragS * frag_then = frag_now;
1089 memset (& rx_bytes, 0, sizeof (rx_bytes));
1091 rx_lex_init (str, str + strlen (str));
1092 if (scan_for_infix_rx_pseudo_ops (str))
1096 /* This simplifies the relaxation code. */
1097 if (rx_bytes.n_relax || rx_bytes.link_relax)
1099 /* We do it this way because we want the frag to have the
1100 rx_bytes in it, which we initialize above. */
1101 bytes = frag_more (12);
1102 frag_then = frag_now;
1103 frag_variant (rs_machine_dependent,
1110 frag_then->fr_opcode = bytes;
1111 frag_then->fr_fix += rx_bytes.n_base + rx_bytes.n_ops;
1112 frag_then->fr_subtype = rx_bytes.n_base + rx_bytes.n_ops;
1116 bytes = frag_more (rx_bytes.n_base + rx_bytes.n_ops);
1117 frag_then = frag_now;
1118 if (fetchalign_bytes)
1119 fetchalign_bytes->n_ops = rx_bytes.n_base + rx_bytes.n_ops;
1122 fetchalign_bytes = NULL;
1124 APPEND (base, n_base);
1125 APPEND (ops, n_ops);
1127 if (rx_bytes.link_relax && rx_bytes.n_fixups)
1131 f = fix_new (frag_then,
1132 (char *) bytes - frag_then->fr_literal,
1135 rx_bytes.link_relax | rx_bytes.n_fixups,
1137 BFD_RELOC_RX_RELAX);
1138 frag_then->tc_frag_data->link_relax_fixP = f;
1141 for (i = 0; i < rx_bytes.n_fixups; i ++)
1143 /* index: [nbytes][type] */
1144 static int reloc_map[5][4] =
1146 { 0, 0, 0, BFD_RELOC_RX_DIR3U_PCREL },
1147 { BFD_RELOC_8, BFD_RELOC_RX_8U, BFD_RELOC_RX_NEG8, BFD_RELOC_8_PCREL },
1148 { BFD_RELOC_RX_16_OP, BFD_RELOC_RX_16U, BFD_RELOC_RX_NEG16, BFD_RELOC_16_PCREL },
1149 { BFD_RELOC_RX_24_OP, BFD_RELOC_RX_24U, BFD_RELOC_RX_NEG24, BFD_RELOC_24_PCREL },
1150 { BFD_RELOC_RX_32_OP, BFD_RELOC_32, BFD_RELOC_RX_NEG32, BFD_RELOC_32_PCREL },
1154 idx = rx_bytes.fixups[i].offset / 8;
1155 rel = reloc_map [rx_bytes.fixups[i].nbits / 8][(int) rx_bytes.fixups[i].type];
1157 if (rx_bytes.fixups[i].reloc)
1158 rel = rx_bytes.fixups[i].reloc;
1160 if (frag_then->tc_frag_data)
1161 exp = & frag_then->tc_frag_data->fixups[i].exp;
1163 exp = & rx_bytes.fixups[i].exp;
1165 f = fix_new_exp (frag_then,
1166 (char *) bytes + idx - frag_then->fr_literal,
1167 rx_bytes.fixups[i].nbits / 8,
1169 rx_bytes.fixups[i].type == RXREL_PCREL ? 1 : 0,
1171 if (frag_then->tc_frag_data)
1172 frag_then->tc_frag_data->fixups[i].fixP = f;
1175 dwarf2_emit_insn (idx);
1183 /* Write a value out to the object file, using the appropriate endianness. */
1186 md_number_to_chars (char * buf, valueT val, int n)
1188 if (target_big_endian)
1189 number_to_chars_bigendian (buf, val, n);
1191 number_to_chars_littleendian (buf, val, n);
1201 { "gp", BFD_RELOC_GPREL16 },
1206 md_operand (expressionS * exp ATTRIBUTE_UNUSED)
1211 for (i = 0; reloc_functions[i].fname; i++)
1213 int flen = strlen (reloc_functions[i].fname);
1215 if (input_line_pointer[0] == '%'
1216 && strncasecmp (input_line_pointer + 1, reloc_functions[i].fname, flen) == 0
1217 && input_line_pointer[flen + 1] == '(')
1219 reloc = reloc_functions[i].reloc;
1220 input_line_pointer += flen + 2;
1228 if (* input_line_pointer == ')')
1229 input_line_pointer ++;
1235 md_section_align (segT segment, valueT size)
1237 int align = bfd_get_section_alignment (stdoutput, segment);
1238 return ((size + (1 << align) - 1) & (-1 << align));
1242 static unsigned char nop_1[] = { 0x03};
1243 /* MOV.L R0,R0 - 1 cycle */
1244 static unsigned char nop_2[] = { 0xef, 0x00};
1245 /* MAX R0,R0 - 1 cycle */
1246 static unsigned char nop_3[] = { 0xfc, 0x13, 0x00 };
1247 /* MUL #1,R0 - 1 cycle */
1248 static unsigned char nop_4[] = { 0x76, 0x10, 0x01, 0x00 };
1249 /* MUL #1,R0 - 1 cycle */
1250 static unsigned char nop_5[] = { 0x77, 0x10, 0x01, 0x00, 0x00 };
1251 /* MUL #1,R0 - 1 cycle */
1252 static unsigned char nop_6[] = { 0x74, 0x10, 0x01, 0x00, 0x00, 0x00 };
1253 /* BRA.S .+7 - 1 cycle */
1254 static unsigned char nop_7[] = { 0x0F, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
1256 static unsigned char *nops[] = { NULL, nop_1, nop_2, nop_3, nop_4, nop_5, nop_6, nop_7 };
1257 #define BIGGEST_NOP 7
1259 /* When relaxing, we need to output a reloc for any .align directive
1260 so that we can retain this alignment as we adjust opcode sizes. */
1262 rx_handle_align (fragS * frag)
1264 /* If handling an alignment frag, use an optimal NOP pattern.
1265 Only do this if a fill value has not already been provided.
1266 FIXME: This test fails if the provided fill value is zero. */
1267 if ((frag->fr_type == rs_align
1268 || frag->fr_type == rs_align_code)
1269 && subseg_text_p (now_seg))
1271 int count = (frag->fr_next->fr_address
1274 unsigned char *base = (unsigned char *)frag->fr_literal + frag->fr_fix;
1278 if (count > BIGGEST_NOP)
1286 memcpy (base, nops[count], count);
1287 frag->fr_var = count;
1293 && (frag->fr_type == rs_align
1294 || frag->fr_type == rs_align_code)
1295 && frag->fr_address + frag->fr_fix > 0
1296 && frag->fr_offset > 0
1297 && now_seg != bss_section)
1299 fix_new (frag, frag->fr_fix, 0,
1300 &abs_symbol, RX_RELAXA_ALIGN + frag->fr_offset,
1301 0, BFD_RELOC_RX_RELAX);
1302 /* For the purposes of relaxation, this relocation is attached
1303 to the byte *after* the alignment - i.e. the byte that must
1305 fix_new (frag->fr_next, 0, 0,
1306 &abs_symbol, RX_RELAXA_ELIGN + frag->fr_offset,
1307 0, BFD_RELOC_RX_RELAX);
1312 md_atof (int type, char * litP, int * sizeP)
1314 return ieee_md_atof (type, litP, sizeP, target_big_endian);
1318 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
1323 /*----------------------------------------------------------------------*/
1324 /* To recap: we estimate everything based on md_estimate_size, then
1325 adjust based on rx_relax_frag. When it all settles, we call
1326 md_convert frag to update the bytes. The relaxation types and
1327 relocations are in fragP->tc_frag_data, which is a copy of that
1330 Our scheme is as follows: fr_fix has the size of the smallest
1331 opcode (like BRA.S). We store the number of total bytes we need in
1332 fr_subtype. When we're done relaxing, we use fr_subtype and the
1333 existing opcode bytes to figure out what actual opcode we need to
1334 put in there. If the fixup isn't resolvable now, we use the
1337 #define TRACE_RELAX 0
1338 #define tprintf if (TRACE_RELAX) printf
1350 /* We're looking for these types of relaxations:
1353 BRA.B 00101110 dspppppp
1354 BRA.W 00111000 dspppppp pppppppp
1355 BRA.A 00000100 dspppppp pppppppp pppppppp
1358 BEQ.B 00100000 dspppppp
1359 BEQ.W 00111010 dspppppp pppppppp
1362 BNE.B 00100001 dspppppp
1363 BNE.W 00111011 dspppppp pppppppp
1365 BSR.W 00111001 dspppppp pppppppp
1366 BSR.A 00000101 dspppppp pppppppp pppppppp
1368 Bcc.B 0010cond dspppppp
1370 Additionally, we can synthesize longer conditional branches using
1371 pairs of opcodes, one with an inverted conditional (flip LSB):
1373 Bcc.W 0010ncnd 00000110 00111000 dspppppp pppppppp
1374 Bcc.A 0010ncnd 00000111 00000100 dspppppp pppppppp pppppppp
1375 BEQ.A 00011100 00000100 dspppppp pppppppp pppppppp
1376 BNE.A 00010100 00000100 dspppppp pppppppp pppppppp */
1378 /* Given the opcode bytes at OP, figure out which opcode it is and
1379 return the type of opcode. We use this to re-encode the opcode as
1380 a different size later. */
1383 rx_opcode_type (char * op)
1385 unsigned char b = (unsigned char) op[0];
1389 case 0x08: return OT_bra;
1390 case 0x10: return OT_beq;
1391 case 0x18: return OT_bne;
1396 case 0x2e: return OT_bra;
1397 case 0x38: return OT_bra;
1398 case 0x04: return OT_bra;
1400 case 0x20: return OT_beq;
1401 case 0x3a: return OT_beq;
1403 case 0x21: return OT_bne;
1404 case 0x3b: return OT_bne;
1406 case 0x39: return OT_bsr;
1407 case 0x05: return OT_bsr;
1410 if ((b & 0xf0) == 0x20)
1416 /* Returns zero if *addrP has the target address. Else returns nonzero
1417 if we cannot compute the target address yet. */
1420 rx_frag_fix_value (fragS * fragP,
1425 addressT * sym_addr)
1428 rx_bytesT * b = fragP->tc_frag_data;
1429 expressionS * exp = & b->fixups[which].exp;
1431 if (need_diff && exp->X_op != O_subtract)
1434 if (exp->X_add_symbol)
1436 if (S_FORCE_RELOC (exp->X_add_symbol, 1))
1438 if (S_GET_SEGMENT (exp->X_add_symbol) != segment)
1440 addr += S_GET_VALUE (exp->X_add_symbol);
1443 if (exp->X_op_symbol)
1445 if (exp->X_op != O_subtract)
1447 if (S_FORCE_RELOC (exp->X_op_symbol, 1))
1449 if (S_GET_SEGMENT (exp->X_op_symbol) != segment)
1451 addr -= S_GET_VALUE (exp->X_op_symbol);
1455 addr += exp->X_add_number;
1460 /* Estimate how big the opcode is after this relax pass. The return
1461 value is the difference between fr_fix and the actual size. We
1462 compute the total size in rx_relax_frag and store it in fr_subtype,
1463 sowe only need to subtract fx_fix and return it. */
1466 md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED, segT segment ATTRIBUTE_UNUSED)
1471 tprintf ("\033[32m est frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1472 (unsigned long) (fragP->fr_address
1473 + (fragP->fr_opcode - fragP->fr_literal)),
1474 (long) fragP->fr_fix, (long) fragP->fr_var, (long) fragP->fr_offset,
1475 fragP->fr_literal, fragP->fr_opcode, fragP->fr_type, fragP->fr_subtype);
1477 /* This is the size of the opcode that's accounted for in fr_fix. */
1478 opfixsize = fragP->fr_fix - (fragP->fr_opcode - fragP->fr_literal);
1479 /* This is the size of the opcode that isn't. */
1480 delta = (fragP->fr_subtype - opfixsize);
1482 tprintf (" -> opfixsize %d delta %d\n", opfixsize, delta);
1486 /* Given a frag FRAGP, return the "next" frag that contains an
1487 opcode. Assumes the next opcode is relaxable, and thus rs_machine_dependent. */
1490 rx_next_opcode (fragS *fragP)
1493 fragP = fragP->fr_next;
1494 } while (fragP && fragP->fr_type != rs_machine_dependent);
1498 /* Given the new addresses for this relax pass, figure out how big
1499 each opcode must be. We store the total number of bytes needed in
1500 fr_subtype. The return value is the difference between the size
1501 after the last pass and the size after this pass, so we use the old
1502 fr_subtype to calculate the difference. */
1505 rx_relax_frag (segT segment ATTRIBUTE_UNUSED, fragS * fragP, long stretch)
1507 addressT addr0, sym_addr;
1510 int oldsize = fragP->fr_subtype;
1511 int newsize = oldsize;
1513 /* Index of relaxation we care about. */
1516 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",
1517 (unsigned long) (fragP->fr_address
1518 + (fragP->fr_opcode - fragP->fr_literal)),
1519 (long) fragP->fr_fix, (long) fragP->fr_var, (long) fragP->fr_offset,
1520 fragP->fr_literal, fragP->fr_opcode, fragP->fr_type, fragP->fr_subtype, stretch);
1522 mypc = fragP->fr_address + (fragP->fr_opcode - fragP->fr_literal);
1524 if (fragP->tc_frag_data->n_base == RX_NBASE_FETCHALIGN)
1526 unsigned int next_size;
1527 if (fragP->fr_next == NULL)
1530 next_size = fragP->tc_frag_data->n_ops;
1533 fragS *n = rx_next_opcode (fragP);
1534 next_size = n->fr_subtype;
1537 fragP->fr_subtype = (8-(mypc & 7)) & 7;
1538 tprintf("subtype %u\n", fragP->fr_subtype);
1539 if (fragP->fr_subtype >= next_size)
1540 fragP->fr_subtype = 0;
1541 tprintf ("\033[34m -> mypc %lu next_size %u new %d old %d delta %d (fetchalign)\033[0m\n",
1543 next_size, fragP->fr_subtype, oldsize, fragP->fr_subtype-oldsize);
1545 newsize = fragP->fr_subtype;
1547 return newsize - oldsize;
1550 optype = rx_opcode_type (fragP->fr_opcode);
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. */
1560 if (rx_frag_fix_value (fragP, segment, ri, & addr0,
1561 fragP->tc_frag_data->relax[ri].type != RX_RELAX_BRANCH,
1564 /* If we don't, we must use the maximum size for the linker.
1565 Note that we don't use synthetically expanded conditionals
1567 switch (fragP->tc_frag_data->relax[ri].type)
1569 case RX_RELAX_BRANCH:
1590 newsize = fragP->tc_frag_data->relax[ri].val_ofs + 4;
1593 fragP->fr_subtype = newsize;
1594 tprintf (" -> new %d old %d delta %d (external)\n", newsize, oldsize, newsize-oldsize);
1595 return newsize - oldsize;
1598 if (sym_addr > mypc)
1601 switch (fragP->tc_frag_data->relax[ri].type)
1603 case RX_RELAX_BRANCH:
1604 tprintf ("branch, addr %08lx pc %08lx disp %ld\n",
1605 (unsigned long) addr0, (unsigned long) mypc,
1606 (long) (addr0 - mypc));
1607 disp = (int) addr0 - (int) mypc;
1612 if (disp >= -128 && (disp - (oldsize-2)) <= 127)
1615 else if (disp >= -32768 && (disp - (oldsize-5)) <= 32767)
1625 if ((disp - (oldsize-1)) >= 3 && (disp - (oldsize-1)) <= 10 && !linkrelax)
1628 else if (disp >= -128 && (disp - (oldsize-2)) <= 127)
1631 else if (disp >= -32768 && (disp - (oldsize-3)) <= 32767)
1641 if ((disp - (oldsize-1)) >= 3 && (disp - (oldsize-1)) <= 10 && !linkrelax)
1644 else if (disp >= -128 && (disp - (oldsize-2)) <= 127)
1647 else if (disp >= -32768 && (disp - (oldsize-3)) <= 32767)
1658 tprintf (" - newsize %d\n", newsize);
1662 tprintf ("other, addr %08lx pc %08lx LI %d OF %d\n",
1663 (unsigned long) addr0, (unsigned long) mypc,
1664 fragP->tc_frag_data->relax[ri].field_pos,
1665 fragP->tc_frag_data->relax[ri].val_ofs);
1667 newsize = fragP->tc_frag_data->relax[ri].val_ofs;
1669 if ((long) addr0 >= -128 && (long) addr0 <= 127)
1671 else if ((long) addr0 >= -32768 && (long) addr0 <= 32767)
1673 else if ((long) addr0 >= -8388608 && (long) addr0 <= 8388607)
1683 if (fragP->tc_frag_data->relax[ri].type == RX_RELAX_BRANCH)
1699 /* This prevents infinite loops in align-heavy sources. */
1700 if (newsize < oldsize)
1702 if (fragP->tc_frag_data->times_shrank > 10
1703 && fragP->tc_frag_data->times_grown > 10)
1705 if (fragP->tc_frag_data->times_shrank < 20)
1706 fragP->tc_frag_data->times_shrank ++;
1708 else if (newsize > oldsize)
1710 if (fragP->tc_frag_data->times_grown < 20)
1711 fragP->tc_frag_data->times_grown ++;
1714 fragP->fr_subtype = newsize;
1715 tprintf (" -> new %d old %d delta %d\n", newsize, oldsize, newsize-oldsize);
1716 return newsize - oldsize;
1719 /* This lets us test for the opcode type and the desired size in a
1720 switch statement. */
1721 #define OPCODE(type,size) ((type) * 16 + (size))
1723 /* Given the opcode stored in fr_opcode and the number of bytes we
1724 think we need, encode a new opcode. We stored a pointer to the
1725 fixup for this opcode in the tc_frag_data structure. If we can do
1726 the fixup here, we change the relocation type to "none" (we test
1727 for that in tc_gen_reloc) else we change it to the right type for
1728 the new (biggest) opcode. */
1731 md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
1732 segT segment ATTRIBUTE_UNUSED,
1733 fragS * fragP ATTRIBUTE_UNUSED)
1735 rx_bytesT * rxb = fragP->tc_frag_data;
1736 addressT addr0, mypc;
1738 int reloc_type, reloc_adjust;
1739 char * op = fragP->fr_opcode;
1742 int fi = (rxb->n_fixups > 1) ? 1 : 0;
1743 fixS * fix = rxb->fixups[fi].fixP;
1745 tprintf ("\033[31mconvrt frag: addr %08lx fix %ld var %ld ofs %ld lit %p opc %p type %d sub %d\033[0m\n",
1746 (unsigned long) (fragP->fr_address
1747 + (fragP->fr_opcode - fragP->fr_literal)),
1748 (long) fragP->fr_fix, (long) fragP->fr_var, (long) fragP->fr_offset,
1749 fragP->fr_literal, fragP->fr_opcode, fragP->fr_type,
1756 printf ("lit 0x%p opc 0x%p", fragP->fr_literal, fragP->fr_opcode);
1757 for (i = 0; i < 10; i++)
1758 printf (" %02x", (unsigned char) (fragP->fr_opcode[i]));
1763 if (fragP->tc_frag_data->n_base == RX_NBASE_FETCHALIGN)
1765 int count = fragP->fr_subtype;
1768 else if (count > BIGGEST_NOP)
1775 memcpy (op, nops[count], count);
1779 /* In the one case where we have both a disp and imm relaxation, we want
1780 the imm relaxation here. */
1782 if (fragP->tc_frag_data->n_relax > 1
1783 && fragP->tc_frag_data->relax[0].type == RX_RELAX_DISP)
1786 /* We used a new frag for this opcode, so the opcode address should
1787 be the frag address. */
1788 mypc = fragP->fr_address + (fragP->fr_opcode - fragP->fr_literal);
1790 /* Try to get the target address. If we fail here, we just use the
1792 if (rx_frag_fix_value (fragP, segment, 0, & addr0,
1793 fragP->tc_frag_data->relax[ri].type != RX_RELAX_BRANCH, 0))
1795 /* We don't know the target address. */
1802 /* We know the target address, and it's in addr0. */
1803 disp = (int) addr0 - (int) mypc;
1809 reloc_type = BFD_RELOC_NONE;
1812 tprintf ("convert, op is %d, disp %d (%lx-%lx)\n",
1813 rx_opcode_type (fragP->fr_opcode), disp,
1814 (unsigned long) addr0, (unsigned long) mypc);
1815 switch (fragP->tc_frag_data->relax[ri].type)
1817 case RX_RELAX_BRANCH:
1818 switch (OPCODE (rx_opcode_type (fragP->fr_opcode), fragP->fr_subtype))
1820 case OPCODE (OT_bra, 1): /* BRA.S - no change. */
1821 op[0] = 0x08 + (disp & 7);
1823 case OPCODE (OT_bra, 2): /* BRA.B - 8 bit. */
1826 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
1829 case OPCODE (OT_bra, 3): /* BRA.W - 16 bit. */
1831 #if RX_OPCODE_BIG_ENDIAN
1832 op[1] = (disp >> 8) & 0xff;
1835 op[2] = (disp >> 8) & 0xff;
1839 reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
1841 case OPCODE (OT_bra, 4): /* BRA.A - 24 bit. */
1843 #if RX_OPCODE_BIG_ENDIAN
1844 op[1] = (disp >> 16) & 0xff;
1845 op[2] = (disp >> 8) & 0xff;
1848 op[3] = (disp >> 16) & 0xff;
1849 op[2] = (disp >> 8) & 0xff;
1852 reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
1856 case OPCODE (OT_beq, 1): /* BEQ.S - no change. */
1857 op[0] = 0x10 + (disp & 7);
1859 case OPCODE (OT_beq, 2): /* BEQ.B - 8 bit. */
1863 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
1865 case OPCODE (OT_beq, 3): /* BEQ.W - 16 bit. */
1867 #if RX_OPCODE_BIG_ENDIAN
1868 op[1] = (disp >> 8) & 0xff;
1871 op[2] = (disp >> 8) & 0xff;
1874 reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
1877 case OPCODE (OT_beq, 5): /* BEQ.A - synthetic. */
1878 op[0] = 0x1d; /* bne.s .+5. */
1879 op[1] = 0x04; /* bra.a dsp:24. */
1881 #if RX_OPCODE_BIG_ENDIAN
1882 op[2] = (disp >> 16) & 0xff;
1883 op[3] = (disp >> 8) & 0xff;
1886 op[4] = (disp >> 16) & 0xff;
1887 op[3] = (disp >> 8) & 0xff;
1890 reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
1894 case OPCODE (OT_bne, 1): /* BNE.S - no change. */
1895 op[0] = 0x18 + (disp & 7);
1897 case OPCODE (OT_bne, 2): /* BNE.B - 8 bit. */
1901 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
1903 case OPCODE (OT_bne, 3): /* BNE.W - 16 bit. */
1905 #if RX_OPCODE_BIG_ENDIAN
1906 op[1] = (disp >> 8) & 0xff;
1909 op[2] = (disp >> 8) & 0xff;
1912 reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
1915 case OPCODE (OT_bne, 5): /* BNE.A - synthetic. */
1916 op[0] = 0x15; /* beq.s .+5. */
1917 op[1] = 0x04; /* bra.a dsp:24. */
1919 #if RX_OPCODE_BIG_ENDIAN
1920 op[2] = (disp >> 16) & 0xff;
1921 op[3] = (disp >> 8) & 0xff;
1924 op[4] = (disp >> 16) & 0xff;
1925 op[3] = (disp >> 8) & 0xff;
1928 reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
1932 case OPCODE (OT_bsr, 3): /* BSR.W - 16 bit. */
1934 #if RX_OPCODE_BIG_ENDIAN
1935 op[1] = (disp >> 8) & 0xff;
1938 op[2] = (disp >> 8) & 0xff;
1941 reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
1944 case OPCODE (OT_bsr, 4): /* BSR.A - 24 bit. */
1946 #if RX_OPCODE_BIG_ENDIAN
1947 op[1] = (disp >> 16) & 0xff;
1948 op[2] = (disp >> 8) & 0xff;
1951 op[3] = (disp >> 16) & 0xff;
1952 op[2] = (disp >> 8) & 0xff;
1955 reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
1959 case OPCODE (OT_bcc, 2): /* Bcond.B - 8 bit. */
1961 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE;
1963 case OPCODE (OT_bcc, 5): /* Bcond.W - synthetic. */
1964 op[0] ^= 1; /* Invert condition. */
1965 op[1] = 5; /* Displacement. */
1968 #if RX_OPCODE_BIG_ENDIAN
1969 op[3] = (disp >> 8) & 0xff;
1972 op[4] = (disp >> 8) & 0xff;
1975 reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE;
1978 case OPCODE (OT_bcc, 6): /* Bcond.S - synthetic. */
1979 op[0] ^= 1; /* Invert condition. */
1980 op[1] = 6; /* Displacement. */
1983 #if RX_OPCODE_BIG_ENDIAN
1984 op[3] = (disp >> 16) & 0xff;
1985 op[4] = (disp >> 8) & 0xff;
1988 op[5] = (disp >> 16) & 0xff;
1989 op[4] = (disp >> 8) & 0xff;
1992 reloc_type = keep_reloc ? BFD_RELOC_24_PCREL : BFD_RELOC_NONE;
1997 /* These are opcodes we'll relax in th linker, later. */
1999 reloc_type = rxb->fixups[ri].fixP->fx_r_type;
2006 int nbytes = fragP->fr_subtype - fragP->tc_frag_data->relax[ri].val_ofs;
2008 char * imm = op + fragP->tc_frag_data->relax[ri].val_ofs;
2015 reloc_type = BFD_RELOC_8;
2019 #if RX_OPCODE_BIG_ENDIAN
2021 imm[0] = addr0 >> 8;
2024 imm[1] = addr0 >> 8;
2026 reloc_type = BFD_RELOC_RX_16_OP;
2030 #if RX_OPCODE_BIG_ENDIAN
2032 imm[1] = addr0 >> 8;
2033 imm[0] = addr0 >> 16;
2036 imm[1] = addr0 >> 8;
2037 imm[2] = addr0 >> 16;
2039 reloc_type = BFD_RELOC_RX_24_OP;
2043 #if RX_OPCODE_BIG_ENDIAN
2045 imm[2] = addr0 >> 8;
2046 imm[1] = addr0 >> 16;
2047 imm[0] = addr0 >> 24;
2050 imm[1] = addr0 >> 8;
2051 imm[2] = addr0 >> 16;
2052 imm[3] = addr0 >> 24;
2054 reloc_type = BFD_RELOC_RX_32_OP;
2057 as_bad (_("invalid immediate size"));
2061 switch (fragP->tc_frag_data->relax[ri].field_pos)
2076 as_bad (_("invalid immediate field position"));
2084 reloc_type = fix->fx_r_type;
2093 fix->fx_r_type = reloc_type;
2094 fix->fx_where += reloc_adjust;
2097 case BFD_RELOC_NONE:
2103 case BFD_RELOC_16_PCREL:
2104 case BFD_RELOC_RX_16_OP:
2107 case BFD_RELOC_24_PCREL:
2108 case BFD_RELOC_RX_24_OP:
2111 case BFD_RELOC_RX_32_OP:
2117 fragP->fr_fix = fragP->fr_subtype + (fragP->fr_opcode - fragP->fr_literal);
2118 tprintf ("fragP->fr_fix now %ld (%d + (%p - %p)\n", (long) fragP->fr_fix,
2119 fragP->fr_subtype, fragP->fr_opcode, fragP->fr_literal);
2122 if (fragP->fr_next != NULL
2123 && ((offsetT) (fragP->fr_next->fr_address - fragP->fr_address)
2125 as_bad (_("bad frag at %p : fix %ld addr %ld %ld \n"), fragP,
2126 (long) fragP->fr_fix,
2127 (long) fragP->fr_address, (long) fragP->fr_next->fr_address);
2133 rx_validate_fix_sub (struct fix * f)
2135 /* We permit the subtraction of two symbols in a few cases. */
2136 /* mov #sym1-sym2, R3 */
2137 if (f->fx_r_type == BFD_RELOC_RX_32_OP)
2139 /* .long sym1-sym2 */
2140 if (f->fx_r_type == BFD_RELOC_RX_DIFF
2142 && (f->fx_size == 4 || f->fx_size == 2 || f->fx_size == 1))
2148 md_pcrel_from_section (fixS * fixP, segT sec)
2152 if (fixP->fx_addsy != NULL
2153 && (! S_IS_DEFINED (fixP->fx_addsy)
2154 || S_GET_SEGMENT (fixP->fx_addsy) != sec))
2155 /* The symbol is undefined (or is defined but not in this section).
2156 Let the linker figure it out. */
2159 rv = fixP->fx_frag->fr_address + fixP->fx_where;
2160 switch (fixP->fx_r_type)
2162 case BFD_RELOC_RX_DIR3U_PCREL:
2170 rx_cons_fix_new (fragS * frag,
2175 bfd_reloc_code_real_type type;
2183 type = BFD_RELOC_16;
2186 type = BFD_RELOC_24;
2189 type = BFD_RELOC_32;
2192 as_bad (_("unsupported constant size %d\n"), size);
2196 if (exp->X_op == O_subtract && exp->X_op_symbol)
2198 if (size != 4 && size != 2 && size != 1)
2199 as_bad (_("difference of two symbols only supported with .long, .short, or .byte"));
2201 type = BFD_RELOC_RX_DIFF;
2204 fix_new_exp (frag, where, (int) size, exp, 0, type);
2208 md_apply_fix (struct fix * f ATTRIBUTE_UNUSED,
2209 valueT * t ATTRIBUTE_UNUSED,
2210 segT s ATTRIBUTE_UNUSED)
2212 /* Instruction bytes are always little endian. */
2216 if (f->fx_addsy && S_FORCE_RELOC (f->fx_addsy, 1))
2218 if (f->fx_subsy && S_FORCE_RELOC (f->fx_subsy, 1))
2221 #define OP2(x) op[target_big_endian ? 1-x : x]
2222 #define OP3(x) op[target_big_endian ? 2-x : x]
2223 #define OP4(x) op[target_big_endian ? 3-x : x]
2225 op = f->fx_frag->fr_literal + f->fx_where;
2226 val = (unsigned long) * t;
2228 /* Opcode words are always the same endian. Data words are either
2229 big or little endian. */
2231 switch (f->fx_r_type)
2233 case BFD_RELOC_NONE:
2236 case BFD_RELOC_RX_RELAX:
2240 case BFD_RELOC_RX_DIR3U_PCREL:
2241 if (val < 3 || val > 10)
2242 as_bad_where (f->fx_file, f->fx_line,
2243 _("jump not 3..10 bytes away (is %d)"), (int) val);
2245 op[0] |= val & 0x07;
2249 case BFD_RELOC_8_PCREL:
2250 case BFD_RELOC_RX_8U:
2255 OP2(1) = val & 0xff;
2256 OP2(0) = (val >> 8) & 0xff;
2259 case BFD_RELOC_16_PCREL:
2260 case BFD_RELOC_RX_16_OP:
2261 case BFD_RELOC_RX_16U:
2262 #if RX_OPCODE_BIG_ENDIAN
2264 op[0] = (val >> 8) & 0xff;
2267 op[1] = (val >> 8) & 0xff;
2272 OP3(0) = val & 0xff;
2273 OP3(1) = (val >> 8) & 0xff;
2274 OP3(2) = (val >> 16) & 0xff;
2277 case BFD_RELOC_24_PCREL:
2278 case BFD_RELOC_RX_24_OP:
2279 case BFD_RELOC_RX_24U:
2280 #if RX_OPCODE_BIG_ENDIAN
2282 op[1] = (val >> 8) & 0xff;
2283 op[0] = (val >> 16) & 0xff;
2286 op[1] = (val >> 8) & 0xff;
2287 op[2] = (val >> 16) & 0xff;
2291 case BFD_RELOC_RX_DIFF:
2298 OP2(0) = val & 0xff;
2299 OP2(1) = (val >> 8) & 0xff;
2302 OP4(0) = val & 0xff;
2303 OP4(1) = (val >> 8) & 0xff;
2304 OP4(2) = (val >> 16) & 0xff;
2305 OP4(3) = (val >> 24) & 0xff;
2311 OP4(0) = val & 0xff;
2312 OP4(1) = (val >> 8) & 0xff;
2313 OP4(2) = (val >> 16) & 0xff;
2314 OP4(3) = (val >> 24) & 0xff;
2317 case BFD_RELOC_RX_32_OP:
2318 #if RX_OPCODE_BIG_ENDIAN
2320 op[2] = (val >> 8) & 0xff;
2321 op[1] = (val >> 16) & 0xff;
2322 op[0] = (val >> 24) & 0xff;
2325 op[1] = (val >> 8) & 0xff;
2326 op[2] = (val >> 16) & 0xff;
2327 op[3] = (val >> 24) & 0xff;
2331 case BFD_RELOC_RX_NEG8:
2335 case BFD_RELOC_RX_NEG16:
2337 #if RX_OPCODE_BIG_ENDIAN
2339 op[0] = (val >> 8) & 0xff;
2342 op[1] = (val >> 8) & 0xff;
2346 case BFD_RELOC_RX_NEG24:
2348 #if RX_OPCODE_BIG_ENDIAN
2350 op[1] = (val >> 8) & 0xff;
2351 op[0] = (val >> 16) & 0xff;
2354 op[1] = (val >> 8) & 0xff;
2355 op[2] = (val >> 16) & 0xff;
2359 case BFD_RELOC_RX_NEG32:
2361 #if RX_OPCODE_BIG_ENDIAN
2363 op[2] = (val >> 8) & 0xff;
2364 op[1] = (val >> 16) & 0xff;
2365 op[0] = (val >> 24) & 0xff;
2368 op[1] = (val >> 8) & 0xff;
2369 op[2] = (val >> 16) & 0xff;
2370 op[3] = (val >> 24) & 0xff;
2374 case BFD_RELOC_RX_GPRELL:
2376 case BFD_RELOC_RX_GPRELW:
2378 case BFD_RELOC_RX_GPRELB:
2379 #if RX_OPCODE_BIG_ENDIAN
2381 op[0] = (val >> 8) & 0xff;
2384 op[1] = (val >> 8) & 0xff;
2389 as_bad (_("Unknown reloc in md_apply_fix: %s"),
2390 bfd_get_reloc_code_name (f->fx_r_type));
2394 if (f->fx_addsy == NULL)
2399 tc_gen_reloc (asection * sec ATTRIBUTE_UNUSED, fixS * fixp)
2401 static arelent * reloc[5];
2402 bfd_boolean is_opcode = FALSE;
2404 if (fixp->fx_r_type == BFD_RELOC_NONE)
2411 && S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
2413 fixp->fx_offset -= S_GET_VALUE (fixp->fx_subsy);
2414 fixp->fx_subsy = NULL;
2417 reloc[0] = (arelent *) xmalloc (sizeof (arelent));
2418 reloc[0]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2419 * reloc[0]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2420 reloc[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2421 reloc[0]->addend = fixp->fx_offset;
2423 if (fixp->fx_r_type == BFD_RELOC_RX_32_OP
2426 fixp->fx_r_type = BFD_RELOC_RX_DIFF;
2430 is_opcode = sec->flags & SEC_CODE;
2432 /* Certain BFD relocations cannot be translated directly into
2433 a single (non-Red Hat) RX relocation, but instead need
2434 multiple RX relocations - handle them here. */
2435 switch (fixp->fx_r_type)
2437 case BFD_RELOC_RX_DIFF:
2438 reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2440 reloc[1] = (arelent *) xmalloc (sizeof (arelent));
2441 reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2442 * reloc[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
2443 reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2444 reloc[1]->addend = 0;
2445 reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2447 reloc[2] = (arelent *) xmalloc (sizeof (arelent));
2448 reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
2449 reloc[2]->addend = 0;
2450 reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2451 reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2453 reloc[3] = (arelent *) xmalloc (sizeof (arelent));
2454 switch (fixp->fx_size)
2457 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS8);
2460 if (!is_opcode && target_big_endian)
2461 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16_REV);
2463 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16UL);
2465 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16);
2468 if (!is_opcode && target_big_endian)
2469 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS32_REV);
2471 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS32);
2474 reloc[3]->addend = 0;
2475 reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2476 reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2481 case BFD_RELOC_RX_GPRELL:
2482 reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2484 reloc[1] = (arelent *) xmalloc (sizeof (arelent));
2485 reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2486 if (gp_symbol == NULL)
2488 if (symbol_table_frozen)
2492 gp = symbol_find ("__gp");
2494 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2496 gp_symbol = symbol_get_bfdsym (gp);
2499 gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2501 * reloc[1]->sym_ptr_ptr = gp_symbol;
2502 reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2503 reloc[1]->addend = 0;
2504 reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2506 reloc[2] = (arelent *) xmalloc (sizeof (arelent));
2507 reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
2508 reloc[2]->addend = 0;
2509 reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2510 reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2512 reloc[3] = (arelent *) xmalloc (sizeof (arelent));
2513 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16UL);
2514 reloc[3]->addend = 0;
2515 reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2516 reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2521 case BFD_RELOC_RX_GPRELW:
2522 reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2524 reloc[1] = (arelent *) xmalloc (sizeof (arelent));
2525 reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2526 if (gp_symbol == NULL)
2528 if (symbol_table_frozen)
2532 gp = symbol_find ("__gp");
2534 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2536 gp_symbol = symbol_get_bfdsym (gp);
2539 gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2541 * reloc[1]->sym_ptr_ptr = gp_symbol;
2542 reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2543 reloc[1]->addend = 0;
2544 reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2546 reloc[2] = (arelent *) xmalloc (sizeof (arelent));
2547 reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
2548 reloc[2]->addend = 0;
2549 reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2550 reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2552 reloc[3] = (arelent *) xmalloc (sizeof (arelent));
2553 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16UW);
2554 reloc[3]->addend = 0;
2555 reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2556 reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2561 case BFD_RELOC_RX_GPRELB:
2562 reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2564 reloc[1] = (arelent *) xmalloc (sizeof (arelent));
2565 reloc[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2566 if (gp_symbol == NULL)
2568 if (symbol_table_frozen)
2572 gp = symbol_find ("__gp");
2574 as_bad (("unable to create __gp symbol: please re-assemble with the -msmall-data-limit option specified"));
2576 gp_symbol = symbol_get_bfdsym (gp);
2579 gp_symbol = symbol_get_bfdsym (symbol_find_or_make ("__gp"));
2581 * reloc[1]->sym_ptr_ptr = gp_symbol;
2582 reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2583 reloc[1]->addend = 0;
2584 reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2586 reloc[2] = (arelent *) xmalloc (sizeof (arelent));
2587 reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_SUBTRACT);
2588 reloc[2]->addend = 0;
2589 reloc[2]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2590 reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2592 reloc[3] = (arelent *) xmalloc (sizeof (arelent));
2593 reloc[3]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS16U);
2594 reloc[3]->addend = 0;
2595 reloc[3]->sym_ptr_ptr = reloc[1]->sym_ptr_ptr;
2596 reloc[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2601 case BFD_RELOC_RX_NEG32:
2602 reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_SYM);
2604 reloc[1] = (arelent *) xmalloc (sizeof (arelent));
2605 reloc[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_OP_NEG);
2606 reloc[1]->addend = 0;
2607 reloc[1]->sym_ptr_ptr = reloc[0]->sym_ptr_ptr;
2608 reloc[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2610 reloc[2] = (arelent *) xmalloc (sizeof (arelent));
2611 reloc[2]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RX_ABS32);
2612 reloc[2]->addend = 0;
2613 reloc[2]->sym_ptr_ptr = reloc[0]->sym_ptr_ptr;
2614 reloc[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2620 reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2628 /* Set the ELF specific flags. */
2631 rx_elf_final_processing (void)
2633 elf_elfheader (stdoutput)->e_flags |= elf_flags;
2636 /* Scan the current input line for occurances of Renesas
2637 local labels and replace them with the GAS version. */
2640 rx_start_line (void)
2642 int in_double_quote = 0;
2643 int in_single_quote = 0;
2645 char * p = input_line_pointer;
2647 /* Scan the line looking for question marks. Skip past quote enclosed regions. */
2658 in_double_quote = ! in_double_quote;
2662 in_single_quote = ! in_single_quote;
2666 if (in_double_quote || in_single_quote)
2671 else if (p[1] == '+')
2676 else if (p[1] == '-')