/src/binutils-gdb/opcodes/or1k-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 or1k. -*- 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 "or1k-desc.h" |
35 | | #include "or1k-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 | 25.1k | #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 | 150k | { |
444 | 150k | 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 | 150k | if (length == 0) |
449 | 0 | { |
450 | 0 | *valuep = 0; |
451 | 0 | return 1; |
452 | 0 | } |
453 | | |
454 | 150k | 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 | 150k | if (cd->min_insn_bitsize < cd->base_insn_bitsize) |
460 | 0 | { |
461 | 0 | if (word_offset + word_length > total_length) |
462 | 0 | word_length = total_length - word_offset; |
463 | 0 | } |
464 | | |
465 | | /* Does the value reside in INSN_VALUE, and at the right alignment? */ |
466 | | |
467 | 150k | if (CGEN_INT_INSN_P || (word_offset == 0 && word_length == total_length)) |
468 | 150k | { |
469 | 150k | if (CGEN_INSN_LSB0_P) |
470 | 150k | value = insn_value >> ((word_offset + start + 1) - length); |
471 | 0 | else |
472 | 0 | value = insn_value >> (total_length - ( word_offset + start + length)); |
473 | 150k | } |
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 | 150k | mask = (1UL << (length - 1) << 1) - 1; |
497 | | |
498 | 150k | value &= mask; |
499 | | /* sign extend? */ |
500 | 150k | if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED) |
501 | 150k | && (value & (1UL << (length - 1)))) |
502 | 12.9k | value |= ~mask; |
503 | | |
504 | 150k | *valuep = value; |
505 | | |
506 | 150k | return 1; |
507 | 150k | } |
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 | 87.2k | { |
526 | 87.2k | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); |
527 | 87.2k | const CGEN_SYNTAX_CHAR_TYPE *syn; |
528 | | |
529 | 87.2k | CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn); |
530 | | |
531 | 87.2k | CGEN_INIT_EXTRACT (cd); |
532 | | |
533 | 475k | for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn) |
534 | 387k | { |
535 | 387k | int length; |
536 | | |
537 | 387k | if (CGEN_SYNTAX_CHAR_P (*syn)) |
538 | 245k | continue; |
539 | | |
540 | 142k | length = (* cd->extract_operand) (cd, CGEN_SYNTAX_FIELD (*syn), |
541 | 142k | ex_info, insn_value, fields, pc); |
542 | 142k | if (length <= 0) |
543 | 0 | return length; |
544 | 142k | } |
545 | | |
546 | | /* We recognized and successfully extracted this insn. */ |
547 | 87.2k | return CGEN_INSN_BITSIZE (insn); |
548 | 87.2k | } |
549 | | |
550 | | /* Machine generated code added here. */ |
551 | | |
552 | | const char * or1k_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 | | or1k_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 OR1K_OPERAND_DISP21 : |
582 | 0 | { |
583 | 0 | long value = fields->f_disp21; |
584 | 0 | value = ((((SI) (value) >> (13))) - (((SI) (pc) >> (13)))); |
585 | 0 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, buffer); |
586 | 0 | } |
587 | 0 | break; |
588 | 0 | case OR1K_OPERAND_DISP26 : |
589 | 0 | { |
590 | 0 | long value = fields->f_disp26; |
591 | 0 | value = ((SI) (((value) - (pc))) >> (2)); |
592 | 0 | errmsg = insert_normal (cd, value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 25, 26, 32, total_length, buffer); |
593 | 0 | } |
594 | 0 | break; |
595 | 0 | case OR1K_OPERAND_RA : |
596 | 0 | errmsg = insert_normal (cd, fields->f_r2, 0, 0, 20, 5, 32, total_length, buffer); |
597 | 0 | break; |
598 | 0 | case OR1K_OPERAND_RAD32F : |
599 | 0 | { |
600 | 0 | { |
601 | 0 | FLD (f_r2) = ((FLD (f_rad32)) & (31)); |
602 | 0 | FLD (f_raoff_9_1) = ((((SI) (FLD (f_rad32)) >> (5))) & (1)); |
603 | 0 | } |
604 | 0 | errmsg = insert_normal (cd, fields->f_r2, 0, 0, 20, 5, 32, total_length, buffer); |
605 | 0 | if (errmsg) |
606 | 0 | break; |
607 | 0 | errmsg = insert_normal (cd, fields->f_raoff_9_1, 0, 0, 9, 1, 32, total_length, buffer); |
608 | 0 | if (errmsg) |
609 | 0 | break; |
610 | 0 | } |
611 | 0 | break; |
612 | 0 | case OR1K_OPERAND_RADI : |
613 | 0 | { |
614 | 0 | { |
615 | 0 | FLD (f_r2) = ((FLD (f_rad32)) & (31)); |
616 | 0 | FLD (f_raoff_9_1) = ((((SI) (FLD (f_rad32)) >> (5))) & (1)); |
617 | 0 | } |
618 | 0 | errmsg = insert_normal (cd, fields->f_r2, 0, 0, 20, 5, 32, total_length, buffer); |
619 | 0 | if (errmsg) |
620 | 0 | break; |
621 | 0 | errmsg = insert_normal (cd, fields->f_raoff_9_1, 0, 0, 9, 1, 32, total_length, buffer); |
622 | 0 | if (errmsg) |
623 | 0 | break; |
624 | 0 | } |
625 | 0 | break; |
626 | 0 | case OR1K_OPERAND_RASF : |
627 | 0 | errmsg = insert_normal (cd, fields->f_r2, 0, 0, 20, 5, 32, total_length, buffer); |
628 | 0 | break; |
629 | 0 | case OR1K_OPERAND_RB : |
630 | 0 | errmsg = insert_normal (cd, fields->f_r3, 0, 0, 15, 5, 32, total_length, buffer); |
631 | 0 | break; |
632 | 0 | case OR1K_OPERAND_RBD32F : |
633 | 0 | { |
634 | 0 | { |
635 | 0 | FLD (f_r3) = ((FLD (f_rbd32)) & (31)); |
636 | 0 | FLD (f_rboff_8_1) = ((((SI) (FLD (f_rbd32)) >> (5))) & (1)); |
637 | 0 | } |
638 | 0 | errmsg = insert_normal (cd, fields->f_r3, 0, 0, 15, 5, 32, total_length, buffer); |
639 | 0 | if (errmsg) |
640 | 0 | break; |
641 | 0 | errmsg = insert_normal (cd, fields->f_rboff_8_1, 0, 0, 8, 1, 32, total_length, buffer); |
642 | 0 | if (errmsg) |
643 | 0 | break; |
644 | 0 | } |
645 | 0 | break; |
646 | 0 | case OR1K_OPERAND_RBDI : |
647 | 0 | { |
648 | 0 | { |
649 | 0 | FLD (f_r3) = ((FLD (f_rbd32)) & (31)); |
650 | 0 | FLD (f_rboff_8_1) = ((((SI) (FLD (f_rbd32)) >> (5))) & (1)); |
651 | 0 | } |
652 | 0 | errmsg = insert_normal (cd, fields->f_r3, 0, 0, 15, 5, 32, total_length, buffer); |
653 | 0 | if (errmsg) |
654 | 0 | break; |
655 | 0 | errmsg = insert_normal (cd, fields->f_rboff_8_1, 0, 0, 8, 1, 32, total_length, buffer); |
656 | 0 | if (errmsg) |
657 | 0 | break; |
658 | 0 | } |
659 | 0 | break; |
660 | 0 | case OR1K_OPERAND_RBSF : |
661 | 0 | errmsg = insert_normal (cd, fields->f_r3, 0, 0, 15, 5, 32, total_length, buffer); |
662 | 0 | break; |
663 | 0 | case OR1K_OPERAND_RD : |
664 | 0 | errmsg = insert_normal (cd, fields->f_r1, 0, 0, 25, 5, 32, total_length, buffer); |
665 | 0 | break; |
666 | 0 | case OR1K_OPERAND_RDD32F : |
667 | 0 | { |
668 | 0 | { |
669 | 0 | FLD (f_r1) = ((FLD (f_rdd32)) & (31)); |
670 | 0 | FLD (f_rdoff_10_1) = ((((SI) (FLD (f_rdd32)) >> (5))) & (1)); |
671 | 0 | } |
672 | 0 | errmsg = insert_normal (cd, fields->f_r1, 0, 0, 25, 5, 32, total_length, buffer); |
673 | 0 | if (errmsg) |
674 | 0 | break; |
675 | 0 | errmsg = insert_normal (cd, fields->f_rdoff_10_1, 0, 0, 10, 1, 32, total_length, buffer); |
676 | 0 | if (errmsg) |
677 | 0 | break; |
678 | 0 | } |
679 | 0 | break; |
680 | 0 | case OR1K_OPERAND_RDDI : |
681 | 0 | { |
682 | 0 | { |
683 | 0 | FLD (f_r1) = ((FLD (f_rdd32)) & (31)); |
684 | 0 | FLD (f_rdoff_10_1) = ((((SI) (FLD (f_rdd32)) >> (5))) & (1)); |
685 | 0 | } |
686 | 0 | errmsg = insert_normal (cd, fields->f_r1, 0, 0, 25, 5, 32, total_length, buffer); |
687 | 0 | if (errmsg) |
688 | 0 | break; |
689 | 0 | errmsg = insert_normal (cd, fields->f_rdoff_10_1, 0, 0, 10, 1, 32, total_length, buffer); |
690 | 0 | if (errmsg) |
691 | 0 | break; |
692 | 0 | } |
693 | 0 | break; |
694 | 0 | case OR1K_OPERAND_RDSF : |
695 | 0 | errmsg = insert_normal (cd, fields->f_r1, 0, 0, 25, 5, 32, total_length, buffer); |
696 | 0 | break; |
697 | 0 | case OR1K_OPERAND_SIMM16 : |
698 | 0 | errmsg = insert_normal (cd, fields->f_simm16, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_SIGN_OPT), 0, 15, 16, 32, total_length, buffer); |
699 | 0 | break; |
700 | 0 | case OR1K_OPERAND_SIMM16_SPLIT : |
701 | 0 | { |
702 | 0 | { |
703 | 0 | FLD (f_imm16_25_5) = ((((INT) (FLD (f_simm16_split)) >> (11))) & (31)); |
704 | 0 | FLD (f_imm16_10_11) = ((FLD (f_simm16_split)) & (2047)); |
705 | 0 | } |
706 | 0 | errmsg = insert_normal (cd, fields->f_imm16_25_5, 0, 0, 25, 5, 32, total_length, buffer); |
707 | 0 | if (errmsg) |
708 | 0 | break; |
709 | 0 | errmsg = insert_normal (cd, fields->f_imm16_10_11, 0, 0, 10, 11, 32, total_length, buffer); |
710 | 0 | if (errmsg) |
711 | 0 | break; |
712 | 0 | } |
713 | 0 | break; |
714 | 0 | case OR1K_OPERAND_UIMM16 : |
715 | 0 | errmsg = insert_normal (cd, fields->f_uimm16, 0, 0, 15, 16, 32, total_length, buffer); |
716 | 0 | break; |
717 | 0 | case OR1K_OPERAND_UIMM16_SPLIT : |
718 | 0 | { |
719 | 0 | { |
720 | 0 | FLD (f_imm16_25_5) = ((((UINT) (FLD (f_uimm16_split)) >> (11))) & (31)); |
721 | 0 | FLD (f_imm16_10_11) = ((FLD (f_uimm16_split)) & (2047)); |
722 | 0 | } |
723 | 0 | errmsg = insert_normal (cd, fields->f_imm16_25_5, 0, 0, 25, 5, 32, total_length, buffer); |
724 | 0 | if (errmsg) |
725 | 0 | break; |
726 | 0 | errmsg = insert_normal (cd, fields->f_imm16_10_11, 0, 0, 10, 11, 32, total_length, buffer); |
727 | 0 | if (errmsg) |
728 | 0 | break; |
729 | 0 | } |
730 | 0 | break; |
731 | 0 | case OR1K_OPERAND_UIMM6 : |
732 | 0 | errmsg = insert_normal (cd, fields->f_uimm6, 0, 0, 5, 6, 32, total_length, buffer); |
733 | 0 | break; |
734 | | |
735 | 0 | default : |
736 | | /* xgettext:c-format */ |
737 | 0 | opcodes_error_handler |
738 | 0 | (_("internal error: unrecognized field %d while building insn"), |
739 | 0 | opindex); |
740 | 0 | abort (); |
741 | 0 | } |
742 | | |
743 | 0 | return errmsg; |
744 | 0 | } |
745 | | |
746 | | int or1k_cgen_extract_operand |
747 | | (CGEN_CPU_DESC, int, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma); |
748 | | |
749 | | /* Main entry point for operand extraction. |
750 | | The result is <= 0 for error, >0 for success. |
751 | | ??? Actual values aren't well defined right now. |
752 | | |
753 | | This function is basically just a big switch statement. Earlier versions |
754 | | used tables to look up the function to use, but |
755 | | - if the table contains both assembler and disassembler functions then |
756 | | the disassembler contains much of the assembler and vice-versa, |
757 | | - there's a lot of inlining possibilities as things grow, |
758 | | - using a switch statement avoids the function call overhead. |
759 | | |
760 | | This function could be moved into `print_insn_normal', but keeping it |
761 | | separate makes clear the interface between `print_insn_normal' and each of |
762 | | the handlers. */ |
763 | | |
764 | | int |
765 | | or1k_cgen_extract_operand (CGEN_CPU_DESC cd, |
766 | | int opindex, |
767 | | CGEN_EXTRACT_INFO *ex_info, |
768 | | CGEN_INSN_INT insn_value, |
769 | | CGEN_FIELDS * fields, |
770 | | bfd_vma pc) |
771 | 142k | { |
772 | | /* Assume success (for those operands that are nops). */ |
773 | 142k | int length = 1; |
774 | 142k | unsigned int total_length = CGEN_FIELDS_BITSIZE (fields); |
775 | | |
776 | 142k | switch (opindex) |
777 | 142k | { |
778 | 2.45k | case OR1K_OPERAND_DISP21 : |
779 | 2.45k | { |
780 | 2.45k | long value; |
781 | 2.45k | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_ABS_ADDR), 0, 20, 21, 32, total_length, pc, & value); |
782 | 2.45k | value = ((((value) + (((SI) (pc) >> (13))))) * (8192)); |
783 | 2.45k | fields->f_disp21 = value; |
784 | 2.45k | } |
785 | 2.45k | break; |
786 | 57.5k | case OR1K_OPERAND_DISP26 : |
787 | 57.5k | { |
788 | 57.5k | long value; |
789 | 57.5k | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 25, 26, 32, total_length, pc, & value); |
790 | 57.5k | value = ((((value) * (4))) + (pc)); |
791 | 57.5k | fields->f_disp26 = value; |
792 | 57.5k | } |
793 | 57.5k | break; |
794 | 25.8k | case OR1K_OPERAND_RA : |
795 | 25.8k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_r2); |
796 | 25.8k | break; |
797 | 74 | case OR1K_OPERAND_RAD32F : |
798 | 74 | { |
799 | 74 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_r2); |
800 | 74 | if (length <= 0) break; |
801 | 74 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 1, 32, total_length, pc, & fields->f_raoff_9_1); |
802 | 74 | if (length <= 0) break; |
803 | 74 | FLD (f_rad32) = ((FLD (f_r2)) | (((FLD (f_raoff_9_1)) << (5)))); |
804 | 74 | } |
805 | 0 | break; |
806 | 3 | case OR1K_OPERAND_RADI : |
807 | 3 | { |
808 | 3 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_r2); |
809 | 3 | if (length <= 0) break; |
810 | 3 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 9, 1, 32, total_length, pc, & fields->f_raoff_9_1); |
811 | 3 | if (length <= 0) break; |
812 | 3 | FLD (f_rad32) = ((FLD (f_r2)) | (((FLD (f_raoff_9_1)) << (5)))); |
813 | 3 | } |
814 | 0 | break; |
815 | 447 | case OR1K_OPERAND_RASF : |
816 | 447 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 20, 5, 32, total_length, pc, & fields->f_r2); |
817 | 447 | break; |
818 | 8.56k | case OR1K_OPERAND_RB : |
819 | 8.56k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_r3); |
820 | 8.56k | break; |
821 | 74 | case OR1K_OPERAND_RBD32F : |
822 | 74 | { |
823 | 74 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_r3); |
824 | 74 | if (length <= 0) break; |
825 | 74 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 1, 32, total_length, pc, & fields->f_rboff_8_1); |
826 | 74 | if (length <= 0) break; |
827 | 74 | FLD (f_rbd32) = ((FLD (f_r3)) | (((FLD (f_rboff_8_1)) << (5)))); |
828 | 74 | } |
829 | 0 | break; |
830 | 0 | case OR1K_OPERAND_RBDI : |
831 | 0 | { |
832 | 0 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_r3); |
833 | 0 | if (length <= 0) break; |
834 | 0 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 8, 1, 32, total_length, pc, & fields->f_rboff_8_1); |
835 | 0 | if (length <= 0) break; |
836 | 0 | FLD (f_rbd32) = ((FLD (f_r3)) | (((FLD (f_rboff_8_1)) << (5)))); |
837 | 0 | } |
838 | 0 | break; |
839 | 447 | case OR1K_OPERAND_RBSF : |
840 | 447 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 5, 32, total_length, pc, & fields->f_r3); |
841 | 447 | break; |
842 | 20.0k | case OR1K_OPERAND_RD : |
843 | 20.0k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_r1); |
844 | 20.0k | break; |
845 | 76 | case OR1K_OPERAND_RDD32F : |
846 | 76 | { |
847 | 76 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_r1); |
848 | 76 | if (length <= 0) break; |
849 | 76 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_rdoff_10_1); |
850 | 76 | if (length <= 0) break; |
851 | 76 | FLD (f_rdd32) = ((FLD (f_r1)) | (((FLD (f_rdoff_10_1)) << (5)))); |
852 | 76 | } |
853 | 0 | break; |
854 | 0 | case OR1K_OPERAND_RDDI : |
855 | 0 | { |
856 | 0 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_r1); |
857 | 0 | if (length <= 0) break; |
858 | 0 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 1, 32, total_length, pc, & fields->f_rdoff_10_1); |
859 | 0 | if (length <= 0) break; |
860 | 0 | FLD (f_rdd32) = ((FLD (f_r1)) | (((FLD (f_rdoff_10_1)) << (5)))); |
861 | 0 | } |
862 | 0 | break; |
863 | 446 | case OR1K_OPERAND_RDSF : |
864 | 446 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_r1); |
865 | 446 | break; |
866 | 13.0k | case OR1K_OPERAND_SIMM16 : |
867 | 13.0k | length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_SIGN_OPT), 0, 15, 16, 32, total_length, pc, & fields->f_simm16); |
868 | 13.0k | break; |
869 | 6.86k | case OR1K_OPERAND_SIMM16_SPLIT : |
870 | 6.86k | { |
871 | 6.86k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_imm16_25_5); |
872 | 6.86k | if (length <= 0) break; |
873 | 6.86k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 11, 32, total_length, pc, & fields->f_imm16_10_11); |
874 | 6.86k | if (length <= 0) break; |
875 | 6.86k | FLD (f_simm16_split) = ((HI) (UINT) (((((FLD (f_imm16_25_5)) << (11))) | (FLD (f_imm16_10_11))))); |
876 | 6.86k | } |
877 | 0 | break; |
878 | 4.59k | case OR1K_OPERAND_UIMM16 : |
879 | 4.59k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 15, 16, 32, total_length, pc, & fields->f_uimm16); |
880 | 4.59k | break; |
881 | 1.29k | case OR1K_OPERAND_UIMM16_SPLIT : |
882 | 1.29k | { |
883 | 1.29k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 25, 5, 32, total_length, pc, & fields->f_imm16_25_5); |
884 | 1.29k | if (length <= 0) break; |
885 | 1.29k | length = extract_normal (cd, ex_info, insn_value, 0, 0, 10, 11, 32, total_length, pc, & fields->f_imm16_10_11); |
886 | 1.29k | if (length <= 0) break; |
887 | 1.29k | FLD (f_uimm16_split) = ((UHI) (UINT) (((((FLD (f_imm16_25_5)) << (11))) | (FLD (f_imm16_10_11))))); |
888 | 1.29k | } |
889 | 0 | break; |
890 | 248 | case OR1K_OPERAND_UIMM6 : |
891 | 248 | length = extract_normal (cd, ex_info, insn_value, 0, 0, 5, 6, 32, total_length, pc, & fields->f_uimm6); |
892 | 248 | break; |
893 | | |
894 | 0 | default : |
895 | | /* xgettext:c-format */ |
896 | 0 | opcodes_error_handler |
897 | 0 | (_("internal error: unrecognized field %d while decoding insn"), |
898 | 0 | opindex); |
899 | 0 | abort (); |
900 | 142k | } |
901 | | |
902 | 142k | return length; |
903 | 142k | } |
904 | | |
905 | | cgen_insert_fn * const or1k_cgen_insert_handlers[] = |
906 | | { |
907 | | insert_insn_normal, |
908 | | }; |
909 | | |
910 | | cgen_extract_fn * const or1k_cgen_extract_handlers[] = |
911 | | { |
912 | | extract_insn_normal, |
913 | | }; |
914 | | |
915 | | int or1k_cgen_get_int_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *); |
916 | | bfd_vma or1k_cgen_get_vma_operand (CGEN_CPU_DESC, int, const CGEN_FIELDS *); |
917 | | |
918 | | /* Getting values from cgen_fields is handled by a collection of functions. |
919 | | They are distinguished by the type of the VALUE argument they return. |
920 | | TODO: floating point, inlining support, remove cases where result type |
921 | | not appropriate. */ |
922 | | |
923 | | int |
924 | | or1k_cgen_get_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
925 | | int opindex, |
926 | | const CGEN_FIELDS * fields) |
927 | 0 | { |
928 | 0 | int value; |
929 | |
|
930 | 0 | switch (opindex) |
931 | 0 | { |
932 | 0 | case OR1K_OPERAND_DISP21 : |
933 | 0 | value = fields->f_disp21; |
934 | 0 | break; |
935 | 0 | case OR1K_OPERAND_DISP26 : |
936 | 0 | value = fields->f_disp26; |
937 | 0 | break; |
938 | 0 | case OR1K_OPERAND_RA : |
939 | 0 | value = fields->f_r2; |
940 | 0 | break; |
941 | 0 | case OR1K_OPERAND_RAD32F : |
942 | 0 | value = fields->f_rad32; |
943 | 0 | break; |
944 | 0 | case OR1K_OPERAND_RADI : |
945 | 0 | value = fields->f_rad32; |
946 | 0 | break; |
947 | 0 | case OR1K_OPERAND_RASF : |
948 | 0 | value = fields->f_r2; |
949 | 0 | break; |
950 | 0 | case OR1K_OPERAND_RB : |
951 | 0 | value = fields->f_r3; |
952 | 0 | break; |
953 | 0 | case OR1K_OPERAND_RBD32F : |
954 | 0 | value = fields->f_rbd32; |
955 | 0 | break; |
956 | 0 | case OR1K_OPERAND_RBDI : |
957 | 0 | value = fields->f_rbd32; |
958 | 0 | break; |
959 | 0 | case OR1K_OPERAND_RBSF : |
960 | 0 | value = fields->f_r3; |
961 | 0 | break; |
962 | 0 | case OR1K_OPERAND_RD : |
963 | 0 | value = fields->f_r1; |
964 | 0 | break; |
965 | 0 | case OR1K_OPERAND_RDD32F : |
966 | 0 | value = fields->f_rdd32; |
967 | 0 | break; |
968 | 0 | case OR1K_OPERAND_RDDI : |
969 | 0 | value = fields->f_rdd32; |
970 | 0 | break; |
971 | 0 | case OR1K_OPERAND_RDSF : |
972 | 0 | value = fields->f_r1; |
973 | 0 | break; |
974 | 0 | case OR1K_OPERAND_SIMM16 : |
975 | 0 | value = fields->f_simm16; |
976 | 0 | break; |
977 | 0 | case OR1K_OPERAND_SIMM16_SPLIT : |
978 | 0 | value = fields->f_simm16_split; |
979 | 0 | break; |
980 | 0 | case OR1K_OPERAND_UIMM16 : |
981 | 0 | value = fields->f_uimm16; |
982 | 0 | break; |
983 | 0 | case OR1K_OPERAND_UIMM16_SPLIT : |
984 | 0 | value = fields->f_uimm16_split; |
985 | 0 | break; |
986 | 0 | case OR1K_OPERAND_UIMM6 : |
987 | 0 | value = fields->f_uimm6; |
988 | 0 | break; |
989 | | |
990 | 0 | default : |
991 | | /* xgettext:c-format */ |
992 | 0 | opcodes_error_handler |
993 | 0 | (_("internal error: unrecognized field %d while getting int operand"), |
994 | 0 | opindex); |
995 | 0 | abort (); |
996 | 0 | } |
997 | | |
998 | 0 | return value; |
999 | 0 | } |
1000 | | |
1001 | | bfd_vma |
1002 | | or1k_cgen_get_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
1003 | | int opindex, |
1004 | | const CGEN_FIELDS * fields) |
1005 | 0 | { |
1006 | 0 | bfd_vma value; |
1007 | |
|
1008 | 0 | switch (opindex) |
1009 | 0 | { |
1010 | 0 | case OR1K_OPERAND_DISP21 : |
1011 | 0 | value = fields->f_disp21; |
1012 | 0 | break; |
1013 | 0 | case OR1K_OPERAND_DISP26 : |
1014 | 0 | value = fields->f_disp26; |
1015 | 0 | break; |
1016 | 0 | case OR1K_OPERAND_RA : |
1017 | 0 | value = fields->f_r2; |
1018 | 0 | break; |
1019 | 0 | case OR1K_OPERAND_RAD32F : |
1020 | 0 | value = fields->f_rad32; |
1021 | 0 | break; |
1022 | 0 | case OR1K_OPERAND_RADI : |
1023 | 0 | value = fields->f_rad32; |
1024 | 0 | break; |
1025 | 0 | case OR1K_OPERAND_RASF : |
1026 | 0 | value = fields->f_r2; |
1027 | 0 | break; |
1028 | 0 | case OR1K_OPERAND_RB : |
1029 | 0 | value = fields->f_r3; |
1030 | 0 | break; |
1031 | 0 | case OR1K_OPERAND_RBD32F : |
1032 | 0 | value = fields->f_rbd32; |
1033 | 0 | break; |
1034 | 0 | case OR1K_OPERAND_RBDI : |
1035 | 0 | value = fields->f_rbd32; |
1036 | 0 | break; |
1037 | 0 | case OR1K_OPERAND_RBSF : |
1038 | 0 | value = fields->f_r3; |
1039 | 0 | break; |
1040 | 0 | case OR1K_OPERAND_RD : |
1041 | 0 | value = fields->f_r1; |
1042 | 0 | break; |
1043 | 0 | case OR1K_OPERAND_RDD32F : |
1044 | 0 | value = fields->f_rdd32; |
1045 | 0 | break; |
1046 | 0 | case OR1K_OPERAND_RDDI : |
1047 | 0 | value = fields->f_rdd32; |
1048 | 0 | break; |
1049 | 0 | case OR1K_OPERAND_RDSF : |
1050 | 0 | value = fields->f_r1; |
1051 | 0 | break; |
1052 | 0 | case OR1K_OPERAND_SIMM16 : |
1053 | 0 | value = fields->f_simm16; |
1054 | 0 | break; |
1055 | 0 | case OR1K_OPERAND_SIMM16_SPLIT : |
1056 | 0 | value = fields->f_simm16_split; |
1057 | 0 | break; |
1058 | 0 | case OR1K_OPERAND_UIMM16 : |
1059 | 0 | value = fields->f_uimm16; |
1060 | 0 | break; |
1061 | 0 | case OR1K_OPERAND_UIMM16_SPLIT : |
1062 | 0 | value = fields->f_uimm16_split; |
1063 | 0 | break; |
1064 | 0 | case OR1K_OPERAND_UIMM6 : |
1065 | 0 | value = fields->f_uimm6; |
1066 | 0 | break; |
1067 | | |
1068 | 0 | default : |
1069 | | /* xgettext:c-format */ |
1070 | 0 | opcodes_error_handler |
1071 | 0 | (_("internal error: unrecognized field %d while getting vma operand"), |
1072 | 0 | opindex); |
1073 | 0 | abort (); |
1074 | 0 | } |
1075 | | |
1076 | 0 | return value; |
1077 | 0 | } |
1078 | | |
1079 | | void or1k_cgen_set_int_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, int); |
1080 | | void or1k_cgen_set_vma_operand (CGEN_CPU_DESC, int, CGEN_FIELDS *, bfd_vma); |
1081 | | |
1082 | | /* Stuffing values in cgen_fields is handled by a collection of functions. |
1083 | | They are distinguished by the type of the VALUE argument they accept. |
1084 | | TODO: floating point, inlining support, remove cases where argument type |
1085 | | not appropriate. */ |
1086 | | |
1087 | | void |
1088 | | or1k_cgen_set_int_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
1089 | | int opindex, |
1090 | | CGEN_FIELDS * fields, |
1091 | | int value) |
1092 | 0 | { |
1093 | 0 | switch (opindex) |
1094 | 0 | { |
1095 | 0 | case OR1K_OPERAND_DISP21 : |
1096 | 0 | fields->f_disp21 = value; |
1097 | 0 | break; |
1098 | 0 | case OR1K_OPERAND_DISP26 : |
1099 | 0 | fields->f_disp26 = value; |
1100 | 0 | break; |
1101 | 0 | case OR1K_OPERAND_RA : |
1102 | 0 | fields->f_r2 = value; |
1103 | 0 | break; |
1104 | 0 | case OR1K_OPERAND_RAD32F : |
1105 | 0 | fields->f_rad32 = value; |
1106 | 0 | break; |
1107 | 0 | case OR1K_OPERAND_RADI : |
1108 | 0 | fields->f_rad32 = value; |
1109 | 0 | break; |
1110 | 0 | case OR1K_OPERAND_RASF : |
1111 | 0 | fields->f_r2 = value; |
1112 | 0 | break; |
1113 | 0 | case OR1K_OPERAND_RB : |
1114 | 0 | fields->f_r3 = value; |
1115 | 0 | break; |
1116 | 0 | case OR1K_OPERAND_RBD32F : |
1117 | 0 | fields->f_rbd32 = value; |
1118 | 0 | break; |
1119 | 0 | case OR1K_OPERAND_RBDI : |
1120 | 0 | fields->f_rbd32 = value; |
1121 | 0 | break; |
1122 | 0 | case OR1K_OPERAND_RBSF : |
1123 | 0 | fields->f_r3 = value; |
1124 | 0 | break; |
1125 | 0 | case OR1K_OPERAND_RD : |
1126 | 0 | fields->f_r1 = value; |
1127 | 0 | break; |
1128 | 0 | case OR1K_OPERAND_RDD32F : |
1129 | 0 | fields->f_rdd32 = value; |
1130 | 0 | break; |
1131 | 0 | case OR1K_OPERAND_RDDI : |
1132 | 0 | fields->f_rdd32 = value; |
1133 | 0 | break; |
1134 | 0 | case OR1K_OPERAND_RDSF : |
1135 | 0 | fields->f_r1 = value; |
1136 | 0 | break; |
1137 | 0 | case OR1K_OPERAND_SIMM16 : |
1138 | 0 | fields->f_simm16 = value; |
1139 | 0 | break; |
1140 | 0 | case OR1K_OPERAND_SIMM16_SPLIT : |
1141 | 0 | fields->f_simm16_split = value; |
1142 | 0 | break; |
1143 | 0 | case OR1K_OPERAND_UIMM16 : |
1144 | 0 | fields->f_uimm16 = value; |
1145 | 0 | break; |
1146 | 0 | case OR1K_OPERAND_UIMM16_SPLIT : |
1147 | 0 | fields->f_uimm16_split = value; |
1148 | 0 | break; |
1149 | 0 | case OR1K_OPERAND_UIMM6 : |
1150 | 0 | fields->f_uimm6 = value; |
1151 | 0 | break; |
1152 | | |
1153 | 0 | default : |
1154 | | /* xgettext:c-format */ |
1155 | 0 | opcodes_error_handler |
1156 | 0 | (_("internal error: unrecognized field %d while setting int operand"), |
1157 | 0 | opindex); |
1158 | 0 | abort (); |
1159 | 0 | } |
1160 | 0 | } |
1161 | | |
1162 | | void |
1163 | | or1k_cgen_set_vma_operand (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
1164 | | int opindex, |
1165 | | CGEN_FIELDS * fields, |
1166 | | bfd_vma value) |
1167 | 0 | { |
1168 | 0 | switch (opindex) |
1169 | 0 | { |
1170 | 0 | case OR1K_OPERAND_DISP21 : |
1171 | 0 | fields->f_disp21 = value; |
1172 | 0 | break; |
1173 | 0 | case OR1K_OPERAND_DISP26 : |
1174 | 0 | fields->f_disp26 = value; |
1175 | 0 | break; |
1176 | 0 | case OR1K_OPERAND_RA : |
1177 | 0 | fields->f_r2 = value; |
1178 | 0 | break; |
1179 | 0 | case OR1K_OPERAND_RAD32F : |
1180 | 0 | fields->f_rad32 = value; |
1181 | 0 | break; |
1182 | 0 | case OR1K_OPERAND_RADI : |
1183 | 0 | fields->f_rad32 = value; |
1184 | 0 | break; |
1185 | 0 | case OR1K_OPERAND_RASF : |
1186 | 0 | fields->f_r2 = value; |
1187 | 0 | break; |
1188 | 0 | case OR1K_OPERAND_RB : |
1189 | 0 | fields->f_r3 = value; |
1190 | 0 | break; |
1191 | 0 | case OR1K_OPERAND_RBD32F : |
1192 | 0 | fields->f_rbd32 = value; |
1193 | 0 | break; |
1194 | 0 | case OR1K_OPERAND_RBDI : |
1195 | 0 | fields->f_rbd32 = value; |
1196 | 0 | break; |
1197 | 0 | case OR1K_OPERAND_RBSF : |
1198 | 0 | fields->f_r3 = value; |
1199 | 0 | break; |
1200 | 0 | case OR1K_OPERAND_RD : |
1201 | 0 | fields->f_r1 = value; |
1202 | 0 | break; |
1203 | 0 | case OR1K_OPERAND_RDD32F : |
1204 | 0 | fields->f_rdd32 = value; |
1205 | 0 | break; |
1206 | 0 | case OR1K_OPERAND_RDDI : |
1207 | 0 | fields->f_rdd32 = value; |
1208 | 0 | break; |
1209 | 0 | case OR1K_OPERAND_RDSF : |
1210 | 0 | fields->f_r1 = value; |
1211 | 0 | break; |
1212 | 0 | case OR1K_OPERAND_SIMM16 : |
1213 | 0 | fields->f_simm16 = value; |
1214 | 0 | break; |
1215 | 0 | case OR1K_OPERAND_SIMM16_SPLIT : |
1216 | 0 | fields->f_simm16_split = value; |
1217 | 0 | break; |
1218 | 0 | case OR1K_OPERAND_UIMM16 : |
1219 | 0 | fields->f_uimm16 = value; |
1220 | 0 | break; |
1221 | 0 | case OR1K_OPERAND_UIMM16_SPLIT : |
1222 | 0 | fields->f_uimm16_split = value; |
1223 | 0 | break; |
1224 | 0 | case OR1K_OPERAND_UIMM6 : |
1225 | 0 | fields->f_uimm6 = value; |
1226 | 0 | break; |
1227 | | |
1228 | 0 | default : |
1229 | | /* xgettext:c-format */ |
1230 | 0 | opcodes_error_handler |
1231 | 0 | (_("internal error: unrecognized field %d while setting vma operand"), |
1232 | 0 | opindex); |
1233 | 0 | abort (); |
1234 | 0 | } |
1235 | 0 | } |
1236 | | |
1237 | | /* Function to call before using the instruction builder tables. */ |
1238 | | |
1239 | | void |
1240 | | or1k_cgen_init_ibld_table (CGEN_CPU_DESC cd) |
1241 | 5 | { |
1242 | 5 | cd->insert_handlers = & or1k_cgen_insert_handlers[0]; |
1243 | 5 | cd->extract_handlers = & or1k_cgen_extract_handlers[0]; |
1244 | | |
1245 | 5 | cd->insert_operand = or1k_cgen_insert_operand; |
1246 | 5 | cd->extract_operand = or1k_cgen_extract_operand; |
1247 | | |
1248 | 5 | cd->get_int_operand = or1k_cgen_get_int_operand; |
1249 | 5 | cd->set_int_operand = or1k_cgen_set_int_operand; |
1250 | 5 | cd->get_vma_operand = or1k_cgen_get_vma_operand; |
1251 | 5 | cd->set_vma_operand = or1k_cgen_set_vma_operand; |
1252 | 5 | } |