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 ();
259 /* just after name is now '\0' */
260 p
= input_line_pointer
;
265 if (*input_line_pointer
!= ',')
267 as_bad (_("Expected comma after symbol-name"));
268 ignore_rest_of_line ();
272 input_line_pointer
++; /* skip ',' */
274 if ((temp
= get_absolute_expression ()) < 0)
276 /* xgettext:c-format */
277 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp
);
278 ignore_rest_of_line ();
284 symbolP
= symbol_find_or_make (name
);
287 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
289 as_bad (_("Ignoring attempt to re-define symbol"));
290 ignore_rest_of_line ();
294 if (S_GET_VALUE (symbolP
) != 0)
296 if (S_GET_VALUE (symbolP
) != size
)
298 /* xgettext:c-format */
299 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
300 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
304 know (symbolP
->sy_frag
== & zero_address_frag
);
306 if (*input_line_pointer
!= ',')
311 input_line_pointer
++;
315 if (! have_align
|| *input_line_pointer
!= '"')
321 temp
= get_absolute_expression ();
325 as_warn (_("Common alignment negative; 0 assumed"));
338 old_subsec
= now_subseg
;
340 applicable
= bfd_applicable_section_flags (stdoutput
);
342 applicable
&= SEC_ALLOC
;
347 if (sbss_section
== NULL
)
349 sbss_section
= subseg_new (".sbss", 0);
351 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
);
353 seg_info (sbss_section
)->bss
= 1;
358 if (zbss_section
== NULL
)
360 zbss_section
= subseg_new (".zbss", 0);
362 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
);
364 seg_info (zbss_section
)->bss
= 1;
369 if (tbss_section
== NULL
)
371 tbss_section
= subseg_new (".tbss", 0);
373 bfd_set_section_flags (stdoutput
, tbss_section
, applicable
);
375 seg_info (tbss_section
)->bss
= 1;
382 /* convert to a power of 2 alignment */
383 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
)
388 as_bad (_("Common alignment not a power of 2"));
389 ignore_rest_of_line ();
399 record_alignment (sbss_section
, align
);
400 obj_elf_section_change_hook();
401 subseg_set (sbss_section
, 0);
405 record_alignment (zbss_section
, align
);
406 obj_elf_section_change_hook();
407 subseg_set (zbss_section
, 0);
411 record_alignment (tbss_section
, align
);
412 obj_elf_section_change_hook();
413 subseg_set (tbss_section
, 0);
421 frag_align (align
, 0, 0);
426 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
427 symbolP
->sy_frag
->fr_symbol
= 0;
431 if (S_GET_SEGMENT (symbolP
) == zbss_section
)
432 symbolP
->sy_frag
->fr_symbol
= 0;
436 if (S_GET_SEGMENT (symbolP
) == tbss_section
)
437 symbolP
->sy_frag
->fr_symbol
= 0;
444 symbolP
->sy_frag
= frag_now
;
445 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
446 (offsetT
) size
, (char *) 0);
448 S_SET_SIZE (symbolP
, size
);
453 S_SET_SEGMENT (symbolP
, sbss_section
);
457 S_SET_SEGMENT (symbolP
, zbss_section
);
461 S_SET_SEGMENT (symbolP
, tbss_section
);
468 S_CLEAR_EXTERNAL (symbolP
);
469 obj_elf_section_change_hook();
470 subseg_set (old_sec
, old_subsec
);
475 S_SET_VALUE (symbolP
, (valueT
) size
);
476 S_SET_ALIGN (symbolP
, temp
);
477 S_SET_EXTERNAL (symbolP
);
482 if (scommon_section
== NULL
)
486 applicable
= bfd_applicable_section_flags (stdoutput
);
488 scommon_section
= subseg_new (".scommon", 0);
490 bfd_set_section_flags (stdoutput
, scommon_section
, applicable
491 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
492 | SEC_HAS_CONTENTS
) | SEC_IS_COMMON
);
494 S_SET_SEGMENT (symbolP
, scommon_section
);
498 if (zcommon_section
== NULL
)
502 applicable
= bfd_applicable_section_flags (stdoutput
);
504 zcommon_section
= subseg_new (".zcommon", 0);
506 bfd_set_section_flags (stdoutput
, zcommon_section
, applicable
507 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
508 | SEC_HAS_CONTENTS
) | SEC_IS_COMMON
);
510 S_SET_SEGMENT (symbolP
, zcommon_section
);
514 if (tcommon_section
== NULL
)
518 applicable
= bfd_applicable_section_flags (stdoutput
);
520 tcommon_section
= subseg_new (".tcommon", 0);
522 bfd_set_section_flags (stdoutput
, tcommon_section
, applicable
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 symbolP
->bsym
->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 /* start-sanitize-v850e */
584 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
585 case bfd_mach_v850ea
: processor_mask
= PROCESSOR_V850EA
; break;
586 /* end-sanitize-v850e */
590 /* The target specific pseudo-ops which we support. */
591 const pseudo_typeS md_pseudo_table
[] =
593 {"sdata", v850_sdata
, 0},
594 {"tdata", v850_tdata
, 0},
595 {"zdata", v850_zdata
, 0},
596 {"sbss", v850_sbss
, 0},
597 {"tbss", v850_tbss
, 0},
598 {"zbss", v850_zbss
, 0},
599 {"rosdata", v850_rosdata
, 0},
600 {"rozdata", v850_rozdata
, 0},
601 {"bss", v850_bss
, 0},
602 {"offset", v850_offset
, 0},
604 {"zcomm", v850_comm
, AREA_ZDA
},
605 {"scomm", v850_comm
, AREA_SDA
},
606 {"tcomm", v850_comm
, AREA_TDA
},
607 {"v850", set_machine
, 0},
608 /* start-sanitize-v850e */
609 {"call_table_data", v850_call_table_data
, 0},
610 {"call_table_text", v850_call_table_text
, 0},
611 {"v850e", set_machine
, bfd_mach_v850e
},
612 {"v850ea", set_machine
, bfd_mach_v850ea
},
613 /* end-sanitize-v850e */
617 /* Opcode hash table. */
618 static struct hash_control
*v850_hash
;
620 /* This table is sorted. Suitable for searching by a binary search. */
621 static const struct reg_name pre_defined_registers
[] =
623 { "ep", 30 }, /* ep - element ptr */
624 { "gp", 4 }, /* gp - global ptr */
625 { "hp", 2 }, /* hp - handler stack ptr */
626 { "lp", 31 }, /* lp - link ptr */
659 { "sp", 3 }, /* sp - stack ptr */
660 { "tp", 5 }, /* tp - text ptr */
663 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
666 static const struct reg_name system_registers
[] =
668 /* start-sanitize-v850e */
674 /* end-sanitize-v850e */
682 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
684 /* start-sanitize-v850e */
685 static const struct reg_name system_list_registers
[] =
690 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
691 /* end-sanitize-v850e */
693 static const struct reg_name cc_names
[] =
718 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
720 /* reg_name_search does a binary search of the given register table
721 to see if "name" is a valid regiter name. Returns the register
722 number from the array on success, or -1 on failure. */
725 reg_name_search (regs
, regcount
, name
, accept_numbers
)
726 const struct reg_name
* regs
;
729 boolean accept_numbers
;
731 int middle
, low
, high
;
735 /* If the register name is a symbol, then evaluate it. */
736 if ((symbolP
= symbol_find (name
)) != NULL
)
738 /* If the symbol is an alias for another name then use that.
739 If the symbol is an alias for a number, then return the number. */
740 if (symbolP
->sy_value
.X_op
== O_symbol
)
742 name
= S_GET_NAME (symbolP
->sy_value
.X_add_symbol
);
744 else if (accept_numbers
)
746 int reg
= S_GET_VALUE (symbolP
);
748 if (reg
>= 0 && reg
<= 31)
758 middle
= (low
+ high
) / 2;
759 cmp
= strcasecmp (name
, regs
[middle
].name
);
765 return regs
[middle
].value
;
772 /* Summary of register_name().
774 * in: Input_line_pointer points to 1st char of operand.
776 * out: A expressionS.
777 * The operand may have been a register: in this case, X_op == O_register,
778 * X_add_number is set to the register number, and truth is returned.
779 * Input_line_pointer->(next non-blank) char after operand, or is in
780 * its original state.
783 register_name (expressionP
)
784 expressionS
* expressionP
;
791 /* Find the spelling of the operand */
792 start
= name
= input_line_pointer
;
794 c
= get_symbol_end ();
796 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
,
799 * input_line_pointer
= c
; /* put back the delimiting char */
801 /* look to see if it's in the register table */
804 expressionP
->X_op
= O_register
;
805 expressionP
->X_add_number
= reg_number
;
807 /* make the rest nice */
808 expressionP
->X_add_symbol
= NULL
;
809 expressionP
->X_op_symbol
= NULL
;
815 /* reset the line as if we had not done anything */
816 input_line_pointer
= start
;
822 /* Summary of system_register_name().
824 * in: Input_line_pointer points to 1st char of operand.
825 * expressionP points to an expression structure to be filled in.
826 * accept_numbers is true iff numerical register names may be used.
827 * start-sanitize-v850e
828 * accept_list_names is true iff the special names PS and SR may be
832 * out: A expressionS structure in expressionP.
833 * The operand may have been a register: in this case, X_op == O_register,
834 * X_add_number is set to the register number, and truth is returned.
835 * Input_line_pointer->(next non-blank) char after operand, or is in
836 * its original state.
839 system_register_name (expressionP
, accept_numbers
840 /* start-sanitize-v850e */
842 /* end-sanitize-v850e */
844 expressionS
* expressionP
;
845 boolean accept_numbers
;
846 /* start-sanitize-v850e */
847 boolean accept_list_names
;
848 /* end-sanitize-v850e */
855 /* Find the spelling of the operand */
856 start
= name
= input_line_pointer
;
858 c
= get_symbol_end ();
859 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
,
862 * input_line_pointer
= c
; /* put back the delimiting char */
867 input_line_pointer
= start
; /* reset input_line pointer */
869 if (isdigit (* input_line_pointer
))
871 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
873 /* Make sure that the register number is allowable. */
876 /* start-sanitize-v850e */
879 /* end-sanitize-v850e */
885 /* start-sanitize-v850e */
886 else if (accept_list_names
)
888 c
= get_symbol_end ();
889 reg_number
= reg_name_search (system_list_registers
,
890 SYSREGLIST_NAME_CNT
, name
, FALSE
);
892 * input_line_pointer
= c
; /* put back the delimiting char */
894 /* end-sanitize-v850e */
897 /* look to see if it's in the register table */
900 expressionP
->X_op
= O_register
;
901 expressionP
->X_add_number
= reg_number
;
903 /* make the rest nice */
904 expressionP
->X_add_symbol
= NULL
;
905 expressionP
->X_op_symbol
= NULL
;
911 /* reset the line as if we had not done anything */
912 input_line_pointer
= start
;
918 /* Summary of cc_name().
920 * in: Input_line_pointer points to 1st char of operand.
922 * out: A expressionS.
923 * The operand may have been a register: in this case, X_op == O_register,
924 * X_add_number is set to the register number, and truth is returned.
925 * Input_line_pointer->(next non-blank) char after operand, or is in
926 * its original state.
929 cc_name (expressionP
)
930 expressionS
* expressionP
;
937 /* Find the spelling of the operand */
938 start
= name
= input_line_pointer
;
940 c
= get_symbol_end ();
941 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
, FALSE
);
943 * input_line_pointer
= c
; /* put back the delimiting char */
945 /* look to see if it's in the register table */
948 expressionP
->X_op
= O_constant
;
949 expressionP
->X_add_number
= reg_number
;
951 /* make the rest nice */
952 expressionP
->X_add_symbol
= NULL
;
953 expressionP
->X_op_symbol
= NULL
;
959 /* reset the line as if we had not done anything */
960 input_line_pointer
= start
;
967 skip_white_space (void)
969 while ( * input_line_pointer
== ' '
970 || * input_line_pointer
== '\t')
971 ++ input_line_pointer
;
974 /* start-sanitize-v850e */
975 /* Summary of parse_register_list ().
977 * in: Input_line_pointer points to 1st char of a list of registers.
978 * insn is the partially constructed instruction.
979 * operand is the operand being inserted.
981 * out: NULL if the parse completed successfully, otherwise a
982 * pointer to an error message is returned. If the parse
983 * completes the correct bit fields in the instruction
986 * Parses register lists with the syntax:
994 * and also parses constant epxressions whoes bits indicate the
995 * registers in the lists. The LSB in the expression refers to
996 * the lowest numbered permissable register in the register list,
997 * and so on upwards. System registers are considered to be very
1004 unsigned long * insn
,
1005 const struct v850_operand
* operand
1008 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 };
1009 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 };
1010 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 };
1015 /* Select a register array to parse. */
1016 switch (operand
->shift
)
1018 case 0xffe00001: regs
= type1_regs
; break;
1019 case 0xfff8000f: regs
= type2_regs
; break;
1020 case 0xfff8001f: regs
= type3_regs
; break;
1022 as_bad (_("unknown operand shift: %x\n"), operand
->shift
);
1023 return _("internal failure in parse_register_list");
1028 /* If the expression starts with a curly brace it is a register list.
1029 Otherwise it is a constant expression, whoes bits indicate which
1030 registers are to be included in the list. */
1032 if (* input_line_pointer
!= '{')
1040 if (exp
.X_op
!= O_constant
)
1041 return _("constant expression or register list expected");
1043 if (regs
== type1_regs
)
1045 if (exp
.X_add_number
& 0xFFFFF000)
1046 return _("high bits set in register list expression");
1048 for (reg
= 20; reg
< 32; reg
++)
1049 if (exp
.X_add_number
& (1 << (reg
- 20)))
1051 for (i
= 0; i
< 32; i
++)
1056 else if (regs
== type2_regs
)
1058 if (exp
.X_add_number
& 0xFFFE0000)
1059 return _("high bits set in register list expression");
1061 for (reg
= 1; reg
< 16; reg
++)
1062 if (exp
.X_add_number
& (1 << (reg
- 1)))
1064 for (i
= 0; i
< 32; i
++)
1069 if (exp
.X_add_number
& (1 << 15))
1072 if (exp
.X_add_number
& (1 << 16))
1073 * insn
|= (1 << 19);
1075 else /* regs == type3_regs */
1077 if (exp
.X_add_number
& 0xFFFE0000)
1078 return _("high bits set in register list expression");
1080 for (reg
= 16; reg
< 32; reg
++)
1081 if (exp
.X_add_number
& (1 << (reg
- 16)))
1083 for (i
= 0; i
< 32; i
++)
1088 if (exp
.X_add_number
& (1 << 16))
1089 * insn
|= (1 << 19);
1095 input_line_pointer
++;
1097 /* Parse the register list until a terminator (closing curly brace or
1098 new-line) is found. */
1101 if (register_name (& exp
))
1105 /* Locate the given register in the list, and if it is there,
1106 insert the corresponding bit into the instruction. */
1107 for (i
= 0; i
< 32; i
++)
1109 if (regs
[ i
] == exp
.X_add_number
)
1118 return _("illegal register included in list");
1121 else if (system_register_name (& exp
, true, true))
1123 if (regs
== type1_regs
)
1125 return _("system registers cannot be included in list");
1127 else if (exp
.X_add_number
== 5)
1129 if (regs
== type2_regs
)
1130 return _("PSW cannot be included in list");
1134 else if (exp
.X_add_number
< 4)
1137 return _("High value system registers cannot be included in list");
1139 else if (* input_line_pointer
== '}')
1141 input_line_pointer
++;
1144 else if (* input_line_pointer
== ',')
1146 input_line_pointer
++;
1149 else if (* input_line_pointer
== '-')
1151 /* We have encountered a range of registers: rX - rY */
1155 /* Skip the dash. */
1156 ++ input_line_pointer
;
1158 /* Get the second register in the range. */
1159 if (! register_name (& exp2
))
1161 return _("second register should follow dash in register list");
1162 exp2
.X_add_number
= exp
.X_add_number
;
1165 /* Add the rest of the registers in the range. */
1166 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1170 /* Locate the given register in the list, and if it is there,
1171 insert the corresponding bit into the instruction. */
1172 for (i
= 0; i
< 32; i
++)
1182 return _("illegal register included in list");
1190 skip_white_space ();
1195 /* end-sanitize-v850e */
1197 CONST
char * md_shortopts
= "m:";
1199 struct option md_longopts
[] =
1201 {NULL
, no_argument
, NULL
, 0}
1203 size_t md_longopts_size
= sizeof md_longopts
;
1207 md_show_usage (stream
)
1210 fprintf (stream
, _(" V850 options:\n"));
1211 fprintf (stream
, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1212 fprintf (stream
, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1213 fprintf (stream
, _(" -mv850 The code is targeted at the v850\n"));
1214 /* start-sanitize-v850e */
1215 fprintf (stream
, _(" -mv850e The code is targeted at the v850e\n"));
1216 fprintf (stream
, _(" -mv850ea The code is targeted at the v850ea\n"));
1217 fprintf (stream
, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1218 /* end-sanitize-v850e */
1222 md_parse_option (c
, arg
)
1228 /* xgettext:c-format */
1229 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1233 if (strcmp (arg
, "warn-signed-overflow") == 0)
1235 warn_signed_overflows
= TRUE
;
1237 else if (strcmp (arg
, "warn-unsigned-overflow") == 0)
1239 warn_unsigned_overflows
= TRUE
;
1241 else if (strcmp (arg
, "v850") == 0)
1244 processor_mask
= PROCESSOR_V850
;
1246 /* start-sanitize-v850e */
1247 else if (strcmp (arg
, "v850e") == 0)
1249 machine
= bfd_mach_v850e
;
1250 processor_mask
= PROCESSOR_V850E
;
1252 else if (strcmp (arg
, "v850ea") == 0)
1254 machine
= bfd_mach_v850ea
;
1255 processor_mask
= PROCESSOR_V850EA
;
1257 else if (strcmp (arg
, "v850any") == 0)
1259 machine
= 0; /* Tell the world that this is for any v850 chip. */
1260 processor_mask
= PROCESSOR_V850EA
; /* But support instructions for the extended versions. */
1262 /* end-sanitize-v850e */
1265 /* xgettext:c-format */
1266 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1274 md_undefined_symbol (name
)
1281 md_atof (type
, litp
, sizep
)
1287 LITTLENUM_TYPE words
[4];
1303 return _("bad call to md_atof");
1306 t
= atof_ieee (input_line_pointer
, type
, words
);
1308 input_line_pointer
= t
;
1312 for (i
= prec
- 1; i
>= 0; i
--)
1314 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1324 md_convert_frag (abfd
, sec
, fragP
)
1329 subseg_change (sec
, 0);
1331 /* In range conditional or unconditional branch. */
1332 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1334 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1335 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1339 /* Out of range conditional branch. Emit a branch around a jump. */
1340 else if (fragP
->fr_subtype
== 1)
1342 unsigned char *buffer
=
1343 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1345 /* Reverse the condition of the first branch. */
1347 /* Mask off all the displacement bits. */
1350 /* Now set the displacement bits so that we branch
1351 around the unconditional branch. */
1354 /* Now create the unconditional branch + fixup to the final
1356 md_number_to_chars (buffer
+ 2, 0x00000780, 4);
1357 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1358 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int) fragP
->fr_opcode
1363 /* Out of range unconditional branch. Emit a jump. */
1364 else if (fragP
->fr_subtype
== 3)
1366 md_number_to_chars (fragP
->fr_fix
+ fragP
->fr_literal
, 0x00000780, 4);
1367 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
1368 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int) fragP
->fr_opcode
1378 md_section_align (seg
, addr
)
1382 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1383 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1389 char * prev_name
= "";
1390 register const struct v850_opcode
* op
;
1391 flagword applicable
;
1393 /* start-sanitize-v850e */
1394 if (strncmp (TARGET_CPU
, "v850ea", 6) == 0)
1397 machine
= bfd_mach_v850ea
;
1399 if (processor_mask
== -1)
1400 processor_mask
= PROCESSOR_V850EA
;
1402 else if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1405 machine
= bfd_mach_v850e
;
1407 if (processor_mask
== -1)
1408 processor_mask
= PROCESSOR_V850E
;
1411 /* end-sanitize-v850e */
1412 if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1417 if (processor_mask
== -1)
1418 processor_mask
= PROCESSOR_V850
;
1421 /* xgettext:c-format */
1422 as_bad (_("Unable to determine default target processor from string: %s"),
1425 v850_hash
= hash_new();
1427 /* Insert unique names into hash table. The V850 instruction set
1428 has many identical opcode names that have different opcodes based
1429 on the operands. This hash table then provides a quick index to
1430 the first opcode with a particular name in the opcode table. */
1435 if (strcmp (prev_name
, op
->name
))
1437 prev_name
= (char *) op
->name
;
1438 hash_insert (v850_hash
, op
->name
, (char *) op
);
1443 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1445 /* start-sanitize-v850e */
1446 call_table_data_section
= subseg_new (".call_table_data", 0);
1447 bfd_set_section_flags (stdoutput
, call_table_data_section
,
1448 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
1449 | SEC_DATA
| SEC_HAS_CONTENTS
));
1451 call_table_text_section
= subseg_new (".call_table_text", 0);
1452 bfd_set_section_flags (stdoutput
, call_table_text_section
,
1453 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
));
1455 /* Restore text section as the current default. */
1456 subseg_set (text_section
, 0);
1457 /* end-sanitize-v850e */
1462 /* start-sanitize-v850e */
1463 static bfd_reloc_code_real_type
1464 handle_ctoff (const struct v850_operand
* operand
)
1466 if (operand
== NULL
)
1467 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1469 if ( operand
->bits
!= 6
1470 || operand
->shift
!= 0)
1472 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1473 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1476 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1478 /* end-sanitize-v850e */
1480 static bfd_reloc_code_real_type
1481 handle_sdaoff (const struct v850_operand
* operand
)
1483 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1484 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1485 /* start-sanitize-v850e */
1486 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1487 /* end-sanitize-v850e */
1489 if ( operand
->bits
!= 16
1490 || operand
->shift
!= 16)
1492 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1493 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1496 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1499 static bfd_reloc_code_real_type
1500 handle_zdaoff (const struct v850_operand
* operand
)
1502 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1503 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1504 /* start-sanitize-v850e */
1505 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1506 /* end-sanitize-v850e */
1508 if ( operand
->bits
!= 16
1509 || operand
->shift
!= 16)
1511 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1512 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1515 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1518 static bfd_reloc_code_real_type
1519 handle_tdaoff (const struct v850_operand
* operand
)
1521 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
; /* data item, not an instruction. */
1522 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
; /* sld.w/sst.w, operand: D8_6 */
1523 /* start-sanitize-v850e */
1524 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
; /* sld.hu, operand: D5-4 */
1525 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
; /* sld.bu, operand: D4 */
1526 /* end-sanitize-v850e */
1527 if (operand
->bits
== 16 && operand
->shift
== 16) return BFD_RELOC_V850_TDA_16_16_OFFSET
; /* set1 & chums, operands: D16 */
1529 if (operand
->bits
!= 7)
1531 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1532 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1535 return operand
->insert
!= NULL
1536 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1537 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1540 /* Warning: The code in this function relies upon the definitions
1541 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1542 matching the hard coded values contained herein. */
1544 static bfd_reloc_code_real_type
1545 v850_reloc_prefix (const struct v850_operand
* operand
)
1547 boolean paren_skipped
= false;
1550 /* Skip leading opening parenthesis. */
1551 if (* input_line_pointer
== '(')
1553 ++ input_line_pointer
;
1554 paren_skipped
= true;
1557 #define CHECK_(name, reloc) \
1558 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1560 input_line_pointer += strlen (name); \
1564 CHECK_ ("hi0", BFD_RELOC_HI16
);
1565 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1566 CHECK_ ("lo", BFD_RELOC_LO16
);
1567 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1568 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1569 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1571 /* start-sanitize-v850e */
1572 CHECK_ ("hilo", BFD_RELOC_32
);
1573 CHECK_ ("ctoff", handle_ctoff (operand
));
1574 /* end-sanitize-v850e */
1576 /* Restore skipped parenthesis. */
1578 -- input_line_pointer
;
1580 return BFD_RELOC_UNUSED
;
1583 /* Insert an operand value into an instruction. */
1585 static unsigned long
1586 v850_insert_operand (insn
, operand
, val
, file
, line
, str
)
1588 const struct v850_operand
* operand
;
1594 if (operand
->insert
)
1596 const char * message
= NULL
;
1598 insn
= operand
->insert (insn
, val
, & message
);
1599 if (message
!= NULL
)
1601 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1602 && ! warn_signed_overflows
1603 && strstr (message
, "out of range") != NULL
)
1605 /* skip warning... */
1607 else if ((operand
->flags
& V850_OPERAND_SIGNED
) == 0
1608 && ! warn_unsigned_overflows
1609 && strstr (message
, "out of range") != NULL
)
1611 /* skip warning... */
1615 if (file
== (char *) NULL
)
1616 as_warn ("%s: %s", str
, message
);
1618 as_warn_where (file
, line
, "%s: %s", str
, message
);
1622 if (file
== (char *) NULL
)
1625 as_warn_where (file
, line
, message
);
1631 if (operand
->bits
!= 32)
1636 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1638 if (! warn_signed_overflows
)
1639 max
= (1 << operand
->bits
) - 1;
1641 max
= (1 << (operand
->bits
- 1)) - 1;
1643 min
= - (1 << (operand
->bits
- 1));
1647 max
= (1 << operand
->bits
) - 1;
1649 if (! warn_unsigned_overflows
)
1650 min
= - (1 << (operand
->bits
- 1));
1655 if (val
< (offsetT
) min
|| val
> (offsetT
) max
)
1657 /* xgettext:c-format */
1658 const char * err
= _("operand out of range (%s not between %ld and %ld)");
1661 /* Restore min and mix to expected values for decimal ranges. */
1662 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1663 && ! warn_signed_overflows
)
1664 max
= (1 << (operand
->bits
- 1)) - 1;
1666 if (! (operand
->flags
& V850_OPERAND_SIGNED
)
1667 && ! warn_unsigned_overflows
)
1672 sprintf (buf
, "%s: ", str
);
1674 sprint_value (buf
+ strlen (buf
), val
);
1677 sprint_value (buf
, val
);
1679 if (file
== (char *) NULL
)
1680 as_warn (err
, buf
, min
, max
);
1682 as_warn_where (file
, line
, err
, buf
, min
, max
);
1686 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1693 static char copy_of_instruction
[128];
1700 char * start_of_operands
;
1701 struct v850_opcode
* opcode
;
1702 struct v850_opcode
* next_opcode
;
1703 const unsigned char * opindex_ptr
;
1707 unsigned long insn_size
;
1711 boolean extra_data_after_insn
= false;
1712 unsigned extra_data_len
;
1713 unsigned long extra_data
;
1714 char * saved_input_line_pointer
;
1717 strncpy (copy_of_instruction
, str
, sizeof (copy_of_instruction
) - 1);
1719 /* Get the opcode. */
1720 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1726 /* find the first opcode with the proper name */
1727 opcode
= (struct v850_opcode
*) hash_find (v850_hash
, str
);
1730 /* xgettext:c-format */
1731 as_bad (_("Unrecognized opcode: `%s'"), str
);
1732 ignore_rest_of_line ();
1737 while (isspace (* str
))
1740 start_of_operands
= str
;
1742 saved_input_line_pointer
= input_line_pointer
;
1746 const char * errmsg
= NULL
;
1750 if ((opcode
->processors
& processor_mask
) == 0)
1752 errmsg
= _("Target processor does not support this instruction.");
1759 insn
= opcode
->opcode
;
1760 extra_data_after_insn
= false;
1762 input_line_pointer
= str
= start_of_operands
;
1764 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1766 const struct v850_operand
* operand
;
1769 bfd_reloc_code_real_type reloc
;
1771 if (next_opindex
== 0)
1773 operand
= & v850_operands
[ * opindex_ptr
];
1777 operand
= & v850_operands
[ next_opindex
];
1783 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1786 if (operand
->flags
& V850_OPERAND_RELAX
)
1789 /* Gather the operand. */
1790 hold
= input_line_pointer
;
1791 input_line_pointer
= str
;
1793 /* lo(), hi(), hi0(), etc... */
1794 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1796 /* This is a fake reloc, used to indicate an error condition. */
1797 if (reloc
== BFD_RELOC_64
)
1805 if (ex
.X_op
== O_constant
)
1809 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1810 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1814 case BFD_RELOC_LO16
:
1816 /* Truncate, then sign extend the value. */
1817 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1821 case BFD_RELOC_HI16
:
1823 /* Truncate, then sign extend the value. */
1824 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1828 case BFD_RELOC_HI16_S
:
1830 /* Truncate, then sign extend the value. */
1831 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1833 temp
+= (ex
.X_add_number
>> 15) & 1;
1835 ex
.X_add_number
= SEXT16 (temp
);
1839 /* start-sanitize-v850e */
1841 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1843 errmsg
= _("immediate operand is too large");
1847 extra_data_after_insn
= true;
1849 extra_data
= ex
.X_add_number
;
1850 ex
.X_add_number
= 0;
1852 /* end-sanitize-v850e */
1855 fprintf (stderr
, "reloc: %d\n", reloc
);
1856 as_bad (_("AAARG -> unhandled constant reloc"));
1860 if (fc
> MAX_INSN_FIXUPS
)
1861 as_fatal (_("too many fixups"));
1863 fixups
[ fc
].exp
= ex
;
1864 fixups
[ fc
].opindex
= * opindex_ptr
;
1865 fixups
[ fc
].reloc
= reloc
;
1870 /* start-sanitize-v850e */
1871 if (reloc
== BFD_RELOC_32
)
1873 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1875 errmsg
= _("immediate operand is too large");
1879 extra_data_after_insn
= true;
1881 extra_data
= ex
.X_add_number
;
1883 /* end-sanitize-v850e */
1885 if (fc
> MAX_INSN_FIXUPS
)
1886 as_fatal (_("too many fixups"));
1888 fixups
[ fc
].exp
= ex
;
1889 fixups
[ fc
].opindex
= * opindex_ptr
;
1890 fixups
[ fc
].reloc
= reloc
;
1898 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1900 if (!register_name (& ex
))
1902 errmsg
= _("invalid register name");
1904 else if ((operand
->flags
& V850_NOT_R0
)
1905 && ex
.X_add_number
== 0)
1907 errmsg
= _("register r0 cannot be used here");
1909 /* Force an error message to be generated by
1910 skipping over any following potential matches
1915 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1917 if (!system_register_name (& ex
, true
1918 /* start-sanitize-v850e */
1920 /* end-sanitize-v850e */
1923 errmsg
= _("invalid system register name");
1926 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1928 char * start
= input_line_pointer
;
1929 char c
= get_symbol_end ();
1931 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1933 /* Put things back the way we found them. */
1934 *input_line_pointer
= c
;
1935 input_line_pointer
= start
;
1936 errmsg
= _("expected EP register");
1940 *input_line_pointer
= c
;
1941 str
= input_line_pointer
;
1942 input_line_pointer
= hold
;
1944 while ( *str
== ' ' || *str
== ',' || *str
== '['
1949 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1951 if (!cc_name (& ex
))
1953 errmsg
= _("invalid condition code name");
1956 /* start-sanitize-v850e */
1957 else if (operand
->flags
& V850E_PUSH_POP
)
1959 errmsg
= parse_register_list (& insn
, operand
);
1961 /* The parse_register_list() function has already done
1962 everything, so fake a dummy expression. */
1963 ex
.X_op
= O_constant
;
1964 ex
.X_add_number
= 0;
1966 else if (operand
->flags
& V850E_IMMEDIATE16
)
1970 if (ex
.X_op
!= O_constant
)
1971 errmsg
= _("constant expression expected");
1972 else if (ex
.X_add_number
& 0xffff0000)
1974 if (ex
.X_add_number
& 0xffff)
1975 errmsg
= _("constant too big to fit into instruction");
1976 else if ((insn
& 0x001fffc0) == 0x00130780)
1977 ex
.X_add_number
>>= 16;
1979 errmsg
= _("constant too big to fit into instruction");
1982 extra_data_after_insn
= true;
1984 extra_data
= ex
.X_add_number
;
1985 ex
.X_add_number
= 0;
1987 else if (operand
->flags
& V850E_IMMEDIATE32
)
1991 if (ex
.X_op
!= O_constant
)
1992 errmsg
= _("constant expression expected");
1994 extra_data_after_insn
= true;
1996 extra_data
= ex
.X_add_number
;
1997 ex
.X_add_number
= 0;
1999 /* end-sanitize-v850e */
2000 else if (register_name (& ex
)
2001 && (operand
->flags
& V850_OPERAND_REG
) == 0)
2006 /* It is possible that an alias has been defined that
2007 matches a register name. For example the code may
2008 include a ".set ZERO, 0" directive, which matches
2009 the register name "zero". Attempt to reparse the
2010 field as an expression, and only complain if we
2011 cannot generate a constant. */
2013 input_line_pointer
= str
;
2015 c
= get_symbol_end();
2017 if (symbol_find (str
) != NULL
)
2020 * input_line_pointer
= c
;
2021 input_line_pointer
= str
;
2025 if (ex
.X_op
!= O_constant
)
2027 /* If this register is actually occuring too early on
2028 the parsing of the instruction, (because another
2029 field is missing) then report this. */
2030 if (opindex_ptr
[1] != 0
2031 && (v850_operands
[opindex_ptr
[1]].flags
& V850_OPERAND_REG
))
2032 errmsg
= _("syntax error: value is missing before the register name");
2034 errmsg
= _("syntax error: register not expected");
2036 /* If we created a symbol in the process of this test then
2037 delete it now, so that it will not be output with the real
2040 && ex
.X_op
== O_symbol
)
2041 symbol_remove (ex
.X_add_symbol
,
2042 & symbol_rootP
, & symbol_lastP
);
2045 else if (system_register_name (& ex
, false
2046 /* start-sanitize-v850e */
2048 /* end-sanitize-v850e */
2050 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
2052 errmsg
= _("syntax error: system register not expected");
2054 else if (cc_name (&ex
)
2055 && (operand
->flags
& V850_OPERAND_CC
) == 0)
2057 errmsg
= _("syntax error: condition code not expected");
2062 /* start-sanitize-v850e */
2064 If we are assembling a MOV instruction (or a CALLT.... :-)
2065 and the immediate value does not fit into the bits
2066 available then create a fake error so that the next MOV
2067 instruction will be selected. This one has a 32 bit
2070 if (((insn
& 0x07e0) == 0x0200)
2071 && ex
.X_op
== O_constant
2072 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1)))
2073 || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
2074 errmsg
= _("immediate operand is too large");
2075 /* end-sanitize-v850e */
2081 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n",
2082 insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
2087 errmsg
= _("illegal operand");
2090 errmsg
= _("missing operand");
2093 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
2095 errmsg
= _("invalid operand");
2098 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2100 copy_of_instruction
);
2104 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2106 copy_of_instruction
);
2110 /* We need to generate a fixup for this expression. */
2111 if (fc
>= MAX_INSN_FIXUPS
)
2112 as_fatal (_("too many fixups"));
2114 fixups
[ fc
].exp
= ex
;
2115 fixups
[ fc
].opindex
= * opindex_ptr
;
2116 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
2122 str
= input_line_pointer
;
2123 input_line_pointer
= hold
;
2125 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
2134 next_opcode
= opcode
+ 1;
2135 if (next_opcode
->name
!= NULL
2136 && strcmp (next_opcode
->name
, opcode
->name
) == 0)
2138 opcode
= next_opcode
;
2140 /* Skip versions that are not supported by the target
2142 if ((opcode
->processors
& processor_mask
) == 0)
2148 as_bad ("%s: %s", copy_of_instruction
, errmsg
);
2150 if (* input_line_pointer
== ']')
2151 ++ input_line_pointer
;
2153 ignore_rest_of_line ();
2154 input_line_pointer
= saved_input_line_pointer
;
2160 while (isspace (*str
))
2164 /* xgettext:c-format */
2165 as_bad (_("junk at end of line: `%s'"), str
);
2167 input_line_pointer
= str
;
2169 /* Write out the instruction. */
2171 if (relaxable
&& fc
> 0)
2176 if (!strcmp (opcode
->name
, "br"))
2178 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
2179 fixups
[0].exp
.X_add_symbol
,
2180 fixups
[0].exp
.X_add_number
,
2181 (char *)fixups
[0].opindex
);
2182 md_number_to_chars (f
, insn
, insn_size
);
2183 md_number_to_chars (f
+ 2, 0, 2);
2187 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
2188 fixups
[0].exp
.X_add_symbol
,
2189 fixups
[0].exp
.X_add_number
,
2190 (char *)fixups
[0].opindex
);
2191 md_number_to_chars (f
, insn
, insn_size
);
2192 md_number_to_chars (f
+ 2, 0, 4);
2197 /* Four byte insns have an opcode with the two high bits on. */
2198 if ((insn
& 0x0600) == 0x0600)
2203 /* start-sanitize-v850e */
2204 /* Special case: 32 bit MOV */
2205 if ((insn
& 0xffe0) == 0x0620)
2207 /* end-sanitize-v850e */
2209 f
= frag_more (insn_size
);
2211 md_number_to_chars (f
, insn
, insn_size
);
2213 if (extra_data_after_insn
)
2215 f
= frag_more (extra_data_len
);
2217 md_number_to_chars (f
, extra_data
, extra_data_len
);
2219 extra_data_after_insn
= false;
2223 /* Create any fixups. At this point we do not use a
2224 bfd_reloc_code_real_type, but instead just use the
2225 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2226 handle fixups for any operand type, although that is admittedly
2227 not a very exciting feature. We pick a BFD reloc type in
2229 for (i
= 0; i
< fc
; i
++)
2231 const struct v850_operand
* operand
;
2232 bfd_reloc_code_real_type reloc
;
2234 operand
= & v850_operands
[ fixups
[i
].opindex
];
2236 reloc
= fixups
[i
].reloc
;
2238 if (reloc
!= BFD_RELOC_UNUSED
)
2240 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
2249 size
= bfd_get_reloc_size (reloc_howto
);
2251 /* XXX This will abort on an R_V850_8 reloc -
2252 is this reloc actually used ? */
2253 if (size
!= 2 && size
!= 4)
2256 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
2258 if (reloc
== BFD_RELOC_32
)
2263 fixP
= fix_new_exp (frag_now
, address
, size
,
2265 reloc_howto
->pc_relative
,
2270 case BFD_RELOC_LO16
:
2271 case BFD_RELOC_HI16
:
2272 case BFD_RELOC_HI16_S
:
2273 fixP
->fx_no_overflow
= 1;
2281 f
- frag_now
->fr_literal
, 4,
2283 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2284 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
2285 + (int) BFD_RELOC_UNUSED
)
2290 input_line_pointer
= saved_input_line_pointer
;
2294 /* If while processing a fixup, a reloc really needs to be created */
2295 /* then it is done here. */
2298 tc_gen_reloc (seg
, fixp
)
2304 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2305 reloc
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
2306 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2307 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2309 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2311 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2312 /* xgettext:c-format */
2313 _("reloc %d not supported by object file format"),
2314 (int)fixp
->fx_r_type
);
2321 reloc
->addend
= fixp
->fx_addnumber
;
2326 /* Assume everything will fit in two bytes, then expand as necessary. */
2328 md_estimate_size_before_relax (fragp
, seg
)
2332 if (fragp
->fr_subtype
== 0)
2334 else if (fragp
->fr_subtype
== 2)
2342 md_pcrel_from (fixp
)
2345 /* If the symbol is undefined, or in a section other than our own,
2346 then let the linker figure it out. */
2347 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
2349 /* The symbol is undefined. Let the linker figure it out. */
2352 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2356 md_apply_fix3 (fixp
, valuep
, seg
)
2364 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2369 else if (fixp
->fx_pcrel
)
2373 value
= fixp
->fx_offset
;
2374 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2376 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2377 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2380 /* We don't actually support subtracting a symbol. */
2381 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2382 _("expression too complex"));
2387 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2390 const struct v850_operand
* operand
;
2393 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2394 operand
= & v850_operands
[ opindex
];
2396 /* Fetch the instruction, insert the fully resolved operand
2397 value, and stuff the instruction back again.
2399 Note the instruction has been stored in little endian
2401 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2403 insn
= bfd_getl32 ((unsigned char *) where
);
2404 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2405 fixp
->fx_file
, fixp
->fx_line
, NULL
);
2406 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2410 /* Nothing else to do here. */
2414 /* Determine a BFD reloc value based on the operand information.
2415 We are only prepared to turn a few of the operands into relocs. */
2417 if (operand
->bits
== 22)
2418 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2419 else if (operand
->bits
== 9)
2420 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2423 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2425 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2426 _("unresolved expression that must be resolved"));
2431 else if (fixp
->fx_done
)
2433 /* We still have to insert the value into memory! */
2434 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2436 if (fixp
->fx_size
== 1)
2437 * where
= value
& 0xff;
2438 else if (fixp
->fx_size
== 2)
2439 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2440 else if (fixp
->fx_size
== 4)
2441 bfd_putl32 (value
, (unsigned char *) where
);
2444 fixp
->fx_addnumber
= value
;
2449 /* Parse a cons expression. We have to handle hi(), lo(), etc
2452 parse_cons_expression_v850 (exp
)
2455 /* See if there's a reloc prefix like hi() we have to handle. */
2456 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2458 /* Do normal expression parsing. */
2462 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2463 found a reloc prefix, then we use that reloc, else we choose an
2464 appropriate one based on the size of the expression. */
2466 cons_fix_new_v850 (frag
, where
, size
, exp
)
2472 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2475 hold_cons_reloc
= BFD_RELOC_32
;
2477 hold_cons_reloc
= BFD_RELOC_16
;
2479 hold_cons_reloc
= BFD_RELOC_8
;
2483 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2485 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);