1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright (C) 1996, 1997 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "opcode/v850.h"
31 /* sign-extend a 16-bit number */
32 #define SEXT16(x) ((((x) & 0xffff) ^ (~ 0x7fff)) + 0x8000)
34 /* Temporarily holds the reloc in a cons expression. */
35 static bfd_reloc_code_real_type hold_cons_reloc;
37 /* Set to TRUE if we want to be pedantic about signed overflows. */
38 static boolean warn_signed_overflows = FALSE;
39 static boolean warn_unsigned_overflows = FALSE;
41 /* Indicates the target BFD machine number. */
42 static int machine = -1;
44 /* Indicates the target processor(s) for the assemble. */
45 static unsigned int processor_mask = -1;
48 /* Structure to hold information about predefined registers. */
55 /* Generic assembler global variables which must be defined by all targets. */
57 /* Characters which always start a comment. */
58 const char comment_chars[] = "#";
60 /* Characters which start a comment at the beginning of a line. */
61 const char line_comment_chars[] = ";#";
63 /* Characters which may be used to separate multiple commands on a
65 const char line_separator_chars[] = ";";
67 /* Characters which are used to indicate an exponent in a floating
69 const char EXP_CHARS[] = "eE";
71 /* Characters which mean that a number is a floating point constant,
73 const char FLT_CHARS[] = "dD";
76 const relax_typeS md_relax_table[] =
78 /* Conditional branches. */
80 {0x1fffff, -0x200000, 6, 0},
81 /* Unconditional branches. */
83 {0x1fffff, -0x200000, 4, 0},
87 static segT sdata_section = NULL;
88 static segT tdata_section = NULL;
89 static segT zdata_section = NULL;
90 static segT sbss_section = NULL;
91 static segT tbss_section = NULL;
92 static segT zbss_section = NULL;
93 static segT rosdata_section = NULL;
94 static segT rozdata_section = NULL;
95 static segT scommon_section = NULL;
96 static segT tcommon_section = NULL;
97 static segT zcommon_section = NULL;
98 /* start-sanitize-v850e */
99 static segT call_table_data_section = NULL;
100 static segT call_table_text_section = NULL;
101 /* end-sanitize-v850e */
104 /* local functions */
105 static unsigned long v850_insert_operand
106 PARAMS ((unsigned long insn, const struct v850_operand *operand,
107 offsetT val, char *file, unsigned int line));
111 #define MAX_INSN_FIXUPS (5)
116 bfd_reloc_code_real_type reloc;
118 struct v850_fixup fixups[MAX_INSN_FIXUPS];
122 v850_sdata (int ignore)
124 obj_elf_section_change_hook();
126 subseg_set (sdata_section, (subsegT) get_absolute_expression ());
128 demand_empty_rest_of_line ();
132 v850_tdata (int ignore)
134 obj_elf_section_change_hook();
136 subseg_set (tdata_section, (subsegT) get_absolute_expression ());
138 demand_empty_rest_of_line ();
142 v850_zdata (int ignore)
144 obj_elf_section_change_hook();
146 subseg_set (zdata_section, (subsegT) get_absolute_expression ());
148 demand_empty_rest_of_line ();
152 v850_sbss (int ignore)
154 obj_elf_section_change_hook();
156 subseg_set (sbss_section, (subsegT) get_absolute_expression ());
158 demand_empty_rest_of_line ();
162 v850_tbss (int ignore)
164 obj_elf_section_change_hook();
166 subseg_set (tbss_section, (subsegT) get_absolute_expression ());
168 demand_empty_rest_of_line ();
172 v850_zbss (int ignore)
174 obj_elf_section_change_hook();
176 subseg_set (zbss_section, (subsegT) get_absolute_expression ());
178 demand_empty_rest_of_line ();
182 v850_rosdata (int ignore)
184 obj_elf_section_change_hook();
186 subseg_set (rosdata_section, (subsegT) get_absolute_expression ());
188 demand_empty_rest_of_line ();
192 v850_rozdata (int ignore)
194 obj_elf_section_change_hook();
196 subseg_set (rozdata_section, (subsegT) get_absolute_expression ());
198 demand_empty_rest_of_line ();
201 /* start-sanitize-v850e */
203 v850_call_table_data (int ignore)
205 obj_elf_section_change_hook();
207 subseg_set (call_table_data_section, (subsegT) get_absolute_expression ());
209 demand_empty_rest_of_line ();
213 v850_call_table_text (int ignore)
215 obj_elf_section_change_hook();
217 subseg_set (call_table_text_section, (subsegT) get_absolute_expression ());
219 demand_empty_rest_of_line ();
221 /* end-sanitize-v850e */
224 v850_bss (int ignore)
226 register int temp = get_absolute_expression ();
228 obj_elf_section_change_hook();
230 subseg_set (bss_section, (subsegT) temp);
232 demand_empty_rest_of_line ();
236 v850_offset (int ignore)
238 int temp = get_absolute_expression ();
240 temp -= frag_now_fix();
243 (void) frag_more (temp);
245 demand_empty_rest_of_line ();
248 /* Copied from obj_elf_common() in gas/config/obj-elf.c */
261 name = input_line_pointer;
262 c = get_symbol_end ();
263 /* just after name is now '\0' */
264 p = input_line_pointer;
267 if (*input_line_pointer != ',')
269 as_bad ("Expected comma after symbol-name");
270 ignore_rest_of_line ();
273 input_line_pointer++; /* skip ',' */
274 if ((temp = get_absolute_expression ()) < 0)
276 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
277 ignore_rest_of_line ();
282 symbolP = symbol_find_or_make (name);
284 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
286 as_bad ("Ignoring attempt to re-define symbol");
287 ignore_rest_of_line ();
290 if (S_GET_VALUE (symbolP) != 0)
292 if (S_GET_VALUE (symbolP) != size)
294 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
295 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
298 know (symbolP->sy_frag == &zero_address_frag);
299 if (*input_line_pointer != ',')
304 input_line_pointer++;
307 if (! have_align || *input_line_pointer != '"')
313 temp = get_absolute_expression ();
317 as_warn ("Common alignment negative; 0 assumed");
329 old_subsec = now_subseg;
332 /* convert to a power of 2 alignment */
333 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
336 as_bad ("Common alignment not a power of 2");
337 ignore_rest_of_line ();
346 record_alignment (sbss_section, align);
347 obj_elf_section_change_hook();
348 subseg_set (sbss_section, 0);
352 record_alignment (zbss_section, align);
353 obj_elf_section_change_hook();
354 subseg_set (zbss_section, 0);
358 record_alignment (tbss_section, align);
359 obj_elf_section_change_hook();
360 subseg_set (tbss_section, 0);
368 frag_align (align, 0, 0);
373 if (S_GET_SEGMENT (symbolP) == sbss_section)
374 symbolP->sy_frag->fr_symbol = 0;
378 if (S_GET_SEGMENT (symbolP) == zbss_section)
379 symbolP->sy_frag->fr_symbol = 0;
383 if (S_GET_SEGMENT (symbolP) == tbss_section)
384 symbolP->sy_frag->fr_symbol = 0;
391 symbolP->sy_frag = frag_now;
392 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
393 (offsetT) size, (char *) 0);
395 S_SET_SIZE (symbolP, size);
399 case AREA_SDA: S_SET_SEGMENT (symbolP, sbss_section); break;
400 case AREA_ZDA: S_SET_SEGMENT (symbolP, zbss_section); break;
401 case AREA_TDA: S_SET_SEGMENT (symbolP, tbss_section); break;
406 S_CLEAR_EXTERNAL (symbolP);
407 obj_elf_section_change_hook();
408 subseg_set (old_sec, old_subsec);
413 S_SET_VALUE (symbolP, (valueT) size);
414 S_SET_ALIGN (symbolP, temp);
415 S_SET_EXTERNAL (symbolP);
419 case AREA_SDA: S_SET_SEGMENT (symbolP, scommon_section); break;
420 case AREA_ZDA: S_SET_SEGMENT (symbolP, zcommon_section); break;
421 case AREA_TDA: S_SET_SEGMENT (symbolP, tcommon_section); break;
429 input_line_pointer++;
430 /* @@ Some use the dot, some don't. Can we get some consistency?? */
431 if (*input_line_pointer == '.')
432 input_line_pointer++;
433 /* @@ Some say data, some say bss. */
434 if (strncmp (input_line_pointer, "bss\"", 4)
435 && strncmp (input_line_pointer, "data\"", 5))
437 while (*--input_line_pointer != '"')
439 input_line_pointer--;
440 goto bad_common_segment;
442 while (*input_line_pointer++ != '"')
444 goto allocate_common;
447 symbolP->bsym->flags |= BSF_OBJECT;
449 demand_empty_rest_of_line ();
454 p = input_line_pointer;
455 while (*p && *p != '\n')
459 as_bad ("bad .common segment %s", input_line_pointer + 1);
461 input_line_pointer = p;
462 ignore_rest_of_line ();
468 set_machine (int number)
471 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
475 case 0: processor_mask = PROCESSOR_V850; break;
476 /* start-sanitize-v850e */
477 case bfd_mach_v850e: processor_mask = PROCESSOR_V850E; break;
478 case bfd_mach_v850eq: processor_mask = PROCESSOR_V850EQ; break;
479 /* end-sanitize-v850e */
483 /* The target specific pseudo-ops which we support. */
484 const pseudo_typeS md_pseudo_table[] =
486 {"sdata", v850_sdata, 0},
487 {"tdata", v850_tdata, 0},
488 {"zdata", v850_zdata, 0},
489 {"sbss", v850_sbss, 0},
490 {"tbss", v850_tbss, 0},
491 {"zbss", v850_zbss, 0},
492 {"rosdata", v850_rosdata, 0},
493 {"rozdata", v850_rozdata, 0},
494 {"bss", v850_bss, 0},
495 {"offset", v850_offset, 0},
497 {"zcomm", v850_comm, AREA_ZDA},
498 {"scomm", v850_comm, AREA_SDA},
499 {"tcomm", v850_comm, AREA_TDA},
500 {"v850", set_machine, 0},
501 /* start-sanitize-v850e */
502 {"call_table_data", v850_call_table_data, 0},
503 {"call_table_text", v850_call_table_text, 0},
504 {"v850e", set_machine, bfd_mach_v850e},
505 {"v850eq", set_machine, bfd_mach_v850eq},
506 /* end-sanitize-v850e */
510 /* Opcode hash table. */
511 static struct hash_control *v850_hash;
513 /* This table is sorted. Suitable for searching by a binary search. */
514 static const struct reg_name pre_defined_registers[] =
516 { "ep", 30 }, /* ep - element ptr */
517 { "gp", 4 }, /* gp - global ptr */
518 { "hp", 2 }, /* hp - handler stack ptr */
519 { "lp", 31 }, /* lp - link ptr */
552 { "sp", 3 }, /* sp - stack ptr */
553 { "tp", 5 }, /* tp - text ptr */
556 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
559 static const struct reg_name system_registers[] =
561 /* start-sanitize-v850e */
567 /* end-sanitize-v850e */
575 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
577 /* start-sanitize-v850e */
578 static const struct reg_name system_list_registers[] =
583 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
584 /* end-sanitize-v850e */
586 static const struct reg_name cc_names[] =
611 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
613 /* reg_name_search does a binary search of the given register table
614 to see if "name" is a valid regiter name. Returns the register
615 number from the array on success, or -1 on failure. */
618 reg_name_search (regs, regcount, name, accept_numbers)
619 const struct reg_name * regs;
622 boolean accept_numbers;
624 int middle, low, high;
628 /* If the register name is a symbol, then evaluate it. */
629 if ((symbolP = symbol_find (name)) != NULL)
631 /* If the symbol is an alias for another name then use that.
632 If the symbol is an alias for a number, then return the number. */
633 if (symbolP->sy_value.X_op == O_symbol)
635 name = S_GET_NAME (symbolP->sy_value.X_add_symbol);
637 else if (accept_numbers)
639 int reg = S_GET_VALUE (symbolP);
641 if (reg >= 0 && reg <= 31)
651 middle = (low + high) / 2;
652 cmp = strcasecmp (name, regs[middle].name);
658 return regs[middle].value;
665 /* Summary of register_name().
667 * in: Input_line_pointer points to 1st char of operand.
669 * out: A expressionS.
670 * The operand may have been a register: in this case, X_op == O_register,
671 * X_add_number is set to the register number, and truth is returned.
672 * Input_line_pointer->(next non-blank) char after operand, or is in
673 * its original state.
676 register_name (expressionP)
677 expressionS * expressionP;
684 /* Find the spelling of the operand */
685 start = name = input_line_pointer;
687 c = get_symbol_end ();
689 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name, FALSE);
691 * input_line_pointer = c; /* put back the delimiting char */
693 /* look to see if it's in the register table */
696 expressionP->X_op = O_register;
697 expressionP->X_add_number = reg_number;
699 /* make the rest nice */
700 expressionP->X_add_symbol = NULL;
701 expressionP->X_op_symbol = NULL;
707 /* reset the line as if we had not done anything */
708 input_line_pointer = start;
714 /* Summary of system_register_name().
716 * in: Input_line_pointer points to 1st char of operand.
717 * expressionP points to an expression structure to be filled in.
718 * accept_numbers is true iff numerical register names may be used.
719 * start-sanitize-v850e
720 * accept_list_names is true iff the special names PS and SR may be
722 * end-sanitize-v850eq
724 * out: A expressionS structure in expressionP.
725 * The operand may have been a register: in this case, X_op == O_register,
726 * X_add_number is set to the register number, and truth is returned.
727 * Input_line_pointer->(next non-blank) char after operand, or is in
728 * its original state.
731 system_register_name (expressionP, accept_numbers
732 /* start-sanitize-v850e */
734 /* end-sanitize-v850e */
736 expressionS * expressionP;
737 boolean accept_numbers;
738 /* start-sanitize-v850e */
739 boolean accept_list_names;
740 /* end-sanitize-v850e */
747 /* Find the spelling of the operand */
748 start = name = input_line_pointer;
750 c = get_symbol_end ();
751 reg_number = reg_name_search (system_registers, SYSREG_NAME_CNT, name, accept_numbers);
753 * input_line_pointer = c; /* put back the delimiting char */
758 input_line_pointer = start; /* reset input_line pointer */
760 if (isdigit (* input_line_pointer))
762 reg_number = strtol (input_line_pointer, & input_line_pointer, 10);
764 /* Make sure that the register number is allowable. */
767 /* start-sanitize-v850e */
770 /* end-sanitize-v850e */
776 /* start-sanitize-v850e */
777 else if (accept_list_names)
779 c = get_symbol_end ();
780 reg_number = reg_name_search (system_list_registers, SYSREGLIST_NAME_CNT, name, FALSE);
782 * input_line_pointer = c; /* put back the delimiting char */
784 /* end-sanitize-v850e */
787 /* look to see if it's in the register table */
790 expressionP->X_op = O_register;
791 expressionP->X_add_number = reg_number;
793 /* make the rest nice */
794 expressionP->X_add_symbol = NULL;
795 expressionP->X_op_symbol = NULL;
801 /* reset the line as if we had not done anything */
802 input_line_pointer = start;
808 /* Summary of cc_name().
810 * in: Input_line_pointer points to 1st char of operand.
812 * out: A expressionS.
813 * The operand may have been a register: in this case, X_op == O_register,
814 * X_add_number is set to the register number, and truth is returned.
815 * Input_line_pointer->(next non-blank) char after operand, or is in
816 * its original state.
819 cc_name (expressionP)
820 expressionS * expressionP;
827 /* Find the spelling of the operand */
828 start = name = input_line_pointer;
830 c = get_symbol_end ();
831 reg_number = reg_name_search (cc_names, CC_NAME_CNT, name, FALSE);
833 * input_line_pointer = c; /* put back the delimiting char */
835 /* look to see if it's in the register table */
838 expressionP->X_op = O_constant;
839 expressionP->X_add_number = reg_number;
841 /* make the rest nice */
842 expressionP->X_add_symbol = NULL;
843 expressionP->X_op_symbol = NULL;
849 /* reset the line as if we had not done anything */
850 input_line_pointer = start;
857 skip_white_space (void)
859 while ( * input_line_pointer == ' '
860 || * input_line_pointer == '\t')
861 ++ input_line_pointer;
864 /* start-sanitize-v850e */
865 /* Summary of parse_register_list ().
867 * in: Input_line_pointer points to 1st char of a list of registers.
868 * insn is the partially constructed instruction.
869 * operand is the operand being inserted.
871 * out: NULL if the parse completed successfully, otherwise a
872 * pointer to an error message is returned. If the parse
873 * completes the correct bit fields in the instruction
876 * Parses register lists with the syntax:
884 * and also parses constant epxressions whoes bits indicate the
885 * registers in the lists. The LSB in the expression refers to
886 * the lowest numbered permissable register in the register list,
887 * and so on upwards. System registers are considered to be very
894 unsigned long * insn,
895 const struct v850_operand * operand
898 static int type1_regs[ 32 ] = { 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
899 static int type2_regs[ 32 ] = { 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
900 static int type3_regs[ 32 ] = { 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8 };
905 /* Select a register array to parse. */
906 switch (operand->shift)
908 case 0xffe00001: regs = type1_regs; break;
909 case 0xfff8000f: regs = type2_regs; break;
910 case 0xfff8001f: regs = type3_regs; break;
912 as_bad ("unknown operand shift: %x\n", operand->shift );
913 return "internal failure in parse_register_list";
918 /* If the expression starts with a curly brace it is a register list.
919 Otherwise it is a constant expression, whoes bits indicate which
920 registers are to be included in the list. */
922 if (* input_line_pointer != '{')
930 if (exp.X_op != O_constant)
931 return "constant expression or register list expected";
933 if (regs == type1_regs)
935 if (exp.X_add_number & 0xFFFFF000)
936 return "high bits set in register list expression";
938 for (reg = 20; reg < 32; reg ++)
939 if (exp.X_add_number & (1 << (reg - 20)))
941 for (i = 0; i < 32; i++)
946 else if (regs == type2_regs)
948 if (exp.X_add_number & 0xFFFE0000)
949 return "high bits set in register list expression";
951 for (reg = 1; reg < 16; reg ++)
952 if (exp.X_add_number & (1 << (reg - 1)))
954 for (i = 0; i < 32; i++)
959 if (exp.X_add_number & (1 << 15))
962 if (exp.X_add_number & (1 << 16))
965 else /* regs == type3_regs */
967 if (exp.X_add_number & 0xFFFE0000)
968 return "high bits set in register list expression";
970 for (reg = 16; reg < 32; reg ++)
971 if (exp.X_add_number & (1 << (reg - 16)))
973 for (i = 0; i < 32; i++)
978 if (exp.X_add_number & (1 << 16))
985 input_line_pointer ++;
987 /* Parse the register list until a terminator (closing curly brace or new-line) is found. */
990 if (register_name (& exp))
994 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
995 for (i = 0; i < 32; i++)
997 if (regs[ i ] == exp.X_add_number)
1006 return "illegal register included in list";
1009 else if (system_register_name (& exp, true, true))
1011 if (regs == type1_regs)
1013 return "system registers cannot be included in list";
1015 else if (exp.X_add_number == 5)
1017 if (regs == type2_regs)
1018 return "PSW cannot be included in list";
1022 else if (exp.X_add_number < 4)
1025 return "High value system registers cannot be included in list";
1027 else if (* input_line_pointer == '}')
1029 input_line_pointer ++;
1032 else if (* input_line_pointer == ',')
1034 input_line_pointer ++;
1037 else if (* input_line_pointer == '-')
1039 /* We have encountered a range of registers: rX - rY */
1043 /* Skip the dash. */
1044 ++ input_line_pointer;
1046 /* Get the second register in the range. */
1047 if (! register_name (& exp2))
1049 return "second register should follow dash in register list";
1050 exp2.X_add_number = exp.X_add_number;
1053 /* Add the rest of the registers in the range. */
1054 for (j = exp.X_add_number + 1; j <= exp2.X_add_number; j++)
1058 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
1059 for (i = 0; i < 32; i++)
1070 return "illegal register included in list";
1084 /* end-sanitize-v850e */
1086 CONST char * md_shortopts = "m:";
1088 struct option md_longopts[] =
1090 {NULL, no_argument, NULL, 0}
1092 size_t md_longopts_size = sizeof md_longopts;
1096 md_show_usage (stream)
1099 fprintf (stream, "V850 options:\n");
1100 fprintf (stream, "\t-mwarn_signed_overflow Warn if signed immediate values overflow\n");
1101 fprintf (stream, "\t-mwarn_unsigned_overflow Warn if unsigned immediate values overflow\n");
1102 fprintf (stream, "\t-mv850 The code is targeted at the v850\n");
1103 /* start-sanitize-v850e */
1104 fprintf (stream, "\t-mv850e The code is targeted at the v850e\n");
1105 fprintf (stream, "\t-mv850eq The code is targeted at the v850eq\n");
1106 /* end-sanitize-v850e */
1110 md_parse_option (c, arg)
1117 if (strcmp (arg, "warn_signed_overflow") == 0)
1119 warn_signed_overflows = TRUE;
1121 else if (strcmp (arg, "warn_unsigned_overflow") == 0)
1123 warn_unsigned_overflows = TRUE;
1125 else if (strcmp (arg, "v850") == 0)
1128 processor_mask = PROCESSOR_V850;
1130 /* start-sanitize-v850e */
1131 else if (strcmp (arg, "v850e") == 0)
1133 machine = bfd_mach_v850e;
1134 processor_mask = PROCESSOR_V850E;
1136 else if (strcmp (arg, "v850eq") == 0)
1138 machine = bfd_mach_v850eq;
1139 processor_mask = PROCESSOR_V850EQ;
1141 /* end-sanitize-v850e */
1149 md_undefined_symbol (name)
1156 md_atof (type, litp, sizep)
1162 LITTLENUM_TYPE words[4];
1178 return "bad call to md_atof";
1181 t = atof_ieee (input_line_pointer, type, words);
1183 input_line_pointer = t;
1187 for (i = prec - 1; i >= 0; i--)
1189 md_number_to_chars (litp, (valueT) words[i], 2);
1199 md_convert_frag (abfd, sec, fragP)
1204 subseg_change (sec, 0);
1206 /* In range conditional or unconditional branch. */
1207 if (fragP->fr_subtype == 0 || fragP->fr_subtype == 2)
1209 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
1210 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode);
1214 /* Out of range conditional branch. Emit a branch around a jump. */
1215 else if (fragP->fr_subtype == 1)
1217 unsigned char *buffer =
1218 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1220 /* Reverse the condition of the first branch. */
1222 /* Mask off all the displacement bits. */
1225 /* Now set the displacement bits so that we branch
1226 around the unconditional branch. */
1229 /* Now create the unconditional branch + fixup to the final
1231 md_number_to_chars (buffer + 2, 0x00000780, 4);
1232 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
1233 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode + 1);
1237 /* Out of range unconditional branch. Emit a jump. */
1238 else if (fragP->fr_subtype == 3)
1240 md_number_to_chars (fragP->fr_fix + fragP->fr_literal, 0x00000780, 4);
1241 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
1242 fragP->fr_offset, 1, BFD_RELOC_UNUSED + (int)fragP->fr_opcode + 1);
1251 md_section_align (seg, addr)
1255 int align = bfd_get_section_alignment (stdoutput, seg);
1256 return ((addr + (1 << align) - 1) & (-1 << align));
1262 char * prev_name = "";
1263 register const struct v850_opcode * op;
1264 flagword applicable;
1266 /* start-sanitize-v850e */
1267 if (strncmp (TARGET_CPU, "v850eq", 6) == 0)
1270 machine = bfd_mach_v850eq;
1272 if (processor_mask == -1)
1273 processor_mask = PROCESSOR_V850EQ;
1275 else if (strncmp (TARGET_CPU, "v850e", 5) == 0)
1278 machine = bfd_mach_v850e;
1280 if (processor_mask == -1)
1281 processor_mask = PROCESSOR_V850E;
1284 /* end-sanitize-v850e */
1285 if (strncmp (TARGET_CPU, "v850", 4) == 0)
1290 if (processor_mask == -1)
1291 processor_mask = PROCESSOR_V850;
1294 as_bad ("Unable to determine default target processor from string: %s",
1297 v850_hash = hash_new();
1299 /* Insert unique names into hash table. The V850 instruction set
1300 has many identical opcode names that have different opcodes based
1301 on the operands. This hash table then provides a quick index to
1302 the first opcode with a particular name in the opcode table. */
1307 if (strcmp (prev_name, op->name))
1309 prev_name = (char *) op->name;
1310 hash_insert (v850_hash, op->name, (char *) op);
1315 bfd_set_arch_mach (stdoutput, TARGET_ARCH, machine);
1317 applicable = bfd_applicable_section_flags (stdoutput);
1319 sdata_section = subseg_new (".sdata", 0);
1320 bfd_set_section_flags (stdoutput, sdata_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS));
1322 tdata_section = subseg_new (".tdata", 0);
1323 bfd_set_section_flags (stdoutput, tdata_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS));
1325 zdata_section = subseg_new (".zdata", 0);
1326 bfd_set_section_flags (stdoutput, zdata_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS));
1328 sbss_section = subseg_new (".sbss", 0);
1329 bfd_set_section_flags (stdoutput, sbss_section, applicable & SEC_ALLOC);
1330 seg_info (sbss_section)->bss = 1;
1332 tbss_section = subseg_new (".tbss", 0);
1333 bfd_set_section_flags (stdoutput, tbss_section, applicable & SEC_ALLOC);
1334 seg_info (tbss_section)->bss = 1;
1336 zbss_section = subseg_new (".zbss", 0);
1337 bfd_set_section_flags (stdoutput, zbss_section, applicable & SEC_ALLOC);
1338 seg_info (zbss_section)->bss = 1;
1340 rosdata_section = subseg_new (".rosdata", 0);
1341 bfd_set_section_flags (stdoutput, rosdata_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY));
1343 rozdata_section = subseg_new (".rozdata", 0);
1344 bfd_set_section_flags (stdoutput, rozdata_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY));
1346 scommon_section = subseg_new (".scommon", 0);
1347 bfd_set_section_flags (stdoutput, scommon_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS | SEC_IS_COMMON));
1349 zcommon_section = subseg_new (".zcommon", 0);
1350 bfd_set_section_flags (stdoutput, zcommon_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS | SEC_IS_COMMON));
1352 tcommon_section = subseg_new (".tcommon", 0);
1353 bfd_set_section_flags (stdoutput, tcommon_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS | SEC_IS_COMMON));
1355 /* start-sanitize-v850e */
1356 call_table_data_section = subseg_new (".call_table_data", 0);
1357 bfd_set_section_flags (stdoutput, call_table_data_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA | SEC_HAS_CONTENTS));
1359 call_table_text_section = subseg_new (".call_table_text", 0);
1360 bfd_set_section_flags (stdoutput, call_table_text_section, applicable & (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE));
1361 /* end-sanitize-v850e */
1365 /* start-sanitize-v850e */
1366 static bfd_reloc_code_real_type
1367 handle_ctoff (const struct v850_operand * operand)
1369 if (operand == NULL)
1370 return BFD_RELOC_V850_CALLT_16_16_OFFSET;
1372 if ( operand->bits != 6
1373 || operand->shift != 0)
1375 as_bad ("ctoff() relocation used on an instruction which does not support it");
1376 return BFD_RELOC_64; /* Used to indicate an error condition. */
1379 return BFD_RELOC_V850_CALLT_6_7_OFFSET;
1381 /* end-sanitize-v850e */
1383 static bfd_reloc_code_real_type
1384 handle_sdaoff (const struct v850_operand * operand)
1386 if (operand == NULL) return BFD_RELOC_V850_SDA_16_16_OFFSET;
1387 if (operand->bits == 15 && operand->shift == 17) return BFD_RELOC_V850_SDA_15_16_OFFSET;
1388 /* start-sanitize-v850e */
1389 if (operand->bits == -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET;
1390 /* end-sanitize-v850e */
1392 if ( operand->bits != 16
1393 || operand->shift != 16)
1395 as_bad ("sdaoff() relocation used on an instruction which does not support it");
1396 return BFD_RELOC_64; /* Used to indicate an error condition. */
1399 return BFD_RELOC_V850_SDA_16_16_OFFSET;
1402 static bfd_reloc_code_real_type
1403 handle_zdaoff (const struct v850_operand * operand)
1405 if (operand == NULL) return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1406 if (operand->bits == 15 && operand->shift == 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET;
1407 /* start-sanitize-v850e */
1408 if (operand->bits == -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET;
1409 /* end-sanitize-v850e */
1411 if ( operand->bits != 16
1412 || operand->shift != 16)
1414 as_bad ("zdaoff() relocation used on an instruction which does not support it");
1415 return BFD_RELOC_64; /* Used to indicate an error condition. */
1418 return BFD_RELOC_V850_ZDA_16_16_OFFSET;
1421 static bfd_reloc_code_real_type
1422 handle_tdaoff (const struct v850_operand * operand)
1424 if (operand == NULL) return BFD_RELOC_V850_TDA_7_7_OFFSET; /* data item, not an instruction. */
1425 if (operand->bits == 6 && operand->shift == 1) return BFD_RELOC_V850_TDA_6_8_OFFSET; /* sld.w/sst.w, operand: D8_6 */
1426 /* start-sanitize-v850e */
1427 if (operand->bits == 4 && operand->insert != NULL) return BFD_RELOC_V850_TDA_4_5_OFFSET; /* sld.hu, operand: D5-4 */
1428 if (operand->bits == 4 && operand->insert == NULL) return BFD_RELOC_V850_TDA_4_4_OFFSET; /* sld.bu, operand: D4 */
1429 /* end-sanitize-v850e */
1430 if (operand->bits == 16 && operand->shift == 16) return BFD_RELOC_V850_TDA_16_16_OFFSET; /* set1 & chums, operands: D16 */
1432 if (operand->bits != 7)
1434 as_bad ("tdaoff() relocation used on an instruction which does not support it");
1435 return BFD_RELOC_64; /* Used to indicate an error condition. */
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
1448 v850_reloc_prefix (const struct v850_operand * operand)
1450 boolean paren_skipped = false;
1453 /* Skip leading opening parenthesis. */
1454 if (* input_line_pointer == '(')
1456 ++ input_line_pointer;
1457 paren_skipped = true;
1460 #define CHECK_(name, reloc) \
1461 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1463 input_line_pointer += strlen (name); \
1467 CHECK_ ("hi0", BFD_RELOC_HI16);
1468 CHECK_ ("hi", BFD_RELOC_HI16_S);
1469 CHECK_ ("lo", BFD_RELOC_LO16);
1470 CHECK_ ("sdaoff", handle_sdaoff (operand));
1471 CHECK_ ("zdaoff", handle_zdaoff (operand));
1472 CHECK_ ("tdaoff", handle_tdaoff (operand));
1474 /* start-sanitize-v850e */
1475 CHECK_ ("hilo", BFD_RELOC_32);
1476 CHECK_ ("ctoff", handle_ctoff (operand));
1477 /* end-sanitize-v850e */
1479 /* Restore skipped parenthesis. */
1481 -- input_line_pointer;
1483 return BFD_RELOC_UNUSED;
1491 char * start_of_operands;
1492 struct v850_opcode * opcode;
1493 struct v850_opcode * next_opcode;
1494 const unsigned char * opindex_ptr;
1498 unsigned long insn_size;
1502 boolean extra_data_after_insn = false;
1503 unsigned extra_data_len;
1504 unsigned long extra_data;
1505 char * saved_input_line_pointer;
1507 /* Get the opcode. */
1508 for (s = str; *s != '\0' && ! isspace (*s); s++)
1514 /* find the first opcode with the proper name */
1515 opcode = (struct v850_opcode *)hash_find (v850_hash, str);
1518 as_bad ("Unrecognized opcode: `%s'", str);
1519 ignore_rest_of_line ();
1524 while (isspace (* str))
1527 start_of_operands = str;
1529 saved_input_line_pointer = input_line_pointer;
1533 const char * errmsg = NULL;
1537 if ((opcode->processors & processor_mask) == 0)
1539 errmsg = "Target processor does not support this instruction.";
1546 insn = opcode->opcode;
1547 extra_data_after_insn = false;
1549 input_line_pointer = str = start_of_operands;
1551 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1553 const struct v850_operand * operand;
1556 bfd_reloc_code_real_type reloc;
1558 if (next_opindex == 0)
1560 operand = & v850_operands[ * opindex_ptr ];
1564 operand = & v850_operands[ next_opindex ];
1570 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1573 if (operand->flags & V850_OPERAND_RELAX)
1576 /* Gather the operand. */
1577 hold = input_line_pointer;
1578 input_line_pointer = str;
1580 /* lo(), hi(), hi0(), etc... */
1581 if ((reloc = v850_reloc_prefix (operand)) != BFD_RELOC_UNUSED)
1583 if (reloc == BFD_RELOC_64) /* This is a fake reloc, used to indicate an error condition. */
1591 if (ex.X_op == O_constant)
1595 case BFD_RELOC_V850_ZDA_16_16_OFFSET:
1596 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]" and the like. */
1599 case BFD_RELOC_LO16:
1601 /* Truncate, then sign extend the value. */
1602 ex.X_add_number = SEXT16 (ex.X_add_number);
1606 case BFD_RELOC_HI16:
1608 /* Truncate, then sign extend the value. */
1609 ex.X_add_number = SEXT16 (ex.X_add_number >> 16);
1613 case BFD_RELOC_HI16_S:
1615 /* Truncate, then sign extend the value. */
1616 int temp = (ex.X_add_number >> 16) & 0xffff;
1618 temp += (ex.X_add_number >> 15) & 1;
1620 ex.X_add_number = SEXT16 (temp);
1624 /* start-sanitize-v850e */
1626 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1628 errmsg = "use bigger instruction";
1632 extra_data_after_insn = true;
1634 extra_data = ex.X_add_number;
1635 ex.X_add_number = 0;
1637 /* end-sanitize-v850e */
1640 fprintf (stderr, "reloc: %d\n", reloc);
1641 as_bad ("AAARG -> unhandled constant reloc");
1645 insn = v850_insert_operand (insn, operand, ex.X_add_number,
1650 /* start-sanitize-v850e */
1651 if (reloc == BFD_RELOC_32)
1653 if ((operand->flags & V850E_IMMEDIATE32) == 0)
1655 errmsg = "use bigger instruction";
1659 extra_data_after_insn = true;
1661 extra_data = ex.X_add_number;
1662 ex.X_add_number = 0;
1664 /* end-sanitize-v850e */
1666 if (fc > MAX_INSN_FIXUPS)
1667 as_fatal ("too many fixups");
1669 fixups[ fc ].exp = ex;
1670 fixups[ fc ].opindex = * opindex_ptr;
1671 fixups[ fc ].reloc = reloc;
1679 if ((operand->flags & V850_OPERAND_REG) != 0)
1681 if (!register_name (& ex))
1683 errmsg = "invalid register name";
1686 if ((operand->flags & V850_NOT_R0)
1687 && ex.X_add_number == 0)
1689 errmsg = "register r0 cannot be used here";
1692 else if ((operand->flags & V850_OPERAND_SRG) != 0)
1694 if (!system_register_name (& ex, true
1695 /* start-sanitize-v850e */
1697 /* end-sanitize-v850e */
1700 errmsg = "invalid system register name";
1703 else if ((operand->flags & V850_OPERAND_EP) != 0)
1705 char * start = input_line_pointer;
1706 char c = get_symbol_end ();
1708 if (strcmp (start, "ep") != 0 && strcmp (start, "r30") != 0)
1710 /* Put things back the way we found them. */
1711 *input_line_pointer = c;
1712 input_line_pointer = start;
1713 errmsg = "expected EP register";
1717 *input_line_pointer = c;
1718 str = input_line_pointer;
1719 input_line_pointer = hold;
1721 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']')
1725 else if ((operand->flags & V850_OPERAND_CC) != 0)
1727 if (!cc_name (& ex))
1729 errmsg = "invalid condition code name";
1732 /* start-sanitize-v850e */
1733 else if (operand->flags & V850E_PUSH_POP)
1735 errmsg = parse_register_list (& insn, operand);
1737 /* The parse_register_list() function has already done everything, so fake a dummy expression. */
1738 ex.X_op = O_constant;
1739 ex.X_add_number = 0;
1741 else if (operand->flags & V850E_IMMEDIATE16)
1745 if (ex.X_op != O_constant)
1746 errmsg = "constant expression expected";
1747 else if (ex.X_add_number & 0xffff0000)
1749 if (ex.X_add_number & 0xffff)
1750 errmsg = "constant too big to fit into instruction";
1751 else if ((insn & 0x001fffc0) == 0x00130780)
1752 ex.X_add_number >>= 16;
1754 errmsg = "constant too big to fit into instruction";
1757 extra_data_after_insn = true;
1759 extra_data = ex.X_add_number;
1760 ex.X_add_number = 0;
1762 else if (operand->flags & V850E_IMMEDIATE32)
1766 if (ex.X_op != O_constant)
1767 errmsg = "constant expression expected";
1769 extra_data_after_insn = true;
1771 extra_data = ex.X_add_number;
1772 ex.X_add_number = 0;
1774 /* end-sanitize-v850e */
1775 else if (register_name (& ex)
1776 && (operand->flags & V850_OPERAND_REG) == 0)
1778 /* It is possible that an alias has been defined that
1779 matches a register name. For example the code may
1780 include a ".set ZERO, 0" directive, which matches
1781 the register name "zero". Attempt to reparse the
1782 field as an expression, and only complain if we
1783 cannot generate a constant. */
1785 input_line_pointer = str;
1789 if (ex.X_op != O_constant)
1790 errmsg = "syntax error: register not expected";
1792 else if (system_register_name (& ex, false
1793 /* start-sanitize-v850e */
1795 /* end-sanitize-v850e */
1797 && (operand->flags & V850_OPERAND_SRG) == 0)
1799 errmsg = "syntax error: system register not expected";
1801 else if (cc_name (&ex)
1802 && (operand->flags & V850_OPERAND_CC) == 0)
1804 errmsg = "syntax error: condition code not expected";
1809 /* start-sanitize-v850e */
1811 If we are assembling a MOV instruction (or a CALLT.... :-)
1812 and the immediate value does not fit into the bits available
1813 then create a fake error so that the next MOV instruction
1814 will be selected. This one has a 32 bit immediate field. */
1816 if (((insn & 0x07e0) == 0x0200)
1817 && ex.X_op == O_constant
1818 && (ex.X_add_number < (- (1 << (operand->bits - 1))) || ex.X_add_number > ((1 << operand->bits) - 1)))
1819 errmsg = "use bigger instruction";
1820 /* end-sanitize-v850e */
1826 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n", insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
1831 errmsg = "illegal operand";
1834 errmsg = "missing operand";
1837 if ((operand->flags & (V850_OPERAND_REG | V850_OPERAND_SRG)) == 0)
1839 errmsg = "invalid operand";
1842 insn = v850_insert_operand (insn, operand, ex.X_add_number,
1847 insn = v850_insert_operand (insn, operand, ex.X_add_number,
1852 /* We need to generate a fixup for this expression. */
1853 if (fc >= MAX_INSN_FIXUPS)
1854 as_fatal ("too many fixups");
1856 fixups[ fc ].exp = ex;
1857 fixups[ fc ].opindex = * opindex_ptr;
1858 fixups[ fc ].reloc = BFD_RELOC_UNUSED;
1864 str = input_line_pointer;
1865 input_line_pointer = hold;
1867 while (*str == ' ' || *str == ',' || *str == '[' || *str == ']'
1876 next_opcode = opcode + 1;
1877 if (next_opcode->name != NULL && strcmp (next_opcode->name, opcode->name) == 0)
1879 opcode = next_opcode;
1884 ignore_rest_of_line ();
1885 input_line_pointer = saved_input_line_pointer;
1891 while (isspace (*str))
1895 as_bad ("junk at end of line: `%s'", str);
1897 input_line_pointer = str;
1899 /* Write out the instruction. */
1901 if (relaxable && fc > 0)
1906 if (!strcmp (opcode->name, "br"))
1908 f = frag_var (rs_machine_dependent, 4, 2, 2,
1909 fixups[0].exp.X_add_symbol,
1910 fixups[0].exp.X_add_number,
1911 (char *)fixups[0].opindex);
1912 md_number_to_chars (f, insn, insn_size);
1913 md_number_to_chars (f + 2, 0, 2);
1917 f = frag_var (rs_machine_dependent, 6, 4, 0,
1918 fixups[0].exp.X_add_symbol,
1919 fixups[0].exp.X_add_number,
1920 (char *)fixups[0].opindex);
1921 md_number_to_chars (f, insn, insn_size);
1922 md_number_to_chars (f + 2, 0, 4);
1927 /* Four byte insns have an opcode with the two high bits on. */
1928 if ((insn & 0x0600) == 0x0600)
1933 /* start-sanitize-v850e */
1934 /* Special case: 32 bit MOV */
1935 if ((insn & 0xffe0) == 0x0620)
1937 /* end-sanitize-v850e */
1939 f = frag_more (insn_size);
1941 md_number_to_chars (f, insn, insn_size);
1943 if (extra_data_after_insn)
1945 f = frag_more (extra_data_len);
1947 md_number_to_chars (f, extra_data, extra_data_len);
1949 extra_data_after_insn = false;
1953 /* Create any fixups. At this point we do not use a
1954 bfd_reloc_code_real_type, but instead just use the
1955 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1956 handle fixups for any operand type, although that is admittedly
1957 not a very exciting feature. We pick a BFD reloc type in
1959 for (i = 0; i < fc; i++)
1961 const struct v850_operand * operand;
1962 bfd_reloc_code_real_type reloc;
1964 operand = & v850_operands[ fixups[i].opindex ];
1966 reloc = fixups[i].reloc;
1968 if (reloc != BFD_RELOC_UNUSED)
1970 reloc_howto_type * reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1978 size = bfd_get_reloc_size (reloc_howto);
1980 if (size != 2 && size != 4) /* XXX this will abort on an R_V850_8 reloc - is this reloc actually used ? */
1983 address = (f - frag_now->fr_literal) + insn_size - size;
1985 if (reloc == BFD_RELOC_32)
1990 fixP = fix_new_exp (frag_now, address, size,
1992 reloc_howto->pc_relative,
1997 case BFD_RELOC_LO16:
1998 case BFD_RELOC_HI16:
1999 case BFD_RELOC_HI16_S:
2000 fixP->fx_no_overflow = 1;
2008 f - frag_now->fr_literal, 4,
2010 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2011 (bfd_reloc_code_real_type) (fixups[i].opindex + (int) BFD_RELOC_UNUSED)
2016 input_line_pointer = saved_input_line_pointer;
2020 /* If while processing a fixup, a reloc really needs to be created */
2021 /* then it is done here. */
2024 tc_gen_reloc (seg, fixp)
2030 reloc = (arelent *) xmalloc (sizeof (arelent));
2031 reloc->sym_ptr_ptr = & fixp->fx_addsy->bsym;
2032 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2033 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2035 if (reloc->howto == (reloc_howto_type *) NULL)
2037 as_bad_where (fixp->fx_file, fixp->fx_line,
2038 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
2045 reloc->addend = fixp->fx_addnumber;
2050 /* Assume everything will fit in two bytes, then expand as necessary. */
2052 md_estimate_size_before_relax (fragp, seg)
2056 if (fragp->fr_subtype == 0)
2058 else if (fragp->fr_subtype == 2)
2066 md_pcrel_from (fixp)
2069 /* If the symbol is undefined, or in a section other than our own,
2070 then let the linker figure it out. */
2071 if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy))
2073 /* The symbol is undefined. Let the linker figure it out. */
2076 return fixp->fx_frag->fr_address + fixp->fx_where;
2080 md_apply_fix3 (fixp, valuep, seg)
2088 if (fixp->fx_addsy == (symbolS *) NULL)
2093 else if (fixp->fx_pcrel)
2097 value = fixp->fx_offset;
2098 if (fixp->fx_subsy != (symbolS *) NULL)
2100 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
2101 value -= S_GET_VALUE (fixp->fx_subsy);
2104 /* We don't actually support subtracting a symbol. */
2105 as_bad_where (fixp->fx_file, fixp->fx_line,
2106 "expression too complex");
2111 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
2114 const struct v850_operand * operand;
2117 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
2118 operand = & v850_operands[ opindex ];
2120 /* Fetch the instruction, insert the fully resolved operand
2121 value, and stuff the instruction back again.
2123 Note the instruction has been stored in little endian
2125 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2127 insn = bfd_getl32 ((unsigned char *) where);
2128 insn = v850_insert_operand (insn, operand, (offsetT) value,
2129 fixp->fx_file, fixp->fx_line);
2130 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
2134 /* Nothing else to do here. */
2138 /* Determine a BFD reloc value based on the operand information.
2139 We are only prepared to turn a few of the operands into relocs. */
2141 if (operand->bits == 22)
2142 fixp->fx_r_type = BFD_RELOC_V850_22_PCREL;
2143 else if (operand->bits == 9)
2144 fixp->fx_r_type = BFD_RELOC_V850_9_PCREL;
2147 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2149 as_bad_where(fixp->fx_file, fixp->fx_line,
2150 "unresolved expression that must be resolved");
2155 else if (fixp->fx_done)
2157 /* We still have to insert the value into memory! */
2158 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2160 if (fixp->fx_size == 1)
2161 *where = value & 0xff;
2162 else if (fixp->fx_size == 2)
2163 bfd_putl16 (value & 0xffff, (unsigned char *) where);
2164 else if (fixp->fx_size == 4)
2165 bfd_putl32 (value, (unsigned char *) where);
2168 fixp->fx_addnumber = value;
2173 /* Insert an operand value into an instruction. */
2175 static unsigned long
2176 v850_insert_operand (insn, operand, val, file, line)
2178 const struct v850_operand * operand;
2183 if (operand->insert)
2185 const char * message = NULL;
2187 insn = (*operand->insert) (insn, val, & message);
2188 if (message != NULL)
2190 if (file == (char *) NULL)
2193 as_warn_where (file, line, message);
2198 if (operand->bits != 32)
2203 if ((operand->flags & V850_OPERAND_SIGNED) != 0)
2205 if (! warn_signed_overflows)
2206 max = (1 << operand->bits) - 1;
2208 max = (1 << (operand->bits - 1)) - 1;
2210 min = - (1 << (operand->bits - 1));
2214 max = (1 << operand->bits) - 1;
2216 if (! warn_unsigned_overflows)
2217 min = - (1 << (operand->bits - 1));
2224 if (test < (offsetT) min || test > (offsetT) max)
2226 const char * err = "operand out of range (%s not between %ld and %ld)";
2229 /* Restore min and mix to expected values for decimal ranges. */
2230 if ((operand->flags & V850_OPERAND_SIGNED) && ! warn_signed_overflows)
2231 max = (1 << (operand->bits - 1)) - 1;
2233 if (! (operand->flags & V850_OPERAND_SIGNED)
2234 && ! warn_unsigned_overflows)
2237 sprint_value (buf, test);
2238 if (file == (char *) NULL)
2239 as_warn (err, buf, min, max);
2241 as_warn_where (file, line, err, buf, min, max);
2245 insn |= (((long) val & ((1 << operand->bits) - 1)) << operand->shift);
2251 /* Parse a cons expression. We have to handle hi(), lo(), etc
2254 parse_cons_expression_v850 (exp)
2257 /* See if there's a reloc prefix like hi() we have to handle. */
2258 hold_cons_reloc = v850_reloc_prefix (NULL);
2260 /* Do normal expression parsing. */
2264 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2265 found a reloc prefix, then we use that reloc, else we choose an
2266 appropriate one based on the size of the expression. */
2268 cons_fix_new_v850 (frag, where, size, exp)
2274 if (hold_cons_reloc == BFD_RELOC_UNUSED)
2277 hold_cons_reloc = BFD_RELOC_32;
2279 hold_cons_reloc = BFD_RELOC_16;
2281 hold_cons_reloc = BFD_RELOC_8;
2285 fix_new_exp (frag, where, size, exp, 0, hold_cons_reloc);
2287 fix_new (frag, where, size, NULL, 0, 0, hold_cons_reloc);