qemu/target/xtensa/xtensa-isa-internal.h
<<
>>
Prefs
   1/* Internal definitions for the Xtensa ISA library.
   2 *
   3 * Copyright (c) 2004-2011 Tensilica Inc.
   4 *
   5 * Permission is hereby granted, free of charge, to any person obtaining
   6 * a copy of this software and associated documentation files (the
   7 * "Software"), to deal in the Software without restriction, including
   8 * without limitation the rights to use, copy, modify, merge, publish,
   9 * distribute, sublicense, and/or sell copies of the Software, and to
  10 * permit persons to whom the Software is furnished to do so, subject to
  11 * the following conditions:
  12 *
  13 * The above copyright notice and this permission notice shall be included
  14 * in all copies or substantial portions of the Software.
  15 *
  16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23 */
  24
  25#ifndef XTENSA_ISA_INTERNAL_H
  26#define XTENSA_ISA_INTERNAL_H
  27
  28#ifndef uint32
  29#define uint32 uint32_t
  30#endif
  31
  32/* Flags. */
  33
  34#define XTENSA_OPERAND_IS_REGISTER      0x00000001
  35#define XTENSA_OPERAND_IS_PCRELATIVE    0x00000002
  36#define XTENSA_OPERAND_IS_INVISIBLE     0x00000004
  37#define XTENSA_OPERAND_IS_UNKNOWN       0x00000008
  38
  39#define XTENSA_OPCODE_IS_BRANCH         0x00000001
  40#define XTENSA_OPCODE_IS_JUMP           0x00000002
  41#define XTENSA_OPCODE_IS_LOOP           0x00000004
  42#define XTENSA_OPCODE_IS_CALL           0x00000008
  43
  44#define XTENSA_STATE_IS_EXPORTED        0x00000001
  45#define XTENSA_STATE_IS_SHARED_OR       0x00000002
  46
  47#define XTENSA_INTERFACE_HAS_SIDE_EFFECT 0x00000001
  48
  49/* Function pointer typedefs */
  50typedef void (*xtensa_format_encode_fn)(xtensa_insnbuf);
  51typedef void (*xtensa_get_slot_fn)(const xtensa_insnbuf, xtensa_insnbuf);
  52typedef void (*xtensa_set_slot_fn)(xtensa_insnbuf, const xtensa_insnbuf);
  53typedef int (*xtensa_opcode_decode_fn)(const xtensa_insnbuf);
  54typedef uint32_t (*xtensa_get_field_fn)(const xtensa_insnbuf);
  55typedef void (*xtensa_set_field_fn)(xtensa_insnbuf, uint32_t);
  56typedef int (*xtensa_immed_decode_fn)(uint32_t *);
  57typedef int (*xtensa_immed_encode_fn)(uint32_t *);
  58typedef int (*xtensa_do_reloc_fn)(uint32_t *, uint32_t);
  59typedef int (*xtensa_undo_reloc_fn)(uint32_t *, uint32_t);
  60typedef void (*xtensa_opcode_encode_fn)(xtensa_insnbuf);
  61typedef int (*xtensa_format_decode_fn)(const xtensa_insnbuf);
  62typedef int (*xtensa_length_decode_fn)(const unsigned char *);
  63
  64typedef struct xtensa_format_internal_struct {
  65    const char *name;           /* Instruction format name. */
  66    int length;                 /* Instruction length in bytes. */
  67    xtensa_format_encode_fn encode_fn;
  68    int num_slots;
  69    int *slot_id;               /* Array[num_slots] of slot IDs. */
  70} xtensa_format_internal;
  71
  72typedef struct xtensa_slot_internal_struct {
  73    const char *name;                   /* Not necessarily unique. */
  74    const char *format;
  75    int position;
  76    xtensa_get_slot_fn get_fn;
  77    xtensa_set_slot_fn set_fn;
  78    xtensa_get_field_fn *get_field_fns; /* Array[field_id]. */
  79    xtensa_set_field_fn *set_field_fns; /* Array[field_id]. */
  80    xtensa_opcode_decode_fn opcode_decode_fn;
  81    const char *nop_name;
  82} xtensa_slot_internal;
  83
  84typedef struct xtensa_operand_internal_struct {
  85    const char *name;
  86    int field_id;
  87    xtensa_regfile regfile;             /* Register file. */
  88    int num_regs;                       /* Usually 1; 2 for reg pairs, etc. */
  89    uint32_t flags;                     /* See XTENSA_OPERAND_* flags. */
  90    xtensa_immed_encode_fn encode;      /* Encode the operand value. */
  91    xtensa_immed_decode_fn decode;      /* Decode the value from the field. */
  92    xtensa_do_reloc_fn do_reloc;        /* Perform a PC-relative reloc. */
  93    xtensa_undo_reloc_fn undo_reloc;    /* Undo a PC-relative relocation. */
  94} xtensa_operand_internal;
  95
  96typedef struct xtensa_arg_internal_struct {
  97    union {
  98        int operand_id;         /* For normal operands. */
  99        xtensa_state state;     /* For stateOperands. */
 100    } u;
 101    char inout;                 /* Direction: 'i', 'o', or 'm'. */
 102} xtensa_arg_internal;
 103
 104typedef struct xtensa_iclass_internal_struct {
 105    int num_operands;           /* Size of "operands" array. */
 106    xtensa_arg_internal *operands;          /* Array[num_operands]. */
 107
 108    int num_stateOperands;      /* Size of "stateOperands" array. */
 109    xtensa_arg_internal *stateOperands;     /* Array[num_stateOperands]. */
 110
 111    int num_interfaceOperands;  /* Size of "interfaceOperands". */
 112    xtensa_interface *interfaceOperands;    /* Array[num_interfaceOperands]. */
 113} xtensa_iclass_internal;
 114
 115typedef struct xtensa_opcode_internal_struct {
 116    const char *name;           /* Opcode mnemonic. */
 117    int iclass_id;              /* Iclass for this opcode. */
 118    uint32_t flags;             /* See XTENSA_OPCODE_* flags. */
 119    xtensa_opcode_encode_fn *encode_fns;    /* Array[slot_id]. */
 120    int num_funcUnit_uses;      /* Number of funcUnit_use entries. */
 121    xtensa_funcUnit_use *funcUnit_uses;     /* Array[num_funcUnit_uses]. */
 122} xtensa_opcode_internal;
 123
 124typedef struct xtensa_regfile_internal_struct {
 125    const char *name;           /* Full name of the regfile. */
 126    const char *shortname;      /* Abbreviated name. */
 127    xtensa_regfile parent;      /* View parent (or identity). */
 128    int num_bits;               /* Width of the registers. */
 129    int num_entries;            /* Number of registers. */
 130} xtensa_regfile_internal;
 131
 132typedef struct xtensa_interface_internal_struct {
 133    const char *name;           /* Interface name. */
 134    int num_bits;               /* Width of the interface. */
 135    uint32_t flags;             /* See XTENSA_INTERFACE_* flags. */
 136    int class_id;               /* Class of related interfaces. */
 137    char inout;                 /* "i" or "o". */
 138} xtensa_interface_internal;
 139
 140typedef struct xtensa_funcUnit_internal_struct {
 141    const char *name;           /* Functional unit name. */
 142    int num_copies;             /* Number of instances. */
 143} xtensa_funcUnit_internal;
 144
 145typedef struct xtensa_state_internal_struct {
 146    const char *name;           /* State name. */
 147    int num_bits;               /* Number of state bits. */
 148    uint32_t flags;             /* See XTENSA_STATE_* flags. */
 149} xtensa_state_internal;
 150
 151typedef struct xtensa_sysreg_internal_struct {
 152    const char *name;           /* Register name. */
 153    int number;                 /* Register number. */
 154    int is_user;                /* Non-zero if a "user register". */
 155} xtensa_sysreg_internal;
 156
 157typedef struct xtensa_lookup_entry_struct {
 158    const char *key;
 159    union {
 160        xtensa_opcode opcode;   /* Internal opcode number. */
 161        xtensa_sysreg sysreg;   /* Internal sysreg number. */
 162        xtensa_state state;     /* Internal state number. */
 163        xtensa_interface intf;  /* Internal interface number. */
 164        xtensa_funcUnit fun;    /* Internal funcUnit number. */
 165    } u;
 166} xtensa_lookup_entry;
 167
 168typedef struct xtensa_isa_internal_struct {
 169    int is_big_endian;          /* Endianness. */
 170    int insn_size;              /* Maximum length in bytes. */
 171    int insnbuf_size;           /* Number of insnbuf_words. */
 172
 173    int num_formats;
 174    xtensa_format_internal *formats;
 175    xtensa_format_decode_fn format_decode_fn;
 176    xtensa_length_decode_fn length_decode_fn;
 177
 178    int num_slots;
 179    xtensa_slot_internal *slots;
 180
 181    int num_fields;
 182
 183    int num_operands;
 184    xtensa_operand_internal *operands;
 185
 186    int num_iclasses;
 187    xtensa_iclass_internal *iclasses;
 188
 189    int num_opcodes;
 190    xtensa_opcode_internal *opcodes;
 191    xtensa_lookup_entry *opname_lookup_table;
 192
 193    int num_regfiles;
 194    xtensa_regfile_internal *regfiles;
 195
 196    int num_states;
 197    xtensa_state_internal *states;
 198    xtensa_lookup_entry *state_lookup_table;
 199
 200    int num_sysregs;
 201    xtensa_sysreg_internal *sysregs;
 202    xtensa_lookup_entry *sysreg_lookup_table;
 203
 204    /*
 205     * The current Xtensa ISA only supports 256 of each kind of sysreg so
 206     * we can get away with implementing lookups with tables indexed by
 207     * the register numbers. If we ever allow larger sysreg numbers, this
 208     * may have to be reimplemented. The first entry in the following
 209     * arrays corresponds to "special" registers and the second to "user"
 210     * registers.
 211     */
 212    int max_sysreg_num[2];
 213    xtensa_sysreg *sysreg_table[2];
 214
 215    int num_interfaces;
 216    xtensa_interface_internal *interfaces;
 217    xtensa_lookup_entry *interface_lookup_table;
 218
 219    int num_funcUnits;
 220    xtensa_funcUnit_internal *funcUnits;
 221    xtensa_lookup_entry *funcUnit_lookup_table;
 222
 223    int num_stages;             /* Number of pipe stages. */
 224} xtensa_isa_internal;
 225
 226int xtensa_isa_name_compare(const void *, const void *);
 227
 228extern xtensa_isa_status xtisa_errno;
 229extern char xtisa_error_msg[];
 230
 231#endif /* XTENSA_ISA_INTERNAL_H */
 232