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