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