Skip to content

Commit 665a8f4

Browse files
committed
style(test-kernel): use sbi_rt directly
Signed-off-by: YdrMaster <ydrml@hotmail.com>
1 parent d464298 commit 665a8f4

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

test-kernel/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use riscv::register::{
1111
stvec::{self, TrapMode},
1212
};
1313

14-
extern crate sbi_rt as sbi;
15-
1614
#[macro_use]
1715
mod console;
1816
mod test;
@@ -28,7 +26,7 @@ use constants::*;
2826

2927
#[cfg_attr(not(test), panic_handler)]
3028
fn panic(info: &core::panic::PanicInfo) -> ! {
31-
use sbi::{system_reset, RESET_REASON_SYSTEM_FAILURE, RESET_TYPE_SHUTDOWN};
29+
use sbi_rt::{system_reset, RESET_REASON_SYSTEM_FAILURE, RESET_TYPE_SHUTDOWN};
3230

3331
let (hard_id, pc): (usize, usize);
3432
unsafe { asm!("mv {}, tp", out(reg) hard_id) };
@@ -90,7 +88,7 @@ extern "C" fn primary_rust_main(hartid: usize, dtb_pa: usize) -> ! {
9088

9189
test::hsm(hartid, smp);
9290

93-
sbi::system_reset(sbi::RESET_TYPE_SHUTDOWN, sbi::RESET_REASON_NO_REASON);
91+
sbi_rt::system_reset(sbi_rt::RESET_TYPE_SHUTDOWN, sbi_rt::RESET_REASON_NO_REASON);
9492
unreachable!()
9593
}
9694

test-kernel/src/test.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"
44
[test-kernel] Testing base extension"
55
);
6-
let base_version = sbi::probe_extension(sbi::EID_BASE);
6+
let base_version = sbi_rt::probe_extension(sbi_rt::EID_BASE);
77
if base_version == 0 {
88
panic!(
99
"\
@@ -12,7 +12,7 @@
1212
);
1313
}
1414

15-
let spec_version = sbi::get_spec_version();
15+
let spec_version = sbi_rt::get_spec_version();
1616
println!(
1717
"\
1818
[test-kernel] Base extension version: {base_version:x}
@@ -24,11 +24,11 @@
2424
[test-kernel] Device mimpid: {mimpid:x}",
2525
major = (spec_version >> 24) & 0x7F,
2626
minor = spec_version & 0xFFFFFF,
27-
impl_id = sbi::get_sbi_impl_id(),
28-
impl_version = sbi::get_sbi_impl_version(),
29-
mvendorid = sbi::get_mvendorid(),
30-
marchid = sbi::get_marchid(),
31-
mimpid = sbi::get_mimpid(),
27+
impl_id = sbi_rt::get_sbi_impl_id(),
28+
impl_version = sbi_rt::get_sbi_impl_version(),
29+
mvendorid = sbi_rt::get_mvendorid(),
30+
marchid = sbi_rt::get_marchid(),
31+
mimpid = sbi_rt::get_mimpid(),
3232
);
3333
}
3434

@@ -80,13 +80,14 @@ pub(crate) fn trap_delegate(hartid: usize) {
8080

8181
/// 所有副核:启动 -> 不可恢复休眠 -> 唤醒 -> 可恢复休眠 -> 唤醒 -> 关闭。
8282
pub(crate) fn hsm(hartid: usize, smp: usize) {
83-
const SUSPENDED: sbi::SbiRet = sbi::SbiRet {
84-
error: sbi::RET_SUCCESS,
85-
value: sbi::HART_STATE_SUSPENDED,
83+
use sbi_rt::SbiRet;
84+
const SUSPENDED: SbiRet = SbiRet {
85+
error: sbi_rt::RET_SUCCESS,
86+
value: sbi_rt::HART_STATE_SUSPENDED,
8687
};
87-
const STOPPED: sbi::SbiRet = sbi::SbiRet {
88-
error: sbi::RET_SUCCESS,
89-
value: sbi::HART_STATE_STOPPED,
88+
const STOPPED: SbiRet = SbiRet {
89+
error: sbi_rt::RET_SUCCESS,
90+
value: sbi_rt::HART_STATE_STOPPED,
9091
};
9192

9293
use spin::{Barrier, Once};
@@ -106,8 +107,8 @@ pub(crate) fn hsm(hartid: usize, smp: usize) {
106107

107108
extern "C" fn start_rust_main(hart_id: usize) -> ! {
108109
STARTED.wait().wait();
109-
let ret = sbi::hart_suspend(
110-
sbi::HART_SUSPEND_TYPE_NON_RETENTIVE,
110+
let ret = sbi_rt::hart_suspend(
111+
sbi_rt::HART_SUSPEND_TYPE_NON_RETENTIVE,
111112
test_entry as _,
112113
resume_rust_main as _,
113114
);
@@ -116,9 +117,9 @@ pub(crate) fn hsm(hartid: usize, smp: usize) {
116117

117118
extern "C" fn resume_rust_main(hart_id: usize) -> ! {
118119
RESUMED.wait().wait();
119-
let ret = sbi::hart_suspend(sbi::HART_SUSPEND_TYPE_RETENTIVE, 0, 0);
120-
assert_eq!(sbi::RET_SUCCESS, ret.error);
121-
let ret = sbi::hart_stop();
120+
let ret = sbi_rt::hart_suspend(sbi_rt::HART_SUSPEND_TYPE_RETENTIVE, 0, 0);
121+
assert_eq!(sbi_rt::RET_SUCCESS, ret.error);
122+
let ret = sbi_rt::hart_stop();
122123
unreachable!("stop [{hart_id}] but {ret:?}");
123124
}
124125

@@ -133,8 +134,8 @@ pub(crate) fn hsm(hartid: usize, smp: usize) {
133134
for id in 0..smp {
134135
if id != hartid {
135136
println!("[test-kernel] Hart{id} is booting...");
136-
let ret = sbi::hart_start(id, test_entry as _, start_rust_main as _);
137-
if ret.error != sbi::RET_SUCCESS {
137+
let ret = sbi_rt::hart_start(id, test_entry as _, start_rust_main as _);
138+
if ret.error != sbi_rt::RET_SUCCESS {
138139
panic!("[test-kernel] Start hart{id} failed: {ret:?}");
139140
}
140141
} else {
@@ -147,7 +148,7 @@ pub(crate) fn hsm(hartid: usize, smp: usize) {
147148
// 等待副核休眠(不可恢复)
148149
for id in 0..smp {
149150
if id != hartid {
150-
while sbi::hart_get_status(id) != SUSPENDED {
151+
while sbi_rt::hart_get_status(id) != SUSPENDED {
151152
core::hint::spin_loop();
152153
}
153154
println!("[test-kernel] Hart{id} suspended.");
@@ -156,21 +157,21 @@ pub(crate) fn hsm(hartid: usize, smp: usize) {
156157
}
157158
}
158159
// 全部唤醒
159-
sbi::send_ipi(0, -1isize as usize);
160+
sbi_rt::send_ipi(0, -1isize as usize);
160161
// 等待副核恢复完成
161162
resumed.wait();
162163
print!("[test-kernel] All harts resume successfully!\n");
163164
for id in 0..smp {
164165
if id != hartid {
165166
// 等待副核休眠
166-
while sbi::hart_get_status(id) != SUSPENDED {
167+
while sbi_rt::hart_get_status(id) != SUSPENDED {
167168
core::hint::spin_loop();
168169
}
169170
print!("[test-kernel] Hart{id} suspended, ");
170171
// 单独唤醒
171-
sbi::send_ipi(1usize << id, 0);
172+
sbi_rt::send_ipi(1usize << id, 0);
172173
// 等待副核关闭
173-
while sbi::hart_get_status(id) != STOPPED {
174+
while sbi_rt::hart_get_status(id) != STOPPED {
174175
core::hint::spin_loop();
175176
}
176177
println!("then stopped.");

0 commit comments

Comments
 (0)