1 /* tc-mn10300.c -- Assembler code for the Matsushita 10300
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007 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 3, 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. */
23 #include "safe-ctype.h"
25 #include "opcode/mn10300.h"
26 #include "dwarf2dbg.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
[] =
58 /* The plus values for the bCC and fBCC instructions in the table below
59 are because the branch instruction is translated into a jump
60 instruction that is now +2 or +3 bytes further on in memory, and the
61 correct size of jump instruction must be selected. */
64 {0x7fff + 2, -0x8000 + 2, 5, 2},
65 {0x7fffffff, -0x80000000, 7, 0},
67 /* bCC relaxing (uncommon cases for 3byte length instructions) */
69 {0x7fff + 3, -0x8000 + 3, 6, 5},
70 {0x7fffffff, -0x80000000, 8, 0},
73 {0x7fff, -0x8000, 5, 7},
74 {0x7fffffff, -0x80000000, 7, 0},
77 {0x7fff, -0x8000, 4, 9},
78 {0x7fffffff, -0x80000000, 6, 0},
82 {0x7fff, -0x8000, 3, 12},
83 {0x7fffffff, -0x80000000, 5, 0},
87 {0x7fff + 3, -0x8000 + 3, 6, 15},
88 {0x7fffffff, -0x80000000, 8, 0},
92 /* Local functions. */
93 static void mn10300_insert_operand
PARAMS ((unsigned long *, unsigned long *,
94 const struct mn10300_operand
*,
95 offsetT
, char *, unsigned,
97 static unsigned long check_operand
PARAMS ((unsigned long,
98 const struct mn10300_operand
*,
100 static int reg_name_search
PARAMS ((const struct reg_name
*, int, const char *));
101 static bfd_boolean data_register_name
PARAMS ((expressionS
*expressionP
));
102 static bfd_boolean address_register_name
PARAMS ((expressionS
*expressionP
));
103 static bfd_boolean other_register_name
PARAMS ((expressionS
*expressionP
));
104 static bfd_boolean r_register_name
PARAMS ((expressionS
*expressionP
));
105 static bfd_boolean xr_register_name
PARAMS ((expressionS
*expressionP
));
106 static void set_arch_mach
PARAMS ((int));
108 /* Set linkrelax here to avoid fixups in most sections. */
111 static int current_machine
;
114 #define MAX_INSN_FIXUPS (5)
119 bfd_reloc_code_real_type reloc
;
121 struct mn10300_fixup fixups
[MAX_INSN_FIXUPS
];
124 /* We must store the value of each register operand so that we can
125 verify that certain registers do not match. */
126 int mn10300_reg_operands
[MN10300_MAX_OPERANDS
];
128 const char *md_shortopts
= "";
129 struct option md_longopts
[] = {
130 {NULL
, no_argument
, NULL
, 0}
132 size_t md_longopts_size
= sizeof (md_longopts
);
134 /* The target specific pseudo-ops which we support. */
135 const pseudo_typeS md_pseudo_table
[] =
137 { "am30", set_arch_mach
, AM30
},
138 { "am33", set_arch_mach
, AM33
},
139 { "am33_2", (void (*) PARAMS ((int))) set_arch_mach
, AM33_2
},
140 { "mn10300", set_arch_mach
, MN103
},
144 #define HAVE_AM33_2 (current_machine == AM33_2)
145 #define HAVE_AM33 (current_machine == AM33 || HAVE_AM33_2)
146 #define HAVE_AM30 (current_machine == AM30)
148 /* Opcode hash table. */
149 static struct hash_control
*mn10300_hash
;
151 /* This table is sorted. Suitable for searching by a binary search. */
152 static const struct reg_name data_registers
[] =
159 #define DATA_REG_NAME_CNT \
160 (sizeof (data_registers) / sizeof (struct reg_name))
162 static const struct reg_name address_registers
[] =
170 #define ADDRESS_REG_NAME_CNT \
171 (sizeof (address_registers) / sizeof (struct reg_name))
173 static const struct reg_name r_registers
[] =
217 #define R_REG_NAME_CNT \
218 (sizeof (r_registers) / sizeof (struct reg_name))
220 static const struct reg_name xr_registers
[] =
245 #define XR_REG_NAME_CNT \
246 (sizeof (xr_registers) / sizeof (struct reg_name))
248 /* We abuse the `value' field, that would be otherwise unused, to
249 encode the architecture on which (access to) the register was
250 introduced. FIXME: we should probably warn when we encounter a
251 register name when assembling for an architecture that doesn't
252 support it, before parsing it as a symbol name. */
253 static const struct reg_name other_registers
[] =
262 #define OTHER_REG_NAME_CNT \
263 (sizeof (other_registers) / sizeof (struct reg_name))
265 static const struct reg_name float_registers
[] =
301 #define FLOAT_REG_NAME_CNT \
302 (sizeof (float_registers) / sizeof (struct reg_name))
304 static const struct reg_name double_registers
[] =
324 #define DOUBLE_REG_NAME_CNT \
325 (sizeof (double_registers) / sizeof (struct reg_name))
328 /* reg_name_search does a binary search of the given register table
329 to see if "name" is a valid regiter name. Returns the register
330 number from the array on success, or -1 on failure. */
333 reg_name_search (regs
, regcount
, name
)
334 const struct reg_name
*regs
;
338 int middle
, low
, high
;
346 middle
= (low
+ high
) / 2;
347 cmp
= strcasecmp (name
, regs
[middle
].name
);
353 return regs
[middle
].value
;
359 /* Summary of register_name().
361 * in: Input_line_pointer points to 1st char of operand.
363 * out: An expressionS.
364 * The operand may have been a register: in this case, X_op == O_register,
365 * X_add_number is set to the register number, and truth is returned.
366 * Input_line_pointer->(next non-blank) char after operand, or is in
367 * its original state.
371 r_register_name (expressionP
)
372 expressionS
*expressionP
;
379 /* Find the spelling of the operand. */
380 start
= name
= input_line_pointer
;
382 c
= get_symbol_end ();
383 reg_number
= reg_name_search (r_registers
, R_REG_NAME_CNT
, name
);
385 /* Put back the delimiting char. */
386 *input_line_pointer
= c
;
388 /* Look to see if it's in the register table. */
391 expressionP
->X_op
= O_register
;
392 expressionP
->X_add_number
= reg_number
;
394 /* Make the rest nice. */
395 expressionP
->X_add_symbol
= NULL
;
396 expressionP
->X_op_symbol
= NULL
;
401 /* Reset the line as if we had not done anything. */
402 input_line_pointer
= start
;
406 /* Summary of register_name().
408 * in: Input_line_pointer points to 1st char of operand.
410 * out: An expressionS.
411 * The operand may have been a register: in this case, X_op == O_register,
412 * X_add_number is set to the register number, and truth is returned.
413 * Input_line_pointer->(next non-blank) char after operand, or is in
414 * its original state.
418 xr_register_name (expressionP
)
419 expressionS
*expressionP
;
426 /* Find the spelling of the operand. */
427 start
= name
= input_line_pointer
;
429 c
= get_symbol_end ();
430 reg_number
= reg_name_search (xr_registers
, XR_REG_NAME_CNT
, name
);
432 /* Put back the delimiting char. */
433 *input_line_pointer
= c
;
435 /* Look to see if it's in the register table. */
438 expressionP
->X_op
= O_register
;
439 expressionP
->X_add_number
= reg_number
;
441 /* Make the rest nice. */
442 expressionP
->X_add_symbol
= NULL
;
443 expressionP
->X_op_symbol
= NULL
;
448 /* Reset the line as if we had not done anything. */
449 input_line_pointer
= start
;
453 /* Summary of register_name().
455 * in: Input_line_pointer points to 1st char of operand.
457 * out: An expressionS.
458 * The operand may have been a register: in this case, X_op == O_register,
459 * X_add_number is set to the register number, and truth is returned.
460 * Input_line_pointer->(next non-blank) char after operand, or is in
461 * its original state.
465 data_register_name (expressionP
)
466 expressionS
*expressionP
;
473 /* Find the spelling of the operand. */
474 start
= name
= input_line_pointer
;
476 c
= get_symbol_end ();
477 reg_number
= reg_name_search (data_registers
, DATA_REG_NAME_CNT
, name
);
479 /* Put back the delimiting char. */
480 *input_line_pointer
= c
;
482 /* Look to see if it's in the register table. */
485 expressionP
->X_op
= O_register
;
486 expressionP
->X_add_number
= reg_number
;
488 /* Make the rest nice. */
489 expressionP
->X_add_symbol
= NULL
;
490 expressionP
->X_op_symbol
= NULL
;
495 /* Reset the line as if we had not done anything. */
496 input_line_pointer
= start
;
500 /* Summary of register_name().
502 * in: Input_line_pointer points to 1st char of operand.
504 * out: An expressionS.
505 * The operand may have been a register: in this case, X_op == O_register,
506 * X_add_number is set to the register number, and truth is returned.
507 * Input_line_pointer->(next non-blank) char after operand, or is in
508 * its original state.
512 address_register_name (expressionP
)
513 expressionS
*expressionP
;
520 /* Find the spelling of the operand. */
521 start
= name
= input_line_pointer
;
523 c
= get_symbol_end ();
524 reg_number
= reg_name_search (address_registers
, ADDRESS_REG_NAME_CNT
, name
);
526 /* Put back the delimiting char. */
527 *input_line_pointer
= c
;
529 /* Look to see if it's in the register table. */
532 expressionP
->X_op
= O_register
;
533 expressionP
->X_add_number
= reg_number
;
535 /* Make the rest nice. */
536 expressionP
->X_add_symbol
= NULL
;
537 expressionP
->X_op_symbol
= NULL
;
542 /* Reset the line as if we had not done anything. */
543 input_line_pointer
= start
;
547 /* Summary of register_name().
549 * in: Input_line_pointer points to 1st char of operand.
551 * out: An expressionS.
552 * The operand may have been a register: in this case, X_op == O_register,
553 * X_add_number is set to the register number, and truth is returned.
554 * Input_line_pointer->(next non-blank) char after operand, or is in
555 * its original state.
559 other_register_name (expressionP
)
560 expressionS
*expressionP
;
567 /* Find the spelling of the operand. */
568 start
= name
= input_line_pointer
;
570 c
= get_symbol_end ();
571 reg_number
= reg_name_search (other_registers
, OTHER_REG_NAME_CNT
, name
);
573 /* Put back the delimiting char. */
574 *input_line_pointer
= c
;
576 /* Look to see if it's in the register table. */
578 || (reg_number
== AM33
&& HAVE_AM33
))
580 expressionP
->X_op
= O_register
;
581 expressionP
->X_add_number
= 0;
583 /* Make the rest nice. */
584 expressionP
->X_add_symbol
= NULL
;
585 expressionP
->X_op_symbol
= NULL
;
590 /* Reset the line as if we had not done anything. */
591 input_line_pointer
= start
;
595 static bfd_boolean double_register_name
PARAMS ((expressionS
*));
596 static bfd_boolean float_register_name
PARAMS ((expressionS
*));
598 /* Summary of float_register_name:
600 in: Input_line_pointer points to 1st char of operand.
603 The operand may have been a register: in this case, X_op == O_register,
604 X_add_number is set to the register number, and truth is returned.
605 Input_line_pointer->(next non-blank) char after operand, or is in
606 its original state. */
609 float_register_name (expressionP
)
610 expressionS
*expressionP
;
617 /* Find the spelling of the operand. */
618 start
= name
= input_line_pointer
;
620 c
= get_symbol_end ();
621 reg_number
= reg_name_search (float_registers
, FLOAT_REG_NAME_CNT
, name
);
623 /* Put back the delimiting char. */
624 * input_line_pointer
= c
;
626 /* Look to see if it's in the register table. */
629 expressionP
->X_op
= O_register
;
630 expressionP
->X_add_number
= reg_number
;
632 /* Make the rest nice. */
633 expressionP
->X_add_symbol
= NULL
;
634 expressionP
->X_op_symbol
= NULL
;
639 /* Reset the line as if we had not done anything. */
640 input_line_pointer
= start
;
644 /* Summary of double_register_name:
646 in: Input_line_pointer points to 1st char of operand.
649 The operand may have been a register: in this case, X_op == O_register,
650 X_add_number is set to the register number, and truth is returned.
651 Input_line_pointer->(next non-blank) char after operand, or is in
652 its original state. */
655 double_register_name (expressionP
)
656 expressionS
*expressionP
;
663 /* Find the spelling of the operand. */
664 start
= name
= input_line_pointer
;
666 c
= get_symbol_end ();
667 reg_number
= reg_name_search (double_registers
, DOUBLE_REG_NAME_CNT
, name
);
669 /* Put back the delimiting char. */
670 * input_line_pointer
= c
;
672 /* Look to see if it's in the register table. */
675 expressionP
->X_op
= O_register
;
676 expressionP
->X_add_number
= reg_number
;
678 /* Make the rest nice. */
679 expressionP
->X_add_symbol
= NULL
;
680 expressionP
->X_op_symbol
= NULL
;
685 /* Reset the line as if we had not done anything. */
686 input_line_pointer
= start
;
691 md_show_usage (stream
)
694 fprintf (stream
, _("MN10300 assembler options:\n\
699 md_parse_option (c
, arg
)
700 int c ATTRIBUTE_UNUSED
;
701 char *arg ATTRIBUTE_UNUSED
;
707 md_undefined_symbol (name
)
708 char *name ATTRIBUTE_UNUSED
;
714 md_atof (int type
, char *litp
, int *sizep
)
716 return ieee_md_atof (type
, litp
, sizep
, FALSE
);
720 md_convert_frag (abfd
, sec
, fragP
)
721 bfd
*abfd ATTRIBUTE_UNUSED
;
725 static unsigned long label_count
= 0;
728 subseg_change (sec
, 0);
729 if (fragP
->fr_subtype
== 0)
731 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
732 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
736 else if (fragP
->fr_subtype
== 1)
738 /* Reverse the condition of the first branch. */
739 int offset
= fragP
->fr_fix
;
740 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
777 fragP
->fr_literal
[offset
] = opcode
;
779 /* Create a fixup for the reversed conditional branch. */
780 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
781 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
782 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
783 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
785 /* Now create the unconditional branch + fixup to the
787 fragP
->fr_literal
[offset
+ 2] = 0xcc;
788 fix_new (fragP
, fragP
->fr_fix
+ 3, 2, fragP
->fr_symbol
,
789 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
793 else if (fragP
->fr_subtype
== 2)
795 /* Reverse the condition of the first branch. */
796 int offset
= fragP
->fr_fix
;
797 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
834 fragP
->fr_literal
[offset
] = opcode
;
836 /* Create a fixup for the reversed conditional branch. */
837 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
838 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
839 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
840 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
842 /* Now create the unconditional branch + fixup to the
844 fragP
->fr_literal
[offset
+ 2] = 0xdc;
845 fix_new (fragP
, fragP
->fr_fix
+ 3, 4, fragP
->fr_symbol
,
846 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
850 else if (fragP
->fr_subtype
== 3)
852 fix_new (fragP
, fragP
->fr_fix
+ 2, 1, fragP
->fr_symbol
,
853 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
857 else if (fragP
->fr_subtype
== 4)
859 /* Reverse the condition of the first branch. */
860 int offset
= fragP
->fr_fix
;
861 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
880 fragP
->fr_literal
[offset
+ 1] = opcode
;
882 /* Create a fixup for the reversed conditional branch. */
883 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
884 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
885 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
886 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
888 /* Now create the unconditional branch + fixup to the
890 fragP
->fr_literal
[offset
+ 3] = 0xcc;
891 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
892 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
896 else if (fragP
->fr_subtype
== 5)
898 /* Reverse the condition of the first branch. */
899 int offset
= fragP
->fr_fix
;
900 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] = 0xdc;
927 fix_new (fragP
, fragP
->fr_fix
+ 4, 4, fragP
->fr_symbol
,
928 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
932 else if (fragP
->fr_subtype
== 6)
934 int offset
= fragP
->fr_fix
;
935 fragP
->fr_literal
[offset
] = 0xcd;
936 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
937 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
941 else if (fragP
->fr_subtype
== 7)
943 int offset
= fragP
->fr_fix
;
944 fragP
->fr_literal
[offset
] = 0xdd;
945 fragP
->fr_literal
[offset
+ 5] = fragP
->fr_literal
[offset
+ 3];
946 fragP
->fr_literal
[offset
+ 6] = fragP
->fr_literal
[offset
+ 4];
948 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
949 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
953 else if (fragP
->fr_subtype
== 8)
955 int offset
= fragP
->fr_fix
;
956 fragP
->fr_literal
[offset
] = 0xfa;
957 fragP
->fr_literal
[offset
+ 1] = 0xff;
958 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
959 fragP
->fr_offset
+ 2, 1, BFD_RELOC_16_PCREL
);
963 else if (fragP
->fr_subtype
== 9)
965 int offset
= fragP
->fr_fix
;
966 fragP
->fr_literal
[offset
] = 0xfc;
967 fragP
->fr_literal
[offset
+ 1] = 0xff;
969 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
970 fragP
->fr_offset
+ 2, 1, BFD_RELOC_32_PCREL
);
974 else if (fragP
->fr_subtype
== 10)
976 fragP
->fr_literal
[fragP
->fr_fix
] = 0xca;
977 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
978 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
982 else if (fragP
->fr_subtype
== 11)
984 int offset
= fragP
->fr_fix
;
985 fragP
->fr_literal
[offset
] = 0xcc;
987 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
988 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
992 else if (fragP
->fr_subtype
== 12)
994 int offset
= fragP
->fr_fix
;
995 fragP
->fr_literal
[offset
] = 0xdc;
997 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
998 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
1002 else if (fragP
->fr_subtype
== 13)
1004 fix_new (fragP
, fragP
->fr_fix
+ 2, 1, fragP
->fr_symbol
,
1005 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
1009 else if (fragP
->fr_subtype
== 14)
1011 /* Reverse the condition of the first branch. */
1012 int offset
= fragP
->fr_fix
;
1013 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
1062 fragP
->fr_literal
[offset
+ 1] = opcode
;
1064 /* Create a fixup for the reversed conditional branch. */
1065 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
1066 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
1067 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
1068 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
1070 /* Now create the unconditional branch + fixup to the
1072 fragP
->fr_literal
[offset
+ 3] = 0xcc;
1073 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
1074 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
1078 else if (fragP
->fr_subtype
== 15)
1080 /* Reverse the condition of the first branch. */
1081 int offset
= fragP
->fr_fix
;
1082 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
1131 fragP
->fr_literal
[offset
+ 1] = opcode
;
1133 /* Create a fixup for the reversed conditional branch. */
1134 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
1135 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
1136 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
1137 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
1139 /* Now create the unconditional branch + fixup to the
1141 fragP
->fr_literal
[offset
+ 3] = 0xdc;
1142 fix_new (fragP
, fragP
->fr_fix
+ 4, 4, fragP
->fr_symbol
,
1143 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
1152 md_section_align (seg
, addr
)
1156 int align
= bfd_get_section_alignment (stdoutput
, seg
);
1157 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
1163 char *prev_name
= "";
1164 register const struct mn10300_opcode
*op
;
1166 mn10300_hash
= hash_new ();
1168 /* Insert unique names into hash table. The MN10300 instruction set
1169 has many identical opcode names that have different opcodes based
1170 on the operands. This hash table then provides a quick index to
1171 the first opcode with a particular name in the opcode table. */
1173 op
= mn10300_opcodes
;
1176 if (strcmp (prev_name
, op
->name
))
1178 prev_name
= (char *) op
->name
;
1179 hash_insert (mn10300_hash
, op
->name
, (char *) op
);
1184 /* Set the default machine type. */
1186 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, AM33_2
))
1187 as_warn (_("could not set architecture and machine"));
1189 current_machine
= AM33_2
;
1191 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, MN103
))
1192 as_warn (_("could not set architecture and machine"));
1194 current_machine
= MN103
;
1198 static symbolS
*GOT_symbol
;
1200 static inline int mn10300_check_fixup
PARAMS ((struct mn10300_fixup
*));
1201 static inline int mn10300_PIC_related_p
PARAMS ((symbolS
*));
1204 mn10300_PIC_related_p (sym
)
1212 if (sym
== GOT_symbol
)
1215 exp
= symbol_get_value_expression (sym
);
1217 return (exp
->X_op
== O_PIC_reloc
1218 || mn10300_PIC_related_p (exp
->X_add_symbol
)
1219 || mn10300_PIC_related_p (exp
->X_op_symbol
));
1223 mn10300_check_fixup (fixup
)
1224 struct mn10300_fixup
*fixup
;
1226 expressionS
*exp
= &fixup
->exp
;
1232 case O_subtract
: /* If we're sufficiently unlucky that the label
1233 and the expression that references it happen
1234 to end up in different frags, the subtract
1235 won't be simplified within expression(). */
1236 /* The PIC-related operand must be the first operand of a sum. */
1237 if (exp
!= &fixup
->exp
|| mn10300_PIC_related_p (exp
->X_op_symbol
))
1240 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
1241 fixup
->reloc
= BFD_RELOC_32_GOT_PCREL
;
1243 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
1247 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
1248 fixup
->reloc
= BFD_RELOC_32_GOT_PCREL
;
1252 fixup
->reloc
= exp
->X_md
;
1253 exp
->X_op
= O_symbol
;
1254 if (fixup
->reloc
== BFD_RELOC_32_PLT_PCREL
1255 && fixup
->opindex
>= 0
1256 && (mn10300_operands
[fixup
->opindex
].flags
1257 & MN10300_OPERAND_RELAX
))
1262 return (mn10300_PIC_related_p (exp
->X_add_symbol
)
1263 || mn10300_PIC_related_p (exp
->X_op_symbol
));
1270 mn10300_cons_fix_new (frag
, off
, size
, exp
)
1275 struct mn10300_fixup fixup
;
1279 fixup
.reloc
= BFD_RELOC_UNUSED
;
1281 mn10300_check_fixup (&fixup
);
1283 if (fixup
.reloc
== BFD_RELOC_MN10300_GOT32
)
1287 fixup
.reloc
= BFD_RELOC_MN10300_GOT16
;
1291 fixup
.reloc
= BFD_RELOC_MN10300_GOT24
;
1300 else if (fixup
.reloc
== BFD_RELOC_UNUSED
)
1304 fixup
.reloc
= BFD_RELOC_8
;
1308 fixup
.reloc
= BFD_RELOC_16
;
1312 fixup
.reloc
= BFD_RELOC_24
;
1316 fixup
.reloc
= BFD_RELOC_32
;
1325 as_bad (_("unsupported BFD relocation size %u"), size
);
1326 fixup
.reloc
= BFD_RELOC_UNUSED
;
1329 fix_new_exp (frag
, off
, size
, &fixup
.exp
, 0, fixup
.reloc
);
1337 struct mn10300_opcode
*opcode
;
1338 struct mn10300_opcode
*next_opcode
;
1339 const unsigned char *opindex_ptr
;
1340 int next_opindex
, relaxable
;
1341 unsigned long insn
, extension
, size
= 0;
1346 /* Get the opcode. */
1347 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); s
++)
1352 /* Find the first opcode with the proper name. */
1353 opcode
= (struct mn10300_opcode
*) hash_find (mn10300_hash
, str
);
1356 as_bad (_("Unrecognized opcode: `%s'"), str
);
1361 while (ISSPACE (*str
))
1364 input_line_pointer
= str
;
1371 int extra_shift
= 0;
1373 errmsg
= _("Invalid opcode/operands");
1375 /* Reset the array of register operands. */
1376 memset (mn10300_reg_operands
, -1, sizeof (mn10300_reg_operands
));
1382 insn
= opcode
->opcode
;
1385 /* If the instruction is not available on the current machine
1386 then it can not possibly match. */
1388 && !(opcode
->machine
== AM33_2
&& HAVE_AM33_2
)
1389 && !(opcode
->machine
== AM33
&& HAVE_AM33
)
1390 && !(opcode
->machine
== AM30
&& HAVE_AM30
))
1393 for (op_idx
= 1, opindex_ptr
= opcode
->operands
;
1395 opindex_ptr
++, op_idx
++)
1397 const struct mn10300_operand
*operand
;
1400 if (next_opindex
== 0)
1402 operand
= &mn10300_operands
[*opindex_ptr
];
1406 operand
= &mn10300_operands
[next_opindex
];
1410 while (*str
== ' ' || *str
== ',')
1413 if (operand
->flags
& MN10300_OPERAND_RELAX
)
1416 /* Gather the operand. */
1417 hold
= input_line_pointer
;
1418 input_line_pointer
= str
;
1420 if (operand
->flags
& MN10300_OPERAND_PAREN
)
1422 if (*input_line_pointer
!= ')' && *input_line_pointer
!= '(')
1424 input_line_pointer
= hold
;
1428 input_line_pointer
++;
1431 /* See if we can match the operands. */
1432 else if (operand
->flags
& MN10300_OPERAND_DREG
)
1434 if (!data_register_name (&ex
))
1436 input_line_pointer
= hold
;
1441 else if (operand
->flags
& MN10300_OPERAND_AREG
)
1443 if (!address_register_name (&ex
))
1445 input_line_pointer
= hold
;
1450 else if (operand
->flags
& MN10300_OPERAND_SP
)
1452 char *start
= input_line_pointer
;
1453 char c
= get_symbol_end ();
1455 if (strcasecmp (start
, "sp") != 0)
1457 *input_line_pointer
= c
;
1458 input_line_pointer
= hold
;
1462 *input_line_pointer
= c
;
1465 else if (operand
->flags
& MN10300_OPERAND_RREG
)
1467 if (!r_register_name (&ex
))
1469 input_line_pointer
= hold
;
1474 else if (operand
->flags
& MN10300_OPERAND_XRREG
)
1476 if (!xr_register_name (&ex
))
1478 input_line_pointer
= hold
;
1483 else if (operand
->flags
& MN10300_OPERAND_FSREG
)
1485 if (!float_register_name (&ex
))
1487 input_line_pointer
= hold
;
1492 else if (operand
->flags
& MN10300_OPERAND_FDREG
)
1494 if (!double_register_name (&ex
))
1496 input_line_pointer
= hold
;
1501 else if (operand
->flags
& MN10300_OPERAND_FPCR
)
1503 char *start
= input_line_pointer
;
1504 char c
= get_symbol_end ();
1506 if (strcasecmp (start
, "fpcr") != 0)
1508 *input_line_pointer
= c
;
1509 input_line_pointer
= hold
;
1513 *input_line_pointer
= c
;
1516 else if (operand
->flags
& MN10300_OPERAND_USP
)
1518 char *start
= input_line_pointer
;
1519 char c
= get_symbol_end ();
1521 if (strcasecmp (start
, "usp") != 0)
1523 *input_line_pointer
= c
;
1524 input_line_pointer
= hold
;
1528 *input_line_pointer
= c
;
1531 else if (operand
->flags
& MN10300_OPERAND_SSP
)
1533 char *start
= input_line_pointer
;
1534 char c
= get_symbol_end ();
1536 if (strcasecmp (start
, "ssp") != 0)
1538 *input_line_pointer
= c
;
1539 input_line_pointer
= hold
;
1543 *input_line_pointer
= c
;
1546 else if (operand
->flags
& MN10300_OPERAND_MSP
)
1548 char *start
= input_line_pointer
;
1549 char c
= get_symbol_end ();
1551 if (strcasecmp (start
, "msp") != 0)
1553 *input_line_pointer
= c
;
1554 input_line_pointer
= hold
;
1558 *input_line_pointer
= c
;
1561 else if (operand
->flags
& MN10300_OPERAND_PC
)
1563 char *start
= input_line_pointer
;
1564 char c
= get_symbol_end ();
1566 if (strcasecmp (start
, "pc") != 0)
1568 *input_line_pointer
= c
;
1569 input_line_pointer
= hold
;
1573 *input_line_pointer
= c
;
1576 else if (operand
->flags
& MN10300_OPERAND_EPSW
)
1578 char *start
= input_line_pointer
;
1579 char c
= get_symbol_end ();
1581 if (strcasecmp (start
, "epsw") != 0)
1583 *input_line_pointer
= c
;
1584 input_line_pointer
= hold
;
1588 *input_line_pointer
= c
;
1591 else if (operand
->flags
& MN10300_OPERAND_PLUS
)
1593 if (*input_line_pointer
!= '+')
1595 input_line_pointer
= hold
;
1599 input_line_pointer
++;
1602 else if (operand
->flags
& MN10300_OPERAND_PSW
)
1604 char *start
= input_line_pointer
;
1605 char c
= get_symbol_end ();
1607 if (strcasecmp (start
, "psw") != 0)
1609 *input_line_pointer
= c
;
1610 input_line_pointer
= hold
;
1614 *input_line_pointer
= c
;
1617 else if (operand
->flags
& MN10300_OPERAND_MDR
)
1619 char *start
= input_line_pointer
;
1620 char c
= get_symbol_end ();
1622 if (strcasecmp (start
, "mdr") != 0)
1624 *input_line_pointer
= c
;
1625 input_line_pointer
= hold
;
1629 *input_line_pointer
= c
;
1632 else if (operand
->flags
& MN10300_OPERAND_REG_LIST
)
1634 unsigned int value
= 0;
1635 if (*input_line_pointer
!= '[')
1637 input_line_pointer
= hold
;
1643 input_line_pointer
++;
1645 /* We used to reject a null register list here; however,
1646 we accept it now so the compiler can emit "call"
1647 instructions for all calls to named functions.
1649 The linker can then fill in the appropriate bits for the
1650 register list and stack size or change the instruction
1651 into a "calls" if using "call" is not profitable. */
1652 while (*input_line_pointer
!= ']')
1657 if (*input_line_pointer
== ',')
1658 input_line_pointer
++;
1660 start
= input_line_pointer
;
1661 c
= get_symbol_end ();
1663 if (strcasecmp (start
, "d2") == 0)
1666 *input_line_pointer
= c
;
1668 else if (strcasecmp (start
, "d3") == 0)
1671 *input_line_pointer
= c
;
1673 else if (strcasecmp (start
, "a2") == 0)
1676 *input_line_pointer
= c
;
1678 else if (strcasecmp (start
, "a3") == 0)
1681 *input_line_pointer
= c
;
1683 else if (strcasecmp (start
, "other") == 0)
1686 *input_line_pointer
= c
;
1689 && strcasecmp (start
, "exreg0") == 0)
1692 *input_line_pointer
= c
;
1695 && strcasecmp (start
, "exreg1") == 0)
1698 *input_line_pointer
= c
;
1701 && strcasecmp (start
, "exother") == 0)
1704 *input_line_pointer
= c
;
1707 && strcasecmp (start
, "all") == 0)
1710 *input_line_pointer
= c
;
1714 input_line_pointer
= hold
;
1719 input_line_pointer
++;
1720 mn10300_insert_operand (&insn
, &extension
, operand
,
1721 value
, (char *) NULL
, 0, 0);
1725 else if (data_register_name (&ex
))
1727 input_line_pointer
= hold
;
1731 else if (address_register_name (&ex
))
1733 input_line_pointer
= hold
;
1737 else if (other_register_name (&ex
))
1739 input_line_pointer
= hold
;
1743 else if (HAVE_AM33
&& r_register_name (&ex
))
1745 input_line_pointer
= hold
;
1749 else if (HAVE_AM33
&& xr_register_name (&ex
))
1751 input_line_pointer
= hold
;
1755 else if (HAVE_AM33_2
&& float_register_name (&ex
))
1757 input_line_pointer
= hold
;
1761 else if (HAVE_AM33_2
&& double_register_name (&ex
))
1763 input_line_pointer
= hold
;
1767 else if (*str
== ')' || *str
== '(')
1769 input_line_pointer
= hold
;
1781 errmsg
= _("illegal operand");
1784 errmsg
= _("missing operand");
1790 mask
= MN10300_OPERAND_DREG
| MN10300_OPERAND_AREG
;
1792 mask
|= MN10300_OPERAND_RREG
| MN10300_OPERAND_XRREG
;
1794 mask
|= MN10300_OPERAND_FSREG
| MN10300_OPERAND_FDREG
;
1795 if ((operand
->flags
& mask
) == 0)
1797 input_line_pointer
= hold
;
1802 if (opcode
->format
== FMT_D1
|| opcode
->format
== FMT_S1
)
1804 else if (opcode
->format
== FMT_D2
1805 || opcode
->format
== FMT_D4
1806 || opcode
->format
== FMT_S2
1807 || opcode
->format
== FMT_S4
1808 || opcode
->format
== FMT_S6
1809 || opcode
->format
== FMT_D5
)
1811 else if (opcode
->format
== FMT_D7
)
1813 else if (opcode
->format
== FMT_D8
|| opcode
->format
== FMT_D9
)
1818 mn10300_insert_operand (&insn
, &extension
, operand
,
1819 ex
.X_add_number
, (char *) NULL
,
1822 /* And note the register number in the register array. */
1823 mn10300_reg_operands
[op_idx
- 1] = ex
.X_add_number
;
1828 /* If this operand can be promoted, and it doesn't
1829 fit into the allocated bitfield for this insn,
1830 then promote it (ie this opcode does not match). */
1832 & (MN10300_OPERAND_PROMOTE
| MN10300_OPERAND_RELAX
)
1833 && !check_operand (insn
, operand
, ex
.X_add_number
))
1835 input_line_pointer
= hold
;
1840 mn10300_insert_operand (&insn
, &extension
, operand
,
1841 ex
.X_add_number
, (char *) NULL
,
1846 /* If this operand can be promoted, then this opcode didn't
1847 match since we can't know if it needed promotion! */
1848 if (operand
->flags
& MN10300_OPERAND_PROMOTE
)
1850 input_line_pointer
= hold
;
1855 /* We need to generate a fixup for this expression. */
1856 if (fc
>= MAX_INSN_FIXUPS
)
1857 as_fatal (_("too many fixups"));
1858 fixups
[fc
].exp
= ex
;
1859 fixups
[fc
].opindex
= *opindex_ptr
;
1860 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1861 if (mn10300_check_fixup (& fixups
[fc
]))
1868 str
= input_line_pointer
;
1869 input_line_pointer
= hold
;
1871 while (*str
== ' ' || *str
== ',')
1876 /* Make sure we used all the operands! */
1880 /* If this instruction has registers that must not match, verify
1881 that they do indeed not match. */
1882 if (opcode
->no_match_operands
)
1886 /* Look at each operand to see if it's marked. */
1887 for (i
= 0; i
< MN10300_MAX_OPERANDS
; i
++)
1889 if ((1 << i
) & opcode
->no_match_operands
)
1893 /* operand I is marked. Check that it does not match any
1894 operands > I which are marked. */
1895 for (j
= i
+ 1; j
< MN10300_MAX_OPERANDS
; j
++)
1897 if (((1 << j
) & opcode
->no_match_operands
)
1898 && mn10300_reg_operands
[i
] == mn10300_reg_operands
[j
])
1900 errmsg
= _("Invalid register specification.");
1912 next_opcode
= opcode
+ 1;
1913 if (!strcmp (next_opcode
->name
, opcode
->name
))
1915 opcode
= next_opcode
;
1919 as_bad ("%s", errmsg
);
1925 while (ISSPACE (*str
))
1929 as_bad (_("junk at end of line: `%s'"), str
);
1931 input_line_pointer
= str
;
1933 /* Determine the size of the instruction. */
1934 if (opcode
->format
== FMT_S0
)
1937 if (opcode
->format
== FMT_S1
|| opcode
->format
== FMT_D0
)
1940 if (opcode
->format
== FMT_S2
|| opcode
->format
== FMT_D1
)
1943 if (opcode
->format
== FMT_D6
)
1946 if (opcode
->format
== FMT_D7
|| opcode
->format
== FMT_D10
)
1949 if (opcode
->format
== FMT_D8
)
1952 if (opcode
->format
== FMT_D9
)
1955 if (opcode
->format
== FMT_S4
)
1958 if (opcode
->format
== FMT_S6
|| opcode
->format
== FMT_D5
)
1961 if (opcode
->format
== FMT_D2
)
1964 if (opcode
->format
== FMT_D3
)
1967 if (opcode
->format
== FMT_D4
)
1970 if (relaxable
&& fc
> 0)
1972 /* On a 64-bit host the size of an 'int' is not the same
1973 as the size of a pointer, so we need a union to convert
1974 the opindex field of the fr_cgen structure into a char *
1975 so that it can be stored in the frag. We do not have
1976 to worry about loosing accuracy as we are not going to
1977 be even close to the 32bit limit of the int. */
1986 /* We want to anchor the line info to the previous frag (if
1987 there isn't one, create it), so that, when the insn is
1988 resized, we still get the right address for the beginning of
1991 dwarf2_emit_insn (0);
1996 /* Handle bra specially. Basically treat it like jmp so
1997 that we automatically handle 8, 16 and 32 bit offsets
1998 correctly as well as jumps to an undefined address.
2000 It is also important to not treat it like other bCC
2001 instructions since the long forms of bra is different
2002 from other bCC instructions. */
2003 if (opcode
->opcode
== 0xca00)
2015 else if (size
== 3 && opcode
->opcode
== 0xcc0000)
2017 else if (size
== 3 && (opcode
->opcode
& 0xfff000) == 0xf8d000)
2019 /* bCC (uncommon cases) */
2023 opindex_converter
.opindex
= fixups
[0].opindex
;
2024 f
= frag_var (rs_machine_dependent
, 8, 8 - size
, type
,
2025 fixups
[0].exp
.X_add_symbol
,
2026 fixups
[0].exp
.X_add_number
,
2027 opindex_converter
.ptr
);
2029 /* This is pretty hokey. We basically just care about the
2030 opcode, so we have to write out the first word big endian.
2032 The exception is "call", which has two operands that we
2035 The first operand (the register list) happens to be in the
2036 first instruction word, and will be in the right place if
2037 we output the first word in big endian mode.
2039 The second operand (stack size) is in the extension word,
2040 and we want it to appear as the first character in the extension
2041 word (as it appears in memory). Luckily, writing the extension
2042 word in big endian format will do what we want. */
2043 number_to_chars_bigendian (f
, insn
, size
> 4 ? 4 : size
);
2046 number_to_chars_bigendian (f
+ 4, extension
, 4);
2047 number_to_chars_bigendian (f
+ 8, 0, size
- 8);
2050 number_to_chars_bigendian (f
+ 4, extension
, size
- 4);
2054 /* Allocate space for the instruction. */
2055 f
= frag_more (size
);
2057 /* Fill in bytes for the instruction. Note that opcode fields
2058 are written big-endian, 16 & 32bit immediates are written
2059 little endian. Egad. */
2060 if (opcode
->format
== FMT_S0
2061 || opcode
->format
== FMT_S1
2062 || opcode
->format
== FMT_D0
2063 || opcode
->format
== FMT_D6
2064 || opcode
->format
== FMT_D7
2065 || opcode
->format
== FMT_D10
2066 || opcode
->format
== FMT_D1
)
2068 number_to_chars_bigendian (f
, insn
, size
);
2070 else if (opcode
->format
== FMT_S2
2071 && opcode
->opcode
!= 0xdf0000
2072 && opcode
->opcode
!= 0xde0000)
2074 /* A format S2 instruction that is _not_ "ret" and "retf". */
2075 number_to_chars_bigendian (f
, (insn
>> 16) & 0xff, 1);
2076 number_to_chars_littleendian (f
+ 1, insn
& 0xffff, 2);
2078 else if (opcode
->format
== FMT_S2
)
2080 /* This must be a ret or retf, which is written entirely in
2081 big-endian format. */
2082 number_to_chars_bigendian (f
, insn
, 3);
2084 else if (opcode
->format
== FMT_S4
2085 && opcode
->opcode
!= 0xdc000000)
2087 /* This must be a format S4 "call" instruction. What a pain. */
2088 unsigned long temp
= (insn
>> 8) & 0xffff;
2089 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
2090 number_to_chars_littleendian (f
+ 1, temp
, 2);
2091 number_to_chars_bigendian (f
+ 3, insn
& 0xff, 1);
2092 number_to_chars_bigendian (f
+ 4, extension
& 0xff, 1);
2094 else if (opcode
->format
== FMT_S4
)
2096 /* This must be a format S4 "jmp" instruction. */
2097 unsigned long temp
= ((insn
& 0xffffff) << 8) | (extension
& 0xff);
2098 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
2099 number_to_chars_littleendian (f
+ 1, temp
, 4);
2101 else if (opcode
->format
== FMT_S6
)
2103 unsigned long temp
= ((insn
& 0xffffff) << 8)
2104 | ((extension
>> 16) & 0xff);
2105 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
2106 number_to_chars_littleendian (f
+ 1, temp
, 4);
2107 number_to_chars_bigendian (f
+ 5, (extension
>> 8) & 0xff, 1);
2108 number_to_chars_bigendian (f
+ 6, extension
& 0xff, 1);
2110 else if (opcode
->format
== FMT_D2
2111 && opcode
->opcode
!= 0xfaf80000
2112 && opcode
->opcode
!= 0xfaf00000
2113 && opcode
->opcode
!= 0xfaf40000)
2115 /* A format D2 instruction where the 16bit immediate is
2116 really a single 16bit value, not two 8bit values. */
2117 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2118 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
2120 else if (opcode
->format
== FMT_D2
)
2122 /* A format D2 instruction where the 16bit immediate
2123 is really two 8bit immediates. */
2124 number_to_chars_bigendian (f
, insn
, 4);
2126 else if (opcode
->format
== FMT_D3
)
2128 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2129 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
2130 number_to_chars_bigendian (f
+ 4, extension
& 0xff, 1);
2132 else if (opcode
->format
== FMT_D4
)
2134 unsigned long temp
= ((insn
& 0xffff) << 16) | (extension
& 0xffff);
2136 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2137 number_to_chars_littleendian (f
+ 2, temp
, 4);
2139 else if (opcode
->format
== FMT_D5
)
2141 unsigned long temp
= (((insn
& 0xffff) << 16)
2142 | ((extension
>> 8) & 0xffff));
2144 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
2145 number_to_chars_littleendian (f
+ 2, temp
, 4);
2146 number_to_chars_bigendian (f
+ 6, extension
& 0xff, 1);
2148 else if (opcode
->format
== FMT_D8
)
2150 unsigned long temp
= ((insn
& 0xff) << 16) | (extension
& 0xffff);
2152 number_to_chars_bigendian (f
, (insn
>> 8) & 0xffffff, 3);
2153 number_to_chars_bigendian (f
+ 3, (temp
& 0xff), 1);
2154 number_to_chars_littleendian (f
+ 4, temp
>> 8, 2);
2156 else if (opcode
->format
== FMT_D9
)
2158 unsigned long temp
= ((insn
& 0xff) << 24) | (extension
& 0xffffff);
2160 number_to_chars_bigendian (f
, (insn
>> 8) & 0xffffff, 3);
2161 number_to_chars_littleendian (f
+ 3, temp
, 4);
2164 /* Create any fixups. */
2165 for (i
= 0; i
< fc
; i
++)
2167 const struct mn10300_operand
*operand
;
2169 operand
= &mn10300_operands
[fixups
[i
].opindex
];
2170 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
2171 && fixups
[i
].reloc
!= BFD_RELOC_32_GOT_PCREL
2172 && fixups
[i
].reloc
!= BFD_RELOC_32_GOTOFF
2173 && fixups
[i
].reloc
!= BFD_RELOC_32_PLT_PCREL
2174 && fixups
[i
].reloc
!= BFD_RELOC_MN10300_GOT32
)
2176 reloc_howto_type
*reloc_howto
;
2181 reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
2187 size
= bfd_get_reloc_size (reloc_howto
);
2189 if (size
< 1 || size
> 4)
2193 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
2194 size
, &fixups
[i
].exp
,
2195 reloc_howto
->pc_relative
,
2200 int reloc
, pcrel
, reloc_size
, offset
;
2203 reloc
= BFD_RELOC_NONE
;
2204 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2205 reloc
= fixups
[i
].reloc
;
2206 /* How big is the reloc? Remember SPLIT relocs are
2207 implicitly 32bits. */
2208 if ((operand
->flags
& MN10300_OPERAND_SPLIT
) != 0)
2210 else if ((operand
->flags
& MN10300_OPERAND_24BIT
) != 0)
2213 reloc_size
= operand
->bits
;
2215 /* Is the reloc pc-relative? */
2216 pcrel
= (operand
->flags
& MN10300_OPERAND_PCREL
) != 0;
2217 if (reloc
!= BFD_RELOC_NONE
)
2218 pcrel
= bfd_reloc_type_lookup (stdoutput
, reloc
)->pc_relative
;
2220 offset
= size
- (reloc_size
+ operand
->shift
) / 8;
2222 /* Choose a proper BFD relocation type. */
2223 if (reloc
!= BFD_RELOC_NONE
)
2227 if (reloc_size
== 32)
2228 reloc
= BFD_RELOC_32_PCREL
;
2229 else if (reloc_size
== 16)
2230 reloc
= BFD_RELOC_16_PCREL
;
2231 else if (reloc_size
== 8)
2232 reloc
= BFD_RELOC_8_PCREL
;
2238 if (reloc_size
== 32)
2239 reloc
= BFD_RELOC_32
;
2240 else if (reloc_size
== 16)
2241 reloc
= BFD_RELOC_16
;
2242 else if (reloc_size
== 8)
2243 reloc
= BFD_RELOC_8
;
2248 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
2249 reloc_size
/ 8, &fixups
[i
].exp
, pcrel
,
2250 ((bfd_reloc_code_real_type
) reloc
));
2253 fixP
->fx_offset
+= offset
;
2257 dwarf2_emit_insn (size
);
2261 /* If while processing a fixup, a reloc really needs to be created
2262 then it is done here. */
2265 tc_gen_reloc (seg
, fixp
)
2266 asection
*seg ATTRIBUTE_UNUSED
;
2270 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2272 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2273 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2275 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2276 _("reloc %d not supported by object file format"),
2277 (int) fixp
->fx_r_type
);
2280 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2283 && S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2285 fixp
->fx_offset
-= S_GET_VALUE (fixp
->fx_subsy
);
2289 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
2291 reloc
->sym_ptr_ptr
= NULL
;
2293 /* If we got a difference between two symbols, and the
2294 subtracted symbol is in the current section, use a
2295 PC-relative relocation. If both symbols are in the same
2296 section, the difference would have already been simplified
2298 if (S_GET_SEGMENT (fixp
->fx_subsy
) == seg
)
2300 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2301 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2302 reloc
->addend
= (reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
)
2305 switch (fixp
->fx_r_type
)
2308 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2313 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2314 BFD_RELOC_16_PCREL
);
2318 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2319 BFD_RELOC_24_PCREL
);
2323 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
2324 BFD_RELOC_32_PCREL
);
2328 /* Try to compute the absolute value below. */
2333 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
2334 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
2336 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2337 "Difference of symbols in different sections is not supported");
2341 char *fixpos
= fixp
->fx_where
+ fixp
->fx_frag
->fr_literal
;
2343 reloc
->addend
= (S_GET_VALUE (fixp
->fx_addsy
)
2344 - S_GET_VALUE (fixp
->fx_subsy
) + fixp
->fx_offset
);
2346 switch (fixp
->fx_r_type
)
2349 md_number_to_chars (fixpos
, reloc
->addend
, 1);
2353 md_number_to_chars (fixpos
, reloc
->addend
, 2);
2357 md_number_to_chars (fixpos
, reloc
->addend
, 3);
2361 md_number_to_chars (fixpos
, reloc
->addend
, 4);
2366 = (asymbol
**) bfd_abs_section_ptr
->symbol_ptr_ptr
;
2371 if (reloc
->sym_ptr_ptr
)
2372 free (reloc
->sym_ptr_ptr
);
2378 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2379 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2380 reloc
->addend
= fixp
->fx_offset
;
2386 md_estimate_size_before_relax (fragp
, seg
)
2390 if (fragp
->fr_subtype
== 6
2391 && (!S_IS_DEFINED (fragp
->fr_symbol
)
2392 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
2393 fragp
->fr_subtype
= 7;
2394 else if (fragp
->fr_subtype
== 8
2395 && (!S_IS_DEFINED (fragp
->fr_symbol
)
2396 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
2397 fragp
->fr_subtype
= 9;
2398 else if (fragp
->fr_subtype
== 10
2399 && (!S_IS_DEFINED (fragp
->fr_symbol
)
2400 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
2401 fragp
->fr_subtype
= 12;
2403 if (fragp
->fr_subtype
== 13)
2405 if (fragp
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
2408 return md_relax_table
[fragp
->fr_subtype
].rlx_length
;
2412 md_pcrel_from (fixp
)
2415 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& !S_IS_DEFINED (fixp
->fx_addsy
))
2417 /* The symbol is undefined. Let the linker figure it out. */
2420 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2424 md_apply_fix (fixP
, valP
, seg
)
2429 char * fixpos
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2431 int value
= (int) * valP
;
2433 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
2435 /* This should never happen. */
2436 if (seg
->flags
& SEC_ALLOC
)
2439 /* The value we are passed in *valuep includes the symbol values.
2440 If we are doing this relocation the code in write.c is going to
2441 call bfd_install_relocation, which is also going to use the symbol
2442 value. That means that if the reloc is fully resolved we want to
2443 use *valuep since bfd_install_relocation is not being used.
2445 However, if the reloc is not fully resolved we do not want to use
2446 *valuep, and must use fx_offset instead. However, if the reloc
2447 is PC relative, we do want to use *valuep since it includes the
2448 result of md_pcrel_from. */
2449 if (fixP
->fx_addsy
!= (symbolS
*) NULL
&& ! fixP
->fx_pcrel
)
2450 value
= fixP
->fx_offset
;
2452 /* If the fix is relative to a symbol which is not defined, or not
2453 in the same segment as the fix, we cannot resolve it here. */
2454 if (fixP
->fx_addsy
!= NULL
2455 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2456 || (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)))
2462 switch (fixP
->fx_r_type
)
2465 case BFD_RELOC_8_PCREL
:
2470 case BFD_RELOC_16_PCREL
:
2475 case BFD_RELOC_32_PCREL
:
2479 case BFD_RELOC_VTABLE_INHERIT
:
2480 case BFD_RELOC_VTABLE_ENTRY
:
2484 case BFD_RELOC_NONE
:
2486 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2487 _("Bad relocation fixup type (%d)"), fixP
->fx_r_type
);
2490 md_number_to_chars (fixpos
, value
, size
);
2492 /* If a symbol remains, pass the fixup, as a reloc, onto the linker. */
2493 if (fixP
->fx_addsy
== NULL
)
2497 /* Return zero if the fixup in fixp should be left alone and not
2501 mn10300_fix_adjustable (fixp
)
2504 if (TC_FORCE_RELOCATION_LOCAL (fixp
))
2507 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2508 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2511 /* Do not adjust relocations involving symbols in code sections,
2512 because it breaks linker relaxations. This could be fixed in the
2513 linker, but this fix is simpler, and it pretty much only affects
2514 object size a little bit. */
2515 if (S_GET_SEGMENT (fixp
->fx_addsy
)->flags
& SEC_CODE
)
2518 /* Likewise, do not adjust symbols that won't be merged, or debug
2519 symbols, because they too break relaxation. We do want to adjust
2520 other mergable symbols, like .rodata, because code relaxations
2521 need section-relative symbols to properly relax them. */
2522 if (! (S_GET_SEGMENT(fixp
->fx_addsy
)->flags
& SEC_MERGE
))
2524 if (strncmp (S_GET_SEGMENT (fixp
->fx_addsy
)->name
, ".debug", 6) == 0)
2530 /* Insert an operand value into an instruction. */
2533 mn10300_insert_operand (insnp
, extensionp
, operand
, val
, file
, line
, shift
)
2534 unsigned long *insnp
;
2535 unsigned long *extensionp
;
2536 const struct mn10300_operand
*operand
;
2542 /* No need to check 32bit operands for a bit. Note that
2543 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
2544 if (operand
->bits
!= 32
2545 && (operand
->flags
& MN10300_OPERAND_SPLIT
) == 0)
2551 bits
= operand
->bits
;
2552 if (operand
->flags
& MN10300_OPERAND_24BIT
)
2555 if ((operand
->flags
& MN10300_OPERAND_SIGNED
) != 0)
2557 max
= (1 << (bits
- 1)) - 1;
2558 min
= - (1 << (bits
- 1));
2562 max
= (1 << bits
) - 1;
2568 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
2569 as_warn_value_out_of_range (_("operand"), test
, (offsetT
) min
, (offsetT
) max
, file
, line
);
2572 if ((operand
->flags
& MN10300_OPERAND_SPLIT
) != 0)
2574 *insnp
|= (val
>> (32 - operand
->bits
)) & ((1 << operand
->bits
) - 1);
2575 *extensionp
|= ((val
& ((1 << (32 - operand
->bits
)) - 1))
2578 else if ((operand
->flags
& MN10300_OPERAND_24BIT
) != 0)
2580 *insnp
|= (val
>> (24 - operand
->bits
)) & ((1 << operand
->bits
) - 1);
2581 *extensionp
|= ((val
& ((1 << (24 - operand
->bits
)) - 1))
2584 else if ((operand
->flags
& (MN10300_OPERAND_FSREG
| MN10300_OPERAND_FDREG
)))
2586 /* See devo/opcodes/m10300-opc.c just before #define FSM0 for an
2587 explanation of these variables. Note that FMT-implied shifts
2588 are not taken into account for FP registers. */
2589 unsigned long mask_low
, mask_high
;
2590 int shl_low
, shr_high
, shl_high
;
2592 switch (operand
->bits
)
2595 /* Handle regular FP registers. */
2596 if (operand
->shift
>= 0)
2598 /* This is an `m' register. */
2599 shl_low
= operand
->shift
;
2600 shl_high
= 8 + (8 & shl_low
) + (shl_low
& 4) / 4;
2604 /* This is an `n' register. */
2605 shl_low
= -operand
->shift
;
2606 shl_high
= shl_low
/ 4;
2615 /* Handle accumulators. */
2616 shl_low
= -operand
->shift
;
2626 *insnp
|= ((((val
& mask_high
) >> shr_high
) << shl_high
)
2627 | ((val
& mask_low
) << shl_low
));
2629 else if ((operand
->flags
& MN10300_OPERAND_EXTENDED
) == 0)
2631 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2632 << (operand
->shift
+ shift
));
2634 if ((operand
->flags
& MN10300_OPERAND_REPEATED
) != 0)
2635 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2636 << (operand
->shift
+ shift
+ operand
->bits
));
2640 *extensionp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2641 << (operand
->shift
+ shift
));
2643 if ((operand
->flags
& MN10300_OPERAND_REPEATED
) != 0)
2644 *extensionp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2645 << (operand
->shift
+ shift
+ operand
->bits
));
2649 static unsigned long
2650 check_operand (insn
, operand
, val
)
2651 unsigned long insn ATTRIBUTE_UNUSED
;
2652 const struct mn10300_operand
*operand
;
2655 /* No need to check 32bit operands for a bit. Note that
2656 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
2657 if (operand
->bits
!= 32
2658 && (operand
->flags
& MN10300_OPERAND_SPLIT
) == 0)
2664 bits
= operand
->bits
;
2665 if (operand
->flags
& MN10300_OPERAND_24BIT
)
2668 if ((operand
->flags
& MN10300_OPERAND_SIGNED
) != 0)
2670 max
= (1 << (bits
- 1)) - 1;
2671 min
= - (1 << (bits
- 1));
2675 max
= (1 << bits
) - 1;
2681 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
2690 set_arch_mach (mach
)
2693 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, mach
))
2694 as_warn (_("could not set architecture and machine"));
2696 current_machine
= mach
;
2699 static inline char * mn10300_end_of_match
PARAMS ((char *, char *));
2701 static inline char *
2702 mn10300_end_of_match (cont
, what
)
2705 int len
= strlen (what
);
2707 if (strncmp (cont
, what
, strlen (what
)) == 0
2708 && ! is_part_of_name (cont
[len
]))
2715 mn10300_parse_name (name
, exprP
, mode
, nextcharP
)
2718 enum expr_mode mode
;
2721 char *next
= input_line_pointer
;
2726 exprP
->X_op_symbol
= NULL
;
2728 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
2731 GOT_symbol
= symbol_find_or_make (name
);
2733 exprP
->X_add_symbol
= GOT_symbol
;
2735 /* If we have an absolute symbol or a reg,
2736 then we know its value now. */
2737 segment
= S_GET_SEGMENT (exprP
->X_add_symbol
);
2738 if (mode
!= expr_defer
&& segment
== absolute_section
)
2740 exprP
->X_op
= O_constant
;
2741 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
2742 exprP
->X_add_symbol
= NULL
;
2744 else if (mode
!= expr_defer
&& segment
== reg_section
)
2746 exprP
->X_op
= O_register
;
2747 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
2748 exprP
->X_add_symbol
= NULL
;
2752 exprP
->X_op
= O_symbol
;
2753 exprP
->X_add_number
= 0;
2759 exprP
->X_add_symbol
= symbol_find_or_make (name
);
2761 if (*nextcharP
!= '@')
2763 else if ((next_end
= mn10300_end_of_match (next
+ 1, "GOTOFF")))
2764 reloc_type
= BFD_RELOC_32_GOTOFF
;
2765 else if ((next_end
= mn10300_end_of_match (next
+ 1, "GOT")))
2766 reloc_type
= BFD_RELOC_MN10300_GOT32
;
2767 else if ((next_end
= mn10300_end_of_match (next
+ 1, "PLT")))
2768 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
2772 *input_line_pointer
= *nextcharP
;
2773 input_line_pointer
= next_end
;
2774 *nextcharP
= *input_line_pointer
;
2775 *input_line_pointer
= '\0';
2777 exprP
->X_op
= O_PIC_reloc
;
2778 exprP
->X_add_number
= 0;
2779 exprP
->X_md
= reloc_type
;