/src/binutils-gdb/opcodes/xstormy16-ibld.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */ |
2 | | /* Instruction building/extraction support for xstormy16. -*- C -*- |
3 | | |
4 | | THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator. |
5 | | - the resultant file is machine generated, cgen-ibld.in isn't |
6 | | |
7 | | Copyright (C) 1996-2025 Free Software Foundation, Inc. |
8 | | |
9 | | This file is part of libopcodes. |
10 | | |
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) |
14 | | any later version. |
15 | | |
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. |
20 | | |
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. */ |
24 | | |
25 | | /* ??? Eventually more and more of this stuff can go to cpu-independent files. |
26 | | Keep that in mind. */ |
27 | | |
28 | | #include "sysdep.h" |
29 | | #include <stdio.h> |
30 | | #include "ansidecl.h" |
31 | | #include "dis-asm.h" |
32 | | #include "bfd.h" |
33 | | #include "symcat.h" |
34 | | #include "xstormy16-desc.h" |
35 | | #include "xstormy16-opc.h" |
36 | | #include "cgen/basic-modes.h" |
37 | | #include "opintl.h" |
38 | | #include "safe-ctype.h" |
39 | | |
40 | | #undef min |
41 | | #define min(a,b) ((a) < (b) ? (a) : (b)) |
42 | | #undef max |
43 | | #define max(a,b) ((a) > (b) ? (a) : (b)) |
44 | | |
45 | | /* Used by the ifield rtx function. */ |
46 | 2.28k | #define FLD(f) (fields->f) |
47 | | |
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); |
61 | | #if CGEN_INT_INSN_P |
62 | | static void put_insn_int_value |
63 | | (CGEN_CPU_DESC, CGEN_INSN_BYTES_PTR, int, int, CGEN_INSN_INT); |
64 | | #endif |
65 | | #if ! CGEN_INT_INSN_P |
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); |
72 | | #endif |
73 | | |
74 | | /* Operand insertion. */ |
75 | | |
76 | | #if ! CGEN_INT_INSN_P |
77 | | |
78 | | /* Subroutine of insert_normal. */ |
79 | | |
80 | | static CGEN_INLINE void |
81 | | insert_1 (CGEN_CPU_DESC cd, |
82 | | unsigned long value, |
83 | | int start, |
84 | | int length, |
85 | | int word_length, |
86 | | unsigned char *bufp) |
87 | | { |
88 | | unsigned long x, mask; |
89 | | int shift; |
90 | | |
91 | | x = cgen_get_insn_value (cd, bufp, word_length, cd->endian); |
92 | | |
93 | | /* Written this way to avoid undefined behaviour. */ |
94 | | mask = (1UL << (length - 1) << 1) - 1; |
95 | | if (CGEN_INSN_LSB0_P) |
96 | | shift = (start + 1) - length; |
97 | | else |
98 | | shift = (word_length - (start + length)); |
99 | | x = (x & ~(mask << shift)) | ((value & mask) << shift); |
100 | | |
101 | | cgen_put_insn_value (cd, bufp, word_length, (bfd_vma) x, cd->endian); |
102 | | } |
103 | | |
104 | | #endif /* ! CGEN_INT_INSN_P */ |
105 | | |
106 | | /* Default insertion routine. |
107 | | |
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. |
114 | | |
115 | | The result is an error message or NULL if success. */ |
116 | | |
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 |
120 | | necessary. */ |
121 | | |
122 | | static const char * |
123 | | insert_normal (CGEN_CPU_DESC cd, |
124 | | long value, |
125 | | unsigned int attrs, |
126 | | unsigned int word_offset, |
127 | | unsigned int start, |
128 | | unsigned int length, |
129 | | unsigned int word_length, |
130 | | unsigned int total_length, |
131 | | CGEN_INSN_BYTES_PTR buffer) |
132 | 0 | { |
133 | 0 | static char errbuf[100]; |
134 | 0 | unsigned long mask; |
135 | | |
136 | | /* If LENGTH is zero, this operand doesn't contribute to the value. */ |
137 | 0 | if (length == 0) |
138 | 0 | return NULL; |
139 | | |
140 | | /* Written this way to avoid undefined behaviour. */ |
141 | 0 | mask = (1UL << (length - 1) << 1) - 1; |
142 | |
|
143 | 0 | if (word_length > 8 * sizeof (CGEN_INSN_INT)) |
144 | 0 | abort (); |
145 | | |
146 | | /* For architectures with insns smaller than the base-insn-bitsize, |
147 | | word_length may be too big. */ |
148 | 0 | if (cd->min_insn_bitsize < cd->base_insn_bitsize) |
149 | 0 | { |
150 | 0 | if (word_offset == 0 |
151 | 0 | && word_length > total_length) |
152 | 0 | word_length = total_length; |
153 | 0 | } |
154 | | |
155 | | /* Ensure VALUE will fit. */ |
156 | 0 | if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT)) |
157 | 0 | { |
158 | 0 | long minval = - (1UL << (length - 1)); |
159 | 0 | unsigned long maxval = mask; |
160 | |
|
161 | 0 | if ((value > 0 && (unsigned long) value > maxval) |
162 | 0 | || value < minval) |
163 | 0 | { |
164 | | /* xgettext:c-format */ |
165 | 0 | sprintf (errbuf, |
166 | 0 | _("operand out of range (%ld not between %ld and %lu)"), |
167 | 0 | value, minval, maxval); |
168 | 0 | return errbuf; |
169 | 0 | } |
170 | 0 | } |
171 | 0 | else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)) |
172 | 0 | { |
173 | 0 | unsigned long maxval = mask; |
174 | 0 | unsigned long val = (unsigned long) value; |
175 | | |
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 | 0 | if (sizeof (unsigned long) > 4 && ((value >> 32) == -1)) |
181 | 0 | val &= 0xFFFFFFFF; |
182 | |
|
183 | 0 | if (val > maxval) |
184 | 0 | { |
185 | | /* xgettext:c-format */ |
186 | 0 | sprintf (errbuf, |
187 | 0 | _("operand out of range (0x%lx not between 0 and 0x%lx)"), |
188 | 0 | val, maxval); |
189 | 0 | return errbuf; |
190 | 0 | } |
191 | 0 | } |
192 | 0 | else |
193 | 0 | { |
194 | 0 | if (! cgen_signed_overflow_ok_p (cd)) |
195 | 0 | { |
196 | 0 | long minval = - (1UL << (length - 1)); |
197 | 0 | long maxval = (1UL << (length - 1)) - 1; |
198 | |
|
199 | 0 | if (value < minval || value > maxval) |
200 | 0 | { |
201 | 0 | sprintf |
202 | | /* xgettext:c-format */ |
203 | 0 | (errbuf, _("operand out of range (%ld not between %ld and %ld)"), |
204 | 0 | value, minval, maxval); |
205 | 0 | return errbuf; |
206 | 0 | } |
207 | 0 | } |
208 | 0 | } |
209 | | |
210 | 0 | #if CGEN_INT_INSN_P |
211 | | |
212 | 0 | { |
213 | 0 | int shift_within_word, shift_to_word, shift; |
214 | | |
215 | | /* How to shift the value to BIT0 of the word. */ |
216 | 0 | shift_to_word = total_length - (word_offset + word_length); |
217 | | |
218 | | /* How to shift the value to the field within the word. */ |
219 | 0 | if (CGEN_INSN_LSB0_P) |
220 | 0 | shift_within_word = start + 1 - length; |
221 | 0 | else |
222 | 0 | shift_within_word = word_length - start - length; |
223 | | |
224 | | /* The total SHIFT, then mask in the value. */ |
225 | 0 | shift = shift_to_word + shift_within_word; |
226 | 0 | *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift); |
227 | 0 | } |
228 | |
|
229 | | #else /* ! CGEN_INT_INSN_P */ |
230 | | |
231 | | { |
232 | | unsigned char *bufp = (unsigned char *) buffer + word_offset / 8; |
233 | | |
234 | | insert_1 (cd, value, start, length, word_length, bufp); |
235 | | } |
236 | | |
237 | | #endif /* ! CGEN_INT_INSN_P */ |
238 | |
|
239 | 0 | return NULL; |
240 | 0 | } |
241 | | |
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. */ |
248 | | |
249 | | static const char * |
250 | | insert_insn_normal (CGEN_CPU_DESC cd, |
251 | | const CGEN_INSN * insn, |
252 | | CGEN_FIELDS * fields, |
253 | | CGEN_INSN_BYTES_PTR buffer, |
254 | | bfd_vma pc) |
255 | 0 | { |
256 | 0 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); |
257 | 0 | unsigned long value; |
258 | 0 | const CGEN_SYNTAX_CHAR_TYPE * syn; |
259 | |
|
260 | 0 | CGEN_INIT_INSERT (cd); |
261 | 0 | value = CGEN_INSN_BASE_VALUE (insn); |
262 | | |
263 | | /* If we're recording insns as numbers (rather than a string of bytes), |
264 | | target byte order handling is deferred until later. */ |
265 | |
|
266 | 0 | #if CGEN_INT_INSN_P |
267 | |
|
268 | 0 | put_insn_int_value (cd, buffer, cd->base_insn_bitsize, |
269 | 0 | CGEN_FIELDS_BITSIZE (fields), value); |
270 | |
|
271 | | #else |
272 | | |
273 | | cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize, |
274 | | (unsigned) CGEN_FIELDS_BITSIZE (fields)), |
275 | | value, cd->insn_endian); |
276 | | |
277 | | #endif /* ! CGEN_INT_INSN_P */ |
278 | | |
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. */ |
283 | |
|
284 | 0 | for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn) |
285 | 0 | { |
286 | 0 | const char *errmsg; |
287 | |
|
288 | 0 | if (CGEN_SYNTAX_CHAR_P (* syn)) |
289 | 0 | continue; |
290 | | |
291 | 0 | errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn), |
292 | 0 | fields, buffer, pc); |
293 | 0 | if (errmsg) |
294 | 0 | return errmsg; |
295 | 0 | } |
296 | | |
297 | 0 | return NULL; |
298 | 0 | } |
299 | | |
300 | | #if CGEN_INT_INSN_P |
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. */ |
303 | | |
304 | | static void |
305 | | put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
306 | | CGEN_INSN_BYTES_PTR buf, |
307 | | int length, |
308 | | int insn_length, |
309 | | CGEN_INSN_INT value) |
310 | 0 | { |
311 | | /* For architectures with insns smaller than the base-insn-bitsize, |
312 | | length may be too big. */ |
313 | 0 | if (length > insn_length) |
314 | 0 | *buf = value; |
315 | 0 | else |
316 | 0 | { |
317 | 0 | int shift = insn_length - length; |
318 | | /* Written this way to avoid undefined behaviour. */ |
319 | 0 | CGEN_INSN_INT mask = length == 0 ? 0 : (1UL << (length - 1) << 1) - 1; |
320 | |
|
321 | 0 | *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift); |
322 | 0 | } |
323 | 0 | } |
324 | | #endif |
325 | | |
326 | | /* Operand extraction. */ |
327 | | |
328 | | #if ! CGEN_INT_INSN_P |
329 | | |
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. */ |
335 | | |
336 | | static CGEN_INLINE int |
337 | | fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
338 | | CGEN_EXTRACT_INFO *ex_info, |
339 | | int offset, |
340 | | int bytes, |
341 | | bfd_vma pc) |
342 | | { |
343 | | /* It's doubtful that the middle part has already been fetched so |
344 | | we don't optimize that case. kiss. */ |
345 | | unsigned int mask; |
346 | | disassemble_info *info = (disassemble_info *) ex_info->dis_info; |
347 | | |
348 | | /* First do a quick check. */ |
349 | | mask = (1 << bytes) - 1; |
350 | | if (((ex_info->valid >> offset) & mask) == mask) |
351 | | return 1; |
352 | | |
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)) |
356 | | break; |
357 | | |
358 | | if (bytes) |
359 | | { |
360 | | int status; |
361 | | |
362 | | pc += offset; |
363 | | status = (*info->read_memory_func) |
364 | | (pc, ex_info->insn_bytes + offset, bytes, info); |
365 | | |
366 | | if (status != 0) |
367 | | { |
368 | | (*info->memory_error_func) (status, pc, info); |
369 | | return 0; |
370 | | } |
371 | | |
372 | | ex_info->valid |= ((1 << bytes) - 1) << offset; |
373 | | } |
374 | | |
375 | | return 1; |
376 | | } |
377 | | |
378 | | /* Subroutine of extract_normal. */ |
379 | | |
380 | | static CGEN_INLINE long |
381 | | extract_1 (CGEN_CPU_DESC cd, |
382 | | CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED, |
383 | | int start, |
384 | | int length, |
385 | | int word_length, |
386 | | unsigned char *bufp, |
387 | | bfd_vma pc ATTRIBUTE_UNUSED) |
388 | | { |
389 | | unsigned long x; |
390 | | int shift; |
391 | | |
392 | | x = cgen_get_insn_value (cd, bufp, word_length, cd->endian); |
393 | | |
394 | | if (CGEN_INSN_LSB0_P) |
395 | | shift = (start + 1) - length; |
396 | | else |
397 | | shift = (word_length - (start + length)); |
398 | | return x >> shift; |
399 | | } |
400 | | |
401 | | #endif /* ! CGEN_INT_INSN_P */ |
402 | | |
403 | | /* Default extraction routine. |
404 | | |
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. |
415 | | |
416 | | Returns 1 for success, 0 for failure. */ |
417 | | |
418 | | /* ??? The return code isn't properly used. wip. */ |
419 | | |
420 | | /* ??? This doesn't handle bfd_vma's. Create another function when |
421 | | necessary. */ |
422 | | |
423 | | static int |
424 | | extract_normal (CGEN_CPU_DESC cd, |
425 | | #if ! CGEN_INT_INSN_P |
426 | | CGEN_EXTRACT_INFO *ex_info, |
427 | | #else |
428 | | CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED, |
429 | | #endif |
430 | | CGEN_INSN_INT insn_value, |
431 | | unsigned int attrs, |
432 | | unsigned int word_offset, |
433 | | unsigned int start, |
434 | | unsigned int length, |
435 | | unsigned int word_length, |
436 | | unsigned int total_length, |
437 | | #if ! CGEN_INT_INSN_P |
438 | | bfd_vma pc, |
439 | | #else |
440 | | bfd_vma pc ATTRIBUTE_UNUSED, |
441 | | #endif |
442 | | long *valuep) |
443 | 45.9k | { |
444 | 45.9k | long value, mask; |
445 | | |
446 | | /* If LENGTH is zero, this operand doesn't contribute to the value |
447 | | so give it a standard value of zero. */ |
448 | 45.9k | if (length == 0) |
449 | 0 | { |
450 | 0 | *valuep = 0; |
451 | 0 | return 1; |
452 | 0 | } |
453 | | |
454 | 45.9k | if (word_length > 8 * sizeof (CGEN_INSN_INT)) |
455 | 0 | abort (); |
456 | | |
457 | | /* For architectures with insns smaller than the insn-base-bitsize, |
458 | | word_length may be too big. */ |
459 | 45.9k | if (cd->min_insn_bitsize < cd->base_insn_bitsize) |
460 | 45.9k | { |
461 | 45.9k | if (word_offset + word_length > total_length) |
462 | 32.6k | word_length = total_length - word_offset; |
463 | 45.9k | } |
464 | | |
465 | | /* Does the value reside in INSN_VALUE, and at the right alignment? */ |
466 | | |
467 | 45.9k | if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length)) |
468 | 45.9k | { |
469 | 45.9k | if (CGEN_INSN_LSB0_P) |
470 | 0 | value = insn_value >> ((word_offset + start + 1) - length); |
471 | 45.9k | else |
472 | 45.9k | value = insn_value >> (total_length - ( word_offset + start + length)); |
473 | 45.9k | } |
474 | | |
475 | | #if ! CGEN_INT_INSN_P |
476 | | |
477 | | else |
478 | | { |
479 | | unsigned char *bufp = ex_info->insn_bytes + word_offset / 8; |
480 | | |
481 | | if (word_length > 8 * sizeof (CGEN_INSN_INT)) |
482 | | abort (); |
483 | | |
484 | | if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0) |
485 | | { |
486 | | *valuep = 0; |
487 | | return 0; |
488 | | } |
489 | | |
490 | | value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc); |
491 | | } |
492 | | |
493 | | #endif /* ! CGEN_INT_INSN_P */ |
494 | | |
495 | | /* Written this way to avoid undefined behaviour. */ |
496 | 45.9k | mask = (1UL << (length - 1) << 1) - 1; |
497 | | |
498 | 45.9k | value &= mask; |
499 | | /* sign extend? */ |
500 | 45.9k | if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED) |
501 | 45.9k | && (value & (1UL << (length - 1)))) |
502 | 3.79k | value |= ~mask; |
503 | | |
504 | 45.9k | *valuep = value; |
505 | | |
506 | 45.9k | return 1; |
507 | 45.9k | } |
508 | | |
509 | | /* Default insn extractor. |
510 | | |
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 |
516 | | been called). */ |
517 | | |
518 | | static int |
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, |
523 | | CGEN_FIELDS *fields, |
524 | | bfd_vma pc) |
525 | 22.1k | { |
526 | 22.1k | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); |
527 | 22.1k | const CGEN_SYNTAX_CHAR_TYPE *syn; |
528 | | |
529 | 22.1k | CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn); |
530 | | |
531 | 22.1k | CGEN_INIT_EXTRACT (cd); |
532 | | |
533 | 144k | for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn) |
534 | 122k | { |
535 | 122k | int length; |
536 | | |
537 | 122k | if (CGEN_SYNTAX_CHAR_P (*syn)) |
538 | 77.5k | continue; |
539 | | |
540 | 45.1k | length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn), |
541 | 45.1k | ex_info, insn_value, fields, pc); |
542 | 45.1k | if (length <= 0) |
543 | 0 | return length; |
544 | 45.1k | } |
545 | | |
546 | | /* We recognized and successfully extracted this insn. */ |
547 | 22.1k | return CGEN_INSN_BITSIZE (insn); |
548 | 22.1k | } |
549 | | |
550 | | /* Machine generated code added here. */ |
551 | | |
552 | | const char * xstormy16_cgen_insert_operand |
553 | | (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma); |
554 | | |
555 | | /* Main entry point for operand insertion. |
556 | | |
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. |
563 | | |
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. */ |
568 | | |
569 | | const char * |
570 | | xstormy16_cgen_insert_operand (CGEN_CPU_DESC cd, |
571 | | int opindex, |
572 | | CGEN_FIELDS * fields, |
573 | | CGEN_INSN_BYTES_PTR buffer, |
574 | | bfd_vma pc ATTRIBUTE_UNUSED) |
575 | 0 | { |
576 | 0 | const char * errmsg = NULL; |
577 | 0 | unsigned int total_length = CGEN_FIELDS_BITSIZE (fields); |
578 | |
|
579 | 0 | switch (opindex) |
580 | 0 | { |
581 | 0 | case XSTORMY16_OPERAND_RB : |
582 | 0 | errmsg = insert_normal (cd, fields->f_Rb, 0, 0, 17, 3, 32, total_length, buffer); |
583 | 0 | break; |
584 | 0 | case XSTORMY16_OPERAND_RBJ : |
585 | 0 | errmsg = insert_normal (cd, fields->f_Rbj, 0, 0, 11, 1, 32, total_length, buffer); |
586 | 0 | break; |
587 | 0 | case XSTORMY16_OPERAND_RD : |
588 | 0 | errmsg = insert_normal (cd, fields->f_Rd, 0, 0, 12, 4, 32, total_length, buffer); |
589 | 0 | break; |
590 | 0 | case XSTORMY16_OPERAND_RDM : |
591 | 0 | errmsg = insert_normal (cd, fields->f_Rdm, 0, 0, 13, 3, 32, total_length, buffer); |
592 | 0 | break; |
593 | 0 | case XSTORMY16_OPERAND_RM : |
594 | 0 | errmsg = insert_normal (cd, fields->f_Rm, 0, 0, 4, 3, 32, total_length, buffer); |
595 | 0 | break; |
596 | 0 | case XSTORMY16_OPERAND_RS : |
597 | 0 | errmsg = insert_normal (cd, fields->f_Rs, 0, 0, 8, 4, 32, total_length, buffer); |
598 | 0 | break; |
599 | 0 | case XSTORMY16_OPERAND_ABS24 : |
600 | 0 | { |
601 | 0 | { |
602 | 0 | FLD (f_abs24_1) = ((FLD (f_abs24)) & (255)); |
603 | 0 | FLD (f_abs24_2) = ((UINT) (FLD (f_abs24)) >> (8)); |
604 | 0 | } |
605 | 0 | errmsg = insert_normal (cd, fields->f_abs24_1, 0, 0, 8, 8, 32, total_length, buffer); |
606 | 0 | if (errmsg) |
607 | 0 | break; |
608 | 0 | errmsg = insert_normal (cd, fields->f_abs24_2, 0, 0, 16, 16, 32, total_length, buffer); |
609 | 0 | if (errmsg) |
610 | 0 | break; |
611 | 0 | } |
612 | 0 | break; |
613 | 0 | case XSTORMY16_OPERAND_BCOND2 : |
614 | 0 | errmsg = insert_normal (cd, fields->f_op2, 0, 0, 4, 4, 32, total_length, buffer); |
615 | 0 | break; |
616 | 0 | case XSTORMY16_OPERAND_BCOND5 : |
617 | 0 | errmsg = insert_normal (cd, fields->f_op5, 0, 0, 16, 4, 32, total_length, buffer); |
618 | 0 | break; |
619 | 0 | case XSTORMY16_OPERAND_HMEM8 : |
620 | 0 | { |
621 | 0 | long value = fields->f_hmem8; |
622 | 0 | value = ((value) - (32512)); |
623 | 0 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, buffer); |
624 | 0 | } |
625 | 0 | break; |
626 | 0 | case XSTORMY16_OPERAND_IMM12 : |
627 | 0 | errmsg = insert_normal (cd, fields->f_imm12, 0|(1<<CGEN_IFLD_SIGNED), 0, 20, 12, 32, total_length, buffer); |
628 | 0 | break; |
629 | 0 | case XSTORMY16_OPERAND_IMM16 : |
630 | 0 | errmsg = insert_normal (cd, fields->f_imm16, 0|(1<<CGEN_IFLD_SIGN_OPT), 0, 16, 16, 32, total_length, buffer); |
631 | 0 | break; |
632 | 0 | case XSTORMY16_OPERAND_IMM2 : |
633 | 0 | errmsg = insert_normal (cd, fields->f_imm2, 0, 0, 10, 2, 32, total_length, buffer); |
634 | 0 | break; |
635 | 0 | case XSTORMY16_OPERAND_IMM3 : |
636 | 0 | errmsg = insert_normal (cd, fields->f_imm3, 0, 0, 4, 3, 32, total_length, buffer); |
637 | 0 | break; |
638 | 0 | case XSTORMY16_OPERAND_IMM3B : |
639 | 0 | errmsg = insert_normal (cd, fields->f_imm3b, 0, 0, 17, 3, 32, total_length, buffer); |
640 | 0 | break; |
641 | 0 | case XSTORMY16_OPERAND_IMM4 : |
642 | 0 | errmsg = insert_normal (cd, fields->f_imm4, 0, 0, 8, 4, 32, total_length, buffer); |
643 | 0 | break; |
644 | 0 | case XSTORMY16_OPERAND_IMM8 : |
645 | 0 | errmsg = insert_normal (cd, fields->f_imm8, 0, 0, 8, 8, 32, total_length, buffer); |
646 | 0 | break; |
647 | 0 | case XSTORMY16_OPERAND_IMM8SMALL : |
648 | 0 | errmsg = insert_normal (cd, fields->f_imm8, 0, 0, 8, 8, 32, total_length, buffer); |
649 | 0 | break; |
650 | 0 | case XSTORMY16_OPERAND_LMEM8 : |
651 | 0 | errmsg = insert_normal (cd, fields->f_lmem8, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, buffer); |
652 | 0 | break; |
653 | 0 | case XSTORMY16_OPERAND_REL12 : |
654 | 0 | { |
655 | 0 | long value = fields->f_rel12; |
656 | 0 | value = ((value) - (((pc) + (4)))); |
657 | 0 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 20, 12, 32, total_length, buffer); |
658 | 0 | } |
659 | 0 | break; |
660 | 0 | case XSTORMY16_OPERAND_REL12A : |
661 | 0 | { |
662 | 0 | long value = fields->f_rel12a; |
663 | 0 | value = ((SI) (((value) - (((pc) + (2))))) >> (1)); |
664 | 0 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 4, 11, 32, total_length, buffer); |
665 | 0 | } |
666 | 0 | break; |
667 | 0 | case XSTORMY16_OPERAND_REL8_2 : |
668 | 0 | { |
669 | 0 | long value = fields->f_rel8_2; |
670 | 0 | value = ((value) - (((pc) + (2)))); |
671 | 0 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 32, total_length, buffer); |
672 | 0 | } |
673 | 0 | break; |
674 | 0 | case XSTORMY16_OPERAND_REL8_4 : |
675 | 0 | { |
676 | 0 | long value = fields->f_rel8_4; |
677 | 0 | value = ((value) - (((pc) + (4)))); |
678 | 0 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 8, 8, 32, total_length, buffer); |
679 | 0 | } |
680 | 0 | break; |
681 | 0 | case XSTORMY16_OPERAND_WS2 : |
682 | 0 | errmsg = insert_normal (cd, fields->f_op2m, 0, 0, 7, 1, 32, total_length, buffer); |
683 | 0 | break; |
684 | | |
685 | 0 | default : |
686 | | /* xgettext:c-format */ |
687 | 0 | opcodes_error_handler |
688 | 0 | (_("internal error: unrecognized field %d while building insn"), |
689 | 0 | opindex); |
690 | 0 | abort (); |
691 | 0 | } |
692 | | |
693 | 0 | return errmsg; |
694 | 0 | } |
695 | | |
696 | | int xstormy16_cgen_extract_operand |
697 | | (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma); |
698 | | |
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. |
702 | | |
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. |
709 | | |
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 |
712 | | the handlers. */ |
713 | | |
714 | | int |
715 | | xstormy16_cgen_extract_operand (CGEN_CPU_DESC cd, |
716 | | int opindex, |
717 | | CGEN_EXTRACT_INFO *ex_info, |
718 | | CGEN_INSN_INT insn_value, |
719 | | CGEN_FIELDS * fields, |
720 | | bfd_vma pc) |
721 | 45.1k | { |
722 | | /* Assume success (for those operands that are nops). */ |
723 | 45.1k | int length = 1; |
724 | 45.1k | unsigned int total_length = CGEN_FIELDS_BITSIZE (fields); |
725 | | |
726 | 45.1k | switch (opindex) |
727 | 45.1k | { |
728 | 528 | case XSTORMY16_OPERAND_RB : |
729 | 528 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 17, 3, 32, total_length, pc, & fields->f_Rb); |
730 | 528 | break; |
731 | 541 | case XSTORMY16_OPERAND_RBJ : |
732 | 541 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_Rbj); |
733 | 541 | break; |
734 | 2.73k | case XSTORMY16_OPERAND_RD : |
735 | 2.73k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 4, 32, total_length, pc, & fields->f_Rd); |
736 | 2.73k | break; |
737 | 1.80k | case XSTORMY16_OPERAND_RDM : |
738 | 1.80k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 13, 3, 32, total_length, pc, & fields->f_Rdm); |
739 | 1.80k | break; |
740 | 4.66k | case XSTORMY16_OPERAND_RM : |
741 | 4.66k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 3, 32, total_length, pc, & fields->f_Rm); |
742 | 4.66k | break; |
743 | 2.59k | case XSTORMY16_OPERAND_RS : |
744 | 2.59k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 32, total_length, pc, & fields->f_Rs); |
745 | 2.59k | break; |
746 | 763 | case XSTORMY16_OPERAND_ABS24 : |
747 | 763 | { |
748 | 763 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 32, total_length, pc, & fields->f_abs24_1); |
749 | 763 | if (length <= 0) break; |
750 | 763 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 16, 16, 32, total_length, pc, & fields->f_abs24_2); |
751 | 763 | if (length <= 0) break; |
752 | 763 | FLD (f_abs24) = ((((FLD (f_abs24_2)) << (8))) | (FLD (f_abs24_1))); |
753 | 763 | } |
754 | 0 | break; |
755 | 3.11k | case XSTORMY16_OPERAND_BCOND2 : |
756 | 3.11k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 4, 32, total_length, pc, & fields->f_op2); |
757 | 3.11k | break; |
758 | 745 | case XSTORMY16_OPERAND_BCOND5 : |
759 | 745 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 16, 4, 32, total_length, pc, & fields->f_op5); |
760 | 745 | break; |
761 | 5.03k | case XSTORMY16_OPERAND_HMEM8 : |
762 | 5.03k | { |
763 | 5.03k | long value; |
764 | 5.03k | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, pc, & value); |
765 | 5.03k | value = ((value) + (32512)); |
766 | 5.03k | fields->f_hmem8 = value; |
767 | 5.03k | } |
768 | 5.03k | break; |
769 | 636 | case XSTORMY16_OPERAND_IMM12 : |
770 | 636 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 20, 12, 32, total_length, pc, & fields->f_imm12); |
771 | 636 | break; |
772 | 1.41k | case XSTORMY16_OPERAND_IMM16 : |
773 | 1.41k | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGN_OPT), 0, 16, 16, 32, total_length, pc, & fields->f_imm16); |
774 | 1.41k | break; |
775 | 341 | case XSTORMY16_OPERAND_IMM2 : |
776 | 341 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 2, 32, total_length, pc, & fields->f_imm2); |
777 | 341 | break; |
778 | 4.13k | case XSTORMY16_OPERAND_IMM3 : |
779 | 4.13k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 4, 3, 32, total_length, pc, & fields->f_imm3); |
780 | 4.13k | break; |
781 | 356 | case XSTORMY16_OPERAND_IMM3B : |
782 | 356 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 17, 3, 32, total_length, pc, & fields->f_imm3b); |
783 | 356 | break; |
784 | 605 | case XSTORMY16_OPERAND_IMM4 : |
785 | 605 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 4, 32, total_length, pc, & fields->f_imm4); |
786 | 605 | break; |
787 | 998 | case XSTORMY16_OPERAND_IMM8 : |
788 | 998 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 32, total_length, pc, & fields->f_imm8); |
789 | 998 | break; |
790 | 889 | case XSTORMY16_OPERAND_IMM8SMALL : |
791 | 889 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 8, 32, total_length, pc, & fields->f_imm8); |
792 | 889 | break; |
793 | 2.63k | case XSTORMY16_OPERAND_LMEM8 : |
794 | 2.63k | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 8, 8, 32, total_length, pc, & fields->f_lmem8); |
795 | 2.63k | break; |
796 | 1.26k | case XSTORMY16_OPERAND_REL12 : |
797 | 1.26k | { |
798 | 1.26k | long value; |
799 | 1.26k | 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 | 1.26k | value = ((value) + (((pc) + (4)))); |
801 | 1.26k | fields->f_rel12 = value; |
802 | 1.26k | } |
803 | 1.26k | break; |
804 | 1.27k | case XSTORMY16_OPERAND_REL12A : |
805 | 1.27k | { |
806 | 1.27k | long value; |
807 | 1.27k | 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 | 1.27k | value = ((((value) * (2))) + (((pc) + (2)))); |
809 | 1.27k | fields->f_rel12a = value; |
810 | 1.27k | } |
811 | 1.27k | break; |
812 | 1.93k | case XSTORMY16_OPERAND_REL8_2 : |
813 | 1.93k | { |
814 | 1.93k | long value; |
815 | 1.93k | 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 | 1.93k | value = ((value) + (((pc) + (2)))); |
817 | 1.93k | fields->f_rel8_2 = value; |
818 | 1.93k | } |
819 | 1.93k | break; |
820 | 1.18k | case XSTORMY16_OPERAND_REL8_4 : |
821 | 1.18k | { |
822 | 1.18k | long value; |
823 | 1.18k | 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 | 1.18k | value = ((value) + (((pc) + (4)))); |
825 | 1.18k | fields->f_rel8_4 = value; |
826 | 1.18k | } |
827 | 1.18k | break; |
828 | 4.98k | case XSTORMY16_OPERAND_WS2 : |
829 | 4.98k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 1, 32, total_length, pc, & fields->f_op2m); |
830 | 4.98k | break; |
831 | | |
832 | 0 | default : |
833 | | /* xgettext:c-format */ |
834 | 0 | opcodes_error_handler |
835 | 0 | (_("internal error: unrecognized field %d while decoding insn"), |
836 | 0 | opindex); |
837 | 0 | abort (); |
838 | 45.1k | } |
839 | | |
840 | 45.1k | return length; |
841 | 45.1k | } |
842 | | |
843 | | cgen_insert_fn * const xstormy16_cgen_insert_handlers[] = |
844 | | { |
845 | | insert_insn_normal, |
846 | | }; |
847 | | |
848 | | cgen_extract_fn * const xstormy16_cgen_extract_handlers[] = |
849 | | { |
850 | | extract_insn_normal, |
851 | | }; |
852 | | |
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 *); |
855 | | |
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 |
859 | | not appropriate. */ |
860 | | |
861 | | int |
862 | | xstormy16_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
863 | | int opindex, |
864 | | const CGEN_FIELDS * fields) |
865 | 0 | { |
866 | 0 | int value; |
867 | |
|
868 | 0 | switch (opindex) |
869 | 0 | { |
870 | 0 | case XSTORMY16_OPERAND_RB : |
871 | 0 | value = fields->f_Rb; |
872 | 0 | break; |
873 | 0 | case XSTORMY16_OPERAND_RBJ : |
874 | 0 | value = fields->f_Rbj; |
875 | 0 | break; |
876 | 0 | case XSTORMY16_OPERAND_RD : |
877 | 0 | value = fields->f_Rd; |
878 | 0 | break; |
879 | 0 | case XSTORMY16_OPERAND_RDM : |
880 | 0 | value = fields->f_Rdm; |
881 | 0 | break; |
882 | 0 | case XSTORMY16_OPERAND_RM : |
883 | 0 | value = fields->f_Rm; |
884 | 0 | break; |
885 | 0 | case XSTORMY16_OPERAND_RS : |
886 | 0 | value = fields->f_Rs; |
887 | 0 | break; |
888 | 0 | case XSTORMY16_OPERAND_ABS24 : |
889 | 0 | value = fields->f_abs24; |
890 | 0 | break; |
891 | 0 | case XSTORMY16_OPERAND_BCOND2 : |
892 | 0 | value = fields->f_op2; |
893 | 0 | break; |
894 | 0 | case XSTORMY16_OPERAND_BCOND5 : |
895 | 0 | value = fields->f_op5; |
896 | 0 | break; |
897 | 0 | case XSTORMY16_OPERAND_HMEM8 : |
898 | 0 | value = fields->f_hmem8; |
899 | 0 | break; |
900 | 0 | case XSTORMY16_OPERAND_IMM12 : |
901 | 0 | value = fields->f_imm12; |
902 | 0 | break; |
903 | 0 | case XSTORMY16_OPERAND_IMM16 : |
904 | 0 | value = fields->f_imm16; |
905 | 0 | break; |
906 | 0 | case XSTORMY16_OPERAND_IMM2 : |
907 | 0 | value = fields->f_imm2; |
908 | 0 | break; |
909 | 0 | case XSTORMY16_OPERAND_IMM3 : |
910 | 0 | value = fields->f_imm3; |
911 | 0 | break; |
912 | 0 | case XSTORMY16_OPERAND_IMM3B : |
913 | 0 | value = fields->f_imm3b; |
914 | 0 | break; |
915 | 0 | case XSTORMY16_OPERAND_IMM4 : |
916 | 0 | value = fields->f_imm4; |
917 | 0 | break; |
918 | 0 | case XSTORMY16_OPERAND_IMM8 : |
919 | 0 | value = fields->f_imm8; |
920 | 0 | break; |
921 | 0 | case XSTORMY16_OPERAND_IMM8SMALL : |
922 | 0 | value = fields->f_imm8; |
923 | 0 | break; |
924 | 0 | case XSTORMY16_OPERAND_LMEM8 : |
925 | 0 | value = fields->f_lmem8; |
926 | 0 | break; |
927 | 0 | case XSTORMY16_OPERAND_REL12 : |
928 | 0 | value = fields->f_rel12; |
929 | 0 | break; |
930 | 0 | case XSTORMY16_OPERAND_REL12A : |
931 | 0 | value = fields->f_rel12a; |
932 | 0 | break; |
933 | 0 | case XSTORMY16_OPERAND_REL8_2 : |
934 | 0 | value = fields->f_rel8_2; |
935 | 0 | break; |
936 | 0 | case XSTORMY16_OPERAND_REL8_4 : |
937 | 0 | value = fields->f_rel8_4; |
938 | 0 | break; |
939 | 0 | case XSTORMY16_OPERAND_WS2 : |
940 | 0 | value = fields->f_op2m; |
941 | 0 | break; |
942 | | |
943 | 0 | default : |
944 | | /* xgettext:c-format */ |
945 | 0 | opcodes_error_handler |
946 | 0 | (_("internal error: unrecognized field %d while getting int operand"), |
947 | 0 | opindex); |
948 | 0 | abort (); |
949 | 0 | } |
950 | | |
951 | 0 | return value; |
952 | 0 | } |
953 | | |
954 | | bfd_vma |
955 | | xstormy16_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
956 | | int opindex, |
957 | | const CGEN_FIELDS * fields) |
958 | 0 | { |
959 | 0 | bfd_vma value; |
960 | |
|
961 | 0 | switch (opindex) |
962 | 0 | { |
963 | 0 | case XSTORMY16_OPERAND_RB : |
964 | 0 | value = fields->f_Rb; |
965 | 0 | break; |
966 | 0 | case XSTORMY16_OPERAND_RBJ : |
967 | 0 | value = fields->f_Rbj; |
968 | 0 | break; |
969 | 0 | case XSTORMY16_OPERAND_RD : |
970 | 0 | value = fields->f_Rd; |
971 | 0 | break; |
972 | 0 | case XSTORMY16_OPERAND_RDM : |
973 | 0 | value = fields->f_Rdm; |
974 | 0 | break; |
975 | 0 | case XSTORMY16_OPERAND_RM : |
976 | 0 | value = fields->f_Rm; |
977 | 0 | break; |
978 | 0 | case XSTORMY16_OPERAND_RS : |
979 | 0 | value = fields->f_Rs; |
980 | 0 | break; |
981 | 0 | case XSTORMY16_OPERAND_ABS24 : |
982 | 0 | value = fields->f_abs24; |
983 | 0 | break; |
984 | 0 | case XSTORMY16_OPERAND_BCOND2 : |
985 | 0 | value = fields->f_op2; |
986 | 0 | break; |
987 | 0 | case XSTORMY16_OPERAND_BCOND5 : |
988 | 0 | value = fields->f_op5; |
989 | 0 | break; |
990 | 0 | case XSTORMY16_OPERAND_HMEM8 : |
991 | 0 | value = fields->f_hmem8; |
992 | 0 | break; |
993 | 0 | case XSTORMY16_OPERAND_IMM12 : |
994 | 0 | value = fields->f_imm12; |
995 | 0 | break; |
996 | 0 | case XSTORMY16_OPERAND_IMM16 : |
997 | 0 | value = fields->f_imm16; |
998 | 0 | break; |
999 | 0 | case XSTORMY16_OPERAND_IMM2 : |
1000 | 0 | value = fields->f_imm2; |
1001 | 0 | break; |
1002 | 0 | case XSTORMY16_OPERAND_IMM3 : |
1003 | 0 | value = fields->f_imm3; |
1004 | 0 | break; |
1005 | 0 | case XSTORMY16_OPERAND_IMM3B : |
1006 | 0 | value = fields->f_imm3b; |
1007 | 0 | break; |
1008 | 0 | case XSTORMY16_OPERAND_IMM4 : |
1009 | 0 | value = fields->f_imm4; |
1010 | 0 | break; |
1011 | 0 | case XSTORMY16_OPERAND_IMM8 : |
1012 | 0 | value = fields->f_imm8; |
1013 | 0 | break; |
1014 | 0 | case XSTORMY16_OPERAND_IMM8SMALL : |
1015 | 0 | value = fields->f_imm8; |
1016 | 0 | break; |
1017 | 0 | case XSTORMY16_OPERAND_LMEM8 : |
1018 | 0 | value = fields->f_lmem8; |
1019 | 0 | break; |
1020 | 0 | case XSTORMY16_OPERAND_REL12 : |
1021 | 0 | value = fields->f_rel12; |
1022 | 0 | break; |
1023 | 0 | case XSTORMY16_OPERAND_REL12A : |
1024 | 0 | value = fields->f_rel12a; |
1025 | 0 | break; |
1026 | 0 | case XSTORMY16_OPERAND_REL8_2 : |
1027 | 0 | value = fields->f_rel8_2; |
1028 | 0 | break; |
1029 | 0 | case XSTORMY16_OPERAND_REL8_4 : |
1030 | 0 | value = fields->f_rel8_4; |
1031 | 0 | break; |
1032 | 0 | case XSTORMY16_OPERAND_WS2 : |
1033 | 0 | value = fields->f_op2m; |
1034 | 0 | break; |
1035 | | |
1036 | 0 | default : |
1037 | | /* xgettext:c-format */ |
1038 | 0 | opcodes_error_handler |
1039 | 0 | (_("internal error: unrecognized field %d while getting vma operand"), |
1040 | 0 | opindex); |
1041 | 0 | abort (); |
1042 | 0 | } |
1043 | | |
1044 | 0 | return value; |
1045 | 0 | } |
1046 | | |
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); |
1049 | | |
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 |
1053 | | not appropriate. */ |
1054 | | |
1055 | | void |
1056 | | xstormy16_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
1057 | | int opindex, |
1058 | | CGEN_FIELDS * fields, |
1059 | | int value) |
1060 | 0 | { |
1061 | 0 | switch (opindex) |
1062 | 0 | { |
1063 | 0 | case XSTORMY16_OPERAND_RB : |
1064 | 0 | fields->f_Rb = value; |
1065 | 0 | break; |
1066 | 0 | case XSTORMY16_OPERAND_RBJ : |
1067 | 0 | fields->f_Rbj = value; |
1068 | 0 | break; |
1069 | 0 | case XSTORMY16_OPERAND_RD : |
1070 | 0 | fields->f_Rd = value; |
1071 | 0 | break; |
1072 | 0 | case XSTORMY16_OPERAND_RDM : |
1073 | 0 | fields->f_Rdm = value; |
1074 | 0 | break; |
1075 | 0 | case XSTORMY16_OPERAND_RM : |
1076 | 0 | fields->f_Rm = value; |
1077 | 0 | break; |
1078 | 0 | case XSTORMY16_OPERAND_RS : |
1079 | 0 | fields->f_Rs = value; |
1080 | 0 | break; |
1081 | 0 | case XSTORMY16_OPERAND_ABS24 : |
1082 | 0 | fields->f_abs24 = value; |
1083 | 0 | break; |
1084 | 0 | case XSTORMY16_OPERAND_BCOND2 : |
1085 | 0 | fields->f_op2 = value; |
1086 | 0 | break; |
1087 | 0 | case XSTORMY16_OPERAND_BCOND5 : |
1088 | 0 | fields->f_op5 = value; |
1089 | 0 | break; |
1090 | 0 | case XSTORMY16_OPERAND_HMEM8 : |
1091 | 0 | fields->f_hmem8 = value; |
1092 | 0 | break; |
1093 | 0 | case XSTORMY16_OPERAND_IMM12 : |
1094 | 0 | fields->f_imm12 = value; |
1095 | 0 | break; |
1096 | 0 | case XSTORMY16_OPERAND_IMM16 : |
1097 | 0 | fields->f_imm16 = value; |
1098 | 0 | break; |
1099 | 0 | case XSTORMY16_OPERAND_IMM2 : |
1100 | 0 | fields->f_imm2 = value; |
1101 | 0 | break; |
1102 | 0 | case XSTORMY16_OPERAND_IMM3 : |
1103 | 0 | fields->f_imm3 = value; |
1104 | 0 | break; |
1105 | 0 | case XSTORMY16_OPERAND_IMM3B : |
1106 | 0 | fields->f_imm3b = value; |
1107 | 0 | break; |
1108 | 0 | case XSTORMY16_OPERAND_IMM4 : |
1109 | 0 | fields->f_imm4 = value; |
1110 | 0 | break; |
1111 | 0 | case XSTORMY16_OPERAND_IMM8 : |
1112 | 0 | fields->f_imm8 = value; |
1113 | 0 | break; |
1114 | 0 | case XSTORMY16_OPERAND_IMM8SMALL : |
1115 | 0 | fields->f_imm8 = value; |
1116 | 0 | break; |
1117 | 0 | case XSTORMY16_OPERAND_LMEM8 : |
1118 | 0 | fields->f_lmem8 = value; |
1119 | 0 | break; |
1120 | 0 | case XSTORMY16_OPERAND_REL12 : |
1121 | 0 | fields->f_rel12 = value; |
1122 | 0 | break; |
1123 | 0 | case XSTORMY16_OPERAND_REL12A : |
1124 | 0 | fields->f_rel12a = value; |
1125 | 0 | break; |
1126 | 0 | case XSTORMY16_OPERAND_REL8_2 : |
1127 | 0 | fields->f_rel8_2 = value; |
1128 | 0 | break; |
1129 | 0 | case XSTORMY16_OPERAND_REL8_4 : |
1130 | 0 | fields->f_rel8_4 = value; |
1131 | 0 | break; |
1132 | 0 | case XSTORMY16_OPERAND_WS2 : |
1133 | 0 | fields->f_op2m = value; |
1134 | 0 | break; |
1135 | | |
1136 | 0 | default : |
1137 | | /* xgettext:c-format */ |
1138 | 0 | opcodes_error_handler |
1139 | 0 | (_("internal error: unrecognized field %d while setting int operand"), |
1140 | 0 | opindex); |
1141 | 0 | abort (); |
1142 | 0 | } |
1143 | 0 | } |
1144 | | |
1145 | | void |
1146 | | xstormy16_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
1147 | | int opindex, |
1148 | | CGEN_FIELDS * fields, |
1149 | | bfd_vma value) |
1150 | 0 | { |
1151 | 0 | switch (opindex) |
1152 | 0 | { |
1153 | 0 | case XSTORMY16_OPERAND_RB : |
1154 | 0 | fields->f_Rb = value; |
1155 | 0 | break; |
1156 | 0 | case XSTORMY16_OPERAND_RBJ : |
1157 | 0 | fields->f_Rbj = value; |
1158 | 0 | break; |
1159 | 0 | case XSTORMY16_OPERAND_RD : |
1160 | 0 | fields->f_Rd = value; |
1161 | 0 | break; |
1162 | 0 | case XSTORMY16_OPERAND_RDM : |
1163 | 0 | fields->f_Rdm = value; |
1164 | 0 | break; |
1165 | 0 | case XSTORMY16_OPERAND_RM : |
1166 | 0 | fields->f_Rm = value; |
1167 | 0 | break; |
1168 | 0 | case XSTORMY16_OPERAND_RS : |
1169 | 0 | fields->f_Rs = value; |
1170 | 0 | break; |
1171 | 0 | case XSTORMY16_OPERAND_ABS24 : |
1172 | 0 | fields->f_abs24 = value; |
1173 | 0 | break; |
1174 | 0 | case XSTORMY16_OPERAND_BCOND2 : |
1175 | 0 | fields->f_op2 = value; |
1176 | 0 | break; |
1177 | 0 | case XSTORMY16_OPERAND_BCOND5 : |
1178 | 0 | fields->f_op5 = value; |
1179 | 0 | break; |
1180 | 0 | case XSTORMY16_OPERAND_HMEM8 : |
1181 | 0 | fields->f_hmem8 = value; |
1182 | 0 | break; |
1183 | 0 | case XSTORMY16_OPERAND_IMM12 : |
1184 | 0 | fields->f_imm12 = value; |
1185 | 0 | break; |
1186 | 0 | case XSTORMY16_OPERAND_IMM16 : |
1187 | 0 | fields->f_imm16 = value; |
1188 | 0 | break; |
1189 | 0 | case XSTORMY16_OPERAND_IMM2 : |
1190 | 0 | fields->f_imm2 = value; |
1191 | 0 | break; |
1192 | 0 | case XSTORMY16_OPERAND_IMM3 : |
1193 | 0 | fields->f_imm3 = value; |
1194 | 0 | break; |
1195 | 0 | case XSTORMY16_OPERAND_IMM3B : |
1196 | 0 | fields->f_imm3b = value; |
1197 | 0 | break; |
1198 | 0 | case XSTORMY16_OPERAND_IMM4 : |
1199 | 0 | fields->f_imm4 = value; |
1200 | 0 | break; |
1201 | 0 | case XSTORMY16_OPERAND_IMM8 : |
1202 | 0 | fields->f_imm8 = value; |
1203 | 0 | break; |
1204 | 0 | case XSTORMY16_OPERAND_IMM8SMALL : |
1205 | 0 | fields->f_imm8 = value; |
1206 | 0 | break; |
1207 | 0 | case XSTORMY16_OPERAND_LMEM8 : |
1208 | 0 | fields->f_lmem8 = value; |
1209 | 0 | break; |
1210 | 0 | case XSTORMY16_OPERAND_REL12 : |
1211 | 0 | fields->f_rel12 = value; |
1212 | 0 | break; |
1213 | 0 | case XSTORMY16_OPERAND_REL12A : |
1214 | 0 | fields->f_rel12a = value; |
1215 | 0 | break; |
1216 | 0 | case XSTORMY16_OPERAND_REL8_2 : |
1217 | 0 | fields->f_rel8_2 = value; |
1218 | 0 | break; |
1219 | 0 | case XSTORMY16_OPERAND_REL8_4 : |
1220 | 0 | fields->f_rel8_4 = value; |
1221 | 0 | break; |
1222 | 0 | case XSTORMY16_OPERAND_WS2 : |
1223 | 0 | fields->f_op2m = value; |
1224 | 0 | break; |
1225 | | |
1226 | 0 | default : |
1227 | | /* xgettext:c-format */ |
1228 | 0 | opcodes_error_handler |
1229 | 0 | (_("internal error: unrecognized field %d while setting vma operand"), |
1230 | 0 | opindex); |
1231 | 0 | abort (); |
1232 | 0 | } |
1233 | 0 | } |
1234 | | |
1235 | | /* Function to call before using the instruction builder tables. */ |
1236 | | |
1237 | | void |
1238 | | xstormy16_cgen_init_ibld_table (CGEN_CPU_DESC cd) |
1239 | 2 | { |
1240 | 2 | cd->insert_handlers = & xstormy16_cgen_insert_handlers[0]; |
1241 | 2 | cd->extract_handlers = & xstormy16_cgen_extract_handlers[0]; |
1242 | | |
1243 | 2 | cd->insert_operand = xstormy16_cgen_insert_operand; |
1244 | 2 | cd->extract_operand = xstormy16_cgen_extract_operand; |
1245 | | |
1246 | 2 | cd->get_int_operand = xstormy16_cgen_get_int_operand; |
1247 | 2 | cd->set_int_operand = xstormy16_cgen_set_int_operand; |
1248 | 2 | cd->get_vma_operand = xstormy16_cgen_get_vma_operand; |
1249 | 2 | cd->set_vma_operand = xstormy16_cgen_set_vma_operand; |
1250 | 2 | } |