]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: expand c_cc[] with POSIX control character indices
authorTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 21:32:46 +0000 (18:32 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 21:32:46 +0000 (18:32 -0300)
- 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.

include/tty.h
src/kernel/tty.c

index fc815d2d562f210826ac162f12cf57bbf273d250..0ec5089b02a70bd03d3fa1b6fadbe7f2ec29f9ee 100644 (file)
@@ -4,9 +4,16 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#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;
index 91da6f750da64d1f9496649cb6e871df3f06f405..fe8d65a90cc6888586f0fb3080cf8d3687ca3e9d 100644 (file)
@@ -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) {