Skip to main content

rustc_target/spec/targets/
x86_64_unknown_uefi.rs

1// This defines the amd64 target for UEFI systems as described in the UEFI specification. See the
2// uefi-base module for generic UEFI options. On x86_64 systems (mostly called "x64" in the spec)
3// UEFI systems always run in long-mode, have the interrupt-controller pre-configured and force a
4// single-CPU execution.
5// The win64 ABI is used. It differs from the sysv64 ABI, so we must use an LLVM target that
6// follows it: "x86_64-unknown-uefi" with LLVM 24 and later, "x86_64-unknown-windows" with LLVM 23
7// and earlier.
8
9use rustc_abi::{CanonAbi, X86Call};
10
11use crate::spec::{Arch, RustcAbi, Target, TargetMetadata, base};
12
13pub(crate) fn target() -> Target {
14    let mut base = base::uefi_msvc::opts();
15    base.cpu = "x86-64".into();
16    base.plt_by_default = false;
17    base.max_atomic_width = Some(64);
18    base.entry_abi = CanonAbi::X86(X86Call::Win64);
19
20    // We disable MMX and SSE for now, even though UEFI allows using them. Problem is, you have to
21    // enable these CPU features explicitly before their first use, otherwise their instructions
22    // will trigger an exception. Rust does not inject any code that enables AVX/MMX/SSE
23    // instruction sets, so this must be done by the firmware. However, existing firmware is known
24    // to leave these uninitialized, thus triggering exceptions if we make use of them. Which is
25    // why we avoid them and instead use soft-floats. This is also what GRUB and friends did so
26    // far.
27    //
28    // If you initialize FP units yourself, you can override these flags with custom linker
29    // arguments, thus giving you access to full MMX/SSE acceleration.
30    base.features = "-mmx,-sse,+soft-float".into();
31    base.rustc_abi = Some(RustcAbi::Softfloat);
32
33    Target {
34        llvm_target: "x86_64-unknown-uefi".into(),
35        metadata: TargetMetadata {
36            description: Some("64-bit UEFI".into()),
37            tier: Some(2),
38            host_tools: Some(false),
39            std: None, // ?
40        },
41        pointer_width: 64,
42        data_layout:
43            "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
44        arch: Arch::X86_64,
45
46        options: base,
47    }
48}