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

Go to the source code of this file.

Macros

#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
 

Macro Definition Documentation

◆ SHIFT

#define SHIFT   1

Definition at line 36 of file pc_kbd.c.

◆ CONTROL

#define CONTROL   2

Definition at line 37 of file pc_kbd.c.

◆ CAPS

#define CAPS   4

Definition at line 38 of file pc_kbd.c.

Function Documentation

◆ get_scancode()

static int get_scancode ( void  )
static

Definition at line 40 of file pc_kbd.c.

41 {
42  int scan;
43 
44  if ((inb(0x64) & 1) == 0)
45  return 0;
46  scan = inb(0x60);
47 
48  switch (scan) {
49  case 0x2a:
50  case 0x36:
51  shift_state |= SHIFT;
52  break;
53  case 0xaa:
54  case 0xb6:
55  shift_state &= ~SHIFT;
56  break;
57  case 0x1d:
59  break;
60  case 0x9d:
61  shift_state &= ~CONTROL;
62  break;
63  case 0x3a:
64  shift_state ^= CAPS;
65  break;
66  }
67 
68  if (scan & 0x80)
69  return 0; /* ignore break code or 0xe0 etc! */
70  return scan;
71 }
#define SHIFT
Definition: pc_kbd.c:36
uint8_t inb(volatile uint8_t *io_addr)
Read byte from I/O-mapped device.
#define CONTROL
Definition: pc_kbd.c:37
static unsigned int shift_state
Definition: pc_kbd.c:35
#define CAPS
Definition: pc_kbd.c:38

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

Referenced by kbd_havekey().

◆ kbd_havekey()

static int kbd_havekey ( void  )
static

Definition at line 73 of file pc_kbd.c.

74 {
75  if (!cur_scan)
77  return cur_scan != 0;
78 }
static int get_scancode(void)
Definition: pc_kbd.c:40
static int cur_scan
Definition: pc_kbd.c:34

References cur_scan, and get_scancode().

Referenced by kbd_ischar().

◆ kbd_ischar()

static int kbd_ischar ( void  )
static

Definition at line 80 of file pc_kbd.c.

81 {
82  if (!kbd_havekey())
83  return 0;
84  if (!key_map[shift_state & SHIFT][cur_scan]) {
85  cur_scan = 0;
86  return 0;
87  }
88  return 1;
89 }
static int kbd_havekey(void)
Definition: pc_kbd.c:73
#define SHIFT
Definition: pc_kbd.c:36
static char key_map[][128]
Definition: pc_kbd.c:16
static unsigned int shift_state
Definition: pc_kbd.c:35
static int cur_scan
Definition: pc_kbd.c:34

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

Referenced by kbd_getc().

◆ kbd_getc()

static int kbd_getc ( void  )
static

Definition at line 91 of file pc_kbd.c.

92 {
93  int c;
94 
95  while (!kbd_ischar())
96  ;
98  if (shift_state & (CONTROL | CAPS)) {
99  if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
100  if (shift_state & CONTROL)
101  c &= 0x1f;
102  else if (shift_state & CAPS)
103  c ^= ('A' ^ 'a');
104  }
105  }
106  cur_scan = 0;
107  return c;
108 }
static __always_inline void off_t int c
Definition: efi_uaccess.h:87
#define SHIFT
Definition: pc_kbd.c:36
static char key_map[][128]
Definition: pc_kbd.c:16
static int kbd_ischar(void)
Definition: pc_kbd.c:80
#define CONTROL
Definition: pc_kbd.c:37
static unsigned int shift_state
Definition: pc_kbd.c:35
#define CAPS
Definition: pc_kbd.c:38
static int cur_scan
Definition: pc_kbd.c:34

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

Variable Documentation

◆ key_map

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().

◆ cur_scan

int cur_scan
static

Definition at line 34 of file pc_kbd.c.

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

◆ shift_state

unsigned int shift_state
static

Definition at line 35 of file pc_kbd.c.

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

◆ __console_driver

struct console_driver pc_kbd_console __console_driver
Initial value:
= {
.getchar = kbd_getc,
}
static int kbd_getc(void)
Definition: pc_kbd.c:91

Definition at line 110 of file pc_kbd.c.