PKUOS - Pintos
Pintos source browser for PKU Operating System course
Data Structures | Macros | Functions | Variables
kbd.c File Reference
#include "devices/kbd.h"
#include <ctype.h>
#include <debug.h>
#include <stdio.h>
#include <string.h>
#include "devices/input.h"
#include "devices/shutdown.h"
#include "threads/interrupt.h"
#include "threads/io.h"
Include dependency graph for kbd.c:

Go to the source code of this file.

Data Structures

struct  keymap
 Maps a set of contiguous scancodes into characters. More...
 

Macros

#define DATA_REG   0x60
 Keyboard data register port. More...
 

Functions

void kbd_init (void)
 Initializes the keyboard. More...
 
void kbd_print_stats (void)
 Prints keyboard statistics. More...
 
static bool map_key (const struct keymap k[], unsigned scancode, uint8_t *c)
 Scans the array of keymaps K for SCANCODE. More...
 
static void keyboard_interrupt (struct intr_frame *args UNUSED)
 

Variables

static bool left_shift
 Current state of shift keys. More...
 
static bool right_shift
 Left and right Shift keys. More...
 
static bool left_alt
 
static bool right_alt
 Left and right Alt keys. More...
 
static bool left_ctrl
 
static bool right_ctrl
 Left and right Ctl keys. More...
 
static bool caps_lock
 Status of Caps Lock. More...
 
static int64_t key_cnt
 Number of keys pressed. More...
 
static intr_handler_func keyboard_interrupt
 
static const struct keymap invariant_keymap []
 Keys that produce the same characters regardless of whether the Shift keys are down. More...
 
static const struct keymap unshifted_keymap []
 Characters for keys pressed without Shift, for those keys where it matters. More...
 
static const struct keymap shifted_keymap []
 Characters for keys pressed with Shift, for those keys where it matters. More...
 

Macro Definition Documentation

◆ DATA_REG

#define DATA_REG   0x60

Keyboard data register port.

Definition at line 12 of file kbd.c.

Function Documentation

◆ kbd_init()

void kbd_init ( void  )

Initializes the keyboard.

Definition at line 31 of file kbd.c.

References intr_register_ext(), and keyboard_interrupt.

Referenced by pintos_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kbd_print_stats()

void kbd_print_stats ( void  )

Prints keyboard statistics.

devices/kbd.h

Definition at line 38 of file kbd.c.

References key_cnt, and printf().

Referenced by print_stats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ keyboard_interrupt()

static void keyboard_interrupt ( struct intr_frame *args  UNUSED)
static

◆ map_key()

static bool map_key ( const struct keymap  k[],
unsigned  scancode,
uint8_t c 
)
static

Scans the array of keymaps K for SCANCODE.

If found, sets *C to the corresponding character and returns true. If not found, returns false and C is ignored.

Definition at line 202 of file kbd.c.

References keymap::chars, keymap::first_scancode, and strlen().

Referenced by keyboard_interrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ caps_lock

bool caps_lock
static

Status of Caps Lock.

True when on, false when off.

Definition at line 22 of file kbd.c.

Referenced by keyboard_interrupt().

◆ invariant_keymap

const struct keymap invariant_keymap[]
static
Initial value:
=
{
{0x01, "\033"},
{0x0e, "\b"},
{0x0f, "\tQWERTYUIOP"},
{0x1c, "\r"},
{0x1e, "ASDFGHJKL"},
{0x2c, "ZXCVBNM"},
{0x37, "*"},
{0x39, " "},
{0x53, "\177"},
{0, NULL},
}
#define NULL
Definition: stddef.h:4

Keys that produce the same characters regardless of whether the Shift keys are down.

Case of letters is an exception that we handle elsewhere.

Definition at line 55 of file kbd.c.

Referenced by keyboard_interrupt().

◆ key_cnt

int64_t key_cnt
static

Number of keys pressed.

Definition at line 25 of file kbd.c.

Referenced by kbd_print_stats(), and keyboard_interrupt().

◆ keyboard_interrupt

intr_handler_func keyboard_interrupt
static

Definition at line 27 of file kbd.c.

Referenced by kbd_init().

◆ left_alt

bool left_alt
static

Definition at line 17 of file kbd.c.

Referenced by keyboard_interrupt().

◆ left_ctrl

bool left_ctrl
static

Definition at line 18 of file kbd.c.

Referenced by keyboard_interrupt().

◆ left_shift

bool left_shift
static

Current state of shift keys.

True if depressed, false otherwise.

Definition at line 16 of file kbd.c.

Referenced by keyboard_interrupt().

◆ right_alt

bool right_alt
static

Left and right Alt keys.

Definition at line 17 of file kbd.c.

Referenced by keyboard_interrupt().

◆ right_ctrl

bool right_ctrl
static

Left and right Ctl keys.

Definition at line 18 of file kbd.c.

Referenced by keyboard_interrupt().

◆ right_shift

bool right_shift
static

Left and right Shift keys.

Definition at line 16 of file kbd.c.

Referenced by keyboard_interrupt().

◆ shifted_keymap

const struct keymap shifted_keymap[]
static
Initial value:
=
{
{0x02, "!@#$%^&*()_+"},
{0x1a, "{}"},
{0x27, ":\"~"},
{0x2b, "|"},
{0x33, "<>?"},
{0, NULL},
}

Characters for keys pressed with Shift, for those keys where it matters.

Definition at line 83 of file kbd.c.

Referenced by keyboard_interrupt().

◆ unshifted_keymap

const struct keymap unshifted_keymap[]
static
Initial value:
=
{
{0x02, "1234567890-="},
{0x1a, "[]"},
{0x27, ";'`"},
{0x2b, "\\"},
{0x33, ",./"},
{0, NULL},
}

Characters for keys pressed without Shift, for those keys where it matters.

Definition at line 71 of file kbd.c.

Referenced by keyboard_interrupt().