17 #define KB_PORT_DATA 0x60 23 #define BSP KEY_BACKSPACE 26 #define ESC KEY_ESCAPE 30 #define PSC KEY_PRTSCR 31 #define CLK KEY_CAPSLOCK 32 #define NLK KEY_NUMLOCK 33 #define SLK KEY_SCRLOCK 34 #define KIN KEY_INSERT 39 #define KCT KEY_CENTER 59 #define SES KEY_SCANESC 60 #define INV KEY_INVALID 69 INV,
ESC,
'!',
'@',
'#',
'$',
'%',
'^',
70 '&',
'*',
'(',
')',
'_',
'+',
BSP,
TAB,
71 'Q',
'W',
'E',
'R',
'T',
'Y',
'U',
'I',
72 'O',
'P',
'{',
'}',
ENT,
CTL,
'A',
'S',
73 'D',
'F',
'G',
'H',
'J',
'K',
'L',
':',
74 '"',
'~',
SHF,
'|',
'Z',
'X',
'C',
'V',
75 'B',
'N',
'M',
'<',
'>',
'?',
SHF,
PSC,
88 INV,
ESC,
'1',
'2',
'3',
'4',
'5',
'6',
89 '7',
'8',
'9',
'0',
'-',
'=',
BSP,
TAB,
90 'q',
'w',
'e',
'r',
't',
'y',
'u',
'i',
91 'o',
'p',
'[',
']',
ENT,
CTL,
'a',
's',
92 'd',
'f',
'g',
'h',
'j',
'k',
'l',
';',
94 'b',
'n',
'm',
',',
'.',
'/',
SHF,
PSC,
118 typedef struct kbstate kbstate_t;
126 if (
state.meta & flag)
160 atomic_fetch_add_explicit(&
state.buf_size, 1, memory_order_relaxed);
170 bool keyup = !!(scancode & 0x80);
179 uint8_t ukeycode =
state.layout.unshifted[scancode];
190 if ((ukeycode >=
'a') && (ukeycode <=
'z'))
195 uint8_t
keycode = shifted ?
state.layout.shifted[scancode] : ukeycode;
246 if (keycode < 0x80) {
254 if ((ukeycode >=
'a') && (ukeycode <=
'z'))
255 ch = (char)(ukeycode -
'a' + 1);
300 if (atomic_compare_exchange_strong(&
state.buf_size, &size, 0))
309 atomic_fetch_sub_explicit(&
state.buf_size, 1, memory_order_relaxed);
323 if (atomic_compare_exchange_strong(&
state.buf_size, &size, 0)) {
324 *(uint32_t *)key = 0;
334 atomic_fetch_sub_explicit(&
state.buf_size, 1, memory_order_relaxed);
bool kb_getkey(key_t *key)
Return the available next key from the keyboard's input buffer.
#define PIC_PORT_CMD_MASTER
Command port for master PIC.
uint8_t kb_meta()
Return the current meta-key bit mask.
#define KEYBRK_DOWN
Key-down break code.
#define META_SHIFT
Set while the shift key is pressed.
__forceinline uint8_t io_inb(uint16_t port)
#define META_SCRLOCK
Set while scroll lock is on.
__forceinline void io_outb(uint16_t port, uint8_t value)
#define PIC_CMD_EOI
End of interrupt.
String and memory operations.
key_t buf[MAX_BUFSIZ]
Buffer holding unconsumed keys.
#define TRAP_IRQ_KEYBOARD
void isr_set(int interrupt, isr_handler handler)
Set an interrupt service routine for the given interrupt number.
#define META_CAPSLOCK
Set while caps lock is on.
keylayout_t layout
The installed keyboard layout.
static const keylayout_t ps2_layout
US English PSC/2 keyboard scan map (default setting)
void kb_init()
Initialize the keyboard so that it can provide input to the kernel.
atomic_uchar buf_size
Number of keys in the buf.
char kb_getchar()
Return the next available character from the keyboard's input buffer.
void kb_setlayout(keylayout_t *layout)
Install a new keyboard layout.
#define META_CTRL
Set while the ctrl key is pressed.
#define KEYBRK_UP
Key-up break code.
uint8_t buf_head
Index of oldest key in buf.
#define META_NUMLOCK
Set while num lock is on.
static void toggle(uint8_t flag)
uint8_t meta
Mask of meta keys currently pressed.
Interrupt handling operations.
uint8_t brk
KEYBRK_UP or KEYBRK_DOWN.
x86 CPU-specific function implementations.
void irq_enable(uint8_t irq)
Tell the PIC to enable a hardware interrupt.
static void isr_keyboard(const interrupt_context_t *context)
static void addkey(uint8_t brk, uint8_t meta, uint8_t code, uint8_t ch)
void * memzero(void *dst, size_t num)
Fill a region of memory with zeroes.
#define MAX_BUFSIZ
Keyboard input buffer size.
#define META_ALT
Set while the alt key is pressed.
The log context describes the state of the log buffers.
#define META_ESCAPED
Set if key's scan code is escaped.
keycode
Key code values representing individual keys on the keyboard.
static kbstate_t state
Current keyboard state.
uint8_t buf_tail
Index of next empty slot in buf.
#define KB_PORT_DATA
Keyboard I/O data port.
A record representing the state of the keyboard at the time a key was presssed or unpressed...
void * memcpy(void *dst, const void *src, size_t num)
Copy bytes from one memory region to another.