Skip to content

Commit

Permalink
Add Xtensa targets for the ESP-IDF framework
Browse files Browse the repository at this point in the history
  • Loading branch information
imarkov authored and MabezDev committed Feb 22, 2022
1 parent 0798a24 commit 7fbd858
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,12 @@ supported_targets! {
("nvptx64-nvidia-cuda", nvptx64_nvidia_cuda),

("xtensa-esp32-none-elf", xtensa_esp32_none_elf),
("xtensa-esp32-espidf", xtensa_esp32_espidf),
("xtensa-esp32s2-none-elf", xtensa_esp32s2_none_elf),
("xtensa-esp32s2-espidf", xtensa_esp32s2_espidf),
("xtensa-esp8266-none-elf", xtensa_esp8266_none_elf),
("xtensa-esp32s3-none-elf", xtensa_esp32s3_none_elf),
("xtensa-esp32s3-espidf", xtensa_esp32s3_espidf),

("i686-wrs-vxworks", i686_wrs_vxworks),
("x86_64-wrs-vxworks", x86_64_wrs_vxworks),
Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_target/src/spec/xtensa_esp32_espidf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::abi::Endian;

pub fn target() -> Target {
Target {
llvm_target: "xtensa-none-elf".to_string(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".to_string(),
arch: "xtensa".to_string(),

options: TargetOptions {
endian: Endian::Little,
c_int_width: "32".to_string(),
families: vec!["unix".to_string()],
os: "espidf".to_string(),
env: "newlib".to_string(),
vendor: "espressif".to_string(),
linker_flavor: LinkerFlavor::Gcc,

executables: true,
cpu: "esp32".to_string(),
linker: Some("xtensa-esp32-elf-gcc".to_string()),

// The esp32 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
// so we claim a max atomic width of 64 here.
max_atomic_width: Some(64),
atomic_cas: true,

..super::xtensa_base::opts()
},
}
}
40 changes: 40 additions & 0 deletions compiler/rustc_target/src/spec/xtensa_esp32s2_espidf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::abi::Endian;

pub fn target() -> Target {
Target {
llvm_target: "xtensa-none-elf".to_string(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".to_string(),
arch: "xtensa".to_string(),

options: TargetOptions {
endian: Endian::Little,
c_int_width: "32".to_string(),
families: vec!["unix".to_string()],
os: "espidf".to_string(),
env: "newlib".to_string(),
vendor: "espressif".to_string(),
linker_flavor: LinkerFlavor::Gcc,

executables: true,
cpu: "esp32-s2".to_string(),
linker: Some("xtensa-esp32s2-elf-gcc".to_string()),

// See https://github.com/espressif/rust-esp32-example/issues/3#issuecomment-861054477
//
// Unlike the original ESP32 chip, ESP32-S2 does not really support atomics.
// If the missing hardware instruction ends up being emulated in ESP-IDF, we might want to revert
// this change and claim that atomics are supported "in hardware" (even though they would be emulated
// by actually trapping the illegal instruction exception handler and calling into an ESP-IDF C emulation code).
//
// However, for now we simultaneously claim "max_atomic_width: Some(64)" **and** atomic_cas: true,
// which should force the compiler to generate libcalls to functions that emulate atomics
// and which are already implemented in the ESP-IDF main branch anyway.
max_atomic_width: Some(64),
atomic_cas: true,

..super::xtensa_base::opts()
},
}
}
32 changes: 32 additions & 0 deletions compiler/rustc_target/src/spec/xtensa_esp32s3_espidf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::spec::{LinkerFlavor, Target, TargetOptions};
use crate::abi::Endian;

pub fn target() -> Target {
Target {
llvm_target: "xtensa-none-elf".to_string(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32".to_string(),
arch: "xtensa".to_string(),

options: TargetOptions {
endian: Endian::Little,
c_int_width: "32".to_string(),
families: vec!["unix".to_string()],
os: "espidf".to_string(),
env: "newlib".to_string(),
vendor: "espressif".to_string(),
linker_flavor: LinkerFlavor::Gcc,

executables: true,
cpu: "esp32-s3".to_string(),
linker: Some("xtensa-esp32s3-elf-gcc".to_string()),

// The esp32s3 only supports native 32bit atomics. However, esp-idf will emulate 64bit atomics
// so we claim a max atomic width of 64 here.
max_atomic_width: Some(64),
atomic_cas: true,

..super::xtensa_base::opts()
},
}
}

0 comments on commit 7fbd858

Please sign in to comment.