Parcourir la source

Add poweroff command

Johannes Zellner il y a 7 mois
Parent
commit
6af54144a6
1 fichiers modifiés avec 15 ajouts et 0 suppressions
  1. 15 0
      poweroff.c

+ 15 - 0
poweroff.c

@@ -0,0 +1,15 @@
+/* Poweroff command: shut down the virtual machine (QEMU/Bochs ACPI port). */
+
+static inline void outw(unsigned short port, unsigned short v)
+{
+	__asm__ volatile ("outw %0, %%dx" : : "a"(v), "d"(port));
+}
+
+void program_poweroff_main(void)
+{
+	/* Bochs/QEMU "ACPI" shutdown — see https://wiki.osdev.org/Shutdown */
+	outw(0x604, 0x2000);
+	outw(0xB004, 0x2000);
+	for (;;)
+		__asm__ volatile ("hlt");
+}