/* 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)
#include <debug.h>
+/* 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;
}
serial_flush ();
- if (power_off_when_done)
- shutdown_power_off ();
+ shutdown ();
for (;;);
}
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;
run_actions (argv);
/* Finish up. */
- if (reboot_when_done)
- shutdown_reboot ();
-
- if (power_off_when_done)
- shutdown_power_off ();
+ shutdown ();
thread_exit ();
}
\f
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);
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;
/* 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 */