xref: /onnv-gate/usr/src/uts/common/sys/tem_impl.h (revision 3994:4fafdadace7c)
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
51253Slq150181  * Common Development and Distribution License (the "License").
61253Slq150181  * 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  */
211253Slq150181 
220Sstevel@tonic-gate /*
23*3994Slq150181  * Copyright 2007 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 
411253Slq150181 #include <sys/types.h>
421253Slq150181 #include <sys/sunddi.h>
430Sstevel@tonic-gate #include <sys/sunldi.h>
440Sstevel@tonic-gate #include <sys/visual_io.h>
451253Slq150181 #include <sys/font.h>
461253Slq150181 #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
832216Slt200341 #define	A_STATE_CSI			2
842216Slt200341 #define	A_STATE_CSI_QMARK		3
852216Slt200341 #define	A_STATE_CSI_EQUAL		4
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /*
880Sstevel@tonic-gate  * Default number of rows and columns
890Sstevel@tonic-gate  */
900Sstevel@tonic-gate #define	TEM_DEFAULT_ROWS	34
910Sstevel@tonic-gate #define	TEM_DEFAULT_COLS	80
920Sstevel@tonic-gate 
93*3994Slq150181 /*
94*3994Slq150181  * Default foreground/background color
95*3994Slq150181  */
96*3994Slq150181 #ifdef _HAVE_TEM_FIRMWARE
97*3994Slq150181 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_BLACK
98*3994Slq150181 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_WHITE
99*3994Slq150181 #else /* _HAVE_TEM_FIRMWARE */
100*3994Slq150181 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_WHITE
101*3994Slq150181 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_BLACK
102*3994Slq150181 #endif
103*3994Slq150181 
1040Sstevel@tonic-gate #define	BUF_LEN		160 /* Two lines of data can be processed at a time */
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate typedef uint8_t text_color_t;
1070Sstevel@tonic-gate 
108*3994Slq150181 typedef struct tem_color {
109*3994Slq150181 	text_color_t	fg_color;
110*3994Slq150181 	text_color_t	bg_color;
111*3994Slq150181 	unsigned short	a_flags;
112*3994Slq150181 } tem_color_t;
113*3994Slq150181 
1140Sstevel@tonic-gate struct tem_pix_pos {
1150Sstevel@tonic-gate 	screen_pos_t	x;
1160Sstevel@tonic-gate 	screen_pos_t	y;
1170Sstevel@tonic-gate };
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate struct tem_char_pos {
1200Sstevel@tonic-gate 	screen_pos_t	col;
1210Sstevel@tonic-gate 	screen_pos_t	row;
1220Sstevel@tonic-gate };
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate struct tem_size {
1250Sstevel@tonic-gate 	screen_size_t	width;
1260Sstevel@tonic-gate 	screen_size_t	height;
1270Sstevel@tonic-gate };
1280Sstevel@tonic-gate 
1291253Slq150181 typedef struct {
1301253Slq150181 	uint8_t red[16];
1311253Slq150181 	uint8_t green[16];
1321253Slq150181 	uint8_t blue[16];
1331253Slq150181 } text_cmap_t;
1341253Slq150181 
1351253Slq150181 extern text_cmap_t cmap4_to_24;
1361253Slq150181 
1371253Slq150181 struct tem;	/* Forward declare */
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate struct in_func_ptrs {
1421253Slq150181 	void (*f_display)(struct tem *, unsigned char *, int,
1430Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, unsigned char, unsigned char,
1440Sstevel@tonic-gate 	    cred_t *, enum called_from);
1451253Slq150181 	void (*f_copy)(struct tem *,
1460Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
1470Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
1481253Slq150181 	void (*f_cursor)(struct tem *, short, cred_t *,
1490Sstevel@tonic-gate 	    enum called_from);
1501253Slq150181 	void (*f_bit2pix)(struct tem *, unsigned char,
1510Sstevel@tonic-gate 	    unsigned char, unsigned char);
1521253Slq150181 	void (*f_cls)(struct tem *, int,
1530Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
1540Sstevel@tonic-gate };
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate /*
1570Sstevel@tonic-gate  * State structure for terminal emulator
1580Sstevel@tonic-gate  */
1591253Slq150181 typedef struct tem_state {		/* state for tem x3.64 emulator */
1601253Slq150181 	int	display_mode;		/* What mode we are in */
1611253Slq150181 	screen_size_t	linebytes;	/* Layered on bytes per scan line */
1620Sstevel@tonic-gate 	unsigned short	a_flags;	/* flags for this x3.64 terminal */
1630Sstevel@tonic-gate 	int	a_state;	/* state in output esc seq processing */
1640Sstevel@tonic-gate 	boolean_t	a_gotparam;	/* does output esc seq have a param */
1650Sstevel@tonic-gate 	int	a_curparam;	/* current param # of output esc seq */
1660Sstevel@tonic-gate 	int	a_paramval;	/* value of current param */
1670Sstevel@tonic-gate 	int	a_params[TEM_MAXPARAMS];  /* parameters of output esc seq */
1680Sstevel@tonic-gate 	screen_pos_t	a_tabs[TEM_MAXTAB];	/* tab stops */
1690Sstevel@tonic-gate 	int	a_ntabs;		/* number of tabs used */
1700Sstevel@tonic-gate 	int	a_nscroll;		/* number of lines to scroll */
1710Sstevel@tonic-gate 	struct tem_char_pos a_s_cursor;	/* start cursor position */
1720Sstevel@tonic-gate 	struct tem_char_pos a_c_cursor;	/* current cursor position */
1730Sstevel@tonic-gate 	struct tem_char_pos a_r_cursor;	/* remembered cursor position */
1740Sstevel@tonic-gate 	struct tem_size a_c_dimension;	/* window dimensions in characters */
1750Sstevel@tonic-gate 	struct tem_size a_p_dimension;	/* screen dimensions in pixels */
1760Sstevel@tonic-gate 	struct tem_pix_pos a_p_offset;	/* pix offset to center the display */
1770Sstevel@tonic-gate 	unsigned char	*a_outbuf;	/* place to keep incomplete lines */
1780Sstevel@tonic-gate 	unsigned char	*a_blank_line;	/* a blank line for scrolling */
1790Sstevel@tonic-gate 	int	a_outindex;	/* index into a_outbuf */
1800Sstevel@tonic-gate 	struct in_func_ptrs	in_fp;	/* internal output functions */
1810Sstevel@tonic-gate 	struct font	a_font;	/* font table */
1820Sstevel@tonic-gate 	int	a_pdepth;	/* pixel depth */
1830Sstevel@tonic-gate 	int	a_initialized;	/* initialization flag */
1840Sstevel@tonic-gate 	void   *a_pix_data;	/* pointer to tmp bitmap area */
1850Sstevel@tonic-gate 	int	a_pix_data_size; /* size of bitmap data areas */
1860Sstevel@tonic-gate 	text_color_t fg_color;
1870Sstevel@tonic-gate 	text_color_t bg_color;
1881253Slq150181 	int	first_line;	/* kernel console output begins */
1891253Slq150181 } tem_state_t;
1901253Slq150181 
1911253Slq150181 /*
1921253Slq150181  * State structure for terminal emulator
1931253Slq150181  */
1941253Slq150181 typedef struct tem {
1951253Slq150181 #ifdef	_HAVE_TEM_FIRMWARE
1961253Slq150181 	void (*cons_wrtvec)	/* PROM output gets redirected thru this vec. */
1971253Slq150181 	    (struct tem *, uchar_t *, ssize_t, cred_t *);
1981253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
1991253Slq150181 	ldi_handle_t		hdl; /* Framework handle for layered on dev */
2001253Slq150181 	dev_info_t		*dip; /* Our dip */
2011253Slq150181 	kmutex_t		lock;
2021253Slq150181 	struct vis_polledio	*fb_polledio;
2031253Slq150181 	tem_state_t		*state;
2041253Slq150181 	tem_modechg_cb_t	modechg_cb;
2051253Slq150181 	tem_modechg_cb_arg_t	modechg_arg;
206*3994Slq150181 	tem_color_t		init_color; /* initial color and attributes */
2071253Slq150181 } tem_t;
2081253Slq150181 
2091253Slq150181 void	tem_check_first_time(tem_t *tem, cred_t *, enum called_from);
2101253Slq150181 void	tem_reset_colormap(tem_t *, cred_t *, enum called_from);
2111253Slq150181 void	tem_align_cursor(tem_t *);
212*3994Slq150181 void	tem_reset_emulator(tem_t *, cred_t *, enum called_from, tem_color_t *);
213*3994Slq150181 void	tem_reset_display(tem_t *, cred_t *, enum called_from, int,
214*3994Slq150181 			tem_color_t *);
2151253Slq150181 void	tem_display_layered(tem_t *, struct vis_consdisplay *, cred_t *);
2161253Slq150181 void	tem_copy_layered(tem_t *, struct vis_conscopy *, cred_t *);
2171253Slq150181 void	tem_cursor_layered(tem_t *, struct vis_conscursor *, cred_t *);
2181253Slq150181 void	tem_terminal_emulate(tem_t *, uchar_t *, int, cred_t *,
2191253Slq150181 			enum called_from);
2201253Slq150181 void	tem_text_display(tem_t *, uchar_t *,
2211253Slq150181 			int, screen_pos_t, screen_pos_t,
2221253Slq150181 			text_color_t, text_color_t,
2231253Slq150181 			cred_t *, enum called_from);
2241253Slq150181 void	tem_text_copy(tem_t *,
2251253Slq150181 			screen_pos_t, screen_pos_t,
2261253Slq150181 			screen_pos_t, screen_pos_t,
2271253Slq150181 			screen_pos_t, screen_pos_t,
2281253Slq150181 			cred_t *, enum called_from);
2291253Slq150181 void	tem_text_cursor(tem_t *, short, cred_t *, enum called_from);
2301253Slq150181 void	tem_text_cls(tem_t *,
2311253Slq150181 			int count, screen_pos_t row, screen_pos_t col,
2321253Slq150181 			cred_t *credp, enum called_from called_from);
2331253Slq150181 void	tem_pix_display(tem_t *, uchar_t *,
2341253Slq150181 			int, screen_pos_t, screen_pos_t,
2351253Slq150181 			text_color_t, text_color_t,
2361253Slq150181 			cred_t *, enum called_from);
2371253Slq150181 void	tem_pix_copy(tem_t *,
2381253Slq150181 			screen_pos_t, screen_pos_t,
2391253Slq150181 			screen_pos_t, screen_pos_t,
2401253Slq150181 			screen_pos_t, screen_pos_t,
2411253Slq150181 			cred_t *, enum called_from);
2421253Slq150181 void	tem_copy(tem_t *,
2431253Slq150181 			struct vis_conscopy *,
2441253Slq150181 			cred_t *, enum called_from);
2451253Slq150181 void	tem_pix_cursor(tem_t *, short, cred_t *, enum called_from);
2461253Slq150181 void	tem_pix_cls(tem_t *, int, screen_pos_t, screen_pos_t,
2471253Slq150181 			cred_t *, enum called_from);
2481253Slq150181 void	tem_pix_cls_range(tem_t *,
2491253Slq150181 			screen_pos_t, int, int,
2501253Slq150181 			screen_pos_t, int, int,
2511253Slq150181 			boolean_t, cred_t *, enum called_from);
2521253Slq150181 
2531253Slq150181 void	bit_to_pix24(tem_t *, uchar_t, text_color_t, text_color_t);
2541253Slq150181 void	bit_to_pix8(tem_t *, uchar_t, text_color_t, text_color_t);
2551253Slq150181 void	bit_to_pix4(tem_t *, uchar_t, text_color_t, text_color_t);
2561253Slq150181 
2571253Slq150181 text_color_t ansi_bg_to_solaris(tem_t *, int);
2581253Slq150181 text_color_t ansi_fg_to_solaris(tem_t *, int);
2591253Slq150181 
2601253Slq150181 void	set_font(struct font *, short *, short *, short, short);
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate #ifdef __cplusplus
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate #endif
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate #endif /* _SYS_TEM_IMPL_H */
267