1*3d8817e4Smiod /* Assembler interface for targets using CGEN. -*- C -*-
2*3d8817e4Smiod CGEN: Cpu tools GENerator
3*3d8817e4Smiod
4*3d8817e4Smiod THIS FILE IS MACHINE GENERATED WITH CGEN.
5*3d8817e4Smiod - the resultant file is machine generated, cgen-asm.in isn't
6*3d8817e4Smiod
7*3d8817e4Smiod Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2005
8*3d8817e4Smiod Free Software Foundation, Inc.
9*3d8817e4Smiod
10*3d8817e4Smiod This file is part of the GNU Binutils and GDB, the GNU debugger.
11*3d8817e4Smiod
12*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
13*3d8817e4Smiod it under the terms of the GNU General Public License as published by
14*3d8817e4Smiod the Free Software Foundation; either version 2, or (at your option)
15*3d8817e4Smiod any later version.
16*3d8817e4Smiod
17*3d8817e4Smiod This program is distributed in the hope that it will be useful,
18*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
19*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20*3d8817e4Smiod GNU General Public License for more details.
21*3d8817e4Smiod
22*3d8817e4Smiod You should have received a copy of the GNU General Public License
23*3d8817e4Smiod along with this program; if not, write to the Free Software Foundation, Inc.,
24*3d8817e4Smiod 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25*3d8817e4Smiod
26*3d8817e4Smiod /* ??? Eventually more and more of this stuff can go to cpu-independent files.
27*3d8817e4Smiod Keep that in mind. */
28*3d8817e4Smiod
29*3d8817e4Smiod #include "sysdep.h"
30*3d8817e4Smiod #include <stdio.h>
31*3d8817e4Smiod #include "ansidecl.h"
32*3d8817e4Smiod #include "bfd.h"
33*3d8817e4Smiod #include "symcat.h"
34*3d8817e4Smiod #include "m32c-desc.h"
35*3d8817e4Smiod #include "m32c-opc.h"
36*3d8817e4Smiod #include "opintl.h"
37*3d8817e4Smiod #include "xregex.h"
38*3d8817e4Smiod #include "libiberty.h"
39*3d8817e4Smiod #include "safe-ctype.h"
40*3d8817e4Smiod
41*3d8817e4Smiod #undef min
42*3d8817e4Smiod #define min(a,b) ((a) < (b) ? (a) : (b))
43*3d8817e4Smiod #undef max
44*3d8817e4Smiod #define max(a,b) ((a) > (b) ? (a) : (b))
45*3d8817e4Smiod
46*3d8817e4Smiod static const char * parse_insn_normal
47*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
48*3d8817e4Smiod
49*3d8817e4Smiod /* -- assembler routines inserted here. */
50*3d8817e4Smiod
51*3d8817e4Smiod /* -- asm.c */
52*3d8817e4Smiod #include "safe-ctype.h"
53*3d8817e4Smiod
54*3d8817e4Smiod #define MACH_M32C 5 /* Must match md_begin. */
55*3d8817e4Smiod
56*3d8817e4Smiod static int
m32c_cgen_isa_register(const char ** strp)57*3d8817e4Smiod m32c_cgen_isa_register (const char **strp)
58*3d8817e4Smiod {
59*3d8817e4Smiod int u;
60*3d8817e4Smiod const char *s = *strp;
61*3d8817e4Smiod static char * m32c_register_names [] =
62*3d8817e4Smiod {
63*3d8817e4Smiod "r0", "r1", "r2", "r3", "r0l", "r0h", "r1l", "r1h",
64*3d8817e4Smiod "a0", "a1", "r2r0", "r3r1", "sp", "fb", "dct0", "dct1", "flg", "svf",
65*3d8817e4Smiod "drc0", "drc1", "dmd0", "dmd1", "intb", "svp", "vct", "isp", "dma0",
66*3d8817e4Smiod "dma1", "dra0", "dra1", "dsa0", "dsa1", 0
67*3d8817e4Smiod };
68*3d8817e4Smiod
69*3d8817e4Smiod for (u = 0; m32c_register_names[u]; u++)
70*3d8817e4Smiod {
71*3d8817e4Smiod int len = strlen (m32c_register_names[u]);
72*3d8817e4Smiod
73*3d8817e4Smiod if (memcmp (m32c_register_names[u], s, len) == 0
74*3d8817e4Smiod && (s[len] == 0 || ! ISALNUM (s[len])))
75*3d8817e4Smiod return 1;
76*3d8817e4Smiod }
77*3d8817e4Smiod return 0;
78*3d8817e4Smiod }
79*3d8817e4Smiod
80*3d8817e4Smiod #define PARSE_UNSIGNED \
81*3d8817e4Smiod do \
82*3d8817e4Smiod { \
83*3d8817e4Smiod /* Don't successfully parse literals beginning with '['. */ \
84*3d8817e4Smiod if (**strp == '[') \
85*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */ \
86*3d8817e4Smiod \
87*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);\
88*3d8817e4Smiod if (errmsg) \
89*3d8817e4Smiod return errmsg; \
90*3d8817e4Smiod } \
91*3d8817e4Smiod while (0)
92*3d8817e4Smiod
93*3d8817e4Smiod #define PARSE_SIGNED \
94*3d8817e4Smiod do \
95*3d8817e4Smiod { \
96*3d8817e4Smiod /* Don't successfully parse literals beginning with '['. */ \
97*3d8817e4Smiod if (**strp == '[') \
98*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */ \
99*3d8817e4Smiod \
100*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value); \
101*3d8817e4Smiod if (errmsg) \
102*3d8817e4Smiod return errmsg; \
103*3d8817e4Smiod } \
104*3d8817e4Smiod while (0)
105*3d8817e4Smiod
106*3d8817e4Smiod static const char *
parse_unsigned6(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)107*3d8817e4Smiod parse_unsigned6 (CGEN_CPU_DESC cd, const char **strp,
108*3d8817e4Smiod int opindex, unsigned long *valuep)
109*3d8817e4Smiod {
110*3d8817e4Smiod const char *errmsg = 0;
111*3d8817e4Smiod unsigned long value;
112*3d8817e4Smiod
113*3d8817e4Smiod PARSE_UNSIGNED;
114*3d8817e4Smiod
115*3d8817e4Smiod if (value > 0x3f)
116*3d8817e4Smiod return _("imm:6 immediate is out of range");
117*3d8817e4Smiod
118*3d8817e4Smiod *valuep = value;
119*3d8817e4Smiod return 0;
120*3d8817e4Smiod }
121*3d8817e4Smiod
122*3d8817e4Smiod static const char *
parse_unsigned8(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)123*3d8817e4Smiod parse_unsigned8 (CGEN_CPU_DESC cd, const char **strp,
124*3d8817e4Smiod int opindex, unsigned long *valuep)
125*3d8817e4Smiod {
126*3d8817e4Smiod const char *errmsg = 0;
127*3d8817e4Smiod unsigned long value;
128*3d8817e4Smiod long have_zero = 0;
129*3d8817e4Smiod
130*3d8817e4Smiod if (strncasecmp (*strp, "%dsp8(", 6) == 0)
131*3d8817e4Smiod {
132*3d8817e4Smiod enum cgen_parse_operand_result result_type;
133*3d8817e4Smiod bfd_vma value;
134*3d8817e4Smiod const char *errmsg;
135*3d8817e4Smiod
136*3d8817e4Smiod *strp += 6;
137*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_8,
138*3d8817e4Smiod & result_type, & value);
139*3d8817e4Smiod if (**strp != ')')
140*3d8817e4Smiod return _("missing `)'");
141*3d8817e4Smiod (*strp) ++;
142*3d8817e4Smiod
143*3d8817e4Smiod if (errmsg == NULL
144*3d8817e4Smiod && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
145*3d8817e4Smiod {
146*3d8817e4Smiod return _("%dsp8() takes a symbolic address, not a number");
147*3d8817e4Smiod }
148*3d8817e4Smiod *valuep = value;
149*3d8817e4Smiod return errmsg;
150*3d8817e4Smiod }
151*3d8817e4Smiod
152*3d8817e4Smiod if (strncmp (*strp, "0x0", 3) == 0
153*3d8817e4Smiod || (**strp == '0' && *(*strp + 1) != 'x'))
154*3d8817e4Smiod have_zero = 1;
155*3d8817e4Smiod
156*3d8817e4Smiod PARSE_UNSIGNED;
157*3d8817e4Smiod
158*3d8817e4Smiod if (value > 0xff)
159*3d8817e4Smiod return _("dsp:8 immediate is out of range");
160*3d8817e4Smiod
161*3d8817e4Smiod /* If this field may require a relocation then use larger dsp16. */
162*3d8817e4Smiod if (! have_zero && value == 0)
163*3d8817e4Smiod return _("dsp:8 immediate is out of range");
164*3d8817e4Smiod
165*3d8817e4Smiod *valuep = value;
166*3d8817e4Smiod return 0;
167*3d8817e4Smiod }
168*3d8817e4Smiod
169*3d8817e4Smiod static const char *
parse_signed4(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)170*3d8817e4Smiod parse_signed4 (CGEN_CPU_DESC cd, const char **strp,
171*3d8817e4Smiod int opindex, signed long *valuep)
172*3d8817e4Smiod {
173*3d8817e4Smiod const char *errmsg = 0;
174*3d8817e4Smiod signed long value;
175*3d8817e4Smiod long have_zero = 0;
176*3d8817e4Smiod
177*3d8817e4Smiod if (strncmp (*strp, "0x0", 3) == 0
178*3d8817e4Smiod || (**strp == '0' && *(*strp + 1) != 'x'))
179*3d8817e4Smiod have_zero = 1;
180*3d8817e4Smiod
181*3d8817e4Smiod PARSE_SIGNED;
182*3d8817e4Smiod
183*3d8817e4Smiod if (value < -8 || value > 7)
184*3d8817e4Smiod return _("Immediate is out of range -8 to 7");
185*3d8817e4Smiod
186*3d8817e4Smiod /* If this field may require a relocation then use larger dsp16. */
187*3d8817e4Smiod if (! have_zero && value == 0)
188*3d8817e4Smiod return _("Immediate is out of range -8 to 7");
189*3d8817e4Smiod
190*3d8817e4Smiod *valuep = value;
191*3d8817e4Smiod return 0;
192*3d8817e4Smiod }
193*3d8817e4Smiod
194*3d8817e4Smiod static const char *
parse_signed4n(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)195*3d8817e4Smiod parse_signed4n (CGEN_CPU_DESC cd, const char **strp,
196*3d8817e4Smiod int opindex, signed long *valuep)
197*3d8817e4Smiod {
198*3d8817e4Smiod const char *errmsg = 0;
199*3d8817e4Smiod signed long value;
200*3d8817e4Smiod long have_zero = 0;
201*3d8817e4Smiod
202*3d8817e4Smiod if (strncmp (*strp, "0x0", 3) == 0
203*3d8817e4Smiod || (**strp == '0' && *(*strp + 1) != 'x'))
204*3d8817e4Smiod have_zero = 1;
205*3d8817e4Smiod
206*3d8817e4Smiod PARSE_SIGNED;
207*3d8817e4Smiod
208*3d8817e4Smiod if (value < -7 || value > 8)
209*3d8817e4Smiod return _("Immediate is out of range -7 to 8");
210*3d8817e4Smiod
211*3d8817e4Smiod /* If this field may require a relocation then use larger dsp16. */
212*3d8817e4Smiod if (! have_zero && value == 0)
213*3d8817e4Smiod return _("Immediate is out of range -7 to 8");
214*3d8817e4Smiod
215*3d8817e4Smiod *valuep = -value;
216*3d8817e4Smiod return 0;
217*3d8817e4Smiod }
218*3d8817e4Smiod
219*3d8817e4Smiod static const char *
parse_signed8(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)220*3d8817e4Smiod parse_signed8 (CGEN_CPU_DESC cd, const char **strp,
221*3d8817e4Smiod int opindex, signed long *valuep)
222*3d8817e4Smiod {
223*3d8817e4Smiod const char *errmsg = 0;
224*3d8817e4Smiod signed long value;
225*3d8817e4Smiod
226*3d8817e4Smiod if (strncasecmp (*strp, "%hi8(", 5) == 0)
227*3d8817e4Smiod {
228*3d8817e4Smiod enum cgen_parse_operand_result result_type;
229*3d8817e4Smiod bfd_vma value;
230*3d8817e4Smiod const char *errmsg;
231*3d8817e4Smiod
232*3d8817e4Smiod *strp += 5;
233*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_M32C_HI8,
234*3d8817e4Smiod & result_type, & value);
235*3d8817e4Smiod if (**strp != ')')
236*3d8817e4Smiod return _("missing `)'");
237*3d8817e4Smiod (*strp) ++;
238*3d8817e4Smiod
239*3d8817e4Smiod if (errmsg == NULL
240*3d8817e4Smiod && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
241*3d8817e4Smiod {
242*3d8817e4Smiod value >>= 16;
243*3d8817e4Smiod }
244*3d8817e4Smiod *valuep = value;
245*3d8817e4Smiod return errmsg;
246*3d8817e4Smiod }
247*3d8817e4Smiod
248*3d8817e4Smiod PARSE_SIGNED;
249*3d8817e4Smiod
250*3d8817e4Smiod if (value <= 255 && value > 127)
251*3d8817e4Smiod value -= 0x100;
252*3d8817e4Smiod
253*3d8817e4Smiod if (value < -128 || value > 127)
254*3d8817e4Smiod return _("dsp:8 immediate is out of range");
255*3d8817e4Smiod
256*3d8817e4Smiod *valuep = value;
257*3d8817e4Smiod return 0;
258*3d8817e4Smiod }
259*3d8817e4Smiod
260*3d8817e4Smiod static const char *
parse_unsigned16(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)261*3d8817e4Smiod parse_unsigned16 (CGEN_CPU_DESC cd, const char **strp,
262*3d8817e4Smiod int opindex, unsigned long *valuep)
263*3d8817e4Smiod {
264*3d8817e4Smiod const char *errmsg = 0;
265*3d8817e4Smiod unsigned long value;
266*3d8817e4Smiod long have_zero = 0;
267*3d8817e4Smiod
268*3d8817e4Smiod if (strncasecmp (*strp, "%dsp16(", 7) == 0)
269*3d8817e4Smiod {
270*3d8817e4Smiod enum cgen_parse_operand_result result_type;
271*3d8817e4Smiod bfd_vma value;
272*3d8817e4Smiod const char *errmsg;
273*3d8817e4Smiod
274*3d8817e4Smiod *strp += 7;
275*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_16,
276*3d8817e4Smiod & result_type, & value);
277*3d8817e4Smiod if (**strp != ')')
278*3d8817e4Smiod return _("missing `)'");
279*3d8817e4Smiod (*strp) ++;
280*3d8817e4Smiod
281*3d8817e4Smiod if (errmsg == NULL
282*3d8817e4Smiod && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
283*3d8817e4Smiod {
284*3d8817e4Smiod return _("%dsp16() takes a symbolic address, not a number");
285*3d8817e4Smiod }
286*3d8817e4Smiod *valuep = value;
287*3d8817e4Smiod return errmsg;
288*3d8817e4Smiod }
289*3d8817e4Smiod
290*3d8817e4Smiod /* Don't successfully parse literals beginning with '['. */
291*3d8817e4Smiod if (**strp == '[')
292*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */
293*3d8817e4Smiod
294*3d8817e4Smiod /* Don't successfully parse register names. */
295*3d8817e4Smiod if (m32c_cgen_isa_register (strp))
296*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */
297*3d8817e4Smiod
298*3d8817e4Smiod if (strncmp (*strp, "0x0", 3) == 0
299*3d8817e4Smiod || (**strp == '0' && *(*strp + 1) != 'x'))
300*3d8817e4Smiod have_zero = 1;
301*3d8817e4Smiod
302*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
303*3d8817e4Smiod if (errmsg)
304*3d8817e4Smiod return errmsg;
305*3d8817e4Smiod
306*3d8817e4Smiod if (value > 0xffff)
307*3d8817e4Smiod return _("dsp:16 immediate is out of range");
308*3d8817e4Smiod
309*3d8817e4Smiod /* If this field may require a relocation then use larger dsp24. */
310*3d8817e4Smiod if (cd->machs == MACH_M32C && ! have_zero && value == 0
311*3d8817e4Smiod && (strncmp (*strp, "[a", 2) == 0
312*3d8817e4Smiod || **strp == ','
313*3d8817e4Smiod || **strp == 0))
314*3d8817e4Smiod return _("dsp:16 immediate is out of range");
315*3d8817e4Smiod
316*3d8817e4Smiod *valuep = value;
317*3d8817e4Smiod return 0;
318*3d8817e4Smiod }
319*3d8817e4Smiod
320*3d8817e4Smiod static const char *
parse_signed16(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)321*3d8817e4Smiod parse_signed16 (CGEN_CPU_DESC cd, const char **strp,
322*3d8817e4Smiod int opindex, signed long *valuep)
323*3d8817e4Smiod {
324*3d8817e4Smiod const char *errmsg = 0;
325*3d8817e4Smiod signed long value;
326*3d8817e4Smiod
327*3d8817e4Smiod if (strncasecmp (*strp, "%lo16(", 6) == 0)
328*3d8817e4Smiod {
329*3d8817e4Smiod enum cgen_parse_operand_result result_type;
330*3d8817e4Smiod bfd_vma value;
331*3d8817e4Smiod const char *errmsg;
332*3d8817e4Smiod
333*3d8817e4Smiod *strp += 6;
334*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
335*3d8817e4Smiod & result_type, & value);
336*3d8817e4Smiod if (**strp != ')')
337*3d8817e4Smiod return _("missing `)'");
338*3d8817e4Smiod (*strp) ++;
339*3d8817e4Smiod
340*3d8817e4Smiod if (errmsg == NULL
341*3d8817e4Smiod && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
342*3d8817e4Smiod {
343*3d8817e4Smiod value &= 0xffff;
344*3d8817e4Smiod }
345*3d8817e4Smiod *valuep = value;
346*3d8817e4Smiod return errmsg;
347*3d8817e4Smiod }
348*3d8817e4Smiod
349*3d8817e4Smiod if (strncasecmp (*strp, "%hi16(", 6) == 0)
350*3d8817e4Smiod {
351*3d8817e4Smiod enum cgen_parse_operand_result result_type;
352*3d8817e4Smiod bfd_vma value;
353*3d8817e4Smiod const char *errmsg;
354*3d8817e4Smiod
355*3d8817e4Smiod *strp += 6;
356*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_HI16,
357*3d8817e4Smiod & result_type, & value);
358*3d8817e4Smiod if (**strp != ')')
359*3d8817e4Smiod return _("missing `)'");
360*3d8817e4Smiod (*strp) ++;
361*3d8817e4Smiod
362*3d8817e4Smiod if (errmsg == NULL
363*3d8817e4Smiod && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
364*3d8817e4Smiod {
365*3d8817e4Smiod value >>= 16;
366*3d8817e4Smiod }
367*3d8817e4Smiod *valuep = value;
368*3d8817e4Smiod return errmsg;
369*3d8817e4Smiod }
370*3d8817e4Smiod
371*3d8817e4Smiod PARSE_SIGNED;
372*3d8817e4Smiod
373*3d8817e4Smiod if (value <= 65535 && value > 32767)
374*3d8817e4Smiod value -= 0x10000;
375*3d8817e4Smiod
376*3d8817e4Smiod if (value < -32768 || value > 32767)
377*3d8817e4Smiod return _("dsp:16 immediate is out of range");
378*3d8817e4Smiod
379*3d8817e4Smiod *valuep = value;
380*3d8817e4Smiod return 0;
381*3d8817e4Smiod }
382*3d8817e4Smiod
383*3d8817e4Smiod static const char *
parse_unsigned20(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)384*3d8817e4Smiod parse_unsigned20 (CGEN_CPU_DESC cd, const char **strp,
385*3d8817e4Smiod int opindex, unsigned long *valuep)
386*3d8817e4Smiod {
387*3d8817e4Smiod const char *errmsg = 0;
388*3d8817e4Smiod unsigned long value;
389*3d8817e4Smiod
390*3d8817e4Smiod /* Don't successfully parse literals beginning with '['. */
391*3d8817e4Smiod if (**strp == '[')
392*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */
393*3d8817e4Smiod
394*3d8817e4Smiod /* Don't successfully parse register names. */
395*3d8817e4Smiod if (m32c_cgen_isa_register (strp))
396*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */
397*3d8817e4Smiod
398*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
399*3d8817e4Smiod if (errmsg)
400*3d8817e4Smiod return errmsg;
401*3d8817e4Smiod
402*3d8817e4Smiod if (value > 0xfffff)
403*3d8817e4Smiod return _("dsp:20 immediate is out of range");
404*3d8817e4Smiod
405*3d8817e4Smiod *valuep = value;
406*3d8817e4Smiod return 0;
407*3d8817e4Smiod }
408*3d8817e4Smiod
409*3d8817e4Smiod static const char *
parse_unsigned24(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)410*3d8817e4Smiod parse_unsigned24 (CGEN_CPU_DESC cd, const char **strp,
411*3d8817e4Smiod int opindex, unsigned long *valuep)
412*3d8817e4Smiod {
413*3d8817e4Smiod const char *errmsg = 0;
414*3d8817e4Smiod unsigned long value;
415*3d8817e4Smiod
416*3d8817e4Smiod /* Don't successfully parse literals beginning with '['. */
417*3d8817e4Smiod if (**strp == '[')
418*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */
419*3d8817e4Smiod
420*3d8817e4Smiod /* Don't successfully parse register names. */
421*3d8817e4Smiod if (m32c_cgen_isa_register (strp))
422*3d8817e4Smiod return "Invalid literal"; /* Anything -- will not be seen. */
423*3d8817e4Smiod
424*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
425*3d8817e4Smiod if (errmsg)
426*3d8817e4Smiod return errmsg;
427*3d8817e4Smiod
428*3d8817e4Smiod if (value > 0xffffff)
429*3d8817e4Smiod return _("dsp:24 immediate is out of range");
430*3d8817e4Smiod
431*3d8817e4Smiod *valuep = value;
432*3d8817e4Smiod return 0;
433*3d8817e4Smiod }
434*3d8817e4Smiod
435*3d8817e4Smiod /* This should only be used for #imm->reg. */
436*3d8817e4Smiod static const char *
parse_signed24(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)437*3d8817e4Smiod parse_signed24 (CGEN_CPU_DESC cd, const char **strp,
438*3d8817e4Smiod int opindex, signed long *valuep)
439*3d8817e4Smiod {
440*3d8817e4Smiod const char *errmsg = 0;
441*3d8817e4Smiod signed long value;
442*3d8817e4Smiod
443*3d8817e4Smiod PARSE_SIGNED;
444*3d8817e4Smiod
445*3d8817e4Smiod if (value <= 0xffffff && value > 0x7fffff)
446*3d8817e4Smiod value -= 0x1000000;
447*3d8817e4Smiod
448*3d8817e4Smiod if (value > 0xffffff)
449*3d8817e4Smiod return _("dsp:24 immediate is out of range");
450*3d8817e4Smiod
451*3d8817e4Smiod *valuep = value;
452*3d8817e4Smiod return 0;
453*3d8817e4Smiod }
454*3d8817e4Smiod
455*3d8817e4Smiod static const char *
parse_signed32(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)456*3d8817e4Smiod parse_signed32 (CGEN_CPU_DESC cd, const char **strp,
457*3d8817e4Smiod int opindex, signed long *valuep)
458*3d8817e4Smiod {
459*3d8817e4Smiod const char *errmsg = 0;
460*3d8817e4Smiod signed long value;
461*3d8817e4Smiod
462*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
463*3d8817e4Smiod if (errmsg)
464*3d8817e4Smiod return errmsg;
465*3d8817e4Smiod
466*3d8817e4Smiod *valuep = value;
467*3d8817e4Smiod return 0;
468*3d8817e4Smiod }
469*3d8817e4Smiod
470*3d8817e4Smiod static const char *
parse_imm1_S(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)471*3d8817e4Smiod parse_imm1_S (CGEN_CPU_DESC cd, const char **strp,
472*3d8817e4Smiod int opindex, signed long *valuep)
473*3d8817e4Smiod {
474*3d8817e4Smiod const char *errmsg = 0;
475*3d8817e4Smiod signed long value;
476*3d8817e4Smiod
477*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
478*3d8817e4Smiod if (errmsg)
479*3d8817e4Smiod return errmsg;
480*3d8817e4Smiod
481*3d8817e4Smiod if (value < 1 || value > 2)
482*3d8817e4Smiod return _("immediate is out of range 1-2");
483*3d8817e4Smiod
484*3d8817e4Smiod *valuep = value;
485*3d8817e4Smiod return 0;
486*3d8817e4Smiod }
487*3d8817e4Smiod
488*3d8817e4Smiod static const char *
parse_imm3_S(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)489*3d8817e4Smiod parse_imm3_S (CGEN_CPU_DESC cd, const char **strp,
490*3d8817e4Smiod int opindex, signed long *valuep)
491*3d8817e4Smiod {
492*3d8817e4Smiod const char *errmsg = 0;
493*3d8817e4Smiod signed long value;
494*3d8817e4Smiod
495*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
496*3d8817e4Smiod if (errmsg)
497*3d8817e4Smiod return errmsg;
498*3d8817e4Smiod
499*3d8817e4Smiod if (value < 1 || value > 8)
500*3d8817e4Smiod return _("immediate is out of range 1-8");
501*3d8817e4Smiod
502*3d8817e4Smiod *valuep = value;
503*3d8817e4Smiod return 0;
504*3d8817e4Smiod }
505*3d8817e4Smiod
506*3d8817e4Smiod static const char *
parse_bit3_S(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)507*3d8817e4Smiod parse_bit3_S (CGEN_CPU_DESC cd, const char **strp,
508*3d8817e4Smiod int opindex, signed long *valuep)
509*3d8817e4Smiod {
510*3d8817e4Smiod const char *errmsg = 0;
511*3d8817e4Smiod signed long value;
512*3d8817e4Smiod
513*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
514*3d8817e4Smiod if (errmsg)
515*3d8817e4Smiod return errmsg;
516*3d8817e4Smiod
517*3d8817e4Smiod if (value < 0 || value > 7)
518*3d8817e4Smiod return _("immediate is out of range 0-7");
519*3d8817e4Smiod
520*3d8817e4Smiod *valuep = value;
521*3d8817e4Smiod return 0;
522*3d8817e4Smiod }
523*3d8817e4Smiod
524*3d8817e4Smiod static const char *
parse_lab_5_3(CGEN_CPU_DESC cd,const char ** strp,int opindex ATTRIBUTE_UNUSED,int opinfo,enum cgen_parse_operand_result * type_addr,bfd_vma * valuep)525*3d8817e4Smiod parse_lab_5_3 (CGEN_CPU_DESC cd,
526*3d8817e4Smiod const char **strp,
527*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
528*3d8817e4Smiod int opinfo,
529*3d8817e4Smiod enum cgen_parse_operand_result *type_addr,
530*3d8817e4Smiod bfd_vma *valuep)
531*3d8817e4Smiod {
532*3d8817e4Smiod const char *errmsg = 0;
533*3d8817e4Smiod bfd_vma value;
534*3d8817e4Smiod enum cgen_parse_operand_result op_res;
535*3d8817e4Smiod
536*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_5_3,
537*3d8817e4Smiod opinfo, & op_res, & value);
538*3d8817e4Smiod
539*3d8817e4Smiod if (type_addr)
540*3d8817e4Smiod *type_addr = op_res;
541*3d8817e4Smiod
542*3d8817e4Smiod if (op_res == CGEN_PARSE_OPERAND_ADDRESS)
543*3d8817e4Smiod {
544*3d8817e4Smiod /* This is a hack; the field cannot handle near-zero signed
545*3d8817e4Smiod offsets that CGEN wants to put in to indicate an "empty"
546*3d8817e4Smiod operand at first. */
547*3d8817e4Smiod *valuep = 2;
548*3d8817e4Smiod return 0;
549*3d8817e4Smiod }
550*3d8817e4Smiod if (errmsg)
551*3d8817e4Smiod return errmsg;
552*3d8817e4Smiod
553*3d8817e4Smiod if (value < 2 || value > 9)
554*3d8817e4Smiod return _("immediate is out of range 2-9");
555*3d8817e4Smiod
556*3d8817e4Smiod *valuep = value;
557*3d8817e4Smiod return 0;
558*3d8817e4Smiod }
559*3d8817e4Smiod
560*3d8817e4Smiod static const char *
parse_Bitno16R(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)561*3d8817e4Smiod parse_Bitno16R (CGEN_CPU_DESC cd, const char **strp,
562*3d8817e4Smiod int opindex, unsigned long *valuep)
563*3d8817e4Smiod {
564*3d8817e4Smiod const char *errmsg = 0;
565*3d8817e4Smiod unsigned long value;
566*3d8817e4Smiod
567*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
568*3d8817e4Smiod if (errmsg)
569*3d8817e4Smiod return errmsg;
570*3d8817e4Smiod
571*3d8817e4Smiod if (value > 15)
572*3d8817e4Smiod return _("Bit number for indexing general register is out of range 0-15");
573*3d8817e4Smiod
574*3d8817e4Smiod *valuep = value;
575*3d8817e4Smiod return 0;
576*3d8817e4Smiod }
577*3d8817e4Smiod
578*3d8817e4Smiod static const char *
parse_unsigned_bitbase(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep,unsigned bits,int allow_syms)579*3d8817e4Smiod parse_unsigned_bitbase (CGEN_CPU_DESC cd, const char **strp,
580*3d8817e4Smiod int opindex, unsigned long *valuep,
581*3d8817e4Smiod unsigned bits, int allow_syms)
582*3d8817e4Smiod {
583*3d8817e4Smiod const char *errmsg = 0;
584*3d8817e4Smiod unsigned long bit;
585*3d8817e4Smiod unsigned long base;
586*3d8817e4Smiod const char *newp = *strp;
587*3d8817e4Smiod unsigned long long bitbase;
588*3d8817e4Smiod long have_zero = 0;
589*3d8817e4Smiod
590*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, & newp, opindex, & bit);
591*3d8817e4Smiod if (errmsg)
592*3d8817e4Smiod return errmsg;
593*3d8817e4Smiod
594*3d8817e4Smiod if (*newp != ',')
595*3d8817e4Smiod return "Missing base for bit,base:8";
596*3d8817e4Smiod
597*3d8817e4Smiod ++newp;
598*3d8817e4Smiod
599*3d8817e4Smiod if (strncmp (newp, "0x0", 3) == 0
600*3d8817e4Smiod || (newp[0] == '0' && newp[1] != 'x'))
601*3d8817e4Smiod have_zero = 1;
602*3d8817e4Smiod
603*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, & newp, opindex, & base);
604*3d8817e4Smiod if (errmsg)
605*3d8817e4Smiod return errmsg;
606*3d8817e4Smiod
607*3d8817e4Smiod bitbase = (unsigned long long) bit + ((unsigned long long) base * 8);
608*3d8817e4Smiod
609*3d8817e4Smiod if (bitbase >= (1ull << bits))
610*3d8817e4Smiod return _("bit,base is out of range");
611*3d8817e4Smiod
612*3d8817e4Smiod /* If this field may require a relocation then use larger displacement. */
613*3d8817e4Smiod if (! have_zero && base == 0)
614*3d8817e4Smiod {
615*3d8817e4Smiod switch (allow_syms) {
616*3d8817e4Smiod case 0:
617*3d8817e4Smiod return _("bit,base out of range for symbol");
618*3d8817e4Smiod case 1:
619*3d8817e4Smiod break;
620*3d8817e4Smiod case 2:
621*3d8817e4Smiod if (strncmp (newp, "[sb]", 4) != 0)
622*3d8817e4Smiod return _("bit,base out of range for symbol");
623*3d8817e4Smiod break;
624*3d8817e4Smiod }
625*3d8817e4Smiod }
626*3d8817e4Smiod
627*3d8817e4Smiod *valuep = bitbase;
628*3d8817e4Smiod *strp = newp;
629*3d8817e4Smiod return 0;
630*3d8817e4Smiod }
631*3d8817e4Smiod
632*3d8817e4Smiod static const char *
parse_signed_bitbase(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep,unsigned bits,int allow_syms)633*3d8817e4Smiod parse_signed_bitbase (CGEN_CPU_DESC cd, const char **strp,
634*3d8817e4Smiod int opindex, signed long *valuep,
635*3d8817e4Smiod unsigned bits, int allow_syms)
636*3d8817e4Smiod {
637*3d8817e4Smiod const char *errmsg = 0;
638*3d8817e4Smiod unsigned long bit;
639*3d8817e4Smiod signed long base;
640*3d8817e4Smiod const char *newp = *strp;
641*3d8817e4Smiod long long bitbase;
642*3d8817e4Smiod long long limit;
643*3d8817e4Smiod long have_zero = 0;
644*3d8817e4Smiod
645*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, & newp, opindex, & bit);
646*3d8817e4Smiod if (errmsg)
647*3d8817e4Smiod return errmsg;
648*3d8817e4Smiod
649*3d8817e4Smiod if (*newp != ',')
650*3d8817e4Smiod return "Missing base for bit,base:8";
651*3d8817e4Smiod
652*3d8817e4Smiod ++newp;
653*3d8817e4Smiod
654*3d8817e4Smiod if (strncmp (newp, "0x0", 3) == 0
655*3d8817e4Smiod || (newp[0] == '0' && newp[1] != 'x'))
656*3d8817e4Smiod have_zero = 1;
657*3d8817e4Smiod
658*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, & newp, opindex, & base);
659*3d8817e4Smiod if (errmsg)
660*3d8817e4Smiod return errmsg;
661*3d8817e4Smiod
662*3d8817e4Smiod bitbase = (long long)bit + ((long long)base * 8);
663*3d8817e4Smiod
664*3d8817e4Smiod limit = 1ll << (bits - 1);
665*3d8817e4Smiod if (bitbase < -limit || bitbase >= limit)
666*3d8817e4Smiod return _("bit,base is out of range");
667*3d8817e4Smiod
668*3d8817e4Smiod /* If this field may require a relocation then use larger displacement. */
669*3d8817e4Smiod if (! have_zero && base == 0 && ! allow_syms)
670*3d8817e4Smiod return _("bit,base out of range for symbol");
671*3d8817e4Smiod
672*3d8817e4Smiod *valuep = bitbase;
673*3d8817e4Smiod *strp = newp;
674*3d8817e4Smiod return 0;
675*3d8817e4Smiod }
676*3d8817e4Smiod
677*3d8817e4Smiod static const char *
parse_unsigned_bitbase8(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)678*3d8817e4Smiod parse_unsigned_bitbase8 (CGEN_CPU_DESC cd, const char **strp,
679*3d8817e4Smiod int opindex, unsigned long *valuep)
680*3d8817e4Smiod {
681*3d8817e4Smiod return parse_unsigned_bitbase (cd, strp, opindex, valuep, 8, 0);
682*3d8817e4Smiod }
683*3d8817e4Smiod
684*3d8817e4Smiod static const char *
parse_unsigned_bitbase11(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)685*3d8817e4Smiod parse_unsigned_bitbase11 (CGEN_CPU_DESC cd, const char **strp,
686*3d8817e4Smiod int opindex, unsigned long *valuep)
687*3d8817e4Smiod {
688*3d8817e4Smiod return parse_unsigned_bitbase (cd, strp, opindex, valuep, 11, 0);
689*3d8817e4Smiod }
690*3d8817e4Smiod
691*3d8817e4Smiod static const char *
parse_unsigned_bitbase16(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)692*3d8817e4Smiod parse_unsigned_bitbase16 (CGEN_CPU_DESC cd, const char **strp,
693*3d8817e4Smiod int opindex, unsigned long *valuep)
694*3d8817e4Smiod {
695*3d8817e4Smiod return parse_unsigned_bitbase (cd, strp, opindex, valuep, 16, 1);
696*3d8817e4Smiod }
697*3d8817e4Smiod
698*3d8817e4Smiod static const char *
parse_unsigned_bitbase19(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)699*3d8817e4Smiod parse_unsigned_bitbase19 (CGEN_CPU_DESC cd, const char **strp,
700*3d8817e4Smiod int opindex, unsigned long *valuep)
701*3d8817e4Smiod {
702*3d8817e4Smiod return parse_unsigned_bitbase (cd, strp, opindex, valuep, 19, 2);
703*3d8817e4Smiod }
704*3d8817e4Smiod
705*3d8817e4Smiod static const char *
parse_unsigned_bitbase27(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)706*3d8817e4Smiod parse_unsigned_bitbase27 (CGEN_CPU_DESC cd, const char **strp,
707*3d8817e4Smiod int opindex, unsigned long *valuep)
708*3d8817e4Smiod {
709*3d8817e4Smiod return parse_unsigned_bitbase (cd, strp, opindex, valuep, 27, 1);
710*3d8817e4Smiod }
711*3d8817e4Smiod
712*3d8817e4Smiod static const char *
parse_signed_bitbase8(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)713*3d8817e4Smiod parse_signed_bitbase8 (CGEN_CPU_DESC cd, const char **strp,
714*3d8817e4Smiod int opindex, signed long *valuep)
715*3d8817e4Smiod {
716*3d8817e4Smiod return parse_signed_bitbase (cd, strp, opindex, valuep, 8, 1);
717*3d8817e4Smiod }
718*3d8817e4Smiod
719*3d8817e4Smiod static const char *
parse_signed_bitbase11(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)720*3d8817e4Smiod parse_signed_bitbase11 (CGEN_CPU_DESC cd, const char **strp,
721*3d8817e4Smiod int opindex, signed long *valuep)
722*3d8817e4Smiod {
723*3d8817e4Smiod return parse_signed_bitbase (cd, strp, opindex, valuep, 11, 0);
724*3d8817e4Smiod }
725*3d8817e4Smiod
726*3d8817e4Smiod static const char *
parse_signed_bitbase19(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)727*3d8817e4Smiod parse_signed_bitbase19 (CGEN_CPU_DESC cd, const char **strp,
728*3d8817e4Smiod int opindex, signed long *valuep)
729*3d8817e4Smiod {
730*3d8817e4Smiod return parse_signed_bitbase (cd, strp, opindex, valuep, 19, 1);
731*3d8817e4Smiod }
732*3d8817e4Smiod
733*3d8817e4Smiod /* Parse the suffix as :<char> or as nothing followed by a whitespace. */
734*3d8817e4Smiod
735*3d8817e4Smiod static const char *
parse_suffix(const char ** strp,char suffix)736*3d8817e4Smiod parse_suffix (const char **strp, char suffix)
737*3d8817e4Smiod {
738*3d8817e4Smiod const char *newp = *strp;
739*3d8817e4Smiod
740*3d8817e4Smiod if (**strp == ':' && TOLOWER (*(*strp + 1)) == suffix)
741*3d8817e4Smiod newp = *strp + 2;
742*3d8817e4Smiod
743*3d8817e4Smiod if (ISSPACE (*newp))
744*3d8817e4Smiod {
745*3d8817e4Smiod *strp = newp;
746*3d8817e4Smiod return 0;
747*3d8817e4Smiod }
748*3d8817e4Smiod
749*3d8817e4Smiod return "Invalid suffix"; /* Anything -- will not be seen. */
750*3d8817e4Smiod }
751*3d8817e4Smiod
752*3d8817e4Smiod static const char *
parse_S(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,signed long * valuep ATTRIBUTE_UNUSED)753*3d8817e4Smiod parse_S (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
754*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
755*3d8817e4Smiod {
756*3d8817e4Smiod return parse_suffix (strp, 's');
757*3d8817e4Smiod }
758*3d8817e4Smiod
759*3d8817e4Smiod static const char *
parse_G(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,signed long * valuep ATTRIBUTE_UNUSED)760*3d8817e4Smiod parse_G (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
761*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
762*3d8817e4Smiod {
763*3d8817e4Smiod return parse_suffix (strp, 'g');
764*3d8817e4Smiod }
765*3d8817e4Smiod
766*3d8817e4Smiod static const char *
parse_Q(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,signed long * valuep ATTRIBUTE_UNUSED)767*3d8817e4Smiod parse_Q (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
768*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
769*3d8817e4Smiod {
770*3d8817e4Smiod return parse_suffix (strp, 'q');
771*3d8817e4Smiod }
772*3d8817e4Smiod
773*3d8817e4Smiod static const char *
parse_Z(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,signed long * valuep ATTRIBUTE_UNUSED)774*3d8817e4Smiod parse_Z (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
775*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
776*3d8817e4Smiod {
777*3d8817e4Smiod return parse_suffix (strp, 'z');
778*3d8817e4Smiod }
779*3d8817e4Smiod
780*3d8817e4Smiod /* Parse an empty suffix. Fail if the next char is ':'. */
781*3d8817e4Smiod
782*3d8817e4Smiod static const char *
parse_X(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,signed long * valuep ATTRIBUTE_UNUSED)783*3d8817e4Smiod parse_X (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
784*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
785*3d8817e4Smiod {
786*3d8817e4Smiod if (**strp == ':')
787*3d8817e4Smiod return "Unexpected suffix";
788*3d8817e4Smiod return 0;
789*3d8817e4Smiod }
790*3d8817e4Smiod
791*3d8817e4Smiod static const char *
parse_r0l_r0h(CGEN_CPU_DESC cd,const char ** strp,int opindex ATTRIBUTE_UNUSED,signed long * valuep)792*3d8817e4Smiod parse_r0l_r0h (CGEN_CPU_DESC cd, const char **strp,
793*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED, signed long *valuep)
794*3d8817e4Smiod {
795*3d8817e4Smiod const char *errmsg;
796*3d8817e4Smiod signed long value;
797*3d8817e4Smiod signed long junk;
798*3d8817e4Smiod const char *newp = *strp;
799*3d8817e4Smiod
800*3d8817e4Smiod /* Parse r0[hl]. */
801*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, & newp, & m32c_cgen_opval_h_r0l_r0h, & value);
802*3d8817e4Smiod if (errmsg)
803*3d8817e4Smiod return errmsg;
804*3d8817e4Smiod
805*3d8817e4Smiod if (*newp != ',')
806*3d8817e4Smiod return _("not a valid r0l/r0h pair");
807*3d8817e4Smiod ++newp;
808*3d8817e4Smiod
809*3d8817e4Smiod /* Parse the second register in the pair. */
810*3d8817e4Smiod if (value == 0) /* r0l */
811*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, & newp, & m32c_cgen_opval_h_r0h, & junk);
812*3d8817e4Smiod else
813*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, & newp, & m32c_cgen_opval_h_r0l, & junk);
814*3d8817e4Smiod if (errmsg)
815*3d8817e4Smiod return errmsg;
816*3d8817e4Smiod
817*3d8817e4Smiod *strp = newp;
818*3d8817e4Smiod *valuep = ! value;
819*3d8817e4Smiod return 0;
820*3d8817e4Smiod }
821*3d8817e4Smiod
822*3d8817e4Smiod /* Accept .b or .w in any case. */
823*3d8817e4Smiod
824*3d8817e4Smiod static const char *
parse_size(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,signed long * valuep ATTRIBUTE_UNUSED)825*3d8817e4Smiod parse_size (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
826*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
827*3d8817e4Smiod {
828*3d8817e4Smiod if (**strp == '.'
829*3d8817e4Smiod && (*(*strp + 1) == 'b' || *(*strp + 1) == 'B'
830*3d8817e4Smiod || *(*strp + 1) == 'w' || *(*strp + 1) == 'W'))
831*3d8817e4Smiod {
832*3d8817e4Smiod *strp += 2;
833*3d8817e4Smiod return NULL;
834*3d8817e4Smiod }
835*3d8817e4Smiod
836*3d8817e4Smiod return _("Invalid size specifier");
837*3d8817e4Smiod }
838*3d8817e4Smiod
839*3d8817e4Smiod /* Special check to ensure that instruction exists for given machine. */
840*3d8817e4Smiod
841*3d8817e4Smiod int
m32c_cgen_insn_supported(CGEN_CPU_DESC cd,const CGEN_INSN * insn)842*3d8817e4Smiod m32c_cgen_insn_supported (CGEN_CPU_DESC cd,
843*3d8817e4Smiod const CGEN_INSN *insn)
844*3d8817e4Smiod {
845*3d8817e4Smiod int machs = CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_MACH);
846*3d8817e4Smiod CGEN_BITSET isas = CGEN_INSN_BITSET_ATTR_VALUE (insn, CGEN_INSN_ISA);
847*3d8817e4Smiod
848*3d8817e4Smiod /* If attributes are absent, assume no restriction. */
849*3d8817e4Smiod if (machs == 0)
850*3d8817e4Smiod machs = ~0;
851*3d8817e4Smiod
852*3d8817e4Smiod return ((machs & cd->machs)
853*3d8817e4Smiod && cgen_bitset_intersect_p (& isas, cd->isas));
854*3d8817e4Smiod }
855*3d8817e4Smiod
856*3d8817e4Smiod /* Parse a set of registers, R0,R1,A0,A1,SB,FB. */
857*3d8817e4Smiod
858*3d8817e4Smiod static const char *
parse_regset(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,unsigned long * valuep,int push)859*3d8817e4Smiod parse_regset (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
860*3d8817e4Smiod const char **strp,
861*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
862*3d8817e4Smiod unsigned long *valuep,
863*3d8817e4Smiod int push)
864*3d8817e4Smiod {
865*3d8817e4Smiod const char *errmsg = 0;
866*3d8817e4Smiod int regno = 0;
867*3d8817e4Smiod
868*3d8817e4Smiod *valuep = 0;
869*3d8817e4Smiod while (**strp && **strp != ')')
870*3d8817e4Smiod {
871*3d8817e4Smiod if (**strp == 'r' || **strp == 'R')
872*3d8817e4Smiod {
873*3d8817e4Smiod ++*strp;
874*3d8817e4Smiod regno = **strp - '0';
875*3d8817e4Smiod if (regno > 4)
876*3d8817e4Smiod errmsg = _("Register number is not valid");
877*3d8817e4Smiod }
878*3d8817e4Smiod else if (**strp == 'a' || **strp == 'A')
879*3d8817e4Smiod {
880*3d8817e4Smiod ++*strp;
881*3d8817e4Smiod regno = **strp - '0';
882*3d8817e4Smiod if (regno > 2)
883*3d8817e4Smiod errmsg = _("Register number is not valid");
884*3d8817e4Smiod regno = **strp - '0' + 4;
885*3d8817e4Smiod }
886*3d8817e4Smiod
887*3d8817e4Smiod else if (strncasecmp (*strp, "sb", 2) == 0 || strncasecmp (*strp, "SB", 2) == 0)
888*3d8817e4Smiod {
889*3d8817e4Smiod regno = 6;
890*3d8817e4Smiod ++*strp;
891*3d8817e4Smiod }
892*3d8817e4Smiod
893*3d8817e4Smiod else if (strncasecmp (*strp, "fb", 2) == 0 || strncasecmp (*strp, "FB", 2) == 0)
894*3d8817e4Smiod {
895*3d8817e4Smiod regno = 7;
896*3d8817e4Smiod ++*strp;
897*3d8817e4Smiod }
898*3d8817e4Smiod
899*3d8817e4Smiod if (push) /* Mask is reversed for push. */
900*3d8817e4Smiod *valuep |= 0x80 >> regno;
901*3d8817e4Smiod else
902*3d8817e4Smiod *valuep |= 1 << regno;
903*3d8817e4Smiod
904*3d8817e4Smiod ++*strp;
905*3d8817e4Smiod if (**strp == ',')
906*3d8817e4Smiod {
907*3d8817e4Smiod if (*(*strp + 1) == ')')
908*3d8817e4Smiod break;
909*3d8817e4Smiod ++*strp;
910*3d8817e4Smiod }
911*3d8817e4Smiod }
912*3d8817e4Smiod
913*3d8817e4Smiod if (!*strp)
914*3d8817e4Smiod errmsg = _("Register list is not valid");
915*3d8817e4Smiod
916*3d8817e4Smiod return errmsg;
917*3d8817e4Smiod }
918*3d8817e4Smiod
919*3d8817e4Smiod #define POP 0
920*3d8817e4Smiod #define PUSH 1
921*3d8817e4Smiod
922*3d8817e4Smiod static const char *
parse_pop_regset(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,unsigned long * valuep)923*3d8817e4Smiod parse_pop_regset (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
924*3d8817e4Smiod const char **strp,
925*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
926*3d8817e4Smiod unsigned long *valuep)
927*3d8817e4Smiod {
928*3d8817e4Smiod return parse_regset (cd, strp, opindex, valuep, POP);
929*3d8817e4Smiod }
930*3d8817e4Smiod
931*3d8817e4Smiod static const char *
parse_push_regset(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,unsigned long * valuep)932*3d8817e4Smiod parse_push_regset (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
933*3d8817e4Smiod const char **strp,
934*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
935*3d8817e4Smiod unsigned long *valuep)
936*3d8817e4Smiod {
937*3d8817e4Smiod return parse_regset (cd, strp, opindex, valuep, PUSH);
938*3d8817e4Smiod }
939*3d8817e4Smiod
940*3d8817e4Smiod /* -- dis.c */
941*3d8817e4Smiod
942*3d8817e4Smiod const char * m32c_cgen_parse_operand
943*3d8817e4Smiod (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
944*3d8817e4Smiod
945*3d8817e4Smiod /* Main entry point for operand parsing.
946*3d8817e4Smiod
947*3d8817e4Smiod This function is basically just a big switch statement. Earlier versions
948*3d8817e4Smiod used tables to look up the function to use, but
949*3d8817e4Smiod - if the table contains both assembler and disassembler functions then
950*3d8817e4Smiod the disassembler contains much of the assembler and vice-versa,
951*3d8817e4Smiod - there's a lot of inlining possibilities as things grow,
952*3d8817e4Smiod - using a switch statement avoids the function call overhead.
953*3d8817e4Smiod
954*3d8817e4Smiod This function could be moved into `parse_insn_normal', but keeping it
955*3d8817e4Smiod separate makes clear the interface between `parse_insn_normal' and each of
956*3d8817e4Smiod the handlers. */
957*3d8817e4Smiod
958*3d8817e4Smiod const char *
m32c_cgen_parse_operand(CGEN_CPU_DESC cd,int opindex,const char ** strp,CGEN_FIELDS * fields)959*3d8817e4Smiod m32c_cgen_parse_operand (CGEN_CPU_DESC cd,
960*3d8817e4Smiod int opindex,
961*3d8817e4Smiod const char ** strp,
962*3d8817e4Smiod CGEN_FIELDS * fields)
963*3d8817e4Smiod {
964*3d8817e4Smiod const char * errmsg = NULL;
965*3d8817e4Smiod /* Used by scalar operands that still need to be parsed. */
966*3d8817e4Smiod long junk ATTRIBUTE_UNUSED;
967*3d8817e4Smiod
968*3d8817e4Smiod switch (opindex)
969*3d8817e4Smiod {
970*3d8817e4Smiod case M32C_OPERAND_A0 :
971*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_a0, & junk);
972*3d8817e4Smiod break;
973*3d8817e4Smiod case M32C_OPERAND_A1 :
974*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_a1, & junk);
975*3d8817e4Smiod break;
976*3d8817e4Smiod case M32C_OPERAND_AN16_PUSH_S :
977*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_4_1);
978*3d8817e4Smiod break;
979*3d8817e4Smiod case M32C_OPERAND_BIT16AN :
980*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst16_an);
981*3d8817e4Smiod break;
982*3d8817e4Smiod case M32C_OPERAND_BIT16RN :
983*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst16_rn);
984*3d8817e4Smiod break;
985*3d8817e4Smiod case M32C_OPERAND_BIT3_S :
986*3d8817e4Smiod errmsg = parse_bit3_S (cd, strp, M32C_OPERAND_BIT3_S, (long *) (& fields->f_imm3_S));
987*3d8817e4Smiod break;
988*3d8817e4Smiod case M32C_OPERAND_BIT32ANPREFIXED :
989*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_prefixed);
990*3d8817e4Smiod break;
991*3d8817e4Smiod case M32C_OPERAND_BIT32ANUNPREFIXED :
992*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
993*3d8817e4Smiod break;
994*3d8817e4Smiod case M32C_OPERAND_BIT32RNPREFIXED :
995*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_prefixed_QI);
996*3d8817e4Smiod break;
997*3d8817e4Smiod case M32C_OPERAND_BIT32RNUNPREFIXED :
998*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_unprefixed_QI);
999*3d8817e4Smiod break;
1000*3d8817e4Smiod case M32C_OPERAND_BITBASE16_16_S8 :
1001*3d8817e4Smiod errmsg = parse_signed_bitbase8 (cd, strp, M32C_OPERAND_BITBASE16_16_S8, (long *) (& fields->f_dsp_16_s8));
1002*3d8817e4Smiod break;
1003*3d8817e4Smiod case M32C_OPERAND_BITBASE16_16_U16 :
1004*3d8817e4Smiod errmsg = parse_unsigned_bitbase16 (cd, strp, M32C_OPERAND_BITBASE16_16_U16, (unsigned long *) (& fields->f_dsp_16_u16));
1005*3d8817e4Smiod break;
1006*3d8817e4Smiod case M32C_OPERAND_BITBASE16_16_U8 :
1007*3d8817e4Smiod errmsg = parse_unsigned_bitbase8 (cd, strp, M32C_OPERAND_BITBASE16_16_U8, (unsigned long *) (& fields->f_dsp_16_u8));
1008*3d8817e4Smiod break;
1009*3d8817e4Smiod case M32C_OPERAND_BITBASE16_8_U11_S :
1010*3d8817e4Smiod errmsg = parse_unsigned_bitbase11 (cd, strp, M32C_OPERAND_BITBASE16_8_U11_S, (unsigned long *) (& fields->f_bitbase16_u11_S));
1011*3d8817e4Smiod break;
1012*3d8817e4Smiod case M32C_OPERAND_BITBASE32_16_S11_UNPREFIXED :
1013*3d8817e4Smiod errmsg = parse_signed_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_16_S11_UNPREFIXED, (long *) (& fields->f_bitbase32_16_s11_unprefixed));
1014*3d8817e4Smiod break;
1015*3d8817e4Smiod case M32C_OPERAND_BITBASE32_16_S19_UNPREFIXED :
1016*3d8817e4Smiod errmsg = parse_signed_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_16_S19_UNPREFIXED, (long *) (& fields->f_bitbase32_16_s19_unprefixed));
1017*3d8817e4Smiod break;
1018*3d8817e4Smiod case M32C_OPERAND_BITBASE32_16_U11_UNPREFIXED :
1019*3d8817e4Smiod errmsg = parse_unsigned_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_16_U11_UNPREFIXED, (unsigned long *) (& fields->f_bitbase32_16_u11_unprefixed));
1020*3d8817e4Smiod break;
1021*3d8817e4Smiod case M32C_OPERAND_BITBASE32_16_U19_UNPREFIXED :
1022*3d8817e4Smiod errmsg = parse_unsigned_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_16_U19_UNPREFIXED, (unsigned long *) (& fields->f_bitbase32_16_u19_unprefixed));
1023*3d8817e4Smiod break;
1024*3d8817e4Smiod case M32C_OPERAND_BITBASE32_16_U27_UNPREFIXED :
1025*3d8817e4Smiod errmsg = parse_unsigned_bitbase27 (cd, strp, M32C_OPERAND_BITBASE32_16_U27_UNPREFIXED, (unsigned long *) (& fields->f_bitbase32_16_u27_unprefixed));
1026*3d8817e4Smiod break;
1027*3d8817e4Smiod case M32C_OPERAND_BITBASE32_24_S11_PREFIXED :
1028*3d8817e4Smiod errmsg = parse_signed_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_24_S11_PREFIXED, (long *) (& fields->f_bitbase32_24_s11_prefixed));
1029*3d8817e4Smiod break;
1030*3d8817e4Smiod case M32C_OPERAND_BITBASE32_24_S19_PREFIXED :
1031*3d8817e4Smiod errmsg = parse_signed_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_24_S19_PREFIXED, (long *) (& fields->f_bitbase32_24_s19_prefixed));
1032*3d8817e4Smiod break;
1033*3d8817e4Smiod case M32C_OPERAND_BITBASE32_24_U11_PREFIXED :
1034*3d8817e4Smiod errmsg = parse_unsigned_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_24_U11_PREFIXED, (unsigned long *) (& fields->f_bitbase32_24_u11_prefixed));
1035*3d8817e4Smiod break;
1036*3d8817e4Smiod case M32C_OPERAND_BITBASE32_24_U19_PREFIXED :
1037*3d8817e4Smiod errmsg = parse_unsigned_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_24_U19_PREFIXED, (unsigned long *) (& fields->f_bitbase32_24_u19_prefixed));
1038*3d8817e4Smiod break;
1039*3d8817e4Smiod case M32C_OPERAND_BITBASE32_24_U27_PREFIXED :
1040*3d8817e4Smiod errmsg = parse_unsigned_bitbase27 (cd, strp, M32C_OPERAND_BITBASE32_24_U27_PREFIXED, (unsigned long *) (& fields->f_bitbase32_24_u27_prefixed));
1041*3d8817e4Smiod break;
1042*3d8817e4Smiod case M32C_OPERAND_BITNO16R :
1043*3d8817e4Smiod errmsg = parse_Bitno16R (cd, strp, M32C_OPERAND_BITNO16R, (unsigned long *) (& fields->f_dsp_16_u8));
1044*3d8817e4Smiod break;
1045*3d8817e4Smiod case M32C_OPERAND_BITNO32PREFIXED :
1046*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, M32C_OPERAND_BITNO32PREFIXED, (unsigned long *) (& fields->f_bitno32_prefixed));
1047*3d8817e4Smiod break;
1048*3d8817e4Smiod case M32C_OPERAND_BITNO32UNPREFIXED :
1049*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, M32C_OPERAND_BITNO32UNPREFIXED, (unsigned long *) (& fields->f_bitno32_unprefixed));
1050*3d8817e4Smiod break;
1051*3d8817e4Smiod case M32C_OPERAND_DSP_10_U6 :
1052*3d8817e4Smiod errmsg = parse_unsigned6 (cd, strp, M32C_OPERAND_DSP_10_U6, (unsigned long *) (& fields->f_dsp_10_u6));
1053*3d8817e4Smiod break;
1054*3d8817e4Smiod case M32C_OPERAND_DSP_16_S16 :
1055*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_16_S16, (long *) (& fields->f_dsp_16_s16));
1056*3d8817e4Smiod break;
1057*3d8817e4Smiod case M32C_OPERAND_DSP_16_S8 :
1058*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_16_S8, (long *) (& fields->f_dsp_16_s8));
1059*3d8817e4Smiod break;
1060*3d8817e4Smiod case M32C_OPERAND_DSP_16_U16 :
1061*3d8817e4Smiod errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_16_U16, (unsigned long *) (& fields->f_dsp_16_u16));
1062*3d8817e4Smiod break;
1063*3d8817e4Smiod case M32C_OPERAND_DSP_16_U20 :
1064*3d8817e4Smiod errmsg = parse_unsigned20 (cd, strp, M32C_OPERAND_DSP_16_U20, (unsigned long *) (& fields->f_dsp_16_u24));
1065*3d8817e4Smiod break;
1066*3d8817e4Smiod case M32C_OPERAND_DSP_16_U24 :
1067*3d8817e4Smiod errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_16_U24, (unsigned long *) (& fields->f_dsp_16_u24));
1068*3d8817e4Smiod break;
1069*3d8817e4Smiod case M32C_OPERAND_DSP_16_U8 :
1070*3d8817e4Smiod errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_16_U8, (unsigned long *) (& fields->f_dsp_16_u8));
1071*3d8817e4Smiod break;
1072*3d8817e4Smiod case M32C_OPERAND_DSP_24_S16 :
1073*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_24_S16, (long *) (& fields->f_dsp_24_s16));
1074*3d8817e4Smiod break;
1075*3d8817e4Smiod case M32C_OPERAND_DSP_24_S8 :
1076*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_24_S8, (long *) (& fields->f_dsp_24_s8));
1077*3d8817e4Smiod break;
1078*3d8817e4Smiod case M32C_OPERAND_DSP_24_U16 :
1079*3d8817e4Smiod errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_24_U16, (unsigned long *) (& fields->f_dsp_24_u16));
1080*3d8817e4Smiod break;
1081*3d8817e4Smiod case M32C_OPERAND_DSP_24_U20 :
1082*3d8817e4Smiod errmsg = parse_unsigned20 (cd, strp, M32C_OPERAND_DSP_24_U20, (unsigned long *) (& fields->f_dsp_24_u24));
1083*3d8817e4Smiod break;
1084*3d8817e4Smiod case M32C_OPERAND_DSP_24_U24 :
1085*3d8817e4Smiod errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_24_U24, (unsigned long *) (& fields->f_dsp_24_u24));
1086*3d8817e4Smiod break;
1087*3d8817e4Smiod case M32C_OPERAND_DSP_24_U8 :
1088*3d8817e4Smiod errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_24_U8, (unsigned long *) (& fields->f_dsp_24_u8));
1089*3d8817e4Smiod break;
1090*3d8817e4Smiod case M32C_OPERAND_DSP_32_S16 :
1091*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_32_S16, (long *) (& fields->f_dsp_32_s16));
1092*3d8817e4Smiod break;
1093*3d8817e4Smiod case M32C_OPERAND_DSP_32_S8 :
1094*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_32_S8, (long *) (& fields->f_dsp_32_s8));
1095*3d8817e4Smiod break;
1096*3d8817e4Smiod case M32C_OPERAND_DSP_32_U16 :
1097*3d8817e4Smiod errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_32_U16, (unsigned long *) (& fields->f_dsp_32_u16));
1098*3d8817e4Smiod break;
1099*3d8817e4Smiod case M32C_OPERAND_DSP_32_U20 :
1100*3d8817e4Smiod errmsg = parse_unsigned20 (cd, strp, M32C_OPERAND_DSP_32_U20, (unsigned long *) (& fields->f_dsp_32_u24));
1101*3d8817e4Smiod break;
1102*3d8817e4Smiod case M32C_OPERAND_DSP_32_U24 :
1103*3d8817e4Smiod errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_32_U24, (unsigned long *) (& fields->f_dsp_32_u24));
1104*3d8817e4Smiod break;
1105*3d8817e4Smiod case M32C_OPERAND_DSP_32_U8 :
1106*3d8817e4Smiod errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_32_U8, (unsigned long *) (& fields->f_dsp_32_u8));
1107*3d8817e4Smiod break;
1108*3d8817e4Smiod case M32C_OPERAND_DSP_40_S16 :
1109*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_40_S16, (long *) (& fields->f_dsp_40_s16));
1110*3d8817e4Smiod break;
1111*3d8817e4Smiod case M32C_OPERAND_DSP_40_S8 :
1112*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_40_S8, (long *) (& fields->f_dsp_40_s8));
1113*3d8817e4Smiod break;
1114*3d8817e4Smiod case M32C_OPERAND_DSP_40_U16 :
1115*3d8817e4Smiod errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_40_U16, (unsigned long *) (& fields->f_dsp_40_u16));
1116*3d8817e4Smiod break;
1117*3d8817e4Smiod case M32C_OPERAND_DSP_40_U24 :
1118*3d8817e4Smiod errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_40_U24, (unsigned long *) (& fields->f_dsp_40_u24));
1119*3d8817e4Smiod break;
1120*3d8817e4Smiod case M32C_OPERAND_DSP_40_U8 :
1121*3d8817e4Smiod errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_40_U8, (unsigned long *) (& fields->f_dsp_40_u8));
1122*3d8817e4Smiod break;
1123*3d8817e4Smiod case M32C_OPERAND_DSP_48_S16 :
1124*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_48_S16, (long *) (& fields->f_dsp_48_s16));
1125*3d8817e4Smiod break;
1126*3d8817e4Smiod case M32C_OPERAND_DSP_48_S8 :
1127*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_48_S8, (long *) (& fields->f_dsp_48_s8));
1128*3d8817e4Smiod break;
1129*3d8817e4Smiod case M32C_OPERAND_DSP_48_U16 :
1130*3d8817e4Smiod errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_48_U16, (unsigned long *) (& fields->f_dsp_48_u16));
1131*3d8817e4Smiod break;
1132*3d8817e4Smiod case M32C_OPERAND_DSP_48_U24 :
1133*3d8817e4Smiod errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_48_U24, (unsigned long *) (& fields->f_dsp_48_u24));
1134*3d8817e4Smiod break;
1135*3d8817e4Smiod case M32C_OPERAND_DSP_48_U8 :
1136*3d8817e4Smiod errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_48_U8, (unsigned long *) (& fields->f_dsp_48_u8));
1137*3d8817e4Smiod break;
1138*3d8817e4Smiod case M32C_OPERAND_DSP_8_S24 :
1139*3d8817e4Smiod errmsg = parse_signed24 (cd, strp, M32C_OPERAND_DSP_8_S24, (long *) (& fields->f_dsp_8_s24));
1140*3d8817e4Smiod break;
1141*3d8817e4Smiod case M32C_OPERAND_DSP_8_S8 :
1142*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_8_S8, (long *) (& fields->f_dsp_8_s8));
1143*3d8817e4Smiod break;
1144*3d8817e4Smiod case M32C_OPERAND_DSP_8_U16 :
1145*3d8817e4Smiod errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_8_U16, (unsigned long *) (& fields->f_dsp_8_u16));
1146*3d8817e4Smiod break;
1147*3d8817e4Smiod case M32C_OPERAND_DSP_8_U24 :
1148*3d8817e4Smiod errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_8_U24, (unsigned long *) (& fields->f_dsp_8_u24));
1149*3d8817e4Smiod break;
1150*3d8817e4Smiod case M32C_OPERAND_DSP_8_U6 :
1151*3d8817e4Smiod errmsg = parse_unsigned6 (cd, strp, M32C_OPERAND_DSP_8_U6, (unsigned long *) (& fields->f_dsp_8_u6));
1152*3d8817e4Smiod break;
1153*3d8817e4Smiod case M32C_OPERAND_DSP_8_U8 :
1154*3d8817e4Smiod errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_8_U8, (unsigned long *) (& fields->f_dsp_8_u8));
1155*3d8817e4Smiod break;
1156*3d8817e4Smiod case M32C_OPERAND_DST16AN :
1157*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst16_an);
1158*3d8817e4Smiod break;
1159*3d8817e4Smiod case M32C_OPERAND_DST16AN_S :
1160*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst16_an_s);
1161*3d8817e4Smiod break;
1162*3d8817e4Smiod case M32C_OPERAND_DST16ANHI :
1163*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst16_an);
1164*3d8817e4Smiod break;
1165*3d8817e4Smiod case M32C_OPERAND_DST16ANQI :
1166*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst16_an);
1167*3d8817e4Smiod break;
1168*3d8817e4Smiod case M32C_OPERAND_DST16ANQI_S :
1169*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst16_rn_QI_s);
1170*3d8817e4Smiod break;
1171*3d8817e4Smiod case M32C_OPERAND_DST16ANSI :
1172*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_SI, & fields->f_dst16_an);
1173*3d8817e4Smiod break;
1174*3d8817e4Smiod case M32C_OPERAND_DST16RNEXTQI :
1175*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_ext_QI, & fields->f_dst16_rn_ext);
1176*3d8817e4Smiod break;
1177*3d8817e4Smiod case M32C_OPERAND_DST16RNHI :
1178*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst16_rn);
1179*3d8817e4Smiod break;
1180*3d8817e4Smiod case M32C_OPERAND_DST16RNQI :
1181*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst16_rn);
1182*3d8817e4Smiod break;
1183*3d8817e4Smiod case M32C_OPERAND_DST16RNQI_S :
1184*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0l_r0h, & fields->f_dst16_rn_QI_s);
1185*3d8817e4Smiod break;
1186*3d8817e4Smiod case M32C_OPERAND_DST16RNSI :
1187*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_dst16_rn);
1188*3d8817e4Smiod break;
1189*3d8817e4Smiod case M32C_OPERAND_DST32ANEXTUNPREFIXED :
1190*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
1191*3d8817e4Smiod break;
1192*3d8817e4Smiod case M32C_OPERAND_DST32ANPREFIXED :
1193*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_prefixed);
1194*3d8817e4Smiod break;
1195*3d8817e4Smiod case M32C_OPERAND_DST32ANPREFIXEDHI :
1196*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst32_an_prefixed);
1197*3d8817e4Smiod break;
1198*3d8817e4Smiod case M32C_OPERAND_DST32ANPREFIXEDQI :
1199*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst32_an_prefixed);
1200*3d8817e4Smiod break;
1201*3d8817e4Smiod case M32C_OPERAND_DST32ANPREFIXEDSI :
1202*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_prefixed);
1203*3d8817e4Smiod break;
1204*3d8817e4Smiod case M32C_OPERAND_DST32ANUNPREFIXED :
1205*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
1206*3d8817e4Smiod break;
1207*3d8817e4Smiod case M32C_OPERAND_DST32ANUNPREFIXEDHI :
1208*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst32_an_unprefixed);
1209*3d8817e4Smiod break;
1210*3d8817e4Smiod case M32C_OPERAND_DST32ANUNPREFIXEDQI :
1211*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst32_an_unprefixed);
1212*3d8817e4Smiod break;
1213*3d8817e4Smiod case M32C_OPERAND_DST32ANUNPREFIXEDSI :
1214*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
1215*3d8817e4Smiod break;
1216*3d8817e4Smiod case M32C_OPERAND_DST32R0HI_S :
1217*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0, & junk);
1218*3d8817e4Smiod break;
1219*3d8817e4Smiod case M32C_OPERAND_DST32R0QI_S :
1220*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0l, & junk);
1221*3d8817e4Smiod break;
1222*3d8817e4Smiod case M32C_OPERAND_DST32RNEXTUNPREFIXEDHI :
1223*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_ext_HI, & fields->f_dst32_rn_ext_unprefixed);
1224*3d8817e4Smiod break;
1225*3d8817e4Smiod case M32C_OPERAND_DST32RNEXTUNPREFIXEDQI :
1226*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_ext_QI, & fields->f_dst32_rn_ext_unprefixed);
1227*3d8817e4Smiod break;
1228*3d8817e4Smiod case M32C_OPERAND_DST32RNPREFIXEDHI :
1229*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst32_rn_prefixed_HI);
1230*3d8817e4Smiod break;
1231*3d8817e4Smiod case M32C_OPERAND_DST32RNPREFIXEDQI :
1232*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_prefixed_QI);
1233*3d8817e4Smiod break;
1234*3d8817e4Smiod case M32C_OPERAND_DST32RNPREFIXEDSI :
1235*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_dst32_rn_prefixed_SI);
1236*3d8817e4Smiod break;
1237*3d8817e4Smiod case M32C_OPERAND_DST32RNUNPREFIXEDHI :
1238*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst32_rn_unprefixed_HI);
1239*3d8817e4Smiod break;
1240*3d8817e4Smiod case M32C_OPERAND_DST32RNUNPREFIXEDQI :
1241*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_unprefixed_QI);
1242*3d8817e4Smiod break;
1243*3d8817e4Smiod case M32C_OPERAND_DST32RNUNPREFIXEDSI :
1244*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_dst32_rn_unprefixed_SI);
1245*3d8817e4Smiod break;
1246*3d8817e4Smiod case M32C_OPERAND_G :
1247*3d8817e4Smiod errmsg = parse_G (cd, strp, M32C_OPERAND_G, (long *) (& junk));
1248*3d8817e4Smiod break;
1249*3d8817e4Smiod case M32C_OPERAND_IMM_12_S4 :
1250*3d8817e4Smiod errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_12_S4, (long *) (& fields->f_imm_12_s4));
1251*3d8817e4Smiod break;
1252*3d8817e4Smiod case M32C_OPERAND_IMM_12_S4N :
1253*3d8817e4Smiod errmsg = parse_signed4n (cd, strp, M32C_OPERAND_IMM_12_S4N, (long *) (& fields->f_imm_12_s4));
1254*3d8817e4Smiod break;
1255*3d8817e4Smiod case M32C_OPERAND_IMM_13_U3 :
1256*3d8817e4Smiod errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_13_U3, (long *) (& fields->f_imm_13_u3));
1257*3d8817e4Smiod break;
1258*3d8817e4Smiod case M32C_OPERAND_IMM_16_HI :
1259*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_16_HI, (long *) (& fields->f_dsp_16_s16));
1260*3d8817e4Smiod break;
1261*3d8817e4Smiod case M32C_OPERAND_IMM_16_QI :
1262*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_16_QI, (long *) (& fields->f_dsp_16_s8));
1263*3d8817e4Smiod break;
1264*3d8817e4Smiod case M32C_OPERAND_IMM_16_SI :
1265*3d8817e4Smiod errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_16_SI, (long *) (& fields->f_dsp_16_s32));
1266*3d8817e4Smiod break;
1267*3d8817e4Smiod case M32C_OPERAND_IMM_20_S4 :
1268*3d8817e4Smiod errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_20_S4, (long *) (& fields->f_imm_20_s4));
1269*3d8817e4Smiod break;
1270*3d8817e4Smiod case M32C_OPERAND_IMM_24_HI :
1271*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_24_HI, (long *) (& fields->f_dsp_24_s16));
1272*3d8817e4Smiod break;
1273*3d8817e4Smiod case M32C_OPERAND_IMM_24_QI :
1274*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_24_QI, (long *) (& fields->f_dsp_24_s8));
1275*3d8817e4Smiod break;
1276*3d8817e4Smiod case M32C_OPERAND_IMM_24_SI :
1277*3d8817e4Smiod errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_24_SI, (long *) (& fields->f_dsp_24_s32));
1278*3d8817e4Smiod break;
1279*3d8817e4Smiod case M32C_OPERAND_IMM_32_HI :
1280*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_32_HI, (long *) (& fields->f_dsp_32_s16));
1281*3d8817e4Smiod break;
1282*3d8817e4Smiod case M32C_OPERAND_IMM_32_QI :
1283*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_32_QI, (long *) (& fields->f_dsp_32_s8));
1284*3d8817e4Smiod break;
1285*3d8817e4Smiod case M32C_OPERAND_IMM_32_SI :
1286*3d8817e4Smiod errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_32_SI, (long *) (& fields->f_dsp_32_s32));
1287*3d8817e4Smiod break;
1288*3d8817e4Smiod case M32C_OPERAND_IMM_40_HI :
1289*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_40_HI, (long *) (& fields->f_dsp_40_s16));
1290*3d8817e4Smiod break;
1291*3d8817e4Smiod case M32C_OPERAND_IMM_40_QI :
1292*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_40_QI, (long *) (& fields->f_dsp_40_s8));
1293*3d8817e4Smiod break;
1294*3d8817e4Smiod case M32C_OPERAND_IMM_40_SI :
1295*3d8817e4Smiod errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_40_SI, (long *) (& fields->f_dsp_40_s32));
1296*3d8817e4Smiod break;
1297*3d8817e4Smiod case M32C_OPERAND_IMM_48_HI :
1298*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_48_HI, (long *) (& fields->f_dsp_48_s16));
1299*3d8817e4Smiod break;
1300*3d8817e4Smiod case M32C_OPERAND_IMM_48_QI :
1301*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_48_QI, (long *) (& fields->f_dsp_48_s8));
1302*3d8817e4Smiod break;
1303*3d8817e4Smiod case M32C_OPERAND_IMM_48_SI :
1304*3d8817e4Smiod errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_48_SI, (long *) (& fields->f_dsp_48_s32));
1305*3d8817e4Smiod break;
1306*3d8817e4Smiod case M32C_OPERAND_IMM_56_HI :
1307*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_56_HI, (long *) (& fields->f_dsp_56_s16));
1308*3d8817e4Smiod break;
1309*3d8817e4Smiod case M32C_OPERAND_IMM_56_QI :
1310*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_56_QI, (long *) (& fields->f_dsp_56_s8));
1311*3d8817e4Smiod break;
1312*3d8817e4Smiod case M32C_OPERAND_IMM_64_HI :
1313*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_64_HI, (long *) (& fields->f_dsp_64_s16));
1314*3d8817e4Smiod break;
1315*3d8817e4Smiod case M32C_OPERAND_IMM_8_HI :
1316*3d8817e4Smiod errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_8_HI, (long *) (& fields->f_dsp_8_s16));
1317*3d8817e4Smiod break;
1318*3d8817e4Smiod case M32C_OPERAND_IMM_8_QI :
1319*3d8817e4Smiod errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_8_QI, (long *) (& fields->f_dsp_8_s8));
1320*3d8817e4Smiod break;
1321*3d8817e4Smiod case M32C_OPERAND_IMM_8_S4 :
1322*3d8817e4Smiod errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_8_S4, (long *) (& fields->f_imm_8_s4));
1323*3d8817e4Smiod break;
1324*3d8817e4Smiod case M32C_OPERAND_IMM_8_S4N :
1325*3d8817e4Smiod errmsg = parse_signed4n (cd, strp, M32C_OPERAND_IMM_8_S4N, (long *) (& fields->f_imm_8_s4));
1326*3d8817e4Smiod break;
1327*3d8817e4Smiod case M32C_OPERAND_IMM_SH_12_S4 :
1328*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_shimm, & fields->f_imm_12_s4);
1329*3d8817e4Smiod break;
1330*3d8817e4Smiod case M32C_OPERAND_IMM_SH_20_S4 :
1331*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_shimm, & fields->f_imm_20_s4);
1332*3d8817e4Smiod break;
1333*3d8817e4Smiod case M32C_OPERAND_IMM_SH_8_S4 :
1334*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_shimm, & fields->f_imm_8_s4);
1335*3d8817e4Smiod break;
1336*3d8817e4Smiod case M32C_OPERAND_IMM1_S :
1337*3d8817e4Smiod errmsg = parse_imm1_S (cd, strp, M32C_OPERAND_IMM1_S, (long *) (& fields->f_imm1_S));
1338*3d8817e4Smiod break;
1339*3d8817e4Smiod case M32C_OPERAND_IMM3_S :
1340*3d8817e4Smiod errmsg = parse_imm3_S (cd, strp, M32C_OPERAND_IMM3_S, (long *) (& fields->f_imm3_S));
1341*3d8817e4Smiod break;
1342*3d8817e4Smiod case M32C_OPERAND_LAB_16_8 :
1343*3d8817e4Smiod {
1344*3d8817e4Smiod bfd_vma value = 0;
1345*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_16_8, 0, NULL, & value);
1346*3d8817e4Smiod fields->f_lab_16_8 = value;
1347*3d8817e4Smiod }
1348*3d8817e4Smiod break;
1349*3d8817e4Smiod case M32C_OPERAND_LAB_24_8 :
1350*3d8817e4Smiod {
1351*3d8817e4Smiod bfd_vma value = 0;
1352*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_24_8, 0, NULL, & value);
1353*3d8817e4Smiod fields->f_lab_24_8 = value;
1354*3d8817e4Smiod }
1355*3d8817e4Smiod break;
1356*3d8817e4Smiod case M32C_OPERAND_LAB_32_8 :
1357*3d8817e4Smiod {
1358*3d8817e4Smiod bfd_vma value = 0;
1359*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_32_8, 0, NULL, & value);
1360*3d8817e4Smiod fields->f_lab_32_8 = value;
1361*3d8817e4Smiod }
1362*3d8817e4Smiod break;
1363*3d8817e4Smiod case M32C_OPERAND_LAB_40_8 :
1364*3d8817e4Smiod {
1365*3d8817e4Smiod bfd_vma value = 0;
1366*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_40_8, 0, NULL, & value);
1367*3d8817e4Smiod fields->f_lab_40_8 = value;
1368*3d8817e4Smiod }
1369*3d8817e4Smiod break;
1370*3d8817e4Smiod case M32C_OPERAND_LAB_5_3 :
1371*3d8817e4Smiod {
1372*3d8817e4Smiod bfd_vma value = 0;
1373*3d8817e4Smiod errmsg = parse_lab_5_3 (cd, strp, M32C_OPERAND_LAB_5_3, 0, NULL, & value);
1374*3d8817e4Smiod fields->f_lab_5_3 = value;
1375*3d8817e4Smiod }
1376*3d8817e4Smiod break;
1377*3d8817e4Smiod case M32C_OPERAND_LAB_8_16 :
1378*3d8817e4Smiod {
1379*3d8817e4Smiod bfd_vma value = 0;
1380*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_8_16, 0, NULL, & value);
1381*3d8817e4Smiod fields->f_lab_8_16 = value;
1382*3d8817e4Smiod }
1383*3d8817e4Smiod break;
1384*3d8817e4Smiod case M32C_OPERAND_LAB_8_24 :
1385*3d8817e4Smiod {
1386*3d8817e4Smiod bfd_vma value = 0;
1387*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_8_24, 0, NULL, & value);
1388*3d8817e4Smiod fields->f_lab_8_24 = value;
1389*3d8817e4Smiod }
1390*3d8817e4Smiod break;
1391*3d8817e4Smiod case M32C_OPERAND_LAB_8_8 :
1392*3d8817e4Smiod {
1393*3d8817e4Smiod bfd_vma value = 0;
1394*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_8_8, 0, NULL, & value);
1395*3d8817e4Smiod fields->f_lab_8_8 = value;
1396*3d8817e4Smiod }
1397*3d8817e4Smiod break;
1398*3d8817e4Smiod case M32C_OPERAND_LAB32_JMP_S :
1399*3d8817e4Smiod {
1400*3d8817e4Smiod bfd_vma value = 0;
1401*3d8817e4Smiod errmsg = parse_lab_5_3 (cd, strp, M32C_OPERAND_LAB32_JMP_S, 0, NULL, & value);
1402*3d8817e4Smiod fields->f_lab32_jmp_s = value;
1403*3d8817e4Smiod }
1404*3d8817e4Smiod break;
1405*3d8817e4Smiod case M32C_OPERAND_Q :
1406*3d8817e4Smiod errmsg = parse_Q (cd, strp, M32C_OPERAND_Q, (long *) (& junk));
1407*3d8817e4Smiod break;
1408*3d8817e4Smiod case M32C_OPERAND_R0 :
1409*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0, & junk);
1410*3d8817e4Smiod break;
1411*3d8817e4Smiod case M32C_OPERAND_R0H :
1412*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0h, & junk);
1413*3d8817e4Smiod break;
1414*3d8817e4Smiod case M32C_OPERAND_R0L :
1415*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0l, & junk);
1416*3d8817e4Smiod break;
1417*3d8817e4Smiod case M32C_OPERAND_R1 :
1418*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r1, & junk);
1419*3d8817e4Smiod break;
1420*3d8817e4Smiod case M32C_OPERAND_R1R2R0 :
1421*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r1r2r0, & junk);
1422*3d8817e4Smiod break;
1423*3d8817e4Smiod case M32C_OPERAND_R2 :
1424*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r2, & junk);
1425*3d8817e4Smiod break;
1426*3d8817e4Smiod case M32C_OPERAND_R2R0 :
1427*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r2r0, & junk);
1428*3d8817e4Smiod break;
1429*3d8817e4Smiod case M32C_OPERAND_R3 :
1430*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r3, & junk);
1431*3d8817e4Smiod break;
1432*3d8817e4Smiod case M32C_OPERAND_R3R1 :
1433*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r3r1, & junk);
1434*3d8817e4Smiod break;
1435*3d8817e4Smiod case M32C_OPERAND_REGSETPOP :
1436*3d8817e4Smiod errmsg = parse_pop_regset (cd, strp, M32C_OPERAND_REGSETPOP, (unsigned long *) (& fields->f_8_8));
1437*3d8817e4Smiod break;
1438*3d8817e4Smiod case M32C_OPERAND_REGSETPUSH :
1439*3d8817e4Smiod errmsg = parse_push_regset (cd, strp, M32C_OPERAND_REGSETPUSH, (unsigned long *) (& fields->f_8_8));
1440*3d8817e4Smiod break;
1441*3d8817e4Smiod case M32C_OPERAND_RN16_PUSH_S :
1442*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_4_1);
1443*3d8817e4Smiod break;
1444*3d8817e4Smiod case M32C_OPERAND_S :
1445*3d8817e4Smiod errmsg = parse_S (cd, strp, M32C_OPERAND_S, (long *) (& junk));
1446*3d8817e4Smiod break;
1447*3d8817e4Smiod case M32C_OPERAND_SRC16AN :
1448*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src16_an);
1449*3d8817e4Smiod break;
1450*3d8817e4Smiod case M32C_OPERAND_SRC16ANHI :
1451*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_src16_an);
1452*3d8817e4Smiod break;
1453*3d8817e4Smiod case M32C_OPERAND_SRC16ANQI :
1454*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_src16_an);
1455*3d8817e4Smiod break;
1456*3d8817e4Smiod case M32C_OPERAND_SRC16RNHI :
1457*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_src16_rn);
1458*3d8817e4Smiod break;
1459*3d8817e4Smiod case M32C_OPERAND_SRC16RNQI :
1460*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_src16_rn);
1461*3d8817e4Smiod break;
1462*3d8817e4Smiod case M32C_OPERAND_SRC32ANPREFIXED :
1463*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_prefixed);
1464*3d8817e4Smiod break;
1465*3d8817e4Smiod case M32C_OPERAND_SRC32ANPREFIXEDHI :
1466*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_src32_an_prefixed);
1467*3d8817e4Smiod break;
1468*3d8817e4Smiod case M32C_OPERAND_SRC32ANPREFIXEDQI :
1469*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_src32_an_prefixed);
1470*3d8817e4Smiod break;
1471*3d8817e4Smiod case M32C_OPERAND_SRC32ANPREFIXEDSI :
1472*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_prefixed);
1473*3d8817e4Smiod break;
1474*3d8817e4Smiod case M32C_OPERAND_SRC32ANUNPREFIXED :
1475*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_unprefixed);
1476*3d8817e4Smiod break;
1477*3d8817e4Smiod case M32C_OPERAND_SRC32ANUNPREFIXEDHI :
1478*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_src32_an_unprefixed);
1479*3d8817e4Smiod break;
1480*3d8817e4Smiod case M32C_OPERAND_SRC32ANUNPREFIXEDQI :
1481*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_src32_an_unprefixed);
1482*3d8817e4Smiod break;
1483*3d8817e4Smiod case M32C_OPERAND_SRC32ANUNPREFIXEDSI :
1484*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_unprefixed);
1485*3d8817e4Smiod break;
1486*3d8817e4Smiod case M32C_OPERAND_SRC32RNPREFIXEDHI :
1487*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_src32_rn_prefixed_HI);
1488*3d8817e4Smiod break;
1489*3d8817e4Smiod case M32C_OPERAND_SRC32RNPREFIXEDQI :
1490*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_src32_rn_prefixed_QI);
1491*3d8817e4Smiod break;
1492*3d8817e4Smiod case M32C_OPERAND_SRC32RNPREFIXEDSI :
1493*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_src32_rn_prefixed_SI);
1494*3d8817e4Smiod break;
1495*3d8817e4Smiod case M32C_OPERAND_SRC32RNUNPREFIXEDHI :
1496*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_src32_rn_unprefixed_HI);
1497*3d8817e4Smiod break;
1498*3d8817e4Smiod case M32C_OPERAND_SRC32RNUNPREFIXEDQI :
1499*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_src32_rn_unprefixed_QI);
1500*3d8817e4Smiod break;
1501*3d8817e4Smiod case M32C_OPERAND_SRC32RNUNPREFIXEDSI :
1502*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_src32_rn_unprefixed_SI);
1503*3d8817e4Smiod break;
1504*3d8817e4Smiod case M32C_OPERAND_SRCDST16_R0L_R0H_S_NORMAL :
1505*3d8817e4Smiod errmsg = parse_r0l_r0h (cd, strp, M32C_OPERAND_SRCDST16_R0L_R0H_S_NORMAL, (long *) (& fields->f_5_1));
1506*3d8817e4Smiod break;
1507*3d8817e4Smiod case M32C_OPERAND_X :
1508*3d8817e4Smiod errmsg = parse_X (cd, strp, M32C_OPERAND_X, (long *) (& junk));
1509*3d8817e4Smiod break;
1510*3d8817e4Smiod case M32C_OPERAND_Z :
1511*3d8817e4Smiod errmsg = parse_Z (cd, strp, M32C_OPERAND_Z, (long *) (& junk));
1512*3d8817e4Smiod break;
1513*3d8817e4Smiod case M32C_OPERAND_COND16_16 :
1514*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16, & fields->f_dsp_16_u8);
1515*3d8817e4Smiod break;
1516*3d8817e4Smiod case M32C_OPERAND_COND16_24 :
1517*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16, & fields->f_dsp_24_u8);
1518*3d8817e4Smiod break;
1519*3d8817e4Smiod case M32C_OPERAND_COND16_32 :
1520*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16, & fields->f_dsp_32_u8);
1521*3d8817e4Smiod break;
1522*3d8817e4Smiod case M32C_OPERAND_COND16C :
1523*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16c, & fields->f_cond16);
1524*3d8817e4Smiod break;
1525*3d8817e4Smiod case M32C_OPERAND_COND16J :
1526*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16j, & fields->f_cond16);
1527*3d8817e4Smiod break;
1528*3d8817e4Smiod case M32C_OPERAND_COND16J5 :
1529*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16j_5, & fields->f_cond16j_5);
1530*3d8817e4Smiod break;
1531*3d8817e4Smiod case M32C_OPERAND_COND32 :
1532*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_cond32);
1533*3d8817e4Smiod break;
1534*3d8817e4Smiod case M32C_OPERAND_COND32_16 :
1535*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_16_u8);
1536*3d8817e4Smiod break;
1537*3d8817e4Smiod case M32C_OPERAND_COND32_24 :
1538*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_24_u8);
1539*3d8817e4Smiod break;
1540*3d8817e4Smiod case M32C_OPERAND_COND32_32 :
1541*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_32_u8);
1542*3d8817e4Smiod break;
1543*3d8817e4Smiod case M32C_OPERAND_COND32_40 :
1544*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_40_u8);
1545*3d8817e4Smiod break;
1546*3d8817e4Smiod case M32C_OPERAND_COND32J :
1547*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_cond32j);
1548*3d8817e4Smiod break;
1549*3d8817e4Smiod case M32C_OPERAND_CR1_PREFIXED_32 :
1550*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr1_32, & fields->f_21_3);
1551*3d8817e4Smiod break;
1552*3d8817e4Smiod case M32C_OPERAND_CR1_UNPREFIXED_32 :
1553*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr1_32, & fields->f_13_3);
1554*3d8817e4Smiod break;
1555*3d8817e4Smiod case M32C_OPERAND_CR16 :
1556*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr_16, & fields->f_9_3);
1557*3d8817e4Smiod break;
1558*3d8817e4Smiod case M32C_OPERAND_CR2_32 :
1559*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr2_32, & fields->f_13_3);
1560*3d8817e4Smiod break;
1561*3d8817e4Smiod case M32C_OPERAND_CR3_PREFIXED_32 :
1562*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr3_32, & fields->f_21_3);
1563*3d8817e4Smiod break;
1564*3d8817e4Smiod case M32C_OPERAND_CR3_UNPREFIXED_32 :
1565*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr3_32, & fields->f_13_3);
1566*3d8817e4Smiod break;
1567*3d8817e4Smiod case M32C_OPERAND_FLAGS16 :
1568*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_flags, & fields->f_9_3);
1569*3d8817e4Smiod break;
1570*3d8817e4Smiod case M32C_OPERAND_FLAGS32 :
1571*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_flags, & fields->f_13_3);
1572*3d8817e4Smiod break;
1573*3d8817e4Smiod case M32C_OPERAND_SCCOND32 :
1574*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_cond16);
1575*3d8817e4Smiod break;
1576*3d8817e4Smiod case M32C_OPERAND_SIZE :
1577*3d8817e4Smiod errmsg = parse_size (cd, strp, M32C_OPERAND_SIZE, (long *) (& junk));
1578*3d8817e4Smiod break;
1579*3d8817e4Smiod
1580*3d8817e4Smiod default :
1581*3d8817e4Smiod /* xgettext:c-format */
1582*3d8817e4Smiod fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
1583*3d8817e4Smiod abort ();
1584*3d8817e4Smiod }
1585*3d8817e4Smiod
1586*3d8817e4Smiod return errmsg;
1587*3d8817e4Smiod }
1588*3d8817e4Smiod
1589*3d8817e4Smiod cgen_parse_fn * const m32c_cgen_parse_handlers[] =
1590*3d8817e4Smiod {
1591*3d8817e4Smiod parse_insn_normal,
1592*3d8817e4Smiod };
1593*3d8817e4Smiod
1594*3d8817e4Smiod void
m32c_cgen_init_asm(CGEN_CPU_DESC cd)1595*3d8817e4Smiod m32c_cgen_init_asm (CGEN_CPU_DESC cd)
1596*3d8817e4Smiod {
1597*3d8817e4Smiod m32c_cgen_init_opcode_table (cd);
1598*3d8817e4Smiod m32c_cgen_init_ibld_table (cd);
1599*3d8817e4Smiod cd->parse_handlers = & m32c_cgen_parse_handlers[0];
1600*3d8817e4Smiod cd->parse_operand = m32c_cgen_parse_operand;
1601*3d8817e4Smiod }
1602*3d8817e4Smiod
1603*3d8817e4Smiod
1604*3d8817e4Smiod
1605*3d8817e4Smiod /* Regex construction routine.
1606*3d8817e4Smiod
1607*3d8817e4Smiod This translates an opcode syntax string into a regex string,
1608*3d8817e4Smiod by replacing any non-character syntax element (such as an
1609*3d8817e4Smiod opcode) with the pattern '.*'
1610*3d8817e4Smiod
1611*3d8817e4Smiod It then compiles the regex and stores it in the opcode, for
1612*3d8817e4Smiod later use by m32c_cgen_assemble_insn
1613*3d8817e4Smiod
1614*3d8817e4Smiod Returns NULL for success, an error message for failure. */
1615*3d8817e4Smiod
1616*3d8817e4Smiod char *
m32c_cgen_build_insn_regex(CGEN_INSN * insn)1617*3d8817e4Smiod m32c_cgen_build_insn_regex (CGEN_INSN *insn)
1618*3d8817e4Smiod {
1619*3d8817e4Smiod CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
1620*3d8817e4Smiod const char *mnem = CGEN_INSN_MNEMONIC (insn);
1621*3d8817e4Smiod char rxbuf[CGEN_MAX_RX_ELEMENTS];
1622*3d8817e4Smiod char *rx = rxbuf;
1623*3d8817e4Smiod const CGEN_SYNTAX_CHAR_TYPE *syn;
1624*3d8817e4Smiod int reg_err;
1625*3d8817e4Smiod
1626*3d8817e4Smiod syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
1627*3d8817e4Smiod
1628*3d8817e4Smiod /* Mnemonics come first in the syntax string. */
1629*3d8817e4Smiod if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1630*3d8817e4Smiod return _("missing mnemonic in syntax string");
1631*3d8817e4Smiod ++syn;
1632*3d8817e4Smiod
1633*3d8817e4Smiod /* Generate a case sensitive regular expression that emulates case
1634*3d8817e4Smiod insensitive matching in the "C" locale. We cannot generate a case
1635*3d8817e4Smiod insensitive regular expression because in Turkish locales, 'i' and 'I'
1636*3d8817e4Smiod are not equal modulo case conversion. */
1637*3d8817e4Smiod
1638*3d8817e4Smiod /* Copy the literal mnemonic out of the insn. */
1639*3d8817e4Smiod for (; *mnem; mnem++)
1640*3d8817e4Smiod {
1641*3d8817e4Smiod char c = *mnem;
1642*3d8817e4Smiod
1643*3d8817e4Smiod if (ISALPHA (c))
1644*3d8817e4Smiod {
1645*3d8817e4Smiod *rx++ = '[';
1646*3d8817e4Smiod *rx++ = TOLOWER (c);
1647*3d8817e4Smiod *rx++ = TOUPPER (c);
1648*3d8817e4Smiod *rx++ = ']';
1649*3d8817e4Smiod }
1650*3d8817e4Smiod else
1651*3d8817e4Smiod *rx++ = c;
1652*3d8817e4Smiod }
1653*3d8817e4Smiod
1654*3d8817e4Smiod /* Copy any remaining literals from the syntax string into the rx. */
1655*3d8817e4Smiod for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
1656*3d8817e4Smiod {
1657*3d8817e4Smiod if (CGEN_SYNTAX_CHAR_P (* syn))
1658*3d8817e4Smiod {
1659*3d8817e4Smiod char c = CGEN_SYNTAX_CHAR (* syn);
1660*3d8817e4Smiod
1661*3d8817e4Smiod switch (c)
1662*3d8817e4Smiod {
1663*3d8817e4Smiod /* Escape any regex metacharacters in the syntax. */
1664*3d8817e4Smiod case '.': case '[': case '\\':
1665*3d8817e4Smiod case '*': case '^': case '$':
1666*3d8817e4Smiod
1667*3d8817e4Smiod #ifdef CGEN_ESCAPE_EXTENDED_REGEX
1668*3d8817e4Smiod case '?': case '{': case '}':
1669*3d8817e4Smiod case '(': case ')': case '*':
1670*3d8817e4Smiod case '|': case '+': case ']':
1671*3d8817e4Smiod #endif
1672*3d8817e4Smiod *rx++ = '\\';
1673*3d8817e4Smiod *rx++ = c;
1674*3d8817e4Smiod break;
1675*3d8817e4Smiod
1676*3d8817e4Smiod default:
1677*3d8817e4Smiod if (ISALPHA (c))
1678*3d8817e4Smiod {
1679*3d8817e4Smiod *rx++ = '[';
1680*3d8817e4Smiod *rx++ = TOLOWER (c);
1681*3d8817e4Smiod *rx++ = TOUPPER (c);
1682*3d8817e4Smiod *rx++ = ']';
1683*3d8817e4Smiod }
1684*3d8817e4Smiod else
1685*3d8817e4Smiod *rx++ = c;
1686*3d8817e4Smiod break;
1687*3d8817e4Smiod }
1688*3d8817e4Smiod }
1689*3d8817e4Smiod else
1690*3d8817e4Smiod {
1691*3d8817e4Smiod /* Replace non-syntax fields with globs. */
1692*3d8817e4Smiod *rx++ = '.';
1693*3d8817e4Smiod *rx++ = '*';
1694*3d8817e4Smiod }
1695*3d8817e4Smiod }
1696*3d8817e4Smiod
1697*3d8817e4Smiod /* Trailing whitespace ok. */
1698*3d8817e4Smiod * rx++ = '[';
1699*3d8817e4Smiod * rx++ = ' ';
1700*3d8817e4Smiod * rx++ = '\t';
1701*3d8817e4Smiod * rx++ = ']';
1702*3d8817e4Smiod * rx++ = '*';
1703*3d8817e4Smiod
1704*3d8817e4Smiod /* But anchor it after that. */
1705*3d8817e4Smiod * rx++ = '$';
1706*3d8817e4Smiod * rx = '\0';
1707*3d8817e4Smiod
1708*3d8817e4Smiod CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
1709*3d8817e4Smiod reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
1710*3d8817e4Smiod
1711*3d8817e4Smiod if (reg_err == 0)
1712*3d8817e4Smiod return NULL;
1713*3d8817e4Smiod else
1714*3d8817e4Smiod {
1715*3d8817e4Smiod static char msg[80];
1716*3d8817e4Smiod
1717*3d8817e4Smiod regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
1718*3d8817e4Smiod regfree ((regex_t *) CGEN_INSN_RX (insn));
1719*3d8817e4Smiod free (CGEN_INSN_RX (insn));
1720*3d8817e4Smiod (CGEN_INSN_RX (insn)) = NULL;
1721*3d8817e4Smiod return msg;
1722*3d8817e4Smiod }
1723*3d8817e4Smiod }
1724*3d8817e4Smiod
1725*3d8817e4Smiod
1726*3d8817e4Smiod /* Default insn parser.
1727*3d8817e4Smiod
1728*3d8817e4Smiod The syntax string is scanned and operands are parsed and stored in FIELDS.
1729*3d8817e4Smiod Relocs are queued as we go via other callbacks.
1730*3d8817e4Smiod
1731*3d8817e4Smiod ??? Note that this is currently an all-or-nothing parser. If we fail to
1732*3d8817e4Smiod parse the instruction, we return 0 and the caller will start over from
1733*3d8817e4Smiod the beginning. Backtracking will be necessary in parsing subexpressions,
1734*3d8817e4Smiod but that can be handled there. Not handling backtracking here may get
1735*3d8817e4Smiod expensive in the case of the m68k. Deal with later.
1736*3d8817e4Smiod
1737*3d8817e4Smiod Returns NULL for success, an error message for failure. */
1738*3d8817e4Smiod
1739*3d8817e4Smiod static const char *
parse_insn_normal(CGEN_CPU_DESC cd,const CGEN_INSN * insn,const char ** strp,CGEN_FIELDS * fields)1740*3d8817e4Smiod parse_insn_normal (CGEN_CPU_DESC cd,
1741*3d8817e4Smiod const CGEN_INSN *insn,
1742*3d8817e4Smiod const char **strp,
1743*3d8817e4Smiod CGEN_FIELDS *fields)
1744*3d8817e4Smiod {
1745*3d8817e4Smiod /* ??? Runtime added insns not handled yet. */
1746*3d8817e4Smiod const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
1747*3d8817e4Smiod const char *str = *strp;
1748*3d8817e4Smiod const char *errmsg;
1749*3d8817e4Smiod const char *p;
1750*3d8817e4Smiod const CGEN_SYNTAX_CHAR_TYPE * syn;
1751*3d8817e4Smiod #ifdef CGEN_MNEMONIC_OPERANDS
1752*3d8817e4Smiod /* FIXME: wip */
1753*3d8817e4Smiod int past_opcode_p;
1754*3d8817e4Smiod #endif
1755*3d8817e4Smiod
1756*3d8817e4Smiod /* For now we assume the mnemonic is first (there are no leading operands).
1757*3d8817e4Smiod We can parse it without needing to set up operand parsing.
1758*3d8817e4Smiod GAS's input scrubber will ensure mnemonics are lowercase, but we may
1759*3d8817e4Smiod not be called from GAS. */
1760*3d8817e4Smiod p = CGEN_INSN_MNEMONIC (insn);
1761*3d8817e4Smiod while (*p && TOLOWER (*p) == TOLOWER (*str))
1762*3d8817e4Smiod ++p, ++str;
1763*3d8817e4Smiod
1764*3d8817e4Smiod if (* p)
1765*3d8817e4Smiod return _("unrecognized instruction");
1766*3d8817e4Smiod
1767*3d8817e4Smiod #ifndef CGEN_MNEMONIC_OPERANDS
1768*3d8817e4Smiod if (* str && ! ISSPACE (* str))
1769*3d8817e4Smiod return _("unrecognized instruction");
1770*3d8817e4Smiod #endif
1771*3d8817e4Smiod
1772*3d8817e4Smiod CGEN_INIT_PARSE (cd);
1773*3d8817e4Smiod cgen_init_parse_operand (cd);
1774*3d8817e4Smiod #ifdef CGEN_MNEMONIC_OPERANDS
1775*3d8817e4Smiod past_opcode_p = 0;
1776*3d8817e4Smiod #endif
1777*3d8817e4Smiod
1778*3d8817e4Smiod /* We don't check for (*str != '\0') here because we want to parse
1779*3d8817e4Smiod any trailing fake arguments in the syntax string. */
1780*3d8817e4Smiod syn = CGEN_SYNTAX_STRING (syntax);
1781*3d8817e4Smiod
1782*3d8817e4Smiod /* Mnemonics come first for now, ensure valid string. */
1783*3d8817e4Smiod if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1784*3d8817e4Smiod abort ();
1785*3d8817e4Smiod
1786*3d8817e4Smiod ++syn;
1787*3d8817e4Smiod
1788*3d8817e4Smiod while (* syn != 0)
1789*3d8817e4Smiod {
1790*3d8817e4Smiod /* Non operand chars must match exactly. */
1791*3d8817e4Smiod if (CGEN_SYNTAX_CHAR_P (* syn))
1792*3d8817e4Smiod {
1793*3d8817e4Smiod /* FIXME: While we allow for non-GAS callers above, we assume the
1794*3d8817e4Smiod first char after the mnemonic part is a space. */
1795*3d8817e4Smiod /* FIXME: We also take inappropriate advantage of the fact that
1796*3d8817e4Smiod GAS's input scrubber will remove extraneous blanks. */
1797*3d8817e4Smiod if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
1798*3d8817e4Smiod {
1799*3d8817e4Smiod #ifdef CGEN_MNEMONIC_OPERANDS
1800*3d8817e4Smiod if (CGEN_SYNTAX_CHAR(* syn) == ' ')
1801*3d8817e4Smiod past_opcode_p = 1;
1802*3d8817e4Smiod #endif
1803*3d8817e4Smiod ++ syn;
1804*3d8817e4Smiod ++ str;
1805*3d8817e4Smiod }
1806*3d8817e4Smiod else if (*str)
1807*3d8817e4Smiod {
1808*3d8817e4Smiod /* Syntax char didn't match. Can't be this insn. */
1809*3d8817e4Smiod static char msg [80];
1810*3d8817e4Smiod
1811*3d8817e4Smiod /* xgettext:c-format */
1812*3d8817e4Smiod sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
1813*3d8817e4Smiod CGEN_SYNTAX_CHAR(*syn), *str);
1814*3d8817e4Smiod return msg;
1815*3d8817e4Smiod }
1816*3d8817e4Smiod else
1817*3d8817e4Smiod {
1818*3d8817e4Smiod /* Ran out of input. */
1819*3d8817e4Smiod static char msg [80];
1820*3d8817e4Smiod
1821*3d8817e4Smiod /* xgettext:c-format */
1822*3d8817e4Smiod sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
1823*3d8817e4Smiod CGEN_SYNTAX_CHAR(*syn));
1824*3d8817e4Smiod return msg;
1825*3d8817e4Smiod }
1826*3d8817e4Smiod continue;
1827*3d8817e4Smiod }
1828*3d8817e4Smiod
1829*3d8817e4Smiod /* We have an operand of some sort. */
1830*3d8817e4Smiod errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
1831*3d8817e4Smiod &str, fields);
1832*3d8817e4Smiod if (errmsg)
1833*3d8817e4Smiod return errmsg;
1834*3d8817e4Smiod
1835*3d8817e4Smiod /* Done with this operand, continue with next one. */
1836*3d8817e4Smiod ++ syn;
1837*3d8817e4Smiod }
1838*3d8817e4Smiod
1839*3d8817e4Smiod /* If we're at the end of the syntax string, we're done. */
1840*3d8817e4Smiod if (* syn == 0)
1841*3d8817e4Smiod {
1842*3d8817e4Smiod /* FIXME: For the moment we assume a valid `str' can only contain
1843*3d8817e4Smiod blanks now. IE: We needn't try again with a longer version of
1844*3d8817e4Smiod the insn and it is assumed that longer versions of insns appear
1845*3d8817e4Smiod before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1846*3d8817e4Smiod while (ISSPACE (* str))
1847*3d8817e4Smiod ++ str;
1848*3d8817e4Smiod
1849*3d8817e4Smiod if (* str != '\0')
1850*3d8817e4Smiod return _("junk at end of line"); /* FIXME: would like to include `str' */
1851*3d8817e4Smiod
1852*3d8817e4Smiod return NULL;
1853*3d8817e4Smiod }
1854*3d8817e4Smiod
1855*3d8817e4Smiod /* We couldn't parse it. */
1856*3d8817e4Smiod return _("unrecognized instruction");
1857*3d8817e4Smiod }
1858*3d8817e4Smiod
1859*3d8817e4Smiod /* Main entry point.
1860*3d8817e4Smiod This routine is called for each instruction to be assembled.
1861*3d8817e4Smiod STR points to the insn to be assembled.
1862*3d8817e4Smiod We assume all necessary tables have been initialized.
1863*3d8817e4Smiod The assembled instruction, less any fixups, is stored in BUF.
1864*3d8817e4Smiod Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1865*3d8817e4Smiod still needs to be converted to target byte order, otherwise BUF is an array
1866*3d8817e4Smiod of bytes in target byte order.
1867*3d8817e4Smiod The result is a pointer to the insn's entry in the opcode table,
1868*3d8817e4Smiod or NULL if an error occured (an error message will have already been
1869*3d8817e4Smiod printed).
1870*3d8817e4Smiod
1871*3d8817e4Smiod Note that when processing (non-alias) macro-insns,
1872*3d8817e4Smiod this function recurses.
1873*3d8817e4Smiod
1874*3d8817e4Smiod ??? It's possible to make this cpu-independent.
1875*3d8817e4Smiod One would have to deal with a few minor things.
1876*3d8817e4Smiod At this point in time doing so would be more of a curiosity than useful
1877*3d8817e4Smiod [for example this file isn't _that_ big], but keeping the possibility in
1878*3d8817e4Smiod mind helps keep the design clean. */
1879*3d8817e4Smiod
1880*3d8817e4Smiod const CGEN_INSN *
m32c_cgen_assemble_insn(CGEN_CPU_DESC cd,const char * str,CGEN_FIELDS * fields,CGEN_INSN_BYTES_PTR buf,char ** errmsg)1881*3d8817e4Smiod m32c_cgen_assemble_insn (CGEN_CPU_DESC cd,
1882*3d8817e4Smiod const char *str,
1883*3d8817e4Smiod CGEN_FIELDS *fields,
1884*3d8817e4Smiod CGEN_INSN_BYTES_PTR buf,
1885*3d8817e4Smiod char **errmsg)
1886*3d8817e4Smiod {
1887*3d8817e4Smiod const char *start;
1888*3d8817e4Smiod CGEN_INSN_LIST *ilist;
1889*3d8817e4Smiod const char *parse_errmsg = NULL;
1890*3d8817e4Smiod const char *insert_errmsg = NULL;
1891*3d8817e4Smiod int recognized_mnemonic = 0;
1892*3d8817e4Smiod
1893*3d8817e4Smiod /* Skip leading white space. */
1894*3d8817e4Smiod while (ISSPACE (* str))
1895*3d8817e4Smiod ++ str;
1896*3d8817e4Smiod
1897*3d8817e4Smiod /* The instructions are stored in hashed lists.
1898*3d8817e4Smiod Get the first in the list. */
1899*3d8817e4Smiod ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
1900*3d8817e4Smiod
1901*3d8817e4Smiod /* Keep looking until we find a match. */
1902*3d8817e4Smiod start = str;
1903*3d8817e4Smiod for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
1904*3d8817e4Smiod {
1905*3d8817e4Smiod const CGEN_INSN *insn = ilist->insn;
1906*3d8817e4Smiod recognized_mnemonic = 1;
1907*3d8817e4Smiod
1908*3d8817e4Smiod #ifdef CGEN_VALIDATE_INSN_SUPPORTED
1909*3d8817e4Smiod /* Not usually needed as unsupported opcodes
1910*3d8817e4Smiod shouldn't be in the hash lists. */
1911*3d8817e4Smiod /* Is this insn supported by the selected cpu? */
1912*3d8817e4Smiod if (! m32c_cgen_insn_supported (cd, insn))
1913*3d8817e4Smiod continue;
1914*3d8817e4Smiod #endif
1915*3d8817e4Smiod /* If the RELAXED attribute is set, this is an insn that shouldn't be
1916*3d8817e4Smiod chosen immediately. Instead, it is used during assembler/linker
1917*3d8817e4Smiod relaxation if possible. */
1918*3d8817e4Smiod if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
1919*3d8817e4Smiod continue;
1920*3d8817e4Smiod
1921*3d8817e4Smiod str = start;
1922*3d8817e4Smiod
1923*3d8817e4Smiod /* Skip this insn if str doesn't look right lexically. */
1924*3d8817e4Smiod if (CGEN_INSN_RX (insn) != NULL &&
1925*3d8817e4Smiod regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
1926*3d8817e4Smiod continue;
1927*3d8817e4Smiod
1928*3d8817e4Smiod /* Allow parse/insert handlers to obtain length of insn. */
1929*3d8817e4Smiod CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
1930*3d8817e4Smiod
1931*3d8817e4Smiod parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
1932*3d8817e4Smiod if (parse_errmsg != NULL)
1933*3d8817e4Smiod continue;
1934*3d8817e4Smiod
1935*3d8817e4Smiod /* ??? 0 is passed for `pc'. */
1936*3d8817e4Smiod insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
1937*3d8817e4Smiod (bfd_vma) 0);
1938*3d8817e4Smiod if (insert_errmsg != NULL)
1939*3d8817e4Smiod continue;
1940*3d8817e4Smiod
1941*3d8817e4Smiod /* It is up to the caller to actually output the insn and any
1942*3d8817e4Smiod queued relocs. */
1943*3d8817e4Smiod return insn;
1944*3d8817e4Smiod }
1945*3d8817e4Smiod
1946*3d8817e4Smiod {
1947*3d8817e4Smiod static char errbuf[150];
1948*3d8817e4Smiod #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1949*3d8817e4Smiod const char *tmp_errmsg;
1950*3d8817e4Smiod
1951*3d8817e4Smiod /* If requesting verbose error messages, use insert_errmsg.
1952*3d8817e4Smiod Failing that, use parse_errmsg. */
1953*3d8817e4Smiod tmp_errmsg = (insert_errmsg ? insert_errmsg :
1954*3d8817e4Smiod parse_errmsg ? parse_errmsg :
1955*3d8817e4Smiod recognized_mnemonic ?
1956*3d8817e4Smiod _("unrecognized form of instruction") :
1957*3d8817e4Smiod _("unrecognized instruction"));
1958*3d8817e4Smiod
1959*3d8817e4Smiod if (strlen (start) > 50)
1960*3d8817e4Smiod /* xgettext:c-format */
1961*3d8817e4Smiod sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
1962*3d8817e4Smiod else
1963*3d8817e4Smiod /* xgettext:c-format */
1964*3d8817e4Smiod sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
1965*3d8817e4Smiod #else
1966*3d8817e4Smiod if (strlen (start) > 50)
1967*3d8817e4Smiod /* xgettext:c-format */
1968*3d8817e4Smiod sprintf (errbuf, _("bad instruction `%.50s...'"), start);
1969*3d8817e4Smiod else
1970*3d8817e4Smiod /* xgettext:c-format */
1971*3d8817e4Smiod sprintf (errbuf, _("bad instruction `%.50s'"), start);
1972*3d8817e4Smiod #endif
1973*3d8817e4Smiod
1974*3d8817e4Smiod *errmsg = errbuf;
1975*3d8817e4Smiod return NULL;
1976*3d8817e4Smiod }
1977*3d8817e4Smiod }
1978