1 #include "devices/shutdown.h"
4 #include "devices/kbd.h"
5 #include "devices/serial.h"
6 #include "devices/timer.h"
7 #include "threads/io.h"
8 #include "threads/thread.h"
10 #include "userprog/exception.h"
13 #include "devices/disk.h"
14 #include "filesys/filesys.h"
17 /* Keyboard control register port. */
18 #define CONTROL_REG 0x64
20 static void print_stats (void);
22 /* Reboots the machine via the keyboard controller. */
24 shutdown_reboot (void)
26 printf ("Rebooting...\n");
28 /* See [kbd] for details on how to program the keyboard
34 /* Poll keyboard controller's status byte until
35 * 'input buffer empty' is reported. */
36 for (i = 0; i < 0x10000; i++)
38 if ((inb (CONTROL_REG) & 0x02) == 0)
45 /* Pulse bit 0 of the output port P2 of the keyboard controller.
46 * This will reset the CPU. */
47 outb (CONTROL_REG, 0xfe);
52 /* Powers down the machine we're running on,
53 as long as we're running on Bochs or QEMU. */
55 shutdown_power_off (void)
57 const char s[] = "Shutdown";
66 printf ("Powering off...\n");
69 /* This is a special power-off sequence supported by Bochs and
70 QEMU, but not by physical hardware. */
71 for (p = s; *p != '\0'; p++)
74 /* This will power off a VMware VM if "gui.exitOnCLIHLT = TRUE"
75 is set in its configuration file. (The "pintos" script does
76 that automatically.) */
77 asm volatile ("cli; hlt" : : : "memory");
79 /* None of those worked. */
80 printf ("still running...\n");
84 /* Print statistics about Pintos execution. */
89 thread_print_stats ();
93 console_print_stats ();
96 exception_print_stats ();