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