Skip to content

Commit

Permalink
Add SOLID targets
Browse files Browse the repository at this point in the history
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
kawadakk committed Sep 28, 2021
1 parent 293b8f2 commit da9ca41
Show file tree
Hide file tree
Showing 45 changed files with 4,062 additions and 0 deletions.
19 changes: 19 additions & 0 deletions compiler/rustc_target/src/spec/aarch64_kmc_solid_asp3.rs
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 compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs
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 compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs
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
},
}
}
5 changes: 5 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ mod netbsd_base;
mod openbsd_base;
mod redox_base;
mod solaris_base;
mod solid_base;
mod thumb_base;
mod uefi_msvc_base;
mod vxworks_base;
Expand Down Expand Up @@ -932,6 +933,10 @@ supported_targets! {
("powerpc-wrs-vxworks-spe", powerpc_wrs_vxworks_spe),
("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks),

("aarch64-kmc-solid_asp3", aarch64_kmc_solid_asp3),
("armv7a-kmc-solid_asp3-eabi", armv7a_kmc_solid_asp3_eabi),
("armv7a-kmc-solid_asp3-eabihf", armv7a_kmc_solid_asp3_eabihf),

("mipsel-sony-psp", mipsel_sony_psp),
("mipsel-unknown-none", mipsel_unknown_none),
("thumbv4t-none-eabi", thumbv4t_none_eabi),
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_target/src/spec/solid_base.rs
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()
}
}
1 change: 1 addition & 0 deletions library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
libc::abort();
}
} else if #[cfg(any(target_os = "hermit",
target_os = "solid_asp3",
all(target_vendor = "fortanix", target_env = "sgx")
))] {
unsafe fn abort() -> ! {
Expand Down
1 change: 1 addition & 0 deletions library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ cfg_if::cfg_if! {
} else if #[cfg(any(
all(target_family = "windows", target_env = "gnu"),
target_os = "psp",
target_os = "solid_asp3",
all(target_family = "unix", not(target_os = "espidf")),
all(target_vendor = "fortanix", target_env = "sgx"),
))] {
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn main() {
|| target.contains("wasm32")
|| target.contains("asmjs")
|| target.contains("espidf")
|| target.contains("solid")
{
// These platforms don't have any special requirements.
} else {
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ pub mod redox;
#[cfg(target_os = "solaris")]
pub mod solaris;

#[cfg(target_os = "solid_asp3")]
pub mod solid;
#[cfg(target_os = "vxworks")]
pub mod vxworks;

Expand Down
41 changes: 41 additions & 0 deletions library/std/src/os/solid/ffi.rs
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};
113 changes: 113 additions & 0 deletions library/std/src/os/solid/io.rs
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 }
17 changes: 17 additions & 0 deletions library/std/src/os/solid/mod.rs
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};
}
Loading

0 comments on commit da9ca41

Please sign in to comment.