fpu.h revision 79609
155714Skris/*- 2280304Sjkim * Copyright (c) 1990 The Regents of the University of California. 3280304Sjkim * All rights reserved. 4280304Sjkim * 555714Skris * This code is derived from software contributed to Berkeley by 655714Skris * William Jolitz. 7160814Ssimon * 855714Skris * Redistribution and use in source and binary forms, with or without 955714Skris * modification, are permitted provided that the following conditions 1055714Skris * are met: 1155714Skris * 1. Redistributions of source code must retain the above copyright 1255714Skris * notice, this list of conditions and the following disclaimer. 1355714Skris * 2. Redistributions in binary form must reproduce the above copyright 14280304Sjkim * notice, this list of conditions and the following disclaimer in the 1555714Skris * documentation and/or other materials provided with the distribution. 1655714Skris * 3. All advertising materials mentioning features or use of this software 1755714Skris * must display the following acknowledgement: 1855714Skris * This product includes software developed by the University of 1955714Skris * California, Berkeley and its contributors. 2055714Skris * 4. Neither the name of the University nor the names of its contributors 2155714Skris * may be used to endorse or promote products derived from this software 2255714Skris * without specific prior written permission. 2355714Skris * 2455714Skris * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2555714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2655714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2755714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2855714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2955714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3055714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3155714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3255714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3355714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3455714Skris * SUCH DAMAGE. 3555714Skris * 3655714Skris * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 3755714Skris * $FreeBSD: head/sys/amd64/include/fpu.h 79609 2001-07-12 06:32:51Z peter $ 3855714Skris */ 3955714Skris 4055714Skris/* 4155714Skris * 287/387 NPX Coprocessor Data Structures and Constants 4255714Skris * W. Jolitz 1/90 4355714Skris */ 4455714Skris 4555714Skris#ifndef _MACHINE_NPX_H_ 4655714Skris#define _MACHINE_NPX_H_ 4755714Skris 4855714Skris/* Environment information of floating point unit */ 4955714Skrisstruct env87 { 5055714Skris long en_cw; /* control word (16bits) */ 5155714Skris long en_sw; /* status word (16bits) */ 5255714Skris long en_tw; /* tag word (16bits) */ 5355714Skris long en_fip; /* floating point instruction pointer */ 5455714Skris u_short en_fcs; /* floating code segment selector */ 5555714Skris u_short en_opcode; /* opcode last executed (11 bits ) */ 5655714Skris long en_foo; /* floating operand offset */ 5755714Skris long en_fos; /* floating operand segment selector */ 5855714Skris}; 5955714Skris 6055714Skris/* Contents of each floating point accumulator */ 6155714Skrisstruct fpacc87 { 6255714Skris#ifdef dontdef /* too unportable */ 6355714Skris u_long fp_mantlo; /* mantissa low (31:0) */ 6455714Skris u_long fp_manthi; /* mantissa high (63:32) */ 6555714Skris int fp_exp:15; /* exponent */ 6655714Skris int fp_sgn:1; /* mantissa sign */ 6755714Skris#else 6855714Skris u_char fp_bytes[10]; 6955714Skris#endif 70280304Sjkim}; 71280304Sjkim 72280304Sjkim/* Floating point context */ 73280304Sjkimstruct save87 { 74280304Sjkim struct env87 sv_env; /* floating point control/status */ 7555714Skris struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ 7655714Skris u_long sv_ex_sw; /* status word for last exception */ 77280304Sjkim /* 78280304Sjkim * Bogus padding for emulators. Emulators should use their own 79280304Sjkim * struct and arrange to store into this struct (ending here) 80280304Sjkim * before it is inspected for ptracing or for core dumps. Some 81109998Smarkm * emulators overwrite the whole struct. We have no good way of 8255714Skris * knowing how much padding to leave. Leave just enough for the 8355714Skris * GPL emulator's i387_union (176 bytes total). 84109998Smarkm */ 85280304Sjkim u_char sv_pad[64]; /* padding; used by emulators */ 86280304Sjkim}; 87280304Sjkim 88280304Sjkimstruct envxmm { 89280304Sjkim u_int16_t en_cw; /* control word (16bits) */ 90280304Sjkim u_int16_t en_sw; /* status word (16bits) */ 91280304Sjkim u_int16_t en_tw; /* tag word (16bits) */ 92280304Sjkim u_int16_t en_opcode; /* opcode last executed (11 bits ) */ 93280304Sjkim u_int32_t en_fip; /* floating point instruction pointer */ 94280304Sjkim u_int16_t en_fcs; /* floating code segment selector */ 95280304Sjkim u_int16_t en_pad0; /* padding */ 96280304Sjkim u_int32_t en_foo; /* floating operand offset */ 97280304Sjkim u_int16_t en_fos; /* floating operand segment selector */ 98280304Sjkim u_int16_t en_pad1; /* padding */ 99280304Sjkim u_int32_t en_mxcsr; /* SSE sontorol/status register */ 10055714Skris u_int32_t en_pad2; /* padding */ 101109998Smarkm}; 10255714Skris 103109998Smarkm/* Contents of each SSE extended accumulator */ 104280304Sjkimstruct xmmacc { 105280304Sjkim u_char xmm_bytes[16]; 106280304Sjkim}; 107280304Sjkim 108280304Sjkimstruct savexmm { 109280304Sjkim struct envxmm sv_env; 110280304Sjkim struct { 111280304Sjkim struct fpacc87 fp_acc; 112280304Sjkim u_char fp_pad[6]; /* padding */ 113280304Sjkim } sv_fp[8]; 11455714Skris struct xmmacc sv_xmm[8]; 115109998Smarkm u_long sv_ex_sw; /* status word for last exception */ 11655714Skris u_char sv_pad[220]; 117109998Smarkm} __attribute__((aligned(16))); 118280304Sjkim 119280304Sjkimunion savefpu { 120280304Sjkim struct save87 sv_87; 121280304Sjkim struct savexmm sv_xmm; 122280304Sjkim}; 123280304Sjkim 124280304Sjkim/* 125280304Sjkim * The hardware default control word for i387's and later coprocessors is 126280304Sjkim * 0x37F, giving: 127280304Sjkim * 128280304Sjkim * round to nearest 129280304Sjkim * 64-bit precision 130280304Sjkim * all exceptions masked. 131280304Sjkim * 132280304Sjkim * We modify the affine mode bit and precision bits in this to give: 133280304Sjkim * 134280304Sjkim * affine mode for 287's (if they work at all) (1 in bitfield 1<<12) 135280304Sjkim * 53-bit precision (2 in bitfield 3<<8) 136280304Sjkim * 137280304Sjkim * 64-bit precision often gives bad results with high level languages 138280304Sjkim * because it makes the results of calculations depend on whether 139280304Sjkim * intermediate values are stored in memory or in FPU registers. 140280304Sjkim */ 141280304Sjkim#define __INITIAL_NPXCW__ 0x127F 142280304Sjkim 143280304Sjkim#ifdef _KERNEL 144280304Sjkimint npxdna __P((void)); 145280304Sjkimvoid npxexit __P((struct proc *p)); 146280304Sjkimvoid npxinit __P((int control)); 147280304Sjkimvoid npxsave __P((union savefpu *addr)); 148280304Sjkimint npxtrap __P((void)); 149280304Sjkim#endif 150280304Sjkim 151280304Sjkim#endif /* !_MACHINE_NPX_H_ */ 152280304Sjkim