Browse Source

Update RustSBI impl

luojia65 4 years ago
parent
commit
9bd8590238
4 changed files with 18 additions and 20 deletions
  1. 3 3
      src/ecall.rs
  2. 10 10
      src/ecall/base.rs
  3. 3 3
      src/legacy_stdio.rs
  4. 2 4
      src/lib.rs

+ 3 - 3
src/ecall.rs

@@ -7,13 +7,13 @@ mod base;
 const EXTENSION_BASE: usize = 0x10;
 
 /// You should call this function in your runtime's exception handler.
-/// If the incoming exception is caused by `ecall`, 
-/// call this function with parameters extracted from trap frame. 
+/// If the incoming exception is caused by `ecall`,
+/// call this function with parameters extracted from trap frame.
 #[inline]
 pub fn handle_ecall(extension: usize, function: usize, param: [usize; 4]) -> SbiRet {
     match extension {
         EXTENSION_BASE => base::handle_ecall_base(function, param[0]),
-        _ => todo!()
+        _ => todo!(),
     }
 }
 

+ 10 - 10
src/ecall/base.rs

@@ -1,15 +1,15 @@
 //! base extension
 use super::SbiRet;
 use crate::{SBI_SPEC_MAJOR, SBI_SPEC_MINOR};
-use riscv::register::{mvendorid, marchid, mimpid};
+use riscv::register::{marchid, mimpid, mvendorid};
 
 const FUNCTION_BASE_GET_SPEC_VERSION: usize = 0x0;
-const FUNCTION_BASE_GET_SBI_IMPL_ID: usize  = 0x1;
+const FUNCTION_BASE_GET_SBI_IMPL_ID: usize = 0x1;
 const FUNCTION_BASE_GET_SBI_IMPL_VERSION: usize = 0x2;
-const FUNCTION_BASE_PROBE_EXTENSION: usize  = 0x3;
-const FUNCTION_BASE_GET_MVENDORID: usize    = 0x4;
-const FUNCTION_BASE_GET_MARCHID: usize      = 0x5;
-const FUNCTION_BASE_GET_MIMPID: usize       = 0x6;
+const FUNCTION_BASE_PROBE_EXTENSION: usize = 0x3;
+const FUNCTION_BASE_GET_MVENDORID: usize = 0x4;
+const FUNCTION_BASE_GET_MARCHID: usize = 0x5;
+const FUNCTION_BASE_GET_MIMPID: usize = 0x6;
 
 pub fn handle_ecall_base(function: usize, param0: usize) -> SbiRet {
     match function {
@@ -20,13 +20,13 @@ pub fn handle_ecall_base(function: usize, param0: usize) -> SbiRet {
         FUNCTION_BASE_GET_MVENDORID => get_mvendorid(),
         FUNCTION_BASE_GET_MARCHID => get_marchid(),
         FUNCTION_BASE_GET_MIMPID => get_mimpid(),
-        _ => unimplemented!()
+        _ => unimplemented!(),
     }
 }
 
 #[inline]
 fn get_spec_version() -> SbiRet {
-    let spec_version = ((SBI_SPEC_MAJOR << 24) | (SBI_SPEC_MINOR)).into();
+    let spec_version = (SBI_SPEC_MAJOR << 24) | (SBI_SPEC_MINOR);
     SbiRet::ok(spec_version)
 }
 
@@ -43,8 +43,8 @@ fn get_sbi_impl_version() -> SbiRet {
 }
 
 #[inline]
-fn probe_extension(extension_id: usize) -> SbiRet {
-    drop(extension_id); // todo use
+fn probe_extension(_extension_id: usize) -> SbiRet {
+    // drop(extension_id); // todo use
     let extension_return = 0; // todo: 可配置
     SbiRet::ok(extension_return)
 }

+ 3 - 3
src/legacy_stdio.rs

@@ -13,7 +13,7 @@ pub trait LegacyStdio {
 
 /// Use serial in `embedded-hal` as legacy standard input/output
 pub struct EmbeddedHalSerial<T> {
-    inner: T
+    inner: T,
 }
 
 impl<T> EmbeddedHalSerial<T> {
@@ -29,8 +29,8 @@ impl<T> EmbeddedHalSerial<T> {
 }
 
 impl<T> LegacyStdio for EmbeddedHalSerial<T>
-where 
-    T: Read<u8> + Write<u8>
+where
+    T: Read<u8> + Write<u8>,
 {
     fn getchar(&mut self) -> u8 {
         // 直接调用embedded-hal里面的函数

+ 2 - 4
src/lib.rs

@@ -15,8 +15,8 @@ todo:考虑这个库是不是单例的。
 #![no_std]
 #![feature(naked_functions)] // 未来稳定后去掉
 
-pub mod legacy_stdio;
 pub mod ecall;
+pub mod legacy_stdio;
 
 const SBI_SPEC_MAJOR: usize = 0;
 const SBI_SPEC_MINOR: usize = 2;
@@ -31,9 +31,7 @@ pub struct Builder<'b> {
 impl<'b> Builder<'b> {
     /// Create a new instance builder
     pub fn new() -> Self {
-        Builder {
-            legacy_stdio: None
-        }
+        Builder { legacy_stdio: None }
     }
 
     /// Wrap a stdio handler for legacy `getchar` and `putchar` functions