1 /* Configurable Xtensa ISA support.
2 Copyright (C) 2003-2022 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 static xtensa_isa_status xtisa_errno
;
28 static 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
;
231 /* ISA information. */
233 extern xtensa_isa_internal xtensa_modules
;
236 xtensa_isa_init (xtensa_isa_status
*errno_p
, char **error_msg_p
)
238 xtensa_isa_internal
*isa
= &xtensa_modules
;
241 /* Set up the opcode name lookup table. */
242 isa
->opname_lookup_table
=
243 bfd_malloc (isa
->num_opcodes
* sizeof (xtensa_lookup_entry
));
244 CHECK_ALLOC_FOR_INIT (isa
->opname_lookup_table
, NULL
, errno_p
, error_msg_p
);
245 for (n
= 0; n
< isa
->num_opcodes
; n
++)
247 isa
->opname_lookup_table
[n
].key
= isa
->opcodes
[n
].name
;
248 isa
->opname_lookup_table
[n
].u
.opcode
= n
;
250 qsort (isa
->opname_lookup_table
, isa
->num_opcodes
,
251 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
253 /* Set up the state name lookup table. */
254 isa
->state_lookup_table
=
255 bfd_malloc (isa
->num_states
* sizeof (xtensa_lookup_entry
));
256 CHECK_ALLOC_FOR_INIT (isa
->state_lookup_table
, NULL
, errno_p
, error_msg_p
);
257 for (n
= 0; n
< isa
->num_states
; n
++)
259 isa
->state_lookup_table
[n
].key
= isa
->states
[n
].name
;
260 isa
->state_lookup_table
[n
].u
.state
= n
;
262 qsort (isa
->state_lookup_table
, isa
->num_states
,
263 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
265 /* Set up the sysreg name lookup table. */
266 isa
->sysreg_lookup_table
=
267 bfd_malloc (isa
->num_sysregs
* sizeof (xtensa_lookup_entry
));
268 CHECK_ALLOC_FOR_INIT (isa
->sysreg_lookup_table
, NULL
, errno_p
, error_msg_p
);
269 for (n
= 0; n
< isa
->num_sysregs
; n
++)
271 isa
->sysreg_lookup_table
[n
].key
= isa
->sysregs
[n
].name
;
272 isa
->sysreg_lookup_table
[n
].u
.sysreg
= n
;
274 qsort (isa
->sysreg_lookup_table
, isa
->num_sysregs
,
275 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
277 /* Set up the user & system sysreg number tables. */
278 for (is_user
= 0; is_user
< 2; is_user
++)
280 isa
->sysreg_table
[is_user
] =
281 bfd_malloc ((isa
->max_sysreg_num
[is_user
] + 1)
282 * sizeof (xtensa_sysreg
));
283 CHECK_ALLOC_FOR_INIT (isa
->sysreg_table
[is_user
], NULL
,
284 errno_p
, error_msg_p
);
286 for (n
= 0; n
<= isa
->max_sysreg_num
[is_user
]; n
++)
287 isa
->sysreg_table
[is_user
][n
] = XTENSA_UNDEFINED
;
289 for (n
= 0; n
< isa
->num_sysregs
; n
++)
291 xtensa_sysreg_internal
*sreg
= &isa
->sysregs
[n
];
292 is_user
= sreg
->is_user
;
294 if (sreg
->number
>= 0)
295 isa
->sysreg_table
[is_user
][sreg
->number
] = n
;
298 /* Set up the interface lookup table. */
299 isa
->interface_lookup_table
=
300 bfd_malloc (isa
->num_interfaces
* sizeof (xtensa_lookup_entry
));
301 CHECK_ALLOC_FOR_INIT (isa
->interface_lookup_table
, NULL
, errno_p
,
303 for (n
= 0; n
< isa
->num_interfaces
; n
++)
305 isa
->interface_lookup_table
[n
].key
= isa
->interfaces
[n
].name
;
306 isa
->interface_lookup_table
[n
].u
.intf
= n
;
308 qsort (isa
->interface_lookup_table
, isa
->num_interfaces
,
309 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
311 /* Set up the funcUnit lookup table. */
312 isa
->funcUnit_lookup_table
=
313 bfd_malloc (isa
->num_funcUnits
* sizeof (xtensa_lookup_entry
));
314 CHECK_ALLOC_FOR_INIT (isa
->funcUnit_lookup_table
, NULL
, errno_p
,
316 for (n
= 0; n
< isa
->num_funcUnits
; n
++)
318 isa
->funcUnit_lookup_table
[n
].key
= isa
->funcUnits
[n
].name
;
319 isa
->funcUnit_lookup_table
[n
].u
.fun
= n
;
321 qsort (isa
->funcUnit_lookup_table
, isa
->num_funcUnits
,
322 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
324 isa
->insnbuf_size
= ((isa
->insn_size
+ sizeof (xtensa_insnbuf_word
) - 1) /
325 sizeof (xtensa_insnbuf_word
));
327 return (xtensa_isa
) isa
;
332 xtensa_isa_free (xtensa_isa isa
)
334 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
337 /* With this version of the code, the xtensa_isa structure is not
338 dynamically allocated, so this function is not essential. Free
339 the memory allocated by xtensa_isa_init and restore the xtensa_isa
340 structure to its initial state. */
342 free (intisa
->opname_lookup_table
);
343 intisa
->opname_lookup_table
= 0;
345 free (intisa
->state_lookup_table
);
346 intisa
->state_lookup_table
= 0;
348 free (intisa
->sysreg_lookup_table
);
349 intisa
->sysreg_lookup_table
= 0;
351 for (n
= 0; n
< 2; n
++)
353 free (intisa
->sysreg_table
[n
]);
354 intisa
->sysreg_table
[n
] = 0;
357 free (intisa
->interface_lookup_table
);
358 intisa
->interface_lookup_table
= 0;
360 free (intisa
->funcUnit_lookup_table
);
361 intisa
->funcUnit_lookup_table
= 0;
366 xtensa_isa_name_compare (const void *v1
, const void *v2
)
368 xtensa_lookup_entry
*e1
= (xtensa_lookup_entry
*) v1
;
369 xtensa_lookup_entry
*e2
= (xtensa_lookup_entry
*) v2
;
371 return strcasecmp (e1
->key
, e2
->key
);
376 xtensa_isa_maxlength (xtensa_isa isa
)
378 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
379 return intisa
->insn_size
;
384 xtensa_isa_length_from_chars (xtensa_isa isa
, const unsigned char *cp
)
386 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
387 return (intisa
->length_decode_fn
) (cp
);
392 xtensa_isa_num_pipe_stages (xtensa_isa isa
)
394 xtensa_opcode opcode
;
395 xtensa_funcUnit_use
*use
;
396 int num_opcodes
, num_uses
;
398 static int max_stage
= XTENSA_UNDEFINED
;
400 /* Only compute the value once. */
401 if (max_stage
!= XTENSA_UNDEFINED
)
402 return max_stage
+ 1;
404 num_opcodes
= xtensa_isa_num_opcodes (isa
);
405 for (opcode
= 0; opcode
< num_opcodes
; opcode
++)
407 num_uses
= xtensa_opcode_num_funcUnit_uses (isa
, opcode
);
408 for (i
= 0; i
< num_uses
; i
++)
410 use
= xtensa_opcode_funcUnit_use (isa
, opcode
, i
);
412 if (stage
> max_stage
)
417 return max_stage
+ 1;
422 xtensa_isa_num_formats (xtensa_isa isa
)
424 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
425 return intisa
->num_formats
;
430 xtensa_isa_num_opcodes (xtensa_isa isa
)
432 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
433 return intisa
->num_opcodes
;
438 xtensa_isa_num_regfiles (xtensa_isa isa
)
440 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
441 return intisa
->num_regfiles
;
446 xtensa_isa_num_states (xtensa_isa isa
)
448 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
449 return intisa
->num_states
;
454 xtensa_isa_num_sysregs (xtensa_isa isa
)
456 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
457 return intisa
->num_sysregs
;
462 xtensa_isa_num_interfaces (xtensa_isa isa
)
464 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
465 return intisa
->num_interfaces
;
470 xtensa_isa_num_funcUnits (xtensa_isa isa
)
472 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
473 return intisa
->num_funcUnits
;
478 /* Instruction formats. */
481 #define CHECK_FORMAT(INTISA,FMT,ERRVAL) \
483 if ((FMT) < 0 || (FMT) >= (INTISA)->num_formats) \
485 xtisa_errno = xtensa_isa_bad_format; \
486 strcpy (xtisa_error_msg, "invalid format specifier"); \
492 #define CHECK_SLOT(INTISA,FMT,SLOT,ERRVAL) \
494 if ((SLOT) < 0 || (SLOT) >= (INTISA)->formats[FMT].num_slots) \
496 xtisa_errno = xtensa_isa_bad_slot; \
497 strcpy (xtisa_error_msg, "invalid slot specifier"); \
504 xtensa_format_name (xtensa_isa isa
, xtensa_format fmt
)
506 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
507 CHECK_FORMAT (intisa
, fmt
, NULL
);
508 return intisa
->formats
[fmt
].name
;
513 xtensa_format_lookup (xtensa_isa isa
, const char *fmtname
)
515 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
518 if (!fmtname
|| !*fmtname
)
520 xtisa_errno
= xtensa_isa_bad_format
;
521 strcpy (xtisa_error_msg
, "invalid format name");
522 return XTENSA_UNDEFINED
;
525 for (fmt
= 0; fmt
< intisa
->num_formats
; fmt
++)
527 if (strcasecmp (fmtname
, intisa
->formats
[fmt
].name
) == 0)
531 xtisa_errno
= xtensa_isa_bad_format
;
532 sprintf (xtisa_error_msg
, "format \"%s\" not recognized", fmtname
);
533 return XTENSA_UNDEFINED
;
538 xtensa_format_decode (xtensa_isa isa
, const xtensa_insnbuf insn
)
540 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
543 fmt
= (intisa
->format_decode_fn
) (insn
);
544 if (fmt
!= XTENSA_UNDEFINED
)
547 xtisa_errno
= xtensa_isa_bad_format
;
548 strcpy (xtisa_error_msg
, "cannot decode instruction format");
549 return XTENSA_UNDEFINED
;
554 xtensa_format_encode (xtensa_isa isa
, xtensa_format fmt
, xtensa_insnbuf insn
)
556 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
557 CHECK_FORMAT (intisa
, fmt
, -1);
558 (*intisa
->formats
[fmt
].encode_fn
) (insn
);
564 xtensa_format_length (xtensa_isa isa
, xtensa_format fmt
)
566 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
567 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
568 return intisa
->formats
[fmt
].length
;
573 xtensa_format_num_slots (xtensa_isa isa
, xtensa_format fmt
)
575 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
576 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
577 return intisa
->formats
[fmt
].num_slots
;
582 xtensa_format_slot_nop_opcode (xtensa_isa isa
, xtensa_format fmt
, int slot
)
584 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
587 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
588 CHECK_SLOT (intisa
, fmt
, slot
, XTENSA_UNDEFINED
);
590 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
591 return xtensa_opcode_lookup (isa
, intisa
->slots
[slot_id
].nop_name
);
596 xtensa_format_get_slot (xtensa_isa isa
, xtensa_format fmt
, int slot
,
597 const xtensa_insnbuf insn
, xtensa_insnbuf slotbuf
)
599 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
602 CHECK_FORMAT (intisa
, fmt
, -1);
603 CHECK_SLOT (intisa
, fmt
, slot
, -1);
605 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
606 (*intisa
->slots
[slot_id
].get_fn
) (insn
, slotbuf
);
612 xtensa_format_set_slot (xtensa_isa isa
, xtensa_format fmt
, int slot
,
613 xtensa_insnbuf insn
, const xtensa_insnbuf slotbuf
)
615 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
618 CHECK_FORMAT (intisa
, fmt
, -1);
619 CHECK_SLOT (intisa
, fmt
, slot
, -1);
621 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
622 (*intisa
->slots
[slot_id
].set_fn
) (insn
, slotbuf
);
628 /* Opcode information. */
631 #define CHECK_OPCODE(INTISA,OPC,ERRVAL) \
633 if ((OPC) < 0 || (OPC) >= (INTISA)->num_opcodes) \
635 xtisa_errno = xtensa_isa_bad_opcode; \
636 strcpy (xtisa_error_msg, "invalid opcode specifier"); \
643 xtensa_opcode_lookup (xtensa_isa isa
, const char *opname
)
645 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
646 xtensa_lookup_entry entry
, *result
= 0;
648 if (!opname
|| !*opname
)
650 xtisa_errno
= xtensa_isa_bad_opcode
;
651 strcpy (xtisa_error_msg
, "invalid opcode name");
652 return XTENSA_UNDEFINED
;
655 if (intisa
->num_opcodes
!= 0)
658 result
= bsearch (&entry
, intisa
->opname_lookup_table
,
659 intisa
->num_opcodes
, sizeof (xtensa_lookup_entry
),
660 xtensa_isa_name_compare
);
665 xtisa_errno
= xtensa_isa_bad_opcode
;
666 sprintf (xtisa_error_msg
, "opcode \"%s\" not recognized", opname
);
667 return XTENSA_UNDEFINED
;
670 return result
->u
.opcode
;
675 xtensa_opcode_decode (xtensa_isa isa
, xtensa_format fmt
, int slot
,
676 const xtensa_insnbuf slotbuf
)
678 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
682 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
683 CHECK_SLOT (intisa
, fmt
, slot
, XTENSA_UNDEFINED
);
685 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
687 opc
= (intisa
->slots
[slot_id
].opcode_decode_fn
) (slotbuf
);
688 if (opc
!= XTENSA_UNDEFINED
)
691 xtisa_errno
= xtensa_isa_bad_opcode
;
692 strcpy (xtisa_error_msg
, "cannot decode opcode");
693 return XTENSA_UNDEFINED
;
698 xtensa_opcode_encode (xtensa_isa isa
, xtensa_format fmt
, int slot
,
699 xtensa_insnbuf slotbuf
, xtensa_opcode opc
)
701 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
703 xtensa_opcode_encode_fn encode_fn
;
705 CHECK_FORMAT (intisa
, fmt
, -1);
706 CHECK_SLOT (intisa
, fmt
, slot
, -1);
707 CHECK_OPCODE (intisa
, opc
, -1);
709 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
710 encode_fn
= intisa
->opcodes
[opc
].encode_fns
[slot_id
];
713 xtisa_errno
= xtensa_isa_wrong_slot
;
714 sprintf (xtisa_error_msg
,
715 "opcode \"%s\" is not allowed in slot %d of format \"%s\"",
716 intisa
->opcodes
[opc
].name
, slot
, intisa
->formats
[fmt
].name
);
719 (*encode_fn
) (slotbuf
);
725 xtensa_opcode_name (xtensa_isa isa
, xtensa_opcode opc
)
727 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
728 CHECK_OPCODE (intisa
, opc
, NULL
);
729 return intisa
->opcodes
[opc
].name
;
734 xtensa_opcode_is_branch (xtensa_isa isa
, xtensa_opcode opc
)
736 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
737 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
738 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_BRANCH
) != 0)
745 xtensa_opcode_is_jump (xtensa_isa isa
, xtensa_opcode opc
)
747 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
748 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
749 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_JUMP
) != 0)
756 xtensa_opcode_is_loop (xtensa_isa isa
, xtensa_opcode opc
)
758 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
759 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
760 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_LOOP
) != 0)
767 xtensa_opcode_is_call (xtensa_isa isa
, xtensa_opcode opc
)
769 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
770 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
771 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_CALL
) != 0)
778 xtensa_opcode_num_operands (xtensa_isa isa
, xtensa_opcode opc
)
780 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
783 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
784 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
785 return intisa
->iclasses
[iclass_id
].num_operands
;
790 xtensa_opcode_num_stateOperands (xtensa_isa isa
, xtensa_opcode opc
)
792 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
795 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
796 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
797 return intisa
->iclasses
[iclass_id
].num_stateOperands
;
802 xtensa_opcode_num_interfaceOperands (xtensa_isa isa
, xtensa_opcode opc
)
804 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
807 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
808 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
809 return intisa
->iclasses
[iclass_id
].num_interfaceOperands
;
814 xtensa_opcode_num_funcUnit_uses (xtensa_isa isa
, xtensa_opcode opc
)
816 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
817 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
818 return intisa
->opcodes
[opc
].num_funcUnit_uses
;
822 xtensa_funcUnit_use
*
823 xtensa_opcode_funcUnit_use (xtensa_isa isa
, xtensa_opcode opc
, int u
)
825 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
826 CHECK_OPCODE (intisa
, opc
, NULL
);
827 if (u
< 0 || u
>= intisa
->opcodes
[opc
].num_funcUnit_uses
)
829 xtisa_errno
= xtensa_isa_bad_funcUnit
;
830 sprintf (xtisa_error_msg
, "invalid functional unit use number (%d); "
831 "opcode \"%s\" has %d", u
, intisa
->opcodes
[opc
].name
,
832 intisa
->opcodes
[opc
].num_funcUnit_uses
);
835 return &intisa
->opcodes
[opc
].funcUnit_uses
[u
];
840 /* Operand information. */
843 #define CHECK_OPERAND(INTISA,OPC,ICLASS,OPND,ERRVAL) \
845 if ((OPND) < 0 || (OPND) >= (ICLASS)->num_operands) \
847 xtisa_errno = xtensa_isa_bad_operand; \
848 sprintf (xtisa_error_msg, "invalid operand number (%d); " \
849 "opcode \"%s\" has %d operands", (OPND), \
850 (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_operands); \
856 static xtensa_operand_internal
*
857 get_operand (xtensa_isa_internal
*intisa
, xtensa_opcode opc
, int opnd
)
859 xtensa_iclass_internal
*iclass
;
860 int iclass_id
, operand_id
;
862 CHECK_OPCODE (intisa
, opc
, NULL
);
863 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
864 iclass
= &intisa
->iclasses
[iclass_id
];
865 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, NULL
);
866 operand_id
= iclass
->operands
[opnd
].u
.operand_id
;
867 return &intisa
->operands
[operand_id
];
872 xtensa_operand_name (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
874 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
875 xtensa_operand_internal
*intop
;
877 intop
= get_operand (intisa
, opc
, opnd
);
878 if (!intop
) return NULL
;
884 xtensa_operand_is_visible (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
886 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
887 xtensa_iclass_internal
*iclass
;
888 int iclass_id
, operand_id
;
889 xtensa_operand_internal
*intop
;
891 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
892 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
893 iclass
= &intisa
->iclasses
[iclass_id
];
894 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, XTENSA_UNDEFINED
);
896 /* Special case for "sout" operands. */
897 if (iclass
->operands
[opnd
].inout
== 's')
900 operand_id
= iclass
->operands
[opnd
].u
.operand_id
;
901 intop
= &intisa
->operands
[operand_id
];
903 if ((intop
->flags
& XTENSA_OPERAND_IS_INVISIBLE
) == 0)
910 xtensa_operand_inout (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
912 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
913 xtensa_iclass_internal
*iclass
;
917 CHECK_OPCODE (intisa
, opc
, 0);
918 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
919 iclass
= &intisa
->iclasses
[iclass_id
];
920 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, 0);
921 inout
= iclass
->operands
[opnd
].inout
;
923 /* Special case for "sout" operands. */
932 xtensa_operand_get_field (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
933 xtensa_format fmt
, int slot
,
934 const xtensa_insnbuf slotbuf
, uint32
*valp
)
936 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
937 xtensa_operand_internal
*intop
;
939 xtensa_get_field_fn get_fn
;
941 intop
= get_operand (intisa
, opc
, opnd
);
942 if (!intop
) return -1;
944 CHECK_FORMAT (intisa
, fmt
, -1);
945 CHECK_SLOT (intisa
, fmt
, slot
, -1);
947 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
948 if (intop
->field_id
== XTENSA_UNDEFINED
)
950 xtisa_errno
= xtensa_isa_no_field
;
951 strcpy (xtisa_error_msg
, "implicit operand has no field");
954 get_fn
= intisa
->slots
[slot_id
].get_field_fns
[intop
->field_id
];
957 xtisa_errno
= xtensa_isa_wrong_slot
;
958 sprintf (xtisa_error_msg
,
959 "operand \"%s\" does not exist in slot %d of format \"%s\"",
960 intop
->name
, slot
, intisa
->formats
[fmt
].name
);
963 *valp
= (*get_fn
) (slotbuf
);
969 xtensa_operand_set_field (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
970 xtensa_format fmt
, int slot
,
971 xtensa_insnbuf slotbuf
, uint32 val
)
973 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
974 xtensa_operand_internal
*intop
;
976 xtensa_set_field_fn set_fn
;
978 intop
= get_operand (intisa
, opc
, opnd
);
979 if (!intop
) return -1;
981 CHECK_FORMAT (intisa
, fmt
, -1);
982 CHECK_SLOT (intisa
, fmt
, slot
, -1);
984 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
985 if (intop
->field_id
== XTENSA_UNDEFINED
)
987 xtisa_errno
= xtensa_isa_no_field
;
988 strcpy (xtisa_error_msg
, "implicit operand has no field");
991 set_fn
= intisa
->slots
[slot_id
].set_field_fns
[intop
->field_id
];
994 xtisa_errno
= xtensa_isa_wrong_slot
;
995 sprintf (xtisa_error_msg
,
996 "operand \"%s\" does not exist in slot %d of format \"%s\"",
997 intop
->name
, slot
, intisa
->formats
[fmt
].name
);
1000 (*set_fn
) (slotbuf
, val
);
1006 xtensa_operand_encode (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1009 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1010 xtensa_operand_internal
*intop
;
1011 uint32 test_val
, orig_val
;
1013 intop
= get_operand (intisa
, opc
, opnd
);
1019 /* This is a default operand for a field. How can we tell if the
1020 value fits in the field? Write the value into the field,
1021 read it back, and then make sure we get the same value. */
1022 static xtensa_insnbuf tmpbuf
= 0;
1027 tmpbuf
= xtensa_insnbuf_alloc (isa
);
1028 CHECK_ALLOC (tmpbuf
, -1);
1031 /* A default operand is always associated with a field,
1032 but check just to be sure.... */
1033 if (intop
->field_id
== XTENSA_UNDEFINED
)
1035 xtisa_errno
= xtensa_isa_internal_error
;
1036 strcpy (xtisa_error_msg
, "operand has no field");
1040 /* Find some slot that includes the field. */
1041 for (slot_id
= 0; slot_id
< intisa
->num_slots
; slot_id
++)
1043 xtensa_get_field_fn get_fn
=
1044 intisa
->slots
[slot_id
].get_field_fns
[intop
->field_id
];
1045 xtensa_set_field_fn set_fn
=
1046 intisa
->slots
[slot_id
].set_field_fns
[intop
->field_id
];
1048 if (get_fn
&& set_fn
)
1050 (*set_fn
) (tmpbuf
, *valp
);
1051 return ((*get_fn
) (tmpbuf
) != *valp
);
1055 /* Couldn't find any slot containing the field.... */
1056 xtisa_errno
= xtensa_isa_no_field
;
1057 strcpy (xtisa_error_msg
, "field does not exist in any slot");
1061 /* Encode the value. In some cases, the encoding function may detect
1062 errors, but most of the time the only way to determine if the value
1063 was successfully encoded is to decode it and check if it matches
1064 the original value. */
1066 if ((*intop
->encode
) (valp
)
1067 || (test_val
= *valp
, (*intop
->decode
) (&test_val
))
1068 || test_val
!= orig_val
)
1070 xtisa_errno
= xtensa_isa_bad_value
;
1071 sprintf (xtisa_error_msg
, "cannot encode operand value 0x%08x", *valp
);
1080 xtensa_operand_decode (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1083 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1084 xtensa_operand_internal
*intop
;
1086 intop
= get_operand (intisa
, opc
, opnd
);
1087 if (!intop
) return -1;
1089 /* Use identity function for "default" operands. */
1093 if ((*intop
->decode
) (valp
))
1095 xtisa_errno
= xtensa_isa_bad_value
;
1096 sprintf (xtisa_error_msg
, "cannot decode operand value 0x%08x", *valp
);
1104 xtensa_operand_is_register (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1106 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1107 xtensa_operand_internal
*intop
;
1109 intop
= get_operand (intisa
, opc
, opnd
);
1110 if (!intop
) return XTENSA_UNDEFINED
;
1112 if ((intop
->flags
& XTENSA_OPERAND_IS_REGISTER
) != 0)
1119 xtensa_operand_regfile (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1121 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1122 xtensa_operand_internal
*intop
;
1124 intop
= get_operand (intisa
, opc
, opnd
);
1125 if (!intop
) return XTENSA_UNDEFINED
;
1127 return intop
->regfile
;
1132 xtensa_operand_num_regs (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1134 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1135 xtensa_operand_internal
*intop
;
1137 intop
= get_operand (intisa
, opc
, opnd
);
1138 if (!intop
) return XTENSA_UNDEFINED
;
1140 return intop
->num_regs
;
1145 xtensa_operand_is_known_reg (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1147 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1148 xtensa_operand_internal
*intop
;
1150 intop
= get_operand (intisa
, opc
, opnd
);
1151 if (!intop
) return XTENSA_UNDEFINED
;
1153 if ((intop
->flags
& XTENSA_OPERAND_IS_UNKNOWN
) == 0)
1160 xtensa_operand_is_PCrelative (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1162 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1163 xtensa_operand_internal
*intop
;
1165 intop
= get_operand (intisa
, opc
, opnd
);
1166 if (!intop
) return XTENSA_UNDEFINED
;
1168 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) != 0)
1175 xtensa_operand_do_reloc (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1176 uint32
*valp
, uint32 pc
)
1178 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1179 xtensa_operand_internal
*intop
;
1181 intop
= get_operand (intisa
, opc
, opnd
);
1182 if (!intop
) return -1;
1184 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) == 0)
1187 if (!intop
->do_reloc
)
1189 xtisa_errno
= xtensa_isa_internal_error
;
1190 strcpy (xtisa_error_msg
, "operand missing do_reloc function");
1194 if ((*intop
->do_reloc
) (valp
, pc
))
1196 xtisa_errno
= xtensa_isa_bad_value
;
1197 sprintf (xtisa_error_msg
,
1198 "do_reloc failed for value 0x%08x at PC 0x%08x", *valp
, pc
);
1207 xtensa_operand_undo_reloc (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1208 uint32
*valp
, uint32 pc
)
1210 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1211 xtensa_operand_internal
*intop
;
1213 intop
= get_operand (intisa
, opc
, opnd
);
1214 if (!intop
) return -1;
1216 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) == 0)
1219 if (!intop
->undo_reloc
)
1221 xtisa_errno
= xtensa_isa_internal_error
;
1222 strcpy (xtisa_error_msg
, "operand missing undo_reloc function");
1226 if ((*intop
->undo_reloc
) (valp
, pc
))
1228 xtisa_errno
= xtensa_isa_bad_value
;
1229 sprintf (xtisa_error_msg
,
1230 "undo_reloc failed for value 0x%08x at PC 0x%08x", *valp
, pc
);
1239 /* State Operands. */
1242 #define CHECK_STATE_OPERAND(INTISA,OPC,ICLASS,STOP,ERRVAL) \
1244 if ((STOP) < 0 || (STOP) >= (ICLASS)->num_stateOperands) \
1246 xtisa_errno = xtensa_isa_bad_operand; \
1247 sprintf (xtisa_error_msg, "invalid state operand number (%d); " \
1248 "opcode \"%s\" has %d state operands", (STOP), \
1249 (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_stateOperands); \
1256 xtensa_stateOperand_state (xtensa_isa isa
, xtensa_opcode opc
, int stOp
)
1258 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1259 xtensa_iclass_internal
*iclass
;
1262 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
1263 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1264 iclass
= &intisa
->iclasses
[iclass_id
];
1265 CHECK_STATE_OPERAND (intisa
, opc
, iclass
, stOp
, XTENSA_UNDEFINED
);
1266 return iclass
->stateOperands
[stOp
].u
.state
;
1271 xtensa_stateOperand_inout (xtensa_isa isa
, xtensa_opcode opc
, int stOp
)
1273 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1274 xtensa_iclass_internal
*iclass
;
1277 CHECK_OPCODE (intisa
, opc
, 0);
1278 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1279 iclass
= &intisa
->iclasses
[iclass_id
];
1280 CHECK_STATE_OPERAND (intisa
, opc
, iclass
, stOp
, 0);
1281 return iclass
->stateOperands
[stOp
].inout
;
1286 /* Interface Operands. */
1289 #define CHECK_INTERFACE_OPERAND(INTISA,OPC,ICLASS,IFOP,ERRVAL) \
1291 if ((IFOP) < 0 || (IFOP) >= (ICLASS)->num_interfaceOperands) \
1293 xtisa_errno = xtensa_isa_bad_operand; \
1294 sprintf (xtisa_error_msg, "invalid interface operand number (%d); " \
1295 "opcode \"%s\" has %d interface operands", (IFOP), \
1296 (INTISA)->opcodes[(OPC)].name, \
1297 (ICLASS)->num_interfaceOperands); \
1304 xtensa_interfaceOperand_interface (xtensa_isa isa
, xtensa_opcode opc
,
1307 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1308 xtensa_iclass_internal
*iclass
;
1311 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
1312 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1313 iclass
= &intisa
->iclasses
[iclass_id
];
1314 CHECK_INTERFACE_OPERAND (intisa
, opc
, iclass
, ifOp
, XTENSA_UNDEFINED
);
1315 return iclass
->interfaceOperands
[ifOp
];
1320 /* Register Files. */
1323 #define CHECK_REGFILE(INTISA,RF,ERRVAL) \
1325 if ((RF) < 0 || (RF) >= (INTISA)->num_regfiles) \
1327 xtisa_errno = xtensa_isa_bad_regfile; \
1328 strcpy (xtisa_error_msg, "invalid regfile specifier"); \
1335 xtensa_regfile_lookup (xtensa_isa isa
, const char *name
)
1337 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1340 if (!name
|| !*name
)
1342 xtisa_errno
= xtensa_isa_bad_regfile
;
1343 strcpy (xtisa_error_msg
, "invalid regfile name");
1344 return XTENSA_UNDEFINED
;
1347 /* The expected number of regfiles is small; use a linear search. */
1348 for (n
= 0; n
< intisa
->num_regfiles
; n
++)
1350 if (!filename_cmp (intisa
->regfiles
[n
].name
, name
))
1354 xtisa_errno
= xtensa_isa_bad_regfile
;
1355 sprintf (xtisa_error_msg
, "regfile \"%s\" not recognized", name
);
1356 return XTENSA_UNDEFINED
;
1361 xtensa_regfile_lookup_shortname (xtensa_isa isa
, const char *shortname
)
1363 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1366 if (!shortname
|| !*shortname
)
1368 xtisa_errno
= xtensa_isa_bad_regfile
;
1369 strcpy (xtisa_error_msg
, "invalid regfile shortname");
1370 return XTENSA_UNDEFINED
;
1373 /* The expected number of regfiles is small; use a linear search. */
1374 for (n
= 0; n
< intisa
->num_regfiles
; n
++)
1376 /* Ignore regfile views since they always have the same shortnames
1377 as their parents. */
1378 if (intisa
->regfiles
[n
].parent
!= n
)
1380 if (!filename_cmp (intisa
->regfiles
[n
].shortname
, shortname
))
1384 xtisa_errno
= xtensa_isa_bad_regfile
;
1385 sprintf (xtisa_error_msg
, "regfile shortname \"%s\" not recognized",
1387 return XTENSA_UNDEFINED
;
1392 xtensa_regfile_name (xtensa_isa isa
, xtensa_regfile rf
)
1394 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1395 CHECK_REGFILE (intisa
, rf
, NULL
);
1396 return intisa
->regfiles
[rf
].name
;
1401 xtensa_regfile_shortname (xtensa_isa isa
, xtensa_regfile rf
)
1403 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1404 CHECK_REGFILE (intisa
, rf
, NULL
);
1405 return intisa
->regfiles
[rf
].shortname
;
1410 xtensa_regfile_view_parent (xtensa_isa isa
, xtensa_regfile rf
)
1412 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1413 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1414 return intisa
->regfiles
[rf
].parent
;
1419 xtensa_regfile_num_bits (xtensa_isa isa
, xtensa_regfile rf
)
1421 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1422 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1423 return intisa
->regfiles
[rf
].num_bits
;
1428 xtensa_regfile_num_entries (xtensa_isa isa
, xtensa_regfile rf
)
1430 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1431 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1432 return intisa
->regfiles
[rf
].num_entries
;
1437 /* Processor States. */
1440 #define CHECK_STATE(INTISA,ST,ERRVAL) \
1442 if ((ST) < 0 || (ST) >= (INTISA)->num_states) \
1444 xtisa_errno = xtensa_isa_bad_state; \
1445 strcpy (xtisa_error_msg, "invalid state specifier"); \
1452 xtensa_state_lookup (xtensa_isa isa
, const char *name
)
1454 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1455 xtensa_lookup_entry entry
, *result
= 0;
1457 if (!name
|| !*name
)
1459 xtisa_errno
= xtensa_isa_bad_state
;
1460 strcpy (xtisa_error_msg
, "invalid state name");
1461 return XTENSA_UNDEFINED
;
1464 if (intisa
->num_states
!= 0)
1467 result
= bsearch (&entry
, intisa
->state_lookup_table
, intisa
->num_states
,
1468 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
1473 xtisa_errno
= xtensa_isa_bad_state
;
1474 sprintf (xtisa_error_msg
, "state \"%s\" not recognized", name
);
1475 return XTENSA_UNDEFINED
;
1478 return result
->u
.state
;
1483 xtensa_state_name (xtensa_isa isa
, xtensa_state st
)
1485 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1486 CHECK_STATE (intisa
, st
, NULL
);
1487 return intisa
->states
[st
].name
;
1492 xtensa_state_num_bits (xtensa_isa isa
, xtensa_state st
)
1494 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1495 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1496 return intisa
->states
[st
].num_bits
;
1501 xtensa_state_is_exported (xtensa_isa isa
, xtensa_state st
)
1503 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1504 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1505 if ((intisa
->states
[st
].flags
& XTENSA_STATE_IS_EXPORTED
) != 0)
1512 xtensa_state_is_shared_or (xtensa_isa isa
, xtensa_state st
)
1514 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1515 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1516 if ((intisa
->states
[st
].flags
& XTENSA_STATE_IS_SHARED_OR
) != 0)
1526 #define CHECK_SYSREG(INTISA,SYSREG,ERRVAL) \
1528 if ((SYSREG) < 0 || (SYSREG) >= (INTISA)->num_sysregs) \
1530 xtisa_errno = xtensa_isa_bad_sysreg; \
1531 strcpy (xtisa_error_msg, "invalid sysreg specifier"); \
1538 xtensa_sysreg_lookup (xtensa_isa isa
, int num
, int is_user
)
1540 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1545 if (num
< 0 || num
> intisa
->max_sysreg_num
[is_user
]
1546 || intisa
->sysreg_table
[is_user
][num
] == XTENSA_UNDEFINED
)
1548 xtisa_errno
= xtensa_isa_bad_sysreg
;
1549 strcpy (xtisa_error_msg
, "sysreg not recognized");
1550 return XTENSA_UNDEFINED
;
1553 return intisa
->sysreg_table
[is_user
][num
];
1558 xtensa_sysreg_lookup_name (xtensa_isa isa
, const char *name
)
1560 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1561 xtensa_lookup_entry entry
, *result
= 0;
1563 if (!name
|| !*name
)
1565 xtisa_errno
= xtensa_isa_bad_sysreg
;
1566 strcpy (xtisa_error_msg
, "invalid sysreg name");
1567 return XTENSA_UNDEFINED
;
1570 if (intisa
->num_sysregs
!= 0)
1573 result
= bsearch (&entry
, intisa
->sysreg_lookup_table
,
1574 intisa
->num_sysregs
, sizeof (xtensa_lookup_entry
),
1575 xtensa_isa_name_compare
);
1580 xtisa_errno
= xtensa_isa_bad_sysreg
;
1581 sprintf (xtisa_error_msg
, "sysreg \"%s\" not recognized", name
);
1582 return XTENSA_UNDEFINED
;
1585 return result
->u
.sysreg
;
1590 xtensa_sysreg_name (xtensa_isa isa
, xtensa_sysreg sysreg
)
1592 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1593 CHECK_SYSREG (intisa
, sysreg
, NULL
);
1594 return intisa
->sysregs
[sysreg
].name
;
1599 xtensa_sysreg_number (xtensa_isa isa
, xtensa_sysreg sysreg
)
1601 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1602 CHECK_SYSREG (intisa
, sysreg
, XTENSA_UNDEFINED
);
1603 return intisa
->sysregs
[sysreg
].number
;
1608 xtensa_sysreg_is_user (xtensa_isa isa
, xtensa_sysreg sysreg
)
1610 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1611 CHECK_SYSREG (intisa
, sysreg
, XTENSA_UNDEFINED
);
1612 if (intisa
->sysregs
[sysreg
].is_user
)
1622 #define CHECK_INTERFACE(INTISA,INTF,ERRVAL) \
1624 if ((INTF) < 0 || (INTF) >= (INTISA)->num_interfaces) \
1626 xtisa_errno = xtensa_isa_bad_interface; \
1627 strcpy (xtisa_error_msg, "invalid interface specifier"); \
1634 xtensa_interface_lookup (xtensa_isa isa
, const char *ifname
)
1636 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1637 xtensa_lookup_entry entry
, *result
= 0;
1639 if (!ifname
|| !*ifname
)
1641 xtisa_errno
= xtensa_isa_bad_interface
;
1642 strcpy (xtisa_error_msg
, "invalid interface name");
1643 return XTENSA_UNDEFINED
;
1646 if (intisa
->num_interfaces
!= 0)
1649 result
= bsearch (&entry
, intisa
->interface_lookup_table
,
1650 intisa
->num_interfaces
, sizeof (xtensa_lookup_entry
),
1651 xtensa_isa_name_compare
);
1656 xtisa_errno
= xtensa_isa_bad_interface
;
1657 sprintf (xtisa_error_msg
, "interface \"%s\" not recognized", ifname
);
1658 return XTENSA_UNDEFINED
;
1661 return result
->u
.intf
;
1666 xtensa_interface_name (xtensa_isa isa
, xtensa_interface intf
)
1668 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1669 CHECK_INTERFACE (intisa
, intf
, NULL
);
1670 return intisa
->interfaces
[intf
].name
;
1675 xtensa_interface_num_bits (xtensa_isa isa
, xtensa_interface intf
)
1677 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1678 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1679 return intisa
->interfaces
[intf
].num_bits
;
1684 xtensa_interface_inout (xtensa_isa isa
, xtensa_interface intf
)
1686 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1687 CHECK_INTERFACE (intisa
, intf
, 0);
1688 return intisa
->interfaces
[intf
].inout
;
1693 xtensa_interface_has_side_effect (xtensa_isa isa
, xtensa_interface intf
)
1695 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1696 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1697 if ((intisa
->interfaces
[intf
].flags
& XTENSA_INTERFACE_HAS_SIDE_EFFECT
) != 0)
1704 xtensa_interface_class_id (xtensa_isa isa
, xtensa_interface intf
)
1706 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1707 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1708 return intisa
->interfaces
[intf
].class_id
;
1713 /* Functional Units. */
1716 #define CHECK_FUNCUNIT(INTISA,FUN,ERRVAL) \
1718 if ((FUN) < 0 || (FUN) >= (INTISA)->num_funcUnits) \
1720 xtisa_errno = xtensa_isa_bad_funcUnit; \
1721 strcpy (xtisa_error_msg, "invalid functional unit specifier"); \
1728 xtensa_funcUnit_lookup (xtensa_isa isa
, const char *fname
)
1730 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1731 xtensa_lookup_entry entry
, *result
= 0;
1733 if (!fname
|| !*fname
)
1735 xtisa_errno
= xtensa_isa_bad_funcUnit
;
1736 strcpy (xtisa_error_msg
, "invalid functional unit name");
1737 return XTENSA_UNDEFINED
;
1740 if (intisa
->num_funcUnits
!= 0)
1743 result
= bsearch (&entry
, intisa
->funcUnit_lookup_table
,
1744 intisa
->num_funcUnits
, sizeof (xtensa_lookup_entry
),
1745 xtensa_isa_name_compare
);
1750 xtisa_errno
= xtensa_isa_bad_funcUnit
;
1751 sprintf (xtisa_error_msg
,
1752 "functional unit \"%s\" not recognized", fname
);
1753 return XTENSA_UNDEFINED
;
1756 return result
->u
.fun
;
1761 xtensa_funcUnit_name (xtensa_isa isa
, xtensa_funcUnit fun
)
1763 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1764 CHECK_FUNCUNIT (intisa
, fun
, NULL
);
1765 return intisa
->funcUnits
[fun
].name
;
1770 xtensa_funcUnit_num_copies (xtensa_isa isa
, xtensa_funcUnit fun
)
1772 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1773 CHECK_FUNCUNIT (intisa
, fun
, XTENSA_UNDEFINED
);
1774 return intisa
->funcUnits
[fun
].num_copies
;