1c5dff60aSchristos /* TI C6X opcode information. 2*1424dfb3Schristos Copyright (C) 2010-2020 Free Software Foundation, Inc. 3c5dff60aSchristos 4c5dff60aSchristos This program is free software; you can redistribute it and/or modify 5c5dff60aSchristos it under the terms of the GNU General Public License as published by 6c5dff60aSchristos the Free Software Foundation; either version 3 of the License, or 7c5dff60aSchristos (at your option) any later version. 8c5dff60aSchristos 9c5dff60aSchristos This program is distributed in the hope that it will be useful, 10c5dff60aSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 11c5dff60aSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12c5dff60aSchristos GNU General Public License for more details. 13c5dff60aSchristos 14c5dff60aSchristos You should have received a copy of the GNU General Public License 15c5dff60aSchristos along with this program; if not, write to the Free Software 16c5dff60aSchristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 17c5dff60aSchristos MA 02110-1301, USA. */ 18c5dff60aSchristos 19c5dff60aSchristos #ifndef OPCODE_TIC6X_H 20c5dff60aSchristos #define OPCODE_TIC6X_H 21c5dff60aSchristos 22c5dff60aSchristos #include "bfd.h" 23c5dff60aSchristos #include "symcat.h" 24c5dff60aSchristos 25c03b94e9Schristos #ifdef __cplusplus 26c03b94e9Schristos extern "C" { 27c03b94e9Schristos #endif 28c03b94e9Schristos 29c5dff60aSchristos /* A field in an instruction format. The names are based on those 30c5dff60aSchristos used in the architecture manuals. */ 31c5dff60aSchristos typedef enum 32c5dff60aSchristos { 33c5dff60aSchristos tic6x_field_baseR, 347af5a897Schristos tic6x_field_cc, 35c5dff60aSchristos tic6x_field_creg, 36c5dff60aSchristos tic6x_field_cst, 37c5dff60aSchristos tic6x_field_csta, 38c5dff60aSchristos tic6x_field_cstb, 39c5dff60aSchristos tic6x_field_dst, 407af5a897Schristos tic6x_field_dstms, 417af5a897Schristos tic6x_field_dw, 42c5dff60aSchristos tic6x_field_fstgfcyc, 43c5dff60aSchristos tic6x_field_h, 447af5a897Schristos tic6x_field_ii, 45c5dff60aSchristos tic6x_field_mask, 46c5dff60aSchristos tic6x_field_mode, 477af5a897Schristos tic6x_field_n, 487af5a897Schristos tic6x_field_na, 49c5dff60aSchristos tic6x_field_offsetR, 50c5dff60aSchristos tic6x_field_op, 51c5dff60aSchristos tic6x_field_p, 527af5a897Schristos tic6x_field_ptr, 53c5dff60aSchristos tic6x_field_r, 54c5dff60aSchristos tic6x_field_s, 55c5dff60aSchristos tic6x_field_sc, 56c5dff60aSchristos tic6x_field_src, 57c5dff60aSchristos tic6x_field_src1, 58c5dff60aSchristos tic6x_field_src2, 59c5dff60aSchristos tic6x_field_srcdst, 607af5a897Schristos tic6x_field_srcms, 617af5a897Schristos tic6x_field_sn, 627af5a897Schristos tic6x_field_sz, 637af5a897Schristos tic6x_field_unit, 647af5a897Schristos tic6x_field_t, 65c5dff60aSchristos tic6x_field_x, 66c5dff60aSchristos tic6x_field_y, 67c5dff60aSchristos tic6x_field_z 68c5dff60aSchristos } tic6x_insn_field_id; 69c5dff60aSchristos 70c5dff60aSchristos typedef struct 71c5dff60aSchristos { 72c5dff60aSchristos /* The least-significant bit position in the field. */ 73c5dff60aSchristos unsigned short low_pos; 74c5dff60aSchristos 75c5dff60aSchristos /* The number of bits in the field. */ 76c5dff60aSchristos unsigned short width; 777af5a897Schristos /* The position of the bitfield in the field. */ 787af5a897Schristos unsigned short pos; 797af5a897Schristos } tic6x_bitfield; 807af5a897Schristos 817af5a897Schristos /* Maximum number of subfields in composite field. */ 827af5a897Schristos #define TIC6X_MAX_BITFIELDS 4 837af5a897Schristos 847af5a897Schristos typedef struct 857af5a897Schristos { 867af5a897Schristos /* The name used to reference the field. */ 877af5a897Schristos tic6x_insn_field_id field_id; 887af5a897Schristos unsigned int num_bitfields; 897af5a897Schristos tic6x_bitfield bitfields[TIC6X_MAX_BITFIELDS]; 90c5dff60aSchristos } tic6x_insn_field; 91c5dff60aSchristos 92c5dff60aSchristos /* Maximum number of variable fields in an instruction format. */ 93c5dff60aSchristos #define TIC6X_MAX_INSN_FIELDS 11 94c5dff60aSchristos 95c5dff60aSchristos /* A particular instruction format. */ 96c5dff60aSchristos typedef struct 97c5dff60aSchristos { 98c5dff60aSchristos /* How many bits in the instruction. */ 99c5dff60aSchristos unsigned int num_bits; 100c5dff60aSchristos 101c5dff60aSchristos /* Constant bits in the instruction. */ 102c5dff60aSchristos unsigned int cst_bits; 103c5dff60aSchristos 104c5dff60aSchristos /* Mask matching those bits. */ 105c5dff60aSchristos unsigned int mask; 106c5dff60aSchristos 107c5dff60aSchristos /* The number of instruction fields. */ 108c5dff60aSchristos unsigned int num_fields; 109c5dff60aSchristos 110c5dff60aSchristos /* Descriptions of instruction fields. */ 111c5dff60aSchristos tic6x_insn_field fields[TIC6X_MAX_INSN_FIELDS]; 112c5dff60aSchristos } tic6x_insn_format; 113c5dff60aSchristos 114c5dff60aSchristos /* An index into the table of instruction formats. */ 115c5dff60aSchristos typedef enum 116c5dff60aSchristos { 117c5dff60aSchristos #define FMT(name, num_bits, cst_bits, mask, fields) \ 118c5dff60aSchristos CONCAT2(tic6x_insn_format_, name), 119c5dff60aSchristos #include "tic6x-insn-formats.h" 120c5dff60aSchristos #undef FMT 121c5dff60aSchristos tic6x_insn_format_max 122c5dff60aSchristos } tic6x_insn_format_id; 123c5dff60aSchristos 124c5dff60aSchristos /* The table itself. */ 125c5dff60aSchristos extern const tic6x_insn_format tic6x_insn_format_table[tic6x_insn_format_max]; 126c5dff60aSchristos 127c5dff60aSchristos /* If instruction format FMT has a field FIELD, return a pointer to 128c5dff60aSchristos the description of that field; otherwise return NULL. */ 129c5dff60aSchristos 130c5dff60aSchristos const tic6x_insn_field *tic6x_field_from_fmt (const tic6x_insn_format *fmt, 131c5dff60aSchristos tic6x_insn_field_id field); 132c5dff60aSchristos 133c5dff60aSchristos /* Description of a field (in an instruction format) whose value is 134c5dff60aSchristos fixed, or constrained to be in a particular range, in a particular 135c5dff60aSchristos opcode. */ 136c5dff60aSchristos typedef struct 137c5dff60aSchristos { 138c5dff60aSchristos /* The name of the field. */ 139c5dff60aSchristos tic6x_insn_field_id field_id; 140c5dff60aSchristos 141c5dff60aSchristos /* The least value of the field in this instruction. */ 142c5dff60aSchristos unsigned int min_val; 143c5dff60aSchristos 144c5dff60aSchristos /* The greatest value of the field in this instruction. */ 145c5dff60aSchristos unsigned int max_val; 146c5dff60aSchristos } tic6x_fixed_field; 147c5dff60aSchristos 1487af5a897Schristos /* Pseudo opcode fields position for compact instructions 1497af5a897Schristos If 16 bits instruction detected, the opcode is enriched 1507af5a897Schristos [DSZ/3][BR][SAT][opcode] */ 1517af5a897Schristos #define TIC6X_COMPACT_SAT_POS 16 1527af5a897Schristos #define TIC6X_COMPACT_BR_POS 17 1537af5a897Schristos #define TIC6X_COMPACT_DSZ_POS 18 1547af5a897Schristos 155c5dff60aSchristos /* Bit-masks for defining instructions present on some subset of 156c5dff60aSchristos processors; each indicates an instruction present on that processor 157c5dff60aSchristos and those that are supersets of it. The options passed to the 158c5dff60aSchristos assembler determine a bit-mask ANDed with the bit-mask indicating 159c5dff60aSchristos when the instruction was added to determine whether the instruction 160c5dff60aSchristos is enabled. */ 161c5dff60aSchristos #define TIC6X_INSN_C62X 0x0001 162c5dff60aSchristos #define TIC6X_INSN_C64X 0x0002 163c5dff60aSchristos #define TIC6X_INSN_C64XP 0x0004 164c5dff60aSchristos #define TIC6X_INSN_C67X 0x0008 165c5dff60aSchristos #define TIC6X_INSN_C67XP 0x0010 166c5dff60aSchristos #define TIC6X_INSN_C674X 0x0020 167c5dff60aSchristos 168c5dff60aSchristos /* Flags with further information about an opcode table entry. */ 169c5dff60aSchristos 170c5dff60aSchristos /* Only used by the assembler, not the disassembler. */ 171c5dff60aSchristos #define TIC6X_FLAG_MACRO 0x0001 172c5dff60aSchristos 173c5dff60aSchristos /* Must be first in its execute packet. */ 174c5dff60aSchristos #define TIC6X_FLAG_FIRST 0x0002 175c5dff60aSchristos 176c5dff60aSchristos /* Multi-cycle NOP (not used for the NOP n instruction itself, which 177c5dff60aSchristos is only a multicycle NOP if n > 1). */ 178c5dff60aSchristos #define TIC6X_FLAG_MCNOP 0x0004 179c5dff60aSchristos 180c5dff60aSchristos /* Cannot be in parallel with a multi-cycle NOP. */ 181c5dff60aSchristos #define TIC6X_FLAG_NO_MCNOP 0x0008 182c5dff60aSchristos 183c5dff60aSchristos /* Load instruction. */ 184c5dff60aSchristos #define TIC6X_FLAG_LOAD 0x0010 185c5dff60aSchristos 186c5dff60aSchristos /* Store instruction. */ 187c5dff60aSchristos #define TIC6X_FLAG_STORE 0x0020 188c5dff60aSchristos 189c5dff60aSchristos /* Unaligned memory operation. */ 190c5dff60aSchristos #define TIC6X_FLAG_UNALIGNED 0x0040 191c5dff60aSchristos 192c5dff60aSchristos /* Only on side B. */ 193c5dff60aSchristos #define TIC6X_FLAG_SIDE_B_ONLY 0x0080 194c5dff60aSchristos 195c5dff60aSchristos /* Only on data path T2. */ 196c5dff60aSchristos #define TIC6X_FLAG_SIDE_T2_ONLY 0x0100 197c5dff60aSchristos 198c5dff60aSchristos /* Does not support cross paths. */ 199c5dff60aSchristos #define TIC6X_FLAG_NO_CROSS 0x0200 200c5dff60aSchristos 201c5dff60aSchristos /* Annotate this branch instruction as a call. */ 202c5dff60aSchristos #define TIC6X_FLAG_CALL 0x0400 203c5dff60aSchristos 204c5dff60aSchristos /* Annotate this branch instruction as a return. */ 205c5dff60aSchristos #define TIC6X_FLAG_RETURN 0x0800 206c5dff60aSchristos 207c5dff60aSchristos /* This instruction starts a software pipelined loop. */ 208c5dff60aSchristos #define TIC6X_FLAG_SPLOOP 0x1000 209c5dff60aSchristos 210c5dff60aSchristos /* This instruction ends a software pipelined loop. */ 211c5dff60aSchristos #define TIC6X_FLAG_SPKERNEL 0x2000 212c5dff60aSchristos 213c5dff60aSchristos /* This instruction takes a list of functional units as parameters; 214c5dff60aSchristos although described as having one parameter, the number may be 0 to 215c5dff60aSchristos 8. */ 216c5dff60aSchristos #define TIC6X_FLAG_SPMASK 0x4000 217c5dff60aSchristos 218c5dff60aSchristos /* When more than one opcode matches the assembly source, prefer the 219c5dff60aSchristos one with the highest value for this bit-field. If two opcode table 220c5dff60aSchristos entries can match the same syntactic form, they must have different 221c5dff60aSchristos values here. */ 222c5dff60aSchristos #define TIC6X_PREFER_VAL(n) (((n) & 0x8000) >> 15) 223c5dff60aSchristos #define TIC6X_FLAG_PREFER(n) ((n) << 15) 2247af5a897Schristos 2257af5a897Schristos /* 16 bits opcode is predicated by register a0 (s = 0) or b0 (s = 1) */ 2267af5a897Schristos #define TIC6X_FLAG_INSN16_SPRED 0x00100000 2277af5a897Schristos /* 16 bits opcode ignores RS bit of fetch packet header */ 2287af5a897Schristos #define TIC6X_FLAG_INSN16_NORS 0x00200000 2297af5a897Schristos /* 16 bits opcode only on side B */ 2307af5a897Schristos #define TIC6X_FLAG_INSN16_BSIDE 0x00400000 2317af5a897Schristos /* 16 bits opcode ptr reg is b15 */ 2327af5a897Schristos #define TIC6X_FLAG_INSN16_B15PTR 0x00800000 2337af5a897Schristos /* 16 bits opcode memory access modes */ 2347af5a897Schristos #define TIC6X_INSN16_MEM_MODE(n) ((n) << 16) 2357af5a897Schristos #define TIC6X_INSN16_MEM_MODE_VAL(n) (((n) & 0x000F0000) >> 16) 2367af5a897Schristos #define TIC6X_MEM_MODE_NEGATIVE 0 2377af5a897Schristos #define TIC6X_MEM_MODE_POSITIVE 1 2387af5a897Schristos #define TIC6X_MEM_MODE_REG_NEGATIVE 4 2397af5a897Schristos #define TIC6X_MEM_MODE_REG_POSITIVE 5 2407af5a897Schristos #define TIC6X_MEM_MODE_PREDECR 8 2417af5a897Schristos #define TIC6X_MEM_MODE_PREINCR 9 2427af5a897Schristos #define TIC6X_MEM_MODE_POSTDECR 10 2437af5a897Schristos #define TIC6X_MEM_MODE_POSTINCR 11 2447af5a897Schristos 2457af5a897Schristos #define TIC6X_FLAG_INSN16_MEM_MODE(mode) TIC6X_INSN16_MEM_MODE(TIC6X_MEM_MODE_##mode) 2467af5a897Schristos 247c5dff60aSchristos #define TIC6X_NUM_PREFER 2 248c5dff60aSchristos 249c5dff60aSchristos /* Maximum number of fixed fields for a particular opcode. */ 250c5dff60aSchristos #define TIC6X_MAX_FIXED_FIELDS 4 251c5dff60aSchristos 252c5dff60aSchristos /* Maximum number of operands in the opcode table for a particular 253c5dff60aSchristos opcode. */ 254c5dff60aSchristos #define TIC6X_MAX_OPERANDS 4 255c5dff60aSchristos 256c5dff60aSchristos /* Maximum number of operands in the source code for a particular 257c5dff60aSchristos opcode (different from the number in the opcode table for SPMASK 258c5dff60aSchristos and SPMASKR). */ 259c5dff60aSchristos #define TIC6X_MAX_SOURCE_OPERANDS 8 260c5dff60aSchristos 261c5dff60aSchristos /* Maximum number of variable fields for a particular opcode. */ 262c5dff60aSchristos #define TIC6X_MAX_VAR_FIELDS 7 263c5dff60aSchristos 264c5dff60aSchristos /* Which functional units an opcode uses. This only describes the 265c5dff60aSchristos basic choice of D, L, M, S or no functional unit; other fields are 266c5dff60aSchristos used to describe further restrictions (instructions only operating 267c5dff60aSchristos on one side), use of cross paths and load/store instructions using 268c5dff60aSchristos one side for the address and the other side for the source or 269c5dff60aSchristos destination register. */ 270c5dff60aSchristos typedef enum 271c5dff60aSchristos { 272c5dff60aSchristos tic6x_func_unit_d, 273c5dff60aSchristos tic6x_func_unit_l, 274c5dff60aSchristos tic6x_func_unit_m, 275c5dff60aSchristos tic6x_func_unit_s, 276c5dff60aSchristos tic6x_func_unit_nfu 277c5dff60aSchristos } tic6x_func_unit_base; 278c5dff60aSchristos 279c5dff60aSchristos /* Possible forms of source operand. */ 280c5dff60aSchristos typedef enum 281c5dff60aSchristos { 282c5dff60aSchristos /* An assembly-time constant. */ 283c5dff60aSchristos tic6x_operand_asm_const, 284c5dff60aSchristos /* A link-time constant. */ 285c5dff60aSchristos tic6x_operand_link_const, 286c5dff60aSchristos /* A register, from the same side as the functional unit 287c5dff60aSchristos selected. */ 288c5dff60aSchristos tic6x_operand_reg, 2897af5a897Schristos /* A register, from the same side as the functional unit 2907af5a897Schristos selected that ignore RS header bit */ 2917af5a897Schristos tic6x_operand_reg_nors, 2927af5a897Schristos /* A register, from the b side */ 2937af5a897Schristos tic6x_operand_reg_bside, 2947af5a897Schristos /* A register, from the b side and from the low register set */ 2957af5a897Schristos tic6x_operand_reg_bside_nors, 296c5dff60aSchristos /* A register, that is from the other side if a cross path is 297c5dff60aSchristos used. */ 298c5dff60aSchristos tic6x_operand_xreg, 299c5dff60aSchristos /* A register, that is from the side of the data path 300c5dff60aSchristos selected. */ 301c5dff60aSchristos tic6x_operand_dreg, 302c5dff60aSchristos /* An address register usable with 15-bit offsets (B14 or B15). 303c5dff60aSchristos This is from the same side as the functional unit if a cross 304c5dff60aSchristos path is not used, and the other side if a cross path is 305c5dff60aSchristos used. */ 306c5dff60aSchristos tic6x_operand_areg, 3077af5a897Schristos /* The B15 register */ 3087af5a897Schristos tic6x_operand_b15reg, 3097af5a897Schristos /* A register coded as an offset from either A16 or B16 depending 3107af5a897Schristos on the value of the t bit. */ 3117af5a897Schristos tic6x_operand_treg, 3127af5a897Schristos /* A register (A0 or B0), from the same side as the 3137af5a897Schristos functional unit selected. */ 3147af5a897Schristos tic6x_operand_zreg, 315c5dff60aSchristos /* A return address register (A3 or B3), from the same side as the 316c5dff60aSchristos functional unit selected. */ 317c5dff60aSchristos tic6x_operand_retreg, 318c5dff60aSchristos /* A register pair, from the same side as the functional unit 319c5dff60aSchristos selected. */ 320c5dff60aSchristos tic6x_operand_regpair, 321c5dff60aSchristos /* A register pair, that is from the other side if a cross path is 322c5dff60aSchristos used. */ 323c5dff60aSchristos tic6x_operand_xregpair, 324c5dff60aSchristos /* A register pair, from the side of the data path selected. */ 325c5dff60aSchristos tic6x_operand_dregpair, 3267af5a897Schristos /* A register pair coded as an offset from either A16 or B16 depending 3277af5a897Schristos on the value of the t bit. */ 3287af5a897Schristos tic6x_operand_tregpair, 329c5dff60aSchristos /* The literal string "irp" (case-insensitive). */ 330c5dff60aSchristos tic6x_operand_irp, 331c5dff60aSchristos /* The literal string "nrp" (case-insensitive). */ 332c5dff60aSchristos tic6x_operand_nrp, 3337af5a897Schristos /* The literal string "ilc" (case-insensitive). */ 3347af5a897Schristos tic6x_operand_ilc, 335c5dff60aSchristos /* A control register. */ 336c5dff60aSchristos tic6x_operand_ctrl, 337c5dff60aSchristos /* A memory reference (base and offset registers from the side of 338c5dff60aSchristos the functional unit selected), using either unsigned 5-bit 339c5dff60aSchristos constant or register offset, if any offset; register offsets 340c5dff60aSchristos cannot use unscaled () syntax. */ 341c5dff60aSchristos tic6x_operand_mem_short, 342c5dff60aSchristos /* A memory reference (base and offset registers from the side of 343c5dff60aSchristos the functional unit selected), using either unsigned 5-bit 344c5dff60aSchristos constant or register offset, if any offset; register offsets 345c5dff60aSchristos can use unscaled () syntax (for LDNDW and STNDW). */ 346c5dff60aSchristos tic6x_operand_mem_ndw, 347c5dff60aSchristos /* A memory reference using 15-bit link-time constant offset 348c5dff60aSchristos relative to B14 or B15. */ 349c5dff60aSchristos tic6x_operand_mem_long, 350c5dff60aSchristos /* A memory reference that only dereferences a register with no 351c5dff60aSchristos further adjustments (*REG), that register being from the side 352c5dff60aSchristos of the functional unit selected. */ 353c5dff60aSchristos tic6x_operand_mem_deref, 354c5dff60aSchristos /* A functional unit name or a list thereof (for SPMASK and 355c5dff60aSchristos SPMASKR). */ 3567af5a897Schristos tic6x_operand_func_unit, 3577af5a897Schristos /* Hardwired constant '5' in Sbu8 Scs10 and Sbu8c 16 bits 3587af5a897Schristos instruction formats - spru732j.pdf Appendix F.4 */ 3597af5a897Schristos tic6x_operand_hw_const_minus_1, 3607af5a897Schristos tic6x_operand_hw_const_0, 3617af5a897Schristos tic6x_operand_hw_const_1, 3627af5a897Schristos tic6x_operand_hw_const_5, 3637af5a897Schristos tic6x_operand_hw_const_16, 3647af5a897Schristos tic6x_operand_hw_const_24, 3657af5a897Schristos tic6x_operand_hw_const_31 366c5dff60aSchristos } tic6x_operand_form; 367c5dff60aSchristos 368c5dff60aSchristos /* Whether something is, or can be, read or written. */ 369c5dff60aSchristos typedef enum 370c5dff60aSchristos { 371c5dff60aSchristos tic6x_rw_none, 372c5dff60aSchristos tic6x_rw_read, 373c5dff60aSchristos tic6x_rw_write, 374c5dff60aSchristos tic6x_rw_read_write 375c5dff60aSchristos } tic6x_rw; 376c5dff60aSchristos 377c5dff60aSchristos /* Description of a source operand and how it is used. */ 378c5dff60aSchristos typedef struct 379c5dff60aSchristos { 380c5dff60aSchristos /* The syntactic form of the operand. */ 381c5dff60aSchristos tic6x_operand_form form; 382c5dff60aSchristos 383c5dff60aSchristos /* For non-constant operands, the size in bytes (1, 2, 4, 5 or 384c5dff60aSchristos 8). Ignored for constant operands. */ 385c5dff60aSchristos unsigned int size; 386c5dff60aSchristos 387c5dff60aSchristos /* Whether the operand is read, written or both. In addition to the 388c5dff60aSchristos operations described here, address registers are read on cycle 1 389c5dff60aSchristos regardless of when the memory operand is read or written, and may 390c5dff60aSchristos be modified as described by the addressing mode, and control 391c5dff60aSchristos registers may be implicitly read by some instructions. There are 392c5dff60aSchristos also some special cases not fully described by this 393c5dff60aSchristos structure. 394c5dff60aSchristos 395c5dff60aSchristos - For mpydp, the low part of src2 is read on cycles 1 and 3 but 396c5dff60aSchristos not 2, and the high part on cycles 2 and 4 but not 3. 397c5dff60aSchristos 398c5dff60aSchristos - The swap2 pseudo-operation maps to packlh2, reading the first 399c5dff60aSchristos operand of swap2 twice. */ 400c5dff60aSchristos tic6x_rw rw; 401c5dff60aSchristos 402c5dff60aSchristos /* The first and last cycles (1 for E1, etc.) at which the operand, 403c5dff60aSchristos or the low part for two-register operands, is read or 404c5dff60aSchristos written. */ 405c5dff60aSchristos unsigned short low_first; 406c5dff60aSchristos unsigned short low_last; 407c5dff60aSchristos 408c5dff60aSchristos /* Likewise, for the high part. */ 409c5dff60aSchristos unsigned short high_first; 410c5dff60aSchristos unsigned short high_last; 411c5dff60aSchristos } tic6x_operand_info; 412c5dff60aSchristos 413c5dff60aSchristos /* Ways of converting an operand or functional unit specifier to a 414c5dff60aSchristos field value. */ 415c5dff60aSchristos typedef enum 416c5dff60aSchristos { 417c5dff60aSchristos /* Store an unsigned assembly-time constant (which must fit) in 418c5dff60aSchristos the field. */ 419c5dff60aSchristos tic6x_coding_ucst, 420c5dff60aSchristos /* Store a signed constant (which must fit) in the field. This 421c5dff60aSchristos may be used both for assembly-time constants and for link-time 422c5dff60aSchristos constants. */ 423c5dff60aSchristos tic6x_coding_scst, 424c5dff60aSchristos /* Subtract one from an unsigned assembly-time constant (which 425c5dff60aSchristos must be strictly positive before the subtraction) and store the 426c5dff60aSchristos value (which must fit) in the field. */ 427c5dff60aSchristos tic6x_coding_ucst_minus_one, 428c5dff60aSchristos /* Negate a signed assembly-time constant, and store the result of 429c5dff60aSchristos negation (which must fit) in the field. Used only for 430c5dff60aSchristos pseudo-operations. */ 431c5dff60aSchristos tic6x_coding_scst_negate, 432c5dff60aSchristos /* Store an unsigned link-time constant, implicitly DP-relative 433c5dff60aSchristos and counting in bytes, in the field. For expression operands, 434c5dff60aSchristos assembly-time constants are encoded as-is. For memory 435c5dff60aSchristos reference operands, the offset is encoded as-is if [] syntax is 436c5dff60aSchristos used and shifted if () is used. */ 437c5dff60aSchristos tic6x_coding_ulcst_dpr_byte, 438c5dff60aSchristos /* Store an unsigned link-time constant, implicitly DP-relative 439c5dff60aSchristos and counting in half-words, in the field. For expression 440c5dff60aSchristos operands, assembly-time constants are encoded as-is. For 441c5dff60aSchristos memory reference operands, the offset is encoded as-is if [] 442c5dff60aSchristos syntax is used and shifted if () is used. */ 443c5dff60aSchristos tic6x_coding_ulcst_dpr_half, 444c5dff60aSchristos /* Store an unsigned link-time constant, implicitly DP-relative 445c5dff60aSchristos and counting in words, in the field. For expression operands, 446c5dff60aSchristos assembly-time constants are encoded as-is. For memory 447c5dff60aSchristos reference operands, the offset is encoded as-is if [] syntax is 448c5dff60aSchristos used and shifted if () is used. */ 449c5dff60aSchristos tic6x_coding_ulcst_dpr_word, 450c5dff60aSchristos /* Store the low 16 bits of a link-time constant in the field; 451c5dff60aSchristos considered unsigned for disassembly. */ 452c5dff60aSchristos tic6x_coding_lcst_low16, 453c5dff60aSchristos /* Store the high 16 bits of a link-time constant in the field; 454c5dff60aSchristos considered unsigned for disassembly. */ 455c5dff60aSchristos tic6x_coding_lcst_high16, 456c5dff60aSchristos /* Store a signed PC-relative value (address of label minus 457c5dff60aSchristos address of fetch packet containing the current instruction, 458c5dff60aSchristos counted in words) in the field. */ 459c5dff60aSchristos tic6x_coding_pcrel, 460c5dff60aSchristos /* Likewise, but counting in half-words if in a header-based fetch 461c5dff60aSchristos packet. */ 462c5dff60aSchristos tic6x_coding_pcrel_half, 4637af5a897Schristos /* Store an unsigned PC-relative value used in compact insn */ 4647af5a897Schristos tic6x_coding_pcrel_half_unsigned, 465c5dff60aSchristos /* Encode the register number (even number for a register pair) in 466c5dff60aSchristos the field. When applied to a memory reference, encode the base 467c5dff60aSchristos register. */ 468c5dff60aSchristos tic6x_coding_reg, 4697af5a897Schristos /* Encode the register-pair's lsb (even register) for instructions 4707af5a897Schristos that use src1 as port for loading lsb of double-precision 4717af5a897Schristos operand value (absdp, dpint, dpsp, dptrunc, rcpdp, rsqrdp). */ 4727af5a897Schristos tic6x_coding_regpair_lsb, 4737af5a897Schristos /* Encode the register-pair's msb (odd register), see above. */ 4747af5a897Schristos tic6x_coding_regpair_msb, 475c5dff60aSchristos /* Store 0 for register B14, 1 for register B15. When applied to 476c5dff60aSchristos a memory reference, encode the base register. */ 477c5dff60aSchristos tic6x_coding_areg, 4787af5a897Schristos /* Compact instruction offset base register */ 4797af5a897Schristos tic6x_coding_reg_ptr, 480c5dff60aSchristos /* Store the low part of a control register address. */ 481c5dff60aSchristos tic6x_coding_crlo, 482c5dff60aSchristos /* Store the high part of a control register address. */ 483c5dff60aSchristos tic6x_coding_crhi, 484c5dff60aSchristos /* Encode the even register number for a register pair, shifted 485c5dff60aSchristos right by one bit. */ 486c5dff60aSchristos tic6x_coding_reg_shift, 487c5dff60aSchristos /* Store either the offset register or the 5-bit unsigned offset 488c5dff60aSchristos for a memory reference. If an offset uses the unscaled () 489c5dff60aSchristos form, which is only permitted with constants, it is scaled 490c5dff60aSchristos according to the access size of the operand before being 491c5dff60aSchristos stored. */ 492c5dff60aSchristos tic6x_coding_mem_offset, 493c5dff60aSchristos /* Store either the offset register or the 5-bit unsigned offset 494c5dff60aSchristos for a memory reference, but with no scaling applied to the 495c5dff60aSchristos offset (for nonaligned doubleword operations). */ 496c5dff60aSchristos tic6x_coding_mem_offset_noscale, 497c5dff60aSchristos /* Store the addressing mode for a memory reference. */ 498c5dff60aSchristos tic6x_coding_mem_mode, 499c5dff60aSchristos /* Store whether a memory reference is scaled. */ 500c5dff60aSchristos tic6x_coding_scaled, 501c5dff60aSchristos /* Store the stage in an SPKERNEL instruction in the upper part of 502c5dff60aSchristos the field. */ 503c5dff60aSchristos tic6x_coding_fstg, 504c5dff60aSchristos /* Store the cycle in an SPKERNEL instruction in the lower part of 505c5dff60aSchristos the field. */ 506c5dff60aSchristos tic6x_coding_fcyc, 507c5dff60aSchristos /* Store the mask bits for functional units in the field in an 508c5dff60aSchristos SPMASK or SPMASKR instruction. */ 509c5dff60aSchristos tic6x_coding_spmask, 510c5dff60aSchristos /* Store the number of a register that is unused, or minimally 511c5dff60aSchristos used, in this execute packet. The number must be the same for 512c5dff60aSchristos all uses of this coding in a single instruction, but may be 513c5dff60aSchristos different for different instructions in the execute packet. 514c5dff60aSchristos This is for the "zero" pseudo-operation. This is not safe when 515c5dff60aSchristos reads may occur from instructions in previous execute packets; 516c5dff60aSchristos in such cases the programmer or compiler should use explicit 517c5dff60aSchristos "sub" instructions for those cases of "zero" that cannot be 518c5dff60aSchristos implemented as "mvk" for the processor specified. */ 519c5dff60aSchristos tic6x_coding_reg_unused, 520c5dff60aSchristos /* Store 1 if the functional unit used is on side B, 0 for side 521c5dff60aSchristos A. */ 522c5dff60aSchristos tic6x_coding_fu, 523c5dff60aSchristos /* Store 1 if the data path used (source register for store, 524c5dff60aSchristos destination for load) is on side B, 0 for side A. */ 525c5dff60aSchristos tic6x_coding_data_fu, 526c5dff60aSchristos /* Store 1 if the cross path is being used, 0 otherwise. */ 5277af5a897Schristos tic6x_coding_xpath, 5287af5a897Schristos /* L3i constant coding */ 5297af5a897Schristos tic6x_coding_scst_l3i, 5307af5a897Schristos /* S3i constant coding */ 5317af5a897Schristos tic6x_coding_cst_s3i, 5327af5a897Schristos /* mem offset minus 1 */ 5337af5a897Schristos tic6x_coding_mem_offset_minus_one, 5347af5a897Schristos /* non aligned mem offset minus 1 */ 5357af5a897Schristos tic6x_coding_mem_offset_minus_one_noscale, 5367af5a897Schristos tic6x_coding_rside 537c5dff60aSchristos } tic6x_coding_method; 538c5dff60aSchristos 539c5dff60aSchristos /* How to generate the value of a particular field. */ 540c5dff60aSchristos typedef struct 541c5dff60aSchristos { 542c5dff60aSchristos /* The name of the field. */ 543c5dff60aSchristos tic6x_insn_field_id field_id; 544c5dff60aSchristos 545c5dff60aSchristos /* How it is encoded. */ 546c5dff60aSchristos tic6x_coding_method coding_method; 547c5dff60aSchristos 548c5dff60aSchristos /* Source operand number, if any. */ 549c5dff60aSchristos unsigned int operand_num; 550c5dff60aSchristos } tic6x_coding_field; 551c5dff60aSchristos 552c5dff60aSchristos /* Types of instruction for pipeline purposes. The type determines 553c5dff60aSchristos functional unit and cross path latency (when the same functional 554c5dff60aSchristos unit can be used by other instructions, when the same cross path 555c5dff60aSchristos can be used by other instructions). */ 556c5dff60aSchristos typedef enum 557c5dff60aSchristos { 558c5dff60aSchristos tic6x_pipeline_nop, 559c5dff60aSchristos tic6x_pipeline_1cycle, 560c5dff60aSchristos tic6x_pipeline_1616_m, 561c5dff60aSchristos tic6x_pipeline_store, 562c5dff60aSchristos tic6x_pipeline_mul_ext, 563c5dff60aSchristos tic6x_pipeline_load, 564c5dff60aSchristos tic6x_pipeline_branch, 565c5dff60aSchristos tic6x_pipeline_2cycle_dp, 566c5dff60aSchristos tic6x_pipeline_4cycle, 567c5dff60aSchristos tic6x_pipeline_intdp, 568c5dff60aSchristos tic6x_pipeline_dpcmp, 569c5dff60aSchristos tic6x_pipeline_addsubdp, 570c5dff60aSchristos tic6x_pipeline_mpyi, 571c5dff60aSchristos tic6x_pipeline_mpyid, 572c5dff60aSchristos tic6x_pipeline_mpydp, 573c5dff60aSchristos tic6x_pipeline_mpyspdp, 574c5dff60aSchristos tic6x_pipeline_mpysp2dp 575c5dff60aSchristos } tic6x_pipeline_type; 576c5dff60aSchristos 577c5dff60aSchristos /* Description of a control register. */ 578c5dff60aSchristos typedef struct 579c5dff60aSchristos { 580c5dff60aSchristos /* The name of the register. */ 581c5dff60aSchristos const char *name; 582c5dff60aSchristos 583c5dff60aSchristos /* Which ISA variants include this control register. */ 584c5dff60aSchristos unsigned short isa_variants; 585c5dff60aSchristos 586c5dff60aSchristos /* Whether it can be read, written or both (in supervisor mode). 587c5dff60aSchristos Some registers use the same address, but different names, for 588c5dff60aSchristos reading and writing. */ 589c5dff60aSchristos tic6x_rw rw; 590c5dff60aSchristos 591c5dff60aSchristos /* crlo value for this register. */ 592c5dff60aSchristos unsigned int crlo; 593c5dff60aSchristos 594c5dff60aSchristos /* Mask that, ANDed with the crhi value in the instruction, must be 595c5dff60aSchristos 0. 0 is always generated when generating code. */ 596c5dff60aSchristos unsigned int crhi_mask; 597c5dff60aSchristos } tic6x_ctrl; 598c5dff60aSchristos 599c5dff60aSchristos /* An index into the table of control registers. */ 600c5dff60aSchristos typedef enum 601c5dff60aSchristos { 602c5dff60aSchristos #define CTRL(name, isa, rw, crlo, crhi_mask) \ 603c5dff60aSchristos CONCAT2(tic6x_ctrl_,name), 604c5dff60aSchristos #include "tic6x-control-registers.h" 605c5dff60aSchristos #undef CTRL 606c5dff60aSchristos tic6x_ctrl_max 607c5dff60aSchristos } tic6x_ctrl_id; 608c5dff60aSchristos 609c5dff60aSchristos /* The table itself. */ 610c5dff60aSchristos extern const tic6x_ctrl tic6x_ctrl_table[tic6x_ctrl_max]; 611c5dff60aSchristos 612c5dff60aSchristos /* An entry in the opcode table. */ 613c5dff60aSchristos typedef struct 614c5dff60aSchristos { 615c5dff60aSchristos /* The name of the instruction. */ 616c5dff60aSchristos const char *name; 617c5dff60aSchristos 618c5dff60aSchristos /* Functional unit used by this instruction (basic information). */ 619c5dff60aSchristos tic6x_func_unit_base func_unit; 620c5dff60aSchristos 621c5dff60aSchristos /* The format of this instruction. */ 622c5dff60aSchristos tic6x_insn_format_id format; 623c5dff60aSchristos 624c5dff60aSchristos /* The pipeline type of this instruction. */ 625c5dff60aSchristos tic6x_pipeline_type type; 626c5dff60aSchristos 627c5dff60aSchristos /* Which ISA variants include this instruction. */ 628c5dff60aSchristos unsigned short isa_variants; 629c5dff60aSchristos 630c5dff60aSchristos /* Flags for this instruction. */ 6317af5a897Schristos unsigned int flags; 632c5dff60aSchristos 633c5dff60aSchristos /* Number of fixed fields, or fields with restricted value ranges, 634c5dff60aSchristos for this instruction. */ 635c5dff60aSchristos unsigned int num_fixed_fields; 636c5dff60aSchristos 637c5dff60aSchristos /* Values of fields fixed for this instruction. */ 638c5dff60aSchristos tic6x_fixed_field fixed_fields[TIC6X_MAX_FIXED_FIELDS]; 639c5dff60aSchristos 640c5dff60aSchristos /* The number of operands in the source form of this 641c5dff60aSchristos instruction. */ 642c5dff60aSchristos unsigned int num_operands; 643c5dff60aSchristos 644c5dff60aSchristos /* Information about individual operands. */ 645c5dff60aSchristos tic6x_operand_info operand_info[TIC6X_MAX_OPERANDS]; 646c5dff60aSchristos 647c5dff60aSchristos /* The number of variable fields for this instruction with encoding 648c5dff60aSchristos instructions explicitly given. */ 649c5dff60aSchristos unsigned int num_variable_fields; 650c5dff60aSchristos 651c5dff60aSchristos /* How fields (other than ones with fixed value) are computed from 652c5dff60aSchristos the source operands and functional unit specifiers. In addition 653c5dff60aSchristos to fields specified here: 654c5dff60aSchristos 655c5dff60aSchristos - creg, if present, is set from the predicate, along with z which 656c5dff60aSchristos must be present if creg is present. 657c5dff60aSchristos 658c5dff60aSchristos - p, if present (on all non-compact instructions), is set from 659c5dff60aSchristos the parallel bars. 660c5dff60aSchristos */ 661c5dff60aSchristos tic6x_coding_field variable_fields[TIC6X_MAX_VAR_FIELDS]; 662c5dff60aSchristos } tic6x_opcode; 663c5dff60aSchristos 664c5dff60aSchristos /* An index into the table of opcodes. */ 665c5dff60aSchristos typedef enum 666c5dff60aSchristos { 667c5dff60aSchristos #define INSN(name, func_unit, format, type, isa, flags, fixed, ops, var) \ 668c5dff60aSchristos CONCAT6(tic6x_opcode_,name,_,func_unit,_,format), 669c5dff60aSchristos #define INSNE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \ 670c5dff60aSchristos CONCAT4(tic6x_opcode_,name,_,e), 6717af5a897Schristos #define INSNU(name, func_unit, format, type, isa, flags, fixed, ops, var) \ 6727af5a897Schristos CONCAT6(tic6x_opcode_,name,_,func_unit,_,format), 6737af5a897Schristos #define INSNUE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \ 6747af5a897Schristos CONCAT6(tic6x_opcode_,name,_,func_unit,_,e), 675c5dff60aSchristos #include "tic6x-opcode-table.h" 676c5dff60aSchristos #undef INSN 677c5dff60aSchristos #undef INSNE 6787af5a897Schristos #undef INSNU 6797af5a897Schristos #undef INSNUE 680c5dff60aSchristos tic6x_opcode_max 681c5dff60aSchristos } tic6x_opcode_id; 682c5dff60aSchristos 683c5dff60aSchristos /* The table itself. */ 684c5dff60aSchristos extern const tic6x_opcode tic6x_opcode_table[tic6x_opcode_max]; 685c5dff60aSchristos 686c5dff60aSchristos /* A linked list of opcodes. */ 687c5dff60aSchristos typedef struct tic6x_opcode_list_tag 688c5dff60aSchristos { 689c5dff60aSchristos tic6x_opcode_id id; 690c5dff60aSchristos struct tic6x_opcode_list_tag *next; 691c5dff60aSchristos } tic6x_opcode_list; 692c5dff60aSchristos 693c5dff60aSchristos /* The information from a fetch packet header. */ 694c5dff60aSchristos typedef struct 695c5dff60aSchristos { 696c5dff60aSchristos /* The header itself. */ 697c5dff60aSchristos unsigned int header; 698c5dff60aSchristos 699c5dff60aSchristos /* Whether each word uses compact instructions. */ 700c5dff60aSchristos bfd_boolean word_compact[7]; 701c5dff60aSchristos 702c5dff60aSchristos /* Whether loads are protected. */ 703c5dff60aSchristos bfd_boolean prot; 704c5dff60aSchristos 705c5dff60aSchristos /* Whether instructions use the high register set. */ 706c5dff60aSchristos bfd_boolean rs; 707c5dff60aSchristos 708c5dff60aSchristos /* Data size. */ 709c5dff60aSchristos unsigned int dsz; 710c5dff60aSchristos 711c5dff60aSchristos /* Whether compact instructions in the S unit are decoded as 712c5dff60aSchristos branches. */ 713c5dff60aSchristos bfd_boolean br; 714c5dff60aSchristos 715c5dff60aSchristos /* Whether compact instructions saturate. */ 716c5dff60aSchristos bfd_boolean sat; 717c5dff60aSchristos 718c5dff60aSchristos /* P-bits. */ 719c5dff60aSchristos bfd_boolean p_bits[14]; 720c5dff60aSchristos } tic6x_fetch_packet_header; 721c5dff60aSchristos 722c03b94e9Schristos #ifdef __cplusplus 723c03b94e9Schristos } 724c03b94e9Schristos #endif 725c03b94e9Schristos 726c5dff60aSchristos #endif /* OPCODE_TIC6X_H */ 727