1*f36c0f62SAndrew Turner /*- 2*f36c0f62SAndrew Turner * Copyright (c) 2015 The FreeBSD Foundation 3*f36c0f62SAndrew Turner * All rights reserved. 4*f36c0f62SAndrew Turner * 5*f36c0f62SAndrew Turner * This software was developed by Andrew Turner under 6*f36c0f62SAndrew Turner * sponsorship from the FreeBSD Foundation. 7*f36c0f62SAndrew Turner * 8*f36c0f62SAndrew Turner * Redistribution and use in source and binary forms, with or without 9*f36c0f62SAndrew Turner * modification, are permitted provided that the following conditions 10*f36c0f62SAndrew Turner * are met: 11*f36c0f62SAndrew Turner * 1. Redistributions of source code must retain the above copyright 12*f36c0f62SAndrew Turner * notice, this list of conditions and the following disclaimer. 13*f36c0f62SAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright 14*f36c0f62SAndrew Turner * notice, this list of conditions and the following disclaimer in the 15*f36c0f62SAndrew Turner * documentation and/or other materials provided with the distribution. 16*f36c0f62SAndrew Turner * 17*f36c0f62SAndrew Turner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18*f36c0f62SAndrew Turner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*f36c0f62SAndrew Turner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*f36c0f62SAndrew Turner * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21*f36c0f62SAndrew Turner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*f36c0f62SAndrew Turner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*f36c0f62SAndrew Turner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*f36c0f62SAndrew Turner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*f36c0f62SAndrew Turner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*f36c0f62SAndrew Turner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*f36c0f62SAndrew Turner * SUCH DAMAGE. 28*f36c0f62SAndrew Turner */ 29*f36c0f62SAndrew Turner 30*f36c0f62SAndrew Turner #include <sys/cdefs.h> 31*f36c0f62SAndrew Turner __FBSDID("$FreeBSD$"); 32*f36c0f62SAndrew Turner 33*f36c0f62SAndrew Turner #include <sys/types.h> 34*f36c0f62SAndrew Turner #include <ieeefp.h> 35*f36c0f62SAndrew Turner 36*f36c0f62SAndrew Turner #define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) 37*f36c0f62SAndrew Turner 38*f36c0f62SAndrew Turner fp_except_t 39*f36c0f62SAndrew Turner fpsetmask(fp_except_t mask) 40*f36c0f62SAndrew Turner { 41*f36c0f62SAndrew Turner uint64_t old, new; 42*f36c0f62SAndrew Turner 43*f36c0f62SAndrew Turner mask &= FP_X_MASK; 44*f36c0f62SAndrew Turner 45*f36c0f62SAndrew Turner /* Read the current mask */ 46*f36c0f62SAndrew Turner __asm __volatile("mrs %0, fpcr" : "=&r"(old)); 47*f36c0f62SAndrew Turner new = old & ~FP_X_MASK; 48*f36c0f62SAndrew Turner new |= mask; 49*f36c0f62SAndrew Turner __asm __volatile("msr fpcr, %0" :: "r"(new)); 50*f36c0f62SAndrew Turner 51*f36c0f62SAndrew Turner return ((fp_except_t)old); 52*f36c0f62SAndrew Turner } 53