Skip to content

Commit

Permalink
without semihosting support, use the firmware for a shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Jan 23, 2024
1 parent 9dbdcdd commit c2a4bc3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ udp = ["smoltcp", "smoltcp/socket-udp"]
trace = []
vga = []
common-os = []
semihosting = []

[dependencies]
ahash = { version = "0.8", default-features = false }
Expand Down Expand Up @@ -127,14 +128,14 @@ qemu-exit = "3.0"
aarch64 = { version = "0.0", default-features = false }
arm-gic = { version = "0.1" }
hermit-dtb = { version = "0.1" }
semihosting = { version = "0.1", default-features = false }
semihosting = { version = "0.1" }

[target.'cfg(target_arch = "riscv64")'.dependencies]
fdt = "0.1"
riscv = "0.11"
sbi = "0.2"
trapframe = "0.9"
semihosting = { version = "0.1", default-features = false }
semihosting = { version = "0.1" }

[dev-dependencies]
float-cmp = "0.9"
Expand Down
16 changes: 15 additions & 1 deletion src/arch/aarch64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,21 @@ pub fn halt() {
/// Shutdown the system
pub fn shutdown() -> ! {
info!("Shutting down system");
semihosting::process::exit(0);

if cfg!(feature = "semihosting") {
semihosting::process::exit(0)
} else {
unsafe {
const PSCI_SYSTEM_OFF: u64 = 0x84000008;
// call firmware to shut down the system
asm!("hvc #0", in("x0") PSCI_SYSTEM_OFF, options(nomem, nostack));

// we should never reach this point
loop {
asm!("wfe", options(nomem, nostack));
}
}
}
}

#[inline]
Expand Down
9 changes: 7 additions & 2 deletions src/arch/riscv64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,13 @@ pub fn halt() {
/// Shutdown the system
pub fn shutdown() -> ! {
info!("Shutting down system");
//SBI shutdown
sbi::legacy::shutdown()

if cfg!(feature = "semihosting") {
semihosting::process::exit(0)
} else {
// use SBI shutdown
sbi::legacy::shutdown()
}
}

pub fn get_timer_ticks() -> u64 {
Expand Down

0 comments on commit c2a4bc3

Please sign in to comment.