xref: /freebsd/share/man/man7/arch.7 (revision 4b9d6057)
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 September 2, 2023
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 armv6       Ta 10.0
91.It armv7       Ta 12.0
92.It i386        Ta 1.0
93.It powerpc     Ta 6.0
94.It powerpcspe  Ta 12.0
95.It powerpc64   Ta 9.0
96.It powerpc64le Ta 13.0
97.It riscv64     Ta 12.0
98.El
99.Pp
100Discontinued architectures are shown in the following table.
101.Bl -column -offset indent "Architecture" "Initial Release" "Final Release"
102.It Sy Architecture Ta Sy Initial Release Ta Sy Final Release
103.It alpha       Ta 3.2   Ta 6.4
104.It arm         Ta 6.0   Ta 12.4
105.It armeb       Ta 8.0   Ta 11.4
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 armv6/armv7
160.El
161.Pp
162.Dv aarch64
163will support execution of
164.Dv armv6
165or
166.Dv armv7
167binaries if the CPU implements
168.Dv AArch32
169execution state, however older
170.Dv armv4
171and
172.Dv armv5
173binaries aren't supported.
174.Pp
175On all supported architectures:
176.Bl -column -offset -indent "long long" "Size"
177.It Sy Type Ta Sy Size
178.It short Ta 2
179.It int Ta 4
180.It long Ta sizeof(void*)
181.It long long Ta 8
182.It float Ta 4
183.It double Ta 8
184.El
185.Pp
186Integers are represented in two's complement.
187Alignment of integer and pointer types is natural, that is,
188the address of the variable must be congruent to zero modulo the type size.
189Most ILP32 ABIs, except
190.Dv arm ,
191require only 4-byte alignment for 64-bit integers.
192.Pp
193Machine-dependent type sizes:
194.Bl -column -offset indent "Architecture" "void *" "long double" "time_t"
195.It Sy Architecture Ta Sy void * Ta Sy long double Ta Sy time_t
196.It aarch64     Ta 8 Ta 16 Ta 8
197.It amd64       Ta 8 Ta 16 Ta 8
198.It armv6       Ta 4 Ta  8 Ta 8
199.It armv7       Ta 4 Ta  8 Ta 8
200.It i386        Ta 4 Ta 12 Ta 4
201.It powerpc     Ta 4 Ta  8 Ta 8
202.It powerpcspe  Ta 4 Ta  8 Ta 8
203.It powerpc64   Ta 8 Ta  8 Ta 8
204.It powerpc64le Ta 8 Ta  8 Ta 8
205.It riscv64     Ta 8 Ta 16 Ta 8
206.El
207.Pp
208.Sy time_t
209is 8 bytes on all supported architectures except i386.
210.Ss Endianness and Char Signedness
211.Bl -column -offset indent "Architecture" "Endianness" "char Signedness"
212.It Sy Architecture Ta Sy Endianness Ta Sy char Signedness
213.It aarch64     Ta little Ta unsigned
214.It amd64       Ta little Ta   signed
215.It armv6       Ta little Ta unsigned
216.It armv7       Ta little Ta unsigned
217.It i386        Ta little Ta   signed
218.It powerpc     Ta big    Ta unsigned
219.It powerpcspe  Ta big    Ta unsigned
220.It powerpc64   Ta big    Ta unsigned
221.It powerpc64le Ta little Ta unsigned
222.It riscv64     Ta little Ta   signed
223.El
224.Ss Page Size
225.Bl -column -offset indent "Architecture" "Page Sizes"
226.It Sy Architecture Ta Sy Page Sizes
227.It aarch64     Ta 4K, 2M, 1G
228.It amd64       Ta 4K, 2M, 1G
229.It armv6       Ta 4K, 1M
230.It armv7       Ta 4K, 1M
231.It i386        Ta 4K, 2M (PAE), 4M
232.It powerpc     Ta 4K
233.It powerpcspe  Ta 4K
234.It powerpc64   Ta 4K
235.It powerpc64le Ta 4K
236.It riscv64     Ta 4K, 2M, 1G
237.El
238.Ss Floating Point
239.Bl -column -offset indent "Architecture" "float, double" "long double"
240.It Sy Architecture Ta Sy float, double Ta Sy long double
241.It aarch64     Ta hard Ta soft, quad precision
242.It amd64       Ta hard Ta hard, 80 bit
243.It armv6       Ta hard Ta hard, double precision
244.It armv7       Ta hard Ta hard, double precision
245.It i386        Ta hard Ta hard, 80 bit
246.It powerpc     Ta hard Ta hard, double precision
247.It powerpcspe  Ta hard Ta hard, double precision
248.It powerpc64   Ta hard Ta hard, double precision
249.It powerpc64le Ta hard Ta hard, double precision
250.It riscv64     Ta hard Ta hard, quad precision
251.El
252.Ss Default Tool Chain
253.Fx
254uses
255.Xr clang 1
256as the default compiler on all supported CPU architectures,
257LLVM's
258.Xr ld.lld 1
259as the default linker, and
260ELF Tool Chain binary utilities such as
261.Xr objcopy 1
262and
263.Xr readelf 1 .
264.Ss MACHINE_ARCH vs MACHINE_CPUARCH vs MACHINE
265.Dv MACHINE_CPUARCH
266should be preferred in Makefiles when the generic
267architecture is being tested.
268.Dv MACHINE_ARCH
269should be preferred when there is something specific to a particular type of
270architecture where there is a choice of many, or could be a choice of many.
271Use
272.Dv MACHINE
273when referring to the kernel, interfaces dependent on a specific type of kernel
274or similar things like boot sequences.
275.Bl -column -offset indent "Dv MACHINE" "Dv MACHINE_CPUARCH" "Dv MACHINE_ARCH"
276.It Dv MACHINE Ta Dv MACHINE_CPUARCH Ta Dv MACHINE_ARCH
277.It arm64 Ta aarch64 Ta aarch64
278.It amd64 Ta amd64 Ta amd64
279.It arm Ta arm Ta armv6, armv7
280.It i386 Ta i386 Ta i386
281.It powerpc Ta powerpc Ta powerpc, powerpcspe, powerpc64, powerpc64le
282.It riscv Ta riscv Ta riscv64
283.El
284.Ss Predefined Macros
285The compiler provides a number of predefined macros.
286Some of these provide architecture-specific details and are explained below.
287Other macros, including those required by the language standard, are not
288included here.
289.Pp
290The full set of predefined macros can be obtained with this command:
291.Bd -literal -offset indent
292cc -x c -dM -E /dev/null
293.Ed
294.Pp
295Common type size and endianness macros:
296.Bl -column -offset indent "BYTE_ORDER" "Meaning"
297.It Sy Macro Ta Sy Meaning
298.It Dv __LP64__ Ta 64-bit (8-byte) long and pointer, 32-bit (4-byte) int
299.It Dv __ILP32__ Ta 32-bit (4-byte) int, long and pointer
300.It Dv BYTE_ORDER Ta Either Dv BIG_ENDIAN or Dv LITTLE_ENDIAN .
301.Dv PDP11_ENDIAN
302is not used on
303.Fx .
304.El
305.Pp
306Architecture-specific macros:
307.Bl -column -offset indent "Architecture" "Predefined macros"
308.It Sy Architecture Ta Sy Predefined macros
309.It aarch64     Ta Dv __aarch64__
310.It amd64       Ta Dv __amd64__ , Dv __x86_64__
311.It armv6       Ta Dv __arm__ , Dv __ARM_ARCH >= 6
312.It armv7       Ta Dv __arm__ , Dv __ARM_ARCH >= 7
313.It i386        Ta Dv __i386__
314.It powerpc     Ta Dv __powerpc__
315.It powerpcspe  Ta Dv __powerpc__ , Dv __SPE__
316.It powerpc64   Ta Dv __powerpc__ , Dv __powerpc64__
317.It powerpc64le Ta Dv __powerpc__ , Dv __powerpc64__
318.It riscv64     Ta Dv __riscv , Dv __riscv_xlen == 64
319.El
320.Pp
321Compilers may define additional variants of architecture-specific macros.
322The macros above are preferred for use in
323.Fx .
324.Ss Important Xr make 1 variables
325Most of the externally settable variables are defined in the
326.Xr build 7
327man page.
328These variables are not otherwise documented and are used extensively
329in the build system.
330.Bl -tag -width "MACHINE_CPUARCH"
331.It Dv MACHINE
332Represents the hardware platform.
333This is the same as the native platform's
334.Xr uname 1
335.Fl m
336output.
337It defines both the userland / kernel interface, as well as the
338bootloader / kernel interface.
339It should only be used in these contexts.
340Each CPU architecture may have multiple hardware platforms it supports
341where
342.Dv MACHINE
343differs among them.
344It is used to collect together all the files from
345.Xr config 8
346to build the kernel.
347It is often the same as
348.Dv MACHINE_ARCH
349just as one CPU architecture can be implemented by many different
350hardware platforms, one hardware platform may support multiple CPU
351architecture family members, though with different binaries.
352For example,
353.Dv MACHINE
354of i386 supported the IBM-AT hardware platform while the
355.Dv MACHINE
356of pc98 supported the Japanese company NEC's PC-9801 and PC-9821
357hardware platforms.
358Both of these hardware platforms supported only the
359.Dv MACHINE_ARCH
360of i386 where they shared a common ABI, except for certain kernel /
361userland interfaces relating to underlying hardware platform
362differences in bus architecture, device enumeration and boot interface.
363Generally,
364.Dv MACHINE
365should only be used in src/sys and src/stand or in system imagers or
366installers.
367.It Dv MACHINE_ARCH
368Represents the CPU processor architecture.
369This is the same as the native platforms
370.Xr uname 1
371.Fl p
372output.
373It defines the CPU instruction family supported.
374It may also encode a variation in the byte ordering of multi-byte
375integers (endian).
376It may also encode a variation in the size of the integer or pointer.
377It may also encode a ISA revision.
378It may also encode hard versus soft floating point ABI and usage.
379It may also encode a variant ABI when the other factors do not
380uniquely define the ABI.
381It, along with
382.Dv MACHINE ,
383defines the ABI used by the system.
384Generally, the plain CPU name specifies the most common (or at least
385first) variant of the CPU.
386This is why powerpc and powerpc64 imply 'big endian' while 'armv6' and 'armv7'
387imply little endian.
388If we ever were to support the so-called x32 ABI (using 32-bit
389pointers on the amd64 architecture), it would most likely be encoded
390as amd64-x32.
391It is unfortunate that amd64 specifies the 64-bit evolution of the x86
392platform (it matches the 'first rule') as everybody else uses x86_64.
393There is no standard name for the processor: each OS selects its own
394conventions.
395.It Dv MACHINE_CPUARCH
396Represents the source location for a given
397.Dv MACHINE_ARCH .
398It is generally the common prefix for all the MACHINE_ARCH that
399share the same implementation, though 'riscv' breaks this rule.
400While amd64 and i386 are closely related, MACHINE_CPUARCH is not x86
401for them.
402The
403.Fx
404source base supports amd64 and i386 with two
405distinct source bases living in subdirectories named amd64 and i386
406(though behind the scenes there's some sharing that fits into this
407framework).
408.It Dv CPUTYPE
409Sets the flavor of
410.Dv MACHINE_ARCH
411to build.
412It is used to optimize the build for a specific CPU / core that the
413binaries run on.
414Generally, this does not change the ABI, though it can be a fine line
415between optimization for specific cases.
416.It Dv TARGET
417Used to set
418.Dv MACHINE
419in the top level Makefile for cross building.
420Unused outside of that scope.
421It is not passed down to the rest of the build.
422Makefiles outside of the top level should not use it at all (though
423some have their own private copy for hysterical raisons).
424.It Dv TARGET_ARCH
425Used to set
426.Dv MACHINE_ARCH
427by the top level Makefile for cross building.
428Like
429.Dv TARGET ,
430it is unused outside of that scope.
431.El
432.Sh SEE ALSO
433.Xr src.conf 5 ,
434.Xr build 7 ,
435.Xr simd 7
436.Sh HISTORY
437An
438.Nm
439manual page appeared in
440.Fx 11.1 .
441