SchOS/include/dev/kbd.h
Nexoniarz 54b25708c3 Demand paging, the RTL8168H, links that come up late, and Ctrl+Alt+F1..F12
- Anonymous memory can be reserved without being backed: large mappings,
  MAP_NORESERVE and PROT_NONE are recorded and each page appears, zeroed,
  on first touch -- from trap() for the program, from uva2ka() for the
  kernel on its behalf. WebKit reserves 4 GB at start and touches a sliver;
  backing it all failed with ENOMEM and Epiphany aborted.
- r8169: the 8168G generation and later (the laptop's 8168H, XID 541) are
  taken from the firmware's out-of-band mode, get their PLL powered, the
  receive gate opened, and their PHY reached through the OCP window. The
  PHY's power-down bit is cleared; the old code kept it while restarting
  autonegotiation. Untested on the hardware so far.
- The network thread follows each device's link into lwIP. The link was
  read once at attach, 0.02 s into boot; real autonegotiation takes
  seconds, so on hardware the interface stayed down for good.
- Twelve terminals, switched with Ctrl+Alt+F1..F12 by default: the keys X
  uses, so the console and the desktop agree. AltGr+F-key is gone from
  the defaults (chvt -c altgr+F brings it back).
- SO_PASSCRED on Unix sockets, with SCM_CREDENTIALS delivered by recvmsg.
  WebKit sets it on its IPC sockets and aborted when refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
2026-10-25 11:27:48 +01:00

116 lines
5 KiB
C

// PC keyboard interface constants
//
// The scancode tables themselves are no longer here. They moved to
// kernel/dev/keymap.c when there became more than one of them -- a header
// full of `static` arrays gives every file that includes it its own private
// copy, which was harmless while exactly one file did.
#ifndef KBD_H
#define KBD_H
#define KBSTATP 0x64 // kbd controller status port(I)
#define KBS_DIB 0x01 // kbd data in buffer
#define KBDATAP 0x60 // kbd data port(I)
#define NO 0
#define SHIFT (1<<0)
#define CTL (1<<1)
#define ALT (1<<2)
#define CAPSLOCK (1<<3)
#define NUMLOCK (1<<4)
#define SCROLLLOCK (1<<5)
#define E0ESC (1<<6)
// Right Alt, tracked apart from left Alt.
//
// They used to be the same bit, which is fine for typing -- neither is used to
// look up a character -- and wrong for chords. On a Polish layout AltGr is how
// you type a c e l n o s x z with their diacritics, and it is held constantly.
// Nothing the kernel binds may involve it.
#define RALT (1<<7)
// Special keycodes.
//
// **Above every Unicode codepoint, deliberately**, and they did not use to be:
// KBD_UP was 0xE2 and its neighbours filled 0xE0..0xE9. Those are exactly the
// UTF-8 lead bytes for three-byte characters, so typing any of U+0800..U+FFFF
// -- which is most punctuation, every arrow, every maths symbol, and the whole
// of CJK -- produced a keycode the console read as an arrow key and turned
// into `ESC [ A`. `∞`, `→`, `≤` and `'` all vanished from the input line while
// `ą` and `ę` came through, because those are two-byte sequences whose lead
// byte is 0xC4 and nothing claimed 0xC4.
//
// The chord codes below already knew this rule and said so; the navigation
// keys predate them and were never brought in line. The rule, stated once: a
// value that a key produces is either a Unicode codepoint or it is above
// 0x10FFFF, and nothing in between means anything.
#define KBD_SPECIAL 0x110000
#define KBD_HOME (KBD_SPECIAL + 0x00)
#define KBD_END (KBD_SPECIAL + 0x01)
#define KBD_UP (KBD_SPECIAL + 0x02)
#define KBD_DN (KBD_SPECIAL + 0x03)
#define KBD_LF (KBD_SPECIAL + 0x04)
#define KBD_RT (KBD_SPECIAL + 0x05)
#define KBD_PGUP (KBD_SPECIAL + 0x06)
#define KBD_PGDN (KBD_SPECIAL + 0x07)
#define KBD_INS (KBD_SPECIAL + 0x08)
#define KBD_DEL (KBD_SPECIAL + 0x09)
// F1..F12, consecutive: KBD_F1 + n is F(n+1).
#define KBD_F1 (KBD_SPECIAL + 0x10)
#define KBD_F12 (KBD_SPECIAL + 0x1B)
// Switch virtual terminal.
//
// *Which* chord is a runtime setting, not a constant here, and that is the
// interesting part. Three separate parties have a claim on every candidate:
//
// the HOST, which sees the keystroke first and may never pass it on
// Alt+F4, Alt+F2 window manager
// Ctrl+Alt+F1..F6 display manager, and it matches loosely --
// adding Shift does not get past it
// Ctrl+Alt+<digit> QEMU's own console tabs
//
// APPLICATIONS, which lose the key permanently if the kernel eats it
// Alt+<anything> Meta. zsh binds Meta-digit as digit-argument
// Ctrl+<letter> control characters
// Ctrl+Shift+<digit> types a character -- Ctrl+Shift+2 is ^@
// F1..F6 alone help, and full-screen programs
//
// the KEYBOARD LAYOUT
// AltGr+<letter> Polish diacritics, and on some setups AltGr
// arrives as Ctrl+Alt
//
// There is no combination that is free for everyone on every host, and the
// guest cannot find out what its host grabs -- the keystroke simply never
// arrives, which is indistinguishable from a chord nobody pressed. So the
// kernel ships a default and lets it be changed: VT_SETCHORD, and `chvt -c`
// in userspace. Setting it to no modifiers disables the chord entirely and
// leaves `chvt N` as the only way to switch, which is a legitimate choice on
// a machine whose host takes everything.
//
// The default is Ctrl+Alt+F1..F12: the keys X switches with, so the console
// and the desktop answer the same chord. It used to be AltGr+F-key, which
// nothing else claims -- Right Alt being a separate modifier bit here is what
// makes that expressible, and `chvt -c altgr+F` still sets it.
#define KBD_VT_SWITCH (KBD_SPECIAL + 0x20)
// Previous / next terminal, on the same modifiers as the chord above. The
// minus and equals keys, which sit together and read as - and + -- a relative
// move for when you have two terminals and do not care which number they are.
#define KBD_VT_PREV (KBD_SPECIAL + 0x30)
#define KBD_VT_NEXT (KBD_SPECIAL + 0x31)
#define SCAN_MINUS 0x0C // - / _
#define SCAN_EQUALS 0x0D // = / +
#define SCAN_F1 0x3B // F1..F6 are scancodes 0x3B..0x40
#define SCAN_1 0x02 // 1..6 are scancodes 0x02..0x07
// C('A') == Control-A
#define C(x) (x - '@')
#endif /* KBD_H */