xref: /titanic_51/usr/src/uts/common/sys/ldterm.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #ifndef _SYS_LDTERM_H
32 #define	_SYS_LDTERM_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 11.5	*/
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #define	IBSIZE	16		/* "standard" input data block size */
41 #define	OBSIZE	64		/* "standard" output data block size */
42 #define	EBSIZE	16		/* "standard" echo data block size */
43 
44 #ifndef MIN
45 #define	MIN(a, b) (((a) < (b)) ? (a) : (b))
46 #endif
47 
48 #define	V_MIN 		tp->t_modes.c_cc[VMIN]
49 #define	V_TIME		tp->t_modes.c_cc[VTIME]
50 #define	RAW_MODE	!(tp->t_modes.c_lflag & ICANON)
51 #define	CANON_MODE	(tp->t_modes.c_lflag & ICANON)
52 
53 /* flow control defines */
54 #define	TTXOLO	132
55 #define	TTXOHI	180
56 #define	HIWAT	1024
57 #define	LOWAT	200
58 #define	LDCHUNK	512
59 
60 
61 /*
62  * The following for EUC and also other types of codesets.
63  */
64 
65 #define	EUCSIZE	sizeof (struct eucioc)
66 #define	EUCIN	0	/* copying eucioc_t IN from ioctl */
67 #define	EUCOUT	1	/* copying it OUT to user format */
68 
69 /*
70  * One assumption made throughout this module is:  EUC characters have
71  * a display width less than 255.  Also, assumed around, is that they
72  * consist of < 256 bytes, but we don't worry much about that.
73  */
74 
75 #define	EUC_TWIDTH	255	/* Width of a TAB, as returned by */
76 				/* "ldterm_dispwidth" */
77 #define	EUC_BSWIDTH	254	/* Width of a backspace as returned */
78 #define	EUC_NLWIDTH	253	/* newline & cr */
79 #define	EUC_CRWIDTH	252
80 
81 #define	UNKNOWN_WIDTH	251
82 
83 #define	EUC_MAXW	4	/* max display width and memory width, both */
84 #define	EUC_WARNCNT	20	/* # bad EUC erase attempts before hollering */
85 
86 /* The next version will be the current LDTERM_DATA_VERSION + 1. */
87 #define	LDTERM_DATA_VERSION		1
88 
89 /*
90  * Supported codeset types:
91  * When you are adding a new codeset type,  do not add any new codeset type
92  * value that is smaller than LDTERM_CS_TYPE_MIN. You will also need to
93  * add the new codeset type sequentially and also increase LDTERM_CS_TYPE_MAX
94  * so that the LDTERM_CS_TYPE_MAX will be always equal to the last, new
95  * codeset type value.
96  *
97  * Whenever you increase the LDTERM_CS_TYPE_MAX, you will also need to
98  * increase the LDTERM_DATA_VERSION and also update the ldterm.c so that
99  * ldterm will have proper version control.
100  */
101 #define	LDTERM_CS_TYPE_MIN		1
102 
103 #define	LDTERM_CS_TYPE_EUC		1
104 #define	LDTERM_CS_TYPE_PCCS		2
105 #define	LDTERM_CS_TYPE_UTF8		3
106 
107 #define	LDTERM_CS_TYPE_MAX		3
108 
109 /*
110  * The maximum number of bytes in a character of the codeset that
111  * can be handled by ldterm.
112  */
113 #define	LDTERM_CS_MAX_BYTE_LENGTH	8
114 
115 /*
116  * The maximum number of sub-codesets in a codeset that can be
117  * handled by ldterm.
118  */
119 #define	LDTERM_CS_MAX_CODESETS		10
120 
121 /* The maximum and minimum sub-codeset numbers possible in EUC codeset. */
122 #define	LDTERM_CS_TYPE_EUC_MIN_SUBCS	0
123 #define	LDTERM_CS_TYPE_EUC_MAX_SUBCS	3
124 
125 /* The maximum and minimum sub-codeset numbers possible in PCCS codeset. */
126 #define	LDTERM_CS_TYPE_PCCS_MIN_SUBCS	1
127 #define	LDTERM_CS_TYPE_PCCS_MAX_SUBCS	LDTERM_CS_MAX_CODESETS
128 
129 /* Some UTF-8 related values: */
130 /* The maximum and minimum UTF-8 character subsequent byte values. */
131 #define	LDTERM_CS_TYPE_UTF8_MIN_BYTE	0x80
132 #define	LDTERM_CS_TYPE_UTF8_MAX_BYTE	0xbf
133 
134 /* Some maximum and minimum character values in UTF-32. */
135 #define	LDTERM_CS_TYPE_UTF8_MAX_P00	0x00ffff
136 #define	LDTERM_CS_TYPE_UTF8_MAX_P01	0x01ffff
137 #define	LDTERM_CS_TYPE_UTF8_MIN_CJKEXTB	0x020000
138 #define	LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB	0x02a6d6
139 #define	LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP	0x02f800
140 #define	LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP	0x02fa1d
141 #define	LDTERM_CS_TYPE_UTF8_MIN_P14	0x0e0000
142 #define	LDTERM_CS_TYPE_UTF8_MAX_P14	0x0e007f
143 #define	LDTERM_CS_TYPE_UTF8_MIN_VARSEL	0x0e0100
144 #define	LDTERM_CS_TYPE_UTF8_MAX_VARSEL	0x0e01ef
145 #define	LDTERM_CS_TYPE_UTF8_MIN_P15	0x0f0000
146 #define	LDTERM_CS_TYPE_UTF8_MAX_P15	0x0ffffd
147 #define	LDTERM_CS_TYPE_UTF8_MIN_P16	0x100000
148 #define	LDTERM_CS_TYPE_UTF8_MAX_P16	0x10fffd
149 
150 /* Bit shift number and mask values for conversion from UTF-8 to UCS-4. */
151 #define	LDTERM_CS_TYPE_UTF8_SHIFT_BITS	6
152 #define	LDTERM_CS_TYPE_UTF8_BIT_MASK	0x3f
153 
154 /*
155  * The following data structure is to provide codeset-specific
156  * information for EUC and PC originated codesets (ldterm_eucpc_data_t)
157  */
158 struct _ldterm_eucpc_data {
159 	uchar_t	byte_length;
160 	uchar_t	screen_width;
161 	uchar_t	msb_start;
162 	uchar_t	msb_end;
163 };
164 typedef struct _ldterm_eucpc_data ldterm_eucpc_data_t;
165 
166 /* ldterm codeset data information for user side. */
167 struct _ldterm_cs_data_user {
168 	uchar_t	version;	/* version: 1 ~ 255 */
169 	uchar_t	codeset_type;
170 	uchar_t	csinfo_num;	/* the # of codesets */
171 	uchar_t	pad;
172 	char	locale_name[MAXNAMELEN];
173 	ldterm_eucpc_data_t	eucpc_data[LDTERM_CS_MAX_CODESETS];
174 						/* width data */
175 };
176 typedef struct _ldterm_cs_data_user ldterm_cs_data_user_t;
177 
178 /* ldterm codeset data information for ldterm. */
179 struct _ldterm_cs_data {
180 	uchar_t	version;	/* version: 1 ~ 255 */
181 	uchar_t	codeset_type;
182 	uchar_t	csinfo_num;	/* the # of codesets */
183 	uchar_t	pad;
184 	char	*locale_name;
185 	ldterm_eucpc_data_t	eucpc_data[LDTERM_CS_MAX_CODESETS];
186 						/* width data */
187 };
188 typedef struct _ldterm_cs_data ldterm_cs_data_t;
189 
190 /*
191  * The following data structure is to handle Unicode codeset.
192  * To represent a single Unicode plane, it requires to have 16384
193  * 'ldterm_unicode_data_cell_t' elements.
194  */
195 struct _ldterm_unicode_data_cell {
196 	uchar_t	u0:2;
197 	uchar_t	u1:2;
198 	uchar_t	u2:2;
199 	uchar_t	u3:2;
200 };
201 typedef struct _ldterm_unicode_data_cell ldterm_unicode_data_cell_t;
202 
203 /* The following function pointers point the current codeset methods.  */
204 typedef struct _ldterm_cs_methods {
205 	int (*ldterm_dispwidth)(uchar_t, void *, int);
206 	int (*ldterm_memwidth)(uchar_t, void *);
207 } ldterm_cs_methods_t;
208 
209 typedef struct ldterm_mod {
210 	struct termios t_modes;	/* Effective modes set by the provider below */
211 	struct termios t_amodes; /* Apparent modes for user programs */
212 	struct termios t_dmodes; /* Modes that driver wishes to process */
213 	unsigned int t_state;	/* internal state of ldterm module */
214 	int	t_line;		/* output line of tty */
215 	int	t_col;		/* output column of tty */
216 	int	t_rocount;	/* number of chars echoed since last output */
217 	int	t_rocol;	/* column in which first such char appeared */
218 	mblk_t	*t_message;	/* pointer to first mblk in message being */
219 				/* built */
220 	mblk_t	*t_endmsg;	/* pointer to last mblk in that message */
221 	size_t	t_msglen;	/* number of characters in that message */
222 	mblk_t	*t_echomp;	/* echoed output being assembled */
223 	int	t_rd_request;   /* Number of bytes requested by M_READ */
224 				/* during vmin/vtime read */
225 	int	t_iocid;	/* ID of ioctl reply being awaited */
226 	bufcall_id_t t_wbufcid;	/* ID of pending write-side bufcall */
227 	timeout_id_t t_vtid;	/* vtime timer id */
228 
229 	/*
230 	 * The following are for EUC and also other types of codeset
231 	 * processing. Please read 'euc' as 'multi-byte codeset' instead.
232 	 */
233 	uchar_t	t_codeset;	/* current code set indicator (read side) */
234 	uchar_t	t_eucleft;	/* bytes left to get in current char (read) */
235 	uchar_t	t_eucign;	/* bytes left to ignore (output post proc) */
236 	uchar_t	t_eucpad;	/* padding ... for eucwioc */
237 	eucioc_t eucwioc;	/* eucioc structure (have to use bcopy) */
238 	uchar_t	*t_eucp;	/* ptr to parallel array of column widths */
239 	mblk_t	*t_eucp_mp;	/* the m_blk that holds parallel array */
240 	uchar_t	t_maxeuc;	/* the max length in memory bytes of an EUC */
241 	int	t_eucwarn;	/* bad EUC counter */
242 
243 	/*
244 	 * The t_csdata, t_csmethods, t_scratch, and, t_scratch_len data
245 	 * fields are to support various non-EUC codesets.
246 	 */
247 	ldterm_cs_data_t	t_csdata;
248 	struct _ldterm_cs_methods t_csmethods;
249 	uchar_t			t_scratch[LDTERM_CS_MAX_BYTE_LENGTH];
250 	uchar_t			t_scratch_len;
251 
252 	mblk_t	*t_closeopts;	/* preallocated stroptions for close */
253 	mblk_t	*t_drainmsg;	/* preallocated TCSBRK drain message */
254 } ldtermstd_state_t;
255 
256 /*
257  * Internal state bits.
258  */
259 #define	TS_XCLUDE	0x00000001	/* exclusive-use flag against open */
260 #define	TS_TTSTOP	0x00000002	/* output stopped by ^S */
261 #define	TS_TBLOCK	0x00000004	/* input stopped by IXOFF mode */
262 #define	TS_QUOT		0x00000008	/* last character input was \ */
263 #define	TS_ERASE	0x00000010	/* within a \.../ for PRTRUB */
264 #define	TS_SLNCH	0x00000020	/* next character service routine */
265 					/* sees is literal */
266 #define	TS_PLNCH	0x00000040	/* next character put routine sees */
267 					/* is literal */
268 
269 #define	TS_TTCR		0x00000080	/* mapping NL to CR-NL */
270 #define	TS_NOCANON	0x00000100	/* canonicalization done by somebody */
271 					/* below us */
272 #define	TS_RESCAN	0x00000400	/* canonicalization mode changed, */
273 					/* rescan input queue */
274 #define	TS_MREAD	0x00000800	/* timer started for vmin/vtime */
275 #define	TS_FLUSHWAIT	0x00001000	/* waiting for flush on write side */
276 #define	TS_MEUC		0x00010000	/* TRUE if multi-byte codesets used */
277 #define	TS_WARNED	0x00020000	/* already warned on console */
278 #define	TS_CLOSE	0x00040000	/* close in progress */
279 #define	TS_IOCWAIT	0x00080000	/* waiting for reply to ioctl message */
280 #define	TS_IFBLOCK	0x00100000	/* input flow blocked */
281 #define	TS_OFBLOCK	0x00200000	/* output flow blocked */
282 #define	TS_ISPTSTTY	0x00400000	/* is x/open terminal */
283 
284 #ifdef	__cplusplus
285 }
286 #endif
287 
288 #endif	/* _SYS_LDTERM_H */
289