Commit | Line | Data |
---|---|---|
4162bb66 | 1 | /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */ |
d031aafb | 2 | /* Instruction building/extraction support for mt. -*- C -*- |
ac188222 | 3 | |
47b0e7ad NC |
4 | THIS FILE IS MACHINE GENERATED WITH CGEN: Cpu tools GENerator. |
5 | - the resultant file is machine generated, cgen-ibld.in isn't | |
ac188222 | 6 | |
b3adc24a | 7 | Copyright (C) 1996-2020 Free Software Foundation, Inc. |
ac188222 | 8 | |
9b201bb5 | 9 | This file is part of libopcodes. |
ac188222 | 10 | |
9b201bb5 | 11 | This library is free software; you can redistribute it and/or modify |
47b0e7ad | 12 | it under the terms of the GNU General Public License as published by |
9b201bb5 | 13 | the Free Software Foundation; either version 3, or (at your option) |
47b0e7ad | 14 | any later version. |
ac188222 | 15 | |
9b201bb5 NC |
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. | |
ac188222 | 20 | |
47b0e7ad NC |
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. */ | |
ac188222 DB |
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" | |
d031aafb NS |
34 | #include "mt-desc.h" |
35 | #include "mt-opc.h" | |
fe8afbc4 | 36 | #include "cgen/basic-modes.h" |
ac188222 DB |
37 | #include "opintl.h" |
38 | #include "safe-ctype.h" | |
39 | ||
47b0e7ad | 40 | #undef min |
ac188222 | 41 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
47b0e7ad | 42 | #undef max |
ac188222 DB |
43 | #define max(a,b) ((a) > (b) ? (a) : (b)) |
44 | ||
45 | /* Used by the ifield rtx function. */ | |
46 | #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 | \f | |
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); | |
92 | ||
93 | /* Written this way to avoid undefined behaviour. */ | |
94 | mask = (((1L << (length - 1)) - 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); | |
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 | { | |
133 | static char errbuf[100]; | |
134 | /* Written this way to avoid undefined behaviour. */ | |
135 | unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1; | |
136 | ||
137 | /* If LENGTH is zero, this operand doesn't contribute to the value. */ | |
138 | if (length == 0) | |
139 | return NULL; | |
140 | ||
b7cd1872 | 141 | if (word_length > 8 * sizeof (CGEN_INSN_INT)) |
ac188222 DB |
142 | abort (); |
143 | ||
144 | /* For architectures with insns smaller than the base-insn-bitsize, | |
145 | word_length may be too big. */ | |
146 | if (cd->min_insn_bitsize < cd->base_insn_bitsize) | |
147 | { | |
148 | if (word_offset == 0 | |
149 | && word_length > total_length) | |
150 | word_length = total_length; | |
151 | } | |
152 | ||
153 | /* Ensure VALUE will fit. */ | |
154 | if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGN_OPT)) | |
155 | { | |
156 | long minval = - (1L << (length - 1)); | |
157 | unsigned long maxval = mask; | |
43e65147 | 158 | |
ac188222 DB |
159 | if ((value > 0 && (unsigned long) value > maxval) |
160 | || value < minval) | |
161 | { | |
162 | /* xgettext:c-format */ | |
163 | sprintf (errbuf, | |
164 | _("operand out of range (%ld not between %ld and %lu)"), | |
165 | value, minval, maxval); | |
166 | return errbuf; | |
167 | } | |
168 | } | |
169 | else if (! CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)) | |
170 | { | |
171 | unsigned long maxval = mask; | |
1620f33d AM |
172 | unsigned long val = (unsigned long) value; |
173 | ||
174 | /* For hosts with a word size > 32 check to see if value has been sign | |
175 | extended beyond 32 bits. If so then ignore these higher sign bits | |
176 | as the user is attempting to store a 32-bit signed value into an | |
177 | unsigned 32-bit field which is allowed. */ | |
178 | if (sizeof (unsigned long) > 4 && ((value >> 32) == -1)) | |
179 | val &= 0xFFFFFFFF; | |
180 | ||
181 | if (val > maxval) | |
ac188222 DB |
182 | { |
183 | /* xgettext:c-format */ | |
184 | sprintf (errbuf, | |
1620f33d AM |
185 | _("operand out of range (0x%lx not between 0 and 0x%lx)"), |
186 | val, maxval); | |
ac188222 DB |
187 | return errbuf; |
188 | } | |
189 | } | |
190 | else | |
191 | { | |
192 | if (! cgen_signed_overflow_ok_p (cd)) | |
193 | { | |
194 | long minval = - (1L << (length - 1)); | |
195 | long maxval = (1L << (length - 1)) - 1; | |
43e65147 | 196 | |
ac188222 DB |
197 | if (value < minval || value > maxval) |
198 | { | |
199 | sprintf | |
200 | /* xgettext:c-format */ | |
201 | (errbuf, _("operand out of range (%ld not between %ld and %ld)"), | |
202 | value, minval, maxval); | |
203 | return errbuf; | |
204 | } | |
205 | } | |
206 | } | |
207 | ||
208 | #if CGEN_INT_INSN_P | |
209 | ||
210 | { | |
a143b004 | 211 | int shift_within_word, shift_to_word, shift; |
ac188222 | 212 | |
a143b004 AB |
213 | /* How to shift the value to BIT0 of the word. */ |
214 | shift_to_word = total_length - (word_offset + word_length); | |
215 | ||
216 | /* How to shift the value to the field within the word. */ | |
ac188222 | 217 | if (CGEN_INSN_LSB0_P) |
a143b004 | 218 | shift_within_word = start + 1 - length; |
ac188222 | 219 | else |
a143b004 AB |
220 | shift_within_word = word_length - start - length; |
221 | ||
222 | /* The total SHIFT, then mask in the value. */ | |
223 | shift = shift_to_word + shift_within_word; | |
ac188222 DB |
224 | *buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift); |
225 | } | |
226 | ||
227 | #else /* ! CGEN_INT_INSN_P */ | |
228 | ||
229 | { | |
230 | unsigned char *bufp = (unsigned char *) buffer + word_offset / 8; | |
231 | ||
232 | insert_1 (cd, value, start, length, word_length, bufp); | |
233 | } | |
234 | ||
235 | #endif /* ! CGEN_INT_INSN_P */ | |
236 | ||
237 | return NULL; | |
238 | } | |
239 | ||
240 | /* Default insn builder (insert handler). | |
241 | The instruction is recorded in CGEN_INT_INSN_P byte order (meaning | |
242 | that if CGEN_INSN_BYTES_PTR is an int * and thus, the value is | |
243 | recorded in host byte order, otherwise BUFFER is an array of bytes | |
244 | and the value is recorded in target byte order). | |
245 | The result is an error message or NULL if success. */ | |
246 | ||
247 | static const char * | |
248 | insert_insn_normal (CGEN_CPU_DESC cd, | |
249 | const CGEN_INSN * insn, | |
250 | CGEN_FIELDS * fields, | |
251 | CGEN_INSN_BYTES_PTR buffer, | |
252 | bfd_vma pc) | |
253 | { | |
254 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); | |
255 | unsigned long value; | |
256 | const CGEN_SYNTAX_CHAR_TYPE * syn; | |
257 | ||
258 | CGEN_INIT_INSERT (cd); | |
259 | value = CGEN_INSN_BASE_VALUE (insn); | |
260 | ||
261 | /* If we're recording insns as numbers (rather than a string of bytes), | |
262 | target byte order handling is deferred until later. */ | |
263 | ||
264 | #if CGEN_INT_INSN_P | |
265 | ||
266 | put_insn_int_value (cd, buffer, cd->base_insn_bitsize, | |
267 | CGEN_FIELDS_BITSIZE (fields), value); | |
268 | ||
269 | #else | |
270 | ||
271 | cgen_put_insn_value (cd, buffer, min ((unsigned) cd->base_insn_bitsize, | |
272 | (unsigned) CGEN_FIELDS_BITSIZE (fields)), | |
273 | value); | |
274 | ||
275 | #endif /* ! CGEN_INT_INSN_P */ | |
276 | ||
277 | /* ??? It would be better to scan the format's fields. | |
278 | Still need to be able to insert a value based on the operand though; | |
279 | e.g. storing a branch displacement that got resolved later. | |
280 | Needs more thought first. */ | |
281 | ||
282 | for (syn = CGEN_SYNTAX_STRING (syntax); * syn; ++ syn) | |
283 | { | |
284 | const char *errmsg; | |
285 | ||
286 | if (CGEN_SYNTAX_CHAR_P (* syn)) | |
287 | continue; | |
288 | ||
289 | errmsg = (* cd->insert_operand) (cd, CGEN_SYNTAX_FIELD (*syn), | |
290 | fields, buffer, pc); | |
291 | if (errmsg) | |
292 | return errmsg; | |
293 | } | |
294 | ||
295 | return NULL; | |
296 | } | |
297 | ||
298 | #if CGEN_INT_INSN_P | |
299 | /* Cover function to store an insn value into an integral insn. Must go here | |
47b0e7ad | 300 | because it needs <prefix>-desc.h for CGEN_INT_INSN_P. */ |
ac188222 DB |
301 | |
302 | static void | |
303 | put_insn_int_value (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, | |
304 | CGEN_INSN_BYTES_PTR buf, | |
305 | int length, | |
306 | int insn_length, | |
307 | CGEN_INSN_INT value) | |
308 | { | |
309 | /* For architectures with insns smaller than the base-insn-bitsize, | |
310 | length may be too big. */ | |
311 | if (length > insn_length) | |
312 | *buf = value; | |
313 | else | |
314 | { | |
315 | int shift = insn_length - length; | |
316 | /* Written this way to avoid undefined behaviour. */ | |
317 | CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1; | |
47b0e7ad | 318 | |
ac188222 DB |
319 | *buf = (*buf & ~(mask << shift)) | ((value & mask) << shift); |
320 | } | |
321 | } | |
322 | #endif | |
323 | \f | |
324 | /* Operand extraction. */ | |
325 | ||
326 | #if ! CGEN_INT_INSN_P | |
327 | ||
328 | /* Subroutine of extract_normal. | |
329 | Ensure sufficient bytes are cached in EX_INFO. | |
330 | OFFSET is the offset in bytes from the start of the insn of the value. | |
331 | BYTES is the length of the needed value. | |
332 | Returns 1 for success, 0 for failure. */ | |
333 | ||
334 | static CGEN_INLINE int | |
335 | fill_cache (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, | |
336 | CGEN_EXTRACT_INFO *ex_info, | |
337 | int offset, | |
338 | int bytes, | |
339 | bfd_vma pc) | |
340 | { | |
341 | /* It's doubtful that the middle part has already been fetched so | |
342 | we don't optimize that case. kiss. */ | |
343 | unsigned int mask; | |
344 | disassemble_info *info = (disassemble_info *) ex_info->dis_info; | |
345 | ||
346 | /* First do a quick check. */ | |
347 | mask = (1 << bytes) - 1; | |
348 | if (((ex_info->valid >> offset) & mask) == mask) | |
349 | return 1; | |
350 | ||
351 | /* Search for the first byte we need to read. */ | |
352 | for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1) | |
353 | if (! (mask & ex_info->valid)) | |
354 | break; | |
355 | ||
356 | if (bytes) | |
357 | { | |
358 | int status; | |
359 | ||
360 | pc += offset; | |
361 | status = (*info->read_memory_func) | |
362 | (pc, ex_info->insn_bytes + offset, bytes, info); | |
363 | ||
364 | if (status != 0) | |
365 | { | |
366 | (*info->memory_error_func) (status, pc, info); | |
367 | return 0; | |
368 | } | |
369 | ||
370 | ex_info->valid |= ((1 << bytes) - 1) << offset; | |
371 | } | |
372 | ||
373 | return 1; | |
374 | } | |
375 | ||
376 | /* Subroutine of extract_normal. */ | |
377 | ||
378 | static CGEN_INLINE long | |
379 | extract_1 (CGEN_CPU_DESC cd, | |
380 | CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED, | |
381 | int start, | |
382 | int length, | |
383 | int word_length, | |
384 | unsigned char *bufp, | |
385 | bfd_vma pc ATTRIBUTE_UNUSED) | |
386 | { | |
387 | unsigned long x; | |
388 | int shift; | |
47b0e7ad | 389 | |
ac188222 DB |
390 | x = cgen_get_insn_value (cd, bufp, word_length); |
391 | ||
392 | if (CGEN_INSN_LSB0_P) | |
393 | shift = (start + 1) - length; | |
394 | else | |
395 | shift = (word_length - (start + length)); | |
396 | return x >> shift; | |
397 | } | |
398 | ||
399 | #endif /* ! CGEN_INT_INSN_P */ | |
400 | ||
401 | /* Default extraction routine. | |
402 | ||
403 | INSN_VALUE is the first base_insn_bitsize bits of the insn in host order, | |
404 | or sometimes less for cases like the m32r where the base insn size is 32 | |
405 | but some insns are 16 bits. | |
406 | ATTRS is a mask of the boolean attributes. We only need `SIGNED', | |
407 | but for generality we take a bitmask of all of them. | |
408 | WORD_OFFSET is the offset in bits from the start of the insn of the value. | |
409 | WORD_LENGTH is the length of the word in bits in which the value resides. | |
410 | START is the starting bit number in the word, architecture origin. | |
411 | LENGTH is the length of VALUE in bits. | |
412 | TOTAL_LENGTH is the total length of the insn in bits. | |
413 | ||
414 | Returns 1 for success, 0 for failure. */ | |
415 | ||
416 | /* ??? The return code isn't properly used. wip. */ | |
417 | ||
418 | /* ??? This doesn't handle bfd_vma's. Create another function when | |
419 | necessary. */ | |
420 | ||
421 | static int | |
422 | extract_normal (CGEN_CPU_DESC cd, | |
423 | #if ! CGEN_INT_INSN_P | |
424 | CGEN_EXTRACT_INFO *ex_info, | |
425 | #else | |
426 | CGEN_EXTRACT_INFO *ex_info ATTRIBUTE_UNUSED, | |
427 | #endif | |
428 | CGEN_INSN_INT insn_value, | |
429 | unsigned int attrs, | |
430 | unsigned int word_offset, | |
431 | unsigned int start, | |
432 | unsigned int length, | |
433 | unsigned int word_length, | |
434 | unsigned int total_length, | |
435 | #if ! CGEN_INT_INSN_P | |
436 | bfd_vma pc, | |
437 | #else | |
438 | bfd_vma pc ATTRIBUTE_UNUSED, | |
439 | #endif | |
440 | long *valuep) | |
441 | { | |
442 | long value, mask; | |
443 | ||
444 | /* If LENGTH is zero, this operand doesn't contribute to the value | |
445 | so give it a standard value of zero. */ | |
446 | if (length == 0) | |
447 | { | |
448 | *valuep = 0; | |
449 | return 1; | |
450 | } | |
451 | ||
b7cd1872 | 452 | if (word_length > 8 * sizeof (CGEN_INSN_INT)) |
ac188222 DB |
453 | abort (); |
454 | ||
455 | /* For architectures with insns smaller than the insn-base-bitsize, | |
456 | word_length may be too big. */ | |
457 | if (cd->min_insn_bitsize < cd->base_insn_bitsize) | |
458 | { | |
1620f33d AM |
459 | if (word_offset + word_length > total_length) |
460 | word_length = total_length - word_offset; | |
ac188222 DB |
461 | } |
462 | ||
463 | /* Does the value reside in INSN_VALUE, and at the right alignment? */ | |
464 | ||
465 | if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length)) | |
466 | { | |
467 | if (CGEN_INSN_LSB0_P) | |
468 | value = insn_value >> ((word_offset + start + 1) - length); | |
469 | else | |
470 | value = insn_value >> (total_length - ( word_offset + start + length)); | |
471 | } | |
472 | ||
473 | #if ! CGEN_INT_INSN_P | |
474 | ||
475 | else | |
476 | { | |
477 | unsigned char *bufp = ex_info->insn_bytes + word_offset / 8; | |
478 | ||
b7cd1872 | 479 | if (word_length > 8 * sizeof (CGEN_INSN_INT)) |
ac188222 DB |
480 | abort (); |
481 | ||
482 | if (fill_cache (cd, ex_info, word_offset / 8, word_length / 8, pc) == 0) | |
2f5dd314 AM |
483 | { |
484 | *valuep = 0; | |
485 | return 0; | |
486 | } | |
ac188222 DB |
487 | |
488 | value = extract_1 (cd, ex_info, start, length, word_length, bufp, pc); | |
489 | } | |
490 | ||
491 | #endif /* ! CGEN_INT_INSN_P */ | |
492 | ||
493 | /* Written this way to avoid undefined behaviour. */ | |
494 | mask = (((1L << (length - 1)) - 1) << 1) | 1; | |
495 | ||
496 | value &= mask; | |
497 | /* sign extend? */ | |
498 | if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED) | |
499 | && (value & (1L << (length - 1)))) | |
500 | value |= ~mask; | |
501 | ||
502 | *valuep = value; | |
503 | ||
504 | return 1; | |
505 | } | |
506 | ||
507 | /* Default insn extractor. | |
508 | ||
509 | INSN_VALUE is the first base_insn_bitsize bits, translated to host order. | |
510 | The extracted fields are stored in FIELDS. | |
511 | EX_INFO is used to handle reading variable length insns. | |
512 | Return the length of the insn in bits, or 0 if no match, | |
513 | or -1 if an error occurs fetching data (memory_error_func will have | |
514 | been called). */ | |
515 | ||
516 | static int | |
517 | extract_insn_normal (CGEN_CPU_DESC cd, | |
518 | const CGEN_INSN *insn, | |
519 | CGEN_EXTRACT_INFO *ex_info, | |
520 | CGEN_INSN_INT insn_value, | |
521 | CGEN_FIELDS *fields, | |
522 | bfd_vma pc) | |
523 | { | |
524 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); | |
525 | const CGEN_SYNTAX_CHAR_TYPE *syn; | |
526 | ||
527 | CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn); | |
528 | ||
529 | CGEN_INIT_EXTRACT (cd); | |
530 | ||
531 | for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn) | |
532 | { | |
533 | int length; | |
534 | ||
535 | if (CGEN_SYNTAX_CHAR_P (*syn)) | |
536 | continue; | |
537 | ||
538 | length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn), | |
539 | ex_info, insn_value, fields, pc); | |
540 | if (length <= 0) | |
541 | return length; | |
542 | } | |
543 | ||
544 | /* We recognized and successfully extracted this insn. */ | |
545 | return CGEN_INSN_BITSIZE (insn); | |
546 | } | |
547 | \f | |
47b0e7ad | 548 | /* Machine generated code added here. */ |
ac188222 | 549 | |
d031aafb | 550 | const char * mt_cgen_insert_operand |
47b0e7ad | 551 | (CGEN_CPU_DESC, int, CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma); |
ac188222 DB |
552 | |
553 | /* Main entry point for operand insertion. | |
554 | ||
555 | This function is basically just a big switch statement. Earlier versions | |
556 | used tables to look up the function to use, but | |
557 | - if the table contains both assembler and disassembler functions then | |
558 | the disassembler contains much of the assembler and vice-versa, | |
559 | - there's a lot of inlining possibilities as things grow, | |
560 | - using a switch statement avoids the function call overhead. | |
561 | ||
562 | This function could be moved into `parse_insn_normal', but keeping it | |
563 | separate makes clear the interface between `parse_insn_normal' and each of | |
564 | the handlers. It's also needed by GAS to insert operands that couldn't be | |
565 | resolved during parsing. */ | |
566 | ||
567 | const char * | |
d031aafb | 568 | mt_cgen_insert_operand (CGEN_CPU_DESC cd, |
47b0e7ad NC |
569 | int opindex, |
570 | CGEN_FIELDS * fields, | |
571 | CGEN_INSN_BYTES_PTR buffer, | |
572 | bfd_vma pc ATTRIBUTE_UNUSED) | |
ac188222 DB |
573 | { |
574 | const char * errmsg = NULL; | |
575 | unsigned int total_length = CGEN_FIELDS_BITSIZE (fields); | |
576 | ||
577 | switch (opindex) | |
578 | { | |
d031aafb | 579 | case MT_OPERAND_A23 : |
ac188222 DB |
580 | errmsg = insert_normal (cd, fields->f_a23, 0, 0, 23, 1, 32, total_length, buffer); |
581 | break; | |
d031aafb | 582 | case MT_OPERAND_BALL : |
ac188222 DB |
583 | errmsg = insert_normal (cd, fields->f_ball, 0, 0, 19, 1, 32, total_length, buffer); |
584 | break; | |
d031aafb | 585 | case MT_OPERAND_BALL2 : |
ac188222 DB |
586 | errmsg = insert_normal (cd, fields->f_ball2, 0, 0, 15, 1, 32, total_length, buffer); |
587 | break; | |
d031aafb | 588 | case MT_OPERAND_BANKADDR : |
ac188222 DB |
589 | errmsg = insert_normal (cd, fields->f_bankaddr, 0, 0, 25, 13, 32, total_length, buffer); |
590 | break; | |
d031aafb | 591 | case MT_OPERAND_BRC : |
ac188222 DB |
592 | errmsg = insert_normal (cd, fields->f_brc, 0, 0, 18, 3, 32, total_length, buffer); |
593 | break; | |
d031aafb | 594 | case MT_OPERAND_BRC2 : |
ac188222 DB |
595 | errmsg = insert_normal (cd, fields->f_brc2, 0, 0, 14, 3, 32, total_length, buffer); |
596 | break; | |
d031aafb | 597 | case MT_OPERAND_CB1INCR : |
6f84a2a6 NS |
598 | errmsg = insert_normal (cd, fields->f_cb1incr, 0|(1<<CGEN_IFLD_SIGNED), 0, 19, 6, 32, total_length, buffer); |
599 | break; | |
d031aafb | 600 | case MT_OPERAND_CB1SEL : |
6f84a2a6 NS |
601 | errmsg = insert_normal (cd, fields->f_cb1sel, 0, 0, 25, 3, 32, total_length, buffer); |
602 | break; | |
d031aafb | 603 | case MT_OPERAND_CB2INCR : |
6f84a2a6 NS |
604 | errmsg = insert_normal (cd, fields->f_cb2incr, 0|(1<<CGEN_IFLD_SIGNED), 0, 13, 6, 32, total_length, buffer); |
605 | break; | |
d031aafb | 606 | case MT_OPERAND_CB2SEL : |
6f84a2a6 NS |
607 | errmsg = insert_normal (cd, fields->f_cb2sel, 0, 0, 22, 3, 32, total_length, buffer); |
608 | break; | |
d031aafb | 609 | case MT_OPERAND_CBRB : |
ac188222 DB |
610 | errmsg = insert_normal (cd, fields->f_cbrb, 0, 0, 10, 1, 32, total_length, buffer); |
611 | break; | |
d031aafb | 612 | case MT_OPERAND_CBS : |
ac188222 DB |
613 | errmsg = insert_normal (cd, fields->f_cbs, 0, 0, 19, 2, 32, total_length, buffer); |
614 | break; | |
d031aafb | 615 | case MT_OPERAND_CBX : |
ac188222 DB |
616 | errmsg = insert_normal (cd, fields->f_cbx, 0, 0, 14, 3, 32, total_length, buffer); |
617 | break; | |
d031aafb | 618 | case MT_OPERAND_CCB : |
ac188222 DB |
619 | errmsg = insert_normal (cd, fields->f_ccb, 0, 0, 11, 1, 32, total_length, buffer); |
620 | break; | |
d031aafb | 621 | case MT_OPERAND_CDB : |
ac188222 DB |
622 | errmsg = insert_normal (cd, fields->f_cdb, 0, 0, 10, 1, 32, total_length, buffer); |
623 | break; | |
d031aafb | 624 | case MT_OPERAND_CELL : |
ac188222 DB |
625 | errmsg = insert_normal (cd, fields->f_cell, 0, 0, 9, 3, 32, total_length, buffer); |
626 | break; | |
d031aafb | 627 | case MT_OPERAND_COLNUM : |
ac188222 DB |
628 | errmsg = insert_normal (cd, fields->f_colnum, 0, 0, 18, 3, 32, total_length, buffer); |
629 | break; | |
d031aafb | 630 | case MT_OPERAND_CONTNUM : |
ac188222 DB |
631 | errmsg = insert_normal (cd, fields->f_contnum, 0, 0, 8, 9, 32, total_length, buffer); |
632 | break; | |
d031aafb | 633 | case MT_OPERAND_CR : |
ac188222 DB |
634 | errmsg = insert_normal (cd, fields->f_cr, 0, 0, 22, 3, 32, total_length, buffer); |
635 | break; | |
d031aafb | 636 | case MT_OPERAND_CTXDISP : |
ac188222 DB |
637 | errmsg = insert_normal (cd, fields->f_ctxdisp, 0, 0, 5, 6, 32, total_length, buffer); |
638 | break; | |
d031aafb | 639 | case MT_OPERAND_DUP : |
ac188222 DB |
640 | errmsg = insert_normal (cd, fields->f_dup, 0, 0, 6, 1, 32, total_length, buffer); |
641 | break; | |
d031aafb | 642 | case MT_OPERAND_FBDISP : |
ac188222 DB |
643 | errmsg = insert_normal (cd, fields->f_fbdisp, 0, 0, 15, 6, 32, total_length, buffer); |
644 | break; | |
d031aafb | 645 | case MT_OPERAND_FBINCR : |
ac188222 DB |
646 | errmsg = insert_normal (cd, fields->f_fbincr, 0, 0, 23, 4, 32, total_length, buffer); |
647 | break; | |
d031aafb | 648 | case MT_OPERAND_FRDR : |
ac188222 DB |
649 | errmsg = insert_normal (cd, fields->f_dr, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, buffer); |
650 | break; | |
d031aafb | 651 | case MT_OPERAND_FRDRRR : |
ac188222 DB |
652 | errmsg = insert_normal (cd, fields->f_drrr, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 4, 32, total_length, buffer); |
653 | break; | |
d031aafb | 654 | case MT_OPERAND_FRSR1 : |
ac188222 DB |
655 | errmsg = insert_normal (cd, fields->f_sr1, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 23, 4, 32, total_length, buffer); |
656 | break; | |
d031aafb | 657 | case MT_OPERAND_FRSR2 : |
ac188222 DB |
658 | errmsg = insert_normal (cd, fields->f_sr2, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, buffer); |
659 | break; | |
d031aafb | 660 | case MT_OPERAND_ID : |
ac188222 DB |
661 | errmsg = insert_normal (cd, fields->f_id, 0, 0, 14, 1, 32, total_length, buffer); |
662 | break; | |
d031aafb | 663 | case MT_OPERAND_IMM16 : |
ac188222 DB |
664 | { |
665 | long value = fields->f_imm16s; | |
666 | value = ((value) + (0)); | |
667 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, buffer); | |
668 | } | |
669 | break; | |
d031aafb | 670 | case MT_OPERAND_IMM16L : |
6f84a2a6 NS |
671 | errmsg = insert_normal (cd, fields->f_imm16l, 0, 0, 23, 16, 32, total_length, buffer); |
672 | break; | |
d031aafb | 673 | case MT_OPERAND_IMM16O : |
ac188222 DB |
674 | { |
675 | long value = fields->f_imm16s; | |
676 | value = ((value) + (0)); | |
677 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, buffer); | |
678 | } | |
679 | break; | |
d031aafb | 680 | case MT_OPERAND_IMM16Z : |
ac188222 DB |
681 | errmsg = insert_normal (cd, fields->f_imm16u, 0, 0, 15, 16, 32, total_length, buffer); |
682 | break; | |
d031aafb | 683 | case MT_OPERAND_INCAMT : |
ac188222 DB |
684 | errmsg = insert_normal (cd, fields->f_incamt, 0, 0, 19, 8, 32, total_length, buffer); |
685 | break; | |
d031aafb | 686 | case MT_OPERAND_INCR : |
ac188222 DB |
687 | errmsg = insert_normal (cd, fields->f_incr, 0, 0, 17, 6, 32, total_length, buffer); |
688 | break; | |
d031aafb | 689 | case MT_OPERAND_LENGTH : |
ac188222 DB |
690 | errmsg = insert_normal (cd, fields->f_length, 0, 0, 15, 3, 32, total_length, buffer); |
691 | break; | |
d031aafb | 692 | case MT_OPERAND_LOOPSIZE : |
6f84a2a6 NS |
693 | { |
694 | long value = fields->f_loopo; | |
fe8afbc4 | 695 | value = ((USI) (value) >> (2)); |
6f84a2a6 NS |
696 | errmsg = insert_normal (cd, value, 0, 0, 7, 8, 32, total_length, buffer); |
697 | } | |
698 | break; | |
d031aafb | 699 | case MT_OPERAND_MASK : |
ac188222 DB |
700 | errmsg = insert_normal (cd, fields->f_mask, 0, 0, 25, 16, 32, total_length, buffer); |
701 | break; | |
d031aafb | 702 | case MT_OPERAND_MASK1 : |
ac188222 DB |
703 | errmsg = insert_normal (cd, fields->f_mask1, 0, 0, 22, 3, 32, total_length, buffer); |
704 | break; | |
d031aafb | 705 | case MT_OPERAND_MODE : |
ac188222 DB |
706 | errmsg = insert_normal (cd, fields->f_mode, 0, 0, 25, 2, 32, total_length, buffer); |
707 | break; | |
d031aafb | 708 | case MT_OPERAND_PERM : |
ac188222 DB |
709 | errmsg = insert_normal (cd, fields->f_perm, 0, 0, 25, 2, 32, total_length, buffer); |
710 | break; | |
d031aafb | 711 | case MT_OPERAND_RBBC : |
ac188222 DB |
712 | errmsg = insert_normal (cd, fields->f_rbbc, 0, 0, 25, 2, 32, total_length, buffer); |
713 | break; | |
d031aafb | 714 | case MT_OPERAND_RC : |
ac188222 DB |
715 | errmsg = insert_normal (cd, fields->f_rc, 0, 0, 15, 1, 32, total_length, buffer); |
716 | break; | |
d031aafb | 717 | case MT_OPERAND_RC1 : |
ac188222 DB |
718 | errmsg = insert_normal (cd, fields->f_rc1, 0, 0, 11, 1, 32, total_length, buffer); |
719 | break; | |
d031aafb | 720 | case MT_OPERAND_RC2 : |
ac188222 DB |
721 | errmsg = insert_normal (cd, fields->f_rc2, 0, 0, 6, 1, 32, total_length, buffer); |
722 | break; | |
d031aafb | 723 | case MT_OPERAND_RC3 : |
6f84a2a6 NS |
724 | errmsg = insert_normal (cd, fields->f_rc3, 0, 0, 7, 1, 32, total_length, buffer); |
725 | break; | |
d031aafb | 726 | case MT_OPERAND_RCNUM : |
ac188222 DB |
727 | errmsg = insert_normal (cd, fields->f_rcnum, 0, 0, 14, 3, 32, total_length, buffer); |
728 | break; | |
d031aafb | 729 | case MT_OPERAND_RDA : |
ac188222 DB |
730 | errmsg = insert_normal (cd, fields->f_rda, 0, 0, 25, 1, 32, total_length, buffer); |
731 | break; | |
d031aafb | 732 | case MT_OPERAND_ROWNUM : |
ac188222 DB |
733 | errmsg = insert_normal (cd, fields->f_rownum, 0, 0, 14, 3, 32, total_length, buffer); |
734 | break; | |
d031aafb | 735 | case MT_OPERAND_ROWNUM1 : |
ac188222 DB |
736 | errmsg = insert_normal (cd, fields->f_rownum1, 0, 0, 12, 3, 32, total_length, buffer); |
737 | break; | |
d031aafb | 738 | case MT_OPERAND_ROWNUM2 : |
ac188222 DB |
739 | errmsg = insert_normal (cd, fields->f_rownum2, 0, 0, 9, 3, 32, total_length, buffer); |
740 | break; | |
d031aafb | 741 | case MT_OPERAND_SIZE : |
ac188222 DB |
742 | errmsg = insert_normal (cd, fields->f_size, 0, 0, 13, 14, 32, total_length, buffer); |
743 | break; | |
d031aafb | 744 | case MT_OPERAND_TYPE : |
ac188222 DB |
745 | errmsg = insert_normal (cd, fields->f_type, 0, 0, 21, 2, 32, total_length, buffer); |
746 | break; | |
d031aafb | 747 | case MT_OPERAND_WR : |
ac188222 DB |
748 | errmsg = insert_normal (cd, fields->f_wr, 0, 0, 24, 1, 32, total_length, buffer); |
749 | break; | |
d031aafb | 750 | case MT_OPERAND_XMODE : |
ac188222 DB |
751 | errmsg = insert_normal (cd, fields->f_xmode, 0, 0, 23, 1, 32, total_length, buffer); |
752 | break; | |
753 | ||
754 | default : | |
755 | /* xgettext:c-format */ | |
a6743a54 AM |
756 | opcodes_error_handler |
757 | (_("internal error: unrecognized field %d while building insn"), | |
758 | opindex); | |
ac188222 DB |
759 | abort (); |
760 | } | |
761 | ||
762 | return errmsg; | |
763 | } | |
764 | ||
d031aafb | 765 | int mt_cgen_extract_operand |
47b0e7ad | 766 | (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma); |
ac188222 DB |
767 | |
768 | /* Main entry point for operand extraction. | |
769 | The result is <= 0 for error, >0 for success. | |
770 | ??? Actual values aren't well defined right now. | |
771 | ||
772 | This function is basically just a big switch statement. Earlier versions | |
773 | used tables to look up the function to use, but | |
774 | - if the table contains both assembler and disassembler functions then | |
775 | the disassembler contains much of the assembler and vice-versa, | |
776 | - there's a lot of inlining possibilities as things grow, | |
777 | - using a switch statement avoids the function call overhead. | |
778 | ||
779 | This function could be moved into `print_insn_normal', but keeping it | |
780 | separate makes clear the interface between `print_insn_normal' and each of | |
781 | the handlers. */ | |
782 | ||
783 | int | |
d031aafb | 784 | mt_cgen_extract_operand (CGEN_CPU_DESC cd, |
47b0e7ad NC |
785 | int opindex, |
786 | CGEN_EXTRACT_INFO *ex_info, | |
787 | CGEN_INSN_INT insn_value, | |
788 | CGEN_FIELDS * fields, | |
789 | bfd_vma pc) | |
ac188222 DB |
790 | { |
791 | /* Assume success (for those operands that are nops). */ | |
792 | int length = 1; | |
793 | unsigned int total_length = CGEN_FIELDS_BITSIZE (fields); | |
794 | ||
795 | switch (opindex) | |
796 | { | |
d031aafb | 797 | case MT_OPERAND_A23 : |
ac188222 DB |
798 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 1, 32, total_length, pc, & fields->f_a23); |
799 | break; | |
d031aafb | 800 | case MT_OPERAND_BALL : |
ac188222 DB |
801 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 1, 32, total_length, pc, & fields->f_ball); |
802 | break; | |
d031aafb | 803 | case MT_OPERAND_BALL2 : |
ac188222 DB |
804 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 1, 32, total_length, pc, & fields->f_ball2); |
805 | break; | |
d031aafb | 806 | case MT_OPERAND_BANKADDR : |
ac188222 DB |
807 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 13, 32, total_length, pc, & fields->f_bankaddr); |
808 | break; | |
d031aafb | 809 | case MT_OPERAND_BRC : |
ac188222 DB |
810 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 18, 3, 32, total_length, pc, & fields->f_brc); |
811 | break; | |
d031aafb | 812 | case MT_OPERAND_BRC2 : |
ac188222 DB |
813 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_brc2); |
814 | break; | |
d031aafb | 815 | case MT_OPERAND_CB1INCR : |
6f84a2a6 NS |
816 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 19, 6, 32, total_length, pc, & fields->f_cb1incr); |
817 | break; | |
d031aafb | 818 | case MT_OPERAND_CB1SEL : |
6f84a2a6 NS |
819 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 3, 32, total_length, pc, & fields->f_cb1sel); |
820 | break; | |
d031aafb | 821 | case MT_OPERAND_CB2INCR : |
6f84a2a6 NS |
822 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 13, 6, 32, total_length, pc, & fields->f_cb2incr); |
823 | break; | |
d031aafb | 824 | case MT_OPERAND_CB2SEL : |
6f84a2a6 NS |
825 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_cb2sel); |
826 | break; | |
d031aafb | 827 | case MT_OPERAND_CBRB : |
ac188222 DB |
828 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_cbrb); |
829 | break; | |
d031aafb | 830 | case MT_OPERAND_CBS : |
ac188222 DB |
831 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 2, 32, total_length, pc, & fields->f_cbs); |
832 | break; | |
d031aafb | 833 | case MT_OPERAND_CBX : |
ac188222 DB |
834 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_cbx); |
835 | break; | |
d031aafb | 836 | case MT_OPERAND_CCB : |
ac188222 DB |
837 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_ccb); |
838 | break; | |
d031aafb | 839 | case MT_OPERAND_CDB : |
ac188222 DB |
840 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_cdb); |
841 | break; | |
d031aafb | 842 | case MT_OPERAND_CELL : |
ac188222 DB |
843 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 3, 32, total_length, pc, & fields->f_cell); |
844 | break; | |
d031aafb | 845 | case MT_OPERAND_COLNUM : |
ac188222 DB |
846 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 18, 3, 32, total_length, pc, & fields->f_colnum); |
847 | break; | |
d031aafb | 848 | case MT_OPERAND_CONTNUM : |
ac188222 DB |
849 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 9, 32, total_length, pc, & fields->f_contnum); |
850 | break; | |
d031aafb | 851 | case MT_OPERAND_CR : |
ac188222 DB |
852 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_cr); |
853 | break; | |
d031aafb | 854 | case MT_OPERAND_CTXDISP : |
ac188222 DB |
855 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 6, 32, total_length, pc, & fields->f_ctxdisp); |
856 | break; | |
d031aafb | 857 | case MT_OPERAND_DUP : |
ac188222 DB |
858 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 6, 1, 32, total_length, pc, & fields->f_dup); |
859 | break; | |
d031aafb | 860 | case MT_OPERAND_FBDISP : |
ac188222 DB |
861 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 6, 32, total_length, pc, & fields->f_fbdisp); |
862 | break; | |
d031aafb | 863 | case MT_OPERAND_FBINCR : |
ac188222 DB |
864 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 4, 32, total_length, pc, & fields->f_fbincr); |
865 | break; | |
d031aafb | 866 | case MT_OPERAND_FRDR : |
ac188222 DB |
867 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, pc, & fields->f_dr); |
868 | break; | |
d031aafb | 869 | case MT_OPERAND_FRDRRR : |
ac188222 DB |
870 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 15, 4, 32, total_length, pc, & fields->f_drrr); |
871 | break; | |
d031aafb | 872 | case MT_OPERAND_FRSR1 : |
ac188222 DB |
873 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 23, 4, 32, total_length, pc, & fields->f_sr1); |
874 | break; | |
d031aafb | 875 | case MT_OPERAND_FRSR2 : |
ac188222 DB |
876 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_ABS_ADDR), 0, 19, 4, 32, total_length, pc, & fields->f_sr2); |
877 | break; | |
d031aafb | 878 | case MT_OPERAND_ID : |
ac188222 DB |
879 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 1, 32, total_length, pc, & fields->f_id); |
880 | break; | |
d031aafb | 881 | case MT_OPERAND_IMM16 : |
ac188222 DB |
882 | { |
883 | long value; | |
884 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, pc, & value); | |
885 | value = ((value) + (0)); | |
886 | fields->f_imm16s = value; | |
887 | } | |
888 | break; | |
d031aafb | 889 | case MT_OPERAND_IMM16L : |
6f84a2a6 NS |
890 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 16, 32, total_length, pc, & fields->f_imm16l); |
891 | break; | |
d031aafb | 892 | case MT_OPERAND_IMM16O : |
ac188222 DB |
893 | { |
894 | long value; | |
895 | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED), 0, 15, 16, 32, total_length, pc, & value); | |
896 | value = ((value) + (0)); | |
897 | fields->f_imm16s = value; | |
898 | } | |
899 | break; | |
d031aafb | 900 | case MT_OPERAND_IMM16Z : |
ac188222 DB |
901 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_imm16u); |
902 | break; | |
d031aafb | 903 | case MT_OPERAND_INCAMT : |
ac188222 DB |
904 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 19, 8, 32, total_length, pc, & fields->f_incamt); |
905 | break; | |
d031aafb | 906 | case MT_OPERAND_INCR : |
ac188222 DB |
907 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 17, 6, 32, total_length, pc, & fields->f_incr); |
908 | break; | |
d031aafb | 909 | case MT_OPERAND_LENGTH : |
ac188222 DB |
910 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 3, 32, total_length, pc, & fields->f_length); |
911 | break; | |
d031aafb | 912 | case MT_OPERAND_LOOPSIZE : |
6f84a2a6 NS |
913 | { |
914 | long value; | |
915 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 8, 32, total_length, pc, & value); | |
916 | value = ((((value) << (2))) + (8)); | |
917 | fields->f_loopo = value; | |
918 | } | |
919 | break; | |
d031aafb | 920 | case MT_OPERAND_MASK : |
ac188222 DB |
921 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 16, 32, total_length, pc, & fields->f_mask); |
922 | break; | |
d031aafb | 923 | case MT_OPERAND_MASK1 : |
ac188222 DB |
924 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 22, 3, 32, total_length, pc, & fields->f_mask1); |
925 | break; | |
d031aafb | 926 | case MT_OPERAND_MODE : |
ac188222 DB |
927 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_mode); |
928 | break; | |
d031aafb | 929 | case MT_OPERAND_PERM : |
ac188222 DB |
930 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_perm); |
931 | break; | |
d031aafb | 932 | case MT_OPERAND_RBBC : |
ac188222 DB |
933 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 2, 32, total_length, pc, & fields->f_rbbc); |
934 | break; | |
d031aafb | 935 | case MT_OPERAND_RC : |
ac188222 DB |
936 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 1, 32, total_length, pc, & fields->f_rc); |
937 | break; | |
d031aafb | 938 | case MT_OPERAND_RC1 : |
ac188222 DB |
939 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 11, 1, 32, total_length, pc, & fields->f_rc1); |
940 | break; | |
d031aafb | 941 | case MT_OPERAND_RC2 : |
ac188222 DB |
942 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 6, 1, 32, total_length, pc, & fields->f_rc2); |
943 | break; | |
d031aafb | 944 | case MT_OPERAND_RC3 : |
6f84a2a6 NS |
945 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 7, 1, 32, total_length, pc, & fields->f_rc3); |
946 | break; | |
d031aafb | 947 | case MT_OPERAND_RCNUM : |
ac188222 DB |
948 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_rcnum); |
949 | break; | |
d031aafb | 950 | case MT_OPERAND_RDA : |
ac188222 DB |
951 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 1, 32, total_length, pc, & fields->f_rda); |
952 | break; | |
d031aafb | 953 | case MT_OPERAND_ROWNUM : |
ac188222 DB |
954 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 14, 3, 32, total_length, pc, & fields->f_rownum); |
955 | break; | |
d031aafb | 956 | case MT_OPERAND_ROWNUM1 : |
ac188222 DB |
957 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 12, 3, 32, total_length, pc, & fields->f_rownum1); |
958 | break; | |
d031aafb | 959 | case MT_OPERAND_ROWNUM2 : |
ac188222 DB |
960 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 3, 32, total_length, pc, & fields->f_rownum2); |
961 | break; | |
d031aafb | 962 | case MT_OPERAND_SIZE : |
ac188222 DB |
963 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 13, 14, 32, total_length, pc, & fields->f_size); |
964 | break; | |
d031aafb | 965 | case MT_OPERAND_TYPE : |
ac188222 DB |
966 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 21, 2, 32, total_length, pc, & fields->f_type); |
967 | break; | |
d031aafb | 968 | case MT_OPERAND_WR : |
ac188222 DB |
969 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 24, 1, 32, total_length, pc, & fields->f_wr); |
970 | break; | |
d031aafb | 971 | case MT_OPERAND_XMODE : |
ac188222 DB |
972 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 23, 1, 32, total_length, pc, & fields->f_xmode); |
973 | break; | |
974 | ||
975 | default : | |
976 | /* xgettext:c-format */ | |
a6743a54 AM |
977 | opcodes_error_handler |
978 | (_("internal error: unrecognized field %d while decoding insn"), | |
979 | opindex); | |
ac188222 DB |
980 | abort (); |
981 | } | |
982 | ||
983 | return length; | |
984 | } | |
985 | ||
43e65147 | 986 | cgen_insert_fn * const mt_cgen_insert_handlers[] = |
ac188222 DB |
987 | { |
988 | insert_insn_normal, | |
989 | }; | |
990 | ||
43e65147 | 991 | cgen_extract_fn * const mt_cgen_extract_handlers[] = |
ac188222 DB |
992 | { |
993 | extract_insn_normal, | |
994 | }; | |
995 | ||
d031aafb NS |
996 | int mt_cgen_get_int_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *); |
997 | bfd_vma mt_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *); | |
ac188222 DB |
998 | |
999 | /* Getting values from cgen_fields is handled by a collection of functions. | |
1000 | They are distinguished by the type of the VALUE argument they return. | |
1001 | TODO: floating point, inlining support, remove cases where result type | |
1002 | not appropriate. */ | |
1003 | ||
1004 | int | |
d031aafb | 1005 | mt_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
47b0e7ad NC |
1006 | int opindex, |
1007 | const CGEN_FIELDS * fields) | |
ac188222 DB |
1008 | { |
1009 | int value; | |
1010 | ||
1011 | switch (opindex) | |
1012 | { | |
d031aafb | 1013 | case MT_OPERAND_A23 : |
ac188222 DB |
1014 | value = fields->f_a23; |
1015 | break; | |
d031aafb | 1016 | case MT_OPERAND_BALL : |
ac188222 DB |
1017 | value = fields->f_ball; |
1018 | break; | |
d031aafb | 1019 | case MT_OPERAND_BALL2 : |
ac188222 DB |
1020 | value = fields->f_ball2; |
1021 | break; | |
d031aafb | 1022 | case MT_OPERAND_BANKADDR : |
ac188222 DB |
1023 | value = fields->f_bankaddr; |
1024 | break; | |
d031aafb | 1025 | case MT_OPERAND_BRC : |
ac188222 DB |
1026 | value = fields->f_brc; |
1027 | break; | |
d031aafb | 1028 | case MT_OPERAND_BRC2 : |
ac188222 DB |
1029 | value = fields->f_brc2; |
1030 | break; | |
d031aafb | 1031 | case MT_OPERAND_CB1INCR : |
6f84a2a6 NS |
1032 | value = fields->f_cb1incr; |
1033 | break; | |
d031aafb | 1034 | case MT_OPERAND_CB1SEL : |
6f84a2a6 NS |
1035 | value = fields->f_cb1sel; |
1036 | break; | |
d031aafb | 1037 | case MT_OPERAND_CB2INCR : |
6f84a2a6 NS |
1038 | value = fields->f_cb2incr; |
1039 | break; | |
d031aafb | 1040 | case MT_OPERAND_CB2SEL : |
6f84a2a6 NS |
1041 | value = fields->f_cb2sel; |
1042 | break; | |
d031aafb | 1043 | case MT_OPERAND_CBRB : |
ac188222 DB |
1044 | value = fields->f_cbrb; |
1045 | break; | |
d031aafb | 1046 | case MT_OPERAND_CBS : |
ac188222 DB |
1047 | value = fields->f_cbs; |
1048 | break; | |
d031aafb | 1049 | case MT_OPERAND_CBX : |
ac188222 DB |
1050 | value = fields->f_cbx; |
1051 | break; | |
d031aafb | 1052 | case MT_OPERAND_CCB : |
ac188222 DB |
1053 | value = fields->f_ccb; |
1054 | break; | |
d031aafb | 1055 | case MT_OPERAND_CDB : |
ac188222 DB |
1056 | value = fields->f_cdb; |
1057 | break; | |
d031aafb | 1058 | case MT_OPERAND_CELL : |
ac188222 DB |
1059 | value = fields->f_cell; |
1060 | break; | |
d031aafb | 1061 | case MT_OPERAND_COLNUM : |
ac188222 DB |
1062 | value = fields->f_colnum; |
1063 | break; | |
d031aafb | 1064 | case MT_OPERAND_CONTNUM : |
ac188222 DB |
1065 | value = fields->f_contnum; |
1066 | break; | |
d031aafb | 1067 | case MT_OPERAND_CR : |
ac188222 DB |
1068 | value = fields->f_cr; |
1069 | break; | |
d031aafb | 1070 | case MT_OPERAND_CTXDISP : |
ac188222 DB |
1071 | value = fields->f_ctxdisp; |
1072 | break; | |
d031aafb | 1073 | case MT_OPERAND_DUP : |
ac188222 DB |
1074 | value = fields->f_dup; |
1075 | break; | |
d031aafb | 1076 | case MT_OPERAND_FBDISP : |
ac188222 DB |
1077 | value = fields->f_fbdisp; |
1078 | break; | |
d031aafb | 1079 | case MT_OPERAND_FBINCR : |
ac188222 DB |
1080 | value = fields->f_fbincr; |
1081 | break; | |
d031aafb | 1082 | case MT_OPERAND_FRDR : |
ac188222 DB |
1083 | value = fields->f_dr; |
1084 | break; | |
d031aafb | 1085 | case MT_OPERAND_FRDRRR : |
ac188222 DB |
1086 | value = fields->f_drrr; |
1087 | break; | |
d031aafb | 1088 | case MT_OPERAND_FRSR1 : |
ac188222 DB |
1089 | value = fields->f_sr1; |
1090 | break; | |
d031aafb | 1091 | case MT_OPERAND_FRSR2 : |
ac188222 DB |
1092 | value = fields->f_sr2; |
1093 | break; | |
d031aafb | 1094 | case MT_OPERAND_ID : |
ac188222 DB |
1095 | value = fields->f_id; |
1096 | break; | |
d031aafb | 1097 | case MT_OPERAND_IMM16 : |
ac188222 DB |
1098 | value = fields->f_imm16s; |
1099 | break; | |
d031aafb | 1100 | case MT_OPERAND_IMM16L : |
6f84a2a6 NS |
1101 | value = fields->f_imm16l; |
1102 | break; | |
d031aafb | 1103 | case MT_OPERAND_IMM16O : |
ac188222 DB |
1104 | value = fields->f_imm16s; |
1105 | break; | |
d031aafb | 1106 | case MT_OPERAND_IMM16Z : |
ac188222 DB |
1107 | value = fields->f_imm16u; |
1108 | break; | |
d031aafb | 1109 | case MT_OPERAND_INCAMT : |
ac188222 DB |
1110 | value = fields->f_incamt; |
1111 | break; | |
d031aafb | 1112 | case MT_OPERAND_INCR : |
ac188222 DB |
1113 | value = fields->f_incr; |
1114 | break; | |
d031aafb | 1115 | case MT_OPERAND_LENGTH : |
ac188222 DB |
1116 | value = fields->f_length; |
1117 | break; | |
d031aafb | 1118 | case MT_OPERAND_LOOPSIZE : |
6f84a2a6 NS |
1119 | value = fields->f_loopo; |
1120 | break; | |
d031aafb | 1121 | case MT_OPERAND_MASK : |
ac188222 DB |
1122 | value = fields->f_mask; |
1123 | break; | |
d031aafb | 1124 | case MT_OPERAND_MASK1 : |
ac188222 DB |
1125 | value = fields->f_mask1; |
1126 | break; | |
d031aafb | 1127 | case MT_OPERAND_MODE : |
ac188222 DB |
1128 | value = fields->f_mode; |
1129 | break; | |
d031aafb | 1130 | case MT_OPERAND_PERM : |
ac188222 DB |
1131 | value = fields->f_perm; |
1132 | break; | |
d031aafb | 1133 | case MT_OPERAND_RBBC : |
ac188222 DB |
1134 | value = fields->f_rbbc; |
1135 | break; | |
d031aafb | 1136 | case MT_OPERAND_RC : |
ac188222 DB |
1137 | value = fields->f_rc; |
1138 | break; | |
d031aafb | 1139 | case MT_OPERAND_RC1 : |
ac188222 DB |
1140 | value = fields->f_rc1; |
1141 | break; | |
d031aafb | 1142 | case MT_OPERAND_RC2 : |
ac188222 DB |
1143 | value = fields->f_rc2; |
1144 | break; | |
d031aafb | 1145 | case MT_OPERAND_RC3 : |
6f84a2a6 NS |
1146 | value = fields->f_rc3; |
1147 | break; | |
d031aafb | 1148 | case MT_OPERAND_RCNUM : |
ac188222 DB |
1149 | value = fields->f_rcnum; |
1150 | break; | |
d031aafb | 1151 | case MT_OPERAND_RDA : |
ac188222 DB |
1152 | value = fields->f_rda; |
1153 | break; | |
d031aafb | 1154 | case MT_OPERAND_ROWNUM : |
ac188222 DB |
1155 | value = fields->f_rownum; |
1156 | break; | |
d031aafb | 1157 | case MT_OPERAND_ROWNUM1 : |
ac188222 DB |
1158 | value = fields->f_rownum1; |
1159 | break; | |
d031aafb | 1160 | case MT_OPERAND_ROWNUM2 : |
ac188222 DB |
1161 | value = fields->f_rownum2; |
1162 | break; | |
d031aafb | 1163 | case MT_OPERAND_SIZE : |
ac188222 DB |
1164 | value = fields->f_size; |
1165 | break; | |
d031aafb | 1166 | case MT_OPERAND_TYPE : |
ac188222 DB |
1167 | value = fields->f_type; |
1168 | break; | |
d031aafb | 1169 | case MT_OPERAND_WR : |
ac188222 DB |
1170 | value = fields->f_wr; |
1171 | break; | |
d031aafb | 1172 | case MT_OPERAND_XMODE : |
ac188222 DB |
1173 | value = fields->f_xmode; |
1174 | break; | |
1175 | ||
1176 | default : | |
1177 | /* xgettext:c-format */ | |
a6743a54 AM |
1178 | opcodes_error_handler |
1179 | (_("internal error: unrecognized field %d while getting int operand"), | |
1180 | opindex); | |
ac188222 DB |
1181 | abort (); |
1182 | } | |
1183 | ||
1184 | return value; | |
1185 | } | |
1186 | ||
1187 | bfd_vma | |
d031aafb | 1188 | mt_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
47b0e7ad NC |
1189 | int opindex, |
1190 | const CGEN_FIELDS * fields) | |
ac188222 DB |
1191 | { |
1192 | bfd_vma value; | |
1193 | ||
1194 | switch (opindex) | |
1195 | { | |
d031aafb | 1196 | case MT_OPERAND_A23 : |
ac188222 DB |
1197 | value = fields->f_a23; |
1198 | break; | |
d031aafb | 1199 | case MT_OPERAND_BALL : |
ac188222 DB |
1200 | value = fields->f_ball; |
1201 | break; | |
d031aafb | 1202 | case MT_OPERAND_BALL2 : |
ac188222 DB |
1203 | value = fields->f_ball2; |
1204 | break; | |
d031aafb | 1205 | case MT_OPERAND_BANKADDR : |
ac188222 DB |
1206 | value = fields->f_bankaddr; |
1207 | break; | |
d031aafb | 1208 | case MT_OPERAND_BRC : |
ac188222 DB |
1209 | value = fields->f_brc; |
1210 | break; | |
d031aafb | 1211 | case MT_OPERAND_BRC2 : |
ac188222 DB |
1212 | value = fields->f_brc2; |
1213 | break; | |
d031aafb | 1214 | case MT_OPERAND_CB1INCR : |
6f84a2a6 NS |
1215 | value = fields->f_cb1incr; |
1216 | break; | |
d031aafb | 1217 | case MT_OPERAND_CB1SEL : |
6f84a2a6 NS |
1218 | value = fields->f_cb1sel; |
1219 | break; | |
d031aafb | 1220 | case MT_OPERAND_CB2INCR : |
6f84a2a6 NS |
1221 | value = fields->f_cb2incr; |
1222 | break; | |
d031aafb | 1223 | case MT_OPERAND_CB2SEL : |
6f84a2a6 NS |
1224 | value = fields->f_cb2sel; |
1225 | break; | |
d031aafb | 1226 | case MT_OPERAND_CBRB : |
ac188222 DB |
1227 | value = fields->f_cbrb; |
1228 | break; | |
d031aafb | 1229 | case MT_OPERAND_CBS : |
ac188222 DB |
1230 | value = fields->f_cbs; |
1231 | break; | |
d031aafb | 1232 | case MT_OPERAND_CBX : |
ac188222 DB |
1233 | value = fields->f_cbx; |
1234 | break; | |
d031aafb | 1235 | case MT_OPERAND_CCB : |
ac188222 DB |
1236 | value = fields->f_ccb; |
1237 | break; | |
d031aafb | 1238 | case MT_OPERAND_CDB : |
ac188222 DB |
1239 | value = fields->f_cdb; |
1240 | break; | |
d031aafb | 1241 | case MT_OPERAND_CELL : |
ac188222 DB |
1242 | value = fields->f_cell; |
1243 | break; | |
d031aafb | 1244 | case MT_OPERAND_COLNUM : |
ac188222 DB |
1245 | value = fields->f_colnum; |
1246 | break; | |
d031aafb | 1247 | case MT_OPERAND_CONTNUM : |
ac188222 DB |
1248 | value = fields->f_contnum; |
1249 | break; | |
d031aafb | 1250 | case MT_OPERAND_CR : |
ac188222 DB |
1251 | value = fields->f_cr; |
1252 | break; | |
d031aafb | 1253 | case MT_OPERAND_CTXDISP : |
ac188222 DB |
1254 | value = fields->f_ctxdisp; |
1255 | break; | |
d031aafb | 1256 | case MT_OPERAND_DUP : |
ac188222 DB |
1257 | value = fields->f_dup; |
1258 | break; | |
d031aafb | 1259 | case MT_OPERAND_FBDISP : |
ac188222 DB |
1260 | value = fields->f_fbdisp; |
1261 | break; | |
d031aafb | 1262 | case MT_OPERAND_FBINCR : |
ac188222 DB |
1263 | value = fields->f_fbincr; |
1264 | break; | |
d031aafb | 1265 | case MT_OPERAND_FRDR : |
ac188222 DB |
1266 | value = fields->f_dr; |
1267 | break; | |
d031aafb | 1268 | case MT_OPERAND_FRDRRR : |
ac188222 DB |
1269 | value = fields->f_drrr; |
1270 | break; | |
d031aafb | 1271 | case MT_OPERAND_FRSR1 : |
ac188222 DB |
1272 | value = fields->f_sr1; |
1273 | break; | |
d031aafb | 1274 | case MT_OPERAND_FRSR2 : |
ac188222 DB |
1275 | value = fields->f_sr2; |
1276 | break; | |
d031aafb | 1277 | case MT_OPERAND_ID : |
ac188222 DB |
1278 | value = fields->f_id; |
1279 | break; | |
d031aafb | 1280 | case MT_OPERAND_IMM16 : |
ac188222 DB |
1281 | value = fields->f_imm16s; |
1282 | break; | |
d031aafb | 1283 | case MT_OPERAND_IMM16L : |
6f84a2a6 NS |
1284 | value = fields->f_imm16l; |
1285 | break; | |
d031aafb | 1286 | case MT_OPERAND_IMM16O : |
ac188222 DB |
1287 | value = fields->f_imm16s; |
1288 | break; | |
d031aafb | 1289 | case MT_OPERAND_IMM16Z : |
ac188222 DB |
1290 | value = fields->f_imm16u; |
1291 | break; | |
d031aafb | 1292 | case MT_OPERAND_INCAMT : |
ac188222 DB |
1293 | value = fields->f_incamt; |
1294 | break; | |
d031aafb | 1295 | case MT_OPERAND_INCR : |
ac188222 DB |
1296 | value = fields->f_incr; |
1297 | break; | |
d031aafb | 1298 | case MT_OPERAND_LENGTH : |
ac188222 DB |
1299 | value = fields->f_length; |
1300 | break; | |
d031aafb | 1301 | case MT_OPERAND_LOOPSIZE : |
6f84a2a6 NS |
1302 | value = fields->f_loopo; |
1303 | break; | |
d031aafb | 1304 | case MT_OPERAND_MASK : |
ac188222 DB |
1305 | value = fields->f_mask; |
1306 | break; | |
d031aafb | 1307 | case MT_OPERAND_MASK1 : |
ac188222 DB |
1308 | value = fields->f_mask1; |
1309 | break; | |
d031aafb | 1310 | case MT_OPERAND_MODE : |
ac188222 DB |
1311 | value = fields->f_mode; |
1312 | break; | |
d031aafb | 1313 | case MT_OPERAND_PERM : |
ac188222 DB |
1314 | value = fields->f_perm; |
1315 | break; | |
d031aafb | 1316 | case MT_OPERAND_RBBC : |
ac188222 DB |
1317 | value = fields->f_rbbc; |
1318 | break; | |
d031aafb | 1319 | case MT_OPERAND_RC : |
ac188222 DB |
1320 | value = fields->f_rc; |
1321 | break; | |
d031aafb | 1322 | case MT_OPERAND_RC1 : |
ac188222 DB |
1323 | value = fields->f_rc1; |
1324 | break; | |
d031aafb | 1325 | case MT_OPERAND_RC2 : |
ac188222 DB |
1326 | value = fields->f_rc2; |
1327 | break; | |
d031aafb | 1328 | case MT_OPERAND_RC3 : |
6f84a2a6 NS |
1329 | value = fields->f_rc3; |
1330 | break; | |
d031aafb | 1331 | case MT_OPERAND_RCNUM : |
ac188222 DB |
1332 | value = fields->f_rcnum; |
1333 | break; | |
d031aafb | 1334 | case MT_OPERAND_RDA : |
ac188222 DB |
1335 | value = fields->f_rda; |
1336 | break; | |
d031aafb | 1337 | case MT_OPERAND_ROWNUM : |
ac188222 DB |
1338 | value = fields->f_rownum; |
1339 | break; | |
d031aafb | 1340 | case MT_OPERAND_ROWNUM1 : |
ac188222 DB |
1341 | value = fields->f_rownum1; |
1342 | break; | |
d031aafb | 1343 | case MT_OPERAND_ROWNUM2 : |
ac188222 DB |
1344 | value = fields->f_rownum2; |
1345 | break; | |
d031aafb | 1346 | case MT_OPERAND_SIZE : |
ac188222 DB |
1347 | value = fields->f_size; |
1348 | break; | |
d031aafb | 1349 | case MT_OPERAND_TYPE : |
ac188222 DB |
1350 | value = fields->f_type; |
1351 | break; | |
d031aafb | 1352 | case MT_OPERAND_WR : |
ac188222 DB |
1353 | value = fields->f_wr; |
1354 | break; | |
d031aafb | 1355 | case MT_OPERAND_XMODE : |
ac188222 DB |
1356 | value = fields->f_xmode; |
1357 | break; | |
1358 | ||
1359 | default : | |
1360 | /* xgettext:c-format */ | |
a6743a54 AM |
1361 | opcodes_error_handler |
1362 | (_("internal error: unrecognized field %d while getting vma operand"), | |
1363 | opindex); | |
ac188222 DB |
1364 | abort (); |
1365 | } | |
1366 | ||
1367 | return value; | |
1368 | } | |
1369 | ||
d031aafb NS |
1370 | void mt_cgen_set_int_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, int); |
1371 | void mt_cgen_set_vma_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma); | |
ac188222 DB |
1372 | |
1373 | /* Stuffing values in cgen_fields is handled by a collection of functions. | |
1374 | They are distinguished by the type of the VALUE argument they accept. | |
1375 | TODO: floating point, inlining support, remove cases where argument type | |
1376 | not appropriate. */ | |
1377 | ||
1378 | void | |
d031aafb | 1379 | mt_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
47b0e7ad NC |
1380 | int opindex, |
1381 | CGEN_FIELDS * fields, | |
1382 | int value) | |
ac188222 DB |
1383 | { |
1384 | switch (opindex) | |
1385 | { | |
d031aafb | 1386 | case MT_OPERAND_A23 : |
ac188222 DB |
1387 | fields->f_a23 = value; |
1388 | break; | |
d031aafb | 1389 | case MT_OPERAND_BALL : |
ac188222 DB |
1390 | fields->f_ball = value; |
1391 | break; | |
d031aafb | 1392 | case MT_OPERAND_BALL2 : |
ac188222 DB |
1393 | fields->f_ball2 = value; |
1394 | break; | |
d031aafb | 1395 | case MT_OPERAND_BANKADDR : |
ac188222 DB |
1396 | fields->f_bankaddr = value; |
1397 | break; | |
d031aafb | 1398 | case MT_OPERAND_BRC : |
ac188222 DB |
1399 | fields->f_brc = value; |
1400 | break; | |
d031aafb | 1401 | case MT_OPERAND_BRC2 : |
ac188222 DB |
1402 | fields->f_brc2 = value; |
1403 | break; | |
d031aafb | 1404 | case MT_OPERAND_CB1INCR : |
6f84a2a6 NS |
1405 | fields->f_cb1incr = value; |
1406 | break; | |
d031aafb | 1407 | case MT_OPERAND_CB1SEL : |
6f84a2a6 NS |
1408 | fields->f_cb1sel = value; |
1409 | break; | |
d031aafb | 1410 | case MT_OPERAND_CB2INCR : |
6f84a2a6 NS |
1411 | fields->f_cb2incr = value; |
1412 | break; | |
d031aafb | 1413 | case MT_OPERAND_CB2SEL : |
6f84a2a6 NS |
1414 | fields->f_cb2sel = value; |
1415 | break; | |
d031aafb | 1416 | case MT_OPERAND_CBRB : |
ac188222 DB |
1417 | fields->f_cbrb = value; |
1418 | break; | |
d031aafb | 1419 | case MT_OPERAND_CBS : |
ac188222 DB |
1420 | fields->f_cbs = value; |
1421 | break; | |
d031aafb | 1422 | case MT_OPERAND_CBX : |
ac188222 DB |
1423 | fields->f_cbx = value; |
1424 | break; | |
d031aafb | 1425 | case MT_OPERAND_CCB : |
ac188222 DB |
1426 | fields->f_ccb = value; |
1427 | break; | |
d031aafb | 1428 | case MT_OPERAND_CDB : |
ac188222 DB |
1429 | fields->f_cdb = value; |
1430 | break; | |
d031aafb | 1431 | case MT_OPERAND_CELL : |
ac188222 DB |
1432 | fields->f_cell = value; |
1433 | break; | |
d031aafb | 1434 | case MT_OPERAND_COLNUM : |
ac188222 DB |
1435 | fields->f_colnum = value; |
1436 | break; | |
d031aafb | 1437 | case MT_OPERAND_CONTNUM : |
ac188222 DB |
1438 | fields->f_contnum = value; |
1439 | break; | |
d031aafb | 1440 | case MT_OPERAND_CR : |
ac188222 DB |
1441 | fields->f_cr = value; |
1442 | break; | |
d031aafb | 1443 | case MT_OPERAND_CTXDISP : |
ac188222 DB |
1444 | fields->f_ctxdisp = value; |
1445 | break; | |
d031aafb | 1446 | case MT_OPERAND_DUP : |
ac188222 DB |
1447 | fields->f_dup = value; |
1448 | break; | |
d031aafb | 1449 | case MT_OPERAND_FBDISP : |
ac188222 DB |
1450 | fields->f_fbdisp = value; |
1451 | break; | |
d031aafb | 1452 | case MT_OPERAND_FBINCR : |
ac188222 DB |
1453 | fields->f_fbincr = value; |
1454 | break; | |
d031aafb | 1455 | case MT_OPERAND_FRDR : |
ac188222 DB |
1456 | fields->f_dr = value; |
1457 | break; | |
d031aafb | 1458 | case MT_OPERAND_FRDRRR : |
ac188222 DB |
1459 | fields->f_drrr = value; |
1460 | break; | |
d031aafb | 1461 | case MT_OPERAND_FRSR1 : |
ac188222 DB |
1462 | fields->f_sr1 = value; |
1463 | break; | |
d031aafb | 1464 | case MT_OPERAND_FRSR2 : |
ac188222 DB |
1465 | fields->f_sr2 = value; |
1466 | break; | |
d031aafb | 1467 | case MT_OPERAND_ID : |
ac188222 DB |
1468 | fields->f_id = value; |
1469 | break; | |
d031aafb | 1470 | case MT_OPERAND_IMM16 : |
ac188222 DB |
1471 | fields->f_imm16s = value; |
1472 | break; | |
d031aafb | 1473 | case MT_OPERAND_IMM16L : |
6f84a2a6 NS |
1474 | fields->f_imm16l = value; |
1475 | break; | |
d031aafb | 1476 | case MT_OPERAND_IMM16O : |
ac188222 DB |
1477 | fields->f_imm16s = value; |
1478 | break; | |
d031aafb | 1479 | case MT_OPERAND_IMM16Z : |
ac188222 DB |
1480 | fields->f_imm16u = value; |
1481 | break; | |
d031aafb | 1482 | case MT_OPERAND_INCAMT : |
ac188222 DB |
1483 | fields->f_incamt = value; |
1484 | break; | |
d031aafb | 1485 | case MT_OPERAND_INCR : |
ac188222 DB |
1486 | fields->f_incr = value; |
1487 | break; | |
d031aafb | 1488 | case MT_OPERAND_LENGTH : |
ac188222 DB |
1489 | fields->f_length = value; |
1490 | break; | |
d031aafb | 1491 | case MT_OPERAND_LOOPSIZE : |
6f84a2a6 NS |
1492 | fields->f_loopo = value; |
1493 | break; | |
d031aafb | 1494 | case MT_OPERAND_MASK : |
ac188222 DB |
1495 | fields->f_mask = value; |
1496 | break; | |
d031aafb | 1497 | case MT_OPERAND_MASK1 : |
ac188222 DB |
1498 | fields->f_mask1 = value; |
1499 | break; | |
d031aafb | 1500 | case MT_OPERAND_MODE : |
ac188222 DB |
1501 | fields->f_mode = value; |
1502 | break; | |
d031aafb | 1503 | case MT_OPERAND_PERM : |
ac188222 DB |
1504 | fields->f_perm = value; |
1505 | break; | |
d031aafb | 1506 | case MT_OPERAND_RBBC : |
ac188222 DB |
1507 | fields->f_rbbc = value; |
1508 | break; | |
d031aafb | 1509 | case MT_OPERAND_RC : |
ac188222 DB |
1510 | fields->f_rc = value; |
1511 | break; | |
d031aafb | 1512 | case MT_OPERAND_RC1 : |
ac188222 DB |
1513 | fields->f_rc1 = value; |
1514 | break; | |
d031aafb | 1515 | case MT_OPERAND_RC2 : |
ac188222 DB |
1516 | fields->f_rc2 = value; |
1517 | break; | |
d031aafb | 1518 | case MT_OPERAND_RC3 : |
6f84a2a6 NS |
1519 | fields->f_rc3 = value; |
1520 | break; | |
d031aafb | 1521 | case MT_OPERAND_RCNUM : |
ac188222 DB |
1522 | fields->f_rcnum = value; |
1523 | break; | |
d031aafb | 1524 | case MT_OPERAND_RDA : |
ac188222 DB |
1525 | fields->f_rda = value; |
1526 | break; | |
d031aafb | 1527 | case MT_OPERAND_ROWNUM : |
ac188222 DB |
1528 | fields->f_rownum = value; |
1529 | break; | |
d031aafb | 1530 | case MT_OPERAND_ROWNUM1 : |
ac188222 DB |
1531 | fields->f_rownum1 = value; |
1532 | break; | |
d031aafb | 1533 | case MT_OPERAND_ROWNUM2 : |
ac188222 DB |
1534 | fields->f_rownum2 = value; |
1535 | break; | |
d031aafb | 1536 | case MT_OPERAND_SIZE : |
ac188222 DB |
1537 | fields->f_size = value; |
1538 | break; | |
d031aafb | 1539 | case MT_OPERAND_TYPE : |
ac188222 DB |
1540 | fields->f_type = value; |
1541 | break; | |
d031aafb | 1542 | case MT_OPERAND_WR : |
ac188222 DB |
1543 | fields->f_wr = value; |
1544 | break; | |
d031aafb | 1545 | case MT_OPERAND_XMODE : |
ac188222 DB |
1546 | fields->f_xmode = value; |
1547 | break; | |
1548 | ||
1549 | default : | |
1550 | /* xgettext:c-format */ | |
a6743a54 AM |
1551 | opcodes_error_handler |
1552 | (_("internal error: unrecognized field %d while setting int operand"), | |
1553 | opindex); | |
ac188222 DB |
1554 | abort (); |
1555 | } | |
1556 | } | |
1557 | ||
1558 | void | |
d031aafb | 1559 | mt_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
47b0e7ad NC |
1560 | int opindex, |
1561 | CGEN_FIELDS * fields, | |
1562 | bfd_vma value) | |
ac188222 DB |
1563 | { |
1564 | switch (opindex) | |
1565 | { | |
d031aafb | 1566 | case MT_OPERAND_A23 : |
ac188222 DB |
1567 | fields->f_a23 = value; |
1568 | break; | |
d031aafb | 1569 | case MT_OPERAND_BALL : |
ac188222 DB |
1570 | fields->f_ball = value; |
1571 | break; | |
d031aafb | 1572 | case MT_OPERAND_BALL2 : |
ac188222 DB |
1573 | fields->f_ball2 = value; |
1574 | break; | |
d031aafb | 1575 | case MT_OPERAND_BANKADDR : |
ac188222 DB |
1576 | fields->f_bankaddr = value; |
1577 | break; | |
d031aafb | 1578 | case MT_OPERAND_BRC : |
ac188222 DB |
1579 | fields->f_brc = value; |
1580 | break; | |
d031aafb | 1581 | case MT_OPERAND_BRC2 : |
ac188222 DB |
1582 | fields->f_brc2 = value; |
1583 | break; | |
d031aafb | 1584 | case MT_OPERAND_CB1INCR : |
6f84a2a6 NS |
1585 | fields->f_cb1incr = value; |
1586 | break; | |
d031aafb | 1587 | case MT_OPERAND_CB1SEL : |
6f84a2a6 NS |
1588 | fields->f_cb1sel = value; |
1589 | break; | |
d031aafb | 1590 | case MT_OPERAND_CB2INCR : |
6f84a2a6 NS |
1591 | fields->f_cb2incr = value; |
1592 | break; | |
d031aafb | 1593 | case MT_OPERAND_CB2SEL : |
6f84a2a6 NS |
1594 | fields->f_cb2sel = value; |
1595 | break; | |
d031aafb | 1596 | case MT_OPERAND_CBRB : |
ac188222 DB |
1597 | fields->f_cbrb = value; |
1598 | break; | |
d031aafb | 1599 | case MT_OPERAND_CBS : |
ac188222 DB |
1600 | fields->f_cbs = value; |
1601 | break; | |
d031aafb | 1602 | case MT_OPERAND_CBX : |
ac188222 DB |
1603 | fields->f_cbx = value; |
1604 | break; | |
d031aafb | 1605 | case MT_OPERAND_CCB : |
ac188222 DB |
1606 | fields->f_ccb = value; |
1607 | break; | |
d031aafb | 1608 | case MT_OPERAND_CDB : |
ac188222 DB |
1609 | fields->f_cdb = value; |
1610 | break; | |
d031aafb | 1611 | case MT_OPERAND_CELL : |
ac188222 DB |
1612 | fields->f_cell = value; |
1613 | break; | |
d031aafb | 1614 | case MT_OPERAND_COLNUM : |
ac188222 DB |
1615 | fields->f_colnum = value; |
1616 | break; | |
d031aafb | 1617 | case MT_OPERAND_CONTNUM : |
ac188222 DB |
1618 | fields->f_contnum = value; |
1619 | break; | |
d031aafb | 1620 | case MT_OPERAND_CR : |
ac188222 DB |
1621 | fields->f_cr = value; |
1622 | break; | |
d031aafb | 1623 | case MT_OPERAND_CTXDISP : |
ac188222 DB |
1624 | fields->f_ctxdisp = value; |
1625 | break; | |
d031aafb | 1626 | case MT_OPERAND_DUP : |
ac188222 DB |
1627 | fields->f_dup = value; |
1628 | break; | |
d031aafb | 1629 | case MT_OPERAND_FBDISP : |
ac188222 DB |
1630 | fields->f_fbdisp = value; |
1631 | break; | |
d031aafb | 1632 | case MT_OPERAND_FBINCR : |
ac188222 DB |
1633 | fields->f_fbincr = value; |
1634 | break; | |
d031aafb | 1635 | case MT_OPERAND_FRDR : |
ac188222 DB |
1636 | fields->f_dr = value; |
1637 | break; | |
d031aafb | 1638 | case MT_OPERAND_FRDRRR : |
ac188222 DB |
1639 | fields->f_drrr = value; |
1640 | break; | |
d031aafb | 1641 | case MT_OPERAND_FRSR1 : |
ac188222 DB |
1642 | fields->f_sr1 = value; |
1643 | break; | |
d031aafb | 1644 | case MT_OPERAND_FRSR2 : |
ac188222 DB |
1645 | fields->f_sr2 = value; |
1646 | break; | |
d031aafb | 1647 | case MT_OPERAND_ID : |
ac188222 DB |
1648 | fields->f_id = value; |
1649 | break; | |
d031aafb | 1650 | case MT_OPERAND_IMM16 : |
ac188222 DB |
1651 | fields->f_imm16s = value; |
1652 | break; | |
d031aafb | 1653 | case MT_OPERAND_IMM16L : |
6f84a2a6 NS |
1654 | fields->f_imm16l = value; |
1655 | break; | |
d031aafb | 1656 | case MT_OPERAND_IMM16O : |
ac188222 DB |
1657 | fields->f_imm16s = value; |
1658 | break; | |
d031aafb | 1659 | case MT_OPERAND_IMM16Z : |
ac188222 DB |
1660 | fields->f_imm16u = value; |
1661 | break; | |
d031aafb | 1662 | case MT_OPERAND_INCAMT : |
ac188222 DB |
1663 | fields->f_incamt = value; |
1664 | break; | |
d031aafb | 1665 | case MT_OPERAND_INCR : |
ac188222 DB |
1666 | fields->f_incr = value; |
1667 | break; | |
d031aafb | 1668 | case MT_OPERAND_LENGTH : |
ac188222 DB |
1669 | fields->f_length = value; |
1670 | break; | |
d031aafb | 1671 | case MT_OPERAND_LOOPSIZE : |
6f84a2a6 NS |
1672 | fields->f_loopo = value; |
1673 | break; | |
d031aafb | 1674 | case MT_OPERAND_MASK : |
ac188222 DB |
1675 | fields->f_mask = value; |
1676 | break; | |
d031aafb | 1677 | case MT_OPERAND_MASK1 : |
ac188222 DB |
1678 | fields->f_mask1 = value; |
1679 | break; | |
d031aafb | 1680 | case MT_OPERAND_MODE : |
ac188222 DB |
1681 | fields->f_mode = value; |
1682 | break; | |
d031aafb | 1683 | case MT_OPERAND_PERM : |
ac188222 DB |
1684 | fields->f_perm = value; |
1685 | break; | |
d031aafb | 1686 | case MT_OPERAND_RBBC : |
ac188222 DB |
1687 | fields->f_rbbc = value; |
1688 | break; | |
d031aafb | 1689 | case MT_OPERAND_RC : |
ac188222 DB |
1690 | fields->f_rc = value; |
1691 | break; | |
d031aafb | 1692 | case MT_OPERAND_RC1 : |
ac188222 DB |
1693 | fields->f_rc1 = value; |
1694 | break; | |
d031aafb | 1695 | case MT_OPERAND_RC2 : |
ac188222 DB |
1696 | fields->f_rc2 = value; |
1697 | break; | |
d031aafb | 1698 | case MT_OPERAND_RC3 : |
6f84a2a6 NS |
1699 | fields->f_rc3 = value; |
1700 | break; | |
d031aafb | 1701 | case MT_OPERAND_RCNUM : |
ac188222 DB |
1702 | fields->f_rcnum = value; |
1703 | break; | |
d031aafb | 1704 | case MT_OPERAND_RDA : |
ac188222 DB |
1705 | fields->f_rda = value; |
1706 | break; | |
d031aafb | 1707 | case MT_OPERAND_ROWNUM : |
ac188222 DB |
1708 | fields->f_rownum = value; |
1709 | break; | |
d031aafb | 1710 | case MT_OPERAND_ROWNUM1 : |
ac188222 DB |
1711 | fields->f_rownum1 = value; |
1712 | break; | |
d031aafb | 1713 | case MT_OPERAND_ROWNUM2 : |
ac188222 DB |
1714 | fields->f_rownum2 = value; |
1715 | break; | |
d031aafb | 1716 | case MT_OPERAND_SIZE : |
ac188222 DB |
1717 | fields->f_size = value; |
1718 | break; | |
d031aafb | 1719 | case MT_OPERAND_TYPE : |
ac188222 DB |
1720 | fields->f_type = value; |
1721 | break; | |
d031aafb | 1722 | case MT_OPERAND_WR : |
ac188222 DB |
1723 | fields->f_wr = value; |
1724 | break; | |
d031aafb | 1725 | case MT_OPERAND_XMODE : |
ac188222 DB |
1726 | fields->f_xmode = value; |
1727 | break; | |
1728 | ||
1729 | default : | |
1730 | /* xgettext:c-format */ | |
a6743a54 AM |
1731 | opcodes_error_handler |
1732 | (_("internal error: unrecognized field %d while setting vma operand"), | |
1733 | opindex); | |
ac188222 DB |
1734 | abort (); |
1735 | } | |
1736 | } | |
1737 | ||
1738 | /* Function to call before using the instruction builder tables. */ | |
1739 | ||
1740 | void | |
d031aafb | 1741 | mt_cgen_init_ibld_table (CGEN_CPU_DESC cd) |
ac188222 | 1742 | { |
d031aafb NS |
1743 | cd->insert_handlers = & mt_cgen_insert_handlers[0]; |
1744 | cd->extract_handlers = & mt_cgen_extract_handlers[0]; | |
ac188222 | 1745 | |
d031aafb NS |
1746 | cd->insert_operand = mt_cgen_insert_operand; |
1747 | cd->extract_operand = mt_cgen_extract_operand; | |
ac188222 | 1748 | |
d031aafb NS |
1749 | cd->get_int_operand = mt_cgen_get_int_operand; |
1750 | cd->set_int_operand = mt_cgen_set_int_operand; | |
1751 | cd->get_vma_operand = mt_cgen_get_vma_operand; | |
1752 | cd->set_vma_operand = mt_cgen_set_vma_operand; | |
ac188222 | 1753 | } |