1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright (C) 1996, 1997, 1998, 1999 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 int processor_mask = -1;
47 /* Structure to hold information about predefined registers. */
54 /* Generic assembler global variables which must be defined by all
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";
75 const relax_typeS md_relax_table[] =
77 /* Conditional branches. */
79 {0x1fffff, -0x200000, 6, 0},
80 /* Unconditional branches. */
82 {0x1fffff, -0x200000, 4, 0},
85 static segT sdata_section = NULL;
86 static segT tdata_section = NULL;
87 static segT zdata_section = NULL;
88 static segT sbss_section = NULL;
89 static segT tbss_section = NULL;
90 static segT zbss_section = NULL;
91 static segT rosdata_section = NULL;
92 static segT rozdata_section = NULL;
93 static segT scommon_section = NULL;
94 static segT tcommon_section = NULL;
95 static segT zcommon_section = NULL;
96 static segT call_table_data_section = NULL;
97 static segT call_table_text_section = NULL;
100 #define MAX_INSN_FIXUPS (5)
105 bfd_reloc_code_real_type reloc;
108 struct v850_fixup fixups[MAX_INSN_FIXUPS];
112 v850_sdata (int ignore ATTRIBUTE_UNUSED)
114 obj_elf_section_change_hook ();
116 subseg_set (sdata_section, (subsegT) get_absolute_expression ());
118 demand_empty_rest_of_line ();
122 v850_tdata (int ignore ATTRIBUTE_UNUSED)
124 obj_elf_section_change_hook ();
126 subseg_set (tdata_section, (subsegT) get_absolute_expression ());
128 demand_empty_rest_of_line ();
132 v850_zdata (int ignore ATTRIBUTE_UNUSED)
134 obj_elf_section_change_hook ();
136 subseg_set (zdata_section, (subsegT) get_absolute_expression ());
138 demand_empty_rest_of_line ();
142 v850_sbss (int ignore ATTRIBUTE_UNUSED)
144 obj_elf_section_change_hook ();
146 subseg_set (sbss_section, (subsegT) get_absolute_expression ());
148 demand_empty_rest_of_line ();
152 v850_tbss (int ignore ATTRIBUTE_UNUSED)
154 obj_elf_section_change_hook ();
156 subseg_set (tbss_section, (subsegT) get_absolute_expression ());
158 demand_empty_rest_of_line ();
162 v850_zbss (int ignore ATTRIBUTE_UNUSED)
164 obj_elf_section_change_hook ();
166 subseg_set (zbss_section, (subsegT) get_absolute_expression ());
168 demand_empty_rest_of_line ();
172 v850_rosdata (int ignore ATTRIBUTE_UNUSED)
174 obj_elf_section_change_hook ();
176 subseg_set (rosdata_section, (subsegT) get_absolute_expression ());
178 demand_empty_rest_of_line ();
182 v850_rozdata (int ignore ATTRIBUTE_UNUSED)
184 obj_elf_section_change_hook ();
186 subseg_set (rozdata_section, (subsegT) get_absolute_expression ());
188 demand_empty_rest_of_line ();
192 v850_call_table_data (int ignore ATTRIBUTE_UNUSED)
194 obj_elf_section_change_hook ();
196 subseg_set (call_table_data_section, (subsegT) get_absolute_expression ());
198 demand_empty_rest_of_line ();
202 v850_call_table_text (int ignore ATTRIBUTE_UNUSED)
204 obj_elf_section_change_hook ();
206 subseg_set (call_table_text_section, (subsegT) get_absolute_expression ());
208 demand_empty_rest_of_line ();
212 v850_bss (int ignore ATTRIBUTE_UNUSED)
214 register int temp = get_absolute_expression ();
216 obj_elf_section_change_hook ();
218 subseg_set (bss_section, (subsegT) temp);
220 demand_empty_rest_of_line ();
224 v850_offset (int ignore ATTRIBUTE_UNUSED)
226 int temp = get_absolute_expression ();
228 temp -= frag_now_fix ();
231 (void) frag_more (temp);
233 demand_empty_rest_of_line ();
236 /* Copied from obj_elf_common() in gas/config/obj-elf.c. */
250 name = input_line_pointer;
251 c = get_symbol_end ();
253 /* Just after name is now '\0'. */
254 p = input_line_pointer;
259 if (*input_line_pointer != ',')
261 as_bad (_("Expected comma after symbol-name"));
262 ignore_rest_of_line ();
267 input_line_pointer++;
269 if ((temp = get_absolute_expression ()) < 0)
271 /* xgettext:c-format */
272 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp);
273 ignore_rest_of_line ();
279 symbolP = symbol_find_or_make (name);
282 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
284 as_bad (_("Ignoring attempt to re-define symbol"));
285 ignore_rest_of_line ();
289 if (S_GET_VALUE (symbolP) != 0)
291 if (S_GET_VALUE (symbolP) != size)
293 /* xgettext:c-format */
294 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
295 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
299 know (symbol_get_frag (symbolP) == &zero_address_frag);
301 if (*input_line_pointer != ',')
306 input_line_pointer++;
310 if (! have_align || *input_line_pointer != '"')
316 temp = get_absolute_expression ();
321 as_warn (_("Common alignment negative; 0 assumed"));
325 if (symbol_get_obj (symbolP)->local)
334 old_subsec = now_subseg;
336 applicable = bfd_applicable_section_flags (stdoutput);
338 applicable &= SEC_ALLOC;
343 if (sbss_section == NULL)
345 sbss_section = subseg_new (".sbss", 0);
347 bfd_set_section_flags (stdoutput, sbss_section, applicable);
349 seg_info (sbss_section)->bss = 1;
354 if (zbss_section == NULL)
356 zbss_section = subseg_new (".zbss", 0);
358 bfd_set_section_flags (stdoutput, sbss_section, applicable);
360 seg_info (zbss_section)->bss = 1;
365 if (tbss_section == NULL)
367 tbss_section = subseg_new (".tbss", 0);
369 bfd_set_section_flags (stdoutput, tbss_section, applicable);
371 seg_info (tbss_section)->bss = 1;
378 /* Convert to a power of 2 alignment. */
379 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align)
384 as_bad (_("Common alignment not a power of 2"));
385 ignore_rest_of_line ();
395 record_alignment (sbss_section, align);
396 obj_elf_section_change_hook ();
397 subseg_set (sbss_section, 0);
401 record_alignment (zbss_section, align);
402 obj_elf_section_change_hook ();
403 subseg_set (zbss_section, 0);
407 record_alignment (tbss_section, align);
408 obj_elf_section_change_hook ();
409 subseg_set (tbss_section, 0);
417 frag_align (align, 0, 0);
422 if (S_GET_SEGMENT (symbolP) == sbss_section)
423 symbol_get_frag (symbolP)->fr_symbol = 0;
427 if (S_GET_SEGMENT (symbolP) == zbss_section)
428 symbol_get_frag (symbolP)->fr_symbol = 0;
432 if (S_GET_SEGMENT (symbolP) == tbss_section)
433 symbol_get_frag (symbolP)->fr_symbol = 0;
440 symbol_set_frag (symbolP, frag_now);
441 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
442 (offsetT) size, (char *) 0);
444 S_SET_SIZE (symbolP, size);
449 S_SET_SEGMENT (symbolP, sbss_section);
453 S_SET_SEGMENT (symbolP, zbss_section);
457 S_SET_SEGMENT (symbolP, tbss_section);
464 S_CLEAR_EXTERNAL (symbolP);
465 obj_elf_section_change_hook ();
466 subseg_set (old_sec, old_subsec);
471 S_SET_VALUE (symbolP, (valueT) size);
472 S_SET_ALIGN (symbolP, temp);
473 S_SET_EXTERNAL (symbolP);
478 if (scommon_section == NULL)
480 flagword applicable =
481 bfd_applicable_section_flags (stdoutput);
483 scommon_section = subseg_new (".scommon", 0);
485 bfd_set_section_flags (stdoutput, scommon_section,
487 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
488 | SEC_HAS_CONTENTS)) | SEC_IS_COMMON);
490 S_SET_SEGMENT (symbolP, scommon_section);
494 if (zcommon_section == NULL)
496 flagword applicable =
497 bfd_applicable_section_flags (stdoutput);
499 zcommon_section = subseg_new (".zcommon", 0);
501 bfd_set_section_flags (stdoutput, zcommon_section,
503 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
504 | SEC_HAS_CONTENTS)) | SEC_IS_COMMON);
506 S_SET_SEGMENT (symbolP, zcommon_section);
510 if (tcommon_section == NULL)
512 flagword applicable =
513 bfd_applicable_section_flags (stdoutput);
515 tcommon_section = subseg_new (".tcommon", 0);
517 bfd_set_section_flags (stdoutput, tcommon_section,
519 & (SEC_ALLOC | SEC_LOAD
520 | SEC_RELOC | SEC_DATA
524 S_SET_SEGMENT (symbolP, tcommon_section);
534 input_line_pointer++;
536 /* @@ Some use the dot, some don't. Can we get some consistency?? */
537 if (*input_line_pointer == '.')
538 input_line_pointer++;
540 /* @@ Some say data, some say bss. */
541 if (strncmp (input_line_pointer, "bss\"", 4)
542 && strncmp (input_line_pointer, "data\"", 5))
544 while (*--input_line_pointer != '"')
546 input_line_pointer--;
547 goto bad_common_segment;
549 while (*input_line_pointer++ != '"')
551 goto allocate_common;
554 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
556 demand_empty_rest_of_line ();
561 p = input_line_pointer;
562 while (*p && *p != '\n')
566 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
568 input_line_pointer = p;
569 ignore_rest_of_line ();
575 set_machine (int number)
578 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
582 case 0: processor_mask = PROCESSOR_V850; break;
583 case bfd_mach_v850e: processor_mask = PROCESSOR_V850E; break;
584 case bfd_mach_v850ea: processor_mask = PROCESSOR_V850EA; break;
588 /* The target specific pseudo-ops which we support. */
589 const pseudo_typeS md_pseudo_table[] =
591 {"sdata", v850_sdata, 0},
592 {"tdata", v850_tdata, 0},
593 {"zdata", v850_zdata, 0},
594 {"sbss", v850_sbss, 0},
595 {"tbss", v850_tbss, 0},
596 {"zbss", v850_zbss, 0},
597 {"rosdata", v850_rosdata, 0},
598 {"rozdata", v850_rozdata, 0},
599 {"bss", v850_bss, 0},
600 {"offset", v850_offset, 0},
602 {"zcomm", v850_comm, AREA_ZDA},
603 {"scomm", v850_comm, AREA_SDA},
604 {"tcomm", v850_comm, AREA_TDA},
605 {"v850", set_machine, 0},
606 {"call_table_data", v850_call_table_data, 0},
607 {"call_table_text", v850_call_table_text, 0},
608 {"v850e", set_machine, bfd_mach_v850e},
609 {"v850ea", set_machine, bfd_mach_v850ea},
613 /* Opcode hash table. */
614 static struct hash_control *v850_hash;
616 /* This table is sorted. Suitable for searching by a binary search. */
617 static const struct reg_name pre_defined_registers[] =
619 { "ep", 30 }, /* ep - element ptr */
620 { "gp", 4 }, /* gp - global ptr */
621 { "hp", 2 }, /* hp - handler stack ptr */
622 { "lp", 31 }, /* lp - link ptr */
655 { "sp", 3 }, /* sp - stack ptr */
656 { "tp", 5 }, /* tp - text ptr */
660 #define REG_NAME_CNT \
661 (sizeof (pre_defined_registers) / sizeof (struct reg_name))
663 static const struct reg_name system_registers[] =
678 #define SYSREG_NAME_CNT \
679 (sizeof (system_registers) / sizeof (struct reg_name))
681 static const struct reg_name system_list_registers[] =
687 #define SYSREGLIST_NAME_CNT \
688 (sizeof (system_list_registers) / sizeof (struct reg_name))
690 static const struct reg_name cc_names[] =
716 #define CC_NAME_CNT \
717 (sizeof (cc_names) / sizeof (struct reg_name))
719 /* Do a binary search of the given register table to see if NAME is a
720 valid regiter name. Return the register number from the array on
721 success, or -1 on failure. */
724 reg_name_search (regs, regcount, name, accept_numbers)
725 const struct reg_name *regs;
728 boolean accept_numbers;
730 int middle, low, high;
734 /* If the register name is a symbol, then evaluate it. */
735 if ((symbolP = symbol_find (name)) != NULL)
737 /* If the symbol is an alias for another name then use that.
738 If the symbol is an alias for a number, then return the number. */
739 if (symbol_equated_p (symbolP))
742 = S_GET_NAME (symbol_get_value_expression (symbolP)->X_add_symbol);
744 else if (accept_numbers)
746 int reg = S_GET_VALUE (symbolP);
748 if (reg >= 0 && reg <= 31)
752 /* Otherwise drop through and try parsing name normally. */
760 middle = (low + high) / 2;
761 cmp = strcasecmp (name, regs[middle].name);
767 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 /* Put back the delimiting char. */
801 *input_line_pointer = c;
803 /* Look to see if it's in the register table. */
806 expressionP->X_op = O_register;
807 expressionP->X_add_number = reg_number;
809 /* Make the rest nice. */
810 expressionP->X_add_symbol = NULL;
811 expressionP->X_op_symbol = NULL;
817 /* Reset the line as if we had not done anything. */
818 input_line_pointer = start;
824 /* Summary of system_register_name().
826 * in: INPUT_LINE_POINTER points to 1st char of operand.
827 * EXPRESSIONP points to an expression structure to be filled in.
828 * ACCEPT_NUMBERS is true iff numerical register names may be used.
829 * ACCEPT_LIST_NAMES is true iff the special names PS and SR may be
832 * out: A expressionS structure in expressionP.
833 * The operand may have been a register: in this case, X_op == O_register,
834 * X_add_number is set to the register number, and truth is returned.
835 * Input_line_pointer->(next non-blank) char after operand, or is in
836 * its original state. */
839 system_register_name (expressionP, accept_numbers, accept_list_names)
840 expressionS *expressionP;
841 boolean accept_numbers;
842 boolean accept_list_names;
849 /* Find the spelling of the operand. */
850 start = name = input_line_pointer;
852 c = get_symbol_end ();
853 reg_number = reg_name_search (system_registers, SYSREG_NAME_CNT, name,
856 /* Put back the delimiting char. */
857 *input_line_pointer = c;
862 /* Reset input_line pointer. */
863 input_line_pointer = start;
865 if (isdigit (*input_line_pointer))
867 reg_number = strtol (input_line_pointer, &input_line_pointer, 10);
869 /* Make sure that the register number is allowable. */
871 || (reg_number > 5 && reg_number < 16)
877 else if (accept_list_names)
879 c = get_symbol_end ();
880 reg_number = reg_name_search (system_list_registers,
881 SYSREGLIST_NAME_CNT, name, FALSE);
883 /* Put back the delimiting char. */
884 *input_line_pointer = c;
888 /* Look to see if it's in the register table. */
891 expressionP->X_op = O_register;
892 expressionP->X_add_number = reg_number;
894 /* Make the rest nice. */
895 expressionP->X_add_symbol = NULL;
896 expressionP->X_op_symbol = NULL;
902 /* Reset the line as if we had not done anything. */
903 input_line_pointer = start;
909 /* Summary of cc_name().
911 * in: INPUT_LINE_POINTER points to 1st char of operand.
913 * out: A expressionS.
914 * The operand may have been a register: in this case, X_op == O_register,
915 * X_add_number is set to the register number, and truth is returned.
916 * Input_line_pointer->(next non-blank) char after operand, or is in
917 * its original state. */
920 cc_name (expressionP)
921 expressionS *expressionP;
928 /* Find the spelling of the operand. */
929 start = name = input_line_pointer;
931 c = get_symbol_end ();
932 reg_number = reg_name_search (cc_names, CC_NAME_CNT, name, FALSE);
934 /* Put back the delimiting char. */
935 *input_line_pointer = c;
937 /* Look to see if it's in the register table. */
940 expressionP->X_op = O_constant;
941 expressionP->X_add_number = reg_number;
943 /* Make the rest nice. */
944 expressionP->X_add_symbol = NULL;
945 expressionP->X_op_symbol = NULL;
951 /* Reset the line as if we had not done anything. */
952 input_line_pointer = start;
959 skip_white_space (void)
961 while (*input_line_pointer == ' '
962 || *input_line_pointer == '\t')
963 ++input_line_pointer;
966 /* Summary of parse_register_list ().
968 * in: INPUT_LINE_POINTER points to 1st char of a list of registers.
969 * INSN is the partially constructed instruction.
970 * OPERAND is the operand being inserted.
972 * out: NULL if the parse completed successfully, otherwise a
973 * pointer to an error message is returned. If the parse
974 * completes the correct bit fields in the instruction
977 * Parses register lists with the syntax:
985 * and also parses constant epxressions whoes bits indicate the
986 * registers in the lists. The LSB in the expression refers to
987 * the lowest numbered permissable register in the register list,
988 * and so on upwards. System registers are considered to be very
992 parse_register_list (insn, operand)
994 const struct v850_operand *operand;
996 static int type1_regs[32] = {
997 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
998 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
1000 static int type2_regs[32] = {
1001 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1002 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
1004 static int type3_regs[32] = {
1005 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1006 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8
1011 /* Select a register array to parse. */
1012 switch (operand->shift)
1014 case 0xffe00001: regs = type1_regs; break;
1015 case 0xfff8000f: regs = type2_regs; break;
1016 case 0xfff8001f: regs = type3_regs; break;
1018 as_bad (_("unknown operand shift: %x\n"), operand->shift);
1019 return _("internal failure in parse_register_list");
1022 skip_white_space ();
1024 /* If the expression starts with a curly brace it is a register list.
1025 Otherwise it is a constant expression, whoes bits indicate which
1026 registers are to be included in the list. */
1028 if (*input_line_pointer != '{')
1035 if (exp.X_op != O_constant)
1036 return _("constant expression or register list expected");
1038 if (regs == type1_regs)
1040 if (exp.X_add_number & 0xFFFFF000)
1041 return _("high bits set in register list expression");
1043 for (reg = 20; reg < 32; reg++)
1044 if (exp.X_add_number & (1 << (reg - 20)))
1046 for (i = 0; i < 32; i++)
1051 else if (regs == type2_regs)
1053 if (exp.X_add_number & 0xFFFE0000)
1054 return _("high bits set in register list expression");
1056 for (reg = 1; reg < 16; reg++)
1057 if (exp.X_add_number & (1 << (reg - 1)))
1059 for (i = 0; i < 32; i++)
1064 if (exp.X_add_number & (1 << 15))
1067 if (exp.X_add_number & (1 << 16))
1070 else /* regs == type3_regs */
1072 if (exp.X_add_number & 0xFFFE0000)
1073 return _("high bits set in register list expression");
1075 for (reg = 16; reg < 32; reg++)
1076 if (exp.X_add_number & (1 << (reg - 16)))
1078 for (i = 0; i < 32; i++)
1083 if (exp.X_add_number & (1 << 16))
1090 input_line_pointer++;
1092 /* Parse the register list until a terminator (closing curly brace or
1093 new-line) is found. */
1096 if (register_name (&exp))
1100 /* Locate the given register in the list, and if it is there,
1101 insert the corresponding bit into the instruction. */
1102 for (i = 0; i < 32; i++)
1104 if (regs[i] == exp.X_add_number)
1113 return _("illegal register included in list");
1116 else if (system_register_name (&exp, true, true))
1118 if (regs == type1_regs)
1120 return _("system registers cannot be included in list");
1122 else if (exp.X_add_number == 5)
1124 if (regs == type2_regs)
1125 return _("PSW cannot be included in list");
1129 else if (exp.X_add_number < 4)
1132 return _("High value system registers cannot be included in list");
1134 else if (*input_line_pointer == '}')
1136 input_line_pointer++;
1139 else if (*input_line_pointer == ',')
1141 input_line_pointer++;
1144 else if (*input_line_pointer == '-')
1146 /* We have encountered a range of registers: rX - rY. */
1150 /* Skip the dash. */
1151 ++input_line_pointer;
1153 /* Get the second register in the range. */
1154 if (! register_name (&exp2))
1156 return _("second register should follow dash in register list");
1157 exp2.X_add_number = exp.X_add_number;
1160 /* Add the rest of the registers in the range. */
1161 for (j = exp.X_add_number + 1; j <= exp2.X_add_number; j++)
1165 /* Locate the given register in the list, and if it is there,
1166 insert the corresponding bit into the instruction. */
1167 for (i = 0; i < 32; i++)
1177 return _("illegal register included in list");
1185 skip_white_space ();
1191 CONST char *md_shortopts = "m:";
1193 struct option md_longopts[] =
1195 {NULL, no_argument, NULL, 0}
1198 size_t md_longopts_size = sizeof (md_longopts);
1201 md_show_usage (stream)
1204 fprintf (stream, _(" V850 options:\n"));
1205 fprintf (stream, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1206 fprintf (stream, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1207 fprintf (stream, _(" -mv850 The code is targeted at the v850\n"));
1208 fprintf (stream, _(" -mv850e The code is targeted at the v850e\n"));
1209 fprintf (stream, _(" -mv850ea The code is targeted at the v850ea\n"));
1210 fprintf (stream, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1214 md_parse_option (c, arg)
1221 /* xgettext:c-format */
1222 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1226 if (strcmp (arg, "warn-signed-overflow") == 0)
1228 warn_signed_overflows = TRUE;
1230 else if (strcmp (arg, "warn-unsigned-overflow") == 0)
1232 warn_unsigned_overflows = TRUE;
1234 else if (strcmp (arg, "v850") == 0)
1237 processor_mask = PROCESSOR_V850;
1239 else if (strcmp (arg, "v850e") == 0)
1241 machine = bfd_mach_v850e;
1242 processor_mask = PROCESSOR_V850E;
1244 else if (strcmp (arg, "v850ea") == 0)
1246 machine = bfd_mach_v850ea;
1247 processor_mask = PROCESSOR_V850EA;
1249 else if (strcmp (arg, "v850any") == 0)
1251 /* Tell the world that this is for any v850 chip. */
1254 /* But support instructions for the extended versions. */
1255 processor_mask = PROCESSOR_V850EA;
1259 /* xgettext:c-format */
1260 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1268 md_undefined_symbol (name)
1269 char *name ATTRIBUTE_UNUSED;
1275 md_atof (type, litp, sizep)
1281 LITTLENUM_TYPE words[4];
1297 return _("bad call to md_atof");
1300 t = atof_ieee (input_line_pointer, type, words);
1302 input_line_pointer = t;
1306 for (i = prec - 1; i >= 0; i--)
1308 md_number_to_chars (litp, (valueT) words[i], 2);
1318 md_convert_frag (abfd, sec, fragP)
1319 bfd *abfd ATTRIBUTE_UNUSED;
1323 subseg_change (sec, 0);
1325 /* In range conditional or unconditional branch. */
1326 if (fragP->fr_subtype == 0 || fragP->fr_subtype == 2)
1328 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
1329 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode);
1333 /* Out of range conditional branch. Emit a branch around a jump. */
1334 else if (fragP->fr_subtype == 1)
1336 unsigned char *buffer =
1337 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1339 /* Reverse the condition of the first branch. */
1341 /* Mask off all the displacement bits. */
1344 /* Now set the displacement bits so that we branch
1345 around the unconditional branch. */
1348 /* Now create the unconditional branch + fixup to the final
1350 md_number_to_chars (buffer + 2, 0x00000780, 4);
1351 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
1352 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1353 (int) fragP->fr_opcode + 1);
1357 /* Out of range unconditional branch. Emit a jump. */
1358 else if (fragP->fr_subtype == 3)
1360 md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x00000780, 4);
1361 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
1362 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1363 (int) fragP->fr_opcode + 1);
1372 md_section_align (seg, addr)
1376 int align = bfd_get_section_alignment (stdoutput, seg);
1377 return ((addr + (1 << align) - 1) & (-1 << align));
1383 char *prev_name = "";
1384 register const struct v850_opcode *op;
1385 flagword applicable;
1387 if (strncmp (TARGET_CPU, "v850ea", 6) == 0)
1390 machine = bfd_mach_v850ea;
1392 if (processor_mask == -1)
1393 processor_mask = PROCESSOR_V850EA;
1395 else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
1398 machine = bfd_mach_v850e;
1400 if (processor_mask == -1)
1401 processor_mask = PROCESSOR_V850E;
1403 else if (strncmp (TARGET_CPU, "v850", 4) == 0)
1408 if (processor_mask == -1)
1409 processor_mask = PROCESSOR_V850;
1412 /* xgettext:c-format */
1413 as_bad (_("Unable to determine default target processor from string: %s"),
1416 v850_hash = hash_new();
1418 /* Insert unique names into hash table. The V850 instruction set
1419 has many identical opcode names that have different opcodes based
1420 on the operands. This hash table then provides a quick index to
1421 the first opcode with a particular name in the opcode table. */
1426 if (strcmp (prev_name, op->name))
1428 prev_name = (char *) op->name;
1429 hash_insert (v850_hash, op->name, (char *) op);
1434 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
1436 applicable = bfd_applicable_section_flags (stdoutput);
1438 call_table_data_section = subseg_new (".call_table_data", 0);
1439 bfd_set_section_flags (stdoutput, call_table_data_section,
1440 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1441 | SEC_DATA | SEC_HAS_CONTENTS));
1443 call_table_text_section = subseg_new (".call_table_text", 0);
1444 bfd_set_section_flags (stdoutput, call_table_text_section,
1445 applicable & (SEC_ALLOC | SEC_LOAD | SEC_READONLY
1448 /* Restore text section as the current default. */
1449 subseg_set (text_section, 0);
1452 static bfd_reloc_code_real_type
1453 handle_ctoff (const struct v850_operand *operand)
1455 if (operand == NULL)
1456 return BFD_RELOC_V850_CALLT_16_16_OFFSET;
1458 if (operand->bits != 6
1459 || operand->shift != 0)
1461 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1462 return BFD_RELOC_64; /* Used to indicate an error condition. */
1465 return BFD_RELOC_V850_CALLT_6_7_OFFSET;
1468 static bfd_reloc_code_real_type
1469 handle_sdaoff (const struct v850_operand *operand)
1471 if (operand == NULL)
1472 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1474 if (operand->bits == 15 && operand->shift == 17)
1475 return BFD_RELOC_V850_SDA_15_16_OFFSET;
1477 if (operand->bits == -1)
1478 return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET;
1480 if (operand->bits != 16
1481 || operand->shift != 16)
1483 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1484 return BFD_RELOC_64; /* Used to indicate an error condition. */
1487 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1490 static bfd_reloc_code_real_type
1491 handle_zdaoff (const struct v850_operand *operand)
1493 if (operand == NULL)
1494 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1496 if (operand->bits == 15 && operand->shift == 17)
1497 return BFD_RELOC_V850_ZDA_15_16_OFFSET;
1499 if (operand->bits == -1)
1500 return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET;
1502 if (operand->bits != 16
1503 || operand->shift != 16)
1505 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1506 /* Used to indicate an error condition. */
1507 return BFD_RELOC_64;
1510 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1513 static bfd_reloc_code_real_type
1514 handle_tdaoff (const struct v850_operand *operand)
1516 if (operand == NULL)
1517 /* Data item, not an instruction. */
1518 return BFD_RELOC_V850_TDA_7_7_OFFSET;
1520 if (operand->bits == 6 && operand->shift == 1)
1521 /* sld.w/sst.w, operand: D8_6 */
1522 return BFD_RELOC_V850_TDA_6_8_OFFSET;
1524 if (operand->bits == 4 && operand->insert != NULL)
1525 /* sld.hu, operand: D5-4 */
1526 return BFD_RELOC_V850_TDA_4_5_OFFSET;
1528 if (operand->bits == 4 && operand->insert == NULL)
1529 /* sld.bu, operand: D4 */
1530 return BFD_RELOC_V850_TDA_4_4_OFFSET;
1532 if (operand->bits == 16 && operand->shift == 16)
1533 /* set1 & chums, operands: D16 */
1534 return BFD_RELOC_V850_TDA_16_16_OFFSET;
1536 if (operand->bits != 7)
1538 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1539 /* Used to indicate an error condition. */
1540 return BFD_RELOC_64;
1543 return operand->insert != NULL
1544 ? BFD_RELOC_V850_TDA_7_8_OFFSET /* sld.h/sst.h, operand: D8_7 */
1545 : BFD_RELOC_V850_TDA_7_7_OFFSET; /* sld.b/sst.b, opreand: D7 */
1548 /* Warning: The code in this function relies upon the definitions
1549 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1550 matching the hard coded values contained herein. */
1552 static bfd_reloc_code_real_type
1553 v850_reloc_prefix (const struct v850_operand *operand)
1555 boolean paren_skipped = false;
1557 /* Skip leading opening parenthesis. */
1558 if (*input_line_pointer == '(')
1560 ++input_line_pointer;
1561 paren_skipped = true;
1564 #define CHECK_(name, reloc) \
1565 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1567 input_line_pointer += strlen (name); \
1571 CHECK_ ("hi0", BFD_RELOC_HI16 );
1572 CHECK_ ("hi", BFD_RELOC_HI16_S );
1573 CHECK_ ("lo", BFD_RELOC_LO16 );
1574 CHECK_ ("sdaoff", handle_sdaoff (operand));
1575 CHECK_ ("zdaoff", handle_zdaoff (operand));
1576 CHECK_ ("tdaoff", handle_tdaoff (operand));
1577 CHECK_ ("hilo", BFD_RELOC_32 );
1578 CHECK_ ("ctoff", handle_ctoff (operand) );
1580 /* Restore skipped parenthesis. */
1582 --input_line_pointer;
1584 return BFD_RELOC_UNUSED;
1587 /* Insert an operand value into an instruction. */
1589 static unsigned long
1590 v850_insert_operand (insn, operand, val, file, line, str)
1592 const struct v850_operand *operand;
1598 if (operand->insert)
1600 const char *message = NULL;
1602 insn = operand->insert (insn, val, &message);
1603 if (message != NULL)
1605 if ((operand->flags & V850_OPERAND_SIGNED)
1606 && ! warn_signed_overflows
1607 && strstr (message, "out of range") != NULL)
1609 /* Skip warning... */
1611 else if ((operand->flags & V850_OPERAND_SIGNED) == 0
1612 && ! warn_unsigned_overflows
1613 && strstr (message, "out of range") != NULL)
1615 /* Skip warning... */
1619 if (file == (char *) NULL)
1620 as_warn ("%s: %s", str, message);
1622 as_warn_where (file, line, "%s: %s", str, message);
1626 if (file == (char *) NULL)
1629 as_warn_where (file, line, message);
1635 if (operand->bits != 32)
1639 if ((operand->flags & V850_OPERAND_SIGNED) != 0)
1641 if (! warn_signed_overflows)
1642 max = (1 << operand->bits) - 1;
1644 max = (1 << (operand->bits - 1)) - 1;
1646 min = -(1 << (operand->bits - 1));
1650 max = (1 << operand->bits) - 1;
1652 if (! warn_unsigned_overflows)
1653 min = -(1 << (operand->bits - 1));
1658 if (val < (offsetT) min || val > (offsetT) max)
1660 /* xgettext:c-format */
1662 _("operand out of range (%s not between %ld and %ld)");
1665 /* Restore min and mix to expected values for decimal ranges. */
1666 if ((operand->flags & V850_OPERAND_SIGNED)
1667 && ! warn_signed_overflows)
1668 max = (1 << (operand->bits - 1)) - 1;
1670 if (! (operand->flags & V850_OPERAND_SIGNED)
1671 && ! warn_unsigned_overflows)
1676 sprintf (buf, "%s: ", str);
1678 sprint_value (buf + strlen (buf), val);
1681 sprint_value (buf, val);
1683 if (file == (char *) NULL)
1684 as_warn (err, buf, min, max);
1686 as_warn_where (file, line, err, buf, min, max);
1690 insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift);
1696 static char copy_of_instruction[128];
1703 char *start_of_operands;
1704 struct v850_opcode *opcode;
1705 struct v850_opcode *next_opcode;
1706 const unsigned char *opindex_ptr;
1710 unsigned long insn_size;
1714 boolean extra_data_after_insn = false;
1715 unsigned extra_data_len = 0;
1716 unsigned long extra_data = 0;
1717 char *saved_input_line_pointer;
1719 strncpy (copy_of_instruction, str, sizeof (copy_of_instruction) - 1);
1721 /* Get the opcode. */
1722 for (s = str; *s != '\0' && ! isspace (*s); s++)
1728 /* Find the first opcode with the proper name. */
1729 opcode = (struct v850_opcode *) hash_find (v850_hash, str);
1732 /* xgettext:c-format */
1733 as_bad (_("Unrecognized opcode: `%s'"), str);
1734 ignore_rest_of_line ();
1739 while (isspace (*str))
1742 start_of_operands = str;
1744 saved_input_line_pointer = input_line_pointer;
1748 const char *errmsg = NULL;
1752 if ((opcode->processors & processor_mask) == 0)
1754 errmsg = _("Target processor does not support this instruction.");
1761 insn = opcode->opcode;
1762 extra_data_after_insn = false;
1764 input_line_pointer = str = start_of_operands;
1766 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1768 const struct v850_operand *operand;
1771 bfd_reloc_code_real_type reloc;
1773 if (next_opindex == 0)
1775 operand = &v850_operands[*opindex_ptr];
1779 operand = &v850_operands[next_opindex];
1785 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1788 if (operand->flags & V850_OPERAND_RELAX)
1791 /* Gather the operand. */
1792 hold = input_line_pointer;
1793 input_line_pointer = str;
1795 /* lo(), hi(), hi0(), etc... */
1796 if ((reloc = v850_reloc_prefix (operand)) != BFD_RELOC_UNUSED)
1798 /* This is a fake reloc, used to indicate an error condition. */
1799 if (reloc == BFD_RELOC_64)
1807 if (ex.X_op == O_constant)
1811 case BFD_RELOC_V850_ZDA_16_16_OFFSET:
1812 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1816 case BFD_RELOC_LO16:
1818 /* Truncate, then sign extend the value. */
1819 ex.X_add_number = SEXT16 (ex.X_add_number);
1823 case BFD_RELOC_HI16:
1825 /* Truncate, then sign extend the value. */
1826 ex.X_add_number = SEXT16 (ex.X_add_number >> 16);
1830 case BFD_RELOC_HI16_S:
1832 /* Truncate, then sign extend the value. */
1833 int temp = (ex.X_add_number >> 16) & 0xffff;
1835 temp += (ex.X_add_number >> 15) & 1;
1837 ex.X_add_number = SEXT16 (temp);
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;
1855 fprintf (stderr, "reloc: %d\n", reloc);
1856 as_bad (_("AAARG -> unhandled constant reloc"));
1860 if (fc > MAX_INSN_FIXUPS)
1861 as_fatal (_("too many fixups"));
1863 fixups[fc].exp = ex;
1864 fixups[fc].opindex = *opindex_ptr;
1865 fixups[fc].reloc = reloc;
1870 if (reloc == BFD_RELOC_32)
1872 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1874 errmsg = _("immediate operand is too large");
1878 extra_data_after_insn = true;
1880 extra_data = ex.X_add_number;
1883 if (fc > MAX_INSN_FIXUPS)
1884 as_fatal (_("too many fixups"));
1886 fixups[fc].exp = ex;
1887 fixups[fc].opindex = *opindex_ptr;
1888 fixups[fc].reloc = reloc;
1896 if ((operand->flags & V850_OPERAND_REG) != 0)
1898 if (!register_name (&ex))
1900 errmsg = _("invalid register name");
1902 else if ((operand->flags & V850_NOT_R0)
1903 && ex.X_add_number == 0)
1905 errmsg = _("register r0 cannot be used here");
1907 /* Force an error message to be generated by
1908 skipping over any following potential matches
1913 else if ((operand->flags & V850_OPERAND_SRG) != 0)
1915 if (!system_register_name (&ex, true, false))
1917 errmsg = _("invalid system register name");
1920 else if ((operand->flags & V850_OPERAND_EP) != 0)
1922 char *start = input_line_pointer;
1923 char c = get_symbol_end ();
1925 if (strcmp (start, "ep") != 0 && strcmp (start, "r30") != 0)
1927 /* Put things back the way we found them. */
1928 *input_line_pointer = c;
1929 input_line_pointer = start;
1930 errmsg = _("expected EP register");
1934 *input_line_pointer = c;
1935 str = input_line_pointer;
1936 input_line_pointer = hold;
1938 while (*str == ' ' || *str == ','
1939 || *str == '[' || *str == ']')
1943 else if ((operand->flags & V850_OPERAND_CC) != 0)
1947 errmsg = _("invalid condition code name");
1950 else if (operand->flags & V850E_PUSH_POP)
1952 errmsg = parse_register_list (&insn, operand);
1954 /* The parse_register_list() function has already done
1955 everything, so fake a dummy expression. */
1956 ex.X_op = O_constant;
1957 ex.X_add_number = 0;
1959 else if (operand->flags & V850E_IMMEDIATE16)
1963 if (ex.X_op != O_constant)
1964 errmsg = _("constant expression expected");
1965 else if (ex.X_add_number & 0xffff0000)
1967 if (ex.X_add_number & 0xffff)
1968 errmsg = _("constant too big to fit into instruction");
1969 else if ((insn & 0x001fffc0) == 0x00130780)
1970 ex.X_add_number >>= 16;
1972 errmsg = _("constant too big to fit into instruction");
1975 extra_data_after_insn = true;
1977 extra_data = ex.X_add_number;
1978 ex.X_add_number = 0;
1980 else if (operand->flags & V850E_IMMEDIATE32)
1984 if (ex.X_op != O_constant)
1985 errmsg = _("constant expression expected");
1987 extra_data_after_insn = true;
1989 extra_data = ex.X_add_number;
1990 ex.X_add_number = 0;
1992 else if (register_name (&ex)
1993 && (operand->flags & V850_OPERAND_REG) == 0)
1998 /* It is possible that an alias has been defined that
1999 matches a register name. For example the code may
2000 include a ".set ZERO, 0" directive, which matches
2001 the register name "zero". Attempt to reparse the
2002 field as an expression, and only complain if we
2003 cannot generate a constant. */
2005 input_line_pointer = str;
2007 c = get_symbol_end ();
2009 if (symbol_find (str) != NULL)
2012 *input_line_pointer = c;
2013 input_line_pointer = str;
2017 if (ex.X_op != O_constant)
2019 /* If this register is actually occuring too early on
2020 the parsing of the instruction, (because another
2021 field is missing) then report this. */
2022 if (opindex_ptr[1] != 0
2023 && (v850_operands[opindex_ptr[1]].flags
2024 & V850_OPERAND_REG))
2025 errmsg = _("syntax error: value is missing before the register name");
2027 errmsg = _("syntax error: register not expected");
2029 /* If we created a symbol in the process of this
2030 test then delete it now, so that it will not
2031 be output with the real symbols... */
2033 && ex.X_op == O_symbol)
2034 symbol_remove (ex.X_add_symbol,
2035 &symbol_rootP, &symbol_lastP);
2038 else if (system_register_name (&ex, false, false)
2039 && (operand->flags & V850_OPERAND_SRG) == 0)
2041 errmsg = _("syntax error: system register not expected");
2043 else if (cc_name (&ex)
2044 && (operand->flags & V850_OPERAND_CC) == 0)
2046 errmsg = _("syntax error: condition code not expected");
2052 If we are assembling a MOV instruction (or a CALLT.... :-)
2053 and the immediate value does not fit into the bits
2054 available then create a fake error so that the next MOV
2055 instruction will be selected. This one has a 32 bit
2058 if (((insn & 0x07e0) == 0x0200)
2059 && ex.X_op == O_constant
2060 && (ex.X_add_number < (-(1 << (operand->bits - 1)))
2061 || ex.X_add_number > ((1 << operand->bits) - 1)))
2062 errmsg = _("immediate operand is too large");
2070 " insn: %x, operand %d, op: %d, add_number: %d\n",
2071 insn, opindex_ptr - opcode->operands,
2072 ex.X_op, ex.X_add_number);
2078 errmsg = _("illegal operand");
2081 errmsg = _("missing operand");
2085 & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0)
2087 errmsg = _("invalid operand");
2090 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2092 copy_of_instruction);
2096 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2098 copy_of_instruction);
2102 /* We need to generate a fixup for this expression. */
2103 if (fc >= MAX_INSN_FIXUPS)
2104 as_fatal (_("too many fixups"));
2106 fixups[fc].exp = ex;
2107 fixups[fc].opindex = *opindex_ptr;
2108 fixups[fc].reloc = BFD_RELOC_UNUSED;
2114 str = input_line_pointer;
2115 input_line_pointer = hold;
2117 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']'
2126 next_opcode = opcode + 1;
2127 if (next_opcode->name != NULL
2128 && strcmp (next_opcode->name, opcode->name) == 0)
2130 opcode = next_opcode;
2132 /* Skip versions that are not supported by the target
2134 if ((opcode->processors & processor_mask) == 0)
2140 as_bad ("%s: %s", copy_of_instruction, errmsg);
2142 if (*input_line_pointer == ']')
2143 ++input_line_pointer;
2145 ignore_rest_of_line ();
2146 input_line_pointer = saved_input_line_pointer;
2152 while (isspace (*str))
2156 /* xgettext:c-format */
2157 as_bad (_("junk at end of line: `%s'"), str);
2159 input_line_pointer = str;
2161 /* Write out the instruction. */
2163 if (relaxable && fc > 0)
2168 if (!strcmp (opcode->name, "br"))
2170 f = frag_var (rs_machine_dependent, 4, 2, 2,
2171 fixups[0].exp.X_add_symbol,
2172 fixups[0].exp.X_add_number,
2173 (char *) fixups[0].opindex);
2174 md_number_to_chars (f, insn, insn_size);
2175 md_number_to_chars (f + 2, 0, 2);
2179 f = frag_var (rs_machine_dependent, 6, 4, 0,
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, 4);
2189 /* Four byte insns have an opcode with the two high bits on. */
2190 if ((insn & 0x0600) == 0x0600)
2195 /* Special case: 32 bit MOV. */
2196 if ((insn & 0xffe0) == 0x0620)
2199 f = frag_more (insn_size);
2201 md_number_to_chars (f, insn, insn_size);
2203 if (extra_data_after_insn)
2205 f = frag_more (extra_data_len);
2207 md_number_to_chars (f, extra_data, extra_data_len);
2209 extra_data_after_insn = false;
2213 /* Create any fixups. At this point we do not use a
2214 bfd_reloc_code_real_type, but instead just use the
2215 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2216 handle fixups for any operand type, although that is admittedly
2217 not a very exciting feature. We pick a BFD reloc type in
2219 for (i = 0; i < fc; i++)
2221 const struct v850_operand *operand;
2222 bfd_reloc_code_real_type reloc;
2224 operand = &v850_operands[fixups[i].opindex];
2226 reloc = fixups[i].reloc;
2228 if (reloc != BFD_RELOC_UNUSED)
2230 reloc_howto_type *reloc_howto =
2231 bfd_reloc_type_lookup (stdoutput, reloc);
2239 size = bfd_get_reloc_size (reloc_howto);
2241 /* XXX This will abort on an R_V850_8 reloc -
2242 is this reloc actually used? */
2243 if (size != 2 && size != 4)
2246 address = (f - frag_now->fr_literal) + insn_size - size;
2248 if (reloc == BFD_RELOC_32)
2251 fixP = fix_new_exp (frag_now, address, size,
2253 reloc_howto->pc_relative,
2258 case BFD_RELOC_LO16:
2259 case BFD_RELOC_HI16:
2260 case BFD_RELOC_HI16_S:
2261 fixP->fx_no_overflow = 1;
2269 fix_new_exp (frag_now,
2270 f - frag_now->fr_literal, 4,
2272 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2273 (bfd_reloc_code_real_type) (fixups[i].opindex
2274 + (int) BFD_RELOC_UNUSED));
2278 input_line_pointer = saved_input_line_pointer;
2281 /* If while processing a fixup, a reloc really needs to be created
2282 then it is done here. */
2285 tc_gen_reloc (seg, fixp)
2286 asection *seg ATTRIBUTE_UNUSED;
2291 reloc = (arelent *) xmalloc (sizeof (arelent));
2292 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2293 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2294 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2295 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2297 if (reloc->howto == (reloc_howto_type *) NULL)
2299 as_bad_where (fixp->fx_file, fixp->fx_line,
2300 /* xgettext:c-format */
2301 _("reloc %d not supported by object file format"),
2302 (int) fixp->fx_r_type);
2309 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
2310 || fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT)
2311 reloc->addend = fixp->fx_offset;
2313 reloc->addend = fixp->fx_addnumber;
2318 /* Assume everything will fit in two bytes, then expand as necessary. */
2321 md_estimate_size_before_relax (fragp, seg)
2323 asection *seg ATTRIBUTE_UNUSED;
2325 if (fragp->fr_subtype == 0)
2327 else if (fragp->fr_subtype == 2)
2335 v850_pcrel_from_section (fixp, section)
2339 /* If the symbol is undefined, or in a section other than our own,
2340 or it is weak (in which case it may well be in another section,
2341 then let the linker figure it out. */
2342 if (fixp->fx_addsy != (symbolS *) NULL
2343 && (! S_IS_DEFINED (fixp->fx_addsy)
2344 || S_IS_WEAK (fixp->fx_addsy)
2345 || (S_GET_SEGMENT (fixp->fx_addsy) != section)))
2348 return fixp->fx_frag->fr_address + fixp->fx_where;
2352 md_apply_fix3 (fixp, valuep, seg)
2355 segT seg ATTRIBUTE_UNUSED;
2360 if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2361 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2367 if (fixp->fx_addsy == (symbolS *) NULL)
2372 else if (fixp->fx_pcrel)
2376 value = fixp->fx_offset;
2377 if (fixp->fx_subsy != (symbolS *) NULL)
2379 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
2380 value -= S_GET_VALUE (fixp->fx_subsy);
2383 /* We don't actually support subtracting a symbol. */
2384 as_bad_where (fixp->fx_file, fixp->fx_line,
2385 _("expression too complex"));
2390 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
2393 const struct v850_operand *operand;
2396 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
2397 operand = &v850_operands[opindex];
2399 /* Fetch the instruction, insert the fully resolved operand
2400 value, and stuff the instruction back again.
2402 Note the instruction has been stored in little endian
2404 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2406 insn = bfd_getl32 ((unsigned char *) where);
2407 insn = v850_insert_operand (insn, operand, (offsetT) value,
2408 fixp->fx_file, fixp->fx_line, NULL);
2409 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
2413 /* Nothing else to do here. */
2417 /* Determine a BFD reloc value based on the operand information.
2418 We are only prepared to turn a few of the operands into relocs. */
2420 if (operand->bits == 22)
2421 fixp->fx_r_type = BFD_RELOC_V850_22_PCREL;
2422 else if (operand->bits == 9)
2423 fixp->fx_r_type = BFD_RELOC_V850_9_PCREL;
2427 fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn);
2430 as_bad_where (fixp->fx_file, fixp->fx_line,
2431 _("unresolved expression that must be resolved"));
2436 else if (fixp->fx_done)
2438 /* We still have to insert the value into memory! */
2439 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2441 if (fixp->fx_size == 1)
2442 *where = value & 0xff;
2443 else if (fixp->fx_size == 2)
2444 bfd_putl16 (value & 0xffff, (unsigned char *) where);
2445 else if (fixp->fx_size == 4)
2446 bfd_putl32 (value, (unsigned char *) where);
2449 fixp->fx_addnumber = value;
2453 /* Parse a cons expression. We have to handle hi(), lo(), etc
2457 parse_cons_expression_v850 (exp)
2460 /* See if there's a reloc prefix like hi() we have to handle. */
2461 hold_cons_reloc = v850_reloc_prefix (NULL);
2463 /* Do normal expression parsing. */
2467 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2468 found a reloc prefix, then we use that reloc, else we choose an
2469 appropriate one based on the size of the expression. */
2472 cons_fix_new_v850 (frag, where, size, exp)
2478 if (hold_cons_reloc == BFD_RELOC_UNUSED)
2481 hold_cons_reloc = BFD_RELOC_32;
2483 hold_cons_reloc = BFD_RELOC_16;
2485 hold_cons_reloc = BFD_RELOC_8;
2489 fix_new_exp (frag, where, size, exp, 0, hold_cons_reloc);
2491 fix_new (frag, where, size, NULL, 0, 0, hold_cons_reloc);
2495 v850_fix_adjustable (fixP)
2498 if (fixP->fx_addsy == NULL)
2501 /* Prevent all adjustments to global symbols. */
2502 if (S_IS_EXTERN (fixP->fx_addsy))
2505 /* Similarly for weak symbols. */
2506 if (S_IS_WEAK (fixP->fx_addsy))
2509 /* Don't adjust function names. */
2510 if (S_IS_FUNCTION (fixP->fx_addsy))
2513 /* We need the symbol name for the VTABLE entries. */
2514 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2515 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2522 v850_force_relocation (fixP)
2525 if (fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy))
2528 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2529 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)