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 processor type. */
38 static int machine
= TARGET_MACHINE
;
41 /* Structure to hold information about predefined registers. */
48 /* Generic assembler global variables which must be defined by all targets. */
50 /* Characters which always start a comment. */
51 const char comment_chars
[] = "#";
53 /* Characters which start a comment at the beginning of a line. */
54 const char line_comment_chars
[] = ";#";
56 /* Characters which may be used to separate multiple commands on a
58 const char line_separator_chars
[] = ";";
60 /* Characters which are used to indicate an exponent in a floating
62 const char EXP_CHARS
[] = "eE";
64 /* Characters which mean that a number is a floating point constant,
66 const char FLT_CHARS
[] = "dD";
69 const relax_typeS md_relax_table
[] = {
71 {0x1fffff, -0x200000, 6, 0},
75 static segT sdata_section
= NULL
;
76 static segT tdata_section
= NULL
;
77 static segT zdata_section
= NULL
;
78 static segT sbss_section
= NULL
;
79 static segT tbss_section
= NULL
;
80 static segT zbss_section
= NULL
;
81 static segT rosdata_section
= NULL
;
82 static segT rozdata_section
= NULL
;
86 static unsigned long v850_insert_operand
87 PARAMS ((unsigned long insn
, const struct v850_operand
*operand
,
88 offsetT val
, char *file
, unsigned int line
));
92 #define MAX_INSN_FIXUPS (5)
97 bfd_reloc_code_real_type reloc
;
99 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
103 v850_sdata (int ignore
)
105 subseg_set (sdata_section
, (subsegT
) get_absolute_expression ());
107 demand_empty_rest_of_line ();
111 v850_tdata (int ignore
)
113 subseg_set (tdata_section
, (subsegT
) get_absolute_expression ());
115 demand_empty_rest_of_line ();
119 v850_zdata (int ignore
)
121 subseg_set (zdata_section
, (subsegT
) get_absolute_expression ());
123 demand_empty_rest_of_line ();
127 v850_sbss (int ignore
)
129 subseg_set (sbss_section
, (subsegT
) get_absolute_expression ());
131 demand_empty_rest_of_line ();
135 v850_tbss (int ignore
)
137 subseg_set (tbss_section
, (subsegT
) get_absolute_expression ());
139 demand_empty_rest_of_line ();
143 v850_zbss (int ignore
)
145 subseg_set (zbss_section
, (subsegT
) get_absolute_expression ());
147 demand_empty_rest_of_line ();
151 v850_rosdata (int ignore
)
153 subseg_set (rosdata_section
, (subsegT
) get_absolute_expression ());
155 demand_empty_rest_of_line ();
159 v850_rozdata (int ignore
)
161 subseg_set (rozdata_section
, (subsegT
) get_absolute_expression ());
163 demand_empty_rest_of_line ();
167 v850_section (int arg
)
172 for (ptr
= input_line_pointer
; * ptr
!= '\n' && * ptr
!= 0; ptr
++)
173 if (* ptr
== ',' && ptr
[1] == '.')
179 obj_elf_section (arg
);
185 v850_bss (int ignore
)
187 register int temp
= get_absolute_expression ();
189 obj_elf_section_change_hook();
191 subseg_set (bss_section
, (subsegT
) temp
);
193 demand_empty_rest_of_line ();
197 v850_offset (int ignore
)
199 int temp
= get_absolute_expression ();
201 temp
-= frag_now_fix();
204 (void) frag_more (temp
);
206 demand_empty_rest_of_line ();
210 set_machine (int number
)
213 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
216 /* The target specific pseudo-ops which we support. */
217 const pseudo_typeS md_pseudo_table
[] =
219 {"sdata", v850_sdata
, 0},
220 {"tdata", v850_tdata
, 0},
221 {"zdata", v850_zdata
, 0},
222 {"sbss", v850_sbss
, 0},
223 {"tbss", v850_tbss
, 0},
224 {"zbss", v850_zbss
, 0},
225 {"rosdata", v850_rosdata
, 0},
226 {"rozdata", v850_rozdata
, 0},
227 {"bss", v850_bss
, 0},
228 {"offset", v850_offset
, 0},
229 {"section", v850_section
, 0},
231 {"v850", set_machine
, 0},
232 /* start-sanitize-v850e */
233 {"v850e", set_machine
, bfd_mach_v850e
},
234 /* end-sanitize-v850e */
235 /* start-sanitize-v850eq */
236 {"v850eq", set_machine
, bfd_mach_v850eq
},
237 /* end-sanitize-v850eq */
241 /* Opcode hash table. */
242 static struct hash_control
*v850_hash
;
244 /* This table is sorted. Suitable for searching by a binary search. */
245 static const struct reg_name pre_defined_registers
[] =
247 { "ep", 30 }, /* ep - element ptr */
248 { "gp", 4 }, /* gp - global ptr */
249 { "hp", 2 }, /* hp - handler stack ptr */
250 { "lp", 31 }, /* lp - link ptr */
283 { "sp", 3 }, /* sp - stack ptr */
284 { "tp", 5 }, /* tp - text ptr */
287 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
290 static const struct reg_name system_registers
[] =
292 /* start-sanitize-v850e */
298 /* end-sanitize-v850e */
306 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
308 static const struct reg_name cc_names
[] =
333 #define CC_NAME_CNT (sizeof(cc_names) / sizeof(struct reg_name))
335 /* reg_name_search does a binary search of the given register table
336 to see if "name" is a valid regiter name. Returns the register
337 number from the array on success, or -1 on failure. */
340 reg_name_search (regs
, regcount
, name
)
341 const struct reg_name
* regs
;
345 int middle
, low
, high
;
353 middle
= (low
+ high
) / 2;
354 cmp
= strcasecmp (name
, regs
[middle
].name
);
360 return regs
[middle
].value
;
367 /* Summary of register_name().
369 * in: Input_line_pointer points to 1st char of operand.
371 * out: A expressionS.
372 * The operand may have been a register: in this case, X_op == O_register,
373 * X_add_number is set to the register number, and truth is returned.
374 * Input_line_pointer->(next non-blank) char after operand, or is in
375 * its original state.
378 register_name (expressionP
)
379 expressionS
* expressionP
;
386 /* Find the spelling of the operand */
387 start
= name
= input_line_pointer
;
389 c
= get_symbol_end ();
391 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
393 * input_line_pointer
= c
; /* put back the delimiting char */
395 /* look to see if it's in the register table */
398 expressionP
->X_op
= O_register
;
399 expressionP
->X_add_number
= reg_number
;
401 /* make the rest nice */
402 expressionP
->X_add_symbol
= NULL
;
403 expressionP
->X_op_symbol
= NULL
;
409 /* reset the line as if we had not done anything */
410 input_line_pointer
= start
;
416 /* Summary of system_register_name().
418 * in: Input_line_pointer points to 1st char of operand.
420 * out: A expressionS.
421 * The operand may have been a register: in this case, X_op == O_register,
422 * X_add_number is set to the register number, and truth is returned.
423 * Input_line_pointer->(next non-blank) char after operand, or is in
424 * its original state.
427 system_register_name (expressionP
, accept_numbers
)
428 expressionS
* expressionP
;
429 boolean accept_numbers
;
436 /* Find the spelling of the operand */
437 start
= name
= input_line_pointer
;
439 c
= get_symbol_end ();
440 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
);
442 * input_line_pointer
= c
; /* put back the delimiting char */
447 input_line_pointer
= start
; /* reset input_line pointer */
449 if (isdigit (* input_line_pointer
))
450 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
452 /* Make sure that the register number is allowable. */
455 /* start-sanitize-v850e */
458 /* end-sanitize-v850e */
465 /* look to see if it's in the register table */
468 expressionP
->X_op
= O_register
;
469 expressionP
->X_add_number
= reg_number
;
471 /* make the rest nice */
472 expressionP
->X_add_symbol
= NULL
;
473 expressionP
->X_op_symbol
= NULL
;
479 /* reset the line as if we had not done anything */
480 input_line_pointer
= start
;
486 /* Summary of cc_name().
488 * in: Input_line_pointer points to 1st char of operand.
490 * out: A expressionS.
491 * The operand may have been a register: in this case, X_op == O_register,
492 * X_add_number is set to the register number, and truth is returned.
493 * Input_line_pointer->(next non-blank) char after operand, or is in
494 * its original state.
497 cc_name (expressionP
)
498 expressionS
*expressionP
;
505 /* Find the spelling of the operand */
506 start
= name
= input_line_pointer
;
508 c
= get_symbol_end ();
509 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
);
511 * input_line_pointer
= c
; /* put back the delimiting char */
513 /* look to see if it's in the register table */
516 expressionP
->X_op
= O_constant
;
517 expressionP
->X_add_number
= reg_number
;
519 /* make the rest nice */
520 expressionP
->X_add_symbol
= NULL
;
521 expressionP
->X_op_symbol
= NULL
;
527 /* reset the line as if we had not done anything */
528 input_line_pointer
= start
;
535 skip_white_space (void)
537 while ( * input_line_pointer
== ' '
538 || * input_line_pointer
== '\t')
539 ++ input_line_pointer
;
542 /* start-sanitize-v850e */
543 /* Summary of parse_register_list ().
545 * in: Input_line_pointer points to 1st char of a list of registers.
546 * insn is the partially constructed instruction.
547 * operand is the operand being inserted.
549 * out: True if the parse completed successfully, False otherwise.
550 * If the parse completes the correct bit fields in the
551 * instruction will be filled in.
553 * Parses register lists with the syntax:
561 * and also parses constant epxressions whoes bits indicate the
562 * registers in the lists. The LSB in the expression refers to
563 * the lowest numbered permissable register in the register list,
564 * and so on upwards. System registers are considered to be very
571 unsigned long * insn
,
572 const struct v850_operand
* operand
575 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 };
576 /* start-sanitize-v850eq */
577 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 };
578 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 };
579 /* end-sanitize-v850eq */
584 /* Select a register array to parse. */
585 switch (operand
->shift
)
587 case 0xffe00001: regs
= type1_regs
; break;
588 /* start-sanitize-v850eq */
589 case 0xfff8000f: regs
= type2_regs
; break;
590 case 0xfff8001f: regs
= type3_regs
; break;
591 /* end-sanitize-v850eq */
593 as_bad ("unknown operand shift: %x\n", operand
->shift
);
594 return "internal failure in parse_register_list";
599 /* If the expression starts with a curly brace it is a register list.
600 Otherwise it is a constant expression ,whoes bits indicate which
601 registers are to be included in the list. */
603 if (* input_line_pointer
!= '{')
611 if (exp
.X_op
!= O_constant
)
612 return "constant expression or register list expected";
614 /* start-sanitize-v850eq */
615 if (regs
== type1_regs
)
616 /* end-sanitize-v850eq */
618 if (exp
.X_add_number
& 0xFFFFF000)
619 return "high bits set in register list expression";
621 for (reg
= 20; reg
< 32; reg
++)
622 if (exp
.X_add_number
& (1 << (reg
- 20)))
624 for (i
= 0; i
< 32; i
++)
629 /* start-sanitize-v850eq */
630 else if (regs
== type2_regs
)
632 if (exp
.X_add_number
& 0xFFFE0000)
633 return "high bits set in register list expression";
635 for (reg
= 1; reg
< 16; reg
++)
636 if (exp
.X_add_number
& (1 << (reg
- 1)))
638 for (i
= 0; i
< 32; i
++)
643 if (exp
.X_add_number
& (1 << 15))
646 if (exp
.X_add_number
& (1 << 16))
649 else /* regs == type3_regs */
651 if (exp
.X_add_number
& 0xFFFE0000)
652 return "high bits set in register list expression";
654 for (reg
= 16; reg
< 32; reg
++)
655 if (exp
.X_add_number
& (1 << (reg
- 16)))
657 for (i
= 0; i
< 32; i
++)
662 if (exp
.X_add_number
& (1 << 16))
665 /* end-sanitize-v850eq */
670 input_line_pointer
++;
672 /* Parse the register list until a terminator (closing curly brace or new-line) is found. */
675 if (register_name (& exp
))
679 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
680 for (i
= 0; i
< 32; i
++)
682 if (regs
[ i
] == exp
.X_add_number
)
691 return "illegal register included in list";
694 else if (system_register_name (& exp
, true))
696 if (regs
== type1_regs
)
698 return "system registers cannot be included in list";
700 else if (exp
.X_add_number
== 5)
702 if (regs
== type2_regs
)
703 return "PSW cannot be included in list";
710 else if (* input_line_pointer
== '}')
712 input_line_pointer
++;
715 else if (* input_line_pointer
== ',')
717 input_line_pointer
++;
720 else if (* input_line_pointer
== '-')
722 /* We have encountered a range of registers: rX - rY */
727 ++ input_line_pointer
;
729 /* Get the second register in the range. */
730 if (! register_name (& exp2
))
732 return "second register should follow dash in register list";
733 exp2
.X_add_number
= exp
.X_add_number
;
736 /* Add the rest of the registers in the range. */
737 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
741 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
742 for (i
= 0; i
< 32; i
++)
753 return "illegal register included in list";
767 /* end-sanitize-v850e */
769 CONST
char * md_shortopts
= "m:";
771 struct option md_longopts
[] =
773 {NULL
, no_argument
, NULL
, 0}
775 size_t md_longopts_size
= sizeof md_longopts
;
779 md_show_usage (stream
)
782 fprintf (stream
, "V850 options:\n");
783 fprintf (stream
, "\t-wsigned_overflow Warn if signed immediate values overflow\n");
784 fprintf (stream
, "\t-wunsigned_overflow Warn if unsigned immediate values overflow\n");
785 fprintf (stream
, "\t-mv850 The code is targeted at the v850\n");
786 /* start-sanitize-v850e */
787 fprintf (stream
, "\t-mv850e The code is targeted at the v850e\n");
788 /* end-sanitize-v850e */
789 /* start-sanitize-v850eq */
790 fprintf (stream
, "\t-mv850eq The code is targeted at the v850eq\n");
791 /* end-sanitize-v850eq */
795 md_parse_option (c
, arg
)
802 if (strcmp (arg
, "signed_overflow") == 0)
804 warn_signed_overflows
= TRUE
;
807 else if (strcmp (arg
, "unsigned_overflow") == 0)
809 warn_unsigned_overflows
= TRUE
;
815 if (strcmp (arg
, "v850") == 0)
820 /* start-sanitize-v850e */
821 else if (strcmp (arg
, "v850e") == 0)
823 machine
= bfd_mach_v850e
;
826 /* end-sanitize-v850e */
827 /* start-sanitize-v850eq */
828 else if (strcmp (arg
, "v850eq") == 0)
830 machine
= bfd_mach_v850eq
;
833 /* end-sanitize-v850eq */
841 md_undefined_symbol (name
)
848 md_atof (type
, litp
, sizep
)
854 LITTLENUM_TYPE words
[4];
870 return "bad call to md_atof";
873 t
= atof_ieee (input_line_pointer
, type
, words
);
875 input_line_pointer
= t
;
879 for (i
= prec
- 1; i
>= 0; i
--)
881 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
891 md_convert_frag (abfd
, sec
, fragP
)
896 subseg_change (sec
, 0);
897 if (fragP
->fr_subtype
== 0)
899 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
900 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
904 else if (fragP
->fr_subtype
== 1)
906 /* Reverse the condition of the first branch. */
907 fragP
->fr_literal
[0] &= 0xf7;
908 /* Mask off all the displacement bits. */
909 fragP
->fr_literal
[0] &= 0x8f;
910 fragP
->fr_literal
[1] &= 0x07;
911 /* Now set the displacement bits so that we branch
912 around the unconditional branch. */
913 fragP
->fr_literal
[0] |= 0x30;
915 /* Now create the unconditional branch + fixup to the final
917 md_number_to_chars (&fragP
->fr_literal
[2], 0x00000780, 4);
918 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
919 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
+ 1);
928 md_section_align (seg
, addr
)
932 int align
= bfd_get_section_alignment (stdoutput
, seg
);
933 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
939 char * prev_name
= "";
940 register const struct v850_opcode
* op
;
944 v850_hash
= hash_new();
946 /* Insert unique names into hash table. The V850 instruction set
947 has many identical opcode names that have different opcodes based
948 on the operands. This hash table then provides a quick index to
949 the first opcode with a particular name in the opcode table. */
954 if (strcmp (prev_name
, op
->name
))
956 prev_name
= (char *) op
->name
;
957 hash_insert (v850_hash
, op
->name
, (char *) op
);
962 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
964 applicable
= bfd_applicable_section_flags (stdoutput
);
966 sdata_section
= subseg_new (".sdata", 0);
967 bfd_set_section_flags (stdoutput
, sdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
969 tdata_section
= subseg_new (".tdata", 0);
970 bfd_set_section_flags (stdoutput
, tdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
972 zdata_section
= subseg_new (".zdata", 0);
973 bfd_set_section_flags (stdoutput
, zdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
975 sbss_section
= subseg_new (".sbss", 0);
976 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
& SEC_ALLOC
);
978 tbss_section
= subseg_new (".tbss", 0);
979 bfd_set_section_flags (stdoutput
, tbss_section
, applicable
& SEC_ALLOC
);
981 zbss_section
= subseg_new (".zbss", 0);
982 bfd_set_section_flags (stdoutput
, zbss_section
, applicable
& SEC_ALLOC
);
984 rosdata_section
= subseg_new (".rosdata", 0);
985 bfd_set_section_flags (stdoutput
, rosdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
));
987 rozdata_section
= subseg_new (".rozdata", 0);
988 bfd_set_section_flags (stdoutput
, rozdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
));
992 /* Warning: The code in this function relies upon the definitions
993 in the v850_operands[] array (defined in opcodes/v850-opc.c)
994 matching the hard coded values conatined herein. */
996 static bfd_reloc_code_real_type
997 v850_reloc_prefix (const struct v850_operand
* operand
)
999 boolean paren_skipped
= false;
1002 /* Skip leading opening parenthesis. */
1003 if (* input_line_pointer
== '(')
1005 ++ input_line_pointer
;
1006 paren_skipped
= true;
1009 if (strncmp (input_line_pointer
, "hi0(", 4) == 0)
1011 input_line_pointer
+= 3;
1012 return BFD_RELOC_HI16
;
1014 if (strncmp (input_line_pointer
, "hi(", 3) == 0)
1016 input_line_pointer
+= 2;
1017 return BFD_RELOC_HI16_S
;
1019 if (strncmp (input_line_pointer
, "lo(", 3) == 0)
1021 input_line_pointer
+= 2;
1022 return BFD_RELOC_LO16
;
1025 if (strncmp (input_line_pointer
, "sdaoff(", 7) == 0)
1027 input_line_pointer
+= 6;
1029 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1030 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1031 /* start-sanitize-v850e */
1032 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1033 /* end-sanitize-v850e */
1035 assert (operand
->bits
== 16);
1036 assert (operand
->shift
== 16);
1038 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1041 if (strncmp (input_line_pointer
, "zdaoff(", 7) == 0)
1043 input_line_pointer
+= 6;
1045 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1046 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1047 /* start-sanitize-v850e */
1048 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1049 /* end-sanitize-v850e */
1051 assert (operand
->bits
== 16);
1052 assert (operand
->shift
== 16);
1054 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1057 if (strncmp (input_line_pointer
, "tdaoff(", 7) == 0)
1059 input_line_pointer
+= 6;
1061 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
;
1062 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
;
1063 /* start-sanitize-v850e */
1064 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
;
1065 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
;
1066 /* end-sanitize-v850e */
1068 assert (operand
->bits
== 7);
1070 return operand
->insert
!= NULL
? BFD_RELOC_V850_TDA_7_8_OFFSET
: BFD_RELOC_V850_TDA_7_7_OFFSET
;
1074 /* Restore skipped character. */
1075 -- input_line_pointer
;
1077 return BFD_RELOC_UNUSED
;
1085 char * start_of_operands
;
1086 struct v850_opcode
* opcode
;
1087 struct v850_opcode
* next_opcode
;
1088 const unsigned char * opindex_ptr
;
1092 unsigned long insn_size
;
1096 boolean extra_data_after_insn
= false;
1097 unsigned extra_data_len
;
1098 unsigned long extra_data
;
1099 char * saved_input_line_pointer
;
1101 /* Get the opcode. */
1102 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1108 /* find the first opcode with the proper name */
1109 opcode
= (struct v850_opcode
*)hash_find (v850_hash
, str
);
1112 as_bad ("Unrecognized opcode: `%s'", str
);
1113 ignore_rest_of_line ();
1118 while (isspace (* str
))
1121 start_of_operands
= str
;
1123 saved_input_line_pointer
= input_line_pointer
;
1127 const char * errmsg
= NULL
;
1133 insn
= opcode
->opcode
;
1134 extra_data_after_insn
= false;
1136 input_line_pointer
= str
= start_of_operands
;
1138 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1140 const struct v850_operand
* operand
;
1143 bfd_reloc_code_real_type reloc
;
1145 if (next_opindex
== 0)
1147 operand
= & v850_operands
[ * opindex_ptr
];
1151 operand
= & v850_operands
[ next_opindex
];
1157 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1160 if (operand
->flags
& V850_OPERAND_RELAX
)
1163 /* Gather the operand. */
1164 hold
= input_line_pointer
;
1165 input_line_pointer
= str
;
1167 /* fprintf (stderr, "operand: %s index = %d, opcode = %s\n", input_line_pointer, opindex_ptr - opcode->operands, opcode->name ); */
1169 /* lo(), hi(), hi0(), etc... */
1170 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1174 if (ex
.X_op
== O_constant
)
1178 case BFD_RELOC_LO16
:
1180 /* Truncate, then sign extend the value. */
1181 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1185 case BFD_RELOC_HI16
:
1187 /* Truncate, then sign extend the value. */
1188 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1192 case BFD_RELOC_HI16_S
:
1194 /* Truncate, then sign extend the value. */
1195 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1197 temp
+= (ex
.X_add_number
>> 15) & 1;
1199 ex
.X_add_number
= SEXT16 (temp
);
1204 as_bad ( "AAARG -> unhandled constant reloc");
1208 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1213 if (fc
> MAX_INSN_FIXUPS
)
1214 as_fatal ("too many fixups");
1216 fixups
[ fc
].exp
= ex
;
1217 fixups
[ fc
].opindex
= * opindex_ptr
;
1218 fixups
[ fc
].reloc
= reloc
;
1226 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1228 if (!register_name (& ex
))
1230 errmsg
= "invalid register name";
1233 if ((operand
->flags
& V850_NOT_R0
)
1234 && ex
.X_add_number
== 0)
1236 errmsg
= "register r0 cannot be used here";
1239 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1241 if (!system_register_name (& ex
, true))
1243 errmsg
= "invalid system register name";
1246 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1248 char * start
= input_line_pointer
;
1249 char c
= get_symbol_end ();
1251 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1253 /* Put things back the way we found them. */
1254 *input_line_pointer
= c
;
1255 input_line_pointer
= start
;
1256 errmsg
= "expected EP register";
1260 *input_line_pointer
= c
;
1261 str
= input_line_pointer
;
1262 input_line_pointer
= hold
;
1264 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1268 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1270 if (!cc_name (& ex
))
1272 errmsg
= "invalid condition code name";
1275 /* start-sanitize-v850e */
1276 else if (operand
->flags
& V850E_PUSH_POP
)
1278 errmsg
= parse_register_list (& insn
, operand
);
1280 /* The parse_register_list() function has already done everything, so fake a dummy expression. */
1281 ex
.X_op
= O_constant
;
1282 ex
.X_add_number
= 0;
1284 /* end-sanitize-v850e */
1285 /* start-sanitize-v850e */
1286 else if (operand
->flags
& V850E_IMMEDIATE16
)
1290 if (ex
.X_op
!= O_constant
)
1291 errmsg
= "constant expression expected";
1292 else if (ex
.X_add_number
& 0xffff0000)
1294 if (ex
.X_add_number
& 0xffff)
1295 errmsg
= "constant too big to fit into instruction";
1296 else if ((insn
& 0x001fffc0) == 0x00130780)
1297 ex
.X_add_number
>>= 16;
1299 errmsg
= "constant too big to fit into instruction";
1302 extra_data_after_insn
= true;
1304 extra_data
= ex
.X_add_number
;
1305 ex
.X_add_number
= 0;
1307 /* end-sanitize-v850e */
1308 /* start-sanitize-v850e */
1309 else if (operand
->flags
& V850E_IMMEDIATE32
)
1313 if (ex
.X_op
!= O_constant
)
1314 errmsg
= "constant expression expected";
1316 extra_data_after_insn
= true;
1318 extra_data
= ex
.X_add_number
;
1319 ex
.X_add_number
= 0;
1321 /* end-sanitize-v850e */
1322 else if (register_name (&ex
)
1323 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1325 errmsg
= "syntax error: register not expected";
1327 else if (system_register_name (& ex
, false)
1328 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1330 errmsg
= "syntax error: system register not expected";
1332 else if (cc_name (&ex
)
1333 && (operand
->flags
& V850_OPERAND_CC
) == 0)
1335 errmsg
= "syntax error: condition code not expected";
1340 /* start-sanitize-v850e */
1342 If we are assembling a MOV instruction (or a CALLT.... :-)
1343 and the immediate value does not fit into the bits available
1344 then create a fake error so that the next MOV instruction
1345 will be selected. This one has a 32 bit immediate field. */
1347 if (((insn
& 0x07e0) == 0x0200)
1348 && ex
.X_op
== O_constant
1349 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1))) || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
1350 errmsg
= "use bigger instruction";
1351 /* end-sanitize-v850e */
1357 /* fprintf (stderr, "insn: %x, operand %d, op: %d, add_number: %d\n", insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number ); */
1362 errmsg
= "illegal operand";
1365 errmsg
= "missing operand";
1368 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
1370 errmsg
= "invalid operand";
1373 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1378 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1383 /* We need to generate a fixup for this expression. */
1384 if (fc
>= MAX_INSN_FIXUPS
)
1385 as_fatal ("too many fixups");
1387 fixups
[ fc
].exp
= ex
;
1388 fixups
[ fc
].opindex
= * opindex_ptr
;
1389 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
1395 str
= input_line_pointer
;
1396 input_line_pointer
= hold
;
1398 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
1407 next_opcode
= opcode
+ 1;
1408 if (next_opcode
->name
!= NULL
&& strcmp (next_opcode
->name
, opcode
->name
) == 0)
1410 opcode
= next_opcode
;
1415 ignore_rest_of_line ();
1416 input_line_pointer
= saved_input_line_pointer
;
1422 while (isspace (*str
))
1426 as_bad ("junk at end of line: `%s'", str
);
1428 input_line_pointer
= str
;
1430 /* Write out the instruction.
1432 Four byte insns have an opcode with the two high bits on. */
1433 if (relaxable
&& fc
> 0)
1435 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
1436 fixups
[0].exp
.X_add_symbol
,
1437 fixups
[0].exp
.X_add_number
,
1438 (char *)fixups
[0].opindex
);
1440 md_number_to_chars (f
, insn
, insn_size
);
1441 md_number_to_chars (f
+ 2, 0, 4);
1446 if ((insn
& 0x0600) == 0x0600)
1451 /* start-sanitize-v850e */
1452 /* Special case: 32 bit MOV */
1453 if ((insn
& 0xffe0) == 0x0620)
1455 /* end_sanitize-v850e */
1457 f
= frag_more (insn_size
);
1459 md_number_to_chars (f
, insn
, insn_size
);
1461 if (extra_data_after_insn
)
1463 char * g
= frag_more (extra_data_len
);
1465 md_number_to_chars (g
, extra_data
, extra_data_len
);
1467 extra_data_after_insn
= false;
1471 /* Create any fixups. At this point we do not use a
1472 bfd_reloc_code_real_type, but instead just use the
1473 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1474 handle fixups for any operand type, although that is admittedly
1475 not a very exciting feature. We pick a BFD reloc type in
1477 for (i
= 0; i
< fc
; i
++)
1479 const struct v850_operand
* operand
;
1481 operand
= & v850_operands
[ fixups
[i
].opindex
];
1483 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1485 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1493 size
= bfd_get_reloc_size (reloc_howto
);
1495 if (size
!= 2 && size
!= 4) /* XXX this will abort on an R_V850_8 reloc - is this reloc actually used ? */
1498 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
1500 fixP
= fix_new_exp (frag_now
, address
, size
,
1502 reloc_howto
->pc_relative
,
1505 switch (fixups
[i
].reloc
)
1507 case BFD_RELOC_LO16
:
1508 case BFD_RELOC_HI16
:
1509 case BFD_RELOC_HI16_S
:
1510 fixP
->fx_no_overflow
= 1;
1518 f
- frag_now
->fr_literal
, 4,
1520 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
1521 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)
1526 input_line_pointer
= saved_input_line_pointer
;
1530 /* If while processing a fixup, a reloc really needs to be created */
1531 /* then it is done here. */
1534 tc_gen_reloc (seg
, fixp
)
1540 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1541 reloc
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
1542 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1543 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1545 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1547 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1548 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
1552 reloc
->addend
= fixp
->fx_addnumber
;
1557 /* Assume everything will fit in two bytes, then expand as necessary. */
1559 md_estimate_size_before_relax (fragp
, seg
)
1569 md_pcrel_from (fixp
)
1572 /* If the symbol is undefined, or in a section other than our own,
1573 then let the linker figure it out. */
1574 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
1576 /* The symbol is undefined. Let the linker figure it out. */
1579 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1583 md_apply_fix3 (fixp
, valuep
, seg
)
1591 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
1596 else if (fixp
->fx_pcrel
)
1600 value
= fixp
->fx_offset
;
1601 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
1603 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
1604 value
-= S_GET_VALUE (fixp
->fx_subsy
);
1607 /* We don't actually support subtracting a symbol. */
1608 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1609 "expression too complex");
1614 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1617 const struct v850_operand
* operand
;
1621 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1622 operand
= & v850_operands
[ opindex
];
1624 /* Fetch the instruction, insert the fully resolved operand
1625 value, and stuff the instruction back again.
1627 Note the instruction has been stored in little endian
1629 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1631 insn
= bfd_getl32 ((unsigned char *) where
);
1632 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
1633 fixp
->fx_file
, fixp
->fx_line
);
1634 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
1638 /* Nothing else to do here. */
1642 /* Determine a BFD reloc value based on the operand information.
1643 We are only prepared to turn a few of the operands into relocs. */
1645 if (operand
->bits
== 22)
1646 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
1647 else if (operand
->bits
== 9)
1648 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
1651 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
1652 "unresolved expression that must be resolved");
1657 else if (fixp
->fx_done
)
1659 /* We still have to insert the value into memory! */
1660 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1661 if (fixp
->fx_size
== 1)
1662 *where
= value
& 0xff;
1663 if (fixp
->fx_size
== 2)
1664 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
1665 if (fixp
->fx_size
== 4)
1666 bfd_putl32 (value
, (unsigned char *) where
);
1669 fixp
->fx_addnumber
= value
;
1674 /* Insert an operand value into an instruction. */
1676 static unsigned long
1677 v850_insert_operand (insn
, operand
, val
, file
, line
)
1679 const struct v850_operand
* operand
;
1684 if (operand
->insert
)
1686 const char * message
= NULL
;
1688 insn
= (*operand
->insert
) (insn
, val
, & message
);
1689 if (message
!= NULL
)
1691 if (file
== (char *) NULL
)
1694 as_warn_where (file
, line
, message
);
1699 if (operand
->bits
!= 32)
1704 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1706 if (! warn_signed_overflows
)
1707 max
= (1 << operand
->bits
) - 1;
1709 max
= (1 << (operand
->bits
- 1)) - 1;
1711 min
= - (1 << (operand
->bits
- 1));
1715 max
= (1 << operand
->bits
) - 1;
1717 if (! warn_unsigned_overflows
)
1718 min
= - (1 << (operand
->bits
- 1));
1725 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1727 const char * err
= "operand out of range (%s not between %ld and %ld)";
1730 sprint_value (buf
, test
);
1731 if (file
== (char *) NULL
)
1732 as_warn (err
, buf
, min
, max
);
1734 as_warn_where (file
, line
, err
, buf
, min
, max
);
1738 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1744 /* Parse a cons expression. We have to handle hi(), lo(), etc
1747 parse_cons_expression_v850 (exp
)
1750 /* See if there's a reloc prefix like hi() we have to handle. */
1751 hold_cons_reloc
= v850_reloc_prefix (NULL
);
1753 /* Do normal expression parsing. */
1757 /* Create a fixup for a cons expression. If parse_cons_expression_v850
1758 found a reloc prefix, then we use that reloc, else we choose an
1759 appropriate one based on the size of the expression. */
1761 cons_fix_new_v850 (frag
, where
, size
, exp
)
1767 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
1770 hold_cons_reloc
= BFD_RELOC_32
;
1772 hold_cons_reloc
= BFD_RELOC_16
;
1774 hold_cons_reloc
= BFD_RELOC_8
;
1778 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
1780 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);