1 /* tc-mn10300.c -- Assembler code for the Matsushita 10300
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "safe-ctype.h"
26 #include "opcode/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
[] = {
60 {0x7fff, -0x8000, 5, 2},
61 {0x7fffffff, -0x80000000, 7, 0},
63 /* bCC relaxing (uncommon cases) */
65 {0x7fff, -0x8000, 6, 5},
66 {0x7fffffff, -0x80000000, 8, 0},
69 {0x7fff, -0x8000, 5, 7},
70 {0x7fffffff, -0x80000000, 7, 0},
73 {0x7fff, -0x8000, 4, 9},
74 {0x7fffffff, -0x80000000, 6, 0},
78 {0x7fff, -0x8000, 3, 12},
79 {0x7fffffff, -0x80000000, 5, 0},
83 /* Local functions. */
84 static void mn10300_insert_operand
PARAMS ((unsigned long *, unsigned long *,
85 const struct mn10300_operand
*,
86 offsetT
, char *, unsigned,
88 static unsigned long check_operand
PARAMS ((unsigned long,
89 const struct mn10300_operand
*,
91 static int reg_name_search
PARAMS ((const struct reg_name
*, int, const char *));
92 static boolean data_register_name
PARAMS ((expressionS
*expressionP
));
93 static boolean address_register_name
PARAMS ((expressionS
*expressionP
));
94 static boolean other_register_name
PARAMS ((expressionS
*expressionP
));
95 static void set_arch_mach
PARAMS ((unsigned int));
97 /* Set linkrelax here to avoid fixups in most sections. */
100 static int current_machine
;
103 #define MAX_INSN_FIXUPS (5)
108 bfd_reloc_code_real_type reloc
;
110 struct mn10300_fixup fixups
[MAX_INSN_FIXUPS
];
113 /* We must store the value of each register operand so that we can
114 verify that certain registers do not match. */
115 int mn10300_reg_operands
[MN10300_MAX_OPERANDS
];
117 const char *md_shortopts
= "";
118 struct option md_longopts
[] = {
119 {NULL
, no_argument
, NULL
, 0}
121 size_t md_longopts_size
= sizeof (md_longopts
);
123 /* The target specific pseudo-ops which we support. */
124 const pseudo_typeS md_pseudo_table
[] =
126 { "file", dwarf2_directive_file
, 0 },
127 { "loc", dwarf2_directive_loc
, 0 },
128 { "am30", set_arch_mach
, AM30
},
129 { "am33", set_arch_mach
, AM33
},
130 { "mn10300", set_arch_mach
, MN103
},
134 #define HAVE_AM33 (current_machine == AM33)
135 #define HAVE_AM30 (current_machine == AM30)
137 /* Opcode hash table. */
138 static struct hash_control
*mn10300_hash
;
140 /* This table is sorted. Suitable for searching by a binary search. */
141 static const struct reg_name data_registers
[] =
148 #define DATA_REG_NAME_CNT \
149 (sizeof (data_registers) / sizeof (struct reg_name))
151 static const struct reg_name address_registers
[] =
159 #define ADDRESS_REG_NAME_CNT \
160 (sizeof (address_registers) / sizeof (struct reg_name))
162 static const struct reg_name r_registers
[] =
206 #define R_REG_NAME_CNT \
207 (sizeof (r_registers) / sizeof (struct reg_name))
209 static const struct reg_name xr_registers
[] =
234 #define XR_REG_NAME_CNT \
235 (sizeof (xr_registers) / sizeof (struct reg_name))
237 /* We abuse the `value' field, that would be otherwise unused, to
238 encode the architecture on which (access to) the register was
239 introduced. FIXME: we should probably warn when we encounter a
240 register name when assembling for an architecture that doesn't
241 support it, before parsing it as a symbol name. */
242 static const struct reg_name other_registers
[] =
251 #define OTHER_REG_NAME_CNT \
252 (sizeof (other_registers) / sizeof (struct reg_name))
254 /* reg_name_search does a binary search of the given register table
255 to see if "name" is a valid regiter name. Returns the register
256 number from the array on success, or -1 on failure. */
259 reg_name_search (regs
, regcount
, name
)
260 const struct reg_name
*regs
;
264 int middle
, low
, high
;
272 middle
= (low
+ high
) / 2;
273 cmp
= strcasecmp (name
, regs
[middle
].name
);
279 return regs
[middle
].value
;
285 /* Summary of register_name().
287 * in: Input_line_pointer points to 1st char of operand.
289 * out: An expressionS.
290 * The operand may have been a register: in this case, X_op == O_register,
291 * X_add_number is set to the register number, and truth is returned.
292 * Input_line_pointer->(next non-blank) char after operand, or is in
293 * its original state.
297 r_register_name (expressionP
)
298 expressionS
*expressionP
;
305 /* Find the spelling of the operand. */
306 start
= name
= input_line_pointer
;
308 c
= get_symbol_end ();
309 reg_number
= reg_name_search (r_registers
, R_REG_NAME_CNT
, name
);
311 /* Put back the delimiting char. */
312 *input_line_pointer
= c
;
314 /* Look to see if it's in the register table. */
317 expressionP
->X_op
= O_register
;
318 expressionP
->X_add_number
= reg_number
;
320 /* Make the rest nice. */
321 expressionP
->X_add_symbol
= NULL
;
322 expressionP
->X_op_symbol
= NULL
;
327 /* Reset the line as if we had not done anything. */
328 input_line_pointer
= start
;
332 /* Summary of register_name().
334 * in: Input_line_pointer points to 1st char of operand.
336 * out: An expressionS.
337 * The operand may have been a register: in this case, X_op == O_register,
338 * X_add_number is set to the register number, and truth is returned.
339 * Input_line_pointer->(next non-blank) char after operand, or is in
340 * its original state.
344 xr_register_name (expressionP
)
345 expressionS
*expressionP
;
352 /* Find the spelling of the operand. */
353 start
= name
= input_line_pointer
;
355 c
= get_symbol_end ();
356 reg_number
= reg_name_search (xr_registers
, XR_REG_NAME_CNT
, name
);
358 /* Put back the delimiting char. */
359 *input_line_pointer
= c
;
361 /* Look to see if it's in the register table. */
364 expressionP
->X_op
= O_register
;
365 expressionP
->X_add_number
= reg_number
;
367 /* Make the rest nice. */
368 expressionP
->X_add_symbol
= NULL
;
369 expressionP
->X_op_symbol
= NULL
;
374 /* Reset the line as if we had not done anything. */
375 input_line_pointer
= start
;
379 /* Summary of register_name().
381 * in: Input_line_pointer points to 1st char of operand.
383 * out: An expressionS.
384 * The operand may have been a register: in this case, X_op == O_register,
385 * X_add_number is set to the register number, and truth is returned.
386 * Input_line_pointer->(next non-blank) char after operand, or is in
387 * its original state.
391 data_register_name (expressionP
)
392 expressionS
*expressionP
;
399 /* Find the spelling of the operand. */
400 start
= name
= input_line_pointer
;
402 c
= get_symbol_end ();
403 reg_number
= reg_name_search (data_registers
, DATA_REG_NAME_CNT
, name
);
405 /* Put back the delimiting char. */
406 *input_line_pointer
= c
;
408 /* Look to see if it's in the register table. */
411 expressionP
->X_op
= O_register
;
412 expressionP
->X_add_number
= reg_number
;
414 /* Make the rest nice. */
415 expressionP
->X_add_symbol
= NULL
;
416 expressionP
->X_op_symbol
= NULL
;
421 /* Reset the line as if we had not done anything. */
422 input_line_pointer
= start
;
426 /* Summary of register_name().
428 * in: Input_line_pointer points to 1st char of operand.
430 * out: An expressionS.
431 * The operand may have been a register: in this case, X_op == O_register,
432 * X_add_number is set to the register number, and truth is returned.
433 * Input_line_pointer->(next non-blank) char after operand, or is in
434 * its original state.
438 address_register_name (expressionP
)
439 expressionS
*expressionP
;
446 /* Find the spelling of the operand. */
447 start
= name
= input_line_pointer
;
449 c
= get_symbol_end ();
450 reg_number
= reg_name_search (address_registers
, ADDRESS_REG_NAME_CNT
, name
);
452 /* Put back the delimiting char. */
453 *input_line_pointer
= c
;
455 /* Look to see if it's in the register table. */
458 expressionP
->X_op
= O_register
;
459 expressionP
->X_add_number
= reg_number
;
461 /* Make the rest nice. */
462 expressionP
->X_add_symbol
= NULL
;
463 expressionP
->X_op_symbol
= NULL
;
468 /* Reset the line as if we had not done anything. */
469 input_line_pointer
= start
;
473 /* Summary of register_name().
475 * in: Input_line_pointer points to 1st char of operand.
477 * out: An expressionS.
478 * The operand may have been a register: in this case, X_op == O_register,
479 * X_add_number is set to the register number, and truth is returned.
480 * Input_line_pointer->(next non-blank) char after operand, or is in
481 * its original state.
485 other_register_name (expressionP
)
486 expressionS
*expressionP
;
493 /* Find the spelling of the operand. */
494 start
= name
= input_line_pointer
;
496 c
= get_symbol_end ();
497 reg_number
= reg_name_search (other_registers
, OTHER_REG_NAME_CNT
, name
);
499 /* Put back the delimiting char. */
500 *input_line_pointer
= c
;
502 /* Look to see if it's in the register table. */
504 || (reg_number
== AM33
&& HAVE_AM33
))
506 expressionP
->X_op
= O_register
;
507 expressionP
->X_add_number
= 0;
509 /* Make the rest nice. */
510 expressionP
->X_add_symbol
= NULL
;
511 expressionP
->X_op_symbol
= NULL
;
516 /* Reset the line as if we had not done anything. */
517 input_line_pointer
= start
;
522 md_show_usage (stream
)
525 fprintf (stream
, _("MN10300 options:\n\
530 md_parse_option (c
, arg
)
531 int c ATTRIBUTE_UNUSED
;
532 char *arg ATTRIBUTE_UNUSED
;
538 md_undefined_symbol (name
)
539 char *name ATTRIBUTE_UNUSED
;
545 md_atof (type
, litp
, sizep
)
551 LITTLENUM_TYPE words
[4];
567 return "bad call to md_atof";
570 t
= atof_ieee (input_line_pointer
, type
, words
);
572 input_line_pointer
= t
;
576 for (i
= prec
- 1; i
>= 0; i
--)
578 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
586 md_convert_frag (abfd
, sec
, fragP
)
587 bfd
*abfd ATTRIBUTE_UNUSED
;
591 static unsigned long label_count
= 0;
594 subseg_change (sec
, 0);
595 if (fragP
->fr_subtype
== 0)
597 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
598 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
602 else if (fragP
->fr_subtype
== 1)
604 /* Reverse the condition of the first branch. */
605 int offset
= fragP
->fr_fix
;
606 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
643 fragP
->fr_literal
[offset
] = opcode
;
645 /* Create a fixup for the reversed conditional branch. */
646 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
647 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
648 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
649 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
651 /* Now create the unconditional branch + fixup to the
653 fragP
->fr_literal
[offset
+ 2] = 0xcc;
654 fix_new (fragP
, fragP
->fr_fix
+ 3, 2, fragP
->fr_symbol
,
655 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
659 else if (fragP
->fr_subtype
== 2)
661 /* Reverse the condition of the first branch. */
662 int offset
= fragP
->fr_fix
;
663 int opcode
= fragP
->fr_literal
[offset
] & 0xff;
700 fragP
->fr_literal
[offset
] = opcode
;
702 /* Create a fixup for the reversed conditional branch. */
703 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
704 fix_new (fragP
, fragP
->fr_fix
+ 1, 1,
705 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
706 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
708 /* Now create the unconditional branch + fixup to the
710 fragP
->fr_literal
[offset
+ 2] = 0xdc;
711 fix_new (fragP
, fragP
->fr_fix
+ 3, 4, fragP
->fr_symbol
,
712 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
716 else if (fragP
->fr_subtype
== 3)
718 fix_new (fragP
, fragP
->fr_fix
+ 2, 1, fragP
->fr_symbol
,
719 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
723 else if (fragP
->fr_subtype
== 4)
725 /* Reverse the condition of the first branch. */
726 int offset
= fragP
->fr_fix
;
727 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
746 fragP
->fr_literal
[offset
+ 1] = opcode
;
748 /* Create a fixup for the reversed conditional branch. */
749 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
750 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
751 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
752 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
754 /* Now create the unconditional branch + fixup to the
756 fragP
->fr_literal
[offset
+ 3] = 0xcc;
757 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
758 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
762 else if (fragP
->fr_subtype
== 5)
764 /* Reverse the condition of the first branch. */
765 int offset
= fragP
->fr_fix
;
766 int opcode
= fragP
->fr_literal
[offset
+ 1] & 0xff;
782 fragP
->fr_literal
[offset
+ 1] = opcode
;
784 /* Create a fixup for the reversed conditional branch. */
785 sprintf (buf
, ".%s_%ld", FAKE_LABEL_NAME
, label_count
++);
786 fix_new (fragP
, fragP
->fr_fix
+ 2, 1,
787 symbol_new (buf
, sec
, 0, fragP
->fr_next
),
788 fragP
->fr_offset
+ 2, 1, BFD_RELOC_8_PCREL
);
790 /* Now create the unconditional branch + fixup to the
792 fragP
->fr_literal
[offset
+ 3] = 0xdc;
793 fix_new (fragP
, fragP
->fr_fix
+ 4, 4, fragP
->fr_symbol
,
794 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
798 else if (fragP
->fr_subtype
== 6)
800 int offset
= fragP
->fr_fix
;
801 fragP
->fr_literal
[offset
] = 0xcd;
802 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
803 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
807 else if (fragP
->fr_subtype
== 7)
809 int offset
= fragP
->fr_fix
;
810 fragP
->fr_literal
[offset
] = 0xdd;
811 fragP
->fr_literal
[offset
+ 5] = fragP
->fr_literal
[offset
+ 3];
812 fragP
->fr_literal
[offset
+ 6] = fragP
->fr_literal
[offset
+ 4];
814 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
815 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
819 else if (fragP
->fr_subtype
== 8)
821 int offset
= fragP
->fr_fix
;
822 fragP
->fr_literal
[offset
] = 0xfa;
823 fragP
->fr_literal
[offset
+ 1] = 0xff;
824 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
825 fragP
->fr_offset
+ 2, 1, BFD_RELOC_16_PCREL
);
829 else if (fragP
->fr_subtype
== 9)
831 int offset
= fragP
->fr_fix
;
832 fragP
->fr_literal
[offset
] = 0xfc;
833 fragP
->fr_literal
[offset
+ 1] = 0xff;
835 fix_new (fragP
, fragP
->fr_fix
+ 2, 4, fragP
->fr_symbol
,
836 fragP
->fr_offset
+ 2, 1, BFD_RELOC_32_PCREL
);
840 else if (fragP
->fr_subtype
== 10)
842 fragP
->fr_literal
[fragP
->fr_fix
] = 0xca;
843 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
844 fragP
->fr_offset
+ 1, 1, BFD_RELOC_8_PCREL
);
848 else if (fragP
->fr_subtype
== 11)
850 int offset
= fragP
->fr_fix
;
851 fragP
->fr_literal
[offset
] = 0xcc;
853 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
854 fragP
->fr_offset
+ 1, 1, BFD_RELOC_16_PCREL
);
858 else if (fragP
->fr_subtype
== 12)
860 int offset
= fragP
->fr_fix
;
861 fragP
->fr_literal
[offset
] = 0xdc;
863 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
864 fragP
->fr_offset
+ 1, 1, BFD_RELOC_32_PCREL
);
873 md_section_align (seg
, addr
)
877 int align
= bfd_get_section_alignment (stdoutput
, seg
);
878 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
884 char *prev_name
= "";
885 register const struct mn10300_opcode
*op
;
887 mn10300_hash
= hash_new ();
889 /* Insert unique names into hash table. The MN10300 instruction set
890 has many identical opcode names that have different opcodes based
891 on the operands. This hash table then provides a quick index to
892 the first opcode with a particular name in the opcode table. */
894 op
= mn10300_opcodes
;
897 if (strcmp (prev_name
, op
->name
))
899 prev_name
= (char *) op
->name
;
900 hash_insert (mn10300_hash
, op
->name
, (char *) op
);
905 /* Set the default machine type. */
906 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, MN103
))
907 as_warn (_("could not set architecture and machine"));
909 current_machine
= MN103
;
917 struct mn10300_opcode
*opcode
;
918 struct mn10300_opcode
*next_opcode
;
919 const unsigned char *opindex_ptr
;
920 int next_opindex
, relaxable
;
921 unsigned long insn
, extension
, size
= 0;
926 /* Get the opcode. */
927 for (s
= str
; *s
!= '\0' && !ISSPACE (*s
); s
++)
932 /* Find the first opcode with the proper name. */
933 opcode
= (struct mn10300_opcode
*) hash_find (mn10300_hash
, str
);
936 as_bad (_("Unrecognized opcode: `%s'"), str
);
941 while (ISSPACE (*str
))
944 input_line_pointer
= str
;
953 errmsg
= _("Invalid opcode/operands");
955 /* Reset the array of register operands. */
956 memset (mn10300_reg_operands
, -1, sizeof (mn10300_reg_operands
));
962 insn
= opcode
->opcode
;
965 /* If the instruction is not available on the current machine
966 then it can not possibly match. */
968 && !(opcode
->machine
== AM33
&& HAVE_AM33
)
969 && !(opcode
->machine
== AM30
&& HAVE_AM30
))
972 for (op_idx
= 1, opindex_ptr
= opcode
->operands
;
974 opindex_ptr
++, op_idx
++)
976 const struct mn10300_operand
*operand
;
979 if (next_opindex
== 0)
981 operand
= &mn10300_operands
[*opindex_ptr
];
985 operand
= &mn10300_operands
[next_opindex
];
989 while (*str
== ' ' || *str
== ',')
992 if (operand
->flags
& MN10300_OPERAND_RELAX
)
995 /* Gather the operand. */
996 hold
= input_line_pointer
;
997 input_line_pointer
= str
;
999 if (operand
->flags
& MN10300_OPERAND_PAREN
)
1001 if (*input_line_pointer
!= ')' && *input_line_pointer
!= '(')
1003 input_line_pointer
= hold
;
1007 input_line_pointer
++;
1010 /* See if we can match the operands. */
1011 else if (operand
->flags
& MN10300_OPERAND_DREG
)
1013 if (!data_register_name (&ex
))
1015 input_line_pointer
= hold
;
1020 else if (operand
->flags
& MN10300_OPERAND_AREG
)
1022 if (!address_register_name (&ex
))
1024 input_line_pointer
= hold
;
1029 else if (operand
->flags
& MN10300_OPERAND_SP
)
1031 char *start
= input_line_pointer
;
1032 char c
= get_symbol_end ();
1034 if (strcasecmp (start
, "sp") != 0)
1036 *input_line_pointer
= c
;
1037 input_line_pointer
= hold
;
1041 *input_line_pointer
= c
;
1044 else if (operand
->flags
& MN10300_OPERAND_RREG
)
1046 if (!r_register_name (&ex
))
1048 input_line_pointer
= hold
;
1053 else if (operand
->flags
& MN10300_OPERAND_XRREG
)
1055 if (!xr_register_name (&ex
))
1057 input_line_pointer
= hold
;
1062 else if (operand
->flags
& MN10300_OPERAND_USP
)
1064 char *start
= input_line_pointer
;
1065 char c
= get_symbol_end ();
1067 if (strcasecmp (start
, "usp") != 0)
1069 *input_line_pointer
= c
;
1070 input_line_pointer
= hold
;
1074 *input_line_pointer
= c
;
1077 else if (operand
->flags
& MN10300_OPERAND_SSP
)
1079 char *start
= input_line_pointer
;
1080 char c
= get_symbol_end ();
1082 if (strcasecmp (start
, "ssp") != 0)
1084 *input_line_pointer
= c
;
1085 input_line_pointer
= hold
;
1089 *input_line_pointer
= c
;
1092 else if (operand
->flags
& MN10300_OPERAND_MSP
)
1094 char *start
= input_line_pointer
;
1095 char c
= get_symbol_end ();
1097 if (strcasecmp (start
, "msp") != 0)
1099 *input_line_pointer
= c
;
1100 input_line_pointer
= hold
;
1104 *input_line_pointer
= c
;
1107 else if (operand
->flags
& MN10300_OPERAND_PC
)
1109 char *start
= input_line_pointer
;
1110 char c
= get_symbol_end ();
1112 if (strcasecmp (start
, "pc") != 0)
1114 *input_line_pointer
= c
;
1115 input_line_pointer
= hold
;
1119 *input_line_pointer
= c
;
1122 else if (operand
->flags
& MN10300_OPERAND_EPSW
)
1124 char *start
= input_line_pointer
;
1125 char c
= get_symbol_end ();
1127 if (strcasecmp (start
, "epsw") != 0)
1129 *input_line_pointer
= c
;
1130 input_line_pointer
= hold
;
1134 *input_line_pointer
= c
;
1137 else if (operand
->flags
& MN10300_OPERAND_PLUS
)
1139 if (*input_line_pointer
!= '+')
1141 input_line_pointer
= hold
;
1145 input_line_pointer
++;
1148 else if (operand
->flags
& MN10300_OPERAND_PSW
)
1150 char *start
= input_line_pointer
;
1151 char c
= get_symbol_end ();
1153 if (strcasecmp (start
, "psw") != 0)
1155 *input_line_pointer
= c
;
1156 input_line_pointer
= hold
;
1160 *input_line_pointer
= c
;
1163 else if (operand
->flags
& MN10300_OPERAND_MDR
)
1165 char *start
= input_line_pointer
;
1166 char c
= get_symbol_end ();
1168 if (strcasecmp (start
, "mdr") != 0)
1170 *input_line_pointer
= c
;
1171 input_line_pointer
= hold
;
1175 *input_line_pointer
= c
;
1178 else if (operand
->flags
& MN10300_OPERAND_REG_LIST
)
1180 unsigned int value
= 0;
1181 if (*input_line_pointer
!= '[')
1183 input_line_pointer
= hold
;
1189 input_line_pointer
++;
1191 /* We used to reject a null register list here; however,
1192 we accept it now so the compiler can emit "call"
1193 instructions for all calls to named functions.
1195 The linker can then fill in the appropriate bits for the
1196 register list and stack size or change the instruction
1197 into a "calls" if using "call" is not profitable. */
1198 while (*input_line_pointer
!= ']')
1203 if (*input_line_pointer
== ',')
1204 input_line_pointer
++;
1206 start
= input_line_pointer
;
1207 c
= get_symbol_end ();
1209 if (strcasecmp (start
, "d2") == 0)
1212 *input_line_pointer
= c
;
1214 else if (strcasecmp (start
, "d3") == 0)
1217 *input_line_pointer
= c
;
1219 else if (strcasecmp (start
, "a2") == 0)
1222 *input_line_pointer
= c
;
1224 else if (strcasecmp (start
, "a3") == 0)
1227 *input_line_pointer
= c
;
1229 else if (strcasecmp (start
, "other") == 0)
1232 *input_line_pointer
= c
;
1235 && strcasecmp (start
, "exreg0") == 0)
1238 *input_line_pointer
= c
;
1241 && strcasecmp (start
, "exreg1") == 0)
1244 *input_line_pointer
= c
;
1247 && strcasecmp (start
, "exother") == 0)
1250 *input_line_pointer
= c
;
1253 && strcasecmp (start
, "all") == 0)
1256 *input_line_pointer
= c
;
1260 input_line_pointer
= hold
;
1265 input_line_pointer
++;
1266 mn10300_insert_operand (&insn
, &extension
, operand
,
1267 value
, (char *) NULL
, 0, 0);
1271 else if (data_register_name (&ex
))
1273 input_line_pointer
= hold
;
1277 else if (address_register_name (&ex
))
1279 input_line_pointer
= hold
;
1283 else if (other_register_name (&ex
))
1285 input_line_pointer
= hold
;
1289 else if (HAVE_AM33
&& r_register_name (&ex
))
1291 input_line_pointer
= hold
;
1295 else if (HAVE_AM33
&& xr_register_name (&ex
))
1297 input_line_pointer
= hold
;
1301 else if (*str
== ')' || *str
== '(')
1303 input_line_pointer
= hold
;
1315 errmsg
= _("illegal operand");
1318 errmsg
= _("missing operand");
1324 mask
= MN10300_OPERAND_DREG
| MN10300_OPERAND_AREG
;
1326 mask
|= MN10300_OPERAND_RREG
| MN10300_OPERAND_XRREG
;
1327 if ((operand
->flags
& mask
) == 0)
1329 input_line_pointer
= hold
;
1334 if (opcode
->format
== FMT_D1
|| opcode
->format
== FMT_S1
)
1336 else if (opcode
->format
== FMT_D2
1337 || opcode
->format
== FMT_D4
1338 || opcode
->format
== FMT_S2
1339 || opcode
->format
== FMT_S4
1340 || opcode
->format
== FMT_S6
1341 || opcode
->format
== FMT_D5
)
1343 else if (opcode
->format
== FMT_D7
)
1345 else if (opcode
->format
== FMT_D8
|| opcode
->format
== FMT_D9
)
1350 mn10300_insert_operand (&insn
, &extension
, operand
,
1351 ex
.X_add_number
, (char *) NULL
,
1354 /* And note the register number in the register array. */
1355 mn10300_reg_operands
[op_idx
- 1] = ex
.X_add_number
;
1360 /* If this operand can be promoted, and it doesn't
1361 fit into the allocated bitfield for this insn,
1362 then promote it (ie this opcode does not match). */
1364 & (MN10300_OPERAND_PROMOTE
| MN10300_OPERAND_RELAX
)
1365 && !check_operand (insn
, operand
, ex
.X_add_number
))
1367 input_line_pointer
= hold
;
1372 mn10300_insert_operand (&insn
, &extension
, operand
,
1373 ex
.X_add_number
, (char *) NULL
,
1378 /* If this operand can be promoted, then this opcode didn't
1379 match since we can't know if it needed promotion! */
1380 if (operand
->flags
& MN10300_OPERAND_PROMOTE
)
1382 input_line_pointer
= hold
;
1387 /* We need to generate a fixup for this expression. */
1388 if (fc
>= MAX_INSN_FIXUPS
)
1389 as_fatal (_("too many fixups"));
1390 fixups
[fc
].exp
= ex
;
1391 fixups
[fc
].opindex
= *opindex_ptr
;
1392 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
1398 str
= input_line_pointer
;
1399 input_line_pointer
= hold
;
1401 while (*str
== ' ' || *str
== ',')
1406 /* Make sure we used all the operands! */
1410 /* If this instruction has registers that must not match, verify
1411 that they do indeed not match. */
1412 if (opcode
->no_match_operands
)
1416 /* Look at each operand to see if it's marked. */
1417 for (i
= 0; i
< MN10300_MAX_OPERANDS
; i
++)
1419 if ((1 << i
) & opcode
->no_match_operands
)
1423 /* operand I is marked. Check that it does not match any
1424 operands > I which are marked. */
1425 for (j
= i
+ 1; j
< MN10300_MAX_OPERANDS
; j
++)
1427 if (((1 << j
) & opcode
->no_match_operands
)
1428 && mn10300_reg_operands
[i
] == mn10300_reg_operands
[j
])
1430 errmsg
= _("Invalid register specification.");
1442 next_opcode
= opcode
+ 1;
1443 if (!strcmp (next_opcode
->name
, opcode
->name
))
1445 opcode
= next_opcode
;
1449 as_bad ("%s", errmsg
);
1455 while (ISSPACE (*str
))
1459 as_bad (_("junk at end of line: `%s'"), str
);
1461 input_line_pointer
= str
;
1463 /* Determine the size of the instruction. */
1464 if (opcode
->format
== FMT_S0
)
1467 if (opcode
->format
== FMT_S1
|| opcode
->format
== FMT_D0
)
1470 if (opcode
->format
== FMT_S2
|| opcode
->format
== FMT_D1
)
1473 if (opcode
->format
== FMT_D6
)
1476 if (opcode
->format
== FMT_D7
|| opcode
->format
== FMT_D10
)
1479 if (opcode
->format
== FMT_D8
)
1482 if (opcode
->format
== FMT_D9
)
1485 if (opcode
->format
== FMT_S4
)
1488 if (opcode
->format
== FMT_S6
|| opcode
->format
== FMT_D5
)
1491 if (opcode
->format
== FMT_D2
)
1494 if (opcode
->format
== FMT_D4
)
1497 if (relaxable
&& fc
> 0)
1501 /* We want to anchor the line info to the previous frag (if
1502 there isn't one, create it), so that, when the insn is
1503 resized, we still get the right address for the beginning of
1506 dwarf2_emit_insn (0);
1511 /* Handle bra specially. Basically treat it like jmp so
1512 that we automatically handle 8, 16 and 32 bit offsets
1513 correctly as well as jumps to an undefined address.
1515 It is also important to not treat it like other bCC
1516 instructions since the long forms of bra is different
1517 from other bCC instructions. */
1518 if (opcode
->opcode
== 0xca00)
1530 else if (size
== 3 && opcode
->opcode
== 0xcc0000)
1532 /* bCC (uncommon cases) */
1536 f
= frag_var (rs_machine_dependent
, 8, 8 - size
, type
,
1537 fixups
[0].exp
.X_add_symbol
,
1538 fixups
[0].exp
.X_add_number
,
1539 (char *)fixups
[0].opindex
);
1541 /* This is pretty hokey. We basically just care about the
1542 opcode, so we have to write out the first word big endian.
1544 The exception is "call", which has two operands that we
1547 The first operand (the register list) happens to be in the
1548 first instruction word, and will be in the right place if
1549 we output the first word in big endian mode.
1551 The second operand (stack size) is in the extension word,
1552 and we want it to appear as the first character in the extension
1553 word (as it appears in memory). Luckily, writing the extension
1554 word in big endian format will do what we want. */
1555 number_to_chars_bigendian (f
, insn
, size
> 4 ? 4 : size
);
1558 number_to_chars_bigendian (f
+ 4, extension
, 4);
1559 number_to_chars_bigendian (f
+ 8, 0, size
- 8);
1562 number_to_chars_bigendian (f
+ 4, extension
, size
- 4);
1566 /* Allocate space for the instruction. */
1567 f
= frag_more (size
);
1569 /* Fill in bytes for the instruction. Note that opcode fields
1570 are written big-endian, 16 & 32bit immediates are written
1571 little endian. Egad. */
1572 if (opcode
->format
== FMT_S0
1573 || opcode
->format
== FMT_S1
1574 || opcode
->format
== FMT_D0
1575 || opcode
->format
== FMT_D6
1576 || opcode
->format
== FMT_D7
1577 || opcode
->format
== FMT_D10
1578 || opcode
->format
== FMT_D1
)
1580 number_to_chars_bigendian (f
, insn
, size
);
1582 else if (opcode
->format
== FMT_S2
1583 && opcode
->opcode
!= 0xdf0000
1584 && opcode
->opcode
!= 0xde0000)
1586 /* A format S2 instruction that is _not_ "ret" and "retf". */
1587 number_to_chars_bigendian (f
, (insn
>> 16) & 0xff, 1);
1588 number_to_chars_littleendian (f
+ 1, insn
& 0xffff, 2);
1590 else if (opcode
->format
== FMT_S2
)
1592 /* This must be a ret or retf, which is written entirely in
1593 big-endian format. */
1594 number_to_chars_bigendian (f
, insn
, 3);
1596 else if (opcode
->format
== FMT_S4
1597 && opcode
->opcode
!= 0xdc000000)
1599 /* This must be a format S4 "call" instruction. What a pain. */
1600 unsigned long temp
= (insn
>> 8) & 0xffff;
1601 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
1602 number_to_chars_littleendian (f
+ 1, temp
, 2);
1603 number_to_chars_bigendian (f
+ 3, insn
& 0xff, 1);
1604 number_to_chars_bigendian (f
+ 4, extension
& 0xff, 1);
1606 else if (opcode
->format
== FMT_S4
)
1608 /* This must be a format S4 "jmp" instruction. */
1609 unsigned long temp
= ((insn
& 0xffffff) << 8) | (extension
& 0xff);
1610 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
1611 number_to_chars_littleendian (f
+ 1, temp
, 4);
1613 else if (opcode
->format
== FMT_S6
)
1615 unsigned long temp
= ((insn
& 0xffffff) << 8)
1616 | ((extension
>> 16) & 0xff);
1617 number_to_chars_bigendian (f
, (insn
>> 24) & 0xff, 1);
1618 number_to_chars_littleendian (f
+ 1, temp
, 4);
1619 number_to_chars_bigendian (f
+ 5, (extension
>> 8) & 0xff, 1);
1620 number_to_chars_bigendian (f
+ 6, extension
& 0xff, 1);
1622 else if (opcode
->format
== FMT_D2
1623 && opcode
->opcode
!= 0xfaf80000
1624 && opcode
->opcode
!= 0xfaf00000
1625 && opcode
->opcode
!= 0xfaf40000)
1627 /* A format D2 instruction where the 16bit immediate is
1628 really a single 16bit value, not two 8bit values. */
1629 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
1630 number_to_chars_littleendian (f
+ 2, insn
& 0xffff, 2);
1632 else if (opcode
->format
== FMT_D2
)
1634 /* A format D2 instruction where the 16bit immediate
1635 is really two 8bit immediates. */
1636 number_to_chars_bigendian (f
, insn
, 4);
1638 else if (opcode
->format
== FMT_D4
)
1640 unsigned long temp
= ((insn
& 0xffff) << 16) | (extension
& 0xffff);
1642 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
1643 number_to_chars_littleendian (f
+ 2, temp
, 4);
1645 else if (opcode
->format
== FMT_D5
)
1647 unsigned long temp
= (((insn
& 0xffff) << 16)
1648 | ((extension
>> 8) & 0xffff));
1650 number_to_chars_bigendian (f
, (insn
>> 16) & 0xffff, 2);
1651 number_to_chars_littleendian (f
+ 2, temp
, 4);
1652 number_to_chars_bigendian (f
+ 6, extension
& 0xff, 1);
1654 else if (opcode
->format
== FMT_D8
)
1656 unsigned long temp
= ((insn
& 0xff) << 16) | (extension
& 0xffff);
1658 number_to_chars_bigendian (f
, (insn
>> 8) & 0xffffff, 3);
1659 number_to_chars_bigendian (f
+ 3, (temp
& 0xff), 1);
1660 number_to_chars_littleendian (f
+ 4, temp
>> 8, 2);
1662 else if (opcode
->format
== FMT_D9
)
1664 unsigned long temp
= ((insn
& 0xff) << 24) | (extension
& 0xffffff);
1666 number_to_chars_bigendian (f
, (insn
>> 8) & 0xffffff, 3);
1667 number_to_chars_littleendian (f
+ 3, temp
, 4);
1670 /* Create any fixups. */
1671 for (i
= 0; i
< fc
; i
++)
1673 const struct mn10300_operand
*operand
;
1675 operand
= &mn10300_operands
[fixups
[i
].opindex
];
1676 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
1678 reloc_howto_type
*reloc_howto
;
1683 reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
1689 size
= bfd_get_reloc_size (reloc_howto
);
1691 if (size
< 1 || size
> 4)
1695 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
1696 size
, &fixups
[i
].exp
,
1697 reloc_howto
->pc_relative
,
1702 int reloc
, pcrel
, reloc_size
, offset
;
1705 reloc
= BFD_RELOC_NONE
;
1706 /* How big is the reloc? Remember SPLIT relocs are
1707 implicitly 32bits. */
1708 if ((operand
->flags
& MN10300_OPERAND_SPLIT
) != 0)
1710 else if ((operand
->flags
& MN10300_OPERAND_24BIT
) != 0)
1713 reloc_size
= operand
->bits
;
1715 /* Is the reloc pc-relative? */
1716 pcrel
= (operand
->flags
& MN10300_OPERAND_PCREL
) != 0;
1718 offset
= size
- (reloc_size
+ operand
->shift
) / 8;
1720 /* Choose a proper BFD relocation type. */
1723 if (reloc_size
== 32)
1724 reloc
= BFD_RELOC_32_PCREL
;
1725 else if (reloc_size
== 16)
1726 reloc
= BFD_RELOC_16_PCREL
;
1727 else if (reloc_size
== 8)
1728 reloc
= BFD_RELOC_8_PCREL
;
1734 if (reloc_size
== 32)
1735 reloc
= BFD_RELOC_32
;
1736 else if (reloc_size
== 16)
1737 reloc
= BFD_RELOC_16
;
1738 else if (reloc_size
== 8)
1739 reloc
= BFD_RELOC_8
;
1744 /* Convert the size of the reloc into what fix_new_exp wants. */
1745 reloc_size
= reloc_size
/ 8;
1746 if (reloc_size
== 8)
1748 else if (reloc_size
== 16)
1750 else if (reloc_size
== 32)
1753 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
,
1754 reloc_size
, &fixups
[i
].exp
, pcrel
,
1755 ((bfd_reloc_code_real_type
) reloc
));
1758 fixP
->fx_offset
+= offset
;
1762 dwarf2_emit_insn (size
);
1766 /* If while processing a fixup, a reloc really needs to be created
1767 then it is done here. */
1770 tc_gen_reloc (seg
, fixp
)
1771 asection
*seg ATTRIBUTE_UNUSED
;
1775 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1777 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1778 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1780 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1781 _("reloc %d not supported by object file format"),
1782 (int) fixp
->fx_r_type
);
1785 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1787 if (fixp
->fx_addsy
&& fixp
->fx_subsy
)
1789 reloc
->sym_ptr_ptr
= NULL
;
1791 /* If we got a difference between two symbols, and the
1792 subtracted symbol is in the current section, use a
1793 PC-relative relocation. If both symbols are in the same
1794 section, the difference would have already been simplified
1796 if (S_GET_SEGMENT (fixp
->fx_subsy
) == seg
)
1798 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1799 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1800 reloc
->addend
= (reloc
->address
- S_GET_VALUE (fixp
->fx_subsy
)
1803 switch (fixp
->fx_r_type
)
1806 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
1811 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
1812 BFD_RELOC_16_PCREL
);
1816 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
1817 BFD_RELOC_24_PCREL
);
1821 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
,
1822 BFD_RELOC_32_PCREL
);
1826 /* Try to compute the absolute value below. */
1831 if ((S_GET_SEGMENT (fixp
->fx_addsy
) != S_GET_SEGMENT (fixp
->fx_subsy
))
1832 || S_GET_SEGMENT (fixp
->fx_addsy
) == undefined_section
)
1834 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1835 "Difference of symbols in different sections is not supported");
1839 char *fixpos
= fixp
->fx_where
+ fixp
->fx_frag
->fr_literal
;
1841 reloc
->addend
= (S_GET_VALUE (fixp
->fx_addsy
)
1842 - S_GET_VALUE (fixp
->fx_subsy
) + fixp
->fx_offset
);
1844 switch (fixp
->fx_r_type
)
1847 md_number_to_chars (fixpos
, reloc
->addend
, 1);
1851 md_number_to_chars (fixpos
, reloc
->addend
, 2);
1855 md_number_to_chars (fixpos
, reloc
->addend
, 3);
1859 md_number_to_chars (fixpos
, reloc
->addend
, 4);
1863 reloc
->sym_ptr_ptr
= (asymbol
**) &bfd_abs_symbol
;
1868 if (reloc
->sym_ptr_ptr
)
1869 free (reloc
->sym_ptr_ptr
);
1875 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1876 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1877 reloc
->addend
= fixp
->fx_offset
;
1883 md_estimate_size_before_relax (fragp
, seg
)
1887 if (fragp
->fr_subtype
== 6
1888 && (!S_IS_DEFINED (fragp
->fr_symbol
)
1889 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
1890 fragp
->fr_subtype
= 7;
1891 else if (fragp
->fr_subtype
== 8
1892 && (!S_IS_DEFINED (fragp
->fr_symbol
)
1893 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
1894 fragp
->fr_subtype
= 9;
1895 else if (fragp
->fr_subtype
== 10
1896 && (!S_IS_DEFINED (fragp
->fr_symbol
)
1897 || seg
!= S_GET_SEGMENT (fragp
->fr_symbol
)))
1898 fragp
->fr_subtype
= 12;
1900 if (fragp
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
1903 return md_relax_table
[fragp
->fr_subtype
].rlx_length
;
1907 md_pcrel_from (fixp
)
1910 if (fixp
->fx_addsy
!= (symbolS
*) NULL
&& !S_IS_DEFINED (fixp
->fx_addsy
))
1912 /* The symbol is undefined. Let the linker figure it out. */
1915 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1919 md_apply_fix3 (fixP
, valP
, seg
)
1924 char * fixpos
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1926 int value
= (int) * valP
;
1928 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
1930 /* This should never happen. */
1931 if (seg
->flags
& SEC_ALLOC
)
1934 /* The value we are passed in *valuep includes the symbol values.
1935 Since we are using BFD_ASSEMBLER, if we are doing this relocation
1936 the code in write.c is going to call bfd_install_relocation, which
1937 is also going to use the symbol value. That means that if the
1938 reloc is fully resolved we want to use *valuep since
1939 bfd_install_relocation is not being used.
1941 However, if the reloc is not fully resolved we do not want to use
1942 *valuep, and must use fx_offset instead. However, if the reloc
1943 is PC relative, we do want to use *valuep since it includes the
1944 result of md_pcrel_from. */
1945 if (fixP
->fx_addsy
!= (symbolS
*) NULL
&& ! fixP
->fx_pcrel
)
1946 value
= fixP
->fx_offset
;
1948 /* If the fix is relative to a symbol which is not defined, or not
1949 in the same segment as the fix, we cannot resolve it here. */
1950 if (fixP
->fx_addsy
!= NULL
1951 && (! S_IS_DEFINED (fixP
->fx_addsy
)
1952 || (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)))
1958 switch (fixP
->fx_r_type
)
1961 case BFD_RELOC_8_PCREL
:
1966 case BFD_RELOC_16_PCREL
:
1971 case BFD_RELOC_32_PCREL
:
1975 case BFD_RELOC_VTABLE_INHERIT
:
1976 case BFD_RELOC_VTABLE_ENTRY
:
1980 case BFD_RELOC_NONE
:
1982 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1983 _("Bad relocation fixup type (%d)"), fixP
->fx_r_type
);
1986 md_number_to_chars (fixpos
, value
, size
);
1988 /* If a symbol remains, pass the fixup, as a reloc, onto the linker. */
1989 if (fixP
->fx_addsy
== NULL
)
1993 /* Return nonzero if the fixup in FIXP will require a relocation,
1994 even it if appears that the fixup could be completely handled
1998 mn10300_force_relocation (fixp
)
2001 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2002 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2005 /* Do not adjust relocations involving symbols in code sections,
2006 because it breaks linker relaxations. This could be fixed in the
2007 linker, but this fix is simpler, and it pretty much only affects
2008 object size a little bit. */
2009 if ((S_GET_SEGMENT (fixp
->fx_addsy
)->flags
& SEC_CODE
)
2011 && S_GET_SEGMENT (fixp
->fx_addsy
) == S_GET_SEGMENT (fixp
->fx_subsy
))
2017 /* Return zero if the fixup in fixp should be left alone and not
2021 mn10300_fix_adjustable (fixp
)
2024 /* Prevent all adjustments to global symbols. */
2025 if (S_IS_EXTERN (fixp
->fx_addsy
) || S_IS_WEAK (fixp
->fx_addsy
))
2028 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2029 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2032 /* Do not adjust relocations involving symbols in code sections,
2033 because it breaks linker relaxations. This could be fixed in the
2034 linker, but this fix is simpler, and it pretty much only affects
2035 object size a little bit. */
2036 if (S_GET_SEGMENT (fixp
->fx_addsy
)->flags
& SEC_CODE
)
2042 /* Insert an operand value into an instruction. */
2045 mn10300_insert_operand (insnp
, extensionp
, operand
, val
, file
, line
, shift
)
2046 unsigned long *insnp
;
2047 unsigned long *extensionp
;
2048 const struct mn10300_operand
*operand
;
2054 /* No need to check 32bit operands for a bit. Note that
2055 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
2056 if (operand
->bits
!= 32
2057 && (operand
->flags
& MN10300_OPERAND_SPLIT
) == 0)
2063 bits
= operand
->bits
;
2064 if (operand
->flags
& MN10300_OPERAND_24BIT
)
2067 if ((operand
->flags
& MN10300_OPERAND_SIGNED
) != 0)
2069 max
= (1 << (bits
- 1)) - 1;
2070 min
= - (1 << (bits
- 1));
2074 max
= (1 << bits
) - 1;
2080 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
2083 _("operand out of range (%s not between %ld and %ld)");
2086 sprint_value (buf
, test
);
2087 if (file
== (char *) NULL
)
2088 as_warn (err
, buf
, min
, max
);
2090 as_warn_where (file
, line
, err
, buf
, min
, max
);
2094 if ((operand
->flags
& MN10300_OPERAND_SPLIT
) != 0)
2096 *insnp
|= (val
>> (32 - operand
->bits
)) & ((1 << operand
->bits
) - 1);
2097 *extensionp
|= ((val
& ((1 << (32 - operand
->bits
)) - 1))
2100 else if ((operand
->flags
& MN10300_OPERAND_24BIT
) != 0)
2102 *insnp
|= (val
>> (24 - operand
->bits
)) & ((1 << operand
->bits
) - 1);
2103 *extensionp
|= ((val
& ((1 << (24 - operand
->bits
)) - 1))
2106 else if ((operand
->flags
& MN10300_OPERAND_EXTENDED
) == 0)
2108 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2109 << (operand
->shift
+ shift
));
2111 if ((operand
->flags
& MN10300_OPERAND_REPEATED
) != 0)
2112 *insnp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2113 << (operand
->shift
+ shift
+ operand
->bits
));
2117 *extensionp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2118 << (operand
->shift
+ shift
));
2120 if ((operand
->flags
& MN10300_OPERAND_REPEATED
) != 0)
2121 *extensionp
|= (((long) val
& ((1 << operand
->bits
) - 1))
2122 << (operand
->shift
+ shift
+ operand
->bits
));
2126 static unsigned long
2127 check_operand (insn
, operand
, val
)
2128 unsigned long insn ATTRIBUTE_UNUSED
;
2129 const struct mn10300_operand
*operand
;
2132 /* No need to check 32bit operands for a bit. Note that
2133 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
2134 if (operand
->bits
!= 32
2135 && (operand
->flags
& MN10300_OPERAND_SPLIT
) == 0)
2141 bits
= operand
->bits
;
2142 if (operand
->flags
& MN10300_OPERAND_24BIT
)
2145 if ((operand
->flags
& MN10300_OPERAND_SIGNED
) != 0)
2147 max
= (1 << (bits
- 1)) - 1;
2148 min
= - (1 << (bits
- 1));
2152 max
= (1 << bits
) - 1;
2158 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
2167 set_arch_mach (mach
)
2170 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_mn10300
, mach
))
2171 as_warn (_("could not set architecture and machine"));
2173 current_machine
= mach
;