1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, 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. */
52 /* Generic assembler global variables which must be defined by all
55 /* Characters which always start a comment. */
56 const char comment_chars
[] = "#";
58 /* Characters which start a comment at the beginning of a line. */
59 const char line_comment_chars
[] = ";#";
61 /* Characters which may be used to separate multiple commands on a
63 const char line_separator_chars
[] = ";";
65 /* Characters which are used to indicate an exponent in a floating
67 const char EXP_CHARS
[] = "eE";
69 /* Characters which mean that a number is a floating point constant,
71 const char FLT_CHARS
[] = "dD";
73 const relax_typeS md_relax_table
[] =
75 /* Conditional branches. */
77 {0x1fffff, -0x200000, 6, 0},
78 /* Unconditional branches. */
80 {0x1fffff, -0x200000, 4, 0},
83 static int v850_relax
= 0;
86 #define MAX_INSN_FIXUPS 5
92 bfd_reloc_code_real_type reloc
;
95 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
105 struct v850_seg_entry v850_seg_table
[] =
108 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
111 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
},
113 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
},
115 SEC_ALLOC
| SEC_SMALL_DATA
},
121 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
| SEC_DATA
122 | SEC_HAS_CONTENTS
| SEC_SMALL_DATA
},
124 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
| SEC_DATA
125 | SEC_HAS_CONTENTS
},
127 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
128 | SEC_SMALL_DATA
| SEC_IS_COMMON
},
130 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
133 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
135 { NULL
, ".call_table_data",
136 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
},
137 { NULL
, ".call_table_text",
138 SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
| SEC_CODE
144 #define SDATA_SECTION 0
145 #define TDATA_SECTION 1
146 #define ZDATA_SECTION 2
147 #define SBSS_SECTION 3
148 #define TBSS_SECTION 4
149 #define ZBSS_SECTION 5
150 #define ROSDATA_SECTION 6
151 #define ROZDATA_SECTION 7
152 #define SCOMMON_SECTION 8
153 #define TCOMMON_SECTION 9
154 #define ZCOMMON_SECTION 10
155 #define CALL_TABLE_DATA_SECTION 11
156 #define CALL_TABLE_TEXT_SECTION 12
157 #define BSS_SECTION 13
160 do_v850_seg (int i
, subsegT sub
)
162 struct v850_seg_entry
*seg
= v850_seg_table
+ i
;
164 obj_elf_section_change_hook ();
167 subseg_set (seg
->s
, sub
);
170 seg
->s
= subseg_new (seg
->name
, sub
);
171 bfd_set_section_flags (stdoutput
, seg
->s
, seg
->flags
);
172 if ((seg
->flags
& SEC_LOAD
) == 0)
173 seg_info (seg
->s
)->bss
= 1;
180 subsegT sub
= get_absolute_expression ();
182 do_v850_seg (i
, sub
);
183 demand_empty_rest_of_line ();
187 v850_offset (int ignore ATTRIBUTE_UNUSED
)
190 int temp
= get_absolute_expression ();
192 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
)0, (symbolS
*)0,
193 (offsetT
) temp
, (char *) 0);
196 demand_empty_rest_of_line ();
199 /* Copied from obj_elf_common() in gas/config/obj-elf.c. */
212 name
= input_line_pointer
;
213 c
= get_symbol_end ();
215 /* Just after name is now '\0'. */
216 p
= input_line_pointer
;
221 if (*input_line_pointer
!= ',')
223 as_bad (_("Expected comma after symbol-name"));
224 ignore_rest_of_line ();
229 input_line_pointer
++;
231 if ((temp
= get_absolute_expression ()) < 0)
233 /* xgettext:c-format */
234 as_bad (_(".COMMon length (%d.) < 0! Ignored."), temp
);
235 ignore_rest_of_line ();
241 symbolP
= symbol_find_or_make (name
);
244 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
246 as_bad (_("Ignoring attempt to re-define symbol"));
247 ignore_rest_of_line ();
251 if (S_GET_VALUE (symbolP
) != 0)
253 if (S_GET_VALUE (symbolP
) != size
)
254 /* xgettext:c-format */
255 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
256 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
259 know (symbol_get_frag (symbolP
) == &zero_address_frag
);
261 if (*input_line_pointer
!= ',')
266 input_line_pointer
++;
270 if (! have_align
|| *input_line_pointer
!= '"')
276 temp
= get_absolute_expression ();
281 as_warn (_("Common alignment negative; 0 assumed"));
285 if (symbol_get_obj (symbolP
)->local
)
294 old_subsec
= now_subseg
;
296 applicable
= bfd_applicable_section_flags (stdoutput
);
298 applicable
&= SEC_ALLOC
;
302 case SCOMMON_SECTION
:
303 do_v850_seg (SBSS_SECTION
, 0);
306 case ZCOMMON_SECTION
:
307 do_v850_seg (ZBSS_SECTION
, 0);
310 case TCOMMON_SECTION
:
311 do_v850_seg (TBSS_SECTION
, 0);
317 /* Convert to a power of 2 alignment. */
318 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
)
323 as_bad (_("Common alignment not a power of 2"));
324 ignore_rest_of_line ();
331 record_alignment (now_seg
, align
);
334 frag_align (align
, 0, 0);
338 case SCOMMON_SECTION
:
339 if (S_GET_SEGMENT (symbolP
) == v850_seg_table
[SBSS_SECTION
].s
)
340 symbol_get_frag (symbolP
)->fr_symbol
= 0;
343 case ZCOMMON_SECTION
:
344 if (S_GET_SEGMENT (symbolP
) == v850_seg_table
[ZBSS_SECTION
].s
)
345 symbol_get_frag (symbolP
)->fr_symbol
= 0;
348 case TCOMMON_SECTION
:
349 if (S_GET_SEGMENT (symbolP
) == v850_seg_table
[TBSS_SECTION
].s
)
350 symbol_get_frag (symbolP
)->fr_symbol
= 0;
357 symbol_set_frag (symbolP
, frag_now
);
358 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
359 (offsetT
) size
, (char *) 0);
361 S_SET_SIZE (symbolP
, size
);
365 case SCOMMON_SECTION
:
366 S_SET_SEGMENT (symbolP
, v850_seg_table
[SBSS_SECTION
].s
);
369 case ZCOMMON_SECTION
:
370 S_SET_SEGMENT (symbolP
, v850_seg_table
[ZBSS_SECTION
].s
);
373 case TCOMMON_SECTION
:
374 S_SET_SEGMENT (symbolP
, v850_seg_table
[TBSS_SECTION
].s
);
381 S_CLEAR_EXTERNAL (symbolP
);
382 obj_elf_section_change_hook ();
383 subseg_set (old_sec
, old_subsec
);
392 old_subsec
= now_subseg
;
394 S_SET_VALUE (symbolP
, (valueT
) size
);
395 S_SET_ALIGN (symbolP
, temp
);
396 S_SET_EXTERNAL (symbolP
);
400 case SCOMMON_SECTION
:
401 case ZCOMMON_SECTION
:
402 case TCOMMON_SECTION
:
403 do_v850_seg (area
, 0);
404 S_SET_SEGMENT (symbolP
, v850_seg_table
[area
].s
);
411 obj_elf_section_change_hook ();
412 subseg_set (old_sec
, old_subsec
);
417 input_line_pointer
++;
419 /* @@ Some use the dot, some don't. Can we get some consistency?? */
420 if (*input_line_pointer
== '.')
421 input_line_pointer
++;
423 /* @@ Some say data, some say bss. */
424 if (strncmp (input_line_pointer
, "bss\"", 4)
425 && strncmp (input_line_pointer
, "data\"", 5))
427 while (*--input_line_pointer
!= '"')
429 input_line_pointer
--;
430 goto bad_common_segment
;
433 while (*input_line_pointer
++ != '"')
436 goto allocate_common
;
439 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
441 demand_empty_rest_of_line ();
446 p
= input_line_pointer
;
447 while (*p
&& *p
!= '\n')
451 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
453 input_line_pointer
= p
;
454 ignore_rest_of_line ();
460 set_machine (int number
)
463 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
467 case 0: processor_mask
= PROCESSOR_V850
; break;
468 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
469 case bfd_mach_v850e1
: processor_mask
= PROCESSOR_V850E
; break;
474 v850_longcode (int type
)
481 as_warn (".longcall pseudo-op seen when not relaxing");
483 as_warn (".longjump pseudo-op seen when not relaxing");
488 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
490 as_bad ("bad .longcall format");
491 ignore_rest_of_line ();
497 fix_new_exp (frag_now
, frag_now_fix (), 4, & ex
, 1,
498 BFD_RELOC_V850_LONGCALL
);
500 fix_new_exp (frag_now
, frag_now_fix (), 4, & ex
, 1,
501 BFD_RELOC_V850_LONGJUMP
);
503 demand_empty_rest_of_line ();
506 /* The target specific pseudo-ops which we support. */
507 const pseudo_typeS md_pseudo_table
[] =
509 { "sdata", v850_seg
, SDATA_SECTION
},
510 { "tdata", v850_seg
, TDATA_SECTION
},
511 { "zdata", v850_seg
, ZDATA_SECTION
},
512 { "sbss", v850_seg
, SBSS_SECTION
},
513 { "tbss", v850_seg
, TBSS_SECTION
},
514 { "zbss", v850_seg
, ZBSS_SECTION
},
515 { "rosdata", v850_seg
, ROSDATA_SECTION
},
516 { "rozdata", v850_seg
, ROZDATA_SECTION
},
517 { "bss", v850_seg
, BSS_SECTION
},
518 { "offset", v850_offset
, 0 },
520 { "zcomm", v850_comm
, ZCOMMON_SECTION
},
521 { "scomm", v850_comm
, SCOMMON_SECTION
},
522 { "tcomm", v850_comm
, TCOMMON_SECTION
},
523 { "v850", set_machine
, 0 },
524 { "call_table_data", v850_seg
, CALL_TABLE_DATA_SECTION
},
525 { "call_table_text", v850_seg
, CALL_TABLE_TEXT_SECTION
},
526 { "v850e", set_machine
, bfd_mach_v850e
},
527 { "v850e1", set_machine
, bfd_mach_v850e1
},
528 { "longcall", v850_longcode
, 1 },
529 { "longjump", v850_longcode
, 2 },
533 /* Opcode hash table. */
534 static struct hash_control
*v850_hash
;
536 /* This table is sorted. Suitable for searching by a binary search. */
537 static const struct reg_name pre_defined_registers
[] =
539 { "ep", 30 }, /* ep - element ptr. */
540 { "gp", 4 }, /* gp - global ptr. */
541 { "hp", 2 }, /* hp - handler stack ptr. */
542 { "lp", 31 }, /* lp - link ptr. */
575 { "sp", 3 }, /* sp - stack ptr. */
576 { "tp", 5 }, /* tp - text ptr. */
580 #define REG_NAME_CNT \
581 (sizeof (pre_defined_registers) / sizeof (struct reg_name))
583 static const struct reg_name system_registers
[] =
605 #define SYSREG_NAME_CNT \
606 (sizeof (system_registers) / sizeof (struct reg_name))
608 static const struct reg_name system_list_registers
[] =
614 #define SYSREGLIST_NAME_CNT \
615 (sizeof (system_list_registers) / sizeof (struct reg_name))
617 static const struct reg_name cc_names
[] =
643 #define CC_NAME_CNT \
644 (sizeof (cc_names) / sizeof (struct reg_name))
646 /* Do a binary search of the given register table to see if NAME is a
647 valid regiter name. Return the register number from the array on
648 success, or -1 on failure. */
651 reg_name_search (const struct reg_name
*regs
,
654 bfd_boolean accept_numbers
)
656 int middle
, low
, high
;
660 /* If the register name is a symbol, then evaluate it. */
661 if ((symbolP
= symbol_find (name
)) != NULL
)
663 /* If the symbol is an alias for another name then use that.
664 If the symbol is an alias for a number, then return the number. */
665 if (symbol_equated_p (symbolP
))
667 = S_GET_NAME (symbol_get_value_expression (symbolP
)->X_add_symbol
);
668 else if (accept_numbers
)
670 int reg
= S_GET_VALUE (symbolP
);
672 if (reg
>= 0 && reg
<= 31)
676 /* Otherwise drop through and try parsing name normally. */
684 middle
= (low
+ high
) / 2;
685 cmp
= strcasecmp (name
, regs
[middle
].name
);
691 return regs
[middle
].value
;
697 /* Summary of register_name().
699 in: Input_line_pointer points to 1st char of operand.
702 The operand may have been a register: in this case, X_op == O_register,
703 X_add_number is set to the register number, and truth is returned.
704 Input_line_pointer->(next non-blank) char after operand, or is in
705 its original state. */
708 register_name (expressionS
*expressionP
)
715 /* Find the spelling of the operand. */
716 start
= name
= input_line_pointer
;
718 c
= get_symbol_end ();
720 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
,
723 /* Put back the delimiting char. */
724 *input_line_pointer
= c
;
726 /* Look to see if it's in the register table. */
729 expressionP
->X_op
= O_register
;
730 expressionP
->X_add_number
= reg_number
;
732 /* Make the rest nice. */
733 expressionP
->X_add_symbol
= NULL
;
734 expressionP
->X_op_symbol
= NULL
;
740 /* Reset the line as if we had not done anything. */
741 input_line_pointer
= start
;
747 /* Summary of system_register_name().
749 in: INPUT_LINE_POINTER points to 1st char of operand.
750 EXPRESSIONP points to an expression structure to be filled in.
751 ACCEPT_NUMBERS is true iff numerical register names may be used.
752 ACCEPT_LIST_NAMES is true iff the special names PS and SR may be
755 out: An expressionS structure in expressionP.
756 The operand may have been a register: in this case, X_op == O_register,
757 X_add_number is set to the register number, and truth is returned.
758 Input_line_pointer->(next non-blank) char after operand, or is in
759 its original state. */
762 system_register_name (expressionS
*expressionP
,
763 bfd_boolean accept_numbers
,
764 bfd_boolean accept_list_names
)
771 /* Find the spelling of the operand. */
772 start
= name
= input_line_pointer
;
774 c
= get_symbol_end ();
775 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
,
778 /* Put back the delimiting char. */
779 *input_line_pointer
= c
;
784 /* Reset input_line pointer. */
785 input_line_pointer
= start
;
787 if (ISDIGIT (*input_line_pointer
))
789 reg_number
= strtol (input_line_pointer
, &input_line_pointer
, 10);
791 /* Make sure that the register number is allowable. */
793 || (reg_number
> 5 && reg_number
< 16)
797 else if (accept_list_names
)
799 c
= get_symbol_end ();
800 reg_number
= reg_name_search (system_list_registers
,
801 SYSREGLIST_NAME_CNT
, name
, FALSE
);
803 /* Put back the delimiting char. */
804 *input_line_pointer
= c
;
808 /* Look to see if it's in the register table. */
811 expressionP
->X_op
= O_register
;
812 expressionP
->X_add_number
= reg_number
;
814 /* Make the rest nice. */
815 expressionP
->X_add_symbol
= NULL
;
816 expressionP
->X_op_symbol
= NULL
;
822 /* Reset the line as if we had not done anything. */
823 input_line_pointer
= start
;
829 /* Summary of cc_name().
831 in: INPUT_LINE_POINTER points to 1st char of operand.
834 The operand may have been a register: in this case, X_op == O_register,
835 X_add_number is set to the register number, and truth is returned.
836 Input_line_pointer->(next non-blank) char after operand, or is in
837 its original state. */
840 cc_name (expressionS
*expressionP
)
847 /* Find the spelling of the operand. */
848 start
= name
= input_line_pointer
;
850 c
= get_symbol_end ();
851 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
, FALSE
);
853 /* Put back the delimiting char. */
854 *input_line_pointer
= c
;
856 /* Look to see if it's in the register table. */
859 expressionP
->X_op
= O_constant
;
860 expressionP
->X_add_number
= reg_number
;
862 /* Make the rest nice. */
863 expressionP
->X_add_symbol
= NULL
;
864 expressionP
->X_op_symbol
= NULL
;
870 /* Reset the line as if we had not done anything. */
871 input_line_pointer
= start
;
878 skip_white_space (void)
880 while (*input_line_pointer
== ' '
881 || *input_line_pointer
== '\t')
882 ++input_line_pointer
;
885 /* Summary of parse_register_list ().
887 in: INPUT_LINE_POINTER points to 1st char of a list of registers.
888 INSN is the partially constructed instruction.
889 OPERAND is the operand being inserted.
891 out: NULL if the parse completed successfully, otherwise a
892 pointer to an error message is returned. If the parse
893 completes the correct bit fields in the instruction
896 Parses register lists with the syntax:
904 and also parses constant expressions whoes bits indicate the
905 registers in the lists. The LSB in the expression refers to
906 the lowest numbered permissible register in the register list,
907 and so on upwards. System registers are considered to be very
911 parse_register_list (unsigned long *insn
,
912 const struct v850_operand
*operand
)
914 static int type1_regs
[32] =
916 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
917 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
919 static int type2_regs
[32] =
921 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
922 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24
924 static int type3_regs
[32] =
926 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
927 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8
932 /* Select a register array to parse. */
933 switch (operand
->shift
)
935 case 0xffe00001: regs
= type1_regs
; break;
936 case 0xfff8000f: regs
= type2_regs
; break;
937 case 0xfff8001f: regs
= type3_regs
; break;
939 as_bad (_("unknown operand shift: %x\n"), operand
->shift
);
940 return _("internal failure in parse_register_list");
945 /* If the expression starts with a curly brace it is a register list.
946 Otherwise it is a constant expression, whoes bits indicate which
947 registers are to be included in the list. */
948 if (*input_line_pointer
!= '{')
955 if (exp
.X_op
!= O_constant
)
956 return _("constant expression or register list expected");
958 if (regs
== type1_regs
)
960 if (exp
.X_add_number
& 0xFFFFF000)
961 return _("high bits set in register list expression");
963 for (reg
= 20; reg
< 32; reg
++)
964 if (exp
.X_add_number
& (1 << (reg
- 20)))
966 for (i
= 0; i
< 32; i
++)
971 else if (regs
== type2_regs
)
973 if (exp
.X_add_number
& 0xFFFE0000)
974 return _("high bits set in register list expression");
976 for (reg
= 1; reg
< 16; reg
++)
977 if (exp
.X_add_number
& (1 << (reg
- 1)))
979 for (i
= 0; i
< 32; i
++)
984 if (exp
.X_add_number
& (1 << 15))
987 if (exp
.X_add_number
& (1 << 16))
990 else /* regs == type3_regs */
992 if (exp
.X_add_number
& 0xFFFE0000)
993 return _("high bits set in register list expression");
995 for (reg
= 16; reg
< 32; reg
++)
996 if (exp
.X_add_number
& (1 << (reg
- 16)))
998 for (i
= 0; i
< 32; i
++)
1003 if (exp
.X_add_number
& (1 << 16))
1010 input_line_pointer
++;
1012 /* Parse the register list until a terminator (closing curly brace or
1013 new-line) is found. */
1016 if (register_name (&exp
))
1020 /* Locate the given register in the list, and if it is there,
1021 insert the corresponding bit into the instruction. */
1022 for (i
= 0; i
< 32; i
++)
1024 if (regs
[i
] == exp
.X_add_number
)
1032 return _("illegal register included in list");
1034 else if (system_register_name (&exp
, TRUE
, TRUE
))
1036 if (regs
== type1_regs
)
1038 return _("system registers cannot be included in list");
1040 else if (exp
.X_add_number
== 5)
1042 if (regs
== type2_regs
)
1043 return _("PSW cannot be included in list");
1047 else if (exp
.X_add_number
< 4)
1050 return _("High value system registers cannot be included in list");
1052 else if (*input_line_pointer
== '}')
1054 input_line_pointer
++;
1057 else if (*input_line_pointer
== ',')
1059 input_line_pointer
++;
1062 else if (*input_line_pointer
== '-')
1064 /* We have encountered a range of registers: rX - rY. */
1068 /* Skip the dash. */
1069 ++input_line_pointer
;
1071 /* Get the second register in the range. */
1072 if (! register_name (&exp2
))
1074 return _("second register should follow dash in register list");
1075 exp2
.X_add_number
= exp
.X_add_number
;
1078 /* Add the rest of the registers in the range. */
1079 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1083 /* Locate the given register in the list, and if it is there,
1084 insert the corresponding bit into the instruction. */
1085 for (i
= 0; i
< 32; i
++)
1095 return _("illegal register included in list");
1101 skip_white_space ();
1107 const char *md_shortopts
= "m:";
1109 struct option md_longopts
[] =
1111 {NULL
, no_argument
, NULL
, 0}
1114 size_t md_longopts_size
= sizeof (md_longopts
);
1117 md_show_usage (FILE *stream
)
1119 fprintf (stream
, _(" V850 options:\n"));
1120 fprintf (stream
, _(" -mwarn-signed-overflow Warn if signed immediate values overflow\n"));
1121 fprintf (stream
, _(" -mwarn-unsigned-overflow Warn if unsigned immediate values overflow\n"));
1122 fprintf (stream
, _(" -mv850 The code is targeted at the v850\n"));
1123 fprintf (stream
, _(" -mv850e The code is targeted at the v850e\n"));
1124 fprintf (stream
, _(" -mv850e1 The code is targeted at the v850e1\n"));
1125 fprintf (stream
, _(" -mv850any The code is generic, despite any processor specific instructions\n"));
1126 fprintf (stream
, _(" -mrelax Enable relaxation\n"));
1130 md_parse_option (int c
, char *arg
)
1135 if (strcmp (arg
, "warn-signed-overflow") == 0)
1136 warn_signed_overflows
= TRUE
;
1138 else if (strcmp (arg
, "warn-unsigned-overflow") == 0)
1139 warn_unsigned_overflows
= TRUE
;
1141 else if (strcmp (arg
, "v850") == 0)
1144 processor_mask
= PROCESSOR_V850
;
1146 else if (strcmp (arg
, "v850e") == 0)
1148 machine
= bfd_mach_v850e
;
1149 processor_mask
= PROCESSOR_V850E
;
1151 else if (strcmp (arg
, "v850e1") == 0)
1153 machine
= bfd_mach_v850e1
;
1154 processor_mask
= PROCESSOR_V850E1
;
1156 else if (strcmp (arg
, "v850any") == 0)
1158 /* Tell the world that this is for any v850 chip. */
1161 /* But support instructions for the extended versions. */
1162 processor_mask
= PROCESSOR_V850E
;
1163 processor_mask
|= PROCESSOR_V850E1
;
1165 else if (strcmp (arg
, "relax") == 0)
1174 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1180 md_atof (int type
, char *litp
, int *sizep
)
1183 LITTLENUM_TYPE words
[4];
1199 return _("bad call to md_atof");
1202 t
= atof_ieee (input_line_pointer
, type
, words
);
1204 input_line_pointer
= t
;
1208 for (i
= prec
- 1; i
>= 0; i
--)
1210 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1220 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
1224 subseg_change (sec
, 0);
1226 /* In range conditional or unconditional branch. */
1227 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1229 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1230 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1233 /* Out of range conditional branch. Emit a branch around a jump. */
1234 else if (fragP
->fr_subtype
== 1)
1236 unsigned char *buffer
=
1237 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1239 /* Reverse the condition of the first branch. */
1241 /* Mask off all the displacement bits. */
1244 /* Now set the displacement bits so that we branch
1245 around the unconditional branch. */
1248 /* Now create the unconditional branch + fixup to the final
1250 md_number_to_chars ((char *) buffer
+ 2, 0x00000780, 4);
1251 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1252 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1253 (int) fragP
->fr_opcode
+ 1);
1256 /* Out of range unconditional branch. Emit a jump. */
1257 else if (fragP
->fr_subtype
== 3)
1259 md_number_to_chars (fragP
->fr_fix
+ fragP
->fr_literal
, 0x00000780, 4);
1260 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
1261 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+
1262 (int) fragP
->fr_opcode
+ 1);
1270 md_section_align (asection
*seg
, valueT addr
)
1272 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1273 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1279 char *prev_name
= "";
1280 const struct v850_opcode
*op
;
1282 if (strncmp (TARGET_CPU
, "v850e1", 6) == 0)
1285 machine
= bfd_mach_v850e1
;
1287 if (processor_mask
== -1)
1288 processor_mask
= PROCESSOR_V850E1
;
1290 else if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1293 machine
= bfd_mach_v850e
;
1295 if (processor_mask
== -1)
1296 processor_mask
= PROCESSOR_V850E
;
1298 else if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1303 if (processor_mask
== -1)
1304 processor_mask
= PROCESSOR_V850
;
1307 /* xgettext:c-format */
1308 as_bad (_("Unable to determine default target processor from string: %s"),
1311 v850_hash
= hash_new ();
1313 /* Insert unique names into hash table. The V850 instruction set
1314 has many identical opcode names that have different opcodes based
1315 on the operands. This hash table then provides a quick index to
1316 the first opcode with a particular name in the opcode table. */
1320 if (strcmp (prev_name
, op
->name
))
1322 prev_name
= (char *) op
->name
;
1323 hash_insert (v850_hash
, op
->name
, (char *) op
);
1328 v850_seg_table
[BSS_SECTION
].s
= bss_section
;
1329 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1332 static bfd_reloc_code_real_type
1333 handle_lo16 (const struct v850_operand
*operand
)
1335 if (operand
!= NULL
)
1337 if (operand
->bits
== -1)
1338 return BFD_RELOC_V850_LO16_SPLIT_OFFSET
;
1340 if (!(operand
->bits
== 16 && operand
->shift
== 16)
1341 && !(operand
->bits
== 15 && operand
->shift
== 17))
1343 as_bad (_("lo() relocation used on an instruction which does "
1345 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1348 return BFD_RELOC_LO16
;
1351 static bfd_reloc_code_real_type
1352 handle_ctoff (const struct v850_operand
*operand
)
1354 if (operand
== NULL
)
1355 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1357 if (operand
->bits
!= 6
1358 || operand
->shift
!= 0)
1360 as_bad (_("ctoff() relocation used on an instruction which does not support it"));
1361 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1364 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1367 static bfd_reloc_code_real_type
1368 handle_sdaoff (const struct v850_operand
*operand
)
1370 if (operand
== NULL
)
1371 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1373 if (operand
->bits
== 15 && operand
->shift
== 17)
1374 return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1376 if (operand
->bits
== -1)
1377 return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1379 if (operand
->bits
!= 16
1380 || operand
->shift
!= 16)
1382 as_bad (_("sdaoff() 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_SDA_16_16_OFFSET
;
1389 static bfd_reloc_code_real_type
1390 handle_zdaoff (const struct v850_operand
*operand
)
1392 if (operand
== NULL
)
1393 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1395 if (operand
->bits
== 15 && operand
->shift
== 17)
1396 return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1398 if (operand
->bits
== -1)
1399 return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1401 if (operand
->bits
!= 16
1402 || operand
->shift
!= 16)
1404 as_bad (_("zdaoff() relocation used on an instruction which does not support it"));
1405 /* Used to indicate an error condition. */
1406 return BFD_RELOC_64
;
1409 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1412 static bfd_reloc_code_real_type
1413 handle_tdaoff (const struct v850_operand
*operand
)
1415 if (operand
== NULL
)
1416 /* Data item, not an instruction. */
1417 return BFD_RELOC_V850_TDA_7_7_OFFSET
;
1419 if (operand
->bits
== 6 && operand
->shift
== 1)
1420 /* sld.w/sst.w, operand: D8_6. */
1421 return BFD_RELOC_V850_TDA_6_8_OFFSET
;
1423 if (operand
->bits
== 4 && operand
->insert
!= NULL
)
1424 /* sld.hu, operand: D5-4. */
1425 return BFD_RELOC_V850_TDA_4_5_OFFSET
;
1427 if (operand
->bits
== 4 && operand
->insert
== NULL
)
1428 /* sld.bu, operand: D4. */
1429 return BFD_RELOC_V850_TDA_4_4_OFFSET
;
1431 if (operand
->bits
== 16 && operand
->shift
== 16)
1432 /* set1 & chums, operands: D16. */
1433 return BFD_RELOC_V850_TDA_16_16_OFFSET
;
1435 if (operand
->bits
!= 7)
1437 as_bad (_("tdaoff() relocation used on an instruction which does not support it"));
1438 /* Used to indicate an error condition. */
1439 return BFD_RELOC_64
;
1442 return operand
->insert
!= NULL
1443 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7. */
1444 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, operand: D7. */
1447 /* Warning: The code in this function relies upon the definitions
1448 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1449 matching the hard coded values contained herein. */
1451 static bfd_reloc_code_real_type
1452 v850_reloc_prefix (const struct v850_operand
*operand
)
1454 bfd_boolean paren_skipped
= FALSE
;
1456 /* Skip leading opening parenthesis. */
1457 if (*input_line_pointer
== '(')
1459 ++input_line_pointer
;
1460 paren_skipped
= TRUE
;
1463 #define CHECK_(name, reloc) \
1464 if (strncmp (input_line_pointer, name "(", strlen (name) + 1) == 0) \
1466 input_line_pointer += strlen (name); \
1470 CHECK_ ("hi0", BFD_RELOC_HI16
);
1471 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1472 CHECK_ ("lo", handle_lo16 (operand
) );
1473 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1474 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1475 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1476 CHECK_ ("hilo", BFD_RELOC_32
);
1477 CHECK_ ("ctoff", handle_ctoff (operand
) );
1479 /* Restore skipped parenthesis. */
1481 --input_line_pointer
;
1483 return BFD_RELOC_UNUSED
;
1486 /* Insert an operand value into an instruction. */
1488 static unsigned long
1489 v850_insert_operand (unsigned long insn
,
1490 const struct v850_operand
*operand
,
1496 if (operand
->insert
)
1498 const char *message
= NULL
;
1500 insn
= operand
->insert (insn
, val
, &message
);
1501 if (message
!= NULL
)
1503 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1504 && ! warn_signed_overflows
1505 && strstr (message
, "out of range") != NULL
)
1507 /* Skip warning... */
1509 else if ((operand
->flags
& V850_OPERAND_SIGNED
) == 0
1510 && ! warn_unsigned_overflows
1511 && strstr (message
, "out of range") != NULL
)
1513 /* Skip warning... */
1517 if (file
== (char *) NULL
)
1518 as_warn ("%s: %s", str
, message
);
1520 as_warn_where (file
, line
, "%s: %s", str
, message
);
1524 if (file
== (char *) NULL
)
1527 as_warn_where (file
, line
, message
);
1533 if (operand
->bits
!= 32)
1537 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1539 if (! warn_signed_overflows
)
1540 max
= (1 << operand
->bits
) - 1;
1542 max
= (1 << (operand
->bits
- 1)) - 1;
1544 min
= -(1 << (operand
->bits
- 1));
1548 max
= (1 << operand
->bits
) - 1;
1550 if (! warn_unsigned_overflows
)
1551 min
= -(1 << (operand
->bits
- 1));
1556 if (val
< (offsetT
) min
|| val
> (offsetT
) max
)
1560 /* Restore min and mix to expected values for decimal ranges. */
1561 if ((operand
->flags
& V850_OPERAND_SIGNED
)
1562 && ! warn_signed_overflows
)
1563 max
= (1 << (operand
->bits
- 1)) - 1;
1565 if (! (operand
->flags
& V850_OPERAND_SIGNED
)
1566 && ! warn_unsigned_overflows
)
1570 sprintf (buf
, "%s: ", str
);
1573 strcat (buf
, _("operand"));
1575 as_bad_value_out_of_range (buf
, val
, (offsetT
) min
, (offsetT
) max
, file
, line
);
1579 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1585 static char copy_of_instruction
[128];
1588 md_assemble (char *str
)
1591 char *start_of_operands
;
1592 struct v850_opcode
*opcode
;
1593 struct v850_opcode
*next_opcode
;
1594 const unsigned char *opindex_ptr
;
1598 unsigned long insn_size
;
1602 bfd_boolean extra_data_after_insn
= FALSE
;
1603 unsigned extra_data_len
= 0;
1604 unsigned long extra_data
= 0;
1605 char *saved_input_line_pointer
;
1607 strncpy (copy_of_instruction
, str
, sizeof (copy_of_instruction
) - 1);
1609 /* Get the opcode. */
1610 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1616 /* Find the first opcode with the proper name. */
1617 opcode
= (struct v850_opcode
*) hash_find (v850_hash
, str
);
1620 /* xgettext:c-format */
1621 as_bad (_("Unrecognized opcode: `%s'"), str
);
1622 ignore_rest_of_line ();
1627 while (ISSPACE (*str
))
1630 start_of_operands
= str
;
1632 saved_input_line_pointer
= input_line_pointer
;
1636 const char *errmsg
= NULL
;
1640 if ((opcode
->processors
& processor_mask
) == 0)
1642 errmsg
= _("Target processor does not support this instruction.");
1649 insn
= opcode
->opcode
;
1650 extra_data_after_insn
= FALSE
;
1652 input_line_pointer
= str
= start_of_operands
;
1654 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1656 const struct v850_operand
*operand
;
1659 bfd_reloc_code_real_type reloc
;
1661 if (next_opindex
== 0)
1662 operand
= &v850_operands
[*opindex_ptr
];
1665 operand
= &v850_operands
[next_opindex
];
1671 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1674 if (operand
->flags
& V850_OPERAND_RELAX
)
1677 /* Gather the operand. */
1678 hold
= input_line_pointer
;
1679 input_line_pointer
= str
;
1681 /* lo(), hi(), hi0(), etc... */
1682 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1684 /* This is a fake reloc, used to indicate an error condition. */
1685 if (reloc
== BFD_RELOC_64
)
1693 if (ex
.X_op
== O_constant
)
1697 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1698 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]"
1702 case BFD_RELOC_LO16
:
1703 case BFD_RELOC_V850_LO16_SPLIT_OFFSET
:
1705 /* Truncate, then sign extend the value. */
1706 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1710 case BFD_RELOC_HI16
:
1712 /* Truncate, then sign extend the value. */
1713 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1717 case BFD_RELOC_HI16_S
:
1719 /* Truncate, then sign extend the value. */
1720 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1722 temp
+= (ex
.X_add_number
>> 15) & 1;
1724 ex
.X_add_number
= SEXT16 (temp
);
1729 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1731 errmsg
= _("immediate operand is too large");
1735 extra_data_after_insn
= TRUE
;
1741 fprintf (stderr
, "reloc: %d\n", reloc
);
1742 as_bad (_("AAARG -> unhandled constant reloc"));
1746 if (fc
> MAX_INSN_FIXUPS
)
1747 as_fatal (_("too many fixups"));
1749 fixups
[fc
].exp
= ex
;
1750 fixups
[fc
].opindex
= *opindex_ptr
;
1751 fixups
[fc
].reloc
= reloc
;
1756 if (reloc
== BFD_RELOC_32
)
1758 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1760 errmsg
= _("immediate operand is too large");
1764 extra_data_after_insn
= TRUE
;
1766 extra_data
= ex
.X_add_number
;
1769 if (fc
> MAX_INSN_FIXUPS
)
1770 as_fatal (_("too many fixups"));
1772 fixups
[fc
].exp
= ex
;
1773 fixups
[fc
].opindex
= *opindex_ptr
;
1774 fixups
[fc
].reloc
= reloc
;
1782 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1784 if (!register_name (&ex
))
1785 errmsg
= _("invalid register name");
1786 else if ((operand
->flags
& V850_NOT_R0
)
1787 && ex
.X_add_number
== 0)
1789 errmsg
= _("register r0 cannot be used here");
1791 /* Force an error message to be generated by
1792 skipping over any following potential matches
1797 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1799 if (!system_register_name (&ex
, TRUE
, FALSE
))
1800 errmsg
= _("invalid system register name");
1802 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1804 char *start
= input_line_pointer
;
1805 char c
= get_symbol_end ();
1807 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1809 /* Put things back the way we found them. */
1810 *input_line_pointer
= c
;
1811 input_line_pointer
= start
;
1812 errmsg
= _("expected EP register");
1816 *input_line_pointer
= c
;
1817 str
= input_line_pointer
;
1818 input_line_pointer
= hold
;
1820 while (*str
== ' ' || *str
== ','
1821 || *str
== '[' || *str
== ']')
1825 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1828 errmsg
= _("invalid condition code name");
1830 else if (operand
->flags
& V850E_PUSH_POP
)
1832 errmsg
= parse_register_list (&insn
, operand
);
1834 /* The parse_register_list() function has already done
1835 everything, so fake a dummy expression. */
1836 ex
.X_op
= O_constant
;
1837 ex
.X_add_number
= 0;
1839 else if (operand
->flags
& V850E_IMMEDIATE16
)
1843 if (ex
.X_op
!= O_constant
)
1844 errmsg
= _("constant expression expected");
1845 else if (ex
.X_add_number
& 0xffff0000)
1847 if (ex
.X_add_number
& 0xffff)
1848 errmsg
= _("constant too big to fit into instruction");
1849 else if ((insn
& 0x001fffc0) == 0x00130780)
1850 ex
.X_add_number
>>= 16;
1852 errmsg
= _("constant too big to fit into instruction");
1855 extra_data_after_insn
= TRUE
;
1857 extra_data
= ex
.X_add_number
;
1858 ex
.X_add_number
= 0;
1860 else if (operand
->flags
& V850E_IMMEDIATE32
)
1864 if (ex
.X_op
!= O_constant
)
1865 errmsg
= _("constant expression expected");
1867 extra_data_after_insn
= TRUE
;
1869 extra_data
= ex
.X_add_number
;
1870 ex
.X_add_number
= 0;
1872 else if (register_name (&ex
)
1873 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1878 /* It is possible that an alias has been defined that
1879 matches a register name. For example the code may
1880 include a ".set ZERO, 0" directive, which matches
1881 the register name "zero". Attempt to reparse the
1882 field as an expression, and only complain if we
1883 cannot generate a constant. */
1885 input_line_pointer
= str
;
1887 c
= get_symbol_end ();
1889 if (symbol_find (str
) != NULL
)
1892 *input_line_pointer
= c
;
1893 input_line_pointer
= str
;
1897 if (ex
.X_op
!= O_constant
)
1899 /* If this register is actually occurring too early on
1900 the parsing of the instruction, (because another
1901 field is missing) then report this. */
1902 if (opindex_ptr
[1] != 0
1903 && (v850_operands
[opindex_ptr
[1]].flags
1904 & V850_OPERAND_REG
))
1905 errmsg
= _("syntax error: value is missing before the register name");
1907 errmsg
= _("syntax error: register not expected");
1909 /* If we created a symbol in the process of this
1910 test then delete it now, so that it will not
1911 be output with the real symbols... */
1913 && ex
.X_op
== O_symbol
)
1914 symbol_remove (ex
.X_add_symbol
,
1915 &symbol_rootP
, &symbol_lastP
);
1918 else if (system_register_name (&ex
, FALSE
, FALSE
)
1919 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1920 errmsg
= _("syntax error: system register not expected");
1922 else if (cc_name (&ex
)
1923 && (operand
->flags
& V850_OPERAND_CC
) == 0)
1924 errmsg
= _("syntax error: condition code not expected");
1930 If we are assembling a MOV instruction and the immediate
1931 value does not fit into the bits available then create a
1932 fake error so that the next MOV instruction will be
1933 selected. This one has a 32 bit immediate field. */
1935 if (((insn
& 0x07e0) == 0x0200)
1936 && operand
->bits
== 5 /* Do not match the CALLT instruction. */
1937 && ex
.X_op
== O_constant
1938 && (ex
.X_add_number
< (-(1 << (operand
->bits
- 1)))
1939 || ex
.X_add_number
> ((1 << (operand
->bits
- 1)) - 1)))
1940 errmsg
= _("immediate operand is too large");
1949 errmsg
= _("illegal operand");
1952 errmsg
= _("missing operand");
1956 & (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
1958 errmsg
= _("invalid operand");
1961 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1962 NULL
, 0, copy_of_instruction
);
1966 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1967 NULL
, 0, copy_of_instruction
);
1971 /* We need to generate a fixup for this expression. */
1972 if (fc
>= MAX_INSN_FIXUPS
)
1973 as_fatal (_("too many fixups"));
1975 fixups
[fc
].exp
= ex
;
1976 fixups
[fc
].opindex
= *opindex_ptr
;
1977 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1983 str
= input_line_pointer
;
1984 input_line_pointer
= hold
;
1986 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
1995 next_opcode
= opcode
+ 1;
1996 if (next_opcode
->name
!= NULL
1997 && strcmp (next_opcode
->name
, opcode
->name
) == 0)
1999 opcode
= next_opcode
;
2001 /* Skip versions that are not supported by the target
2003 if ((opcode
->processors
& processor_mask
) == 0)
2009 as_bad ("%s: %s", copy_of_instruction
, errmsg
);
2011 if (*input_line_pointer
== ']')
2012 ++input_line_pointer
;
2014 ignore_rest_of_line ();
2015 input_line_pointer
= saved_input_line_pointer
;
2021 while (ISSPACE (*str
))
2025 /* xgettext:c-format */
2026 as_bad (_("junk at end of line: `%s'"), str
);
2028 input_line_pointer
= str
;
2030 /* Tie dwarf2 debug info to the address at the start of the insn.
2031 We can't do this after the insn has been output as the current
2032 frag may have been closed off. eg. by frag_var. */
2033 dwarf2_emit_insn (0);
2035 /* Write out the instruction. */
2037 if (relaxable
&& fc
> 0)
2042 if (!strcmp (opcode
->name
, "br"))
2044 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
2045 fixups
[0].exp
.X_add_symbol
,
2046 fixups
[0].exp
.X_add_number
,
2047 (char *) fixups
[0].opindex
);
2048 md_number_to_chars (f
, insn
, insn_size
);
2049 md_number_to_chars (f
+ 2, 0, 2);
2053 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
2054 fixups
[0].exp
.X_add_symbol
,
2055 fixups
[0].exp
.X_add_number
,
2056 (char *) fixups
[0].opindex
);
2057 md_number_to_chars (f
, insn
, insn_size
);
2058 md_number_to_chars (f
+ 2, 0, 4);
2063 /* Four byte insns have an opcode with the two high bits on. */
2064 if ((insn
& 0x0600) == 0x0600)
2069 /* Special case: 32 bit MOV. */
2070 if ((insn
& 0xffe0) == 0x0620)
2073 f
= frag_more (insn_size
);
2074 md_number_to_chars (f
, insn
, insn_size
);
2076 if (extra_data_after_insn
)
2078 f
= frag_more (extra_data_len
);
2079 md_number_to_chars (f
, extra_data
, extra_data_len
);
2081 extra_data_after_insn
= FALSE
;
2085 /* Create any fixups. At this point we do not use a
2086 bfd_reloc_code_real_type, but instead just use the
2087 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2088 handle fixups for any operand type, although that is admittedly
2089 not a very exciting feature. We pick a BFD reloc type in
2091 for (i
= 0; i
< fc
; i
++)
2093 const struct v850_operand
*operand
;
2094 bfd_reloc_code_real_type reloc
;
2096 operand
= &v850_operands
[fixups
[i
].opindex
];
2098 reloc
= fixups
[i
].reloc
;
2100 if (reloc
!= BFD_RELOC_UNUSED
)
2102 reloc_howto_type
*reloc_howto
=
2103 bfd_reloc_type_lookup (stdoutput
, reloc
);
2111 size
= bfd_get_reloc_size (reloc_howto
);
2113 /* XXX This will abort on an R_V850_8 reloc -
2114 is this reloc actually used? */
2115 if (size
!= 2 && size
!= 4)
2118 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
2120 if (reloc
== BFD_RELOC_32
)
2123 fixP
= fix_new_exp (frag_now
, address
, size
,
2125 reloc_howto
->pc_relative
,
2130 case BFD_RELOC_LO16
:
2131 case BFD_RELOC_V850_LO16_SPLIT_OFFSET
:
2132 case BFD_RELOC_HI16
:
2133 case BFD_RELOC_HI16_S
:
2134 fixP
->fx_no_overflow
= 1;
2142 fix_new_exp (frag_now
,
2143 f
- frag_now
->fr_literal
, 4,
2145 (operand
->flags
& V850_OPERAND_DISP
) != 0,
2146 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
2147 + (int) BFD_RELOC_UNUSED
));
2151 input_line_pointer
= saved_input_line_pointer
;
2154 /* If while processing a fixup, a reloc really needs to be created
2155 then it is done here. */
2158 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2162 reloc
= xmalloc (sizeof (arelent
));
2163 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2164 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2165 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2167 if ( fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2168 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2169 || fixp
->fx_r_type
== BFD_RELOC_V850_LONGCALL
2170 || fixp
->fx_r_type
== BFD_RELOC_V850_LONGJUMP
2171 || fixp
->fx_r_type
== BFD_RELOC_V850_ALIGN
)
2172 reloc
->addend
= fixp
->fx_offset
;
2175 if (fixp
->fx_r_type
== BFD_RELOC_32
2177 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
2179 reloc
->addend
= fixp
->fx_addnumber
;
2182 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2184 if (reloc
->howto
== NULL
)
2186 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2187 /* xgettext:c-format */
2188 _("reloc %d not supported by object file format"),
2189 (int) fixp
->fx_r_type
);
2200 v850_handle_align (fragS
* frag
)
2203 && frag
->fr_type
== rs_align
2204 && frag
->fr_address
+ frag
->fr_fix
> 0
2205 && frag
->fr_offset
> 1
2206 && now_seg
!= bss_section
2207 && now_seg
!= v850_seg_table
[SBSS_SECTION
].s
2208 && now_seg
!= v850_seg_table
[TBSS_SECTION
].s
2209 && now_seg
!= v850_seg_table
[ZBSS_SECTION
].s
)
2210 fix_new (frag
, frag
->fr_fix
, 2, & abs_symbol
, frag
->fr_offset
, 0,
2211 BFD_RELOC_V850_ALIGN
);
2214 /* Return current size of variable part of frag. */
2217 md_estimate_size_before_relax (fragS
*fragp
, asection
*seg ATTRIBUTE_UNUSED
)
2219 if (fragp
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
2222 return md_relax_table
[fragp
->fr_subtype
].rlx_length
;
2226 v850_pcrel_from_section (fixS
*fixp
, segT section
)
2228 /* If the symbol is undefined, or in a section other than our own,
2229 or it is weak (in which case it may well be in another section,
2230 then let the linker figure it out. */
2231 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2232 && (! S_IS_DEFINED (fixp
->fx_addsy
)
2233 || S_IS_WEAK (fixp
->fx_addsy
)
2234 || (S_GET_SEGMENT (fixp
->fx_addsy
) != section
)))
2237 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2241 md_apply_fix3 (fixS
*fixP
, valueT
*valueP
, segT seg ATTRIBUTE_UNUSED
)
2243 valueT value
= * valueP
;
2246 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2247 || fixP
->fx_r_type
== BFD_RELOC_V850_LONGCALL
2248 || fixP
->fx_r_type
== BFD_RELOC_V850_LONGJUMP
2249 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2255 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
2256 fixP
->fx_addnumber
= value
,
2259 else if (fixP
->fx_pcrel
)
2260 fixP
->fx_addnumber
= fixP
->fx_offset
;
2264 value
= fixP
->fx_offset
;
2265 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
2267 if (S_GET_SEGMENT (fixP
->fx_subsy
) == absolute_section
)
2268 value
-= S_GET_VALUE (fixP
->fx_subsy
);
2270 /* We don't actually support subtracting a symbol. */
2271 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2272 _("expression too complex"));
2274 fixP
->fx_addnumber
= value
;
2277 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2280 const struct v850_operand
*operand
;
2283 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2284 operand
= &v850_operands
[opindex
];
2286 /* Fetch the instruction, insert the fully resolved operand
2287 value, and stuff the instruction back again.
2289 Note the instruction has been stored in little endian
2291 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2293 insn
= bfd_getl32 ((unsigned char *) where
);
2294 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2295 fixP
->fx_file
, fixP
->fx_line
, NULL
);
2296 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2299 /* Nothing else to do here. */
2302 /* Determine a BFD reloc value based on the operand information.
2303 We are only prepared to turn a few of the operands into relocs. */
2305 if (operand
->bits
== 22)
2306 fixP
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2307 else if (operand
->bits
== 9)
2308 fixP
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2311 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2312 _("unresolved expression that must be resolved"));
2317 else if (fixP
->fx_done
)
2319 /* We still have to insert the value into memory! */
2320 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2322 if (fixP
->fx_r_type
== BFD_RELOC_V850_LO16_SPLIT_OFFSET
)
2323 bfd_putl32 (((value
<< 16) & 0xfffe0000)
2324 | ((value
<< 5) & 0x20)
2325 | (bfd_getl32 (where
) & ~0xfffe0020), where
);
2326 else if (fixP
->fx_size
== 1)
2327 *where
= value
& 0xff;
2328 else if (fixP
->fx_size
== 2)
2329 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2330 else if (fixP
->fx_size
== 4)
2331 bfd_putl32 (value
, (unsigned char *) where
);
2335 /* Parse a cons expression. We have to handle hi(), lo(), etc
2339 parse_cons_expression_v850 (expressionS
*exp
)
2341 /* See if there's a reloc prefix like hi() we have to handle. */
2342 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2344 /* Do normal expression parsing. */
2348 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2349 found a reloc prefix, then we use that reloc, else we choose an
2350 appropriate one based on the size of the expression. */
2353 cons_fix_new_v850 (fragS
*frag
,
2358 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2361 hold_cons_reloc
= BFD_RELOC_32
;
2363 hold_cons_reloc
= BFD_RELOC_16
;
2365 hold_cons_reloc
= BFD_RELOC_8
;
2369 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2371 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);
2373 hold_cons_reloc
= BFD_RELOC_UNUSED
;
2377 v850_fix_adjustable (fixS
*fixP
)
2379 if (fixP
->fx_addsy
== NULL
)
2382 /* Don't adjust function names. */
2383 if (S_IS_FUNCTION (fixP
->fx_addsy
))
2386 /* We need the symbol name for the VTABLE entries. */
2387 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2388 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2395 v850_force_relocation (struct fix
*fixP
)
2397 if (fixP
->fx_r_type
== BFD_RELOC_V850_LONGCALL
2398 || fixP
->fx_r_type
== BFD_RELOC_V850_LONGJUMP
)
2403 || fixP
->fx_r_type
== BFD_RELOC_V850_ALIGN
2404 || fixP
->fx_r_type
== BFD_RELOC_V850_22_PCREL
2405 || fixP
->fx_r_type
== BFD_RELOC_V850_9_PCREL
2406 || fixP
->fx_r_type
>= BFD_RELOC_UNUSED
))
2409 return generic_force_reloc (fixP
);