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