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));
94 static void set_arch_mach PARAMS ((int));
96 static int current_machine;
99 #define MAX_INSN_FIXUPS (5)
104 bfd_reloc_code_real_type reloc;
106 struct mn10300_fixup fixups[MAX_INSN_FIXUPS];
109 const char *md_shortopts = "";
110 struct option md_longopts[] = {
111 {NULL, no_argument, NULL, 0}
113 size_t md_longopts_size = sizeof(md_longopts);
115 /* The target specific pseudo-ops which we support. */
116 const pseudo_typeS md_pseudo_table[] =
118 { "am30", set_arch_mach, 300 },
119 /* start-sanitize-am33 */
120 { "am33", set_arch_mach, 330 },
121 /* end-sanitize-am33 */
122 { "mn10300", set_arch_mach, 300 },
126 /* Opcode hash table. */
127 static struct hash_control *mn10300_hash;
129 /* This table is sorted. Suitable for searching by a binary search. */
130 static const struct reg_name data_registers[] =
137 #define DATA_REG_NAME_CNT (sizeof(data_registers) / sizeof(struct reg_name))
139 static const struct reg_name address_registers[] =
146 #define ADDRESS_REG_NAME_CNT (sizeof(address_registers) / sizeof(struct reg_name))
148 /* start-sanitize-am33 */
149 static const struct reg_name r_registers[] =
186 #define R_REG_NAME_CNT (sizeof(r_registers) / sizeof(struct reg_name))
188 static const struct reg_name xr_registers[] =
212 #define XR_REG_NAME_CNT (sizeof(xr_registers) / sizeof(struct reg_name))
214 /* end-sanitize-am33 */
216 static const struct reg_name other_registers[] =
222 #define OTHER_REG_NAME_CNT (sizeof(other_registers) / sizeof(struct reg_name))
224 /* reg_name_search does a binary search of the given register table
225 to see if "name" is a valid regiter name. Returns the register
226 number from the array on success, or -1 on failure. */
229 reg_name_search (regs, regcount, name)
230 const struct reg_name *regs;
234 int middle, low, high;
242 middle = (low + high) / 2;
243 cmp = strcasecmp (name, regs[middle].name);
249 return regs[middle].value;
256 /* start-sanitize-am33 */
257 /* Summary of register_name().
259 * in: Input_line_pointer points to 1st char of operand.
261 * out: A expressionS.
262 * The operand may have been a register: in this case, X_op == O_register,
263 * X_add_number is set to the register number, and truth is returned.
264 * Input_line_pointer->(next non-blank) char after operand, or is in
265 * its original state.
268 r_register_name (expressionP)
269 expressionS *expressionP;
276 /* Find the spelling of the operand */
277 start = name = input_line_pointer;
279 c = get_symbol_end ();
280 reg_number = reg_name_search (r_registers, R_REG_NAME_CNT, name);
282 /* look to see if it's in the register table */
285 expressionP->X_op = O_register;
286 expressionP->X_add_number = reg_number;
288 /* make the rest nice */
289 expressionP->X_add_symbol = NULL;
290 expressionP->X_op_symbol = NULL;
291 *input_line_pointer = c; /* put back the delimiting char */
296 /* reset the line as if we had not done anything */
297 *input_line_pointer = c; /* put back the delimiting char */
298 input_line_pointer = start; /* reset input_line pointer */
303 /* Summary of register_name().
305 * in: Input_line_pointer points to 1st char of operand.
307 * out: A expressionS.
308 * The operand may have been a register: in this case, X_op == O_register,
309 * X_add_number is set to the register number, and truth is returned.
310 * Input_line_pointer->(next non-blank) char after operand, or is in
311 * its original state.
314 xr_register_name (expressionP)
315 expressionS *expressionP;
322 /* Find the spelling of the operand */
323 start = name = input_line_pointer;
325 c = get_symbol_end ();
326 reg_number = reg_name_search (xr_registers, XR_REG_NAME_CNT, name);
328 /* look to see if it's in the register table */
331 expressionP->X_op = O_register;
332 expressionP->X_add_number = reg_number;
334 /* make the rest nice */
335 expressionP->X_add_symbol = NULL;
336 expressionP->X_op_symbol = NULL;
337 *input_line_pointer = c; /* put back the delimiting char */
342 /* reset the line as if we had not done anything */
343 *input_line_pointer = c; /* put back the delimiting char */
344 input_line_pointer = start; /* reset input_line pointer */
348 /* end-sanitize-am33 */
350 /* Summary of register_name().
352 * in: Input_line_pointer points to 1st char of operand.
354 * out: A expressionS.
355 * The operand may have been a register: in this case, X_op == O_register,
356 * X_add_number is set to the register number, and truth is returned.
357 * Input_line_pointer->(next non-blank) char after operand, or is in
358 * its original state.
361 data_register_name (expressionP)
362 expressionS *expressionP;
369 /* Find the spelling of the operand */
370 start = name = input_line_pointer;
372 c = get_symbol_end ();
373 reg_number = reg_name_search (data_registers, DATA_REG_NAME_CNT, name);
375 /* look to see if it's in the register table */
378 expressionP->X_op = O_register;
379 expressionP->X_add_number = reg_number;
381 /* make the rest nice */
382 expressionP->X_add_symbol = NULL;
383 expressionP->X_op_symbol = NULL;
384 *input_line_pointer = c; /* put back the delimiting char */
389 /* reset the line as if we had not done anything */
390 *input_line_pointer = c; /* put back the delimiting char */
391 input_line_pointer = start; /* reset input_line pointer */
396 /* Summary of register_name().
398 * in: Input_line_pointer points to 1st char of operand.
400 * out: A expressionS.
401 * The operand may have been a register: in this case, X_op == O_register,
402 * X_add_number is set to the register number, and truth is returned.
403 * Input_line_pointer->(next non-blank) char after operand, or is in
404 * its original state.
407 address_register_name (expressionP)
408 expressionS *expressionP;
415 /* Find the spelling of the operand */
416 start = name = input_line_pointer;
418 c = get_symbol_end ();
419 reg_number = reg_name_search (address_registers, ADDRESS_REG_NAME_CNT, name);
421 /* look to see if it's in the register table */
424 expressionP->X_op = O_register;
425 expressionP->X_add_number = reg_number;
427 /* make the rest nice */
428 expressionP->X_add_symbol = NULL;
429 expressionP->X_op_symbol = NULL;
430 *input_line_pointer = c; /* put back the delimiting char */
435 /* reset the line as if we had not done anything */
436 *input_line_pointer = c; /* put back the delimiting char */
437 input_line_pointer = start; /* reset input_line pointer */
442 /* Summary of register_name().
444 * in: Input_line_pointer points to 1st char of operand.
446 * out: A expressionS.
447 * The operand may have been a register: in this case, X_op == O_register,
448 * X_add_number is set to the register number, and truth is returned.
449 * Input_line_pointer->(next non-blank) char after operand, or is in
450 * its original state.
453 other_register_name (expressionP)
454 expressionS *expressionP;
461 /* Find the spelling of the operand */
462 start = name = input_line_pointer;
464 c = get_symbol_end ();
465 reg_number = reg_name_search (other_registers, OTHER_REG_NAME_CNT, name);
467 /* look to see if it's in the register table */
470 expressionP->X_op = O_register;
471 expressionP->X_add_number = reg_number;
473 /* make the rest nice */
474 expressionP->X_add_symbol = NULL;
475 expressionP->X_op_symbol = NULL;
476 *input_line_pointer = c; /* put back the delimiting char */
481 /* reset the line as if we had not done anything */
482 *input_line_pointer = c; /* put back the delimiting char */
483 input_line_pointer = start; /* reset input_line pointer */
489 md_show_usage (stream)
492 fprintf(stream, _("MN10300 options:\n\
497 md_parse_option (c, arg)
505 md_undefined_symbol (name)
512 md_atof (type, litp, sizep)
518 LITTLENUM_TYPE words[4];
534 return "bad call to md_atof";
537 t = atof_ieee (input_line_pointer, type, words);
539 input_line_pointer = t;
543 for (i = prec - 1; i >= 0; i--)
545 md_number_to_chars (litp, (valueT) words[i], 2);
554 md_convert_frag (abfd, sec, fragP)
559 static unsigned long label_count = 0;
562 subseg_change (sec, 0);
563 if (fragP->fr_subtype == 0)
565 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
566 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
570 else if (fragP->fr_subtype == 1)
572 /* Reverse the condition of the first branch. */
573 int offset = fragP->fr_fix;
574 int opcode = fragP->fr_literal[offset] & 0xff;
611 fragP->fr_literal[offset] = opcode;
613 /* Create a fixup for the reversed conditional branch. */
614 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
615 fix_new (fragP, fragP->fr_fix + 1, 1,
616 symbol_new (buf, sec, 0, fragP->fr_next),
617 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
619 /* Now create the unconditional branch + fixup to the
621 fragP->fr_literal[offset + 2] = 0xcc;
622 fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
623 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
627 else if (fragP->fr_subtype == 2)
629 /* Reverse the condition of the first branch. */
630 int offset = fragP->fr_fix;
631 int opcode = fragP->fr_literal[offset] & 0xff;
668 fragP->fr_literal[offset] = opcode;
670 /* Create a fixup for the reversed conditional branch. */
671 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
672 fix_new (fragP, fragP->fr_fix + 1, 1,
673 symbol_new (buf, sec, 0, fragP->fr_next),
674 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
676 /* Now create the unconditional branch + fixup to the
678 fragP->fr_literal[offset + 2] = 0xdc;
679 fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
680 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
684 else if (fragP->fr_subtype == 3)
686 fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
687 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
691 else if (fragP->fr_subtype == 4)
693 /* Reverse the condition of the first branch. */
694 int offset = fragP->fr_fix;
695 int opcode = fragP->fr_literal[offset + 1] & 0xff;
714 fragP->fr_literal[offset + 1] = opcode;
716 /* Create a fixup for the reversed conditional branch. */
717 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
718 fix_new (fragP, fragP->fr_fix + 2, 1,
719 symbol_new (buf, sec, 0, fragP->fr_next),
720 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
722 /* Now create the unconditional branch + fixup to the
724 fragP->fr_literal[offset + 3] = 0xcc;
725 fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
726 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
730 else if (fragP->fr_subtype == 5)
732 /* Reverse the condition of the first branch. */
733 int offset = fragP->fr_fix;
734 int opcode = fragP->fr_literal[offset + 1] & 0xff;
750 fragP->fr_literal[offset + 1] = opcode;
752 /* Create a fixup for the reversed conditional branch. */
753 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
754 fix_new (fragP, fragP->fr_fix + 2, 1,
755 symbol_new (buf, sec, 0, fragP->fr_next),
756 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
758 /* Now create the unconditional branch + fixup to the
760 fragP->fr_literal[offset + 3] = 0xdc;
761 fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
762 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
766 else if (fragP->fr_subtype == 6)
768 int offset = fragP->fr_fix;
769 fragP->fr_literal[offset] = 0xcd;
770 fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
771 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
775 else if (fragP->fr_subtype == 7)
777 int offset = fragP->fr_fix;
778 fragP->fr_literal[offset] = 0xdd;
779 fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
780 fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
782 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
783 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
787 else if (fragP->fr_subtype == 8)
789 int offset = fragP->fr_fix;
790 fragP->fr_literal[offset] = 0xfa;
791 fragP->fr_literal[offset + 1] = 0xff;
792 fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
793 fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
797 else if (fragP->fr_subtype == 9)
799 int offset = fragP->fr_fix;
800 fragP->fr_literal[offset] = 0xfc;
801 fragP->fr_literal[offset + 1] = 0xff;
803 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
804 fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
808 else if (fragP->fr_subtype == 10)
810 fragP->fr_literal[fragP->fr_fix] = 0xca;
811 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
812 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
816 else if (fragP->fr_subtype == 11)
818 int offset = fragP->fr_fix;
819 fragP->fr_literal[offset] = 0xcc;
821 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
822 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
826 else if (fragP->fr_subtype == 12)
828 int offset = fragP->fr_fix;
829 fragP->fr_literal[offset] = 0xdc;
831 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
832 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
841 md_section_align (seg, addr)
845 int align = bfd_get_section_alignment (stdoutput, seg);
846 return ((addr + (1 << align) - 1) & (-1 << align));
852 char *prev_name = "";
853 register const struct mn10300_opcode *op;
855 mn10300_hash = hash_new();
857 /* Insert unique names into hash table. The MN10300 instruction set
858 has many identical opcode names that have different opcodes based
859 on the operands. This hash table then provides a quick index to
860 the first opcode with a particular name in the opcode table. */
862 op = mn10300_opcodes;
865 if (strcmp (prev_name, op->name))
867 prev_name = (char *) op->name;
868 hash_insert (mn10300_hash, op->name, (char *) op);
873 /* This is both a simplification (we don't have to write md_apply_fix)
874 and support for future optimizations (branch shortening and similar
875 stuff in the linker. */
878 /* Set the default machine type. */
879 if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, 300))
880 as_warn (_("could not set architecture and machine"));
882 current_machine = 300;
890 struct mn10300_opcode *opcode;
891 struct mn10300_opcode *next_opcode;
892 const unsigned char *opindex_ptr;
893 int next_opindex, relaxable;
894 unsigned long insn, extension, size = 0;
899 /* Get the opcode. */
900 for (s = str; *s != '\0' && ! isspace (*s); s++)
905 /* find the first opcode with the proper name */
906 opcode = (struct mn10300_opcode *)hash_find (mn10300_hash, str);
909 as_bad (_("Unrecognized opcode: `%s'"), str);
914 while (isspace (*str))
917 input_line_pointer = str;
921 const char *errmsg = NULL;
931 insn = opcode->opcode;
934 /* If the instruction is not available on the current machine
935 then it can not possibly match. */
937 && (opcode->machine != current_machine))
940 for (op_idx = 1, opindex_ptr = opcode->operands;
942 opindex_ptr++, op_idx++)
944 const struct mn10300_operand *operand;
947 if (next_opindex == 0)
949 operand = &mn10300_operands[*opindex_ptr];
953 operand = &mn10300_operands[next_opindex];
959 while (*str == ' ' || *str == ',')
962 if (operand->flags & MN10300_OPERAND_RELAX)
965 /* Gather the operand. */
966 hold = input_line_pointer;
967 input_line_pointer = str;
969 if (operand->flags & MN10300_OPERAND_PAREN)
971 if (*input_line_pointer != ')' && *input_line_pointer != '(')
973 input_line_pointer = hold;
977 input_line_pointer++;
980 /* See if we can match the operands. */
981 else if (operand->flags & MN10300_OPERAND_DREG)
983 if (!data_register_name (&ex))
985 input_line_pointer = hold;
990 else if (operand->flags & MN10300_OPERAND_AREG)
992 if (!address_register_name (&ex))
994 input_line_pointer = hold;
999 else if (operand->flags & MN10300_OPERAND_SP)
1001 char *start = input_line_pointer;
1002 char c = get_symbol_end ();
1004 if (strcasecmp (start, "sp") != 0)
1006 *input_line_pointer = c;
1007 input_line_pointer = hold;
1011 *input_line_pointer = c;
1014 /* start-sanitize-am33 */
1015 else if (operand->flags & MN10300_OPERAND_RREG)
1017 if (!r_register_name (&ex))
1019 input_line_pointer = hold;
1024 else if (operand->flags & MN10300_OPERAND_XRREG)
1026 if (!xr_register_name (&ex))
1028 input_line_pointer = hold;
1033 else if (operand->flags & MN10300_OPERAND_USP)
1035 char *start = input_line_pointer;
1036 char c = get_symbol_end ();
1038 if (strcasecmp (start, "usp") != 0)
1040 *input_line_pointer = c;
1041 input_line_pointer = hold;
1045 *input_line_pointer = c;
1048 else if (operand->flags & MN10300_OPERAND_SSP)
1050 char *start = input_line_pointer;
1051 char c = get_symbol_end ();
1053 if (strcasecmp (start, "ssp") != 0)
1055 *input_line_pointer = c;
1056 input_line_pointer = hold;
1060 *input_line_pointer = c;
1063 else if (operand->flags & MN10300_OPERAND_MSP)
1065 char *start = input_line_pointer;
1066 char c = get_symbol_end ();
1068 if (strcasecmp (start, "msp") != 0)
1070 *input_line_pointer = c;
1071 input_line_pointer = hold;
1075 *input_line_pointer = c;
1078 else if (operand->flags & MN10300_OPERAND_PC)
1080 char *start = input_line_pointer;
1081 char c = get_symbol_end ();
1083 if (strcasecmp (start, "pc") != 0)
1085 *input_line_pointer = c;
1086 input_line_pointer = hold;
1090 *input_line_pointer = c;
1093 else if (operand->flags & MN10300_OPERAND_EPSW)
1095 char *start = input_line_pointer;
1096 char c = get_symbol_end ();
1098 if (strcasecmp (start, "epsw") != 0)
1100 *input_line_pointer = c;
1101 input_line_pointer = hold;
1105 *input_line_pointer = c;
1108 else if (operand->flags & MN10300_OPERAND_PLUS)
1110 if (*input_line_pointer != '+')
1112 input_line_pointer = hold;
1116 input_line_pointer++;
1119 /* end-sanitize-am33 */
1120 else if (operand->flags & MN10300_OPERAND_PSW)
1122 char *start = input_line_pointer;
1123 char c = get_symbol_end ();
1125 if (strcasecmp (start, "psw") != 0)
1127 *input_line_pointer = c;
1128 input_line_pointer = hold;
1132 *input_line_pointer = c;
1135 else if (operand->flags & MN10300_OPERAND_MDR)
1137 char *start = input_line_pointer;
1138 char c = get_symbol_end ();
1140 if (strcasecmp (start, "mdr") != 0)
1142 *input_line_pointer = c;
1143 input_line_pointer = hold;
1147 *input_line_pointer = c;
1150 else if (operand->flags & MN10300_OPERAND_REG_LIST)
1152 unsigned int value = 0;
1153 if (*input_line_pointer != '[')
1155 input_line_pointer = hold;
1161 input_line_pointer++;
1163 /* We used to reject a null register list here; however,
1164 we accept it now so the compiler can emit "call" instructions
1165 for all calls to named functions.
1167 The linker can then fill in the appropriate bits for the
1168 register list and stack size or change the instruction
1169 into a "calls" if using "call" is not profitable. */
1170 while (*input_line_pointer != ']')
1175 if (*input_line_pointer == ',')
1176 input_line_pointer++;
1178 start = input_line_pointer;
1179 c = get_symbol_end ();
1181 if (strcasecmp (start, "d2") == 0)
1184 *input_line_pointer = c;
1186 else if (strcasecmp (start, "d3") == 0)
1189 *input_line_pointer = c;
1191 else if (strcasecmp (start, "a2") == 0)
1194 *input_line_pointer = c;
1196 else if (strcasecmp (start, "a3") == 0)
1199 *input_line_pointer = c;
1201 else if (strcasecmp (start, "other") == 0)
1204 *input_line_pointer = c;
1206 /* start-sanitize-am33 */
1207 else if (strcasecmp (start, "exreg0") == 0)
1210 *input_line_pointer = c;
1212 else if (strcasecmp (start, "exreg1") == 0)
1215 *input_line_pointer = c;
1217 else if (strcasecmp (start, "exother") == 0)
1220 *input_line_pointer = c;
1222 else if (strcasecmp (start, "all") == 0)
1225 *input_line_pointer = c;
1227 /* end-sanitize-am33 */
1230 input_line_pointer = hold;
1235 input_line_pointer++;
1236 mn10300_insert_operand (&insn, &extension, operand,
1237 value, (char *) NULL, 0, 0);
1241 else if (data_register_name (&ex))
1243 input_line_pointer = hold;
1247 else if (address_register_name (&ex))
1249 input_line_pointer = hold;
1253 else if (other_register_name (&ex))
1255 input_line_pointer = hold;
1259 else if (*str == ')' || *str == '(')
1261 input_line_pointer = hold;
1273 errmsg = _("illegal operand");
1276 errmsg = _("missing operand");
1282 mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
1283 /* start-sanitize-am33 */
1284 mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
1285 /* end-sanitize-am33 */
1286 if ((operand->flags & mask) == 0)
1288 input_line_pointer = hold;
1293 if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
1295 else if (opcode->format == FMT_D2
1296 || opcode->format == FMT_D4
1297 || opcode->format == FMT_S2
1298 || opcode->format == FMT_S4
1299 || opcode->format == FMT_S6
1300 || opcode->format == FMT_D5)
1302 /* start-sanitize-am33 */
1303 else if (opcode->format == FMT_D7)
1305 else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
1307 /* end-sanitize-am33 */
1311 mn10300_insert_operand (&insn, &extension, operand,
1312 ex.X_add_number, (char *) NULL,
1319 /* If this operand can be promoted, and it doesn't
1320 fit into the allocated bitfield for this insn,
1321 then promote it (ie this opcode does not match). */
1323 & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
1324 && ! check_operand (insn, operand, ex.X_add_number))
1326 input_line_pointer = hold;
1331 mn10300_insert_operand (&insn, &extension, operand,
1332 ex.X_add_number, (char *) NULL,
1337 /* If this operand can be promoted, then this opcode didn't
1338 match since we can't know if it needed promotion! */
1339 if (operand->flags & MN10300_OPERAND_PROMOTE)
1341 input_line_pointer = hold;
1346 /* We need to generate a fixup for this expression. */
1347 if (fc >= MAX_INSN_FIXUPS)
1348 as_fatal (_("too many fixups"));
1349 fixups[fc].exp = ex;
1350 fixups[fc].opindex = *opindex_ptr;
1351 fixups[fc].reloc = BFD_RELOC_UNUSED;
1357 str = input_line_pointer;
1358 input_line_pointer = hold;
1360 while (*str == ' ' || *str == ',')
1365 /* Make sure we used all the operands! */
1372 next_opcode = opcode + 1;
1373 if (!strcmp(next_opcode->name, opcode->name))
1375 opcode = next_opcode;
1379 as_bad ("%s", errmsg);
1385 while (isspace (*str))
1389 as_bad (_("junk at end of line: `%s'"), str);
1391 input_line_pointer = str;
1393 /* Determine the size of the instruction. */
1394 if (opcode->format == FMT_S0)
1397 if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
1400 if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
1403 /* start-sanitize-am33 */
1404 if (opcode->format == FMT_D6)
1407 if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
1410 if (opcode->format == FMT_D8)
1413 if (opcode->format == FMT_D9)
1415 /* end-sanitize-am33 */
1417 if (opcode->format == FMT_S4)
1420 if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
1423 if (opcode->format == FMT_D2)
1426 if (opcode->format == FMT_D4)
1429 if (relaxable && fc > 0)
1436 /* Handle bra specially. Basically treat it like jmp so
1437 that we automatically handle 8, 16 and 32 bit offsets
1438 correctly as well as jumps to an undefined address.
1440 It is also important to not treat it like other bCC
1441 instructions since the long forms of bra is different
1442 from other bCC instructions. */
1443 if (opcode->opcode == 0xca00)
1455 else if (size == 3 && opcode->opcode == 0xcc0000)
1457 /* bCC (uncommon cases) */
1461 f = frag_var (rs_machine_dependent, 8, 8 - size, type,
1462 fixups[0].exp.X_add_symbol,
1463 fixups[0].exp.X_add_number,
1464 (char *)fixups[0].opindex);
1466 /* This is pretty hokey. We basically just care about the
1467 opcode, so we have to write out the first word big endian.
1469 The exception is "call", which has two operands that we
1472 The first operand (the register list) happens to be in the
1473 first instruction word, and will be in the right place if
1474 we output the first word in big endian mode.
1476 The second operand (stack size) is in the extension word,
1477 and we want it to appear as the first character in the extension
1478 word (as it appears in memory). Luckily, writing the extension
1479 word in big endian format will do what we want. */
1480 number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
1483 number_to_chars_bigendian (f + 4, extension, 4);
1484 number_to_chars_bigendian (f + 8, 0, size - 8);
1487 number_to_chars_bigendian (f + 4, extension, size - 4);
1491 /* Allocate space for the instruction. */
1492 f = frag_more (size);
1494 /* Fill in bytes for the instruction. Note that opcode fields
1495 are written big-endian, 16 & 32bit immediates are written
1496 little endian. Egad. */
1497 if (opcode->format == FMT_S0
1498 || opcode->format == FMT_S1
1499 || opcode->format == FMT_D0
1500 /* start-sanitize-am33 */
1501 || opcode->format == FMT_D6
1502 || opcode->format == FMT_D7
1503 || opcode->format == FMT_D10
1504 /* end-sanitize-am33 */
1505 || opcode->format == FMT_D1)
1507 number_to_chars_bigendian (f, insn, size);
1509 else if (opcode->format == FMT_S2
1510 && opcode->opcode != 0xdf0000
1511 && opcode->opcode != 0xde0000)
1513 /* A format S2 instruction that is _not_ "ret" and "retf". */
1514 number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
1515 number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
1517 else if (opcode->format == FMT_S2)
1519 /* This must be a ret or retf, which is written entirely in
1520 big-endian format. */
1521 number_to_chars_bigendian (f, insn, 3);
1523 else if (opcode->format == FMT_S4
1524 && opcode->opcode != 0xdc000000)
1526 /* This must be a format S4 "call" instruction. What a pain. */
1527 unsigned long temp = (insn >> 8) & 0xffff;
1528 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1529 number_to_chars_littleendian (f + 1, temp, 2);
1530 number_to_chars_bigendian (f + 3, insn & 0xff, 1);
1531 number_to_chars_bigendian (f + 4, extension & 0xff, 1);
1533 else if (opcode->format == FMT_S4)
1535 /* This must be a format S4 "jmp" instruction. */
1536 unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
1537 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1538 number_to_chars_littleendian (f + 1, temp, 4);
1540 else if (opcode->format == FMT_S6)
1542 unsigned long temp = ((insn & 0xffffff) << 8)
1543 | ((extension >> 16) & 0xff);
1544 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1545 number_to_chars_littleendian (f + 1, temp, 4);
1546 number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
1547 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1549 else if (opcode->format == FMT_D2
1550 && opcode->opcode != 0xfaf80000
1551 && opcode->opcode != 0xfaf00000
1552 && opcode->opcode != 0xfaf40000)
1554 /* A format D2 instruction where the 16bit immediate is
1555 really a single 16bit value, not two 8bit values. */
1556 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1557 number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
1559 else if (opcode->format == FMT_D2)
1561 /* A format D2 instruction where the 16bit immediate
1562 is really two 8bit immediates. */
1563 number_to_chars_bigendian (f, insn, 4);
1565 else if (opcode->format == FMT_D4)
1567 unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
1568 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1569 number_to_chars_littleendian (f + 2, temp, 4);
1571 else if (opcode->format == FMT_D5)
1573 unsigned long temp = ((insn & 0xffff) << 16)
1574 | ((extension >> 8) & 0xffff);
1575 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1576 number_to_chars_littleendian (f + 2, temp, 4);
1577 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1579 /* start-sanitize-am33 */
1580 else if (opcode->format == FMT_D8)
1582 unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
1583 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1584 number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
1585 number_to_chars_littleendian (f + 4, temp >> 8, 2);
1587 else if (opcode->format == FMT_D9)
1589 unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
1590 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1591 number_to_chars_littleendian (f + 3, temp, 4);
1593 /* end-sanitize-am33 */
1595 /* Create any fixups. */
1596 for (i = 0; i < fc; i++)
1598 const struct mn10300_operand *operand;
1600 operand = &mn10300_operands[fixups[i].opindex];
1601 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1603 reloc_howto_type *reloc_howto;
1608 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1613 size = bfd_get_reloc_size (reloc_howto);
1615 if (size < 1 || size > 4)
1619 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1620 size, &fixups[i].exp,
1621 reloc_howto->pc_relative,
1626 int reloc, pcrel, reloc_size, offset;
1629 reloc = BFD_RELOC_NONE;
1630 /* How big is the reloc? Remember SPLIT relocs are
1631 implicitly 32bits. */
1632 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1634 /* start-sanitize-am33 */
1635 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1637 /* end-sanitize-am33 */
1639 reloc_size = operand->bits;
1641 /* Is the reloc pc-relative? */
1642 pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
1644 /* Gross. This disgusting hack is to make sure we
1645 get the right offset for the 16/32 bit reloc in
1646 "call" instructions. Basically they're a pain
1647 because the reloc isn't at the end of the instruction. */
1648 if ((size == 5 || size == 7)
1649 && (((insn >> 24) & 0xff) == 0xcd
1650 || ((insn >> 24) & 0xff) == 0xdd))
1653 /* Similarly for certain bit instructions which don't
1654 hav their 32bit reloc at the tail of the instruction. */
1656 && (((insn >> 16) & 0xffff) == 0xfe00
1657 || ((insn >> 16) & 0xffff) == 0xfe01
1658 || ((insn >> 16) & 0xffff) == 0xfe02))
1661 offset = size - reloc_size / 8;
1663 /* Choose a proper BFD relocation type. */
1666 if (reloc_size == 32)
1667 reloc = BFD_RELOC_32_PCREL;
1668 else if (reloc_size == 16)
1669 reloc = BFD_RELOC_16_PCREL;
1670 else if (reloc_size == 8)
1671 reloc = BFD_RELOC_8_PCREL;
1677 if (reloc_size == 32)
1678 reloc = BFD_RELOC_32;
1679 else if (reloc_size == 16)
1680 reloc = BFD_RELOC_16;
1681 else if (reloc_size == 8)
1682 reloc = BFD_RELOC_8;
1687 /* Convert the size of the reloc into what fix_new_exp wants. */
1688 reloc_size = reloc_size / 8;
1689 if (reloc_size == 8)
1691 else if (reloc_size == 16)
1693 else if (reloc_size == 32)
1696 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1697 reloc_size, &fixups[i].exp, pcrel,
1698 ((bfd_reloc_code_real_type) reloc));
1701 fixP->fx_offset += offset;
1708 /* if while processing a fixup, a reloc really needs to be created */
1709 /* then it is done here */
1712 tc_gen_reloc (seg, fixp)
1717 reloc = (arelent *) xmalloc (sizeof (arelent));
1719 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1720 if (reloc->howto == (reloc_howto_type *) NULL)
1722 as_bad_where (fixp->fx_file, fixp->fx_line,
1723 _("reloc %d not supported by object file format"),
1724 (int)fixp->fx_r_type);
1727 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1729 if (fixp->fx_addsy && fixp->fx_subsy)
1732 if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
1733 || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
1735 as_bad_where (fixp->fx_file, fixp->fx_line,
1736 "Difference of symbols in different sections is not supported");
1740 reloc->sym_ptr_ptr = &bfd_abs_symbol;
1741 reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
1742 - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
1746 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
1747 reloc->addend = fixp->fx_offset;
1753 md_estimate_size_before_relax (fragp, seg)
1757 if (fragp->fr_subtype == 0)
1759 if (fragp->fr_subtype == 3)
1761 if (fragp->fr_subtype == 6)
1763 if (!S_IS_DEFINED (fragp->fr_symbol)
1764 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1766 fragp->fr_subtype = 7;
1772 if (fragp->fr_subtype == 8)
1774 if (!S_IS_DEFINED (fragp->fr_symbol)
1775 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1777 fragp->fr_subtype = 9;
1783 if (fragp->fr_subtype == 10)
1785 if (!S_IS_DEFINED (fragp->fr_symbol)
1786 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1788 fragp->fr_subtype = 12;
1797 md_pcrel_from (fixp)
1800 return fixp->fx_frag->fr_address;
1802 if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy))
1804 /* The symbol is undefined. Let the linker figure it out. */
1807 return fixp->fx_frag->fr_address + fixp->fx_where;
1812 md_apply_fix3 (fixp, valuep, seg)
1817 /* We shouldn't ever get here because linkrelax is nonzero. */
1823 /* Insert an operand value into an instruction. */
1826 mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift)
1827 unsigned long *insnp;
1828 unsigned long *extensionp;
1829 const struct mn10300_operand *operand;
1835 /* No need to check 32bit operands for a bit. Note that
1836 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1837 if (operand->bits != 32
1838 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1844 bits = operand->bits;
1845 /* start-sanitize-am33 */
1846 if (operand->flags & MN10300_OPERAND_24BIT)
1848 /* end-sanitize-am33 */
1850 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1852 max = (1 << (bits - 1)) - 1;
1853 min = - (1 << (bits - 1));
1857 max = (1 << bits) - 1;
1864 if (test < (offsetT) min || test > (offsetT) max)
1867 _("operand out of range (%s not between %ld and %ld)");
1870 sprint_value (buf, test);
1871 if (file == (char *) NULL)
1872 as_warn (err, buf, min, max);
1874 as_warn_where (file, line, err, buf, min, max);
1878 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1880 *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
1881 *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
1884 /* start-sanitize-am33 */
1885 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1887 *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1);
1888 *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1))
1891 /* end-sanitize-am33 */
1892 else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
1894 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1895 << (operand->shift + shift));
1897 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1898 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1899 << (operand->shift + shift + operand->bits));
1903 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1904 << (operand->shift + shift));
1906 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1907 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1908 << (operand->shift + shift + operand->bits));
1912 static unsigned long
1913 check_operand (insn, operand, val)
1915 const struct mn10300_operand *operand;
1918 /* No need to check 32bit operands for a bit. Note that
1919 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1920 if (operand->bits != 32
1921 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1927 bits = operand->bits;
1928 /* start-sanitize-am33 */
1929 if (operand->flags & MN10300_OPERAND_24BIT)
1931 /* end-sanitize-am33 */
1933 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1935 max = (1 << (bits - 1)) - 1;
1936 min = - (1 << (bits - 1));
1940 max = (1 << bits) - 1;
1947 if (test < (offsetT) min || test > (offsetT) max)
1956 set_arch_mach (mach)
1959 if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, mach))
1960 as_warn (_("could not set architecture and machine"));
1962 current_machine = mach;