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;
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 :
594 errmsg = insert_normal (cd, fields->f_nil, 0, 0, 0, 0, 0, total_length, buffer);
596 case FR30_OPERAND_R14 :
597 errmsg = insert_normal (cd, fields->f_nil, 0, 0, 0, 0, 0, total_length, buffer);
599 case FR30_OPERAND_R15 :
600 errmsg = insert_normal (cd, fields->f_nil, 0, 0, 0, 0, 0, total_length, buffer);
602 case FR30_OPERAND_RI :
603 errmsg = insert_normal (cd, fields->f_Ri, 0, 0, 12, 4, 16, total_length, buffer);
605 case FR30_OPERAND_RIC :
606 errmsg = insert_normal (cd, fields->f_Ric, 0, 16, 12, 4, 16, total_length, buffer);
608 case FR30_OPERAND_RJ :
609 errmsg = insert_normal (cd, fields->f_Rj, 0, 0, 8, 4, 16, total_length, buffer);
611 case FR30_OPERAND_RJC :
612 errmsg = insert_normal (cd, fields->f_Rjc, 0, 16, 8, 4, 16, total_length, buffer);
614 case FR30_OPERAND_RS1 :
615 errmsg = insert_normal (cd, fields->f_Rs1, 0, 0, 8, 4, 16, total_length, buffer);
617 case FR30_OPERAND_RS2 :
618 errmsg = insert_normal (cd, fields->f_Rs2, 0, 0, 12, 4, 16, total_length, buffer);
620 case FR30_OPERAND_CC :
621 errmsg = insert_normal (cd, fields->f_cc, 0, 0, 4, 4, 16, total_length, buffer);
623 case FR30_OPERAND_CCC :
624 errmsg = insert_normal (cd, fields->f_ccc, 0, 16, 0, 8, 16, total_length, buffer);
626 case FR30_OPERAND_DIR10 :
628 long value = fields->f_dir10;
629 value = ((unsigned int) (value) >> (2));
630 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
633 case FR30_OPERAND_DIR8 :
634 errmsg = insert_normal (cd, fields->f_dir8, 0, 0, 8, 8, 16, total_length, buffer);
636 case FR30_OPERAND_DIR9 :
638 long value = fields->f_dir9;
639 value = ((unsigned int) (value) >> (1));
640 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
643 case FR30_OPERAND_DISP10 :
645 long value = fields->f_disp10;
646 value = ((int) (value) >> (2));
647 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
650 case FR30_OPERAND_DISP8 :
651 errmsg = insert_normal (cd, fields->f_disp8, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
653 case FR30_OPERAND_DISP9 :
655 long value = fields->f_disp9;
656 value = ((int) (value) >> (1));
657 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, buffer);
660 case FR30_OPERAND_I20 :
663 FLD (f_i20_4) = ((unsigned int) (FLD (f_i20)) >> (16));
664 FLD (f_i20_16) = ((FLD (f_i20)) & (65535));
666 errmsg = insert_normal (cd, fields->f_i20_4, 0, 0, 8, 4, 16, total_length, buffer);
669 errmsg = insert_normal (cd, fields->f_i20_16, 0, 16, 0, 16, 16, total_length, buffer);
674 case FR30_OPERAND_I32 :
675 errmsg = insert_normal (cd, fields->f_i32, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, buffer);
677 case FR30_OPERAND_I8 :
678 errmsg = insert_normal (cd, fields->f_i8, 0, 0, 4, 8, 16, total_length, buffer);
680 case FR30_OPERAND_LABEL12 :
682 long value = fields->f_rel12;
683 value = ((int) (((value) - (((pc) + (2))))) >> (1));
684 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 5, 11, 16, total_length, buffer);
687 case FR30_OPERAND_LABEL9 :
689 long value = fields->f_rel9;
690 value = ((int) (((value) - (((pc) + (2))))) >> (1));
691 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 16, total_length, buffer);
694 case FR30_OPERAND_M4 :
696 long value = fields->f_m4;
697 value = ((value) & (15));
698 errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
701 case FR30_OPERAND_PS :
702 errmsg = insert_normal (cd, fields->f_nil, 0, 0, 0, 0, 0, total_length, buffer);
704 case FR30_OPERAND_REGLIST_HI_LD :
705 errmsg = insert_normal (cd, fields->f_reglist_hi_ld, 0, 0, 8, 8, 16, total_length, buffer);
707 case FR30_OPERAND_REGLIST_HI_ST :
708 errmsg = insert_normal (cd, fields->f_reglist_hi_st, 0, 0, 8, 8, 16, total_length, buffer);
710 case FR30_OPERAND_REGLIST_LOW_LD :
711 errmsg = insert_normal (cd, fields->f_reglist_low_ld, 0, 0, 8, 8, 16, total_length, buffer);
713 case FR30_OPERAND_REGLIST_LOW_ST :
714 errmsg = insert_normal (cd, fields->f_reglist_low_st, 0, 0, 8, 8, 16, total_length, buffer);
716 case FR30_OPERAND_S10 :
718 long value = fields->f_s10;
719 value = ((int) (value) >> (2));
720 errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, buffer);
723 case FR30_OPERAND_U10 :
725 long value = fields->f_u10;
726 value = ((unsigned int) (value) >> (2));
727 errmsg = insert_normal (cd, value, 0, 0, 8, 8, 16, total_length, buffer);
730 case FR30_OPERAND_U4 :
731 errmsg = insert_normal (cd, fields->f_u4, 0, 0, 8, 4, 16, total_length, buffer);
733 case FR30_OPERAND_U4C :
734 errmsg = insert_normal (cd, fields->f_u4c, 0, 0, 12, 4, 16, total_length, buffer);
736 case FR30_OPERAND_U8 :
737 errmsg = insert_normal (cd, fields->f_u8, 0, 0, 8, 8, 16, total_length, buffer);
739 case FR30_OPERAND_UDISP6 :
741 long value = fields->f_udisp6;
742 value = ((unsigned int) (value) >> (2));
743 errmsg = insert_normal (cd, value, 0, 0, 8, 4, 16, total_length, buffer);
748 /* xgettext:c-format */
749 fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
757 /* Main entry point for operand extraction.
759 This function is basically just a big switch statement. Earlier versions
760 used tables to look up the function to use, but
761 - if the table contains both assembler and disassembler functions then
762 the disassembler contains much of the assembler and vice-versa,
763 - there's a lot of inlining possibilities as things grow,
764 - using a switch statement avoids the function call overhead.
766 This function could be moved into `print_insn_normal', but keeping it
767 separate makes clear the interface between `print_insn_normal' and each of
772 fr30_cgen_extract_operand (cd, opindex, ex_info, insn_value, fields, pc)
775 CGEN_EXTRACT_INFO *ex_info;
776 CGEN_INSN_INT insn_value;
777 CGEN_FIELDS * fields;
781 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
785 case FR30_OPERAND_CRI :
786 length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_CRi);
788 case FR30_OPERAND_CRJ :
789 length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_CRj);
791 case FR30_OPERAND_R13 :
792 length = extract_normal (cd, ex_info, insn_value, 0, 0, 0, 0, 0, total_length, pc, & fields->f_nil);
794 case FR30_OPERAND_R14 :
795 length = extract_normal (cd, ex_info, insn_value, 0, 0, 0, 0, 0, total_length, pc, & fields->f_nil);
797 case FR30_OPERAND_R15 :
798 length = extract_normal (cd, ex_info, insn_value, 0, 0, 0, 0, 0, total_length, pc, & fields->f_nil);
800 case FR30_OPERAND_RI :
801 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Ri);
803 case FR30_OPERAND_RIC :
804 length = extract_normal (cd, ex_info, insn_value, 0, 16, 12, 4, 16, total_length, pc, & fields->f_Ric);
806 case FR30_OPERAND_RJ :
807 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rj);
809 case FR30_OPERAND_RJC :
810 length = extract_normal (cd, ex_info, insn_value, 0, 16, 8, 4, 16, total_length, pc, & fields->f_Rjc);
812 case FR30_OPERAND_RS1 :
813 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_Rs1);
815 case FR30_OPERAND_RS2 :
816 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_Rs2);
818 case FR30_OPERAND_CC :
819 length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 4, 16, total_length, pc, & fields->f_cc);
821 case FR30_OPERAND_CCC :
822 length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 8, 16, total_length, pc, & fields->f_ccc);
824 case FR30_OPERAND_DIR10 :
827 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
828 value = ((value) << (2));
829 fields->f_dir10 = value;
832 case FR30_OPERAND_DIR8 :
833 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_dir8);
835 case FR30_OPERAND_DIR9 :
838 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
839 value = ((value) << (1));
840 fields->f_dir9 = value;
843 case FR30_OPERAND_DISP10 :
846 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
847 value = ((value) << (2));
848 fields->f_disp10 = value;
851 case FR30_OPERAND_DISP8 :
852 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & fields->f_disp8);
854 case FR30_OPERAND_DISP9 :
857 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 4, 8, 16, total_length, pc, & value);
858 value = ((value) << (1));
859 fields->f_disp9 = value;
862 case FR30_OPERAND_I20 :
864 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_i20_4);
865 length = extract_normal (cd, ex_info, insn_value, 0, 16, 0, 16, 16, total_length, pc, & fields->f_i20_16);
867 FLD (f_i20) = ((((FLD (f_i20_4)) << (16))) | (FLD (f_i20_16)));
871 case FR30_OPERAND_I32 :
872 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT), 16, 0, 32, 32, total_length, pc, & fields->f_i32);
874 case FR30_OPERAND_I8 :
875 length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 8, 16, total_length, pc, & fields->f_i8);
877 case FR30_OPERAND_LABEL12 :
880 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);
881 value = ((((value) << (1))) + (((pc) + (2))));
882 fields->f_rel12 = value;
885 case FR30_OPERAND_LABEL9 :
888 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);
889 value = ((((value) << (1))) + (((pc) + (2))));
890 fields->f_rel9 = value;
893 case FR30_OPERAND_M4 :
896 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
897 value = ((value) | (((-1) << (4))));
898 fields->f_m4 = value;
901 case FR30_OPERAND_PS :
902 length = extract_normal (cd, ex_info, insn_value, 0, 0, 0, 0, 0, total_length, pc, & fields->f_nil);
904 case FR30_OPERAND_REGLIST_HI_LD :
905 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_ld);
907 case FR30_OPERAND_REGLIST_HI_ST :
908 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_hi_st);
910 case FR30_OPERAND_REGLIST_LOW_LD :
911 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_ld);
913 case FR30_OPERAND_REGLIST_LOW_ST :
914 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_reglist_low_st);
916 case FR30_OPERAND_S10 :
919 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 8, 8, 16, total_length, pc, & value);
920 value = ((value) << (2));
921 fields->f_s10 = value;
924 case FR30_OPERAND_U10 :
927 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & value);
928 value = ((value) << (2));
929 fields->f_u10 = value;
932 case FR30_OPERAND_U4 :
933 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & fields->f_u4);
935 case FR30_OPERAND_U4C :
936 length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 16, total_length, pc, & fields->f_u4c);
938 case FR30_OPERAND_U8 :
939 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 16, total_length, pc, & fields->f_u8);
941 case FR30_OPERAND_UDISP6 :
944 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 16, total_length, pc, & value);
945 value = ((value) << (2));
946 fields->f_udisp6 = value;
951 /* xgettext:c-format */
952 fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
960 cgen_insert_fn * const fr30_cgen_insert_handlers[] =
965 cgen_extract_fn * const fr30_cgen_extract_handlers[] =
970 /* Getting values from cgen_fields is handled by a collection of functions.
971 They are distinguished by the type of the VALUE argument they return.
972 TODO: floating point, inlining support, remove cases where result type
976 fr30_cgen_get_int_operand (cd, opindex, fields)
979 const CGEN_FIELDS * fields;
985 case FR30_OPERAND_CRI :
986 value = fields->f_CRi;
988 case FR30_OPERAND_CRJ :
989 value = fields->f_CRj;
991 case FR30_OPERAND_R13 :
992 value = fields->f_nil;
994 case FR30_OPERAND_R14 :
995 value = fields->f_nil;
997 case FR30_OPERAND_R15 :
998 value = fields->f_nil;
1000 case FR30_OPERAND_RI :
1001 value = fields->f_Ri;
1003 case FR30_OPERAND_RIC :
1004 value = fields->f_Ric;
1006 case FR30_OPERAND_RJ :
1007 value = fields->f_Rj;
1009 case FR30_OPERAND_RJC :
1010 value = fields->f_Rjc;
1012 case FR30_OPERAND_RS1 :
1013 value = fields->f_Rs1;
1015 case FR30_OPERAND_RS2 :
1016 value = fields->f_Rs2;
1018 case FR30_OPERAND_CC :
1019 value = fields->f_cc;
1021 case FR30_OPERAND_CCC :
1022 value = fields->f_ccc;
1024 case FR30_OPERAND_DIR10 :
1025 value = fields->f_dir10;
1027 case FR30_OPERAND_DIR8 :
1028 value = fields->f_dir8;
1030 case FR30_OPERAND_DIR9 :
1031 value = fields->f_dir9;
1033 case FR30_OPERAND_DISP10 :
1034 value = fields->f_disp10;
1036 case FR30_OPERAND_DISP8 :
1037 value = fields->f_disp8;
1039 case FR30_OPERAND_DISP9 :
1040 value = fields->f_disp9;
1042 case FR30_OPERAND_I20 :
1043 value = fields->f_i20;
1045 case FR30_OPERAND_I32 :
1046 value = fields->f_i32;
1048 case FR30_OPERAND_I8 :
1049 value = fields->f_i8;
1051 case FR30_OPERAND_LABEL12 :
1052 value = fields->f_rel12;
1054 case FR30_OPERAND_LABEL9 :
1055 value = fields->f_rel9;
1057 case FR30_OPERAND_M4 :
1058 value = fields->f_m4;
1060 case FR30_OPERAND_PS :
1061 value = fields->f_nil;
1063 case FR30_OPERAND_REGLIST_HI_LD :
1064 value = fields->f_reglist_hi_ld;
1066 case FR30_OPERAND_REGLIST_HI_ST :
1067 value = fields->f_reglist_hi_st;
1069 case FR30_OPERAND_REGLIST_LOW_LD :
1070 value = fields->f_reglist_low_ld;
1072 case FR30_OPERAND_REGLIST_LOW_ST :
1073 value = fields->f_reglist_low_st;
1075 case FR30_OPERAND_S10 :
1076 value = fields->f_s10;
1078 case FR30_OPERAND_U10 :
1079 value = fields->f_u10;
1081 case FR30_OPERAND_U4 :
1082 value = fields->f_u4;
1084 case FR30_OPERAND_U4C :
1085 value = fields->f_u4c;
1087 case FR30_OPERAND_U8 :
1088 value = fields->f_u8;
1090 case FR30_OPERAND_UDISP6 :
1091 value = fields->f_udisp6;
1095 /* xgettext:c-format */
1096 fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
1105 fr30_cgen_get_vma_operand (cd, opindex, fields)
1108 const CGEN_FIELDS * fields;
1114 case FR30_OPERAND_CRI :
1115 value = fields->f_CRi;
1117 case FR30_OPERAND_CRJ :
1118 value = fields->f_CRj;
1120 case FR30_OPERAND_R13 :
1121 value = fields->f_nil;
1123 case FR30_OPERAND_R14 :
1124 value = fields->f_nil;
1126 case FR30_OPERAND_R15 :
1127 value = fields->f_nil;
1129 case FR30_OPERAND_RI :
1130 value = fields->f_Ri;
1132 case FR30_OPERAND_RIC :
1133 value = fields->f_Ric;
1135 case FR30_OPERAND_RJ :
1136 value = fields->f_Rj;
1138 case FR30_OPERAND_RJC :
1139 value = fields->f_Rjc;
1141 case FR30_OPERAND_RS1 :
1142 value = fields->f_Rs1;
1144 case FR30_OPERAND_RS2 :
1145 value = fields->f_Rs2;
1147 case FR30_OPERAND_CC :
1148 value = fields->f_cc;
1150 case FR30_OPERAND_CCC :
1151 value = fields->f_ccc;
1153 case FR30_OPERAND_DIR10 :
1154 value = fields->f_dir10;
1156 case FR30_OPERAND_DIR8 :
1157 value = fields->f_dir8;
1159 case FR30_OPERAND_DIR9 :
1160 value = fields->f_dir9;
1162 case FR30_OPERAND_DISP10 :
1163 value = fields->f_disp10;
1165 case FR30_OPERAND_DISP8 :
1166 value = fields->f_disp8;
1168 case FR30_OPERAND_DISP9 :
1169 value = fields->f_disp9;
1171 case FR30_OPERAND_I20 :
1172 value = fields->f_i20;
1174 case FR30_OPERAND_I32 :
1175 value = fields->f_i32;
1177 case FR30_OPERAND_I8 :
1178 value = fields->f_i8;
1180 case FR30_OPERAND_LABEL12 :
1181 value = fields->f_rel12;
1183 case FR30_OPERAND_LABEL9 :
1184 value = fields->f_rel9;
1186 case FR30_OPERAND_M4 :
1187 value = fields->f_m4;
1189 case FR30_OPERAND_PS :
1190 value = fields->f_nil;
1192 case FR30_OPERAND_REGLIST_HI_LD :
1193 value = fields->f_reglist_hi_ld;
1195 case FR30_OPERAND_REGLIST_HI_ST :
1196 value = fields->f_reglist_hi_st;
1198 case FR30_OPERAND_REGLIST_LOW_LD :
1199 value = fields->f_reglist_low_ld;
1201 case FR30_OPERAND_REGLIST_LOW_ST :
1202 value = fields->f_reglist_low_st;
1204 case FR30_OPERAND_S10 :
1205 value = fields->f_s10;
1207 case FR30_OPERAND_U10 :
1208 value = fields->f_u10;
1210 case FR30_OPERAND_U4 :
1211 value = fields->f_u4;
1213 case FR30_OPERAND_U4C :
1214 value = fields->f_u4c;
1216 case FR30_OPERAND_U8 :
1217 value = fields->f_u8;
1219 case FR30_OPERAND_UDISP6 :
1220 value = fields->f_udisp6;
1224 /* xgettext:c-format */
1225 fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
1233 /* Stuffing values in cgen_fields is handled by a collection of functions.
1234 They are distinguished by the type of the VALUE argument they accept.
1235 TODO: floating point, inlining support, remove cases where argument type
1239 fr30_cgen_set_int_operand (cd, opindex, fields, value)
1242 CGEN_FIELDS * fields;
1247 case FR30_OPERAND_CRI :
1248 fields->f_CRi = value;
1250 case FR30_OPERAND_CRJ :
1251 fields->f_CRj = value;
1253 case FR30_OPERAND_R13 :
1254 fields->f_nil = value;
1256 case FR30_OPERAND_R14 :
1257 fields->f_nil = value;
1259 case FR30_OPERAND_R15 :
1260 fields->f_nil = value;
1262 case FR30_OPERAND_RI :
1263 fields->f_Ri = value;
1265 case FR30_OPERAND_RIC :
1266 fields->f_Ric = value;
1268 case FR30_OPERAND_RJ :
1269 fields->f_Rj = value;
1271 case FR30_OPERAND_RJC :
1272 fields->f_Rjc = value;
1274 case FR30_OPERAND_RS1 :
1275 fields->f_Rs1 = value;
1277 case FR30_OPERAND_RS2 :
1278 fields->f_Rs2 = value;
1280 case FR30_OPERAND_CC :
1281 fields->f_cc = value;
1283 case FR30_OPERAND_CCC :
1284 fields->f_ccc = value;
1286 case FR30_OPERAND_DIR10 :
1287 fields->f_dir10 = value;
1289 case FR30_OPERAND_DIR8 :
1290 fields->f_dir8 = value;
1292 case FR30_OPERAND_DIR9 :
1293 fields->f_dir9 = value;
1295 case FR30_OPERAND_DISP10 :
1296 fields->f_disp10 = value;
1298 case FR30_OPERAND_DISP8 :
1299 fields->f_disp8 = value;
1301 case FR30_OPERAND_DISP9 :
1302 fields->f_disp9 = value;
1304 case FR30_OPERAND_I20 :
1305 fields->f_i20 = value;
1307 case FR30_OPERAND_I32 :
1308 fields->f_i32 = value;
1310 case FR30_OPERAND_I8 :
1311 fields->f_i8 = value;
1313 case FR30_OPERAND_LABEL12 :
1314 fields->f_rel12 = value;
1316 case FR30_OPERAND_LABEL9 :
1317 fields->f_rel9 = value;
1319 case FR30_OPERAND_M4 :
1320 fields->f_m4 = value;
1322 case FR30_OPERAND_PS :
1323 fields->f_nil = value;
1325 case FR30_OPERAND_REGLIST_HI_LD :
1326 fields->f_reglist_hi_ld = value;
1328 case FR30_OPERAND_REGLIST_HI_ST :
1329 fields->f_reglist_hi_st = value;
1331 case FR30_OPERAND_REGLIST_LOW_LD :
1332 fields->f_reglist_low_ld = value;
1334 case FR30_OPERAND_REGLIST_LOW_ST :
1335 fields->f_reglist_low_st = value;
1337 case FR30_OPERAND_S10 :
1338 fields->f_s10 = value;
1340 case FR30_OPERAND_U10 :
1341 fields->f_u10 = value;
1343 case FR30_OPERAND_U4 :
1344 fields->f_u4 = value;
1346 case FR30_OPERAND_U4C :
1347 fields->f_u4c = value;
1349 case FR30_OPERAND_U8 :
1350 fields->f_u8 = value;
1352 case FR30_OPERAND_UDISP6 :
1353 fields->f_udisp6 = value;
1357 /* xgettext:c-format */
1358 fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
1365 fr30_cgen_set_vma_operand (cd, opindex, fields, value)
1368 CGEN_FIELDS * fields;
1373 case FR30_OPERAND_CRI :
1374 fields->f_CRi = value;
1376 case FR30_OPERAND_CRJ :
1377 fields->f_CRj = value;
1379 case FR30_OPERAND_R13 :
1380 fields->f_nil = value;
1382 case FR30_OPERAND_R14 :
1383 fields->f_nil = value;
1385 case FR30_OPERAND_R15 :
1386 fields->f_nil = value;
1388 case FR30_OPERAND_RI :
1389 fields->f_Ri = value;
1391 case FR30_OPERAND_RIC :
1392 fields->f_Ric = value;
1394 case FR30_OPERAND_RJ :
1395 fields->f_Rj = value;
1397 case FR30_OPERAND_RJC :
1398 fields->f_Rjc = value;
1400 case FR30_OPERAND_RS1 :
1401 fields->f_Rs1 = value;
1403 case FR30_OPERAND_RS2 :
1404 fields->f_Rs2 = value;
1406 case FR30_OPERAND_CC :
1407 fields->f_cc = value;
1409 case FR30_OPERAND_CCC :
1410 fields->f_ccc = value;
1412 case FR30_OPERAND_DIR10 :
1413 fields->f_dir10 = value;
1415 case FR30_OPERAND_DIR8 :
1416 fields->f_dir8 = value;
1418 case FR30_OPERAND_DIR9 :
1419 fields->f_dir9 = value;
1421 case FR30_OPERAND_DISP10 :
1422 fields->f_disp10 = value;
1424 case FR30_OPERAND_DISP8 :
1425 fields->f_disp8 = value;
1427 case FR30_OPERAND_DISP9 :
1428 fields->f_disp9 = value;
1430 case FR30_OPERAND_I20 :
1431 fields->f_i20 = value;
1433 case FR30_OPERAND_I32 :
1434 fields->f_i32 = value;
1436 case FR30_OPERAND_I8 :
1437 fields->f_i8 = value;
1439 case FR30_OPERAND_LABEL12 :
1440 fields->f_rel12 = value;
1442 case FR30_OPERAND_LABEL9 :
1443 fields->f_rel9 = value;
1445 case FR30_OPERAND_M4 :
1446 fields->f_m4 = value;
1448 case FR30_OPERAND_PS :
1449 fields->f_nil = value;
1451 case FR30_OPERAND_REGLIST_HI_LD :
1452 fields->f_reglist_hi_ld = value;
1454 case FR30_OPERAND_REGLIST_HI_ST :
1455 fields->f_reglist_hi_st = value;
1457 case FR30_OPERAND_REGLIST_LOW_LD :
1458 fields->f_reglist_low_ld = value;
1460 case FR30_OPERAND_REGLIST_LOW_ST :
1461 fields->f_reglist_low_st = value;
1463 case FR30_OPERAND_S10 :
1464 fields->f_s10 = value;
1466 case FR30_OPERAND_U10 :
1467 fields->f_u10 = value;
1469 case FR30_OPERAND_U4 :
1470 fields->f_u4 = value;
1472 case FR30_OPERAND_U4C :
1473 fields->f_u4c = value;
1475 case FR30_OPERAND_U8 :
1476 fields->f_u8 = value;
1478 case FR30_OPERAND_UDISP6 :
1479 fields->f_udisp6 = value;
1483 /* xgettext:c-format */
1484 fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
1490 /* Function to call before using the instruction builder tables. */
1493 fr30_cgen_init_ibld_table (cd)
1496 cd->insert_handlers = & fr30_cgen_insert_handlers[0];
1497 cd->extract_handlers = & fr30_cgen_extract_handlers[0];
1499 cd->insert_operand = fr30_cgen_insert_operand;
1500 cd->extract_operand = fr30_cgen_extract_operand;
1502 cd->get_int_operand = fr30_cgen_get_int_operand;
1503 cd->set_int_operand = fr30_cgen_set_int_operand;
1504 cd->get_vma_operand = fr30_cgen_get_vma_operand;
1505 cd->set_vma_operand = fr30_cgen_set_vma_operand;