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