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