From c2a4bc3367ece2c2dbfa21692672751b499072a4 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 23 Jan 2024 21:52:41 +0000 Subject: [PATCH] without semihosting support, use the firmware for a shutdown --- Cargo.toml | 5 +++-- src/arch/aarch64/kernel/processor.rs | 16 +++++++++++++++- src/arch/riscv64/kernel/processor.rs | 9 +++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 785e3bca8c..486af9bba9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ udp = ["smoltcp", "smoltcp/socket-udp"] trace = [] vga = [] common-os = [] +semihosting = [] [dependencies] ahash = { version = "0.8", default-features = false } @@ -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" diff --git a/src/arch/aarch64/kernel/processor.rs b/src/arch/aarch64/kernel/processor.rs index 592e3f7dbc..7536679297 100644 --- a/src/arch/aarch64/kernel/processor.rs +++ b/src/arch/aarch64/kernel/processor.rs @@ -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] diff --git a/src/arch/riscv64/kernel/processor.rs b/src/arch/riscv64/kernel/processor.rs index 56ac9a3317..832fd5edee 100644 --- a/src/arch/riscv64/kernel/processor.rs +++ b/src/arch/riscv64/kernel/processor.rs @@ -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 {