1 /* tc-v850.c -- Assembler code for the NEC V850
2 Copyright (C) 1996, 1997 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "opcode/v850.h"
27 /* sign-extend a 16-bit number */
28 #define SEXT16(x) ((((x) & 0xffff) ^ (~ 0x7fff)) + 0x8000)
30 /* Temporarily holds the reloc in a cons expression. */
31 static bfd_reloc_code_real_type hold_cons_reloc
;
33 /* Set to TRUE if we want to be pedantic about signed overflows. */
34 static boolean warn_signed_overflows
= FALSE
;
35 static boolean warn_unsigned_overflows
= FALSE
;
37 /* Indicates the target BFD machine number. */
38 static int machine
= TARGET_MACHINE
;
40 /* Indicates the target processor(s) for the assemble. */
41 static unsigned int processor_mask
= TARGET_PROCESSOR
;
44 /* Structure to hold information about predefined registers. */
51 /* Generic assembler global variables which must be defined by all targets. */
53 /* Characters which always start a comment. */
54 const char comment_chars
[] = "#";
56 /* Characters which start a comment at the beginning of a line. */
57 const char line_comment_chars
[] = ";#";
59 /* Characters which may be used to separate multiple commands on a
61 const char line_separator_chars
[] = ";";
63 /* Characters which are used to indicate an exponent in a floating
65 const char EXP_CHARS
[] = "eE";
67 /* Characters which mean that a number is a floating point constant,
69 const char FLT_CHARS
[] = "dD";
72 const relax_typeS md_relax_table
[] = {
74 {0x1fffff, -0x200000, 6, 0},
78 static segT sdata_section
= NULL
;
79 static segT tdata_section
= NULL
;
80 static segT zdata_section
= NULL
;
81 static segT sbss_section
= NULL
;
82 static segT tbss_section
= NULL
;
83 static segT zbss_section
= NULL
;
84 static segT rosdata_section
= NULL
;
85 static segT rozdata_section
= NULL
;
86 /* start-sanitize-v850e */
87 static segT call_table_data_section
= NULL
;
88 static segT call_table_text_section
= NULL
;
89 /* end-sanitize-v850e */
93 static unsigned long v850_insert_operand
94 PARAMS ((unsigned long insn
, const struct v850_operand
*operand
,
95 offsetT val
, char *file
, unsigned int line
));
99 #define MAX_INSN_FIXUPS (5)
104 bfd_reloc_code_real_type reloc
;
106 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
110 v850_sdata (int ignore
)
112 subseg_set (sdata_section
, (subsegT
) get_absolute_expression ());
114 demand_empty_rest_of_line ();
118 v850_tdata (int ignore
)
120 subseg_set (tdata_section
, (subsegT
) get_absolute_expression ());
122 demand_empty_rest_of_line ();
126 v850_zdata (int ignore
)
128 subseg_set (zdata_section
, (subsegT
) get_absolute_expression ());
130 demand_empty_rest_of_line ();
134 v850_sbss (int ignore
)
136 subseg_set (sbss_section
, (subsegT
) get_absolute_expression ());
138 demand_empty_rest_of_line ();
142 v850_tbss (int ignore
)
144 subseg_set (tbss_section
, (subsegT
) get_absolute_expression ());
146 demand_empty_rest_of_line ();
150 v850_zbss (int ignore
)
152 subseg_set (zbss_section
, (subsegT
) get_absolute_expression ());
154 demand_empty_rest_of_line ();
158 v850_rosdata (int ignore
)
160 subseg_set (rosdata_section
, (subsegT
) get_absolute_expression ());
162 demand_empty_rest_of_line ();
166 v850_rozdata (int ignore
)
168 subseg_set (rozdata_section
, (subsegT
) get_absolute_expression ());
170 demand_empty_rest_of_line ();
173 /* start-sanitize-v850e */
175 v850_call_table_data (int ignore
)
177 subseg_set (call_table_data_section
, (subsegT
) get_absolute_expression ());
179 demand_empty_rest_of_line ();
183 v850_call_table_text (int ignore
)
185 subseg_set (call_table_text_section
, (subsegT
) get_absolute_expression ());
187 demand_empty_rest_of_line ();
189 /* end-sanitize-v850e */
192 v850_section (int arg
)
197 for (ptr
= input_line_pointer
; * ptr
!= '\n' && * ptr
!= 0; ptr
++)
198 if (* ptr
== ',' && ptr
[1] == '.')
204 obj_elf_section (arg
);
210 v850_bss (int ignore
)
212 register int temp
= get_absolute_expression ();
214 obj_elf_section_change_hook();
216 subseg_set (bss_section
, (subsegT
) temp
);
218 demand_empty_rest_of_line ();
222 v850_offset (int ignore
)
224 int temp
= get_absolute_expression ();
226 temp
-= frag_now_fix();
229 (void) frag_more (temp
);
231 demand_empty_rest_of_line ();
235 set_machine (int number
)
238 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
242 case 0: processor_mask
= PROCESSOR_V850
; break;
243 /* start-sanitize-v850e */
244 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
245 /* end-sanitize-v850e */
246 /* start-sanitize-v850eq */
247 case bfd_mach_v850eq
: processor_mask
= PROCESSOR_V850EQ
; break;
248 /* end-sanitize-v850eq */
252 /* The target specific pseudo-ops which we support. */
253 const pseudo_typeS md_pseudo_table
[] =
255 {"sdata", v850_sdata
, 0},
256 {"tdata", v850_tdata
, 0},
257 {"zdata", v850_zdata
, 0},
258 {"sbss", v850_sbss
, 0},
259 {"tbss", v850_tbss
, 0},
260 {"zbss", v850_zbss
, 0},
261 {"rosdata", v850_rosdata
, 0},
262 {"rozdata", v850_rozdata
, 0},
263 {"bss", v850_bss
, 0},
264 {"offset", v850_offset
, 0},
265 {"section", v850_section
, 0},
267 {"v850", set_machine
, 0},
268 /* start-sanitize-v850e */
269 {"call_table_data", v850_call_table_data
, 0},
270 {"call_table_text", v850_call_table_text
, 0},
271 {"v850e", set_machine
, bfd_mach_v850e
},
272 /* end-sanitize-v850e */
273 /* start-sanitize-v850eq */
274 {"v850eq", set_machine
, bfd_mach_v850eq
},
275 /* end-sanitize-v850eq */
279 /* Opcode hash table. */
280 static struct hash_control
*v850_hash
;
282 /* This table is sorted. Suitable for searching by a binary search. */
283 static const struct reg_name pre_defined_registers
[] =
285 { "ep", 30 }, /* ep - element ptr */
286 { "gp", 4 }, /* gp - global ptr */
287 { "hp", 2 }, /* hp - handler stack ptr */
288 { "lp", 31 }, /* lp - link ptr */
321 { "sp", 3 }, /* sp - stack ptr */
322 { "tp", 5 }, /* tp - text ptr */
325 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
328 static const struct reg_name system_registers
[] =
330 /* start-sanitize-v850e */
336 /* end-sanitize-v850e */
344 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
346 static const struct reg_name cc_names
[] =
371 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
373 /* reg_name_search does a binary search of the given register table
374 to see if "name" is a valid regiter name. Returns the register
375 number from the array on success, or -1 on failure. */
378 reg_name_search (regs
, regcount
, name
)
379 const struct reg_name
* regs
;
383 int middle
, low
, high
;
391 middle
= (low
+ high
) / 2;
392 cmp
= strcasecmp (name
, regs
[middle
].name
);
398 return regs
[middle
].value
;
405 /* Summary of register_name().
407 * in: Input_line_pointer points to 1st char of operand.
409 * out: A expressionS.
410 * The operand may have been a register: in this case, X_op == O_register,
411 * X_add_number is set to the register number, and truth is returned.
412 * Input_line_pointer->(next non-blank) char after operand, or is in
413 * its original state.
416 register_name (expressionP
)
417 expressionS
* expressionP
;
424 /* Find the spelling of the operand */
425 start
= name
= input_line_pointer
;
427 c
= get_symbol_end ();
429 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
431 * input_line_pointer
= c
; /* put back the delimiting char */
433 /* look to see if it's in the register table */
436 expressionP
->X_op
= O_register
;
437 expressionP
->X_add_number
= reg_number
;
439 /* make the rest nice */
440 expressionP
->X_add_symbol
= NULL
;
441 expressionP
->X_op_symbol
= NULL
;
447 /* reset the line as if we had not done anything */
448 input_line_pointer
= start
;
454 /* Summary of system_register_name().
456 * in: Input_line_pointer points to 1st char of operand.
458 * out: A expressionS.
459 * The operand may have been a register: in this case, X_op == O_register,
460 * X_add_number is set to the register number, and truth is returned.
461 * Input_line_pointer->(next non-blank) char after operand, or is in
462 * its original state.
465 system_register_name (expressionP
, accept_numbers
)
466 expressionS
* expressionP
;
467 boolean accept_numbers
;
474 /* Find the spelling of the operand */
475 start
= name
= input_line_pointer
;
477 c
= get_symbol_end ();
478 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
);
480 * input_line_pointer
= c
; /* put back the delimiting char */
485 input_line_pointer
= start
; /* reset input_line pointer */
487 if (isdigit (* input_line_pointer
))
488 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
490 /* Make sure that the register number is allowable. */
493 /* start-sanitize-v850e */
496 /* end-sanitize-v850e */
503 /* look to see if it's in the register table */
506 expressionP
->X_op
= O_register
;
507 expressionP
->X_add_number
= reg_number
;
509 /* make the rest nice */
510 expressionP
->X_add_symbol
= NULL
;
511 expressionP
->X_op_symbol
= NULL
;
517 /* reset the line as if we had not done anything */
518 input_line_pointer
= start
;
524 /* Summary of cc_name().
526 * in: Input_line_pointer points to 1st char of operand.
528 * out: A expressionS.
529 * The operand may have been a register: in this case, X_op == O_register,
530 * X_add_number is set to the register number, and truth is returned.
531 * Input_line_pointer->(next non-blank) char after operand, or is in
532 * its original state.
535 cc_name (expressionP
)
536 expressionS
* expressionP
;
543 /* Find the spelling of the operand */
544 start
= name
= input_line_pointer
;
546 c
= get_symbol_end ();
547 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
);
549 * input_line_pointer
= c
; /* put back the delimiting char */
551 /* look to see if it's in the register table */
554 expressionP
->X_op
= O_constant
;
555 expressionP
->X_add_number
= reg_number
;
557 /* make the rest nice */
558 expressionP
->X_add_symbol
= NULL
;
559 expressionP
->X_op_symbol
= NULL
;
565 /* reset the line as if we had not done anything */
566 input_line_pointer
= start
;
573 skip_white_space (void)
575 while ( * input_line_pointer
== ' '
576 || * input_line_pointer
== '\t')
577 ++ input_line_pointer
;
580 /* start-sanitize-v850e */
581 /* Summary of parse_register_list ().
583 * in: Input_line_pointer points to 1st char of a list of registers.
584 * insn is the partially constructed instruction.
585 * operand is the operand being inserted.
587 * out: True if the parse completed successfully, False otherwise.
588 * If the parse completes the correct bit fields in the
589 * instruction will be filled in.
591 * Parses register lists with the syntax:
599 * and also parses constant epxressions whoes bits indicate the
600 * registers in the lists. The LSB in the expression refers to
601 * the lowest numbered permissable register in the register list,
602 * and so on upwards. System registers are considered to be very
609 unsigned long * insn
,
610 const struct v850_operand
* operand
613 static int type1_regs
[ 32 ] = { 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
614 /* start-sanitize-v850eq */
615 static int type2_regs
[ 32 ] = { 19, 18, 17, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 31, 29, 28, 23, 22, 21, 20, 27, 26, 25, 24 };
616 static int type3_regs
[ 32 ] = { 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 15, 13, 12, 7, 6, 5, 4, 11, 10, 9, 8 };
617 /* end-sanitize-v850eq */
622 /* Select a register array to parse. */
623 switch (operand
->shift
)
625 case 0xffe00001: regs
= type1_regs
; break;
626 /* start-sanitize-v850eq */
627 case 0xfff8000f: regs
= type2_regs
; break;
628 case 0xfff8001f: regs
= type3_regs
; break;
629 /* end-sanitize-v850eq */
631 as_bad ("unknown operand shift: %x\n", operand
->shift
);
632 return "internal failure in parse_register_list";
637 /* If the expression starts with a curly brace it is a register list.
638 Otherwise it is a constant expression ,whoes bits indicate which
639 registers are to be included in the list. */
641 if (* input_line_pointer
!= '{')
649 if (exp
.X_op
!= O_constant
)
650 return "constant expression or register list expected";
652 /* start-sanitize-v850eq */
653 if (regs
== type1_regs
)
654 /* end-sanitize-v850eq */
656 if (exp
.X_add_number
& 0xFFFFF000)
657 return "high bits set in register list expression";
659 for (reg
= 20; reg
< 32; reg
++)
660 if (exp
.X_add_number
& (1 << (reg
- 20)))
662 for (i
= 0; i
< 32; i
++)
667 /* start-sanitize-v850eq */
668 else if (regs
== type2_regs
)
670 if (exp
.X_add_number
& 0xFFFE0000)
671 return "high bits set in register list expression";
673 for (reg
= 1; reg
< 16; reg
++)
674 if (exp
.X_add_number
& (1 << (reg
- 1)))
676 for (i
= 0; i
< 32; i
++)
681 if (exp
.X_add_number
& (1 << 15))
684 if (exp
.X_add_number
& (1 << 16))
687 else /* regs == type3_regs */
689 if (exp
.X_add_number
& 0xFFFE0000)
690 return "high bits set in register list expression";
692 for (reg
= 16; reg
< 32; reg
++)
693 if (exp
.X_add_number
& (1 << (reg
- 16)))
695 for (i
= 0; i
< 32; i
++)
700 if (exp
.X_add_number
& (1 << 16))
703 /* end-sanitize-v850eq */
708 input_line_pointer
++;
710 /* Parse the register list until a terminator (closing curly brace or new-line) is found. */
713 if (register_name (& exp
))
717 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
718 for (i
= 0; i
< 32; i
++)
720 if (regs
[ i
] == exp
.X_add_number
)
729 return "illegal register included in list";
732 else if (system_register_name (& exp
, true))
734 if (regs
== type1_regs
)
736 return "system registers cannot be included in list";
738 else if (exp
.X_add_number
== 5)
740 if (regs
== type2_regs
)
741 return "PSW cannot be included in list";
748 else if (* input_line_pointer
== '}')
750 input_line_pointer
++;
753 else if (* input_line_pointer
== ',')
755 input_line_pointer
++;
758 else if (* input_line_pointer
== '-')
760 /* We have encountered a range of registers: rX - rY */
765 ++ input_line_pointer
;
767 /* Get the second register in the range. */
768 if (! register_name (& exp2
))
770 return "second register should follow dash in register list";
771 exp2
.X_add_number
= exp
.X_add_number
;
774 /* Add the rest of the registers in the range. */
775 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
779 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
780 for (i
= 0; i
< 32; i
++)
791 return "illegal register included in list";
805 /* end-sanitize-v850e */
807 CONST
char * md_shortopts
= "m:";
809 struct option md_longopts
[] =
811 {NULL
, no_argument
, NULL
, 0}
813 size_t md_longopts_size
= sizeof md_longopts
;
817 md_show_usage (stream
)
820 fprintf (stream
, "V850 options:\n");
821 fprintf (stream
, "\t-wsigned_overflow Warn if signed immediate values overflow\n");
822 fprintf (stream
, "\t-wunsigned_overflow Warn if unsigned immediate values overflow\n");
823 fprintf (stream
, "\t-mv850 The code is targeted at the v850\n");
824 /* start-sanitize-v850e */
825 fprintf (stream
, "\t-mv850e The code is targeted at the v850e\n");
826 /* end-sanitize-v850e */
827 /* start-sanitize-v850eq */
828 fprintf (stream
, "\t-mv850eq The code is targeted at the v850eq\n");
829 /* end-sanitize-v850eq */
833 md_parse_option (c
, arg
)
840 if (strcmp (arg
, "signed_overflow") == 0)
842 warn_signed_overflows
= TRUE
;
845 else if (strcmp (arg
, "unsigned_overflow") == 0)
847 warn_unsigned_overflows
= TRUE
;
853 if (strcmp (arg
, "v850") == 0)
856 processor_mask
= PROCESSOR_V850
;
859 /* start-sanitize-v850e */
860 else if (strcmp (arg
, "v850e") == 0)
862 machine
= bfd_mach_v850e
;
863 processor_mask
= PROCESSOR_V850E
;
867 /* end-sanitize-v850e */
868 /* start-sanitize-v850eq */
869 else if (strcmp (arg
, "v850eq") == 0)
871 machine
= bfd_mach_v850eq
;
872 processor_mask
= PROCESSOR_V850EQ
;
875 /* end-sanitize-v850eq */
883 md_undefined_symbol (name
)
890 md_atof (type
, litp
, sizep
)
896 LITTLENUM_TYPE words
[4];
912 return "bad call to md_atof";
915 t
= atof_ieee (input_line_pointer
, type
, words
);
917 input_line_pointer
= t
;
921 for (i
= prec
- 1; i
>= 0; i
--)
923 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
933 md_convert_frag (abfd
, sec
, fragP
)
938 subseg_change (sec
, 0);
939 if (fragP
->fr_subtype
== 0)
941 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
942 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
946 else if (fragP
->fr_subtype
== 1)
948 /* Reverse the condition of the first branch. */
949 fragP
->fr_literal
[0] &= 0xf7;
950 /* Mask off all the displacement bits. */
951 fragP
->fr_literal
[0] &= 0x8f;
952 fragP
->fr_literal
[1] &= 0x07;
953 /* Now set the displacement bits so that we branch
954 around the unconditional branch. */
955 fragP
->fr_literal
[0] |= 0x30;
957 /* Now create the unconditional branch + fixup to the final
959 md_number_to_chars (&fragP
->fr_literal
[2], 0x00000780, 4);
960 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
961 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
+ 1);
970 md_section_align (seg
, addr
)
974 int align
= bfd_get_section_alignment (stdoutput
, seg
);
975 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
981 char * prev_name
= "";
982 register const struct v850_opcode
* op
;
986 v850_hash
= hash_new();
988 /* Insert unique names into hash table. The V850 instruction set
989 has many identical opcode names that have different opcodes based
990 on the operands. This hash table then provides a quick index to
991 the first opcode with a particular name in the opcode table. */
996 if (strcmp (prev_name
, op
->name
))
998 prev_name
= (char *) op
->name
;
999 hash_insert (v850_hash
, op
->name
, (char *) op
);
1004 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1006 applicable
= bfd_applicable_section_flags (stdoutput
);
1008 sdata_section
= subseg_new (".sdata", 0);
1009 bfd_set_section_flags (stdoutput
, sdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1011 tdata_section
= subseg_new (".tdata", 0);
1012 bfd_set_section_flags (stdoutput
, tdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1014 zdata_section
= subseg_new (".zdata", 0);
1015 bfd_set_section_flags (stdoutput
, zdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1017 sbss_section
= subseg_new (".sbss", 0);
1018 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
& SEC_ALLOC
);
1020 tbss_section
= subseg_new (".tbss", 0);
1021 bfd_set_section_flags (stdoutput
, tbss_section
, applicable
& SEC_ALLOC
);
1023 zbss_section
= subseg_new (".zbss", 0);
1024 bfd_set_section_flags (stdoutput
, zbss_section
, applicable
& SEC_ALLOC
);
1026 rosdata_section
= subseg_new (".rosdata", 0);
1027 bfd_set_section_flags (stdoutput
, rosdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
));
1029 rozdata_section
= subseg_new (".rozdata", 0);
1030 bfd_set_section_flags (stdoutput
, rozdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
));
1032 /* start-sanitize-v850e */
1033 call_table_data_section
= subseg_new (".call_table_data", 0);
1034 bfd_set_section_flags (stdoutput
, call_table_data_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1036 call_table_text_section
= subseg_new (".call_table_text", 0);
1037 bfd_set_section_flags (stdoutput
, call_table_text_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
));
1038 /* end-sanitize-v850e */
1042 /* start-sanitize-v850e */
1043 static bfd_reloc_code_real_type
1044 handle_ctoff (const struct v850_operand
* operand
)
1046 if (operand
== NULL
)
1047 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1049 if ( operand
->bits
!= 6
1050 || operand
->shift
!= 0)
1052 as_bad ("ctoff() relocation used on an instruction which does not support it");
1053 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1056 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1058 /* end-sanitize-v850e */
1060 static bfd_reloc_code_real_type
1061 handle_sdaoff (const struct v850_operand
* operand
)
1063 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1064 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1065 /* start-sanitize-v850e */
1066 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1067 /* end-sanitize-v850e */
1069 if ( operand
->bits
!= 16
1070 || operand
->shift
!= 16)
1072 as_bad ("sdaoff() relocation used on an instruction which does not support it");
1073 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1076 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1079 static bfd_reloc_code_real_type
1080 handle_zdaoff (const struct v850_operand
* operand
)
1082 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1083 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1084 /* start-sanitize-v850e */
1085 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1086 /* end-sanitize-v850e */
1088 if ( operand
->bits
!= 16
1089 || operand
->shift
!= 16)
1091 as_bad ("zdaoff() relocation used on an instruction which does not support it");
1092 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1095 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1098 static bfd_reloc_code_real_type
1099 handle_tdaoff (const struct v850_operand
* operand
)
1101 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
; /* data item, not an instruction. */
1102 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
; /* sld.w/sst.w, operand: D8_6 */
1103 /* start-sanitize-v850e */
1104 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
; /* sld.hu, operand: D5-4 */
1105 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
; /* sld.bu, operand: D4 */
1106 /* end-sanitize-v850e */
1107 if (operand
->bits
== 16 && operand
->shift
== 16) return BFD_RELOC_V850_TDA_16_16_OFFSET
; /* set1 & chums, operands: D16 */
1109 if (operand
->bits
!= 7)
1111 as_bad ("tdaoff() relocation used on an instruction which does not support it");
1112 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1115 return operand
->insert
!= NULL
1116 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1117 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1120 /* Warning: The code in this function relies upon the definitions
1121 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1122 matching the hard coded values contained herein. */
1124 static bfd_reloc_code_real_type
1125 v850_reloc_prefix (const struct v850_operand
* operand
)
1127 boolean paren_skipped
= false;
1130 /* Skip leading opening parenthesis. */
1131 if (* input_line_pointer
== '(')
1133 ++ input_line_pointer
;
1134 paren_skipped
= true;
1137 #define CHECK_(name, reloc) \
1138 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1140 input_line_pointer += strlen (name); \
1144 CHECK_ ("hi0", BFD_RELOC_HI16
);
1145 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1146 CHECK_ ("lo", BFD_RELOC_LO16
);
1147 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1148 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1149 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1151 /* start-sanitize-v850e */
1152 CHECK_ ("hilo", BFD_RELOC_32
);
1153 CHECK_ ("ctoff", handle_ctoff (operand
));
1154 /* end-sanitize-v850e */
1156 /* Restore skipped parenthesis. */
1158 -- input_line_pointer
;
1160 return BFD_RELOC_UNUSED
;
1168 char * start_of_operands
;
1169 struct v850_opcode
* opcode
;
1170 struct v850_opcode
* next_opcode
;
1171 const unsigned char * opindex_ptr
;
1175 unsigned long insn_size
;
1179 boolean extra_data_after_insn
= false;
1180 unsigned extra_data_len
;
1181 unsigned long extra_data
;
1182 char * saved_input_line_pointer
;
1184 /* Get the opcode. */
1185 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1191 /* find the first opcode with the proper name */
1192 opcode
= (struct v850_opcode
*)hash_find (v850_hash
, str
);
1195 as_bad ("Unrecognized opcode: `%s'", str
);
1196 ignore_rest_of_line ();
1201 while (isspace (* str
))
1204 start_of_operands
= str
;
1206 saved_input_line_pointer
= input_line_pointer
;
1210 const char * errmsg
= NULL
;
1214 if ((opcode
->processors
& processor_mask
) == 0)
1216 errmsg
= "Target processor does not support this instruction.";
1223 insn
= opcode
->opcode
;
1224 extra_data_after_insn
= false;
1226 input_line_pointer
= str
= start_of_operands
;
1228 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1230 const struct v850_operand
* operand
;
1233 bfd_reloc_code_real_type reloc
;
1235 if (next_opindex
== 0)
1237 operand
= & v850_operands
[ * opindex_ptr
];
1241 operand
= & v850_operands
[ next_opindex
];
1247 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1250 if (operand
->flags
& V850_OPERAND_RELAX
)
1253 /* Gather the operand. */
1254 hold
= input_line_pointer
;
1255 input_line_pointer
= str
;
1257 /* lo(), hi(), hi0(), etc... */
1258 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1260 if (reloc
== BFD_RELOC_64
) /* This is a fake reloc, used to indicate an error condition. */
1268 if (ex
.X_op
== O_constant
)
1272 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1273 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]" and the like. */
1276 case BFD_RELOC_LO16
:
1278 /* Truncate, then sign extend the value. */
1279 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1283 case BFD_RELOC_HI16
:
1285 /* Truncate, then sign extend the value. */
1286 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1290 case BFD_RELOC_HI16_S
:
1292 /* Truncate, then sign extend the value. */
1293 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1295 temp
+= (ex
.X_add_number
>> 15) & 1;
1297 ex
.X_add_number
= SEXT16 (temp
);
1301 /* start-sanitize-v850e */
1303 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1305 errmsg
= "use bigger instruction";
1309 extra_data_after_insn
= true;
1311 extra_data
= ex
.X_add_number
;
1312 ex
.X_add_number
= 0;
1314 /* end-sanitize-v850e */
1317 fprintf (stderr
, "reloc: %d\n", reloc
);
1318 as_bad ("AAARG -> unhandled constant reloc");
1322 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1327 if (reloc
== BFD_RELOC_32
)
1329 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1331 errmsg
= "use bigger instruction";
1335 extra_data_after_insn
= true;
1337 extra_data
= ex
.X_add_number
;
1338 ex
.X_add_number
= 0;
1341 if (fc
> MAX_INSN_FIXUPS
)
1342 as_fatal ("too many fixups");
1344 fixups
[ fc
].exp
= ex
;
1345 fixups
[ fc
].opindex
= * opindex_ptr
;
1346 fixups
[ fc
].reloc
= reloc
;
1354 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1356 if (!register_name (& ex
))
1358 errmsg
= "invalid register name";
1361 if ((operand
->flags
& V850_NOT_R0
)
1362 && ex
.X_add_number
== 0)
1364 errmsg
= "register r0 cannot be used here";
1367 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1369 if (!system_register_name (& ex
, true))
1371 errmsg
= "invalid system register name";
1374 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1376 char * start
= input_line_pointer
;
1377 char c
= get_symbol_end ();
1379 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1381 /* Put things back the way we found them. */
1382 *input_line_pointer
= c
;
1383 input_line_pointer
= start
;
1384 errmsg
= "expected EP register";
1388 *input_line_pointer
= c
;
1389 str
= input_line_pointer
;
1390 input_line_pointer
= hold
;
1392 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1396 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1398 if (!cc_name (& ex
))
1400 errmsg
= "invalid condition code name";
1403 /* start-sanitize-v850e */
1404 else if (operand
->flags
& V850E_PUSH_POP
)
1406 errmsg
= parse_register_list (& insn
, operand
);
1408 /* The parse_register_list() function has already done everything, so fake a dummy expression. */
1409 ex
.X_op
= O_constant
;
1410 ex
.X_add_number
= 0;
1412 else if (operand
->flags
& V850E_IMMEDIATE16
)
1416 if (ex
.X_op
!= O_constant
)
1417 errmsg
= "constant expression expected";
1418 else if (ex
.X_add_number
& 0xffff0000)
1420 if (ex
.X_add_number
& 0xffff)
1421 errmsg
= "constant too big to fit into instruction";
1422 else if ((insn
& 0x001fffc0) == 0x00130780)
1423 ex
.X_add_number
>>= 16;
1425 errmsg
= "constant too big to fit into instruction";
1428 extra_data_after_insn
= true;
1430 extra_data
= ex
.X_add_number
;
1431 ex
.X_add_number
= 0;
1433 else if (operand
->flags
& V850E_IMMEDIATE32
)
1437 if (ex
.X_op
!= O_constant
)
1438 errmsg
= "constant expression expected";
1440 extra_data_after_insn
= true;
1442 extra_data
= ex
.X_add_number
;
1443 ex
.X_add_number
= 0;
1445 /* end-sanitize-v850e */
1446 else if (register_name (&ex
)
1447 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1449 errmsg
= "syntax error: register not expected";
1451 else if (system_register_name (& ex
, false)
1452 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1454 errmsg
= "syntax error: system register not expected";
1456 else if (cc_name (&ex
)
1457 && (operand
->flags
& V850_OPERAND_CC
) == 0)
1459 errmsg
= "syntax error: condition code not expected";
1464 /* start-sanitize-v850e */
1466 If we are assembling a MOV instruction (or a CALLT.... :-)
1467 and the immediate value does not fit into the bits available
1468 then create a fake error so that the next MOV instruction
1469 will be selected. This one has a 32 bit immediate field. */
1471 if (((insn
& 0x07e0) == 0x0200)
1472 && ex
.X_op
== O_constant
1473 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1))) || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
1474 errmsg
= "use bigger instruction";
1475 /* end-sanitize-v850e */
1481 /* fprintf (stderr, "insn: %x, operand %d, op: %d, add_number: %d\n", insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number ); */
1486 errmsg
= "illegal operand";
1489 errmsg
= "missing operand";
1492 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
1494 errmsg
= "invalid operand";
1497 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1502 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1507 /* We need to generate a fixup for this expression. */
1508 if (fc
>= MAX_INSN_FIXUPS
)
1509 as_fatal ("too many fixups");
1511 fixups
[ fc
].exp
= ex
;
1512 fixups
[ fc
].opindex
= * opindex_ptr
;
1513 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
1519 str
= input_line_pointer
;
1520 input_line_pointer
= hold
;
1522 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
1531 next_opcode
= opcode
+ 1;
1532 if (next_opcode
->name
!= NULL
&& strcmp (next_opcode
->name
, opcode
->name
) == 0)
1534 opcode
= next_opcode
;
1539 ignore_rest_of_line ();
1540 input_line_pointer
= saved_input_line_pointer
;
1546 while (isspace (*str
))
1550 as_bad ("junk at end of line: `%s'", str
);
1552 input_line_pointer
= str
;
1554 /* Write out the instruction.
1556 Four byte insns have an opcode with the two high bits on. */
1557 if (relaxable
&& fc
> 0)
1559 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
1560 fixups
[0].exp
.X_add_symbol
,
1561 fixups
[0].exp
.X_add_number
,
1562 (char *)fixups
[0].opindex
);
1564 md_number_to_chars (f
, insn
, insn_size
);
1565 md_number_to_chars (f
+ 2, 0, 4);
1570 if ((insn
& 0x0600) == 0x0600)
1575 /* start-sanitize-v850e */
1576 /* Special case: 32 bit MOV */
1577 if ((insn
& 0xffe0) == 0x0620)
1579 /* end-sanitize-v850e */
1581 f
= frag_more (insn_size
);
1583 md_number_to_chars (f
, insn
, insn_size
);
1585 if (extra_data_after_insn
)
1587 f
= frag_more (extra_data_len
);
1589 md_number_to_chars (f
, extra_data
, extra_data_len
);
1591 extra_data_after_insn
= false;
1595 /* Create any fixups. At this point we do not use a
1596 bfd_reloc_code_real_type, but instead just use the
1597 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1598 handle fixups for any operand type, although that is admittedly
1599 not a very exciting feature. We pick a BFD reloc type in
1601 for (i
= 0; i
< fc
; i
++)
1603 const struct v850_operand
* operand
;
1604 bfd_reloc_code_real_type reloc
;
1606 operand
= & v850_operands
[ fixups
[i
].opindex
];
1608 reloc
= fixups
[i
].reloc
;
1610 if (reloc
!= BFD_RELOC_UNUSED
)
1612 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1620 size
= bfd_get_reloc_size (reloc_howto
);
1622 if (size
!= 2 && size
!= 4) /* XXX this will abort on an R_V850_8 reloc - is this reloc actually used ? */
1625 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
1627 if (reloc
== BFD_RELOC_32
)
1632 fixP
= fix_new_exp (frag_now
, address
, size
,
1634 reloc_howto
->pc_relative
,
1639 case BFD_RELOC_LO16
:
1640 case BFD_RELOC_HI16
:
1641 case BFD_RELOC_HI16_S
:
1642 fixP
->fx_no_overflow
= 1;
1650 f
- frag_now
->fr_literal
, 4,
1652 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
1653 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)
1658 input_line_pointer
= saved_input_line_pointer
;
1662 /* If while processing a fixup, a reloc really needs to be created */
1663 /* then it is done here. */
1666 tc_gen_reloc (seg
, fixp
)
1672 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1673 reloc
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
1674 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1675 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1677 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1679 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1680 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
1687 reloc
->addend
= fixp
->fx_addnumber
;
1692 /* Assume everything will fit in two bytes, then expand as necessary. */
1694 md_estimate_size_before_relax (fragp
, seg
)
1703 md_pcrel_from (fixp
)
1706 /* If the symbol is undefined, or in a section other than our own,
1707 then let the linker figure it out. */
1708 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
1710 /* The symbol is undefined. Let the linker figure it out. */
1713 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1717 md_apply_fix3 (fixp
, valuep
, seg
)
1725 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
1730 else if (fixp
->fx_pcrel
)
1734 value
= fixp
->fx_offset
;
1735 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
1737 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
1738 value
-= S_GET_VALUE (fixp
->fx_subsy
);
1741 /* We don't actually support subtracting a symbol. */
1742 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1743 "expression too complex");
1748 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1751 const struct v850_operand
* operand
;
1754 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1755 operand
= & v850_operands
[ opindex
];
1757 /* Fetch the instruction, insert the fully resolved operand
1758 value, and stuff the instruction back again.
1760 Note the instruction has been stored in little endian
1762 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1764 insn
= bfd_getl32 ((unsigned char *) where
);
1765 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
1766 fixp
->fx_file
, fixp
->fx_line
);
1767 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
1771 /* Nothing else to do here. */
1775 /* Determine a BFD reloc value based on the operand information.
1776 We are only prepared to turn a few of the operands into relocs. */
1778 if (operand
->bits
== 22)
1779 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
1780 else if (operand
->bits
== 9)
1781 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
1784 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
1786 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
1787 "unresolved expression that must be resolved");
1792 else if (fixp
->fx_done
)
1794 /* We still have to insert the value into memory! */
1795 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1796 if (fixp
->fx_size
== 1)
1797 *where
= value
& 0xff;
1798 else if (fixp
->fx_size
== 2)
1799 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
1800 else if (fixp
->fx_size
== 4)
1801 bfd_putl32 (value
, (unsigned char *) where
);
1804 fixp
->fx_addnumber
= value
;
1809 /* Insert an operand value into an instruction. */
1811 static unsigned long
1812 v850_insert_operand (insn
, operand
, val
, file
, line
)
1814 const struct v850_operand
* operand
;
1819 if (operand
->insert
)
1821 const char * message
= NULL
;
1823 insn
= (*operand
->insert
) (insn
, val
, & message
);
1824 if (message
!= NULL
)
1826 if (file
== (char *) NULL
)
1829 as_warn_where (file
, line
, message
);
1834 if (operand
->bits
!= 32)
1839 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1841 if (! warn_signed_overflows
)
1842 max
= (1 << operand
->bits
) - 1;
1844 max
= (1 << (operand
->bits
- 1)) - 1;
1846 min
= - (1 << (operand
->bits
- 1));
1850 max
= (1 << operand
->bits
) - 1;
1852 if (! warn_unsigned_overflows
)
1853 min
= - (1 << (operand
->bits
- 1));
1860 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1862 const char * err
= "operand out of range (%s not between %ld and %ld)";
1865 sprint_value (buf
, test
);
1866 if (file
== (char *) NULL
)
1867 as_warn (err
, buf
, min
, max
);
1869 as_warn_where (file
, line
, err
, buf
, min
, max
);
1873 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1879 /* Parse a cons expression. We have to handle hi(), lo(), etc
1882 parse_cons_expression_v850 (exp
)
1885 /* See if there's a reloc prefix like hi() we have to handle. */
1886 hold_cons_reloc
= v850_reloc_prefix (NULL
);
1888 /* Do normal expression parsing. */
1892 /* Create a fixup for a cons expression. If parse_cons_expression_v850
1893 found a reloc prefix, then we use that reloc, else we choose an
1894 appropriate one based on the size of the expression. */
1896 cons_fix_new_v850 (frag
, where
, size
, exp
)
1902 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
1905 hold_cons_reloc
= BFD_RELOC_32
;
1907 hold_cons_reloc
= BFD_RELOC_16
;
1909 hold_cons_reloc
= BFD_RELOC_8
;
1913 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
1915 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);