1*38ecc1a7SArtur Wyszynski /*- 2*38ecc1a7SArtur Wyszynski * Copyright (c) 1990 The Regents of the University of California. 3*38ecc1a7SArtur Wyszynski * All rights reserved. 4*38ecc1a7SArtur Wyszynski * 5*38ecc1a7SArtur Wyszynski * This code is derived from software contributed to Berkeley by 6*38ecc1a7SArtur Wyszynski * William Jolitz. 7*38ecc1a7SArtur Wyszynski * 8*38ecc1a7SArtur Wyszynski * Redistribution and use in source and binary forms, with or without 9*38ecc1a7SArtur Wyszynski * modification, are permitted provided that the following conditions 10*38ecc1a7SArtur Wyszynski * are met: 11*38ecc1a7SArtur Wyszynski * 1. Redistributions of source code must retain the above copyright 12*38ecc1a7SArtur Wyszynski * notice, this list of conditions and the following disclaimer. 13*38ecc1a7SArtur Wyszynski * 2. Redistributions in binary form must reproduce the above copyright 14*38ecc1a7SArtur Wyszynski * notice, this list of conditions and the following disclaimer in the 15*38ecc1a7SArtur Wyszynski * documentation and/or other materials provided with the distribution. 16*38ecc1a7SArtur Wyszynski * 4. Neither the name of the University nor the names of its contributors 17*38ecc1a7SArtur Wyszynski * may be used to endorse or promote products derived from this software 18*38ecc1a7SArtur Wyszynski * without specific prior written permission. 19*38ecc1a7SArtur Wyszynski * 20*38ecc1a7SArtur Wyszynski * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21*38ecc1a7SArtur Wyszynski * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22*38ecc1a7SArtur Wyszynski * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23*38ecc1a7SArtur Wyszynski * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24*38ecc1a7SArtur Wyszynski * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25*38ecc1a7SArtur Wyszynski * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26*38ecc1a7SArtur Wyszynski * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27*38ecc1a7SArtur Wyszynski * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28*38ecc1a7SArtur Wyszynski * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29*38ecc1a7SArtur Wyszynski * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30*38ecc1a7SArtur Wyszynski * SUCH DAMAGE. 31*38ecc1a7SArtur Wyszynski * 32*38ecc1a7SArtur Wyszynski * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 33*38ecc1a7SArtur Wyszynski * $FreeBSD$ 34*38ecc1a7SArtur Wyszynski */ 35*38ecc1a7SArtur Wyszynski 36*38ecc1a7SArtur Wyszynski /* 37*38ecc1a7SArtur Wyszynski * 287/387 NPX Coprocessor Data Structures and Constants 38*38ecc1a7SArtur Wyszynski * W. Jolitz 1/90 39*38ecc1a7SArtur Wyszynski */ 40*38ecc1a7SArtur Wyszynski 41*38ecc1a7SArtur Wyszynski #ifndef _MACHINE_NPX_H_ 42*38ecc1a7SArtur Wyszynski #define _MACHINE_NPX_H_ 43*38ecc1a7SArtur Wyszynski 44*38ecc1a7SArtur Wyszynski #define __aligned(x) __attribute__((__aligned__(x))) 45*38ecc1a7SArtur Wyszynski 46*38ecc1a7SArtur Wyszynski /* Environment information of floating point unit */ 47*38ecc1a7SArtur Wyszynski struct env87 { 48*38ecc1a7SArtur Wyszynski long en_cw; /* control word (16bits) */ 49*38ecc1a7SArtur Wyszynski long en_sw; /* status word (16bits) */ 50*38ecc1a7SArtur Wyszynski long en_tw; /* tag word (16bits) */ 51*38ecc1a7SArtur Wyszynski long en_fip; /* floating point instruction pointer */ 52*38ecc1a7SArtur Wyszynski u_short en_fcs; /* floating code segment selector */ 53*38ecc1a7SArtur Wyszynski u_short en_opcode; /* opcode last executed (11 bits ) */ 54*38ecc1a7SArtur Wyszynski long en_foo; /* floating operand offset */ 55*38ecc1a7SArtur Wyszynski long en_fos; /* floating operand segment selector */ 56*38ecc1a7SArtur Wyszynski }; 57*38ecc1a7SArtur Wyszynski 58*38ecc1a7SArtur Wyszynski /* Contents of each floating point accumulator */ 59*38ecc1a7SArtur Wyszynski struct fpacc87 { 60*38ecc1a7SArtur Wyszynski #ifdef dontdef /* too unportable */ 61*38ecc1a7SArtur Wyszynski u_long fp_mantlo; /* mantissa low (31:0) */ 62*38ecc1a7SArtur Wyszynski u_long fp_manthi; /* mantissa high (63:32) */ 63*38ecc1a7SArtur Wyszynski int fp_exp:15; /* exponent */ 64*38ecc1a7SArtur Wyszynski int fp_sgn:1; /* mantissa sign */ 65*38ecc1a7SArtur Wyszynski #else 66*38ecc1a7SArtur Wyszynski u_char fp_bytes[10]; 67*38ecc1a7SArtur Wyszynski #endif 68*38ecc1a7SArtur Wyszynski }; 69*38ecc1a7SArtur Wyszynski 70*38ecc1a7SArtur Wyszynski /* Floating point context */ 71*38ecc1a7SArtur Wyszynski struct save87 { 72*38ecc1a7SArtur Wyszynski struct env87 sv_env; /* floating point control/status */ 73*38ecc1a7SArtur Wyszynski struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ 74*38ecc1a7SArtur Wyszynski u_char sv_pad0[4]; /* padding for (now unused) saved status word */ 75*38ecc1a7SArtur Wyszynski /* 76*38ecc1a7SArtur Wyszynski * Bogus padding for emulators. Emulators should use their own 77*38ecc1a7SArtur Wyszynski * struct and arrange to store into this struct (ending here) 78*38ecc1a7SArtur Wyszynski * before it is inspected for ptracing or for core dumps. Some 79*38ecc1a7SArtur Wyszynski * emulators overwrite the whole struct. We have no good way of 80*38ecc1a7SArtur Wyszynski * knowing how much padding to leave. Leave just enough for the 81*38ecc1a7SArtur Wyszynski * GPL emulator's i387_union (176 bytes total). 82*38ecc1a7SArtur Wyszynski */ 83*38ecc1a7SArtur Wyszynski u_char sv_pad[64]; /* padding; used by emulators */ 84*38ecc1a7SArtur Wyszynski }; 85*38ecc1a7SArtur Wyszynski 86*38ecc1a7SArtur Wyszynski struct envxmm { 87*38ecc1a7SArtur Wyszynski uint16 en_cw; /* control word (16bits) */ 88*38ecc1a7SArtur Wyszynski uint16 en_sw; /* status word (16bits) */ 89*38ecc1a7SArtur Wyszynski uint16 en_tw; /* tag word (16bits) */ 90*38ecc1a7SArtur Wyszynski uint16 en_opcode; /* opcode last executed (11 bits ) */ 91*38ecc1a7SArtur Wyszynski uint32 en_fip; /* floating point instruction pointer */ 92*38ecc1a7SArtur Wyszynski uint16 en_fcs; /* floating code segment selector */ 93*38ecc1a7SArtur Wyszynski uint16 en_pad0; /* padding */ 94*38ecc1a7SArtur Wyszynski uint32 en_foo; /* floating operand offset */ 95*38ecc1a7SArtur Wyszynski uint16 en_fos; /* floating operand segment selector */ 96*38ecc1a7SArtur Wyszynski uint16 en_pad1; /* padding */ 97*38ecc1a7SArtur Wyszynski uint32 en_mxcsr; /* SSE control/status register */ 98*38ecc1a7SArtur Wyszynski uint32 en_mxcsr_mask; /* valid bits in mxcsr */ 99*38ecc1a7SArtur Wyszynski }; 100*38ecc1a7SArtur Wyszynski 101*38ecc1a7SArtur Wyszynski /* Contents of each SSE extended accumulator */ 102*38ecc1a7SArtur Wyszynski struct xmmacc { 103*38ecc1a7SArtur Wyszynski u_char xmm_bytes[16]; 104*38ecc1a7SArtur Wyszynski }; 105*38ecc1a7SArtur Wyszynski 106*38ecc1a7SArtur Wyszynski struct savexmm { 107*38ecc1a7SArtur Wyszynski struct envxmm sv_env; 108*38ecc1a7SArtur Wyszynski struct { 109*38ecc1a7SArtur Wyszynski struct fpacc87 fp_acc; 110*38ecc1a7SArtur Wyszynski u_char fp_pad[6]; /* padding */ 111*38ecc1a7SArtur Wyszynski } sv_fp[8]; 112*38ecc1a7SArtur Wyszynski struct xmmacc sv_xmm[8]; 113*38ecc1a7SArtur Wyszynski u_char sv_pad[224]; 114*38ecc1a7SArtur Wyszynski } __aligned(16); 115*38ecc1a7SArtur Wyszynski 116*38ecc1a7SArtur Wyszynski union savefpu { 117*38ecc1a7SArtur Wyszynski struct save87 sv_87; 118*38ecc1a7SArtur Wyszynski struct savexmm sv_xmm; 119*38ecc1a7SArtur Wyszynski }; 120*38ecc1a7SArtur Wyszynski 121*38ecc1a7SArtur Wyszynski /* 122*38ecc1a7SArtur Wyszynski * The hardware default control word for i387's and later coprocessors is 123*38ecc1a7SArtur Wyszynski * 0x37F, giving: 124*38ecc1a7SArtur Wyszynski * 125*38ecc1a7SArtur Wyszynski * round to nearest 126*38ecc1a7SArtur Wyszynski * 64-bit precision 127*38ecc1a7SArtur Wyszynski * all exceptions masked. 128*38ecc1a7SArtur Wyszynski * 129*38ecc1a7SArtur Wyszynski * We modify the affine mode bit and precision bits in this to give: 130*38ecc1a7SArtur Wyszynski * 131*38ecc1a7SArtur Wyszynski * affine mode for 287's (if they work at all) (1 in bitfield 1<<12) 132*38ecc1a7SArtur Wyszynski * 53-bit precision (2 in bitfield 3<<8) 133*38ecc1a7SArtur Wyszynski * 134*38ecc1a7SArtur Wyszynski * 64-bit precision often gives bad results with high level languages 135*38ecc1a7SArtur Wyszynski * because it makes the results of calculations depend on whether 136*38ecc1a7SArtur Wyszynski * intermediate values are stored in memory or in FPU registers. 137*38ecc1a7SArtur Wyszynski */ 138*38ecc1a7SArtur Wyszynski #define __INITIAL_NPXCW__ 0x127F 139*38ecc1a7SArtur Wyszynski #define __INITIAL_MXCSR__ 0x1F80 140*38ecc1a7SArtur Wyszynski 141*38ecc1a7SArtur Wyszynski #ifdef _KERNEL 142*38ecc1a7SArtur Wyszynski 143*38ecc1a7SArtur Wyszynski #define IO_NPX 0x0F0 /* Numeric Coprocessor */ 144*38ecc1a7SArtur Wyszynski #define IO_NPXSIZE 16 /* 80387/80487 NPX registers */ 145*38ecc1a7SArtur Wyszynski 146*38ecc1a7SArtur Wyszynski #define IRQ_NPX 13 147*38ecc1a7SArtur Wyszynski 148*38ecc1a7SArtur Wyszynski /* full reset on some systems, NOP on others */ 149*38ecc1a7SArtur Wyszynski #define npx_full_reset() outb(IO_NPX + 1, 0) 150*38ecc1a7SArtur Wyszynski 151*38ecc1a7SArtur Wyszynski int npxdna(void); 152*38ecc1a7SArtur Wyszynski void npxdrop(void); 153*38ecc1a7SArtur Wyszynski void npxexit(struct thread *td); 154*38ecc1a7SArtur Wyszynski int npxformat(void); 155*38ecc1a7SArtur Wyszynski int npxgetregs(struct thread *td, union savefpu *addr); 156*38ecc1a7SArtur Wyszynski void npxinit(void); 157*38ecc1a7SArtur Wyszynski void npxsave(union savefpu *addr); 158*38ecc1a7SArtur Wyszynski void npxsetregs(struct thread *td, union savefpu *addr); 159*38ecc1a7SArtur Wyszynski int npxtrap(void); 160*38ecc1a7SArtur Wyszynski 161*38ecc1a7SArtur Wyszynski #endif 162*38ecc1a7SArtur Wyszynski 163*38ecc1a7SArtur Wyszynski #endif /* !_MACHINE_NPX_H_ */ 164