1 /* tc-mn10200.c -- Assembler code for the Matsushita 10200
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "safe-ctype.h"
26 #include "opcode/mn10200.h"
28 /* Structure to hold information about predefined registers. */
35 /* Generic assembler global variables which must be defined by all
38 /* Characters which always start a comment. */
39 const char comment_chars
[] = "#";
41 /* Characters which start a comment at the beginning of a line. */
42 const char line_comment_chars
[] = ";#";
44 /* Characters which may be used to separate multiple commands on a
46 const char line_separator_chars
[] = ";";
48 /* Characters which are used to indicate an exponent in a floating
50 const char EXP_CHARS
[] = "eE";
52 /* Characters which mean that a number is a floating point constant,
54 const char FLT_CHARS
[] = "dD";
56 const relax_typeS md_relax_table
[] = {
59 {0x8004, -0x7ffb, 5, 2},
60 {0x800006, -0x7ffff9, 7, 0},
63 {0x8004, -0x7ffb, 6, 5},
64 {0x800006, -0x7ffff9, 8, 0},
66 {0x8004, -0x7ffb, 3, 7},
67 {0x800006, -0x7ffff9, 5, 0},
70 {0x8004, -0x7ffb, 3, 10},
71 {0x800006, -0x7ffff9, 5, 0},
75 /* Local functions. */
76 static void mn10200_insert_operand
PARAMS ((unsigned long *, unsigned long *,
77 const struct mn10200_operand
*,
78 offsetT
, char *, unsigned,
80 static unsigned long check_operand
PARAMS ((unsigned long,
81 const struct mn10200_operand
*,
83 static int reg_name_search
PARAMS ((const struct reg_name
*, int, const char *));
84 static bfd_boolean data_register_name
PARAMS ((expressionS
*expressionP
));
85 static bfd_boolean address_register_name
PARAMS ((expressionS
*expressionP
));
86 static bfd_boolean other_register_name
PARAMS ((expressionS
*expressionP
));
89 #define MAX_INSN_FIXUPS (5)
94 bfd_reloc_code_real_type reloc
;
96 struct mn10200_fixup fixups
[MAX_INSN_FIXUPS
];
99 const char *md_shortopts
= "";
100 struct option md_longopts
[] = {
101 {NULL
, no_argument
, NULL
, 0}
103 size_t md_longopts_size
= sizeof (md_longopts
);
105 /* The target specific pseudo-ops which we support. */
106 const pseudo_typeS md_pseudo_table
[] =
111 /* Opcode hash table. */
112 static struct hash_control
*mn10200_hash
;
114 /* This table is sorted. Suitable for searching by a binary search. */
115 static const struct reg_name data_registers
[] =
122 #define DATA_REG_NAME_CNT \
123 (sizeof (data_registers) / sizeof (struct reg_name))
125 static const struct reg_name address_registers
[] =
132 #define ADDRESS_REG_NAME_CNT \
133 (sizeof (address_registers) / sizeof (struct reg_name))
135 static const struct reg_name other_registers
[] =
140 #define OTHER_REG_NAME_CNT \
141 (sizeof (other_registers) / sizeof (struct reg_name))
143 /* reg_name_search does a binary search of the given register table
144 to see if "name" is a valid regiter name. Returns the register
145 number from the array on success, or -1 on failure. */
148 reg_name_search (regs
, regcount
, name
)
149 const struct reg_name
*regs
;
153 int middle
, low
, high
;
161 middle
= (low
+ high
) / 2;
162 cmp
= strcasecmp (name
, regs
[middle
].name
);
168 return regs
[middle
].value
;
174 /* Summary of register_name().
176 * in: Input_line_pointer points to 1st char of operand.
178 * out: An expressionS.
179 * The operand may have been a register: in this case, X_op == O_register,
180 * X_add_number is set to the register number, and truth is returned.
181 * Input_line_pointer->(next non-blank) char after operand, or is in
182 * its original state.
186 data_register_name (expressionP
)
187 expressionS
*expressionP
;
194 /* Find the spelling of the operand. */
195 start
= name
= input_line_pointer
;
197 c
= get_symbol_end ();
198 reg_number
= reg_name_search (data_registers
, DATA_REG_NAME_CNT
, name
);
200 /* Put back the delimiting char. */
201 *input_line_pointer
= c
;
203 /* Look to see if it's in the register table. */
206 expressionP
->X_op
= O_register
;
207 expressionP
->X_add_number
= reg_number
;
209 /* Make the rest nice. */
210 expressionP
->X_add_symbol
= NULL
;
211 expressionP
->X_op_symbol
= NULL
;
216 /* Reset the line as if we had not done anything. */
217 input_line_pointer
= start
;
221 /* Summary of register_name().
223 * in: Input_line_pointer points to 1st char of operand.
225 * out: An expressionS.
226 * The operand may have been a register: in this case, X_op == O_register,
227 * X_add_number is set to the register number, and truth is returned.
228 * Input_line_pointer->(next non-blank) char after operand, or is in
229 * its original state.
233 address_register_name (expressionP
)
234 expressionS
*expressionP
;
241 /* Find the spelling of the operand. */
242 start
= name
= input_line_pointer
;
244 c
= get_symbol_end ();
245 reg_number
= reg_name_search (address_registers
, ADDRESS_REG_NAME_CNT
, name
);
247 /* Put back the delimiting char. */
248 *input_line_pointer
= c
;
250 /* Look to see if it's in the register table. */
253 expressionP
->X_op
= O_register
;
254 expressionP
->X_add_number
= reg_number
;
256 /* Make the rest nice. */
257 expressionP
->X_add_symbol
= NULL
;
258 expressionP
->X_op_symbol
= NULL
;
263 /* Reset the line as if we had not done anything. */
264 input_line_pointer
= start
;
268 /* Summary of register_name().
270 * in: Input_line_pointer points to 1st char of operand.
272 * out: An expressionS.
273 * The operand may have been a register: in this case, X_op == O_register,
274 * X_add_number is set to the register number, and truth is returned.
275 * Input_line_pointer->(next non-blank) char after operand, or is in
276 * its original state.
280 other_register_name (expressionP
)
281 expressionS
*expressionP
;
288 /* Find the spelling of the operand. */
289 start
= name
= input_line_pointer
;
291 c
= get_symbol_end ();
292 reg_number
= reg_name_search (other_registers
, OTHER_REG_NAME_CNT
, name
);
294 /* Put back the delimiting char. */
295 *input_line_pointer
= c
;
297 /* Look to see if it's in the register table. */
300 expressionP
->X_op
= O_register
;
301 expressionP
->X_add_number
= reg_number
;
303 /* Make the rest nice. */
304 expressionP
->X_add_symbol
= NULL
;
305 expressionP
->X_op_symbol
= NULL
;
310 /* Reset the line as if we had not done anything. */
311 input_line_pointer
= start
;
316 md_show_usage (stream
)
319 fprintf (stream
, _("MN10200 options:\n\
324 md_parse_option (c
, arg
)
325 int c ATTRIBUTE_UNUSED
;
326 char *arg ATTRIBUTE_UNUSED
;
332 md_undefined_symbol (name
)
333 char *name ATTRIBUTE_UNUSED
;
339 md_atof (type
, litp
, sizep
)
345 LITTLENUM_TYPE words
[4];
361 return _("bad call to md_atof");
364 t
= atof_ieee (input_line_pointer
, type
, words
);
366 input_line_pointer
= t
;
370 for (i
= prec
- 1; i
>= 0; i
--)
372 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
380 md_convert_frag (abfd
, sec
, fragP
)
381 bfd
*abfd ATTRIBUTE_UNUSED
;
385 static unsigned long label_count
= 0;
388 subseg_change (sec
, 0);
389 if (fragP
->fr_subtype
== 0)
391 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
392 fragP
->fr_offset
, 1, BFD_RELOC_8_PCREL
);
396 else if (fragP
->fr_subtype
== 1)
398 /* Reverse the condition of the first branch. */
399 int offset
= fragP
->fr_fix
;
400 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
437 fragP
->fr_literal
[offset
] = opcode
;
439 /* Create a fixup for the reversed conditional branch. */
440 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
441 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
442 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
443 fragP
->fr_offset
, 1, BFD_RELOC_8_PCREL
);
445 /* Now create the unconditional branch + fixup to the
447 fragP
->fr_literal
[offset
+ 2] = 0xfc;
448 fix_new (fragP
, fragP
->fr_fix
+ 3, 2, fragP
->fr_symbol
,
449 fragP
->fr_offset
, 1, BFD_RELOC_16_PCREL
);
453 else if (fragP
->fr_subtype
== 2)
455 /* Reverse the condition of the first branch. */
456 int offset
= fragP
->fr_fix
;
457 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
494 fragP
->fr_literal
[offset
] = opcode
;
496 /* Create a fixup for the reversed conditional branch. */
497 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
498 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
499 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
500 fragP
->fr_offset
, 1, BFD_RELOC_8_PCREL
);
502 /* Now create the unconditional branch + fixup to the
504 fragP
->fr_literal
[offset
+ 2] = 0xf4;
505 fragP
->fr_literal
[offset
+ 3] = 0xe0;
506 fix_new (fragP
, fragP
->fr_fix
+ 4, 4, fragP
->fr_symbol
,
507 fragP
->fr_offset
, 1, BFD_RELOC_24_PCREL
);
511 else if (fragP
->fr_subtype
== 3)
513 fix_new (fragP
, fragP
->fr_fix
+ 2, 1, fragP
->fr_symbol
,
514 fragP
->fr_offset
, 1, BFD_RELOC_8_PCREL
);
518 else if (fragP
->fr_subtype
== 4)
520 /* Reverse the condition of the first branch. */
521 int offset
= fragP
->fr_fix
;
522 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
582 fragP
->fr_literal
[offset
+ 1] = opcode
;
584 /* Create a fixup for the reversed conditional branch. */
585 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
586 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
587 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
588 fragP
->fr_offset
, 1, BFD_RELOC_8_PCREL
);
590 /* Now create the unconditional branch + fixup to the
592 fragP
->fr_literal
[offset
+ 3] = 0xfc;
593 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
594 fragP
->fr_offset
, 1, BFD_RELOC_16_PCREL
);
598 else if (fragP
->fr_subtype
== 5)
600 /* Reverse the condition of the first branch. */
601 int offset
= fragP
->fr_fix
;
602 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
662 fragP
->fr_literal
[offset
+ 1] = opcode
;
664 /* Create a fixup for the reversed conditional branch. */
665 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
666 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
667 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
668 fragP
->fr_offset
, 1, BFD_RELOC_8_PCREL
);
670 /* Now create the unconditional branch + fixup to the
672 fragP
->fr_literal
[offset
+ 3] = 0xf4;
673 fragP
->fr_literal
[offset
+ 4] = 0xe0;
674 fix_new (fragP
, fragP
->fr_fix
+ 5, 4, fragP
->fr_symbol
,
675 fragP
->fr_offset
, 1, BFD_RELOC_24_PCREL
);
679 else if (fragP
->fr_subtype
== 6)
681 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
682 fragP
->fr_offset
, 1, BFD_RELOC_16_PCREL
);
686 else if (fragP
->fr_subtype
== 7)
688 int offset
= fragP
->fr_fix
;
689 fragP
->fr_literal
[offset
] = 0xf4;
690 fragP
->fr_literal
[offset
+ 1] = 0xe1;
692 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
693 fragP
->fr_offset
, 1, BFD_RELOC_24_PCREL
);
697 else if (fragP
->fr_subtype
== 8)
699 fragP
->fr_literal
[fragP
->fr_fix
] = 0xea;
700 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
701 fragP
->fr_offset
, 1, BFD_RELOC_8_PCREL
);
705 else if (fragP
->fr_subtype
== 9)
707 int offset
= fragP
->fr_fix
;
708 fragP
->fr_literal
[offset
] = 0xfc;
710 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
711 fragP
->fr_offset
, 1, BFD_RELOC_16_PCREL
);
715 else if (fragP
->fr_subtype
== 10)
717 int offset
= fragP
->fr_fix
;
718 fragP
->fr_literal
[offset
] = 0xf4;
719 fragP
->fr_literal
[offset
+ 1] = 0xe0;
721 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
722 fragP
->fr_offset
, 1, BFD_RELOC_24_PCREL
);
731 md_section_align (seg
, addr
)
735 int align
= bfd_get_section_alignment (stdoutput
, seg
);
736 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
742 char *prev_name
= "";
743 register const struct mn10200_opcode
*op
;
745 mn10200_hash
= hash_new ();
747 /* Insert unique names into hash table. The MN10200 instruction set
748 has many identical opcode names that have different opcodes based
749 on the operands. This hash table then provides a quick index to
750 the first opcode with a particular name in the opcode table. */
752 op
= mn10200_opcodes
;
755 if (strcmp (prev_name
, op
->name
))
757 prev_name
= (char *) op
->name
;
758 hash_insert (mn10200_hash
, op
->name
, (char *) op
);
763 /* This is both a simplification (we don't have to write md_apply_fix3)
764 and support for future optimizations (branch shortening and similar
765 stuff in the linker. */
774 struct mn10200_opcode
*opcode
;
775 struct mn10200_opcode
*next_opcode
;
776 const unsigned char *opindex_ptr
;
777 int next_opindex
, relaxable
;
778 unsigned long insn
, extension
, size
= 0;
783 /* Get the opcode. */
784 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); s
++)
789 /* Find the first opcode with the proper name. */
790 opcode
= (struct mn10200_opcode
*) hash_find (mn10200_hash
, str
);
793 as_bad (_("Unrecognized opcode: `%s'"), str
);
798 while (ISSPACE (*str
))
801 input_line_pointer
= str
;
805 const char *errmsg
= NULL
;
814 insn
= opcode
->opcode
;
816 for (op_idx
= 1, opindex_ptr
= opcode
->operands
;
818 opindex_ptr
++, op_idx
++)
820 const struct mn10200_operand
*operand
;
823 if (next_opindex
== 0)
825 operand
= &mn10200_operands
[*opindex_ptr
];
829 operand
= &mn10200_operands
[next_opindex
];
835 while (*str
== ' ' || *str
== ',')
838 if (operand
->flags
& MN10200_OPERAND_RELAX
)
841 /* Gather the operand. */
842 hold
= input_line_pointer
;
843 input_line_pointer
= str
;
845 if (operand
->flags
& MN10200_OPERAND_PAREN
)
847 if (*input_line_pointer
!= ')' && *input_line_pointer
!= '(')
849 input_line_pointer
= hold
;
853 input_line_pointer
++;
856 /* See if we can match the operands. */
857 else if (operand
->flags
& MN10200_OPERAND_DREG
)
859 if (!data_register_name (&ex
))
861 input_line_pointer
= hold
;
866 else if (operand
->flags
& MN10200_OPERAND_AREG
)
868 if (!address_register_name (&ex
))
870 input_line_pointer
= hold
;
875 else if (operand
->flags
& MN10200_OPERAND_PSW
)
877 char *start
= input_line_pointer
;
878 char c
= get_symbol_end ();
880 if (strcmp (start
, "psw") != 0)
882 *input_line_pointer
= c
;
883 input_line_pointer
= hold
;
887 *input_line_pointer
= c
;
890 else if (operand
->flags
& MN10200_OPERAND_MDR
)
892 char *start
= input_line_pointer
;
893 char c
= get_symbol_end ();
895 if (strcmp (start
, "mdr") != 0)
897 *input_line_pointer
= c
;
898 input_line_pointer
= hold
;
902 *input_line_pointer
= c
;
905 else if (data_register_name (&ex
))
907 input_line_pointer
= hold
;
911 else if (address_register_name (&ex
))
913 input_line_pointer
= hold
;
917 else if (other_register_name (&ex
))
919 input_line_pointer
= hold
;
923 else if (*str
== ')' || *str
== '(')
925 input_line_pointer
= hold
;
937 errmsg
= _("illegal operand");
940 errmsg
= _("missing operand");
944 & (MN10200_OPERAND_DREG
| MN10200_OPERAND_AREG
)) == 0)
946 input_line_pointer
= hold
;
951 if (opcode
->format
== FMT_2
|| opcode
->format
== FMT_5
)
953 else if (opcode
->format
== FMT_3
|| opcode
->format
== FMT_6
954 || opcode
->format
== FMT_7
)
959 mn10200_insert_operand (&insn
, &extension
, operand
,
960 ex
.X_add_number
, (char *) NULL
,
966 /* If this operand can be promoted, and it doesn't
967 fit into the allocated bitfield for this insn,
968 then promote it (ie this opcode does not match). */
970 & (MN10200_OPERAND_PROMOTE
| MN10200_OPERAND_RELAX
)
971 && !check_operand (insn
, operand
, ex
.X_add_number
))
973 input_line_pointer
= hold
;
978 mn10200_insert_operand (&insn
, &extension
, operand
,
979 ex
.X_add_number
, (char *) NULL
,
984 /* If this operand can be promoted, then this opcode didn't
985 match since we can't know if it needed promotion! */
986 if (operand
->flags
& MN10200_OPERAND_PROMOTE
)
988 input_line_pointer
= hold
;
993 /* We need to generate a fixup for this expression. */
994 if (fc
>= MAX_INSN_FIXUPS
)
995 as_fatal (_("too many fixups"));
997 fixups
[fc
].opindex
= *opindex_ptr
;
998 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1004 str
= input_line_pointer
;
1005 input_line_pointer
= hold
;
1007 while (*str
== ' ' || *str
== ',')
1012 /* Make sure we used all the operands! */
1019 next_opcode
= opcode
+ 1;
1020 if (!strcmp (next_opcode
->name
, opcode
->name
))
1022 opcode
= next_opcode
;
1026 as_bad ("%s", errmsg
);
1032 while (ISSPACE (*str
))
1036 as_bad (_("junk at end of line: `%s'"), str
);
1038 input_line_pointer
= str
;
1040 if (opcode
->format
== FMT_1
)
1042 else if (opcode
->format
== FMT_2
|| opcode
->format
== FMT_4
)
1044 else if (opcode
->format
== FMT_3
|| opcode
->format
== FMT_5
)
1046 else if (opcode
->format
== FMT_6
)
1048 else if (opcode
->format
== FMT_7
)
1053 /* Write out the instruction. */
1055 if (relaxable
&& fc
> 0)
1060 if (size
== 2 && opcode
->opcode
!= 0xfc0000)
1062 /* Handle bra specially. Basically treat it like jmp so
1063 that we automatically handle 8, 16 and 32 bit offsets
1064 correctly as well as jumps to an undefined address.
1066 It is also important to not treat it like other bCC
1067 instructions since the long forms of bra is different
1068 from other bCC instructions. */
1069 if (opcode
->opcode
== 0xea00)
1075 else if (size
== 3 && opcode
->opcode
== 0xfd0000)
1078 else if (size
== 3 && opcode
->opcode
== 0xfc0000)
1084 f
= frag_var (rs_machine_dependent
, 8, 8 - size
, type
,
1085 fixups
[0].exp
.X_add_symbol
,
1086 fixups
[0].exp
.X_add_number
,
1087 (char *)fixups
[0].opindex
);
1088 number_to_chars_bigendian (f
, insn
, size
);
1091 number_to_chars_bigendian (f
+ size
, 0, 4);
1092 number_to_chars_bigendian (f
+ size
+ 4, 0, 8 - size
- 4);
1095 number_to_chars_bigendian (f
+ size
, 0, 8 - size
);
1100 f
= frag_more (size
);
1102 /* Oh, what a mess. The instruction is in big endian format, but
1103 16 and 24bit immediates are little endian! */
1104 if (opcode
->format
== FMT_3
)
1106 number_to_chars_bigendian (f
, (insn
>> 16) & 0xff, 1);
1107 number_to_chars_littleendian (f
+ 1, insn
& 0xffff, 2);
1109 else if (opcode
->format
== FMT_6
)
1111 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
1112 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
1114 else if (opcode
->format
== FMT_7
)
1116 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
1117 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
1118 number_to_chars_littleendian (f
+ 4, extension
& 0xff, 1);
1122 number_to_chars_bigendian (f
, insn
, size
> 4 ? 4 : size
);
1125 /* Create any fixups. */
1126 for (i
= 0; i
< fc
; i
++)
1128 const struct mn10200_operand
*operand
;
1130 operand
= &mn10200_operands
[fixups
[i
].opindex
];
1131 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1133 reloc_howto_type
*reloc_howto
;
1138 reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
1144 size
= bfd_get_reloc_size (reloc_howto
);
1146 if (size
< 1 || size
> 4)
1150 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
1153 reloc_howto
->pc_relative
,
1156 /* PC-relative offsets are from the first byte of the
1157 next instruction, not from the start of the current
1159 if (reloc_howto
->pc_relative
)
1160 fixP
->fx_offset
+= size
;
1164 int reloc
, pcrel
, reloc_size
, offset
;
1167 reloc
= BFD_RELOC_NONE
;
1168 /* How big is the reloc? Remember SPLIT relocs are
1169 implicitly 32bits. */
1170 reloc_size
= operand
->bits
;
1172 offset
= size
- reloc_size
/ 8;
1174 /* Is the reloc pc-relative? */
1175 pcrel
= (operand
->flags
& MN10200_OPERAND_PCREL
) != 0;
1177 /* Choose a proper BFD relocation type. */
1180 if (reloc_size
== 8)
1181 reloc
= BFD_RELOC_8_PCREL
;
1182 else if (reloc_size
== 24)
1183 reloc
= BFD_RELOC_24_PCREL
;
1189 if (reloc_size
== 32)
1190 reloc
= BFD_RELOC_32
;
1191 else if (reloc_size
== 16)
1192 reloc
= BFD_RELOC_16
;
1193 else if (reloc_size
== 8)
1194 reloc
= BFD_RELOC_8
;
1195 else if (reloc_size
== 24)
1196 reloc
= BFD_RELOC_24
;
1201 /* Convert the size of the reloc into what fix_new_exp
1203 reloc_size
= reloc_size
/ 8;
1204 if (reloc_size
== 8)
1206 else if (reloc_size
== 16)
1208 else if (reloc_size
== 32 || reloc_size
== 24)
1211 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
1212 reloc_size
, &fixups
[i
].exp
, pcrel
,
1213 ((bfd_reloc_code_real_type
) reloc
));
1215 /* PC-relative offsets are from the first byte of the
1216 next instruction, not from the start of the current
1219 fixP
->fx_offset
+= size
;
1225 /* If while processing a fixup, a reloc really needs to be created
1226 Then it is done here. */
1229 tc_gen_reloc (seg
, fixp
)
1230 asection
*seg ATTRIBUTE_UNUSED
;
1234 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1236 if (fixp
->fx_subsy
!= NULL
)
1238 /* FIXME: We should resolve difference expressions if possible
1239 here. At least this is better than silently ignoring the
1241 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1242 _("can't resolve `%s' {%s section} - `%s' {%s section}"),
1243 fixp
->fx_addsy
? S_GET_NAME (fixp
->fx_addsy
) : "0",
1244 segment_name (fixp
->fx_addsy
1245 ? S_GET_SEGMENT (fixp
->fx_addsy
)
1246 : absolute_section
),
1247 S_GET_NAME (fixp
->fx_subsy
),
1248 segment_name (S_GET_SEGMENT (fixp
->fx_addsy
)));
1251 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1252 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1254 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1255 _("reloc %d not supported by object file format"),
1256 (int) fixp
->fx_r_type
);
1259 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1260 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1261 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1262 reloc
->addend
= fixp
->fx_offset
;
1267 md_estimate_size_before_relax (fragp
, seg
)
1271 if (fragp
->fr_subtype
== 6
1272 && (!S_IS_DEFINED (fragp
->fr_symbol
)
1273 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
1274 fragp
->fr_subtype
= 7;
1275 else if (fragp
->fr_subtype
== 8
1276 && (!S_IS_DEFINED (fragp
->fr_symbol
)
1277 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
1278 fragp
->fr_subtype
= 10;
1280 if (fragp
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
1283 return md_relax_table
[fragp
->fr_subtype
].rlx_length
;
1287 md_pcrel_from (fixp
)
1290 return fixp
->fx_frag
->fr_address
;
1292 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& !S_IS_DEFINED (fixp
->fx_addsy
))
1294 /* The symbol is undefined. Let the linker figure it out. */
1297 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1302 md_apply_fix3 (fixP
, valP
, seg
)
1304 valueT
* valP ATTRIBUTE_UNUSED
;
1305 segT seg ATTRIBUTE_UNUSED
;
1307 /* We shouldn't ever get here because linkrelax is nonzero. */
1312 /* Insert an operand value into an instruction. */
1315 mn10200_insert_operand (insnp
, extensionp
, operand
, val
, file
, line
, shift
)
1316 unsigned long *insnp
;
1317 unsigned long *extensionp
;
1318 const struct mn10200_operand
*operand
;
1324 /* No need to check 24 or 32bit operands for a bit. */
1325 if (operand
->bits
< 24
1326 && (operand
->flags
& MN10200_OPERAND_NOCHECK
) == 0)
1331 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
1333 max
= (1 << (operand
->bits
- 1)) - 1;
1334 min
= - (1 << (operand
->bits
- 1));
1338 max
= (1 << operand
->bits
) - 1;
1344 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1345 as_warn_value_out_of_range (_("operand"), test
, (offsetT
) min
, (offsetT
) max
, file
, line
);
1348 if ((operand
->flags
& MN10200_OPERAND_EXTENDED
) == 0)
1350 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
1351 << (operand
->shift
+ shift
));
1353 if ((operand
->flags
& MN10200_OPERAND_REPEATED
) != 0)
1354 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
1355 << (operand
->shift
+ shift
+ 2));
1359 *extensionp
|= (val
>> 16) & 0xff;
1360 *insnp
|= val
& 0xffff;
1364 static unsigned long
1365 check_operand (insn
, operand
, val
)
1366 unsigned long insn ATTRIBUTE_UNUSED
;
1367 const struct mn10200_operand
*operand
;
1370 /* No need to check 24bit or 32bit operands for a bit. */
1371 if (operand
->bits
< 24
1372 && (operand
->flags
& MN10200_OPERAND_NOCHECK
) == 0)
1377 if ((operand
->flags
& MN10200_OPERAND_SIGNED
) != 0)
1379 max
= (1 << (operand
->bits
- 1)) - 1;
1380 min
= - (1 << (operand
->bits
- 1));
1384 max
= (1 << operand
->bits
) - 1;
1390 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)