xref: /netbsd-src/external/gpl3/gdb.old/dist/include/opcode/cris.h (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1a5a4af3bSchristos /* cris.h -- Header file for CRIS opcode and register tables.
2*8b657b07Schristos    Copyright (C) 2000-2022 Free Software Foundation, Inc.
3a5a4af3bSchristos    Contributed by Axis Communications AB, Lund, Sweden.
4a5a4af3bSchristos    Originally written for GAS 1.38.1 by Mikael Asker.
5a5a4af3bSchristos    Updated, BFDized and GNUified by Hans-Peter Nilsson.
6a5a4af3bSchristos 
7a5a4af3bSchristos    This file is part of GAS, GDB and the GNU binutils.
8a5a4af3bSchristos 
9a5a4af3bSchristos    GAS, GDB, and GNU binutils is free software; you can redistribute it
10a5a4af3bSchristos    and/or modify it under the terms of the GNU General Public License as
11a5a4af3bSchristos    published by the Free Software Foundation; either version 3, or (at your
12a5a4af3bSchristos    option) any later version.
13a5a4af3bSchristos 
14a5a4af3bSchristos    GAS, GDB, and GNU binutils are distributed in the hope that they will be
15a5a4af3bSchristos    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16a5a4af3bSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a5a4af3bSchristos    GNU General Public License for more details.
18a5a4af3bSchristos 
19a5a4af3bSchristos    You should have received a copy of the GNU General Public License
20a5a4af3bSchristos    along with this program; if not, write to the Free Software
21a5a4af3bSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22a5a4af3bSchristos    MA 02110-1301, USA.  */
23a5a4af3bSchristos 
24a5a4af3bSchristos #ifndef __CRIS_H_INCLUDED_
25a5a4af3bSchristos #define __CRIS_H_INCLUDED_
26a5a4af3bSchristos 
27a5a4af3bSchristos #if !defined(__STDC__) && !defined(const)
28a5a4af3bSchristos #define const
29a5a4af3bSchristos #endif
30a5a4af3bSchristos 
31a5a4af3bSchristos 
32a5a4af3bSchristos /* Registers.  */
33a5a4af3bSchristos #define MAX_REG (15)
34a5a4af3bSchristos #define REG_SP (14)
35a5a4af3bSchristos #define REG_PC (15)
36a5a4af3bSchristos 
37a5a4af3bSchristos /* CPU version control of disassembly and assembly of instructions.
38a5a4af3bSchristos    May affect how the instruction is assembled, at least the size of
39a5a4af3bSchristos    immediate operands.  */
40a5a4af3bSchristos enum cris_insn_version_usage
41a5a4af3bSchristos {
42a5a4af3bSchristos   /* Any version.  */
43a5a4af3bSchristos   cris_ver_version_all=0,
44a5a4af3bSchristos 
45a5a4af3bSchristos   /* Indeterminate (intended for disassembly only, or obsolete).  */
46a5a4af3bSchristos   cris_ver_warning,
47a5a4af3bSchristos 
48a5a4af3bSchristos   /* Only for v0..3 (Etrax 1..4).  */
49a5a4af3bSchristos   cris_ver_v0_3,
50a5a4af3bSchristos 
51a5a4af3bSchristos   /* Only for v3 or higher (ETRAX 4 and beyond).  */
52a5a4af3bSchristos   cris_ver_v3p,
53a5a4af3bSchristos 
54a5a4af3bSchristos   /* Only for v8 (Etrax 100).  */
55a5a4af3bSchristos   cris_ver_v8,
56a5a4af3bSchristos 
57a5a4af3bSchristos   /* Only for v8 or higher (ETRAX 100, ETRAX 100 LX).  */
58a5a4af3bSchristos   cris_ver_v8p,
59a5a4af3bSchristos 
60a5a4af3bSchristos   /* Only for v0..10.  FIXME: Not sure what to do with this.  */
61a5a4af3bSchristos   cris_ver_sim_v0_10,
62a5a4af3bSchristos 
63a5a4af3bSchristos   /* Only for v0..10.  */
64a5a4af3bSchristos   cris_ver_v0_10,
65a5a4af3bSchristos 
66a5a4af3bSchristos   /* Only for v3..10.  (ETRAX 4, ETRAX 100 and ETRAX 100 LX).  */
67a5a4af3bSchristos   cris_ver_v3_10,
68a5a4af3bSchristos 
69a5a4af3bSchristos   /* Only for v8..10 (ETRAX 100 and ETRAX 100 LX).  */
70a5a4af3bSchristos   cris_ver_v8_10,
71a5a4af3bSchristos 
72a5a4af3bSchristos   /* Only for v10 (ETRAX 100 LX) and same series.  */
73a5a4af3bSchristos   cris_ver_v10,
74a5a4af3bSchristos 
75a5a4af3bSchristos   /* Only for v10 (ETRAX 100 LX) and same series.  */
76a5a4af3bSchristos   cris_ver_v10p,
77a5a4af3bSchristos 
78a5a4af3bSchristos   /* Only for v32 or higher (codename GUINNESS).
79a5a4af3bSchristos      Of course some or all these of may change to cris_ver_v32p if/when
80a5a4af3bSchristos      there's a new revision. */
81a5a4af3bSchristos   cris_ver_v32p
82a5a4af3bSchristos };
83a5a4af3bSchristos 
84a5a4af3bSchristos 
85a5a4af3bSchristos /* Special registers.  */
86a5a4af3bSchristos struct cris_spec_reg
87a5a4af3bSchristos {
88a5a4af3bSchristos   const char *const name;
89a5a4af3bSchristos   unsigned int number;
90a5a4af3bSchristos 
91a5a4af3bSchristos   /* The size of the register.  */
92a5a4af3bSchristos   unsigned int reg_size;
93a5a4af3bSchristos 
94a5a4af3bSchristos   /* What CPU version the special register of that name is implemented
95a5a4af3bSchristos      in.  If cris_ver_warning, emit an unimplemented-warning.  */
96a5a4af3bSchristos   enum cris_insn_version_usage applicable_version;
97a5a4af3bSchristos 
98a5a4af3bSchristos   /* There might be a specific warning for using a special register
99a5a4af3bSchristos      here.  */
100a5a4af3bSchristos   const char *const warning;
101a5a4af3bSchristos };
102a5a4af3bSchristos extern const struct cris_spec_reg cris_spec_regs[];
103a5a4af3bSchristos 
104a5a4af3bSchristos 
105a5a4af3bSchristos /* Support registers (kind of special too, but not named as such).  */
106a5a4af3bSchristos struct cris_support_reg
107a5a4af3bSchristos {
108a5a4af3bSchristos   const char *const name;
109a5a4af3bSchristos   unsigned int number;
110a5a4af3bSchristos };
111a5a4af3bSchristos extern const struct cris_support_reg cris_support_regs[];
112a5a4af3bSchristos 
113a5a4af3bSchristos struct cris_cond15
114a5a4af3bSchristos {
115a5a4af3bSchristos   /* The name of the condition.  */
116a5a4af3bSchristos   const char *const name;
117a5a4af3bSchristos 
118a5a4af3bSchristos   /* What CPU version this condition name applies to.  */
119a5a4af3bSchristos   enum cris_insn_version_usage applicable_version;
120a5a4af3bSchristos };
121a5a4af3bSchristos extern const struct cris_cond15 cris_conds15[];
122a5a4af3bSchristos 
123a5a4af3bSchristos /* Opcode-dependent constants.  */
124a5a4af3bSchristos #define AUTOINCR_BIT (0x04)
125a5a4af3bSchristos 
126a5a4af3bSchristos /* Prefixes.  */
127a5a4af3bSchristos #define BDAP_QUICK_OPCODE (0x0100)
128a5a4af3bSchristos #define BDAP_QUICK_Z_BITS (0x0e00)
129a5a4af3bSchristos 
130a5a4af3bSchristos #define BIAP_OPCODE	  (0x0540)
131a5a4af3bSchristos #define BIAP_Z_BITS	  (0x0a80)
132a5a4af3bSchristos 
133a5a4af3bSchristos #define DIP_OPCODE	  (0x0970)
134a5a4af3bSchristos #define DIP_Z_BITS	  (0xf280)
135a5a4af3bSchristos 
136a5a4af3bSchristos #define BDAP_INDIR_LOW	  (0x40)
137a5a4af3bSchristos #define BDAP_INDIR_LOW_Z  (0x80)
138a5a4af3bSchristos #define BDAP_INDIR_HIGH	  (0x09)
139a5a4af3bSchristos #define BDAP_INDIR_HIGH_Z (0x02)
140a5a4af3bSchristos 
141a5a4af3bSchristos #define BDAP_INDIR_OPCODE (BDAP_INDIR_HIGH * 0x0100 + BDAP_INDIR_LOW)
142a5a4af3bSchristos #define BDAP_INDIR_Z_BITS (BDAP_INDIR_HIGH_Z * 0x100 + BDAP_INDIR_LOW_Z)
143a5a4af3bSchristos #define BDAP_PC_LOW	  (BDAP_INDIR_LOW + REG_PC)
144a5a4af3bSchristos #define BDAP_INCR_HIGH	  (BDAP_INDIR_HIGH + AUTOINCR_BIT)
145a5a4af3bSchristos 
146a5a4af3bSchristos /* No prefix must have this code for its "match" bits in the
147a5a4af3bSchristos    opcode-table.  "BCC .+2" will do nicely.  */
148a5a4af3bSchristos #define NO_CRIS_PREFIX 0
149a5a4af3bSchristos 
150a5a4af3bSchristos /* Definitions for condition codes.  */
151a5a4af3bSchristos #define CC_CC  0x0
152a5a4af3bSchristos #define CC_HS  0x0
153a5a4af3bSchristos #define CC_CS  0x1
154a5a4af3bSchristos #define CC_LO  0x1
155a5a4af3bSchristos #define CC_NE  0x2
156a5a4af3bSchristos #define CC_EQ  0x3
157a5a4af3bSchristos #define CC_VC  0x4
158a5a4af3bSchristos #define CC_VS  0x5
159a5a4af3bSchristos #define CC_PL  0x6
160a5a4af3bSchristos #define CC_MI  0x7
161a5a4af3bSchristos #define CC_LS  0x8
162a5a4af3bSchristos #define CC_HI  0x9
163a5a4af3bSchristos #define CC_GE  0xA
164a5a4af3bSchristos #define CC_LT  0xB
165a5a4af3bSchristos #define CC_GT  0xC
166a5a4af3bSchristos #define CC_LE  0xD
167a5a4af3bSchristos #define CC_A   0xE
168a5a4af3bSchristos #define CC_EXT 0xF
169a5a4af3bSchristos 
170a5a4af3bSchristos /* A table of strings "cc", "cs"... indexed with condition code
171a5a4af3bSchristos    values as above.  */
172a5a4af3bSchristos extern const char *const cris_cc_strings[];
173a5a4af3bSchristos 
174a5a4af3bSchristos /* Bcc quick.  */
175a5a4af3bSchristos #define BRANCH_QUICK_LOW  (0)
176a5a4af3bSchristos #define BRANCH_QUICK_HIGH (0)
177a5a4af3bSchristos #define BRANCH_QUICK_OPCODE (BRANCH_QUICK_HIGH * 0x0100 + BRANCH_QUICK_LOW)
178a5a4af3bSchristos #define BRANCH_QUICK_Z_BITS (0x0F00)
179a5a4af3bSchristos 
180a5a4af3bSchristos /* BA quick.  */
181a5a4af3bSchristos #define BA_QUICK_HIGH (BRANCH_QUICK_HIGH + CC_A * 0x10)
182a5a4af3bSchristos #define BA_QUICK_OPCODE (BA_QUICK_HIGH * 0x100 + BRANCH_QUICK_LOW)
183a5a4af3bSchristos 
184a5a4af3bSchristos /* Bcc [PC+].  */
185a5a4af3bSchristos #define BRANCH_PC_LOW	 (0xFF)
186a5a4af3bSchristos #define BRANCH_INCR_HIGH (0x0D)
187a5a4af3bSchristos #define BA_PC_INCR_OPCODE \
188a5a4af3bSchristos  ((BRANCH_INCR_HIGH + CC_A * 0x10) * 0x0100 + BRANCH_PC_LOW)
189a5a4af3bSchristos 
190a5a4af3bSchristos /* Jump.  */
191a5a4af3bSchristos /* Note that old versions generated special register 8 (in high bits)
192a5a4af3bSchristos    and not-that-old versions recognized it as a jump-instruction.
193a5a4af3bSchristos    That opcode now belongs to JUMPU.  */
194a5a4af3bSchristos #define JUMP_INDIR_OPCODE (0x0930)
195a5a4af3bSchristos #define JUMP_INDIR_Z_BITS (0xf2c0)
196a5a4af3bSchristos #define JUMP_PC_INCR_OPCODE \
197a5a4af3bSchristos  (JUMP_INDIR_OPCODE + AUTOINCR_BIT * 0x0100 + REG_PC)
198a5a4af3bSchristos 
199a5a4af3bSchristos #define MOVE_M_TO_PREG_OPCODE 0x0a30
200a5a4af3bSchristos #define MOVE_M_TO_PREG_ZBITS 0x01c0
201a5a4af3bSchristos 
202a5a4af3bSchristos /* BDAP.D N,PC.  */
203a5a4af3bSchristos #define MOVE_PC_INCR_OPCODE_PREFIX \
204a5a4af3bSchristos  (((BDAP_INCR_HIGH | (REG_PC << 4)) << 8) | BDAP_PC_LOW | (2 << 4))
205a5a4af3bSchristos #define MOVE_PC_INCR_OPCODE_SUFFIX \
206a5a4af3bSchristos  (MOVE_M_TO_PREG_OPCODE | REG_PC | (AUTOINCR_BIT << 8))
207a5a4af3bSchristos 
208a5a4af3bSchristos #define JUMP_PC_INCR_OPCODE_V32 (0x0DBF)
209a5a4af3bSchristos 
210a5a4af3bSchristos /* BA DWORD (V32).  */
211a5a4af3bSchristos #define BA_DWORD_OPCODE (0x0EBF)
212a5a4af3bSchristos 
213a5a4af3bSchristos /* Nop.  */
214a5a4af3bSchristos #define NOP_OPCODE (0x050F)
215a5a4af3bSchristos #define NOP_Z_BITS (0xFFFF ^ NOP_OPCODE)
216a5a4af3bSchristos 
217a5a4af3bSchristos #define NOP_OPCODE_V32 (0x05B0)
218a5a4af3bSchristos #define NOP_Z_BITS_V32 (0xFFFF ^ NOP_OPCODE_V32)
219a5a4af3bSchristos 
220a5a4af3bSchristos /* For the compatibility mode, let's use "MOVE R0,P0".  Doesn't affect
221a5a4af3bSchristos    registers or flags.  Unfortunately shuts off interrupts for one cycle
222a5a4af3bSchristos    for < v32, but there doesn't seem to be any alternative without that
223a5a4af3bSchristos    effect.  */
224a5a4af3bSchristos #define NOP_OPCODE_COMMON (0x630)
225a5a4af3bSchristos #define NOP_OPCODE_ZBITS_COMMON (0xffff & ~NOP_OPCODE_COMMON)
226a5a4af3bSchristos 
227a5a4af3bSchristos /* LAPC.D  */
228a5a4af3bSchristos #define LAPC_DWORD_OPCODE (0x0D7F)
229a5a4af3bSchristos #define LAPC_DWORD_Z_BITS (0x0fff & ~LAPC_DWORD_OPCODE)
230a5a4af3bSchristos 
231a5a4af3bSchristos /* Structure of an opcode table entry.  */
232a5a4af3bSchristos enum cris_imm_oprnd_size_type
233a5a4af3bSchristos {
234a5a4af3bSchristos   /* No size is applicable.  */
235a5a4af3bSchristos   SIZE_NONE,
236a5a4af3bSchristos 
237a5a4af3bSchristos   /* Always 32 bits.  */
238a5a4af3bSchristos   SIZE_FIX_32,
239a5a4af3bSchristos 
240a5a4af3bSchristos   /* Indicated by size of special register.  */
241a5a4af3bSchristos   SIZE_SPEC_REG,
242a5a4af3bSchristos 
243a5a4af3bSchristos   /* Indicated by size field, signed.  */
244a5a4af3bSchristos   SIZE_FIELD_SIGNED,
245a5a4af3bSchristos 
246a5a4af3bSchristos   /* Indicated by size field, unsigned.  */
247a5a4af3bSchristos   SIZE_FIELD_UNSIGNED,
248a5a4af3bSchristos 
249a5a4af3bSchristos   /* Indicated by size field, no sign implied.  */
250a5a4af3bSchristos   SIZE_FIELD
251a5a4af3bSchristos };
252a5a4af3bSchristos 
253a5a4af3bSchristos /* For GDB.  FIXME: Is this the best way to handle opcode
254a5a4af3bSchristos    interpretation?  */
255a5a4af3bSchristos enum cris_op_type
256a5a4af3bSchristos {
257a5a4af3bSchristos   cris_not_implemented_op = 0,
258a5a4af3bSchristos   cris_abs_op,
259a5a4af3bSchristos   cris_addi_op,
260a5a4af3bSchristos   cris_asr_op,
261a5a4af3bSchristos   cris_asrq_op,
262a5a4af3bSchristos   cris_ax_ei_setf_op,
263a5a4af3bSchristos   cris_bdap_prefix,
264a5a4af3bSchristos   cris_biap_prefix,
265a5a4af3bSchristos   cris_break_op,
266a5a4af3bSchristos   cris_btst_nop_op,
267a5a4af3bSchristos   cris_clearf_di_op,
268a5a4af3bSchristos   cris_dip_prefix,
269a5a4af3bSchristos   cris_dstep_logshift_mstep_neg_not_op,
270a5a4af3bSchristos   cris_eight_bit_offset_branch_op,
271a5a4af3bSchristos   cris_move_mem_to_reg_movem_op,
272a5a4af3bSchristos   cris_move_reg_to_mem_movem_op,
273a5a4af3bSchristos   cris_move_to_preg_op,
274a5a4af3bSchristos   cris_muls_op,
275a5a4af3bSchristos   cris_mulu_op,
276a5a4af3bSchristos   cris_none_reg_mode_add_sub_cmp_and_or_move_op,
277a5a4af3bSchristos   cris_none_reg_mode_clear_test_op,
278a5a4af3bSchristos   cris_none_reg_mode_jump_op,
279a5a4af3bSchristos   cris_none_reg_mode_move_from_preg_op,
280a5a4af3bSchristos   cris_quick_mode_add_sub_op,
281a5a4af3bSchristos   cris_quick_mode_and_cmp_move_or_op,
282a5a4af3bSchristos   cris_quick_mode_bdap_prefix,
283a5a4af3bSchristos   cris_reg_mode_add_sub_cmp_and_or_move_op,
284a5a4af3bSchristos   cris_reg_mode_clear_op,
285a5a4af3bSchristos   cris_reg_mode_jump_op,
286a5a4af3bSchristos   cris_reg_mode_move_from_preg_op,
287a5a4af3bSchristos   cris_reg_mode_test_op,
288a5a4af3bSchristos   cris_scc_op,
289a5a4af3bSchristos   cris_sixteen_bit_offset_branch_op,
290a5a4af3bSchristos   cris_three_operand_add_sub_cmp_and_or_op,
291a5a4af3bSchristos   cris_three_operand_bound_op,
292a5a4af3bSchristos   cris_two_operand_bound_op,
293a5a4af3bSchristos   cris_xor_op
294a5a4af3bSchristos };
295a5a4af3bSchristos 
296a5a4af3bSchristos struct cris_opcode
297a5a4af3bSchristos {
298a5a4af3bSchristos   /* The name of the insn.  */
299a5a4af3bSchristos   const char *name;
300a5a4af3bSchristos 
301a5a4af3bSchristos   /* Bits that must be 1 for a match.  */
302a5a4af3bSchristos   unsigned int match;
303a5a4af3bSchristos 
304a5a4af3bSchristos   /* Bits that must be 0 for a match.  */
305a5a4af3bSchristos   unsigned int lose;
306a5a4af3bSchristos 
307a5a4af3bSchristos   /* See the table in "opcodes/cris-opc.c".  */
308a5a4af3bSchristos   const char *args;
309a5a4af3bSchristos 
310a5a4af3bSchristos   /* Nonzero if this is a delayed branch instruction.  */
311a5a4af3bSchristos   char delayed;
312a5a4af3bSchristos 
313a5a4af3bSchristos   /* Size of immediate operands.  */
314a5a4af3bSchristos   enum cris_imm_oprnd_size_type imm_oprnd_size;
315a5a4af3bSchristos 
316a5a4af3bSchristos   /* Indicates which version this insn was first implemented in.  */
317a5a4af3bSchristos   enum cris_insn_version_usage applicable_version;
318a5a4af3bSchristos 
319a5a4af3bSchristos   /* What kind of operation this is.  */
320a5a4af3bSchristos   enum cris_op_type op;
321a5a4af3bSchristos };
322a5a4af3bSchristos extern const struct cris_opcode cris_opcodes[];
323a5a4af3bSchristos 
324a5a4af3bSchristos 
325a5a4af3bSchristos /* These macros are for the target-specific flags in disassemble_info
326a5a4af3bSchristos    used at disassembly.  */
327a5a4af3bSchristos 
328a5a4af3bSchristos /* This insn accesses memory.  This flag is more trustworthy than
329a5a4af3bSchristos    checking insn_type for "dis_dref" which does not work for
330a5a4af3bSchristos    e.g. "JSR [foo]".  */
331a5a4af3bSchristos #define CRIS_DIS_FLAG_MEMREF (1 << 0)
332a5a4af3bSchristos 
333a5a4af3bSchristos /* The "target" field holds a register number.  */
334a5a4af3bSchristos #define CRIS_DIS_FLAG_MEM_TARGET_IS_REG (1 << 1)
335a5a4af3bSchristos 
336a5a4af3bSchristos /* The "target2" field holds a register number; add it to "target".  */
337a5a4af3bSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_IS_REG (1 << 2)
338a5a4af3bSchristos 
339a5a4af3bSchristos /* Yet another add-on: the register in "target2" must be multiplied
340a5a4af3bSchristos    by 2 before adding to "target".  */
341a5a4af3bSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MULT2 (1 << 3)
342a5a4af3bSchristos 
343a5a4af3bSchristos /* Yet another add-on: the register in "target2" must be multiplied
344a5a4af3bSchristos    by 4 (mutually exclusive with .._MULT2).  */
345a5a4af3bSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MULT4 (1 << 4)
346a5a4af3bSchristos 
347a5a4af3bSchristos /* The register in "target2" is an indirect memory reference (of the
348a5a4af3bSchristos    register there), add to "target".  Assumed size is dword (mutually
349a5a4af3bSchristos    exclusive with .._MULT[24]).  */
350a5a4af3bSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MEM (1 << 5)
351a5a4af3bSchristos 
352a5a4af3bSchristos /* Add-on to CRIS_DIS_FLAG_MEM_TARGET2_MEM; the memory access is "byte";
353a5a4af3bSchristos    sign-extended before adding to "target".  */
354a5a4af3bSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MEM_BYTE (1 << 6)
355a5a4af3bSchristos 
356a5a4af3bSchristos /* Add-on to CRIS_DIS_FLAG_MEM_TARGET2_MEM; the memory access is "word";
357a5a4af3bSchristos    sign-extended before adding to "target".  */
358a5a4af3bSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MEM_WORD (1 << 7)
359a5a4af3bSchristos 
360a5a4af3bSchristos #endif /* __CRIS_H_INCLUDED_ */
361a5a4af3bSchristos 
362a5a4af3bSchristos /*
363a5a4af3bSchristos  * Local variables:
364a5a4af3bSchristos  * eval: (c-set-style "gnu")
365a5a4af3bSchristos  * indent-tabs-mode: t
366a5a4af3bSchristos  * End:
367a5a4af3bSchristos  */
368