xref: /openbsd/lib/libc/arch/mips64/gen/fpc_csr.c (revision 1a6ecb2c)
1 /*	$OpenBSD: fpc_csr.c,v 1.1 2010/09/24 13:54:06 miod Exp $	*/
2 
3 /*
4  * Copyright (c) 2010 Miodrag Vallat.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * IRIX-compatible get_fpc_csr() and set_fpc_csr() functions
21  */
22 
23 #include <sys/types.h>
24 #include <machine/fpu.h>
25 
26 int
get_fpc_csr()27 get_fpc_csr()
28 {
29 	int32_t csr;
30 
31 	__asm__("cfc1 %0,$31" : "=r" (csr));
32 	return csr;
33 }
34 
35 int
set_fpc_csr(int csr)36 set_fpc_csr(int csr)
37 {
38 	int32_t oldcsr;
39 
40 	__asm__("cfc1 %0,$31" : "=r" (oldcsr));
41 	__asm__("ctc1 %0,$31" :: "r" (csr));
42 
43 	return oldcsr;
44 }
45