fpu.h revision 189412
152400Sbillf/*-
252400Sbillf * Copyright (c) 1990 The Regents of the University of California.
352400Sbillf * All rights reserved.
452400Sbillf *
552400Sbillf * This code is derived from software contributed to Berkeley by
652400Sbillf * William Jolitz.
752400Sbillf *
890564Sdougb * Redistribution and use in source and binary forms, with or without
973651Sdougb * modification, are permitted provided that the following conditions
1052400Sbillf * are met:
1152495Sbillf * 1. Redistributions of source code must retain the above copyright
1252400Sbillf *    notice, this list of conditions and the following disclaimer.
1368507Sdougb * 2. Redistributions in binary form must reproduce the above copyright
1452400Sbillf *    notice, this list of conditions and the following disclaimer in the
1552400Sbillf *    documentation and/or other materials provided with the distribution.
1652533Sbillf * 4. Neither the name of the University nor the names of its contributors
1752400Sbillf *    may be used to endorse or promote products derived from this software
1891193Sdougb *    without specific prior written permission.
1967949Sdougb *
2052400Sbillf * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2152400Sbillf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2252400Sbillf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2352400Sbillf * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2452400Sbillf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2552400Sbillf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2652400Sbillf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2767949Sdougb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2891193Sdougb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2991193Sdougb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3052400Sbillf * SUCH DAMAGE.
3152400Sbillf *
3252400Sbillf *	from: @(#)npx.h	5.3 (Berkeley) 1/18/91
3352400Sbillf * $FreeBSD: head/sys/amd64/include/fpu.h 189412 2009-03-05 16:56:16Z jhb $
3452400Sbillf */
3567949Sdougb
3652400Sbillf/*
3752400Sbillf * Floating Point Data Structures and Constants
3852400Sbillf * W. Jolitz 1/90
3952400Sbillf */
4052400Sbillf
4152400Sbillf#ifndef _MACHINE_FPU_H_
4252400Sbillf#define	_MACHINE_FPU_H_
4367859Sdougb
4467949Sdougb/* Contents of each x87 floating point accumulator */
4552400Sbillfstruct fpacc87 {
4652400Sbillf	u_char	fp_bytes[10];
4758910Salfred};
4858910Salfred
4958910Salfred/* Contents of each SSE extended accumulator */
5067850Sdougbstruct  xmmacc {
5167850Sdougb	u_char	xmm_bytes[16];
5267850Sdougb};
5367850Sdougb
5467850Sdougbstruct  envxmm {
5567850Sdougb	u_int16_t	en_cw;		/* control word (16bits) */
5667850Sdougb	u_int16_t	en_sw;		/* status word (16bits) */
5767850Sdougb	u_int8_t	en_tw;		/* tag word (8bits) */
5867850Sdougb	u_int8_t	en_zero;
5967850Sdougb	u_int16_t	en_opcode;	/* opcode last executed (11 bits ) */
6067850Sdougb	u_int64_t	en_rip;		/* floating point instruction pointer */
6167850Sdougb	u_int64_t	en_rdp;		/* floating operand pointer */
6267949Sdougb	u_int32_t	en_mxcsr;	/* SSE sontorol/status register */
6367850Sdougb	u_int32_t	en_mxcsr_mask;	/* valid bits in mxcsr */
6467850Sdougb};
6567850Sdougb
6667850Sdougbstruct  savefpu {
6767850Sdougb	struct	envxmm	sv_env;
6867850Sdougb	struct {
6967850Sdougb		struct fpacc87	fp_acc;
7067850Sdougb		u_char		fp_pad[6];      /* padding */
7167859Sdougb	} sv_fp[8];
7267859Sdougb	struct xmmacc	sv_xmm[16];
7358910Salfred	u_char sv_pad[96];
7467850Sdougb} __aligned(16);
7567850Sdougb
7667850Sdougb/*
7767850Sdougb * The hardware default control word for i387's and later coprocessors is
7867850Sdougb * 0x37F, giving:
7967850Sdougb *
8067859Sdougb *	round to nearest
8167850Sdougb *	64-bit precision
8267859Sdougb *	all exceptions masked.
8367850Sdougb *
8467850Sdougb * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc
8567850Sdougb * because of the difference between memory and fpu register stack arguments.
8667850Sdougb * If its using an intermediate fpu register, it has 80/64 bits to work
8767859Sdougb * with.  If it uses memory, it has 64/53 bits to work with.  However,
8867850Sdougb * gcc is aware of this and goes to a fair bit of trouble to make the
8967850Sdougb * best use of it.
9067850Sdougb *
9167850Sdougb * This is mostly academic for AMD64, because the ABI prefers the use
9267850Sdougb * SSE2 based math.  For FreeBSD/amd64, we go with the default settings.
9367850Sdougb */
9467850Sdougb#define	__INITIAL_FPUCW__	0x037F
9567850Sdougb#define	__INITIAL_FPUCW_I386__	0x127F
9667850Sdougb#define	__INITIAL_MXCSR__	0x1F80
9767850Sdougb#define	__INITIAL_MXCSR_MASK__	0xFFBF
9867850Sdougb
9967850Sdougb#ifdef _KERNEL
10067850Sdougbvoid	fpudna(void);
10167850Sdougbvoid	fpudrop(void);
10258910Salfredvoid	fpuexit(struct thread *td);
10358910Salfredint	fpuformat(void);
10458910Salfredint	fpugetregs(struct thread *td, struct savefpu *addr);
10558910Salfredvoid	fpuinit(void);
10658910Salfredvoid	fpusetregs(struct thread *td, struct savefpu *addr);
10758910Salfredint	fputrap(void);
10867850Sdougb#endif
10958910Salfred
11077323Sdougb#endif /* !_MACHINE_FPU_H_ */
11177323Sdougb