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)
28 printf ("Rebooting...\n");
30 /* See [kbd] for details on how to program the keyboard
32 for (i = 0; i < 100; i++)
36 /* Poll keyboard controller's status byte until
37 * 'input buffer empty' is reported. */
38 for (j = 0; j < 0x10000; j++)
40 if ((inb (CONTROL_REG) & 0x02) == 0)
47 /* Pulse bit 0 of the output port P2 of the keyboard controller.
48 * This will reset the CPU. */
49 outb (CONTROL_REG, 0xfe);
54 /* Powers down the machine we're running on,
55 as long as we're running on Bochs or QEMU. */
57 shutdown_power_off (void)
59 const char s[] = "Shutdown";
68 printf ("Powering off...\n");
71 /* This is a special power-off sequence supported by Bochs and
72 QEMU, but not by physical hardware. */
73 for (p = s; *p != '\0'; p++)
76 /* This will power off a VMware VM if "gui.exitOnCLIHLT = TRUE"
77 is set in its configuration file. (The "pintos" script does
78 that automatically.) */
79 asm volatile ("cli; hlt" : : : "memory");
81 /* None of those worked. */
82 printf ("still running...\n");
86 /* Print statistics about Pintos execution. */
91 thread_print_stats ();
95 console_print_stats ();
98 exception_print_stats ();