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