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 static segT call_table_data_section = NULL;
99 static segT call_table_text_section = NULL;
102 #define MAX_INSN_FIXUPS (5)
107 bfd_reloc_code_real_type reloc;
110 struct v850_fixup fixups [MAX_INSN_FIXUPS];
115 v850_sdata (int ignore)
117 obj_elf_section_change_hook();
119 subseg_set (sdata_section, (subsegT) get_absolute_expression ());
121 demand_empty_rest_of_line ();
125 v850_tdata (int ignore)
127 obj_elf_section_change_hook();
129 subseg_set (tdata_section, (subsegT) get_absolute_expression ());
131 demand_empty_rest_of_line ();
135 v850_zdata (int ignore)
137 obj_elf_section_change_hook();
139 subseg_set (zdata_section, (subsegT) get_absolute_expression ());
141 demand_empty_rest_of_line ();
145 v850_sbss (int ignore)
147 obj_elf_section_change_hook();
149 subseg_set (sbss_section, (subsegT) get_absolute_expression ());
151 demand_empty_rest_of_line ();
155 v850_tbss (int ignore)
157 obj_elf_section_change_hook();
159 subseg_set (tbss_section, (subsegT) get_absolute_expression ());
161 demand_empty_rest_of_line ();
165 v850_zbss (int ignore)
167 obj_elf_section_change_hook();
169 subseg_set (zbss_section, (subsegT) get_absolute_expression ());
171 demand_empty_rest_of_line ();
175 v850_rosdata (int ignore)
177 obj_elf_section_change_hook();
179 subseg_set (rosdata_section, (subsegT) get_absolute_expression ());
181 demand_empty_rest_of_line ();
185 v850_rozdata (int ignore)
187 obj_elf_section_change_hook();
189 subseg_set (rozdata_section, (subsegT) get_absolute_expression ());
191 demand_empty_rest_of_line ();
195 v850_call_table_data (int ignore)
197 obj_elf_section_change_hook();
199 subseg_set (call_table_data_section, (subsegT) get_absolute_expression ());
201 demand_empty_rest_of_line ();
205 v850_call_table_text (int ignore)
207 obj_elf_section_change_hook();
209 subseg_set (call_table_text_section, (subsegT) get_absolute_expression ());
211 demand_empty_rest_of_line ();
215 v850_bss (int ignore)
217 register int temp = get_absolute_expression ();
219 obj_elf_section_change_hook();
221 subseg_set (bss_section, (subsegT) temp);
223 demand_empty_rest_of_line ();
227 v850_offset (int ignore)
229 int temp = get_absolute_expression ();
231 temp -= frag_now_fix();
234 (void) frag_more (temp);
236 demand_empty_rest_of_line ();
239 /* Copied from obj_elf_common() in gas/config/obj-elf.c */
252 name = input_line_pointer;
253 c = get_symbol_end ();
255 /* just after name is now '\0' */
256 p = input_line_pointer;
261 if (*input_line_pointer != ',')
263 as_bad (_("Expected comma after symbol-name"));
264 ignore_rest_of_line ();
268 input_line_pointer ++; /* skip ',' */
270 if ((temp = get_absolute_expression ()) < 0)
272 /* xgettext:c-format */
273 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp);
274 ignore_rest_of_line ();
280 symbolP = symbol_find_or_make (name);
283 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
285 as_bad (_("Ignoring attempt to re-define symbol"));
286 ignore_rest_of_line ();
290 if (S_GET_VALUE (symbolP) != 0)
292 if (S_GET_VALUE (symbolP) != size)
294 /* xgettext:c-format */
295 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
296 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
300 know (symbolP->sy_frag == & zero_address_frag);
302 if (*input_line_pointer != ',')
307 input_line_pointer++;
311 if (! have_align || *input_line_pointer != '"')
317 temp = get_absolute_expression ();
322 as_warn (_("Common alignment negative; 0 assumed"));
335 old_subsec = now_subseg;
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 /* convert to a power of 2 alignment */
380 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align)
385 as_bad (_("Common alignment not a power of 2"));
386 ignore_rest_of_line ();
396 record_alignment (sbss_section, align);
397 obj_elf_section_change_hook();
398 subseg_set (sbss_section, 0);
402 record_alignment (zbss_section, align);
403 obj_elf_section_change_hook();
404 subseg_set (zbss_section, 0);
408 record_alignment (tbss_section, align);
409 obj_elf_section_change_hook();
410 subseg_set (tbss_section, 0);
418 frag_align (align, 0, 0);
423 if (S_GET_SEGMENT (symbolP) == sbss_section)
424 symbolP->sy_frag->fr_symbol = 0;
428 if (S_GET_SEGMENT (symbolP) == zbss_section)
429 symbolP->sy_frag->fr_symbol = 0;
433 if (S_GET_SEGMENT (symbolP) == tbss_section)
434 symbolP->sy_frag->fr_symbol = 0;
441 symbolP->sy_frag = frag_now;
442 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
443 (offsetT) size, (char *) 0);
445 S_SET_SIZE (symbolP, size);
450 S_SET_SEGMENT (symbolP, sbss_section);
454 S_SET_SEGMENT (symbolP, zbss_section);
458 S_SET_SEGMENT (symbolP, tbss_section);
465 S_CLEAR_EXTERNAL (symbolP);
466 obj_elf_section_change_hook();
467 subseg_set (old_sec, old_subsec);
472 S_SET_VALUE (symbolP, (valueT) size);
473 S_SET_ALIGN (symbolP, temp);
474 S_SET_EXTERNAL (symbolP);
479 if (scommon_section == NULL)
483 applicable = bfd_applicable_section_flags (stdoutput);
485 scommon_section = subseg_new (".scommon", 0);
487 bfd_set_section_flags (stdoutput, scommon_section, applicable
488 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
489 | SEC_HAS_CONTENTS) | SEC_IS_COMMON);
491 S_SET_SEGMENT (symbolP, scommon_section);
495 if (zcommon_section == NULL)
499 applicable = bfd_applicable_section_flags (stdoutput);
501 zcommon_section = subseg_new (".zcommon", 0);
503 bfd_set_section_flags (stdoutput, zcommon_section, applicable
504 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
505 | SEC_HAS_CONTENTS) | SEC_IS_COMMON);
507 S_SET_SEGMENT (symbolP, zcommon_section);
511 if (tcommon_section == NULL)
515 applicable = bfd_applicable_section_flags (stdoutput);
517 tcommon_section = subseg_new (".tcommon", 0);
519 bfd_set_section_flags (stdoutput, tcommon_section, applicable
520 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
521 | SEC_HAS_CONTENTS) | SEC_IS_COMMON);
523 S_SET_SEGMENT (symbolP, tcommon_section);
533 input_line_pointer++;
534 /* @@ Some use the dot, some don't. Can we get some consistency?? */
535 if (*input_line_pointer == '.')
536 input_line_pointer++;
537 /* @@ Some say data, some say bss. */
538 if (strncmp (input_line_pointer, "bss\"", 4)
539 && strncmp (input_line_pointer, "data\"", 5))
541 while (*--input_line_pointer != '"')
543 input_line_pointer--;
544 goto bad_common_segment;
546 while (*input_line_pointer++ != '"')
548 goto allocate_common;
551 symbolP->bsym->flags |= BSF_OBJECT;
553 demand_empty_rest_of_line ();
558 p = input_line_pointer;
559 while (*p && *p != '\n')
563 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
565 input_line_pointer = p;
566 ignore_rest_of_line ();
572 set_machine (int number)
575 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
579 case 0: processor_mask = PROCESSOR_V850; break;
580 case bfd_mach_v850e: processor_mask = PROCESSOR_V850E; break;
581 case bfd_mach_v850ea: processor_mask = PROCESSOR_V850EA; break;
585 /* The target specific pseudo-ops which we support. */
586 const pseudo_typeS md_pseudo_table[] =
588 {"sdata", v850_sdata, 0},
589 {"tdata", v850_tdata, 0},
590 {"zdata", v850_zdata, 0},
591 {"sbss", v850_sbss, 0},
592 {"tbss", v850_tbss, 0},
593 {"zbss", v850_zbss, 0},
594 {"rosdata", v850_rosdata, 0},
595 {"rozdata", v850_rozdata, 0},
596 {"bss", v850_bss, 0},
597 {"offset", v850_offset, 0},
599 {"zcomm", v850_comm, AREA_ZDA},
600 {"scomm", v850_comm, AREA_SDA},
601 {"tcomm", v850_comm, AREA_TDA},
602 {"v850", set_machine, 0},
603 {"call_table_data", v850_call_table_data, 0},
604 {"call_table_text", v850_call_table_text, 0},
605 {"v850e", set_machine, bfd_mach_v850e},
606 {"v850ea", set_machine, bfd_mach_v850ea},
610 /* Opcode hash table. */
611 static struct hash_control *v850_hash;
613 /* This table is sorted. Suitable for searching by a binary search. */
614 static const struct reg_name pre_defined_registers[] =
616 { "ep", 30 }, /* ep - element ptr */
617 { "gp", 4 }, /* gp - global ptr */
618 { "hp", 2 }, /* hp - handler stack ptr */
619 { "lp", 31 }, /* lp - link ptr */
652 { "sp", 3 }, /* sp - stack ptr */
653 { "tp", 5 }, /* tp - text ptr */
656 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
659 static const struct reg_name system_registers[] =
673 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
675 static const struct reg_name system_list_registers[] =
680 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
682 static const struct reg_name cc_names[] =
707 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
709 /* reg_name_search does a binary search of the given register table
710 to see if "name" is a valid regiter name. Returns the register
711 number from the array on success, or -1 on failure. */
714 reg_name_search (regs, regcount, name, accept_numbers)
715 const struct reg_name * regs;
718 boolean accept_numbers;
720 int middle, low, high;
724 /* If the register name is a symbol, then evaluate it. */
725 if ((symbolP = symbol_find (name)) != NULL)
727 /* If the symbol is an alias for another name then use that.
728 If the symbol is an alias for a number, then return the number. */
729 if (symbolP->sy_value.X_op == O_symbol)
731 name = S_GET_NAME (symbolP->sy_value.X_add_symbol);
733 else if (accept_numbers)
735 int reg = S_GET_VALUE (symbolP);
737 if (reg >= 0 && reg <= 31)
741 /* Otherwise drop through and try parsing name normally. */
749 middle = (low + high) / 2;
750 cmp = strcasecmp (name, regs[middle].name);
756 return regs[middle].value;
763 /* Summary of register_name().
765 * in: Input_line_pointer points to 1st char of operand.
767 * out: A expressionS.
768 * The operand may have been a register: in this case, X_op == O_register,
769 * X_add_number is set to the register number, and truth is returned.
770 * Input_line_pointer->(next non-blank) char after operand, or is in
771 * its original state.
774 register_name (expressionP)
775 expressionS * expressionP;
782 /* Find the spelling of the operand */
783 start = name = input_line_pointer;
785 c = get_symbol_end ();
787 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT,
790 * input_line_pointer = c; /* put back the delimiting char */
792 /* look to see if it's in the register table */
795 expressionP->X_op = O_register;
796 expressionP->X_add_number = reg_number;
798 /* make the rest nice */
799 expressionP->X_add_symbol = NULL;
800 expressionP->X_op_symbol = NULL;
806 /* reset the line as if we had not done anything */
807 input_line_pointer = start;
813 /* Summary of system_register_name().
815 * in: Input_line_pointer points to 1st char of operand.
816 * expressionP points to an expression structure to be filled in.
817 * accept_numbers is true iff numerical register names may be used.
818 * accept_list_names is true iff the special names PS and SR may be
821 * out: A expressionS structure in expressionP.
822 * The operand may have been a register: in this case, X_op == O_register,
823 * X_add_number is set to the register number, and truth is returned.
824 * Input_line_pointer->(next non-blank) char after operand, or is in
825 * its original state.
828 system_register_name (expressionP, accept_numbers, accept_list_names)
829 expressionS * expressionP;
830 boolean accept_numbers;
831 boolean accept_list_names;
838 /* Find the spelling of the operand */
839 start = name = input_line_pointer;
841 c = get_symbol_end ();
842 reg_number = reg_name_search (system_registers, SYSREG_NAME_CNT, name,
845 * input_line_pointer = c; /* put back the delimiting char */
850 input_line_pointer = start; /* reset input_line pointer */
852 if (isdigit (* input_line_pointer))
854 reg_number = strtol (input_line_pointer, & input_line_pointer, 10);
856 /* Make sure that the register number is allowable. */
866 else if (accept_list_names)
868 c = get_symbol_end ();
869 reg_number = reg_name_search (system_list_registers,
870 SYSREGLIST_NAME_CNT, name, FALSE);
872 * input_line_pointer = c; /* put back the delimiting char */
876 /* look to see if it's in the register table */
879 expressionP->X_op = O_register;
880 expressionP->X_add_number = reg_number;
882 /* make the rest nice */
883 expressionP->X_add_symbol = NULL;
884 expressionP->X_op_symbol = NULL;
890 /* reset the line as if we had not done anything */
891 input_line_pointer = start;
897 /* Summary of cc_name().
899 * in: Input_line_pointer points to 1st char of operand.
901 * out: A expressionS.
902 * The operand may have been a register: in this case, X_op == O_register,
903 * X_add_number is set to the register number, and truth is returned.
904 * Input_line_pointer->(next non-blank) char after operand, or is in
905 * its original state.
908 cc_name (expressionP)
909 expressionS * expressionP;
916 /* Find the spelling of the operand */
917 start = name = input_line_pointer;
919 c = get_symbol_end ();
920 reg_number = reg_name_search (cc_names, CC_NAME_CNT, name, FALSE);
922 * input_line_pointer = c; /* put back the delimiting char */
924 /* look to see if it's in the register table */
927 expressionP->X_op = O_constant;
928 expressionP->X_add_number = reg_number;
930 /* make the rest nice */
931 expressionP->X_add_symbol = NULL;
932 expressionP->X_op_symbol = NULL;
938 /* reset the line as if we had not done anything */
939 input_line_pointer = start;
946 skip_white_space (void)
948 while ( * input_line_pointer == ' '
949 || * input_line_pointer == '\t')
950 ++ input_line_pointer;
953 /* Summary of parse_register_list ().
955 * in: Input_line_pointer points to 1st char of a list of registers.
956 * insn is the partially constructed instruction.
957 * operand is the operand being inserted.
959 * out: NULL if the parse completed successfully, otherwise a
960 * pointer to an error message is returned. If the parse
961 * completes the correct bit fields in the instruction
964 * Parses register lists with the syntax:
972 * and also parses constant epxressions whoes bits indicate the
973 * registers in the lists. The LSB in the expression refers to
974 * the lowest numbered permissable register in the register list,
975 * and so on upwards. System registers are considered to be very
982 unsigned long * insn,
983 const struct v850_operand * operand
986 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 };
987 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 };
988 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 };
993 /* Select a register array to parse. */
994 switch (operand->shift)
996 case 0xffe00001: regs = type1_regs; break;
997 case 0xfff8000f: regs = type2_regs; break;
998 case 0xfff8001f: regs = type3_regs; break;
1000 as_bad (_("unknown operand shift: %x\n"), operand->shift);
1001 return _("internal failure in parse_register_list");
1004 skip_white_space ();
1006 /* If the expression starts with a curly brace it is a register list.
1007 Otherwise it is a constant expression, whoes bits indicate which
1008 registers are to be included in the list. */
1010 if (* input_line_pointer != '{')
1018 if (exp.X_op != O_constant)
1019 return _("constant expression or register list expected");
1021 if (regs == type1_regs)
1023 if (exp.X_add_number & 0xFFFFF000)
1024 return _("high bits set in register list expression");
1026 for (reg = 20; reg < 32; reg ++)
1027 if (exp.X_add_number & (1 << (reg - 20)))
1029 for (i = 0; i < 32; i++)
1034 else if (regs == type2_regs)
1036 if (exp.X_add_number & 0xFFFE0000)
1037 return _("high bits set in register list expression");
1039 for (reg = 1; reg < 16; reg ++)
1040 if (exp.X_add_number & (1 << (reg - 1)))
1042 for (i = 0; i < 32; i++)
1047 if (exp.X_add_number & (1 << 15))
1050 if (exp.X_add_number & (1 << 16))
1051 * insn |= (1 << 19);
1053 else /* regs == type3_regs */
1055 if (exp.X_add_number & 0xFFFE0000)
1056 return _("high bits set in register list expression");
1058 for (reg = 16; reg < 32; reg ++)
1059 if (exp.X_add_number & (1 << (reg - 16)))
1061 for (i = 0; i < 32; i++)
1066 if (exp.X_add_number & (1 << 16))
1067 * insn |= (1 << 19);
1073 input_line_pointer ++;
1075 /* Parse the register list until a terminator (closing curly brace or
1076 new-line) is found. */
1079 if (register_name (& exp))
1083 /* Locate the given register in the list, and if it is there,
1084 insert the corresponding bit into the instruction. */
1085 for (i = 0; i < 32; i++)
1087 if (regs[ i ] == exp.X_add_number)
1096 return _("illegal register included in list");
1099 else if (system_register_name (& exp, true, true))
1101 if (regs == type1_regs)
1103 return _("system registers cannot be included in list");
1105 else if (exp.X_add_number == 5)
1107 if (regs == type2_regs)
1108 return _("PSW cannot be included in list");
1112 else if (exp.X_add_number < 4)
1115 return _("High value system registers cannot be included in list");
1117 else if (* input_line_pointer == '}')
1119 input_line_pointer ++;
1122 else if (* input_line_pointer == ',')
1124 input_line_pointer ++;
1127 else if (* input_line_pointer == '-')
1129 /* We have encountered a range of registers: rX - rY */
1133 /* Skip the dash. */
1134 ++ input_line_pointer;
1136 /* Get the second register in the range. */
1137 if (! register_name (& exp2))
1139 return _("second register should follow dash in register list");
1140 exp2.X_add_number = exp.X_add_number;
1143 /* Add the rest of the registers in the range. */
1144 for (j = exp.X_add_number + 1; j <= exp2.X_add_number; j++)
1148 /* Locate the given register in the list, and if it is there,
1149 insert the corresponding bit into the instruction. */
1150 for (i = 0; i < 32; i++)
1160 return _("illegal register included in list");
1168 skip_white_space ();
1174 CONST char * md_shortopts = "m:";
1176 struct option md_longopts[] =
1178 {NULL, no_argument, NULL, 0}
1180 size_t md_longopts_size = sizeof md_longopts;
1184 md_show_usage (stream)
1187 fprintf (stream, _(" V850 options:\n"));
1188 fprintf (stream, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1189 fprintf (stream, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1190 fprintf (stream, _(" -mv850 The code is targeted at the v850\n"));
1191 fprintf (stream, _(" -mv850e The code is targeted at the v850e\n"));
1192 fprintf (stream, _(" -mv850ea The code is targeted at the v850ea\n"));
1193 fprintf (stream, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1197 md_parse_option (c, arg)
1203 /* xgettext:c-format */
1204 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1208 if (strcmp (arg, "warn-signed-overflow") == 0)
1210 warn_signed_overflows = TRUE;
1212 else if (strcmp (arg, "warn-unsigned-overflow") == 0)
1214 warn_unsigned_overflows = TRUE;
1216 else if (strcmp (arg, "v850") == 0)
1219 processor_mask = PROCESSOR_V850;
1221 else if (strcmp (arg, "v850e") == 0)
1223 machine = bfd_mach_v850e;
1224 processor_mask = PROCESSOR_V850E;
1226 else if (strcmp (arg, "v850ea") == 0)
1228 machine = bfd_mach_v850ea;
1229 processor_mask = PROCESSOR_V850EA;
1231 else if (strcmp (arg, "v850any") == 0)
1233 machine = 0; /* Tell the world that this is for any v850 chip. */
1234 processor_mask = PROCESSOR_V850EA; /* But support instructions for the extended versions. */
1238 /* xgettext:c-format */
1239 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1247 md_undefined_symbol (name)
1254 md_atof (type, litp, sizep)
1260 LITTLENUM_TYPE words[4];
1276 return _("bad call to md_atof");
1279 t = atof_ieee (input_line_pointer, type, words);
1281 input_line_pointer = t;
1285 for (i = prec - 1; i >= 0; i--)
1287 md_number_to_chars (litp, (valueT) words[i], 2);
1297 md_convert_frag (abfd, sec, fragP)
1302 subseg_change (sec, 0);
1304 /* In range conditional or unconditional branch. */
1305 if (fragP->fr_subtype == 0 || fragP->fr_subtype == 2)
1307 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
1308 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode);
1312 /* Out of range conditional branch. Emit a branch around a jump. */
1313 else if (fragP->fr_subtype == 1)
1315 unsigned char *buffer =
1316 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1318 /* Reverse the condition of the first branch. */
1320 /* Mask off all the displacement bits. */
1323 /* Now set the displacement bits so that we branch
1324 around the unconditional branch. */
1327 /* Now create the unconditional branch + fixup to the final
1329 md_number_to_chars (buffer + 2, 0x00000780, 4);
1330 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
1331 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1332 (int) fragP->fr_opcode + 1);
1336 /* Out of range unconditional branch. Emit a jump. */
1337 else if (fragP->fr_subtype == 3)
1339 md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x00000780, 4);
1340 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
1341 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1342 (int) fragP->fr_opcode + 1);
1351 md_section_align (seg, addr)
1355 int align = bfd_get_section_alignment (stdoutput, seg);
1356 return ((addr + (1 << align) - 1) & (-1 << align));
1362 char * prev_name = "";
1363 register const struct v850_opcode * op;
1364 flagword applicable;
1366 if (strncmp (TARGET_CPU, "v850ea", 6) == 0)
1369 machine = bfd_mach_v850ea;
1371 if (processor_mask == -1)
1372 processor_mask = PROCESSOR_V850EA;
1374 else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
1377 machine = bfd_mach_v850e;
1379 if (processor_mask == -1)
1380 processor_mask = PROCESSOR_V850E;
1383 if (strncmp (TARGET_CPU, "v850", 4) == 0)
1388 if (processor_mask == -1)
1389 processor_mask = PROCESSOR_V850;
1392 /* xgettext:c-format */
1393 as_bad (_("Unable to determine default target processor from string: %s"),
1396 v850_hash = hash_new();
1398 /* Insert unique names into hash table. The V850 instruction set
1399 has many identical opcode names that have different opcodes based
1400 on the operands. This hash table then provides a quick index to
1401 the first opcode with a particular name in the opcode table. */
1406 if (strcmp (prev_name, op->name))
1408 prev_name = (char *) op->name;
1409 hash_insert (v850_hash, op->name, (char *) op);
1414 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
1416 applicable = bfd_applicable_section_flags (stdoutput);
1418 call_table_data_section = subseg_new (".call_table_data", 0);
1419 bfd_set_section_flags (stdoutput, call_table_data_section,
1420 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1421 | SEC_DATA | SEC_HAS_CONTENTS));
1423 call_table_text_section = subseg_new (".call_table_text", 0);
1424 bfd_set_section_flags (stdoutput, call_table_text_section,
1425 applicable & (SEC_ALLOC | SEC_LOAD | SEC_READONLY
1428 /* Restore text section as the current default. */
1429 subseg_set (text_section, 0);
1433 static bfd_reloc_code_real_type
1434 handle_ctoff (const struct v850_operand * operand)
1436 if (operand == NULL)
1437 return BFD_RELOC_V850_CALLT_16_16_OFFSET;
1439 if ( operand->bits != 6
1440 || operand->shift != 0)
1442 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1443 return BFD_RELOC_64; /* Used to indicate an error condition. */
1446 return BFD_RELOC_V850_CALLT_6_7_OFFSET;
1449 static bfd_reloc_code_real_type
1450 handle_sdaoff (const struct v850_operand * operand)
1452 if (operand == NULL) return BFD_RELOC_V850_SDA_16_16_OFFSET;
1453 if (operand->bits == 15 && operand->shift == 17) return BFD_RELOC_V850_SDA_15_16_OFFSET;
1454 if (operand->bits == -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET;
1456 if ( operand->bits != 16
1457 || operand->shift != 16)
1459 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1460 return BFD_RELOC_64; /* Used to indicate an error condition. */
1463 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1466 static bfd_reloc_code_real_type
1467 handle_zdaoff (const struct v850_operand * operand)
1469 if (operand == NULL) return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1470 if (operand->bits == 15 && operand->shift == 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET;
1471 if (operand->bits == -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET;
1473 if ( operand->bits != 16
1474 || operand->shift != 16)
1476 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1477 return BFD_RELOC_64; /* Used to indicate an error condition. */
1480 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1483 static bfd_reloc_code_real_type
1484 handle_tdaoff (const struct v850_operand * operand)
1486 if (operand == NULL) return BFD_RELOC_V850_TDA_7_7_OFFSET; /* data item, not an instruction. */
1487 if (operand->bits == 6 && operand->shift == 1) return BFD_RELOC_V850_TDA_6_8_OFFSET; /* sld.w/sst.w, operand: D8_6 */
1488 if (operand->bits == 4 && operand->insert != NULL) return BFD_RELOC_V850_TDA_4_5_OFFSET; /* sld.hu, operand: D5-4 */
1489 if (operand->bits == 4 && operand->insert == NULL) return BFD_RELOC_V850_TDA_4_4_OFFSET; /* sld.bu, operand: D4 */
1490 if (operand->bits == 16 && operand->shift == 16) return BFD_RELOC_V850_TDA_16_16_OFFSET; /* set1 & chums, operands: D16 */
1492 if (operand->bits != 7)
1494 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1495 return BFD_RELOC_64; /* Used to indicate an error condition. */
1498 return operand->insert != NULL
1499 ? BFD_RELOC_V850_TDA_7_8_OFFSET /* sld.h/sst.h, operand: D8_7 */
1500 : BFD_RELOC_V850_TDA_7_7_OFFSET; /* sld.b/sst.b, opreand: D7 */
1503 /* Warning: The code in this function relies upon the definitions
1504 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1505 matching the hard coded values contained herein. */
1507 static bfd_reloc_code_real_type
1508 v850_reloc_prefix (const struct v850_operand * operand)
1510 boolean paren_skipped = false;
1513 /* Skip leading opening parenthesis. */
1514 if (* input_line_pointer == '(')
1516 ++ input_line_pointer;
1517 paren_skipped = true;
1520 #define CHECK_(name, reloc) \
1521 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1523 input_line_pointer += strlen (name); \
1527 CHECK_ ("hi0", BFD_RELOC_HI16);
1528 CHECK_ ("hi", BFD_RELOC_HI16_S);
1529 CHECK_ ("lo", BFD_RELOC_LO16);
1530 CHECK_ ("sdaoff", handle_sdaoff (operand));
1531 CHECK_ ("zdaoff", handle_zdaoff (operand));
1532 CHECK_ ("tdaoff", handle_tdaoff (operand));
1533 CHECK_ ("hilo", BFD_RELOC_32);
1534 CHECK_ ("ctoff", handle_ctoff (operand));
1536 /* Restore skipped parenthesis. */
1538 -- input_line_pointer;
1540 return BFD_RELOC_UNUSED;
1543 /* Insert an operand value into an instruction. */
1545 static unsigned long
1546 v850_insert_operand (insn, operand, val, file, line, str)
1548 const struct v850_operand * operand;
1554 if (operand->insert)
1556 const char * message = NULL;
1558 insn = operand->insert (insn, val, & message);
1559 if (message != NULL)
1561 if ((operand->flags & V850_OPERAND_SIGNED)
1562 && ! warn_signed_overflows
1563 && strstr (message, "out of range") != NULL)
1565 /* skip warning... */
1567 else if ((operand->flags & V850_OPERAND_SIGNED) == 0
1568 && ! warn_unsigned_overflows
1569 && strstr (message, "out of range") != NULL)
1571 /* skip warning... */
1575 if (file == (char *) NULL)
1576 as_warn ("%s: %s", str, message);
1578 as_warn_where (file, line, "%s: %s", str, message);
1582 if (file == (char *) NULL)
1585 as_warn_where (file, line, message);
1591 if (operand->bits != 32)
1596 if ((operand->flags & V850_OPERAND_SIGNED) != 0)
1598 if (! warn_signed_overflows)
1599 max = (1 << operand->bits) - 1;
1601 max = (1 << (operand->bits - 1)) - 1;
1603 min = - (1 << (operand->bits - 1));
1607 max = (1 << operand->bits) - 1;
1609 if (! warn_unsigned_overflows)
1610 min = - (1 << (operand->bits - 1));
1615 if (val < (offsetT) min || val > (offsetT) max)
1617 /* xgettext:c-format */
1618 const char * err = _("operand out of range (%s not between %ld and %ld)");
1621 /* Restore min and mix to expected values for decimal ranges. */
1622 if ((operand->flags & V850_OPERAND_SIGNED)
1623 && ! warn_signed_overflows)
1624 max = (1 << (operand->bits - 1)) - 1;
1626 if (! (operand->flags & V850_OPERAND_SIGNED)
1627 && ! warn_unsigned_overflows)
1632 sprintf (buf, "%s: ", str);
1634 sprint_value (buf + strlen (buf), val);
1637 sprint_value (buf, val);
1639 if (file == (char *) NULL)
1640 as_warn (err, buf, min, max);
1642 as_warn_where (file, line, err, buf, min, max);
1646 insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift);
1653 static char copy_of_instruction [128];
1660 char * start_of_operands;
1661 struct v850_opcode * opcode;
1662 struct v850_opcode * next_opcode;
1663 const unsigned char * opindex_ptr;
1667 unsigned long insn_size;
1671 boolean extra_data_after_insn = false;
1672 unsigned extra_data_len;
1673 unsigned long extra_data;
1674 char * saved_input_line_pointer;
1677 strncpy (copy_of_instruction, str, sizeof (copy_of_instruction) - 1);
1679 /* Get the opcode. */
1680 for (s = str; *s != '\0' && ! isspace (*s); s++)
1686 /* find the first opcode with the proper name */
1687 opcode = (struct v850_opcode *) hash_find (v850_hash, str);
1690 /* xgettext:c-format */
1691 as_bad (_("Unrecognized opcode: `%s'"), str);
1692 ignore_rest_of_line ();
1697 while (isspace (* str))
1700 start_of_operands = str;
1702 saved_input_line_pointer = input_line_pointer;
1706 const char * errmsg = NULL;
1710 if ((opcode->processors & processor_mask) == 0)
1712 errmsg = _("Target processor does not support this instruction.");
1719 insn = opcode->opcode;
1720 extra_data_after_insn = false;
1722 input_line_pointer = str = start_of_operands;
1724 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr ++)
1726 const struct v850_operand * operand;
1729 bfd_reloc_code_real_type reloc;
1731 if (next_opindex == 0)
1733 operand = & v850_operands[ * opindex_ptr ];
1737 operand = & v850_operands[ next_opindex ];
1743 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1746 if (operand->flags & V850_OPERAND_RELAX)
1749 /* Gather the operand. */
1750 hold = input_line_pointer;
1751 input_line_pointer = str;
1753 /* lo(), hi(), hi0(), etc... */
1754 if ((reloc = v850_reloc_prefix (operand)) != BFD_RELOC_UNUSED)
1756 /* This is a fake reloc, used to indicate an error condition. */
1757 if (reloc == BFD_RELOC_64)
1765 if (ex.X_op == O_constant)
1769 case BFD_RELOC_V850_ZDA_16_16_OFFSET:
1770 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1774 case BFD_RELOC_LO16:
1776 /* Truncate, then sign extend the value. */
1777 ex.X_add_number = SEXT16 (ex.X_add_number);
1781 case BFD_RELOC_HI16:
1783 /* Truncate, then sign extend the value. */
1784 ex.X_add_number = SEXT16 (ex.X_add_number >> 16);
1788 case BFD_RELOC_HI16_S:
1790 /* Truncate, then sign extend the value. */
1791 int temp = (ex.X_add_number >> 16) & 0xffff;
1793 temp += (ex.X_add_number >> 15) & 1;
1795 ex.X_add_number = SEXT16 (temp);
1800 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1802 errmsg = _("immediate operand is too large");
1806 extra_data_after_insn = true;
1808 extra_data = ex.X_add_number;
1809 ex.X_add_number = 0;
1813 fprintf (stderr, "reloc: %d\n", reloc);
1814 as_bad (_("AAARG -> unhandled constant reloc"));
1818 if (fc > MAX_INSN_FIXUPS)
1819 as_fatal (_("too many fixups"));
1821 fixups[ fc ].exp = ex;
1822 fixups[ fc ].opindex = * opindex_ptr;
1823 fixups[ fc ].reloc = reloc;
1828 if (reloc == BFD_RELOC_32)
1830 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1832 errmsg = _("immediate operand is too large");
1836 extra_data_after_insn = true;
1838 extra_data = ex.X_add_number;
1841 if (fc > MAX_INSN_FIXUPS)
1842 as_fatal (_("too many fixups"));
1844 fixups[ fc ].exp = ex;
1845 fixups[ fc ].opindex = * opindex_ptr;
1846 fixups[ fc ].reloc = reloc;
1854 if ((operand->flags & V850_OPERAND_REG) != 0)
1856 if (!register_name (& ex))
1858 errmsg = _("invalid register name");
1860 else if ((operand->flags & V850_NOT_R0)
1861 && ex.X_add_number == 0)
1863 errmsg = _("register r0 cannot be used here");
1865 /* Force an error message to be generated by
1866 skipping over any following potential matches
1871 else if ((operand->flags & V850_OPERAND_SRG) != 0)
1873 if (!system_register_name (& ex, true, false))
1875 errmsg = _("invalid system register name");
1878 else if ((operand->flags & V850_OPERAND_EP) != 0)
1880 char * start = input_line_pointer;
1881 char c = get_symbol_end ();
1883 if (strcmp (start, "ep") != 0 && strcmp (start, "r30") != 0)
1885 /* Put things back the way we found them. */
1886 *input_line_pointer = c;
1887 input_line_pointer = start;
1888 errmsg = _("expected EP register");
1892 *input_line_pointer = c;
1893 str = input_line_pointer;
1894 input_line_pointer = hold;
1896 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1900 else if ((operand->flags & V850_OPERAND_CC) != 0)
1902 if (!cc_name (& ex))
1904 errmsg = _("invalid condition code name");
1907 else if (operand->flags & V850E_PUSH_POP)
1909 errmsg = parse_register_list (& insn, operand);
1911 /* The parse_register_list() function has already done
1912 everything, so fake a dummy expression. */
1913 ex.X_op = O_constant;
1914 ex.X_add_number = 0;
1916 else if (operand->flags & V850E_IMMEDIATE16)
1920 if (ex.X_op != O_constant)
1921 errmsg = _("constant expression expected");
1922 else if (ex.X_add_number & 0xffff0000)
1924 if (ex.X_add_number & 0xffff)
1925 errmsg = _("constant too big to fit into instruction");
1926 else if ((insn & 0x001fffc0) == 0x00130780)
1927 ex.X_add_number >>= 16;
1929 errmsg = _("constant too big to fit into instruction");
1932 extra_data_after_insn = true;
1934 extra_data = ex.X_add_number;
1935 ex.X_add_number = 0;
1937 else if (operand->flags & V850E_IMMEDIATE32)
1941 if (ex.X_op != O_constant)
1942 errmsg = _("constant expression expected");
1944 extra_data_after_insn = true;
1946 extra_data = ex.X_add_number;
1947 ex.X_add_number = 0;
1949 else if (register_name (& ex)
1950 && (operand->flags & V850_OPERAND_REG) == 0)
1955 /* It is possible that an alias has been defined that
1956 matches a register name. For example the code may
1957 include a ".set ZERO, 0" directive, which matches
1958 the register name "zero". Attempt to reparse the
1959 field as an expression, and only complain if we
1960 cannot generate a constant. */
1962 input_line_pointer = str;
1964 c = get_symbol_end ();
1966 if (symbol_find (str) != NULL)
1969 * input_line_pointer = c;
1970 input_line_pointer = str;
1974 if (ex.X_op != O_constant)
1976 /* If this register is actually occuring too early on
1977 the parsing of the instruction, (because another
1978 field is missing) then report this. */
1979 if (opindex_ptr[1] != 0
1980 && (v850_operands [opindex_ptr [1]].flags & V850_OPERAND_REG))
1981 errmsg = _("syntax error: value is missing before the register name");
1983 errmsg = _("syntax error: register not expected");
1985 /* If we created a symbol in the process of this test then
1986 delete it now, so that it will not be output with the real
1989 && ex.X_op == O_symbol)
1990 symbol_remove (ex.X_add_symbol,
1991 & symbol_rootP, & symbol_lastP);
1994 else if (system_register_name (& ex, false, false)
1995 && (operand->flags & V850_OPERAND_SRG) == 0)
1997 errmsg = _("syntax error: system register not expected");
1999 else if (cc_name (&ex)
2000 && (operand->flags & V850_OPERAND_CC) == 0)
2002 errmsg = _("syntax error: condition code not expected");
2008 If we are assembling a MOV instruction (or a CALLT.... :-)
2009 and the immediate value does not fit into the bits
2010 available then create a fake error so that the next MOV
2011 instruction will be selected. This one has a 32 bit
2014 if (((insn & 0x07e0) == 0x0200)
2015 && ex.X_op == O_constant
2016 && (ex.X_add_number < (- (1 << (operand->bits - 1)))
2017 || ex.X_add_number > ((1 << operand->bits) - 1)))
2018 errmsg = _("immediate operand is too large");
2024 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n",
2025 insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
2030 errmsg = _("illegal operand");
2033 errmsg = _("missing operand");
2036 if ((operand->flags & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0)
2038 errmsg = _("invalid operand");
2041 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2043 copy_of_instruction);
2047 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2049 copy_of_instruction);
2053 /* We need to generate a fixup for this expression. */
2054 if (fc >= MAX_INSN_FIXUPS)
2055 as_fatal (_("too many fixups"));
2057 fixups[ fc ].exp = ex;
2058 fixups[ fc ].opindex = * opindex_ptr;
2059 fixups[ fc ].reloc = BFD_RELOC_UNUSED;
2065 str = input_line_pointer;
2066 input_line_pointer = hold;
2068 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']'
2077 next_opcode = opcode + 1;
2078 if (next_opcode->name != NULL
2079 && strcmp (next_opcode->name, opcode->name) == 0)
2081 opcode = next_opcode;
2083 /* Skip versions that are not supported by the target
2085 if ((opcode->processors & processor_mask) == 0)
2091 as_bad ("%s: %s", copy_of_instruction, errmsg);
2093 if (* input_line_pointer == ']')
2094 ++ input_line_pointer;
2096 ignore_rest_of_line ();
2097 input_line_pointer = saved_input_line_pointer;
2103 while (isspace (*str))
2107 /* xgettext:c-format */
2108 as_bad (_("junk at end of line: `%s'"), str);
2110 input_line_pointer = str;
2112 /* Write out the instruction. */
2114 if (relaxable && fc > 0)
2119 if (!strcmp (opcode->name, "br"))
2121 f = frag_var (rs_machine_dependent, 4, 2, 2,
2122 fixups[0].exp.X_add_symbol,
2123 fixups[0].exp.X_add_number,
2124 (char *)fixups[0].opindex);
2125 md_number_to_chars (f, insn, insn_size);
2126 md_number_to_chars (f + 2, 0, 2);
2130 f = frag_var (rs_machine_dependent, 6, 4, 0,
2131 fixups[0].exp.X_add_symbol,
2132 fixups[0].exp.X_add_number,
2133 (char *)fixups[0].opindex);
2134 md_number_to_chars (f, insn, insn_size);
2135 md_number_to_chars (f + 2, 0, 4);
2140 /* Four byte insns have an opcode with the two high bits on. */
2141 if ((insn & 0x0600) == 0x0600)
2146 /* Special case: 32 bit MOV */
2147 if ((insn & 0xffe0) == 0x0620)
2150 f = frag_more (insn_size);
2152 md_number_to_chars (f, insn, insn_size);
2154 if (extra_data_after_insn)
2156 f = frag_more (extra_data_len);
2158 md_number_to_chars (f, extra_data, extra_data_len);
2160 extra_data_after_insn = false;
2164 /* Create any fixups. At this point we do not use a
2165 bfd_reloc_code_real_type, but instead just use the
2166 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2167 handle fixups for any operand type, although that is admittedly
2168 not a very exciting feature. We pick a BFD reloc type in
2170 for (i = 0; i < fc; i++)
2172 const struct v850_operand * operand;
2173 bfd_reloc_code_real_type reloc;
2175 operand = & v850_operands[ fixups[i].opindex ];
2177 reloc = fixups[i].reloc;
2179 if (reloc != BFD_RELOC_UNUSED)
2181 reloc_howto_type * reloc_howto = bfd_reloc_type_lookup (stdoutput,
2190 size = bfd_get_reloc_size (reloc_howto);
2192 /* XXX This will abort on an R_V850_8 reloc -
2193 is this reloc actually used ? */
2194 if (size != 2 && size != 4)
2197 address = (f - frag_now->fr_literal) + insn_size - size;
2199 if (reloc == BFD_RELOC_32)
2204 fixP = fix_new_exp (frag_now, address, size,
2206 reloc_howto->pc_relative,
2211 case BFD_RELOC_LO16:
2212 case BFD_RELOC_HI16:
2213 case BFD_RELOC_HI16_S:
2214 fixP->fx_no_overflow = 1;
2222 f - frag_now->fr_literal, 4,
2224 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2225 (bfd_reloc_code_real_type) (fixups[i].opindex
2226 + (int) BFD_RELOC_UNUSED)
2231 input_line_pointer = saved_input_line_pointer;
2235 /* If while processing a fixup, a reloc really needs to be created */
2236 /* then it is done here. */
2239 tc_gen_reloc (seg, fixp)
2245 reloc = (arelent *) xmalloc (sizeof (arelent));
2246 reloc->sym_ptr_ptr = & fixp->fx_addsy->bsym;
2247 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2248 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2250 if (reloc->howto == (reloc_howto_type *) NULL)
2252 as_bad_where (fixp->fx_file, fixp->fx_line,
2253 /* xgettext:c-format */
2254 _("reloc %d not supported by object file format"),
2255 (int) fixp->fx_r_type);
2262 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
2263 || fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT)
2264 reloc->addend = fixp->fx_offset;
2266 reloc->addend = fixp->fx_addnumber;
2271 /* Assume everything will fit in two bytes, then expand as necessary. */
2273 md_estimate_size_before_relax (fragp, seg)
2277 if (fragp->fr_subtype == 0)
2279 else if (fragp->fr_subtype == 2)
2287 v850_pcrel_from_section (fixp, section)
2291 /* If the symbol is undefined, or in a section other than our own,
2292 then let the linker figure it out. */
2293 if (fixp->fx_addsy != (symbolS *) NULL
2294 && (! S_IS_DEFINED (fixp->fx_addsy)
2295 || (S_GET_SEGMENT (fixp->fx_addsy) != section)))
2297 /* The symbol is undefined/not in our section.
2298 Let the linker figure it out. */
2302 return fixp->fx_frag->fr_address + fixp->fx_where;
2306 md_apply_fix3 (fixp, valuep, seg)
2314 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2315 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2321 if (fixp->fx_addsy == (symbolS *) NULL)
2326 else if (fixp->fx_pcrel)
2330 value = fixp->fx_offset;
2331 if (fixp->fx_subsy != (symbolS *) NULL)
2333 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
2334 value -= S_GET_VALUE (fixp->fx_subsy);
2337 /* We don't actually support subtracting a symbol. */
2338 as_bad_where (fixp->fx_file, fixp->fx_line,
2339 _("expression too complex"));
2344 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
2347 const struct v850_operand * operand;
2350 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
2351 operand = & v850_operands[ opindex ];
2353 /* Fetch the instruction, insert the fully resolved operand
2354 value, and stuff the instruction back again.
2356 Note the instruction has been stored in little endian
2358 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2360 insn = bfd_getl32 ((unsigned char *) where);
2361 insn = v850_insert_operand (insn, operand, (offsetT) value,
2362 fixp->fx_file, fixp->fx_line, NULL);
2363 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
2367 /* Nothing else to do here. */
2371 /* Determine a BFD reloc value based on the operand information.
2372 We are only prepared to turn a few of the operands into relocs. */
2374 if (operand->bits == 22)
2375 fixp->fx_r_type = BFD_RELOC_V850_22_PCREL;
2376 else if (operand->bits == 9)
2377 fixp->fx_r_type = BFD_RELOC_V850_9_PCREL;
2380 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2382 as_bad_where (fixp->fx_file, fixp->fx_line,
2383 _("unresolved expression that must be resolved"));
2388 else if (fixp->fx_done)
2390 /* We still have to insert the value into memory! */
2391 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2393 if (fixp->fx_size == 1)
2394 * where = value & 0xff;
2395 else if (fixp->fx_size == 2)
2396 bfd_putl16 (value & 0xffff, (unsigned char *) where);
2397 else if (fixp->fx_size == 4)
2398 bfd_putl32 (value, (unsigned char *) where);
2401 fixp->fx_addnumber = value;
2406 /* Parse a cons expression. We have to handle hi(), lo(), etc
2409 parse_cons_expression_v850 (exp)
2412 /* See if there's a reloc prefix like hi() we have to handle. */
2413 hold_cons_reloc = v850_reloc_prefix (NULL);
2415 /* Do normal expression parsing. */
2419 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2420 found a reloc prefix, then we use that reloc, else we choose an
2421 appropriate one based on the size of the expression. */
2423 cons_fix_new_v850 (frag, where, size, exp)
2429 if (hold_cons_reloc == BFD_RELOC_UNUSED)
2432 hold_cons_reloc = BFD_RELOC_32;
2434 hold_cons_reloc = BFD_RELOC_16;
2436 hold_cons_reloc = BFD_RELOC_8;
2440 fix_new_exp (frag, where, size, exp, 0, hold_cons_reloc);
2442 fix_new (frag, where, size, NULL, 0, 0, hold_cons_reloc);
2445 v850_fix_adjustable (fixP)
2449 if (fixP->fx_addsy == NULL)
2452 /* Prevent all adjustments to global symbols. */
2453 if (S_IS_EXTERN (fixP->fx_addsy))
2455 if (S_IS_WEAK (fixP->fx_addsy))
2457 /* Don't adjust function names */
2458 if (S_IS_FUNCTION (fixP->fx_addsy))
2461 /* We need the symbol name for the VTABLE entries */
2462 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2463 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2470 v850_force_relocation (fixp)
2473 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2474 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)