1234353Sdim/*-
2193323Sed * Copyright (c) 1990 The Regents of the University of California.
3193323Sed * All rights reserved.
4193323Sed *
5193323Sed * This code is derived from software contributed to Berkeley by
6193323Sed * William Jolitz.
7193323Sed *
8193323Sed * Redistribution and use in source and binary forms, with or without
9193323Sed * modification, are permitted provided that the following conditions
10193323Sed * are met:
11193323Sed * 1. Redistributions of source code must retain the above copyright
12193323Sed *    notice, this list of conditions and the following disclaimer.
13193323Sed * 2. Redistributions in binary form must reproduce the above copyright
14193323Sed *    notice, this list of conditions and the following disclaimer in the
15193323Sed *    documentation and/or other materials provided with the distribution.
16193323Sed * 4. Neither the name of the University nor the names of its contributors
17193323Sed *    may be used to endorse or promote products derived from this software
18193323Sed *    without specific prior written permission.
19193323Sed *
20193323Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23193323Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26193323Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27193323Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30200581Srdivacky * SUCH DAMAGE.
31200581Srdivacky *
32200581Srdivacky *	from: @(#)npx.h	5.3 (Berkeley) 1/18/91
33193323Sed * $FreeBSD$
34193323Sed */
35193323Sed
36193323Sed/*
37193323Sed * 287/387 NPX Coprocessor Data Structures and Constants
38193323Sed * W. Jolitz 1/90
39198090Srdivacky */
40193323Sed
41193323Sed#ifndef _MACHINE_NPX_H_
42193323Sed#define	_MACHINE_NPX_H_
43193323Sed
44193323Sed#define __aligned(x)    __attribute__((__aligned__(x)))
45193323Sed
46193323Sed/* Environment information of floating point unit */
47193323Sedstruct env87 {
48193323Sed	long	en_cw;		/* control word (16bits) */
49193323Sed	long	en_sw;		/* status word (16bits) */
50200581Srdivacky	long	en_tw;		/* tag word (16bits) */
51193323Sed	long	en_fip;		/* floating point instruction pointer */
52193323Sed	u_short	en_fcs;		/* floating code segment selector */
53193323Sed	u_short	en_opcode;	/* opcode last executed (11 bits ) */
54193323Sed	long	en_foo;		/* floating operand offset */
55193323Sed	long	en_fos;		/* floating operand segment selector */
56193323Sed};
57193323Sed
58193323Sed/* Contents of each floating point accumulator */
59193323Sedstruct fpacc87 {
60200581Srdivacky#ifdef dontdef /* too unportable */
61193323Sed	u_long	fp_mantlo;	/* mantissa low (31:0) */
62200581Srdivacky	u_long	fp_manthi;	/* mantissa high (63:32) */
63200581Srdivacky	int	fp_exp:15;	/* exponent */
64200581Srdivacky	int	fp_sgn:1;	/* mantissa sign */
65200581Srdivacky#else
66193323Sed	u_char	fp_bytes[10];
67193323Sed#endif
68193323Sed};
69193323Sed
70193323Sed/* Floating point context */
71193323Sedstruct save87 {
72193323Sed	struct	env87 sv_env;	/* floating point control/status */
73193323Sed	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
74193323Sed	u_char	sv_pad0[4];	/* padding for (now unused) saved status word */
75193323Sed	/*
76249423Sdim	 * Bogus padding for emulators.  Emulators should use their own
77219077Sdim	 * struct and arrange to store into this struct (ending here)
78193323Sed	 * before it is inspected for ptracing or for core dumps.  Some
79207618Srdivacky	 * emulators overwrite the whole struct.  We have no good way of
80193323Sed	 * knowing how much padding to leave.  Leave just enough for the
81193323Sed	 * GPL emulator's i387_union (176 bytes total).
82193323Sed	 */
83193323Sed	u_char	sv_pad[64];	/* padding; used by emulators */
84193323Sed};
85207618Srdivacky
86207618Srdivackystruct  envxmm {
87207618Srdivacky	uint16	en_cw;		/* control word (16bits) */
88207618Srdivacky	uint16	en_sw;		/* status word (16bits) */
89207618Srdivacky	uint16	en_tw;		/* tag word (16bits) */
90207618Srdivacky	uint16	en_opcode;	/* opcode last executed (11 bits ) */
91207618Srdivacky	uint32	en_fip;		/* floating point instruction pointer */
92207618Srdivacky	uint16	en_fcs;		/* floating code segment selector */
93207618Srdivacky	uint16	en_pad0;	/* padding */
94207618Srdivacky	uint32	en_foo;		/* floating operand offset */
95249423Sdim	uint16	en_fos;		/* floating operand segment selector */
96263508Sdim	uint16	en_pad1;	/* padding */
97207618Srdivacky	uint32	en_mxcsr;	/* SSE control/status register */
98193323Sed	uint32	en_mxcsr_mask;	/* valid bits in mxcsr */
99198090Srdivacky};
100198090Srdivacky
101198090Srdivacky/* Contents of each SSE extended accumulator */
102263508Sdimstruct  xmmacc {
103193323Sed	u_char	xmm_bytes[16];
104202878Srdivacky};
105202878Srdivacky
106202878Srdivackystruct  savexmm {
107226633Sdim	struct	envxmm	sv_env;
108202878Srdivacky	struct {
109202878Srdivacky		struct fpacc87	fp_acc;
110202878Srdivacky		u_char		fp_pad[6];      /* padding */
111202878Srdivacky	} sv_fp[8];
112202878Srdivacky	struct xmmacc	sv_xmm[8];
113202878Srdivacky	u_char sv_pad[224];
114202878Srdivacky} __aligned(16);
115202878Srdivacky
116202878Srdivackyunion	savefpu {
117202878Srdivacky	struct	save87	sv_87;
118226633Sdim	struct	savexmm	sv_xmm;
119202878Srdivacky};
120249423Sdim
121202878Srdivacky/*
122193323Sed * The hardware default control word for i387's and later coprocessors is
123207618Srdivacky * 0x37F, giving:
124200581Srdivacky *
125207618Srdivacky *	round to nearest
126193323Sed *	64-bit precision
127193323Sed *	all exceptions masked.
128198090Srdivacky *
129198090Srdivacky * We modify the affine mode bit and precision bits in this to give:
130198090Srdivacky *
131198090Srdivacky *	affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
132210299Sed *	53-bit precision (2 in bitfield 3<<8)
133198090Srdivacky *
134263508Sdim * 64-bit precision often gives bad results with high level languages
135207618Srdivacky * because it makes the results of calculations depend on whether
136198090Srdivacky * intermediate values are stored in memory or in FPU registers.
137198090Srdivacky */
138198090Srdivacky#define	__INITIAL_NPXCW__	0x127F
139198090Srdivacky#define	__INITIAL_MXCSR__	0x1F80
140198090Srdivacky
141263508Sdim#ifdef _KERNEL
142198090Srdivacky
143207618Srdivacky#define	IO_NPX		0x0F0		/* Numeric Coprocessor */
144198090Srdivacky#define	IO_NPXSIZE	16		/* 80387/80487 NPX registers */
145198090Srdivacky
146198090Srdivacky#define	IRQ_NPX		13
147198090Srdivacky
148263508Sdim/* full reset on some systems, NOP on others */
149207618Srdivacky#define npx_full_reset() outb(IO_NPX + 1, 0)
150198090Srdivacky
151198090Srdivackyint	npxdna(void);
152198090Srdivackyvoid	npxdrop(void);
153198090Srdivackyvoid	npxexit(struct thread *td);
154198090Srdivackyint	npxformat(void);
155263508Sdimint	npxgetregs(struct thread *td, union savefpu *addr);
156207618Srdivackyvoid	npxinit(void);
157198090Srdivackyvoid	npxsave(union savefpu *addr);
158239462Sdimvoid	npxsetregs(struct thread *td, union savefpu *addr);
159207618Srdivackyint	npxtrap(void);
160198090Srdivacky
161198090Srdivacky#endif
162198090Srdivacky
163198090Srdivacky#endif /* !_MACHINE_NPX_H_ */
164198090Srdivacky