xref: /netbsd-src/external/gpl3/gdb/dist/include/xtensa-isa.h (revision e663ba6e3a60083e70de702e9d54bf486a57b6a7)
198b9484cSchristos /* Interface definition for configurable Xtensa ISA support.
2*e663ba6eSchristos    Copyright (C) 2003-2024 Free Software Foundation, Inc.
398b9484cSchristos 
498b9484cSchristos    This file is part of BFD, the Binary File Descriptor library.
598b9484cSchristos 
698b9484cSchristos    This program is free software; you can redistribute it and/or modify
798b9484cSchristos    it under the terms of the GNU General Public License as published by
898b9484cSchristos    the Free Software Foundation; either version 3 of the License, or
998b9484cSchristos    (at your option) any later version.
1098b9484cSchristos 
1198b9484cSchristos    This program is distributed in the hope that it will be useful,
1298b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1398b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1498b9484cSchristos    GNU General Public License for more details.
1598b9484cSchristos 
1698b9484cSchristos    You should have received a copy of the GNU General Public License
1798b9484cSchristos    along with this program; if not, write to the Free Software
1898b9484cSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
1998b9484cSchristos    USA.  */
2098b9484cSchristos 
2198b9484cSchristos #ifndef XTENSA_LIBISA_H
2298b9484cSchristos #define XTENSA_LIBISA_H
2398b9484cSchristos 
2498b9484cSchristos #ifdef __cplusplus
2598b9484cSchristos extern "C" {
2698b9484cSchristos #endif
2798b9484cSchristos 
2898b9484cSchristos /* Version number: This is intended to help support code that works with
2998b9484cSchristos    versions of this library from multiple Xtensa releases.  */
3098b9484cSchristos 
3198b9484cSchristos #define XTENSA_ISA_VERSION 7000
3298b9484cSchristos 
3398b9484cSchristos #ifndef uint32
3498b9484cSchristos #define uint32 unsigned int
3598b9484cSchristos #endif
3698b9484cSchristos 
3798b9484cSchristos /* This file defines the interface to the Xtensa ISA library.  This
3898b9484cSchristos    library contains most of the ISA-specific information for a
3998b9484cSchristos    particular Xtensa processor.  For example, the set of valid
4098b9484cSchristos    instructions, their opcode encodings and operand fields are all
4198b9484cSchristos    included here.
4298b9484cSchristos 
4398b9484cSchristos    This interface basically defines a number of abstract data types.
4498b9484cSchristos 
4598b9484cSchristos    . an instruction buffer - for holding the raw instruction bits
4698b9484cSchristos    . ISA info - information about the ISA as a whole
4798b9484cSchristos    . instruction formats - instruction size and slot structure
4898b9484cSchristos    . opcodes - information about individual instructions
4998b9484cSchristos    . operands - information about register and immediate instruction operands
5098b9484cSchristos    . stateOperands - information about processor state instruction operands
5198b9484cSchristos    . interfaceOperands - information about interface instruction operands
5298b9484cSchristos    . register files - register file information
5398b9484cSchristos    . processor states - internal processor state information
5498b9484cSchristos    . system registers - "special registers" and "user registers"
5598b9484cSchristos    . interfaces - TIE interfaces that are external to the processor
5698b9484cSchristos    . functional units - TIE shared functions
5798b9484cSchristos 
5898b9484cSchristos    The interface defines a set of functions to access each data type.
5998b9484cSchristos    With the exception of the instruction buffer, the internal
6098b9484cSchristos    representations of the data structures are hidden.  All accesses must
6198b9484cSchristos    be made through the functions defined here.  */
6298b9484cSchristos 
6398b9484cSchristos typedef struct xtensa_isa_opaque { int unused; } *xtensa_isa;
6498b9484cSchristos 
6598b9484cSchristos 
6698b9484cSchristos /* Most of the Xtensa ISA entities (e.g., opcodes, regfiles, etc.) are
6798b9484cSchristos    represented here using sequential integers beginning with 0.  The
6898b9484cSchristos    specific values are only fixed for a particular instantiation of an
6998b9484cSchristos    xtensa_isa structure, so these values should only be used
7098b9484cSchristos    internally.  */
7198b9484cSchristos 
7298b9484cSchristos typedef int xtensa_opcode;
7398b9484cSchristos typedef int xtensa_format;
7498b9484cSchristos typedef int xtensa_regfile;
7598b9484cSchristos typedef int xtensa_state;
7698b9484cSchristos typedef int xtensa_sysreg;
7798b9484cSchristos typedef int xtensa_interface;
7898b9484cSchristos typedef int xtensa_funcUnit;
7998b9484cSchristos 
8098b9484cSchristos 
8198b9484cSchristos /* Define a unique value for undefined items.  */
8298b9484cSchristos 
8398b9484cSchristos #define XTENSA_UNDEFINED -1
8498b9484cSchristos 
8598b9484cSchristos 
8698b9484cSchristos /* Overview of using this interface to decode/encode instructions:
8798b9484cSchristos 
8898b9484cSchristos    Each Xtensa instruction is associated with a particular instruction
8998b9484cSchristos    format, where the format defines a fixed number of slots for
9098b9484cSchristos    operations.  The formats for the core Xtensa ISA have only one slot,
9198b9484cSchristos    but FLIX instructions may have multiple slots.  Within each slot,
9298b9484cSchristos    there is a single opcode and some number of associated operands.
9398b9484cSchristos 
9498b9484cSchristos    The encoding and decoding functions operate on instruction buffers,
9598b9484cSchristos    not on the raw bytes of the instructions.  The same instruction
9698b9484cSchristos    buffer data structure is used for both entire instructions and
9798b9484cSchristos    individual slots in those instructions -- the contents of a slot need
9898b9484cSchristos    to be extracted from or inserted into the buffer for the instruction
9998b9484cSchristos    as a whole.
10098b9484cSchristos 
10198b9484cSchristos    Decoding an instruction involves first finding the format, which
10298b9484cSchristos    identifies the number of slots, and then decoding each slot
10398b9484cSchristos    separately.  A slot is decoded by finding the opcode and then using
10498b9484cSchristos    the opcode to determine how many operands there are.  For example:
10598b9484cSchristos 
10698b9484cSchristos    xtensa_insnbuf_from_chars
10798b9484cSchristos    xtensa_format_decode
10898b9484cSchristos    for each slot {
10998b9484cSchristos      xtensa_format_get_slot
11098b9484cSchristos      xtensa_opcode_decode
11198b9484cSchristos      for each operand {
11298b9484cSchristos        xtensa_operand_get_field
11398b9484cSchristos        xtensa_operand_decode
11498b9484cSchristos      }
11598b9484cSchristos    }
11698b9484cSchristos 
11798b9484cSchristos    Encoding an instruction is roughly the same procedure in reverse:
11898b9484cSchristos 
11998b9484cSchristos    xtensa_format_encode
12098b9484cSchristos    for each slot {
12198b9484cSchristos      xtensa_opcode_encode
12298b9484cSchristos      for each operand {
12398b9484cSchristos        xtensa_operand_encode
12498b9484cSchristos        xtensa_operand_set_field
12598b9484cSchristos      }
12698b9484cSchristos      xtensa_format_set_slot
12798b9484cSchristos    }
12898b9484cSchristos    xtensa_insnbuf_to_chars
12998b9484cSchristos */
13098b9484cSchristos 
13198b9484cSchristos 
13298b9484cSchristos /* Error handling.  */
13398b9484cSchristos 
13498b9484cSchristos /* Error codes.  The code for the most recent error condition can be
13598b9484cSchristos    retrieved with the "errno" function.  For any result other than
13698b9484cSchristos    xtensa_isa_ok, an error message containing additional information
13798b9484cSchristos    about the problem can be retrieved using the "error_msg" function.
13898b9484cSchristos    The error messages are stored in an internal buffer, which should
13998b9484cSchristos    not be freed and may be overwritten by subsequent operations.  */
14098b9484cSchristos 
14198b9484cSchristos typedef enum xtensa_isa_status_enum
14298b9484cSchristos {
14398b9484cSchristos   xtensa_isa_ok = 0,
14498b9484cSchristos   xtensa_isa_bad_format,
14598b9484cSchristos   xtensa_isa_bad_slot,
14698b9484cSchristos   xtensa_isa_bad_opcode,
14798b9484cSchristos   xtensa_isa_bad_operand,
14898b9484cSchristos   xtensa_isa_bad_field,
14998b9484cSchristos   xtensa_isa_bad_iclass,
15098b9484cSchristos   xtensa_isa_bad_regfile,
15198b9484cSchristos   xtensa_isa_bad_sysreg,
15298b9484cSchristos   xtensa_isa_bad_state,
15398b9484cSchristos   xtensa_isa_bad_interface,
15498b9484cSchristos   xtensa_isa_bad_funcUnit,
15598b9484cSchristos   xtensa_isa_wrong_slot,
15698b9484cSchristos   xtensa_isa_no_field,
15798b9484cSchristos   xtensa_isa_out_of_memory,
15898b9484cSchristos   xtensa_isa_buffer_overflow,
15998b9484cSchristos   xtensa_isa_internal_error,
16098b9484cSchristos   xtensa_isa_bad_value
16198b9484cSchristos } xtensa_isa_status;
16298b9484cSchristos 
16398b9484cSchristos extern xtensa_isa_status
16498b9484cSchristos xtensa_isa_errno (xtensa_isa isa);
16598b9484cSchristos 
16698b9484cSchristos extern char *
16798b9484cSchristos xtensa_isa_error_msg (xtensa_isa isa);
16898b9484cSchristos 
16998b9484cSchristos 
17098b9484cSchristos 
17198b9484cSchristos /* Instruction buffers.  */
17298b9484cSchristos 
17398b9484cSchristos typedef uint32 xtensa_insnbuf_word;
17498b9484cSchristos typedef xtensa_insnbuf_word *xtensa_insnbuf;
17598b9484cSchristos 
17698b9484cSchristos 
17798b9484cSchristos /* Get the size in "insnbuf_words" of the xtensa_insnbuf array.  */
17898b9484cSchristos 
17998b9484cSchristos extern int
18098b9484cSchristos xtensa_insnbuf_size (xtensa_isa isa);
18198b9484cSchristos 
18298b9484cSchristos 
18398b9484cSchristos /* Allocate an xtensa_insnbuf of the right size.  */
18498b9484cSchristos 
18598b9484cSchristos extern xtensa_insnbuf
18698b9484cSchristos xtensa_insnbuf_alloc (xtensa_isa isa);
18798b9484cSchristos 
18898b9484cSchristos 
18998b9484cSchristos /* Release an xtensa_insnbuf.  */
19098b9484cSchristos 
19198b9484cSchristos extern void
19298b9484cSchristos xtensa_insnbuf_free (xtensa_isa isa, xtensa_insnbuf buf);
19398b9484cSchristos 
19498b9484cSchristos 
19598b9484cSchristos /* Conversion between raw memory (char arrays) and our internal
19698b9484cSchristos    instruction representation.  This is complicated by the Xtensa ISA's
19798b9484cSchristos    variable instruction lengths.  When converting to chars, the buffer
19898b9484cSchristos    must contain a valid instruction so we know how many bytes to copy;
19998b9484cSchristos    thus, the "to_chars" function returns the number of bytes copied or
20098b9484cSchristos    XTENSA_UNDEFINED on error.  The "from_chars" function first reads the
20198b9484cSchristos    minimal number of bytes required to decode the instruction length and
20298b9484cSchristos    then proceeds to copy the entire instruction into the buffer; if the
20398b9484cSchristos    memory does not contain a valid instruction, it copies the maximum
20498b9484cSchristos    number of bytes required for the longest Xtensa instruction.  The
20598b9484cSchristos    "num_chars" argument may be used to limit the number of bytes that
20698b9484cSchristos    can be read or written.  Otherwise, if "num_chars" is zero, the
20798b9484cSchristos    functions may read or write past the end of the code.  */
20898b9484cSchristos 
20998b9484cSchristos extern int
21098b9484cSchristos xtensa_insnbuf_to_chars (xtensa_isa isa, const xtensa_insnbuf insn,
21198b9484cSchristos 			 unsigned char *cp, int num_chars);
21298b9484cSchristos 
21398b9484cSchristos extern void
21498b9484cSchristos xtensa_insnbuf_from_chars (xtensa_isa isa, xtensa_insnbuf insn,
21598b9484cSchristos 			   const unsigned char *cp, int num_chars);
21698b9484cSchristos 
21798b9484cSchristos 
21898b9484cSchristos 
21998b9484cSchristos /* ISA information.  */
22098b9484cSchristos 
22198b9484cSchristos /* Initialize the ISA information.  */
22298b9484cSchristos 
22398b9484cSchristos extern xtensa_isa
22498b9484cSchristos xtensa_isa_init (xtensa_isa_status *errno_p, char **error_msg_p);
22598b9484cSchristos 
22698b9484cSchristos 
22798b9484cSchristos /* Deallocate an xtensa_isa structure.  */
22898b9484cSchristos 
22998b9484cSchristos extern void
23098b9484cSchristos xtensa_isa_free (xtensa_isa isa);
23198b9484cSchristos 
23298b9484cSchristos 
23398b9484cSchristos /* Get the maximum instruction size in bytes.  */
23498b9484cSchristos 
23598b9484cSchristos extern int
23698b9484cSchristos xtensa_isa_maxlength (xtensa_isa isa);
23798b9484cSchristos 
23898b9484cSchristos 
23998b9484cSchristos /* Decode the length in bytes of an instruction in raw memory (not an
24098b9484cSchristos    insnbuf).  This function reads only the minimal number of bytes
24198b9484cSchristos    required to decode the instruction length.  Returns
24298b9484cSchristos    XTENSA_UNDEFINED on error.  */
24398b9484cSchristos 
24498b9484cSchristos extern int
24598b9484cSchristos xtensa_isa_length_from_chars (xtensa_isa isa, const unsigned char *cp);
24698b9484cSchristos 
24798b9484cSchristos 
24898b9484cSchristos /* Get the number of stages in the processor's pipeline.  The pipeline
24998b9484cSchristos    stage values returned by other functions in this library will range
25098b9484cSchristos    from 0 to N-1, where N is the value returned by this function.
25198b9484cSchristos    Note that the stage numbers used here may not correspond to the
25298b9484cSchristos    actual processor hardware, e.g., the hardware may have additional
25398b9484cSchristos    stages before stage 0.  Returns XTENSA_UNDEFINED on error.  */
25498b9484cSchristos 
25598b9484cSchristos extern int
25698b9484cSchristos xtensa_isa_num_pipe_stages (xtensa_isa isa);
25798b9484cSchristos 
25898b9484cSchristos 
25998b9484cSchristos /* Get the number of various entities that are defined for this processor.  */
26098b9484cSchristos 
26198b9484cSchristos extern int
26298b9484cSchristos xtensa_isa_num_formats (xtensa_isa isa);
26398b9484cSchristos 
26498b9484cSchristos extern int
26598b9484cSchristos xtensa_isa_num_opcodes (xtensa_isa isa);
26698b9484cSchristos 
26798b9484cSchristos extern int
26898b9484cSchristos xtensa_isa_num_regfiles (xtensa_isa isa);
26998b9484cSchristos 
27098b9484cSchristos extern int
27198b9484cSchristos xtensa_isa_num_states (xtensa_isa isa);
27298b9484cSchristos 
27398b9484cSchristos extern int
27498b9484cSchristos xtensa_isa_num_sysregs (xtensa_isa isa);
27598b9484cSchristos 
27698b9484cSchristos extern int
27798b9484cSchristos xtensa_isa_num_interfaces (xtensa_isa isa);
27898b9484cSchristos 
27998b9484cSchristos extern int
28098b9484cSchristos xtensa_isa_num_funcUnits (xtensa_isa isa);
28198b9484cSchristos 
28298b9484cSchristos 
28398b9484cSchristos 
28498b9484cSchristos /* Instruction formats.  */
28598b9484cSchristos 
28698b9484cSchristos /* Get the name of a format.  Returns null on error.  */
28798b9484cSchristos 
28898b9484cSchristos extern const char *
28998b9484cSchristos xtensa_format_name (xtensa_isa isa, xtensa_format fmt);
29098b9484cSchristos 
29198b9484cSchristos 
29298b9484cSchristos /* Given a format name, return the format number.  Returns
29398b9484cSchristos    XTENSA_UNDEFINED if the name is not a valid format.  */
29498b9484cSchristos 
29598b9484cSchristos extern xtensa_format
29698b9484cSchristos xtensa_format_lookup (xtensa_isa isa, const char *fmtname);
29798b9484cSchristos 
29898b9484cSchristos 
29998b9484cSchristos /* Decode the instruction format from a binary instruction buffer.
30098b9484cSchristos    Returns XTENSA_UNDEFINED if the format is not recognized.  */
30198b9484cSchristos 
30298b9484cSchristos extern xtensa_format
30398b9484cSchristos xtensa_format_decode (xtensa_isa isa, const xtensa_insnbuf insn);
30498b9484cSchristos 
30598b9484cSchristos 
30698b9484cSchristos /* Set the instruction format field(s) in a binary instruction buffer.
30798b9484cSchristos    All the other fields are set to zero.  Returns non-zero on error.  */
30898b9484cSchristos 
30998b9484cSchristos extern int
31098b9484cSchristos xtensa_format_encode (xtensa_isa isa, xtensa_format fmt, xtensa_insnbuf insn);
31198b9484cSchristos 
31298b9484cSchristos 
31398b9484cSchristos /* Find the length (in bytes) of an instruction.  Returns
31498b9484cSchristos    XTENSA_UNDEFINED on error.  */
31598b9484cSchristos 
31698b9484cSchristos extern int
31798b9484cSchristos xtensa_format_length (xtensa_isa isa, xtensa_format fmt);
31898b9484cSchristos 
31998b9484cSchristos 
32098b9484cSchristos /* Get the number of slots in an instruction.  Returns XTENSA_UNDEFINED
32198b9484cSchristos    on error.  */
32298b9484cSchristos 
32398b9484cSchristos extern int
32498b9484cSchristos xtensa_format_num_slots (xtensa_isa isa, xtensa_format fmt);
32598b9484cSchristos 
32698b9484cSchristos 
32798b9484cSchristos /* Get the opcode for a no-op in a particular slot.
32898b9484cSchristos    Returns XTENSA_UNDEFINED on error.  */
32998b9484cSchristos 
33098b9484cSchristos extern xtensa_opcode
33198b9484cSchristos xtensa_format_slot_nop_opcode (xtensa_isa isa, xtensa_format fmt, int slot);
33298b9484cSchristos 
33398b9484cSchristos 
33498b9484cSchristos /* Get the bits for a specified slot out of an insnbuf for the
33598b9484cSchristos    instruction as a whole and put them into an insnbuf for that one
33698b9484cSchristos    slot, and do the opposite to set a slot.  Return non-zero on error.  */
33798b9484cSchristos 
33898b9484cSchristos extern int
33998b9484cSchristos xtensa_format_get_slot (xtensa_isa isa, xtensa_format fmt, int slot,
34098b9484cSchristos 			const xtensa_insnbuf insn, xtensa_insnbuf slotbuf);
34198b9484cSchristos 
34298b9484cSchristos extern int
34398b9484cSchristos xtensa_format_set_slot (xtensa_isa isa, xtensa_format fmt, int slot,
34498b9484cSchristos 			xtensa_insnbuf insn, const xtensa_insnbuf slotbuf);
34598b9484cSchristos 
34698b9484cSchristos 
34798b9484cSchristos 
34898b9484cSchristos /* Opcode information.  */
34998b9484cSchristos 
35098b9484cSchristos /* Translate a mnemonic name to an opcode.  Returns XTENSA_UNDEFINED if
35198b9484cSchristos    the name is not a valid opcode mnemonic.  */
35298b9484cSchristos 
35398b9484cSchristos extern xtensa_opcode
35498b9484cSchristos xtensa_opcode_lookup (xtensa_isa isa, const char *opname);
35598b9484cSchristos 
35698b9484cSchristos 
35798b9484cSchristos /* Decode the opcode for one instruction slot from a binary instruction
35898b9484cSchristos    buffer.  Returns the opcode or XTENSA_UNDEFINED if the opcode is
35998b9484cSchristos    illegal.  */
36098b9484cSchristos 
36198b9484cSchristos extern xtensa_opcode
36298b9484cSchristos xtensa_opcode_decode (xtensa_isa isa, xtensa_format fmt, int slot,
36398b9484cSchristos 		      const xtensa_insnbuf slotbuf);
36498b9484cSchristos 
36598b9484cSchristos 
36698b9484cSchristos /* Set the opcode field(s) for an instruction slot.  All other fields
36798b9484cSchristos    in the slot are set to zero.  Returns non-zero if the opcode cannot
36898b9484cSchristos    be encoded.  */
36998b9484cSchristos 
37098b9484cSchristos extern int
37198b9484cSchristos xtensa_opcode_encode (xtensa_isa isa, xtensa_format fmt, int slot,
37298b9484cSchristos 		      xtensa_insnbuf slotbuf, xtensa_opcode opc);
37398b9484cSchristos 
37498b9484cSchristos 
37598b9484cSchristos /* Get the mnemonic name for an opcode.  Returns null on error.  */
37698b9484cSchristos 
37798b9484cSchristos extern const char *
37898b9484cSchristos xtensa_opcode_name (xtensa_isa isa, xtensa_opcode opc);
37998b9484cSchristos 
38098b9484cSchristos 
38198b9484cSchristos /* Check various properties of opcodes.  These functions return 0 if
38298b9484cSchristos    the condition is false, 1 if the condition is true, and
38398b9484cSchristos    XTENSA_UNDEFINED on error.  The instructions are classified as
38498b9484cSchristos    follows:
38598b9484cSchristos 
38698b9484cSchristos    branch: conditional branch; may fall through to next instruction (B*)
38798b9484cSchristos    jump: unconditional branch (J, JX, RET*, RF*)
38898b9484cSchristos    loop: zero-overhead loop (LOOP*)
38998b9484cSchristos    call: unconditional call; control returns to next instruction (CALL*)
39098b9484cSchristos 
39198b9484cSchristos    For the opcodes that affect control flow in some way, the branch
39298b9484cSchristos    target may be specified by an immediate operand or it may be an
39398b9484cSchristos    address stored in a register.  You can distinguish these by
39498b9484cSchristos    checking if the instruction has a PC-relative immediate
39598b9484cSchristos    operand.  */
39698b9484cSchristos 
39798b9484cSchristos extern int
39898b9484cSchristos xtensa_opcode_is_branch (xtensa_isa isa, xtensa_opcode opc);
39998b9484cSchristos 
40098b9484cSchristos extern int
40198b9484cSchristos xtensa_opcode_is_jump (xtensa_isa isa, xtensa_opcode opc);
40298b9484cSchristos 
40398b9484cSchristos extern int
40498b9484cSchristos xtensa_opcode_is_loop (xtensa_isa isa, xtensa_opcode opc);
40598b9484cSchristos 
40698b9484cSchristos extern int
40798b9484cSchristos xtensa_opcode_is_call (xtensa_isa isa, xtensa_opcode opc);
40898b9484cSchristos 
40998b9484cSchristos 
41098b9484cSchristos /* Find the number of ordinary operands, state operands, and interface
41198b9484cSchristos    operands for an instruction.  These return XTENSA_UNDEFINED on
41298b9484cSchristos    error.  */
41398b9484cSchristos 
41498b9484cSchristos extern int
41598b9484cSchristos xtensa_opcode_num_operands (xtensa_isa isa, xtensa_opcode opc);
41698b9484cSchristos 
41798b9484cSchristos extern int
41898b9484cSchristos xtensa_opcode_num_stateOperands (xtensa_isa isa, xtensa_opcode opc);
41998b9484cSchristos 
42098b9484cSchristos extern int
42198b9484cSchristos xtensa_opcode_num_interfaceOperands (xtensa_isa isa, xtensa_opcode opc);
42298b9484cSchristos 
42398b9484cSchristos 
42498b9484cSchristos /* Get functional unit usage requirements for an opcode.  Each "use"
42598b9484cSchristos    is identified by a <functional unit, pipeline stage> pair.  The
42698b9484cSchristos    "num_funcUnit_uses" function returns the number of these "uses" or
42798b9484cSchristos    XTENSA_UNDEFINED on error.  The "funcUnit_use" function returns
42898b9484cSchristos    a pointer to a "use" pair or null on error.  */
42998b9484cSchristos 
43098b9484cSchristos typedef struct xtensa_funcUnit_use_struct
43198b9484cSchristos {
43298b9484cSchristos   xtensa_funcUnit unit;
43398b9484cSchristos   int stage;
43498b9484cSchristos } xtensa_funcUnit_use;
43598b9484cSchristos 
43698b9484cSchristos extern int
43798b9484cSchristos xtensa_opcode_num_funcUnit_uses (xtensa_isa isa, xtensa_opcode opc);
43898b9484cSchristos 
43998b9484cSchristos extern xtensa_funcUnit_use *
44098b9484cSchristos xtensa_opcode_funcUnit_use (xtensa_isa isa, xtensa_opcode opc, int u);
44198b9484cSchristos 
44298b9484cSchristos 
44398b9484cSchristos 
44498b9484cSchristos /* Operand information.  */
44598b9484cSchristos 
44698b9484cSchristos /* Get the name of an operand.  Returns null on error.  */
44798b9484cSchristos 
44898b9484cSchristos extern const char *
44998b9484cSchristos xtensa_operand_name (xtensa_isa isa, xtensa_opcode opc, int opnd);
45098b9484cSchristos 
45198b9484cSchristos 
45298b9484cSchristos /* Some operands are "invisible", i.e., not explicitly specified in
45398b9484cSchristos    assembly language.  When assembling an instruction, you need not set
45498b9484cSchristos    the values of invisible operands, since they are either hardwired or
45598b9484cSchristos    derived from other field values.  The values of invisible operands
45698b9484cSchristos    can be examined in the same way as other operands, but remember that
45798b9484cSchristos    an invisible operand may get its value from another visible one, so
45898b9484cSchristos    the entire instruction must be available before examining the
45998b9484cSchristos    invisible operand values.  This function returns 1 if an operand is
46098b9484cSchristos    visible, 0 if it is invisible, or XTENSA_UNDEFINED on error.  Note
46198b9484cSchristos    that whether an operand is visible is orthogonal to whether it is
46298b9484cSchristos    "implicit", i.e., whether it is encoded in a field in the
46398b9484cSchristos    instruction.  */
46498b9484cSchristos 
46598b9484cSchristos extern int
46698b9484cSchristos xtensa_operand_is_visible (xtensa_isa isa, xtensa_opcode opc, int opnd);
46798b9484cSchristos 
46898b9484cSchristos 
46998b9484cSchristos /* Check if an operand is an input ('i'), output ('o'), or inout ('m')
47098b9484cSchristos    operand.  Note: The output operand of a conditional assignment
47198b9484cSchristos    (e.g., movnez) appears here as an inout ('m') even if it is declared
47298b9484cSchristos    in the TIE code as an output ('o'); this allows the compiler to
47398b9484cSchristos    properly handle register allocation for conditional assignments.
47498b9484cSchristos    Returns 0 on error.  */
47598b9484cSchristos 
47698b9484cSchristos extern char
47798b9484cSchristos xtensa_operand_inout (xtensa_isa isa, xtensa_opcode opc, int opnd);
47898b9484cSchristos 
47998b9484cSchristos 
48098b9484cSchristos /* Get and set the raw (encoded) value of the field for the specified
48198b9484cSchristos    operand.  The "set" function does not check if the value fits in the
48298b9484cSchristos    field; that is done by the "encode" function below.  Both of these
48398b9484cSchristos    functions return non-zero on error, e.g., if the field is not defined
48498b9484cSchristos    for the specified slot.  */
48598b9484cSchristos 
48698b9484cSchristos extern int
48798b9484cSchristos xtensa_operand_get_field (xtensa_isa isa, xtensa_opcode opc, int opnd,
48898b9484cSchristos 			  xtensa_format fmt, int slot,
48998b9484cSchristos 			  const xtensa_insnbuf slotbuf, uint32 *valp);
49098b9484cSchristos 
49198b9484cSchristos extern int
49298b9484cSchristos xtensa_operand_set_field (xtensa_isa isa, xtensa_opcode opc, int opnd,
49398b9484cSchristos 			  xtensa_format fmt, int slot,
49498b9484cSchristos 			  xtensa_insnbuf slotbuf, uint32 val);
49598b9484cSchristos 
49698b9484cSchristos 
49798b9484cSchristos /* Encode and decode operands.  The raw bits in the operand field may
49898b9484cSchristos    be encoded in a variety of different ways.  These functions hide
49998b9484cSchristos    the details of that encoding.  The result values are returned through
50098b9484cSchristos    the argument pointer.  The return value is non-zero on error.  */
50198b9484cSchristos 
50298b9484cSchristos extern int
50398b9484cSchristos xtensa_operand_encode (xtensa_isa isa, xtensa_opcode opc, int opnd,
50498b9484cSchristos 		       uint32 *valp);
50598b9484cSchristos 
50698b9484cSchristos extern int
50798b9484cSchristos xtensa_operand_decode (xtensa_isa isa, xtensa_opcode opc, int opnd,
50898b9484cSchristos 		       uint32 *valp);
50998b9484cSchristos 
51098b9484cSchristos 
51198b9484cSchristos /* An operand may be either a register operand or an immediate of some
51298b9484cSchristos    sort (e.g., PC-relative or not).  The "is_register" function returns
51398b9484cSchristos    0 if the operand is an immediate, 1 if it is a register, and
51498b9484cSchristos    XTENSA_UNDEFINED on error.  The "regfile" function returns the
51598b9484cSchristos    regfile for a register operand, or XTENSA_UNDEFINED on error.  */
51698b9484cSchristos 
51798b9484cSchristos extern int
51898b9484cSchristos xtensa_operand_is_register (xtensa_isa isa, xtensa_opcode opc, int opnd);
51998b9484cSchristos 
52098b9484cSchristos extern xtensa_regfile
52198b9484cSchristos xtensa_operand_regfile (xtensa_isa isa, xtensa_opcode opc, int opnd);
52298b9484cSchristos 
52398b9484cSchristos 
52498b9484cSchristos /* Register operands may span multiple consecutive registers, e.g., a
52598b9484cSchristos    64-bit data type may occupy two 32-bit registers.  Only the first
52698b9484cSchristos    register is encoded in the operand field.  This function specifies
52798b9484cSchristos    the number of consecutive registers occupied by this operand.  For
52898b9484cSchristos    non-register operands, the return value is undefined.  Returns
52998b9484cSchristos    XTENSA_UNDEFINED on error.  */
53098b9484cSchristos 
53198b9484cSchristos extern int
53298b9484cSchristos xtensa_operand_num_regs (xtensa_isa isa, xtensa_opcode opc, int opnd);
53398b9484cSchristos 
53498b9484cSchristos 
53598b9484cSchristos /* Some register operands do not completely identify the register being
53698b9484cSchristos    accessed.  For example, the operand value may be added to an internal
53798b9484cSchristos    state value.  By definition, this implies that the corresponding
53898b9484cSchristos    regfile is not allocatable.  Unknown registers should generally be
53998b9484cSchristos    treated with worst-case assumptions.  The function returns 0 if the
54098b9484cSchristos    register value is unknown, 1 if known, and XTENSA_UNDEFINED on
54198b9484cSchristos    error.  */
54298b9484cSchristos 
54398b9484cSchristos extern int
54498b9484cSchristos xtensa_operand_is_known_reg (xtensa_isa isa, xtensa_opcode opc, int opnd);
54598b9484cSchristos 
54698b9484cSchristos 
54798b9484cSchristos /* Check if an immediate operand is PC-relative.  Returns 0 for register
54898b9484cSchristos    operands and non-PC-relative immediates, 1 for PC-relative
54998b9484cSchristos    immediates, and XTENSA_UNDEFINED on error.  */
55098b9484cSchristos 
55198b9484cSchristos extern int
55298b9484cSchristos xtensa_operand_is_PCrelative (xtensa_isa isa, xtensa_opcode opc, int opnd);
55398b9484cSchristos 
55498b9484cSchristos 
55598b9484cSchristos /* For PC-relative offset operands, the interpretation of the offset may
55698b9484cSchristos    vary between opcodes, e.g., is it relative to the current PC or that
55798b9484cSchristos    of the next instruction?  The following functions are defined to
55898b9484cSchristos    perform PC-relative relocations and to undo them (as in the
55998b9484cSchristos    disassembler).  The "do_reloc" function takes the desired address
56098b9484cSchristos    value and the PC of the current instruction and sets the value to the
56198b9484cSchristos    corresponding PC-relative offset (which can then be encoded and
56298b9484cSchristos    stored into the operand field).  The "undo_reloc" function takes the
56398b9484cSchristos    unencoded offset value and the current PC and sets the value to the
56498b9484cSchristos    appropriate address.  The return values are non-zero on error.  Note
56598b9484cSchristos    that these functions do not replace the encode/decode functions; the
56698b9484cSchristos    operands must be encoded/decoded separately and the encode functions
56798b9484cSchristos    are responsible for detecting invalid operand values.  */
56898b9484cSchristos 
56998b9484cSchristos extern int
57098b9484cSchristos xtensa_operand_do_reloc (xtensa_isa isa, xtensa_opcode opc, int opnd,
57198b9484cSchristos 			 uint32 *valp, uint32 pc);
57298b9484cSchristos 
57398b9484cSchristos extern int
57498b9484cSchristos xtensa_operand_undo_reloc (xtensa_isa isa, xtensa_opcode opc, int opnd,
57598b9484cSchristos 			   uint32 *valp, uint32 pc);
57698b9484cSchristos 
57798b9484cSchristos 
57898b9484cSchristos 
57998b9484cSchristos /* State Operands.  */
58098b9484cSchristos 
58198b9484cSchristos /* Get the state accessed by a state operand.  Returns XTENSA_UNDEFINED
58298b9484cSchristos    on error.  */
58398b9484cSchristos 
58498b9484cSchristos extern xtensa_state
58598b9484cSchristos xtensa_stateOperand_state (xtensa_isa isa, xtensa_opcode opc, int stOp);
58698b9484cSchristos 
58798b9484cSchristos 
58898b9484cSchristos /* Check if a state operand is an input ('i'), output ('o'), or inout
58998b9484cSchristos    ('m') operand.  Returns 0 on error.  */
59098b9484cSchristos 
59198b9484cSchristos extern char
59298b9484cSchristos xtensa_stateOperand_inout (xtensa_isa isa, xtensa_opcode opc, int stOp);
59398b9484cSchristos 
59498b9484cSchristos 
59598b9484cSchristos 
59698b9484cSchristos /* Interface Operands.  */
59798b9484cSchristos 
59898b9484cSchristos /* Get the external interface accessed by an interface operand.
59998b9484cSchristos    Returns XTENSA_UNDEFINED on error.  */
60098b9484cSchristos 
60198b9484cSchristos extern xtensa_interface
60298b9484cSchristos xtensa_interfaceOperand_interface (xtensa_isa isa, xtensa_opcode opc,
60398b9484cSchristos 				   int ifOp);
60498b9484cSchristos 
60598b9484cSchristos 
60698b9484cSchristos 
60798b9484cSchristos /* Register Files.  */
60898b9484cSchristos 
60998b9484cSchristos /* Regfiles include both "real" regfiles and "views", where a view
61098b9484cSchristos    allows a group of adjacent registers in a real "parent" regfile to be
61198b9484cSchristos    viewed as a single register.  A regfile view has all the same
61298b9484cSchristos    properties as its parent except for its (long) name, bit width, number
61398b9484cSchristos    of entries, and default ctype.  You can use the parent function to
61498b9484cSchristos    distinguish these two classes.  */
61598b9484cSchristos 
61698b9484cSchristos /* Look up a regfile by either its name or its abbreviated "short name".
61798b9484cSchristos    Returns XTENSA_UNDEFINED on error.  The "lookup_shortname" function
61898b9484cSchristos    ignores "view" regfiles since they always have the same shortname as
61998b9484cSchristos    their parents.  */
62098b9484cSchristos 
62198b9484cSchristos extern xtensa_regfile
62298b9484cSchristos xtensa_regfile_lookup (xtensa_isa isa, const char *name);
62398b9484cSchristos 
62498b9484cSchristos extern xtensa_regfile
62598b9484cSchristos xtensa_regfile_lookup_shortname (xtensa_isa isa, const char *shortname);
62698b9484cSchristos 
62798b9484cSchristos 
62898b9484cSchristos /* Get the name or abbreviated "short name" of a regfile.
62998b9484cSchristos    Returns null on error.  */
63098b9484cSchristos 
63198b9484cSchristos extern const char *
63298b9484cSchristos xtensa_regfile_name (xtensa_isa isa, xtensa_regfile rf);
63398b9484cSchristos 
63498b9484cSchristos extern const char *
63598b9484cSchristos xtensa_regfile_shortname (xtensa_isa isa, xtensa_regfile rf);
63698b9484cSchristos 
63798b9484cSchristos 
63898b9484cSchristos /* Get the parent regfile of a "view" regfile.  If the regfile is not a
63998b9484cSchristos    view, the result is the same as the input parameter.  Returns
64098b9484cSchristos    XTENSA_UNDEFINED on error.  */
64198b9484cSchristos 
64298b9484cSchristos extern xtensa_regfile
64398b9484cSchristos xtensa_regfile_view_parent (xtensa_isa isa, xtensa_regfile rf);
64498b9484cSchristos 
64598b9484cSchristos 
64698b9484cSchristos /* Get the bit width of a regfile or regfile view.
64798b9484cSchristos    Returns XTENSA_UNDEFINED on error.  */
64898b9484cSchristos 
64998b9484cSchristos extern int
65098b9484cSchristos xtensa_regfile_num_bits (xtensa_isa isa, xtensa_regfile rf);
65198b9484cSchristos 
65298b9484cSchristos 
65398b9484cSchristos /* Get the number of regfile entries.  Returns XTENSA_UNDEFINED on
65498b9484cSchristos    error.  */
65598b9484cSchristos 
65698b9484cSchristos extern int
65798b9484cSchristos xtensa_regfile_num_entries (xtensa_isa isa, xtensa_regfile rf);
65898b9484cSchristos 
65998b9484cSchristos 
66098b9484cSchristos 
66198b9484cSchristos /* Processor States.  */
66298b9484cSchristos 
66398b9484cSchristos /* Look up a state by name.  Returns XTENSA_UNDEFINED on error.  */
66498b9484cSchristos 
66598b9484cSchristos extern xtensa_state
66698b9484cSchristos xtensa_state_lookup (xtensa_isa isa, const char *name);
66798b9484cSchristos 
66898b9484cSchristos 
66998b9484cSchristos /* Get the name for a processor state.  Returns null on error.  */
67098b9484cSchristos 
67198b9484cSchristos extern const char *
67298b9484cSchristos xtensa_state_name (xtensa_isa isa, xtensa_state st);
67398b9484cSchristos 
67498b9484cSchristos 
67598b9484cSchristos /* Get the bit width for a processor state.
67698b9484cSchristos    Returns XTENSA_UNDEFINED on error.  */
67798b9484cSchristos 
67898b9484cSchristos extern int
67998b9484cSchristos xtensa_state_num_bits (xtensa_isa isa, xtensa_state st);
68098b9484cSchristos 
68198b9484cSchristos 
68298b9484cSchristos /* Check if a state is exported from the processor core.  Returns 0 if
68398b9484cSchristos    the condition is false, 1 if the condition is true, and
68498b9484cSchristos    XTENSA_UNDEFINED on error.  */
68598b9484cSchristos 
68698b9484cSchristos extern int
68798b9484cSchristos xtensa_state_is_exported (xtensa_isa isa, xtensa_state st);
68898b9484cSchristos 
68998b9484cSchristos 
69098b9484cSchristos /* Check for a "shared_or" state.  Returns 0 if the condition is false,
69198b9484cSchristos    1 if the condition is true, and XTENSA_UNDEFINED on error.  */
69298b9484cSchristos 
69398b9484cSchristos extern int
69498b9484cSchristos xtensa_state_is_shared_or (xtensa_isa isa, xtensa_state st);
69598b9484cSchristos 
69698b9484cSchristos 
69798b9484cSchristos 
69898b9484cSchristos /* Sysregs ("special registers" and "user registers").  */
69998b9484cSchristos 
70098b9484cSchristos /* Look up a register by its number and whether it is a "user register"
70198b9484cSchristos    or a "special register".  Returns XTENSA_UNDEFINED if the sysreg does
70298b9484cSchristos    not exist.  */
70398b9484cSchristos 
70498b9484cSchristos extern xtensa_sysreg
70598b9484cSchristos xtensa_sysreg_lookup (xtensa_isa isa, int num, int is_user);
70698b9484cSchristos 
70798b9484cSchristos 
70898b9484cSchristos /* Check if there exists a sysreg with a given name.
70998b9484cSchristos    If not, this function returns XTENSA_UNDEFINED.  */
71098b9484cSchristos 
71198b9484cSchristos extern xtensa_sysreg
71298b9484cSchristos xtensa_sysreg_lookup_name (xtensa_isa isa, const char *name);
71398b9484cSchristos 
71498b9484cSchristos 
71598b9484cSchristos /* Get the name of a sysreg.  Returns null on error.  */
71698b9484cSchristos 
71798b9484cSchristos extern const char *
71898b9484cSchristos xtensa_sysreg_name (xtensa_isa isa, xtensa_sysreg sysreg);
71998b9484cSchristos 
72098b9484cSchristos 
72198b9484cSchristos /* Get the register number.  Returns XTENSA_UNDEFINED on error.  */
72298b9484cSchristos 
72398b9484cSchristos extern int
72498b9484cSchristos xtensa_sysreg_number (xtensa_isa isa, xtensa_sysreg sysreg);
72598b9484cSchristos 
72698b9484cSchristos 
72798b9484cSchristos /* Check if a sysreg is a "special register" or a "user register".
72898b9484cSchristos    Returns 0 for special registers, 1 for user registers and
72998b9484cSchristos    XTENSA_UNDEFINED on error.  */
73098b9484cSchristos 
73198b9484cSchristos extern int
73298b9484cSchristos xtensa_sysreg_is_user (xtensa_isa isa, xtensa_sysreg sysreg);
73398b9484cSchristos 
73498b9484cSchristos 
73598b9484cSchristos 
73698b9484cSchristos /* Interfaces.  */
73798b9484cSchristos 
73898b9484cSchristos /* Find an interface by name.  The return value is XTENSA_UNDEFINED if
73998b9484cSchristos    the specified interface is not found.  */
74098b9484cSchristos 
74198b9484cSchristos extern xtensa_interface
74298b9484cSchristos xtensa_interface_lookup (xtensa_isa isa, const char *ifname);
74398b9484cSchristos 
74498b9484cSchristos 
74598b9484cSchristos /* Get the name of an interface.  Returns null on error.  */
74698b9484cSchristos 
74798b9484cSchristos extern const char *
74898b9484cSchristos xtensa_interface_name (xtensa_isa isa, xtensa_interface intf);
74998b9484cSchristos 
75098b9484cSchristos 
75198b9484cSchristos /* Get the bit width for an interface.
75298b9484cSchristos    Returns XTENSA_UNDEFINED on error.  */
75398b9484cSchristos 
75498b9484cSchristos extern int
75598b9484cSchristos xtensa_interface_num_bits (xtensa_isa isa, xtensa_interface intf);
75698b9484cSchristos 
75798b9484cSchristos 
75898b9484cSchristos /* Check if an interface is an input ('i') or output ('o') with respect
75998b9484cSchristos    to the Xtensa processor core.  Returns 0 on error.  */
76098b9484cSchristos 
76198b9484cSchristos extern char
76298b9484cSchristos xtensa_interface_inout (xtensa_isa isa, xtensa_interface intf);
76398b9484cSchristos 
76498b9484cSchristos 
76598b9484cSchristos /* Check if accessing an interface has potential side effects.
76698b9484cSchristos    Currently "data" interfaces have side effects and "control"
76798b9484cSchristos    interfaces do not.  Returns 1 if there are side effects, 0 if not,
76898b9484cSchristos    and XTENSA_UNDEFINED on error.  */
76998b9484cSchristos 
77098b9484cSchristos extern int
77198b9484cSchristos xtensa_interface_has_side_effect (xtensa_isa isa, xtensa_interface intf);
77298b9484cSchristos 
77398b9484cSchristos 
77498b9484cSchristos /* Some interfaces may be related such that accessing one interface
77598b9484cSchristos    has side effects on a set of related interfaces.  The interfaces
77698b9484cSchristos    are partitioned into equivalence classes of related interfaces, and
77798b9484cSchristos    each class is assigned a unique identifier number.  This function
77898b9484cSchristos    returns the class identifier for an interface, or XTENSA_UNDEFINED
77998b9484cSchristos    on error.  These identifiers can be compared to determine if two
78098b9484cSchristos    interfaces are related; the specific values of the identifiers have
78198b9484cSchristos    no particular meaning otherwise.  */
78298b9484cSchristos 
78398b9484cSchristos extern int
78498b9484cSchristos xtensa_interface_class_id (xtensa_isa isa, xtensa_interface intf);
78598b9484cSchristos 
78698b9484cSchristos 
78798b9484cSchristos 
78898b9484cSchristos /* Functional Units.  */
78998b9484cSchristos 
79098b9484cSchristos /* Find a functional unit by name.  The return value is XTENSA_UNDEFINED if
79198b9484cSchristos    the specified unit is not found.  */
79298b9484cSchristos 
79398b9484cSchristos extern xtensa_funcUnit
79498b9484cSchristos xtensa_funcUnit_lookup (xtensa_isa isa, const char *fname);
79598b9484cSchristos 
79698b9484cSchristos 
79798b9484cSchristos /* Get the name of a functional unit.  Returns null on error.  */
79898b9484cSchristos 
79998b9484cSchristos extern const char *
80098b9484cSchristos xtensa_funcUnit_name (xtensa_isa isa, xtensa_funcUnit fun);
80198b9484cSchristos 
80298b9484cSchristos 
80398b9484cSchristos /* Functional units may be replicated.  See how many instances of a
80498b9484cSchristos    particular function unit exist.  Returns XTENSA_UNDEFINED on error.  */
80598b9484cSchristos 
80698b9484cSchristos extern int
80798b9484cSchristos xtensa_funcUnit_num_copies (xtensa_isa isa, xtensa_funcUnit fun);
80898b9484cSchristos 
80998b9484cSchristos 
81098b9484cSchristos #ifdef __cplusplus
81198b9484cSchristos }
81298b9484cSchristos #endif
81398b9484cSchristos #endif /* XTENSA_LIBISA_H */
814