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*bc0e9132SGordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved. 23*bc0e9132SGordon Ross * 247af88ac7SKuriakose Kuruvilla * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */ 287c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */ 297c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifndef _SYS_FP_H 327c478bd9Sstevel@tonic-gate #define _SYS_FP_H 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * 80287/80387 and SSE/SSE2 floating point processor definitions 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * values that go into fp_kind 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate #define FP_NO 0 /* no fp chip, no emulator (no fp support) */ 467c478bd9Sstevel@tonic-gate #define FP_SW 1 /* no fp chip, using software emulator */ 477c478bd9Sstevel@tonic-gate #define FP_HW 2 /* chip present bit */ 487c478bd9Sstevel@tonic-gate #define FP_287 2 /* 80287 chip present */ 497c478bd9Sstevel@tonic-gate #define FP_387 3 /* 80387 chip present */ 507c478bd9Sstevel@tonic-gate #define FP_487 6 /* 80487 chip present */ 517c478bd9Sstevel@tonic-gate #define FP_486 6 /* 80486 chip present */ 527af88ac7SKuriakose Kuruvilla /* 537af88ac7SKuriakose Kuruvilla * The following values are bit flags instead of actual values. 547af88ac7SKuriakose Kuruvilla * E.g. to know if we are using SSE, test (value & __FP_SSE) instead 557af88ac7SKuriakose Kuruvilla * of (value == __FP_SSE). 567af88ac7SKuriakose Kuruvilla */ 577af88ac7SKuriakose Kuruvilla #define __FP_SSE 0x100 /* .. plus SSE-capable CPU */ 587af88ac7SKuriakose Kuruvilla #define __FP_AVX 0x200 /* .. plus AVX-capable CPU */ 597af88ac7SKuriakose Kuruvilla 607af88ac7SKuriakose Kuruvilla /* 617af88ac7SKuriakose Kuruvilla * values that go into fp_save_mech 627af88ac7SKuriakose Kuruvilla */ 637af88ac7SKuriakose Kuruvilla #define FP_FNSAVE 1 /* fnsave/frstor instructions */ 647af88ac7SKuriakose Kuruvilla #define FP_FXSAVE 2 /* fxsave/fxrstor instructions */ 657af88ac7SKuriakose Kuruvilla #define FP_XSAVE 3 /* xsave/xrstor instructions */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * masks for 80387 control word 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate #define FPIM 0x00000001 /* invalid operation */ 717c478bd9Sstevel@tonic-gate #define FPDM 0x00000002 /* denormalized operand */ 727c478bd9Sstevel@tonic-gate #define FPZM 0x00000004 /* zero divide */ 737c478bd9Sstevel@tonic-gate #define FPOM 0x00000008 /* overflow */ 747c478bd9Sstevel@tonic-gate #define FPUM 0x00000010 /* underflow */ 757c478bd9Sstevel@tonic-gate #define FPPM 0x00000020 /* precision */ 767c478bd9Sstevel@tonic-gate #define FPPC 0x00000300 /* precision control */ 777c478bd9Sstevel@tonic-gate #define FPRC 0x00000C00 /* rounding control */ 787c478bd9Sstevel@tonic-gate #define FPIC 0x00001000 /* infinity control */ 797c478bd9Sstevel@tonic-gate #define WFPDE 0x00000080 /* data chain exception */ 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* 827c478bd9Sstevel@tonic-gate * (Old symbol compatibility) 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate #define FPINV FPIM 857c478bd9Sstevel@tonic-gate #define FPDNO FPDM 867c478bd9Sstevel@tonic-gate #define FPZDIV FPZM 877c478bd9Sstevel@tonic-gate #define FPOVR FPOM 887c478bd9Sstevel@tonic-gate #define FPUNR FPUM 897c478bd9Sstevel@tonic-gate #define FPPRE FPPM 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * precision, rounding, and infinity options in control word 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate #define FPSIG24 0x00000000 /* 24-bit significand precision (short) */ 957c478bd9Sstevel@tonic-gate #define FPSIG53 0x00000200 /* 53-bit significand precision (long) */ 967c478bd9Sstevel@tonic-gate #define FPSIG64 0x00000300 /* 64-bit significand precision (temp) */ 977c478bd9Sstevel@tonic-gate #define FPRTN 0x00000000 /* round to nearest or even */ 987c478bd9Sstevel@tonic-gate #define FPRD 0x00000400 /* round down */ 997c478bd9Sstevel@tonic-gate #define FPRU 0x00000800 /* round up */ 1007c478bd9Sstevel@tonic-gate #define FPCHOP 0x00000C00 /* chop (truncate toward zero) */ 1017c478bd9Sstevel@tonic-gate #define FPP 0x00000000 /* projective infinity */ 1027c478bd9Sstevel@tonic-gate #define FPA 0x00001000 /* affine infinity */ 1037c478bd9Sstevel@tonic-gate #define WFPB17 0x00020000 /* bit 17 */ 1047c478bd9Sstevel@tonic-gate #define WFPB24 0x00040000 /* bit 24 */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * masks for 80387 status word 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate #define FPS_IE 0x00000001 /* invalid operation */ 1107c478bd9Sstevel@tonic-gate #define FPS_DE 0x00000002 /* denormalized operand */ 111ae115bc7Smrj #define FPS_ZE 0x00000004 /* zero divide */ 1127c478bd9Sstevel@tonic-gate #define FPS_OE 0x00000008 /* overflow */ 1137c478bd9Sstevel@tonic-gate #define FPS_UE 0x00000010 /* underflow */ 1147c478bd9Sstevel@tonic-gate #define FPS_PE 0x00000020 /* precision */ 1157c478bd9Sstevel@tonic-gate #define FPS_SF 0x00000040 /* stack fault */ 1167c478bd9Sstevel@tonic-gate #define FPS_ES 0x00000080 /* error summary bit */ 1177c478bd9Sstevel@tonic-gate #define FPS_C0 0x00000100 /* C0 bit */ 1187c478bd9Sstevel@tonic-gate #define FPS_C1 0x00000200 /* C1 bit */ 1197c478bd9Sstevel@tonic-gate #define FPS_C2 0x00000400 /* C2 bit */ 1207c478bd9Sstevel@tonic-gate #define FPS_TOP 0x00003800 /* top of stack pointer */ 1217c478bd9Sstevel@tonic-gate #define FPS_C3 0x00004000 /* C3 bit */ 1227c478bd9Sstevel@tonic-gate #define FPS_B 0x00008000 /* busy bit */ 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * Exception flags manually cleared during x87 exception handling. 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate #define FPS_SW_EFLAGS \ 1287c478bd9Sstevel@tonic-gate (FPS_IE|FPS_DE|FPS_ZE|FPS_OE|FPS_UE|FPS_PE|FPS_SF|FPS_ES|FPS_B) 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Initial value of FPU control word as per 4th ed. ABI document 1327c478bd9Sstevel@tonic-gate * - affine infinity 1337c478bd9Sstevel@tonic-gate * - round to nearest or even 1347c478bd9Sstevel@tonic-gate * - 64-bit double precision 1357c478bd9Sstevel@tonic-gate * - all exceptions masked 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate #define FPU_CW_INIT 0x133f 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * masks and flags for SSE/SSE2 MXCSR 1417c478bd9Sstevel@tonic-gate */ 1427c478bd9Sstevel@tonic-gate #define SSE_IE 0x00000001 /* invalid operation */ 1437c478bd9Sstevel@tonic-gate #define SSE_DE 0x00000002 /* denormalized operand */ 1447c478bd9Sstevel@tonic-gate #define SSE_ZE 0x00000004 /* zero divide */ 1457c478bd9Sstevel@tonic-gate #define SSE_OE 0x00000008 /* overflow */ 1467c478bd9Sstevel@tonic-gate #define SSE_UE 0x00000010 /* underflow */ 1477c478bd9Sstevel@tonic-gate #define SSE_PE 0x00000020 /* precision */ 1487c478bd9Sstevel@tonic-gate #define SSE_DAZ 0x00000040 /* denormals are zero */ 1497c478bd9Sstevel@tonic-gate #define SSE_IM 0x00000080 /* invalid op exception mask */ 1507c478bd9Sstevel@tonic-gate #define SSE_DM 0x00000100 /* denormalize exception mask */ 1517c478bd9Sstevel@tonic-gate #define SSE_ZM 0x00000200 /* zero-divide exception mask */ 1527c478bd9Sstevel@tonic-gate #define SSE_OM 0x00000400 /* overflow exception mask */ 1537c478bd9Sstevel@tonic-gate #define SSE_UM 0x00000800 /* underflow exception mask */ 1547c478bd9Sstevel@tonic-gate #define SSE_PM 0x00001000 /* precision exception mask */ 1557c478bd9Sstevel@tonic-gate #define SSE_RC 0x00006000 /* rounding control */ 1567c478bd9Sstevel@tonic-gate #define SSE_RD 0x00002000 /* rounding control: round down */ 1577c478bd9Sstevel@tonic-gate #define SSE_RU 0x00004000 /* rounding control: round up */ 1587c478bd9Sstevel@tonic-gate #define SSE_FZ 0x00008000 /* flush to zero for masked underflow */ 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #define SSE_MXCSR_EFLAGS \ 1617c478bd9Sstevel@tonic-gate (SSE_IE|SSE_DE|SSE_ZE|SSE_OE|SSE_UE|SSE_PE) /* 0x3f */ 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #define SSE_MXCSR_INIT \ 1647c478bd9Sstevel@tonic-gate (SSE_IM|SSE_DM|SSE_ZM|SSE_OM|SSE_UM|SSE_PM) /* 0x1f80 */ 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #define SSE_MXCSR_MASK_DEFAULT \ 1677c478bd9Sstevel@tonic-gate (0xffff & ~SSE_DAZ) /* 0xffbf */ 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate #define SSE_FMT_MXCSR \ 1707c478bd9Sstevel@tonic-gate "\20\20fz\17ru\16rd\15pm\14um\13om\12zm\11dm" \ 1717c478bd9Sstevel@tonic-gate "\10im\7daz\6pe\5ue\4oe\3ze\2de\1ie" 1727c478bd9Sstevel@tonic-gate 173*bc0e9132SGordon Ross /* 174*bc0e9132SGordon Ross * This structure is written to memory by an 'fnsave' instruction 175*bc0e9132SGordon Ross */ 176*bc0e9132SGordon Ross struct fnsave_state { 177*bc0e9132SGordon Ross uint16_t f_fcw; 178*bc0e9132SGordon Ross uint16_t __f_ign0; 179*bc0e9132SGordon Ross uint16_t f_fsw; 180*bc0e9132SGordon Ross uint16_t __f_ign1; 181*bc0e9132SGordon Ross uint16_t f_ftw; 182*bc0e9132SGordon Ross uint16_t __f_ign2; 183*bc0e9132SGordon Ross uint32_t f_eip; 184*bc0e9132SGordon Ross uint16_t f_cs; 185*bc0e9132SGordon Ross uint16_t f_fop; 186*bc0e9132SGordon Ross uint32_t f_dp; 187*bc0e9132SGordon Ross uint16_t f_ds; 188*bc0e9132SGordon Ross uint16_t __f_ign3; 189*bc0e9132SGordon Ross union { 190*bc0e9132SGordon Ross uint16_t fpr_16[5]; /* 80-bits of x87 state */ 191*bc0e9132SGordon Ross } f_st[8]; 192*bc0e9132SGordon Ross }; /* 108 bytes */ 193*bc0e9132SGordon Ross 194*bc0e9132SGordon Ross /* 195*bc0e9132SGordon Ross * This structure is written to memory by an 'fxsave' instruction 196*bc0e9132SGordon Ross * Note the variant behaviour of this instruction between long mode 197*bc0e9132SGordon Ross * and legacy environments! 198*bc0e9132SGordon Ross */ 199*bc0e9132SGordon Ross struct fxsave_state { 200*bc0e9132SGordon Ross uint16_t fx_fcw; 201*bc0e9132SGordon Ross uint16_t fx_fsw; 202*bc0e9132SGordon Ross uint16_t fx_fctw; /* compressed tag word */ 203*bc0e9132SGordon Ross uint16_t fx_fop; 204*bc0e9132SGordon Ross #if defined(__amd64) 205*bc0e9132SGordon Ross uint64_t fx_rip; 206*bc0e9132SGordon Ross uint64_t fx_rdp; 207*bc0e9132SGordon Ross #else 208*bc0e9132SGordon Ross uint32_t fx_eip; 209*bc0e9132SGordon Ross uint16_t fx_cs; 210*bc0e9132SGordon Ross uint16_t __fx_ign0; 211*bc0e9132SGordon Ross uint32_t fx_dp; 212*bc0e9132SGordon Ross uint16_t fx_ds; 213*bc0e9132SGordon Ross uint16_t __fx_ign1; 214*bc0e9132SGordon Ross #endif 215*bc0e9132SGordon Ross uint32_t fx_mxcsr; 216*bc0e9132SGordon Ross uint32_t fx_mxcsr_mask; 217*bc0e9132SGordon Ross union { 218*bc0e9132SGordon Ross uint16_t fpr_16[5]; /* 80-bits of x87 state */ 219*bc0e9132SGordon Ross u_longlong_t fpr_mmx; /* 64-bit mmx register */ 220*bc0e9132SGordon Ross uint32_t __fpr_pad[4]; /* (pad out to 128-bits) */ 221*bc0e9132SGordon Ross } fx_st[8]; 222*bc0e9132SGordon Ross #if defined(__amd64) 223*bc0e9132SGordon Ross upad128_t fx_xmm[16]; /* 128-bit registers */ 224*bc0e9132SGordon Ross upad128_t __fx_ign2[6]; 225*bc0e9132SGordon Ross #else 226*bc0e9132SGordon Ross upad128_t fx_xmm[8]; /* 128-bit registers */ 227*bc0e9132SGordon Ross upad128_t __fx_ign2[14]; 228*bc0e9132SGordon Ross #endif 229*bc0e9132SGordon Ross }; /* 512 bytes */ 230*bc0e9132SGordon Ross 231*bc0e9132SGordon Ross /* 232*bc0e9132SGordon Ross * This structure is written to memory by an 'xsave' instruction. 233*bc0e9132SGordon Ross * First 512 byte is compatible with the format of an 'fxsave' area. 234*bc0e9132SGordon Ross */ 235*bc0e9132SGordon Ross struct xsave_state { 236*bc0e9132SGordon Ross struct fxsave_state xs_fxsave; 237*bc0e9132SGordon Ross uint64_t xs_xstate_bv; /* 512 */ 238*bc0e9132SGordon Ross uint64_t xs_rsv_mbz[2]; 239*bc0e9132SGordon Ross uint64_t xs_reserved[5]; 240*bc0e9132SGordon Ross upad128_t xs_ymm[16]; /* avx - 576 */ 241*bc0e9132SGordon Ross }; /* 832 bytes, asserted in fpnoextflt() */ 242*bc0e9132SGordon Ross 243*bc0e9132SGordon Ross /* 244*bc0e9132SGordon Ross * Kernel's FPU save area 245*bc0e9132SGordon Ross */ 246*bc0e9132SGordon Ross typedef struct { 247*bc0e9132SGordon Ross union _kfpu_u { 248*bc0e9132SGordon Ross struct fxsave_state kfpu_fx; 249*bc0e9132SGordon Ross #if defined(__i386) 250*bc0e9132SGordon Ross struct fnsave_state kfpu_fn; 251*bc0e9132SGordon Ross #endif 252*bc0e9132SGordon Ross struct xsave_state kfpu_xs; 253*bc0e9132SGordon Ross } kfpu_u; 254*bc0e9132SGordon Ross uint32_t kfpu_status; /* saved at #mf exception */ 255*bc0e9132SGordon Ross uint32_t kfpu_xstatus; /* saved at #xm exception */ 256*bc0e9132SGordon Ross } kfpu_t; 257*bc0e9132SGordon Ross 2587c478bd9Sstevel@tonic-gate extern int fp_kind; /* kind of fp support */ 2597af88ac7SKuriakose Kuruvilla extern int fp_save_mech; /* fp save/restore mechanism */ 2607c478bd9Sstevel@tonic-gate extern int fpu_exists; /* FPU hw exists */ 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate #ifdef _KERNEL 2637c478bd9Sstevel@tonic-gate 264ae115bc7Smrj extern int fpu_ignored; 265ae115bc7Smrj extern int fpu_pentium_fdivbug; 266ae115bc7Smrj 2677c478bd9Sstevel@tonic-gate extern uint32_t sse_mxcsr_mask; 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate extern void fpu_probe(void); 270ae115bc7Smrj extern uint_t fpu_initial_probe(void); 271ae115bc7Smrj extern int fpu_probe_pentium_fdivbug(void); 2727c478bd9Sstevel@tonic-gate 273ae115bc7Smrj extern void fpnsave_ctxt(void *); 274ae115bc7Smrj extern void fpxsave_ctxt(void *); 2757af88ac7SKuriakose Kuruvilla extern void xsave_ctxt(void *); 276ae115bc7Smrj extern void (*fpsave_ctxt)(void *); 2777c478bd9Sstevel@tonic-gate 278ae115bc7Smrj extern void fxsave_insn(struct fxsave_state *); 2797c478bd9Sstevel@tonic-gate extern void fpsave(struct fnsave_state *); 2807c478bd9Sstevel@tonic-gate extern void fprestore(struct fnsave_state *); 2817c478bd9Sstevel@tonic-gate extern void fpxsave(struct fxsave_state *); 2827c478bd9Sstevel@tonic-gate extern void fpxrestore(struct fxsave_state *); 2837af88ac7SKuriakose Kuruvilla extern void xsave(struct xsave_state *, uint64_t); 2847af88ac7SKuriakose Kuruvilla extern void xrestore(struct xsave_state *, uint64_t); 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate extern void fpenable(void); 2877c478bd9Sstevel@tonic-gate extern void fpdisable(void); 2887c478bd9Sstevel@tonic-gate extern void fpinit(void); 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate extern uint32_t fperr_reset(void); 2917c478bd9Sstevel@tonic-gate extern uint32_t fpxerr_reset(void); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate extern uint32_t fpgetcwsw(void); 2947c478bd9Sstevel@tonic-gate extern uint32_t fpgetmxcsr(void); 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate struct regs; 2977c478bd9Sstevel@tonic-gate extern int fpnoextflt(struct regs *); 2987c478bd9Sstevel@tonic-gate extern int fpextovrflt(struct regs *); 2997c478bd9Sstevel@tonic-gate extern int fpexterrflt(struct regs *); 3007c478bd9Sstevel@tonic-gate extern int fpsimderrflt(struct regs *); 3017c478bd9Sstevel@tonic-gate extern void fpsetcw(uint16_t, uint32_t); 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate #ifdef __cplusplus 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate #endif 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate #endif /* _SYS_FP_H */ 310