1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */ 28*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */ 29*0Sstevel@tonic-gate /* All Rights Reserved */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #ifndef _SYS_FP_H 32*0Sstevel@tonic-gate #define _SYS_FP_H 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #ifdef __cplusplus 37*0Sstevel@tonic-gate extern "C" { 38*0Sstevel@tonic-gate #endif 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate /* 41*0Sstevel@tonic-gate * 80287/80387 and SSE/SSE2 floating point processor definitions 42*0Sstevel@tonic-gate */ 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate /* 45*0Sstevel@tonic-gate * values that go into fp_kind 46*0Sstevel@tonic-gate */ 47*0Sstevel@tonic-gate #define FP_NO 0 /* no fp chip, no emulator (no fp support) */ 48*0Sstevel@tonic-gate #define FP_SW 1 /* no fp chip, using software emulator */ 49*0Sstevel@tonic-gate #define FP_HW 2 /* chip present bit */ 50*0Sstevel@tonic-gate #define FP_287 2 /* 80287 chip present */ 51*0Sstevel@tonic-gate #define FP_387 3 /* 80387 chip present */ 52*0Sstevel@tonic-gate #define FP_487 6 /* 80487 chip present */ 53*0Sstevel@tonic-gate #define FP_486 6 /* 80486 chip present */ 54*0Sstevel@tonic-gate #define __FP_SSE 0x103 /* x87 plus SSE-capable CPU */ 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate /* 57*0Sstevel@tonic-gate * masks for 80387 control word 58*0Sstevel@tonic-gate */ 59*0Sstevel@tonic-gate #define FPIM 0x00000001 /* invalid operation */ 60*0Sstevel@tonic-gate #define FPDM 0x00000002 /* denormalized operand */ 61*0Sstevel@tonic-gate #define FPZM 0x00000004 /* zero divide */ 62*0Sstevel@tonic-gate #define FPOM 0x00000008 /* overflow */ 63*0Sstevel@tonic-gate #define FPUM 0x00000010 /* underflow */ 64*0Sstevel@tonic-gate #define FPPM 0x00000020 /* precision */ 65*0Sstevel@tonic-gate #define FPPC 0x00000300 /* precision control */ 66*0Sstevel@tonic-gate #define FPRC 0x00000C00 /* rounding control */ 67*0Sstevel@tonic-gate #define FPIC 0x00001000 /* infinity control */ 68*0Sstevel@tonic-gate #define WFPDE 0x00000080 /* data chain exception */ 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate /* 71*0Sstevel@tonic-gate * (Old symbol compatibility) 72*0Sstevel@tonic-gate */ 73*0Sstevel@tonic-gate #define FPINV FPIM 74*0Sstevel@tonic-gate #define FPDNO FPDM 75*0Sstevel@tonic-gate #define FPZDIV FPZM 76*0Sstevel@tonic-gate #define FPOVR FPOM 77*0Sstevel@tonic-gate #define FPUNR FPUM 78*0Sstevel@tonic-gate #define FPPRE FPPM 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate /* 81*0Sstevel@tonic-gate * precision, rounding, and infinity options in control word 82*0Sstevel@tonic-gate */ 83*0Sstevel@tonic-gate #define FPSIG24 0x00000000 /* 24-bit significand precision (short) */ 84*0Sstevel@tonic-gate #define FPSIG53 0x00000200 /* 53-bit significand precision (long) */ 85*0Sstevel@tonic-gate #define FPSIG64 0x00000300 /* 64-bit significand precision (temp) */ 86*0Sstevel@tonic-gate #define FPRTN 0x00000000 /* round to nearest or even */ 87*0Sstevel@tonic-gate #define FPRD 0x00000400 /* round down */ 88*0Sstevel@tonic-gate #define FPRU 0x00000800 /* round up */ 89*0Sstevel@tonic-gate #define FPCHOP 0x00000C00 /* chop (truncate toward zero) */ 90*0Sstevel@tonic-gate #define FPP 0x00000000 /* projective infinity */ 91*0Sstevel@tonic-gate #define FPA 0x00001000 /* affine infinity */ 92*0Sstevel@tonic-gate #define WFPB17 0x00020000 /* bit 17 */ 93*0Sstevel@tonic-gate #define WFPB24 0x00040000 /* bit 24 */ 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate /* 96*0Sstevel@tonic-gate * masks for 80387 status word 97*0Sstevel@tonic-gate */ 98*0Sstevel@tonic-gate #define FPS_IE 0x00000001 /* invalid operation */ 99*0Sstevel@tonic-gate #define FPS_DE 0x00000002 /* denormalized operand */ 100*0Sstevel@tonic-gate #define FPS_ZE 0x00000004 /* zero devide */ 101*0Sstevel@tonic-gate #define FPS_OE 0x00000008 /* overflow */ 102*0Sstevel@tonic-gate #define FPS_UE 0x00000010 /* underflow */ 103*0Sstevel@tonic-gate #define FPS_PE 0x00000020 /* precision */ 104*0Sstevel@tonic-gate #define FPS_SF 0x00000040 /* stack fault */ 105*0Sstevel@tonic-gate #define FPS_ES 0x00000080 /* error summary bit */ 106*0Sstevel@tonic-gate #define FPS_C0 0x00000100 /* C0 bit */ 107*0Sstevel@tonic-gate #define FPS_C1 0x00000200 /* C1 bit */ 108*0Sstevel@tonic-gate #define FPS_C2 0x00000400 /* C2 bit */ 109*0Sstevel@tonic-gate #define FPS_TOP 0x00003800 /* top of stack pointer */ 110*0Sstevel@tonic-gate #define FPS_C3 0x00004000 /* C3 bit */ 111*0Sstevel@tonic-gate #define FPS_B 0x00008000 /* busy bit */ 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate /* 114*0Sstevel@tonic-gate * Exception flags manually cleared during x87 exception handling. 115*0Sstevel@tonic-gate */ 116*0Sstevel@tonic-gate #define FPS_SW_EFLAGS \ 117*0Sstevel@tonic-gate (FPS_IE|FPS_DE|FPS_ZE|FPS_OE|FPS_UE|FPS_PE|FPS_SF|FPS_ES|FPS_B) 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate /* 120*0Sstevel@tonic-gate * Initial value of FPU control word as per 4th ed. ABI document 121*0Sstevel@tonic-gate * - affine infinity 122*0Sstevel@tonic-gate * - round to nearest or even 123*0Sstevel@tonic-gate * - 64-bit double precision 124*0Sstevel@tonic-gate * - all exceptions masked 125*0Sstevel@tonic-gate */ 126*0Sstevel@tonic-gate #define FPU_CW_INIT 0x133f 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate /* 129*0Sstevel@tonic-gate * masks and flags for SSE/SSE2 MXCSR 130*0Sstevel@tonic-gate */ 131*0Sstevel@tonic-gate #define SSE_IE 0x00000001 /* invalid operation */ 132*0Sstevel@tonic-gate #define SSE_DE 0x00000002 /* denormalized operand */ 133*0Sstevel@tonic-gate #define SSE_ZE 0x00000004 /* zero divide */ 134*0Sstevel@tonic-gate #define SSE_OE 0x00000008 /* overflow */ 135*0Sstevel@tonic-gate #define SSE_UE 0x00000010 /* underflow */ 136*0Sstevel@tonic-gate #define SSE_PE 0x00000020 /* precision */ 137*0Sstevel@tonic-gate #define SSE_DAZ 0x00000040 /* denormals are zero */ 138*0Sstevel@tonic-gate #define SSE_IM 0x00000080 /* invalid op exception mask */ 139*0Sstevel@tonic-gate #define SSE_DM 0x00000100 /* denormalize exception mask */ 140*0Sstevel@tonic-gate #define SSE_ZM 0x00000200 /* zero-divide exception mask */ 141*0Sstevel@tonic-gate #define SSE_OM 0x00000400 /* overflow exception mask */ 142*0Sstevel@tonic-gate #define SSE_UM 0x00000800 /* underflow exception mask */ 143*0Sstevel@tonic-gate #define SSE_PM 0x00001000 /* precision exception mask */ 144*0Sstevel@tonic-gate #define SSE_RC 0x00006000 /* rounding control */ 145*0Sstevel@tonic-gate #define SSE_RD 0x00002000 /* rounding control: round down */ 146*0Sstevel@tonic-gate #define SSE_RU 0x00004000 /* rounding control: round up */ 147*0Sstevel@tonic-gate #define SSE_FZ 0x00008000 /* flush to zero for masked underflow */ 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate #define SSE_MXCSR_EFLAGS \ 150*0Sstevel@tonic-gate (SSE_IE|SSE_DE|SSE_ZE|SSE_OE|SSE_UE|SSE_PE) /* 0x3f */ 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate #define SSE_MXCSR_INIT \ 153*0Sstevel@tonic-gate (SSE_IM|SSE_DM|SSE_ZM|SSE_OM|SSE_UM|SSE_PM) /* 0x1f80 */ 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate #define SSE_MXCSR_MASK_DEFAULT \ 156*0Sstevel@tonic-gate (0xffff & ~SSE_DAZ) /* 0xffbf */ 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate #define SSE_FMT_MXCSR \ 159*0Sstevel@tonic-gate "\20\20fz\17ru\16rd\15pm\14um\13om\12zm\11dm" \ 160*0Sstevel@tonic-gate "\10im\7daz\6pe\5ue\4oe\3ze\2de\1ie" 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate extern int fp_kind; /* kind of fp support */ 163*0Sstevel@tonic-gate extern int fpu_exists; /* FPU hw exists */ 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate #ifdef _KERNEL 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate extern uint32_t sse_mxcsr_mask; 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate extern void fpu_probe(void); 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate extern void fpnsave_begin(void *); 172*0Sstevel@tonic-gate extern void fpxsave_begin(void *); 173*0Sstevel@tonic-gate extern void (*fpsave_begin)(void *); 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate extern void fpsave(struct fnsave_state *); 176*0Sstevel@tonic-gate extern void fprestore(struct fnsave_state *); 177*0Sstevel@tonic-gate extern void fpxsave(struct fxsave_state *); 178*0Sstevel@tonic-gate extern void fpxrestore(struct fxsave_state *); 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate extern void fpenable(void); 181*0Sstevel@tonic-gate extern void fpdisable(void); 182*0Sstevel@tonic-gate extern void fpinit(void); 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate extern uint32_t fperr_reset(void); 185*0Sstevel@tonic-gate extern uint32_t fpxerr_reset(void); 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate extern uint32_t fpgetcwsw(void); 188*0Sstevel@tonic-gate extern uint32_t fpgetmxcsr(void); 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate struct regs; 191*0Sstevel@tonic-gate extern int fpnoextflt(struct regs *); 192*0Sstevel@tonic-gate extern int fpextovrflt(struct regs *); 193*0Sstevel@tonic-gate extern int fpexterrflt(struct regs *); 194*0Sstevel@tonic-gate extern int fpsimderrflt(struct regs *); 195*0Sstevel@tonic-gate extern void fpsetcw(uint16_t, uint32_t); 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate #endif /* _KERNEL */ 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate #ifdef __cplusplus 200*0Sstevel@tonic-gate } 201*0Sstevel@tonic-gate #endif 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate #endif /* _SYS_FP_H */ 204