fpu.h revision 215865
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 * 4. Neither the name of the University nor the names of its contributors
174Srgrimes *    may be used to endorse or promote products derived from this software
184Srgrimes *    without specific prior written permission.
194Srgrimes *
204Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
214Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
244Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304Srgrimes * SUCH DAMAGE.
314Srgrimes *
32621Srgrimes *	from: @(#)npx.h	5.3 (Berkeley) 1/18/91
3350477Speter * $FreeBSD: head/sys/amd64/include/fpu.h 215865 2010-11-26 14:50:42Z kib $
344Srgrimes */
354Srgrimes
364Srgrimes/*
37122292Speter * Floating Point Data Structures and Constants
384Srgrimes * W. Jolitz 1/90
394Srgrimes */
404Srgrimes
41122292Speter#ifndef _MACHINE_FPU_H_
42122292Speter#define	_MACHINE_FPU_H_
434Srgrimes
44114349Speter/* Contents of each x87 floating point accumulator */
4583047Sobrienstruct fpacc87 {
464Srgrimes	u_char	fp_bytes[10];
474Srgrimes};
484Srgrimes
49114349Speter/* Contents of each SSE extended accumulator */
50114349Speterstruct  xmmacc {
51114349Speter	u_char	xmm_bytes[16];
524Srgrimes};
534Srgrimes
5479609Speterstruct  envxmm {
5579609Speter	u_int16_t	en_cw;		/* control word (16bits) */
5679609Speter	u_int16_t	en_sw;		/* status word (16bits) */
57114349Speter	u_int8_t	en_tw;		/* tag word (8bits) */
58114349Speter	u_int8_t	en_zero;
5979609Speter	u_int16_t	en_opcode;	/* opcode last executed (11 bits ) */
60114349Speter	u_int64_t	en_rip;		/* floating point instruction pointer */
61114349Speter	u_int64_t	en_rdp;		/* floating operand pointer */
6279609Speter	u_int32_t	en_mxcsr;	/* SSE sontorol/status register */
63114349Speter	u_int32_t	en_mxcsr_mask;	/* valid bits in mxcsr */
6479609Speter};
6579609Speter
66114349Speterstruct  savefpu {
6779609Speter	struct	envxmm	sv_env;
6879609Speter	struct {
6979609Speter		struct fpacc87	fp_acc;
7079609Speter		u_char		fp_pad[6];      /* padding */
7179609Speter	} sv_fp[8];
72114349Speter	struct xmmacc	sv_xmm[16];
73114349Speter	u_char sv_pad[96];
74103834Speter} __aligned(16);
7579609Speter
76208833Skib#ifdef _KERNEL
77208833Skibstruct fpu_kern_ctx {
78208833Skib	struct savefpu hwstate;
79208833Skib	struct savefpu *prev;
80208833Skib	uint32_t flags;
81208833Skib};
82208833Skib#define	FPU_KERN_CTX_FPUINITDONE 0x01
83208833Skib
84208833Skib#define	PCB_USER_FPU(pcb) (((pcb)->pcb_flags & PCB_KERNFPU) == 0)
85208833Skib#endif
86208833Skib
874Srgrimes/*
8857890Scracauer * The hardware default control word for i387's and later coprocessors is
8957890Scracauer * 0x37F, giving:
904Srgrimes *
914Srgrimes *	round to nearest
924Srgrimes *	64-bit precision
934Srgrimes *	all exceptions masked.
944Srgrimes *
95117865Speter * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc
96117865Speter * because of the difference between memory and fpu register stack arguments.
97117865Speter * If its using an intermediate fpu register, it has 80/64 bits to work
98117865Speter * with.  If it uses memory, it has 64/53 bits to work with.  However,
99117865Speter * gcc is aware of this and goes to a fair bit of trouble to make the
100117865Speter * best use of it.
1014Srgrimes *
102117865Speter * This is mostly academic for AMD64, because the ABI prefers the use
103117865Speter * SSE2 based math.  For FreeBSD/amd64, we go with the default settings.
1044Srgrimes */
105122292Speter#define	__INITIAL_FPUCW__	0x037F
106187867Sjhb#define	__INITIAL_FPUCW_I386__	0x127F
107114859Speter#define	__INITIAL_MXCSR__	0x1F80
108114859Speter#define	__INITIAL_MXCSR_MASK__	0xFFBF
1094Srgrimes
11055205Speter#ifdef _KERNEL
111189412Sjhbvoid	fpudna(void);
112122292Spetervoid	fpudrop(void);
113122292Spetervoid	fpuexit(struct thread *td);
114122292Speterint	fpuformat(void);
115215865Skibint	fpugetregs(struct thread *td);
116122295Spetervoid	fpuinit(void);
117122292Spetervoid	fpusetregs(struct thread *td, struct savefpu *addr);
118122292Speterint	fputrap(void);
119215865Skibvoid	fpuuserinited(struct thread *td);
120208833Skibint	fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx,
121208833Skib	    u_int flags);
122208833Skibint	fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx);
123208833Skibint	fpu_kern_thread(u_int flags);
124208833Skibint	is_fpu_kern_thread(u_int flags);
125208833Skib
126208833Skib/*
127208833Skib * Flags for fpu_kern_enter() and fpu_kern_thread().
128208833Skib */
129208833Skib#define	FPU_KERN_NORMAL	0x0000
130208833Skib
1314175Sbde#endif
1324175Sbde
133122292Speter#endif /* !_MACHINE_FPU_H_ */
134