iPXE
Defines | Functions | Variables
pc_kbd.c File Reference
#include <ipxe/io.h>
#include <ipxe/console.h>

Go to the source code of this file.

Defines

#define SHIFT   1
#define CONTROL   2
#define CAPS   4

Functions

static int get_scancode (void)
static int kbd_havekey (void)
static int kbd_ischar (void)
static int kbd_getc (void)

Variables

static char key_map [][128]
static int cur_scan
static unsigned int shift_state
struct console_driver
pc_kbd_console 
__console_driver

Define Documentation

#define SHIFT   1

Definition at line 36 of file pc_kbd.c.

Referenced by get_scancode(), kbd_getc(), and kbd_ischar().

#define CONTROL   2

Definition at line 37 of file pc_kbd.c.

Referenced by get_scancode(), and kbd_getc().

#define CAPS   4

Definition at line 38 of file pc_kbd.c.

Referenced by get_scancode(), and kbd_getc().


Function Documentation

static int get_scancode ( void  ) [static]

Definition at line 40 of file pc_kbd.c.

References CAPS, CONTROL, inb(), SHIFT, and shift_state.

Referenced by kbd_havekey().

{
    int scan;

    if ((inb(0x64) & 1) == 0)
        return 0;
    scan = inb(0x60);

    switch (scan) {
    case 0x2a:
    case 0x36:
        shift_state |= SHIFT;
        break;
    case 0xaa:
    case 0xb6:
        shift_state &= ~SHIFT;
        break;
    case 0x1d:
        shift_state |= CONTROL;
        break;
    case 0x9d:
        shift_state &= ~CONTROL;
        break;
    case 0x3a:
        shift_state ^= CAPS;
        break;
    }

    if (scan & 0x80)
        return 0; /* ignore break code or 0xe0 etc! */
    return scan;
}
static int kbd_havekey ( void  ) [static]

Definition at line 73 of file pc_kbd.c.

References cur_scan, and get_scancode().

Referenced by kbd_ischar().

{
    if (!cur_scan)
        cur_scan = get_scancode();
    return cur_scan != 0;
}
static int kbd_ischar ( void  ) [static]

Definition at line 80 of file pc_kbd.c.

References cur_scan, kbd_havekey(), key_map, SHIFT, and shift_state.

Referenced by kbd_getc().

{
    if (!kbd_havekey())
        return 0;
    if (!key_map[shift_state & SHIFT][cur_scan]) {
        cur_scan = 0;
        return 0;
    }
    return 1;
}
static int kbd_getc ( void  ) [static]

Definition at line 91 of file pc_kbd.c.

References CAPS, CONTROL, cur_scan, kbd_ischar(), key_map, SHIFT, and shift_state.

{
    int c;

    while (!kbd_ischar())
        ;
    c = key_map[shift_state & SHIFT][cur_scan];
    if (shift_state & (CONTROL | CAPS)) {
        if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
            if (shift_state & CONTROL)
                c &= 0x1f;
            else if (shift_state & CAPS)
                c ^= ('A' ^ 'a');
        }
    }
    cur_scan = 0;
    return c;
}

Variable Documentation

char key_map[][128] [static]
Initial value:
 {
    {
        "\0\x1b""1234567890-=\b\t"
        "qwertyuiop[]\r\0as"
        "dfghjkl;'`\0\\zxcv"
        "bnm,./\0*\0 \0\0\0\0\0\0"
        "\0\0\0\0\0\0\0""789-456+1"
        "230."
    },{
        "\0\x1b""!@#$%^&*()_+\b\t"
        "QWERTYUIOP{}\r\0AS"
        "DFGHJKL:\"~\0|ZXCV"
        "BNM<>?\0\0\0 \0\0\0\0\0\0"
        "\0\0\0\0\0\0\0""789-456+1"
        "230."
    }
}

Definition at line 16 of file pc_kbd.c.

Referenced by kbd_getc(), and kbd_ischar().

int cur_scan [static]

Definition at line 34 of file pc_kbd.c.

Referenced by kbd_getc(), kbd_havekey(), and kbd_ischar().

unsigned int shift_state [static]

Definition at line 35 of file pc_kbd.c.

Referenced by get_scancode(), kbd_getc(), and kbd_ischar().

struct console_driver pc_kbd_console __console_driver
Initial value:
 {
        .getchar = kbd_getc,
}

Definition at line 110 of file pc_kbd.c.