xref: /onnv-gate/usr/src/uts/intel/sys/fp.h (revision 13134:8315ff49e22e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53446Smrj  * Common Development and Distribution License (the "License").
63446Smrj  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*13134Skuriakose.kuruvilla@oracle.com  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
270Sstevel@tonic-gate /*		All Rights Reserved				*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifndef _SYS_FP_H
300Sstevel@tonic-gate #define	_SYS_FP_H
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef __cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * 80287/80387 and SSE/SSE2 floating point processor definitions
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate  * values that go into fp_kind
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate #define	FP_NO	0	/* no fp chip, no emulator (no fp support)	*/
440Sstevel@tonic-gate #define	FP_SW	1	/* no fp chip, using software emulator		*/
450Sstevel@tonic-gate #define	FP_HW	2	/* chip present bit				*/
460Sstevel@tonic-gate #define	FP_287	2	/* 80287 chip present				*/
470Sstevel@tonic-gate #define	FP_387	3	/* 80387 chip present				*/
480Sstevel@tonic-gate #define	FP_487	6	/* 80487 chip present				*/
490Sstevel@tonic-gate #define	FP_486	6	/* 80486 chip present				*/
50*13134Skuriakose.kuruvilla@oracle.com /*
51*13134Skuriakose.kuruvilla@oracle.com  * The following values are bit flags instead of actual values.
52*13134Skuriakose.kuruvilla@oracle.com  * E.g. to know if we are using SSE, test (value & __FP_SSE) instead
53*13134Skuriakose.kuruvilla@oracle.com  * of (value == __FP_SSE).
54*13134Skuriakose.kuruvilla@oracle.com  */
55*13134Skuriakose.kuruvilla@oracle.com #define	__FP_SSE	0x100	/* .. plus SSE-capable CPU		*/
56*13134Skuriakose.kuruvilla@oracle.com #define	__FP_AVX	0x200	/* .. plus AVX-capable CPU		*/
57*13134Skuriakose.kuruvilla@oracle.com 
58*13134Skuriakose.kuruvilla@oracle.com /*
59*13134Skuriakose.kuruvilla@oracle.com  * values that go into fp_save_mech
60*13134Skuriakose.kuruvilla@oracle.com  */
61*13134Skuriakose.kuruvilla@oracle.com #define	FP_FNSAVE	1	/* fnsave/frstor instructions		*/
62*13134Skuriakose.kuruvilla@oracle.com #define	FP_FXSAVE	2	/* fxsave/fxrstor instructions		*/
63*13134Skuriakose.kuruvilla@oracle.com #define	FP_XSAVE	3	/* xsave/xrstor instructions		*/
640Sstevel@tonic-gate 
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate  * masks for 80387 control word
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate #define	FPIM	0x00000001	/* invalid operation			*/
690Sstevel@tonic-gate #define	FPDM	0x00000002	/* denormalized operand			*/
700Sstevel@tonic-gate #define	FPZM	0x00000004	/* zero divide				*/
710Sstevel@tonic-gate #define	FPOM	0x00000008	/* overflow				*/
720Sstevel@tonic-gate #define	FPUM	0x00000010	/* underflow				*/
730Sstevel@tonic-gate #define	FPPM	0x00000020	/* precision				*/
740Sstevel@tonic-gate #define	FPPC	0x00000300	/* precision control			*/
750Sstevel@tonic-gate #define	FPRC	0x00000C00	/* rounding control			*/
760Sstevel@tonic-gate #define	FPIC	0x00001000	/* infinity control			*/
770Sstevel@tonic-gate #define	WFPDE	0x00000080	/* data chain exception			*/
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate  * (Old symbol compatibility)
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate #define	FPINV	FPIM
830Sstevel@tonic-gate #define	FPDNO	FPDM
840Sstevel@tonic-gate #define	FPZDIV	FPZM
850Sstevel@tonic-gate #define	FPOVR	FPOM
860Sstevel@tonic-gate #define	FPUNR	FPUM
870Sstevel@tonic-gate #define	FPPRE	FPPM
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * precision, rounding, and infinity options in control word
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate #define	FPSIG24 0x00000000	/* 24-bit significand precision (short) */
930Sstevel@tonic-gate #define	FPSIG53 0x00000200	/* 53-bit significand precision (long)	*/
940Sstevel@tonic-gate #define	FPSIG64 0x00000300	/* 64-bit significand precision (temp)	*/
950Sstevel@tonic-gate #define	FPRTN	0x00000000	/* round to nearest or even		*/
960Sstevel@tonic-gate #define	FPRD	0x00000400	/* round down				*/
970Sstevel@tonic-gate #define	FPRU	0x00000800	/* round up				*/
980Sstevel@tonic-gate #define	FPCHOP	0x00000C00	/* chop (truncate toward zero)		*/
990Sstevel@tonic-gate #define	FPP	0x00000000	/* projective infinity			*/
1000Sstevel@tonic-gate #define	FPA	0x00001000	/* affine infinity			*/
1010Sstevel@tonic-gate #define	WFPB17	0x00020000	/* bit 17				*/
1020Sstevel@tonic-gate #define	WFPB24	0x00040000	/* bit 24				*/
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate /*
1050Sstevel@tonic-gate  * masks for 80387 status word
1060Sstevel@tonic-gate  */
1070Sstevel@tonic-gate #define	FPS_IE	0x00000001	/* invalid operation			*/
1080Sstevel@tonic-gate #define	FPS_DE	0x00000002	/* denormalized operand			*/
1093446Smrj #define	FPS_ZE	0x00000004	/* zero divide				*/
1100Sstevel@tonic-gate #define	FPS_OE	0x00000008	/* overflow				*/
1110Sstevel@tonic-gate #define	FPS_UE	0x00000010	/* underflow				*/
1120Sstevel@tonic-gate #define	FPS_PE	0x00000020	/* precision				*/
1130Sstevel@tonic-gate #define	FPS_SF	0x00000040	/* stack fault				*/
1140Sstevel@tonic-gate #define	FPS_ES	0x00000080	/* error summary bit			*/
1150Sstevel@tonic-gate #define	FPS_C0	0x00000100	/* C0 bit				*/
1160Sstevel@tonic-gate #define	FPS_C1	0x00000200	/* C1 bit				*/
1170Sstevel@tonic-gate #define	FPS_C2	0x00000400	/* C2 bit				*/
1180Sstevel@tonic-gate #define	FPS_TOP	0x00003800	/* top of stack pointer			*/
1190Sstevel@tonic-gate #define	FPS_C3	0x00004000	/* C3 bit				*/
1200Sstevel@tonic-gate #define	FPS_B	0x00008000	/* busy bit				*/
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate /*
1230Sstevel@tonic-gate  * Exception flags manually cleared during x87 exception handling.
1240Sstevel@tonic-gate  */
1250Sstevel@tonic-gate #define	FPS_SW_EFLAGS	\
1260Sstevel@tonic-gate 	(FPS_IE|FPS_DE|FPS_ZE|FPS_OE|FPS_UE|FPS_PE|FPS_SF|FPS_ES|FPS_B)
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate /*
1290Sstevel@tonic-gate  * Initial value of FPU control word as per 4th ed. ABI document
1300Sstevel@tonic-gate  * - affine infinity
1310Sstevel@tonic-gate  * - round to nearest or even
1320Sstevel@tonic-gate  * - 64-bit double precision
1330Sstevel@tonic-gate  * - all exceptions masked
1340Sstevel@tonic-gate  */
1350Sstevel@tonic-gate #define	FPU_CW_INIT	0x133f
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate  * masks and flags for SSE/SSE2 MXCSR
1390Sstevel@tonic-gate  */
1400Sstevel@tonic-gate #define	SSE_IE 	0x00000001	/* invalid operation			*/
1410Sstevel@tonic-gate #define	SSE_DE 	0x00000002	/* denormalized operand			*/
1420Sstevel@tonic-gate #define	SSE_ZE	0x00000004	/* zero divide				*/
1430Sstevel@tonic-gate #define	SSE_OE	0x00000008	/* overflow				*/
1440Sstevel@tonic-gate #define	SSE_UE	0x00000010	/* underflow				*/
1450Sstevel@tonic-gate #define	SSE_PE	0x00000020	/* precision				*/
1460Sstevel@tonic-gate #define	SSE_DAZ	0x00000040	/* denormals are zero			*/
1470Sstevel@tonic-gate #define	SSE_IM	0x00000080	/* invalid op exception mask		*/
1480Sstevel@tonic-gate #define	SSE_DM	0x00000100	/* denormalize exception mask		*/
1490Sstevel@tonic-gate #define	SSE_ZM	0x00000200	/* zero-divide exception mask		*/
1500Sstevel@tonic-gate #define	SSE_OM	0x00000400	/* overflow exception mask		*/
1510Sstevel@tonic-gate #define	SSE_UM	0x00000800	/* underflow exception mask		*/
1520Sstevel@tonic-gate #define	SSE_PM	0x00001000	/* precision exception mask		*/
1530Sstevel@tonic-gate #define	SSE_RC	0x00006000	/* rounding control			*/
1540Sstevel@tonic-gate #define	SSE_RD	0x00002000	/* rounding control: round down		*/
1550Sstevel@tonic-gate #define	SSE_RU	0x00004000	/* rounding control: round up		*/
1560Sstevel@tonic-gate #define	SSE_FZ	0x00008000	/* flush to zero for masked underflow 	*/
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #define	SSE_MXCSR_EFLAGS	\
1590Sstevel@tonic-gate 	(SSE_IE|SSE_DE|SSE_ZE|SSE_OE|SSE_UE|SSE_PE)	/* 0x3f */
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate #define	SSE_MXCSR_INIT	\
1620Sstevel@tonic-gate 	(SSE_IM|SSE_DM|SSE_ZM|SSE_OM|SSE_UM|SSE_PM)	/* 0x1f80 */
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate #define	SSE_MXCSR_MASK_DEFAULT	\
1650Sstevel@tonic-gate 	(0xffff & ~SSE_DAZ)				/* 0xffbf */
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #define	SSE_FMT_MXCSR	\
1680Sstevel@tonic-gate 	"\20\20fz\17ru\16rd\15pm\14um\13om\12zm\11dm"	\
1690Sstevel@tonic-gate 	"\10im\7daz\6pe\5ue\4oe\3ze\2de\1ie"
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate extern int fp_kind;		/* kind of fp support			*/
172*13134Skuriakose.kuruvilla@oracle.com extern int fp_save_mech;	/* fp save/restore mechanism		*/
1730Sstevel@tonic-gate extern int fpu_exists;		/* FPU hw exists			*/
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate #ifdef _KERNEL
1760Sstevel@tonic-gate 
1773446Smrj extern int fpu_ignored;
1783446Smrj extern int fpu_pentium_fdivbug;
1793446Smrj 
1800Sstevel@tonic-gate extern uint32_t sse_mxcsr_mask;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate extern void fpu_probe(void);
1833446Smrj extern uint_t fpu_initial_probe(void);
1843446Smrj extern int fpu_probe_pentium_fdivbug(void);
1850Sstevel@tonic-gate 
1863446Smrj extern void fpnsave_ctxt(void *);
1873446Smrj extern void fpxsave_ctxt(void *);
188*13134Skuriakose.kuruvilla@oracle.com extern void xsave_ctxt(void *);
1893446Smrj extern void (*fpsave_ctxt)(void *);
1900Sstevel@tonic-gate 
1913446Smrj struct fnsave_state;
1923446Smrj struct fxsave_state;
193*13134Skuriakose.kuruvilla@oracle.com struct xsave_state;
1943446Smrj extern void fxsave_insn(struct fxsave_state *);
1950Sstevel@tonic-gate extern void fpsave(struct fnsave_state *);
1960Sstevel@tonic-gate extern void fprestore(struct fnsave_state *);
1970Sstevel@tonic-gate extern void fpxsave(struct fxsave_state *);
1980Sstevel@tonic-gate extern void fpxrestore(struct fxsave_state *);
199*13134Skuriakose.kuruvilla@oracle.com extern void xsave(struct xsave_state *, uint64_t);
200*13134Skuriakose.kuruvilla@oracle.com extern void xrestore(struct xsave_state *, uint64_t);
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate extern void fpenable(void);
2030Sstevel@tonic-gate extern void fpdisable(void);
2040Sstevel@tonic-gate extern void fpinit(void);
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate extern uint32_t fperr_reset(void);
2070Sstevel@tonic-gate extern uint32_t fpxerr_reset(void);
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate extern uint32_t fpgetcwsw(void);
2100Sstevel@tonic-gate extern uint32_t fpgetmxcsr(void);
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate struct regs;
2130Sstevel@tonic-gate extern int fpnoextflt(struct regs *);
2140Sstevel@tonic-gate extern int fpextovrflt(struct regs *);
2150Sstevel@tonic-gate extern int fpexterrflt(struct regs *);
2160Sstevel@tonic-gate extern int fpsimderrflt(struct regs *);
2170Sstevel@tonic-gate extern void fpsetcw(uint16_t, uint32_t);
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate #endif	/* _KERNEL */
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate #ifdef __cplusplus
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate #endif
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate #endif	/* _SYS_FP_H */
226