Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using crate semihosting on aarch64 #1040

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading