소스 검색

Add poweroff command

Johannes Zellner 7 달 전
부모
커밋
6af54144a6
1개의 변경된 파일과 15개의 추가작업 그리고 0개의 파일을 삭제
  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");
+}