From: Ben Pfaff Date: Mon, 10 Nov 2008 00:19:48 +0000 (-0800) Subject: Get rid of power_off_when_done global variable. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94618414d6e0e051cf95e900c63ed2835ed16a82;p=pintos-anon Get rid of power_off_when_done global variable. This global variable was not named according to the convention that a global variable name start with its module name. Furthermore, its usage was somewhat scattered across the source tree. This commit introduces new functions shutdown() and shutdown_configure() to improve the situation. --- diff --git a/src/devices/shutdown.c b/src/devices/shutdown.c index 4c978f9..42b67df 100644 --- a/src/devices/shutdown.c +++ b/src/devices/shutdown.c @@ -17,8 +17,41 @@ /* 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) diff --git a/src/devices/shutdown.h b/src/devices/shutdown.h index 7bcef19..dc4f942 100644 --- a/src/devices/shutdown.h +++ b/src/devices/shutdown.h @@ -3,6 +3,16 @@ #include +/* How to shut down when Pintos has nothing left to do. */ +enum shutdown_type + { + SHUTDOWN_NONE, /* Loop forever. */ + SHUTDOWN_POWER_OFF, /* Power off the machine (if possible). */ + SHUTDOWN_REBOOT, /* Reboot the machine (if possible). */ + }; + +void shutdown (void); +void shutdown_configure (enum shutdown_type); void shutdown_reboot (void) NO_RETURN; void shutdown_power_off (void) NO_RETURN; diff --git a/src/lib/kernel/debug.c b/src/lib/kernel/debug.c index 43d8c1e..b12f4f9 100644 --- a/src/lib/kernel/debug.c +++ b/src/lib/kernel/debug.c @@ -46,8 +46,7 @@ debug_panic (const char *file, int line, const char *function, } serial_flush (); - if (power_off_when_done) - shutdown_power_off (); + shutdown (); for (;;); } diff --git a/src/threads/init.c b/src/threads/init.c index 01eec11..f804b86 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -48,12 +48,6 @@ uint32_t *init_page_dir; static bool format_filesys; #endif -/* -q: Power off after kernel tasks complete? */ -bool power_off_when_done; - -/* -r: Reboot after kernel tasks complete? */ -static bool reboot_when_done; - /* -ul: Maximum number of pages to put into palloc's user pool. */ static size_t user_page_limit = SIZE_MAX; @@ -126,11 +120,7 @@ main (void) run_actions (argv); /* Finish up. */ - if (reboot_when_done) - shutdown_reboot (); - - if (power_off_when_done) - shutdown_power_off (); + shutdown (); thread_exit (); } @@ -169,7 +159,7 @@ paging_init (void) pd = init_page_dir = palloc_get_page (PAL_ASSERT | PAL_ZERO); pt = NULL; - for (page = 0; page < ram_pages; page++) + for (page = 0; page < ram_pages; page++) { uintptr_t paddr = page * PGSIZE; char *vaddr = ptov (paddr); @@ -243,9 +233,9 @@ parse_options (char **argv) if (!strcmp (name, "-h")) usage (); else if (!strcmp (name, "-q")) - power_off_when_done = true; + shutdown_configure (SHUTDOWN_POWER_OFF); else if (!strcmp (name, "-r")) - reboot_when_done = true; + shutdown_configure (SHUTDOWN_REBOOT); #ifdef FILESYS else if (!strcmp (name, "-f")) format_filesys = true; diff --git a/src/threads/init.h b/src/threads/init.h index 06cf71e..a5c7500 100644 --- a/src/threads/init.h +++ b/src/threads/init.h @@ -12,7 +12,4 @@ extern size_t ram_pages; /* Page directory with kernel mappings only. */ extern uint32_t *init_page_dir; -/* -q: Power off when kernel tasks complete? */ -extern bool power_off_when_done; - #endif /* threads/init.h */