Move reboot() and power_off() to new file, and rename to fit convention.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 9 Nov 2008 19:41:18 +0000 (11:41 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 9 Nov 2008 19:41:18 +0000 (11:41 -0800)
src/Makefile.build
src/devices/kbd.c
src/devices/shutdown.c [new file with mode: 0644]
src/devices/shutdown.h [new file with mode: 0644]
src/lib/kernel/debug.c
src/threads/init.c

index 4bd92202bb0838afdf16cdcd4956e67f8d71f889..ceb34121b6aeb5557097ad941f8119156c8ad323 100644 (file)
@@ -31,6 +31,7 @@ devices_SRC += devices/disk.c         # IDE disk device.
 devices_SRC += devices/input.c         # Serial and keyboard input.
 devices_SRC += devices/intq.c          # Interrupt queue.
 devices_SRC += devices/rtc.c           # Real-time clock.
 devices_SRC += devices/input.c         # Serial and keyboard input.
 devices_SRC += devices/intq.c          # Interrupt queue.
 devices_SRC += devices/rtc.c           # Real-time clock.
+devices_SRC += devices/shutdown.c      # Reboot and power off.
 
 # Library code shared between kernel and user programs.
 lib_SRC  = lib/debug.c                 # Debug helpers.
 
 # Library code shared between kernel and user programs.
 lib_SRC  = lib/debug.c                 # Debug helpers.
index 1aa71f5a3062c1888b3d3342d9a2d6675765b4e6..fcc82bed0680dee0a9b511b9284ec15b7b328b01 100644 (file)
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "devices/input.h"
 #include <stdio.h>
 #include <string.h>
 #include "devices/input.h"
-#include "threads/init.h"
+#include "devices/shutdown.h"
 #include "threads/interrupt.h"
 #include "threads/io.h"
 
 #include "threads/interrupt.h"
 #include "threads/io.h"
 
@@ -135,7 +135,7 @@ keyboard_interrupt (struct intr_frame *args UNUSED)
         {
           /* Reboot if Ctrl+Alt+Del pressed. */
           if (c == 0177 && ctrl && alt)
         {
           /* Reboot if Ctrl+Alt+Del pressed. */
           if (c == 0177 && ctrl && alt)
-            reboot ();
+            shutdown_reboot ();
 
           /* Handle Ctrl, Shift.
              Note that Ctrl overrides Shift. */
 
           /* Handle Ctrl, Shift.
              Note that Ctrl overrides Shift. */
diff --git a/src/devices/shutdown.c b/src/devices/shutdown.c
new file mode 100644 (file)
index 0000000..fbc662b
--- /dev/null
@@ -0,0 +1,100 @@
+#include "devices/shutdown.h"
+#include <console.h>
+#include <stdio.h>
+#include "devices/kbd.h"
+#include "devices/serial.h"
+#include "devices/timer.h"
+#include "threads/io.h"
+#include "threads/thread.h"
+#ifdef USERPROG
+#include "userprog/exception.h"
+#endif
+#ifdef FILESYS
+#include "devices/disk.h"
+#include "filesys/filesys.h"
+#endif
+
+/* Keyboard control register port. */
+#define CONTROL_REG 0x64
+
+static void print_stats (void);
+
+/* Reboots the machine via the keyboard controller. */
+void
+shutdown_reboot (void)
+{
+  int i;
+
+  printf ("Rebooting...\n");
+
+    /* See [kbd] for details on how to program the keyboard
+     * controller. */
+  for (i = 0; i < 100; i++)
+    {
+      int j;
+
+      /* Poll keyboard controller's status byte until
+       * 'input buffer empty' is reported. */
+      for (j = 0; j < 0x10000; j++)
+        {
+          if ((inb (CONTROL_REG) & 0x02) == 0)
+            break;
+          timer_udelay (2);
+        }
+
+      timer_udelay (50);
+
+      /* Pulse bit 0 of the output port P2 of the keyboard controller.
+       * This will reset the CPU. */
+      outb (CONTROL_REG, 0xfe);
+      timer_udelay (50);
+    }
+}
+
+/* Powers down the machine we're running on,
+   as long as we're running on Bochs or QEMU. */
+void
+shutdown_power_off (void)
+{
+  const char s[] = "Shutdown";
+  const char *p;
+
+#ifdef FILESYS
+  filesys_done ();
+#endif
+
+  print_stats ();
+
+  printf ("Powering off...\n");
+  serial_flush ();
+
+  /* This is a special power-off sequence supported by Bochs and
+     QEMU, but not by physical hardware. */
+  for (p = s; *p != '\0'; p++)
+    outb (0x8900, *p);
+
+  /* This will power off a VMware VM if "gui.exitOnCLIHLT = TRUE"
+     is set in its configuration file.  (The "pintos" script does
+     that automatically.)  */
+  asm volatile ("cli; hlt" : : : "memory");
+
+  /* None of those worked. */
+  printf ("still running...\n");
+  for (;;);
+}
+
+/* Print statistics about Pintos execution. */
+static void
+print_stats (void)
+{
+  timer_print_stats ();
+  thread_print_stats ();
+#ifdef FILESYS
+  disk_print_stats ();
+#endif
+  console_print_stats ();
+  kbd_print_stats ();
+#ifdef USERPROG
+  exception_print_stats ();
+#endif
+}
diff --git a/src/devices/shutdown.h b/src/devices/shutdown.h
new file mode 100644 (file)
index 0000000..0bc5657
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef DEVICES_SHUTDOWN_H
+#define DEVICES_SHUTDOWN_H
+
+void shutdown_reboot (void);
+void shutdown_power_off (void);
+
+#endif /* devices/shutdown.h */
index 22801954dd66512d489287a629371c6d88133ecf..43d8c1eddedd70e66c6de5e4b3b2586e45dd90ec 100644 (file)
@@ -11,6 +11,7 @@
 #include "threads/switch.h"
 #include "threads/vaddr.h"
 #include "devices/serial.h"
 #include "threads/switch.h"
 #include "threads/vaddr.h"
 #include "devices/serial.h"
+#include "devices/shutdown.h"
 
 /* Halts the OS, printing the source file name, line number, and
    function name, plus a user-specific message. */
 
 /* Halts the OS, printing the source file name, line number, and
    function name, plus a user-specific message. */
@@ -46,7 +47,7 @@ debug_panic (const char *file, int line, const char *function,
 
   serial_flush ();
   if (power_off_when_done)
 
   serial_flush ();
   if (power_off_when_done)
-    power_off ();
+    shutdown_power_off ();
   for (;;);
 }
 
   for (;;);
 }
 
index 8a037058a7358bea829c75153cfdca313570febd..01eec1120c923804083b747367b4e1a621ea5e19 100644 (file)
@@ -11,6 +11,7 @@
 #include "devices/kbd.h"
 #include "devices/input.h"
 #include "devices/serial.h"
 #include "devices/kbd.h"
 #include "devices/input.h"
 #include "devices/serial.h"
+#include "devices/shutdown.h"
 #include "devices/timer.h"
 #include "devices/vga.h"
 #include "devices/rtc.h"
 #include "devices/timer.h"
 #include "devices/vga.h"
 #include "devices/rtc.h"
@@ -64,9 +65,6 @@ static char **parse_options (char **argv);
 static void run_actions (char **argv);
 static void usage (void);
 
 static void run_actions (char **argv);
 static void usage (void);
 
-static void print_stats (void);
-
-
 int main (void) NO_RETURN;
 
 /* Pintos main program. */
 int main (void) NO_RETURN;
 
 /* Pintos main program. */
@@ -129,10 +127,10 @@ main (void)
 
   /* Finish up. */
   if (reboot_when_done)
 
   /* Finish up. */
   if (reboot_when_done)
-    reboot ();
+    shutdown_reboot ();
 
   if (power_off_when_done)
 
   if (power_off_when_done)
-    power_off ();
+    shutdown_power_off ();
   thread_exit ();
 }
 \f
   thread_exit ();
 }
 \f
@@ -376,80 +374,5 @@ usage (void)
           "  -ul=COUNT          Limit user memory to COUNT pages.\n"
 #endif
           );
           "  -ul=COUNT          Limit user memory to COUNT pages.\n"
 #endif
           );
-  power_off ();
-}
-
-/* Keyboard control register port. */
-#define CONTROL_REG 0x64
-
-/* Reboots the machine via the keyboard controller. */
-void
-reboot (void)
-{
-  int i;
-
-  printf ("Rebooting...\n");
-
-    /* See [kbd] for details on how to program the keyboard
-     * controller. */
-  for (i = 0; i < 100; i++) 
-    {
-      int j;
-
-      /* Poll keyboard controller's status byte until 
-       * 'input buffer empty' is reported. */
-      for (j = 0; j < 0x10000; j++) 
-        {
-          if ((inb (CONTROL_REG) & 0x02) == 0)   
-            break;
-          timer_udelay (2);
-        }
-
-      timer_udelay (50);
-
-      /* Pulse bit 0 of the output port P2 of the keyboard controller. 
-       * This will reset the CPU. */
-      outb (CONTROL_REG, 0xfe);
-      timer_udelay (50);
-    }
-}
-
-/* Powers down the machine we're running on,
-   as long as we're running on Bochs or QEMU. */
-void
-power_off (void) 
-{
-  const char s[] = "Shutdown";
-  const char *p;
-
-#ifdef FILESYS
-  filesys_done ();
-#endif
-
-  print_stats ();
-
-  printf ("Powering off...\n");
-  serial_flush ();
-
-  for (p = s; *p != '\0'; p++)
-    outb (0x8900, *p);
-  asm volatile ("cli; hlt" : : : "memory");
-  printf ("still running...\n");
-  for (;;);
-}
-
-/* Print statistics about Pintos execution. */
-static void
-print_stats (void) 
-{
-  timer_print_stats ();
-  thread_print_stats ();
-#ifdef FILESYS
-  disk_print_stats ();
-#endif
-  console_print_stats ();
-  kbd_print_stats ();
-#ifdef USERPROG
-  exception_print_stats ();
-#endif
+  shutdown_power_off ();
 }
 }