npx.h revision 5350
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
375350Sbde *	$Id: npx.h,v 1.6 1994/11/05 22:59:09 bde Exp $
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
484Srgrimes/* Environment information of floating point unit */
494Srgrimesstruct	env87 {
504Srgrimes	long	en_cw;		/* control word (16bits) */
514Srgrimes	long	en_sw;		/* status word (16bits) */
524Srgrimes	long	en_tw;		/* tag word (16bits) */
534Srgrimes	long	en_fip;		/* floating point instruction pointer */
544Srgrimes	u_short	en_fcs;		/* floating code segment selector */
554Srgrimes	u_short	en_opcode;	/* opcode last executed (11 bits ) */
564Srgrimes	long	en_foo;		/* floating operand offset */
574Srgrimes	long	en_fos;		/* floating operand segment selector */
584Srgrimes};
594Srgrimes
604Srgrimes/* Contents of each floating point accumulator */
614Srgrimesstruct	fpacc87 {
624Srgrimes#ifdef dontdef /* too unportable */
634Srgrimes	u_long	fp_mantlo;	/* mantissa low (31:0) */
644Srgrimes	u_long	fp_manthi;	/* mantissa high (63:32) */
654Srgrimes	int	fp_exp:15;	/* exponent */
664Srgrimes	int	fp_sgn:1;	/* mantissa sign */
674Srgrimes#else
684Srgrimes	u_char	fp_bytes[10];
694Srgrimes#endif
704Srgrimes};
714Srgrimes
724Srgrimes/* Floating point context */
734Srgrimesstruct	save87 {
745350Sbde	struct	env87 sv_env;	/* floating point control/status */
754Srgrimes	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
765350Sbde	u_long	sv_ex_sw;	/* status word for last exception */
775350Sbde	/*
785350Sbde	 * Bogus padding for emulators.  Emulators should use their own
795350Sbde	 * struct and arrange to store into this struct (ending here)
805350Sbde	 * before it is inspected for ptracing or for core dumps.  Some
815350Sbde	 * emulators overwrite the whole struct.  We have no good way of
825350Sbde	 * knowing how much padding to leave.  Leave just enough for the
835350Sbde	 * GPL emulator's i387_union (176 bytes total).
845350Sbde	 */
855350Sbde	u_char	sv_pad[64];	/* padding; used by emulators */
864Srgrimes};
874Srgrimes
884Srgrimes/* Cyrix EMC memory - mapped coprocessor context switch information */
894Srgrimesstruct	emcsts {
904Srgrimes	long	em_msw;		/* memory mapped status register when swtched */
914Srgrimes	long	em_tar;		/* memory mapped temp A register when swtched */
924Srgrimes	long	em_dl;		/* memory mapped D low register when swtched */
934Srgrimes};
944Srgrimes
954Srgrimes/* Intel prefers long real (53 bit) precision */
964Srgrimes#define	__iBCS_NPXCW__		0x262
974Srgrimes/* wfj prefers temporary real (64 bit) precision */
984Srgrimes#define	__386BSD_NPXCW__	0x362
994Srgrimes/*
1004Srgrimes * bde prefers 53 bit precision and all exceptions masked.
1014Srgrimes *
1024Srgrimes * The standard control word from finit is 0x37F, giving:
1034Srgrimes *
1044Srgrimes *	round to nearest
1054Srgrimes *	64-bit precision
1064Srgrimes *	all exceptions masked.
1074Srgrimes *
1084Srgrimes * Now I want:
1094Srgrimes *
1104Srgrimes *	affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
1114Srgrimes *	53-bit precision (2 in bitfield 3<<8)
1124Srgrimes *	overflow exception unmasked (0 in bitfield 1<<3)
1134Srgrimes *	zero divide exception unmasked (0 in bitfield 1<<2)
1144Srgrimes *	invalid-operand exception unmasked (0 in bitfield 1<<0).
1154Srgrimes *
1164Srgrimes * 64-bit precision often gives bad results with high level languages
1174Srgrimes * because it makes the results of calculations depend on whether
1184Srgrimes * intermediate values are stored in memory or in FPU registers.
1194Srgrimes *
1204Srgrimes * The "Intel" and wfj control words have:
1214Srgrimes *
1224Srgrimes *	underflow exception unmasked (0 in bitfield 1<<4)
1234Srgrimes *
1244Srgrimes * but that causes an unexpected exception in the test program 'paranoia'
1254Srgrimes * and makes denormals useless (DBL_MIN / 2 underflows).  It doesn't make
1264Srgrimes * a lot of sense to trap underflow without trapping denormals.
1274Srgrimes *
1284Srgrimes * Later I will want the IEEE default of all exceptions masked.  See the
1294Srgrimes * 0.0 math manpage for why this is better.  The 0.1 math manpage is empty.
1304Srgrimes */
1314Srgrimes#define	__BDE_NPXCW__		0x1272
1324Srgrimes#define	__BETTER_BDE_NPXCW__	0x127f
1334Srgrimes
1344Srgrimes#ifdef __BROKEN_NPXCW__
1354131Sjkh#ifdef __FreeBSD__
1364Srgrimes#define	__INITIAL_NPXCW__	__386BSD_NPXCW__
1374Srgrimes#else
1384Srgrimes#define	__INITIAL_NPXCW__	__iBCS_NPXCW__
1394Srgrimes#endif
1404Srgrimes#else
1414Srgrimes#define	__INITIAL_NPXCW__	__BDE_NPXCW__
1424Srgrimes#endif
1434Srgrimes
1444175Sbde#ifdef KERNEL
1454175Sbde#include <sys/cdefs.h>
1464175Sbde#include <machine/frame.h>
1474175Sbde
1484175Sbdestruct proc;
1494175Sbde
1504175Sbdeint	npxdna __P((void));
1514175Sbdevoid	npxexit __P((struct proc *p));
1525350Sbdevoid	npxinit __P((int control));
1534175Sbdevoid	npxintr __P((struct intrframe frame));
1544175Sbdevoid	npxsave __P((struct save87 *addr));
1554175Sbde#endif
1564175Sbde
1574175Sbde#endif /* !_MACHINE_NPX_H_ */
158