fpu.h revision 57890
14Srgrimes/*- 24Srgrimes * Copyright (c) 1990 The Regents of the University of California. 34Srgrimes * All rights reserved. 44Srgrimes * 54Srgrimes * This code is derived from software contributed to Berkeley by 64Srgrimes * William Jolitz. 74Srgrimes * 84Srgrimes * Redistribution and use in source and binary forms, with or without 94Srgrimes * modification, are permitted provided that the following conditions 104Srgrimes * are met: 114Srgrimes * 1. Redistributions of source code must retain the above copyright 124Srgrimes * notice, this list of conditions and the following disclaimer. 134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 144Srgrimes * notice, this list of conditions and the following disclaimer in the 154Srgrimes * documentation and/or other materials provided with the distribution. 164Srgrimes * 3. All advertising materials mentioning features or use of this software 174Srgrimes * must display the following acknowledgement: 184Srgrimes * This product includes software developed by the University of 194Srgrimes * California, Berkeley and its contributors. 204Srgrimes * 4. Neither the name of the University nor the names of its contributors 214Srgrimes * may be used to endorse or promote products derived from this software 224Srgrimes * without specific prior written permission. 234Srgrimes * 244Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 254Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 264Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 274Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 284Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 294Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 304Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 314Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 324Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 334Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 344Srgrimes * SUCH DAMAGE. 354Srgrimes * 36621Srgrimes * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 3750477Speter * $FreeBSD: head/sys/amd64/include/fpu.h 57890 2000-03-10 17:56:33Z cracauer $ 384Srgrimes */ 394Srgrimes 404Srgrimes/* 414Srgrimes * 287/387 NPX Coprocessor Data Structures and Constants 424Srgrimes * W. Jolitz 1/90 434Srgrimes */ 444Srgrimes 454175Sbde#ifndef _MACHINE_NPX_H_ 464175Sbde#define _MACHINE_NPX_H_ 474Srgrimes 4846129Sluoqi#include <machine/globals.h> 4946129Sluoqi 504Srgrimes/* Environment information of floating point unit */ 514Srgrimesstruct env87 { 524Srgrimes long en_cw; /* control word (16bits) */ 534Srgrimes long en_sw; /* status word (16bits) */ 544Srgrimes long en_tw; /* tag word (16bits) */ 554Srgrimes long en_fip; /* floating point instruction pointer */ 564Srgrimes u_short en_fcs; /* floating code segment selector */ 574Srgrimes u_short en_opcode; /* opcode last executed (11 bits ) */ 584Srgrimes long en_foo; /* floating operand offset */ 594Srgrimes long en_fos; /* floating operand segment selector */ 604Srgrimes}; 614Srgrimes 624Srgrimes/* Contents of each floating point accumulator */ 634Srgrimesstruct fpacc87 { 644Srgrimes#ifdef dontdef /* too unportable */ 654Srgrimes u_long fp_mantlo; /* mantissa low (31:0) */ 664Srgrimes u_long fp_manthi; /* mantissa high (63:32) */ 674Srgrimes int fp_exp:15; /* exponent */ 684Srgrimes int fp_sgn:1; /* mantissa sign */ 694Srgrimes#else 704Srgrimes u_char fp_bytes[10]; 714Srgrimes#endif 724Srgrimes}; 734Srgrimes 744Srgrimes/* Floating point context */ 754Srgrimesstruct save87 { 765350Sbde struct env87 sv_env; /* floating point control/status */ 774Srgrimes struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ 785350Sbde u_long sv_ex_sw; /* status word for last exception */ 795350Sbde /* 805350Sbde * Bogus padding for emulators. Emulators should use their own 815350Sbde * struct and arrange to store into this struct (ending here) 825350Sbde * before it is inspected for ptracing or for core dumps. Some 835350Sbde * emulators overwrite the whole struct. We have no good way of 845350Sbde * knowing how much padding to leave. Leave just enough for the 855350Sbde * GPL emulator's i387_union (176 bytes total). 865350Sbde */ 875350Sbde u_char sv_pad[64]; /* padding; used by emulators */ 884Srgrimes}; 894Srgrimes 904Srgrimes/* 9157890Scracauer * The hardware default control word for i387's and later coprocessors is 9257890Scracauer * 0x37F, giving: 934Srgrimes * 944Srgrimes * round to nearest 954Srgrimes * 64-bit precision 964Srgrimes * all exceptions masked. 974Srgrimes * 9857890Scracauer * We modify the affine mode bit and precision bits in this to give: 994Srgrimes * 1004Srgrimes * affine mode for 287's (if they work at all) (1 in bitfield 1<<12) 1014Srgrimes * 53-bit precision (2 in bitfield 3<<8) 1024Srgrimes * 1034Srgrimes * 64-bit precision often gives bad results with high level languages 1044Srgrimes * because it makes the results of calculations depend on whether 1054Srgrimes * intermediate values are stored in memory or in FPU registers. 1064Srgrimes */ 10757890Scracauer#define __INITIAL_NPXCW__ 0x127F 1084Srgrimes 10955205Speter#ifdef _KERNEL 11046129Sluoqi#ifndef npxproc 11126812Speterextern struct proc *npxproc; 11246129Sluoqi#endif 11326812Speter 1144175Sbdeint npxdna __P((void)); 1154175Sbdevoid npxexit __P((struct proc *p)); 1165350Sbdevoid npxinit __P((int control)); 1174175Sbdevoid npxsave __P((struct save87 *addr)); 1184175Sbde#endif 1194175Sbde 1204175Sbde#endif /* !_MACHINE_NPX_H_ */ 121