Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add armv7a-vex-v5 tier three target #131530

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a5ccf0a
add armv7a-vex-v5 target
max-niederman May 28, 2024
a149b59
add (shimmed) std support for armv7a-vex-v5
max-niederman May 28, 2024
4b7ba7f
add panic, stdio, and alloc support to armv7a-vex-v5
max-niederman May 28, 2024
ce7fc68
fix linker script and call main
max-niederman May 30, 2024
45ea8cb
zero out bss section in _start
max-niederman Jul 17, 2024
c2b14c0
use static TLS implementation on vexos
max-niederman Jul 17, 2024
75474a5
make minor improvements to linker script
max-niederman Jul 17, 2024
061ac0e
enable stdio and fix stdout flushing
max-niederman Jul 18, 2024
a372ca0
add: `Instant` implementation
Gavin-Niederman Jul 18, 2024
a95f748
remove broken cleanup
max-niederman Jul 18, 2024
9fd7615
fix `.code_signature` section error
Tropix126 Jul 18, 2024
d9edb32
move `.code_signature` section into `.text`
Tropix126 Jul 18, 2024
8ef0fe5
adjust `armv7a-vex-v5` target features for more aggressive hardware o…
Tropix126 Jul 18, 2024
264ea44
switch `llvm_target` to use ARM hard-float abi
Tropix126 Jul 18, 2024
70448c0
add `env` implementation for `vexos` PAL
Tropix126 Jul 18, 2024
a5682b6
feat: experimental fs support
Gavin-Niederman Jul 18, 2024
32ea1c3
add support for more missing file operations
Tropix126 Jul 18, 2024
d48c422
feat: file writes vectored writes and vectored reads
Gavin-Niederman Jul 18, 2024
efd26d9
add helper for mapping FRESULT values
Tropix126 Jul 21, 2024
503c7b1
add: try_file_exists and stat
Gavin-Niederman Jul 21, 2024
1f57c2c
add: fileattr functions
Gavin-Niederman Jul 21, 2024
ebcd00e
fix: check current position in file when getting size
Gavin-Niederman Jul 21, 2024
d24f040
refactor: pseudorandom hashmap keys
Gavin-Niederman Jul 21, 2024
ed278ef
fix: support File::file_attr and dissalow read and write mode at the …
Gavin-Niederman Jul 22, 2024
6b3acd6
feat: seek implementation
Gavin-Niederman Jul 22, 2024
7a06d08
feat: almost working directory reading
Gavin-Niederman Jul 23, 2024
2cbbabb
fix: remove trailing slashes sooner
Gavin-Niederman Jul 23, 2024
a5b7a20
remove test code and document filesystem quirks
Tropix126 Jul 27, 2024
2883fb2
add default code signature, ensure stdout flush
Tropix126 Aug 4, 2024
e5018c1
add platform docs
Tropix126 Aug 4, 2024
71b8640
adjust wording and fix typos in target documentation
Tropix126 Aug 4, 2024
3ec948e
update PAL and add `check-cfg` override for `target_os`
Tropix126 Aug 5, 2024
f1eadde
add additional information to target spec and supporting docs
Tropix126 Aug 5, 2024
5fa6b4c
fix `EXE_SUFFFIX` to use dot
Tropix126 Aug 9, 2024
5c05880
fix: use correct code signature default values
Tropix126 Aug 17, 2024
ccf19ef
don't compile with `+thumb-mode` feature for now
Tropix126 Aug 21, 2024
887ff2d
properly flush serial on abort
Tropix126 Sep 6, 2024
53e5abc
clarify documentation regarding cargo-v5, adjust `SystemTime` panic m…
Tropix126 Sep 7, 2024
729072b
use aapcs as system abi
max-niederman Oct 9, 2024
71875d3
fix stack corruptions in startup routine
max-niederman Oct 9, 2024
5371b62
fix thread locals
max-niederman Oct 9, 2024
be3dd7a
implement (shimmed) std::random
max-niederman Oct 9, 2024
5efc465
fix allocation
max-niederman Oct 9, 2024
e41b73b
update linkerscript to include unwinding-related sections
Tropix126 Oct 11, 2024
7fbb673
format target doc and reorder maintainer list
max-niederman Oct 11, 2024
3977027
bump vex-sdk version and allow vex-sdk to be a stdlib dep
max-niederman Oct 11, 2024
4336524
add assembly test for armv7a-vex-v5
max-niederman Oct 11, 2024
da8d804
bless well-known-values test
max-niederman Oct 11, 2024
3a06fc8
add armv7a-vex-v5 target docs to summary
max-niederman Oct 11, 2024
a47c7df
better document the is_like_vexos property of TargetOptions
max-niederman Oct 11, 2024
b66a0f7
detail summary of armv7a-vex-v5's target support
max-niederman Oct 11, 2024
73dffc6
add more descriptive comments to the `armv7a-vex-v5` linkerscript
Tropix126 Oct 13, 2024
5a43c39
add `"v5"` target env armv7a-vex-v5 target spec
Tropix126 Oct 15, 2024
50cf19a
implement `Stderr` in vexos PAL
Tropix126 Oct 23, 2024
8a2d12b
run VEXos cpu1 scheduler while waiting for abort
Tropix126 Oct 23, 2024
dba2111
update to `vex-sdk` 0.23.0
Tropix126 Oct 23, 2024
8e5361b
add rudimentary implementation of `Thread::sleep` and `Thread::yield_…
Tropix126 Oct 25, 2024
c60ba56
fix broken reference to Instant in pal
max-niederman Oct 30, 2024
539baf1
switch to `+vfp3d16` LLVM feature in `armv7a-vex-v5`
Tropix126 Nov 11, 2024
c0c18aa
fix and clean up comments surrounding file seeking
Tropix126 Dec 23, 2024
d46d9e6
add private unit to all pub fs types in vexos PAL
Tropix126 Dec 23, 2024
53447c9
treat all `io::Error`s as non-EBADF in vexos
Tropix126 Dec 23, 2024
70ef480
adjust error message for `FRESULT::FR_INT_ERR`
Tropix126 Dec 23, 2024
668dfa4
bump `vex-sdk` to 0.26.0
Tropix126 Dec 23, 2024
1b9d337
update libstd lockfile
Tropix126 Dec 23, 2024
1e2ba27
fix circular dependency on cc-rs using a temporary patched version of…
max-niederman Jan 1, 2025
82f85a5
add unsupported file_lock functions
max-niederman Jan 1, 2025
55869f4
fix mistakes in fs PAL
max-niederman Jan 1, 2025
fbd50d7
add `llvm_floatabi` to armv7a-vex-v5 spec
Tropix126 Jan 2, 2025
9522587
serialize `is_like_vexos` in target json specs
doinkythederp Jan 2, 2025
3f6b70c
ensure `arm` arch before adjusting VEXos system ABI to `aapcs`
doinkythederp Jan 2, 2025
20144f8
bless `well-known-values` test again
Tropix126 Jan 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ impl Target {
key!(is_like_msvc, bool);
key!(is_like_wasm, bool);
key!(is_like_android, bool);
key!(is_like_vexos, bool);
key!(default_dwarf_version, u32);
key!(allows_weak_linkage, bool);
key!(has_rpath, bool);
Expand Down Expand Up @@ -746,6 +747,7 @@ impl ToJson for Target {
target_option_val!(is_like_msvc);
target_option_val!(is_like_wasm);
target_option_val!(is_like_android);
target_option_val!(is_like_vexos);
target_option_val!(default_dwarf_version);
target_option_val!(allows_weak_linkage);
target_option_val!(has_rpath);
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,8 @@ supported_targets! {

("armv7-sony-vita-newlibeabihf", armv7_sony_vita_newlibeabihf),

("armv7a-vex-v5", armv7a_vex_v5),

("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi),
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),

Expand Down Expand Up @@ -2328,6 +2330,9 @@ pub struct TargetOptions {
pub is_like_wasm: bool,
/// Whether a target toolchain is like Android, implying a Linux kernel and a Bionic libc
pub is_like_android: bool,
/// Whether a target toolchain is like VEXos, the operating system used by the VEX Robotics V5 Brain.
/// Introduced for the `armv7a-vex-v5` target.
pub is_like_vexos: bool,
/// Default supported version of DWARF on this platform.
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
pub default_dwarf_version: u32,
Expand Down Expand Up @@ -2704,6 +2709,7 @@ impl Default for TargetOptions {
is_like_msvc: false,
is_like_wasm: false,
is_like_android: false,
is_like_vexos: false,
default_dwarf_version: 4,
allows_weak_linkage: true,
has_rpath: false,
Expand Down Expand Up @@ -2811,6 +2817,9 @@ impl Target {
Abi::System { unwind } if self.is_like_windows && self.arch == "x86" && !c_variadic => {
Abi::Stdcall { unwind }
}
Abi::System { unwind } if self.is_like_vexos && self.arch == "arm" && !c_variadic => {
Abi::Aapcs { unwind }
}
Abi::System { unwind } => Abi::C { unwind },
Abi::EfiApi if self.arch == "arm" => Abi::Aapcs { unwind: false },
Abi::EfiApi if self.arch == "x86_64" => Abi::Win64 { unwind: false },
Expand Down
41 changes: 41 additions & 0 deletions compiler/rustc_target/src/spec/targets/armv7a_vex_v5.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::spec::{
Cc, FloatAbi, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions,
};

const LINK_SCRIPT: &str = include_str!("./armv7a_vex_v5_linker_script.ld");

pub(crate) fn target() -> Target {
Target {
llvm_target: "armv7a-none-eabihf".into(),
metadata: crate::spec::TargetMetadata {
description: Some("Armv7-A Cortex-A9 VEX V5 Brain, VEXos".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(true),
},
pointer_width: 32,
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
arch: "arm".into(),
options: TargetOptions {
llvm_floatabi: Some(FloatAbi::Hard),
os: "vexos".into(),
is_like_vexos: true,
vendor: "vex".into(),
env: "v5".into(),
cpu: "cortex-a9".into(),
abi: "eabihf".into(),
features: "+v7,+neon,+vfp3d16,+thumb2".into(),
linker: Some("rust-lld".into()),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
link_script: Some(LINK_SCRIPT.into()),
panic_strategy: PanicStrategy::Abort,
relocation_model: RelocModel::Static,
c_enum_min_bits: Some(8),
max_atomic_width: Some(64),
disable_redzone: true,
emit_debug_gdb_scripts: false,
has_thumb_interworking: true,
..Default::default()
},
}
}
100 changes: 100 additions & 0 deletions compiler/rustc_target/src/spec/targets/armv7a_vex_v5_linker_script.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
OUTPUT_FORMAT("elf32-littlearm")

ENTRY(_boot)

__user_ram_start = 0x03800000;
__user_ram_length = 0x04800000;
__user_ram_end = __user_ram_start + __user_ram_length;

__code_signature_length = 0x20;

__stack_length = 0x400000;
__heap_end = __user_ram_end - __stack_length;

/* see https://github.com/llvm/llvm-project/blob/main/libunwind/src/AddressSpace.hpp#L78 */
__eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0;
__eh_frame_hdr_end = SIZEOF(.eh_frame_hdr) > 0 ? . : 0;

MEMORY {
USER_RAM : ORIGIN = __user_ram_start, LENGTH = __user_ram_length
}

SECTIONS {
/*
* VEXos expects program binaries to have a 32-byte header called a "code signature",
* at their start, which tells the OS that we are a valid program and configures some
* miscellaneous startup behavior.
*
* This section is then initialized as a weak symbol in our PAL.
*/
.code_signature : {
KEEP(*(.code_signature))
. = __user_ram_start + __code_signature_length;
} > USER_RAM

.text : {
*(.boot)
*(.text .text.*)
} > USER_RAM

/* Global/uninitialized/static/constant data sections. */
.rodata : {
*(.rodata .rodata.*)
} > USER_RAM

.data : {
*(.data .data.*)
} > USER_RAM

.bss : {
__bss_start = .;
*(.bss .bss.*)
__bss_end = .;
} > USER_RAM

/*
* These sections are added by the compiler in some cases to facilitate stack unwinding.
* __eh_frame_start and similar symbols are used by libunwind.
*/
.eh_frame_hdr : {
KEEP(*(.eh_frame_hdr))
} > USER_RAM

.eh_frame : {
__eh_frame_start = .;
KEEP(*(.eh_frame))
__eh_frame_end = .;
} > USER_RAM

.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > USER_RAM

.ARM.extab : {
__extab_start = .;
*(.ARM.extab*)
__extab_end = .;
} > USER_RAM

/* Active memory regions for the stack/heap. */
.heap (NOLOAD) : ALIGN(4) {
__heap_start = .;
. = __heap_end;
} > USER_RAM

.stack (NOLOAD) : ALIGN(8) {
__stack_bottom = .;
. += __stack_length;
__stack_top = .;
} > USER_RAM

/*
* `.ARM.attributes` contains arch metadata for compatibility purposes, but we
* only target one hardware configuration, meaning it'd just take up space.
*/
/DISCARD/ : {
*(.ARM.attributes*)
}
}
11 changes: 11 additions & 0 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ dependencies = [
"rustc-demangle",
"std_detect",
"unwind",
"vex-sdk",
"wasi",
"windows-targets 0.0.0",
]
Expand Down Expand Up @@ -401,6 +402,16 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "vex-sdk"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be1b586dd8546706564cf20c94bae51c8f9e4891d70360d3fb63d563350df3d1"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-core",
]

[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
Expand Down
4 changes: 4 additions & 0 deletions library/panic_abort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ compiler_builtins = "0.1.0"

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2", default-features = false }

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ['cfg(target_os, values("vexos"))']
1 change: 1 addition & 0 deletions library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
all(target_vendor = "fortanix", target_env = "sgx"),
target_os = "xous",
target_os = "uefi",
target_os = "vexos",
))] {
unsafe fn abort() -> ! {
// call std::sys::abort_internal
Expand Down
6 changes: 5 additions & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ path = "../windows_targets"
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
rand_xorshift = "0.3.0"

[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "xous", all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "vexos", target_os = "xous", all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
dlmalloc = { version = "0.2.4", features = ['rustc-dep-of-std'] }

[target.x86_64-fortanix-unknown-sgx.dependencies]
Expand All @@ -85,6 +85,9 @@ wasi = { version = "0.11.0", features = [
r-efi = { version = "4.5.0", features = ['rustc-dep-of-std'] }
r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std'] }

[target.'cfg(target_os = "vexos")'.dependencies]
vex-sdk = { version = "0.26.0", features = ['rustc-dep-of-std'] }

[features]
backtrace = [
'addr2line/rustc-dep-of-std',
Expand Down Expand Up @@ -140,6 +143,7 @@ level = "warn"
check-cfg = [
'cfg(bootstrap)',
'cfg(target_arch, values("xtensa"))',
'cfg(target_os, values("vexos"))',
# std use #[path] imports to portable-simd `std_float` crate
# and to the `backtrace` crate which messes-up with Cargo list
# of declared features, we therefor expect any feature cfg
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn main() {
|| target_os == "zkvm"
|| target_os == "rtems"
|| target_os == "nuttx"
|| target_os == "vexos"

// See src/bootstrap/src/core/build_steps/synthetic_targets.rs
|| env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok()
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,7 @@ cfg_if::cfg_if! {
mod xous;
} else if #[cfg(target_os = "zkvm")] {
mod zkvm;
} else if #[cfg(target_os = "vexos")] {
mod vexos;
}
}
98 changes: 98 additions & 0 deletions library/std/src/sys/alloc/vexos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
#![allow(static_mut_refs)]

use crate::alloc::{GlobalAlloc, Layout, System};
use crate::ptr;
use crate::sync::atomic::{AtomicBool, Ordering};

static mut DLMALLOC: dlmalloc::Dlmalloc<Vexos> = dlmalloc::Dlmalloc::new_with_allocator(Vexos);

extern "C" {
static mut __heap_start: u8;
static mut __heap_end: u8;
}

struct Vexos;

unsafe impl dlmalloc::Allocator for Vexos {
/// Allocs system resources
fn alloc(&self, _size: usize) -> (*mut u8, usize, u32) {
static INIT: AtomicBool = AtomicBool::new(false);

if !INIT.swap(true, Ordering::Relaxed) {
unsafe {
(
ptr::addr_of_mut!(__heap_start).cast(),
ptr::addr_of!(__heap_end).byte_offset_from(ptr::addr_of!(__heap_start)) as _,
0,
)
}
} else {
(ptr::null_mut(), 0, 0)
}
}

fn remap(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool) -> *mut u8 {
ptr::null_mut()
}

fn free_part(&self, _ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}

fn free(&self, _ptr: *mut u8, _size: usize) -> bool {
false
}

fn can_release_part(&self, _flags: u32) -> bool {
false
}

fn allocates_zeros(&self) -> bool {
false
}

fn page_size(&self) -> usize {
0x1000
}
}

#[stable(feature = "alloc_system_type", since = "1.28.0")]
unsafe impl GlobalAlloc for System {
#[inline]
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
// SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
// Calling malloc() is safe because preconditions on this function match the trait method preconditions.
let _lock = lock::lock();
unsafe { DLMALLOC.malloc(layout.size(), layout.align()) }
}

#[inline]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
// SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
// Calling calloc() is safe because preconditions on this function match the trait method preconditions.
let _lock = lock::lock();
unsafe { DLMALLOC.calloc(layout.size(), layout.align()) }
}

#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
// SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
// Calling free() is safe because preconditions on this function match the trait method preconditions.
let _lock = lock::lock();
unsafe { DLMALLOC.free(ptr, layout.size(), layout.align()) }
}

#[inline]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
// SAFETY: DLMALLOC access is guaranteed to be safe because the lock gives us unique and non-reentrant access.
// Calling realloc() is safe because preconditions on this function match the trait method preconditions.
let _lock = lock::lock();
unsafe { DLMALLOC.realloc(ptr, layout.size(), layout.align(), new_size) }
}
}

mod lock {
#[inline]
pub fn lock() {} // we don't have threads, which makes this real easy
}
workingjubilee marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions library/std/src/sys/pal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ cfg_if::cfg_if! {
} else if #[cfg(target_os = "zkvm")] {
mod zkvm;
pub use self::zkvm::*;
} else if #[cfg(target_os = "vexos")] {
mod vexos;
pub use self::vexos::*;
} else {
mod unsupported;
pub use self::unsupported::*;
Expand Down
Loading
Loading