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
readkey(). The chip managing the keyboard on the IBM PC is the Intel
8042.
Syscall interface
NAME
readkey - handle the keyboard
SYNOPSIS
int readkey(struct key_event *event);
DESCRIPTION
readkey() returns the key events as a FIFO.
The `event` argument is a `struct key_event` (as specified in `<kstd.h>`):
struct key_event {
int state; /* KEY_PRESSED or KEY_RELEASED */
int key; /* scan code */
}
RETURN VALUE
readkey() returns 0 in case of success.
ERRORS
-EAGAIN no key event since last call.
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
readkey()as described previously - You should implement a queue for the keyboard 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
clior may not have been enabled withsti - The keyboard interrupt may be masked in the PIC