Rizin
unix-like reverse engineering framework and cli tools
lanai.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 1994, 1995 Myricom, Inc.
2 // SPDX-License-Identifier: GPL-2.0-only
3 
4 /*************************************************************************
5  * *
6  * Definitions for opcode table for the Lanai. *
7  * *
8  * Copyright (c) 1994, 1995 by Myricom, Inc. *
9  * All rights reserved. *
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of version 2 of the GNU General Public License *
13  * as published by the Free Software Foundation. Myricom requests that *
14  * all modifications of this software be returned to Myricom, Inc. for *
15  * redistribution. The name of Myricom, Inc. may not be used to endorse *
16  * or promote products derived from this software without specific prior *
17  * written permission. *
18  * *
19  * Myricom, Inc. makes no representations about the suitability of this *
20  * software for any purpose. *
21  * *
22  * THIS FILE IS PROVIDED "AS-IS" WITHOUT WARRANTY OF ANY KIND, WHETHER *
23  * EXPRESSED OR IMPLIED, INCLUDING THE WARRANTY OF MERCHANTABILITY OR *
24  * FITNESS FOR A PARTICULAR PURPOSE. MYRICOM, INC. SHALL HAVE NO *
25  * LIABILITY WITH RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE *
26  * SECRETS OR ANY PATENTS BY THIS FILE OR ANY PART THEREOF. *
27  * *
28  * In no event will Myricom, Inc. be liable for any lost revenue *
29  * or profits or other special, indirect and consequential damages, even *
30  * if Myricom has been advised of the possibility of such damages. *
31  * *
32  * Other copyrights might apply to parts of this software and are so *
33  * noted when applicable. *
34  * *
35  * Myricom, Inc. Email: info@myri.com *
36  * 325 N. Santa Anita Ave. World Wide Web: http://www.myri.com/ *
37  * Arcadia, CA 91024 *
38  *************************************************************************/
39 /* initial version released 5/95 */
40 /* This file is based upon sparc.h from the Gnu binutils-2.5.2
41  release, which had the following copyright notice: */
42 
43 /* Definitions for opcode table for the sparc.
44  Copyright 1989, 1991, 1992 Free Software Foundation, Inc.
45 
46  This file is part of GAS, the GNU Assembler, GDB, the GNU debugger, and
47  the GNU Binutils.
48 
49 
50  GAS/GDB is free software; you can redistribute it and/or modify
51  it under the terms of the GNU General Public License as published by
52  the Free Software Foundation; either version 2, or (at your option)
53  any later version.
54 
55  GAS/GDB is distributed in the hope that it will be useful,
56  but WITHOUT ANY WARRANTY; without even the implied warranty of
57  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58  GNU General Public License for more details.
59 
60  You should have received a copy of the GNU General Public License
61  along with GAS or GDB; see the file COPYING. If not, write to
62  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
63  USA. */
64 
65 /* The Lanai opcode table (and other related data) is defined in
66  the opcodes library in lanai-opc.c. If you change anything here, make
67  sure you fix up that file, and vice versa. */
68 
69 /* FIXME-someday: perhaps the ,a's and such should be embedded in the
70  instruction's name rather than the args. This would make gas faster, pinsn
71  slower, but would mess up some macros a bit. xoxorich. */
72 
73 #define lanai_architecture bfd_lanai_architecture
74 #define architecture_pname bfd_lanai_architecture_pname
75 #define lanai_opcode bfd_lanai_opcode
76 #define lanai_opcodes bfd_lanai_opcodes
77 
78 /*
79  * Structure of an opcode table entry.
80  * This enumerator must parallel the architecture_pname array
81  * in bfd/opc-lanai.c.
82  */
84  v0 = 0,
85  v1
86 };
87 
88 extern const char *architecture_pname[];
89 
90 struct lanai_opcode {
91  const char *name;
92  unsigned long match; /* Bits that must be set. */
93  unsigned long lose; /* Bits that must be clear. */
94  const char *args;
95  unsigned int flags;
97 };
98 
99 #define F_ALIAS 1 /* Alias for a "real" instruction */
100 #define F_JSR 2 /* Subroutine call */
101 
102 #define F_RI 0x10
103 #define F_RR 0x20
104 #define F_RRR 0x40
105 #define F_RM 0x80
106 #define F_RRM 0x100
107 #define F_BR 0x200
108 #define F_SLS 0x400
109 #define F_SLI 0x800
110 #define F_SPLS 0x1000
111 #define F_PUNT 0x2000
112 #define F_SBR 0x4000
113 #define F_SCC 0x8000
114 
115 #define F_BYTE 0x20000
116 #define F_HALF 0x10000
117 #define F_FULL 0x00000
118 #define F_DATA_SIZE(X) (4 >> ((X)&0x30000))
119 #define F_CONDITIONAL 0x40000
120 #define F_REL 0x80000
121 
122 #define F_LEADZ 0x100000
123 #define F_POPC 0x200000
124 
125 #define F_CONDBR (F_BR | F_CONDITIONAL) /* Conditional branch */
126 #define F_UNBR (F_BR) /* Unconditional branch */
127 #define F_RELCONDBR (F_REL | F_BR | F_CONDITIONAL) /* Conditional branch */
128 #define F_RELUNBR (F_REL | F_BR) /* Unconditional branch */
129 
130 /* FIXME: Add F_ANACHRONISTIC flag for v9. */
131 /* FIXME: Add F_OBSOLETE flag for v9, for instructions that no longer exist? */
132 
133 /*
134 
135 All lanai opcodes are 32 bits.
136 
137 The match component is a mask saying which bits must match a particular
138 opcode in order for an instruction to be an instance of that opcode.
139 
140 The args component is a string containing one character for each operand of the
141 instruction.
142 
143 Kinds of operands:
144  # Number used by optimizer. It is ignored.
145  1 Rs1 register.
146  2 Rs2 register.
147  3 Rs3 register.
148  d Rd register.
149 
150  4 Op1 (for RRR)
151  5 Op2 (for RRR)
152  6 Op2 (for RRM)
153 
154  J 0x????0000
155  j 0x0000????
156  L 0x????ffff
157  l 0xffff????
158  k -j
159 
160  o 16 bit signed offset
161  s 6 bit signed shift constant
162  i 10 bit signed immediate.
163  I 5/16 split 21-bit unsigned immediate.
164  Y 5/16 split 21-bit unsigned immediate with 2 LSB's == 0.
165  B 2+23-bit absolute.
166  b 2+23-bit PC relative immediate.
167 
168  P %pc or %r2 as Rd
169  p %pc or %r2 as Rs1
170 X Q %apc or %r29
171 X q %aps or %r28
172 X S %isr or %r31
173 X M %imr or %r30
174  ! %r1
175  0 %r0
176 
177 Literals:([])*+- ,
178 
179 */
180 
181 /* whether to use certain insns */
182 #define L3_USE_SI
183 #define L3_USE_SPLS
184 #define L3_USE_SLS
185 #define L3_USE_SLI
186 #define L3_USE_SBR
187 
188 /* encodings of various conditions */
189 #define L3_T 0
190 #define L3_F 1
191 #define L3_HI 2
192 #define L3_LS 3
193 #define L3_CC 4
194 #define L3_CS 5
195 #define L3_NE 6
196 #define L3_EQ 7
197 #define L3_VC 8
198 #define L3_VS 9
199 #define L3_PL 10
200 #define L3_MI 11
201 #define L3_GE 12
202 #define L3_LT 13
203 #define L3_GT 14
204 #define L3_LE 15
205 
206 #define L3_UGE L3_CC
207 #define L3_ULT L3_CS
208 #define L3_UGT L3_GT
209 #define L3_ULE L3_LE
210 
211 /* opcodes */
212 /* NOTE: The following masks specify all the bits that can be
213  determined solely by knowing which line in lanai-opc.c (in the opcodes
214  directory in the gnu binutils release) matched the line of assembly
215  code. The OPCODE_MASK specifies which bits of the instruction are constant
216  for all instructions in the family.
217 */
218 #define L3_RI (0x00000000)
219 #define L3_RI_OPCODE_MASK (0x80000000)
220 #define L3_RI_MASK (0xf0030000)
221 #define L3_RR (0xc0000000)
222 #define L3_RR_OPCODE_MASK (0xf0000003)
223 #define L3_RR_MASK (0xf00207fb)
224 #define L3_LEADZ (0xc0000002)
225 #define L3_LEADZ_OPCODE_MASK L3_RR_OPCODE_MASK
226 #define L3_LEADZ_MASK (0xf00207fb)
227 #define L3_POPC (0xc0000003)
228 #define L3_POPC_OPCODE_MASK L3_RR_OPCODE_MASK
229 #define L3_POPC_MASK (0xf00207fb)
230 #define L3_RRR (0xd0000000)
231 #define L3_RRR_OPCODE_MASK (0xf0000000)
232 #define L3_RRR_MASK (0xf0000000)
233 #define L3_RM (0x80000000)
234 #define L3_RM_OPCODE_MASK (0xe0000000)
235 #define L3_RM_MASK (0xf0030000)
236 #define L3_RRM (0xa0000000)
237 #define L3_RRM_OPCODE_MASK (0xe0000000)
238 #define L3_RRM_MASK (0xe0030007)
239 #define L3_BR (0xe0000000)
240 #define L3_BR_OPCODE_MASK (0xf0000002)
241 #define L3_BR_MASK (0xfe000003)
242 #define L3_BRR (0xe1000002)
243 #define L3_BRR_OPCODE_MASK (0xf1000002)
244 #define L3_BRR_MASK (0xff000003)
245 #define L3_SCC (0xe0000002)
246 #define L3_SCC_OPCODE_MASK (0xf1000002)
247 #define L3_SCC_MASK (0xff000003)
248 #define L3_SLS (0xf0000000)
249 #define L3_SLS_OPCODE_MASK (0xf0020000)
250 #define L3_SLS_MASK (0xf0030000)
251 #define L3_SLI (0xf0020000)
252 #define L3_SLI_OPCODE_MASK (0xf0030000)
253 #define L3_SLI_MASK (0xf0030000)
254 #define L3_SPLS (0xf0030000)
255 #define L3_SPLS_OPCODE_MASK (0xf0038000)
256 #define L3_SPLS_MASK (0xf003fc00)
257 #ifdef BAD
258 /* BAD: needs fixing */
259 #define L3_SI (0xf0038000)
260 #define L3_SI_OPCODE_MASK ___bogus___
261 #define L3_SI_MASK (0xf003cf47)
262 #endif
263 #define L3_PUNT (0xf003ff47)
264 #define L3_PUNT_OPCODE_MASK (0xf003ff47)
265 #define L3_PUNT_MASK (0xf003ff47)
266 #define L3_SBR (0xf003c000)
267 #define L3_SBR_OPCODE_MASK (0xf003f806)
268 #define L3_SBR_MASK (0xfe03f807)
269 
270 /* operations */
271 #define L3_ADD (0x00)
272 #define L3_ADDC (0x01)
273 #define L3_SUB (0x02)
274 #define L3_SUBB (0x03)
275 #define L3_AND (0x04)
276 #define L3_OR (0x05)
277 #define L3_XOR (0x06)
278 #define L3_SH (0x07)
279 #define L3_OP_MASK (0x07)
280 #define L3_FLAGS (0x08)
281 #define L3_ARITH (0x10)
282 
283 /* Data sizes */
284 #define L3_HALFWORD 0
285 #define L3_BYTE 4 /* was 1 */
286 #define L3_FULLWORD 2
287 
288 /* RRM modes for BYTE and HALFWORD load */
289 #define L3_SIGNED 0
290 #define L3_UNSIGNED 1 /* was 4 */
291 
292 #define L3_SIGNED_HALFWORD (L3_SIGNED | L3_HALFWORD)
293 #define L3_SIGNED_BYTE (L3_SIGNED | L3_BYTE)
294 #define L3_SIGNED_FULLWORD (L3_SIGNED | L3_FULLWORD)
295 #define L3_UNSIGNED_HALFWORD (L3_UNSIGNED | L3_HALFWORD)
296 #define L3_UNSIGNED_BYTE (L3_UNSIGNED | L3_BYTE)
297 #define L3_UNSIGNED_FULLWORD (L3_UNSIGNED | L3_FULLWORD)
298 
299 /* flags */
300 #define L3_RI_F (0x00020000)
301 #define L3_RI_H (0x00010000)
302 
303 #define L3_RR_F (0x00020000)
304 #define L3_LEADZ_F L3_RR_F
305 #define L3_POPC_F L3_RR_F
306 
307 #define L3_RRR_F (0x00020000)
308 #define L3_RRR_H (0x00010000)
309 
310 #define L3_RM_P (0x00020000)
311 #define L3_RM_Q (0x00010000)
312 #define L3_RM_S (0x10000000)
313 
314 #define L3_RRM_P (0x00020000)
315 #define L3_RRM_Q (0x00010000)
316 #define L3_RRM_S (0x10000000)
317 #define L3_RRM_Y (0x00000004)
318 #define L3_RRM_L (0x00000002)
319 #define L3_RRM_E (0x00000001)
320 
321 #define L3_BR_R (0x00000002)
322 
323 #define L3_SLS_S (0x00010000)
324 
325 #define L3_SPLS_Y (0x00004000)
326 #define L3_SPLS_S (0x00002000)
327 #define L3_SPLS_E (0x00001000)
328 #define L3_SPLS_P (0x00000800)
329 #define L3_SPLS_Q (0x00000400)
330 
331 #define L3_SI_F (0x00002000)
332 
333 #define L3_SBR_H (0x00000004)
334 #define L3_SBR_R (0x00000002)
335 #define L3_SBR_N (0x00000001)
336 
337 /* masks */
338 
339 #define L3_CONST_MASK (0x0000ffff)
340 #define L3_BR_CONST_MASK (0x01fffffc)
341 #define L3_SPLS_CONST_MASK (0x000003ff)
342 
343 /* field insertion */
344 #define L3_RD(x) (((x)&0x1f) << 23)
345 #define L3_RS1(x) (((x)&0x1f) << 18)
346 #define L3_RS2(x) (((x)&0x1f) << 11)
347 #define L3_RS3(x) (((x)&0x1f) << 3)
348 
349 #define L3_RI_OP(x) (((x)&L3_OP_MASK) << 28)
350 #define L3_RR_OP(x) (((x)&L3_OP_MASK) << 8)
351 #define L3_RRR_OP1(x) (((x)&L3_OP_MASK) << 0)
352 #define L3_RRR_OP2(x) (((x)&L3_OP_MASK) << 8)
353 #define L3_RRM_OP(x) (((x)&L3_OP_MASK) << 8)
354 #define L3_RRM_MODE(x) (((x)&0x7) << 0)
355 #define L3_BR_COND(x) ((((x)&0xe) << 24) | ((x)&1))
356 #define L3_SBR_COND(x) ((((x)&0xe) << 24) | ((x)&1))
357 #define L3_SLS_HIBITS(x) (((x)&0x1f) << 18)
358 #define L3_SLS_CONST(x) ((((x)&0x1f) << 18) | ((x)&0xffff))
359 /* Delete this:
360 #define L3_SLI_HIBITS(x) (((x)&0x7) << 18)
361 */
362 #define L3_SLI_CONST(x) ((((x)&0x1f) << 18) | ((x)&0xffff))
363 #define L3_SPLS_MODE(x) (((x)&0x5) << 12)
364 #define L3_SBR_OP(x) (((x)&0x7) << 8)
365 
366 #define L3_OP1(x) (((x)&0x7) << 0)
367 #define L3_OP2(x) (((x)&0x7) << 8)
368 
369 /* Sign-extend a value which is N bits long. */
370 #define SIGN_EXT(value, bits) \
371  ((((int)(value)) << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits))
372 
373 /* Macros used to extract instruction fields. Not all fields have
374  macros defined here, only those which are actually used. */
375 
376 #define X_RD(i) (((i) >> 23) & 0x1f)
377 #define X_RS1(i) (((i) >> 18) & 0x1f)
378 #define X_RS2(i) (((i) >> 11) & 0x1f)
379 #define X_RS3(i) (((i) >> 3) & 0x1f)
380 
381 #define X_OP1(i) (((i) >> 0) & 0x07)
382 #define X_OP2(i) (((i) >> 8) & 0x07)
383 #define X_RI_OP(i) (((i) >> 28) & 0x07)
384 #define X_RR_OP(i) X_OP2(i)
385 #define X_RRM_OP(i) X_OP2(i)
386 #define X_RRR_OP1(i) X_OP1(i)
387 #define X_RRR_OP2(i) X_OP2(i)
388 
389 #define X_C10(i) ((i)&0x3ff)
390 #define X_C16(i) ((i)&0xffff)
391 #define X_C21(i) (((i)&0xffff) | (((i)&0x7c0000) >> 2))
392 #define X_C25(i) ((i)&0x1fffffc)
393 
394 extern struct lanai_opcode lanai_opcodes[];
395 extern const int bfd_lanai_num_opcodes;
396 
397 #define NUMOPCODES bfd_lanai_num_opcodes
398 
399 /* end of lanai.h */
const int bfd_lanai_num_opcodes
Definition: lanai-opc.c:578
#define lanai_opcodes
Definition: lanai.h:76
lanai_architecture
Definition: lanai.h:83
@ v0
Definition: lanai.h:84
@ v1
Definition: lanai.h:85
#define architecture_pname
Definition: lanai.h:74
unsigned long lose
Definition: lanai.h:93
unsigned int flags
Definition: lanai.h:95
const char * args
Definition: lanai.h:94
unsigned long match
Definition: lanai.h:92
const char * name
Definition: lanai.h:91
enum lanai_architecture architecture
Definition: lanai.h:96