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