miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
tty.c File Reference
Include dependency graph for tty.c:

Classes

struct  tty_state_t

Macros

#define USER_PTR_VALID(p)
#define SIGINT   2
#define TTY_BUFFER_SIZE   256

Functions

static uint16_t tty_ring_count (void)
static void tty_ring_push (char c)
static int tty_ring_pop (char *out)
static void tty_echo_byte (char c)
static void tty_flush_pending_input_locked (void)
static void tty_finalize_canonical_line_locked (void)
static void tty_deliver_sigint_locked (void)
static void tty_apply_defaults_locked (void)
static void tty_apply_termios_locked (const struct minios_termios *termios, int flush_input)
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.
int tty_has_data (void)
void tty_inject_escape (const char *seq, int len)
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).
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.

Variables

static tty_state_t tty_state

Macro Definition Documentation

◆ SIGINT

#define SIGINT   2

◆ TTY_BUFFER_SIZE

#define TTY_BUFFER_SIZE   256

◆ USER_PTR_VALID

#define USER_PTR_VALID ( p)
Value:
unsigned long int uint64_t
Definition types.h:37
unsigned long uintptr_t
Definition types.h:59
#define KERNEL_VMA
Definition vmm.h:41

Function Documentation

◆ tty_apply_defaults_locked()

void tty_apply_defaults_locked ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tty_apply_termios_locked()

void tty_apply_termios_locked ( const struct minios_termios * termios,
int flush_input )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tty_deliver_sigint_locked()

void tty_deliver_sigint_locked ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tty_echo_byte()

void tty_echo_byte ( char c)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tty_finalize_canonical_line_locked()

void tty_finalize_canonical_line_locked ( void )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tty_flush_pending_input_locked()

void tty_flush_pending_input_locked ( void )
static
Here is the caller graph for this function:

◆ tty_ring_count()

uint16_t tty_ring_count ( void )
static
Here is the caller graph for this function:

◆ tty_ring_pop()

int tty_ring_pop ( char * out)
static
Here is the caller graph for this function:

◆ tty_ring_push()

void tty_ring_push ( char c)
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ tty_state

tty_state_t tty_state
static
Initial value:
= {
.lock = SPINLOCK_INIT,
}
#define SPINLOCK_INIT
Definition spinlock.h:55