1176491Smarcel/*	$NetBSD: instr.h,v 1.4 2005/12/11 12:18:43 christos Exp $ */
2176491Smarcel/* $FreeBSD$ */
3176491Smarcel
4176491Smarcel/*
5176491Smarcel * Copyright (c) 1992, 1993
6176491Smarcel *	The Regents of the University of California.  All rights reserved.
7176491Smarcel *
8176491Smarcel * This software was developed by the Computer Systems Engineering group
9176491Smarcel * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10176491Smarcel * contributed to Berkeley.
11176491Smarcel *
12176491Smarcel * All advertising materials mentioning features or use of this software
13176491Smarcel * must display the following acknowledgement:
14176491Smarcel *	This product includes software developed by the University of
15176491Smarcel *	California, Lawrence Berkeley Laboratory.
16176491Smarcel *
17176491Smarcel * Redistribution and use in source and binary forms, with or without
18176491Smarcel * modification, are permitted provided that the following conditions
19176491Smarcel * are met:
20176491Smarcel * 1. Redistributions of source code must retain the above copyright
21176491Smarcel *    notice, this list of conditions and the following disclaimer.
22176491Smarcel * 2. Redistributions in binary form must reproduce the above copyright
23176491Smarcel *    notice, this list of conditions and the following disclaimer in the
24176491Smarcel *    documentation and/or other materials provided with the distribution.
25176491Smarcel * 3. Neither the name of the University nor the names of its contributors
26176491Smarcel *    may be used to endorse or promote products derived from this software
27176491Smarcel *    without specific prior written permission.
28176491Smarcel *
29176491Smarcel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30176491Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31176491Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32176491Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33176491Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34176491Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35176491Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36176491Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37176491Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38176491Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39176491Smarcel * SUCH DAMAGE.
40176491Smarcel *
41176491Smarcel *	@(#)instr.h	8.1 (Berkeley) 6/11/93
42176491Smarcel */
43176491Smarcel
44176491Smarcel/*
45176491Smarcel * An instruction.
46176491Smarcel */
47176491Smarcelunion instr {
48176491Smarcel	int	i_int;			/* as a whole */
49176491Smarcel
50176491Smarcel	/*
51176491Smarcel	 * Any instruction type.
52176491Smarcel	 */
53176491Smarcel	struct {
54176491Smarcel		u_int	i_opcd:6;	/* first-level decode */
55176491Smarcel		u_int	:25;
56176491Smarcel		u_int	i_rc:1;
57176491Smarcel	} i_any;
58176491Smarcel
59176491Smarcel	/*
60176491Smarcel	 * Format A
61176491Smarcel	 */
62176491Smarcel	struct {
63176491Smarcel		u_int	i_opcd:6;
64176491Smarcel		u_int	i_frt:5;
65176491Smarcel		u_int	i_fra:5;
66176491Smarcel		u_int	i_frb:5;
67176491Smarcel		u_int	i_frc:5;
68176491Smarcel		u_int	i_xo:5;
69176491Smarcel		u_int	i_rc:1;
70176491Smarcel	} i_a;
71176491Smarcel
72176491Smarcel	/*
73176491Smarcel	 * Format B
74176491Smarcel	 */
75176491Smarcel	struct {
76176491Smarcel		u_int	i_opcd:6;
77176491Smarcel		int	i_bo:5;
78176491Smarcel		int	i_bi:5;
79176491Smarcel		int	i_bd:14;
80176491Smarcel		int	i_aa:1;
81176491Smarcel		int	i_lk:1;
82176491Smarcel	} i_b;
83176491Smarcel
84176491Smarcel	/*
85176491Smarcel	 * Format D
86176491Smarcel	 */
87176491Smarcel	struct {
88176491Smarcel		u_int	i_opcd:6;
89176491Smarcel		u_int	i_rs:5;
90176491Smarcel		u_int	i_ra:5;
91176491Smarcel		int	i_d:16;
92176491Smarcel	} i_d;
93176491Smarcel
94176491Smarcel	/*
95176491Smarcel	 * Format DE
96176491Smarcel	 */
97176491Smarcel	struct {
98176491Smarcel		u_int	i_opcd:6;
99176491Smarcel		u_int	i_rs:5;
100176491Smarcel		u_int	i_ra:5;
101176491Smarcel		int	i_d:12;
102176491Smarcel		u_int	i_xo:4;
103176491Smarcel	} i_de;
104176491Smarcel
105176491Smarcel	/*
106176491Smarcel	 * Format I
107176491Smarcel	 */
108176491Smarcel	struct {
109176491Smarcel		u_int	i_opcd:6;
110176491Smarcel		int	i_li:24;
111176491Smarcel		int	i_aa:1;
112176491Smarcel		int	i_lk:1;
113176491Smarcel	} i_i;
114176491Smarcel
115176491Smarcel	/*
116176491Smarcel	 * Format M
117176491Smarcel	 */
118176491Smarcel	struct {
119176491Smarcel		u_int	i_opcd:6;
120176491Smarcel		u_int	i_rs:5;
121176491Smarcel		u_int	i_ra:5;
122176491Smarcel		u_int	i_rb:5;
123176491Smarcel		int	i_mb:5;
124176491Smarcel		int	i_me:5;
125176491Smarcel		u_int	i_rc:1;
126176491Smarcel	} i_m;
127176491Smarcel
128176491Smarcel	/*
129176491Smarcel	 * Format MD
130176491Smarcel	 */
131176491Smarcel	struct {
132176491Smarcel		u_int	i_opcd:6;
133176491Smarcel		u_int	i_rs:5;
134176491Smarcel		u_int	i_ra:5;
135176491Smarcel		u_int	i_rb:5;
136176491Smarcel		int	i_sh1_5:5;
137176491Smarcel		int	i_mb:6;
138176491Smarcel		u_int	i_xo:3;
139176491Smarcel		int	i_sh0:2;
140176491Smarcel		u_int	i_rc:1;
141176491Smarcel	} i_md;
142176491Smarcel
143176491Smarcel	/*
144176491Smarcel	 * Format MDS
145176491Smarcel	 */
146176491Smarcel	struct {
147176491Smarcel		u_int	i_opcd:6;
148176491Smarcel		u_int	i_rs:5;
149176491Smarcel		u_int	i_ra:5;
150176491Smarcel		u_int	i_rb:5;
151176491Smarcel		int	i_sh:5;
152176491Smarcel		int	i_mb:6;
153176491Smarcel		u_int	i_xo:4;
154176491Smarcel		u_int	i_rc:1;
155176491Smarcel	} i_mds;
156176491Smarcel
157176491Smarcel
158176491Smarcel	/*
159176491Smarcel	 * Format S
160176491Smarcel	 */
161176491Smarcel	struct {
162176491Smarcel		u_int	i_opcd:6;
163176491Smarcel		int	:24;
164176491Smarcel		int	i_i:1;
165176491Smarcel		int	:1;
166176491Smarcel	} i_s;
167176491Smarcel
168176491Smarcel	/*
169176491Smarcel	 * Format X
170176491Smarcel	 */
171176491Smarcel	struct {
172176491Smarcel		u_int	i_opcd:6;
173176491Smarcel		u_int	i_rs:5;
174176491Smarcel		u_int	i_ra:5;
175176491Smarcel		u_int	i_rb:5;
176176491Smarcel		u_int	i_xo:10;
177176491Smarcel		u_int	i_rc:1;
178176491Smarcel	} i_x;
179176491Smarcel
180176491Smarcel	/*
181176491Smarcel	 * Format XFL
182176491Smarcel	 */
183176491Smarcel	struct {
184176491Smarcel		u_int	i_opcd:6;
185176491Smarcel		int	:1;
186176491Smarcel		int	i_flm:8;
187176491Smarcel		int	:1;
188176491Smarcel		int	i_frb:5;
189176491Smarcel		u_int	i_xo:10;
190176491Smarcel		int	:1;
191176491Smarcel	} i_xfl;
192176491Smarcel
193176491Smarcel	/*
194176491Smarcel	 * Format XFX
195176491Smarcel	 */
196176491Smarcel	struct {
197176491Smarcel		u_int	i_opcd:6;
198176491Smarcel		int	i_dcrn:10;
199176491Smarcel		u_int	i_xo:10;
200176491Smarcel		int	:1;
201176491Smarcel	} i_xfx;
202176491Smarcel
203176491Smarcel	/*
204176491Smarcel	 * Format XL
205176491Smarcel	 */
206176491Smarcel	struct {
207176491Smarcel		u_int	i_opcd:6;
208176491Smarcel		int	i_bt:5;
209176491Smarcel		int	i_ba:5;
210176491Smarcel		int	i_bb:5;
211176491Smarcel		u_int	i_xo:10;
212176491Smarcel		int	i_lk:1;
213176491Smarcel	} i_xl;
214176491Smarcel
215176491Smarcel	/*
216176491Smarcel	 * Format XS
217176491Smarcel	 */
218176491Smarcel	struct {
219176491Smarcel		u_int	i_opcd:6;
220176491Smarcel		u_int	i_rs:5;
221176491Smarcel		u_int	i_ra:5;
222176491Smarcel		int	i_sh0_4:5;
223176491Smarcel		u_int	i_xo:9;
224176491Smarcel		int	i_sh5:1;
225176491Smarcel		u_int	i_rc:1;
226176491Smarcel	} i_xs;
227176491Smarcel
228176491Smarcel};
229176491Smarcel
230176491Smarcel#define	i_rt	i_rs
231176491Smarcel
232176491Smarcel/*
233176491Smarcel * Primary opcode numbers:
234176491Smarcel */
235176491Smarcel
236176491Smarcel#define	OPC_TDI		0x02
237176491Smarcel#define	OPC_TWI		0x03
238176491Smarcel#define	OPC_MULLI	0x07
239176491Smarcel#define	OPC_SUBFIC	0x08
240176491Smarcel#define	OPC_BCE		0x09
241176491Smarcel#define	OPC_CMPLI	0x0a
242176491Smarcel#define	OPC_CMPI	0x0b
243176491Smarcel#define	OPC_ADDIC	0x0c
244176491Smarcel#define	OPC_ADDIC_DOT	0x0d
245176491Smarcel#define	OPC_ADDI	0x0e
246176491Smarcel#define	OPC_ADDIS	0x0f
247176491Smarcel#define	OPC_BC		0x10
248176491Smarcel#define	OPC_SC		0x11
249176491Smarcel#define	OPC_B		0x12
250176491Smarcel#define	OPC_branch_19	0x13
251176491Smarcel#define	OPC_RLWIMI	0x14
252176491Smarcel#define	OPC_RLWINM	0x15
253176491Smarcel#define	OPC_BE		0x16
254176491Smarcel#define	OPC_RLWNM	0x17
255176491Smarcel#define	OPC_ORI		0x18
256176491Smarcel#define	OPC_ORIS	0x19
257176491Smarcel#define	OPC_XORI	0x1a
258176491Smarcel#define	OPC_XORIS	0x1b
259176491Smarcel#define	OPC_ANDI	0x1c
260176491Smarcel#define	OPC_ANDIS	0x1d
261176491Smarcel#define	OPC_dwe_rot_30	0x1e
262176491Smarcel#define	OPC_integer_31	0x1f
263176491Smarcel#define	OPC_LWZ		0x20
264176491Smarcel#define	OPC_LWZU	0x21
265176491Smarcel#define	OPC_LBZ		0x22
266176491Smarcel#define	OPC_LBZU	0x23
267176491Smarcel#define	OPC_STW		0x24
268176491Smarcel#define	OPC_STWU	0x25
269176491Smarcel#define	OPC_STB		0x26
270176491Smarcel#define	OPC_STBU	0x27
271176491Smarcel#define	OPC_LHZ		0x28
272176491Smarcel#define	OPC_LHZU	0x29
273176491Smarcel#define	OPC_LHA		0x2a
274176491Smarcel#define	OPC_LHAU	0x2b
275176491Smarcel#define	OPC_STH		0x2c
276176491Smarcel#define	OPC_STHU	0x2d
277176491Smarcel#define	OPC_LMW		0x2e
278176491Smarcel#define	OPC_STMW	0x2f
279176491Smarcel#define	OPC_LFS		0x30
280176491Smarcel#define	OPC_LFSU	0x31
281176491Smarcel#define	OPC_LFD		0x32
282176491Smarcel#define	OPC_LFDU	0x33
283176491Smarcel#define	OPC_STFS	0x34
284176491Smarcel#define	OPC_STFSU	0x35
285176491Smarcel#define	OPC_STFD	0x36
286176491Smarcel#define	OPC_STFDU	0x37
287176491Smarcel#define	OPC_load_st_58	0x3a
288176491Smarcel#define	OPC_sp_fp_59	0x3b
289176491Smarcel#define	OPC_load_st_62	0x3e
290176491Smarcel#define	OPC_dp_fp_63	0x3f
291176491Smarcel
292176491Smarcel/*
293176491Smarcel * Opcode 31 sub-types (FP only)
294176491Smarcel */
295176491Smarcel#define	OPC31_TW	0x004
296176491Smarcel#define	OPC31_LFSX	0x217
297176491Smarcel#define	OPC31_LFSUX	0x237
298176491Smarcel#define	OPC31_LFDX	0x257
299176491Smarcel#define	OPC31_LFDUX	0x277
300176491Smarcel#define	OPC31_STFSX	0x297
301176491Smarcel#define	OPC31_STFSUX	0x2b7
302176491Smarcel#define	OPC31_STFDX	0x2d7
303176491Smarcel#define	OPC31_STFDUX	0x2f7
304176491Smarcel#define	OPC31_STFIWX	0x3d7
305176491Smarcel
306176491Smarcel/* Mask for all valid indexed FP load/store ops (except stfiwx) */
307176491Smarcel#define	OPC31_FPMASK	0x31f
308176491Smarcel#define	OPC31_FPOP	0x217
309176491Smarcel
310176491Smarcel/*
311176491Smarcel * Opcode 59 sub-types:
312176491Smarcel */
313176491Smarcel
314176491Smarcel#define	OPC59_FDIVS	0x12
315176491Smarcel#define	OPC59_FSUBS	0x14
316176491Smarcel#define	OPC59_FADDS	0x15
317176491Smarcel#define	OPC59_FSQRTS	0x16
318176491Smarcel#define	OPC59_FRES	0x18
319176491Smarcel#define	OPC59_FMULS	0x19
320176491Smarcel#define	OPC59_FMSUBS	0x1c
321176491Smarcel#define	OPC59_FMADDS	0x1d
322176491Smarcel#define	OPC59_FNMSUBS	0x1e
323176491Smarcel#define	OPC59_FNMADDS	0x1f
324176491Smarcel
325176491Smarcel/*
326176491Smarcel * Opcode 62 sub-types:
327176491Smarcel */
328176491Smarcel#define	OPC62_LDE	0x0
329176491Smarcel#define	OPC62_LDEU	0x1
330176491Smarcel#define	OPC62_LFSE	0x4
331176491Smarcel#define	OPC62_LFSEU	0x5
332176491Smarcel#define	OPC62_LFDE	0x6
333176491Smarcel#define	OPC62_LFDEU	0x7
334176491Smarcel#define	OPC62_STDE	0x8
335176491Smarcel#define	OPC62_STDEU	0x9
336176491Smarcel#define	OPC62_STFSE	0xc
337176491Smarcel#define	OPC62_STFSEU	0xd
338176491Smarcel#define	OPC62_STFDE	0xe
339176491Smarcel#define	OPC62_STFDEU	0xf
340176491Smarcel
341176491Smarcel/*
342176491Smarcel * Opcode 63 sub-types:
343176491Smarcel *
344176491Smarcel * (The first group are masks....)
345176491Smarcel */
346176491Smarcel
347176491Smarcel#define	OPC63M_MASK	0x10
348176491Smarcel#define	OPC63M_FDIV	0x12
349176491Smarcel#define	OPC63M_FSUB	0x14
350176491Smarcel#define	OPC63M_FADD	0x15
351176491Smarcel#define	OPC63M_FSQRT	0x16
352176491Smarcel#define	OPC63M_FSEL	0x17
353176491Smarcel#define	OPC63M_FMUL	0x19
354176491Smarcel#define	OPC63M_FRSQRTE	0x1a
355176491Smarcel#define	OPC63M_FMSUB	0x1c
356176491Smarcel#define	OPC63M_FMADD	0x1d
357176491Smarcel#define	OPC63M_FNMSUB	0x1e
358176491Smarcel#define	OPC63M_FNMADD	0x1f
359176491Smarcel
360176491Smarcel#define	OPC63_FCMPU	0x00
361176491Smarcel#define	OPC63_FRSP	0x0c
362176491Smarcel#define	OPC63_FCTIW	0x0e
363176491Smarcel#define	OPC63_FCTIWZ	0x0f
364176491Smarcel#define	OPC63_FCMPO	0x20
365176491Smarcel#define	OPC63_MTFSB1	0x26
366176491Smarcel#define	OPC63_FNEG	0x28
367176491Smarcel#define	OPC63_MCRFS	0x40
368176491Smarcel#define	OPC63_MTFSB0	0x46
369176491Smarcel#define	OPC63_FMR	0x48
370176491Smarcel#define	OPC63_MTFSFI	0x86
371176491Smarcel#define	OPC63_FNABS	0x88
372176491Smarcel#define	OPC63_FABS	0x108
373176491Smarcel#define	OPC63_MFFS	0x247
374176491Smarcel#define	OPC63_MTFSF	0x2c7
375176491Smarcel#define	OPC63_FCTID	0x32e
376176491Smarcel#define	OPC63_FCTIDZ	0x32f
377176491Smarcel#define	OPC63_FCFID	0x34e
378176491Smarcel
379176491Smarcel/*
380176491Smarcel * FPU data types.
381176491Smarcel */
382176491Smarcel#define FTYPE_LNG	-1	/* data = 64-bit signed long integer */
383176491Smarcel#define	FTYPE_INT	0	/* data = 32-bit signed integer */
384176491Smarcel#define	FTYPE_SNG	1	/* data = 32-bit float */
385176491Smarcel#define	FTYPE_DBL	2	/* data = 64-bit double */
386176491Smarcel
387