syscons.h revision 50254
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.51 1999/08/20 20:25:00 julian Exp $
29 */
30
31#ifndef _DEV_SYSCONS_SYSCONS_H_
32#define	_DEV_SYSCONS_SYSCONS_H_
33
34/* machine-dependent part of the header */
35
36#ifdef PC98
37#include <pc98/pc98/sc_machdep.h>
38#elif defined(__i386__)
39/* nothing for the moment */
40#elif defined(__alpha__)
41/* nothing for the moment */
42#endif
43
44/* default values for configuration options */
45
46#ifndef MAXCONS
47#define MAXCONS		16
48#endif
49
50#ifdef SC_NO_SYSMOUSE
51#undef SC_NO_CUTPASTE
52#define SC_NO_CUTPASTE	1
53#endif
54
55#ifdef SC_NO_MODE_CHANGE
56#undef SC_PIXEL_MODE
57#endif
58
59#ifndef SC_DEBUG_LEVEL
60#define SC_DEBUG_LEVEL	0
61#endif
62
63#define DPRINTF(l, p)	if (SC_DEBUG_LEVEL >= (l)) printf p
64
65#define SC_DRIVER_NAME	"sc"
66#define SC_VTY(dev)	minor(dev)
67
68/* printable chars */
69#ifndef PRINTABLE
70#define PRINTABLE(ch)	((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
71			 || (ch) < 0x07)
72#endif
73
74/* macros for "intelligent" screen update */
75#define mark_for_update(scp, x)	{\
76			  	    if ((x) < scp->start) scp->start = (x);\
77				    else if ((x) > scp->end) scp->end = (x);\
78				}
79#define mark_all(scp)		{\
80				    scp->start = 0;\
81				    scp->end = scp->xsize * scp->ysize - 1;\
82				}
83
84/* vty status flags (scp->status) */
85#define UNKNOWN_MODE	0x00010
86#define SWITCH_WAIT_REL	0x00080
87#define SWITCH_WAIT_ACQ	0x00100
88#define BUFFER_SAVED	0x00200
89#define CURSOR_ENABLED 	0x00400
90#define MOUSE_MOVED	0x01000
91#define MOUSE_CUTTING	0x02000
92#define MOUSE_VISIBLE	0x04000
93#define GRAPHICS_MODE	0x08000
94#define PIXEL_MODE	0x10000
95#define SAVER_RUNNING	0x20000
96#define VR_CURSOR_BLINK	0x40000
97#define VR_CURSOR_ON	0x80000
98
99/* attribute flags */
100#define NORMAL_ATTR             0x00
101#define BLINK_ATTR              0x01
102#define BOLD_ATTR               0x02
103#define UNDERLINE_ATTR          0x04
104#define REVERSE_ATTR            0x08
105#define FOREGROUND_CHANGED      0x10
106#define BACKGROUND_CHANGED      0x20
107
108/* misc defines */
109#define FALSE		0
110#define TRUE		1
111#define MAX_ESC_PAR 	5
112#define	LOAD		1
113#define SAVE		0
114#define	COL		80
115#define	ROW		25
116#define CONSOLE_BUFSIZE 1024
117#define PCBURST		128
118#define FONT_NONE	1
119#define FONT_8		2
120#define FONT_14		4
121#define FONT_16		8
122
123#ifndef BELL_DURATION
124#define BELL_DURATION	5
125#define BELL_PITCH	800
126#endif
127
128/* special characters */
129#define cntlc		0x03
130#define cntld		0x04
131#define bs		0x08
132#define lf		0x0a
133#define cr		0x0d
134#define del		0x7f
135
136#define DEAD_CHAR 	0x07			/* char used for cursor */
137
138/* virtual terminal buffer */
139typedef struct sc_vtb {
140	int		vtb_flags;
141#define VTB_VALID	(1 << 0)
142	int		vtb_type;
143#define VTB_INVALID	0
144#define VTB_MEMORY	1
145#define VTB_FRAMEBUFFER	2
146#define VTB_RINGBUFFER	3
147	int		vtb_cols;
148	int		vtb_rows;
149	int		vtb_size;
150	vm_offset_t	vtb_buffer;
151	int		vtb_tail;	/* valid for VTB_RINGBUFFER only */
152} sc_vtb_t;
153
154/* terminal status */
155typedef struct term_stat {
156	int 		esc;			/* processing escape sequence */
157	int 		num_param;		/* # of parameters to ESC */
158	int	 	last_param;		/* last parameter # */
159	int 		param[MAX_ESC_PAR];	/* contains ESC parameters */
160	int             cur_attr;               /* current hardware attr word */
161	int             attr_mask;              /* current logical attr mask */
162	int             cur_color;              /* current hardware color */
163	int             std_color;              /* normal hardware color */
164	int             rev_color;              /* reverse hardware color */
165} term_stat;
166
167/* softc */
168
169struct keyboard;
170struct video_adapter;
171struct scr_stat;
172struct tty;
173
174typedef struct sc_softc {
175	int		unit;			/* unit # */
176	int		config;			/* configuration flags */
177#define SC_VESA800X600	(1 << 7)
178#define SC_AUTODETECT_KBD (1 << 8)
179#define SC_KERNEL_CONSOLE (1 << 9)
180
181	int		flags;			/* status flags */
182#define SC_VISUAL_BELL	(1 << 0)
183#define SC_QUIET_BELL	(1 << 1)
184#define SC_BLINK_CURSOR	(1 << 2)
185#define SC_CHAR_CURSOR	(1 << 3)
186#define SC_MOUSE_ENABLED (1 << 4)
187#define	SC_SCRN_IDLE	(1 << 5)
188#define	SC_SCRN_BLANKED	(1 << 6)
189#define	SC_SAVER_FAILED	(1 << 7)
190
191#define	SC_INIT_DONE	(1 << 16)
192#define	SC_SPLASH_SCRN	(1 << 17)
193
194	int		keyboard;		/* -1 if unavailable */
195	struct keyboard	*kbd;
196
197	int		adapter;
198	struct video_adapter *adp;
199	int		initial_mode;		/* initial video mode */
200
201	int		first_vty;
202	int		vtys;
203	struct tty	*tty;
204	struct scr_stat	**console;
205	struct scr_stat	*cur_scp;
206	struct scr_stat	*new_scp;
207	struct scr_stat	*old_scp;
208	int     	delayed_next_scr;
209
210	char        	font_loading_in_progress;
211	char        	switch_in_progress;
212	char        	videoio_in_progress;
213	char        	write_in_progress;
214	char        	blink_in_progress;
215
216	long		scrn_time_stamp;
217
218	char		cursor_base;
219	char		cursor_height;
220
221	u_char      	scr_map[256];
222	u_char      	scr_rmap[256];
223
224#ifdef _SC_MD_SOFTC_DECLARED_
225	sc_md_softc_t	md;			/* machine dependent vars */
226#endif
227
228#ifndef SC_NO_PALETTE_LOADING
229	u_char        	palette[256*3];
230#endif
231
232#ifndef SC_NO_FONT_LOADING
233	int     	fonts_loaded;
234	u_char		*font_8;
235	u_char		*font_14;
236	u_char		*font_16;
237#endif
238
239} sc_softc_t;
240
241/* virtual screen */
242typedef struct scr_stat {
243	int		index;			/* index of this vty */
244	struct sc_softc *sc;			/* pointer to softc */
245	struct sc_rndr_sw *rndr;		/* renderer */
246	sc_vtb_t	scr;
247	sc_vtb_t	vtb;
248	int 		xpos;			/* current X position */
249	int 		ypos;			/* current Y position */
250	int             saved_xpos;             /* saved X position */
251	int             saved_ypos;             /* saved Y position */
252	int 		xsize;			/* X text size */
253	int 		ysize;			/* Y text size */
254	int 		xpixel;			/* X graphics size */
255	int 		ypixel;			/* Y graphics size */
256	int		xoff;			/* X offset in pixel mode */
257	int		yoff;			/* Y offset in pixel mode */
258	u_char		*font;			/* current font */
259	int		font_size;		/* fontsize in Y direction */
260	int		start;			/* modified area start */
261	int		end;			/* modified area end */
262	term_stat 	term;			/* terminal emulation stuff */
263	int	 	status;			/* status (bitfield) */
264	int		kbd_mode;		/* keyboard I/O mode */
265	int		cursor_pos;		/* cursor buffer position */
266	int		cursor_oldpos;		/* cursor old buffer position */
267	u_short		cursor_saveunder_char;	/* saved char under cursor */
268	u_short		cursor_saveunder_attr;	/* saved attr under cursor */
269	char		cursor_base;		/* cursor base line # */
270	char		cursor_height;		/* cursor height */
271	int		mouse_pos;		/* mouse buffer position */
272	int		mouse_oldpos;		/* mouse old buffer position */
273	short		mouse_xpos;		/* mouse x coordinate */
274	short		mouse_ypos;		/* mouse y coordinate */
275	short		mouse_buttons;		/* mouse buttons */
276	int		mouse_cut_start;	/* mouse cut start pos */
277	int		mouse_cut_end;		/* mouse cut end pos */
278	struct proc 	*mouse_proc;		/* proc* of controlling proc */
279	pid_t 		mouse_pid;		/* pid of controlling proc */
280	int		mouse_signal;		/* signal # to report with */
281	u_short		bell_duration;
282	u_short		bell_pitch;
283	u_char		border;			/* border color */
284	int	 	mode;			/* mode */
285	pid_t 		pid;			/* pid of controlling proc */
286	struct proc 	*proc;			/* proc* of controlling proc */
287	struct vt_mode 	smode;			/* switch mode */
288	sc_vtb_t	*history;		/* circular history buffer */
289	int		history_pos;		/* position shown on screen */
290	int		history_size;		/* size of history buffer */
291	int		splash_save_mode;	/* saved mode for splash screen */
292	int		splash_save_status;	/* saved status for splash screen */
293#ifdef _SCR_MD_STAT_DECLARED_
294	scr_md_stat_t	md;			/* machine dependent vars */
295#endif
296} scr_stat;
297
298typedef struct default_attr {
299	int             std_color;              /* normal hardware color */
300	int             rev_color;              /* reverse hardware color */
301} default_attr;
302
303#ifndef SC_NORM_ATTR
304#define SC_NORM_ATTR		(FG_LIGHTGREY | BG_BLACK)
305#endif
306#ifndef SC_NORM_REV_ATTR
307#define SC_NORM_REV_ATTR	(FG_BLACK | BG_LIGHTGREY)
308#endif
309#ifndef SC_KERNEL_CONS_ATTR
310#define SC_KERNEL_CONS_ATTR	(FG_WHITE | BG_BLACK)
311#endif
312#ifndef SC_KERNEL_CONS_REV_ATTR
313#define SC_KERNEL_CONS_REV_ATTR	(FG_BLACK | BG_LIGHTGREY)
314#endif
315
316/* renderer function table */
317typedef void	vr_clear_t(scr_stat *scp, int c, int attr);
318typedef void	vr_draw_border_t(scr_stat *scp, int color);
319typedef void	vr_draw_t(scr_stat *scp, int from, int count, int flip);
320typedef void	vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
321typedef void	vr_draw_cursor_t(scr_stat *scp, int at, int blink,
322				 int on, int flip);
323typedef void	vr_blink_cursor_t(scr_stat *scp, int at, int flip);
324typedef void	vr_set_mouse_t(scr_stat *scp);
325typedef void	vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
326
327typedef struct sc_rndr_sw {
328	vr_clear_t		*clear;
329	vr_draw_border_t	*draw_border;
330	vr_draw_t		*draw;
331	vr_set_cursor_t		*set_cursor;
332	vr_draw_cursor_t	*draw_cursor;
333	vr_blink_cursor_t	*blink_cursor;
334	vr_set_mouse_t		*set_mouse;
335	vr_draw_mouse_t		*draw_mouse;
336} sc_rndr_sw_t;
337
338typedef struct sc_renderer {
339	char		*name;
340	int		mode;
341	sc_rndr_sw_t	*rndrsw;
342} sc_renderer_t;
343
344#define RENDERER(name, mode, sw)				\
345	static struct sc_renderer name##_##mode##_renderer = {	\
346		#name, mode, &sw				\
347	};							\
348	DATA_SET(scrndr_set, name##_##mode##_renderer)
349
350extern struct linker_set scrndr_set;
351
352typedef struct {
353	int		cursor_start;
354	int		cursor_end;
355	int		shift_state;
356	int		bell_pitch;
357} bios_values_t;
358
359/* other macros */
360#define ISTEXTSC(scp)	(!((scp)->status 				\
361			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
362#define ISGRAPHSC(scp)	(((scp)->status 				\
363			  & (UNKNOWN_MODE | GRAPHICS_MODE)))
364#define ISPIXELSC(scp)	(((scp)->status 				\
365			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
366			  == PIXEL_MODE)
367#define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
368
369#ifndef ISMOUSEAVAIL
370#ifdef SC_ALT_MOUSE_IMAGE
371#define ISMOUSEAVAIL(af) (1)
372#else
373#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
374#endif /* SC_ALT_MOUSE_IMAGE */
375#define ISFONTAVAIL(af)	((af) & V_ADP_FONT)
376#define ISPALAVAIL(af)	((af) & V_ADP_PALETTE)
377#endif /* ISMOUSEAVAIL */
378
379#define ISSIGVALID(sig)	((sig) > 0 && (sig) < NSIG)
380
381#define kbd_read_char(kbd, wait)					\
382		(*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait))
383#define kbd_check_char(kbd)						\
384		(*kbdsw[(kbd)->kb_index]->check_char)((kbd))
385#define kbd_enable(kbd)							\
386		(*kbdsw[(kbd)->kb_index]->enable)((kbd))
387#define kbd_disable(kbd)						\
388		(*kbdsw[(kbd)->kb_index]->disable)((kbd))
389#define kbd_lock(kbd, lockf)						\
390		(*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf))
391#define kbd_ioctl(kbd, cmd, arg)					\
392	    (((kbd) == NULL) ?						\
393		ENODEV : (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg)))
394#define kbd_clear_state(kbd)						\
395		(*kbdsw[(kbd)->kb_index]->clear_state)((kbd))
396#define kbd_get_fkeystr(kbd, fkey, len)					\
397		(*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len))
398#define kbd_poll(kbd, on)						\
399		(*kbdsw[(kbd)->kb_index]->poll)((kbd), (on))
400
401/* syscons.c */
402extern int 	(*sc_user_ioctl)(dev_t dev, u_long cmd, caddr_t data,
403				 int flag, struct proc *p);
404
405int		sc_probe_unit(int unit, int flags);
406int		sc_attach_unit(int unit, int flags);
407int		sc_resume_unit(int unit);
408
409int		set_mode(scr_stat *scp);
410scr_stat	*sc_get_scr_stat(dev_t dev);
411
412void		copy_font(scr_stat *scp, int operation, int font_size,
413			  u_char *font_image);
414void		set_border(scr_stat *scp, int color);
415
416void		sc_touch_scrn_saver(void);
417void		sc_clear_screen(scr_stat *scp);
418void		sc_set_cursor_image(scr_stat *scp);
419int		sc_clean_up(scr_stat *scp);
420void		sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
421struct tty	*scdevtotty(dev_t dev);
422#ifndef SC_NO_SYSMOUSE
423struct tty	*sc_get_mouse_tty(void);
424#endif /* SC_NO_SYSMOUSE */
425#ifndef SC_NO_CUTPASTE
426void		sc_paste(scr_stat *scp, u_char *p, int count);
427#endif /* SC_NO_CUTPASTE */
428
429/* schistory.c */
430#ifndef SC_NO_HISTORY
431int		sc_alloc_history_buffer(scr_stat *scp, int lines,
432					int prev_ysize, int wait);
433void		sc_free_history_buffer(scr_stat *scp, int prev_ysize);
434void		sc_hist_save(scr_stat *scp);
435#define		sc_hist_save_one_line(scp, from)	\
436		sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
437int		sc_hist_restore(scr_stat *scp);
438void		sc_hist_home(scr_stat *scp);
439void		sc_hist_end(scr_stat *scp);
440int		sc_hist_up_line(scr_stat *scp);
441int		sc_hist_down_line(scr_stat *scp);
442int		sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data,
443			      int flag, struct proc *p);
444#endif /* SC_NO_HISTORY */
445
446/* scmouse.c */
447#ifndef SC_NO_CUTPASTE
448void		sc_alloc_cut_buffer(scr_stat *scp, int wait);
449void		sc_draw_mouse_image(scr_stat *scp);
450void		sc_remove_mouse_image(scr_stat *scp);
451int		sc_inside_cutmark(scr_stat *scp, int pos);
452void		sc_remove_cutmarking(scr_stat *scp);
453void		sc_remove_all_cutmarkings(sc_softc_t *scp);
454void		sc_remove_all_mouse(sc_softc_t *scp);
455#else
456#define		sc_inside_cutmark(scp, pos)	FALSE
457#define		sc_remove_cutmarking(scp)
458#endif /* SC_NO_CUTPASTE */
459#ifndef SC_NO_SYSMOUSE
460void		sc_mouse_set_level(int level);
461void		sc_mouse_move(scr_stat *scp, int x, int y);
462int		sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
463			       int flag, struct proc *p);
464#endif /* SC_NO_SYSMOUSE */
465
466/* scvidctl.c */
467int		sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
468				 int xsize, int ysize, int fontsize);
469int		sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
470int		sc_set_pixel_mode(scr_stat *scp, struct tty *tp,
471				  int xsize, int ysize, int fontsize);
472sc_rndr_sw_t	*sc_render_match(scr_stat *scp, video_adapter_t *adp, int mode);
473int		sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
474			     struct proc *p);
475
476/* scvtb.c */
477void		sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,
478			    void *buffer, int wait);
479void		sc_vtb_destroy(sc_vtb_t *vtb);
480size_t		sc_vtb_size(int cols, int rows);
481void		sc_vtb_clear(sc_vtb_t *vtb, int c, int attr);
482
483int		sc_vtb_getc(sc_vtb_t *vtb, int at);
484int		sc_vtb_geta(sc_vtb_t *vtb, int at);
485void		sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a);
486vm_offset_t	sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a);
487vm_offset_t	sc_vtb_pointer(sc_vtb_t *vtb, int at);
488int		sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset);
489
490#define		sc_vtb_tail(vtb)	((vtb)->vtb_tail)
491#define		sc_vtb_rows(vtb)	((vtb)->vtb_rows)
492
493void		sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to,
494			    int count);
495void		sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2,
496			      int count);
497void		sc_vtb_seek(sc_vtb_t *vtb, int pos);
498void		sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr);
499void		sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count);
500void		sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr);
501void		sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr);
502
503/* machine dependent functions */
504int		sc_max_unit(void);
505sc_softc_t	*sc_get_softc(int unit, int flags);
506sc_softc_t	*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd);
507int		sc_get_cons_priority(int *unit, int *flags);
508void		sc_get_bios_values(bios_values_t *values);
509int		sc_tone(int herz);
510
511#endif /* !_DEV_SYSCONS_SYSCONS_H_ */
512