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"));
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 old_subsec
= now_subseg
;
383 /* convert to a power of 2 alignment */
384 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
)
389 as_bad (_("Common alignment not a power of 2"));
390 ignore_rest_of_line ();
400 record_alignment (sbss_section
, align
);
401 obj_elf_section_change_hook();
402 subseg_set (sbss_section
, 0);
406 record_alignment (zbss_section
, align
);
407 obj_elf_section_change_hook();
408 subseg_set (zbss_section
, 0);
412 record_alignment (tbss_section
, align
);
413 obj_elf_section_change_hook();
414 subseg_set (tbss_section
, 0);
422 frag_align (align
, 0, 0);
427 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
428 symbolP
->sy_frag
->fr_symbol
= 0;
432 if (S_GET_SEGMENT (symbolP
) == zbss_section
)
433 symbolP
->sy_frag
->fr_symbol
= 0;
437 if (S_GET_SEGMENT (symbolP
) == tbss_section
)
438 symbolP
->sy_frag
->fr_symbol
= 0;
445 symbolP
->sy_frag
= frag_now
;
446 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
447 (offsetT
) size
, (char *) 0);
449 S_SET_SIZE (symbolP
, size
);
454 S_SET_SEGMENT (symbolP
, sbss_section
);
458 S_SET_SEGMENT (symbolP
, zbss_section
);
462 S_SET_SEGMENT (symbolP
, tbss_section
);
469 S_CLEAR_EXTERNAL (symbolP
);
470 obj_elf_section_change_hook();
471 subseg_set (old_sec
, old_subsec
);
476 S_SET_VALUE (symbolP
, (valueT
) size
);
477 S_SET_ALIGN (symbolP
, temp
);
478 S_SET_EXTERNAL (symbolP
);
483 if (scommon_section
== NULL
)
487 applicable
= bfd_applicable_section_flags (stdoutput
);
489 scommon_section
= subseg_new (".scommon", 0);
491 bfd_set_section_flags (stdoutput
, scommon_section
, applicable
492 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| 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
| 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
, applicable
522 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_IS_COMMON
));
524 S_SET_SEGMENT (symbolP
, tcommon_section
);
534 input_line_pointer
++;
535 /* @@ Some use the dot, some don't. Can we get some consistency?? */
536 if (*input_line_pointer
== '.')
537 input_line_pointer
++;
538 /* @@ Some say data, some say bss. */
539 if (strncmp (input_line_pointer
, "bss\"", 4)
540 && strncmp (input_line_pointer
, "data\"", 5))
542 while (*--input_line_pointer
!= '"')
544 input_line_pointer
--;
545 goto bad_common_segment
;
547 while (*input_line_pointer
++ != '"')
549 goto allocate_common
;
552 symbolP
->bsym
->flags
|= BSF_OBJECT
;
554 demand_empty_rest_of_line ();
559 p
= input_line_pointer
;
560 while (*p
&& *p
!= '\n')
564 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
566 input_line_pointer
= p
;
567 ignore_rest_of_line ();
573 set_machine (int number
)
576 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
580 case 0: processor_mask
= PROCESSOR_V850
; break;
581 /* start-sanitize-v850e */
582 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
583 case bfd_mach_v850ea
: processor_mask
= PROCESSOR_V850EA
; break;
584 /* end-sanitize-v850e */
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 /* start-sanitize-v850e */
607 {"call_table_data", v850_call_table_data
, 0},
608 {"call_table_text", v850_call_table_text
, 0},
609 {"v850e", set_machine
, bfd_mach_v850e
},
610 {"v850ea", set_machine
, bfd_mach_v850ea
},
611 /* end-sanitize-v850e */
615 /* Opcode hash table. */
616 static struct hash_control
*v850_hash
;
618 /* This table is sorted. Suitable for searching by a binary search. */
619 static const struct reg_name pre_defined_registers
[] =
621 { "ep", 30 }, /* ep - element ptr */
622 { "gp", 4 }, /* gp - global ptr */
623 { "hp", 2 }, /* hp - handler stack ptr */
624 { "lp", 31 }, /* lp - link ptr */
657 { "sp", 3 }, /* sp - stack ptr */
658 { "tp", 5 }, /* tp - text ptr */
661 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
664 static const struct reg_name system_registers
[] =
666 /* start-sanitize-v850e */
672 /* end-sanitize-v850e */
680 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
682 /* start-sanitize-v850e */
683 static const struct reg_name system_list_registers
[] =
688 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
689 /* end-sanitize-v850e */
691 static const struct reg_name cc_names
[] =
716 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
718 /* reg_name_search does a binary search of the given register table
719 to see if "name" is a valid regiter name. Returns the register
720 number from the array on success, or -1 on failure. */
723 reg_name_search (regs
, regcount
, name
, accept_numbers
)
724 const struct reg_name
* regs
;
727 boolean accept_numbers
;
729 int middle
, low
, high
;
733 /* If the register name is a symbol, then evaluate it. */
734 if ((symbolP
= symbol_find (name
)) != NULL
)
736 /* If the symbol is an alias for another name then use that.
737 If the symbol is an alias for a number, then return the number. */
738 if (symbolP
->sy_value
.X_op
== O_symbol
)
740 name
= S_GET_NAME (symbolP
->sy_value
.X_add_symbol
);
742 else if (accept_numbers
)
744 int reg
= S_GET_VALUE (symbolP
);
746 if (reg
>= 0 && reg
<= 31)
756 middle
= (low
+ high
) / 2;
757 cmp
= strcasecmp (name
, regs
[middle
].name
);
763 return regs
[middle
].value
;
770 /* Summary of register_name().
772 * in: Input_line_pointer points to 1st char of operand.
774 * out: A expressionS.
775 * The operand may have been a register: in this case, X_op == O_register,
776 * X_add_number is set to the register number, and truth is returned.
777 * Input_line_pointer->(next non-blank) char after operand, or is in
778 * its original state.
781 register_name (expressionP
)
782 expressionS
* expressionP
;
789 /* Find the spelling of the operand */
790 start
= name
= input_line_pointer
;
792 c
= get_symbol_end ();
794 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
,
797 * input_line_pointer
= c
; /* put back the delimiting char */
799 /* look to see if it's in the register table */
802 expressionP
->X_op
= O_register
;
803 expressionP
->X_add_number
= reg_number
;
805 /* make the rest nice */
806 expressionP
->X_add_symbol
= NULL
;
807 expressionP
->X_op_symbol
= NULL
;
813 /* reset the line as if we had not done anything */
814 input_line_pointer
= start
;
820 /* Summary of system_register_name().
822 * in: Input_line_pointer points to 1st char of operand.
823 * expressionP points to an expression structure to be filled in.
824 * accept_numbers is true iff numerical register names may be used.
825 * start-sanitize-v850e
826 * accept_list_names is true iff the special names PS and SR may be
830 * out: A expressionS structure in expressionP.
831 * The operand may have been a register: in this case, X_op == O_register,
832 * X_add_number is set to the register number, and truth is returned.
833 * Input_line_pointer->(next non-blank) char after operand, or is in
834 * its original state.
837 system_register_name (expressionP
, accept_numbers
838 /* start-sanitize-v850e */
840 /* end-sanitize-v850e */
842 expressionS
* expressionP
;
843 boolean accept_numbers
;
844 /* start-sanitize-v850e */
845 boolean accept_list_names
;
846 /* end-sanitize-v850e */
853 /* Find the spelling of the operand */
854 start
= name
= input_line_pointer
;
856 c
= get_symbol_end ();
857 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
,
860 * input_line_pointer
= c
; /* put back the delimiting char */
865 input_line_pointer
= start
; /* reset input_line pointer */
867 if (isdigit (* input_line_pointer
))
869 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
871 /* Make sure that the register number is allowable. */
874 /* start-sanitize-v850e */
877 /* end-sanitize-v850e */
883 /* start-sanitize-v850e */
884 else if (accept_list_names
)
886 c
= get_symbol_end ();
887 reg_number
= reg_name_search (system_list_registers
,
888 SYSREGLIST_NAME_CNT
, name
, FALSE
);
890 * input_line_pointer
= c
; /* put back the delimiting char */
892 /* end-sanitize-v850e */
895 /* look to see if it's in the register table */
898 expressionP
->X_op
= O_register
;
899 expressionP
->X_add_number
= reg_number
;
901 /* make the rest nice */
902 expressionP
->X_add_symbol
= NULL
;
903 expressionP
->X_op_symbol
= NULL
;
909 /* reset the line as if we had not done anything */
910 input_line_pointer
= start
;
916 /* Summary of cc_name().
918 * in: Input_line_pointer points to 1st char of operand.
920 * out: A expressionS.
921 * The operand may have been a register: in this case, X_op == O_register,
922 * X_add_number is set to the register number, and truth is returned.
923 * Input_line_pointer->(next non-blank) char after operand, or is in
924 * its original state.
927 cc_name (expressionP
)
928 expressionS
* expressionP
;
935 /* Find the spelling of the operand */
936 start
= name
= input_line_pointer
;
938 c
= get_symbol_end ();
939 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
, FALSE
);
941 * input_line_pointer
= c
; /* put back the delimiting char */
943 /* look to see if it's in the register table */
946 expressionP
->X_op
= O_constant
;
947 expressionP
->X_add_number
= reg_number
;
949 /* make the rest nice */
950 expressionP
->X_add_symbol
= NULL
;
951 expressionP
->X_op_symbol
= NULL
;
957 /* reset the line as if we had not done anything */
958 input_line_pointer
= start
;
965 skip_white_space (void)
967 while ( * input_line_pointer
== ' '
968 || * input_line_pointer
== '\t')
969 ++ input_line_pointer
;
972 /* start-sanitize-v850e */
973 /* Summary of parse_register_list ().
975 * in: Input_line_pointer points to 1st char of a list of registers.
976 * insn is the partially constructed instruction.
977 * operand is the operand being inserted.
979 * out: NULL if the parse completed successfully, otherwise a
980 * pointer to an error message is returned. If the parse
981 * completes the correct bit fields in the instruction
984 * Parses register lists with the syntax:
992 * and also parses constant epxressions whoes bits indicate the
993 * registers in the lists. The LSB in the expression refers to
994 * the lowest numbered permissable register in the register list,
995 * and so on upwards. System registers are considered to be very
1002 unsigned long * insn
,
1003 const struct v850_operand
* operand
1006 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 };
1007 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 };
1008 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 };
1013 /* Select a register array to parse. */
1014 switch (operand
->shift
)
1016 case 0xffe00001: regs
= type1_regs
; break;
1017 case 0xfff8000f: regs
= type2_regs
; break;
1018 case 0xfff8001f: regs
= type3_regs
; break;
1020 as_bad (_("unknown operand shift: %x\n"), operand
->shift
);
1021 return _("internal failure in parse_register_list");
1026 /* If the expression starts with a curly brace it is a register list.
1027 Otherwise it is a constant expression, whoes bits indicate which
1028 registers are to be included in the list. */
1030 if (* input_line_pointer
!= '{')
1038 if (exp
.X_op
!= O_constant
)
1039 return _("constant expression or register list expected");
1041 if (regs
== type1_regs
)
1043 if (exp
.X_add_number
& 0xFFFFF000)
1044 return _("high bits set in register list expression");
1046 for (reg
= 20; reg
< 32; reg
++)
1047 if (exp
.X_add_number
& (1 << (reg
- 20)))
1049 for (i
= 0; i
< 32; i
++)
1054 else if (regs
== type2_regs
)
1056 if (exp
.X_add_number
& 0xFFFE0000)
1057 return _("high bits set in register list expression");
1059 for (reg
= 1; reg
< 16; reg
++)
1060 if (exp
.X_add_number
& (1 << (reg
- 1)))
1062 for (i
= 0; i
< 32; i
++)
1067 if (exp
.X_add_number
& (1 << 15))
1070 if (exp
.X_add_number
& (1 << 16))
1071 * insn
|= (1 << 19);
1073 else /* regs == type3_regs */
1075 if (exp
.X_add_number
& 0xFFFE0000)
1076 return _("high bits set in register list expression");
1078 for (reg
= 16; reg
< 32; reg
++)
1079 if (exp
.X_add_number
& (1 << (reg
- 16)))
1081 for (i
= 0; i
< 32; i
++)
1086 if (exp
.X_add_number
& (1 << 16))
1087 * insn
|= (1 << 19);
1093 input_line_pointer
++;
1095 /* Parse the register list until a terminator (closing curly brace or
1096 new-line) is found. */
1099 if (register_name (& exp
))
1103 /* Locate the given register in the list, and if it is there,
1104 insert the corresponding bit into the instruction. */
1105 for (i
= 0; i
< 32; i
++)
1107 if (regs
[ i
] == exp
.X_add_number
)
1116 return _("illegal register included in list");
1119 else if (system_register_name (& exp
, true, true))
1121 if (regs
== type1_regs
)
1123 return _("system registers cannot be included in list");
1125 else if (exp
.X_add_number
== 5)
1127 if (regs
== type2_regs
)
1128 return _("PSW cannot be included in list");
1132 else if (exp
.X_add_number
< 4)
1135 return _("High value system registers cannot be included in list");
1137 else if (* input_line_pointer
== '}')
1139 input_line_pointer
++;
1142 else if (* input_line_pointer
== ',')
1144 input_line_pointer
++;
1147 else if (* input_line_pointer
== '-')
1149 /* We have encountered a range of registers: rX - rY */
1153 /* Skip the dash. */
1154 ++ input_line_pointer
;
1156 /* Get the second register in the range. */
1157 if (! register_name (& exp2
))
1159 return _("second register should follow dash in register list");
1160 exp2
.X_add_number
= exp
.X_add_number
;
1163 /* Add the rest of the registers in the range. */
1164 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1168 /* Locate the given register in the list, and if it is there,
1169 insert the corresponding bit into the instruction. */
1170 for (i
= 0; i
< 32; i
++)
1180 return _("illegal register included in list");
1188 skip_white_space ();
1193 /* end-sanitize-v850e */
1195 CONST
char * md_shortopts
= "m:";
1197 struct option md_longopts
[] =
1199 {NULL
, no_argument
, NULL
, 0}
1201 size_t md_longopts_size
= sizeof md_longopts
;
1205 md_show_usage (stream
)
1208 fprintf (stream
, _("V850 options:\n"));
1209 fprintf (stream
, _("\t-mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1210 fprintf (stream
, _("\t-mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1211 fprintf (stream
, _("\t-mv850 The code is targeted at the v850\n"));
1212 /* start-sanitize-v850e */
1213 fprintf (stream
, _("\t-mv850e The code is targeted at the v850e\n"));
1214 fprintf (stream
, _("\t-mv850ea The code is targeted at the v850ea\n"));
1215 fprintf (stream
, _("\t-mv850any The code is generic, despite any processor specific instructions\n"));
1216 /* end-sanitize-v850e */
1220 md_parse_option (c
, arg
)
1226 /* xgettext:c-format */
1227 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1231 if (strcmp (arg
, "warn-signed-overflow") == 0)
1233 warn_signed_overflows
= TRUE
;
1235 else if (strcmp (arg
, "warn-unsigned-overflow") == 0)
1237 warn_unsigned_overflows
= TRUE
;
1239 else if (strcmp (arg
, "v850") == 0)
1242 processor_mask
= PROCESSOR_V850
;
1244 /* start-sanitize-v850e */
1245 else if (strcmp (arg
, "v850e") == 0)
1247 machine
= bfd_mach_v850e
;
1248 processor_mask
= PROCESSOR_V850E
;
1250 else if (strcmp (arg
, "v850ea") == 0)
1252 machine
= bfd_mach_v850ea
;
1253 processor_mask
= PROCESSOR_V850EA
;
1255 else if (strcmp (arg
, "v850any") == 0)
1257 machine
= 0; /* Tell the world that this is for any v850 chip. */
1258 processor_mask
= PROCESSOR_V850EA
; /* But support instructions for the extended versions. */
1260 /* end-sanitize-v850e */
1263 /* xgettext:c-format */
1264 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1272 md_undefined_symbol (name
)
1279 md_atof (type
, litp
, sizep
)
1285 LITTLENUM_TYPE words
[4];
1301 return _("bad call to md_atof");
1304 t
= atof_ieee (input_line_pointer
, type
, words
);
1306 input_line_pointer
= t
;
1310 for (i
= prec
- 1; i
>= 0; i
--)
1312 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1322 md_convert_frag (abfd
, sec
, fragP
)
1327 subseg_change (sec
, 0);
1329 /* In range conditional or unconditional branch. */
1330 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1332 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1333 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1337 /* Out of range conditional branch. Emit a branch around a jump. */
1338 else if (fragP
->fr_subtype
== 1)
1340 unsigned char *buffer
=
1341 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1343 /* Reverse the condition of the first branch. */
1345 /* Mask off all the displacement bits. */
1348 /* Now set the displacement bits so that we branch
1349 around the unconditional branch. */
1352 /* Now create the unconditional branch + fixup to the final
1354 md_number_to_chars (buffer
+ 2, 0x00000780, 4);
1355 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1356 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int) fragP
->fr_opcode
1361 /* Out of range unconditional branch. Emit a jump. */
1362 else if (fragP
->fr_subtype
== 3)
1364 md_number_to_chars (fragP
->fr_fix
+ fragP
->fr_literal
, 0x00000780, 4);
1365 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
1366 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int) fragP
->fr_opcode
1376 md_section_align (seg
, addr
)
1380 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1381 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1387 char * prev_name
= "";
1388 register const struct v850_opcode
* op
;
1389 flagword applicable
;
1391 /* start-sanitize-v850e */
1392 if (strncmp (TARGET_CPU
, "v850ea", 6) == 0)
1395 machine
= bfd_mach_v850ea
;
1397 if (processor_mask
== -1)
1398 processor_mask
= PROCESSOR_V850EA
;
1400 else if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1403 machine
= bfd_mach_v850e
;
1405 if (processor_mask
== -1)
1406 processor_mask
= PROCESSOR_V850E
;
1409 /* end-sanitize-v850e */
1410 if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1415 if (processor_mask
== -1)
1416 processor_mask
= PROCESSOR_V850
;
1419 /* xgettext:c-format */
1420 as_bad (_("Unable to determine default target processor from string: %s"),
1423 v850_hash
= hash_new();
1425 /* Insert unique names into hash table. The V850 instruction set
1426 has many identical opcode names that have different opcodes based
1427 on the operands. This hash table then provides a quick index to
1428 the first opcode with a particular name in the opcode table. */
1433 if (strcmp (prev_name
, op
->name
))
1435 prev_name
= (char *) op
->name
;
1436 hash_insert (v850_hash
, op
->name
, (char *) op
);
1441 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1443 /* start-sanitize-v850e */
1444 call_table_data_section
= subseg_new (".call_table_data", 0);
1445 bfd_set_section_flags (stdoutput
, call_table_data_section
,
1446 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
1447 | SEC_DATA
| SEC_HAS_CONTENTS
));
1449 call_table_text_section
= subseg_new (".call_table_text", 0);
1450 bfd_set_section_flags (stdoutput
, call_table_text_section
,
1451 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
));
1452 /* end-sanitize-v850e */
1457 /* start-sanitize-v850e */
1458 static bfd_reloc_code_real_type
1459 handle_ctoff (const struct v850_operand
* operand
)
1461 if (operand
== NULL
)
1462 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1464 if ( operand
->bits
!= 6
1465 || operand
->shift
!= 0)
1467 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1468 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1471 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1473 /* end-sanitize-v850e */
1475 static bfd_reloc_code_real_type
1476 handle_sdaoff (const struct v850_operand
* operand
)
1478 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1479 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1480 /* start-sanitize-v850e */
1481 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1482 /* end-sanitize-v850e */
1484 if ( operand
->bits
!= 16
1485 || operand
->shift
!= 16)
1487 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1488 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1491 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1494 static bfd_reloc_code_real_type
1495 handle_zdaoff (const struct v850_operand
* operand
)
1497 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1498 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1499 /* start-sanitize-v850e */
1500 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1501 /* end-sanitize-v850e */
1503 if ( operand
->bits
!= 16
1504 || operand
->shift
!= 16)
1506 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1507 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1510 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1513 static bfd_reloc_code_real_type
1514 handle_tdaoff (const struct v850_operand
* operand
)
1516 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
; /* data item, not an instruction. */
1517 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
; /* sld.w/sst.w, operand: D8_6 */
1518 /* start-sanitize-v850e */
1519 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
; /* sld.hu, operand: D5-4 */
1520 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
; /* sld.bu, operand: D4 */
1521 /* end-sanitize-v850e */
1522 if (operand
->bits
== 16 && operand
->shift
== 16) return BFD_RELOC_V850_TDA_16_16_OFFSET
; /* set1 & chums, operands: D16 */
1524 if (operand
->bits
!= 7)
1526 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1527 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1530 return operand
->insert
!= NULL
1531 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1532 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1535 /* Warning: The code in this function relies upon the definitions
1536 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1537 matching the hard coded values contained herein. */
1539 static bfd_reloc_code_real_type
1540 v850_reloc_prefix (const struct v850_operand
* operand
)
1542 boolean paren_skipped
= false;
1545 /* Skip leading opening parenthesis. */
1546 if (* input_line_pointer
== '(')
1548 ++ input_line_pointer
;
1549 paren_skipped
= true;
1552 #define CHECK_(name, reloc) \
1553 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1555 input_line_pointer += strlen (name); \
1559 CHECK_ ("hi0", BFD_RELOC_HI16
);
1560 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1561 CHECK_ ("lo", BFD_RELOC_LO16
);
1562 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1563 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1564 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1566 /* start-sanitize-v850e */
1567 CHECK_ ("hilo", BFD_RELOC_32
);
1568 CHECK_ ("ctoff", handle_ctoff (operand
));
1569 /* end-sanitize-v850e */
1571 /* Restore skipped parenthesis. */
1573 -- input_line_pointer
;
1575 return BFD_RELOC_UNUSED
;
1578 /* Insert an operand value into an instruction. */
1580 static unsigned long
1581 v850_insert_operand (insn
, operand
, val
, file
, line
, str
)
1583 const struct v850_operand
* operand
;
1589 if (operand
->insert
)
1591 const char * message
= NULL
;
1593 insn
= operand
->insert (insn
, val
, & message
);
1594 if (message
!= NULL
)
1596 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1597 && ! warn_signed_overflows
1598 && strstr (message
, "out of range") != NULL
)
1600 /* skip warning... */
1602 else if ((operand
->flags
& V850_OPERAND_SIGNED
) == 0
1603 && ! warn_unsigned_overflows
1604 && strstr (message
, "out of range") != NULL
)
1606 /* skip warning... */
1610 if (file
== (char *) NULL
)
1611 as_warn ("%s: %s", str
, message
);
1613 as_warn_where (file
, line
, "%s: %s", str
, message
);
1617 if (file
== (char *) NULL
)
1620 as_warn_where (file
, line
, message
);
1626 if (operand
->bits
!= 32)
1631 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1633 if (! warn_signed_overflows
)
1634 max
= (1 << operand
->bits
) - 1;
1636 max
= (1 << (operand
->bits
- 1)) - 1;
1638 min
= - (1 << (operand
->bits
- 1));
1642 max
= (1 << operand
->bits
) - 1;
1644 if (! warn_unsigned_overflows
)
1645 min
= - (1 << (operand
->bits
- 1));
1650 if (val
< (offsetT
) min
|| val
> (offsetT
) max
)
1652 /* xgettext:c-format */
1653 const char * err
= _("operand out of range (%s not between %ld and %ld)");
1656 /* Restore min and mix to expected values for decimal ranges. */
1657 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1658 && ! warn_signed_overflows
)
1659 max
= (1 << (operand
->bits
- 1)) - 1;
1661 if (! (operand
->flags
& V850_OPERAND_SIGNED
)
1662 && ! warn_unsigned_overflows
)
1667 sprintf (buf
, "%s: ", str
);
1669 sprint_value (buf
+ strlen (buf
), val
);
1672 sprint_value (buf
, val
);
1674 if (file
== (char *) NULL
)
1675 as_warn (err
, buf
, min
, max
);
1677 as_warn_where (file
, line
, err
, buf
, min
, max
);
1681 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1688 static char copy_of_instruction
[128];
1695 char * start_of_operands
;
1696 struct v850_opcode
* opcode
;
1697 struct v850_opcode
* next_opcode
;
1698 const unsigned char * opindex_ptr
;
1702 unsigned long insn_size
;
1706 boolean extra_data_after_insn
= false;
1707 unsigned extra_data_len
;
1708 unsigned long extra_data
;
1709 char * saved_input_line_pointer
;
1712 strncpy (copy_of_instruction
, str
, sizeof (copy_of_instruction
) - 1);
1714 /* Get the opcode. */
1715 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1721 /* find the first opcode with the proper name */
1722 opcode
= (struct v850_opcode
*) hash_find (v850_hash
, str
);
1725 /* xgettext:c-format */
1726 as_bad (_("Unrecognized opcode: `%s'"), str
);
1727 ignore_rest_of_line ();
1732 while (isspace (* str
))
1735 start_of_operands
= str
;
1737 saved_input_line_pointer
= input_line_pointer
;
1741 const char * errmsg
= NULL
;
1745 if ((opcode
->processors
& processor_mask
) == 0)
1747 errmsg
= _("Target processor does not support this instruction.");
1754 insn
= opcode
->opcode
;
1755 extra_data_after_insn
= false;
1757 input_line_pointer
= str
= start_of_operands
;
1759 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1761 const struct v850_operand
* operand
;
1764 bfd_reloc_code_real_type reloc
;
1766 if (next_opindex
== 0)
1768 operand
= & v850_operands
[ * opindex_ptr
];
1772 operand
= & v850_operands
[ next_opindex
];
1778 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1781 if (operand
->flags
& V850_OPERAND_RELAX
)
1784 /* Gather the operand. */
1785 hold
= input_line_pointer
;
1786 input_line_pointer
= str
;
1788 /* lo(), hi(), hi0(), etc... */
1789 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1791 /* This is a fake reloc, used to indicate an error condition. */
1792 if (reloc
== BFD_RELOC_64
)
1800 if (ex
.X_op
== O_constant
)
1804 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1805 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1809 case BFD_RELOC_LO16
:
1811 /* Truncate, then sign extend the value. */
1812 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1816 case BFD_RELOC_HI16
:
1818 /* Truncate, then sign extend the value. */
1819 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1823 case BFD_RELOC_HI16_S
:
1825 /* Truncate, then sign extend the value. */
1826 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1828 temp
+= (ex
.X_add_number
>> 15) & 1;
1830 ex
.X_add_number
= SEXT16 (temp
);
1834 /* start-sanitize-v850e */
1836 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1838 errmsg
= _("immediate operand is too large");
1842 extra_data_after_insn
= true;
1844 extra_data
= ex
.X_add_number
;
1845 ex
.X_add_number
= 0;
1847 /* end-sanitize-v850e */
1850 fprintf (stderr
, "reloc: %d\n", reloc
);
1851 as_bad (_("AAARG -> unhandled constant reloc"));
1855 if (fc
> MAX_INSN_FIXUPS
)
1856 as_fatal (_("too many fixups"));
1858 fixups
[ fc
].exp
= ex
;
1859 fixups
[ fc
].opindex
= * opindex_ptr
;
1860 fixups
[ fc
].reloc
= reloc
;
1865 /* start-sanitize-v850e */
1866 if (reloc
== BFD_RELOC_32
)
1868 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1870 errmsg
= _("immediate operand is too large");
1874 extra_data_after_insn
= true;
1876 extra_data
= ex
.X_add_number
;
1878 /* end-sanitize-v850e */
1880 if (fc
> MAX_INSN_FIXUPS
)
1881 as_fatal (_("too many fixups"));
1883 fixups
[ fc
].exp
= ex
;
1884 fixups
[ fc
].opindex
= * opindex_ptr
;
1885 fixups
[ fc
].reloc
= reloc
;
1893 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1895 if (!register_name (& ex
))
1897 errmsg
= _("invalid register name");
1899 else if ((operand
->flags
& V850_NOT_R0
)
1900 && ex
.X_add_number
== 0)
1902 errmsg
= _("register r0 cannot be used here");
1904 /* Force an error message to be generated by
1905 skipping over any following potential matches
1910 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1912 if (!system_register_name (& ex
, true
1913 /* start-sanitize-v850e */
1915 /* end-sanitize-v850e */
1918 errmsg
= _("invalid system register name");
1921 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1923 char * start
= input_line_pointer
;
1924 char c
= get_symbol_end ();
1926 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1928 /* Put things back the way we found them. */
1929 *input_line_pointer
= c
;
1930 input_line_pointer
= start
;
1931 errmsg
= _("expected EP register");
1935 *input_line_pointer
= c
;
1936 str
= input_line_pointer
;
1937 input_line_pointer
= hold
;
1939 while ( *str
== ' ' || *str
== ',' || *str
== '['
1944 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1946 if (!cc_name (& ex
))
1948 errmsg
= _("invalid condition code name");
1951 /* start-sanitize-v850e */
1952 else if (operand
->flags
& V850E_PUSH_POP
)
1954 errmsg
= parse_register_list (& insn
, operand
);
1956 /* The parse_register_list() function has already done
1957 everything, so fake a dummy expression. */
1958 ex
.X_op
= O_constant
;
1959 ex
.X_add_number
= 0;
1961 else if (operand
->flags
& V850E_IMMEDIATE16
)
1965 if (ex
.X_op
!= O_constant
)
1966 errmsg
= _("constant expression expected");
1967 else if (ex
.X_add_number
& 0xffff0000)
1969 if (ex
.X_add_number
& 0xffff)
1970 errmsg
= _("constant too big to fit into instruction");
1971 else if ((insn
& 0x001fffc0) == 0x00130780)
1972 ex
.X_add_number
>>= 16;
1974 errmsg
= _("constant too big to fit into instruction");
1977 extra_data_after_insn
= true;
1979 extra_data
= ex
.X_add_number
;
1980 ex
.X_add_number
= 0;
1982 else if (operand
->flags
& V850E_IMMEDIATE32
)
1986 if (ex
.X_op
!= O_constant
)
1987 errmsg
= _("constant expression expected");
1989 extra_data_after_insn
= true;
1991 extra_data
= ex
.X_add_number
;
1992 ex
.X_add_number
= 0;
1994 /* end-sanitize-v850e */
1995 else if (register_name (& ex
)
1996 && (operand
->flags
& V850_OPERAND_REG
) == 0)
2001 /* It is possible that an alias has been defined that
2002 matches a register name. For example the code may
2003 include a ".set ZERO, 0" directive, which matches
2004 the register name "zero". Attempt to reparse the
2005 field as an expression, and only complain if we
2006 cannot generate a constant. */
2008 input_line_pointer
= str
;
2010 c
= get_symbol_end();
2012 if (symbol_find (str
) != NULL
)
2015 * input_line_pointer
= c
;
2016 input_line_pointer
= str
;
2020 if (ex
.X_op
!= O_constant
)
2022 /* If this register is actually occuring too early on
2023 the parsing of the instruction, (because another
2024 field is missing) then report this. */
2025 if (opindex_ptr
[1] != 0
2026 && (v850_operands
[opindex_ptr
[1]].flags
& V850_OPERAND_REG
))
2027 errmsg
= _("syntax error: value is missing before the register name");
2029 errmsg
= _("syntax error: register not expected");
2031 /* If we created a symbol in the process of this test then
2032 delete it now, so that it will not be output with the real
2035 && ex
.X_op
== O_symbol
)
2036 symbol_remove (ex
.X_add_symbol
,
2037 & symbol_rootP
, & symbol_lastP
);
2040 else if (system_register_name (& ex
, false
2041 /* start-sanitize-v850e */
2043 /* end-sanitize-v850e */
2045 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
2047 errmsg
= _("syntax error: system register not expected");
2049 else if (cc_name (&ex
)
2050 && (operand
->flags
& V850_OPERAND_CC
) == 0)
2052 errmsg
= _("syntax error: condition code not expected");
2057 /* start-sanitize-v850e */
2059 If we are assembling a MOV instruction (or a CALLT.... :-)
2060 and the immediate value does not fit into the bits
2061 available then create a fake error so that the next MOV
2062 instruction will be selected. This one has a 32 bit
2065 if (((insn
& 0x07e0) == 0x0200)
2066 && ex
.X_op
== O_constant
2067 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1)))
2068 || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
2069 errmsg
= _("immediate operand is too large");
2070 /* end-sanitize-v850e */
2076 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n",
2077 insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
2082 errmsg
= _("illegal operand");
2085 errmsg
= _("missing operand");
2088 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
2090 errmsg
= _("invalid operand");
2093 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2095 copy_of_instruction
);
2099 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2101 copy_of_instruction
);
2105 /* We need to generate a fixup for this expression. */
2106 if (fc
>= MAX_INSN_FIXUPS
)
2107 as_fatal (_("too many fixups"));
2109 fixups
[ fc
].exp
= ex
;
2110 fixups
[ fc
].opindex
= * opindex_ptr
;
2111 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
2117 str
= input_line_pointer
;
2118 input_line_pointer
= hold
;
2120 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
2129 next_opcode
= opcode
+ 1;
2130 if (next_opcode
->name
!= NULL
2131 && strcmp (next_opcode
->name
, opcode
->name
) == 0)
2133 opcode
= next_opcode
;
2135 /* Skip versions that are not supported by the target
2137 if ((opcode
->processors
& processor_mask
) == 0)
2143 as_bad ("%s: %s", copy_of_instruction
, errmsg
);
2145 if (* input_line_pointer
== ']')
2146 ++ input_line_pointer
;
2148 ignore_rest_of_line ();
2149 input_line_pointer
= saved_input_line_pointer
;
2155 while (isspace (*str
))
2159 /* xgettext:c-format */
2160 as_bad (_("junk at end of line: `%s'"), str
);
2162 input_line_pointer
= str
;
2164 /* Write out the instruction. */
2166 if (relaxable
&& fc
> 0)
2171 if (!strcmp (opcode
->name
, "br"))
2173 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
2174 fixups
[0].exp
.X_add_symbol
,
2175 fixups
[0].exp
.X_add_number
,
2176 (char *)fixups
[0].opindex
);
2177 md_number_to_chars (f
, insn
, insn_size
);
2178 md_number_to_chars (f
+ 2, 0, 2);
2182 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
2183 fixups
[0].exp
.X_add_symbol
,
2184 fixups
[0].exp
.X_add_number
,
2185 (char *)fixups
[0].opindex
);
2186 md_number_to_chars (f
, insn
, insn_size
);
2187 md_number_to_chars (f
+ 2, 0, 4);
2192 /* Four byte insns have an opcode with the two high bits on. */
2193 if ((insn
& 0x0600) == 0x0600)
2198 /* start-sanitize-v850e */
2199 /* Special case: 32 bit MOV */
2200 if ((insn
& 0xffe0) == 0x0620)
2202 /* end-sanitize-v850e */
2204 f
= frag_more (insn_size
);
2206 md_number_to_chars (f
, insn
, insn_size
);
2208 if (extra_data_after_insn
)
2210 f
= frag_more (extra_data_len
);
2212 md_number_to_chars (f
, extra_data
, extra_data_len
);
2214 extra_data_after_insn
= false;
2218 /* Create any fixups. At this point we do not use a
2219 bfd_reloc_code_real_type, but instead just use the
2220 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2221 handle fixups for any operand type, although that is admittedly
2222 not a very exciting feature. We pick a BFD reloc type in
2224 for (i
= 0; i
< fc
; i
++)
2226 const struct v850_operand
* operand
;
2227 bfd_reloc_code_real_type reloc
;
2229 operand
= & v850_operands
[ fixups
[i
].opindex
];
2231 reloc
= fixups
[i
].reloc
;
2233 if (reloc
!= BFD_RELOC_UNUSED
)
2235 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
2244 size
= bfd_get_reloc_size (reloc_howto
);
2246 /* XXX This will abort on an R_V850_8 reloc -
2247 is this reloc actually used ? */
2248 if (size
!= 2 && size
!= 4)
2251 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
2253 if (reloc
== BFD_RELOC_32
)
2258 fixP
= fix_new_exp (frag_now
, address
, size
,
2260 reloc_howto
->pc_relative
,
2265 case BFD_RELOC_LO16
:
2266 case BFD_RELOC_HI16
:
2267 case BFD_RELOC_HI16_S
:
2268 fixP
->fx_no_overflow
= 1;
2276 f
- frag_now
->fr_literal
, 4,
2278 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2279 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
2280 + (int) BFD_RELOC_UNUSED
)
2285 input_line_pointer
= saved_input_line_pointer
;
2289 /* If while processing a fixup, a reloc really needs to be created */
2290 /* then it is done here. */
2293 tc_gen_reloc (seg
, fixp
)
2299 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2300 reloc
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
2301 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2302 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2304 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2306 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2307 /* xgettext:c-format */
2308 _("reloc %d not supported by object file format"),
2309 (int)fixp
->fx_r_type
);
2316 reloc
->addend
= fixp
->fx_addnumber
;
2321 /* Assume everything will fit in two bytes, then expand as necessary. */
2323 md_estimate_size_before_relax (fragp
, seg
)
2327 if (fragp
->fr_subtype
== 0)
2329 else if (fragp
->fr_subtype
== 2)
2337 md_pcrel_from (fixp
)
2340 /* If the symbol is undefined, or in a section other than our own,
2341 then let the linker figure it out. */
2342 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
2344 /* The symbol is undefined. Let the linker figure it out. */
2347 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2351 md_apply_fix3 (fixp
, valuep
, seg
)
2359 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2364 else if (fixp
->fx_pcrel
)
2368 value
= fixp
->fx_offset
;
2369 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2371 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2372 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2375 /* We don't actually support subtracting a symbol. */
2376 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2377 _("expression too complex"));
2382 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2385 const struct v850_operand
* operand
;
2388 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2389 operand
= & v850_operands
[ opindex
];
2391 /* Fetch the instruction, insert the fully resolved operand
2392 value, and stuff the instruction back again.
2394 Note the instruction has been stored in little endian
2396 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2398 insn
= bfd_getl32 ((unsigned char *) where
);
2399 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2400 fixp
->fx_file
, fixp
->fx_line
, NULL
);
2401 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2405 /* Nothing else to do here. */
2409 /* Determine a BFD reloc value based on the operand information.
2410 We are only prepared to turn a few of the operands into relocs. */
2412 if (operand
->bits
== 22)
2413 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2414 else if (operand
->bits
== 9)
2415 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2418 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2420 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
2421 _("unresolved expression that must be resolved"));
2426 else if (fixp
->fx_done
)
2428 /* We still have to insert the value into memory! */
2429 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2431 if (fixp
->fx_size
== 1)
2432 *where
= value
& 0xff;
2433 else if (fixp
->fx_size
== 2)
2434 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2435 else if (fixp
->fx_size
== 4)
2436 bfd_putl32 (value
, (unsigned char *) where
);
2439 fixp
->fx_addnumber
= value
;
2444 /* Parse a cons expression. We have to handle hi(), lo(), etc
2447 parse_cons_expression_v850 (exp
)
2450 /* See if there's a reloc prefix like hi() we have to handle. */
2451 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2453 /* Do normal expression parsing. */
2457 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2458 found a reloc prefix, then we use that reloc, else we choose an
2459 appropriate one based on the size of the expression. */
2461 cons_fix_new_v850 (frag
, where
, size
, exp
)
2467 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2470 hold_cons_reloc
= BFD_RELOC_32
;
2472 hold_cons_reloc
= BFD_RELOC_16
;
2474 hold_cons_reloc
= BFD_RELOC_8
;
2478 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2480 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);