xref: /haiku/src/system/libroot/os/arch/sparc/fpu_reg.h (revision 803a4704e82749bce36c05ee56792dad62576144)
1*803a4704SPulkoMandy /*-
2*803a4704SPulkoMandy  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*803a4704SPulkoMandy  *
4*803a4704SPulkoMandy  * Copyright (c) 2002 by Thomas Moestl <tmm@FreeBSD.org>.
5*803a4704SPulkoMandy  * All rights reserved.
6*803a4704SPulkoMandy  *
7*803a4704SPulkoMandy  * Redistribution and use in source and binary forms, with or without
8*803a4704SPulkoMandy  * modification, are permitted provided that the following conditions
9*803a4704SPulkoMandy  * are met:
10*803a4704SPulkoMandy  * 1. Redistributions of source code must retain the above copyright
11*803a4704SPulkoMandy  *    notice, this list of conditions and the following disclaimer.
12*803a4704SPulkoMandy  * 2. Redistributions in binary form must reproduce the above copyright
13*803a4704SPulkoMandy  *    notice, this list of conditions and the following disclaimer in the
14*803a4704SPulkoMandy  *    documentation and/or other materials provided with the distribution.
15*803a4704SPulkoMandy  *
16*803a4704SPulkoMandy  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*803a4704SPulkoMandy  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*803a4704SPulkoMandy  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*803a4704SPulkoMandy  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20*803a4704SPulkoMandy  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21*803a4704SPulkoMandy  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22*803a4704SPulkoMandy  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23*803a4704SPulkoMandy  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24*803a4704SPulkoMandy  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25*803a4704SPulkoMandy  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*803a4704SPulkoMandy  *
27*803a4704SPulkoMandy  * $FreeBSD: head/lib/libc/sparc64/fpu/fpu_reg.h 327232 2017-12-27 03:23:41Z eadler $
28*803a4704SPulkoMandy  */
29*803a4704SPulkoMandy 
30*803a4704SPulkoMandy #ifndef _LIBC_SPARC64_FPU_FPU_REG_H_
31*803a4704SPulkoMandy #define _LIBC_SPARC64_FPU_FPU_REG_H_
32*803a4704SPulkoMandy 
33*803a4704SPulkoMandy #include <stdint.h>
34*803a4704SPulkoMandy 
35*803a4704SPulkoMandy /*
36*803a4704SPulkoMandy  * These are not really of type char[]. They are arrays of functions defined
37*803a4704SPulkoMandy  * in fpu_reg.S; each array member loads/stores a certain fpu register of the
38*803a4704SPulkoMandy  * given size.
39*803a4704SPulkoMandy  */
40*803a4704SPulkoMandy extern char __fpu_ld32[];
41*803a4704SPulkoMandy extern char __fpu_st32[];
42*803a4704SPulkoMandy extern char __fpu_ld64[];
43*803a4704SPulkoMandy extern char __fpu_st64[];
44*803a4704SPulkoMandy 
45*803a4704SPulkoMandy /* Size of the functions in the arrays. */
46*803a4704SPulkoMandy #define	FPU_LD32_SZ	8
47*803a4704SPulkoMandy #define	FPU_ST32_SZ	8
48*803a4704SPulkoMandy #define	FPU_LD64_SZ	8
49*803a4704SPulkoMandy #define	FPU_ST64_SZ	8
50*803a4704SPulkoMandy 
51*803a4704SPulkoMandy /* Typedefs for convenient casts in the functions below. */
52*803a4704SPulkoMandy typedef void (fp_ldst32_fn)(uint32_t *);
53*803a4704SPulkoMandy typedef void (fp_ldst64_fn)(uint64_t *);
54*803a4704SPulkoMandy 
55*803a4704SPulkoMandy /*
56*803a4704SPulkoMandy  * These are the functions that are actually used in the fpu emulation code to
57*803a4704SPulkoMandy  * access the fp registers. They are usually not used more than once, so
58*803a4704SPulkoMandy  * caching needs not be done here.
59*803a4704SPulkoMandy  */
60*803a4704SPulkoMandy static __inline uint32_t
__fpu_getreg(int r)61*803a4704SPulkoMandy __fpu_getreg(int r)
62*803a4704SPulkoMandy {
63*803a4704SPulkoMandy 	uint32_t rv;
64*803a4704SPulkoMandy 
65*803a4704SPulkoMandy 	((fp_ldst32_fn *)&__fpu_st32[r * FPU_ST32_SZ])(&rv);
66*803a4704SPulkoMandy 	return (rv);
67*803a4704SPulkoMandy }
68*803a4704SPulkoMandy 
69*803a4704SPulkoMandy static __inline uint64_t
__fpu_getreg64(int r)70*803a4704SPulkoMandy __fpu_getreg64(int r)
71*803a4704SPulkoMandy {
72*803a4704SPulkoMandy 	uint64_t rv;
73*803a4704SPulkoMandy 
74*803a4704SPulkoMandy 	((fp_ldst64_fn *)&__fpu_st64[(r >> 1) * FPU_ST64_SZ])(&rv);
75*803a4704SPulkoMandy 	return (rv);
76*803a4704SPulkoMandy }
77*803a4704SPulkoMandy 
78*803a4704SPulkoMandy static __inline void
__fpu_setreg(int r,uint32_t v)79*803a4704SPulkoMandy __fpu_setreg(int r, uint32_t v)
80*803a4704SPulkoMandy {
81*803a4704SPulkoMandy 
82*803a4704SPulkoMandy 	((fp_ldst32_fn *)&__fpu_ld32[r * FPU_LD32_SZ])(&v);
83*803a4704SPulkoMandy }
84*803a4704SPulkoMandy 
85*803a4704SPulkoMandy static __inline void
__fpu_setreg64(int r,uint64_t v)86*803a4704SPulkoMandy __fpu_setreg64(int r, uint64_t v)
87*803a4704SPulkoMandy {
88*803a4704SPulkoMandy 
89*803a4704SPulkoMandy 	((fp_ldst64_fn *)&__fpu_ld64[(r >> 1) * FPU_LD64_SZ])(&v);
90*803a4704SPulkoMandy }
91*803a4704SPulkoMandy 
92*803a4704SPulkoMandy #endif /* _LIBC_SPARC64_FPU_FPU_REG_H_ */
93