1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation.
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 2, 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
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "opcode/v850.h"
31 /* sign-extend a 16-bit number */
32 #define SEXT16(x) ((((x) & 0xffff) ^ (~ 0x7fff)) + 0x8000)
34 /* Temporarily holds the reloc in a cons expression. */
35 static bfd_reloc_code_real_type hold_cons_reloc;
37 /* Set to TRUE if we want to be pedantic about signed overflows. */
38 static boolean warn_signed_overflows = FALSE;
39 static boolean warn_unsigned_overflows = FALSE;
41 /* Indicates the target BFD machine number. */
42 static int machine = -1;
44 /* Indicates the target processor(s) for the assemble. */
45 static unsigned int processor_mask = -1;
48 /* Structure to hold information about predefined registers. */
55 /* Generic assembler global variables which must be defined by all targets. */
57 /* Characters which always start a comment. */
58 const char comment_chars[] = "#";
60 /* Characters which start a comment at the beginning of a line. */
61 const char line_comment_chars[] = ";#";
63 /* Characters which may be used to separate multiple commands on a
65 const char line_separator_chars[] = ";";
67 /* Characters which are used to indicate an exponent in a floating
69 const char EXP_CHARS[] = "eE";
71 /* Characters which mean that a number is a floating point constant,
73 const char FLT_CHARS[] = "dD";
76 const relax_typeS md_relax_table[] =
78 /* Conditional branches. */
80 {0x1fffff, -0x200000, 6, 0},
81 /* Unconditional branches. */
83 {0x1fffff, -0x200000, 4, 0},
87 static segT sdata_section = NULL;
88 static segT tdata_section = NULL;
89 static segT zdata_section = NULL;
90 static segT sbss_section = NULL;
91 static segT tbss_section = NULL;
92 static segT zbss_section = NULL;
93 static segT rosdata_section = NULL;
94 static segT rozdata_section = NULL;
95 static segT scommon_section = NULL;
96 static segT tcommon_section = NULL;
97 static segT zcommon_section = NULL;
98 /* start-sanitize-v850e */
99 static segT call_table_data_section = NULL;
100 static segT call_table_text_section = NULL;
101 /* end-sanitize-v850e */
104 #define MAX_INSN_FIXUPS (5)
109 bfd_reloc_code_real_type reloc;
112 struct v850_fixup fixups [MAX_INSN_FIXUPS];
117 v850_sdata (int ignore)
119 obj_elf_section_change_hook();
121 subseg_set (sdata_section, (subsegT) get_absolute_expression ());
123 demand_empty_rest_of_line ();
127 v850_tdata (int ignore)
129 obj_elf_section_change_hook();
131 subseg_set (tdata_section, (subsegT) get_absolute_expression ());
133 demand_empty_rest_of_line ();
137 v850_zdata (int ignore)
139 obj_elf_section_change_hook();
141 subseg_set (zdata_section, (subsegT) get_absolute_expression ());
143 demand_empty_rest_of_line ();
147 v850_sbss (int ignore)
149 obj_elf_section_change_hook();
151 subseg_set (sbss_section, (subsegT) get_absolute_expression ());
153 demand_empty_rest_of_line ();
157 v850_tbss (int ignore)
159 obj_elf_section_change_hook();
161 subseg_set (tbss_section, (subsegT) get_absolute_expression ());
163 demand_empty_rest_of_line ();
167 v850_zbss (int ignore)
169 obj_elf_section_change_hook();
171 subseg_set (zbss_section, (subsegT) get_absolute_expression ());
173 demand_empty_rest_of_line ();
177 v850_rosdata (int ignore)
179 obj_elf_section_change_hook();
181 subseg_set (rosdata_section, (subsegT) get_absolute_expression ());
183 demand_empty_rest_of_line ();
187 v850_rozdata (int ignore)
189 obj_elf_section_change_hook();
191 subseg_set (rozdata_section, (subsegT) get_absolute_expression ());
193 demand_empty_rest_of_line ();
196 /* start-sanitize-v850e */
198 v850_call_table_data (int ignore)
200 obj_elf_section_change_hook();
202 subseg_set (call_table_data_section, (subsegT) get_absolute_expression ());
204 demand_empty_rest_of_line ();
208 v850_call_table_text (int ignore)
210 obj_elf_section_change_hook();
212 subseg_set (call_table_text_section, (subsegT) get_absolute_expression ());
214 demand_empty_rest_of_line ();
216 /* end-sanitize-v850e */
219 v850_bss (int ignore)
221 register int temp = get_absolute_expression ();
223 obj_elf_section_change_hook();
225 subseg_set (bss_section, (subsegT) temp);
227 demand_empty_rest_of_line ();
231 v850_offset (int ignore)
233 int temp = get_absolute_expression ();
235 temp -= frag_now_fix();
238 (void) frag_more (temp);
240 demand_empty_rest_of_line ();
243 /* Copied from obj_elf_common() in gas/config/obj-elf.c */
256 name = input_line_pointer;
257 c = get_symbol_end ();
259 /* just after name is now '\0' */
260 p = input_line_pointer;
265 if (*input_line_pointer != ',')
267 as_bad (_("Expected comma after symbol-name"));
268 ignore_rest_of_line ();
272 input_line_pointer++; /* skip ',' */
274 if ((temp = get_absolute_expression ()) < 0)
276 /* xgettext:c-format */
277 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp);
278 ignore_rest_of_line ();
284 symbolP = symbol_find_or_make (name);
287 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
289 as_bad (_("Ignoring attempt to re-define symbol"));
290 ignore_rest_of_line ();
294 if (S_GET_VALUE (symbolP) != 0)
296 if (S_GET_VALUE (symbolP) != size)
298 /* xgettext:c-format */
299 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
300 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
304 know (symbolP->sy_frag == & zero_address_frag);
306 if (*input_line_pointer != ',')
311 input_line_pointer++;
315 if (! have_align || *input_line_pointer != '"')
321 temp = get_absolute_expression ();
325 as_warn (_("Common alignment negative; 0 assumed"));
337 applicable = bfd_applicable_section_flags (stdoutput);
339 applicable &= SEC_ALLOC;
344 if (sbss_section == NULL)
346 sbss_section = subseg_new (".sbss", 0);
348 bfd_set_section_flags (stdoutput, sbss_section, applicable);
350 seg_info (sbss_section)->bss = 1;
355 if (zbss_section == NULL)
357 zbss_section = subseg_new (".zbss", 0);
359 bfd_set_section_flags (stdoutput, sbss_section, applicable);
361 seg_info (zbss_section)->bss = 1;
366 if (tbss_section == NULL)
368 tbss_section = subseg_new (".tbss", 0);
370 bfd_set_section_flags (stdoutput, tbss_section, applicable);
372 seg_info (tbss_section)->bss = 1;
379 old_subsec = now_subseg;
383 /* convert to a power of 2 alignment */
384 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align)
389 as_bad (_("Common alignment not a power of 2"));
390 ignore_rest_of_line ();
400 record_alignment (sbss_section, align);
401 obj_elf_section_change_hook();
402 subseg_set (sbss_section, 0);
406 record_alignment (zbss_section, align);
407 obj_elf_section_change_hook();
408 subseg_set (zbss_section, 0);
412 record_alignment (tbss_section, align);
413 obj_elf_section_change_hook();
414 subseg_set (tbss_section, 0);
422 frag_align (align, 0, 0);
427 if (S_GET_SEGMENT (symbolP) == sbss_section)
428 symbolP->sy_frag->fr_symbol = 0;
432 if (S_GET_SEGMENT (symbolP) == zbss_section)
433 symbolP->sy_frag->fr_symbol = 0;
437 if (S_GET_SEGMENT (symbolP) == tbss_section)
438 symbolP->sy_frag->fr_symbol = 0;
445 symbolP->sy_frag = frag_now;
446 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
447 (offsetT) size, (char *) 0);
449 S_SET_SIZE (symbolP, size);
454 S_SET_SEGMENT (symbolP, sbss_section);
458 S_SET_SEGMENT (symbolP, zbss_section);
462 S_SET_SEGMENT (symbolP, tbss_section);
469 S_CLEAR_EXTERNAL (symbolP);
470 obj_elf_section_change_hook();
471 subseg_set (old_sec, old_subsec);
476 S_SET_VALUE (symbolP, (valueT) size);
477 S_SET_ALIGN (symbolP, temp);
478 S_SET_EXTERNAL (symbolP);
483 if (scommon_section == NULL)
487 applicable = bfd_applicable_section_flags (stdoutput);
489 scommon_section = subseg_new (".scommon", 0);
491 bfd_set_section_flags (stdoutput, scommon_section, applicable
492 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
493 | SEC_HAS_CONTENTS) | SEC_IS_COMMON);
495 S_SET_SEGMENT (symbolP, scommon_section);
499 if (zcommon_section == NULL)
503 applicable = bfd_applicable_section_flags (stdoutput);
505 zcommon_section = subseg_new (".zcommon", 0);
507 bfd_set_section_flags (stdoutput, zcommon_section, applicable
508 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
509 | SEC_HAS_CONTENTS) | SEC_IS_COMMON);
511 S_SET_SEGMENT (symbolP, zcommon_section);
515 if (tcommon_section == NULL)
519 applicable = bfd_applicable_section_flags (stdoutput);
521 tcommon_section = subseg_new (".tcommon", 0);
523 bfd_set_section_flags (stdoutput, tcommon_section, applicable
524 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
525 | SEC_HAS_CONTENTS) | SEC_IS_COMMON);
527 S_SET_SEGMENT (symbolP, tcommon_section);
537 input_line_pointer++;
538 /* @@ Some use the dot, some don't. Can we get some consistency?? */
539 if (*input_line_pointer == '.')
540 input_line_pointer++;
541 /* @@ Some say data, some say bss. */
542 if (strncmp (input_line_pointer, "bss\"", 4)
543 && strncmp (input_line_pointer, "data\"", 5))
545 while (*--input_line_pointer != '"')
547 input_line_pointer--;
548 goto bad_common_segment;
550 while (*input_line_pointer++ != '"')
552 goto allocate_common;
555 symbolP->bsym->flags |= BSF_OBJECT;
557 demand_empty_rest_of_line ();
562 p = input_line_pointer;
563 while (*p && *p != '\n')
567 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
569 input_line_pointer = p;
570 ignore_rest_of_line ();
576 set_machine (int number)
579 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
583 case 0: processor_mask = PROCESSOR_V850; break;
584 /* start-sanitize-v850e */
585 case bfd_mach_v850e: processor_mask = PROCESSOR_V850E; break;
586 case bfd_mach_v850ea: processor_mask = PROCESSOR_V850EA; break;
587 /* end-sanitize-v850e */
591 /* The target specific pseudo-ops which we support. */
592 const pseudo_typeS md_pseudo_table[] =
594 {"sdata", v850_sdata, 0},
595 {"tdata", v850_tdata, 0},
596 {"zdata", v850_zdata, 0},
597 {"sbss", v850_sbss, 0},
598 {"tbss", v850_tbss, 0},
599 {"zbss", v850_zbss, 0},
600 {"rosdata", v850_rosdata, 0},
601 {"rozdata", v850_rozdata, 0},
602 {"bss", v850_bss, 0},
603 {"offset", v850_offset, 0},
605 {"zcomm", v850_comm, AREA_ZDA},
606 {"scomm", v850_comm, AREA_SDA},
607 {"tcomm", v850_comm, AREA_TDA},
608 {"v850", set_machine, 0},
609 /* start-sanitize-v850e */
610 {"call_table_data", v850_call_table_data, 0},
611 {"call_table_text", v850_call_table_text, 0},
612 {"v850e", set_machine, bfd_mach_v850e},
613 {"v850ea", set_machine, bfd_mach_v850ea},
614 /* end-sanitize-v850e */
618 /* Opcode hash table. */
619 static struct hash_control *v850_hash;
621 /* This table is sorted. Suitable for searching by a binary search. */
622 static const struct reg_name pre_defined_registers[] =
624 { "ep", 30 }, /* ep - element ptr */
625 { "gp", 4 }, /* gp - global ptr */
626 { "hp", 2 }, /* hp - handler stack ptr */
627 { "lp", 31 }, /* lp - link ptr */
660 { "sp", 3 }, /* sp - stack ptr */
661 { "tp", 5 }, /* tp - text ptr */
664 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
667 static const struct reg_name system_registers[] =
669 /* start-sanitize-v850e */
675 /* end-sanitize-v850e */
683 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
685 /* start-sanitize-v850e */
686 static const struct reg_name system_list_registers[] =
691 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
692 /* end-sanitize-v850e */
694 static const struct reg_name cc_names[] =
719 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
721 /* reg_name_search does a binary search of the given register table
722 to see if "name" is a valid regiter name. Returns the register
723 number from the array on success, or -1 on failure. */
726 reg_name_search (regs, regcount, name, accept_numbers)
727 const struct reg_name * regs;
730 boolean accept_numbers;
732 int middle, low, high;
736 /* If the register name is a symbol, then evaluate it. */
737 if ((symbolP = symbol_find (name)) != NULL)
739 /* If the symbol is an alias for another name then use that.
740 If the symbol is an alias for a number, then return the number. */
741 if (symbolP->sy_value.X_op == O_symbol)
743 name = S_GET_NAME (symbolP->sy_value.X_add_symbol);
745 else if (accept_numbers)
747 int reg = S_GET_VALUE (symbolP);
749 if (reg >= 0 && reg <= 31)
759 middle = (low + high) / 2;
760 cmp = strcasecmp (name, regs[middle].name);
766 return regs[middle].value;
773 /* Summary of register_name().
775 * in: Input_line_pointer points to 1st char of operand.
777 * out: A expressionS.
778 * The operand may have been a register: in this case, X_op == O_register,
779 * X_add_number is set to the register number, and truth is returned.
780 * Input_line_pointer->(next non-blank) char after operand, or is in
781 * its original state.
784 register_name (expressionP)
785 expressionS * expressionP;
792 /* Find the spelling of the operand */
793 start = name = input_line_pointer;
795 c = get_symbol_end ();
797 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT,
800 * input_line_pointer = c; /* put back the delimiting char */
802 /* look to see if it's in the register table */
805 expressionP->X_op = O_register;
806 expressionP->X_add_number = reg_number;
808 /* make the rest nice */
809 expressionP->X_add_symbol = NULL;
810 expressionP->X_op_symbol = NULL;
816 /* reset the line as if we had not done anything */
817 input_line_pointer = start;
823 /* Summary of system_register_name().
825 * in: Input_line_pointer points to 1st char of operand.
826 * expressionP points to an expression structure to be filled in.
827 * accept_numbers is true iff numerical register names may be used.
828 * start-sanitize-v850e
829 * accept_list_names is true iff the special names PS and SR may be
833 * out: A expressionS structure in expressionP.
834 * The operand may have been a register: in this case, X_op == O_register,
835 * X_add_number is set to the register number, and truth is returned.
836 * Input_line_pointer->(next non-blank) char after operand, or is in
837 * its original state.
840 system_register_name (expressionP, accept_numbers
841 /* start-sanitize-v850e */
843 /* end-sanitize-v850e */
845 expressionS * expressionP;
846 boolean accept_numbers;
847 /* start-sanitize-v850e */
848 boolean accept_list_names;
849 /* end-sanitize-v850e */
856 /* Find the spelling of the operand */
857 start = name = input_line_pointer;
859 c = get_symbol_end ();
860 reg_number = reg_name_search (system_registers, SYSREG_NAME_CNT, name,
863 * input_line_pointer = c; /* put back the delimiting char */
868 input_line_pointer = start; /* reset input_line pointer */
870 if (isdigit (* input_line_pointer))
872 reg_number = strtol (input_line_pointer, & input_line_pointer, 10);
874 /* Make sure that the register number is allowable. */
877 /* start-sanitize-v850e */
880 /* end-sanitize-v850e */
886 /* start-sanitize-v850e */
887 else if (accept_list_names)
889 c = get_symbol_end ();
890 reg_number = reg_name_search (system_list_registers,
891 SYSREGLIST_NAME_CNT, name, FALSE);
893 * input_line_pointer = c; /* put back the delimiting char */
895 /* end-sanitize-v850e */
898 /* look to see if it's in the register table */
901 expressionP->X_op = O_register;
902 expressionP->X_add_number = reg_number;
904 /* make the rest nice */
905 expressionP->X_add_symbol = NULL;
906 expressionP->X_op_symbol = NULL;
912 /* reset the line as if we had not done anything */
913 input_line_pointer = start;
919 /* Summary of cc_name().
921 * in: Input_line_pointer points to 1st char of operand.
923 * out: A expressionS.
924 * The operand may have been a register: in this case, X_op == O_register,
925 * X_add_number is set to the register number, and truth is returned.
926 * Input_line_pointer->(next non-blank) char after operand, or is in
927 * its original state.
930 cc_name (expressionP)
931 expressionS * expressionP;
938 /* Find the spelling of the operand */
939 start = name = input_line_pointer;
941 c = get_symbol_end ();
942 reg_number = reg_name_search (cc_names, CC_NAME_CNT, name, FALSE);
944 * input_line_pointer = c; /* put back the delimiting char */
946 /* look to see if it's in the register table */
949 expressionP->X_op = O_constant;
950 expressionP->X_add_number = reg_number;
952 /* make the rest nice */
953 expressionP->X_add_symbol = NULL;
954 expressionP->X_op_symbol = NULL;
960 /* reset the line as if we had not done anything */
961 input_line_pointer = start;
968 skip_white_space (void)
970 while ( * input_line_pointer == ' '
971 || * input_line_pointer == '\t')
972 ++ input_line_pointer;
975 /* start-sanitize-v850e */
976 /* Summary of parse_register_list ().
978 * in: Input_line_pointer points to 1st char of a list of registers.
979 * insn is the partially constructed instruction.
980 * operand is the operand being inserted.
982 * out: NULL if the parse completed successfully, otherwise a
983 * pointer to an error message is returned. If the parse
984 * completes the correct bit fields in the instruction
987 * Parses register lists with the syntax:
995 * and also parses constant epxressions whoes bits indicate the
996 * registers in the lists. The LSB in the expression refers to
997 * the lowest numbered permissable register in the register list,
998 * and so on upwards. System registers are considered to be very
1005 unsigned long * insn,
1006 const struct v850_operand * operand
1009 static int type1_regs[ 32 ] = { 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
1010 static int type2_regs[ 32 ] = { 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
1011 static int type3_regs[ 32 ] = { 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8 };
1016 /* Select a register array to parse. */
1017 switch (operand->shift)
1019 case 0xffe00001: regs = type1_regs; break;
1020 case 0xfff8000f: regs = type2_regs; break;
1021 case 0xfff8001f: regs = type3_regs; break;
1023 as_bad (_("unknown operand shift: %x\n"), operand->shift );
1024 return _("internal failure in parse_register_list");
1029 /* If the expression starts with a curly brace it is a register list.
1030 Otherwise it is a constant expression, whoes bits indicate which
1031 registers are to be included in the list. */
1033 if (* input_line_pointer != '{')
1041 if (exp.X_op != O_constant)
1042 return _("constant expression or register list expected");
1044 if (regs == type1_regs)
1046 if (exp.X_add_number & 0xFFFFF000)
1047 return _("high bits set in register list expression");
1049 for (reg = 20; reg < 32; reg ++)
1050 if (exp.X_add_number & (1 << (reg - 20)))
1052 for (i = 0; i < 32; i++)
1057 else if (regs == type2_regs)
1059 if (exp.X_add_number & 0xFFFE0000)
1060 return _("high bits set in register list expression");
1062 for (reg = 1; reg < 16; reg ++)
1063 if (exp.X_add_number & (1 << (reg - 1)))
1065 for (i = 0; i < 32; i++)
1070 if (exp.X_add_number & (1 << 15))
1073 if (exp.X_add_number & (1 << 16))
1074 * insn |= (1 << 19);
1076 else /* regs == type3_regs */
1078 if (exp.X_add_number & 0xFFFE0000)
1079 return _("high bits set in register list expression");
1081 for (reg = 16; reg < 32; reg ++)
1082 if (exp.X_add_number & (1 << (reg - 16)))
1084 for (i = 0; i < 32; i++)
1089 if (exp.X_add_number & (1 << 16))
1090 * insn |= (1 << 19);
1096 input_line_pointer ++;
1098 /* Parse the register list until a terminator (closing curly brace or
1099 new-line) is found. */
1102 if (register_name (& exp))
1106 /* Locate the given register in the list, and if it is there,
1107 insert the corresponding bit into the instruction. */
1108 for (i = 0; i < 32; i++)
1110 if (regs[ i ] == exp.X_add_number)
1119 return _("illegal register included in list");
1122 else if (system_register_name (& exp, true, true))
1124 if (regs == type1_regs)
1126 return _("system registers cannot be included in list");
1128 else if (exp.X_add_number == 5)
1130 if (regs == type2_regs)
1131 return _("PSW cannot be included in list");
1135 else if (exp.X_add_number < 4)
1138 return _("High value system registers cannot be included in list");
1140 else if (* input_line_pointer == '}')
1142 input_line_pointer ++;
1145 else if (* input_line_pointer == ',')
1147 input_line_pointer ++;
1150 else if (* input_line_pointer == '-')
1152 /* We have encountered a range of registers: rX - rY */
1156 /* Skip the dash. */
1157 ++ input_line_pointer;
1159 /* Get the second register in the range. */
1160 if (! register_name (& exp2))
1162 return _("second register should follow dash in register list");
1163 exp2.X_add_number = exp.X_add_number;
1166 /* Add the rest of the registers in the range. */
1167 for (j = exp.X_add_number + 1; j <= exp2.X_add_number; j++)
1171 /* Locate the given register in the list, and if it is there,
1172 insert the corresponding bit into the instruction. */
1173 for (i = 0; i < 32; i++)
1183 return _("illegal register included in list");
1191 skip_white_space ();
1196 /* end-sanitize-v850e */
1198 CONST char * md_shortopts = "m:";
1200 struct option md_longopts[] =
1202 {NULL, no_argument, NULL, 0}
1204 size_t md_longopts_size = sizeof md_longopts;
1208 md_show_usage (stream)
1211 fprintf (stream, _("V850 options:\n"));
1212 fprintf (stream, _("\t-mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1213 fprintf (stream, _("\t-mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1214 fprintf (stream, _("\t-mv850 The code is targeted at the v850\n"));
1215 /* start-sanitize-v850e */
1216 fprintf (stream, _("\t-mv850e The code is targeted at the v850e\n"));
1217 fprintf (stream, _("\t-mv850ea The code is targeted at the v850ea\n"));
1218 fprintf (stream, _("\t-mv850any The code is generic, despite any processor specific instructions\n"));
1219 /* end-sanitize-v850e */
1223 md_parse_option (c, arg)
1229 /* xgettext:c-format */
1230 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1234 if (strcmp (arg, "warn-signed-overflow") == 0)
1236 warn_signed_overflows = TRUE;
1238 else if (strcmp (arg, "warn-unsigned-overflow") == 0)
1240 warn_unsigned_overflows = TRUE;
1242 else if (strcmp (arg, "v850") == 0)
1245 processor_mask = PROCESSOR_V850;
1247 /* start-sanitize-v850e */
1248 else if (strcmp (arg, "v850e") == 0)
1250 machine = bfd_mach_v850e;
1251 processor_mask = PROCESSOR_V850E;
1253 else if (strcmp (arg, "v850ea") == 0)
1255 machine = bfd_mach_v850ea;
1256 processor_mask = PROCESSOR_V850EA;
1258 else if (strcmp (arg, "v850any") == 0)
1260 machine = 0; /* Tell the world that this is for any v850 chip. */
1261 processor_mask = PROCESSOR_V850EA; /* But support instructions for the extended versions. */
1263 /* end-sanitize-v850e */
1266 /* xgettext:c-format */
1267 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1275 md_undefined_symbol (name)
1282 md_atof (type, litp, sizep)
1288 LITTLENUM_TYPE words[4];
1304 return _("bad call to md_atof");
1307 t = atof_ieee (input_line_pointer, type, words);
1309 input_line_pointer = t;
1313 for (i = prec - 1; i >= 0; i--)
1315 md_number_to_chars (litp, (valueT) words[i], 2);
1325 md_convert_frag (abfd, sec, fragP)
1330 subseg_change (sec, 0);
1332 /* In range conditional or unconditional branch. */
1333 if (fragP->fr_subtype == 0 || fragP->fr_subtype == 2)
1335 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
1336 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode);
1340 /* Out of range conditional branch. Emit a branch around a jump. */
1341 else if (fragP->fr_subtype == 1)
1343 unsigned char *buffer =
1344 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1346 /* Reverse the condition of the first branch. */
1348 /* Mask off all the displacement bits. */
1351 /* Now set the displacement bits so that we branch
1352 around the unconditional branch. */
1355 /* Now create the unconditional branch + fixup to the final
1357 md_number_to_chars (buffer + 2, 0x00000780, 4);
1358 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
1359 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int) fragP->fr_opcode
1364 /* Out of range unconditional branch. Emit a jump. */
1365 else if (fragP->fr_subtype == 3)
1367 md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x00000780, 4);
1368 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
1369 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int) fragP->fr_opcode
1379 md_section_align (seg, addr)
1383 int align = bfd_get_section_alignment (stdoutput, seg);
1384 return ((addr + (1 << align) - 1) & (-1 << align));
1390 char * prev_name = "";
1391 register const struct v850_opcode * op;
1392 flagword applicable;
1394 /* start-sanitize-v850e */
1395 if (strncmp (TARGET_CPU, "v850ea", 6) == 0)
1398 machine = bfd_mach_v850ea;
1400 if (processor_mask == -1)
1401 processor_mask = PROCESSOR_V850EA;
1403 else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
1406 machine = bfd_mach_v850e;
1408 if (processor_mask == -1)
1409 processor_mask = PROCESSOR_V850E;
1412 /* end-sanitize-v850e */
1413 if (strncmp (TARGET_CPU, "v850", 4) == 0)
1418 if (processor_mask == -1)
1419 processor_mask = PROCESSOR_V850;
1422 /* xgettext:c-format */
1423 as_bad (_("Unable to determine default target processor from string: %s"),
1426 v850_hash = hash_new();
1428 /* Insert unique names into hash table. The V850 instruction set
1429 has many identical opcode names that have different opcodes based
1430 on the operands. This hash table then provides a quick index to
1431 the first opcode with a particular name in the opcode table. */
1436 if (strcmp (prev_name, op->name))
1438 prev_name = (char *) op->name;
1439 hash_insert (v850_hash, op->name, (char *) op);
1444 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
1446 /* start-sanitize-v850e */
1447 call_table_data_section = subseg_new (".call_table_data", 0);
1448 bfd_set_section_flags (stdoutput, call_table_data_section,
1449 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1450 | SEC_DATA | SEC_HAS_CONTENTS));
1452 call_table_text_section = subseg_new (".call_table_text", 0);
1453 bfd_set_section_flags (stdoutput, call_table_text_section,
1454 applicable & (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE));
1456 /* Restore text section as the current default. */
1457 subseg_set (text_section, 0);
1458 /* end-sanitize-v850e */
1463 /* start-sanitize-v850e */
1464 static bfd_reloc_code_real_type
1465 handle_ctoff (const struct v850_operand * operand)
1467 if (operand == NULL)
1468 return BFD_RELOC_V850_CALLT_16_16_OFFSET;
1470 if ( operand->bits != 6
1471 || operand->shift != 0)
1473 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1474 return BFD_RELOC_64; /* Used to indicate an error condition. */
1477 return BFD_RELOC_V850_CALLT_6_7_OFFSET;
1479 /* end-sanitize-v850e */
1481 static bfd_reloc_code_real_type
1482 handle_sdaoff (const struct v850_operand * operand)
1484 if (operand == NULL) return BFD_RELOC_V850_SDA_16_16_OFFSET;
1485 if (operand->bits == 15 && operand->shift == 17) return BFD_RELOC_V850_SDA_15_16_OFFSET;
1486 /* start-sanitize-v850e */
1487 if (operand->bits == -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET;
1488 /* end-sanitize-v850e */
1490 if ( operand->bits != 16
1491 || operand->shift != 16)
1493 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1494 return BFD_RELOC_64; /* Used to indicate an error condition. */
1497 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1500 static bfd_reloc_code_real_type
1501 handle_zdaoff (const struct v850_operand * operand)
1503 if (operand == NULL) return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1504 if (operand->bits == 15 && operand->shift == 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET;
1505 /* start-sanitize-v850e */
1506 if (operand->bits == -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET;
1507 /* end-sanitize-v850e */
1509 if ( operand->bits != 16
1510 || operand->shift != 16)
1512 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1513 return BFD_RELOC_64; /* Used to indicate an error condition. */
1516 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1519 static bfd_reloc_code_real_type
1520 handle_tdaoff (const struct v850_operand * operand)
1522 if (operand == NULL) return BFD_RELOC_V850_TDA_7_7_OFFSET; /* data item, not an instruction. */
1523 if (operand->bits == 6 && operand->shift == 1) return BFD_RELOC_V850_TDA_6_8_OFFSET; /* sld.w/sst.w, operand: D8_6 */
1524 /* start-sanitize-v850e */
1525 if (operand->bits == 4 && operand->insert != NULL) return BFD_RELOC_V850_TDA_4_5_OFFSET; /* sld.hu, operand: D5-4 */
1526 if (operand->bits == 4 && operand->insert == NULL) return BFD_RELOC_V850_TDA_4_4_OFFSET; /* sld.bu, operand: D4 */
1527 /* end-sanitize-v850e */
1528 if (operand->bits == 16 && operand->shift == 16) return BFD_RELOC_V850_TDA_16_16_OFFSET; /* set1 & chums, operands: D16 */
1530 if (operand->bits != 7)
1532 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1533 return BFD_RELOC_64; /* Used to indicate an error condition. */
1536 return operand->insert != NULL
1537 ? BFD_RELOC_V850_TDA_7_8_OFFSET /* sld.h/sst.h, operand: D8_7 */
1538 : BFD_RELOC_V850_TDA_7_7_OFFSET; /* sld.b/sst.b, opreand: D7 */
1541 /* Warning: The code in this function relies upon the definitions
1542 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1543 matching the hard coded values contained herein. */
1545 static bfd_reloc_code_real_type
1546 v850_reloc_prefix (const struct v850_operand * operand)
1548 boolean paren_skipped = false;
1551 /* Skip leading opening parenthesis. */
1552 if (* input_line_pointer == '(')
1554 ++ input_line_pointer;
1555 paren_skipped = true;
1558 #define CHECK_(name, reloc) \
1559 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1561 input_line_pointer += strlen (name); \
1565 CHECK_ ("hi0", BFD_RELOC_HI16);
1566 CHECK_ ("hi", BFD_RELOC_HI16_S);
1567 CHECK_ ("lo", BFD_RELOC_LO16);
1568 CHECK_ ("sdaoff", handle_sdaoff (operand));
1569 CHECK_ ("zdaoff", handle_zdaoff (operand));
1570 CHECK_ ("tdaoff", handle_tdaoff (operand));
1572 /* start-sanitize-v850e */
1573 CHECK_ ("hilo", BFD_RELOC_32);
1574 CHECK_ ("ctoff", handle_ctoff (operand));
1575 /* end-sanitize-v850e */
1577 /* Restore skipped parenthesis. */
1579 -- input_line_pointer;
1581 return BFD_RELOC_UNUSED;
1584 /* Insert an operand value into an instruction. */
1586 static unsigned long
1587 v850_insert_operand (insn, operand, val, file, line, str)
1589 const struct v850_operand * operand;
1595 if (operand->insert)
1597 const char * message = NULL;
1599 insn = operand->insert (insn, val, & message);
1600 if (message != NULL)
1602 if ((operand->flags & V850_OPERAND_SIGNED)
1603 && ! warn_signed_overflows
1604 && strstr (message, "out of range") != NULL)
1606 /* skip warning... */
1608 else if ((operand->flags & V850_OPERAND_SIGNED) == 0
1609 && ! warn_unsigned_overflows
1610 && strstr (message, "out of range") != NULL)
1612 /* skip warning... */
1616 if (file == (char *) NULL)
1617 as_warn ("%s: %s", str, message);
1619 as_warn_where (file, line, "%s: %s", str, message);
1623 if (file == (char *) NULL)
1626 as_warn_where (file, line, message);
1632 if (operand->bits != 32)
1637 if ((operand->flags & V850_OPERAND_SIGNED) != 0)
1639 if (! warn_signed_overflows)
1640 max = (1 << operand->bits) - 1;
1642 max = (1 << (operand->bits - 1)) - 1;
1644 min = - (1 << (operand->bits - 1));
1648 max = (1 << operand->bits) - 1;
1650 if (! warn_unsigned_overflows)
1651 min = - (1 << (operand->bits - 1));
1656 if (val < (offsetT) min || val > (offsetT) max)
1658 /* xgettext:c-format */
1659 const char * err = _("operand out of range (%s not between %ld and %ld)");
1662 /* Restore min and mix to expected values for decimal ranges. */
1663 if ((operand->flags & V850_OPERAND_SIGNED)
1664 && ! warn_signed_overflows)
1665 max = (1 << (operand->bits - 1)) - 1;
1667 if (! (operand->flags & V850_OPERAND_SIGNED)
1668 && ! warn_unsigned_overflows)
1673 sprintf (buf, "%s: ", str);
1675 sprint_value (buf + strlen (buf), val);
1678 sprint_value (buf, val);
1680 if (file == (char *) NULL)
1681 as_warn (err, buf, min, max);
1683 as_warn_where (file, line, err, buf, min, max);
1687 insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift);
1694 static char copy_of_instruction [128];
1701 char * start_of_operands;
1702 struct v850_opcode * opcode;
1703 struct v850_opcode * next_opcode;
1704 const unsigned char * opindex_ptr;
1708 unsigned long insn_size;
1712 boolean extra_data_after_insn = false;
1713 unsigned extra_data_len;
1714 unsigned long extra_data;
1715 char * saved_input_line_pointer;
1718 strncpy (copy_of_instruction, str, sizeof (copy_of_instruction) - 1);
1720 /* Get the opcode. */
1721 for (s = str; *s != '\0' && ! isspace (*s); s++)
1727 /* find the first opcode with the proper name */
1728 opcode = (struct v850_opcode *) hash_find (v850_hash, str);
1731 /* xgettext:c-format */
1732 as_bad (_("Unrecognized opcode: `%s'"), str);
1733 ignore_rest_of_line ();
1738 while (isspace (* str))
1741 start_of_operands = str;
1743 saved_input_line_pointer = input_line_pointer;
1747 const char * errmsg = NULL;
1751 if ((opcode->processors & processor_mask) == 0)
1753 errmsg = _("Target processor does not support this instruction.");
1760 insn = opcode->opcode;
1761 extra_data_after_insn = false;
1763 input_line_pointer = str = start_of_operands;
1765 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr ++)
1767 const struct v850_operand * operand;
1770 bfd_reloc_code_real_type reloc;
1772 if (next_opindex == 0)
1774 operand = & v850_operands[ * opindex_ptr ];
1778 operand = & v850_operands[ next_opindex ];
1784 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1787 if (operand->flags & V850_OPERAND_RELAX)
1790 /* Gather the operand. */
1791 hold = input_line_pointer;
1792 input_line_pointer = str;
1794 /* lo(), hi(), hi0(), etc... */
1795 if ((reloc = v850_reloc_prefix (operand)) != BFD_RELOC_UNUSED)
1797 /* This is a fake reloc, used to indicate an error condition. */
1798 if (reloc == BFD_RELOC_64)
1806 if (ex.X_op == O_constant)
1810 case BFD_RELOC_V850_ZDA_16_16_OFFSET:
1811 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1815 case BFD_RELOC_LO16:
1817 /* Truncate, then sign extend the value. */
1818 ex.X_add_number = SEXT16 (ex.X_add_number);
1822 case BFD_RELOC_HI16:
1824 /* Truncate, then sign extend the value. */
1825 ex.X_add_number = SEXT16 (ex.X_add_number >> 16);
1829 case BFD_RELOC_HI16_S:
1831 /* Truncate, then sign extend the value. */
1832 int temp = (ex.X_add_number >> 16) & 0xffff;
1834 temp += (ex.X_add_number >> 15) & 1;
1836 ex.X_add_number = SEXT16 (temp);
1840 /* start-sanitize-v850e */
1842 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1844 errmsg = _("immediate operand is too large");
1848 extra_data_after_insn = true;
1850 extra_data = ex.X_add_number;
1851 ex.X_add_number = 0;
1853 /* end-sanitize-v850e */
1856 fprintf (stderr, "reloc: %d\n", reloc);
1857 as_bad (_("AAARG -> unhandled constant reloc"));
1861 if (fc > MAX_INSN_FIXUPS)
1862 as_fatal (_("too many fixups"));
1864 fixups[ fc ].exp = ex;
1865 fixups[ fc ].opindex = * opindex_ptr;
1866 fixups[ fc ].reloc = reloc;
1871 /* start-sanitize-v850e */
1872 if (reloc == BFD_RELOC_32)
1874 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1876 errmsg = _("immediate operand is too large");
1880 extra_data_after_insn = true;
1882 extra_data = ex.X_add_number;
1884 /* end-sanitize-v850e */
1886 if (fc > MAX_INSN_FIXUPS)
1887 as_fatal (_("too many fixups"));
1889 fixups[ fc ].exp = ex;
1890 fixups[ fc ].opindex = * opindex_ptr;
1891 fixups[ fc ].reloc = reloc;
1899 if ((operand->flags & V850_OPERAND_REG) != 0)
1901 if (!register_name (& ex))
1903 errmsg = _("invalid register name");
1905 else if ((operand->flags & V850_NOT_R0)
1906 && ex.X_add_number == 0)
1908 errmsg = _("register r0 cannot be used here");
1910 /* Force an error message to be generated by
1911 skipping over any following potential matches
1916 else if ((operand->flags & V850_OPERAND_SRG) != 0)
1918 if (!system_register_name (& ex, true
1919 /* start-sanitize-v850e */
1921 /* end-sanitize-v850e */
1924 errmsg = _("invalid system register name");
1927 else if ((operand->flags & V850_OPERAND_EP) != 0)
1929 char * start = input_line_pointer;
1930 char c = get_symbol_end ();
1932 if (strcmp (start, "ep") != 0 && strcmp (start, "r30") != 0)
1934 /* Put things back the way we found them. */
1935 *input_line_pointer = c;
1936 input_line_pointer = start;
1937 errmsg = _("expected EP register");
1941 *input_line_pointer = c;
1942 str = input_line_pointer;
1943 input_line_pointer = hold;
1945 while ( *str == ' ' || *str == ',' || *str == '['
1950 else if ((operand->flags & V850_OPERAND_CC) != 0)
1952 if (!cc_name (& ex))
1954 errmsg = _("invalid condition code name");
1957 /* start-sanitize-v850e */
1958 else if (operand->flags & V850E_PUSH_POP)
1960 errmsg = parse_register_list (& insn, operand);
1962 /* The parse_register_list() function has already done
1963 everything, so fake a dummy expression. */
1964 ex.X_op = O_constant;
1965 ex.X_add_number = 0;
1967 else if (operand->flags & V850E_IMMEDIATE16)
1971 if (ex.X_op != O_constant)
1972 errmsg = _("constant expression expected");
1973 else if (ex.X_add_number & 0xffff0000)
1975 if (ex.X_add_number & 0xffff)
1976 errmsg = _("constant too big to fit into instruction");
1977 else if ((insn & 0x001fffc0) == 0x00130780)
1978 ex.X_add_number >>= 16;
1980 errmsg = _("constant too big to fit into instruction");
1983 extra_data_after_insn = true;
1985 extra_data = ex.X_add_number;
1986 ex.X_add_number = 0;
1988 else if (operand->flags & V850E_IMMEDIATE32)
1992 if (ex.X_op != O_constant)
1993 errmsg = _("constant expression expected");
1995 extra_data_after_insn = true;
1997 extra_data = ex.X_add_number;
1998 ex.X_add_number = 0;
2000 /* end-sanitize-v850e */
2001 else if (register_name (& ex)
2002 && (operand->flags & V850_OPERAND_REG) == 0)
2007 /* It is possible that an alias has been defined that
2008 matches a register name. For example the code may
2009 include a ".set ZERO, 0" directive, which matches
2010 the register name "zero". Attempt to reparse the
2011 field as an expression, and only complain if we
2012 cannot generate a constant. */
2014 input_line_pointer = str;
2016 c = get_symbol_end();
2018 if (symbol_find (str) != NULL)
2021 * input_line_pointer = c;
2022 input_line_pointer = str;
2026 if (ex.X_op != O_constant)
2028 /* If this register is actually occuring too early on
2029 the parsing of the instruction, (because another
2030 field is missing) then report this. */
2031 if (opindex_ptr[1] != 0
2032 && (v850_operands [opindex_ptr [1]].flags & V850_OPERAND_REG))
2033 errmsg = _("syntax error: value is missing before the register name");
2035 errmsg = _("syntax error: register not expected");
2037 /* If we created a symbol in the process of this test then
2038 delete it now, so that it will not be output with the real
2041 && ex.X_op == O_symbol)
2042 symbol_remove (ex.X_add_symbol,
2043 & symbol_rootP, & symbol_lastP);
2046 else if (system_register_name (& ex, false
2047 /* start-sanitize-v850e */
2049 /* end-sanitize-v850e */
2051 && (operand->flags & V850_OPERAND_SRG) == 0)
2053 errmsg = _("syntax error: system register not expected");
2055 else if (cc_name (&ex)
2056 && (operand->flags & V850_OPERAND_CC) == 0)
2058 errmsg = _("syntax error: condition code not expected");
2063 /* start-sanitize-v850e */
2065 If we are assembling a MOV instruction (or a CALLT.... :-)
2066 and the immediate value does not fit into the bits
2067 available then create a fake error so that the next MOV
2068 instruction will be selected. This one has a 32 bit
2071 if (((insn & 0x07e0) == 0x0200)
2072 && ex.X_op == O_constant
2073 && (ex.X_add_number < (- (1 << (operand->bits - 1)))
2074 || ex.X_add_number > ((1 << operand->bits) - 1)))
2075 errmsg = _("immediate operand is too large");
2076 /* end-sanitize-v850e */
2082 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n",
2083 insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
2088 errmsg = _("illegal operand");
2091 errmsg = _("missing operand");
2094 if ((operand->flags & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0)
2096 errmsg = _("invalid operand");
2099 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2101 copy_of_instruction);
2105 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2107 copy_of_instruction);
2111 /* We need to generate a fixup for this expression. */
2112 if (fc >= MAX_INSN_FIXUPS)
2113 as_fatal (_("too many fixups"));
2115 fixups[ fc ].exp = ex;
2116 fixups[ fc ].opindex = * opindex_ptr;
2117 fixups[ fc ].reloc = BFD_RELOC_UNUSED;
2123 str = input_line_pointer;
2124 input_line_pointer = hold;
2126 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']'
2135 next_opcode = opcode + 1;
2136 if (next_opcode->name != NULL
2137 && strcmp (next_opcode->name, opcode->name) == 0)
2139 opcode = next_opcode;
2141 /* Skip versions that are not supported by the target
2143 if ((opcode->processors & processor_mask) == 0)
2149 as_bad ("%s: %s", copy_of_instruction, errmsg);
2151 if (* input_line_pointer == ']')
2152 ++ input_line_pointer;
2154 ignore_rest_of_line ();
2155 input_line_pointer = saved_input_line_pointer;
2161 while (isspace (*str))
2165 /* xgettext:c-format */
2166 as_bad (_("junk at end of line: `%s'"), str);
2168 input_line_pointer = str;
2170 /* Write out the instruction. */
2172 if (relaxable && fc > 0)
2177 if (!strcmp (opcode->name, "br"))
2179 f = frag_var (rs_machine_dependent, 4, 2, 2,
2180 fixups[0].exp.X_add_symbol,
2181 fixups[0].exp.X_add_number,
2182 (char *)fixups[0].opindex);
2183 md_number_to_chars (f, insn, insn_size);
2184 md_number_to_chars (f + 2, 0, 2);
2188 f = frag_var (rs_machine_dependent, 6, 4, 0,
2189 fixups[0].exp.X_add_symbol,
2190 fixups[0].exp.X_add_number,
2191 (char *)fixups[0].opindex);
2192 md_number_to_chars (f, insn, insn_size);
2193 md_number_to_chars (f + 2, 0, 4);
2198 /* Four byte insns have an opcode with the two high bits on. */
2199 if ((insn & 0x0600) == 0x0600)
2204 /* start-sanitize-v850e */
2205 /* Special case: 32 bit MOV */
2206 if ((insn & 0xffe0) == 0x0620)
2208 /* end-sanitize-v850e */
2210 f = frag_more (insn_size);
2212 md_number_to_chars (f, insn, insn_size);
2214 if (extra_data_after_insn)
2216 f = frag_more (extra_data_len);
2218 md_number_to_chars (f, extra_data, extra_data_len);
2220 extra_data_after_insn = false;
2224 /* Create any fixups. At this point we do not use a
2225 bfd_reloc_code_real_type, but instead just use the
2226 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2227 handle fixups for any operand type, although that is admittedly
2228 not a very exciting feature. We pick a BFD reloc type in
2230 for (i = 0; i < fc; i++)
2232 const struct v850_operand * operand;
2233 bfd_reloc_code_real_type reloc;
2235 operand = & v850_operands[ fixups[i].opindex ];
2237 reloc = fixups[i].reloc;
2239 if (reloc != BFD_RELOC_UNUSED)
2241 reloc_howto_type * reloc_howto = bfd_reloc_type_lookup (stdoutput,
2250 size = bfd_get_reloc_size (reloc_howto);
2252 /* XXX This will abort on an R_V850_8 reloc -
2253 is this reloc actually used ? */
2254 if (size != 2 && size != 4)
2257 address = (f - frag_now->fr_literal) + insn_size - size;
2259 if (reloc == BFD_RELOC_32)
2264 fixP = fix_new_exp (frag_now, address, size,
2266 reloc_howto->pc_relative,
2271 case BFD_RELOC_LO16:
2272 case BFD_RELOC_HI16:
2273 case BFD_RELOC_HI16_S:
2274 fixP->fx_no_overflow = 1;
2282 f - frag_now->fr_literal, 4,
2284 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2285 (bfd_reloc_code_real_type) (fixups[i].opindex
2286 + (int) BFD_RELOC_UNUSED)
2291 input_line_pointer = saved_input_line_pointer;
2295 /* If while processing a fixup, a reloc really needs to be created */
2296 /* then it is done here. */
2299 tc_gen_reloc (seg, fixp)
2305 reloc = (arelent *) xmalloc (sizeof (arelent));
2306 reloc->sym_ptr_ptr = & fixp->fx_addsy->bsym;
2307 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2308 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2310 if (reloc->howto == (reloc_howto_type *) NULL)
2312 as_bad_where (fixp->fx_file, fixp->fx_line,
2313 /* xgettext:c-format */
2314 _("reloc %d not supported by object file format"),
2315 (int)fixp->fx_r_type);
2322 reloc->addend = fixp->fx_addnumber;
2327 /* Assume everything will fit in two bytes, then expand as necessary. */
2329 md_estimate_size_before_relax (fragp, seg)
2333 if (fragp->fr_subtype == 0)
2335 else if (fragp->fr_subtype == 2)
2343 md_pcrel_from (fixp)
2346 /* If the symbol is undefined, or in a section other than our own,
2347 then let the linker figure it out. */
2348 if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy))
2350 /* The symbol is undefined. Let the linker figure it out. */
2353 return fixp->fx_frag->fr_address + fixp->fx_where;
2357 md_apply_fix3 (fixp, valuep, seg)
2365 if (fixp->fx_addsy == (symbolS *) NULL)
2370 else if (fixp->fx_pcrel)
2374 value = fixp->fx_offset;
2375 if (fixp->fx_subsy != (symbolS *) NULL)
2377 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
2378 value -= S_GET_VALUE (fixp->fx_subsy);
2381 /* We don't actually support subtracting a symbol. */
2382 as_bad_where (fixp->fx_file, fixp->fx_line,
2383 _("expression too complex"));
2388 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
2391 const struct v850_operand * operand;
2394 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
2395 operand = & v850_operands[ opindex ];
2397 /* Fetch the instruction, insert the fully resolved operand
2398 value, and stuff the instruction back again.
2400 Note the instruction has been stored in little endian
2402 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2404 insn = bfd_getl32 ((unsigned char *) where);
2405 insn = v850_insert_operand (insn, operand, (offsetT) value,
2406 fixp->fx_file, fixp->fx_line, NULL);
2407 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
2411 /* Nothing else to do here. */
2415 /* Determine a BFD reloc value based on the operand information.
2416 We are only prepared to turn a few of the operands into relocs. */
2418 if (operand->bits == 22)
2419 fixp->fx_r_type = BFD_RELOC_V850_22_PCREL;
2420 else if (operand->bits == 9)
2421 fixp->fx_r_type = BFD_RELOC_V850_9_PCREL;
2424 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2426 as_bad_where (fixp->fx_file, fixp->fx_line,
2427 _("unresolved expression that must be resolved"));
2432 else if (fixp->fx_done)
2434 /* We still have to insert the value into memory! */
2435 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2437 if (fixp->fx_size == 1)
2438 * where = value & 0xff;
2439 else if (fixp->fx_size == 2)
2440 bfd_putl16 (value & 0xffff, (unsigned char *) where);
2441 else if (fixp->fx_size == 4)
2442 bfd_putl32 (value, (unsigned char *) where);
2445 fixp->fx_addnumber = value;
2450 /* Parse a cons expression. We have to handle hi(), lo(), etc
2453 parse_cons_expression_v850 (exp)
2456 /* See if there's a reloc prefix like hi() we have to handle. */
2457 hold_cons_reloc = v850_reloc_prefix (NULL);
2459 /* Do normal expression parsing. */
2463 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2464 found a reloc prefix, then we use that reloc, else we choose an
2465 appropriate one based on the size of the expression. */
2467 cons_fix_new_v850 (frag, where, size, exp)
2473 if (hold_cons_reloc == BFD_RELOC_UNUSED)
2476 hold_cons_reloc = BFD_RELOC_32;
2478 hold_cons_reloc = BFD_RELOC_16;
2480 hold_cons_reloc = BFD_RELOC_8;
2484 fix_new_exp (frag, where, size, exp, 0, hold_cons_reloc);
2486 fix_new (frag, where, size, NULL, 0, 0, hold_cons_reloc);