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 else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
1263 /* end-sanitize-am33 */
1267 mn10300_insert_operand (&insn, &extension, operand,
1268 ex.X_add_number, (char *) NULL,
1275 /* If this operand can be promoted, and it doesn't
1276 fit into the allocated bitfield for this insn,
1277 then promote it (ie this opcode does not match). */
1279 & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
1280 && ! check_operand (insn, operand, ex.X_add_number))
1282 input_line_pointer = hold;
1287 mn10300_insert_operand (&insn, &extension, operand,
1288 ex.X_add_number, (char *) NULL,
1293 /* If this operand can be promoted, then this opcode didn't
1294 match since we can't know if it needed promotion! */
1295 if (operand->flags & MN10300_OPERAND_PROMOTE)
1297 input_line_pointer = hold;
1302 /* We need to generate a fixup for this expression. */
1303 if (fc >= MAX_INSN_FIXUPS)
1304 as_fatal (_("too many fixups"));
1305 fixups[fc].exp = ex;
1306 fixups[fc].opindex = *opindex_ptr;
1307 fixups[fc].reloc = BFD_RELOC_UNUSED;
1313 str = input_line_pointer;
1314 input_line_pointer = hold;
1316 while (*str == ' ' || *str == ',')
1321 /* Make sure we used all the operands! */
1328 next_opcode = opcode + 1;
1329 if (!strcmp(next_opcode->name, opcode->name))
1331 opcode = next_opcode;
1335 as_bad ("%s", errmsg);
1341 while (isspace (*str))
1345 as_bad (_("junk at end of line: `%s'"), str);
1347 input_line_pointer = str;
1349 /* Determine the size of the instruction. */
1350 if (opcode->format == FMT_S0)
1353 if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
1356 if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
1359 /* start-sanitize-am33 */
1360 if (opcode->format == FMT_D6)
1363 if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
1366 if (opcode->format == FMT_D8)
1369 if (opcode->format == FMT_D9)
1371 /* end-sanitize-am33 */
1373 if (opcode->format == FMT_S4)
1376 if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
1379 if (opcode->format == FMT_D2)
1382 if (opcode->format == FMT_D4)
1385 if (relaxable && fc > 0)
1392 /* Handle bra specially. Basically treat it like jmp so
1393 that we automatically handle 8, 16 and 32 bit offsets
1394 correctly as well as jumps to an undefined address.
1396 It is also important to not treat it like other bCC
1397 instructions since the long forms of bra is different
1398 from other bCC instructions. */
1399 if (opcode->opcode == 0xca00)
1411 else if (size == 3 && opcode->opcode == 0xcc0000)
1413 /* bCC (uncommon cases) */
1417 f = frag_var (rs_machine_dependent, 8, 8 - size, type,
1418 fixups[0].exp.X_add_symbol,
1419 fixups[0].exp.X_add_number,
1420 (char *)fixups[0].opindex);
1422 /* This is pretty hokey. We basically just care about the
1423 opcode, so we have to write out the first word big endian.
1425 The exception is "call", which has two operands that we
1428 The first operand (the register list) happens to be in the
1429 first instruction word, and will be in the right place if
1430 we output the first word in big endian mode.
1432 The second operand (stack size) is in the extension word,
1433 and we want it to appear as the first character in the extension
1434 word (as it appears in memory). Luckily, writing the extension
1435 word in big endian format will do what we want. */
1436 number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
1439 number_to_chars_bigendian (f + 4, extension, 4);
1440 number_to_chars_bigendian (f + 8, 0, size - 8);
1443 number_to_chars_bigendian (f + 4, extension, size - 4);
1447 /* Allocate space for the instruction. */
1448 f = frag_more (size);
1450 /* Fill in bytes for the instruction. Note that opcode fields
1451 are written big-endian, 16 & 32bit immediates are written
1452 little endian. Egad. */
1453 if (opcode->format == FMT_S0
1454 || opcode->format == FMT_S1
1455 || opcode->format == FMT_D0
1456 /* start-sanitize-am33 */
1457 || opcode->format == FMT_D6
1458 || opcode->format == FMT_D7
1459 || opcode->format == FMT_D10
1460 /* end-sanitize-am33 */
1461 || opcode->format == FMT_D1)
1463 number_to_chars_bigendian (f, insn, size);
1465 else if (opcode->format == FMT_S2
1466 && opcode->opcode != 0xdf0000
1467 && opcode->opcode != 0xde0000)
1469 /* A format S2 instruction that is _not_ "ret" and "retf". */
1470 number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
1471 number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
1473 else if (opcode->format == FMT_S2)
1475 /* This must be a ret or retf, which is written entirely in
1476 big-endian format. */
1477 number_to_chars_bigendian (f, insn, 3);
1479 else if (opcode->format == FMT_S4
1480 && opcode->opcode != 0xdc000000)
1482 /* This must be a format S4 "call" instruction. What a pain. */
1483 unsigned long temp = (insn >> 8) & 0xffff;
1484 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1485 number_to_chars_littleendian (f + 1, temp, 2);
1486 number_to_chars_bigendian (f + 3, insn & 0xff, 1);
1487 number_to_chars_bigendian (f + 4, extension & 0xff, 1);
1489 else if (opcode->format == FMT_S4)
1491 /* This must be a format S4 "jmp" instruction. */
1492 unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
1493 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1494 number_to_chars_littleendian (f + 1, temp, 4);
1496 else if (opcode->format == FMT_S6)
1498 unsigned long temp = ((insn & 0xffffff) << 8)
1499 | ((extension >> 16) & 0xff);
1500 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1501 number_to_chars_littleendian (f + 1, temp, 4);
1502 number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
1503 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1505 else if (opcode->format == FMT_D2
1506 && opcode->opcode != 0xfaf80000
1507 && opcode->opcode != 0xfaf00000
1508 && opcode->opcode != 0xfaf40000)
1510 /* A format D2 instruction where the 16bit immediate is
1511 really a single 16bit value, not two 8bit values. */
1512 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1513 number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
1515 else if (opcode->format == FMT_D2)
1517 /* A format D2 instruction where the 16bit immediate
1518 is really two 8bit immediates. */
1519 number_to_chars_bigendian (f, insn, 4);
1521 else if (opcode->format == FMT_D4)
1523 unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
1524 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1525 number_to_chars_littleendian (f + 2, temp, 4);
1527 else if (opcode->format == FMT_D5)
1529 unsigned long temp = ((insn & 0xffff) << 16)
1530 | ((extension >> 8) & 0xffff);
1531 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1532 number_to_chars_littleendian (f + 2, temp, 4);
1533 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1535 /* start-sanitize-am33 */
1536 else if (opcode->format == FMT_D8)
1538 unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
1539 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1540 number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
1541 number_to_chars_littleendian (f + 4, temp >> 8, 2);
1543 else if (opcode->format == FMT_D9)
1545 unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
1546 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1547 number_to_chars_littleendian (f + 3, temp, 4);
1549 /* end-sanitize-am33 */
1551 /* Create any fixups. */
1552 for (i = 0; i < fc; i++)
1554 const struct mn10300_operand *operand;
1556 operand = &mn10300_operands[fixups[i].opindex];
1557 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1559 reloc_howto_type *reloc_howto;
1564 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1569 size = bfd_get_reloc_size (reloc_howto);
1571 if (size < 1 || size > 4)
1575 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1576 size, &fixups[i].exp,
1577 reloc_howto->pc_relative,
1582 int reloc, pcrel, reloc_size, offset;
1585 reloc = BFD_RELOC_NONE;
1586 /* How big is the reloc? Remember SPLIT relocs are
1587 implicitly 32bits. */
1588 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1590 /* start-sanitize-am33 */
1591 if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1593 /* end-sanitize-am33 */
1595 reloc_size = operand->bits;
1597 /* Is the reloc pc-relative? */
1598 pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
1600 /* Gross. This disgusting hack is to make sure we
1601 get the right offset for the 16/32 bit reloc in
1602 "call" instructions. Basically they're a pain
1603 because the reloc isn't at the end of the instruction. */
1604 if ((size == 5 || size == 7)
1605 && (((insn >> 24) & 0xff) == 0xcd
1606 || ((insn >> 24) & 0xff) == 0xdd))
1609 /* Similarly for certain bit instructions which don't
1610 hav their 32bit reloc at the tail of the instruction. */
1612 && (((insn >> 16) & 0xffff) == 0xfe00
1613 || ((insn >> 16) & 0xffff) == 0xfe01
1614 || ((insn >> 16) & 0xffff) == 0xfe02))
1617 offset = size - reloc_size / 8;
1619 /* Choose a proper BFD relocation type. */
1622 if (reloc_size == 32)
1623 reloc = BFD_RELOC_32_PCREL;
1624 else if (reloc_size == 16)
1625 reloc = BFD_RELOC_16_PCREL;
1626 else if (reloc_size == 8)
1627 reloc = BFD_RELOC_8_PCREL;
1633 if (reloc_size == 32)
1634 reloc = BFD_RELOC_32;
1635 else if (reloc_size == 16)
1636 reloc = BFD_RELOC_16;
1637 else if (reloc_size == 8)
1638 reloc = BFD_RELOC_8;
1643 /* Convert the size of the reloc into what fix_new_exp wants. */
1644 reloc_size = reloc_size / 8;
1645 if (reloc_size == 8)
1647 else if (reloc_size == 16)
1649 else if (reloc_size == 32)
1652 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1653 reloc_size, &fixups[i].exp, pcrel,
1654 ((bfd_reloc_code_real_type) reloc));
1657 fixP->fx_offset += offset;
1664 /* if while processing a fixup, a reloc really needs to be created */
1665 /* then it is done here */
1668 tc_gen_reloc (seg, fixp)
1673 reloc = (arelent *) xmalloc (sizeof (arelent));
1675 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1676 if (reloc->howto == (reloc_howto_type *) NULL)
1678 as_bad_where (fixp->fx_file, fixp->fx_line,
1679 _("reloc %d not supported by object file format"),
1680 (int)fixp->fx_r_type);
1683 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1685 if (fixp->fx_addsy && fixp->fx_subsy)
1688 if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
1689 || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
1691 as_bad_where (fixp->fx_file, fixp->fx_line,
1692 "Difference of symbols in different sections is not supported");
1696 reloc->sym_ptr_ptr = &bfd_abs_symbol;
1697 reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
1698 - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
1702 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
1703 reloc->addend = fixp->fx_offset;
1709 md_estimate_size_before_relax (fragp, seg)
1713 if (fragp->fr_subtype == 0)
1715 if (fragp->fr_subtype == 3)
1717 if (fragp->fr_subtype == 6)
1719 if (!S_IS_DEFINED (fragp->fr_symbol)
1720 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1722 fragp->fr_subtype = 7;
1728 if (fragp->fr_subtype == 8)
1730 if (!S_IS_DEFINED (fragp->fr_symbol)
1731 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1733 fragp->fr_subtype = 9;
1739 if (fragp->fr_subtype == 10)
1741 if (!S_IS_DEFINED (fragp->fr_symbol)
1742 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1744 fragp->fr_subtype = 12;
1753 md_pcrel_from (fixp)
1756 return fixp->fx_frag->fr_address;
1758 if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy))
1760 /* The symbol is undefined. Let the linker figure it out. */
1763 return fixp->fx_frag->fr_address + fixp->fx_where;
1768 md_apply_fix3 (fixp, valuep, seg)
1773 /* We shouldn't ever get here because linkrelax is nonzero. */
1779 /* Insert an operand value into an instruction. */
1782 mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift)
1783 unsigned long *insnp;
1784 unsigned long *extensionp;
1785 const struct mn10300_operand *operand;
1791 /* No need to check 32bit operands for a bit. Note that
1792 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1793 if (operand->bits != 32
1794 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1800 bits = operand->bits;
1801 /* start-sanitize-am33 */
1802 if (operand->flags & MN10300_OPERAND_24BIT)
1804 /* end-sanitize-am33 */
1806 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1808 max = (1 << (bits - 1)) - 1;
1809 min = - (1 << (bits - 1));
1813 max = (1 << bits) - 1;
1820 if (test < (offsetT) min || test > (offsetT) max)
1823 _("operand out of range (%s not between %ld and %ld)");
1826 sprint_value (buf, test);
1827 if (file == (char *) NULL)
1828 as_warn (err, buf, min, max);
1830 as_warn_where (file, line, err, buf, min, max);
1834 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1836 *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
1837 *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
1840 /* start-sanitize-am33 */
1841 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1843 *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1);
1844 *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1))
1847 /* end-sanitize-am33 */
1848 else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
1850 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1851 << (operand->shift + shift));
1853 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1854 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1855 << (operand->shift + shift + operand->bits));
1859 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1860 << (operand->shift + shift));
1862 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1863 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1864 << (operand->shift + shift + operand->bits));
1868 static unsigned long
1869 check_operand (insn, operand, val)
1871 const struct mn10300_operand *operand;
1874 /* No need to check 32bit operands for a bit. Note that
1875 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1876 if (operand->bits != 32
1877 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1883 bits = operand->bits;
1884 /* start-sanitize-am33 */
1885 if (operand->flags & MN10300_OPERAND_24BIT)
1887 /* end-sanitize-am33 */
1889 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1891 max = (1 << (bits - 1)) - 1;
1892 min = - (1 << (bits - 1));
1896 max = (1 << bits) - 1;
1903 if (test < (offsetT) min || test > (offsetT) max)