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