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 /* Structure to hold information about predefined registers. */
40 /* Generic assembler global variables which must be defined by all targets. */
42 /* Characters which always start a comment. */
43 const char comment_chars
[] = "#";
45 /* Characters which start a comment at the beginning of a line. */
46 const char line_comment_chars
[] = ";#";
48 /* Characters which may be used to separate multiple commands on a
50 const char line_separator_chars
[] = ";";
52 /* Characters which are used to indicate an exponent in a floating
54 const char EXP_CHARS
[] = "eE";
56 /* Characters which mean that a number is a floating point constant,
58 const char FLT_CHARS
[] = "dD";
61 const relax_typeS md_relax_table
[] = {
63 {0x1fffff, -0x200000, 6, 0},
68 static unsigned long v850_insert_operand
69 PARAMS ((unsigned long insn
, const struct v850_operand
*operand
,
70 offsetT val
, char *file
, unsigned int line
));
74 #define MAX_INSN_FIXUPS (5)
79 bfd_reloc_code_real_type reloc
;
81 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
85 v850_section (int arg
)
90 for (ptr
= input_line_pointer
; * ptr
!= '\n' && * ptr
!= 0; ptr
++)
91 if (* ptr
== ',' && ptr
[1] == '.')
97 obj_elf_section (arg
);
103 v850_bss (int ignore
)
105 register int temp
= get_absolute_expression ();
107 subseg_set (bss_section
, (subsegT
) temp
);
109 demand_empty_rest_of_line ();
113 v850_offset (int ignore
)
115 register int temp
= get_absolute_expression ();
117 subseg_set (now_seg
, (subsegT
) temp
);
119 demand_empty_rest_of_line ();
122 /* The target specific pseudo-ops which we support. */
123 const pseudo_typeS md_pseudo_table
[] =
125 {"bss", v850_bss
, 0},
126 {"offset", v850_offset
, 0},
127 {"section", v850_section
, 0},
132 /* Opcode hash table. */
133 static struct hash_control
*v850_hash
;
135 /* This table is sorted. Suitable for searching by a binary search. */
136 static const struct reg_name pre_defined_registers
[] =
138 { "ep", 30 }, /* ep - element ptr */
139 { "gp", 4 }, /* gp - global ptr */
140 { "lp", 31 }, /* lp - link ptr */
173 { "sp", 3 }, /* sp - stack ptr */
174 { "tp", 5 }, /* tp - text ptr */
177 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct reg_name))
180 static const struct reg_name system_registers
[] =
182 /* start-sanitize-v850e */
188 /* end-sanitize-v850e */
196 #define SYSREG_NAME_CNT (sizeof (system_registers) / sizeof (struct reg_name))
198 static const struct reg_name cc_names
[] =
221 #define CC_NAME_CNT (sizeof(cc_names) / sizeof(struct reg_name))
223 /* reg_name_search does a binary search of the given register table
224 to see if "name" is a valid regiter name. Returns the register
225 number from the array on success, or -1 on failure. */
228 reg_name_search (regs
, regcount
, name
)
229 const struct reg_name
*regs
;
233 int middle
, low
, high
;
241 middle
= (low
+ high
) / 2;
242 cmp
= strcasecmp (name
, regs
[middle
].name
);
248 return regs
[middle
].value
;
255 /* Summary of register_name().
257 * in: Input_line_pointer points to 1st char of operand.
259 * out: A expressionS.
260 * The operand may have been a register: in this case, X_op == O_register,
261 * X_add_number is set to the register number, and truth is returned.
262 * Input_line_pointer->(next non-blank) char after operand, or is in
263 * its original state.
266 register_name (expressionP
)
267 expressionS
*expressionP
;
274 /* Find the spelling of the operand */
275 start
= name
= input_line_pointer
;
277 c
= get_symbol_end ();
278 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
280 /* look to see if it's in the register table */
283 expressionP
->X_op
= O_register
;
284 expressionP
->X_add_number
= reg_number
;
286 /* make the rest nice */
287 expressionP
->X_add_symbol
= NULL
;
288 expressionP
->X_op_symbol
= NULL
;
289 *input_line_pointer
= c
; /* put back the delimiting char */
294 /* reset the line as if we had not done anything */
295 *input_line_pointer
= c
; /* put back the delimiting char */
296 input_line_pointer
= start
; /* reset input_line pointer */
301 /* Summary of system_register_name().
303 * in: Input_line_pointer points to 1st char of operand.
305 * out: A expressionS.
306 * The operand may have been a register: in this case, X_op == O_register,
307 * X_add_number is set to the register number, and truth is returned.
308 * Input_line_pointer->(next non-blank) char after operand, or is in
309 * its original state.
312 system_register_name (expressionP
, accept_numbers
)
313 expressionS
* expressionP
;
314 boolean accept_numbers
;
321 /* Find the spelling of the operand */
322 start
= name
= input_line_pointer
;
324 c
= get_symbol_end ();
325 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
);
330 * input_line_pointer
= c
; /* put back the delimiting char */
331 input_line_pointer
= start
; /* reset input_line pointer */
333 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
335 /* Make sure that the register number is allowable. */
338 /* start-sanitize-v850e */
341 /* end-sanitize-v850e */
348 c
= * input_line_pointer
;
352 /* look to see if it's in the register table */
355 expressionP
->X_op
= O_register
;
356 expressionP
->X_add_number
= reg_number
;
358 /* make the rest nice */
359 expressionP
->X_add_symbol
= NULL
;
360 expressionP
->X_op_symbol
= NULL
;
361 *input_line_pointer
= c
; /* put back the delimiting char */
366 /* reset the line as if we had not done anything */
367 *input_line_pointer
= c
; /* put back the delimiting char */
368 input_line_pointer
= start
; /* reset input_line pointer */
373 /* Summary of cc_name().
375 * in: Input_line_pointer points to 1st char of operand.
377 * out: A expressionS.
378 * The operand may have been a register: in this case, X_op == O_register,
379 * X_add_number is set to the register number, and truth is returned.
380 * Input_line_pointer->(next non-blank) char after operand, or is in
381 * its original state.
384 cc_name (expressionP
)
385 expressionS
*expressionP
;
392 /* Find the spelling of the operand */
393 start
= name
= input_line_pointer
;
395 c
= get_symbol_end ();
396 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
);
398 /* look to see if it's in the register table */
401 expressionP
->X_op
= O_constant
;
402 expressionP
->X_add_number
= reg_number
;
404 /* make the rest nice */
405 expressionP
->X_add_symbol
= NULL
;
406 expressionP
->X_op_symbol
= NULL
;
407 *input_line_pointer
= c
; /* put back the delimiting char */
412 /* reset the line as if we had not done anything */
413 *input_line_pointer
= c
; /* put back the delimiting char */
414 input_line_pointer
= start
; /* reset input_line pointer */
419 /* start-sanitize-v850e */
420 /* Summary of parse_register_list ().
422 * in: Input_line_pointer points to 1st char of a list of registers.
423 * insn is the partially constructed instruction.
424 * operand is the operand being inserted.
426 * out: True if the parse completed successfully, False otherwise.
427 * If the parse completes the correct bit fields in the
428 * instruction will be filled in.
433 unsigned long * insn
,
434 const struct v850_operand
* operand
437 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 };
438 /* start-sanitize-v850eq */
439 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 };
440 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 };
441 /* end-sanitize-v850eq */
444 /* Select a register array to parse. */
445 switch (operand
->shift
)
447 case 0xffe00001: regs
= type1_regs
; break;
448 /* start-sanitize-v850eq */
449 case 0xfff8000f: regs
= type2_regs
; break;
450 case 0xfff8001f: regs
= type3_regs
; break;
451 /* end-sanitize-v850eq */
453 fprintf (stderr
, "unknown operand shift: %x\n", operand
->shift
);
457 /* Parse the register list until a terminator (comma or new-line) is found. */
463 if (register_name (& exp
))
465 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
466 for (i
= 0; i
< 32; i
++)
468 if (regs
[ i
] == exp
.X_add_number
)
477 as_bad( "unable to insert register r%d into list\n", exp
.X_add_number
);
481 else if (system_register_name (& exp
, true))
483 if (regs
== type1_regs
)
485 as_bad ("system registers cannot be included in this register list" );
488 else if (exp
.X_add_number
== 5)
490 if (regs
== type2_regs
)
491 as_bad ("PSW cannot be included in this register list" );
501 /* Skip white space. */
502 while (* input_line_pointer
== ' ' || * input_line_pointer
== '\t')
503 ++ input_line_pointer
;
508 /* end-sanitize-v850e */
510 CONST
char * md_shortopts
= "m:";
512 struct option md_longopts
[] =
514 {NULL
, no_argument
, NULL
, 0}
516 size_t md_longopts_size
= sizeof md_longopts
;
520 md_show_usage (stream
)
523 fprintf (stream
, "V850 options:\n");
524 fprintf (stream
, "\tnone at present\n");
528 md_parse_option (c
, arg
)
536 md_undefined_symbol (name
)
543 md_atof (type
, litp
, sizep
)
549 LITTLENUM_TYPE words
[4];
565 return "bad call to md_atof";
568 t
= atof_ieee (input_line_pointer
, type
, words
);
570 input_line_pointer
= t
;
574 for (i
= prec
- 1; i
>= 0; i
--)
576 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
586 md_convert_frag (abfd
, sec
, fragP
)
591 subseg_change (sec
, 0);
592 if (fragP
->fr_subtype
== 0)
594 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
595 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
599 else if (fragP
->fr_subtype
== 1)
601 /* Reverse the condition of the first branch. */
602 fragP
->fr_literal
[0] &= 0xf7;
603 /* Mask off all the displacement bits. */
604 fragP
->fr_literal
[0] &= 0x8f;
605 fragP
->fr_literal
[1] &= 0x07;
606 /* Now set the displacement bits so that we branch
607 around the unconditional branch. */
608 fragP
->fr_literal
[0] |= 0x30;
610 /* Now create the unconditional branch + fixup to the final
612 md_number_to_chars (&fragP
->fr_literal
[2], 0x00000780, 4);
613 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
614 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
+ 1);
623 md_section_align (seg
, addr
)
627 int align
= bfd_get_section_alignment (stdoutput
, seg
);
628 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
634 char *prev_name
= "";
635 register const struct v850_opcode
*op
;
637 v850_hash
= hash_new();
639 /* Insert unique names into hash table. The V850 instruction set
640 has many identical opcode names that have different opcodes based
641 on the operands. This hash table then provides a quick index to
642 the first opcode with a particular name in the opcode table. */
647 if (strcmp (prev_name
, op
->name
))
649 prev_name
= (char *) op
->name
;
650 hash_insert (v850_hash
, op
->name
, (char *) op
);
656 static bfd_reloc_code_real_type
659 if (strncmp(input_line_pointer
, "hi0(", 4) == 0)
661 input_line_pointer
+= 3;
662 return BFD_RELOC_HI16
;
664 if (strncmp(input_line_pointer
, "hi(", 3) == 0)
666 input_line_pointer
+= 2;
667 return BFD_RELOC_HI16_S
;
669 if (strncmp (input_line_pointer
, "lo(", 3) == 0)
671 input_line_pointer
+= 2;
672 return BFD_RELOC_LO16
;
675 if (strncmp (input_line_pointer
, "sdaoff(", 7) == 0)
677 input_line_pointer
+= 6;
678 return BFD_RELOC_V850_SDA_OFFSET
;
681 if (strncmp (input_line_pointer
, "zdaoff(", 7) == 0)
683 input_line_pointer
+= 6;
684 return BFD_RELOC_V850_ZDA_OFFSET
;
687 if (strncmp (input_line_pointer
, "tdaoff(", 7) == 0)
689 input_line_pointer
+= 6;
690 return BFD_RELOC_V850_TDA_OFFSET
;
694 if (strncmp(input_line_pointer
, "(hi0(", 5) == 0)
696 input_line_pointer
+= 4;
697 return BFD_RELOC_HI16
;
699 if (strncmp(input_line_pointer
, "(hi(", 4) == 0)
701 input_line_pointer
+= 3;
702 return BFD_RELOC_HI16_S
;
704 if (strncmp (input_line_pointer
, "(lo(", 4) == 0)
706 input_line_pointer
+= 3;
707 return BFD_RELOC_LO16
;
710 if (strncmp (input_line_pointer
, "(sdaoff(", 8) == 0)
712 input_line_pointer
+= 7;
713 return BFD_RELOC_V850_SDA_OFFSET
;
716 if (strncmp (input_line_pointer
, "(zdaoff(", 8) == 0)
718 input_line_pointer
+= 7;
719 return BFD_RELOC_V850_ZDA_OFFSET
;
722 if (strncmp (input_line_pointer
, "(tdaoff(", 8) == 0)
724 input_line_pointer
+= 7;
725 return BFD_RELOC_V850_TDA_OFFSET
;
728 return BFD_RELOC_UNUSED
;
736 char * start_of_operands
;
737 struct v850_opcode
* opcode
;
738 struct v850_opcode
* next_opcode
;
739 const unsigned char * opindex_ptr
;
743 unsigned long insn_size
;
747 bfd_reloc_code_real_type reloc
;
748 boolean extra_data_after_insn
= false;
749 unsigned extra_data_len
;
750 unsigned long extra_data
;
753 /* Get the opcode. */
754 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
760 /* find the first opcode with the proper name */
761 opcode
= (struct v850_opcode
*)hash_find (v850_hash
, str
);
764 as_bad ("Unrecognized opcode: `%s'", str
);
765 ignore_rest_of_line ();
770 while (isspace (*str
))
773 start_of_operands
= str
;
777 const char * errmsg
= NULL
;
783 insn
= opcode
->opcode
;
784 extra_data_after_insn
= false;
786 input_line_pointer
= str
= start_of_operands
;
788 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
790 const struct v850_operand
* operand
;
794 if (next_opindex
== 0)
796 operand
= &v850_operands
[*opindex_ptr
];
800 operand
= &v850_operands
[next_opindex
];
806 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
809 if (operand
->flags
& V850_OPERAND_RELAX
)
812 /* Gather the operand. */
813 hold
= input_line_pointer
;
814 input_line_pointer
= str
;
816 //fprintf (stderr, "operand: %s index = %d, opcode = %s\n", input_line_pointer, opindex_ptr - opcode->operands, opcode->name );
818 /* lo(), hi(), hi0(), etc... */
819 if ((reloc
= v850_reloc_prefix()) != BFD_RELOC_UNUSED
)
823 if (ex
.X_op
== O_constant
)
829 /* Truncate, then sign extend the value. */
830 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
836 /* Truncate, then sign extend the value. */
837 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
841 case BFD_RELOC_HI16_S
:
843 /* Truncate, then sign extend the value. */
844 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
846 temp
+= (ex
.X_add_number
>> 15) & 1;
848 ex
.X_add_number
= SEXT16 (temp
);
856 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
861 if (fc
> MAX_INSN_FIXUPS
)
862 as_fatal ("too many fixups");
864 /* Adjust any offsets for sst.{h,w}/sld.{h,w} instructions */
865 if (operand
->flags
& V850_OPERAND_ADJUST_SHORT_MEMORY
)
866 ex
.X_add_number
>>= 1;
869 fixups
[fc
].opindex
= *opindex_ptr
;
870 fixups
[fc
].reloc
= reloc
;
878 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
880 if (!register_name (& ex
))
882 errmsg
= "invalid register name";
885 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
887 if (!system_register_name (& ex
, true))
889 errmsg
= "UGG invalid system register name";
892 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
894 char * start
= input_line_pointer
;
895 char c
= get_symbol_end ();
897 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
899 /* Put things back the way we found them. */
900 *input_line_pointer
= c
;
901 input_line_pointer
= start
;
902 errmsg
= "expected EP register";
906 *input_line_pointer
= c
;
907 str
= input_line_pointer
;
908 input_line_pointer
= hold
;
910 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
914 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
918 errmsg
= "invalid condition code name";
921 else if (operand
->flags
& V850E_PUSH_POP
)
923 if (! parse_register_list (& insn
, operand
))
925 errmsg
= "invalid register list";
928 /* The parse_register_list() function has already done everything, so fake a dummy expression. */
929 ex
.X_op
= O_constant
;
932 else if (operand
->flags
& V850E_IMMEDIATE16
)
936 if (ex
.X_op
!= O_constant
)
937 errmsg
= "constant expression expected";
938 else if (ex
.X_add_number
& 0xffff0000)
940 if (ex
.X_add_number
& 0xffff)
941 errmsg
= "constant too big to fit into instruction";
942 else if ((insn
& 0x001fffc0) == 0x00130780)
943 ex
.X_add_number
>>= 16;
945 errmsg
= "constant too big to fit into instruction";
948 extra_data_after_insn
= true;
950 extra_data
= ex
.X_add_number
;
953 else if (operand
->flags
& V850E_IMMEDIATE32
)
957 if (ex
.X_op
!= O_constant
)
958 errmsg
= "constant expression expected";
960 extra_data_after_insn
= true;
962 extra_data
= ex
.X_add_number
;
965 else if (register_name (&ex
)
966 && (operand
->flags
& V850_OPERAND_REG
) == 0)
968 errmsg
= "syntax error: register not expected";
970 else if (system_register_name (& ex
, false)
971 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
973 errmsg
= "syntax error: system register not expected";
975 else if (cc_name (&ex
)
976 && (operand
->flags
& V850_OPERAND_CC
) == 0)
978 errmsg
= "syntax error: condition code not expected";
983 /* start-sanitize-v850e */
985 If we are assembling a MOV instruction (or a CALLT.... :-)
986 and the immediate value does not fit into the bits available
987 then create a fake error so that the next MOV instruction
988 will be selected. This one has a 32 bit immediate field. */
990 if (((insn
& 0x07e0) == 0x0200)
991 && ex
.X_op
== O_constant
992 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1))) || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
993 errmsg
= "use bigger instruction";
994 /* end-sanitize-v850e */
1000 //fprintf (stderr, "insn: %x, operand %d, op: %d, add_number: %d\n", insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number );
1005 errmsg
= "illegal operand";
1008 errmsg
= "missing operand";
1011 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
1013 errmsg
= "invalid operand";
1016 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1021 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1026 /* We need to generate a fixup for this expression. */
1027 if (fc
>= MAX_INSN_FIXUPS
)
1028 as_fatal ("too many fixups");
1029 fixups
[fc
].exp
= ex
;
1030 fixups
[fc
].opindex
= *opindex_ptr
;
1031 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1037 str
= input_line_pointer
;
1038 input_line_pointer
= hold
;
1040 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
1049 next_opcode
= opcode
+ 1;
1050 if (next_opcode
->opcode
!= 0 && !strcmp(next_opcode
->name
, opcode
->name
))
1052 opcode
= next_opcode
;
1056 as_bad ("%s", errmsg
);
1057 ignore_rest_of_line ();
1063 while (isspace (*str
))
1067 as_bad ("junk at end of line: `%s'", str
);
1069 input_line_pointer
= str
;
1071 /* Write out the instruction.
1073 Four byte insns have an opcode with the two high bits on. */
1074 if (relaxable
&& fc
> 0)
1076 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
1077 fixups
[0].exp
.X_add_symbol
,
1078 fixups
[0].exp
.X_add_number
,
1079 (char *)fixups
[0].opindex
);
1081 md_number_to_chars (f
, insn
, insn_size
);
1082 md_number_to_chars (f
+ 2, 0, 4);
1087 if ((insn
& 0x0600) == 0x0600)
1092 /* start-sanitize-v850e */
1093 /* Special case: 32 bit MOV */
1094 if ((insn
& 0xffe0) == 0x0620)
1096 /* end_sanitize-v850e */
1098 f
= frag_more (insn_size
);
1100 md_number_to_chars (f
, insn
, insn_size
);
1102 if (extra_data_after_insn
)
1104 f
= frag_more (extra_data_len
);
1105 md_number_to_chars (f
, extra_data
, extra_data_len
);
1107 extra_data_after_insn
= false;
1111 /* Create any fixups. At this point we do not use a
1112 bfd_reloc_code_real_type, but instead just use the
1113 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1114 handle fixups for any operand type, although that is admittedly
1115 not a very exciting feature. We pick a BFD reloc type in
1117 for (i
= 0; i
< fc
; i
++)
1119 const struct v850_operand
*operand
;
1121 operand
= &v850_operands
[fixups
[i
].opindex
];
1122 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1124 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1132 size
= bfd_get_reloc_size (reloc_howto
);
1134 /* The "size" of a TDA_OFFSET reloc varies depending
1135 on what kind of instruction it's used in! */
1136 if (reloc_howto
->type
== 11 && insn_size
> 2)
1139 if (size
< 1 || size
> 4)
1143 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1145 reloc_howto
->pc_relative
,
1148 switch (fixups
[i
].reloc
)
1150 case BFD_RELOC_LO16
:
1151 case BFD_RELOC_HI16
:
1152 case BFD_RELOC_HI16_S
:
1153 fixP
->fx_no_overflow
= 1;
1159 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1161 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
1162 ((bfd_reloc_code_real_type
)
1163 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1169 /* if while processing a fixup, a reloc really needs to be created */
1170 /* then it is done here */
1173 tc_gen_reloc (seg
, fixp
)
1178 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1179 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
1180 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1181 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1182 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1184 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1185 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
1188 reloc
->addend
= fixp
->fx_addnumber
;
1189 /* printf("tc_gen_reloc: addr=%x addend=%x\n", reloc->address, reloc->addend); */
1193 /* Assume everything will fit in two bytes, then expand as necessary. */
1195 md_estimate_size_before_relax (fragp
, seg
)
1205 md_pcrel_from (fixp
)
1208 /* If the symbol is undefined, or in a section other than our own,
1209 then let the linker figure it out. */
1210 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
1212 /* The symbol is undefined. Let the linker figure it out. */
1215 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1219 md_apply_fix3 (fixp
, valuep
, seg
)
1227 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
1232 else if (fixp
->fx_pcrel
)
1236 value
= fixp
->fx_offset
;
1237 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
1239 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
1240 value
-= S_GET_VALUE (fixp
->fx_subsy
);
1243 /* We don't actually support subtracting a symbol. */
1244 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1245 "expression too complex");
1250 /* printf("md_apply_fix: value=0x%x type=%d\n", value, fixp->fx_r_type); */
1252 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1255 const struct v850_operand
*operand
;
1259 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1260 operand
= &v850_operands
[opindex
];
1262 /* Fetch the instruction, insert the fully resolved operand
1263 value, and stuff the instruction back again.
1265 Note the instruction has been stored in little endian
1267 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1269 insn
= bfd_getl32((unsigned char *) where
);
1270 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
1271 fixp
->fx_file
, fixp
->fx_line
);
1272 bfd_putl32((bfd_vma
) insn
, (unsigned char *) where
);
1276 /* Nothing else to do here. */
1280 /* Determine a BFD reloc value based on the operand information.
1281 We are only prepared to turn a few of the operands into relocs. */
1283 if (operand
->bits
== 22)
1284 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
1285 else if (operand
->bits
== 9)
1286 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
1287 else if (operand
->bits
== 16)
1288 fixp
->fx_r_type
= BFD_RELOC_V850_16_PCREL
;
1291 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
1292 "unresolved expression that must be resolved");
1297 else if (fixp
->fx_done
)
1299 /* We still have to insert the value into memory! */
1300 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1301 if (fixp
->fx_size
== 1)
1302 *where
= value
& 0xff;
1303 if (fixp
->fx_size
== 2)
1304 bfd_putl16(value
& 0xffff, (unsigned char *) where
);
1305 if (fixp
->fx_size
== 4)
1306 bfd_putl32(value
, (unsigned char *) where
);
1309 fixp
->fx_addnumber
= value
;
1314 /* Insert an operand value into an instruction. */
1316 static unsigned long
1317 v850_insert_operand (insn
, operand
, val
, file
, line
)
1319 const struct v850_operand
* operand
;
1324 if (operand
->bits
!= 32)
1329 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1331 max
= (1 << (operand
->bits
- 1)) - 1;
1332 min
= - (1 << (operand
->bits
- 1));
1336 max
= (1 << operand
->bits
) - 1;
1342 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1345 "operand out of range (%s not between %ld and %ld)";
1348 sprint_value (buf
, test
);
1349 if (file
== (char *) NULL
)
1350 as_warn (err
, buf
, min
, max
);
1352 as_warn_where (file
, line
, err
, buf
, min
, max
);
1356 if (operand
->insert
)
1358 const char * message
= NULL
;
1360 insn
= (*operand
->insert
) (insn
, val
, & message
);
1361 if (message
!= NULL
)
1363 if (file
== (char *) NULL
)
1366 as_warn_where (file
, line
, message
);
1370 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1375 /* Parse a cons expression. We have to handle hi(), lo(), etc
1378 parse_cons_expression_v850 (exp
)
1381 /* See if there's a reloc prefix like hi() we have to handle. */
1382 hold_cons_reloc
= v850_reloc_prefix ();
1384 /* Do normal expression parsing. */
1388 /* Create a fixup for a cons expression. If parse_cons_expression_v850
1389 found a reloc prefix, then we use that reloc, else we choose an
1390 appropriate one based on the size of the expression. */
1392 cons_fix_new_v850 (frag
, where
, size
, exp
)
1398 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
1401 hold_cons_reloc
= BFD_RELOC_32
;
1403 hold_cons_reloc
= BFD_RELOC_16
;
1405 hold_cons_reloc
= BFD_RELOC_8
;
1409 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
1411 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);