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[] =
179 #define R_REG_NAME_CNT (sizeof(r_registers) / sizeof(struct reg_name))
181 static const struct reg_name xr_registers[] =
205 #define XR_REG_NAME_CNT (sizeof(xr_registers) / sizeof(struct reg_name))
207 /* end-sanitize-am33 */
209 static const struct reg_name other_registers[] =
215 #define OTHER_REG_NAME_CNT (sizeof(other_registers) / sizeof(struct reg_name))
217 /* reg_name_search does a binary search of the given register table
218 to see if "name" is a valid regiter name. Returns the register
219 number from the array on success, or -1 on failure. */
222 reg_name_search (regs, regcount, name)
223 const struct reg_name *regs;
227 int middle, low, high;
235 middle = (low + high) / 2;
236 cmp = strcasecmp (name, regs[middle].name);
242 return regs[middle].value;
249 /* start-sanitize-am33 */
250 /* Summary of register_name().
252 * in: Input_line_pointer points to 1st char of operand.
254 * out: A expressionS.
255 * The operand may have been a register: in this case, X_op == O_register,
256 * X_add_number is set to the register number, and truth is returned.
257 * Input_line_pointer->(next non-blank) char after operand, or is in
258 * its original state.
261 r_register_name (expressionP)
262 expressionS *expressionP;
269 /* Find the spelling of the operand */
270 start = name = input_line_pointer;
272 c = get_symbol_end ();
273 reg_number = reg_name_search (r_registers, R_REG_NAME_CNT, name);
275 /* look to see if it's in the register table */
278 expressionP->X_op = O_register;
279 expressionP->X_add_number = reg_number;
281 /* make the rest nice */
282 expressionP->X_add_symbol = NULL;
283 expressionP->X_op_symbol = NULL;
284 *input_line_pointer = c; /* put back the delimiting char */
289 /* reset the line as if we had not done anything */
290 *input_line_pointer = c; /* put back the delimiting char */
291 input_line_pointer = start; /* reset input_line pointer */
296 /* Summary of register_name().
298 * in: Input_line_pointer points to 1st char of operand.
300 * out: A expressionS.
301 * The operand may have been a register: in this case, X_op == O_register,
302 * X_add_number is set to the register number, and truth is returned.
303 * Input_line_pointer->(next non-blank) char after operand, or is in
304 * its original state.
307 xr_register_name (expressionP)
308 expressionS *expressionP;
315 /* Find the spelling of the operand */
316 start = name = input_line_pointer;
318 c = get_symbol_end ();
319 reg_number = reg_name_search (xr_registers, XR_REG_NAME_CNT, name);
321 /* look to see if it's in the register table */
324 expressionP->X_op = O_register;
325 expressionP->X_add_number = reg_number;
327 /* make the rest nice */
328 expressionP->X_add_symbol = NULL;
329 expressionP->X_op_symbol = NULL;
330 *input_line_pointer = c; /* put back the delimiting char */
335 /* reset the line as if we had not done anything */
336 *input_line_pointer = c; /* put back the delimiting char */
337 input_line_pointer = start; /* reset input_line pointer */
341 /* end-sanitize-am33 */
343 /* Summary of register_name().
345 * in: Input_line_pointer points to 1st char of operand.
347 * out: A expressionS.
348 * The operand may have been a register: in this case, X_op == O_register,
349 * X_add_number is set to the register number, and truth is returned.
350 * Input_line_pointer->(next non-blank) char after operand, or is in
351 * its original state.
354 data_register_name (expressionP)
355 expressionS *expressionP;
362 /* Find the spelling of the operand */
363 start = name = input_line_pointer;
365 c = get_symbol_end ();
366 reg_number = reg_name_search (data_registers, DATA_REG_NAME_CNT, name);
368 /* look to see if it's in the register table */
371 expressionP->X_op = O_register;
372 expressionP->X_add_number = reg_number;
374 /* make the rest nice */
375 expressionP->X_add_symbol = NULL;
376 expressionP->X_op_symbol = NULL;
377 *input_line_pointer = c; /* put back the delimiting char */
382 /* reset the line as if we had not done anything */
383 *input_line_pointer = c; /* put back the delimiting char */
384 input_line_pointer = start; /* reset input_line pointer */
389 /* Summary of register_name().
391 * in: Input_line_pointer points to 1st char of operand.
393 * out: A expressionS.
394 * The operand may have been a register: in this case, X_op == O_register,
395 * X_add_number is set to the register number, and truth is returned.
396 * Input_line_pointer->(next non-blank) char after operand, or is in
397 * its original state.
400 address_register_name (expressionP)
401 expressionS *expressionP;
408 /* Find the spelling of the operand */
409 start = name = input_line_pointer;
411 c = get_symbol_end ();
412 reg_number = reg_name_search (address_registers, ADDRESS_REG_NAME_CNT, name);
414 /* look to see if it's in the register table */
417 expressionP->X_op = O_register;
418 expressionP->X_add_number = reg_number;
420 /* make the rest nice */
421 expressionP->X_add_symbol = NULL;
422 expressionP->X_op_symbol = NULL;
423 *input_line_pointer = c; /* put back the delimiting char */
428 /* reset the line as if we had not done anything */
429 *input_line_pointer = c; /* put back the delimiting char */
430 input_line_pointer = start; /* reset input_line pointer */
435 /* Summary of register_name().
437 * in: Input_line_pointer points to 1st char of operand.
439 * out: A expressionS.
440 * The operand may have been a register: in this case, X_op == O_register,
441 * X_add_number is set to the register number, and truth is returned.
442 * Input_line_pointer->(next non-blank) char after operand, or is in
443 * its original state.
446 other_register_name (expressionP)
447 expressionS *expressionP;
454 /* Find the spelling of the operand */
455 start = name = input_line_pointer;
457 c = get_symbol_end ();
458 reg_number = reg_name_search (other_registers, OTHER_REG_NAME_CNT, name);
460 /* look to see if it's in the register table */
463 expressionP->X_op = O_register;
464 expressionP->X_add_number = reg_number;
466 /* make the rest nice */
467 expressionP->X_add_symbol = NULL;
468 expressionP->X_op_symbol = NULL;
469 *input_line_pointer = c; /* put back the delimiting char */
474 /* reset the line as if we had not done anything */
475 *input_line_pointer = c; /* put back the delimiting char */
476 input_line_pointer = start; /* reset input_line pointer */
482 md_show_usage (stream)
485 fprintf(stream, _("MN10300 options:\n\
490 md_parse_option (c, arg)
498 md_undefined_symbol (name)
505 md_atof (type, litp, sizep)
511 LITTLENUM_TYPE words[4];
527 return "bad call to md_atof";
530 t = atof_ieee (input_line_pointer, type, words);
532 input_line_pointer = t;
536 for (i = prec - 1; i >= 0; i--)
538 md_number_to_chars (litp, (valueT) words[i], 2);
547 md_convert_frag (abfd, sec, fragP)
552 static unsigned long label_count = 0;
555 subseg_change (sec, 0);
556 if (fragP->fr_subtype == 0)
558 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
559 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
563 else if (fragP->fr_subtype == 1)
565 /* Reverse the condition of the first branch. */
566 int offset = fragP->fr_fix;
567 int opcode = fragP->fr_literal[offset] & 0xff;
604 fragP->fr_literal[offset] = opcode;
606 /* Create a fixup for the reversed conditional branch. */
607 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
608 fix_new (fragP, fragP->fr_fix + 1, 1,
609 symbol_new (buf, sec, 0, fragP->fr_next),
610 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
612 /* Now create the unconditional branch + fixup to the
614 fragP->fr_literal[offset + 2] = 0xcc;
615 fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
616 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
620 else if (fragP->fr_subtype == 2)
622 /* Reverse the condition of the first branch. */
623 int offset = fragP->fr_fix;
624 int opcode = fragP->fr_literal[offset] & 0xff;
661 fragP->fr_literal[offset] = opcode;
663 /* Create a fixup for the reversed conditional branch. */
664 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
665 fix_new (fragP, fragP->fr_fix + 1, 1,
666 symbol_new (buf, sec, 0, fragP->fr_next),
667 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
669 /* Now create the unconditional branch + fixup to the
671 fragP->fr_literal[offset + 2] = 0xdc;
672 fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
673 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
677 else if (fragP->fr_subtype == 3)
679 fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
680 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
684 else if (fragP->fr_subtype == 4)
686 /* Reverse the condition of the first branch. */
687 int offset = fragP->fr_fix;
688 int opcode = fragP->fr_literal[offset + 1] & 0xff;
707 fragP->fr_literal[offset + 1] = opcode;
709 /* Create a fixup for the reversed conditional branch. */
710 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
711 fix_new (fragP, fragP->fr_fix + 2, 1,
712 symbol_new (buf, sec, 0, fragP->fr_next),
713 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
715 /* Now create the unconditional branch + fixup to the
717 fragP->fr_literal[offset + 3] = 0xcc;
718 fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
719 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
723 else if (fragP->fr_subtype == 5)
725 /* Reverse the condition of the first branch. */
726 int offset = fragP->fr_fix;
727 int opcode = fragP->fr_literal[offset + 1] & 0xff;
743 fragP->fr_literal[offset + 1] = opcode;
745 /* Create a fixup for the reversed conditional branch. */
746 sprintf (buf, ".%s_%d", FAKE_LABEL_NAME, label_count++);
747 fix_new (fragP, fragP->fr_fix + 2, 1,
748 symbol_new (buf, sec, 0, fragP->fr_next),
749 fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
751 /* Now create the unconditional branch + fixup to the
753 fragP->fr_literal[offset + 3] = 0xdc;
754 fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
755 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
759 else if (fragP->fr_subtype == 6)
761 int offset = fragP->fr_fix;
762 fragP->fr_literal[offset] = 0xcd;
763 fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
764 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
768 else if (fragP->fr_subtype == 7)
770 int offset = fragP->fr_fix;
771 fragP->fr_literal[offset] = 0xdd;
772 fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
773 fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
775 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
776 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
780 else if (fragP->fr_subtype == 8)
782 int offset = fragP->fr_fix;
783 fragP->fr_literal[offset] = 0xfa;
784 fragP->fr_literal[offset + 1] = 0xff;
785 fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
786 fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
790 else if (fragP->fr_subtype == 9)
792 int offset = fragP->fr_fix;
793 fragP->fr_literal[offset] = 0xfc;
794 fragP->fr_literal[offset + 1] = 0xff;
796 fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
797 fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
801 else if (fragP->fr_subtype == 10)
803 fragP->fr_literal[fragP->fr_fix] = 0xca;
804 fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
805 fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
809 else if (fragP->fr_subtype == 11)
811 int offset = fragP->fr_fix;
812 fragP->fr_literal[offset] = 0xcc;
814 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
815 fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
819 else if (fragP->fr_subtype == 12)
821 int offset = fragP->fr_fix;
822 fragP->fr_literal[offset] = 0xdc;
824 fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
825 fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
834 md_section_align (seg, addr)
838 int align = bfd_get_section_alignment (stdoutput, seg);
839 return ((addr + (1 << align) - 1) & (-1 << align));
845 char *prev_name = "";
846 register const struct mn10300_opcode *op;
848 mn10300_hash = hash_new();
850 /* Insert unique names into hash table. The MN10300 instruction set
851 has many identical opcode names that have different opcodes based
852 on the operands. This hash table then provides a quick index to
853 the first opcode with a particular name in the opcode table. */
855 op = mn10300_opcodes;
858 if (strcmp (prev_name, op->name))
860 prev_name = (char *) op->name;
861 hash_insert (mn10300_hash, op->name, (char *) op);
866 /* This is both a simplification (we don't have to write md_apply_fix)
867 and support for future optimizations (branch shortening and similar
868 stuff in the linker. */
877 struct mn10300_opcode *opcode;
878 struct mn10300_opcode *next_opcode;
879 const unsigned char *opindex_ptr;
880 int next_opindex, relaxable;
881 unsigned long insn, extension, size = 0;
886 /* Get the opcode. */
887 for (s = str; *s != '\0' && ! isspace (*s); s++)
892 /* find the first opcode with the proper name */
893 opcode = (struct mn10300_opcode *)hash_find (mn10300_hash, str);
896 as_bad (_("Unrecognized opcode: `%s'"), str);
901 while (isspace (*str))
904 input_line_pointer = str;
908 const char *errmsg = NULL;
917 insn = opcode->opcode;
919 for (op_idx = 1, opindex_ptr = opcode->operands;
921 opindex_ptr++, op_idx++)
923 const struct mn10300_operand *operand;
926 if (next_opindex == 0)
928 operand = &mn10300_operands[*opindex_ptr];
932 operand = &mn10300_operands[next_opindex];
938 while (*str == ' ' || *str == ',')
941 if (operand->flags & MN10300_OPERAND_RELAX)
944 /* Gather the operand. */
945 hold = input_line_pointer;
946 input_line_pointer = str;
948 if (operand->flags & MN10300_OPERAND_PAREN)
950 if (*input_line_pointer != ')' && *input_line_pointer != '(')
952 input_line_pointer = hold;
956 input_line_pointer++;
959 /* See if we can match the operands. */
960 else if (operand->flags & MN10300_OPERAND_DREG)
962 if (!data_register_name (&ex))
964 input_line_pointer = hold;
969 else if (operand->flags & MN10300_OPERAND_AREG)
971 if (!address_register_name (&ex))
973 input_line_pointer = hold;
978 else if (operand->flags & MN10300_OPERAND_SP)
980 char *start = input_line_pointer;
981 char c = get_symbol_end ();
983 if (strcasecmp (start, "sp") != 0)
985 *input_line_pointer = c;
986 input_line_pointer = hold;
990 *input_line_pointer = c;
993 /* start-sanitize-am33 */
994 else if (operand->flags & MN10300_OPERAND_RREG)
996 if (!r_register_name (&ex))
998 input_line_pointer = hold;
1003 else if (operand->flags & MN10300_OPERAND_XRREG)
1005 if (!xr_register_name (&ex))
1007 input_line_pointer = hold;
1012 else if (operand->flags & MN10300_OPERAND_USP)
1014 char *start = input_line_pointer;
1015 char c = get_symbol_end ();
1017 if (strcasecmp (start, "usp") != 0)
1019 *input_line_pointer = c;
1020 input_line_pointer = hold;
1024 *input_line_pointer = c;
1027 else if (operand->flags & MN10300_OPERAND_SSP)
1029 char *start = input_line_pointer;
1030 char c = get_symbol_end ();
1032 if (strcasecmp (start, "ssp") != 0)
1034 *input_line_pointer = c;
1035 input_line_pointer = hold;
1039 *input_line_pointer = c;
1042 else if (operand->flags & MN10300_OPERAND_MSP)
1044 char *start = input_line_pointer;
1045 char c = get_symbol_end ();
1047 if (strcasecmp (start, "msp") != 0)
1049 *input_line_pointer = c;
1050 input_line_pointer = hold;
1054 *input_line_pointer = c;
1057 else if (operand->flags & MN10300_OPERAND_PC)
1059 char *start = input_line_pointer;
1060 char c = get_symbol_end ();
1062 if (strcasecmp (start, "pc") != 0)
1064 *input_line_pointer = c;
1065 input_line_pointer = hold;
1069 *input_line_pointer = c;
1072 else if (operand->flags & MN10300_OPERAND_EPSW)
1074 char *start = input_line_pointer;
1075 char c = get_symbol_end ();
1077 if (strcasecmp (start, "epsw") != 0)
1079 *input_line_pointer = c;
1080 input_line_pointer = hold;
1084 *input_line_pointer = c;
1087 else if (operand->flags & MN10300_OPERAND_PLUS)
1089 if (*input_line_pointer != '+')
1091 input_line_pointer = hold;
1095 input_line_pointer++;
1098 /* end-sanitize-am33 */
1099 else if (operand->flags & MN10300_OPERAND_PSW)
1101 char *start = input_line_pointer;
1102 char c = get_symbol_end ();
1104 if (strcasecmp (start, "psw") != 0)
1106 *input_line_pointer = c;
1107 input_line_pointer = hold;
1111 *input_line_pointer = c;
1114 else if (operand->flags & MN10300_OPERAND_MDR)
1116 char *start = input_line_pointer;
1117 char c = get_symbol_end ();
1119 if (strcasecmp (start, "mdr") != 0)
1121 *input_line_pointer = c;
1122 input_line_pointer = hold;
1126 *input_line_pointer = c;
1129 else if (operand->flags & MN10300_OPERAND_REG_LIST)
1131 unsigned int value = 0;
1132 if (*input_line_pointer != '[')
1134 input_line_pointer = hold;
1140 input_line_pointer++;
1142 /* We used to reject a null register list here; however,
1143 we accept it now so the compiler can emit "call" instructions
1144 for all calls to named functions.
1146 The linker can then fill in the appropriate bits for the
1147 register list and stack size or change the instruction
1148 into a "calls" if using "call" is not profitable. */
1149 while (*input_line_pointer != ']')
1154 if (*input_line_pointer == ',')
1155 input_line_pointer++;
1157 start = input_line_pointer;
1158 c = get_symbol_end ();
1160 if (strcasecmp (start, "d2") == 0)
1163 *input_line_pointer = c;
1165 else if (strcasecmp (start, "d3") == 0)
1168 *input_line_pointer = c;
1170 else if (strcasecmp (start, "a2") == 0)
1173 *input_line_pointer = c;
1175 else if (strcasecmp (start, "a3") == 0)
1178 *input_line_pointer = c;
1180 else if (strcasecmp (start, "other") == 0)
1183 *input_line_pointer = c;
1185 /* start-sanitize-am33 */
1186 else if (strcasecmp (start, "exreg0") == 0)
1189 *input_line_pointer = c;
1191 else if (strcasecmp (start, "exreg1") == 0)
1194 *input_line_pointer = c;
1196 else if (strcasecmp (start, "exother") == 0)
1199 *input_line_pointer = c;
1201 else if (strcasecmp (start, "all") == 0)
1204 *input_line_pointer = c;
1206 /* end-sanitize-am33 */
1209 input_line_pointer = hold;
1214 input_line_pointer++;
1215 mn10300_insert_operand (&insn, &extension, operand,
1216 value, (char *) NULL, 0, 0);
1220 else if (data_register_name (&ex))
1222 input_line_pointer = hold;
1226 else if (address_register_name (&ex))
1228 input_line_pointer = hold;
1232 else if (other_register_name (&ex))
1234 input_line_pointer = hold;
1238 else if (*str == ')' || *str == '(')
1240 input_line_pointer = hold;
1252 errmsg = _("illegal operand");
1255 errmsg = _("missing operand");
1261 mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
1262 /* start-sanitize-am33 */
1263 mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
1264 /* end-sanitize-am33 */
1265 if ((operand->flags & mask) == 0)
1267 input_line_pointer = hold;
1272 if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
1274 else if (opcode->format == FMT_D2
1275 || opcode->format == FMT_D4
1276 || opcode->format == FMT_S2
1277 || opcode->format == FMT_S4
1278 || opcode->format == FMT_S6
1279 || opcode->format == FMT_D5)
1281 /* start-sanitize-am33 */
1282 else if (opcode->format == FMT_D7)
1284 else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
1286 /* end-sanitize-am33 */
1290 mn10300_insert_operand (&insn, &extension, operand,
1291 ex.X_add_number, (char *) NULL,
1298 /* If this operand can be promoted, and it doesn't
1299 fit into the allocated bitfield for this insn,
1300 then promote it (ie this opcode does not match). */
1302 & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
1303 && ! check_operand (insn, operand, ex.X_add_number))
1305 input_line_pointer = hold;
1310 mn10300_insert_operand (&insn, &extension, operand,
1311 ex.X_add_number, (char *) NULL,
1316 /* If this operand can be promoted, then this opcode didn't
1317 match since we can't know if it needed promotion! */
1318 if (operand->flags & MN10300_OPERAND_PROMOTE)
1320 input_line_pointer = hold;
1325 /* We need to generate a fixup for this expression. */
1326 if (fc >= MAX_INSN_FIXUPS)
1327 as_fatal (_("too many fixups"));
1328 fixups[fc].exp = ex;
1329 fixups[fc].opindex = *opindex_ptr;
1330 fixups[fc].reloc = BFD_RELOC_UNUSED;
1336 str = input_line_pointer;
1337 input_line_pointer = hold;
1339 while (*str == ' ' || *str == ',')
1344 /* Make sure we used all the operands! */
1351 next_opcode = opcode + 1;
1352 if (!strcmp(next_opcode->name, opcode->name))
1354 opcode = next_opcode;
1358 as_bad ("%s", errmsg);
1364 while (isspace (*str))
1368 as_bad (_("junk at end of line: `%s'"), str);
1370 input_line_pointer = str;
1372 /* Determine the size of the instruction. */
1373 if (opcode->format == FMT_S0)
1376 if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
1379 if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
1382 /* start-sanitize-am33 */
1383 if (opcode->format == FMT_D6)
1386 if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
1389 if (opcode->format == FMT_D8)
1392 if (opcode->format == FMT_D9)
1394 /* end-sanitize-am33 */
1396 if (opcode->format == FMT_S4)
1399 if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
1402 if (opcode->format == FMT_D2)
1405 if (opcode->format == FMT_D4)
1408 if (relaxable && fc > 0)
1415 /* Handle bra specially. Basically treat it like jmp so
1416 that we automatically handle 8, 16 and 32 bit offsets
1417 correctly as well as jumps to an undefined address.
1419 It is also important to not treat it like other bCC
1420 instructions since the long forms of bra is different
1421 from other bCC instructions. */
1422 if (opcode->opcode == 0xca00)
1434 else if (size == 3 && opcode->opcode == 0xcc0000)
1436 /* bCC (uncommon cases) */
1440 f = frag_var (rs_machine_dependent, 8, 8 - size, type,
1441 fixups[0].exp.X_add_symbol,
1442 fixups[0].exp.X_add_number,
1443 (char *)fixups[0].opindex);
1445 /* This is pretty hokey. We basically just care about the
1446 opcode, so we have to write out the first word big endian.
1448 The exception is "call", which has two operands that we
1451 The first operand (the register list) happens to be in the
1452 first instruction word, and will be in the right place if
1453 we output the first word in big endian mode.
1455 The second operand (stack size) is in the extension word,
1456 and we want it to appear as the first character in the extension
1457 word (as it appears in memory). Luckily, writing the extension
1458 word in big endian format will do what we want. */
1459 number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
1462 number_to_chars_bigendian (f + 4, extension, 4);
1463 number_to_chars_bigendian (f + 8, 0, size - 8);
1466 number_to_chars_bigendian (f + 4, extension, size - 4);
1470 /* Allocate space for the instruction. */
1471 f = frag_more (size);
1473 /* Fill in bytes for the instruction. Note that opcode fields
1474 are written big-endian, 16 & 32bit immediates are written
1475 little endian. Egad. */
1476 if (opcode->format == FMT_S0
1477 || opcode->format == FMT_S1
1478 || opcode->format == FMT_D0
1479 /* start-sanitize-am33 */
1480 || opcode->format == FMT_D6
1481 || opcode->format == FMT_D7
1482 || opcode->format == FMT_D10
1483 /* end-sanitize-am33 */
1484 || opcode->format == FMT_D1)
1486 number_to_chars_bigendian (f, insn, size);
1488 else if (opcode->format == FMT_S2
1489 && opcode->opcode != 0xdf0000
1490 && opcode->opcode != 0xde0000)
1492 /* A format S2 instruction that is _not_ "ret" and "retf". */
1493 number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
1494 number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
1496 else if (opcode->format == FMT_S2)
1498 /* This must be a ret or retf, which is written entirely in
1499 big-endian format. */
1500 number_to_chars_bigendian (f, insn, 3);
1502 else if (opcode->format == FMT_S4
1503 && opcode->opcode != 0xdc000000)
1505 /* This must be a format S4 "call" instruction. What a pain. */
1506 unsigned long temp = (insn >> 8) & 0xffff;
1507 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1508 number_to_chars_littleendian (f + 1, temp, 2);
1509 number_to_chars_bigendian (f + 3, insn & 0xff, 1);
1510 number_to_chars_bigendian (f + 4, extension & 0xff, 1);
1512 else if (opcode->format == FMT_S4)
1514 /* This must be a format S4 "jmp" instruction. */
1515 unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
1516 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1517 number_to_chars_littleendian (f + 1, temp, 4);
1519 else if (opcode->format == FMT_S6)
1521 unsigned long temp = ((insn & 0xffffff) << 8)
1522 | ((extension >> 16) & 0xff);
1523 number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1524 number_to_chars_littleendian (f + 1, temp, 4);
1525 number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
1526 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1528 else if (opcode->format == FMT_D2
1529 && opcode->opcode != 0xfaf80000
1530 && opcode->opcode != 0xfaf00000
1531 && opcode->opcode != 0xfaf40000)
1533 /* A format D2 instruction where the 16bit immediate is
1534 really a single 16bit value, not two 8bit values. */
1535 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1536 number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
1538 else if (opcode->format == FMT_D2)
1540 /* A format D2 instruction where the 16bit immediate
1541 is really two 8bit immediates. */
1542 number_to_chars_bigendian (f, insn, 4);
1544 else if (opcode->format == FMT_D4)
1546 unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
1547 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1548 number_to_chars_littleendian (f + 2, temp, 4);
1550 else if (opcode->format == FMT_D5)
1552 unsigned long temp = ((insn & 0xffff) << 16)
1553 | ((extension >> 8) & 0xffff);
1554 number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
1555 number_to_chars_littleendian (f + 2, temp, 4);
1556 number_to_chars_bigendian (f + 6, extension & 0xff, 1);
1558 /* start-sanitize-am33 */
1559 else if (opcode->format == FMT_D8)
1561 unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
1562 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1563 number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
1564 number_to_chars_littleendian (f + 4, temp >> 8, 2);
1566 else if (opcode->format == FMT_D9)
1568 unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
1569 number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
1570 number_to_chars_littleendian (f + 3, temp, 4);
1572 /* end-sanitize-am33 */
1574 /* Create any fixups. */
1575 for (i = 0; i < fc; i++)
1577 const struct mn10300_operand *operand;
1579 operand = &mn10300_operands[fixups[i].opindex];
1580 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1582 reloc_howto_type *reloc_howto;
1587 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1592 size = bfd_get_reloc_size (reloc_howto);
1594 if (size < 1 || size > 4)
1598 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1599 size, &fixups[i].exp,
1600 reloc_howto->pc_relative,
1605 int reloc, pcrel, reloc_size, offset;
1608 reloc = BFD_RELOC_NONE;
1609 /* How big is the reloc? Remember SPLIT relocs are
1610 implicitly 32bits. */
1611 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1613 /* start-sanitize-am33 */
1614 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1616 /* end-sanitize-am33 */
1618 reloc_size = operand->bits;
1620 /* Is the reloc pc-relative? */
1621 pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
1623 /* Gross. This disgusting hack is to make sure we
1624 get the right offset for the 16/32 bit reloc in
1625 "call" instructions. Basically they're a pain
1626 because the reloc isn't at the end of the instruction. */
1627 if ((size == 5 || size == 7)
1628 && (((insn >> 24) & 0xff) == 0xcd
1629 || ((insn >> 24) & 0xff) == 0xdd))
1632 /* Similarly for certain bit instructions which don't
1633 hav their 32bit reloc at the tail of the instruction. */
1635 && (((insn >> 16) & 0xffff) == 0xfe00
1636 || ((insn >> 16) & 0xffff) == 0xfe01
1637 || ((insn >> 16) & 0xffff) == 0xfe02))
1640 offset = size - reloc_size / 8;
1642 /* Choose a proper BFD relocation type. */
1645 if (reloc_size == 32)
1646 reloc = BFD_RELOC_32_PCREL;
1647 else if (reloc_size == 16)
1648 reloc = BFD_RELOC_16_PCREL;
1649 else if (reloc_size == 8)
1650 reloc = BFD_RELOC_8_PCREL;
1656 if (reloc_size == 32)
1657 reloc = BFD_RELOC_32;
1658 else if (reloc_size == 16)
1659 reloc = BFD_RELOC_16;
1660 else if (reloc_size == 8)
1661 reloc = BFD_RELOC_8;
1666 /* Convert the size of the reloc into what fix_new_exp wants. */
1667 reloc_size = reloc_size / 8;
1668 if (reloc_size == 8)
1670 else if (reloc_size == 16)
1672 else if (reloc_size == 32)
1675 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
1676 reloc_size, &fixups[i].exp, pcrel,
1677 ((bfd_reloc_code_real_type) reloc));
1680 fixP->fx_offset += offset;
1687 /* if while processing a fixup, a reloc really needs to be created */
1688 /* then it is done here */
1691 tc_gen_reloc (seg, fixp)
1696 reloc = (arelent *) xmalloc (sizeof (arelent));
1698 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1699 if (reloc->howto == (reloc_howto_type *) NULL)
1701 as_bad_where (fixp->fx_file, fixp->fx_line,
1702 _("reloc %d not supported by object file format"),
1703 (int)fixp->fx_r_type);
1706 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1708 if (fixp->fx_addsy && fixp->fx_subsy)
1711 if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
1712 || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
1714 as_bad_where (fixp->fx_file, fixp->fx_line,
1715 "Difference of symbols in different sections is not supported");
1719 reloc->sym_ptr_ptr = &bfd_abs_symbol;
1720 reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
1721 - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
1725 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
1726 reloc->addend = fixp->fx_offset;
1732 md_estimate_size_before_relax (fragp, seg)
1736 if (fragp->fr_subtype == 0)
1738 if (fragp->fr_subtype == 3)
1740 if (fragp->fr_subtype == 6)
1742 if (!S_IS_DEFINED (fragp->fr_symbol)
1743 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1745 fragp->fr_subtype = 7;
1751 if (fragp->fr_subtype == 8)
1753 if (!S_IS_DEFINED (fragp->fr_symbol)
1754 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1756 fragp->fr_subtype = 9;
1762 if (fragp->fr_subtype == 10)
1764 if (!S_IS_DEFINED (fragp->fr_symbol)
1765 || seg != S_GET_SEGMENT (fragp->fr_symbol))
1767 fragp->fr_subtype = 12;
1776 md_pcrel_from (fixp)
1779 return fixp->fx_frag->fr_address;
1781 if (fixp->fx_addsy != (symbolS *) NULL && ! S_IS_DEFINED (fixp->fx_addsy))
1783 /* The symbol is undefined. Let the linker figure it out. */
1786 return fixp->fx_frag->fr_address + fixp->fx_where;
1791 md_apply_fix3 (fixp, valuep, seg)
1796 /* We shouldn't ever get here because linkrelax is nonzero. */
1802 /* Insert an operand value into an instruction. */
1805 mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift)
1806 unsigned long *insnp;
1807 unsigned long *extensionp;
1808 const struct mn10300_operand *operand;
1814 /* No need to check 32bit operands for a bit. Note that
1815 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1816 if (operand->bits != 32
1817 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1823 bits = operand->bits;
1824 /* start-sanitize-am33 */
1825 if (operand->flags & MN10300_OPERAND_24BIT)
1827 /* end-sanitize-am33 */
1829 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1831 max = (1 << (bits - 1)) - 1;
1832 min = - (1 << (bits - 1));
1836 max = (1 << bits) - 1;
1843 if (test < (offsetT) min || test > (offsetT) max)
1846 _("operand out of range (%s not between %ld and %ld)");
1849 sprint_value (buf, test);
1850 if (file == (char *) NULL)
1851 as_warn (err, buf, min, max);
1853 as_warn_where (file, line, err, buf, min, max);
1857 if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1859 *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
1860 *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
1863 /* start-sanitize-am33 */
1864 else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1866 *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1);
1867 *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1))
1870 /* end-sanitize-am33 */
1871 else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
1873 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1874 << (operand->shift + shift));
1876 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1877 *insnp |= (((long) val & ((1 << operand->bits) - 1))
1878 << (operand->shift + shift + operand->bits));
1882 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1883 << (operand->shift + shift));
1885 if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1886 *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1887 << (operand->shift + shift + operand->bits));
1891 static unsigned long
1892 check_operand (insn, operand, val)
1894 const struct mn10300_operand *operand;
1897 /* No need to check 32bit operands for a bit. Note that
1898 MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1899 if (operand->bits != 32
1900 && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1906 bits = operand->bits;
1907 /* start-sanitize-am33 */
1908 if (operand->flags & MN10300_OPERAND_24BIT)
1910 /* end-sanitize-am33 */
1912 if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1914 max = (1 << (bits - 1)) - 1;
1915 min = - (1 << (bits - 1));
1919 max = (1 << bits) - 1;
1926 if (test < (offsetT) min || test > (offsetT) max)