Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /*- |
2 | * Copyright (c) 1982, 1986 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)tty.h 7.10 (Berkeley) 6/26/91 | |
34 | * $Header: /usr/bill/working/sys/sys/RCS/tty.h,v 1.3 92/01/21 21:51:49 william Exp $ | |
35 | * | |
36 | * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE | |
37 | * -------------------- ----- ---------------------- | |
38 | * CURRENT PATCH LEVEL: 2 00061 | |
39 | * -------------------- ----- ---------------------- | |
40 | * | |
41 | * 18 Aug 92 Stephen McKay Fixed RB_LEN macro | |
42 | * 11 Dec 92 Williams Jolitz Fixed tty handling | |
43 | * -------------------- ----- ---------------------- | |
44 | * | |
45 | */ | |
46 | ||
47 | #include <sys/termios.h> | |
48 | ||
49 | /* | |
50 | * Ring buffers provide a contiguous, dense storage for | |
51 | * character data used by the tty driver. | |
52 | */ | |
53 | #define RBSZ 1024 | |
54 | ||
55 | struct ringb { | |
56 | char *rb_hd; /* head of buffer segment to be read */ | |
57 | char *rb_tl; /* tail of buffer segment to be written */ | |
58 | char rb_buf[RBSZ]; /* segment contents */ | |
59 | }; | |
60 | ||
61 | #define RB_SUCC(rbp, p) \ | |
62 | ((p) >= (rbp)->rb_buf + RBSZ - 1 ? (rbp)->rb_buf : (p) + 1) | |
63 | ||
64 | #define RB_ROLLOVER(rbp, p) \ | |
65 | ((p) > (rbp)->rb_buf + RBSZ - 1 ? (rbp)->rb_buf : (p)) | |
66 | ||
67 | #define RB_PRED(rbp, p) \ | |
68 | ((p) <= (rbp)->rb_buf ? (rbp)->rb_buf + RBSZ - 1 : (p) - 1) | |
69 | ||
70 | #define RB_LEN(rp) \ | |
71 | ((rp)->rb_hd <= (rp)->rb_tl ? (rp)->rb_tl - (rp)->rb_hd : \ | |
72 | RBSZ - ((rp)->rb_hd - (rp)->rb_tl)) | |
73 | ||
74 | #define RB_CONTIGPUT(rp) \ | |
75 | (RB_PRED(rp, (rp)->rb_hd) < (rp)->rb_tl ? \ | |
76 | (rp)->rb_buf + RBSZ - (rp)->rb_tl : \ | |
77 | RB_PRED(rp, (rp)->rb_hd) - (rp)->rb_tl) | |
78 | ||
79 | #define RB_CONTIGGET(rp) \ | |
80 | ((rp)->rb_hd <= (rp)->rb_tl ? (rp)->rb_tl - (rp)->rb_hd : \ | |
81 | (rp)->rb_buf + RBSZ - (rp)->rb_hd) | |
82 | ||
83 | /* | |
84 | * Per-tty structure. | |
85 | * | |
86 | * Should be split in two, into device and tty drivers. | |
87 | * Glue could be masks of what to echo and circular buffer | |
88 | * (low, high, timeout). | |
89 | */ | |
90 | struct tty { | |
91 | int (*t_oproc)(); /* device */ | |
92 | int (*t_param)(); /* device */ | |
93 | pid_t t_rsel; /* tty */ | |
94 | pid_t t_wsel; | |
95 | caddr_t T_LINEP; /* XXX */ | |
96 | caddr_t t_addr; /* ??? */ | |
97 | dev_t t_dev; /* device */ | |
98 | int t_flags; /* (compat) some of both */ | |
99 | int t_state; /* some of both */ | |
100 | struct session *t_session; /* tty */ | |
101 | struct pgrp *t_pgrp; /* foreground process group */ | |
102 | char t_line; /* glue */ | |
103 | short t_col; /* tty */ | |
104 | short t_rocount, t_rocol; /* tty */ | |
105 | short t_hiwat; /* hi water mark */ | |
106 | short t_lowat; /* low water mark */ | |
107 | struct winsize t_winsize; /* window size */ | |
108 | struct termios t_termios; /* termios state */ | |
109 | #define t_iflag t_termios.c_iflag | |
110 | #define t_oflag t_termios.c_oflag | |
111 | #define t_cflag t_termios.c_cflag | |
112 | #define t_lflag t_termios.c_lflag | |
113 | #define t_min t_termios.c_min | |
114 | #define t_time t_termios.c_time | |
115 | #define t_cc t_termios.c_cc | |
116 | #define t_ispeed t_termios.c_ispeed | |
117 | #define t_ospeed t_termios.c_ospeed | |
118 | long t_cancc; /* stats */ | |
119 | long t_rawcc; | |
120 | long t_outcc; | |
121 | short t_gen; /* generation number */ | |
122 | short t_mask; /* interrupt mask */ | |
123 | struct ringb t_raw; /* ring buffers */ | |
124 | struct ringb t_can; | |
125 | struct ringb t_out; | |
126 | }; | |
127 | ||
128 | #define TTIPRI 25 /* sleep priority for tty reads */ | |
129 | #define TTOPRI 26 /* sleep priority for tty writes */ | |
130 | ||
131 | #define TTMASK 15 | |
132 | #define OBUFSIZ 100 | |
133 | #define TTYHOG 1024 | |
134 | ||
135 | #ifdef KERNEL | |
136 | #define TTMAXHIWAT (RBSZ/2) /* XXX */ | |
137 | #define TTMINHIWAT 128 | |
138 | #define TTMAXLOWAT 256 | |
139 | #define TTMINLOWAT 32 | |
140 | extern struct ttychars ttydefaults; | |
141 | #endif /* KERNEL */ | |
142 | ||
143 | /* internal state bits */ | |
144 | #define TS_TIMEOUT 0x000001 /* delay timeout in progress */ | |
145 | #define TS_WOPEN 0x000002 /* waiting for open to complete */ | |
146 | #define TS_ISOPEN 0x000004 /* device is open */ | |
147 | #define TS_FLUSH 0x000008 /* outq has been flushed during DMA */ | |
148 | #define TS_CARR_ON 0x000010 /* software copy of carrier-present */ | |
149 | #define TS_BUSY 0x000020 /* output in progress */ | |
150 | #define TS_ASLEEP 0x000040 /* wakeup when output done */ | |
151 | #define TS_XCLUDE 0x000080 /* exclusive-use flag against open */ | |
152 | #define TS_TTSTOP 0x000100 /* output stopped by ctl-s */ | |
153 | /* was TS_HUPCLS 0x000200 * hang up upon last close */ | |
154 | #define TS_TBLOCK 0x000400 /* tandem queue blocked */ | |
155 | #define TS_RCOLL 0x000800 /* collision in read select */ | |
156 | #define TS_WCOLL 0x001000 /* collision in write select */ | |
157 | #define TS_ASYNC 0x004000 /* tty in async i/o mode */ | |
158 | /* state for intra-line fancy editing work */ | |
159 | #define TS_BKSL 0x010000 /* state for lowercase \ work */ | |
160 | #define TS_ERASE 0x040000 /* within a \.../ for PRTRUB */ | |
161 | #define TS_LNCH 0x080000 /* next character is literal */ | |
162 | #define TS_TYPEN 0x100000 /* retyping suspended input (PENDIN) */ | |
163 | #define TS_CNTTB 0x200000 /* counting tab width, ignore FLUSHO */ | |
164 | ||
165 | #define TS_LOCAL (TS_BKSL|TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB) | |
166 | ||
167 | /* define partab character types */ | |
168 | #define ORDINARY 0 | |
169 | #define CONTROL 1 | |
170 | #define BACKSPACE 2 | |
171 | #define NEWLINE 3 | |
172 | #define TAB 4 | |
173 | #define VTAB 5 | |
174 | #define RETURN 6 | |
175 | ||
176 | struct speedtab { | |
177 | int sp_speed; | |
178 | int sp_code; | |
179 | }; | |
180 | /* | |
181 | * Flags on character passed to ttyinput | |
182 | */ | |
183 | #define TTY_CHARMASK 0x000000ff /* Character mask */ | |
184 | #define TTY_QUOTE 0x00000100 /* Character quoted */ | |
185 | #define TTY_ERRORMASK 0xff000000 /* Error mask */ | |
186 | #define TTY_FE 0x01000000 /* Framing error or BREAK condition */ | |
187 | #define TTY_PE 0x02000000 /* Parity error */ | |
188 | ||
189 | /* | |
190 | * Is tp controlling terminal for p | |
191 | */ | |
192 | #define isctty(p, tp) ((p)->p_session == (tp)->t_session && \ | |
193 | (p)->p_flag&SCTTY) | |
194 | /* | |
195 | * Is p in background of tp | |
196 | */ | |
197 | #define isbackground(p, tp) (isctty((p), (tp)) && \ | |
198 | (p)->p_pgrp != (tp)->t_pgrp) | |
199 | /* | |
200 | * Modem control commands (driver). | |
201 | */ | |
202 | #define DMSET 0 | |
203 | #define DMBIS 1 | |
204 | #define DMBIC 2 | |
205 | #define DMGET 3 | |
206 | ||
207 | #ifdef KERNEL | |
208 | /* symbolic sleep message strings */ | |
209 | extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[]; | |
210 | #endif |