1 /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
2 /* Instruction building/extraction support for xstormy16. -*- 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-2021 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 "xstormy16-desc.h"
35 #include "xstormy16-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
,
88 unsigned long x
, mask
;
91 x
= cgen_get_insn_value (cd
, bufp
, word_length
, cd
->endian
);
93 /* Written this way to avoid undefined behaviour. */
94 mask
= (1UL << (length
- 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
, cd
->endian
);
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];
136 /* If LENGTH is zero, this operand doesn't contribute to the value. */
140 /* Written this way to avoid undefined behaviour. */
141 mask
= (1UL << (length
- 1) << 1) - 1;
143 if (word_length
> 8 * sizeof (CGEN_INSN_INT
))
146 /* For architectures with insns smaller than the base-insn-bitsize,
147 word_length may be too big. */
148 if (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
)
151 && word_length
> total_length
)
152 word_length
= total_length
;
155 /* Ensure VALUE will fit. */
156 if (CGEN_BOOL_ATTR (attrs
, CGEN_IFLD_SIGN_OPT
))
158 long minval
= - (1UL << (length
- 1));
159 unsigned long maxval
= mask
;
161 if ((value
> 0 && (unsigned long) value
> maxval
)
164 /* xgettext:c-format */
166 _("operand out of range (%ld not between %ld and %lu)"),
167 value
, minval
, maxval
);
171 else if (! CGEN_BOOL_ATTR (attrs
, CGEN_IFLD_SIGNED
))
173 unsigned long maxval
= mask
;
174 unsigned long val
= (unsigned long) value
;
176 /* For hosts with a word size > 32 check to see if value has been sign
177 extended beyond 32 bits. If so then ignore these higher sign bits
178 as the user is attempting to store a 32-bit signed value into an
179 unsigned 32-bit field which is allowed. */
180 if (sizeof (unsigned long) > 4 && ((value
>> 32) == -1))
185 /* xgettext:c-format */
187 _("operand out of range (0x%lx not between 0 and 0x%lx)"),
194 if (! cgen_signed_overflow_ok_p (cd
))
196 long minval
= - (1UL << (length
- 1));
197 long maxval
= (1UL << (length
- 1)) - 1;
199 if (value
< minval
|| value
> maxval
)
202 /* xgettext:c-format */
203 (errbuf
, _("operand out of range (%ld not between %ld and %ld)"),
204 value
, minval
, maxval
);
213 int shift_within_word
, shift_to_word
, shift
;
215 /* How to shift the value to BIT0 of the word. */
216 shift_to_word
= total_length
- (word_offset
+ word_length
);
218 /* How to shift the value to the field within the word. */
219 if (CGEN_INSN_LSB0_P
)
220 shift_within_word
= start
+ 1 - length
;
222 shift_within_word
= word_length
- start
- length
;
224 /* The total SHIFT, then mask in the value. */
225 shift
= shift_to_word
+ shift_within_word
;
226 *buffer
= (*buffer
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
229 #else /* ! CGEN_INT_INSN_P */
232 unsigned char *bufp
= (unsigned char *) buffer
+ word_offset
/ 8;
234 insert_1 (cd
, value
, start
, length
, word_length
, bufp
);
237 #endif /* ! CGEN_INT_INSN_P */
242 /* Default insn builder (insert handler).
243 The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
244 that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
245 recorded in host byte order, otherwise BUFFER is an array of bytes
246 and the value is recorded in target byte order).
247 The result is an error message or NULL if success. */
250 insert_insn_normal (CGEN_CPU_DESC cd
,
251 const CGEN_INSN
* insn
,
252 CGEN_FIELDS
* fields
,
253 CGEN_INSN_BYTES_PTR buffer
,
256 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
258 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
260 CGEN_INIT_INSERT (cd
);
261 value
= CGEN_INSN_BASE_VALUE (insn
);
263 /* If we're recording insns as numbers (rather than a string of bytes),
264 target byte order handling is deferred until later. */
268 put_insn_int_value (cd
, buffer
, cd
->base_insn_bitsize
,
269 CGEN_FIELDS_BITSIZE (fields
), value
);
273 cgen_put_insn_value (cd
, buffer
, min ((unsigned) cd
->base_insn_bitsize
,
274 (unsigned) CGEN_FIELDS_BITSIZE (fields
)),
275 value
, cd
->insn_endian
);
277 #endif /* ! CGEN_INT_INSN_P */
279 /* ??? It would be better to scan the format's fields.
280 Still need to be able to insert a value based on the operand though;
281 e.g. storing a branch displacement that got resolved later.
282 Needs more thought first. */
284 for (syn
= CGEN_SYNTAX_STRING (syntax
); * syn
; ++ syn
)
288 if (CGEN_SYNTAX_CHAR_P (* syn
))
291 errmsg
= (* cd
->insert_operand
) (cd
, CGEN_SYNTAX_FIELD (*syn
),
301 /* Cover function to store an insn value into an integral insn. Must go here
302 because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */
305 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
306 CGEN_INSN_BYTES_PTR buf
,
311 /* For architectures with insns smaller than the base-insn-bitsize,
312 length may be too big. */
313 if (length
> insn_length
)
317 int shift
= insn_length
- length
;
318 /* Written this way to avoid undefined behaviour. */
319 CGEN_INSN_INT mask
= length
== 0 ? 0 : (1UL << (length
- 1) << 1) - 1;
321 *buf
= (*buf
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
326 /* Operand extraction. */
328 #if ! CGEN_INT_INSN_P
330 /* Subroutine of extract_normal.
331 Ensure sufficient bytes are cached in EX_INFO.
332 OFFSET is the offset in bytes from the start of the insn of the value.
333 BYTES is the length of the needed value.
334 Returns 1 for success, 0 for failure. */
336 static CGEN_INLINE
int
337 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
338 CGEN_EXTRACT_INFO
*ex_info
,
343 /* It's doubtful that the middle part has already been fetched so
344 we don't optimize that case. kiss. */
346 disassemble_info
*info
= (disassemble_info
*) ex_info
->dis_info
;
348 /* First do a quick check. */
349 mask
= (1 << bytes
) - 1;
350 if (((ex_info
->valid
>> offset
) & mask
) == mask
)
353 /* Search for the first byte we need to read. */
354 for (mask
= 1 << offset
; bytes
> 0; --bytes
, ++offset
, mask
<<= 1)
355 if (! (mask
& ex_info
->valid
))
363 status
= (*info
->read_memory_func
)
364 (pc
, ex_info
->insn_bytes
+ offset
, bytes
, info
);
368 (*info
->memory_error_func
) (status
, pc
, info
);
372 ex_info
->valid
|= ((1 << bytes
) - 1) << offset
;
378 /* Subroutine of extract_normal. */
380 static CGEN_INLINE
long
381 extract_1 (CGEN_CPU_DESC cd
,
382 CGEN_EXTRACT_INFO
*ex_info ATTRIBUTE_UNUSED
,
387 bfd_vma pc ATTRIBUTE_UNUSED
)
392 x
= cgen_get_insn_value (cd
, bufp
, word_length
, cd
->endian
);
394 if (CGEN_INSN_LSB0_P
)
395 shift
= (start
+ 1) - length
;
397 shift
= (word_length
- (start
+ length
));
401 #endif /* ! CGEN_INT_INSN_P */
403 /* Default extraction routine.
405 INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
406 or sometimes less for cases like the m32r where the base insn size is 32
407 but some insns are 16 bits.
408 ATTRS is a mask of the boolean attributes. We only need `SIGNED',
409 but for generality we take a bitmask of all of them.
410 WORD_OFFSET is the offset in bits from the start of the insn of the value.
411 WORD_LENGTH is the length of the word in bits in which the value resides.
412 START is the starting bit number in the word, architecture origin.
413 LENGTH is the length of VALUE in bits.
414 TOTAL_LENGTH is the total length of the insn in bits.
416 Returns 1 for success, 0 for failure. */
418 /* ??? The return code isn't properly used. wip. */
420 /* ??? This doesn't handle bfd_vma's. Create another function when
424 extract_normal (CGEN_CPU_DESC cd
,
425 #if ! CGEN_INT_INSN_P
426 CGEN_EXTRACT_INFO
*ex_info
,
428 CGEN_EXTRACT_INFO
*ex_info ATTRIBUTE_UNUSED
,
430 CGEN_INSN_INT insn_value
,
432 unsigned int word_offset
,
435 unsigned int word_length
,
436 unsigned int total_length
,
437 #if ! CGEN_INT_INSN_P
440 bfd_vma pc ATTRIBUTE_UNUSED
,
446 /* If LENGTH is zero, this operand doesn't contribute to the value
447 so give it a standard value of zero. */
454 if (word_length
> 8 * sizeof (CGEN_INSN_INT
))
457 /* For architectures with insns smaller than the insn-base-bitsize,
458 word_length may be too big. */
459 if (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
)
461 if (word_offset
+ word_length
> total_length
)
462 word_length
= total_length
- word_offset
;
465 /* Does the value reside in INSN_VALUE, and at the right alignment? */
467 if (CGEN_INT_INSN_P
|| (word_offset
== 0 && word_length
== total_length
))
469 if (CGEN_INSN_LSB0_P
)
470 value
= insn_value
>> ((word_offset
+ start
+ 1) - length
);
472 value
= insn_value
>> (total_length
- ( word_offset
+ start
+ length
));
475 #if ! CGEN_INT_INSN_P
479 unsigned char *bufp
= ex_info
->insn_bytes
+ word_offset
/ 8;
481 if (word_length
> 8 * sizeof (CGEN_INSN_INT
))
484 if (fill_cache (cd
, ex_info
, word_offset
/ 8, word_length
/ 8, pc
) == 0)
490 value
= extract_1 (cd
, ex_info
, start
, length
, word_length
, bufp
, pc
);
493 #endif /* ! CGEN_INT_INSN_P */
495 /* Written this way to avoid undefined behaviour. */
496 mask
= (1UL << (length
- 1) << 1) - 1;
500 if (CGEN_BOOL_ATTR (attrs
, CGEN_IFLD_SIGNED
)
501 && (value
& (1UL << (length
- 1))))
509 /* Default insn extractor.
511 INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
512 The extracted fields are stored in FIELDS.
513 EX_INFO is used to handle reading variable length insns.
514 Return the length of the insn in bits, or 0 if no match,
515 or -1 if an error occurs fetching data (memory_error_func will have
519 extract_insn_normal (CGEN_CPU_DESC cd
,
520 const CGEN_INSN
*insn
,
521 CGEN_EXTRACT_INFO
*ex_info
,
522 CGEN_INSN_INT insn_value
,
526 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
527 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
529 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
531 CGEN_INIT_EXTRACT (cd
);
533 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
537 if (CGEN_SYNTAX_CHAR_P (*syn
))
540 length
= (* cd
->extract_operand
) (cd
, CGEN_SYNTAX_FIELD (*syn
),
541 ex_info
, insn_value
, fields
, pc
);
546 /* We recognized and successfully extracted this insn. */
547 return CGEN_INSN_BITSIZE (insn
);
550 /* Machine generated code added here. */
552 const char * xstormy16_cgen_insert_operand
553 (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, CGEN_INSN_BYTES_PTR
, bfd_vma
);
555 /* Main entry point for operand insertion.
557 This function is basically just a big switch statement. Earlier versions
558 used tables to look up the function to use, but
559 - if the table contains both assembler and disassembler functions then
560 the disassembler contains much of the assembler and vice-versa,
561 - there's a lot of inlining possibilities as things grow,
562 - using a switch statement avoids the function call overhead.
564 This function could be moved into `parse_insn_normal', but keeping it
565 separate makes clear the interface between `parse_insn_normal' and each of
566 the handlers. It's also needed by GAS to insert operands that couldn't be
567 resolved during parsing. */
570 xstormy16_cgen_insert_operand (CGEN_CPU_DESC cd
,
572 CGEN_FIELDS
* fields
,
573 CGEN_INSN_BYTES_PTR buffer
,
574 bfd_vma pc ATTRIBUTE_UNUSED
)
576 const char * errmsg
= NULL
;
577 unsigned int total_length
= CGEN_FIELDS_BITSIZE (fields
);
581 case XSTORMY16_OPERAND_RB
:
582 errmsg
= insert_normal (cd
, fields
->f_Rb
, 0, 0, 17, 3, 32, total_length
, buffer
);
584 case XSTORMY16_OPERAND_RBJ
:
585 errmsg
= insert_normal (cd
, fields
->f_Rbj
, 0, 0, 11, 1, 32, total_length
, buffer
);
587 case XSTORMY16_OPERAND_RD
:
588 errmsg
= insert_normal (cd
, fields
->f_Rd
, 0, 0, 12, 4, 32, total_length
, buffer
);
590 case XSTORMY16_OPERAND_RDM
:
591 errmsg
= insert_normal (cd
, fields
->f_Rdm
, 0, 0, 13, 3, 32, total_length
, buffer
);
593 case XSTORMY16_OPERAND_RM
:
594 errmsg
= insert_normal (cd
, fields
->f_Rm
, 0, 0, 4, 3, 32, total_length
, buffer
);
596 case XSTORMY16_OPERAND_RS
:
597 errmsg
= insert_normal (cd
, fields
->f_Rs
, 0, 0, 8, 4, 32, total_length
, buffer
);
599 case XSTORMY16_OPERAND_ABS24
:
602 FLD (f_abs24_1
) = ((FLD (f_abs24
)) & (255));
603 FLD (f_abs24_2
) = ((UINT
) (FLD (f_abs24
)) >> (8));
605 errmsg
= insert_normal (cd
, fields
->f_abs24_1
, 0, 0, 8, 8, 32, total_length
, buffer
);
608 errmsg
= insert_normal (cd
, fields
->f_abs24_2
, 0, 0, 16, 16, 32, total_length
, buffer
);
613 case XSTORMY16_OPERAND_BCOND2
:
614 errmsg
= insert_normal (cd
, fields
->f_op2
, 0, 0, 4, 4, 32, total_length
, buffer
);
616 case XSTORMY16_OPERAND_BCOND5
:
617 errmsg
= insert_normal (cd
, fields
->f_op5
, 0, 0, 16, 4, 32, total_length
, buffer
);
619 case XSTORMY16_OPERAND_HMEM8
:
621 long value
= fields
->f_hmem8
;
622 value
= ((value
) - (32512));
623 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
626 case XSTORMY16_OPERAND_IMM12
:
627 errmsg
= insert_normal (cd
, fields
->f_imm12
, 0|(1<<CGEN_IFLD_SIGNED
), 0, 20, 12, 32, total_length
, buffer
);
629 case XSTORMY16_OPERAND_IMM16
:
630 errmsg
= insert_normal (cd
, fields
->f_imm16
, 0|(1<<CGEN_IFLD_SIGN_OPT
), 0, 16, 16, 32, total_length
, buffer
);
632 case XSTORMY16_OPERAND_IMM2
:
633 errmsg
= insert_normal (cd
, fields
->f_imm2
, 0, 0, 10, 2, 32, total_length
, buffer
);
635 case XSTORMY16_OPERAND_IMM3
:
636 errmsg
= insert_normal (cd
, fields
->f_imm3
, 0, 0, 4, 3, 32, total_length
, buffer
);
638 case XSTORMY16_OPERAND_IMM3B
:
639 errmsg
= insert_normal (cd
, fields
->f_imm3b
, 0, 0, 17, 3, 32, total_length
, buffer
);
641 case XSTORMY16_OPERAND_IMM4
:
642 errmsg
= insert_normal (cd
, fields
->f_imm4
, 0, 0, 8, 4, 32, total_length
, buffer
);
644 case XSTORMY16_OPERAND_IMM8
:
645 errmsg
= insert_normal (cd
, fields
->f_imm8
, 0, 0, 8, 8, 32, total_length
, buffer
);
647 case XSTORMY16_OPERAND_IMM8SMALL
:
648 errmsg
= insert_normal (cd
, fields
->f_imm8
, 0, 0, 8, 8, 32, total_length
, buffer
);
650 case XSTORMY16_OPERAND_LMEM8
:
651 errmsg
= insert_normal (cd
, fields
->f_lmem8
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
653 case XSTORMY16_OPERAND_REL12
:
655 long value
= fields
->f_rel12
;
656 value
= ((value
) - (((pc
) + (4))));
657 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 20, 12, 32, total_length
, buffer
);
660 case XSTORMY16_OPERAND_REL12A
:
662 long value
= fields
->f_rel12a
;
663 value
= ((SI
) (((value
) - (((pc
) + (2))))) >> (1));
664 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 4, 11, 32, total_length
, buffer
);
667 case XSTORMY16_OPERAND_REL8_2
:
669 long value
= fields
->f_rel8_2
;
670 value
= ((value
) - (((pc
) + (2))));
671 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
674 case XSTORMY16_OPERAND_REL8_4
:
676 long value
= fields
->f_rel8_4
;
677 value
= ((value
) - (((pc
) + (4))));
678 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
681 case XSTORMY16_OPERAND_WS2
:
682 errmsg
= insert_normal (cd
, fields
->f_op2m
, 0, 0, 7, 1, 32, total_length
, buffer
);
686 /* xgettext:c-format */
687 opcodes_error_handler
688 (_("internal error: unrecognized field %d while building insn"),
696 int xstormy16_cgen_extract_operand
697 (CGEN_CPU_DESC
, int, CGEN_EXTRACT_INFO
*, CGEN_INSN_INT
, CGEN_FIELDS
*, bfd_vma
);
699 /* Main entry point for operand extraction.
700 The result is <= 0 for error, >0 for success.
701 ??? Actual values aren't well defined right now.
703 This function is basically just a big switch statement. Earlier versions
704 used tables to look up the function to use, but
705 - if the table contains both assembler and disassembler functions then
706 the disassembler contains much of the assembler and vice-versa,
707 - there's a lot of inlining possibilities as things grow,
708 - using a switch statement avoids the function call overhead.
710 This function could be moved into `print_insn_normal', but keeping it
711 separate makes clear the interface between `print_insn_normal' and each of
715 xstormy16_cgen_extract_operand (CGEN_CPU_DESC cd
,
717 CGEN_EXTRACT_INFO
*ex_info
,
718 CGEN_INSN_INT insn_value
,
719 CGEN_FIELDS
* fields
,
722 /* Assume success (for those operands that are nops). */
724 unsigned int total_length
= CGEN_FIELDS_BITSIZE (fields
);
728 case XSTORMY16_OPERAND_RB
:
729 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 17, 3, 32, total_length
, pc
, & fields
->f_Rb
);
731 case XSTORMY16_OPERAND_RBJ
:
732 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 1, 32, total_length
, pc
, & fields
->f_Rbj
);
734 case XSTORMY16_OPERAND_RD
:
735 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 12, 4, 32, total_length
, pc
, & fields
->f_Rd
);
737 case XSTORMY16_OPERAND_RDM
:
738 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 13, 3, 32, total_length
, pc
, & fields
->f_Rdm
);
740 case XSTORMY16_OPERAND_RM
:
741 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 4, 3, 32, total_length
, pc
, & fields
->f_Rm
);
743 case XSTORMY16_OPERAND_RS
:
744 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 4, 32, total_length
, pc
, & fields
->f_Rs
);
746 case XSTORMY16_OPERAND_ABS24
:
748 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 8, 32, total_length
, pc
, & fields
->f_abs24_1
);
749 if (length
<= 0) break;
750 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 16, 16, 32, total_length
, pc
, & fields
->f_abs24_2
);
751 if (length
<= 0) break;
752 FLD (f_abs24
) = ((((FLD (f_abs24_2
)) << (8))) | (FLD (f_abs24_1
)));
755 case XSTORMY16_OPERAND_BCOND2
:
756 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 4, 4, 32, total_length
, pc
, & fields
->f_op2
);
758 case XSTORMY16_OPERAND_BCOND5
:
759 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 16, 4, 32, total_length
, pc
, & fields
->f_op5
);
761 case XSTORMY16_OPERAND_HMEM8
:
764 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, pc
, & value
);
765 value
= ((value
) + (32512));
766 fields
->f_hmem8
= value
;
769 case XSTORMY16_OPERAND_IMM12
:
770 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGNED
), 0, 20, 12, 32, total_length
, pc
, & fields
->f_imm12
);
772 case XSTORMY16_OPERAND_IMM16
:
773 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGN_OPT
), 0, 16, 16, 32, total_length
, pc
, & fields
->f_imm16
);
775 case XSTORMY16_OPERAND_IMM2
:
776 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 10, 2, 32, total_length
, pc
, & fields
->f_imm2
);
778 case XSTORMY16_OPERAND_IMM3
:
779 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 4, 3, 32, total_length
, pc
, & fields
->f_imm3
);
781 case XSTORMY16_OPERAND_IMM3B
:
782 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 17, 3, 32, total_length
, pc
, & fields
->f_imm3b
);
784 case XSTORMY16_OPERAND_IMM4
:
785 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 4, 32, total_length
, pc
, & fields
->f_imm4
);
787 case XSTORMY16_OPERAND_IMM8
:
788 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 8, 32, total_length
, pc
, & fields
->f_imm8
);
790 case XSTORMY16_OPERAND_IMM8SMALL
:
791 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 8, 32, total_length
, pc
, & fields
->f_imm8
);
793 case XSTORMY16_OPERAND_LMEM8
:
794 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, pc
, & fields
->f_lmem8
);
796 case XSTORMY16_OPERAND_REL12
:
799 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 20, 12, 32, total_length
, pc
, & value
);
800 value
= ((value
) + (((pc
) + (4))));
801 fields
->f_rel12
= value
;
804 case XSTORMY16_OPERAND_REL12A
:
807 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 4, 11, 32, total_length
, pc
, & value
);
808 value
= ((((value
) * (2))) + (((pc
) + (2))));
809 fields
->f_rel12a
= value
;
812 case XSTORMY16_OPERAND_REL8_2
:
815 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 8, 8, 32, total_length
, pc
, & value
);
816 value
= ((value
) + (((pc
) + (2))));
817 fields
->f_rel8_2
= value
;
820 case XSTORMY16_OPERAND_REL8_4
:
823 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 8, 8, 32, total_length
, pc
, & value
);
824 value
= ((value
) + (((pc
) + (4))));
825 fields
->f_rel8_4
= value
;
828 case XSTORMY16_OPERAND_WS2
:
829 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 7, 1, 32, total_length
, pc
, & fields
->f_op2m
);
833 /* xgettext:c-format */
834 opcodes_error_handler
835 (_("internal error: unrecognized field %d while decoding insn"),
843 cgen_insert_fn
* const xstormy16_cgen_insert_handlers
[] =
848 cgen_extract_fn
* const xstormy16_cgen_extract_handlers
[] =
853 int xstormy16_cgen_get_int_operand (CGEN_CPU_DESC
, int, const CGEN_FIELDS
*);
854 bfd_vma
xstormy16_cgen_get_vma_operand (CGEN_CPU_DESC
, int, const CGEN_FIELDS
*);
856 /* Getting values from cgen_fields is handled by a collection of functions.
857 They are distinguished by the type of the VALUE argument they return.
858 TODO: floating point, inlining support, remove cases where result type
862 xstormy16_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
864 const CGEN_FIELDS
* fields
)
870 case XSTORMY16_OPERAND_RB
:
871 value
= fields
->f_Rb
;
873 case XSTORMY16_OPERAND_RBJ
:
874 value
= fields
->f_Rbj
;
876 case XSTORMY16_OPERAND_RD
:
877 value
= fields
->f_Rd
;
879 case XSTORMY16_OPERAND_RDM
:
880 value
= fields
->f_Rdm
;
882 case XSTORMY16_OPERAND_RM
:
883 value
= fields
->f_Rm
;
885 case XSTORMY16_OPERAND_RS
:
886 value
= fields
->f_Rs
;
888 case XSTORMY16_OPERAND_ABS24
:
889 value
= fields
->f_abs24
;
891 case XSTORMY16_OPERAND_BCOND2
:
892 value
= fields
->f_op2
;
894 case XSTORMY16_OPERAND_BCOND5
:
895 value
= fields
->f_op5
;
897 case XSTORMY16_OPERAND_HMEM8
:
898 value
= fields
->f_hmem8
;
900 case XSTORMY16_OPERAND_IMM12
:
901 value
= fields
->f_imm12
;
903 case XSTORMY16_OPERAND_IMM16
:
904 value
= fields
->f_imm16
;
906 case XSTORMY16_OPERAND_IMM2
:
907 value
= fields
->f_imm2
;
909 case XSTORMY16_OPERAND_IMM3
:
910 value
= fields
->f_imm3
;
912 case XSTORMY16_OPERAND_IMM3B
:
913 value
= fields
->f_imm3b
;
915 case XSTORMY16_OPERAND_IMM4
:
916 value
= fields
->f_imm4
;
918 case XSTORMY16_OPERAND_IMM8
:
919 value
= fields
->f_imm8
;
921 case XSTORMY16_OPERAND_IMM8SMALL
:
922 value
= fields
->f_imm8
;
924 case XSTORMY16_OPERAND_LMEM8
:
925 value
= fields
->f_lmem8
;
927 case XSTORMY16_OPERAND_REL12
:
928 value
= fields
->f_rel12
;
930 case XSTORMY16_OPERAND_REL12A
:
931 value
= fields
->f_rel12a
;
933 case XSTORMY16_OPERAND_REL8_2
:
934 value
= fields
->f_rel8_2
;
936 case XSTORMY16_OPERAND_REL8_4
:
937 value
= fields
->f_rel8_4
;
939 case XSTORMY16_OPERAND_WS2
:
940 value
= fields
->f_op2m
;
944 /* xgettext:c-format */
945 opcodes_error_handler
946 (_("internal error: unrecognized field %d while getting int operand"),
955 xstormy16_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
957 const CGEN_FIELDS
* fields
)
963 case XSTORMY16_OPERAND_RB
:
964 value
= fields
->f_Rb
;
966 case XSTORMY16_OPERAND_RBJ
:
967 value
= fields
->f_Rbj
;
969 case XSTORMY16_OPERAND_RD
:
970 value
= fields
->f_Rd
;
972 case XSTORMY16_OPERAND_RDM
:
973 value
= fields
->f_Rdm
;
975 case XSTORMY16_OPERAND_RM
:
976 value
= fields
->f_Rm
;
978 case XSTORMY16_OPERAND_RS
:
979 value
= fields
->f_Rs
;
981 case XSTORMY16_OPERAND_ABS24
:
982 value
= fields
->f_abs24
;
984 case XSTORMY16_OPERAND_BCOND2
:
985 value
= fields
->f_op2
;
987 case XSTORMY16_OPERAND_BCOND5
:
988 value
= fields
->f_op5
;
990 case XSTORMY16_OPERAND_HMEM8
:
991 value
= fields
->f_hmem8
;
993 case XSTORMY16_OPERAND_IMM12
:
994 value
= fields
->f_imm12
;
996 case XSTORMY16_OPERAND_IMM16
:
997 value
= fields
->f_imm16
;
999 case XSTORMY16_OPERAND_IMM2
:
1000 value
= fields
->f_imm2
;
1002 case XSTORMY16_OPERAND_IMM3
:
1003 value
= fields
->f_imm3
;
1005 case XSTORMY16_OPERAND_IMM3B
:
1006 value
= fields
->f_imm3b
;
1008 case XSTORMY16_OPERAND_IMM4
:
1009 value
= fields
->f_imm4
;
1011 case XSTORMY16_OPERAND_IMM8
:
1012 value
= fields
->f_imm8
;
1014 case XSTORMY16_OPERAND_IMM8SMALL
:
1015 value
= fields
->f_imm8
;
1017 case XSTORMY16_OPERAND_LMEM8
:
1018 value
= fields
->f_lmem8
;
1020 case XSTORMY16_OPERAND_REL12
:
1021 value
= fields
->f_rel12
;
1023 case XSTORMY16_OPERAND_REL12A
:
1024 value
= fields
->f_rel12a
;
1026 case XSTORMY16_OPERAND_REL8_2
:
1027 value
= fields
->f_rel8_2
;
1029 case XSTORMY16_OPERAND_REL8_4
:
1030 value
= fields
->f_rel8_4
;
1032 case XSTORMY16_OPERAND_WS2
:
1033 value
= fields
->f_op2m
;
1037 /* xgettext:c-format */
1038 opcodes_error_handler
1039 (_("internal error: unrecognized field %d while getting vma operand"),
1047 void xstormy16_cgen_set_int_operand (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, int);
1048 void xstormy16_cgen_set_vma_operand (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, bfd_vma
);
1050 /* Stuffing values in cgen_fields is handled by a collection of functions.
1051 They are distinguished by the type of the VALUE argument they accept.
1052 TODO: floating point, inlining support, remove cases where argument type
1056 xstormy16_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
1058 CGEN_FIELDS
* fields
,
1063 case XSTORMY16_OPERAND_RB
:
1064 fields
->f_Rb
= value
;
1066 case XSTORMY16_OPERAND_RBJ
:
1067 fields
->f_Rbj
= value
;
1069 case XSTORMY16_OPERAND_RD
:
1070 fields
->f_Rd
= value
;
1072 case XSTORMY16_OPERAND_RDM
:
1073 fields
->f_Rdm
= value
;
1075 case XSTORMY16_OPERAND_RM
:
1076 fields
->f_Rm
= value
;
1078 case XSTORMY16_OPERAND_RS
:
1079 fields
->f_Rs
= value
;
1081 case XSTORMY16_OPERAND_ABS24
:
1082 fields
->f_abs24
= value
;
1084 case XSTORMY16_OPERAND_BCOND2
:
1085 fields
->f_op2
= value
;
1087 case XSTORMY16_OPERAND_BCOND5
:
1088 fields
->f_op5
= value
;
1090 case XSTORMY16_OPERAND_HMEM8
:
1091 fields
->f_hmem8
= value
;
1093 case XSTORMY16_OPERAND_IMM12
:
1094 fields
->f_imm12
= value
;
1096 case XSTORMY16_OPERAND_IMM16
:
1097 fields
->f_imm16
= value
;
1099 case XSTORMY16_OPERAND_IMM2
:
1100 fields
->f_imm2
= value
;
1102 case XSTORMY16_OPERAND_IMM3
:
1103 fields
->f_imm3
= value
;
1105 case XSTORMY16_OPERAND_IMM3B
:
1106 fields
->f_imm3b
= value
;
1108 case XSTORMY16_OPERAND_IMM4
:
1109 fields
->f_imm4
= value
;
1111 case XSTORMY16_OPERAND_IMM8
:
1112 fields
->f_imm8
= value
;
1114 case XSTORMY16_OPERAND_IMM8SMALL
:
1115 fields
->f_imm8
= value
;
1117 case XSTORMY16_OPERAND_LMEM8
:
1118 fields
->f_lmem8
= value
;
1120 case XSTORMY16_OPERAND_REL12
:
1121 fields
->f_rel12
= value
;
1123 case XSTORMY16_OPERAND_REL12A
:
1124 fields
->f_rel12a
= value
;
1126 case XSTORMY16_OPERAND_REL8_2
:
1127 fields
->f_rel8_2
= value
;
1129 case XSTORMY16_OPERAND_REL8_4
:
1130 fields
->f_rel8_4
= value
;
1132 case XSTORMY16_OPERAND_WS2
:
1133 fields
->f_op2m
= value
;
1137 /* xgettext:c-format */
1138 opcodes_error_handler
1139 (_("internal error: unrecognized field %d while setting int operand"),
1146 xstormy16_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
1148 CGEN_FIELDS
* fields
,
1153 case XSTORMY16_OPERAND_RB
:
1154 fields
->f_Rb
= value
;
1156 case XSTORMY16_OPERAND_RBJ
:
1157 fields
->f_Rbj
= value
;
1159 case XSTORMY16_OPERAND_RD
:
1160 fields
->f_Rd
= value
;
1162 case XSTORMY16_OPERAND_RDM
:
1163 fields
->f_Rdm
= value
;
1165 case XSTORMY16_OPERAND_RM
:
1166 fields
->f_Rm
= value
;
1168 case XSTORMY16_OPERAND_RS
:
1169 fields
->f_Rs
= value
;
1171 case XSTORMY16_OPERAND_ABS24
:
1172 fields
->f_abs24
= value
;
1174 case XSTORMY16_OPERAND_BCOND2
:
1175 fields
->f_op2
= value
;
1177 case XSTORMY16_OPERAND_BCOND5
:
1178 fields
->f_op5
= value
;
1180 case XSTORMY16_OPERAND_HMEM8
:
1181 fields
->f_hmem8
= value
;
1183 case XSTORMY16_OPERAND_IMM12
:
1184 fields
->f_imm12
= value
;
1186 case XSTORMY16_OPERAND_IMM16
:
1187 fields
->f_imm16
= value
;
1189 case XSTORMY16_OPERAND_IMM2
:
1190 fields
->f_imm2
= value
;
1192 case XSTORMY16_OPERAND_IMM3
:
1193 fields
->f_imm3
= value
;
1195 case XSTORMY16_OPERAND_IMM3B
:
1196 fields
->f_imm3b
= value
;
1198 case XSTORMY16_OPERAND_IMM4
:
1199 fields
->f_imm4
= value
;
1201 case XSTORMY16_OPERAND_IMM8
:
1202 fields
->f_imm8
= value
;
1204 case XSTORMY16_OPERAND_IMM8SMALL
:
1205 fields
->f_imm8
= value
;
1207 case XSTORMY16_OPERAND_LMEM8
:
1208 fields
->f_lmem8
= value
;
1210 case XSTORMY16_OPERAND_REL12
:
1211 fields
->f_rel12
= value
;
1213 case XSTORMY16_OPERAND_REL12A
:
1214 fields
->f_rel12a
= value
;
1216 case XSTORMY16_OPERAND_REL8_2
:
1217 fields
->f_rel8_2
= value
;
1219 case XSTORMY16_OPERAND_REL8_4
:
1220 fields
->f_rel8_4
= value
;
1222 case XSTORMY16_OPERAND_WS2
:
1223 fields
->f_op2m
= value
;
1227 /* xgettext:c-format */
1228 opcodes_error_handler
1229 (_("internal error: unrecognized field %d while setting vma operand"),
1235 /* Function to call before using the instruction builder tables. */
1238 xstormy16_cgen_init_ibld_table (CGEN_CPU_DESC cd
)
1240 cd
->insert_handlers
= & xstormy16_cgen_insert_handlers
[0];
1241 cd
->extract_handlers
= & xstormy16_cgen_extract_handlers
[0];
1243 cd
->insert_operand
= xstormy16_cgen_insert_operand
;
1244 cd
->extract_operand
= xstormy16_cgen_extract_operand
;
1246 cd
->get_int_operand
= xstormy16_cgen_get_int_operand
;
1247 cd
->set_int_operand
= xstormy16_cgen_set_int_operand
;
1248 cd
->get_vma_operand
= xstormy16_cgen_get_vma_operand
;
1249 cd
->set_vma_operand
= xstormy16_cgen_set_vma_operand
;