1 /* Configurable Xtensa ISA support.
2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
24 #include "xtensa-isa.h"
25 #include "xtensa-isa-internal.h"
27 xtensa_isa_status xtisa_errno
;
28 char xtisa_error_msg
[1024];
32 xtensa_isa_errno (xtensa_isa isa
__attribute__ ((unused
)))
39 xtensa_isa_error_msg (xtensa_isa isa
__attribute__ ((unused
)))
41 return xtisa_error_msg
;
45 #define CHECK_ALLOC(MEM,ERRVAL) \
49 xtisa_errno = xtensa_isa_out_of_memory; \
50 strcpy (xtisa_error_msg, "out of memory"); \
55 #define CHECK_ALLOC_FOR_INIT(MEM,ERRVAL,ERRNO_P,ERROR_MSG_P) \
59 xtisa_errno = xtensa_isa_out_of_memory; \
60 strcpy (xtisa_error_msg, "out of memory"); \
61 if (ERRNO_P) *(ERRNO_P) = xtisa_errno; \
62 if (ERROR_MSG_P) *(ERROR_MSG_P) = xtisa_error_msg; \
69 /* Instruction buffers. */
72 xtensa_insnbuf_size (xtensa_isa isa
)
74 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
75 return intisa
->insnbuf_size
;
80 xtensa_insnbuf_alloc (xtensa_isa isa
)
82 xtensa_insnbuf result
= (xtensa_insnbuf
)
83 malloc (xtensa_insnbuf_size (isa
) * sizeof (xtensa_insnbuf_word
));
84 CHECK_ALLOC (result
, 0);
90 xtensa_insnbuf_free (xtensa_isa isa
__attribute__ ((unused
)),
97 /* Given <byte_index>, the index of a byte in a xtensa_insnbuf, our
98 internal representation of a xtensa instruction word, return the index of
99 its word and the bit index of its low order byte in the xtensa_insnbuf. */
102 byte_to_word_index (int byte_index
)
104 return byte_index
/ sizeof (xtensa_insnbuf_word
);
109 byte_to_bit_index (int byte_index
)
111 return (byte_index
& 0x3) * 8;
115 /* Copy an instruction in the 32-bit words pointed at by "insn" to
116 characters pointed at by "cp". This is more complicated than you
117 might think because we want 16-bit instructions in bytes 2 & 3 for
118 big-endian configurations. This function allows us to specify
119 which byte in "insn" to start with and which way to increment,
120 allowing trivial implementation for both big- and little-endian
121 configurations....and it seems to make pretty good code for
125 xtensa_insnbuf_to_chars (xtensa_isa isa
,
126 const xtensa_insnbuf insn
,
130 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
131 int insn_size
= xtensa_isa_maxlength (isa
);
132 int fence_post
, start
, increment
, i
, byte_count
;
136 num_chars
= insn_size
;
138 if (intisa
->is_big_endian
)
140 start
= insn_size
- 1;
149 /* Find the instruction format. Do nothing if the buffer does not contain
150 a valid instruction since we need to know how many bytes to copy. */
151 fmt
= xtensa_format_decode (isa
, insn
);
152 if (fmt
== XTENSA_UNDEFINED
)
153 return XTENSA_UNDEFINED
;
155 byte_count
= xtensa_format_length (isa
, fmt
);
156 if (byte_count
== XTENSA_UNDEFINED
)
157 return XTENSA_UNDEFINED
;
159 if (byte_count
> num_chars
)
161 xtisa_errno
= xtensa_isa_buffer_overflow
;
162 strcpy (xtisa_error_msg
, "output buffer too small for instruction");
163 return XTENSA_UNDEFINED
;
166 fence_post
= start
+ (byte_count
* increment
);
168 for (i
= start
; i
!= fence_post
; i
+= increment
, ++cp
)
170 int word_inx
= byte_to_word_index (i
);
171 int bit_inx
= byte_to_bit_index (i
);
173 *cp
= (insn
[word_inx
] >> bit_inx
) & 0xff;
180 /* Inward conversion from byte stream to xtensa_insnbuf. See
181 xtensa_insnbuf_to_chars for a discussion of why this is complicated
185 xtensa_insnbuf_from_chars (xtensa_isa isa
,
187 const unsigned char *cp
,
190 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
191 int max_size
, insn_size
, fence_post
, start
, increment
, i
;
193 max_size
= xtensa_isa_maxlength (isa
);
195 /* Decode the instruction length so we know how many bytes to read. */
196 insn_size
= (intisa
->length_decode_fn
) (cp
);
197 if (insn_size
== XTENSA_UNDEFINED
)
199 /* This should never happen when the byte stream contains a
200 valid instruction. Just read the maximum number of bytes.... */
201 insn_size
= max_size
;
204 if (num_chars
== 0 || num_chars
> insn_size
)
205 num_chars
= insn_size
;
207 if (intisa
->is_big_endian
)
209 start
= max_size
- 1;
218 fence_post
= start
+ (num_chars
* increment
);
219 memset (insn
, 0, xtensa_insnbuf_size (isa
) * sizeof (xtensa_insnbuf_word
));
221 for (i
= start
; i
!= fence_post
; i
+= increment
, ++cp
)
223 int word_inx
= byte_to_word_index (i
);
224 int bit_inx
= byte_to_bit_index (i
);
226 insn
[word_inx
] |= (unsigned) (*cp
& 0xff) << bit_inx
;
232 /* ISA information. */
234 extern xtensa_isa_internal xtensa_modules
;
237 xtensa_isa_init (xtensa_isa_status
*errno_p
, char **error_msg_p
)
239 xtensa_isa_internal
*isa
= &xtensa_modules
;
242 /* Set up the opcode name lookup table. */
243 isa
->opname_lookup_table
=
244 bfd_malloc (isa
->num_opcodes
* sizeof (xtensa_lookup_entry
));
245 CHECK_ALLOC_FOR_INIT (isa
->opname_lookup_table
, NULL
, errno_p
, error_msg_p
);
246 for (n
= 0; n
< isa
->num_opcodes
; n
++)
248 isa
->opname_lookup_table
[n
].key
= isa
->opcodes
[n
].name
;
249 isa
->opname_lookup_table
[n
].u
.opcode
= n
;
251 qsort (isa
->opname_lookup_table
, isa
->num_opcodes
,
252 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
254 /* Set up the state name lookup table. */
255 isa
->state_lookup_table
=
256 bfd_malloc (isa
->num_states
* sizeof (xtensa_lookup_entry
));
257 CHECK_ALLOC_FOR_INIT (isa
->state_lookup_table
, NULL
, errno_p
, error_msg_p
);
258 for (n
= 0; n
< isa
->num_states
; n
++)
260 isa
->state_lookup_table
[n
].key
= isa
->states
[n
].name
;
261 isa
->state_lookup_table
[n
].u
.state
= n
;
263 qsort (isa
->state_lookup_table
, isa
->num_states
,
264 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
266 /* Set up the sysreg name lookup table. */
267 isa
->sysreg_lookup_table
=
268 bfd_malloc (isa
->num_sysregs
* sizeof (xtensa_lookup_entry
));
269 CHECK_ALLOC_FOR_INIT (isa
->sysreg_lookup_table
, NULL
, errno_p
, error_msg_p
);
270 for (n
= 0; n
< isa
->num_sysregs
; n
++)
272 isa
->sysreg_lookup_table
[n
].key
= isa
->sysregs
[n
].name
;
273 isa
->sysreg_lookup_table
[n
].u
.sysreg
= n
;
275 qsort (isa
->sysreg_lookup_table
, isa
->num_sysregs
,
276 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
278 /* Set up the user & system sysreg number tables. */
279 for (is_user
= 0; is_user
< 2; is_user
++)
281 isa
->sysreg_table
[is_user
] =
282 bfd_malloc ((isa
->max_sysreg_num
[is_user
] + 1)
283 * sizeof (xtensa_sysreg
));
284 CHECK_ALLOC_FOR_INIT (isa
->sysreg_table
[is_user
], NULL
,
285 errno_p
, error_msg_p
);
287 for (n
= 0; n
<= isa
->max_sysreg_num
[is_user
]; n
++)
288 isa
->sysreg_table
[is_user
][n
] = XTENSA_UNDEFINED
;
290 for (n
= 0; n
< isa
->num_sysregs
; n
++)
292 xtensa_sysreg_internal
*sreg
= &isa
->sysregs
[n
];
293 is_user
= sreg
->is_user
;
295 if (sreg
->number
>= 0)
296 isa
->sysreg_table
[is_user
][sreg
->number
] = n
;
299 /* Set up the interface lookup table. */
300 isa
->interface_lookup_table
=
301 bfd_malloc (isa
->num_interfaces
* sizeof (xtensa_lookup_entry
));
302 CHECK_ALLOC_FOR_INIT (isa
->interface_lookup_table
, NULL
, errno_p
,
304 for (n
= 0; n
< isa
->num_interfaces
; n
++)
306 isa
->interface_lookup_table
[n
].key
= isa
->interfaces
[n
].name
;
307 isa
->interface_lookup_table
[n
].u
.intf
= n
;
309 qsort (isa
->interface_lookup_table
, isa
->num_interfaces
,
310 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
312 /* Set up the funcUnit lookup table. */
313 isa
->funcUnit_lookup_table
=
314 bfd_malloc (isa
->num_funcUnits
* sizeof (xtensa_lookup_entry
));
315 CHECK_ALLOC_FOR_INIT (isa
->funcUnit_lookup_table
, NULL
, errno_p
,
317 for (n
= 0; n
< isa
->num_funcUnits
; n
++)
319 isa
->funcUnit_lookup_table
[n
].key
= isa
->funcUnits
[n
].name
;
320 isa
->funcUnit_lookup_table
[n
].u
.fun
= n
;
322 qsort (isa
->funcUnit_lookup_table
, isa
->num_funcUnits
,
323 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
325 isa
->insnbuf_size
= ((isa
->insn_size
+ sizeof (xtensa_insnbuf_word
) - 1) /
326 sizeof (xtensa_insnbuf_word
));
328 return (xtensa_isa
) isa
;
333 xtensa_isa_free (xtensa_isa isa
)
335 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
338 /* With this version of the code, the xtensa_isa structure is not
339 dynamically allocated, so this function is not essential. Free
340 the memory allocated by xtensa_isa_init and restore the xtensa_isa
341 structure to its initial state. */
343 free (intisa
->opname_lookup_table
);
344 intisa
->opname_lookup_table
= 0;
346 free (intisa
->state_lookup_table
);
347 intisa
->state_lookup_table
= 0;
349 free (intisa
->sysreg_lookup_table
);
350 intisa
->sysreg_lookup_table
= 0;
352 for (n
= 0; n
< 2; n
++)
354 free (intisa
->sysreg_table
[n
]);
355 intisa
->sysreg_table
[n
] = 0;
358 free (intisa
->interface_lookup_table
);
359 intisa
->interface_lookup_table
= 0;
361 free (intisa
->funcUnit_lookup_table
);
362 intisa
->funcUnit_lookup_table
= 0;
367 xtensa_isa_name_compare (const void *v1
, const void *v2
)
369 xtensa_lookup_entry
*e1
= (xtensa_lookup_entry
*) v1
;
370 xtensa_lookup_entry
*e2
= (xtensa_lookup_entry
*) v2
;
372 return strcasecmp (e1
->key
, e2
->key
);
377 xtensa_isa_maxlength (xtensa_isa isa
)
379 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
380 return intisa
->insn_size
;
385 xtensa_isa_length_from_chars (xtensa_isa isa
, const unsigned char *cp
)
387 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
388 return (intisa
->length_decode_fn
) (cp
);
393 xtensa_isa_num_pipe_stages (xtensa_isa isa
)
395 xtensa_opcode opcode
;
396 xtensa_funcUnit_use
*use
;
397 int num_opcodes
, num_uses
;
399 static int max_stage
= XTENSA_UNDEFINED
;
401 /* Only compute the value once. */
402 if (max_stage
!= XTENSA_UNDEFINED
)
403 return max_stage
+ 1;
405 num_opcodes
= xtensa_isa_num_opcodes (isa
);
406 for (opcode
= 0; opcode
< num_opcodes
; opcode
++)
408 num_uses
= xtensa_opcode_num_funcUnit_uses (isa
, opcode
);
409 for (i
= 0; i
< num_uses
; i
++)
411 use
= xtensa_opcode_funcUnit_use (isa
, opcode
, i
);
413 if (stage
> max_stage
)
418 return max_stage
+ 1;
423 xtensa_isa_num_formats (xtensa_isa isa
)
425 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
426 return intisa
->num_formats
;
431 xtensa_isa_num_opcodes (xtensa_isa isa
)
433 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
434 return intisa
->num_opcodes
;
439 xtensa_isa_num_regfiles (xtensa_isa isa
)
441 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
442 return intisa
->num_regfiles
;
447 xtensa_isa_num_states (xtensa_isa isa
)
449 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
450 return intisa
->num_states
;
455 xtensa_isa_num_sysregs (xtensa_isa isa
)
457 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
458 return intisa
->num_sysregs
;
463 xtensa_isa_num_interfaces (xtensa_isa isa
)
465 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
466 return intisa
->num_interfaces
;
471 xtensa_isa_num_funcUnits (xtensa_isa isa
)
473 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
474 return intisa
->num_funcUnits
;
479 /* Instruction formats. */
482 #define CHECK_FORMAT(INTISA,FMT,ERRVAL) \
484 if ((FMT) < 0 || (FMT) >= (INTISA)->num_formats) \
486 xtisa_errno = xtensa_isa_bad_format; \
487 strcpy (xtisa_error_msg, "invalid format specifier"); \
493 #define CHECK_SLOT(INTISA,FMT,SLOT,ERRVAL) \
495 if ((SLOT) < 0 || (SLOT) >= (INTISA)->formats[FMT].num_slots) \
497 xtisa_errno = xtensa_isa_bad_slot; \
498 strcpy (xtisa_error_msg, "invalid slot specifier"); \
505 xtensa_format_name (xtensa_isa isa
, xtensa_format fmt
)
507 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
508 CHECK_FORMAT (intisa
, fmt
, NULL
);
509 return intisa
->formats
[fmt
].name
;
514 xtensa_format_lookup (xtensa_isa isa
, const char *fmtname
)
516 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
519 if (!fmtname
|| !*fmtname
)
521 xtisa_errno
= xtensa_isa_bad_format
;
522 strcpy (xtisa_error_msg
, "invalid format name");
523 return XTENSA_UNDEFINED
;
526 for (fmt
= 0; fmt
< intisa
->num_formats
; fmt
++)
528 if (strcasecmp (fmtname
, intisa
->formats
[fmt
].name
) == 0)
532 xtisa_errno
= xtensa_isa_bad_format
;
533 sprintf (xtisa_error_msg
, "format \"%s\" not recognized", fmtname
);
534 return XTENSA_UNDEFINED
;
539 xtensa_format_decode (xtensa_isa isa
, const xtensa_insnbuf insn
)
541 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
544 fmt
= (intisa
->format_decode_fn
) (insn
);
545 if (fmt
!= XTENSA_UNDEFINED
)
548 xtisa_errno
= xtensa_isa_bad_format
;
549 strcpy (xtisa_error_msg
, "cannot decode instruction format");
550 return XTENSA_UNDEFINED
;
555 xtensa_format_encode (xtensa_isa isa
, xtensa_format fmt
, xtensa_insnbuf insn
)
557 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
558 CHECK_FORMAT (intisa
, fmt
, -1);
559 (*intisa
->formats
[fmt
].encode_fn
) (insn
);
565 xtensa_format_length (xtensa_isa isa
, xtensa_format fmt
)
567 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
568 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
569 return intisa
->formats
[fmt
].length
;
574 xtensa_format_num_slots (xtensa_isa isa
, xtensa_format fmt
)
576 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
577 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
578 return intisa
->formats
[fmt
].num_slots
;
583 xtensa_format_slot_nop_opcode (xtensa_isa isa
, xtensa_format fmt
, int slot
)
585 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
588 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
589 CHECK_SLOT (intisa
, fmt
, slot
, XTENSA_UNDEFINED
);
591 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
592 return xtensa_opcode_lookup (isa
, intisa
->slots
[slot_id
].nop_name
);
597 xtensa_format_get_slot (xtensa_isa isa
, xtensa_format fmt
, int slot
,
598 const xtensa_insnbuf insn
, xtensa_insnbuf slotbuf
)
600 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
603 CHECK_FORMAT (intisa
, fmt
, -1);
604 CHECK_SLOT (intisa
, fmt
, slot
, -1);
606 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
607 (*intisa
->slots
[slot_id
].get_fn
) (insn
, slotbuf
);
613 xtensa_format_set_slot (xtensa_isa isa
, xtensa_format fmt
, int slot
,
614 xtensa_insnbuf insn
, const xtensa_insnbuf slotbuf
)
616 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
619 CHECK_FORMAT (intisa
, fmt
, -1);
620 CHECK_SLOT (intisa
, fmt
, slot
, -1);
622 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
623 (*intisa
->slots
[slot_id
].set_fn
) (insn
, slotbuf
);
629 /* Opcode information. */
632 #define CHECK_OPCODE(INTISA,OPC,ERRVAL) \
634 if ((OPC) < 0 || (OPC) >= (INTISA)->num_opcodes) \
636 xtisa_errno = xtensa_isa_bad_opcode; \
637 strcpy (xtisa_error_msg, "invalid opcode specifier"); \
644 xtensa_opcode_lookup (xtensa_isa isa
, const char *opname
)
646 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
647 xtensa_lookup_entry entry
, *result
= 0;
649 if (!opname
|| !*opname
)
651 xtisa_errno
= xtensa_isa_bad_opcode
;
652 strcpy (xtisa_error_msg
, "invalid opcode name");
653 return XTENSA_UNDEFINED
;
656 if (intisa
->num_opcodes
!= 0)
659 result
= bsearch (&entry
, intisa
->opname_lookup_table
,
660 intisa
->num_opcodes
, sizeof (xtensa_lookup_entry
),
661 xtensa_isa_name_compare
);
666 xtisa_errno
= xtensa_isa_bad_opcode
;
667 sprintf (xtisa_error_msg
, "opcode \"%s\" not recognized", opname
);
668 return XTENSA_UNDEFINED
;
671 return result
->u
.opcode
;
676 xtensa_opcode_decode (xtensa_isa isa
, xtensa_format fmt
, int slot
,
677 const xtensa_insnbuf slotbuf
)
679 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
683 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
684 CHECK_SLOT (intisa
, fmt
, slot
, XTENSA_UNDEFINED
);
686 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
688 opc
= (intisa
->slots
[slot_id
].opcode_decode_fn
) (slotbuf
);
689 if (opc
!= XTENSA_UNDEFINED
)
692 xtisa_errno
= xtensa_isa_bad_opcode
;
693 strcpy (xtisa_error_msg
, "cannot decode opcode");
694 return XTENSA_UNDEFINED
;
699 xtensa_opcode_encode (xtensa_isa isa
, xtensa_format fmt
, int slot
,
700 xtensa_insnbuf slotbuf
, xtensa_opcode opc
)
702 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
704 xtensa_opcode_encode_fn encode_fn
;
706 CHECK_FORMAT (intisa
, fmt
, -1);
707 CHECK_SLOT (intisa
, fmt
, slot
, -1);
708 CHECK_OPCODE (intisa
, opc
, -1);
710 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
711 encode_fn
= intisa
->opcodes
[opc
].encode_fns
[slot_id
];
714 xtisa_errno
= xtensa_isa_wrong_slot
;
715 sprintf (xtisa_error_msg
,
716 "opcode \"%s\" is not allowed in slot %d of format \"%s\"",
717 intisa
->opcodes
[opc
].name
, slot
, intisa
->formats
[fmt
].name
);
720 (*encode_fn
) (slotbuf
);
726 xtensa_opcode_name (xtensa_isa isa
, xtensa_opcode opc
)
728 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
729 CHECK_OPCODE (intisa
, opc
, NULL
);
730 return intisa
->opcodes
[opc
].name
;
735 xtensa_opcode_is_branch (xtensa_isa isa
, xtensa_opcode opc
)
737 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
738 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
739 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_BRANCH
) != 0)
746 xtensa_opcode_is_jump (xtensa_isa isa
, xtensa_opcode opc
)
748 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
749 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
750 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_JUMP
) != 0)
757 xtensa_opcode_is_loop (xtensa_isa isa
, xtensa_opcode opc
)
759 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
760 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
761 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_LOOP
) != 0)
768 xtensa_opcode_is_call (xtensa_isa isa
, xtensa_opcode opc
)
770 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
771 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
772 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_CALL
) != 0)
779 xtensa_opcode_num_operands (xtensa_isa isa
, xtensa_opcode opc
)
781 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
784 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
785 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
786 return intisa
->iclasses
[iclass_id
].num_operands
;
791 xtensa_opcode_num_stateOperands (xtensa_isa isa
, xtensa_opcode opc
)
793 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
796 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
797 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
798 return intisa
->iclasses
[iclass_id
].num_stateOperands
;
803 xtensa_opcode_num_interfaceOperands (xtensa_isa isa
, xtensa_opcode opc
)
805 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
808 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
809 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
810 return intisa
->iclasses
[iclass_id
].num_interfaceOperands
;
815 xtensa_opcode_num_funcUnit_uses (xtensa_isa isa
, xtensa_opcode opc
)
817 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
818 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
819 return intisa
->opcodes
[opc
].num_funcUnit_uses
;
823 xtensa_funcUnit_use
*
824 xtensa_opcode_funcUnit_use (xtensa_isa isa
, xtensa_opcode opc
, int u
)
826 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
827 CHECK_OPCODE (intisa
, opc
, NULL
);
828 if (u
< 0 || u
>= intisa
->opcodes
[opc
].num_funcUnit_uses
)
830 xtisa_errno
= xtensa_isa_bad_funcUnit
;
831 sprintf (xtisa_error_msg
, "invalid functional unit use number (%d); "
832 "opcode \"%s\" has %d", u
, intisa
->opcodes
[opc
].name
,
833 intisa
->opcodes
[opc
].num_funcUnit_uses
);
836 return &intisa
->opcodes
[opc
].funcUnit_uses
[u
];
841 /* Operand information. */
844 #define CHECK_OPERAND(INTISA,OPC,ICLASS,OPND,ERRVAL) \
846 if ((OPND) < 0 || (OPND) >= (ICLASS)->num_operands) \
848 xtisa_errno = xtensa_isa_bad_operand; \
849 sprintf (xtisa_error_msg, "invalid operand number (%d); " \
850 "opcode \"%s\" has %d operands", (OPND), \
851 (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_operands); \
857 static xtensa_operand_internal
*
858 get_operand (xtensa_isa_internal
*intisa
, xtensa_opcode opc
, int opnd
)
860 xtensa_iclass_internal
*iclass
;
861 int iclass_id
, operand_id
;
863 CHECK_OPCODE (intisa
, opc
, NULL
);
864 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
865 iclass
= &intisa
->iclasses
[iclass_id
];
866 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, NULL
);
867 operand_id
= iclass
->operands
[opnd
].u
.operand_id
;
868 return &intisa
->operands
[operand_id
];
873 xtensa_operand_name (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
875 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
876 xtensa_operand_internal
*intop
;
878 intop
= get_operand (intisa
, opc
, opnd
);
879 if (!intop
) return NULL
;
885 xtensa_operand_is_visible (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
887 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
888 xtensa_iclass_internal
*iclass
;
889 int iclass_id
, operand_id
;
890 xtensa_operand_internal
*intop
;
892 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
893 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
894 iclass
= &intisa
->iclasses
[iclass_id
];
895 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, XTENSA_UNDEFINED
);
897 /* Special case for "sout" operands. */
898 if (iclass
->operands
[opnd
].inout
== 's')
901 operand_id
= iclass
->operands
[opnd
].u
.operand_id
;
902 intop
= &intisa
->operands
[operand_id
];
904 if ((intop
->flags
& XTENSA_OPERAND_IS_INVISIBLE
) == 0)
911 xtensa_operand_inout (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
913 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
914 xtensa_iclass_internal
*iclass
;
918 CHECK_OPCODE (intisa
, opc
, 0);
919 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
920 iclass
= &intisa
->iclasses
[iclass_id
];
921 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, 0);
922 inout
= iclass
->operands
[opnd
].inout
;
924 /* Special case for "sout" operands. */
933 xtensa_operand_get_field (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
934 xtensa_format fmt
, int slot
,
935 const xtensa_insnbuf slotbuf
, uint32
*valp
)
937 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
938 xtensa_operand_internal
*intop
;
940 xtensa_get_field_fn get_fn
;
942 intop
= get_operand (intisa
, opc
, opnd
);
943 if (!intop
) return -1;
945 CHECK_FORMAT (intisa
, fmt
, -1);
946 CHECK_SLOT (intisa
, fmt
, slot
, -1);
948 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
949 if (intop
->field_id
== XTENSA_UNDEFINED
)
951 xtisa_errno
= xtensa_isa_no_field
;
952 strcpy (xtisa_error_msg
, "implicit operand has no field");
955 get_fn
= intisa
->slots
[slot_id
].get_field_fns
[intop
->field_id
];
958 xtisa_errno
= xtensa_isa_wrong_slot
;
959 sprintf (xtisa_error_msg
,
960 "operand \"%s\" does not exist in slot %d of format \"%s\"",
961 intop
->name
, slot
, intisa
->formats
[fmt
].name
);
964 *valp
= (*get_fn
) (slotbuf
);
970 xtensa_operand_set_field (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
971 xtensa_format fmt
, int slot
,
972 xtensa_insnbuf slotbuf
, uint32 val
)
974 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
975 xtensa_operand_internal
*intop
;
977 xtensa_set_field_fn set_fn
;
979 intop
= get_operand (intisa
, opc
, opnd
);
980 if (!intop
) return -1;
982 CHECK_FORMAT (intisa
, fmt
, -1);
983 CHECK_SLOT (intisa
, fmt
, slot
, -1);
985 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
986 if (intop
->field_id
== XTENSA_UNDEFINED
)
988 xtisa_errno
= xtensa_isa_no_field
;
989 strcpy (xtisa_error_msg
, "implicit operand has no field");
992 set_fn
= intisa
->slots
[slot_id
].set_field_fns
[intop
->field_id
];
995 xtisa_errno
= xtensa_isa_wrong_slot
;
996 sprintf (xtisa_error_msg
,
997 "operand \"%s\" does not exist in slot %d of format \"%s\"",
998 intop
->name
, slot
, intisa
->formats
[fmt
].name
);
1001 (*set_fn
) (slotbuf
, val
);
1007 xtensa_operand_encode (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1010 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1011 xtensa_operand_internal
*intop
;
1012 uint32 test_val
, orig_val
;
1014 intop
= get_operand (intisa
, opc
, opnd
);
1020 /* This is a default operand for a field. How can we tell if the
1021 value fits in the field? Write the value into the field,
1022 read it back, and then make sure we get the same value. */
1023 static xtensa_insnbuf tmpbuf
= 0;
1028 tmpbuf
= xtensa_insnbuf_alloc (isa
);
1029 CHECK_ALLOC (tmpbuf
, -1);
1032 /* A default operand is always associated with a field,
1033 but check just to be sure.... */
1034 if (intop
->field_id
== XTENSA_UNDEFINED
)
1036 xtisa_errno
= xtensa_isa_internal_error
;
1037 strcpy (xtisa_error_msg
, "operand has no field");
1041 /* Find some slot that includes the field. */
1042 for (slot_id
= 0; slot_id
< intisa
->num_slots
; slot_id
++)
1044 xtensa_get_field_fn get_fn
=
1045 intisa
->slots
[slot_id
].get_field_fns
[intop
->field_id
];
1046 xtensa_set_field_fn set_fn
=
1047 intisa
->slots
[slot_id
].set_field_fns
[intop
->field_id
];
1049 if (get_fn
&& set_fn
)
1051 (*set_fn
) (tmpbuf
, *valp
);
1052 return ((*get_fn
) (tmpbuf
) != *valp
);
1056 /* Couldn't find any slot containing the field.... */
1057 xtisa_errno
= xtensa_isa_no_field
;
1058 strcpy (xtisa_error_msg
, "field does not exist in any slot");
1062 /* Encode the value. In some cases, the encoding function may detect
1063 errors, but most of the time the only way to determine if the value
1064 was successfully encoded is to decode it and check if it matches
1065 the original value. */
1067 if ((*intop
->encode
) (valp
)
1068 || (test_val
= *valp
, (*intop
->decode
) (&test_val
))
1069 || test_val
!= orig_val
)
1071 xtisa_errno
= xtensa_isa_bad_value
;
1072 sprintf (xtisa_error_msg
, "cannot encode operand value 0x%08x", *valp
);
1081 xtensa_operand_decode (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1084 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1085 xtensa_operand_internal
*intop
;
1087 intop
= get_operand (intisa
, opc
, opnd
);
1088 if (!intop
) return -1;
1090 /* Use identity function for "default" operands. */
1094 if ((*intop
->decode
) (valp
))
1096 xtisa_errno
= xtensa_isa_bad_value
;
1097 sprintf (xtisa_error_msg
, "cannot decode operand value 0x%08x", *valp
);
1105 xtensa_operand_is_register (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1107 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1108 xtensa_operand_internal
*intop
;
1110 intop
= get_operand (intisa
, opc
, opnd
);
1111 if (!intop
) return XTENSA_UNDEFINED
;
1113 if ((intop
->flags
& XTENSA_OPERAND_IS_REGISTER
) != 0)
1120 xtensa_operand_regfile (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1122 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1123 xtensa_operand_internal
*intop
;
1125 intop
= get_operand (intisa
, opc
, opnd
);
1126 if (!intop
) return XTENSA_UNDEFINED
;
1128 return intop
->regfile
;
1133 xtensa_operand_num_regs (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1135 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1136 xtensa_operand_internal
*intop
;
1138 intop
= get_operand (intisa
, opc
, opnd
);
1139 if (!intop
) return XTENSA_UNDEFINED
;
1141 return intop
->num_regs
;
1146 xtensa_operand_is_known_reg (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1148 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1149 xtensa_operand_internal
*intop
;
1151 intop
= get_operand (intisa
, opc
, opnd
);
1152 if (!intop
) return XTENSA_UNDEFINED
;
1154 if ((intop
->flags
& XTENSA_OPERAND_IS_UNKNOWN
) == 0)
1161 xtensa_operand_is_PCrelative (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1163 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1164 xtensa_operand_internal
*intop
;
1166 intop
= get_operand (intisa
, opc
, opnd
);
1167 if (!intop
) return XTENSA_UNDEFINED
;
1169 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) != 0)
1176 xtensa_operand_do_reloc (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1177 uint32
*valp
, uint32 pc
)
1179 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1180 xtensa_operand_internal
*intop
;
1182 intop
= get_operand (intisa
, opc
, opnd
);
1183 if (!intop
) return -1;
1185 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) == 0)
1188 if (!intop
->do_reloc
)
1190 xtisa_errno
= xtensa_isa_internal_error
;
1191 strcpy (xtisa_error_msg
, "operand missing do_reloc function");
1195 if ((*intop
->do_reloc
) (valp
, pc
))
1197 xtisa_errno
= xtensa_isa_bad_value
;
1198 sprintf (xtisa_error_msg
,
1199 "do_reloc failed for value 0x%08x at PC 0x%08x", *valp
, pc
);
1208 xtensa_operand_undo_reloc (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1209 uint32
*valp
, uint32 pc
)
1211 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1212 xtensa_operand_internal
*intop
;
1214 intop
= get_operand (intisa
, opc
, opnd
);
1215 if (!intop
) return -1;
1217 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) == 0)
1220 if (!intop
->undo_reloc
)
1222 xtisa_errno
= xtensa_isa_internal_error
;
1223 strcpy (xtisa_error_msg
, "operand missing undo_reloc function");
1227 if ((*intop
->undo_reloc
) (valp
, pc
))
1229 xtisa_errno
= xtensa_isa_bad_value
;
1230 sprintf (xtisa_error_msg
,
1231 "undo_reloc failed for value 0x%08x at PC 0x%08x", *valp
, pc
);
1240 /* State Operands. */
1243 #define CHECK_STATE_OPERAND(INTISA,OPC,ICLASS,STOP,ERRVAL) \
1245 if ((STOP) < 0 || (STOP) >= (ICLASS)->num_stateOperands) \
1247 xtisa_errno = xtensa_isa_bad_operand; \
1248 sprintf (xtisa_error_msg, "invalid state operand number (%d); " \
1249 "opcode \"%s\" has %d state operands", (STOP), \
1250 (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_stateOperands); \
1257 xtensa_stateOperand_state (xtensa_isa isa
, xtensa_opcode opc
, int stOp
)
1259 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1260 xtensa_iclass_internal
*iclass
;
1263 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
1264 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1265 iclass
= &intisa
->iclasses
[iclass_id
];
1266 CHECK_STATE_OPERAND (intisa
, opc
, iclass
, stOp
, XTENSA_UNDEFINED
);
1267 return iclass
->stateOperands
[stOp
].u
.state
;
1272 xtensa_stateOperand_inout (xtensa_isa isa
, xtensa_opcode opc
, int stOp
)
1274 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1275 xtensa_iclass_internal
*iclass
;
1278 CHECK_OPCODE (intisa
, opc
, 0);
1279 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1280 iclass
= &intisa
->iclasses
[iclass_id
];
1281 CHECK_STATE_OPERAND (intisa
, opc
, iclass
, stOp
, 0);
1282 return iclass
->stateOperands
[stOp
].inout
;
1287 /* Interface Operands. */
1290 #define CHECK_INTERFACE_OPERAND(INTISA,OPC,ICLASS,IFOP,ERRVAL) \
1292 if ((IFOP) < 0 || (IFOP) >= (ICLASS)->num_interfaceOperands) \
1294 xtisa_errno = xtensa_isa_bad_operand; \
1295 sprintf (xtisa_error_msg, "invalid interface operand number (%d); " \
1296 "opcode \"%s\" has %d interface operands", (IFOP), \
1297 (INTISA)->opcodes[(OPC)].name, \
1298 (ICLASS)->num_interfaceOperands); \
1305 xtensa_interfaceOperand_interface (xtensa_isa isa
, xtensa_opcode opc
,
1308 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1309 xtensa_iclass_internal
*iclass
;
1312 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
1313 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1314 iclass
= &intisa
->iclasses
[iclass_id
];
1315 CHECK_INTERFACE_OPERAND (intisa
, opc
, iclass
, ifOp
, XTENSA_UNDEFINED
);
1316 return iclass
->interfaceOperands
[ifOp
];
1321 /* Register Files. */
1324 #define CHECK_REGFILE(INTISA,RF,ERRVAL) \
1326 if ((RF) < 0 || (RF) >= (INTISA)->num_regfiles) \
1328 xtisa_errno = xtensa_isa_bad_regfile; \
1329 strcpy (xtisa_error_msg, "invalid regfile specifier"); \
1336 xtensa_regfile_lookup (xtensa_isa isa
, const char *name
)
1338 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1341 if (!name
|| !*name
)
1343 xtisa_errno
= xtensa_isa_bad_regfile
;
1344 strcpy (xtisa_error_msg
, "invalid regfile name");
1345 return XTENSA_UNDEFINED
;
1348 /* The expected number of regfiles is small; use a linear search. */
1349 for (n
= 0; n
< intisa
->num_regfiles
; n
++)
1351 if (!filename_cmp (intisa
->regfiles
[n
].name
, name
))
1355 xtisa_errno
= xtensa_isa_bad_regfile
;
1356 sprintf (xtisa_error_msg
, "regfile \"%s\" not recognized", name
);
1357 return XTENSA_UNDEFINED
;
1362 xtensa_regfile_lookup_shortname (xtensa_isa isa
, const char *shortname
)
1364 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1367 if (!shortname
|| !*shortname
)
1369 xtisa_errno
= xtensa_isa_bad_regfile
;
1370 strcpy (xtisa_error_msg
, "invalid regfile shortname");
1371 return XTENSA_UNDEFINED
;
1374 /* The expected number of regfiles is small; use a linear search. */
1375 for (n
= 0; n
< intisa
->num_regfiles
; n
++)
1377 /* Ignore regfile views since they always have the same shortnames
1378 as their parents. */
1379 if (intisa
->regfiles
[n
].parent
!= n
)
1381 if (!filename_cmp (intisa
->regfiles
[n
].shortname
, shortname
))
1385 xtisa_errno
= xtensa_isa_bad_regfile
;
1386 sprintf (xtisa_error_msg
, "regfile shortname \"%s\" not recognized",
1388 return XTENSA_UNDEFINED
;
1393 xtensa_regfile_name (xtensa_isa isa
, xtensa_regfile rf
)
1395 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1396 CHECK_REGFILE (intisa
, rf
, NULL
);
1397 return intisa
->regfiles
[rf
].name
;
1402 xtensa_regfile_shortname (xtensa_isa isa
, xtensa_regfile rf
)
1404 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1405 CHECK_REGFILE (intisa
, rf
, NULL
);
1406 return intisa
->regfiles
[rf
].shortname
;
1411 xtensa_regfile_view_parent (xtensa_isa isa
, xtensa_regfile rf
)
1413 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1414 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1415 return intisa
->regfiles
[rf
].parent
;
1420 xtensa_regfile_num_bits (xtensa_isa isa
, xtensa_regfile rf
)
1422 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1423 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1424 return intisa
->regfiles
[rf
].num_bits
;
1429 xtensa_regfile_num_entries (xtensa_isa isa
, xtensa_regfile rf
)
1431 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1432 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1433 return intisa
->regfiles
[rf
].num_entries
;
1438 /* Processor States. */
1441 #define CHECK_STATE(INTISA,ST,ERRVAL) \
1443 if ((ST) < 0 || (ST) >= (INTISA)->num_states) \
1445 xtisa_errno = xtensa_isa_bad_state; \
1446 strcpy (xtisa_error_msg, "invalid state specifier"); \
1453 xtensa_state_lookup (xtensa_isa isa
, const char *name
)
1455 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1456 xtensa_lookup_entry entry
, *result
= 0;
1458 if (!name
|| !*name
)
1460 xtisa_errno
= xtensa_isa_bad_state
;
1461 strcpy (xtisa_error_msg
, "invalid state name");
1462 return XTENSA_UNDEFINED
;
1465 if (intisa
->num_states
!= 0)
1468 result
= bsearch (&entry
, intisa
->state_lookup_table
, intisa
->num_states
,
1469 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
1474 xtisa_errno
= xtensa_isa_bad_state
;
1475 sprintf (xtisa_error_msg
, "state \"%s\" not recognized", name
);
1476 return XTENSA_UNDEFINED
;
1479 return result
->u
.state
;
1484 xtensa_state_name (xtensa_isa isa
, xtensa_state st
)
1486 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1487 CHECK_STATE (intisa
, st
, NULL
);
1488 return intisa
->states
[st
].name
;
1493 xtensa_state_num_bits (xtensa_isa isa
, xtensa_state st
)
1495 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1496 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1497 return intisa
->states
[st
].num_bits
;
1502 xtensa_state_is_exported (xtensa_isa isa
, xtensa_state st
)
1504 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1505 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1506 if ((intisa
->states
[st
].flags
& XTENSA_STATE_IS_EXPORTED
) != 0)
1513 xtensa_state_is_shared_or (xtensa_isa isa
, xtensa_state st
)
1515 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1516 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1517 if ((intisa
->states
[st
].flags
& XTENSA_STATE_IS_SHARED_OR
) != 0)
1527 #define CHECK_SYSREG(INTISA,SYSREG,ERRVAL) \
1529 if ((SYSREG) < 0 || (SYSREG) >= (INTISA)->num_sysregs) \
1531 xtisa_errno = xtensa_isa_bad_sysreg; \
1532 strcpy (xtisa_error_msg, "invalid sysreg specifier"); \
1539 xtensa_sysreg_lookup (xtensa_isa isa
, int num
, int is_user
)
1541 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1546 if (num
< 0 || num
> intisa
->max_sysreg_num
[is_user
]
1547 || intisa
->sysreg_table
[is_user
][num
] == XTENSA_UNDEFINED
)
1549 xtisa_errno
= xtensa_isa_bad_sysreg
;
1550 strcpy (xtisa_error_msg
, "sysreg not recognized");
1551 return XTENSA_UNDEFINED
;
1554 return intisa
->sysreg_table
[is_user
][num
];
1559 xtensa_sysreg_lookup_name (xtensa_isa isa
, const char *name
)
1561 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1562 xtensa_lookup_entry entry
, *result
= 0;
1564 if (!name
|| !*name
)
1566 xtisa_errno
= xtensa_isa_bad_sysreg
;
1567 strcpy (xtisa_error_msg
, "invalid sysreg name");
1568 return XTENSA_UNDEFINED
;
1571 if (intisa
->num_sysregs
!= 0)
1574 result
= bsearch (&entry
, intisa
->sysreg_lookup_table
,
1575 intisa
->num_sysregs
, sizeof (xtensa_lookup_entry
),
1576 xtensa_isa_name_compare
);
1581 xtisa_errno
= xtensa_isa_bad_sysreg
;
1582 sprintf (xtisa_error_msg
, "sysreg \"%s\" not recognized", name
);
1583 return XTENSA_UNDEFINED
;
1586 return result
->u
.sysreg
;
1591 xtensa_sysreg_name (xtensa_isa isa
, xtensa_sysreg sysreg
)
1593 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1594 CHECK_SYSREG (intisa
, sysreg
, NULL
);
1595 return intisa
->sysregs
[sysreg
].name
;
1600 xtensa_sysreg_number (xtensa_isa isa
, xtensa_sysreg sysreg
)
1602 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1603 CHECK_SYSREG (intisa
, sysreg
, XTENSA_UNDEFINED
);
1604 return intisa
->sysregs
[sysreg
].number
;
1609 xtensa_sysreg_is_user (xtensa_isa isa
, xtensa_sysreg sysreg
)
1611 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1612 CHECK_SYSREG (intisa
, sysreg
, XTENSA_UNDEFINED
);
1613 if (intisa
->sysregs
[sysreg
].is_user
)
1623 #define CHECK_INTERFACE(INTISA,INTF,ERRVAL) \
1625 if ((INTF) < 0 || (INTF) >= (INTISA)->num_interfaces) \
1627 xtisa_errno = xtensa_isa_bad_interface; \
1628 strcpy (xtisa_error_msg, "invalid interface specifier"); \
1635 xtensa_interface_lookup (xtensa_isa isa
, const char *ifname
)
1637 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1638 xtensa_lookup_entry entry
, *result
= 0;
1640 if (!ifname
|| !*ifname
)
1642 xtisa_errno
= xtensa_isa_bad_interface
;
1643 strcpy (xtisa_error_msg
, "invalid interface name");
1644 return XTENSA_UNDEFINED
;
1647 if (intisa
->num_interfaces
!= 0)
1650 result
= bsearch (&entry
, intisa
->interface_lookup_table
,
1651 intisa
->num_interfaces
, sizeof (xtensa_lookup_entry
),
1652 xtensa_isa_name_compare
);
1657 xtisa_errno
= xtensa_isa_bad_interface
;
1658 sprintf (xtisa_error_msg
, "interface \"%s\" not recognized", ifname
);
1659 return XTENSA_UNDEFINED
;
1662 return result
->u
.intf
;
1667 xtensa_interface_name (xtensa_isa isa
, xtensa_interface intf
)
1669 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1670 CHECK_INTERFACE (intisa
, intf
, NULL
);
1671 return intisa
->interfaces
[intf
].name
;
1676 xtensa_interface_num_bits (xtensa_isa isa
, xtensa_interface intf
)
1678 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1679 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1680 return intisa
->interfaces
[intf
].num_bits
;
1685 xtensa_interface_inout (xtensa_isa isa
, xtensa_interface intf
)
1687 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1688 CHECK_INTERFACE (intisa
, intf
, 0);
1689 return intisa
->interfaces
[intf
].inout
;
1694 xtensa_interface_has_side_effect (xtensa_isa isa
, xtensa_interface intf
)
1696 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1697 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1698 if ((intisa
->interfaces
[intf
].flags
& XTENSA_INTERFACE_HAS_SIDE_EFFECT
) != 0)
1705 xtensa_interface_class_id (xtensa_isa isa
, xtensa_interface intf
)
1707 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1708 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1709 return intisa
->interfaces
[intf
].class_id
;
1714 /* Functional Units. */
1717 #define CHECK_FUNCUNIT(INTISA,FUN,ERRVAL) \
1719 if ((FUN) < 0 || (FUN) >= (INTISA)->num_funcUnits) \
1721 xtisa_errno = xtensa_isa_bad_funcUnit; \
1722 strcpy (xtisa_error_msg, "invalid functional unit specifier"); \
1729 xtensa_funcUnit_lookup (xtensa_isa isa
, const char *fname
)
1731 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1732 xtensa_lookup_entry entry
, *result
= 0;
1734 if (!fname
|| !*fname
)
1736 xtisa_errno
= xtensa_isa_bad_funcUnit
;
1737 strcpy (xtisa_error_msg
, "invalid functional unit name");
1738 return XTENSA_UNDEFINED
;
1741 if (intisa
->num_funcUnits
!= 0)
1744 result
= bsearch (&entry
, intisa
->funcUnit_lookup_table
,
1745 intisa
->num_funcUnits
, sizeof (xtensa_lookup_entry
),
1746 xtensa_isa_name_compare
);
1751 xtisa_errno
= xtensa_isa_bad_funcUnit
;
1752 sprintf (xtisa_error_msg
,
1753 "functional unit \"%s\" not recognized", fname
);
1754 return XTENSA_UNDEFINED
;
1757 return result
->u
.fun
;
1762 xtensa_funcUnit_name (xtensa_isa isa
, xtensa_funcUnit fun
)
1764 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1765 CHECK_FUNCUNIT (intisa
, fun
, NULL
);
1766 return intisa
->funcUnits
[fun
].name
;
1771 xtensa_funcUnit_num_copies (xtensa_isa isa
, xtensa_funcUnit fun
)
1773 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1774 CHECK_FUNCUNIT (intisa
, fun
, XTENSA_UNDEFINED
);
1775 return intisa
->funcUnits
[fun
].num_copies
;