implement restarting

This commit is contained in:
Ashwin Naren
2025-12-14 14:48:59 -08:00
committed by Matthew Leach
parent b8edd4af68
commit f63ad250f4
3 changed files with 15 additions and 1 deletions

View File

@@ -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 (),

View File

@@ -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,

View File

@@ -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),
}