From: Tulio A M Mendes Date: Fri, 13 Feb 2026 21:32:46 +0000 (-0300) Subject: feat: expand c_cc[] with POSIX control character indices X-Git-Url: https://projects.tadryanom.me/docs/POSIX_ROADMAP.md?a=commitdiff_plain;h=dd335b3b7e0c170688cafe0ded6dc66dd4a525cf;p=AdrOS.git feat: expand c_cc[] with POSIX control character indices - NCCS expanded from 8 to 11 - Define VINTR(0), VQUIT(1), VERASE(2), VKILL(3), VEOF(4), VSUSP(7), VMIN(8), VTIME(9) with standard index values - Initialize tty_cc[] with POSIX defaults: VINTR=^C, VQUIT=^\, VERASE=DEL, VKILL=^U, VEOF=^D, VSUSP=^Z - Replace all hardcoded signal/control character comparisons in tty_input_char with tty_cc[] lookups - VERASE now accepts both 0x08 (BS) and 0x7F (DEL) - All c_cc[] entries are user-configurable via TCSETS 20/20 smoke tests pass. --- diff --git a/include/tty.h b/include/tty.h index fc815d2..0ec5089 100644 --- a/include/tty.h +++ b/include/tty.h @@ -4,9 +4,16 @@ #include #include -#define NCCS 8 -#define VMIN 4 -#define VTIME 5 +#define NCCS 11 + +#define VINTR 0 /* Ctrl-C → SIGINT */ +#define VQUIT 1 /* Ctrl-\ → SIGQUIT */ +#define VERASE 2 /* Backspace / DEL */ +#define VKILL 3 /* Ctrl-U (kill line)*/ +#define VEOF 4 /* Ctrl-D (EOF) */ +#define VSUSP 7 /* Ctrl-Z → SIGTSTP */ +#define VMIN 8 +#define VTIME 9 struct termios { uint32_t c_iflag; diff --git a/src/kernel/tty.c b/src/kernel/tty.c index 91da6f7..fe8d65a 100644 --- a/src/kernel/tty.c +++ b/src/kernel/tty.c @@ -28,7 +28,16 @@ static waitqueue_t tty_wq; static uint32_t tty_lflag = TTY_ICANON | TTY_ECHO | TTY_ISIG; static uint32_t tty_oflag = TTY_OPOST | TTY_ONLCR; -static uint8_t tty_cc[NCCS] = {0, 0, 0, 0, 1, 0, 0, 0}; +static uint8_t tty_cc[NCCS] = { + [VINTR] = 0x03, /* Ctrl-C */ + [VQUIT] = 0x1C, /* Ctrl-\ */ + [VERASE] = 0x7F, /* DEL */ + [VKILL] = 0x15, /* Ctrl-U */ + [VEOF] = 0x04, /* Ctrl-D */ + [VSUSP] = 0x1A, /* Ctrl-Z */ + [VMIN] = 1, + [VTIME] = 0, +}; static struct winsize tty_winsize = { 24, 80, 0, 0 }; @@ -284,7 +293,7 @@ void tty_input_char(char c) { enum { SIGINT_NUM = 2, SIGQUIT_NUM = 3, SIGTSTP_NUM = 20 }; if (lflag & TTY_ISIG) { - if (c == 0x03) { + if (tty_cc[VINTR] && (uint8_t)c == tty_cc[VINTR]) { spin_unlock_irqrestore(&tty_lock, flags); if (lflag & TTY_ECHO) { kprintf("^C\n"); @@ -295,7 +304,7 @@ void tty_input_char(char c) { return; } - if (c == 0x1C) { + if (tty_cc[VQUIT] && (uint8_t)c == tty_cc[VQUIT]) { spin_unlock_irqrestore(&tty_lock, flags); if (lflag & TTY_ECHO) { kprintf("^\\\n"); @@ -306,7 +315,7 @@ void tty_input_char(char c) { return; } - if (c == 0x1A) { + if (tty_cc[VSUSP] && (uint8_t)c == tty_cc[VSUSP]) { spin_unlock_irqrestore(&tty_lock, flags); if (lflag & TTY_ECHO) { kprintf("^Z\n"); @@ -318,7 +327,7 @@ void tty_input_char(char c) { } } - if (c == 0x04 && (lflag & TTY_ICANON)) { + if (tty_cc[VEOF] && (uint8_t)c == tty_cc[VEOF] && (lflag & TTY_ICANON)) { if (lflag & TTY_ECHO) { kprintf("^D"); } @@ -342,7 +351,7 @@ void tty_input_char(char c) { return; } - if (c == '\b') { + if (c == '\b' || (tty_cc[VERASE] && (uint8_t)c == tty_cc[VERASE])) { if (line_len > 0) { line_len--; if (lflag & TTY_ECHO) {