xref: /freebsd/sys/contrib/openzfs/include/os/linux/spl/sys/isa_defs.h (revision d411c1d696ef35d60f8c3564e5eef7aeafa2fece)
1 /*
2  *  Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3  *  Copyright (C) 2007 The Regents of the University of California.
4  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5  *  Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6  *  UCRL-CODE-235197
7  *
8  *  This file is part of the SPL, Solaris Porting Layer.
9  *
10  *  The SPL is free software; you can redistribute it and/or modify it
11  *  under the terms of the GNU General Public License as published by the
12  *  Free Software Foundation; either version 2 of the License, or (at your
13  *  option) any later version.
14  *
15  *  The SPL is distributed in the hope that it will be useful, but WITHOUT
16  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18  *  for more details.
19  *
20  *  You should have received a copy of the GNU General Public License along
21  *  with the SPL.  If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef	_SPL_ISA_DEFS_H
25 #define	_SPL_ISA_DEFS_H
26 
27 /* x86_64 arch specific defines */
28 #if defined(__x86_64) || defined(__x86_64__)
29 
30 #if !defined(__x86_64)
31 #define	__x86_64
32 #endif
33 
34 #if !defined(__amd64)
35 #define	__amd64
36 #endif
37 
38 #if !defined(__x86)
39 #define	__x86
40 #endif
41 
42 #if defined(_ILP32)
43 /* x32-specific defines; careful to *not* define _LP64 here */
44 #else
45 #if !defined(_LP64)
46 #define	_LP64
47 #endif
48 #endif
49 
50 /* i386 arch specific defines */
51 #elif defined(__i386) || defined(__i386__)
52 
53 #if !defined(__i386)
54 #define	__i386
55 #endif
56 
57 #if !defined(__x86)
58 #define	__x86
59 #endif
60 
61 #if !defined(_ILP32)
62 #define	_ILP32
63 #endif
64 
65 /* powerpc (ppc64) arch specific defines */
66 #elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__)
67 
68 #if !defined(__powerpc)
69 #define	__powerpc
70 #endif
71 
72 #if !defined(__powerpc__)
73 #define	__powerpc__
74 #endif
75 
76 #if defined(__powerpc64__)
77 #if !defined(_LP64)
78 #define	_LP64
79 #endif
80 #else
81 #if !defined(_ILP32)
82 #define	_ILP32
83 #endif
84 #endif
85 
86 /* arm arch specific defines */
87 #elif defined(__arm) || defined(__arm__)
88 
89 #if !defined(__arm)
90 #define	__arm
91 #endif
92 
93 #if !defined(__arm__)
94 #define	__arm__
95 #endif
96 
97 #if !defined(_ILP32)
98 #define	_ILP32
99 #endif
100 
101 #if defined(__ARMEL__)
102 #define	_ZFS_LITTLE_ENDIAN
103 #else
104 #define	_ZFS_BIG_ENDIAN
105 #endif
106 
107 /* aarch64 arch specific defines */
108 #elif defined(__aarch64__)
109 
110 #if !defined(_LP64)
111 #define	_LP64
112 #endif
113 
114 #if defined(__AARCH64EL__)
115 #define	_ZFS_LITTLE_ENDIAN
116 #else
117 #define	_ZFS_BIG_ENDIAN
118 #endif
119 
120 /* sparc arch specific defines */
121 #elif defined(__sparc) || defined(__sparc__)
122 
123 #if !defined(__sparc)
124 #define	__sparc
125 #endif
126 
127 #if !defined(__sparc__)
128 #define	__sparc__
129 #endif
130 
131 #if defined(__arch64__)
132 #if !defined(_LP64)
133 #define	_LP64
134 #endif
135 #else
136 #if !defined(_ILP32)
137 #define	_ILP32
138 #endif
139 #endif
140 
141 #define	_ZFS_BIG_ENDIAN
142 #define	_SUNOS_VTOC_16
143 
144 /* s390 arch specific defines */
145 #elif defined(__s390__)
146 #if defined(__s390x__)
147 #if !defined(_LP64)
148 #define	_LP64
149 #endif
150 #else
151 #if !defined(_ILP32)
152 #define	_ILP32
153 #endif
154 #endif
155 
156 #define	_ZFS_BIG_ENDIAN
157 
158 /* MIPS arch specific defines */
159 #elif defined(__mips__)
160 
161 #if defined(__MIPSEB__)
162 #define	_ZFS_BIG_ENDIAN
163 #elif defined(__MIPSEL__)
164 #define	_ZFS_LITTLE_ENDIAN
165 #else
166 #error MIPS no endian specified
167 #endif
168 
169 #ifndef _LP64
170 #define	_ILP32
171 #endif
172 
173 #define	_SUNOS_VTOC_16
174 
175 /*
176  * RISC-V arch specific defines
177  * only RV64G (including atomic) LP64 is supported yet
178  */
179 #elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 && \
180 	defined(__riscv_atomic) && __riscv_atomic
181 
182 #if !defined(_LP64)
183 #define	_LP64 1
184 #endif
185 
186 #ifndef	__riscv__
187 #define	__riscv__
188 #endif
189 
190 #ifndef	__rv64g__
191 #define	__rv64g__
192 #endif
193 
194 #define	_ZFS_LITTLE_ENDIAN
195 
196 #define	_SUNOS_VTOC_16
197 
198 /*
199  * LoongArch arch specific defines
200  * only LoongArch64 is supported yet
201  */
202 #elif defined(__loongarch__) && defined(__loongarch_lp64)
203 
204 #if !defined(_LP64)
205 #define	_LP64
206 #endif
207 
208 #define	_ZFS_LITTLE_ENDIAN
209 #define	_SUNOS_VTOC_16
210 
211 /* not all LoongArch cores support unaligned accesses in hardware */
212 #define	_ALIGNMENT_REQUIRED	1
213 
214 #else
215 /*
216  * Currently supported:
217  * x86_64, x32, i386, arm, powerpc, s390, sparc, mips, RV64G, and LoongArch64
218  */
219 #error "Unsupported ISA type"
220 #endif
221 
222 #if defined(_ILP32) && defined(_LP64)
223 #error "Both _ILP32 and _LP64 are defined"
224 #endif
225 
226 #if !defined(_ILP32) && !defined(_LP64)
227 #error "Neither _ILP32 or _LP64 are defined"
228 #endif
229 
230 #include <sys/byteorder.h>
231 
232 /*
233  * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS will be defined by the Linux
234  * kernel for architectures which support efficient unaligned access.
235  */
236 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
237 #define	HAVE_EFFICIENT_UNALIGNED_ACCESS
238 #endif
239 
240 #if defined(_ZFS_LITTLE_ENDIAN) && defined(_ZFS_BIG_ENDIAN)
241 #error "Both _ZFS_LITTLE_ENDIAN and _ZFS_BIG_ENDIAN are defined"
242 #endif
243 
244 #if !defined(_ZFS_LITTLE_ENDIAN) && !defined(_ZFS_BIG_ENDIAN)
245 #error "Neither _ZFS_LITTLE_ENDIAN or _ZFS_BIG_ENDIAN are defined"
246 #endif
247 
248 #endif	/* _SPL_ISA_DEFS_H */
249