1 /* Configurable Xtensa ISA support.
2 Copyright 2003, 2004, 2005 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "xtensa-isa.h"
24 #include "xtensa-isa-internal.h"
26 xtensa_isa_status xtisa_errno
;
27 char xtisa_error_msg
[1024];
31 xtensa_isa_errno (xtensa_isa isa
__attribute__ ((unused
)))
38 xtensa_isa_error_msg (xtensa_isa isa
__attribute__ ((unused
)))
40 return xtisa_error_msg
;
44 #define CHECK_ALLOC(MEM,ERRVAL) \
48 xtisa_errno = xtensa_isa_out_of_memory; \
49 strcpy (xtisa_error_msg, "out of memory"); \
54 #define CHECK_ALLOC_FOR_INIT(MEM,ERRVAL,ERRNO_P,ERROR_MSG_P) \
58 xtisa_errno = xtensa_isa_out_of_memory; \
59 strcpy (xtisa_error_msg, "out of memory"); \
60 if (ERRNO_P) *(ERRNO_P) = xtisa_errno; \
61 if (ERROR_MSG_P) *(ERROR_MSG_P) = xtisa_error_msg; \
67 /* Instruction buffers. */
70 xtensa_insnbuf_size (xtensa_isa isa
)
72 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
73 return intisa
->insnbuf_size
;
78 xtensa_insnbuf_alloc (xtensa_isa isa
)
80 xtensa_insnbuf result
= (xtensa_insnbuf
)
81 malloc (xtensa_insnbuf_size (isa
) * sizeof (xtensa_insnbuf_word
));
82 CHECK_ALLOC (result
, 0);
88 xtensa_insnbuf_free (xtensa_isa isa
__attribute__ ((unused
)),
95 /* Given <byte_index>, the index of a byte in a xtensa_insnbuf, our
96 internal representation of a xtensa instruction word, return the index of
97 its word and the bit index of its low order byte in the xtensa_insnbuf. */
100 byte_to_word_index (int byte_index
)
102 return byte_index
/ sizeof (xtensa_insnbuf_word
);
107 byte_to_bit_index (int byte_index
)
109 return (byte_index
& 0x3) * 8;
113 /* Copy an instruction in the 32-bit words pointed at by "insn" to
114 characters pointed at by "cp". This is more complicated than you
115 might think because we want 16-bit instructions in bytes 2 & 3 for
116 big-endian configurations. This function allows us to specify
117 which byte in "insn" to start with and which way to increment,
118 allowing trivial implementation for both big- and little-endian
119 configurations....and it seems to make pretty good code for
123 xtensa_insnbuf_to_chars (xtensa_isa isa
,
124 const xtensa_insnbuf insn
,
128 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
129 int insn_size
= xtensa_isa_maxlength (isa
);
130 int fence_post
, start
, increment
, i
, byte_count
;
134 num_chars
= insn_size
;
136 if (intisa
->is_big_endian
)
138 start
= insn_size
- 1;
147 /* Find the instruction format. Do nothing if the buffer does not contain
148 a valid instruction since we need to know how many bytes to copy. */
149 fmt
= xtensa_format_decode (isa
, insn
);
150 if (fmt
== XTENSA_UNDEFINED
)
151 return XTENSA_UNDEFINED
;
153 byte_count
= xtensa_format_length (isa
, fmt
);
154 if (byte_count
== XTENSA_UNDEFINED
)
155 return XTENSA_UNDEFINED
;
157 if (byte_count
> num_chars
)
159 xtisa_errno
= xtensa_isa_buffer_overflow
;
160 strcpy (xtisa_error_msg
, "output buffer too small for instruction");
161 return XTENSA_UNDEFINED
;
164 fence_post
= start
+ (byte_count
* increment
);
166 for (i
= start
; i
!= fence_post
; i
+= increment
, ++cp
)
168 int word_inx
= byte_to_word_index (i
);
169 int bit_inx
= byte_to_bit_index (i
);
171 *cp
= (insn
[word_inx
] >> bit_inx
) & 0xff;
178 /* Inward conversion from byte stream to xtensa_insnbuf. See
179 xtensa_insnbuf_to_chars for a discussion of why this is complicated
183 xtensa_insnbuf_from_chars (xtensa_isa isa
,
185 const unsigned char *cp
,
188 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
189 int max_size
, insn_size
, fence_post
, start
, increment
, i
;
191 max_size
= xtensa_isa_maxlength (isa
);
193 /* Decode the instruction length so we know how many bytes to read. */
194 insn_size
= (intisa
->length_decode_fn
) (cp
);
195 if (insn_size
== XTENSA_UNDEFINED
)
197 /* This should never happen when the byte stream contains a
198 valid instruction. Just read the maximum number of bytes.... */
199 insn_size
= max_size
;
202 if (num_chars
== 0 || num_chars
> insn_size
)
203 num_chars
= insn_size
;
205 if (intisa
->is_big_endian
)
207 start
= max_size
- 1;
216 fence_post
= start
+ (num_chars
* increment
);
217 memset (insn
, 0, xtensa_insnbuf_size (isa
) * sizeof (xtensa_insnbuf_word
));
219 for (i
= start
; i
!= fence_post
; i
+= increment
, ++cp
)
221 int word_inx
= byte_to_word_index (i
);
222 int bit_inx
= byte_to_bit_index (i
);
224 insn
[word_inx
] |= (*cp
& 0xff) << bit_inx
;
230 /* ISA information. */
232 extern xtensa_isa_internal xtensa_modules
;
235 xtensa_isa_init (xtensa_isa_status
*errno_p
, char **error_msg_p
)
237 xtensa_isa_internal
*isa
= &xtensa_modules
;
240 /* Set up the opcode name lookup table. */
241 isa
->opname_lookup_table
=
242 bfd_malloc (isa
->num_opcodes
* sizeof (xtensa_lookup_entry
));
243 CHECK_ALLOC_FOR_INIT (isa
->opname_lookup_table
, NULL
, errno_p
, error_msg_p
);
244 for (n
= 0; n
< isa
->num_opcodes
; n
++)
246 isa
->opname_lookup_table
[n
].key
= isa
->opcodes
[n
].name
;
247 isa
->opname_lookup_table
[n
].u
.opcode
= n
;
249 qsort (isa
->opname_lookup_table
, isa
->num_opcodes
,
250 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
252 /* Set up the state name lookup table. */
253 isa
->state_lookup_table
=
254 bfd_malloc (isa
->num_states
* sizeof (xtensa_lookup_entry
));
255 CHECK_ALLOC_FOR_INIT (isa
->state_lookup_table
, NULL
, errno_p
, error_msg_p
);
256 for (n
= 0; n
< isa
->num_states
; n
++)
258 isa
->state_lookup_table
[n
].key
= isa
->states
[n
].name
;
259 isa
->state_lookup_table
[n
].u
.state
= n
;
261 qsort (isa
->state_lookup_table
, isa
->num_states
,
262 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
264 /* Set up the sysreg name lookup table. */
265 isa
->sysreg_lookup_table
=
266 bfd_malloc (isa
->num_sysregs
* sizeof (xtensa_lookup_entry
));
267 CHECK_ALLOC_FOR_INIT (isa
->sysreg_lookup_table
, NULL
, errno_p
, error_msg_p
);
268 for (n
= 0; n
< isa
->num_sysregs
; n
++)
270 isa
->sysreg_lookup_table
[n
].key
= isa
->sysregs
[n
].name
;
271 isa
->sysreg_lookup_table
[n
].u
.sysreg
= n
;
273 qsort (isa
->sysreg_lookup_table
, isa
->num_sysregs
,
274 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
276 /* Set up the user & system sysreg number tables. */
277 for (is_user
= 0; is_user
< 2; is_user
++)
279 isa
->sysreg_table
[is_user
] =
280 bfd_malloc ((isa
->max_sysreg_num
[is_user
] + 1)
281 * sizeof (xtensa_sysreg
));
282 CHECK_ALLOC_FOR_INIT (isa
->sysreg_table
[is_user
], NULL
,
283 errno_p
, error_msg_p
);
285 for (n
= 0; n
<= isa
->max_sysreg_num
[is_user
]; n
++)
286 isa
->sysreg_table
[is_user
][n
] = XTENSA_UNDEFINED
;
288 for (n
= 0; n
< isa
->num_sysregs
; n
++)
290 xtensa_sysreg_internal
*sreg
= &isa
->sysregs
[n
];
291 is_user
= sreg
->is_user
;
293 isa
->sysreg_table
[is_user
][sreg
->number
] = n
;
296 /* Set up the interface lookup table. */
297 isa
->interface_lookup_table
=
298 bfd_malloc (isa
->num_interfaces
* sizeof (xtensa_lookup_entry
));
299 CHECK_ALLOC_FOR_INIT (isa
->interface_lookup_table
, NULL
, errno_p
,
301 for (n
= 0; n
< isa
->num_interfaces
; n
++)
303 isa
->interface_lookup_table
[n
].key
= isa
->interfaces
[n
].name
;
304 isa
->interface_lookup_table
[n
].u
.intf
= n
;
306 qsort (isa
->interface_lookup_table
, isa
->num_interfaces
,
307 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
309 /* Set up the funcUnit lookup table. */
310 isa
->funcUnit_lookup_table
=
311 bfd_malloc (isa
->num_funcUnits
* sizeof (xtensa_lookup_entry
));
312 CHECK_ALLOC_FOR_INIT (isa
->funcUnit_lookup_table
, NULL
, errno_p
,
314 for (n
= 0; n
< isa
->num_funcUnits
; n
++)
316 isa
->funcUnit_lookup_table
[n
].key
= isa
->funcUnits
[n
].name
;
317 isa
->funcUnit_lookup_table
[n
].u
.fun
= n
;
319 qsort (isa
->funcUnit_lookup_table
, isa
->num_funcUnits
,
320 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
322 isa
->insnbuf_size
= ((isa
->insn_size
+ sizeof (xtensa_insnbuf_word
) - 1) /
323 sizeof (xtensa_insnbuf_word
));
325 return (xtensa_isa
) isa
;
330 xtensa_isa_free (xtensa_isa isa
)
332 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
335 /* With this version of the code, the xtensa_isa structure is not
336 dynamically allocated, so this function is not essential. Free
337 the memory allocated by xtensa_isa_init and restore the xtensa_isa
338 structure to its initial state. */
340 if (intisa
->opname_lookup_table
)
342 free (intisa
->opname_lookup_table
);
343 intisa
->opname_lookup_table
= 0;
346 if (intisa
->state_lookup_table
)
348 free (intisa
->state_lookup_table
);
349 intisa
->state_lookup_table
= 0;
352 if (intisa
->sysreg_lookup_table
)
354 free (intisa
->sysreg_lookup_table
);
355 intisa
->sysreg_lookup_table
= 0;
357 for (n
= 0; n
< 2; n
++)
359 if (intisa
->sysreg_table
[n
])
361 free (intisa
->sysreg_table
[n
]);
362 intisa
->sysreg_table
[n
] = 0;
366 if (intisa
->interface_lookup_table
)
368 free (intisa
->interface_lookup_table
);
369 intisa
->interface_lookup_table
= 0;
372 if (intisa
->funcUnit_lookup_table
)
374 free (intisa
->funcUnit_lookup_table
);
375 intisa
->funcUnit_lookup_table
= 0;
381 xtensa_isa_name_compare (const void *v1
, const void *v2
)
383 xtensa_lookup_entry
*e1
= (xtensa_lookup_entry
*) v1
;
384 xtensa_lookup_entry
*e2
= (xtensa_lookup_entry
*) v2
;
386 return strcasecmp (e1
->key
, e2
->key
);
391 xtensa_isa_maxlength (xtensa_isa isa
)
393 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
394 return intisa
->insn_size
;
399 xtensa_isa_length_from_chars (xtensa_isa isa
, const unsigned char *cp
)
401 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
402 return (intisa
->length_decode_fn
) (cp
);
407 xtensa_isa_num_pipe_stages (xtensa_isa isa
)
409 int num_opcodes
, num_uses
;
410 xtensa_opcode opcode
;
411 xtensa_funcUnit_use
*use
;
412 int i
, stage
, max_stage
= XTENSA_UNDEFINED
;
414 num_opcodes
= xtensa_isa_num_opcodes (isa
);
415 for (opcode
= 0; opcode
< num_opcodes
; opcode
++)
417 num_uses
= xtensa_opcode_num_funcUnit_uses (isa
, opcode
);
418 for (i
= 0; i
< num_uses
; i
++)
420 use
= xtensa_opcode_funcUnit_use (isa
, opcode
, i
);
422 if (stage
> max_stage
)
427 return max_stage
+ 1;
432 xtensa_isa_num_formats (xtensa_isa isa
)
434 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
435 return intisa
->num_formats
;
440 xtensa_isa_num_opcodes (xtensa_isa isa
)
442 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
443 return intisa
->num_opcodes
;
448 xtensa_isa_num_regfiles (xtensa_isa isa
)
450 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
451 return intisa
->num_regfiles
;
456 xtensa_isa_num_states (xtensa_isa isa
)
458 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
459 return intisa
->num_states
;
464 xtensa_isa_num_sysregs (xtensa_isa isa
)
466 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
467 return intisa
->num_sysregs
;
472 xtensa_isa_num_interfaces (xtensa_isa isa
)
474 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
475 return intisa
->num_interfaces
;
480 xtensa_isa_num_funcUnits (xtensa_isa isa
)
482 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
483 return intisa
->num_funcUnits
;
488 /* Instruction formats. */
491 #define CHECK_FORMAT(INTISA,FMT,ERRVAL) \
493 if ((FMT) < 0 || (FMT) >= (INTISA)->num_formats) \
495 xtisa_errno = xtensa_isa_bad_format; \
496 strcpy (xtisa_error_msg, "invalid format specifier"); \
502 #define CHECK_SLOT(INTISA,FMT,SLOT,ERRVAL) \
504 if ((SLOT) < 0 || (SLOT) >= (INTISA)->formats[FMT].num_slots) \
506 xtisa_errno = xtensa_isa_bad_slot; \
507 strcpy (xtisa_error_msg, "invalid slot specifier"); \
514 xtensa_format_name (xtensa_isa isa
, xtensa_format fmt
)
516 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
517 CHECK_FORMAT (intisa
, fmt
, NULL
);
518 return intisa
->formats
[fmt
].name
;
523 xtensa_format_lookup (xtensa_isa isa
, const char *fmtname
)
525 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
528 if (!fmtname
|| !*fmtname
)
530 xtisa_errno
= xtensa_isa_bad_format
;
531 strcpy (xtisa_error_msg
, "invalid format name");
532 return XTENSA_UNDEFINED
;
535 for (fmt
= 0; fmt
< intisa
->num_formats
; fmt
++)
537 if (strcasecmp (fmtname
, intisa
->formats
[fmt
].name
) == 0)
541 xtisa_errno
= xtensa_isa_bad_format
;
542 sprintf (xtisa_error_msg
, "format \"%s\" not recognized", fmtname
);
543 return XTENSA_UNDEFINED
;
548 xtensa_format_decode (xtensa_isa isa
, const xtensa_insnbuf insn
)
550 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
553 fmt
= (intisa
->format_decode_fn
) (insn
);
554 if (fmt
!= XTENSA_UNDEFINED
)
557 xtisa_errno
= xtensa_isa_bad_format
;
558 strcpy (xtisa_error_msg
, "cannot decode instruction format");
559 return XTENSA_UNDEFINED
;
564 xtensa_format_encode (xtensa_isa isa
, xtensa_format fmt
, xtensa_insnbuf insn
)
566 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
567 CHECK_FORMAT (intisa
, fmt
, -1);
568 (*intisa
->formats
[fmt
].encode_fn
) (insn
);
574 xtensa_format_length (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
].length
;
583 xtensa_format_num_slots (xtensa_isa isa
, xtensa_format fmt
)
585 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
586 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
587 return intisa
->formats
[fmt
].num_slots
;
592 xtensa_format_slot_nop_opcode (xtensa_isa isa
, xtensa_format fmt
, int slot
)
594 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
597 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
598 CHECK_SLOT (intisa
, fmt
, slot
, XTENSA_UNDEFINED
);
600 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
601 return xtensa_opcode_lookup (isa
, intisa
->slots
[slot_id
].nop_name
);
606 xtensa_format_get_slot (xtensa_isa isa
, xtensa_format fmt
, int slot
,
607 const xtensa_insnbuf insn
, xtensa_insnbuf slotbuf
)
609 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
612 CHECK_FORMAT (intisa
, fmt
, -1);
613 CHECK_SLOT (intisa
, fmt
, slot
, -1);
615 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
616 (*intisa
->slots
[slot_id
].get_fn
) (insn
, slotbuf
);
622 xtensa_format_set_slot (xtensa_isa isa
, xtensa_format fmt
, int slot
,
623 xtensa_insnbuf insn
, const xtensa_insnbuf slotbuf
)
625 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
628 CHECK_FORMAT (intisa
, fmt
, -1);
629 CHECK_SLOT (intisa
, fmt
, slot
, -1);
631 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
632 (*intisa
->slots
[slot_id
].set_fn
) (insn
, slotbuf
);
638 /* Opcode information. */
641 #define CHECK_OPCODE(INTISA,OPC,ERRVAL) \
643 if ((OPC) < 0 || (OPC) >= (INTISA)->num_opcodes) \
645 xtisa_errno = xtensa_isa_bad_opcode; \
646 strcpy (xtisa_error_msg, "invalid opcode specifier"); \
653 xtensa_opcode_lookup (xtensa_isa isa
, const char *opname
)
655 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
656 xtensa_lookup_entry entry
, *result
;
658 if (!opname
|| !*opname
)
660 xtisa_errno
= xtensa_isa_bad_opcode
;
661 strcpy (xtisa_error_msg
, "invalid opcode name");
662 return XTENSA_UNDEFINED
;
666 result
= bsearch (&entry
, intisa
->opname_lookup_table
, intisa
->num_opcodes
,
667 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
671 xtisa_errno
= xtensa_isa_bad_opcode
;
672 sprintf (xtisa_error_msg
, "opcode \"%s\" not recognized", opname
);
673 return XTENSA_UNDEFINED
;
676 return result
->u
.opcode
;
681 xtensa_opcode_decode (xtensa_isa isa
, xtensa_format fmt
, int slot
,
682 const xtensa_insnbuf slotbuf
)
684 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
688 CHECK_FORMAT (intisa
, fmt
, XTENSA_UNDEFINED
);
689 CHECK_SLOT (intisa
, fmt
, slot
, XTENSA_UNDEFINED
);
691 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
693 opc
= (intisa
->slots
[slot_id
].opcode_decode_fn
) (slotbuf
);
694 if (opc
== XTENSA_UNDEFINED
)
696 xtisa_errno
= xtensa_isa_bad_opcode
;
697 strcpy (xtisa_error_msg
, "cannot decode opcode");
704 xtensa_opcode_encode (xtensa_isa isa
, xtensa_format fmt
, int slot
,
705 xtensa_insnbuf slotbuf
, xtensa_opcode opc
)
707 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
709 xtensa_opcode_encode_fn encode_fn
;
711 CHECK_FORMAT (intisa
, fmt
, -1);
712 CHECK_SLOT (intisa
, fmt
, slot
, -1);
713 CHECK_OPCODE (intisa
, opc
, -1);
715 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
716 encode_fn
= intisa
->opcodes
[opc
].encode_fns
[slot_id
];
719 xtisa_errno
= xtensa_isa_wrong_slot
;
720 sprintf (xtisa_error_msg
,
721 "opcode \"%s\" is not allowed in slot %d of format \"%s\"",
722 intisa
->opcodes
[opc
].name
, slot
, intisa
->formats
[fmt
].name
);
725 (*encode_fn
) (slotbuf
);
731 xtensa_opcode_name (xtensa_isa isa
, xtensa_opcode opc
)
733 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
734 CHECK_OPCODE (intisa
, opc
, NULL
);
735 return intisa
->opcodes
[opc
].name
;
740 xtensa_opcode_is_branch (xtensa_isa isa
, xtensa_opcode opc
)
742 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
743 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
744 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_BRANCH
) != 0)
751 xtensa_opcode_is_jump (xtensa_isa isa
, xtensa_opcode opc
)
753 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
754 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
755 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_JUMP
) != 0)
762 xtensa_opcode_is_loop (xtensa_isa isa
, xtensa_opcode opc
)
764 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
765 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
766 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_LOOP
) != 0)
773 xtensa_opcode_is_call (xtensa_isa isa
, xtensa_opcode opc
)
775 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
776 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
777 if ((intisa
->opcodes
[opc
].flags
& XTENSA_OPCODE_IS_CALL
) != 0)
784 xtensa_opcode_num_operands (xtensa_isa isa
, xtensa_opcode opc
)
786 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
789 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
790 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
791 return intisa
->iclasses
[iclass_id
].num_operands
;
796 xtensa_opcode_num_stateOperands (xtensa_isa isa
, xtensa_opcode opc
)
798 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
801 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
802 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
803 return intisa
->iclasses
[iclass_id
].num_stateOperands
;
808 xtensa_opcode_num_interfaceOperands (xtensa_isa isa
, xtensa_opcode opc
)
810 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
813 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
814 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
815 return intisa
->iclasses
[iclass_id
].num_interfaceOperands
;
820 xtensa_opcode_num_funcUnit_uses (xtensa_isa isa
, xtensa_opcode opc
)
822 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
823 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
824 return intisa
->opcodes
[opc
].num_funcUnit_uses
;
828 xtensa_funcUnit_use
*
829 xtensa_opcode_funcUnit_use (xtensa_isa isa
, xtensa_opcode opc
, int u
)
831 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
832 CHECK_OPCODE (intisa
, opc
, NULL
);
833 if (u
< 0 || u
>= intisa
->opcodes
[opc
].num_funcUnit_uses
)
835 xtisa_errno
= xtensa_isa_bad_funcUnit
;
836 sprintf (xtisa_error_msg
, "invalid functional unit use number (%d); "
837 "opcode \"%s\" has %d", u
, intisa
->opcodes
[opc
].name
,
838 intisa
->opcodes
[opc
].num_funcUnit_uses
);
841 return &intisa
->opcodes
[opc
].funcUnit_uses
[u
];
846 /* Operand information. */
849 #define CHECK_OPERAND(INTISA,OPC,ICLASS,OPND,ERRVAL) \
851 if ((OPND) < 0 || (OPND) >= (ICLASS)->num_operands) \
853 xtisa_errno = xtensa_isa_bad_operand; \
854 sprintf (xtisa_error_msg, "invalid operand number (%d); " \
855 "opcode \"%s\" has %d operands", (OPND), \
856 (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_operands); \
862 static xtensa_operand_internal
*
863 get_operand (xtensa_isa_internal
*intisa
, xtensa_opcode opc
, int opnd
)
865 xtensa_iclass_internal
*iclass
;
866 int iclass_id
, operand_id
;
868 CHECK_OPCODE (intisa
, opc
, NULL
);
869 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
870 iclass
= &intisa
->iclasses
[iclass_id
];
871 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, NULL
);
872 operand_id
= iclass
->operands
[opnd
].u
.operand_id
;
873 return &intisa
->operands
[operand_id
];
878 xtensa_operand_name (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
880 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
881 xtensa_operand_internal
*intop
;
883 intop
= get_operand (intisa
, opc
, opnd
);
884 if (!intop
) return NULL
;
890 xtensa_operand_is_visible (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
892 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
893 xtensa_iclass_internal
*iclass
;
894 int iclass_id
, operand_id
;
895 xtensa_operand_internal
*intop
;
897 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
898 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
899 iclass
= &intisa
->iclasses
[iclass_id
];
900 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, XTENSA_UNDEFINED
);
902 /* Special case for "sout" operands. */
903 if (iclass
->operands
[opnd
].inout
== 's')
906 operand_id
= iclass
->operands
[opnd
].u
.operand_id
;
907 intop
= &intisa
->operands
[operand_id
];
909 if ((intop
->flags
& XTENSA_OPERAND_IS_INVISIBLE
) == 0)
916 xtensa_operand_inout (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
918 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
919 xtensa_iclass_internal
*iclass
;
923 CHECK_OPCODE (intisa
, opc
, 0);
924 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
925 iclass
= &intisa
->iclasses
[iclass_id
];
926 CHECK_OPERAND (intisa
, opc
, iclass
, opnd
, 0);
927 inout
= iclass
->operands
[opnd
].inout
;
929 /* Special case for "sout" operands. */
938 xtensa_operand_get_field (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
939 xtensa_format fmt
, int slot
,
940 const xtensa_insnbuf slotbuf
, uint32
*valp
)
942 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
943 xtensa_operand_internal
*intop
;
945 xtensa_get_field_fn get_fn
;
947 intop
= get_operand (intisa
, opc
, opnd
);
948 if (!intop
) return -1;
950 CHECK_FORMAT (intisa
, fmt
, -1);
951 CHECK_SLOT (intisa
, fmt
, slot
, -1);
953 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
954 if (intop
->field_id
== XTENSA_UNDEFINED
)
956 xtisa_errno
= xtensa_isa_no_field
;
957 strcpy (xtisa_error_msg
, "implicit operand has no field");
960 get_fn
= intisa
->slots
[slot_id
].get_field_fns
[intop
->field_id
];
963 xtisa_errno
= xtensa_isa_wrong_slot
;
964 sprintf (xtisa_error_msg
,
965 "operand \"%s\" does not exist in slot %d of format \"%s\"",
966 intop
->name
, slot
, intisa
->formats
[fmt
].name
);
969 *valp
= (*get_fn
) (slotbuf
);
975 xtensa_operand_set_field (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
976 xtensa_format fmt
, int slot
,
977 xtensa_insnbuf slotbuf
, uint32 val
)
979 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
980 xtensa_operand_internal
*intop
;
982 xtensa_set_field_fn set_fn
;
984 intop
= get_operand (intisa
, opc
, opnd
);
985 if (!intop
) return -1;
987 CHECK_FORMAT (intisa
, fmt
, -1);
988 CHECK_SLOT (intisa
, fmt
, slot
, -1);
990 slot_id
= intisa
->formats
[fmt
].slot_id
[slot
];
991 if (intop
->field_id
== XTENSA_UNDEFINED
)
993 xtisa_errno
= xtensa_isa_no_field
;
994 strcpy (xtisa_error_msg
, "implicit operand has no field");
997 set_fn
= intisa
->slots
[slot_id
].set_field_fns
[intop
->field_id
];
1000 xtisa_errno
= xtensa_isa_wrong_slot
;
1001 sprintf (xtisa_error_msg
,
1002 "operand \"%s\" does not exist in slot %d of format \"%s\"",
1003 intop
->name
, slot
, intisa
->formats
[fmt
].name
);
1006 (*set_fn
) (slotbuf
, val
);
1012 xtensa_operand_encode (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1015 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1016 xtensa_operand_internal
*intop
;
1017 uint32 test_val
, orig_val
;
1019 intop
= get_operand (intisa
, opc
, opnd
);
1020 if (!intop
) return -1;
1024 /* This is a default operand for a field. How can we tell if the
1025 value fits in the field? Write the value into the field,
1026 read it back, and then make sure we get the same value. */
1028 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1029 static xtensa_insnbuf tmpbuf
= 0;
1034 tmpbuf
= xtensa_insnbuf_alloc (isa
);
1035 CHECK_ALLOC (tmpbuf
, -1);
1038 /* A default operand is always associated with a field,
1039 but check just to be sure.... */
1040 if (intop
->field_id
== XTENSA_UNDEFINED
)
1042 xtisa_errno
= xtensa_isa_internal_error
;
1043 strcpy (xtisa_error_msg
, "operand has no field");
1047 /* Find some slot that includes the field. */
1048 for (slot_id
= 0; slot_id
< intisa
->num_slots
; slot_id
++)
1050 xtensa_get_field_fn get_fn
=
1051 intisa
->slots
[slot_id
].get_field_fns
[intop
->field_id
];
1052 xtensa_set_field_fn set_fn
=
1053 intisa
->slots
[slot_id
].set_field_fns
[intop
->field_id
];
1055 if (get_fn
&& set_fn
)
1057 (*set_fn
) (tmpbuf
, *valp
);
1058 return ((*get_fn
) (tmpbuf
) != *valp
);
1062 /* Couldn't find any slot containing the field.... */
1063 xtisa_errno
= xtensa_isa_no_field
;
1064 strcpy (xtisa_error_msg
, "field does not exist in any slot");
1068 /* Encode the value. In some cases, the encoding function may detect
1069 errors, but most of the time the only way to determine if the value
1070 was successfully encoded is to decode it and check if it matches
1071 the original value. */
1073 if ((*intop
->encode
) (valp
) ||
1074 (test_val
= *valp
, (*intop
->decode
) (&test_val
)) ||
1075 test_val
!= orig_val
)
1077 xtisa_errno
= xtensa_isa_bad_value
;
1078 sprintf (xtisa_error_msg
, "cannot encode operand value 0x%08x", *valp
);
1087 xtensa_operand_decode (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1090 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1091 xtensa_operand_internal
*intop
;
1093 intop
= get_operand (intisa
, opc
, opnd
);
1094 if (!intop
) return -1;
1096 /* Use identity function for "default" operands. */
1100 if ((*intop
->decode
) (valp
))
1102 xtisa_errno
= xtensa_isa_bad_value
;
1103 sprintf (xtisa_error_msg
, "cannot decode operand value 0x%08x", *valp
);
1111 xtensa_operand_is_register (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1113 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1114 xtensa_operand_internal
*intop
;
1116 intop
= get_operand (intisa
, opc
, opnd
);
1117 if (!intop
) return XTENSA_UNDEFINED
;
1119 if ((intop
->flags
& XTENSA_OPERAND_IS_REGISTER
) != 0)
1126 xtensa_operand_regfile (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1128 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1129 xtensa_operand_internal
*intop
;
1131 intop
= get_operand (intisa
, opc
, opnd
);
1132 if (!intop
) return XTENSA_UNDEFINED
;
1134 return intop
->regfile
;
1139 xtensa_operand_num_regs (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1141 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1142 xtensa_operand_internal
*intop
;
1144 intop
= get_operand (intisa
, opc
, opnd
);
1145 if (!intop
) return XTENSA_UNDEFINED
;
1147 return intop
->num_regs
;
1152 xtensa_operand_is_known_reg (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1154 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1155 xtensa_operand_internal
*intop
;
1157 intop
= get_operand (intisa
, opc
, opnd
);
1158 if (!intop
) return XTENSA_UNDEFINED
;
1160 if ((intop
->flags
& XTENSA_OPERAND_IS_UNKNOWN
) == 0)
1167 xtensa_operand_is_PCrelative (xtensa_isa isa
, xtensa_opcode opc
, int opnd
)
1169 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1170 xtensa_operand_internal
*intop
;
1172 intop
= get_operand (intisa
, opc
, opnd
);
1173 if (!intop
) return XTENSA_UNDEFINED
;
1175 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) != 0)
1182 xtensa_operand_do_reloc (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1183 uint32
*valp
, uint32 pc
)
1185 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1186 xtensa_operand_internal
*intop
;
1188 intop
= get_operand (intisa
, opc
, opnd
);
1189 if (!intop
) return -1;
1191 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) == 0)
1194 if (!intop
->do_reloc
)
1196 xtisa_errno
= xtensa_isa_internal_error
;
1197 strcpy (xtisa_error_msg
, "operand missing do_reloc function");
1201 if ((*intop
->do_reloc
) (valp
, pc
))
1203 xtisa_errno
= xtensa_isa_bad_value
;
1204 sprintf (xtisa_error_msg
,
1205 "do_reloc failed for value 0x%08x at PC 0x%08x", *valp
, pc
);
1214 xtensa_operand_undo_reloc (xtensa_isa isa
, xtensa_opcode opc
, int opnd
,
1215 uint32
*valp
, uint32 pc
)
1217 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1218 xtensa_operand_internal
*intop
;
1220 intop
= get_operand (intisa
, opc
, opnd
);
1221 if (!intop
) return -1;
1223 if ((intop
->flags
& XTENSA_OPERAND_IS_PCRELATIVE
) == 0)
1226 if (!intop
->undo_reloc
)
1228 xtisa_errno
= xtensa_isa_internal_error
;
1229 strcpy (xtisa_error_msg
, "operand missing undo_reloc function");
1233 if ((*intop
->undo_reloc
) (valp
, pc
))
1235 xtisa_errno
= xtensa_isa_bad_value
;
1236 sprintf (xtisa_error_msg
,
1237 "undo_reloc failed for value 0x%08x at PC 0x%08x", *valp
, pc
);
1246 /* State Operands. */
1249 #define CHECK_STATE_OPERAND(INTISA,OPC,ICLASS,STOP,ERRVAL) \
1251 if ((STOP) < 0 || (STOP) >= (ICLASS)->num_stateOperands) \
1253 xtisa_errno = xtensa_isa_bad_operand; \
1254 sprintf (xtisa_error_msg, "invalid state operand number (%d); " \
1255 "opcode \"%s\" has %d state operands", (STOP), \
1256 (INTISA)->opcodes[(OPC)].name, (ICLASS)->num_stateOperands); \
1263 xtensa_stateOperand_state (xtensa_isa isa
, xtensa_opcode opc
, int stOp
)
1265 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1266 xtensa_iclass_internal
*iclass
;
1269 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
1270 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1271 iclass
= &intisa
->iclasses
[iclass_id
];
1272 CHECK_STATE_OPERAND (intisa
, opc
, iclass
, stOp
, XTENSA_UNDEFINED
);
1273 return iclass
->stateOperands
[stOp
].u
.state
;
1278 xtensa_stateOperand_inout (xtensa_isa isa
, xtensa_opcode opc
, int stOp
)
1280 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1281 xtensa_iclass_internal
*iclass
;
1284 CHECK_OPCODE (intisa
, opc
, 0);
1285 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1286 iclass
= &intisa
->iclasses
[iclass_id
];
1287 CHECK_STATE_OPERAND (intisa
, opc
, iclass
, stOp
, 0);
1288 return iclass
->stateOperands
[stOp
].inout
;
1292 /* Interface Operands. */
1295 #define CHECK_INTERFACE_OPERAND(INTISA,OPC,ICLASS,IFOP,ERRVAL) \
1297 if ((IFOP) < 0 || (IFOP) >= (ICLASS)->num_interfaceOperands) \
1299 xtisa_errno = xtensa_isa_bad_operand; \
1300 sprintf (xtisa_error_msg, "invalid interface operand number (%d); " \
1301 "opcode \"%s\" has %d interface operands", (IFOP), \
1302 (INTISA)->opcodes[(OPC)].name, \
1303 (ICLASS)->num_interfaceOperands); \
1310 xtensa_interfaceOperand_interface (xtensa_isa isa
, xtensa_opcode opc
,
1313 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1314 xtensa_iclass_internal
*iclass
;
1317 CHECK_OPCODE (intisa
, opc
, XTENSA_UNDEFINED
);
1318 iclass_id
= intisa
->opcodes
[opc
].iclass_id
;
1319 iclass
= &intisa
->iclasses
[iclass_id
];
1320 CHECK_INTERFACE_OPERAND (intisa
, opc
, iclass
, ifOp
, XTENSA_UNDEFINED
);
1321 return iclass
->interfaceOperands
[ifOp
];
1326 /* Register Files. */
1329 #define CHECK_REGFILE(INTISA,RF,ERRVAL) \
1331 if ((RF) < 0 || (RF) >= (INTISA)->num_regfiles) \
1333 xtisa_errno = xtensa_isa_bad_regfile; \
1334 strcpy (xtisa_error_msg, "invalid regfile specifier"); \
1341 xtensa_regfile_lookup (xtensa_isa isa
, const char *name
)
1343 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1346 if (!name
|| !*name
)
1348 xtisa_errno
= xtensa_isa_bad_regfile
;
1349 strcpy (xtisa_error_msg
, "invalid regfile name");
1350 return XTENSA_UNDEFINED
;
1353 /* The expected number of regfiles is small; use a linear search. */
1354 for (n
= 0; n
< intisa
->num_regfiles
; n
++)
1356 if (!strcmp (intisa
->regfiles
[n
].name
, name
))
1360 xtisa_errno
= xtensa_isa_bad_regfile
;
1361 sprintf (xtisa_error_msg
, "regfile \"%s\" not recognized", name
);
1362 return XTENSA_UNDEFINED
;
1367 xtensa_regfile_lookup_shortname (xtensa_isa isa
, const char *shortname
)
1369 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1372 if (!shortname
|| !*shortname
)
1374 xtisa_errno
= xtensa_isa_bad_regfile
;
1375 strcpy (xtisa_error_msg
, "invalid regfile shortname");
1376 return XTENSA_UNDEFINED
;
1379 /* The expected number of regfiles is small; use a linear search. */
1380 for (n
= 0; n
< intisa
->num_regfiles
; n
++)
1382 /* Ignore regfile views since they always have the same shortnames
1383 as their parents. */
1384 if (intisa
->regfiles
[n
].parent
!= n
)
1386 if (!strcmp (intisa
->regfiles
[n
].shortname
, shortname
))
1390 xtisa_errno
= xtensa_isa_bad_regfile
;
1391 sprintf (xtisa_error_msg
, "regfile shortname \"%s\" not recognized",
1393 return XTENSA_UNDEFINED
;
1398 xtensa_regfile_name (xtensa_isa isa
, xtensa_regfile rf
)
1400 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1401 CHECK_REGFILE (intisa
, rf
, NULL
);
1402 return intisa
->regfiles
[rf
].name
;
1407 xtensa_regfile_shortname (xtensa_isa isa
, xtensa_regfile rf
)
1409 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1410 CHECK_REGFILE (intisa
, rf
, NULL
);
1411 return intisa
->regfiles
[rf
].shortname
;
1416 xtensa_regfile_view_parent (xtensa_isa isa
, xtensa_regfile rf
)
1418 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1419 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1420 return intisa
->regfiles
[rf
].parent
;
1425 xtensa_regfile_num_bits (xtensa_isa isa
, xtensa_regfile rf
)
1427 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1428 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1429 return intisa
->regfiles
[rf
].num_bits
;
1434 xtensa_regfile_num_entries (xtensa_isa isa
, xtensa_regfile rf
)
1436 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1437 CHECK_REGFILE (intisa
, rf
, XTENSA_UNDEFINED
);
1438 return intisa
->regfiles
[rf
].num_entries
;
1442 /* Processor States. */
1445 #define CHECK_STATE(INTISA,ST,ERRVAL) \
1447 if ((ST) < 0 || (ST) >= (INTISA)->num_states) \
1449 xtisa_errno = xtensa_isa_bad_state; \
1450 strcpy (xtisa_error_msg, "invalid state specifier"); \
1457 xtensa_state_lookup (xtensa_isa isa
, const char *name
)
1459 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1460 xtensa_lookup_entry entry
, *result
;
1462 if (!name
|| !*name
)
1464 xtisa_errno
= xtensa_isa_bad_state
;
1465 strcpy (xtisa_error_msg
, "invalid state name");
1466 return XTENSA_UNDEFINED
;
1470 result
= bsearch (&entry
, intisa
->state_lookup_table
, intisa
->num_states
,
1471 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
1475 xtisa_errno
= xtensa_isa_bad_state
;
1476 sprintf (xtisa_error_msg
, "state \"%s\" not recognized", name
);
1477 return XTENSA_UNDEFINED
;
1480 return result
->u
.state
;
1485 xtensa_state_name (xtensa_isa isa
, xtensa_state st
)
1487 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1488 CHECK_STATE (intisa
, st
, NULL
);
1489 return intisa
->states
[st
].name
;
1494 xtensa_state_num_bits (xtensa_isa isa
, xtensa_state st
)
1496 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1497 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1498 return intisa
->states
[st
].num_bits
;
1503 xtensa_state_is_exported (xtensa_isa isa
, xtensa_state st
)
1505 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1506 CHECK_STATE (intisa
, st
, XTENSA_UNDEFINED
);
1507 if ((intisa
->states
[st
].flags
& XTENSA_STATE_IS_EXPORTED
) != 0)
1516 #define CHECK_SYSREG(INTISA,SYSREG,ERRVAL) \
1518 if ((SYSREG) < 0 || (SYSREG) >= (INTISA)->num_sysregs) \
1520 xtisa_errno = xtensa_isa_bad_sysreg; \
1521 strcpy (xtisa_error_msg, "invalid sysreg specifier"); \
1528 xtensa_sysreg_lookup (xtensa_isa isa
, int num
, int is_user
)
1530 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1535 if (num
< 0 || num
> intisa
->max_sysreg_num
[is_user
]
1536 || intisa
->sysreg_table
[is_user
][num
] == XTENSA_UNDEFINED
)
1538 xtisa_errno
= xtensa_isa_bad_sysreg
;
1539 strcpy (xtisa_error_msg
, "sysreg not recognized");
1540 return XTENSA_UNDEFINED
;
1543 return intisa
->sysreg_table
[is_user
][num
];
1548 xtensa_sysreg_lookup_name (xtensa_isa isa
, const char *name
)
1550 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1551 xtensa_lookup_entry entry
, *result
;
1553 if (!name
|| !*name
)
1555 xtisa_errno
= xtensa_isa_bad_sysreg
;
1556 strcpy (xtisa_error_msg
, "invalid sysreg name");
1557 return XTENSA_UNDEFINED
;
1561 result
= bsearch (&entry
, intisa
->sysreg_lookup_table
, intisa
->num_sysregs
,
1562 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
1566 xtisa_errno
= xtensa_isa_bad_sysreg
;
1567 sprintf (xtisa_error_msg
, "sysreg \"%s\" not recognized", name
);
1568 return XTENSA_UNDEFINED
;
1571 return result
->u
.sysreg
;
1576 xtensa_sysreg_name (xtensa_isa isa
, xtensa_sysreg sysreg
)
1578 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1579 CHECK_SYSREG (intisa
, sysreg
, NULL
);
1580 return intisa
->sysregs
[sysreg
].name
;
1585 xtensa_sysreg_number (xtensa_isa isa
, xtensa_sysreg sysreg
)
1587 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1588 CHECK_SYSREG (intisa
, sysreg
, XTENSA_UNDEFINED
);
1589 return intisa
->sysregs
[sysreg
].number
;
1594 xtensa_sysreg_is_user (xtensa_isa isa
, xtensa_sysreg sysreg
)
1596 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1597 CHECK_SYSREG (intisa
, sysreg
, XTENSA_UNDEFINED
);
1598 if (intisa
->sysregs
[sysreg
].is_user
)
1607 #define CHECK_INTERFACE(INTISA,INTF,ERRVAL) \
1609 if ((INTF) < 0 || (INTF) >= (INTISA)->num_interfaces) \
1611 xtisa_errno = xtensa_isa_bad_interface; \
1612 strcpy (xtisa_error_msg, "invalid interface specifier"); \
1619 xtensa_interface_lookup (xtensa_isa isa
, const char *ifname
)
1621 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1622 xtensa_lookup_entry entry
, *result
;
1624 if (!ifname
|| !*ifname
)
1626 xtisa_errno
= xtensa_isa_bad_interface
;
1627 strcpy (xtisa_error_msg
, "invalid interface name");
1628 return XTENSA_UNDEFINED
;
1632 result
= bsearch (&entry
, intisa
->interface_lookup_table
,
1633 intisa
->num_interfaces
,
1634 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
1638 xtisa_errno
= xtensa_isa_bad_interface
;
1639 sprintf (xtisa_error_msg
, "interface \"%s\" not recognized", ifname
);
1640 return XTENSA_UNDEFINED
;
1643 return result
->u
.intf
;
1648 xtensa_interface_name (xtensa_isa isa
, xtensa_interface intf
)
1650 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1651 CHECK_INTERFACE (intisa
, intf
, NULL
);
1652 return intisa
->interfaces
[intf
].name
;
1657 xtensa_interface_num_bits (xtensa_isa isa
, xtensa_interface intf
)
1659 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1660 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1661 return intisa
->interfaces
[intf
].num_bits
;
1666 xtensa_interface_inout (xtensa_isa isa
, xtensa_interface intf
)
1668 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1669 CHECK_INTERFACE (intisa
, intf
, 0);
1670 return intisa
->interfaces
[intf
].inout
;
1675 xtensa_interface_has_side_effect (xtensa_isa isa
, xtensa_interface intf
)
1677 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1678 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1679 if ((intisa
->interfaces
[intf
].flags
& XTENSA_INTERFACE_HAS_SIDE_EFFECT
) != 0)
1686 xtensa_interface_class_id (xtensa_isa isa
, xtensa_interface intf
)
1688 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1689 CHECK_INTERFACE (intisa
, intf
, XTENSA_UNDEFINED
);
1690 return intisa
->interfaces
[intf
].class_id
;
1694 /* Functional Units. */
1697 #define CHECK_FUNCUNIT(INTISA,FUN,ERRVAL) \
1699 if ((FUN) < 0 || (FUN) >= (INTISA)->num_funcUnits) \
1701 xtisa_errno = xtensa_isa_bad_funcUnit; \
1702 strcpy (xtisa_error_msg, "invalid functional unit specifier"); \
1709 xtensa_funcUnit_lookup (xtensa_isa isa
, const char *fname
)
1711 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1712 xtensa_lookup_entry entry
, *result
;
1714 if (!fname
|| !*fname
)
1716 xtisa_errno
= xtensa_isa_bad_funcUnit
;
1717 strcpy (xtisa_error_msg
, "invalid functional unit name");
1718 return XTENSA_UNDEFINED
;
1722 result
= bsearch (&entry
, intisa
->funcUnit_lookup_table
,
1723 intisa
->num_funcUnits
,
1724 sizeof (xtensa_lookup_entry
), xtensa_isa_name_compare
);
1728 xtisa_errno
= xtensa_isa_bad_funcUnit
;
1729 sprintf (xtisa_error_msg
,
1730 "functional unit \"%s\" not recognized", fname
);
1731 return XTENSA_UNDEFINED
;
1734 return result
->u
.fun
;
1739 xtensa_funcUnit_name (xtensa_isa isa
, xtensa_funcUnit fun
)
1741 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1742 CHECK_FUNCUNIT (intisa
, fun
, NULL
);
1743 return intisa
->funcUnits
[fun
].name
;
1748 xtensa_funcUnit_num_copies (xtensa_isa isa
, xtensa_funcUnit fun
)
1750 xtensa_isa_internal
*intisa
= (xtensa_isa_internal
*) isa
;
1751 CHECK_FUNCUNIT (intisa
, fun
, XTENSA_UNDEFINED
);
1752 return intisa
->funcUnits
[fun
].num_copies
;