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.13 2004/09/19 02:11:56 dillon Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/eventhandler.h>
45 #include <sys/reboot.h>
48 #include <sys/signalvar.h>
49 #include <sys/sysctl.h>
51 #include <sys/kernel.h>
52 #include <sys/malloc.h>
54 #include <sys/random.h>
56 #include <machine/clock.h>
57 #include <machine/console.h>
58 #include <machine/psl.h>
59 #include <machine/pc/display.h>
61 #include <machine/apm_bios.h>
62 #include <machine/frame.h>
65 #include <dev/misc/kbd/kbdreg.h>
66 #include <dev/video/fb/fbreg.h>
67 #include <dev/video/fb/splashreg.h>
73 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
74 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
76 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
78 typedef struct default_attr {
79 int std_color; /* normal hardware color */
80 int rev_color; /* reverse hardware color */
83 static default_attr user_default = {
88 static default_attr kernel_default = {
90 SC_KERNEL_CONS_REV_ATTR,
93 static int sc_console_unit = -1;
94 static scr_stat *sc_console;
95 static struct tty *sc_console_tty;
96 static void *kernel_console_ts;
98 static char init_done = COLD;
99 static char shutdown_in_progress = FALSE;
100 static char sc_malloc = FALSE;
102 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
103 static int run_scrn_saver = FALSE; /* should run the saver? */
104 static long scrn_blank_time = 0; /* screen saver timeout value */
106 static int scrn_blanked; /* # of blanked screen */
107 static int sticky_splash = FALSE;
109 static void none_saver(sc_softc_t *sc, int blank) { }
110 static void (*current_saver)(sc_softc_t *, int) = none_saver;
113 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
117 d_ioctl_t *sc_user_ioctl;
119 static bios_values_t bios_value;
121 static int enable_panic_key;
122 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
125 #define SC_CONSOLECTL 255
127 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
128 SC_DEV((sc), (x))->si_tty : NULL)
129 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
134 static int scvidprobe(int unit, int flags, int cons);
135 static int sckbdprobe(int unit, int flags, int cons);
136 static void scmeminit(void *arg);
137 static int scdevtounit(dev_t dev);
138 static kbd_callback_func_t sckbdevent;
139 static int scparam(struct tty *tp, struct termios *t);
140 static void scstart(struct tty *tp);
141 static void scinit(int unit, int flags);
143 static void scterm(int unit, int flags);
145 static void scshutdown(void *arg, int howto);
146 static u_int scgetc(sc_softc_t *sc, u_int flags);
148 #define SCGETC_NONBLOCK 2
149 static int sccngetch(int flags);
150 static void sccnupdate(scr_stat *scp);
151 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
152 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
153 static timeout_t scrn_timer;
154 static int and_region(int *s1, int *e1, int s2, int e2);
155 static void scrn_update(scr_stat *scp, int show_cursor);
158 static int scsplash_callback(int event, void *arg);
159 static void scsplash_saver(sc_softc_t *sc, int show);
160 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
161 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
162 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
163 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
164 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
165 static int wait_scrn_saver_stop(sc_softc_t *sc);
166 #define scsplash_stick(stick) (sticky_splash = (stick))
168 #define scsplash_stick(stick)
171 static int do_switch_scr(sc_softc_t *sc, int s);
172 static int vt_proc_alive(scr_stat *scp);
173 static int signal_vt_rel(scr_stat *scp);
174 static int signal_vt_acq(scr_stat *scp);
175 static int finish_vt_rel(scr_stat *scp, int release, int *s);
176 static int finish_vt_acq(scr_stat *scp);
177 static void exchange_scr(sc_softc_t *sc);
178 static void update_cursor_image(scr_stat *scp);
179 static int save_kbd_state(scr_stat *scp);
180 static int update_kbd_state(scr_stat *scp, int state, int mask);
181 static int update_kbd_leds(scr_stat *scp, int which);
182 static timeout_t blink_screen;
184 #define CDEV_MAJOR 12
186 static cn_probe_t sccnprobe;
187 static cn_init_t sccninit;
188 static cn_getc_t sccngetc;
189 static cn_checkc_t sccncheckc;
190 static cn_putc_t sccnputc;
191 static cn_dbctl_t sccndbctl;
192 static cn_term_t sccnterm;
195 void sccnattach(void);
198 CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc,
201 static d_open_t scopen;
202 static d_close_t scclose;
203 static d_read_t scread;
204 static d_ioctl_t scioctl;
205 static d_mmap_t scmmap;
207 static struct cdevsw sc_cdevsw = {
209 /* maj */ CDEV_MAJOR,
210 /* flags */ D_TTY | D_KQFILTER,
217 /* write */ ttywrite,
221 /* strategy */ nostrategy,
224 /* kqfilter */ ttykqfilter
228 sc_probe_unit(int unit, int flags)
230 if (!scvidprobe(unit, flags, FALSE)) {
232 printf("sc%d: no video adapter found.\n", unit);
236 /* syscons will be attached even when there is no keyboard */
237 sckbdprobe(unit, flags, FALSE);
242 /* probe video adapters, return TRUE if found */
244 scvidprobe(int unit, int flags, int cons)
247 * Access the video adapter driver through the back door!
248 * Video adapter drivers need to be configured before syscons.
249 * However, when syscons is being probed as the low-level console,
250 * they have not been initialized yet. We force them to initialize
251 * themselves here. XXX
253 vid_configure(cons ? VIO_PROBE_ONLY : 0);
255 return (vid_find_adapter("*", unit) >= 0);
258 /* probe the keyboard, return TRUE if found */
260 sckbdprobe(int unit, int flags, int cons)
262 /* access the keyboard driver through the backdoor! */
263 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
265 return (kbd_find_keyboard("*", unit) >= 0);
269 *adapter_name(video_adapter_t *adp)
275 { KD_MONO, { "MDA", "MDA" } },
276 { KD_HERCULES, { "Hercules", "Hercules" } },
277 { KD_CGA, { "CGA", "CGA" } },
278 { KD_EGA, { "EGA", "EGA (mono)" } },
279 { KD_VGA, { "VGA", "VGA (mono)" } },
280 { KD_PC98, { "PC-98x1", "PC-98x1" } },
281 { KD_TGA, { "TGA", "TGA" } },
282 { -1, { "Unknown", "Unknown" } },
286 for (i = 0; names[i].type != -1; ++i)
287 if (names[i].type == adp->va_type)
289 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
293 sc_attach_unit(int unit, int flags)
303 flags &= ~SC_KERNEL_CONSOLE;
305 if (sc_console_unit == unit) {
307 * If this unit is being used as the system console, we need to
308 * adjust some variables and buffers before and after scinit().
310 /* assert(sc_console != NULL) */
311 flags |= SC_KERNEL_CONSOLE;
316 if (sc_console->tsw->te_size > 0) {
317 /* assert(sc_console->ts != NULL); */
318 kernel_console_ts = sc_console->ts;
319 sc_console->ts = malloc(sc_console->tsw->te_size,
321 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
322 (*sc_console->tsw->te_default_attr)(sc_console,
323 user_default.std_color,
324 user_default.rev_color);
330 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
332 callout_init(&sc->scrn_timer_ch);
333 scp = SC_STAT(sc->dev[0]);
334 if (sc_console == NULL) /* sc_console_unit < 0 */
338 if ((sc->config & SC_VESA800X600)
339 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
341 if (sc->flags & SC_SPLASH_SCRN)
342 splash_term(sc->adp);
344 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
345 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
346 sc->initial_mode = M_VESA_800x600;
348 /* put up the splash again! */
349 if (sc->flags & SC_SPLASH_SCRN)
350 splash_init(sc->adp, scsplash_callback, sc);
353 #endif /* SC_PIXEL_MODE */
355 /* initialize cursor */
357 update_cursor_image(scp);
359 /* get screen update going */
362 /* set up the keyboard */
363 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
364 update_kbd_state(scp, scp->status, LOCK_MASK);
366 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
367 unit, adapter_name(sc->adp), sc->vtys, sc->config);
369 printf("sc%d:", unit);
370 if (sc->adapter >= 0)
371 printf(" fb%d", sc->adapter);
372 if (sc->keyboard >= 0)
373 printf(", kbd%d", sc->keyboard);
375 printf(", terminal emulator: %s (%s)",
376 scp->tsw->te_name, scp->tsw->te_desc);
380 /* register a shutdown callback for the kernel console */
381 if (sc_console_unit == unit)
382 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
383 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
386 * create devices. cdevsw_add() must be called to make devices under
387 * this major number available to userland.
389 cdevsw_add(&sc_cdevsw, ~(MAXCONS - 1), unit * MAXCONS);
391 for (vc = 0; vc < sc->vtys; vc++) {
392 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
393 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
396 * The first vty already has struct tty and scr_stat initialized
397 * in scinit(). The other vtys will have these structs when
402 cdevsw_add(&sc_cdevsw, -1, SC_CONSOLECTL); /* XXX */
403 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
404 UID_ROOT, GID_WHEEL, 0600, "consolectl");
405 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
406 SC_STAT(dev) = sc_console;
419 * As soon as malloc() becomes functional, we had better allocate
420 * various buffers for the kernel console.
423 if (sc_console_unit < 0) /* sc_console == NULL */
426 /* copy the temporary buffer to the final buffer */
427 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
429 #ifndef SC_NO_CUTPASTE
430 sc_alloc_cut_buffer(sc_console, TRUE);
433 #ifndef SC_NO_HISTORY
434 /* initialize history buffer & pointers */
435 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
440 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
443 scdevtounit(dev_t dev)
445 int vty = SC_VTY(dev);
447 if (vty == SC_CONSOLECTL)
448 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
449 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
456 scopen(dev_t dev, int flag, int mode, struct thread *td)
458 int unit = scdevtounit(dev);
465 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
466 major(dev), minor(dev), unit, SC_VTY(dev)));
468 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
472 tp = dev->si_tty = ttymalloc(dev->si_tty);
473 tp->t_oproc = scstart;
474 tp->t_param = scparam;
475 tp->t_stop = nottystop;
477 if (!ISTTYOPEN(tp)) {
479 /* Use the current setting of the <-- key as default VERASE. */
480 /* If the Delete key is preferable, an stty is necessary */
481 if (sc->kbd != NULL) {
482 key.keynum = KEYCODE_BS;
483 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
484 tp->t_cc[VERASE] = key.key.map[0];
486 tp->t_iflag = TTYDEF_IFLAG;
487 tp->t_oflag = TTYDEF_OFLAG;
488 tp->t_cflag = TTYDEF_CFLAG;
489 tp->t_lflag = TTYDEF_LFLAG;
490 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
491 scparam(tp, &tp->t_termios);
492 (*linesw[tp->t_line].l_modem)(tp, 1);
495 if (tp->t_state & TS_XCLUDE && suser(td))
498 error = (*linesw[tp->t_line].l_open)(dev, tp);
502 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
504 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
506 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
507 tp->t_winsize.ws_col = scp->xsize;
508 tp->t_winsize.ws_row = scp->ysize;
515 scclose(dev_t dev, int flag, int mode, struct thread *td)
517 struct tty *tp = dev->si_tty;
521 if (SC_VTY(dev) != SC_CONSOLECTL) {
522 scp = SC_STAT(tp->t_dev);
523 /* were we in the middle of the VT switching process? */
524 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
526 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
527 cons_unavail = FALSE;
528 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
529 DPRINTF(5, ("reset WAIT_REL, "));
530 if (finish_vt_acq(scp) == 0) /* force acknowledge */
531 DPRINTF(5, ("reset WAIT_ACQ, "));
533 if (scp == &main_console) {
536 scp->smode.mode = VT_AUTO;
539 sc_vtb_destroy(&scp->vtb);
540 sc_vtb_destroy(&scp->scr);
541 sc_free_history_buffer(scp, scp->ysize);
548 scp->smode.mode = VT_AUTO;
550 scp->kbd_mode = K_XLATE;
551 if (scp == scp->sc->cur_scp)
552 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
553 DPRINTF(5, ("done.\n"));
556 (*linesw[tp->t_line].l_close)(tp, flag);
563 scread(dev_t dev, struct uio *uio, int flag)
565 sc_touch_scrn_saver();
566 return ttyread(dev, uio, flag);
570 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
578 sc = (sc_softc_t *)arg;
579 /* assert(thiskbd == sc->kbd) */
584 case KBDIO_UNLOADING:
587 kbd_release(thiskbd, (void *)&sc->keyboard);
594 * Loop while there is still input to get from the keyboard.
595 * I don't think this is nessesary, and it doesn't fix
596 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
598 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
600 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
601 if (!ISTTYOPEN(cur_tty)) {
602 cur_tty = sc_console_tty;
603 if (!ISTTYOPEN(cur_tty))
607 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
610 switch (KEYFLAGS(c)) {
611 case 0x0000: /* normal key */
612 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
614 case FKEY: /* function key, return string */
615 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
618 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
621 case MKEY: /* meta is active, prepend ESC */
622 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
623 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
625 case BKEY: /* backtab fixed sequence (esc [ Z) */
626 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
627 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
628 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
633 sc->cur_scp->status |= MOUSE_HIDDEN;
639 scparam(struct tty *tp, struct termios *t)
641 tp->t_ispeed = t->c_ispeed;
642 tp->t_ospeed = t->c_ospeed;
643 tp->t_cflag = t->c_cflag;
648 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
656 struct proc *p = td->td_proc;
662 /* If there is a user_ioctl function call that first */
664 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
665 if (error != ENOIOCTL)
669 error = sc_vid_ioctl(tp, cmd, data, flag, td);
670 if (error != ENOIOCTL)
673 #ifndef SC_NO_HISTORY
674 error = sc_hist_ioctl(tp, cmd, data, flag, td);
675 if (error != ENOIOCTL)
679 #ifndef SC_NO_SYSMOUSE
680 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
681 if (error != ENOIOCTL)
685 scp = SC_STAT(tp->t_dev);
686 /* assert(scp != NULL) */
687 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
691 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
692 if (error != ENOIOCTL)
696 switch (cmd) { /* process console hardware related ioctl's */
698 case GIO_ATTR: /* get current attributes */
699 /* this ioctl is not processed here, but in the terminal emulator */
702 case GIO_COLOR: /* is this a color console ? */
703 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
706 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
707 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
710 scrn_blank_time = *(int *)data;
711 run_scrn_saver = (scrn_blank_time != 0);
715 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
717 if (!ISGRAPHSC(sc->cur_scp))
718 sc_remove_cursor_image(sc->cur_scp);
719 if ((*(int*)data) & 0x01)
720 sc->flags |= SC_BLINK_CURSOR;
722 sc->flags &= ~SC_BLINK_CURSOR;
723 if ((*(int*)data) & 0x02) {
724 sc->flags |= SC_CHAR_CURSOR;
726 sc->flags &= ~SC_CHAR_CURSOR;
728 * The cursor shape is global property; all virtual consoles
729 * are affected. Update the cursor in the current console...
731 if (!ISGRAPHSC(sc->cur_scp)) {
732 sc_set_cursor_image(sc->cur_scp);
733 sc_draw_cursor_image(sc->cur_scp);
738 case CONS_BELLTYPE: /* set bell type sound/visual */
739 if ((*(int *)data) & 0x01)
740 sc->flags |= SC_VISUAL_BELL;
742 sc->flags &= ~SC_VISUAL_BELL;
743 if ((*(int *)data) & 0x02)
744 sc->flags |= SC_QUIET_BELL;
746 sc->flags &= ~SC_QUIET_BELL;
749 case CONS_GETINFO: /* get current (virtual) console info */
751 vid_info_t *ptr = (vid_info_t*)data;
752 if (ptr->size == sizeof(struct vid_info)) {
753 ptr->m_num = sc->cur_scp->index;
754 ptr->font_size = scp->font_size;
755 ptr->mv_col = scp->xpos;
756 ptr->mv_row = scp->ypos;
757 ptr->mv_csz = scp->xsize;
758 ptr->mv_rsz = scp->ysize;
760 * The following fields are filled by the terminal emulator. XXX
767 ptr->mv_grfc.fore = 0; /* not supported */
768 ptr->mv_grfc.back = 0; /* not supported */
769 ptr->mv_ovscan = scp->border;
770 if (scp == sc->cur_scp)
772 ptr->mk_keylock = scp->status & LOCK_MASK;
778 case CONS_GETVERS: /* get version number */
779 *(int*)data = 0x200; /* version 2.0 */
782 case CONS_IDLE: /* see if the screen has been idle */
784 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
785 * the user process may have been writing something on the
786 * screen and syscons is not aware of it. Declare the screen
787 * is NOT idle if it is in one of these modes. But there is
788 * an exception to it; if a screen saver is running in the
789 * graphics mode in the current screen, we should say that the
790 * screen has been idle.
792 *(int *)data = (sc->flags & SC_SCRN_IDLE)
793 && (!ISGRAPHSC(sc->cur_scp)
794 || (sc->cur_scp->status & SAVER_RUNNING));
797 case CONS_SAVERMODE: /* set saver mode */
798 switch(*(int *)data) {
801 /* if a LKM screen saver is running, stop it first. */
802 scsplash_stick(FALSE);
803 saver_mode = *(int *)data;
806 if ((error = wait_scrn_saver_stop(NULL))) {
811 run_scrn_saver = TRUE;
812 if (saver_mode == CONS_USR_SAVER)
813 scp->status |= SAVER_RUNNING;
815 scp->status &= ~SAVER_RUNNING;
816 scsplash_stick(TRUE);
821 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
822 scp->status &= ~SAVER_RUNNING;
823 saver_mode = *(int *)data;
831 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
833 * Note that this ioctl does not guarantee the screen saver
834 * actually starts or stops. It merely attempts to do so...
837 run_scrn_saver = (*(int *)data != 0);
839 sc->scrn_time_stamp -= scrn_blank_time;
843 case CONS_SCRSHOT: /* get a screen shot */
845 scrshot_t *ptr = (scrshot_t*)data;
847 if (ISGRAPHSC(scp)) {
851 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
855 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
856 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
861 case VT_SETMODE: /* set screen switcher mode */
863 struct vt_mode *mode;
865 mode = (struct vt_mode *)data;
866 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
867 if (scp->smode.mode == VT_PROCESS) {
868 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
869 DPRINTF(5, ("error EPERM\n"));
874 if (mode->mode == VT_AUTO) {
875 scp->smode.mode = VT_AUTO;
878 DPRINTF(5, ("VT_AUTO, "));
879 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
880 cons_unavail = FALSE;
881 /* were we in the middle of the vty switching process? */
882 if (finish_vt_rel(scp, TRUE, &s) == 0)
883 DPRINTF(5, ("reset WAIT_REL, "));
884 if (finish_vt_acq(scp) == 0)
885 DPRINTF(5, ("reset WAIT_ACQ, "));
887 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
888 || !ISSIGVALID(mode->frsig)) {
890 DPRINTF(5, ("error EINVAL\n"));
893 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
894 bcopy(data, &scp->smode, sizeof(struct vt_mode));
896 scp->pid = scp->proc->p_pid;
897 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
905 case VT_GETMODE: /* get screen switcher mode */
906 bcopy(&scp->smode, data, sizeof(struct vt_mode));
909 case VT_RELDISP: /* screen switcher ioctl */
912 * This must be the current vty which is in the VT_PROCESS
915 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
919 /* ...and this process is controlling it. */
920 if (scp->proc != p) {
925 switch(*(int *)data) {
926 case VT_FALSE: /* user refuses to release screen, abort */
927 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
928 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
930 case VT_TRUE: /* user has released screen, go on */
931 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
932 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
934 case VT_ACKACQ: /* acquire acknowledged, switch completed */
935 if ((error = finish_vt_acq(scp)) == 0)
936 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
944 case VT_OPENQRY: /* return free virtual console */
945 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
946 tp = VIRTUAL_TTY(sc, i);
947 if (!ISTTYOPEN(tp)) {
948 *(int *)data = i + 1;
954 case VT_ACTIVATE: /* switch to screen *data */
955 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
957 sc_clean_up(sc->cur_scp);
959 return sc_switch_scr(sc, i);
961 case VT_WAITACTIVE: /* wait for switch to occur */
962 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
963 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
966 error = sc_clean_up(sc->cur_scp);
970 scp = SC_STAT(SC_DEV(sc, i));
971 if (scp == scp->sc->cur_scp)
973 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
974 "waitvt", 0)) == ERESTART) ;
977 case VT_GETACTIVE: /* get active vty # */
978 *(int *)data = sc->cur_scp->index + 1;
981 case VT_GETINDEX: /* get this vty # */
982 *(int *)data = scp->index + 1;
985 case VT_LOCKSWITCH: /* prevent vty switching */
986 if ((*(int *)data) & 0x01)
987 sc->flags |= SC_SCRN_VTYLOCK;
989 sc->flags &= ~SC_SCRN_VTYLOCK;
992 case KDENABIO: /* allow io operations */
999 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
1003 case KDDISABIO: /* disallow io operations (default) */
1005 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
1009 case KDSKBSTATE: /* set keyboard state (locks) */
1010 if (*(int *)data & ~LOCK_MASK)
1012 scp->status &= ~LOCK_MASK;
1013 scp->status |= *(int *)data;
1014 if (scp == sc->cur_scp)
1015 update_kbd_state(scp, scp->status, LOCK_MASK);
1018 case KDGKBSTATE: /* get keyboard state (locks) */
1019 if (scp == sc->cur_scp)
1020 save_kbd_state(scp);
1021 *(int *)data = scp->status & LOCK_MASK;
1024 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1025 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1026 error = kbd_ioctl(sc->kbd, cmd, data);
1027 if (error == ENOIOCTL)
1031 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1032 if (*(int *)data & ~0x7f)
1034 error = kbd_ioctl(sc->kbd, cmd, data);
1035 if (error == ENOIOCTL)
1039 case KDSKBMODE: /* set keyboard mode */
1040 switch (*(int *)data) {
1041 case K_XLATE: /* switch to XLT ascii mode */
1042 case K_RAW: /* switch to RAW scancode mode */
1043 case K_CODE: /* switch to CODE mode */
1044 scp->kbd_mode = *(int *)data;
1045 if (scp == sc->cur_scp)
1046 kbd_ioctl(sc->kbd, cmd, data);
1053 case KDGKBMODE: /* get keyboard mode */
1054 *(int *)data = scp->kbd_mode;
1058 error = kbd_ioctl(sc->kbd, cmd, data);
1059 if (error == ENOIOCTL)
1063 case KDMKTONE: /* sound the bell */
1065 sc_bell(scp, (*(int*)data)&0xffff,
1066 (((*(int*)data)>>16)&0xffff)*hz/1000);
1068 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1071 case KIOCSOUND: /* make tone (*data) hz */
1072 if (scp == sc->cur_scp) {
1074 return sc_tone(*(int *)data);
1080 case KDGKBTYPE: /* get keyboard type */
1081 error = kbd_ioctl(sc->kbd, cmd, data);
1082 if (error == ENOIOCTL) {
1083 /* always return something? XXX */
1088 case KDSETLED: /* set keyboard LED status */
1089 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1091 scp->status &= ~LED_MASK;
1092 scp->status |= *(int *)data;
1093 if (scp == sc->cur_scp)
1094 update_kbd_leds(scp, scp->status);
1097 case KDGETLED: /* get keyboard LED status */
1098 if (scp == sc->cur_scp)
1099 save_kbd_state(scp);
1100 *(int *)data = scp->status & LED_MASK;
1103 case CONS_SETKBD: /* set the new keyboard */
1108 newkbd = kbd_get_keyboard(*(int *)data);
1109 if (newkbd == NULL) {
1114 if (sc->kbd != newkbd) {
1115 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1116 (void *)&sc->keyboard, sckbdevent, sc);
1117 /* i == newkbd->kb_index */
1119 if (sc->kbd != NULL) {
1120 save_kbd_state(sc->cur_scp);
1121 kbd_release(sc->kbd, (void *)&sc->keyboard);
1123 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1125 kbd_ioctl(sc->kbd, KDSKBMODE,
1126 (caddr_t)&sc->cur_scp->kbd_mode);
1127 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1130 error = EPERM; /* XXX */
1137 case CONS_RELKBD: /* release the current keyboard */
1140 if (sc->kbd != NULL) {
1141 save_kbd_state(sc->cur_scp);
1142 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1151 case CONS_GETTERM: /* get the current terminal emulator info */
1155 if (((term_info_t *)data)->ti_index == 0) {
1158 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1161 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1162 sizeof(((term_info_t *)data)->ti_name));
1163 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1164 sizeof(((term_info_t *)data)->ti_desc));
1165 ((term_info_t *)data)->ti_flags = 0;
1168 ((term_info_t *)data)->ti_name[0] = '\0';
1169 ((term_info_t *)data)->ti_desc[0] = '\0';
1170 ((term_info_t *)data)->ti_flags = 0;
1175 case CONS_SETTERM: /* set the current terminal emulator */
1177 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1178 /* FIXME: what if scp == sc_console! XXX */
1182 case GIO_SCRNMAP: /* get output translation table */
1183 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1186 case PIO_SCRNMAP: /* set output translation table */
1187 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1188 for (i=0; i<sizeof(sc->scr_map); i++) {
1189 sc->scr_rmap[sc->scr_map[i]] = i;
1193 case GIO_KEYMAP: /* get keyboard translation table */
1194 case PIO_KEYMAP: /* set keyboard translation table */
1195 case GIO_DEADKEYMAP: /* get accent key translation table */
1196 case PIO_DEADKEYMAP: /* set accent key translation table */
1197 case GETFKEY: /* get function key string */
1198 case SETFKEY: /* set function key string */
1199 error = kbd_ioctl(sc->kbd, cmd, data);
1200 if (error == ENOIOCTL)
1204 #ifndef SC_NO_FONT_LOADING
1206 case PIO_FONT8x8: /* set 8x8 dot font */
1207 if (!ISFONTAVAIL(sc->adp->va_flags))
1209 bcopy(data, sc->font_8, 8*256);
1210 sc->fonts_loaded |= FONT_8;
1213 * Always use the font page #0. XXX
1214 * Don't load if the current font size is not 8x8.
1216 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1217 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1220 case GIO_FONT8x8: /* get 8x8 dot font */
1221 if (!ISFONTAVAIL(sc->adp->va_flags))
1223 if (sc->fonts_loaded & FONT_8) {
1224 bcopy(sc->font_8, data, 8*256);
1230 case PIO_FONT8x14: /* set 8x14 dot font */
1231 if (!ISFONTAVAIL(sc->adp->va_flags))
1233 bcopy(data, sc->font_14, 14*256);
1234 sc->fonts_loaded |= FONT_14;
1237 * Always use the font page #0. XXX
1238 * Don't load if the current font size is not 8x14.
1240 if (ISTEXTSC(sc->cur_scp)
1241 && (sc->cur_scp->font_size >= 14)
1242 && (sc->cur_scp->font_size < 16))
1243 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1246 case GIO_FONT8x14: /* get 8x14 dot font */
1247 if (!ISFONTAVAIL(sc->adp->va_flags))
1249 if (sc->fonts_loaded & FONT_14) {
1250 bcopy(sc->font_14, data, 14*256);
1256 case PIO_FONT8x16: /* set 8x16 dot font */
1257 if (!ISFONTAVAIL(sc->adp->va_flags))
1259 bcopy(data, sc->font_16, 16*256);
1260 sc->fonts_loaded |= FONT_16;
1263 * Always use the font page #0. XXX
1264 * Don't load if the current font size is not 8x16.
1266 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1267 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1270 case GIO_FONT8x16: /* get 8x16 dot font */
1271 if (!ISFONTAVAIL(sc->adp->va_flags))
1273 if (sc->fonts_loaded & FONT_16) {
1274 bcopy(sc->font_16, data, 16*256);
1280 #endif /* SC_NO_FONT_LOADING */
1286 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1287 if (error != ENOIOCTL)
1289 error = ttioctl(tp, cmd, data, flag);
1290 if (error != ENOIOCTL)
1296 scstart(struct tty *tp)
1300 u_char buf[PCBURST];
1301 scr_stat *scp = SC_STAT(tp->t_dev);
1303 if (scp->status & SLKED ||
1304 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1307 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1308 tp->t_state |= TS_BUSY;
1311 len = q_to_b(rbp, buf, PCBURST);
1313 sc_puts(scp, buf, len);
1316 tp->t_state &= ~TS_BUSY;
1323 sccnprobe(struct consdev *cp)
1329 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1331 /* a video card is always required */
1332 if (!scvidprobe(unit, flags, TRUE))
1333 cp->cn_pri = CN_DEAD;
1335 /* syscons will become console even when there is no keyboard */
1336 sckbdprobe(unit, flags, TRUE);
1338 if (cp->cn_pri == CN_DEAD)
1341 /* initialize required fields */
1342 cp->cn_dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
1343 UID_ROOT, GID_WHEEL, 0600, "consolectl");
1344 #endif /* __i386__ */
1348 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm()
1349 * interface to install the console. Always return CN_DEAD from
1352 cp->cn_pri = CN_DEAD;
1353 #endif /* __alpha__ */
1357 sccninit(struct consdev *cp)
1363 sc_get_cons_priority(&unit, &flags);
1364 scinit(unit, flags | SC_KERNEL_CONSOLE);
1365 sc_console_unit = unit;
1366 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1367 #endif /* __i386__ */
1370 /* SHOULDN'T REACH HERE */
1371 #endif /* __alpha__ */
1375 sccnterm(struct consdev *cp)
1377 /* we are not the kernel console any more, release everything */
1379 if (sc_console_unit < 0)
1380 return; /* shouldn't happen */
1384 sc_clear_screen(sc_console);
1385 sccnupdate(sc_console);
1387 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1388 sc_console_unit = -1;
1390 #endif /* __i386__ */
1393 /* do nothing XXX */
1394 #endif /* __alpha__ */
1402 static struct consdev consdev;
1406 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev));
1407 consdev.cn_pri = sc_get_cons_priority(&unit, &flags);
1409 /* a video card is always required */
1410 if (!scvidprobe(unit, flags, TRUE))
1411 consdev.cn_pri = CN_DEAD;
1413 /* alpha doesn't allow the console being without a keyboard... Why? */
1414 if (!sckbdprobe(unit, flags, TRUE))
1415 consdev.cn_pri = CN_DEAD;
1417 if (consdev.cn_pri == CN_DEAD)
1420 scinit(unit, flags | SC_KERNEL_CONSOLE);
1421 sc_console_unit = unit;
1422 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1423 consdev.cn_dev = make_dev(&sc_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
1428 #endif /* __alpha__ */
1431 sccnputc(dev_t dev, int c)
1434 scr_stat *scp = sc_console;
1436 #ifndef SC_NO_HISTORY
1438 #endif /* !SC_NO_HISTORY */
1441 /* assert(sc_console != NULL) */
1443 #ifndef SC_NO_HISTORY
1444 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1445 scp->status &= ~SLKED;
1446 update_kbd_state(scp, scp->status, SLKED);
1447 if (scp->status & BUFFER_SAVED) {
1448 if (!sc_hist_restore(scp))
1449 sc_remove_cutmarking(scp);
1450 scp->status &= ~BUFFER_SAVED;
1451 scp->status |= CURSOR_ENABLED;
1452 sc_draw_cursor_image(scp);
1454 tp = VIRTUAL_TTY(scp->sc, scp->index);
1458 #endif /* !SC_NO_HISTORY */
1461 if (kernel_console_ts != NULL)
1462 scp->ts = kernel_console_ts;
1464 sc_puts(scp, buf, 1);
1467 s = spltty(); /* block sckbdevent and scrn_timer */
1475 return sccngetch(0);
1479 sccncheckc(dev_t dev)
1481 return sccngetch(SCGETC_NONBLOCK);
1485 sccndbctl(dev_t dev, int on)
1487 /* assert(sc_console_unit >= 0) */
1488 /* try to switch to the kernel console screen */
1489 if (on && debugger == 0) {
1491 * TRY to make sure the screen saver is stopped,
1492 * and the screen is updated before switching to
1497 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1498 && sc_console->smode.mode == VT_AUTO) {
1499 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1500 sc_switch_scr(sc_console->sc, sc_console->index);
1510 sccngetch(int flags)
1512 static struct fkeytab fkey;
1517 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1520 /* assert(sc_console != NULL) */
1523 * Stop the screen saver and update the screen if necessary.
1524 * What if we have been running in the screen saver code... XXX
1526 sc_touch_scrn_saver();
1527 scp = sc_console->sc->cur_scp; /* XXX */
1530 if (fkeycp < fkey.len) {
1532 return fkey.str[fkeycp++];
1535 if (scp->sc->kbd == NULL) {
1541 * Make sure the keyboard is accessible even when the kbd device
1542 * driver is disabled.
1544 kbd_enable(scp->sc->kbd);
1546 /* we shall always use the keyboard in the XLATE mode here */
1547 cur_mode = scp->kbd_mode;
1548 scp->kbd_mode = K_XLATE;
1549 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1551 kbd_poll(scp->sc->kbd, TRUE);
1552 c = scgetc(scp->sc, SCGETC_CN | flags);
1553 kbd_poll(scp->sc->kbd, FALSE);
1555 scp->kbd_mode = cur_mode;
1556 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1557 kbd_disable(scp->sc->kbd);
1560 switch (KEYFLAGS(c)) {
1561 case 0: /* normal char */
1563 case FKEY: /* function key */
1564 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1566 if ((p != NULL) && (fkey.len > 0)) {
1567 bcopy(p, fkey.str, fkey.len);
1581 sccnupdate(scr_stat *scp)
1583 /* this is a cut-down version of scrn_timer()... */
1585 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1588 if (debugger > 0 || panicstr || shutdown_in_progress) {
1589 sc_touch_scrn_saver();
1590 } else if (scp != scp->sc->cur_scp) {
1594 if (!run_scrn_saver)
1595 scp->sc->flags &= ~SC_SCRN_IDLE;
1597 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1598 if (scp->sc->flags & SC_SCRN_BLANKED)
1599 stop_scrn_saver(scp->sc, current_saver);
1600 #endif /* NSPLASH */
1602 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1603 || scp->sc->switch_in_progress)
1606 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1607 * when write_in_progress is non-zero. XXX
1610 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1611 scrn_update(scp, TRUE);
1615 scrn_timer(void *arg)
1617 static int kbd_interval = 0;
1624 again = (arg != NULL);
1626 sc = (sc_softc_t *)arg;
1627 else if (sc_console != NULL)
1628 sc = sc_console->sc;
1632 /* don't do anything when we are performing some I/O operations */
1633 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1635 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1640 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1641 /* try to allocate a keyboard automatically */
1642 if (++kbd_interval >= 25) {
1643 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1645 if (sc->keyboard >= 0) {
1646 sc->kbd = kbd_get_keyboard(sc->keyboard);
1647 kbd_ioctl(sc->kbd, KDSKBMODE,
1648 (caddr_t)&sc->cur_scp->kbd_mode);
1649 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1656 /* find the vty to update */
1659 /* should we stop the screen saver? */
1660 getmicrouptime(&tv);
1661 if (debugger > 0 || panicstr || shutdown_in_progress)
1662 sc_touch_scrn_saver();
1663 if (run_scrn_saver) {
1664 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1665 sc->flags |= SC_SCRN_IDLE;
1667 sc->flags &= ~SC_SCRN_IDLE;
1669 sc->scrn_time_stamp = tv.tv_sec;
1670 sc->flags &= ~SC_SCRN_IDLE;
1671 if (scrn_blank_time > 0)
1672 run_scrn_saver = TRUE;
1675 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1676 if (sc->flags & SC_SCRN_BLANKED)
1677 stop_scrn_saver(sc, current_saver);
1678 #endif /* NSPLASH */
1680 /* should we just return ? */
1681 if (sc->blink_in_progress || sc->switch_in_progress
1682 || sc->write_in_progress) {
1684 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1689 /* Update the screen */
1690 scp = sc->cur_scp; /* cur_scp may have changed... */
1691 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1692 scrn_update(scp, TRUE);
1695 /* should we activate the screen saver? */
1696 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1697 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1698 (*current_saver)(sc, TRUE);
1699 #endif /* NSPLASH */
1702 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1707 and_region(int *s1, int *e1, int s2, int e2)
1709 if (*e1 < s2 || e2 < *s1)
1711 *s1 = imax(*s1, s2);
1712 *e1 = imin(*e1, e2);
1717 scrn_update(scr_stat *scp, int show_cursor)
1724 /* assert(scp == scp->sc->cur_scp) */
1726 ++scp->sc->videoio_in_progress;
1728 #ifndef SC_NO_CUTPASTE
1729 /* remove the previous mouse pointer image if necessary */
1730 if (scp->status & MOUSE_VISIBLE) {
1732 e = scp->mouse_pos + scp->xsize + 1;
1733 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1734 || and_region(&s, &e, scp->start, scp->end)
1735 || ((scp->status & CURSOR_ENABLED) &&
1736 (scp->cursor_pos != scp->cursor_oldpos) &&
1737 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1738 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1739 sc_remove_mouse_image(scp);
1740 if (scp->end >= scp->xsize*scp->ysize)
1741 scp->end = scp->xsize*scp->ysize - 1;
1744 #endif /* !SC_NO_CUTPASTE */
1748 if (scp->end >= scp->xsize*scp->ysize) {
1749 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1750 scp->end = scp->xsize*scp->ysize - 1;
1752 if (scp->start < 0) {
1753 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1758 /* update screen image */
1759 if (scp->start <= scp->end) {
1760 if (scp->mouse_cut_end >= 0) {
1761 /* there is a marked region for cut & paste */
1762 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1763 start = scp->mouse_cut_start;
1764 end = scp->mouse_cut_end;
1766 start = scp->mouse_cut_end;
1767 end = scp->mouse_cut_start - 1;
1771 /* does the cut-mark region overlap with the update region? */
1772 if (and_region(&s, &e, scp->start, scp->end)) {
1773 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1776 if (and_region(&s, &e, scp->start, scp->end))
1777 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1779 e = scp->xsize*scp->ysize - 1;
1780 if (and_region(&s, &e, scp->start, scp->end))
1781 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1783 (*scp->rndr->draw)(scp, scp->start,
1784 scp->end - scp->start + 1, FALSE);
1787 (*scp->rndr->draw)(scp, scp->start,
1788 scp->end - scp->start + 1, FALSE);
1792 /* we are not to show the cursor and the mouse pointer... */
1795 scp->start = scp->xsize*scp->ysize - 1;
1796 --scp->sc->videoio_in_progress;
1800 /* update cursor image */
1801 if (scp->status & CURSOR_ENABLED) {
1804 /* did cursor move since last time ? */
1805 if (scp->cursor_pos != scp->cursor_oldpos) {
1806 /* do we need to remove old cursor image ? */
1807 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1808 sc_remove_cursor_image(scp);
1809 sc_draw_cursor_image(scp);
1811 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1812 /* cursor didn't move, but has been overwritten */
1813 sc_draw_cursor_image(scp);
1814 else if (scp->sc->flags & SC_BLINK_CURSOR)
1815 /* if it's a blinking cursor, update it */
1816 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1817 sc_inside_cutmark(scp,
1822 #ifndef SC_NO_CUTPASTE
1823 /* update "pseudo" mouse pointer image */
1824 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1825 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1826 scp->status &= ~MOUSE_MOVED;
1827 sc_draw_mouse_image(scp);
1830 #endif /* SC_NO_CUTPASTE */
1833 scp->start = scp->xsize*scp->ysize - 1;
1835 --scp->sc->videoio_in_progress;
1840 scsplash_callback(int event, void *arg)
1845 sc = (sc_softc_t *)arg;
1849 if (add_scrn_saver(scsplash_saver) == 0) {
1850 sc->flags &= ~SC_SAVER_FAILED;
1851 run_scrn_saver = TRUE;
1852 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1853 scsplash_stick(TRUE);
1854 (*current_saver)(sc, TRUE);
1860 if (current_saver == scsplash_saver) {
1861 scsplash_stick(FALSE);
1862 error = remove_scrn_saver(scsplash_saver);
1874 scsplash_saver(sc_softc_t *sc, int show)
1876 static int busy = FALSE;
1885 if (!(sc->flags & SC_SAVER_FAILED)) {
1886 if (!(sc->flags & SC_SCRN_BLANKED))
1887 set_scrn_saver_mode(scp, -1, NULL, 0);
1888 switch (splash(sc->adp, TRUE)) {
1889 case 0: /* succeeded */
1891 case EAGAIN: /* try later */
1892 restore_scrn_saver_mode(scp, FALSE);
1893 sc_touch_scrn_saver(); /* XXX */
1896 sc->flags |= SC_SAVER_FAILED;
1897 scsplash_stick(FALSE);
1898 restore_scrn_saver_mode(scp, TRUE);
1899 printf("scsplash_saver(): failed to put up the image\n");
1903 } else if (!sticky_splash) {
1904 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1905 restore_scrn_saver_mode(scp, TRUE);
1911 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1916 if (current_saver != none_saver) {
1917 error = remove_scrn_saver(current_saver);
1922 if (current_saver != none_saver)
1925 run_scrn_saver = FALSE;
1926 saver_mode = CONS_LKM_SAVER;
1927 current_saver = this_saver;
1932 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1934 if (current_saver != this_saver)
1939 * In order to prevent `current_saver' from being called by
1940 * the timeout routine `scrn_timer()' while we manipulate
1941 * the saver list, we shall set `current_saver' to `none_saver'
1942 * before stopping the current saver, rather than blocking by `splXX()'.
1944 current_saver = none_saver;
1946 stop_scrn_saver(this_saver);
1949 /* unblank all blanked screens */
1950 wait_scrn_saver_stop(NULL);
1954 current_saver = none_saver;
1959 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1963 /* assert(scp == scp->sc->cur_scp) */
1965 if (!ISGRAPHSC(scp))
1966 sc_remove_cursor_image(scp);
1967 scp->splash_save_mode = scp->mode;
1968 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1969 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1970 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1971 scp->sc->flags |= SC_SCRN_BLANKED;
1977 if (set_mode(scp) == 0) {
1978 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1979 scp->status |= GRAPHICS_MODE;
1980 #ifndef SC_NO_PALETTE_LOADING
1982 load_palette(scp->sc->adp, pal);
1984 sc_set_border(scp, border);
1988 scp->mode = scp->splash_save_mode;
1989 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1990 scp->status |= scp->splash_save_status;
1997 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2003 /* assert(scp == scp->sc->cur_scp) */
2006 status = scp->status;
2007 scp->mode = scp->splash_save_mode;
2008 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2009 scp->status |= scp->splash_save_status;
2010 scp->sc->flags &= ~SC_SCRN_BLANKED;
2012 if (!ISGRAPHSC(scp))
2013 sc_draw_cursor_image(scp);
2018 if (set_mode(scp) == 0) {
2019 #ifndef SC_NO_PALETTE_LOADING
2020 load_palette(scp->sc->adp, scp->sc->palette);
2027 scp->status = status;
2034 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2036 (*saver)(sc, FALSE);
2037 run_scrn_saver = FALSE;
2038 /* the screen saver may have chosen not to stop after all... */
2039 if (sc->flags & SC_SCRN_BLANKED)
2042 mark_all(sc->cur_scp);
2043 if (sc->delayed_next_scr)
2044 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2045 wakeup((caddr_t)&scrn_blanked);
2049 wait_scrn_saver_stop(sc_softc_t *sc)
2053 while (scrn_blanked > 0) {
2054 run_scrn_saver = FALSE;
2055 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2059 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2060 if ((error != 0) && (error != ERESTART))
2063 run_scrn_saver = FALSE;
2066 #endif /* NSPLASH */
2069 sc_touch_scrn_saver(void)
2071 scsplash_stick(FALSE);
2072 run_scrn_saver = FALSE;
2076 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2082 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2084 /* prevent switch if previously requested */
2085 if (sc->flags & SC_SCRN_VTYLOCK) {
2086 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2087 sc->cur_scp->bell_duration);
2091 /* delay switch if the screen is blanked or being updated */
2092 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2093 || sc->blink_in_progress || sc->videoio_in_progress) {
2094 sc->delayed_next_scr = next_scr + 1;
2095 sc_touch_scrn_saver();
2096 DPRINTF(5, ("switch delayed\n"));
2101 cur_scp = sc->cur_scp;
2103 /* we are in the middle of the vty switching process... */
2104 if (sc->switch_in_progress
2105 && (cur_scp->smode.mode == VT_PROCESS)
2107 if (cur_scp->proc != pfind(cur_scp->pid)) {
2109 * The controlling process has died!!. Do some clean up.
2110 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2111 * are not reset here yet; they will be cleared later.
2113 DPRINTF(5, ("cur_scp controlling process %d died, ",
2115 if (cur_scp->status & SWITCH_WAIT_REL) {
2117 * Force the previous switch to finish, but return now
2120 DPRINTF(5, ("reset WAIT_REL, "));
2121 finish_vt_rel(cur_scp, TRUE, &s);
2123 DPRINTF(5, ("finishing previous switch\n"));
2125 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2126 /* let's assume screen switch has been completed. */
2127 DPRINTF(5, ("reset WAIT_ACQ, "));
2128 finish_vt_acq(cur_scp);
2131 * We are in between screen release and acquisition, and
2132 * reached here via scgetc() or scrn_timer() which has
2133 * interrupted exchange_scr(). Don't do anything stupid.
2135 DPRINTF(5, ("waiting nothing, "));
2139 * The controlling process is alive, but not responding...
2140 * It is either buggy or it may be just taking time.
2141 * The following code is a gross kludge to cope with this
2142 * problem for which there is no clean solution. XXX
2144 if (cur_scp->status & SWITCH_WAIT_REL) {
2145 switch (sc->switch_in_progress++) {
2149 DPRINTF(5, ("sending relsig again, "));
2150 signal_vt_rel(cur_scp);
2157 * Act as if the controlling program returned
2160 DPRINTF(5, ("force reset WAIT_REL, "));
2161 finish_vt_rel(cur_scp, FALSE, &s);
2163 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2166 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2167 switch (sc->switch_in_progress++) {
2171 DPRINTF(5, ("sending acqsig again, "));
2172 signal_vt_acq(cur_scp);
2178 /* clear the flag and finish the previous switch */
2179 DPRINTF(5, ("force reset WAIT_ACQ, "));
2180 finish_vt_acq(cur_scp);
2188 * Return error if an invalid argument is given, or vty switch
2189 * is still in progress.
2191 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2192 || sc->switch_in_progress) {
2194 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2195 DPRINTF(5, ("error 1\n"));
2200 * Don't allow switching away from the graphics mode vty
2201 * if the switch mode is VT_AUTO, unless the next vty is the same
2202 * as the current or the current vty has been closed (but showing).
2204 tp = VIRTUAL_TTY(sc, cur_scp->index);
2205 if ((cur_scp->index != next_scr)
2207 && (cur_scp->smode.mode == VT_AUTO)
2208 && ISGRAPHSC(cur_scp)) {
2210 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2211 DPRINTF(5, ("error, graphics mode\n"));
2216 * Is the wanted vty open? Don't allow switching to a closed vty.
2217 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2218 * Note that we always allow the user to switch to the kernel
2219 * console even if it is closed.
2221 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2222 tp = VIRTUAL_TTY(sc, next_scr);
2223 if (!ISTTYOPEN(tp)) {
2225 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2226 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2229 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2231 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2236 /* this is the start of vty switching process... */
2237 ++sc->switch_in_progress;
2238 sc->delayed_next_scr = 0;
2239 sc->old_scp = cur_scp;
2240 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2241 if (sc->new_scp == sc->old_scp) {
2242 sc->switch_in_progress = 0;
2243 wakeup((caddr_t)&sc->new_scp->smode);
2245 DPRINTF(5, ("switch done (new == old)\n"));
2249 /* has controlling process died? */
2250 vt_proc_alive(sc->old_scp);
2251 vt_proc_alive(sc->new_scp);
2253 /* wait for the controlling process to release the screen, if necessary */
2254 if (signal_vt_rel(sc->old_scp)) {
2259 /* go set up the new vty screen */
2264 /* wake up processes waiting for this vty */
2265 wakeup((caddr_t)&sc->cur_scp->smode);
2267 /* wait for the controlling process to acknowledge, if necessary */
2268 if (signal_vt_acq(sc->cur_scp)) {
2273 sc->switch_in_progress = 0;
2274 if (sc->unit == sc_console_unit)
2275 cons_unavail = FALSE;
2277 DPRINTF(5, ("switch done\n"));
2283 do_switch_scr(sc_softc_t *sc, int s)
2285 vt_proc_alive(sc->new_scp);
2290 /* sc->cur_scp == sc->new_scp */
2291 wakeup((caddr_t)&sc->cur_scp->smode);
2293 /* wait for the controlling process to acknowledge, if necessary */
2294 if (!signal_vt_acq(sc->cur_scp)) {
2295 sc->switch_in_progress = 0;
2296 if (sc->unit == sc_console_unit)
2297 cons_unavail = FALSE;
2304 vt_proc_alive(scr_stat *scp)
2307 if (scp->proc == pfind(scp->pid))
2310 scp->smode.mode = VT_AUTO;
2311 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2317 signal_vt_rel(scr_stat *scp)
2319 if (scp->smode.mode != VT_PROCESS)
2321 scp->status |= SWITCH_WAIT_REL;
2322 psignal(scp->proc, scp->smode.relsig);
2323 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2328 signal_vt_acq(scr_stat *scp)
2330 if (scp->smode.mode != VT_PROCESS)
2332 if (scp->sc->unit == sc_console_unit)
2333 cons_unavail = TRUE;
2334 scp->status |= SWITCH_WAIT_ACQ;
2335 psignal(scp->proc, scp->smode.acqsig);
2336 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2341 finish_vt_rel(scr_stat *scp, int release, int *s)
2343 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2344 scp->status &= ~SWITCH_WAIT_REL;
2346 *s = do_switch_scr(scp->sc, *s);
2348 scp->sc->switch_in_progress = 0;
2355 finish_vt_acq(scr_stat *scp)
2357 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2358 scp->status &= ~SWITCH_WAIT_ACQ;
2359 scp->sc->switch_in_progress = 0;
2366 exchange_scr(sc_softc_t *sc)
2370 /* save the current state of video and keyboard */
2371 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2372 if (!ISGRAPHSC(sc->old_scp))
2373 sc_remove_cursor_image(sc->old_scp);
2374 if (sc->old_scp->kbd_mode == K_XLATE)
2375 save_kbd_state(sc->old_scp);
2377 /* set up the video for the new screen */
2378 scp = sc->cur_scp = sc->new_scp;
2379 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2382 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2383 (void *)sc->adp->va_window, FALSE);
2384 scp->status |= MOUSE_HIDDEN;
2385 sc_move_cursor(scp, scp->xpos, scp->ypos);
2386 if (!ISGRAPHSC(scp))
2387 sc_set_cursor_image(scp);
2388 #ifndef SC_NO_PALETTE_LOADING
2389 if (ISGRAPHSC(sc->old_scp))
2390 load_palette(sc->adp, sc->palette);
2392 sc_set_border(scp, scp->border);
2394 /* set up the keyboard for the new screen */
2395 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2396 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2397 update_kbd_state(scp, scp->status, LOCK_MASK);
2403 sc_puts(scr_stat *scp, u_char *buf, int len)
2406 /* make screensaver happy */
2407 if (!sticky_splash && scp == scp->sc->cur_scp)
2408 run_scrn_saver = FALSE;
2412 (*scp->tsw->te_puts)(scp, buf, len);
2414 if (scp->sc->delayed_next_scr)
2415 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2419 sc_draw_cursor_image(scr_stat *scp)
2421 /* assert(scp == scp->sc->cur_scp); */
2422 ++scp->sc->videoio_in_progress;
2423 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2424 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2425 sc_inside_cutmark(scp, scp->cursor_pos));
2426 scp->cursor_oldpos = scp->cursor_pos;
2427 --scp->sc->videoio_in_progress;
2431 sc_remove_cursor_image(scr_stat *scp)
2433 /* assert(scp == scp->sc->cur_scp); */
2434 ++scp->sc->videoio_in_progress;
2435 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2436 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2437 sc_inside_cutmark(scp, scp->cursor_oldpos));
2438 --scp->sc->videoio_in_progress;
2442 update_cursor_image(scr_stat *scp)
2446 if (scp->sc->flags & SC_CHAR_CURSOR) {
2447 scp->cursor_base = imax(0, scp->sc->cursor_base);
2448 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2450 scp->cursor_base = 0;
2451 scp->cursor_height = scp->font_size;
2453 blink = scp->sc->flags & SC_BLINK_CURSOR;
2455 /* assert(scp == scp->sc->cur_scp); */
2456 ++scp->sc->videoio_in_progress;
2457 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2458 sc_inside_cutmark(scp, scp->cursor_pos));
2459 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2460 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2461 sc_inside_cutmark(scp, scp->cursor_pos));
2462 --scp->sc->videoio_in_progress;
2466 sc_set_cursor_image(scr_stat *scp)
2468 if (scp->sc->flags & SC_CHAR_CURSOR) {
2469 scp->cursor_base = imax(0, scp->sc->cursor_base);
2470 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2472 scp->cursor_base = 0;
2473 scp->cursor_height = scp->font_size;
2476 /* assert(scp == scp->sc->cur_scp); */
2477 ++scp->sc->videoio_in_progress;
2478 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2479 scp->sc->flags & SC_BLINK_CURSOR);
2480 --scp->sc->videoio_in_progress;
2484 scinit(int unit, int flags)
2487 * When syscons is being initialized as the kernel console, malloc()
2488 * is not yet functional, because various kernel structures has not been
2489 * fully initialized yet. Therefore, we need to declare the following
2490 * static buffers for the console. This is less than ideal,
2491 * but is necessry evil for the time being. XXX
2493 static scr_stat main_console;
2494 static dev_t main_devs[MAXCONS];
2495 static struct tty main_tty;
2496 static u_short sc_buffer[ROW*COL]; /* XXX */
2497 #ifndef SC_NO_FONT_LOADING
2498 static u_char font_8[256*8];
2499 static u_char font_14[256*14];
2500 static u_char font_16[256*16];
2505 video_adapter_t *adp;
2510 /* one time initialization */
2511 if (init_done == COLD)
2512 sc_get_bios_values(&bios_value);
2516 * Allocate resources. Even if we are being called for the second
2517 * time, we must allocate them again, because they might have
2520 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2522 if (sc->adapter >= 0) {
2523 vid_release(sc->adp, (void *)&sc->adapter);
2527 if (sc->keyboard >= 0) {
2528 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2529 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2530 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2531 if (sc->kbd != NULL) {
2532 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2533 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2537 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2538 sc->adp = vid_get_adapter(sc->adapter);
2539 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2540 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2542 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2543 sc->kbd = kbd_get_keyboard(sc->keyboard);
2544 if (sc->kbd != NULL) {
2545 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2546 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2549 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2551 sc->initial_mode = sc->adp->va_initial_mode;
2553 #ifndef SC_NO_FONT_LOADING
2554 if (flags & SC_KERNEL_CONSOLE) {
2555 sc->font_8 = font_8;
2556 sc->font_14 = font_14;
2557 sc->font_16 = font_16;
2558 } else if (sc->font_8 == NULL) {
2559 /* assert(sc_malloc) */
2560 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2561 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2562 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2566 /* extract the hardware cursor location and hide the cursor for now */
2567 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2568 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2570 /* set up the first console */
2571 sc->first_vty = unit*MAXCONS;
2572 sc->vtys = MAXCONS; /* XXX: should be configurable */
2573 if (flags & SC_KERNEL_CONSOLE) {
2574 sc->dev = main_devs;
2575 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2576 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2577 sc->dev[0]->si_tty = &main_tty;
2578 ttyregister(&main_tty);
2579 scp = &main_console;
2580 init_scp(sc, sc->first_vty, scp);
2581 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2582 (void *)sc_buffer, FALSE);
2583 if (sc_init_emulator(scp, SC_DFLT_TERM))
2584 sc_init_emulator(scp, "*");
2585 (*scp->tsw->te_default_attr)(scp,
2586 kernel_default.std_color,
2587 kernel_default.rev_color);
2589 /* assert(sc_malloc) */
2590 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
2591 bzero(sc->dev, sizeof(dev_t)*sc->vtys);
2592 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2593 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2594 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2595 scp = alloc_scp(sc, sc->first_vty);
2597 SC_STAT(sc->dev[0]) = scp;
2600 /* copy screen to temporary buffer */
2601 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2602 (void *)scp->sc->adp->va_window, FALSE);
2604 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2606 /* move cursors to the initial positions */
2607 if (col >= scp->xsize)
2609 if (row >= scp->ysize)
2610 row = scp->ysize - 1;
2613 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2614 if (bios_value.cursor_end < scp->font_size)
2615 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2617 sc->cursor_base = 0;
2618 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2619 sc->cursor_height = imin(i, scp->font_size);
2620 #ifndef SC_NO_SYSMOUSE
2621 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2623 if (!ISGRAPHSC(scp)) {
2624 sc_set_cursor_image(scp);
2625 sc_draw_cursor_image(scp);
2628 /* save font and palette */
2629 #ifndef SC_NO_FONT_LOADING
2630 sc->fonts_loaded = 0;
2631 if (ISFONTAVAIL(sc->adp->va_flags)) {
2633 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2634 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2635 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2636 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2637 if (scp->font_size < 14) {
2638 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2639 } else if (scp->font_size >= 16) {
2640 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2642 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2644 #else /* !SC_DFLT_FONT */
2645 if (scp->font_size < 14) {
2646 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2647 sc->fonts_loaded = FONT_8;
2648 } else if (scp->font_size >= 16) {
2649 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2650 sc->fonts_loaded = FONT_16;
2652 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2653 sc->fonts_loaded = FONT_14;
2655 #endif /* SC_DFLT_FONT */
2656 /* FONT KLUDGE: always use the font page #0. XXX */
2657 sc_show_font(scp, 0);
2659 #endif /* !SC_NO_FONT_LOADING */
2661 #ifndef SC_NO_PALETTE_LOADING
2662 save_palette(sc->adp, sc->palette);
2666 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2667 /* we are ready to put up the splash image! */
2668 splash_init(sc->adp, scsplash_callback, sc);
2669 sc->flags |= SC_SPLASH_SCRN;
2671 #endif /* NSPLASH */
2674 /* the rest is not necessary, if we have done it once */
2675 if (sc->flags & SC_INIT_DONE)
2678 /* initialize mapscrn arrays to a one to one map */
2679 for (i = 0; i < sizeof(sc->scr_map); i++)
2680 sc->scr_map[i] = sc->scr_rmap[i] = i;
2682 sc->flags |= SC_INIT_DONE;
2687 scterm(int unit, int flags)
2692 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2694 return; /* shouldn't happen */
2697 /* this console is no longer available for the splash screen */
2698 if (sc->flags & SC_SPLASH_SCRN) {
2699 splash_term(sc->adp);
2700 sc->flags &= ~SC_SPLASH_SCRN;
2702 #endif /* NSPLASH */
2705 /* move the hardware cursor to the upper-left corner */
2706 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2709 /* release the keyboard and the video card */
2710 if (sc->keyboard >= 0)
2711 kbd_release(sc->kbd, &sc->keyboard);
2712 if (sc->adapter >= 0)
2713 vid_release(sc->adp, &sc->adapter);
2715 /* stop the terminal emulator, if any */
2716 scp = SC_STAT(sc->dev[0]);
2718 (*scp->tsw->te_term)(scp, &scp->ts);
2719 if (scp->ts != NULL)
2720 free(scp->ts, M_DEVBUF);
2722 /* clear the structure */
2723 if (!(flags & SC_KERNEL_CONSOLE)) {
2724 /* XXX: We need delete_dev() for this */
2725 free(sc->dev, M_DEVBUF);
2727 /* XXX: We need a ttyunregister for this */
2728 free(sc->tty, M_DEVBUF);
2730 #ifndef SC_NO_FONT_LOADING
2731 free(sc->font_8, M_DEVBUF);
2732 free(sc->font_14, M_DEVBUF);
2733 free(sc->font_16, M_DEVBUF);
2735 /* XXX vtb, history */
2737 bzero(sc, sizeof(*sc));
2744 scshutdown(void *arg, int howto)
2746 /* assert(sc_console != NULL) */
2748 sc_touch_scrn_saver();
2749 if (!cold && sc_console
2750 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2751 && sc_console->smode.mode == VT_AUTO)
2752 sc_switch_scr(sc_console->sc, sc_console->index);
2753 shutdown_in_progress = TRUE;
2757 sc_clean_up(scr_stat *scp)
2761 #endif /* NSPLASH */
2763 if (scp->sc->flags & SC_SCRN_BLANKED) {
2764 sc_touch_scrn_saver();
2766 if ((error = wait_scrn_saver_stop(scp->sc)))
2768 #endif /* NSPLASH */
2770 scp->status |= MOUSE_HIDDEN;
2771 sc_remove_mouse_image(scp);
2772 sc_remove_cutmarking(scp);
2777 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2783 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2784 if (!discard && (old.vtb_flags & VTB_VALID)) {
2785 /* retain the current cursor position and buffer contants */
2786 scp->cursor_oldpos = scp->cursor_pos;
2788 * This works only if the old buffer has the same size as or larger
2789 * than the new one. XXX
2791 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2795 sc_vtb_destroy(&old);
2798 #ifndef SC_NO_SYSMOUSE
2799 /* move the mouse cursor at the center of the screen */
2800 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2805 *alloc_scp(sc_softc_t *sc, int vty)
2809 /* assert(sc_malloc) */
2811 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2812 init_scp(sc, vty, scp);
2814 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2815 if (sc_init_emulator(scp, SC_DFLT_TERM))
2816 sc_init_emulator(scp, "*");
2818 #ifndef SC_NO_CUTPASTE
2819 sc_alloc_cut_buffer(scp, TRUE);
2822 #ifndef SC_NO_HISTORY
2823 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2830 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2834 bzero(scp, sizeof(*scp));
2839 scp->mode = sc->initial_mode;
2840 callout_init(&scp->blink_screen_ch);
2841 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2842 if (info.vi_flags & V_INFO_GRAPHICS) {
2843 scp->status |= GRAPHICS_MODE;
2844 scp->xpixel = info.vi_width;
2845 scp->ypixel = info.vi_height;
2846 scp->xsize = info.vi_width/8;
2847 scp->ysize = info.vi_height/info.vi_cheight;
2851 scp->xsize = info.vi_width;
2852 scp->ysize = info.vi_height;
2853 scp->xpixel = scp->xsize*8;
2854 scp->ypixel = scp->ysize*info.vi_cheight;
2855 if (info.vi_cheight < 14) {
2857 #ifndef SC_NO_FONT_LOADING
2858 scp->font = sc->font_8;
2862 } else if (info.vi_cheight >= 16) {
2863 scp->font_size = 16;
2864 #ifndef SC_NO_FONT_LOADING
2865 scp->font = sc->font_16;
2870 scp->font_size = 14;
2871 #ifndef SC_NO_FONT_LOADING
2872 scp->font = sc->font_14;
2878 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2879 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2880 scp->xoff = scp->yoff = 0;
2881 scp->xpos = scp->ypos = 0;
2882 scp->start = scp->xsize * scp->ysize - 1;
2887 scp->border = BG_BLACK;
2888 scp->cursor_base = sc->cursor_base;
2889 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2890 scp->mouse_cut_start = scp->xsize*scp->ysize;
2891 scp->mouse_cut_end = -1;
2892 scp->mouse_signal = 0;
2894 scp->mouse_proc = NULL;
2895 scp->kbd_mode = K_XLATE;
2896 scp->bell_pitch = bios_value.bell_pitch;
2897 scp->bell_duration = BELL_DURATION;
2898 scp->status |= (bios_value.shift_state & NLKED);
2899 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2902 scp->smode.mode = VT_AUTO;
2903 scp->history = NULL;
2904 scp->history_pos = 0;
2905 scp->history_size = 0;
2909 sc_init_emulator(scr_stat *scp, char *name)
2916 if (name == NULL) /* if no name is given, use the current emulator */
2918 else /* ...otherwise find the named emulator */
2919 sw = sc_term_match(name);
2924 if (strcmp(sw->te_renderer, "*") != 0) {
2925 rndr = sc_render_match(scp, sw->te_renderer,
2926 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2929 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2930 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2935 if (sw == scp->tsw) {
2936 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2938 scp->rndr->init(scp);
2939 sc_clear_screen(scp);
2940 /* assert(error == 0); */
2944 if (sc_malloc && (sw->te_size > 0))
2945 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
2948 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2953 (*scp->tsw->te_term)(scp, &scp->ts);
2954 if (scp->ts != NULL)
2955 free(scp->ts, M_DEVBUF);
2959 scp->rndr->init(scp);
2962 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2963 sc_clear_screen(scp);
2969 * scgetc(flags) - get character from keyboard.
2970 * If flags & SCGETC_CN, then avoid harmful side effects.
2971 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2972 * return NOKEY if there is nothing there.
2975 scgetc(sc_softc_t *sc, u_int flags)
2978 #ifndef SC_NO_HISTORY
2986 if (sc->kbd == NULL)
2991 /* I don't like this, but... XXX */
2992 if (flags & SCGETC_CN)
2993 sccnupdate(sc->cur_scp);
2996 /* first see if there is something in the keyboard port */
2998 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3000 if (!(flags & SCGETC_CN))
3001 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3002 } else if (c == NOKEY)
3008 /* make screensaver happy */
3010 sc_touch_scrn_saver();
3013 if (!(flags & SCGETC_CN))
3014 /* do the /dev/random device a favour */
3015 add_keyboard_randomness(c);
3018 if (scp->kbd_mode != K_XLATE)
3021 /* if scroll-lock pressed allow history browsing */
3022 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3024 scp->status &= ~CURSOR_ENABLED;
3025 sc_remove_cursor_image(scp);
3027 #ifndef SC_NO_HISTORY
3028 if (!(scp->status & BUFFER_SAVED)) {
3029 scp->status |= BUFFER_SAVED;
3033 /* FIXME: key codes */
3034 case SPCLKEY | FKEY | F(49): /* home key */
3035 sc_remove_cutmarking(scp);
3039 case SPCLKEY | FKEY | F(57): /* end key */
3040 sc_remove_cutmarking(scp);
3044 case SPCLKEY | FKEY | F(50): /* up arrow key */
3045 sc_remove_cutmarking(scp);
3046 if (sc_hist_up_line(scp))
3047 if (!(flags & SCGETC_CN))
3048 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3051 case SPCLKEY | FKEY | F(58): /* down arrow key */
3052 sc_remove_cutmarking(scp);
3053 if (sc_hist_down_line(scp))
3054 if (!(flags & SCGETC_CN))
3055 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3058 case SPCLKEY | FKEY | F(51): /* page up key */
3059 sc_remove_cutmarking(scp);
3060 for (i=0; i<scp->ysize; i++)
3061 if (sc_hist_up_line(scp)) {
3062 if (!(flags & SCGETC_CN))
3063 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3068 case SPCLKEY | FKEY | F(59): /* page down key */
3069 sc_remove_cutmarking(scp);
3070 for (i=0; i<scp->ysize; i++)
3071 if (sc_hist_down_line(scp)) {
3072 if (!(flags & SCGETC_CN))
3073 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3078 #endif /* SC_NO_HISTORY */
3082 * Process and consume special keys here. Return a plain char code
3083 * or a char code with the META flag or a function key code.
3087 /* goto next_code */
3092 switch (KEYCHAR(c)) {
3094 case NLK: case CLK: case ALK:
3097 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3099 scp->status |= SLKED;
3101 if (scp->status & SLKED) {
3102 scp->status &= ~SLKED;
3103 #ifndef SC_NO_HISTORY
3104 if (scp->status & BUFFER_SAVED) {
3105 if (!sc_hist_restore(scp))
3106 sc_remove_cutmarking(scp);
3107 scp->status &= ~BUFFER_SAVED;
3108 scp->status |= CURSOR_ENABLED;
3109 sc_draw_cursor_image(scp);
3111 tp = VIRTUAL_TTY(sc, scp->index);
3119 /* NON-LOCKING KEYS */
3121 case LSH: case RSH: case LCTR: case RCTR:
3122 case LALT: case RALT: case ASH: case META:
3126 if (!(sc->flags & SC_SCRN_BLANKED))
3132 /* force activatation/deactivation of the screen saver */
3133 if (!(sc->flags & SC_SCRN_BLANKED)) {
3134 run_scrn_saver = TRUE;
3135 sc->scrn_time_stamp -= scrn_blank_time;
3139 * While devices are being probed, the screen saver need
3140 * to be invoked explictly. XXX
3142 if (sc->flags & SC_SCRN_BLANKED) {
3143 scsplash_stick(FALSE);
3144 stop_scrn_saver(sc, current_saver);
3146 if (!ISGRAPHSC(scp)) {
3147 scsplash_stick(TRUE);
3148 (*current_saver)(sc, TRUE);
3152 #endif /* NSPLASH */
3156 #ifndef SC_DISABLE_REBOOT
3162 #ifndef SC_DISABLE_REBOOT
3163 shutdown_nice(RB_HALT);
3168 #ifndef SC_DISABLE_REBOOT
3169 shutdown_nice(RB_HALT|RB_POWEROFF);
3175 apm_suspend(PMST_SUSPEND);
3178 apm_suspend(PMST_STANDBY);
3187 #ifndef SC_DISABLE_DDBKEY
3189 Debugger("manual escape to debugger");
3191 printf("No debugger in kernel\n");
3193 #else /* SC_DISABLE_DDBKEY */
3195 #endif /* SC_DISABLE_DDBKEY */
3199 if (enable_panic_key)
3200 panic("Forced by the panic key");
3204 this_scr = scp->index;
3205 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3206 sc->first_vty + i != this_scr;
3207 i = (i + 1)%sc->vtys) {
3208 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3209 if (ISTTYOPEN(tp)) {
3210 sc_switch_scr(scp->sc, sc->first_vty + i);
3217 this_scr = scp->index;
3218 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3219 sc->first_vty + i != this_scr;
3220 i = (i + sc->vtys - 1)%sc->vtys) {
3221 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3222 if (ISTTYOPEN(tp)) {
3223 sc_switch_scr(scp->sc, sc->first_vty + i);
3230 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3231 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3234 /* assert(c & FKEY) */
3235 if (!(sc->flags & SC_SCRN_BLANKED))
3239 /* goto next_code */
3241 /* regular keys (maybe MKEY is set) */
3242 if (!(sc->flags & SC_SCRN_BLANKED))
3251 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3256 if (scp != scp->sc->cur_scp)
3258 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3262 save_kbd_state(scr_stat *scp)
3267 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3268 if (error == ENOIOCTL)
3271 scp->status &= ~LOCK_MASK;
3272 scp->status |= state;
3278 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3283 if (mask != LOCK_MASK) {
3284 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3285 if (error == ENOIOCTL)
3290 state |= new_bits & mask;
3292 state = new_bits & LOCK_MASK;
3294 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3295 if (error == ENOIOCTL)
3301 update_kbd_leds(scr_stat *scp, int which)
3306 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3307 if (error == ENOIOCTL)
3313 set_mode(scr_stat *scp)
3317 /* reject unsupported mode */
3318 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3321 /* if this vty is not currently showing, do nothing */
3322 if (scp != scp->sc->cur_scp)
3325 /* setup video hardware for the given mode */
3326 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3327 scp->rndr->init(scp);
3328 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3329 (void *)scp->sc->adp->va_window, FALSE);
3331 #ifndef SC_NO_FONT_LOADING
3332 /* load appropriate font */
3333 if (!(scp->status & GRAPHICS_MODE)) {
3334 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3335 if (scp->font_size < 14) {
3336 if (scp->sc->fonts_loaded & FONT_8)
3337 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3338 } else if (scp->font_size >= 16) {
3339 if (scp->sc->fonts_loaded & FONT_16)
3340 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3342 if (scp->sc->fonts_loaded & FONT_14)
3343 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3347 * This is an interim kludge to display correct font.
3348 * Always use the font page #0 on the video plane 2.
3349 * Somehow we cannot show the font in other font pages on
3350 * some video cards... XXX
3352 sc_show_font(scp, 0);
3356 #endif /* !SC_NO_FONT_LOADING */
3358 sc_set_border(scp, scp->border);
3359 sc_set_cursor_image(scp);
3365 sc_set_border(scr_stat *scp, int color)
3367 ++scp->sc->videoio_in_progress;
3368 (*scp->rndr->draw_border)(scp, color);
3369 --scp->sc->videoio_in_progress;
3372 #ifndef SC_NO_FONT_LOADING
3374 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3375 int base, int count)
3380 sc->font_loading_in_progress = TRUE;
3381 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3382 sc->font_loading_in_progress = FALSE;
3386 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3387 int base, int count)
3392 sc->font_loading_in_progress = TRUE;
3393 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3394 sc->font_loading_in_progress = FALSE;
3398 sc_show_font(scr_stat *scp, int page)
3400 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3402 #endif /* !SC_NO_FONT_LOADING */
3405 sc_paste(scr_stat *scp, u_char *p, int count)
3410 if (scp->status & MOUSE_VISIBLE) {
3411 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3414 rmap = scp->sc->scr_rmap;
3415 for (; count > 0; --count)
3416 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3421 sc_bell(scr_stat *scp, int pitch, int duration)
3423 if (cold || shutdown_in_progress)
3426 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3429 if (scp->sc->flags & SC_VISUAL_BELL) {
3430 if (scp->sc->blink_in_progress)
3432 scp->sc->blink_in_progress = 3;
3433 if (scp != scp->sc->cur_scp)
3434 scp->sc->blink_in_progress += 2;
3435 blink_screen(scp->sc->cur_scp);
3436 } else if (duration != 0 && pitch != 0) {
3437 if (scp != scp->sc->cur_scp)
3439 sysbeep(pitch, duration);
3444 blink_screen(void *arg)
3446 scr_stat *scp = arg;
3449 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3450 scp->sc->blink_in_progress = 0;
3452 tp = VIRTUAL_TTY(scp->sc, scp->index);
3455 if (scp->sc->delayed_next_scr)
3456 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3459 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3460 scp->sc->blink_in_progress & 1);
3461 scp->sc->blink_in_progress--;
3462 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);