xref: /openbsd-src/sys/arch/mips64/include/mips_opcode.h (revision 2fef4a9239f881729bf148d7a57caa1ebe22d91f)
1*2fef4a92Svisa /*      $OpenBSD: mips_opcode.h,v 1.9 2017/04/20 15:42:26 visa Exp $	*/
2f58c7388Spefo 
3f58c7388Spefo /*-
4f58c7388Spefo  * Copyright (c) 1992, 1993
5f58c7388Spefo  *	The Regents of the University of California.  All rights reserved.
6f58c7388Spefo  *
7f58c7388Spefo  * This code is derived from software contributed to Berkeley by
8f58c7388Spefo  * Ralph Campbell.
9f58c7388Spefo  *
10f58c7388Spefo  * Redistribution and use in source and binary forms, with or without
11f58c7388Spefo  * modification, are permitted provided that the following conditions
12f58c7388Spefo  * are met:
13f58c7388Spefo  * 1. Redistributions of source code must retain the above copyright
14f58c7388Spefo  *    notice, this list of conditions and the following disclaimer.
15f58c7388Spefo  * 2. Redistributions in binary form must reproduce the above copyright
16f58c7388Spefo  *    notice, this list of conditions and the following disclaimer in the
17f58c7388Spefo  *    documentation and/or other materials provided with the distribution.
1853aa784aSmiod  * 3. Neither the name of the University nor the names of its contributors
19f58c7388Spefo  *    may be used to endorse or promote products derived from this software
20f58c7388Spefo  *    without specific prior written permission.
21f58c7388Spefo  *
22f58c7388Spefo  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23f58c7388Spefo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24f58c7388Spefo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25f58c7388Spefo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26f58c7388Spefo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27f58c7388Spefo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28f58c7388Spefo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29f58c7388Spefo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30f58c7388Spefo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31f58c7388Spefo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32f58c7388Spefo  * SUCH DAMAGE.
33f58c7388Spefo  *
34f58c7388Spefo  *	from: @(#)mips_opcode.h	8.1 (Berkeley) 6/10/93
35f58c7388Spefo  */
36f58c7388Spefo 
372fa72412Spirofti #ifndef _MIPS64_MIPS_OPCODE_H_
382fa72412Spirofti #define	_MIPS64_MIPS_OPCODE_H_
39f58c7388Spefo 
40f58c7388Spefo /*
41f58c7388Spefo  * Define the instruction formats and opcode values for the
42f58c7388Spefo  * MIPS instruction set.
43f58c7388Spefo  */
44f58c7388Spefo 
45f58c7388Spefo /*
46f58c7388Spefo  * Define the instruction formats.
47f58c7388Spefo  */
48f58c7388Spefo typedef union {
49f58c7388Spefo 	unsigned word;
50f58c7388Spefo 
51f58c7388Spefo #if BYTE_ORDER == BIG_ENDIAN
52f58c7388Spefo 	struct {
53f58c7388Spefo 		unsigned op: 6;
54f58c7388Spefo 		unsigned rs: 5;
55f58c7388Spefo 		unsigned rt: 5;
56f58c7388Spefo 		unsigned imm: 16;
57f58c7388Spefo 	} IType;
58f58c7388Spefo 
59f58c7388Spefo 	struct {
60f58c7388Spefo 		unsigned op: 6;
61f58c7388Spefo 		unsigned target: 26;
62f58c7388Spefo 	} JType;
63f58c7388Spefo 
64f58c7388Spefo 	struct {
65f58c7388Spefo 		unsigned op: 6;
66f58c7388Spefo 		unsigned rs: 5;
67f58c7388Spefo 		unsigned rt: 5;
68f58c7388Spefo 		unsigned rd: 5;
69f58c7388Spefo 		unsigned shamt: 5;
70f58c7388Spefo 		unsigned func: 6;
71f58c7388Spefo 	} RType;
72f58c7388Spefo 
73f58c7388Spefo 	struct {
74bb80a8d6Smiod 		unsigned op: 6;		/* COP1 */
75f58c7388Spefo 		unsigned : 1;		/* always '1' */
76f58c7388Spefo 		unsigned fmt: 4;
77f58c7388Spefo 		unsigned ft: 5;
78f58c7388Spefo 		unsigned fs: 5;
79f58c7388Spefo 		unsigned fd: 5;
80f58c7388Spefo 		unsigned func: 6;
81f58c7388Spefo 	} FRType;
82bb80a8d6Smiod 
83bb80a8d6Smiod 	struct {
84bb80a8d6Smiod 		unsigned op: 6;		/* COP1X */
85bb80a8d6Smiod 		unsigned fr: 5;
86bb80a8d6Smiod 		unsigned ft: 5;
87bb80a8d6Smiod 		unsigned fs: 5;
88bb80a8d6Smiod 		unsigned fd: 5;
89bb80a8d6Smiod 		unsigned op4: 3;
90bb80a8d6Smiod 		unsigned fmt3: 3;
91bb80a8d6Smiod 	} FQType;
92f58c7388Spefo #endif
93f58c7388Spefo #if BYTE_ORDER == LITTLE_ENDIAN
94f58c7388Spefo 	struct {
95f58c7388Spefo 		unsigned imm: 16;
96f58c7388Spefo 		unsigned rt: 5;
97f58c7388Spefo 		unsigned rs: 5;
98f58c7388Spefo 		unsigned op: 6;
99f58c7388Spefo 	} IType;
100f58c7388Spefo 
101f58c7388Spefo 	struct {
102f58c7388Spefo 		unsigned target: 26;
103f58c7388Spefo 		unsigned op: 6;
104f58c7388Spefo 	} JType;
105f58c7388Spefo 
106f58c7388Spefo 	struct {
107f58c7388Spefo 		unsigned func: 6;
108f58c7388Spefo 		unsigned shamt: 5;
109f58c7388Spefo 		unsigned rd: 5;
110f58c7388Spefo 		unsigned rt: 5;
111f58c7388Spefo 		unsigned rs: 5;
112f58c7388Spefo 		unsigned op: 6;
113f58c7388Spefo 	} RType;
114f58c7388Spefo 
115f58c7388Spefo 	struct {
116f58c7388Spefo 		unsigned func: 6;
117f58c7388Spefo 		unsigned fd: 5;
118f58c7388Spefo 		unsigned fs: 5;
119f58c7388Spefo 		unsigned ft: 5;
120f58c7388Spefo 		unsigned fmt: 4;
121f58c7388Spefo 		unsigned : 1;		/* always '1' */
122bb80a8d6Smiod 		unsigned op: 6;		/* COP1 */
123f58c7388Spefo 	} FRType;
124bb80a8d6Smiod 
125bb80a8d6Smiod 	struct {
126bb80a8d6Smiod 		unsigned fmt3: 3;
127bb80a8d6Smiod 		unsigned op4: 3;
128bb80a8d6Smiod 		unsigned fd: 5;
129bb80a8d6Smiod 		unsigned fs: 5;
130bb80a8d6Smiod 		unsigned ft: 5;
131bb80a8d6Smiod 		unsigned fr: 5;
132bb80a8d6Smiod 		unsigned op: 6;		/* COP1X */
133bb80a8d6Smiod 	} FQType;
134f58c7388Spefo #endif
135f58c7388Spefo } InstFmt;
136f58c7388Spefo 
137f58c7388Spefo /*
138f58c7388Spefo  * Values for the 'op' field.
139f58c7388Spefo  */
140f58c7388Spefo #define	OP_SPECIAL	000
141f58c7388Spefo #define	OP_BCOND	001
142f58c7388Spefo #define	OP_J		002
143f58c7388Spefo #define	OP_JAL		003
144f58c7388Spefo #define	OP_BEQ		004
145f58c7388Spefo #define	OP_BNE		005
146f58c7388Spefo #define	OP_BLEZ		006
147f58c7388Spefo #define	OP_BGTZ		007
148f58c7388Spefo 
149f58c7388Spefo #define	OP_ADDI		010
150f58c7388Spefo #define	OP_ADDIU	011
151f58c7388Spefo #define	OP_SLTI		012
152f58c7388Spefo #define	OP_SLTIU	013
153f58c7388Spefo #define	OP_ANDI		014
154f58c7388Spefo #define	OP_ORI		015
155f58c7388Spefo #define	OP_XORI		016
156f58c7388Spefo #define	OP_LUI		017
157f58c7388Spefo 
158f58c7388Spefo #define	OP_COP0		020
159f58c7388Spefo #define	OP_COP1		021
160f58c7388Spefo #define	OP_COP2		022
161f58c7388Spefo #define	OP_COP3		023
162bb80a8d6Smiod #define	OP_COP1X	023
163f58c7388Spefo #define	OP_BEQL		024
164f58c7388Spefo #define	OP_BNEL		025
165f58c7388Spefo #define	OP_BLEZL	026
166f58c7388Spefo #define	OP_BGTZL	027
167f58c7388Spefo 
168f58c7388Spefo #define	OP_DADDI	030
169f58c7388Spefo #define	OP_DADDIU	031
170f58c7388Spefo #define	OP_LDL		032
171f58c7388Spefo #define	OP_LDR		033
172f58c7388Spefo 
173*2fef4a92Svisa #define	OP_SPECIAL3	037
174*2fef4a92Svisa 
175f58c7388Spefo #define	OP_LB		040
176f58c7388Spefo #define	OP_LH		041
177f58c7388Spefo #define	OP_LWL		042
178f58c7388Spefo #define	OP_LW		043
179f58c7388Spefo #define	OP_LBU		044
180f58c7388Spefo #define	OP_LHU		045
181f58c7388Spefo #define	OP_LWR		046
182f58c7388Spefo #define	OP_LWU		047
183f58c7388Spefo 
184f58c7388Spefo #define	OP_SB		050
185f58c7388Spefo #define	OP_SH		051
186f58c7388Spefo #define	OP_SWL		052
187f58c7388Spefo #define	OP_SW		053
188f58c7388Spefo #define	OP_SDL		054
189f58c7388Spefo #define	OP_SDR		055
190f58c7388Spefo #define	OP_SWR		056
191f58c7388Spefo #define	OP_CACHE	057
192f58c7388Spefo 
193f58c7388Spefo #define	OP_LL		060
194f58c7388Spefo #define	OP_LWC1		061
195f58c7388Spefo #define	OP_LWC2		062
196f58c7388Spefo #define	OP_LWC3		063
197bb80a8d6Smiod #define	OP_PREF		063
198f58c7388Spefo #define	OP_LLD		064
199bb80a8d6Smiod #define	OP_LDC1		065
200bb80a8d6Smiod #define	OP_LDC2		066
201f58c7388Spefo #define	OP_LD		067
202f58c7388Spefo 
203f58c7388Spefo #define	OP_SC		070
204f58c7388Spefo #define	OP_SWC1		071
205f58c7388Spefo #define	OP_SWC2		072
206f58c7388Spefo #define	OP_SWC3		073
207f58c7388Spefo #define	OP_SCD		074
208bb80a8d6Smiod #define	OP_SDC1		075
209bb80a8d6Smiod #define	OP_SDC2		076
210f58c7388Spefo #define	OP_SD		077
211f58c7388Spefo 
212f58c7388Spefo /*
213f58c7388Spefo  * Values for the 'func' field when 'op' == OP_SPECIAL.
214f58c7388Spefo  */
215f58c7388Spefo #define	OP_SLL		000
216bb80a8d6Smiod #define	OP_MOVCI	001
217f58c7388Spefo #define	OP_SRL		002
218f58c7388Spefo #define	OP_SRA		003
219f58c7388Spefo #define	OP_SLLV		004
220f58c7388Spefo #define	OP_SRLV		006
221f58c7388Spefo #define	OP_SRAV		007
222f58c7388Spefo 
223f58c7388Spefo #define	OP_JR		010
224f58c7388Spefo #define	OP_JALR		011
225bb80a8d6Smiod #define	OP_MOVZ		012
226bb80a8d6Smiod #define	OP_MOVN		013
227f58c7388Spefo #define	OP_SYSCALL	014
228f58c7388Spefo #define	OP_BREAK	015
229f58c7388Spefo #define	OP_SYNC		017
230f58c7388Spefo 
231f58c7388Spefo #define	OP_MFHI		020
232f58c7388Spefo #define	OP_MTHI		021
233f58c7388Spefo #define	OP_MFLO		022
234f58c7388Spefo #define	OP_MTLO		023
235f58c7388Spefo #define	OP_DSLLV	024
236f58c7388Spefo #define	OP_DSRLV	026
237f58c7388Spefo #define	OP_DSRAV	027
238f58c7388Spefo 
239f58c7388Spefo #define	OP_MULT		030
240f58c7388Spefo #define	OP_MULTU	031
241f58c7388Spefo #define	OP_DIV		032
242f58c7388Spefo #define	OP_DIVU		033
243f58c7388Spefo #define	OP_DMULT	034
244f58c7388Spefo #define	OP_DMULTU	035
245f58c7388Spefo #define	OP_DDIV		036
246f58c7388Spefo #define	OP_DDIVU	037
247f58c7388Spefo 
248f58c7388Spefo #define	OP_ADD		040
249f58c7388Spefo #define	OP_ADDU		041
250f58c7388Spefo #define	OP_SUB		042
251f58c7388Spefo #define	OP_SUBU		043
252f58c7388Spefo #define	OP_AND		044
253f58c7388Spefo #define	OP_OR		045
254f58c7388Spefo #define	OP_XOR		046
255f58c7388Spefo #define	OP_NOR		047
256f58c7388Spefo 
257f58c7388Spefo #define	OP_SLT		052
258f58c7388Spefo #define	OP_SLTU		053
259f58c7388Spefo #define	OP_DADD		054
260f58c7388Spefo #define	OP_DADDU	055
261f58c7388Spefo #define	OP_DSUB		056
262f58c7388Spefo #define	OP_DSUBU	057
263f58c7388Spefo 
264f58c7388Spefo #define	OP_TGE		060
265f58c7388Spefo #define	OP_TGEU		061
266f58c7388Spefo #define	OP_TLT		062
267f58c7388Spefo #define	OP_TLTU		063
268f58c7388Spefo #define	OP_TEQ		064
269f58c7388Spefo #define	OP_TNE		066
270f58c7388Spefo 
271f58c7388Spefo #define	OP_DSLL		070
272f58c7388Spefo #define	OP_DSRL		072
273f58c7388Spefo #define	OP_DSRA		073
274f58c7388Spefo #define	OP_DSLL32	074
275f58c7388Spefo #define	OP_DSRL32	076
276f58c7388Spefo #define	OP_DSRA32	077
277f58c7388Spefo 
278f58c7388Spefo /*
279944cd5b7Smiod  * Values for the 'rt' field when 'op' == OP_BCOND.
280f58c7388Spefo  */
281f58c7388Spefo #define	OP_BLTZ		000
282f58c7388Spefo #define	OP_BGEZ		001
283f58c7388Spefo #define	OP_BLTZL	002
284f58c7388Spefo #define	OP_BGEZL	003
285f58c7388Spefo 
286f58c7388Spefo #define	OP_TGEI		010
287f58c7388Spefo #define	OP_TGEIU	011
288f58c7388Spefo #define	OP_TLTI		012
289f58c7388Spefo #define	OP_TLTIU	013
290f58c7388Spefo #define	OP_TEQI		014
291f58c7388Spefo #define	OP_TNEI		016
292f58c7388Spefo 
293f58c7388Spefo #define	OP_BLTZAL	020
294f58c7388Spefo #define	OP_BGEZAL	021
295f58c7388Spefo #define	OP_BLTZALL	022
296f58c7388Spefo #define	OP_BGEZALL	023
297f58c7388Spefo 
298f58c7388Spefo /*
29912a2e78eSmiod  * Values for the 'rs' field when 'op' == OP_COPz.
30012a2e78eSmiod  */
30112a2e78eSmiod #define	OP_MF		000
30212a2e78eSmiod #define	OP_DMF		001
30312a2e78eSmiod #define	OP_CF		002
30412a2e78eSmiod #define	OP_MFH		003
30512a2e78eSmiod #define	OP_MT		004
30612a2e78eSmiod #define	OP_DMT		005
30712a2e78eSmiod #define	OP_CT		006
30812a2e78eSmiod #define	OP_MTH		007
30912a2e78eSmiod #define	OP_BC		010
31012a2e78eSmiod #define	OP_C0MISC	020	/* cop0 only */
311a4a4ed5cSmiod #define	OP_TFP_C0MISC	030	/* cop0 only on R8000 */
31212a2e78eSmiod 
31312a2e78eSmiod /*
31412a2e78eSmiod  * Values for the 'rt' field when 'op' == OP_COPz.
31512a2e78eSmiod  */
31612a2e78eSmiod #define	COPz_BC_TF_MASK		0x01
31712a2e78eSmiod #define	COPz_BC_TRUE		0x01
31812a2e78eSmiod #define	COPz_BC_FALSE		0x00
31912a2e78eSmiod #define	COPz_BCL_TF_MASK	0x02
32012a2e78eSmiod #define	COPz_BCL_TRUE		0x02
32112a2e78eSmiod #define	COPz_BCL_FALSE		0x00
32212a2e78eSmiod #define	COPz_BC_CC_MASK		0x1c
32312a2e78eSmiod #define	COPz_BC_CC_SHIFT	2
32412a2e78eSmiod 
32512a2e78eSmiod /*
326bb80a8d6Smiod  * Values for the 'func' field when 'op' == OP_COP1X.
327bb80a8d6Smiod  */
328bb80a8d6Smiod #define	OP_LWXC1	000
329bb80a8d6Smiod #define	OP_LDXC1	001
330bb80a8d6Smiod #define	OP_SWXC1	010
331bb80a8d6Smiod #define	OP_SDXC1	011
332bb80a8d6Smiod #define	OP_PREFX	017
333bb80a8d6Smiod 
334bb80a8d6Smiod /*
335bb80a8d6Smiod  * Values for the 'op4' field when 'op' == OP_COP1X.
336bb80a8d6Smiod  */
337bb80a8d6Smiod #define	OP_MADD		04
338bb80a8d6Smiod #define	OP_MSUB		05
339bb80a8d6Smiod #define	OP_NMADD	06
340bb80a8d6Smiod #define	OP_NMSUB	07
341bb80a8d6Smiod 
342*2fef4a92Svisa /*
343*2fef4a92Svisa  * Values for the 'func' field when 'op' == OP_SPECIAL3.
344*2fef4a92Svisa  */
345*2fef4a92Svisa #define	OP_RDHWR	073
346*2fef4a92Svisa 
3472fa72412Spirofti #endif /* !_MIPS64_MIPS_OPCODE_H_ */
348