2 * Copyright (c) 1992-1998 Søren Schmidt
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/dev/syscons/syscons.c,v 1.336.2.17 2004/03/25 08:41:09 ru Exp $
32 * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.32 2007/05/07 05:21:40 dillon Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/eventhandler.h>
43 #include <sys/reboot.h>
46 #include <sys/signalvar.h>
47 #include <sys/sysctl.h>
49 #include <sys/kernel.h>
51 #include <sys/random.h>
52 #include <sys/thread2.h>
54 #include <machine/clock.h>
55 #include <machine/console.h>
56 #include <machine/psl.h>
57 #include <machine/pc/display.h>
58 #include <machine/apm_bios.h>
59 #include <machine/frame.h>
61 #include <dev/misc/kbd/kbdreg.h>
62 #include <dev/video/fb/fbreg.h>
63 #include <dev/video/fb/splashreg.h>
69 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
70 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
72 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
74 MALLOC_DEFINE(M_SYSCONS
, "syscons", "Syscons");
76 typedef struct default_attr
{
77 int std_color
; /* normal hardware color */
78 int rev_color
; /* reverse hardware color */
81 static default_attr user_default
= {
86 static default_attr kernel_default
= {
88 SC_KERNEL_CONS_REV_ATTR
,
91 static int sc_console_unit
= -1;
92 static scr_stat
*sc_console
;
93 static struct tty
*sc_console_tty
;
94 static void *kernel_console_ts
;
96 static char init_done
= COLD
;
97 static char shutdown_in_progress
= FALSE
;
98 static char sc_malloc
= FALSE
;
100 static int saver_mode
= CONS_NO_SAVER
; /* LKM/user saver */
101 static int run_scrn_saver
= FALSE
; /* should run the saver? */
102 static long scrn_blank_time
= 0; /* screen saver timeout value */
104 static int scrn_blanked
; /* # of blanked screen */
105 static int sticky_splash
= FALSE
;
107 static void none_saver(sc_softc_t
*sc
, int blank
) { }
108 static void (*current_saver
)(sc_softc_t
*, int) = none_saver
;
111 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
115 d_ioctl_t
*sc_user_ioctl
;
117 static bios_values_t bios_value
;
119 static int enable_panic_key
;
120 SYSCTL_INT(_machdep
, OID_AUTO
, enable_panic_key
, CTLFLAG_RW
, &enable_panic_key
,
123 #define SC_CONSOLECTL 255
125 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
126 SC_DEV((sc), (x))->si_tty : NULL)
127 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
132 static int scvidprobe(int unit
, int flags
, int cons
);
133 static int sckbdprobe(int unit
, int flags
, int cons
);
134 static void scmeminit(void *arg
);
135 static int scdevtounit(cdev_t dev
);
136 static kbd_callback_func_t sckbdevent
;
137 static int scparam(struct tty
*tp
, struct termios
*t
);
138 static void scstart(struct tty
*tp
);
139 static void scinit(int unit
, int flags
);
140 static void scterm(int unit
, int flags
);
141 static void scshutdown(void *arg
, int howto
);
142 static u_int
scgetc(sc_softc_t
*sc
, u_int flags
);
144 #define SCGETC_NONBLOCK 2
145 static int sccngetch(int flags
);
146 static void sccnupdate(scr_stat
*scp
);
147 static scr_stat
*alloc_scp(sc_softc_t
*sc
, int vty
);
148 static void init_scp(sc_softc_t
*sc
, int vty
, scr_stat
*scp
);
149 static timeout_t scrn_timer
;
150 static int and_region(int *s1
, int *e1
, int s2
, int e2
);
151 static void scrn_update(scr_stat
*scp
, int show_cursor
);
154 static int scsplash_callback(int event
, void *arg
);
155 static void scsplash_saver(sc_softc_t
*sc
, int show
);
156 static int add_scrn_saver(void (*this_saver
)(sc_softc_t
*, int));
157 static int remove_scrn_saver(void (*this_saver
)(sc_softc_t
*, int));
158 static int set_scrn_saver_mode(scr_stat
*scp
, int mode
, u_char
*pal
, int border
);
159 static int restore_scrn_saver_mode(scr_stat
*scp
, int changemode
);
160 static void stop_scrn_saver(sc_softc_t
*sc
, void (*saver
)(sc_softc_t
*, int));
161 static int wait_scrn_saver_stop(sc_softc_t
*sc
);
162 #define scsplash_stick(stick) (sticky_splash = (stick))
164 #define scsplash_stick(stick)
167 static void do_switch_scr(sc_softc_t
*sc
);
168 static int vt_proc_alive(scr_stat
*scp
);
169 static int signal_vt_rel(scr_stat
*scp
);
170 static int signal_vt_acq(scr_stat
*scp
);
171 static int finish_vt_rel(scr_stat
*scp
, int release
);
172 static int finish_vt_acq(scr_stat
*scp
);
173 static void exchange_scr(sc_softc_t
*sc
);
174 static void update_cursor_image(scr_stat
*scp
);
175 static int save_kbd_state(scr_stat
*scp
);
176 static int update_kbd_state(scr_stat
*scp
, int state
, int mask
);
177 static int update_kbd_leds(scr_stat
*scp
, int which
);
178 static timeout_t blink_screen
;
180 #define CDEV_MAJOR 12
182 static cn_probe_t sccnprobe
;
183 static cn_init_t sccninit
;
184 static cn_init_t sccninit_fini
;
185 static cn_getc_t sccngetc
;
186 static cn_checkc_t sccncheckc
;
187 static cn_putc_t sccnputc
;
188 static cn_dbctl_t sccndbctl
;
189 static cn_term_t sccnterm
;
191 CONS_DRIVER(sc
, sccnprobe
, sccninit
, sccninit_fini
, sccnterm
,
192 sccngetc
, sccncheckc
, sccnputc
, sccndbctl
);
194 static d_open_t scopen
;
195 static d_close_t scclose
;
196 static d_read_t scread
;
197 static d_ioctl_t scioctl
;
198 static d_mmap_t scmmap
;
200 static struct dev_ops sc_ops
= {
201 { "sc", CDEV_MAJOR
, D_TTY
| D_KQFILTER
},
209 .d_kqfilter
= ttykqfilter
213 sc_probe_unit(int unit
, int flags
)
215 if (!scvidprobe(unit
, flags
, FALSE
)) {
217 kprintf("sc%d: no video adapter found.\n", unit
);
221 /* syscons will be attached even when there is no keyboard */
222 sckbdprobe(unit
, flags
, FALSE
);
227 /* probe video adapters, return TRUE if found */
229 scvidprobe(int unit
, int flags
, int cons
)
232 * Access the video adapter driver through the back door!
233 * Video adapter drivers need to be configured before syscons.
234 * However, when syscons is being probed as the low-level console,
235 * they have not been initialized yet. We force them to initialize
236 * themselves here. XXX
238 vid_configure(cons
? VIO_PROBE_ONLY
: 0);
240 return (vid_find_adapter("*", unit
) >= 0);
243 /* probe the keyboard, return TRUE if found */
245 sckbdprobe(int unit
, int flags
, int cons
)
247 /* access the keyboard driver through the backdoor! */
248 kbd_configure(cons
? KB_CONF_PROBE_ONLY
: 0);
250 return (kbd_find_keyboard("*", unit
) >= 0);
254 adapter_name(video_adapter_t
*adp
)
260 { KD_MONO
, { "MDA", "MDA" } },
261 { KD_HERCULES
, { "Hercules", "Hercules" } },
262 { KD_CGA
, { "CGA", "CGA" } },
263 { KD_EGA
, { "EGA", "EGA (mono)" } },
264 { KD_VGA
, { "VGA", "VGA (mono)" } },
265 { KD_TGA
, { "TGA", "TGA" } },
266 { -1, { "Unknown", "Unknown" } },
270 for (i
= 0; names
[i
].type
!= -1; ++i
)
271 if (names
[i
].type
== adp
->va_type
)
273 return names
[i
].name
[(adp
->va_flags
& V_ADP_COLOR
) ? 0 : 1];
277 sc_attach_unit(int unit
, int flags
)
287 flags
&= ~SC_KERNEL_CONSOLE
;
289 if (sc_console_unit
== unit
) {
291 * If this unit is being used as the system console, we need to
292 * adjust some variables and buffers before and after scinit().
294 /* assert(sc_console != NULL) */
295 flags
|= SC_KERNEL_CONSOLE
;
300 if (sc_console
->tsw
->te_size
> 0) {
301 /* assert(sc_console->ts != NULL); */
302 kernel_console_ts
= sc_console
->ts
;
303 sc_console
->ts
= kmalloc(sc_console
->tsw
->te_size
,
304 M_SYSCONS
, M_WAITOK
);
305 bcopy(kernel_console_ts
, sc_console
->ts
, sc_console
->tsw
->te_size
);
306 (*sc_console
->tsw
->te_default_attr
)(sc_console
,
307 user_default
.std_color
,
308 user_default
.rev_color
);
314 sc
= sc_get_softc(unit
, flags
& SC_KERNEL_CONSOLE
);
317 * If this is the console we couldn't setup sc->dev before because
318 * malloc wasn't working. Set it up now.
320 if (flags
& SC_KERNEL_CONSOLE
) {
321 KKASSERT(sc
->dev
== NULL
);
322 sc
->dev
= kmalloc(sizeof(cdev_t
)*sc
->vtys
, M_SYSCONS
, M_WAITOK
|M_ZERO
);
323 sc
->dev
[0] = make_dev(&sc_ops
, sc_console_unit
*MAXCONS
, UID_ROOT
,
325 "ttyv%r", sc_console_unit
*MAXCONS
);
326 sc
->dev
[0]->si_tty
= ttymalloc(sc
->dev
[0]->si_tty
);
327 sc
->dev
[0]->si_drv1
= sc_console
;
331 * Finish up the standard attach
334 callout_init(&sc
->scrn_timer_ch
);
335 scp
= SC_STAT(sc
->dev
[0]);
336 if (sc_console
== NULL
) /* sc_console_unit < 0 */
340 if ((sc
->config
& SC_VESA800X600
)
341 && ((*vidsw
[sc
->adapter
]->get_info
)(sc
->adp
, M_VESA_800x600
, &info
) == 0)) {
343 if (sc
->flags
& SC_SPLASH_SCRN
)
344 splash_term(sc
->adp
);
346 sc_set_graphics_mode(scp
, NULL
, M_VESA_800x600
);
347 sc_set_pixel_mode(scp
, NULL
, COL
, ROW
, 16);
348 sc
->initial_mode
= M_VESA_800x600
;
350 /* put up the splash again! */
351 if (sc
->flags
& SC_SPLASH_SCRN
)
352 splash_init(sc
->adp
, scsplash_callback
, sc
);
355 #endif /* SC_PIXEL_MODE */
357 /* initialize cursor */
359 update_cursor_image(scp
);
361 /* get screen update going */
364 /* set up the keyboard */
365 kbd_ioctl(sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
366 update_kbd_state(scp
, scp
->status
, LOCK_MASK
);
368 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
369 unit
, adapter_name(sc
->adp
), sc
->vtys
, sc
->config
);
371 kprintf("sc%d:", unit
);
372 if (sc
->adapter
>= 0)
373 kprintf(" fb%d", sc
->adapter
);
374 if (sc
->keyboard
>= 0)
375 kprintf(", kbd%d", sc
->keyboard
);
377 kprintf(", terminal emulator: %s (%s)",
378 scp
->tsw
->te_name
, scp
->tsw
->te_desc
);
382 /* register a shutdown callback for the kernel console */
383 if (sc_console_unit
== unit
)
384 EVENTHANDLER_REGISTER(shutdown_pre_sync
, scshutdown
,
385 (void *)(uintptr_t)unit
, SHUTDOWN_PRI_DEFAULT
);
388 * create devices. dev_ops_add() must be called to make devices under
389 * this major number available to userland.
391 dev_ops_add(&sc_ops
, ~(MAXCONS
- 1), unit
* MAXCONS
);
393 for (vc
= 0; vc
< sc
->vtys
; vc
++) {
394 dev
= make_dev(&sc_ops
, vc
+ unit
* MAXCONS
,
395 UID_ROOT
, GID_WHEEL
, 0600, "ttyv%r", vc
+ unit
* MAXCONS
);
398 * The first vty already has struct tty and scr_stat initialized
399 * in scinit(). The other vtys will have these structs when
404 dev_ops_add(&sc_ops
, -1, SC_CONSOLECTL
); /* XXX */
405 dev
= make_dev(&sc_ops
, SC_CONSOLECTL
,
406 UID_ROOT
, GID_WHEEL
, 0600, "consolectl");
407 dev
->si_tty
= sc_console_tty
= ttymalloc(sc_console_tty
);
408 dev
->si_drv1
= sc_console
;
421 * As soon as malloc() becomes functional, we had better allocate
422 * various buffers for the kernel console.
425 if (sc_console_unit
< 0) /* sc_console == NULL */
428 /* copy the temporary buffer to the final buffer */
429 sc_alloc_scr_buffer(sc_console
, TRUE
, FALSE
);
431 #ifndef SC_NO_CUTPASTE
432 sc_alloc_cut_buffer(sc_console
, TRUE
);
435 #ifndef SC_NO_HISTORY
436 /* initialize history buffer & pointers */
437 sc_alloc_history_buffer(sc_console
, 0, 0, TRUE
);
441 SYSINIT(sc_mem
, SI_BOOT1_POST
, SI_ORDER_ANY
, scmeminit
, NULL
);
444 scdevtounit(cdev_t dev
)
446 int vty
= SC_VTY(dev
);
448 if (vty
== SC_CONSOLECTL
)
449 return ((sc_console
!= NULL
) ? sc_console
->sc
->unit
: -1);
450 else if ((vty
< 0) || (vty
>= MAXCONS
*sc_max_unit()))
457 scopen(struct dev_open_args
*ap
)
459 cdev_t dev
= ap
->a_head
.a_dev
;
460 int unit
= scdevtounit(dev
);
467 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
468 major(dev
), minor(dev
), unit
, SC_VTY(dev
)));
470 sc
= sc_get_softc(unit
, (sc_console_unit
== unit
) ? SC_KERNEL_CONSOLE
: 0);
474 tp
= dev
->si_tty
= ttymalloc(dev
->si_tty
);
475 tp
->t_oproc
= scstart
;
476 tp
->t_param
= scparam
;
477 tp
->t_stop
= nottystop
;
479 if (!ISTTYOPEN(tp
)) {
481 /* Use the current setting of the <-- key as default VERASE. */
482 /* If the Delete key is preferable, an stty is necessary */
483 if (sc
->kbd
!= NULL
) {
484 key
.keynum
= KEYCODE_BS
;
485 kbd_ioctl(sc
->kbd
, GIO_KEYMAPENT
, (caddr_t
)&key
);
486 tp
->t_cc
[VERASE
] = key
.key
.map
[0];
488 tp
->t_iflag
= TTYDEF_IFLAG
;
489 tp
->t_oflag
= TTYDEF_OFLAG
;
490 tp
->t_cflag
= TTYDEF_CFLAG
;
491 tp
->t_lflag
= TTYDEF_LFLAG
;
492 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
493 scparam(tp
, &tp
->t_termios
);
494 (*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
497 if (tp
->t_state
& TS_XCLUDE
&& suser_cred(ap
->a_cred
, 0))
500 error
= (*linesw
[tp
->t_line
].l_open
)(dev
, tp
);
504 scp
= dev
->si_drv1
= alloc_scp(sc
, SC_VTY(dev
));
506 sc_set_pixel_mode(scp
, NULL
, COL
, ROW
, 16);
508 if (!tp
->t_winsize
.ws_col
&& !tp
->t_winsize
.ws_row
) {
509 tp
->t_winsize
.ws_col
= scp
->xsize
;
510 tp
->t_winsize
.ws_row
= scp
->ysize
;
517 scclose(struct dev_close_args
*ap
)
519 cdev_t dev
= ap
->a_head
.a_dev
;
520 struct tty
*tp
= dev
->si_tty
;
524 if (SC_VTY(dev
) != SC_CONSOLECTL
) {
525 scp
= SC_STAT(tp
->t_dev
);
526 /* were we in the middle of the VT switching process? */
527 DPRINTF(5, ("sc%d: scclose(), ", scp
->sc
->unit
));
528 if ((scp
== scp
->sc
->cur_scp
) && (scp
->sc
->unit
== sc_console_unit
))
529 cons_unavail
= FALSE
;
531 * note: must be called from a critical section because finish_vt_rel
532 * will call do_switch_scr which releases it temporarily
534 if (finish_vt_rel(scp
, TRUE
) == 0) /* force release */
535 DPRINTF(5, ("reset WAIT_REL, "));
536 if (finish_vt_acq(scp
) == 0) /* force acknowledge */
537 DPRINTF(5, ("reset WAIT_ACQ, "));
539 if (scp
== &main_console
) {
542 scp
->smode
.mode
= VT_AUTO
;
545 sc_vtb_destroy(&scp
->vtb
);
546 sc_vtb_destroy(&scp
->scr
);
547 sc_free_history_buffer(scp
, scp
->ysize
);
549 kfree(scp
, M_SYSCONS
);
554 scp
->smode
.mode
= VT_AUTO
;
556 scp
->kbd_mode
= K_XLATE
;
557 if (scp
== scp
->sc
->cur_scp
)
558 kbd_ioctl(scp
->sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
559 DPRINTF(5, ("done.\n"));
561 (*linesw
[tp
->t_line
].l_close
)(tp
, ap
->a_fflag
);
568 scread(struct dev_read_args
*ap
)
570 sc_touch_scrn_saver();
571 return (ttyread(ap
));
575 sckbdevent(keyboard_t
*thiskbd
, int event
, void *arg
)
583 sc
= (sc_softc_t
*)arg
;
584 /* assert(thiskbd == sc->kbd) */
589 case KBDIO_UNLOADING
:
592 kbd_release(thiskbd
, (void *)&sc
->keyboard
);
599 * Loop while there is still input to get from the keyboard.
600 * I don't think this is nessesary, and it doesn't fix
601 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
603 while ((c
= scgetc(sc
, SCGETC_NONBLOCK
)) != NOKEY
) {
605 cur_tty
= VIRTUAL_TTY(sc
, sc
->cur_scp
->index
);
606 if (!ISTTYOPEN(cur_tty
)) {
607 cur_tty
= sc_console_tty
;
608 if (!ISTTYOPEN(cur_tty
))
612 if ((*sc
->cur_scp
->tsw
->te_input
)(sc
->cur_scp
, c
, cur_tty
))
615 switch (KEYFLAGS(c
)) {
616 case 0x0000: /* normal key */
617 (*linesw
[cur_tty
->t_line
].l_rint
)(KEYCHAR(c
), cur_tty
);
619 case FKEY
: /* function key, return string */
620 cp
= kbd_get_fkeystr(thiskbd
, KEYCHAR(c
), &len
);
623 (*linesw
[cur_tty
->t_line
].l_rint
)(*cp
++, cur_tty
);
626 case MKEY
: /* meta is active, prepend ESC */
627 (*linesw
[cur_tty
->t_line
].l_rint
)(0x1b, cur_tty
);
628 (*linesw
[cur_tty
->t_line
].l_rint
)(KEYCHAR(c
), cur_tty
);
630 case BKEY
: /* backtab fixed sequence (esc [ Z) */
631 (*linesw
[cur_tty
->t_line
].l_rint
)(0x1b, cur_tty
);
632 (*linesw
[cur_tty
->t_line
].l_rint
)('[', cur_tty
);
633 (*linesw
[cur_tty
->t_line
].l_rint
)('Z', cur_tty
);
638 sc
->cur_scp
->status
|= MOUSE_HIDDEN
;
644 scparam(struct tty
*tp
, struct termios
*t
)
646 tp
->t_ispeed
= t
->c_ispeed
;
647 tp
->t_ospeed
= t
->c_ospeed
;
648 tp
->t_cflag
= t
->c_cflag
;
653 scioctl(struct dev_ioctl_args
*ap
)
655 cdev_t dev
= ap
->a_head
.a_dev
;
656 u_long cmd
= ap
->a_cmd
;
657 caddr_t data
= ap
->a_data
;
658 int flag
= ap
->a_fflag
;
667 /* If there is a user_ioctl function call that first */
669 error
= (*sc_user_ioctl
)(ap
);
670 if (error
!= ENOIOCTL
)
674 error
= sc_vid_ioctl(tp
, cmd
, data
, flag
);
675 if (error
!= ENOIOCTL
)
678 #ifndef SC_NO_HISTORY
679 error
= sc_hist_ioctl(tp
, cmd
, data
, flag
);
680 if (error
!= ENOIOCTL
)
684 #ifndef SC_NO_SYSMOUSE
685 error
= sc_mouse_ioctl(tp
, cmd
, data
, flag
);
686 if (error
!= ENOIOCTL
)
690 scp
= SC_STAT(tp
->t_dev
);
691 /* assert(scp != NULL) */
692 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
696 error
= (*scp
->tsw
->te_ioctl
)(scp
, tp
, cmd
, data
, flag
);
697 if (error
!= ENOIOCTL
)
701 switch (cmd
) { /* process console hardware related ioctl's */
703 case GIO_ATTR
: /* get current attributes */
704 /* this ioctl is not processed here, but in the terminal emulator */
707 case GIO_COLOR
: /* is this a color console ? */
708 *(int *)data
= (sc
->adp
->va_flags
& V_ADP_COLOR
) ? 1 : 0;
711 case CONS_BLANKTIME
: /* set screen saver timeout (0 = no saver) */
712 if (*(int *)data
< 0 || *(int *)data
> MAX_BLANKTIME
)
715 scrn_blank_time
= *(int *)data
;
716 run_scrn_saver
= (scrn_blank_time
!= 0);
720 case CONS_CURSORTYPE
: /* set cursor type blink/noblink */
722 if (!ISGRAPHSC(sc
->cur_scp
))
723 sc_remove_cursor_image(sc
->cur_scp
);
724 if ((*(int*)data
) & 0x01)
725 sc
->flags
|= SC_BLINK_CURSOR
;
727 sc
->flags
&= ~SC_BLINK_CURSOR
;
728 if ((*(int*)data
) & 0x02) {
729 sc
->flags
|= SC_CHAR_CURSOR
;
731 sc
->flags
&= ~SC_CHAR_CURSOR
;
733 * The cursor shape is global property; all virtual consoles
734 * are affected. Update the cursor in the current console...
736 if (!ISGRAPHSC(sc
->cur_scp
)) {
737 sc_set_cursor_image(sc
->cur_scp
);
738 sc_draw_cursor_image(sc
->cur_scp
);
743 case CONS_BELLTYPE
: /* set bell type sound/visual */
744 if ((*(int *)data
) & 0x01)
745 sc
->flags
|= SC_VISUAL_BELL
;
747 sc
->flags
&= ~SC_VISUAL_BELL
;
748 if ((*(int *)data
) & 0x02)
749 sc
->flags
|= SC_QUIET_BELL
;
751 sc
->flags
&= ~SC_QUIET_BELL
;
754 case CONS_GETINFO
: /* get current (virtual) console info */
756 vid_info_t
*ptr
= (vid_info_t
*)data
;
757 if (ptr
->size
== sizeof(struct vid_info
)) {
758 ptr
->m_num
= sc
->cur_scp
->index
;
759 ptr
->font_size
= scp
->font_size
;
760 ptr
->mv_col
= scp
->xpos
;
761 ptr
->mv_row
= scp
->ypos
;
762 ptr
->mv_csz
= scp
->xsize
;
763 ptr
->mv_rsz
= scp
->ysize
;
765 * The following fields are filled by the terminal emulator. XXX
772 ptr
->mv_grfc
.fore
= 0; /* not supported */
773 ptr
->mv_grfc
.back
= 0; /* not supported */
774 ptr
->mv_ovscan
= scp
->border
;
775 if (scp
== sc
->cur_scp
)
777 ptr
->mk_keylock
= scp
->status
& LOCK_MASK
;
783 case CONS_GETVERS
: /* get version number */
784 *(int*)data
= 0x200; /* version 2.0 */
787 case CONS_IDLE
: /* see if the screen has been idle */
789 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
790 * the user process may have been writing something on the
791 * screen and syscons is not aware of it. Declare the screen
792 * is NOT idle if it is in one of these modes. But there is
793 * an exception to it; if a screen saver is running in the
794 * graphics mode in the current screen, we should say that the
795 * screen has been idle.
797 *(int *)data
= (sc
->flags
& SC_SCRN_IDLE
)
798 && (!ISGRAPHSC(sc
->cur_scp
)
799 || (sc
->cur_scp
->status
& SAVER_RUNNING
));
802 case CONS_SAVERMODE
: /* set saver mode */
803 switch(*(int *)data
) {
806 /* if a LKM screen saver is running, stop it first. */
807 scsplash_stick(FALSE
);
808 saver_mode
= *(int *)data
;
811 if ((error
= wait_scrn_saver_stop(NULL
))) {
816 run_scrn_saver
= TRUE
;
817 if (saver_mode
== CONS_USR_SAVER
)
818 scp
->status
|= SAVER_RUNNING
;
820 scp
->status
&= ~SAVER_RUNNING
;
821 scsplash_stick(TRUE
);
826 if ((saver_mode
== CONS_USR_SAVER
) && (scp
->status
& SAVER_RUNNING
))
827 scp
->status
&= ~SAVER_RUNNING
;
828 saver_mode
= *(int *)data
;
836 case CONS_SAVERSTART
: /* immediately start/stop the screen saver */
838 * Note that this ioctl does not guarantee the screen saver
839 * actually starts or stops. It merely attempts to do so...
842 run_scrn_saver
= (*(int *)data
!= 0);
844 sc
->scrn_time_stamp
-= scrn_blank_time
;
848 case CONS_SCRSHOT
: /* get a screen shot */
850 scrshot_t
*ptr
= (scrshot_t
*)data
;
852 if (ISGRAPHSC(scp
)) {
856 if (scp
->xsize
!= ptr
->xsize
|| scp
->ysize
!= ptr
->ysize
) {
860 copyout ((void*)scp
->vtb
.vtb_buffer
, ptr
->buf
,
861 ptr
->xsize
* ptr
->ysize
* sizeof(uint16_t));
866 case VT_SETMODE
: /* set screen switcher mode */
868 struct vt_mode
*mode
;
870 mode
= (struct vt_mode
*)data
;
871 DPRINTF(5, ("sc%d: VT_SETMODE ", sc
->unit
));
872 if (scp
->smode
.mode
== VT_PROCESS
) {
873 if (scp
->proc
== pfind(scp
->pid
) && scp
->proc
!= curproc
) {
874 DPRINTF(5, ("error EPERM\n"));
879 if (mode
->mode
== VT_AUTO
) {
880 scp
->smode
.mode
= VT_AUTO
;
883 DPRINTF(5, ("VT_AUTO, "));
884 if ((scp
== sc
->cur_scp
) && (sc
->unit
== sc_console_unit
))
885 cons_unavail
= FALSE
;
887 * note: must be called from a critical section because
888 * finish_vt_rel will call do_switch_scr which releases it
891 if (finish_vt_rel(scp
, TRUE
) == 0)
892 DPRINTF(5, ("reset WAIT_REL, "));
893 if (finish_vt_acq(scp
) == 0)
894 DPRINTF(5, ("reset WAIT_ACQ, "));
896 if (!ISSIGVALID(mode
->relsig
) || !ISSIGVALID(mode
->acqsig
)
897 || !ISSIGVALID(mode
->frsig
)) {
899 DPRINTF(5, ("error EINVAL\n"));
902 DPRINTF(5, ("VT_PROCESS %d, ", curproc
->p_pid
));
903 bcopy(data
, &scp
->smode
, sizeof(struct vt_mode
));
905 scp
->pid
= scp
->proc
->p_pid
;
906 if ((scp
== sc
->cur_scp
) && (sc
->unit
== sc_console_unit
))
914 case VT_GETMODE
: /* get screen switcher mode */
915 bcopy(&scp
->smode
, data
, sizeof(struct vt_mode
));
918 case VT_RELDISP
: /* screen switcher ioctl */
921 * This must be the current vty which is in the VT_PROCESS
924 if ((scp
!= sc
->cur_scp
) || (scp
->smode
.mode
!= VT_PROCESS
)) {
928 /* ...and this process is controlling it. */
929 if (scp
->proc
!= curproc
) {
934 switch(*(int *)data
) {
935 case VT_FALSE
: /* user refuses to release screen, abort */
937 * note: must be called from a critical section because
938 * finish_vt_rel will call do_switch_scr which releases it
941 if ((error
= finish_vt_rel(scp
, FALSE
)) == 0)
942 DPRINTF(5, ("sc%d: VT_FALSE\n", sc
->unit
));
944 case VT_TRUE
: /* user has released screen, go on */
946 * note: must be called from a critical section because
947 * finish_vt_rel will call do_switch_scr which releases it
950 if ((error
= finish_vt_rel(scp
, TRUE
)) == 0)
951 DPRINTF(5, ("sc%d: VT_TRUE\n", sc
->unit
));
953 case VT_ACKACQ
: /* acquire acknowledged, switch completed */
954 if ((error
= finish_vt_acq(scp
)) == 0)
955 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc
->unit
));
963 case VT_OPENQRY
: /* return free virtual console */
964 for (i
= sc
->first_vty
; i
< sc
->first_vty
+ sc
->vtys
; i
++) {
965 tp
= VIRTUAL_TTY(sc
, i
);
966 if (!ISTTYOPEN(tp
)) {
967 *(int *)data
= i
+ 1;
973 case VT_ACTIVATE
: /* switch to screen *data */
974 i
= (*(int *)data
== 0) ? scp
->index
: (*(int *)data
- 1);
976 sc_clean_up(sc
->cur_scp
);
978 return sc_switch_scr(sc
, i
);
980 case VT_WAITACTIVE
: /* wait for switch to occur */
981 i
= (*(int *)data
== 0) ? scp
->index
: (*(int *)data
- 1);
982 if ((i
< sc
->first_vty
) || (i
>= sc
->first_vty
+ sc
->vtys
))
985 error
= sc_clean_up(sc
->cur_scp
);
989 scp
= SC_STAT(SC_DEV(sc
, i
));
990 if (scp
== scp
->sc
->cur_scp
)
992 while ((error
=tsleep((caddr_t
)&scp
->smode
, PCATCH
,
993 "waitvt", 0)) == ERESTART
) ;
996 case VT_GETACTIVE
: /* get active vty # */
997 *(int *)data
= sc
->cur_scp
->index
+ 1;
1000 case VT_GETINDEX
: /* get this vty # */
1001 *(int *)data
= scp
->index
+ 1;
1004 case VT_LOCKSWITCH
: /* prevent vty switching */
1005 if ((*(int *)data
) & 0x01)
1006 sc
->flags
|= SC_SCRN_VTYLOCK
;
1008 sc
->flags
&= ~SC_SCRN_VTYLOCK
;
1011 case KDENABIO
: /* allow io operations */
1012 error
= suser_cred(ap
->a_cred
, 0);
1015 if (securelevel
> 0)
1017 curthread
->td_lwp
->lwp_md
.md_regs
->tf_eflags
|= PSL_IOPL
;
1020 case KDDISABIO
: /* disallow io operations (default) */
1021 curthread
->td_lwp
->lwp_md
.md_regs
->tf_eflags
&= ~PSL_IOPL
;
1024 case KDSKBSTATE
: /* set keyboard state (locks) */
1025 if (*(int *)data
& ~LOCK_MASK
)
1027 scp
->status
&= ~LOCK_MASK
;
1028 scp
->status
|= *(int *)data
;
1029 if (scp
== sc
->cur_scp
)
1030 update_kbd_state(scp
, scp
->status
, LOCK_MASK
);
1033 case KDGKBSTATE
: /* get keyboard state (locks) */
1034 if (scp
== sc
->cur_scp
)
1035 save_kbd_state(scp
);
1036 *(int *)data
= scp
->status
& LOCK_MASK
;
1039 case KDGETREPEAT
: /* get keyboard repeat & delay rates */
1040 case KDSETREPEAT
: /* set keyboard repeat & delay rates (new) */
1041 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1042 if (error
== ENOIOCTL
)
1046 case KDSETRAD
: /* set keyboard repeat & delay rates (old) */
1047 if (*(int *)data
& ~0x7f)
1049 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1050 if (error
== ENOIOCTL
)
1054 case KDSKBMODE
: /* set keyboard mode */
1055 switch (*(int *)data
) {
1056 case K_XLATE
: /* switch to XLT ascii mode */
1057 case K_RAW
: /* switch to RAW scancode mode */
1058 case K_CODE
: /* switch to CODE mode */
1059 scp
->kbd_mode
= *(int *)data
;
1060 if (scp
== sc
->cur_scp
)
1061 kbd_ioctl(sc
->kbd
, cmd
, data
);
1068 case KDGKBMODE
: /* get keyboard mode */
1069 *(int *)data
= scp
->kbd_mode
;
1073 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1074 if (error
== ENOIOCTL
)
1078 case KDMKTONE
: /* sound the bell */
1080 sc_bell(scp
, (*(int*)data
)&0xffff,
1081 (((*(int*)data
)>>16)&0xffff)*hz
/1000);
1083 sc_bell(scp
, scp
->bell_pitch
, scp
->bell_duration
);
1086 case KIOCSOUND
: /* make tone (*data) hz */
1087 if (scp
== sc
->cur_scp
) {
1089 return sc_tone(*(int *)data
);
1095 case KDGKBTYPE
: /* get keyboard type */
1096 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1097 if (error
== ENOIOCTL
) {
1098 /* always return something? XXX */
1103 case KDSETLED
: /* set keyboard LED status */
1104 if (*(int *)data
& ~LED_MASK
) /* FIXME: LOCK_MASK? */
1106 scp
->status
&= ~LED_MASK
;
1107 scp
->status
|= *(int *)data
;
1108 if (scp
== sc
->cur_scp
)
1109 update_kbd_leds(scp
, scp
->status
);
1112 case KDGETLED
: /* get keyboard LED status */
1113 if (scp
== sc
->cur_scp
)
1114 save_kbd_state(scp
);
1115 *(int *)data
= scp
->status
& LED_MASK
;
1118 case CONS_SETKBD
: /* set the new keyboard */
1123 newkbd
= kbd_get_keyboard(*(int *)data
);
1124 if (newkbd
== NULL
) {
1129 if (sc
->kbd
!= newkbd
) {
1130 i
= kbd_allocate(newkbd
->kb_name
, newkbd
->kb_unit
,
1131 (void *)&sc
->keyboard
, sckbdevent
, sc
);
1132 /* i == newkbd->kb_index */
1134 if (sc
->kbd
!= NULL
) {
1135 save_kbd_state(sc
->cur_scp
);
1136 kbd_release(sc
->kbd
, (void *)&sc
->keyboard
);
1138 sc
->kbd
= kbd_get_keyboard(i
); /* sc->kbd == newkbd */
1140 kbd_ioctl(sc
->kbd
, KDSKBMODE
,
1141 (caddr_t
)&sc
->cur_scp
->kbd_mode
);
1142 update_kbd_state(sc
->cur_scp
, sc
->cur_scp
->status
,
1145 error
= EPERM
; /* XXX */
1152 case CONS_RELKBD
: /* release the current keyboard */
1155 if (sc
->kbd
!= NULL
) {
1156 save_kbd_state(sc
->cur_scp
);
1157 error
= kbd_release(sc
->kbd
, (void *)&sc
->keyboard
);
1166 case CONS_GETTERM
: /* get the current terminal emulator info */
1170 if (((term_info_t
*)data
)->ti_index
== 0) {
1173 sw
= sc_term_match_by_number(((term_info_t
*)data
)->ti_index
);
1176 strncpy(((term_info_t
*)data
)->ti_name
, sw
->te_name
,
1177 sizeof(((term_info_t
*)data
)->ti_name
));
1178 strncpy(((term_info_t
*)data
)->ti_desc
, sw
->te_desc
,
1179 sizeof(((term_info_t
*)data
)->ti_desc
));
1180 ((term_info_t
*)data
)->ti_flags
= 0;
1183 ((term_info_t
*)data
)->ti_name
[0] = '\0';
1184 ((term_info_t
*)data
)->ti_desc
[0] = '\0';
1185 ((term_info_t
*)data
)->ti_flags
= 0;
1190 case CONS_SETTERM
: /* set the current terminal emulator */
1192 error
= sc_init_emulator(scp
, ((term_info_t
*)data
)->ti_name
);
1193 /* FIXME: what if scp == sc_console! XXX */
1197 case GIO_SCRNMAP
: /* get output translation table */
1198 bcopy(&sc
->scr_map
, data
, sizeof(sc
->scr_map
));
1201 case PIO_SCRNMAP
: /* set output translation table */
1202 bcopy(data
, &sc
->scr_map
, sizeof(sc
->scr_map
));
1203 for (i
=0; i
<sizeof(sc
->scr_map
); i
++) {
1204 sc
->scr_rmap
[sc
->scr_map
[i
]] = i
;
1208 case GIO_KEYMAP
: /* get keyboard translation table */
1209 case PIO_KEYMAP
: /* set keyboard translation table */
1210 case GIO_DEADKEYMAP
: /* get accent key translation table */
1211 case PIO_DEADKEYMAP
: /* set accent key translation table */
1212 case GETFKEY
: /* get function key string */
1213 case SETFKEY
: /* set function key string */
1214 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1215 if (error
== ENOIOCTL
)
1219 #ifndef SC_NO_FONT_LOADING
1221 case PIO_FONT8x8
: /* set 8x8 dot font */
1222 if (!ISFONTAVAIL(sc
->adp
->va_flags
))
1224 bcopy(data
, sc
->font_8
, 8*256);
1225 sc
->fonts_loaded
|= FONT_8
;
1228 * Always use the font page #0. XXX
1229 * Don't load if the current font size is not 8x8.
1231 if (ISTEXTSC(sc
->cur_scp
) && (sc
->cur_scp
->font_size
< 14))
1232 sc_load_font(sc
->cur_scp
, 0, 8, sc
->font_8
, 0, 256);
1235 case GIO_FONT8x8
: /* get 8x8 dot font */
1236 if (!ISFONTAVAIL(sc
->adp
->va_flags
))
1238 if (sc
->fonts_loaded
& FONT_8
) {
1239 bcopy(sc
->font_8
, data
, 8*256);
1245 case PIO_FONT8x14
: /* set 8x14 dot font */
1246 if (!ISFONTAVAIL(sc
->adp
->va_flags
))
1248 bcopy(data
, sc
->font_14
, 14*256);
1249 sc
->fonts_loaded
|= FONT_14
;
1252 * Always use the font page #0. XXX
1253 * Don't load if the current font size is not 8x14.
1255 if (ISTEXTSC(sc
->cur_scp
)
1256 && (sc
->cur_scp
->font_size
>= 14)
1257 && (sc
->cur_scp
->font_size
< 16))
1258 sc_load_font(sc
->cur_scp
, 0, 14, sc
->font_14
, 0, 256);
1261 case GIO_FONT8x14
: /* get 8x14 dot font */
1262 if (!ISFONTAVAIL(sc
->adp
->va_flags
))
1264 if (sc
->fonts_loaded
& FONT_14
) {
1265 bcopy(sc
->font_14
, data
, 14*256);
1271 case PIO_FONT8x16
: /* set 8x16 dot font */
1272 if (!ISFONTAVAIL(sc
->adp
->va_flags
))
1274 bcopy(data
, sc
->font_16
, 16*256);
1275 sc
->fonts_loaded
|= FONT_16
;
1278 * Always use the font page #0. XXX
1279 * Don't load if the current font size is not 8x16.
1281 if (ISTEXTSC(sc
->cur_scp
) && (sc
->cur_scp
->font_size
>= 16))
1282 sc_load_font(sc
->cur_scp
, 0, 16, sc
->font_16
, 0, 256);
1285 case GIO_FONT8x16
: /* get 8x16 dot font */
1286 if (!ISFONTAVAIL(sc
->adp
->va_flags
))
1288 if (sc
->fonts_loaded
& FONT_16
) {
1289 bcopy(sc
->font_16
, data
, 16*256);
1295 #endif /* SC_NO_FONT_LOADING */
1301 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, ap
->a_cred
);
1302 if (error
!= ENOIOCTL
)
1304 error
= ttioctl(tp
, cmd
, data
, flag
);
1305 if (error
!= ENOIOCTL
)
1311 scstart(struct tty
*tp
)
1315 u_char buf
[PCBURST
];
1316 scr_stat
*scp
= SC_STAT(tp
->t_dev
);
1318 if (scp
->status
& SLKED
||
1319 (scp
== scp
->sc
->cur_scp
&& scp
->sc
->blink_in_progress
))
1322 if (!(tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))) {
1323 tp
->t_state
|= TS_BUSY
;
1326 len
= q_to_b(rbp
, buf
, PCBURST
);
1328 sc_puts(scp
, buf
, len
);
1331 tp
->t_state
&= ~TS_BUSY
;
1338 sccnprobe(struct consdev
*cp
)
1343 cp
->cn_pri
= sc_get_cons_priority(&unit
, &flags
);
1345 /* a video card is always required */
1346 if (!scvidprobe(unit
, flags
, TRUE
))
1347 cp
->cn_pri
= CN_DEAD
;
1349 /* syscons will become console even when there is no keyboard */
1350 sckbdprobe(unit
, flags
, TRUE
);
1352 if (cp
->cn_pri
== CN_DEAD
)
1355 /* initialize required fields */
1356 cp
->cn_probegood
= 1;
1360 sccninit(struct consdev
*cp
)
1365 sc_get_cons_priority(&unit
, &flags
);
1366 scinit(unit
, flags
| SC_KERNEL_CONSOLE
);
1367 sc_console_unit
= unit
;
1368 sc_console
= sc_get_softc(unit
, SC_KERNEL_CONSOLE
)->console_scp
;
1372 sccninit_fini(struct consdev
*cp
)
1374 cp
->cn_dev
= make_dev(&sc_ops
, SC_CONSOLECTL
,
1375 UID_ROOT
, GID_WHEEL
, 0600, "consolectl");
1379 sccnterm(struct consdev
*cp
)
1381 /* we are not the kernel console any more, release everything */
1383 if (sc_console_unit
< 0)
1384 return; /* shouldn't happen */
1387 sc_clear_screen(sc_console
);
1388 sccnupdate(sc_console
);
1390 scterm(sc_console_unit
, SC_KERNEL_CONSOLE
);
1391 sc_console_unit
= -1;
1396 sccnputc(void *private, int c
)
1399 scr_stat
*scp
= sc_console
;
1401 #ifndef SC_NO_HISTORY
1403 #endif /* !SC_NO_HISTORY */
1405 /* assert(sc_console != NULL) */
1407 #ifndef SC_NO_HISTORY
1408 if (scp
== scp
->sc
->cur_scp
&& scp
->status
& SLKED
) {
1409 scp
->status
&= ~SLKED
;
1410 update_kbd_state(scp
, scp
->status
, SLKED
);
1411 if (scp
->status
& BUFFER_SAVED
) {
1412 if (!sc_hist_restore(scp
))
1413 sc_remove_cutmarking(scp
);
1414 scp
->status
&= ~BUFFER_SAVED
;
1415 scp
->status
|= CURSOR_ENABLED
;
1416 sc_draw_cursor_image(scp
);
1418 tp
= VIRTUAL_TTY(scp
->sc
, scp
->index
);
1422 #endif /* !SC_NO_HISTORY */
1425 if (kernel_console_ts
!= NULL
)
1426 scp
->ts
= kernel_console_ts
;
1428 sc_puts(scp
, buf
, 1);
1437 sccngetc(void *private)
1439 return sccngetch(0);
1443 sccncheckc(void *private)
1445 return sccngetch(SCGETC_NONBLOCK
);
1449 sccndbctl(void *private, int on
)
1451 /* assert(sc_console_unit >= 0) */
1452 /* try to switch to the kernel console screen */
1453 if (on
&& debugger
== 0) {
1455 * TRY to make sure the screen saver is stopped,
1456 * and the screen is updated before switching to
1461 && sc_console
->sc
->cur_scp
->smode
.mode
== VT_AUTO
1462 && sc_console
->smode
.mode
== VT_AUTO
) {
1463 sc_console
->sc
->cur_scp
->status
|= MOUSE_HIDDEN
;
1464 sc_switch_scr(sc_console
->sc
, sc_console
->index
);
1474 sccngetch(int flags
)
1476 static struct fkeytab fkey
;
1484 /* assert(sc_console != NULL) */
1487 * Stop the screen saver and update the screen if necessary.
1488 * What if we have been running in the screen saver code... XXX
1490 sc_touch_scrn_saver();
1491 scp
= sc_console
->sc
->cur_scp
; /* XXX */
1494 if (fkeycp
< fkey
.len
) {
1496 return fkey
.str
[fkeycp
++];
1499 if (scp
->sc
->kbd
== NULL
) {
1505 * Make sure the keyboard is accessible even when the kbd device
1506 * driver is disabled.
1508 kbd_enable(scp
->sc
->kbd
);
1510 /* we shall always use the keyboard in the XLATE mode here */
1511 cur_mode
= scp
->kbd_mode
;
1512 scp
->kbd_mode
= K_XLATE
;
1513 kbd_ioctl(scp
->sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
1515 kbd_poll(scp
->sc
->kbd
, TRUE
);
1516 c
= scgetc(scp
->sc
, SCGETC_CN
| flags
);
1517 kbd_poll(scp
->sc
->kbd
, FALSE
);
1519 scp
->kbd_mode
= cur_mode
;
1520 kbd_ioctl(scp
->sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
1521 kbd_disable(scp
->sc
->kbd
);
1524 switch (KEYFLAGS(c
)) {
1525 case 0: /* normal char */
1527 case FKEY
: /* function key */
1528 p
= kbd_get_fkeystr(scp
->sc
->kbd
, KEYCHAR(c
), (size_t *)&fkeycp
);
1530 if ((p
!= NULL
) && (fkey
.len
> 0)) {
1531 bcopy(p
, fkey
.str
, fkey
.len
);
1545 sccnupdate(scr_stat
*scp
)
1547 /* this is a cut-down version of scrn_timer()... */
1549 if (scp
->sc
->font_loading_in_progress
|| scp
->sc
->videoio_in_progress
)
1552 if (debugger
> 0 || panicstr
|| shutdown_in_progress
) {
1553 sc_touch_scrn_saver();
1554 } else if (scp
!= scp
->sc
->cur_scp
) {
1558 if (!run_scrn_saver
)
1559 scp
->sc
->flags
&= ~SC_SCRN_IDLE
;
1561 if ((saver_mode
!= CONS_LKM_SAVER
) || !(scp
->sc
->flags
& SC_SCRN_IDLE
))
1562 if (scp
->sc
->flags
& SC_SCRN_BLANKED
)
1563 stop_scrn_saver(scp
->sc
, current_saver
);
1564 #endif /* NSPLASH */
1566 if (scp
!= scp
->sc
->cur_scp
|| scp
->sc
->blink_in_progress
1567 || scp
->sc
->switch_in_progress
)
1570 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1571 * when write_in_progress is non-zero. XXX
1574 if (!ISGRAPHSC(scp
) && !(scp
->sc
->flags
& SC_SCRN_BLANKED
))
1575 scrn_update(scp
, TRUE
);
1579 scrn_timer(void *arg
)
1581 static int kbd_interval
= 0;
1587 again
= (arg
!= NULL
);
1589 sc
= (sc_softc_t
*)arg
;
1590 else if (sc_console
!= NULL
)
1591 sc
= sc_console
->sc
;
1595 /* don't do anything when we are performing some I/O operations */
1596 if (sc
->font_loading_in_progress
|| sc
->videoio_in_progress
) {
1598 callout_reset(&sc
->scrn_timer_ch
, hz
/ 10, scrn_timer
, sc
);
1603 if ((sc
->kbd
== NULL
) && (sc
->config
& SC_AUTODETECT_KBD
)) {
1604 /* try to allocate a keyboard automatically */
1605 if (++kbd_interval
>= 25) {
1606 sc
->keyboard
= kbd_allocate("*", -1, (void *)&sc
->keyboard
,
1608 if (sc
->keyboard
>= 0) {
1609 sc
->kbd
= kbd_get_keyboard(sc
->keyboard
);
1610 kbd_ioctl(sc
->kbd
, KDSKBMODE
,
1611 (caddr_t
)&sc
->cur_scp
->kbd_mode
);
1612 update_kbd_state(sc
->cur_scp
, sc
->cur_scp
->status
,
1619 /* find the vty to update */
1622 /* should we stop the screen saver? */
1623 getmicrouptime(&tv
);
1624 if (debugger
> 0 || panicstr
|| shutdown_in_progress
)
1625 sc_touch_scrn_saver();
1626 if (run_scrn_saver
) {
1627 if (tv
.tv_sec
> sc
->scrn_time_stamp
+ scrn_blank_time
)
1628 sc
->flags
|= SC_SCRN_IDLE
;
1630 sc
->flags
&= ~SC_SCRN_IDLE
;
1632 sc
->scrn_time_stamp
= tv
.tv_sec
;
1633 sc
->flags
&= ~SC_SCRN_IDLE
;
1634 if (scrn_blank_time
> 0)
1635 run_scrn_saver
= TRUE
;
1638 if ((saver_mode
!= CONS_LKM_SAVER
) || !(sc
->flags
& SC_SCRN_IDLE
))
1639 if (sc
->flags
& SC_SCRN_BLANKED
)
1640 stop_scrn_saver(sc
, current_saver
);
1641 #endif /* NSPLASH */
1643 /* should we just return ? */
1644 if (sc
->blink_in_progress
|| sc
->switch_in_progress
1645 || sc
->write_in_progress
) {
1647 callout_reset(&sc
->scrn_timer_ch
, hz
/ 10, scrn_timer
, sc
);
1652 /* Update the screen */
1653 scp
= sc
->cur_scp
; /* cur_scp may have changed... */
1654 if (!ISGRAPHSC(scp
) && !(sc
->flags
& SC_SCRN_BLANKED
))
1655 scrn_update(scp
, TRUE
);
1658 /* should we activate the screen saver? */
1659 if ((saver_mode
== CONS_LKM_SAVER
) && (sc
->flags
& SC_SCRN_IDLE
))
1660 if (!ISGRAPHSC(scp
) || (sc
->flags
& SC_SCRN_BLANKED
))
1661 (*current_saver
)(sc
, TRUE
);
1662 #endif /* NSPLASH */
1665 callout_reset(&sc
->scrn_timer_ch
, hz
/ 25, scrn_timer
, sc
);
1670 and_region(int *s1
, int *e1
, int s2
, int e2
)
1672 if (*e1
< s2
|| e2
< *s1
)
1674 *s1
= imax(*s1
, s2
);
1675 *e1
= imin(*e1
, e2
);
1680 scrn_update(scr_stat
*scp
, int show_cursor
)
1687 /* assert(scp == scp->sc->cur_scp) */
1689 ++scp
->sc
->videoio_in_progress
;
1691 #ifndef SC_NO_CUTPASTE
1692 /* remove the previous mouse pointer image if necessary */
1693 if (scp
->status
& MOUSE_VISIBLE
) {
1695 e
= scp
->mouse_pos
+ scp
->xsize
+ 1;
1696 if ((scp
->status
& (MOUSE_MOVED
| MOUSE_HIDDEN
))
1697 || and_region(&s
, &e
, scp
->start
, scp
->end
)
1698 || ((scp
->status
& CURSOR_ENABLED
) &&
1699 (scp
->cursor_pos
!= scp
->cursor_oldpos
) &&
1700 (and_region(&s
, &e
, scp
->cursor_pos
, scp
->cursor_pos
)
1701 || and_region(&s
, &e
, scp
->cursor_oldpos
, scp
->cursor_oldpos
)))) {
1702 sc_remove_mouse_image(scp
);
1703 if (scp
->end
>= scp
->xsize
*scp
->ysize
)
1704 scp
->end
= scp
->xsize
*scp
->ysize
- 1;
1707 #endif /* !SC_NO_CUTPASTE */
1711 if (scp
->end
>= scp
->xsize
*scp
->ysize
) {
1712 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp
->end
);
1713 scp
->end
= scp
->xsize
*scp
->ysize
- 1;
1715 if (scp
->start
< 0) {
1716 kprintf("scrn_update(): scp->start %d < 0\n", scp
->start
);
1721 /* update screen image */
1722 if (scp
->start
<= scp
->end
) {
1723 if (scp
->mouse_cut_end
>= 0) {
1724 /* there is a marked region for cut & paste */
1725 if (scp
->mouse_cut_start
<= scp
->mouse_cut_end
) {
1726 start
= scp
->mouse_cut_start
;
1727 end
= scp
->mouse_cut_end
;
1729 start
= scp
->mouse_cut_end
;
1730 end
= scp
->mouse_cut_start
- 1;
1734 /* does the cut-mark region overlap with the update region? */
1735 if (and_region(&s
, &e
, scp
->start
, scp
->end
)) {
1736 (*scp
->rndr
->draw
)(scp
, s
, e
- s
+ 1, TRUE
);
1739 if (and_region(&s
, &e
, scp
->start
, scp
->end
))
1740 (*scp
->rndr
->draw
)(scp
, s
, e
- s
+ 1, FALSE
);
1742 e
= scp
->xsize
*scp
->ysize
- 1;
1743 if (and_region(&s
, &e
, scp
->start
, scp
->end
))
1744 (*scp
->rndr
->draw
)(scp
, s
, e
- s
+ 1, FALSE
);
1746 (*scp
->rndr
->draw
)(scp
, scp
->start
,
1747 scp
->end
- scp
->start
+ 1, FALSE
);
1750 (*scp
->rndr
->draw
)(scp
, scp
->start
,
1751 scp
->end
- scp
->start
+ 1, FALSE
);
1755 /* we are not to show the cursor and the mouse pointer... */
1758 scp
->start
= scp
->xsize
*scp
->ysize
- 1;
1759 --scp
->sc
->videoio_in_progress
;
1763 /* update cursor image */
1764 if (scp
->status
& CURSOR_ENABLED
) {
1767 /* did cursor move since last time ? */
1768 if (scp
->cursor_pos
!= scp
->cursor_oldpos
) {
1769 /* do we need to remove old cursor image ? */
1770 if (!and_region(&s
, &e
, scp
->cursor_oldpos
, scp
->cursor_oldpos
))
1771 sc_remove_cursor_image(scp
);
1772 sc_draw_cursor_image(scp
);
1774 if (and_region(&s
, &e
, scp
->cursor_pos
, scp
->cursor_pos
))
1775 /* cursor didn't move, but has been overwritten */
1776 sc_draw_cursor_image(scp
);
1777 else if (scp
->sc
->flags
& SC_BLINK_CURSOR
)
1778 /* if it's a blinking cursor, update it */
1779 (*scp
->rndr
->blink_cursor
)(scp
, scp
->cursor_pos
,
1780 sc_inside_cutmark(scp
,
1785 #ifndef SC_NO_CUTPASTE
1786 /* update "pseudo" mouse pointer image */
1787 if (scp
->sc
->flags
& SC_MOUSE_ENABLED
) {
1788 if (!(scp
->status
& (MOUSE_VISIBLE
| MOUSE_HIDDEN
))) {
1789 scp
->status
&= ~MOUSE_MOVED
;
1790 sc_draw_mouse_image(scp
);
1793 #endif /* SC_NO_CUTPASTE */
1796 scp
->start
= scp
->xsize
*scp
->ysize
- 1;
1798 --scp
->sc
->videoio_in_progress
;
1803 scsplash_callback(int event
, void *arg
)
1808 sc
= (sc_softc_t
*)arg
;
1812 if (add_scrn_saver(scsplash_saver
) == 0) {
1813 sc
->flags
&= ~SC_SAVER_FAILED
;
1814 run_scrn_saver
= TRUE
;
1815 if (cold
&& !(boothowto
& (RB_VERBOSE
| RB_CONFIG
))) {
1816 scsplash_stick(TRUE
);
1817 (*current_saver
)(sc
, TRUE
);
1823 if (current_saver
== scsplash_saver
) {
1824 scsplash_stick(FALSE
);
1825 error
= remove_scrn_saver(scsplash_saver
);
1837 scsplash_saver(sc_softc_t
*sc
, int show
)
1839 static int busy
= FALSE
;
1848 if (!(sc
->flags
& SC_SAVER_FAILED
)) {
1849 if (!(sc
->flags
& SC_SCRN_BLANKED
))
1850 set_scrn_saver_mode(scp
, -1, NULL
, 0);
1851 switch (splash(sc
->adp
, TRUE
)) {
1852 case 0: /* succeeded */
1854 case EAGAIN
: /* try later */
1855 restore_scrn_saver_mode(scp
, FALSE
);
1856 sc_touch_scrn_saver(); /* XXX */
1859 sc
->flags
|= SC_SAVER_FAILED
;
1860 scsplash_stick(FALSE
);
1861 restore_scrn_saver_mode(scp
, TRUE
);
1862 kprintf("scsplash_saver(): failed to put up the image\n");
1866 } else if (!sticky_splash
) {
1867 if ((sc
->flags
& SC_SCRN_BLANKED
) && (splash(sc
->adp
, FALSE
) == 0))
1868 restore_scrn_saver_mode(scp
, TRUE
);
1874 add_scrn_saver(void (*this_saver
)(sc_softc_t
*, int))
1879 if (current_saver
!= none_saver
) {
1880 error
= remove_scrn_saver(current_saver
);
1885 if (current_saver
!= none_saver
)
1888 run_scrn_saver
= FALSE
;
1889 saver_mode
= CONS_LKM_SAVER
;
1890 current_saver
= this_saver
;
1895 remove_scrn_saver(void (*this_saver
)(sc_softc_t
*, int))
1897 if (current_saver
!= this_saver
)
1902 * In order to prevent `current_saver' from being called by
1903 * the timeout routine `scrn_timer()' while we manipulate
1904 * the saver list, we shall set `current_saver' to `none_saver'
1905 * before stopping the current saver, rather than blocking by `splXX()'.
1907 current_saver
= none_saver
;
1909 stop_scrn_saver(this_saver
);
1912 /* unblank all blanked screens */
1913 wait_scrn_saver_stop(NULL
);
1917 current_saver
= none_saver
;
1922 set_scrn_saver_mode(scr_stat
*scp
, int mode
, u_char
*pal
, int border
)
1925 /* assert(scp == scp->sc->cur_scp) */
1927 if (!ISGRAPHSC(scp
))
1928 sc_remove_cursor_image(scp
);
1929 scp
->splash_save_mode
= scp
->mode
;
1930 scp
->splash_save_status
= scp
->status
& (GRAPHICS_MODE
| PIXEL_MODE
);
1931 scp
->status
&= ~(GRAPHICS_MODE
| PIXEL_MODE
);
1932 scp
->status
|= (UNKNOWN_MODE
| SAVER_RUNNING
);
1933 scp
->sc
->flags
|= SC_SCRN_BLANKED
;
1939 if (set_mode(scp
) == 0) {
1940 if (scp
->sc
->adp
->va_info
.vi_flags
& V_INFO_GRAPHICS
)
1941 scp
->status
|= GRAPHICS_MODE
;
1942 #ifndef SC_NO_PALETTE_LOADING
1944 load_palette(scp
->sc
->adp
, pal
);
1946 sc_set_border(scp
, border
);
1950 scp
->mode
= scp
->splash_save_mode
;
1951 scp
->status
&= ~(UNKNOWN_MODE
| SAVER_RUNNING
);
1952 scp
->status
|= scp
->splash_save_status
;
1959 restore_scrn_saver_mode(scr_stat
*scp
, int changemode
)
1964 /* assert(scp == scp->sc->cur_scp) */
1967 status
= scp
->status
;
1968 scp
->mode
= scp
->splash_save_mode
;
1969 scp
->status
&= ~(UNKNOWN_MODE
| SAVER_RUNNING
);
1970 scp
->status
|= scp
->splash_save_status
;
1971 scp
->sc
->flags
&= ~SC_SCRN_BLANKED
;
1973 if (!ISGRAPHSC(scp
))
1974 sc_draw_cursor_image(scp
);
1979 if (set_mode(scp
) == 0) {
1980 #ifndef SC_NO_PALETTE_LOADING
1981 load_palette(scp
->sc
->adp
, scp
->sc
->palette
);
1988 scp
->status
= status
;
1995 stop_scrn_saver(sc_softc_t
*sc
, void (*saver
)(sc_softc_t
*, int))
1997 (*saver
)(sc
, FALSE
);
1998 run_scrn_saver
= FALSE
;
1999 /* the screen saver may have chosen not to stop after all... */
2000 if (sc
->flags
& SC_SCRN_BLANKED
)
2003 mark_all(sc
->cur_scp
);
2004 if (sc
->delayed_next_scr
)
2005 sc_switch_scr(sc
, sc
->delayed_next_scr
- 1);
2006 wakeup((caddr_t
)&scrn_blanked
);
2010 wait_scrn_saver_stop(sc_softc_t
*sc
)
2014 while (scrn_blanked
> 0) {
2015 run_scrn_saver
= FALSE
;
2016 if (sc
&& !(sc
->flags
& SC_SCRN_BLANKED
)) {
2020 error
= tsleep((caddr_t
)&scrn_blanked
, PCATCH
, "scrsav", 0);
2021 if ((error
!= 0) && (error
!= ERESTART
))
2024 run_scrn_saver
= FALSE
;
2027 #endif /* NSPLASH */
2030 sc_touch_scrn_saver(void)
2032 scsplash_stick(FALSE
);
2033 run_scrn_saver
= FALSE
;
2037 sc_switch_scr(sc_softc_t
*sc
, u_int next_scr
)
2042 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr
+ 1));
2044 /* prevent switch if previously requested */
2045 if (sc
->flags
& SC_SCRN_VTYLOCK
) {
2046 sc_bell(sc
->cur_scp
, sc
->cur_scp
->bell_pitch
,
2047 sc
->cur_scp
->bell_duration
);
2051 /* delay switch if the screen is blanked or being updated */
2052 if ((sc
->flags
& SC_SCRN_BLANKED
) || sc
->write_in_progress
2053 || sc
->blink_in_progress
|| sc
->videoio_in_progress
) {
2054 sc
->delayed_next_scr
= next_scr
+ 1;
2055 sc_touch_scrn_saver();
2056 DPRINTF(5, ("switch delayed\n"));
2061 cur_scp
= sc
->cur_scp
;
2063 /* we are in the middle of the vty switching process... */
2064 if (sc
->switch_in_progress
2065 && (cur_scp
->smode
.mode
== VT_PROCESS
)
2067 if (cur_scp
->proc
!= pfind(cur_scp
->pid
)) {
2069 * The controlling process has died!!. Do some clean up.
2070 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2071 * are not reset here yet; they will be cleared later.
2073 DPRINTF(5, ("cur_scp controlling process %d died, ",
2075 if (cur_scp
->status
& SWITCH_WAIT_REL
) {
2077 * Force the previous switch to finish, but return now
2080 * note: must be called from a critical section because
2081 * finish_vt_rel will call do_switch_scr which releases it
2084 DPRINTF(5, ("reset WAIT_REL, "));
2085 finish_vt_rel(cur_scp
, TRUE
);
2087 DPRINTF(5, ("finishing previous switch\n"));
2089 } else if (cur_scp
->status
& SWITCH_WAIT_ACQ
) {
2090 /* let's assume screen switch has been completed. */
2091 DPRINTF(5, ("reset WAIT_ACQ, "));
2092 finish_vt_acq(cur_scp
);
2095 * We are in between screen release and acquisition, and
2096 * reached here via scgetc() or scrn_timer() which has
2097 * interrupted exchange_scr(). Don't do anything stupid.
2099 DPRINTF(5, ("waiting nothing, "));
2103 * The controlling process is alive, but not responding...
2104 * It is either buggy or it may be just taking time.
2105 * The following code is a gross kludge to cope with this
2106 * problem for which there is no clean solution. XXX
2108 if (cur_scp
->status
& SWITCH_WAIT_REL
) {
2109 switch (sc
->switch_in_progress
++) {
2113 DPRINTF(5, ("sending relsig again, "));
2114 signal_vt_rel(cur_scp
);
2121 * Act as if the controlling program returned
2124 * note: must be called from a critical section because
2125 * finish_vt_rel will call do_switch_scr which releases it
2128 DPRINTF(5, ("force reset WAIT_REL, "));
2129 finish_vt_rel(cur_scp
, FALSE
);
2131 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2134 } else if (cur_scp
->status
& SWITCH_WAIT_ACQ
) {
2135 switch (sc
->switch_in_progress
++) {
2139 DPRINTF(5, ("sending acqsig again, "));
2140 signal_vt_acq(cur_scp
);
2146 /* clear the flag and finish the previous switch */
2147 DPRINTF(5, ("force reset WAIT_ACQ, "));
2148 finish_vt_acq(cur_scp
);
2156 * Return error if an invalid argument is given, or vty switch
2157 * is still in progress.
2159 if ((next_scr
< sc
->first_vty
) || (next_scr
>= sc
->first_vty
+ sc
->vtys
)
2160 || sc
->switch_in_progress
) {
2162 sc_bell(cur_scp
, bios_value
.bell_pitch
, BELL_DURATION
);
2163 DPRINTF(5, ("error 1\n"));
2168 * Don't allow switching away from the graphics mode vty
2169 * if the switch mode is VT_AUTO, unless the next vty is the same
2170 * as the current or the current vty has been closed (but showing).
2172 tp
= VIRTUAL_TTY(sc
, cur_scp
->index
);
2173 if ((cur_scp
->index
!= next_scr
)
2175 && (cur_scp
->smode
.mode
== VT_AUTO
)
2176 && ISGRAPHSC(cur_scp
)) {
2178 sc_bell(cur_scp
, bios_value
.bell_pitch
, BELL_DURATION
);
2179 DPRINTF(5, ("error, graphics mode\n"));
2184 * Is the wanted vty open? Don't allow switching to a closed vty.
2185 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2186 * Note that we always allow the user to switch to the kernel
2187 * console even if it is closed.
2189 if ((sc_console
== NULL
) || (next_scr
!= sc_console
->index
)) {
2190 tp
= VIRTUAL_TTY(sc
, next_scr
);
2191 if (!ISTTYOPEN(tp
)) {
2193 sc_bell(cur_scp
, bios_value
.bell_pitch
, BELL_DURATION
);
2194 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2197 if ((debugger
> 0) && (SC_STAT(tp
->t_dev
)->smode
.mode
== VT_PROCESS
)) {
2199 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2204 /* this is the start of vty switching process... */
2205 ++sc
->switch_in_progress
;
2206 sc
->delayed_next_scr
= 0;
2207 sc
->old_scp
= cur_scp
;
2208 sc
->new_scp
= SC_STAT(SC_DEV(sc
, next_scr
));
2209 if (sc
->new_scp
== sc
->old_scp
) {
2210 sc
->switch_in_progress
= 0;
2211 wakeup((caddr_t
)&sc
->new_scp
->smode
);
2213 DPRINTF(5, ("switch done (new == old)\n"));
2217 /* has controlling process died? */
2218 vt_proc_alive(sc
->old_scp
);
2219 vt_proc_alive(sc
->new_scp
);
2221 /* wait for the controlling process to release the screen, if necessary */
2222 if (signal_vt_rel(sc
->old_scp
)) {
2227 /* go set up the new vty screen */
2232 /* wake up processes waiting for this vty */
2233 wakeup((caddr_t
)&sc
->cur_scp
->smode
);
2235 /* wait for the controlling process to acknowledge, if necessary */
2236 if (signal_vt_acq(sc
->cur_scp
)) {
2241 sc
->switch_in_progress
= 0;
2242 if (sc
->unit
== sc_console_unit
)
2243 cons_unavail
= FALSE
;
2245 DPRINTF(5, ("switch done\n"));
2251 * NOTE: must be called from a critical section because do_switch_scr
2252 * will release it temporarily.
2255 do_switch_scr(sc_softc_t
*sc
)
2257 vt_proc_alive(sc
->new_scp
);
2262 /* sc->cur_scp == sc->new_scp */
2263 wakeup((caddr_t
)&sc
->cur_scp
->smode
);
2265 /* wait for the controlling process to acknowledge, if necessary */
2266 if (!signal_vt_acq(sc
->cur_scp
)) {
2267 sc
->switch_in_progress
= 0;
2268 if (sc
->unit
== sc_console_unit
)
2269 cons_unavail
= FALSE
;
2274 vt_proc_alive(scr_stat
*scp
)
2277 if (scp
->proc
== pfind(scp
->pid
))
2280 scp
->smode
.mode
= VT_AUTO
;
2281 DPRINTF(5, ("vt controlling process %d died\n", scp
->pid
));
2287 signal_vt_rel(scr_stat
*scp
)
2289 if (scp
->smode
.mode
!= VT_PROCESS
)
2291 scp
->status
|= SWITCH_WAIT_REL
;
2292 ksignal(scp
->proc
, scp
->smode
.relsig
);
2293 DPRINTF(5, ("sending relsig to %d\n", scp
->pid
));
2298 signal_vt_acq(scr_stat
*scp
)
2300 if (scp
->smode
.mode
!= VT_PROCESS
)
2302 if (scp
->sc
->unit
== sc_console_unit
)
2303 cons_unavail
= TRUE
;
2304 scp
->status
|= SWITCH_WAIT_ACQ
;
2305 ksignal(scp
->proc
, scp
->smode
.acqsig
);
2306 DPRINTF(5, ("sending acqsig to %d\n", scp
->pid
));
2311 * NOTE: must be called from a critical section because do_switch_scr
2312 * will release it temporarily.
2315 finish_vt_rel(scr_stat
*scp
, int release
)
2317 if (scp
== scp
->sc
->old_scp
&& scp
->status
& SWITCH_WAIT_REL
) {
2318 scp
->status
&= ~SWITCH_WAIT_REL
;
2320 do_switch_scr(scp
->sc
);
2322 scp
->sc
->switch_in_progress
= 0;
2329 finish_vt_acq(scr_stat
*scp
)
2331 if (scp
== scp
->sc
->new_scp
&& scp
->status
& SWITCH_WAIT_ACQ
) {
2332 scp
->status
&= ~SWITCH_WAIT_ACQ
;
2333 scp
->sc
->switch_in_progress
= 0;
2340 exchange_scr(sc_softc_t
*sc
)
2344 /* save the current state of video and keyboard */
2345 sc_move_cursor(sc
->old_scp
, sc
->old_scp
->xpos
, sc
->old_scp
->ypos
);
2346 if (!ISGRAPHSC(sc
->old_scp
))
2347 sc_remove_cursor_image(sc
->old_scp
);
2348 if (sc
->old_scp
->kbd_mode
== K_XLATE
)
2349 save_kbd_state(sc
->old_scp
);
2351 /* set up the video for the new screen */
2352 scp
= sc
->cur_scp
= sc
->new_scp
;
2353 if (sc
->old_scp
->mode
!= scp
->mode
|| ISUNKNOWNSC(sc
->old_scp
))
2356 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, scp
->xsize
, scp
->ysize
,
2357 (void *)sc
->adp
->va_window
, FALSE
);
2358 scp
->status
|= MOUSE_HIDDEN
;
2359 sc_move_cursor(scp
, scp
->xpos
, scp
->ypos
);
2360 if (!ISGRAPHSC(scp
))
2361 sc_set_cursor_image(scp
);
2362 #ifndef SC_NO_PALETTE_LOADING
2363 if (ISGRAPHSC(sc
->old_scp
))
2364 load_palette(sc
->adp
, sc
->palette
);
2366 sc_set_border(scp
, scp
->border
);
2368 /* set up the keyboard for the new screen */
2369 if (sc
->old_scp
->kbd_mode
!= scp
->kbd_mode
)
2370 kbd_ioctl(sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
2371 update_kbd_state(scp
, scp
->status
, LOCK_MASK
);
2377 sc_puts(scr_stat
*scp
, u_char
*buf
, int len
)
2380 /* make screensaver happy */
2381 if (!sticky_splash
&& scp
== scp
->sc
->cur_scp
)
2382 run_scrn_saver
= FALSE
;
2386 (*scp
->tsw
->te_puts
)(scp
, buf
, len
);
2388 if (scp
->sc
->delayed_next_scr
)
2389 sc_switch_scr(scp
->sc
, scp
->sc
->delayed_next_scr
- 1);
2393 sc_draw_cursor_image(scr_stat
*scp
)
2395 /* assert(scp == scp->sc->cur_scp); */
2396 ++scp
->sc
->videoio_in_progress
;
2397 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_pos
,
2398 scp
->sc
->flags
& SC_BLINK_CURSOR
, TRUE
,
2399 sc_inside_cutmark(scp
, scp
->cursor_pos
));
2400 scp
->cursor_oldpos
= scp
->cursor_pos
;
2401 --scp
->sc
->videoio_in_progress
;
2405 sc_remove_cursor_image(scr_stat
*scp
)
2407 /* assert(scp == scp->sc->cur_scp); */
2408 ++scp
->sc
->videoio_in_progress
;
2409 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_oldpos
,
2410 scp
->sc
->flags
& SC_BLINK_CURSOR
, FALSE
,
2411 sc_inside_cutmark(scp
, scp
->cursor_oldpos
));
2412 --scp
->sc
->videoio_in_progress
;
2416 update_cursor_image(scr_stat
*scp
)
2420 if (scp
->sc
->flags
& SC_CHAR_CURSOR
) {
2421 scp
->cursor_base
= imax(0, scp
->sc
->cursor_base
);
2422 scp
->cursor_height
= imin(scp
->sc
->cursor_height
, scp
->font_size
);
2424 scp
->cursor_base
= 0;
2425 scp
->cursor_height
= scp
->font_size
;
2427 blink
= scp
->sc
->flags
& SC_BLINK_CURSOR
;
2429 /* assert(scp == scp->sc->cur_scp); */
2430 ++scp
->sc
->videoio_in_progress
;
2431 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_oldpos
, blink
, FALSE
,
2432 sc_inside_cutmark(scp
, scp
->cursor_pos
));
2433 (*scp
->rndr
->set_cursor
)(scp
, scp
->cursor_base
, scp
->cursor_height
, blink
);
2434 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_pos
, blink
, TRUE
,
2435 sc_inside_cutmark(scp
, scp
->cursor_pos
));
2436 --scp
->sc
->videoio_in_progress
;
2440 sc_set_cursor_image(scr_stat
*scp
)
2442 if (scp
->sc
->flags
& SC_CHAR_CURSOR
) {
2443 scp
->cursor_base
= imax(0, scp
->sc
->cursor_base
);
2444 scp
->cursor_height
= imin(scp
->sc
->cursor_height
, scp
->font_size
);
2446 scp
->cursor_base
= 0;
2447 scp
->cursor_height
= scp
->font_size
;
2450 /* assert(scp == scp->sc->cur_scp); */
2451 ++scp
->sc
->videoio_in_progress
;
2452 (*scp
->rndr
->set_cursor
)(scp
, scp
->cursor_base
, scp
->cursor_height
,
2453 scp
->sc
->flags
& SC_BLINK_CURSOR
);
2454 --scp
->sc
->videoio_in_progress
;
2458 scinit(int unit
, int flags
)
2461 * When syscons is being initialized as the kernel console, malloc()
2462 * is not yet functional, because various kernel structures has not been
2463 * fully initialized yet. Therefore, we need to declare the following
2464 * static buffers for the console. This is less than ideal,
2465 * but is necessry evil for the time being. XXX
2467 static scr_stat main_console
;
2468 static u_short sc_buffer
[ROW
*COL
]; /* XXX */
2469 #ifndef SC_NO_FONT_LOADING
2470 static u_char font_8
[256*8];
2471 static u_char font_14
[256*14];
2472 static u_char font_16
[256*16];
2477 video_adapter_t
*adp
;
2482 /* one time initialization */
2483 if (init_done
== COLD
)
2484 sc_get_bios_values(&bios_value
);
2488 * Allocate resources. Even if we are being called for the second
2489 * time, we must allocate them again, because they might have
2492 sc
= sc_get_softc(unit
, flags
& SC_KERNEL_CONSOLE
);
2494 if (sc
->adapter
>= 0) {
2495 vid_release(sc
->adp
, (void *)&sc
->adapter
);
2499 if (sc
->keyboard
>= 0) {
2500 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit
, sc
->keyboard
));
2501 i
= kbd_release(sc
->kbd
, (void *)&sc
->keyboard
);
2502 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit
, i
));
2503 if (sc
->kbd
!= NULL
) {
2504 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2505 unit
, sc
->kbd
->kb_index
, sc
->kbd
->kb_unit
, sc
->kbd
->kb_flags
));
2509 sc
->adapter
= vid_allocate("*", unit
, (void *)&sc
->adapter
);
2510 sc
->adp
= vid_get_adapter(sc
->adapter
);
2511 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2512 sc
->keyboard
= kbd_allocate("*", unit
, (void *)&sc
->keyboard
,
2514 DPRINTF(1, ("sc%d: keyboard %d\n", unit
, sc
->keyboard
));
2515 sc
->kbd
= kbd_get_keyboard(sc
->keyboard
);
2516 if (sc
->kbd
!= NULL
) {
2517 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2518 unit
, sc
->kbd
->kb_index
, sc
->kbd
->kb_unit
, sc
->kbd
->kb_flags
));
2521 if (!(sc
->flags
& SC_INIT_DONE
) || (adp
!= sc
->adp
)) {
2523 sc
->initial_mode
= sc
->adp
->va_initial_mode
;
2525 #ifndef SC_NO_FONT_LOADING
2526 if (flags
& SC_KERNEL_CONSOLE
) {
2527 sc
->font_8
= font_8
;
2528 sc
->font_14
= font_14
;
2529 sc
->font_16
= font_16
;
2530 } else if (sc
->font_8
== NULL
) {
2531 /* assert(sc_malloc) */
2532 sc
->font_8
= kmalloc(sizeof(font_8
), M_SYSCONS
, M_WAITOK
);
2533 sc
->font_14
= kmalloc(sizeof(font_14
), M_SYSCONS
, M_WAITOK
);
2534 sc
->font_16
= kmalloc(sizeof(font_16
), M_SYSCONS
, M_WAITOK
);
2538 /* extract the hardware cursor location and hide the cursor for now */
2539 (*vidsw
[sc
->adapter
]->read_hw_cursor
)(sc
->adp
, &col
, &row
);
2540 (*vidsw
[sc
->adapter
]->set_hw_cursor
)(sc
->adp
, -1, -1);
2542 /* set up the first console */
2543 sc
->first_vty
= unit
*MAXCONS
;
2544 sc
->vtys
= MAXCONS
; /* XXX: should be configurable */
2545 if (flags
& SC_KERNEL_CONSOLE
) {
2546 scp
= &main_console
;
2547 sc
->console_scp
= scp
;
2548 init_scp(sc
, sc
->first_vty
, scp
);
2549 sc_vtb_init(&scp
->vtb
, VTB_MEMORY
, scp
->xsize
, scp
->ysize
,
2550 (void *)sc_buffer
, FALSE
);
2551 if (sc_init_emulator(scp
, SC_DFLT_TERM
))
2552 sc_init_emulator(scp
, "*");
2553 (*scp
->tsw
->te_default_attr
)(scp
,
2554 kernel_default
.std_color
,
2555 kernel_default
.rev_color
);
2557 /* assert(sc_malloc) */
2558 sc
->dev
= kmalloc(sizeof(cdev_t
)*sc
->vtys
, M_SYSCONS
, M_WAITOK
| M_ZERO
);
2559 sc
->dev
[0] = make_dev(&sc_ops
, unit
*MAXCONS
, UID_ROOT
,
2560 GID_WHEEL
, 0600, "ttyv%r", unit
*MAXCONS
);
2561 sc
->dev
[0]->si_tty
= ttymalloc(sc
->dev
[0]->si_tty
);
2562 scp
= alloc_scp(sc
, sc
->first_vty
);
2563 sc
->dev
[0]->si_drv1
= scp
;
2567 /* copy screen to temporary buffer */
2568 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, scp
->xsize
, scp
->ysize
,
2569 (void *)scp
->sc
->adp
->va_window
, FALSE
);
2571 sc_vtb_copy(&scp
->scr
, 0, &scp
->vtb
, 0, scp
->xsize
*scp
->ysize
);
2573 /* move cursors to the initial positions */
2574 if (col
>= scp
->xsize
)
2576 if (row
>= scp
->ysize
)
2577 row
= scp
->ysize
- 1;
2580 scp
->cursor_pos
= scp
->cursor_oldpos
= row
*scp
->xsize
+ col
;
2581 if (bios_value
.cursor_end
< scp
->font_size
)
2582 sc
->cursor_base
= scp
->font_size
- bios_value
.cursor_end
- 1;
2584 sc
->cursor_base
= 0;
2585 i
= bios_value
.cursor_end
- bios_value
.cursor_start
+ 1;
2586 sc
->cursor_height
= imin(i
, scp
->font_size
);
2587 #ifndef SC_NO_SYSMOUSE
2588 sc_mouse_move(scp
, scp
->xpixel
/2, scp
->ypixel
/2);
2590 if (!ISGRAPHSC(scp
)) {
2591 sc_set_cursor_image(scp
);
2592 sc_draw_cursor_image(scp
);
2595 /* save font and palette */
2596 #ifndef SC_NO_FONT_LOADING
2597 sc
->fonts_loaded
= 0;
2598 if (ISFONTAVAIL(sc
->adp
->va_flags
)) {
2600 bcopy(dflt_font_8
, sc
->font_8
, sizeof(dflt_font_8
));
2601 bcopy(dflt_font_14
, sc
->font_14
, sizeof(dflt_font_14
));
2602 bcopy(dflt_font_16
, sc
->font_16
, sizeof(dflt_font_16
));
2603 sc
->fonts_loaded
= FONT_16
| FONT_14
| FONT_8
;
2604 if (scp
->font_size
< 14) {
2605 sc_load_font(scp
, 0, 8, sc
->font_8
, 0, 256);
2606 } else if (scp
->font_size
>= 16) {
2607 sc_load_font(scp
, 0, 16, sc
->font_16
, 0, 256);
2609 sc_load_font(scp
, 0, 14, sc
->font_14
, 0, 256);
2611 #else /* !SC_DFLT_FONT */
2612 if (scp
->font_size
< 14) {
2613 sc_save_font(scp
, 0, 8, sc
->font_8
, 0, 256);
2614 sc
->fonts_loaded
= FONT_8
;
2615 } else if (scp
->font_size
>= 16) {
2616 sc_save_font(scp
, 0, 16, sc
->font_16
, 0, 256);
2617 sc
->fonts_loaded
= FONT_16
;
2619 sc_save_font(scp
, 0, 14, sc
->font_14
, 0, 256);
2620 sc
->fonts_loaded
= FONT_14
;
2622 #endif /* SC_DFLT_FONT */
2623 /* FONT KLUDGE: always use the font page #0. XXX */
2624 sc_show_font(scp
, 0);
2626 #endif /* !SC_NO_FONT_LOADING */
2628 #ifndef SC_NO_PALETTE_LOADING
2629 save_palette(sc
->adp
, sc
->palette
);
2633 if (!(sc
->flags
& SC_SPLASH_SCRN
) && (flags
& SC_KERNEL_CONSOLE
)) {
2634 /* we are ready to put up the splash image! */
2635 splash_init(sc
->adp
, scsplash_callback
, sc
);
2636 sc
->flags
|= SC_SPLASH_SCRN
;
2638 #endif /* NSPLASH */
2641 /* the rest is not necessary, if we have done it once */
2642 if (sc
->flags
& SC_INIT_DONE
)
2645 /* initialize mapscrn arrays to a one to one map */
2646 for (i
= 0; i
< sizeof(sc
->scr_map
); i
++)
2647 sc
->scr_map
[i
] = sc
->scr_rmap
[i
] = i
;
2649 sc
->flags
|= SC_INIT_DONE
;
2653 scterm(int unit
, int flags
)
2658 sc
= sc_get_softc(unit
, flags
& SC_KERNEL_CONSOLE
);
2660 return; /* shouldn't happen */
2663 /* this console is no longer available for the splash screen */
2664 if (sc
->flags
& SC_SPLASH_SCRN
) {
2665 splash_term(sc
->adp
);
2666 sc
->flags
&= ~SC_SPLASH_SCRN
;
2668 #endif /* NSPLASH */
2671 /* move the hardware cursor to the upper-left corner */
2672 (*vidsw
[sc
->adapter
]->set_hw_cursor
)(sc
->adp
, 0, 0);
2675 /* release the keyboard and the video card */
2676 if (sc
->keyboard
>= 0)
2677 kbd_release(sc
->kbd
, &sc
->keyboard
);
2678 if (sc
->adapter
>= 0)
2679 vid_release(sc
->adp
, &sc
->adapter
);
2682 * Stop the terminal emulator, if any. If operating on the
2683 * kernel console sc->dev may not be setup yet.
2685 if (flags
& SC_KERNEL_CONSOLE
)
2686 scp
= sc
->console_scp
;
2688 scp
= SC_STAT(sc
->dev
[0]);
2690 (*scp
->tsw
->te_term
)(scp
, &scp
->ts
);
2691 if (scp
->ts
!= NULL
)
2692 kfree(scp
->ts
, M_SYSCONS
);
2694 /* clear the structure */
2695 if (!(flags
& SC_KERNEL_CONSOLE
)) {
2696 /* XXX: We need delete_dev() for this */
2697 kfree(sc
->dev
, M_SYSCONS
);
2699 /* XXX: We need a ttyunregister for this */
2700 kfree(sc
->tty
, M_SYSCONS
);
2702 #ifndef SC_NO_FONT_LOADING
2703 kfree(sc
->font_8
, M_SYSCONS
);
2704 kfree(sc
->font_14
, M_SYSCONS
);
2705 kfree(sc
->font_16
, M_SYSCONS
);
2707 /* XXX vtb, history */
2709 bzero(sc
, sizeof(*sc
));
2715 scshutdown(void *arg
, int howto
)
2717 /* assert(sc_console != NULL) */
2719 sc_touch_scrn_saver();
2720 if (!cold
&& sc_console
2721 && sc_console
->sc
->cur_scp
->smode
.mode
== VT_AUTO
2722 && sc_console
->smode
.mode
== VT_AUTO
)
2723 sc_switch_scr(sc_console
->sc
, sc_console
->index
);
2724 shutdown_in_progress
= TRUE
;
2728 sc_clean_up(scr_stat
*scp
)
2732 #endif /* NSPLASH */
2734 if (scp
->sc
->flags
& SC_SCRN_BLANKED
) {
2735 sc_touch_scrn_saver();
2737 if ((error
= wait_scrn_saver_stop(scp
->sc
)))
2739 #endif /* NSPLASH */
2741 scp
->status
|= MOUSE_HIDDEN
;
2742 sc_remove_mouse_image(scp
);
2743 sc_remove_cutmarking(scp
);
2748 sc_alloc_scr_buffer(scr_stat
*scp
, int wait
, int discard
)
2754 sc_vtb_init(&new, VTB_MEMORY
, scp
->xsize
, scp
->ysize
, NULL
, wait
);
2755 if (!discard
&& (old
.vtb_flags
& VTB_VALID
)) {
2756 /* retain the current cursor position and buffer contants */
2757 scp
->cursor_oldpos
= scp
->cursor_pos
;
2759 * This works only if the old buffer has the same size as or larger
2760 * than the new one. XXX
2762 sc_vtb_copy(&old
, 0, &new, 0, scp
->xsize
*scp
->ysize
);
2766 sc_vtb_destroy(&old
);
2769 #ifndef SC_NO_SYSMOUSE
2770 /* move the mouse cursor at the center of the screen */
2771 sc_mouse_move(scp
, scp
->xpixel
/ 2, scp
->ypixel
/ 2);
2776 alloc_scp(sc_softc_t
*sc
, int vty
)
2780 /* assert(sc_malloc) */
2782 scp
= kmalloc(sizeof(scr_stat
), M_SYSCONS
, M_WAITOK
);
2783 init_scp(sc
, vty
, scp
);
2785 sc_alloc_scr_buffer(scp
, TRUE
, TRUE
);
2786 if (sc_init_emulator(scp
, SC_DFLT_TERM
))
2787 sc_init_emulator(scp
, "*");
2789 #ifndef SC_NO_CUTPASTE
2790 sc_alloc_cut_buffer(scp
, TRUE
);
2793 #ifndef SC_NO_HISTORY
2794 sc_alloc_history_buffer(scp
, 0, 0, TRUE
);
2801 init_scp(sc_softc_t
*sc
, int vty
, scr_stat
*scp
)
2805 bzero(scp
, sizeof(*scp
));
2810 scp
->mode
= sc
->initial_mode
;
2811 callout_init(&scp
->blink_screen_ch
);
2812 (*vidsw
[sc
->adapter
]->get_info
)(sc
->adp
, scp
->mode
, &info
);
2813 if (info
.vi_flags
& V_INFO_GRAPHICS
) {
2814 scp
->status
|= GRAPHICS_MODE
;
2815 scp
->xpixel
= info
.vi_width
;
2816 scp
->ypixel
= info
.vi_height
;
2817 scp
->xsize
= info
.vi_width
/8;
2818 scp
->ysize
= info
.vi_height
/info
.vi_cheight
;
2822 scp
->xsize
= info
.vi_width
;
2823 scp
->ysize
= info
.vi_height
;
2824 scp
->xpixel
= scp
->xsize
*8;
2825 scp
->ypixel
= scp
->ysize
*info
.vi_cheight
;
2826 if (info
.vi_cheight
< 14) {
2828 #ifndef SC_NO_FONT_LOADING
2829 scp
->font
= sc
->font_8
;
2833 } else if (info
.vi_cheight
>= 16) {
2834 scp
->font_size
= 16;
2835 #ifndef SC_NO_FONT_LOADING
2836 scp
->font
= sc
->font_16
;
2841 scp
->font_size
= 14;
2842 #ifndef SC_NO_FONT_LOADING
2843 scp
->font
= sc
->font_14
;
2849 sc_vtb_init(&scp
->vtb
, VTB_MEMORY
, 0, 0, NULL
, FALSE
);
2850 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, 0, 0, NULL
, FALSE
);
2851 scp
->xoff
= scp
->yoff
= 0;
2852 scp
->xpos
= scp
->ypos
= 0;
2853 scp
->start
= scp
->xsize
* scp
->ysize
- 1;
2858 scp
->border
= BG_BLACK
;
2859 scp
->cursor_base
= sc
->cursor_base
;
2860 scp
->cursor_height
= imin(sc
->cursor_height
, scp
->font_size
);
2861 scp
->mouse_cut_start
= scp
->xsize
*scp
->ysize
;
2862 scp
->mouse_cut_end
= -1;
2863 scp
->mouse_signal
= 0;
2865 scp
->mouse_proc
= NULL
;
2866 scp
->kbd_mode
= K_XLATE
;
2867 scp
->bell_pitch
= bios_value
.bell_pitch
;
2868 scp
->bell_duration
= BELL_DURATION
;
2869 scp
->status
|= (bios_value
.shift_state
& NLKED
);
2870 scp
->status
|= CURSOR_ENABLED
| MOUSE_HIDDEN
;
2873 scp
->smode
.mode
= VT_AUTO
;
2874 scp
->history
= NULL
;
2875 scp
->history_pos
= 0;
2876 scp
->history_size
= 0;
2880 sc_init_emulator(scr_stat
*scp
, char *name
)
2887 if (name
== NULL
) /* if no name is given, use the current emulator */
2889 else /* ...otherwise find the named emulator */
2890 sw
= sc_term_match(name
);
2895 if (strcmp(sw
->te_renderer
, "*") != 0) {
2896 rndr
= sc_render_match(scp
, sw
->te_renderer
,
2897 scp
->status
& (GRAPHICS_MODE
| PIXEL_MODE
));
2900 rndr
= sc_render_match(scp
, scp
->sc
->adp
->va_name
,
2901 scp
->status
& (GRAPHICS_MODE
| PIXEL_MODE
));
2906 if (sw
== scp
->tsw
) {
2907 error
= (*sw
->te_init
)(scp
, &scp
->ts
, SC_TE_WARM_INIT
);
2909 scp
->rndr
->init(scp
);
2910 sc_clear_screen(scp
);
2911 /* assert(error == 0); */
2915 if (sc_malloc
&& (sw
->te_size
> 0))
2916 p
= kmalloc(sw
->te_size
, M_SYSCONS
, M_NOWAIT
);
2919 error
= (*sw
->te_init
)(scp
, &p
, SC_TE_COLD_INIT
);
2924 (*scp
->tsw
->te_term
)(scp
, &scp
->ts
);
2925 if (scp
->ts
!= NULL
)
2926 kfree(scp
->ts
, M_SYSCONS
);
2930 scp
->rndr
->init(scp
);
2933 (*sw
->te_default_attr
)(scp
, user_default
.std_color
, user_default
.rev_color
);
2934 sc_clear_screen(scp
);
2940 * scgetc(flags) - get character from keyboard.
2941 * If flags & SCGETC_CN, then avoid harmful side effects.
2942 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2943 * return NOKEY if there is nothing there.
2946 scgetc(sc_softc_t
*sc
, u_int flags
)
2949 #ifndef SC_NO_HISTORY
2957 if (sc
->kbd
== NULL
)
2962 /* I don't like this, but... XXX */
2963 if (flags
& SCGETC_CN
)
2964 sccnupdate(sc
->cur_scp
);
2967 /* first see if there is something in the keyboard port */
2969 c
= kbd_read_char(sc
->kbd
, !(flags
& SCGETC_NONBLOCK
));
2971 if (!(flags
& SCGETC_CN
))
2972 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
2973 } else if (c
== NOKEY
)
2979 /* make screensaver happy */
2981 sc_touch_scrn_saver();
2983 if (!(flags
& SCGETC_CN
))
2984 /* do the /dev/random device a favour */
2985 add_keyboard_randomness(c
);
2987 if (scp
->kbd_mode
!= K_XLATE
)
2990 /* if scroll-lock pressed allow history browsing */
2991 if (!ISGRAPHSC(scp
) && scp
->history
&& scp
->status
& SLKED
) {
2993 scp
->status
&= ~CURSOR_ENABLED
;
2994 sc_remove_cursor_image(scp
);
2996 #ifndef SC_NO_HISTORY
2997 if (!(scp
->status
& BUFFER_SAVED
)) {
2998 scp
->status
|= BUFFER_SAVED
;
3002 /* FIXME: key codes */
3003 case SPCLKEY
| FKEY
| F(49): /* home key */
3004 sc_remove_cutmarking(scp
);
3008 case SPCLKEY
| FKEY
| F(57): /* end key */
3009 sc_remove_cutmarking(scp
);
3013 case SPCLKEY
| FKEY
| F(50): /* up arrow key */
3014 sc_remove_cutmarking(scp
);
3015 if (sc_hist_up_line(scp
))
3016 if (!(flags
& SCGETC_CN
))
3017 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3020 case SPCLKEY
| FKEY
| F(58): /* down arrow key */
3021 sc_remove_cutmarking(scp
);
3022 if (sc_hist_down_line(scp
))
3023 if (!(flags
& SCGETC_CN
))
3024 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3027 case SPCLKEY
| FKEY
| F(51): /* page up key */
3028 sc_remove_cutmarking(scp
);
3029 for (i
=0; i
<scp
->ysize
; i
++)
3030 if (sc_hist_up_line(scp
)) {
3031 if (!(flags
& SCGETC_CN
))
3032 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3037 case SPCLKEY
| FKEY
| F(59): /* page down key */
3038 sc_remove_cutmarking(scp
);
3039 for (i
=0; i
<scp
->ysize
; i
++)
3040 if (sc_hist_down_line(scp
)) {
3041 if (!(flags
& SCGETC_CN
))
3042 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3047 #endif /* SC_NO_HISTORY */
3051 * Process and consume special keys here. Return a plain char code
3052 * or a char code with the META flag or a function key code.
3056 /* goto next_code */
3061 switch (KEYCHAR(c
)) {
3063 case NLK
: case CLK
: case ALK
:
3066 kbd_ioctl(sc
->kbd
, KDGKBSTATE
, (caddr_t
)&f
);
3068 scp
->status
|= SLKED
;
3070 if (scp
->status
& SLKED
) {
3071 scp
->status
&= ~SLKED
;
3072 #ifndef SC_NO_HISTORY
3073 if (scp
->status
& BUFFER_SAVED
) {
3074 if (!sc_hist_restore(scp
))
3075 sc_remove_cutmarking(scp
);
3076 scp
->status
&= ~BUFFER_SAVED
;
3077 scp
->status
|= CURSOR_ENABLED
;
3078 sc_draw_cursor_image(scp
);
3080 tp
= VIRTUAL_TTY(sc
, scp
->index
);
3088 /* NON-LOCKING KEYS */
3090 case LSH
: case RSH
: case LCTR
: case RCTR
:
3091 case LALT
: case RALT
: case ASH
: case META
:
3095 if (!(sc
->flags
& SC_SCRN_BLANKED
))
3101 /* force activatation/deactivation of the screen saver */
3102 if (!(sc
->flags
& SC_SCRN_BLANKED
)) {
3103 run_scrn_saver
= TRUE
;
3104 sc
->scrn_time_stamp
-= scrn_blank_time
;
3108 * While devices are being probed, the screen saver need
3109 * to be invoked explictly. XXX
3111 if (sc
->flags
& SC_SCRN_BLANKED
) {
3112 scsplash_stick(FALSE
);
3113 stop_scrn_saver(sc
, current_saver
);
3115 if (!ISGRAPHSC(scp
)) {
3116 scsplash_stick(TRUE
);
3117 (*current_saver
)(sc
, TRUE
);
3121 #endif /* NSPLASH */
3125 #ifndef SC_DISABLE_REBOOT
3131 #ifndef SC_DISABLE_REBOOT
3132 shutdown_nice(RB_HALT
);
3137 #ifndef SC_DISABLE_REBOOT
3138 shutdown_nice(RB_HALT
|RB_POWEROFF
);
3144 apm_suspend(PMST_SUSPEND
);
3147 apm_suspend(PMST_STANDBY
);
3156 #ifndef SC_DISABLE_DDBKEY
3158 Debugger("manual escape to debugger");
3160 kprintf("No debugger in kernel\n");
3162 #else /* SC_DISABLE_DDBKEY */
3164 #endif /* SC_DISABLE_DDBKEY */
3168 if (enable_panic_key
)
3169 panic("Forced by the panic key");
3173 this_scr
= scp
->index
;
3174 for (i
= (this_scr
- sc
->first_vty
+ 1)%sc
->vtys
;
3175 sc
->first_vty
+ i
!= this_scr
;
3176 i
= (i
+ 1)%sc
->vtys
) {
3177 struct tty
*tp
= VIRTUAL_TTY(sc
, sc
->first_vty
+ i
);
3178 if (ISTTYOPEN(tp
)) {
3179 sc_switch_scr(scp
->sc
, sc
->first_vty
+ i
);
3186 this_scr
= scp
->index
;
3187 for (i
= (this_scr
- sc
->first_vty
+ sc
->vtys
- 1)%sc
->vtys
;
3188 sc
->first_vty
+ i
!= this_scr
;
3189 i
= (i
+ sc
->vtys
- 1)%sc
->vtys
) {
3190 struct tty
*tp
= VIRTUAL_TTY(sc
, sc
->first_vty
+ i
);
3191 if (ISTTYOPEN(tp
)) {
3192 sc_switch_scr(scp
->sc
, sc
->first_vty
+ i
);
3199 if (KEYCHAR(c
) >= F_SCR
&& KEYCHAR(c
) <= L_SCR
) {
3200 sc_switch_scr(scp
->sc
, sc
->first_vty
+ KEYCHAR(c
) - F_SCR
);
3203 /* assert(c & FKEY) */
3204 if (!(sc
->flags
& SC_SCRN_BLANKED
))
3208 /* goto next_code */
3210 /* regular keys (maybe MKEY is set) */
3211 if (!(sc
->flags
& SC_SCRN_BLANKED
))
3220 scmmap(struct dev_mmap_args
*ap
)
3224 scp
= SC_STAT(ap
->a_head
.a_dev
);
3225 if (scp
!= scp
->sc
->cur_scp
)
3227 ap
->a_result
= (*vidsw
[scp
->sc
->adapter
]->mmap
)(scp
->sc
->adp
, ap
->a_offset
,
3233 save_kbd_state(scr_stat
*scp
)
3238 error
= kbd_ioctl(scp
->sc
->kbd
, KDGKBSTATE
, (caddr_t
)&state
);
3239 if (error
== ENOIOCTL
)
3242 scp
->status
&= ~LOCK_MASK
;
3243 scp
->status
|= state
;
3249 update_kbd_state(scr_stat
*scp
, int new_bits
, int mask
)
3254 if (mask
!= LOCK_MASK
) {
3255 error
= kbd_ioctl(scp
->sc
->kbd
, KDGKBSTATE
, (caddr_t
)&state
);
3256 if (error
== ENOIOCTL
)
3261 state
|= new_bits
& mask
;
3263 state
= new_bits
& LOCK_MASK
;
3265 error
= kbd_ioctl(scp
->sc
->kbd
, KDSKBSTATE
, (caddr_t
)&state
);
3266 if (error
== ENOIOCTL
)
3272 update_kbd_leds(scr_stat
*scp
, int which
)
3277 error
= kbd_ioctl(scp
->sc
->kbd
, KDSETLED
, (caddr_t
)&which
);
3278 if (error
== ENOIOCTL
)
3284 set_mode(scr_stat
*scp
)
3288 /* reject unsupported mode */
3289 if ((*vidsw
[scp
->sc
->adapter
]->get_info
)(scp
->sc
->adp
, scp
->mode
, &info
))
3292 /* if this vty is not currently showing, do nothing */
3293 if (scp
!= scp
->sc
->cur_scp
)
3296 /* setup video hardware for the given mode */
3297 (*vidsw
[scp
->sc
->adapter
]->set_mode
)(scp
->sc
->adp
, scp
->mode
);
3298 scp
->rndr
->init(scp
);
3299 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, scp
->xsize
, scp
->ysize
,
3300 (void *)scp
->sc
->adp
->va_window
, FALSE
);
3302 #ifndef SC_NO_FONT_LOADING
3303 /* load appropriate font */
3304 if (!(scp
->status
& GRAPHICS_MODE
)) {
3305 if (!(scp
->status
& PIXEL_MODE
) && ISFONTAVAIL(scp
->sc
->adp
->va_flags
)) {
3306 if (scp
->font_size
< 14) {
3307 if (scp
->sc
->fonts_loaded
& FONT_8
)
3308 sc_load_font(scp
, 0, 8, scp
->sc
->font_8
, 0, 256);
3309 } else if (scp
->font_size
>= 16) {
3310 if (scp
->sc
->fonts_loaded
& FONT_16
)
3311 sc_load_font(scp
, 0, 16, scp
->sc
->font_16
, 0, 256);
3313 if (scp
->sc
->fonts_loaded
& FONT_14
)
3314 sc_load_font(scp
, 0, 14, scp
->sc
->font_14
, 0, 256);
3318 * This is an interim kludge to display correct font.
3319 * Always use the font page #0 on the video plane 2.
3320 * Somehow we cannot show the font in other font pages on
3321 * some video cards... XXX
3323 sc_show_font(scp
, 0);
3327 #endif /* !SC_NO_FONT_LOADING */
3329 sc_set_border(scp
, scp
->border
);
3330 sc_set_cursor_image(scp
);
3336 refresh_ega_palette(scr_stat
*scp
)
3340 int rsize
, gsize
, bsize
;
3341 int rfld
, gfld
, bfld
;
3344 rsize
= scp
->sc
->adp
->va_info
.vi_pixel_fsizes
[0];
3345 gsize
= scp
->sc
->adp
->va_info
.vi_pixel_fsizes
[1];
3346 bsize
= scp
->sc
->adp
->va_info
.vi_pixel_fsizes
[2];
3347 rfld
= scp
->sc
->adp
->va_info
.vi_pixel_fields
[0];
3348 gfld
= scp
->sc
->adp
->va_info
.vi_pixel_fields
[1];
3349 bfld
= scp
->sc
->adp
->va_info
.vi_pixel_fields
[2];
3351 for (i
= 0; i
< 16; i
++) {
3352 reg
= scp
->sc
->adp
->va_palette_regs
[i
];
3354 r
= scp
->sc
->palette
[reg
* 3] >> (8 - rsize
);
3355 g
= scp
->sc
->palette
[reg
* 3 + 1] >> (8 - gsize
);
3356 b
= scp
->sc
->palette
[reg
* 3 + 2] >> (8 - bsize
);
3358 scp
->ega_palette
[i
] = (r
<< rfld
) + (g
<< gfld
) + (b
<< bfld
);
3363 sc_set_border(scr_stat
*scp
, int color
)
3365 ++scp
->sc
->videoio_in_progress
;
3366 (*scp
->rndr
->draw_border
)(scp
, color
);
3367 --scp
->sc
->videoio_in_progress
;
3370 #ifndef SC_NO_FONT_LOADING
3372 sc_load_font(scr_stat
*scp
, int page
, int size
, u_char
*buf
,
3373 int base
, int count
)
3378 sc
->font_loading_in_progress
= TRUE
;
3379 (*vidsw
[sc
->adapter
]->load_font
)(sc
->adp
, page
, size
, buf
, base
, count
);
3380 sc
->font_loading_in_progress
= FALSE
;
3384 sc_save_font(scr_stat
*scp
, int page
, int size
, u_char
*buf
,
3385 int base
, int count
)
3390 sc
->font_loading_in_progress
= TRUE
;
3391 (*vidsw
[sc
->adapter
]->save_font
)(sc
->adp
, page
, size
, buf
, base
, count
);
3392 sc
->font_loading_in_progress
= FALSE
;
3396 sc_show_font(scr_stat
*scp
, int page
)
3398 (*vidsw
[scp
->sc
->adapter
]->show_font
)(scp
->sc
->adp
, page
);
3400 #endif /* !SC_NO_FONT_LOADING */
3403 sc_paste(scr_stat
*scp
, u_char
*p
, int count
)
3408 if (scp
->status
& MOUSE_VISIBLE
) {
3409 tp
= VIRTUAL_TTY(scp
->sc
, scp
->sc
->cur_scp
->index
);
3412 rmap
= scp
->sc
->scr_rmap
;
3413 for (; count
> 0; --count
)
3414 (*linesw
[tp
->t_line
].l_rint
)(rmap
[*p
++], tp
);
3419 sc_bell(scr_stat
*scp
, int pitch
, int duration
)
3421 if (cold
|| shutdown_in_progress
)
3424 if (scp
!= scp
->sc
->cur_scp
&& (scp
->sc
->flags
& SC_QUIET_BELL
))
3427 if (scp
->sc
->flags
& SC_VISUAL_BELL
) {
3428 if (scp
->sc
->blink_in_progress
)
3430 scp
->sc
->blink_in_progress
= 3;
3431 if (scp
!= scp
->sc
->cur_scp
)
3432 scp
->sc
->blink_in_progress
+= 2;
3433 blink_screen(scp
->sc
->cur_scp
);
3434 } else if (duration
!= 0 && pitch
!= 0) {
3435 if (scp
!= scp
->sc
->cur_scp
)
3437 sysbeep(pitch
, duration
);
3442 blink_screen(void *arg
)
3444 scr_stat
*scp
= arg
;
3447 if (ISGRAPHSC(scp
) || (scp
->sc
->blink_in_progress
<= 1)) {
3448 scp
->sc
->blink_in_progress
= 0;
3450 tp
= VIRTUAL_TTY(scp
->sc
, scp
->index
);
3453 if (scp
->sc
->delayed_next_scr
)
3454 sc_switch_scr(scp
->sc
, scp
->sc
->delayed_next_scr
- 1);
3457 (*scp
->rndr
->draw
)(scp
, 0, scp
->xsize
*scp
->ysize
,
3458 scp
->sc
->blink_in_progress
& 1);
3459 scp
->sc
->blink_in_progress
--;
3460 callout_reset(&scp
->blink_screen_ch
, hz
/ 10, blink_screen
, scp
);