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