xref: /freebsd/share/man/man7/arch.7 (revision 9978553d0199e7ec0bdd1c44fc7f6c7b0c11e43b)
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 November 27, 2025
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 13.0
46and later, unless otherwise noted.
47.Pp
48.Fx
49uses a flat address space.
50Variables of types
51.Vt unsigned long ,
52.Vt ptraddr_t ,
53and
54.Vt size_t
55have 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 as these types are the only integer types where the
63C standard guarantees that a pointer may be cast to it and then cast back
64to the original type.
65On CHERI systems,
66.Vt uintptr_t
67and
68.Vt intptr_t
69are defined as
70.Vt __uintcap_t
71and
72.Vt __intcap_t
73which represent capabilities that can be manipulated by integer operations.
74Pointers should not be cast to
75.Vt long ,
76.Vt ptrdiff_t ,
77or
78.Vt size_t
79if they will later be cast back to a pointer that is expected to be
80dereferenceable as they remain bare integer types on all architectures.
81.Pp
82On some architectures, e.g.,
83AIM variants of
84.Dv powerpc64 ,
85the kernel uses a separate address space.
86On other architectures, kernel and a user mode process share a
87single address space.
88The kernel is located at the highest addresses.
89.Pp
90On each architecture, the main user mode thread's stack starts near
91the highest user address and grows down.
92.Pp
93.Fx
94architecture support varies by release.
95This table shows currently supported CPU architectures along with the first
96.Fx
97release to support each architecture.
98.Bl -column -offset indent "Architecture" "Initial Release"
99.It Sy Architecture Ta Sy Initial Release
100.It aarch64     Ta 11.0
101.It aarch64c    Ta 16.0 (planned)
102.It amd64       Ta 5.1
103.It armv7       Ta 12.0
104.It powerpc64   Ta 9.0
105.It powerpc64le Ta 13.0
106.It riscv64     Ta 12.0
107.It riscv64c    Ta 16.0 (planned)
108.El
109.Pp
110Discontinued architectures are shown in the following table.
111.Bl -column -offset indent "Architecture" "Initial Release" "Final Release"
112.It Sy Architecture Ta Sy Initial Release Ta Sy Final Release
113.It alpha       Ta 3.2   Ta 6.4
114.It arm         Ta 6.0   Ta 12.4
115.It armeb       Ta 8.0   Ta 11.4
116.It armv6       Ta 10.0  Ta 14.x
117.It ia64        Ta 5.0   Ta 10.4
118.It i386        Ta 1.0   Ta 14.x
119.It mips        Ta 8.0   Ta 13.5
120.It mipsel      Ta 9.0   Ta 13.5
121.It mipselhf    Ta 12.0  Ta 13.5
122.It mipshf      Ta 12.0  Ta 13.5
123.It mipsn32     Ta 9.0   Ta 13.5
124.It mips64      Ta 9.0   Ta 13.5
125.It mips64el    Ta 9.0   Ta 13.5
126.It mips64elhf  Ta 12.0  Ta 13.5
127.It mips64hf    Ta 12.0  Ta 13.5
128.It pc98        Ta 2.2   Ta 11.4
129.It powerpc     Ta 6.0   Ta 14.x
130.It powerpcspe  Ta 12.0  Ta 14.x
131.It riscv64sf   Ta 12.0  Ta 13.5
132.It sparc64     Ta 5.0   Ta 12.4
133.El
134.Ss Type sizes
135All
136.Fx
137architectures use some variant of the ELF (see
138.Xr elf 5 )
139.Sy Application Binary Interface
140(ABI) for the machine processor.
141Supported ABIs can be divided into three main groups:
142.Bl -tag -width "Dv L64PC128"
143.It Dv ILP32
144.Vt int ,
145.Vt intptr_t ,
146.Vt long ,
147and
148.Vt void *
149types machine representations all have 4-byte size.
150.It Dv LP64
151.Vt int
152type machine representation uses 4 bytes,
153while
154.Vt intptr_t ,
155.Vt long ,
156and
157.Vt void *
158are 8 bytes.
159.It Dv L64PC128
160.Vt int
161type machine representation uses 4 bytes.
162.Vt long
163type machine representation uses 8 bytes.
164.Vt intptr_t
165and
166.Vt void *
167are 16 byte capabilities.
168.El
169.Pp
170Some machines support more than one
171.Fx
172ABI.
173Typically these are 64-bit machines, where the
174.Dq native
175.Dv LP64
176execution environment is accompanied by the
177.Dq legacy
178.Dv ILP32
179environment, which was the historical 32-bit predecessor for 64-bit evolution.
180Examples are:
181.Bl -column -offset indent "powerpc64" "ILP32 counterpart"
182.It Sy LP64        Ta Sy ILP32 counterpart
183.It Dv amd64       Ta Dv i386
184.It Dv powerpc64   Ta Dv powerpc
185.It Dv aarch64     Ta Dv armv7
186.El
187.Pp
188.Dv aarch64
189will support execution of
190.Dv armv7
191binaries if the CPU implements
192.Dv AArch32
193execution state.
194Binaries targeting
195.Dv armv6
196and earlier are no longer supported by
197.Fx .
198.Pp
199Architectures with 128-bit capabilities support both a
200.Dq native
201.Dv L64PC128
202execution environment and a
203.Dv LP64
204environment:
205.Bl -column -offset indent "aarch64c" "LP64 counterpart"
206.It Sy L64PC128    Ta Sy LP64 counterpart
207.It Dv aarch64c    Ta Dv aarch64
208.It Dv riscv64c    Ta Dv riscv64
209.El
210.Pp
211On all supported architectures:
212.Bl -column -offset indent "long long" "Size"
213.It Sy Type Ta Sy Size
214.It short Ta 2
215.It int Ta 4
216.It long long Ta 8
217.It float Ta 4
218.It double Ta 8
219.El
220.Pp
221Integers are represented in two's complement.
222Alignment of integer and pointer types is natural, that is,
223the address of the variable must be congruent to zero modulo the type size.
224The sole exception is that
225.Dv i386
226requires only 4-byte alignment for 64-bit integers.
227.Pp
228Machine-dependent type sizes:
229.Bl -column -offset indent "Architecture" "long" "void *" "long double" "time_t"
230.It Sy Architecture Ta Sy long Ta Sy void * Ta Sy long double Ta Sy time_t
231.It aarch64     Ta 8 Ta  8 Ta 16 Ta 8
232.It aarch64c    Ta 8 Ta 16 Ta 16 Ta 8
233.It amd64       Ta 8 Ta  8 Ta 16 Ta 8
234.It armv7       Ta 4 Ta  4 Ta  8 Ta 8
235.It i386        Ta 4 Ta  4 Ta 12 Ta 4
236.It powerpc     Ta 4 Ta  4 Ta  8 Ta 8
237.It powerpcspe  Ta 4 Ta  4 Ta  8 Ta 8
238.It powerpc64   Ta 8 Ta  8 Ta  8 Ta 8
239.It powerpc64le Ta 8 Ta  8 Ta  8 Ta 8
240.It riscv64     Ta 8 Ta  8 Ta 16 Ta 8
241.It riscv64c    Ta 8 Ta 16 Ta 16 Ta 8
242.El
243.Pp
244.Sy time_t
245is 8 bytes on all supported architectures except i386.
246.Ss Endianness and Char Signedness
247.Bl -column -offset indent "Architecture" "Endianness" "char Signedness"
248.It Sy Architecture Ta Sy Endianness Ta Sy char Signedness
249.It aarch64     Ta little Ta unsigned
250.It aarch64c    Ta little Ta unsigned
251.It amd64       Ta little Ta   signed
252.It armv7       Ta little Ta unsigned
253.It i386        Ta little Ta   signed
254.It powerpc     Ta big    Ta unsigned
255.It powerpcspe  Ta big    Ta unsigned
256.It powerpc64   Ta big    Ta unsigned
257.It powerpc64le Ta little Ta unsigned
258.It riscv64     Ta little Ta   signed
259.It riscv64c    Ta little Ta   signed
260.El
261.Ss Page Size
262.Bl -column -offset indent "Architecture" "Page Sizes"
263.It Sy Architecture Ta Sy Page Sizes
264.It aarch64     Ta 4K, 64K, 2M, 1G
265.It aarch64c    Ta 4K, 64K, 2M, 1G
266.It amd64       Ta 4K, 2M, 1G
267.It armv7       Ta 4K, 1M
268.It i386        Ta 4K, 2M (PAE), 4M
269.It powerpc     Ta 4K
270.It powerpcspe  Ta 4K
271.It powerpc64   Ta 4K
272.It powerpc64le Ta 4K
273.It riscv64     Ta 4K, 2M, 1G
274.It riscv64c    Ta 4K, 2M, 1G
275.El
276.Ss User Address Space Layout
277.Bl -column -offset indent "riscv64 (Sv48)" "0x0001000000000000" "NNNU"
278.It Sy Architecture Ta Sy Maximum Address Ta Sy Address Space Size
279.It aarch64        Ta 0x0001000000000000 Ta 256TiB
280.It aarch64c       Ta 0x0001000000000000 Ta 256TiB
281.It amd64 (LA48)   Ta 0x0000800000000000 Ta 128TiB
282.It amd64 (LA57)   Ta 0x0100000000000000 Ta 64PiB
283.It armv7          Ta 0xbfc00000         Ta 3GiB
284.It i386           Ta 0xffc00000         Ta 4GiB
285.It powerpc        Ta 0xfffff000         Ta 4GiB
286.It powerpcspe     Ta 0x7ffff000         Ta 2GiB
287.It powerpc64      Ta 0x000fffffc0000000 Ta 4PiB
288.It powerpc64le    Ta 0x000fffffc0000000 Ta 4PiB
289.It riscv64 (Sv39) Ta 0x0000004000000000 Ta 256GiB
290.It riscv64c (Sv39) Ta 0x0000004000000000 Ta 256GiB
291.It riscv64 (Sv48) Ta 0x0000800000000000 Ta 128TiB
292.It riscv64c (Sv48) Ta 0x0000800000000000 Ta 128TiB
293.El
294.Pp
295The layout of a process' address space can be queried via the
296.Dv KERN_PROC_VM_LAYOUT
297.Xr sysctl 3
298MIB.
299.Pp
300Historically, amd64 CPUs were limited to a 48-bit virtual address space.
301Newer CPUs support 5-level page tables, which extend the significant bits of
302addresses to 57 bits (LA57 mode).
303The address space layout is determined by the CPU's support for LA57.
304Setting the
305.Sy vm.pmap.la57
306tunable to 0 forces the system into 4-level paging mode, even on hardware that
307supports 5-level paging.
308In this mode, all processes get a 48-bit address space.
309The
310.Sy vm.pmap.prefer_la48_uva
311tunable determines whether processes running on a LA57 system are limited to
312a 48-bit address space by default.
313Some applications make use of unused upper bits in pointer values to store
314information, and thus implicitly assume they are running in LA48 mode.
315To avoid breaking compatibility, all processes run in LA48 mode by default.
316The
317.Xr elfctl 1
318utility can be used to request LA48 or LA57 mode for specific executables.
319Similarly,
320.Xr proccontrol 1
321can be used to configure the address space layout when executing a process.
322.Pp
323The RISC-V specification permits 3-level (Sv39), 4-level (Sv48), and
3245-level (Sv57) page tables.
325Hardware is only required to implement Sv39; implementations which support
326Sv48 must also support Sv39, and implementations which support Sv57 must also
327support Sv48.
328The
329.Sy vm.pmap.mode
330tunable can be used to select the layout.
331.Fx
332currently supports Sv39 and Sv48 and defaults to using Sv39.
333.Ss Floating Point
334.Bl -column -offset indent "Architecture" "float, double" "long double"
335.It Sy Architecture Ta Sy float, double Ta Sy long double
336.It aarch64     Ta hard Ta soft, quad precision
337.It aarch64c    Ta hard Ta soft, quad precision
338.It amd64       Ta hard Ta hard, 80 bit
339.It armv7       Ta hard Ta hard, double precision
340.It i386        Ta hard Ta hard, 80 bit
341.It powerpc     Ta hard Ta hard, double precision
342.It powerpcspe  Ta hard Ta hard, double precision
343.It powerpc64   Ta hard Ta hard, double precision
344.It powerpc64le Ta hard Ta hard, double precision
345.It riscv64     Ta hard Ta hard, quad precision
346.It riscv64c    Ta hard Ta hard, quad precision
347.El
348.Ss Default Tool Chain
349.Fx
350uses
351.Xr clang 1
352as the default compiler on all supported CPU architectures,
353LLVM's
354.Xr ld.lld 1
355as the default linker, and
356LLVM binary utilities such as
357.Xr objcopy 1
358and
359.Xr readelf 1 .
360.Ss MACHINE_ARCH vs MACHINE_CPUARCH vs MACHINE
361.Dv MACHINE_CPUARCH
362should be preferred in Makefiles when the generic
363architecture is being tested.
364.Dv MACHINE_ARCH
365should be preferred when there is something specific to a particular type of
366architecture where there is a choice of many, or could be a choice of many.
367Use
368.Dv MACHINE
369when referring to the kernel, interfaces dependent on a specific type of kernel
370or similar things like boot sequences.
371.Bl -column -offset indent "Dv MACHINE" "Dv MACHINE_CPUARCH" "Dv MACHINE_ARCH"
372.It Dv MACHINE Ta Dv MACHINE_CPUARCH Ta Dv MACHINE_ARCH
373.It arm64 Ta aarch64 Ta aarch64, aarch64c
374.It amd64 Ta amd64 Ta amd64
375.It arm Ta arm Ta armv7
376.It i386 Ta i386 Ta i386
377.It powerpc Ta powerpc Ta powerpc, powerpcspe, powerpc64, powerpc64le
378.It riscv Ta riscv Ta riscv64, riscv64c
379.El
380.Ss Predefined Macros
381The compiler provides a number of predefined macros.
382Some of these provide architecture-specific details and are explained below.
383Other macros, including those required by the language standard, are not
384included here.
385.Pp
386The full set of predefined macros can be obtained with this command:
387.Bd -literal -offset indent
388cc -x c -dM -E /dev/null
389.Ed
390.Pp
391Common type size and endianness macros:
392.Bl -column -offset indent "__SIZEOF_POINTER__" "Meaning"
393.It Sy Macro Ta Sy Meaning
394.It Dv __SIZEOF_LONG__ Ta size in bytes of long
395.It Dv __SIZEOF_POINTER__ Ta size in bytes of intptr_t and pointers
396.It Dv __SIZEOF_SIZE_T__ Ta size in bytes of size_t
397.It Dv __LP64__ Ta 64-bit (8-byte) long and pointer, 32-bit (4-byte) int
398.It Dv __ILP32__ Ta 32-bit (4-byte) int, long and pointer
399.It Dv __CHERI__ Ta 128-bit (16-byte) capability pointer, 64-bit (8-byte) long
400.It Dv BYTE_ORDER Ta Either Dv BIG_ENDIAN or Dv LITTLE_ENDIAN .
401.El
402.Pp
403Because systems were historically either
404.Dv __ILP32__
405or
406.Dv __LP64__
407it has been common for programmers to test only one and assume the other
408one in an else branch.
409With the arrival of CHERI architectures, this is no longer the case.
410.Dv __SIZEOF_*__
411macros should be used instead.
412New uses of
413.Dv __ILP32__
414and
415.Dv __LP64__
416should be avoided.
417Compilers for CHERI targets do not define
418.Dv __LP64__
419as their pointers are 128-bit capabilities.
420.Pp
421Architecture-specific macros:
422.Bl -column -offset indent "Architecture" "Predefined macros"
423.It Sy Architecture Ta Sy Predefined macros
424.It aarch64     Ta Dv __aarch64__
425.It aarch64c    Ta Dv __aarch64__ , Dv __CHERI__
426.It amd64       Ta Dv __amd64__ , Dv __x86_64__
427.It armv7       Ta Dv __arm__ , Dv __ARM_ARCH >= 7
428.It i386        Ta Dv __i386__
429.It powerpc     Ta Dv __powerpc__
430.It powerpcspe  Ta Dv __powerpc__ , Dv __SPE__
431.It powerpc64   Ta Dv __powerpc__ , Dv __powerpc64__
432.It powerpc64le Ta Dv __powerpc__ , Dv __powerpc64__
433.It riscv64     Ta Dv __riscv , Dv __riscv_xlen == 64
434.It riscv64c    Ta Dv __riscv , Dv __riscv_xlen == 64 , Dv __CHERI__
435.El
436.Pp
437Compilers may define additional variants of architecture-specific macros.
438The macros above are preferred for use in
439.Fx .
440.Ss Important Xr make 1 variables
441Most of the externally settable variables are defined in the
442.Xr build 7
443man page.
444These variables are not otherwise documented and are used extensively
445in the build system.
446.Bl -tag -width "MACHINE_CPUARCH"
447.It Dv MACHINE
448Represents the hardware platform.
449This is the same as the native platform's
450.Xr uname 1
451.Fl m
452output.
453It defines both the userland / kernel interface, as well as the
454bootloader / kernel interface.
455It should only be used in these contexts.
456Each CPU architecture may have multiple hardware platforms it supports
457where
458.Dv MACHINE
459differs among them.
460It is used to collect together all the files from
461.Xr config 8
462to build the kernel.
463It is often the same as
464.Dv MACHINE_ARCH
465just as one CPU architecture can be implemented by many different
466hardware platforms, one hardware platform may support multiple CPU
467architecture family members, though with different binaries.
468For example,
469.Dv MACHINE
470of i386 supported the IBM-AT hardware platform while the
471.Dv MACHINE
472of pc98 supported the Japanese company NEC's PC-9801 and PC-9821
473hardware platforms.
474Both of these hardware platforms supported only the
475.Dv MACHINE_ARCH
476of i386 where they shared a common ABI, except for certain kernel /
477userland interfaces relating to underlying hardware platform
478differences in bus architecture, device enumeration and boot interface.
479Generally,
480.Dv MACHINE
481should only be used in src/sys and src/stand or in system imagers or
482installers.
483.It Dv MACHINE_ARCH
484Represents the CPU processor architecture.
485This is the same as the native platforms
486.Xr uname 1
487.Fl p
488output.
489It defines the CPU instruction family supported.
490It may also encode a variation in the byte ordering of multi-byte
491integers (endian).
492It may also encode a variation in the size of the integer or pointer.
493It may also encode a ISA revision.
494It may also encode hard versus soft floating point ABI and usage.
495It may also encode a variant ABI when the other factors do not
496uniquely define the ABI.
497It, along with
498.Dv MACHINE ,
499defines the ABI used by the system.
500Generally, the plain CPU name specifies the most common (or at least
501first) variant of the CPU.
502This is why powerpc and powerpc64 imply 'big endian' while armv7 and aarch64
503imply little endian.
504If we ever were to support the so-called x32 ABI (using 32-bit
505pointers on the amd64 architecture), it would most likely be encoded
506as amd64-x32.
507It is unfortunate that amd64 specifies the 64-bit evolution of the x86 platform
508(it matches the 'first rule') as almost everybody else uses x86_64.
509The
510.Fx
511port was so early, it predated processor name standardization after Intel joined
512the market.
513At the time, each OS selected its own conventions.
514Backwards compatibility means it is not easy to change to the consensus name.
515.It Dv MACHINE_CPUARCH
516Represents the source location for a given
517.Dv MACHINE_ARCH .
518It is generally the common prefix for all the MACHINE_ARCH that
519share the same implementation, though 'riscv' breaks this rule.
520While amd64 and i386 are closely related, MACHINE_CPUARCH is not x86
521for them.
522The
523.Fx
524source base supports amd64 and i386 with two
525distinct source bases living in subdirectories named amd64 and i386
526(though behind the scenes there's some sharing that fits into this
527framework).
528.It Dv CPUTYPE
529Sets the flavor of
530.Dv MACHINE_ARCH
531to build.
532It is used to optimize the build for a specific CPU / core that the
533binaries run on.
534Generally, this does not change the ABI, though it can be a fine line
535between optimization for specific cases.
536.It Dv TARGET
537Used to set
538.Dv MACHINE
539in the top level Makefile for cross building.
540Unused outside of that scope.
541It is not passed down to the rest of the build.
542Makefiles outside of the top level should not use it at all (though
543some have their own private copy for historical reasons).
544.It Dv TARGET_ARCH
545Used to set
546.Dv MACHINE_ARCH
547by the top level Makefile for cross building.
548Like
549.Dv TARGET ,
550it is unused outside of that scope.
551.El
552.Sh SEE ALSO
553.Xr elfctl 1 ,
554.Xr proccontrol 1 ,
555.Xr sysctl 3 ,
556.Xr src.conf 5 ,
557.Xr build 7 ,
558.Xr simd 7
559.Sh HISTORY
560An
561.Nm
562manual page appeared in
563.Fx 11.1 .
564