1 /* Morpho Technologies mRISC opcode support, for GNU Binutils. -*- C -*-
2 Copyright 2001, 2007, 2008, 2009 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 3 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,
22 MA 02110-1301, USA. */
25 /* Each section is delimited with start and end markers.
27 <arch>-opc.h additions use: "-- opc.h"
28 <arch>-opc.c additions use: "-- opc.c"
29 <arch>-asm.c additions use: "-- asm.c"
30 <arch>-dis.c additions use: "-- dis.c"
31 <arch>-ibd.h additions use: "-- ibd.h" */
35 /* Check applicability of instructions against machines. */
36 #define CGEN_VALIDATE_INSN_SUPPORTED
38 /* Allows reason codes to be output when assembler errors occur. */
39 #define CGEN_VERBOSE_ASSEMBLER_ERRORS
41 /* Override disassembly hashing - there are variable bits in the top
42 byte of these instructions. */
43 #define CGEN_DIS_HASH_SIZE 8
44 #define CGEN_DIS_HASH(buf, value) (((* (unsigned char *) (buf)) >> 5) % CGEN_DIS_HASH_SIZE)
46 #define CGEN_ASM_HASH_SIZE 127
47 #define CGEN_ASM_HASH(insn) mt_asm_hash (insn)
49 extern unsigned int mt_asm_hash (const char *);
51 extern int mt_cgen_insn_supported (CGEN_CPU_DESC, const CGEN_INSN *);
55 #include "safe-ctype.h"
57 /* Special check to ensure that instruction exists for given machine. */
60 mt_cgen_insn_supported (CGEN_CPU_DESC cd, const CGEN_INSN *insn)
62 int machs = CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_MACH);
64 /* No mach attribute? Assume it's supported for all machs. */
68 return ((machs & cd->machs) != 0);
71 /* A better hash function for instruction mnemonics. */
74 mt_asm_hash (const char* insn)
79 for (hash = 0; *m && ! ISSPACE (*m); m++)
80 hash = (hash * 23) ^ (0x1F & TOLOWER (*m));
82 /* printf ("%s %d\n", insn, (hash % CGEN_ASM_HASH_SIZE)); */
84 return hash % CGEN_ASM_HASH_SIZE;
89 /* Range checking for signed numbers. Returns 0 if acceptable
90 and 1 if the value is out of bounds for a signed quantity. */
93 signed_out_of_bounds (long val)
95 if ((val < -32768) || (val > 32767))
101 parse_loopsize (CGEN_CPU_DESC cd,
106 signed long * valuep = (signed long *) arg;
108 bfd_reloc_code_real_type code = BFD_RELOC_NONE;
109 enum cgen_parse_operand_result result_type;
112 /* Is it a control transfer instructions? */
113 if (opindex == (CGEN_OPERAND_TYPE) MT_OPERAND_LOOPSIZE)
115 code = BFD_RELOC_MT_PCINSN8;
116 errmsg = cgen_parse_address (cd, strp, opindex, code,
117 & result_type, & value);
126 parse_imm16 (CGEN_CPU_DESC cd,
131 signed long * valuep = (signed long *) arg;
133 enum cgen_parse_operand_result result_type;
134 bfd_reloc_code_real_type code = BFD_RELOC_NONE;
137 /* Is it a control transfer instructions? */
138 if (opindex == (CGEN_OPERAND_TYPE) MT_OPERAND_IMM16O)
140 code = BFD_RELOC_16_PCREL;
141 errmsg = cgen_parse_address (cd, strp, opindex, code,
142 & result_type, & value);
145 if (signed_out_of_bounds (value))
146 errmsg = _("Operand out of range. Must be between -32768 and 32767.");
152 /* If it's not a control transfer instruction, then
153 we have to check for %OP relocating operators. */
154 if (opindex == (CGEN_OPERAND_TYPE) MT_OPERAND_IMM16L)
156 else if (strncmp (*strp, "%hi16", 5) == 0)
159 code = BFD_RELOC_HI16;
161 else if (strncmp (*strp, "%lo16", 5) == 0)
164 code = BFD_RELOC_LO16;
167 /* If we found a %OP relocating operator, then parse it as an address.
168 If not, we need to parse it as an integer, either signed or unsigned
169 depending on which operand type we have. */
170 if (code != BFD_RELOC_NONE)
172 /* %OP relocating operator found. */
173 errmsg = cgen_parse_address (cd, strp, opindex, code,
174 & result_type, & value);
179 case (CGEN_PARSE_OPERAND_RESULT_NUMBER):
180 if (code == BFD_RELOC_HI16)
181 value = (value >> 16) & 0xFFFF;
182 else if (code == BFD_RELOC_LO16)
183 value = value & 0xFFFF;
185 errmsg = _("Biiiig Trouble in parse_imm16!");
188 case (CGEN_PARSE_OPERAND_RESULT_QUEUED):
189 /* No special processing for this case. */
193 errmsg = _("The percent-operator's operand is not a symbol");
201 /* Parse hex values like 0xffff as unsigned, and sign extend
203 int parse_signed = (opindex == (CGEN_OPERAND_TYPE)MT_OPERAND_IMM16);
205 if ((*strp)[0] == '0'
206 && ((*strp)[1] == 'x' || (*strp)[1] == 'X'))
209 /* No relocating operator. Parse as an number. */
212 /* Parse as as signed integer. */
214 errmsg = cgen_parse_signed_integer (cd, strp, opindex, valuep);
219 /* Manual range checking is needed for the signed case. */
220 if (*valuep & 0x8000)
221 value = 0xffff0000 | *valuep;
225 if (signed_out_of_bounds (value))
226 errmsg = _("Operand out of range. Must be between -32768 and 32767.");
227 /* Truncate to 16 bits. This is necessary
228 because cgen will have sign extended *valuep. */
235 /* MT_OPERAND_IMM16Z. Parse as an unsigned integer. */
236 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, (unsigned long *) valuep);
238 if (opindex == (CGEN_OPERAND_TYPE) MT_OPERAND_IMM16
240 && *valuep <= 0xffff)
250 parse_dup (CGEN_CPU_DESC cd,
253 unsigned long *valuep)
255 const char *errmsg = NULL;
257 if (strncmp (*strp, "dup", 3) == 0 || strncmp (*strp, "DUP", 3) == 0)
262 else if (strncmp (*strp, "xx", 2) == 0 || strncmp (*strp, "XX", 2) == 0)
268 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
275 parse_ball (CGEN_CPU_DESC cd,
278 unsigned long *valuep)
280 const char *errmsg = NULL;
282 if (strncmp (*strp, "all", 3) == 0 || strncmp (*strp, "ALL", 3) == 0)
287 else if (strncmp (*strp, "one", 3) == 0 || strncmp (*strp, "ONE", 3) == 0)
293 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
299 parse_xmode (CGEN_CPU_DESC cd,
302 unsigned long *valuep)
304 const char *errmsg = NULL;
306 if (strncmp (*strp, "pm", 2) == 0 || strncmp (*strp, "PM", 2) == 0)
311 else if (strncmp (*strp, "xm", 2) == 0 || strncmp (*strp, "XM", 2) == 0)
317 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
323 parse_rc (CGEN_CPU_DESC cd,
326 unsigned long *valuep)
328 const char *errmsg = NULL;
330 if (strncmp (*strp, "r", 1) == 0 || strncmp (*strp, "R", 1) == 0)
335 else if (strncmp (*strp, "c", 1) == 0 || strncmp (*strp, "C", 1) == 0)
341 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
347 parse_cbrb (CGEN_CPU_DESC cd,
350 unsigned long *valuep)
352 const char *errmsg = NULL;
354 if (strncmp (*strp, "rb", 2) == 0 || strncmp (*strp, "RB", 2) == 0)
359 else if (strncmp (*strp, "cb", 2) == 0 || strncmp (*strp, "CB", 2) == 0)
365 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
371 parse_rbbc (CGEN_CPU_DESC cd,
374 unsigned long *valuep)
376 const char *errmsg = NULL;
378 if (strncmp (*strp, "rt", 2) == 0 || strncmp (*strp, "RT", 2) == 0)
383 else if (strncmp (*strp, "br1", 3) == 0 || strncmp (*strp, "BR1", 3) == 0)
388 else if (strncmp (*strp, "br2", 3) == 0 || strncmp (*strp, "BR2", 3) == 0)
393 else if (strncmp (*strp, "cs", 2) == 0 || strncmp (*strp, "CS", 2) == 0)
399 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
405 parse_type (CGEN_CPU_DESC cd,
408 unsigned long *valuep)
410 const char *errmsg = NULL;
412 if (strncmp (*strp, "odd", 3) == 0 || strncmp (*strp, "ODD", 3) == 0)
417 else if (strncmp (*strp, "even", 4) == 0 || strncmp (*strp, "EVEN", 4) == 0)
422 else if (strncmp (*strp, "oe", 2) == 0 || strncmp (*strp, "OE", 2) == 0)
428 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
430 if ((errmsg == NULL) && (*valuep == 3))
431 errmsg = _("invalid operand. type may have values 0,1,2 only.");
437 static void print_dollarhex (CGEN_CPU_DESC, PTR, long, unsigned, bfd_vma, int);
438 static void print_pcrel (CGEN_CPU_DESC, PTR, long, unsigned, bfd_vma, int);
441 print_dollarhex (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
444 unsigned int attrs ATTRIBUTE_UNUSED,
445 bfd_vma pc ATTRIBUTE_UNUSED,
446 int length ATTRIBUTE_UNUSED)
448 disassemble_info *info = (disassemble_info *) dis_info;
450 info->fprintf_func (info->stream, "$%lx", value);
453 print_normal (cd, dis_info, value, attrs, pc, length);
457 print_pcrel (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
460 unsigned int attrs ATTRIBUTE_UNUSED,
461 bfd_vma pc ATTRIBUTE_UNUSED,
462 int length ATTRIBUTE_UNUSED)
464 print_address (cd, dis_info, value + pc, attrs, pc, length);