1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23/*
24 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25 * Use is subject to license terms.
26 */
27
28#ifndef	_SYS_ISA_DEFS_H
29#define	_SYS_ISA_DEFS_H
30#include <sys/endian.h>
31
32/*
33 * This header file serves to group a set of well known defines and to
34 * set these for each instruction set architecture.  These defines may
35 * be divided into two groups;  characteristics of the processor and
36 * implementation choices for Solaris on a processor.
37 *
38 * Processor Characteristics:
39 *
40 * _LITTLE_ENDIAN / _BIG_ENDIAN:
41 *	The natural byte order of the processor.  A pointer to an int points
42 *	to the least/most significant byte of that int.
43 *
44 *
45 * Implementation Choices:
46 *
47 * _ILP32 / _LP64:
48 *	This specifies the compiler data type implementation as specified in
49 *	the relevant ABI.  The choice between these is strongly influenced
50 *	by the underlying hardware, but is not absolutely tied to it.
51 *	Currently only two data type models are supported:
52 *
53 *	_ILP32:
54 *		Int/Long/Pointer are 32 bits.  This is the historical UNIX
55 *		and Solaris implementation.  Due to its historical standing,
56 *		this is the default case.
57 *
58 *	_LP64:
59 *		Long/Pointer are 64 bits, Int is 32 bits.  This is the chosen
60 *		implementation for 64-bit ABIs such as SPARC V9.
61 *
62 *	In all cases, Char is 8 bits and Short is 16 bits.
63 *
64 * _SUNOS_VTOC_8 / _SUNOS_VTOC_16 / _SVR4_VTOC_16:
65 *	This specifies the form of the disk VTOC (or label):
66 *
67 *	_SUNOS_VTOC_8:
68 *		This is a VTOC form which is upwardly compatible with the
69 *		SunOS 4.x disk label and allows 8 partitions per disk.
70 *
71 *	_SUNOS_VTOC_16:
72 *		In this format the incore vtoc image matches the ondisk
73 *		version.  It allows 16 slices per disk, and is not
74 *		compatible with the SunOS 4.x disk label.
75 *
76 *	Note that these are not the only two VTOC forms possible and
77 *	additional forms may be added.  One possible form would be the
78 *	SVr4 VTOC form.  The symbol for that is reserved now, although
79 *	it is not implemented.
80 *
81 *	_SVR4_VTOC_16:
82 *		This VTOC form is compatible with the System V Release 4
83 *		VTOC (as implemented on the SVr4 Intel and 3b ports) with
84 *		16 partitions per disk.
85 *
86 *
87 * __x86
88 *	This is ONLY a synonym for defined(__i386) || defined(__amd64)
89 *	which is useful only insofar as these two architectures share
90 *	common attributes.  Analogous to __sparc.
91 */
92
93#ifdef	__cplusplus
94extern "C" {
95#endif
96
97/*
98 * The following set of definitions characterize Solaris on AMD's
99 * 64-bit systems.
100 */
101#if defined(__x86_64) || defined(__amd64)
102
103#if !defined(__amd64)
104#define	__amd64		/* preferred guard */
105#endif
106
107#if !defined(__x86)
108#define	__x86
109#endif
110
111/*
112 * Define the appropriate "implementation choices".
113 */
114#if !defined(_LP64)
115#error "_LP64 not defined"
116#endif
117#define	_SUNOS_VTOC_16
118
119/*
120 * The feature test macro __i386 is generic for all processors implementing
121 * the Intel 386 instruction set or a superset of it.  Specifically, this
122 * includes all members of the 386, 486, and Pentium family of processors.
123 */
124#elif defined(__i386) || defined(__i386__)
125
126#if !defined(__i386)
127#define	__i386
128#endif
129
130#if !defined(__x86)
131#define	__x86
132#endif
133
134/*
135 * Define the appropriate "implementation choices".
136 */
137#if !defined(_ILP32)
138#define	_ILP32
139#endif
140#define	_SUNOS_VTOC_16
141
142#elif defined(__aarch64__)
143
144/*
145 * Define the appropriate "implementation choices"
146 */
147#if !defined(_LP64)
148#error "_LP64 not defined"
149#endif
150#define	_SUNOS_VTOC_16
151
152#elif defined(__riscv)
153
154/*
155 * Define the appropriate "implementation choices"
156 */
157#if !defined(_LP64)
158#define	_LP64
159#endif
160#define	_SUNOS_VTOC_16
161
162#elif defined(__arm__)
163
164/*
165 * Define the appropriate "implementation choices".
166 */
167#if !defined(_ILP32)
168#define	_ILP32
169#endif
170#define	_SUNOS_VTOC_16
171
172#elif defined(__mips__)
173
174#if defined(__mips_n64)
175/*
176 * Define the appropriate "implementation choices".
177 */
178#if !defined(_LP64)
179#error "_LP64 not defined"
180#endif
181#else
182/*
183 * Define the appropriate "implementation choices".
184 */
185#if !defined(_ILP32)
186#define	_ILP32
187#endif
188#endif
189#define	_SUNOS_VTOC_16
190
191#elif defined(__powerpc__)
192
193#if !defined(__powerpc)
194#define	__powerpc
195#endif
196
197#define	_SUNOS_VTOC_16	1
198
199/*
200 * The following set of definitions characterize the Solaris on SPARC systems.
201 *
202 * The symbol __sparc indicates any of the SPARC family of processor
203 * architectures.  This includes SPARC V7, SPARC V8 and SPARC V9.
204 *
205 * The symbol __sparcv8 indicates the 32-bit SPARC V8 architecture as defined
206 * by Version 8 of the SPARC Architecture Manual.  (SPARC V7 is close enough
207 * to SPARC V8 for the former to be subsumed into the latter definition.)
208 *
209 * The symbol __sparcv9 indicates the 64-bit SPARC V9 architecture as defined
210 * by Version 9 of the SPARC Architecture Manual.
211 *
212 * The symbols __sparcv8 and __sparcv9 are mutually exclusive, and are only
213 * relevant when the symbol __sparc is defined.
214 */
215/*
216 * XXX Due to the existence of 5110166, "defined(__sparcv9)" needs to be added
217 * to support backwards builds.  This workaround should be removed in s10_71.
218 */
219#elif defined(__sparc) || defined(__sparcv9) || defined(__sparc__)
220#if !defined(__sparc)
221#define	__sparc
222#endif
223
224/*
225 * You can be 32-bit or 64-bit, but not both at the same time.
226 */
227#if defined(__sparcv8) && defined(__sparcv9)
228#error	"SPARC Versions 8 and 9 are mutually exclusive choices"
229#endif
230
231/*
232 * Existing compilers do not set __sparcv8.  Years will transpire before
233 * the compilers can be depended on to set the feature test macro. In
234 * the interim, we'll set it here on the basis of historical behaviour;
235 * if you haven't asked for SPARC V9, then you must've meant SPARC V8.
236 */
237#if !defined(__sparcv9) && !defined(__sparcv8)
238#define	__sparcv8
239#endif
240
241/*
242 * Define the appropriate "implementation choices" shared between versions.
243 */
244#define	_SUNOS_VTOC_8
245
246/*
247 * The following set of definitions characterize the implementation of
248 * 32-bit Solaris on SPARC V8 systems.
249 */
250#if defined(__sparcv8)
251
252/*
253 * Define the appropriate "implementation choices"
254 */
255#define	_ILP32
256
257/*
258 * The following set of definitions characterize the implementation of
259 * 64-bit Solaris on SPARC V9 systems.
260 */
261#elif defined(__sparcv9)
262
263/*
264 * Define the appropriate "implementation choices"
265 */
266#if !defined(_LP64)
267#error "_LP64 not defined"
268#endif
269
270#else
271#error	"unknown SPARC version"
272#endif
273
274/*
275 * #error is strictly ansi-C, but works as well as anything for K&R systems.
276 */
277#else
278#error "ISA not supported"
279#endif
280
281#if defined(_ILP32) && defined(_LP64)
282#error "Both _ILP32 and _LP64 are defined"
283#endif
284
285#if BYTE_ORDER == _BIG_ENDIAN
286#define	_ZFS_BIG_ENDIAN
287#elif BYTE_ORDER == _LITTLE_ENDIAN
288#define	_ZFS_LITTLE_ENDIAN
289#else
290#error "unknown byte order"
291#endif
292
293#ifdef	__cplusplus
294}
295#endif
296
297#endif	/* _SYS_ISA_DEFS_H */
298