X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdevices%2Fkbd.c;h=a26498477cb3397c5f1d771b06303c5c6c3ffaaf;hb=cad1898695fa89ab8354db670865a3e1a0d91654;hp=ea9835876a53626e11d00d663e92b7501c4ba157;hpb=e27b29c73bebb27cf263ce10f58669ac8bdfc51a;p=pintos-anon diff --git a/src/devices/kbd.c b/src/devices/kbd.c index ea98358..a264984 100644 --- a/src/devices/kbd.c +++ b/src/devices/kbd.c @@ -25,6 +25,9 @@ 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. */ @@ -40,14 +43,22 @@ kbd_init (void) uint8_t kbd_getc (void) { + enum intr_level old_level; uint8_t key; - - intq_lock (&buffer); + + old_level = intr_disable (); key = intq_getc (&buffer); - intq_unlock (&buffer); + intr_set_level (old_level); 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 @@ -159,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