X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Fdevices%2Fshutdown.c;h=61c76f7b060d2746ae6fa1763feede4f895db200;hp=4c978f970216169d69b34d061ae7c1c3d746f857;hb=f5fa837e313d018a945eaedd28352e7f24e5b1a6;hpb=9a4067dc5bd3d810ce4b1d9dd8ba394dee4c247b diff --git a/src/devices/shutdown.c b/src/devices/shutdown.c index 4c978f9..61c76f7 100644 --- a/src/devices/shutdown.c +++ b/src/devices/shutdown.c @@ -10,15 +10,48 @@ #include "userprog/exception.h" #endif #ifdef FILESYS -#include "devices/disk.h" +#include "devices/block.h" #include "filesys/filesys.h" #endif /* Keyboard control register port. */ #define CONTROL_REG 0x64 +/* How to shut down when shutdown() is called. */ +static enum shutdown_type how = SHUTDOWN_NONE; + static void print_stats (void); +/* Shuts down the machine in the way configured by + shutdown_configure(). If the shutdown type is SHUTDOWN_NONE + (which is the default), returns without doing anything. */ +void +shutdown (void) +{ + switch (how) + { + case SHUTDOWN_POWER_OFF: + shutdown_power_off (); + break; + + case SHUTDOWN_REBOOT: + shutdown_reboot (); + break; + + default: + /* Nothing to do. */ + break; + } +} + +/* Sets TYPE as the way that machine will shut down when Pintos + execution is complete. */ +void +shutdown_configure (enum shutdown_type type) +{ + how = type; +} + /* Reboots the machine via the keyboard controller. */ void shutdown_reboot (void) @@ -66,6 +99,9 @@ shutdown_power_off (void) printf ("Powering off...\n"); serial_flush (); + /* ACPI power-off */ + outw (0xB004, 0x2000); + /* This is a special power-off sequence supported by Bochs and QEMU, but not by physical hardware. */ for (p = s; *p != '\0'; p++) @@ -88,7 +124,7 @@ print_stats (void) timer_print_stats (); thread_print_stats (); #ifdef FILESYS - disk_print_stats (); + block_print_stats (); #endif console_print_stats (); kbd_print_stats ();