Home | History | Annotate | Line # | Download | only in include
fpu.h revision 1.5
      1 /* $NetBSD: fpu.h,v 1.5 2008/04/28 20:23:11 martin Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2001 Ross Harvey
      5  * All rights reserved.
      6  *
      7  * This software was written for NetBSD.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef _ALPHA_FPU_H_
     32 #define _ALPHA_FPU_H_
     33 
     34 #define	_FP_C_DEF(n) (1UL << (n))
     35 
     36 /*
     37  * Most of these next definitions were moved from <ieeefp.h>. Apparently the
     38  * names happen to match those exported by Compaq and Linux from their fpu.h
     39  * files.
     40  */
     41 
     42 #define	FPCR_SUM	_FP_C_DEF(63)
     43 #define	FPCR_INED	_FP_C_DEF(62)
     44 #define	FPCR_UNFD	_FP_C_DEF(61)
     45 #define	FPCR_UNDZ	_FP_C_DEF(60)
     46 #define	FPCR_DYN(rm)	((unsigned long)(rm) << 58)
     47 #define	FPCR_IOV	_FP_C_DEF(57)
     48 #define	FPCR_INE	_FP_C_DEF(56)
     49 #define	FPCR_UNF	_FP_C_DEF(55)
     50 #define	FPCR_OVF	_FP_C_DEF(54)
     51 #define	FPCR_DZE	_FP_C_DEF(53)
     52 #define	FPCR_INV	_FP_C_DEF(52)
     53 #define	FPCR_OVFD	_FP_C_DEF(51)
     54 #define	FPCR_DZED	_FP_C_DEF(50)
     55 #define	FPCR_INVD	_FP_C_DEF(49)
     56 #define	FPCR_DNZ	_FP_C_DEF(48)
     57 #define	FPCR_DNOD	_FP_C_DEF(47)
     58 
     59 #define	FPCR_MIRRORED (FPCR_INE | FPCR_UNF | FPCR_OVF | FPCR_DZE | FPCR_INV)
     60 #define FPCR_MIR_START 52
     61 
     62 /*
     63  * The AARM specifies the bit positions of the software word used for
     64  * user mode interface to the control and status of the kernel completion
     65  * routines. Although it largely just redefines the FPCR, it shuffles
     66  * the bit order. The names of the bits are defined in the AARM, and
     67  * the definition prefix can easily be determined from public domain
     68  * programs written to either the Compaq or Linux interfaces, which
     69  * appear to be identical.
     70  */
     71 
     72 #define IEEE_STATUS_DNO _FP_C_DEF(22)
     73 #define IEEE_STATUS_INE _FP_C_DEF(21)
     74 #define IEEE_STATUS_UNF _FP_C_DEF(20)
     75 #define IEEE_STATUS_OVF _FP_C_DEF(19)
     76 #define IEEE_STATUS_DZE _FP_C_DEF(18)
     77 #define IEEE_STATUS_INV _FP_C_DEF(17)
     78 
     79 #define	IEEE_TRAP_ENABLE_DNO _FP_C_DEF(6)
     80 #define	IEEE_TRAP_ENABLE_INE _FP_C_DEF(5)
     81 #define	IEEE_TRAP_ENABLE_UNF _FP_C_DEF(4)
     82 #define	IEEE_TRAP_ENABLE_OVF _FP_C_DEF(3)
     83 #define	IEEE_TRAP_ENABLE_DZE _FP_C_DEF(2)
     84 #define	IEEE_TRAP_ENABLE_INV _FP_C_DEF(1)
     85 
     86 #define	IEEE_INHERIT _FP_C_DEF(14)
     87 #define	IEEE_MAP_UMZ _FP_C_DEF(13)
     88 #define	IEEE_MAP_DMZ _FP_C_DEF(12)
     89 
     90 #define FP_C_MIRRORED (IEEE_STATUS_INE | IEEE_STATUS_UNF | IEEE_STATUS_OVF\
     91 				| IEEE_STATUS_DZE | IEEE_STATUS_INV)
     92 #define	FP_C_MIR_START 17
     93 
     94 #ifdef _KERNEL
     95 
     96 #define	FLD_MASK(len) ((1UL << (len)) - 1)
     97 #define FLD_CLEAR(obj, origin, len)	\
     98 		((obj) & ~(FLD_MASK(len) << (origin)))
     99 #define	FLD_INSERT(obj, origin, len, value)	\
    100 		(FLD_CLEAR(obj, origin, len) | (value) << origin)
    101 
    102 #define	FP_C_TO_NETBSD_MASK(fp_c) 	((fp_c) >> 1 & 0x3f)
    103 #define	FP_C_TO_NETBSD_FLAG(fp_c) 	((fp_c) >> 17 & 0x3f)
    104 #define NETBSD_MASK_TO_FP_C(m)		(((m) & 0x3f) << 1)
    105 #define NETBSD_FLAG_TO_FP_C(s)		(((s) & 0x3f) << 17)
    106 #define	CLEAR_FP_C_MASK(fp_c)		((fp_c) & ~(0x3f << 1))
    107 #define	CLEAR_FP_C_FLAG(fp_c)		((fp_c) & ~(0x3f << 17))
    108 #define	SET_FP_C_MASK(fp_c, m) (CLEAR_FP_C_MASK(fp_c) | NETBSD_MASK_TO_FP_C(m))
    109 #define	SET_FP_C_FLAG(fp_c, m) (CLEAR_FP_C_FLAG(fp_c) | NETBSD_FLAG_TO_FP_C(m))
    110 
    111 #endif
    112 
    113 #endif
    114