Keyboard
Description
The keyboard driver is used to add a first form of input in k. It just detects
when a key is pressed by configuring the keyboard controller to trigger
interrupt when a key is pressed. You have to implement the non-blocking syscall
getkey()
. The chip managing the keyboard on the IBM PC is the Intel
8042.
Syscall interface
NAME
getkey - handle the keyboard
SYNOPSIS
int getkey(void);
DESCRIPTION
getkey() returns the last pressed key. It does not support simultaneous key strikes.
RETURN VALUE
getkey() returns the key code, or -1 if no key was pressed.
SEE ALSO
Useful constants for scan codes are defined in k/kstd.h.
Recommended methodology
- Ensure that the event manager is working
- Initialize the driver:
- Add the keyboard interrupt gate to the IDT
- Update the PIC to unmask the IRQ line 1
- Write a very simple keyboard handler:
- Read scancodes from I/O port
0x60
- Extra features such as modifier keys or simultaneous key strikes support are not mandatory
- Read scancodes from I/O port
- Implement
getkey()
as described previously - You might implement a queue for the keyboard buffer
- You don’t have to push released keys in the buffer
Possible bug causes
- Execution context may be corrupted. Check twice whether the context is correctly restored and whether the stack is well adjusted before returning from interrupt handler
- Hardware interrupts may have been disabled with
cli
or may not have been enabled withsti
- The keyboard interrupt may be masked in the PIC