Skip to content

Commit da9ca41

Browse files
committed
Add SOLID targets
SOLID[1] is an embedded development platform provided by Kyoto Microcomputer Co., Ltd. This commit introduces a basic Tier 3 support for SOLID. # New Targets The following targets are added: - `aarch64-kmc-solid_asp3` - `armv7a-kmc-solid_asp3-eabi` - `armv7a-kmc-solid_asp3-eabihf` SOLID's target software system can be divided into two parts: an RTOS kernel, which is responsible for threading and synchronization, and Core Services, which provides filesystems, networking, and other things. The RTOS kernel is a μITRON4.0[2][3]-derived kernel based on the open-source TOPPERS RTOS kernels[4]. For uniprocessor systems (more precisely, systems where only one processor core is allocated for SOLID), this will be the TOPPERS/ASP3 kernel. As μITRON is traditionally only specified at the source-code level, the ABI is unique to each implementation, which is why `asp3` is included in the target names. More targets could be added later, as we support other base kernels (there are at least three at the point of writing) and are interested in supporting other processor architectures in the future. # C Compiler Although SOLID provides its own supported C/C++ build toolchain, GNU Arm Embedded Toolchain seems to work for the purpose of building Rust. # Unresolved Questions A μITRON4 kernel can support `Thread::unpark` natively, but it's not used by this commit's implementation because the underlying kernel feature is also used to implement `Condvar`, and it's unclear whether `std` should guarantee that parking tokens are not clobbered by other synchronization primitives. # Unsupported or Unimplemented Features Most features are implemented. The following features are not implemented due to the lack of native support: - `fs::File::{file_attr, truncate, duplicate, set_permissions}` - `fs::{symlink, link, canonicalize}` - Process creation - Command-line arguments Backtrace generation is not really a good fit for embedded targets, so it's intentionally left unimplemented. Unwinding is functional, however. ## Dynamic Linking Dynamic linking is not supported. The target platform supports dynamic linking, but enabling this in Rust causes several problems. - The linker invocation used to build the shared object of `std` is too long for the platform-provided linker to handle. - A linker script with specific requirements is required for the compiled shared object to be actually loadable. As such, we decided to disable dynamic linking for now. Regardless, the users can try to create shared objects by manually invoking the linker. ## Executable Building an executable is not supported as the notion of "executable files" isn't well-defined for these targets. [1] https://solid.kmckk.com/SOLID/ [2] http://ertl.jp/ITRON/SPEC/mitron4-e.html [3] https://en.wikipedia.org/wiki/ITRON_project [4] https://toppers.jp/
1 parent 293b8f2 commit da9ca41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4062
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use super::{RelocModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
let base = super::solid_base::opts("asp3");
5+
Target {
6+
llvm_target: "aarch64-unknown-none".to_string(),
7+
pointer_width: 64,
8+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
9+
arch: "aarch64".to_string(),
10+
options: TargetOptions {
11+
linker: Some("aarch64-kmc-elf-gcc".to_owned()),
12+
features: "+neon,+fp-armv8".to_string(),
13+
relocation_model: RelocModel::Static,
14+
disable_redzone: true,
15+
max_atomic_width: Some(128),
16+
..base
17+
},
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use super::{RelocModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
let base = super::solid_base::opts("asp3");
5+
Target {
6+
llvm_target: "armv7a-none-eabi".to_string(),
7+
pointer_width: 32,
8+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
9+
arch: "arm".to_string(),
10+
options: TargetOptions {
11+
linker: Some("arm-kmc-eabi-gcc".to_owned()),
12+
features: "+v7,+soft-float,+thumb2,-neon".to_string(),
13+
relocation_model: RelocModel::Static,
14+
disable_redzone: true,
15+
max_atomic_width: Some(64),
16+
..base
17+
},
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use super::{RelocModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
let base = super::solid_base::opts("asp3");
5+
Target {
6+
llvm_target: "armv7a-none-eabihf".to_string(),
7+
pointer_width: 32,
8+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
9+
arch: "arm".to_string(),
10+
options: TargetOptions {
11+
linker: Some("arm-kmc-eabi-gcc".to_owned()),
12+
features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(),
13+
relocation_model: RelocModel::Static,
14+
disable_redzone: true,
15+
max_atomic_width: Some(64),
16+
..base
17+
},
18+
}
19+
}

compiler/rustc_target/src/spec/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ mod netbsd_base;
7575
mod openbsd_base;
7676
mod redox_base;
7777
mod solaris_base;
78+
mod solid_base;
7879
mod thumb_base;
7980
mod uefi_msvc_base;
8081
mod vxworks_base;
@@ -932,6 +933,10 @@ supported_targets! {
932933
("powerpc-wrs-vxworks-spe", powerpc_wrs_vxworks_spe),
933934
("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks),
934935

936+
("aarch64-kmc-solid_asp3", aarch64_kmc_solid_asp3),
937+
("armv7a-kmc-solid_asp3-eabi", armv7a_kmc_solid_asp3_eabi),
938+
("armv7a-kmc-solid_asp3-eabihf", armv7a_kmc_solid_asp3_eabihf),
939+
935940
("mipsel-sony-psp", mipsel_sony_psp),
936941
("mipsel-unknown-none", mipsel_unknown_none),
937942
("thumbv4t-none-eabi", thumbv4t_none_eabi),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use super::FramePointer;
2+
use crate::spec::TargetOptions;
3+
4+
pub fn opts(kernel: &str) -> TargetOptions {
5+
TargetOptions {
6+
os: format!("solid_{}", kernel),
7+
vendor: "kmc".to_string(),
8+
frame_pointer: FramePointer::NonLeaf,
9+
has_elf_tls: true,
10+
..Default::default()
11+
}
12+
}

library/panic_abort/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
4444
libc::abort();
4545
}
4646
} else if #[cfg(any(target_os = "hermit",
47+
target_os = "solid_asp3",
4748
all(target_vendor = "fortanix", target_env = "sgx")
4849
))] {
4950
unsafe fn abort() -> ! {

library/panic_unwind/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ cfg_if::cfg_if! {
4545
} else if #[cfg(any(
4646
all(target_family = "windows", target_env = "gnu"),
4747
target_os = "psp",
48+
target_os = "solid_asp3",
4849
all(target_family = "unix", not(target_os = "espidf")),
4950
all(target_vendor = "fortanix", target_env = "sgx"),
5051
))] {

library/std/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fn main() {
2727
|| target.contains("wasm32")
2828
|| target.contains("asmjs")
2929
|| target.contains("espidf")
30+
|| target.contains("solid")
3031
{
3132
// These platforms don't have any special requirements.
3233
} else {

library/std/src/os/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ pub mod redox;
138138
#[cfg(target_os = "solaris")]
139139
pub mod solaris;
140140

141+
#[cfg(target_os = "solid_asp3")]
142+
pub mod solid;
141143
#[cfg(target_os = "vxworks")]
142144
pub mod vxworks;
143145

library/std/src/os/solid/ffi.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! SOLID-specific extension to the primitives in the `std::ffi` module
2+
//!
3+
//! # Examples
4+
//!
5+
//! ```
6+
//! use std::ffi::OsString;
7+
//! use std::os::solid::ffi::OsStringExt;
8+
//!
9+
//! let bytes = b"foo".to_vec();
10+
//!
11+
//! // OsStringExt::from_vec
12+
//! let os_string = OsString::from_vec(bytes);
13+
//! assert_eq!(os_string.to_str(), Some("foo"));
14+
//!
15+
//! // OsStringExt::into_vec
16+
//! let bytes = os_string.into_vec();
17+
//! assert_eq!(bytes, b"foo");
18+
//! ```
19+
//!
20+
//! ```
21+
//! use std::ffi::OsStr;
22+
//! use std::os::solid::ffi::OsStrExt;
23+
//!
24+
//! let bytes = b"foo";
25+
//!
26+
//! // OsStrExt::from_bytes
27+
//! let os_str = OsStr::from_bytes(bytes);
28+
//! assert_eq!(os_str.to_str(), Some("foo"));
29+
//!
30+
//! // OsStrExt::as_bytes
31+
//! let bytes = os_str.as_bytes();
32+
//! assert_eq!(bytes, b"foo");
33+
//! ```
34+
35+
#![stable(feature = "rust1", since = "1.0.0")]
36+
37+
#[path = "../unix/ffi/os_str.rs"]
38+
mod os_str;
39+
40+
#[stable(feature = "rust1", since = "1.0.0")]
41+
pub use self::os_str::{OsStrExt, OsStringExt};

library/std/src/os/solid/io.rs

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//! SOLID-specific extensions to general I/O primitives
2+
3+
#![deny(unsafe_op_in_unsafe_fn)]
4+
#![unstable(feature = "solid_ext", issue = "none")]
5+
6+
use crate::net;
7+
use crate::sys;
8+
use crate::sys_common::{self, AsInner, FromInner, IntoInner};
9+
10+
/// Raw file descriptors.
11+
pub type RawFd = i32;
12+
13+
/// A trait to extract the raw SOLID Sockets file descriptor from an underlying
14+
/// object.
15+
pub trait AsRawFd {
16+
/// Extracts the raw file descriptor.
17+
///
18+
/// This method does **not** pass ownership of the raw file descriptor
19+
/// to the caller. The descriptor is only guaranteed to be valid while
20+
/// the original object has not yet been destroyed.
21+
fn as_raw_fd(&self) -> RawFd;
22+
}
23+
24+
/// A trait to express the ability to construct an object from a raw file
25+
/// descriptor.
26+
pub trait FromRawFd {
27+
/// Constructs a new instance of `Self` from the given raw file
28+
/// descriptor.
29+
///
30+
/// This function **consumes ownership** of the specified file
31+
/// descriptor. The returned object will take responsibility for closing
32+
/// it when the object goes out of scope.
33+
///
34+
/// This function is also unsafe as the primitives currently returned
35+
/// have the contract that they are the sole owner of the file
36+
/// descriptor they are wrapping. Usage of this function could
37+
/// accidentally allow violating this contract which can cause memory
38+
/// unsafety in code that relies on it being true.
39+
unsafe fn from_raw_fd(fd: RawFd) -> Self;
40+
}
41+
42+
/// A trait to express the ability to consume an object and acquire ownership of
43+
/// its raw file descriptor.
44+
pub trait IntoRawFd {
45+
/// Consumes this object, returning the raw underlying file descriptor.
46+
///
47+
/// This function **transfers ownership** of the underlying file descriptor
48+
/// to the caller. Callers are then the unique owners of the file descriptor
49+
/// and must close the descriptor once it's no longer needed.
50+
fn into_raw_fd(self) -> RawFd;
51+
}
52+
53+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
54+
impl AsRawFd for RawFd {
55+
#[inline]
56+
fn as_raw_fd(&self) -> RawFd {
57+
*self
58+
}
59+
}
60+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
61+
impl IntoRawFd for RawFd {
62+
#[inline]
63+
fn into_raw_fd(self) -> RawFd {
64+
self
65+
}
66+
}
67+
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")]
68+
impl FromRawFd for RawFd {
69+
#[inline]
70+
unsafe fn from_raw_fd(fd: RawFd) -> RawFd {
71+
fd
72+
}
73+
}
74+
75+
macro_rules! impl_as_raw_fd {
76+
($($t:ident)*) => {$(
77+
#[stable(feature = "rust1", since = "1.0.0")]
78+
impl AsRawFd for net::$t {
79+
#[inline]
80+
fn as_raw_fd(&self) -> RawFd {
81+
*self.as_inner().socket().as_inner()
82+
}
83+
}
84+
)*};
85+
}
86+
impl_as_raw_fd! { TcpStream TcpListener UdpSocket }
87+
88+
macro_rules! impl_from_raw_fd {
89+
($($t:ident)*) => {$(
90+
#[stable(feature = "from_raw_os", since = "1.1.0")]
91+
impl FromRawFd for net::$t {
92+
#[inline]
93+
unsafe fn from_raw_fd(fd: RawFd) -> net::$t {
94+
let socket = sys::net::Socket::from_inner(fd);
95+
net::$t::from_inner(sys_common::net::$t::from_inner(socket))
96+
}
97+
}
98+
)*};
99+
}
100+
impl_from_raw_fd! { TcpStream TcpListener UdpSocket }
101+
102+
macro_rules! impl_into_raw_fd {
103+
($($t:ident)*) => {$(
104+
#[stable(feature = "into_raw_os", since = "1.4.0")]
105+
impl IntoRawFd for net::$t {
106+
#[inline]
107+
fn into_raw_fd(self) -> RawFd {
108+
self.into_inner().into_socket().into_inner()
109+
}
110+
}
111+
)*};
112+
}
113+
impl_into_raw_fd! { TcpStream TcpListener UdpSocket }

library/std/src/os/solid/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![stable(feature = "rust1", since = "1.0.0")]
2+
3+
pub mod ffi;
4+
pub mod io;
5+
6+
/// A prelude for conveniently writing platform-specific code.
7+
///
8+
/// Includes all extension traits, and some important type definitions.
9+
#[stable(feature = "rust1", since = "1.0.0")]
10+
pub mod prelude {
11+
#[doc(no_inline)]
12+
#[stable(feature = "rust1", since = "1.0.0")]
13+
pub use super::ffi::{OsStrExt, OsStringExt};
14+
#[doc(no_inline)]
15+
#[stable(feature = "rust1", since = "1.0.0")]
16+
pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
17+
}

0 commit comments

Comments
 (0)