1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
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"
29 /* Sign-extend a 16-bit number. */
30 #define SEXT16(x) ((((x) & 0xffff) ^ (~0x7fff)) + 0x8000)
32 /* Temporarily holds the reloc in a cons expression. */
33 static bfd_reloc_code_real_type hold_cons_reloc = BFD_RELOC_UNUSED;
35 /* Set to TRUE if we want to be pedantic about signed overflows. */
36 static boolean warn_signed_overflows = FALSE;
37 static boolean warn_unsigned_overflows = FALSE;
39 /* Indicates the target BFD machine number. */
40 static int machine = -1;
42 /* Indicates the target processor(s) for the assemble. */
43 static int processor_mask = -1;
45 /* Structure to hold information about predefined registers. */
51 /* Generic assembler global variables which must be defined by all
54 /* Characters which always start a comment. */
55 const char comment_chars[] = "#";
57 /* Characters which start a comment at the beginning of a line. */
58 const char line_comment_chars[] = ";#";
60 /* Characters which may be used to separate multiple commands on a
62 const char line_separator_chars[] = ";";
64 /* Characters which are used to indicate an exponent in a floating
66 const char EXP_CHARS[] = "eE";
68 /* Characters which mean that a number is a floating point constant,
70 const char FLT_CHARS[] = "dD";
72 const relax_typeS md_relax_table[] = {
73 /* Conditional branches. */
75 {0x1fffff, -0x200000, 6, 0},
76 /* Unconditional branches. */
78 {0x1fffff, -0x200000, 4, 0},
82 #define MAX_INSN_FIXUPS (5)
86 bfd_reloc_code_real_type reloc;
89 struct v850_fixup fixups[MAX_INSN_FIXUPS];
99 struct v850_seg_entry v850_seg_table[] =
102 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
105 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS },
107 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS },
109 SEC_ALLOC | SEC_SMALL_DATA },
115 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY | SEC_DATA
116 | SEC_HAS_CONTENTS | SEC_SMALL_DATA },
118 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY | SEC_DATA
119 | SEC_HAS_CONTENTS },
121 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
122 | SEC_SMALL_DATA | SEC_IS_COMMON },
124 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
127 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS
129 { NULL, ".call_table_data",
130 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS },
131 { NULL, ".call_table_text",
132 SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY | SEC_CODE
138 #define SDATA_SECTION 0
139 #define TDATA_SECTION 1
140 #define ZDATA_SECTION 2
141 #define SBSS_SECTION 3
142 #define TBSS_SECTION 4
143 #define ZBSS_SECTION 5
144 #define ROSDATA_SECTION 6
145 #define ROZDATA_SECTION 7
146 #define SCOMMON_SECTION 8
147 #define TCOMMON_SECTION 9
148 #define ZCOMMON_SECTION 10
149 #define CALL_TABLE_DATA_SECTION 11
150 #define CALL_TABLE_TEXT_SECTION 12
151 #define BSS_SECTION 13
153 static void do_v850_seg PARAMS ((int, subsegT));
160 struct v850_seg_entry *seg = v850_seg_table + i;
162 obj_elf_section_change_hook ();
165 subseg_set (seg->s, sub);
169 seg->s = subseg_new (seg->name, sub);
170 bfd_set_section_flags (stdoutput, seg->s, seg->flags);
171 if ((seg->flags & SEC_LOAD) == 0)
172 seg_info (seg->s)->bss = 1;
176 static void v850_seg PARAMS ((int i));
182 subsegT sub = get_absolute_expression ();
184 do_v850_seg (i, sub);
185 demand_empty_rest_of_line ();
188 static void v850_offset PARAMS ((int));
192 int ignore ATTRIBUTE_UNUSED;
194 int temp = get_absolute_expression ();
196 temp -= frag_now_fix ();
199 (void) frag_more (temp);
201 demand_empty_rest_of_line ();
204 /* Copied from obj_elf_common() in gas/config/obj-elf.c. */
206 static void v850_comm PARAMS ((int));
220 name = input_line_pointer;
221 c = get_symbol_end ();
223 /* Just after name is now '\0'. */
224 p = input_line_pointer;
229 if (*input_line_pointer != ',')
231 as_bad (_("Expected comma after symbol-name"));
232 ignore_rest_of_line ();
237 input_line_pointer++;
239 if ((temp = get_absolute_expression ()) < 0)
241 /* xgettext:c-format */
242 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp);
243 ignore_rest_of_line ();
249 symbolP = symbol_find_or_make (name);
252 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
254 as_bad (_("Ignoring attempt to re-define symbol"));
255 ignore_rest_of_line ();
259 if (S_GET_VALUE (symbolP) != 0)
261 if (S_GET_VALUE (symbolP) != size)
263 /* xgettext:c-format */
264 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
265 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
269 know (symbol_get_frag (symbolP) == &zero_address_frag);
271 if (*input_line_pointer != ',')
276 input_line_pointer++;
280 if (! have_align || *input_line_pointer != '"')
286 temp = get_absolute_expression ();
291 as_warn (_("Common alignment negative; 0 assumed"));
295 if (symbol_get_obj (symbolP)->local)
304 old_subsec = now_subseg;
306 applicable = bfd_applicable_section_flags (stdoutput);
308 applicable &= SEC_ALLOC;
312 case SCOMMON_SECTION:
313 do_v850_seg (SBSS_SECTION, 0);
316 case ZCOMMON_SECTION:
317 do_v850_seg (ZBSS_SECTION, 0);
320 case TCOMMON_SECTION:
321 do_v850_seg (TBSS_SECTION, 0);
327 /* Convert to a power of 2 alignment. */
328 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align)
333 as_bad (_("Common alignment not a power of 2"));
334 ignore_rest_of_line ();
341 record_alignment (now_seg, align);
344 frag_align (align, 0, 0);
348 case SCOMMON_SECTION:
349 if (S_GET_SEGMENT (symbolP) == v850_seg_table[SBSS_SECTION].s)
350 symbol_get_frag (symbolP)->fr_symbol = 0;
353 case ZCOMMON_SECTION:
354 if (S_GET_SEGMENT (symbolP) == v850_seg_table[ZBSS_SECTION].s)
355 symbol_get_frag (symbolP)->fr_symbol = 0;
358 case TCOMMON_SECTION:
359 if (S_GET_SEGMENT (symbolP) == v850_seg_table[TBSS_SECTION].s)
360 symbol_get_frag (symbolP)->fr_symbol = 0;
367 symbol_set_frag (symbolP, frag_now);
368 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
369 (offsetT) size, (char *) 0);
371 S_SET_SIZE (symbolP, size);
375 case SCOMMON_SECTION:
376 S_SET_SEGMENT (symbolP, v850_seg_table[SBSS_SECTION].s);
379 case ZCOMMON_SECTION:
380 S_SET_SEGMENT (symbolP, v850_seg_table[ZBSS_SECTION].s);
383 case TCOMMON_SECTION:
384 S_SET_SEGMENT (symbolP, v850_seg_table[TBSS_SECTION].s);
391 S_CLEAR_EXTERNAL (symbolP);
392 obj_elf_section_change_hook ();
393 subseg_set (old_sec, old_subsec);
398 S_SET_VALUE (symbolP, (valueT) size);
399 S_SET_ALIGN (symbolP, temp);
400 S_SET_EXTERNAL (symbolP);
404 case SCOMMON_SECTION:
405 case ZCOMMON_SECTION:
406 case TCOMMON_SECTION:
407 do_v850_seg (area, 0);
408 S_SET_SEGMENT (symbolP, v850_seg_table[area].s);
418 input_line_pointer++;
420 /* @@ Some use the dot, some don't. Can we get some consistency?? */
421 if (*input_line_pointer == '.')
422 input_line_pointer++;
424 /* @@ Some say data, some say bss. */
425 if (strncmp (input_line_pointer, "bss\"", 4)
426 && strncmp (input_line_pointer, "data\"", 5))
428 while (*--input_line_pointer != '"')
430 input_line_pointer--;
431 goto bad_common_segment;
433 while (*input_line_pointer++ != '"')
435 goto allocate_common;
438 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
440 demand_empty_rest_of_line ();
445 p = input_line_pointer;
446 while (*p && *p != '\n')
450 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
452 input_line_pointer = p;
453 ignore_rest_of_line ();
458 static void set_machine PARAMS ((int));
465 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
469 case 0: processor_mask = PROCESSOR_V850; break;
470 case bfd_mach_v850e: processor_mask = PROCESSOR_V850E; break;
471 case bfd_mach_v850ea: processor_mask = PROCESSOR_V850EA; break;
475 /* The target specific pseudo-ops which we support. */
476 const pseudo_typeS md_pseudo_table[] = {
477 { "sdata", v850_seg, SDATA_SECTION },
478 { "tdata", v850_seg, TDATA_SECTION },
479 { "zdata", v850_seg, ZDATA_SECTION },
480 { "sbss", v850_seg, SBSS_SECTION },
481 { "tbss", v850_seg, TBSS_SECTION },
482 { "zbss", v850_seg, ZBSS_SECTION },
483 { "rosdata", v850_seg, ROSDATA_SECTION },
484 { "rozdata", v850_seg, ROZDATA_SECTION },
485 { "bss", v850_seg, BSS_SECTION },
486 { "offset", v850_offset, 0 },
488 { "zcomm", v850_comm, ZCOMMON_SECTION },
489 { "scomm", v850_comm, SCOMMON_SECTION },
490 { "tcomm", v850_comm, TCOMMON_SECTION },
491 { "v850", set_machine, 0 },
492 { "call_table_data", v850_seg, CALL_TABLE_DATA_SECTION },
493 { "call_table_text", v850_seg, CALL_TABLE_TEXT_SECTION },
494 { "v850e", set_machine, bfd_mach_v850e },
495 { "v850ea", set_machine, bfd_mach_v850ea },
496 { "file", dwarf2_directive_file, 0 },
497 { "loc", dwarf2_directive_loc, 0 },
501 /* Opcode hash table. */
502 static struct hash_control *v850_hash;
504 /* This table is sorted. Suitable for searching by a binary search. */
505 static const struct reg_name pre_defined_registers[] = {
506 { "ep", 30 }, /* ep - element ptr */
507 { "gp", 4 }, /* gp - global ptr */
508 { "hp", 2 }, /* hp - handler stack ptr */
509 { "lp", 31 }, /* lp - link ptr */
542 { "sp", 3 }, /* sp - stack ptr */
543 { "tp", 5 }, /* tp - text ptr */
547 #define REG_NAME_CNT \
548 (sizeof (pre_defined_registers) / sizeof (struct reg_name))
550 static const struct reg_name system_registers[] = {
564 #define SYSREG_NAME_CNT \
565 (sizeof (system_registers) / sizeof (struct reg_name))
567 static const struct reg_name system_list_registers[] = {
572 #define SYSREGLIST_NAME_CNT \
573 (sizeof (system_list_registers) / sizeof (struct reg_name))
575 static const struct reg_name cc_names[] = {
600 #define CC_NAME_CNT \
601 (sizeof (cc_names) / sizeof (struct reg_name))
603 /* Do a binary search of the given register table to see if NAME is a
604 valid regiter name. Return the register number from the array on
605 success, or -1 on failure. */
607 static int reg_name_search
608 PARAMS ((const struct reg_name *, int, const char *, boolean));
611 reg_name_search (regs, regcount, name, accept_numbers)
612 const struct reg_name *regs;
615 boolean accept_numbers;
617 int middle, low, high;
621 /* If the register name is a symbol, then evaluate it. */
622 if ((symbolP = symbol_find (name)) != NULL)
624 /* If the symbol is an alias for another name then use that.
625 If the symbol is an alias for a number, then return the number. */
626 if (symbol_equated_p (symbolP))
629 = S_GET_NAME (symbol_get_value_expression (symbolP)->X_add_symbol);
631 else if (accept_numbers)
633 int reg = S_GET_VALUE (symbolP);
635 if (reg >= 0 && reg <= 31)
639 /* Otherwise drop through and try parsing name normally. */
647 middle = (low + high) / 2;
648 cmp = strcasecmp (name, regs[middle].name);
654 return regs[middle].value;
660 /* Summary of register_name().
662 * in: Input_line_pointer points to 1st char of operand.
664 * out: An expressionS.
665 * The operand may have been a register: in this case, X_op == O_register,
666 * X_add_number is set to the register number, and truth is returned.
667 * Input_line_pointer->(next non-blank) char after operand, or is in
668 * its original state. */
670 static boolean register_name PARAMS ((expressionS *));
673 register_name (expressionP)
674 expressionS *expressionP;
681 /* Find the spelling of the operand. */
682 start = name = input_line_pointer;
684 c = get_symbol_end ();
686 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT,
689 /* Put back the delimiting char. */
690 *input_line_pointer = c;
692 /* Look to see if it's in the register table. */
695 expressionP->X_op = O_register;
696 expressionP->X_add_number = reg_number;
698 /* Make the rest nice. */
699 expressionP->X_add_symbol = NULL;
700 expressionP->X_op_symbol = NULL;
706 /* Reset the line as if we had not done anything. */
707 input_line_pointer = start;
713 /* Summary of system_register_name().
715 * in: INPUT_LINE_POINTER points to 1st char of operand.
716 * EXPRESSIONP points to an expression structure to be filled in.
717 * ACCEPT_NUMBERS is true iff numerical register names may be used.
718 * ACCEPT_LIST_NAMES is true iff the special names PS and SR may be
721 * out: An expressionS structure in expressionP.
722 * The operand may have been a register: in this case, X_op == O_register,
723 * X_add_number is set to the register number, and truth is returned.
724 * Input_line_pointer->(next non-blank) char after operand, or is in
725 * its original state. */
727 static boolean system_register_name PARAMS ((expressionS *, boolean, boolean));
730 system_register_name (expressionP, accept_numbers, accept_list_names)
731 expressionS *expressionP;
732 boolean accept_numbers;
733 boolean accept_list_names;
740 /* Find the spelling of the operand. */
741 start = name = input_line_pointer;
743 c = get_symbol_end ();
744 reg_number = reg_name_search (system_registers, SYSREG_NAME_CNT, name,
747 /* Put back the delimiting char. */
748 *input_line_pointer = c;
753 /* Reset input_line pointer. */
754 input_line_pointer = start;
756 if (ISDIGIT (*input_line_pointer))
758 reg_number = strtol (input_line_pointer, &input_line_pointer, 10);
760 /* Make sure that the register number is allowable. */
762 || (reg_number > 5 && reg_number < 16)
768 else if (accept_list_names)
770 c = get_symbol_end ();
771 reg_number = reg_name_search (system_list_registers,
772 SYSREGLIST_NAME_CNT, name, FALSE);
774 /* Put back the delimiting char. */
775 *input_line_pointer = c;
779 /* Look to see if it's in the register table. */
782 expressionP->X_op = O_register;
783 expressionP->X_add_number = reg_number;
785 /* Make the rest nice. */
786 expressionP->X_add_symbol = NULL;
787 expressionP->X_op_symbol = NULL;
793 /* Reset the line as if we had not done anything. */
794 input_line_pointer = start;
800 /* Summary of cc_name().
802 * in: INPUT_LINE_POINTER points to 1st char of operand.
804 * out: An expressionS.
805 * The operand may have been a register: in this case, X_op == O_register,
806 * X_add_number is set to the register number, and truth is returned.
807 * Input_line_pointer->(next non-blank) char after operand, or is in
808 * its original state. */
810 static boolean cc_name PARAMS ((expressionS *));
813 cc_name (expressionP)
814 expressionS *expressionP;
821 /* Find the spelling of the operand. */
822 start = name = input_line_pointer;
824 c = get_symbol_end ();
825 reg_number = reg_name_search (cc_names, CC_NAME_CNT, name, FALSE);
827 /* Put back the delimiting char. */
828 *input_line_pointer = c;
830 /* Look to see if it's in the register table. */
833 expressionP->X_op = O_constant;
834 expressionP->X_add_number = reg_number;
836 /* Make the rest nice. */
837 expressionP->X_add_symbol = NULL;
838 expressionP->X_op_symbol = NULL;
844 /* Reset the line as if we had not done anything. */
845 input_line_pointer = start;
851 static void skip_white_space PARAMS ((void));
856 while (*input_line_pointer == ' '
857 || *input_line_pointer == '\t')
858 ++input_line_pointer;
861 /* Summary of parse_register_list ().
863 * in: INPUT_LINE_POINTER points to 1st char of a list of registers.
864 * INSN is the partially constructed instruction.
865 * OPERAND is the operand being inserted.
867 * out: NULL if the parse completed successfully, otherwise a
868 * pointer to an error message is returned. If the parse
869 * completes the correct bit fields in the instruction
872 * Parses register lists with the syntax:
880 * and also parses constant epxressions whoes bits indicate the
881 * registers in the lists. The LSB in the expression refers to
882 * the lowest numbered permissable register in the register list,
883 * and so on upwards. System registers are considered to be very
886 static char *parse_register_list
887 PARAMS ((unsigned long *, const struct v850_operand *));
890 parse_register_list (insn, operand)
892 const struct v850_operand *operand;
894 static int type1_regs[32] = {
895 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
896 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
898 static int type2_regs[32] = {
899 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
900 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
902 static int type3_regs[32] = {
903 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
904 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8
909 /* Select a register array to parse. */
910 switch (operand->shift)
912 case 0xffe00001: regs = type1_regs; break;
913 case 0xfff8000f: regs = type2_regs; break;
914 case 0xfff8001f: regs = type3_regs; break;
916 as_bad (_("unknown operand shift: %x\n"), operand->shift);
917 return _("internal failure in parse_register_list");
922 /* If the expression starts with a curly brace it is a register list.
923 Otherwise it is a constant expression, whoes bits indicate which
924 registers are to be included in the list. */
926 if (*input_line_pointer != '{')
933 if (exp.X_op != O_constant)
934 return _("constant expression or register list expected");
936 if (regs == type1_regs)
938 if (exp.X_add_number & 0xFFFFF000)
939 return _("high bits set in register list expression");
941 for (reg = 20; reg < 32; reg++)
942 if (exp.X_add_number & (1 << (reg - 20)))
944 for (i = 0; i < 32; i++)
949 else if (regs == type2_regs)
951 if (exp.X_add_number & 0xFFFE0000)
952 return _("high bits set in register list expression");
954 for (reg = 1; reg < 16; reg++)
955 if (exp.X_add_number & (1 << (reg - 1)))
957 for (i = 0; i < 32; i++)
962 if (exp.X_add_number & (1 << 15))
965 if (exp.X_add_number & (1 << 16))
968 else /* regs == type3_regs */
970 if (exp.X_add_number & 0xFFFE0000)
971 return _("high bits set in register list expression");
973 for (reg = 16; reg < 32; reg++)
974 if (exp.X_add_number & (1 << (reg - 16)))
976 for (i = 0; i < 32; i++)
981 if (exp.X_add_number & (1 << 16))
988 input_line_pointer++;
990 /* Parse the register list until a terminator (closing curly brace or
991 new-line) is found. */
994 if (register_name (&exp))
998 /* Locate the given register in the list, and if it is there,
999 insert the corresponding bit into the instruction. */
1000 for (i = 0; i < 32; i++)
1002 if (regs[i] == exp.X_add_number)
1011 return _("illegal register included in list");
1014 else if (system_register_name (&exp, true, true))
1016 if (regs == type1_regs)
1018 return _("system registers cannot be included in list");
1020 else if (exp.X_add_number == 5)
1022 if (regs == type2_regs)
1023 return _("PSW cannot be included in list");
1027 else if (exp.X_add_number < 4)
1030 return _("High value system registers cannot be included in list");
1032 else if (*input_line_pointer == '}')
1034 input_line_pointer++;
1037 else if (*input_line_pointer == ',')
1039 input_line_pointer++;
1042 else if (*input_line_pointer == '-')
1044 /* We have encountered a range of registers: rX - rY. */
1048 /* Skip the dash. */
1049 ++input_line_pointer;
1051 /* Get the second register in the range. */
1052 if (! register_name (&exp2))
1054 return _("second register should follow dash in register list");
1055 exp2.X_add_number = exp.X_add_number;
1058 /* Add the rest of the registers in the range. */
1059 for (j = exp.X_add_number + 1; j <= exp2.X_add_number; j++)
1063 /* Locate the given register in the list, and if it is there,
1064 insert the corresponding bit into the instruction. */
1065 for (i = 0; i < 32; i++)
1075 return _("illegal register included in list");
1083 skip_white_space ();
1089 const char *md_shortopts = "m:";
1091 struct option md_longopts[] = {
1092 {NULL, no_argument, NULL, 0}
1095 size_t md_longopts_size = sizeof (md_longopts);
1098 md_show_usage (stream)
1101 fprintf (stream, _(" V850 options:\n"));
1102 fprintf (stream, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1103 fprintf (stream, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1104 fprintf (stream, _(" -mv850 The code is targeted at the v850\n"));
1105 fprintf (stream, _(" -mv850e The code is targeted at the v850e\n"));
1106 fprintf (stream, _(" -mv850ea The code is targeted at the v850ea\n"));
1107 fprintf (stream, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1111 md_parse_option (c, arg)
1118 /* xgettext:c-format */
1119 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1123 if (strcmp (arg, "warn-signed-overflow") == 0)
1125 warn_signed_overflows = TRUE;
1127 else if (strcmp (arg, "warn-unsigned-overflow") == 0)
1129 warn_unsigned_overflows = TRUE;
1131 else if (strcmp (arg, "v850") == 0)
1134 processor_mask = PROCESSOR_V850;
1136 else if (strcmp (arg, "v850e") == 0)
1138 machine = bfd_mach_v850e;
1139 processor_mask = PROCESSOR_V850E;
1141 else if (strcmp (arg, "v850ea") == 0)
1143 machine = bfd_mach_v850ea;
1144 processor_mask = PROCESSOR_V850EA;
1146 else if (strcmp (arg, "v850any") == 0)
1148 /* Tell the world that this is for any v850 chip. */
1151 /* But support instructions for the extended versions. */
1152 processor_mask = PROCESSOR_V850EA;
1156 /* xgettext:c-format */
1157 fprintf (stderr, _("unknown command line option: -%c%s\n"), c, arg);
1165 md_undefined_symbol (name)
1166 char *name ATTRIBUTE_UNUSED;
1172 md_atof (type, litp, sizep)
1178 LITTLENUM_TYPE words[4];
1194 return _("bad call to md_atof");
1197 t = atof_ieee (input_line_pointer, type, words);
1199 input_line_pointer = t;
1203 for (i = prec - 1; i >= 0; i--)
1205 md_number_to_chars (litp, (valueT) words[i], 2);
1215 md_convert_frag (abfd, sec, fragP)
1216 bfd *abfd ATTRIBUTE_UNUSED;
1220 subseg_change (sec, 0);
1222 /* In range conditional or unconditional branch. */
1223 if (fragP->fr_subtype == 0 || fragP->fr_subtype == 2)
1225 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
1226 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode);
1229 /* Out of range conditional branch. Emit a branch around a jump. */
1230 else if (fragP->fr_subtype == 1)
1232 unsigned char *buffer =
1233 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1235 /* Reverse the condition of the first branch. */
1237 /* Mask off all the displacement bits. */
1240 /* Now set the displacement bits so that we branch
1241 around the unconditional branch. */
1244 /* Now create the unconditional branch + fixup to the final
1246 md_number_to_chars (buffer + 2, 0x00000780, 4);
1247 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
1248 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1249 (int) fragP->fr_opcode + 1);
1252 /* Out of range unconditional branch. Emit a jump. */
1253 else if (fragP->fr_subtype == 3)
1255 md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x00000780, 4);
1256 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
1257 fragP->fr_offset, 1, BFD_RELOC_UNUSED +
1258 (int) fragP->fr_opcode + 1);
1266 md_section_align (seg, addr)
1270 int align = bfd_get_section_alignment (stdoutput, seg);
1271 return ((addr + (1 << align) - 1) & (-1 << align));
1277 char *prev_name = "";
1278 register const struct v850_opcode *op;
1280 if (strncmp (TARGET_CPU, "v850ea", 6) == 0)
1283 machine = bfd_mach_v850ea;
1285 if (processor_mask == -1)
1286 processor_mask = PROCESSOR_V850EA;
1288 else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
1291 machine = bfd_mach_v850e;
1293 if (processor_mask == -1)
1294 processor_mask = PROCESSOR_V850E;
1296 else if (strncmp (TARGET_CPU, "v850", 4) == 0)
1301 if (processor_mask == -1)
1302 processor_mask = PROCESSOR_V850;
1305 /* xgettext:c-format */
1306 as_bad (_("Unable to determine default target processor from string: %s"),
1309 v850_hash = hash_new ();
1311 /* Insert unique names into hash table. The V850 instruction set
1312 has many identical opcode names that have different opcodes based
1313 on the operands. This hash table then provides a quick index to
1314 the first opcode with a particular name in the opcode table. */
1319 if (strcmp (prev_name, op->name))
1321 prev_name = (char *) op->name;
1322 hash_insert (v850_hash, op->name, (char *) op);
1327 v850_seg_table[BSS_SECTION].s = bss_section;
1328 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
1331 static bfd_reloc_code_real_type handle_ctoff
1332 PARAMS ((const struct v850_operand *));
1334 static bfd_reloc_code_real_type
1335 handle_ctoff (operand)
1336 const struct v850_operand *operand;
1338 if (operand == NULL)
1339 return BFD_RELOC_V850_CALLT_16_16_OFFSET;
1341 if (operand->bits != 6
1342 || operand->shift != 0)
1344 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1345 return BFD_RELOC_64; /* Used to indicate an error condition. */
1348 return BFD_RELOC_V850_CALLT_6_7_OFFSET;
1351 static bfd_reloc_code_real_type handle_sdaoff
1352 PARAMS ((const struct v850_operand *));
1354 static bfd_reloc_code_real_type
1355 handle_sdaoff (operand)
1356 const struct v850_operand *operand;
1358 if (operand == NULL)
1359 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1361 if (operand->bits == 15 && operand->shift == 17)
1362 return BFD_RELOC_V850_SDA_15_16_OFFSET;
1364 if (operand->bits == -1)
1365 return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET;
1367 if (operand->bits != 16
1368 || operand->shift != 16)
1370 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1371 return BFD_RELOC_64; /* Used to indicate an error condition. */
1374 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1377 static bfd_reloc_code_real_type handle_zdaoff
1378 PARAMS ((const struct v850_operand *));
1380 static bfd_reloc_code_real_type
1381 handle_zdaoff (operand)
1382 const struct v850_operand *operand;
1384 if (operand == NULL)
1385 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1387 if (operand->bits == 15 && operand->shift == 17)
1388 return BFD_RELOC_V850_ZDA_15_16_OFFSET;
1390 if (operand->bits == -1)
1391 return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET;
1393 if (operand->bits != 16
1394 || operand->shift != 16)
1396 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1397 /* Used to indicate an error condition. */
1398 return BFD_RELOC_64;
1401 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1404 static bfd_reloc_code_real_type handle_tdaoff
1405 PARAMS ((const struct v850_operand *));
1407 static bfd_reloc_code_real_type
1408 handle_tdaoff (operand)
1409 const struct v850_operand *operand;
1411 if (operand == NULL)
1412 /* Data item, not an instruction. */
1413 return BFD_RELOC_V850_TDA_7_7_OFFSET;
1415 if (operand->bits == 6 && operand->shift == 1)
1416 /* sld.w/sst.w, operand: D8_6 */
1417 return BFD_RELOC_V850_TDA_6_8_OFFSET;
1419 if (operand->bits == 4 && operand->insert != NULL)
1420 /* sld.hu, operand: D5-4 */
1421 return BFD_RELOC_V850_TDA_4_5_OFFSET;
1423 if (operand->bits == 4 && operand->insert == NULL)
1424 /* sld.bu, operand: D4 */
1425 return BFD_RELOC_V850_TDA_4_4_OFFSET;
1427 if (operand->bits == 16 && operand->shift == 16)
1428 /* set1 & chums, operands: D16 */
1429 return BFD_RELOC_V850_TDA_16_16_OFFSET;
1431 if (operand->bits != 7)
1433 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1434 /* Used to indicate an error condition. */
1435 return BFD_RELOC_64;
1438 return operand->insert != NULL
1439 ? BFD_RELOC_V850_TDA_7_8_OFFSET /* sld.h/sst.h, operand: D8_7 */
1440 : BFD_RELOC_V850_TDA_7_7_OFFSET; /* sld.b/sst.b, opreand: D7 */
1443 /* Warning: The code in this function relies upon the definitions
1444 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1445 matching the hard coded values contained herein. */
1447 static bfd_reloc_code_real_type v850_reloc_prefix
1448 PARAMS ((const struct v850_operand *));
1450 static bfd_reloc_code_real_type
1451 v850_reloc_prefix (operand)
1452 const struct v850_operand *operand;
1454 boolean paren_skipped = false;
1456 /* Skip leading opening parenthesis. */
1457 if (*input_line_pointer == '(')
1459 ++input_line_pointer;
1460 paren_skipped = true;
1463 #define CHECK_(name, reloc) \
1464 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1466 input_line_pointer += strlen (name); \
1470 CHECK_ ("hi0", BFD_RELOC_HI16 );
1471 CHECK_ ("hi", BFD_RELOC_HI16_S );
1472 CHECK_ ("lo", BFD_RELOC_LO16 );
1473 CHECK_ ("sdaoff", handle_sdaoff (operand));
1474 CHECK_ ("zdaoff", handle_zdaoff (operand));
1475 CHECK_ ("tdaoff", handle_tdaoff (operand));
1476 CHECK_ ("hilo", BFD_RELOC_32 );
1477 CHECK_ ("ctoff", handle_ctoff (operand) );
1479 /* Restore skipped parenthesis. */
1481 --input_line_pointer;
1483 return BFD_RELOC_UNUSED;
1486 /* Insert an operand value into an instruction. */
1488 static unsigned long v850_insert_operand
1489 PARAMS ((unsigned long, const struct v850_operand *, offsetT, char *,
1490 unsigned int, char *));
1492 static unsigned long
1493 v850_insert_operand (insn, operand, val, file, line, str)
1495 const struct v850_operand *operand;
1501 if (operand->insert)
1503 const char *message = NULL;
1505 insn = operand->insert (insn, val, &message);
1506 if (message != NULL)
1508 if ((operand->flags & V850_OPERAND_SIGNED)
1509 && ! warn_signed_overflows
1510 && strstr (message, "out of range") != NULL)
1512 /* Skip warning... */
1514 else if ((operand->flags & V850_OPERAND_SIGNED) == 0
1515 && ! warn_unsigned_overflows
1516 && strstr (message, "out of range") != NULL)
1518 /* Skip warning... */
1522 if (file == (char *) NULL)
1523 as_warn ("%s: %s", str, message);
1525 as_warn_where (file, line, "%s: %s", str, message);
1529 if (file == (char *) NULL)
1532 as_warn_where (file, line, message);
1538 if (operand->bits != 32)
1542 if ((operand->flags & V850_OPERAND_SIGNED) != 0)
1544 if (! warn_signed_overflows)
1545 max = (1 << operand->bits) - 1;
1547 max = (1 << (operand->bits - 1)) - 1;
1549 min = -(1 << (operand->bits - 1));
1553 max = (1 << operand->bits) - 1;
1555 if (! warn_unsigned_overflows)
1556 min = -(1 << (operand->bits - 1));
1561 if (val < (offsetT) min || val > (offsetT) max)
1563 /* xgettext:c-format */
1565 _("operand out of range (%s not between %ld and %ld)");
1568 /* Restore min and mix to expected values for decimal ranges. */
1569 if ((operand->flags & V850_OPERAND_SIGNED)
1570 && ! warn_signed_overflows)
1571 max = (1 << (operand->bits - 1)) - 1;
1573 if (! (operand->flags & V850_OPERAND_SIGNED)
1574 && ! warn_unsigned_overflows)
1579 sprintf (buf, "%s: ", str);
1581 sprint_value (buf + strlen (buf), val);
1584 sprint_value (buf, val);
1586 if (file == (char *) NULL)
1587 as_warn (err, buf, min, max);
1589 as_warn_where (file, line, err, buf, min, max);
1593 insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift);
1599 static char copy_of_instruction[128];
1606 char *start_of_operands;
1607 struct v850_opcode *opcode;
1608 struct v850_opcode *next_opcode;
1609 const unsigned char *opindex_ptr;
1613 unsigned long insn_size;
1617 boolean extra_data_after_insn = false;
1618 unsigned extra_data_len = 0;
1619 unsigned long extra_data = 0;
1620 char *saved_input_line_pointer;
1622 strncpy (copy_of_instruction, str, sizeof (copy_of_instruction) - 1);
1624 /* Get the opcode. */
1625 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1631 /* Find the first opcode with the proper name. */
1632 opcode = (struct v850_opcode *) hash_find (v850_hash, str);
1635 /* xgettext:c-format */
1636 as_bad (_("Unrecognized opcode: `%s'"), str);
1637 ignore_rest_of_line ();
1642 while (ISSPACE (*str))
1645 start_of_operands = str;
1647 saved_input_line_pointer = input_line_pointer;
1651 const char *errmsg = NULL;
1655 if ((opcode->processors & processor_mask) == 0)
1657 errmsg = _("Target processor does not support this instruction.");
1664 insn = opcode->opcode;
1665 extra_data_after_insn = false;
1667 input_line_pointer = str = start_of_operands;
1669 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1671 const struct v850_operand *operand;
1674 bfd_reloc_code_real_type reloc;
1676 if (next_opindex == 0)
1678 operand = &v850_operands[*opindex_ptr];
1682 operand = &v850_operands[next_opindex];
1688 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1691 if (operand->flags & V850_OPERAND_RELAX)
1694 /* Gather the operand. */
1695 hold = input_line_pointer;
1696 input_line_pointer = str;
1698 /* lo(), hi(), hi0(), etc... */
1699 if ((reloc = v850_reloc_prefix (operand)) != BFD_RELOC_UNUSED)
1701 /* This is a fake reloc, used to indicate an error condition. */
1702 if (reloc == BFD_RELOC_64)
1710 if (ex.X_op == O_constant)
1714 case BFD_RELOC_V850_ZDA_16_16_OFFSET:
1715 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1719 case BFD_RELOC_LO16:
1721 /* Truncate, then sign extend the value. */
1722 ex.X_add_number = SEXT16 (ex.X_add_number);
1726 case BFD_RELOC_HI16:
1728 /* Truncate, then sign extend the value. */
1729 ex.X_add_number = SEXT16 (ex.X_add_number >> 16);
1733 case BFD_RELOC_HI16_S:
1735 /* Truncate, then sign extend the value. */
1736 int temp = (ex.X_add_number >> 16) & 0xffff;
1738 temp += (ex.X_add_number >> 15) & 1;
1740 ex.X_add_number = SEXT16 (temp);
1745 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1747 errmsg = _("immediate operand is too large");
1751 extra_data_after_insn = true;
1753 extra_data = ex.X_add_number;
1754 ex.X_add_number = 0;
1758 fprintf (stderr, "reloc: %d\n", reloc);
1759 as_bad (_("AAARG -> unhandled constant reloc"));
1763 if (fc > MAX_INSN_FIXUPS)
1764 as_fatal (_("too many fixups"));
1766 fixups[fc].exp = ex;
1767 fixups[fc].opindex = *opindex_ptr;
1768 fixups[fc].reloc = reloc;
1773 if (reloc == BFD_RELOC_32)
1775 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1777 errmsg = _("immediate operand is too large");
1781 extra_data_after_insn = true;
1783 extra_data = ex.X_add_number;
1786 if (fc > MAX_INSN_FIXUPS)
1787 as_fatal (_("too many fixups"));
1789 fixups[fc].exp = ex;
1790 fixups[fc].opindex = *opindex_ptr;
1791 fixups[fc].reloc = reloc;
1799 if ((operand->flags & V850_OPERAND_REG) != 0)
1801 if (!register_name (&ex))
1803 errmsg = _("invalid register name");
1805 else if ((operand->flags & V850_NOT_R0)
1806 && ex.X_add_number == 0)
1808 errmsg = _("register r0 cannot be used here");
1810 /* Force an error message to be generated by
1811 skipping over any following potential matches
1816 else if ((operand->flags & V850_OPERAND_SRG) != 0)
1818 if (!system_register_name (&ex, true, false))
1820 errmsg = _("invalid system register name");
1823 else if ((operand->flags & V850_OPERAND_EP) != 0)
1825 char *start = input_line_pointer;
1826 char c = get_symbol_end ();
1828 if (strcmp (start, "ep") != 0 && strcmp (start, "r30") != 0)
1830 /* Put things back the way we found them. */
1831 *input_line_pointer = c;
1832 input_line_pointer = start;
1833 errmsg = _("expected EP register");
1837 *input_line_pointer = c;
1838 str = input_line_pointer;
1839 input_line_pointer = hold;
1841 while (*str == ' ' || *str == ','
1842 || *str == '[' || *str == ']')
1846 else if ((operand->flags & V850_OPERAND_CC) != 0)
1850 errmsg = _("invalid condition code name");
1853 else if (operand->flags & V850E_PUSH_POP)
1855 errmsg = parse_register_list (&insn, operand);
1857 /* The parse_register_list() function has already done
1858 everything, so fake a dummy expression. */
1859 ex.X_op = O_constant;
1860 ex.X_add_number = 0;
1862 else if (operand->flags & V850E_IMMEDIATE16)
1866 if (ex.X_op != O_constant)
1867 errmsg = _("constant expression expected");
1868 else if (ex.X_add_number & 0xffff0000)
1870 if (ex.X_add_number & 0xffff)
1871 errmsg = _("constant too big to fit into instruction");
1872 else if ((insn & 0x001fffc0) == 0x00130780)
1873 ex.X_add_number >>= 16;
1875 errmsg = _("constant too big to fit into instruction");
1878 extra_data_after_insn = true;
1880 extra_data = ex.X_add_number;
1881 ex.X_add_number = 0;
1883 else if (operand->flags & V850E_IMMEDIATE32)
1887 if (ex.X_op != O_constant)
1888 errmsg = _("constant expression expected");
1890 extra_data_after_insn = true;
1892 extra_data = ex.X_add_number;
1893 ex.X_add_number = 0;
1895 else if (register_name (&ex)
1896 && (operand->flags & V850_OPERAND_REG) == 0)
1901 /* It is possible that an alias has been defined that
1902 matches a register name. For example the code may
1903 include a ".set ZERO, 0" directive, which matches
1904 the register name "zero". Attempt to reparse the
1905 field as an expression, and only complain if we
1906 cannot generate a constant. */
1908 input_line_pointer = str;
1910 c = get_symbol_end ();
1912 if (symbol_find (str) != NULL)
1915 *input_line_pointer = c;
1916 input_line_pointer = str;
1920 if (ex.X_op != O_constant)
1922 /* If this register is actually occuring too early on
1923 the parsing of the instruction, (because another
1924 field is missing) then report this. */
1925 if (opindex_ptr[1] != 0
1926 && (v850_operands[opindex_ptr[1]].flags
1927 & V850_OPERAND_REG))
1928 errmsg = _("syntax error: value is missing before the register name");
1930 errmsg = _("syntax error: register not expected");
1932 /* If we created a symbol in the process of this
1933 test then delete it now, so that it will not
1934 be output with the real symbols... */
1936 && ex.X_op == O_symbol)
1937 symbol_remove (ex.X_add_symbol,
1938 &symbol_rootP, &symbol_lastP);
1941 else if (system_register_name (&ex, false, false)
1942 && (operand->flags & V850_OPERAND_SRG) == 0)
1944 errmsg = _("syntax error: system register not expected");
1946 else if (cc_name (&ex)
1947 && (operand->flags & V850_OPERAND_CC) == 0)
1949 errmsg = _("syntax error: condition code not expected");
1955 If we are assembling a MOV instruction (or a CALLT.... :-)
1956 and the immediate value does not fit into the bits
1957 available then create a fake error so that the next MOV
1958 instruction will be selected. This one has a 32 bit
1961 if (((insn & 0x07e0) == 0x0200)
1962 && ex.X_op == O_constant
1963 && (ex.X_add_number < (-(1 << (operand->bits - 1)))
1964 || ex.X_add_number > ((1 << operand->bits) - 1)))
1965 errmsg = _("immediate operand is too large");
1973 " insn: %x, operand %d, op: %d, add_number: %d\n",
1974 insn, opindex_ptr - opcode->operands,
1975 ex.X_op, ex.X_add_number);
1981 errmsg = _("illegal operand");
1984 errmsg = _("missing operand");
1988 & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0)
1990 errmsg = _("invalid operand");
1993 insn = v850_insert_operand (insn, operand, ex.X_add_number,
1995 copy_of_instruction);
1999 insn = v850_insert_operand (insn, operand, ex.X_add_number,
2001 copy_of_instruction);
2005 /* We need to generate a fixup for this expression. */
2006 if (fc >= MAX_INSN_FIXUPS)
2007 as_fatal (_("too many fixups"));
2009 fixups[fc].exp = ex;
2010 fixups[fc].opindex = *opindex_ptr;
2011 fixups[fc].reloc = BFD_RELOC_UNUSED;
2017 str = input_line_pointer;
2018 input_line_pointer = hold;
2020 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']'
2029 next_opcode = opcode + 1;
2030 if (next_opcode->name != NULL
2031 && strcmp (next_opcode->name, opcode->name) == 0)
2033 opcode = next_opcode;
2035 /* Skip versions that are not supported by the target
2037 if ((opcode->processors & processor_mask) == 0)
2043 as_bad ("%s: %s", copy_of_instruction, errmsg);
2045 if (*input_line_pointer == ']')
2046 ++input_line_pointer;
2048 ignore_rest_of_line ();
2049 input_line_pointer = saved_input_line_pointer;
2055 while (ISSPACE (*str))
2059 /* xgettext:c-format */
2060 as_bad (_("junk at end of line: `%s'"), str);
2062 input_line_pointer = str;
2064 /* Tie dwarf2 debug info to the address at the start of the insn.
2065 We can't do this after the insn has been output as the current
2066 frag may have been closed off. eg. by frag_var. */
2067 dwarf2_emit_insn (0);
2069 /* Write out the instruction. */
2071 if (relaxable && fc > 0)
2076 if (!strcmp (opcode->name, "br"))
2078 f = frag_var (rs_machine_dependent, 4, 2, 2,
2079 fixups[0].exp.X_add_symbol,
2080 fixups[0].exp.X_add_number,
2081 (char *) fixups[0].opindex);
2082 md_number_to_chars (f, insn, insn_size);
2083 md_number_to_chars (f + 2, 0, 2);
2087 f = frag_var (rs_machine_dependent, 6, 4, 0,
2088 fixups[0].exp.X_add_symbol,
2089 fixups[0].exp.X_add_number,
2090 (char *) fixups[0].opindex);
2091 md_number_to_chars (f, insn, insn_size);
2092 md_number_to_chars (f + 2, 0, 4);
2097 /* Four byte insns have an opcode with the two high bits on. */
2098 if ((insn & 0x0600) == 0x0600)
2103 /* Special case: 32 bit MOV. */
2104 if ((insn & 0xffe0) == 0x0620)
2107 f = frag_more (insn_size);
2108 md_number_to_chars (f, insn, insn_size);
2110 if (extra_data_after_insn)
2112 f = frag_more (extra_data_len);
2113 md_number_to_chars (f, extra_data, extra_data_len);
2115 extra_data_after_insn = false;
2119 /* Create any fixups. At this point we do not use a
2120 bfd_reloc_code_real_type, but instead just use the
2121 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2122 handle fixups for any operand type, although that is admittedly
2123 not a very exciting feature. We pick a BFD reloc type in
2125 for (i = 0; i < fc; i++)
2127 const struct v850_operand *operand;
2128 bfd_reloc_code_real_type reloc;
2130 operand = &v850_operands[fixups[i].opindex];
2132 reloc = fixups[i].reloc;
2134 if (reloc != BFD_RELOC_UNUSED)
2136 reloc_howto_type *reloc_howto =
2137 bfd_reloc_type_lookup (stdoutput, reloc);
2145 size = bfd_get_reloc_size (reloc_howto);
2147 /* XXX This will abort on an R_V850_8 reloc -
2148 is this reloc actually used? */
2149 if (size != 2 && size != 4)
2152 address = (f - frag_now->fr_literal) + insn_size - size;
2154 if (reloc == BFD_RELOC_32)
2157 fixP = fix_new_exp (frag_now, address, size,
2159 reloc_howto->pc_relative,
2164 case BFD_RELOC_LO16:
2165 case BFD_RELOC_HI16:
2166 case BFD_RELOC_HI16_S:
2167 fixP->fx_no_overflow = 1;
2175 fix_new_exp (frag_now,
2176 f - frag_now->fr_literal, 4,
2178 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2179 (bfd_reloc_code_real_type) (fixups[i].opindex
2180 + (int) BFD_RELOC_UNUSED));
2184 input_line_pointer = saved_input_line_pointer;
2187 /* If while processing a fixup, a reloc really needs to be created
2188 then it is done here. */
2191 tc_gen_reloc (seg, fixp)
2192 asection *seg ATTRIBUTE_UNUSED;
2197 reloc = (arelent *) xmalloc (sizeof (arelent));
2198 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2199 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2200 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2201 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2203 if (reloc->howto == (reloc_howto_type *) NULL)
2205 as_bad_where (fixp->fx_file, fixp->fx_line,
2206 /* xgettext:c-format */
2207 _("reloc %d not supported by object file format"),
2208 (int) fixp->fx_r_type);
2215 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
2216 || fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT)
2217 reloc->addend = fixp->fx_offset;
2219 reloc->addend = fixp->fx_addnumber;
2224 /* Return current size of variable part of frag. */
2227 md_estimate_size_before_relax (fragp, seg)
2229 asection *seg ATTRIBUTE_UNUSED;
2231 if (fragp->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
2234 return md_relax_table[fragp->fr_subtype].rlx_length;
2238 v850_pcrel_from_section (fixp, section)
2242 /* If the symbol is undefined, or in a section other than our own,
2243 or it is weak (in which case it may well be in another section,
2244 then let the linker figure it out. */
2245 if (fixp->fx_addsy != (symbolS *) NULL
2246 && (! S_IS_DEFINED (fixp->fx_addsy)
2247 || S_IS_WEAK (fixp->fx_addsy)
2248 || (S_GET_SEGMENT (fixp->fx_addsy) != section)))
2251 return fixp->fx_frag->fr_address + fixp->fx_where;
2255 md_apply_fix3 (fixP, valueP, seg)
2258 segT seg ATTRIBUTE_UNUSED;
2260 valueT value = * valueP;
2263 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2264 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2270 if (fixP->fx_addsy == (symbolS *) NULL)
2273 else if (fixP->fx_pcrel)
2278 value = fixP->fx_offset;
2279 if (fixP->fx_subsy != (symbolS *) NULL)
2281 if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section)
2282 value -= S_GET_VALUE (fixP->fx_subsy);
2285 /* We don't actually support subtracting a symbol. */
2286 as_bad_where (fixP->fx_file, fixP->fx_line,
2287 _("expression too complex"));
2292 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
2295 const struct v850_operand *operand;
2298 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
2299 operand = &v850_operands[opindex];
2301 /* Fetch the instruction, insert the fully resolved operand
2302 value, and stuff the instruction back again.
2304 Note the instruction has been stored in little endian
2306 where = fixP->fx_frag->fr_literal + fixP->fx_where;
2308 insn = bfd_getl32 ((unsigned char *) where);
2309 insn = v850_insert_operand (insn, operand, (offsetT) value,
2310 fixP->fx_file, fixP->fx_line, NULL);
2311 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
2314 /* Nothing else to do here. */
2317 /* Determine a BFD reloc value based on the operand information.
2318 We are only prepared to turn a few of the operands into relocs. */
2320 if (operand->bits == 22)
2321 fixP->fx_r_type = BFD_RELOC_V850_22_PCREL;
2322 else if (operand->bits == 9)
2323 fixP->fx_r_type = BFD_RELOC_V850_9_PCREL;
2327 fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn);
2330 as_bad_where (fixP->fx_file, fixP->fx_line,
2331 _("unresolved expression that must be resolved"));
2336 else if (fixP->fx_done)
2338 /* We still have to insert the value into memory! */
2339 where = fixP->fx_frag->fr_literal + fixP->fx_where;
2341 if (fixP->fx_size == 1)
2342 *where = value & 0xff;
2343 else if (fixP->fx_size == 2)
2344 bfd_putl16 (value & 0xffff, (unsigned char *) where);
2345 else if (fixP->fx_size == 4)
2346 bfd_putl32 (value, (unsigned char *) where);
2349 fixP->fx_addnumber = value;
2352 /* Parse a cons expression. We have to handle hi(), lo(), etc
2356 parse_cons_expression_v850 (exp)
2359 /* See if there's a reloc prefix like hi() we have to handle. */
2360 hold_cons_reloc = v850_reloc_prefix (NULL);
2362 /* Do normal expression parsing. */
2366 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2367 found a reloc prefix, then we use that reloc, else we choose an
2368 appropriate one based on the size of the expression. */
2371 cons_fix_new_v850 (frag, where, size, exp)
2377 if (hold_cons_reloc == BFD_RELOC_UNUSED)
2380 hold_cons_reloc = BFD_RELOC_32;
2382 hold_cons_reloc = BFD_RELOC_16;
2384 hold_cons_reloc = BFD_RELOC_8;
2388 fix_new_exp (frag, where, size, exp, 0, hold_cons_reloc);
2390 fix_new (frag, where, size, NULL, 0, 0, hold_cons_reloc);
2392 hold_cons_reloc = BFD_RELOC_UNUSED;
2396 v850_fix_adjustable (fixP)
2399 if (fixP->fx_addsy == NULL)
2402 /* Prevent all adjustments to global symbols. */
2403 if (S_IS_EXTERN (fixP->fx_addsy))
2406 /* Similarly for weak symbols. */
2407 if (S_IS_WEAK (fixP->fx_addsy))
2410 /* Don't adjust function names. */
2411 if (S_IS_FUNCTION (fixP->fx_addsy))
2414 /* We need the symbol name for the VTABLE entries. */
2415 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2416 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2423 v850_force_relocation (fixP)
2426 if (fixP->fx_addsy && S_IS_WEAK (fixP->fx_addsy))
2429 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2430 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)