Skip to content

Commit 301acab

Browse files
committed
rustsbi-qemu: hart counting fixes, update to RustSBI 0.2.1
Signed-off-by: luojia65 <me@luojia.cc>
1 parent 0c5cd6e commit 301acab

File tree

7 files changed

+23
-28
lines changed

7 files changed

+23
-28
lines changed

Cargo.lock

Lines changed: 5 additions & 5 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rustsbi = "0.2.0"
9+
rustsbi = "0.2.1"
1010
buddy_system_allocator = "0.8"
1111
lazy_static = { version = "1", features = ["spin_no_std"] }
1212
spin = "0.9"

rustsbi-qemu/src/clint.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,11 @@ impl Clint {
5050
}
5151

5252
impl Ipi for Clint {
53-
#[inline]
54-
fn max_hart_id(&self) -> usize {
55-
// 这个值将在初始化的时候加载,会从dtb_pa读取设备树,然后数里面有几个核
56-
*crate::count_harts::MAX_HART_ID.lock()
57-
}
58-
5953
#[inline]
6054
fn send_ipi_many(&self, hart_mask: HartMask) -> SbiRet {
6155
// println!("[rustsbi] send ipi many, {:?}", hart_mask);
62-
for i in 0..=self.max_hart_id() {
56+
let num_harts = *crate::count_harts::NUM_HARTS.lock();
57+
for i in 0..num_harts {
6358
if hart_mask.has_bit(i) {
6459
self.send_soft(i);
6560
}

rustsbi-qemu/src/count_harts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use device_tree::{DeviceTree, Node};
2+
23
const DEVICE_TREE_MAGIC: u32 = 0xD00DFEED;
34

45
lazy_static::lazy_static! {
56
// 最大的硬件线程编号;只在启动时写入,跨核软中断发生时读取
6-
pub static ref MAX_HART_ID: spin::Mutex<usize> = spin::Mutex::new(8);
7+
pub static ref NUM_HARTS: spin::Mutex<usize> = spin::Mutex::new(8);
78
}
89

910
pub unsafe fn init_hart_count(dtb_pa: usize) {
10-
*MAX_HART_ID.lock() = count_harts(dtb_pa)
11+
*NUM_HARTS.lock() = count_harts(dtb_pa)
1112
}
1213

1314
#[repr(C)]

rustsbi-qemu/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod hart_csr_utils;
2222
mod ns16550a;
2323
mod prv_mem;
2424
mod qemu_hsm;
25+
mod qemu_pmu;
2526
mod runtime;
2627
mod test_device;
2728

@@ -88,8 +89,8 @@ extern "C" fn rust_main(hartid: usize, opqaue: usize) -> ! {
8889
hart_csr_utils::print_hart_csrs();
8990
// start other harts
9091
let clint = clint::Clint::new(0x2000000 as *mut u8);
91-
let max_hart_id = *{ count_harts::MAX_HART_ID.lock() };
92-
for target_hart_id in 0..max_hart_id {
92+
let num_harts = *{ count_harts::NUM_HARTS.lock() };
93+
for target_hart_id in 0..num_harts {
9394
if target_hart_id != 0 {
9495
clint.send_soft(target_hart_id);
9596
}

rustsbi-qemu/src/qemu_pmu.rs

Whitespace-only changes.

test-kernel/src/main.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44
#![no_std]
55
#![no_main]
66

7-
#[macro_use]
8-
mod console;
9-
mod mm;
10-
mod sbi;
11-
127
use core::arch::asm;
8+
use core::panic::PanicInfo;
9+
1310
use riscv::register::{
1411
scause::{self, Exception, Trap},
1512
sepc,
1613
stvec::{self, TrapMode},
1714
};
1815

16+
#[macro_use]
17+
mod console;
18+
mod mm;
19+
mod sbi;
20+
1921
pub extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
2022
if hartid == 0 {
2123
// initialization
@@ -59,14 +61,12 @@ pub extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
5961
"<< Test-kernel: test for hart {} success, wake another hart",
6062
hartid
6163
);
62-
let bv: usize = 0b10;
63-
let sbi_ret = sbi::send_ipi(&bv as *const _ as usize, hartid); // wake hartid + 1
64+
let sbi_ret = sbi::send_ipi(0b10, 0); // wake hart 1
6465
println!(">> Wake hart 1, sbi return value {:?}", sbi_ret);
6566
loop {} // wait for machine shutdown
6667
} else if hartid == 1 {
6768
// send software IPI to activate hart 2
68-
let bv: usize = 0b10;
69-
let sbi_ret = sbi::send_ipi(&bv as *const _ as usize, hartid); // wake hartid + 1
69+
let sbi_ret = sbi::send_ipi(0b1, 2);
7070
println!(">> Wake hart 2, sbi return value {:?}", sbi_ret);
7171
loop {}
7272
} else {
@@ -153,8 +153,6 @@ pub extern "C" fn rust_trap_exception() {
153153
sepc::write(sepc::read().wrapping_add(4));
154154
}
155155

156-
use core::panic::PanicInfo;
157-
158156
#[cfg_attr(not(test), panic_handler)]
159157
#[allow(unused)]
160158
fn panic(info: &PanicInfo) -> ! {

0 commit comments

Comments
 (0)