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 ();
326 as_warn (_("Common alignment negative; 0 assumed"));
339 old_subsec
= now_subseg
;
341 applicable
= bfd_applicable_section_flags (stdoutput
);
343 applicable
&= SEC_ALLOC
;
348 if (sbss_section
== NULL
)
350 sbss_section
= subseg_new (".sbss", 0);
352 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
);
354 seg_info (sbss_section
)->bss
= 1;
359 if (zbss_section
== NULL
)
361 zbss_section
= subseg_new (".zbss", 0);
363 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
);
365 seg_info (zbss_section
)->bss
= 1;
370 if (tbss_section
== NULL
)
372 tbss_section
= subseg_new (".tbss", 0);
374 bfd_set_section_flags (stdoutput
, tbss_section
, applicable
);
376 seg_info (tbss_section
)->bss
= 1;
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
493 | SEC_HAS_CONTENTS
) | SEC_IS_COMMON
);
495 S_SET_SEGMENT (symbolP
, scommon_section
);
499 if (zcommon_section
== NULL
)
503 applicable
= bfd_applicable_section_flags (stdoutput
);
505 zcommon_section
= subseg_new (".zcommon", 0);
507 bfd_set_section_flags (stdoutput
, zcommon_section
, applicable
508 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
509 | SEC_HAS_CONTENTS
) | SEC_IS_COMMON
);
511 S_SET_SEGMENT (symbolP
, zcommon_section
);
515 if (tcommon_section
== NULL
)
519 applicable
= bfd_applicable_section_flags (stdoutput
);
521 tcommon_section
= subseg_new (".tcommon", 0);
523 bfd_set_section_flags (stdoutput
, tcommon_section
, applicable
524 & (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
525 | SEC_HAS_CONTENTS
) | SEC_IS_COMMON
);
527 S_SET_SEGMENT (symbolP
, tcommon_section
);
537 input_line_pointer
++;
538 /* @@ Some use the dot, some don't. Can we get some consistency?? */
539 if (*input_line_pointer
== '.')
540 input_line_pointer
++;
541 /* @@ Some say data, some say bss. */
542 if (strncmp (input_line_pointer
, "bss\"", 4)
543 && strncmp (input_line_pointer
, "data\"", 5))
545 while (*--input_line_pointer
!= '"')
547 input_line_pointer
--;
548 goto bad_common_segment
;
550 while (*input_line_pointer
++ != '"')
552 goto allocate_common
;
555 symbolP
->bsym
->flags
|= BSF_OBJECT
;
557 demand_empty_rest_of_line ();
562 p
= input_line_pointer
;
563 while (*p
&& *p
!= '\n')
567 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
569 input_line_pointer
= p
;
570 ignore_rest_of_line ();
576 set_machine (int number
)
579 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
583 case 0: processor_mask
= PROCESSOR_V850
; break;
584 /* start-sanitize-v850e */
585 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
586 case bfd_mach_v850ea
: processor_mask
= PROCESSOR_V850EA
; break;
587 /* end-sanitize-v850e */
591 /* The target specific pseudo-ops which we support. */
592 const pseudo_typeS md_pseudo_table
[] =
594 {"sdata", v850_sdata
, 0},
595 {"tdata", v850_tdata
, 0},
596 {"zdata", v850_zdata
, 0},
597 {"sbss", v850_sbss
, 0},
598 {"tbss", v850_tbss
, 0},
599 {"zbss", v850_zbss
, 0},
600 {"rosdata", v850_rosdata
, 0},
601 {"rozdata", v850_rozdata
, 0},
602 {"bss", v850_bss
, 0},
603 {"offset", v850_offset
, 0},
605 {"zcomm", v850_comm
, AREA_ZDA
},
606 {"scomm", v850_comm
, AREA_SDA
},
607 {"tcomm", v850_comm
, AREA_TDA
},
608 {"v850", set_machine
, 0},
609 /* start-sanitize-v850e */
610 {"call_table_data", v850_call_table_data
, 0},
611 {"call_table_text", v850_call_table_text
, 0},
612 {"v850e", set_machine
, bfd_mach_v850e
},
613 {"v850ea", set_machine
, bfd_mach_v850ea
},
614 /* end-sanitize-v850e */
618 /* Opcode hash table. */
619 static struct hash_control
*v850_hash
;
621 /* This table is sorted. Suitable for searching by a binary search. */
622 static const struct reg_name pre_defined_registers
[] =
624 { "ep", 30 }, /* ep - element ptr */
625 { "gp", 4 }, /* gp - global ptr */
626 { "hp", 2 }, /* hp - handler stack ptr */
627 { "lp", 31 }, /* lp - link ptr */
660 { "sp", 3 }, /* sp - stack ptr */
661 { "tp", 5 }, /* tp - text ptr */
664 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
667 static const struct reg_name system_registers
[] =
669 /* start-sanitize-v850e */
675 /* end-sanitize-v850e */
683 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
685 /* start-sanitize-v850e */
686 static const struct reg_name system_list_registers
[] =
691 #define SYSREGLIST_NAME_CNT (sizeof (system_list_registers) / sizeof (struct reg_name))
692 /* end-sanitize-v850e */
694 static const struct reg_name cc_names
[] =
719 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
721 /* reg_name_search does a binary search of the given register table
722 to see if "name" is a valid regiter name. Returns the register
723 number from the array on success, or -1 on failure. */
726 reg_name_search (regs
, regcount
, name
, accept_numbers
)
727 const struct reg_name
* regs
;
730 boolean accept_numbers
;
732 int middle
, low
, high
;
736 /* If the register name is a symbol, then evaluate it. */
737 if ((symbolP
= symbol_find (name
)) != NULL
)
739 /* If the symbol is an alias for another name then use that.
740 If the symbol is an alias for a number, then return the number. */
741 if (symbolP
->sy_value
.X_op
== O_symbol
)
743 name
= S_GET_NAME (symbolP
->sy_value
.X_add_symbol
);
745 else if (accept_numbers
)
747 int reg
= S_GET_VALUE (symbolP
);
749 if (reg
>= 0 && reg
<= 31)
753 /* Otherwise drop through and try parsing name normally. */
761 middle
= (low
+ high
) / 2;
762 cmp
= strcasecmp (name
, regs
[middle
].name
);
768 return regs
[middle
].value
;
775 /* Summary of register_name().
777 * in: Input_line_pointer points to 1st char of operand.
779 * out: A expressionS.
780 * The operand may have been a register: in this case, X_op == O_register,
781 * X_add_number is set to the register number, and truth is returned.
782 * Input_line_pointer->(next non-blank) char after operand, or is in
783 * its original state.
786 register_name (expressionP
)
787 expressionS
* expressionP
;
794 /* Find the spelling of the operand */
795 start
= name
= input_line_pointer
;
797 c
= get_symbol_end ();
799 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
,
802 * input_line_pointer
= c
; /* put back the delimiting char */
804 /* look to see if it's in the register table */
807 expressionP
->X_op
= O_register
;
808 expressionP
->X_add_number
= reg_number
;
810 /* make the rest nice */
811 expressionP
->X_add_symbol
= NULL
;
812 expressionP
->X_op_symbol
= NULL
;
818 /* reset the line as if we had not done anything */
819 input_line_pointer
= start
;
825 /* Summary of system_register_name().
827 * in: Input_line_pointer points to 1st char of operand.
828 * expressionP points to an expression structure to be filled in.
829 * accept_numbers is true iff numerical register names may be used.
830 * start-sanitize-v850e
831 * accept_list_names is true iff the special names PS and SR may be
835 * out: A expressionS structure in expressionP.
836 * The operand may have been a register: in this case, X_op == O_register,
837 * X_add_number is set to the register number, and truth is returned.
838 * Input_line_pointer->(next non-blank) char after operand, or is in
839 * its original state.
842 system_register_name (expressionP
, accept_numbers
843 /* start-sanitize-v850e */
845 /* end-sanitize-v850e */
847 expressionS
* expressionP
;
848 boolean accept_numbers
;
849 /* start-sanitize-v850e */
850 boolean accept_list_names
;
851 /* end-sanitize-v850e */
858 /* Find the spelling of the operand */
859 start
= name
= input_line_pointer
;
861 c
= get_symbol_end ();
862 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
,
865 * input_line_pointer
= c
; /* put back the delimiting char */
870 input_line_pointer
= start
; /* reset input_line pointer */
872 if (isdigit (* input_line_pointer
))
874 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
876 /* Make sure that the register number is allowable. */
879 /* start-sanitize-v850e */
882 /* end-sanitize-v850e */
888 /* start-sanitize-v850e */
889 else if (accept_list_names
)
891 c
= get_symbol_end ();
892 reg_number
= reg_name_search (system_list_registers
,
893 SYSREGLIST_NAME_CNT
, name
, FALSE
);
895 * input_line_pointer
= c
; /* put back the delimiting char */
897 /* end-sanitize-v850e */
900 /* look to see if it's in the register table */
903 expressionP
->X_op
= O_register
;
904 expressionP
->X_add_number
= reg_number
;
906 /* make the rest nice */
907 expressionP
->X_add_symbol
= NULL
;
908 expressionP
->X_op_symbol
= NULL
;
914 /* reset the line as if we had not done anything */
915 input_line_pointer
= start
;
921 /* Summary of cc_name().
923 * in: Input_line_pointer points to 1st char of operand.
925 * out: A expressionS.
926 * The operand may have been a register: in this case, X_op == O_register,
927 * X_add_number is set to the register number, and truth is returned.
928 * Input_line_pointer->(next non-blank) char after operand, or is in
929 * its original state.
932 cc_name (expressionP
)
933 expressionS
* expressionP
;
940 /* Find the spelling of the operand */
941 start
= name
= input_line_pointer
;
943 c
= get_symbol_end ();
944 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
, FALSE
);
946 * input_line_pointer
= c
; /* put back the delimiting char */
948 /* look to see if it's in the register table */
951 expressionP
->X_op
= O_constant
;
952 expressionP
->X_add_number
= reg_number
;
954 /* make the rest nice */
955 expressionP
->X_add_symbol
= NULL
;
956 expressionP
->X_op_symbol
= NULL
;
962 /* reset the line as if we had not done anything */
963 input_line_pointer
= start
;
970 skip_white_space (void)
972 while ( * input_line_pointer
== ' '
973 || * input_line_pointer
== '\t')
974 ++ input_line_pointer
;
977 /* start-sanitize-v850e */
978 /* Summary of parse_register_list ().
980 * in: Input_line_pointer points to 1st char of a list of registers.
981 * insn is the partially constructed instruction.
982 * operand is the operand being inserted.
984 * out: NULL if the parse completed successfully, otherwise a
985 * pointer to an error message is returned. If the parse
986 * completes the correct bit fields in the instruction
989 * Parses register lists with the syntax:
997 * and also parses constant epxressions whoes bits indicate the
998 * registers in the lists. The LSB in the expression refers to
999 * the lowest numbered permissable register in the register list,
1000 * and so on upwards. System registers are considered to be very
1007 unsigned long * insn
,
1008 const struct v850_operand
* operand
1011 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 };
1012 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 };
1013 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 };
1018 /* Select a register array to parse. */
1019 switch (operand
->shift
)
1021 case 0xffe00001: regs
= type1_regs
; break;
1022 case 0xfff8000f: regs
= type2_regs
; break;
1023 case 0xfff8001f: regs
= type3_regs
; break;
1025 as_bad (_("unknown operand shift: %x\n"), operand
->shift
);
1026 return _("internal failure in parse_register_list");
1029 skip_white_space ();
1031 /* If the expression starts with a curly brace it is a register list.
1032 Otherwise it is a constant expression, whoes bits indicate which
1033 registers are to be included in the list. */
1035 if (* input_line_pointer
!= '{')
1043 if (exp
.X_op
!= O_constant
)
1044 return _("constant expression or register list expected");
1046 if (regs
== type1_regs
)
1048 if (exp
.X_add_number
& 0xFFFFF000)
1049 return _("high bits set in register list expression");
1051 for (reg
= 20; reg
< 32; reg
++)
1052 if (exp
.X_add_number
& (1 << (reg
- 20)))
1054 for (i
= 0; i
< 32; i
++)
1059 else if (regs
== type2_regs
)
1061 if (exp
.X_add_number
& 0xFFFE0000)
1062 return _("high bits set in register list expression");
1064 for (reg
= 1; reg
< 16; reg
++)
1065 if (exp
.X_add_number
& (1 << (reg
- 1)))
1067 for (i
= 0; i
< 32; i
++)
1072 if (exp
.X_add_number
& (1 << 15))
1075 if (exp
.X_add_number
& (1 << 16))
1076 * insn
|= (1 << 19);
1078 else /* regs == type3_regs */
1080 if (exp
.X_add_number
& 0xFFFE0000)
1081 return _("high bits set in register list expression");
1083 for (reg
= 16; reg
< 32; reg
++)
1084 if (exp
.X_add_number
& (1 << (reg
- 16)))
1086 for (i
= 0; i
< 32; i
++)
1091 if (exp
.X_add_number
& (1 << 16))
1092 * insn
|= (1 << 19);
1098 input_line_pointer
++;
1100 /* Parse the register list until a terminator (closing curly brace or
1101 new-line) is found. */
1104 if (register_name (& exp
))
1108 /* Locate the given register in the list, and if it is there,
1109 insert the corresponding bit into the instruction. */
1110 for (i
= 0; i
< 32; i
++)
1112 if (regs
[ i
] == exp
.X_add_number
)
1121 return _("illegal register included in list");
1124 else if (system_register_name (& exp
, true, true))
1126 if (regs
== type1_regs
)
1128 return _("system registers cannot be included in list");
1130 else if (exp
.X_add_number
== 5)
1132 if (regs
== type2_regs
)
1133 return _("PSW cannot be included in list");
1137 else if (exp
.X_add_number
< 4)
1140 return _("High value system registers cannot be included in list");
1142 else if (* input_line_pointer
== '}')
1144 input_line_pointer
++;
1147 else if (* input_line_pointer
== ',')
1149 input_line_pointer
++;
1152 else if (* input_line_pointer
== '-')
1154 /* We have encountered a range of registers: rX - rY */
1158 /* Skip the dash. */
1159 ++ input_line_pointer
;
1161 /* Get the second register in the range. */
1162 if (! register_name (& exp2
))
1164 return _("second register should follow dash in register list");
1165 exp2
.X_add_number
= exp
.X_add_number
;
1168 /* Add the rest of the registers in the range. */
1169 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1173 /* Locate the given register in the list, and if it is there,
1174 insert the corresponding bit into the instruction. */
1175 for (i
= 0; i
< 32; i
++)
1185 return _("illegal register included in list");
1193 skip_white_space ();
1198 /* end-sanitize-v850e */
1200 CONST
char * md_shortopts
= "m:";
1202 struct option md_longopts
[] =
1204 {NULL
, no_argument
, NULL
, 0}
1206 size_t md_longopts_size
= sizeof md_longopts
;
1210 md_show_usage (stream
)
1213 fprintf (stream
, _(" V850 options:\n"));
1214 fprintf (stream
, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1215 fprintf (stream
, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1216 fprintf (stream
, _(" -mv850 The code is targeted at the v850\n"));
1217 /* start-sanitize-v850e */
1218 fprintf (stream
, _(" -mv850e The code is targeted at the v850e\n"));
1219 fprintf (stream
, _(" -mv850ea The code is targeted at the v850ea\n"));
1220 fprintf (stream
, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1221 /* end-sanitize-v850e */
1225 md_parse_option (c
, arg
)
1231 /* xgettext:c-format */
1232 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1236 if (strcmp (arg
, "warn-signed-overflow") == 0)
1238 warn_signed_overflows
= TRUE
;
1240 else if (strcmp (arg
, "warn-unsigned-overflow") == 0)
1242 warn_unsigned_overflows
= TRUE
;
1244 else if (strcmp (arg
, "v850") == 0)
1247 processor_mask
= PROCESSOR_V850
;
1249 /* start-sanitize-v850e */
1250 else if (strcmp (arg
, "v850e") == 0)
1252 machine
= bfd_mach_v850e
;
1253 processor_mask
= PROCESSOR_V850E
;
1255 else if (strcmp (arg
, "v850ea") == 0)
1257 machine
= bfd_mach_v850ea
;
1258 processor_mask
= PROCESSOR_V850EA
;
1260 else if (strcmp (arg
, "v850any") == 0)
1262 machine
= 0; /* Tell the world that this is for any v850 chip. */
1263 processor_mask
= PROCESSOR_V850EA
; /* But support instructions for the extended versions. */
1265 /* end-sanitize-v850e */
1268 /* xgettext:c-format */
1269 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1277 md_undefined_symbol (name
)
1284 md_atof (type
, litp
, sizep
)
1290 LITTLENUM_TYPE words
[4];
1306 return _("bad call to md_atof");
1309 t
= atof_ieee (input_line_pointer
, type
, words
);
1311 input_line_pointer
= t
;
1315 for (i
= prec
- 1; i
>= 0; i
--)
1317 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1327 md_convert_frag (abfd
, sec
, fragP
)
1332 subseg_change (sec
, 0);
1334 /* In range conditional or unconditional branch. */
1335 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1337 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1338 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1342 /* Out of range conditional branch. Emit a branch around a jump. */
1343 else if (fragP
->fr_subtype
== 1)
1345 unsigned char *buffer
=
1346 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1348 /* Reverse the condition of the first branch. */
1350 /* Mask off all the displacement bits. */
1353 /* Now set the displacement bits so that we branch
1354 around the unconditional branch. */
1357 /* Now create the unconditional branch + fixup to the final
1359 md_number_to_chars (buffer
+ 2, 0x00000780, 4);
1360 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1361 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1362 (int) fragP
->fr_opcode
+ 1);
1366 /* Out of range unconditional branch. Emit a jump. */
1367 else if (fragP
->fr_subtype
== 3)
1369 md_number_to_chars (fragP
->fr_fix
+ fragP
->fr_literal
, 0x00000780, 4);
1370 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
1371 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1372 (int) fragP
->fr_opcode
+ 1);
1381 md_section_align (seg
, addr
)
1385 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1386 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1392 char * prev_name
= "";
1393 register const struct v850_opcode
* op
;
1394 flagword applicable
;
1396 /* start-sanitize-v850e */
1397 if (strncmp (TARGET_CPU
, "v850ea", 6) == 0)
1400 machine
= bfd_mach_v850ea
;
1402 if (processor_mask
== -1)
1403 processor_mask
= PROCESSOR_V850EA
;
1405 else if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1408 machine
= bfd_mach_v850e
;
1410 if (processor_mask
== -1)
1411 processor_mask
= PROCESSOR_V850E
;
1414 /* end-sanitize-v850e */
1415 if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1420 if (processor_mask
== -1)
1421 processor_mask
= PROCESSOR_V850
;
1424 /* xgettext:c-format */
1425 as_bad (_("Unable to determine default target processor from string: %s"),
1428 v850_hash
= hash_new();
1430 /* Insert unique names into hash table. The V850 instruction set
1431 has many identical opcode names that have different opcodes based
1432 on the operands. This hash table then provides a quick index to
1433 the first opcode with a particular name in the opcode table. */
1438 if (strcmp (prev_name
, op
->name
))
1440 prev_name
= (char *) op
->name
;
1441 hash_insert (v850_hash
, op
->name
, (char *) op
);
1446 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1448 /* start-sanitize-v850e */
1449 applicable
= bfd_applicable_section_flags (stdoutput
);
1451 call_table_data_section
= subseg_new (".call_table_data", 0);
1452 bfd_set_section_flags (stdoutput
, call_table_data_section
,
1453 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
1454 | SEC_DATA
| SEC_HAS_CONTENTS
));
1456 call_table_text_section
= subseg_new (".call_table_text", 0);
1457 bfd_set_section_flags (stdoutput
, call_table_text_section
,
1458 applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
1461 /* Restore text section as the current default. */
1462 subseg_set (text_section
, 0);
1463 /* end-sanitize-v850e */
1467 /* start-sanitize-v850e */
1468 static bfd_reloc_code_real_type
1469 handle_ctoff (const struct v850_operand
* operand
)
1471 if (operand
== NULL
)
1472 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1474 if ( operand
->bits
!= 6
1475 || operand
->shift
!= 0)
1477 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1478 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1481 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1483 /* end-sanitize-v850e */
1485 static bfd_reloc_code_real_type
1486 handle_sdaoff (const struct v850_operand
* operand
)
1488 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1489 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1490 /* start-sanitize-v850e */
1491 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1492 /* end-sanitize-v850e */
1494 if ( operand
->bits
!= 16
1495 || operand
->shift
!= 16)
1497 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1498 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1501 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1504 static bfd_reloc_code_real_type
1505 handle_zdaoff (const struct v850_operand
* operand
)
1507 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1508 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1509 /* start-sanitize-v850e */
1510 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1511 /* end-sanitize-v850e */
1513 if ( operand
->bits
!= 16
1514 || operand
->shift
!= 16)
1516 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1517 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1520 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1523 static bfd_reloc_code_real_type
1524 handle_tdaoff (const struct v850_operand
* operand
)
1526 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
; /* data item, not an instruction. */
1527 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
; /* sld.w/sst.w, operand: D8_6 */
1528 /* start-sanitize-v850e */
1529 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
; /* sld.hu, operand: D5-4 */
1530 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
; /* sld.bu, operand: D4 */
1531 /* end-sanitize-v850e */
1532 if (operand
->bits
== 16 && operand
->shift
== 16) return BFD_RELOC_V850_TDA_16_16_OFFSET
; /* set1 & chums, operands: D16 */
1534 if (operand
->bits
!= 7)
1536 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1537 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1540 return operand
->insert
!= NULL
1541 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1542 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1545 /* Warning: The code in this function relies upon the definitions
1546 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1547 matching the hard coded values contained herein. */
1549 static bfd_reloc_code_real_type
1550 v850_reloc_prefix (const struct v850_operand
* operand
)
1552 boolean paren_skipped
= false;
1555 /* Skip leading opening parenthesis. */
1556 if (* input_line_pointer
== '(')
1558 ++ input_line_pointer
;
1559 paren_skipped
= true;
1562 #define CHECK_(name, reloc) \
1563 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1565 input_line_pointer += strlen (name); \
1569 CHECK_ ("hi0", BFD_RELOC_HI16
);
1570 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1571 CHECK_ ("lo", BFD_RELOC_LO16
);
1572 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1573 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1574 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1576 /* start-sanitize-v850e */
1577 CHECK_ ("hilo", BFD_RELOC_32
);
1578 CHECK_ ("ctoff", handle_ctoff (operand
));
1579 /* end-sanitize-v850e */
1581 /* Restore skipped parenthesis. */
1583 -- input_line_pointer
;
1585 return BFD_RELOC_UNUSED
;
1588 /* Insert an operand value into an instruction. */
1590 static unsigned long
1591 v850_insert_operand (insn
, operand
, val
, file
, line
, str
)
1593 const struct v850_operand
* operand
;
1599 if (operand
->insert
)
1601 const char * message
= NULL
;
1603 insn
= operand
->insert (insn
, val
, & message
);
1604 if (message
!= NULL
)
1606 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1607 && ! warn_signed_overflows
1608 && strstr (message
, "out of range") != NULL
)
1610 /* skip warning... */
1612 else if ((operand
->flags
& V850_OPERAND_SIGNED
) == 0
1613 && ! warn_unsigned_overflows
1614 && strstr (message
, "out of range") != NULL
)
1616 /* skip warning... */
1620 if (file
== (char *) NULL
)
1621 as_warn ("%s: %s", str
, message
);
1623 as_warn_where (file
, line
, "%s: %s", str
, message
);
1627 if (file
== (char *) NULL
)
1630 as_warn_where (file
, line
, message
);
1636 if (operand
->bits
!= 32)
1641 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1643 if (! warn_signed_overflows
)
1644 max
= (1 << operand
->bits
) - 1;
1646 max
= (1 << (operand
->bits
- 1)) - 1;
1648 min
= - (1 << (operand
->bits
- 1));
1652 max
= (1 << operand
->bits
) - 1;
1654 if (! warn_unsigned_overflows
)
1655 min
= - (1 << (operand
->bits
- 1));
1660 if (val
< (offsetT
) min
|| val
> (offsetT
) max
)
1662 /* xgettext:c-format */
1663 const char * err
= _("operand out of range (%s not between %ld and %ld)");
1666 /* Restore min and mix to expected values for decimal ranges. */
1667 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1668 && ! warn_signed_overflows
)
1669 max
= (1 << (operand
->bits
- 1)) - 1;
1671 if (! (operand
->flags
& V850_OPERAND_SIGNED
)
1672 && ! warn_unsigned_overflows
)
1677 sprintf (buf
, "%s: ", str
);
1679 sprint_value (buf
+ strlen (buf
), val
);
1682 sprint_value (buf
, val
);
1684 if (file
== (char *) NULL
)
1685 as_warn (err
, buf
, min
, max
);
1687 as_warn_where (file
, line
, err
, buf
, min
, max
);
1691 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1698 static char copy_of_instruction
[128];
1705 char * start_of_operands
;
1706 struct v850_opcode
* opcode
;
1707 struct v850_opcode
* next_opcode
;
1708 const unsigned char * opindex_ptr
;
1712 unsigned long insn_size
;
1716 boolean extra_data_after_insn
= false;
1717 unsigned extra_data_len
;
1718 unsigned long extra_data
;
1719 char * saved_input_line_pointer
;
1722 strncpy (copy_of_instruction
, str
, sizeof (copy_of_instruction
) - 1);
1724 /* Get the opcode. */
1725 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1731 /* find the first opcode with the proper name */
1732 opcode
= (struct v850_opcode
*) hash_find (v850_hash
, str
);
1735 /* xgettext:c-format */
1736 as_bad (_("Unrecognized opcode: `%s'"), str
);
1737 ignore_rest_of_line ();
1742 while (isspace (* str
))
1745 start_of_operands
= str
;
1747 saved_input_line_pointer
= input_line_pointer
;
1751 const char * errmsg
= NULL
;
1755 if ((opcode
->processors
& processor_mask
) == 0)
1757 errmsg
= _("Target processor does not support this instruction.");
1764 insn
= opcode
->opcode
;
1765 extra_data_after_insn
= false;
1767 input_line_pointer
= str
= start_of_operands
;
1769 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1771 const struct v850_operand
* operand
;
1774 bfd_reloc_code_real_type reloc
;
1776 if (next_opindex
== 0)
1778 operand
= & v850_operands
[ * opindex_ptr
];
1782 operand
= & v850_operands
[ next_opindex
];
1788 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1791 if (operand
->flags
& V850_OPERAND_RELAX
)
1794 /* Gather the operand. */
1795 hold
= input_line_pointer
;
1796 input_line_pointer
= str
;
1798 /* lo(), hi(), hi0(), etc... */
1799 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1801 /* This is a fake reloc, used to indicate an error condition. */
1802 if (reloc
== BFD_RELOC_64
)
1810 if (ex
.X_op
== O_constant
)
1814 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1815 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1819 case BFD_RELOC_LO16
:
1821 /* Truncate, then sign extend the value. */
1822 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1826 case BFD_RELOC_HI16
:
1828 /* Truncate, then sign extend the value. */
1829 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1833 case BFD_RELOC_HI16_S
:
1835 /* Truncate, then sign extend the value. */
1836 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1838 temp
+= (ex
.X_add_number
>> 15) & 1;
1840 ex
.X_add_number
= SEXT16 (temp
);
1844 /* start-sanitize-v850e */
1846 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1848 errmsg
= _("immediate operand is too large");
1852 extra_data_after_insn
= true;
1854 extra_data
= ex
.X_add_number
;
1855 ex
.X_add_number
= 0;
1857 /* end-sanitize-v850e */
1860 fprintf (stderr
, "reloc: %d\n", reloc
);
1861 as_bad (_("AAARG -> unhandled constant reloc"));
1865 if (fc
> MAX_INSN_FIXUPS
)
1866 as_fatal (_("too many fixups"));
1868 fixups
[ fc
].exp
= ex
;
1869 fixups
[ fc
].opindex
= * opindex_ptr
;
1870 fixups
[ fc
].reloc
= reloc
;
1875 /* start-sanitize-v850e */
1876 if (reloc
== BFD_RELOC_32
)
1878 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1880 errmsg
= _("immediate operand is too large");
1884 extra_data_after_insn
= true;
1886 extra_data
= ex
.X_add_number
;
1888 /* end-sanitize-v850e */
1890 if (fc
> MAX_INSN_FIXUPS
)
1891 as_fatal (_("too many fixups"));
1893 fixups
[ fc
].exp
= ex
;
1894 fixups
[ fc
].opindex
= * opindex_ptr
;
1895 fixups
[ fc
].reloc
= reloc
;
1903 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1905 if (!register_name (& ex
))
1907 errmsg
= _("invalid register name");
1909 else if ((operand
->flags
& V850_NOT_R0
)
1910 && ex
.X_add_number
== 0)
1912 errmsg
= _("register r0 cannot be used here");
1914 /* Force an error message to be generated by
1915 skipping over any following potential matches
1920 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1922 if (!system_register_name (& ex
, true
1923 /* start-sanitize-v850e */
1925 /* end-sanitize-v850e */
1928 errmsg
= _("invalid system register name");
1931 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1933 char * start
= input_line_pointer
;
1934 char c
= get_symbol_end ();
1936 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1938 /* Put things back the way we found them. */
1939 *input_line_pointer
= c
;
1940 input_line_pointer
= start
;
1941 errmsg
= _("expected EP register");
1945 *input_line_pointer
= c
;
1946 str
= input_line_pointer
;
1947 input_line_pointer
= hold
;
1949 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1953 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1955 if (!cc_name (& ex
))
1957 errmsg
= _("invalid condition code name");
1960 /* start-sanitize-v850e */
1961 else if (operand
->flags
& V850E_PUSH_POP
)
1963 errmsg
= parse_register_list (& insn
, operand
);
1965 /* The parse_register_list() function has already done
1966 everything, so fake a dummy expression. */
1967 ex
.X_op
= O_constant
;
1968 ex
.X_add_number
= 0;
1970 else if (operand
->flags
& V850E_IMMEDIATE16
)
1974 if (ex
.X_op
!= O_constant
)
1975 errmsg
= _("constant expression expected");
1976 else if (ex
.X_add_number
& 0xffff0000)
1978 if (ex
.X_add_number
& 0xffff)
1979 errmsg
= _("constant too big to fit into instruction");
1980 else if ((insn
& 0x001fffc0) == 0x00130780)
1981 ex
.X_add_number
>>= 16;
1983 errmsg
= _("constant too big to fit into instruction");
1986 extra_data_after_insn
= true;
1988 extra_data
= ex
.X_add_number
;
1989 ex
.X_add_number
= 0;
1991 else if (operand
->flags
& V850E_IMMEDIATE32
)
1995 if (ex
.X_op
!= O_constant
)
1996 errmsg
= _("constant expression expected");
1998 extra_data_after_insn
= true;
2000 extra_data
= ex
.X_add_number
;
2001 ex
.X_add_number
= 0;
2003 /* end-sanitize-v850e */
2004 else if (register_name (& ex
)
2005 && (operand
->flags
& V850_OPERAND_REG
) == 0)
2010 /* It is possible that an alias has been defined that
2011 matches a register name. For example the code may
2012 include a ".set ZERO, 0" directive, which matches
2013 the register name "zero". Attempt to reparse the
2014 field as an expression, and only complain if we
2015 cannot generate a constant. */
2017 input_line_pointer
= str
;
2019 c
= get_symbol_end ();
2021 if (symbol_find (str
) != NULL
)
2024 * input_line_pointer
= c
;
2025 input_line_pointer
= str
;
2029 if (ex
.X_op
!= O_constant
)
2031 /* If this register is actually occuring too early on
2032 the parsing of the instruction, (because another
2033 field is missing) then report this. */
2034 if (opindex_ptr
[1] != 0
2035 && (v850_operands
[opindex_ptr
[1]].flags
& V850_OPERAND_REG
))
2036 errmsg
= _("syntax error: value is missing before the register name");
2038 errmsg
= _("syntax error: register not expected");
2040 /* If we created a symbol in the process of this test then
2041 delete it now, so that it will not be output with the real
2044 && ex
.X_op
== O_symbol
)
2045 symbol_remove (ex
.X_add_symbol
,
2046 & symbol_rootP
, & symbol_lastP
);
2049 else if (system_register_name (& ex
, false
2050 /* start-sanitize-v850e */
2052 /* end-sanitize-v850e */
2054 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
2056 errmsg
= _("syntax error: system register not expected");
2058 else if (cc_name (&ex
)
2059 && (operand
->flags
& V850_OPERAND_CC
) == 0)
2061 errmsg
= _("syntax error: condition code not expected");
2066 /* start-sanitize-v850e */
2068 If we are assembling a MOV instruction (or a CALLT.... :-)
2069 and the immediate value does not fit into the bits
2070 available then create a fake error so that the next MOV
2071 instruction will be selected. This one has a 32 bit
2074 if (((insn
& 0x07e0) == 0x0200)
2075 && ex
.X_op
== O_constant
2076 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1)))
2077 || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
2078 errmsg
= _("immediate operand is too large");
2079 /* end-sanitize-v850e */
2085 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n",
2086 insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
2091 errmsg
= _("illegal operand");
2094 errmsg
= _("missing operand");
2097 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
2099 errmsg
= _("invalid operand");
2102 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2104 copy_of_instruction
);
2108 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2110 copy_of_instruction
);
2114 /* We need to generate a fixup for this expression. */
2115 if (fc
>= MAX_INSN_FIXUPS
)
2116 as_fatal (_("too many fixups"));
2118 fixups
[ fc
].exp
= ex
;
2119 fixups
[ fc
].opindex
= * opindex_ptr
;
2120 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
2126 str
= input_line_pointer
;
2127 input_line_pointer
= hold
;
2129 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
2138 next_opcode
= opcode
+ 1;
2139 if (next_opcode
->name
!= NULL
2140 && strcmp (next_opcode
->name
, opcode
->name
) == 0)
2142 opcode
= next_opcode
;
2144 /* Skip versions that are not supported by the target
2146 if ((opcode
->processors
& processor_mask
) == 0)
2152 as_bad ("%s: %s", copy_of_instruction
, errmsg
);
2154 if (* input_line_pointer
== ']')
2155 ++ input_line_pointer
;
2157 ignore_rest_of_line ();
2158 input_line_pointer
= saved_input_line_pointer
;
2164 while (isspace (*str
))
2168 /* xgettext:c-format */
2169 as_bad (_("junk at end of line: `%s'"), str
);
2171 input_line_pointer
= str
;
2173 /* Write out the instruction. */
2175 if (relaxable
&& fc
> 0)
2180 if (!strcmp (opcode
->name
, "br"))
2182 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
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, 2);
2191 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
2192 fixups
[0].exp
.X_add_symbol
,
2193 fixups
[0].exp
.X_add_number
,
2194 (char *)fixups
[0].opindex
);
2195 md_number_to_chars (f
, insn
, insn_size
);
2196 md_number_to_chars (f
+ 2, 0, 4);
2201 /* Four byte insns have an opcode with the two high bits on. */
2202 if ((insn
& 0x0600) == 0x0600)
2207 /* start-sanitize-v850e */
2208 /* Special case: 32 bit MOV */
2209 if ((insn
& 0xffe0) == 0x0620)
2211 /* end-sanitize-v850e */
2213 f
= frag_more (insn_size
);
2215 md_number_to_chars (f
, insn
, insn_size
);
2217 if (extra_data_after_insn
)
2219 f
= frag_more (extra_data_len
);
2221 md_number_to_chars (f
, extra_data
, extra_data_len
);
2223 extra_data_after_insn
= false;
2227 /* Create any fixups. At this point we do not use a
2228 bfd_reloc_code_real_type, but instead just use the
2229 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2230 handle fixups for any operand type, although that is admittedly
2231 not a very exciting feature. We pick a BFD reloc type in
2233 for (i
= 0; i
< fc
; i
++)
2235 const struct v850_operand
* operand
;
2236 bfd_reloc_code_real_type reloc
;
2238 operand
= & v850_operands
[ fixups
[i
].opindex
];
2240 reloc
= fixups
[i
].reloc
;
2242 if (reloc
!= BFD_RELOC_UNUSED
)
2244 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
2253 size
= bfd_get_reloc_size (reloc_howto
);
2255 /* XXX This will abort on an R_V850_8 reloc -
2256 is this reloc actually used ? */
2257 if (size
!= 2 && size
!= 4)
2260 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
2262 if (reloc
== BFD_RELOC_32
)
2267 fixP
= fix_new_exp (frag_now
, address
, size
,
2269 reloc_howto
->pc_relative
,
2274 case BFD_RELOC_LO16
:
2275 case BFD_RELOC_HI16
:
2276 case BFD_RELOC_HI16_S
:
2277 fixP
->fx_no_overflow
= 1;
2285 f
- frag_now
->fr_literal
, 4,
2287 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2288 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
2289 + (int) BFD_RELOC_UNUSED
)
2294 input_line_pointer
= saved_input_line_pointer
;
2298 /* If while processing a fixup, a reloc really needs to be created */
2299 /* then it is done here. */
2302 tc_gen_reloc (seg
, fixp
)
2308 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2309 reloc
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
2310 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2311 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2313 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2315 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2316 /* xgettext:c-format */
2317 _("reloc %d not supported by object file format"),
2318 (int) fixp
->fx_r_type
);
2325 reloc
->addend
= fixp
->fx_addnumber
;
2330 /* Assume everything will fit in two bytes, then expand as necessary. */
2332 md_estimate_size_before_relax (fragp
, seg
)
2336 if (fragp
->fr_subtype
== 0)
2338 else if (fragp
->fr_subtype
== 2)
2346 v850_pcrel_from_section (fixp
, section
)
2350 /* If the symbol is undefined, or in a section other than our own,
2351 then let the linker figure it out. */
2352 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2353 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2354 || (S_GET_SEGMENT (fixp
->fx_addsy
) != section
)))
2356 /* The symbol is undefined/not in our section.
2357 Let the linker figure it out. */
2361 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2365 md_apply_fix3 (fixp
, valuep
, seg
)
2373 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2378 else if (fixp
->fx_pcrel
)
2382 value
= fixp
->fx_offset
;
2383 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2385 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2386 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2389 /* We don't actually support subtracting a symbol. */
2390 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2391 _("expression too complex"));
2396 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2399 const struct v850_operand
* operand
;
2402 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2403 operand
= & v850_operands
[ opindex
];
2405 /* Fetch the instruction, insert the fully resolved operand
2406 value, and stuff the instruction back again.
2408 Note the instruction has been stored in little endian
2410 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2412 insn
= bfd_getl32 ((unsigned char *) where
);
2413 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2414 fixp
->fx_file
, fixp
->fx_line
, NULL
);
2415 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2419 /* Nothing else to do here. */
2423 /* Determine a BFD reloc value based on the operand information.
2424 We are only prepared to turn a few of the operands into relocs. */
2426 if (operand
->bits
== 22)
2427 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2428 else if (operand
->bits
== 9)
2429 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2432 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2434 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2435 _("unresolved expression that must be resolved"));
2440 else if (fixp
->fx_done
)
2442 /* We still have to insert the value into memory! */
2443 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2445 if (fixp
->fx_size
== 1)
2446 * where
= value
& 0xff;
2447 else if (fixp
->fx_size
== 2)
2448 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2449 else if (fixp
->fx_size
== 4)
2450 bfd_putl32 (value
, (unsigned char *) where
);
2453 fixp
->fx_addnumber
= value
;
2458 /* Parse a cons expression. We have to handle hi(), lo(), etc
2461 parse_cons_expression_v850 (exp
)
2464 /* See if there's a reloc prefix like hi() we have to handle. */
2465 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2467 /* Do normal expression parsing. */
2471 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2472 found a reloc prefix, then we use that reloc, else we choose an
2473 appropriate one based on the size of the expression. */
2475 cons_fix_new_v850 (frag
, where
, size
, exp
)
2481 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2484 hold_cons_reloc
= BFD_RELOC_32
;
2486 hold_cons_reloc
= BFD_RELOC_16
;
2488 hold_cons_reloc
= BFD_RELOC_8
;
2492 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2494 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);