1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "opcode/v850.h"
31 /* sign-extend a 16-bit number */
32 #define SEXT16(x) ((((x) & 0xffff) ^ (~ 0x7fff)) + 0x8000)
34 /* Temporarily holds the reloc in a cons expression. */
35 static bfd_reloc_code_real_type hold_cons_reloc
;
37 /* Set to TRUE if we want to be pedantic about signed overflows. */
38 static boolean warn_signed_overflows
= FALSE
;
39 static boolean warn_unsigned_overflows
= FALSE
;
41 /* Indicates the target BFD machine number. */
42 static int machine
= -1;
44 /* Indicates the target processor(s) for the assemble. */
45 static unsigned int processor_mask
= -1;
48 /* Structure to hold information about predefined registers. */
55 /* Generic assembler global variables which must be defined by all targets. */
57 /* Characters which always start a comment. */
58 const char comment_chars
[] = "#";
60 /* Characters which start a comment at the beginning of a line. */
61 const char line_comment_chars
[] = ";#";
63 /* Characters which may be used to separate multiple commands on a
65 const char line_separator_chars
[] = ";";
67 /* Characters which are used to indicate an exponent in a floating
69 const char EXP_CHARS
[] = "eE";
71 /* Characters which mean that a number is a floating point constant,
73 const char FLT_CHARS
[] = "dD";
76 const relax_typeS md_relax_table
[] =
78 /* Conditional branches. */
80 {0x1fffff, -0x200000, 6, 0},
81 /* Unconditional branches. */
83 {0x1fffff, -0x200000, 4, 0},
87 static segT sdata_section
= NULL
;
88 static segT tdata_section
= NULL
;
89 static segT zdata_section
= NULL
;
90 static segT sbss_section
= NULL
;
91 static segT tbss_section
= NULL
;
92 static segT zbss_section
= NULL
;
93 static segT rosdata_section
= NULL
;
94 static segT rozdata_section
= NULL
;
95 static segT scommon_section
= NULL
;
96 static segT tcommon_section
= NULL
;
97 static segT zcommon_section
= NULL
;
98 /* start-sanitize-v850e */
99 static segT call_table_data_section
= NULL
;
100 static segT call_table_text_section
= NULL
;
101 /* end-sanitize-v850e */
104 #define MAX_INSN_FIXUPS (5)
109 bfd_reloc_code_real_type reloc
;
112 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
117 v850_sdata (int ignore
)
119 obj_elf_section_change_hook();
121 subseg_set (sdata_section
, (subsegT
) get_absolute_expression ());
123 demand_empty_rest_of_line ();
127 v850_tdata (int ignore
)
129 obj_elf_section_change_hook();
131 subseg_set (tdata_section
, (subsegT
) get_absolute_expression ());
133 demand_empty_rest_of_line ();
137 v850_zdata (int ignore
)
139 obj_elf_section_change_hook();
141 subseg_set (zdata_section
, (subsegT
) get_absolute_expression ());
143 demand_empty_rest_of_line ();
147 v850_sbss (int ignore
)
149 obj_elf_section_change_hook();
151 subseg_set (sbss_section
, (subsegT
) get_absolute_expression ());
153 demand_empty_rest_of_line ();
157 v850_tbss (int ignore
)
159 obj_elf_section_change_hook();
161 subseg_set (tbss_section
, (subsegT
) get_absolute_expression ());
163 demand_empty_rest_of_line ();
167 v850_zbss (int ignore
)
169 obj_elf_section_change_hook();
171 subseg_set (zbss_section
, (subsegT
) get_absolute_expression ());
173 demand_empty_rest_of_line ();
177 v850_rosdata (int ignore
)
179 obj_elf_section_change_hook();
181 subseg_set (rosdata_section
, (subsegT
) get_absolute_expression ());
183 demand_empty_rest_of_line ();
187 v850_rozdata (int ignore
)
189 obj_elf_section_change_hook();
191 subseg_set (rozdata_section
, (subsegT
) get_absolute_expression ());
193 demand_empty_rest_of_line ();
196 /* start-sanitize-v850e */
198 v850_call_table_data (int ignore
)
200 obj_elf_section_change_hook();
202 subseg_set (call_table_data_section
, (subsegT
) get_absolute_expression ());
204 demand_empty_rest_of_line ();
208 v850_call_table_text (int ignore
)
210 obj_elf_section_change_hook();
212 subseg_set (call_table_text_section
, (subsegT
) get_absolute_expression ());
214 demand_empty_rest_of_line ();
216 /* end-sanitize-v850e */
219 v850_bss (int ignore
)
221 register int temp
= get_absolute_expression ();
223 obj_elf_section_change_hook();
225 subseg_set (bss_section
, (subsegT
) temp
);
227 demand_empty_rest_of_line ();
231 v850_offset (int ignore
)
233 int temp
= get_absolute_expression ();
235 temp
-= frag_now_fix();
238 (void) frag_more (temp
);
240 demand_empty_rest_of_line ();
243 /* Copied from obj_elf_common() in gas/config/obj-elf.c */
256 name
= input_line_pointer
;
257 c
= get_symbol_end ();
258 /* just after name is now '\0' */
259 p
= input_line_pointer
;
262 if (*input_line_pointer
!= ',')
264 as_bad (_("Expected comma after symbol-name"));
265 ignore_rest_of_line ();
268 input_line_pointer
++; /* skip ',' */
269 if ((temp
= get_absolute_expression ()) < 0)
271 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
272 ignore_rest_of_line ();
277 symbolP
= symbol_find_or_make (name
);
279 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
281 as_bad (_("Ignoring attempt to re-define symbol"));
282 ignore_rest_of_line ();
285 if (S_GET_VALUE (symbolP
) != 0)
287 if (S_GET_VALUE (symbolP
) != size
)
289 /* xgettext:c-format */
290 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
291 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
294 know (symbolP
->sy_frag
== &zero_address_frag
);
295 if (*input_line_pointer
!= ',')
300 input_line_pointer
++;
303 if (! have_align
|| *input_line_pointer
!= '"')
309 temp
= get_absolute_expression ();
313 as_warn (_("Common alignment negative; 0 assumed"));
325 old_subsec
= now_subseg
;
328 /* convert to a power of 2 alignment */
329 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
332 as_bad (_("Common alignment not a power of 2"));
333 ignore_rest_of_line ();
342 record_alignment (sbss_section
, align
);
343 obj_elf_section_change_hook();
344 subseg_set (sbss_section
, 0);
348 record_alignment (zbss_section
, align
);
349 obj_elf_section_change_hook();
350 subseg_set (zbss_section
, 0);
354 record_alignment (tbss_section
, align
);
355 obj_elf_section_change_hook();
356 subseg_set (tbss_section
, 0);
364 frag_align (align
, 0, 0);
369 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
370 symbolP
->sy_frag
->fr_symbol
= 0;
374 if (S_GET_SEGMENT (symbolP
) == zbss_section
)
375 symbolP
->sy_frag
->fr_symbol
= 0;
379 if (S_GET_SEGMENT (symbolP
) == tbss_section
)
380 symbolP
->sy_frag
->fr_symbol
= 0;
387 symbolP
->sy_frag
= frag_now
;
388 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
389 (offsetT
) size
, (char *) 0);
391 S_SET_SIZE (symbolP
, size
);
395 case AREA_SDA
: S_SET_SEGMENT (symbolP
, sbss_section
); break;
396 case AREA_ZDA
: S_SET_SEGMENT (symbolP
, zbss_section
); break;
397 case AREA_TDA
: S_SET_SEGMENT (symbolP
, tbss_section
); break;
402 S_CLEAR_EXTERNAL (symbolP
);
403 obj_elf_section_change_hook();
404 subseg_set (old_sec
, old_subsec
);
409 S_SET_VALUE (symbolP
, (valueT
) size
);
410 S_SET_ALIGN (symbolP
, temp
);
411 S_SET_EXTERNAL (symbolP
);
415 case AREA_SDA
: S_SET_SEGMENT (symbolP
, scommon_section
); break;
416 case AREA_ZDA
: S_SET_SEGMENT (symbolP
, zcommon_section
); break;
417 case AREA_TDA
: S_SET_SEGMENT (symbolP
, tcommon_section
); break;
425 input_line_pointer
++;
426 /* @@ Some use the dot, some don't. Can we get some consistency?? */
427 if (*input_line_pointer
== '.')
428 input_line_pointer
++;
429 /* @@ Some say data, some say bss. */
430 if (strncmp (input_line_pointer
, "bss\"", 4)
431 && strncmp (input_line_pointer
, "data\"", 5))
433 while (*--input_line_pointer
!= '"')
435 input_line_pointer
--;
436 goto bad_common_segment
;
438 while (*input_line_pointer
++ != '"')
440 goto allocate_common
;
443 symbolP
->bsym
->flags
|= BSF_OBJECT
;
445 demand_empty_rest_of_line ();
450 p
= input_line_pointer
;
451 while (*p
&& *p
!= '\n')
455 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
457 input_line_pointer
= p
;
458 ignore_rest_of_line ();
464 set_machine (int number
)
467 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
471 case 0: processor_mask
= PROCESSOR_V850
; break;
472 /* start-sanitize-v850e */
473 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
474 case bfd_mach_v850ea
: processor_mask
= PROCESSOR_V850EA
; break;
475 /* end-sanitize-v850e */
479 /* The target specific pseudo-ops which we support. */
480 const pseudo_typeS md_pseudo_table
[] =
482 {"sdata", v850_sdata
, 0},
483 {"tdata", v850_tdata
, 0},
484 {"zdata", v850_zdata
, 0},
485 {"sbss", v850_sbss
, 0},
486 {"tbss", v850_tbss
, 0},
487 {"zbss", v850_zbss
, 0},
488 {"rosdata", v850_rosdata
, 0},
489 {"rozdata", v850_rozdata
, 0},
490 {"bss", v850_bss
, 0},
491 {"offset", v850_offset
, 0},
493 {"zcomm", v850_comm
, AREA_ZDA
},
494 {"scomm", v850_comm
, AREA_SDA
},
495 {"tcomm", v850_comm
, AREA_TDA
},
496 {"v850", set_machine
, 0},
497 /* start-sanitize-v850e */
498 {"call_table_data", v850_call_table_data
, 0},
499 {"call_table_text", v850_call_table_text
, 0},
500 {"v850e", set_machine
, bfd_mach_v850e
},
501 {"v850ea", set_machine
, bfd_mach_v850ea
},
502 /* end-sanitize-v850e */
506 /* Opcode hash table. */
507 static struct hash_control
*v850_hash
;
509 /* This table is sorted. Suitable for searching by a binary search. */
510 static const struct reg_name pre_defined_registers
[] =
512 { "ep", 30 }, /* ep - element ptr */
513 { "gp", 4 }, /* gp - global ptr */
514 { "hp", 2 }, /* hp - handler stack ptr */
515 { "lp", 31 }, /* lp - link ptr */
548 { "sp", 3 }, /* sp - stack ptr */
549 { "tp", 5 }, /* tp - text ptr */
552 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
555 static const struct reg_name system_registers
[] =
557 /* start-sanitize-v850e */
563 /* end-sanitize-v850e */
571 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
573 /* start-sanitize-v850e */
574 static const struct reg_name system_list_registers
[] =
579 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
580 /* end-sanitize-v850e */
582 static const struct reg_name cc_names
[] =
607 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
609 /* reg_name_search does a binary search of the given register table
610 to see if "name" is a valid regiter name. Returns the register
611 number from the array on success, or -1 on failure. */
614 reg_name_search (regs
, regcount
, name
, accept_numbers
)
615 const struct reg_name
* regs
;
618 boolean accept_numbers
;
620 int middle
, low
, high
;
624 /* If the register name is a symbol, then evaluate it. */
625 if ((symbolP
= symbol_find (name
)) != NULL
)
627 /* If the symbol is an alias for another name then use that.
628 If the symbol is an alias for a number, then return the number. */
629 if (symbolP
->sy_value
.X_op
== O_symbol
)
631 name
= S_GET_NAME (symbolP
->sy_value
.X_add_symbol
);
633 else if (accept_numbers
)
635 int reg
= S_GET_VALUE (symbolP
);
637 if (reg
>= 0 && reg
<= 31)
647 middle
= (low
+ high
) / 2;
648 cmp
= strcasecmp (name
, regs
[middle
].name
);
654 return regs
[middle
].value
;
661 /* Summary of register_name().
663 * in: Input_line_pointer points to 1st char of operand.
665 * out: A expressionS.
666 * The operand may have been a register: in this case, X_op == O_register,
667 * X_add_number is set to the register number, and truth is returned.
668 * Input_line_pointer->(next non-blank) char after operand, or is in
669 * its original state.
672 register_name (expressionP
)
673 expressionS
* expressionP
;
680 /* Find the spelling of the operand */
681 start
= name
= input_line_pointer
;
683 c
= get_symbol_end ();
685 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
,
688 * input_line_pointer
= c
; /* put back the delimiting char */
690 /* look to see if it's in the register table */
693 expressionP
->X_op
= O_register
;
694 expressionP
->X_add_number
= reg_number
;
696 /* make the rest nice */
697 expressionP
->X_add_symbol
= NULL
;
698 expressionP
->X_op_symbol
= NULL
;
704 /* reset the line as if we had not done anything */
705 input_line_pointer
= start
;
711 /* Summary of system_register_name().
713 * in: Input_line_pointer points to 1st char of operand.
714 * expressionP points to an expression structure to be filled in.
715 * accept_numbers is true iff numerical register names may be used.
716 * start-sanitize-v850e
717 * accept_list_names is true iff the special names PS and SR may be
721 * out: A 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.
728 system_register_name (expressionP
, accept_numbers
729 /* start-sanitize-v850e */
731 /* end-sanitize-v850e */
733 expressionS
* expressionP
;
734 boolean accept_numbers
;
735 /* start-sanitize-v850e */
736 boolean accept_list_names
;
737 /* end-sanitize-v850e */
744 /* Find the spelling of the operand */
745 start
= name
= input_line_pointer
;
747 c
= get_symbol_end ();
748 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
,
751 * input_line_pointer
= c
; /* put back the delimiting char */
756 input_line_pointer
= start
; /* reset input_line pointer */
758 if (isdigit (* input_line_pointer
))
760 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
762 /* Make sure that the register number is allowable. */
765 /* start-sanitize-v850e */
768 /* end-sanitize-v850e */
774 /* start-sanitize-v850e */
775 else if (accept_list_names
)
777 c
= get_symbol_end ();
778 reg_number
= reg_name_search (system_list_registers
,
779 SYSREGLIST_NAME_CNT
, name
, FALSE
);
781 * input_line_pointer
= c
; /* put back the delimiting char */
783 /* end-sanitize-v850e */
786 /* look to see if it's in the register table */
789 expressionP
->X_op
= O_register
;
790 expressionP
->X_add_number
= reg_number
;
792 /* make the rest nice */
793 expressionP
->X_add_symbol
= NULL
;
794 expressionP
->X_op_symbol
= NULL
;
800 /* reset the line as if we had not done anything */
801 input_line_pointer
= start
;
807 /* Summary of cc_name().
809 * in: Input_line_pointer points to 1st char of operand.
811 * out: A expressionS.
812 * The operand may have been a register: in this case, X_op == O_register,
813 * X_add_number is set to the register number, and truth is returned.
814 * Input_line_pointer->(next non-blank) char after operand, or is in
815 * its original state.
818 cc_name (expressionP
)
819 expressionS
* expressionP
;
826 /* Find the spelling of the operand */
827 start
= name
= input_line_pointer
;
829 c
= get_symbol_end ();
830 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
, FALSE
);
832 * input_line_pointer
= c
; /* put back the delimiting char */
834 /* look to see if it's in the register table */
837 expressionP
->X_op
= O_constant
;
838 expressionP
->X_add_number
= reg_number
;
840 /* make the rest nice */
841 expressionP
->X_add_symbol
= NULL
;
842 expressionP
->X_op_symbol
= NULL
;
848 /* reset the line as if we had not done anything */
849 input_line_pointer
= start
;
856 skip_white_space (void)
858 while ( * input_line_pointer
== ' '
859 || * input_line_pointer
== '\t')
860 ++ input_line_pointer
;
863 /* start-sanitize-v850e */
864 /* Summary of parse_register_list ().
866 * in: Input_line_pointer points to 1st char of a list of registers.
867 * insn is the partially constructed instruction.
868 * operand is the operand being inserted.
870 * out: NULL if the parse completed successfully, otherwise a
871 * pointer to an error message is returned. If the parse
872 * completes the correct bit fields in the instruction
875 * Parses register lists with the syntax:
883 * and also parses constant epxressions whoes bits indicate the
884 * registers in the lists. The LSB in the expression refers to
885 * the lowest numbered permissable register in the register list,
886 * and so on upwards. System registers are considered to be very
893 unsigned long * insn
,
894 const struct v850_operand
* operand
897 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 };
898 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 };
899 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 };
904 /* Select a register array to parse. */
905 switch (operand
->shift
)
907 case 0xffe00001: regs
= type1_regs
; break;
908 case 0xfff8000f: regs
= type2_regs
; break;
909 case 0xfff8001f: regs
= type3_regs
; break;
911 as_bad (_("unknown operand shift: %x\n"), operand
->shift
);
912 return _("internal failure in parse_register_list");
917 /* If the expression starts with a curly brace it is a register list.
918 Otherwise it is a constant expression, whoes bits indicate which
919 registers are to be included in the list. */
921 if (* input_line_pointer
!= '{')
929 if (exp
.X_op
!= O_constant
)
930 return _("constant expression or register list expected");
932 if (regs
== type1_regs
)
934 if (exp
.X_add_number
& 0xFFFFF000)
935 return _("high bits set in register list expression");
937 for (reg
= 20; reg
< 32; reg
++)
938 if (exp
.X_add_number
& (1 << (reg
- 20)))
940 for (i
= 0; i
< 32; i
++)
945 else if (regs
== type2_regs
)
947 if (exp
.X_add_number
& 0xFFFE0000)
948 return _("high bits set in register list expression");
950 for (reg
= 1; reg
< 16; reg
++)
951 if (exp
.X_add_number
& (1 << (reg
- 1)))
953 for (i
= 0; i
< 32; i
++)
958 if (exp
.X_add_number
& (1 << 15))
961 if (exp
.X_add_number
& (1 << 16))
964 else /* regs == type3_regs */
966 if (exp
.X_add_number
& 0xFFFE0000)
967 return _("high bits set in register list expression");
969 for (reg
= 16; reg
< 32; reg
++)
970 if (exp
.X_add_number
& (1 << (reg
- 16)))
972 for (i
= 0; i
< 32; i
++)
977 if (exp
.X_add_number
& (1 << 16))
984 input_line_pointer
++;
986 /* Parse the register list until a terminator (closing curly brace or
987 new-line) is found. */
990 if (register_name (& exp
))
994 /* Locate the given register in the list, and if it is there,
995 insert the corresponding bit into the instruction. */
996 for (i
= 0; i
< 32; i
++)
998 if (regs
[ i
] == exp
.X_add_number
)
1007 return _("illegal register included in list");
1010 else if (system_register_name (& exp
, true, true))
1012 if (regs
== type1_regs
)
1014 return _("system registers cannot be included in list");
1016 else if (exp
.X_add_number
== 5)
1018 if (regs
== type2_regs
)
1019 return _("PSW cannot be included in list");
1023 else if (exp
.X_add_number
< 4)
1026 return _("High value system registers cannot be included in list");
1028 else if (* input_line_pointer
== '}')
1030 input_line_pointer
++;
1033 else if (* input_line_pointer
== ',')
1035 input_line_pointer
++;
1038 else if (* input_line_pointer
== '-')
1040 /* We have encountered a range of registers: rX - rY */
1044 /* Skip the dash. */
1045 ++ input_line_pointer
;
1047 /* Get the second register in the range. */
1048 if (! register_name (& exp2
))
1050 return _("second register should follow dash in register list");
1051 exp2
.X_add_number
= exp
.X_add_number
;
1054 /* Add the rest of the registers in the range. */
1055 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1059 /* Locate the given register in the list, and if it is there,
1060 insert the corresponding bit into the instruction. */
1061 for (i
= 0; i
< 32; i
++)
1071 return _("illegal register included in list");
1079 skip_white_space ();
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-mv850ea The code is targeted at the v850ea\n"));
1106 fprintf (stream
, _("\t-mv850any The code is generic, despite any processor specific instructions\n"));
1107 /* end-sanitize-v850e */
1111 md_parse_option (c
, arg
)
1117 /* xgettext:c-format */
1118 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1122 if (strcmp (arg
, "warn-signed-overflow") == 0)
1124 warn_signed_overflows
= TRUE
;
1126 else if (strcmp (arg
, "warn-unsigned-overflow") == 0)
1128 warn_unsigned_overflows
= TRUE
;
1130 else if (strcmp (arg
, "v850") == 0)
1133 processor_mask
= PROCESSOR_V850
;
1135 /* start-sanitize-v850e */
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 machine
= 0; /* Tell the world that this is for any v850 chip. */
1149 processor_mask
= PROCESSOR_V850EA
; /* But support instructions for the extended versions. */
1151 /* end-sanitize-v850e */
1154 /* xgettext:c-format */
1155 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1163 md_undefined_symbol (name
)
1170 md_atof (type
, litp
, sizep
)
1176 LITTLENUM_TYPE words
[4];
1192 return _("bad call to md_atof");
1195 t
= atof_ieee (input_line_pointer
, type
, words
);
1197 input_line_pointer
= t
;
1201 for (i
= prec
- 1; i
>= 0; i
--)
1203 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1213 md_convert_frag (abfd
, sec
, fragP
)
1218 subseg_change (sec
, 0);
1220 /* In range conditional or unconditional branch. */
1221 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1223 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1224 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1228 /* Out of range conditional branch. Emit a branch around a jump. */
1229 else if (fragP
->fr_subtype
== 1)
1231 unsigned char *buffer
=
1232 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1234 /* Reverse the condition of the first branch. */
1236 /* Mask off all the displacement bits. */
1239 /* Now set the displacement bits so that we branch
1240 around the unconditional branch. */
1243 /* Now create the unconditional branch + fixup to the final
1245 md_number_to_chars (buffer
+ 2, 0x00000780, 4);
1246 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1247 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int) fragP
->fr_opcode
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
+ (int) fragP
->fr_opcode
1267 md_section_align (seg
, addr
)
1271 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1272 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1278 char * prev_name
= "";
1279 register const struct v850_opcode
* op
;
1280 flagword applicable
;
1282 /* start-sanitize-v850e */
1283 if (strncmp (TARGET_CPU
, "v850ea", 6) == 0)
1286 machine
= bfd_mach_v850ea
;
1288 if (processor_mask
== -1)
1289 processor_mask
= PROCESSOR_V850EA
;
1291 else if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1294 machine
= bfd_mach_v850e
;
1296 if (processor_mask
== -1)
1297 processor_mask
= PROCESSOR_V850E
;
1300 /* end-sanitize-v850e */
1301 if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1306 if (processor_mask
== -1)
1307 processor_mask
= PROCESSOR_V850
;
1310 /* xgettext:c-format */
1311 as_bad (_("Unable to determine default target processor from string: %s"),
1314 v850_hash
= hash_new();
1316 /* Insert unique names into hash table. The V850 instruction set
1317 has many identical opcode names that have different opcodes based
1318 on the operands. This hash table then provides a quick index to
1319 the first opcode with a particular name in the opcode table. */
1324 if (strcmp (prev_name
, op
->name
))
1326 prev_name
= (char *) op
->name
;
1327 hash_insert (v850_hash
, op
->name
, (char *) op
);
1332 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1337 /* start-sanitize-v850e */
1338 static bfd_reloc_code_real_type
1339 handle_ctoff (const struct v850_operand
* operand
)
1341 if (operand
== NULL
)
1342 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1344 if ( operand
->bits
!= 6
1345 || operand
->shift
!= 0)
1347 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1348 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1351 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1353 /* end-sanitize-v850e */
1355 static bfd_reloc_code_real_type
1356 handle_sdaoff (const struct v850_operand
* operand
)
1358 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1359 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1360 /* start-sanitize-v850e */
1361 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1362 /* end-sanitize-v850e */
1364 if ( operand
->bits
!= 16
1365 || operand
->shift
!= 16)
1367 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1368 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1371 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1374 static bfd_reloc_code_real_type
1375 handle_zdaoff (const struct v850_operand
* operand
)
1377 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1378 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1379 /* start-sanitize-v850e */
1380 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1381 /* end-sanitize-v850e */
1383 if ( operand
->bits
!= 16
1384 || operand
->shift
!= 16)
1386 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1387 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1390 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1393 static bfd_reloc_code_real_type
1394 handle_tdaoff (const struct v850_operand
* operand
)
1396 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
; /* data item, not an instruction. */
1397 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
; /* sld.w/sst.w, operand: D8_6 */
1398 /* start-sanitize-v850e */
1399 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
; /* sld.hu, operand: D5-4 */
1400 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
; /* sld.bu, operand: D4 */
1401 /* end-sanitize-v850e */
1402 if (operand
->bits
== 16 && operand
->shift
== 16) return BFD_RELOC_V850_TDA_16_16_OFFSET
; /* set1 & chums, operands: D16 */
1404 if (operand
->bits
!= 7)
1406 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1407 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1410 return operand
->insert
!= NULL
1411 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1412 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1415 /* Warning: The code in this function relies upon the definitions
1416 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1417 matching the hard coded values contained herein. */
1419 static bfd_reloc_code_real_type
1420 v850_reloc_prefix (const struct v850_operand
* operand
)
1422 boolean paren_skipped
= false;
1425 /* Skip leading opening parenthesis. */
1426 if (* input_line_pointer
== '(')
1428 ++ input_line_pointer
;
1429 paren_skipped
= true;
1432 #define CHECK_(name, reloc) \
1433 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1435 input_line_pointer += strlen (name); \
1439 CHECK_ ("hi0", BFD_RELOC_HI16
);
1440 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1441 CHECK_ ("lo", BFD_RELOC_LO16
);
1442 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1443 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1444 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1446 /* start-sanitize-v850e */
1447 CHECK_ ("hilo", BFD_RELOC_32
);
1448 CHECK_ ("ctoff", handle_ctoff (operand
));
1449 /* end-sanitize-v850e */
1451 /* Restore skipped parenthesis. */
1453 -- input_line_pointer
;
1455 return BFD_RELOC_UNUSED
;
1458 /* Insert an operand value into an instruction. */
1460 static unsigned long
1461 v850_insert_operand (insn
, operand
, val
, file
, line
, str
)
1463 const struct v850_operand
* operand
;
1469 if (operand
->insert
)
1471 const char * message
= NULL
;
1473 insn
= operand
->insert (insn
, val
, & message
);
1474 if (message
!= NULL
)
1476 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1477 && ! warn_signed_overflows
1478 && strstr (message
, "out of range") != NULL
)
1480 /* skip warning... */
1482 else if ((operand
->flags
& V850_OPERAND_SIGNED
) == 0
1483 && ! warn_unsigned_overflows
1484 && strstr (message
, "out of range") != NULL
)
1486 /* skip warning... */
1490 if (file
== (char *) NULL
)
1491 as_warn ("%s: %s", str
, message
);
1493 as_warn_where (file
, line
, "%s: %s", str
, message
);
1497 if (file
== (char *) NULL
)
1500 as_warn_where (file
, line
, message
);
1506 if (operand
->bits
!= 32)
1511 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1513 if (! warn_signed_overflows
)
1514 max
= (1 << operand
->bits
) - 1;
1516 max
= (1 << (operand
->bits
- 1)) - 1;
1518 min
= - (1 << (operand
->bits
- 1));
1522 max
= (1 << operand
->bits
) - 1;
1524 if (! warn_unsigned_overflows
)
1525 min
= - (1 << (operand
->bits
- 1));
1530 if (val
< (offsetT
) min
|| val
> (offsetT
) max
)
1532 /* xgettext:c-format */
1533 const char * err
= _("operand out of range (%s not between %ld and %ld)");
1536 /* Restore min and mix to expected values for decimal ranges. */
1537 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1538 && ! warn_signed_overflows
)
1539 max
= (1 << (operand
->bits
- 1)) - 1;
1541 if (! (operand
->flags
& V850_OPERAND_SIGNED
)
1542 && ! warn_unsigned_overflows
)
1547 sprintf (buf
, "%s: ", str
);
1549 sprint_value (buf
+ strlen (buf
), val
);
1552 sprint_value (buf
, val
);
1554 if (file
== (char *) NULL
)
1555 as_warn (err
, buf
, min
, max
);
1557 as_warn_where (file
, line
, err
, buf
, min
, max
);
1561 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1568 static char copy_of_instruction
[128];
1575 char * start_of_operands
;
1576 struct v850_opcode
* opcode
;
1577 struct v850_opcode
* next_opcode
;
1578 const unsigned char * opindex_ptr
;
1582 unsigned long insn_size
;
1586 boolean extra_data_after_insn
= false;
1587 unsigned extra_data_len
;
1588 unsigned long extra_data
;
1589 char * saved_input_line_pointer
;
1592 strncpy (copy_of_instruction
, str
, sizeof (copy_of_instruction
) - 1);
1594 /* Get the opcode. */
1595 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1601 /* find the first opcode with the proper name */
1602 opcode
= (struct v850_opcode
*) hash_find (v850_hash
, str
);
1605 /* xgettext:c-format */
1606 as_bad (_("Unrecognized opcode: `%s'"), str
);
1607 ignore_rest_of_line ();
1612 while (isspace (* str
))
1615 start_of_operands
= str
;
1617 saved_input_line_pointer
= input_line_pointer
;
1621 const char * errmsg
= NULL
;
1625 if ((opcode
->processors
& processor_mask
) == 0)
1627 errmsg
= _("Target processor does not support this instruction.");
1634 insn
= opcode
->opcode
;
1635 extra_data_after_insn
= false;
1637 input_line_pointer
= str
= start_of_operands
;
1639 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1641 const struct v850_operand
* operand
;
1644 bfd_reloc_code_real_type reloc
;
1646 if (next_opindex
== 0)
1648 operand
= & v850_operands
[ * opindex_ptr
];
1652 operand
= & v850_operands
[ next_opindex
];
1658 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1661 if (operand
->flags
& V850_OPERAND_RELAX
)
1664 /* Gather the operand. */
1665 hold
= input_line_pointer
;
1666 input_line_pointer
= str
;
1668 /* lo(), hi(), hi0(), etc... */
1669 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1671 /* This is a fake reloc, used to indicate an error condition. */
1672 if (reloc
== BFD_RELOC_64
)
1680 if (ex
.X_op
== O_constant
)
1684 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1685 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1689 case BFD_RELOC_LO16
:
1691 /* Truncate, then sign extend the value. */
1692 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1696 case BFD_RELOC_HI16
:
1698 /* Truncate, then sign extend the value. */
1699 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1703 case BFD_RELOC_HI16_S
:
1705 /* Truncate, then sign extend the value. */
1706 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1708 temp
+= (ex
.X_add_number
>> 15) & 1;
1710 ex
.X_add_number
= SEXT16 (temp
);
1714 /* start-sanitize-v850e */
1716 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1718 errmsg
= _("immediate operand is too large");
1722 extra_data_after_insn
= true;
1724 extra_data
= ex
.X_add_number
;
1725 ex
.X_add_number
= 0;
1727 /* end-sanitize-v850e */
1730 fprintf (stderr
, "reloc: %d\n", reloc
);
1731 as_bad (_("AAARG -> unhandled constant reloc"));
1735 if (fc
> MAX_INSN_FIXUPS
)
1736 as_fatal (_("too many fixups"));
1738 fixups
[ fc
].exp
= ex
;
1739 fixups
[ fc
].opindex
= * opindex_ptr
;
1740 fixups
[ fc
].reloc
= reloc
;
1745 /* start-sanitize-v850e */
1746 if (reloc
== BFD_RELOC_32
)
1748 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1750 errmsg
= _("immediate operand is too large");
1754 extra_data_after_insn
= true;
1756 extra_data
= ex
.X_add_number
;
1758 /* end-sanitize-v850e */
1760 if (fc
> MAX_INSN_FIXUPS
)
1761 as_fatal (_("too many fixups"));
1763 fixups
[ fc
].exp
= ex
;
1764 fixups
[ fc
].opindex
= * opindex_ptr
;
1765 fixups
[ fc
].reloc
= reloc
;
1773 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1775 if (!register_name (& ex
))
1777 errmsg
= _("invalid register name");
1779 else if ((operand
->flags
& V850_NOT_R0
)
1780 && ex
.X_add_number
== 0)
1782 errmsg
= _("register r0 cannot be used here");
1784 /* Force an error message to be generated by
1785 skipping over any following potential matches
1790 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1792 if (!system_register_name (& ex
, true
1793 /* start-sanitize-v850e */
1795 /* end-sanitize-v850e */
1798 errmsg
= _("invalid system register name");
1801 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1803 char * start
= input_line_pointer
;
1804 char c
= get_symbol_end ();
1806 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1808 /* Put things back the way we found them. */
1809 *input_line_pointer
= c
;
1810 input_line_pointer
= start
;
1811 errmsg
= _("expected EP register");
1815 *input_line_pointer
= c
;
1816 str
= input_line_pointer
;
1817 input_line_pointer
= hold
;
1819 while ( *str
== ' ' || *str
== ',' || *str
== '['
1824 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1826 if (!cc_name (& ex
))
1828 errmsg
= _("invalid condition code name");
1831 /* start-sanitize-v850e */
1832 else if (operand
->flags
& V850E_PUSH_POP
)
1834 errmsg
= parse_register_list (& insn
, operand
);
1836 /* The parse_register_list() function has already done
1837 everything, so fake a dummy expression. */
1838 ex
.X_op
= O_constant
;
1839 ex
.X_add_number
= 0;
1841 else if (operand
->flags
& V850E_IMMEDIATE16
)
1845 if (ex
.X_op
!= O_constant
)
1846 errmsg
= _("constant expression expected");
1847 else if (ex
.X_add_number
& 0xffff0000)
1849 if (ex
.X_add_number
& 0xffff)
1850 errmsg
= _("constant too big to fit into instruction");
1851 else if ((insn
& 0x001fffc0) == 0x00130780)
1852 ex
.X_add_number
>>= 16;
1854 errmsg
= _("constant too big to fit into instruction");
1857 extra_data_after_insn
= true;
1859 extra_data
= ex
.X_add_number
;
1860 ex
.X_add_number
= 0;
1862 else if (operand
->flags
& V850E_IMMEDIATE32
)
1866 if (ex
.X_op
!= O_constant
)
1867 errmsg
= _("constant expression expected");
1869 extra_data_after_insn
= true;
1871 extra_data
= ex
.X_add_number
;
1872 ex
.X_add_number
= 0;
1874 /* end-sanitize-v850e */
1875 else if (register_name (& ex
)
1876 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1881 /* It is possible that an alias has been defined that
1882 matches a register name. For example the code may
1883 include a ".set ZERO, 0" directive, which matches
1884 the register name "zero". Attempt to reparse the
1885 field as an expression, and only complain if we
1886 cannot generate a constant. */
1888 input_line_pointer
= str
;
1890 c
= get_symbol_end();
1892 if (symbol_find (str
) != NULL
)
1895 * input_line_pointer
= c
;
1896 input_line_pointer
= str
;
1900 if (ex
.X_op
!= O_constant
)
1902 /* If this register is actually occuring too early on
1903 the parsing of the instruction, (because another
1904 field is missing) then report this. */
1905 if (opindex_ptr
[1] != 0
1906 && (v850_operands
[opindex_ptr
[1]].flags
& V850_OPERAND_REG
))
1907 errmsg
= _("syntax error: value is missing before the register name");
1909 errmsg
= _("syntax error: register not expected");
1911 /* If we created a symbol in the process of this test then
1912 delete it now, so that it will not be output with the real
1915 && ex
.X_op
== O_symbol
)
1916 symbol_remove (ex
.X_add_symbol
,
1917 & symbol_rootP
, & symbol_lastP
);
1920 else if (system_register_name (& ex
, false
1921 /* start-sanitize-v850e */
1923 /* end-sanitize-v850e */
1925 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1927 errmsg
= _("syntax error: system register not expected");
1929 else if (cc_name (&ex
)
1930 && (operand
->flags
& V850_OPERAND_CC
) == 0)
1932 errmsg
= _("syntax error: condition code not expected");
1937 /* start-sanitize-v850e */
1939 If we are assembling a MOV instruction (or a CALLT.... :-)
1940 and the immediate value does not fit into the bits
1941 available then create a fake error so that the next MOV
1942 instruction will be selected. This one has a 32 bit
1945 if (((insn
& 0x07e0) == 0x0200)
1946 && ex
.X_op
== O_constant
1947 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1)))
1948 || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
1949 errmsg
= _("immediate operand is too large");
1950 /* end-sanitize-v850e */
1956 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n",
1957 insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
1962 errmsg
= _("illegal operand");
1965 errmsg
= _("missing operand");
1968 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
1970 errmsg
= _("invalid operand");
1973 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1975 copy_of_instruction
);
1979 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1981 copy_of_instruction
);
1985 /* We need to generate a fixup for this expression. */
1986 if (fc
>= MAX_INSN_FIXUPS
)
1987 as_fatal (_("too many fixups"));
1989 fixups
[ fc
].exp
= ex
;
1990 fixups
[ fc
].opindex
= * opindex_ptr
;
1991 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
1997 str
= input_line_pointer
;
1998 input_line_pointer
= hold
;
2000 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
2009 next_opcode
= opcode
+ 1;
2010 if (next_opcode
->name
!= NULL
2011 && strcmp (next_opcode
->name
, opcode
->name
) == 0)
2013 opcode
= next_opcode
;
2015 /* Skip versions that are not supported by the target
2017 if ((opcode
->processors
& processor_mask
) == 0)
2023 as_bad ("%s: %s", copy_of_instruction
, errmsg
);
2025 if (* input_line_pointer
== ']')
2026 ++ input_line_pointer
;
2028 ignore_rest_of_line ();
2029 input_line_pointer
= saved_input_line_pointer
;
2035 while (isspace (*str
))
2039 /* xgettext:c-format */
2040 as_bad (_("junk at end of line: `%s'"), str
);
2042 input_line_pointer
= str
;
2044 /* Write out the instruction. */
2046 if (relaxable
&& fc
> 0)
2051 if (!strcmp (opcode
->name
, "br"))
2053 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
2054 fixups
[0].exp
.X_add_symbol
,
2055 fixups
[0].exp
.X_add_number
,
2056 (char *)fixups
[0].opindex
);
2057 md_number_to_chars (f
, insn
, insn_size
);
2058 md_number_to_chars (f
+ 2, 0, 2);
2062 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
2063 fixups
[0].exp
.X_add_symbol
,
2064 fixups
[0].exp
.X_add_number
,
2065 (char *)fixups
[0].opindex
);
2066 md_number_to_chars (f
, insn
, insn_size
);
2067 md_number_to_chars (f
+ 2, 0, 4);
2072 /* Four byte insns have an opcode with the two high bits on. */
2073 if ((insn
& 0x0600) == 0x0600)
2078 /* start-sanitize-v850e */
2079 /* Special case: 32 bit MOV */
2080 if ((insn
& 0xffe0) == 0x0620)
2082 /* end-sanitize-v850e */
2084 f
= frag_more (insn_size
);
2086 md_number_to_chars (f
, insn
, insn_size
);
2088 if (extra_data_after_insn
)
2090 f
= frag_more (extra_data_len
);
2092 md_number_to_chars (f
, extra_data
, extra_data_len
);
2094 extra_data_after_insn
= false;
2098 /* Create any fixups. At this point we do not use a
2099 bfd_reloc_code_real_type, but instead just use the
2100 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2101 handle fixups for any operand type, although that is admittedly
2102 not a very exciting feature. We pick a BFD reloc type in
2104 for (i
= 0; i
< fc
; i
++)
2106 const struct v850_operand
* operand
;
2107 bfd_reloc_code_real_type reloc
;
2109 operand
= & v850_operands
[ fixups
[i
].opindex
];
2111 reloc
= fixups
[i
].reloc
;
2113 if (reloc
!= BFD_RELOC_UNUSED
)
2115 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
2124 size
= bfd_get_reloc_size (reloc_howto
);
2126 /* XXX This will abort on an R_V850_8 reloc -
2127 is this reloc actually used ? */
2128 if (size
!= 2 && size
!= 4)
2131 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
2133 if (reloc
== BFD_RELOC_32
)
2138 fixP
= fix_new_exp (frag_now
, address
, size
,
2140 reloc_howto
->pc_relative
,
2145 case BFD_RELOC_LO16
:
2146 case BFD_RELOC_HI16
:
2147 case BFD_RELOC_HI16_S
:
2148 fixP
->fx_no_overflow
= 1;
2156 f
- frag_now
->fr_literal
, 4,
2158 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2159 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
2160 + (int) BFD_RELOC_UNUSED
)
2165 input_line_pointer
= saved_input_line_pointer
;
2169 /* If while processing a fixup, a reloc really needs to be created */
2170 /* then it is done here. */
2173 tc_gen_reloc (seg
, fixp
)
2179 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2180 reloc
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
2181 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2182 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2184 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2186 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2187 /* xgettext:c-format */
2188 _("reloc %d not supported by object file format"),
2189 (int)fixp
->fx_r_type
);
2196 reloc
->addend
= fixp
->fx_addnumber
;
2201 /* Assume everything will fit in two bytes, then expand as necessary. */
2203 md_estimate_size_before_relax (fragp
, seg
)
2207 if (fragp
->fr_subtype
== 0)
2209 else if (fragp
->fr_subtype
== 2)
2217 md_pcrel_from (fixp
)
2220 /* If the symbol is undefined, or in a section other than our own,
2221 then let the linker figure it out. */
2222 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
2224 /* The symbol is undefined. Let the linker figure it out. */
2227 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2231 md_apply_fix3 (fixp
, valuep
, seg
)
2239 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2244 else if (fixp
->fx_pcrel
)
2248 value
= fixp
->fx_offset
;
2249 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2251 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2252 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2255 /* We don't actually support subtracting a symbol. */
2256 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2257 _("expression too complex"));
2262 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2265 const struct v850_operand
* operand
;
2268 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2269 operand
= & v850_operands
[ opindex
];
2271 /* Fetch the instruction, insert the fully resolved operand
2272 value, and stuff the instruction back again.
2274 Note the instruction has been stored in little endian
2276 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2278 insn
= bfd_getl32 ((unsigned char *) where
);
2279 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2280 fixp
->fx_file
, fixp
->fx_line
, NULL
);
2281 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2285 /* Nothing else to do here. */
2289 /* Determine a BFD reloc value based on the operand information.
2290 We are only prepared to turn a few of the operands into relocs. */
2292 if (operand
->bits
== 22)
2293 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2294 else if (operand
->bits
== 9)
2295 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2298 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2300 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
2301 _("unresolved expression that must be resolved"));
2306 else if (fixp
->fx_done
)
2308 /* We still have to insert the value into memory! */
2309 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2311 if (fixp
->fx_size
== 1)
2312 *where
= value
& 0xff;
2313 else if (fixp
->fx_size
== 2)
2314 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2315 else if (fixp
->fx_size
== 4)
2316 bfd_putl32 (value
, (unsigned char *) where
);
2319 fixp
->fx_addnumber
= value
;
2324 /* Parse a cons expression. We have to handle hi(), lo(), etc
2327 parse_cons_expression_v850 (exp
)
2330 /* See if there's a reloc prefix like hi() we have to handle. */
2331 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2333 /* Do normal expression parsing. */
2337 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2338 found a reloc prefix, then we use that reloc, else we choose an
2339 appropriate one based on the size of the expression. */
2341 cons_fix_new_v850 (frag
, where
, size
, exp
)
2347 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2350 hold_cons_reloc
= BFD_RELOC_32
;
2352 hold_cons_reloc
= BFD_RELOC_16
;
2354 hold_cons_reloc
= BFD_RELOC_8
;
2358 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2360 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);