1 /* Assembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS USED TO GENERATE fr30-asm.c.
6 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
8 This file is part of the GNU Binutils and GDB, the GNU debugger.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 #define min(a,b) ((a) < (b) ? (a) : (b))
36 #define max(a,b) ((a) > (b) ? (a) : (b))
40 #define INLINE __inline__
45 static const char * insert_normal
46 PARAMS ((CGEN_OPCODE_DESC, long, unsigned int, int, int, int,
47 CGEN_INSN_BYTES_PTR));
48 static const char * parse_insn_normal
49 PARAMS ((CGEN_OPCODE_DESC, const CGEN_INSN *,
50 const char **, CGEN_FIELDS *));
51 static const char * insert_insn_normal
52 PARAMS ((CGEN_OPCODE_DESC, const CGEN_INSN *,
53 CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma));
55 /* -- assembler routines inserted here */
57 /* Handle register lists for LDMx and STMx */
60 parse_low_register_list (od, strp, opindex, valuep)
64 unsigned long *valuep;
67 while (**strp && **strp != ')')
73 return "Register list is not valid";
79 parse_hi_register_list (od, strp, opindex, valuep)
83 unsigned long *valuep;
85 return parse_low_register_list (od, strp, opindex, valuep);
90 /* Main entry point for operand parsing.
92 This function is basically just a big switch statement. Earlier versions
93 used tables to look up the function to use, but
94 - if the table contains both assembler and disassembler functions then
95 the disassembler contains much of the assembler and vice-versa,
96 - there's a lot of inlining possibilities as things grow,
97 - using a switch statement avoids the function call overhead.
99 This function could be moved into `parse_insn_normal', but keeping it
100 separate makes clear the interface between `parse_insn_normal' and each of
105 fr30_cgen_parse_operand (od, opindex, strp, fields)
109 CGEN_FIELDS * fields;
115 case FR30_OPERAND_RI :
116 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_gr, & fields->f_Ri);
118 case FR30_OPERAND_RJ :
119 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_gr, & fields->f_Rj);
121 case FR30_OPERAND_RIC :
122 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_gr, & fields->f_Ric);
124 case FR30_OPERAND_RJC :
125 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_gr, & fields->f_Rjc);
127 case FR30_OPERAND_CRI :
128 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_cr, & fields->f_CRi);
130 case FR30_OPERAND_CRJ :
131 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_cr, & fields->f_CRj);
133 case FR30_OPERAND_RS1 :
134 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_dr, & fields->f_Rs1);
136 case FR30_OPERAND_RS2 :
137 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_dr, & fields->f_Rs2);
139 case FR30_OPERAND_R13 :
140 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_r13, & fields->f_nil);
142 case FR30_OPERAND_R14 :
143 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_r14, & fields->f_nil);
145 case FR30_OPERAND_R15 :
146 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_r15, & fields->f_nil);
148 case FR30_OPERAND_PS :
149 errmsg = cgen_parse_keyword (od, strp, & fr30_cgen_opval_h_ps, & fields->f_nil);
151 case FR30_OPERAND_U4 :
152 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_U4, &fields->f_u4);
154 case FR30_OPERAND_U4C :
155 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_U4C, &fields->f_u4c);
157 case FR30_OPERAND_M4 :
158 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_M4, &fields->f_m4);
160 case FR30_OPERAND_U8 :
161 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_U8, &fields->f_u8);
163 case FR30_OPERAND_I8 :
164 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_I8, &fields->f_i8);
166 case FR30_OPERAND_UDISP6 :
167 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_UDISP6, &fields->f_udisp6);
169 case FR30_OPERAND_DISP8 :
170 errmsg = cgen_parse_signed_integer (od, strp, FR30_OPERAND_DISP8, &fields->f_disp8);
172 case FR30_OPERAND_DISP9 :
173 errmsg = cgen_parse_signed_integer (od, strp, FR30_OPERAND_DISP9, &fields->f_disp9);
175 case FR30_OPERAND_DISP10 :
176 errmsg = cgen_parse_signed_integer (od, strp, FR30_OPERAND_DISP10, &fields->f_disp10);
178 case FR30_OPERAND_S10 :
179 errmsg = cgen_parse_signed_integer (od, strp, FR30_OPERAND_S10, &fields->f_s10);
181 case FR30_OPERAND_U10 :
182 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_U10, &fields->f_u10);
184 case FR30_OPERAND_I32 :
185 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_I32, &fields->f_i32);
187 case FR30_OPERAND_DIR8 :
188 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_DIR8, &fields->f_dir8);
190 case FR30_OPERAND_DIR9 :
191 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_DIR9, &fields->f_dir9);
193 case FR30_OPERAND_DIR10 :
194 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_DIR10, &fields->f_dir10);
196 case FR30_OPERAND_LABEL9 :
197 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_LABEL9, &fields->f_rel9);
199 case FR30_OPERAND_LABEL12 :
200 errmsg = cgen_parse_signed_integer (od, strp, FR30_OPERAND_LABEL12, &fields->f_rel12);
202 case FR30_OPERAND_REGLIST_LOW :
203 errmsg = parse_low_register_list (od, strp, FR30_OPERAND_REGLIST_LOW, &fields->f_reglist_low);
205 case FR30_OPERAND_REGLIST_HI :
206 errmsg = parse_hi_register_list (od, strp, FR30_OPERAND_REGLIST_HI, &fields->f_reglist_hi);
208 case FR30_OPERAND_CC :
209 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_CC, &fields->f_cc);
211 case FR30_OPERAND_CCC :
212 errmsg = cgen_parse_unsigned_integer (od, strp, FR30_OPERAND_CCC, &fields->f_ccc);
216 /* xgettext:c-format */
217 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
224 /* Main entry point for operand insertion.
226 This function is basically just a big switch statement. Earlier versions
227 used tables to look up the function to use, but
228 - if the table contains both assembler and disassembler functions then
229 the disassembler contains much of the assembler and vice-versa,
230 - there's a lot of inlining possibilities as things grow,
231 - using a switch statement avoids the function call overhead.
233 This function could be moved into `parse_insn_normal', but keeping it
234 separate makes clear the interface between `parse_insn_normal' and each of
235 the handlers. It's also needed by GAS to insert operands that couldn't be
236 resolved during parsing.
240 fr30_cgen_insert_operand (od, opindex, fields, buffer, pc)
243 CGEN_FIELDS * fields;
244 CGEN_INSN_BYTES_PTR buffer;
251 case FR30_OPERAND_RI :
252 errmsg = insert_normal (od, fields->f_Ri, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
254 case FR30_OPERAND_RJ :
255 errmsg = insert_normal (od, fields->f_Rj, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
257 case FR30_OPERAND_RIC :
258 errmsg = insert_normal (od, fields->f_Ric, 0|(1<<CGEN_OPERAND_UNSIGNED), 28, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
260 case FR30_OPERAND_RJC :
261 errmsg = insert_normal (od, fields->f_Rjc, 0|(1<<CGEN_OPERAND_UNSIGNED), 24, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
263 case FR30_OPERAND_CRI :
264 errmsg = insert_normal (od, fields->f_CRi, 0|(1<<CGEN_OPERAND_UNSIGNED), 28, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
266 case FR30_OPERAND_CRJ :
267 errmsg = insert_normal (od, fields->f_CRj, 0|(1<<CGEN_OPERAND_UNSIGNED), 24, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
269 case FR30_OPERAND_RS1 :
270 errmsg = insert_normal (od, fields->f_Rs1, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
272 case FR30_OPERAND_RS2 :
273 errmsg = insert_normal (od, fields->f_Rs2, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
275 case FR30_OPERAND_R13 :
276 errmsg = insert_normal (od, fields->f_nil, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
278 case FR30_OPERAND_R14 :
279 errmsg = insert_normal (od, fields->f_nil, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
281 case FR30_OPERAND_R15 :
282 errmsg = insert_normal (od, fields->f_nil, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
284 case FR30_OPERAND_PS :
285 errmsg = insert_normal (od, fields->f_nil, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), buffer);
287 case FR30_OPERAND_U4 :
288 errmsg = insert_normal (od, fields->f_u4, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
290 case FR30_OPERAND_U4C :
291 errmsg = insert_normal (od, fields->f_u4c, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
293 case FR30_OPERAND_M4 :
295 long value = fields->f_m4;
296 value = ((value) & (15));
297 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
300 case FR30_OPERAND_U8 :
301 errmsg = insert_normal (od, fields->f_u8, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
303 case FR30_OPERAND_I8 :
304 errmsg = insert_normal (od, fields->f_i8, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
306 case FR30_OPERAND_UDISP6 :
308 long value = fields->f_udisp6;
309 value = ((unsigned int) (value) >> (2));
310 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
313 case FR30_OPERAND_DISP8 :
314 errmsg = insert_normal (od, fields->f_disp8, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
316 case FR30_OPERAND_DISP9 :
318 long value = fields->f_disp9;
319 value = ((int) (value) >> (1));
320 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
323 case FR30_OPERAND_DISP10 :
325 long value = fields->f_disp10;
326 value = ((int) (value) >> (2));
327 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
330 case FR30_OPERAND_S10 :
332 long value = fields->f_s10;
333 value = ((int) (value) >> (2));
334 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
337 case FR30_OPERAND_U10 :
339 long value = fields->f_u10;
340 value = ((unsigned int) (value) >> (2));
341 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
344 case FR30_OPERAND_I32 :
345 errmsg = insert_normal (od, fields->f_i32, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), 16, 32, CGEN_FIELDS_BITSIZE (fields), buffer);
347 case FR30_OPERAND_DIR8 :
348 errmsg = insert_normal (od, fields->f_dir8, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
350 case FR30_OPERAND_DIR9 :
352 long value = fields->f_dir9;
353 value = ((unsigned int) (value) >> (1));
354 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
357 case FR30_OPERAND_DIR10 :
359 long value = fields->f_dir10;
360 value = ((unsigned int) (value) >> (2));
361 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
364 case FR30_OPERAND_LABEL9 :
366 long value = fields->f_rel9;
367 value = ((int) (((value) - (((pc) + (2))))) >> (1));
368 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_SIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
371 case FR30_OPERAND_LABEL12 :
373 long value = fields->f_rel12;
374 value = ((int) (((value) - (((pc) & (-2))))) >> (1));
375 errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_SIGNED), 5, 11, CGEN_FIELDS_BITSIZE (fields), buffer);
378 case FR30_OPERAND_REGLIST_LOW :
379 errmsg = insert_normal (od, fields->f_reglist_low, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
381 case FR30_OPERAND_REGLIST_HI :
382 errmsg = insert_normal (od, fields->f_reglist_hi, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
384 case FR30_OPERAND_CC :
385 errmsg = insert_normal (od, fields->f_cc, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, CGEN_FIELDS_BITSIZE (fields), buffer);
387 case FR30_OPERAND_CCC :
388 errmsg = insert_normal (od, fields->f_ccc, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 16, 8, CGEN_FIELDS_BITSIZE (fields), buffer);
392 /* xgettext:c-format */
393 fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
401 cgen_parse_fn * const fr30_cgen_parse_handlers[] =
407 cgen_insert_fn * const fr30_cgen_insert_handlers[] =
414 fr30_cgen_init_asm (od)
420 #if ! CGEN_INT_INSN_P
422 /* Subroutine of insert_normal. */
425 insert_1 (od, value, start, length, word_length, bufp)
428 int start,length,word_length;
431 unsigned long x,mask;
433 int big_p = CGEN_OPCODE_INSN_ENDIAN (od) == CGEN_ENDIAN_BIG;
442 x = bfd_getb16 (bufp);
444 x = bfd_getl16 (bufp);
447 /* ??? This may need reworking as these cases don't necessarily
448 want the first byte and the last two bytes handled like this. */
450 x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
452 x = bfd_getl16 (bufp) | (bufp[2] << 16);
456 x = bfd_getb32 (bufp);
458 x = bfd_getl32 (bufp);
464 /* Written this way to avoid undefined behaviour. */
465 mask = (((1L << (length - 1)) - 1) << 1) | 1;
466 if (CGEN_INSN_LSB0_P)
469 shift = (word_length - (start + length));
470 x = (x & ~(mask << shift)) | ((value & mask) << shift);
479 bfd_putb16 (x, bufp);
481 bfd_putl16 (x, bufp);
484 /* ??? This may need reworking as these cases don't necessarily
485 want the first byte and the last two bytes handled like this. */
489 bfd_putb16 (x, bufp + 1);
493 bfd_putl16 (x, bufp);
499 bfd_putb32 (x, bufp);
501 bfd_putl32 (x, bufp);
508 #endif /* ! CGEN_INT_INSN_P */
510 /* Default insertion routine.
512 ATTRS is a mask of the boolean attributes.
513 START is the starting bit number, architecture origin.
514 LENGTH is the length of VALUE in bits.
515 TOTAL_LENGTH is the total length of the insn.
517 The result is an error message or NULL if success. */
519 /* ??? This duplicates functionality with bfd's howto table and
520 bfd_install_relocation. */
521 /* ??? For architectures where insns can be representable as ints,
522 store insn in `field' struct and add registers, etc. while parsing? */
523 /* ??? This doesn't handle bfd_vma's. Create another function when
527 insert_normal (od, value, attrs, start, length, total_length, buffer)
534 CGEN_INSN_BYTES_PTR buffer;
536 static char errbuf[100];
537 /* Written this way to avoid undefined behaviour. */
538 unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
540 /* If LENGTH is zero, this operand doesn't contribute to the value. */
544 /* Ensure VALUE will fit. */
545 if ((attrs & CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED)) != 0)
547 unsigned long maxval = mask;
548 if ((unsigned long) value > maxval)
550 /* xgettext:c-format */
552 _("operand out of range (%lu not between 0 and %lu)"),
559 long minval = - (1L << (length - 1));
560 long maxval = (1L << (length - 1)) - 1;
561 if (value < minval || value > maxval)
564 /* xgettext:c-format */
565 (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
566 value, minval, maxval);
573 if (total_length > 32) /* 32 bits in a portable host int */
578 if (CGEN_INSN_LSB0_P)
581 shift = total_length - (start + length);
582 *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
587 /* FIXME: unfinished and untested */
589 /* The hard case is probably too slow for the normal cases.
590 It's certainly more difficult to understand than the normal case.
591 Thus this is split into two. The hard case is defined
592 to be when a field straddles a (loosely defined) word boundary
593 (??? which may require target specific help to determine). */
597 #define HARD_CASE_P 0 /* FIXME:wip */
601 unsigned char *bufp = (unsigned char *) buffer;
602 int insn_length_left = total_length;
604 if (CGEN_INSN_LSB0_P)
606 int word_offset = (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG
608 : start / CGEN_BASE_INSN_BITSIZE);
609 bufp += word_offset * (CGEN_BASE_INSN_BITSIZE / 8);
610 if (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG)
612 start -= word_offset * CGEN_BASE_INSN_BITSIZE;
616 int word_offset = (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG
617 ? start / CGEN_BASE_INSN_BITSIZE
619 bufp += word_offset * (CGEN_BASE_INSN_BITSIZE / 8);
620 if (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG)
621 start -= word_offset * CGEN_BASE_INSN_BITSIZE;
625 /* Loop so we handle a field straddling an insn word boundary
626 (remember, "insn word boundary" is loosely defined here). */
630 int this_pass_length = length;
631 int this_pass_start = start;
632 int this_pass_word_length = min (insn_length_left,
633 (CGEN_BASE_INSN_BITSIZE == 8
635 : CGEN_BASE_INSN_BITSIZE));
637 insert_1 (od, value, attrs,
638 this_pass_start, this_pass_length, this_pass_word_length,
641 length -= this_pass_length;
642 insn_length_left -= this_pass_word_length;
653 bufp += this_pass_word_length / 8;
659 unsigned char *bufp = (unsigned char *) buffer;
664 /* Adjust start,total_length,bufp to point to the pseudo-word that holds
665 the value. For example in a 48 bit insn where the value to insert
666 (say an immediate value) is the last 16 bits then fetch_length here
667 would be 16. To handle a 24 bit insn with an 18 bit immediate,
668 insert_1 handles 24 bits. */
670 if (total_length > 32)
672 int needed_width = start % 8 + length;
673 int fetch_length = (needed_width <= 8 ? 8
674 : needed_width <= 16 ? 16
677 if (CGEN_INSN_LSB0_P)
679 if (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG)
685 int offset = start & ~7;
689 total_length = fetch_length;
694 if (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG)
696 int offset = start & ~7;
700 total_length = fetch_length;
709 insert_1 (od, value, start, length, total_length, bufp);
712 #endif /* ! CGEN_INT_INSN_P */
717 /* Default insn parser.
719 The syntax string is scanned and operands are parsed and stored in FIELDS.
720 Relocs are queued as we go via other callbacks.
722 ??? Note that this is currently an all-or-nothing parser. If we fail to
723 parse the instruction, we return 0 and the caller will start over from
724 the beginning. Backtracking will be necessary in parsing subexpressions,
725 but that can be handled there. Not handling backtracking here may get
726 expensive in the case of the m68k. Deal with later.
728 Returns NULL for success, an error message for failure.
732 parse_insn_normal (od, insn, strp, fields)
734 const CGEN_INSN * insn;
736 CGEN_FIELDS * fields;
738 const CGEN_SYNTAX * syntax = CGEN_INSN_SYNTAX (insn);
739 const char * str = *strp;
742 const unsigned char * syn;
743 #ifdef CGEN_MNEMONIC_OPERANDS
748 /* For now we assume the mnemonic is first (there are no leading operands).
749 We can parse it without needing to set up operand parsing.
750 GAS's input scrubber will ensure mnemonics are lowercase, but we may
751 not be called from GAS. */
752 p = CGEN_INSN_MNEMONIC (insn);
753 while (*p && tolower (*p) == tolower (*str))
756 if (* p || (* str && !isspace (* str)))
757 return _("unrecognized instruction");
759 CGEN_INIT_PARSE (od);
760 cgen_init_parse_operand (od);
761 #ifdef CGEN_MNEMONIC_OPERANDS
765 /* We don't check for (*str != '\0') here because we want to parse
766 any trailing fake arguments in the syntax string. */
767 syn = CGEN_SYNTAX_STRING (syntax);
769 /* Mnemonics come first for now, ensure valid string. */
770 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
777 /* Non operand chars must match exactly. */
778 if (CGEN_SYNTAX_CHAR_P (* syn))
780 if (*str == CGEN_SYNTAX_CHAR (* syn))
782 #ifdef CGEN_MNEMONIC_OPERANDS
791 /* Syntax char didn't match. Can't be this insn. */
792 /* FIXME: would like to return something like
793 "expected char `c'" */
794 return _("syntax error");
799 /* We have an operand of some sort. */
800 errmsg = fr30_cgen_parse_operand (od, CGEN_SYNTAX_FIELD (*syn),
805 /* Done with this operand, continue with next one. */
809 /* If we're at the end of the syntax string, we're done. */
812 /* FIXME: For the moment we assume a valid `str' can only contain
813 blanks now. IE: We needn't try again with a longer version of
814 the insn and it is assumed that longer versions of insns appear
815 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
816 while (isspace (* str))
820 return _("junk at end of line"); /* FIXME: would like to include `str' */
825 /* We couldn't parse it. */
826 return _("unrecognized instruction");
829 /* Default insn builder (insert handler).
830 The instruction is recorded in CGEN_INT_INSN_P byte order
831 (meaning that if CGEN_INT_INSN_P BUFFER is an int * and thus the value is
832 recorded in host byte order, otherwise BUFFER is an array of bytes and the
833 value is recorded in target byte order).
834 The result is an error message or NULL if success. */
837 insert_insn_normal (od, insn, fields, buffer, pc)
839 const CGEN_INSN * insn;
840 CGEN_FIELDS * fields;
841 CGEN_INSN_BYTES_PTR buffer;
844 const CGEN_SYNTAX * syntax = CGEN_INSN_SYNTAX (insn);
846 const unsigned char * syn;
848 CGEN_INIT_INSERT (od);
849 value = CGEN_INSN_VALUE (insn);
851 /* If we're recording insns as numbers (rather than a string of bytes),
852 target byte order handling is deferred until later. */
860 cgen_put_insn_value (od, buffer, min (CGEN_BASE_INSN_BITSIZE,
861 CGEN_FIELDS_BITSIZE (fields)),
864 #endif /* ! CGEN_INT_INSN_P */
866 /* ??? Rather than scanning the syntax string again, we could store
867 in `fields' a null terminated list of the fields that are present. */
869 for (syn = CGEN_SYNTAX_STRING (syntax); * syn != '\0'; ++ syn)
873 if (CGEN_SYNTAX_CHAR_P (* syn))
876 errmsg = fr30_cgen_insert_operand (od, CGEN_SYNTAX_FIELD (*syn),
886 This routine is called for each instruction to be assembled.
887 STR points to the insn to be assembled.
888 We assume all necessary tables have been initialized.
889 The assembled instruction, less any fixups, is stored in BUF.
890 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
891 still needs to be converted to target byte order, otherwise BUF is an array
892 of bytes in target byte order.
893 The result is a pointer to the insn's entry in the opcode table,
894 or NULL if an error occured (an error message will have already been
897 Note that when processing (non-alias) macro-insns,
898 this function recurses. */
901 fr30_cgen_assemble_insn (od, str, fields, buf, errmsg)
904 CGEN_FIELDS * fields;
905 CGEN_INSN_BYTES_PTR buf;
909 CGEN_INSN_LIST * ilist;
911 /* Skip leading white space. */
912 while (isspace (* str))
915 /* The instructions are stored in hashed lists.
916 Get the first in the list. */
917 ilist = CGEN_ASM_LOOKUP_INSN (od, str);
919 /* Keep looking until we find a match. */
922 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
924 const CGEN_INSN *insn = ilist->insn;
926 #if 0 /* not needed as unsupported opcodes shouldn't be in the hash lists */
927 /* Is this insn supported by the selected cpu? */
928 if (! fr30_cgen_insn_supported (od, insn))
932 /* If the RELAX attribute is set, this is an insn that shouldn't be
933 chosen immediately. Instead, it is used during assembler/linker
934 relaxation if possible. */
935 if (CGEN_INSN_ATTR (insn, CGEN_INSN_RELAX) != 0)
940 /* Record a default length for the insn. This will get set to the
941 correct value while parsing. */
943 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
945 if (! CGEN_PARSE_FN (insn) (od, insn, & str, fields))
947 /* ??? 0 is passed for `pc' */
948 if (CGEN_INSERT_FN (insn) (od, insn, fields, buf, (bfd_vma) 0) != NULL)
950 /* It is up to the caller to actually output the insn and any
955 /* Try the next entry. */
958 /* FIXME: We can return a better error message than this.
959 Need to track why it failed and pick the right one. */
961 static char errbuf[100];
962 if (strlen (start) > 50)
963 /* xgettext:c-format */
964 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
966 /* xgettext:c-format */
967 sprintf (errbuf, _("bad instruction `%.50s'"), start);
974 #if 0 /* This calls back to GAS which we can't do without care. */
976 /* Record each member of OPVALS in the assembler's symbol table.
977 This lets GAS parse registers for us.
978 ??? Interesting idea but not currently used. */
980 /* Record each member of OPVALS in the assembler's symbol table.
981 FIXME: Not currently used. */
984 fr30_cgen_asm_hash_keywords (od, opvals)
986 CGEN_KEYWORD * opvals;
988 CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
989 const CGEN_KEYWORD_ENTRY * ke;
991 while ((ke = cgen_keyword_search_next (& search)) != NULL)
993 #if 0 /* Unnecessary, should be done in the search routine. */
994 if (! fr30_cgen_opval_supported (ke))
997 cgen_asm_record_register (od, ke->name, ke->value);