1 /* Instruction building/extraction support for xc16x. -*- 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-2014 Free Software Foundation, Inc.
8 This file is part of libopcodes.
10 This library 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 3, or (at your option)
15 It is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 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 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
33 #include "xc16x-desc.h"
34 #include "xc16x-opc.h"
35 #include "cgen/basic-modes.h"
37 #include "safe-ctype.h"
40 #define min(a,b) ((a) < (b) ? (a) : (b))
42 #define max(a,b) ((a) > (b) ? (a) : (b))
44 /* Used by the ifield rtx function. */
45 #define FLD(f) (fields->f)
47 static const char * insert_normal
48 (CGEN_CPU_DESC
, long, unsigned int, unsigned int, unsigned int,
49 unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR
);
50 static const char * insert_insn_normal
51 (CGEN_CPU_DESC
, const CGEN_INSN
*,
52 CGEN_FIELDS
*, CGEN_INSN_BYTES_PTR
, bfd_vma
);
53 static int extract_normal
54 (CGEN_CPU_DESC
, CGEN_EXTRACT_INFO
*, CGEN_INSN_INT
,
55 unsigned int, unsigned int, unsigned int, unsigned int,
56 unsigned int, unsigned int, bfd_vma
, long *);
57 static int extract_insn_normal
58 (CGEN_CPU_DESC
, const CGEN_INSN
*, CGEN_EXTRACT_INFO
*,
59 CGEN_INSN_INT
, CGEN_FIELDS
*, bfd_vma
);
61 static void put_insn_int_value
62 (CGEN_CPU_DESC
, CGEN_INSN_BYTES_PTR
, int, int, CGEN_INSN_INT
);
65 static CGEN_INLINE
void insert_1
66 (CGEN_CPU_DESC
, unsigned long, int, int, int, unsigned char *);
67 static CGEN_INLINE
int fill_cache
68 (CGEN_CPU_DESC
, CGEN_EXTRACT_INFO
*, int, int, bfd_vma
);
69 static CGEN_INLINE
long extract_1
70 (CGEN_CPU_DESC
, CGEN_EXTRACT_INFO
*, int, int, int, unsigned char *, bfd_vma
);
73 /* Operand insertion. */
77 /* Subroutine of insert_normal. */
79 static CGEN_INLINE
void
80 insert_1 (CGEN_CPU_DESC cd
,
90 x
= cgen_get_insn_value (cd
, bufp
, word_length
);
92 /* Written this way to avoid undefined behaviour. */
93 mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
95 shift
= (start
+ 1) - length
;
97 shift
= (word_length
- (start
+ length
));
98 x
= (x
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
100 cgen_put_insn_value (cd
, bufp
, word_length
, (bfd_vma
) x
);
103 #endif /* ! CGEN_INT_INSN_P */
105 /* Default insertion routine.
107 ATTRS is a mask of the boolean attributes.
108 WORD_OFFSET is the offset in bits from the start of the insn of the value.
109 WORD_LENGTH is the length of the word in bits in which the value resides.
110 START is the starting bit number in the word, architecture origin.
111 LENGTH is the length of VALUE in bits.
112 TOTAL_LENGTH is the total length of the insn in bits.
114 The result is an error message or NULL if success. */
116 /* ??? This duplicates functionality with bfd's howto table and
117 bfd_install_relocation. */
118 /* ??? This doesn't handle bfd_vma's. Create another function when
122 insert_normal (CGEN_CPU_DESC cd
,
125 unsigned int word_offset
,
128 unsigned int word_length
,
129 unsigned int total_length
,
130 CGEN_INSN_BYTES_PTR buffer
)
132 static char errbuf
[100];
133 /* Written this way to avoid undefined behaviour. */
134 unsigned long mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
136 /* If LENGTH is zero, this operand doesn't contribute to the value. */
140 if (word_length
> 8 * sizeof (CGEN_INSN_INT
))
143 /* For architectures with insns smaller than the base-insn-bitsize,
144 word_length may be too big. */
145 if (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
)
148 && word_length
> total_length
)
149 word_length
= total_length
;
152 /* Ensure VALUE will fit. */
153 if (CGEN_BOOL_ATTR (attrs
, CGEN_IFLD_SIGN_OPT
))
155 long minval
= - (1L << (length
- 1));
156 unsigned long maxval
= mask
;
158 if ((value
> 0 && (unsigned long) value
> maxval
)
161 /* xgettext:c-format */
163 _("operand out of range (%ld not between %ld and %lu)"),
164 value
, minval
, maxval
);
168 else if (! CGEN_BOOL_ATTR (attrs
, CGEN_IFLD_SIGNED
))
170 unsigned long maxval
= mask
;
171 unsigned long val
= (unsigned long) value
;
173 /* For hosts with a word size > 32 check to see if value has been sign
174 extended beyond 32 bits. If so then ignore these higher sign bits
175 as the user is attempting to store a 32-bit signed value into an
176 unsigned 32-bit field which is allowed. */
177 if (sizeof (unsigned long) > 4 && ((value
>> 32) == -1))
182 /* xgettext:c-format */
184 _("operand out of range (0x%lx not between 0 and 0x%lx)"),
191 if (! cgen_signed_overflow_ok_p (cd
))
193 long minval
= - (1L << (length
- 1));
194 long maxval
= (1L << (length
- 1)) - 1;
196 if (value
< minval
|| value
> maxval
)
199 /* xgettext:c-format */
200 (errbuf
, _("operand out of range (%ld not between %ld and %ld)"),
201 value
, minval
, maxval
);
212 if (CGEN_INSN_LSB0_P
)
213 shift
= (word_offset
+ start
+ 1) - length
;
215 shift
= total_length
- (word_offset
+ start
+ length
);
216 *buffer
= (*buffer
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
219 #else /* ! CGEN_INT_INSN_P */
222 unsigned char *bufp
= (unsigned char *) buffer
+ word_offset
/ 8;
224 insert_1 (cd
, value
, start
, length
, word_length
, bufp
);
227 #endif /* ! CGEN_INT_INSN_P */
232 /* Default insn builder (insert handler).
233 The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
234 that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
235 recorded in host byte order, otherwise BUFFER is an array of bytes
236 and the value is recorded in target byte order).
237 The result is an error message or NULL if success. */
240 insert_insn_normal (CGEN_CPU_DESC cd
,
241 const CGEN_INSN
* insn
,
242 CGEN_FIELDS
* fields
,
243 CGEN_INSN_BYTES_PTR buffer
,
246 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
248 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
250 CGEN_INIT_INSERT (cd
);
251 value
= CGEN_INSN_BASE_VALUE (insn
);
253 /* If we're recording insns as numbers (rather than a string of bytes),
254 target byte order handling is deferred until later. */
258 put_insn_int_value (cd
, buffer
, cd
->base_insn_bitsize
,
259 CGEN_FIELDS_BITSIZE (fields
), value
);
263 cgen_put_insn_value (cd
, buffer
, min ((unsigned) cd
->base_insn_bitsize
,
264 (unsigned) CGEN_FIELDS_BITSIZE (fields
)),
267 #endif /* ! CGEN_INT_INSN_P */
269 /* ??? It would be better to scan the format's fields.
270 Still need to be able to insert a value based on the operand though;
271 e.g. storing a branch displacement that got resolved later.
272 Needs more thought first. */
274 for (syn
= CGEN_SYNTAX_STRING (syntax
); * syn
; ++ syn
)
278 if (CGEN_SYNTAX_CHAR_P (* syn
))
281 errmsg
= (* cd
->insert_operand
) (cd
, CGEN_SYNTAX_FIELD (*syn
),
291 /* Cover function to store an insn value into an integral insn. Must go here
292 because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */
295 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
296 CGEN_INSN_BYTES_PTR buf
,
301 /* For architectures with insns smaller than the base-insn-bitsize,
302 length may be too big. */
303 if (length
> insn_length
)
307 int shift
= insn_length
- length
;
308 /* Written this way to avoid undefined behaviour. */
309 CGEN_INSN_INT mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
311 *buf
= (*buf
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
316 /* Operand extraction. */
318 #if ! CGEN_INT_INSN_P
320 /* Subroutine of extract_normal.
321 Ensure sufficient bytes are cached in EX_INFO.
322 OFFSET is the offset in bytes from the start of the insn of the value.
323 BYTES is the length of the needed value.
324 Returns 1 for success, 0 for failure. */
326 static CGEN_INLINE
int
327 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
328 CGEN_EXTRACT_INFO
*ex_info
,
333 /* It's doubtful that the middle part has already been fetched so
334 we don't optimize that case. kiss. */
336 disassemble_info
*info
= (disassemble_info
*) ex_info
->dis_info
;
338 /* First do a quick check. */
339 mask
= (1 << bytes
) - 1;
340 if (((ex_info
->valid
>> offset
) & mask
) == mask
)
343 /* Search for the first byte we need to read. */
344 for (mask
= 1 << offset
; bytes
> 0; --bytes
, ++offset
, mask
<<= 1)
345 if (! (mask
& ex_info
->valid
))
353 status
= (*info
->read_memory_func
)
354 (pc
, ex_info
->insn_bytes
+ offset
, bytes
, info
);
358 (*info
->memory_error_func
) (status
, pc
, info
);
362 ex_info
->valid
|= ((1 << bytes
) - 1) << offset
;
368 /* Subroutine of extract_normal. */
370 static CGEN_INLINE
long
371 extract_1 (CGEN_CPU_DESC cd
,
372 CGEN_EXTRACT_INFO
*ex_info ATTRIBUTE_UNUSED
,
377 bfd_vma pc ATTRIBUTE_UNUSED
)
382 x
= cgen_get_insn_value (cd
, bufp
, word_length
);
384 if (CGEN_INSN_LSB0_P
)
385 shift
= (start
+ 1) - length
;
387 shift
= (word_length
- (start
+ length
));
391 #endif /* ! CGEN_INT_INSN_P */
393 /* Default extraction routine.
395 INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
396 or sometimes less for cases like the m32r where the base insn size is 32
397 but some insns are 16 bits.
398 ATTRS is a mask of the boolean attributes. We only need `SIGNED',
399 but for generality we take a bitmask of all of them.
400 WORD_OFFSET is the offset in bits from the start of the insn of the value.
401 WORD_LENGTH is the length of the word in bits in which the value resides.
402 START is the starting bit number in the word, architecture origin.
403 LENGTH is the length of VALUE in bits.
404 TOTAL_LENGTH is the total length of the insn in bits.
406 Returns 1 for success, 0 for failure. */
408 /* ??? The return code isn't properly used. wip. */
410 /* ??? This doesn't handle bfd_vma's. Create another function when
414 extract_normal (CGEN_CPU_DESC cd
,
415 #if ! CGEN_INT_INSN_P
416 CGEN_EXTRACT_INFO
*ex_info
,
418 CGEN_EXTRACT_INFO
*ex_info ATTRIBUTE_UNUSED
,
420 CGEN_INSN_INT insn_value
,
422 unsigned int word_offset
,
425 unsigned int word_length
,
426 unsigned int total_length
,
427 #if ! CGEN_INT_INSN_P
430 bfd_vma pc ATTRIBUTE_UNUSED
,
436 /* If LENGTH is zero, this operand doesn't contribute to the value
437 so give it a standard value of zero. */
444 if (word_length
> 8 * sizeof (CGEN_INSN_INT
))
447 /* For architectures with insns smaller than the insn-base-bitsize,
448 word_length may be too big. */
449 if (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
)
451 if (word_offset
+ word_length
> total_length
)
452 word_length
= total_length
- word_offset
;
455 /* Does the value reside in INSN_VALUE, and at the right alignment? */
457 if (CGEN_INT_INSN_P
|| (word_offset
== 0 && word_length
== total_length
))
459 if (CGEN_INSN_LSB0_P
)
460 value
= insn_value
>> ((word_offset
+ start
+ 1) - length
);
462 value
= insn_value
>> (total_length
- ( word_offset
+ start
+ length
));
465 #if ! CGEN_INT_INSN_P
469 unsigned char *bufp
= ex_info
->insn_bytes
+ word_offset
/ 8;
471 if (word_length
> 8 * sizeof (CGEN_INSN_INT
))
474 if (fill_cache (cd
, ex_info
, word_offset
/ 8, word_length
/ 8, pc
) == 0)
477 value
= extract_1 (cd
, ex_info
, start
, length
, word_length
, bufp
, pc
);
480 #endif /* ! CGEN_INT_INSN_P */
482 /* Written this way to avoid undefined behaviour. */
483 mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
487 if (CGEN_BOOL_ATTR (attrs
, CGEN_IFLD_SIGNED
)
488 && (value
& (1L << (length
- 1))))
496 /* Default insn extractor.
498 INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
499 The extracted fields are stored in FIELDS.
500 EX_INFO is used to handle reading variable length insns.
501 Return the length of the insn in bits, or 0 if no match,
502 or -1 if an error occurs fetching data (memory_error_func will have
506 extract_insn_normal (CGEN_CPU_DESC cd
,
507 const CGEN_INSN
*insn
,
508 CGEN_EXTRACT_INFO
*ex_info
,
509 CGEN_INSN_INT insn_value
,
513 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
514 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
516 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
518 CGEN_INIT_EXTRACT (cd
);
520 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
524 if (CGEN_SYNTAX_CHAR_P (*syn
))
527 length
= (* cd
->extract_operand
) (cd
, CGEN_SYNTAX_FIELD (*syn
),
528 ex_info
, insn_value
, fields
, pc
);
533 /* We recognized and successfully extracted this insn. */
534 return CGEN_INSN_BITSIZE (insn
);
537 /* Machine generated code added here. */
539 const char * xc16x_cgen_insert_operand
540 (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, CGEN_INSN_BYTES_PTR
, bfd_vma
);
542 /* Main entry point for operand insertion.
544 This function is basically just a big switch statement. Earlier versions
545 used tables to look up the function to use, but
546 - if the table contains both assembler and disassembler functions then
547 the disassembler contains much of the assembler and vice-versa,
548 - there's a lot of inlining possibilities as things grow,
549 - using a switch statement avoids the function call overhead.
551 This function could be moved into `parse_insn_normal', but keeping it
552 separate makes clear the interface between `parse_insn_normal' and each of
553 the handlers. It's also needed by GAS to insert operands that couldn't be
554 resolved during parsing. */
557 xc16x_cgen_insert_operand (CGEN_CPU_DESC cd
,
559 CGEN_FIELDS
* fields
,
560 CGEN_INSN_BYTES_PTR buffer
,
561 bfd_vma pc ATTRIBUTE_UNUSED
)
563 const char * errmsg
= NULL
;
564 unsigned int total_length
= CGEN_FIELDS_BITSIZE (fields
);
568 case XC16X_OPERAND_REGNAM
:
569 errmsg
= insert_normal (cd
, fields
->f_reg8
, 0, 0, 15, 8, 32, total_length
, buffer
);
571 case XC16X_OPERAND_BIT01
:
572 errmsg
= insert_normal (cd
, fields
->f_op_1bit
, 0, 0, 8, 1, 32, total_length
, buffer
);
574 case XC16X_OPERAND_BIT1
:
575 errmsg
= insert_normal (cd
, fields
->f_op_bit1
, 0, 0, 11, 1, 32, total_length
, buffer
);
577 case XC16X_OPERAND_BIT2
:
578 errmsg
= insert_normal (cd
, fields
->f_op_bit2
, 0, 0, 11, 2, 32, total_length
, buffer
);
580 case XC16X_OPERAND_BIT4
:
581 errmsg
= insert_normal (cd
, fields
->f_op_bit4
, 0, 0, 11, 4, 32, total_length
, buffer
);
583 case XC16X_OPERAND_BIT8
:
584 errmsg
= insert_normal (cd
, fields
->f_op_bit8
, 0, 0, 31, 8, 32, total_length
, buffer
);
586 case XC16X_OPERAND_BITONE
:
587 errmsg
= insert_normal (cd
, fields
->f_op_onebit
, 0, 0, 9, 1, 32, total_length
, buffer
);
589 case XC16X_OPERAND_CADDR
:
590 errmsg
= insert_normal (cd
, fields
->f_offset16
, 0|(1<<CGEN_IFLD_RELOC
)|(1<<CGEN_IFLD_ABS_ADDR
), 0, 31, 16, 32, total_length
, buffer
);
592 case XC16X_OPERAND_COND
:
593 errmsg
= insert_normal (cd
, fields
->f_condcode
, 0, 0, 7, 4, 32, total_length
, buffer
);
595 case XC16X_OPERAND_DATA8
:
596 errmsg
= insert_normal (cd
, fields
->f_data8
, 0, 0, 23, 8, 32, total_length
, buffer
);
598 case XC16X_OPERAND_DATAHI8
:
599 errmsg
= insert_normal (cd
, fields
->f_datahi8
, 0, 0, 31, 8, 32, total_length
, buffer
);
601 case XC16X_OPERAND_DOT
:
603 case XC16X_OPERAND_DR
:
604 errmsg
= insert_normal (cd
, fields
->f_r1
, 0, 0, 15, 4, 32, total_length
, buffer
);
606 case XC16X_OPERAND_DRB
:
607 errmsg
= insert_normal (cd
, fields
->f_r1
, 0, 0, 15, 4, 32, total_length
, buffer
);
609 case XC16X_OPERAND_DRI
:
610 errmsg
= insert_normal (cd
, fields
->f_r4
, 0, 0, 11, 4, 32, total_length
, buffer
);
612 case XC16X_OPERAND_EXTCOND
:
613 errmsg
= insert_normal (cd
, fields
->f_extccode
, 0, 0, 15, 5, 32, total_length
, buffer
);
615 case XC16X_OPERAND_GENREG
:
616 errmsg
= insert_normal (cd
, fields
->f_regb8
, 0, 0, 15, 8, 32, total_length
, buffer
);
618 case XC16X_OPERAND_HASH
:
620 case XC16X_OPERAND_ICOND
:
621 errmsg
= insert_normal (cd
, fields
->f_icondcode
, 0, 0, 15, 4, 32, total_length
, buffer
);
623 case XC16X_OPERAND_LBIT2
:
624 errmsg
= insert_normal (cd
, fields
->f_op_lbit2
, 0, 0, 15, 2, 32, total_length
, buffer
);
626 case XC16X_OPERAND_LBIT4
:
627 errmsg
= insert_normal (cd
, fields
->f_op_lbit4
, 0, 0, 15, 4, 32, total_length
, buffer
);
629 case XC16X_OPERAND_MASK8
:
630 errmsg
= insert_normal (cd
, fields
->f_mask8
, 0, 0, 23, 8, 32, total_length
, buffer
);
632 case XC16X_OPERAND_MASKLO8
:
633 errmsg
= insert_normal (cd
, fields
->f_datahi8
, 0, 0, 31, 8, 32, total_length
, buffer
);
635 case XC16X_OPERAND_MEMGR8
:
636 errmsg
= insert_normal (cd
, fields
->f_memgr8
, 0, 0, 31, 16, 32, total_length
, buffer
);
638 case XC16X_OPERAND_MEMORY
:
639 errmsg
= insert_normal (cd
, fields
->f_memory
, 0, 0, 31, 16, 32, total_length
, buffer
);
641 case XC16X_OPERAND_PAG
:
643 case XC16X_OPERAND_PAGENUM
:
644 errmsg
= insert_normal (cd
, fields
->f_pagenum
, 0, 0, 25, 10, 32, total_length
, buffer
);
646 case XC16X_OPERAND_POF
:
648 case XC16X_OPERAND_QBIT
:
649 errmsg
= insert_normal (cd
, fields
->f_qbit
, 0, 0, 7, 4, 32, total_length
, buffer
);
651 case XC16X_OPERAND_QHIBIT
:
652 errmsg
= insert_normal (cd
, fields
->f_qhibit
, 0, 0, 27, 4, 32, total_length
, buffer
);
654 case XC16X_OPERAND_QLOBIT
:
655 errmsg
= insert_normal (cd
, fields
->f_qlobit
, 0, 0, 31, 4, 32, total_length
, buffer
);
657 case XC16X_OPERAND_REG8
:
658 errmsg
= insert_normal (cd
, fields
->f_reg8
, 0, 0, 15, 8, 32, total_length
, buffer
);
660 case XC16X_OPERAND_REGB8
:
661 errmsg
= insert_normal (cd
, fields
->f_regb8
, 0, 0, 15, 8, 32, total_length
, buffer
);
663 case XC16X_OPERAND_REGBMEM8
:
664 errmsg
= insert_normal (cd
, fields
->f_regmem8
, 0, 0, 15, 8, 32, total_length
, buffer
);
666 case XC16X_OPERAND_REGHI8
:
667 errmsg
= insert_normal (cd
, fields
->f_reghi8
, 0, 0, 23, 8, 32, total_length
, buffer
);
669 case XC16X_OPERAND_REGMEM8
:
670 errmsg
= insert_normal (cd
, fields
->f_regmem8
, 0, 0, 15, 8, 32, total_length
, buffer
);
672 case XC16X_OPERAND_REGOFF8
:
673 errmsg
= insert_normal (cd
, fields
->f_regoff8
, 0, 0, 15, 8, 32, total_length
, buffer
);
675 case XC16X_OPERAND_REL
:
676 errmsg
= insert_normal (cd
, fields
->f_rel8
, 0|(1<<CGEN_IFLD_RELOC
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 15, 8, 32, total_length
, buffer
);
678 case XC16X_OPERAND_RELHI
:
679 errmsg
= insert_normal (cd
, fields
->f_relhi8
, 0|(1<<CGEN_IFLD_RELOC
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 23, 8, 32, total_length
, buffer
);
681 case XC16X_OPERAND_SEG
:
682 errmsg
= insert_normal (cd
, fields
->f_seg8
, 0, 0, 15, 8, 32, total_length
, buffer
);
684 case XC16X_OPERAND_SEGHI8
:
685 errmsg
= insert_normal (cd
, fields
->f_segnum8
, 0, 0, 23, 8, 32, total_length
, buffer
);
687 case XC16X_OPERAND_SEGM
:
689 case XC16X_OPERAND_SOF
:
691 case XC16X_OPERAND_SR
:
692 errmsg
= insert_normal (cd
, fields
->f_r2
, 0, 0, 11, 4, 32, total_length
, buffer
);
694 case XC16X_OPERAND_SR2
:
695 errmsg
= insert_normal (cd
, fields
->f_r0
, 0, 0, 9, 2, 32, total_length
, buffer
);
697 case XC16X_OPERAND_SRB
:
698 errmsg
= insert_normal (cd
, fields
->f_r2
, 0, 0, 11, 4, 32, total_length
, buffer
);
700 case XC16X_OPERAND_SRC1
:
701 errmsg
= insert_normal (cd
, fields
->f_r1
, 0, 0, 15, 4, 32, total_length
, buffer
);
703 case XC16X_OPERAND_SRC2
:
704 errmsg
= insert_normal (cd
, fields
->f_r2
, 0, 0, 11, 4, 32, total_length
, buffer
);
706 case XC16X_OPERAND_SRDIV
:
707 errmsg
= insert_normal (cd
, fields
->f_reg8
, 0, 0, 15, 8, 32, total_length
, buffer
);
709 case XC16X_OPERAND_U4
:
710 errmsg
= insert_normal (cd
, fields
->f_uimm4
, 0, 0, 15, 4, 32, total_length
, buffer
);
712 case XC16X_OPERAND_UIMM16
:
713 errmsg
= insert_normal (cd
, fields
->f_uimm16
, 0, 0, 31, 16, 32, total_length
, buffer
);
715 case XC16X_OPERAND_UIMM2
:
716 errmsg
= insert_normal (cd
, fields
->f_uimm2
, 0, 0, 13, 2, 32, total_length
, buffer
);
718 case XC16X_OPERAND_UIMM3
:
719 errmsg
= insert_normal (cd
, fields
->f_uimm3
, 0, 0, 10, 3, 32, total_length
, buffer
);
721 case XC16X_OPERAND_UIMM4
:
722 errmsg
= insert_normal (cd
, fields
->f_uimm4
, 0, 0, 15, 4, 32, total_length
, buffer
);
724 case XC16X_OPERAND_UIMM7
:
725 errmsg
= insert_normal (cd
, fields
->f_uimm7
, 0|(1<<CGEN_IFLD_RELOC
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 15, 7, 32, total_length
, buffer
);
727 case XC16X_OPERAND_UIMM8
:
728 errmsg
= insert_normal (cd
, fields
->f_uimm8
, 0, 0, 23, 8, 32, total_length
, buffer
);
730 case XC16X_OPERAND_UPAG16
:
731 errmsg
= insert_normal (cd
, fields
->f_uimm16
, 0, 0, 31, 16, 32, total_length
, buffer
);
733 case XC16X_OPERAND_UPOF16
:
734 errmsg
= insert_normal (cd
, fields
->f_memory
, 0, 0, 31, 16, 32, total_length
, buffer
);
736 case XC16X_OPERAND_USEG16
:
737 errmsg
= insert_normal (cd
, fields
->f_offset16
, 0|(1<<CGEN_IFLD_RELOC
)|(1<<CGEN_IFLD_ABS_ADDR
), 0, 31, 16, 32, total_length
, buffer
);
739 case XC16X_OPERAND_USEG8
:
740 errmsg
= insert_normal (cd
, fields
->f_seg8
, 0, 0, 15, 8, 32, total_length
, buffer
);
742 case XC16X_OPERAND_USOF16
:
743 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 /* xgettext:c-format */
748 fprintf (stderr
, _("Unrecognized field %d while building insn.\n"),
756 int xc16x_cgen_extract_operand
757 (CGEN_CPU_DESC
, int, CGEN_EXTRACT_INFO
*, CGEN_INSN_INT
, CGEN_FIELDS
*, bfd_vma
);
759 /* Main entry point for operand extraction.
760 The result is <= 0 for error, >0 for success.
761 ??? Actual values aren't well defined right now.
763 This function is basically just a big switch statement. Earlier versions
764 used tables to look up the function to use, but
765 - if the table contains both assembler and disassembler functions then
766 the disassembler contains much of the assembler and vice-versa,
767 - there's a lot of inlining possibilities as things grow,
768 - using a switch statement avoids the function call overhead.
770 This function could be moved into `print_insn_normal', but keeping it
771 separate makes clear the interface between `print_insn_normal' and each of
775 xc16x_cgen_extract_operand (CGEN_CPU_DESC cd
,
777 CGEN_EXTRACT_INFO
*ex_info
,
778 CGEN_INSN_INT insn_value
,
779 CGEN_FIELDS
* fields
,
782 /* Assume success (for those operands that are nops). */
784 unsigned int total_length
= CGEN_FIELDS_BITSIZE (fields
);
788 case XC16X_OPERAND_REGNAM
:
789 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_reg8
);
791 case XC16X_OPERAND_BIT01
:
792 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 1, 32, total_length
, pc
, & fields
->f_op_1bit
);
794 case XC16X_OPERAND_BIT1
:
795 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 1, 32, total_length
, pc
, & fields
->f_op_bit1
);
797 case XC16X_OPERAND_BIT2
:
798 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 2, 32, total_length
, pc
, & fields
->f_op_bit2
);
800 case XC16X_OPERAND_BIT4
:
801 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 4, 32, total_length
, pc
, & fields
->f_op_bit4
);
803 case XC16X_OPERAND_BIT8
:
804 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 8, 32, total_length
, pc
, & fields
->f_op_bit8
);
806 case XC16X_OPERAND_BITONE
:
807 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 9, 1, 32, total_length
, pc
, & fields
->f_op_onebit
);
809 case XC16X_OPERAND_CADDR
:
810 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
);
812 case XC16X_OPERAND_COND
:
813 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 7, 4, 32, total_length
, pc
, & fields
->f_condcode
);
815 case XC16X_OPERAND_DATA8
:
816 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 23, 8, 32, total_length
, pc
, & fields
->f_data8
);
818 case XC16X_OPERAND_DATAHI8
:
819 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 8, 32, total_length
, pc
, & fields
->f_datahi8
);
821 case XC16X_OPERAND_DOT
:
823 case XC16X_OPERAND_DR
:
824 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 4, 32, total_length
, pc
, & fields
->f_r1
);
826 case XC16X_OPERAND_DRB
:
827 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 4, 32, total_length
, pc
, & fields
->f_r1
);
829 case XC16X_OPERAND_DRI
:
830 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 4, 32, total_length
, pc
, & fields
->f_r4
);
832 case XC16X_OPERAND_EXTCOND
:
833 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 5, 32, total_length
, pc
, & fields
->f_extccode
);
835 case XC16X_OPERAND_GENREG
:
836 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_regb8
);
838 case XC16X_OPERAND_HASH
:
840 case XC16X_OPERAND_ICOND
:
841 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 4, 32, total_length
, pc
, & fields
->f_icondcode
);
843 case XC16X_OPERAND_LBIT2
:
844 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 2, 32, total_length
, pc
, & fields
->f_op_lbit2
);
846 case XC16X_OPERAND_LBIT4
:
847 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 4, 32, total_length
, pc
, & fields
->f_op_lbit4
);
849 case XC16X_OPERAND_MASK8
:
850 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 23, 8, 32, total_length
, pc
, & fields
->f_mask8
);
852 case XC16X_OPERAND_MASKLO8
:
853 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 8, 32, total_length
, pc
, & fields
->f_datahi8
);
855 case XC16X_OPERAND_MEMGR8
:
856 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 16, 32, total_length
, pc
, & fields
->f_memgr8
);
858 case XC16X_OPERAND_MEMORY
:
859 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 16, 32, total_length
, pc
, & fields
->f_memory
);
861 case XC16X_OPERAND_PAG
:
863 case XC16X_OPERAND_PAGENUM
:
864 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 25, 10, 32, total_length
, pc
, & fields
->f_pagenum
);
866 case XC16X_OPERAND_POF
:
868 case XC16X_OPERAND_QBIT
:
869 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 7, 4, 32, total_length
, pc
, & fields
->f_qbit
);
871 case XC16X_OPERAND_QHIBIT
:
872 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 27, 4, 32, total_length
, pc
, & fields
->f_qhibit
);
874 case XC16X_OPERAND_QLOBIT
:
875 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 4, 32, total_length
, pc
, & fields
->f_qlobit
);
877 case XC16X_OPERAND_REG8
:
878 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_reg8
);
880 case XC16X_OPERAND_REGB8
:
881 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_regb8
);
883 case XC16X_OPERAND_REGBMEM8
:
884 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_regmem8
);
886 case XC16X_OPERAND_REGHI8
:
887 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 23, 8, 32, total_length
, pc
, & fields
->f_reghi8
);
889 case XC16X_OPERAND_REGMEM8
:
890 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_regmem8
);
892 case XC16X_OPERAND_REGOFF8
:
893 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_regoff8
);
895 case XC16X_OPERAND_REL
:
896 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
);
898 case XC16X_OPERAND_RELHI
:
899 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
);
901 case XC16X_OPERAND_SEG
:
902 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_seg8
);
904 case XC16X_OPERAND_SEGHI8
:
905 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 23, 8, 32, total_length
, pc
, & fields
->f_segnum8
);
907 case XC16X_OPERAND_SEGM
:
909 case XC16X_OPERAND_SOF
:
911 case XC16X_OPERAND_SR
:
912 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 4, 32, total_length
, pc
, & fields
->f_r2
);
914 case XC16X_OPERAND_SR2
:
915 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 9, 2, 32, total_length
, pc
, & fields
->f_r0
);
917 case XC16X_OPERAND_SRB
:
918 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 4, 32, total_length
, pc
, & fields
->f_r2
);
920 case XC16X_OPERAND_SRC1
:
921 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 4, 32, total_length
, pc
, & fields
->f_r1
);
923 case XC16X_OPERAND_SRC2
:
924 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 4, 32, total_length
, pc
, & fields
->f_r2
);
926 case XC16X_OPERAND_SRDIV
:
927 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_reg8
);
929 case XC16X_OPERAND_U4
:
930 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 4, 32, total_length
, pc
, & fields
->f_uimm4
);
932 case XC16X_OPERAND_UIMM16
:
933 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 16, 32, total_length
, pc
, & fields
->f_uimm16
);
935 case XC16X_OPERAND_UIMM2
:
936 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 13, 2, 32, total_length
, pc
, & fields
->f_uimm2
);
938 case XC16X_OPERAND_UIMM3
:
939 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 10, 3, 32, total_length
, pc
, & fields
->f_uimm3
);
941 case XC16X_OPERAND_UIMM4
:
942 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 4, 32, total_length
, pc
, & fields
->f_uimm4
);
944 case XC16X_OPERAND_UIMM7
:
945 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
);
947 case XC16X_OPERAND_UIMM8
:
948 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 23, 8, 32, total_length
, pc
, & fields
->f_uimm8
);
950 case XC16X_OPERAND_UPAG16
:
951 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 16, 32, total_length
, pc
, & fields
->f_uimm16
);
953 case XC16X_OPERAND_UPOF16
:
954 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 31, 16, 32, total_length
, pc
, & fields
->f_memory
);
956 case XC16X_OPERAND_USEG16
:
957 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
);
959 case XC16X_OPERAND_USEG8
:
960 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 15, 8, 32, total_length
, pc
, & fields
->f_seg8
);
962 case XC16X_OPERAND_USOF16
:
963 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 /* xgettext:c-format */
968 fprintf (stderr
, _("Unrecognized field %d while decoding insn.\n"),
976 cgen_insert_fn
* const xc16x_cgen_insert_handlers
[] =
981 cgen_extract_fn
* const xc16x_cgen_extract_handlers
[] =
986 int xc16x_cgen_get_int_operand (CGEN_CPU_DESC
, int, const CGEN_FIELDS
*);
987 bfd_vma
xc16x_cgen_get_vma_operand (CGEN_CPU_DESC
, int, const CGEN_FIELDS
*);
989 /* Getting values from cgen_fields is handled by a collection of functions.
990 They are distinguished by the type of the VALUE argument they return.
991 TODO: floating point, inlining support, remove cases where result type
995 xc16x_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
997 const CGEN_FIELDS
* fields
)
1003 case XC16X_OPERAND_REGNAM
:
1004 value
= fields
->f_reg8
;
1006 case XC16X_OPERAND_BIT01
:
1007 value
= fields
->f_op_1bit
;
1009 case XC16X_OPERAND_BIT1
:
1010 value
= fields
->f_op_bit1
;
1012 case XC16X_OPERAND_BIT2
:
1013 value
= fields
->f_op_bit2
;
1015 case XC16X_OPERAND_BIT4
:
1016 value
= fields
->f_op_bit4
;
1018 case XC16X_OPERAND_BIT8
:
1019 value
= fields
->f_op_bit8
;
1021 case XC16X_OPERAND_BITONE
:
1022 value
= fields
->f_op_onebit
;
1024 case XC16X_OPERAND_CADDR
:
1025 value
= fields
->f_offset16
;
1027 case XC16X_OPERAND_COND
:
1028 value
= fields
->f_condcode
;
1030 case XC16X_OPERAND_DATA8
:
1031 value
= fields
->f_data8
;
1033 case XC16X_OPERAND_DATAHI8
:
1034 value
= fields
->f_datahi8
;
1036 case XC16X_OPERAND_DOT
:
1039 case XC16X_OPERAND_DR
:
1040 value
= fields
->f_r1
;
1042 case XC16X_OPERAND_DRB
:
1043 value
= fields
->f_r1
;
1045 case XC16X_OPERAND_DRI
:
1046 value
= fields
->f_r4
;
1048 case XC16X_OPERAND_EXTCOND
:
1049 value
= fields
->f_extccode
;
1051 case XC16X_OPERAND_GENREG
:
1052 value
= fields
->f_regb8
;
1054 case XC16X_OPERAND_HASH
:
1057 case XC16X_OPERAND_ICOND
:
1058 value
= fields
->f_icondcode
;
1060 case XC16X_OPERAND_LBIT2
:
1061 value
= fields
->f_op_lbit2
;
1063 case XC16X_OPERAND_LBIT4
:
1064 value
= fields
->f_op_lbit4
;
1066 case XC16X_OPERAND_MASK8
:
1067 value
= fields
->f_mask8
;
1069 case XC16X_OPERAND_MASKLO8
:
1070 value
= fields
->f_datahi8
;
1072 case XC16X_OPERAND_MEMGR8
:
1073 value
= fields
->f_memgr8
;
1075 case XC16X_OPERAND_MEMORY
:
1076 value
= fields
->f_memory
;
1078 case XC16X_OPERAND_PAG
:
1081 case XC16X_OPERAND_PAGENUM
:
1082 value
= fields
->f_pagenum
;
1084 case XC16X_OPERAND_POF
:
1087 case XC16X_OPERAND_QBIT
:
1088 value
= fields
->f_qbit
;
1090 case XC16X_OPERAND_QHIBIT
:
1091 value
= fields
->f_qhibit
;
1093 case XC16X_OPERAND_QLOBIT
:
1094 value
= fields
->f_qlobit
;
1096 case XC16X_OPERAND_REG8
:
1097 value
= fields
->f_reg8
;
1099 case XC16X_OPERAND_REGB8
:
1100 value
= fields
->f_regb8
;
1102 case XC16X_OPERAND_REGBMEM8
:
1103 value
= fields
->f_regmem8
;
1105 case XC16X_OPERAND_REGHI8
:
1106 value
= fields
->f_reghi8
;
1108 case XC16X_OPERAND_REGMEM8
:
1109 value
= fields
->f_regmem8
;
1111 case XC16X_OPERAND_REGOFF8
:
1112 value
= fields
->f_regoff8
;
1114 case XC16X_OPERAND_REL
:
1115 value
= fields
->f_rel8
;
1117 case XC16X_OPERAND_RELHI
:
1118 value
= fields
->f_relhi8
;
1120 case XC16X_OPERAND_SEG
:
1121 value
= fields
->f_seg8
;
1123 case XC16X_OPERAND_SEGHI8
:
1124 value
= fields
->f_segnum8
;
1126 case XC16X_OPERAND_SEGM
:
1129 case XC16X_OPERAND_SOF
:
1132 case XC16X_OPERAND_SR
:
1133 value
= fields
->f_r2
;
1135 case XC16X_OPERAND_SR2
:
1136 value
= fields
->f_r0
;
1138 case XC16X_OPERAND_SRB
:
1139 value
= fields
->f_r2
;
1141 case XC16X_OPERAND_SRC1
:
1142 value
= fields
->f_r1
;
1144 case XC16X_OPERAND_SRC2
:
1145 value
= fields
->f_r2
;
1147 case XC16X_OPERAND_SRDIV
:
1148 value
= fields
->f_reg8
;
1150 case XC16X_OPERAND_U4
:
1151 value
= fields
->f_uimm4
;
1153 case XC16X_OPERAND_UIMM16
:
1154 value
= fields
->f_uimm16
;
1156 case XC16X_OPERAND_UIMM2
:
1157 value
= fields
->f_uimm2
;
1159 case XC16X_OPERAND_UIMM3
:
1160 value
= fields
->f_uimm3
;
1162 case XC16X_OPERAND_UIMM4
:
1163 value
= fields
->f_uimm4
;
1165 case XC16X_OPERAND_UIMM7
:
1166 value
= fields
->f_uimm7
;
1168 case XC16X_OPERAND_UIMM8
:
1169 value
= fields
->f_uimm8
;
1171 case XC16X_OPERAND_UPAG16
:
1172 value
= fields
->f_uimm16
;
1174 case XC16X_OPERAND_UPOF16
:
1175 value
= fields
->f_memory
;
1177 case XC16X_OPERAND_USEG16
:
1178 value
= fields
->f_offset16
;
1180 case XC16X_OPERAND_USEG8
:
1181 value
= fields
->f_seg8
;
1183 case XC16X_OPERAND_USOF16
:
1184 value
= fields
->f_offset16
;
1188 /* xgettext:c-format */
1189 fprintf (stderr
, _("Unrecognized field %d while getting int operand.\n"),
1198 xc16x_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
1200 const CGEN_FIELDS
* fields
)
1206 case XC16X_OPERAND_REGNAM
:
1207 value
= fields
->f_reg8
;
1209 case XC16X_OPERAND_BIT01
:
1210 value
= fields
->f_op_1bit
;
1212 case XC16X_OPERAND_BIT1
:
1213 value
= fields
->f_op_bit1
;
1215 case XC16X_OPERAND_BIT2
:
1216 value
= fields
->f_op_bit2
;
1218 case XC16X_OPERAND_BIT4
:
1219 value
= fields
->f_op_bit4
;
1221 case XC16X_OPERAND_BIT8
:
1222 value
= fields
->f_op_bit8
;
1224 case XC16X_OPERAND_BITONE
:
1225 value
= fields
->f_op_onebit
;
1227 case XC16X_OPERAND_CADDR
:
1228 value
= fields
->f_offset16
;
1230 case XC16X_OPERAND_COND
:
1231 value
= fields
->f_condcode
;
1233 case XC16X_OPERAND_DATA8
:
1234 value
= fields
->f_data8
;
1236 case XC16X_OPERAND_DATAHI8
:
1237 value
= fields
->f_datahi8
;
1239 case XC16X_OPERAND_DOT
:
1242 case XC16X_OPERAND_DR
:
1243 value
= fields
->f_r1
;
1245 case XC16X_OPERAND_DRB
:
1246 value
= fields
->f_r1
;
1248 case XC16X_OPERAND_DRI
:
1249 value
= fields
->f_r4
;
1251 case XC16X_OPERAND_EXTCOND
:
1252 value
= fields
->f_extccode
;
1254 case XC16X_OPERAND_GENREG
:
1255 value
= fields
->f_regb8
;
1257 case XC16X_OPERAND_HASH
:
1260 case XC16X_OPERAND_ICOND
:
1261 value
= fields
->f_icondcode
;
1263 case XC16X_OPERAND_LBIT2
:
1264 value
= fields
->f_op_lbit2
;
1266 case XC16X_OPERAND_LBIT4
:
1267 value
= fields
->f_op_lbit4
;
1269 case XC16X_OPERAND_MASK8
:
1270 value
= fields
->f_mask8
;
1272 case XC16X_OPERAND_MASKLO8
:
1273 value
= fields
->f_datahi8
;
1275 case XC16X_OPERAND_MEMGR8
:
1276 value
= fields
->f_memgr8
;
1278 case XC16X_OPERAND_MEMORY
:
1279 value
= fields
->f_memory
;
1281 case XC16X_OPERAND_PAG
:
1284 case XC16X_OPERAND_PAGENUM
:
1285 value
= fields
->f_pagenum
;
1287 case XC16X_OPERAND_POF
:
1290 case XC16X_OPERAND_QBIT
:
1291 value
= fields
->f_qbit
;
1293 case XC16X_OPERAND_QHIBIT
:
1294 value
= fields
->f_qhibit
;
1296 case XC16X_OPERAND_QLOBIT
:
1297 value
= fields
->f_qlobit
;
1299 case XC16X_OPERAND_REG8
:
1300 value
= fields
->f_reg8
;
1302 case XC16X_OPERAND_REGB8
:
1303 value
= fields
->f_regb8
;
1305 case XC16X_OPERAND_REGBMEM8
:
1306 value
= fields
->f_regmem8
;
1308 case XC16X_OPERAND_REGHI8
:
1309 value
= fields
->f_reghi8
;
1311 case XC16X_OPERAND_REGMEM8
:
1312 value
= fields
->f_regmem8
;
1314 case XC16X_OPERAND_REGOFF8
:
1315 value
= fields
->f_regoff8
;
1317 case XC16X_OPERAND_REL
:
1318 value
= fields
->f_rel8
;
1320 case XC16X_OPERAND_RELHI
:
1321 value
= fields
->f_relhi8
;
1323 case XC16X_OPERAND_SEG
:
1324 value
= fields
->f_seg8
;
1326 case XC16X_OPERAND_SEGHI8
:
1327 value
= fields
->f_segnum8
;
1329 case XC16X_OPERAND_SEGM
:
1332 case XC16X_OPERAND_SOF
:
1335 case XC16X_OPERAND_SR
:
1336 value
= fields
->f_r2
;
1338 case XC16X_OPERAND_SR2
:
1339 value
= fields
->f_r0
;
1341 case XC16X_OPERAND_SRB
:
1342 value
= fields
->f_r2
;
1344 case XC16X_OPERAND_SRC1
:
1345 value
= fields
->f_r1
;
1347 case XC16X_OPERAND_SRC2
:
1348 value
= fields
->f_r2
;
1350 case XC16X_OPERAND_SRDIV
:
1351 value
= fields
->f_reg8
;
1353 case XC16X_OPERAND_U4
:
1354 value
= fields
->f_uimm4
;
1356 case XC16X_OPERAND_UIMM16
:
1357 value
= fields
->f_uimm16
;
1359 case XC16X_OPERAND_UIMM2
:
1360 value
= fields
->f_uimm2
;
1362 case XC16X_OPERAND_UIMM3
:
1363 value
= fields
->f_uimm3
;
1365 case XC16X_OPERAND_UIMM4
:
1366 value
= fields
->f_uimm4
;
1368 case XC16X_OPERAND_UIMM7
:
1369 value
= fields
->f_uimm7
;
1371 case XC16X_OPERAND_UIMM8
:
1372 value
= fields
->f_uimm8
;
1374 case XC16X_OPERAND_UPAG16
:
1375 value
= fields
->f_uimm16
;
1377 case XC16X_OPERAND_UPOF16
:
1378 value
= fields
->f_memory
;
1380 case XC16X_OPERAND_USEG16
:
1381 value
= fields
->f_offset16
;
1383 case XC16X_OPERAND_USEG8
:
1384 value
= fields
->f_seg8
;
1386 case XC16X_OPERAND_USOF16
:
1387 value
= fields
->f_offset16
;
1391 /* xgettext:c-format */
1392 fprintf (stderr
, _("Unrecognized field %d while getting vma operand.\n"),
1400 void xc16x_cgen_set_int_operand (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, int);
1401 void xc16x_cgen_set_vma_operand (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, bfd_vma
);
1403 /* Stuffing values in cgen_fields is handled by a collection of functions.
1404 They are distinguished by the type of the VALUE argument they accept.
1405 TODO: floating point, inlining support, remove cases where argument type
1409 xc16x_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
1411 CGEN_FIELDS
* fields
,
1416 case XC16X_OPERAND_REGNAM
:
1417 fields
->f_reg8
= value
;
1419 case XC16X_OPERAND_BIT01
:
1420 fields
->f_op_1bit
= value
;
1422 case XC16X_OPERAND_BIT1
:
1423 fields
->f_op_bit1
= value
;
1425 case XC16X_OPERAND_BIT2
:
1426 fields
->f_op_bit2
= value
;
1428 case XC16X_OPERAND_BIT4
:
1429 fields
->f_op_bit4
= value
;
1431 case XC16X_OPERAND_BIT8
:
1432 fields
->f_op_bit8
= value
;
1434 case XC16X_OPERAND_BITONE
:
1435 fields
->f_op_onebit
= value
;
1437 case XC16X_OPERAND_CADDR
:
1438 fields
->f_offset16
= value
;
1440 case XC16X_OPERAND_COND
:
1441 fields
->f_condcode
= value
;
1443 case XC16X_OPERAND_DATA8
:
1444 fields
->f_data8
= value
;
1446 case XC16X_OPERAND_DATAHI8
:
1447 fields
->f_datahi8
= value
;
1449 case XC16X_OPERAND_DOT
:
1451 case XC16X_OPERAND_DR
:
1452 fields
->f_r1
= value
;
1454 case XC16X_OPERAND_DRB
:
1455 fields
->f_r1
= value
;
1457 case XC16X_OPERAND_DRI
:
1458 fields
->f_r4
= value
;
1460 case XC16X_OPERAND_EXTCOND
:
1461 fields
->f_extccode
= value
;
1463 case XC16X_OPERAND_GENREG
:
1464 fields
->f_regb8
= value
;
1466 case XC16X_OPERAND_HASH
:
1468 case XC16X_OPERAND_ICOND
:
1469 fields
->f_icondcode
= value
;
1471 case XC16X_OPERAND_LBIT2
:
1472 fields
->f_op_lbit2
= value
;
1474 case XC16X_OPERAND_LBIT4
:
1475 fields
->f_op_lbit4
= value
;
1477 case XC16X_OPERAND_MASK8
:
1478 fields
->f_mask8
= value
;
1480 case XC16X_OPERAND_MASKLO8
:
1481 fields
->f_datahi8
= value
;
1483 case XC16X_OPERAND_MEMGR8
:
1484 fields
->f_memgr8
= value
;
1486 case XC16X_OPERAND_MEMORY
:
1487 fields
->f_memory
= value
;
1489 case XC16X_OPERAND_PAG
:
1491 case XC16X_OPERAND_PAGENUM
:
1492 fields
->f_pagenum
= value
;
1494 case XC16X_OPERAND_POF
:
1496 case XC16X_OPERAND_QBIT
:
1497 fields
->f_qbit
= value
;
1499 case XC16X_OPERAND_QHIBIT
:
1500 fields
->f_qhibit
= value
;
1502 case XC16X_OPERAND_QLOBIT
:
1503 fields
->f_qlobit
= value
;
1505 case XC16X_OPERAND_REG8
:
1506 fields
->f_reg8
= value
;
1508 case XC16X_OPERAND_REGB8
:
1509 fields
->f_regb8
= value
;
1511 case XC16X_OPERAND_REGBMEM8
:
1512 fields
->f_regmem8
= value
;
1514 case XC16X_OPERAND_REGHI8
:
1515 fields
->f_reghi8
= value
;
1517 case XC16X_OPERAND_REGMEM8
:
1518 fields
->f_regmem8
= value
;
1520 case XC16X_OPERAND_REGOFF8
:
1521 fields
->f_regoff8
= value
;
1523 case XC16X_OPERAND_REL
:
1524 fields
->f_rel8
= value
;
1526 case XC16X_OPERAND_RELHI
:
1527 fields
->f_relhi8
= value
;
1529 case XC16X_OPERAND_SEG
:
1530 fields
->f_seg8
= value
;
1532 case XC16X_OPERAND_SEGHI8
:
1533 fields
->f_segnum8
= value
;
1535 case XC16X_OPERAND_SEGM
:
1537 case XC16X_OPERAND_SOF
:
1539 case XC16X_OPERAND_SR
:
1540 fields
->f_r2
= value
;
1542 case XC16X_OPERAND_SR2
:
1543 fields
->f_r0
= value
;
1545 case XC16X_OPERAND_SRB
:
1546 fields
->f_r2
= value
;
1548 case XC16X_OPERAND_SRC1
:
1549 fields
->f_r1
= value
;
1551 case XC16X_OPERAND_SRC2
:
1552 fields
->f_r2
= value
;
1554 case XC16X_OPERAND_SRDIV
:
1555 fields
->f_reg8
= value
;
1557 case XC16X_OPERAND_U4
:
1558 fields
->f_uimm4
= value
;
1560 case XC16X_OPERAND_UIMM16
:
1561 fields
->f_uimm16
= value
;
1563 case XC16X_OPERAND_UIMM2
:
1564 fields
->f_uimm2
= value
;
1566 case XC16X_OPERAND_UIMM3
:
1567 fields
->f_uimm3
= value
;
1569 case XC16X_OPERAND_UIMM4
:
1570 fields
->f_uimm4
= value
;
1572 case XC16X_OPERAND_UIMM7
:
1573 fields
->f_uimm7
= value
;
1575 case XC16X_OPERAND_UIMM8
:
1576 fields
->f_uimm8
= value
;
1578 case XC16X_OPERAND_UPAG16
:
1579 fields
->f_uimm16
= value
;
1581 case XC16X_OPERAND_UPOF16
:
1582 fields
->f_memory
= value
;
1584 case XC16X_OPERAND_USEG16
:
1585 fields
->f_offset16
= value
;
1587 case XC16X_OPERAND_USEG8
:
1588 fields
->f_seg8
= value
;
1590 case XC16X_OPERAND_USOF16
:
1591 fields
->f_offset16
= value
;
1595 /* xgettext:c-format */
1596 fprintf (stderr
, _("Unrecognized field %d while setting int operand.\n"),
1603 xc16x_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
1605 CGEN_FIELDS
* fields
,
1610 case XC16X_OPERAND_REGNAM
:
1611 fields
->f_reg8
= value
;
1613 case XC16X_OPERAND_BIT01
:
1614 fields
->f_op_1bit
= value
;
1616 case XC16X_OPERAND_BIT1
:
1617 fields
->f_op_bit1
= value
;
1619 case XC16X_OPERAND_BIT2
:
1620 fields
->f_op_bit2
= value
;
1622 case XC16X_OPERAND_BIT4
:
1623 fields
->f_op_bit4
= value
;
1625 case XC16X_OPERAND_BIT8
:
1626 fields
->f_op_bit8
= value
;
1628 case XC16X_OPERAND_BITONE
:
1629 fields
->f_op_onebit
= value
;
1631 case XC16X_OPERAND_CADDR
:
1632 fields
->f_offset16
= value
;
1634 case XC16X_OPERAND_COND
:
1635 fields
->f_condcode
= value
;
1637 case XC16X_OPERAND_DATA8
:
1638 fields
->f_data8
= value
;
1640 case XC16X_OPERAND_DATAHI8
:
1641 fields
->f_datahi8
= value
;
1643 case XC16X_OPERAND_DOT
:
1645 case XC16X_OPERAND_DR
:
1646 fields
->f_r1
= value
;
1648 case XC16X_OPERAND_DRB
:
1649 fields
->f_r1
= value
;
1651 case XC16X_OPERAND_DRI
:
1652 fields
->f_r4
= value
;
1654 case XC16X_OPERAND_EXTCOND
:
1655 fields
->f_extccode
= value
;
1657 case XC16X_OPERAND_GENREG
:
1658 fields
->f_regb8
= value
;
1660 case XC16X_OPERAND_HASH
:
1662 case XC16X_OPERAND_ICOND
:
1663 fields
->f_icondcode
= value
;
1665 case XC16X_OPERAND_LBIT2
:
1666 fields
->f_op_lbit2
= value
;
1668 case XC16X_OPERAND_LBIT4
:
1669 fields
->f_op_lbit4
= value
;
1671 case XC16X_OPERAND_MASK8
:
1672 fields
->f_mask8
= value
;
1674 case XC16X_OPERAND_MASKLO8
:
1675 fields
->f_datahi8
= value
;
1677 case XC16X_OPERAND_MEMGR8
:
1678 fields
->f_memgr8
= value
;
1680 case XC16X_OPERAND_MEMORY
:
1681 fields
->f_memory
= value
;
1683 case XC16X_OPERAND_PAG
:
1685 case XC16X_OPERAND_PAGENUM
:
1686 fields
->f_pagenum
= value
;
1688 case XC16X_OPERAND_POF
:
1690 case XC16X_OPERAND_QBIT
:
1691 fields
->f_qbit
= value
;
1693 case XC16X_OPERAND_QHIBIT
:
1694 fields
->f_qhibit
= value
;
1696 case XC16X_OPERAND_QLOBIT
:
1697 fields
->f_qlobit
= value
;
1699 case XC16X_OPERAND_REG8
:
1700 fields
->f_reg8
= value
;
1702 case XC16X_OPERAND_REGB8
:
1703 fields
->f_regb8
= value
;
1705 case XC16X_OPERAND_REGBMEM8
:
1706 fields
->f_regmem8
= value
;
1708 case XC16X_OPERAND_REGHI8
:
1709 fields
->f_reghi8
= value
;
1711 case XC16X_OPERAND_REGMEM8
:
1712 fields
->f_regmem8
= value
;
1714 case XC16X_OPERAND_REGOFF8
:
1715 fields
->f_regoff8
= value
;
1717 case XC16X_OPERAND_REL
:
1718 fields
->f_rel8
= value
;
1720 case XC16X_OPERAND_RELHI
:
1721 fields
->f_relhi8
= value
;
1723 case XC16X_OPERAND_SEG
:
1724 fields
->f_seg8
= value
;
1726 case XC16X_OPERAND_SEGHI8
:
1727 fields
->f_segnum8
= value
;
1729 case XC16X_OPERAND_SEGM
:
1731 case XC16X_OPERAND_SOF
:
1733 case XC16X_OPERAND_SR
:
1734 fields
->f_r2
= value
;
1736 case XC16X_OPERAND_SR2
:
1737 fields
->f_r0
= value
;
1739 case XC16X_OPERAND_SRB
:
1740 fields
->f_r2
= value
;
1742 case XC16X_OPERAND_SRC1
:
1743 fields
->f_r1
= value
;
1745 case XC16X_OPERAND_SRC2
:
1746 fields
->f_r2
= value
;
1748 case XC16X_OPERAND_SRDIV
:
1749 fields
->f_reg8
= value
;
1751 case XC16X_OPERAND_U4
:
1752 fields
->f_uimm4
= value
;
1754 case XC16X_OPERAND_UIMM16
:
1755 fields
->f_uimm16
= value
;
1757 case XC16X_OPERAND_UIMM2
:
1758 fields
->f_uimm2
= value
;
1760 case XC16X_OPERAND_UIMM3
:
1761 fields
->f_uimm3
= value
;
1763 case XC16X_OPERAND_UIMM4
:
1764 fields
->f_uimm4
= value
;
1766 case XC16X_OPERAND_UIMM7
:
1767 fields
->f_uimm7
= value
;
1769 case XC16X_OPERAND_UIMM8
:
1770 fields
->f_uimm8
= value
;
1772 case XC16X_OPERAND_UPAG16
:
1773 fields
->f_uimm16
= value
;
1775 case XC16X_OPERAND_UPOF16
:
1776 fields
->f_memory
= value
;
1778 case XC16X_OPERAND_USEG16
:
1779 fields
->f_offset16
= value
;
1781 case XC16X_OPERAND_USEG8
:
1782 fields
->f_seg8
= value
;
1784 case XC16X_OPERAND_USOF16
:
1785 fields
->f_offset16
= value
;
1789 /* xgettext:c-format */
1790 fprintf (stderr
, _("Unrecognized field %d while setting vma operand.\n"),
1796 /* Function to call before using the instruction builder tables. */
1799 xc16x_cgen_init_ibld_table (CGEN_CPU_DESC cd
)
1801 cd
->insert_handlers
= & xc16x_cgen_insert_handlers
[0];
1802 cd
->extract_handlers
= & xc16x_cgen_extract_handlers
[0];
1804 cd
->insert_operand
= xc16x_cgen_insert_operand
;
1805 cd
->extract_operand
= xc16x_cgen_extract_operand
;
1807 cd
->get_int_operand
= xc16x_cgen_get_int_operand
;
1808 cd
->set_int_operand
= xc16x_cgen_set_int_operand
;
1809 cd
->get_vma_operand
= xc16x_cgen_get_vma_operand
;
1810 cd
->set_vma_operand
= xc16x_cgen_set_vma_operand
;