1 /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
2 /* Instruction building/extraction support for xc16x. -*- C -*-
4 THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator.
5 - the resultant file is machine generated, cgen-ibld.in isn't
7 Copyright (C) 1996-2017 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 "xc16x-desc.h"
35 #include "xc16x-opc.h"
36 #include "cgen/basic-modes.h"
38 #include "safe-ctype.h"
41 #define min(a,b) ((a) < (b) ? (a) : (b))
43 #define max(a,b) ((a) > (b) ? (a) : (b))
45 /* Used by the ifield rtx function. */
46 #define FLD(f) (fields->f)
48 static const char * insert_normal
49 (CGEN_CPU_DESC, long, unsigned int, unsigned int, unsigned int,
50 unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR);
51 static const char * insert_insn_normal
52 (CGEN_CPU_DESC, const CGEN_INSN *,
53 CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
54 static int extract_normal
55 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
56 unsigned int, unsigned int, unsigned int, unsigned int,
57 unsigned int, unsigned int, bfd_vma, long *);
58 static int extract_insn_normal
59 (CGEN_CPU_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
60 CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
62 static void put_insn_int_value
63 (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT);
66 static CGEN_INLINE void insert_1
67 (CGEN_CPU_DESC, unsigned long, int, int, int, unsigned char *);
68 static CGEN_INLINE int fill_cache
69 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, bfd_vma);
70 static CGEN_INLINE long extract_1
71 (CGEN_CPU_DESC, CGEN_EXTRACT_INFO *, int, int, int, unsigned char *, bfd_vma);
74 /* Operand insertion. */
78 /* Subroutine of insert_normal. */
80 static CGEN_INLINE void
81 insert_1 (CGEN_CPU_DESC cd,
91 x = cgen_get_insn_value (cd, bufp, word_length);
93 /* Written this way to avoid undefined behaviour. */
94 mask = (((1L << (length - 1)) - 1) << 1) | 1;
96 shift = (start + 1) - length;
98 shift = (word_length - (start + length));
99 x = (x & ~(mask << shift)) | ((value & mask) << shift);
101 cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x);
104 #endif /* ! CGEN_INT_INSN_P */
106 /* Default insertion routine.
108 ATTRS is a mask of the boolean attributes.
109 WORD_OFFSET is the offset in bits from the start of the insn of the value.
110 WORD_LENGTH is the length of the word in bits in which the value resides.
111 START is the starting bit number in the word, architecture origin.
112 LENGTH is the length of VALUE in bits.
113 TOTAL_LENGTH is the total length of the insn in bits.
115 The result is an error message or NULL if success. */
117 /* ??? This duplicates functionality with bfd's howto table and
118 bfd_install_relocation. */
119 /* ??? This doesn't handle bfd_vma's. Create another function when
123 insert_normal (CGEN_CPU_DESC cd,
126 unsigned int word_offset,
129 unsigned int word_length,
130 unsigned int total_length,
131 CGEN_INSN_BYTES_PTR buffer)
133 static char errbuf[100];
134 /* Written this way to avoid undefined behaviour. */
135 unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
137 /* If LENGTH is zero, this operand doesn't contribute to the value. */
141 if (word_length > 8 * sizeof (CGEN_INSN_INT))
144 /* For architectures with insns smaller than the base-insn-bitsize,
145 word_length may be too big. */
146 if (cd->min_insn_bitsize < cd->base_insn_bitsize)
149 && word_length > total_length)
150 word_length = total_length;
153 /* Ensure VALUE will fit. */
154 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT))
156 long minval = - (1L << (length - 1));
157 unsigned long maxval = mask;
159 if ((value > 0 && (unsigned long) value > maxval)
162 /* xgettext:c-format */
164 _("operand out of range (%ld not between %ld and %lu)"),
165 value, minval, maxval);
169 else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED))
171 unsigned long maxval = mask;
172 unsigned long val = (unsigned long) value;
174 /* For hosts with a word size > 32 check to see if value has been sign
175 extended beyond 32 bits. If so then ignore these higher sign bits
176 as the user is attempting to store a 32-bit signed value into an
177 unsigned 32-bit field which is allowed. */
178 if (sizeof (unsigned long) > 4 && ((value >> 32) == -1))
183 /* xgettext:c-format */
185 _("operand out of range (0x%lx not between 0 and 0x%lx)"),
192 if (! cgen_signed_overflow_ok_p (cd))
194 long minval = - (1L << (length - 1));
195 long maxval = (1L << (length - 1)) - 1;
197 if (value < minval || value > maxval)
200 /* xgettext:c-format */
201 (errbuf, _("operand out of range (%ld not between %ld and %ld)"),
202 value, minval, maxval);
211 int shift_within_word, shift_to_word, shift;
213 /* How to shift the value to BIT0 of the word. */
214 shift_to_word = total_length - (word_offset + word_length);
216 /* How to shift the value to the field within the word. */
217 if (CGEN_INSN_LSB0_P)
218 shift_within_word = start + 1 - length;
220 shift_within_word = word_length - start - length;
222 /* The total SHIFT, then mask in the value. */
223 shift = shift_to_word + shift_within_word;
224 *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
227 #else /* ! CGEN_INT_INSN_P */
230 unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
232 insert_1 (cd, value, start, length, word_length, bufp);
235 #endif /* ! CGEN_INT_INSN_P */
240 /* Default insn builder (insert handler).
241 The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
242 that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
243 recorded in host byte order, otherwise BUFFER is an array of bytes
244 and the value is recorded in target byte order).
245 The result is an error message or NULL if success. */
248 insert_insn_normal (CGEN_CPU_DESC cd,
249 const CGEN_INSN * insn,
250 CGEN_FIELDS * fields,
251 CGEN_INSN_BYTES_PTR buffer,
254 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
256 const CGEN_SYNTAX_CHAR_TYPE * syn;
258 CGEN_INIT_INSERT (cd);
259 value = CGEN_INSN_BASE_VALUE (insn);
261 /* If we're recording insns as numbers (rather than a string of bytes),
262 target byte order handling is deferred until later. */
266 put_insn_int_value (cd, buffer, cd->base_insn_bitsize,
267 CGEN_FIELDS_BITSIZE (fields), value);
271 cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize,
272 (unsigned) CGEN_FIELDS_BITSIZE (fields)),
275 #endif /* ! CGEN_INT_INSN_P */
277 /* ??? It would be better to scan the format's fields.
278 Still need to be able to insert a value based on the operand though;
279 e.g. storing a branch displacement that got resolved later.
280 Needs more thought first. */
282 for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn)
286 if (CGEN_SYNTAX_CHAR_P (* syn))
289 errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
299 /* Cover function to store an insn value into an integral insn. Must go here
300 because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */
303 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
304 CGEN_INSN_BYTES_PTR buf,
309 /* For architectures with insns smaller than the base-insn-bitsize,
310 length may be too big. */
311 if (length > insn_length)
315 int shift = insn_length - length;
316 /* Written this way to avoid undefined behaviour. */
317 CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
319 *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift);
324 /* Operand extraction. */
326 #if ! CGEN_INT_INSN_P
328 /* Subroutine of extract_normal.
329 Ensure sufficient bytes are cached in EX_INFO.
330 OFFSET is the offset in bytes from the start of the insn of the value.
331 BYTES is the length of the needed value.
332 Returns 1 for success, 0 for failure. */
334 static CGEN_INLINE int
335 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
336 CGEN_EXTRACT_INFO *ex_info,
341 /* It's doubtful that the middle part has already been fetched so
342 we don't optimize that case. kiss. */
344 disassemble_info *info = (disassemble_info *) ex_info->dis_info;
346 /* First do a quick check. */
347 mask = (1 << bytes) - 1;
348 if (((ex_info->valid >> offset) & mask) == mask)
351 /* Search for the first byte we need to read. */
352 for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
353 if (! (mask & ex_info->valid))
361 status = (*info->read_memory_func)
362 (pc, ex_info->insn_bytes + offset, bytes, info);
366 (*info->memory_error_func) (status, pc, info);
370 ex_info->valid |= ((1 << bytes) - 1) << offset;
376 /* Subroutine of extract_normal. */
378 static CGEN_INLINE long
379 extract_1 (CGEN_CPU_DESC cd,
380 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
385 bfd_vma pc ATTRIBUTE_UNUSED)
390 x = cgen_get_insn_value (cd, bufp, word_length);
392 if (CGEN_INSN_LSB0_P)
393 shift = (start + 1) - length;
395 shift = (word_length - (start + length));
399 #endif /* ! CGEN_INT_INSN_P */
401 /* Default extraction routine.
403 INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
404 or sometimes less for cases like the m32r where the base insn size is 32
405 but some insns are 16 bits.
406 ATTRS is a mask of the boolean attributes. We only need `SIGNED',
407 but for generality we take a bitmask of all of them.
408 WORD_OFFSET is the offset in bits from the start of the insn of the value.
409 WORD_LENGTH is the length of the word in bits in which the value resides.
410 START is the starting bit number in the word, architecture origin.
411 LENGTH is the length of VALUE in bits.
412 TOTAL_LENGTH is the total length of the insn in bits.
414 Returns 1 for success, 0 for failure. */
416 /* ??? The return code isn't properly used. wip. */
418 /* ??? This doesn't handle bfd_vma's. Create another function when
422 extract_normal (CGEN_CPU_DESC cd,
423 #if ! CGEN_INT_INSN_P
424 CGEN_EXTRACT_INFO *ex_info,
426 CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED,
428 CGEN_INSN_INT insn_value,
430 unsigned int word_offset,
433 unsigned int word_length,
434 unsigned int total_length,
435 #if ! CGEN_INT_INSN_P
438 bfd_vma pc ATTRIBUTE_UNUSED,
444 /* If LENGTH is zero, this operand doesn't contribute to the value
445 so give it a standard value of zero. */
452 if (word_length > 8 * sizeof (CGEN_INSN_INT))
455 /* For architectures with insns smaller than the insn-base-bitsize,
456 word_length may be too big. */
457 if (cd->min_insn_bitsize < cd->base_insn_bitsize)
459 if (word_offset + word_length > total_length)
460 word_length = total_length - word_offset;
463 /* Does the value reside in INSN_VALUE, and at the right alignment? */
465 if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length))
467 if (CGEN_INSN_LSB0_P)
468 value = insn_value >> ((word_offset + start + 1) - length);
470 value = insn_value >> (total_length - ( word_offset + start + length));
473 #if ! CGEN_INT_INSN_P
477 unsigned char *bufp = ex_info->insn_bytes + word_offset / 8;
479 if (word_length > 8 * sizeof (CGEN_INSN_INT))
482 if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0)
485 value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc);
488 #endif /* ! CGEN_INT_INSN_P */
490 /* Written this way to avoid undefined behaviour. */
491 mask = (((1L << (length - 1)) - 1) << 1) | 1;
495 if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
496 && (value & (1L << (length - 1))))
504 /* Default insn extractor.
506 INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
507 The extracted fields are stored in FIELDS.
508 EX_INFO is used to handle reading variable length insns.
509 Return the length of the insn in bits, or 0 if no match,
510 or -1 if an error occurs fetching data (memory_error_func will have
514 extract_insn_normal (CGEN_CPU_DESC cd,
515 const CGEN_INSN *insn,
516 CGEN_EXTRACT_INFO *ex_info,
517 CGEN_INSN_INT insn_value,
521 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
522 const CGEN_SYNTAX_CHAR_TYPE *syn;
524 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
526 CGEN_INIT_EXTRACT (cd);
528 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
532 if (CGEN_SYNTAX_CHAR_P (*syn))
535 length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn),
536 ex_info, insn_value, fields, pc);
541 /* We recognized and successfully extracted this insn. */
542 return CGEN_INSN_BITSIZE (insn);
545 /* Machine generated code added here. */
547 const char * xc16x_cgen_insert_operand
548 (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma);
550 /* Main entry point for operand insertion.
552 This function is basically just a big switch statement. Earlier versions
553 used tables to look up the function to use, but
554 - if the table contains both assembler and disassembler functions then
555 the disassembler contains much of the assembler and vice-versa,
556 - there's a lot of inlining possibilities as things grow,
557 - using a switch statement avoids the function call overhead.
559 This function could be moved into `parse_insn_normal', but keeping it
560 separate makes clear the interface between `parse_insn_normal' and each of
561 the handlers. It's also needed by GAS to insert operands that couldn't be
562 resolved during parsing. */
565 xc16x_cgen_insert_operand (CGEN_CPU_DESC cd,
567 CGEN_FIELDS * fields,
568 CGEN_INSN_BYTES_PTR buffer,
569 bfd_vma pc ATTRIBUTE_UNUSED)
571 const char * errmsg = NULL;
572 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
576 case XC16X_OPERAND_REGNAM :
577 errmsg = insert_normal (cd, fields->f_reg8, 0, 0, 15, 8, 32, total_length, buffer);
579 case XC16X_OPERAND_BIT01 :
580 errmsg = insert_normal (cd, fields->f_op_1bit, 0, 0, 8, 1, 32, total_length, buffer);
582 case XC16X_OPERAND_BIT1 :
583 errmsg = insert_normal (cd, fields->f_op_bit1, 0, 0, 11, 1, 32, total_length, buffer);
585 case XC16X_OPERAND_BIT2 :
586 errmsg = insert_normal (cd, fields->f_op_bit2, 0, 0, 11, 2, 32, total_length, buffer);
588 case XC16X_OPERAND_BIT4 :
589 errmsg = insert_normal (cd, fields->f_op_bit4, 0, 0, 11, 4, 32, total_length, buffer);
591 case XC16X_OPERAND_BIT8 :
592 errmsg = insert_normal (cd, fields->f_op_bit8, 0, 0, 31, 8, 32, total_length, buffer);
594 case XC16X_OPERAND_BITONE :
595 errmsg = insert_normal (cd, fields->f_op_onebit, 0, 0, 9, 1, 32, total_length, buffer);
597 case XC16X_OPERAND_CADDR :
598 errmsg = insert_normal (cd, fields->f_offset16, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, buffer);
600 case XC16X_OPERAND_COND :
601 errmsg = insert_normal (cd, fields->f_condcode, 0, 0, 7, 4, 32, total_length, buffer);
603 case XC16X_OPERAND_DATA8 :
604 errmsg = insert_normal (cd, fields->f_data8, 0, 0, 23, 8, 32, total_length, buffer);
606 case XC16X_OPERAND_DATAHI8 :
607 errmsg = insert_normal (cd, fields->f_datahi8, 0, 0, 31, 8, 32, total_length, buffer);
609 case XC16X_OPERAND_DOT :
611 case XC16X_OPERAND_DR :
612 errmsg = insert_normal (cd, fields->f_r1, 0, 0, 15, 4, 32, total_length, buffer);
614 case XC16X_OPERAND_DRB :
615 errmsg = insert_normal (cd, fields->f_r1, 0, 0, 15, 4, 32, total_length, buffer);
617 case XC16X_OPERAND_DRI :
618 errmsg = insert_normal (cd, fields->f_r4, 0, 0, 11, 4, 32, total_length, buffer);
620 case XC16X_OPERAND_EXTCOND :
621 errmsg = insert_normal (cd, fields->f_extccode, 0, 0, 15, 5, 32, total_length, buffer);
623 case XC16X_OPERAND_GENREG :
624 errmsg = insert_normal (cd, fields->f_regb8, 0, 0, 15, 8, 32, total_length, buffer);
626 case XC16X_OPERAND_HASH :
628 case XC16X_OPERAND_ICOND :
629 errmsg = insert_normal (cd, fields->f_icondcode, 0, 0, 15, 4, 32, total_length, buffer);
631 case XC16X_OPERAND_LBIT2 :
632 errmsg = insert_normal (cd, fields->f_op_lbit2, 0, 0, 15, 2, 32, total_length, buffer);
634 case XC16X_OPERAND_LBIT4 :
635 errmsg = insert_normal (cd, fields->f_op_lbit4, 0, 0, 15, 4, 32, total_length, buffer);
637 case XC16X_OPERAND_MASK8 :
638 errmsg = insert_normal (cd, fields->f_mask8, 0, 0, 23, 8, 32, total_length, buffer);
640 case XC16X_OPERAND_MASKLO8 :
641 errmsg = insert_normal (cd, fields->f_datahi8, 0, 0, 31, 8, 32, total_length, buffer);
643 case XC16X_OPERAND_MEMGR8 :
644 errmsg = insert_normal (cd, fields->f_memgr8, 0, 0, 31, 16, 32, total_length, buffer);
646 case XC16X_OPERAND_MEMORY :
647 errmsg = insert_normal (cd, fields->f_memory, 0, 0, 31, 16, 32, total_length, buffer);
649 case XC16X_OPERAND_PAG :
651 case XC16X_OPERAND_PAGENUM :
652 errmsg = insert_normal (cd, fields->f_pagenum, 0, 0, 25, 10, 32, total_length, buffer);
654 case XC16X_OPERAND_POF :
656 case XC16X_OPERAND_QBIT :
657 errmsg = insert_normal (cd, fields->f_qbit, 0, 0, 7, 4, 32, total_length, buffer);
659 case XC16X_OPERAND_QHIBIT :
660 errmsg = insert_normal (cd, fields->f_qhibit, 0, 0, 27, 4, 32, total_length, buffer);
662 case XC16X_OPERAND_QLOBIT :
663 errmsg = insert_normal (cd, fields->f_qlobit, 0, 0, 31, 4, 32, total_length, buffer);
665 case XC16X_OPERAND_REG8 :
666 errmsg = insert_normal (cd, fields->f_reg8, 0, 0, 15, 8, 32, total_length, buffer);
668 case XC16X_OPERAND_REGB8 :
669 errmsg = insert_normal (cd, fields->f_regb8, 0, 0, 15, 8, 32, total_length, buffer);
671 case XC16X_OPERAND_REGBMEM8 :
672 errmsg = insert_normal (cd, fields->f_regmem8, 0, 0, 15, 8, 32, total_length, buffer);
674 case XC16X_OPERAND_REGHI8 :
675 errmsg = insert_normal (cd, fields->f_reghi8, 0, 0, 23, 8, 32, total_length, buffer);
677 case XC16X_OPERAND_REGMEM8 :
678 errmsg = insert_normal (cd, fields->f_regmem8, 0, 0, 15, 8, 32, total_length, buffer);
680 case XC16X_OPERAND_REGOFF8 :
681 errmsg = insert_normal (cd, fields->f_regoff8, 0, 0, 15, 8, 32, total_length, buffer);
683 case XC16X_OPERAND_REL :
684 errmsg = insert_normal (cd, fields->f_rel8, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 8, 32, total_length, buffer);
686 case XC16X_OPERAND_RELHI :
687 errmsg = insert_normal (cd, fields->f_relhi8, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 23, 8, 32, total_length, buffer);
689 case XC16X_OPERAND_SEG :
690 errmsg = insert_normal (cd, fields->f_seg8, 0, 0, 15, 8, 32, total_length, buffer);
692 case XC16X_OPERAND_SEGHI8 :
693 errmsg = insert_normal (cd, fields->f_segnum8, 0, 0, 23, 8, 32, total_length, buffer);
695 case XC16X_OPERAND_SEGM :
697 case XC16X_OPERAND_SOF :
699 case XC16X_OPERAND_SR :
700 errmsg = insert_normal (cd, fields->f_r2, 0, 0, 11, 4, 32, total_length, buffer);
702 case XC16X_OPERAND_SR2 :
703 errmsg = insert_normal (cd, fields->f_r0, 0, 0, 9, 2, 32, total_length, buffer);
705 case XC16X_OPERAND_SRB :
706 errmsg = insert_normal (cd, fields->f_r2, 0, 0, 11, 4, 32, total_length, buffer);
708 case XC16X_OPERAND_SRC1 :
709 errmsg = insert_normal (cd, fields->f_r1, 0, 0, 15, 4, 32, total_length, buffer);
711 case XC16X_OPERAND_SRC2 :
712 errmsg = insert_normal (cd, fields->f_r2, 0, 0, 11, 4, 32, total_length, buffer);
714 case XC16X_OPERAND_SRDIV :
715 errmsg = insert_normal (cd, fields->f_reg8, 0, 0, 15, 8, 32, total_length, buffer);
717 case XC16X_OPERAND_U4 :
718 errmsg = insert_normal (cd, fields->f_uimm4, 0, 0, 15, 4, 32, total_length, buffer);
720 case XC16X_OPERAND_UIMM16 :
721 errmsg = insert_normal (cd, fields->f_uimm16, 0, 0, 31, 16, 32, total_length, buffer);
723 case XC16X_OPERAND_UIMM2 :
724 errmsg = insert_normal (cd, fields->f_uimm2, 0, 0, 13, 2, 32, total_length, buffer);
726 case XC16X_OPERAND_UIMM3 :
727 errmsg = insert_normal (cd, fields->f_uimm3, 0, 0, 10, 3, 32, total_length, buffer);
729 case XC16X_OPERAND_UIMM4 :
730 errmsg = insert_normal (cd, fields->f_uimm4, 0, 0, 15, 4, 32, total_length, buffer);
732 case XC16X_OPERAND_UIMM7 :
733 errmsg = insert_normal (cd, fields->f_uimm7, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 7, 32, total_length, buffer);
735 case XC16X_OPERAND_UIMM8 :
736 errmsg = insert_normal (cd, fields->f_uimm8, 0, 0, 23, 8, 32, total_length, buffer);
738 case XC16X_OPERAND_UPAG16 :
739 errmsg = insert_normal (cd, fields->f_uimm16, 0, 0, 31, 16, 32, total_length, buffer);
741 case XC16X_OPERAND_UPOF16 :
742 errmsg = insert_normal (cd, fields->f_memory, 0, 0, 31, 16, 32, total_length, buffer);
744 case XC16X_OPERAND_USEG16 :
745 errmsg = insert_normal (cd, fields->f_offset16, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, buffer);
747 case XC16X_OPERAND_USEG8 :
748 errmsg = insert_normal (cd, fields->f_seg8, 0, 0, 15, 8, 32, total_length, buffer);
750 case XC16X_OPERAND_USOF16 :
751 errmsg = insert_normal (cd, fields->f_offset16, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, buffer);
755 /* xgettext:c-format */
756 fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
764 int xc16x_cgen_extract_operand
765 (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma);
767 /* Main entry point for operand extraction.
768 The result is <= 0 for error, >0 for success.
769 ??? Actual values aren't well defined right now.
771 This function is basically just a big switch statement. Earlier versions
772 used tables to look up the function to use, but
773 - if the table contains both assembler and disassembler functions then
774 the disassembler contains much of the assembler and vice-versa,
775 - there's a lot of inlining possibilities as things grow,
776 - using a switch statement avoids the function call overhead.
778 This function could be moved into `print_insn_normal', but keeping it
779 separate makes clear the interface between `print_insn_normal' and each of
783 xc16x_cgen_extract_operand (CGEN_CPU_DESC cd,
785 CGEN_EXTRACT_INFO *ex_info,
786 CGEN_INSN_INT insn_value,
787 CGEN_FIELDS * fields,
790 /* Assume success (for those operands that are nops). */
792 unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
796 case XC16X_OPERAND_REGNAM :
797 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_reg8);
799 case XC16X_OPERAND_BIT01 :
800 length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 1, 32, total_length, pc, & fields->f_op_1bit);
802 case XC16X_OPERAND_BIT1 :
803 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_op_bit1);
805 case XC16X_OPERAND_BIT2 :
806 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 2, 32, total_length, pc, & fields->f_op_bit2);
808 case XC16X_OPERAND_BIT4 :
809 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_op_bit4);
811 case XC16X_OPERAND_BIT8 :
812 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 8, 32, total_length, pc, & fields->f_op_bit8);
814 case XC16X_OPERAND_BITONE :
815 length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 1, 32, total_length, pc, & fields->f_op_onebit);
817 case XC16X_OPERAND_CADDR :
818 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, pc, & fields->f_offset16);
820 case XC16X_OPERAND_COND :
821 length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 4, 32, total_length, pc, & fields->f_condcode);
823 case XC16X_OPERAND_DATA8 :
824 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_data8);
826 case XC16X_OPERAND_DATAHI8 :
827 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 8, 32, total_length, pc, & fields->f_datahi8);
829 case XC16X_OPERAND_DOT :
831 case XC16X_OPERAND_DR :
832 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_r1);
834 case XC16X_OPERAND_DRB :
835 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_r1);
837 case XC16X_OPERAND_DRI :
838 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r4);
840 case XC16X_OPERAND_EXTCOND :
841 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_extccode);
843 case XC16X_OPERAND_GENREG :
844 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regb8);
846 case XC16X_OPERAND_HASH :
848 case XC16X_OPERAND_ICOND :
849 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_icondcode);
851 case XC16X_OPERAND_LBIT2 :
852 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 2, 32, total_length, pc, & fields->f_op_lbit2);
854 case XC16X_OPERAND_LBIT4 :
855 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_op_lbit4);
857 case XC16X_OPERAND_MASK8 :
858 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_mask8);
860 case XC16X_OPERAND_MASKLO8 :
861 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 8, 32, total_length, pc, & fields->f_datahi8);
863 case XC16X_OPERAND_MEMGR8 :
864 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_memgr8);
866 case XC16X_OPERAND_MEMORY :
867 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_memory);
869 case XC16X_OPERAND_PAG :
871 case XC16X_OPERAND_PAGENUM :
872 length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 10, 32, total_length, pc, & fields->f_pagenum);
874 case XC16X_OPERAND_POF :
876 case XC16X_OPERAND_QBIT :
877 length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 4, 32, total_length, pc, & fields->f_qbit);
879 case XC16X_OPERAND_QHIBIT :
880 length = extract_normal (cd, ex_info, insn_value, 0, 0, 27, 4, 32, total_length, pc, & fields->f_qhibit);
882 case XC16X_OPERAND_QLOBIT :
883 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 4, 32, total_length, pc, & fields->f_qlobit);
885 case XC16X_OPERAND_REG8 :
886 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_reg8);
888 case XC16X_OPERAND_REGB8 :
889 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regb8);
891 case XC16X_OPERAND_REGBMEM8 :
892 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regmem8);
894 case XC16X_OPERAND_REGHI8 :
895 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_reghi8);
897 case XC16X_OPERAND_REGMEM8 :
898 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regmem8);
900 case XC16X_OPERAND_REGOFF8 :
901 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_regoff8);
903 case XC16X_OPERAND_REL :
904 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 8, 32, total_length, pc, & fields->f_rel8);
906 case XC16X_OPERAND_RELHI :
907 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 23, 8, 32, total_length, pc, & fields->f_relhi8);
909 case XC16X_OPERAND_SEG :
910 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_seg8);
912 case XC16X_OPERAND_SEGHI8 :
913 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_segnum8);
915 case XC16X_OPERAND_SEGM :
917 case XC16X_OPERAND_SOF :
919 case XC16X_OPERAND_SR :
920 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r2);
922 case XC16X_OPERAND_SR2 :
923 length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 2, 32, total_length, pc, & fields->f_r0);
925 case XC16X_OPERAND_SRB :
926 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r2);
928 case XC16X_OPERAND_SRC1 :
929 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_r1);
931 case XC16X_OPERAND_SRC2 :
932 length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 4, 32, total_length, pc, & fields->f_r2);
934 case XC16X_OPERAND_SRDIV :
935 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_reg8);
937 case XC16X_OPERAND_U4 :
938 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_uimm4);
940 case XC16X_OPERAND_UIMM16 :
941 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_uimm16);
943 case XC16X_OPERAND_UIMM2 :
944 length = extract_normal (cd, ex_info, insn_value, 0, 0, 13, 2, 32, total_length, pc, & fields->f_uimm2);
946 case XC16X_OPERAND_UIMM3 :
947 length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 3, 32, total_length, pc, & fields->f_uimm3);
949 case XC16X_OPERAND_UIMM4 :
950 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 4, 32, total_length, pc, & fields->f_uimm4);
952 case XC16X_OPERAND_UIMM7 :
953 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 7, 32, total_length, pc, & fields->f_uimm7);
955 case XC16X_OPERAND_UIMM8 :
956 length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 8, 32, total_length, pc, & fields->f_uimm8);
958 case XC16X_OPERAND_UPAG16 :
959 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_uimm16);
961 case XC16X_OPERAND_UPOF16 :
962 length = extract_normal (cd, ex_info, insn_value, 0, 0, 31, 16, 32, total_length, pc, & fields->f_memory);
964 case XC16X_OPERAND_USEG16 :
965 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, pc, & fields->f_offset16);
967 case XC16X_OPERAND_USEG8 :
968 length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 8, 32, total_length, pc, & fields->f_seg8);
970 case XC16X_OPERAND_USOF16 :
971 length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_RELOC)|(1<<CGEN_IFLD_ABS_ADDR), 0, 31, 16, 32, total_length, pc, & fields->f_offset16);
975 /* xgettext:c-format */
976 fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
984 cgen_insert_fn * const xc16x_cgen_insert_handlers[] =
989 cgen_extract_fn * const xc16x_cgen_extract_handlers[] =
994 int xc16x_cgen_get_int_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
995 bfd_vma xc16x_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *);
997 /* Getting values from cgen_fields is handled by a collection of functions.
998 They are distinguished by the type of the VALUE argument they return.
999 TODO: floating point, inlining support, remove cases where result type
1003 xc16x_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1005 const CGEN_FIELDS * fields)
1011 case XC16X_OPERAND_REGNAM :
1012 value = fields->f_reg8;
1014 case XC16X_OPERAND_BIT01 :
1015 value = fields->f_op_1bit;
1017 case XC16X_OPERAND_BIT1 :
1018 value = fields->f_op_bit1;
1020 case XC16X_OPERAND_BIT2 :
1021 value = fields->f_op_bit2;
1023 case XC16X_OPERAND_BIT4 :
1024 value = fields->f_op_bit4;
1026 case XC16X_OPERAND_BIT8 :
1027 value = fields->f_op_bit8;
1029 case XC16X_OPERAND_BITONE :
1030 value = fields->f_op_onebit;
1032 case XC16X_OPERAND_CADDR :
1033 value = fields->f_offset16;
1035 case XC16X_OPERAND_COND :
1036 value = fields->f_condcode;
1038 case XC16X_OPERAND_DATA8 :
1039 value = fields->f_data8;
1041 case XC16X_OPERAND_DATAHI8 :
1042 value = fields->f_datahi8;
1044 case XC16X_OPERAND_DOT :
1047 case XC16X_OPERAND_DR :
1048 value = fields->f_r1;
1050 case XC16X_OPERAND_DRB :
1051 value = fields->f_r1;
1053 case XC16X_OPERAND_DRI :
1054 value = fields->f_r4;
1056 case XC16X_OPERAND_EXTCOND :
1057 value = fields->f_extccode;
1059 case XC16X_OPERAND_GENREG :
1060 value = fields->f_regb8;
1062 case XC16X_OPERAND_HASH :
1065 case XC16X_OPERAND_ICOND :
1066 value = fields->f_icondcode;
1068 case XC16X_OPERAND_LBIT2 :
1069 value = fields->f_op_lbit2;
1071 case XC16X_OPERAND_LBIT4 :
1072 value = fields->f_op_lbit4;
1074 case XC16X_OPERAND_MASK8 :
1075 value = fields->f_mask8;
1077 case XC16X_OPERAND_MASKLO8 :
1078 value = fields->f_datahi8;
1080 case XC16X_OPERAND_MEMGR8 :
1081 value = fields->f_memgr8;
1083 case XC16X_OPERAND_MEMORY :
1084 value = fields->f_memory;
1086 case XC16X_OPERAND_PAG :
1089 case XC16X_OPERAND_PAGENUM :
1090 value = fields->f_pagenum;
1092 case XC16X_OPERAND_POF :
1095 case XC16X_OPERAND_QBIT :
1096 value = fields->f_qbit;
1098 case XC16X_OPERAND_QHIBIT :
1099 value = fields->f_qhibit;
1101 case XC16X_OPERAND_QLOBIT :
1102 value = fields->f_qlobit;
1104 case XC16X_OPERAND_REG8 :
1105 value = fields->f_reg8;
1107 case XC16X_OPERAND_REGB8 :
1108 value = fields->f_regb8;
1110 case XC16X_OPERAND_REGBMEM8 :
1111 value = fields->f_regmem8;
1113 case XC16X_OPERAND_REGHI8 :
1114 value = fields->f_reghi8;
1116 case XC16X_OPERAND_REGMEM8 :
1117 value = fields->f_regmem8;
1119 case XC16X_OPERAND_REGOFF8 :
1120 value = fields->f_regoff8;
1122 case XC16X_OPERAND_REL :
1123 value = fields->f_rel8;
1125 case XC16X_OPERAND_RELHI :
1126 value = fields->f_relhi8;
1128 case XC16X_OPERAND_SEG :
1129 value = fields->f_seg8;
1131 case XC16X_OPERAND_SEGHI8 :
1132 value = fields->f_segnum8;
1134 case XC16X_OPERAND_SEGM :
1137 case XC16X_OPERAND_SOF :
1140 case XC16X_OPERAND_SR :
1141 value = fields->f_r2;
1143 case XC16X_OPERAND_SR2 :
1144 value = fields->f_r0;
1146 case XC16X_OPERAND_SRB :
1147 value = fields->f_r2;
1149 case XC16X_OPERAND_SRC1 :
1150 value = fields->f_r1;
1152 case XC16X_OPERAND_SRC2 :
1153 value = fields->f_r2;
1155 case XC16X_OPERAND_SRDIV :
1156 value = fields->f_reg8;
1158 case XC16X_OPERAND_U4 :
1159 value = fields->f_uimm4;
1161 case XC16X_OPERAND_UIMM16 :
1162 value = fields->f_uimm16;
1164 case XC16X_OPERAND_UIMM2 :
1165 value = fields->f_uimm2;
1167 case XC16X_OPERAND_UIMM3 :
1168 value = fields->f_uimm3;
1170 case XC16X_OPERAND_UIMM4 :
1171 value = fields->f_uimm4;
1173 case XC16X_OPERAND_UIMM7 :
1174 value = fields->f_uimm7;
1176 case XC16X_OPERAND_UIMM8 :
1177 value = fields->f_uimm8;
1179 case XC16X_OPERAND_UPAG16 :
1180 value = fields->f_uimm16;
1182 case XC16X_OPERAND_UPOF16 :
1183 value = fields->f_memory;
1185 case XC16X_OPERAND_USEG16 :
1186 value = fields->f_offset16;
1188 case XC16X_OPERAND_USEG8 :
1189 value = fields->f_seg8;
1191 case XC16X_OPERAND_USOF16 :
1192 value = fields->f_offset16;
1196 /* xgettext:c-format */
1197 fprintf (stderr, _("Unrecognized field %d while getting int operand.\n"),
1206 xc16x_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1208 const CGEN_FIELDS * fields)
1214 case XC16X_OPERAND_REGNAM :
1215 value = fields->f_reg8;
1217 case XC16X_OPERAND_BIT01 :
1218 value = fields->f_op_1bit;
1220 case XC16X_OPERAND_BIT1 :
1221 value = fields->f_op_bit1;
1223 case XC16X_OPERAND_BIT2 :
1224 value = fields->f_op_bit2;
1226 case XC16X_OPERAND_BIT4 :
1227 value = fields->f_op_bit4;
1229 case XC16X_OPERAND_BIT8 :
1230 value = fields->f_op_bit8;
1232 case XC16X_OPERAND_BITONE :
1233 value = fields->f_op_onebit;
1235 case XC16X_OPERAND_CADDR :
1236 value = fields->f_offset16;
1238 case XC16X_OPERAND_COND :
1239 value = fields->f_condcode;
1241 case XC16X_OPERAND_DATA8 :
1242 value = fields->f_data8;
1244 case XC16X_OPERAND_DATAHI8 :
1245 value = fields->f_datahi8;
1247 case XC16X_OPERAND_DOT :
1250 case XC16X_OPERAND_DR :
1251 value = fields->f_r1;
1253 case XC16X_OPERAND_DRB :
1254 value = fields->f_r1;
1256 case XC16X_OPERAND_DRI :
1257 value = fields->f_r4;
1259 case XC16X_OPERAND_EXTCOND :
1260 value = fields->f_extccode;
1262 case XC16X_OPERAND_GENREG :
1263 value = fields->f_regb8;
1265 case XC16X_OPERAND_HASH :
1268 case XC16X_OPERAND_ICOND :
1269 value = fields->f_icondcode;
1271 case XC16X_OPERAND_LBIT2 :
1272 value = fields->f_op_lbit2;
1274 case XC16X_OPERAND_LBIT4 :
1275 value = fields->f_op_lbit4;
1277 case XC16X_OPERAND_MASK8 :
1278 value = fields->f_mask8;
1280 case XC16X_OPERAND_MASKLO8 :
1281 value = fields->f_datahi8;
1283 case XC16X_OPERAND_MEMGR8 :
1284 value = fields->f_memgr8;
1286 case XC16X_OPERAND_MEMORY :
1287 value = fields->f_memory;
1289 case XC16X_OPERAND_PAG :
1292 case XC16X_OPERAND_PAGENUM :
1293 value = fields->f_pagenum;
1295 case XC16X_OPERAND_POF :
1298 case XC16X_OPERAND_QBIT :
1299 value = fields->f_qbit;
1301 case XC16X_OPERAND_QHIBIT :
1302 value = fields->f_qhibit;
1304 case XC16X_OPERAND_QLOBIT :
1305 value = fields->f_qlobit;
1307 case XC16X_OPERAND_REG8 :
1308 value = fields->f_reg8;
1310 case XC16X_OPERAND_REGB8 :
1311 value = fields->f_regb8;
1313 case XC16X_OPERAND_REGBMEM8 :
1314 value = fields->f_regmem8;
1316 case XC16X_OPERAND_REGHI8 :
1317 value = fields->f_reghi8;
1319 case XC16X_OPERAND_REGMEM8 :
1320 value = fields->f_regmem8;
1322 case XC16X_OPERAND_REGOFF8 :
1323 value = fields->f_regoff8;
1325 case XC16X_OPERAND_REL :
1326 value = fields->f_rel8;
1328 case XC16X_OPERAND_RELHI :
1329 value = fields->f_relhi8;
1331 case XC16X_OPERAND_SEG :
1332 value = fields->f_seg8;
1334 case XC16X_OPERAND_SEGHI8 :
1335 value = fields->f_segnum8;
1337 case XC16X_OPERAND_SEGM :
1340 case XC16X_OPERAND_SOF :
1343 case XC16X_OPERAND_SR :
1344 value = fields->f_r2;
1346 case XC16X_OPERAND_SR2 :
1347 value = fields->f_r0;
1349 case XC16X_OPERAND_SRB :
1350 value = fields->f_r2;
1352 case XC16X_OPERAND_SRC1 :
1353 value = fields->f_r1;
1355 case XC16X_OPERAND_SRC2 :
1356 value = fields->f_r2;
1358 case XC16X_OPERAND_SRDIV :
1359 value = fields->f_reg8;
1361 case XC16X_OPERAND_U4 :
1362 value = fields->f_uimm4;
1364 case XC16X_OPERAND_UIMM16 :
1365 value = fields->f_uimm16;
1367 case XC16X_OPERAND_UIMM2 :
1368 value = fields->f_uimm2;
1370 case XC16X_OPERAND_UIMM3 :
1371 value = fields->f_uimm3;
1373 case XC16X_OPERAND_UIMM4 :
1374 value = fields->f_uimm4;
1376 case XC16X_OPERAND_UIMM7 :
1377 value = fields->f_uimm7;
1379 case XC16X_OPERAND_UIMM8 :
1380 value = fields->f_uimm8;
1382 case XC16X_OPERAND_UPAG16 :
1383 value = fields->f_uimm16;
1385 case XC16X_OPERAND_UPOF16 :
1386 value = fields->f_memory;
1388 case XC16X_OPERAND_USEG16 :
1389 value = fields->f_offset16;
1391 case XC16X_OPERAND_USEG8 :
1392 value = fields->f_seg8;
1394 case XC16X_OPERAND_USOF16 :
1395 value = fields->f_offset16;
1399 /* xgettext:c-format */
1400 fprintf (stderr, _("Unrecognized field %d while getting vma operand.\n"),
1408 void xc16x_cgen_set_int_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, int);
1409 void xc16x_cgen_set_vma_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma);
1411 /* Stuffing values in cgen_fields is handled by a collection of functions.
1412 They are distinguished by the type of the VALUE argument they accept.
1413 TODO: floating point, inlining support, remove cases where argument type
1417 xc16x_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1419 CGEN_FIELDS * fields,
1424 case XC16X_OPERAND_REGNAM :
1425 fields->f_reg8 = value;
1427 case XC16X_OPERAND_BIT01 :
1428 fields->f_op_1bit = value;
1430 case XC16X_OPERAND_BIT1 :
1431 fields->f_op_bit1 = value;
1433 case XC16X_OPERAND_BIT2 :
1434 fields->f_op_bit2 = value;
1436 case XC16X_OPERAND_BIT4 :
1437 fields->f_op_bit4 = value;
1439 case XC16X_OPERAND_BIT8 :
1440 fields->f_op_bit8 = value;
1442 case XC16X_OPERAND_BITONE :
1443 fields->f_op_onebit = value;
1445 case XC16X_OPERAND_CADDR :
1446 fields->f_offset16 = value;
1448 case XC16X_OPERAND_COND :
1449 fields->f_condcode = value;
1451 case XC16X_OPERAND_DATA8 :
1452 fields->f_data8 = value;
1454 case XC16X_OPERAND_DATAHI8 :
1455 fields->f_datahi8 = value;
1457 case XC16X_OPERAND_DOT :
1459 case XC16X_OPERAND_DR :
1460 fields->f_r1 = value;
1462 case XC16X_OPERAND_DRB :
1463 fields->f_r1 = value;
1465 case XC16X_OPERAND_DRI :
1466 fields->f_r4 = value;
1468 case XC16X_OPERAND_EXTCOND :
1469 fields->f_extccode = value;
1471 case XC16X_OPERAND_GENREG :
1472 fields->f_regb8 = value;
1474 case XC16X_OPERAND_HASH :
1476 case XC16X_OPERAND_ICOND :
1477 fields->f_icondcode = value;
1479 case XC16X_OPERAND_LBIT2 :
1480 fields->f_op_lbit2 = value;
1482 case XC16X_OPERAND_LBIT4 :
1483 fields->f_op_lbit4 = value;
1485 case XC16X_OPERAND_MASK8 :
1486 fields->f_mask8 = value;
1488 case XC16X_OPERAND_MASKLO8 :
1489 fields->f_datahi8 = value;
1491 case XC16X_OPERAND_MEMGR8 :
1492 fields->f_memgr8 = value;
1494 case XC16X_OPERAND_MEMORY :
1495 fields->f_memory = value;
1497 case XC16X_OPERAND_PAG :
1499 case XC16X_OPERAND_PAGENUM :
1500 fields->f_pagenum = value;
1502 case XC16X_OPERAND_POF :
1504 case XC16X_OPERAND_QBIT :
1505 fields->f_qbit = value;
1507 case XC16X_OPERAND_QHIBIT :
1508 fields->f_qhibit = value;
1510 case XC16X_OPERAND_QLOBIT :
1511 fields->f_qlobit = value;
1513 case XC16X_OPERAND_REG8 :
1514 fields->f_reg8 = value;
1516 case XC16X_OPERAND_REGB8 :
1517 fields->f_regb8 = value;
1519 case XC16X_OPERAND_REGBMEM8 :
1520 fields->f_regmem8 = value;
1522 case XC16X_OPERAND_REGHI8 :
1523 fields->f_reghi8 = value;
1525 case XC16X_OPERAND_REGMEM8 :
1526 fields->f_regmem8 = value;
1528 case XC16X_OPERAND_REGOFF8 :
1529 fields->f_regoff8 = value;
1531 case XC16X_OPERAND_REL :
1532 fields->f_rel8 = value;
1534 case XC16X_OPERAND_RELHI :
1535 fields->f_relhi8 = value;
1537 case XC16X_OPERAND_SEG :
1538 fields->f_seg8 = value;
1540 case XC16X_OPERAND_SEGHI8 :
1541 fields->f_segnum8 = value;
1543 case XC16X_OPERAND_SEGM :
1545 case XC16X_OPERAND_SOF :
1547 case XC16X_OPERAND_SR :
1548 fields->f_r2 = value;
1550 case XC16X_OPERAND_SR2 :
1551 fields->f_r0 = value;
1553 case XC16X_OPERAND_SRB :
1554 fields->f_r2 = value;
1556 case XC16X_OPERAND_SRC1 :
1557 fields->f_r1 = value;
1559 case XC16X_OPERAND_SRC2 :
1560 fields->f_r2 = value;
1562 case XC16X_OPERAND_SRDIV :
1563 fields->f_reg8 = value;
1565 case XC16X_OPERAND_U4 :
1566 fields->f_uimm4 = value;
1568 case XC16X_OPERAND_UIMM16 :
1569 fields->f_uimm16 = value;
1571 case XC16X_OPERAND_UIMM2 :
1572 fields->f_uimm2 = value;
1574 case XC16X_OPERAND_UIMM3 :
1575 fields->f_uimm3 = value;
1577 case XC16X_OPERAND_UIMM4 :
1578 fields->f_uimm4 = value;
1580 case XC16X_OPERAND_UIMM7 :
1581 fields->f_uimm7 = value;
1583 case XC16X_OPERAND_UIMM8 :
1584 fields->f_uimm8 = value;
1586 case XC16X_OPERAND_UPAG16 :
1587 fields->f_uimm16 = value;
1589 case XC16X_OPERAND_UPOF16 :
1590 fields->f_memory = value;
1592 case XC16X_OPERAND_USEG16 :
1593 fields->f_offset16 = value;
1595 case XC16X_OPERAND_USEG8 :
1596 fields->f_seg8 = value;
1598 case XC16X_OPERAND_USOF16 :
1599 fields->f_offset16 = value;
1603 /* xgettext:c-format */
1604 fprintf (stderr, _("Unrecognized field %d while setting int operand.\n"),
1611 xc16x_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
1613 CGEN_FIELDS * fields,
1618 case XC16X_OPERAND_REGNAM :
1619 fields->f_reg8 = value;
1621 case XC16X_OPERAND_BIT01 :
1622 fields->f_op_1bit = value;
1624 case XC16X_OPERAND_BIT1 :
1625 fields->f_op_bit1 = value;
1627 case XC16X_OPERAND_BIT2 :
1628 fields->f_op_bit2 = value;
1630 case XC16X_OPERAND_BIT4 :
1631 fields->f_op_bit4 = value;
1633 case XC16X_OPERAND_BIT8 :
1634 fields->f_op_bit8 = value;
1636 case XC16X_OPERAND_BITONE :
1637 fields->f_op_onebit = value;
1639 case XC16X_OPERAND_CADDR :
1640 fields->f_offset16 = value;
1642 case XC16X_OPERAND_COND :
1643 fields->f_condcode = value;
1645 case XC16X_OPERAND_DATA8 :
1646 fields->f_data8 = value;
1648 case XC16X_OPERAND_DATAHI8 :
1649 fields->f_datahi8 = value;
1651 case XC16X_OPERAND_DOT :
1653 case XC16X_OPERAND_DR :
1654 fields->f_r1 = value;
1656 case XC16X_OPERAND_DRB :
1657 fields->f_r1 = value;
1659 case XC16X_OPERAND_DRI :
1660 fields->f_r4 = value;
1662 case XC16X_OPERAND_EXTCOND :
1663 fields->f_extccode = value;
1665 case XC16X_OPERAND_GENREG :
1666 fields->f_regb8 = value;
1668 case XC16X_OPERAND_HASH :
1670 case XC16X_OPERAND_ICOND :
1671 fields->f_icondcode = value;
1673 case XC16X_OPERAND_LBIT2 :
1674 fields->f_op_lbit2 = value;
1676 case XC16X_OPERAND_LBIT4 :
1677 fields->f_op_lbit4 = value;
1679 case XC16X_OPERAND_MASK8 :
1680 fields->f_mask8 = value;
1682 case XC16X_OPERAND_MASKLO8 :
1683 fields->f_datahi8 = value;
1685 case XC16X_OPERAND_MEMGR8 :
1686 fields->f_memgr8 = value;
1688 case XC16X_OPERAND_MEMORY :
1689 fields->f_memory = value;
1691 case XC16X_OPERAND_PAG :
1693 case XC16X_OPERAND_PAGENUM :
1694 fields->f_pagenum = value;
1696 case XC16X_OPERAND_POF :
1698 case XC16X_OPERAND_QBIT :
1699 fields->f_qbit = value;
1701 case XC16X_OPERAND_QHIBIT :
1702 fields->f_qhibit = value;
1704 case XC16X_OPERAND_QLOBIT :
1705 fields->f_qlobit = value;
1707 case XC16X_OPERAND_REG8 :
1708 fields->f_reg8 = value;
1710 case XC16X_OPERAND_REGB8 :
1711 fields->f_regb8 = value;
1713 case XC16X_OPERAND_REGBMEM8 :
1714 fields->f_regmem8 = value;
1716 case XC16X_OPERAND_REGHI8 :
1717 fields->f_reghi8 = value;
1719 case XC16X_OPERAND_REGMEM8 :
1720 fields->f_regmem8 = value;
1722 case XC16X_OPERAND_REGOFF8 :
1723 fields->f_regoff8 = value;
1725 case XC16X_OPERAND_REL :
1726 fields->f_rel8 = value;
1728 case XC16X_OPERAND_RELHI :
1729 fields->f_relhi8 = value;
1731 case XC16X_OPERAND_SEG :
1732 fields->f_seg8 = value;
1734 case XC16X_OPERAND_SEGHI8 :
1735 fields->f_segnum8 = value;
1737 case XC16X_OPERAND_SEGM :
1739 case XC16X_OPERAND_SOF :
1741 case XC16X_OPERAND_SR :
1742 fields->f_r2 = value;
1744 case XC16X_OPERAND_SR2 :
1745 fields->f_r0 = value;
1747 case XC16X_OPERAND_SRB :
1748 fields->f_r2 = value;
1750 case XC16X_OPERAND_SRC1 :
1751 fields->f_r1 = value;
1753 case XC16X_OPERAND_SRC2 :
1754 fields->f_r2 = value;
1756 case XC16X_OPERAND_SRDIV :
1757 fields->f_reg8 = value;
1759 case XC16X_OPERAND_U4 :
1760 fields->f_uimm4 = value;
1762 case XC16X_OPERAND_UIMM16 :
1763 fields->f_uimm16 = value;
1765 case XC16X_OPERAND_UIMM2 :
1766 fields->f_uimm2 = value;
1768 case XC16X_OPERAND_UIMM3 :
1769 fields->f_uimm3 = value;
1771 case XC16X_OPERAND_UIMM4 :
1772 fields->f_uimm4 = value;
1774 case XC16X_OPERAND_UIMM7 :
1775 fields->f_uimm7 = value;
1777 case XC16X_OPERAND_UIMM8 :
1778 fields->f_uimm8 = value;
1780 case XC16X_OPERAND_UPAG16 :
1781 fields->f_uimm16 = value;
1783 case XC16X_OPERAND_UPOF16 :
1784 fields->f_memory = value;
1786 case XC16X_OPERAND_USEG16 :
1787 fields->f_offset16 = value;
1789 case XC16X_OPERAND_USEG8 :
1790 fields->f_seg8 = value;
1792 case XC16X_OPERAND_USOF16 :
1793 fields->f_offset16 = value;
1797 /* xgettext:c-format */
1798 fprintf (stderr, _("Unrecognized field %d while setting vma operand.\n"),
1804 /* Function to call before using the instruction builder tables. */
1807 xc16x_cgen_init_ibld_table (CGEN_CPU_DESC cd)
1809 cd->insert_handlers = & xc16x_cgen_insert_handlers[0];
1810 cd->extract_handlers = & xc16x_cgen_extract_handlers[0];
1812 cd->insert_operand = xc16x_cgen_insert_operand;
1813 cd->extract_operand = xc16x_cgen_extract_operand;
1815 cd->get_int_operand = xc16x_cgen_get_int_operand;
1816 cd->set_int_operand = xc16x_cgen_set_int_operand;
1817 cd->get_vma_operand = xc16x_cgen_get_vma_operand;
1818 cd->set_vma_operand = xc16x_cgen_set_vma_operand;