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