Skip to content

Commit 0b13333

Browse files
committed
Using sbi-rt instead of asm && update rustsbi-qemu to latest
rustsbi-qemu version: a4f0bbe44d9f2f1069a9e5becd09f291e542852c
1 parent cf34027 commit 0b13333

File tree

6 files changed

+18
-116
lines changed

6 files changed

+18
-116
lines changed

bootloader/rustsbi-qemu.bin

-6.44 KB
Binary file not shown.

os/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ edition = "2021"
88

99
[dependencies]
1010
log = "0.4"
11+
sbi-rt = { version = "0.0.2", features = ["legacy"] }
12+
1113
[profile.release]
1214
debug = true

os/src/boards/qemu.rs

Lines changed: 0 additions & 79 deletions
This file was deleted.

os/src/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ fn panic(info: &PanicInfo) -> ! {
1515
} else {
1616
println!("[kernel] Panicked: {}", info.message().unwrap());
1717
}
18-
shutdown()
18+
shutdown(true)
1919
}

os/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ mod lang_items;
2222
mod logging;
2323
mod sbi;
2424

25-
#[path = "boards/qemu.rs"]
26-
mod board;
27-
2825
global_asm!(include_str!("entry.asm"));
2926

3027
/// clear BSS segment
@@ -73,7 +70,7 @@ pub fn rust_main() -> ! {
7370
);
7471
error!("[kernel] .bss [{:#x}, {:#x})", sbss as usize, ebss as usize);
7572

76-
use crate::board::QEMUExit;
77-
crate::board::QEMU_EXIT_HANDLE.exit_success(); // CI autotest success
78-
//crate::board::QEMU_EXIT_HANDLE.exit_failure(); // CI autoest failed
73+
// CI autotest success: sbi::shutdown(false)
74+
// CI autotest failed : sbi::shutdown(true)
75+
sbi::shutdown(false)
7976
}

os/src/sbi.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
11
#![allow(unused)]
22

3-
use core::arch::asm;
4-
5-
const SBI_SET_TIMER: usize = 0;
6-
const SBI_CONSOLE_PUTCHAR: usize = 1;
7-
const SBI_CONSOLE_GETCHAR: usize = 2;
8-
const SBI_SHUTDOWN: usize = 8;
9-
10-
#[inline(always)]
11-
fn sbi_call(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize {
12-
let mut ret;
13-
unsafe {
14-
asm!(
15-
"li x16, 0",
16-
"ecall",
17-
inlateout("x10") arg0 => ret,
18-
in("x11") arg1,
19-
in("x12") arg2,
20-
in("x17") which,
21-
);
22-
}
23-
ret
24-
}
25-
263
/// use sbi call to putchar in console (qemu uart handler)
274
pub fn console_putchar(c: usize) {
28-
sbi_call(SBI_CONSOLE_PUTCHAR, c, 0, 0);
5+
#[allow(deprecated)]
6+
sbi_rt::legacy::console_putchar(c);
297
}
308

319
/// use sbi call to getchar from console (qemu uart handler)
3210
pub fn console_getchar() -> usize {
33-
sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
11+
#[allow(deprecated)]
12+
sbi_rt::legacy::console_getchar()
3413
}
3514

36-
use crate::board::QEMUExit;
3715
/// use sbi call to shutdown the kernel
38-
pub fn shutdown() -> ! {
39-
crate::board::QEMU_EXIT_HANDLE.exit_failure();
40-
41-
panic!("It should shutdown!");
16+
pub fn shutdown(failure: bool) -> ! {
17+
use sbi_rt::{system_reset, NoReason, Shutdown, SystemFailure};
18+
if !failure {
19+
system_reset(Shutdown, NoReason);
20+
} else {
21+
system_reset(Shutdown, SystemFailure);
22+
}
23+
unreachable!()
4224
}

0 commit comments

Comments
 (0)