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
[] =
223 #define CC_NAME_CNT (sizeof(cc_names) / sizeof(struct reg_name))
225 /* reg_name_search does a binary search of the given register table
226 to see if "name" is a valid regiter name. Returns the register
227 number from the array on success, or -1 on failure. */
230 reg_name_search (regs
, regcount
, name
)
231 const struct reg_name
*regs
;
235 int middle
, low
, high
;
243 middle
= (low
+ high
) / 2;
244 cmp
= strcasecmp (name
, regs
[middle
].name
);
250 return regs
[middle
].value
;
257 /* Summary of register_name().
259 * in: Input_line_pointer points to 1st char of operand.
261 * out: A expressionS.
262 * The operand may have been a register: in this case, X_op == O_register,
263 * X_add_number is set to the register number, and truth is returned.
264 * Input_line_pointer->(next non-blank) char after operand, or is in
265 * its original state.
268 register_name (expressionP
)
269 expressionS
*expressionP
;
276 /* Find the spelling of the operand */
277 start
= name
= input_line_pointer
;
279 c
= get_symbol_end ();
281 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
283 * input_line_pointer
= c
; /* put back the delimiting char */
285 /* look to see if it's in the register table */
288 expressionP
->X_op
= O_register
;
289 expressionP
->X_add_number
= reg_number
;
291 /* make the rest nice */
292 expressionP
->X_add_symbol
= NULL
;
293 expressionP
->X_op_symbol
= NULL
;
299 /* reset the line as if we had not done anything */
300 input_line_pointer
= start
;
306 /* Summary of system_register_name().
308 * in: Input_line_pointer points to 1st char of operand.
310 * out: A expressionS.
311 * The operand may have been a register: in this case, X_op == O_register,
312 * X_add_number is set to the register number, and truth is returned.
313 * Input_line_pointer->(next non-blank) char after operand, or is in
314 * its original state.
317 system_register_name (expressionP
, accept_numbers
)
318 expressionS
* expressionP
;
319 boolean accept_numbers
;
326 /* Find the spelling of the operand */
327 start
= name
= input_line_pointer
;
329 c
= get_symbol_end ();
330 reg_number
= reg_name_search (system_registers
, SYSREG_NAME_CNT
, name
);
332 * input_line_pointer
= c
; /* put back the delimiting char */
337 input_line_pointer
= start
; /* reset input_line pointer */
339 if (isdigit (* input_line_pointer
))
340 reg_number
= strtol (input_line_pointer
, & input_line_pointer
, 10);
342 /* Make sure that the register number is allowable. */
345 /* start-sanitize-v850e */
348 /* end-sanitize-v850e */
355 /* look to see if it's in the register table */
358 expressionP
->X_op
= O_register
;
359 expressionP
->X_add_number
= reg_number
;
361 /* make the rest nice */
362 expressionP
->X_add_symbol
= NULL
;
363 expressionP
->X_op_symbol
= NULL
;
369 /* reset the line as if we had not done anything */
370 input_line_pointer
= start
;
376 /* Summary of cc_name().
378 * in: Input_line_pointer points to 1st char of operand.
380 * out: A expressionS.
381 * The operand may have been a register: in this case, X_op == O_register,
382 * X_add_number is set to the register number, and truth is returned.
383 * Input_line_pointer->(next non-blank) char after operand, or is in
384 * its original state.
387 cc_name (expressionP
)
388 expressionS
*expressionP
;
395 /* Find the spelling of the operand */
396 start
= name
= input_line_pointer
;
398 c
= get_symbol_end ();
399 reg_number
= reg_name_search (cc_names
, CC_NAME_CNT
, name
);
401 * input_line_pointer
= c
; /* put back the delimiting char */
403 /* look to see if it's in the register table */
406 expressionP
->X_op
= O_constant
;
407 expressionP
->X_add_number
= reg_number
;
409 /* make the rest nice */
410 expressionP
->X_add_symbol
= NULL
;
411 expressionP
->X_op_symbol
= NULL
;
417 /* reset the line as if we had not done anything */
418 input_line_pointer
= start
;
425 skip_white_space (void)
427 while ( * input_line_pointer
== ' '
428 || * input_line_pointer
== '\t')
429 ++ input_line_pointer
;
432 /* start-sanitize-v850e */
433 /* Summary of parse_register_list ().
435 * in: Input_line_pointer points to 1st char of a list of registers.
436 * insn is the partially constructed instruction.
437 * operand is the operand being inserted.
439 * out: True if the parse completed successfully, False otherwise.
440 * If the parse completes the correct bit fields in the
441 * instruction will be filled in.
446 unsigned long * insn
,
447 const struct v850_operand
* operand
450 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 };
451 /* start-sanitize-v850eq */
452 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 };
453 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 };
454 /* end-sanitize-v850eq */
457 /* Select a register array to parse. */
458 switch (operand
->shift
)
460 case 0xffe00001: regs
= type1_regs
; break;
461 /* start-sanitize-v850eq */
462 case 0xfff8000f: regs
= type2_regs
; break;
463 case 0xfff8001f: regs
= type3_regs
; break;
464 /* end-sanitize-v850eq */
466 as_bad ("unknown operand shift: %x\n", operand
->shift
);
472 if (* input_line_pointer
!= '{')
474 as_bad ("no opening curly brace at start of register list\n");
478 input_line_pointer
++;
480 /* Parse the register list until a terminator (closing curly brace or new-line) is found. */
485 if (register_name (& exp
))
489 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
490 for (i
= 0; i
< 32; i
++)
492 if (regs
[ i
] == exp
.X_add_number
)
501 as_bad( "it is illegal to include register r%d in list\n", exp
.X_add_number
);
505 else if (system_register_name (& exp
, true))
507 if (regs
== type1_regs
)
509 as_bad ("system registers cannot be included in this register list" );
512 else if (exp
.X_add_number
== 5)
514 if (regs
== type2_regs
)
515 as_bad ("PSW cannot be included in this register list" );
522 else if (* input_line_pointer
== '}')
524 input_line_pointer
++;
527 else if (* input_line_pointer
== ',')
529 input_line_pointer
++;
532 else if (* input_line_pointer
== '-')
534 /* We have encountered a range of registers: rX - rY */
539 ++ input_line_pointer
;
541 /* Get the second register in the range. */
542 if (! register_name (& exp2
))
544 as_bad ("second register should follow dash in register list\n");
545 exp2
.X_add_number
= exp
.X_add_number
;
548 /* Add the rest of the registers in the range. */
549 for (j
= exp
.X_add_number
+ 1; j
<= exp2
.X_add_number
; j
++)
553 /* Locate the given register in the list, and if it is there, insert the corresponding bit into the instruction. */
554 for (i
= 0; i
< 32; i
++)
565 as_bad( "it is illegal to include register r%d in list\n", j
);
580 /* end-sanitize-v850e */
582 CONST
char * md_shortopts
= "m:";
584 struct option md_longopts
[] =
586 {NULL
, no_argument
, NULL
, 0}
588 size_t md_longopts_size
= sizeof md_longopts
;
592 md_show_usage (stream
)
595 fprintf (stream
, "V850 options:\n");
596 fprintf (stream
, "\tnone at present\n");
600 md_parse_option (c
, arg
)
608 md_undefined_symbol (name
)
615 md_atof (type
, litp
, sizep
)
621 LITTLENUM_TYPE words
[4];
637 return "bad call to md_atof";
640 t
= atof_ieee (input_line_pointer
, type
, words
);
642 input_line_pointer
= t
;
646 for (i
= prec
- 1; i
>= 0; i
--)
648 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
658 md_convert_frag (abfd
, sec
, fragP
)
663 subseg_change (sec
, 0);
664 if (fragP
->fr_subtype
== 0)
666 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
667 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
);
671 else if (fragP
->fr_subtype
== 1)
673 /* Reverse the condition of the first branch. */
674 fragP
->fr_literal
[0] &= 0xf7;
675 /* Mask off all the displacement bits. */
676 fragP
->fr_literal
[0] &= 0x8f;
677 fragP
->fr_literal
[1] &= 0x07;
678 /* Now set the displacement bits so that we branch
679 around the unconditional branch. */
680 fragP
->fr_literal
[0] |= 0x30;
682 /* Now create the unconditional branch + fixup to the final
684 md_number_to_chars (&fragP
->fr_literal
[2], 0x00000780, 4);
685 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
686 fragP
->fr_offset
, 1, BFD_RELOC_UNUSED
+ (int)fragP
->fr_opcode
+ 1);
695 md_section_align (seg
, addr
)
699 int align
= bfd_get_section_alignment (stdoutput
, seg
);
700 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
706 char *prev_name
= "";
707 register const struct v850_opcode
*op
;
709 v850_hash
= hash_new();
711 /* Insert unique names into hash table. The V850 instruction set
712 has many identical opcode names that have different opcodes based
713 on the operands. This hash table then provides a quick index to
714 the first opcode with a particular name in the opcode table. */
719 if (strcmp (prev_name
, op
->name
))
721 prev_name
= (char *) op
->name
;
722 hash_insert (v850_hash
, op
->name
, (char *) op
);
728 static bfd_reloc_code_real_type
731 if (strncmp(input_line_pointer
, "hi0(", 4) == 0)
733 input_line_pointer
+= 3;
734 return BFD_RELOC_HI16
;
736 if (strncmp(input_line_pointer
, "hi(", 3) == 0)
738 input_line_pointer
+= 2;
739 return BFD_RELOC_HI16_S
;
741 if (strncmp (input_line_pointer
, "lo(", 3) == 0)
743 input_line_pointer
+= 2;
744 return BFD_RELOC_LO16
;
747 if (strncmp (input_line_pointer
, "sdaoff(", 7) == 0)
749 input_line_pointer
+= 6;
750 return BFD_RELOC_V850_SDA_OFFSET
;
753 if (strncmp (input_line_pointer
, "zdaoff(", 7) == 0)
755 input_line_pointer
+= 6;
756 return BFD_RELOC_V850_ZDA_OFFSET
;
759 if (strncmp (input_line_pointer
, "tdaoff(", 7) == 0)
761 input_line_pointer
+= 6;
762 return BFD_RELOC_V850_TDA_OFFSET
;
766 if (strncmp(input_line_pointer
, "(hi0(", 5) == 0)
768 input_line_pointer
+= 4;
769 return BFD_RELOC_HI16
;
771 if (strncmp(input_line_pointer
, "(hi(", 4) == 0)
773 input_line_pointer
+= 3;
774 return BFD_RELOC_HI16_S
;
776 if (strncmp (input_line_pointer
, "(lo(", 4) == 0)
778 input_line_pointer
+= 3;
779 return BFD_RELOC_LO16
;
782 if (strncmp (input_line_pointer
, "(sdaoff(", 8) == 0)
784 input_line_pointer
+= 7;
785 return BFD_RELOC_V850_SDA_OFFSET
;
788 if (strncmp (input_line_pointer
, "(zdaoff(", 8) == 0)
790 input_line_pointer
+= 7;
791 return BFD_RELOC_V850_ZDA_OFFSET
;
794 if (strncmp (input_line_pointer
, "(tdaoff(", 8) == 0)
796 input_line_pointer
+= 7;
797 return BFD_RELOC_V850_TDA_OFFSET
;
800 return BFD_RELOC_UNUSED
;
808 char * start_of_operands
;
809 struct v850_opcode
* opcode
;
810 struct v850_opcode
* next_opcode
;
811 const unsigned char * opindex_ptr
;
815 unsigned long insn_size
;
819 bfd_reloc_code_real_type reloc
;
820 boolean extra_data_after_insn
= false;
821 unsigned extra_data_len
;
822 unsigned long extra_data
;
825 /* Get the opcode. */
826 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
832 /* find the first opcode with the proper name */
833 opcode
= (struct v850_opcode
*)hash_find (v850_hash
, str
);
836 as_bad ("Unrecognized opcode: `%s'", str
);
837 ignore_rest_of_line ();
842 while (isspace (*str
))
845 start_of_operands
= str
;
849 const char * errmsg
= NULL
;
855 insn
= opcode
->opcode
;
856 extra_data_after_insn
= false;
858 input_line_pointer
= str
= start_of_operands
;
860 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
862 const struct v850_operand
* operand
;
866 if (next_opindex
== 0)
868 operand
= & v850_operands
[ * opindex_ptr
];
872 operand
= & v850_operands
[ next_opindex
];
878 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
881 if (operand
->flags
& V850_OPERAND_RELAX
)
884 /* Gather the operand. */
885 hold
= input_line_pointer
;
886 input_line_pointer
= str
;
888 /*fprintf (stderr, "operand: %s index = %d, opcode = %s\n", input_line_pointer, opindex_ptr - opcode->operands, opcode->name );*/
890 /* lo(), hi(), hi0(), etc... */
891 if ((reloc
= v850_reloc_prefix()) != BFD_RELOC_UNUSED
)
895 if (ex
.X_op
== O_constant
)
901 /* Truncate, then sign extend the value. */
902 ex
.X_add_number
= SEXT16 (ex
.X_add_number
);
908 /* Truncate, then sign extend the value. */
909 ex
.X_add_number
= SEXT16 (ex
.X_add_number
>> 16);
913 case BFD_RELOC_HI16_S
:
915 /* Truncate, then sign extend the value. */
916 int temp
= (ex
.X_add_number
>> 16) & 0xffff;
918 temp
+= (ex
.X_add_number
>> 15) & 1;
920 ex
.X_add_number
= SEXT16 (temp
);
928 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
933 if (fc
> MAX_INSN_FIXUPS
)
934 as_fatal ("too many fixups");
936 /* Adjust any offsets for sst.{h,w}/sld.{h,w} instructions */
937 if (operand
->flags
& V850_OPERAND_ADJUST_SHORT_MEMORY
)
938 ex
.X_add_number
>>= 1;
941 fixups
[fc
].opindex
= *opindex_ptr
;
942 fixups
[fc
].reloc
= reloc
;
950 if ((operand
->flags
& V850_OPERAND_REG
) != 0)
952 if (!register_name (& ex
))
954 errmsg
= "invalid register name";
957 if ((operand
->flags
& V850_NOT_R0
)
958 && ex
.X_add_number
== 0)
960 errmsg
= "register r0 cannot be used here";
963 else if ((operand
->flags
& V850_OPERAND_SRG
) != 0)
965 if (!system_register_name (& ex
, true))
967 errmsg
= "UGG invalid system register name";
970 else if ((operand
->flags
& V850_OPERAND_EP
) != 0)
972 char * start
= input_line_pointer
;
973 char c
= get_symbol_end ();
975 if (strcmp (start
, "ep") != 0 && strcmp (start
, "r30") != 0)
977 /* Put things back the way we found them. */
978 *input_line_pointer
= c
;
979 input_line_pointer
= start
;
980 errmsg
= "expected EP register";
984 *input_line_pointer
= c
;
985 str
= input_line_pointer
;
986 input_line_pointer
= hold
;
988 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']')
992 else if ((operand
->flags
& V850_OPERAND_CC
) != 0)
996 errmsg
= "invalid condition code name";
999 else if (operand
->flags
& V850E_PUSH_POP
)
1001 if (! parse_register_list (& insn
, operand
))
1003 errmsg
= "invalid register list";
1006 /* The parse_register_list() function has already done everything, so fake a dummy expression. */
1007 ex
.X_op
= O_constant
;
1008 ex
.X_add_number
= 0;
1010 else if (operand
->flags
& V850E_IMMEDIATE16
)
1014 if (ex
.X_op
!= O_constant
)
1015 errmsg
= "constant expression expected";
1016 else if (ex
.X_add_number
& 0xffff0000)
1018 if (ex
.X_add_number
& 0xffff)
1019 errmsg
= "constant too big to fit into instruction";
1020 else if ((insn
& 0x001fffc0) == 0x00130780)
1021 ex
.X_add_number
>>= 16;
1023 errmsg
= "constant too big to fit into instruction";
1026 extra_data_after_insn
= true;
1028 extra_data
= ex
.X_add_number
;
1029 ex
.X_add_number
= 0;
1031 else if (operand
->flags
& V850E_IMMEDIATE32
)
1035 if (ex
.X_op
!= O_constant
)
1036 errmsg
= "constant expression expected";
1038 extra_data_after_insn
= true;
1040 extra_data
= ex
.X_add_number
;
1041 ex
.X_add_number
= 0;
1043 else if (register_name (&ex
)
1044 && (operand
->flags
& V850_OPERAND_REG
) == 0)
1046 errmsg
= "syntax error: register not expected";
1048 else if (system_register_name (& ex
, false)
1049 && (operand
->flags
& V850_OPERAND_SRG
) == 0)
1051 errmsg
= "syntax error: system register not expected";
1053 else if (cc_name (&ex
)
1054 && (operand
->flags
& V850_OPERAND_CC
) == 0)
1056 errmsg
= "syntax error: condition code not expected";
1061 /* start-sanitize-v850e */
1063 If we are assembling a MOV instruction (or a CALLT.... :-)
1064 and the immediate value does not fit into the bits available
1065 then create a fake error so that the next MOV instruction
1066 will be selected. This one has a 32 bit immediate field. */
1068 if (((insn
& 0x07e0) == 0x0200)
1069 && ex
.X_op
== O_constant
1070 && (ex
.X_add_number
< (- (1 << (operand
->bits
- 1))) || ex
.X_add_number
> ((1 << operand
->bits
) - 1)))
1071 errmsg
= "use bigger instruction";
1072 /* end-sanitize-v850e */
1078 /*fprintf (stderr, "insn: %x, operand %d, op: %d, add_number: %d\n", insn, opindex_ptr - opcode->operands, ex.X_op, ex.X_add_number );*/
1083 errmsg
= "illegal operand";
1086 errmsg
= "missing operand";
1089 if ((operand
->flags
& (V850_OPERAND_REG
| V850_OPERAND_SRG
)) == 0)
1091 errmsg
= "invalid operand";
1094 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1099 insn
= v850_insert_operand (insn
, operand
, ex
.X_add_number
,
1104 /* We need to generate a fixup for this expression. */
1105 if (fc
>= MAX_INSN_FIXUPS
)
1106 as_fatal ("too many fixups");
1107 fixups
[fc
].exp
= ex
;
1108 fixups
[fc
].opindex
= *opindex_ptr
;
1109 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1115 str
= input_line_pointer
;
1116 input_line_pointer
= hold
;
1118 while (*str
== ' ' || *str
== ',' || *str
== '[' || *str
== ']'
1127 next_opcode
= opcode
+ 1;
1128 if (next_opcode
->opcode
!= 0 && !strcmp (next_opcode
->name
, opcode
->name
))
1130 opcode
= next_opcode
;
1134 as_bad ("%s", errmsg
);
1135 ignore_rest_of_line ();
1141 while (isspace (*str
))
1145 as_bad ("junk at end of line: `%s'", str
);
1147 input_line_pointer
= str
;
1149 /* Write out the instruction.
1151 Four byte insns have an opcode with the two high bits on. */
1152 if (relaxable
&& fc
> 0)
1154 f
= frag_var (rs_machine_dependent
, 6, 4, 0,
1155 fixups
[0].exp
.X_add_symbol
,
1156 fixups
[0].exp
.X_add_number
,
1157 (char *)fixups
[0].opindex
);
1159 md_number_to_chars (f
, insn
, insn_size
);
1160 md_number_to_chars (f
+ 2, 0, 4);
1165 if ((insn
& 0x0600) == 0x0600)
1170 /* start-sanitize-v850e */
1171 /* Special case: 32 bit MOV */
1172 if ((insn
& 0xffe0) == 0x0620)
1174 /* end_sanitize-v850e */
1176 f
= frag_more (insn_size
);
1178 md_number_to_chars (f
, insn
, insn_size
);
1180 if (extra_data_after_insn
)
1182 f
= frag_more (extra_data_len
);
1183 md_number_to_chars (f
, extra_data
, extra_data_len
);
1185 extra_data_after_insn
= false;
1189 /* Create any fixups. At this point we do not use a
1190 bfd_reloc_code_real_type, but instead just use the
1191 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1192 handle fixups for any operand type, although that is admittedly
1193 not a very exciting feature. We pick a BFD reloc type in
1195 for (i
= 0; i
< fc
; i
++)
1197 const struct v850_operand
*operand
;
1199 operand
= &v850_operands
[fixups
[i
].opindex
];
1200 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1202 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
1210 size
= bfd_get_reloc_size (reloc_howto
);
1212 /* The "size" of a TDA_OFFSET reloc varies depending
1213 on what kind of instruction it's used in! */
1214 if (reloc_howto
->type
== 11 && insn_size
> 2)
1217 if (size
< 1 || size
> 4)
1221 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
1223 reloc_howto
->pc_relative
,
1226 switch (fixups
[i
].reloc
)
1228 case BFD_RELOC_LO16
:
1229 case BFD_RELOC_HI16
:
1230 case BFD_RELOC_HI16_S
:
1231 fixP
->fx_no_overflow
= 1;
1237 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
1239 1 /* FIXME: V850_OPERAND_RELATIVE ??? */,
1240 ((bfd_reloc_code_real_type
)
1241 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
1247 /* if while processing a fixup, a reloc really needs to be created */
1248 /* then it is done here */
1251 tc_gen_reloc (seg
, fixp
)
1256 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1257 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
1258 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1259 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1260 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1262 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1263 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
1266 reloc
->addend
= fixp
->fx_addnumber
;
1267 /* printf("tc_gen_reloc: addr=%x addend=%x\n", reloc->address, reloc->addend); */
1271 /* Assume everything will fit in two bytes, then expand as necessary. */
1273 md_estimate_size_before_relax (fragp
, seg
)
1283 md_pcrel_from (fixp
)
1286 /* If the symbol is undefined, or in a section other than our own,
1287 then let the linker figure it out. */
1288 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& ! S_IS_DEFINED (fixp
->fx_addsy
))
1290 /* The symbol is undefined. Let the linker figure it out. */
1293 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1297 md_apply_fix3 (fixp
, valuep
, seg
)
1305 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
1310 else if (fixp
->fx_pcrel
)
1314 value
= fixp
->fx_offset
;
1315 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
1317 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
1318 value
-= S_GET_VALUE (fixp
->fx_subsy
);
1321 /* We don't actually support subtracting a symbol. */
1322 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1323 "expression too complex");
1328 /* printf("md_apply_fix: value=0x%x type=%d\n", value, fixp->fx_r_type); */
1330 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
1333 const struct v850_operand
*operand
;
1337 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
1338 operand
= &v850_operands
[opindex
];
1340 /* Fetch the instruction, insert the fully resolved operand
1341 value, and stuff the instruction back again.
1343 Note the instruction has been stored in little endian
1345 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1347 insn
= bfd_getl32((unsigned char *) where
);
1348 insn
= v850_insert_operand (insn
, operand
, (offsetT
) value
,
1349 fixp
->fx_file
, fixp
->fx_line
);
1350 bfd_putl32((bfd_vma
) insn
, (unsigned char *) where
);
1354 /* Nothing else to do here. */
1358 /* Determine a BFD reloc value based on the operand information.
1359 We are only prepared to turn a few of the operands into relocs. */
1361 if (operand
->bits
== 22)
1362 fixp
->fx_r_type
= BFD_RELOC_V850_22_PCREL
;
1363 else if (operand
->bits
== 9)
1364 fixp
->fx_r_type
= BFD_RELOC_V850_9_PCREL
;
1365 else if (operand
->bits
== 16)
1366 fixp
->fx_r_type
= BFD_RELOC_V850_16_PCREL
;
1369 as_bad_where(fixp
->fx_file
, fixp
->fx_line
,
1370 "unresolved expression that must be resolved");
1375 else if (fixp
->fx_done
)
1377 /* We still have to insert the value into memory! */
1378 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
1379 if (fixp
->fx_size
== 1)
1380 *where
= value
& 0xff;
1381 if (fixp
->fx_size
== 2)
1382 bfd_putl16(value
& 0xffff, (unsigned char *) where
);
1383 if (fixp
->fx_size
== 4)
1384 bfd_putl32(value
, (unsigned char *) where
);
1387 fixp
->fx_addnumber
= value
;
1392 /* Insert an operand value into an instruction. */
1394 static unsigned long
1395 v850_insert_operand (insn
, operand
, val
, file
, line
)
1397 const struct v850_operand
* operand
;
1402 if (operand
->bits
!= 32)
1407 if ((operand
->flags
& V850_OPERAND_SIGNED
) != 0)
1409 max
= (1 << (operand
->bits
- 1)) - 1;
1410 min
= - (1 << (operand
->bits
- 1));
1414 max
= (1 << operand
->bits
) - 1;
1420 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1423 "operand out of range (%s not between %ld and %ld)";
1426 sprint_value (buf
, test
);
1427 if (file
== (char *) NULL
)
1428 as_warn (err
, buf
, min
, max
);
1430 as_warn_where (file
, line
, err
, buf
, min
, max
);
1434 if (operand
->insert
)
1436 const char * message
= NULL
;
1438 insn
= (*operand
->insert
) (insn
, val
, & message
);
1439 if (message
!= NULL
)
1441 if (file
== (char *) NULL
)
1444 as_warn_where (file
, line
, message
);
1448 insn
|= (((long) val
& ((1 << operand
->bits
) - 1)) << operand
->shift
);
1453 /* Parse a cons expression. We have to handle hi(), lo(), etc
1456 parse_cons_expression_v850 (exp
)
1459 /* See if there's a reloc prefix like hi() we have to handle. */
1460 hold_cons_reloc
= v850_reloc_prefix ();
1462 /* Do normal expression parsing. */
1466 /* Create a fixup for a cons expression. If parse_cons_expression_v850
1467 found a reloc prefix, then we use that reloc, else we choose an
1468 appropriate one based on the size of the expression. */
1470 cons_fix_new_v850 (frag
, where
, size
, exp
)
1476 if (hold_cons_reloc
== BFD_RELOC_UNUSED
)
1479 hold_cons_reloc
= BFD_RELOC_32
;
1481 hold_cons_reloc
= BFD_RELOC_16
;
1483 hold_cons_reloc
= BFD_RELOC_8
;
1487 fix_new_exp (frag
, where
, size
, exp
, 0, hold_cons_reloc
);
1489 fix_new (frag
, where
, size
, NULL
, 0, 0, hold_cons_reloc
);