xref: /titanic_44/usr/src/uts/intel/sys/fp.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
28*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
29*7c478bd9Sstevel@tonic-gate /*		All Rights Reserved				*/
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #ifndef _SYS_FP_H
32*7c478bd9Sstevel@tonic-gate #define	_SYS_FP_H
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
37*7c478bd9Sstevel@tonic-gate extern "C" {
38*7c478bd9Sstevel@tonic-gate #endif
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*
41*7c478bd9Sstevel@tonic-gate  * 80287/80387 and SSE/SSE2 floating point processor definitions
42*7c478bd9Sstevel@tonic-gate  */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * values that go into fp_kind
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate #define	FP_NO	0	/* no fp chip, no emulator (no fp support)	*/
48*7c478bd9Sstevel@tonic-gate #define	FP_SW	1	/* no fp chip, using software emulator		*/
49*7c478bd9Sstevel@tonic-gate #define	FP_HW	2	/* chip present bit				*/
50*7c478bd9Sstevel@tonic-gate #define	FP_287	2	/* 80287 chip present				*/
51*7c478bd9Sstevel@tonic-gate #define	FP_387	3	/* 80387 chip present				*/
52*7c478bd9Sstevel@tonic-gate #define	FP_487	6	/* 80487 chip present				*/
53*7c478bd9Sstevel@tonic-gate #define	FP_486	6	/* 80486 chip present				*/
54*7c478bd9Sstevel@tonic-gate #define	__FP_SSE 0x103	/* x87 plus SSE-capable CPU			*/
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate /*
57*7c478bd9Sstevel@tonic-gate  * masks for 80387 control word
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate #define	FPIM	0x00000001	/* invalid operation			*/
60*7c478bd9Sstevel@tonic-gate #define	FPDM	0x00000002	/* denormalized operand			*/
61*7c478bd9Sstevel@tonic-gate #define	FPZM	0x00000004	/* zero divide				*/
62*7c478bd9Sstevel@tonic-gate #define	FPOM	0x00000008	/* overflow				*/
63*7c478bd9Sstevel@tonic-gate #define	FPUM	0x00000010	/* underflow				*/
64*7c478bd9Sstevel@tonic-gate #define	FPPM	0x00000020	/* precision				*/
65*7c478bd9Sstevel@tonic-gate #define	FPPC	0x00000300	/* precision control			*/
66*7c478bd9Sstevel@tonic-gate #define	FPRC	0x00000C00	/* rounding control			*/
67*7c478bd9Sstevel@tonic-gate #define	FPIC	0x00001000	/* infinity control			*/
68*7c478bd9Sstevel@tonic-gate #define	WFPDE	0x00000080	/* data chain exception			*/
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate /*
71*7c478bd9Sstevel@tonic-gate  * (Old symbol compatibility)
72*7c478bd9Sstevel@tonic-gate  */
73*7c478bd9Sstevel@tonic-gate #define	FPINV	FPIM
74*7c478bd9Sstevel@tonic-gate #define	FPDNO	FPDM
75*7c478bd9Sstevel@tonic-gate #define	FPZDIV	FPZM
76*7c478bd9Sstevel@tonic-gate #define	FPOVR	FPOM
77*7c478bd9Sstevel@tonic-gate #define	FPUNR	FPUM
78*7c478bd9Sstevel@tonic-gate #define	FPPRE	FPPM
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate /*
81*7c478bd9Sstevel@tonic-gate  * precision, rounding, and infinity options in control word
82*7c478bd9Sstevel@tonic-gate  */
83*7c478bd9Sstevel@tonic-gate #define	FPSIG24 0x00000000	/* 24-bit significand precision (short) */
84*7c478bd9Sstevel@tonic-gate #define	FPSIG53 0x00000200	/* 53-bit significand precision (long)	*/
85*7c478bd9Sstevel@tonic-gate #define	FPSIG64 0x00000300	/* 64-bit significand precision (temp)	*/
86*7c478bd9Sstevel@tonic-gate #define	FPRTN	0x00000000	/* round to nearest or even		*/
87*7c478bd9Sstevel@tonic-gate #define	FPRD	0x00000400	/* round down				*/
88*7c478bd9Sstevel@tonic-gate #define	FPRU	0x00000800	/* round up				*/
89*7c478bd9Sstevel@tonic-gate #define	FPCHOP	0x00000C00	/* chop (truncate toward zero)		*/
90*7c478bd9Sstevel@tonic-gate #define	FPP	0x00000000	/* projective infinity			*/
91*7c478bd9Sstevel@tonic-gate #define	FPA	0x00001000	/* affine infinity			*/
92*7c478bd9Sstevel@tonic-gate #define	WFPB17	0x00020000	/* bit 17				*/
93*7c478bd9Sstevel@tonic-gate #define	WFPB24	0x00040000	/* bit 24				*/
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate /*
96*7c478bd9Sstevel@tonic-gate  * masks for 80387 status word
97*7c478bd9Sstevel@tonic-gate  */
98*7c478bd9Sstevel@tonic-gate #define	FPS_IE	0x00000001	/* invalid operation			*/
99*7c478bd9Sstevel@tonic-gate #define	FPS_DE	0x00000002	/* denormalized operand			*/
100*7c478bd9Sstevel@tonic-gate #define	FPS_ZE	0x00000004	/* zero devide				*/
101*7c478bd9Sstevel@tonic-gate #define	FPS_OE	0x00000008	/* overflow				*/
102*7c478bd9Sstevel@tonic-gate #define	FPS_UE	0x00000010	/* underflow				*/
103*7c478bd9Sstevel@tonic-gate #define	FPS_PE	0x00000020	/* precision				*/
104*7c478bd9Sstevel@tonic-gate #define	FPS_SF	0x00000040	/* stack fault				*/
105*7c478bd9Sstevel@tonic-gate #define	FPS_ES	0x00000080	/* error summary bit			*/
106*7c478bd9Sstevel@tonic-gate #define	FPS_C0	0x00000100	/* C0 bit				*/
107*7c478bd9Sstevel@tonic-gate #define	FPS_C1	0x00000200	/* C1 bit				*/
108*7c478bd9Sstevel@tonic-gate #define	FPS_C2	0x00000400	/* C2 bit				*/
109*7c478bd9Sstevel@tonic-gate #define	FPS_TOP	0x00003800	/* top of stack pointer			*/
110*7c478bd9Sstevel@tonic-gate #define	FPS_C3	0x00004000	/* C3 bit				*/
111*7c478bd9Sstevel@tonic-gate #define	FPS_B	0x00008000	/* busy bit				*/
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate /*
114*7c478bd9Sstevel@tonic-gate  * Exception flags manually cleared during x87 exception handling.
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate #define	FPS_SW_EFLAGS	\
117*7c478bd9Sstevel@tonic-gate 	(FPS_IE|FPS_DE|FPS_ZE|FPS_OE|FPS_UE|FPS_PE|FPS_SF|FPS_ES|FPS_B)
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate /*
120*7c478bd9Sstevel@tonic-gate  * Initial value of FPU control word as per 4th ed. ABI document
121*7c478bd9Sstevel@tonic-gate  * - affine infinity
122*7c478bd9Sstevel@tonic-gate  * - round to nearest or even
123*7c478bd9Sstevel@tonic-gate  * - 64-bit double precision
124*7c478bd9Sstevel@tonic-gate  * - all exceptions masked
125*7c478bd9Sstevel@tonic-gate  */
126*7c478bd9Sstevel@tonic-gate #define	FPU_CW_INIT	0x133f
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate /*
129*7c478bd9Sstevel@tonic-gate  * masks and flags for SSE/SSE2 MXCSR
130*7c478bd9Sstevel@tonic-gate  */
131*7c478bd9Sstevel@tonic-gate #define	SSE_IE 	0x00000001	/* invalid operation			*/
132*7c478bd9Sstevel@tonic-gate #define	SSE_DE 	0x00000002	/* denormalized operand			*/
133*7c478bd9Sstevel@tonic-gate #define	SSE_ZE	0x00000004	/* zero divide				*/
134*7c478bd9Sstevel@tonic-gate #define	SSE_OE	0x00000008	/* overflow				*/
135*7c478bd9Sstevel@tonic-gate #define	SSE_UE	0x00000010	/* underflow				*/
136*7c478bd9Sstevel@tonic-gate #define	SSE_PE	0x00000020	/* precision				*/
137*7c478bd9Sstevel@tonic-gate #define	SSE_DAZ	0x00000040	/* denormals are zero			*/
138*7c478bd9Sstevel@tonic-gate #define	SSE_IM	0x00000080	/* invalid op exception mask		*/
139*7c478bd9Sstevel@tonic-gate #define	SSE_DM	0x00000100	/* denormalize exception mask		*/
140*7c478bd9Sstevel@tonic-gate #define	SSE_ZM	0x00000200	/* zero-divide exception mask		*/
141*7c478bd9Sstevel@tonic-gate #define	SSE_OM	0x00000400	/* overflow exception mask		*/
142*7c478bd9Sstevel@tonic-gate #define	SSE_UM	0x00000800	/* underflow exception mask		*/
143*7c478bd9Sstevel@tonic-gate #define	SSE_PM	0x00001000	/* precision exception mask		*/
144*7c478bd9Sstevel@tonic-gate #define	SSE_RC	0x00006000	/* rounding control			*/
145*7c478bd9Sstevel@tonic-gate #define	SSE_RD	0x00002000	/* rounding control: round down		*/
146*7c478bd9Sstevel@tonic-gate #define	SSE_RU	0x00004000	/* rounding control: round up		*/
147*7c478bd9Sstevel@tonic-gate #define	SSE_FZ	0x00008000	/* flush to zero for masked underflow 	*/
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_EFLAGS	\
150*7c478bd9Sstevel@tonic-gate 	(SSE_IE|SSE_DE|SSE_ZE|SSE_OE|SSE_UE|SSE_PE)	/* 0x3f */
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_INIT	\
153*7c478bd9Sstevel@tonic-gate 	(SSE_IM|SSE_DM|SSE_ZM|SSE_OM|SSE_UM|SSE_PM)	/* 0x1f80 */
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_MASK_DEFAULT	\
156*7c478bd9Sstevel@tonic-gate 	(0xffff & ~SSE_DAZ)				/* 0xffbf */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate #define	SSE_FMT_MXCSR	\
159*7c478bd9Sstevel@tonic-gate 	"\20\20fz\17ru\16rd\15pm\14um\13om\12zm\11dm"	\
160*7c478bd9Sstevel@tonic-gate 	"\10im\7daz\6pe\5ue\4oe\3ze\2de\1ie"
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate extern int fp_kind;		/* kind of fp support			*/
163*7c478bd9Sstevel@tonic-gate extern int fpu_exists;		/* FPU hw exists			*/
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate extern uint32_t sse_mxcsr_mask;
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate extern void fpu_probe(void);
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate extern void fpnsave_begin(void *);
172*7c478bd9Sstevel@tonic-gate extern void fpxsave_begin(void *);
173*7c478bd9Sstevel@tonic-gate extern void (*fpsave_begin)(void *);
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate extern void fpsave(struct fnsave_state *);
176*7c478bd9Sstevel@tonic-gate extern void fprestore(struct fnsave_state *);
177*7c478bd9Sstevel@tonic-gate extern void fpxsave(struct fxsave_state *);
178*7c478bd9Sstevel@tonic-gate extern void fpxrestore(struct fxsave_state *);
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate extern void fpenable(void);
181*7c478bd9Sstevel@tonic-gate extern void fpdisable(void);
182*7c478bd9Sstevel@tonic-gate extern void fpinit(void);
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate extern uint32_t fperr_reset(void);
185*7c478bd9Sstevel@tonic-gate extern uint32_t fpxerr_reset(void);
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate extern uint32_t fpgetcwsw(void);
188*7c478bd9Sstevel@tonic-gate extern uint32_t fpgetmxcsr(void);
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate struct regs;
191*7c478bd9Sstevel@tonic-gate extern int fpnoextflt(struct regs *);
192*7c478bd9Sstevel@tonic-gate extern int fpextovrflt(struct regs *);
193*7c478bd9Sstevel@tonic-gate extern int fpexterrflt(struct regs *);
194*7c478bd9Sstevel@tonic-gate extern int fpsimderrflt(struct regs *);
195*7c478bd9Sstevel@tonic-gate extern void fpsetcw(uint16_t, uint32_t);
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
200*7c478bd9Sstevel@tonic-gate }
201*7c478bd9Sstevel@tonic-gate #endif
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_FP_H */
204