xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/tic6x.h (revision aab831cebf6361fb2b518a47c70732e608d9abd2)
198b9484cSchristos /* TI C6X opcode information.
2*aab831ceSchristos    Copyright (C) 2010-2024 Free Software Foundation, Inc.
398b9484cSchristos 
498b9484cSchristos    This program is free software; you can redistribute it and/or modify
598b9484cSchristos    it under the terms of the GNU General Public License as published by
698b9484cSchristos    the Free Software Foundation; either version 3 of the License, or
798b9484cSchristos    (at your option) any later version.
898b9484cSchristos 
998b9484cSchristos    This program is distributed in the hope that it will be useful,
1098b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1198b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1298b9484cSchristos    GNU General Public License for more details.
1398b9484cSchristos 
1498b9484cSchristos    You should have received a copy of the GNU General Public License
1598b9484cSchristos    along with this program; if not, write to the Free Software
1698b9484cSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1798b9484cSchristos    MA 02110-1301, USA.  */
1898b9484cSchristos 
1998b9484cSchristos #ifndef OPCODE_TIC6X_H
2098b9484cSchristos #define OPCODE_TIC6X_H
2198b9484cSchristos 
2298b9484cSchristos #include "bfd.h"
2398b9484cSchristos #include "symcat.h"
2498b9484cSchristos 
25ba340e45Schristos #ifdef __cplusplus
26ba340e45Schristos extern "C" {
27ba340e45Schristos #endif
28ba340e45Schristos 
2998b9484cSchristos /* A field in an instruction format.  The names are based on those
3098b9484cSchristos    used in the architecture manuals.  */
3198b9484cSchristos typedef enum
3298b9484cSchristos   {
3398b9484cSchristos     tic6x_field_baseR,
3403467a24Schristos     tic6x_field_cc,
3598b9484cSchristos     tic6x_field_creg,
3698b9484cSchristos     tic6x_field_cst,
3798b9484cSchristos     tic6x_field_csta,
3898b9484cSchristos     tic6x_field_cstb,
3998b9484cSchristos     tic6x_field_dst,
4003467a24Schristos     tic6x_field_dstms,
4103467a24Schristos     tic6x_field_dw,
4298b9484cSchristos     tic6x_field_fstgfcyc,
4398b9484cSchristos     tic6x_field_h,
4403467a24Schristos     tic6x_field_ii,
4598b9484cSchristos     tic6x_field_mask,
4698b9484cSchristos     tic6x_field_mode,
4703467a24Schristos     tic6x_field_n,
4803467a24Schristos     tic6x_field_na,
4998b9484cSchristos     tic6x_field_offsetR,
5098b9484cSchristos     tic6x_field_op,
5198b9484cSchristos     tic6x_field_p,
5203467a24Schristos     tic6x_field_ptr,
5398b9484cSchristos     tic6x_field_r,
5498b9484cSchristos     tic6x_field_s,
5598b9484cSchristos     tic6x_field_sc,
5698b9484cSchristos     tic6x_field_src,
5798b9484cSchristos     tic6x_field_src1,
5898b9484cSchristos     tic6x_field_src2,
5998b9484cSchristos     tic6x_field_srcdst,
6003467a24Schristos     tic6x_field_srcms,
6103467a24Schristos     tic6x_field_sn,
6203467a24Schristos     tic6x_field_sz,
6303467a24Schristos     tic6x_field_unit,
6403467a24Schristos     tic6x_field_t,
6598b9484cSchristos     tic6x_field_x,
6698b9484cSchristos     tic6x_field_y,
6798b9484cSchristos     tic6x_field_z
6898b9484cSchristos   } tic6x_insn_field_id;
6998b9484cSchristos 
7098b9484cSchristos typedef struct
7198b9484cSchristos {
7298b9484cSchristos   /* The least-significant bit position in the field.  */
7398b9484cSchristos   unsigned short low_pos;
7498b9484cSchristos 
7598b9484cSchristos   /* The number of bits in the field.  */
7698b9484cSchristos   unsigned short width;
7703467a24Schristos   /* The position of the bitfield in the field. */
7803467a24Schristos   unsigned short pos;
7903467a24Schristos } tic6x_bitfield;
8003467a24Schristos 
8103467a24Schristos /* Maximum number of subfields in composite field.  */
8203467a24Schristos #define TIC6X_MAX_BITFIELDS 4
8303467a24Schristos 
8403467a24Schristos typedef struct
8503467a24Schristos {
8603467a24Schristos   /* The name used to reference the field.  */
8703467a24Schristos   tic6x_insn_field_id field_id;
8803467a24Schristos   unsigned int num_bitfields;
8903467a24Schristos   tic6x_bitfield bitfields[TIC6X_MAX_BITFIELDS];
9098b9484cSchristos } tic6x_insn_field;
9198b9484cSchristos 
9298b9484cSchristos /* Maximum number of variable fields in an instruction format.  */
9398b9484cSchristos #define TIC6X_MAX_INSN_FIELDS 11
9498b9484cSchristos 
9598b9484cSchristos /* A particular instruction format.  */
9698b9484cSchristos typedef struct
9798b9484cSchristos {
9898b9484cSchristos   /* How many bits in the instruction.  */
9998b9484cSchristos   unsigned int num_bits;
10098b9484cSchristos 
10198b9484cSchristos   /* Constant bits in the instruction.  */
10298b9484cSchristos   unsigned int cst_bits;
10398b9484cSchristos 
10498b9484cSchristos   /* Mask matching those bits.  */
10598b9484cSchristos   unsigned int mask;
10698b9484cSchristos 
10798b9484cSchristos   /* The number of instruction fields.  */
10898b9484cSchristos   unsigned int num_fields;
10998b9484cSchristos 
11098b9484cSchristos   /* Descriptions of instruction fields.  */
11198b9484cSchristos   tic6x_insn_field fields[TIC6X_MAX_INSN_FIELDS];
11298b9484cSchristos } tic6x_insn_format;
11398b9484cSchristos 
11498b9484cSchristos /* An index into the table of instruction formats.  */
11598b9484cSchristos typedef enum
11698b9484cSchristos   {
11798b9484cSchristos #define FMT(name, num_bits, cst_bits, mask, fields)	\
11898b9484cSchristos   CONCAT2(tic6x_insn_format_, name),
11998b9484cSchristos #include "tic6x-insn-formats.h"
12098b9484cSchristos #undef FMT
12198b9484cSchristos     tic6x_insn_format_max
12298b9484cSchristos   } tic6x_insn_format_id;
12398b9484cSchristos 
12498b9484cSchristos /* The table itself.  */
12598b9484cSchristos extern const tic6x_insn_format tic6x_insn_format_table[tic6x_insn_format_max];
12698b9484cSchristos 
12798b9484cSchristos /* If instruction format FMT has a field FIELD, return a pointer to
12898b9484cSchristos    the description of that field; otherwise return NULL.  */
12998b9484cSchristos 
13098b9484cSchristos const tic6x_insn_field *tic6x_field_from_fmt (const tic6x_insn_format *fmt,
13198b9484cSchristos 					      tic6x_insn_field_id field);
13298b9484cSchristos 
13398b9484cSchristos /* Description of a field (in an instruction format) whose value is
13498b9484cSchristos    fixed, or constrained to be in a particular range, in a particular
13598b9484cSchristos    opcode.  */
13698b9484cSchristos typedef struct
13798b9484cSchristos {
13898b9484cSchristos   /* The name of the field.  */
13998b9484cSchristos   tic6x_insn_field_id field_id;
14098b9484cSchristos 
14198b9484cSchristos   /* The least value of the field in this instruction.  */
14298b9484cSchristos   unsigned int min_val;
14398b9484cSchristos 
14498b9484cSchristos   /* The greatest value of the field in this instruction.  */
14598b9484cSchristos   unsigned int max_val;
14698b9484cSchristos } tic6x_fixed_field;
14798b9484cSchristos 
14803467a24Schristos /* Pseudo opcode fields position for compact instructions
14903467a24Schristos    If 16 bits instruction detected, the opcode is enriched
15003467a24Schristos    [DSZ/3][BR][SAT][opcode] */
15103467a24Schristos #define TIC6X_COMPACT_SAT_POS 16
15203467a24Schristos #define TIC6X_COMPACT_BR_POS 17
15303467a24Schristos #define TIC6X_COMPACT_DSZ_POS 18
15403467a24Schristos 
15598b9484cSchristos /* Bit-masks for defining instructions present on some subset of
15698b9484cSchristos    processors; each indicates an instruction present on that processor
15798b9484cSchristos    and those that are supersets of it.  The options passed to the
15898b9484cSchristos    assembler determine a bit-mask ANDed with the bit-mask indicating
15998b9484cSchristos    when the instruction was added to determine whether the instruction
16098b9484cSchristos    is enabled.  */
16198b9484cSchristos #define TIC6X_INSN_C62X		0x0001
16298b9484cSchristos #define TIC6X_INSN_C64X		0x0002
16398b9484cSchristos #define TIC6X_INSN_C64XP	0x0004
16498b9484cSchristos #define TIC6X_INSN_C67X		0x0008
16598b9484cSchristos #define TIC6X_INSN_C67XP	0x0010
16698b9484cSchristos #define TIC6X_INSN_C674X	0x0020
16798b9484cSchristos 
16898b9484cSchristos /* Flags with further information about an opcode table entry.  */
16998b9484cSchristos 
17098b9484cSchristos /* Only used by the assembler, not the disassembler.  */
17198b9484cSchristos #define TIC6X_FLAG_MACRO	0x0001
17298b9484cSchristos 
17398b9484cSchristos /* Must be first in its execute packet.  */
17498b9484cSchristos #define TIC6X_FLAG_FIRST	0x0002
17598b9484cSchristos 
17698b9484cSchristos /* Multi-cycle NOP (not used for the NOP n instruction itself, which
17798b9484cSchristos    is only a multicycle NOP if n > 1).  */
17898b9484cSchristos #define TIC6X_FLAG_MCNOP	0x0004
17998b9484cSchristos 
18098b9484cSchristos /* Cannot be in parallel with a multi-cycle NOP.  */
18198b9484cSchristos #define TIC6X_FLAG_NO_MCNOP	0x0008
18298b9484cSchristos 
18398b9484cSchristos /* Load instruction.  */
18498b9484cSchristos #define TIC6X_FLAG_LOAD		0x0010
18598b9484cSchristos 
18698b9484cSchristos /* Store instruction.  */
18798b9484cSchristos #define TIC6X_FLAG_STORE	0x0020
18898b9484cSchristos 
18998b9484cSchristos /* Unaligned memory operation.  */
19098b9484cSchristos #define TIC6X_FLAG_UNALIGNED	0x0040
19198b9484cSchristos 
19298b9484cSchristos /* Only on side B.  */
19398b9484cSchristos #define TIC6X_FLAG_SIDE_B_ONLY	0x0080
19498b9484cSchristos 
19598b9484cSchristos /* Only on data path T2.  */
19698b9484cSchristos #define TIC6X_FLAG_SIDE_T2_ONLY	0x0100
19798b9484cSchristos 
19898b9484cSchristos /* Does not support cross paths.  */
19998b9484cSchristos #define TIC6X_FLAG_NO_CROSS	0x0200
20098b9484cSchristos 
20198b9484cSchristos /* Annotate this branch instruction as a call.  */
20298b9484cSchristos #define TIC6X_FLAG_CALL		0x0400
20398b9484cSchristos 
20498b9484cSchristos /* Annotate this branch instruction as a return.  */
20598b9484cSchristos #define TIC6X_FLAG_RETURN	0x0800
20698b9484cSchristos 
20798b9484cSchristos /* This instruction starts a software pipelined loop.  */
20898b9484cSchristos #define TIC6X_FLAG_SPLOOP	0x1000
20998b9484cSchristos 
21098b9484cSchristos /* This instruction ends a software pipelined loop.  */
21198b9484cSchristos #define TIC6X_FLAG_SPKERNEL	0x2000
21298b9484cSchristos 
21398b9484cSchristos /* This instruction takes a list of functional units as parameters;
21498b9484cSchristos    although described as having one parameter, the number may be 0 to
21598b9484cSchristos    8.  */
21698b9484cSchristos #define TIC6X_FLAG_SPMASK	0x4000
21798b9484cSchristos 
21898b9484cSchristos /* When more than one opcode matches the assembly source, prefer the
21998b9484cSchristos    one with the highest value for this bit-field.  If two opcode table
22098b9484cSchristos    entries can match the same syntactic form, they must have different
22198b9484cSchristos    values here.  */
22298b9484cSchristos #define TIC6X_PREFER_VAL(n)	(((n) & 0x8000) >> 15)
22398b9484cSchristos #define TIC6X_FLAG_PREFER(n)	((n) << 15)
22403467a24Schristos 
22503467a24Schristos /* 16 bits opcode is predicated by register a0 (s = 0) or b0 (s = 1) */
22603467a24Schristos #define TIC6X_FLAG_INSN16_SPRED      0x00100000
22703467a24Schristos /* 16 bits opcode ignores RS bit of fetch packet header */
22803467a24Schristos #define TIC6X_FLAG_INSN16_NORS       0x00200000
22903467a24Schristos /* 16 bits opcode only on side B */
23003467a24Schristos #define TIC6X_FLAG_INSN16_BSIDE      0x00400000
23103467a24Schristos /* 16 bits opcode ptr reg is b15 */
23203467a24Schristos #define TIC6X_FLAG_INSN16_B15PTR     0x00800000
23303467a24Schristos /* 16 bits opcode memory access modes */
23403467a24Schristos #define TIC6X_INSN16_MEM_MODE(n)           ((n) << 16)
23503467a24Schristos #define TIC6X_INSN16_MEM_MODE_VAL(n) (((n) & 0x000F0000) >> 16)
23603467a24Schristos #define TIC6X_MEM_MODE_NEGATIVE      0
23703467a24Schristos #define TIC6X_MEM_MODE_POSITIVE      1
23803467a24Schristos #define TIC6X_MEM_MODE_REG_NEGATIVE  4
23903467a24Schristos #define TIC6X_MEM_MODE_REG_POSITIVE  5
24003467a24Schristos #define TIC6X_MEM_MODE_PREDECR       8
24103467a24Schristos #define TIC6X_MEM_MODE_PREINCR       9
24203467a24Schristos #define TIC6X_MEM_MODE_POSTDECR      10
24303467a24Schristos #define TIC6X_MEM_MODE_POSTINCR      11
24403467a24Schristos 
24503467a24Schristos #define TIC6X_FLAG_INSN16_MEM_MODE(mode) TIC6X_INSN16_MEM_MODE(TIC6X_MEM_MODE_##mode)
24603467a24Schristos 
24798b9484cSchristos #define TIC6X_NUM_PREFER	2
24898b9484cSchristos 
24998b9484cSchristos /* Maximum number of fixed fields for a particular opcode.  */
25098b9484cSchristos #define TIC6X_MAX_FIXED_FIELDS 4
25198b9484cSchristos 
25298b9484cSchristos /* Maximum number of operands in the opcode table for a particular
25398b9484cSchristos    opcode.  */
25498b9484cSchristos #define TIC6X_MAX_OPERANDS 4
25598b9484cSchristos 
25698b9484cSchristos /* Maximum number of operands in the source code for a particular
25798b9484cSchristos    opcode (different from the number in the opcode table for SPMASK
25898b9484cSchristos    and SPMASKR).  */
25998b9484cSchristos #define TIC6X_MAX_SOURCE_OPERANDS 8
26098b9484cSchristos 
26198b9484cSchristos /* Maximum number of variable fields for a particular opcode.  */
26298b9484cSchristos #define TIC6X_MAX_VAR_FIELDS 7
26398b9484cSchristos 
26498b9484cSchristos /* Which functional units an opcode uses.  This only describes the
26598b9484cSchristos    basic choice of D, L, M, S or no functional unit; other fields are
26698b9484cSchristos    used to describe further restrictions (instructions only operating
26798b9484cSchristos    on one side), use of cross paths and load/store instructions using
26898b9484cSchristos    one side for the address and the other side for the source or
26998b9484cSchristos    destination register.  */
27098b9484cSchristos typedef enum
27198b9484cSchristos   {
27298b9484cSchristos     tic6x_func_unit_d,
27398b9484cSchristos     tic6x_func_unit_l,
27498b9484cSchristos     tic6x_func_unit_m,
27598b9484cSchristos     tic6x_func_unit_s,
27698b9484cSchristos     tic6x_func_unit_nfu
27798b9484cSchristos   } tic6x_func_unit_base;
27898b9484cSchristos 
27998b9484cSchristos /* Possible forms of source operand.  */
28098b9484cSchristos typedef enum
28198b9484cSchristos   {
28298b9484cSchristos     /* An assembly-time constant.  */
28398b9484cSchristos     tic6x_operand_asm_const,
28498b9484cSchristos     /* A link-time constant.  */
28598b9484cSchristos     tic6x_operand_link_const,
28698b9484cSchristos     /* A register, from the same side as the functional unit
28798b9484cSchristos        selected.  */
28898b9484cSchristos     tic6x_operand_reg,
28903467a24Schristos     /* A register, from the same side as the functional unit
29003467a24Schristos        selected that ignore RS header bit */
29103467a24Schristos     tic6x_operand_reg_nors,
29203467a24Schristos     /* A register, from the b side */
29303467a24Schristos     tic6x_operand_reg_bside,
29403467a24Schristos     /* A register, from the b side and from the low register set */
29503467a24Schristos     tic6x_operand_reg_bside_nors,
29698b9484cSchristos     /* A register, that is from the other side if a cross path is
29798b9484cSchristos        used.  */
29898b9484cSchristos     tic6x_operand_xreg,
29998b9484cSchristos     /* A register, that is from the side of the data path
30098b9484cSchristos        selected.  */
30198b9484cSchristos     tic6x_operand_dreg,
30298b9484cSchristos     /* An address register usable with 15-bit offsets (B14 or B15).
30398b9484cSchristos        This is from the same side as the functional unit if a cross
30498b9484cSchristos        path is not used, and the other side if a cross path is
30598b9484cSchristos        used.  */
30698b9484cSchristos     tic6x_operand_areg,
30703467a24Schristos     /* The B15 register */
30803467a24Schristos     tic6x_operand_b15reg,
30903467a24Schristos     /* A register coded as an offset from either A16 or B16 depending
31003467a24Schristos        on the value of the t bit. */
31103467a24Schristos     tic6x_operand_treg,
31203467a24Schristos     /* A register (A0 or B0), from the same side as the
31303467a24Schristos        functional unit selected.  */
31403467a24Schristos     tic6x_operand_zreg,
31598b9484cSchristos     /* A return address register (A3 or B3), from the same side as the
31698b9484cSchristos        functional unit selected.  */
31798b9484cSchristos     tic6x_operand_retreg,
31898b9484cSchristos     /* A register pair, from the same side as the functional unit
31998b9484cSchristos        selected.  */
32098b9484cSchristos     tic6x_operand_regpair,
32198b9484cSchristos     /* A register pair, that is from the other side if a cross path is
32298b9484cSchristos        used.  */
32398b9484cSchristos     tic6x_operand_xregpair,
32498b9484cSchristos     /* A register pair, from the side of the data path selected.  */
32598b9484cSchristos     tic6x_operand_dregpair,
32603467a24Schristos     /* A register pair coded as an offset from either A16 or B16 depending
32703467a24Schristos        on the value of the t bit. */
32803467a24Schristos     tic6x_operand_tregpair,
32998b9484cSchristos     /* The literal string "irp" (case-insensitive).  */
33098b9484cSchristos     tic6x_operand_irp,
33198b9484cSchristos     /* The literal string "nrp" (case-insensitive).  */
33298b9484cSchristos     tic6x_operand_nrp,
33303467a24Schristos     /* The literal string "ilc" (case-insensitive).  */
33403467a24Schristos 	tic6x_operand_ilc,
33598b9484cSchristos     /* A control register.  */
33698b9484cSchristos     tic6x_operand_ctrl,
33798b9484cSchristos     /* A memory reference (base and offset registers from the side of
33898b9484cSchristos        the functional unit selected), using either unsigned 5-bit
33998b9484cSchristos        constant or register offset, if any offset; register offsets
34098b9484cSchristos        cannot use unscaled () syntax.  */
34198b9484cSchristos     tic6x_operand_mem_short,
34298b9484cSchristos     /* A memory reference (base and offset registers from the side of
34398b9484cSchristos        the functional unit selected), using either unsigned 5-bit
34498b9484cSchristos        constant or register offset, if any offset; register offsets
34598b9484cSchristos        can use unscaled () syntax (for LDNDW and STNDW).  */
34698b9484cSchristos     tic6x_operand_mem_ndw,
34798b9484cSchristos     /* A memory reference using 15-bit link-time constant offset
34898b9484cSchristos        relative to B14 or B15.  */
34998b9484cSchristos     tic6x_operand_mem_long,
35098b9484cSchristos     /* A memory reference that only dereferences a register with no
35198b9484cSchristos        further adjustments (*REG), that register being from the side
35298b9484cSchristos        of the functional unit selected.  */
35398b9484cSchristos     tic6x_operand_mem_deref,
35498b9484cSchristos     /* A functional unit name or a list thereof (for SPMASK and
35598b9484cSchristos        SPMASKR).  */
35603467a24Schristos     tic6x_operand_func_unit,
35703467a24Schristos     /* Hardwired constant '5' in Sbu8 Scs10 and Sbu8c 16 bits
35803467a24Schristos        instruction formats - spru732j.pdf Appendix F.4 */
35903467a24Schristos     tic6x_operand_hw_const_minus_1,
36003467a24Schristos     tic6x_operand_hw_const_0,
36103467a24Schristos     tic6x_operand_hw_const_1,
36203467a24Schristos     tic6x_operand_hw_const_5,
36303467a24Schristos     tic6x_operand_hw_const_16,
36403467a24Schristos     tic6x_operand_hw_const_24,
36503467a24Schristos     tic6x_operand_hw_const_31
36698b9484cSchristos   } tic6x_operand_form;
36798b9484cSchristos 
36898b9484cSchristos /* Whether something is, or can be, read or written.  */
36998b9484cSchristos typedef enum
37098b9484cSchristos   {
37198b9484cSchristos     tic6x_rw_none,
37298b9484cSchristos     tic6x_rw_read,
37398b9484cSchristos     tic6x_rw_write,
37498b9484cSchristos     tic6x_rw_read_write
37598b9484cSchristos   } tic6x_rw;
37698b9484cSchristos 
37798b9484cSchristos /* Description of a source operand and how it is used.  */
37898b9484cSchristos typedef struct
37998b9484cSchristos {
38098b9484cSchristos   /* The syntactic form of the operand.  */
38198b9484cSchristos   tic6x_operand_form form;
38298b9484cSchristos 
38398b9484cSchristos   /* For non-constant operands, the size in bytes (1, 2, 4, 5 or
38498b9484cSchristos      8).  Ignored for constant operands.  */
38598b9484cSchristos   unsigned int size;
38698b9484cSchristos 
38798b9484cSchristos   /* Whether the operand is read, written or both.  In addition to the
38898b9484cSchristos      operations described here, address registers are read on cycle 1
38998b9484cSchristos      regardless of when the memory operand is read or written, and may
39098b9484cSchristos      be modified as described by the addressing mode, and control
39198b9484cSchristos      registers may be implicitly read by some instructions.  There are
39298b9484cSchristos      also some special cases not fully described by this
39398b9484cSchristos      structure.
39498b9484cSchristos 
39598b9484cSchristos      - For mpydp, the low part of src2 is read on cycles 1 and 3 but
39698b9484cSchristos        not 2, and the high part on cycles 2 and 4 but not 3.
39798b9484cSchristos 
39898b9484cSchristos      - The swap2 pseudo-operation maps to packlh2, reading the first
39998b9484cSchristos        operand of swap2 twice.  */
40098b9484cSchristos   tic6x_rw rw;
40198b9484cSchristos 
40298b9484cSchristos   /* The first and last cycles (1 for E1, etc.) at which the operand,
40398b9484cSchristos      or the low part for two-register operands, is read or
40498b9484cSchristos      written.  */
40598b9484cSchristos   unsigned short low_first;
40698b9484cSchristos   unsigned short low_last;
40798b9484cSchristos 
40898b9484cSchristos   /* Likewise, for the high part.  */
40998b9484cSchristos   unsigned short high_first;
41098b9484cSchristos   unsigned short high_last;
41198b9484cSchristos } tic6x_operand_info;
41298b9484cSchristos 
41398b9484cSchristos /* Ways of converting an operand or functional unit specifier to a
41498b9484cSchristos    field value.  */
41598b9484cSchristos typedef enum
41698b9484cSchristos   {
41798b9484cSchristos     /* Store an unsigned assembly-time constant (which must fit) in
41898b9484cSchristos        the field.  */
41998b9484cSchristos     tic6x_coding_ucst,
42098b9484cSchristos     /* Store a signed constant (which must fit) in the field.  This
42198b9484cSchristos        may be used both for assembly-time constants and for link-time
42298b9484cSchristos        constants.  */
42398b9484cSchristos     tic6x_coding_scst,
42498b9484cSchristos     /* Subtract one from an unsigned assembly-time constant (which
42598b9484cSchristos        must be strictly positive before the subtraction) and store the
42698b9484cSchristos        value (which must fit) in the field.  */
42798b9484cSchristos     tic6x_coding_ucst_minus_one,
42898b9484cSchristos     /* Negate a signed assembly-time constant, and store the result of
42998b9484cSchristos        negation (which must fit) in the field.  Used only for
43098b9484cSchristos        pseudo-operations.  */
43198b9484cSchristos     tic6x_coding_scst_negate,
43298b9484cSchristos     /* Store an unsigned link-time constant, implicitly DP-relative
43398b9484cSchristos        and counting in bytes, in the field.  For expression operands,
43498b9484cSchristos        assembly-time constants are encoded as-is.  For memory
43598b9484cSchristos        reference operands, the offset is encoded as-is if [] syntax is
43698b9484cSchristos        used and shifted if () is used.  */
43798b9484cSchristos     tic6x_coding_ulcst_dpr_byte,
43898b9484cSchristos     /* Store an unsigned link-time constant, implicitly DP-relative
43998b9484cSchristos        and counting in half-words, in the field.  For expression
44098b9484cSchristos        operands, assembly-time constants are encoded as-is.  For
44198b9484cSchristos        memory reference operands, the offset is encoded as-is if []
44298b9484cSchristos        syntax is used and shifted if () is used.  */
44398b9484cSchristos     tic6x_coding_ulcst_dpr_half,
44498b9484cSchristos     /* Store an unsigned link-time constant, implicitly DP-relative
44598b9484cSchristos        and counting in words, in the field.  For expression operands,
44698b9484cSchristos        assembly-time constants are encoded as-is.  For memory
44798b9484cSchristos        reference operands, the offset is encoded as-is if [] syntax is
44898b9484cSchristos        used and shifted if () is used.  */
44998b9484cSchristos     tic6x_coding_ulcst_dpr_word,
45098b9484cSchristos     /* Store the low 16 bits of a link-time constant in the field;
45198b9484cSchristos        considered unsigned for disassembly.  */
45298b9484cSchristos     tic6x_coding_lcst_low16,
45398b9484cSchristos     /* Store the high 16 bits of a link-time constant in the field;
45498b9484cSchristos        considered unsigned for disassembly.  */
45598b9484cSchristos     tic6x_coding_lcst_high16,
45698b9484cSchristos     /* Store a signed PC-relative value (address of label minus
45798b9484cSchristos        address of fetch packet containing the current instruction,
45898b9484cSchristos        counted in words) in the field.  */
45998b9484cSchristos     tic6x_coding_pcrel,
46098b9484cSchristos     /* Likewise, but counting in half-words if in a header-based fetch
46198b9484cSchristos        packet.  */
46298b9484cSchristos     tic6x_coding_pcrel_half,
46303467a24Schristos     /* Store an unsigned PC-relative value used in compact insn */
46403467a24Schristos     tic6x_coding_pcrel_half_unsigned,
46598b9484cSchristos     /* Encode the register number (even number for a register pair) in
46698b9484cSchristos        the field.  When applied to a memory reference, encode the base
46798b9484cSchristos        register.  */
46898b9484cSchristos     tic6x_coding_reg,
46903467a24Schristos     /* Encode the register-pair's lsb (even register) for instructions
47003467a24Schristos        that use src1 as port for loading lsb of double-precision
47103467a24Schristos        operand value (absdp, dpint, dpsp, dptrunc, rcpdp, rsqrdp).  */
47203467a24Schristos     tic6x_coding_regpair_lsb,
47303467a24Schristos     /* Encode the register-pair's msb (odd register), see above.  */
47403467a24Schristos     tic6x_coding_regpair_msb,
47598b9484cSchristos     /* Store 0 for register B14, 1 for register B15.  When applied to
47698b9484cSchristos        a memory reference, encode the base register.  */
47798b9484cSchristos     tic6x_coding_areg,
47803467a24Schristos     /* Compact instruction offset base register */
47903467a24Schristos     tic6x_coding_reg_ptr,
48098b9484cSchristos     /* Store the low part of a control register address.  */
48198b9484cSchristos     tic6x_coding_crlo,
48298b9484cSchristos     /* Store the high part of a control register address.  */
48398b9484cSchristos     tic6x_coding_crhi,
48498b9484cSchristos     /* Encode the even register number for a register pair, shifted
48598b9484cSchristos        right by one bit.  */
48698b9484cSchristos     tic6x_coding_reg_shift,
48798b9484cSchristos     /* Store either the offset register or the 5-bit unsigned offset
48898b9484cSchristos        for a memory reference.  If an offset uses the unscaled ()
48998b9484cSchristos        form, which is only permitted with constants, it is scaled
49098b9484cSchristos        according to the access size of the operand before being
49198b9484cSchristos        stored.  */
49298b9484cSchristos     tic6x_coding_mem_offset,
49398b9484cSchristos     /* Store either the offset register or the 5-bit unsigned offset
49498b9484cSchristos        for a memory reference, but with no scaling applied to the
49598b9484cSchristos        offset (for nonaligned doubleword operations).  */
49698b9484cSchristos     tic6x_coding_mem_offset_noscale,
49798b9484cSchristos     /* Store the addressing mode for a memory reference.  */
49898b9484cSchristos     tic6x_coding_mem_mode,
49998b9484cSchristos     /* Store whether a memory reference is scaled.  */
50098b9484cSchristos     tic6x_coding_scaled,
50198b9484cSchristos     /* Store the stage in an SPKERNEL instruction in the upper part of
50298b9484cSchristos        the field.  */
50398b9484cSchristos     tic6x_coding_fstg,
50498b9484cSchristos     /* Store the cycle in an SPKERNEL instruction in the lower part of
50598b9484cSchristos        the field.  */
50698b9484cSchristos     tic6x_coding_fcyc,
50798b9484cSchristos     /* Store the mask bits for functional units in the field in an
50898b9484cSchristos        SPMASK or SPMASKR instruction.  */
50998b9484cSchristos     tic6x_coding_spmask,
51098b9484cSchristos     /* Store the number of a register that is unused, or minimally
51198b9484cSchristos        used, in this execute packet.  The number must be the same for
51298b9484cSchristos        all uses of this coding in a single instruction, but may be
51398b9484cSchristos        different for different instructions in the execute packet.
51498b9484cSchristos        This is for the "zero" pseudo-operation.  This is not safe when
51598b9484cSchristos        reads may occur from instructions in previous execute packets;
51698b9484cSchristos        in such cases the programmer or compiler should use explicit
51798b9484cSchristos        "sub" instructions for those cases of "zero" that cannot be
51898b9484cSchristos        implemented as "mvk" for the processor specified.  */
51998b9484cSchristos     tic6x_coding_reg_unused,
52098b9484cSchristos     /* Store 1 if the functional unit used is on side B, 0 for side
52198b9484cSchristos        A.  */
52298b9484cSchristos     tic6x_coding_fu,
52398b9484cSchristos     /* Store 1 if the data path used (source register for store,
52498b9484cSchristos        destination for load) is on side B, 0 for side A.  */
52598b9484cSchristos     tic6x_coding_data_fu,
52698b9484cSchristos     /* Store 1 if the cross path is being used, 0 otherwise.  */
52703467a24Schristos     tic6x_coding_xpath,
52803467a24Schristos     /* L3i constant coding */
52903467a24Schristos     tic6x_coding_scst_l3i,
53003467a24Schristos     /* S3i constant coding */
53103467a24Schristos     tic6x_coding_cst_s3i,
53203467a24Schristos     /* mem offset minus 1 */
53303467a24Schristos     tic6x_coding_mem_offset_minus_one,
53403467a24Schristos     /* non aligned mem offset minus 1 */
53503467a24Schristos     tic6x_coding_mem_offset_minus_one_noscale,
53603467a24Schristos     tic6x_coding_rside
53798b9484cSchristos   } tic6x_coding_method;
53898b9484cSchristos 
53998b9484cSchristos /* How to generate the value of a particular field.  */
54098b9484cSchristos typedef struct
54198b9484cSchristos {
54298b9484cSchristos   /* The name of the field.  */
54398b9484cSchristos   tic6x_insn_field_id field_id;
54498b9484cSchristos 
54598b9484cSchristos   /* How it is encoded.  */
54698b9484cSchristos   tic6x_coding_method coding_method;
54798b9484cSchristos 
54898b9484cSchristos   /* Source operand number, if any.  */
54998b9484cSchristos   unsigned int operand_num;
55098b9484cSchristos } tic6x_coding_field;
55198b9484cSchristos 
55298b9484cSchristos /* Types of instruction for pipeline purposes.  The type determines
55398b9484cSchristos    functional unit and cross path latency (when the same functional
55498b9484cSchristos    unit can be used by other instructions, when the same cross path
55598b9484cSchristos    can be used by other instructions).  */
55698b9484cSchristos typedef enum
55798b9484cSchristos   {
55898b9484cSchristos     tic6x_pipeline_nop,
55998b9484cSchristos     tic6x_pipeline_1cycle,
56098b9484cSchristos     tic6x_pipeline_1616_m,
56198b9484cSchristos     tic6x_pipeline_store,
56298b9484cSchristos     tic6x_pipeline_mul_ext,
56398b9484cSchristos     tic6x_pipeline_load,
56498b9484cSchristos     tic6x_pipeline_branch,
56598b9484cSchristos     tic6x_pipeline_2cycle_dp,
56698b9484cSchristos     tic6x_pipeline_4cycle,
56798b9484cSchristos     tic6x_pipeline_intdp,
56898b9484cSchristos     tic6x_pipeline_dpcmp,
56998b9484cSchristos     tic6x_pipeline_addsubdp,
57098b9484cSchristos     tic6x_pipeline_mpyi,
57198b9484cSchristos     tic6x_pipeline_mpyid,
57298b9484cSchristos     tic6x_pipeline_mpydp,
57398b9484cSchristos     tic6x_pipeline_mpyspdp,
57498b9484cSchristos     tic6x_pipeline_mpysp2dp
57598b9484cSchristos   } tic6x_pipeline_type;
57698b9484cSchristos 
57798b9484cSchristos /* Description of a control register.  */
57898b9484cSchristos typedef struct
57998b9484cSchristos {
58098b9484cSchristos   /* The name of the register.  */
58198b9484cSchristos   const char *name;
58298b9484cSchristos 
58398b9484cSchristos   /* Which ISA variants include this control register.  */
58498b9484cSchristos   unsigned short isa_variants;
58598b9484cSchristos 
58698b9484cSchristos   /* Whether it can be read, written or both (in supervisor mode).
58798b9484cSchristos      Some registers use the same address, but different names, for
58898b9484cSchristos      reading and writing.  */
58998b9484cSchristos   tic6x_rw rw;
59098b9484cSchristos 
59198b9484cSchristos   /* crlo value for this register.  */
59298b9484cSchristos   unsigned int crlo;
59398b9484cSchristos 
59498b9484cSchristos   /* Mask that, ANDed with the crhi value in the instruction, must be
59598b9484cSchristos      0.  0 is always generated when generating code.  */
59698b9484cSchristos   unsigned int crhi_mask;
59798b9484cSchristos } tic6x_ctrl;
59898b9484cSchristos 
59998b9484cSchristos /* An index into the table of control registers.  */
60098b9484cSchristos typedef enum
60198b9484cSchristos   {
60298b9484cSchristos #define CTRL(name, isa, rw, crlo, crhi_mask)	\
60398b9484cSchristos     CONCAT2(tic6x_ctrl_,name),
60498b9484cSchristos #include "tic6x-control-registers.h"
60598b9484cSchristos #undef CTRL
60698b9484cSchristos     tic6x_ctrl_max
60798b9484cSchristos   } tic6x_ctrl_id;
60898b9484cSchristos 
60998b9484cSchristos /* The table itself.  */
61098b9484cSchristos extern const tic6x_ctrl tic6x_ctrl_table[tic6x_ctrl_max];
61198b9484cSchristos 
61298b9484cSchristos /* An entry in the opcode table.  */
61398b9484cSchristos typedef struct
61498b9484cSchristos {
61598b9484cSchristos   /* The name of the instruction.  */
61698b9484cSchristos   const char *name;
61798b9484cSchristos 
61898b9484cSchristos   /* Functional unit used by this instruction (basic information).  */
61998b9484cSchristos   tic6x_func_unit_base func_unit;
62098b9484cSchristos 
62198b9484cSchristos   /* The format of this instruction.  */
62298b9484cSchristos   tic6x_insn_format_id format;
62398b9484cSchristos 
62498b9484cSchristos   /* The pipeline type of this instruction.  */
62598b9484cSchristos   tic6x_pipeline_type type;
62698b9484cSchristos 
62798b9484cSchristos   /* Which ISA variants include this instruction.  */
62898b9484cSchristos   unsigned short isa_variants;
62998b9484cSchristos 
63098b9484cSchristos   /* Flags for this instruction.  */
63103467a24Schristos   unsigned int flags;
63298b9484cSchristos 
63398b9484cSchristos   /* Number of fixed fields, or fields with restricted value ranges,
63498b9484cSchristos      for this instruction.  */
63598b9484cSchristos   unsigned int num_fixed_fields;
63698b9484cSchristos 
63798b9484cSchristos   /* Values of fields fixed for this instruction.  */
63898b9484cSchristos   tic6x_fixed_field fixed_fields[TIC6X_MAX_FIXED_FIELDS];
63998b9484cSchristos 
64098b9484cSchristos   /* The number of operands in the source form of this
64198b9484cSchristos      instruction.  */
64298b9484cSchristos   unsigned int num_operands;
64398b9484cSchristos 
64498b9484cSchristos   /* Information about individual operands.  */
64598b9484cSchristos   tic6x_operand_info operand_info[TIC6X_MAX_OPERANDS];
64698b9484cSchristos 
64798b9484cSchristos   /* The number of variable fields for this instruction with encoding
64898b9484cSchristos      instructions explicitly given.  */
64998b9484cSchristos   unsigned int num_variable_fields;
65098b9484cSchristos 
65198b9484cSchristos   /* How fields (other than ones with fixed value) are computed from
65298b9484cSchristos      the source operands and functional unit specifiers.  In addition
65398b9484cSchristos      to fields specified here:
65498b9484cSchristos 
65598b9484cSchristos      - creg, if present, is set from the predicate, along with z which
65698b9484cSchristos        must be present if creg is present.
65798b9484cSchristos 
65898b9484cSchristos      - p, if present (on all non-compact instructions), is set from
65998b9484cSchristos        the parallel bars.
66098b9484cSchristos   */
66198b9484cSchristos   tic6x_coding_field variable_fields[TIC6X_MAX_VAR_FIELDS];
66298b9484cSchristos } tic6x_opcode;
66398b9484cSchristos 
66498b9484cSchristos /* An index into the table of opcodes.  */
66598b9484cSchristos typedef enum
66698b9484cSchristos   {
66798b9484cSchristos #define INSN(name, func_unit, format, type, isa, flags, fixed, ops, var) \
66898b9484cSchristos     CONCAT6(tic6x_opcode_,name,_,func_unit,_,format),
66998b9484cSchristos #define INSNE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \
67098b9484cSchristos     CONCAT4(tic6x_opcode_,name,_,e),
67103467a24Schristos #define INSNU(name, func_unit, format, type, isa, flags, fixed, ops, var) \
67203467a24Schristos     CONCAT6(tic6x_opcode_,name,_,func_unit,_,format),
67303467a24Schristos #define INSNUE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \
67403467a24Schristos     CONCAT6(tic6x_opcode_,name,_,func_unit,_,e),
67598b9484cSchristos #include "tic6x-opcode-table.h"
67698b9484cSchristos #undef INSN
67798b9484cSchristos #undef INSNE
67803467a24Schristos #undef INSNU
67903467a24Schristos #undef INSNUE
68098b9484cSchristos     tic6x_opcode_max
68198b9484cSchristos   } tic6x_opcode_id;
68298b9484cSchristos 
68398b9484cSchristos /* The table itself.  */
68498b9484cSchristos extern const tic6x_opcode tic6x_opcode_table[tic6x_opcode_max];
68598b9484cSchristos 
68698b9484cSchristos /* A linked list of opcodes.  */
68798b9484cSchristos typedef struct tic6x_opcode_list_tag
68898b9484cSchristos {
68998b9484cSchristos   tic6x_opcode_id id;
69098b9484cSchristos   struct tic6x_opcode_list_tag *next;
69198b9484cSchristos } tic6x_opcode_list;
69298b9484cSchristos 
69398b9484cSchristos /* The information from a fetch packet header.  */
69498b9484cSchristos typedef struct
69598b9484cSchristos {
69698b9484cSchristos   /* The header itself.  */
69798b9484cSchristos   unsigned int header;
69898b9484cSchristos 
69998b9484cSchristos   /* Whether each word uses compact instructions.  */
7004b169a6bSchristos   bool word_compact[7];
70198b9484cSchristos 
70298b9484cSchristos   /* Whether loads are protected.  */
7034b169a6bSchristos   bool prot;
70498b9484cSchristos 
70598b9484cSchristos   /* Whether instructions use the high register set.  */
7064b169a6bSchristos   bool rs;
70798b9484cSchristos 
70898b9484cSchristos   /* Data size.  */
70998b9484cSchristos   unsigned int dsz;
71098b9484cSchristos 
71198b9484cSchristos   /* Whether compact instructions in the S unit are decoded as
71298b9484cSchristos      branches.  */
7134b169a6bSchristos   bool br;
71498b9484cSchristos 
71598b9484cSchristos   /* Whether compact instructions saturate.  */
7164b169a6bSchristos   bool sat;
71798b9484cSchristos 
71898b9484cSchristos   /* P-bits.  */
7194b169a6bSchristos   bool p_bits[14];
72098b9484cSchristos } tic6x_fetch_packet_header;
72198b9484cSchristos 
722ba340e45Schristos #ifdef __cplusplus
723ba340e45Schristos }
724ba340e45Schristos #endif
725ba340e45Schristos 
72698b9484cSchristos #endif /* OPCODE_TIC6X_H */
727