Skip to content

Commit 4f56ee9

Browse files
luojia65gmacd
authored andcommitted
riscv64: use SBI SRST extension instead of legacy SBI for system shutdown
Legacy SBI have been deprecated years ago (on Jun 9, 2021). Modern RISC-V SBI firmware would use SBI SRST extension to shutdown an S-mode environment; we use `sbi-rt` crate for this purpose. Unused feature gate `opensbi` is removed, as RISC-V SBI support does not usually satisfy which implementation we'd use, unless e.g. fixing implementation-specific bugs. Signed-off-by: Zhouqi Jiang <[email protected]>
1 parent 0cda5c2 commit 4f56ee9

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Cargo.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

riscv64/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ default-target = "riscv64gc-unknown-none-elf"
88

99
[dependencies]
1010
port = { path = "../port" }
11+
sbi-rt = "0.0.3"
1112

1213
[features]
13-
opensbi = []
1414

1515
[lints.rust]
1616
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(platform, values("nezha"))', 'cfg(platform, values("virt"))'] }

riscv64/src/sbi.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub fn _consgetb() -> u8 {
4949
}
5050

5151
pub fn shutdown() -> ! {
52-
sbi_call_legacy(SBI_SHUTDOWN, 0, 0, 0);
53-
panic!("shutdown failed!");
52+
sbi_rt::system_reset(sbi_rt::Shutdown, sbi_rt::NoReason);
53+
loop {
54+
unsafe { core::arch::asm!("wfi") }
55+
}
5456
}

0 commit comments

Comments
 (0)