xref: /onnv-gate/usr/src/uts/common/sys/tem_impl.h (revision 1253:0df630a41817)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1253Slq150181  * Common Development and Distribution License (the "License").
6*1253Slq150181  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*1253Slq150181 
220Sstevel@tonic-gate /*
23*1253Slq150181  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
300Sstevel@tonic-gate /*	  All Rights Reserved  	*/
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifndef	_SYS_TEM_IMPL_H
330Sstevel@tonic-gate #define	_SYS_TEM_IMPL_H
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #ifdef __cplusplus
380Sstevel@tonic-gate extern "C" {
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
41*1253Slq150181 #include <sys/types.h>
42*1253Slq150181 #include <sys/sunddi.h>
430Sstevel@tonic-gate #include <sys/sunldi.h>
440Sstevel@tonic-gate #include <sys/visual_io.h>
45*1253Slq150181 #include <sys/font.h>
46*1253Slq150181 #include <sys/tem.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * definitions for ANSI x3.64 terminal control language parser
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #define	TEM_MAXPARAMS	5	/* maximum number of ANSI paramters */
530Sstevel@tonic-gate #define	TEM_MAXTAB	40	/* maximum number of tab stops */
540Sstevel@tonic-gate #define	TEM_MAXFKEY	30	/* max length of function key with <ESC>Q */
550Sstevel@tonic-gate #define	MAX_TEM		2	/* max number of loadable terminal emulators */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define	TEM_SCROLL_UP		0
580Sstevel@tonic-gate #define	TEM_SCROLL_DOWN		1
590Sstevel@tonic-gate #define	TEM_SHIFT_LEFT		0
600Sstevel@tonic-gate #define	TEM_SHIFT_RIGHT		1
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #define	TEM_ATTR_NORMAL		0x0000
630Sstevel@tonic-gate #define	TEM_ATTR_REVERSE	0x0001
640Sstevel@tonic-gate #define	TEM_ATTR_BOLD		0x0002
650Sstevel@tonic-gate #define	TEM_ATTR_BLINK		0x0004
660Sstevel@tonic-gate #define	TEM_ATTR_TRANSPARENT	0x0008
670Sstevel@tonic-gate #define	TEM_ATTR_SCREEN_REVERSE	0x0010
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #define	ANSI_COLOR_BLACK	0
700Sstevel@tonic-gate #define	ANSI_COLOR_WHITE	7
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #define	TEM_TEXT_WHITE		0
730Sstevel@tonic-gate #define	TEM_TEXT_BLACK		1
740Sstevel@tonic-gate #define	TEM_TEXT_BLACK24_RED	0x00
750Sstevel@tonic-gate #define	TEM_TEXT_BLACK24_GREEN	0x00
760Sstevel@tonic-gate #define	TEM_TEXT_BLACK24_BLUE	0x00
770Sstevel@tonic-gate #define	TEM_TEXT_WHITE24_RED	0xff
780Sstevel@tonic-gate #define	TEM_TEXT_WHITE24_GREEN	0xff
790Sstevel@tonic-gate #define	TEM_TEXT_WHITE24_BLUE	0xff
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #define	A_STATE_START			0
820Sstevel@tonic-gate #define	A_STATE_ESC			1
830Sstevel@tonic-gate #define	A_STATE_ESC_Q			2
840Sstevel@tonic-gate #define	A_STATE_ESC_Q_DELM		3
850Sstevel@tonic-gate #define	A_STATE_ESC_Q_DELM_CTRL		4
860Sstevel@tonic-gate #define	A_STATE_ESC_C			5
870Sstevel@tonic-gate #define	A_STATE_CSI			6
880Sstevel@tonic-gate #define	A_STATE_CSI_QMARK		7
890Sstevel@tonic-gate #define	A_STATE_CSI_EQUAL		8
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate  * Default number of rows and columns
930Sstevel@tonic-gate  */
940Sstevel@tonic-gate #define	TEM_DEFAULT_ROWS	34
950Sstevel@tonic-gate #define	TEM_DEFAULT_COLS	80
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	BUF_LEN		160 /* Two lines of data can be processed at a time */
980Sstevel@tonic-gate 
990Sstevel@tonic-gate typedef uint8_t text_color_t;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate struct tem_pix_pos {
1020Sstevel@tonic-gate 	screen_pos_t	x;
1030Sstevel@tonic-gate 	screen_pos_t	y;
1040Sstevel@tonic-gate };
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate struct tem_char_pos {
1070Sstevel@tonic-gate 	screen_pos_t	col;
1080Sstevel@tonic-gate 	screen_pos_t	row;
1090Sstevel@tonic-gate };
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate struct tem_size {
1120Sstevel@tonic-gate 	screen_size_t	width;
1130Sstevel@tonic-gate 	screen_size_t	height;
1140Sstevel@tonic-gate };
1150Sstevel@tonic-gate 
116*1253Slq150181 typedef struct {
117*1253Slq150181 	uint8_t red[16];
118*1253Slq150181 	uint8_t green[16];
119*1253Slq150181 	uint8_t blue[16];
120*1253Slq150181 } text_cmap_t;
121*1253Slq150181 
122*1253Slq150181 extern text_cmap_t cmap4_to_24;
123*1253Slq150181 
124*1253Slq150181 struct tem;	/* Forward declare */
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate struct in_func_ptrs {
129*1253Slq150181 	void (*f_display)(struct tem *, unsigned char *, int,
1300Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, unsigned char, unsigned char,
1310Sstevel@tonic-gate 	    cred_t *, enum called_from);
132*1253Slq150181 	void (*f_copy)(struct tem *,
1330Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
1340Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
135*1253Slq150181 	void (*f_cursor)(struct tem *, short, cred_t *,
1360Sstevel@tonic-gate 	    enum called_from);
137*1253Slq150181 	void (*f_bit2pix)(struct tem *, unsigned char,
1380Sstevel@tonic-gate 	    unsigned char, unsigned char);
139*1253Slq150181 	void (*f_cls)(struct tem *, int,
1400Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
1410Sstevel@tonic-gate };
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate /*
1440Sstevel@tonic-gate  * State structure for terminal emulator
1450Sstevel@tonic-gate  */
146*1253Slq150181 typedef struct tem_state {		/* state for tem x3.64 emulator */
147*1253Slq150181 	int	display_mode;		/* What mode we are in */
148*1253Slq150181 	screen_size_t	linebytes;	/* Layered on bytes per scan line */
1490Sstevel@tonic-gate 	unsigned short	a_flags;	/* flags for this x3.64 terminal */
1500Sstevel@tonic-gate 	int	a_state;	/* state in output esc seq processing */
1510Sstevel@tonic-gate 	boolean_t	a_gotparam;	/* does output esc seq have a param */
1520Sstevel@tonic-gate 	int	a_curparam;	/* current param # of output esc seq */
1530Sstevel@tonic-gate 	int	a_paramval;	/* value of current param */
1540Sstevel@tonic-gate 	int	a_params[TEM_MAXPARAMS];  /* parameters of output esc seq */
1550Sstevel@tonic-gate 	char	a_fkey[TEM_MAXFKEY];	/* work space for function key */
1560Sstevel@tonic-gate 	screen_pos_t	a_tabs[TEM_MAXTAB];	/* tab stops */
1570Sstevel@tonic-gate 	int	a_ntabs;		/* number of tabs used */
1580Sstevel@tonic-gate 	int	a_nscroll;		/* number of lines to scroll */
1590Sstevel@tonic-gate 	struct tem_char_pos a_s_cursor;	/* start cursor position */
1600Sstevel@tonic-gate 	struct tem_char_pos a_c_cursor;	/* current cursor position */
1610Sstevel@tonic-gate 	struct tem_char_pos a_r_cursor;	/* remembered cursor position */
1620Sstevel@tonic-gate 	struct tem_size a_c_dimension;	/* window dimensions in characters */
1630Sstevel@tonic-gate 	struct tem_size a_p_dimension;	/* screen dimensions in pixels */
1640Sstevel@tonic-gate 	struct tem_pix_pos a_p_offset;	/* pix offset to center the display */
1650Sstevel@tonic-gate 	unsigned char	*a_outbuf;	/* place to keep incomplete lines */
1660Sstevel@tonic-gate 	unsigned char	*a_blank_line;	/* a blank line for scrolling */
1670Sstevel@tonic-gate 	int	a_outindex;	/* index into a_outbuf */
1680Sstevel@tonic-gate 	struct in_func_ptrs	in_fp;	/* internal output functions */
1690Sstevel@tonic-gate 	struct font	a_font;	/* font table */
1700Sstevel@tonic-gate 	int	a_pdepth;	/* pixel depth */
1710Sstevel@tonic-gate 	int	a_initialized;	/* initialization flag */
1720Sstevel@tonic-gate 	void   *a_pix_data;	/* pointer to tmp bitmap area */
1730Sstevel@tonic-gate 	int	a_pix_data_size; /* size of bitmap data areas */
1740Sstevel@tonic-gate 	text_color_t fg_color;
1750Sstevel@tonic-gate 	text_color_t bg_color;
176*1253Slq150181 	int	first_line;	/* kernel console output begins */
177*1253Slq150181 } tem_state_t;
178*1253Slq150181 
179*1253Slq150181 /*
180*1253Slq150181  * State structure for terminal emulator
181*1253Slq150181  */
182*1253Slq150181 typedef struct tem {
183*1253Slq150181 #ifdef	_HAVE_TEM_FIRMWARE
184*1253Slq150181 	void (*cons_wrtvec)	/* PROM output gets redirected thru this vec. */
185*1253Slq150181 	    (struct tem *, uchar_t *, ssize_t, cred_t *);
186*1253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
187*1253Slq150181 	ldi_handle_t		hdl; /* Framework handle for layered on dev */
188*1253Slq150181 	dev_info_t		*dip; /* Our dip */
189*1253Slq150181 	kmutex_t		lock;
190*1253Slq150181 	struct vis_polledio	*fb_polledio;
191*1253Slq150181 	tem_state_t		*state;
192*1253Slq150181 	tem_modechg_cb_t	modechg_cb;
193*1253Slq150181 	tem_modechg_cb_arg_t	modechg_arg;
194*1253Slq150181 } tem_t;
195*1253Slq150181 
196*1253Slq150181 void	tem_check_first_time(tem_t *tem, cred_t *, enum called_from);
197*1253Slq150181 void	tem_reset_colormap(tem_t *, cred_t *, enum called_from);
198*1253Slq150181 void	tem_align_cursor(tem_t *);
199*1253Slq150181 void	tem_reset_emulator(tem_t *, cred_t *, enum called_from);
200*1253Slq150181 void	tem_reset_display(tem_t *, cred_t *, enum called_from, int);
201*1253Slq150181 void	tem_display_layered(tem_t *, struct vis_consdisplay *, cred_t *);
202*1253Slq150181 void	tem_copy_layered(tem_t *, struct vis_conscopy *, cred_t *);
203*1253Slq150181 void	tem_cursor_layered(tem_t *, struct vis_conscursor *, cred_t *);
204*1253Slq150181 void	tem_terminal_emulate(tem_t *, uchar_t *, int, cred_t *,
205*1253Slq150181 			enum called_from);
206*1253Slq150181 void	tem_text_display(tem_t *, uchar_t *,
207*1253Slq150181 			int, screen_pos_t, screen_pos_t,
208*1253Slq150181 			text_color_t, text_color_t,
209*1253Slq150181 			cred_t *, enum called_from);
210*1253Slq150181 void	tem_text_copy(tem_t *,
211*1253Slq150181 			screen_pos_t, screen_pos_t,
212*1253Slq150181 			screen_pos_t, screen_pos_t,
213*1253Slq150181 			screen_pos_t, screen_pos_t,
214*1253Slq150181 			cred_t *, enum called_from);
215*1253Slq150181 void	tem_text_cursor(tem_t *, short, cred_t *, enum called_from);
216*1253Slq150181 void	tem_text_cls(tem_t *,
217*1253Slq150181 			int count, screen_pos_t row, screen_pos_t col,
218*1253Slq150181 			cred_t *credp, enum called_from called_from);
219*1253Slq150181 void	tem_pix_display(tem_t *, uchar_t *,
220*1253Slq150181 			int, screen_pos_t, screen_pos_t,
221*1253Slq150181 			text_color_t, text_color_t,
222*1253Slq150181 			cred_t *, enum called_from);
223*1253Slq150181 void	tem_pix_copy(tem_t *,
224*1253Slq150181 			screen_pos_t, screen_pos_t,
225*1253Slq150181 			screen_pos_t, screen_pos_t,
226*1253Slq150181 			screen_pos_t, screen_pos_t,
227*1253Slq150181 			cred_t *, enum called_from);
228*1253Slq150181 void	tem_copy(tem_t *,
229*1253Slq150181 			struct vis_conscopy *,
230*1253Slq150181 			cred_t *, enum called_from);
231*1253Slq150181 void	tem_pix_cursor(tem_t *, short, cred_t *, enum called_from);
232*1253Slq150181 void	tem_pix_cls(tem_t *, int, screen_pos_t, screen_pos_t,
233*1253Slq150181 			cred_t *, enum called_from);
234*1253Slq150181 void	tem_pix_cls_range(tem_t *,
235*1253Slq150181 			screen_pos_t, int, int,
236*1253Slq150181 			screen_pos_t, int, int,
237*1253Slq150181 			boolean_t, cred_t *, enum called_from);
238*1253Slq150181 
239*1253Slq150181 void	bit_to_pix24(tem_t *, uchar_t, text_color_t, text_color_t);
240*1253Slq150181 void	bit_to_pix8(tem_t *, uchar_t, text_color_t, text_color_t);
241*1253Slq150181 void	bit_to_pix4(tem_t *, uchar_t, text_color_t, text_color_t);
242*1253Slq150181 
243*1253Slq150181 text_color_t ansi_bg_to_solaris(tem_t *, int);
244*1253Slq150181 text_color_t ansi_fg_to_solaris(tem_t *, int);
245*1253Slq150181 
246*1253Slq150181 void	set_font(struct font *, short *, short *, short, short);
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate #ifdef __cplusplus
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate #endif
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate #endif /* _SYS_TEM_IMPL_H */
253