xref: /illumos-gate/usr/src/uts/intel/sys/fp.h (revision ed093b41)
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 /*
22bc0e9132SGordon Ross  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
23d0158222SRobert Mustacchi  * Copyright (c) 2018, Joyent, Inc.
24*ed093b41SRobert Mustacchi  * Copyright 2023 Oxide Computer Company
25bc0e9132SGordon Ross  *
267af88ac7SKuriakose Kuruvilla  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
307c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
317c478bd9Sstevel@tonic-gate /*		All Rights Reserved				*/
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef _SYS_FP_H
347c478bd9Sstevel@tonic-gate #define	_SYS_FP_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef __cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * 80287/80387 and SSE/SSE2 floating point processor definitions
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * values that go into fp_kind
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate #define	FP_NO	0	/* no fp chip, no emulator (no fp support)	*/
487c478bd9Sstevel@tonic-gate #define	FP_SW	1	/* no fp chip, using software emulator		*/
497c478bd9Sstevel@tonic-gate #define	FP_HW	2	/* chip present bit				*/
507c478bd9Sstevel@tonic-gate #define	FP_287	2	/* 80287 chip present				*/
517c478bd9Sstevel@tonic-gate #define	FP_387	3	/* 80387 chip present				*/
527c478bd9Sstevel@tonic-gate #define	FP_487	6	/* 80487 chip present				*/
537c478bd9Sstevel@tonic-gate #define	FP_486	6	/* 80486 chip present				*/
547af88ac7SKuriakose Kuruvilla /*
557af88ac7SKuriakose Kuruvilla  * The following values are bit flags instead of actual values.
567af88ac7SKuriakose Kuruvilla  * E.g. to know if we are using SSE, test (value & __FP_SSE) instead
577af88ac7SKuriakose Kuruvilla  * of (value == __FP_SSE).
587af88ac7SKuriakose Kuruvilla  */
597af88ac7SKuriakose Kuruvilla #define	__FP_SSE	0x100	/* .. plus SSE-capable CPU		*/
607af88ac7SKuriakose Kuruvilla #define	__FP_AVX	0x200	/* .. plus AVX-capable CPU		*/
617af88ac7SKuriakose Kuruvilla 
627af88ac7SKuriakose Kuruvilla /*
637af88ac7SKuriakose Kuruvilla  * values that go into fp_save_mech
647af88ac7SKuriakose Kuruvilla  */
657af88ac7SKuriakose Kuruvilla #define	FP_FNSAVE	1	/* fnsave/frstor instructions		*/
667af88ac7SKuriakose Kuruvilla #define	FP_FXSAVE	2	/* fxsave/fxrstor instructions		*/
677af88ac7SKuriakose Kuruvilla #define	FP_XSAVE	3	/* xsave/xrstor instructions		*/
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * masks for 80387 control word
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	FPIM	0x00000001	/* invalid operation			*/
737c478bd9Sstevel@tonic-gate #define	FPDM	0x00000002	/* denormalized operand			*/
747c478bd9Sstevel@tonic-gate #define	FPZM	0x00000004	/* zero divide				*/
757c478bd9Sstevel@tonic-gate #define	FPOM	0x00000008	/* overflow				*/
767c478bd9Sstevel@tonic-gate #define	FPUM	0x00000010	/* underflow				*/
777c478bd9Sstevel@tonic-gate #define	FPPM	0x00000020	/* precision				*/
787c478bd9Sstevel@tonic-gate #define	FPPC	0x00000300	/* precision control			*/
797c478bd9Sstevel@tonic-gate #define	FPRC	0x00000C00	/* rounding control			*/
807c478bd9Sstevel@tonic-gate #define	FPIC	0x00001000	/* infinity control			*/
817c478bd9Sstevel@tonic-gate #define	WFPDE	0x00000080	/* data chain exception			*/
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * (Old symbol compatibility)
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate #define	FPINV	FPIM
877c478bd9Sstevel@tonic-gate #define	FPDNO	FPDM
887c478bd9Sstevel@tonic-gate #define	FPZDIV	FPZM
897c478bd9Sstevel@tonic-gate #define	FPOVR	FPOM
907c478bd9Sstevel@tonic-gate #define	FPUNR	FPUM
917c478bd9Sstevel@tonic-gate #define	FPPRE	FPPM
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * precision, rounding, and infinity options in control word
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate #define	FPSIG24 0x00000000	/* 24-bit significand precision (short) */
977c478bd9Sstevel@tonic-gate #define	FPSIG53 0x00000200	/* 53-bit significand precision (long)	*/
987c478bd9Sstevel@tonic-gate #define	FPSIG64 0x00000300	/* 64-bit significand precision (temp)	*/
997c478bd9Sstevel@tonic-gate #define	FPRTN	0x00000000	/* round to nearest or even		*/
1007c478bd9Sstevel@tonic-gate #define	FPRD	0x00000400	/* round down				*/
1017c478bd9Sstevel@tonic-gate #define	FPRU	0x00000800	/* round up				*/
1027c478bd9Sstevel@tonic-gate #define	FPCHOP	0x00000C00	/* chop (truncate toward zero)		*/
1037c478bd9Sstevel@tonic-gate #define	FPP	0x00000000	/* projective infinity			*/
1047c478bd9Sstevel@tonic-gate #define	FPA	0x00001000	/* affine infinity			*/
1057c478bd9Sstevel@tonic-gate #define	WFPB17	0x00020000	/* bit 17				*/
1067c478bd9Sstevel@tonic-gate #define	WFPB24	0x00040000	/* bit 24				*/
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * masks for 80387 status word
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #define	FPS_IE	0x00000001	/* invalid operation			*/
1127c478bd9Sstevel@tonic-gate #define	FPS_DE	0x00000002	/* denormalized operand			*/
113ae115bc7Smrj #define	FPS_ZE	0x00000004	/* zero divide				*/
1147c478bd9Sstevel@tonic-gate #define	FPS_OE	0x00000008	/* overflow				*/
1157c478bd9Sstevel@tonic-gate #define	FPS_UE	0x00000010	/* underflow				*/
1167c478bd9Sstevel@tonic-gate #define	FPS_PE	0x00000020	/* precision				*/
1177c478bd9Sstevel@tonic-gate #define	FPS_SF	0x00000040	/* stack fault				*/
1187c478bd9Sstevel@tonic-gate #define	FPS_ES	0x00000080	/* error summary bit			*/
1197c478bd9Sstevel@tonic-gate #define	FPS_C0	0x00000100	/* C0 bit				*/
1207c478bd9Sstevel@tonic-gate #define	FPS_C1	0x00000200	/* C1 bit				*/
1217c478bd9Sstevel@tonic-gate #define	FPS_C2	0x00000400	/* C2 bit				*/
1227c478bd9Sstevel@tonic-gate #define	FPS_TOP	0x00003800	/* top of stack pointer			*/
1237c478bd9Sstevel@tonic-gate #define	FPS_C3	0x00004000	/* C3 bit				*/
1247c478bd9Sstevel@tonic-gate #define	FPS_B	0x00008000	/* busy bit				*/
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * Exception flags manually cleared during x87 exception handling.
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate #define	FPS_SW_EFLAGS	\
1307c478bd9Sstevel@tonic-gate 	(FPS_IE|FPS_DE|FPS_ZE|FPS_OE|FPS_UE|FPS_PE|FPS_SF|FPS_ES|FPS_B)
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Initial value of FPU control word as per 4th ed. ABI document
1347c478bd9Sstevel@tonic-gate  * - affine infinity
1357c478bd9Sstevel@tonic-gate  * - round to nearest or even
1367c478bd9Sstevel@tonic-gate  * - 64-bit double precision
1377c478bd9Sstevel@tonic-gate  * - all exceptions masked
138*ed093b41SRobert Mustacchi  *
139*ed093b41SRobert Mustacchi  * The 4th ed. SVR4 ABI didn't discuss the value of reserved bits. The ISA
140*ed093b41SRobert Mustacchi  * defines bit 6 (0x40) as reserved, but also that it is set (rather than clear,
141*ed093b41SRobert Mustacchi  * like many other Reserved bits). We preserve that in our value here.
142*ed093b41SRobert Mustacchi  */
143*ed093b41SRobert Mustacchi #define	FPU_CW_INIT	0x137f
144*ed093b41SRobert Mustacchi 
145*ed093b41SRobert Mustacchi /*
146*ed093b41SRobert Mustacchi  * This is the Intel mandated form of the default value of the x87 control word.
147*ed093b41SRobert Mustacchi  * This is different from what we use and should only be used in the context of
148*ed093b41SRobert Mustacchi  * representing that default state (e.g. in /proc xregs).
1497c478bd9Sstevel@tonic-gate  */
150*ed093b41SRobert Mustacchi #define	FPU_CW_INIT_HW	0x037f
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * masks and flags for SSE/SSE2 MXCSR
1547c478bd9Sstevel@tonic-gate  */
155d0158222SRobert Mustacchi #define	SSE_IE	0x00000001	/* invalid operation			*/
156d0158222SRobert Mustacchi #define	SSE_DE	0x00000002	/* denormalized operand			*/
1577c478bd9Sstevel@tonic-gate #define	SSE_ZE	0x00000004	/* zero divide				*/
1587c478bd9Sstevel@tonic-gate #define	SSE_OE	0x00000008	/* overflow				*/
1597c478bd9Sstevel@tonic-gate #define	SSE_UE	0x00000010	/* underflow				*/
1607c478bd9Sstevel@tonic-gate #define	SSE_PE	0x00000020	/* precision				*/
1617c478bd9Sstevel@tonic-gate #define	SSE_DAZ	0x00000040	/* denormals are zero			*/
1627c478bd9Sstevel@tonic-gate #define	SSE_IM	0x00000080	/* invalid op exception mask		*/
1637c478bd9Sstevel@tonic-gate #define	SSE_DM	0x00000100	/* denormalize exception mask		*/
1647c478bd9Sstevel@tonic-gate #define	SSE_ZM	0x00000200	/* zero-divide exception mask		*/
1657c478bd9Sstevel@tonic-gate #define	SSE_OM	0x00000400	/* overflow exception mask		*/
1667c478bd9Sstevel@tonic-gate #define	SSE_UM	0x00000800	/* underflow exception mask		*/
1677c478bd9Sstevel@tonic-gate #define	SSE_PM	0x00001000	/* precision exception mask		*/
1687c478bd9Sstevel@tonic-gate #define	SSE_RC	0x00006000	/* rounding control			*/
1697c478bd9Sstevel@tonic-gate #define	SSE_RD	0x00002000	/* rounding control: round down		*/
1707c478bd9Sstevel@tonic-gate #define	SSE_RU	0x00004000	/* rounding control: round up		*/
171d0158222SRobert Mustacchi #define	SSE_FZ	0x00008000	/* flush to zero for masked underflow	*/
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_EFLAGS	\
1747c478bd9Sstevel@tonic-gate 	(SSE_IE|SSE_DE|SSE_ZE|SSE_OE|SSE_UE|SSE_PE)	/* 0x3f */
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_INIT	\
1777c478bd9Sstevel@tonic-gate 	(SSE_IM|SSE_DM|SSE_ZM|SSE_OM|SSE_UM|SSE_PM)	/* 0x1f80 */
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #define	SSE_MXCSR_MASK_DEFAULT	\
1807c478bd9Sstevel@tonic-gate 	(0xffff & ~SSE_DAZ)				/* 0xffbf */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #define	SSE_FMT_MXCSR	\
1837c478bd9Sstevel@tonic-gate 	"\20\20fz\17ru\16rd\15pm\14um\13om\12zm\11dm"	\
1847c478bd9Sstevel@tonic-gate 	"\10im\7daz\6pe\5ue\4oe\3ze\2de\1ie"
1857c478bd9Sstevel@tonic-gate 
186bc0e9132SGordon Ross /*
187bc0e9132SGordon Ross  * This structure is written to memory by an 'fnsave' instruction
188bc0e9132SGordon Ross  */
189bc0e9132SGordon Ross struct fnsave_state {
190bc0e9132SGordon Ross 	uint16_t	f_fcw;
191bc0e9132SGordon Ross 	uint16_t	__f_ign0;
192bc0e9132SGordon Ross 	uint16_t	f_fsw;
193bc0e9132SGordon Ross 	uint16_t	__f_ign1;
194bc0e9132SGordon Ross 	uint16_t	f_ftw;
195bc0e9132SGordon Ross 	uint16_t	__f_ign2;
196bc0e9132SGordon Ross 	uint32_t	f_eip;
197bc0e9132SGordon Ross 	uint16_t	f_cs;
198bc0e9132SGordon Ross 	uint16_t	f_fop;
199bc0e9132SGordon Ross 	uint32_t	f_dp;
200bc0e9132SGordon Ross 	uint16_t	f_ds;
201bc0e9132SGordon Ross 	uint16_t	__f_ign3;
202bc0e9132SGordon Ross 	union {
203bc0e9132SGordon Ross 		uint16_t fpr_16[5];	/* 80-bits of x87 state */
204bc0e9132SGordon Ross 	} f_st[8];
205bc0e9132SGordon Ross };	/* 108 bytes */
206bc0e9132SGordon Ross 
207bc0e9132SGordon Ross /*
208bc0e9132SGordon Ross  * This structure is written to memory by an 'fxsave' instruction
209bc0e9132SGordon Ross  * Note the variant behaviour of this instruction between long mode
210bc0e9132SGordon Ross  * and legacy environments!
211bc0e9132SGordon Ross  */
212bc0e9132SGordon Ross struct fxsave_state {
213bc0e9132SGordon Ross 	uint16_t	fx_fcw;
214bc0e9132SGordon Ross 	uint16_t	fx_fsw;
215bc0e9132SGordon Ross 	uint16_t	fx_fctw;	/* compressed tag word */
216bc0e9132SGordon Ross 	uint16_t	fx_fop;
217bc0e9132SGordon Ross #if defined(__amd64)
218bc0e9132SGordon Ross 	uint64_t	fx_rip;
219bc0e9132SGordon Ross 	uint64_t	fx_rdp;
220bc0e9132SGordon Ross #else
221bc0e9132SGordon Ross 	uint32_t	fx_eip;
222bc0e9132SGordon Ross 	uint16_t	fx_cs;
223bc0e9132SGordon Ross 	uint16_t	__fx_ign0;
224bc0e9132SGordon Ross 	uint32_t	fx_dp;
225bc0e9132SGordon Ross 	uint16_t	fx_ds;
226bc0e9132SGordon Ross 	uint16_t	__fx_ign1;
227bc0e9132SGordon Ross #endif
228bc0e9132SGordon Ross 	uint32_t	fx_mxcsr;
229bc0e9132SGordon Ross 	uint32_t	fx_mxcsr_mask;
230bc0e9132SGordon Ross 	union {
231bc0e9132SGordon Ross 		uint16_t fpr_16[5];	/* 80-bits of x87 state */
232bc0e9132SGordon Ross 		u_longlong_t fpr_mmx;	/* 64-bit mmx register */
233bc0e9132SGordon Ross 		uint32_t __fpr_pad[4];	/* (pad out to 128-bits) */
234bc0e9132SGordon Ross 	} fx_st[8];
235bc0e9132SGordon Ross #if defined(__amd64)
236bc0e9132SGordon Ross 	upad128_t	fx_xmm[16];	/* 128-bit registers */
237bc0e9132SGordon Ross 	upad128_t	__fx_ign2[6];
238bc0e9132SGordon Ross #else
239bc0e9132SGordon Ross 	upad128_t	fx_xmm[8];	/* 128-bit registers */
240bc0e9132SGordon Ross 	upad128_t	__fx_ign2[14];
241bc0e9132SGordon Ross #endif
242da8e4073SToomas Soome } __aligned(16);	/* 512 bytes */
243bc0e9132SGordon Ross 
244957246c9SPatrick Mooney /*
245957246c9SPatrick Mooney  * This structure represents the header portion of the data layout used by the
246957246c9SPatrick Mooney  * 'xsave' instruction variants.  It is documented in section 13.4.2 of the
247957246c9SPatrick Mooney  * Intel 64 and IA-32 Architectures Software Developer’s Manual, Volume 1
248957246c9SPatrick Mooney  * (IASDv1).  Although "header" is somewhat of a misnomer, considering the data
249957246c9SPatrick Mooney  * begins at offset 512 of the xsave area, its contents dictate which portions
250957246c9SPatrick Mooney  * of the area are present and how they may be formatted.
251957246c9SPatrick Mooney  */
252957246c9SPatrick Mooney struct xsave_header {
253957246c9SPatrick Mooney 	uint64_t	xsh_xstate_bv;
254957246c9SPatrick Mooney 	uint64_t	xsh_xcomp_bv;
255957246c9SPatrick Mooney 	uint64_t	xsh_reserved[6];
256957246c9SPatrick Mooney };
257957246c9SPatrick Mooney 
258bc0e9132SGordon Ross /*
259088d69f8SJerry Jelinek  * This structure is written to memory by one of the 'xsave' instruction
260088d69f8SJerry Jelinek  * variants. The first 512 bytes are compatible with the format of the 'fxsave'
261957246c9SPatrick Mooney  * area.  The extended portion is documented in section 13.4.3.
262088d69f8SJerry Jelinek  *
2634c28a617SRobert Mustacchi  * Our size is at least AVX_XSAVE_SIZE (832 bytes), which is asserted
2644c28a617SRobert Mustacchi  * statically.  Enabling additional xsave-related CPU features requires an
2654c28a617SRobert Mustacchi  * increase in the size. We dynamically allocate the per-lwp xsave area at
2664c28a617SRobert Mustacchi  * runtime, based on the size needed for the CPU-specific features. This
2674c28a617SRobert Mustacchi  * xsave_state structure simply defines our historical layout for the beginning
2684c28a617SRobert Mustacchi  * of the xsave area. The locations and size of new, extended, components is
2694c28a617SRobert Mustacchi  * determined dynamically by querying the CPU. See the xsave_info structure in
2704c28a617SRobert Mustacchi  * cpuid.c.
271088d69f8SJerry Jelinek  *
272957246c9SPatrick Mooney  * xsave component usage is tracked using bits in the xstate_bv field of the
273957246c9SPatrick Mooney  * header. The components are documented in section 13.1 of IASDv1. For easy
274957246c9SPatrick Mooney  * reference, this is a summary of the currently defined component bit
275957246c9SPatrick Mooney  * definitions:
276088d69f8SJerry Jelinek  *	x87			0x0001
277088d69f8SJerry Jelinek  *	SSE			0x0002
278088d69f8SJerry Jelinek  *	AVX			0x0004
279088d69f8SJerry Jelinek  *	bndreg (MPX)		0x0008
280088d69f8SJerry Jelinek  *	bndcsr (MPX)		0x0010
281088d69f8SJerry Jelinek  *	opmask (AVX512)		0x0020
282088d69f8SJerry Jelinek  *	zmm hi256 (AVX512)	0x0040
283088d69f8SJerry Jelinek  *	zmm hi16 (AVX512)	0x0080
284088d69f8SJerry Jelinek  *	PT			0x0100
285088d69f8SJerry Jelinek  *	PKRU			0x0200
286088d69f8SJerry Jelinek  * When xsaveopt_ctxt is being used to save into the xsave_state area, the
287957246c9SPatrick Mooney  * xstate_bv field is updated by the xsaveopt instruction to indicate which
288088d69f8SJerry Jelinek  * elements of the xsave area are active.
289088d69f8SJerry Jelinek  *
290957246c9SPatrick Mooney  * The xcomp_bv field should always be 0, since we do not currently use the
291957246c9SPatrick Mooney  * compressed form of xsave (xsavec).
292bc0e9132SGordon Ross  */
293bc0e9132SGordon Ross struct xsave_state {
294088d69f8SJerry Jelinek 	struct fxsave_state	xs_fxsave;	/* 0-511 legacy region */
295957246c9SPatrick Mooney 	struct xsave_header	xs_header;	/* 512-575 XSAVE header */
296088d69f8SJerry Jelinek 	upad128_t		xs_ymm[16];	/* 576 AVX component */
297da8e4073SToomas Soome } __aligned(64);
298bc0e9132SGordon Ross 
299957246c9SPatrick Mooney /*
300957246c9SPatrick Mooney  * While AVX_XSTATE_SIZE is the smallest the kernel will allocate for FPU
301957246c9SPatrick Mooney  * state-saving, other consumers may constrain themselves to the minimum
302957246c9SPatrick Mooney  * possible xsave state structure, which features only the legacy area and the
303957246c9SPatrick Mooney  * bare xsave header.
304957246c9SPatrick Mooney  */
305957246c9SPatrick Mooney #define	MIN_XSAVE_SIZE	(sizeof (struct fxsave_state) + \
306957246c9SPatrick Mooney 			    sizeof (struct xsave_header))
307957246c9SPatrick Mooney 
308bc0e9132SGordon Ross /*
309bc0e9132SGordon Ross  * Kernel's FPU save area
310bc0e9132SGordon Ross  */
311bc0e9132SGordon Ross typedef struct {
312bc0e9132SGordon Ross 	union _kfpu_u {
313088d69f8SJerry Jelinek 		void *kfpu_generic;
314088d69f8SJerry Jelinek 		struct fxsave_state *kfpu_fx;
315088d69f8SJerry Jelinek 		struct xsave_state *kfpu_xs;
316bc0e9132SGordon Ross 	} kfpu_u;
317bc0e9132SGordon Ross 	uint32_t kfpu_status;		/* saved at #mf exception */
318bc0e9132SGordon Ross 	uint32_t kfpu_xstatus;		/* saved at #xm exception */
319bc0e9132SGordon Ross } kfpu_t;
320bc0e9132SGordon Ross 
321*ed093b41SRobert Mustacchi extern int fp_kind;		/* kind of fp support */
322*ed093b41SRobert Mustacchi extern int fp_save_mech;	/* fp save/restore mechanism */
323*ed093b41SRobert Mustacchi extern int fpu_exists;		/* FPU hw exists */
324*ed093b41SRobert Mustacchi extern int fp_elf;		/* FP elf type */
325*ed093b41SRobert Mustacchi extern uint64_t xsave_bv_all;	/* Set of enabed xcr0 values */
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate #ifdef _KERNEL
3287c478bd9Sstevel@tonic-gate 
329ae115bc7Smrj extern int fpu_ignored;
330ae115bc7Smrj extern int fpu_pentium_fdivbug;
331ae115bc7Smrj 
3327c478bd9Sstevel@tonic-gate extern uint32_t sse_mxcsr_mask;
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate extern void fpu_probe(void);
335ae115bc7Smrj extern uint_t fpu_initial_probe(void);
3367c478bd9Sstevel@tonic-gate 
337d0158222SRobert Mustacchi extern void fpu_auxv_info(int *, size_t *);
338*ed093b41SRobert Mustacchi extern boolean_t fpu_xsave_enabled(void);
339d0158222SRobert Mustacchi 
340ae115bc7Smrj extern void fpnsave_ctxt(void *);
341ae115bc7Smrj extern void fpxsave_ctxt(void *);
3427af88ac7SKuriakose Kuruvilla extern void xsave_ctxt(void *);
343088d69f8SJerry Jelinek extern void xsaveopt_ctxt(void *);
344088d69f8SJerry Jelinek extern void fpxsave_excp_clr_ctxt(void *);
345088d69f8SJerry Jelinek extern void xsave_excp_clr_ctxt(void *);
346088d69f8SJerry Jelinek extern void xsaveopt_excp_clr_ctxt(void *);
347ae115bc7Smrj extern void (*fpsave_ctxt)(void *);
348088d69f8SJerry Jelinek extern void (*xsavep)(struct xsave_state *, uint64_t);
3497c478bd9Sstevel@tonic-gate 
3504c28a617SRobert Mustacchi extern void fpxrestore_ctxt(void *);
3514c28a617SRobert Mustacchi extern void xrestore_ctxt(void *);
3524c28a617SRobert Mustacchi extern void (*fprestore_ctxt)(void *);
3534c28a617SRobert Mustacchi 
354ae115bc7Smrj extern void fxsave_insn(struct fxsave_state *);
3557c478bd9Sstevel@tonic-gate extern void fpxsave(struct fxsave_state *);
3567c478bd9Sstevel@tonic-gate extern void fpxrestore(struct fxsave_state *);
3577af88ac7SKuriakose Kuruvilla extern void xsave(struct xsave_state *, uint64_t);
358088d69f8SJerry Jelinek extern void xsaveopt(struct xsave_state *, uint64_t);
3597af88ac7SKuriakose Kuruvilla extern void xrestore(struct xsave_state *, uint64_t);
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate extern void fpenable(void);
3627c478bd9Sstevel@tonic-gate extern void fpdisable(void);
3637c478bd9Sstevel@tonic-gate extern void fpinit(void);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate extern uint32_t fperr_reset(void);
3667c478bd9Sstevel@tonic-gate extern uint32_t fpxerr_reset(void);
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate extern uint32_t fpgetcwsw(void);
3697c478bd9Sstevel@tonic-gate extern uint32_t fpgetmxcsr(void);
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate struct regs;
3727c478bd9Sstevel@tonic-gate extern int fpexterrflt(struct regs *);
3737c478bd9Sstevel@tonic-gate extern int fpsimderrflt(struct regs *);
3747c478bd9Sstevel@tonic-gate extern void fpsetcw(uint16_t, uint32_t);
3754c28a617SRobert Mustacchi extern void fp_seed(void);
3764c28a617SRobert Mustacchi extern void fp_exec(void);
377088d69f8SJerry Jelinek struct _klwp;
378088d69f8SJerry Jelinek extern void fp_lwp_init(struct _klwp *);
379088d69f8SJerry Jelinek extern void fp_lwp_cleanup(struct _klwp *);
380088d69f8SJerry Jelinek extern void fp_lwp_dup(struct _klwp *);
3817c478bd9Sstevel@tonic-gate 
382a32a1f37SRobert Mustacchi extern const struct fxsave_state sse_initial;
383a32a1f37SRobert Mustacchi extern const struct xsave_state avx_initial;
384a32a1f37SRobert Mustacchi 
385*ed093b41SRobert Mustacchi struct proc;
386*ed093b41SRobert Mustacchi struct ucontext;
387*ed093b41SRobert Mustacchi extern void fpu_proc_xregs_info(struct proc *, uint32_t *, uint32_t *,
388*ed093b41SRobert Mustacchi     uint32_t *);
389*ed093b41SRobert Mustacchi extern size_t fpu_proc_xregs_max_size(void);
390*ed093b41SRobert Mustacchi extern void fpu_proc_xregs_get(struct _klwp *, void *);
391*ed093b41SRobert Mustacchi extern int fpu_proc_xregs_set(struct _klwp *, void *);
392*ed093b41SRobert Mustacchi extern int fpu_signal_copyin(struct _klwp *, struct ucontext *);
393*ed093b41SRobert Mustacchi typedef int (*fpu_copyout_f)(const void *, void *, size_t);
394*ed093b41SRobert Mustacchi extern int fpu_signal_copyout(struct _klwp *, uintptr_t, fpu_copyout_f);
395*ed093b41SRobert Mustacchi extern void fpu_set_xsave(struct _klwp *, const void *);
396*ed093b41SRobert Mustacchi extern size_t fpu_signal_size(struct _klwp *);
397*ed093b41SRobert Mustacchi 
398*ed093b41SRobert Mustacchi extern void fpu_get_fpregset(struct _klwp *, fpregset_t *);
399*ed093b41SRobert Mustacchi extern void fpu_set_fpregset(struct _klwp *, const fpregset_t *);
400*ed093b41SRobert Mustacchi 
4017c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate #endif
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate #endif	/* _SYS_FP_H */
408