xref: /netbsd-src/external/gpl3/binutils.old/dist/include/xtensa-isa.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* Interface definition for configurable Xtensa ISA support.
2*e992f068Schristos    Copyright (C) 2003-2022 Free Software Foundation, Inc.
375fd0b74Schristos 
475fd0b74Schristos    This file is part of BFD, the Binary File Descriptor library.
575fd0b74Schristos 
675fd0b74Schristos    This program is free software; you can redistribute it and/or modify
775fd0b74Schristos    it under the terms of the GNU General Public License as published by
875fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
975fd0b74Schristos    (at your option) any later version.
1075fd0b74Schristos 
1175fd0b74Schristos    This program is distributed in the hope that it will be useful,
1275fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1375fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1475fd0b74Schristos    GNU General Public License for more details.
1575fd0b74Schristos 
1675fd0b74Schristos    You should have received a copy of the GNU General Public License
1775fd0b74Schristos    along with this program; if not, write to the Free Software
1875fd0b74Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
1975fd0b74Schristos    USA.  */
2075fd0b74Schristos 
2175fd0b74Schristos #ifndef XTENSA_LIBISA_H
2275fd0b74Schristos #define XTENSA_LIBISA_H
2375fd0b74Schristos 
2475fd0b74Schristos #ifdef __cplusplus
2575fd0b74Schristos extern "C" {
2675fd0b74Schristos #endif
2775fd0b74Schristos 
2875fd0b74Schristos /* Version number: This is intended to help support code that works with
2975fd0b74Schristos    versions of this library from multiple Xtensa releases.  */
3075fd0b74Schristos 
3175fd0b74Schristos #define XTENSA_ISA_VERSION 7000
3275fd0b74Schristos 
3375fd0b74Schristos #ifndef uint32
3475fd0b74Schristos #define uint32 unsigned int
3575fd0b74Schristos #endif
3675fd0b74Schristos 
3775fd0b74Schristos /* This file defines the interface to the Xtensa ISA library.  This
3875fd0b74Schristos    library contains most of the ISA-specific information for a
3975fd0b74Schristos    particular Xtensa processor.  For example, the set of valid
4075fd0b74Schristos    instructions, their opcode encodings and operand fields are all
4175fd0b74Schristos    included here.
4275fd0b74Schristos 
4375fd0b74Schristos    This interface basically defines a number of abstract data types.
4475fd0b74Schristos 
4575fd0b74Schristos    . an instruction buffer - for holding the raw instruction bits
4675fd0b74Schristos    . ISA info - information about the ISA as a whole
4775fd0b74Schristos    . instruction formats - instruction size and slot structure
4875fd0b74Schristos    . opcodes - information about individual instructions
4975fd0b74Schristos    . operands - information about register and immediate instruction operands
5075fd0b74Schristos    . stateOperands - information about processor state instruction operands
5175fd0b74Schristos    . interfaceOperands - information about interface instruction operands
5275fd0b74Schristos    . register files - register file information
5375fd0b74Schristos    . processor states - internal processor state information
5475fd0b74Schristos    . system registers - "special registers" and "user registers"
5575fd0b74Schristos    . interfaces - TIE interfaces that are external to the processor
5675fd0b74Schristos    . functional units - TIE shared functions
5775fd0b74Schristos 
5875fd0b74Schristos    The interface defines a set of functions to access each data type.
5975fd0b74Schristos    With the exception of the instruction buffer, the internal
6075fd0b74Schristos    representations of the data structures are hidden.  All accesses must
6175fd0b74Schristos    be made through the functions defined here.  */
6275fd0b74Schristos 
6375fd0b74Schristos typedef struct xtensa_isa_opaque { int unused; } *xtensa_isa;
6475fd0b74Schristos 
6575fd0b74Schristos 
6675fd0b74Schristos /* Most of the Xtensa ISA entities (e.g., opcodes, regfiles, etc.) are
6775fd0b74Schristos    represented here using sequential integers beginning with 0.  The
6875fd0b74Schristos    specific values are only fixed for a particular instantiation of an
6975fd0b74Schristos    xtensa_isa structure, so these values should only be used
7075fd0b74Schristos    internally.  */
7175fd0b74Schristos 
7275fd0b74Schristos typedef int xtensa_opcode;
7375fd0b74Schristos typedef int xtensa_format;
7475fd0b74Schristos typedef int xtensa_regfile;
7575fd0b74Schristos typedef int xtensa_state;
7675fd0b74Schristos typedef int xtensa_sysreg;
7775fd0b74Schristos typedef int xtensa_interface;
7875fd0b74Schristos typedef int xtensa_funcUnit;
7975fd0b74Schristos 
8075fd0b74Schristos 
8175fd0b74Schristos /* Define a unique value for undefined items.  */
8275fd0b74Schristos 
8375fd0b74Schristos #define XTENSA_UNDEFINED -1
8475fd0b74Schristos 
8575fd0b74Schristos 
8675fd0b74Schristos /* Overview of using this interface to decode/encode instructions:
8775fd0b74Schristos 
8875fd0b74Schristos    Each Xtensa instruction is associated with a particular instruction
8975fd0b74Schristos    format, where the format defines a fixed number of slots for
9075fd0b74Schristos    operations.  The formats for the core Xtensa ISA have only one slot,
9175fd0b74Schristos    but FLIX instructions may have multiple slots.  Within each slot,
9275fd0b74Schristos    there is a single opcode and some number of associated operands.
9375fd0b74Schristos 
9475fd0b74Schristos    The encoding and decoding functions operate on instruction buffers,
9575fd0b74Schristos    not on the raw bytes of the instructions.  The same instruction
9675fd0b74Schristos    buffer data structure is used for both entire instructions and
9775fd0b74Schristos    individual slots in those instructions -- the contents of a slot need
9875fd0b74Schristos    to be extracted from or inserted into the buffer for the instruction
9975fd0b74Schristos    as a whole.
10075fd0b74Schristos 
10175fd0b74Schristos    Decoding an instruction involves first finding the format, which
10275fd0b74Schristos    identifies the number of slots, and then decoding each slot
10375fd0b74Schristos    separately.  A slot is decoded by finding the opcode and then using
10475fd0b74Schristos    the opcode to determine how many operands there are.  For example:
10575fd0b74Schristos 
10675fd0b74Schristos    xtensa_insnbuf_from_chars
10775fd0b74Schristos    xtensa_format_decode
10875fd0b74Schristos    for each slot {
10975fd0b74Schristos      xtensa_format_get_slot
11075fd0b74Schristos      xtensa_opcode_decode
11175fd0b74Schristos      for each operand {
11275fd0b74Schristos        xtensa_operand_get_field
11375fd0b74Schristos        xtensa_operand_decode
11475fd0b74Schristos      }
11575fd0b74Schristos    }
11675fd0b74Schristos 
11775fd0b74Schristos    Encoding an instruction is roughly the same procedure in reverse:
11875fd0b74Schristos 
11975fd0b74Schristos    xtensa_format_encode
12075fd0b74Schristos    for each slot {
12175fd0b74Schristos      xtensa_opcode_encode
12275fd0b74Schristos      for each operand {
12375fd0b74Schristos        xtensa_operand_encode
12475fd0b74Schristos        xtensa_operand_set_field
12575fd0b74Schristos      }
12675fd0b74Schristos      xtensa_format_set_slot
12775fd0b74Schristos    }
12875fd0b74Schristos    xtensa_insnbuf_to_chars
12975fd0b74Schristos */
13075fd0b74Schristos 
13175fd0b74Schristos 
13275fd0b74Schristos /* Error handling.  */
13375fd0b74Schristos 
13475fd0b74Schristos /* Error codes.  The code for the most recent error condition can be
13575fd0b74Schristos    retrieved with the "errno" function.  For any result other than
13675fd0b74Schristos    xtensa_isa_ok, an error message containing additional information
13775fd0b74Schristos    about the problem can be retrieved using the "error_msg" function.
13875fd0b74Schristos    The error messages are stored in an internal buffer, which should
13975fd0b74Schristos    not be freed and may be overwritten by subsequent operations.  */
14075fd0b74Schristos 
14175fd0b74Schristos typedef enum xtensa_isa_status_enum
14275fd0b74Schristos {
14375fd0b74Schristos   xtensa_isa_ok = 0,
14475fd0b74Schristos   xtensa_isa_bad_format,
14575fd0b74Schristos   xtensa_isa_bad_slot,
14675fd0b74Schristos   xtensa_isa_bad_opcode,
14775fd0b74Schristos   xtensa_isa_bad_operand,
14875fd0b74Schristos   xtensa_isa_bad_field,
14975fd0b74Schristos   xtensa_isa_bad_iclass,
15075fd0b74Schristos   xtensa_isa_bad_regfile,
15175fd0b74Schristos   xtensa_isa_bad_sysreg,
15275fd0b74Schristos   xtensa_isa_bad_state,
15375fd0b74Schristos   xtensa_isa_bad_interface,
15475fd0b74Schristos   xtensa_isa_bad_funcUnit,
15575fd0b74Schristos   xtensa_isa_wrong_slot,
15675fd0b74Schristos   xtensa_isa_no_field,
15775fd0b74Schristos   xtensa_isa_out_of_memory,
15875fd0b74Schristos   xtensa_isa_buffer_overflow,
15975fd0b74Schristos   xtensa_isa_internal_error,
16075fd0b74Schristos   xtensa_isa_bad_value
16175fd0b74Schristos } xtensa_isa_status;
16275fd0b74Schristos 
16375fd0b74Schristos extern xtensa_isa_status
16475fd0b74Schristos xtensa_isa_errno (xtensa_isa isa);
16575fd0b74Schristos 
16675fd0b74Schristos extern char *
16775fd0b74Schristos xtensa_isa_error_msg (xtensa_isa isa);
16875fd0b74Schristos 
16975fd0b74Schristos 
17075fd0b74Schristos 
17175fd0b74Schristos /* Instruction buffers.  */
17275fd0b74Schristos 
17375fd0b74Schristos typedef uint32 xtensa_insnbuf_word;
17475fd0b74Schristos typedef xtensa_insnbuf_word *xtensa_insnbuf;
17575fd0b74Schristos 
17675fd0b74Schristos 
17775fd0b74Schristos /* Get the size in "insnbuf_words" of the xtensa_insnbuf array.  */
17875fd0b74Schristos 
17975fd0b74Schristos extern int
18075fd0b74Schristos xtensa_insnbuf_size (xtensa_isa isa);
18175fd0b74Schristos 
18275fd0b74Schristos 
18375fd0b74Schristos /* Allocate an xtensa_insnbuf of the right size.  */
18475fd0b74Schristos 
18575fd0b74Schristos extern xtensa_insnbuf
18675fd0b74Schristos xtensa_insnbuf_alloc (xtensa_isa isa);
18775fd0b74Schristos 
18875fd0b74Schristos 
18975fd0b74Schristos /* Release an xtensa_insnbuf.  */
19075fd0b74Schristos 
19175fd0b74Schristos extern void
19275fd0b74Schristos xtensa_insnbuf_free (xtensa_isa isa, xtensa_insnbuf buf);
19375fd0b74Schristos 
19475fd0b74Schristos 
19575fd0b74Schristos /* Conversion between raw memory (char arrays) and our internal
19675fd0b74Schristos    instruction representation.  This is complicated by the Xtensa ISA's
19775fd0b74Schristos    variable instruction lengths.  When converting to chars, the buffer
19875fd0b74Schristos    must contain a valid instruction so we know how many bytes to copy;
19975fd0b74Schristos    thus, the "to_chars" function returns the number of bytes copied or
20075fd0b74Schristos    XTENSA_UNDEFINED on error.  The "from_chars" function first reads the
20175fd0b74Schristos    minimal number of bytes required to decode the instruction length and
20275fd0b74Schristos    then proceeds to copy the entire instruction into the buffer; if the
20375fd0b74Schristos    memory does not contain a valid instruction, it copies the maximum
20475fd0b74Schristos    number of bytes required for the longest Xtensa instruction.  The
20575fd0b74Schristos    "num_chars" argument may be used to limit the number of bytes that
20675fd0b74Schristos    can be read or written.  Otherwise, if "num_chars" is zero, the
20775fd0b74Schristos    functions may read or write past the end of the code.  */
20875fd0b74Schristos 
20975fd0b74Schristos extern int
21075fd0b74Schristos xtensa_insnbuf_to_chars (xtensa_isa isa, const xtensa_insnbuf insn,
21175fd0b74Schristos 			 unsigned char *cp, int num_chars);
21275fd0b74Schristos 
21375fd0b74Schristos extern void
21475fd0b74Schristos xtensa_insnbuf_from_chars (xtensa_isa isa, xtensa_insnbuf insn,
21575fd0b74Schristos 			   const unsigned char *cp, int num_chars);
21675fd0b74Schristos 
21775fd0b74Schristos 
21875fd0b74Schristos 
21975fd0b74Schristos /* ISA information.  */
22075fd0b74Schristos 
22175fd0b74Schristos /* Initialize the ISA information.  */
22275fd0b74Schristos 
22375fd0b74Schristos extern xtensa_isa
22475fd0b74Schristos xtensa_isa_init (xtensa_isa_status *errno_p, char **error_msg_p);
22575fd0b74Schristos 
22675fd0b74Schristos 
22775fd0b74Schristos /* Deallocate an xtensa_isa structure.  */
22875fd0b74Schristos 
22975fd0b74Schristos extern void
23075fd0b74Schristos xtensa_isa_free (xtensa_isa isa);
23175fd0b74Schristos 
23275fd0b74Schristos 
23375fd0b74Schristos /* Get the maximum instruction size in bytes.  */
23475fd0b74Schristos 
23575fd0b74Schristos extern int
23675fd0b74Schristos xtensa_isa_maxlength (xtensa_isa isa);
23775fd0b74Schristos 
23875fd0b74Schristos 
23975fd0b74Schristos /* Decode the length in bytes of an instruction in raw memory (not an
24075fd0b74Schristos    insnbuf).  This function reads only the minimal number of bytes
24175fd0b74Schristos    required to decode the instruction length.  Returns
24275fd0b74Schristos    XTENSA_UNDEFINED on error.  */
24375fd0b74Schristos 
24475fd0b74Schristos extern int
24575fd0b74Schristos xtensa_isa_length_from_chars (xtensa_isa isa, const unsigned char *cp);
24675fd0b74Schristos 
24775fd0b74Schristos 
24875fd0b74Schristos /* Get the number of stages in the processor's pipeline.  The pipeline
24975fd0b74Schristos    stage values returned by other functions in this library will range
25075fd0b74Schristos    from 0 to N-1, where N is the value returned by this function.
25175fd0b74Schristos    Note that the stage numbers used here may not correspond to the
25275fd0b74Schristos    actual processor hardware, e.g., the hardware may have additional
25375fd0b74Schristos    stages before stage 0.  Returns XTENSA_UNDEFINED on error.  */
25475fd0b74Schristos 
25575fd0b74Schristos extern int
25675fd0b74Schristos xtensa_isa_num_pipe_stages (xtensa_isa isa);
25775fd0b74Schristos 
25875fd0b74Schristos 
25975fd0b74Schristos /* Get the number of various entities that are defined for this processor.  */
26075fd0b74Schristos 
26175fd0b74Schristos extern int
26275fd0b74Schristos xtensa_isa_num_formats (xtensa_isa isa);
26375fd0b74Schristos 
26475fd0b74Schristos extern int
26575fd0b74Schristos xtensa_isa_num_opcodes (xtensa_isa isa);
26675fd0b74Schristos 
26775fd0b74Schristos extern int
26875fd0b74Schristos xtensa_isa_num_regfiles (xtensa_isa isa);
26975fd0b74Schristos 
27075fd0b74Schristos extern int
27175fd0b74Schristos xtensa_isa_num_states (xtensa_isa isa);
27275fd0b74Schristos 
27375fd0b74Schristos extern int
27475fd0b74Schristos xtensa_isa_num_sysregs (xtensa_isa isa);
27575fd0b74Schristos 
27675fd0b74Schristos extern int
27775fd0b74Schristos xtensa_isa_num_interfaces (xtensa_isa isa);
27875fd0b74Schristos 
27975fd0b74Schristos extern int
28075fd0b74Schristos xtensa_isa_num_funcUnits (xtensa_isa isa);
28175fd0b74Schristos 
28275fd0b74Schristos 
28375fd0b74Schristos 
28475fd0b74Schristos /* Instruction formats.  */
28575fd0b74Schristos 
28675fd0b74Schristos /* Get the name of a format.  Returns null on error.  */
28775fd0b74Schristos 
28875fd0b74Schristos extern const char *
28975fd0b74Schristos xtensa_format_name (xtensa_isa isa, xtensa_format fmt);
29075fd0b74Schristos 
29175fd0b74Schristos 
29275fd0b74Schristos /* Given a format name, return the format number.  Returns
29375fd0b74Schristos    XTENSA_UNDEFINED if the name is not a valid format.  */
29475fd0b74Schristos 
29575fd0b74Schristos extern xtensa_format
29675fd0b74Schristos xtensa_format_lookup (xtensa_isa isa, const char *fmtname);
29775fd0b74Schristos 
29875fd0b74Schristos 
29975fd0b74Schristos /* Decode the instruction format from a binary instruction buffer.
30075fd0b74Schristos    Returns XTENSA_UNDEFINED if the format is not recognized.  */
30175fd0b74Schristos 
30275fd0b74Schristos extern xtensa_format
30375fd0b74Schristos xtensa_format_decode (xtensa_isa isa, const xtensa_insnbuf insn);
30475fd0b74Schristos 
30575fd0b74Schristos 
30675fd0b74Schristos /* Set the instruction format field(s) in a binary instruction buffer.
30775fd0b74Schristos    All the other fields are set to zero.  Returns non-zero on error.  */
30875fd0b74Schristos 
30975fd0b74Schristos extern int
31075fd0b74Schristos xtensa_format_encode (xtensa_isa isa, xtensa_format fmt, xtensa_insnbuf insn);
31175fd0b74Schristos 
31275fd0b74Schristos 
31375fd0b74Schristos /* Find the length (in bytes) of an instruction.  Returns
31475fd0b74Schristos    XTENSA_UNDEFINED on error.  */
31575fd0b74Schristos 
31675fd0b74Schristos extern int
31775fd0b74Schristos xtensa_format_length (xtensa_isa isa, xtensa_format fmt);
31875fd0b74Schristos 
31975fd0b74Schristos 
32075fd0b74Schristos /* Get the number of slots in an instruction.  Returns XTENSA_UNDEFINED
32175fd0b74Schristos    on error.  */
32275fd0b74Schristos 
32375fd0b74Schristos extern int
32475fd0b74Schristos xtensa_format_num_slots (xtensa_isa isa, xtensa_format fmt);
32575fd0b74Schristos 
32675fd0b74Schristos 
32775fd0b74Schristos /* Get the opcode for a no-op in a particular slot.
32875fd0b74Schristos    Returns XTENSA_UNDEFINED on error.  */
32975fd0b74Schristos 
33075fd0b74Schristos extern xtensa_opcode
33175fd0b74Schristos xtensa_format_slot_nop_opcode (xtensa_isa isa, xtensa_format fmt, int slot);
33275fd0b74Schristos 
33375fd0b74Schristos 
33475fd0b74Schristos /* Get the bits for a specified slot out of an insnbuf for the
33575fd0b74Schristos    instruction as a whole and put them into an insnbuf for that one
33675fd0b74Schristos    slot, and do the opposite to set a slot.  Return non-zero on error.  */
33775fd0b74Schristos 
33875fd0b74Schristos extern int
33975fd0b74Schristos xtensa_format_get_slot (xtensa_isa isa, xtensa_format fmt, int slot,
34075fd0b74Schristos 			const xtensa_insnbuf insn, xtensa_insnbuf slotbuf);
34175fd0b74Schristos 
34275fd0b74Schristos extern int
34375fd0b74Schristos xtensa_format_set_slot (xtensa_isa isa, xtensa_format fmt, int slot,
34475fd0b74Schristos 			xtensa_insnbuf insn, const xtensa_insnbuf slotbuf);
34575fd0b74Schristos 
34675fd0b74Schristos 
34775fd0b74Schristos 
34875fd0b74Schristos /* Opcode information.  */
34975fd0b74Schristos 
35075fd0b74Schristos /* Translate a mnemonic name to an opcode.  Returns XTENSA_UNDEFINED if
35175fd0b74Schristos    the name is not a valid opcode mnemonic.  */
35275fd0b74Schristos 
35375fd0b74Schristos extern xtensa_opcode
35475fd0b74Schristos xtensa_opcode_lookup (xtensa_isa isa, const char *opname);
35575fd0b74Schristos 
35675fd0b74Schristos 
35775fd0b74Schristos /* Decode the opcode for one instruction slot from a binary instruction
35875fd0b74Schristos    buffer.  Returns the opcode or XTENSA_UNDEFINED if the opcode is
35975fd0b74Schristos    illegal.  */
36075fd0b74Schristos 
36175fd0b74Schristos extern xtensa_opcode
36275fd0b74Schristos xtensa_opcode_decode (xtensa_isa isa, xtensa_format fmt, int slot,
36375fd0b74Schristos 		      const xtensa_insnbuf slotbuf);
36475fd0b74Schristos 
36575fd0b74Schristos 
36675fd0b74Schristos /* Set the opcode field(s) for an instruction slot.  All other fields
36775fd0b74Schristos    in the slot are set to zero.  Returns non-zero if the opcode cannot
36875fd0b74Schristos    be encoded.  */
36975fd0b74Schristos 
37075fd0b74Schristos extern int
37175fd0b74Schristos xtensa_opcode_encode (xtensa_isa isa, xtensa_format fmt, int slot,
37275fd0b74Schristos 		      xtensa_insnbuf slotbuf, xtensa_opcode opc);
37375fd0b74Schristos 
37475fd0b74Schristos 
37575fd0b74Schristos /* Get the mnemonic name for an opcode.  Returns null on error.  */
37675fd0b74Schristos 
37775fd0b74Schristos extern const char *
37875fd0b74Schristos xtensa_opcode_name (xtensa_isa isa, xtensa_opcode opc);
37975fd0b74Schristos 
38075fd0b74Schristos 
38175fd0b74Schristos /* Check various properties of opcodes.  These functions return 0 if
38275fd0b74Schristos    the condition is false, 1 if the condition is true, and
38375fd0b74Schristos    XTENSA_UNDEFINED on error.  The instructions are classified as
38475fd0b74Schristos    follows:
38575fd0b74Schristos 
38675fd0b74Schristos    branch: conditional branch; may fall through to next instruction (B*)
38775fd0b74Schristos    jump: unconditional branch (J, JX, RET*, RF*)
38875fd0b74Schristos    loop: zero-overhead loop (LOOP*)
38975fd0b74Schristos    call: unconditional call; control returns to next instruction (CALL*)
39075fd0b74Schristos 
39175fd0b74Schristos    For the opcodes that affect control flow in some way, the branch
39275fd0b74Schristos    target may be specified by an immediate operand or it may be an
39375fd0b74Schristos    address stored in a register.  You can distinguish these by
39475fd0b74Schristos    checking if the instruction has a PC-relative immediate
39575fd0b74Schristos    operand.  */
39675fd0b74Schristos 
39775fd0b74Schristos extern int
39875fd0b74Schristos xtensa_opcode_is_branch (xtensa_isa isa, xtensa_opcode opc);
39975fd0b74Schristos 
40075fd0b74Schristos extern int
40175fd0b74Schristos xtensa_opcode_is_jump (xtensa_isa isa, xtensa_opcode opc);
40275fd0b74Schristos 
40375fd0b74Schristos extern int
40475fd0b74Schristos xtensa_opcode_is_loop (xtensa_isa isa, xtensa_opcode opc);
40575fd0b74Schristos 
40675fd0b74Schristos extern int
40775fd0b74Schristos xtensa_opcode_is_call (xtensa_isa isa, xtensa_opcode opc);
40875fd0b74Schristos 
40975fd0b74Schristos 
41075fd0b74Schristos /* Find the number of ordinary operands, state operands, and interface
41175fd0b74Schristos    operands for an instruction.  These return XTENSA_UNDEFINED on
41275fd0b74Schristos    error.  */
41375fd0b74Schristos 
41475fd0b74Schristos extern int
41575fd0b74Schristos xtensa_opcode_num_operands (xtensa_isa isa, xtensa_opcode opc);
41675fd0b74Schristos 
41775fd0b74Schristos extern int
41875fd0b74Schristos xtensa_opcode_num_stateOperands (xtensa_isa isa, xtensa_opcode opc);
41975fd0b74Schristos 
42075fd0b74Schristos extern int
42175fd0b74Schristos xtensa_opcode_num_interfaceOperands (xtensa_isa isa, xtensa_opcode opc);
42275fd0b74Schristos 
42375fd0b74Schristos 
42475fd0b74Schristos /* Get functional unit usage requirements for an opcode.  Each "use"
42575fd0b74Schristos    is identified by a <functional unit, pipeline stage> pair.  The
42675fd0b74Schristos    "num_funcUnit_uses" function returns the number of these "uses" or
42775fd0b74Schristos    XTENSA_UNDEFINED on error.  The "funcUnit_use" function returns
42875fd0b74Schristos    a pointer to a "use" pair or null on error.  */
42975fd0b74Schristos 
43075fd0b74Schristos typedef struct xtensa_funcUnit_use_struct
43175fd0b74Schristos {
43275fd0b74Schristos   xtensa_funcUnit unit;
43375fd0b74Schristos   int stage;
43475fd0b74Schristos } xtensa_funcUnit_use;
43575fd0b74Schristos 
43675fd0b74Schristos extern int
43775fd0b74Schristos xtensa_opcode_num_funcUnit_uses (xtensa_isa isa, xtensa_opcode opc);
43875fd0b74Schristos 
43975fd0b74Schristos extern xtensa_funcUnit_use *
44075fd0b74Schristos xtensa_opcode_funcUnit_use (xtensa_isa isa, xtensa_opcode opc, int u);
44175fd0b74Schristos 
44275fd0b74Schristos 
44375fd0b74Schristos 
44475fd0b74Schristos /* Operand information.  */
44575fd0b74Schristos 
44675fd0b74Schristos /* Get the name of an operand.  Returns null on error.  */
44775fd0b74Schristos 
44875fd0b74Schristos extern const char *
44975fd0b74Schristos xtensa_operand_name (xtensa_isa isa, xtensa_opcode opc, int opnd);
45075fd0b74Schristos 
45175fd0b74Schristos 
45275fd0b74Schristos /* Some operands are "invisible", i.e., not explicitly specified in
45375fd0b74Schristos    assembly language.  When assembling an instruction, you need not set
45475fd0b74Schristos    the values of invisible operands, since they are either hardwired or
45575fd0b74Schristos    derived from other field values.  The values of invisible operands
45675fd0b74Schristos    can be examined in the same way as other operands, but remember that
45775fd0b74Schristos    an invisible operand may get its value from another visible one, so
45875fd0b74Schristos    the entire instruction must be available before examining the
45975fd0b74Schristos    invisible operand values.  This function returns 1 if an operand is
46075fd0b74Schristos    visible, 0 if it is invisible, or XTENSA_UNDEFINED on error.  Note
46175fd0b74Schristos    that whether an operand is visible is orthogonal to whether it is
46275fd0b74Schristos    "implicit", i.e., whether it is encoded in a field in the
46375fd0b74Schristos    instruction.  */
46475fd0b74Schristos 
46575fd0b74Schristos extern int
46675fd0b74Schristos xtensa_operand_is_visible (xtensa_isa isa, xtensa_opcode opc, int opnd);
46775fd0b74Schristos 
46875fd0b74Schristos 
46975fd0b74Schristos /* Check if an operand is an input ('i'), output ('o'), or inout ('m')
47075fd0b74Schristos    operand.  Note: The output operand of a conditional assignment
47175fd0b74Schristos    (e.g., movnez) appears here as an inout ('m') even if it is declared
47275fd0b74Schristos    in the TIE code as an output ('o'); this allows the compiler to
47375fd0b74Schristos    properly handle register allocation for conditional assignments.
47475fd0b74Schristos    Returns 0 on error.  */
47575fd0b74Schristos 
47675fd0b74Schristos extern char
47775fd0b74Schristos xtensa_operand_inout (xtensa_isa isa, xtensa_opcode opc, int opnd);
47875fd0b74Schristos 
47975fd0b74Schristos 
48075fd0b74Schristos /* Get and set the raw (encoded) value of the field for the specified
48175fd0b74Schristos    operand.  The "set" function does not check if the value fits in the
48275fd0b74Schristos    field; that is done by the "encode" function below.  Both of these
48375fd0b74Schristos    functions return non-zero on error, e.g., if the field is not defined
48475fd0b74Schristos    for the specified slot.  */
48575fd0b74Schristos 
48675fd0b74Schristos extern int
48775fd0b74Schristos xtensa_operand_get_field (xtensa_isa isa, xtensa_opcode opc, int opnd,
48875fd0b74Schristos 			  xtensa_format fmt, int slot,
48975fd0b74Schristos 			  const xtensa_insnbuf slotbuf, uint32 *valp);
49075fd0b74Schristos 
49175fd0b74Schristos extern int
49275fd0b74Schristos xtensa_operand_set_field (xtensa_isa isa, xtensa_opcode opc, int opnd,
49375fd0b74Schristos 			  xtensa_format fmt, int slot,
49475fd0b74Schristos 			  xtensa_insnbuf slotbuf, uint32 val);
49575fd0b74Schristos 
49675fd0b74Schristos 
49775fd0b74Schristos /* Encode and decode operands.  The raw bits in the operand field may
49875fd0b74Schristos    be encoded in a variety of different ways.  These functions hide
49975fd0b74Schristos    the details of that encoding.  The result values are returned through
50075fd0b74Schristos    the argument pointer.  The return value is non-zero on error.  */
50175fd0b74Schristos 
50275fd0b74Schristos extern int
50375fd0b74Schristos xtensa_operand_encode (xtensa_isa isa, xtensa_opcode opc, int opnd,
50475fd0b74Schristos 		       uint32 *valp);
50575fd0b74Schristos 
50675fd0b74Schristos extern int
50775fd0b74Schristos xtensa_operand_decode (xtensa_isa isa, xtensa_opcode opc, int opnd,
50875fd0b74Schristos 		       uint32 *valp);
50975fd0b74Schristos 
51075fd0b74Schristos 
51175fd0b74Schristos /* An operand may be either a register operand or an immediate of some
51275fd0b74Schristos    sort (e.g., PC-relative or not).  The "is_register" function returns
51375fd0b74Schristos    0 if the operand is an immediate, 1 if it is a register, and
51475fd0b74Schristos    XTENSA_UNDEFINED on error.  The "regfile" function returns the
51575fd0b74Schristos    regfile for a register operand, or XTENSA_UNDEFINED on error.  */
51675fd0b74Schristos 
51775fd0b74Schristos extern int
51875fd0b74Schristos xtensa_operand_is_register (xtensa_isa isa, xtensa_opcode opc, int opnd);
51975fd0b74Schristos 
52075fd0b74Schristos extern xtensa_regfile
52175fd0b74Schristos xtensa_operand_regfile (xtensa_isa isa, xtensa_opcode opc, int opnd);
52275fd0b74Schristos 
52375fd0b74Schristos 
52475fd0b74Schristos /* Register operands may span multiple consecutive registers, e.g., a
52575fd0b74Schristos    64-bit data type may occupy two 32-bit registers.  Only the first
52675fd0b74Schristos    register is encoded in the operand field.  This function specifies
52775fd0b74Schristos    the number of consecutive registers occupied by this operand.  For
52875fd0b74Schristos    non-register operands, the return value is undefined.  Returns
52975fd0b74Schristos    XTENSA_UNDEFINED on error.  */
53075fd0b74Schristos 
53175fd0b74Schristos extern int
53275fd0b74Schristos xtensa_operand_num_regs (xtensa_isa isa, xtensa_opcode opc, int opnd);
53375fd0b74Schristos 
53475fd0b74Schristos 
53575fd0b74Schristos /* Some register operands do not completely identify the register being
53675fd0b74Schristos    accessed.  For example, the operand value may be added to an internal
53775fd0b74Schristos    state value.  By definition, this implies that the corresponding
53875fd0b74Schristos    regfile is not allocatable.  Unknown registers should generally be
53975fd0b74Schristos    treated with worst-case assumptions.  The function returns 0 if the
54075fd0b74Schristos    register value is unknown, 1 if known, and XTENSA_UNDEFINED on
54175fd0b74Schristos    error.  */
54275fd0b74Schristos 
54375fd0b74Schristos extern int
54475fd0b74Schristos xtensa_operand_is_known_reg (xtensa_isa isa, xtensa_opcode opc, int opnd);
54575fd0b74Schristos 
54675fd0b74Schristos 
54775fd0b74Schristos /* Check if an immediate operand is PC-relative.  Returns 0 for register
54875fd0b74Schristos    operands and non-PC-relative immediates, 1 for PC-relative
54975fd0b74Schristos    immediates, and XTENSA_UNDEFINED on error.  */
55075fd0b74Schristos 
55175fd0b74Schristos extern int
55275fd0b74Schristos xtensa_operand_is_PCrelative (xtensa_isa isa, xtensa_opcode opc, int opnd);
55375fd0b74Schristos 
55475fd0b74Schristos 
55575fd0b74Schristos /* For PC-relative offset operands, the interpretation of the offset may
55675fd0b74Schristos    vary between opcodes, e.g., is it relative to the current PC or that
55775fd0b74Schristos    of the next instruction?  The following functions are defined to
55875fd0b74Schristos    perform PC-relative relocations and to undo them (as in the
55975fd0b74Schristos    disassembler).  The "do_reloc" function takes the desired address
56075fd0b74Schristos    value and the PC of the current instruction and sets the value to the
56175fd0b74Schristos    corresponding PC-relative offset (which can then be encoded and
56275fd0b74Schristos    stored into the operand field).  The "undo_reloc" function takes the
56375fd0b74Schristos    unencoded offset value and the current PC and sets the value to the
56475fd0b74Schristos    appropriate address.  The return values are non-zero on error.  Note
56575fd0b74Schristos    that these functions do not replace the encode/decode functions; the
56675fd0b74Schristos    operands must be encoded/decoded separately and the encode functions
56775fd0b74Schristos    are responsible for detecting invalid operand values.  */
56875fd0b74Schristos 
56975fd0b74Schristos extern int
57075fd0b74Schristos xtensa_operand_do_reloc (xtensa_isa isa, xtensa_opcode opc, int opnd,
57175fd0b74Schristos 			 uint32 *valp, uint32 pc);
57275fd0b74Schristos 
57375fd0b74Schristos extern int
57475fd0b74Schristos xtensa_operand_undo_reloc (xtensa_isa isa, xtensa_opcode opc, int opnd,
57575fd0b74Schristos 			   uint32 *valp, uint32 pc);
57675fd0b74Schristos 
57775fd0b74Schristos 
57875fd0b74Schristos 
57975fd0b74Schristos /* State Operands.  */
58075fd0b74Schristos 
58175fd0b74Schristos /* Get the state accessed by a state operand.  Returns XTENSA_UNDEFINED
58275fd0b74Schristos    on error.  */
58375fd0b74Schristos 
58475fd0b74Schristos extern xtensa_state
58575fd0b74Schristos xtensa_stateOperand_state (xtensa_isa isa, xtensa_opcode opc, int stOp);
58675fd0b74Schristos 
58775fd0b74Schristos 
58875fd0b74Schristos /* Check if a state operand is an input ('i'), output ('o'), or inout
58975fd0b74Schristos    ('m') operand.  Returns 0 on error.  */
59075fd0b74Schristos 
59175fd0b74Schristos extern char
59275fd0b74Schristos xtensa_stateOperand_inout (xtensa_isa isa, xtensa_opcode opc, int stOp);
59375fd0b74Schristos 
59475fd0b74Schristos 
59575fd0b74Schristos 
59675fd0b74Schristos /* Interface Operands.  */
59775fd0b74Schristos 
59875fd0b74Schristos /* Get the external interface accessed by an interface operand.
59975fd0b74Schristos    Returns XTENSA_UNDEFINED on error.  */
60075fd0b74Schristos 
60175fd0b74Schristos extern xtensa_interface
60275fd0b74Schristos xtensa_interfaceOperand_interface (xtensa_isa isa, xtensa_opcode opc,
60375fd0b74Schristos 				   int ifOp);
60475fd0b74Schristos 
60575fd0b74Schristos 
60675fd0b74Schristos 
60775fd0b74Schristos /* Register Files.  */
60875fd0b74Schristos 
60975fd0b74Schristos /* Regfiles include both "real" regfiles and "views", where a view
61075fd0b74Schristos    allows a group of adjacent registers in a real "parent" regfile to be
61175fd0b74Schristos    viewed as a single register.  A regfile view has all the same
61275fd0b74Schristos    properties as its parent except for its (long) name, bit width, number
61375fd0b74Schristos    of entries, and default ctype.  You can use the parent function to
61475fd0b74Schristos    distinguish these two classes.  */
61575fd0b74Schristos 
61675fd0b74Schristos /* Look up a regfile by either its name or its abbreviated "short name".
61775fd0b74Schristos    Returns XTENSA_UNDEFINED on error.  The "lookup_shortname" function
61875fd0b74Schristos    ignores "view" regfiles since they always have the same shortname as
61975fd0b74Schristos    their parents.  */
62075fd0b74Schristos 
62175fd0b74Schristos extern xtensa_regfile
62275fd0b74Schristos xtensa_regfile_lookup (xtensa_isa isa, const char *name);
62375fd0b74Schristos 
62475fd0b74Schristos extern xtensa_regfile
62575fd0b74Schristos xtensa_regfile_lookup_shortname (xtensa_isa isa, const char *shortname);
62675fd0b74Schristos 
62775fd0b74Schristos 
62875fd0b74Schristos /* Get the name or abbreviated "short name" of a regfile.
62975fd0b74Schristos    Returns null on error.  */
63075fd0b74Schristos 
63175fd0b74Schristos extern const char *
63275fd0b74Schristos xtensa_regfile_name (xtensa_isa isa, xtensa_regfile rf);
63375fd0b74Schristos 
63475fd0b74Schristos extern const char *
63575fd0b74Schristos xtensa_regfile_shortname (xtensa_isa isa, xtensa_regfile rf);
63675fd0b74Schristos 
63775fd0b74Schristos 
63875fd0b74Schristos /* Get the parent regfile of a "view" regfile.  If the regfile is not a
63975fd0b74Schristos    view, the result is the same as the input parameter.  Returns
64075fd0b74Schristos    XTENSA_UNDEFINED on error.  */
64175fd0b74Schristos 
64275fd0b74Schristos extern xtensa_regfile
64375fd0b74Schristos xtensa_regfile_view_parent (xtensa_isa isa, xtensa_regfile rf);
64475fd0b74Schristos 
64575fd0b74Schristos 
64675fd0b74Schristos /* Get the bit width of a regfile or regfile view.
64775fd0b74Schristos    Returns XTENSA_UNDEFINED on error.  */
64875fd0b74Schristos 
64975fd0b74Schristos extern int
65075fd0b74Schristos xtensa_regfile_num_bits (xtensa_isa isa, xtensa_regfile rf);
65175fd0b74Schristos 
65275fd0b74Schristos 
65375fd0b74Schristos /* Get the number of regfile entries.  Returns XTENSA_UNDEFINED on
65475fd0b74Schristos    error.  */
65575fd0b74Schristos 
65675fd0b74Schristos extern int
65775fd0b74Schristos xtensa_regfile_num_entries (xtensa_isa isa, xtensa_regfile rf);
65875fd0b74Schristos 
65975fd0b74Schristos 
66075fd0b74Schristos 
66175fd0b74Schristos /* Processor States.  */
66275fd0b74Schristos 
66375fd0b74Schristos /* Look up a state by name.  Returns XTENSA_UNDEFINED on error.  */
66475fd0b74Schristos 
66575fd0b74Schristos extern xtensa_state
66675fd0b74Schristos xtensa_state_lookup (xtensa_isa isa, const char *name);
66775fd0b74Schristos 
66875fd0b74Schristos 
66975fd0b74Schristos /* Get the name for a processor state.  Returns null on error.  */
67075fd0b74Schristos 
67175fd0b74Schristos extern const char *
67275fd0b74Schristos xtensa_state_name (xtensa_isa isa, xtensa_state st);
67375fd0b74Schristos 
67475fd0b74Schristos 
67575fd0b74Schristos /* Get the bit width for a processor state.
67675fd0b74Schristos    Returns XTENSA_UNDEFINED on error.  */
67775fd0b74Schristos 
67875fd0b74Schristos extern int
67975fd0b74Schristos xtensa_state_num_bits (xtensa_isa isa, xtensa_state st);
68075fd0b74Schristos 
68175fd0b74Schristos 
68275fd0b74Schristos /* Check if a state is exported from the processor core.  Returns 0 if
68375fd0b74Schristos    the condition is false, 1 if the condition is true, and
68475fd0b74Schristos    XTENSA_UNDEFINED on error.  */
68575fd0b74Schristos 
68675fd0b74Schristos extern int
68775fd0b74Schristos xtensa_state_is_exported (xtensa_isa isa, xtensa_state st);
68875fd0b74Schristos 
68975fd0b74Schristos 
69075fd0b74Schristos /* Check for a "shared_or" state.  Returns 0 if the condition is false,
69175fd0b74Schristos    1 if the condition is true, and XTENSA_UNDEFINED on error.  */
69275fd0b74Schristos 
69375fd0b74Schristos extern int
69475fd0b74Schristos xtensa_state_is_shared_or (xtensa_isa isa, xtensa_state st);
69575fd0b74Schristos 
69675fd0b74Schristos 
69775fd0b74Schristos 
69875fd0b74Schristos /* Sysregs ("special registers" and "user registers").  */
69975fd0b74Schristos 
70075fd0b74Schristos /* Look up a register by its number and whether it is a "user register"
70175fd0b74Schristos    or a "special register".  Returns XTENSA_UNDEFINED if the sysreg does
70275fd0b74Schristos    not exist.  */
70375fd0b74Schristos 
70475fd0b74Schristos extern xtensa_sysreg
70575fd0b74Schristos xtensa_sysreg_lookup (xtensa_isa isa, int num, int is_user);
70675fd0b74Schristos 
70775fd0b74Schristos 
70875fd0b74Schristos /* Check if there exists a sysreg with a given name.
70975fd0b74Schristos    If not, this function returns XTENSA_UNDEFINED.  */
71075fd0b74Schristos 
71175fd0b74Schristos extern xtensa_sysreg
71275fd0b74Schristos xtensa_sysreg_lookup_name (xtensa_isa isa, const char *name);
71375fd0b74Schristos 
71475fd0b74Schristos 
71575fd0b74Schristos /* Get the name of a sysreg.  Returns null on error.  */
71675fd0b74Schristos 
71775fd0b74Schristos extern const char *
71875fd0b74Schristos xtensa_sysreg_name (xtensa_isa isa, xtensa_sysreg sysreg);
71975fd0b74Schristos 
72075fd0b74Schristos 
72175fd0b74Schristos /* Get the register number.  Returns XTENSA_UNDEFINED on error.  */
72275fd0b74Schristos 
72375fd0b74Schristos extern int
72475fd0b74Schristos xtensa_sysreg_number (xtensa_isa isa, xtensa_sysreg sysreg);
72575fd0b74Schristos 
72675fd0b74Schristos 
72775fd0b74Schristos /* Check if a sysreg is a "special register" or a "user register".
72875fd0b74Schristos    Returns 0 for special registers, 1 for user registers and
72975fd0b74Schristos    XTENSA_UNDEFINED on error.  */
73075fd0b74Schristos 
73175fd0b74Schristos extern int
73275fd0b74Schristos xtensa_sysreg_is_user (xtensa_isa isa, xtensa_sysreg sysreg);
73375fd0b74Schristos 
73475fd0b74Schristos 
73575fd0b74Schristos 
73675fd0b74Schristos /* Interfaces.  */
73775fd0b74Schristos 
73875fd0b74Schristos /* Find an interface by name.  The return value is XTENSA_UNDEFINED if
73975fd0b74Schristos    the specified interface is not found.  */
74075fd0b74Schristos 
74175fd0b74Schristos extern xtensa_interface
74275fd0b74Schristos xtensa_interface_lookup (xtensa_isa isa, const char *ifname);
74375fd0b74Schristos 
74475fd0b74Schristos 
74575fd0b74Schristos /* Get the name of an interface.  Returns null on error.  */
74675fd0b74Schristos 
74775fd0b74Schristos extern const char *
74875fd0b74Schristos xtensa_interface_name (xtensa_isa isa, xtensa_interface intf);
74975fd0b74Schristos 
75075fd0b74Schristos 
75175fd0b74Schristos /* Get the bit width for an interface.
75275fd0b74Schristos    Returns XTENSA_UNDEFINED on error.  */
75375fd0b74Schristos 
75475fd0b74Schristos extern int
75575fd0b74Schristos xtensa_interface_num_bits (xtensa_isa isa, xtensa_interface intf);
75675fd0b74Schristos 
75775fd0b74Schristos 
75875fd0b74Schristos /* Check if an interface is an input ('i') or output ('o') with respect
75975fd0b74Schristos    to the Xtensa processor core.  Returns 0 on error.  */
76075fd0b74Schristos 
76175fd0b74Schristos extern char
76275fd0b74Schristos xtensa_interface_inout (xtensa_isa isa, xtensa_interface intf);
76375fd0b74Schristos 
76475fd0b74Schristos 
76575fd0b74Schristos /* Check if accessing an interface has potential side effects.
76675fd0b74Schristos    Currently "data" interfaces have side effects and "control"
76775fd0b74Schristos    interfaces do not.  Returns 1 if there are side effects, 0 if not,
76875fd0b74Schristos    and XTENSA_UNDEFINED on error.  */
76975fd0b74Schristos 
77075fd0b74Schristos extern int
77175fd0b74Schristos xtensa_interface_has_side_effect (xtensa_isa isa, xtensa_interface intf);
77275fd0b74Schristos 
77375fd0b74Schristos 
77475fd0b74Schristos /* Some interfaces may be related such that accessing one interface
77575fd0b74Schristos    has side effects on a set of related interfaces.  The interfaces
77675fd0b74Schristos    are partitioned into equivalence classes of related interfaces, and
77775fd0b74Schristos    each class is assigned a unique identifier number.  This function
77875fd0b74Schristos    returns the class identifier for an interface, or XTENSA_UNDEFINED
77975fd0b74Schristos    on error.  These identifiers can be compared to determine if two
78075fd0b74Schristos    interfaces are related; the specific values of the identifiers have
78175fd0b74Schristos    no particular meaning otherwise.  */
78275fd0b74Schristos 
78375fd0b74Schristos extern int
78475fd0b74Schristos xtensa_interface_class_id (xtensa_isa isa, xtensa_interface intf);
78575fd0b74Schristos 
78675fd0b74Schristos 
78775fd0b74Schristos 
78875fd0b74Schristos /* Functional Units.  */
78975fd0b74Schristos 
79075fd0b74Schristos /* Find a functional unit by name.  The return value is XTENSA_UNDEFINED if
79175fd0b74Schristos    the specified unit is not found.  */
79275fd0b74Schristos 
79375fd0b74Schristos extern xtensa_funcUnit
79475fd0b74Schristos xtensa_funcUnit_lookup (xtensa_isa isa, const char *fname);
79575fd0b74Schristos 
79675fd0b74Schristos 
79775fd0b74Schristos /* Get the name of a functional unit.  Returns null on error.  */
79875fd0b74Schristos 
79975fd0b74Schristos extern const char *
80075fd0b74Schristos xtensa_funcUnit_name (xtensa_isa isa, xtensa_funcUnit fun);
80175fd0b74Schristos 
80275fd0b74Schristos 
80375fd0b74Schristos /* Functional units may be replicated.  See how many instances of a
80475fd0b74Schristos    particular function unit exist.  Returns XTENSA_UNDEFINED on error.  */
80575fd0b74Schristos 
80675fd0b74Schristos extern int
80775fd0b74Schristos xtensa_funcUnit_num_copies (xtensa_isa isa, xtensa_funcUnit fun);
80875fd0b74Schristos 
80975fd0b74Schristos 
81075fd0b74Schristos #ifdef __cplusplus
81175fd0b74Schristos }
81275fd0b74Schristos #endif
81375fd0b74Schristos #endif /* XTENSA_LIBISA_H */
814