1 /* Morpho Technologies mRISC opcode support, for GNU Binutils. -*- C -*-
2 Copyright 2001 Free Software Foundation, Inc.
4 Contributed by Red Hat Inc; developed under contract from
7 This file is part of the GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
26 Each section is delimited with start and end markers.
28 <arch>-opc.h additions use: "-- opc.h"
29 <arch>-opc.c additions use: "-- opc.c"
30 <arch>-asm.c additions use: "-- asm.c"
31 <arch>-dis.c additions use: "-- dis.c"
32 <arch>-ibd.h additions use: "-- ibd.h"
37 /* Check applicability of instructions against machines. */
38 #define CGEN_VALIDATE_INSN_SUPPORTED
40 /* Allows reason codes to be output when assembler errors occur. */
41 #define CGEN_VERBOSE_ASSEMBLER_ERRORS
43 /* Override disassembly hashing - there are variable bits in the top
44 byte of these instructions. */
45 #define CGEN_DIS_HASH_SIZE 8
46 #define CGEN_DIS_HASH(buf, value) (((* (unsigned char *) (buf)) >> 5) % CGEN_DIS_HASH_SIZE)
48 #define CGEN_ASM_HASH_SIZE 127
49 #define CGEN_ASM_HASH(insn) ms1_asm_hash (insn)
51 extern unsigned int ms1_asm_hash (const char *);
53 extern int ms1_cgen_insn_supported (CGEN_CPU_DESC, const CGEN_INSN *);
57 #include "safe-ctype.h"
59 /* Special check to ensure that instruction exists for given machine. */
62 ms1_cgen_insn_supported (CGEN_CPU_DESC cd,
63 const CGEN_INSN *insn)
65 int machs = CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_MACH);
67 /* No mach attribute? Assume it's supported for all machs. */
71 return ((machs & cd->machs) != 0);
74 /* A better hash function for instruction mnemonics. */
77 ms1_asm_hash (const char* insn)
82 for (hash = 0; *m && ! ISSPACE (*m); m++)
83 hash = (hash * 23) ^ (0x1F & TOLOWER (*m));
85 /* printf ("%s %d\n", insn, (hash % CGEN_ASM_HASH_SIZE)); */
87 return hash % CGEN_ASM_HASH_SIZE;
92 static int signed_out_of_bounds (long);
93 static const char * parse_imm16 (CGEN_CPU_DESC, const char **, int, long *);
94 static const char * parse_dup (CGEN_CPU_DESC, const char **, int, long *);
95 static const char * parse_ball (CGEN_CPU_DESC, const char **, int, long *);
96 static const char * parse_xmode (CGEN_CPU_DESC, const char **, int, long *);
97 static const char * parse_rc (CGEN_CPU_DESC, const char **, int, long *);
98 static const char * parse_cbrb (CGEN_CPU_DESC, const char **, int, long *);
99 static const char * parse_rbbc (CGEN_CPU_DESC, const char **, int, long *);
100 static const char * parse_type (CGEN_CPU_DESC, const char **, int, long *);
102 /* Range checking for signed numbers. Returns 0 if acceptable
103 and 1 if the value is out of bounds for a signed quantity. */
106 signed_out_of_bounds (long val)
108 if ((val < -32768) || (val > 32767))
114 parse_imm16 (CGEN_CPU_DESC cd,
120 enum cgen_parse_operand_result result_type;
121 bfd_reloc_code_real_type code = BFD_RELOC_NONE;
124 /* Is it a control transfer instructions? */
125 if (opindex == (CGEN_OPERAND_TYPE) MS1_OPERAND_IMM16O)
127 code = BFD_RELOC_16_PCREL;
128 errmsg = cgen_parse_address (cd, strp, opindex, code,
129 & result_type, & value);
132 if (signed_out_of_bounds (value))
133 errmsg = _("Operand out of range. Must be between -32768 and 32767.");
139 /* If it's not a control transfer instruction, then
140 we have to check for %OP relocating operators. */
141 if (strncmp (*strp, "%hi16", 5) == 0)
144 code = BFD_RELOC_HI16;
146 else if (strncmp (*strp, "%lo16", 5) == 0)
149 code = BFD_RELOC_LO16;
152 /* If we found a %OP relocating operator, then parse it as an address.
153 If not, we need to parse it as an integer, either signed or unsigned
154 depending on which operand type we have. */
155 if (code != BFD_RELOC_NONE)
157 /* %OP relocating operator found. */
158 errmsg = cgen_parse_address (cd, strp, opindex, code,
159 & result_type, & value);
164 case (CGEN_PARSE_OPERAND_RESULT_NUMBER):
165 if (code == BFD_RELOC_HI16)
166 value = (value >> 16) & 0xFFFF;
167 else if (code == BFD_RELOC_LO16)
168 value = value & 0xFFFF;
170 errmsg = _("Biiiig Trouble in parse_imm16!");
173 case (CGEN_PARSE_OPERAND_RESULT_QUEUED):
174 /* No special processing for this case. */
178 errmsg = _("%operator operand is not a symbol");
186 /* Parse hex values like 0xffff as unsigned, and sign extend
188 int parse_signed = (opindex == (CGEN_OPERAND_TYPE)MS1_OPERAND_IMM16);
190 if ((*strp)[0] == '0'
191 && ((*strp)[1] == 'x' || (*strp)[1] == 'X'))
194 /* No relocating operator. Parse as an number. */
197 /* Parse as as signed integer. */
199 errmsg = cgen_parse_signed_integer (cd, strp, opindex, valuep);
204 /* Manual range checking is needed for the signed case. */
205 if (*valuep & 0x8000)
206 value = 0xffff0000 | *valuep;
210 if (signed_out_of_bounds (value))
211 errmsg = _("Operand out of range. Must be between -32768 and 32767.");
212 /* Truncate to 16 bits. This is necessary
213 because cgen will have sign extended *valuep. */
220 /* MS1_OPERAND_IMM16Z. Parse as an unsigned integer. */
221 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
223 if (opindex == (CGEN_OPERAND_TYPE)MS1_OPERAND_IMM16
225 && *valuep <= 0xffff)
235 parse_dup (CGEN_CPU_DESC cd,
240 const char *errmsg = NULL;
242 if (strncmp (*strp, "dup", 3) == 0 || strncmp (*strp, "DUP", 3) == 0)
247 else if (strncmp (*strp, "xx", 2) == 0 || strncmp (*strp, "XX", 2) == 0)
253 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
260 parse_ball (CGEN_CPU_DESC cd,
265 const char *errmsg = NULL;
267 if (strncmp (*strp, "all", 3) == 0 || strncmp (*strp, "ALL", 3) == 0)
272 else if (strncmp (*strp, "one", 3) == 0 || strncmp (*strp, "ONE", 3) == 0)
278 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
284 parse_xmode (CGEN_CPU_DESC cd,
289 const char *errmsg = NULL;
291 if (strncmp (*strp, "pm", 2) == 0 || strncmp (*strp, "PM", 2) == 0)
296 else if (strncmp (*strp, "xm", 2) == 0 || strncmp (*strp, "XM", 2) == 0)
302 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
308 parse_rc (CGEN_CPU_DESC cd,
313 const char *errmsg = NULL;
315 if (strncmp (*strp, "r", 1) == 0 || strncmp (*strp, "R", 1) == 0)
320 else if (strncmp (*strp, "c", 1) == 0 || strncmp (*strp, "C", 1) == 0)
326 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
332 parse_cbrb (CGEN_CPU_DESC cd,
337 const char *errmsg = NULL;
339 if (strncmp (*strp, "rb", 2) == 0 || strncmp (*strp, "RB", 2) == 0)
344 else if (strncmp (*strp, "cb", 2) == 0 || strncmp (*strp, "CB", 2) == 0)
350 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
356 parse_rbbc (CGEN_CPU_DESC cd,
361 const char *errmsg = NULL;
363 if (strncmp (*strp, "rt", 2) == 0 || strncmp (*strp, "RT", 2) == 0)
368 else if (strncmp (*strp, "br1", 3) == 0 || strncmp (*strp, "BR1", 3) == 0)
373 else if (strncmp (*strp, "br2", 3) == 0 || strncmp (*strp, "BR2", 3) == 0)
378 else if (strncmp (*strp, "cs", 2) == 0 || strncmp (*strp, "CS", 2) == 0)
384 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
390 parse_type (CGEN_CPU_DESC cd,
395 const char *errmsg = NULL;
397 if (strncmp (*strp, "odd", 3) == 0 || strncmp (*strp, "ODD", 3) == 0)
402 else if (strncmp (*strp, "even", 4) == 0 || strncmp (*strp, "EVEN", 4) == 0)
407 else if (strncmp (*strp, "oe", 2) == 0 || strncmp (*strp, "OE", 2) == 0)
413 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
415 if ((errmsg == NULL) && (*valuep == 3))
416 errmsg = _("invalid operand. type may have values 0,1,2 only.");
422 static void print_dollarhex (CGEN_CPU_DESC, PTR, long, unsigned, bfd_vma, int);
425 print_dollarhex (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
428 unsigned int attrs ATTRIBUTE_UNUSED,
429 bfd_vma pc ATTRIBUTE_UNUSED,
430 int length ATTRIBUTE_UNUSED)
432 disassemble_info *info = (disassemble_info *) dis_info;
434 info->fprintf_func (info->stream, "$%x", value);
437 print_normal (cd, dis_info, value, attrs, pc, length);