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