15b81b6b3SRodney W. Grimes /*- 25b81b6b3SRodney W. Grimes * Copyright (c) 1990 The Regents of the University of California. 35b81b6b3SRodney W. Grimes * All rights reserved. 45b81b6b3SRodney W. Grimes * 55b81b6b3SRodney W. Grimes * This code is derived from software contributed to Berkeley by 65b81b6b3SRodney W. Grimes * William Jolitz. 75b81b6b3SRodney W. Grimes * 85b81b6b3SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 95b81b6b3SRodney W. Grimes * modification, are permitted provided that the following conditions 105b81b6b3SRodney W. Grimes * are met: 115b81b6b3SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 125b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 135b81b6b3SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 145b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 155b81b6b3SRodney W. Grimes * documentation and/or other materials provided with the distribution. 165b81b6b3SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 175b81b6b3SRodney W. Grimes * must display the following acknowledgement: 185b81b6b3SRodney W. Grimes * This product includes software developed by the University of 195b81b6b3SRodney W. Grimes * California, Berkeley and its contributors. 205b81b6b3SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 215b81b6b3SRodney W. Grimes * may be used to endorse or promote products derived from this software 225b81b6b3SRodney W. Grimes * without specific prior written permission. 235b81b6b3SRodney W. Grimes * 245b81b6b3SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 255b81b6b3SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 265b81b6b3SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 275b81b6b3SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 285b81b6b3SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 295b81b6b3SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 305b81b6b3SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 315b81b6b3SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 325b81b6b3SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 335b81b6b3SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 345b81b6b3SRodney W. Grimes * SUCH DAMAGE. 355b81b6b3SRodney W. Grimes * 3634a8ed1bSRodney W. Grimes * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 37c3aac50fSPeter Wemm * $FreeBSD$ 385b81b6b3SRodney W. Grimes */ 395b81b6b3SRodney W. Grimes 405b81b6b3SRodney W. Grimes /* 41bf2f09eeSPeter Wemm * Floating Point Data Structures and Constants 425b81b6b3SRodney W. Grimes * W. Jolitz 1/90 435b81b6b3SRodney W. Grimes */ 445b81b6b3SRodney W. Grimes 45bf2f09eeSPeter Wemm #ifndef _MACHINE_FPU_H_ 46bf2f09eeSPeter Wemm #define _MACHINE_FPU_H_ 475b81b6b3SRodney W. Grimes 48afa88623SPeter Wemm /* Contents of each x87 floating point accumulator */ 495b81b6b3SRodney W. Grimes struct fpacc87 { 505b81b6b3SRodney W. Grimes u_char fp_bytes[10]; 519d146ac5SPeter Wemm }; 529d146ac5SPeter Wemm 539d146ac5SPeter Wemm /* Contents of each SSE extended accumulator */ 549d146ac5SPeter Wemm struct xmmacc { 559d146ac5SPeter Wemm u_char xmm_bytes[16]; 569d146ac5SPeter Wemm }; 579d146ac5SPeter Wemm 58afa88623SPeter Wemm struct envxmm { 59afa88623SPeter Wemm u_int16_t en_cw; /* control word (16bits) */ 60afa88623SPeter Wemm u_int16_t en_sw; /* status word (16bits) */ 61afa88623SPeter Wemm u_int8_t en_tw; /* tag word (8bits) */ 62afa88623SPeter Wemm u_int8_t en_zero; 63afa88623SPeter Wemm u_int16_t en_opcode; /* opcode last executed (11 bits ) */ 64afa88623SPeter Wemm u_int64_t en_rip; /* floating point instruction pointer */ 65afa88623SPeter Wemm u_int64_t en_rdp; /* floating operand pointer */ 66afa88623SPeter Wemm u_int32_t en_mxcsr; /* SSE sontorol/status register */ 67afa88623SPeter Wemm u_int32_t en_mxcsr_mask; /* valid bits in mxcsr */ 68afa88623SPeter Wemm }; 69afa88623SPeter Wemm 70afa88623SPeter Wemm struct savefpu { 719d146ac5SPeter Wemm struct envxmm sv_env; 729d146ac5SPeter Wemm struct { 739d146ac5SPeter Wemm struct fpacc87 fp_acc; 749d146ac5SPeter Wemm u_char fp_pad[6]; /* padding */ 759d146ac5SPeter Wemm } sv_fp[8]; 76afa88623SPeter Wemm struct xmmacc sv_xmm[16]; 77afa88623SPeter Wemm u_char sv_pad[96]; 78c692fbe0SPeter Wemm } __aligned(16); 799d146ac5SPeter Wemm 805b81b6b3SRodney W. Grimes /* 810c14a660SMartin Cracauer * The hardware default control word for i387's and later coprocessors is 820c14a660SMartin Cracauer * 0x37F, giving: 835b81b6b3SRodney W. Grimes * 845b81b6b3SRodney W. Grimes * round to nearest 855b81b6b3SRodney W. Grimes * 64-bit precision 865b81b6b3SRodney W. Grimes * all exceptions masked. 875b81b6b3SRodney W. Grimes * 885b9f8ddbSPeter Wemm * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc 895b9f8ddbSPeter Wemm * because of the difference between memory and fpu register stack arguments. 905b9f8ddbSPeter Wemm * If its using an intermediate fpu register, it has 80/64 bits to work 915b9f8ddbSPeter Wemm * with. If it uses memory, it has 64/53 bits to work with. However, 925b9f8ddbSPeter Wemm * gcc is aware of this and goes to a fair bit of trouble to make the 935b9f8ddbSPeter Wemm * best use of it. 945b81b6b3SRodney W. Grimes * 955b9f8ddbSPeter Wemm * This is mostly academic for AMD64, because the ABI prefers the use 965b9f8ddbSPeter Wemm * SSE2 based math. For FreeBSD/amd64, we go with the default settings. 975b81b6b3SRodney W. Grimes */ 98bf2f09eeSPeter Wemm #define __INITIAL_FPUCW__ 0x037F 99395e65aaSPeter Wemm #define __INITIAL_MXCSR__ 0x1F80 100395e65aaSPeter Wemm #define __INITIAL_MXCSR_MASK__ 0xFFBF 1015b81b6b3SRodney W. Grimes 102664a31e4SPeter Wemm #ifdef _KERNEL 103bf2f09eeSPeter Wemm int fpudna(void); 104bf2f09eeSPeter Wemm void fpudrop(void); 105bf2f09eeSPeter Wemm void fpuexit(struct thread *td); 106bf2f09eeSPeter Wemm int fpuformat(void); 107bf2f09eeSPeter Wemm int fpugetregs(struct thread *td, struct savefpu *addr); 108bf2f09eeSPeter Wemm void fpuinit(u_short control); 109bf2f09eeSPeter Wemm void fpusave(struct savefpu *addr); 110bf2f09eeSPeter Wemm void fpusetregs(struct thread *td, struct savefpu *addr); 111bf2f09eeSPeter Wemm int fputrap(void); 112a1ca704eSBruce Evans #endif 113a1ca704eSBruce Evans 114bf2f09eeSPeter Wemm #endif /* !_MACHINE_FPU_H_ */ 115