syscons.h revision 42831
1/*-
2 * Copyright (c) 1995-1998 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer,
10 *    without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 *	$Id: syscons.h,v 1.45 1999/01/11 03:18:29 yokota Exp $
29 */
30
31#ifndef _DEV_SYSCONS_SYSCONS_H_
32#define	_DEV_SYSCONS_SYSCONS_H_
33
34/* vm things */
35#define	ISMAPPED(pa, width) \
36	(((pa) <= (u_long)0x1000 - (width)) \
37	 || ((pa) >= 0xa0000 && (pa) <= 0x100000 - (width)))
38#define	pa_to_va(pa)	(KERNBASE + (pa))	/* works if ISMAPPED(pa...) */
39
40/* printable chars */
41#define PRINTABLE(ch)	((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
42			 || (ch) < 0x07)
43
44/* macros for "intelligent" screen update */
45#define mark_for_update(scp, x)	{\
46			  	    if ((x) < scp->start) scp->start = (x);\
47				    else if ((x) > scp->end) scp->end = (x);\
48				}
49#define mark_all(scp)		{\
50				    scp->start = 0;\
51				    scp->end = scp->xsize * scp->ysize - 1;\
52				}
53
54/* status flags */
55#define UNKNOWN_MODE	0x00010
56#define SWITCH_WAIT_REL	0x00080
57#define SWITCH_WAIT_ACQ	0x00100
58#define BUFFER_SAVED	0x00200
59#define CURSOR_ENABLED 	0x00400
60#define MOUSE_ENABLED	0x00800
61#define MOUSE_MOVED	0x01000
62#define MOUSE_CUTTING	0x02000
63#define MOUSE_VISIBLE	0x04000
64#define GRAPHICS_MODE	0x08000
65#define PIXEL_MODE	0x10000
66#define SAVER_RUNNING	0x20000
67
68/* configuration flags */
69#define VISUAL_BELL	0x00001
70#define BLINK_CURSOR	0x00002
71#define CHAR_CURSOR	0x00004
72/* these options are now obsolete; use corresponding options for kbd driver */
73#if 0
74#define DETECT_KBD	0x00008
75#define XT_KEYBD	0x00010
76#define KBD_NORESET	0x00020
77#endif
78#define QUIET_BELL	0x00040
79#define VESA800X600	0x00080
80#define AUTODETECT_KBD	0x00100
81
82/* attribute flags */
83#define NORMAL_ATTR             0x00
84#define BLINK_ATTR              0x01
85#define BOLD_ATTR               0x02
86#define UNDERLINE_ATTR          0x04
87#define REVERSE_ATTR            0x08
88#define FOREGROUND_CHANGED      0x10
89#define BACKGROUND_CHANGED      0x20
90
91/* misc defines */
92#define FALSE		0
93#define TRUE		1
94#define MAX_ESC_PAR 	5
95#define	LOAD		1
96#define SAVE		0
97#define	COL		80
98#define	ROW		25
99#define BELL_DURATION	5
100#define BELL_PITCH	800
101#define CONSOLE_BUFSIZE 1024
102#define PCBURST		128
103#define FONT_NONE	1
104#define FONT_8		2
105#define FONT_14		4
106#define FONT_16		8
107
108/* special characters */
109#define cntlc		0x03
110#define cntld		0x04
111#define bs		0x08
112#define lf		0x0a
113#define cr		0x0d
114#define del		0x7f
115
116#define DEAD_CHAR 	0x07			/* char used for cursor */
117
118typedef struct term_stat {
119	int 		esc;			/* processing escape sequence */
120	int 		num_param;		/* # of parameters to ESC */
121	int	 	last_param;		/* last parameter # */
122	int 		param[MAX_ESC_PAR];	/* contains ESC parameters */
123	int             cur_attr;               /* current hardware attr word */
124	int             attr_mask;              /* current logical attr mask */
125	int             cur_color;              /* current hardware color */
126	int             std_color;              /* normal hardware color */
127	int             rev_color;              /* reverse hardware color */
128} term_stat;
129
130typedef struct scr_stat {
131	int		ad;			/* video adapter index */
132	video_adapter_t	*adp;			/* video adapter structure */
133	u_short 	*scr_buf;		/* buffer when off screen */
134	int 		xpos;			/* current X position */
135	int 		ypos;			/* current Y position */
136	int             saved_xpos;             /* saved X position */
137	int             saved_ypos;             /* saved Y position */
138	int 		xsize;			/* X text size */
139	int 		ysize;			/* Y text size */
140	int 		xpixel;			/* X graphics size */
141	int 		ypixel;			/* Y graphics size */
142	int		xoff;			/* X offset in pixel mode */
143	int		yoff;			/* Y offset in pixel mode */
144	int		font_size;		/* fontsize in Y direction */
145	int		start;			/* modified area start */
146	int		end;			/* modified area end */
147	term_stat 	term;			/* terminal emulation stuff */
148	int	 	status;			/* status (bitfield) */
149	int		kbd_mode;		/* keyboard I/O mode */
150	u_short 	*cursor_pos;		/* cursor buffer position */
151	u_short 	*cursor_oldpos;		/* cursor old buffer position */
152	u_short		cursor_saveunder;	/* saved chars under cursor */
153	char		cursor_start;		/* cursor start line # */
154	char		cursor_end;		/* cursor end line # */
155	u_short		*mouse_pos;		/* mouse buffer position */
156	u_short		*mouse_oldpos;		/* mouse old buffer position */
157	short		mouse_xpos;		/* mouse x coordinate */
158	short		mouse_ypos;		/* mouse y coordinate */
159	short		mouse_buttons;		/* mouse buttons */
160	u_char		mouse_cursor[128];	/* mouse cursor bitmap store */
161	u_short		*mouse_cut_start;	/* mouse cut start pos */
162	u_short		*mouse_cut_end;		/* mouse cut end pos */
163	struct proc 	*mouse_proc;		/* proc* of controlling proc */
164	pid_t 		mouse_pid;		/* pid of controlling proc */
165	int		mouse_signal;		/* signal # to report with */
166	u_short		bell_duration;
167	u_short		bell_pitch;
168	u_char		border;			/* border color */
169	int	 	mode;			/* mode */
170	pid_t 		pid;			/* pid of controlling proc */
171	struct proc 	*proc;			/* proc* of controlling proc */
172	struct vt_mode 	smode;			/* switch mode */
173	u_short		*history;		/* circular history buffer */
174	u_short		*history_head;		/* current head position */
175	u_short		*history_pos;		/* position shown on screen */
176	u_short		*history_save;		/* save area index */
177	int		history_size;		/* size of history buffer */
178#ifdef __i386__
179	struct apmhook  r_hook;			/* reconfiguration support */
180#endif
181	int		splash_save_mode;	/* saved mode for splash screen */
182	int		splash_save_status;	/* saved status for splash screen */
183} scr_stat;
184
185typedef struct default_attr {
186	int             std_color;              /* normal hardware color */
187	int             rev_color;              /* reverse hardware color */
188} default_attr;
189
190
191#define ISTEXTSC(scp)	(!((scp)->status 				\
192			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
193#define ISGRAPHSC(scp)	(((scp)->status 				\
194			  & (UNKNOWN_MODE | GRAPHICS_MODE)))
195#define ISPIXELSC(scp)	(((scp)->status 				\
196			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
197			  == PIXEL_MODE)
198#define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
199
200#define ISFONTAVAIL(af)	((af) & V_ADP_FONT)
201#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
202#define ISPALAVAIL(af)	((af) & V_ADP_PALETTE)
203
204/* misc prototypes used by different syscons related LKM's */
205
206/* syscons.c */
207int sc_probe_unit(int unit, int flags);
208int sc_attach_unit(int unit, int flags);
209
210extern int (*sc_user_ioctl)(dev_t dev, u_long cmd, caddr_t data, int flag,
211			    struct proc *p);
212
213int set_mode(scr_stat *scp);
214scr_stat *sc_get_scr_stat(dev_t dev);
215
216void copy_font(scr_stat *scp, int operation, int font_size, u_char *font_image);
217void set_border(scr_stat *scp, int color);
218#define save_palette(adp, pal)				\
219	(*vidsw[(adp)->va_index]->save_palette)((adp), (pal))
220#define load_palette(adp, pal)				\
221	(*vidsw[(adp)->va_index]->load_palette)((adp), (pal))
222
223void sc_touch_scrn_saver(void);
224void sc_clear_screen(scr_stat *scp);
225void sc_move_mouse(scr_stat *scp, int x, int y);
226int sc_clean_up(scr_stat *scp);
227void sc_alloc_scr_buffer(scr_stat *scp, int wait, int clear);
228void sc_alloc_cut_buffer(scr_stat *scp, int wait);
229void sc_alloc_history_buffer(scr_stat *scp, int lines, int extra, int wait);
230struct tty *scdevtotty(dev_t dev);
231
232/* scvidctl.c */
233int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
234		     int xsize, int ysize, int fontsize);
235int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
236int sc_set_pixel_mode(scr_stat *scp, struct tty *tp,
237		      int xsize, int ysize, int fontsize);
238int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
239		 struct proc *p);
240
241#endif /* !_DEV_SYSCONS_SYSCONS_H_ */
242