Skip to content

Commit

Permalink
riscv64: use SBI SRST extension instead of legacy SBI for system shut…
Browse files Browse the repository at this point in the history
…down

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]>
  • Loading branch information
luojia65 authored and gmacd committed Oct 24, 2024
1 parent 0cda5c2 commit 4f56ee9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion riscv64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ default-target = "riscv64gc-unknown-none-elf"

[dependencies]
port = { path = "../port" }
sbi-rt = "0.0.3"

[features]
opensbi = []

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(platform, values("nezha"))', 'cfg(platform, values("virt"))'] }
6 changes: 4 additions & 2 deletions riscv64/src/sbi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub fn _consgetb() -> u8 {
}

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

0 comments on commit 4f56ee9

Please sign in to comment.