From ba667148af04963f5d70c647511ea1fad1add21d Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 16:01:46 +0200 Subject: power: proper shutdown via UEFI ResetSystem (ACPI S5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - uefi.rs: full EFI_RUNTIME_SERVICES layout with reset_system at index 10 (spec order); EfiResetSystem type + RESET_* constants - power.rs: stash the runtime-services table pre-EBS; poweroff() calls ResetSystem(EfiResetShutdown) — still callable after ExitBootServices because we never call SetVirtualAddressMap, so the pointers keep working with physical addresses; falls back to the hlt loop - shell: 'poweroff' and 'exit' shut the machine down (QEMU exits), 'halt' keeps the plain hlt loop --- shell/src/lib.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'shell') diff --git a/shell/src/lib.rs b/shell/src/lib.rs index 4d5ba9c..5cab122 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs @@ -40,7 +40,8 @@ pub fn run() -> ! { "help" => cmd_help(), "echo" => cmd_echo(args), "clear" => cmd_clear(), - "halt" | "poweroff" | "exit" => cmd_halt(), + "halt" => cmd_halt(), + "poweroff" | "exit" => cmd_poweroff(), "hello" => { gop_println!("World!"); serial_println!("World!"); @@ -123,10 +124,11 @@ fn cmd_help() { gop_println!(" mem — show memory info"); gop_println!(" mmap — dump the UEFI memory map"); gop_println!(" stress — stress-test heap/page allocators"); - gop_println!(" halt — halt the system"); - gop_println!(" exit — alias for halt"); + gop_println!(" halt — halt the system (hlt loop)"); + gop_println!(" poweroff — shut down via ACPI (ResetSystem)"); + gop_println!(" exit — alias for poweroff"); serial_println!("available commands:"); - serial_println!(" help, echo, clear, hello, info, mem, mmap, stress, halt, exit"); + serial_println!(" help, echo, clear, hello, info, mem, mmap, stress, halt, poweroff, exit"); } fn cmd_echo(args: &str) { @@ -359,11 +361,13 @@ fn cmd_stress(args: &str) { fn cmd_halt() -> ! { gop_println!("halting..."); serial_println!("halting..."); - loop { - unsafe { - core::arch::asm!("cli; hlt"); - } - } + rsnix::power::halt() +} + +fn cmd_poweroff() -> ! { + gop_println!("shutting down..."); + serial_println!("shutting down..."); + rsnix::power::poweroff() } // --------------------------------------------------------------------------- -- cgit v1.2.3