fpu.h revision 122295
1235783Skib/*- 2235783Skib * Copyright (c) 1990 The Regents of the University of California. 3235783Skib * All rights reserved. 4235783Skib * 5235783Skib * This code is derived from software contributed to Berkeley by 6235783Skib * William Jolitz. 7235783Skib * 8235783Skib * Redistribution and use in source and binary forms, with or without 9235783Skib * modification, are permitted provided that the following conditions 10235783Skib * are met: 11235783Skib * 1. Redistributions of source code must retain the above copyright 12235783Skib * notice, this list of conditions and the following disclaimer. 13235783Skib * 2. Redistributions in binary form must reproduce the above copyright 14235783Skib * notice, this list of conditions and the following disclaimer in the 15235783Skib * documentation and/or other materials provided with the distribution. 16235783Skib * 3. All advertising materials mentioning features or use of this software 17235783Skib * must display the following acknowledgement: 18235783Skib * This product includes software developed by the University of 19235783Skib * California, Berkeley and its contributors. 20235783Skib * 4. Neither the name of the University nor the names of its contributors 21235783Skib * may be used to endorse or promote products derived from this software 22235783Skib * without specific prior written permission. 23235783Skib * 24235783Skib * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25235783Skib * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26235783Skib * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27235783Skib * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28235783Skib * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29235783Skib * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30235783Skib * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31235783Skib * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32235783Skib * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33235783Skib * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34235783Skib * SUCH DAMAGE. 35235783Skib * 36235783Skib * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 37235783Skib * $FreeBSD: head/sys/amd64/include/fpu.h 122295 2003-11-08 04:37:54Z peter $ 38235783Skib */ 39235783Skib 40235783Skib/* 41235783Skib * Floating Point Data Structures and Constants 42235783Skib * W. Jolitz 1/90 43235783Skib */ 44235783Skib 45235783Skib#ifndef _MACHINE_FPU_H_ 46235783Skib#define _MACHINE_FPU_H_ 47235783Skib 48235783Skib/* Contents of each x87 floating point accumulator */ 49235783Skibstruct fpacc87 { 50235783Skib u_char fp_bytes[10]; 51235783Skib}; 52235783Skib 53235783Skib/* Contents of each SSE extended accumulator */ 54235783Skibstruct xmmacc { 55235783Skib u_char xmm_bytes[16]; 56235783Skib}; 57235783Skib 58235783Skibstruct envxmm { 59235783Skib u_int16_t en_cw; /* control word (16bits) */ 60235783Skib u_int16_t en_sw; /* status word (16bits) */ 61235783Skib u_int8_t en_tw; /* tag word (8bits) */ 62235783Skib u_int8_t en_zero; 63235783Skib u_int16_t en_opcode; /* opcode last executed (11 bits ) */ 64235783Skib u_int64_t en_rip; /* floating point instruction pointer */ 65235783Skib u_int64_t en_rdp; /* floating operand pointer */ 66235783Skib u_int32_t en_mxcsr; /* SSE sontorol/status register */ 67235783Skib u_int32_t en_mxcsr_mask; /* valid bits in mxcsr */ 68235783Skib}; 69235783Skib 70235783Skibstruct savefpu { 71235783Skib struct envxmm sv_env; 72235783Skib struct { 73235783Skib struct fpacc87 fp_acc; 74235783Skib u_char fp_pad[6]; /* padding */ 75235783Skib } sv_fp[8]; 76235783Skib struct xmmacc sv_xmm[16]; 77235783Skib u_char sv_pad[96]; 78235783Skib} __aligned(16); 79235783Skib 80235783Skib/* 81235783Skib * The hardware default control word for i387's and later coprocessors is 82235783Skib * 0x37F, giving: 83235783Skib * 84235783Skib * round to nearest 85235783Skib * 64-bit precision 86235783Skib * all exceptions masked. 87235783Skib * 88235783Skib * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc 89235783Skib * because of the difference between memory and fpu register stack arguments. 90235783Skib * If its using an intermediate fpu register, it has 80/64 bits to work 91235783Skib * with. If it uses memory, it has 64/53 bits to work with. However, 92235783Skib * gcc is aware of this and goes to a fair bit of trouble to make the 93235783Skib * best use of it. 94235783Skib * 95235783Skib * This is mostly academic for AMD64, because the ABI prefers the use 96235783Skib * SSE2 based math. For FreeBSD/amd64, we go with the default settings. 97235783Skib */ 98235783Skib#define __INITIAL_FPUCW__ 0x037F 99235783Skib#define __INITIAL_MXCSR__ 0x1F80 100235783Skib#define __INITIAL_MXCSR_MASK__ 0xFFBF 101235783Skib 102235783Skib#ifdef _KERNEL 103235783Skibint fpudna(void); 104235783Skibvoid fpudrop(void); 105235783Skibvoid fpuexit(struct thread *td); 106235783Skibint fpuformat(void); 107235783Skibint fpugetregs(struct thread *td, struct savefpu *addr); 108235783Skibvoid fpuinit(void); 109235783Skibvoid fpusave(struct savefpu *addr); 110235783Skibvoid fpusetregs(struct thread *td, struct savefpu *addr); 111235783Skibint fputrap(void); 112235783Skib#endif 113235783Skib 114235783Skib#endif /* !_MACHINE_FPU_H_ */ 115235783Skib