Skip to content

Commit 78e64e9

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 631f767 commit 78e64e9

37 files changed

+3919
-0
lines changed

panic_abort/src/lib.rs

Lines changed: 1 addition & 0 deletions
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() -> ! {

panic_unwind/src/lib.rs

Lines changed: 1 addition & 0 deletions
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
))] {

std/build.rs

Lines changed: 1 addition & 0 deletions
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 {

std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
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

std/src/os/solid/ffi.rs

Lines changed: 41 additions & 0 deletions
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};

std/src/os/solid/io.rs

Lines changed: 113 additions & 0 deletions
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 }

std/src/os/solid/mod.rs

Lines changed: 17 additions & 0 deletions
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+
}

std/src/sys/itron/abi.rs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//! ABI for μITRON derivatives
2+
pub type int_t = crate::os::raw::c_int;
3+
pub type uint_t = crate::os::raw::c_uint;
4+
pub type bool_t = int_t;
5+
6+
/// Kernel object ID
7+
pub type ID = int_t;
8+
9+
/// The current task.
10+
pub const TSK_SELF: ID = 0;
11+
12+
/// Relative time
13+
pub type RELTIM = u32;
14+
15+
/// Timeout (a valid `RELTIM` value or `TMO_FEVR`)
16+
pub type TMO = u32;
17+
18+
/// The infinite timeout value
19+
pub const TMO_FEVR: TMO = TMO::MAX;
20+
21+
/// The maximum valid value of `RELTIM`
22+
pub const TMAX_RELTIM: RELTIM = 4_000_000_000;
23+
24+
/// System time
25+
pub type SYSTIM = u64;
26+
27+
/// Error code type
28+
pub type ER = int_t;
29+
30+
/// Error code type, `ID` on success
31+
pub type ER_ID = int_t;
32+
33+
/// Task or interrupt priority
34+
pub type PRI = int_t;
35+
36+
/// The special value of `PRI` representing the current task's priority.
37+
pub const TPRI_SELF: PRI = 0;
38+
39+
/// Object attributes
40+
pub type ATR = uint_t;
41+
42+
/// Use the priority inheritance protocol
43+
#[cfg(target_os = "solid_asp3")]
44+
pub const TA_INHERIT: ATR = 0x02;
45+
46+
/// Activate the task on creation
47+
pub const TA_ACT: ATR = 0x01;
48+
49+
/// The maximum count of a semaphore
50+
pub const TMAX_MAXSEM: uint_t = uint_t::MAX;
51+
52+
/// Callback parameter
53+
pub type EXINF = isize;
54+
55+
/// Task entrypoint
56+
pub type TASK = Option<unsafe extern "C" fn(EXINF)>;
57+
58+
// Error codes
59+
pub const E_OK: ER = 0;
60+
pub const E_SYS: ER = -5;
61+
pub const E_NOSPT: ER = -9;
62+
pub const E_RSFN: ER = -10;
63+
pub const E_RSATR: ER = -11;
64+
pub const E_PAR: ER = -17;
65+
pub const E_ID: ER = -18;
66+
pub const E_CTX: ER = -25;
67+
pub const E_MACV: ER = -26;
68+
pub const E_OACV: ER = -27;
69+
pub const E_ILUSE: ER = -28;
70+
pub const E_NOMEM: ER = -33;
71+
pub const E_NOID: ER = -34;
72+
pub const E_NORES: ER = -35;
73+
pub const E_OBJ: ER = -41;
74+
pub const E_NOEXS: ER = -42;
75+
pub const E_QOVR: ER = -43;
76+
pub const E_RLWAI: ER = -49;
77+
pub const E_TMOUT: ER = -50;
78+
pub const E_DLT: ER = -51;
79+
pub const E_CLS: ER = -52;
80+
pub const E_RASTER: ER = -53;
81+
pub const E_WBLK: ER = -57;
82+
pub const E_BOVR: ER = -58;
83+
pub const E_COMM: ER = -65;
84+
85+
#[derive(Clone, Copy)]
86+
#[repr(C)]
87+
pub struct T_CSEM {
88+
pub sematr: ATR,
89+
pub isemcnt: uint_t,
90+
pub maxsem: uint_t,
91+
}
92+
93+
#[derive(Clone, Copy)]
94+
#[repr(C)]
95+
pub struct T_CMTX {
96+
pub mtxatr: ATR,
97+
pub ceilpri: PRI,
98+
}
99+
100+
#[derive(Clone, Copy)]
101+
#[repr(C)]
102+
pub struct T_CTSK {
103+
pub tskatr: ATR,
104+
pub exinf: EXINF,
105+
pub task: TASK,
106+
pub itskpri: PRI,
107+
pub stksz: usize,
108+
pub stk: *mut u8,
109+
}
110+
111+
extern "C" {
112+
#[link_name = "__asp3_acre_tsk"]
113+
pub fn acre_tsk(pk_ctsk: *const T_CTSK) -> ER_ID;
114+
#[link_name = "__asp3_get_tid"]
115+
pub fn get_tid(p_tskid: *mut ID) -> ER;
116+
#[link_name = "__asp3_dly_tsk"]
117+
pub fn dly_tsk(dlytim: RELTIM) -> ER;
118+
#[link_name = "__asp3_ter_tsk"]
119+
pub fn ter_tsk(tskid: ID) -> ER;
120+
#[link_name = "__asp3_del_tsk"]
121+
pub fn del_tsk(tskid: ID) -> ER;
122+
#[link_name = "__asp3_get_pri"]
123+
pub fn get_pri(tskid: ID, p_tskpri: *mut PRI) -> ER;
124+
#[link_name = "__asp3_rot_rdq"]
125+
pub fn rot_rdq(tskpri: PRI) -> ER;
126+
#[link_name = "__asp3_slp_tsk"]
127+
pub fn slp_tsk() -> ER;
128+
#[link_name = "__asp3_tslp_tsk"]
129+
pub fn tslp_tsk(tmout: TMO) -> ER;
130+
#[link_name = "__asp3_wup_tsk"]
131+
pub fn wup_tsk(tskid: ID) -> ER;
132+
#[link_name = "__asp3_unl_cpu"]
133+
pub fn unl_cpu() -> ER;
134+
#[link_name = "__asp3_dis_dsp"]
135+
pub fn dis_dsp() -> ER;
136+
#[link_name = "__asp3_ena_dsp"]
137+
pub fn ena_dsp() -> ER;
138+
#[link_name = "__asp3_sns_dsp"]
139+
pub fn sns_dsp() -> bool_t;
140+
#[link_name = "__asp3_get_tim"]
141+
pub fn get_tim(p_systim: *mut SYSTIM) -> ER;
142+
#[link_name = "__asp3_acre_mtx"]
143+
pub fn acre_mtx(pk_cmtx: *const T_CMTX) -> ER_ID;
144+
#[link_name = "__asp3_del_mtx"]
145+
pub fn del_mtx(tskid: ID) -> ER;
146+
#[link_name = "__asp3_loc_mtx"]
147+
pub fn loc_mtx(mtxid: ID) -> ER;
148+
#[link_name = "__asp3_ploc_mtx"]
149+
pub fn ploc_mtx(mtxid: ID) -> ER;
150+
#[link_name = "__asp3_tloc_mtx"]
151+
pub fn tloc_mtx(mtxid: ID, tmout: TMO) -> ER;
152+
#[link_name = "__asp3_unl_mtx"]
153+
pub fn unl_mtx(mtxid: ID) -> ER;
154+
pub fn exd_tsk() -> ER;
155+
}

0 commit comments

Comments
 (0)