1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "safe-ctype.h"
26 #include "opcode/v850.h"
27 #include "dwarf2dbg.h"
33 /* Sign-extend a 16-bit number. */
34 #define SEXT16(x) ((((x) & 0xffff) ^ (~0x7fff)) + 0x8000)
36 /* Temporarily holds the reloc in a cons expression. */
37 static bfd_reloc_code_real_type hold_cons_reloc = BFD_RELOC_UNUSED;
39 /* Set to TRUE if we want to be pedantic about signed overflows. */
40 static boolean warn_signed_overflows = FALSE;
41 static boolean warn_unsigned_overflows = FALSE;
43 /* Indicates the target BFD machine number. */
44 static int machine = -1;
46 /* Indicates the target processor(s) for the assemble. */
47 static int processor_mask = -1;
49 /* Structure to hold information about predefined registers. */
55 /* Generic assembler global variables which must be defined by all
58 /* Characters which always start a comment. */
59 const char comment_chars[] = "#";
61 /* Characters which start a comment at the beginning of a line. */
62 const char line_comment_chars[] = ";#";
64 /* Characters which may be used to separate multiple commands on a
66 const char line_separator_chars[] = ";";
68 /* Characters which are used to indicate an exponent in a floating
70 const char EXP_CHARS[] = "eE";
72 /* Characters which mean that a number is a floating point constant,
74 const char FLT_CHARS[] = "dD";
76 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)
104 bfd_reloc_code_real_type reloc;
107 struct v850_fixup fixups[MAX_INSN_FIXUPS];
111 v850_sdata (int ignore ATTRIBUTE_UNUSED)
113 obj_elf_section_change_hook ();
115 subseg_set (sdata_section, (subsegT) get_absolute_expression ());
117 demand_empty_rest_of_line ();
121 v850_tdata (int ignore ATTRIBUTE_UNUSED)
123 obj_elf_section_change_hook ();
125 subseg_set (tdata_section, (subsegT) get_absolute_expression ());
127 demand_empty_rest_of_line ();
131 v850_zdata (int ignore ATTRIBUTE_UNUSED)
133 obj_elf_section_change_hook ();
135 subseg_set (zdata_section, (subsegT) get_absolute_expression ());
137 demand_empty_rest_of_line ();
141 v850_sbss (int ignore ATTRIBUTE_UNUSED)
143 obj_elf_section_change_hook ();
145 subseg_set (sbss_section, (subsegT) get_absolute_expression ());
147 demand_empty_rest_of_line ();
151 v850_tbss (int ignore ATTRIBUTE_UNUSED)
153 obj_elf_section_change_hook ();
155 subseg_set (tbss_section, (subsegT) get_absolute_expression ());
157 demand_empty_rest_of_line ();
161 v850_zbss (int ignore ATTRIBUTE_UNUSED)
163 obj_elf_section_change_hook ();
165 subseg_set (zbss_section, (subsegT) get_absolute_expression ());
167 demand_empty_rest_of_line ();
171 v850_rosdata (int ignore ATTRIBUTE_UNUSED)
173 obj_elf_section_change_hook ();
175 subseg_set (rosdata_section, (subsegT) get_absolute_expression ());
177 demand_empty_rest_of_line ();
181 v850_rozdata (int ignore ATTRIBUTE_UNUSED)
183 obj_elf_section_change_hook ();
185 subseg_set (rozdata_section, (subsegT) get_absolute_expression ());
187 demand_empty_rest_of_line ();
191 v850_call_table_data (int ignore ATTRIBUTE_UNUSED)
193 obj_elf_section_change_hook ();
195 subseg_set (call_table_data_section, (subsegT) get_absolute_expression ());
197 demand_empty_rest_of_line ();
201 v850_call_table_text (int ignore ATTRIBUTE_UNUSED)
203 obj_elf_section_change_hook ();
205 subseg_set (call_table_text_section, (subsegT) get_absolute_expression ());
207 demand_empty_rest_of_line ();
211 v850_bss (int ignore ATTRIBUTE_UNUSED)
213 register int temp = get_absolute_expression ();
215 obj_elf_section_change_hook ();
217 subseg_set (bss_section, (subsegT) temp);
219 demand_empty_rest_of_line ();
223 v850_offset (int ignore ATTRIBUTE_UNUSED)
225 int temp = get_absolute_expression ();
227 temp -= frag_now_fix ();
230 (void) frag_more (temp);
232 demand_empty_rest_of_line ();
235 /* Copied from obj_elf_common() in gas/config/obj-elf.c. */
249 name = input_line_pointer;
250 c = get_symbol_end ();
252 /* Just after name is now '\0'. */
253 p = input_line_pointer;
258 if (*input_line_pointer != ',')
260 as_bad (_("Expected comma after symbol-name"));
261 ignore_rest_of_line ();
266 input_line_pointer++;
268 if ((temp = get_absolute_expression ()) < 0)
270 /* xgettext:c-format */
271 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp);
272 ignore_rest_of_line ();
278 symbolP = symbol_find_or_make (name);
281 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
283 as_bad (_("Ignoring attempt to re-define symbol"));
284 ignore_rest_of_line ();
288 if (S_GET_VALUE (symbolP) != 0)
290 if (S_GET_VALUE (symbolP) != size)
292 /* xgettext:c-format */
293 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
294 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
298 know (symbol_get_frag (symbolP) == &zero_address_frag);
300 if (*input_line_pointer != ',')
305 input_line_pointer++;
309 if (! have_align || *input_line_pointer != '"')
315 temp = get_absolute_expression ();
320 as_warn (_("Common alignment negative; 0 assumed"));
324 if (symbol_get_obj (symbolP)->local)
333 old_subsec = now_subseg;
335 applicable = bfd_applicable_section_flags (stdoutput);
337 applicable &= SEC_ALLOC;
342 if (sbss_section == NULL)
344 sbss_section = subseg_new (".sbss", 0);
346 bfd_set_section_flags (stdoutput, sbss_section, applicable);
348 seg_info (sbss_section)->bss = 1;
353 if (zbss_section == NULL)
355 zbss_section = subseg_new (".zbss", 0);
357 bfd_set_section_flags (stdoutput, sbss_section, applicable);
359 seg_info (zbss_section)->bss = 1;
364 if (tbss_section == NULL)
366 tbss_section = subseg_new (".tbss", 0);
368 bfd_set_section_flags (stdoutput, tbss_section, applicable);
370 seg_info (tbss_section)->bss = 1;
377 /* Convert to a power of 2 alignment. */
378 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align)
383 as_bad (_("Common alignment not a power of 2"));
384 ignore_rest_of_line ();
394 record_alignment (sbss_section, align);
395 obj_elf_section_change_hook ();
396 subseg_set (sbss_section, 0);
400 record_alignment (zbss_section, align);
401 obj_elf_section_change_hook ();
402 subseg_set (zbss_section, 0);
406 record_alignment (tbss_section, align);
407 obj_elf_section_change_hook ();
408 subseg_set (tbss_section, 0);
416 frag_align (align, 0, 0);
421 if (S_GET_SEGMENT (symbolP) == sbss_section)
422 symbol_get_frag (symbolP)->fr_symbol = 0;
426 if (S_GET_SEGMENT (symbolP) == zbss_section)
427 symbol_get_frag (symbolP)->fr_symbol = 0;
431 if (S_GET_SEGMENT (symbolP) == tbss_section)
432 symbol_get_frag (symbolP)->fr_symbol = 0;
439 symbol_set_frag (symbolP, frag_now);
440 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
441 (offsetT) size, (char *) 0);
443 S_SET_SIZE (symbolP, size);
448 S_SET_SEGMENT (symbolP, sbss_section);
452 S_SET_SEGMENT (symbolP, zbss_section);
456 S_SET_SEGMENT (symbolP, tbss_section);
463 S_CLEAR_EXTERNAL (symbolP);
464 obj_elf_section_change_hook ();
465 subseg_set (old_sec, old_subsec);
470 S_SET_VALUE (symbolP, (valueT) size);
471 S_SET_ALIGN (symbolP, temp);
472 S_SET_EXTERNAL (symbolP);
477 if (scommon_section == NULL)
479 flagword applicable =
480 bfd_applicable_section_flags (stdoutput);
482 scommon_section = subseg_new (".scommon", 0);
484 bfd_set_section_flags (stdoutput, scommon_section,
486 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
487 | SEC_HAS_CONTENTS)) | SEC_IS_COMMON);
489 S_SET_SEGMENT (symbolP, scommon_section);
493 if (zcommon_section == NULL)
495 flagword applicable =
496 bfd_applicable_section_flags (stdoutput);
498 zcommon_section = subseg_new (".zcommon", 0);
500 bfd_set_section_flags (stdoutput, zcommon_section,
502 & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
503 | SEC_HAS_CONTENTS)) | SEC_IS_COMMON);
505 S_SET_SEGMENT (symbolP, zcommon_section);
509 if (tcommon_section == NULL)
511 flagword applicable =
512 bfd_applicable_section_flags (stdoutput);
514 tcommon_section = subseg_new (".tcommon", 0);
516 bfd_set_section_flags (stdoutput, tcommon_section,
518 & (SEC_ALLOC | SEC_LOAD
519 | SEC_RELOC | SEC_DATA
523 S_SET_SEGMENT (symbolP, tcommon_section);
533 input_line_pointer++;
535 /* @@ Some use the dot, some don't. Can we get some consistency?? */
536 if (*input_line_pointer == '.')
537 input_line_pointer++;
539 /* @@ Some say data, some say bss. */
540 if (strncmp (input_line_pointer, "bss\"", 4)
541 && strncmp (input_line_pointer, "data\"", 5))
543 while (*--input_line_pointer != '"')
545 input_line_pointer--;
546 goto bad_common_segment;
548 while (*input_line_pointer++ != '"')
550 goto allocate_common;
553 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
555 demand_empty_rest_of_line ();
560 p = input_line_pointer;
561 while (*p && *p != '\n')
565 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
567 input_line_pointer = p;
568 ignore_rest_of_line ();
574 set_machine (int number)
577 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
581 case 0: processor_mask = PROCESSOR_V850; break;
582 case bfd_mach_v850e: processor_mask = PROCESSOR_V850E; break;
583 case bfd_mach_v850ea: processor_mask = PROCESSOR_V850EA; break;
587 /* The target specific pseudo-ops which we support. */
588 const pseudo_typeS md_pseudo_table[] = {
589 {"sdata", v850_sdata, 0},
590 {"tdata", v850_tdata, 0},
591 {"zdata", v850_zdata, 0},
592 {"sbss", v850_sbss, 0},
593 {"tbss", v850_tbss, 0},
594 {"zbss", v850_zbss, 0},
595 {"rosdata", v850_rosdata, 0},
596 {"rozdata", v850_rozdata, 0},
597 {"bss", v850_bss, 0},
598 {"offset", v850_offset, 0},
600 {"zcomm", v850_comm, AREA_ZDA},
601 {"scomm", v850_comm, AREA_SDA},
602 {"tcomm", v850_comm, AREA_TDA},
603 {"v850", set_machine, 0},
604 {"call_table_data", v850_call_table_data, 0},
605 {"call_table_text", v850_call_table_text, 0},
606 {"v850e", set_machine, bfd_mach_v850e},
607 {"v850ea", set_machine, bfd_mach_v850ea},
608 {"file", dwarf2_directive_file, 0},
609 {"loc", dwarf2_directive_loc, 0},
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[] = {
618 { "ep", 30 }, /* ep - element ptr */
619 { "gp", 4 }, /* gp - global ptr */
620 { "hp", 2 }, /* hp - handler stack ptr */
621 { "lp", 31 }, /* lp - link ptr */
654 { "sp", 3 }, /* sp - stack ptr */
655 { "tp", 5 }, /* tp - text ptr */
659 #define REG_NAME_CNT \
660 (sizeof (pre_defined_registers) / sizeof (struct reg_name))
662 static const struct reg_name system_registers[] = {
676 #define SYSREG_NAME_CNT \
677 (sizeof (system_registers) / sizeof (struct reg_name))
679 static const struct reg_name system_list_registers[] = {
684 #define SYSREGLIST_NAME_CNT \
685 (sizeof (system_list_registers) / sizeof (struct reg_name))
687 static const struct reg_name cc_names[] = {
712 #define CC_NAME_CNT \
713 (sizeof (cc_names) / sizeof (struct reg_name))
715 /* Do a binary search of the given register table to see if NAME is a
716 valid regiter name. Return the register number from the array on
717 success, or -1 on failure. */
720 reg_name_search (regs, regcount, name, accept_numbers)
721 const struct reg_name *regs;
724 boolean accept_numbers;
726 int middle, low, high;
730 /* If the register name is a symbol, then evaluate it. */
731 if ((symbolP = symbol_find (name)) != NULL)
733 /* If the symbol is an alias for another name then use that.
734 If the symbol is an alias for a number, then return the number. */
735 if (symbol_equated_p (symbolP))
738 = S_GET_NAME (symbol_get_value_expression (symbolP)->X_add_symbol);
740 else if (accept_numbers)
742 int reg = S_GET_VALUE (symbolP);
744 if (reg >= 0 && reg <= 31)
748 /* Otherwise drop through and try parsing name normally. */
756 middle = (low + high) / 2;
757 cmp = strcasecmp (name, regs[middle].name);
763 return regs[middle].value;
769 /* Summary of register_name().
771 * in: Input_line_pointer points to 1st char of operand.
773 * out: An expressionS.
774 * The operand may have been a register: in this case, X_op == O_register,
775 * X_add_number is set to the register number, and truth is returned.
776 * Input_line_pointer->(next non-blank) char after operand, or is in
777 * its original state. */
780 register_name (expressionP)
781 expressionS *expressionP;
788 /* Find the spelling of the operand. */
789 start = name = input_line_pointer;
791 c = get_symbol_end ();
793 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT,
796 /* Put back the delimiting char. */
797 *input_line_pointer = c;
799 /* Look to see if it's in the register table. */
802 expressionP->X_op = O_register;
803 expressionP->X_add_number = reg_number;
805 /* Make the rest nice. */
806 expressionP->X_add_symbol = NULL;
807 expressionP->X_op_symbol = NULL;
813 /* Reset the line as if we had not done anything. */
814 input_line_pointer = start;
820 /* Summary of system_register_name().
822 * in: INPUT_LINE_POINTER points to 1st char of operand.
823 * EXPRESSIONP points to an expression structure to be filled in.
824 * ACCEPT_NUMBERS is true iff numerical register names may be used.
825 * ACCEPT_LIST_NAMES is true iff the special names PS and SR may be
828 * out: An expressionS structure in expressionP.
829 * The operand may have been a register: in this case, X_op == O_register,
830 * X_add_number is set to the register number, and truth is returned.
831 * Input_line_pointer->(next non-blank) char after operand, or is in
832 * its original state. */
835 system_register_name (expressionP, accept_numbers, accept_list_names)
836 expressionS *expressionP;
837 boolean accept_numbers;
838 boolean accept_list_names;
845 /* Find the spelling of the operand. */
846 start = name = input_line_pointer;
848 c = get_symbol_end ();
849 reg_number = reg_name_search (system_registers, SYSREG_NAME_CNT, name,
852 /* Put back the delimiting char. */
853 *input_line_pointer = c;
858 /* Reset input_line pointer. */
859 input_line_pointer = start;
861 if (ISDIGIT (*input_line_pointer))
863 reg_number = strtol (input_line_pointer, &input_line_pointer, 10);
865 /* Make sure that the register number is allowable. */
867 || (reg_number > 5 && reg_number < 16)
873 else if (accept_list_names)
875 c = get_symbol_end ();
876 reg_number = reg_name_search (system_list_registers,
877 SYSREGLIST_NAME_CNT, name, FALSE);
879 /* Put back the delimiting char. */
880 *input_line_pointer = c;
884 /* Look to see if it's in the register table. */
887 expressionP->X_op = O_register;
888 expressionP->X_add_number = reg_number;
890 /* Make the rest nice. */
891 expressionP->X_add_symbol = NULL;
892 expressionP->X_op_symbol = NULL;
898 /* Reset the line as if we had not done anything. */
899 input_line_pointer = start;
905 /* Summary of cc_name().
907 * in: INPUT_LINE_POINTER points to 1st char of operand.
909 * out: An expressionS.
910 * The operand may have been a register: in this case, X_op == O_register,
911 * X_add_number is set to the register number, and truth is returned.
912 * Input_line_pointer->(next non-blank) char after operand, or is in
913 * its original state. */
916 cc_name (expressionP)
917 expressionS *expressionP;
924 /* Find the spelling of the operand. */
925 start = name = input_line_pointer;
927 c = get_symbol_end ();
928 reg_number = reg_name_search (cc_names, CC_NAME_CNT, name, FALSE);
930 /* Put back the delimiting char. */
931 *input_line_pointer = c;
933 /* Look to see if it's in the register table. */
936 expressionP->X_op = O_constant;
937 expressionP->X_add_number = reg_number;
939 /* Make the rest nice. */
940 expressionP->X_add_symbol = NULL;
941 expressionP->X_op_symbol = NULL;
947 /* Reset the line as if we had not done anything. */
948 input_line_pointer = start;
955 skip_white_space (void)
957 while (*input_line_pointer == ' '
958 || *input_line_pointer == '\t')
959 ++input_line_pointer;
962 /* Summary of parse_register_list ().
964 * in: INPUT_LINE_POINTER points to 1st char of a list of registers.
965 * INSN is the partially constructed instruction.
966 * OPERAND is the operand being inserted.
968 * out: NULL if the parse completed successfully, otherwise a
969 * pointer to an error message is returned. If the parse
970 * completes the correct bit fields in the instruction
973 * Parses register lists with the syntax:
981 * and also parses constant epxressions whoes bits indicate the
982 * registers in the lists. The LSB in the expression refers to
983 * the lowest numbered permissable register in the register list,
984 * and so on upwards. System registers are considered to be very
988 parse_register_list (insn, operand)
990 const struct v850_operand *operand;
992 static int type1_regs[32] = {
993 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
994 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
996 static int type2_regs[32] = {
997 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
998 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
1000 static int type3_regs[32] = {
1001 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1002 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8
1007 /* Select a register array to parse. */
1008 switch (operand->shift)
1010 case 0xffe00001: regs = type1_regs; break;
1011 case 0xfff8000f: regs = type2_regs; break;
1012 case 0xfff8001f: regs = type3_regs; break;
1014 as_bad (_("unknown operand shift: %x\n"), operand->shift);
1015 return _("internal failure in parse_register_list");
1018 skip_white_space ();
1020 /* If the expression starts with a curly brace it is a register list.
1021 Otherwise it is a constant expression, whoes bits indicate which
1022 registers are to be included in the list. */
1024 if (*input_line_pointer != '{')
1031 if (exp.X_op != O_constant)
1032 return _("constant expression or register list expected");
1034 if (regs == type1_regs)
1036 if (exp.X_add_number & 0xFFFFF000)
1037 return _("high bits set in register list expression");
1039 for (reg = 20; reg < 32; reg++)
1040 if (exp.X_add_number & (1 << (reg - 20)))
1042 for (i = 0; i < 32; i++)
1047 else if (regs == type2_regs)
1049 if (exp.X_add_number & 0xFFFE0000)
1050 return _("high bits set in register list expression");
1052 for (reg = 1; reg < 16; reg++)
1053 if (exp.X_add_number & (1 << (reg - 1)))
1055 for (i = 0; i < 32; i++)
1060 if (exp.X_add_number & (1 << 15))
1063 if (exp.X_add_number & (1 << 16))
1066 else /* regs == type3_regs */
1068 if (exp.X_add_number & 0xFFFE0000)
1069 return _("high bits set in register list expression");
1071 for (reg = 16; reg < 32; reg++)
1072 if (exp.X_add_number & (1 << (reg - 16)))
1074 for (i = 0; i < 32; i++)
1079 if (exp.X_add_number & (1 << 16))
1086 input_line_pointer++;
1088 /* Parse the register list until a terminator (closing curly brace or
1089 new-line) is found. */
1092 if (register_name (&exp))
1096 /* Locate the given register in the list, and if it is there,
1097 insert the corresponding bit into the instruction. */
1098 for (i = 0; i < 32; i++)
1100 if (regs[i] == exp.X_add_number)
1109 return _("illegal register included in list");
1112 else if (system_register_name (&exp, true, true))
1114 if (regs == type1_regs)
1116 return _("system registers cannot be included in list");
1118 else if (exp.X_add_number == 5)
1120 if (regs == type2_regs)
1121 return _("PSW cannot be included in list");
1125 else if (exp.X_add_number < 4)
1128 return _("High value system registers cannot be included in list");
1130 else if (*input_line_pointer == '}')
1132 input_line_pointer++;
1135 else if (*input_line_pointer == ',')
1137 input_line_pointer++;
1140 else if (*input_line_pointer == '-')
1142 /* We have encountered a range of registers: rX - rY. */
1146 /* Skip the dash. */
1147 ++input_line_pointer;
1149 /* Get the second register in the range. */
1150 if (! register_name (&exp2))
1152 return _("second register should follow dash in register list");
1153 exp2.X_add_number = exp.X_add_number;
1156 /* Add the rest of the registers in the range. */
1157 for (j = exp.X_add_number + 1; j <= exp2.X_add_number; j++)
1161 /* Locate the given register in the list, and if it is there,
1162 insert the corresponding bit into the instruction. */
1163 for (i = 0; i < 32; i++)
1173 return _("illegal register included in list");
1181 skip_white_space ();
1187 CONST char *md_shortopts = "m:";
1189 struct option md_longopts[] = {
1190 {NULL, no_argument, NULL, 0}
1193 size_t md_longopts_size = sizeof (md_longopts);
1196 md_show_usage (stream)
1199 fprintf (stream, _(" V850 options:\n"));
1200 fprintf (stream, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1201 fprintf (stream, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1202 fprintf (stream, _(" -mv850 The code is targeted at the v850\n"));
1203 fprintf (stream, _(" -mv850e The code is targeted at the v850e\n"));
1204 fprintf (stream, _(" -mv850ea The code is targeted at the v850ea\n"));
1205 fprintf (stream, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1209 md_parse_option (c, arg)
1216 /* xgettext:c-format */
1217 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1221 if (strcmp (arg, "warn-signed-overflow") == 0)
1223 warn_signed_overflows = TRUE;
1225 else if (strcmp (arg, "warn-unsigned-overflow") == 0)
1227 warn_unsigned_overflows = TRUE;
1229 else if (strcmp (arg, "v850") == 0)
1232 processor_mask = PROCESSOR_V850;
1234 else if (strcmp (arg, "v850e") == 0)
1236 machine = bfd_mach_v850e;
1237 processor_mask = PROCESSOR_V850E;
1239 else if (strcmp (arg, "v850ea") == 0)
1241 machine = bfd_mach_v850ea;
1242 processor_mask = PROCESSOR_V850EA;
1244 else if (strcmp (arg, "v850any") == 0)
1246 /* Tell the world that this is for any v850 chip. */
1249 /* But support instructions for the extended versions. */
1250 processor_mask = PROCESSOR_V850EA;
1254 /* xgettext:c-format */
1255 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1263 md_undefined_symbol (name)
1264 char *name ATTRIBUTE_UNUSED;
1270 md_atof (type, litp, sizep)
1276 LITTLENUM_TYPE words[4];
1292 return _("bad call to md_atof");
1295 t = atof_ieee (input_line_pointer, type, words);
1297 input_line_pointer = t;
1301 for (i = prec - 1; i >= 0; i--)
1303 md_number_to_chars (litp, (valueT) words[i], 2);
1313 md_convert_frag (abfd, sec, fragP)
1314 bfd *abfd ATTRIBUTE_UNUSED;
1318 subseg_change (sec, 0);
1320 /* In range conditional or unconditional branch. */
1321 if (fragP->fr_subtype == 0 || fragP->fr_subtype == 2)
1323 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
1324 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode);
1327 /* Out of range conditional branch. Emit a branch around a jump. */
1328 else if (fragP->fr_subtype == 1)
1330 unsigned char *buffer =
1331 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1333 /* Reverse the condition of the first branch. */
1335 /* Mask off all the displacement bits. */
1338 /* Now set the displacement bits so that we branch
1339 around the unconditional branch. */
1342 /* Now create the unconditional branch + fixup to the final
1344 md_number_to_chars (buffer + 2, 0x00000780, 4);
1345 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
1346 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1347 (int) fragP->fr_opcode + 1);
1350 /* Out of range unconditional branch. Emit a jump. */
1351 else if (fragP->fr_subtype == 3)
1353 md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x00000780, 4);
1354 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
1355 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1356 (int) fragP->fr_opcode + 1);
1364 md_section_align (seg, addr)
1368 int align = bfd_get_section_alignment (stdoutput, seg);
1369 return ((addr + (1 << align) - 1) & (-1 << align));
1375 char *prev_name = "";
1376 register const struct v850_opcode *op;
1377 flagword applicable;
1379 if (strncmp (TARGET_CPU, "v850ea", 6) == 0)
1382 machine = bfd_mach_v850ea;
1384 if (processor_mask == -1)
1385 processor_mask = PROCESSOR_V850EA;
1387 else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
1390 machine = bfd_mach_v850e;
1392 if (processor_mask == -1)
1393 processor_mask = PROCESSOR_V850E;
1395 else if (strncmp (TARGET_CPU, "v850", 4) == 0)
1400 if (processor_mask == -1)
1401 processor_mask = PROCESSOR_V850;
1404 /* xgettext:c-format */
1405 as_bad (_("Unable to determine default target processor from string: %s"),
1408 v850_hash = hash_new ();
1410 /* Insert unique names into hash table. The V850 instruction set
1411 has many identical opcode names that have different opcodes based
1412 on the operands. This hash table then provides a quick index to
1413 the first opcode with a particular name in the opcode table. */
1418 if (strcmp (prev_name, op->name))
1420 prev_name = (char *) op->name;
1421 hash_insert (v850_hash, op->name, (char *) op);
1426 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
1428 applicable = bfd_applicable_section_flags (stdoutput);
1430 call_table_data_section = subseg_new (".call_table_data", 0);
1431 bfd_set_section_flags (stdoutput, call_table_data_section,
1432 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1433 | SEC_DATA | SEC_HAS_CONTENTS));
1435 call_table_text_section = subseg_new (".call_table_text", 0);
1436 bfd_set_section_flags (stdoutput, call_table_text_section,
1437 applicable & (SEC_ALLOC | SEC_LOAD | SEC_READONLY
1440 /* Restore text section as the current default. */
1441 subseg_set (text_section, 0);
1444 static bfd_reloc_code_real_type
1445 handle_ctoff (const struct v850_operand *operand)
1447 if (operand == NULL)
1448 return BFD_RELOC_V850_CALLT_16_16_OFFSET;
1450 if (operand->bits != 6
1451 || operand->shift != 0)
1453 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1454 return BFD_RELOC_64; /* Used to indicate an error condition. */
1457 return BFD_RELOC_V850_CALLT_6_7_OFFSET;
1460 static bfd_reloc_code_real_type
1461 handle_sdaoff (const struct v850_operand *operand)
1463 if (operand == NULL)
1464 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1466 if (operand->bits == 15 && operand->shift == 17)
1467 return BFD_RELOC_V850_SDA_15_16_OFFSET;
1469 if (operand->bits == -1)
1470 return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET;
1472 if (operand->bits != 16
1473 || operand->shift != 16)
1475 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1476 return BFD_RELOC_64; /* Used to indicate an error condition. */
1479 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1482 static bfd_reloc_code_real_type
1483 handle_zdaoff (const struct v850_operand *operand)
1485 if (operand == NULL)
1486 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1488 if (operand->bits == 15 && operand->shift == 17)
1489 return BFD_RELOC_V850_ZDA_15_16_OFFSET;
1491 if (operand->bits == -1)
1492 return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET;
1494 if (operand->bits != 16
1495 || operand->shift != 16)
1497 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1498 /* Used to indicate an error condition. */
1499 return BFD_RELOC_64;
1502 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1505 static bfd_reloc_code_real_type
1506 handle_tdaoff (const struct v850_operand *operand)
1508 if (operand == NULL)
1509 /* Data item, not an instruction. */
1510 return BFD_RELOC_V850_TDA_7_7_OFFSET;
1512 if (operand->bits == 6 && operand->shift == 1)
1513 /* sld.w/sst.w, operand: D8_6 */
1514 return BFD_RELOC_V850_TDA_6_8_OFFSET;
1516 if (operand->bits == 4 && operand->insert != NULL)
1517 /* sld.hu, operand: D5-4 */
1518 return BFD_RELOC_V850_TDA_4_5_OFFSET;
1520 if (operand->bits == 4 && operand->insert == NULL)
1521 /* sld.bu, operand: D4 */
1522 return BFD_RELOC_V850_TDA_4_4_OFFSET;
1524 if (operand->bits == 16 && operand->shift == 16)
1525 /* set1 & chums, operands: D16 */
1526 return BFD_RELOC_V850_TDA_16_16_OFFSET;
1528 if (operand->bits != 7)
1530 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1531 /* Used to indicate an error condition. */
1532 return BFD_RELOC_64;
1535 return operand->insert != NULL
1536 ? BFD_RELOC_V850_TDA_7_8_OFFSET /* sld.h/sst.h, operand: D8_7 */
1537 : BFD_RELOC_V850_TDA_7_7_OFFSET; /* sld.b/sst.b, opreand: D7 */
1540 /* Warning: The code in this function relies upon the definitions
1541 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1542 matching the hard coded values contained herein. */
1544 static bfd_reloc_code_real_type
1545 v850_reloc_prefix (const struct v850_operand *operand)
1547 boolean paren_skipped = false;
1549 /* Skip leading opening parenthesis. */
1550 if (*input_line_pointer == '(')
1552 ++input_line_pointer;
1553 paren_skipped = true;
1556 #define CHECK_(name, reloc) \
1557 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1559 input_line_pointer += strlen (name); \
1563 CHECK_ ("hi0", BFD_RELOC_HI16 );
1564 CHECK_ ("hi", BFD_RELOC_HI16_S );
1565 CHECK_ ("lo", BFD_RELOC_LO16 );
1566 CHECK_ ("sdaoff", handle_sdaoff (operand));
1567 CHECK_ ("zdaoff", handle_zdaoff (operand));
1568 CHECK_ ("tdaoff", handle_tdaoff (operand));
1569 CHECK_ ("hilo", BFD_RELOC_32 );
1570 CHECK_ ("ctoff", handle_ctoff (operand) );
1572 /* Restore skipped parenthesis. */
1574 --input_line_pointer;
1576 return BFD_RELOC_UNUSED;
1579 /* Insert an operand value into an instruction. */
1581 static unsigned long
1582 v850_insert_operand (insn, operand, val, file, line, str)
1584 const struct v850_operand *operand;
1590 if (operand->insert)
1592 const char *message = NULL;
1594 insn = operand->insert (insn, val, &message);
1595 if (message != NULL)
1597 if ((operand->flags & V850_OPERAND_SIGNED)
1598 && ! warn_signed_overflows
1599 && strstr (message, "out of range") != NULL)
1601 /* Skip warning... */
1603 else if ((operand->flags & V850_OPERAND_SIGNED) == 0
1604 && ! warn_unsigned_overflows
1605 && strstr (message, "out of range") != NULL)
1607 /* Skip warning... */
1611 if (file == (char *) NULL)
1612 as_warn ("%s: %s", str, message);
1614 as_warn_where (file, line, "%s: %s", str, message);
1618 if (file == (char *) NULL)
1621 as_warn_where (file, line, message);
1627 if (operand->bits != 32)
1631 if ((operand->flags & V850_OPERAND_SIGNED) != 0)
1633 if (! warn_signed_overflows)
1634 max = (1 << operand->bits) - 1;
1636 max = (1 << (operand->bits - 1)) - 1;
1638 min = -(1 << (operand->bits - 1));
1642 max = (1 << operand->bits) - 1;
1644 if (! warn_unsigned_overflows)
1645 min = -(1 << (operand->bits - 1));
1650 if (val < (offsetT) min || val > (offsetT) max)
1652 /* xgettext:c-format */
1654 _("operand out of range (%s not between %ld and %ld)");
1657 /* Restore min and mix to expected values for decimal ranges. */
1658 if ((operand->flags & V850_OPERAND_SIGNED)
1659 && ! warn_signed_overflows)
1660 max = (1 << (operand->bits - 1)) - 1;
1662 if (! (operand->flags & V850_OPERAND_SIGNED)
1663 && ! warn_unsigned_overflows)
1668 sprintf (buf, "%s: ", str);
1670 sprint_value (buf + strlen (buf), val);
1673 sprint_value (buf, val);
1675 if (file == (char *) NULL)
1676 as_warn (err, buf, min, max);
1678 as_warn_where (file, line, err, buf, min, max);
1682 insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift);
1688 static char copy_of_instruction[128];
1695 char *start_of_operands;
1696 struct v850_opcode *opcode;
1697 struct v850_opcode *next_opcode;
1698 const unsigned char *opindex_ptr;
1702 unsigned long insn_size;
1706 boolean extra_data_after_insn = false;
1707 unsigned extra_data_len = 0;
1708 unsigned long extra_data = 0;
1709 char *saved_input_line_pointer;
1711 strncpy (copy_of_instruction, str, sizeof (copy_of_instruction) - 1);
1713 /* Get the opcode. */
1714 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1720 /* Find the first opcode with the proper name. */
1721 opcode = (struct v850_opcode *) hash_find (v850_hash, str);
1724 /* xgettext:c-format */
1725 as_bad (_("Unrecognized opcode: `%s'"), str);
1726 ignore_rest_of_line ();
1731 while (ISSPACE (*str))
1734 start_of_operands = str;
1736 saved_input_line_pointer = input_line_pointer;
1740 const char *errmsg = NULL;
1744 if ((opcode->processors & processor_mask) == 0)
1746 errmsg = _("Target processor does not support this instruction.");
1753 insn = opcode->opcode;
1754 extra_data_after_insn = false;
1756 input_line_pointer = str = start_of_operands;
1758 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1760 const struct v850_operand *operand;
1763 bfd_reloc_code_real_type reloc;
1765 if (next_opindex == 0)
1767 operand = &v850_operands[*opindex_ptr];
1771 operand = &v850_operands[next_opindex];
1777 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1780 if (operand->flags & V850_OPERAND_RELAX)
1783 /* Gather the operand. */
1784 hold = input_line_pointer;
1785 input_line_pointer = str;
1787 /* lo(), hi(), hi0(), etc... */
1788 if ((reloc = v850_reloc_prefix (operand)) != BFD_RELOC_UNUSED)
1790 /* This is a fake reloc, used to indicate an error condition. */
1791 if (reloc == BFD_RELOC_64)
1799 if (ex.X_op == O_constant)
1803 case BFD_RELOC_V850_ZDA_16_16_OFFSET:
1804 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1808 case BFD_RELOC_LO16:
1810 /* Truncate, then sign extend the value. */
1811 ex.X_add_number = SEXT16 (ex.X_add_number);
1815 case BFD_RELOC_HI16:
1817 /* Truncate, then sign extend the value. */
1818 ex.X_add_number = SEXT16 (ex.X_add_number >> 16);
1822 case BFD_RELOC_HI16_S:
1824 /* Truncate, then sign extend the value. */
1825 int temp = (ex.X_add_number >> 16) & 0xffff;
1827 temp += (ex.X_add_number >> 15) & 1;
1829 ex.X_add_number = SEXT16 (temp);
1834 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1836 errmsg = _("immediate operand is too large");
1840 extra_data_after_insn = true;
1842 extra_data = ex.X_add_number;
1843 ex.X_add_number = 0;
1847 fprintf (stderr, "reloc: %d\n", reloc);
1848 as_bad (_("AAARG -> unhandled constant reloc"));
1852 if (fc > MAX_INSN_FIXUPS)
1853 as_fatal (_("too many fixups"));
1855 fixups[fc].exp = ex;
1856 fixups[fc].opindex = *opindex_ptr;
1857 fixups[fc].reloc = reloc;
1862 if (reloc == BFD_RELOC_32)
1864 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1866 errmsg = _("immediate operand is too large");
1870 extra_data_after_insn = true;
1872 extra_data = ex.X_add_number;
1875 if (fc > MAX_INSN_FIXUPS)
1876 as_fatal (_("too many fixups"));
1878 fixups[fc].exp = ex;
1879 fixups[fc].opindex = *opindex_ptr;
1880 fixups[fc].reloc = reloc;
1888 if ((operand->flags & V850_OPERAND_REG) != 0)
1890 if (!register_name (&ex))
1892 errmsg = _("invalid register name");
1894 else if ((operand->flags & V850_NOT_R0)
1895 && ex.X_add_number == 0)
1897 errmsg = _("register r0 cannot be used here");
1899 /* Force an error message to be generated by
1900 skipping over any following potential matches
1905 else if ((operand->flags & V850_OPERAND_SRG) != 0)
1907 if (!system_register_name (&ex, true, false))
1909 errmsg = _("invalid system register name");
1912 else if ((operand->flags & V850_OPERAND_EP) != 0)
1914 char *start = input_line_pointer;
1915 char c = get_symbol_end ();
1917 if (strcmp (start, "ep") != 0 && strcmp (start, "r30") != 0)
1919 /* Put things back the way we found them. */
1920 *input_line_pointer = c;
1921 input_line_pointer = start;
1922 errmsg = _("expected EP register");
1926 *input_line_pointer = c;
1927 str = input_line_pointer;
1928 input_line_pointer = hold;
1930 while (*str == ' ' || *str == ','
1931 || *str == '[' || *str == ']')
1935 else if ((operand->flags & V850_OPERAND_CC) != 0)
1939 errmsg = _("invalid condition code name");
1942 else if (operand->flags & V850E_PUSH_POP)
1944 errmsg = parse_register_list (&insn, operand);
1946 /* The parse_register_list() function has already done
1947 everything, so fake a dummy expression. */
1948 ex.X_op = O_constant;
1949 ex.X_add_number = 0;
1951 else if (operand->flags & V850E_IMMEDIATE16)
1955 if (ex.X_op != O_constant)
1956 errmsg = _("constant expression expected");
1957 else if (ex.X_add_number & 0xffff0000)
1959 if (ex.X_add_number & 0xffff)
1960 errmsg = _("constant too big to fit into instruction");
1961 else if ((insn & 0x001fffc0) == 0x00130780)
1962 ex.X_add_number >>= 16;
1964 errmsg = _("constant too big to fit into instruction");
1967 extra_data_after_insn = true;
1969 extra_data = ex.X_add_number;
1970 ex.X_add_number = 0;
1972 else if (operand->flags & V850E_IMMEDIATE32)
1976 if (ex.X_op != O_constant)
1977 errmsg = _("constant expression expected");
1979 extra_data_after_insn = true;
1981 extra_data = ex.X_add_number;
1982 ex.X_add_number = 0;
1984 else if (register_name (&ex)
1985 && (operand->flags & V850_OPERAND_REG) == 0)
1990 /* It is possible that an alias has been defined that
1991 matches a register name. For example the code may
1992 include a ".set ZERO, 0" directive, which matches
1993 the register name "zero". Attempt to reparse the
1994 field as an expression, and only complain if we
1995 cannot generate a constant. */
1997 input_line_pointer = str;
1999 c = get_symbol_end ();
2001 if (symbol_find (str) != NULL)
2004 *input_line_pointer = c;
2005 input_line_pointer = str;
2009 if (ex.X_op != O_constant)
2011 /* If this register is actually occuring too early on
2012 the parsing of the instruction, (because another
2013 field is missing) then report this. */
2014 if (opindex_ptr[1] != 0
2015 && (v850_operands[opindex_ptr[1]].flags
2016 & V850_OPERAND_REG))
2017 errmsg = _("syntax error: value is missing before the register name");
2019 errmsg = _("syntax error: register not expected");
2021 /* If we created a symbol in the process of this
2022 test then delete it now, so that it will not
2023 be output with the real symbols... */
2025 && ex.X_op == O_symbol)
2026 symbol_remove (ex.X_add_symbol,
2027 &symbol_rootP, &symbol_lastP);
2030 else if (system_register_name (&ex, false, false)
2031 && (operand->flags & V850_OPERAND_SRG) == 0)
2033 errmsg = _("syntax error: system register not expected");
2035 else if (cc_name (&ex)
2036 && (operand->flags & V850_OPERAND_CC) == 0)
2038 errmsg = _("syntax error: condition code not expected");
2044 If we are assembling a MOV instruction (or a CALLT.... :-)
2045 and the immediate value does not fit into the bits
2046 available then create a fake error so that the next MOV
2047 instruction will be selected. This one has a 32 bit
2050 if (((insn & 0x07e0) == 0x0200)
2051 && ex.X_op == O_constant
2052 && (ex.X_add_number < (-(1 << (operand->bits - 1)))
2053 || ex.X_add_number > ((1 << operand->bits) - 1)))
2054 errmsg = _("immediate operand is too large");
2062 " insn: %x, operand %d, op: %d, add_number: %d\n",
2063 insn, opindex_ptr - opcode->operands,
2064 ex.X_op, ex.X_add_number);
2070 errmsg = _("illegal operand");
2073 errmsg = _("missing operand");
2077 & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0)
2079 errmsg = _("invalid operand");
2082 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2084 copy_of_instruction);
2088 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2090 copy_of_instruction);
2094 /* We need to generate a fixup for this expression. */
2095 if (fc >= MAX_INSN_FIXUPS)
2096 as_fatal (_("too many fixups"));
2098 fixups[fc].exp = ex;
2099 fixups[fc].opindex = *opindex_ptr;
2100 fixups[fc].reloc = BFD_RELOC_UNUSED;
2106 str = input_line_pointer;
2107 input_line_pointer = hold;
2109 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']'
2118 next_opcode = opcode + 1;
2119 if (next_opcode->name != NULL
2120 && strcmp (next_opcode->name, opcode->name) == 0)
2122 opcode = next_opcode;
2124 /* Skip versions that are not supported by the target
2126 if ((opcode->processors & processor_mask) == 0)
2132 as_bad ("%s: %s", copy_of_instruction, errmsg);
2134 if (*input_line_pointer == ']')
2135 ++input_line_pointer;
2137 ignore_rest_of_line ();
2138 input_line_pointer = saved_input_line_pointer;
2144 while (ISSPACE (*str))
2148 /* xgettext:c-format */
2149 as_bad (_("junk at end of line: `%s'"), str);
2151 input_line_pointer = str;
2153 /* Tie dwarf2 debug info to the address at the start of the insn.
2154 We can't do this after the insn has been output as the current
2155 frag may have been closed off. eg. by frag_var. */
2156 dwarf2_emit_insn (0);
2158 /* Write out the instruction. */
2160 if (relaxable && fc > 0)
2165 if (!strcmp (opcode->name, "br"))
2167 f = frag_var (rs_machine_dependent, 4, 2, 2,
2168 fixups[0].exp.X_add_symbol,
2169 fixups[0].exp.X_add_number,
2170 (char *) fixups[0].opindex);
2171 md_number_to_chars (f, insn, insn_size);
2172 md_number_to_chars (f + 2, 0, 2);
2176 f = frag_var (rs_machine_dependent, 6, 4, 0,
2177 fixups[0].exp.X_add_symbol,
2178 fixups[0].exp.X_add_number,
2179 (char *) fixups[0].opindex);
2180 md_number_to_chars (f, insn, insn_size);
2181 md_number_to_chars (f + 2, 0, 4);
2186 /* Four byte insns have an opcode with the two high bits on. */
2187 if ((insn & 0x0600) == 0x0600)
2192 /* Special case: 32 bit MOV. */
2193 if ((insn & 0xffe0) == 0x0620)
2196 f = frag_more (insn_size);
2197 md_number_to_chars (f, insn, insn_size);
2199 if (extra_data_after_insn)
2201 f = frag_more (extra_data_len);
2202 md_number_to_chars (f, extra_data, extra_data_len);
2204 extra_data_after_insn = false;
2208 /* Create any fixups. At this point we do not use a
2209 bfd_reloc_code_real_type, but instead just use the
2210 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2211 handle fixups for any operand type, although that is admittedly
2212 not a very exciting feature. We pick a BFD reloc type in
2214 for (i = 0; i < fc; i++)
2216 const struct v850_operand *operand;
2217 bfd_reloc_code_real_type reloc;
2219 operand = &v850_operands[fixups[i].opindex];
2221 reloc = fixups[i].reloc;
2223 if (reloc != BFD_RELOC_UNUSED)
2225 reloc_howto_type *reloc_howto =
2226 bfd_reloc_type_lookup (stdoutput, reloc);
2234 size = bfd_get_reloc_size (reloc_howto);
2236 /* XXX This will abort on an R_V850_8 reloc -
2237 is this reloc actually used? */
2238 if (size != 2 && size != 4)
2241 address = (f - frag_now->fr_literal) + insn_size - size;
2243 if (reloc == BFD_RELOC_32)
2246 fixP = fix_new_exp (frag_now, address, size,
2248 reloc_howto->pc_relative,
2253 case BFD_RELOC_LO16:
2254 case BFD_RELOC_HI16:
2255 case BFD_RELOC_HI16_S:
2256 fixP->fx_no_overflow = 1;
2264 fix_new_exp (frag_now,
2265 f - frag_now->fr_literal, 4,
2267 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2268 (bfd_reloc_code_real_type) (fixups[i].opindex
2269 + (int) BFD_RELOC_UNUSED));
2273 input_line_pointer = saved_input_line_pointer;
2276 /* If while processing a fixup, a reloc really needs to be created
2277 then it is done here. */
2280 tc_gen_reloc (seg, fixp)
2281 asection *seg ATTRIBUTE_UNUSED;
2286 reloc = (arelent *) xmalloc (sizeof (arelent));
2287 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2288 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2289 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2290 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2292 if (reloc->howto == (reloc_howto_type *) NULL)
2294 as_bad_where (fixp->fx_file, fixp->fx_line,
2295 /* xgettext:c-format */
2296 _("reloc %d not supported by object file format"),
2297 (int) fixp->fx_r_type);
2304 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
2305 || fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT)
2306 reloc->addend = fixp->fx_offset;
2308 reloc->addend = fixp->fx_addnumber;
2313 /* Return current size of variable part of frag. */
2316 md_estimate_size_before_relax (fragp, seg)
2318 asection *seg ATTRIBUTE_UNUSED;
2320 if (fragp->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
2323 return md_relax_table[fragp->fr_subtype].rlx_length;
2327 v850_pcrel_from_section (fixp, section)
2331 /* If the symbol is undefined, or in a section other than our own,
2332 or it is weak (in which case it may well be in another section,
2333 then let the linker figure it out. */
2334 if (fixp->fx_addsy != (symbolS *) NULL
2335 && (! S_IS_DEFINED (fixp->fx_addsy)
2336 || S_IS_WEAK (fixp->fx_addsy)
2337 || (S_GET_SEGMENT (fixp->fx_addsy) != section)))
2340 return fixp->fx_frag->fr_address + fixp->fx_where;
2344 md_apply_fix3 (fixP, valueP, seg)
2347 segT seg ATTRIBUTE_UNUSED;
2349 valueT value = * valueP;
2352 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2353 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2359 if (fixP->fx_addsy == (symbolS *) NULL)
2362 else if (fixP->fx_pcrel)
2367 value = fixP->fx_offset;
2368 if (fixP->fx_subsy != (symbolS *) NULL)
2370 if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section)
2371 value -= S_GET_VALUE (fixP->fx_subsy);
2374 /* We don't actually support subtracting a symbol. */
2375 as_bad_where (fixP->fx_file, fixP->fx_line,
2376 _("expression too complex"));
2381 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
2384 const struct v850_operand *operand;
2387 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
2388 operand = &v850_operands[opindex];
2390 /* Fetch the instruction, insert the fully resolved operand
2391 value, and stuff the instruction back again.
2393 Note the instruction has been stored in little endian
2395 where = fixP->fx_frag->fr_literal + fixP->fx_where;
2397 insn = bfd_getl32 ((unsigned char *) where);
2398 insn = v850_insert_operand (insn, operand, (offsetT) value,
2399 fixP->fx_file, fixP->fx_line, NULL);
2400 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
2403 /* Nothing else to do here. */
2406 /* Determine a BFD reloc value based on the operand information.
2407 We are only prepared to turn a few of the operands into relocs. */
2409 if (operand->bits == 22)
2410 fixP->fx_r_type = BFD_RELOC_V850_22_PCREL;
2411 else if (operand->bits == 9)
2412 fixP->fx_r_type = BFD_RELOC_V850_9_PCREL;
2416 fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn);
2419 as_bad_where (fixP->fx_file, fixP->fx_line,
2420 _("unresolved expression that must be resolved"));
2425 else if (fixP->fx_done)
2427 /* We still have to insert the value into memory! */
2428 where = fixP->fx_frag->fr_literal + fixP->fx_where;
2430 if (fixP->fx_size == 1)
2431 *where = value & 0xff;
2432 else if (fixP->fx_size == 2)
2433 bfd_putl16 (value & 0xffff, (unsigned char *) where);
2434 else if (fixP->fx_size == 4)
2435 bfd_putl32 (value, (unsigned char *) where);
2438 fixP->fx_addnumber = value;
2441 /* Parse a cons expression. We have to handle hi(), lo(), etc
2445 parse_cons_expression_v850 (exp)
2448 /* See if there's a reloc prefix like hi() we have to handle. */
2449 hold_cons_reloc = v850_reloc_prefix (NULL);
2451 /* Do normal expression parsing. */
2455 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2456 found a reloc prefix, then we use that reloc, else we choose an
2457 appropriate one based on the size of the expression. */
2460 cons_fix_new_v850 (frag, where, size, exp)
2466 if (hold_cons_reloc == BFD_RELOC_UNUSED)
2469 hold_cons_reloc = BFD_RELOC_32;
2471 hold_cons_reloc = BFD_RELOC_16;
2473 hold_cons_reloc = BFD_RELOC_8;
2477 fix_new_exp (frag, where, size, exp, 0, hold_cons_reloc);
2479 fix_new (frag, where, size, NULL, 0, 0, hold_cons_reloc);
2481 hold_cons_reloc = BFD_RELOC_UNUSED;
2485 v850_fix_adjustable (fixP)
2488 if (fixP->fx_addsy == NULL)
2491 /* Prevent all adjustments to global symbols. */
2492 if (S_IS_EXTERN (fixP->fx_addsy))
2495 /* Similarly for weak symbols. */
2496 if (S_IS_WEAK (fixP->fx_addsy))
2499 /* Don't adjust function names. */
2500 if (S_IS_FUNCTION (fixP->fx_addsy))
2503 /* We need the symbol name for the VTABLE entries. */
2504 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2505 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2512 v850_force_relocation (fixP)
2515 if (fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy))
2518 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2519 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)