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