Skip to content

Commit ff916db

Browse files
committed
refactor: 依赖新版本 rustsbi
1 parent 195b9b6 commit ff916db

File tree

6 files changed

+21
-89
lines changed

6 files changed

+21
-89
lines changed

Cargo.lock

Lines changed: 4 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustsbi-qemu/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ readme = "README.md"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
rustsbi = { git = "https://github.com/rustsbi/rustsbi.git", rev = "40c2985" }
10+
rustsbi = { git = "https://github.com/YdrMaster/rustsbi.git", rev = "bdd67f8" }
1111
riscv = "0.8"
12-
embedded-hal = "0.2.7"
1312
spin = "0.9"
1413
r0 = "1"
15-
nb = "1"
1614
buddy_system_allocator = "0.8"
1715
uart_16550 = "0.2"
1816
dtb-walker = { git = "https://github.com/YdrMaster/dtb-walker.git", rev = "0ef2209" }

rustsbi-qemu/src/clint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Clint {
3838
}
3939
}
4040

41-
impl Ipi for &'static Clint {
41+
impl Ipi for Clint {
4242
#[inline]
4343
fn send_ipi_many(&self, hart_mask: HartMask) -> SbiRet {
4444
let hsm = crate::HSM.wait();
@@ -51,7 +51,7 @@ impl Ipi for &'static Clint {
5151
}
5252
}
5353

54-
impl Timer for &'static Clint {
54+
impl Timer for Clint {
5555
#[inline]
5656
fn set_timer(&self, time_value: u64) {
5757
unsafe {

rustsbi-qemu/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ use core::sync::atomic::{AtomicBool, Ordering::AcqRel};
110110
use device_tree::BoardInfo;
111111
use spin::Once;
112112

113+
#[link_section = ".bss.uninit"]
114+
static mut SERIAL: Option<ns16550a::Ns16550a> = None;
115+
113116
#[link_section = ".bss.uninit"]
114117
static HSM: Once<qemu_hsm::QemuHsm> = Once::new();
115118

@@ -133,13 +136,13 @@ extern "C" fn rust_main(_hartid: usize, opaque: usize) {
133136
// 初始化外设
134137
clint::init(board_info.clint.start);
135138
test_device::init(board_info.test.start);
136-
let uart = unsafe { ns16550a::Ns16550a::new(board_info.uart.start) };
139+
unsafe { SERIAL = Some(ns16550a::Ns16550a::new(board_info.uart.start)) };
137140
let hsm = HSM.call_once(|| qemu_hsm::QemuHsm::new(clint::get(), NUM_HART_MAX, opaque));
138141
// 初始化 SBI 服务
139-
rustsbi::legacy_stdio::init_legacy_stdio_embedded_hal(uart);
142+
rustsbi::legacy_stdio::init_legacy_stdio(unsafe { SERIAL.as_mut() }.unwrap());
140143
rustsbi::init_ipi(clint::get());
141144
rustsbi::init_timer(clint::get());
142-
rustsbi::init_reset(test_device::get().clone());
145+
rustsbi::init_reset(test_device::get());
143146
rustsbi::init_hsm(hsm);
144147
// 打印启动信息
145148
print!(
@@ -156,7 +159,7 @@ extern "C" fn rust_main(_hartid: usize, opaque: usize) {
156159
[rustsbi] Supervisor Address : {SUPERVISOR_ENTRY:#x}
157160
",
158161
ver_sbi = rustsbi::VERSION,
159-
logo = rustsbi::LOGO,
162+
logo = rustsbi::logo(),
160163
ver_impl = env!("CARGO_PKG_VERSION"),
161164
model = board_info.model,
162165
smp = board_info.smp,

rustsbi-qemu/src/ns16550a.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use core::convert::Infallible;
2-
use embedded_hal::serial::{Read, Write};
1+
use rustsbi::legacy_stdio::LegacyStdio;
32
use uart_16550::MmioSerialPort;
43

54
pub(crate) struct Ns16550a(MmioSerialPort);
@@ -10,23 +9,12 @@ impl Ns16550a {
109
}
1110
}
1211

13-
impl Read<u8> for Ns16550a {
14-
type Error = Infallible;
15-
16-
fn read(&mut self) -> nb::Result<u8, Self::Error> {
17-
Ok(self.0.receive())
18-
}
19-
}
20-
21-
impl Write<u8> for Ns16550a {
22-
type Error = Infallible;
23-
24-
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
25-
self.0.send(word);
26-
Ok(())
12+
impl LegacyStdio for Ns16550a {
13+
fn getchar(&mut self) -> u8 {
14+
self.0.receive()
2715
}
2816

29-
fn flush(&mut self) -> nb::Result<(), Self::Error> {
30-
Ok(())
17+
fn putchar(&mut self, ch: u8) {
18+
self.0.send(ch);
3119
}
3220
}

rustsbi-qemu/src/qemu_hsm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl QemuHsm {
194194
}
195195

196196
// Adapt RustSBI interface to RustSBI-QEMU's QemuHsm.
197-
impl rustsbi::Hsm for &'static QemuHsm {
197+
impl rustsbi::Hsm for QemuHsm {
198198
fn hart_start(&self, hart_id: usize, start_addr: usize, opaque: usize) -> SbiRet {
199199
use core::sync::atomic::Ordering::{AcqRel, Acquire};
200200
use riscv::register::mstatus::{self, MPP};

0 commit comments

Comments
 (0)