1 /* Adapteva epiphany opcode support. -*- C -*-
3 Copyright 2009, 2011 Free Software Foundation, Inc.
5 Contributed by Embecosm on behalf of Adapteva, Inc.
7 This file is part of the GNU Binutils and of GDB.
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 /* enumerate relaxation types for gas. */
36 typedef enum epiphany_relax_types
38 EPIPHANY_RELAX_NONE=0,
39 EPIPHANY_RELAX_NEED_RELAXING,
41 EPIPHANY_RELAX_BRANCH_SHORT, /* Fits into +127..-128 */
42 EPIPHANY_RELAX_BRANCH_LONG, /* b/bl/b<cond> +-2*16 */
44 EPIPHANY_RELAX_ARITH_SIMM3, /* add/sub -7..3 */
45 EPIPHANY_RELAX_ARITH_SIMM11, /* add/sub -2**11-1 .. 2**10-1 */
47 EPIPHANY_RELAX_MOV_IMM8, /* mov r,imm8 */
48 EPIPHANY_RELAX_MOV_IMM16, /* mov r,imm16 */
50 EPIPHANY_RELAX_LDST_IMM3, /* (ldr|str)* r,[r,disp3] */
51 EPIPHANY_RELAX_LDST_IMM11 /* (ldr|str)* r,[r,disp11] */
53 } EPIPHANY_RELAX_TYPES;
55 /* Override disassembly hashing... */
57 /* Can only depend on instruction having 4 decode bits which gets us to the
58 major groups of 16/32 instructions. */
59 #undef CGEN_DIS_HASH_SIZE
62 /* hash code on the 4 LSBs */
63 #define CGEN_DIS_HASH_SIZE 16
65 #define CGEN_DIS_HASH(buf, value) ((*buf) & 0xf)
67 #define CGEN_DIS_HASH_SIZE 1
68 #define CGEN_DIS_HASH(buf, value) 0
71 extern const char * parse_shortregs (CGEN_CPU_DESC cd,
73 CGEN_KEYWORD * keywords,
76 extern const char * parse_branch_addr (CGEN_CPU_DESC cd,
80 enum cgen_parse_operand_result * resultp,
83 /* Allows reason codes to be output when assembler errors occur. */
84 #define CGEN_VERBOSE_ASSEMBLER_ERRORS
93 parse_shortregs (CGEN_CPU_DESC cd,
95 CGEN_KEYWORD * keywords,
100 /* Parse register. */
101 errmsg = cgen_parse_keyword (cd, strp, keywords, regno);
107 errmsg = _("register unavailable for short instructions");
112 static const char * parse_simm_not_reg (CGEN_CPU_DESC, const char **, int,
116 parse_uimm_not_reg (CGEN_CPU_DESC cd,
119 unsigned long * valuep)
121 long * svalp = (void *) valuep;
122 return parse_simm_not_reg (cd, strp, opindex, svalp);
125 /* Handle simm3/simm11/imm3/imm12. */
128 parse_simm_not_reg (CGEN_CPU_DESC cd,
140 case EPIPHANY_OPERAND_SIMM3:
141 sign = 1; bits = 3; break;
142 case EPIPHANY_OPERAND_SIMM11:
143 sign = 1; bits = 11; break;
144 case EPIPHANY_OPERAND_DISP3:
145 sign = 0; bits = 3; break;
146 case EPIPHANY_OPERAND_DISP11:
147 /* Load/store displacement is a sign-magnitude 12 bit value. */
148 sign = 0; bits = 11; break;
151 /* First try to parse as a register name and reject the operand. */
152 errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names,valuep);
154 return _("register name used as immediate value");
156 errmsg = (sign ? cgen_parse_signed_integer (cd, strp, opindex, valuep)
157 : cgen_parse_unsigned_integer (cd, strp, opindex,
158 (unsigned long *) valuep));
163 errmsg = cgen_validate_signed_integer (*valuep,
164 -((1L << bits) - 1), (1 << (bits - 1)) - 1);
166 errmsg = cgen_validate_unsigned_integer (*valuep, 0, (1L << bits) - 1);
172 parse_postindex (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
174 int opindex ATTRIBUTE_UNUSED,
175 unsigned long *valuep)
178 ++*strp; /* Skip leading hashes. */
185 else if (**strp == '+')
197 parse_imm8 (CGEN_CPU_DESC cd,
200 bfd_reloc_code_real_type code,
201 enum cgen_parse_operand_result * result_type,
205 enum cgen_parse_operand_result rt;
211 code = BFD_RELOC_NONE;
213 if (!cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_gr_names, &dummyval)
214 || !cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_cr_names,
216 /* Don't treat "mov ip,ip" as a move-immediate. */
217 return _("register source in immediate move");
219 errmsg = cgen_parse_address (cd, strp, opindex, code, result_type, valuep);
223 if (*result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
224 errmsg = cgen_validate_unsigned_integer (*valuep, 0, 0xff);
226 errmsg = _("byte relocation unsupported");
232 static const char * MISSING_CLOSE_PARENTHESIS = N_("missing `)'");
235 parse_imm16 (CGEN_CPU_DESC cd,
238 bfd_reloc_code_real_type code ATTRIBUTE_UNUSED,
239 enum cgen_parse_operand_result * result_type,
243 enum cgen_parse_operand_result rt;
249 if (strncasecmp (*strp, "%high(", 6) == 0)
252 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_EPIPHANY_HIGH,
253 result_type, valuep);
255 return MISSING_CLOSE_PARENTHESIS;
259 else if (strncasecmp (*strp, "%low(", 5) == 0)
262 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_EPIPHANY_LOW,
263 result_type, valuep);
265 return MISSING_CLOSE_PARENTHESIS;
268 else if (!cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_gr_names,
270 || !cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_cr_names,
272 /* Don't treat "mov ip,ip" as a move-immediate. */
273 return _("register source in immediate move");
275 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_16,
276 result_type, valuep);
278 if (!errmsg && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
279 errmsg = cgen_validate_unsigned_integer (*valuep, 0, 0xffff);
286 parse_branch_addr (CGEN_CPU_DESC cd,
289 int opinfo ATTRIBUTE_UNUSED,
290 enum cgen_parse_operand_result * resultp ATTRIBUTE_UNUSED,
291 bfd_vma *valuep ATTRIBUTE_UNUSED)
294 enum cgen_parse_operand_result result_type;
295 bfd_reloc_code_real_type code = BFD_RELOC_NONE;
300 case EPIPHANY_OPERAND_SIMM24:
301 code = BFD_RELOC_EPIPHANY_SIMM24;
304 case EPIPHANY_OPERAND_SIMM8:
305 code = BFD_RELOC_EPIPHANY_SIMM8;
309 errmsg = _("ABORT: unknown operand");
313 errmsg = cgen_parse_address (cd, strp, opindex, code,
314 &result_type, &value);
317 if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
319 /* Act as if we had done a PC-relative branch, ala .+num. */
321 const char * bufp = (const char *) buf;
323 sprintf (buf, ".+%ld", (long) value);
324 errmsg = cgen_parse_address (cd, &bufp, opindex, code, &result_type,
328 if (result_type == CGEN_PARSE_OPERAND_RESULT_QUEUED)
330 /* This will happen for things like (s2-s1) where s2 and s1
332 /* Nothing further to be done. */
335 errmsg = _("Not a pc-relative address.");
342 #define CGEN_PRINT_INSN epiphany_print_insn
345 epiphany_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
347 bfd_byte buf[CGEN_MAX_INSN_SIZE];
351 info->bytes_per_chunk = 2;
353 /* Attempt to read the base part of the insn. */
354 info->bytes_per_line = buflen = cd->base_insn_bitsize / 8;
355 status = (*info->read_memory_func) (pc, buf, buflen, info);
357 /* Try again with the minimum part, if min < base. */
358 if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
360 info->bytes_per_line = buflen = cd->min_insn_bitsize / 8;
361 status = (*info->read_memory_func) (pc, buf, buflen, info);
366 (*info->memory_error_func) (status, pc, info);
370 return print_insn (cd, pc, info, buf, buflen);
375 print_postindex (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
378 unsigned int attrs ATTRIBUTE_UNUSED,
379 bfd_vma pc ATTRIBUTE_UNUSED,
380 int length ATTRIBUTE_UNUSED)
382 disassemble_info *info = (disassemble_info *) dis_info;
383 (*info->fprintf_func) (info->stream, value ? "-" : "+");
387 print_simm_not_reg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
390 unsigned int attrs ATTRIBUTE_UNUSED,
391 bfd_vma pc ATTRIBUTE_UNUSED,
392 int length ATTRIBUTE_UNUSED)
394 print_address (cd, dis_info, value, attrs, pc, length);
398 print_uimm_not_reg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
401 unsigned int attrs ATTRIBUTE_UNUSED,
402 bfd_vma pc ATTRIBUTE_UNUSED,
403 int length ATTRIBUTE_UNUSED)
405 disassemble_info *info = (disassemble_info *)dis_info;
408 (*info->fprintf_func) (info->stream, "-");
411 print_address (cd, dis_info, value, attrs, pc, length);