浏览代码

Remove embedded-hal serial adapter to legacy console

Remove dependency on crate alloc; RustSBI now works without heap
luojia65 2 年之前
父节点
当前提交
36f8553e7a
共有 5 个文件被更改,包括 5 次插入94 次删除
  1. 2 1
      CHANGELOG.md
  2. 2 5
      Cargo.toml
  3. 0 81
      src/legacy_stdio.rs
  4. 0 7
      src/lib.rs
  5. 1 0
      src/util.rs

+ 2 - 1
CHANGELOG.md

@@ -11,7 +11,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 - Feature `legacy` to gate SBI legacy extension
 
 ### Modified
-- Update depenency embedded-hal to 1.0.0-alpha.8
+- Remove dependency on crate alloc; RustSBI now works without heap
+- Remove embedded-hal serial adapter to legacy console
 
 ### Fixed
 

+ 2 - 5
Cargo.toml

@@ -17,15 +17,12 @@ edition = "2021"
 
 [dependencies]
 riscv = "0.8"
-sbi-spec = { git = "https://github.com/rustsbi/sbi-spec.git", rev = "9d728bb" }
-# The following two dependencies are used to support legacy console feature
-embedded-hal = { version = "1.0.0-alpha.8", optional = true }
-nb = { version = "1.0", optional = true }
+sbi-spec = "0.0.1"
 
 [features]
 default = []
 # Support legacy extension; this feature is not included by default.
-legacy = ["embedded-hal", "nb"]
+legacy = []
 # Dynamic pointer widths on SBI implementations; useful for developing hypervisors
 guest = []
 

+ 0 - 81
src/legacy_stdio.rs

@@ -2,9 +2,6 @@
 //! 如果制造实例的时候,给定了stdout,那么就会打印到这个stdout里面
 use crate::util::AmoOnceRef;
 use core::fmt;
-use alloc::boxed::Box;
-use embedded_hal::serial::nb::{Read, Write};
-use nb::block;
 
 /// Legacy standard input/output
 pub trait LegacyStdio: Send + Sync {
@@ -20,68 +17,6 @@ pub trait LegacyStdio: Send + Sync {
     }
 }
 
-
-/// Legacy standard input/output
-pub trait LegacyStdio: Send {
-    /// Get a character from legacy stdin
-    fn getchar(&mut self) -> u8;
-    /// Put a character into legacy stdout
-    fn putchar(&mut self, ch: u8);
-}
-
-/// Use serial in `embedded-hal` as legacy standard input/output
-struct EmbeddedHalSerial<T> {
-    inner: T,
-}
-
-impl<T> EmbeddedHalSerial<T> {
-    /// Create a wrapper with a value
-    #[inline]
-    fn new(inner: T) -> Self {
-        Self { inner }
-    }
-}
-
-impl<T: Send> LegacyStdio for EmbeddedHalSerial<T>
-where
-    T: Read<u8> + Write<u8>,
-{
-    #[inline]
-    fn getchar(&mut self) -> u8 {
-        // 直接调用embedded-hal里面的函数
-        // 关于unwrap:因为这个是legacy函数,这里没有详细的处理流程,就panic掉
-        block!(self.inner.read()).ok().unwrap()
-    }
-
-    #[inline]
-    fn putchar(&mut self, ch: u8) {
-        // 直接调用函数写一个字节
-        block!(self.inner.write(ch)).ok();
-        // 写一次flush一次,因为是legacy,就不考虑效率了
-        block!(self.inner.flush()).ok();
-    }
-}
-
-struct Fused<T, R>(T, R);
-
-// 和上面的原理差不多,就是分开了
-impl<T, R> LegacyStdio for Fused<T, R>
-where
-    T: Write<u8> + Send + 'static,
-    R: Read<u8> + Send + 'static,
-{
-    #[inline]
-    fn getchar(&mut self) -> u8 {
-        block!(self.1.read()).ok().unwrap()
-    }
-
-    #[inline]
-    fn putchar(&mut self, ch: u8) {
-        block!(self.0.write(ch)).ok();
-        block!(self.0.flush()).ok();
-    }
-}
-
 static LEGACY_STDIO: AmoOnceRef<dyn LegacyStdio> = AmoOnceRef::new();
 
 #[inline]
@@ -91,22 +26,6 @@ pub fn init_legacy_stdio(stdio: &'static dyn LegacyStdio) {
     }
 }
 
-#[doc(hidden)] // use through a macro
-pub fn init_legacy_stdio_embedded_hal<T: Read<u8> + Write<u8> + Send + 'static>(serial: T) {
-    let serial = EmbeddedHalSerial::new(serial);
-    *LEGACY_STDIO.lock() = Some(Box::new(serial));
-}
-
-#[doc(hidden)] // use through a macro
-pub fn init_legacy_stdio_embedded_hal_fuse<T, R>(tx: T, rx: R)
-where
-    T: Write<u8> + Send + 'static,
-    R: Read<u8> + Send + 'static,
-{
-    let serial = Fused(tx, rx);
-    *LEGACY_STDIO.lock() = Some(Box::new(serial));
-}
-
 #[inline]
 pub fn legacy_stdio_putchar(ch: u8) {
     if let Some(stdio) = LEGACY_STDIO.get() {

+ 0 - 7
src/lib.rs

@@ -180,18 +180,11 @@
 //! [dependencies]
 //! rustsbi = { version = "0.3.0", features = ["legacy"] }
 //! ```
-//! 
-//! By using the `legacy` feature, RustSBI will include `embedded-hal` compliant blocking serial interface.
-//! You may use any embedded-hal implementation to implement the legacy console.
-//! RustSBI legacy feature only supports blocking embedded-hal interface, as is defined in legacy
-//! SBI 0.1 specification.
 
 #![no_std]
 #![feature(ptr_metadata)]
 #![deny(warnings)] // cancel this line for developing
 
-extern crate alloc;
-
 #[cfg(feature = "legacy")]
 #[doc(hidden)]
 #[macro_use]

+ 1 - 0
src/util.rs

@@ -1,6 +1,7 @@
 //! useful structures
 
 use core::{arch::asm, cell::UnsafeCell, marker::PhantomData, mem::MaybeUninit, ptr::Pointee};
+
 /// 只使用 AMO 指令的一次初始化引用存储。
 pub struct AmoOnceRef<'a, T: ?Sized> {
     /// As atomic bool, to check if it is the first time to set `ptr`.