From ca511b98f3c1b7556fd07e656919d0b6ab328a9b Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Fri, 1 Feb 2019 20:12:06 -0700
Subject: [PATCH] Add code to shut down QEMU with it's default ACPI settings,
 run cli hlt in loop

---
 src/arch/x86_64/stop.rs | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/arch/x86_64/stop.rs b/src/arch/x86_64/stop.rs
index ec0b23a6..909757fb 100644
--- a/src/arch/x86_64/stop.rs
+++ b/src/arch/x86_64/stop.rs
@@ -36,9 +36,17 @@ pub unsafe extern fn kstop() -> ! {
         Pio::<u8>::new(port).write(c);
     }
 
+    // Magic shutdown using qemu default ACPI method
+    {
+        let port = 0x604;
+        let data = 0x2000;
+        println!("Shutdown with outb(0x{:X}, 0x{:X})", port, data);
+        Pio::<u16>::new(port).write(data);
+    }
+
     // Magic code for VMWare. Also a hard lock.
     println!("Shutdown with cli hlt");
-    asm!("cli; hlt" : : : : "intel", "volatile");
-
-    unreachable!();
+    loop {
+        asm!("cli; hlt" : : : : "intel", "volatile");
+    }
 }
-- 
GitLab