1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "safe-ctype.h"
26 #include "opcode/v850.h"
27 #include "dwarf2dbg.h"
29 /* Sign-extend a 16-bit number. */
30 #define SEXT16(x) ((((x) & 0xffff) ^ (~0x7fff)) + 0x8000)
32 /* Temporarily holds the reloc in a cons expression. */
33 static bfd_reloc_code_real_type hold_cons_reloc
= BFD_RELOC_UNUSED
;
35 /* Set to TRUE if we want to be pedantic about signed overflows. */
36 static bfd_boolean warn_signed_overflows
= FALSE
;
37 static bfd_boolean warn_unsigned_overflows
= FALSE
;
39 /* Indicates the target BFD machine number. */
40 static int machine
= -1;
42 /* Indicates the target processor(s) for the assemble. */
43 static int processor_mask
= -1;
45 /* Structure to hold information about predefined registers. */
51 /* Generic assembler global variables which must be defined by all
54 /* Characters which always start a comment. */
55 const char comment_chars
[] = "#";
57 /* Characters which start a comment at the beginning of a line. */
58 const char line_comment_chars
[] = ";#";
60 /* Characters which may be used to separate multiple commands on a
62 const char line_separator_chars
[] = ";";
64 /* Characters which are used to indicate an exponent in a floating
66 const char EXP_CHARS
[] = "eE";
68 /* Characters which mean that a number is a floating point constant,
70 const char FLT_CHARS
[] = "dD";
72 const relax_typeS md_relax_table
[] = {
73 /* Conditional branches. */
75 {0x1fffff, -0x200000, 6, 0},
76 /* Unconditional branches. */
78 {0x1fffff, -0x200000, 4, 0},
81 static int v850_relax
= 0;
84 #define MAX_INSN_FIXUPS (5)
88 bfd_reloc_code_real_type reloc
;
91 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
101 struct v850_seg_entry v850_seg_table
[] =
104 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
107 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
},
109 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
},
111 SEC_ALLOC
| SEC_SMALL_DATA
},
117 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
| SEC_DATA
118 | SEC_HAS_CONTENTS
| SEC_SMALL_DATA
},
120 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
| SEC_DATA
121 | SEC_HAS_CONTENTS
},
123 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
124 | SEC_SMALL_DATA
| SEC_IS_COMMON
},
126 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
129 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
131 { NULL
, ".call_table_data",
132 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
},
133 { NULL
, ".call_table_text",
134 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
| SEC_CODE
140 #define SDATA_SECTION 0
141 #define TDATA_SECTION 1
142 #define ZDATA_SECTION 2
143 #define SBSS_SECTION 3
144 #define TBSS_SECTION 4
145 #define ZBSS_SECTION 5
146 #define ROSDATA_SECTION 6
147 #define ROZDATA_SECTION 7
148 #define SCOMMON_SECTION 8
149 #define TCOMMON_SECTION 9
150 #define ZCOMMON_SECTION 10
151 #define CALL_TABLE_DATA_SECTION 11
152 #define CALL_TABLE_TEXT_SECTION 12
153 #define BSS_SECTION 13
155 static void do_v850_seg
PARAMS ((int, subsegT
));
162 struct v850_seg_entry
*seg
= v850_seg_table
+ i
;
164 obj_elf_section_change_hook ();
167 subseg_set (seg
->s
, sub
);
171 seg
->s
= subseg_new (seg
->name
, sub
);
172 bfd_set_section_flags (stdoutput
, seg
->s
, seg
->flags
);
173 if ((seg
->flags
& SEC_LOAD
) == 0)
174 seg_info (seg
->s
)->bss
= 1;
178 static void v850_seg
PARAMS ((int i
));
184 subsegT sub
= get_absolute_expression ();
186 do_v850_seg (i
, sub
);
187 demand_empty_rest_of_line ();
190 static void v850_offset
PARAMS ((int));
194 int ignore ATTRIBUTE_UNUSED
;
197 int temp
= get_absolute_expression ();
199 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, (symbolS
*)0,
200 (offsetT
) temp
, (char *) 0);
203 demand_empty_rest_of_line ();
206 /* Copied from obj_elf_common() in gas/config/obj-elf.c. */
208 static void v850_comm
PARAMS ((int));
222 name
= input_line_pointer
;
223 c
= get_symbol_end ();
225 /* Just after name is now '\0'. */
226 p
= input_line_pointer
;
231 if (*input_line_pointer
!= ',')
233 as_bad (_("Expected comma after symbol-name"));
234 ignore_rest_of_line ();
239 input_line_pointer
++;
241 if ((temp
= get_absolute_expression ()) < 0)
243 /* xgettext:c-format */
244 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp
);
245 ignore_rest_of_line ();
251 symbolP
= symbol_find_or_make (name
);
254 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
256 as_bad (_("Ignoring attempt to re-define symbol"));
257 ignore_rest_of_line ();
261 if (S_GET_VALUE (symbolP
) != 0)
263 if (S_GET_VALUE (symbolP
) != size
)
265 /* xgettext:c-format */
266 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
267 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
271 know (symbol_get_frag (symbolP
) == &zero_address_frag
);
273 if (*input_line_pointer
!= ',')
278 input_line_pointer
++;
282 if (! have_align
|| *input_line_pointer
!= '"')
288 temp
= get_absolute_expression ();
293 as_warn (_("Common alignment negative; 0 assumed"));
297 if (symbol_get_obj (symbolP
)->local
)
306 old_subsec
= now_subseg
;
308 applicable
= bfd_applicable_section_flags (stdoutput
);
310 applicable
&= SEC_ALLOC
;
314 case SCOMMON_SECTION
:
315 do_v850_seg (SBSS_SECTION
, 0);
318 case ZCOMMON_SECTION
:
319 do_v850_seg (ZBSS_SECTION
, 0);
322 case TCOMMON_SECTION
:
323 do_v850_seg (TBSS_SECTION
, 0);
329 /* Convert to a power of 2 alignment. */
330 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
)
335 as_bad (_("Common alignment not a power of 2"));
336 ignore_rest_of_line ();
343 record_alignment (now_seg
, align
);
346 frag_align (align
, 0, 0);
350 case SCOMMON_SECTION
:
351 if (S_GET_SEGMENT (symbolP
) == v850_seg_table
[SBSS_SECTION
].s
)
352 symbol_get_frag (symbolP
)->fr_symbol
= 0;
355 case ZCOMMON_SECTION
:
356 if (S_GET_SEGMENT (symbolP
) == v850_seg_table
[ZBSS_SECTION
].s
)
357 symbol_get_frag (symbolP
)->fr_symbol
= 0;
360 case TCOMMON_SECTION
:
361 if (S_GET_SEGMENT (symbolP
) == v850_seg_table
[TBSS_SECTION
].s
)
362 symbol_get_frag (symbolP
)->fr_symbol
= 0;
369 symbol_set_frag (symbolP
, frag_now
);
370 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
371 (offsetT
) size
, (char *) 0);
373 S_SET_SIZE (symbolP
, size
);
377 case SCOMMON_SECTION
:
378 S_SET_SEGMENT (symbolP
, v850_seg_table
[SBSS_SECTION
].s
);
381 case ZCOMMON_SECTION
:
382 S_SET_SEGMENT (symbolP
, v850_seg_table
[ZBSS_SECTION
].s
);
385 case TCOMMON_SECTION
:
386 S_SET_SEGMENT (symbolP
, v850_seg_table
[TBSS_SECTION
].s
);
393 S_CLEAR_EXTERNAL (symbolP
);
394 obj_elf_section_change_hook ();
395 subseg_set (old_sec
, old_subsec
);
404 old_subsec
= now_subseg
;
406 S_SET_VALUE (symbolP
, (valueT
) size
);
407 S_SET_ALIGN (symbolP
, temp
);
408 S_SET_EXTERNAL (symbolP
);
412 case SCOMMON_SECTION
:
413 case ZCOMMON_SECTION
:
414 case TCOMMON_SECTION
:
415 do_v850_seg (area
, 0);
416 S_SET_SEGMENT (symbolP
, v850_seg_table
[area
].s
);
423 obj_elf_section_change_hook ();
424 subseg_set (old_sec
, old_subsec
);
429 input_line_pointer
++;
431 /* @@ Some use the dot, some don't. Can we get some consistency?? */
432 if (*input_line_pointer
== '.')
433 input_line_pointer
++;
435 /* @@ Some say data, some say bss. */
436 if (strncmp (input_line_pointer
, "bss\"", 4)
437 && strncmp (input_line_pointer
, "data\"", 5))
439 while (*--input_line_pointer
!= '"')
441 input_line_pointer
--;
442 goto bad_common_segment
;
444 while (*input_line_pointer
++ != '"')
446 goto allocate_common
;
449 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
451 demand_empty_rest_of_line ();
456 p
= input_line_pointer
;
457 while (*p
&& *p
!= '\n')
461 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
463 input_line_pointer
= p
;
464 ignore_rest_of_line ();
469 static void set_machine
PARAMS ((int));
476 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
480 case 0: processor_mask
= PROCESSOR_V850
; break;
481 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
485 static void v850_longcode
PARAMS ((int));
496 as_warn (".longcall pseudo-op seen when not relaxing");
498 as_warn (".longjump pseudo-op seen when not relaxing");
503 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
505 as_bad ("bad .longcall format");
506 ignore_rest_of_line ();
512 fix_new_exp (frag_now
, frag_now_fix (), 4, & ex
, 1,
513 BFD_RELOC_V850_LONGCALL
);
515 fix_new_exp (frag_now
, frag_now_fix (), 4, & ex
, 1,
516 BFD_RELOC_V850_LONGJUMP
);
518 demand_empty_rest_of_line ();
521 /* The target specific pseudo-ops which we support. */
522 const pseudo_typeS md_pseudo_table
[] = {
523 { "sdata", v850_seg
, SDATA_SECTION
},
524 { "tdata", v850_seg
, TDATA_SECTION
},
525 { "zdata", v850_seg
, ZDATA_SECTION
},
526 { "sbss", v850_seg
, SBSS_SECTION
},
527 { "tbss", v850_seg
, TBSS_SECTION
},
528 { "zbss", v850_seg
, ZBSS_SECTION
},
529 { "rosdata", v850_seg
, ROSDATA_SECTION
},
530 { "rozdata", v850_seg
, ROZDATA_SECTION
},
531 { "bss", v850_seg
, BSS_SECTION
},
532 { "offset", v850_offset
, 0 },
534 { "zcomm", v850_comm
, ZCOMMON_SECTION
},
535 { "scomm", v850_comm
, SCOMMON_SECTION
},
536 { "tcomm", v850_comm
, TCOMMON_SECTION
},
537 { "v850", set_machine
, 0 },
538 { "call_table_data", v850_seg
, CALL_TABLE_DATA_SECTION
},
539 { "call_table_text", v850_seg
, CALL_TABLE_TEXT_SECTION
},
540 { "v850e", set_machine
, bfd_mach_v850e
},
541 { "file", (void (*) PARAMS ((int))) dwarf2_directive_file
, 0 },
542 { "loc", dwarf2_directive_loc
, 0 },
543 { "longcall", v850_longcode
, 1 },
544 { "longjump", v850_longcode
, 2 },
548 /* Opcode hash table. */
549 static struct hash_control
*v850_hash
;
551 /* This table is sorted. Suitable for searching by a binary search. */
552 static const struct reg_name pre_defined_registers
[] = {
553 { "ep", 30 }, /* ep - element ptr */
554 { "gp", 4 }, /* gp - global ptr */
555 { "hp", 2 }, /* hp - handler stack ptr */
556 { "lp", 31 }, /* lp - link ptr */
589 { "sp", 3 }, /* sp - stack ptr */
590 { "tp", 5 }, /* tp - text ptr */
594 #define REG_NAME_CNT \
595 (sizeof (pre_defined_registers) / sizeof (struct reg_name))
597 static const struct reg_name system_registers
[] = {
611 #define SYSREG_NAME_CNT \
612 (sizeof (system_registers) / sizeof (struct reg_name))
614 static const struct reg_name system_list_registers
[] = {
619 #define SYSREGLIST_NAME_CNT \
620 (sizeof (system_list_registers) / sizeof (struct reg_name))
622 static const struct reg_name cc_names
[] = {
647 #define CC_NAME_CNT \
648 (sizeof (cc_names) / sizeof (struct reg_name))
650 /* Do a binary search of the given register table to see if NAME is a
651 valid regiter name. Return the register number from the array on
652 success, or -1 on failure. */
654 static int reg_name_search
655 PARAMS ((const struct reg_name
*, int, const char *, bfd_boolean
));
658 reg_name_search (regs
, regcount
, name
, accept_numbers
)
659 const struct reg_name
*regs
;
662 bfd_boolean accept_numbers
;
664 int middle
, low
, high
;
668 /* If the register name is a symbol, then evaluate it. */
669 if ((symbolP
= symbol_find (name
)) != NULL
)
671 /* If the symbol is an alias for another name then use that.
672 If the symbol is an alias for a number, then return the number. */
673 if (symbol_equated_p (symbolP
))
676 = S_GET_NAME (symbol_get_value_expression (symbolP
)->X_add_symbol
);
678 else if (accept_numbers
)
680 int reg
= S_GET_VALUE (symbolP
);
682 if (reg
>= 0 && reg
<= 31)
686 /* Otherwise drop through and try parsing name normally. */
694 middle
= (low
+ high
) / 2;
695 cmp
= strcasecmp (name
, regs
[middle
].name
);
701 return regs
[middle
].value
;
707 /* Summary of register_name().
709 * in: Input_line_pointer points to 1st char of operand.
711 * out: An expressionS.
712 * The operand may have been a register: in this case, X_op == O_register,
713 * X_add_number is set to the register number, and truth is returned.
714 * Input_line_pointer->(next non-blank) char after operand, or is in
715 * its original state. */
717 static bfd_boolean register_name
PARAMS ((expressionS
*));
720 register_name (expressionP
)
721 expressionS
*expressionP
;
728 /* Find the spelling of the operand. */
729 start
= name
= input_line_pointer
;
731 c
= get_symbol_end ();
733 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
,
736 /* Put back the delimiting char. */
737 *input_line_pointer
= c
;
739 /* Look to see if it's in the register table. */
742 expressionP
->X_op
= O_register
;
743 expressionP
->X_add_number
= reg_number
;
745 /* Make the rest nice. */
746 expressionP
->X_add_symbol
= NULL
;
747 expressionP
->X_op_symbol
= NULL
;
753 /* Reset the line as if we had not done anything. */
754 input_line_pointer
= start
;
760 /* Summary of system_register_name().
762 * in: INPUT_LINE_POINTER points to 1st char of operand.
763 * EXPRESSIONP points to an expression structure to be filled in.
764 * ACCEPT_NUMBERS is true iff numerical register names may be used.
765 * ACCEPT_LIST_NAMES is true iff the special names PS and SR may be
768 * out: An expressionS structure in expressionP.
769 * The operand may have been a register: in this case, X_op == O_register,
770 * X_add_number is set to the register number, and truth is returned.
771 * Input_line_pointer->(next non-blank) char after operand, or is in
772 * its original state. */
774 static bfd_boolean system_register_name
775 PARAMS ((expressionS
*, bfd_boolean
, bfd_boolean
));
778 system_register_name (expressionP
, accept_numbers
, accept_list_names
)
779 expressionS
*expressionP
;
780 bfd_boolean accept_numbers
;
781 bfd_boolean accept_list_names
;
788 /* Find the spelling of the operand. */
789 start
= name
= input_line_pointer
;
791 c
= get_symbol_end ();
792 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
,
795 /* Put back the delimiting char. */
796 *input_line_pointer
= c
;
801 /* Reset input_line pointer. */
802 input_line_pointer
= start
;
804 if (ISDIGIT (*input_line_pointer
))
806 reg_number
= strtol (input_line_pointer
, &input_line_pointer
, 10);
808 /* Make sure that the register number is allowable. */
810 || (reg_number
> 5 && reg_number
< 16)
816 else if (accept_list_names
)
818 c
= get_symbol_end ();
819 reg_number
= reg_name_search (system_list_registers
,
820 SYSREGLIST_NAME_CNT
, name
, FALSE
);
822 /* Put back the delimiting char. */
823 *input_line_pointer
= c
;
827 /* Look to see if it's in the register table. */
830 expressionP
->X_op
= O_register
;
831 expressionP
->X_add_number
= reg_number
;
833 /* Make the rest nice. */
834 expressionP
->X_add_symbol
= NULL
;
835 expressionP
->X_op_symbol
= NULL
;
841 /* Reset the line as if we had not done anything. */
842 input_line_pointer
= start
;
848 /* Summary of cc_name().
850 * in: INPUT_LINE_POINTER points to 1st char of operand.
852 * out: An expressionS.
853 * The operand may have been a register: in this case, X_op == O_register,
854 * X_add_number is set to the register number, and truth is returned.
855 * Input_line_pointer->(next non-blank) char after operand, or is in
856 * its original state. */
858 static bfd_boolean cc_name
PARAMS ((expressionS
*));
861 cc_name (expressionP
)
862 expressionS
*expressionP
;
869 /* Find the spelling of the operand. */
870 start
= name
= input_line_pointer
;
872 c
= get_symbol_end ();
873 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
, FALSE
);
875 /* Put back the delimiting char. */
876 *input_line_pointer
= c
;
878 /* Look to see if it's in the register table. */
881 expressionP
->X_op
= O_constant
;
882 expressionP
->X_add_number
= reg_number
;
884 /* Make the rest nice. */
885 expressionP
->X_add_symbol
= NULL
;
886 expressionP
->X_op_symbol
= NULL
;
892 /* Reset the line as if we had not done anything. */
893 input_line_pointer
= start
;
899 static void skip_white_space
PARAMS ((void));
904 while (*input_line_pointer
== ' '
905 || *input_line_pointer
== '\t')
906 ++input_line_pointer
;
909 /* Summary of parse_register_list ().
911 * in: INPUT_LINE_POINTER points to 1st char of a list of registers.
912 * INSN is the partially constructed instruction.
913 * OPERAND is the operand being inserted.
915 * out: NULL if the parse completed successfully, otherwise a
916 * pointer to an error message is returned. If the parse
917 * completes the correct bit fields in the instruction
920 * Parses register lists with the syntax:
928 * and also parses constant epxressions whoes bits indicate the
929 * registers in the lists. The LSB in the expression refers to
930 * the lowest numbered permissable register in the register list,
931 * and so on upwards. System registers are considered to be very
934 static char *parse_register_list
935 PARAMS ((unsigned long *, const struct v850_operand
*));
938 parse_register_list (insn
, operand
)
940 const struct v850_operand
*operand
;
942 static int type1_regs
[32] = {
943 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
944 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
946 static int type2_regs
[32] = {
947 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
948 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
950 static int type3_regs
[32] = {
951 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
952 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8
957 /* Select a register array to parse. */
958 switch (operand
->shift
)
960 case 0xffe00001: regs
= type1_regs
; break;
961 case 0xfff8000f: regs
= type2_regs
; break;
962 case 0xfff8001f: regs
= type3_regs
; break;
964 as_bad (_("unknown operand shift: %x\n"), operand
->shift
);
965 return _("internal failure in parse_register_list");
970 /* If the expression starts with a curly brace it is a register list.
971 Otherwise it is a constant expression, whoes bits indicate which
972 registers are to be included in the list. */
974 if (*input_line_pointer
!= '{')
981 if (exp
.X_op
!= O_constant
)
982 return _("constant expression or register list expected");
984 if (regs
== type1_regs
)
986 if (exp
.X_add_number
& 0xFFFFF000)
987 return _("high bits set in register list expression");
989 for (reg
= 20; reg
< 32; reg
++)
990 if (exp
.X_add_number
& (1 << (reg
- 20)))
992 for (i
= 0; i
< 32; i
++)
997 else if (regs
== type2_regs
)
999 if (exp
.X_add_number
& 0xFFFE0000)
1000 return _("high bits set in register list expression");
1002 for (reg
= 1; reg
< 16; reg
++)
1003 if (exp
.X_add_number
& (1 << (reg
- 1)))
1005 for (i
= 0; i
< 32; i
++)
1010 if (exp
.X_add_number
& (1 << 15))
1013 if (exp
.X_add_number
& (1 << 16))
1016 else /* regs == type3_regs */
1018 if (exp
.X_add_number
& 0xFFFE0000)
1019 return _("high bits set in register list expression");
1021 for (reg
= 16; reg
< 32; reg
++)
1022 if (exp
.X_add_number
& (1 << (reg
- 16)))
1024 for (i
= 0; i
< 32; i
++)
1029 if (exp
.X_add_number
& (1 << 16))
1036 input_line_pointer
++;
1038 /* Parse the register list until a terminator (closing curly brace or
1039 new-line) is found. */
1042 if (register_name (&exp
))
1046 /* Locate the given register in the list, and if it is there,
1047 insert the corresponding bit into the instruction. */
1048 for (i
= 0; i
< 32; i
++)
1050 if (regs
[i
] == exp
.X_add_number
)
1059 return _("illegal register included in list");
1062 else if (system_register_name (&exp
, TRUE
, TRUE
))
1064 if (regs
== type1_regs
)
1066 return _("system registers cannot be included in list");
1068 else if (exp
.X_add_number
== 5)
1070 if (regs
== type2_regs
)
1071 return _("PSW cannot be included in list");
1075 else if (exp
.X_add_number
< 4)
1078 return _("High value system registers cannot be included in list");
1080 else if (*input_line_pointer
== '}')
1082 input_line_pointer
++;
1085 else if (*input_line_pointer
== ',')
1087 input_line_pointer
++;
1090 else if (*input_line_pointer
== '-')
1092 /* We have encountered a range of registers: rX - rY. */
1096 /* Skip the dash. */
1097 ++input_line_pointer
;
1099 /* Get the second register in the range. */
1100 if (! register_name (&exp2
))
1102 return _("second register should follow dash in register list");
1103 exp2
.X_add_number
= exp
.X_add_number
;
1106 /* Add the rest of the registers in the range. */
1107 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1111 /* Locate the given register in the list, and if it is there,
1112 insert the corresponding bit into the instruction. */
1113 for (i
= 0; i
< 32; i
++)
1123 return _("illegal register included in list");
1131 skip_white_space ();
1137 const char *md_shortopts
= "m:";
1139 struct option md_longopts
[] = {
1140 {NULL
, no_argument
, NULL
, 0}
1143 size_t md_longopts_size
= sizeof (md_longopts
);
1146 md_show_usage (stream
)
1149 fprintf (stream
, _(" V850 options:\n"));
1150 fprintf (stream
, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1151 fprintf (stream
, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1152 fprintf (stream
, _(" -mv850 The code is targeted at the v850\n"));
1153 fprintf (stream
, _(" -mv850e The code is targeted at the v850e\n"));
1154 fprintf (stream
, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1155 fprintf (stream
, _(" -mrelax Enable relaxation\n"));
1160 md_parse_option (c
, arg
)
1167 /* xgettext:c-format */
1168 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1172 if (strcmp (arg
, "warn-signed-overflow") == 0)
1174 warn_signed_overflows
= TRUE
;
1176 else if (strcmp (arg
, "warn-unsigned-overflow") == 0)
1178 warn_unsigned_overflows
= TRUE
;
1180 else if (strcmp (arg
, "v850") == 0)
1183 processor_mask
= PROCESSOR_V850
;
1185 else if (strcmp (arg
, "v850e") == 0)
1187 machine
= bfd_mach_v850e
;
1188 processor_mask
= PROCESSOR_V850E
;
1190 else if (strcmp (arg
, "v850any") == 0)
1192 /* Tell the world that this is for any v850 chip. */
1195 /* But support instructions for the extended versions. */
1196 processor_mask
= PROCESSOR_V850E
;
1198 else if (strcmp (arg
, "relax") == 0)
1202 /* xgettext:c-format */
1203 fprintf (stderr
, _("unknown command line option: -%c%s\n"), c
, arg
);
1211 md_undefined_symbol (name
)
1212 char *name ATTRIBUTE_UNUSED
;
1218 md_atof (type
, litp
, sizep
)
1224 LITTLENUM_TYPE words
[4];
1240 return _("bad call to md_atof");
1243 t
= atof_ieee (input_line_pointer
, type
, words
);
1245 input_line_pointer
= t
;
1249 for (i
= prec
- 1; i
>= 0; i
--)
1251 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1261 md_convert_frag (abfd
, sec
, fragP
)
1262 bfd
*abfd ATTRIBUTE_UNUSED
;
1266 subseg_change (sec
, 0);
1268 /* In range conditional or unconditional branch. */
1269 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1271 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1272 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1275 /* Out of range conditional branch. Emit a branch around a jump. */
1276 else if (fragP
->fr_subtype
== 1)
1278 unsigned char *buffer
=
1279 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1281 /* Reverse the condition of the first branch. */
1283 /* Mask off all the displacement bits. */
1286 /* Now set the displacement bits so that we branch
1287 around the unconditional branch. */
1290 /* Now create the unconditional branch + fixup to the final
1292 md_number_to_chars (buffer
+ 2, 0x00000780, 4);
1293 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1294 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1295 (int) fragP
->fr_opcode
+ 1);
1298 /* Out of range unconditional branch. Emit a jump. */
1299 else if (fragP
->fr_subtype
== 3)
1301 md_number_to_chars (fragP
->fr_fix
+ fragP
->fr_literal
, 0x00000780, 4);
1302 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
1303 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1304 (int) fragP
->fr_opcode
+ 1);
1312 md_section_align (seg
, addr
)
1316 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1317 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1323 char *prev_name
= "";
1324 const struct v850_opcode
*op
;
1326 if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1329 machine
= bfd_mach_v850e
;
1331 if (processor_mask
== -1)
1332 processor_mask
= PROCESSOR_V850E
;
1334 else if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1339 if (processor_mask
== -1)
1340 processor_mask
= PROCESSOR_V850
;
1343 /* xgettext:c-format */
1344 as_bad (_("Unable to determine default target processor from string: %s"),
1347 v850_hash
= hash_new ();
1349 /* Insert unique names into hash table. The V850 instruction set
1350 has many identical opcode names that have different opcodes based
1351 on the operands. This hash table then provides a quick index to
1352 the first opcode with a particular name in the opcode table. */
1357 if (strcmp (prev_name
, op
->name
))
1359 prev_name
= (char *) op
->name
;
1360 hash_insert (v850_hash
, op
->name
, (char *) op
);
1365 v850_seg_table
[BSS_SECTION
].s
= bss_section
;
1366 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1369 static bfd_reloc_code_real_type handle_ctoff
1370 PARAMS ((const struct v850_operand
*));
1372 static bfd_reloc_code_real_type
1373 handle_ctoff (operand
)
1374 const struct v850_operand
*operand
;
1376 if (operand
== NULL
)
1377 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1379 if (operand
->bits
!= 6
1380 || operand
->shift
!= 0)
1382 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1383 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1386 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1389 static bfd_reloc_code_real_type handle_sdaoff
1390 PARAMS ((const struct v850_operand
*));
1392 static bfd_reloc_code_real_type
1393 handle_sdaoff (operand
)
1394 const struct v850_operand
*operand
;
1396 if (operand
== NULL
)
1397 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1399 if (operand
->bits
== 15 && operand
->shift
== 17)
1400 return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1402 if (operand
->bits
== -1)
1403 return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1405 if (operand
->bits
!= 16
1406 || operand
->shift
!= 16)
1408 as_bad (_("sdaoff() relocation used on an instruction which does not support it"));
1409 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1412 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1415 static bfd_reloc_code_real_type handle_zdaoff
1416 PARAMS ((const struct v850_operand
*));
1418 static bfd_reloc_code_real_type
1419 handle_zdaoff (operand
)
1420 const struct v850_operand
*operand
;
1422 if (operand
== NULL
)
1423 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1425 if (operand
->bits
== 15 && operand
->shift
== 17)
1426 return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1428 if (operand
->bits
== -1)
1429 return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1431 if (operand
->bits
!= 16
1432 || operand
->shift
!= 16)
1434 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1435 /* Used to indicate an error condition. */
1436 return BFD_RELOC_64
;
1439 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1442 static bfd_reloc_code_real_type handle_tdaoff
1443 PARAMS ((const struct v850_operand
*));
1445 static bfd_reloc_code_real_type
1446 handle_tdaoff (operand
)
1447 const struct v850_operand
*operand
;
1449 if (operand
== NULL
)
1450 /* Data item, not an instruction. */
1451 return BFD_RELOC_V850_TDA_7_7_OFFSET
;
1453 if (operand
->bits
== 6 && operand
->shift
== 1)
1454 /* sld.w/sst.w, operand: D8_6 */
1455 return BFD_RELOC_V850_TDA_6_8_OFFSET
;
1457 if (operand
->bits
== 4 && operand
->insert
!= NULL
)
1458 /* sld.hu, operand: D5-4 */
1459 return BFD_RELOC_V850_TDA_4_5_OFFSET
;
1461 if (operand
->bits
== 4 && operand
->insert
== NULL
)
1462 /* sld.bu, operand: D4 */
1463 return BFD_RELOC_V850_TDA_4_4_OFFSET
;
1465 if (operand
->bits
== 16 && operand
->shift
== 16)
1466 /* set1 & chums, operands: D16 */
1467 return BFD_RELOC_V850_TDA_16_16_OFFSET
;
1469 if (operand
->bits
!= 7)
1471 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1472 /* Used to indicate an error condition. */
1473 return BFD_RELOC_64
;
1476 return operand
->insert
!= NULL
1477 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1478 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1481 /* Warning: The code in this function relies upon the definitions
1482 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1483 matching the hard coded values contained herein. */
1485 static bfd_reloc_code_real_type v850_reloc_prefix
1486 PARAMS ((const struct v850_operand
*));
1488 static bfd_reloc_code_real_type
1489 v850_reloc_prefix (operand
)
1490 const struct v850_operand
*operand
;
1492 bfd_boolean paren_skipped
= FALSE
;
1494 /* Skip leading opening parenthesis. */
1495 if (*input_line_pointer
== '(')
1497 ++input_line_pointer
;
1498 paren_skipped
= TRUE
;
1501 #define CHECK_(name, reloc) \
1502 if (strncmp (input_line_pointer, name "(", strlen (name) + 1) == 0) \
1504 input_line_pointer += strlen (name); \
1508 CHECK_ ("hi0", BFD_RELOC_HI16
);
1509 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1510 CHECK_ ("lo", BFD_RELOC_LO16
);
1511 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1512 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1513 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1514 CHECK_ ("hilo", BFD_RELOC_32
);
1515 CHECK_ ("ctoff", handle_ctoff (operand
) );
1517 /* Restore skipped parenthesis. */
1519 --input_line_pointer
;
1521 return BFD_RELOC_UNUSED
;
1524 /* Insert an operand value into an instruction. */
1526 static unsigned long v850_insert_operand
1527 PARAMS ((unsigned long, const struct v850_operand
*, offsetT
, char *,
1528 unsigned int, char *));
1530 static unsigned long
1531 v850_insert_operand (insn
, operand
, val
, file
, line
, str
)
1533 const struct v850_operand
*operand
;
1539 if (operand
->insert
)
1541 const char *message
= NULL
;
1543 insn
= operand
->insert (insn
, val
, &message
);
1544 if (message
!= NULL
)
1546 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1547 && ! warn_signed_overflows
1548 && strstr (message
, "out of range") != NULL
)
1550 /* Skip warning... */
1552 else if ((operand
->flags
& V850_OPERAND_SIGNED
) == 0
1553 && ! warn_unsigned_overflows
1554 && strstr (message
, "out of range") != NULL
)
1556 /* Skip warning... */
1560 if (file
== (char *) NULL
)
1561 as_warn ("%s: %s", str
, message
);
1563 as_warn_where (file
, line
, "%s: %s", str
, message
);
1567 if (file
== (char *) NULL
)
1570 as_warn_where (file
, line
, message
);
1576 if (operand
->bits
!= 32)
1580 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1582 if (! warn_signed_overflows
)
1583 max
= (1 << operand
->bits
) - 1;
1585 max
= (1 << (operand
->bits
- 1)) - 1;
1587 min
= -(1 << (operand
->bits
- 1));
1591 max
= (1 << operand
->bits
) - 1;
1593 if (! warn_unsigned_overflows
)
1594 min
= -(1 << (operand
->bits
- 1));
1599 if (val
< (offsetT
) min
|| val
> (offsetT
) max
)
1601 /* xgettext:c-format */
1603 _("operand out of range (%s not between %ld and %ld)");
1606 /* Restore min and mix to expected values for decimal ranges. */
1607 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1608 && ! warn_signed_overflows
)
1609 max
= (1 << (operand
->bits
- 1)) - 1;
1611 if (! (operand
->flags
& V850_OPERAND_SIGNED
)
1612 && ! warn_unsigned_overflows
)
1617 sprintf (buf
, "%s: ", str
);
1619 sprint_value (buf
+ strlen (buf
), val
);
1622 sprint_value (buf
, val
);
1624 if (file
== (char *) NULL
)
1625 as_warn (err
, buf
, min
, max
);
1627 as_warn_where (file
, line
, err
, buf
, min
, max
);
1631 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1637 static char copy_of_instruction
[128];
1644 char *start_of_operands
;
1645 struct v850_opcode
*opcode
;
1646 struct v850_opcode
*next_opcode
;
1647 const unsigned char *opindex_ptr
;
1651 unsigned long insn_size
;
1655 bfd_boolean extra_data_after_insn
= FALSE
;
1656 unsigned extra_data_len
= 0;
1657 unsigned long extra_data
= 0;
1658 char *saved_input_line_pointer
;
1660 strncpy (copy_of_instruction
, str
, sizeof (copy_of_instruction
) - 1);
1662 /* Get the opcode. */
1663 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1669 /* Find the first opcode with the proper name. */
1670 opcode
= (struct v850_opcode
*) hash_find (v850_hash
, str
);
1673 /* xgettext:c-format */
1674 as_bad (_("Unrecognized opcode: `%s'"), str
);
1675 ignore_rest_of_line ();
1680 while (ISSPACE (*str
))
1683 start_of_operands
= str
;
1685 saved_input_line_pointer
= input_line_pointer
;
1689 const char *errmsg
= NULL
;
1693 if ((opcode
->processors
& processor_mask
) == 0)
1695 errmsg
= _("Target processor does not support this instruction.");
1702 insn
= opcode
->opcode
;
1703 extra_data_after_insn
= FALSE
;
1705 input_line_pointer
= str
= start_of_operands
;
1707 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1709 const struct v850_operand
*operand
;
1712 bfd_reloc_code_real_type reloc
;
1714 if (next_opindex
== 0)
1716 operand
= &v850_operands
[*opindex_ptr
];
1720 operand
= &v850_operands
[next_opindex
];
1726 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1729 if (operand
->flags
& V850_OPERAND_RELAX
)
1732 /* Gather the operand. */
1733 hold
= input_line_pointer
;
1734 input_line_pointer
= str
;
1736 /* lo(), hi(), hi0(), etc... */
1737 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1739 /* This is a fake reloc, used to indicate an error condition. */
1740 if (reloc
== BFD_RELOC_64
)
1748 if (ex
.X_op
== O_constant
)
1752 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1753 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1757 case BFD_RELOC_LO16
:
1759 /* Truncate, then sign extend the value. */
1760 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1764 case BFD_RELOC_HI16
:
1766 /* Truncate, then sign extend the value. */
1767 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1771 case BFD_RELOC_HI16_S
:
1773 /* Truncate, then sign extend the value. */
1774 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1776 temp
+= (ex
.X_add_number
>> 15) & 1;
1778 ex
.X_add_number
= SEXT16 (temp
);
1783 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1785 errmsg
= _("immediate operand is too large");
1789 extra_data_after_insn
= TRUE
;
1795 fprintf (stderr
, "reloc: %d\n", reloc
);
1796 as_bad (_("AAARG -> unhandled constant reloc"));
1800 if (fc
> MAX_INSN_FIXUPS
)
1801 as_fatal (_("too many fixups"));
1803 fixups
[fc
].exp
= ex
;
1804 fixups
[fc
].opindex
= *opindex_ptr
;
1805 fixups
[fc
].reloc
= reloc
;
1810 if (reloc
== BFD_RELOC_32
)
1812 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1814 errmsg
= _("immediate operand is too large");
1818 extra_data_after_insn
= TRUE
;
1820 extra_data
= ex
.X_add_number
;
1823 if (fc
> MAX_INSN_FIXUPS
)
1824 as_fatal (_("too many fixups"));
1826 fixups
[fc
].exp
= ex
;
1827 fixups
[fc
].opindex
= *opindex_ptr
;
1828 fixups
[fc
].reloc
= reloc
;
1836 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1838 if (!register_name (&ex
))
1840 errmsg
= _("invalid register name");
1842 else if ((operand
->flags
& V850_NOT_R0
)
1843 && ex
.X_add_number
== 0)
1845 errmsg
= _("register r0 cannot be used here");
1847 /* Force an error message to be generated by
1848 skipping over any following potential matches
1853 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1855 if (!system_register_name (&ex
, TRUE
, FALSE
))
1857 errmsg
= _("invalid system register name");
1860 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1862 char *start
= input_line_pointer
;
1863 char c
= get_symbol_end ();
1865 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1867 /* Put things back the way we found them. */
1868 *input_line_pointer
= c
;
1869 input_line_pointer
= start
;
1870 errmsg
= _("expected EP register");
1874 *input_line_pointer
= c
;
1875 str
= input_line_pointer
;
1876 input_line_pointer
= hold
;
1878 while (*str
== ' ' || *str
== ','
1879 || *str
== '[' || *str
== ']')
1883 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1887 errmsg
= _("invalid condition code name");
1890 else if (operand
->flags
& V850E_PUSH_POP
)
1892 errmsg
= parse_register_list (&insn
, operand
);
1894 /* The parse_register_list() function has already done
1895 everything, so fake a dummy expression. */
1896 ex
.X_op
= O_constant
;
1897 ex
.X_add_number
= 0;
1899 else if (operand
->flags
& V850E_IMMEDIATE16
)
1903 if (ex
.X_op
!= O_constant
)
1904 errmsg
= _("constant expression expected");
1905 else if (ex
.X_add_number
& 0xffff0000)
1907 if (ex
.X_add_number
& 0xffff)
1908 errmsg
= _("constant too big to fit into instruction");
1909 else if ((insn
& 0x001fffc0) == 0x00130780)
1910 ex
.X_add_number
>>= 16;
1912 errmsg
= _("constant too big to fit into instruction");
1915 extra_data_after_insn
= TRUE
;
1917 extra_data
= ex
.X_add_number
;
1918 ex
.X_add_number
= 0;
1920 else if (operand
->flags
& V850E_IMMEDIATE32
)
1924 if (ex
.X_op
!= O_constant
)
1925 errmsg
= _("constant expression expected");
1927 extra_data_after_insn
= TRUE
;
1929 extra_data
= ex
.X_add_number
;
1930 ex
.X_add_number
= 0;
1932 else if (register_name (&ex
)
1933 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1938 /* It is possible that an alias has been defined that
1939 matches a register name. For example the code may
1940 include a ".set ZERO, 0" directive, which matches
1941 the register name "zero". Attempt to reparse the
1942 field as an expression, and only complain if we
1943 cannot generate a constant. */
1945 input_line_pointer
= str
;
1947 c
= get_symbol_end ();
1949 if (symbol_find (str
) != NULL
)
1952 *input_line_pointer
= c
;
1953 input_line_pointer
= str
;
1957 if (ex
.X_op
!= O_constant
)
1959 /* If this register is actually occuring too early on
1960 the parsing of the instruction, (because another
1961 field is missing) then report this. */
1962 if (opindex_ptr
[1] != 0
1963 && (v850_operands
[opindex_ptr
[1]].flags
1964 & V850_OPERAND_REG
))
1965 errmsg
= _("syntax error: value is missing before the register name");
1967 errmsg
= _("syntax error: register not expected");
1969 /* If we created a symbol in the process of this
1970 test then delete it now, so that it will not
1971 be output with the real symbols... */
1973 && ex
.X_op
== O_symbol
)
1974 symbol_remove (ex
.X_add_symbol
,
1975 &symbol_rootP
, &symbol_lastP
);
1978 else if (system_register_name (&ex
, FALSE
, FALSE
)
1979 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1981 errmsg
= _("syntax error: system register not expected");
1983 else if (cc_name (&ex
)
1984 && (operand
->flags
& V850_OPERAND_CC
) == 0)
1986 errmsg
= _("syntax error: condition code not expected");
1992 If we are assembling a MOV instruction and the immediate
1993 value does not fit into the bits available then create a
1994 fake error so that the next MOV instruction will be
1995 selected. This one has a 32 bit immediate field. */
1997 if (((insn
& 0x07e0) == 0x0200)
1998 && operand
->bits
== 5 /* Do not match the CALLT instruction. */
1999 && ex
.X_op
== O_constant
2000 && (ex
.X_add_number
< (-(1 << (operand
->bits
- 1)))
2001 || ex
.X_add_number
> ((1 << (operand
->bits
- 1)) - 1)))
2002 errmsg
= _("immediate operand is too large");
2010 " insn: %x, operand %d, op: %d, add_number: %d\n",
2011 insn
, opindex_ptr
- opcode
->operands
,
2012 ex
.X_op
, ex
.X_add_number
);
2018 errmsg
= _("illegal operand");
2021 errmsg
= _("missing operand");
2025 & (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
2027 errmsg
= _("invalid operand");
2030 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2032 copy_of_instruction
);
2036 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
2038 copy_of_instruction
);
2042 /* We need to generate a fixup for this expression. */
2043 if (fc
>= MAX_INSN_FIXUPS
)
2044 as_fatal (_("too many fixups"));
2046 fixups
[fc
].exp
= ex
;
2047 fixups
[fc
].opindex
= *opindex_ptr
;
2048 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2054 str
= input_line_pointer
;
2055 input_line_pointer
= hold
;
2057 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
2066 next_opcode
= opcode
+ 1;
2067 if (next_opcode
->name
!= NULL
2068 && strcmp (next_opcode
->name
, opcode
->name
) == 0)
2070 opcode
= next_opcode
;
2072 /* Skip versions that are not supported by the target
2074 if ((opcode
->processors
& processor_mask
) == 0)
2080 as_bad ("%s: %s", copy_of_instruction
, errmsg
);
2082 if (*input_line_pointer
== ']')
2083 ++input_line_pointer
;
2085 ignore_rest_of_line ();
2086 input_line_pointer
= saved_input_line_pointer
;
2092 while (ISSPACE (*str
))
2096 /* xgettext:c-format */
2097 as_bad (_("junk at end of line: `%s'"), str
);
2099 input_line_pointer
= str
;
2101 /* Tie dwarf2 debug info to the address at the start of the insn.
2102 We can't do this after the insn has been output as the current
2103 frag may have been closed off. eg. by frag_var. */
2104 dwarf2_emit_insn (0);
2106 /* Write out the instruction. */
2108 if (relaxable
&& fc
> 0)
2113 if (!strcmp (opcode
->name
, "br"))
2115 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
2116 fixups
[0].exp
.X_add_symbol
,
2117 fixups
[0].exp
.X_add_number
,
2118 (char *) fixups
[0].opindex
);
2119 md_number_to_chars (f
, insn
, insn_size
);
2120 md_number_to_chars (f
+ 2, 0, 2);
2124 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
2125 fixups
[0].exp
.X_add_symbol
,
2126 fixups
[0].exp
.X_add_number
,
2127 (char *) fixups
[0].opindex
);
2128 md_number_to_chars (f
, insn
, insn_size
);
2129 md_number_to_chars (f
+ 2, 0, 4);
2134 /* Four byte insns have an opcode with the two high bits on. */
2135 if ((insn
& 0x0600) == 0x0600)
2140 /* Special case: 32 bit MOV. */
2141 if ((insn
& 0xffe0) == 0x0620)
2144 f
= frag_more (insn_size
);
2145 md_number_to_chars (f
, insn
, insn_size
);
2147 if (extra_data_after_insn
)
2149 f
= frag_more (extra_data_len
);
2150 md_number_to_chars (f
, extra_data
, extra_data_len
);
2152 extra_data_after_insn
= FALSE
;
2156 /* Create any fixups. At this point we do not use a
2157 bfd_reloc_code_real_type, but instead just use the
2158 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2159 handle fixups for any operand type, although that is admittedly
2160 not a very exciting feature. We pick a BFD reloc type in
2162 for (i
= 0; i
< fc
; i
++)
2164 const struct v850_operand
*operand
;
2165 bfd_reloc_code_real_type reloc
;
2167 operand
= &v850_operands
[fixups
[i
].opindex
];
2169 reloc
= fixups
[i
].reloc
;
2171 if (reloc
!= BFD_RELOC_UNUSED
)
2173 reloc_howto_type
*reloc_howto
=
2174 bfd_reloc_type_lookup (stdoutput
, reloc
);
2182 size
= bfd_get_reloc_size (reloc_howto
);
2184 /* XXX This will abort on an R_V850_8 reloc -
2185 is this reloc actually used? */
2186 if (size
!= 2 && size
!= 4)
2189 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
2191 if (reloc
== BFD_RELOC_32
)
2194 fixP
= fix_new_exp (frag_now
, address
, size
,
2196 reloc_howto
->pc_relative
,
2201 case BFD_RELOC_LO16
:
2202 case BFD_RELOC_HI16
:
2203 case BFD_RELOC_HI16_S
:
2204 fixP
->fx_no_overflow
= 1;
2212 fix_new_exp (frag_now
,
2213 f
- frag_now
->fr_literal
, 4,
2215 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
2216 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
2217 + (int) BFD_RELOC_UNUSED
));
2221 input_line_pointer
= saved_input_line_pointer
;
2224 /* If while processing a fixup, a reloc really needs to be created
2225 then it is done here. */
2228 tc_gen_reloc (seg
, fixp
)
2229 asection
*seg ATTRIBUTE_UNUSED
;
2234 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2235 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2236 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2237 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2238 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2240 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2242 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2243 /* xgettext:c-format */
2244 _("reloc %d not supported by object file format"),
2245 (int) fixp
->fx_r_type
);
2252 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2253 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
)
2254 reloc
->addend
= fixp
->fx_offset
;
2255 else if ( fixp
->fx_r_type
== BFD_RELOC_V850_LONGCALL
2256 || fixp
->fx_r_type
== BFD_RELOC_V850_LONGJUMP
2257 || fixp
->fx_r_type
== BFD_RELOC_V850_ALIGN
)
2258 reloc
->addend
= fixp
->fx_offset
;
2260 reloc
->addend
= fixp
->fx_addnumber
;
2266 v850_handle_align (frag
)
2270 && frag
->fr_type
== rs_align
2271 && frag
->fr_address
+ frag
->fr_fix
> 0
2272 && frag
->fr_offset
> 1
2273 && now_seg
!= bss_section
2274 && now_seg
!= v850_seg_table
[SBSS_SECTION
].s
2275 && now_seg
!= v850_seg_table
[TBSS_SECTION
].s
2276 && now_seg
!= v850_seg_table
[ZBSS_SECTION
].s
)
2277 fix_new (frag
, frag
->fr_fix
, 2, & abs_symbol
, frag
->fr_offset
, 0,
2278 BFD_RELOC_V850_ALIGN
);
2281 /* Return current size of variable part of frag. */
2284 md_estimate_size_before_relax (fragp
, seg
)
2286 asection
*seg ATTRIBUTE_UNUSED
;
2288 if (fragp
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
2291 return md_relax_table
[fragp
->fr_subtype
].rlx_length
;
2295 v850_pcrel_from_section (fixp
, section
)
2299 /* If the symbol is undefined, or in a section other than our own,
2300 or it is weak (in which case it may well be in another section,
2301 then let the linker figure it out. */
2302 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2303 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2304 || S_IS_WEAK (fixp
->fx_addsy
)
2305 || (S_GET_SEGMENT (fixp
->fx_addsy
) != section
)))
2308 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2312 md_apply_fix3 (fixP
, valueP
, seg
)
2315 segT seg ATTRIBUTE_UNUSED
;
2317 valueT value
= * valueP
;
2320 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2321 || fixP
->fx_r_type
== BFD_RELOC_V850_LONGCALL
2322 || fixP
->fx_r_type
== BFD_RELOC_V850_LONGJUMP
2323 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2329 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
2330 fixP
->fx_addnumber
= value
,
2333 else if (fixP
->fx_pcrel
)
2334 fixP
->fx_addnumber
= fixP
->fx_offset
;
2338 value
= fixP
->fx_offset
;
2339 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
2341 if (S_GET_SEGMENT (fixP
->fx_subsy
) == absolute_section
)
2342 value
-= S_GET_VALUE (fixP
->fx_subsy
);
2345 /* We don't actually support subtracting a symbol. */
2346 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2347 _("expression too complex"));
2350 fixP
->fx_addnumber
= value
;
2353 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2356 const struct v850_operand
*operand
;
2359 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2360 operand
= &v850_operands
[opindex
];
2362 /* Fetch the instruction, insert the fully resolved operand
2363 value, and stuff the instruction back again.
2365 Note the instruction has been stored in little endian
2367 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2369 insn
= bfd_getl32 ((unsigned char *) where
);
2370 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2371 fixP
->fx_file
, fixP
->fx_line
, NULL
);
2372 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2375 /* Nothing else to do here. */
2378 /* Determine a BFD reloc value based on the operand information.
2379 We are only prepared to turn a few of the operands into relocs. */
2381 if (operand
->bits
== 22)
2382 fixP
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2383 else if (operand
->bits
== 9)
2384 fixP
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2388 fprintf (stderr
, "bits: %d, insn: %x\n", operand
->bits
, insn
);
2391 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2392 _("unresolved expression that must be resolved"));
2397 else if (fixP
->fx_done
)
2399 /* We still have to insert the value into memory! */
2400 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2402 if (fixP
->fx_size
== 1)
2403 *where
= value
& 0xff;
2404 else if (fixP
->fx_size
== 2)
2405 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2406 else if (fixP
->fx_size
== 4)
2407 bfd_putl32 (value
, (unsigned char *) where
);
2411 /* Parse a cons expression. We have to handle hi(), lo(), etc
2415 parse_cons_expression_v850 (exp
)
2418 /* See if there's a reloc prefix like hi() we have to handle. */
2419 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2421 /* Do normal expression parsing. */
2425 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2426 found a reloc prefix, then we use that reloc, else we choose an
2427 appropriate one based on the size of the expression. */
2430 cons_fix_new_v850 (frag
, where
, size
, exp
)
2436 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2439 hold_cons_reloc
= BFD_RELOC_32
;
2441 hold_cons_reloc
= BFD_RELOC_16
;
2443 hold_cons_reloc
= BFD_RELOC_8
;
2447 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2449 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);
2451 hold_cons_reloc
= BFD_RELOC_UNUSED
;
2455 v850_fix_adjustable (fixP
)
2458 if (fixP
->fx_addsy
== NULL
)
2461 /* Don't adjust function names. */
2462 if (S_IS_FUNCTION (fixP
->fx_addsy
))
2465 /* We need the symbol name for the VTABLE entries. */
2466 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2467 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2474 v850_force_relocation (fixP
)
2477 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2478 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2481 if (fixP
->fx_r_type
== BFD_RELOC_V850_LONGCALL
2482 || fixP
->fx_r_type
== BFD_RELOC_V850_LONGJUMP
)
2487 || fixP
->fx_r_type
== BFD_RELOC_V850_ALIGN
2488 || fixP
->fx_r_type
== BFD_RELOC_V850_22_PCREL
2489 || fixP
->fx_r_type
== BFD_RELOC_V850_9_PCREL
2490 || fixP
->fx_r_type
>= BFD_RELOC_UNUSED
))
2493 return S_FORCE_RELOC (fixP
->fx_addsy
);