1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "opcode/v850.h"
31 /* sign-extend a 16-bit number */
32 #define SEXT16(x) ((((x) & 0xffff) ^ (~ 0x7fff)) + 0x8000)
34 /* Temporarily holds the reloc in a cons expression. */
35 static bfd_reloc_code_real_type hold_cons_reloc
;
37 /* Set to TRUE if we want to be pedantic about signed overflows. */
38 static boolean warn_signed_overflows
= FALSE
;
39 static boolean warn_unsigned_overflows
= FALSE
;
41 /* Indicates the target BFD machine number. */
42 static int machine
= -1;
44 /* Indicates the target processor(s) for the assemble. */
45 static int processor_mask
= -1;
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 static segT call_table_data_section
= NULL
;
99 static segT call_table_text_section
= NULL
;
102 #define MAX_INSN_FIXUPS (5)
107 bfd_reloc_code_real_type reloc
;
110 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
115 v850_sdata (int ignore ATTRIBUTE_UNUSED
)
117 obj_elf_section_change_hook();
119 subseg_set (sdata_section
, (subsegT
) get_absolute_expression ());
121 demand_empty_rest_of_line ();
125 v850_tdata (int ignore ATTRIBUTE_UNUSED
)
127 obj_elf_section_change_hook();
129 subseg_set (tdata_section
, (subsegT
) get_absolute_expression ());
131 demand_empty_rest_of_line ();
135 v850_zdata (int ignore ATTRIBUTE_UNUSED
)
137 obj_elf_section_change_hook();
139 subseg_set (zdata_section
, (subsegT
) get_absolute_expression ());
141 demand_empty_rest_of_line ();
145 v850_sbss (int ignore ATTRIBUTE_UNUSED
)
147 obj_elf_section_change_hook();
149 subseg_set (sbss_section
, (subsegT
) get_absolute_expression ());
151 demand_empty_rest_of_line ();
155 v850_tbss (int ignore ATTRIBUTE_UNUSED
)
157 obj_elf_section_change_hook();
159 subseg_set (tbss_section
, (subsegT
) get_absolute_expression ());
161 demand_empty_rest_of_line ();
165 v850_zbss (int ignore ATTRIBUTE_UNUSED
)
167 obj_elf_section_change_hook();
169 subseg_set (zbss_section
, (subsegT
) get_absolute_expression ());
171 demand_empty_rest_of_line ();
175 v850_rosdata (int ignore ATTRIBUTE_UNUSED
)
177 obj_elf_section_change_hook();
179 subseg_set (rosdata_section
, (subsegT
) get_absolute_expression ());
181 demand_empty_rest_of_line ();
185 v850_rozdata (int ignore ATTRIBUTE_UNUSED
)
187 obj_elf_section_change_hook();
189 subseg_set (rozdata_section
, (subsegT
) get_absolute_expression ());
191 demand_empty_rest_of_line ();
195 v850_call_table_data (int ignore ATTRIBUTE_UNUSED
)
197 obj_elf_section_change_hook();
199 subseg_set (call_table_data_section
, (subsegT
) get_absolute_expression ());
201 demand_empty_rest_of_line ();
205 v850_call_table_text (int ignore ATTRIBUTE_UNUSED
)
207 obj_elf_section_change_hook();
209 subseg_set (call_table_text_section
, (subsegT
) get_absolute_expression ());
211 demand_empty_rest_of_line ();
215 v850_bss (int ignore ATTRIBUTE_UNUSED
)
217 register int temp
= get_absolute_expression ();
219 obj_elf_section_change_hook();
221 subseg_set (bss_section
, (subsegT
) temp
);
223 demand_empty_rest_of_line ();
227 v850_offset (int ignore ATTRIBUTE_UNUSED
)
229 int temp
= get_absolute_expression ();
231 temp
-= frag_now_fix();
234 (void) frag_more (temp
);
236 demand_empty_rest_of_line ();
239 /* Copied from obj_elf_common() in gas/config/obj-elf.c */
252 name
= input_line_pointer
;
253 c
= get_symbol_end ();
255 /* just after name is now '\0' */
256 p
= input_line_pointer
;
261 if (*input_line_pointer
!= ',')
263 as_bad (_("Expected comma after symbol-name"));
264 ignore_rest_of_line ();
268 input_line_pointer
++; /* skip ',' */
270 if ((temp
= get_absolute_expression ()) < 0)
272 /* xgettext:c-format */
273 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp
);
274 ignore_rest_of_line ();
280 symbolP
= symbol_find_or_make (name
);
283 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
285 as_bad (_("Ignoring attempt to re-define symbol"));
286 ignore_rest_of_line ();
290 if (S_GET_VALUE (symbolP
) != 0)
292 if (S_GET_VALUE (symbolP
) != size
)
294 /* xgettext:c-format */
295 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
296 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
300 know (symbol_get_frag (symbolP
) == & zero_address_frag
);
302 if (*input_line_pointer
!= ',')
307 input_line_pointer
++;
311 if (! have_align
|| *input_line_pointer
!= '"')
317 temp
= get_absolute_expression ();
322 as_warn (_("Common alignment negative; 0 assumed"));
326 if (symbol_get_obj (symbolP
)->local
)
335 old_subsec
= now_subseg
;
337 applicable
= bfd_applicable_section_flags (stdoutput
);
339 applicable
&= SEC_ALLOC
;
344 if (sbss_section
== NULL
)
346 sbss_section
= subseg_new (".sbss", 0);
348 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
);
350 seg_info (sbss_section
)->bss
= 1;
355 if (zbss_section
== NULL
)
357 zbss_section
= subseg_new (".zbss", 0);
359 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
);
361 seg_info (zbss_section
)->bss
= 1;
366 if (tbss_section
== NULL
)
368 tbss_section
= subseg_new (".tbss", 0);
370 bfd_set_section_flags (stdoutput
, tbss_section
, applicable
);
372 seg_info (tbss_section
)->bss
= 1;
379 /* convert to a power of 2 alignment */
380 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
)
385 as_bad (_("Common alignment not a power of 2"));
386 ignore_rest_of_line ();
396 record_alignment (sbss_section
, align
);
397 obj_elf_section_change_hook();
398 subseg_set (sbss_section
, 0);
402 record_alignment (zbss_section
, align
);
403 obj_elf_section_change_hook();
404 subseg_set (zbss_section
, 0);
408 record_alignment (tbss_section
, align
);
409 obj_elf_section_change_hook();
410 subseg_set (tbss_section
, 0);
418 frag_align (align
, 0, 0);
423 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
424 symbol_get_frag (symbolP
)->fr_symbol
= 0;
428 if (S_GET_SEGMENT (symbolP
) == zbss_section
)
429 symbol_get_frag (symbolP
)->fr_symbol
= 0;
433 if (S_GET_SEGMENT (symbolP
) == tbss_section
)
434 symbol_get_frag (symbolP
)->fr_symbol
= 0;
441 symbol_set_frag (symbolP
, frag_now
);
442 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
443 (offsetT
) size
, (char *) 0);
445 S_SET_SIZE (symbolP
, size
);
450 S_SET_SEGMENT (symbolP
, sbss_section
);
454 S_SET_SEGMENT (symbolP
, zbss_section
);
458 S_SET_SEGMENT (symbolP
, tbss_section
);
465 S_CLEAR_EXTERNAL (symbolP
);
466 obj_elf_section_change_hook();
467 subseg_set (old_sec
, old_subsec
);
472 S_SET_VALUE (symbolP
, (valueT
) size
);
473 S_SET_ALIGN (symbolP
, temp
);
474 S_SET_EXTERNAL (symbolP
);
479 if (scommon_section
== NULL
)
483 applicable
= bfd_applicable_section_flags (stdoutput
);
485 scommon_section
= subseg_new (".scommon", 0);
487 bfd_set_section_flags (stdoutput
, scommon_section
,
489 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
490 | SEC_HAS_CONTENTS
)) | SEC_IS_COMMON
);
492 S_SET_SEGMENT (symbolP
, scommon_section
);
496 if (zcommon_section
== NULL
)
500 applicable
= bfd_applicable_section_flags (stdoutput
);
502 zcommon_section
= subseg_new (".zcommon", 0);
504 bfd_set_section_flags (stdoutput
, zcommon_section
,
506 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
507 | SEC_HAS_CONTENTS
)) | SEC_IS_COMMON
);
509 S_SET_SEGMENT (symbolP
, zcommon_section
);
513 if (tcommon_section
== NULL
)
517 applicable
= bfd_applicable_section_flags (stdoutput
);
519 tcommon_section
= subseg_new (".tcommon", 0);
521 bfd_set_section_flags (stdoutput
, tcommon_section
,
523 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
524 | SEC_HAS_CONTENTS
)) | SEC_IS_COMMON
);
526 S_SET_SEGMENT (symbolP
, tcommon_section
);
536 input_line_pointer
++;
537 /* @@ Some use the dot, some don't. Can we get some consistency?? */
538 if (*input_line_pointer
== '.')
539 input_line_pointer
++;
540 /* @@ Some say data, some say bss. */
541 if (strncmp (input_line_pointer
, "bss\"", 4)
542 && strncmp (input_line_pointer
, "data\"", 5))
544 while (*--input_line_pointer
!= '"')
546 input_line_pointer
--;
547 goto bad_common_segment
;
549 while (*input_line_pointer
++ != '"')
551 goto allocate_common
;
554 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
556 demand_empty_rest_of_line ();
561 p
= input_line_pointer
;
562 while (*p
&& *p
!= '\n')
566 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
568 input_line_pointer
= p
;
569 ignore_rest_of_line ();
575 set_machine (int number
)
578 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
582 case 0: processor_mask
= PROCESSOR_V850
; break;
583 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
584 case bfd_mach_v850ea
: processor_mask
= PROCESSOR_V850EA
; break;
588 /* The target specific pseudo-ops which we support. */
589 const pseudo_typeS md_pseudo_table
[] =
591 {"sdata", v850_sdata
, 0},
592 {"tdata", v850_tdata
, 0},
593 {"zdata", v850_zdata
, 0},
594 {"sbss", v850_sbss
, 0},
595 {"tbss", v850_tbss
, 0},
596 {"zbss", v850_zbss
, 0},
597 {"rosdata", v850_rosdata
, 0},
598 {"rozdata", v850_rozdata
, 0},
599 {"bss", v850_bss
, 0},
600 {"offset", v850_offset
, 0},
602 {"zcomm", v850_comm
, AREA_ZDA
},
603 {"scomm", v850_comm
, AREA_SDA
},
604 {"tcomm", v850_comm
, AREA_TDA
},
605 {"v850", set_machine
, 0},
606 {"call_table_data", v850_call_table_data
, 0},
607 {"call_table_text", v850_call_table_text
, 0},
608 {"v850e", set_machine
, bfd_mach_v850e
},
609 {"v850ea", set_machine
, bfd_mach_v850ea
},
613 /* Opcode hash table. */
614 static struct hash_control
*v850_hash
;
616 /* This table is sorted. Suitable for searching by a binary search. */
617 static const struct reg_name pre_defined_registers
[] =
619 { "ep", 30 }, /* ep - element ptr */
620 { "gp", 4 }, /* gp - global ptr */
621 { "hp", 2 }, /* hp - handler stack ptr */
622 { "lp", 31 }, /* lp - link ptr */
655 { "sp", 3 }, /* sp - stack ptr */
656 { "tp", 5 }, /* tp - text ptr */
659 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
662 static const struct reg_name system_registers
[] =
676 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
678 static const struct reg_name system_list_registers
[] =
683 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
685 static const struct reg_name cc_names
[] =
710 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
712 /* reg_name_search does a binary search of the given register table
713 to see if "name" is a valid regiter name. Returns the register
714 number from the array on success, or -1 on failure. */
717 reg_name_search (regs
, regcount
, name
, accept_numbers
)
718 const struct reg_name
* regs
;
721 boolean accept_numbers
;
723 int middle
, low
, high
;
727 /* If the register name is a symbol, then evaluate it. */
728 if ((symbolP
= symbol_find (name
)) != NULL
)
730 /* If the symbol is an alias for another name then use that.
731 If the symbol is an alias for a number, then return the number. */
732 if (symbol_equated_p (symbolP
))
734 name
= S_GET_NAME (symbol_get_value_expression (symbolP
)->X_add_symbol
);
736 else if (accept_numbers
)
738 int reg
= S_GET_VALUE (symbolP
);
740 if (reg
>= 0 && reg
<= 31)
744 /* Otherwise drop through and try parsing name normally. */
752 middle
= (low
+ high
) / 2;
753 cmp
= strcasecmp (name
, regs
[middle
].name
);
759 return regs
[middle
].value
;
766 /* Summary of register_name().
768 * in: Input_line_pointer points to 1st char of operand.
770 * out: A expressionS.
771 * The operand may have been a register: in this case, X_op == O_register,
772 * X_add_number is set to the register number, and truth is returned.
773 * Input_line_pointer->(next non-blank) char after operand, or is in
774 * its original state.
777 register_name (expressionP
)
778 expressionS
* expressionP
;
785 /* Find the spelling of the operand */
786 start
= name
= input_line_pointer
;
788 c
= get_symbol_end ();
790 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
,
793 * input_line_pointer
= c
; /* put back the delimiting char */
795 /* look to see if it's in the register table */
798 expressionP
->X_op
= O_register
;
799 expressionP
->X_add_number
= reg_number
;
801 /* make the rest nice */
802 expressionP
->X_add_symbol
= NULL
;
803 expressionP
->X_op_symbol
= NULL
;
809 /* reset the line as if we had not done anything */
810 input_line_pointer
= start
;
816 /* Summary of system_register_name().
818 * in: Input_line_pointer points to 1st char of operand.
819 * expressionP points to an expression structure to be filled in.
820 * accept_numbers is true iff numerical register names may be used.
821 * accept_list_names is true iff the special names PS and SR may be
824 * out: A expressionS structure in expressionP.
825 * The operand may have been a register: in this case, X_op == O_register,
826 * X_add_number is set to the register number, and truth is returned.
827 * Input_line_pointer->(next non-blank) char after operand, or is in
828 * its original state.
831 system_register_name (expressionP
, accept_numbers
, accept_list_names
)
832 expressionS
* expressionP
;
833 boolean accept_numbers
;
834 boolean accept_list_names
;
841 /* Find the spelling of the operand */
842 start
= name
= input_line_pointer
;
844 c
= get_symbol_end ();
845 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
,
848 * input_line_pointer
= c
; /* put back the delimiting char */
853 input_line_pointer
= start
; /* reset input_line pointer */
855 if (isdigit (* input_line_pointer
))
857 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
859 /* Make sure that the register number is allowable. */
861 || (reg_number
> 5 && reg_number
< 16)
868 else if (accept_list_names
)
870 c
= get_symbol_end ();
871 reg_number
= reg_name_search (system_list_registers
,
872 SYSREGLIST_NAME_CNT
, name
, FALSE
);
874 * input_line_pointer
= c
; /* put back the delimiting char */
878 /* look to see if it's in the register table */
881 expressionP
->X_op
= O_register
;
882 expressionP
->X_add_number
= reg_number
;
884 /* make the rest nice */
885 expressionP
->X_add_symbol
= NULL
;
886 expressionP
->X_op_symbol
= NULL
;
892 /* reset the line as if we had not done anything */
893 input_line_pointer
= start
;
899 /* Summary of cc_name().
901 * in: Input_line_pointer points to 1st char of operand.
903 * out: A expressionS.
904 * The operand may have been a register: in this case, X_op == O_register,
905 * X_add_number is set to the register number, and truth is returned.
906 * Input_line_pointer->(next non-blank) char after operand, or is in
907 * its original state.
910 cc_name (expressionP
)
911 expressionS
* expressionP
;
918 /* Find the spelling of the operand */
919 start
= name
= input_line_pointer
;
921 c
= get_symbol_end ();
922 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
, FALSE
);
924 * input_line_pointer
= c
; /* put back the delimiting char */
926 /* look to see if it's in the register table */
929 expressionP
->X_op
= O_constant
;
930 expressionP
->X_add_number
= reg_number
;
932 /* make the rest nice */
933 expressionP
->X_add_symbol
= NULL
;
934 expressionP
->X_op_symbol
= NULL
;
940 /* reset the line as if we had not done anything */
941 input_line_pointer
= start
;
948 skip_white_space (void)
950 while ( * input_line_pointer
== ' '
951 || * input_line_pointer
== '\t')
952 ++ input_line_pointer
;
955 /* Summary of parse_register_list ().
957 * in: Input_line_pointer points to 1st char of a list of registers.
958 * insn is the partially constructed instruction.
959 * operand is the operand being inserted.
961 * out: NULL if the parse completed successfully, otherwise a
962 * pointer to an error message is returned. If the parse
963 * completes the correct bit fields in the instruction
966 * Parses register lists with the syntax:
974 * and also parses constant epxressions whoes bits indicate the
975 * registers in the lists. The LSB in the expression refers to
976 * the lowest numbered permissable register in the register list,
977 * and so on upwards. System registers are considered to be very
984 unsigned long * insn
,
985 const struct v850_operand
* operand
988 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 };
989 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 };
990 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 };
995 /* Select a register array to parse. */
996 switch (operand
->shift
)
998 case 0xffe00001: regs
= type1_regs
; break;
999 case 0xfff8000f: regs
= type2_regs
; break;
1000 case 0xfff8001f: regs
= type3_regs
; break;
1002 as_bad (_("unknown operand shift: %x\n"), operand
->shift
);
1003 return _("internal failure in parse_register_list");
1006 skip_white_space ();
1008 /* If the expression starts with a curly brace it is a register list.
1009 Otherwise it is a constant expression, whoes bits indicate which
1010 registers are to be included in the list. */
1012 if (* input_line_pointer
!= '{')
1019 if (exp
.X_op
!= O_constant
)
1020 return _("constant expression or register list expected");
1022 if (regs
== type1_regs
)
1024 if (exp
.X_add_number
& 0xFFFFF000)
1025 return _("high bits set in register list expression");
1027 for (reg
= 20; reg
< 32; reg
++)
1028 if (exp
.X_add_number
& (1 << (reg
- 20)))
1030 for (i
= 0; i
< 32; i
++)
1035 else if (regs
== type2_regs
)
1037 if (exp
.X_add_number
& 0xFFFE0000)
1038 return _("high bits set in register list expression");
1040 for (reg
= 1; reg
< 16; reg
++)
1041 if (exp
.X_add_number
& (1 << (reg
- 1)))
1043 for (i
= 0; i
< 32; i
++)
1048 if (exp
.X_add_number
& (1 << 15))
1051 if (exp
.X_add_number
& (1 << 16))
1052 * insn
|= (1 << 19);
1054 else /* regs == type3_regs */
1056 if (exp
.X_add_number
& 0xFFFE0000)
1057 return _("high bits set in register list expression");
1059 for (reg
= 16; reg
< 32; reg
++)
1060 if (exp
.X_add_number
& (1 << (reg
- 16)))
1062 for (i
= 0; i
< 32; i
++)
1067 if (exp
.X_add_number
& (1 << 16))
1068 * insn
|= (1 << 19);
1074 input_line_pointer
++;
1076 /* Parse the register list until a terminator (closing curly brace or
1077 new-line) is found. */
1080 if (register_name (& exp
))
1084 /* Locate the given register in the list, and if it is there,
1085 insert the corresponding bit into the instruction. */
1086 for (i
= 0; i
< 32; i
++)
1088 if (regs
[ i
] == exp
.X_add_number
)
1097 return _("illegal register included in list");
1100 else if (system_register_name (& exp
, true, true))
1102 if (regs
== type1_regs
)
1104 return _("system registers cannot be included in list");
1106 else if (exp
.X_add_number
== 5)
1108 if (regs
== type2_regs
)
1109 return _("PSW cannot be included in list");
1113 else if (exp
.X_add_number
< 4)
1116 return _("High value system registers cannot be included in list");
1118 else if (* input_line_pointer
== '}')
1120 input_line_pointer
++;
1123 else if (* input_line_pointer
== ',')
1125 input_line_pointer
++;
1128 else if (* input_line_pointer
== '-')
1130 /* We have encountered a range of registers: rX - rY */
1134 /* Skip the dash. */
1135 ++ input_line_pointer
;
1137 /* Get the second register in the range. */
1138 if (! register_name (& exp2
))
1140 return _("second register should follow dash in register list");
1141 exp2
.X_add_number
= exp
.X_add_number
;
1144 /* Add the rest of the registers in the range. */
1145 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1149 /* Locate the given register in the list, and if it is there,
1150 insert the corresponding bit into the instruction. */
1151 for (i
= 0; i
< 32; i
++)
1161 return _("illegal register included in list");
1169 skip_white_space ();
1175 CONST
char * md_shortopts
= "m:";
1177 struct option md_longopts
[] =
1179 {NULL
, no_argument
, NULL
, 0}
1181 size_t md_longopts_size
= sizeof md_longopts
;
1185 md_show_usage (stream
)
1188 fprintf (stream
, _(" V850 options:\n"));
1189 fprintf (stream
, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1190 fprintf (stream
, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1191 fprintf (stream
, _(" -mv850 The code is targeted at the v850\n"));
1192 fprintf (stream
, _(" -mv850e The code is targeted at the v850e\n"));
1193 fprintf (stream
, _(" -mv850ea The code is targeted at the v850ea\n"));
1194 fprintf (stream
, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1198 md_parse_option (c
, arg
)
1205 /* xgettext:c-format */
1206 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1210 if (strcmp (arg
, "warn-signed-overflow") == 0)
1212 warn_signed_overflows
= TRUE
;
1214 else if (strcmp (arg
, "warn-unsigned-overflow") == 0)
1216 warn_unsigned_overflows
= TRUE
;
1218 else if (strcmp (arg
, "v850") == 0)
1221 processor_mask
= PROCESSOR_V850
;
1223 else if (strcmp (arg
, "v850e") == 0)
1225 machine
= bfd_mach_v850e
;
1226 processor_mask
= PROCESSOR_V850E
;
1228 else if (strcmp (arg
, "v850ea") == 0)
1230 machine
= bfd_mach_v850ea
;
1231 processor_mask
= PROCESSOR_V850EA
;
1233 else if (strcmp (arg
, "v850any") == 0)
1235 machine
= 0; /* Tell the world that this is for any v850 chip. */
1236 processor_mask
= PROCESSOR_V850EA
; /* But support instructions for the extended versions. */
1240 /* xgettext:c-format */
1241 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1249 md_undefined_symbol (name
)
1250 char * name ATTRIBUTE_UNUSED
;
1256 md_atof (type
, litp
, sizep
)
1262 LITTLENUM_TYPE words
[4];
1278 return _("bad call to md_atof");
1281 t
= atof_ieee (input_line_pointer
, type
, words
);
1283 input_line_pointer
= t
;
1287 for (i
= prec
- 1; i
>= 0; i
--)
1289 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1299 md_convert_frag (abfd
, sec
, fragP
)
1300 bfd
* abfd ATTRIBUTE_UNUSED
;
1304 subseg_change (sec
, 0);
1306 /* In range conditional or unconditional branch. */
1307 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1309 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1310 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1314 /* Out of range conditional branch. Emit a branch around a jump. */
1315 else if (fragP
->fr_subtype
== 1)
1317 unsigned char *buffer
=
1318 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1320 /* Reverse the condition of the first branch. */
1322 /* Mask off all the displacement bits. */
1325 /* Now set the displacement bits so that we branch
1326 around the unconditional branch. */
1329 /* Now create the unconditional branch + fixup to the final
1331 md_number_to_chars (buffer
+ 2, 0x00000780, 4);
1332 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1333 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1334 (int) fragP
->fr_opcode
+ 1);
1338 /* Out of range unconditional branch. Emit a jump. */
1339 else if (fragP
->fr_subtype
== 3)
1341 md_number_to_chars (fragP
->fr_fix
+ fragP
->fr_literal
, 0x00000780, 4);
1342 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
1343 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1344 (int) fragP
->fr_opcode
+ 1);
1353 md_section_align (seg
, addr
)
1357 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1358 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1364 char * prev_name
= "";
1365 register const struct v850_opcode
* op
;
1366 flagword applicable
;
1368 if (strncmp (TARGET_CPU
, "v850ea", 6) == 0)
1371 machine
= bfd_mach_v850ea
;
1373 if (processor_mask
== -1)
1374 processor_mask
= PROCESSOR_V850EA
;
1376 else if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1379 machine
= bfd_mach_v850e
;
1381 if (processor_mask
== -1)
1382 processor_mask
= PROCESSOR_V850E
;
1385 if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1390 if (processor_mask
== -1)
1391 processor_mask
= PROCESSOR_V850
;
1394 /* xgettext:c-format */
1395 as_bad (_("Unable to determine default target processor from string: %s"),
1398 v850_hash
= hash_new();
1400 /* Insert unique names into hash table. The V850 instruction set
1401 has many identical opcode names that have different opcodes based
1402 on the operands. This hash table then provides a quick index to
1403 the first opcode with a particular name in the opcode table. */
1408 if (strcmp (prev_name
, op
->name
))
1410 prev_name
= (char *) op
->name
;
1411 hash_insert (v850_hash
, op
->name
, (char *) op
);
1416 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1418 applicable
= bfd_applicable_section_flags (stdoutput
);
1420 call_table_data_section
= subseg_new (".call_table_data", 0);
1421 bfd_set_section_flags (stdoutput
, call_table_data_section
,
1422 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
1423 | SEC_DATA
| SEC_HAS_CONTENTS
));
1425 call_table_text_section
= subseg_new (".call_table_text", 0);
1426 bfd_set_section_flags (stdoutput
, call_table_text_section
,
1427 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1430 /* Restore text section as the current default. */
1431 subseg_set (text_section
, 0);
1435 static bfd_reloc_code_real_type
1436 handle_ctoff (const struct v850_operand
* operand
)
1438 if (operand
== NULL
)
1439 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1441 if ( operand
->bits
!= 6
1442 || operand
->shift
!= 0)
1444 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1445 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1448 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1451 static bfd_reloc_code_real_type
1452 handle_sdaoff (const struct v850_operand
* operand
)
1454 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1455 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1456 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1458 if ( operand
->bits
!= 16
1459 || operand
->shift
!= 16)
1461 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1462 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1465 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1468 static bfd_reloc_code_real_type
1469 handle_zdaoff (const struct v850_operand
* operand
)
1471 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1472 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1473 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1475 if ( operand
->bits
!= 16
1476 || operand
->shift
!= 16)
1478 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1479 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1482 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1485 static bfd_reloc_code_real_type
1486 handle_tdaoff (const struct v850_operand
* operand
)
1488 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
; /* data item, not an instruction. */
1489 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
; /* sld.w/sst.w, operand: D8_6 */
1490 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
; /* sld.hu, operand: D5-4 */
1491 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
; /* sld.bu, operand: D4 */
1492 if (operand
->bits
== 16 && operand
->shift
== 16) return BFD_RELOC_V850_TDA_16_16_OFFSET
; /* set1 & chums, operands: D16 */
1494 if (operand
->bits
!= 7)
1496 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1497 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1500 return operand
->insert
!= NULL
1501 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1502 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1505 /* Warning: The code in this function relies upon the definitions
1506 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1507 matching the hard coded values contained herein. */
1509 static bfd_reloc_code_real_type
1510 v850_reloc_prefix (const struct v850_operand
* operand
)
1512 boolean paren_skipped
= false;
1515 /* Skip leading opening parenthesis. */
1516 if (* input_line_pointer
== '(')
1518 ++ input_line_pointer
;
1519 paren_skipped
= true;
1522 #define CHECK_(name, reloc) \
1523 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1525 input_line_pointer += strlen (name); \
1529 CHECK_ ("hi0", BFD_RELOC_HI16
);
1530 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1531 CHECK_ ("lo", BFD_RELOC_LO16
);
1532 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1533 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1534 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1535 CHECK_ ("hilo", BFD_RELOC_32
);
1536 CHECK_ ("ctoff", handle_ctoff (operand
));
1538 /* Restore skipped parenthesis. */
1540 -- input_line_pointer
;
1542 return BFD_RELOC_UNUSED
;
1545 /* Insert an operand value into an instruction. */
1547 static unsigned long
1548 v850_insert_operand (insn
, operand
, val
, file
, line
, str
)
1550 const struct v850_operand
* operand
;
1556 if (operand
->insert
)
1558 const char * message
= NULL
;
1560 insn
= operand
->insert (insn
, val
, & message
);
1561 if (message
!= NULL
)
1563 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1564 && ! warn_signed_overflows
1565 && strstr (message
, "out of range") != NULL
)
1567 /* skip warning... */
1569 else if ((operand
->flags
& V850_OPERAND_SIGNED
) == 0
1570 && ! warn_unsigned_overflows
1571 && strstr (message
, "out of range") != NULL
)
1573 /* skip warning... */
1577 if (file
== (char *) NULL
)
1578 as_warn ("%s: %s", str
, message
);
1580 as_warn_where (file
, line
, "%s: %s", str
, message
);
1584 if (file
== (char *) NULL
)
1587 as_warn_where (file
, line
, message
);
1593 if (operand
->bits
!= 32)
1597 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1599 if (! warn_signed_overflows
)
1600 max
= (1 << operand
->bits
) - 1;
1602 max
= (1 << (operand
->bits
- 1)) - 1;
1604 min
= - (1 << (operand
->bits
- 1));
1608 max
= (1 << operand
->bits
) - 1;
1610 if (! warn_unsigned_overflows
)
1611 min
= - (1 << (operand
->bits
- 1));
1616 if (val
< (offsetT
) min
|| val
> (offsetT
) max
)
1618 /* xgettext:c-format */
1619 const char * err
= _("operand out of range (%s not between %ld and %ld)");
1622 /* Restore min and mix to expected values for decimal ranges. */
1623 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1624 && ! warn_signed_overflows
)
1625 max
= (1 << (operand
->bits
- 1)) - 1;
1627 if (! (operand
->flags
& V850_OPERAND_SIGNED
)
1628 && ! warn_unsigned_overflows
)
1633 sprintf (buf
, "%s: ", str
);
1635 sprint_value (buf
+ strlen (buf
), val
);
1638 sprint_value (buf
, val
);
1640 if (file
== (char *) NULL
)
1641 as_warn (err
, buf
, min
, max
);
1643 as_warn_where (file
, line
, err
, buf
, min
, max
);
1647 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1654 static char copy_of_instruction
[128];
1661 char * start_of_operands
;
1662 struct v850_opcode
* opcode
;
1663 struct v850_opcode
* next_opcode
;
1664 const unsigned char * opindex_ptr
;
1668 unsigned long insn_size
;
1672 boolean extra_data_after_insn
= false;
1673 unsigned extra_data_len
= 0;
1674 unsigned long extra_data
= 0;
1675 char * saved_input_line_pointer
;
1678 strncpy (copy_of_instruction
, str
, sizeof (copy_of_instruction
) - 1);
1680 /* Get the opcode. */
1681 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1687 /* find the first opcode with the proper name */
1688 opcode
= (struct v850_opcode
*) hash_find (v850_hash
, str
);
1691 /* xgettext:c-format */
1692 as_bad (_("Unrecognized opcode: `%s'"), str
);
1693 ignore_rest_of_line ();
1698 while (isspace (* str
))
1701 start_of_operands
= str
;
1703 saved_input_line_pointer
= input_line_pointer
;
1707 const char * errmsg
= NULL
;
1711 if ((opcode
->processors
& processor_mask
) == 0)
1713 errmsg
= _("Target processor does not support this instruction.");
1720 insn
= opcode
->opcode
;
1721 extra_data_after_insn
= false;
1723 input_line_pointer
= str
= start_of_operands
;
1725 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1727 const struct v850_operand
* operand
;
1730 bfd_reloc_code_real_type reloc
;
1732 if (next_opindex
== 0)
1734 operand
= & v850_operands
[ * opindex_ptr
];
1738 operand
= & v850_operands
[ next_opindex
];
1744 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1747 if (operand
->flags
& V850_OPERAND_RELAX
)
1750 /* Gather the operand. */
1751 hold
= input_line_pointer
;
1752 input_line_pointer
= str
;
1754 /* lo(), hi(), hi0(), etc... */
1755 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1757 /* This is a fake reloc, used to indicate an error condition. */
1758 if (reloc
== BFD_RELOC_64
)
1766 if (ex
.X_op
== O_constant
)
1770 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1771 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1775 case BFD_RELOC_LO16
:
1777 /* Truncate, then sign extend the value. */
1778 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1782 case BFD_RELOC_HI16
:
1784 /* Truncate, then sign extend the value. */
1785 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1789 case BFD_RELOC_HI16_S
:
1791 /* Truncate, then sign extend the value. */
1792 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1794 temp
+= (ex
.X_add_number
>> 15) & 1;
1796 ex
.X_add_number
= SEXT16 (temp
);
1801 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1803 errmsg
= _("immediate operand is too large");
1807 extra_data_after_insn
= true;
1809 extra_data
= ex
.X_add_number
;
1810 ex
.X_add_number
= 0;
1814 fprintf (stderr
, "reloc: %d\n", reloc
);
1815 as_bad (_("AAARG -> unhandled constant reloc"));
1819 if (fc
> MAX_INSN_FIXUPS
)
1820 as_fatal (_("too many fixups"));
1822 fixups
[ fc
].exp
= ex
;
1823 fixups
[ fc
].opindex
= * opindex_ptr
;
1824 fixups
[ fc
].reloc
= reloc
;
1829 if (reloc
== BFD_RELOC_32
)
1831 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1833 errmsg
= _("immediate operand is too large");
1837 extra_data_after_insn
= true;
1839 extra_data
= ex
.X_add_number
;
1842 if (fc
> MAX_INSN_FIXUPS
)
1843 as_fatal (_("too many fixups"));
1845 fixups
[ fc
].exp
= ex
;
1846 fixups
[ fc
].opindex
= * opindex_ptr
;
1847 fixups
[ fc
].reloc
= reloc
;
1855 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1857 if (!register_name (& ex
))
1859 errmsg
= _("invalid register name");
1861 else if ((operand
->flags
& V850_NOT_R0
)
1862 && ex
.X_add_number
== 0)
1864 errmsg
= _("register r0 cannot be used here");
1866 /* Force an error message to be generated by
1867 skipping over any following potential matches
1872 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1874 if (!system_register_name (& ex
, true, false))
1876 errmsg
= _("invalid system register name");
1879 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1881 char * start
= input_line_pointer
;
1882 char c
= get_symbol_end ();
1884 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1886 /* Put things back the way we found them. */
1887 *input_line_pointer
= c
;
1888 input_line_pointer
= start
;
1889 errmsg
= _("expected EP register");
1893 *input_line_pointer
= c
;
1894 str
= input_line_pointer
;
1895 input_line_pointer
= hold
;
1897 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1901 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1903 if (!cc_name (& ex
))
1905 errmsg
= _("invalid condition code name");
1908 else if (operand
->flags
& V850E_PUSH_POP
)
1910 errmsg
= parse_register_list (& insn
, operand
);
1912 /* The parse_register_list() function has already done
1913 everything, so fake a dummy expression. */
1914 ex
.X_op
= O_constant
;
1915 ex
.X_add_number
= 0;
1917 else if (operand
->flags
& V850E_IMMEDIATE16
)
1921 if (ex
.X_op
!= O_constant
)
1922 errmsg
= _("constant expression expected");
1923 else if (ex
.X_add_number
& 0xffff0000)
1925 if (ex
.X_add_number
& 0xffff)
1926 errmsg
= _("constant too big to fit into instruction");
1927 else if ((insn
& 0x001fffc0) == 0x00130780)
1928 ex
.X_add_number
>>= 16;
1930 errmsg
= _("constant too big to fit into instruction");
1933 extra_data_after_insn
= true;
1935 extra_data
= ex
.X_add_number
;
1936 ex
.X_add_number
= 0;
1938 else if (operand
->flags
& V850E_IMMEDIATE32
)
1942 if (ex
.X_op
!= O_constant
)
1943 errmsg
= _("constant expression expected");
1945 extra_data_after_insn
= true;
1947 extra_data
= ex
.X_add_number
;
1948 ex
.X_add_number
= 0;
1950 else if (register_name (& ex
)
1951 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1956 /* It is possible that an alias has been defined that
1957 matches a register name. For example the code may
1958 include a ".set ZERO, 0" directive, which matches
1959 the register name "zero". Attempt to reparse the
1960 field as an expression, and only complain if we
1961 cannot generate a constant. */
1963 input_line_pointer
= str
;
1965 c
= get_symbol_end ();
1967 if (symbol_find (str
) != NULL
)
1970 * input_line_pointer
= c
;
1971 input_line_pointer
= str
;
1975 if (ex
.X_op
!= O_constant
)
1977 /* If this register is actually occuring too early on
1978 the parsing of the instruction, (because another
1979 field is missing) then report this. */
1980 if (opindex_ptr
[1] != 0
1981 && (v850_operands
[opindex_ptr
[1]].flags
& V850_OPERAND_REG
))
1982 errmsg
= _("syntax error: value is missing before the register name");
1984 errmsg
= _("syntax error: register not expected");
1986 /* If we created a symbol in the process of this test then
1987 delete it now, so that it will not be output with the real
1990 && ex
.X_op
== O_symbol
)
1991 symbol_remove (ex
.X_add_symbol
,
1992 & symbol_rootP
, & symbol_lastP
);
1995 else if (system_register_name (& ex
, false, false)
1996 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1998 errmsg
= _("syntax error: system register not expected");
2000 else if (cc_name (&ex
)
2001 && (operand
->flags
& V850_OPERAND_CC
) == 0)
2003 errmsg
= _("syntax error: condition code not expected");
2009 If we are assembling a MOV instruction (or a CALLT.... :-)
2010 and the immediate value does not fit into the bits
2011 available then create a fake error so that the next MOV
2012 instruction will be selected. This one has a 32 bit
2015 if (((insn
& 0x07e0) == 0x0200)
2016 && ex
.X_op
== O_constant
2017 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1)))
2018 || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
2019 errmsg
= _("immediate operand is too large");
2025 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n",
2026 insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
2031 errmsg
= _("illegal operand");
2034 errmsg
= _("missing operand");
2037 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
2039 errmsg
= _("invalid operand");
2042 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2044 copy_of_instruction
);
2048 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2050 copy_of_instruction
);
2054 /* We need to generate a fixup for this expression. */
2055 if (fc
>= MAX_INSN_FIXUPS
)
2056 as_fatal (_("too many fixups"));
2058 fixups
[ fc
].exp
= ex
;
2059 fixups
[ fc
].opindex
= * opindex_ptr
;
2060 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
2066 str
= input_line_pointer
;
2067 input_line_pointer
= hold
;
2069 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
2078 next_opcode
= opcode
+ 1;
2079 if (next_opcode
->name
!= NULL
2080 && strcmp (next_opcode
->name
, opcode
->name
) == 0)
2082 opcode
= next_opcode
;
2084 /* Skip versions that are not supported by the target
2086 if ((opcode
->processors
& processor_mask
) == 0)
2092 as_bad ("%s: %s", copy_of_instruction
, errmsg
);
2094 if (* input_line_pointer
== ']')
2095 ++ input_line_pointer
;
2097 ignore_rest_of_line ();
2098 input_line_pointer
= saved_input_line_pointer
;
2104 while (isspace (*str
))
2108 /* xgettext:c-format */
2109 as_bad (_("junk at end of line: `%s'"), str
);
2111 input_line_pointer
= str
;
2113 /* Write out the instruction. */
2115 if (relaxable
&& fc
> 0)
2120 if (!strcmp (opcode
->name
, "br"))
2122 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
2123 fixups
[0].exp
.X_add_symbol
,
2124 fixups
[0].exp
.X_add_number
,
2125 (char *)fixups
[0].opindex
);
2126 md_number_to_chars (f
, insn
, insn_size
);
2127 md_number_to_chars (f
+ 2, 0, 2);
2131 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
2132 fixups
[0].exp
.X_add_symbol
,
2133 fixups
[0].exp
.X_add_number
,
2134 (char *)fixups
[0].opindex
);
2135 md_number_to_chars (f
, insn
, insn_size
);
2136 md_number_to_chars (f
+ 2, 0, 4);
2141 /* Four byte insns have an opcode with the two high bits on. */
2142 if ((insn
& 0x0600) == 0x0600)
2147 /* Special case: 32 bit MOV */
2148 if ((insn
& 0xffe0) == 0x0620)
2151 f
= frag_more (insn_size
);
2153 md_number_to_chars (f
, insn
, insn_size
);
2155 if (extra_data_after_insn
)
2157 f
= frag_more (extra_data_len
);
2159 md_number_to_chars (f
, extra_data
, extra_data_len
);
2161 extra_data_after_insn
= false;
2165 /* Create any fixups. At this point we do not use a
2166 bfd_reloc_code_real_type, but instead just use the
2167 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2168 handle fixups for any operand type, although that is admittedly
2169 not a very exciting feature. We pick a BFD reloc type in
2171 for (i
= 0; i
< fc
; i
++)
2173 const struct v850_operand
* operand
;
2174 bfd_reloc_code_real_type reloc
;
2176 operand
= & v850_operands
[ fixups
[i
].opindex
];
2178 reloc
= fixups
[i
].reloc
;
2180 if (reloc
!= BFD_RELOC_UNUSED
)
2182 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
2191 size
= bfd_get_reloc_size (reloc_howto
);
2193 /* XXX This will abort on an R_V850_8 reloc -
2194 is this reloc actually used ? */
2195 if (size
!= 2 && size
!= 4)
2198 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
2200 if (reloc
== BFD_RELOC_32
)
2205 fixP
= fix_new_exp (frag_now
, address
, size
,
2207 reloc_howto
->pc_relative
,
2212 case BFD_RELOC_LO16
:
2213 case BFD_RELOC_HI16
:
2214 case BFD_RELOC_HI16_S
:
2215 fixP
->fx_no_overflow
= 1;
2225 f
- frag_now
->fr_literal
, 4,
2227 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2228 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
2229 + (int) BFD_RELOC_UNUSED
)
2234 input_line_pointer
= saved_input_line_pointer
;
2238 /* If while processing a fixup, a reloc really needs to be created */
2239 /* then it is done here. */
2242 tc_gen_reloc (seg
, fixp
)
2243 asection
* seg ATTRIBUTE_UNUSED
;
2248 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2249 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2250 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2251 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2252 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2254 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2256 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2257 /* xgettext:c-format */
2258 _("reloc %d not supported by object file format"),
2259 (int) fixp
->fx_r_type
);
2266 if ( fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2267 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
)
2268 reloc
->addend
= fixp
->fx_offset
;
2270 reloc
->addend
= fixp
->fx_addnumber
;
2275 /* Assume everything will fit in two bytes, then expand as necessary. */
2277 md_estimate_size_before_relax (fragp
, seg
)
2279 asection
* seg ATTRIBUTE_UNUSED
;
2281 if (fragp
->fr_subtype
== 0)
2283 else if (fragp
->fr_subtype
== 2)
2291 v850_pcrel_from_section (fixp
, section
)
2295 /* If the symbol is undefined, or in a section other than our own,
2296 or it is weak (in which case it may well be in another section,
2297 then let the linker figure it out. */
2298 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2299 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2300 || S_IS_WEAK (fixp
->fx_addsy
)
2301 || (S_GET_SEGMENT (fixp
->fx_addsy
) != section
)))
2304 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2308 md_apply_fix3 (fixp
, valuep
, seg
)
2311 segT seg ATTRIBUTE_UNUSED
;
2316 if ( fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2317 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2323 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2328 else if (fixp
->fx_pcrel
)
2332 value
= fixp
->fx_offset
;
2333 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2335 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2336 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2339 /* We don't actually support subtracting a symbol. */
2340 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2341 _("expression too complex"));
2346 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2349 const struct v850_operand
* operand
;
2352 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2353 operand
= & v850_operands
[ opindex
];
2355 /* Fetch the instruction, insert the fully resolved operand
2356 value, and stuff the instruction back again.
2358 Note the instruction has been stored in little endian
2360 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2362 insn
= bfd_getl32 ((unsigned char *) where
);
2363 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2364 fixp
->fx_file
, fixp
->fx_line
, NULL
);
2365 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2369 /* Nothing else to do here. */
2373 /* Determine a BFD reloc value based on the operand information.
2374 We are only prepared to turn a few of the operands into relocs. */
2376 if (operand
->bits
== 22)
2377 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2378 else if (operand
->bits
== 9)
2379 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2382 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2384 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2385 _("unresolved expression that must be resolved"));
2390 else if (fixp
->fx_done
)
2392 /* We still have to insert the value into memory! */
2393 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2395 if (fixp
->fx_size
== 1)
2396 * where
= value
& 0xff;
2397 else if (fixp
->fx_size
== 2)
2398 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2399 else if (fixp
->fx_size
== 4)
2400 bfd_putl32 (value
, (unsigned char *) where
);
2403 fixp
->fx_addnumber
= value
;
2408 /* Parse a cons expression. We have to handle hi(), lo(), etc
2411 parse_cons_expression_v850 (exp
)
2414 /* See if there's a reloc prefix like hi() we have to handle. */
2415 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2417 /* Do normal expression parsing. */
2421 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2422 found a reloc prefix, then we use that reloc, else we choose an
2423 appropriate one based on the size of the expression. */
2425 cons_fix_new_v850 (frag
, where
, size
, exp
)
2431 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2434 hold_cons_reloc
= BFD_RELOC_32
;
2436 hold_cons_reloc
= BFD_RELOC_16
;
2438 hold_cons_reloc
= BFD_RELOC_8
;
2442 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2444 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);
2448 v850_fix_adjustable (fixP
)
2451 if (fixP
->fx_addsy
== NULL
)
2454 /* Prevent all adjustments to global symbols. */
2455 if (S_IS_EXTERN (fixP
->fx_addsy
))
2458 /* Similarly for weak symbols. */
2459 if (S_IS_WEAK (fixP
->fx_addsy
))
2462 /* Don't adjust function names */
2463 if (S_IS_FUNCTION (fixP
->fx_addsy
))
2466 /* We need the symbol name for the VTABLE entries */
2467 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2468 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2475 v850_force_relocation (fixP
)
2478 if (fixP
->fx_addsy
&& S_IS_WEAK (fixP
->fx_addsy
))
2481 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2482 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)