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