tty: reading input from a tty is now handled by the line discipline

This commit is contained in:
2023-06-14 17:38:03 +01:00
parent 16d0a398b3
commit 2656696757
4 changed files with 206 additions and 10 deletions

113
include/socks/termios.h Normal file
View File

@@ -0,0 +1,113 @@
#ifndef SOCKS_TERMIOS_H_
#define SOCKS_TERMIOS_H_
#include <stdint.h>
#define NCCS 32
#define BRKINT 00000001
#define ICRNL 00000002
#define IGNBRK 00000004
#define IGNCR 00000010
#define IGNPAR 00000020
#define INLCR 00000040
#define INPCK 00000100
#define ISTRIP 00000200
#define IUCLC 00000400
#define IXANY 00001000
#define IXOFF 00002000
#define IXON 00004000
#define PARMRK 00010000
#define OPOST 00000001
#define OLCUC 00000002
#define ONLCR 00000004
#define OCRNL 00000010
#define ONOCR 00000020
#define ONLRET 00000040
#define NLDLY 00000100
#define NL0 00000000
#define NL1 00000100
#define OFILL 00000200
#define CRDLY 00003400
#define CR0 00000000
#define CR1 00000400
#define CR2 00001000
#define CR3 00002000
#define TABDLY 00034000
#define TAB0 00000000
#define TAB1 00004000
#define TAB2 00010000
#define TAB3 00020000
#define BSDLY 00040000
#define BS0 00000000
#define BS1 00040000
#define VTDLY 00100000
#define VT0 00000000
#define VT1 00100000
#define FFDLY 00200000
#define FF0 00000000
#define FF1 00200000
#define B0 0
#define B50 50
#define B75 75
#define B110 110
#define B134 134
#define B150 150
#define B200 200
#define B300 300
#define B600 600
#define B1200 1200
#define B1800 1800
#define B2400 2400
#define B4800 4800
#define B9600 9600
#define B19200 19200
#define B38400 38400
#define CSIZE 00000007
#define CS5 00000000
#define CS6 00000001
#define CS7 00000002
#define CS8 00000004
#define CSTOPB 00000010
#define CREAD 00000020
#define PARENB 00000040
#define PARODD 00000100
#define HUPCL 00000200
#define CLOCAL 00000400
#define ECHO 00000001
#define ECHOE 00000002
#define ECHOK 00000004
#define ECHONL 00000010
#define ICANON 00000020
#define IEXTEN 00000040
#define ISIG 00000100
#define NOFLSH 00000200
#define TOSTOP 00000400
#define XCASE 00001000
#define TCSANOW 1
#define TCSADRAIN 2
#define TCSAFLUSH 3
#define TCIFLUSH 1
#define TCOFLUSH 2
#define TCIOFLUSH (TCIFLUSH | TCOFLUSH)
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
typedef unsigned char cc_t;
struct termios {
tcflag_t c_iflag;
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_line;
cc_t c_cc[NCCS];
};
#endif

View File

@@ -5,12 +5,14 @@
#include <socks/device.h>
#include <socks/queue.h>
#include <socks/object.h>
#include <socks/termios.h>
#include <stdint.h>
#define TTY_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_CHAR ? (dev)->chr.c_tty : NULL)
#define TTY_DRIVER(drv) ((struct tty_driver *)((char *)drv - offsetof(struct tty_driver, tty_base)))
#define TTY_INPUT_QUEUE_SIZE 256
#define TTY_LINE_MAX 4096
struct kext;
@@ -92,13 +94,14 @@ struct tty_driver {
struct tty_ldisc {
char name[OBJECT_NAME_MAX];
kern_status_t(*read)(struct device *, void *, size_t, size_t *, socks_flags_t);
void(*write)(struct device *, const struct input_event *);
};
struct tty_device {
unsigned int tty_xcells, tty_ycells;
unsigned int tty_xcur, tty_ycur;
unsigned int tty_iflag, tty_oflag, tty_lflag;
struct termios tty_config;
tty_attrib_t tty_curattrib;
enum tty_modifier_key tty_modstate;
@@ -107,6 +110,7 @@ struct tty_device {
/* input characters processed from tty_events, returned by tty_read() */
struct ringbuffer tty_input;
char *tty_linebuf;
};
extern kern_status_t tty_bootstrap(void);