|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|
Kernel TTY: line discipline, canonical/raw input, termios, and ioctl. More...
Classes | |
| struct | minios_termios |
| struct | minios_winsize |
Macros | |
| #define | TTY_LFLAG_ISIG 0x0001u |
| #define | TTY_LFLAG_ICANON 0x0002u |
| #define | TTY_LFLAG_ECHO 0x0008u |
| #define | VINTR 0 |
| #define | VEOF 1 |
| #define | TTY_NCCS 8 |
| #define | TCGETS 0x5401UL |
| #define | TCSETS 0x5402UL |
| #define | TCSETSW 0x5403UL |
| #define | TCSETSF 0x5404UL |
| #define | TIOCSCTTY 0x540EUL |
| #define | TIOCGPGRP 0x540FUL /* get foreground process group id */ |
| #define | TIOCSPGRP 0x5410UL /* set foreground process group id */ |
| #define | TIOCGWINSZ 0x5413UL |
| #define | TIOCNOTTY 0x5422UL |
Functions | |
| void | tty_init (void) |
| Sets up the canonical input ring buffer, initialises the default termios (c_lflag = ICANON|ECHO|ISIG, VINTR=^C, VEOF=^D), and sets the window size to SCREEN_ROWS x SCREEN_COLS. Must be called once during kernel boot before tty_keyboard_input() or tty_read() are used. | |
| void | tty_keyboard_input (char c) |
In canonical mode (ICANON set): appends to the line buffer; on newline or VEOF flushes the complete line to the read buffer. In raw mode: writes directly to the read buffer. Echoes to vt_write_byte() if ECHO is set. Sends SIGINT to the foreground process group if ISIG is set and == VINTR. Called from the keyboard interrupt handler (IRQ1). | |
| void | tty_inject_escape (const char *seq, int len) |
| int | tty_has_data (void) |
| int | tty_read (void *buf, uint32_t len, int nonblock) |
| In canonical mode: blocks (or returns -EAGAIN if nonblock) until a complete line is available, then copies up to @len bytes. In raw mode: returns as many bytes as are immediately available up to @len. | |
| int | tty_write (const void *buf, uint32_t len) |
| Forwards each byte to vt_write_byte(), which handles ANSI/VT escape sequence parsing and VGA cell rendering. | |
| int | tty_ioctl (uint64_t cmd, uint64_t arg) |
| TCGETS: copies current termios to *arg. TCSETS/TCSETSW: copies termios from *arg into the kernel TTY state. TIOCGWINSZ: copies the window size (SCREEN_ROWS x SCREEN_COLS) to *arg. TIOCSCTTY/TIOCNOTTY: accepted (no-op in single-TTY kernel). | |
| int | tty_isatty_fd (int fd) |
| Returns 1 if the fd's vfs_file entry has ftype == VFS_FILE_TYPE_CHAR and device_type == VFS_DEVICE_TTY, 0 otherwise. Used by the isatty(3) Newlib stub. | |
Kernel TTY: line discipline, canonical/raw input, termios, and ioctl.
The TTY layer sits between the keyboard driver and userspace. It implements a POSIX-like line discipline: canonical buffering with echo, SIGINT on ^C (ISIG), and raw mode (ICANON cleared). Exposes the /dev/tty device via tty_read()/tty_write() and processes TCGETS/TCSETS/TIOCGWINSZ via tty_ioctl().
| #define TCGETS 0x5401UL |
| #define TCSETS 0x5402UL |
| #define TCSETSF 0x5404UL |
| #define TCSETSW 0x5403UL |
| #define TIOCGPGRP 0x540FUL /* get foreground process group id */ |
| #define TIOCGWINSZ 0x5413UL |
| #define TIOCNOTTY 0x5422UL |
| #define TIOCSCTTY 0x540EUL |
| #define TIOCSPGRP 0x5410UL /* set foreground process group id */ |
| #define TTY_LFLAG_ECHO 0x0008u |
| #define TTY_LFLAG_ICANON 0x0002u |
| #define TTY_LFLAG_ISIG 0x0001u |
| #define TTY_NCCS 8 |
| #define VEOF 1 |
| #define VINTR 0 |
| int tty_has_data | ( | void | ) |
tty_has_data() - Return non-zero if the TTY input ring buffer has unread bytes. Used by poll() to report POLLIN readiness for stdin.


| void tty_init | ( | void | ) |
Sets up the canonical input ring buffer, initialises the default termios (c_lflag = ICANON|ECHO|ISIG, VINTR=^C, VEOF=^D), and sets the window size to SCREEN_ROWS x SCREEN_COLS. Must be called once during kernel boot before tty_keyboard_input() or tty_read() are used.
tty_init() - Initialise the TTY subsystem.


| void tty_inject_escape | ( | const char * | seq, |
| int | len ) |
tty_inject_escape() - Inject a multi-byte escape sequence directly into the TTY read buffer, bypassing echo and canonical buffering. @seq: Byte sequence to inject (e.g. "\x1b[A" for cursor-up). @len: Number of bytes to push.
Use for special keys (arrow keys, function keys) whose escape sequences must never be echoed to the screen and must bypass ICANON line buffering.


TCGETS: copies current termios to *arg. TCSETS/TCSETSW: copies termios from *arg into the kernel TTY state. TIOCGWINSZ: copies the window size (SCREEN_ROWS x SCREEN_COLS) to *arg. TIOCSCTTY/TIOCNOTTY: accepted (no-op in single-TTY kernel).
tty_ioctl() - Handle terminal ioctl commands.
| cmd | Ioctl command code (TCGETS=0x5401, TCSETS=0x5402, TCSETSW=0x5403, TIOCSCTTY=0x540E, TIOCGWINSZ=0x5413, TIOCNOTTY=0x5422). |
| arg | User-space pointer to a struct minios_termios or struct minios_winsize, depending on @cmd. |


| int tty_isatty_fd | ( | int | fd | ) |
Returns 1 if the fd's vfs_file entry has ftype == VFS_FILE_TYPE_CHAR and device_type == VFS_DEVICE_TTY, 0 otherwise. Used by the isatty(3) Newlib stub.
tty_isatty_fd() - Test whether a file descriptor refers to the TTY device.
| fd | File descriptor to test. |
| void tty_keyboard_input | ( | char | c | ) |
In canonical mode (ICANON set): appends to the line buffer; on newline or VEOF flushes the complete line to the read buffer. In raw mode: writes directly to the read buffer. Echoes to vt_write_byte() if ECHO is set. Sends SIGINT to the foreground process group if ISIG is set and == VINTR. Called from the keyboard interrupt handler (IRQ1).
tty_keyboard_input() - Feed a raw character from the keyboard ISR into the TTY.
| c | Raw character byte from the PS/2 keyboard driver. |


| int tty_read | ( | void * | buf, |
| uint32_t | len, | ||
| int | nonblock ) |
In canonical mode: blocks (or returns -EAGAIN if nonblock) until a complete line is available, then copies up to @len bytes. In raw mode: returns as many bytes as are immediately available up to @len.
tty_read() - Read bytes from the TTY input buffer.
| buf | Destination buffer. |
| len | Maximum number of bytes to read. |
| nonblock | Non-zero to return immediately if no data is available (O_NONBLOCK). |


| int tty_write | ( | const void * | buf, |
| uint32_t | len ) |
Forwards each byte to vt_write_byte(), which handles ANSI/VT escape sequence parsing and VGA cell rendering.
tty_write() - Write bytes to the TTY output (VGA terminal).
| buf | Source buffer of bytes to write. |
| len | Number of bytes. |

