xref: /original-bsd/sys/sys/tty.h (revision c3e32dec)
1 /*-
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tty.h	8.1 (Berkeley) 06/02/93
8  */
9 
10 #include <sys/termios.h>
11 #include <sys/select.h>			/* for struct selinfo */
12 
13 /*
14  * Clists are character lists, which is a variable length linked list
15  * of cblocks, wiht a count of the number of characters in the list.
16  */
17 struct clist {
18 	int	c_cc;		/* count of characters in queue */
19 	char	*c_cf;		/* first character/cblock */
20 	char	*c_cl;		/* last chararacter/cblock */
21 };
22 
23 /*
24  * Per-tty structure.
25  *
26  * Should be split in two, into device and tty drivers.
27  * Glue could be masks of what to echo and circular buffer
28  * (low, high, timeout).
29  */
30 struct tty {
31 	struct	clist t_rawq;		/* queues */
32 	struct	clist t_canq;
33 	struct	clist t_outq;
34 	void	(*t_oproc)();		/* device */
35 #ifdef sun4c
36 	void	(*t_stop)();		/* device */
37 #endif
38 	int	(*t_param)();		/* device */
39 	struct	selinfo t_rsel;		/* tty read/oob select */
40 	struct	selinfo t_wsel;		/* tty write select */
41 	caddr_t	T_LINEP; 		/* XXX */
42 	caddr_t	t_addr;			/* ??? */
43 	dev_t	t_dev;			/* device */
44 	int	t_flags;		/* (compat) some of both */
45 	int	t_state;		/* some of both */
46 	struct	session *t_session;	/* tty */
47 	struct	pgrp *t_pgrp;		/* foreground process group */
48 	char	t_line;			/* glue */
49 	short	t_col;			/* tty */
50 	short	t_rocount, t_rocol;	/* tty */
51 	short	t_hiwat;		/* hi water mark */
52 	short	t_lowat;		/* low water mark */
53 	struct	winsize t_winsize;	/* window size */
54 	struct	termios t_termios;	/* termios state */
55 #define	t_iflag		t_termios.c_iflag
56 #define	t_oflag		t_termios.c_oflag
57 #define	t_cflag		t_termios.c_cflag
58 #define	t_lflag		t_termios.c_lflag
59 #define	t_min		t_termios.c_min
60 #define	t_time		t_termios.c_time
61 #define	t_cc		t_termios.c_cc
62 #define t_ispeed	t_termios.c_ispeed
63 #define t_ospeed	t_termios.c_ospeed
64 	long	t_cancc;		/* stats */
65 	long	t_rawcc;
66 	long	t_outcc;
67 	short	t_gen;			/* generation number */
68 };
69 
70 #define	TTIPRI	25			/* sleep priority for tty reads */
71 #define	TTOPRI	26			/* sleep priority for tty writes */
72 
73 #define	TTMASK	15
74 #define	OBUFSIZ	100
75 #define	TTYHOG	1024
76 
77 #ifdef KERNEL
78 #define TTMAXHIWAT	roundup(2048, CBSIZE)
79 #define TTMINHIWAT	roundup(100, CBSIZE)
80 #define TTMAXLOWAT	256
81 #define TTMINLOWAT	32
82 extern	struct ttychars ttydefaults;
83 #endif /* KERNEL */
84 
85 /* internal state bits */
86 #define	TS_TIMEOUT	0x000001	/* delay timeout in progress */
87 #define	TS_WOPEN	0x000002	/* waiting for open to complete */
88 #define	TS_ISOPEN	0x000004	/* device is open */
89 #define	TS_FLUSH	0x000008	/* outq has been flushed during DMA */
90 #define	TS_CARR_ON	0x000010	/* software copy of carrier-present */
91 #define	TS_BUSY		0x000020	/* output in progress */
92 #define	TS_ASLEEP	0x000040	/* wakeup when output done */
93 #define	TS_XCLUDE	0x000080	/* exclusive-use flag against open */
94 #define	TS_TTSTOP	0x000100	/* output stopped by ctl-s */
95 /* was	TS_HUPCLS	0x000200 	 * hang up upon last close */
96 #define	TS_TBLOCK	0x000400	/* tandem queue blocked */
97 #define	TS_ASYNC	0x004000	/* tty in async i/o mode */
98 /* state for intra-line fancy editing work */
99 #define	TS_BKSL		0x010000	/* state for lowercase \ work */
100 #define	TS_ERASE	0x040000	/* within a \.../ for PRTRUB */
101 #define	TS_LNCH		0x080000	/* next character is literal */
102 #define	TS_TYPEN	0x100000	/* retyping suspended input (PENDIN) */
103 #define	TS_CNTTB	0x200000	/* counting tab width, ignore FLUSHO */
104 
105 #define	TS_LOCAL	(TS_BKSL|TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB)
106 
107 /* define partab character types */
108 #define	ORDINARY	0
109 #define	CONTROL		1
110 #define	BACKSPACE	2
111 #define	NEWLINE		3
112 #define	TAB		4
113 #define	VTAB		5
114 #define	RETURN		6
115 
116 struct speedtab {
117         int sp_speed;
118         int sp_code;
119 };
120 /*
121  * Flags on character passed to ttyinput
122  */
123 #define TTY_CHARMASK    0x000000ff      /* Character mask */
124 #define TTY_QUOTE       0x00000100      /* Character quoted */
125 #define TTY_ERRORMASK   0xff000000      /* Error mask */
126 #define TTY_FE          0x01000000      /* Framing error or BREAK condition */
127 #define TTY_PE          0x02000000      /* Parity error */
128 
129 /*
130  * Is tp controlling terminal for p
131  */
132 #define isctty(p, tp)	((p)->p_session == (tp)->t_session && \
133 			 (p)->p_flag&SCTTY)
134 /*
135  * Is p in background of tp
136  */
137 #define isbackground(p, tp)	(isctty((p), (tp)) && \
138 				(p)->p_pgrp != (tp)->t_pgrp)
139 /*
140  * Modem control commands (driver).
141  */
142 #define	DMSET		0
143 #define	DMBIS		1
144 #define	DMBIC		2
145 #define	DMGET		3
146 
147 #ifdef KERNEL
148 /* symbolic sleep message strings */
149 extern	 char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
150 #endif
151