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 (C) 1996, 1997, 1998, 1999 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. */
24 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
34 #include "fr30-desc.h"
39 #define min(a,b) ((a) < (b) ? (a) : (b))
41 #define max(a,b) ((a) > (b) ? (a) : (b))
43 /* Used by the ifield rtx function. */
44 #define FLD(f) (fields->f)
46 static const char * insert_normal
47 PARAMS ((CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
48 unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR));
49 static const char * insert_insn_normal
50 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *,
51 CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma));
53 static int extract_normal
54 PARAMS ((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 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
59 CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma));
61 /* Operand insertion. */
65 /* Subroutine of insert_normal. */
67 static CGEN_INLINE void
68 insert_1 (cd, value, start, length, word_length, bufp)
71 int start,length,word_length;
76 int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
85 x = bfd_getb16 (bufp);
87 x = bfd_getl16 (bufp);
90 /* ??? This may need reworking as these cases don't necessarily
91 want the first byte and the last two bytes handled like this. */
93 x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
95 x = bfd_getl16 (bufp) | (bufp[2] << 16);
99 x = bfd_getb32 (bufp);
101 x = bfd_getl32 (bufp);
107 /* Written this way to avoid undefined behaviour. */
108 mask = (((1L << (length - 1)) - 1) << 1) | 1;
109 if (CGEN_INSN_LSB0_P)
110 shift = (start + 1) - length;
112 shift = (word_length - (start + length));
113 x = (x & ~(mask << shift)) | ((value & mask) << shift);
122 bfd_putb16 (x, bufp);
124 bfd_putl16 (x, bufp);
127 /* ??? This may need reworking as these cases don't necessarily
128 want the first byte and the last two bytes handled like this. */
132 bfd_putb16 (x, bufp + 1);
136 bfd_putl16 (x, bufp);
142 bfd_putb32 (x, bufp);
144 bfd_putl32 (x, bufp);
151 #endif /* ! CGEN_INT_INSN_P */
153 /* Default insertion routine.
155 ATTRS is a mask of the boolean attributes.
156 WORD_OFFSET is the offset in bits from the start of the insn of the value.
157 WORD_LENGTH is the length of the word in bits in which the value resides.
158 START is the starting bit number in the word, architecture origin.
159 LENGTH is the length of VALUE in bits.
160 TOTAL_LENGTH is the total length of the insn in bits.
162 The result is an error message or NULL if success. */
164 /* ??? This duplicates functionality with bfd's howto table and
165 bfd_install_relocation. */
166 /* ??? This doesn't handle bfd_vma's. Create another function when
170 insert_normal (cd, value, attrs, word_offset, start, length, word_length,
171 total_length, buffer)
175 unsigned int word_offset, start, length, word_length, total_length;
176 CGEN_INSN_BYTES_PTR buffer;
178 static char errbuf[100];
179 /* Written this way to avoid undefined behaviour. */
180 unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
182 /* If LENGTH is zero, this operand doesn't contribute to the value. */
190 if (word_length > 32)
193 /* For architectures with insns smaller than the base-insn-bitsize,
194 word_length may be too big. */
195 if (cd->min_insn_bitsize < cd->base_insn_bitsize)
198 && word_length > total_length)
199 word_length = total_length;
202 /* Ensure VALUE will fit. */
203 if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
205 unsigned long maxval = mask;
206 if ((unsigned long) value > maxval)
208 /* xgettext:c-format */
210 _("operand out of range (%lu not between 0 and %lu)"),
217 long minval = - (1L << (length - 1));
218 long maxval = (1L << (length - 1)) - 1;
219 if (value < minval || value > maxval)
222 /* xgettext:c-format */
223 (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
224 value, minval, maxval);
234 if (CGEN_INSN_LSB0_P)
235 shift = (start + 1) - length;
237 shift = word_length - (start + length);
238 *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
241 #else /* ! CGEN_INT_INSN_P */
244 unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
246 insert_1 (cd, value, start, length, word_length, bufp);
249 #endif /* ! CGEN_INT_INSN_P */
254 /* Default insn builder (insert handler).
255 The instruction is recorded in CGEN_INT_INSN_P byte order
256 (meaning that if CGEN_INT_INSN_P BUFFER is an int * and thus the value is
257 recorded in host byte order, otherwise BUFFER is an array of bytes and the
258 value is recorded in target byte order).
259 The result is an error message or NULL if success. */
262 insert_insn_normal (cd, insn, fields, buffer, pc)
264 const CGEN_INSN * insn;
265 CGEN_FIELDS * fields;
266 CGEN_INSN_BYTES_PTR buffer;
269 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
271 const unsigned char * syn;
273 CGEN_INIT_INSERT (cd);
274 value = CGEN_INSN_BASE_VALUE (insn);
276 /* If we're recording insns as numbers (rather than a string of bytes),
277 target byte order handling is deferred until later. */
285 cgen_put_insn_value (cd, buffer, min (cd->base_insn_bitsize,
286 CGEN_FIELDS_BITSIZE (fields)),
289 #endif /* ! CGEN_INT_INSN_P */
291 /* ??? It would be better to scan the format's fields.
292 Still need to be able to insert a value based on the operand though;
293 e.g. storing a branch displacement that got resolved later.
294 Needs more thought first. */
296 for (syn = CGEN_SYNTAX_STRING (syntax); * syn != '\0'; ++ syn)
300 if (CGEN_SYNTAX_CHAR_P (* syn))
303 errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
312 /* Operand extraction. */
314 #if ! CGEN_INT_INSN_P
316 /* Subroutine of extract_normal.
317 Ensure sufficient bytes are cached in EX_INFO.
318 OFFSET is the offset in bytes from the start of the insn of the value.
319 BYTES is the length of the needed value.
320 Returns 1 for success, 0 for failure. */
322 static CGEN_INLINE int
323 fill_cache (cd, ex_info, offset, bytes, pc)
325 CGEN_EXTRACT_INFO *ex_info;
329 /* It's doubtful that the middle part has already been fetched so
330 we don't optimize that case. kiss. */
332 disassemble_info *info = (disassemble_info *) ex_info->dis_info;
334 /* First do a quick check. */
335 mask = (1 << bytes) - 1;
336 if (((ex_info->valid >> offset) & mask) == mask)
339 /* Search for the first byte we need to read. */
340 for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
341 if (! (mask & ex_info->valid))
349 status = (*info->read_memory_func)
350 (pc, ex_info->insn_bytes + offset, bytes, info);
354 (*info->memory_error_func) (status, pc, info);
358 ex_info->valid |= ((1 << bytes) - 1) << offset;
364 /* Subroutine of extract_normal. */
366 static CGEN_INLINE long
367 extract_1 (cd, ex_info, start, length, word_length, bufp, pc)
369 CGEN_EXTRACT_INFO *ex_info;
370 int start,length,word_length;
374 unsigned long x,mask;
376 int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
385 x = bfd_getb16 (bufp);
387 x = bfd_getl16 (bufp);
390 /* ??? This may need reworking as these cases don't necessarily
391 want the first byte and the last two bytes handled like this. */
393 x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
395 x = bfd_getl16 (bufp) | (bufp[2] << 16);
399 x = bfd_getb32 (bufp);
401 x = bfd_getl32 (bufp);
407 /* Written this way to avoid undefined behaviour. */
408 mask = (((1L << (length - 1)) - 1) << 1) | 1;
409 if (CGEN_INSN_LSB0_P)
410 shift = (start + 1) - length;
412 shift = (word_length - (start + length));
413 return (x >> shift) & mask;
416 #endif /* ! CGEN_INT_INSN_P */
418 /* Default extraction routine.
420 INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
421 or sometimes less for cases like the m32r where the base insn size is 32
422 but some insns are 16 bits.
423 ATTRS is a mask of the boolean attributes. We only need `SIGNED',
424 but for generality we take a bitmask of all of them.
425 WORD_OFFSET is the offset in bits from the start of the insn of the value.
426 WORD_LENGTH is the length of the word in bits in which the value resides.
427 START is the starting bit number in the word, architecture origin.
428 LENGTH is the length of VALUE in bits.
429 TOTAL_LENGTH is the total length of the insn in bits.
431 Returns 1 for success, 0 for failure. */
433 /* ??? The return code isn't properly used. wip. */
435 /* ??? This doesn't handle bfd_vma's. Create another function when
439 extract_normal (cd, ex_info, insn_value, attrs, word_offset, start, length,
440 word_length, total_length, pc, valuep)
442 CGEN_EXTRACT_INFO *ex_info;
443 CGEN_INSN_INT insn_value;
445 unsigned int word_offset, start, length, word_length, total_length;
451 /* If LENGTH is zero, this operand doesn't contribute to the value
452 so give it a standard value of zero. */
463 if (word_length > 32)
466 /* For architectures with insns smaller than the insn-base-bitsize,
467 word_length may be too big. */
468 if (cd->min_insn_bitsize < cd->base_insn_bitsize)
471 && word_length > total_length)
472 word_length = total_length;
475 /* Does the value reside in INSN_VALUE? */
477 if (word_offset == 0)
479 /* Written this way to avoid undefined behaviour. */
480 CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
482 if (CGEN_INSN_LSB0_P)
483 value = insn_value >> ((start + 1) - length);
485 value = insn_value >> (word_length - (start + length));
488 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
489 && (value & (1L << (length - 1))))
493 #if ! CGEN_INT_INSN_P
497 unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
499 if (word_length > 32)
502 if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
505 value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
508 #endif /* ! CGEN_INT_INSN_P */
515 /* Default insn extractor.
517 INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
518 The extracted fields are stored in FIELDS.
519 EX_INFO is used to handle reading variable length insns.
520 Return the length of the insn in bits, or 0 if no match,
521 or -1 if an error occurs fetching data (memory_error_func will have
525 extract_insn_normal (cd, insn, ex_info, insn_value, fields, pc)
527 const CGEN_INSN *insn;
528 CGEN_EXTRACT_INFO *ex_info;
529 CGEN_INSN_INT insn_value;
533 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
534 const unsigned char *syn;
536 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
538 CGEN_INIT_EXTRACT (cd);
540 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
544 if (CGEN_SYNTAX_CHAR_P (*syn))
547 length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
548 ex_info, insn_value, fields, pc);
553 /* We recognized and successfully extracted this insn. */
554 return CGEN_INSN_BITSIZE (insn);
557 /* machine generated code added here */
559 /* Main entry point for operand insertion.
561 This function is basically just a big switch statement. Earlier versions
562 used tables to look up the function to use, but
563 - if the table contains both assembler and disassembler functions then
564 the disassembler contains much of the assembler and vice-versa,
565 - there's a lot of inlining possibilities as things grow,
566 - using a switch statement avoids the function call overhead.
568 This function could be moved into `parse_insn_normal', but keeping it
569 separate makes clear the interface between `parse_insn_normal' and each of
570 the handlers. It's also needed by GAS to insert operands that couldn't be
571 resolved during parsing.
575 fr30_cgen_insert_operand (cd, opindex, fields, buffer, pc)
578 CGEN_FIELDS * fields;
579 CGEN_INSN_BYTES_PTR buffer;
582 const char * errmsg = NULL;
583 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
587 case FR30_OPERAND_CRI :
588 errmsg = insert_normal (cd, fields->f_CRi, 0, 16, 12, 4, 16, total_length, buffer);
590 case FR30_OPERAND_CRJ :
591 errmsg = insert_normal (cd, fields->f_CRj, 0, 16, 8, 4, 16, total_length, buffer);
593 case FR30_OPERAND_R13 :
595 case FR30_OPERAND_R14 :
597 case FR30_OPERAND_R15 :
599 case FR30_OPERAND_RI :
600 errmsg = insert_normal (cd, fields->f_Ri, 0, 0, 12, 4, 16, total_length, buffer);
602 case FR30_OPERAND_RIC :
603 errmsg = insert_normal (cd, fields->f_Ric, 0, 16, 12, 4, 16, total_length, buffer);
605 case FR30_OPERAND_RJ :
606 errmsg = insert_normal (cd, fields->f_Rj, 0, 0, 8, 4, 16, total_length, buffer);
608 case FR30_OPERAND_RJC :
609 errmsg = insert_normal (cd, fields->f_Rjc, 0, 16, 8, 4, 16, total_length, buffer);
611 case FR30_OPERAND_RS1 :
612 errmsg = insert_normal (cd, fields->f_Rs1, 0, 0, 8, 4, 16, total_length, buffer);
614 case FR30_OPERAND_RS2 :
615 errmsg = insert_normal (cd, fields->f_Rs2, 0, 0, 12, 4, 16, total_length, buffer);
617 case FR30_OPERAND_CC :
618 errmsg = insert_normal (cd, fields->f_cc, 0, 0, 4, 4, 16, total_length, buffer);
620 case FR30_OPERAND_CCC :
621 errmsg = insert_normal (cd, fields->f_ccc, 0, 16, 0, 8, 16, total_length, buffer);
623 case FR30_OPERAND_DIR10 :
625 long value = fields->f_dir10;
626 value = ((unsigned int) (value) >> (2));
627 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
630 case FR30_OPERAND_DIR8 :
631 errmsg = insert_normal (cd, fields->f_dir8, 0, 0, 8, 8, 16, total_length, buffer);
633 case FR30_OPERAND_DIR9 :
635 long value = fields->f_dir9;
636 value = ((unsigned int) (value) >> (1));
637 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
640 case FR30_OPERAND_DISP10 :
642 long value = fields->f_disp10;
643 value = ((int) (value) >> (2));
644 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
647 case FR30_OPERAND_DISP8 :
648 errmsg = insert_normal (cd, fields->f_disp8, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
650 case FR30_OPERAND_DISP9 :
652 long value = fields->f_disp9;
653 value = ((int) (value) >> (1));
654 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
657 case FR30_OPERAND_I20 :
660 FLD (f_i20_4) = ((unsigned int) (FLD (f_i20)) >> (16));
661 FLD (f_i20_16) = ((FLD (f_i20)) & (65535));
663 errmsg = insert_normal (cd, fields->f_i20_4, 0, 0, 8, 4, 16, total_length, buffer);
666 errmsg = insert_normal (cd, fields->f_i20_16, 0, 16, 0, 16, 16, total_length, buffer);
671 case FR30_OPERAND_I32 :
672 errmsg = insert_normal (cd, fields->f_i32, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, buffer);
674 case FR30_OPERAND_I8 :
675 errmsg = insert_normal (cd, fields->f_i8, 0, 0, 4, 8, 16, total_length, buffer);
677 case FR30_OPERAND_LABEL12 :
679 long value = fields->f_rel12;
680 value = ((int) (((value) - (((pc) + (2))))) >> (1));
681 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, buffer);
684 case FR30_OPERAND_LABEL9 :
686 long value = fields->f_rel9;
687 value = ((int) (((value) - (((pc) + (2))))) >> (1));
688 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, buffer);
691 case FR30_OPERAND_M4 :
693 long value = fields->f_m4;
694 value = ((value) & (15));
695 errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
698 case FR30_OPERAND_PS :
700 case FR30_OPERAND_REGLIST_HI_LD :
701 errmsg = insert_normal (cd, fields->f_reglist_hi_ld, 0, 0, 8, 8, 16, total_length, buffer);
703 case FR30_OPERAND_REGLIST_HI_ST :
704 errmsg = insert_normal (cd, fields->f_reglist_hi_st, 0, 0, 8, 8, 16, total_length, buffer);
706 case FR30_OPERAND_REGLIST_LOW_LD :
707 errmsg = insert_normal (cd, fields->f_reglist_low_ld, 0, 0, 8, 8, 16, total_length, buffer);
709 case FR30_OPERAND_REGLIST_LOW_ST :
710 errmsg = insert_normal (cd, fields->f_reglist_low_st, 0, 0, 8, 8, 16, total_length, buffer);
712 case FR30_OPERAND_S10 :
714 long value = fields->f_s10;
715 value = ((int) (value) >> (2));
716 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, buffer);
719 case FR30_OPERAND_U10 :
721 long value = fields->f_u10;
722 value = ((unsigned int) (value) >> (2));
723 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
726 case FR30_OPERAND_U4 :
727 errmsg = insert_normal (cd, fields->f_u4, 0, 0, 8, 4, 16, total_length, buffer);
729 case FR30_OPERAND_U4C :
730 errmsg = insert_normal (cd, fields->f_u4c, 0, 0, 12, 4, 16, total_length, buffer);
732 case FR30_OPERAND_U8 :
733 errmsg = insert_normal (cd, fields->f_u8, 0, 0, 8, 8, 16, total_length, buffer);
735 case FR30_OPERAND_UDISP6 :
737 long value = fields->f_udisp6;
738 value = ((unsigned int) (value) >> (2));
739 errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
744 /* xgettext:c-format */
745 fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
753 /* Main entry point for operand extraction.
754 The result is <= 0 for error, >0 for success.
755 ??? Actual values aren't well defined right now.
757 This function is basically just a big switch statement. Earlier versions
758 used tables to look up the function to use, but
759 - if the table contains both assembler and disassembler functions then
760 the disassembler contains much of the assembler and vice-versa,
761 - there's a lot of inlining possibilities as things grow,
762 - using a switch statement avoids the function call overhead.
764 This function could be moved into `print_insn_normal', but keeping it
765 separate makes clear the interface between `print_insn_normal' and each of
770 fr30_cgen_extract_operand (cd, opindex, ex_info, insn_value, fields, pc)
773 CGEN_EXTRACT_INFO *ex_info;
774 CGEN_INSN_INT insn_value;
775 CGEN_FIELDS * fields;
778 /* Assume success (for those operands that are nops). */
780 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
784 case FR30_OPERAND_CRI :
785 length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_CRi);
787 case FR30_OPERAND_CRJ :
788 length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_CRj);
790 case FR30_OPERAND_R13 :
792 case FR30_OPERAND_R14 :
794 case FR30_OPERAND_R15 :
796 case FR30_OPERAND_RI :
797 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Ri);
799 case FR30_OPERAND_RIC :
800 length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_Ric);
802 case FR30_OPERAND_RJ :
803 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rj);
805 case FR30_OPERAND_RJC :
806 length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_Rjc);
808 case FR30_OPERAND_RS1 :
809 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rs1);
811 case FR30_OPERAND_RS2 :
812 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Rs2);
814 case FR30_OPERAND_CC :
815 length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 4, 16, total_length, pc, & fields->f_cc);
817 case FR30_OPERAND_CCC :
818 length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 8, 16, total_length, pc, & fields->f_ccc);
820 case FR30_OPERAND_DIR10 :
823 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
824 value = ((value) << (2));
825 fields->f_dir10 = value;
828 case FR30_OPERAND_DIR8 :
829 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_dir8);
831 case FR30_OPERAND_DIR9 :
834 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
835 value = ((value) << (1));
836 fields->f_dir9 = value;
839 case FR30_OPERAND_DISP10 :
842 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
843 value = ((value) << (2));
844 fields->f_disp10 = value;
847 case FR30_OPERAND_DISP8 :
848 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & fields->f_disp8);
850 case FR30_OPERAND_DISP9 :
853 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
854 value = ((value) << (1));
855 fields->f_disp9 = value;
858 case FR30_OPERAND_I20 :
860 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_i20_4);
861 length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 16, 16, total_length, pc, & fields->f_i20_16);
863 FLD (f_i20) = ((((FLD (f_i20_4)) << (16))) | (FLD (f_i20_16)));
867 case FR30_OPERAND_I32 :
868 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, pc, & fields->f_i32);
870 case FR30_OPERAND_I8 :
871 length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 8, 16, total_length, pc, & fields->f_i8);
873 case FR30_OPERAND_LABEL12 :
876 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);
877 value = ((((value) << (1))) + (((pc) + (2))));
878 fields->f_rel12 = value;
881 case FR30_OPERAND_LABEL9 :
884 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);
885 value = ((((value) << (1))) + (((pc) + (2))));
886 fields->f_rel9 = value;
889 case FR30_OPERAND_M4 :
892 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
893 value = ((value) | (((-1) << (4))));
894 fields->f_m4 = value;
897 case FR30_OPERAND_PS :
899 case FR30_OPERAND_REGLIST_HI_LD :
900 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_ld);
902 case FR30_OPERAND_REGLIST_HI_ST :
903 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_st);
905 case FR30_OPERAND_REGLIST_LOW_LD :
906 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_ld);
908 case FR30_OPERAND_REGLIST_LOW_ST :
909 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_st);
911 case FR30_OPERAND_S10 :
914 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, pc, & value);
915 value = ((value) << (2));
916 fields->f_s10 = value;
919 case FR30_OPERAND_U10 :
922 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
923 value = ((value) << (2));
924 fields->f_u10 = value;
927 case FR30_OPERAND_U4 :
928 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_u4);
930 case FR30_OPERAND_U4C :
931 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_u4c);
933 case FR30_OPERAND_U8 :
934 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_u8);
936 case FR30_OPERAND_UDISP6 :
939 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
940 value = ((value) << (2));
941 fields->f_udisp6 = value;
946 /* xgettext:c-format */
947 fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
955 cgen_insert_fn * const fr30_cgen_insert_handlers[] =
960 cgen_extract_fn * const fr30_cgen_extract_handlers[] =
965 /* Getting values from cgen_fields is handled by a collection of functions.
966 They are distinguished by the type of the VALUE argument they return.
967 TODO: floating point, inlining support, remove cases where result type
971 fr30_cgen_get_int_operand (cd, opindex, fields)
974 const CGEN_FIELDS * fields;
980 case FR30_OPERAND_CRI :
981 value = fields->f_CRi;
983 case FR30_OPERAND_CRJ :
984 value = fields->f_CRj;
986 case FR30_OPERAND_R13 :
989 case FR30_OPERAND_R14 :
992 case FR30_OPERAND_R15 :
995 case FR30_OPERAND_RI :
996 value = fields->f_Ri;
998 case FR30_OPERAND_RIC :
999 value = fields->f_Ric;
1001 case FR30_OPERAND_RJ :
1002 value = fields->f_Rj;
1004 case FR30_OPERAND_RJC :
1005 value = fields->f_Rjc;
1007 case FR30_OPERAND_RS1 :
1008 value = fields->f_Rs1;
1010 case FR30_OPERAND_RS2 :
1011 value = fields->f_Rs2;
1013 case FR30_OPERAND_CC :
1014 value = fields->f_cc;
1016 case FR30_OPERAND_CCC :
1017 value = fields->f_ccc;
1019 case FR30_OPERAND_DIR10 :
1020 value = fields->f_dir10;
1022 case FR30_OPERAND_DIR8 :
1023 value = fields->f_dir8;
1025 case FR30_OPERAND_DIR9 :
1026 value = fields->f_dir9;
1028 case FR30_OPERAND_DISP10 :
1029 value = fields->f_disp10;
1031 case FR30_OPERAND_DISP8 :
1032 value = fields->f_disp8;
1034 case FR30_OPERAND_DISP9 :
1035 value = fields->f_disp9;
1037 case FR30_OPERAND_I20 :
1038 value = fields->f_i20;
1040 case FR30_OPERAND_I32 :
1041 value = fields->f_i32;
1043 case FR30_OPERAND_I8 :
1044 value = fields->f_i8;
1046 case FR30_OPERAND_LABEL12 :
1047 value = fields->f_rel12;
1049 case FR30_OPERAND_LABEL9 :
1050 value = fields->f_rel9;
1052 case FR30_OPERAND_M4 :
1053 value = fields->f_m4;
1055 case FR30_OPERAND_PS :
1058 case FR30_OPERAND_REGLIST_HI_LD :
1059 value = fields->f_reglist_hi_ld;
1061 case FR30_OPERAND_REGLIST_HI_ST :
1062 value = fields->f_reglist_hi_st;
1064 case FR30_OPERAND_REGLIST_LOW_LD :
1065 value = fields->f_reglist_low_ld;
1067 case FR30_OPERAND_REGLIST_LOW_ST :
1068 value = fields->f_reglist_low_st;
1070 case FR30_OPERAND_S10 :
1071 value = fields->f_s10;
1073 case FR30_OPERAND_U10 :
1074 value = fields->f_u10;
1076 case FR30_OPERAND_U4 :
1077 value = fields->f_u4;
1079 case FR30_OPERAND_U4C :
1080 value = fields->f_u4c;
1082 case FR30_OPERAND_U8 :
1083 value = fields->f_u8;
1085 case FR30_OPERAND_UDISP6 :
1086 value = fields->f_udisp6;
1090 /* xgettext:c-format */
1091 fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
1100 fr30_cgen_get_vma_operand (cd, opindex, fields)
1103 const CGEN_FIELDS * fields;
1109 case FR30_OPERAND_CRI :
1110 value = fields->f_CRi;
1112 case FR30_OPERAND_CRJ :
1113 value = fields->f_CRj;
1115 case FR30_OPERAND_R13 :
1118 case FR30_OPERAND_R14 :
1121 case FR30_OPERAND_R15 :
1124 case FR30_OPERAND_RI :
1125 value = fields->f_Ri;
1127 case FR30_OPERAND_RIC :
1128 value = fields->f_Ric;
1130 case FR30_OPERAND_RJ :
1131 value = fields->f_Rj;
1133 case FR30_OPERAND_RJC :
1134 value = fields->f_Rjc;
1136 case FR30_OPERAND_RS1 :
1137 value = fields->f_Rs1;
1139 case FR30_OPERAND_RS2 :
1140 value = fields->f_Rs2;
1142 case FR30_OPERAND_CC :
1143 value = fields->f_cc;
1145 case FR30_OPERAND_CCC :
1146 value = fields->f_ccc;
1148 case FR30_OPERAND_DIR10 :
1149 value = fields->f_dir10;
1151 case FR30_OPERAND_DIR8 :
1152 value = fields->f_dir8;
1154 case FR30_OPERAND_DIR9 :
1155 value = fields->f_dir9;
1157 case FR30_OPERAND_DISP10 :
1158 value = fields->f_disp10;
1160 case FR30_OPERAND_DISP8 :
1161 value = fields->f_disp8;
1163 case FR30_OPERAND_DISP9 :
1164 value = fields->f_disp9;
1166 case FR30_OPERAND_I20 :
1167 value = fields->f_i20;
1169 case FR30_OPERAND_I32 :
1170 value = fields->f_i32;
1172 case FR30_OPERAND_I8 :
1173 value = fields->f_i8;
1175 case FR30_OPERAND_LABEL12 :
1176 value = fields->f_rel12;
1178 case FR30_OPERAND_LABEL9 :
1179 value = fields->f_rel9;
1181 case FR30_OPERAND_M4 :
1182 value = fields->f_m4;
1184 case FR30_OPERAND_PS :
1187 case FR30_OPERAND_REGLIST_HI_LD :
1188 value = fields->f_reglist_hi_ld;
1190 case FR30_OPERAND_REGLIST_HI_ST :
1191 value = fields->f_reglist_hi_st;
1193 case FR30_OPERAND_REGLIST_LOW_LD :
1194 value = fields->f_reglist_low_ld;
1196 case FR30_OPERAND_REGLIST_LOW_ST :
1197 value = fields->f_reglist_low_st;
1199 case FR30_OPERAND_S10 :
1200 value = fields->f_s10;
1202 case FR30_OPERAND_U10 :
1203 value = fields->f_u10;
1205 case FR30_OPERAND_U4 :
1206 value = fields->f_u4;
1208 case FR30_OPERAND_U4C :
1209 value = fields->f_u4c;
1211 case FR30_OPERAND_U8 :
1212 value = fields->f_u8;
1214 case FR30_OPERAND_UDISP6 :
1215 value = fields->f_udisp6;
1219 /* xgettext:c-format */
1220 fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
1228 /* Stuffing values in cgen_fields is handled by a collection of functions.
1229 They are distinguished by the type of the VALUE argument they accept.
1230 TODO: floating point, inlining support, remove cases where argument type
1234 fr30_cgen_set_int_operand (cd, opindex, fields, value)
1237 CGEN_FIELDS * fields;
1242 case FR30_OPERAND_CRI :
1243 fields->f_CRi = value;
1245 case FR30_OPERAND_CRJ :
1246 fields->f_CRj = value;
1248 case FR30_OPERAND_R13 :
1250 case FR30_OPERAND_R14 :
1252 case FR30_OPERAND_R15 :
1254 case FR30_OPERAND_RI :
1255 fields->f_Ri = value;
1257 case FR30_OPERAND_RIC :
1258 fields->f_Ric = value;
1260 case FR30_OPERAND_RJ :
1261 fields->f_Rj = value;
1263 case FR30_OPERAND_RJC :
1264 fields->f_Rjc = value;
1266 case FR30_OPERAND_RS1 :
1267 fields->f_Rs1 = value;
1269 case FR30_OPERAND_RS2 :
1270 fields->f_Rs2 = value;
1272 case FR30_OPERAND_CC :
1273 fields->f_cc = value;
1275 case FR30_OPERAND_CCC :
1276 fields->f_ccc = value;
1278 case FR30_OPERAND_DIR10 :
1279 fields->f_dir10 = value;
1281 case FR30_OPERAND_DIR8 :
1282 fields->f_dir8 = value;
1284 case FR30_OPERAND_DIR9 :
1285 fields->f_dir9 = value;
1287 case FR30_OPERAND_DISP10 :
1288 fields->f_disp10 = value;
1290 case FR30_OPERAND_DISP8 :
1291 fields->f_disp8 = value;
1293 case FR30_OPERAND_DISP9 :
1294 fields->f_disp9 = value;
1296 case FR30_OPERAND_I20 :
1297 fields->f_i20 = value;
1299 case FR30_OPERAND_I32 :
1300 fields->f_i32 = value;
1302 case FR30_OPERAND_I8 :
1303 fields->f_i8 = value;
1305 case FR30_OPERAND_LABEL12 :
1306 fields->f_rel12 = value;
1308 case FR30_OPERAND_LABEL9 :
1309 fields->f_rel9 = value;
1311 case FR30_OPERAND_M4 :
1312 fields->f_m4 = value;
1314 case FR30_OPERAND_PS :
1316 case FR30_OPERAND_REGLIST_HI_LD :
1317 fields->f_reglist_hi_ld = value;
1319 case FR30_OPERAND_REGLIST_HI_ST :
1320 fields->f_reglist_hi_st = value;
1322 case FR30_OPERAND_REGLIST_LOW_LD :
1323 fields->f_reglist_low_ld = value;
1325 case FR30_OPERAND_REGLIST_LOW_ST :
1326 fields->f_reglist_low_st = value;
1328 case FR30_OPERAND_S10 :
1329 fields->f_s10 = value;
1331 case FR30_OPERAND_U10 :
1332 fields->f_u10 = value;
1334 case FR30_OPERAND_U4 :
1335 fields->f_u4 = value;
1337 case FR30_OPERAND_U4C :
1338 fields->f_u4c = value;
1340 case FR30_OPERAND_U8 :
1341 fields->f_u8 = value;
1343 case FR30_OPERAND_UDISP6 :
1344 fields->f_udisp6 = value;
1348 /* xgettext:c-format */
1349 fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
1356 fr30_cgen_set_vma_operand (cd, opindex, fields, value)
1359 CGEN_FIELDS * fields;
1364 case FR30_OPERAND_CRI :
1365 fields->f_CRi = value;
1367 case FR30_OPERAND_CRJ :
1368 fields->f_CRj = value;
1370 case FR30_OPERAND_R13 :
1372 case FR30_OPERAND_R14 :
1374 case FR30_OPERAND_R15 :
1376 case FR30_OPERAND_RI :
1377 fields->f_Ri = value;
1379 case FR30_OPERAND_RIC :
1380 fields->f_Ric = value;
1382 case FR30_OPERAND_RJ :
1383 fields->f_Rj = value;
1385 case FR30_OPERAND_RJC :
1386 fields->f_Rjc = value;
1388 case FR30_OPERAND_RS1 :
1389 fields->f_Rs1 = value;
1391 case FR30_OPERAND_RS2 :
1392 fields->f_Rs2 = value;
1394 case FR30_OPERAND_CC :
1395 fields->f_cc = value;
1397 case FR30_OPERAND_CCC :
1398 fields->f_ccc = value;
1400 case FR30_OPERAND_DIR10 :
1401 fields->f_dir10 = value;
1403 case FR30_OPERAND_DIR8 :
1404 fields->f_dir8 = value;
1406 case FR30_OPERAND_DIR9 :
1407 fields->f_dir9 = value;
1409 case FR30_OPERAND_DISP10 :
1410 fields->f_disp10 = value;
1412 case FR30_OPERAND_DISP8 :
1413 fields->f_disp8 = value;
1415 case FR30_OPERAND_DISP9 :
1416 fields->f_disp9 = value;
1418 case FR30_OPERAND_I20 :
1419 fields->f_i20 = value;
1421 case FR30_OPERAND_I32 :
1422 fields->f_i32 = value;
1424 case FR30_OPERAND_I8 :
1425 fields->f_i8 = value;
1427 case FR30_OPERAND_LABEL12 :
1428 fields->f_rel12 = value;
1430 case FR30_OPERAND_LABEL9 :
1431 fields->f_rel9 = value;
1433 case FR30_OPERAND_M4 :
1434 fields->f_m4 = value;
1436 case FR30_OPERAND_PS :
1438 case FR30_OPERAND_REGLIST_HI_LD :
1439 fields->f_reglist_hi_ld = value;
1441 case FR30_OPERAND_REGLIST_HI_ST :
1442 fields->f_reglist_hi_st = value;
1444 case FR30_OPERAND_REGLIST_LOW_LD :
1445 fields->f_reglist_low_ld = value;
1447 case FR30_OPERAND_REGLIST_LOW_ST :
1448 fields->f_reglist_low_st = value;
1450 case FR30_OPERAND_S10 :
1451 fields->f_s10 = value;
1453 case FR30_OPERAND_U10 :
1454 fields->f_u10 = value;
1456 case FR30_OPERAND_U4 :
1457 fields->f_u4 = value;
1459 case FR30_OPERAND_U4C :
1460 fields->f_u4c = value;
1462 case FR30_OPERAND_U8 :
1463 fields->f_u8 = value;
1465 case FR30_OPERAND_UDISP6 :
1466 fields->f_udisp6 = value;
1470 /* xgettext:c-format */
1471 fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
1477 /* Function to call before using the instruction builder tables. */
1480 fr30_cgen_init_ibld_table (cd)
1483 cd->insert_handlers = & fr30_cgen_insert_handlers[0];
1484 cd->extract_handlers = & fr30_cgen_extract_handlers[0];
1486 cd->insert_operand = fr30_cgen_insert_operand;
1487 cd->extract_operand = fr30_cgen_extract_operand;
1489 cd->get_int_operand = fr30_cgen_get_int_operand;
1490 cd->set_int_operand = fr30_cgen_set_int_operand;
1491 cd->get_vma_operand = fr30_cgen_get_vma_operand;
1492 cd->set_vma_operand = fr30_cgen_set_vma_operand;