System information

5 Device Emulation
1. Keyboard sends one byte to the controller.
2. Controller stores the byte in the output buffer.
3. Controller activates the interrupt line.
4. Device driver reads out one byte at port 0x60.
Port Mode Description
0x64 read Status Register
0x64 write Command Register
0x60 read Output Register
0x60 write Data Register
Table 5.4: Register of the 8042 keyboard controller.
The CHARM card does not interface with the physical keyboard interface of the keyboard
controller. Instead, the CHARM card writes the keystrokes with the aid of the controller
ports to the output buffer. The following simplified C-code illustrates this process:
outb(0x64,0xD2);
outb(0x60,keycode);
First, the CHARM card setups the keyboard controller. The command 0xD2 tells the
controller that the next data byte written to port 0x60 is written to the output register as
if initiated by a device. Afterwards, the code of the pressed key is written to port 0x60.
By the way, the USB keyboard legacy driver of the computer BIOS uses a similar way
to forward keystrokes. The keyboard controller informs the host CPU that new data are
available. The host CPU reads out the keyboard controller output buffer and processes the
data.
5.2.2 BIOS Keyboard Buffer
Some computer BIOS does not process keystroke if no physical device is plugged into the
computer. The CHARM card cannot use the keyboard controller in such a case. But the
BIOS administrates a keyboard buffer to store the received keystrokes [61, 74]. The buffer
is located in the BIOS memory area. It starts at 0x41E and is 32 bytes in length. The
buffer is organized as a circular buffer. A start and an end pointers maintain the buffer.
The word (2 bytes) at 0x41A holds the current head, the start pointer of the BIOS keyboard
buffer. Furthermore, the word (2 bytes) at 0x41C holds the current tail, the end pointer of
the BIOS keyboard buffer.
Figure 5.9 depicts the keyboard buffer of the BIOS. A keystroke is stored into two bytes.
The first byte is the ASCII
12
representation of the pressed key. The second byte is the scan-
code of the key. A scancode is the number or sequence of numbers assigned to each key on
the keyboard. Since every key is stored into two bytes, the standard BIOS keyboard buffer
12
American Standard Code for Information Interchange.
76