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.14 2005/01/28 21:08:38 swildner 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;
194 CONS_DRIVER(sc, sccnprobe, sccninit, sccnterm, sccngetc, sccncheckc, sccnputc,
197 static d_open_t scopen;
198 static d_close_t scclose;
199 static d_read_t scread;
200 static d_ioctl_t scioctl;
201 static d_mmap_t scmmap;
203 static struct cdevsw sc_cdevsw = {
205 /* maj */ CDEV_MAJOR,
206 /* flags */ D_TTY | D_KQFILTER,
213 /* write */ ttywrite,
217 /* strategy */ nostrategy,
220 /* kqfilter */ ttykqfilter
224 sc_probe_unit(int unit, int flags)
226 if (!scvidprobe(unit, flags, FALSE)) {
228 printf("sc%d: no video adapter found.\n", unit);
232 /* syscons will be attached even when there is no keyboard */
233 sckbdprobe(unit, flags, FALSE);
238 /* probe video adapters, return TRUE if found */
240 scvidprobe(int unit, int flags, int cons)
243 * Access the video adapter driver through the back door!
244 * Video adapter drivers need to be configured before syscons.
245 * However, when syscons is being probed as the low-level console,
246 * they have not been initialized yet. We force them to initialize
247 * themselves here. XXX
249 vid_configure(cons ? VIO_PROBE_ONLY : 0);
251 return (vid_find_adapter("*", unit) >= 0);
254 /* probe the keyboard, return TRUE if found */
256 sckbdprobe(int unit, int flags, int cons)
258 /* access the keyboard driver through the backdoor! */
259 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
261 return (kbd_find_keyboard("*", unit) >= 0);
265 *adapter_name(video_adapter_t *adp)
271 { KD_MONO, { "MDA", "MDA" } },
272 { KD_HERCULES, { "Hercules", "Hercules" } },
273 { KD_CGA, { "CGA", "CGA" } },
274 { KD_EGA, { "EGA", "EGA (mono)" } },
275 { KD_VGA, { "VGA", "VGA (mono)" } },
276 { KD_PC98, { "PC-98x1", "PC-98x1" } },
277 { KD_TGA, { "TGA", "TGA" } },
278 { -1, { "Unknown", "Unknown" } },
282 for (i = 0; names[i].type != -1; ++i)
283 if (names[i].type == adp->va_type)
285 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
289 sc_attach_unit(int unit, int flags)
299 flags &= ~SC_KERNEL_CONSOLE;
301 if (sc_console_unit == unit) {
303 * If this unit is being used as the system console, we need to
304 * adjust some variables and buffers before and after scinit().
306 /* assert(sc_console != NULL) */
307 flags |= SC_KERNEL_CONSOLE;
312 if (sc_console->tsw->te_size > 0) {
313 /* assert(sc_console->ts != NULL); */
314 kernel_console_ts = sc_console->ts;
315 sc_console->ts = malloc(sc_console->tsw->te_size,
317 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
318 (*sc_console->tsw->te_default_attr)(sc_console,
319 user_default.std_color,
320 user_default.rev_color);
326 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
328 callout_init(&sc->scrn_timer_ch);
329 scp = SC_STAT(sc->dev[0]);
330 if (sc_console == NULL) /* sc_console_unit < 0 */
334 if ((sc->config & SC_VESA800X600)
335 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
337 if (sc->flags & SC_SPLASH_SCRN)
338 splash_term(sc->adp);
340 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
341 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
342 sc->initial_mode = M_VESA_800x600;
344 /* put up the splash again! */
345 if (sc->flags & SC_SPLASH_SCRN)
346 splash_init(sc->adp, scsplash_callback, sc);
349 #endif /* SC_PIXEL_MODE */
351 /* initialize cursor */
353 update_cursor_image(scp);
355 /* get screen update going */
358 /* set up the keyboard */
359 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
360 update_kbd_state(scp, scp->status, LOCK_MASK);
362 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
363 unit, adapter_name(sc->adp), sc->vtys, sc->config);
365 printf("sc%d:", unit);
366 if (sc->adapter >= 0)
367 printf(" fb%d", sc->adapter);
368 if (sc->keyboard >= 0)
369 printf(", kbd%d", sc->keyboard);
371 printf(", terminal emulator: %s (%s)",
372 scp->tsw->te_name, scp->tsw->te_desc);
376 /* register a shutdown callback for the kernel console */
377 if (sc_console_unit == unit)
378 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
379 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
382 * create devices. cdevsw_add() must be called to make devices under
383 * this major number available to userland.
385 cdevsw_add(&sc_cdevsw, ~(MAXCONS - 1), unit * MAXCONS);
387 for (vc = 0; vc < sc->vtys; vc++) {
388 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
389 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
392 * The first vty already has struct tty and scr_stat initialized
393 * in scinit(). The other vtys will have these structs when
398 cdevsw_add(&sc_cdevsw, -1, SC_CONSOLECTL); /* XXX */
399 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
400 UID_ROOT, GID_WHEEL, 0600, "consolectl");
401 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
402 SC_STAT(dev) = sc_console;
415 * As soon as malloc() becomes functional, we had better allocate
416 * various buffers for the kernel console.
419 if (sc_console_unit < 0) /* sc_console == NULL */
422 /* copy the temporary buffer to the final buffer */
423 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
425 #ifndef SC_NO_CUTPASTE
426 sc_alloc_cut_buffer(sc_console, TRUE);
429 #ifndef SC_NO_HISTORY
430 /* initialize history buffer & pointers */
431 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
436 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
439 scdevtounit(dev_t dev)
441 int vty = SC_VTY(dev);
443 if (vty == SC_CONSOLECTL)
444 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
445 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
452 scopen(dev_t dev, int flag, int mode, struct thread *td)
454 int unit = scdevtounit(dev);
461 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
462 major(dev), minor(dev), unit, SC_VTY(dev)));
464 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
468 tp = dev->si_tty = ttymalloc(dev->si_tty);
469 tp->t_oproc = scstart;
470 tp->t_param = scparam;
471 tp->t_stop = nottystop;
473 if (!ISTTYOPEN(tp)) {
475 /* Use the current setting of the <-- key as default VERASE. */
476 /* If the Delete key is preferable, an stty is necessary */
477 if (sc->kbd != NULL) {
478 key.keynum = KEYCODE_BS;
479 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
480 tp->t_cc[VERASE] = key.key.map[0];
482 tp->t_iflag = TTYDEF_IFLAG;
483 tp->t_oflag = TTYDEF_OFLAG;
484 tp->t_cflag = TTYDEF_CFLAG;
485 tp->t_lflag = TTYDEF_LFLAG;
486 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
487 scparam(tp, &tp->t_termios);
488 (*linesw[tp->t_line].l_modem)(tp, 1);
491 if (tp->t_state & TS_XCLUDE && suser(td))
494 error = (*linesw[tp->t_line].l_open)(dev, tp);
498 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
500 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
502 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
503 tp->t_winsize.ws_col = scp->xsize;
504 tp->t_winsize.ws_row = scp->ysize;
511 scclose(dev_t dev, int flag, int mode, struct thread *td)
513 struct tty *tp = dev->si_tty;
517 if (SC_VTY(dev) != SC_CONSOLECTL) {
518 scp = SC_STAT(tp->t_dev);
519 /* were we in the middle of the VT switching process? */
520 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
522 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
523 cons_unavail = FALSE;
524 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
525 DPRINTF(5, ("reset WAIT_REL, "));
526 if (finish_vt_acq(scp) == 0) /* force acknowledge */
527 DPRINTF(5, ("reset WAIT_ACQ, "));
529 if (scp == &main_console) {
532 scp->smode.mode = VT_AUTO;
535 sc_vtb_destroy(&scp->vtb);
536 sc_vtb_destroy(&scp->scr);
537 sc_free_history_buffer(scp, scp->ysize);
544 scp->smode.mode = VT_AUTO;
546 scp->kbd_mode = K_XLATE;
547 if (scp == scp->sc->cur_scp)
548 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
549 DPRINTF(5, ("done.\n"));
552 (*linesw[tp->t_line].l_close)(tp, flag);
559 scread(dev_t dev, struct uio *uio, int flag)
561 sc_touch_scrn_saver();
562 return ttyread(dev, uio, flag);
566 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
574 sc = (sc_softc_t *)arg;
575 /* assert(thiskbd == sc->kbd) */
580 case KBDIO_UNLOADING:
583 kbd_release(thiskbd, (void *)&sc->keyboard);
590 * Loop while there is still input to get from the keyboard.
591 * I don't think this is nessesary, and it doesn't fix
592 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
594 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
596 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
597 if (!ISTTYOPEN(cur_tty)) {
598 cur_tty = sc_console_tty;
599 if (!ISTTYOPEN(cur_tty))
603 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
606 switch (KEYFLAGS(c)) {
607 case 0x0000: /* normal key */
608 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
610 case FKEY: /* function key, return string */
611 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
614 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
617 case MKEY: /* meta is active, prepend ESC */
618 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
619 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
621 case BKEY: /* backtab fixed sequence (esc [ Z) */
622 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
623 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
624 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
629 sc->cur_scp->status |= MOUSE_HIDDEN;
635 scparam(struct tty *tp, struct termios *t)
637 tp->t_ispeed = t->c_ispeed;
638 tp->t_ospeed = t->c_ospeed;
639 tp->t_cflag = t->c_cflag;
644 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
652 struct proc *p = td->td_proc;
658 /* If there is a user_ioctl function call that first */
660 error = (*sc_user_ioctl)(dev, cmd, data, flag, td);
661 if (error != ENOIOCTL)
665 error = sc_vid_ioctl(tp, cmd, data, flag, td);
666 if (error != ENOIOCTL)
669 #ifndef SC_NO_HISTORY
670 error = sc_hist_ioctl(tp, cmd, data, flag, td);
671 if (error != ENOIOCTL)
675 #ifndef SC_NO_SYSMOUSE
676 error = sc_mouse_ioctl(tp, cmd, data, flag, td);
677 if (error != ENOIOCTL)
681 scp = SC_STAT(tp->t_dev);
682 /* assert(scp != NULL) */
683 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
687 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, td);
688 if (error != ENOIOCTL)
692 switch (cmd) { /* process console hardware related ioctl's */
694 case GIO_ATTR: /* get current attributes */
695 /* this ioctl is not processed here, but in the terminal emulator */
698 case GIO_COLOR: /* is this a color console ? */
699 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
702 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
703 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
706 scrn_blank_time = *(int *)data;
707 run_scrn_saver = (scrn_blank_time != 0);
711 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
713 if (!ISGRAPHSC(sc->cur_scp))
714 sc_remove_cursor_image(sc->cur_scp);
715 if ((*(int*)data) & 0x01)
716 sc->flags |= SC_BLINK_CURSOR;
718 sc->flags &= ~SC_BLINK_CURSOR;
719 if ((*(int*)data) & 0x02) {
720 sc->flags |= SC_CHAR_CURSOR;
722 sc->flags &= ~SC_CHAR_CURSOR;
724 * The cursor shape is global property; all virtual consoles
725 * are affected. Update the cursor in the current console...
727 if (!ISGRAPHSC(sc->cur_scp)) {
728 sc_set_cursor_image(sc->cur_scp);
729 sc_draw_cursor_image(sc->cur_scp);
734 case CONS_BELLTYPE: /* set bell type sound/visual */
735 if ((*(int *)data) & 0x01)
736 sc->flags |= SC_VISUAL_BELL;
738 sc->flags &= ~SC_VISUAL_BELL;
739 if ((*(int *)data) & 0x02)
740 sc->flags |= SC_QUIET_BELL;
742 sc->flags &= ~SC_QUIET_BELL;
745 case CONS_GETINFO: /* get current (virtual) console info */
747 vid_info_t *ptr = (vid_info_t*)data;
748 if (ptr->size == sizeof(struct vid_info)) {
749 ptr->m_num = sc->cur_scp->index;
750 ptr->font_size = scp->font_size;
751 ptr->mv_col = scp->xpos;
752 ptr->mv_row = scp->ypos;
753 ptr->mv_csz = scp->xsize;
754 ptr->mv_rsz = scp->ysize;
756 * The following fields are filled by the terminal emulator. XXX
763 ptr->mv_grfc.fore = 0; /* not supported */
764 ptr->mv_grfc.back = 0; /* not supported */
765 ptr->mv_ovscan = scp->border;
766 if (scp == sc->cur_scp)
768 ptr->mk_keylock = scp->status & LOCK_MASK;
774 case CONS_GETVERS: /* get version number */
775 *(int*)data = 0x200; /* version 2.0 */
778 case CONS_IDLE: /* see if the screen has been idle */
780 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
781 * the user process may have been writing something on the
782 * screen and syscons is not aware of it. Declare the screen
783 * is NOT idle if it is in one of these modes. But there is
784 * an exception to it; if a screen saver is running in the
785 * graphics mode in the current screen, we should say that the
786 * screen has been idle.
788 *(int *)data = (sc->flags & SC_SCRN_IDLE)
789 && (!ISGRAPHSC(sc->cur_scp)
790 || (sc->cur_scp->status & SAVER_RUNNING));
793 case CONS_SAVERMODE: /* set saver mode */
794 switch(*(int *)data) {
797 /* if a LKM screen saver is running, stop it first. */
798 scsplash_stick(FALSE);
799 saver_mode = *(int *)data;
802 if ((error = wait_scrn_saver_stop(NULL))) {
807 run_scrn_saver = TRUE;
808 if (saver_mode == CONS_USR_SAVER)
809 scp->status |= SAVER_RUNNING;
811 scp->status &= ~SAVER_RUNNING;
812 scsplash_stick(TRUE);
817 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
818 scp->status &= ~SAVER_RUNNING;
819 saver_mode = *(int *)data;
827 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
829 * Note that this ioctl does not guarantee the screen saver
830 * actually starts or stops. It merely attempts to do so...
833 run_scrn_saver = (*(int *)data != 0);
835 sc->scrn_time_stamp -= scrn_blank_time;
839 case CONS_SCRSHOT: /* get a screen shot */
841 scrshot_t *ptr = (scrshot_t*)data;
843 if (ISGRAPHSC(scp)) {
847 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
851 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
852 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
857 case VT_SETMODE: /* set screen switcher mode */
859 struct vt_mode *mode;
861 mode = (struct vt_mode *)data;
862 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
863 if (scp->smode.mode == VT_PROCESS) {
864 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
865 DPRINTF(5, ("error EPERM\n"));
870 if (mode->mode == VT_AUTO) {
871 scp->smode.mode = VT_AUTO;
874 DPRINTF(5, ("VT_AUTO, "));
875 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
876 cons_unavail = FALSE;
877 /* were we in the middle of the vty switching process? */
878 if (finish_vt_rel(scp, TRUE, &s) == 0)
879 DPRINTF(5, ("reset WAIT_REL, "));
880 if (finish_vt_acq(scp) == 0)
881 DPRINTF(5, ("reset WAIT_ACQ, "));
883 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
884 || !ISSIGVALID(mode->frsig)) {
886 DPRINTF(5, ("error EINVAL\n"));
889 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
890 bcopy(data, &scp->smode, sizeof(struct vt_mode));
892 scp->pid = scp->proc->p_pid;
893 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
901 case VT_GETMODE: /* get screen switcher mode */
902 bcopy(&scp->smode, data, sizeof(struct vt_mode));
905 case VT_RELDISP: /* screen switcher ioctl */
908 * This must be the current vty which is in the VT_PROCESS
911 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
915 /* ...and this process is controlling it. */
916 if (scp->proc != p) {
921 switch(*(int *)data) {
922 case VT_FALSE: /* user refuses to release screen, abort */
923 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
924 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
926 case VT_TRUE: /* user has released screen, go on */
927 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
928 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
930 case VT_ACKACQ: /* acquire acknowledged, switch completed */
931 if ((error = finish_vt_acq(scp)) == 0)
932 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
940 case VT_OPENQRY: /* return free virtual console */
941 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
942 tp = VIRTUAL_TTY(sc, i);
943 if (!ISTTYOPEN(tp)) {
944 *(int *)data = i + 1;
950 case VT_ACTIVATE: /* switch to screen *data */
951 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
953 sc_clean_up(sc->cur_scp);
955 return sc_switch_scr(sc, i);
957 case VT_WAITACTIVE: /* wait for switch to occur */
958 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
959 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
962 error = sc_clean_up(sc->cur_scp);
966 scp = SC_STAT(SC_DEV(sc, i));
967 if (scp == scp->sc->cur_scp)
969 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
970 "waitvt", 0)) == ERESTART) ;
973 case VT_GETACTIVE: /* get active vty # */
974 *(int *)data = sc->cur_scp->index + 1;
977 case VT_GETINDEX: /* get this vty # */
978 *(int *)data = scp->index + 1;
981 case VT_LOCKSWITCH: /* prevent vty switching */
982 if ((*(int *)data) & 0x01)
983 sc->flags |= SC_SCRN_VTYLOCK;
985 sc->flags &= ~SC_SCRN_VTYLOCK;
988 case KDENABIO: /* allow io operations */
995 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
999 case KDDISABIO: /* disallow io operations (default) */
1001 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
1005 case KDSKBSTATE: /* set keyboard state (locks) */
1006 if (*(int *)data & ~LOCK_MASK)
1008 scp->status &= ~LOCK_MASK;
1009 scp->status |= *(int *)data;
1010 if (scp == sc->cur_scp)
1011 update_kbd_state(scp, scp->status, LOCK_MASK);
1014 case KDGKBSTATE: /* get keyboard state (locks) */
1015 if (scp == sc->cur_scp)
1016 save_kbd_state(scp);
1017 *(int *)data = scp->status & LOCK_MASK;
1020 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1021 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1022 error = kbd_ioctl(sc->kbd, cmd, data);
1023 if (error == ENOIOCTL)
1027 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1028 if (*(int *)data & ~0x7f)
1030 error = kbd_ioctl(sc->kbd, cmd, data);
1031 if (error == ENOIOCTL)
1035 case KDSKBMODE: /* set keyboard mode */
1036 switch (*(int *)data) {
1037 case K_XLATE: /* switch to XLT ascii mode */
1038 case K_RAW: /* switch to RAW scancode mode */
1039 case K_CODE: /* switch to CODE mode */
1040 scp->kbd_mode = *(int *)data;
1041 if (scp == sc->cur_scp)
1042 kbd_ioctl(sc->kbd, cmd, data);
1049 case KDGKBMODE: /* get keyboard mode */
1050 *(int *)data = scp->kbd_mode;
1054 error = kbd_ioctl(sc->kbd, cmd, data);
1055 if (error == ENOIOCTL)
1059 case KDMKTONE: /* sound the bell */
1061 sc_bell(scp, (*(int*)data)&0xffff,
1062 (((*(int*)data)>>16)&0xffff)*hz/1000);
1064 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1067 case KIOCSOUND: /* make tone (*data) hz */
1068 if (scp == sc->cur_scp) {
1070 return sc_tone(*(int *)data);
1076 case KDGKBTYPE: /* get keyboard type */
1077 error = kbd_ioctl(sc->kbd, cmd, data);
1078 if (error == ENOIOCTL) {
1079 /* always return something? XXX */
1084 case KDSETLED: /* set keyboard LED status */
1085 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1087 scp->status &= ~LED_MASK;
1088 scp->status |= *(int *)data;
1089 if (scp == sc->cur_scp)
1090 update_kbd_leds(scp, scp->status);
1093 case KDGETLED: /* get keyboard LED status */
1094 if (scp == sc->cur_scp)
1095 save_kbd_state(scp);
1096 *(int *)data = scp->status & LED_MASK;
1099 case CONS_SETKBD: /* set the new keyboard */
1104 newkbd = kbd_get_keyboard(*(int *)data);
1105 if (newkbd == NULL) {
1110 if (sc->kbd != newkbd) {
1111 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1112 (void *)&sc->keyboard, sckbdevent, sc);
1113 /* i == newkbd->kb_index */
1115 if (sc->kbd != NULL) {
1116 save_kbd_state(sc->cur_scp);
1117 kbd_release(sc->kbd, (void *)&sc->keyboard);
1119 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1121 kbd_ioctl(sc->kbd, KDSKBMODE,
1122 (caddr_t)&sc->cur_scp->kbd_mode);
1123 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1126 error = EPERM; /* XXX */
1133 case CONS_RELKBD: /* release the current keyboard */
1136 if (sc->kbd != NULL) {
1137 save_kbd_state(sc->cur_scp);
1138 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1147 case CONS_GETTERM: /* get the current terminal emulator info */
1151 if (((term_info_t *)data)->ti_index == 0) {
1154 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1157 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1158 sizeof(((term_info_t *)data)->ti_name));
1159 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1160 sizeof(((term_info_t *)data)->ti_desc));
1161 ((term_info_t *)data)->ti_flags = 0;
1164 ((term_info_t *)data)->ti_name[0] = '\0';
1165 ((term_info_t *)data)->ti_desc[0] = '\0';
1166 ((term_info_t *)data)->ti_flags = 0;
1171 case CONS_SETTERM: /* set the current terminal emulator */
1173 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1174 /* FIXME: what if scp == sc_console! XXX */
1178 case GIO_SCRNMAP: /* get output translation table */
1179 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1182 case PIO_SCRNMAP: /* set output translation table */
1183 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1184 for (i=0; i<sizeof(sc->scr_map); i++) {
1185 sc->scr_rmap[sc->scr_map[i]] = i;
1189 case GIO_KEYMAP: /* get keyboard translation table */
1190 case PIO_KEYMAP: /* set keyboard translation table */
1191 case GIO_DEADKEYMAP: /* get accent key translation table */
1192 case PIO_DEADKEYMAP: /* set accent key translation table */
1193 case GETFKEY: /* get function key string */
1194 case SETFKEY: /* set function key string */
1195 error = kbd_ioctl(sc->kbd, cmd, data);
1196 if (error == ENOIOCTL)
1200 #ifndef SC_NO_FONT_LOADING
1202 case PIO_FONT8x8: /* set 8x8 dot font */
1203 if (!ISFONTAVAIL(sc->adp->va_flags))
1205 bcopy(data, sc->font_8, 8*256);
1206 sc->fonts_loaded |= FONT_8;
1209 * Always use the font page #0. XXX
1210 * Don't load if the current font size is not 8x8.
1212 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1213 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1216 case GIO_FONT8x8: /* get 8x8 dot font */
1217 if (!ISFONTAVAIL(sc->adp->va_flags))
1219 if (sc->fonts_loaded & FONT_8) {
1220 bcopy(sc->font_8, data, 8*256);
1226 case PIO_FONT8x14: /* set 8x14 dot font */
1227 if (!ISFONTAVAIL(sc->adp->va_flags))
1229 bcopy(data, sc->font_14, 14*256);
1230 sc->fonts_loaded |= FONT_14;
1233 * Always use the font page #0. XXX
1234 * Don't load if the current font size is not 8x14.
1236 if (ISTEXTSC(sc->cur_scp)
1237 && (sc->cur_scp->font_size >= 14)
1238 && (sc->cur_scp->font_size < 16))
1239 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1242 case GIO_FONT8x14: /* get 8x14 dot font */
1243 if (!ISFONTAVAIL(sc->adp->va_flags))
1245 if (sc->fonts_loaded & FONT_14) {
1246 bcopy(sc->font_14, data, 14*256);
1252 case PIO_FONT8x16: /* set 8x16 dot font */
1253 if (!ISFONTAVAIL(sc->adp->va_flags))
1255 bcopy(data, sc->font_16, 16*256);
1256 sc->fonts_loaded |= FONT_16;
1259 * Always use the font page #0. XXX
1260 * Don't load if the current font size is not 8x16.
1262 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1263 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1266 case GIO_FONT8x16: /* get 8x16 dot font */
1267 if (!ISFONTAVAIL(sc->adp->va_flags))
1269 if (sc->fonts_loaded & FONT_16) {
1270 bcopy(sc->font_16, data, 16*256);
1276 #endif /* SC_NO_FONT_LOADING */
1282 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1283 if (error != ENOIOCTL)
1285 error = ttioctl(tp, cmd, data, flag);
1286 if (error != ENOIOCTL)
1292 scstart(struct tty *tp)
1296 u_char buf[PCBURST];
1297 scr_stat *scp = SC_STAT(tp->t_dev);
1299 if (scp->status & SLKED ||
1300 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1303 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1304 tp->t_state |= TS_BUSY;
1307 len = q_to_b(rbp, buf, PCBURST);
1309 sc_puts(scp, buf, len);
1312 tp->t_state &= ~TS_BUSY;
1319 sccnprobe(struct consdev *cp)
1325 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1327 /* a video card is always required */
1328 if (!scvidprobe(unit, flags, TRUE))
1329 cp->cn_pri = CN_DEAD;
1331 /* syscons will become console even when there is no keyboard */
1332 sckbdprobe(unit, flags, TRUE);
1334 if (cp->cn_pri == CN_DEAD)
1337 /* initialize required fields */
1338 cp->cn_dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
1339 UID_ROOT, GID_WHEEL, 0600, "consolectl");
1340 #endif /* __i386__ */
1344 sccninit(struct consdev *cp)
1350 sc_get_cons_priority(&unit, &flags);
1351 scinit(unit, flags | SC_KERNEL_CONSOLE);
1352 sc_console_unit = unit;
1353 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1354 #endif /* __i386__ */
1358 sccnterm(struct consdev *cp)
1360 /* we are not the kernel console any more, release everything */
1362 if (sc_console_unit < 0)
1363 return; /* shouldn't happen */
1367 sc_clear_screen(sc_console);
1368 sccnupdate(sc_console);
1370 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1371 sc_console_unit = -1;
1373 #endif /* __i386__ */
1377 sccnputc(dev_t dev, int c)
1380 scr_stat *scp = sc_console;
1382 #ifndef SC_NO_HISTORY
1384 #endif /* !SC_NO_HISTORY */
1387 /* assert(sc_console != NULL) */
1389 #ifndef SC_NO_HISTORY
1390 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1391 scp->status &= ~SLKED;
1392 update_kbd_state(scp, scp->status, SLKED);
1393 if (scp->status & BUFFER_SAVED) {
1394 if (!sc_hist_restore(scp))
1395 sc_remove_cutmarking(scp);
1396 scp->status &= ~BUFFER_SAVED;
1397 scp->status |= CURSOR_ENABLED;
1398 sc_draw_cursor_image(scp);
1400 tp = VIRTUAL_TTY(scp->sc, scp->index);
1404 #endif /* !SC_NO_HISTORY */
1407 if (kernel_console_ts != NULL)
1408 scp->ts = kernel_console_ts;
1410 sc_puts(scp, buf, 1);
1413 s = spltty(); /* block sckbdevent and scrn_timer */
1421 return sccngetch(0);
1425 sccncheckc(dev_t dev)
1427 return sccngetch(SCGETC_NONBLOCK);
1431 sccndbctl(dev_t dev, int on)
1433 /* assert(sc_console_unit >= 0) */
1434 /* try to switch to the kernel console screen */
1435 if (on && debugger == 0) {
1437 * TRY to make sure the screen saver is stopped,
1438 * and the screen is updated before switching to
1443 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1444 && sc_console->smode.mode == VT_AUTO) {
1445 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1446 sc_switch_scr(sc_console->sc, sc_console->index);
1456 sccngetch(int flags)
1458 static struct fkeytab fkey;
1463 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1466 /* assert(sc_console != NULL) */
1469 * Stop the screen saver and update the screen if necessary.
1470 * What if we have been running in the screen saver code... XXX
1472 sc_touch_scrn_saver();
1473 scp = sc_console->sc->cur_scp; /* XXX */
1476 if (fkeycp < fkey.len) {
1478 return fkey.str[fkeycp++];
1481 if (scp->sc->kbd == NULL) {
1487 * Make sure the keyboard is accessible even when the kbd device
1488 * driver is disabled.
1490 kbd_enable(scp->sc->kbd);
1492 /* we shall always use the keyboard in the XLATE mode here */
1493 cur_mode = scp->kbd_mode;
1494 scp->kbd_mode = K_XLATE;
1495 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1497 kbd_poll(scp->sc->kbd, TRUE);
1498 c = scgetc(scp->sc, SCGETC_CN | flags);
1499 kbd_poll(scp->sc->kbd, FALSE);
1501 scp->kbd_mode = cur_mode;
1502 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1503 kbd_disable(scp->sc->kbd);
1506 switch (KEYFLAGS(c)) {
1507 case 0: /* normal char */
1509 case FKEY: /* function key */
1510 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1512 if ((p != NULL) && (fkey.len > 0)) {
1513 bcopy(p, fkey.str, fkey.len);
1527 sccnupdate(scr_stat *scp)
1529 /* this is a cut-down version of scrn_timer()... */
1531 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1534 if (debugger > 0 || panicstr || shutdown_in_progress) {
1535 sc_touch_scrn_saver();
1536 } else if (scp != scp->sc->cur_scp) {
1540 if (!run_scrn_saver)
1541 scp->sc->flags &= ~SC_SCRN_IDLE;
1543 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1544 if (scp->sc->flags & SC_SCRN_BLANKED)
1545 stop_scrn_saver(scp->sc, current_saver);
1546 #endif /* NSPLASH */
1548 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1549 || scp->sc->switch_in_progress)
1552 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1553 * when write_in_progress is non-zero. XXX
1556 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1557 scrn_update(scp, TRUE);
1561 scrn_timer(void *arg)
1563 static int kbd_interval = 0;
1570 again = (arg != NULL);
1572 sc = (sc_softc_t *)arg;
1573 else if (sc_console != NULL)
1574 sc = sc_console->sc;
1578 /* don't do anything when we are performing some I/O operations */
1579 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1581 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1586 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1587 /* try to allocate a keyboard automatically */
1588 if (++kbd_interval >= 25) {
1589 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1591 if (sc->keyboard >= 0) {
1592 sc->kbd = kbd_get_keyboard(sc->keyboard);
1593 kbd_ioctl(sc->kbd, KDSKBMODE,
1594 (caddr_t)&sc->cur_scp->kbd_mode);
1595 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1602 /* find the vty to update */
1605 /* should we stop the screen saver? */
1606 getmicrouptime(&tv);
1607 if (debugger > 0 || panicstr || shutdown_in_progress)
1608 sc_touch_scrn_saver();
1609 if (run_scrn_saver) {
1610 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1611 sc->flags |= SC_SCRN_IDLE;
1613 sc->flags &= ~SC_SCRN_IDLE;
1615 sc->scrn_time_stamp = tv.tv_sec;
1616 sc->flags &= ~SC_SCRN_IDLE;
1617 if (scrn_blank_time > 0)
1618 run_scrn_saver = TRUE;
1621 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1622 if (sc->flags & SC_SCRN_BLANKED)
1623 stop_scrn_saver(sc, current_saver);
1624 #endif /* NSPLASH */
1626 /* should we just return ? */
1627 if (sc->blink_in_progress || sc->switch_in_progress
1628 || sc->write_in_progress) {
1630 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1635 /* Update the screen */
1636 scp = sc->cur_scp; /* cur_scp may have changed... */
1637 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1638 scrn_update(scp, TRUE);
1641 /* should we activate the screen saver? */
1642 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1643 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1644 (*current_saver)(sc, TRUE);
1645 #endif /* NSPLASH */
1648 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1653 and_region(int *s1, int *e1, int s2, int e2)
1655 if (*e1 < s2 || e2 < *s1)
1657 *s1 = imax(*s1, s2);
1658 *e1 = imin(*e1, e2);
1663 scrn_update(scr_stat *scp, int show_cursor)
1670 /* assert(scp == scp->sc->cur_scp) */
1672 ++scp->sc->videoio_in_progress;
1674 #ifndef SC_NO_CUTPASTE
1675 /* remove the previous mouse pointer image if necessary */
1676 if (scp->status & MOUSE_VISIBLE) {
1678 e = scp->mouse_pos + scp->xsize + 1;
1679 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1680 || and_region(&s, &e, scp->start, scp->end)
1681 || ((scp->status & CURSOR_ENABLED) &&
1682 (scp->cursor_pos != scp->cursor_oldpos) &&
1683 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1684 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1685 sc_remove_mouse_image(scp);
1686 if (scp->end >= scp->xsize*scp->ysize)
1687 scp->end = scp->xsize*scp->ysize - 1;
1690 #endif /* !SC_NO_CUTPASTE */
1694 if (scp->end >= scp->xsize*scp->ysize) {
1695 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1696 scp->end = scp->xsize*scp->ysize - 1;
1698 if (scp->start < 0) {
1699 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1704 /* update screen image */
1705 if (scp->start <= scp->end) {
1706 if (scp->mouse_cut_end >= 0) {
1707 /* there is a marked region for cut & paste */
1708 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1709 start = scp->mouse_cut_start;
1710 end = scp->mouse_cut_end;
1712 start = scp->mouse_cut_end;
1713 end = scp->mouse_cut_start - 1;
1717 /* does the cut-mark region overlap with the update region? */
1718 if (and_region(&s, &e, scp->start, scp->end)) {
1719 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1722 if (and_region(&s, &e, scp->start, scp->end))
1723 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1725 e = scp->xsize*scp->ysize - 1;
1726 if (and_region(&s, &e, scp->start, scp->end))
1727 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1729 (*scp->rndr->draw)(scp, scp->start,
1730 scp->end - scp->start + 1, FALSE);
1733 (*scp->rndr->draw)(scp, scp->start,
1734 scp->end - scp->start + 1, FALSE);
1738 /* we are not to show the cursor and the mouse pointer... */
1741 scp->start = scp->xsize*scp->ysize - 1;
1742 --scp->sc->videoio_in_progress;
1746 /* update cursor image */
1747 if (scp->status & CURSOR_ENABLED) {
1750 /* did cursor move since last time ? */
1751 if (scp->cursor_pos != scp->cursor_oldpos) {
1752 /* do we need to remove old cursor image ? */
1753 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1754 sc_remove_cursor_image(scp);
1755 sc_draw_cursor_image(scp);
1757 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1758 /* cursor didn't move, but has been overwritten */
1759 sc_draw_cursor_image(scp);
1760 else if (scp->sc->flags & SC_BLINK_CURSOR)
1761 /* if it's a blinking cursor, update it */
1762 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1763 sc_inside_cutmark(scp,
1768 #ifndef SC_NO_CUTPASTE
1769 /* update "pseudo" mouse pointer image */
1770 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1771 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1772 scp->status &= ~MOUSE_MOVED;
1773 sc_draw_mouse_image(scp);
1776 #endif /* SC_NO_CUTPASTE */
1779 scp->start = scp->xsize*scp->ysize - 1;
1781 --scp->sc->videoio_in_progress;
1786 scsplash_callback(int event, void *arg)
1791 sc = (sc_softc_t *)arg;
1795 if (add_scrn_saver(scsplash_saver) == 0) {
1796 sc->flags &= ~SC_SAVER_FAILED;
1797 run_scrn_saver = TRUE;
1798 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1799 scsplash_stick(TRUE);
1800 (*current_saver)(sc, TRUE);
1806 if (current_saver == scsplash_saver) {
1807 scsplash_stick(FALSE);
1808 error = remove_scrn_saver(scsplash_saver);
1820 scsplash_saver(sc_softc_t *sc, int show)
1822 static int busy = FALSE;
1831 if (!(sc->flags & SC_SAVER_FAILED)) {
1832 if (!(sc->flags & SC_SCRN_BLANKED))
1833 set_scrn_saver_mode(scp, -1, NULL, 0);
1834 switch (splash(sc->adp, TRUE)) {
1835 case 0: /* succeeded */
1837 case EAGAIN: /* try later */
1838 restore_scrn_saver_mode(scp, FALSE);
1839 sc_touch_scrn_saver(); /* XXX */
1842 sc->flags |= SC_SAVER_FAILED;
1843 scsplash_stick(FALSE);
1844 restore_scrn_saver_mode(scp, TRUE);
1845 printf("scsplash_saver(): failed to put up the image\n");
1849 } else if (!sticky_splash) {
1850 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1851 restore_scrn_saver_mode(scp, TRUE);
1857 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1862 if (current_saver != none_saver) {
1863 error = remove_scrn_saver(current_saver);
1868 if (current_saver != none_saver)
1871 run_scrn_saver = FALSE;
1872 saver_mode = CONS_LKM_SAVER;
1873 current_saver = this_saver;
1878 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1880 if (current_saver != this_saver)
1885 * In order to prevent `current_saver' from being called by
1886 * the timeout routine `scrn_timer()' while we manipulate
1887 * the saver list, we shall set `current_saver' to `none_saver'
1888 * before stopping the current saver, rather than blocking by `splXX()'.
1890 current_saver = none_saver;
1892 stop_scrn_saver(this_saver);
1895 /* unblank all blanked screens */
1896 wait_scrn_saver_stop(NULL);
1900 current_saver = none_saver;
1905 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1909 /* assert(scp == scp->sc->cur_scp) */
1911 if (!ISGRAPHSC(scp))
1912 sc_remove_cursor_image(scp);
1913 scp->splash_save_mode = scp->mode;
1914 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1915 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1916 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1917 scp->sc->flags |= SC_SCRN_BLANKED;
1923 if (set_mode(scp) == 0) {
1924 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1925 scp->status |= GRAPHICS_MODE;
1926 #ifndef SC_NO_PALETTE_LOADING
1928 load_palette(scp->sc->adp, pal);
1930 sc_set_border(scp, border);
1934 scp->mode = scp->splash_save_mode;
1935 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1936 scp->status |= scp->splash_save_status;
1943 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1949 /* assert(scp == scp->sc->cur_scp) */
1952 status = scp->status;
1953 scp->mode = scp->splash_save_mode;
1954 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1955 scp->status |= scp->splash_save_status;
1956 scp->sc->flags &= ~SC_SCRN_BLANKED;
1958 if (!ISGRAPHSC(scp))
1959 sc_draw_cursor_image(scp);
1964 if (set_mode(scp) == 0) {
1965 #ifndef SC_NO_PALETTE_LOADING
1966 load_palette(scp->sc->adp, scp->sc->palette);
1973 scp->status = status;
1980 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
1982 (*saver)(sc, FALSE);
1983 run_scrn_saver = FALSE;
1984 /* the screen saver may have chosen not to stop after all... */
1985 if (sc->flags & SC_SCRN_BLANKED)
1988 mark_all(sc->cur_scp);
1989 if (sc->delayed_next_scr)
1990 sc_switch_scr(sc, sc->delayed_next_scr - 1);
1991 wakeup((caddr_t)&scrn_blanked);
1995 wait_scrn_saver_stop(sc_softc_t *sc)
1999 while (scrn_blanked > 0) {
2000 run_scrn_saver = FALSE;
2001 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2005 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2006 if ((error != 0) && (error != ERESTART))
2009 run_scrn_saver = FALSE;
2012 #endif /* NSPLASH */
2015 sc_touch_scrn_saver(void)
2017 scsplash_stick(FALSE);
2018 run_scrn_saver = FALSE;
2022 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2028 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2030 /* prevent switch if previously requested */
2031 if (sc->flags & SC_SCRN_VTYLOCK) {
2032 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2033 sc->cur_scp->bell_duration);
2037 /* delay switch if the screen is blanked or being updated */
2038 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2039 || sc->blink_in_progress || sc->videoio_in_progress) {
2040 sc->delayed_next_scr = next_scr + 1;
2041 sc_touch_scrn_saver();
2042 DPRINTF(5, ("switch delayed\n"));
2047 cur_scp = sc->cur_scp;
2049 /* we are in the middle of the vty switching process... */
2050 if (sc->switch_in_progress
2051 && (cur_scp->smode.mode == VT_PROCESS)
2053 if (cur_scp->proc != pfind(cur_scp->pid)) {
2055 * The controlling process has died!!. Do some clean up.
2056 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2057 * are not reset here yet; they will be cleared later.
2059 DPRINTF(5, ("cur_scp controlling process %d died, ",
2061 if (cur_scp->status & SWITCH_WAIT_REL) {
2063 * Force the previous switch to finish, but return now
2066 DPRINTF(5, ("reset WAIT_REL, "));
2067 finish_vt_rel(cur_scp, TRUE, &s);
2069 DPRINTF(5, ("finishing previous switch\n"));
2071 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2072 /* let's assume screen switch has been completed. */
2073 DPRINTF(5, ("reset WAIT_ACQ, "));
2074 finish_vt_acq(cur_scp);
2077 * We are in between screen release and acquisition, and
2078 * reached here via scgetc() or scrn_timer() which has
2079 * interrupted exchange_scr(). Don't do anything stupid.
2081 DPRINTF(5, ("waiting nothing, "));
2085 * The controlling process is alive, but not responding...
2086 * It is either buggy or it may be just taking time.
2087 * The following code is a gross kludge to cope with this
2088 * problem for which there is no clean solution. XXX
2090 if (cur_scp->status & SWITCH_WAIT_REL) {
2091 switch (sc->switch_in_progress++) {
2095 DPRINTF(5, ("sending relsig again, "));
2096 signal_vt_rel(cur_scp);
2103 * Act as if the controlling program returned
2106 DPRINTF(5, ("force reset WAIT_REL, "));
2107 finish_vt_rel(cur_scp, FALSE, &s);
2109 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2112 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2113 switch (sc->switch_in_progress++) {
2117 DPRINTF(5, ("sending acqsig again, "));
2118 signal_vt_acq(cur_scp);
2124 /* clear the flag and finish the previous switch */
2125 DPRINTF(5, ("force reset WAIT_ACQ, "));
2126 finish_vt_acq(cur_scp);
2134 * Return error if an invalid argument is given, or vty switch
2135 * is still in progress.
2137 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2138 || sc->switch_in_progress) {
2140 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2141 DPRINTF(5, ("error 1\n"));
2146 * Don't allow switching away from the graphics mode vty
2147 * if the switch mode is VT_AUTO, unless the next vty is the same
2148 * as the current or the current vty has been closed (but showing).
2150 tp = VIRTUAL_TTY(sc, cur_scp->index);
2151 if ((cur_scp->index != next_scr)
2153 && (cur_scp->smode.mode == VT_AUTO)
2154 && ISGRAPHSC(cur_scp)) {
2156 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2157 DPRINTF(5, ("error, graphics mode\n"));
2162 * Is the wanted vty open? Don't allow switching to a closed vty.
2163 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2164 * Note that we always allow the user to switch to the kernel
2165 * console even if it is closed.
2167 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2168 tp = VIRTUAL_TTY(sc, next_scr);
2169 if (!ISTTYOPEN(tp)) {
2171 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2172 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2175 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2177 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2182 /* this is the start of vty switching process... */
2183 ++sc->switch_in_progress;
2184 sc->delayed_next_scr = 0;
2185 sc->old_scp = cur_scp;
2186 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2187 if (sc->new_scp == sc->old_scp) {
2188 sc->switch_in_progress = 0;
2189 wakeup((caddr_t)&sc->new_scp->smode);
2191 DPRINTF(5, ("switch done (new == old)\n"));
2195 /* has controlling process died? */
2196 vt_proc_alive(sc->old_scp);
2197 vt_proc_alive(sc->new_scp);
2199 /* wait for the controlling process to release the screen, if necessary */
2200 if (signal_vt_rel(sc->old_scp)) {
2205 /* go set up the new vty screen */
2210 /* wake up processes waiting for this vty */
2211 wakeup((caddr_t)&sc->cur_scp->smode);
2213 /* wait for the controlling process to acknowledge, if necessary */
2214 if (signal_vt_acq(sc->cur_scp)) {
2219 sc->switch_in_progress = 0;
2220 if (sc->unit == sc_console_unit)
2221 cons_unavail = FALSE;
2223 DPRINTF(5, ("switch done\n"));
2229 do_switch_scr(sc_softc_t *sc, int s)
2231 vt_proc_alive(sc->new_scp);
2236 /* sc->cur_scp == sc->new_scp */
2237 wakeup((caddr_t)&sc->cur_scp->smode);
2239 /* wait for the controlling process to acknowledge, if necessary */
2240 if (!signal_vt_acq(sc->cur_scp)) {
2241 sc->switch_in_progress = 0;
2242 if (sc->unit == sc_console_unit)
2243 cons_unavail = FALSE;
2250 vt_proc_alive(scr_stat *scp)
2253 if (scp->proc == pfind(scp->pid))
2256 scp->smode.mode = VT_AUTO;
2257 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2263 signal_vt_rel(scr_stat *scp)
2265 if (scp->smode.mode != VT_PROCESS)
2267 scp->status |= SWITCH_WAIT_REL;
2268 psignal(scp->proc, scp->smode.relsig);
2269 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2274 signal_vt_acq(scr_stat *scp)
2276 if (scp->smode.mode != VT_PROCESS)
2278 if (scp->sc->unit == sc_console_unit)
2279 cons_unavail = TRUE;
2280 scp->status |= SWITCH_WAIT_ACQ;
2281 psignal(scp->proc, scp->smode.acqsig);
2282 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2287 finish_vt_rel(scr_stat *scp, int release, int *s)
2289 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2290 scp->status &= ~SWITCH_WAIT_REL;
2292 *s = do_switch_scr(scp->sc, *s);
2294 scp->sc->switch_in_progress = 0;
2301 finish_vt_acq(scr_stat *scp)
2303 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2304 scp->status &= ~SWITCH_WAIT_ACQ;
2305 scp->sc->switch_in_progress = 0;
2312 exchange_scr(sc_softc_t *sc)
2316 /* save the current state of video and keyboard */
2317 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2318 if (!ISGRAPHSC(sc->old_scp))
2319 sc_remove_cursor_image(sc->old_scp);
2320 if (sc->old_scp->kbd_mode == K_XLATE)
2321 save_kbd_state(sc->old_scp);
2323 /* set up the video for the new screen */
2324 scp = sc->cur_scp = sc->new_scp;
2325 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2328 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2329 (void *)sc->adp->va_window, FALSE);
2330 scp->status |= MOUSE_HIDDEN;
2331 sc_move_cursor(scp, scp->xpos, scp->ypos);
2332 if (!ISGRAPHSC(scp))
2333 sc_set_cursor_image(scp);
2334 #ifndef SC_NO_PALETTE_LOADING
2335 if (ISGRAPHSC(sc->old_scp))
2336 load_palette(sc->adp, sc->palette);
2338 sc_set_border(scp, scp->border);
2340 /* set up the keyboard for the new screen */
2341 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2342 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2343 update_kbd_state(scp, scp->status, LOCK_MASK);
2349 sc_puts(scr_stat *scp, u_char *buf, int len)
2352 /* make screensaver happy */
2353 if (!sticky_splash && scp == scp->sc->cur_scp)
2354 run_scrn_saver = FALSE;
2358 (*scp->tsw->te_puts)(scp, buf, len);
2360 if (scp->sc->delayed_next_scr)
2361 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2365 sc_draw_cursor_image(scr_stat *scp)
2367 /* assert(scp == scp->sc->cur_scp); */
2368 ++scp->sc->videoio_in_progress;
2369 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2370 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2371 sc_inside_cutmark(scp, scp->cursor_pos));
2372 scp->cursor_oldpos = scp->cursor_pos;
2373 --scp->sc->videoio_in_progress;
2377 sc_remove_cursor_image(scr_stat *scp)
2379 /* assert(scp == scp->sc->cur_scp); */
2380 ++scp->sc->videoio_in_progress;
2381 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2382 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2383 sc_inside_cutmark(scp, scp->cursor_oldpos));
2384 --scp->sc->videoio_in_progress;
2388 update_cursor_image(scr_stat *scp)
2392 if (scp->sc->flags & SC_CHAR_CURSOR) {
2393 scp->cursor_base = imax(0, scp->sc->cursor_base);
2394 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2396 scp->cursor_base = 0;
2397 scp->cursor_height = scp->font_size;
2399 blink = scp->sc->flags & SC_BLINK_CURSOR;
2401 /* assert(scp == scp->sc->cur_scp); */
2402 ++scp->sc->videoio_in_progress;
2403 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2404 sc_inside_cutmark(scp, scp->cursor_pos));
2405 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2406 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2407 sc_inside_cutmark(scp, scp->cursor_pos));
2408 --scp->sc->videoio_in_progress;
2412 sc_set_cursor_image(scr_stat *scp)
2414 if (scp->sc->flags & SC_CHAR_CURSOR) {
2415 scp->cursor_base = imax(0, scp->sc->cursor_base);
2416 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2418 scp->cursor_base = 0;
2419 scp->cursor_height = scp->font_size;
2422 /* assert(scp == scp->sc->cur_scp); */
2423 ++scp->sc->videoio_in_progress;
2424 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2425 scp->sc->flags & SC_BLINK_CURSOR);
2426 --scp->sc->videoio_in_progress;
2430 scinit(int unit, int flags)
2433 * When syscons is being initialized as the kernel console, malloc()
2434 * is not yet functional, because various kernel structures has not been
2435 * fully initialized yet. Therefore, we need to declare the following
2436 * static buffers for the console. This is less than ideal,
2437 * but is necessry evil for the time being. XXX
2439 static scr_stat main_console;
2440 static dev_t main_devs[MAXCONS];
2441 static struct tty main_tty;
2442 static u_short sc_buffer[ROW*COL]; /* XXX */
2443 #ifndef SC_NO_FONT_LOADING
2444 static u_char font_8[256*8];
2445 static u_char font_14[256*14];
2446 static u_char font_16[256*16];
2451 video_adapter_t *adp;
2456 /* one time initialization */
2457 if (init_done == COLD)
2458 sc_get_bios_values(&bios_value);
2462 * Allocate resources. Even if we are being called for the second
2463 * time, we must allocate them again, because they might have
2466 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2468 if (sc->adapter >= 0) {
2469 vid_release(sc->adp, (void *)&sc->adapter);
2473 if (sc->keyboard >= 0) {
2474 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2475 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2476 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2477 if (sc->kbd != NULL) {
2478 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2479 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2483 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2484 sc->adp = vid_get_adapter(sc->adapter);
2485 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2486 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2488 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2489 sc->kbd = kbd_get_keyboard(sc->keyboard);
2490 if (sc->kbd != NULL) {
2491 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2492 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2495 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2497 sc->initial_mode = sc->adp->va_initial_mode;
2499 #ifndef SC_NO_FONT_LOADING
2500 if (flags & SC_KERNEL_CONSOLE) {
2501 sc->font_8 = font_8;
2502 sc->font_14 = font_14;
2503 sc->font_16 = font_16;
2504 } else if (sc->font_8 == NULL) {
2505 /* assert(sc_malloc) */
2506 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2507 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2508 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2512 /* extract the hardware cursor location and hide the cursor for now */
2513 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2514 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2516 /* set up the first console */
2517 sc->first_vty = unit*MAXCONS;
2518 sc->vtys = MAXCONS; /* XXX: should be configurable */
2519 if (flags & SC_KERNEL_CONSOLE) {
2520 sc->dev = main_devs;
2521 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2522 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2523 sc->dev[0]->si_tty = &main_tty;
2524 ttyregister(&main_tty);
2525 scp = &main_console;
2526 init_scp(sc, sc->first_vty, scp);
2527 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2528 (void *)sc_buffer, FALSE);
2529 if (sc_init_emulator(scp, SC_DFLT_TERM))
2530 sc_init_emulator(scp, "*");
2531 (*scp->tsw->te_default_attr)(scp,
2532 kernel_default.std_color,
2533 kernel_default.rev_color);
2535 /* assert(sc_malloc) */
2536 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
2537 bzero(sc->dev, sizeof(dev_t)*sc->vtys);
2538 sc->dev[0] = make_dev(&sc_cdevsw, unit*MAXCONS, UID_ROOT,
2539 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2540 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2541 scp = alloc_scp(sc, sc->first_vty);
2543 SC_STAT(sc->dev[0]) = scp;
2546 /* copy screen to temporary buffer */
2547 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2548 (void *)scp->sc->adp->va_window, FALSE);
2550 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2552 /* move cursors to the initial positions */
2553 if (col >= scp->xsize)
2555 if (row >= scp->ysize)
2556 row = scp->ysize - 1;
2559 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2560 if (bios_value.cursor_end < scp->font_size)
2561 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2563 sc->cursor_base = 0;
2564 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2565 sc->cursor_height = imin(i, scp->font_size);
2566 #ifndef SC_NO_SYSMOUSE
2567 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2569 if (!ISGRAPHSC(scp)) {
2570 sc_set_cursor_image(scp);
2571 sc_draw_cursor_image(scp);
2574 /* save font and palette */
2575 #ifndef SC_NO_FONT_LOADING
2576 sc->fonts_loaded = 0;
2577 if (ISFONTAVAIL(sc->adp->va_flags)) {
2579 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2580 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2581 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2582 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2583 if (scp->font_size < 14) {
2584 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2585 } else if (scp->font_size >= 16) {
2586 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2588 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2590 #else /* !SC_DFLT_FONT */
2591 if (scp->font_size < 14) {
2592 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2593 sc->fonts_loaded = FONT_8;
2594 } else if (scp->font_size >= 16) {
2595 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2596 sc->fonts_loaded = FONT_16;
2598 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2599 sc->fonts_loaded = FONT_14;
2601 #endif /* SC_DFLT_FONT */
2602 /* FONT KLUDGE: always use the font page #0. XXX */
2603 sc_show_font(scp, 0);
2605 #endif /* !SC_NO_FONT_LOADING */
2607 #ifndef SC_NO_PALETTE_LOADING
2608 save_palette(sc->adp, sc->palette);
2612 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2613 /* we are ready to put up the splash image! */
2614 splash_init(sc->adp, scsplash_callback, sc);
2615 sc->flags |= SC_SPLASH_SCRN;
2617 #endif /* NSPLASH */
2620 /* the rest is not necessary, if we have done it once */
2621 if (sc->flags & SC_INIT_DONE)
2624 /* initialize mapscrn arrays to a one to one map */
2625 for (i = 0; i < sizeof(sc->scr_map); i++)
2626 sc->scr_map[i] = sc->scr_rmap[i] = i;
2628 sc->flags |= SC_INIT_DONE;
2633 scterm(int unit, int flags)
2638 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2640 return; /* shouldn't happen */
2643 /* this console is no longer available for the splash screen */
2644 if (sc->flags & SC_SPLASH_SCRN) {
2645 splash_term(sc->adp);
2646 sc->flags &= ~SC_SPLASH_SCRN;
2648 #endif /* NSPLASH */
2651 /* move the hardware cursor to the upper-left corner */
2652 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2655 /* release the keyboard and the video card */
2656 if (sc->keyboard >= 0)
2657 kbd_release(sc->kbd, &sc->keyboard);
2658 if (sc->adapter >= 0)
2659 vid_release(sc->adp, &sc->adapter);
2661 /* stop the terminal emulator, if any */
2662 scp = SC_STAT(sc->dev[0]);
2664 (*scp->tsw->te_term)(scp, &scp->ts);
2665 if (scp->ts != NULL)
2666 free(scp->ts, M_DEVBUF);
2668 /* clear the structure */
2669 if (!(flags & SC_KERNEL_CONSOLE)) {
2670 /* XXX: We need delete_dev() for this */
2671 free(sc->dev, M_DEVBUF);
2673 /* XXX: We need a ttyunregister for this */
2674 free(sc->tty, M_DEVBUF);
2676 #ifndef SC_NO_FONT_LOADING
2677 free(sc->font_8, M_DEVBUF);
2678 free(sc->font_14, M_DEVBUF);
2679 free(sc->font_16, M_DEVBUF);
2681 /* XXX vtb, history */
2683 bzero(sc, sizeof(*sc));
2690 scshutdown(void *arg, int howto)
2692 /* assert(sc_console != NULL) */
2694 sc_touch_scrn_saver();
2695 if (!cold && sc_console
2696 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2697 && sc_console->smode.mode == VT_AUTO)
2698 sc_switch_scr(sc_console->sc, sc_console->index);
2699 shutdown_in_progress = TRUE;
2703 sc_clean_up(scr_stat *scp)
2707 #endif /* NSPLASH */
2709 if (scp->sc->flags & SC_SCRN_BLANKED) {
2710 sc_touch_scrn_saver();
2712 if ((error = wait_scrn_saver_stop(scp->sc)))
2714 #endif /* NSPLASH */
2716 scp->status |= MOUSE_HIDDEN;
2717 sc_remove_mouse_image(scp);
2718 sc_remove_cutmarking(scp);
2723 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2729 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2730 if (!discard && (old.vtb_flags & VTB_VALID)) {
2731 /* retain the current cursor position and buffer contants */
2732 scp->cursor_oldpos = scp->cursor_pos;
2734 * This works only if the old buffer has the same size as or larger
2735 * than the new one. XXX
2737 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2741 sc_vtb_destroy(&old);
2744 #ifndef SC_NO_SYSMOUSE
2745 /* move the mouse cursor at the center of the screen */
2746 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2751 *alloc_scp(sc_softc_t *sc, int vty)
2755 /* assert(sc_malloc) */
2757 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2758 init_scp(sc, vty, scp);
2760 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2761 if (sc_init_emulator(scp, SC_DFLT_TERM))
2762 sc_init_emulator(scp, "*");
2764 #ifndef SC_NO_CUTPASTE
2765 sc_alloc_cut_buffer(scp, TRUE);
2768 #ifndef SC_NO_HISTORY
2769 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2776 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2780 bzero(scp, sizeof(*scp));
2785 scp->mode = sc->initial_mode;
2786 callout_init(&scp->blink_screen_ch);
2787 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2788 if (info.vi_flags & V_INFO_GRAPHICS) {
2789 scp->status |= GRAPHICS_MODE;
2790 scp->xpixel = info.vi_width;
2791 scp->ypixel = info.vi_height;
2792 scp->xsize = info.vi_width/8;
2793 scp->ysize = info.vi_height/info.vi_cheight;
2797 scp->xsize = info.vi_width;
2798 scp->ysize = info.vi_height;
2799 scp->xpixel = scp->xsize*8;
2800 scp->ypixel = scp->ysize*info.vi_cheight;
2801 if (info.vi_cheight < 14) {
2803 #ifndef SC_NO_FONT_LOADING
2804 scp->font = sc->font_8;
2808 } else if (info.vi_cheight >= 16) {
2809 scp->font_size = 16;
2810 #ifndef SC_NO_FONT_LOADING
2811 scp->font = sc->font_16;
2816 scp->font_size = 14;
2817 #ifndef SC_NO_FONT_LOADING
2818 scp->font = sc->font_14;
2824 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2825 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2826 scp->xoff = scp->yoff = 0;
2827 scp->xpos = scp->ypos = 0;
2828 scp->start = scp->xsize * scp->ysize - 1;
2833 scp->border = BG_BLACK;
2834 scp->cursor_base = sc->cursor_base;
2835 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2836 scp->mouse_cut_start = scp->xsize*scp->ysize;
2837 scp->mouse_cut_end = -1;
2838 scp->mouse_signal = 0;
2840 scp->mouse_proc = NULL;
2841 scp->kbd_mode = K_XLATE;
2842 scp->bell_pitch = bios_value.bell_pitch;
2843 scp->bell_duration = BELL_DURATION;
2844 scp->status |= (bios_value.shift_state & NLKED);
2845 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2848 scp->smode.mode = VT_AUTO;
2849 scp->history = NULL;
2850 scp->history_pos = 0;
2851 scp->history_size = 0;
2855 sc_init_emulator(scr_stat *scp, char *name)
2862 if (name == NULL) /* if no name is given, use the current emulator */
2864 else /* ...otherwise find the named emulator */
2865 sw = sc_term_match(name);
2870 if (strcmp(sw->te_renderer, "*") != 0) {
2871 rndr = sc_render_match(scp, sw->te_renderer,
2872 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2875 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2876 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2881 if (sw == scp->tsw) {
2882 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2884 scp->rndr->init(scp);
2885 sc_clear_screen(scp);
2886 /* assert(error == 0); */
2890 if (sc_malloc && (sw->te_size > 0))
2891 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
2894 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2899 (*scp->tsw->te_term)(scp, &scp->ts);
2900 if (scp->ts != NULL)
2901 free(scp->ts, M_DEVBUF);
2905 scp->rndr->init(scp);
2908 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2909 sc_clear_screen(scp);
2915 * scgetc(flags) - get character from keyboard.
2916 * If flags & SCGETC_CN, then avoid harmful side effects.
2917 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2918 * return NOKEY if there is nothing there.
2921 scgetc(sc_softc_t *sc, u_int flags)
2924 #ifndef SC_NO_HISTORY
2932 if (sc->kbd == NULL)
2937 /* I don't like this, but... XXX */
2938 if (flags & SCGETC_CN)
2939 sccnupdate(sc->cur_scp);
2942 /* first see if there is something in the keyboard port */
2944 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2946 if (!(flags & SCGETC_CN))
2947 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2948 } else if (c == NOKEY)
2954 /* make screensaver happy */
2956 sc_touch_scrn_saver();
2959 if (!(flags & SCGETC_CN))
2960 /* do the /dev/random device a favour */
2961 add_keyboard_randomness(c);
2964 if (scp->kbd_mode != K_XLATE)
2967 /* if scroll-lock pressed allow history browsing */
2968 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
2970 scp->status &= ~CURSOR_ENABLED;
2971 sc_remove_cursor_image(scp);
2973 #ifndef SC_NO_HISTORY
2974 if (!(scp->status & BUFFER_SAVED)) {
2975 scp->status |= BUFFER_SAVED;
2979 /* FIXME: key codes */
2980 case SPCLKEY | FKEY | F(49): /* home key */
2981 sc_remove_cutmarking(scp);
2985 case SPCLKEY | FKEY | F(57): /* end key */
2986 sc_remove_cutmarking(scp);
2990 case SPCLKEY | FKEY | F(50): /* up arrow key */
2991 sc_remove_cutmarking(scp);
2992 if (sc_hist_up_line(scp))
2993 if (!(flags & SCGETC_CN))
2994 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2997 case SPCLKEY | FKEY | F(58): /* down arrow key */
2998 sc_remove_cutmarking(scp);
2999 if (sc_hist_down_line(scp))
3000 if (!(flags & SCGETC_CN))
3001 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3004 case SPCLKEY | FKEY | F(51): /* page up key */
3005 sc_remove_cutmarking(scp);
3006 for (i=0; i<scp->ysize; i++)
3007 if (sc_hist_up_line(scp)) {
3008 if (!(flags & SCGETC_CN))
3009 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3014 case SPCLKEY | FKEY | F(59): /* page down key */
3015 sc_remove_cutmarking(scp);
3016 for (i=0; i<scp->ysize; i++)
3017 if (sc_hist_down_line(scp)) {
3018 if (!(flags & SCGETC_CN))
3019 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3024 #endif /* SC_NO_HISTORY */
3028 * Process and consume special keys here. Return a plain char code
3029 * or a char code with the META flag or a function key code.
3033 /* goto next_code */
3038 switch (KEYCHAR(c)) {
3040 case NLK: case CLK: case ALK:
3043 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3045 scp->status |= SLKED;
3047 if (scp->status & SLKED) {
3048 scp->status &= ~SLKED;
3049 #ifndef SC_NO_HISTORY
3050 if (scp->status & BUFFER_SAVED) {
3051 if (!sc_hist_restore(scp))
3052 sc_remove_cutmarking(scp);
3053 scp->status &= ~BUFFER_SAVED;
3054 scp->status |= CURSOR_ENABLED;
3055 sc_draw_cursor_image(scp);
3057 tp = VIRTUAL_TTY(sc, scp->index);
3065 /* NON-LOCKING KEYS */
3067 case LSH: case RSH: case LCTR: case RCTR:
3068 case LALT: case RALT: case ASH: case META:
3072 if (!(sc->flags & SC_SCRN_BLANKED))
3078 /* force activatation/deactivation of the screen saver */
3079 if (!(sc->flags & SC_SCRN_BLANKED)) {
3080 run_scrn_saver = TRUE;
3081 sc->scrn_time_stamp -= scrn_blank_time;
3085 * While devices are being probed, the screen saver need
3086 * to be invoked explictly. XXX
3088 if (sc->flags & SC_SCRN_BLANKED) {
3089 scsplash_stick(FALSE);
3090 stop_scrn_saver(sc, current_saver);
3092 if (!ISGRAPHSC(scp)) {
3093 scsplash_stick(TRUE);
3094 (*current_saver)(sc, TRUE);
3098 #endif /* NSPLASH */
3102 #ifndef SC_DISABLE_REBOOT
3108 #ifndef SC_DISABLE_REBOOT
3109 shutdown_nice(RB_HALT);
3114 #ifndef SC_DISABLE_REBOOT
3115 shutdown_nice(RB_HALT|RB_POWEROFF);
3121 apm_suspend(PMST_SUSPEND);
3124 apm_suspend(PMST_STANDBY);
3133 #ifndef SC_DISABLE_DDBKEY
3135 Debugger("manual escape to debugger");
3137 printf("No debugger in kernel\n");
3139 #else /* SC_DISABLE_DDBKEY */
3141 #endif /* SC_DISABLE_DDBKEY */
3145 if (enable_panic_key)
3146 panic("Forced by the panic key");
3150 this_scr = scp->index;
3151 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3152 sc->first_vty + i != this_scr;
3153 i = (i + 1)%sc->vtys) {
3154 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3155 if (ISTTYOPEN(tp)) {
3156 sc_switch_scr(scp->sc, sc->first_vty + i);
3163 this_scr = scp->index;
3164 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3165 sc->first_vty + i != this_scr;
3166 i = (i + sc->vtys - 1)%sc->vtys) {
3167 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3168 if (ISTTYOPEN(tp)) {
3169 sc_switch_scr(scp->sc, sc->first_vty + i);
3176 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3177 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3180 /* assert(c & FKEY) */
3181 if (!(sc->flags & SC_SCRN_BLANKED))
3185 /* goto next_code */
3187 /* regular keys (maybe MKEY is set) */
3188 if (!(sc->flags & SC_SCRN_BLANKED))
3197 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3202 if (scp != scp->sc->cur_scp)
3204 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3208 save_kbd_state(scr_stat *scp)
3213 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3214 if (error == ENOIOCTL)
3217 scp->status &= ~LOCK_MASK;
3218 scp->status |= state;
3224 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3229 if (mask != LOCK_MASK) {
3230 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3231 if (error == ENOIOCTL)
3236 state |= new_bits & mask;
3238 state = new_bits & LOCK_MASK;
3240 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3241 if (error == ENOIOCTL)
3247 update_kbd_leds(scr_stat *scp, int which)
3252 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3253 if (error == ENOIOCTL)
3259 set_mode(scr_stat *scp)
3263 /* reject unsupported mode */
3264 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3267 /* if this vty is not currently showing, do nothing */
3268 if (scp != scp->sc->cur_scp)
3271 /* setup video hardware for the given mode */
3272 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3273 scp->rndr->init(scp);
3274 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3275 (void *)scp->sc->adp->va_window, FALSE);
3277 #ifndef SC_NO_FONT_LOADING
3278 /* load appropriate font */
3279 if (!(scp->status & GRAPHICS_MODE)) {
3280 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3281 if (scp->font_size < 14) {
3282 if (scp->sc->fonts_loaded & FONT_8)
3283 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3284 } else if (scp->font_size >= 16) {
3285 if (scp->sc->fonts_loaded & FONT_16)
3286 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3288 if (scp->sc->fonts_loaded & FONT_14)
3289 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3293 * This is an interim kludge to display correct font.
3294 * Always use the font page #0 on the video plane 2.
3295 * Somehow we cannot show the font in other font pages on
3296 * some video cards... XXX
3298 sc_show_font(scp, 0);
3302 #endif /* !SC_NO_FONT_LOADING */
3304 sc_set_border(scp, scp->border);
3305 sc_set_cursor_image(scp);
3311 sc_set_border(scr_stat *scp, int color)
3313 ++scp->sc->videoio_in_progress;
3314 (*scp->rndr->draw_border)(scp, color);
3315 --scp->sc->videoio_in_progress;
3318 #ifndef SC_NO_FONT_LOADING
3320 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3321 int base, int count)
3326 sc->font_loading_in_progress = TRUE;
3327 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3328 sc->font_loading_in_progress = FALSE;
3332 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3333 int base, int count)
3338 sc->font_loading_in_progress = TRUE;
3339 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3340 sc->font_loading_in_progress = FALSE;
3344 sc_show_font(scr_stat *scp, int page)
3346 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3348 #endif /* !SC_NO_FONT_LOADING */
3351 sc_paste(scr_stat *scp, u_char *p, int count)
3356 if (scp->status & MOUSE_VISIBLE) {
3357 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3360 rmap = scp->sc->scr_rmap;
3361 for (; count > 0; --count)
3362 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3367 sc_bell(scr_stat *scp, int pitch, int duration)
3369 if (cold || shutdown_in_progress)
3372 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3375 if (scp->sc->flags & SC_VISUAL_BELL) {
3376 if (scp->sc->blink_in_progress)
3378 scp->sc->blink_in_progress = 3;
3379 if (scp != scp->sc->cur_scp)
3380 scp->sc->blink_in_progress += 2;
3381 blink_screen(scp->sc->cur_scp);
3382 } else if (duration != 0 && pitch != 0) {
3383 if (scp != scp->sc->cur_scp)
3385 sysbeep(pitch, duration);
3390 blink_screen(void *arg)
3392 scr_stat *scp = arg;
3395 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3396 scp->sc->blink_in_progress = 0;
3398 tp = VIRTUAL_TTY(scp->sc, scp->index);
3401 if (scp->sc->delayed_next_scr)
3402 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3405 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3406 scp->sc->blink_in_progress & 1);
3407 scp->sc->blink_in_progress--;
3408 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);