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"
31 /* sign-extend a 16-bit number */
32 #define SEXT16(x) ((((x) & 0xffff) ^ (~ 0x7fff)) + 0x8000)
34 /* Temporarily holds the reloc in a cons expression. */
35 static bfd_reloc_code_real_type hold_cons_reloc
;
37 /* Set to TRUE if we want to be pedantic about signed overflows. */
38 static boolean warn_signed_overflows
= FALSE
;
39 static boolean warn_unsigned_overflows
= FALSE
;
41 /* Indicates the target BFD machine number. */
42 static int machine
= -1;
44 /* Indicates the target processor(s) for the assemble. */
45 static unsigned int processor_mask
= -1;
48 /* Structure to hold information about predefined registers. */
55 /* Generic assembler global variables which must be defined by all targets. */
57 /* Characters which always start a comment. */
58 const char comment_chars
[] = "#";
60 /* Characters which start a comment at the beginning of a line. */
61 const char line_comment_chars
[] = ";#";
63 /* Characters which may be used to separate multiple commands on a
65 const char line_separator_chars
[] = ";";
67 /* Characters which are used to indicate an exponent in a floating
69 const char EXP_CHARS
[] = "eE";
71 /* Characters which mean that a number is a floating point constant,
73 const char FLT_CHARS
[] = "dD";
76 const relax_typeS md_relax_table
[] =
78 /* Conditional branches. */
80 {0x1fffff, -0x200000, 6, 0},
81 /* Unconditional branches. */
83 {0x1fffff, -0x200000, 4, 0},
87 static segT sdata_section
= NULL
;
88 static segT tdata_section
= NULL
;
89 static segT zdata_section
= NULL
;
90 static segT sbss_section
= NULL
;
91 static segT tbss_section
= NULL
;
92 static segT zbss_section
= NULL
;
93 static segT rosdata_section
= NULL
;
94 static segT rozdata_section
= NULL
;
95 static segT scommon_section
= NULL
;
96 static segT tcommon_section
= NULL
;
97 static segT zcommon_section
= NULL
;
98 /* start-sanitize-v850e */
99 static segT call_table_data_section
= NULL
;
100 static segT call_table_text_section
= NULL
;
101 /* end-sanitize-v850e */
104 /* local functions */
105 static unsigned long v850_insert_operand
106 PARAMS ((unsigned long insn
, const struct v850_operand
*operand
,
107 offsetT val
, char *file
, unsigned int line
));
111 #define MAX_INSN_FIXUPS (5)
116 bfd_reloc_code_real_type reloc
;
118 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
122 v850_sdata (int ignore
)
124 obj_elf_section_change_hook();
126 subseg_set (sdata_section
, (subsegT
) get_absolute_expression ());
128 demand_empty_rest_of_line ();
132 v850_tdata (int ignore
)
134 obj_elf_section_change_hook();
136 subseg_set (tdata_section
, (subsegT
) get_absolute_expression ());
138 demand_empty_rest_of_line ();
142 v850_zdata (int ignore
)
144 obj_elf_section_change_hook();
146 subseg_set (zdata_section
, (subsegT
) get_absolute_expression ());
148 demand_empty_rest_of_line ();
152 v850_sbss (int ignore
)
154 obj_elf_section_change_hook();
156 subseg_set (sbss_section
, (subsegT
) get_absolute_expression ());
158 demand_empty_rest_of_line ();
162 v850_tbss (int ignore
)
164 obj_elf_section_change_hook();
166 subseg_set (tbss_section
, (subsegT
) get_absolute_expression ());
168 demand_empty_rest_of_line ();
172 v850_zbss (int ignore
)
174 obj_elf_section_change_hook();
176 subseg_set (zbss_section
, (subsegT
) get_absolute_expression ());
178 demand_empty_rest_of_line ();
182 v850_rosdata (int ignore
)
184 obj_elf_section_change_hook();
186 subseg_set (rosdata_section
, (subsegT
) get_absolute_expression ());
188 demand_empty_rest_of_line ();
192 v850_rozdata (int ignore
)
194 obj_elf_section_change_hook();
196 subseg_set (rozdata_section
, (subsegT
) get_absolute_expression ());
198 demand_empty_rest_of_line ();
201 /* start-sanitize-v850e */
203 v850_call_table_data (int ignore
)
205 obj_elf_section_change_hook();
207 subseg_set (call_table_data_section
, (subsegT
) get_absolute_expression ());
209 demand_empty_rest_of_line ();
213 v850_call_table_text (int ignore
)
215 obj_elf_section_change_hook();
217 subseg_set (call_table_text_section
, (subsegT
) get_absolute_expression ());
219 demand_empty_rest_of_line ();
221 /* end-sanitize-v850e */
224 v850_bss (int ignore
)
226 register int temp
= get_absolute_expression ();
228 obj_elf_section_change_hook();
230 subseg_set (bss_section
, (subsegT
) temp
);
232 demand_empty_rest_of_line ();
236 v850_offset (int ignore
)
238 int temp
= get_absolute_expression ();
240 temp
-= frag_now_fix();
243 (void) frag_more (temp
);
245 demand_empty_rest_of_line ();
248 /* Copied from obj_elf_common() in gas/config/obj-elf.c */
261 name
= input_line_pointer
;
262 c
= get_symbol_end ();
263 /* just after name is now '\0' */
264 p
= input_line_pointer
;
267 if (*input_line_pointer
!= ',')
269 as_bad ("Expected comma after symbol-name");
270 ignore_rest_of_line ();
273 input_line_pointer
++; /* skip ',' */
274 if ((temp
= get_absolute_expression ()) < 0)
276 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
277 ignore_rest_of_line ();
282 symbolP
= symbol_find_or_make (name
);
284 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
286 as_bad ("Ignoring attempt to re-define symbol");
287 ignore_rest_of_line ();
290 if (S_GET_VALUE (symbolP
) != 0)
292 if (S_GET_VALUE (symbolP
) != size
)
294 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
295 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
298 know (symbolP
->sy_frag
== &zero_address_frag
);
299 if (*input_line_pointer
!= ',')
304 input_line_pointer
++;
307 if (! have_align
|| *input_line_pointer
!= '"')
313 temp
= get_absolute_expression ();
317 as_warn ("Common alignment negative; 0 assumed");
329 old_subsec
= now_subseg
;
332 /* convert to a power of 2 alignment */
333 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
336 as_bad ("Common alignment not a power of 2");
337 ignore_rest_of_line ();
346 record_alignment (sbss_section
, align
);
347 obj_elf_section_change_hook();
348 subseg_set (sbss_section
, 0);
352 record_alignment (zbss_section
, align
);
353 obj_elf_section_change_hook();
354 subseg_set (zbss_section
, 0);
358 record_alignment (tbss_section
, align
);
359 obj_elf_section_change_hook();
360 subseg_set (tbss_section
, 0);
368 frag_align (align
, 0, 0);
373 if (S_GET_SEGMENT (symbolP
) == sbss_section
)
374 symbolP
->sy_frag
->fr_symbol
= 0;
378 if (S_GET_SEGMENT (symbolP
) == zbss_section
)
379 symbolP
->sy_frag
->fr_symbol
= 0;
383 if (S_GET_SEGMENT (symbolP
) == tbss_section
)
384 symbolP
->sy_frag
->fr_symbol
= 0;
391 symbolP
->sy_frag
= frag_now
;
392 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
393 (offsetT
) size
, (char *) 0);
395 S_SET_SIZE (symbolP
, size
);
399 case AREA_SDA
: S_SET_SEGMENT (symbolP
, sbss_section
); break;
400 case AREA_ZDA
: S_SET_SEGMENT (symbolP
, zbss_section
); break;
401 case AREA_TDA
: S_SET_SEGMENT (symbolP
, tbss_section
); break;
406 S_CLEAR_EXTERNAL (symbolP
);
407 obj_elf_section_change_hook();
408 subseg_set (old_sec
, old_subsec
);
413 S_SET_VALUE (symbolP
, (valueT
) size
);
414 S_SET_ALIGN (symbolP
, temp
);
415 S_SET_EXTERNAL (symbolP
);
419 case AREA_SDA
: S_SET_SEGMENT (symbolP
, scommon_section
); break;
420 case AREA_ZDA
: S_SET_SEGMENT (symbolP
, zcommon_section
); break;
421 case AREA_TDA
: S_SET_SEGMENT (symbolP
, tcommon_section
); break;
429 input_line_pointer
++;
430 /* @@ Some use the dot, some don't. Can we get some consistency?? */
431 if (*input_line_pointer
== '.')
432 input_line_pointer
++;
433 /* @@ Some say data, some say bss. */
434 if (strncmp (input_line_pointer
, "bss\"", 4)
435 && strncmp (input_line_pointer
, "data\"", 5))
437 while (*--input_line_pointer
!= '"')
439 input_line_pointer
--;
440 goto bad_common_segment
;
442 while (*input_line_pointer
++ != '"')
444 goto allocate_common
;
447 symbolP
->bsym
->flags
|= BSF_OBJECT
;
449 demand_empty_rest_of_line ();
454 p
= input_line_pointer
;
455 while (*p
&& *p
!= '\n')
459 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
461 input_line_pointer
= p
;
462 ignore_rest_of_line ();
468 set_machine (int number
)
471 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
475 case 0: processor_mask
= PROCESSOR_V850
; break;
476 /* start-sanitize-v850e */
477 case bfd_mach_v850e
: processor_mask
= PROCESSOR_V850E
; break;
478 case bfd_mach_v850eq
: processor_mask
= PROCESSOR_V850EQ
; break;
479 /* end-sanitize-v850e */
483 /* The target specific pseudo-ops which we support. */
484 const pseudo_typeS md_pseudo_table
[] =
486 {"sdata", v850_sdata
, 0},
487 {"tdata", v850_tdata
, 0},
488 {"zdata", v850_zdata
, 0},
489 {"sbss", v850_sbss
, 0},
490 {"tbss", v850_tbss
, 0},
491 {"zbss", v850_zbss
, 0},
492 {"rosdata", v850_rosdata
, 0},
493 {"rozdata", v850_rozdata
, 0},
494 {"bss", v850_bss
, 0},
495 {"offset", v850_offset
, 0},
497 {"zcomm", v850_comm
, AREA_ZDA
},
498 {"scomm", v850_comm
, AREA_SDA
},
499 {"tcomm", v850_comm
, AREA_TDA
},
500 {"v850", set_machine
, 0},
501 /* start-sanitize-v850e */
502 {"call_table_data", v850_call_table_data
, 0},
503 {"call_table_text", v850_call_table_text
, 0},
504 {"v850e", set_machine
, bfd_mach_v850e
},
505 {"v850eq", set_machine
, bfd_mach_v850eq
},
506 /* end-sanitize-v850e */
510 /* Opcode hash table. */
511 static struct hash_control
*v850_hash
;
513 /* This table is sorted. Suitable for searching by a binary search. */
514 static const struct reg_name pre_defined_registers
[] =
516 { "ep", 30 }, /* ep - element ptr */
517 { "gp", 4 }, /* gp - global ptr */
518 { "hp", 2 }, /* hp - handler stack ptr */
519 { "lp", 31 }, /* lp - link ptr */
552 { "sp", 3 }, /* sp - stack ptr */
553 { "tp", 5 }, /* tp - text ptr */
556 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
559 static const struct reg_name system_registers
[] =
561 /* start-sanitize-v850e */
568 /* end-sanitize-v850e */
576 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
578 static const struct reg_name cc_names
[] =
603 #define CC_NAME_CNT (sizeof (cc_names) / sizeof (struct reg_name))
605 /* reg_name_search does a binary search of the given register table
606 to see if "name" is a valid regiter name. Returns the register
607 number from the array on success, or -1 on failure. */
610 reg_name_search (regs
, regcount
, name
)
611 const struct reg_name
* regs
;
615 int middle
, low
, high
;
623 middle
= (low
+ high
) / 2;
624 cmp
= strcasecmp (name
, regs
[middle
].name
);
630 return regs
[middle
].value
;
637 /* Summary of register_name().
639 * in: Input_line_pointer points to 1st char of operand.
641 * out: A expressionS.
642 * The operand may have been a register: in this case, X_op == O_register,
643 * X_add_number is set to the register number, and truth is returned.
644 * Input_line_pointer->(next non-blank) char after operand, or is in
645 * its original state.
648 register_name (expressionP
)
649 expressionS
* expressionP
;
656 /* Find the spelling of the operand */
657 start
= name
= input_line_pointer
;
659 c
= get_symbol_end ();
661 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
663 * input_line_pointer
= c
; /* put back the delimiting char */
665 /* look to see if it's in the register table */
668 expressionP
->X_op
= O_register
;
669 expressionP
->X_add_number
= reg_number
;
671 /* make the rest nice */
672 expressionP
->X_add_symbol
= NULL
;
673 expressionP
->X_op_symbol
= NULL
;
679 /* reset the line as if we had not done anything */
680 input_line_pointer
= start
;
686 /* Summary of system_register_name().
688 * in: Input_line_pointer points to 1st char of operand.
690 * out: A expressionS.
691 * The operand may have been a register: in this case, X_op == O_register,
692 * X_add_number is set to the register number, and truth is returned.
693 * Input_line_pointer->(next non-blank) char after operand, or is in
694 * its original state.
697 system_register_name (expressionP
, accept_numbers
)
698 expressionS
* expressionP
;
699 boolean accept_numbers
;
706 /* Find the spelling of the operand */
707 start
= name
= input_line_pointer
;
709 c
= get_symbol_end ();
710 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
);
712 * input_line_pointer
= c
; /* put back the delimiting char */
717 input_line_pointer
= start
; /* reset input_line pointer */
719 if (isdigit (* input_line_pointer
))
720 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
722 /* Make sure that the register number is allowable. */
725 /* start-sanitize-v850e */
728 /* end-sanitize-v850e */
735 /* look to see if it's in the register table */
738 expressionP
->X_op
= O_register
;
739 expressionP
->X_add_number
= reg_number
;
741 /* make the rest nice */
742 expressionP
->X_add_symbol
= NULL
;
743 expressionP
->X_op_symbol
= NULL
;
749 /* reset the line as if we had not done anything */
750 input_line_pointer
= start
;
756 /* Summary of cc_name().
758 * in: Input_line_pointer points to 1st char of operand.
760 * out: A expressionS.
761 * The operand may have been a register: in this case, X_op == O_register,
762 * X_add_number is set to the register number, and truth is returned.
763 * Input_line_pointer->(next non-blank) char after operand, or is in
764 * its original state.
767 cc_name (expressionP
)
768 expressionS
* expressionP
;
775 /* Find the spelling of the operand */
776 start
= name
= input_line_pointer
;
778 c
= get_symbol_end ();
779 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
);
781 * input_line_pointer
= c
; /* put back the delimiting char */
783 /* look to see if it's in the register table */
786 expressionP
->X_op
= O_constant
;
787 expressionP
->X_add_number
= reg_number
;
789 /* make the rest nice */
790 expressionP
->X_add_symbol
= NULL
;
791 expressionP
->X_op_symbol
= NULL
;
797 /* reset the line as if we had not done anything */
798 input_line_pointer
= start
;
805 skip_white_space (void)
807 while ( * input_line_pointer
== ' '
808 || * input_line_pointer
== '\t')
809 ++ input_line_pointer
;
812 /* start-sanitize-v850e */
813 /* Summary of parse_register_list ().
815 * in: Input_line_pointer points to 1st char of a list of registers.
816 * insn is the partially constructed instruction.
817 * operand is the operand being inserted.
819 * out: NULL if the parse completed successfully, otherwise a
820 * pointer to an error message is returned. If the parse
821 * completes the correct bit fields in the instruction
824 * Parses register lists with the syntax:
832 * and also parses constant epxressions whoes bits indicate the
833 * registers in the lists. The LSB in the expression refers to
834 * the lowest numbered permissable register in the register list,
835 * and so on upwards. System registers are considered to be very
842 unsigned long * insn
,
843 const struct v850_operand
* operand
846 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 };
847 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 };
848 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 };
853 /* Select a register array to parse. */
854 switch (operand
->shift
)
856 case 0xffe00001: regs
= type1_regs
; break;
857 case 0xfff8000f: regs
= type2_regs
; break;
858 case 0xfff8001f: regs
= type3_regs
; break;
860 as_bad ("unknown operand shift: %x\n", operand
->shift
);
861 return "internal failure in parse_register_list";
866 /* If the expression starts with a curly brace it is a register list.
867 Otherwise it is a constant expression, whoes bits indicate which
868 registers are to be included in the list. */
870 if (* input_line_pointer
!= '{')
878 if (exp
.X_op
!= O_constant
)
879 return "constant expression or register list expected";
881 if (regs
== type1_regs
)
883 if (exp
.X_add_number
& 0xFFFFF000)
884 return "high bits set in register list expression";
886 for (reg
= 20; reg
< 32; reg
++)
887 if (exp
.X_add_number
& (1 << (reg
- 20)))
889 for (i
= 0; i
< 32; i
++)
894 else if (regs
== type2_regs
)
896 if (exp
.X_add_number
& 0xFFFE0000)
897 return "high bits set in register list expression";
899 for (reg
= 1; reg
< 16; reg
++)
900 if (exp
.X_add_number
& (1 << (reg
- 1)))
902 for (i
= 0; i
< 32; i
++)
907 if (exp
.X_add_number
& (1 << 15))
910 if (exp
.X_add_number
& (1 << 16))
913 else /* regs == type3_regs */
915 if (exp
.X_add_number
& 0xFFFE0000)
916 return "high bits set in register list expression";
918 for (reg
= 16; reg
< 32; reg
++)
919 if (exp
.X_add_number
& (1 << (reg
- 16)))
921 for (i
= 0; i
< 32; i
++)
926 if (exp
.X_add_number
& (1 << 16))
933 input_line_pointer
++;
935 /* Parse the register list until a terminator (closing curly brace or new-line) is found. */
938 if (register_name (& exp
))
942 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
943 for (i
= 0; i
< 32; i
++)
945 if (regs
[ i
] == exp
.X_add_number
)
954 return "illegal register included in list";
957 else if (system_register_name (& exp
, true))
959 if (regs
== type1_regs
)
961 return "system registers cannot be included in list";
963 else if (exp
.X_add_number
== 5)
965 if (regs
== type2_regs
)
966 return "PSW cannot be included in list";
973 else if (* input_line_pointer
== '}')
975 input_line_pointer
++;
978 else if (* input_line_pointer
== ',')
980 input_line_pointer
++;
983 else if (* input_line_pointer
== '-')
985 /* We have encountered a range of registers: rX - rY */
990 ++ input_line_pointer
;
992 /* Get the second register in the range. */
993 if (! register_name (& exp2
))
995 return "second register should follow dash in register list";
996 exp2
.X_add_number
= exp
.X_add_number
;
999 /* Add the rest of the registers in the range. */
1000 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
1004 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
1005 for (i
= 0; i
< 32; i
++)
1016 return "illegal register included in list";
1030 /* end-sanitize-v850e */
1032 CONST
char * md_shortopts
= "m:";
1034 struct option md_longopts
[] =
1036 {NULL
, no_argument
, NULL
, 0}
1038 size_t md_longopts_size
= sizeof md_longopts
;
1042 md_show_usage (stream
)
1045 fprintf (stream
, "V850 options:\n");
1046 fprintf (stream
, "\t-wsigned_overflow Warn if signed immediate values overflow\n");
1047 fprintf (stream
, "\t-wunsigned_overflow Warn if unsigned immediate values overflow\n");
1048 fprintf (stream
, "\t-mv850 The code is targeted at the v850\n");
1049 /* start-sanitize-v850e */
1050 fprintf (stream
, "\t-mv850e The code is targeted at the v850e\n");
1051 fprintf (stream
, "\t-mv850eq The code is targeted at the v850eq\n");
1052 /* end-sanitize-v850e */
1056 md_parse_option (c
, arg
)
1063 if (strcmp (arg
, "signed_overflow") == 0)
1065 warn_signed_overflows
= TRUE
;
1068 else if (strcmp (arg
, "unsigned_overflow") == 0)
1070 warn_unsigned_overflows
= TRUE
;
1076 if (strcmp (arg
, "v850") == 0)
1079 processor_mask
= PROCESSOR_V850
;
1082 /* start-sanitize-v850e */
1083 else if (strcmp (arg
, "v850e") == 0)
1085 machine
= bfd_mach_v850e
;
1086 processor_mask
= PROCESSOR_V850E
;
1089 else if (strcmp (arg
, "v850eq") == 0)
1091 machine
= bfd_mach_v850eq
;
1092 processor_mask
= PROCESSOR_V850EQ
;
1095 /* end-sanitize-v850e */
1103 md_undefined_symbol (name
)
1110 md_atof (type
, litp
, sizep
)
1116 LITTLENUM_TYPE words
[4];
1132 return "bad call to md_atof";
1135 t
= atof_ieee (input_line_pointer
, type
, words
);
1137 input_line_pointer
= t
;
1141 for (i
= prec
- 1; i
>= 0; i
--)
1143 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
1153 md_convert_frag (abfd
, sec
, fragP
)
1158 subseg_change (sec
, 0);
1160 /* In range conditional or unconditional branch. */
1161 if (fragP
->fr_subtype
== 0 || fragP
->fr_subtype
== 2)
1163 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1164 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
1168 /* Out of range conditional branch. Emit a branch around a jump. */
1169 else if (fragP
->fr_subtype
== 1)
1171 unsigned char *buffer
=
1172 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
1174 /* Reverse the condition of the first branch. */
1176 /* Mask off all the displacement bits. */
1179 /* Now set the displacement bits so that we branch
1180 around the unconditional branch. */
1183 /* Now create the unconditional branch + fixup to the final
1185 md_number_to_chars (buffer
+ 2, 0x00000780, 4);
1186 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1187 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
+ 1);
1191 /* Out of range unconditional branch. Emit a jump. */
1192 else if (fragP
->fr_subtype
== 3)
1194 md_number_to_chars (fragP
->fr_fix
+ fragP
->fr_literal
, 0x00000780, 4);
1195 fix_new (fragP
, fragP
->fr_fix
, 4, fragP
->fr_symbol
,
1196 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
+ 1);
1205 md_section_align (seg
, addr
)
1209 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1210 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1216 char * prev_name
= "";
1217 register const struct v850_opcode
* op
;
1218 flagword applicable
;
1220 /* start-sanitize-v850e */
1221 if (strncmp (TARGET_CPU
, "v850eq", 6) == 0)
1224 machine
= bfd_mach_v850eq
;
1226 if (processor_mask
== -1)
1227 processor_mask
= PROCESSOR_V850EQ
;
1229 else if (strncmp (TARGET_CPU
, "v850e", 5) == 0)
1232 machine
= bfd_mach_v850e
;
1234 if (processor_mask
== -1)
1235 processor_mask
= PROCESSOR_V850E
;
1238 /* end-sanitize-v850e */
1239 if (strncmp (TARGET_CPU
, "v850", 4) == 0)
1244 if (processor_mask
== -1)
1245 processor_mask
= PROCESSOR_V850
;
1248 as_bad ("Unable to determine default target processor from string: %s",
1251 v850_hash
= hash_new();
1253 /* Insert unique names into hash table. The V850 instruction set
1254 has many identical opcode names that have different opcodes based
1255 on the operands. This hash table then provides a quick index to
1256 the first opcode with a particular name in the opcode table. */
1261 if (strcmp (prev_name
, op
->name
))
1263 prev_name
= (char *) op
->name
;
1264 hash_insert (v850_hash
, op
->name
, (char *) op
);
1269 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, machine
);
1271 applicable
= bfd_applicable_section_flags (stdoutput
);
1273 sdata_section
= subseg_new (".sdata", 0);
1274 bfd_set_section_flags (stdoutput
, sdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1276 tdata_section
= subseg_new (".tdata", 0);
1277 bfd_set_section_flags (stdoutput
, tdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1279 zdata_section
= subseg_new (".zdata", 0);
1280 bfd_set_section_flags (stdoutput
, zdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1282 sbss_section
= subseg_new (".sbss", 0);
1283 bfd_set_section_flags (stdoutput
, sbss_section
, applicable
& SEC_ALLOC
);
1284 seg_info (sbss_section
)->bss
= 1;
1286 tbss_section
= subseg_new (".tbss", 0);
1287 bfd_set_section_flags (stdoutput
, tbss_section
, applicable
& SEC_ALLOC
);
1288 seg_info (tbss_section
)->bss
= 1;
1290 zbss_section
= subseg_new (".zbss", 0);
1291 bfd_set_section_flags (stdoutput
, zbss_section
, applicable
& SEC_ALLOC
);
1292 seg_info (zbss_section
)->bss
= 1;
1294 rosdata_section
= subseg_new (".rosdata", 0);
1295 bfd_set_section_flags (stdoutput
, rosdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
));
1297 rozdata_section
= subseg_new (".rozdata", 0);
1298 bfd_set_section_flags (stdoutput
, rozdata_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_READONLY
));
1300 scommon_section
= subseg_new (".scommon", 0);
1301 bfd_set_section_flags (stdoutput
, scommon_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_IS_COMMON
));
1303 zcommon_section
= subseg_new (".zcommon", 0);
1304 bfd_set_section_flags (stdoutput
, zcommon_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
| SEC_IS_COMMON
));
1306 /* start-sanitize-v850e */
1307 call_table_data_section
= subseg_new (".call_table_data", 0);
1308 bfd_set_section_flags (stdoutput
, call_table_data_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_DATA
| SEC_HAS_CONTENTS
));
1310 call_table_text_section
= subseg_new (".call_table_text", 0);
1311 bfd_set_section_flags (stdoutput
, call_table_text_section
, applicable
& (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
));
1312 /* end-sanitize-v850e */
1316 /* start-sanitize-v850e */
1317 static bfd_reloc_code_real_type
1318 handle_ctoff (const struct v850_operand
* operand
)
1320 if (operand
== NULL
)
1321 return BFD_RELOC_V850_CALLT_16_16_OFFSET
;
1323 if ( operand
->bits
!= 6
1324 || operand
->shift
!= 0)
1326 as_bad ("ctoff() relocation used on an instruction which does not support it");
1327 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1330 return BFD_RELOC_V850_CALLT_6_7_OFFSET
;
1332 /* end-sanitize-v850e */
1334 static bfd_reloc_code_real_type
1335 handle_sdaoff (const struct v850_operand
* operand
)
1337 if (operand
== NULL
) return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1338 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_SDA_15_16_OFFSET
;
1339 /* start-sanitize-v850e */
1340 if (operand
->bits
== -1) return BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET
;
1341 /* end-sanitize-v850e */
1343 if ( operand
->bits
!= 16
1344 || operand
->shift
!= 16)
1346 as_bad ("sdaoff() relocation used on an instruction which does not support it");
1347 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1350 return BFD_RELOC_V850_SDA_16_16_OFFSET
;
1353 static bfd_reloc_code_real_type
1354 handle_zdaoff (const struct v850_operand
* operand
)
1356 if (operand
== NULL
) return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1357 if (operand
->bits
== 15 && operand
->shift
== 17) return BFD_RELOC_V850_ZDA_15_16_OFFSET
;
1358 /* start-sanitize-v850e */
1359 if (operand
->bits
== -1) return BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET
;
1360 /* end-sanitize-v850e */
1362 if ( operand
->bits
!= 16
1363 || operand
->shift
!= 16)
1365 as_bad ("zdaoff() relocation used on an instruction which does not support it");
1366 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1369 return BFD_RELOC_V850_ZDA_16_16_OFFSET
;
1372 static bfd_reloc_code_real_type
1373 handle_tdaoff (const struct v850_operand
* operand
)
1375 if (operand
== NULL
) return BFD_RELOC_V850_TDA_7_7_OFFSET
; /* data item, not an instruction. */
1376 if (operand
->bits
== 6 && operand
->shift
== 1) return BFD_RELOC_V850_TDA_6_8_OFFSET
; /* sld.w/sst.w, operand: D8_6 */
1377 /* start-sanitize-v850e */
1378 if (operand
->bits
== 4 && operand
->insert
!= NULL
) return BFD_RELOC_V850_TDA_4_5_OFFSET
; /* sld.hu, operand: D5-4 */
1379 if (operand
->bits
== 4 && operand
->insert
== NULL
) return BFD_RELOC_V850_TDA_4_4_OFFSET
; /* sld.bu, operand: D4 */
1380 /* end-sanitize-v850e */
1381 if (operand
->bits
== 16 && operand
->shift
== 16) return BFD_RELOC_V850_TDA_16_16_OFFSET
; /* set1 & chums, operands: D16 */
1383 if (operand
->bits
!= 7)
1385 as_bad ("tdaoff() relocation used on an instruction which does not support it");
1386 return BFD_RELOC_64
; /* Used to indicate an error condition. */
1389 return operand
->insert
!= NULL
1390 ? BFD_RELOC_V850_TDA_7_8_OFFSET
/* sld.h/sst.h, operand: D8_7 */
1391 : BFD_RELOC_V850_TDA_7_7_OFFSET
; /* sld.b/sst.b, opreand: D7 */
1394 /* Warning: The code in this function relies upon the definitions
1395 in the v850_operands[] array (defined in opcodes/v850-opc.c)
1396 matching the hard coded values contained herein. */
1398 static bfd_reloc_code_real_type
1399 v850_reloc_prefix (const struct v850_operand
* operand
)
1401 boolean paren_skipped
= false;
1404 /* Skip leading opening parenthesis. */
1405 if (* input_line_pointer
== '(')
1407 ++ input_line_pointer
;
1408 paren_skipped
= true;
1411 #define CHECK_(name, reloc) \
1412 if (strncmp (input_line_pointer, name##"(", strlen (name) + 1) == 0) \
1414 input_line_pointer += strlen (name); \
1418 CHECK_ ("hi0", BFD_RELOC_HI16
);
1419 CHECK_ ("hi", BFD_RELOC_HI16_S
);
1420 CHECK_ ("lo", BFD_RELOC_LO16
);
1421 CHECK_ ("sdaoff", handle_sdaoff (operand
));
1422 CHECK_ ("zdaoff", handle_zdaoff (operand
));
1423 CHECK_ ("tdaoff", handle_tdaoff (operand
));
1425 /* start-sanitize-v850e */
1426 CHECK_ ("hilo", BFD_RELOC_32
);
1427 CHECK_ ("ctoff", handle_ctoff (operand
));
1428 /* end-sanitize-v850e */
1430 /* Restore skipped parenthesis. */
1432 -- input_line_pointer
;
1434 return BFD_RELOC_UNUSED
;
1442 char * start_of_operands
;
1443 struct v850_opcode
* opcode
;
1444 struct v850_opcode
* next_opcode
;
1445 const unsigned char * opindex_ptr
;
1449 unsigned long insn_size
;
1453 boolean extra_data_after_insn
= false;
1454 unsigned extra_data_len
;
1455 unsigned long extra_data
;
1456 char * saved_input_line_pointer
;
1458 /* Get the opcode. */
1459 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1465 /* find the first opcode with the proper name */
1466 opcode
= (struct v850_opcode
*)hash_find (v850_hash
, str
);
1469 as_bad ("Unrecognized opcode: `%s'", str
);
1470 ignore_rest_of_line ();
1475 while (isspace (* str
))
1478 start_of_operands
= str
;
1480 saved_input_line_pointer
= input_line_pointer
;
1484 const char * errmsg
= NULL
;
1488 if ((opcode
->processors
& processor_mask
) == 0)
1490 errmsg
= "Target processor does not support this instruction.";
1497 insn
= opcode
->opcode
;
1498 extra_data_after_insn
= false;
1500 input_line_pointer
= str
= start_of_operands
;
1502 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1504 const struct v850_operand
* operand
;
1507 bfd_reloc_code_real_type reloc
;
1509 if (next_opindex
== 0)
1511 operand
= & v850_operands
[ * opindex_ptr
];
1515 operand
= & v850_operands
[ next_opindex
];
1521 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1524 if (operand
->flags
& V850_OPERAND_RELAX
)
1527 /* Gather the operand. */
1528 hold
= input_line_pointer
;
1529 input_line_pointer
= str
;
1531 /* lo(), hi(), hi0(), etc... */
1532 if ((reloc
= v850_reloc_prefix (operand
)) != BFD_RELOC_UNUSED
)
1534 if (reloc
== BFD_RELOC_64
) /* This is a fake reloc, used to indicate an error condition. */
1542 if (ex
.X_op
== O_constant
)
1546 case BFD_RELOC_V850_ZDA_16_16_OFFSET
:
1547 /* To cope with "not1 7, zdaoff(0xfffff006)[r0]" and the like. */
1550 case BFD_RELOC_LO16
:
1552 /* Truncate, then sign extend the value. */
1553 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
1557 case BFD_RELOC_HI16
:
1559 /* Truncate, then sign extend the value. */
1560 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
1564 case BFD_RELOC_HI16_S
:
1566 /* Truncate, then sign extend the value. */
1567 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
1569 temp
+= (ex
.X_add_number
>> 15) & 1;
1571 ex
.X_add_number
= SEXT16 (temp
);
1575 /* start-sanitize-v850e */
1577 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1579 errmsg
= "use bigger instruction";
1583 extra_data_after_insn
= true;
1585 extra_data
= ex
.X_add_number
;
1586 ex
.X_add_number
= 0;
1588 /* end-sanitize-v850e */
1591 fprintf (stderr
, "reloc: %d\n", reloc
);
1592 as_bad ("AAARG -> unhandled constant reloc");
1596 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1601 if (reloc
== BFD_RELOC_32
)
1603 if ((operand
->flags
& V850E_IMMEDIATE32
) == 0)
1605 errmsg
= "use bigger instruction";
1609 extra_data_after_insn
= true;
1611 extra_data
= ex
.X_add_number
;
1612 ex
.X_add_number
= 0;
1615 if (fc
> MAX_INSN_FIXUPS
)
1616 as_fatal ("too many fixups");
1618 fixups
[ fc
].exp
= ex
;
1619 fixups
[ fc
].opindex
= * opindex_ptr
;
1620 fixups
[ fc
].reloc
= reloc
;
1628 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
1630 if (!register_name (& ex
))
1632 errmsg
= "invalid register name";
1635 if ((operand
->flags
& V850_NOT_R0
)
1636 && ex
.X_add_number
== 0)
1638 errmsg
= "register r0 cannot be used here";
1641 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
1643 if (!system_register_name (& ex
, true))
1645 errmsg
= "invalid system register name";
1648 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
1650 char * start
= input_line_pointer
;
1651 char c
= get_symbol_end ();
1653 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
1655 /* Put things back the way we found them. */
1656 *input_line_pointer
= c
;
1657 input_line_pointer
= start
;
1658 errmsg
= "expected EP register";
1662 *input_line_pointer
= c
;
1663 str
= input_line_pointer
;
1664 input_line_pointer
= hold
;
1666 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
1670 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
1672 if (!cc_name (& ex
))
1674 errmsg
= "invalid condition code name";
1677 /* start-sanitize-v850e */
1678 else if (operand
->flags
& V850E_PUSH_POP
)
1680 errmsg
= parse_register_list (& insn
, operand
);
1682 /* The parse_register_list() function has already done everything, so fake a dummy expression. */
1683 ex
.X_op
= O_constant
;
1684 ex
.X_add_number
= 0;
1686 else if (operand
->flags
& V850E_IMMEDIATE16
)
1690 if (ex
.X_op
!= O_constant
)
1691 errmsg
= "constant expression expected";
1692 else if (ex
.X_add_number
& 0xffff0000)
1694 if (ex
.X_add_number
& 0xffff)
1695 errmsg
= "constant too big to fit into instruction";
1696 else if ((insn
& 0x001fffc0) == 0x00130780)
1697 ex
.X_add_number
>>= 16;
1699 errmsg
= "constant too big to fit into instruction";
1702 extra_data_after_insn
= true;
1704 extra_data
= ex
.X_add_number
;
1705 ex
.X_add_number
= 0;
1707 else if (operand
->flags
& V850E_IMMEDIATE32
)
1711 if (ex
.X_op
!= O_constant
)
1712 errmsg
= "constant expression expected";
1714 extra_data_after_insn
= true;
1716 extra_data
= ex
.X_add_number
;
1717 ex
.X_add_number
= 0;
1719 /* end-sanitize-v850e */
1720 else if (register_name (&ex
)
1721 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1723 errmsg
= "syntax error: register not expected";
1725 else if (system_register_name (& ex
, false)
1726 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1728 errmsg
= "syntax error: system register not expected";
1730 else if (cc_name (&ex
)
1731 && (operand
->flags
& V850_OPERAND_CC
) == 0)
1733 errmsg
= "syntax error: condition code not expected";
1738 /* start-sanitize-v850e */
1740 If we are assembling a MOV instruction (or a CALLT.... :-)
1741 and the immediate value does not fit into the bits available
1742 then create a fake error so that the next MOV instruction
1743 will be selected. This one has a 32 bit immediate field. */
1745 if (((insn
& 0x07e0) == 0x0200)
1746 && ex
.X_op
== O_constant
1747 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1))) || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
1748 errmsg
= "use bigger instruction";
1749 /* end-sanitize-v850e */
1755 /* fprintf (stderr, " insn: %x, operand %d, op: %d, add_number: %d\n", insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number); */
1760 errmsg
= "illegal operand";
1763 errmsg
= "missing operand";
1766 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
1768 errmsg
= "invalid operand";
1771 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1776 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1781 /* We need to generate a fixup for this expression. */
1782 if (fc
>= MAX_INSN_FIXUPS
)
1783 as_fatal ("too many fixups");
1785 fixups
[ fc
].exp
= ex
;
1786 fixups
[ fc
].opindex
= * opindex_ptr
;
1787 fixups
[ fc
].reloc
= BFD_RELOC_UNUSED
;
1793 str
= input_line_pointer
;
1794 input_line_pointer
= hold
;
1796 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
1805 next_opcode
= opcode
+ 1;
1806 if (next_opcode
->name
!= NULL
&& strcmp (next_opcode
->name
, opcode
->name
) == 0)
1808 opcode
= next_opcode
;
1813 ignore_rest_of_line ();
1814 input_line_pointer
= saved_input_line_pointer
;
1820 while (isspace (*str
))
1824 as_bad ("junk at end of line: `%s'", str
);
1826 input_line_pointer
= str
;
1828 /* Write out the instruction. */
1830 if (relaxable
&& fc
> 0)
1835 if (!strcmp (opcode
->name
, "br"))
1837 f
= frag_var (rs_machine_dependent
, 4, 2, 2,
1838 fixups
[0].exp
.X_add_symbol
,
1839 fixups
[0].exp
.X_add_number
,
1840 (char *)fixups
[0].opindex
);
1841 md_number_to_chars (f
, insn
, insn_size
);
1842 md_number_to_chars (f
+ 2, 0, 2);
1846 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
1847 fixups
[0].exp
.X_add_symbol
,
1848 fixups
[0].exp
.X_add_number
,
1849 (char *)fixups
[0].opindex
);
1850 md_number_to_chars (f
, insn
, insn_size
);
1851 md_number_to_chars (f
+ 2, 0, 4);
1856 /* Four byte insns have an opcode with the two high bits on. */
1857 if ((insn
& 0x0600) == 0x0600)
1862 /* start-sanitize-v850e */
1863 /* Special case: 32 bit MOV */
1864 if ((insn
& 0xffe0) == 0x0620)
1866 /* end-sanitize-v850e */
1868 f
= frag_more (insn_size
);
1870 md_number_to_chars (f
, insn
, insn_size
);
1872 if (extra_data_after_insn
)
1874 f
= frag_more (extra_data_len
);
1876 md_number_to_chars (f
, extra_data
, extra_data_len
);
1878 extra_data_after_insn
= false;
1882 /* Create any fixups. At this point we do not use a
1883 bfd_reloc_code_real_type, but instead just use the
1884 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1885 handle fixups for any operand type, although that is admittedly
1886 not a very exciting feature. We pick a BFD reloc type in
1888 for (i
= 0; i
< fc
; i
++)
1890 const struct v850_operand
* operand
;
1891 bfd_reloc_code_real_type reloc
;
1893 operand
= & v850_operands
[ fixups
[i
].opindex
];
1895 reloc
= fixups
[i
].reloc
;
1897 if (reloc
!= BFD_RELOC_UNUSED
)
1899 reloc_howto_type
* reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1907 size
= bfd_get_reloc_size (reloc_howto
);
1909 if (size
!= 2 && size
!= 4) /* XXX this will abort on an R_V850_8 reloc - is this reloc actually used ? */
1912 address
= (f
- frag_now
->fr_literal
) + insn_size
- size
;
1914 if (reloc
== BFD_RELOC_32
)
1919 fixP
= fix_new_exp (frag_now
, address
, size
,
1921 reloc_howto
->pc_relative
,
1926 case BFD_RELOC_LO16
:
1927 case BFD_RELOC_HI16
:
1928 case BFD_RELOC_HI16_S
:
1929 fixP
->fx_no_overflow
= 1;
1937 f
- frag_now
->fr_literal
, 4,
1939 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
1940 (bfd_reloc_code_real_type
) (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)
1945 input_line_pointer
= saved_input_line_pointer
;
1949 /* If while processing a fixup, a reloc really needs to be created */
1950 /* then it is done here. */
1953 tc_gen_reloc (seg
, fixp
)
1959 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1960 reloc
->sym_ptr_ptr
= & fixp
->fx_addsy
->bsym
;
1961 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1962 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1964 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1966 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1967 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
1974 reloc
->addend
= fixp
->fx_addnumber
;
1979 /* Assume everything will fit in two bytes, then expand as necessary. */
1981 md_estimate_size_before_relax (fragp
, seg
)
1985 if (fragp
->fr_subtype
== 0)
1987 else if (fragp
->fr_subtype
== 2)
1995 md_pcrel_from (fixp
)
1998 /* If the symbol is undefined, or in a section other than our own,
1999 then let the linker figure it out. */
2000 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
2002 /* The symbol is undefined. Let the linker figure it out. */
2005 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2009 md_apply_fix3 (fixp
, valuep
, seg
)
2017 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2022 else if (fixp
->fx_pcrel
)
2026 value
= fixp
->fx_offset
;
2027 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2029 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2030 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2033 /* We don't actually support subtracting a symbol. */
2034 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2035 "expression too complex");
2040 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2043 const struct v850_operand
* operand
;
2046 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2047 operand
= & v850_operands
[ opindex
];
2049 /* Fetch the instruction, insert the fully resolved operand
2050 value, and stuff the instruction back again.
2052 Note the instruction has been stored in little endian
2054 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2056 insn
= bfd_getl32 ((unsigned char *) where
);
2057 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
2058 fixp
->fx_file
, fixp
->fx_line
);
2059 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2063 /* Nothing else to do here. */
2067 /* Determine a BFD reloc value based on the operand information.
2068 We are only prepared to turn a few of the operands into relocs. */
2070 if (operand
->bits
== 22)
2071 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
2072 else if (operand
->bits
== 9)
2073 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
2076 /* fprintf (stderr, "bits: %d, insn: %x\n", operand->bits, insn); */
2078 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
2079 "unresolved expression that must be resolved");
2084 else if (fixp
->fx_done
)
2086 /* We still have to insert the value into memory! */
2087 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2089 if (fixp
->fx_size
== 1)
2090 *where
= value
& 0xff;
2091 else if (fixp
->fx_size
== 2)
2092 bfd_putl16 (value
& 0xffff, (unsigned char *) where
);
2093 else if (fixp
->fx_size
== 4)
2094 bfd_putl32 (value
, (unsigned char *) where
);
2097 fixp
->fx_addnumber
= value
;
2102 /* Insert an operand value into an instruction. */
2104 static unsigned long
2105 v850_insert_operand (insn
, operand
, val
, file
, line
)
2107 const struct v850_operand
* operand
;
2112 if (operand
->insert
)
2114 const char * message
= NULL
;
2116 insn
= (*operand
->insert
) (insn
, val
, & message
);
2117 if (message
!= NULL
)
2119 if (file
== (char *) NULL
)
2122 as_warn_where (file
, line
, message
);
2127 if (operand
->bits
!= 32)
2132 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
2134 if (! warn_signed_overflows
)
2135 max
= (1 << operand
->bits
) - 1;
2137 max
= (1 << (operand
->bits
- 1)) - 1;
2139 min
= - (1 << (operand
->bits
- 1));
2143 max
= (1 << operand
->bits
) - 1;
2145 if (! warn_unsigned_overflows
)
2146 min
= - (1 << (operand
->bits
- 1));
2153 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
2155 const char * err
= "operand out of range (%s not between %ld and %ld)";
2158 sprint_value (buf
, test
);
2159 if (file
== (char *) NULL
)
2160 as_warn (err
, buf
, min
, max
);
2162 as_warn_where (file
, line
, err
, buf
, min
, max
);
2166 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
2172 /* Parse a cons expression. We have to handle hi(), lo(), etc
2175 parse_cons_expression_v850 (exp
)
2178 /* See if there's a reloc prefix like hi() we have to handle. */
2179 hold_cons_reloc
= v850_reloc_prefix (NULL
);
2181 /* Do normal expression parsing. */
2185 /* Create a fixup for a cons expression. If parse_cons_expression_v850
2186 found a reloc prefix, then we use that reloc, else we choose an
2187 appropriate one based on the size of the expression. */
2189 cons_fix_new_v850 (frag
, where
, size
, exp
)
2195 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
2198 hold_cons_reloc
= BFD_RELOC_32
;
2200 hold_cons_reloc
= BFD_RELOC_16
;
2202 hold_cons_reloc
= BFD_RELOC_8
;
2206 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
2208 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);