1 /* $OpenBSD: mips_opcode.h,v 1.2 1999/01/27 04:46:05 imp Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * from: @(#)mips_opcode.h 8.1 (Berkeley) 6/10/93
35 * JNPR: mips_opcode.h,v 1.1 2006/08/07 05:38:57 katta
39 #ifndef _MACHINE_MIPS_OPCODE_H_
40 #define _MACHINE_MIPS_OPCODE_H_
43 * Define the instruction formats and opcode values for the
44 * MIPS instruction set.
46 #include <machine/endian.h>
49 * Define the instruction formats.
54 #if BYTE_ORDER == BIG_ENDIAN
77 unsigned op: 6; /* always '0x11' */
78 unsigned : 1; /* always '1' */
86 #if BYTE_ORDER == LITTLE_ENDIAN
114 unsigned : 1; /* always '1' */
115 unsigned op: 6; /* always '0x11' */
120 /* instruction field decoding macros */
121 #define MIPS_INST_OPCODE(val) (val >> 26)
122 #define MIPS_INST_RS(val) ((val & 0x03e00000) >> 21)
123 #define MIPS_INST_RT(val) ((val & 0x001f0000) >> 16)
124 #define MIPS_INST_IMM(val) ((val & 0x0000ffff))
126 #define MIPS_INST_RD(val) ((val & 0x0000f800) >> 11)
127 #define MIPS_INST_SA(val) ((val & 0x000007c0) >> 6)
128 #define MIPS_INST_FUNC(val) (val & 0x0000003f)
130 #define MIPS_INST_INDEX(val) (val & 0x03ffffff)
133 * the mips opcode and function table use a 3bit row and 3bit col
134 * number we define the following macro for easy transcribing
137 #define MIPS_OPCODE(r, c) (((r & 0x07) << 3) | (c & 0x07))
141 * Values for the 'op' field.
143 #define OP_SPECIAL 000
152 #define OP_REGIMM OP_BCOND
172 #define OP_COP1X OP_COP3
175 #define OP_DADDIU 031
206 #define OP_PREF OP_LWC3
218 * Values for the 'func' field when 'op' == OP_SPECIAL.
228 #define OP_F_SLL OP_SLL
229 #define OP_F_MOVCI OP_MOVCI
230 #define OP_F_SRL OP_SRL
231 #define OP_F_SRA OP_SRA
232 #define OP_F_SLLV OP_SLLV
233 #define OP_F_SRLV OP_SRLV
234 #define OP_F_SRAV OP_SRAV
240 #define OP_SYSCALL 014
244 #define OP_F_JR OP_JR
245 #define OP_F_JALR OP_JALR
246 #define OP_F_MOVZ OP_MOVZ
247 #define OP_F_MOVN OP_MOVN
248 #define OP_F_SYSCALL OP_SYSCALL
249 #define OP_F_BREAK OP_BREAK
250 #define OP_F_SYNC OP_SYNC
260 #define OP_F_MFHI OP_MFHI
261 #define OP_F_MTHI OP_MTHI
262 #define OP_F_MFLO OP_MFLO
263 #define OP_F_MTLO OP_MTLO
264 #define OP_F_DSLLV OP_DSLLV
265 #define OP_F_DSRLV OP_DSRLV
266 #define OP_F_DSRAV OP_DSRAV
273 #define OP_DMULTU 035
277 #define OP_F_MULT OP_MULT
278 #define OP_F_MULTU OP_MULTU
279 #define OP_F_DIV OP_DIV
280 #define OP_F_DIVU OP_DIVU
281 #define OP_F_DMULT OP_DMULT
282 #define OP_F_DMULTU OP_DMULTU
283 #define OP_F_DDIV OP_DDIV
284 #define OP_F_DDIVU OP_DDIVU
295 #define OP_F_ADD OP_ADD
296 #define OP_F_ADDU OP_ADDU
297 #define OP_F_SUB OP_SUB
298 #define OP_F_SUBU OP_SUBU
299 #define OP_F_AND OP_AND
300 #define OP_F_OR OP_OR
301 #define OP_F_XOR OP_XOR
302 #define OP_F_NOR OP_NOR
311 #define OP_F_SLT OP_SLT
312 #define OP_F_SLTU OP_SLTU
313 #define OP_F_DADD OP_DADD
314 #define OP_F_DADDU OP_DADDU
315 #define OP_F_DSUB OP_DSUB
316 #define OP_F_DSUBU OP_DSUBU
325 #define OP_F_TGE OP_TGE
326 #define OP_F_TGEU OP_TGEU
327 #define OP_F_TLT OP_TLT
328 #define OP_F_TLTU OP_TLTU
329 #define OP_F_TEQ OP_TEQ
330 #define OP_F_TNE OP_TNE
335 #define OP_DSLL32 074
336 #define OP_DSRL32 076
337 #define OP_DSRA32 077
339 #define OP_F_DSLL OP_DSLL
340 #define OP_F_DSRL OP_DSRL
341 #define OP_F_DSRA OP_DSRA
342 #define OP_F_DSLL32 OP_DSLL32
343 #define OP_F_DSRL32 OP_DSRL32
344 #define OP_F_DSRA32 OP_DSRA32
347 * The REGIMM - register immediate instructions are further
348 * decoded using this table that has 2bit row numbers, hence
349 * a need for a new helper macro.
352 #define MIPS_ROP(r, c) ((r & 0x03) << 3) | (c & 0x07)
355 * Values for the 'func' field when 'op' == OP_BCOND.
362 #define OP_R_BLTZ OP_BLTZ
363 #define OP_R_BGEZ OP_BGEZ
364 #define OP_R_BLTZL OP_BLTZL
365 #define OP_R_BGEZL OP_BGEZL
374 #define OP_R_TGEI OP_TGEI
375 #define OP_R_TGEIU OP_TGEIU
376 #define OP_R_TLTI OP_TLTI
377 #define OP_R_TLTIU OP_TLTIU
378 #define OP_R_TEQI OP_TEQI
379 #define OP_R_TNEI OP_TNEI
381 #define OP_BLTZAL 020
382 #define OP_BGEZAL 021
383 #define OP_BLTZALL 022
384 #define OP_BGEZALL 023
386 #define OP_R_BLTZAL OP_BLTZAL
387 #define OP_R_BGEZAL OP_BGEZAL
388 #define OP_R_BLTZALL OP_BLTZALL
389 #define OP_R_BGEZALL OP_BGEZALL
392 * Values for the 'rs' field when 'op' == OP_COPz.
404 * Values for the 'rt' field when 'op' == OP_COPz.
406 #define COPz_BC_TF_MASK 0x01
407 #define COPz_BC_TRUE 0x01
408 #define COPz_BC_FALSE 0x00
409 #define COPz_BCL_TF_MASK 0x02
410 #define COPz_BCL_TRUE 0x02
411 #define COPz_BCL_FALSE 0x00
413 #endif /* !_MACHINE_MIPS_OPCODE_H_ */