1 /* tc-mn10300.c -- Assembler code for the Matsushita 10300
3 Copyright (C) 1996, 1997, 1998 Free Software Foundation.
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. */
26 #include "opcode/mn10300.h"
28 /* Structure to hold information about predefined registers. */
35 /* Generic assembler global variables which must be defined by all targets. */
37 /* Characters which always start a comment. */
38 const char comment_chars[] = "#";
40 /* Characters which start a comment at the beginning of a line. */
41 const char line_comment_chars[] = ";#";
43 /* Characters which may be used to separate multiple commands on a
45 const char line_separator_chars[] = ";";
47 /* Characters which are used to indicate an exponent in a floating
49 const char EXP_CHARS[] = "eE";
51 /* Characters which mean that a number is a floating point constant,
53 const char FLT_CHARS[] = "dD";
56 const relax_typeS md_relax_table[] = {
59 {0x7fff, -0x8000, 5, 2},
60 {0x7fffffff, -0x80000000, 7, 0},
62 /* bCC relaxing (uncommon cases) */
64 {0x7fff, -0x8000, 6, 5},
65 {0x7fffffff, -0x80000000, 8, 0},
68 {0x7fff, -0x8000, 5, 7},
69 {0x7fffffff, -0x80000000, 7, 0},
72 {0x7fff, -0x8000, 4, 9},
73 {0x7fffffff, -0x80000000, 6, 0},
77 {0x7fff, -0x8000, 3, 12},
78 {0x7fffffff, -0x80000000, 5, 0},
83 static void mn10300_insert_operand PARAMS ((unsigned long *, unsigned long *,
84 const struct mn10300_operand *,
85 offsetT, char *, unsigned,
87 static unsigned long check_operand PARAMS ((unsigned long,
88 const struct mn10300_operand *,
90 static int reg_name_search PARAMS ((const struct reg_name *, int, const char *));
91 static boolean data_register_name PARAMS ((expressionS *expressionP));
92 static boolean address_register_name PARAMS ((expressionS *expressionP));
93 static boolean other_register_name PARAMS ((expressionS *expressionP));
97 #define MAX_INSN_FIXUPS (5)
102 bfd_reloc_code_real_type reloc;
104 struct mn10300_fixup fixups[MAX_INSN_FIXUPS];
107 const char *md_shortopts = "";
108 struct option md_longopts[] = {
109 {NULL, no_argument, NULL, 0}
111 size_t md_longopts_size = sizeof(md_longopts);
113 /* The target specific pseudo-ops which we support. */
114 const pseudo_typeS md_pseudo_table[] =
119 /* Opcode hash table. */
120 static struct hash_control *mn10300_hash;
122 /* This table is sorted. Suitable for searching by a binary search. */
123 static const struct reg_name data_registers[] =
130 #define DATA_REG_NAME_CNT (sizeof(data_registers) / sizeof(struct reg_name))
132 static const struct reg_name address_registers[] =
139 #define ADDRESS_REG_NAME_CNT (sizeof(address_registers) / sizeof(struct reg_name))
141 /* start-sanitize-am33 */
142 static const struct reg_name r_registers[] =
161 #define R_REG_NAME_CNT (sizeof(r_registers) / sizeof(struct reg_name))
163 static const struct reg_name xr_registers[] =
182 #define XR_REG_NAME_CNT (sizeof(xr_registers) / sizeof(struct reg_name))
184 /* end-sanitize-am33 */
186 static const struct reg_name other_registers[] =
192 #define OTHER_REG_NAME_CNT (sizeof(other_registers) / sizeof(struct reg_name))
194 /* reg_name_search does a binary search of the given register table
195 to see if "name" is a valid regiter name. Returns the register
196 number from the array on success, or -1 on failure. */
199 reg_name_search (regs, regcount, name)
200 const struct reg_name *regs;
204 int middle, low, high;
212 middle = (low + high) / 2;
213 cmp = strcasecmp (name, regs[middle].name);
219 return regs[middle].value;
226 /* start-sanitize-am33 */
227 /* Summary of register_name().
229 * in: Input_line_pointer points to 1st char of operand.
231 * out: A expressionS.
232 * The operand may have been a register: in this case, X_op == O_register,
233 * X_add_number is set to the register number, and truth is returned.
234 * Input_line_pointer->(next non-blank) char after operand, or is in
235 * its original state.
238 r_register_name (expressionP)
239 expressionS *expressionP;
246 /* Find the spelling of the operand */
247 start = name = input_line_pointer;
249 c = get_symbol_end ();
250 reg_number = reg_name_search (r_registers, R_REG_NAME_CNT, name);
252 /* look to see if it's in the register table */
255 expressionP->X_op = O_register;
256 expressionP->X_add_number = reg_number;
258 /* make the rest nice */
259 expressionP->X_add_symbol = NULL;
260 expressionP->X_op_symbol = NULL;
261 *input_line_pointer = c; /* put back the delimiting char */
266 /* reset the line as if we had not done anything */
267 *input_line_pointer = c; /* put back the delimiting char */
268 input_line_pointer = start; /* reset input_line pointer */
273 /* Summary of register_name().
275 * in: Input_line_pointer points to 1st char of operand.
277 * out: A expressionS.
278 * The operand may have been a register: in this case, X_op == O_register,
279 * X_add_number is set to the register number, and truth is returned.
280 * Input_line_pointer->(next non-blank) char after operand, or is in
281 * its original state.
284 xr_register_name (expressionP)
285 expressionS *expressionP;
292 /* Find the spelling of the operand */
293 start = name = input_line_pointer;
295 c = get_symbol_end ();
296 reg_number = reg_name_search (xr_registers, XR_REG_NAME_CNT, name);
298 /* look to see if it's in the register table */
301 expressionP->X_op = O_register;
302 expressionP->X_add_number = reg_number;
304 /* make the rest nice */
305 expressionP->X_add_symbol = NULL;
306 expressionP->X_op_symbol = NULL;
307 *input_line_pointer = c; /* put back the delimiting char */
312 /* reset the line as if we had not done anything */
313 *input_line_pointer = c; /* put back the delimiting char */
314 input_line_pointer = start; /* reset input_line pointer */
318 /* end-sanitize-am33 */
320 /* Summary of register_name().
322 * in: Input_line_pointer points to 1st char of operand.
324 * out: A expressionS.
325 * The operand may have been a register: in this case, X_op == O_register,
326 * X_add_number is set to the register number, and truth is returned.
327 * Input_line_pointer->(next non-blank) char after operand, or is in
328 * its original state.
331 data_register_name (expressionP)
332 expressionS *expressionP;
339 /* Find the spelling of the operand */
340 start = name = input_line_pointer;
342 c = get_symbol_end ();
343 reg_number = reg_name_search (data_registers, DATA_REG_NAME_CNT, name);
345 /* look to see if it's in the register table */
348 expressionP->X_op = O_register;
349 expressionP->X_add_number = reg_number;
351 /* make the rest nice */
352 expressionP->X_add_symbol = NULL;
353 expressionP->X_op_symbol = NULL;
354 *input_line_pointer = c; /* put back the delimiting char */
359 /* reset the line as if we had not done anything */
360 *input_line_pointer = c; /* put back the delimiting char */
361 input_line_pointer = start; /* reset input_line pointer */
366 /* Summary of register_name().
368 * in: Input_line_pointer points to 1st char of operand.
370 * out: A expressionS.
371 * The operand may have been a register: in this case, X_op == O_register,
372 * X_add_number is set to the register number, and truth is returned.
373 * Input_line_pointer->(next non-blank) char after operand, or is in
374 * its original state.
377 address_register_name (expressionP)
378 expressionS *expressionP;
385 /* Find the spelling of the operand */
386 start = name = input_line_pointer;
388 c = get_symbol_end ();
389 reg_number = reg_name_search (address_registers, ADDRESS_REG_NAME_CNT, name);
391 /* look to see if it's in the register table */
394 expressionP->X_op = O_register;
395 expressionP->X_add_number = reg_number;
397 /* make the rest nice */
398 expressionP->X_add_symbol = NULL;
399 expressionP->X_op_symbol = NULL;
400 *input_line_pointer = c; /* put back the delimiting char */
405 /* reset the line as if we had not done anything */
406 *input_line_pointer = c; /* put back the delimiting char */
407 input_line_pointer = start; /* reset input_line pointer */
412 /* Summary of register_name().
414 * in: Input_line_pointer points to 1st char of operand.
416 * out: A expressionS.
417 * The operand may have been a register: in this case, X_op == O_register,
418 * X_add_number is set to the register number, and truth is returned.
419 * Input_line_pointer->(next non-blank) char after operand, or is in
420 * its original state.
423 other_register_name (expressionP)
424 expressionS *expressionP;
431 /* Find the spelling of the operand */
432 start = name = input_line_pointer;
434 c = get_symbol_end ();
435 reg_number = reg_name_search (other_registers, OTHER_REG_NAME_CNT, name);
437 /* look to see if it's in the register table */
440 expressionP->X_op = O_register;
441 expressionP->X_add_number = reg_number;
443 /* make the rest nice */
444 expressionP->X_add_symbol = NULL;
445 expressionP->X_op_symbol = NULL;
446 *input_line_pointer = c; /* put back the delimiting char */
451 /* reset the line as if we had not done anything */
452 *input_line_pointer = c; /* put back the delimiting char */
453 input_line_pointer = start; /* reset input_line pointer */
459 md_show_usage (stream)
462 fprintf(stream, _("MN10300 options:\n\
467 md_parse_option (c, arg)
475 md_undefined_symbol (name)
482 md_atof (type, litp, sizep)
488 LITTLENUM_TYPE words[4];
504 return "bad call to md_atof";
507 t = atof_ieee (input_line_pointer, type, words);
509 input_line_pointer = t;
513 for (i = prec - 1; i >= 0; i--)
515 md_number_to_chars (litp, (valueT) words[i], 2);
524 md_convert_frag (abfd, sec, fragP)
529 static unsigned long label_count = 0;
532 subseg_change (sec, 0);
533 if (fragP->fr_subtype == 0)
535 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
536 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
540 else if (fragP->fr_subtype == 1)
542 /* Reverse the condition of the first branch. */
543 int offset = fragP->fr_fix;
544 int opcode = fragP->fr_literal[offset] & 0xff;
581 fragP->fr_literal[offset] = opcode;
583 /* Create a fixup for the reversed conditional branch. */
584 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
585 fix_new (fragP, fragP->fr_fix + 1, 1,
586 symbol_new (buf, sec, 0, fragP->fr_next),
587 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
589 /* Now create the unconditional branch + fixup to the
591 fragP->fr_literal[offset + 2] = 0xcc;
592 fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
593 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
597 else if (fragP->fr_subtype == 2)
599 /* Reverse the condition of the first branch. */
600 int offset = fragP->fr_fix;
601 int opcode = fragP->fr_literal[offset] & 0xff;
638 fragP->fr_literal[offset] = opcode;
640 /* Create a fixup for the reversed conditional branch. */
641 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
642 fix_new (fragP, fragP->fr_fix + 1, 1,
643 symbol_new (buf, sec, 0, fragP->fr_next),
644 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
646 /* Now create the unconditional branch + fixup to the
648 fragP->fr_literal[offset + 2] = 0xdc;
649 fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
650 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
654 else if (fragP->fr_subtype == 3)
656 fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
657 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
661 else if (fragP->fr_subtype == 4)
663 /* Reverse the condition of the first branch. */
664 int offset = fragP->fr_fix;
665 int opcode = fragP->fr_literal[offset + 1] & 0xff;
684 fragP->fr_literal[offset + 1] = opcode;
686 /* Create a fixup for the reversed conditional branch. */
687 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
688 fix_new (fragP, fragP->fr_fix + 2, 1,
689 symbol_new (buf, sec, 0, fragP->fr_next),
690 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
692 /* Now create the unconditional branch + fixup to the
694 fragP->fr_literal[offset + 3] = 0xcc;
695 fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
696 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
700 else if (fragP->fr_subtype == 5)
702 /* Reverse the condition of the first branch. */
703 int offset = fragP->fr_fix;
704 int opcode = fragP->fr_literal[offset + 1] & 0xff;
720 fragP->fr_literal[offset + 1] = opcode;
722 /* Create a fixup for the reversed conditional branch. */
723 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
724 fix_new (fragP, fragP->fr_fix + 2, 1,
725 symbol_new (buf, sec, 0, fragP->fr_next),
726 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
728 /* Now create the unconditional branch + fixup to the
730 fragP->fr_literal[offset + 3] = 0xdc;
731 fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
732 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
736 else if (fragP->fr_subtype == 6)
738 int offset = fragP->fr_fix;
739 fragP->fr_literal[offset] = 0xcd;
740 fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
741 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
745 else if (fragP->fr_subtype == 7)
747 int offset = fragP->fr_fix;
748 fragP->fr_literal[offset] = 0xdd;
749 fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
750 fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
752 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
753 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
757 else if (fragP->fr_subtype == 8)
759 int offset = fragP->fr_fix;
760 fragP->fr_literal[offset] = 0xfa;
761 fragP->fr_literal[offset + 1] = 0xff;
762 fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
763 fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
767 else if (fragP->fr_subtype == 9)
769 int offset = fragP->fr_fix;
770 fragP->fr_literal[offset] = 0xfc;
771 fragP->fr_literal[offset + 1] = 0xff;
773 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
774 fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
778 else if (fragP->fr_subtype == 10)
780 fragP->fr_literal[fragP->fr_fix] = 0xca;
781 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
782 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
786 else if (fragP->fr_subtype == 11)
788 int offset = fragP->fr_fix;
789 fragP->fr_literal[offset] = 0xcc;
791 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
792 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
796 else if (fragP->fr_subtype == 12)
798 int offset = fragP->fr_fix;
799 fragP->fr_literal[offset] = 0xdc;
801 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
802 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
811 md_section_align (seg, addr)
815 int align = bfd_get_section_alignment (stdoutput, seg);
816 return ((addr + (1 << align) - 1) & (-1 << align));
822 char *prev_name = "";
823 register const struct mn10300_opcode *op;
825 mn10300_hash = hash_new();
827 /* Insert unique names into hash table. The MN10300 instruction set
828 has many identical opcode names that have different opcodes based
829 on the operands. This hash table then provides a quick index to
830 the first opcode with a particular name in the opcode table. */
832 op = mn10300_opcodes;
835 if (strcmp (prev_name, op->name))
837 prev_name = (char *) op->name;
838 hash_insert (mn10300_hash, op->name, (char *) op);
843 /* This is both a simplification (we don't have to write md_apply_fix)
844 and support for future optimizations (branch shortening and similar
845 stuff in the linker. */
854 struct mn10300_opcode *opcode;
855 struct mn10300_opcode *next_opcode;
856 const unsigned char *opindex_ptr;
857 int next_opindex, relaxable;
858 unsigned long insn, extension, size = 0;
863 /* Get the opcode. */
864 for (s = str; *s != '\0' && ! isspace (*s); s++)
869 /* find the first opcode with the proper name */
870 opcode = (struct mn10300_opcode *)hash_find (mn10300_hash, str);
873 as_bad (_("Unrecognized opcode: `%s'"), str);
878 while (isspace (*str))
881 input_line_pointer = str;
885 const char *errmsg = NULL;
894 insn = opcode->opcode;
896 for (op_idx = 1, opindex_ptr = opcode->operands;
898 opindex_ptr++, op_idx++)
900 const struct mn10300_operand *operand;
903 if (next_opindex == 0)
905 operand = &mn10300_operands[*opindex_ptr];
909 operand = &mn10300_operands[next_opindex];
915 while (*str == ' ' || *str == ',')
918 if (operand->flags & MN10300_OPERAND_RELAX)
921 /* Gather the operand. */
922 hold = input_line_pointer;
923 input_line_pointer = str;
925 if (operand->flags & MN10300_OPERAND_PAREN)
927 if (*input_line_pointer != ')' && *input_line_pointer != '(')
929 input_line_pointer = hold;
933 input_line_pointer++;
936 /* See if we can match the operands. */
937 else if (operand->flags & MN10300_OPERAND_DREG)
939 if (!data_register_name (&ex))
941 input_line_pointer = hold;
946 else if (operand->flags & MN10300_OPERAND_AREG)
948 if (!address_register_name (&ex))
950 input_line_pointer = hold;
955 else if (operand->flags & MN10300_OPERAND_SP)
957 char *start = input_line_pointer;
958 char c = get_symbol_end ();
960 if (strcasecmp (start, "sp") != 0)
962 *input_line_pointer = c;
963 input_line_pointer = hold;
967 *input_line_pointer = c;
970 /* start-sanitize-am33 */
971 else if (operand->flags & MN10300_OPERAND_RREG)
973 if (!r_register_name (&ex))
975 input_line_pointer = hold;
980 else if (operand->flags & MN10300_OPERAND_XRREG)
982 if (!xr_register_name (&ex))
984 input_line_pointer = hold;
989 else if (operand->flags & MN10300_OPERAND_USP)
991 char *start = input_line_pointer;
992 char c = get_symbol_end ();
994 if (strcasecmp (start, "usp") != 0)
996 *input_line_pointer = c;
997 input_line_pointer = hold;
1001 *input_line_pointer = c;
1004 else if (operand->flags & MN10300_OPERAND_SSP)
1006 char *start = input_line_pointer;
1007 char c = get_symbol_end ();
1009 if (strcasecmp (start, "ssp") != 0)
1011 *input_line_pointer = c;
1012 input_line_pointer = hold;
1016 *input_line_pointer = c;
1019 else if (operand->flags & MN10300_OPERAND_MSP)
1021 char *start = input_line_pointer;
1022 char c = get_symbol_end ();
1024 if (strcasecmp (start, "msp") != 0)
1026 *input_line_pointer = c;
1027 input_line_pointer = hold;
1031 *input_line_pointer = c;
1034 else if (operand->flags & MN10300_OPERAND_PC)
1036 char *start = input_line_pointer;
1037 char c = get_symbol_end ();
1039 if (strcasecmp (start, "pc") != 0)
1041 *input_line_pointer = c;
1042 input_line_pointer = hold;
1046 *input_line_pointer = c;
1049 else if (operand->flags & MN10300_OPERAND_EPSW)
1051 char *start = input_line_pointer;
1052 char c = get_symbol_end ();
1054 if (strcasecmp (start, "epsw") != 0)
1056 *input_line_pointer = c;
1057 input_line_pointer = hold;
1061 *input_line_pointer = c;
1064 else if (operand->flags & MN10300_OPERAND_PLUS)
1066 if (*input_line_pointer != '+')
1068 input_line_pointer = hold;
1072 input_line_pointer++;
1075 /* end-sanitize-am33 */
1076 else if (operand->flags & MN10300_OPERAND_PSW)
1078 char *start = input_line_pointer;
1079 char c = get_symbol_end ();
1081 if (strcasecmp (start, "psw") != 0)
1083 *input_line_pointer = c;
1084 input_line_pointer = hold;
1088 *input_line_pointer = c;
1091 else if (operand->flags & MN10300_OPERAND_MDR)
1093 char *start = input_line_pointer;
1094 char c = get_symbol_end ();
1096 if (strcasecmp (start, "mdr") != 0)
1098 *input_line_pointer = c;
1099 input_line_pointer = hold;
1103 *input_line_pointer = c;
1106 else if (operand->flags & MN10300_OPERAND_REG_LIST)
1108 unsigned int value = 0;
1109 if (*input_line_pointer != '[')
1111 input_line_pointer = hold;
1117 input_line_pointer++;
1119 /* We used to reject a null register list here; however,
1120 we accept it now so the compiler can emit "call" instructions
1121 for all calls to named functions.
1123 The linker can then fill in the appropriate bits for the
1124 register list and stack size or change the instruction
1125 into a "calls" if using "call" is not profitable. */
1126 while (*input_line_pointer != ']')
1131 if (*input_line_pointer == ',')
1132 input_line_pointer++;
1134 start = input_line_pointer;
1135 c = get_symbol_end ();
1137 if (strcasecmp (start, "d2") == 0)
1140 *input_line_pointer = c;
1142 else if (strcasecmp (start, "d3") == 0)
1145 *input_line_pointer = c;
1147 else if (strcasecmp (start, "a2") == 0)
1150 *input_line_pointer = c;
1152 else if (strcasecmp (start, "a3") == 0)
1155 *input_line_pointer = c;
1157 else if (strcasecmp (start, "other") == 0)
1160 *input_line_pointer = c;
1162 /* start-sanitize-am33 */
1163 else if (strcasecmp (start, "exreg0") == 0)
1166 *input_line_pointer = c;
1168 else if (strcasecmp (start, "exreg1") == 0)
1171 *input_line_pointer = c;
1173 else if (strcasecmp (start, "exother") == 0)
1176 *input_line_pointer = c;
1178 else if (strcasecmp (start, "all") == 0)
1181 *input_line_pointer = c;
1183 /* end-sanitize-am33 */
1186 input_line_pointer = hold;
1191 input_line_pointer++;
1192 mn10300_insert_operand (&insn, &extension, operand,
1193 value, (char *) NULL, 0, 0);
1197 else if (data_register_name (&ex))
1199 input_line_pointer = hold;
1203 else if (address_register_name (&ex))
1205 input_line_pointer = hold;
1209 else if (other_register_name (&ex))
1211 input_line_pointer = hold;
1215 else if (*str == ')' || *str == '(')
1217 input_line_pointer = hold;
1229 errmsg = _("illegal operand");
1232 errmsg = _("missing operand");
1238 mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
1239 /* start-sanitize-am33 */
1240 mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
1241 /* end-sanitize-am33 */
1242 if ((operand->flags & mask) == 0)
1244 input_line_pointer = hold;
1249 if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
1251 else if (opcode->format == FMT_D2
1252 || opcode->format == FMT_D4
1253 || opcode->format == FMT_S2
1254 || opcode->format == FMT_S4
1255 || opcode->format == FMT_S6
1256 || opcode->format == FMT_D5)
1258 /* start-sanitize-am33 */
1259 else if (opcode->format == FMT_D7)
1261 /* end-sanitize-am33 */
1265 mn10300_insert_operand (&insn, &extension, operand,
1266 ex.X_add_number, (char *) NULL,
1273 /* If this operand can be promoted, and it doesn't
1274 fit into the allocated bitfield for this insn,
1275 then promote it (ie this opcode does not match). */
1277 & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
1278 && ! check_operand (insn, operand, ex.X_add_number))
1280 input_line_pointer = hold;
1285 mn10300_insert_operand (&insn, &extension, operand,
1286 ex.X_add_number, (char *) NULL,
1291 /* If this operand can be promoted, then this opcode didn't
1292 match since we can't know if it needed promotion! */
1293 if (operand->flags & MN10300_OPERAND_PROMOTE)
1295 input_line_pointer = hold;
1300 /* We need to generate a fixup for this expression. */
1301 if (fc >= MAX_INSN_FIXUPS)
1302 as_fatal (_("too many fixups"));
1303 fixups[fc].exp = ex;
1304 fixups[fc].opindex = *opindex_ptr;
1305 fixups[fc].reloc = BFD_RELOC_UNUSED;
1311 str = input_line_pointer;
1312 input_line_pointer = hold;
1314 while (*str == ' ' || *str == ',')
1319 /* Make sure we used all the operands! */
1326 next_opcode = opcode + 1;
1327 if (!strcmp(next_opcode->name, opcode->name))
1329 opcode = next_opcode;
1333 as_bad ("%s", errmsg);
1339 while (isspace (*str))
1343 as_bad (_("junk at end of line: `%s'"), str);
1345 input_line_pointer = str;
1347 /* Determine the size of the instruction. */
1348 if (opcode->format == FMT_S0)
1351 if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
1354 if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
1357 /* start-sanitize-am33 */
1358 if (opcode->format == FMT_D6)
1361 if (opcode->format == FMT_D7)
1363 /* end-sanitize-am33 */
1365 if (opcode->format == FMT_S4)
1368 if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
1371 if (opcode->format == FMT_D2)
1374 if (opcode->format == FMT_D4)
1377 if (relaxable && fc > 0)
1384 /* Handle bra specially. Basically treat it like jmp so
1385 that we automatically handle 8, 16 and 32 bit offsets
1386 correctly as well as jumps to an undefined address.
1388 It is also important to not treat it like other bCC
1389 instructions since the long forms of bra is different
1390 from other bCC instructions. */
1391 if (opcode->opcode == 0xca00)
1403 else if (size == 3 && opcode->opcode == 0xcc0000)
1405 /* bCC (uncommon cases) */
1409 f = frag_var (rs_machine_dependent, 8, 8 - size, type,
1410 fixups[0].exp.X_add_symbol,
1411 fixups[0].exp.X_add_number,
1412 (char *)fixups[0].opindex);
1414 /* This is pretty hokey. We basically just care about the
1415 opcode, so we have to write out the first word big endian.
1417 The exception is "call", which has two operands that we
1420 The first operand (the register list) happens to be in the
1421 first instruction word, and will be in the right place if
1422 we output the first word in big endian mode.
1424 The second operand (stack size) is in the extension word,
1425 and we want it to appear as the first character in the extension
1426 word (as it appears in memory). Luckily, writing the extension
1427 word in big endian format will do what we want. */
1428 number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
1431 number_to_chars_bigendian (f + 4, extension, 4);
1432 number_to_chars_bigendian (f + 8, 0, size - 8);
1435 number_to_chars_bigendian (f + 4, extension, size - 4);
1439 /* Allocate space for the instruction. */
1440 f = frag_more (size);
1442 /* Fill in bytes for the instruction. Note that opcode fields
1443 are written big-endian, 16 & 32bit immediates are written
1444 little endian. Egad. */
1445 if (opcode->format == FMT_S0
1446 || opcode->format == FMT_S1
1447 || opcode->format == FMT_D0
1448 /* start-sanitize-am33 */
1449 || opcode->format == FMT_D6
1450 || opcode->format == FMT_D7
1451 /* end-sanitize-am33 */
1452 || opcode->format == FMT_D1)
1454 number_to_chars_bigendian (f, insn, size);
1456 else if (opcode->format == FMT_S2
1457 && opcode->opcode != 0xdf0000
1458 && opcode->opcode != 0xde0000)
1460 /* A format S2 instruction that is _not_ "ret" and "retf". */
1461 number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
1462 number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
1464 else if (opcode->format == FMT_S2)
1466 /* This must be a ret or retf, which is written entirely in
1467 big-endian format. */
1468 number_to_chars_bigendian (f, insn, 3);
1470 else if (opcode->format == FMT_S4
1471 && opcode->opcode != 0xdc000000)
1473 /* This must be a format S4 "call" instruction. What a pain. */
1474 unsigned long temp = (insn >> 8) & 0xffff;
1475 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1476 number_to_chars_littleendian (f + 1, temp, 2);
1477 number_to_chars_bigendian (f + 3, insn & 0xff, 1);
1478 number_to_chars_bigendian (f + 4, extension & 0xff, 1);
1480 else if (opcode->format == FMT_S4)
1482 /* This must be a format S4 "jmp" instruction. */
1483 unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
1484 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1485 number_to_chars_littleendian (f + 1, temp, 4);
1487 else if (opcode->format == FMT_S6)
1489 unsigned long temp = ((insn & 0xffffff) << 8)
1490 | ((extension >> 16) & 0xff);
1491 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1492 number_to_chars_littleendian (f + 1, temp, 4);
1493 number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
1494 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1496 else if (opcode->format == FMT_D2
1497 && opcode->opcode != 0xfaf80000
1498 && opcode->opcode != 0xfaf00000
1499 && opcode->opcode != 0xfaf40000)
1501 /* A format D2 instruction where the 16bit immediate is
1502 really a single 16bit value, not two 8bit values. */
1503 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1504 number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
1506 else if (opcode->format == FMT_D2)
1508 /* A format D2 instruction where the 16bit immediate
1509 is really two 8bit immediates. */
1510 number_to_chars_bigendian (f, insn, 4);
1512 else if (opcode->format == FMT_D4)
1514 unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
1515 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1516 number_to_chars_littleendian (f + 2, temp, 4);
1518 else if (opcode->format == FMT_D5)
1520 unsigned long temp = ((insn & 0xffff) << 16)
1521 | ((extension >> 8) & 0xffff);
1522 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1523 number_to_chars_littleendian (f + 2, temp, 4);
1524 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1527 /* Create any fixups. */
1528 for (i = 0; i < fc; i++)
1530 const struct mn10300_operand *operand;
1532 operand = &mn10300_operands[fixups[i].opindex];
1533 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1535 reloc_howto_type *reloc_howto;
1540 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1545 size = bfd_get_reloc_size (reloc_howto);
1547 if (size < 1 || size > 4)
1551 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1552 size, &fixups[i].exp,
1553 reloc_howto->pc_relative,
1558 int reloc, pcrel, reloc_size, offset;
1561 reloc = BFD_RELOC_NONE;
1562 /* How big is the reloc? Remember SPLIT relocs are
1563 implicitly 32bits. */
1564 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1567 reloc_size = operand->bits;
1569 /* Is the reloc pc-relative? */
1570 pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
1572 /* Gross. This disgusting hack is to make sure we
1573 get the right offset for the 16/32 bit reloc in
1574 "call" instructions. Basically they're a pain
1575 because the reloc isn't at the end of the instruction. */
1576 if ((size == 5 || size == 7)
1577 && (((insn >> 24) & 0xff) == 0xcd
1578 || ((insn >> 24) & 0xff) == 0xdd))
1581 /* Similarly for certain bit instructions which don't
1582 hav their 32bit reloc at the tail of the instruction. */
1584 && (((insn >> 16) & 0xffff) == 0xfe00
1585 || ((insn >> 16) & 0xffff) == 0xfe01
1586 || ((insn >> 16) & 0xffff) == 0xfe02))
1589 offset = size - reloc_size / 8;
1591 /* Choose a proper BFD relocation type. */
1594 if (reloc_size == 32)
1595 reloc = BFD_RELOC_32_PCREL;
1596 else if (reloc_size == 16)
1597 reloc = BFD_RELOC_16_PCREL;
1598 else if (reloc_size == 8)
1599 reloc = BFD_RELOC_8_PCREL;
1605 if (reloc_size == 32)
1606 reloc = BFD_RELOC_32;
1607 else if (reloc_size == 16)
1608 reloc = BFD_RELOC_16;
1609 else if (reloc_size == 8)
1610 reloc = BFD_RELOC_8;
1615 /* Convert the size of the reloc into what fix_new_exp wants. */
1616 reloc_size = reloc_size / 8;
1617 if (reloc_size == 8)
1619 else if (reloc_size == 16)
1621 else if (reloc_size == 32)
1624 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1625 reloc_size, &fixups[i].exp, pcrel,
1626 ((bfd_reloc_code_real_type) reloc));
1629 fixP->fx_offset += offset;
1636 /* if while processing a fixup, a reloc really needs to be created */
1637 /* then it is done here */
1640 tc_gen_reloc (seg, fixp)
1645 reloc = (arelent *) xmalloc (sizeof (arelent));
1647 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1648 if (reloc->howto == (reloc_howto_type *) NULL)
1650 as_bad_where (fixp->fx_file, fixp->fx_line,
1651 _("reloc %d not supported by object file format"),
1652 (int)fixp->fx_r_type);
1655 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1657 if (fixp->fx_addsy && fixp->fx_subsy)
1660 if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
1661 || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
1663 as_bad_where (fixp->fx_file, fixp->fx_line,
1664 "Difference of symbols in different sections is not supported");
1668 reloc->sym_ptr_ptr = &bfd_abs_symbol;
1669 reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
1670 - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
1674 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
1675 reloc->addend = fixp->fx_offset;
1681 md_estimate_size_before_relax (fragp, seg)
1685 if (fragp->fr_subtype == 0)
1687 if (fragp->fr_subtype == 3)
1689 if (fragp->fr_subtype == 6)
1691 if (!S_IS_DEFINED (fragp->fr_symbol)
1692 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1694 fragp->fr_subtype = 7;
1700 if (fragp->fr_subtype == 8)
1702 if (!S_IS_DEFINED (fragp->fr_symbol)
1703 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1705 fragp->fr_subtype = 9;
1711 if (fragp->fr_subtype == 10)
1713 if (!S_IS_DEFINED (fragp->fr_symbol)
1714 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1716 fragp->fr_subtype = 12;
1725 md_pcrel_from (fixp)
1728 return fixp->fx_frag->fr_address;
1730 if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy))
1732 /* The symbol is undefined. Let the linker figure it out. */
1735 return fixp->fx_frag->fr_address + fixp->fx_where;
1740 md_apply_fix3 (fixp, valuep, seg)
1745 /* We shouldn't ever get here because linkrelax is nonzero. */
1751 /* Insert an operand value into an instruction. */
1754 mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift)
1755 unsigned long *insnp;
1756 unsigned long *extensionp;
1757 const struct mn10300_operand *operand;
1763 /* No need to check 32bit operands for a bit. Note that
1764 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1765 if (operand->bits != 32
1766 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1771 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1773 max = (1 << (operand->bits - 1)) - 1;
1774 min = - (1 << (operand->bits - 1));
1778 max = (1 << operand->bits) - 1;
1785 if (test < (offsetT) min || test > (offsetT) max)
1788 _("operand out of range (%s not between %ld and %ld)");
1791 sprint_value (buf, test);
1792 if (file == (char *) NULL)
1793 as_warn (err, buf, min, max);
1795 as_warn_where (file, line, err, buf, min, max);
1799 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1801 *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
1802 *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
1805 else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
1807 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1808 << (operand->shift + shift));
1810 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1811 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1812 << (operand->shift + shift + operand->bits));
1816 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1817 << (operand->shift + shift));
1819 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1820 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1821 << (operand->shift + shift + operand->bits));
1825 static unsigned long
1826 check_operand (insn, operand, val)
1828 const struct mn10300_operand *operand;
1831 /* No need to check 32bit operands for a bit. Note that
1832 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1833 if (operand->bits != 32
1834 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1839 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1841 max = (1 << (operand->bits - 1)) - 1;
1842 min = - (1 << (operand->bits - 1));
1846 max = (1 << operand->bits) - 1;
1853 if (test < (offsetT) min || test > (offsetT) max)