AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vt.h
Go to the documentation of this file.
1#ifndef _DEV_VT_H
2#define _DEV_VT_H
3
4#include <core/system.h>
5#include <dev/tty.h>
6#include <ds/ringbuf.h>
7#include <ds/queue.h>
8#include <aquila/kd.h>
9#include <aquila/vt.h>
10
11/*
12 * Virtual terminals: the screen and keyboard as terminals.
13 *
14 * The kernel emulates a terminal (the Linux console's escape sequences,
15 * TERM=linux) on the framebuffer, or in VGA text mode without one, and
16 * turns key presses into what such a terminal sends. /dev/tty1 to
17 * /dev/tty6 (major 4) are separate terminals, and Alt+F1 to Alt+F6 switch
18 * between them.
19 */
20
21/* How many virtual terminals there are. */
22#define VT_COUNT 6
23
24/* A character's attributes. */
25#define VT_BOLD 0x01
26#define VT_DIM 0x02
27#define VT_UNDERLINE 0x04
28#define VT_BLINK 0x08
29#define VT_REVERSE 0x10
30#define VT_INVISIBLE 0x20
31#define VT_ITALIC 0x40
32#define VT_CURSOR 0x80 /* the cursor is drawn on it */
33
35struct vt_cell {
36 uint8_t ch; /* code page 437 */
40};
41
43struct vt_display {
44 char *name;
45 int rows, cols;
46
48 void (*draw)(int row, int col, struct vt_cell cell);
49
51 void (*cursor)(int row, int col, int visible);
52};
53
54/* The displays: the framebuffer, and VGA text mode. Their probes return
55 * 0 if they can be used. */
56extern struct vt_display vt_fb_display;
57extern struct vt_display vt_vga_display;
58int vt_fb_probe(void);
59int vt_vga_probe(void);
60
61/* Returns the RGB value of a palette color. */
63
64/* Returns a cell's VGA text mode attribute. */
65uint8_t vt_vga_attr(struct vt_cell cell);
66
68struct vt_cursor {
69 int row, col;
70 struct vt_cell pen;
71 int charset[2], gl;
73};
74
76struct vt {
77 int id;
78 int rows, cols;
79
80 /* the main screen and the alternate one; `screen` is the one shown */
81 struct vt_cell *main, *alt, *screen;
82
83 /* the cursor, and a pending wrap (a character was written in the
84 * last column) */
86
87 /* the attributes and colors characters are written with */
88 struct vt_cell pen;
89
90 /* the scrolling region: its top and bottom rows, inclusive */
91 int top, bottom;
92
93 /* modes */
96
97 /* the G0 and G1 character sets ('B' for ASCII, '0' for DEC special
98 * graphics), and the one in use (SO/SI) */
99 int charset[2], gl;
100
101 /* tab stops */
103
104 struct vt_cursor saved, saved_alt;
105
106 /* the escape sequence parser */
107 int state;
108 int params[16], nparams;
109 char private, intermediate;
110 uint8_t last; /* the last character written, for REP */
111
112 /* the UTF-8 decoder */
115
116 /* replies to requests (DSR, DA), sent as input once a write is done */
117 char reply[32];
118 size_t reply_len;
119
120 /* KD_TEXT, or KD_GRAPHICS when a program draws on the framebuffer
121 * and the terminal doesn't; what the keyboard sends (K_XLATE, K_RAW,
122 * ...); and the process that set them, which they are undone for
123 * once it is gone */
126
127 /* VT_PROCESS: switching away waits for the process (relsig, then
128 * VT_RELDISP), and the process is told when the terminal is back
129 * (acqsig) */
130 struct vt_mode mode;
132
133 /* how many descriptors have it open, for VT_OPENQRY */
134 int opens;
135
136 /* the tty, and the input that readers get */
137 struct tty *tty;
138 struct ringbuf *in;
139 struct vnode *vnode;
140 struct waitq read_queue, write_queue;
141};
142
143/* term.c: the terminal emulator: sets up, resets, and writes to a
144 * terminal's screen */
145int vt_term_init(struct vt *vt, int rows, int cols);
146void vt_term_reset(struct vt *vt);
147void vt_term_write(struct vt *vt, const char *buf, size_t size);
148
149/* vt.c: the terminals' device, input, and switching between them */
150extern struct dev vtdev;
151void vt_input(const char *buf, size_t size);
152void vt_switch(int id);
153void vt_keypress(void);
154struct vt *vt_foreground(void);
155
156/* keyboard.c: PS/2 scancodes (set 1) from the keyboard driver, turned
157 * into what the terminal sends */
158void vt_scancode(int scancode);
159void vt_keyboard_reset(void);
160int vt_keymap(int table, int keycode);
161
162#endif /* ! _DEV_VT_H */
int vt_fb_probe(void)
Sets up the virtual terminals on the framebuffer, if there is one the terminals can draw on,...
Definition fb.c:100
struct vt_display vt_fb_display
Definition fb.c:130
int vt_vga_probe(void)
Says whether VGA text mode can be used.
Definition vga.c:48
struct vt_display vt_vga_display
Definition vga.c:53
int vt_keymap(int table, int keycode)
Says what a key is, for KDGKBENT: programs that read key codes (K_MEDIUMRAW) use it to know what each...
Definition keyboard.c:130
void vt_scancode(int scancode)
Takes a scancode from the keyboard, and sends what the key means to the foreground terminal,...
Definition keyboard.c:307
void vt_keyboard_reset(void)
Forgets a prefix or a sequence that a change of mode cut in the middle.
Definition keyboard.c:198
static uint64_t * table(paddr_t paddr)
Returns a page table, through the direct map.
Definition pmap.c:72
unsigned int uint32_t
Definition stddef.h:22
unsigned char uint8_t
Definition stddef.h:20
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
A ring buffer.
Definition ringbuf.h:18
A character cell.
Definition vt.h:35
uint8_t fg
Definition vt.h:38
uint8_t ch
Definition vt.h:36
uint8_t bg
Definition vt.h:39
uint8_t attr
Definition vt.h:37
The cursor's state, saved by DECSC.
Definition vt.h:68
int col
Definition vt.h:69
struct vt_cell pen
Definition vt.h:70
int charset[2]
Definition vt.h:71
int wrap
Definition vt.h:72
int gl
Definition vt.h:71
int origin
Definition vt.h:72
int row
Definition vt.h:69
A display that virtual terminals are shown on.
Definition vt.h:43
void(*) cursor(int row, int col, int visible)
moves a hardware cursor; NULL if the cursor is drawn (VT_CURSOR)
Definition vt.h:51
void(*) draw(int row, int col, struct vt_cell cell)
draws a cell
Definition vt.h:48
int rows
Definition vt.h:45
char * name
Definition vt.h:44
int cols
Definition vt.h:45
A virtual terminal: its screen, its emulator's state, and its tty.
Definition vt.h:76
struct vnode * vnode
Definition vt.h:139
int newline
Definition vt.h:94
struct tty * tty
Definition vt.h:137
uint8_t last
Definition vt.h:110
pid_t kd_pid
Definition vt.h:125
int reverse_screen
Definition vt.h:95
int rows
Definition vt.h:78
int opens
Definition vt.h:134
uint32_t utf8
Definition vt.h:113
size_t reply_len
Definition vt.h:118
int params[16]
Definition vt.h:108
int row
Definition vt.h:85
struct waitq read_queue write_queue
Definition vt.h:140
char reply[32]
Definition vt.h:117
struct vt_cursor saved saved_alt
Definition vt.h:104
struct vt_cell * main
Definition vt.h:81
int id
Definition vt.h:77
int col
Definition vt.h:85
int cursor_visible
Definition vt.h:94
int wrap_pending
Definition vt.h:85
int cursor_keys
Definition vt.h:94
struct vt_cell * screen
Definition vt.h:81
int kb_mode
Definition vt.h:124
uint8_t tabs[32]
Definition vt.h:102
int top
Definition vt.h:91
struct vt_cell pen
Definition vt.h:88
int origin
Definition vt.h:94
int kd_mode
Definition vt.h:124
int bottom
Definition vt.h:91
int cols
Definition vt.h:78
int keypad
Definition vt.h:95
int utf8_left
Definition vt.h:114
int nparams
Definition vt.h:108
int autowrap
Definition vt.h:94
int charset[2]
Definition vt.h:99
struct ringbuf * in
Definition vt.h:138
char intermediate
Definition vt.h:109
struct vt_mode mode
Definition vt.h:130
int state
Definition vt.h:107
int insert
Definition vt.h:94
struct vt_cell * alt
Definition vt.h:81
int gl
Definition vt.h:99
pid_t mode_pid
Definition vt.h:131
Definition waitq.h:19
void vt_term_write(struct vt *vt, const char *buf, size_t size)
Takes what programs write to a terminal, and changes its screen.
Definition term.c:957
void vt_term_reset(struct vt *vt)
Resets a terminal (RIS, ESC c): the defaults, the tab stops every 8 columns, the main screen cleared,...
Definition term.c:395
int vt_term_init(struct vt *vt, int rows, int cols)
Sets a terminal's screens up, the main one and the alternate one, both cleared, and resets it.
Definition term.c:420
int pid_t
Definition types.h:8
void vt_input(const char *buf, size_t size)
Gives what keys sent to the foreground terminal, as input.
Definition vt.c:375
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 ...
Definition vt.c:122
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,...
Definition vt.c:73
struct dev vtdev
Definition vt.c:774
struct vt * vt_foreground(void)
Returns the terminal in the foreground.
Definition vt.c:261
void vt_switch(int id)
Switches to another terminal, for Alt+Fn and VT_ACTIVATE.
Definition vt.c:341
void vt_keypress(void)
Undoes, at a key press, the modes that a process which is gone had set on the foreground terminal: ot...
Definition vt.c:363