miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
tty.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2026 Christian Spoo
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
34
35#ifndef _MINIOS_DRIVERS_TTY_H_
36#define _MINIOS_DRIVERS_TTY_H_
37
38#include <miniOS/types.h>
39
40#define TTY_LFLAG_ISIG 0x0001u
41#define TTY_LFLAG_ICANON 0x0002u
42#define TTY_LFLAG_ECHO 0x0008u
43
44#define VINTR 0
45#define VEOF 1
46#define TTY_NCCS 8
47
48#define TCGETS 0x5401UL
49#define TCSETS 0x5402UL
50#define TCSETSW 0x5403UL
51#define TCSETSF 0x5404UL
52#define TIOCSCTTY 0x540EUL
53#define TIOCGPGRP 0x540FUL /* get foreground process group id */
54#define TIOCSPGRP 0x5410UL /* set foreground process group id */
55#define TIOCGWINSZ 0x5413UL
56#define TIOCNOTTY 0x5422UL
57
65
72
81void tty_init(void);
82
93void tty_keyboard_input(char c);
94
104void tty_inject_escape(const char *seq, int len);
105
110int tty_has_data(void);
111
124int tty_read(void *buf, uint32_t len, int nonblock);
125
136int tty_write(const void *buf, uint32_t len);
137
152int tty_ioctl(uint64_t cmd, uint64_t arg);
153
163int tty_isatty_fd(int fd);
164
166
167#endif /* _MINIOS_DRIVERS_TTY_H_ */
void tty_init(void)
Sets up the canonical input ring buffer, initialises the default termios (c_lflag = ICANON|ECHO|ISIG,...
Definition tty.c:165
#define TTY_NCCS
Definition tty.h:46
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 ren...
Definition tty.c:294
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 ...
Definition tty.c:304
void tty_inject_escape(const char *seq, int len)
Definition tty.c:181
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_TT...
Definition tty.c:364
int tty_has_data(void)
Definition tty.c:173
void tty_keyboard_input(char c)
In canonical mode (ICANON set): appends to the line buffer; on newline or VEOF flushes the complete l...
Definition tty.c:189
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,...
Definition tty.c:254
Definition tty.h:58
uint32_t c_oflag
Definition tty.h:60
uint8_t c_cc[TTY_NCCS]
Definition tty.h:63
uint32_t c_lflag
Definition tty.h:62
uint32_t c_cflag
Definition tty.h:61
uint32_t c_iflag
Definition tty.h:59
Definition tty.h:66
uint16_t ws_xpixel
Definition tty.h:69
uint16_t ws_ypixel
Definition tty.h:70
uint16_t ws_col
Definition tty.h:68
uint16_t ws_row
Definition tty.h:67
int fd
Definition syscall_fs.c:0
unsigned short uint16_t
Definition types.h:31
unsigned int uint32_t
Definition types.h:34
unsigned long int uint64_t
Definition types.h:37
unsigned char uint8_t
Definition types.h:28
uint32_t len
Definition virtio_net.c:1