-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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/
- Loading branch information
Showing
45 changed files
with
4,062 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::{RelocModel, Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
let base = super::solid_base::opts("asp3"); | ||
Target { | ||
llvm_target: "aarch64-unknown-none".to_string(), | ||
pointer_width: 64, | ||
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), | ||
arch: "aarch64".to_string(), | ||
options: TargetOptions { | ||
linker: Some("aarch64-kmc-elf-gcc".to_owned()), | ||
features: "+neon,+fp-armv8".to_string(), | ||
relocation_model: RelocModel::Static, | ||
disable_redzone: true, | ||
max_atomic_width: Some(128), | ||
..base | ||
}, | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::{RelocModel, Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
let base = super::solid_base::opts("asp3"); | ||
Target { | ||
llvm_target: "armv7a-none-eabi".to_string(), | ||
pointer_width: 32, | ||
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), | ||
arch: "arm".to_string(), | ||
options: TargetOptions { | ||
linker: Some("arm-kmc-eabi-gcc".to_owned()), | ||
features: "+v7,+soft-float,+thumb2,-neon".to_string(), | ||
relocation_model: RelocModel::Static, | ||
disable_redzone: true, | ||
max_atomic_width: Some(64), | ||
..base | ||
}, | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::{RelocModel, Target, TargetOptions}; | ||
|
||
pub fn target() -> Target { | ||
let base = super::solid_base::opts("asp3"); | ||
Target { | ||
llvm_target: "armv7a-none-eabihf".to_string(), | ||
pointer_width: 32, | ||
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), | ||
arch: "arm".to_string(), | ||
options: TargetOptions { | ||
linker: Some("arm-kmc-eabi-gcc".to_owned()), | ||
features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), | ||
relocation_model: RelocModel::Static, | ||
disable_redzone: true, | ||
max_atomic_width: Some(64), | ||
..base | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use super::FramePointer; | ||
use crate::spec::TargetOptions; | ||
|
||
pub fn opts(kernel: &str) -> TargetOptions { | ||
TargetOptions { | ||
os: format!("solid_{}", kernel), | ||
vendor: "kmc".to_string(), | ||
frame_pointer: FramePointer::NonLeaf, | ||
has_elf_tls: true, | ||
..Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! SOLID-specific extension to the primitives in the `std::ffi` module | ||
//! | ||
//! # Examples | ||
//! | ||
//! ``` | ||
//! use std::ffi::OsString; | ||
//! use std::os::solid::ffi::OsStringExt; | ||
//! | ||
//! let bytes = b"foo".to_vec(); | ||
//! | ||
//! // OsStringExt::from_vec | ||
//! let os_string = OsString::from_vec(bytes); | ||
//! assert_eq!(os_string.to_str(), Some("foo")); | ||
//! | ||
//! // OsStringExt::into_vec | ||
//! let bytes = os_string.into_vec(); | ||
//! assert_eq!(bytes, b"foo"); | ||
//! ``` | ||
//! | ||
//! ``` | ||
//! use std::ffi::OsStr; | ||
//! use std::os::solid::ffi::OsStrExt; | ||
//! | ||
//! let bytes = b"foo"; | ||
//! | ||
//! // OsStrExt::from_bytes | ||
//! let os_str = OsStr::from_bytes(bytes); | ||
//! assert_eq!(os_str.to_str(), Some("foo")); | ||
//! | ||
//! // OsStrExt::as_bytes | ||
//! let bytes = os_str.as_bytes(); | ||
//! assert_eq!(bytes, b"foo"); | ||
//! ``` | ||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
#[path = "../unix/ffi/os_str.rs"] | ||
mod os_str; | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use self::os_str::{OsStrExt, OsStringExt}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
//! SOLID-specific extensions to general I/O primitives | ||
#![deny(unsafe_op_in_unsafe_fn)] | ||
#![unstable(feature = "solid_ext", issue = "none")] | ||
|
||
use crate::net; | ||
use crate::sys; | ||
use crate::sys_common::{self, AsInner, FromInner, IntoInner}; | ||
|
||
/// Raw file descriptors. | ||
pub type RawFd = i32; | ||
|
||
/// A trait to extract the raw SOLID Sockets file descriptor from an underlying | ||
/// object. | ||
pub trait AsRawFd { | ||
/// Extracts the raw file descriptor. | ||
/// | ||
/// This method does **not** pass ownership of the raw file descriptor | ||
/// to the caller. The descriptor is only guaranteed to be valid while | ||
/// the original object has not yet been destroyed. | ||
fn as_raw_fd(&self) -> RawFd; | ||
} | ||
|
||
/// A trait to express the ability to construct an object from a raw file | ||
/// descriptor. | ||
pub trait FromRawFd { | ||
/// Constructs a new instance of `Self` from the given raw file | ||
/// descriptor. | ||
/// | ||
/// This function **consumes ownership** of the specified file | ||
/// descriptor. The returned object will take responsibility for closing | ||
/// it when the object goes out of scope. | ||
/// | ||
/// This function is also unsafe as the primitives currently returned | ||
/// have the contract that they are the sole owner of the file | ||
/// descriptor they are wrapping. Usage of this function could | ||
/// accidentally allow violating this contract which can cause memory | ||
/// unsafety in code that relies on it being true. | ||
unsafe fn from_raw_fd(fd: RawFd) -> Self; | ||
} | ||
|
||
/// A trait to express the ability to consume an object and acquire ownership of | ||
/// its raw file descriptor. | ||
pub trait IntoRawFd { | ||
/// Consumes this object, returning the raw underlying file descriptor. | ||
/// | ||
/// This function **transfers ownership** of the underlying file descriptor | ||
/// to the caller. Callers are then the unique owners of the file descriptor | ||
/// and must close the descriptor once it's no longer needed. | ||
fn into_raw_fd(self) -> RawFd; | ||
} | ||
|
||
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")] | ||
impl AsRawFd for RawFd { | ||
#[inline] | ||
fn as_raw_fd(&self) -> RawFd { | ||
*self | ||
} | ||
} | ||
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")] | ||
impl IntoRawFd for RawFd { | ||
#[inline] | ||
fn into_raw_fd(self) -> RawFd { | ||
self | ||
} | ||
} | ||
#[stable(feature = "raw_fd_reflexive_traits", since = "1.48.0")] | ||
impl FromRawFd for RawFd { | ||
#[inline] | ||
unsafe fn from_raw_fd(fd: RawFd) -> RawFd { | ||
fd | ||
} | ||
} | ||
|
||
macro_rules! impl_as_raw_fd { | ||
($($t:ident)*) => {$( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl AsRawFd for net::$t { | ||
#[inline] | ||
fn as_raw_fd(&self) -> RawFd { | ||
*self.as_inner().socket().as_inner() | ||
} | ||
} | ||
)*}; | ||
} | ||
impl_as_raw_fd! { TcpStream TcpListener UdpSocket } | ||
|
||
macro_rules! impl_from_raw_fd { | ||
($($t:ident)*) => {$( | ||
#[stable(feature = "from_raw_os", since = "1.1.0")] | ||
impl FromRawFd for net::$t { | ||
#[inline] | ||
unsafe fn from_raw_fd(fd: RawFd) -> net::$t { | ||
let socket = sys::net::Socket::from_inner(fd); | ||
net::$t::from_inner(sys_common::net::$t::from_inner(socket)) | ||
} | ||
} | ||
)*}; | ||
} | ||
impl_from_raw_fd! { TcpStream TcpListener UdpSocket } | ||
|
||
macro_rules! impl_into_raw_fd { | ||
($($t:ident)*) => {$( | ||
#[stable(feature = "into_raw_os", since = "1.4.0")] | ||
impl IntoRawFd for net::$t { | ||
#[inline] | ||
fn into_raw_fd(self) -> RawFd { | ||
self.into_inner().into_socket().into_inner() | ||
} | ||
} | ||
)*}; | ||
} | ||
impl_into_raw_fd! { TcpStream TcpListener UdpSocket } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
pub mod ffi; | ||
pub mod io; | ||
|
||
/// A prelude for conveniently writing platform-specific code. | ||
/// | ||
/// Includes all extension traits, and some important type definitions. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub mod prelude { | ||
#[doc(no_inline)] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use super::ffi::{OsStrExt, OsStringExt}; | ||
#[doc(no_inline)] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; | ||
} |
Oops, something went wrong.