Skip to content

Commit

Permalink
using crate semihosting on aarch64
Browse files Browse the repository at this point in the history
This crate provides access to semihosting, a mechanism for
programs running on the real or virtual (e.g., QEMU) target
to communicate with I/O facilities on the host system.

Co-authored-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
stlankes and mkroening committed Jan 25, 2024
1 parent b4d04d6 commit 9283123
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion 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 = ["dep:semihosting"]

[dependencies]
ahash = { version = "0.8", default-features = false }
Expand All @@ -85,7 +86,6 @@ num-traits = { version = "0.2", default-features = false }
pci-ids = { version = "0.2", optional = true }
pci_types = { version = "0.6" }
pflock = "0.2"
qemu-exit = "3.0"
rand_chacha = { version = "0.3", default-features = false }
shell-words = { version = "1.1", default-features = false }
smallvec = { version = "1", features = ["const_new"] }
Expand Down Expand Up @@ -122,17 +122,20 @@ multiboot = "0.8"
uart_16550 = "0.3"
x86 = { version = "0.52", default-features = false }
x86_64 = "0.14"
qemu-exit = "3.0"

[target.'cfg(target_arch = "aarch64")'.dependencies]
aarch64 = { version = "0.0", default-features = false }
arm-gic = { version = "0.1" }
hermit-dtb = { version = "0.1" }
semihosting = { version = "0.1", optional = true }

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

[dev-dependencies]
float-cmp = "0.9"
Expand Down
19 changes: 16 additions & 3 deletions src/arch/aarch64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use core::{fmt, str};
use aarch64::regs::{Readable, CNTFRQ_EL0};
use hermit_dtb::Dtb;
use hermit_sync::{without_interrupts, Lazy};
use qemu_exit::QEMUExit;

use crate::arch::aarch64::kernel::boot_info;
use crate::env;
Expand Down Expand Up @@ -119,8 +118,22 @@ pub fn halt() {
pub fn shutdown() -> ! {
info!("Shutting down system");

let exit_handler = qemu_exit::AArch64::new();
exit_handler.exit_success();
cfg_if::cfg_if! {
if #[cfg(feature = "semihosting")] {
semihosting::process::exit(0)
} else {
unsafe {
const PSCI_SYSTEM_OFF: u64 = 0x84000008;
// call hypervisor 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
11 changes: 9 additions & 2 deletions src/arch/riscv64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,15 @@ pub fn halt() {
/// Shutdown the system
pub fn shutdown() -> ! {
info!("Shutting down system");
//SBI shutdown
sbi::legacy::shutdown()

cfg_if::cfg_if! {
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 9283123

Please sign in to comment.