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 /* Temporarily holds the reloc in a cons expression. */
28 static bfd_reloc_code_real_type hold_cons_reloc
;
30 /* Structure to hold information about predefined registers. */
37 /* Generic assembler global variables which must be defined by all targets. */
39 /* Characters which always start a comment. */
40 const char comment_chars
[] = "#";
42 /* Characters which start a comment at the beginning of a line. */
43 const char line_comment_chars
[] = ";#";
45 /* Characters which may be used to separate multiple commands on a
47 const char line_separator_chars
[] = ";";
49 /* Characters which are used to indicate an exponent in a floating
51 const char EXP_CHARS
[] = "eE";
53 /* Characters which mean that a number is a floating point constant,
55 const char FLT_CHARS
[] = "dD";
58 const relax_typeS md_relax_table
[] = {
60 {0x1fffff, -0x200000, 6, 0},
63 /* start-sanitize-v850e */
64 static boolean support_v850e
= false;
65 /* end-sanitize-v850e */
66 /* start-sanitize-v850eq */
67 static boolean support_v850eq
= false;
68 /* end-sanitize-v850eq */
71 static unsigned long v850_insert_operand
72 PARAMS ((unsigned long insn
, const struct v850_operand
*operand
,
73 offsetT val
, char *file
, unsigned int line
));
77 #define MAX_INSN_FIXUPS (5)
82 bfd_reloc_code_real_type reloc
;
84 struct v850_fixup fixups
[MAX_INSN_FIXUPS
];
87 /* The target specific pseudo-ops which we support. */
88 const pseudo_typeS md_pseudo_table
[] =
94 /* Opcode hash table. */
95 static struct hash_control
*v850_hash
;
97 /* This table is sorted. Suitable for searching by a binary search. */
98 static const struct reg_name pre_defined_registers
[] =
100 { "ep", 30 }, /* ep - element ptr */
101 { "gp", 4 }, /* gp - global ptr */
102 { "lp", 31 }, /* lp - link ptr */
135 { "sp", 3 }, /* sp - stack ptr */
136 { "tp", 5 }, /* tp - text ptr */
139 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct reg_name))
142 static const struct reg_name system_registers
[] =
151 #define SYSREG_NAME_CNT (sizeof(system_registers) / sizeof(struct reg_name))
153 static const struct reg_name cc_names
[] =
176 #define CC_NAME_CNT (sizeof(cc_names) / sizeof(struct reg_name))
178 /* reg_name_search does a binary search of the given register table
179 to see if "name" is a valid regiter name. Returns the register
180 number from the array on success, or -1 on failure. */
183 reg_name_search (regs
, regcount
, name
)
184 const struct reg_name
*regs
;
188 int middle
, low
, high
;
196 middle
= (low
+ high
) / 2;
197 cmp
= strcasecmp (name
, regs
[middle
].name
);
203 return regs
[middle
].value
;
210 /* Summary of register_name().
212 * in: Input_line_pointer points to 1st char of operand.
214 * out: A expressionS.
215 * The operand may have been a register: in this case, X_op == O_register,
216 * X_add_number is set to the register number, and truth is returned.
217 * Input_line_pointer->(next non-blank) char after operand, or is in
218 * its original state.
221 register_name (expressionP
)
222 expressionS
*expressionP
;
229 /* Find the spelling of the operand */
230 start
= name
= input_line_pointer
;
232 c
= get_symbol_end ();
233 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
235 /* look to see if it's in the register table */
238 expressionP
->X_op
= O_register
;
239 expressionP
->X_add_number
= reg_number
;
241 /* make the rest nice */
242 expressionP
->X_add_symbol
= NULL
;
243 expressionP
->X_op_symbol
= NULL
;
244 *input_line_pointer
= c
; /* put back the delimiting char */
249 /* reset the line as if we had not done anything */
250 *input_line_pointer
= c
; /* put back the delimiting char */
251 input_line_pointer
= start
; /* reset input_line pointer */
256 /* Summary of system_register_name().
258 * in: Input_line_pointer points to 1st char of operand.
260 * out: A expressionS.
261 * The operand may have been a register: in this case, X_op == O_register,
262 * X_add_number is set to the register number, and truth is returned.
263 * Input_line_pointer->(next non-blank) char after operand, or is in
264 * its original state.
267 system_register_name (expressionP
)
268 expressionS
*expressionP
;
275 /* Find the spelling of the operand */
276 start
= name
= input_line_pointer
;
278 c
= get_symbol_end ();
279 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
);
281 /* look to see if it's in the register table */
284 expressionP
->X_op
= O_register
;
285 expressionP
->X_add_number
= reg_number
;
287 /* make the rest nice */
288 expressionP
->X_add_symbol
= NULL
;
289 expressionP
->X_op_symbol
= NULL
;
290 *input_line_pointer
= c
; /* put back the delimiting char */
295 /* reset the line as if we had not done anything */
296 *input_line_pointer
= c
; /* put back the delimiting char */
297 input_line_pointer
= start
; /* reset input_line pointer */
302 /* Summary of cc_name().
304 * in: Input_line_pointer points to 1st char of operand.
306 * out: A expressionS.
307 * The operand may have been a register: in this case, X_op == O_register,
308 * X_add_number is set to the register number, and truth is returned.
309 * Input_line_pointer->(next non-blank) char after operand, or is in
310 * its original state.
313 cc_name (expressionP
)
314 expressionS
*expressionP
;
321 /* Find the spelling of the operand */
322 start
= name
= input_line_pointer
;
324 c
= get_symbol_end ();
325 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
);
327 /* look to see if it's in the register table */
330 expressionP
->X_op
= O_constant
;
331 expressionP
->X_add_number
= reg_number
;
333 /* make the rest nice */
334 expressionP
->X_add_symbol
= NULL
;
335 expressionP
->X_op_symbol
= NULL
;
336 *input_line_pointer
= c
; /* put back the delimiting char */
341 /* reset the line as if we had not done anything */
342 *input_line_pointer
= c
; /* put back the delimiting char */
343 input_line_pointer
= start
; /* reset input_line pointer */
348 /* start-sanitize-v850e */
349 /* Summary of parse_register_list ().
351 * in: Input_line_pointer points to 1st char of a list of registers.
352 * insn is the partially constructed instruction.
353 * operand is the operand being inserted.
355 * out: True if the parse completed successfully, False otherwise.
356 * If the parse completes the correct bit fields in the
357 * instruction will be filled in.
362 unsigned long * insn
,
363 const struct v850_operand
* operand
366 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 };
367 /* start-sanitize-v850eq */
368 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 };
369 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 };
370 /* end-sanitize-v850eq */
373 /* Select a register array to parse. */
374 switch (operand
->shift
)
376 case 0xffe00001: regs
= type1_regs
; break;
377 /* start-sanitize-v850eq */
378 case 0xfff8000f: regs
= type2_regs
; break;
379 case 0xfff8001f: regs
= type3_regs
; break;
380 /* end-sanitize-v850eq */
382 fprintf (stderr
, "unknown operand shift: %x\n", operand
->shift
);
386 /* Parse the register list until a terminator (comma or new-line) is found. */
392 if (register_name (& exp
))
394 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
395 for (i
= 0; i
< 32; i
++)
397 if (regs
[ i
] == exp
.X_add_number
)
406 as_bad( "unable to insert register r%d into list\n", exp
.X_add_number
);
410 else if (system_register_name (& exp
))
412 if (regs
== type1_regs
)
414 as_bad ("system registers cannot be included in this register list" );
417 else if (exp
.X_add_number
== 5)
419 if (regs
== type2_regs
)
420 as_bad ("PSW cannot be included in this register list" );
430 /* Skip white space. */
431 while (* input_line_pointer
== ' ' || * input_line_pointer
== '\t')
432 ++ input_line_pointer
;
437 /* end-sanitize-v850e */
439 CONST
char * md_shortopts
= "m:";
441 struct option md_longopts
[] =
443 {NULL
, no_argument
, NULL
, 0}
445 size_t md_longopts_size
= sizeof md_longopts
;
449 md_show_usage (stream
)
452 fprintf (stream
, "V850 options:\n");
453 /* start-sanitize-v850e */
454 fprintf (stream
, " -mcpu=v850e target the V850E processor\n");
455 /* end-sanitize-v850e */
456 /* start-sanitize-v850eq */
457 fprintf (stream
, " -mcpu=v850eq target the V850E processor with Quantum's extensions\n");
458 /* end-sanitize-v850eq */
462 md_parse_option (c
, arg
)
466 /* start-sanitize-v850e */
467 if ((c
== 'm') && arg
!= NULL
&& (strcmp (arg
, "cpu=v850e") == 0))
469 support_v850e
= true;
472 /* end-sanitize-v850e */
474 /* start-sanitize-v850eq */
475 if ((c
== 'm') && arg
!= NULL
&& (strcmp (arg
, "cpu=v850eq") == 0))
477 support_v850e
= true;
478 support_v850eq
= true;
481 /* end-sanitize-v850eq */
487 md_undefined_symbol (name
)
494 md_atof (type
, litp
, sizep
)
500 LITTLENUM_TYPE words
[4];
516 return "bad call to md_atof";
519 t
= atof_ieee (input_line_pointer
, type
, words
);
521 input_line_pointer
= t
;
525 for (i
= prec
- 1; i
>= 0; i
--)
527 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
537 md_convert_frag (abfd
, sec
, fragP
)
542 subseg_change (sec
, 0);
543 if (fragP
->fr_subtype
== 0)
545 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
546 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
550 else if (fragP
->fr_subtype
== 1)
552 /* Reverse the condition of the first branch. */
553 fragP
->fr_literal
[0] &= 0xf7;
554 /* Mask off all the displacement bits. */
555 fragP
->fr_literal
[0] &= 0x8f;
556 fragP
->fr_literal
[1] &= 0x07;
557 /* Now set the displacement bits so that we branch
558 around the unconditional branch. */
559 fragP
->fr_literal
[0] |= 0x30;
561 /* Now create the unconditional branch + fixup to the final
563 md_number_to_chars (&fragP
->fr_literal
[2], 0x00000780, 4);
564 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
565 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
+ 1);
574 md_section_align (seg
, addr
)
578 int align
= bfd_get_section_alignment (stdoutput
, seg
);
579 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
585 char *prev_name
= "";
586 register const struct v850_opcode
*op
;
588 v850_hash
= hash_new();
590 /* Insert unique names into hash table. The V850 instruction set
591 has many identical opcode names that have different opcodes based
592 on the operands. This hash table then provides a quick index to
593 the first opcode with a particular name in the opcode table. */
598 if (strcmp (prev_name
, op
->name
))
600 prev_name
= (char *) op
->name
;
601 hash_insert (v850_hash
, op
->name
, (char *) op
);
607 static bfd_reloc_code_real_type
610 if (strncmp(input_line_pointer
, "hi0(", 4) == 0)
612 input_line_pointer
+= 3;
613 return BFD_RELOC_HI16
;
615 if (strncmp(input_line_pointer
, "hi(", 3) == 0)
617 input_line_pointer
+= 2;
618 return BFD_RELOC_HI16_S
;
620 if (strncmp (input_line_pointer
, "lo(", 3) == 0)
622 input_line_pointer
+= 2;
623 return BFD_RELOC_LO16
;
626 if (strncmp (input_line_pointer
, "sdaoff(", 7) == 0)
628 input_line_pointer
+= 6;
629 return BFD_RELOC_V850_SDA_OFFSET
;
632 if (strncmp (input_line_pointer
, "zdaoff(", 7) == 0)
634 input_line_pointer
+= 6;
635 return BFD_RELOC_V850_ZDA_OFFSET
;
638 if (strncmp (input_line_pointer
, "tdaoff(", 7) == 0)
640 input_line_pointer
+= 6;
641 return BFD_RELOC_V850_TDA_OFFSET
;
645 if (strncmp(input_line_pointer
, "(hi0(", 5) == 0)
647 input_line_pointer
+= 4;
648 return BFD_RELOC_HI16
;
650 if (strncmp(input_line_pointer
, "(hi(", 4) == 0)
652 input_line_pointer
+= 3;
653 return BFD_RELOC_HI16_S
;
655 if (strncmp (input_line_pointer
, "(lo(", 4) == 0)
657 input_line_pointer
+= 3;
658 return BFD_RELOC_LO16
;
661 if (strncmp (input_line_pointer
, "(sdaoff(", 8) == 0)
663 input_line_pointer
+= 7;
664 return BFD_RELOC_V850_SDA_OFFSET
;
667 if (strncmp (input_line_pointer
, "(zdaoff(", 8) == 0)
669 input_line_pointer
+= 7;
670 return BFD_RELOC_V850_ZDA_OFFSET
;
673 if (strncmp (input_line_pointer
, "(tdaoff(", 8) == 0)
675 input_line_pointer
+= 7;
676 return BFD_RELOC_V850_TDA_OFFSET
;
679 return BFD_RELOC_UNUSED
;
687 char * start_of_operands
;
688 struct v850_opcode
* opcode
;
689 struct v850_opcode
* next_opcode
;
690 const unsigned char * opindex_ptr
;
694 unsigned long insn_size
;
698 bfd_reloc_code_real_type reloc
;
699 boolean extra_data_after_insn
= false;
700 unsigned extra_data_len
;
701 unsigned long extra_data
;
704 /* Get the opcode. */
705 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
711 /* find the first opcode with the proper name */
712 opcode
= (struct v850_opcode
*)hash_find (v850_hash
, str
);
715 as_bad ("Unrecognized opcode: `%s'", str
);
716 ignore_rest_of_line ();
721 while (isspace (*str
))
724 start_of_operands
= str
;
728 const char * errmsg
= NULL
;
734 insn
= opcode
->opcode
;
735 extra_data_after_insn
= false;
737 input_line_pointer
= str
= start_of_operands
;
739 /* start-sanitize-v850e */
740 if ((opcode
->flags
& V850E_INSTRUCTION
) && ! support_v850e
)
742 errmsg
= "V850E instructions not allowed";
745 /* end-sanitize-v850e */
747 /* start-sanitize-v850eq */
748 if ((opcode
->flags
& V850EQ_INSTRUCTION
) && ! support_v850eq
)
750 errmsg
= "V850EQ instructions not allowed";
753 /* end-sanitize-v850eq */
755 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
757 const struct v850_operand
* operand
;
761 if (next_opindex
== 0)
763 operand
= &v850_operands
[*opindex_ptr
];
767 operand
= &v850_operands
[next_opindex
];
773 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
776 if (operand
->flags
& V850_OPERAND_RELAX
)
779 /* Gather the operand. */
780 hold
= input_line_pointer
;
781 input_line_pointer
= str
;
783 // fprintf (stderr, "operand: %s index = %d, opcode = %s\n", input_line_pointer, opindex_ptr - opcode->operands, opcode->name );
785 /* lo(), hi(), hi0(), etc... */
786 if ((reloc
= v850_reloc_prefix()) != BFD_RELOC_UNUSED
)
790 if (ex
.X_op
== O_constant
)
796 /* Truncate, then sign extend the value. */
797 int temp
= ex
.X_add_number
& 0xffff;
799 /* XXX Assumes 32bit ints! */
800 temp
= (temp
<< 16) >> 16;
801 ex
.X_add_number
= temp
;
807 /* Truncate, then sign extend the value. */
808 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
810 /* XXX Assumes 32bit ints! */
811 temp
= (temp
<< 16) >> 16;
812 ex
.X_add_number
= temp
;
816 case BFD_RELOC_HI16_S
:
818 /* Truncate, then sign extend the value. */
819 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
821 temp
+= (ex
.X_add_number
>> 15) & 1;
823 /* XXX Assumes 32bit ints! */
824 temp
= (temp
<< 16) >> 16;
825 ex
.X_add_number
= temp
;
833 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
838 if (fc
> MAX_INSN_FIXUPS
)
839 as_fatal ("too many fixups");
841 /* Adjust any offsets for sst.{h,w}/sld.{h,w} instructions */
842 if (operand
->flags
& V850_OPERAND_ADJUST_SHORT_MEMORY
)
843 ex
.X_add_number
>>= 1;
846 fixups
[fc
].opindex
= *opindex_ptr
;
847 fixups
[fc
].reloc
= reloc
;
855 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
857 if (!register_name (& ex
))
859 errmsg
= "invalid register name";
862 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
864 if (!system_register_name (& ex
))
866 errmsg
= "invalid system register name";
869 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
871 char * start
= input_line_pointer
;
872 char c
= get_symbol_end ();
874 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
876 /* Put things back the way we found them. */
877 *input_line_pointer
= c
;
878 input_line_pointer
= start
;
879 errmsg
= "expected EP register";
883 *input_line_pointer
= c
;
884 str
= input_line_pointer
;
885 input_line_pointer
= hold
;
887 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
891 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
895 errmsg
= "invalid condition code name";
898 else if (operand
->flags
& V850E_PUSH_POP
)
900 if (! parse_register_list (& insn
, operand
))
902 errmsg
= "invalid register list";
905 /* The parse_register_list() function has already done everything, so fake a dummy expression. */
906 ex
.X_op
= O_constant
;
909 else if (operand
->flags
& V850E_IMMEDIATE16
)
913 if (ex
.X_op
!= O_constant
)
914 errmsg
= "constant expression expected";
915 else if (ex
.X_add_number
& 0xffff0000)
917 if (ex
.X_add_number
& 0xffff)
918 errmsg
= "constant too big to fit into instruction";
919 else if ((insn
& 0x001fffc0) == 0x00130780)
920 ex
.X_add_number
>>= 16;
922 errmsg
= "constant too big to fit into instruction";
925 extra_data_after_insn
= true;
927 extra_data
= ex
.X_add_number
;
930 else if (operand
->flags
& V850E_IMMEDIATE32
)
934 if (ex
.X_op
!= O_constant
)
935 errmsg
= "constant expression expected";
937 extra_data_after_insn
= true;
939 extra_data
= ex
.X_add_number
;
942 else if (register_name (&ex
)
943 && (operand
->flags
& V850_OPERAND_REG
) == 0)
945 errmsg
= "syntax error: register not expected";
947 else if (system_register_name (&ex
)
948 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
950 errmsg
= "syntax error: system register not expected";
952 else if (cc_name (&ex
)
953 && (operand
->flags
& V850_OPERAND_CC
) == 0)
955 errmsg
= "syntax error: condition code not expected";
960 /* start-sanitize-v850e */
962 If we are assembling a MOV instruction (or a CALLT.... :-)
963 and the immediate value does not fit into the bits available
964 and we are supporting V850e instructions
965 then create a fake error so that the next MOV instruction
966 will be selected. This one has a 32 bit immediate field. */
968 if (((insn
& 0x07e0) == 0x0200)
969 && ex
.X_op
== O_constant
970 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1))) || ex
.X_add_number
> ((1 << operand
->bits
) - 1))
972 errmsg
= "use bigger instruction";
973 /* end-sanitize-v850e */
982 errmsg
= "illegal operand";
985 errmsg
= "missing operand";
988 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
990 errmsg
= "invalid operand";
994 if (ex
.X_add_number
== 0
995 && (operand
->shift
== 11))
997 as_warn ("register 0 being used as destination of instruction" );
1000 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1005 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1010 /* We need to generate a fixup for this expression. */
1011 if (fc
>= MAX_INSN_FIXUPS
)
1012 as_fatal ("too many fixups");
1013 fixups
[fc
].exp
= ex
;
1014 fixups
[fc
].opindex
= *opindex_ptr
;
1015 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1021 str
= input_line_pointer
;
1022 input_line_pointer
= hold
;
1024 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
1033 next_opcode
= opcode
+ 1;
1034 if (next_opcode
->opcode
!= 0 && !strcmp(next_opcode
->name
, opcode
->name
))
1036 opcode
= next_opcode
;
1040 as_bad ("%s", errmsg
);
1041 ignore_rest_of_line ();
1047 while (isspace (*str
))
1051 as_bad ("junk at end of line: `%s'", str
);
1053 input_line_pointer
= str
;
1055 /* Write out the instruction.
1057 Four byte insns have an opcode with the two high bits on. */
1058 if (relaxable
&& fc
> 0)
1060 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
1061 fixups
[0].exp
.X_add_symbol
,
1062 fixups
[0].exp
.X_add_number
,
1063 (char *)fixups
[0].opindex
);
1065 md_number_to_chars (f
, insn
, insn_size
);
1066 md_number_to_chars (f
+ 2, 0, 4);
1071 if ((insn
& 0x0600) == 0x0600)
1076 /* Special case: 32 bit MOV */
1077 if ((insn
& 0xffe0) == 0x0620)
1080 f
= frag_more (insn_size
);
1082 md_number_to_chars (f
, insn
, insn_size
);
1084 if (extra_data_after_insn
)
1086 f
= frag_more (extra_data_len
);
1087 md_number_to_chars (f
, extra_data
, extra_data_len
);
1089 extra_data_after_insn
= false;
1093 /* Create any fixups. At this point we do not use a
1094 bfd_reloc_code_real_type, but instead just use the
1095 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1096 handle fixups for any operand type, although that is admittedly
1097 not a very exciting feature. We pick a BFD reloc type in
1099 for (i
= 0; i
< fc
; i
++)
1101 const struct v850_operand
*operand
;
1103 operand
= &v850_operands
[fixups
[i
].opindex
];
1104 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1106 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1114 size
= bfd_get_reloc_size (reloc_howto
);
1116 /* The "size" of a TDA_OFFSET reloc varies depending
1117 on what kind of instruction it's used in! */
1118 if (reloc_howto
->type
== 11 && insn_size
> 2)
1121 if (size
< 1 || size
> 4)
1125 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1127 reloc_howto
->pc_relative
,
1130 switch (fixups
[i
].reloc
)
1132 case BFD_RELOC_LO16
:
1133 case BFD_RELOC_HI16
:
1134 case BFD_RELOC_HI16_S
:
1135 fixP
->fx_no_overflow
= 1;
1141 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1143 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
1144 ((bfd_reloc_code_real_type
)
1145 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1151 /* if while processing a fixup, a reloc really needs to be created */
1152 /* then it is done here */
1155 tc_gen_reloc (seg
, fixp
)
1160 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1161 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
1162 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1163 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1164 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1166 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1167 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
1170 reloc
->addend
= fixp
->fx_addnumber
;
1171 /* printf("tc_gen_reloc: addr=%x addend=%x\n", reloc->address, reloc->addend); */
1175 /* Assume everything will fit in two bytes, then expand as necessary. */
1177 md_estimate_size_before_relax (fragp
, seg
)
1187 md_pcrel_from (fixp
)
1190 /* If the symbol is undefined, or in a section other than our own,
1191 then let the linker figure it out. */
1192 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
1194 /* The symbol is undefined. Let the linker figure it out. */
1197 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1201 md_apply_fix3 (fixp
, valuep
, seg
)
1209 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
1214 else if (fixp
->fx_pcrel
)
1218 value
= fixp
->fx_offset
;
1219 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
1221 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
1222 value
-= S_GET_VALUE (fixp
->fx_subsy
);
1225 /* We don't actually support subtracting a symbol. */
1226 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1227 "expression too complex");
1232 /* printf("md_apply_fix: value=0x%x type=%d\n", value, fixp->fx_r_type); */
1234 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1237 const struct v850_operand
*operand
;
1241 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1242 operand
= &v850_operands
[opindex
];
1244 /* Fetch the instruction, insert the fully resolved operand
1245 value, and stuff the instruction back again.
1247 Note the instruction has been stored in little endian
1249 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1251 insn
= bfd_getl32((unsigned char *) where
);
1252 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
1253 fixp
->fx_file
, fixp
->fx_line
);
1254 bfd_putl32((bfd_vma
) insn
, (unsigned char *) where
);
1258 /* Nothing else to do here. */
1262 /* Determine a BFD reloc value based on the operand information.
1263 We are only prepared to turn a few of the operands into relocs. */
1265 if (operand
->bits
== 22)
1266 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
1267 else if (operand
->bits
== 9)
1268 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
1271 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
1272 "unresolved expression that must be resolved");
1277 else if (fixp
->fx_done
)
1279 /* We still have to insert the value into memory! */
1280 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1281 if (fixp
->fx_size
== 1)
1282 *where
= value
& 0xff;
1283 if (fixp
->fx_size
== 2)
1284 bfd_putl16(value
& 0xffff, (unsigned char *) where
);
1285 if (fixp
->fx_size
== 4)
1286 bfd_putl32(value
, (unsigned char *) where
);
1289 fixp
->fx_addnumber
= value
;
1294 /* Insert an operand value into an instruction. */
1296 static unsigned long
1297 v850_insert_operand (insn
, operand
, val
, file
, line
)
1299 const struct v850_operand
* operand
;
1304 if (operand
->bits
!= 32)
1309 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1311 max
= (1 << (operand
->bits
- 1)) - 1;
1312 min
= - (1 << (operand
->bits
- 1));
1316 max
= (1 << operand
->bits
) - 1;
1322 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1325 "operand out of range (%s not between %ld and %ld)";
1328 sprint_value (buf
, test
);
1329 if (file
== (char *) NULL
)
1330 as_warn (err
, buf
, min
, max
);
1332 as_warn_where (file
, line
, err
, buf
, min
, max
);
1336 if (operand
->insert
)
1338 const char * message
= NULL
;
1340 insn
= (*operand
->insert
) (insn
, val
, & message
);
1341 if (message
!= NULL
)
1343 if (file
== (char *) NULL
)
1346 as_warn_where (file
, line
, message
);
1350 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1355 /* Parse a cons expression. We have to handle hi(), lo(), etc
1358 parse_cons_expression_v850 (exp
)
1361 /* See if there's a reloc prefix like hi() we have to handle. */
1362 hold_cons_reloc
= v850_reloc_prefix ();
1364 /* Do normal expression parsing. */
1368 /* Create a fixup for a cons expression. If parse_cons_expression_v850
1369 found a reloc prefix, then we use that reloc, else we choose an
1370 appropriate one based on the size of the expression. */
1372 cons_fix_new_v850 (frag
, where
, size
, exp
)
1378 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
1381 hold_cons_reloc
= BFD_RELOC_32
;
1383 hold_cons_reloc
= BFD_RELOC_16
;
1385 hold_cons_reloc
= BFD_RELOC_8
;
1389 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
1391 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);