1 /* Instruction building/extraction support for fr30. -*- C -*-
3 THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
4 - the resultant file is machine generated, cgen-ibld.in isn't
6 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2005, 2006, 2007
7 Free Software Foundation, Inc.
9 This file is part of libopcodes.
11 This library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
16 It is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
34 #include "fr30-desc.h"
37 #include "safe-ctype.h"
40 #define min(a,b) ((a) < (b) ? (a) : (b))
42 #define max(a,b) ((a) > (b) ? (a) : (b))
44 /* Used by the ifield rtx function. */
45 #define FLD(f) (fields->f)
47 static const char * insert_normal
48 (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
49 unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR);
50 static const char * insert_insn_normal
51 (CGEN_CPU_DESC, const CGEN_INSN *,
52 CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
53 static int extract_normal
54 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
55 unsigned int, unsigned int, unsigned int, unsigned int,
56 unsigned int, unsigned int, bfd_vma, long *);
57 static int extract_insn_normal
58 (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
59 CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
61 static void put_insn_int_value
62 (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT);
65 static CGEN_INLINE void insert_1
66 (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *);
67 static CGEN_INLINE int fill_cache
68 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, bfd_vma);
69 static CGEN_INLINE long extract_1
70 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma);
73 /* Operand insertion. */
77 /* Subroutine of insert_normal. */
79 static CGEN_INLINE void
80 insert_1 (CGEN_CPU_DESC cd,
90 x = cgen_get_insn_value (cd, bufp, word_length);
92 /* Written this way to avoid undefined behaviour. */
93 mask = (((1L << (length - 1)) - 1) << 1) | 1;
95 shift = (start + 1) - length;
97 shift = (word_length - (start + length));
98 x = (x & ~(mask << shift)) | ((value & mask) << shift);
100 cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x);
103 #endif /* ! CGEN_INT_INSN_P */
105 /* Default insertion routine.
107 ATTRS is a mask of the boolean attributes.
108 WORD_OFFSET is the offset in bits from the start of the insn of the value.
109 WORD_LENGTH is the length of the word in bits in which the value resides.
110 START is the starting bit number in the word, architecture origin.
111 LENGTH is the length of VALUE in bits.
112 TOTAL_LENGTH is the total length of the insn in bits.
114 The result is an error message or NULL if success. */
116 /* ??? This duplicates functionality with bfd's howto table and
117 bfd_install_relocation. */
118 /* ??? This doesn't handle bfd_vma's. Create another function when
122 insert_normal (CGEN_CPU_DESC cd,
125 unsigned int word_offset,
128 unsigned int word_length,
129 unsigned int total_length,
130 CGEN_INSN_BYTES_PTR buffer)
132 static char errbuf[100];
133 /* Written this way to avoid undefined behaviour. */
134 unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
136 /* If LENGTH is zero, this operand doesn't contribute to the value. */
140 if (word_length > 32)
143 /* For architectures with insns smaller than the base-insn-bitsize,
144 word_length may be too big. */
145 if (cd->min_insn_bitsize < cd->base_insn_bitsize)
148 && word_length > total_length)
149 word_length = total_length;
152 /* Ensure VALUE will fit. */
153 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
155 long minval = - (1L << (length - 1));
156 unsigned long maxval = mask;
158 if ((value > 0 && (unsigned long) value > maxval)
161 /* xgettext:c-format */
163 _("operand out of range (%ld not between %ld and %lu)"),
164 value, minval, maxval);
168 else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
170 unsigned long maxval = mask;
171 unsigned long val = (unsigned long) value;
173 /* For hosts with a word size > 32 check to see if value has been sign
174 extended beyond 32 bits. If so then ignore these higher sign bits
175 as the user is attempting to store a 32-bit signed value into an
176 unsigned 32-bit field which is allowed. */
177 if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
182 /* xgettext:c-format */
184 _("operand out of range (0x%lx not between 0 and 0x%lx)"),
191 if (! cgen_signed_overflow_ok_p (cd))
193 long minval = - (1L << (length - 1));
194 long maxval = (1L << (length - 1)) - 1;
196 if (value < minval || value > maxval)
199 /* xgettext:c-format */
200 (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
201 value, minval, maxval);
212 if (CGEN_INSN_LSB0_P)
213 shift = (word_offset + start + 1) - length;
215 shift = total_length - (word_offset + start + length);
216 *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
219 #else /* ! CGEN_INT_INSN_P */
222 unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
224 insert_1 (cd, value, start, length, word_length, bufp);
227 #endif /* ! CGEN_INT_INSN_P */
232 /* Default insn builder (insert handler).
233 The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
234 that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
235 recorded in host byte order, otherwise BUFFER is an array of bytes
236 and the value is recorded in target byte order).
237 The result is an error message or NULL if success. */
240 insert_insn_normal (CGEN_CPU_DESC cd,
241 const CGEN_INSN * insn,
242 CGEN_FIELDS * fields,
243 CGEN_INSN_BYTES_PTR buffer,
246 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
248 const CGEN_SYNTAX_CHAR_TYPE * syn;
250 CGEN_INIT_INSERT (cd);
251 value = CGEN_INSN_BASE_VALUE (insn);
253 /* If we're recording insns as numbers (rather than a string of bytes),
254 target byte order handling is deferred until later. */
258 put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
259 CGEN_FIELDS_BITSIZE (fields), value);
263 cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
264 (unsigned) CGEN_FIELDS_BITSIZE (fields)),
267 #endif /* ! CGEN_INT_INSN_P */
269 /* ??? It would be better to scan the format's fields.
270 Still need to be able to insert a value based on the operand though;
271 e.g. storing a branch displacement that got resolved later.
272 Needs more thought first. */
274 for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
278 if (CGEN_SYNTAX_CHAR_P (* syn))
281 errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
291 /* Cover function to store an insn value into an integral insn. Must go here
292 because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */
295 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
296 CGEN_INSN_BYTES_PTR buf,
301 /* For architectures with insns smaller than the base-insn-bitsize,
302 length may be too big. */
303 if (length > insn_length)
307 int shift = insn_length - length;
308 /* Written this way to avoid undefined behaviour. */
309 CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
311 *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
316 /* Operand extraction. */
318 #if ! CGEN_INT_INSN_P
320 /* Subroutine of extract_normal.
321 Ensure sufficient bytes are cached in EX_INFO.
322 OFFSET is the offset in bytes from the start of the insn of the value.
323 BYTES is the length of the needed value.
324 Returns 1 for success, 0 for failure. */
326 static CGEN_INLINE int
327 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
328 CGEN_EXTRACT_INFO *ex_info,
333 /* It's doubtful that the middle part has already been fetched so
334 we don't optimize that case. kiss. */
336 disassemble_info *info = (disassemble_info *) ex_info->dis_info;
338 /* First do a quick check. */
339 mask = (1 << bytes) - 1;
340 if (((ex_info->valid >> offset) & mask) == mask)
343 /* Search for the first byte we need to read. */
344 for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
345 if (! (mask & ex_info->valid))
353 status = (*info->read_memory_func)
354 (pc, ex_info->insn_bytes + offset, bytes, info);
358 (*info->memory_error_func) (status, pc, info);
362 ex_info->valid |= ((1 << bytes) - 1) << offset;
368 /* Subroutine of extract_normal. */
370 static CGEN_INLINE long
371 extract_1 (CGEN_CPU_DESC cd,
372 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
377 bfd_vma pc ATTRIBUTE_UNUSED)
382 x = cgen_get_insn_value (cd, bufp, word_length);
384 if (CGEN_INSN_LSB0_P)
385 shift = (start + 1) - length;
387 shift = (word_length - (start + length));
391 #endif /* ! CGEN_INT_INSN_P */
393 /* Default extraction routine.
395 INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
396 or sometimes less for cases like the m32r where the base insn size is 32
397 but some insns are 16 bits.
398 ATTRS is a mask of the boolean attributes. We only need `SIGNED',
399 but for generality we take a bitmask of all of them.
400 WORD_OFFSET is the offset in bits from the start of the insn of the value.
401 WORD_LENGTH is the length of the word in bits in which the value resides.
402 START is the starting bit number in the word, architecture origin.
403 LENGTH is the length of VALUE in bits.
404 TOTAL_LENGTH is the total length of the insn in bits.
406 Returns 1 for success, 0 for failure. */
408 /* ??? The return code isn't properly used. wip. */
410 /* ??? This doesn't handle bfd_vma's. Create another function when
414 extract_normal (CGEN_CPU_DESC cd,
415 #if ! CGEN_INT_INSN_P
416 CGEN_EXTRACT_INFO *ex_info,
418 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
420 CGEN_INSN_INT insn_value,
422 unsigned int word_offset,
425 unsigned int word_length,
426 unsigned int total_length,
427 #if ! CGEN_INT_INSN_P
430 bfd_vma pc ATTRIBUTE_UNUSED,
436 /* If LENGTH is zero, this operand doesn't contribute to the value
437 so give it a standard value of zero. */
444 if (word_length > 32)
447 /* For architectures with insns smaller than the insn-base-bitsize,
448 word_length may be too big. */
449 if (cd->min_insn_bitsize < cd->base_insn_bitsize)
451 if (word_offset + word_length > total_length)
452 word_length = total_length - word_offset;
455 /* Does the value reside in INSN_VALUE, and at the right alignment? */
457 if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
459 if (CGEN_INSN_LSB0_P)
460 value = insn_value >> ((word_offset + start + 1) - length);
462 value = insn_value >> (total_length - ( word_offset + start + length));
465 #if ! CGEN_INT_INSN_P
469 unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
471 if (word_length > 32)
474 if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
477 value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
480 #endif /* ! CGEN_INT_INSN_P */
482 /* Written this way to avoid undefined behaviour. */
483 mask = (((1L << (length - 1)) - 1) << 1) | 1;
487 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
488 && (value & (1L << (length - 1))))
496 /* Default insn extractor.
498 INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
499 The extracted fields are stored in FIELDS.
500 EX_INFO is used to handle reading variable length insns.
501 Return the length of the insn in bits, or 0 if no match,
502 or -1 if an error occurs fetching data (memory_error_func will have
506 extract_insn_normal (CGEN_CPU_DESC cd,
507 const CGEN_INSN *insn,
508 CGEN_EXTRACT_INFO *ex_info,
509 CGEN_INSN_INT insn_value,
513 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
514 const CGEN_SYNTAX_CHAR_TYPE *syn;
516 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
518 CGEN_INIT_EXTRACT (cd);
520 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
524 if (CGEN_SYNTAX_CHAR_P (*syn))
527 length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
528 ex_info, insn_value, fields, pc);
533 /* We recognized and successfully extracted this insn. */
534 return CGEN_INSN_BITSIZE (insn);
537 /* Machine generated code added here. */
539 const char * fr30_cgen_insert_operand
540 (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
542 /* Main entry point for operand insertion.
544 This function is basically just a big switch statement. Earlier versions
545 used tables to look up the function to use, but
546 - if the table contains both assembler and disassembler functions then
547 the disassembler contains much of the assembler and vice-versa,
548 - there's a lot of inlining possibilities as things grow,
549 - using a switch statement avoids the function call overhead.
551 This function could be moved into `parse_insn_normal', but keeping it
552 separate makes clear the interface between `parse_insn_normal' and each of
553 the handlers. It's also needed by GAS to insert operands that couldn't be
554 resolved during parsing. */
557 fr30_cgen_insert_operand (CGEN_CPU_DESC cd,
559 CGEN_FIELDS * fields,
560 CGEN_INSN_BYTES_PTR buffer,
561 bfd_vma pc ATTRIBUTE_UNUSED)
563 const char * errmsg = NULL;
564 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
568 case FR30_OPERAND_CRI :
569 errmsg = insert_normal (cd, fields->f_CRi, 0, 16, 12, 4, 16, total_length, buffer);
571 case FR30_OPERAND_CRJ :
572 errmsg = insert_normal (cd, fields->f_CRj, 0, 16, 8, 4, 16, total_length, buffer);
574 case FR30_OPERAND_R13 :
576 case FR30_OPERAND_R14 :
578 case FR30_OPERAND_R15 :
580 case FR30_OPERAND_RI :
581 errmsg = insert_normal (cd, fields->f_Ri, 0, 0, 12, 4, 16, total_length, buffer);
583 case FR30_OPERAND_RIC :
584 errmsg = insert_normal (cd, fields->f_Ric, 0, 16, 12, 4, 16, total_length, buffer);
586 case FR30_OPERAND_RJ :
587 errmsg = insert_normal (cd, fields->f_Rj, 0, 0, 8, 4, 16, total_length, buffer);
589 case FR30_OPERAND_RJC :
590 errmsg = insert_normal (cd, fields->f_Rjc, 0, 16, 8, 4, 16, total_length, buffer);
592 case FR30_OPERAND_RS1 :
593 errmsg = insert_normal (cd, fields->f_Rs1, 0, 0, 8, 4, 16, total_length, buffer);
595 case FR30_OPERAND_RS2 :
596 errmsg = insert_normal (cd, fields->f_Rs2, 0, 0, 12, 4, 16, total_length, buffer);
598 case FR30_OPERAND_CC :
599 errmsg = insert_normal (cd, fields->f_cc, 0, 0, 4, 4, 16, total_length, buffer);
601 case FR30_OPERAND_CCC :
602 errmsg = insert_normal (cd, fields->f_ccc, 0, 16, 0, 8, 16, total_length, buffer);
604 case FR30_OPERAND_DIR10 :
606 long value = fields->f_dir10;
607 value = ((unsigned int) (value) >> (2));
608 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
611 case FR30_OPERAND_DIR8 :
612 errmsg = insert_normal (cd, fields->f_dir8, 0, 0, 8, 8, 16, total_length, buffer);
614 case FR30_OPERAND_DIR9 :
616 long value = fields->f_dir9;
617 value = ((unsigned int) (value) >> (1));
618 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
621 case FR30_OPERAND_DISP10 :
623 long value = fields->f_disp10;
624 value = ((int) (value) >> (2));
625 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
628 case FR30_OPERAND_DISP8 :
629 errmsg = insert_normal (cd, fields->f_disp8, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
631 case FR30_OPERAND_DISP9 :
633 long value = fields->f_disp9;
634 value = ((int) (value) >> (1));
635 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
638 case FR30_OPERAND_I20 :
641 FLD (f_i20_4) = ((unsigned int) (FLD (f_i20)) >> (16));
642 FLD (f_i20_16) = ((FLD (f_i20)) & (65535));
644 errmsg = insert_normal (cd, fields->f_i20_4, 0, 0, 8, 4, 16, total_length, buffer);
647 errmsg = insert_normal (cd, fields->f_i20_16, 0, 16, 0, 16, 16, total_length, buffer);
652 case FR30_OPERAND_I32 :
653 errmsg = insert_normal (cd, fields->f_i32, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, buffer);
655 case FR30_OPERAND_I8 :
656 errmsg = insert_normal (cd, fields->f_i8, 0, 0, 4, 8, 16, total_length, buffer);
658 case FR30_OPERAND_LABEL12 :
660 long value = fields->f_rel12;
661 value = ((int) (((value) - (((pc) + (2))))) >> (1));
662 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, buffer);
665 case FR30_OPERAND_LABEL9 :
667 long value = fields->f_rel9;
668 value = ((int) (((value) - (((pc) + (2))))) >> (1));
669 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, buffer);
672 case FR30_OPERAND_M4 :
674 long value = fields->f_m4;
675 value = ((value) & (15));
676 errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
679 case FR30_OPERAND_PS :
681 case FR30_OPERAND_REGLIST_HI_LD :
682 errmsg = insert_normal (cd, fields->f_reglist_hi_ld, 0, 0, 8, 8, 16, total_length, buffer);
684 case FR30_OPERAND_REGLIST_HI_ST :
685 errmsg = insert_normal (cd, fields->f_reglist_hi_st, 0, 0, 8, 8, 16, total_length, buffer);
687 case FR30_OPERAND_REGLIST_LOW_LD :
688 errmsg = insert_normal (cd, fields->f_reglist_low_ld, 0, 0, 8, 8, 16, total_length, buffer);
690 case FR30_OPERAND_REGLIST_LOW_ST :
691 errmsg = insert_normal (cd, fields->f_reglist_low_st, 0, 0, 8, 8, 16, total_length, buffer);
693 case FR30_OPERAND_S10 :
695 long value = fields->f_s10;
696 value = ((int) (value) >> (2));
697 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, buffer);
700 case FR30_OPERAND_U10 :
702 long value = fields->f_u10;
703 value = ((unsigned int) (value) >> (2));
704 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
707 case FR30_OPERAND_U4 :
708 errmsg = insert_normal (cd, fields->f_u4, 0, 0, 8, 4, 16, total_length, buffer);
710 case FR30_OPERAND_U4C :
711 errmsg = insert_normal (cd, fields->f_u4c, 0, 0, 12, 4, 16, total_length, buffer);
713 case FR30_OPERAND_U8 :
714 errmsg = insert_normal (cd, fields->f_u8, 0, 0, 8, 8, 16, total_length, buffer);
716 case FR30_OPERAND_UDISP6 :
718 long value = fields->f_udisp6;
719 value = ((unsigned int) (value) >> (2));
720 errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
725 /* xgettext:c-format */
726 fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
734 int fr30_cgen_extract_operand
735 (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
737 /* Main entry point for operand extraction.
738 The result is <= 0 for error, >0 for success.
739 ??? Actual values aren't well defined right now.
741 This function is basically just a big switch statement. Earlier versions
742 used tables to look up the function to use, but
743 - if the table contains both assembler and disassembler functions then
744 the disassembler contains much of the assembler and vice-versa,
745 - there's a lot of inlining possibilities as things grow,
746 - using a switch statement avoids the function call overhead.
748 This function could be moved into `print_insn_normal', but keeping it
749 separate makes clear the interface between `print_insn_normal' and each of
753 fr30_cgen_extract_operand (CGEN_CPU_DESC cd,
755 CGEN_EXTRACT_INFO *ex_info,
756 CGEN_INSN_INT insn_value,
757 CGEN_FIELDS * fields,
760 /* Assume success (for those operands that are nops). */
762 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
766 case FR30_OPERAND_CRI :
767 length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_CRi);
769 case FR30_OPERAND_CRJ :
770 length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_CRj);
772 case FR30_OPERAND_R13 :
774 case FR30_OPERAND_R14 :
776 case FR30_OPERAND_R15 :
778 case FR30_OPERAND_RI :
779 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Ri);
781 case FR30_OPERAND_RIC :
782 length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_Ric);
784 case FR30_OPERAND_RJ :
785 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rj);
787 case FR30_OPERAND_RJC :
788 length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_Rjc);
790 case FR30_OPERAND_RS1 :
791 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rs1);
793 case FR30_OPERAND_RS2 :
794 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Rs2);
796 case FR30_OPERAND_CC :
797 length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 4, 16, total_length, pc, & fields->f_cc);
799 case FR30_OPERAND_CCC :
800 length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 8, 16, total_length, pc, & fields->f_ccc);
802 case FR30_OPERAND_DIR10 :
805 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
806 value = ((value) << (2));
807 fields->f_dir10 = value;
810 case FR30_OPERAND_DIR8 :
811 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_dir8);
813 case FR30_OPERAND_DIR9 :
816 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
817 value = ((value) << (1));
818 fields->f_dir9 = value;
821 case FR30_OPERAND_DISP10 :
824 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
825 value = ((value) << (2));
826 fields->f_disp10 = value;
829 case FR30_OPERAND_DISP8 :
830 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & fields->f_disp8);
832 case FR30_OPERAND_DISP9 :
835 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
836 value = ((value) << (1));
837 fields->f_disp9 = value;
840 case FR30_OPERAND_I20 :
842 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_i20_4);
843 if (length <= 0) break;
844 length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 16, 16, total_length, pc, & fields->f_i20_16);
845 if (length <= 0) break;
847 FLD (f_i20) = ((((FLD (f_i20_4)) << (16))) | (FLD (f_i20_16)));
851 case FR30_OPERAND_I32 :
852 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, pc, & fields->f_i32);
854 case FR30_OPERAND_I8 :
855 length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 8, 16, total_length, pc, & fields->f_i8);
857 case FR30_OPERAND_LABEL12 :
860 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, pc, & value);
861 value = ((((value) << (1))) + (((pc) + (2))));
862 fields->f_rel12 = value;
865 case FR30_OPERAND_LABEL9 :
868 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, pc, & value);
869 value = ((((value) << (1))) + (((pc) + (2))));
870 fields->f_rel9 = value;
873 case FR30_OPERAND_M4 :
876 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
877 value = ((value) | (((-1) << (4))));
878 fields->f_m4 = value;
881 case FR30_OPERAND_PS :
883 case FR30_OPERAND_REGLIST_HI_LD :
884 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_ld);
886 case FR30_OPERAND_REGLIST_HI_ST :
887 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_st);
889 case FR30_OPERAND_REGLIST_LOW_LD :
890 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_ld);
892 case FR30_OPERAND_REGLIST_LOW_ST :
893 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_st);
895 case FR30_OPERAND_S10 :
898 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, pc, & value);
899 value = ((value) << (2));
900 fields->f_s10 = value;
903 case FR30_OPERAND_U10 :
906 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
907 value = ((value) << (2));
908 fields->f_u10 = value;
911 case FR30_OPERAND_U4 :
912 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_u4);
914 case FR30_OPERAND_U4C :
915 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_u4c);
917 case FR30_OPERAND_U8 :
918 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_u8);
920 case FR30_OPERAND_UDISP6 :
923 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
924 value = ((value) << (2));
925 fields->f_udisp6 = value;
930 /* xgettext:c-format */
931 fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
939 cgen_insert_fn * const fr30_cgen_insert_handlers[] =
944 cgen_extract_fn * const fr30_cgen_extract_handlers[] =
949 int fr30_cgen_get_int_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
950 bfd_vma fr30_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
952 /* Getting values from cgen_fields is handled by a collection of functions.
953 They are distinguished by the type of the VALUE argument they return.
954 TODO: floating point, inlining support, remove cases where result type
958 fr30_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
960 const CGEN_FIELDS * fields)
966 case FR30_OPERAND_CRI :
967 value = fields->f_CRi;
969 case FR30_OPERAND_CRJ :
970 value = fields->f_CRj;
972 case FR30_OPERAND_R13 :
975 case FR30_OPERAND_R14 :
978 case FR30_OPERAND_R15 :
981 case FR30_OPERAND_RI :
982 value = fields->f_Ri;
984 case FR30_OPERAND_RIC :
985 value = fields->f_Ric;
987 case FR30_OPERAND_RJ :
988 value = fields->f_Rj;
990 case FR30_OPERAND_RJC :
991 value = fields->f_Rjc;
993 case FR30_OPERAND_RS1 :
994 value = fields->f_Rs1;
996 case FR30_OPERAND_RS2 :
997 value = fields->f_Rs2;
999 case FR30_OPERAND_CC :
1000 value = fields->f_cc;
1002 case FR30_OPERAND_CCC :
1003 value = fields->f_ccc;
1005 case FR30_OPERAND_DIR10 :
1006 value = fields->f_dir10;
1008 case FR30_OPERAND_DIR8 :
1009 value = fields->f_dir8;
1011 case FR30_OPERAND_DIR9 :
1012 value = fields->f_dir9;
1014 case FR30_OPERAND_DISP10 :
1015 value = fields->f_disp10;
1017 case FR30_OPERAND_DISP8 :
1018 value = fields->f_disp8;
1020 case FR30_OPERAND_DISP9 :
1021 value = fields->f_disp9;
1023 case FR30_OPERAND_I20 :
1024 value = fields->f_i20;
1026 case FR30_OPERAND_I32 :
1027 value = fields->f_i32;
1029 case FR30_OPERAND_I8 :
1030 value = fields->f_i8;
1032 case FR30_OPERAND_LABEL12 :
1033 value = fields->f_rel12;
1035 case FR30_OPERAND_LABEL9 :
1036 value = fields->f_rel9;
1038 case FR30_OPERAND_M4 :
1039 value = fields->f_m4;
1041 case FR30_OPERAND_PS :
1044 case FR30_OPERAND_REGLIST_HI_LD :
1045 value = fields->f_reglist_hi_ld;
1047 case FR30_OPERAND_REGLIST_HI_ST :
1048 value = fields->f_reglist_hi_st;
1050 case FR30_OPERAND_REGLIST_LOW_LD :
1051 value = fields->f_reglist_low_ld;
1053 case FR30_OPERAND_REGLIST_LOW_ST :
1054 value = fields->f_reglist_low_st;
1056 case FR30_OPERAND_S10 :
1057 value = fields->f_s10;
1059 case FR30_OPERAND_U10 :
1060 value = fields->f_u10;
1062 case FR30_OPERAND_U4 :
1063 value = fields->f_u4;
1065 case FR30_OPERAND_U4C :
1066 value = fields->f_u4c;
1068 case FR30_OPERAND_U8 :
1069 value = fields->f_u8;
1071 case FR30_OPERAND_UDISP6 :
1072 value = fields->f_udisp6;
1076 /* xgettext:c-format */
1077 fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
1086 fr30_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1088 const CGEN_FIELDS * fields)
1094 case FR30_OPERAND_CRI :
1095 value = fields->f_CRi;
1097 case FR30_OPERAND_CRJ :
1098 value = fields->f_CRj;
1100 case FR30_OPERAND_R13 :
1103 case FR30_OPERAND_R14 :
1106 case FR30_OPERAND_R15 :
1109 case FR30_OPERAND_RI :
1110 value = fields->f_Ri;
1112 case FR30_OPERAND_RIC :
1113 value = fields->f_Ric;
1115 case FR30_OPERAND_RJ :
1116 value = fields->f_Rj;
1118 case FR30_OPERAND_RJC :
1119 value = fields->f_Rjc;
1121 case FR30_OPERAND_RS1 :
1122 value = fields->f_Rs1;
1124 case FR30_OPERAND_RS2 :
1125 value = fields->f_Rs2;
1127 case FR30_OPERAND_CC :
1128 value = fields->f_cc;
1130 case FR30_OPERAND_CCC :
1131 value = fields->f_ccc;
1133 case FR30_OPERAND_DIR10 :
1134 value = fields->f_dir10;
1136 case FR30_OPERAND_DIR8 :
1137 value = fields->f_dir8;
1139 case FR30_OPERAND_DIR9 :
1140 value = fields->f_dir9;
1142 case FR30_OPERAND_DISP10 :
1143 value = fields->f_disp10;
1145 case FR30_OPERAND_DISP8 :
1146 value = fields->f_disp8;
1148 case FR30_OPERAND_DISP9 :
1149 value = fields->f_disp9;
1151 case FR30_OPERAND_I20 :
1152 value = fields->f_i20;
1154 case FR30_OPERAND_I32 :
1155 value = fields->f_i32;
1157 case FR30_OPERAND_I8 :
1158 value = fields->f_i8;
1160 case FR30_OPERAND_LABEL12 :
1161 value = fields->f_rel12;
1163 case FR30_OPERAND_LABEL9 :
1164 value = fields->f_rel9;
1166 case FR30_OPERAND_M4 :
1167 value = fields->f_m4;
1169 case FR30_OPERAND_PS :
1172 case FR30_OPERAND_REGLIST_HI_LD :
1173 value = fields->f_reglist_hi_ld;
1175 case FR30_OPERAND_REGLIST_HI_ST :
1176 value = fields->f_reglist_hi_st;
1178 case FR30_OPERAND_REGLIST_LOW_LD :
1179 value = fields->f_reglist_low_ld;
1181 case FR30_OPERAND_REGLIST_LOW_ST :
1182 value = fields->f_reglist_low_st;
1184 case FR30_OPERAND_S10 :
1185 value = fields->f_s10;
1187 case FR30_OPERAND_U10 :
1188 value = fields->f_u10;
1190 case FR30_OPERAND_U4 :
1191 value = fields->f_u4;
1193 case FR30_OPERAND_U4C :
1194 value = fields->f_u4c;
1196 case FR30_OPERAND_U8 :
1197 value = fields->f_u8;
1199 case FR30_OPERAND_UDISP6 :
1200 value = fields->f_udisp6;
1204 /* xgettext:c-format */
1205 fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
1213 void fr30_cgen_set_int_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
1214 void fr30_cgen_set_vma_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
1216 /* Stuffing values in cgen_fields is handled by a collection of functions.
1217 They are distinguished by the type of the VALUE argument they accept.
1218 TODO: floating point, inlining support, remove cases where argument type
1222 fr30_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1224 CGEN_FIELDS * fields,
1229 case FR30_OPERAND_CRI :
1230 fields->f_CRi = value;
1232 case FR30_OPERAND_CRJ :
1233 fields->f_CRj = value;
1235 case FR30_OPERAND_R13 :
1237 case FR30_OPERAND_R14 :
1239 case FR30_OPERAND_R15 :
1241 case FR30_OPERAND_RI :
1242 fields->f_Ri = value;
1244 case FR30_OPERAND_RIC :
1245 fields->f_Ric = value;
1247 case FR30_OPERAND_RJ :
1248 fields->f_Rj = value;
1250 case FR30_OPERAND_RJC :
1251 fields->f_Rjc = value;
1253 case FR30_OPERAND_RS1 :
1254 fields->f_Rs1 = value;
1256 case FR30_OPERAND_RS2 :
1257 fields->f_Rs2 = value;
1259 case FR30_OPERAND_CC :
1260 fields->f_cc = value;
1262 case FR30_OPERAND_CCC :
1263 fields->f_ccc = value;
1265 case FR30_OPERAND_DIR10 :
1266 fields->f_dir10 = value;
1268 case FR30_OPERAND_DIR8 :
1269 fields->f_dir8 = value;
1271 case FR30_OPERAND_DIR9 :
1272 fields->f_dir9 = value;
1274 case FR30_OPERAND_DISP10 :
1275 fields->f_disp10 = value;
1277 case FR30_OPERAND_DISP8 :
1278 fields->f_disp8 = value;
1280 case FR30_OPERAND_DISP9 :
1281 fields->f_disp9 = value;
1283 case FR30_OPERAND_I20 :
1284 fields->f_i20 = value;
1286 case FR30_OPERAND_I32 :
1287 fields->f_i32 = value;
1289 case FR30_OPERAND_I8 :
1290 fields->f_i8 = value;
1292 case FR30_OPERAND_LABEL12 :
1293 fields->f_rel12 = value;
1295 case FR30_OPERAND_LABEL9 :
1296 fields->f_rel9 = value;
1298 case FR30_OPERAND_M4 :
1299 fields->f_m4 = value;
1301 case FR30_OPERAND_PS :
1303 case FR30_OPERAND_REGLIST_HI_LD :
1304 fields->f_reglist_hi_ld = value;
1306 case FR30_OPERAND_REGLIST_HI_ST :
1307 fields->f_reglist_hi_st = value;
1309 case FR30_OPERAND_REGLIST_LOW_LD :
1310 fields->f_reglist_low_ld = value;
1312 case FR30_OPERAND_REGLIST_LOW_ST :
1313 fields->f_reglist_low_st = value;
1315 case FR30_OPERAND_S10 :
1316 fields->f_s10 = value;
1318 case FR30_OPERAND_U10 :
1319 fields->f_u10 = value;
1321 case FR30_OPERAND_U4 :
1322 fields->f_u4 = value;
1324 case FR30_OPERAND_U4C :
1325 fields->f_u4c = value;
1327 case FR30_OPERAND_U8 :
1328 fields->f_u8 = value;
1330 case FR30_OPERAND_UDISP6 :
1331 fields->f_udisp6 = value;
1335 /* xgettext:c-format */
1336 fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
1343 fr30_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1345 CGEN_FIELDS * fields,
1350 case FR30_OPERAND_CRI :
1351 fields->f_CRi = value;
1353 case FR30_OPERAND_CRJ :
1354 fields->f_CRj = value;
1356 case FR30_OPERAND_R13 :
1358 case FR30_OPERAND_R14 :
1360 case FR30_OPERAND_R15 :
1362 case FR30_OPERAND_RI :
1363 fields->f_Ri = value;
1365 case FR30_OPERAND_RIC :
1366 fields->f_Ric = value;
1368 case FR30_OPERAND_RJ :
1369 fields->f_Rj = value;
1371 case FR30_OPERAND_RJC :
1372 fields->f_Rjc = value;
1374 case FR30_OPERAND_RS1 :
1375 fields->f_Rs1 = value;
1377 case FR30_OPERAND_RS2 :
1378 fields->f_Rs2 = value;
1380 case FR30_OPERAND_CC :
1381 fields->f_cc = value;
1383 case FR30_OPERAND_CCC :
1384 fields->f_ccc = value;
1386 case FR30_OPERAND_DIR10 :
1387 fields->f_dir10 = value;
1389 case FR30_OPERAND_DIR8 :
1390 fields->f_dir8 = value;
1392 case FR30_OPERAND_DIR9 :
1393 fields->f_dir9 = value;
1395 case FR30_OPERAND_DISP10 :
1396 fields->f_disp10 = value;
1398 case FR30_OPERAND_DISP8 :
1399 fields->f_disp8 = value;
1401 case FR30_OPERAND_DISP9 :
1402 fields->f_disp9 = value;
1404 case FR30_OPERAND_I20 :
1405 fields->f_i20 = value;
1407 case FR30_OPERAND_I32 :
1408 fields->f_i32 = value;
1410 case FR30_OPERAND_I8 :
1411 fields->f_i8 = value;
1413 case FR30_OPERAND_LABEL12 :
1414 fields->f_rel12 = value;
1416 case FR30_OPERAND_LABEL9 :
1417 fields->f_rel9 = value;
1419 case FR30_OPERAND_M4 :
1420 fields->f_m4 = value;
1422 case FR30_OPERAND_PS :
1424 case FR30_OPERAND_REGLIST_HI_LD :
1425 fields->f_reglist_hi_ld = value;
1427 case FR30_OPERAND_REGLIST_HI_ST :
1428 fields->f_reglist_hi_st = value;
1430 case FR30_OPERAND_REGLIST_LOW_LD :
1431 fields->f_reglist_low_ld = value;
1433 case FR30_OPERAND_REGLIST_LOW_ST :
1434 fields->f_reglist_low_st = value;
1436 case FR30_OPERAND_S10 :
1437 fields->f_s10 = value;
1439 case FR30_OPERAND_U10 :
1440 fields->f_u10 = value;
1442 case FR30_OPERAND_U4 :
1443 fields->f_u4 = value;
1445 case FR30_OPERAND_U4C :
1446 fields->f_u4c = value;
1448 case FR30_OPERAND_U8 :
1449 fields->f_u8 = value;
1451 case FR30_OPERAND_UDISP6 :
1452 fields->f_udisp6 = value;
1456 /* xgettext:c-format */
1457 fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
1463 /* Function to call before using the instruction builder tables. */
1466 fr30_cgen_init_ibld_table (CGEN_CPU_DESC cd)
1468 cd->insert_handlers = & fr30_cgen_insert_handlers[0];
1469 cd->extract_handlers = & fr30_cgen_extract_handlers[0];
1471 cd->insert_operand = fr30_cgen_insert_operand;
1472 cd->extract_operand = fr30_cgen_extract_operand;
1474 cd->get_int_operand = fr30_cgen_get_int_operand;
1475 cd->set_int_operand = fr30_cgen_set_int_operand;
1476 cd->get_vma_operand = fr30_cgen_get_vma_operand;
1477 cd->set_vma_operand = fr30_cgen_set_vma_operand;