xref: /freebsd/sys/powerpc/fpu/fpu_instr.h (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1 /*	$NetBSD: instr.h,v 1.4 2005/12/11 12:18:43 christos Exp $ */
2 /* $FreeBSD$ */
3 
4 /*-
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Copyright (c) 1992, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * This software was developed by the Computer Systems Engineering group
11  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
12  * contributed to Berkeley.
13  *
14  * All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  *	This product includes software developed by the University of
17  *	California, Lawrence Berkeley Laboratory.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  * 1. Redistributions of source code must retain the above copyright
23  *    notice, this list of conditions and the following disclaimer.
24  * 2. Redistributions in binary form must reproduce the above copyright
25  *    notice, this list of conditions and the following disclaimer in the
26  *    documentation and/or other materials provided with the distribution.
27  * 3. Neither the name of the University nor the names of its contributors
28  *    may be used to endorse or promote products derived from this software
29  *    without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41  * SUCH DAMAGE.
42  *
43  *	@(#)instr.h	8.1 (Berkeley) 6/11/93
44  */
45 
46 /*
47  * An instruction.
48  */
49 union instr {
50 	int	i_int;			/* as a whole */
51 
52 	/*
53 	 * Any instruction type.
54 	 */
55 	struct {
56 		u_int	i_opcd:6;	/* first-level decode */
57 		u_int	:25;
58 		u_int	i_rc:1;
59 	} i_any;
60 
61 	/*
62 	 * Format A
63 	 */
64 	struct {
65 		u_int	i_opcd:6;
66 		u_int	i_frt:5;
67 		u_int	i_fra:5;
68 		u_int	i_frb:5;
69 		u_int	i_frc:5;
70 		u_int	i_xo:5;
71 		u_int	i_rc:1;
72 	} i_a;
73 
74 	/*
75 	 * Format B
76 	 */
77 	struct {
78 		u_int	i_opcd:6;
79 		int	i_bo:5;
80 		int	i_bi:5;
81 		int	i_bd:14;
82 		int	i_aa:1;
83 		int	i_lk:1;
84 	} i_b;
85 
86 	/*
87 	 * Format D
88 	 */
89 	struct {
90 		u_int	i_opcd:6;
91 		u_int	i_rs:5;
92 		u_int	i_ra:5;
93 		int	i_d:16;
94 	} i_d;
95 
96 	/*
97 	 * Format DE
98 	 */
99 	struct {
100 		u_int	i_opcd:6;
101 		u_int	i_rs:5;
102 		u_int	i_ra:5;
103 		int	i_d:12;
104 		u_int	i_xo:4;
105 	} i_de;
106 
107 	/*
108 	 * Format I
109 	 */
110 	struct {
111 		u_int	i_opcd:6;
112 		int	i_li:24;
113 		int	i_aa:1;
114 		int	i_lk:1;
115 	} i_i;
116 
117 	/*
118 	 * Format M
119 	 */
120 	struct {
121 		u_int	i_opcd:6;
122 		u_int	i_rs:5;
123 		u_int	i_ra:5;
124 		u_int	i_rb:5;
125 		int	i_mb:5;
126 		int	i_me:5;
127 		u_int	i_rc:1;
128 	} i_m;
129 
130 	/*
131 	 * Format MD
132 	 */
133 	struct {
134 		u_int	i_opcd:6;
135 		u_int	i_rs:5;
136 		u_int	i_ra:5;
137 		u_int	i_rb:5;
138 		int	i_sh1_5:5;
139 		int	i_mb:6;
140 		u_int	i_xo:3;
141 		int	i_sh0:2;
142 		u_int	i_rc:1;
143 	} i_md;
144 
145 	/*
146 	 * Format MDS
147 	 */
148 	struct {
149 		u_int	i_opcd:6;
150 		u_int	i_rs:5;
151 		u_int	i_ra:5;
152 		u_int	i_rb:5;
153 		int	i_sh:5;
154 		int	i_mb:6;
155 		u_int	i_xo:4;
156 		u_int	i_rc:1;
157 	} i_mds;
158 
159 	/*
160 	 * Format S
161 	 */
162 	struct {
163 		u_int	i_opcd:6;
164 		int	:24;
165 		int	i_i:1;
166 		int	:1;
167 	} i_s;
168 
169 	/*
170 	 * Format X
171 	 */
172 	struct {
173 		u_int	i_opcd:6;
174 		u_int	i_rs:5;
175 		u_int	i_ra:5;
176 		u_int	i_rb:5;
177 		u_int	i_xo:10;
178 		u_int	i_rc:1;
179 	} i_x;
180 
181 	/*
182 	 * Format XFL
183 	 */
184 	struct {
185 		u_int	i_opcd:6;
186 		int	:1;
187 		int	i_flm:8;
188 		int	:1;
189 		int	i_frb:5;
190 		u_int	i_xo:10;
191 		int	:1;
192 	} i_xfl;
193 
194 	/*
195 	 * Format XFX
196 	 */
197 	struct {
198 		u_int	i_opcd:6;
199 		int	i_dcrn:10;
200 		u_int	i_xo:10;
201 		int	:1;
202 	} i_xfx;
203 
204 	/*
205 	 * Format XL
206 	 */
207 	struct {
208 		u_int	i_opcd:6;
209 		int	i_bt:5;
210 		int	i_ba:5;
211 		int	i_bb:5;
212 		u_int	i_xo:10;
213 		int	i_lk:1;
214 	} i_xl;
215 
216 	/*
217 	 * Format XS
218 	 */
219 	struct {
220 		u_int	i_opcd:6;
221 		u_int	i_rs:5;
222 		u_int	i_ra:5;
223 		int	i_sh0_4:5;
224 		u_int	i_xo:9;
225 		int	i_sh5:1;
226 		u_int	i_rc:1;
227 	} i_xs;
228 
229 };
230 
231 #define	i_rt	i_rs
232 
233 /*
234  * Primary opcode numbers:
235  */
236 
237 #define	OPC_TDI		0x02
238 #define	OPC_TWI		0x03
239 #define	OPC_MULLI	0x07
240 #define	OPC_SUBFIC	0x08
241 #define	OPC_BCE		0x09
242 #define	OPC_CMPLI	0x0a
243 #define	OPC_CMPI	0x0b
244 #define	OPC_ADDIC	0x0c
245 #define	OPC_ADDIC_DOT	0x0d
246 #define	OPC_ADDI	0x0e
247 #define	OPC_ADDIS	0x0f
248 #define	OPC_BC		0x10
249 #define	OPC_SC		0x11
250 #define	OPC_B		0x12
251 #define	OPC_branch_19	0x13
252 #define	OPC_RLWIMI	0x14
253 #define	OPC_RLWINM	0x15
254 #define	OPC_BE		0x16
255 #define	OPC_RLWNM	0x17
256 #define	OPC_ORI		0x18
257 #define	OPC_ORIS	0x19
258 #define	OPC_XORI	0x1a
259 #define	OPC_XORIS	0x1b
260 #define	OPC_ANDI	0x1c
261 #define	OPC_ANDIS	0x1d
262 #define	OPC_dwe_rot_30	0x1e
263 #define	OPC_integer_31	0x1f
264 #define	OPC_LWZ		0x20
265 #define	OPC_LWZU	0x21
266 #define	OPC_LBZ		0x22
267 #define	OPC_LBZU	0x23
268 #define	OPC_STW		0x24
269 #define	OPC_STWU	0x25
270 #define	OPC_STB		0x26
271 #define	OPC_STBU	0x27
272 #define	OPC_LHZ		0x28
273 #define	OPC_LHZU	0x29
274 #define	OPC_LHA		0x2a
275 #define	OPC_LHAU	0x2b
276 #define	OPC_STH		0x2c
277 #define	OPC_STHU	0x2d
278 #define	OPC_LMW		0x2e
279 #define	OPC_STMW	0x2f
280 #define	OPC_LFS		0x30
281 #define	OPC_LFSU	0x31
282 #define	OPC_LFD		0x32
283 #define	OPC_LFDU	0x33
284 #define	OPC_STFS	0x34
285 #define	OPC_STFSU	0x35
286 #define	OPC_STFD	0x36
287 #define	OPC_STFDU	0x37
288 #define	OPC_load_st_58	0x3a
289 #define	OPC_sp_fp_59	0x3b
290 #define	OPC_load_st_62	0x3e
291 #define	OPC_dp_fp_63	0x3f
292 
293 /*
294  * Opcode 31 sub-types (FP only)
295  */
296 #define	OPC31_TW	0x004
297 #define	OPC31_LFSX	0x217
298 #define	OPC31_LFSUX	0x237
299 #define	OPC31_LFDX	0x257
300 #define	OPC31_LFDUX	0x277
301 #define	OPC31_STFSX	0x297
302 #define	OPC31_STFSUX	0x2b7
303 #define	OPC31_STFDX	0x2d7
304 #define	OPC31_STFDUX	0x2f7
305 #define	OPC31_STFIWX	0x3d7
306 
307 /* Mask for all valid indexed FP load/store ops (except stfiwx) */
308 #define	OPC31_FPMASK	0x31f
309 #define	OPC31_FPOP	0x217
310 
311 /*
312  * Opcode 59 sub-types:
313  */
314 
315 #define	OPC59_FDIVS	0x12
316 #define	OPC59_FSUBS	0x14
317 #define	OPC59_FADDS	0x15
318 #define	OPC59_FSQRTS	0x16
319 #define	OPC59_FRES	0x18
320 #define	OPC59_FMULS	0x19
321 #define	OPC59_FMSUBS	0x1c
322 #define	OPC59_FMADDS	0x1d
323 #define	OPC59_FNMSUBS	0x1e
324 #define	OPC59_FNMADDS	0x1f
325 
326 /*
327  * Opcode 62 sub-types:
328  */
329 #define	OPC62_LDE	0x0
330 #define	OPC62_LDEU	0x1
331 #define	OPC62_LFSE	0x4
332 #define	OPC62_LFSEU	0x5
333 #define	OPC62_LFDE	0x6
334 #define	OPC62_LFDEU	0x7
335 #define	OPC62_STDE	0x8
336 #define	OPC62_STDEU	0x9
337 #define	OPC62_STFSE	0xc
338 #define	OPC62_STFSEU	0xd
339 #define	OPC62_STFDE	0xe
340 #define	OPC62_STFDEU	0xf
341 
342 /*
343  * Opcode 63 sub-types:
344  *
345  * (The first group are masks....)
346  */
347 
348 #define	OPC63M_MASK	0x10
349 #define	OPC63M_FDIV	0x12
350 #define	OPC63M_FSUB	0x14
351 #define	OPC63M_FADD	0x15
352 #define	OPC63M_FSQRT	0x16
353 #define	OPC63M_FSEL	0x17
354 #define	OPC63M_FMUL	0x19
355 #define	OPC63M_FRSQRTE	0x1a
356 #define	OPC63M_FMSUB	0x1c
357 #define	OPC63M_FMADD	0x1d
358 #define	OPC63M_FNMSUB	0x1e
359 #define	OPC63M_FNMADD	0x1f
360 
361 #define	OPC63_FCMPU	0x00
362 #define	OPC63_FRSP	0x0c
363 #define	OPC63_FCTIW	0x0e
364 #define	OPC63_FCTIWZ	0x0f
365 #define	OPC63_FCMPO	0x20
366 #define	OPC63_MTFSB1	0x26
367 #define	OPC63_FNEG	0x28
368 #define	OPC63_MCRFS	0x40
369 #define	OPC63_MTFSB0	0x46
370 #define	OPC63_FMR	0x48
371 #define	OPC63_MTFSFI	0x86
372 #define	OPC63_FNABS	0x88
373 #define	OPC63_FABS	0x108
374 #define	OPC63_MFFS	0x247
375 #define	OPC63_MTFSF	0x2c7
376 #define	OPC63_FCTID	0x32e
377 #define	OPC63_FCTIDZ	0x32f
378 #define	OPC63_FCFID	0x34e
379 
380 /*
381  * FPU data types.
382  */
383 #define FTYPE_LNG	-1	/* data = 64-bit signed long integer */
384 #define	FTYPE_INT	0	/* data = 32-bit signed integer */
385 #define	FTYPE_SNG	1	/* data = 32-bit float */
386 #define	FTYPE_DBL	2	/* data = 64-bit double */
387