]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/x86_64_unknown_uefi.rs
Auto merge of #68414 - michaelwoerister:share-drop-glue, r=alexcrichton
[rust.git] / src / librustc_target / spec / 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 a windows target with
6 // LLVM. "x86_64-unknown-windows" is used to get the minimal subset of windows-specific features.
7
8 use crate::spec::{LinkerFlavor, LldFlavor, Target, TargetResult};
9
10 pub fn target() -> TargetResult {
11     let mut base = super::uefi_base::opts();
12     base.cpu = "x86-64".to_string();
13     base.max_atomic_width = Some(64);
14
15     // We disable MMX and SSE for now, even though UEFI allows using them. Problem is, you have to
16     // enable these CPU features explicitly before their first use, otherwise their instructions
17     // will trigger an exception. Rust does not inject any code that enables AVX/MMX/SSE
18     // instruction sets, so this must be done by the firmware. However, existing firmware is known
19     // to leave these uninitialized, thus triggering exceptions if we make use of them. Which is
20     // why we avoid them and instead use soft-floats. This is also what GRUB and friends did so
21     // far.
22     // If you initialize FP units yourself, you can override these flags with custom linker
23     // arguments, thus giving you access to full MMX/SSE acceleration.
24     base.features = "-mmx,-sse,+soft-float".to_string();
25
26     // UEFI systems run without a host OS, hence we cannot assume any code locality. We must tell
27     // LLVM to expect code to reference any address in the address-space. The "large" code-model
28     // places no locality-restrictions, so it fits well here.
29     base.code_model = Some("large".to_string());
30
31     // UEFI mirrors the calling-conventions used on windows. In case of x86-64 this means small
32     // structs will be returned as int. This shouldn't matter much, since the restrictions placed
33     // by the UEFI specifications forbid any ABI to return structures.
34     base.abi_return_struct_as_int = true;
35
36     Ok(Target {
37         llvm_target: "x86_64-unknown-windows".to_string(),
38         target_endian: "little".to_string(),
39         target_pointer_width: "64".to_string(),
40         target_c_int_width: "32".to_string(),
41         data_layout: "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
42             .to_string(),
43         target_os: "uefi".to_string(),
44         target_env: "".to_string(),
45         target_vendor: "unknown".to_string(),
46         arch: "x86_64".to_string(),
47         linker_flavor: LinkerFlavor::Lld(LldFlavor::Link),
48
49         options: base,
50     })
51 }