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[] =
192 #define R_REG_NAME_CNT (sizeof(r_registers) / sizeof(struct reg_name))
194 static const struct reg_name xr_registers[] =
218 #define XR_REG_NAME_CNT (sizeof(xr_registers) / sizeof(struct reg_name))
220 /* end-sanitize-am33 */
222 static const struct reg_name other_registers[] =
228 #define OTHER_REG_NAME_CNT (sizeof(other_registers) / sizeof(struct reg_name))
230 /* reg_name_search does a binary search of the given register table
231 to see if "name" is a valid regiter name. Returns the register
232 number from the array on success, or -1 on failure. */
235 reg_name_search (regs, regcount, name)
236 const struct reg_name *regs;
240 int middle, low, high;
248 middle = (low + high) / 2;
249 cmp = strcasecmp (name, regs[middle].name);
255 return regs[middle].value;
262 /* start-sanitize-am33 */
263 /* Summary of register_name().
265 * in: Input_line_pointer points to 1st char of operand.
267 * out: A expressionS.
268 * The operand may have been a register: in this case, X_op == O_register,
269 * X_add_number is set to the register number, and truth is returned.
270 * Input_line_pointer->(next non-blank) char after operand, or is in
271 * its original state.
274 r_register_name (expressionP)
275 expressionS *expressionP;
282 /* Find the spelling of the operand */
283 start = name = input_line_pointer;
285 c = get_symbol_end ();
286 reg_number = reg_name_search (r_registers, R_REG_NAME_CNT, name);
288 /* look to see if it's in the register table */
291 expressionP->X_op = O_register;
292 expressionP->X_add_number = reg_number;
294 /* make the rest nice */
295 expressionP->X_add_symbol = NULL;
296 expressionP->X_op_symbol = NULL;
297 *input_line_pointer = c; /* put back the delimiting char */
302 /* reset the line as if we had not done anything */
303 *input_line_pointer = c; /* put back the delimiting char */
304 input_line_pointer = start; /* reset input_line pointer */
309 /* Summary of register_name().
311 * in: Input_line_pointer points to 1st char of operand.
313 * out: A expressionS.
314 * The operand may have been a register: in this case, X_op == O_register,
315 * X_add_number is set to the register number, and truth is returned.
316 * Input_line_pointer->(next non-blank) char after operand, or is in
317 * its original state.
320 xr_register_name (expressionP)
321 expressionS *expressionP;
328 /* Find the spelling of the operand */
329 start = name = input_line_pointer;
331 c = get_symbol_end ();
332 reg_number = reg_name_search (xr_registers, XR_REG_NAME_CNT, name);
334 /* look to see if it's in the register table */
337 expressionP->X_op = O_register;
338 expressionP->X_add_number = reg_number;
340 /* make the rest nice */
341 expressionP->X_add_symbol = NULL;
342 expressionP->X_op_symbol = NULL;
343 *input_line_pointer = c; /* put back the delimiting char */
348 /* reset the line as if we had not done anything */
349 *input_line_pointer = c; /* put back the delimiting char */
350 input_line_pointer = start; /* reset input_line pointer */
354 /* end-sanitize-am33 */
356 /* Summary of register_name().
358 * in: Input_line_pointer points to 1st char of operand.
360 * out: A expressionS.
361 * The operand may have been a register: in this case, X_op == O_register,
362 * X_add_number is set to the register number, and truth is returned.
363 * Input_line_pointer->(next non-blank) char after operand, or is in
364 * its original state.
367 data_register_name (expressionP)
368 expressionS *expressionP;
375 /* Find the spelling of the operand */
376 start = name = input_line_pointer;
378 c = get_symbol_end ();
379 reg_number = reg_name_search (data_registers, DATA_REG_NAME_CNT, name);
381 /* look to see if it's in the register table */
384 expressionP->X_op = O_register;
385 expressionP->X_add_number = reg_number;
387 /* make the rest nice */
388 expressionP->X_add_symbol = NULL;
389 expressionP->X_op_symbol = NULL;
390 *input_line_pointer = c; /* put back the delimiting char */
395 /* reset the line as if we had not done anything */
396 *input_line_pointer = c; /* put back the delimiting char */
397 input_line_pointer = start; /* reset input_line pointer */
402 /* Summary of register_name().
404 * in: Input_line_pointer points to 1st char of operand.
406 * out: A expressionS.
407 * The operand may have been a register: in this case, X_op == O_register,
408 * X_add_number is set to the register number, and truth is returned.
409 * Input_line_pointer->(next non-blank) char after operand, or is in
410 * its original state.
413 address_register_name (expressionP)
414 expressionS *expressionP;
421 /* Find the spelling of the operand */
422 start = name = input_line_pointer;
424 c = get_symbol_end ();
425 reg_number = reg_name_search (address_registers, ADDRESS_REG_NAME_CNT, name);
427 /* look to see if it's in the register table */
430 expressionP->X_op = O_register;
431 expressionP->X_add_number = reg_number;
433 /* make the rest nice */
434 expressionP->X_add_symbol = NULL;
435 expressionP->X_op_symbol = NULL;
436 *input_line_pointer = c; /* put back the delimiting char */
441 /* reset the line as if we had not done anything */
442 *input_line_pointer = c; /* put back the delimiting char */
443 input_line_pointer = start; /* reset input_line pointer */
448 /* Summary of register_name().
450 * in: Input_line_pointer points to 1st char of operand.
452 * out: A expressionS.
453 * The operand may have been a register: in this case, X_op == O_register,
454 * X_add_number is set to the register number, and truth is returned.
455 * Input_line_pointer->(next non-blank) char after operand, or is in
456 * its original state.
459 other_register_name (expressionP)
460 expressionS *expressionP;
467 /* Find the spelling of the operand */
468 start = name = input_line_pointer;
470 c = get_symbol_end ();
471 reg_number = reg_name_search (other_registers, OTHER_REG_NAME_CNT, name);
473 /* look to see if it's in the register table */
476 expressionP->X_op = O_register;
477 expressionP->X_add_number = reg_number;
479 /* make the rest nice */
480 expressionP->X_add_symbol = NULL;
481 expressionP->X_op_symbol = NULL;
482 *input_line_pointer = c; /* put back the delimiting char */
487 /* reset the line as if we had not done anything */
488 *input_line_pointer = c; /* put back the delimiting char */
489 input_line_pointer = start; /* reset input_line pointer */
495 md_show_usage (stream)
498 fprintf(stream, _("MN10300 options:\n\
503 md_parse_option (c, arg)
511 md_undefined_symbol (name)
518 md_atof (type, litp, sizep)
524 LITTLENUM_TYPE words[4];
540 return "bad call to md_atof";
543 t = atof_ieee (input_line_pointer, type, words);
545 input_line_pointer = t;
549 for (i = prec - 1; i >= 0; i--)
551 md_number_to_chars (litp, (valueT) words[i], 2);
560 md_convert_frag (abfd, sec, fragP)
565 static unsigned long label_count = 0;
568 subseg_change (sec, 0);
569 if (fragP->fr_subtype == 0)
571 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
572 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
576 else if (fragP->fr_subtype == 1)
578 /* Reverse the condition of the first branch. */
579 int offset = fragP->fr_fix;
580 int opcode = fragP->fr_literal[offset] & 0xff;
617 fragP->fr_literal[offset] = opcode;
619 /* Create a fixup for the reversed conditional branch. */
620 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
621 fix_new (fragP, fragP->fr_fix + 1, 1,
622 symbol_new (buf, sec, 0, fragP->fr_next),
623 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
625 /* Now create the unconditional branch + fixup to the
627 fragP->fr_literal[offset + 2] = 0xcc;
628 fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
629 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
633 else if (fragP->fr_subtype == 2)
635 /* Reverse the condition of the first branch. */
636 int offset = fragP->fr_fix;
637 int opcode = fragP->fr_literal[offset] & 0xff;
674 fragP->fr_literal[offset] = opcode;
676 /* Create a fixup for the reversed conditional branch. */
677 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
678 fix_new (fragP, fragP->fr_fix + 1, 1,
679 symbol_new (buf, sec, 0, fragP->fr_next),
680 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
682 /* Now create the unconditional branch + fixup to the
684 fragP->fr_literal[offset + 2] = 0xdc;
685 fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
686 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
690 else if (fragP->fr_subtype == 3)
692 fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
693 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
697 else if (fragP->fr_subtype == 4)
699 /* Reverse the condition of the first branch. */
700 int offset = fragP->fr_fix;
701 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] = 0xcc;
731 fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
732 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
736 else if (fragP->fr_subtype == 5)
738 /* Reverse the condition of the first branch. */
739 int offset = fragP->fr_fix;
740 int opcode = fragP->fr_literal[offset + 1] & 0xff;
756 fragP->fr_literal[offset + 1] = opcode;
758 /* Create a fixup for the reversed conditional branch. */
759 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
760 fix_new (fragP, fragP->fr_fix + 2, 1,
761 symbol_new (buf, sec, 0, fragP->fr_next),
762 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
764 /* Now create the unconditional branch + fixup to the
766 fragP->fr_literal[offset + 3] = 0xdc;
767 fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
768 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
772 else if (fragP->fr_subtype == 6)
774 int offset = fragP->fr_fix;
775 fragP->fr_literal[offset] = 0xcd;
776 fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
777 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
781 else if (fragP->fr_subtype == 7)
783 int offset = fragP->fr_fix;
784 fragP->fr_literal[offset] = 0xdd;
785 fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
786 fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
788 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
789 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
793 else if (fragP->fr_subtype == 8)
795 int offset = fragP->fr_fix;
796 fragP->fr_literal[offset] = 0xfa;
797 fragP->fr_literal[offset + 1] = 0xff;
798 fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
799 fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
803 else if (fragP->fr_subtype == 9)
805 int offset = fragP->fr_fix;
806 fragP->fr_literal[offset] = 0xfc;
807 fragP->fr_literal[offset + 1] = 0xff;
809 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
810 fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
814 else if (fragP->fr_subtype == 10)
816 fragP->fr_literal[fragP->fr_fix] = 0xca;
817 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
818 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
822 else if (fragP->fr_subtype == 11)
824 int offset = fragP->fr_fix;
825 fragP->fr_literal[offset] = 0xcc;
827 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
828 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
832 else if (fragP->fr_subtype == 12)
834 int offset = fragP->fr_fix;
835 fragP->fr_literal[offset] = 0xdc;
837 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
838 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
847 md_section_align (seg, addr)
851 int align = bfd_get_section_alignment (stdoutput, seg);
852 return ((addr + (1 << align) - 1) & (-1 << align));
858 char *prev_name = "";
859 register const struct mn10300_opcode *op;
861 mn10300_hash = hash_new();
863 /* Insert unique names into hash table. The MN10300 instruction set
864 has many identical opcode names that have different opcodes based
865 on the operands. This hash table then provides a quick index to
866 the first opcode with a particular name in the opcode table. */
868 op = mn10300_opcodes;
871 if (strcmp (prev_name, op->name))
873 prev_name = (char *) op->name;
874 hash_insert (mn10300_hash, op->name, (char *) op);
879 /* This is both a simplification (we don't have to write md_apply_fix)
880 and support for future optimizations (branch shortening and similar
881 stuff in the linker. */
884 /* Set the default machine type. */
885 if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, 300))
886 as_warn (_("could not set architecture and machine"));
888 current_machine = 300;
896 struct mn10300_opcode *opcode;
897 struct mn10300_opcode *next_opcode;
898 const unsigned char *opindex_ptr;
899 int next_opindex, relaxable;
900 unsigned long insn, extension, size = 0;
905 /* Get the opcode. */
906 for (s = str; *s != '\0' && ! isspace (*s); s++)
911 /* find the first opcode with the proper name */
912 opcode = (struct mn10300_opcode *)hash_find (mn10300_hash, str);
915 as_bad (_("Unrecognized opcode: `%s'"), str);
920 while (isspace (*str))
923 input_line_pointer = str;
927 const char *errmsg = "Invalid opcode/operands";
937 insn = opcode->opcode;
940 /* If the instruction is not available on the current machine
941 then it can not possibly match. */
943 && (opcode->machine != current_machine))
946 for (op_idx = 1, opindex_ptr = opcode->operands;
948 opindex_ptr++, op_idx++)
950 const struct mn10300_operand *operand;
953 if (next_opindex == 0)
955 operand = &mn10300_operands[*opindex_ptr];
959 operand = &mn10300_operands[next_opindex];
963 while (*str == ' ' || *str == ',')
966 if (operand->flags & MN10300_OPERAND_RELAX)
969 /* Gather the operand. */
970 hold = input_line_pointer;
971 input_line_pointer = str;
973 if (operand->flags & MN10300_OPERAND_PAREN)
975 if (*input_line_pointer != ')' && *input_line_pointer != '(')
977 input_line_pointer = hold;
981 input_line_pointer++;
984 /* See if we can match the operands. */
985 else if (operand->flags & MN10300_OPERAND_DREG)
987 if (!data_register_name (&ex))
989 input_line_pointer = hold;
994 else if (operand->flags & MN10300_OPERAND_AREG)
996 if (!address_register_name (&ex))
998 input_line_pointer = hold;
1003 else if (operand->flags & MN10300_OPERAND_SP)
1005 char *start = input_line_pointer;
1006 char c = get_symbol_end ();
1008 if (strcasecmp (start, "sp") != 0)
1010 *input_line_pointer = c;
1011 input_line_pointer = hold;
1015 *input_line_pointer = c;
1018 /* start-sanitize-am33 */
1019 else if (operand->flags & MN10300_OPERAND_RREG)
1021 if (!r_register_name (&ex))
1023 input_line_pointer = hold;
1028 else if (operand->flags & MN10300_OPERAND_XRREG)
1030 if (!xr_register_name (&ex))
1032 input_line_pointer = hold;
1037 else if (operand->flags & MN10300_OPERAND_USP)
1039 char *start = input_line_pointer;
1040 char c = get_symbol_end ();
1042 if (strcasecmp (start, "usp") != 0)
1044 *input_line_pointer = c;
1045 input_line_pointer = hold;
1049 *input_line_pointer = c;
1052 else if (operand->flags & MN10300_OPERAND_SSP)
1054 char *start = input_line_pointer;
1055 char c = get_symbol_end ();
1057 if (strcasecmp (start, "ssp") != 0)
1059 *input_line_pointer = c;
1060 input_line_pointer = hold;
1064 *input_line_pointer = c;
1067 else if (operand->flags & MN10300_OPERAND_MSP)
1069 char *start = input_line_pointer;
1070 char c = get_symbol_end ();
1072 if (strcasecmp (start, "msp") != 0)
1074 *input_line_pointer = c;
1075 input_line_pointer = hold;
1079 *input_line_pointer = c;
1082 else if (operand->flags & MN10300_OPERAND_PC)
1084 char *start = input_line_pointer;
1085 char c = get_symbol_end ();
1087 if (strcasecmp (start, "pc") != 0)
1089 *input_line_pointer = c;
1090 input_line_pointer = hold;
1094 *input_line_pointer = c;
1097 else if (operand->flags & MN10300_OPERAND_EPSW)
1099 char *start = input_line_pointer;
1100 char c = get_symbol_end ();
1102 if (strcasecmp (start, "epsw") != 0)
1104 *input_line_pointer = c;
1105 input_line_pointer = hold;
1109 *input_line_pointer = c;
1112 else if (operand->flags & MN10300_OPERAND_PLUS)
1114 if (*input_line_pointer != '+')
1116 input_line_pointer = hold;
1120 input_line_pointer++;
1123 /* end-sanitize-am33 */
1124 else if (operand->flags & MN10300_OPERAND_PSW)
1126 char *start = input_line_pointer;
1127 char c = get_symbol_end ();
1129 if (strcasecmp (start, "psw") != 0)
1131 *input_line_pointer = c;
1132 input_line_pointer = hold;
1136 *input_line_pointer = c;
1139 else if (operand->flags & MN10300_OPERAND_MDR)
1141 char *start = input_line_pointer;
1142 char c = get_symbol_end ();
1144 if (strcasecmp (start, "mdr") != 0)
1146 *input_line_pointer = c;
1147 input_line_pointer = hold;
1151 *input_line_pointer = c;
1154 else if (operand->flags & MN10300_OPERAND_REG_LIST)
1156 unsigned int value = 0;
1157 if (*input_line_pointer != '[')
1159 input_line_pointer = hold;
1165 input_line_pointer++;
1167 /* We used to reject a null register list here; however,
1168 we accept it now so the compiler can emit "call" instructions
1169 for all calls to named functions.
1171 The linker can then fill in the appropriate bits for the
1172 register list and stack size or change the instruction
1173 into a "calls" if using "call" is not profitable. */
1174 while (*input_line_pointer != ']')
1179 if (*input_line_pointer == ',')
1180 input_line_pointer++;
1182 start = input_line_pointer;
1183 c = get_symbol_end ();
1185 if (strcasecmp (start, "d2") == 0)
1188 *input_line_pointer = c;
1190 else if (strcasecmp (start, "d3") == 0)
1193 *input_line_pointer = c;
1195 else if (strcasecmp (start, "a2") == 0)
1198 *input_line_pointer = c;
1200 else if (strcasecmp (start, "a3") == 0)
1203 *input_line_pointer = c;
1205 else if (strcasecmp (start, "other") == 0)
1208 *input_line_pointer = c;
1210 /* start-sanitize-am33 */
1211 else if (strcasecmp (start, "exreg0") == 0)
1214 *input_line_pointer = c;
1216 else if (strcasecmp (start, "exreg1") == 0)
1219 *input_line_pointer = c;
1221 else if (strcasecmp (start, "exother") == 0)
1224 *input_line_pointer = c;
1226 else if (strcasecmp (start, "all") == 0)
1229 *input_line_pointer = c;
1231 /* end-sanitize-am33 */
1234 input_line_pointer = hold;
1239 input_line_pointer++;
1240 mn10300_insert_operand (&insn, &extension, operand,
1241 value, (char *) NULL, 0, 0);
1245 else if (data_register_name (&ex))
1247 input_line_pointer = hold;
1251 else if (address_register_name (&ex))
1253 input_line_pointer = hold;
1257 else if (other_register_name (&ex))
1259 input_line_pointer = hold;
1263 /* start-sanitize-am33 */
1264 else if (r_register_name (&ex))
1266 input_line_pointer = hold;
1270 else if (xr_register_name (&ex))
1272 input_line_pointer = hold;
1276 /* end-sanitize-am33 */
1277 else if (*str == ')' || *str == '(')
1279 input_line_pointer = hold;
1291 errmsg = _("illegal operand");
1294 errmsg = _("missing operand");
1300 mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
1301 /* start-sanitize-am33 */
1302 mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
1303 /* end-sanitize-am33 */
1304 if ((operand->flags & mask) == 0)
1306 input_line_pointer = hold;
1311 if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
1313 else if (opcode->format == FMT_D2
1314 || opcode->format == FMT_D4
1315 || opcode->format == FMT_S2
1316 || opcode->format == FMT_S4
1317 || opcode->format == FMT_S6
1318 || opcode->format == FMT_D5)
1320 /* start-sanitize-am33 */
1321 else if (opcode->format == FMT_D7)
1323 else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
1325 /* end-sanitize-am33 */
1329 mn10300_insert_operand (&insn, &extension, operand,
1330 ex.X_add_number, (char *) NULL,
1337 /* If this operand can be promoted, and it doesn't
1338 fit into the allocated bitfield for this insn,
1339 then promote it (ie this opcode does not match). */
1341 & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
1342 && ! check_operand (insn, operand, ex.X_add_number))
1344 input_line_pointer = hold;
1349 mn10300_insert_operand (&insn, &extension, operand,
1350 ex.X_add_number, (char *) NULL,
1355 /* If this operand can be promoted, then this opcode didn't
1356 match since we can't know if it needed promotion! */
1357 if (operand->flags & MN10300_OPERAND_PROMOTE)
1359 input_line_pointer = hold;
1364 /* We need to generate a fixup for this expression. */
1365 if (fc >= MAX_INSN_FIXUPS)
1366 as_fatal (_("too many fixups"));
1367 fixups[fc].exp = ex;
1368 fixups[fc].opindex = *opindex_ptr;
1369 fixups[fc].reloc = BFD_RELOC_UNUSED;
1375 str = input_line_pointer;
1376 input_line_pointer = hold;
1378 while (*str == ' ' || *str == ',')
1383 /* Make sure we used all the operands! */
1390 next_opcode = opcode + 1;
1391 if (!strcmp(next_opcode->name, opcode->name))
1393 opcode = next_opcode;
1397 as_bad ("%s", errmsg);
1403 while (isspace (*str))
1407 as_bad (_("junk at end of line: `%s'"), str);
1409 input_line_pointer = str;
1411 /* Determine the size of the instruction. */
1412 if (opcode->format == FMT_S0)
1415 if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
1418 if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
1421 /* start-sanitize-am33 */
1422 if (opcode->format == FMT_D6)
1425 if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
1428 if (opcode->format == FMT_D8)
1431 if (opcode->format == FMT_D9)
1433 /* end-sanitize-am33 */
1435 if (opcode->format == FMT_S4)
1438 if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
1441 if (opcode->format == FMT_D2)
1444 if (opcode->format == FMT_D4)
1447 if (relaxable && fc > 0)
1454 /* Handle bra specially. Basically treat it like jmp so
1455 that we automatically handle 8, 16 and 32 bit offsets
1456 correctly as well as jumps to an undefined address.
1458 It is also important to not treat it like other bCC
1459 instructions since the long forms of bra is different
1460 from other bCC instructions. */
1461 if (opcode->opcode == 0xca00)
1473 else if (size == 3 && opcode->opcode == 0xcc0000)
1475 /* bCC (uncommon cases) */
1479 f = frag_var (rs_machine_dependent, 8, 8 - size, type,
1480 fixups[0].exp.X_add_symbol,
1481 fixups[0].exp.X_add_number,
1482 (char *)fixups[0].opindex);
1484 /* This is pretty hokey. We basically just care about the
1485 opcode, so we have to write out the first word big endian.
1487 The exception is "call", which has two operands that we
1490 The first operand (the register list) happens to be in the
1491 first instruction word, and will be in the right place if
1492 we output the first word in big endian mode.
1494 The second operand (stack size) is in the extension word,
1495 and we want it to appear as the first character in the extension
1496 word (as it appears in memory). Luckily, writing the extension
1497 word in big endian format will do what we want. */
1498 number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
1501 number_to_chars_bigendian (f + 4, extension, 4);
1502 number_to_chars_bigendian (f + 8, 0, size - 8);
1505 number_to_chars_bigendian (f + 4, extension, size - 4);
1509 /* Allocate space for the instruction. */
1510 f = frag_more (size);
1512 /* Fill in bytes for the instruction. Note that opcode fields
1513 are written big-endian, 16 & 32bit immediates are written
1514 little endian. Egad. */
1515 if (opcode->format == FMT_S0
1516 || opcode->format == FMT_S1
1517 || opcode->format == FMT_D0
1518 /* start-sanitize-am33 */
1519 || opcode->format == FMT_D6
1520 || opcode->format == FMT_D7
1521 || opcode->format == FMT_D10
1522 /* end-sanitize-am33 */
1523 || opcode->format == FMT_D1)
1525 number_to_chars_bigendian (f, insn, size);
1527 else if (opcode->format == FMT_S2
1528 && opcode->opcode != 0xdf0000
1529 && opcode->opcode != 0xde0000)
1531 /* A format S2 instruction that is _not_ "ret" and "retf". */
1532 number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
1533 number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
1535 else if (opcode->format == FMT_S2)
1537 /* This must be a ret or retf, which is written entirely in
1538 big-endian format. */
1539 number_to_chars_bigendian (f, insn, 3);
1541 else if (opcode->format == FMT_S4
1542 && opcode->opcode != 0xdc000000)
1544 /* This must be a format S4 "call" instruction. What a pain. */
1545 unsigned long temp = (insn >> 8) & 0xffff;
1546 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1547 number_to_chars_littleendian (f + 1, temp, 2);
1548 number_to_chars_bigendian (f + 3, insn & 0xff, 1);
1549 number_to_chars_bigendian (f + 4, extension & 0xff, 1);
1551 else if (opcode->format == FMT_S4)
1553 /* This must be a format S4 "jmp" instruction. */
1554 unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
1555 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1556 number_to_chars_littleendian (f + 1, temp, 4);
1558 else if (opcode->format == FMT_S6)
1560 unsigned long temp = ((insn & 0xffffff) << 8)
1561 | ((extension >> 16) & 0xff);
1562 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1563 number_to_chars_littleendian (f + 1, temp, 4);
1564 number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
1565 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1567 else if (opcode->format == FMT_D2
1568 && opcode->opcode != 0xfaf80000
1569 && opcode->opcode != 0xfaf00000
1570 && opcode->opcode != 0xfaf40000)
1572 /* A format D2 instruction where the 16bit immediate is
1573 really a single 16bit value, not two 8bit values. */
1574 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1575 number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
1577 else if (opcode->format == FMT_D2)
1579 /* A format D2 instruction where the 16bit immediate
1580 is really two 8bit immediates. */
1581 number_to_chars_bigendian (f, insn, 4);
1583 else if (opcode->format == FMT_D4)
1585 unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
1586 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1587 number_to_chars_littleendian (f + 2, temp, 4);
1589 else if (opcode->format == FMT_D5)
1591 unsigned long temp = ((insn & 0xffff) << 16)
1592 | ((extension >> 8) & 0xffff);
1593 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1594 number_to_chars_littleendian (f + 2, temp, 4);
1595 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1597 /* start-sanitize-am33 */
1598 else if (opcode->format == FMT_D8)
1600 unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
1601 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1602 number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
1603 number_to_chars_littleendian (f + 4, temp >> 8, 2);
1605 else if (opcode->format == FMT_D9)
1607 unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
1608 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1609 number_to_chars_littleendian (f + 3, temp, 4);
1611 /* end-sanitize-am33 */
1613 /* Create any fixups. */
1614 for (i = 0; i < fc; i++)
1616 const struct mn10300_operand *operand;
1618 operand = &mn10300_operands[fixups[i].opindex];
1619 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1621 reloc_howto_type *reloc_howto;
1626 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1631 size = bfd_get_reloc_size (reloc_howto);
1633 if (size < 1 || size > 4)
1637 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1638 size, &fixups[i].exp,
1639 reloc_howto->pc_relative,
1644 int reloc, pcrel, reloc_size, offset;
1647 reloc = BFD_RELOC_NONE;
1648 /* How big is the reloc? Remember SPLIT relocs are
1649 implicitly 32bits. */
1650 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1652 /* start-sanitize-am33 */
1653 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1655 /* end-sanitize-am33 */
1657 reloc_size = operand->bits;
1659 /* Is the reloc pc-relative? */
1660 pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
1662 /* Gross. This disgusting hack is to make sure we
1663 get the right offset for the 16/32 bit reloc in
1664 "call" instructions. Basically they're a pain
1665 because the reloc isn't at the end of the instruction. */
1666 if ((size == 5 || size == 7)
1667 && (((insn >> 24) & 0xff) == 0xcd
1668 || ((insn >> 24) & 0xff) == 0xdd))
1671 /* Similarly for certain bit instructions which don't
1672 hav their 32bit reloc at the tail of the instruction. */
1674 && (((insn >> 16) & 0xffff) == 0xfe00
1675 || ((insn >> 16) & 0xffff) == 0xfe01
1676 || ((insn >> 16) & 0xffff) == 0xfe02))
1679 offset = size - reloc_size / 8;
1681 /* Choose a proper BFD relocation type. */
1684 if (reloc_size == 32)
1685 reloc = BFD_RELOC_32_PCREL;
1686 else if (reloc_size == 16)
1687 reloc = BFD_RELOC_16_PCREL;
1688 else if (reloc_size == 8)
1689 reloc = BFD_RELOC_8_PCREL;
1695 if (reloc_size == 32)
1696 reloc = BFD_RELOC_32;
1697 else if (reloc_size == 16)
1698 reloc = BFD_RELOC_16;
1699 else if (reloc_size == 8)
1700 reloc = BFD_RELOC_8;
1705 /* Convert the size of the reloc into what fix_new_exp wants. */
1706 reloc_size = reloc_size / 8;
1707 if (reloc_size == 8)
1709 else if (reloc_size == 16)
1711 else if (reloc_size == 32)
1714 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1715 reloc_size, &fixups[i].exp, pcrel,
1716 ((bfd_reloc_code_real_type) reloc));
1719 fixP->fx_offset += offset;
1726 /* if while processing a fixup, a reloc really needs to be created */
1727 /* then it is done here */
1730 tc_gen_reloc (seg, fixp)
1735 reloc = (arelent *) xmalloc (sizeof (arelent));
1737 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1738 if (reloc->howto == (reloc_howto_type *) NULL)
1740 as_bad_where (fixp->fx_file, fixp->fx_line,
1741 _("reloc %d not supported by object file format"),
1742 (int)fixp->fx_r_type);
1745 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1747 if (fixp->fx_addsy && fixp->fx_subsy)
1750 if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
1751 || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
1753 as_bad_where (fixp->fx_file, fixp->fx_line,
1754 "Difference of symbols in different sections is not supported");
1758 reloc->sym_ptr_ptr = &bfd_abs_symbol;
1759 reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
1760 - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
1764 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
1765 reloc->addend = fixp->fx_offset;
1771 md_estimate_size_before_relax (fragp, seg)
1775 if (fragp->fr_subtype == 0)
1777 if (fragp->fr_subtype == 3)
1779 if (fragp->fr_subtype == 6)
1781 if (!S_IS_DEFINED (fragp->fr_symbol)
1782 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1784 fragp->fr_subtype = 7;
1790 if (fragp->fr_subtype == 8)
1792 if (!S_IS_DEFINED (fragp->fr_symbol)
1793 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1795 fragp->fr_subtype = 9;
1801 if (fragp->fr_subtype == 10)
1803 if (!S_IS_DEFINED (fragp->fr_symbol)
1804 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1806 fragp->fr_subtype = 12;
1815 md_pcrel_from (fixp)
1818 return fixp->fx_frag->fr_address;
1820 if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy))
1822 /* The symbol is undefined. Let the linker figure it out. */
1825 return fixp->fx_frag->fr_address + fixp->fx_where;
1830 md_apply_fix3 (fixp, valuep, seg)
1835 /* We shouldn't ever get here because linkrelax is nonzero. */
1841 /* Insert an operand value into an instruction. */
1844 mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift)
1845 unsigned long *insnp;
1846 unsigned long *extensionp;
1847 const struct mn10300_operand *operand;
1853 /* No need to check 32bit operands for a bit. Note that
1854 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1855 if (operand->bits != 32
1856 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1862 bits = operand->bits;
1863 /* start-sanitize-am33 */
1864 if (operand->flags & MN10300_OPERAND_24BIT)
1866 /* end-sanitize-am33 */
1868 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1870 max = (1 << (bits - 1)) - 1;
1871 min = - (1 << (bits - 1));
1875 max = (1 << bits) - 1;
1882 if (test < (offsetT) min || test > (offsetT) max)
1885 _("operand out of range (%s not between %ld and %ld)");
1888 sprint_value (buf, test);
1889 if (file == (char *) NULL)
1890 as_warn (err, buf, min, max);
1892 as_warn_where (file, line, err, buf, min, max);
1896 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1898 *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
1899 *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
1902 /* start-sanitize-am33 */
1903 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1905 *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1);
1906 *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1))
1909 /* end-sanitize-am33 */
1910 else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
1912 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1913 << (operand->shift + shift));
1915 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1916 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1917 << (operand->shift + shift + operand->bits));
1921 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1922 << (operand->shift + shift));
1924 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1925 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1926 << (operand->shift + shift + operand->bits));
1930 static unsigned long
1931 check_operand (insn, operand, val)
1933 const struct mn10300_operand *operand;
1936 /* No need to check 32bit operands for a bit. Note that
1937 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1938 if (operand->bits != 32
1939 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1945 bits = operand->bits;
1946 /* start-sanitize-am33 */
1947 if (operand->flags & MN10300_OPERAND_24BIT)
1949 /* end-sanitize-am33 */
1951 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1953 max = (1 << (bits - 1)) - 1;
1954 min = - (1 << (bits - 1));
1958 max = (1 << bits) - 1;
1965 if (test < (offsetT) min || test > (offsetT) max)
1974 set_arch_mach (mach)
1977 if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, mach))
1978 as_warn (_("could not set architecture and machine"));
1980 current_machine = mach;