syscons.h revision 48189
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.48 1999/06/22 14:13:32 yokota 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	void		**devfs_token;
211
212	char        	font_loading_in_progress;
213	char        	switch_in_progress;
214	char        	videoio_in_progress;
215	char        	write_in_progress;
216	char        	blink_in_progress;
217
218	long		scrn_time_stamp;
219
220	char		cursor_base;
221	char		cursor_height;
222
223	u_char      	scr_map[256];
224	u_char      	scr_rmap[256];
225
226#ifdef _SC_MD_SOFTC_DECLARED_
227	sc_md_softc_t	md;			/* machine dependent vars */
228#endif
229
230#ifndef SC_NO_PALETTE_LOADING
231	u_char        	palette[256*3];
232#endif
233
234#ifndef SC_NO_FONT_LOADING
235	int     	fonts_loaded;
236	u_char		*font_8;
237	u_char		*font_14;
238	u_char		*font_16;
239#endif
240
241} sc_softc_t;
242
243/* virtual screen */
244typedef struct scr_stat {
245	int		index;			/* index of this vty */
246	struct sc_softc *sc;			/* pointer to softc */
247	struct sc_rndr_sw *rndr;		/* renderer */
248	sc_vtb_t	scr;
249	sc_vtb_t	vtb;
250	int 		xpos;			/* current X position */
251	int 		ypos;			/* current Y position */
252	int             saved_xpos;             /* saved X position */
253	int             saved_ypos;             /* saved Y position */
254	int 		xsize;			/* X text size */
255	int 		ysize;			/* Y text size */
256	int 		xpixel;			/* X graphics size */
257	int 		ypixel;			/* Y graphics size */
258	int		xoff;			/* X offset in pixel mode */
259	int		yoff;			/* Y offset in pixel mode */
260	u_char		*font;			/* current font */
261	int		font_size;		/* fontsize in Y direction */
262	int		start;			/* modified area start */
263	int		end;			/* modified area end */
264	term_stat 	term;			/* terminal emulation stuff */
265	int	 	status;			/* status (bitfield) */
266	int		kbd_mode;		/* keyboard I/O mode */
267	int		cursor_pos;		/* cursor buffer position */
268	int		cursor_oldpos;		/* cursor old buffer position */
269	u_short		cursor_saveunder_char;	/* saved char under cursor */
270	u_short		cursor_saveunder_attr;	/* saved attr under cursor */
271	char		cursor_base;		/* cursor base line # */
272	char		cursor_height;		/* cursor height */
273	int		mouse_pos;		/* mouse buffer position */
274	int		mouse_oldpos;		/* mouse old buffer position */
275	short		mouse_xpos;		/* mouse x coordinate */
276	short		mouse_ypos;		/* mouse y coordinate */
277	short		mouse_buttons;		/* mouse buttons */
278	int		mouse_cut_start;	/* mouse cut start pos */
279	int		mouse_cut_end;		/* mouse cut end pos */
280	struct proc 	*mouse_proc;		/* proc* of controlling proc */
281	pid_t 		mouse_pid;		/* pid of controlling proc */
282	int		mouse_signal;		/* signal # to report with */
283	u_short		bell_duration;
284	u_short		bell_pitch;
285	u_char		border;			/* border color */
286	int	 	mode;			/* mode */
287	pid_t 		pid;			/* pid of controlling proc */
288	struct proc 	*proc;			/* proc* of controlling proc */
289	struct vt_mode 	smode;			/* switch mode */
290	sc_vtb_t	*history;		/* circular history buffer */
291	int		history_pos;		/* position shown on screen */
292	int		history_size;		/* size of history buffer */
293	int		splash_save_mode;	/* saved mode for splash screen */
294	int		splash_save_status;	/* saved status for splash screen */
295#ifdef _SCR_MD_STAT_DECLARED_
296	scr_md_stat_t	md;			/* machine dependent vars */
297#endif
298} scr_stat;
299
300typedef struct default_attr {
301	int             std_color;              /* normal hardware color */
302	int             rev_color;              /* reverse hardware color */
303} default_attr;
304
305#ifndef SC_NORM_ATTR
306#define SC_NORM_ATTR		(FG_LIGHTGREY | BG_BLACK)
307#endif
308#ifndef SC_NORM_REV_ATTR
309#define SC_NORM_REV_ATTR	(FG_BLACK | BG_LIGHTGREY)
310#endif
311#ifndef SC_KERNEL_CONS_ATTR
312#define SC_KERNEL_CONS_ATTR	(FG_WHITE | BG_BLACK)
313#endif
314#ifndef SC_KERNEL_CONS_REV_ATTR
315#define SC_KERNEL_CONS_REV_ATTR	(FG_BLACK | BG_LIGHTGREY)
316#endif
317
318/* renderer function table */
319typedef void	vr_clear_t(scr_stat *scp, int c, int attr);
320typedef void	vr_draw_border_t(scr_stat *scp, int color);
321typedef void	vr_draw_t(scr_stat *scp, int from, int count, int flip);
322typedef void	vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
323typedef void	vr_draw_cursor_t(scr_stat *scp, int at, int blink,
324				 int on, int flip);
325typedef void	vr_blink_cursor_t(scr_stat *scp, int at, int flip);
326typedef void	vr_set_mouse_t(scr_stat *scp);
327typedef void	vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
328
329typedef struct sc_rndr_sw {
330	vr_clear_t		*clear;
331	vr_draw_border_t	*draw_border;
332	vr_draw_t		*draw;
333	vr_set_cursor_t		*set_cursor;
334	vr_draw_cursor_t	*draw_cursor;
335	vr_blink_cursor_t	*blink_cursor;
336	vr_set_mouse_t		*set_mouse;
337	vr_draw_mouse_t		*draw_mouse;
338} sc_rndr_sw_t;
339
340typedef struct sc_renderer {
341	char		*name;
342	int		mode;
343	sc_rndr_sw_t	*rndrsw;
344} sc_renderer_t;
345
346#define RENDERER(name, mode, sw)				\
347	static struct sc_renderer name##_##mode##_renderer = {	\
348		#name, mode, &sw				\
349	};							\
350	DATA_SET(scrndr_set, name##_##mode##_renderer)
351
352extern struct linker_set scrndr_set;
353
354typedef struct {
355	int		cursor_start;
356	int		cursor_end;
357	int		shift_state;
358	int		bell_pitch;
359} bios_values_t;
360
361/* other macros */
362#define ISTEXTSC(scp)	(!((scp)->status 				\
363			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
364#define ISGRAPHSC(scp)	(((scp)->status 				\
365			  & (UNKNOWN_MODE | GRAPHICS_MODE)))
366#define ISPIXELSC(scp)	(((scp)->status 				\
367			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
368			  == PIXEL_MODE)
369#define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
370
371#ifndef ISMOUSEAVAIL
372#ifdef SC_ALT_MOUSE_IMAGE
373#define ISMOUSEAVAIL(af) (1)
374#else
375#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
376#endif /* SC_ALT_MOUSE_IMAGE */
377#define ISFONTAVAIL(af)	((af) & V_ADP_FONT)
378#define ISPALAVAIL(af)	((af) & V_ADP_PALETTE)
379#endif /* ISMOUSEAVAIL */
380
381#define ISSIGVALID(sig)	((sig) > 0 && (sig) < NSIG)
382
383#define kbd_read_char(kbd, wait)					\
384		(*kbdsw[(kbd)->kb_index]->read_char)((kbd), (wait))
385#define kbd_check_char(kbd)						\
386		(*kbdsw[(kbd)->kb_index]->check_char)((kbd))
387#define kbd_enable(kbd)							\
388		(*kbdsw[(kbd)->kb_index]->enable)((kbd))
389#define kbd_disable(kbd)						\
390		(*kbdsw[(kbd)->kb_index]->disable)((kbd))
391#define kbd_lock(kbd, lockf)						\
392		(*kbdsw[(kbd)->kb_index]->lock)((kbd), (lockf))
393#define kbd_ioctl(kbd, cmd, arg)					\
394	    (((kbd) == NULL) ?						\
395		ENODEV : (*kbdsw[(kbd)->kb_index]->ioctl)((kbd), (cmd), (arg)))
396#define kbd_clear_state(kbd)						\
397		(*kbdsw[(kbd)->kb_index]->clear_state)((kbd))
398#define kbd_get_fkeystr(kbd, fkey, len)					\
399		(*kbdsw[(kbd)->kb_index]->get_fkeystr)((kbd), (fkey), (len))
400#define kbd_poll(kbd, on)						\
401		(*kbdsw[(kbd)->kb_index]->poll)((kbd), (on))
402
403/* syscons.c */
404extern int 	(*sc_user_ioctl)(dev_t dev, u_long cmd, caddr_t data,
405				 int flag, struct proc *p);
406
407int		sc_probe_unit(int unit, int flags);
408int		sc_attach_unit(int unit, int flags);
409int		sc_resume_unit(int unit);
410
411int		set_mode(scr_stat *scp);
412scr_stat	*sc_get_scr_stat(dev_t dev);
413
414void		copy_font(scr_stat *scp, int operation, int font_size,
415			  u_char *font_image);
416void		set_border(scr_stat *scp, int color);
417
418void		sc_touch_scrn_saver(void);
419void		sc_clear_screen(scr_stat *scp);
420void		sc_set_cursor_image(scr_stat *scp);
421int		sc_clean_up(scr_stat *scp);
422void		sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
423struct tty	*scdevtotty(dev_t dev);
424#ifndef SC_NO_SYSMOUSE
425struct tty	*sc_get_mouse_tty(void);
426#endif /* SC_NO_SYSMOUSE */
427#ifndef SC_NO_CUTPASTE
428void		sc_paste(scr_stat *scp, u_char *p, int count);
429#endif /* SC_NO_CUTPASTE */
430
431/* schistory.c */
432#ifndef SC_NO_HISTORY
433int		sc_alloc_history_buffer(scr_stat *scp, int lines, int wait);
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