`∞`, `→`, `≤` and `'` could not be typed. `ą` and `ę` could. That pairing is
the whole diagnosis: KBD_UP was 0xE2 and its neighbours filled 0xE0..0xE9,
which are exactly the UTF-8 lead bytes for three-byte characters. Every
character in U+0800..U+FFFF -- most punctuation, every arrow, every maths
symbol, the whole of CJK -- arrived as a value the console read as an arrow key
and helpfully turned into `ESC [ A`. Two-byte sequences lead with 0xC4 and
nothing claimed 0xC4, so Polish came through and the rest did not.
The chord codes already knew this rule and said so in a comment. The navigation
keys predate them and were never brought in line. Stated once, in kbd.h: a key
produces either a Unicode codepoint or a value above 0x10FFFF, and nothing in
between means anything. KEY_* -> KBD_*, which also settles a silent collision
-- include/input.h defines its own KEY_HOME, KEY_UP and KEY_END as evdev
numbers, and kbd.c includes both headers, so three macros were being quietly
redefined in the one file that used them.
Then the layouts, which is what the codepoint-sized keycodes were for.
kernel/dev/keymap.c: us, pl, de. A layout is four tables -- plain, Shift,
AltGr, Shift+AltGr -- of uint32 codepoints. uint32 and not uchar is the reason
the file exists: `ó` fits in a byte and `ą` does not, and half a Polish
alphabet is not a Polish layout.
Two things deliberately are *not* tables:
- **Ctrl is derived from the plain codepoint.** The table it replaces was
indexed by scancode, which quietly assumed US -- on QWERTZ the Y and Z keys
swap, so Ctrl+Z would have suspended a job only on some layouts.
- **Caps Lock is a case toggle on the result**, so AltGr+a with Caps Lock is
`Ą`. No second table could say that, because Caps Lock combines with AltGr
rather than replacing it. Latin Extended-A alternates upper/lower by
codepoint but not all the same way round -- Ł is U+0141 (odd) and Ą is
U+0104 (even) -- so Polish lands in both halves and the parity matters.
kbdgetc() encodes to UTF-8 and returns the bytes one call at a time.
consoleintr()'s contract is bytes: the serial line hands it UTF-8 already and
it could not tell an encoded codepoint from a byte of the same value.
The layouts live in the kernel. Linux's loadkeys compiles a text keymap and
uploads it a key at a time through KDSKBENT, which puts the data in userspace
-- and a machine whose /usr has not mounted then has no layout at all. Here the
kernel always has a working keyboard and `loadkeys` only names which one.
KB_GETLAYOUT/KB_SETLAYOUT/KB_LISTLAYOUT; /etc/vconsole.conf and an
os.schos.keymap job for the boot-time choice. No dead keys, so French and
Spanish are absent rather than wrong.
/etc/locale.conf and LANG=C.UTF-8 in profile and zshenv. Only the charset half
of that is real -- musl decodes UTF-8 whatever the locale says and ships no
locale data -- but an unset LANG reads as "ASCII only" to everything that asks,
which is its own way of producing `?`.
And two symlink bugs found while chasing
zsh: locking failed for /root/.zsh_history: operation not permitted
on every boot. symlink() is the classic atomic lock -- create the link, and if
it exists someone else holds it -- and zsh distinguishes EEXIST ("contended,
retry") from anything else ("this cannot work, give up"). sys_symlink returned
a bare -1, which is -EPERM, so every zsh on the machine took the second branch
on a filesystem that supports symlinks perfectly well. Same errno class as
commit 75ccf98.
The second one the first was hiding: **divesymlink() has been in fs.c since the
fork and nothing ever called it.** A symlink behaved as a small file containing
its own target, so `cat link` printed the target's *name*. open() and openat()
follow the final component now (O_NOFOLLOW gives ELOOP), and stat() and lstat()
stop being the same function, since which one follows is the only difference
between them. Mid-path symlinks are still not resolved -- that belongs in
namex(), which would re-enter lookup holding a directory lock.
Verified on the emulated keyboard, not just over serial: AltGr+a/e/s gives
ąęś, Shift+AltGr gives ĄĘŚ, Caps Lock+AltGr gives ĄĘŚ, de types zy for the
physical y/z keys and @€µ on AltGr. `∞ 'x' → ≤ • — …` typed over serial now
survives. Three fresh boots: 0 lock failures, 0 faults.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
115 lines
5 KiB
C
115 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)
|
|
|
|
// 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 AltGr+F1..F6, and the "AltGr wants it" line above needs
|
|
// reading carefully: what a Polish layout wants is AltGr+*letter*. AltGr with
|
|
// a function key produces nothing on any layout, no window manager binds it,
|
|
// and no application asks for it. Right Alt being a separate modifier bit
|
|
// here is what makes the distinction expressible at all -- it used to share
|
|
// ALT, which is harmless for typing and useless for this.
|
|
#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 */
|