1 /* TI C6X opcode information.
2 Copyright 2010-2013 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
17 MA 02110-1301, USA. */
19 #ifndef OPCODE_TIC6X_H
20 #define OPCODE_TIC6X_H
25 /* A field in an instruction format. The names are based on those
26 used in the architecture manuals. */
52 } tic6x_insn_field_id
;
56 /* The name used to reference the field. */
57 tic6x_insn_field_id field_id
;
59 /* The least-significant bit position in the field. */
60 unsigned short low_pos
;
62 /* The number of bits in the field. */
66 /* Maximum number of variable fields in an instruction format. */
67 #define TIC6X_MAX_INSN_FIELDS 11
69 /* A particular instruction format. */
72 /* How many bits in the instruction. */
73 unsigned int num_bits
;
75 /* Constant bits in the instruction. */
76 unsigned int cst_bits
;
78 /* Mask matching those bits. */
81 /* The number of instruction fields. */
82 unsigned int num_fields
;
84 /* Descriptions of instruction fields. */
85 tic6x_insn_field fields
[TIC6X_MAX_INSN_FIELDS
];
88 /* An index into the table of instruction formats. */
91 #define FMT(name, num_bits, cst_bits, mask, fields) \
92 CONCAT2(tic6x_insn_format_, name),
93 #include "tic6x-insn-formats.h"
96 } tic6x_insn_format_id
;
98 /* The table itself. */
99 extern const tic6x_insn_format tic6x_insn_format_table
[tic6x_insn_format_max
];
101 /* If instruction format FMT has a field FIELD, return a pointer to
102 the description of that field; otherwise return NULL. */
104 const tic6x_insn_field
*tic6x_field_from_fmt (const tic6x_insn_format
*fmt
,
105 tic6x_insn_field_id field
);
107 /* Description of a field (in an instruction format) whose value is
108 fixed, or constrained to be in a particular range, in a particular
112 /* The name of the field. */
113 tic6x_insn_field_id field_id
;
115 /* The least value of the field in this instruction. */
116 unsigned int min_val
;
118 /* The greatest value of the field in this instruction. */
119 unsigned int max_val
;
122 /* Bit-masks for defining instructions present on some subset of
123 processors; each indicates an instruction present on that processor
124 and those that are supersets of it. The options passed to the
125 assembler determine a bit-mask ANDed with the bit-mask indicating
126 when the instruction was added to determine whether the instruction
128 #define TIC6X_INSN_C62X 0x0001
129 #define TIC6X_INSN_C64X 0x0002
130 #define TIC6X_INSN_C64XP 0x0004
131 #define TIC6X_INSN_C67X 0x0008
132 #define TIC6X_INSN_C67XP 0x0010
133 #define TIC6X_INSN_C674X 0x0020
135 /* Flags with further information about an opcode table entry. */
137 /* Only used by the assembler, not the disassembler. */
138 #define TIC6X_FLAG_MACRO 0x0001
140 /* Must be first in its execute packet. */
141 #define TIC6X_FLAG_FIRST 0x0002
143 /* Multi-cycle NOP (not used for the NOP n instruction itself, which
144 is only a multicycle NOP if n > 1). */
145 #define TIC6X_FLAG_MCNOP 0x0004
147 /* Cannot be in parallel with a multi-cycle NOP. */
148 #define TIC6X_FLAG_NO_MCNOP 0x0008
150 /* Load instruction. */
151 #define TIC6X_FLAG_LOAD 0x0010
153 /* Store instruction. */
154 #define TIC6X_FLAG_STORE 0x0020
156 /* Unaligned memory operation. */
157 #define TIC6X_FLAG_UNALIGNED 0x0040
159 /* Only on side B. */
160 #define TIC6X_FLAG_SIDE_B_ONLY 0x0080
162 /* Only on data path T2. */
163 #define TIC6X_FLAG_SIDE_T2_ONLY 0x0100
165 /* Does not support cross paths. */
166 #define TIC6X_FLAG_NO_CROSS 0x0200
168 /* Annotate this branch instruction as a call. */
169 #define TIC6X_FLAG_CALL 0x0400
171 /* Annotate this branch instruction as a return. */
172 #define TIC6X_FLAG_RETURN 0x0800
174 /* This instruction starts a software pipelined loop. */
175 #define TIC6X_FLAG_SPLOOP 0x1000
177 /* This instruction ends a software pipelined loop. */
178 #define TIC6X_FLAG_SPKERNEL 0x2000
180 /* This instruction takes a list of functional units as parameters;
181 although described as having one parameter, the number may be 0 to
183 #define TIC6X_FLAG_SPMASK 0x4000
185 /* When more than one opcode matches the assembly source, prefer the
186 one with the highest value for this bit-field. If two opcode table
187 entries can match the same syntactic form, they must have different
189 #define TIC6X_PREFER_VAL(n) (((n) & 0x8000) >> 15)
190 #define TIC6X_FLAG_PREFER(n) ((n) << 15)
191 #define TIC6X_NUM_PREFER 2
193 /* Maximum number of fixed fields for a particular opcode. */
194 #define TIC6X_MAX_FIXED_FIELDS 4
196 /* Maximum number of operands in the opcode table for a particular
198 #define TIC6X_MAX_OPERANDS 4
200 /* Maximum number of operands in the source code for a particular
201 opcode (different from the number in the opcode table for SPMASK
203 #define TIC6X_MAX_SOURCE_OPERANDS 8
205 /* Maximum number of variable fields for a particular opcode. */
206 #define TIC6X_MAX_VAR_FIELDS 7
208 /* Which functional units an opcode uses. This only describes the
209 basic choice of D, L, M, S or no functional unit; other fields are
210 used to describe further restrictions (instructions only operating
211 on one side), use of cross paths and load/store instructions using
212 one side for the address and the other side for the source or
213 destination register. */
221 } tic6x_func_unit_base
;
223 /* Possible forms of source operand. */
226 /* An assembly-time constant. */
227 tic6x_operand_asm_const
,
228 /* A link-time constant. */
229 tic6x_operand_link_const
,
230 /* A register, from the same side as the functional unit
233 /* A register, that is from the other side if a cross path is
236 /* A register, that is from the side of the data path
239 /* An address register usable with 15-bit offsets (B14 or B15).
240 This is from the same side as the functional unit if a cross
241 path is not used, and the other side if a cross path is
244 /* A return address register (A3 or B3), from the same side as the
245 functional unit selected. */
246 tic6x_operand_retreg
,
247 /* A register pair, from the same side as the functional unit
249 tic6x_operand_regpair
,
250 /* A register pair, that is from the other side if a cross path is
252 tic6x_operand_xregpair
,
253 /* A register pair, from the side of the data path selected. */
254 tic6x_operand_dregpair
,
255 /* The literal string "irp" (case-insensitive). */
257 /* The literal string "nrp" (case-insensitive). */
259 /* A control register. */
261 /* A memory reference (base and offset registers from the side of
262 the functional unit selected), using either unsigned 5-bit
263 constant or register offset, if any offset; register offsets
264 cannot use unscaled () syntax. */
265 tic6x_operand_mem_short
,
266 /* A memory reference (base and offset registers from the side of
267 the functional unit selected), using either unsigned 5-bit
268 constant or register offset, if any offset; register offsets
269 can use unscaled () syntax (for LDNDW and STNDW). */
270 tic6x_operand_mem_ndw
,
271 /* A memory reference using 15-bit link-time constant offset
272 relative to B14 or B15. */
273 tic6x_operand_mem_long
,
274 /* A memory reference that only dereferences a register with no
275 further adjustments (*REG), that register being from the side
276 of the functional unit selected. */
277 tic6x_operand_mem_deref
,
278 /* A functional unit name or a list thereof (for SPMASK and
280 tic6x_operand_func_unit
281 } tic6x_operand_form
;
283 /* Whether something is, or can be, read or written. */
292 /* Description of a source operand and how it is used. */
295 /* The syntactic form of the operand. */
296 tic6x_operand_form form
;
298 /* For non-constant operands, the size in bytes (1, 2, 4, 5 or
299 8). Ignored for constant operands. */
302 /* Whether the operand is read, written or both. In addition to the
303 operations described here, address registers are read on cycle 1
304 regardless of when the memory operand is read or written, and may
305 be modified as described by the addressing mode, and control
306 registers may be implicitly read by some instructions. There are
307 also some special cases not fully described by this
310 - For mpydp, the low part of src2 is read on cycles 1 and 3 but
311 not 2, and the high part on cycles 2 and 4 but not 3.
313 - The swap2 pseudo-operation maps to packlh2, reading the first
314 operand of swap2 twice. */
317 /* The first and last cycles (1 for E1, etc.) at which the operand,
318 or the low part for two-register operands, is read or
320 unsigned short low_first
;
321 unsigned short low_last
;
323 /* Likewise, for the high part. */
324 unsigned short high_first
;
325 unsigned short high_last
;
326 } tic6x_operand_info
;
328 /* Ways of converting an operand or functional unit specifier to a
332 /* Store an unsigned assembly-time constant (which must fit) in
335 /* Store a signed constant (which must fit) in the field. This
336 may be used both for assembly-time constants and for link-time
339 /* Subtract one from an unsigned assembly-time constant (which
340 must be strictly positive before the subtraction) and store the
341 value (which must fit) in the field. */
342 tic6x_coding_ucst_minus_one
,
343 /* Negate a signed assembly-time constant, and store the result of
344 negation (which must fit) in the field. Used only for
345 pseudo-operations. */
346 tic6x_coding_scst_negate
,
347 /* Store an unsigned link-time constant, implicitly DP-relative
348 and counting in bytes, in the field. For expression operands,
349 assembly-time constants are encoded as-is. For memory
350 reference operands, the offset is encoded as-is if [] syntax is
351 used and shifted if () is used. */
352 tic6x_coding_ulcst_dpr_byte
,
353 /* Store an unsigned link-time constant, implicitly DP-relative
354 and counting in half-words, in the field. For expression
355 operands, assembly-time constants are encoded as-is. For
356 memory reference operands, the offset is encoded as-is if []
357 syntax is used and shifted if () is used. */
358 tic6x_coding_ulcst_dpr_half
,
359 /* Store an unsigned link-time constant, implicitly DP-relative
360 and counting in words, in the field. For expression operands,
361 assembly-time constants are encoded as-is. For memory
362 reference operands, the offset is encoded as-is if [] syntax is
363 used and shifted if () is used. */
364 tic6x_coding_ulcst_dpr_word
,
365 /* Store the low 16 bits of a link-time constant in the field;
366 considered unsigned for disassembly. */
367 tic6x_coding_lcst_low16
,
368 /* Store the high 16 bits of a link-time constant in the field;
369 considered unsigned for disassembly. */
370 tic6x_coding_lcst_high16
,
371 /* Store a signed PC-relative value (address of label minus
372 address of fetch packet containing the current instruction,
373 counted in words) in the field. */
375 /* Likewise, but counting in half-words if in a header-based fetch
377 tic6x_coding_pcrel_half
,
378 /* Encode the register number (even number for a register pair) in
379 the field. When applied to a memory reference, encode the base
382 /* Encode the register-pair's lsb (even register) for instructions
383 that use src1 as port for loading lsb of double-precision
384 operand value (absdp, dpint, dpsp, dptrunc, rcpdp, rsqrdp). */
385 tic6x_coding_regpair_lsb
,
386 /* Encode the register-pair's msb (odd register), see above. */
387 tic6x_coding_regpair_msb
,
388 /* Store 0 for register B14, 1 for register B15. When applied to
389 a memory reference, encode the base register. */
391 /* Store the low part of a control register address. */
393 /* Store the high part of a control register address. */
395 /* Encode the even register number for a register pair, shifted
397 tic6x_coding_reg_shift
,
398 /* Store either the offset register or the 5-bit unsigned offset
399 for a memory reference. If an offset uses the unscaled ()
400 form, which is only permitted with constants, it is scaled
401 according to the access size of the operand before being
403 tic6x_coding_mem_offset
,
404 /* Store either the offset register or the 5-bit unsigned offset
405 for a memory reference, but with no scaling applied to the
406 offset (for nonaligned doubleword operations). */
407 tic6x_coding_mem_offset_noscale
,
408 /* Store the addressing mode for a memory reference. */
409 tic6x_coding_mem_mode
,
410 /* Store whether a memory reference is scaled. */
412 /* Store the stage in an SPKERNEL instruction in the upper part of
415 /* Store the cycle in an SPKERNEL instruction in the lower part of
418 /* Store the mask bits for functional units in the field in an
419 SPMASK or SPMASKR instruction. */
421 /* Store the number of a register that is unused, or minimally
422 used, in this execute packet. The number must be the same for
423 all uses of this coding in a single instruction, but may be
424 different for different instructions in the execute packet.
425 This is for the "zero" pseudo-operation. This is not safe when
426 reads may occur from instructions in previous execute packets;
427 in such cases the programmer or compiler should use explicit
428 "sub" instructions for those cases of "zero" that cannot be
429 implemented as "mvk" for the processor specified. */
430 tic6x_coding_reg_unused
,
431 /* Store 1 if the functional unit used is on side B, 0 for side
434 /* Store 1 if the data path used (source register for store,
435 destination for load) is on side B, 0 for side A. */
436 tic6x_coding_data_fu
,
437 /* Store 1 if the cross path is being used, 0 otherwise. */
439 } tic6x_coding_method
;
441 /* How to generate the value of a particular field. */
444 /* The name of the field. */
445 tic6x_insn_field_id field_id
;
447 /* How it is encoded. */
448 tic6x_coding_method coding_method
;
450 /* Source operand number, if any. */
451 unsigned int operand_num
;
452 } tic6x_coding_field
;
454 /* Types of instruction for pipeline purposes. The type determines
455 functional unit and cross path latency (when the same functional
456 unit can be used by other instructions, when the same cross path
457 can be used by other instructions). */
461 tic6x_pipeline_1cycle
,
462 tic6x_pipeline_1616_m
,
463 tic6x_pipeline_store
,
464 tic6x_pipeline_mul_ext
,
466 tic6x_pipeline_branch
,
467 tic6x_pipeline_2cycle_dp
,
468 tic6x_pipeline_4cycle
,
469 tic6x_pipeline_intdp
,
470 tic6x_pipeline_dpcmp
,
471 tic6x_pipeline_addsubdp
,
473 tic6x_pipeline_mpyid
,
474 tic6x_pipeline_mpydp
,
475 tic6x_pipeline_mpyspdp
,
476 tic6x_pipeline_mpysp2dp
477 } tic6x_pipeline_type
;
479 /* Description of a control register. */
482 /* The name of the register. */
485 /* Which ISA variants include this control register. */
486 unsigned short isa_variants
;
488 /* Whether it can be read, written or both (in supervisor mode).
489 Some registers use the same address, but different names, for
490 reading and writing. */
493 /* crlo value for this register. */
496 /* Mask that, ANDed with the crhi value in the instruction, must be
497 0. 0 is always generated when generating code. */
498 unsigned int crhi_mask
;
501 /* An index into the table of control registers. */
504 #define CTRL(name, isa, rw, crlo, crhi_mask) \
505 CONCAT2(tic6x_ctrl_,name),
506 #include "tic6x-control-registers.h"
511 /* The table itself. */
512 extern const tic6x_ctrl tic6x_ctrl_table
[tic6x_ctrl_max
];
514 /* An entry in the opcode table. */
517 /* The name of the instruction. */
520 /* Functional unit used by this instruction (basic information). */
521 tic6x_func_unit_base func_unit
;
523 /* The format of this instruction. */
524 tic6x_insn_format_id format
;
526 /* The pipeline type of this instruction. */
527 tic6x_pipeline_type type
;
529 /* Which ISA variants include this instruction. */
530 unsigned short isa_variants
;
532 /* Flags for this instruction. */
533 unsigned short flags
;
535 /* Number of fixed fields, or fields with restricted value ranges,
536 for this instruction. */
537 unsigned int num_fixed_fields
;
539 /* Values of fields fixed for this instruction. */
540 tic6x_fixed_field fixed_fields
[TIC6X_MAX_FIXED_FIELDS
];
542 /* The number of operands in the source form of this
544 unsigned int num_operands
;
546 /* Information about individual operands. */
547 tic6x_operand_info operand_info
[TIC6X_MAX_OPERANDS
];
549 /* The number of variable fields for this instruction with encoding
550 instructions explicitly given. */
551 unsigned int num_variable_fields
;
553 /* How fields (other than ones with fixed value) are computed from
554 the source operands and functional unit specifiers. In addition
555 to fields specified here:
557 - creg, if present, is set from the predicate, along with z which
558 must be present if creg is present.
560 - p, if present (on all non-compact instructions), is set from
563 tic6x_coding_field variable_fields
[TIC6X_MAX_VAR_FIELDS
];
566 /* An index into the table of opcodes. */
569 #define INSN(name, func_unit, format, type, isa, flags, fixed, ops, var) \
570 CONCAT6(tic6x_opcode_,name,_,func_unit,_,format),
571 #define INSNE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \
572 CONCAT4(tic6x_opcode_,name,_,e),
573 #include "tic6x-opcode-table.h"
579 /* The table itself. */
580 extern const tic6x_opcode tic6x_opcode_table
[tic6x_opcode_max
];
582 /* A linked list of opcodes. */
583 typedef struct tic6x_opcode_list_tag
586 struct tic6x_opcode_list_tag
*next
;
589 /* The information from a fetch packet header. */
592 /* The header itself. */
595 /* Whether each word uses compact instructions. */
596 bfd_boolean word_compact
[7];
598 /* Whether loads are protected. */
601 /* Whether instructions use the high register set. */
607 /* Whether compact instructions in the S unit are decoded as
611 /* Whether compact instructions saturate. */
615 bfd_boolean p_bits
[14];
616 } tic6x_fetch_packet_header
;
618 #endif /* OPCODE_TIC6X_H */