xref: /freebsd/share/man/man7/arch.7 (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1.\" Copyright (c) 2016-2017 The FreeBSD Foundation.
2.\"
3.\" This documentation was created by Ed Maste under sponsorship of
4.\" The FreeBSD Foundation.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.Dd July 13, 2024
28.Dt ARCH 7
29.Os
30.Sh NAME
31.Nm arch
32.Nd Architecture-specific details
33.Sh DESCRIPTION
34Differences between CPU architectures and platforms supported by
35.Fx .
36.Ss Introduction
37This document is a quick reference of key ABI details of
38.Fx
39architecture ports.
40For full details consult the processor-specific ABI supplement
41documentation.
42.Pp
43If not explicitly mentioned, sizes are in bytes.
44The architecture details in this document apply to
45.Fx 12.0
46and later, unless otherwise noted.
47.Pp
48.Fx
49uses a flat address space.
50Variables of types
51.Vt unsigned long ,
52.Vt uintptr_t ,
53and
54.Vt size_t
55and pointers all have the same representation.
56.Pp
57In order to maximize compatibility with future pointer integrity mechanisms,
58manipulations of pointers as integers should be performed via
59.Vt uintptr_t
60or
61.Vt intptr_t
62and no other types.
63In particular,
64.Vt long
65and
66.Vt ptrdiff_t
67should be avoided.
68.Pp
69On some architectures, e.g.,
70.Dv powerpc
71and AIM variants of
72.Dv powerpc64 ,
73the kernel uses a separate address space.
74On other architectures, kernel and a user mode process share a
75single address space.
76The kernel is located at the highest addresses.
77.Pp
78On each architecture, the main user mode thread's stack starts near
79the highest user address and grows down.
80.Pp
81.Fx
82architecture support varies by release.
83This table shows currently supported CPU architectures along with the first
84.Fx
85release to support each architecture.
86.Bl -column -offset indent "Architecture" "Initial Release"
87.It Sy Architecture Ta Sy Initial Release
88.It aarch64     Ta 11.0
89.It amd64       Ta 5.1
90.It armv7       Ta 12.0
91.It i386        Ta 1.0
92.It powerpc     Ta 6.0
93.It powerpcspe  Ta 12.0
94.It powerpc64   Ta 9.0
95.It powerpc64le Ta 13.0
96.It riscv64     Ta 12.0
97.El
98.Pp
99Discontinued architectures are shown in the following table.
100.Bl -column -offset indent "Architecture" "Initial Release" "Final Release"
101.It Sy Architecture Ta Sy Initial Release Ta Sy Final Release
102.It alpha       Ta 3.2   Ta 6.4
103.It arm         Ta 6.0   Ta 12.4
104.It armeb       Ta 8.0   Ta 11.4
105.It armv6       Ta 10.0  Ta 14.x
106.It ia64        Ta 5.0   Ta 10.4
107.It mips        Ta 8.0   Ta 13.x
108.It mipsel      Ta 9.0   Ta 13.x
109.It mipselhf    Ta 12.0  Ta 13.x
110.It mipshf      Ta 12.0  Ta 13.x
111.It mipsn32     Ta 9.0   Ta 13.x
112.It mips64      Ta 9.0   Ta 13.x
113.It mips64el    Ta 9.0   Ta 13.x
114.It mips64elhf  Ta 12.0  Ta 13.x
115.It mips64hf    Ta 12.0  Ta 13.x
116.It pc98        Ta 2.2   Ta 11.4
117.It riscv64sf   Ta 12.0  Ta 13.x
118.It sparc64     Ta 5.0   Ta 12.4
119.El
120.Ss Type sizes
121All
122.Fx
123architectures use some variant of the ELF (see
124.Xr elf 5 )
125.Sy Application Binary Interface
126(ABI) for the machine processor.
127All supported ABIs can be divided into two groups:
128.Bl -tag -width "Dv ILP32"
129.It Dv ILP32
130.Vt int ,
131.Vt long ,
132.Vt void *
133types machine representations all have 4-byte size.
134.It Dv LP64
135.Vt int
136type machine representation uses 4 bytes,
137while
138.Vt long
139and
140.Vt void *
141are 8 bytes.
142.El
143.Pp
144Some machines support more than one
145.Fx
146ABI.
147Typically these are 64-bit machines, where the
148.Dq native
149.Dv LP64
150execution environment is accompanied by the
151.Dq legacy
152.Dv ILP32
153environment, which was the historical 32-bit predecessor for 64-bit evolution.
154Examples are:
155.Bl -column -offset indent "powerpc64" "ILP32 counterpart"
156.It Sy LP64        Ta Sy ILP32 counterpart
157.It Dv amd64       Ta Dv i386
158.It Dv powerpc64   Ta Dv powerpc
159.It Dv aarch64     Ta Dv armv7
160.El
161.Pp
162.Dv aarch64
163will support execution of
164.Dv armv7
165binaries if the CPU implements
166.Dv AArch32
167execution state, however older arm binaries are not supported by
168.Fx .
169.Pp
170On all supported architectures:
171.Bl -column -offset -indent "long long" "Size"
172.It Sy Type Ta Sy Size
173.It short Ta 2
174.It int Ta 4
175.It long Ta sizeof(void*)
176.It long long Ta 8
177.It float Ta 4
178.It double Ta 8
179.El
180.Pp
181Integers are represented in two's complement.
182Alignment of integer and pointer types is natural, that is,
183the address of the variable must be congruent to zero modulo the type size.
184Most ILP32 ABIs, except
185.Dv arm ,
186require only 4-byte alignment for 64-bit integers.
187.Pp
188Machine-dependent type sizes:
189.Bl -column -offset indent "Architecture" "void *" "long double" "time_t"
190.It Sy Architecture Ta Sy void * Ta Sy long double Ta Sy time_t
191.It aarch64     Ta 8 Ta 16 Ta 8
192.It amd64       Ta 8 Ta 16 Ta 8
193.It armv7       Ta 4 Ta  8 Ta 8
194.It i386        Ta 4 Ta 12 Ta 4
195.It powerpc     Ta 4 Ta  8 Ta 8
196.It powerpcspe  Ta 4 Ta  8 Ta 8
197.It powerpc64   Ta 8 Ta  8 Ta 8
198.It powerpc64le Ta 8 Ta  8 Ta 8
199.It riscv64     Ta 8 Ta 16 Ta 8
200.El
201.Pp
202.Sy time_t
203is 8 bytes on all supported architectures except i386.
204.Ss Endianness and Char Signedness
205.Bl -column -offset indent "Architecture" "Endianness" "char Signedness"
206.It Sy Architecture Ta Sy Endianness Ta Sy char Signedness
207.It aarch64     Ta little Ta unsigned
208.It amd64       Ta little Ta   signed
209.It armv7       Ta little Ta unsigned
210.It i386        Ta little Ta   signed
211.It powerpc     Ta big    Ta unsigned
212.It powerpcspe  Ta big    Ta unsigned
213.It powerpc64   Ta big    Ta unsigned
214.It powerpc64le Ta little Ta unsigned
215.It riscv64     Ta little Ta   signed
216.El
217.Ss Page Size
218.Bl -column -offset indent "Architecture" "Page Sizes"
219.It Sy Architecture Ta Sy Page Sizes
220.It aarch64     Ta 4K, 64K, 2M, 1G
221.It amd64       Ta 4K, 2M, 1G
222.It armv7       Ta 4K, 1M
223.It i386        Ta 4K, 2M (PAE), 4M
224.It powerpc     Ta 4K
225.It powerpcspe  Ta 4K
226.It powerpc64   Ta 4K
227.It powerpc64le Ta 4K
228.It riscv64     Ta 4K, 2M, 1G
229.El
230.Ss Floating Point
231.Bl -column -offset indent "Architecture" "float, double" "long double"
232.It Sy Architecture Ta Sy float, double Ta Sy long double
233.It aarch64     Ta hard Ta soft, quad precision
234.It amd64       Ta hard Ta hard, 80 bit
235.It armv7       Ta hard Ta hard, double precision
236.It i386        Ta hard Ta hard, 80 bit
237.It powerpc     Ta hard Ta hard, double precision
238.It powerpcspe  Ta hard Ta hard, double precision
239.It powerpc64   Ta hard Ta hard, double precision
240.It powerpc64le Ta hard Ta hard, double precision
241.It riscv64     Ta hard Ta hard, quad precision
242.El
243.Ss Default Tool Chain
244.Fx
245uses
246.Xr clang 1
247as the default compiler on all supported CPU architectures,
248LLVM's
249.Xr ld.lld 1
250as the default linker, and
251ELF Tool Chain binary utilities such as
252.Xr objcopy 1
253and
254.Xr readelf 1 .
255.Ss MACHINE_ARCH vs MACHINE_CPUARCH vs MACHINE
256.Dv MACHINE_CPUARCH
257should be preferred in Makefiles when the generic
258architecture is being tested.
259.Dv MACHINE_ARCH
260should be preferred when there is something specific to a particular type of
261architecture where there is a choice of many, or could be a choice of many.
262Use
263.Dv MACHINE
264when referring to the kernel, interfaces dependent on a specific type of kernel
265or similar things like boot sequences.
266.Bl -column -offset indent "Dv MACHINE" "Dv MACHINE_CPUARCH" "Dv MACHINE_ARCH"
267.It Dv MACHINE Ta Dv MACHINE_CPUARCH Ta Dv MACHINE_ARCH
268.It arm64 Ta aarch64 Ta aarch64
269.It amd64 Ta amd64 Ta amd64
270.It arm Ta arm Ta armv7
271.It i386 Ta i386 Ta i386
272.It powerpc Ta powerpc Ta powerpc, powerpcspe, powerpc64, powerpc64le
273.It riscv Ta riscv Ta riscv64
274.El
275.Ss Predefined Macros
276The compiler provides a number of predefined macros.
277Some of these provide architecture-specific details and are explained below.
278Other macros, including those required by the language standard, are not
279included here.
280.Pp
281The full set of predefined macros can be obtained with this command:
282.Bd -literal -offset indent
283cc -x c -dM -E /dev/null
284.Ed
285.Pp
286Common type size and endianness macros:
287.Bl -column -offset indent "BYTE_ORDER" "Meaning"
288.It Sy Macro Ta Sy Meaning
289.It Dv __LP64__ Ta 64-bit (8-byte) long and pointer, 32-bit (4-byte) int
290.It Dv __ILP32__ Ta 32-bit (4-byte) int, long and pointer
291.It Dv BYTE_ORDER Ta Either Dv BIG_ENDIAN or Dv LITTLE_ENDIAN .
292.Dv PDP11_ENDIAN
293is not used on
294.Fx .
295.El
296.Pp
297Architecture-specific macros:
298.Bl -column -offset indent "Architecture" "Predefined macros"
299.It Sy Architecture Ta Sy Predefined macros
300.It aarch64     Ta Dv __aarch64__
301.It amd64       Ta Dv __amd64__ , Dv __x86_64__
302.It armv7       Ta Dv __arm__ , Dv __ARM_ARCH >= 7
303.It i386        Ta Dv __i386__
304.It powerpc     Ta Dv __powerpc__
305.It powerpcspe  Ta Dv __powerpc__ , Dv __SPE__
306.It powerpc64   Ta Dv __powerpc__ , Dv __powerpc64__
307.It powerpc64le Ta Dv __powerpc__ , Dv __powerpc64__
308.It riscv64     Ta Dv __riscv , Dv __riscv_xlen == 64
309.El
310.Pp
311Compilers may define additional variants of architecture-specific macros.
312The macros above are preferred for use in
313.Fx .
314.Ss Important Xr make 1 variables
315Most of the externally settable variables are defined in the
316.Xr build 7
317man page.
318These variables are not otherwise documented and are used extensively
319in the build system.
320.Bl -tag -width "MACHINE_CPUARCH"
321.It Dv MACHINE
322Represents the hardware platform.
323This is the same as the native platform's
324.Xr uname 1
325.Fl m
326output.
327It defines both the userland / kernel interface, as well as the
328bootloader / kernel interface.
329It should only be used in these contexts.
330Each CPU architecture may have multiple hardware platforms it supports
331where
332.Dv MACHINE
333differs among them.
334It is used to collect together all the files from
335.Xr config 8
336to build the kernel.
337It is often the same as
338.Dv MACHINE_ARCH
339just as one CPU architecture can be implemented by many different
340hardware platforms, one hardware platform may support multiple CPU
341architecture family members, though with different binaries.
342For example,
343.Dv MACHINE
344of i386 supported the IBM-AT hardware platform while the
345.Dv MACHINE
346of pc98 supported the Japanese company NEC's PC-9801 and PC-9821
347hardware platforms.
348Both of these hardware platforms supported only the
349.Dv MACHINE_ARCH
350of i386 where they shared a common ABI, except for certain kernel /
351userland interfaces relating to underlying hardware platform
352differences in bus architecture, device enumeration and boot interface.
353Generally,
354.Dv MACHINE
355should only be used in src/sys and src/stand or in system imagers or
356installers.
357.It Dv MACHINE_ARCH
358Represents the CPU processor architecture.
359This is the same as the native platforms
360.Xr uname 1
361.Fl p
362output.
363It defines the CPU instruction family supported.
364It may also encode a variation in the byte ordering of multi-byte
365integers (endian).
366It may also encode a variation in the size of the integer or pointer.
367It may also encode a ISA revision.
368It may also encode hard versus soft floating point ABI and usage.
369It may also encode a variant ABI when the other factors do not
370uniquely define the ABI.
371It, along with
372.Dv MACHINE ,
373defines the ABI used by the system.
374Generally, the plain CPU name specifies the most common (or at least
375first) variant of the CPU.
376This is why powerpc and powerpc64 imply 'big endian' while armv7 and aarch64
377imply little endian.
378If we ever were to support the so-called x32 ABI (using 32-bit
379pointers on the amd64 architecture), it would most likely be encoded
380as amd64-x32.
381It is unfortunate that amd64 specifies the 64-bit evolution of the x86 platform
382(it matches the 'first rule') as almost everybody else uses x86_64.
383The
384.Fx
385port was so early, it predated processor name standardization after Intel joined
386the market.
387At the time, each OS selected its own conventions.
388Backwards compatibility means it is not easy to change to the consensus name.
389.It Dv MACHINE_CPUARCH
390Represents the source location for a given
391.Dv MACHINE_ARCH .
392It is generally the common prefix for all the MACHINE_ARCH that
393share the same implementation, though 'riscv' breaks this rule.
394While amd64 and i386 are closely related, MACHINE_CPUARCH is not x86
395for them.
396The
397.Fx
398source base supports amd64 and i386 with two
399distinct source bases living in subdirectories named amd64 and i386
400(though behind the scenes there's some sharing that fits into this
401framework).
402.It Dv CPUTYPE
403Sets the flavor of
404.Dv MACHINE_ARCH
405to build.
406It is used to optimize the build for a specific CPU / core that the
407binaries run on.
408Generally, this does not change the ABI, though it can be a fine line
409between optimization for specific cases.
410.It Dv TARGET
411Used to set
412.Dv MACHINE
413in the top level Makefile for cross building.
414Unused outside of that scope.
415It is not passed down to the rest of the build.
416Makefiles outside of the top level should not use it at all (though
417some have their own private copy for hysterical raisons).
418.It Dv TARGET_ARCH
419Used to set
420.Dv MACHINE_ARCH
421by the top level Makefile for cross building.
422Like
423.Dv TARGET ,
424it is unused outside of that scope.
425.El
426.Sh SEE ALSO
427.Xr src.conf 5 ,
428.Xr build 7 ,
429.Xr simd 7
430.Sh HISTORY
431An
432.Nm
433manual page appeared in
434.Fx 11.1 .
435