AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
keyboard.c File Reference

The keyboard of the virtual terminals. More...

#include <core/system.h>
#include <core/string.h>
#include <dev/vt.h>
#include <sys/reboot.h>
#include <aquila/keyboard.h>

Go to the source code of this file.

Macros

#define SC_ESC   0x01
#define SC_BS   0x0E
#define SC_TAB   0x0F
#define SC_ENTER   0x1C
#define SC_CTRL   0x1D
#define SC_LSHIFT   0x2A
#define SC_RSHIFT   0x36
#define SC_KP_MUL   0x37
#define SC_ALT   0x38
#define SC_CAPS   0x3A
#define SC_F1   0x3B
#define SC_F10   0x44
#define SC_NUM   0x45
#define SC_KP7   0x47
#define SC_KP_DEL   0x53
#define SC_F11   0x57
#define SC_F12   0x58
#define KEY_PAUSE   119

Functions

static void send (const char *s)
 Sends a string to the foreground terminal, as typed input.
static void send_byte (int c)
 Sends one byte to the foreground terminal, as typed input.
int vt_keymap (int table, int keycode)
 Says what a key is, for KDGKBENT: programs that read key codes (K_MEDIUMRAW) use it to know what each key means.
void vt_keyboard_reset (void)
 Forgets a prefix or a sequence that a change of mode cut in the middle.
static void send_key (const char *s)
 Sends what a key sends, with ESC before it if Alt is held.
static void send_char (char c)
 Sends one character, with ESC before it if Alt is held.
static void cursor_key (char dir)
 Sends a cursor key: ESC [ x, or ESC O x in the terminal's application cursor key mode (DECCKM).
static void editing_key (const char *s)
 Sends a key of the editing block: its sequence, or a cursor key if it is one letter.
static int control (char c)
 Returns the control character that Ctrl with a key sends, as the Linux console does (Ctrl+A is 1, Ctrl+[ is ESC, ...).
static int modifier (int code, int release, int ext)
 Keeps track of Shift, Ctrl and Alt, in every mode, since they may be held while the mode changes.
void vt_scancode (int scancode)
 Takes a scancode from the keyboard, and sends what the key means to the foreground terminal, in its keyboard mode.

Variables

static const char keys [128]
static const char shifted [128]
static const char * fkeys [12]
static const char * keypad_keys [13]
static const char keypad_digits [] = "789-456+1230."
static const uint8_t e0_keycodes [128]
static int shift
static int ctrl
static int alt
static int caps
static int num
static int extended
static int skip

Detailed Description

The keyboard of the virtual terminals.

The keyboard sends PS/2 scancodes (set 1, which the i8042 translates to). This file turns them into what the Linux console sends for each key, with the US layout, and gives that to the foreground terminal. Alt sends ESC before the key, Alt+F1 to Alt+F6 switch terminals, and Ctrl+Alt+Del restarts the machine (or tells init: see sys/reboot.c).

A program can ask for raw input instead (KDSKBMODE): the scancodes as they come (K_RAW), or Linux key codes, with 0x80 added for a release (K_MEDIUMRAW). The program then handles every key itself, switching terminals too.

Definition in file keyboard.c.

Macro Definition Documentation

◆ KEY_PAUSE

#define KEY_PAUSE   119

Definition at line 99 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_ALT

#define SC_ALT   0x38

Definition at line 31 of file keyboard.c.

Referenced by modifier(), and vt_keymap().

◆ SC_BS

#define SC_BS   0x0E

Definition at line 24 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_CAPS

#define SC_CAPS   0x3A

Definition at line 32 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_CTRL

#define SC_CTRL   0x1D

Definition at line 27 of file keyboard.c.

Referenced by modifier(), and vt_keymap().

◆ SC_ENTER

#define SC_ENTER   0x1C

Definition at line 26 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_ESC

#define SC_ESC   0x01

Definition at line 23 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_F1

#define SC_F1   0x3B

Definition at line 33 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_F10

#define SC_F10   0x44

Definition at line 34 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_F11

#define SC_F11   0x57

Definition at line 38 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_F12

#define SC_F12   0x58

Definition at line 39 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_KP7

#define SC_KP7   0x47

Definition at line 36 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_KP_DEL

#define SC_KP_DEL   0x53

Definition at line 37 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_KP_MUL

#define SC_KP_MUL   0x37

Definition at line 30 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_LSHIFT

#define SC_LSHIFT   0x2A

Definition at line 28 of file keyboard.c.

Referenced by modifier(), vt_keymap(), and vt_scancode().

◆ SC_NUM

#define SC_NUM   0x45

Definition at line 35 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ SC_RSHIFT

#define SC_RSHIFT   0x36

Definition at line 29 of file keyboard.c.

Referenced by modifier(), vt_keymap(), and vt_scancode().

◆ SC_TAB

#define SC_TAB   0x0F

Definition at line 25 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

Function Documentation

◆ control()

int control ( char c)
static

Returns the control character that Ctrl with a key sends, as the Linux console does (Ctrl+A is 1, Ctrl+[ is ESC, ...).

Definition at line 249 of file keyboard.c.

Referenced by vt_scancode().

◆ cursor_key()

void cursor_key ( char dir)
static

Sends a cursor key: ESC [ x, or ESC O x in the terminal's application cursor key mode (DECCKM).

Definition at line 229 of file keyboard.c.

References cursor_key(), vt::cursor_keys, send_key(), and vt_foreground().

Referenced by cursor_key(), editing_key(), and vt_scancode().

◆ editing_key()

void editing_key ( const char * s)
static

Sends a key of the editing block: its sequence, or a cursor key if it is one letter.

Definition at line 239 of file keyboard.c.

References cursor_key(), editing_key(), and send_key().

Referenced by editing_key(), and vt_scancode().

◆ modifier()

int modifier ( int code,
int release,
int ext )
static

Keeps track of Shift, Ctrl and Alt, in every mode, since they may be held while the mode changes.

Returns whether the key was one of them.

Definition at line 279 of file keyboard.c.

References alt, ctrl, modifier(), SC_ALT, SC_CTRL, SC_LSHIFT, SC_RSHIFT, and shift.

Referenced by modifier(), and vt_scancode().

◆ send()

void send ( const char * s)
static

Sends a string to the foreground terminal, as typed input.

Definition at line 108 of file keyboard.c.

References vt_input().

Referenced by send_char(), send_key(), and vt_scancode().

◆ send_byte()

void send_byte ( int c)
static

Sends one byte to the foreground terminal, as typed input.

Definition at line 114 of file keyboard.c.

References send_byte(), and vt_input().

Referenced by send_byte(), and vt_scancode().

◆ send_char()

void send_char ( char c)
static

Sends one character, with ESC before it if Alt is held.

Definition at line 212 of file keyboard.c.

References alt, send(), send_char(), send_key(), and vt_input().

Referenced by send_char(), and vt_scancode().

◆ send_key()

void send_key ( const char * s)
static

Sends what a key sends, with ESC before it if Alt is held.

Definition at line 204 of file keyboard.c.

References alt, send(), and send_key().

Referenced by cursor_key(), editing_key(), send_char(), send_key(), and vt_scancode().

◆ vt_keyboard_reset()

void vt_keyboard_reset ( void )

Forgets a prefix or a sequence that a change of mode cut in the middle.

Definition at line 198 of file keyboard.c.

References extended, skip, and vt_keyboard_reset().

Referenced by vt_check(), vt_kd_ioctl(), vt_keyboard_reset(), and vt_switch_now().

◆ vt_keymap()

int vt_keymap ( int table,
int keycode )

Says what a key is, for KDGKBENT: programs that read key codes (K_MEDIUMRAW) use it to know what each key means.

Parameters
tablethe table: none, Shift, AltGr, or both (AltGr is the same as without: the US layout has no AltGr)
keycodethe key's Linux key code
Returns
the key's meaning (K(type, value)), or K_HOLE if the key isn't in that table

Definition at line 130 of file keyboard.c.

References KEY_PAUSE, keys, SC_ALT, SC_BS, SC_CAPS, SC_CTRL, SC_ENTER, SC_ESC, SC_F1, SC_F10, SC_F11, SC_F12, SC_KP7, SC_KP_DEL, SC_KP_MUL, SC_LSHIFT, SC_NUM, SC_RSHIFT, SC_TAB, shifted, table(), and vt_keymap().

Referenced by vt_kd_ioctl(), and vt_keymap().

◆ vt_scancode()

void vt_scancode ( int scancode)

Takes a scancode from the keyboard, and sends what the key means to the foreground terminal, in its keyboard mode.

The PS/2 keyboard driver calls it from the keyboard's interrupt.

Parameters
scancodethe scancode (set 1)

Definition at line 307 of file keyboard.c.

References alt, caps, control(), ctrl, cursor_key(), e0_keycodes, editing_key(), extended, fkeys, vt::kb_mode, kernel_ctrlaltdel(), KEY_PAUSE, keypad_digits, keypad_keys, keys, vt::mode, modifier(), num, SC_BS, SC_CAPS, SC_ENTER, SC_ESC, SC_F1, SC_F10, SC_F11, SC_F12, SC_KP7, SC_KP_DEL, SC_KP_MUL, SC_LSHIFT, SC_NUM, SC_RSHIFT, SC_TAB, send(), send_byte(), send_char(), send_key(), shift, shifted, skip, vt_foreground(), vt_keypress(), vt_scancode(), and vt_switch().

Referenced by ps2kbd_probe(), and vt_scancode().

Variable Documentation

◆ alt

int alt
static

Definition at line 101 of file keyboard.c.

Referenced by modifier(), send_char(), send_key(), and vt_scancode().

◆ caps

int caps
static

Definition at line 101 of file keyboard.c.

Referenced by vt_scancode().

◆ ctrl

int ctrl
static

Definition at line 101 of file keyboard.c.

Referenced by modifier(), and vt_scancode().

◆ e0_keycodes

const uint8_t e0_keycodes[128]
static
Initial value:
= {
[0x1C] = 96,
[0x1D] = 97,
[0x35] = 98,
[0x37] = 99,
[0x38] = 100,
[0x47] = 102,
[0x48] = 103,
[0x49] = 104,
[0x4B] = 105,
[0x4D] = 106,
[0x4F] = 107,
[0x50] = 108,
[0x51] = 109,
[0x52] = 110,
[0x53] = 111,
[0x5B] = 125,
[0x5C] = 126,
[0x5D] = 127,
}

Definition at line 78 of file keyboard.c.

Referenced by vt_scancode().

◆ extended

int extended
static

Definition at line 105 of file keyboard.c.

Referenced by vt_keyboard_reset(), and vt_scancode().

◆ fkeys

const char* fkeys[12]
static
Initial value:
= {
"\033[[A", "\033[[B", "\033[[C", "\033[[D", "\033[[E", "\033[17~",
"\033[18~", "\033[19~", "\033[20~", "\033[21~", "\033[23~", "\033[24~",
}

Definition at line 61 of file keyboard.c.

Referenced by vt_scancode().

◆ keypad_digits

const char keypad_digits[] = "789-456+1230."
static

Definition at line 74 of file keyboard.c.

Referenced by vt_scancode().

◆ keypad_keys

const char* keypad_keys[13]
static
Initial value:
= {
"\033[1~", "A", "\033[5~", NULL, "D", "\033[G", "C", NULL,
"\033[4~", "B", "\033[6~", "\033[2~", "\033[3~",
}
#define NULL
Definition stddef.h:27

Definition at line 69 of file keyboard.c.

Referenced by vt_scancode().

◆ keys

const char keys[128]
static
Initial value:
= {
[0x02] = '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
[0x10] = 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
[0x1E] = 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
[0x2B] = '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
[0x39] = ' ',
[0x56] = '<',
}

Definition at line 42 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ num

int num
static

Definition at line 101 of file keyboard.c.

Referenced by vt_scancode().

◆ shift

int shift
static

Definition at line 101 of file keyboard.c.

Referenced by modifier(), vfs_access(), and vt_scancode().

◆ shifted

const char shifted[128]
static
Initial value:
= {
[0x02] = '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
[0x10] = 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
[0x1E] = 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~',
[0x2B] = '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
[0x39] = ' ',
[0x56] = '>',
}

Definition at line 51 of file keyboard.c.

Referenced by vt_keymap(), and vt_scancode().

◆ skip

int skip
static

Definition at line 105 of file keyboard.c.