xref: /titanic_53/usr/src/uts/intel/sys/fp.h (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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
5*ae115bc7Smrj  * Common Development and Distribution License (the "License").
6*ae115bc7Smrj  * 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*ae115bc7Smrj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
287c478bd9Sstevel@tonic-gate /*		All Rights Reserved				*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_FP_H
317c478bd9Sstevel@tonic-gate #define	_SYS_FP_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef __cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * 80287/80387 and SSE/SSE2 floating point processor definitions
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * values that go into fp_kind
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate #define	FP_NO	0	/* no fp chip, no emulator (no fp support)	*/
477c478bd9Sstevel@tonic-gate #define	FP_SW	1	/* no fp chip, using software emulator		*/
487c478bd9Sstevel@tonic-gate #define	FP_HW	2	/* chip present bit				*/
497c478bd9Sstevel@tonic-gate #define	FP_287	2	/* 80287 chip present				*/
507c478bd9Sstevel@tonic-gate #define	FP_387	3	/* 80387 chip present				*/
517c478bd9Sstevel@tonic-gate #define	FP_487	6	/* 80487 chip present				*/
527c478bd9Sstevel@tonic-gate #define	FP_486	6	/* 80486 chip present				*/
537c478bd9Sstevel@tonic-gate #define	__FP_SSE 0x103	/* x87 plus SSE-capable CPU			*/
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * masks for 80387 control word
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #define	FPIM	0x00000001	/* invalid operation			*/
597c478bd9Sstevel@tonic-gate #define	FPDM	0x00000002	/* denormalized operand			*/
607c478bd9Sstevel@tonic-gate #define	FPZM	0x00000004	/* zero divide				*/
617c478bd9Sstevel@tonic-gate #define	FPOM	0x00000008	/* overflow				*/
627c478bd9Sstevel@tonic-gate #define	FPUM	0x00000010	/* underflow				*/
637c478bd9Sstevel@tonic-gate #define	FPPM	0x00000020	/* precision				*/
647c478bd9Sstevel@tonic-gate #define	FPPC	0x00000300	/* precision control			*/
657c478bd9Sstevel@tonic-gate #define	FPRC	0x00000C00	/* rounding control			*/
667c478bd9Sstevel@tonic-gate #define	FPIC	0x00001000	/* infinity control			*/
677c478bd9Sstevel@tonic-gate #define	WFPDE	0x00000080	/* data chain exception			*/
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * (Old symbol compatibility)
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	FPINV	FPIM
737c478bd9Sstevel@tonic-gate #define	FPDNO	FPDM
747c478bd9Sstevel@tonic-gate #define	FPZDIV	FPZM
757c478bd9Sstevel@tonic-gate #define	FPOVR	FPOM
767c478bd9Sstevel@tonic-gate #define	FPUNR	FPUM
777c478bd9Sstevel@tonic-gate #define	FPPRE	FPPM
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * precision, rounding, and infinity options in control word
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate #define	FPSIG24 0x00000000	/* 24-bit significand precision (short) */
837c478bd9Sstevel@tonic-gate #define	FPSIG53 0x00000200	/* 53-bit significand precision (long)	*/
847c478bd9Sstevel@tonic-gate #define	FPSIG64 0x00000300	/* 64-bit significand precision (temp)	*/
857c478bd9Sstevel@tonic-gate #define	FPRTN	0x00000000	/* round to nearest or even		*/
867c478bd9Sstevel@tonic-gate #define	FPRD	0x00000400	/* round down				*/
877c478bd9Sstevel@tonic-gate #define	FPRU	0x00000800	/* round up				*/
887c478bd9Sstevel@tonic-gate #define	FPCHOP	0x00000C00	/* chop (truncate toward zero)		*/
897c478bd9Sstevel@tonic-gate #define	FPP	0x00000000	/* projective infinity			*/
907c478bd9Sstevel@tonic-gate #define	FPA	0x00001000	/* affine infinity			*/
917c478bd9Sstevel@tonic-gate #define	WFPB17	0x00020000	/* bit 17				*/
927c478bd9Sstevel@tonic-gate #define	WFPB24	0x00040000	/* bit 24				*/
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * masks for 80387 status word
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #define	FPS_IE	0x00000001	/* invalid operation			*/
987c478bd9Sstevel@tonic-gate #define	FPS_DE	0x00000002	/* denormalized operand			*/
99*ae115bc7Smrj #define	FPS_ZE	0x00000004	/* zero divide				*/
1007c478bd9Sstevel@tonic-gate #define	FPS_OE	0x00000008	/* overflow				*/
1017c478bd9Sstevel@tonic-gate #define	FPS_UE	0x00000010	/* underflow				*/
1027c478bd9Sstevel@tonic-gate #define	FPS_PE	0x00000020	/* precision				*/
1037c478bd9Sstevel@tonic-gate #define	FPS_SF	0x00000040	/* stack fault				*/
1047c478bd9Sstevel@tonic-gate #define	FPS_ES	0x00000080	/* error summary bit			*/
1057c478bd9Sstevel@tonic-gate #define	FPS_C0	0x00000100	/* C0 bit				*/
1067c478bd9Sstevel@tonic-gate #define	FPS_C1	0x00000200	/* C1 bit				*/
1077c478bd9Sstevel@tonic-gate #define	FPS_C2	0x00000400	/* C2 bit				*/
1087c478bd9Sstevel@tonic-gate #define	FPS_TOP	0x00003800	/* top of stack pointer			*/
1097c478bd9Sstevel@tonic-gate #define	FPS_C3	0x00004000	/* C3 bit				*/
1107c478bd9Sstevel@tonic-gate #define	FPS_B	0x00008000	/* busy bit				*/
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * Exception flags manually cleared during x87 exception handling.
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate #define	FPS_SW_EFLAGS	\
1167c478bd9Sstevel@tonic-gate 	(FPS_IE|FPS_DE|FPS_ZE|FPS_OE|FPS_UE|FPS_PE|FPS_SF|FPS_ES|FPS_B)
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * Initial value of FPU control word as per 4th ed. ABI document
1207c478bd9Sstevel@tonic-gate  * - affine infinity
1217c478bd9Sstevel@tonic-gate  * - round to nearest or even
1227c478bd9Sstevel@tonic-gate  * - 64-bit double precision
1237c478bd9Sstevel@tonic-gate  * - all exceptions masked
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate #define	FPU_CW_INIT	0x133f
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * masks and flags for SSE/SSE2 MXCSR
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate #define	SSE_IE 	0x00000001	/* invalid operation			*/
1317c478bd9Sstevel@tonic-gate #define	SSE_DE 	0x00000002	/* denormalized operand			*/
1327c478bd9Sstevel@tonic-gate #define	SSE_ZE	0x00000004	/* zero divide				*/
1337c478bd9Sstevel@tonic-gate #define	SSE_OE	0x00000008	/* overflow				*/
1347c478bd9Sstevel@tonic-gate #define	SSE_UE	0x00000010	/* underflow				*/
1357c478bd9Sstevel@tonic-gate #define	SSE_PE	0x00000020	/* precision				*/
1367c478bd9Sstevel@tonic-gate #define	SSE_DAZ	0x00000040	/* denormals are zero			*/
1377c478bd9Sstevel@tonic-gate #define	SSE_IM	0x00000080	/* invalid op exception mask		*/
1387c478bd9Sstevel@tonic-gate #define	SSE_DM	0x00000100	/* denormalize exception mask		*/
1397c478bd9Sstevel@tonic-gate #define	SSE_ZM	0x00000200	/* zero-divide exception mask		*/
1407c478bd9Sstevel@tonic-gate #define	SSE_OM	0x00000400	/* overflow exception mask		*/
1417c478bd9Sstevel@tonic-gate #define	SSE_UM	0x00000800	/* underflow exception mask		*/
1427c478bd9Sstevel@tonic-gate #define	SSE_PM	0x00001000	/* precision exception mask		*/
1437c478bd9Sstevel@tonic-gate #define	SSE_RC	0x00006000	/* rounding control			*/
1447c478bd9Sstevel@tonic-gate #define	SSE_RD	0x00002000	/* rounding control: round down		*/
1457c478bd9Sstevel@tonic-gate #define	SSE_RU	0x00004000	/* rounding control: round up		*/
1467c478bd9Sstevel@tonic-gate #define	SSE_FZ	0x00008000	/* flush to zero for masked underflow 	*/
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_EFLAGS	\
1497c478bd9Sstevel@tonic-gate 	(SSE_IE|SSE_DE|SSE_ZE|SSE_OE|SSE_UE|SSE_PE)	/* 0x3f */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_INIT	\
1527c478bd9Sstevel@tonic-gate 	(SSE_IM|SSE_DM|SSE_ZM|SSE_OM|SSE_UM|SSE_PM)	/* 0x1f80 */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_MASK_DEFAULT	\
1557c478bd9Sstevel@tonic-gate 	(0xffff & ~SSE_DAZ)				/* 0xffbf */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #define	SSE_FMT_MXCSR	\
1587c478bd9Sstevel@tonic-gate 	"\20\20fz\17ru\16rd\15pm\14um\13om\12zm\11dm"	\
1597c478bd9Sstevel@tonic-gate 	"\10im\7daz\6pe\5ue\4oe\3ze\2de\1ie"
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate extern int fp_kind;		/* kind of fp support			*/
1627c478bd9Sstevel@tonic-gate extern int fpu_exists;		/* FPU hw exists			*/
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1657c478bd9Sstevel@tonic-gate 
166*ae115bc7Smrj extern int fpu_ignored;
167*ae115bc7Smrj extern int fpu_pentium_fdivbug;
168*ae115bc7Smrj 
1697c478bd9Sstevel@tonic-gate extern uint32_t sse_mxcsr_mask;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate extern void fpu_probe(void);
172*ae115bc7Smrj extern uint_t fpu_initial_probe(void);
173*ae115bc7Smrj extern int fpu_probe_pentium_fdivbug(void);
1747c478bd9Sstevel@tonic-gate 
175*ae115bc7Smrj extern void fpnsave_ctxt(void *);
176*ae115bc7Smrj extern void fpxsave_ctxt(void *);
177*ae115bc7Smrj extern void (*fpsave_ctxt)(void *);
1787c478bd9Sstevel@tonic-gate 
179*ae115bc7Smrj struct fnsave_state;
180*ae115bc7Smrj struct fxsave_state;
181*ae115bc7Smrj extern void fxsave_insn(struct fxsave_state *);
1827c478bd9Sstevel@tonic-gate extern void fpsave(struct fnsave_state *);
1837c478bd9Sstevel@tonic-gate extern void fprestore(struct fnsave_state *);
1847c478bd9Sstevel@tonic-gate extern void fpxsave(struct fxsave_state *);
1857c478bd9Sstevel@tonic-gate extern void fpxrestore(struct fxsave_state *);
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate extern void fpenable(void);
1887c478bd9Sstevel@tonic-gate extern void fpdisable(void);
1897c478bd9Sstevel@tonic-gate extern void fpinit(void);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate extern uint32_t fperr_reset(void);
1927c478bd9Sstevel@tonic-gate extern uint32_t fpxerr_reset(void);
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate extern uint32_t fpgetcwsw(void);
1957c478bd9Sstevel@tonic-gate extern uint32_t fpgetmxcsr(void);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate struct regs;
1987c478bd9Sstevel@tonic-gate extern int fpnoextflt(struct regs *);
1997c478bd9Sstevel@tonic-gate extern int fpextovrflt(struct regs *);
2007c478bd9Sstevel@tonic-gate extern int fpexterrflt(struct regs *);
2017c478bd9Sstevel@tonic-gate extern int fpsimderrflt(struct regs *);
2027c478bd9Sstevel@tonic-gate extern void fpsetcw(uint16_t, uint32_t);
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate #endif
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #endif	/* _SYS_FP_H */
211