X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdevices%2Fkbd.c;h=1ddf3e243c38220640016f3beb02280b5fa6f049;hb=865cfbaabf666e24567b598ea355b87dea02bfbb;hp=9cd28400864abddcc1a18fa586eaf5951d9a96bb;hpb=eb718e3b5a5470b11e58dcc652f79e115272257a;p=pintos-anon diff --git a/src/devices/kbd.c b/src/devices/kbd.c index 9cd2840..1ddf3e2 100644 --- a/src/devices/kbd.c +++ b/src/devices/kbd.c @@ -25,14 +25,17 @@ static unsigned shift_state; /* Keyboard buffer. */ static struct intq buffer; +/* Number of keys pressed. */ +static int64_t key_cnt; + static intr_handler_func keyboard_interrupt; /* Initializes the keyboard. */ void kbd_init (void) { - intq_init (&buffer, "keyboard"); - intr_register (0x21, 0, INTR_OFF, keyboard_interrupt, "8042 Keyboard"); + intq_init (&buffer); + intr_register_ext (0x21, keyboard_interrupt, "8042 Keyboard"); } /* Retrieves a key from the keyboard buffer. @@ -49,6 +52,13 @@ kbd_getc (void) return key; } + +/* Prints keyboard statistics. */ +void +kbd_print_stats (void) +{ + printf ("Keyboard: %lld keys pressed\n", key_cnt); +} /* Maps a set of contiguous scancodes into characters. */ struct keymap @@ -160,8 +170,11 @@ keyboard_interrupt (struct intr_frame *args UNUSED) c += 0x80; /* Append to keyboard buffer. */ - if (!intq_full (&buffer)) - intq_putc (&buffer, c); + if (!intq_full (&buffer)) + { + key_cnt++; + intq_putc (&buffer, c); + } } } else