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