|
AquilaOS documentation
How it works, and its code
|
Virtual terminals: /dev/tty1 to /dev/tty6 (character device 4, 1 to 6), and /dev/console, which is the first one. More...
#include <core/system.h>#include <core/module.h>#include <core/string.h>#include <console/earlycon.h>#include <dev/dev.h>#include <dev/vt.h>#include <fs/posix.h>#include <sys/sched.h>#include <sys/signal.h>#include <sys/uaccess.h>Go to the source code of this file.
Macros | |
| #define | VT_RING 4096 |
Functions | |
| uint32_t | vt_palette (uint8_t color) |
| Returns one of the 256 colours of xterm's palette: the 16 colours, a 6 x 6 x 6 cube, and 24 greys. | |
| static uint8_t | color16 (uint8_t color) |
| Returns the closest of the 16 colours to one of the 256. | |
| uint8_t | vt_vga_attr (struct vt_cell cell) |
| Returns the VGA text mode attribute of a cell (its colours, in VGA's order), for the VGA display and /dev/vcsa. | |
| static void | refresh (struct vt *vt, int all) |
| Draws the cells of the foreground terminal that changed, or all of them with all, and moves the cursor. | |
| static ssize_t | vt_tty_output (struct tty *tty, size_t size, void *buf) |
| Takes the terminal's output: it goes through the emulator to the screen. | |
| static ssize_t | vt_tty_input (struct tty *tty, size_t size, void *buf) |
| Takes the terminal's input, after line editing, for its readers. | |
| static void | vt_input_flush (struct tty *tty) |
| Drops the input waiting to be read (tcflush()). | |
| static void | vt_input_to (struct vt *vt, const char *buf, size_t size) |
| Gives input to a terminal: key presses, or replies to requests. | |
| static void | vt_reply (struct vt *vt) |
| Gives the replies to requests that programs wrote (DSR, DA) to the terminal, as input. | |
| static int | vt_setup (struct vt *vt) |
| Sets a terminal up the first time it is used: its screen, its input ring and its terminal. | |
| struct vt * | vt_foreground (void) |
| Returns the terminal in the foreground. | |
| static int | proc_alive (pid_t pid) |
| Returns whether a process is still running. | |
| static void | vt_check (struct vt *vt) |
| Undoes the modes that a process which is gone had set on a terminal (graphics mode, raw keyboard, VT_PROCESS). | |
| static void | vt_signal (struct vt *vt, int signal) |
| Sends a signal to the process that put a terminal in VT_PROCESS mode. | |
| static void | vt_switch_now (int id) |
| Switches to terminal id (an index) at once: it is set up if needed, drawn, and its VT_PROCESS process is told. | |
| void | vt_switch (int id) |
| Switches to another terminal, for Alt+Fn and VT_ACTIVATE. | |
| void | vt_keypress (void) |
| Undoes, at a key press, the modes that a process which is gone had set on the foreground terminal: otherwise the keyboard could be left to no one. | |
| void | vt_input (const char *buf, size_t size) |
| Gives what keys sent to the foreground terminal, as input. | |
| static void | vt_kmsg (const char *s, size_t len) |
| Writes kernel messages to the foreground terminal's screen. | |
| static struct vt * | vt_get (struct devid *dd) |
| Returns the terminal of a device number: /dev/console is the first one, /dev/tty0 the one in the foreground. | |
| static struct vt * | vt_file (struct file *file) |
| Returns the terminal of an open file. | |
| static ssize_t | vt_read (struct devid *dd, off_t offset, struct iobuf *io) |
| Reads a terminal's input. | |
| static ssize_t | vt_write (struct devid *dd, off_t offset, struct iobuf *io) |
| Writes to a terminal's screen. | |
| static int | vt_in_use (struct vt *vt) |
| Returns whether a terminal is in use, so that VT_OPENQRY doesn't give it. | |
| static size_t | vt_ioctl_argsize (int request) |
| Returns the size of the user memory that a KD* or VT_* request reads or writes, or 0 if its argument is a value. | |
| static int | vt_kd_ioctl (struct vt *vt, int request, void *argp) |
| Handles the Linux console's KD* and VT_* requests. | |
| static int | vt_ioctl (struct devid *dd, int request, void *argp) |
| Handles a terminal's ioctl()s: the console's own (KD*, VT_*), through a kernel copy of their argument, and the terminal's. | |
| static int | vt_file_open (struct file *file) |
| Opens a terminal, setting it up the first time. | |
| static int | vt_file_close (struct file *file) |
| Closes a terminal. | |
| static int | vt_file_eof (struct file *file) |
| Returns whether a read that found no data is at the end of the file. | |
| static uint64_t | vt_read_timeout (struct file *file) |
| Returns how long a read may wait, from the terminal's mode (VTIME), or 0 for no limit. | |
| static int | vt_can_read (struct file *file, size_t size) |
| Returns whether a read wouldn't have to wait. | |
| static ssize_t | vcs_read (struct devid *dd, off_t offset, struct iobuf *io) |
| Reads a terminal's screen. | |
| static void | vt_kmsg_replay (void) |
| Shows the kernel messages printed so far, before the terminals were set up. | |
| static int | vt_probe (void) |
| Sets the virtual terminals up at boot, on the framebuffer or in VGA text mode, and shows the first one, with the kernel messages. | |
Variables | |
| static struct vt | vts [VT_COUNT] |
| static struct vt * | fg |
| static struct vt_display * | display |
| static struct vt_cell * | shown |
| static int | busy |
| static int | pending = -1 |
| static struct waitq | active_queue |
| static const uint32_t | ansi_colors [16] |
| struct dev | vtdev |
| static struct dev | vcsdev |
Virtual terminals: /dev/tty1 to /dev/tty6 (character device 4, 1 to 6), and /dev/console, which is the first one.
What programs write to a terminal goes through the terminal emulator (term.c) to its screen, and key presses (keyboard.c) go through the line discipline to its readers. Only the terminal in the foreground is shown, on the framebuffer or in VGA text mode; the others keep their screens in memory. /dev/tty0 is the foreground terminal.
/dev/vcsN and /dev/vcsaN (character device 7, minors N and 128 + N; N = 0 is the foreground terminal) read the screen of /dev/ttyN, as on Linux.
Programs that draw on the framebuffer themselves (an X server) use the Linux console's ioctl()s: KDSETMODE (with KD_GRAPHICS, the terminal isn't drawn), KDSKBMODE (scancodes or key codes instead of characters), and VT_* to switch terminals, or to be asked before a switch (VT_PROCESS). Once the process that set these modes is gone, they are undone; otherwise the screen would be left to no one.
Definition in file vt.c.
| #define VT_RING 4096 |
Definition at line 39 of file vt.c.
Referenced by vt_setup().
Returns the closest of the 16 colours to one of the 256.
Definition at line 90 of file vt.c.
References ansi_colors, color16(), and vt_palette().
Referenced by color16(), and vt_vga_attr().
|
static |
Returns whether a process is still running.
Definition at line 267 of file vt.c.
References proc::pid, proc_alive(), proc_pid_find(), and proc::running.
Referenced by proc_alive(), and vt_check().
|
static |
Draws the cells of the foreground terminal that changed, or all of them with all, and moves the cursor.
A terminal that isn't shown, or is in graphics mode, isn't drawn.
Definition at line 149 of file vt.c.
References vt_cell::attr, vt::col, vt::cols, cursor, vt_display::cursor, vt::cursor_visible, display, vt_display::draw, fg, vt::kd_mode, memcmp(), refresh(), vt::reverse_screen, vt::row, vt::rows, vt::screen, shown, VT_CURSOR, and VT_REVERSE.
Referenced by refresh(), vt_check(), vt_input(), vt_kd_ioctl(), vt_kmsg(), vt_switch_now(), and vt_write().
Reads a terminal's screen.
/dev/vcsN gives the characters of the screen, row after row. /dev/vcsaN gives the rows, the columns, and the cursor's column and row (a byte each), then each character with its VGA attribute.
Definition at line 801 of file vt.c.
References cells(), vt_cell::ch, vt::col, vt::cols, fg, iobuf_out(), devid::minor, NULL, iobuf::resid, vt::row, vt::rows, vt::screen, vt::tty, vcs_read(), VT_COUNT, vt_vga_attr(), and vts.
Referenced by vcs_read().
Returns whether a read wouldn't have to wait.
Definition at line 768 of file vt.c.
References vt::in, vt::tty, tty_can_read(), vt_can_read(), and vt_file().
Referenced by vt_can_read().
|
static |
Undoes the modes that a process which is gone had set on a terminal (graphics mode, raw keyboard, VT_PROCESS).
Definition at line 275 of file vt.c.
References vt::kb_mode, vt::kd_mode, vt::kd_pid, vt::mode, vt::mode_pid, proc_alive(), refresh(), vt_check(), and vt_keyboard_reset().
Referenced by vt_check(), vt_kd_ioctl(), vt_keypress(), vt_switch(), and vt_switch_now().
Returns the terminal of an open file.
Definition at line 434 of file vt.c.
References VNODE_DEV, vt_file(), and vt_get().
Referenced by vt_can_read(), vt_file(), vt_file_close(), vt_file_eof(), vt_file_open(), and vt_read_timeout().
|
static |
Closes a terminal.
Definition at line 739 of file vt.c.
References DEV_MAJOR, DEV_MINOR, vt::opens, posix_file_close(), vt_file(), and vt_file_close().
Referenced by vt_file_close().
|
static |
Returns whether a read that found no data is at the end of the file.
Definition at line 753 of file vt.c.
References vt::tty, tty_eof(), vt_file(), and vt_file_eof().
Referenced by vt_file_eof().
|
static |
Opens a terminal, setting it up the first time.
It may become the process's controlling terminal (tty_open()).
Definition at line 701 of file vt.c.
References DEV_MAJOR, DEV_MINOR, vt::opens, vt::tty, tty_open(), tty::vnode, vt::vnode, vt_file(), vt_file_open(), vt_setup(), and vt::write_queue.
Referenced by vt_file_open().
| struct vt * vt_foreground | ( | void | ) |
Returns the terminal in the foreground.
Definition at line 261 of file vt.c.
References fg, and vt_foreground().
Referenced by cursor_key(), vt_foreground(), and vt_scancode().
Returns the terminal of a device number: /dev/console is the first one, /dev/tty0 the one in the foreground.
Definition at line 419 of file vt.c.
References fg, devid::major, devid::minor, NULL, VT_COUNT, vt_get(), and vts.
Referenced by vt_file(), vt_get(), vt_ioctl(), vt_read(), and vt_write().
|
static |
Returns whether a terminal is in use, so that VT_OPENQRY doesn't give it.
Definition at line 481 of file vt.c.
References vt::opens, tty::session, vt::tty, and vt_in_use().
Referenced by vt_in_use(), and vt_kd_ioctl().
| void vt_input | ( | const char * | buf, |
| size_t | size ) |
Gives what keys sent to the foreground terminal, as input.
| buf | what the keys sent |
| size | its size, in bytes |
Definition at line 375 of file vt.c.
References busy, fg, refresh(), vt_input(), vt_input_to(), and vt_reply().
Referenced by send(), send_byte(), send_char(), and vt_input().
|
static |
Drops the input waiting to be read (tcflush()).
Definition at line 194 of file vt.c.
References vt::in, tty::p, and vt_input_flush().
Referenced by vt_input_flush(), and vt_setup().
Gives input to a terminal: key presses, or replies to requests.
Definition at line 204 of file vt.c.
References vt::tty, tty_master_write(), vt_input_to(), and waitq_wakeup().
Referenced by vt_input(), vt_input_to(), and vt_reply().
|
static |
Handles a terminal's ioctl()s: the console's own (KD*, VT_*), through a kernel copy of their argument, and the terminal's.
Definition at line 666 of file vt.c.
References vt::mode, vt::tty, tty_ioctl(), vt_get(), vt_ioctl(), vt_ioctl_argsize(), and vt_kd_ioctl().
Referenced by vt_ioctl().
|
static |
Returns the size of the user memory that a KD* or VT_* request reads or writes, or 0 if its argument is a value.
Definition at line 488 of file vt.c.
References vt_ioctl_argsize().
Referenced by vt_ioctl(), and vt_ioctl_argsize().
|
static |
Handles the Linux console's KD* and VT_* requests.
The argument is a value, or a pointer to the kernel's copy of the user's memory (vt_ioctl() copies it in and out).
Definition at line 512 of file vt.c.
References active_queue, curproc, vt_display::cursor, display, fg, vt::id, vt::kb_mode, vt::kd_mode, vt::kd_pid, vt::mode, vt::mode_pid, pending, refresh(), vt_check(), VT_COUNT, vt_in_use(), vt_kd_ioctl(), vt_keyboard_reset(), vt_keymap(), vt_switch(), vt_switch_now(), vts, and waitq_sleep().
Referenced by vt_ioctl(), and vt_kd_ioctl().
| void vt_keypress | ( | void | ) |
Undoes, at a key press, the modes that a process which is gone had set on the foreground terminal: otherwise the keyboard could be left to no one.
Definition at line 363 of file vt.c.
References fg, vt_check(), and vt_keypress().
Referenced by vt_keypress(), and vt_scancode().
|
static |
Writes kernel messages to the foreground terminal's screen.
Definition at line 388 of file vt.c.
References busy, fg, refresh(), vt::state, vt::utf8_left, vt_kmsg(), and vt_term_write().
Referenced by vt_kmsg(), vt_kmsg_replay(), and vt_probe().
|
static |
Shows the kernel messages printed so far, before the terminals were set up.
Definition at line 867 of file vt.c.
References ringbuf::buf, kmsg, MIN, vt_kmsg(), and vt_kmsg_replay().
Referenced by vt_kmsg_replay(), and vt_probe().
Returns one of the 256 colours of xterm's palette: the 16 colours, a 6 x 6 x 6 cube, and 24 greys.
| color | the colour's number |
Definition at line 73 of file vt.c.
References ansi_colors, and vt_palette().
Referenced by color16(), fb_draw(), and vt_palette().
|
static |
Sets the virtual terminals up at boot, on the framebuffer or in VGA text mode, and shows the first one, with the kernel messages.
Definition at line 886 of file vt.c.
References vt_display::cols, display, earlycon_disable(), earlycon_on_screen(), fg, vt::id, vt::kb_mode, kdev_chrdev_register(), kmalloc(), vt_display::name, NULL, printk(), printk_console(), vt_display::rows, shown, vcsdev, VT_COUNT, vt_fb_display, vt_fb_probe(), vt_kmsg(), vt_kmsg_replay(), vt_probe(), vt_switch_now(), vt_vga_display, vt_vga_probe(), and vts.
Referenced by vt_probe().
Reads a terminal's input.
A process of a background group gets SIGTTIN instead.
Definition at line 441 of file vt.c.
References vt::in, iobuf::resid, vt::tty, tty_background(), vt_get(), and vt_read().
Referenced by vt_read().
Returns how long a read may wait, from the terminal's mode (VTIME), or 0 for no limit.
Definition at line 761 of file vt.c.
References vt::tty, tty_read_timeout(), vt_file(), and vt_read_timeout().
Referenced by vt_read_timeout().
|
static |
Gives the replies to requests that programs wrote (DSR, DA) to the terminal, as input.
Definition at line 212 of file vt.c.
References memcpy(), vt::reply, vt::reply_len, vt_input_to(), and vt_reply().
Referenced by vt_input(), vt_reply(), and vt_write().
|
static |
Sets a terminal up the first time it is used: its screen, its input ring and its terminal.
Returns 0 or a negative errno.
Definition at line 228 of file vt.c.
References vt::cols, vt_display::cols, display, vt::in, tty::input_flush, NULL, vt::rows, vt_display::rows, vt::tty, tty_new(), vt_input_flush(), VT_RING, vt_setup(), vt_term_init(), vt_tty_input(), vt_tty_output(), and tty::ws.
Referenced by vt_file_open(), vt_setup(), and vt_switch_now().
|
static |
Sends a signal to the process that put a terminal in VT_PROCESS mode.
Definition at line 296 of file vt.c.
References vt::mode_pid, proc_pid_find(), signal_proc_send(), and vt_signal().
Referenced by vt_signal(), vt_switch(), and vt_switch_now().
| void vt_switch | ( | int | id | ) |
Switches to another terminal, for Alt+Fn and VT_ACTIVATE.
If the foreground terminal's process asked to decide (VT_PROCESS), it is asked instead, and the switch waits for its answer (VT_RELDISP).
| id | the terminal's index: 0 for /dev/tty1 |
Definition at line 341 of file vt.c.
References fg, vt::id, vt::mode, pending, vt_check(), VT_COUNT, vt_signal(), vt_switch(), vt_switch_now(), and vts.
Referenced by vt_kd_ioctl(), vt_scancode(), and vt_switch().
|
static |
Switches to terminal id (an index) at once: it is set up if needed, drawn, and its VT_PROCESS process is told.
Definition at line 306 of file vt.c.
References active_queue, vt_display::cursor, display, fg, vt::id, vt::kb_mode, vt::kd_mode, vt::mode, pending, refresh(), vt_check(), vt_keyboard_reset(), vt_setup(), vt_signal(), vt_switch_now(), vts, and waitq_wakeup().
Referenced by vt_kd_ioctl(), vt_probe(), vt_switch(), and vt_switch_now().
Takes the terminal's input, after line editing, for its readers.
Definition at line 187 of file vt.c.
References vt::in, tty::p, and vt_tty_input().
Referenced by vt_setup(), and vt_tty_input().
Takes the terminal's output: it goes through the emulator to the screen.
Definition at line 180 of file vt.c.
References tty::p, vt_term_write(), and vt_tty_output().
Referenced by vt_setup(), and vt_tty_output().
Returns the VGA text mode attribute of a cell (its colours, in VGA's order), for the VGA display and /dev/vcsa.
| cell | the cell |
Definition at line 122 of file vt.c.
References vt_cell::attr, vt_cell::bg, color16(), fg, vt_cell::fg, vga, VT_BOLD, VT_INVISIBLE, VT_REVERSE, and vt_vga_attr().
Referenced by vcs_read(), vga_draw(), and vt_vga_attr().
Writes to a terminal's screen.
With TOSTOP, a process of a background group gets SIGTTOU instead.
Definition at line 456 of file vt.c.
References busy, refresh(), tty::tios, vt::tty, tty_background(), tty_slave_write(), tty_write_iobuf(), vt_get(), vt_reply(), and vt_write().
Referenced by vt_write().
|
static |
Definition at line 58 of file vt.c.
Referenced by vt_kd_ioctl(), and vt_switch_now().
|
static |
Definition at line 61 of file vt.c.
Referenced by color16(), and vt_palette().
|
static |
Definition at line 51 of file vt.c.
Referenced by vt_input(), vt_kmsg(), and vt_write().
|
static |
Definition at line 44 of file vt.c.
Referenced by refresh(), vt_kd_ioctl(), vt_probe(), vt_setup(), and vt_switch_now().
|
static |
Definition at line 42 of file vt.c.
Referenced by refresh(), vcs_read(), vt_foreground(), vt_get(), vt_input(), vt_kd_ioctl(), vt_keypress(), vt_kmsg(), vt_probe(), vt_switch(), vt_switch_now(), and vt_vga_attr().
|
static |
Definition at line 55 of file vt.c.
Referenced by arp_resolve(), pending_flush(), vt_kd_ioctl(), vt_switch(), and vt_switch_now().
|
static |
Definition at line 47 of file vt.c.
Referenced by refresh(), and vt_probe().
|
static |
Definition at line 850 of file vt.c.
Referenced by vt_probe().
| struct dev vtdev |
Definition at line 774 of file vt.c.
Referenced by sttydev_mux(), and ttydev_mux().
Definition at line 41 of file vt.c.
Referenced by vcs_read(), vt_get(), vt_kd_ioctl(), vt_probe(), vt_switch(), and vt_switch_now().