xref: /freebsd/lib/libc/powerpcspe/gen/fpgetmask.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1dc9b124dSJustin Hibbits /*	$NetBSD: fpgetmask.c,v 1.3 2002/01/13 21:45:47 thorpej Exp $	*/
2dc9b124dSJustin Hibbits 
3dc9b124dSJustin Hibbits /*
4dc9b124dSJustin Hibbits  * Copyright (c) 2016 Justin Hibbits
5dc9b124dSJustin Hibbits  * All rights reserved.
6dc9b124dSJustin Hibbits  *
7dc9b124dSJustin Hibbits  * This code is derived from software contributed to The NetBSD Foundation
8dc9b124dSJustin Hibbits  * by Dan Winship.
9dc9b124dSJustin Hibbits  *
10dc9b124dSJustin Hibbits  * Redistribution and use in source and binary forms, with or without
11dc9b124dSJustin Hibbits  * modification, are permitted provided that the following conditions
12dc9b124dSJustin Hibbits  * are met:
13dc9b124dSJustin Hibbits  * 1. Redistributions of source code must retain the above copyright
14dc9b124dSJustin Hibbits  *    notice, this list of conditions and the following disclaimer.
15dc9b124dSJustin Hibbits  * 2. Redistributions in binary form must reproduce the above copyright
16dc9b124dSJustin Hibbits  *    notice, this list of conditions and the following disclaimer in the
17dc9b124dSJustin Hibbits  *    documentation and/or other materials provided with the distribution.
18dc9b124dSJustin Hibbits  *
19dc9b124dSJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20dc9b124dSJustin Hibbits  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21dc9b124dSJustin Hibbits  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22dc9b124dSJustin Hibbits  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23dc9b124dSJustin Hibbits  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24dc9b124dSJustin Hibbits  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25dc9b124dSJustin Hibbits  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26dc9b124dSJustin Hibbits  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27dc9b124dSJustin Hibbits  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28dc9b124dSJustin Hibbits  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29dc9b124dSJustin Hibbits  * POSSIBILITY OF SUCH DAMAGE.
30dc9b124dSJustin Hibbits  *
31dc9b124dSJustin Hibbits  */
32dc9b124dSJustin Hibbits 
33dc9b124dSJustin Hibbits #include <sys/types.h>
34dc9b124dSJustin Hibbits #include <machine/spr.h>
35dc9b124dSJustin Hibbits #include <ieeefp.h>
36dc9b124dSJustin Hibbits 
37dc9b124dSJustin Hibbits #ifndef _SOFT_FLOAT
38dc9b124dSJustin Hibbits fp_except_t
fpgetmask()39dc9b124dSJustin Hibbits fpgetmask()
40dc9b124dSJustin Hibbits {
41dc9b124dSJustin Hibbits 	uint32_t fpscr;
42dc9b124dSJustin Hibbits 
43dc9b124dSJustin Hibbits 	__asm__ __volatile("mfspr %0, %1" : "=r"(fpscr) : "K"(SPR_SPEFSCR));
44*adc9dcf3SJustin Hibbits 	return ((fp_except_t)((fpscr >> 2) & 0x1f));
45dc9b124dSJustin Hibbits }
46dc9b124dSJustin Hibbits #endif
47