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 * 4. Neither the name of the University nor the names of its contributors 175b81b6b3SRodney W. Grimes * may be used to endorse or promote products derived from this software 185b81b6b3SRodney W. Grimes * without specific prior written permission. 195b81b6b3SRodney W. Grimes * 205b81b6b3SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 215b81b6b3SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 225b81b6b3SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 235b81b6b3SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 245b81b6b3SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 255b81b6b3SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 265b81b6b3SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 275b81b6b3SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 285b81b6b3SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 295b81b6b3SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 305b81b6b3SRodney W. Grimes * SUCH DAMAGE. 315b81b6b3SRodney W. Grimes * 3234a8ed1bSRodney W. Grimes * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 33c3aac50fSPeter Wemm * $FreeBSD$ 345b81b6b3SRodney W. Grimes */ 355b81b6b3SRodney W. Grimes 365b81b6b3SRodney W. Grimes /* 37bf2f09eeSPeter Wemm * Floating Point Data Structures and Constants 385b81b6b3SRodney W. Grimes * W. Jolitz 1/90 395b81b6b3SRodney W. Grimes */ 405b81b6b3SRodney W. Grimes 41bf2f09eeSPeter Wemm #ifndef _MACHINE_FPU_H_ 42bf2f09eeSPeter Wemm #define _MACHINE_FPU_H_ 435b81b6b3SRodney W. Grimes 44afa88623SPeter Wemm /* Contents of each x87 floating point accumulator */ 455b81b6b3SRodney W. Grimes struct fpacc87 { 465b81b6b3SRodney W. Grimes u_char fp_bytes[10]; 479d146ac5SPeter Wemm }; 489d146ac5SPeter Wemm 499d146ac5SPeter Wemm /* Contents of each SSE extended accumulator */ 509d146ac5SPeter Wemm struct xmmacc { 519d146ac5SPeter Wemm u_char xmm_bytes[16]; 529d146ac5SPeter Wemm }; 539d146ac5SPeter Wemm 54afa88623SPeter Wemm struct envxmm { 55afa88623SPeter Wemm u_int16_t en_cw; /* control word (16bits) */ 56afa88623SPeter Wemm u_int16_t en_sw; /* status word (16bits) */ 57afa88623SPeter Wemm u_int8_t en_tw; /* tag word (8bits) */ 58afa88623SPeter Wemm u_int8_t en_zero; 59afa88623SPeter Wemm u_int16_t en_opcode; /* opcode last executed (11 bits ) */ 60afa88623SPeter Wemm u_int64_t en_rip; /* floating point instruction pointer */ 61afa88623SPeter Wemm u_int64_t en_rdp; /* floating operand pointer */ 62afa88623SPeter Wemm u_int32_t en_mxcsr; /* SSE sontorol/status register */ 63afa88623SPeter Wemm u_int32_t en_mxcsr_mask; /* valid bits in mxcsr */ 64afa88623SPeter Wemm }; 65afa88623SPeter Wemm 66afa88623SPeter Wemm struct savefpu { 679d146ac5SPeter Wemm struct envxmm sv_env; 689d146ac5SPeter Wemm struct { 699d146ac5SPeter Wemm struct fpacc87 fp_acc; 709d146ac5SPeter Wemm u_char fp_pad[6]; /* padding */ 719d146ac5SPeter Wemm } sv_fp[8]; 72afa88623SPeter Wemm struct xmmacc sv_xmm[16]; 73afa88623SPeter Wemm u_char sv_pad[96]; 74c692fbe0SPeter Wemm } __aligned(16); 759d146ac5SPeter Wemm 765b81b6b3SRodney W. Grimes /* 770c14a660SMartin Cracauer * The hardware default control word for i387's and later coprocessors is 780c14a660SMartin Cracauer * 0x37F, giving: 795b81b6b3SRodney W. Grimes * 805b81b6b3SRodney W. Grimes * round to nearest 815b81b6b3SRodney W. Grimes * 64-bit precision 825b81b6b3SRodney W. Grimes * all exceptions masked. 835b81b6b3SRodney W. Grimes * 845b9f8ddbSPeter Wemm * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc 855b9f8ddbSPeter Wemm * because of the difference between memory and fpu register stack arguments. 865b9f8ddbSPeter Wemm * If its using an intermediate fpu register, it has 80/64 bits to work 875b9f8ddbSPeter Wemm * with. If it uses memory, it has 64/53 bits to work with. However, 885b9f8ddbSPeter Wemm * gcc is aware of this and goes to a fair bit of trouble to make the 895b9f8ddbSPeter Wemm * best use of it. 905b81b6b3SRodney W. Grimes * 915b9f8ddbSPeter Wemm * This is mostly academic for AMD64, because the ABI prefers the use 925b9f8ddbSPeter Wemm * SSE2 based math. For FreeBSD/amd64, we go with the default settings. 935b81b6b3SRodney W. Grimes */ 94bf2f09eeSPeter Wemm #define __INITIAL_FPUCW__ 0x037F 95de43ac60SJohn Baldwin #define __INITIAL_FPUCW_I386__ 0x127F 96395e65aaSPeter Wemm #define __INITIAL_MXCSR__ 0x1F80 97395e65aaSPeter Wemm #define __INITIAL_MXCSR_MASK__ 0xFFBF 985b81b6b3SRodney W. Grimes 99664a31e4SPeter Wemm #ifdef _KERNEL 100a8346a98SJohn Baldwin void fpudna(void); 101bf2f09eeSPeter Wemm void fpudrop(void); 102bf2f09eeSPeter Wemm void fpuexit(struct thread *td); 103bf2f09eeSPeter Wemm int fpuformat(void); 104bf2f09eeSPeter Wemm int fpugetregs(struct thread *td, struct savefpu *addr); 105398dbb11SPeter Wemm void fpuinit(void); 106bf2f09eeSPeter Wemm void fpusetregs(struct thread *td, struct savefpu *addr); 107bf2f09eeSPeter Wemm int fputrap(void); 108a1ca704eSBruce Evans #endif 109a1ca704eSBruce Evans 110bf2f09eeSPeter Wemm #endif /* !_MACHINE_FPU_H_ */ 111