1 /* XSTORMY16 opcode support. -*- C -*-
2 Copyright 2011 Free Software Foundation, Inc.
4 Contributed by Red Hat Inc;
6 This file is part of the GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 /* This file is an addendum to xstormy16.cpu. Heavy use of C code isn't
24 appropriate in .cpu files, so it resides here. This especially applies
25 to assembly/disassembly where parsing/printing can be quite involved.
26 Such things aren't really part of the specification of the cpu, per se,
27 so .cpu files provide the general framework and .opc files handle the
28 nitty-gritty details as necessary.
30 Each section is delimited with start and end markers.
32 <arch>-opc.h additions use: "-- opc.h"
33 <arch>-opc.c additions use: "-- opc.c"
34 <arch>-asm.c additions use: "-- asm.c"
35 <arch>-dis.c additions use: "-- dis.c"
36 <arch>-ibd.h additions use: "-- ibd.h". */
40 /* Allows reason codes to be output when assembler errors occur. */
41 #define CGEN_VERBOSE_ASSEMBLER_ERRORS
43 /* We can't use the default hash size because many bits are used by
45 #define CGEN_DIS_HASH_SIZE 1
46 #define CGEN_DIS_HASH(buf, value) 0
51 /* The machine-independent code doesn't know how to disambiguate
55 where 'foo' is a label. This helps it out. */
58 parse_mem8 (CGEN_CPU_DESC cd,
61 unsigned long *valuep)
65 const char *s = *strp;
67 if (s[1] == '-' && s[2] == '-')
68 return _("Bad register in preincrement");
70 while (ISALNUM (*++s))
72 if (s[0] == '+' && s[1] == '+' && (s[2] == ')' || s[2] == ','))
73 return _("Bad register in postincrement");
74 if (s[0] == ',' || s[0] == ')')
75 return _("Bad register name");
77 else if (cgen_parse_keyword (cd, strp, & xstormy16_cgen_opval_gr_names,
78 (long *) valuep) == NULL)
79 return _("Label conflicts with register name");
80 else if (strncasecmp (*strp, "rx,", 3) == 0
81 || strncasecmp (*strp, "rxl,", 3) == 0
82 || strncasecmp (*strp, "rxh,", 3) == 0)
83 return _("Label conflicts with `Rx'");
84 else if (**strp == '#')
85 return _("Bad immediate expression");
87 return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
90 /* For the add and subtract instructions, there are two immediate forms,
91 one for small operands and one for large ones. We want to use
92 the small one when possible, but we do not want to generate relocs
93 of the small size. This is somewhat tricky. */
96 parse_small_immediate (CGEN_CPU_DESC cd,
99 unsigned long *valuep)
102 enum cgen_parse_operand_result result;
106 return _("No relocation for small immediate");
108 errmsg = (* cd->parse_operand_fn)
109 (cd, CGEN_PARSE_OPERAND_INTEGER, strp, opindex, BFD_RELOC_NONE,
115 if (result != CGEN_PARSE_OPERAND_RESULT_NUMBER)
116 return _("Small operand was not an immediate number");
122 /* Literal scan be either a normal literal, a @hi() or @lo relocation. */
125 parse_immediate16 (CGEN_CPU_DESC cd,
128 unsigned long *valuep)
131 enum cgen_parse_operand_result result;
132 bfd_reloc_code_real_type code = BFD_RELOC_NONE;
135 if (strncmp (*strp, "@hi(", 4) == 0)
138 code = BFD_RELOC_HI16;
141 if (strncmp (*strp, "@lo(", 4) == 0)
144 code = BFD_RELOC_LO16;
147 if (code == BFD_RELOC_NONE)
148 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
151 errmsg = cgen_parse_address (cd, strp, opindex, code, &result, &value);
152 if ((errmsg == NULL) &&
153 (result != CGEN_PARSE_OPERAND_RESULT_QUEUED))
154 errmsg = _("Operand is not a symbol");
157 if ((code == BFD_RELOC_HI16 || code == BFD_RELOC_LO16)
162 errmsg = _("Syntax error: No trailing ')'");