xref: /freebsd/lib/libc/arm/gen/fpsetmask_vfp.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
13f573009SAndrew Turner /*
23f573009SAndrew Turner  * Copyright (C) 2014 Andrew Turner
33f573009SAndrew Turner  * All rights reserved.
43f573009SAndrew Turner  *
53f573009SAndrew Turner  * Redistribution and use in source and binary forms, with or without
63f573009SAndrew Turner  * modification, are permitted provided that the following conditions
73f573009SAndrew Turner  * are met:
83f573009SAndrew Turner  * 1. Redistributions of source code must retain the above copyright
93f573009SAndrew Turner  *    notice, this list of conditions and the following disclaimer.
103f573009SAndrew Turner  * 2. Redistributions in binary form must reproduce the above copyright
113f573009SAndrew Turner  *    notice, this list of conditions and the following disclaimer in the
123f573009SAndrew Turner  *    documentation and/or other materials provided with the distribution.
133f573009SAndrew Turner  *
143f573009SAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
153f573009SAndrew Turner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
163f573009SAndrew Turner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
173f573009SAndrew Turner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
183f573009SAndrew Turner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
193f573009SAndrew Turner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
203f573009SAndrew Turner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
213f573009SAndrew Turner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
223f573009SAndrew Turner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
233f573009SAndrew Turner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
243f573009SAndrew Turner  * SUCH DAMAGE.
253f573009SAndrew Turner  *
263f573009SAndrew Turner  */
273f573009SAndrew Turner 
283f573009SAndrew Turner #include <sys/types.h>
293f573009SAndrew Turner #include <ieeefp.h>
303f573009SAndrew Turner 
313f573009SAndrew Turner #ifdef __weak_alias
__weak_alias(fpsetmask,_fpsetmask)323f573009SAndrew Turner __weak_alias(fpsetmask,_fpsetmask)
333f573009SAndrew Turner #endif
343f573009SAndrew Turner 
353f573009SAndrew Turner #define FP_X_MASK	(FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP)
363f573009SAndrew Turner 
373f573009SAndrew Turner fp_except_t
383f573009SAndrew Turner fpsetmask(fp_except_t mask)
393f573009SAndrew Turner {
403f573009SAndrew Turner 	fp_except old, new;
413f573009SAndrew Turner 
423f573009SAndrew Turner 	__asm __volatile("vmrs %0, fpscr" : "=&r"(old));
433f573009SAndrew Turner 	mask = (mask & FP_X_MASK) << 8;
443f573009SAndrew Turner 	new = (old & ~(FP_X_MASK << 8)) | mask;
45*8258fd68SAndrew Turner 	__asm __volatile("vmsr fpscr, %0" : : "r"(new));
463f573009SAndrew Turner 
473f573009SAndrew Turner 	return ((old >> 8) & FP_X_MASK);
483f573009SAndrew Turner }
493f573009SAndrew Turner 
50