xref: /titanic_41/usr/src/uts/intel/sys/fp.h (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*7af88ac7SKuriakose Kuruvilla  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
277c478bd9Sstevel@tonic-gate /*		All Rights Reserved				*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _SYS_FP_H
307c478bd9Sstevel@tonic-gate #define	_SYS_FP_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * 80287/80387 and SSE/SSE2 floating point processor definitions
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * values that go into fp_kind
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate #define	FP_NO	0	/* no fp chip, no emulator (no fp support)	*/
447c478bd9Sstevel@tonic-gate #define	FP_SW	1	/* no fp chip, using software emulator		*/
457c478bd9Sstevel@tonic-gate #define	FP_HW	2	/* chip present bit				*/
467c478bd9Sstevel@tonic-gate #define	FP_287	2	/* 80287 chip present				*/
477c478bd9Sstevel@tonic-gate #define	FP_387	3	/* 80387 chip present				*/
487c478bd9Sstevel@tonic-gate #define	FP_487	6	/* 80487 chip present				*/
497c478bd9Sstevel@tonic-gate #define	FP_486	6	/* 80486 chip present				*/
50*7af88ac7SKuriakose Kuruvilla /*
51*7af88ac7SKuriakose Kuruvilla  * The following values are bit flags instead of actual values.
52*7af88ac7SKuriakose Kuruvilla  * E.g. to know if we are using SSE, test (value & __FP_SSE) instead
53*7af88ac7SKuriakose Kuruvilla  * of (value == __FP_SSE).
54*7af88ac7SKuriakose Kuruvilla  */
55*7af88ac7SKuriakose Kuruvilla #define	__FP_SSE	0x100	/* .. plus SSE-capable CPU		*/
56*7af88ac7SKuriakose Kuruvilla #define	__FP_AVX	0x200	/* .. plus AVX-capable CPU		*/
57*7af88ac7SKuriakose Kuruvilla 
58*7af88ac7SKuriakose Kuruvilla /*
59*7af88ac7SKuriakose Kuruvilla  * values that go into fp_save_mech
60*7af88ac7SKuriakose Kuruvilla  */
61*7af88ac7SKuriakose Kuruvilla #define	FP_FNSAVE	1	/* fnsave/frstor instructions		*/
62*7af88ac7SKuriakose Kuruvilla #define	FP_FXSAVE	2	/* fxsave/fxrstor instructions		*/
63*7af88ac7SKuriakose Kuruvilla #define	FP_XSAVE	3	/* xsave/xrstor instructions		*/
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * masks for 80387 control word
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate #define	FPIM	0x00000001	/* invalid operation			*/
697c478bd9Sstevel@tonic-gate #define	FPDM	0x00000002	/* denormalized operand			*/
707c478bd9Sstevel@tonic-gate #define	FPZM	0x00000004	/* zero divide				*/
717c478bd9Sstevel@tonic-gate #define	FPOM	0x00000008	/* overflow				*/
727c478bd9Sstevel@tonic-gate #define	FPUM	0x00000010	/* underflow				*/
737c478bd9Sstevel@tonic-gate #define	FPPM	0x00000020	/* precision				*/
747c478bd9Sstevel@tonic-gate #define	FPPC	0x00000300	/* precision control			*/
757c478bd9Sstevel@tonic-gate #define	FPRC	0x00000C00	/* rounding control			*/
767c478bd9Sstevel@tonic-gate #define	FPIC	0x00001000	/* infinity control			*/
777c478bd9Sstevel@tonic-gate #define	WFPDE	0x00000080	/* data chain exception			*/
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * (Old symbol compatibility)
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate #define	FPINV	FPIM
837c478bd9Sstevel@tonic-gate #define	FPDNO	FPDM
847c478bd9Sstevel@tonic-gate #define	FPZDIV	FPZM
857c478bd9Sstevel@tonic-gate #define	FPOVR	FPOM
867c478bd9Sstevel@tonic-gate #define	FPUNR	FPUM
877c478bd9Sstevel@tonic-gate #define	FPPRE	FPPM
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * precision, rounding, and infinity options in control word
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	FPSIG24 0x00000000	/* 24-bit significand precision (short) */
937c478bd9Sstevel@tonic-gate #define	FPSIG53 0x00000200	/* 53-bit significand precision (long)	*/
947c478bd9Sstevel@tonic-gate #define	FPSIG64 0x00000300	/* 64-bit significand precision (temp)	*/
957c478bd9Sstevel@tonic-gate #define	FPRTN	0x00000000	/* round to nearest or even		*/
967c478bd9Sstevel@tonic-gate #define	FPRD	0x00000400	/* round down				*/
977c478bd9Sstevel@tonic-gate #define	FPRU	0x00000800	/* round up				*/
987c478bd9Sstevel@tonic-gate #define	FPCHOP	0x00000C00	/* chop (truncate toward zero)		*/
997c478bd9Sstevel@tonic-gate #define	FPP	0x00000000	/* projective infinity			*/
1007c478bd9Sstevel@tonic-gate #define	FPA	0x00001000	/* affine infinity			*/
1017c478bd9Sstevel@tonic-gate #define	WFPB17	0x00020000	/* bit 17				*/
1027c478bd9Sstevel@tonic-gate #define	WFPB24	0x00040000	/* bit 24				*/
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * masks for 80387 status word
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate #define	FPS_IE	0x00000001	/* invalid operation			*/
1087c478bd9Sstevel@tonic-gate #define	FPS_DE	0x00000002	/* denormalized operand			*/
109ae115bc7Smrj #define	FPS_ZE	0x00000004	/* zero divide				*/
1107c478bd9Sstevel@tonic-gate #define	FPS_OE	0x00000008	/* overflow				*/
1117c478bd9Sstevel@tonic-gate #define	FPS_UE	0x00000010	/* underflow				*/
1127c478bd9Sstevel@tonic-gate #define	FPS_PE	0x00000020	/* precision				*/
1137c478bd9Sstevel@tonic-gate #define	FPS_SF	0x00000040	/* stack fault				*/
1147c478bd9Sstevel@tonic-gate #define	FPS_ES	0x00000080	/* error summary bit			*/
1157c478bd9Sstevel@tonic-gate #define	FPS_C0	0x00000100	/* C0 bit				*/
1167c478bd9Sstevel@tonic-gate #define	FPS_C1	0x00000200	/* C1 bit				*/
1177c478bd9Sstevel@tonic-gate #define	FPS_C2	0x00000400	/* C2 bit				*/
1187c478bd9Sstevel@tonic-gate #define	FPS_TOP	0x00003800	/* top of stack pointer			*/
1197c478bd9Sstevel@tonic-gate #define	FPS_C3	0x00004000	/* C3 bit				*/
1207c478bd9Sstevel@tonic-gate #define	FPS_B	0x00008000	/* busy bit				*/
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * Exception flags manually cleared during x87 exception handling.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate #define	FPS_SW_EFLAGS	\
1267c478bd9Sstevel@tonic-gate 	(FPS_IE|FPS_DE|FPS_ZE|FPS_OE|FPS_UE|FPS_PE|FPS_SF|FPS_ES|FPS_B)
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Initial value of FPU control word as per 4th ed. ABI document
1307c478bd9Sstevel@tonic-gate  * - affine infinity
1317c478bd9Sstevel@tonic-gate  * - round to nearest or even
1327c478bd9Sstevel@tonic-gate  * - 64-bit double precision
1337c478bd9Sstevel@tonic-gate  * - all exceptions masked
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate #define	FPU_CW_INIT	0x133f
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /*
1387c478bd9Sstevel@tonic-gate  * masks and flags for SSE/SSE2 MXCSR
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate #define	SSE_IE 	0x00000001	/* invalid operation			*/
1417c478bd9Sstevel@tonic-gate #define	SSE_DE 	0x00000002	/* denormalized operand			*/
1427c478bd9Sstevel@tonic-gate #define	SSE_ZE	0x00000004	/* zero divide				*/
1437c478bd9Sstevel@tonic-gate #define	SSE_OE	0x00000008	/* overflow				*/
1447c478bd9Sstevel@tonic-gate #define	SSE_UE	0x00000010	/* underflow				*/
1457c478bd9Sstevel@tonic-gate #define	SSE_PE	0x00000020	/* precision				*/
1467c478bd9Sstevel@tonic-gate #define	SSE_DAZ	0x00000040	/* denormals are zero			*/
1477c478bd9Sstevel@tonic-gate #define	SSE_IM	0x00000080	/* invalid op exception mask		*/
1487c478bd9Sstevel@tonic-gate #define	SSE_DM	0x00000100	/* denormalize exception mask		*/
1497c478bd9Sstevel@tonic-gate #define	SSE_ZM	0x00000200	/* zero-divide exception mask		*/
1507c478bd9Sstevel@tonic-gate #define	SSE_OM	0x00000400	/* overflow exception mask		*/
1517c478bd9Sstevel@tonic-gate #define	SSE_UM	0x00000800	/* underflow exception mask		*/
1527c478bd9Sstevel@tonic-gate #define	SSE_PM	0x00001000	/* precision exception mask		*/
1537c478bd9Sstevel@tonic-gate #define	SSE_RC	0x00006000	/* rounding control			*/
1547c478bd9Sstevel@tonic-gate #define	SSE_RD	0x00002000	/* rounding control: round down		*/
1557c478bd9Sstevel@tonic-gate #define	SSE_RU	0x00004000	/* rounding control: round up		*/
1567c478bd9Sstevel@tonic-gate #define	SSE_FZ	0x00008000	/* flush to zero for masked underflow 	*/
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_EFLAGS	\
1597c478bd9Sstevel@tonic-gate 	(SSE_IE|SSE_DE|SSE_ZE|SSE_OE|SSE_UE|SSE_PE)	/* 0x3f */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_INIT	\
1627c478bd9Sstevel@tonic-gate 	(SSE_IM|SSE_DM|SSE_ZM|SSE_OM|SSE_UM|SSE_PM)	/* 0x1f80 */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_MASK_DEFAULT	\
1657c478bd9Sstevel@tonic-gate 	(0xffff & ~SSE_DAZ)				/* 0xffbf */
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #define	SSE_FMT_MXCSR	\
1687c478bd9Sstevel@tonic-gate 	"\20\20fz\17ru\16rd\15pm\14um\13om\12zm\11dm"	\
1697c478bd9Sstevel@tonic-gate 	"\10im\7daz\6pe\5ue\4oe\3ze\2de\1ie"
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate extern int fp_kind;		/* kind of fp support			*/
172*7af88ac7SKuriakose Kuruvilla extern int fp_save_mech;	/* fp save/restore mechanism		*/
1737c478bd9Sstevel@tonic-gate extern int fpu_exists;		/* FPU hw exists			*/
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1767c478bd9Sstevel@tonic-gate 
177ae115bc7Smrj extern int fpu_ignored;
178ae115bc7Smrj extern int fpu_pentium_fdivbug;
179ae115bc7Smrj 
1807c478bd9Sstevel@tonic-gate extern uint32_t sse_mxcsr_mask;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate extern void fpu_probe(void);
183ae115bc7Smrj extern uint_t fpu_initial_probe(void);
184ae115bc7Smrj extern int fpu_probe_pentium_fdivbug(void);
1857c478bd9Sstevel@tonic-gate 
186ae115bc7Smrj extern void fpnsave_ctxt(void *);
187ae115bc7Smrj extern void fpxsave_ctxt(void *);
188*7af88ac7SKuriakose Kuruvilla extern void xsave_ctxt(void *);
189ae115bc7Smrj extern void (*fpsave_ctxt)(void *);
1907c478bd9Sstevel@tonic-gate 
191ae115bc7Smrj struct fnsave_state;
192ae115bc7Smrj struct fxsave_state;
193*7af88ac7SKuriakose Kuruvilla struct xsave_state;
194ae115bc7Smrj extern void fxsave_insn(struct fxsave_state *);
1957c478bd9Sstevel@tonic-gate extern void fpsave(struct fnsave_state *);
1967c478bd9Sstevel@tonic-gate extern void fprestore(struct fnsave_state *);
1977c478bd9Sstevel@tonic-gate extern void fpxsave(struct fxsave_state *);
1987c478bd9Sstevel@tonic-gate extern void fpxrestore(struct fxsave_state *);
199*7af88ac7SKuriakose Kuruvilla extern void xsave(struct xsave_state *, uint64_t);
200*7af88ac7SKuriakose Kuruvilla extern void xrestore(struct xsave_state *, uint64_t);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate extern void fpenable(void);
2037c478bd9Sstevel@tonic-gate extern void fpdisable(void);
2047c478bd9Sstevel@tonic-gate extern void fpinit(void);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate extern uint32_t fperr_reset(void);
2077c478bd9Sstevel@tonic-gate extern uint32_t fpxerr_reset(void);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate extern uint32_t fpgetcwsw(void);
2107c478bd9Sstevel@tonic-gate extern uint32_t fpgetmxcsr(void);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate struct regs;
2137c478bd9Sstevel@tonic-gate extern int fpnoextflt(struct regs *);
2147c478bd9Sstevel@tonic-gate extern int fpextovrflt(struct regs *);
2157c478bd9Sstevel@tonic-gate extern int fpexterrflt(struct regs *);
2167c478bd9Sstevel@tonic-gate extern int fpsimderrflt(struct regs *);
2177c478bd9Sstevel@tonic-gate extern void fpsetcw(uint16_t, uint32_t);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate #endif
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #endif	/* _SYS_FP_H */
226