Reboot when Ctrl+Alt+Del is pressed.
[pintos-anon] / src / devices / kbd.c
index e48d1b98291cb3571476d93eab5f958d1a00f6fe..1aa71f5a3062c1888b3d3342d9a2d6675765b4e6 100644 (file)
@@ -3,7 +3,8 @@
 #include <debug.h>
 #include <stdio.h>
 #include <string.h>
-#include "devices/intq.h"
+#include "devices/input.h"
+#include "threads/init.h"
 #include "threads/interrupt.h"
 #include "threads/io.h"
 
@@ -20,9 +21,6 @@ static bool left_ctrl, right_ctrl;      /* Left and right Ctl keys. */
    True when on, false when off. */
 static bool caps_lock;
 
-/* Keyboard buffer. */
-static struct intq buffer;
-
 /* Number of keys pressed. */
 static int64_t key_cnt;
 
@@ -32,25 +30,9 @@ static intr_handler_func keyboard_interrupt;
 void
 kbd_init (void) 
 {
-  intq_init (&buffer);
   intr_register_ext (0x21, keyboard_interrupt, "8042 Keyboard");
 }
 
-/* Retrieves a key from the keyboard buffer.
-   If the buffer is empty, waits for a key to be pressed. */
-uint8_t
-kbd_getc (void) 
-{
-  enum intr_level old_level;
-  uint8_t key;
-
-  old_level = intr_disable ();
-  key = intq_getc (&buffer);
-  intr_set_level (old_level);
-  
-  return key;
-}
-
 /* Prints keyboard statistics. */
 void
 kbd_print_stats (void) 
@@ -72,14 +54,15 @@ struct keymap
    that we handle elsewhere.  */
 static const struct keymap invariant_keymap[] = 
   {
-    {0x01, "\033"},
+    {0x01, "\033"},             /* Escape. */
     {0x0e, "\b"},
     {0x0f, "\tQWERTYUIOP"},
-    {0x1c, "\n"},
+    {0x1c, "\r"},
     {0x1e, "ASDFGHJKL"},
     {0x2c, "ZXCVBNM"},
     {0x37, "*"},
     {0x39, " "},
+    {0x53, "\177"},             /* Delete. */
     {0, NULL},
   };
 
@@ -150,6 +133,10 @@ keyboard_interrupt (struct intr_frame *args UNUSED)
       /* Ordinary character. */
       if (!release) 
         {
+          /* Reboot if Ctrl+Alt+Del pressed. */
+          if (c == 0177 && ctrl && alt)
+            reboot ();
+
           /* Handle Ctrl, Shift.
              Note that Ctrl overrides Shift. */
           if (ctrl && c >= 0x40 && c < 0x60) 
@@ -167,10 +154,10 @@ keyboard_interrupt (struct intr_frame *args UNUSED)
             c += 0x80;
 
           /* Append to keyboard buffer. */
-          if (!intq_full (&buffer)) 
+          if (!input_full ())
             {
               key_cnt++;
-              intq_putc (&buffer, c); 
+              input_putc (c);
             }
         }
     }