1 /* tc-mn10300.c -- Assembler code for the Matsushita 10300
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 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, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
24 #include "safe-ctype.h"
26 #include "opcode/mn10300.h"
27 #include "dwarf2dbg.h"
29 /* Structure to hold information about predefined registers. */
36 /* Generic assembler global variables which must be defined by all
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";
57 const relax_typeS md_relax_table
[] =
59 /* The plus values for the bCC and fBCC instructions in the table below
60 are because the branch instruction is translated into a jump
61 instruction that is now +2 or +3 bytes further on in memory, and the
62 correct size of jump instruction must be selected. */
65 {0x7fff + 2, -0x8000 + 2, 5, 2},
66 {0x7fffffff, -0x80000000, 7, 0},
68 /* bCC relaxing (uncommon cases for 3byte length instructions) */
70 {0x7fff + 3, -0x8000 + 3, 6, 5},
71 {0x7fffffff, -0x80000000, 8, 0},
74 {0x7fff, -0x8000, 5, 7},
75 {0x7fffffff, -0x80000000, 7, 0},
78 {0x7fff, -0x8000, 4, 9},
79 {0x7fffffff, -0x80000000, 6, 0},
83 {0x7fff, -0x8000, 3, 12},
84 {0x7fffffff, -0x80000000, 5, 0},
88 {0x7fff + 3, -0x8000 + 3, 6, 15},
89 {0x7fffffff, -0x80000000, 8, 0},
93 /* Local functions. */
94 static void mn10300_insert_operand
PARAMS ((unsigned long *, unsigned long *,
95 const struct mn10300_operand
*,
96 offsetT
, char *, unsigned,
98 static unsigned long check_operand
PARAMS ((unsigned long,
99 const struct mn10300_operand
*,
101 static int reg_name_search
PARAMS ((const struct reg_name
*, int, const char *));
102 static bfd_boolean data_register_name
PARAMS ((expressionS
*expressionP
));
103 static bfd_boolean address_register_name
PARAMS ((expressionS
*expressionP
));
104 static bfd_boolean other_register_name
PARAMS ((expressionS
*expressionP
));
105 static bfd_boolean r_register_name
PARAMS ((expressionS
*expressionP
));
106 static bfd_boolean xr_register_name
PARAMS ((expressionS
*expressionP
));
107 static void set_arch_mach
PARAMS ((int));
109 /* Set linkrelax here to avoid fixups in most sections. */
112 static int current_machine
;
115 #define MAX_INSN_FIXUPS (5)
120 bfd_reloc_code_real_type reloc
;
122 struct mn10300_fixup fixups
[MAX_INSN_FIXUPS
];
125 /* We must store the value of each register operand so that we can
126 verify that certain registers do not match. */
127 int mn10300_reg_operands
[MN10300_MAX_OPERANDS
];
129 const char *md_shortopts
= "";
130 struct option md_longopts
[] = {
131 {NULL
, no_argument
, NULL
, 0}
133 size_t md_longopts_size
= sizeof (md_longopts
);
135 /* The target specific pseudo-ops which we support. */
136 const pseudo_typeS md_pseudo_table
[] =
138 { "am30", set_arch_mach
, AM30
},
139 { "am33", set_arch_mach
, AM33
},
140 { "am33_2", (void (*) PARAMS ((int))) set_arch_mach
, AM33_2
},
141 { "mn10300", set_arch_mach
, MN103
},
145 #define HAVE_AM33_2 (current_machine == AM33_2)
146 #define HAVE_AM33 (current_machine == AM33 || HAVE_AM33_2)
147 #define HAVE_AM30 (current_machine == AM30)
149 /* Opcode hash table. */
150 static struct hash_control
*mn10300_hash
;
152 /* This table is sorted. Suitable for searching by a binary search. */
153 static const struct reg_name data_registers
[] =
160 #define DATA_REG_NAME_CNT \
161 (sizeof (data_registers) / sizeof (struct reg_name))
163 static const struct reg_name address_registers
[] =
171 #define ADDRESS_REG_NAME_CNT \
172 (sizeof (address_registers) / sizeof (struct reg_name))
174 static const struct reg_name r_registers
[] =
218 #define R_REG_NAME_CNT \
219 (sizeof (r_registers) / sizeof (struct reg_name))
221 static const struct reg_name xr_registers
[] =
246 #define XR_REG_NAME_CNT \
247 (sizeof (xr_registers) / sizeof (struct reg_name))
249 /* We abuse the `value' field, that would be otherwise unused, to
250 encode the architecture on which (access to) the register was
251 introduced. FIXME: we should probably warn when we encounter a
252 register name when assembling for an architecture that doesn't
253 support it, before parsing it as a symbol name. */
254 static const struct reg_name other_registers
[] =
263 #define OTHER_REG_NAME_CNT \
264 (sizeof (other_registers) / sizeof (struct reg_name))
266 static const struct reg_name float_registers
[] =
302 #define FLOAT_REG_NAME_CNT \
303 (sizeof (float_registers) / sizeof (struct reg_name))
305 static const struct reg_name double_registers
[] =
325 #define DOUBLE_REG_NAME_CNT \
326 (sizeof (double_registers) / sizeof (struct reg_name))
329 /* reg_name_search does a binary search of the given register table
330 to see if "name" is a valid regiter name. Returns the register
331 number from the array on success, or -1 on failure. */
334 reg_name_search (regs
, regcount
, name
)
335 const struct reg_name
*regs
;
339 int middle
, low
, high
;
347 middle
= (low
+ high
) / 2;
348 cmp
= strcasecmp (name
, regs
[middle
].name
);
354 return regs
[middle
].value
;
360 /* Summary of register_name().
362 * in: Input_line_pointer points to 1st char of operand.
364 * out: An expressionS.
365 * The operand may have been a register: in this case, X_op == O_register,
366 * X_add_number is set to the register number, and truth is returned.
367 * Input_line_pointer->(next non-blank) char after operand, or is in
368 * its original state.
372 r_register_name (expressionP
)
373 expressionS
*expressionP
;
380 /* Find the spelling of the operand. */
381 start
= name
= input_line_pointer
;
383 c
= get_symbol_end ();
384 reg_number
= reg_name_search (r_registers
, R_REG_NAME_CNT
, name
);
386 /* Put back the delimiting char. */
387 *input_line_pointer
= c
;
389 /* Look to see if it's in the register table. */
392 expressionP
->X_op
= O_register
;
393 expressionP
->X_add_number
= reg_number
;
395 /* Make the rest nice. */
396 expressionP
->X_add_symbol
= NULL
;
397 expressionP
->X_op_symbol
= NULL
;
402 /* Reset the line as if we had not done anything. */
403 input_line_pointer
= start
;
407 /* Summary of register_name().
409 * in: Input_line_pointer points to 1st char of operand.
411 * out: An expressionS.
412 * The operand may have been a register: in this case, X_op == O_register,
413 * X_add_number is set to the register number, and truth is returned.
414 * Input_line_pointer->(next non-blank) char after operand, or is in
415 * its original state.
419 xr_register_name (expressionP
)
420 expressionS
*expressionP
;
427 /* Find the spelling of the operand. */
428 start
= name
= input_line_pointer
;
430 c
= get_symbol_end ();
431 reg_number
= reg_name_search (xr_registers
, XR_REG_NAME_CNT
, name
);
433 /* Put back the delimiting char. */
434 *input_line_pointer
= c
;
436 /* Look to see if it's in the register table. */
439 expressionP
->X_op
= O_register
;
440 expressionP
->X_add_number
= reg_number
;
442 /* Make the rest nice. */
443 expressionP
->X_add_symbol
= NULL
;
444 expressionP
->X_op_symbol
= NULL
;
449 /* Reset the line as if we had not done anything. */
450 input_line_pointer
= start
;
454 /* Summary of register_name().
456 * in: Input_line_pointer points to 1st char of operand.
458 * out: An expressionS.
459 * The operand may have been a register: in this case, X_op == O_register,
460 * X_add_number is set to the register number, and truth is returned.
461 * Input_line_pointer->(next non-blank) char after operand, or is in
462 * its original state.
466 data_register_name (expressionP
)
467 expressionS
*expressionP
;
474 /* Find the spelling of the operand. */
475 start
= name
= input_line_pointer
;
477 c
= get_symbol_end ();
478 reg_number
= reg_name_search (data_registers
, DATA_REG_NAME_CNT
, name
);
480 /* Put back the delimiting char. */
481 *input_line_pointer
= c
;
483 /* Look to see if it's in the register table. */
486 expressionP
->X_op
= O_register
;
487 expressionP
->X_add_number
= reg_number
;
489 /* Make the rest nice. */
490 expressionP
->X_add_symbol
= NULL
;
491 expressionP
->X_op_symbol
= NULL
;
496 /* Reset the line as if we had not done anything. */
497 input_line_pointer
= start
;
501 /* Summary of register_name().
503 * in: Input_line_pointer points to 1st char of operand.
505 * out: An expressionS.
506 * The operand may have been a register: in this case, X_op == O_register,
507 * X_add_number is set to the register number, and truth is returned.
508 * Input_line_pointer->(next non-blank) char after operand, or is in
509 * its original state.
513 address_register_name (expressionP
)
514 expressionS
*expressionP
;
521 /* Find the spelling of the operand. */
522 start
= name
= input_line_pointer
;
524 c
= get_symbol_end ();
525 reg_number
= reg_name_search (address_registers
, ADDRESS_REG_NAME_CNT
, name
);
527 /* Put back the delimiting char. */
528 *input_line_pointer
= c
;
530 /* Look to see if it's in the register table. */
533 expressionP
->X_op
= O_register
;
534 expressionP
->X_add_number
= reg_number
;
536 /* Make the rest nice. */
537 expressionP
->X_add_symbol
= NULL
;
538 expressionP
->X_op_symbol
= NULL
;
543 /* Reset the line as if we had not done anything. */
544 input_line_pointer
= start
;
548 /* Summary of register_name().
550 * in: Input_line_pointer points to 1st char of operand.
552 * out: An expressionS.
553 * The operand may have been a register: in this case, X_op == O_register,
554 * X_add_number is set to the register number, and truth is returned.
555 * Input_line_pointer->(next non-blank) char after operand, or is in
556 * its original state.
560 other_register_name (expressionP
)
561 expressionS
*expressionP
;
568 /* Find the spelling of the operand. */
569 start
= name
= input_line_pointer
;
571 c
= get_symbol_end ();
572 reg_number
= reg_name_search (other_registers
, OTHER_REG_NAME_CNT
, name
);
574 /* Put back the delimiting char. */
575 *input_line_pointer
= c
;
577 /* Look to see if it's in the register table. */
579 || (reg_number
== AM33
&& HAVE_AM33
))
581 expressionP
->X_op
= O_register
;
582 expressionP
->X_add_number
= 0;
584 /* Make the rest nice. */
585 expressionP
->X_add_symbol
= NULL
;
586 expressionP
->X_op_symbol
= NULL
;
591 /* Reset the line as if we had not done anything. */
592 input_line_pointer
= start
;
596 static bfd_boolean double_register_name
PARAMS ((expressionS
*));
597 static bfd_boolean float_register_name
PARAMS ((expressionS
*));
599 /* Summary of float_register_name:
601 in: Input_line_pointer points to 1st char of operand.
604 The operand may have been a register: in this case, X_op == O_register,
605 X_add_number is set to the register number, and truth is returned.
606 Input_line_pointer->(next non-blank) char after operand, or is in
607 its original state. */
610 float_register_name (expressionP
)
611 expressionS
*expressionP
;
618 /* Find the spelling of the operand. */
619 start
= name
= input_line_pointer
;
621 c
= get_symbol_end ();
622 reg_number
= reg_name_search (float_registers
, FLOAT_REG_NAME_CNT
, name
);
624 /* Put back the delimiting char. */
625 * input_line_pointer
= c
;
627 /* Look to see if it's in the register table. */
630 expressionP
->X_op
= O_register
;
631 expressionP
->X_add_number
= reg_number
;
633 /* Make the rest nice. */
634 expressionP
->X_add_symbol
= NULL
;
635 expressionP
->X_op_symbol
= NULL
;
640 /* Reset the line as if we had not done anything. */
641 input_line_pointer
= start
;
645 /* Summary of double_register_name:
647 in: Input_line_pointer points to 1st char of operand.
650 The operand may have been a register: in this case, X_op == O_register,
651 X_add_number is set to the register number, and truth is returned.
652 Input_line_pointer->(next non-blank) char after operand, or is in
653 its original state. */
656 double_register_name (expressionP
)
657 expressionS
*expressionP
;
664 /* Find the spelling of the operand. */
665 start
= name
= input_line_pointer
;
667 c
= get_symbol_end ();
668 reg_number
= reg_name_search (double_registers
, DOUBLE_REG_NAME_CNT
, name
);
670 /* Put back the delimiting char. */
671 * input_line_pointer
= c
;
673 /* Look to see if it's in the register table. */
676 expressionP
->X_op
= O_register
;
677 expressionP
->X_add_number
= reg_number
;
679 /* Make the rest nice. */
680 expressionP
->X_add_symbol
= NULL
;
681 expressionP
->X_op_symbol
= NULL
;
686 /* Reset the line as if we had not done anything. */
687 input_line_pointer
= start
;
692 md_show_usage (stream
)
695 fprintf (stream
, _("MN10300 options:\n\
700 md_parse_option (c
, arg
)
701 int c ATTRIBUTE_UNUSED
;
702 char *arg ATTRIBUTE_UNUSED
;
708 md_undefined_symbol (name
)
709 char *name ATTRIBUTE_UNUSED
;
715 md_atof (type
, litp
, sizep
)
721 LITTLENUM_TYPE words
[4];
737 return "bad call to md_atof";
740 t
= atof_ieee (input_line_pointer
, type
, words
);
742 input_line_pointer
= t
;
746 for (i
= prec
- 1; i
>= 0; i
--)
748 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
756 md_convert_frag (abfd
, sec
, fragP
)
757 bfd
*abfd ATTRIBUTE_UNUSED
;
761 static unsigned long label_count
= 0;
764 subseg_change (sec
, 0);
765 if (fragP
->fr_subtype
== 0)
767 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
768 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
772 else if (fragP
->fr_subtype
== 1)
774 /* Reverse the condition of the first branch. */
775 int offset
= fragP
->fr_fix
;
776 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
813 fragP
->fr_literal
[offset
] = opcode
;
815 /* Create a fixup for the reversed conditional branch. */
816 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
817 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
818 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
819 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
821 /* Now create the unconditional branch + fixup to the
823 fragP
->fr_literal
[offset
+ 2] = 0xcc;
824 fix_new (fragP
, fragP
->fr_fix
+ 3, 2, fragP
->fr_symbol
,
825 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
829 else if (fragP
->fr_subtype
== 2)
831 /* Reverse the condition of the first branch. */
832 int offset
= fragP
->fr_fix
;
833 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
870 fragP
->fr_literal
[offset
] = opcode
;
872 /* Create a fixup for the reversed conditional branch. */
873 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
874 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
875 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
876 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
878 /* Now create the unconditional branch + fixup to the
880 fragP
->fr_literal
[offset
+ 2] = 0xdc;
881 fix_new (fragP
, fragP
->fr_fix
+ 3, 4, fragP
->fr_symbol
,
882 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
886 else if (fragP
->fr_subtype
== 3)
888 fix_new (fragP
, fragP
->fr_fix
+ 2, 1, fragP
->fr_symbol
,
889 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
893 else if (fragP
->fr_subtype
== 4)
895 /* Reverse the condition of the first branch. */
896 int offset
= fragP
->fr_fix
;
897 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
916 fragP
->fr_literal
[offset
+ 1] = opcode
;
918 /* Create a fixup for the reversed conditional branch. */
919 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
920 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
921 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
922 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
924 /* Now create the unconditional branch + fixup to the
926 fragP
->fr_literal
[offset
+ 3] = 0xcc;
927 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
928 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
932 else if (fragP
->fr_subtype
== 5)
934 /* Reverse the condition of the first branch. */
935 int offset
= fragP
->fr_fix
;
936 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
952 fragP
->fr_literal
[offset
+ 1] = opcode
;
954 /* Create a fixup for the reversed conditional branch. */
955 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
956 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
957 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
958 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
960 /* Now create the unconditional branch + fixup to the
962 fragP
->fr_literal
[offset
+ 3] = 0xdc;
963 fix_new (fragP
, fragP
->fr_fix
+ 4, 4, fragP
->fr_symbol
,
964 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
968 else if (fragP
->fr_subtype
== 6)
970 int offset
= fragP
->fr_fix
;
971 fragP
->fr_literal
[offset
] = 0xcd;
972 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
973 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
977 else if (fragP
->fr_subtype
== 7)
979 int offset
= fragP
->fr_fix
;
980 fragP
->fr_literal
[offset
] = 0xdd;
981 fragP
->fr_literal
[offset
+ 5] = fragP
->fr_literal
[offset
+ 3];
982 fragP
->fr_literal
[offset
+ 6] = fragP
->fr_literal
[offset
+ 4];
984 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
985 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
989 else if (fragP
->fr_subtype
== 8)
991 int offset
= fragP
->fr_fix
;
992 fragP
->fr_literal
[offset
] = 0xfa;
993 fragP
->fr_literal
[offset
+ 1] = 0xff;
994 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
995 fragP
->fr_offset
+ 2, 1, BFD_RELOC_16_PCREL
);
999 else if (fragP
->fr_subtype
== 9)
1001 int offset
= fragP
->fr_fix
;
1002 fragP
->fr_literal
[offset
] = 0xfc;
1003 fragP
->fr_literal
[offset
+ 1] = 0xff;
1005 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
1006 fragP
->fr_offset
+ 2, 1, BFD_RELOC_32_PCREL
);
1010 else if (fragP
->fr_subtype
== 10)
1012 fragP
->fr_literal
[fragP
->fr_fix
] = 0xca;
1013 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
1014 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
1018 else if (fragP
->fr_subtype
== 11)
1020 int offset
= fragP
->fr_fix
;
1021 fragP
->fr_literal
[offset
] = 0xcc;
1023 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
1024 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
1028 else if (fragP
->fr_subtype
== 12)
1030 int offset
= fragP
->fr_fix
;
1031 fragP
->fr_literal
[offset
] = 0xdc;
1033 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
1034 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
1038 else if (fragP
->fr_subtype
== 13)
1040 fix_new (fragP
, fragP
->fr_fix
+ 2, 1, fragP
->fr_symbol
,
1041 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
1045 else if (fragP
->fr_subtype
== 14)
1047 /* Reverse the condition of the first branch. */
1048 int offset
= fragP
->fr_fix
;
1049 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
1098 fragP
->fr_literal
[offset
+ 1] = opcode
;
1100 /* Create a fixup for the reversed conditional branch. */
1101 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
1102 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
1103 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
1104 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
1106 /* Now create the unconditional branch + fixup to the
1108 fragP
->fr_literal
[offset
+ 3] = 0xcc;
1109 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
1110 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
1114 else if (fragP
->fr_subtype
== 15)
1116 /* Reverse the condition of the first branch. */
1117 int offset
= fragP
->fr_fix
;
1118 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
1167 fragP
->fr_literal
[offset
+ 1] = opcode
;
1169 /* Create a fixup for the reversed conditional branch. */
1170 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
1171 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
1172 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
1173 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
1175 /* Now create the unconditional branch + fixup to the
1177 fragP
->fr_literal
[offset
+ 3] = 0xdc;
1178 fix_new (fragP
, fragP
->fr_fix
+ 4, 4, fragP
->fr_symbol
,
1179 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
1188 md_section_align (seg
, addr
)
1192 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1193 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1199 char *prev_name
= "";
1200 register const struct mn10300_opcode
*op
;
1202 mn10300_hash
= hash_new ();
1204 /* Insert unique names into hash table. The MN10300 instruction set
1205 has many identical opcode names that have different opcodes based
1206 on the operands. This hash table then provides a quick index to
1207 the first opcode with a particular name in the opcode table. */
1209 op
= mn10300_opcodes
;
1212 if (strcmp (prev_name
, op
->name
))
1214 prev_name
= (char *) op
->name
;
1215 hash_insert (mn10300_hash
, op
->name
, (char *) op
);
1220 /* Set the default machine type. */
1222 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, AM33_2
))
1223 as_warn (_("could not set architecture and machine"));
1225 current_machine
= AM33_2
;
1227 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, MN103
))
1228 as_warn (_("could not set architecture and machine"));
1230 current_machine
= MN103
;
1234 static symbolS
*GOT_symbol
;
1236 static inline int mn10300_check_fixup
PARAMS ((struct mn10300_fixup
*));
1237 static inline int mn10300_PIC_related_p
PARAMS ((symbolS
*));
1240 mn10300_PIC_related_p (sym
)
1248 if (sym
== GOT_symbol
)
1251 exp
= symbol_get_value_expression (sym
);
1253 return (exp
->X_op
== O_PIC_reloc
1254 || mn10300_PIC_related_p (exp
->X_add_symbol
)
1255 || mn10300_PIC_related_p (exp
->X_op_symbol
));
1259 mn10300_check_fixup (fixup
)
1260 struct mn10300_fixup
*fixup
;
1262 expressionS
*exp
= &fixup
->exp
;
1268 case O_subtract
: /* If we're sufficiently unlucky that the label
1269 and the expression that references it happen
1270 to end up in different frags, the subtract
1271 won't be simplified within expression(). */
1272 /* The PIC-related operand must be the first operand of a sum. */
1273 if (exp
!= &fixup
->exp
|| mn10300_PIC_related_p (exp
->X_op_symbol
))
1276 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
1277 fixup
->reloc
= BFD_RELOC_32_GOT_PCREL
;
1279 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
1283 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
1284 fixup
->reloc
= BFD_RELOC_32_GOT_PCREL
;
1288 fixup
->reloc
= exp
->X_md
;
1289 exp
->X_op
= O_symbol
;
1290 if (fixup
->reloc
== BFD_RELOC_32_PLT_PCREL
1291 && fixup
->opindex
>= 0
1292 && (mn10300_operands
[fixup
->opindex
].flags
1293 & MN10300_OPERAND_RELAX
))
1298 return (mn10300_PIC_related_p (exp
->X_add_symbol
)
1299 || mn10300_PIC_related_p (exp
->X_op_symbol
));
1306 mn10300_cons_fix_new (frag
, off
, size
, exp
)
1311 struct mn10300_fixup fixup
;
1315 fixup
.reloc
= BFD_RELOC_UNUSED
;
1317 mn10300_check_fixup (&fixup
);
1319 if (fixup
.reloc
== BFD_RELOC_MN10300_GOT32
)
1323 fixup
.reloc
= BFD_RELOC_MN10300_GOT16
;
1327 fixup
.reloc
= BFD_RELOC_MN10300_GOT24
;
1336 else if (fixup
.reloc
== BFD_RELOC_UNUSED
)
1340 fixup
.reloc
= BFD_RELOC_8
;
1344 fixup
.reloc
= BFD_RELOC_16
;
1348 fixup
.reloc
= BFD_RELOC_24
;
1352 fixup
.reloc
= BFD_RELOC_32
;
1361 as_bad (_("unsupported BFD relocation size %u"), size
);
1362 fixup
.reloc
= BFD_RELOC_UNUSED
;
1365 fix_new_exp (frag
, off
, size
, &fixup
.exp
, 0, fixup
.reloc
);
1373 struct mn10300_opcode
*opcode
;
1374 struct mn10300_opcode
*next_opcode
;
1375 const unsigned char *opindex_ptr
;
1376 int next_opindex
, relaxable
;
1377 unsigned long insn
, extension
, size
= 0;
1382 /* Get the opcode. */
1383 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); s
++)
1388 /* Find the first opcode with the proper name. */
1389 opcode
= (struct mn10300_opcode
*) hash_find (mn10300_hash
, str
);
1392 as_bad (_("Unrecognized opcode: `%s'"), str
);
1397 while (ISSPACE (*str
))
1400 input_line_pointer
= str
;
1407 int extra_shift
= 0;
1409 errmsg
= _("Invalid opcode/operands");
1411 /* Reset the array of register operands. */
1412 memset (mn10300_reg_operands
, -1, sizeof (mn10300_reg_operands
));
1418 insn
= opcode
->opcode
;
1421 /* If the instruction is not available on the current machine
1422 then it can not possibly match. */
1424 && !(opcode
->machine
== AM33_2
&& HAVE_AM33_2
)
1425 && !(opcode
->machine
== AM33
&& HAVE_AM33
)
1426 && !(opcode
->machine
== AM30
&& HAVE_AM30
))
1429 for (op_idx
= 1, opindex_ptr
= opcode
->operands
;
1431 opindex_ptr
++, op_idx
++)
1433 const struct mn10300_operand
*operand
;
1436 if (next_opindex
== 0)
1438 operand
= &mn10300_operands
[*opindex_ptr
];
1442 operand
= &mn10300_operands
[next_opindex
];
1446 while (*str
== ' ' || *str
== ',')
1449 if (operand
->flags
& MN10300_OPERAND_RELAX
)
1452 /* Gather the operand. */
1453 hold
= input_line_pointer
;
1454 input_line_pointer
= str
;
1456 if (operand
->flags
& MN10300_OPERAND_PAREN
)
1458 if (*input_line_pointer
!= ')' && *input_line_pointer
!= '(')
1460 input_line_pointer
= hold
;
1464 input_line_pointer
++;
1467 /* See if we can match the operands. */
1468 else if (operand
->flags
& MN10300_OPERAND_DREG
)
1470 if (!data_register_name (&ex
))
1472 input_line_pointer
= hold
;
1477 else if (operand
->flags
& MN10300_OPERAND_AREG
)
1479 if (!address_register_name (&ex
))
1481 input_line_pointer
= hold
;
1486 else if (operand
->flags
& MN10300_OPERAND_SP
)
1488 char *start
= input_line_pointer
;
1489 char c
= get_symbol_end ();
1491 if (strcasecmp (start
, "sp") != 0)
1493 *input_line_pointer
= c
;
1494 input_line_pointer
= hold
;
1498 *input_line_pointer
= c
;
1501 else if (operand
->flags
& MN10300_OPERAND_RREG
)
1503 if (!r_register_name (&ex
))
1505 input_line_pointer
= hold
;
1510 else if (operand
->flags
& MN10300_OPERAND_XRREG
)
1512 if (!xr_register_name (&ex
))
1514 input_line_pointer
= hold
;
1519 else if (operand
->flags
& MN10300_OPERAND_FSREG
)
1521 if (!float_register_name (&ex
))
1523 input_line_pointer
= hold
;
1528 else if (operand
->flags
& MN10300_OPERAND_FDREG
)
1530 if (!double_register_name (&ex
))
1532 input_line_pointer
= hold
;
1537 else if (operand
->flags
& MN10300_OPERAND_FPCR
)
1539 char *start
= input_line_pointer
;
1540 char c
= get_symbol_end ();
1542 if (strcasecmp (start
, "fpcr") != 0)
1544 *input_line_pointer
= c
;
1545 input_line_pointer
= hold
;
1549 *input_line_pointer
= c
;
1552 else if (operand
->flags
& MN10300_OPERAND_USP
)
1554 char *start
= input_line_pointer
;
1555 char c
= get_symbol_end ();
1557 if (strcasecmp (start
, "usp") != 0)
1559 *input_line_pointer
= c
;
1560 input_line_pointer
= hold
;
1564 *input_line_pointer
= c
;
1567 else if (operand
->flags
& MN10300_OPERAND_SSP
)
1569 char *start
= input_line_pointer
;
1570 char c
= get_symbol_end ();
1572 if (strcasecmp (start
, "ssp") != 0)
1574 *input_line_pointer
= c
;
1575 input_line_pointer
= hold
;
1579 *input_line_pointer
= c
;
1582 else if (operand
->flags
& MN10300_OPERAND_MSP
)
1584 char *start
= input_line_pointer
;
1585 char c
= get_symbol_end ();
1587 if (strcasecmp (start
, "msp") != 0)
1589 *input_line_pointer
= c
;
1590 input_line_pointer
= hold
;
1594 *input_line_pointer
= c
;
1597 else if (operand
->flags
& MN10300_OPERAND_PC
)
1599 char *start
= input_line_pointer
;
1600 char c
= get_symbol_end ();
1602 if (strcasecmp (start
, "pc") != 0)
1604 *input_line_pointer
= c
;
1605 input_line_pointer
= hold
;
1609 *input_line_pointer
= c
;
1612 else if (operand
->flags
& MN10300_OPERAND_EPSW
)
1614 char *start
= input_line_pointer
;
1615 char c
= get_symbol_end ();
1617 if (strcasecmp (start
, "epsw") != 0)
1619 *input_line_pointer
= c
;
1620 input_line_pointer
= hold
;
1624 *input_line_pointer
= c
;
1627 else if (operand
->flags
& MN10300_OPERAND_PLUS
)
1629 if (*input_line_pointer
!= '+')
1631 input_line_pointer
= hold
;
1635 input_line_pointer
++;
1638 else if (operand
->flags
& MN10300_OPERAND_PSW
)
1640 char *start
= input_line_pointer
;
1641 char c
= get_symbol_end ();
1643 if (strcasecmp (start
, "psw") != 0)
1645 *input_line_pointer
= c
;
1646 input_line_pointer
= hold
;
1650 *input_line_pointer
= c
;
1653 else if (operand
->flags
& MN10300_OPERAND_MDR
)
1655 char *start
= input_line_pointer
;
1656 char c
= get_symbol_end ();
1658 if (strcasecmp (start
, "mdr") != 0)
1660 *input_line_pointer
= c
;
1661 input_line_pointer
= hold
;
1665 *input_line_pointer
= c
;
1668 else if (operand
->flags
& MN10300_OPERAND_REG_LIST
)
1670 unsigned int value
= 0;
1671 if (*input_line_pointer
!= '[')
1673 input_line_pointer
= hold
;
1679 input_line_pointer
++;
1681 /* We used to reject a null register list here; however,
1682 we accept it now so the compiler can emit "call"
1683 instructions for all calls to named functions.
1685 The linker can then fill in the appropriate bits for the
1686 register list and stack size or change the instruction
1687 into a "calls" if using "call" is not profitable. */
1688 while (*input_line_pointer
!= ']')
1693 if (*input_line_pointer
== ',')
1694 input_line_pointer
++;
1696 start
= input_line_pointer
;
1697 c
= get_symbol_end ();
1699 if (strcasecmp (start
, "d2") == 0)
1702 *input_line_pointer
= c
;
1704 else if (strcasecmp (start
, "d3") == 0)
1707 *input_line_pointer
= c
;
1709 else if (strcasecmp (start
, "a2") == 0)
1712 *input_line_pointer
= c
;
1714 else if (strcasecmp (start
, "a3") == 0)
1717 *input_line_pointer
= c
;
1719 else if (strcasecmp (start
, "other") == 0)
1722 *input_line_pointer
= c
;
1725 && strcasecmp (start
, "exreg0") == 0)
1728 *input_line_pointer
= c
;
1731 && strcasecmp (start
, "exreg1") == 0)
1734 *input_line_pointer
= c
;
1737 && strcasecmp (start
, "exother") == 0)
1740 *input_line_pointer
= c
;
1743 && strcasecmp (start
, "all") == 0)
1746 *input_line_pointer
= c
;
1750 input_line_pointer
= hold
;
1755 input_line_pointer
++;
1756 mn10300_insert_operand (&insn
, &extension
, operand
,
1757 value
, (char *) NULL
, 0, 0);
1761 else if (data_register_name (&ex
))
1763 input_line_pointer
= hold
;
1767 else if (address_register_name (&ex
))
1769 input_line_pointer
= hold
;
1773 else if (other_register_name (&ex
))
1775 input_line_pointer
= hold
;
1779 else if (HAVE_AM33
&& r_register_name (&ex
))
1781 input_line_pointer
= hold
;
1785 else if (HAVE_AM33
&& xr_register_name (&ex
))
1787 input_line_pointer
= hold
;
1791 else if (HAVE_AM33_2
&& float_register_name (&ex
))
1793 input_line_pointer
= hold
;
1797 else if (HAVE_AM33_2
&& double_register_name (&ex
))
1799 input_line_pointer
= hold
;
1803 else if (*str
== ')' || *str
== '(')
1805 input_line_pointer
= hold
;
1817 errmsg
= _("illegal operand");
1820 errmsg
= _("missing operand");
1826 mask
= MN10300_OPERAND_DREG
| MN10300_OPERAND_AREG
;
1828 mask
|= MN10300_OPERAND_RREG
| MN10300_OPERAND_XRREG
;
1830 mask
|= MN10300_OPERAND_FSREG
| MN10300_OPERAND_FDREG
;
1831 if ((operand
->flags
& mask
) == 0)
1833 input_line_pointer
= hold
;
1838 if (opcode
->format
== FMT_D1
|| opcode
->format
== FMT_S1
)
1840 else if (opcode
->format
== FMT_D2
1841 || opcode
->format
== FMT_D4
1842 || opcode
->format
== FMT_S2
1843 || opcode
->format
== FMT_S4
1844 || opcode
->format
== FMT_S6
1845 || opcode
->format
== FMT_D5
)
1847 else if (opcode
->format
== FMT_D7
)
1849 else if (opcode
->format
== FMT_D8
|| opcode
->format
== FMT_D9
)
1854 mn10300_insert_operand (&insn
, &extension
, operand
,
1855 ex
.X_add_number
, (char *) NULL
,
1858 /* And note the register number in the register array. */
1859 mn10300_reg_operands
[op_idx
- 1] = ex
.X_add_number
;
1864 /* If this operand can be promoted, and it doesn't
1865 fit into the allocated bitfield for this insn,
1866 then promote it (ie this opcode does not match). */
1868 & (MN10300_OPERAND_PROMOTE
| MN10300_OPERAND_RELAX
)
1869 && !check_operand (insn
, operand
, ex
.X_add_number
))
1871 input_line_pointer
= hold
;
1876 mn10300_insert_operand (&insn
, &extension
, operand
,
1877 ex
.X_add_number
, (char *) NULL
,
1882 /* If this operand can be promoted, then this opcode didn't
1883 match since we can't know if it needed promotion! */
1884 if (operand
->flags
& MN10300_OPERAND_PROMOTE
)
1886 input_line_pointer
= hold
;
1891 /* We need to generate a fixup for this expression. */
1892 if (fc
>= MAX_INSN_FIXUPS
)
1893 as_fatal (_("too many fixups"));
1894 fixups
[fc
].exp
= ex
;
1895 fixups
[fc
].opindex
= *opindex_ptr
;
1896 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1897 if (mn10300_check_fixup (& fixups
[fc
]))
1904 str
= input_line_pointer
;
1905 input_line_pointer
= hold
;
1907 while (*str
== ' ' || *str
== ',')
1912 /* Make sure we used all the operands! */
1916 /* If this instruction has registers that must not match, verify
1917 that they do indeed not match. */
1918 if (opcode
->no_match_operands
)
1922 /* Look at each operand to see if it's marked. */
1923 for (i
= 0; i
< MN10300_MAX_OPERANDS
; i
++)
1925 if ((1 << i
) & opcode
->no_match_operands
)
1929 /* operand I is marked. Check that it does not match any
1930 operands > I which are marked. */
1931 for (j
= i
+ 1; j
< MN10300_MAX_OPERANDS
; j
++)
1933 if (((1 << j
) & opcode
->no_match_operands
)
1934 && mn10300_reg_operands
[i
] == mn10300_reg_operands
[j
])
1936 errmsg
= _("Invalid register specification.");
1948 next_opcode
= opcode
+ 1;
1949 if (!strcmp (next_opcode
->name
, opcode
->name
))
1951 opcode
= next_opcode
;
1955 as_bad ("%s", errmsg
);
1961 while (ISSPACE (*str
))
1965 as_bad (_("junk at end of line: `%s'"), str
);
1967 input_line_pointer
= str
;
1969 /* Determine the size of the instruction. */
1970 if (opcode
->format
== FMT_S0
)
1973 if (opcode
->format
== FMT_S1
|| opcode
->format
== FMT_D0
)
1976 if (opcode
->format
== FMT_S2
|| opcode
->format
== FMT_D1
)
1979 if (opcode
->format
== FMT_D6
)
1982 if (opcode
->format
== FMT_D7
|| opcode
->format
== FMT_D10
)
1985 if (opcode
->format
== FMT_D8
)
1988 if (opcode
->format
== FMT_D9
)
1991 if (opcode
->format
== FMT_S4
)
1994 if (opcode
->format
== FMT_S6
|| opcode
->format
== FMT_D5
)
1997 if (opcode
->format
== FMT_D2
)
2000 if (opcode
->format
== FMT_D3
)
2003 if (opcode
->format
== FMT_D4
)
2006 if (relaxable
&& fc
> 0)
2008 /* On a 64-bit host the size of an 'int' is not the same
2009 as the size of a pointer, so we need a union to convert
2010 the opindex field of the fr_cgen structure into a char *
2011 so that it can be stored in the frag. We do not have
2012 to worry about loosing accuracy as we are not going to
2013 be even close to the 32bit limit of the int. */
2022 /* We want to anchor the line info to the previous frag (if
2023 there isn't one, create it), so that, when the insn is
2024 resized, we still get the right address for the beginning of
2027 dwarf2_emit_insn (0);
2032 /* Handle bra specially. Basically treat it like jmp so
2033 that we automatically handle 8, 16 and 32 bit offsets
2034 correctly as well as jumps to an undefined address.
2036 It is also important to not treat it like other bCC
2037 instructions since the long forms of bra is different
2038 from other bCC instructions. */
2039 if (opcode
->opcode
== 0xca00)
2051 else if (size
== 3 && opcode
->opcode
== 0xcc0000)
2053 else if (size
== 3 && (opcode
->opcode
& 0xfff000) == 0xf8d000)
2055 /* bCC (uncommon cases) */
2059 opindex_converter
.opindex
= fixups
[0].opindex
;
2060 f
= frag_var (rs_machine_dependent
, 8, 8 - size
, type
,
2061 fixups
[0].exp
.X_add_symbol
,
2062 fixups
[0].exp
.X_add_number
,
2063 opindex_converter
.ptr
);
2065 /* This is pretty hokey. We basically just care about the
2066 opcode, so we have to write out the first word big endian.
2068 The exception is "call", which has two operands that we
2071 The first operand (the register list) happens to be in the
2072 first instruction word, and will be in the right place if
2073 we output the first word in big endian mode.
2075 The second operand (stack size) is in the extension word,
2076 and we want it to appear as the first character in the extension
2077 word (as it appears in memory). Luckily, writing the extension
2078 word in big endian format will do what we want. */
2079 number_to_chars_bigendian (f
, insn
, size
> 4 ? 4 : size
);
2082 number_to_chars_bigendian (f
+ 4, extension
, 4);
2083 number_to_chars_bigendian (f
+ 8, 0, size
- 8);
2086 number_to_chars_bigendian (f
+ 4, extension
, size
- 4);
2090 /* Allocate space for the instruction. */
2091 f
= frag_more (size
);
2093 /* Fill in bytes for the instruction. Note that opcode fields
2094 are written big-endian, 16 & 32bit immediates are written
2095 little endian. Egad. */
2096 if (opcode
->format
== FMT_S0
2097 || opcode
->format
== FMT_S1
2098 || opcode
->format
== FMT_D0
2099 || opcode
->format
== FMT_D6
2100 || opcode
->format
== FMT_D7
2101 || opcode
->format
== FMT_D10
2102 || opcode
->format
== FMT_D1
)
2104 number_to_chars_bigendian (f
, insn
, size
);
2106 else if (opcode
->format
== FMT_S2
2107 && opcode
->opcode
!= 0xdf0000
2108 && opcode
->opcode
!= 0xde0000)
2110 /* A format S2 instruction that is _not_ "ret" and "retf". */
2111 number_to_chars_bigendian (f
, (insn
>> 16) & 0xff, 1);
2112 number_to_chars_littleendian (f
+ 1, insn
& 0xffff, 2);
2114 else if (opcode
->format
== FMT_S2
)
2116 /* This must be a ret or retf, which is written entirely in
2117 big-endian format. */
2118 number_to_chars_bigendian (f
, insn
, 3);
2120 else if (opcode
->format
== FMT_S4
2121 && opcode
->opcode
!= 0xdc000000)
2123 /* This must be a format S4 "call" instruction. What a pain. */
2124 unsigned long temp
= (insn
>> 8) & 0xffff;
2125 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
2126 number_to_chars_littleendian (f
+ 1, temp
, 2);
2127 number_to_chars_bigendian (f
+ 3, insn
& 0xff, 1);
2128 number_to_chars_bigendian (f
+ 4, extension
& 0xff, 1);
2130 else if (opcode
->format
== FMT_S4
)
2132 /* This must be a format S4 "jmp" instruction. */
2133 unsigned long temp
= ((insn
& 0xffffff) << 8) | (extension
& 0xff);
2134 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
2135 number_to_chars_littleendian (f
+ 1, temp
, 4);
2137 else if (opcode
->format
== FMT_S6
)
2139 unsigned long temp
= ((insn
& 0xffffff) << 8)
2140 | ((extension
>> 16) & 0xff);
2141 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
2142 number_to_chars_littleendian (f
+ 1, temp
, 4);
2143 number_to_chars_bigendian (f
+ 5, (extension
>> 8) & 0xff, 1);
2144 number_to_chars_bigendian (f
+ 6, extension
& 0xff, 1);
2146 else if (opcode
->format
== FMT_D2
2147 && opcode
->opcode
!= 0xfaf80000
2148 && opcode
->opcode
!= 0xfaf00000
2149 && opcode
->opcode
!= 0xfaf40000)
2151 /* A format D2 instruction where the 16bit immediate is
2152 really a single 16bit value, not two 8bit values. */
2153 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2154 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
2156 else if (opcode
->format
== FMT_D2
)
2158 /* A format D2 instruction where the 16bit immediate
2159 is really two 8bit immediates. */
2160 number_to_chars_bigendian (f
, insn
, 4);
2162 else if (opcode
->format
== FMT_D3
)
2164 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2165 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
2166 number_to_chars_bigendian (f
+ 4, extension
& 0xff, 1);
2168 else if (opcode
->format
== FMT_D4
)
2170 unsigned long temp
= ((insn
& 0xffff) << 16) | (extension
& 0xffff);
2172 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2173 number_to_chars_littleendian (f
+ 2, temp
, 4);
2175 else if (opcode
->format
== FMT_D5
)
2177 unsigned long temp
= (((insn
& 0xffff) << 16)
2178 | ((extension
>> 8) & 0xffff));
2180 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2181 number_to_chars_littleendian (f
+ 2, temp
, 4);
2182 number_to_chars_bigendian (f
+ 6, extension
& 0xff, 1);
2184 else if (opcode
->format
== FMT_D8
)
2186 unsigned long temp
= ((insn
& 0xff) << 16) | (extension
& 0xffff);
2188 number_to_chars_bigendian (f
, (insn
>> 8) & 0xffffff, 3);
2189 number_to_chars_bigendian (f
+ 3, (temp
& 0xff), 1);
2190 number_to_chars_littleendian (f
+ 4, temp
>> 8, 2);
2192 else if (opcode
->format
== FMT_D9
)
2194 unsigned long temp
= ((insn
& 0xff) << 24) | (extension
& 0xffffff);
2196 number_to_chars_bigendian (f
, (insn
>> 8) & 0xffffff, 3);
2197 number_to_chars_littleendian (f
+ 3, temp
, 4);
2200 /* Create any fixups. */
2201 for (i
= 0; i
< fc
; i
++)
2203 const struct mn10300_operand
*operand
;
2205 operand
= &mn10300_operands
[fixups
[i
].opindex
];
2206 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
2207 && fixups
[i
].reloc
!= BFD_RELOC_32_GOT_PCREL
2208 && fixups
[i
].reloc
!= BFD_RELOC_32_GOTOFF
2209 && fixups
[i
].reloc
!= BFD_RELOC_32_PLT_PCREL
2210 && fixups
[i
].reloc
!= BFD_RELOC_MN10300_GOT32
)
2212 reloc_howto_type
*reloc_howto
;
2217 reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
2223 size
= bfd_get_reloc_size (reloc_howto
);
2225 if (size
< 1 || size
> 4)
2229 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
2230 size
, &fixups
[i
].exp
,
2231 reloc_howto
->pc_relative
,
2236 int reloc
, pcrel
, reloc_size
, offset
;
2239 reloc
= BFD_RELOC_NONE
;
2240 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2241 reloc
= fixups
[i
].reloc
;
2242 /* How big is the reloc? Remember SPLIT relocs are
2243 implicitly 32bits. */
2244 if ((operand
->flags
& MN10300_OPERAND_SPLIT
) != 0)
2246 else if ((operand
->flags
& MN10300_OPERAND_24BIT
) != 0)
2249 reloc_size
= operand
->bits
;
2251 /* Is the reloc pc-relative? */
2252 pcrel
= (operand
->flags
& MN10300_OPERAND_PCREL
) != 0;
2253 if (reloc
!= BFD_RELOC_NONE
)
2254 pcrel
= bfd_reloc_type_lookup (stdoutput
, reloc
)->pc_relative
;
2256 offset
= size
- (reloc_size
+ operand
->shift
) / 8;
2258 /* Choose a proper BFD relocation type. */
2259 if (reloc
!= BFD_RELOC_NONE
)
2263 if (reloc_size
== 32)
2264 reloc
= BFD_RELOC_32_PCREL
;
2265 else if (reloc_size
== 16)
2266 reloc
= BFD_RELOC_16_PCREL
;
2267 else if (reloc_size
== 8)
2268 reloc
= BFD_RELOC_8_PCREL
;
2274 if (reloc_size
== 32)
2275 reloc
= BFD_RELOC_32
;
2276 else if (reloc_size
== 16)
2277 reloc
= BFD_RELOC_16
;
2278 else if (reloc_size
== 8)
2279 reloc
= BFD_RELOC_8
;
2284 /* Convert the size of the reloc into what fix_new_exp wants. */
2285 reloc_size
= reloc_size
/ 8;
2286 if (reloc_size
== 8)
2288 else if (reloc_size
== 16)
2290 else if (reloc_size
== 32)
2293 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
2294 reloc_size
, &fixups
[i
].exp
, pcrel
,
2295 ((bfd_reloc_code_real_type
) reloc
));
2298 fixP
->fx_offset
+= offset
;
2302 dwarf2_emit_insn (size
);
2306 /* If while processing a fixup, a reloc really needs to be created
2307 then it is done here. */
2310 tc_gen_reloc (seg
, fixp
)
2311 asection
*seg ATTRIBUTE_UNUSED
;
2315 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2317 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2318 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2320 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2321 _("reloc %d not supported by object file format"),
2322 (int) fixp
->fx_r_type
);
2325 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2328 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2330 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2334 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
2336 reloc
->sym_ptr_ptr
= NULL
;
2338 /* If we got a difference between two symbols, and the
2339 subtracted symbol is in the current section, use a
2340 PC-relative relocation. If both symbols are in the same
2341 section, the difference would have already been simplified
2343 if (S_GET_SEGMENT (fixp
->fx_subsy
) == seg
)
2345 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2346 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2347 reloc
->addend
= (reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
)
2350 switch (fixp
->fx_r_type
)
2353 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2358 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2359 BFD_RELOC_16_PCREL
);
2363 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2364 BFD_RELOC_24_PCREL
);
2368 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2369 BFD_RELOC_32_PCREL
);
2373 /* Try to compute the absolute value below. */
2378 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
2379 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
2381 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2382 "Difference of symbols in different sections is not supported");
2386 char *fixpos
= fixp
->fx_where
+ fixp
->fx_frag
->fr_literal
;
2388 reloc
->addend
= (S_GET_VALUE (fixp
->fx_addsy
)
2389 - S_GET_VALUE (fixp
->fx_subsy
) + fixp
->fx_offset
);
2391 switch (fixp
->fx_r_type
)
2394 md_number_to_chars (fixpos
, reloc
->addend
, 1);
2398 md_number_to_chars (fixpos
, reloc
->addend
, 2);
2402 md_number_to_chars (fixpos
, reloc
->addend
, 3);
2406 md_number_to_chars (fixpos
, reloc
->addend
, 4);
2410 reloc
->sym_ptr_ptr
= (asymbol
**) &bfd_abs_symbol
;
2415 if (reloc
->sym_ptr_ptr
)
2416 free (reloc
->sym_ptr_ptr
);
2422 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2423 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2424 reloc
->addend
= fixp
->fx_offset
;
2430 md_estimate_size_before_relax (fragp
, seg
)
2434 if (fragp
->fr_subtype
== 6
2435 && (!S_IS_DEFINED (fragp
->fr_symbol
)
2436 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
2437 fragp
->fr_subtype
= 7;
2438 else if (fragp
->fr_subtype
== 8
2439 && (!S_IS_DEFINED (fragp
->fr_symbol
)
2440 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
2441 fragp
->fr_subtype
= 9;
2442 else if (fragp
->fr_subtype
== 10
2443 && (!S_IS_DEFINED (fragp
->fr_symbol
)
2444 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
2445 fragp
->fr_subtype
= 12;
2447 if (fragp
->fr_subtype
== 13)
2449 if (fragp
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
2452 return md_relax_table
[fragp
->fr_subtype
].rlx_length
;
2456 md_pcrel_from (fixp
)
2459 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& !S_IS_DEFINED (fixp
->fx_addsy
))
2461 /* The symbol is undefined. Let the linker figure it out. */
2464 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2468 md_apply_fix (fixP
, valP
, seg
)
2473 char * fixpos
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2475 int value
= (int) * valP
;
2477 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
2479 /* This should never happen. */
2480 if (seg
->flags
& SEC_ALLOC
)
2483 /* The value we are passed in *valuep includes the symbol values.
2484 If we are doing this relocation the code in write.c is going to
2485 call bfd_install_relocation, which is also going to use the symbol
2486 value. That means that if the reloc is fully resolved we want to
2487 use *valuep since bfd_install_relocation is not being used.
2489 However, if the reloc is not fully resolved we do not want to use
2490 *valuep, and must use fx_offset instead. However, if the reloc
2491 is PC relative, we do want to use *valuep since it includes the
2492 result of md_pcrel_from. */
2493 if (fixP
->fx_addsy
!= (symbolS
*) NULL
&& ! fixP
->fx_pcrel
)
2494 value
= fixP
->fx_offset
;
2496 /* If the fix is relative to a symbol which is not defined, or not
2497 in the same segment as the fix, we cannot resolve it here. */
2498 if (fixP
->fx_addsy
!= NULL
2499 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2500 || (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)))
2506 switch (fixP
->fx_r_type
)
2509 case BFD_RELOC_8_PCREL
:
2514 case BFD_RELOC_16_PCREL
:
2519 case BFD_RELOC_32_PCREL
:
2523 case BFD_RELOC_VTABLE_INHERIT
:
2524 case BFD_RELOC_VTABLE_ENTRY
:
2528 case BFD_RELOC_NONE
:
2530 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2531 _("Bad relocation fixup type (%d)"), fixP
->fx_r_type
);
2534 md_number_to_chars (fixpos
, value
, size
);
2536 /* If a symbol remains, pass the fixup, as a reloc, onto the linker. */
2537 if (fixP
->fx_addsy
== NULL
)
2541 /* Return zero if the fixup in fixp should be left alone and not
2545 mn10300_fix_adjustable (fixp
)
2548 if (! TC_RELOC_RTSYM_LOC_FIXUP (fixp
))
2551 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2552 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2555 /* Do not adjust relocations involving symbols in code sections,
2556 because it breaks linker relaxations. This could be fixed in the
2557 linker, but this fix is simpler, and it pretty much only affects
2558 object size a little bit. */
2559 if (S_GET_SEGMENT (fixp
->fx_addsy
)->flags
& SEC_CODE
)
2562 /* Likewise, do not adjust symbols that won't be merged, or debug
2563 symbols, because they too break relaxation. We do want to adjust
2564 other mergable symbols, like .rodata, because code relaxations
2565 need section-relative symbols to properly relax them. */
2566 if (! (S_GET_SEGMENT(fixp
->fx_addsy
)->flags
& SEC_MERGE
))
2568 if (strncmp (S_GET_SEGMENT (fixp
->fx_addsy
)->name
, ".debug", 6) == 0)
2574 /* Insert an operand value into an instruction. */
2577 mn10300_insert_operand (insnp
, extensionp
, operand
, val
, file
, line
, shift
)
2578 unsigned long *insnp
;
2579 unsigned long *extensionp
;
2580 const struct mn10300_operand
*operand
;
2586 /* No need to check 32bit operands for a bit. Note that
2587 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
2588 if (operand
->bits
!= 32
2589 && (operand
->flags
& MN10300_OPERAND_SPLIT
) == 0)
2595 bits
= operand
->bits
;
2596 if (operand
->flags
& MN10300_OPERAND_24BIT
)
2599 if ((operand
->flags
& MN10300_OPERAND_SIGNED
) != 0)
2601 max
= (1 << (bits
- 1)) - 1;
2602 min
= - (1 << (bits
- 1));
2606 max
= (1 << bits
) - 1;
2612 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
2613 as_warn_value_out_of_range (_("operand"), test
, (offsetT
) min
, (offsetT
) max
, file
, line
);
2616 if ((operand
->flags
& MN10300_OPERAND_SPLIT
) != 0)
2618 *insnp
|= (val
>> (32 - operand
->bits
)) & ((1 << operand
->bits
) - 1);
2619 *extensionp
|= ((val
& ((1 << (32 - operand
->bits
)) - 1))
2622 else if ((operand
->flags
& MN10300_OPERAND_24BIT
) != 0)
2624 *insnp
|= (val
>> (24 - operand
->bits
)) & ((1 << operand
->bits
) - 1);
2625 *extensionp
|= ((val
& ((1 << (24 - operand
->bits
)) - 1))
2628 else if ((operand
->flags
& (MN10300_OPERAND_FSREG
| MN10300_OPERAND_FDREG
)))
2630 /* See devo/opcodes/m10300-opc.c just before #define FSM0 for an
2631 explanation of these variables. Note that FMT-implied shifts
2632 are not taken into account for FP registers. */
2633 unsigned long mask_low
, mask_high
;
2634 int shl_low
, shr_high
, shl_high
;
2636 switch (operand
->bits
)
2639 /* Handle regular FP registers. */
2640 if (operand
->shift
>= 0)
2642 /* This is an `m' register. */
2643 shl_low
= operand
->shift
;
2644 shl_high
= 8 + (8 & shl_low
) + (shl_low
& 4) / 4;
2648 /* This is an `n' register. */
2649 shl_low
= -operand
->shift
;
2650 shl_high
= shl_low
/ 4;
2659 /* Handle accumulators. */
2660 shl_low
= -operand
->shift
;
2670 *insnp
|= ((((val
& mask_high
) >> shr_high
) << shl_high
)
2671 | ((val
& mask_low
) << shl_low
));
2673 else if ((operand
->flags
& MN10300_OPERAND_EXTENDED
) == 0)
2675 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2676 << (operand
->shift
+ shift
));
2678 if ((operand
->flags
& MN10300_OPERAND_REPEATED
) != 0)
2679 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2680 << (operand
->shift
+ shift
+ operand
->bits
));
2684 *extensionp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2685 << (operand
->shift
+ shift
));
2687 if ((operand
->flags
& MN10300_OPERAND_REPEATED
) != 0)
2688 *extensionp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2689 << (operand
->shift
+ shift
+ operand
->bits
));
2693 static unsigned long
2694 check_operand (insn
, operand
, val
)
2695 unsigned long insn ATTRIBUTE_UNUSED
;
2696 const struct mn10300_operand
*operand
;
2699 /* No need to check 32bit operands for a bit. Note that
2700 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
2701 if (operand
->bits
!= 32
2702 && (operand
->flags
& MN10300_OPERAND_SPLIT
) == 0)
2708 bits
= operand
->bits
;
2709 if (operand
->flags
& MN10300_OPERAND_24BIT
)
2712 if ((operand
->flags
& MN10300_OPERAND_SIGNED
) != 0)
2714 max
= (1 << (bits
- 1)) - 1;
2715 min
= - (1 << (bits
- 1));
2719 max
= (1 << bits
) - 1;
2725 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
2734 set_arch_mach (mach
)
2737 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, mach
))
2738 as_warn (_("could not set architecture and machine"));
2740 current_machine
= mach
;
2743 static inline char * mn10300_end_of_match
PARAMS ((char *, char *));
2745 static inline char *
2746 mn10300_end_of_match (cont
, what
)
2749 int len
= strlen (what
);
2751 if (strncmp (cont
, what
, strlen (what
)) == 0
2752 && ! is_part_of_name (cont
[len
]))
2759 mn10300_parse_name (name
, exprP
, mode
, nextcharP
)
2762 enum expr_mode mode
;
2765 char *next
= input_line_pointer
;
2770 exprP
->X_op_symbol
= NULL
;
2772 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
2775 GOT_symbol
= symbol_find_or_make (name
);
2777 exprP
->X_add_symbol
= GOT_symbol
;
2779 /* If we have an absolute symbol or a reg,
2780 then we know its value now. */
2781 segment
= S_GET_SEGMENT (exprP
->X_add_symbol
);
2782 if (mode
!= expr_defer
&& segment
== absolute_section
)
2784 exprP
->X_op
= O_constant
;
2785 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
2786 exprP
->X_add_symbol
= NULL
;
2788 else if (mode
!= expr_defer
&& segment
== reg_section
)
2790 exprP
->X_op
= O_register
;
2791 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
2792 exprP
->X_add_symbol
= NULL
;
2796 exprP
->X_op
= O_symbol
;
2797 exprP
->X_add_number
= 0;
2803 exprP
->X_add_symbol
= symbol_find_or_make (name
);
2805 if (*nextcharP
!= '@')
2807 else if ((next_end
= mn10300_end_of_match (next
+ 1, "GOTOFF")))
2808 reloc_type
= BFD_RELOC_32_GOTOFF
;
2809 else if ((next_end
= mn10300_end_of_match (next
+ 1, "GOT")))
2810 reloc_type
= BFD_RELOC_MN10300_GOT32
;
2811 else if ((next_end
= mn10300_end_of_match (next
+ 1, "PLT")))
2812 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
2816 *input_line_pointer
= *nextcharP
;
2817 input_line_pointer
= next_end
;
2818 *nextcharP
= *input_line_pointer
;
2819 *input_line_pointer
= '\0';
2821 exprP
->X_op
= O_PIC_reloc
;
2822 exprP
->X_add_number
= 0;
2823 exprP
->X_md
= reloc_type
;