1 /* $NetBSD: npx.h,v 1.22 2006/05/02 19:03:24 drochner Exp $ */
4 * Copyright (c) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)npx.h 5.3 (Berkeley) 1/18/91
38 * 287/387 NPX Coprocessor Data Structures and Constants
45 /* Environment information of floating point unit */
47 long en_cw
; /* control word (16bits) */
48 long en_sw
; /* status word (16bits) */
49 long en_tw
; /* tag word (16bits) */
50 long en_fip
; /* floating point instruction pointer */
51 u_short en_fcs
; /* floating code segment selector */
52 u_short en_opcode
; /* opcode last executed (11 bits ) */
53 long en_foo
; /* floating operand offset */
54 long en_fos
; /* floating operand segment selector */
57 /* Contents of each floating point accumulator */
59 #ifdef dontdef /* too unportable */
60 u_long fp_mantlo
; /* mantissa low (31:0) */
61 u_long fp_manthi
; /* mantissa high (63:32) */
62 int fp_exp
:15; /* exponent */
63 int fp_sgn
:1; /* mantissa sign */
69 /* Floating point context */
71 struct env87 sv_env
; /* floating point control/status */
72 struct fpacc87 sv_ac
[8]; /* accumulator contents, 0-7 */
74 u_long sv_ex_sw
; /* status word for last exception (was pad) */
75 u_long sv_ex_tw
; /* tag word for last exception (was pad) */
76 u_char sv_pad
[8 * 2 - 2 * 4]; /* bogus historical padding */
80 /* Environment of FPU/MMX/SSE/SSE2. */
82 /*0*/ uint16_t en_cw
; /* FPU Control Word */
83 uint16_t en_sw
; /* FPU Status Word */
84 uint8_t en_tw
; /* FPU Tag Word (abridged) */
86 uint16_t en_opcode
; /* FPU Opcode */
87 uint32_t en_fip
; /* FPU Instruction Pointer */
88 uint16_t en_fcs
; /* FPU IP selector */
90 /*16*/ uint32_t en_foo
; /* FPU Data pointer */
91 uint16_t en_fos
; /* FPU Data pointer selector */
93 uint32_t en_mxcsr
; /* MXCSR Register State */
97 /* FPU regsters in the extended save format. */
103 /* SSE/SSE2 registers. */
105 uint8_t sse_bytes
[16];
108 /* FPU/MMX/SSE/SSE2 context */
110 struct envxmm sv_env
; /* control/status context */
111 struct fpaccxmm sv_ac
[8]; /* ST/MM regs */
112 struct xmmreg sv_xmmregs
[8]; /* XMM regs */
113 uint8_t sv_rsvd
[16 * 14];
114 /* 512-bytes --- end of hardware portion of save area */
115 uint32_t sv_ex_sw
; /* saved SW from last exception */
116 uint32_t sv_ex_tw
; /* saved TW from last exception */
121 struct savexmm sv_xmm
;
125 * The i387 defaults to Intel extended precision mode and round to nearest,
126 * with all exceptions masked.
128 #define __INITIAL_NPXCW__ 0x037f
129 /* NetBSD uses IEEE double precision. */
130 #define __NetBSD_NPXCW__ 0x127f
131 /* FreeBSD leaves some exceptions unmasked as well. */
132 #define __FreeBSD_NPXCW__ 0x1272
133 /* iBCS2 goes a bit further and leaves the underflow exception unmasked. */
134 #define __iBCS2_NPXCW__ 0x0262
135 /* Linux just uses the default control word. */
136 #define __Linux_NPXCW__ 0x037f
137 /* SVR4 uses the same control word as iBCS2. */
138 #define __SVR4_NPXCW__ 0x0262
141 * The default MXCSR value at reset is 0x1f80, IA-32 Instruction
142 * Set Reference, pg. 3-369.
144 #define __INITIAL_MXCSR__ 0x1f80
148 * 80387 control word bits
150 #define EN_SW_INVOP 0x0001 /* Invalid operation */
151 #define EN_SW_DENORM 0x0002 /* Denormalized operand */
152 #define EN_SW_ZERODIV 0x0004 /* Divide by zero */
153 #define EN_SW_OVERFLOW 0x0008 /* Overflow */
154 #define EN_SW_UNDERFLOW 0x0010 /* Underflow */
155 #define EN_SW_PRECLOSS 0x0020 /* Loss of precision */
156 #define EN_SW_DATACHAIN 0x0080 /* Data chain exception */
157 #define EN_SW_CTL_PREC 0x0300 /* Precision control */
158 #define EN_SW_CTL_ROUND 0x0c00 /* Rounding control */
159 #define EN_SW_CTL_INF 0x1000 /* Infinity control */
162 * The standard control word from finit is 0x37F, giving:
165 * all exceptions masked.
168 * affine mode (if we decide to support 287's)
171 * all exceptions masked.
173 * 64-bit precision often gives bad results with high level languages
174 * because it makes the results of calculations depend on whether
175 * intermediate values are stored in memory or in FPU registers.
177 * The iBCS control word has underflow, overflow, zero divide, and invalid
178 * operation exceptions unmasked. But that causes an unexpected exception
179 * in the test program 'paranoia' and makes denormals useless (DBL_MIN / 2
180 * underflows). It doesn't make a lot of sense to trap underflow without
181 * trapping denormals.
186 void probeintr(void);
187 void probetrap(void);
188 int npx586bug1(int, int);
189 void npxinit(struct cpu_info
*);
190 void process_xmm_to_s87(const struct savexmm
*, struct save87
*);
191 void process_s87_to_xmm(const struct save87
*, struct savexmm
*);
195 #endif /* !_I386_NPX_H_ */