From f63ad250f45f7d41e704c785870de861402567b2 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Sun, 14 Dec 2025 14:48:59 -0800 Subject: [PATCH] implement restarting --- src/arch/arm64/mod.rs | 10 ++++++++++ src/arch/mod.rs | 3 +++ src/kernel/power.rs | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/arch/arm64/mod.rs b/src/arch/arm64/mod.rs index 25adea3..fc03dba 100644 --- a/src/arch/arm64/mod.rs +++ b/src/arch/arm64/mod.rs @@ -121,6 +121,16 @@ impl Arch for Aarch64 { Self::halt() } + fn restart() -> ! { + const PSCI_SYSTEM_RESET: u32 = 0x8400_0009; + unsafe { + psci::do_psci_hyp_call(PSCI_SYSTEM_RESET, 0, 0, 0); + } + + // Fallback: halt the CPU indefinitely. + Self::halt() + } + unsafe fn copy_from_user( src: UA, dst: *mut (), diff --git a/src/arch/mod.rs b/src/arch/mod.rs index 8886252..ef58ca0 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -42,6 +42,9 @@ pub trait Arch: CpuOps + VirtualMemory { /// Powers off the machine. Implementations must never return. fn power_off() -> !; + /// Restarts the machine. Implementations must never return. + fn restart() -> !; + /// Call a user-specified signal handler in the current process. fn do_signal( sig: SigId, diff --git a/src/kernel/power.rs b/src/kernel/power.rs index 72d9d31..e0cd0f7 100644 --- a/src/kernel/power.rs +++ b/src/kernel/power.rs @@ -12,7 +12,7 @@ pub async fn sys_reboot(magic: u32, magic2: u32, op: u32, _arg: usize) -> Result // const LINUX_REBOOT_CMD_HALT: u32 = 0xcdef_0123; // const LINUX_REBOOT_CMD_KEXEC: u32 = 0x4558_4543; const LINUX_REBOOT_CMD_POWER_OFF: u32 = 0x4321_fedc; - // const LINUX_REBOOT_CMD_RESTART: u32 = 0x0123_4567; + const LINUX_REBOOT_CMD_RESTART: u32 = 0x0123_4567; // const LINUX_REBOOT_CMD_RESTART2: u32 = 0xa1b2_c3d4; // const LINUX_REBOOT_CMD_SW_SUSPEND: u32 = 0xd000_fce1; if magic != LINUX_REBOOT_MAGIC1 @@ -28,6 +28,7 @@ pub async fn sys_reboot(magic: u32, magic2: u32, op: u32, _arg: usize) -> Result // User is supposed to sync first. ArchImpl::power_off() } + LINUX_REBOOT_CMD_RESTART => ArchImpl::restart(), // TODO: Implement other reboot operations. _ => Err(KernelError::InvalidValue), }