1 /* Instruction building/extraction support for xstormy16. -*- 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 1996, 1997, 1998, 1999, 2000, 2001, 2005
7 Free Software Foundation, Inc.
9 This file is part of the GNU Binutils and GDB, the GNU debugger.
11 This program 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 2, or (at your option)
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public 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"
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
> 32)
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
;
172 if ((unsigned long) value
> maxval
)
174 /* xgettext:c-format */
176 _("operand out of range (%lu not between 0 and %lu)"),
183 if (! cgen_signed_overflow_ok_p (cd
))
185 long minval
= - (1L << (length
- 1));
186 long maxval
= (1L << (length
- 1)) - 1;
188 if (value
< minval
|| value
> maxval
)
191 /* xgettext:c-format */
192 (errbuf
, _("operand out of range (%ld not between %ld and %ld)"),
193 value
, minval
, maxval
);
204 if (CGEN_INSN_LSB0_P
)
205 shift
= (word_offset
+ start
+ 1) - length
;
207 shift
= total_length
- (word_offset
+ start
+ length
);
208 *buffer
= (*buffer
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
211 #else /* ! CGEN_INT_INSN_P */
214 unsigned char *bufp
= (unsigned char *) buffer
+ word_offset
/ 8;
216 insert_1 (cd
, value
, start
, length
, word_length
, bufp
);
219 #endif /* ! CGEN_INT_INSN_P */
224 /* Default insn builder (insert handler).
225 The instruction is recorded in CGEN_INT_INSN_P byte order (meaning
226 that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is
227 recorded in host byte order, otherwise BUFFER is an array of bytes
228 and the value is recorded in target byte order).
229 The result is an error message or NULL if success. */
232 insert_insn_normal (CGEN_CPU_DESC cd
,
233 const CGEN_INSN
* insn
,
234 CGEN_FIELDS
* fields
,
235 CGEN_INSN_BYTES_PTR buffer
,
238 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
240 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
242 CGEN_INIT_INSERT (cd
);
243 value
= CGEN_INSN_BASE_VALUE (insn
);
245 /* If we're recording insns as numbers (rather than a string of bytes),
246 target byte order handling is deferred until later. */
250 put_insn_int_value (cd
, buffer
, cd
->base_insn_bitsize
,
251 CGEN_FIELDS_BITSIZE (fields
), value
);
255 cgen_put_insn_value (cd
, buffer
, min ((unsigned) cd
->base_insn_bitsize
,
256 (unsigned) CGEN_FIELDS_BITSIZE (fields
)),
259 #endif /* ! CGEN_INT_INSN_P */
261 /* ??? It would be better to scan the format's fields.
262 Still need to be able to insert a value based on the operand though;
263 e.g. storing a branch displacement that got resolved later.
264 Needs more thought first. */
266 for (syn
= CGEN_SYNTAX_STRING (syntax
); * syn
; ++ syn
)
270 if (CGEN_SYNTAX_CHAR_P (* syn
))
273 errmsg
= (* cd
->insert_operand
) (cd
, CGEN_SYNTAX_FIELD (*syn
),
283 /* Cover function to store an insn value into an integral insn. Must go here
284 because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */
287 put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
288 CGEN_INSN_BYTES_PTR buf
,
293 /* For architectures with insns smaller than the base-insn-bitsize,
294 length may be too big. */
295 if (length
> insn_length
)
299 int shift
= insn_length
- length
;
300 /* Written this way to avoid undefined behaviour. */
301 CGEN_INSN_INT mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
303 *buf
= (*buf
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
308 /* Operand extraction. */
310 #if ! CGEN_INT_INSN_P
312 /* Subroutine of extract_normal.
313 Ensure sufficient bytes are cached in EX_INFO.
314 OFFSET is the offset in bytes from the start of the insn of the value.
315 BYTES is the length of the needed value.
316 Returns 1 for success, 0 for failure. */
318 static CGEN_INLINE
int
319 fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
320 CGEN_EXTRACT_INFO
*ex_info
,
325 /* It's doubtful that the middle part has already been fetched so
326 we don't optimize that case. kiss. */
328 disassemble_info
*info
= (disassemble_info
*) ex_info
->dis_info
;
330 /* First do a quick check. */
331 mask
= (1 << bytes
) - 1;
332 if (((ex_info
->valid
>> offset
) & mask
) == mask
)
335 /* Search for the first byte we need to read. */
336 for (mask
= 1 << offset
; bytes
> 0; --bytes
, ++offset
, mask
<<= 1)
337 if (! (mask
& ex_info
->valid
))
345 status
= (*info
->read_memory_func
)
346 (pc
, ex_info
->insn_bytes
+ offset
, bytes
, info
);
350 (*info
->memory_error_func
) (status
, pc
, info
);
354 ex_info
->valid
|= ((1 << bytes
) - 1) << offset
;
360 /* Subroutine of extract_normal. */
362 static CGEN_INLINE
long
363 extract_1 (CGEN_CPU_DESC cd
,
364 CGEN_EXTRACT_INFO
*ex_info ATTRIBUTE_UNUSED
,
369 bfd_vma pc ATTRIBUTE_UNUSED
)
374 x
= cgen_get_insn_value (cd
, bufp
, word_length
);
376 if (CGEN_INSN_LSB0_P
)
377 shift
= (start
+ 1) - length
;
379 shift
= (word_length
- (start
+ length
));
383 #endif /* ! CGEN_INT_INSN_P */
385 /* Default extraction routine.
387 INSN_VALUE is the first base_insn_bitsize bits of the insn in host order,
388 or sometimes less for cases like the m32r where the base insn size is 32
389 but some insns are 16 bits.
390 ATTRS is a mask of the boolean attributes. We only need `SIGNED',
391 but for generality we take a bitmask of all of them.
392 WORD_OFFSET is the offset in bits from the start of the insn of the value.
393 WORD_LENGTH is the length of the word in bits in which the value resides.
394 START is the starting bit number in the word, architecture origin.
395 LENGTH is the length of VALUE in bits.
396 TOTAL_LENGTH is the total length of the insn in bits.
398 Returns 1 for success, 0 for failure. */
400 /* ??? The return code isn't properly used. wip. */
402 /* ??? This doesn't handle bfd_vma's. Create another function when
406 extract_normal (CGEN_CPU_DESC cd
,
407 #if ! CGEN_INT_INSN_P
408 CGEN_EXTRACT_INFO
*ex_info
,
410 CGEN_EXTRACT_INFO
*ex_info ATTRIBUTE_UNUSED
,
412 CGEN_INSN_INT insn_value
,
414 unsigned int word_offset
,
417 unsigned int word_length
,
418 unsigned int total_length
,
419 #if ! CGEN_INT_INSN_P
422 bfd_vma pc ATTRIBUTE_UNUSED
,
428 /* If LENGTH is zero, this operand doesn't contribute to the value
429 so give it a standard value of zero. */
436 if (word_length
> 32)
439 /* For architectures with insns smaller than the insn-base-bitsize,
440 word_length may be too big. */
441 if (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
)
444 && word_length
> total_length
)
445 word_length
= total_length
;
448 /* Does the value reside in INSN_VALUE, and at the right alignment? */
450 if (CGEN_INT_INSN_P
|| (word_offset
== 0 && word_length
== total_length
))
452 if (CGEN_INSN_LSB0_P
)
453 value
= insn_value
>> ((word_offset
+ start
+ 1) - length
);
455 value
= insn_value
>> (total_length
- ( word_offset
+ start
+ length
));
458 #if ! CGEN_INT_INSN_P
462 unsigned char *bufp
= ex_info
->insn_bytes
+ word_offset
/ 8;
464 if (word_length
> 32)
467 if (fill_cache (cd
, ex_info
, word_offset
/ 8, word_length
/ 8, pc
) == 0)
470 value
= extract_1 (cd
, ex_info
, start
, length
, word_length
, bufp
, pc
);
473 #endif /* ! CGEN_INT_INSN_P */
475 /* Written this way to avoid undefined behaviour. */
476 mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
480 if (CGEN_BOOL_ATTR (attrs
, CGEN_IFLD_SIGNED
)
481 && (value
& (1L << (length
- 1))))
489 /* Default insn extractor.
491 INSN_VALUE is the first base_insn_bitsize bits, translated to host order.
492 The extracted fields are stored in FIELDS.
493 EX_INFO is used to handle reading variable length insns.
494 Return the length of the insn in bits, or 0 if no match,
495 or -1 if an error occurs fetching data (memory_error_func will have
499 extract_insn_normal (CGEN_CPU_DESC cd
,
500 const CGEN_INSN
*insn
,
501 CGEN_EXTRACT_INFO
*ex_info
,
502 CGEN_INSN_INT insn_value
,
506 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
507 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
509 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
511 CGEN_INIT_EXTRACT (cd
);
513 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
517 if (CGEN_SYNTAX_CHAR_P (*syn
))
520 length
= (* cd
->extract_operand
) (cd
, CGEN_SYNTAX_FIELD (*syn
),
521 ex_info
, insn_value
, fields
, pc
);
526 /* We recognized and successfully extracted this insn. */
527 return CGEN_INSN_BITSIZE (insn
);
530 /* Machine generated code added here. */
532 const char * xstormy16_cgen_insert_operand
533 (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, CGEN_INSN_BYTES_PTR
, bfd_vma
);
535 /* Main entry point for operand insertion.
537 This function is basically just a big switch statement. Earlier versions
538 used tables to look up the function to use, but
539 - if the table contains both assembler and disassembler functions then
540 the disassembler contains much of the assembler and vice-versa,
541 - there's a lot of inlining possibilities as things grow,
542 - using a switch statement avoids the function call overhead.
544 This function could be moved into `parse_insn_normal', but keeping it
545 separate makes clear the interface between `parse_insn_normal' and each of
546 the handlers. It's also needed by GAS to insert operands that couldn't be
547 resolved during parsing. */
550 xstormy16_cgen_insert_operand (CGEN_CPU_DESC cd
,
552 CGEN_FIELDS
* fields
,
553 CGEN_INSN_BYTES_PTR buffer
,
554 bfd_vma pc ATTRIBUTE_UNUSED
)
556 const char * errmsg
= NULL
;
557 unsigned int total_length
= CGEN_FIELDS_BITSIZE (fields
);
561 case XSTORMY16_OPERAND_RB
:
562 errmsg
= insert_normal (cd
, fields
->f_Rb
, 0, 0, 17, 3, 32, total_length
, buffer
);
564 case XSTORMY16_OPERAND_RBJ
:
565 errmsg
= insert_normal (cd
, fields
->f_Rbj
, 0, 0, 11, 1, 32, total_length
, buffer
);
567 case XSTORMY16_OPERAND_RD
:
568 errmsg
= insert_normal (cd
, fields
->f_Rd
, 0, 0, 12, 4, 32, total_length
, buffer
);
570 case XSTORMY16_OPERAND_RDM
:
571 errmsg
= insert_normal (cd
, fields
->f_Rdm
, 0, 0, 13, 3, 32, total_length
, buffer
);
573 case XSTORMY16_OPERAND_RM
:
574 errmsg
= insert_normal (cd
, fields
->f_Rm
, 0, 0, 4, 3, 32, total_length
, buffer
);
576 case XSTORMY16_OPERAND_RS
:
577 errmsg
= insert_normal (cd
, fields
->f_Rs
, 0, 0, 8, 4, 32, total_length
, buffer
);
579 case XSTORMY16_OPERAND_ABS24
:
582 FLD (f_abs24_1
) = ((FLD (f_abs24
)) & (255));
583 FLD (f_abs24_2
) = ((unsigned int) (FLD (f_abs24
)) >> (8));
585 errmsg
= insert_normal (cd
, fields
->f_abs24_1
, 0, 0, 8, 8, 32, total_length
, buffer
);
588 errmsg
= insert_normal (cd
, fields
->f_abs24_2
, 0, 0, 16, 16, 32, total_length
, buffer
);
593 case XSTORMY16_OPERAND_BCOND2
:
594 errmsg
= insert_normal (cd
, fields
->f_op2
, 0, 0, 4, 4, 32, total_length
, buffer
);
596 case XSTORMY16_OPERAND_BCOND5
:
597 errmsg
= insert_normal (cd
, fields
->f_op5
, 0, 0, 16, 4, 32, total_length
, buffer
);
599 case XSTORMY16_OPERAND_HMEM8
:
601 long value
= fields
->f_hmem8
;
602 value
= ((value
) - (32512));
603 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
606 case XSTORMY16_OPERAND_IMM12
:
607 errmsg
= insert_normal (cd
, fields
->f_imm12
, 0|(1<<CGEN_IFLD_SIGNED
), 0, 20, 12, 32, total_length
, buffer
);
609 case XSTORMY16_OPERAND_IMM16
:
610 errmsg
= insert_normal (cd
, fields
->f_imm16
, 0|(1<<CGEN_IFLD_SIGN_OPT
), 0, 16, 16, 32, total_length
, buffer
);
612 case XSTORMY16_OPERAND_IMM2
:
613 errmsg
= insert_normal (cd
, fields
->f_imm2
, 0, 0, 10, 2, 32, total_length
, buffer
);
615 case XSTORMY16_OPERAND_IMM3
:
616 errmsg
= insert_normal (cd
, fields
->f_imm3
, 0, 0, 4, 3, 32, total_length
, buffer
);
618 case XSTORMY16_OPERAND_IMM3B
:
619 errmsg
= insert_normal (cd
, fields
->f_imm3b
, 0, 0, 17, 3, 32, total_length
, buffer
);
621 case XSTORMY16_OPERAND_IMM4
:
622 errmsg
= insert_normal (cd
, fields
->f_imm4
, 0, 0, 8, 4, 32, total_length
, buffer
);
624 case XSTORMY16_OPERAND_IMM8
:
625 errmsg
= insert_normal (cd
, fields
->f_imm8
, 0, 0, 8, 8, 32, total_length
, buffer
);
627 case XSTORMY16_OPERAND_IMM8SMALL
:
628 errmsg
= insert_normal (cd
, fields
->f_imm8
, 0, 0, 8, 8, 32, total_length
, buffer
);
630 case XSTORMY16_OPERAND_LMEM8
:
631 errmsg
= insert_normal (cd
, fields
->f_lmem8
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
633 case XSTORMY16_OPERAND_REL12
:
635 long value
= fields
->f_rel12
;
636 value
= ((value
) - (((pc
) + (4))));
637 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 20, 12, 32, total_length
, buffer
);
640 case XSTORMY16_OPERAND_REL12A
:
642 long value
= fields
->f_rel12a
;
643 value
= ((int) (((value
) - (((pc
) + (2))))) >> (1));
644 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 4, 11, 32, total_length
, buffer
);
647 case XSTORMY16_OPERAND_REL8_2
:
649 long value
= fields
->f_rel8_2
;
650 value
= ((value
) - (((pc
) + (2))));
651 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
654 case XSTORMY16_OPERAND_REL8_4
:
656 long value
= fields
->f_rel8_4
;
657 value
= ((value
) - (((pc
) + (4))));
658 errmsg
= insert_normal (cd
, value
, 0|(1<<CGEN_IFLD_SIGNED
)|(1<<CGEN_IFLD_PCREL_ADDR
), 0, 8, 8, 32, total_length
, buffer
);
661 case XSTORMY16_OPERAND_WS2
:
662 errmsg
= insert_normal (cd
, fields
->f_op2m
, 0, 0, 7, 1, 32, total_length
, buffer
);
666 /* xgettext:c-format */
667 fprintf (stderr
, _("Unrecognized field %d while building insn.\n"),
675 int xstormy16_cgen_extract_operand
676 (CGEN_CPU_DESC
, int, CGEN_EXTRACT_INFO
*, CGEN_INSN_INT
, CGEN_FIELDS
*, bfd_vma
);
678 /* Main entry point for operand extraction.
679 The result is <= 0 for error, >0 for success.
680 ??? Actual values aren't well defined right now.
682 This function is basically just a big switch statement. Earlier versions
683 used tables to look up the function to use, but
684 - if the table contains both assembler and disassembler functions then
685 the disassembler contains much of the assembler and vice-versa,
686 - there's a lot of inlining possibilities as things grow,
687 - using a switch statement avoids the function call overhead.
689 This function could be moved into `print_insn_normal', but keeping it
690 separate makes clear the interface between `print_insn_normal' and each of
694 xstormy16_cgen_extract_operand (CGEN_CPU_DESC cd
,
696 CGEN_EXTRACT_INFO
*ex_info
,
697 CGEN_INSN_INT insn_value
,
698 CGEN_FIELDS
* fields
,
701 /* Assume success (for those operands that are nops). */
703 unsigned int total_length
= CGEN_FIELDS_BITSIZE (fields
);
707 case XSTORMY16_OPERAND_RB
:
708 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 17, 3, 32, total_length
, pc
, & fields
->f_Rb
);
710 case XSTORMY16_OPERAND_RBJ
:
711 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 11, 1, 32, total_length
, pc
, & fields
->f_Rbj
);
713 case XSTORMY16_OPERAND_RD
:
714 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 12, 4, 32, total_length
, pc
, & fields
->f_Rd
);
716 case XSTORMY16_OPERAND_RDM
:
717 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 13, 3, 32, total_length
, pc
, & fields
->f_Rdm
);
719 case XSTORMY16_OPERAND_RM
:
720 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 4, 3, 32, total_length
, pc
, & fields
->f_Rm
);
722 case XSTORMY16_OPERAND_RS
:
723 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 4, 32, total_length
, pc
, & fields
->f_Rs
);
725 case XSTORMY16_OPERAND_ABS24
:
727 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 8, 32, total_length
, pc
, & fields
->f_abs24_1
);
728 if (length
<= 0) break;
729 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 16, 16, 32, total_length
, pc
, & fields
->f_abs24_2
);
730 if (length
<= 0) break;
731 FLD (f_abs24
) = ((((FLD (f_abs24_2
)) << (8))) | (FLD (f_abs24_1
)));
734 case XSTORMY16_OPERAND_BCOND2
:
735 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 4, 4, 32, total_length
, pc
, & fields
->f_op2
);
737 case XSTORMY16_OPERAND_BCOND5
:
738 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 16, 4, 32, total_length
, pc
, & fields
->f_op5
);
740 case XSTORMY16_OPERAND_HMEM8
:
743 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, pc
, & value
);
744 value
= ((value
) + (32512));
745 fields
->f_hmem8
= value
;
748 case XSTORMY16_OPERAND_IMM12
:
749 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGNED
), 0, 20, 12, 32, total_length
, pc
, & fields
->f_imm12
);
751 case XSTORMY16_OPERAND_IMM16
:
752 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_SIGN_OPT
), 0, 16, 16, 32, total_length
, pc
, & fields
->f_imm16
);
754 case XSTORMY16_OPERAND_IMM2
:
755 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 10, 2, 32, total_length
, pc
, & fields
->f_imm2
);
757 case XSTORMY16_OPERAND_IMM3
:
758 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 4, 3, 32, total_length
, pc
, & fields
->f_imm3
);
760 case XSTORMY16_OPERAND_IMM3B
:
761 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 17, 3, 32, total_length
, pc
, & fields
->f_imm3b
);
763 case XSTORMY16_OPERAND_IMM4
:
764 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 4, 32, total_length
, pc
, & fields
->f_imm4
);
766 case XSTORMY16_OPERAND_IMM8
:
767 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 8, 32, total_length
, pc
, & fields
->f_imm8
);
769 case XSTORMY16_OPERAND_IMM8SMALL
:
770 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 8, 8, 32, total_length
, pc
, & fields
->f_imm8
);
772 case XSTORMY16_OPERAND_LMEM8
:
773 length
= extract_normal (cd
, ex_info
, insn_value
, 0|(1<<CGEN_IFLD_ABS_ADDR
), 0, 8, 8, 32, total_length
, pc
, & fields
->f_lmem8
);
775 case XSTORMY16_OPERAND_REL12
:
778 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
);
779 value
= ((value
) + (((pc
) + (4))));
780 fields
->f_rel12
= value
;
783 case XSTORMY16_OPERAND_REL12A
:
786 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
);
787 value
= ((((value
) << (1))) + (((pc
) + (2))));
788 fields
->f_rel12a
= value
;
791 case XSTORMY16_OPERAND_REL8_2
:
794 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
);
795 value
= ((value
) + (((pc
) + (2))));
796 fields
->f_rel8_2
= value
;
799 case XSTORMY16_OPERAND_REL8_4
:
802 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
);
803 value
= ((value
) + (((pc
) + (4))));
804 fields
->f_rel8_4
= value
;
807 case XSTORMY16_OPERAND_WS2
:
808 length
= extract_normal (cd
, ex_info
, insn_value
, 0, 0, 7, 1, 32, total_length
, pc
, & fields
->f_op2m
);
812 /* xgettext:c-format */
813 fprintf (stderr
, _("Unrecognized field %d while decoding insn.\n"),
821 cgen_insert_fn
* const xstormy16_cgen_insert_handlers
[] =
826 cgen_extract_fn
* const xstormy16_cgen_extract_handlers
[] =
831 int xstormy16_cgen_get_int_operand (CGEN_CPU_DESC
, int, const CGEN_FIELDS
*);
832 bfd_vma
xstormy16_cgen_get_vma_operand (CGEN_CPU_DESC
, int, const CGEN_FIELDS
*);
834 /* Getting values from cgen_fields is handled by a collection of functions.
835 They are distinguished by the type of the VALUE argument they return.
836 TODO: floating point, inlining support, remove cases where result type
840 xstormy16_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
842 const CGEN_FIELDS
* fields
)
848 case XSTORMY16_OPERAND_RB
:
849 value
= fields
->f_Rb
;
851 case XSTORMY16_OPERAND_RBJ
:
852 value
= fields
->f_Rbj
;
854 case XSTORMY16_OPERAND_RD
:
855 value
= fields
->f_Rd
;
857 case XSTORMY16_OPERAND_RDM
:
858 value
= fields
->f_Rdm
;
860 case XSTORMY16_OPERAND_RM
:
861 value
= fields
->f_Rm
;
863 case XSTORMY16_OPERAND_RS
:
864 value
= fields
->f_Rs
;
866 case XSTORMY16_OPERAND_ABS24
:
867 value
= fields
->f_abs24
;
869 case XSTORMY16_OPERAND_BCOND2
:
870 value
= fields
->f_op2
;
872 case XSTORMY16_OPERAND_BCOND5
:
873 value
= fields
->f_op5
;
875 case XSTORMY16_OPERAND_HMEM8
:
876 value
= fields
->f_hmem8
;
878 case XSTORMY16_OPERAND_IMM12
:
879 value
= fields
->f_imm12
;
881 case XSTORMY16_OPERAND_IMM16
:
882 value
= fields
->f_imm16
;
884 case XSTORMY16_OPERAND_IMM2
:
885 value
= fields
->f_imm2
;
887 case XSTORMY16_OPERAND_IMM3
:
888 value
= fields
->f_imm3
;
890 case XSTORMY16_OPERAND_IMM3B
:
891 value
= fields
->f_imm3b
;
893 case XSTORMY16_OPERAND_IMM4
:
894 value
= fields
->f_imm4
;
896 case XSTORMY16_OPERAND_IMM8
:
897 value
= fields
->f_imm8
;
899 case XSTORMY16_OPERAND_IMM8SMALL
:
900 value
= fields
->f_imm8
;
902 case XSTORMY16_OPERAND_LMEM8
:
903 value
= fields
->f_lmem8
;
905 case XSTORMY16_OPERAND_REL12
:
906 value
= fields
->f_rel12
;
908 case XSTORMY16_OPERAND_REL12A
:
909 value
= fields
->f_rel12a
;
911 case XSTORMY16_OPERAND_REL8_2
:
912 value
= fields
->f_rel8_2
;
914 case XSTORMY16_OPERAND_REL8_4
:
915 value
= fields
->f_rel8_4
;
917 case XSTORMY16_OPERAND_WS2
:
918 value
= fields
->f_op2m
;
922 /* xgettext:c-format */
923 fprintf (stderr
, _("Unrecognized field %d while getting int operand.\n"),
932 xstormy16_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
934 const CGEN_FIELDS
* fields
)
940 case XSTORMY16_OPERAND_RB
:
941 value
= fields
->f_Rb
;
943 case XSTORMY16_OPERAND_RBJ
:
944 value
= fields
->f_Rbj
;
946 case XSTORMY16_OPERAND_RD
:
947 value
= fields
->f_Rd
;
949 case XSTORMY16_OPERAND_RDM
:
950 value
= fields
->f_Rdm
;
952 case XSTORMY16_OPERAND_RM
:
953 value
= fields
->f_Rm
;
955 case XSTORMY16_OPERAND_RS
:
956 value
= fields
->f_Rs
;
958 case XSTORMY16_OPERAND_ABS24
:
959 value
= fields
->f_abs24
;
961 case XSTORMY16_OPERAND_BCOND2
:
962 value
= fields
->f_op2
;
964 case XSTORMY16_OPERAND_BCOND5
:
965 value
= fields
->f_op5
;
967 case XSTORMY16_OPERAND_HMEM8
:
968 value
= fields
->f_hmem8
;
970 case XSTORMY16_OPERAND_IMM12
:
971 value
= fields
->f_imm12
;
973 case XSTORMY16_OPERAND_IMM16
:
974 value
= fields
->f_imm16
;
976 case XSTORMY16_OPERAND_IMM2
:
977 value
= fields
->f_imm2
;
979 case XSTORMY16_OPERAND_IMM3
:
980 value
= fields
->f_imm3
;
982 case XSTORMY16_OPERAND_IMM3B
:
983 value
= fields
->f_imm3b
;
985 case XSTORMY16_OPERAND_IMM4
:
986 value
= fields
->f_imm4
;
988 case XSTORMY16_OPERAND_IMM8
:
989 value
= fields
->f_imm8
;
991 case XSTORMY16_OPERAND_IMM8SMALL
:
992 value
= fields
->f_imm8
;
994 case XSTORMY16_OPERAND_LMEM8
:
995 value
= fields
->f_lmem8
;
997 case XSTORMY16_OPERAND_REL12
:
998 value
= fields
->f_rel12
;
1000 case XSTORMY16_OPERAND_REL12A
:
1001 value
= fields
->f_rel12a
;
1003 case XSTORMY16_OPERAND_REL8_2
:
1004 value
= fields
->f_rel8_2
;
1006 case XSTORMY16_OPERAND_REL8_4
:
1007 value
= fields
->f_rel8_4
;
1009 case XSTORMY16_OPERAND_WS2
:
1010 value
= fields
->f_op2m
;
1014 /* xgettext:c-format */
1015 fprintf (stderr
, _("Unrecognized field %d while getting vma operand.\n"),
1023 void xstormy16_cgen_set_int_operand (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, int);
1024 void xstormy16_cgen_set_vma_operand (CGEN_CPU_DESC
, int, CGEN_FIELDS
*, bfd_vma
);
1026 /* Stuffing values in cgen_fields is handled by a collection of functions.
1027 They are distinguished by the type of the VALUE argument they accept.
1028 TODO: floating point, inlining support, remove cases where argument type
1032 xstormy16_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
1034 CGEN_FIELDS
* fields
,
1039 case XSTORMY16_OPERAND_RB
:
1040 fields
->f_Rb
= value
;
1042 case XSTORMY16_OPERAND_RBJ
:
1043 fields
->f_Rbj
= value
;
1045 case XSTORMY16_OPERAND_RD
:
1046 fields
->f_Rd
= value
;
1048 case XSTORMY16_OPERAND_RDM
:
1049 fields
->f_Rdm
= value
;
1051 case XSTORMY16_OPERAND_RM
:
1052 fields
->f_Rm
= value
;
1054 case XSTORMY16_OPERAND_RS
:
1055 fields
->f_Rs
= value
;
1057 case XSTORMY16_OPERAND_ABS24
:
1058 fields
->f_abs24
= value
;
1060 case XSTORMY16_OPERAND_BCOND2
:
1061 fields
->f_op2
= value
;
1063 case XSTORMY16_OPERAND_BCOND5
:
1064 fields
->f_op5
= value
;
1066 case XSTORMY16_OPERAND_HMEM8
:
1067 fields
->f_hmem8
= value
;
1069 case XSTORMY16_OPERAND_IMM12
:
1070 fields
->f_imm12
= value
;
1072 case XSTORMY16_OPERAND_IMM16
:
1073 fields
->f_imm16
= value
;
1075 case XSTORMY16_OPERAND_IMM2
:
1076 fields
->f_imm2
= value
;
1078 case XSTORMY16_OPERAND_IMM3
:
1079 fields
->f_imm3
= value
;
1081 case XSTORMY16_OPERAND_IMM3B
:
1082 fields
->f_imm3b
= value
;
1084 case XSTORMY16_OPERAND_IMM4
:
1085 fields
->f_imm4
= value
;
1087 case XSTORMY16_OPERAND_IMM8
:
1088 fields
->f_imm8
= value
;
1090 case XSTORMY16_OPERAND_IMM8SMALL
:
1091 fields
->f_imm8
= value
;
1093 case XSTORMY16_OPERAND_LMEM8
:
1094 fields
->f_lmem8
= value
;
1096 case XSTORMY16_OPERAND_REL12
:
1097 fields
->f_rel12
= value
;
1099 case XSTORMY16_OPERAND_REL12A
:
1100 fields
->f_rel12a
= value
;
1102 case XSTORMY16_OPERAND_REL8_2
:
1103 fields
->f_rel8_2
= value
;
1105 case XSTORMY16_OPERAND_REL8_4
:
1106 fields
->f_rel8_4
= value
;
1108 case XSTORMY16_OPERAND_WS2
:
1109 fields
->f_op2m
= value
;
1113 /* xgettext:c-format */
1114 fprintf (stderr
, _("Unrecognized field %d while setting int operand.\n"),
1121 xstormy16_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
1123 CGEN_FIELDS
* fields
,
1128 case XSTORMY16_OPERAND_RB
:
1129 fields
->f_Rb
= value
;
1131 case XSTORMY16_OPERAND_RBJ
:
1132 fields
->f_Rbj
= value
;
1134 case XSTORMY16_OPERAND_RD
:
1135 fields
->f_Rd
= value
;
1137 case XSTORMY16_OPERAND_RDM
:
1138 fields
->f_Rdm
= value
;
1140 case XSTORMY16_OPERAND_RM
:
1141 fields
->f_Rm
= value
;
1143 case XSTORMY16_OPERAND_RS
:
1144 fields
->f_Rs
= value
;
1146 case XSTORMY16_OPERAND_ABS24
:
1147 fields
->f_abs24
= value
;
1149 case XSTORMY16_OPERAND_BCOND2
:
1150 fields
->f_op2
= value
;
1152 case XSTORMY16_OPERAND_BCOND5
:
1153 fields
->f_op5
= value
;
1155 case XSTORMY16_OPERAND_HMEM8
:
1156 fields
->f_hmem8
= value
;
1158 case XSTORMY16_OPERAND_IMM12
:
1159 fields
->f_imm12
= value
;
1161 case XSTORMY16_OPERAND_IMM16
:
1162 fields
->f_imm16
= value
;
1164 case XSTORMY16_OPERAND_IMM2
:
1165 fields
->f_imm2
= value
;
1167 case XSTORMY16_OPERAND_IMM3
:
1168 fields
->f_imm3
= value
;
1170 case XSTORMY16_OPERAND_IMM3B
:
1171 fields
->f_imm3b
= value
;
1173 case XSTORMY16_OPERAND_IMM4
:
1174 fields
->f_imm4
= value
;
1176 case XSTORMY16_OPERAND_IMM8
:
1177 fields
->f_imm8
= value
;
1179 case XSTORMY16_OPERAND_IMM8SMALL
:
1180 fields
->f_imm8
= value
;
1182 case XSTORMY16_OPERAND_LMEM8
:
1183 fields
->f_lmem8
= value
;
1185 case XSTORMY16_OPERAND_REL12
:
1186 fields
->f_rel12
= value
;
1188 case XSTORMY16_OPERAND_REL12A
:
1189 fields
->f_rel12a
= value
;
1191 case XSTORMY16_OPERAND_REL8_2
:
1192 fields
->f_rel8_2
= value
;
1194 case XSTORMY16_OPERAND_REL8_4
:
1195 fields
->f_rel8_4
= value
;
1197 case XSTORMY16_OPERAND_WS2
:
1198 fields
->f_op2m
= value
;
1202 /* xgettext:c-format */
1203 fprintf (stderr
, _("Unrecognized field %d while setting vma operand.\n"),
1209 /* Function to call before using the instruction builder tables. */
1212 xstormy16_cgen_init_ibld_table (CGEN_CPU_DESC cd
)
1214 cd
->insert_handlers
= & xstormy16_cgen_insert_handlers
[0];
1215 cd
->extract_handlers
= & xstormy16_cgen_extract_handlers
[0];
1217 cd
->insert_operand
= xstormy16_cgen_insert_operand
;
1218 cd
->extract_operand
= xstormy16_cgen_extract_operand
;
1220 cd
->get_int_operand
= xstormy16_cgen_get_int_operand
;
1221 cd
->set_int_operand
= xstormy16_cgen_set_int_operand
;
1222 cd
->get_vma_operand
= xstormy16_cgen_get_vma_operand
;
1223 cd
->set_vma_operand
= xstormy16_cgen_set_vma_operand
;