2 * Copyright (c) 1992-1998 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/dev/syscons/syscons.c,v 1.336.2.15 2002/10/24 00:35:31 kbyanc Exp $
32 #include "opt_syscons.h"
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/eventhandler.h>
41 #include <sys/reboot.h>
44 #include <sys/signalvar.h>
45 #include <sys/sysctl.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
50 #include <sys/random.h>
52 #include <machine/clock.h>
53 #include <machine/console.h>
54 #include <machine/psl.h>
55 #include <machine/pc/display.h>
57 #include <machine/apm_bios.h>
58 #include <machine/frame.h>
61 #include <dev/kbd/kbdreg.h>
62 #include <dev/fb/fbreg.h>
63 #include <dev/fb/splashreg.h>
64 #include <dev/syscons/syscons.h>
69 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
70 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
72 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
74 typedef struct default_attr {
75 int std_color; /* normal hardware color */
76 int rev_color; /* reverse hardware color */
79 static default_attr user_default = {
84 static default_attr kernel_default = {
86 SC_KERNEL_CONS_REV_ATTR,
89 static int sc_console_unit = -1;
90 static scr_stat *sc_console;
91 static struct tty *sc_console_tty;
92 static void *kernel_console_ts;
94 static char init_done = COLD;
95 static char shutdown_in_progress = FALSE;
96 static char sc_malloc = FALSE;
98 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
99 static int run_scrn_saver = FALSE; /* should run the saver? */
100 static long scrn_blank_time = 0; /* screen saver timeout value */
102 static int scrn_blanked; /* # of blanked screen */
103 static int sticky_splash = FALSE;
105 static void none_saver(sc_softc_t *sc, int blank) { }
106 static void (*current_saver)(sc_softc_t *, int) = none_saver;
109 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
113 d_ioctl_t *sc_user_ioctl;
115 static bios_values_t bios_value;
117 static int enable_panic_key;
118 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
121 #define SC_CONSOLECTL 255
123 #define VIRTUAL_TTY(sc, x) (SC_DEV((sc), (x)) != NULL ? \
124 SC_DEV((sc), (x))->si_tty : NULL)
125 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
130 static int scvidprobe(int unit, int flags, int cons);
131 static int sckbdprobe(int unit, int flags, int cons);
132 static void scmeminit(void *arg);
133 static int scdevtounit(dev_t dev);
134 static kbd_callback_func_t sckbdevent;
135 static int scparam(struct tty *tp, struct termios *t);
136 static void scstart(struct tty *tp);
137 static void scinit(int unit, int flags);
139 static void scterm(int unit, int flags);
141 static void scshutdown(void *arg, int howto);
142 static u_int scgetc(sc_softc_t *sc, u_int flags);
144 #define SCGETC_NONBLOCK 2
145 static int sccngetch(int flags);
146 static void sccnupdate(scr_stat *scp);
147 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
148 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
149 static timeout_t scrn_timer;
150 static int and_region(int *s1, int *e1, int s2, int e2);
151 static void scrn_update(scr_stat *scp, int show_cursor);
154 static int scsplash_callback(int event, void *arg);
155 static void scsplash_saver(sc_softc_t *sc, int show);
156 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
157 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
158 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
159 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
160 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
161 static int wait_scrn_saver_stop(sc_softc_t *sc);
162 #define scsplash_stick(stick) (sticky_splash = (stick))
164 #define scsplash_stick(stick)
167 static int do_switch_scr(sc_softc_t *sc, int s);
168 static int vt_proc_alive(scr_stat *scp);
169 static int signal_vt_rel(scr_stat *scp);
170 static int signal_vt_acq(scr_stat *scp);
171 static int finish_vt_rel(scr_stat *scp, int release, int *s);
172 static int finish_vt_acq(scr_stat *scp);
173 static void exchange_scr(sc_softc_t *sc);
174 static void update_cursor_image(scr_stat *scp);
175 static int save_kbd_state(scr_stat *scp);
176 static int update_kbd_state(scr_stat *scp, int state, int mask);
177 static int update_kbd_leds(scr_stat *scp, int which);
178 static timeout_t blink_screen;
180 #define CDEV_MAJOR 12
182 static cn_probe_t sccnprobe;
183 static cn_init_t sccninit;
184 static cn_getc_t sccngetc;
185 static cn_checkc_t sccncheckc;
186 static cn_putc_t sccnputc;
187 static cn_dbctl_t sccndbctl;
188 static cn_term_t sccnterm;
191 void sccnattach(void);
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 = {
207 /* write */ ttywrite,
211 /* strategy */ nostrategy,
213 /* maj */ CDEV_MAJOR,
216 /* flags */ D_TTY | D_KQFILTER,
218 /* kqfilter */ ttykqfilter
222 sc_probe_unit(int unit, int flags)
224 if (!scvidprobe(unit, flags, FALSE)) {
226 printf("sc%d: no video adapter found.\n", unit);
230 /* syscons will be attached even when there is no keyboard */
231 sckbdprobe(unit, flags, FALSE);
236 /* probe video adapters, return TRUE if found */
238 scvidprobe(int unit, int flags, int cons)
241 * Access the video adapter driver through the back door!
242 * Video adapter drivers need to be configured before syscons.
243 * However, when syscons is being probed as the low-level console,
244 * they have not been initialized yet. We force them to initialize
245 * themselves here. XXX
247 vid_configure(cons ? VIO_PROBE_ONLY : 0);
249 return (vid_find_adapter("*", unit) >= 0);
252 /* probe the keyboard, return TRUE if found */
254 sckbdprobe(int unit, int flags, int cons)
256 /* access the keyboard driver through the backdoor! */
257 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
259 return (kbd_find_keyboard("*", unit) >= 0);
263 *adapter_name(video_adapter_t *adp)
269 { KD_MONO, { "MDA", "MDA" } },
270 { KD_HERCULES, { "Hercules", "Hercules" } },
271 { KD_CGA, { "CGA", "CGA" } },
272 { KD_EGA, { "EGA", "EGA (mono)" } },
273 { KD_VGA, { "VGA", "VGA (mono)" } },
274 { KD_PC98, { "PC-98x1", "PC-98x1" } },
275 { KD_TGA, { "TGA", "TGA" } },
276 { -1, { "Unknown", "Unknown" } },
280 for (i = 0; names[i].type != -1; ++i)
281 if (names[i].type == adp->va_type)
283 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
287 sc_attach_unit(int unit, int flags)
297 flags &= ~SC_KERNEL_CONSOLE;
299 if (sc_console_unit == unit) {
301 * If this unit is being used as the system console, we need to
302 * adjust some variables and buffers before and after scinit().
304 /* assert(sc_console != NULL) */
305 flags |= SC_KERNEL_CONSOLE;
310 if (sc_console->tsw->te_size > 0) {
311 /* assert(sc_console->ts != NULL); */
312 kernel_console_ts = sc_console->ts;
313 sc_console->ts = malloc(sc_console->tsw->te_size,
315 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
316 (*sc_console->tsw->te_default_attr)(sc_console,
317 user_default.std_color,
318 user_default.rev_color);
324 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
326 scp = SC_STAT(sc->dev[0]);
327 if (sc_console == NULL) /* sc_console_unit < 0 */
331 if ((sc->config & SC_VESA800X600)
332 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
334 if (sc->flags & SC_SPLASH_SCRN)
335 splash_term(sc->adp);
337 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
338 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
339 sc->initial_mode = M_VESA_800x600;
341 /* put up the splash again! */
342 if (sc->flags & SC_SPLASH_SCRN)
343 splash_init(sc->adp, scsplash_callback, sc);
346 #endif /* SC_PIXEL_MODE */
348 /* initialize cursor */
350 update_cursor_image(scp);
352 /* get screen update going */
355 /* set up the keyboard */
356 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
357 update_kbd_state(scp, scp->status, LOCK_MASK);
359 printf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
360 unit, adapter_name(sc->adp), sc->vtys, sc->config);
362 printf("sc%d:", unit);
363 if (sc->adapter >= 0)
364 printf(" fb%d", sc->adapter);
365 if (sc->keyboard >= 0)
366 printf(", kbd%d", sc->keyboard);
368 printf(", terminal emulator: %s (%s)",
369 scp->tsw->te_name, scp->tsw->te_desc);
373 /* register a shutdown callback for the kernel console */
374 if (sc_console_unit == unit)
375 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
376 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
378 for (vc = 0; vc < sc->vtys; vc++) {
379 dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
380 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
383 * The first vty already has struct tty and scr_stat initialized
384 * in scinit(). The other vtys will have these structs when
389 dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
390 UID_ROOT, GID_WHEEL, 0600, "consolectl");
391 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
392 SC_STAT(dev) = sc_console;
405 * As soon as malloc() becomes functional, we had better allocate
406 * various buffers for the kernel console.
409 if (sc_console_unit < 0) /* sc_console == NULL */
412 /* copy the temporary buffer to the final buffer */
413 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
415 #ifndef SC_NO_CUTPASTE
416 sc_alloc_cut_buffer(sc_console, FALSE);
419 #ifndef SC_NO_HISTORY
420 /* initialize history buffer & pointers */
421 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
426 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
429 scdevtounit(dev_t dev)
431 int vty = SC_VTY(dev);
433 if (vty == SC_CONSOLECTL)
434 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
435 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
442 scopen(dev_t dev, int flag, int mode, struct proc *p)
444 int unit = scdevtounit(dev);
451 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
452 major(dev), minor(dev), unit, SC_VTY(dev)));
454 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
458 tp = dev->si_tty = ttymalloc(dev->si_tty);
459 tp->t_oproc = scstart;
460 tp->t_param = scparam;
461 tp->t_stop = nottystop;
463 if (!ISTTYOPEN(tp)) {
465 /* Use the current setting of the <-- key as default VERASE. */
466 /* If the Delete key is preferable, an stty is necessary */
467 if (sc->kbd != NULL) {
468 key.keynum = KEYCODE_BS;
469 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
470 tp->t_cc[VERASE] = key.key.map[0];
472 tp->t_iflag = TTYDEF_IFLAG;
473 tp->t_oflag = TTYDEF_OFLAG;
474 tp->t_cflag = TTYDEF_CFLAG;
475 tp->t_lflag = TTYDEF_LFLAG;
476 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
477 scparam(tp, &tp->t_termios);
478 (*linesw[tp->t_line].l_modem)(tp, 1);
481 if (tp->t_state & TS_XCLUDE && suser(p))
484 error = (*linesw[tp->t_line].l_open)(dev, tp);
488 scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
490 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
492 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
493 tp->t_winsize.ws_col = scp->xsize;
494 tp->t_winsize.ws_row = scp->ysize;
501 scclose(dev_t dev, int flag, int mode, struct proc *p)
503 struct tty *tp = dev->si_tty;
507 if (SC_VTY(dev) != SC_CONSOLECTL) {
508 scp = SC_STAT(tp->t_dev);
509 /* were we in the middle of the VT switching process? */
510 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
512 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
513 cons_unavail = FALSE;
514 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
515 DPRINTF(5, ("reset WAIT_REL, "));
516 if (finish_vt_acq(scp) == 0) /* force acknowledge */
517 DPRINTF(5, ("reset WAIT_ACQ, "));
519 if (scp == &main_console) {
522 scp->smode.mode = VT_AUTO;
525 sc_vtb_destroy(&scp->vtb);
526 sc_vtb_destroy(&scp->scr);
527 sc_free_history_buffer(scp, scp->ysize);
534 scp->smode.mode = VT_AUTO;
536 scp->kbd_mode = K_XLATE;
537 if (scp == scp->sc->cur_scp)
538 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
539 DPRINTF(5, ("done.\n"));
542 (*linesw[tp->t_line].l_close)(tp, flag);
549 scread(dev_t dev, struct uio *uio, int flag)
551 sc_touch_scrn_saver();
552 return ttyread(dev, uio, flag);
556 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
564 sc = (sc_softc_t *)arg;
565 /* assert(thiskbd == sc->kbd) */
570 case KBDIO_UNLOADING:
573 kbd_release(thiskbd, (void *)&sc->keyboard);
580 * Loop while there is still input to get from the keyboard.
581 * I don't think this is nessesary, and it doesn't fix
582 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
584 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
586 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
587 if (!ISTTYOPEN(cur_tty)) {
588 cur_tty = sc_console_tty;
589 if (!ISTTYOPEN(cur_tty))
593 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
596 switch (KEYFLAGS(c)) {
597 case 0x0000: /* normal key */
598 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
600 case FKEY: /* function key, return string */
601 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
604 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
607 case MKEY: /* meta is active, prepend ESC */
608 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
609 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
611 case BKEY: /* backtab fixed sequence (esc [ Z) */
612 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
613 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
614 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
619 sc->cur_scp->status |= MOUSE_HIDDEN;
625 scparam(struct tty *tp, struct termios *t)
627 tp->t_ispeed = t->c_ispeed;
628 tp->t_ospeed = t->c_ospeed;
629 tp->t_cflag = t->c_cflag;
634 scioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
645 /* If there is a user_ioctl function call that first */
647 error = (*sc_user_ioctl)(dev, cmd, data, flag, p);
648 if (error != ENOIOCTL)
652 error = sc_vid_ioctl(tp, cmd, data, flag, p);
653 if (error != ENOIOCTL)
656 #ifndef SC_NO_HISTORY
657 error = sc_hist_ioctl(tp, cmd, data, flag, p);
658 if (error != ENOIOCTL)
662 #ifndef SC_NO_SYSMOUSE
663 error = sc_mouse_ioctl(tp, cmd, data, flag, p);
664 if (error != ENOIOCTL)
668 scp = SC_STAT(tp->t_dev);
669 /* assert(scp != NULL) */
670 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
674 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag, p);
675 if (error != ENOIOCTL)
679 switch (cmd) { /* process console hardware related ioctl's */
681 case GIO_ATTR: /* get current attributes */
682 /* this ioctl is not processed here, but in the terminal emulator */
685 case GIO_COLOR: /* is this a color console ? */
686 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
689 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
690 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
693 scrn_blank_time = *(int *)data;
694 run_scrn_saver = (scrn_blank_time != 0);
698 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
700 if (!ISGRAPHSC(sc->cur_scp))
701 sc_remove_cursor_image(sc->cur_scp);
702 if ((*(int*)data) & 0x01)
703 sc->flags |= SC_BLINK_CURSOR;
705 sc->flags &= ~SC_BLINK_CURSOR;
706 if ((*(int*)data) & 0x02) {
707 sc->flags |= SC_CHAR_CURSOR;
709 sc->flags &= ~SC_CHAR_CURSOR;
711 * The cursor shape is global property; all virtual consoles
712 * are affected. Update the cursor in the current console...
714 if (!ISGRAPHSC(sc->cur_scp)) {
715 sc_set_cursor_image(sc->cur_scp);
716 sc_draw_cursor_image(sc->cur_scp);
721 case CONS_BELLTYPE: /* set bell type sound/visual */
722 if ((*(int *)data) & 0x01)
723 sc->flags |= SC_VISUAL_BELL;
725 sc->flags &= ~SC_VISUAL_BELL;
726 if ((*(int *)data) & 0x02)
727 sc->flags |= SC_QUIET_BELL;
729 sc->flags &= ~SC_QUIET_BELL;
732 case CONS_GETINFO: /* get current (virtual) console info */
734 vid_info_t *ptr = (vid_info_t*)data;
735 if (ptr->size == sizeof(struct vid_info)) {
736 ptr->m_num = sc->cur_scp->index;
737 ptr->font_size = scp->font_size;
738 ptr->mv_col = scp->xpos;
739 ptr->mv_row = scp->ypos;
740 ptr->mv_csz = scp->xsize;
741 ptr->mv_rsz = scp->ysize;
743 * The following fields are filled by the terminal emulator. XXX
750 ptr->mv_grfc.fore = 0; /* not supported */
751 ptr->mv_grfc.back = 0; /* not supported */
752 ptr->mv_ovscan = scp->border;
753 if (scp == sc->cur_scp)
755 ptr->mk_keylock = scp->status & LOCK_MASK;
761 case CONS_GETVERS: /* get version number */
762 *(int*)data = 0x200; /* version 2.0 */
765 case CONS_IDLE: /* see if the screen has been idle */
767 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
768 * the user process may have been writing something on the
769 * screen and syscons is not aware of it. Declare the screen
770 * is NOT idle if it is in one of these modes. But there is
771 * an exception to it; if a screen saver is running in the
772 * graphics mode in the current screen, we should say that the
773 * screen has been idle.
775 *(int *)data = (sc->flags & SC_SCRN_IDLE)
776 && (!ISGRAPHSC(sc->cur_scp)
777 || (sc->cur_scp->status & SAVER_RUNNING));
780 case CONS_SAVERMODE: /* set saver mode */
781 switch(*(int *)data) {
784 /* if a LKM screen saver is running, stop it first. */
785 scsplash_stick(FALSE);
786 saver_mode = *(int *)data;
789 if ((error = wait_scrn_saver_stop(NULL))) {
794 run_scrn_saver = TRUE;
795 if (saver_mode == CONS_USR_SAVER)
796 scp->status |= SAVER_RUNNING;
798 scp->status &= ~SAVER_RUNNING;
799 scsplash_stick(TRUE);
804 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
805 scp->status &= ~SAVER_RUNNING;
806 saver_mode = *(int *)data;
814 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
816 * Note that this ioctl does not guarantee the screen saver
817 * actually starts or stops. It merely attempts to do so...
820 run_scrn_saver = (*(int *)data != 0);
822 sc->scrn_time_stamp -= scrn_blank_time;
826 case CONS_SCRSHOT: /* get a screen shot */
828 scrshot_t *ptr = (scrshot_t*)data;
830 if (ISGRAPHSC(scp)) {
834 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
838 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
839 ptr->xsize * ptr->ysize * sizeof(u_int16_t));
844 case VT_SETMODE: /* set screen switcher mode */
846 struct vt_mode *mode;
848 mode = (struct vt_mode *)data;
849 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
850 if (scp->smode.mode == VT_PROCESS) {
851 if (scp->proc == pfind(scp->pid) && scp->proc != p) {
852 DPRINTF(5, ("error EPERM\n"));
857 if (mode->mode == VT_AUTO) {
858 scp->smode.mode = VT_AUTO;
861 DPRINTF(5, ("VT_AUTO, "));
862 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
863 cons_unavail = FALSE;
864 /* were we in the middle of the vty switching process? */
865 if (finish_vt_rel(scp, TRUE, &s) == 0)
866 DPRINTF(5, ("reset WAIT_REL, "));
867 if (finish_vt_acq(scp) == 0)
868 DPRINTF(5, ("reset WAIT_ACQ, "));
870 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
871 || !ISSIGVALID(mode->frsig)) {
873 DPRINTF(5, ("error EINVAL\n"));
876 DPRINTF(5, ("VT_PROCESS %d, ", p->p_pid));
877 bcopy(data, &scp->smode, sizeof(struct vt_mode));
879 scp->pid = scp->proc->p_pid;
880 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
888 case VT_GETMODE: /* get screen switcher mode */
889 bcopy(&scp->smode, data, sizeof(struct vt_mode));
892 case VT_RELDISP: /* screen switcher ioctl */
895 * This must be the current vty which is in the VT_PROCESS
898 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
902 /* ...and this process is controlling it. */
903 if (scp->proc != p) {
908 switch(*(int *)data) {
909 case VT_FALSE: /* user refuses to release screen, abort */
910 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
911 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
913 case VT_TRUE: /* user has released screen, go on */
914 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
915 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
917 case VT_ACKACQ: /* acquire acknowledged, switch completed */
918 if ((error = finish_vt_acq(scp)) == 0)
919 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
927 case VT_OPENQRY: /* return free virtual console */
928 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
929 tp = VIRTUAL_TTY(sc, i);
930 if (!ISTTYOPEN(tp)) {
931 *(int *)data = i + 1;
937 case VT_ACTIVATE: /* switch to screen *data */
938 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
940 sc_clean_up(sc->cur_scp);
942 return sc_switch_scr(sc, i);
944 case VT_WAITACTIVE: /* wait for switch to occur */
945 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
946 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
949 error = sc_clean_up(sc->cur_scp);
953 scp = SC_STAT(SC_DEV(sc, i));
954 if (scp == scp->sc->cur_scp)
956 while ((error=tsleep((caddr_t)&scp->smode, PZERO|PCATCH,
957 "waitvt", 0)) == ERESTART) ;
960 case VT_GETACTIVE: /* get active vty # */
961 *(int *)data = sc->cur_scp->index + 1;
964 case VT_GETINDEX: /* get this vty # */
965 *(int *)data = scp->index + 1;
968 case VT_LOCKSWITCH: /* prevent vty switching */
969 if ((*(int *)data) & 0x01)
970 sc->flags |= SC_SCRN_VTYLOCK;
972 sc->flags &= ~SC_SCRN_VTYLOCK;
975 case KDENABIO: /* allow io operations */
982 p->p_md.md_regs->tf_eflags |= PSL_IOPL;
986 case KDDISABIO: /* disallow io operations (default) */
988 p->p_md.md_regs->tf_eflags &= ~PSL_IOPL;
992 case KDSKBSTATE: /* set keyboard state (locks) */
993 if (*(int *)data & ~LOCK_MASK)
995 scp->status &= ~LOCK_MASK;
996 scp->status |= *(int *)data;
997 if (scp == sc->cur_scp)
998 update_kbd_state(scp, scp->status, LOCK_MASK);
1001 case KDGKBSTATE: /* get keyboard state (locks) */
1002 if (scp == sc->cur_scp)
1003 save_kbd_state(scp);
1004 *(int *)data = scp->status & LOCK_MASK;
1007 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1008 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1009 error = kbd_ioctl(sc->kbd, cmd, data);
1010 if (error == ENOIOCTL)
1014 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1015 if (*(int *)data & ~0x7f)
1017 error = kbd_ioctl(sc->kbd, cmd, data);
1018 if (error == ENOIOCTL)
1022 case KDSKBMODE: /* set keyboard mode */
1023 switch (*(int *)data) {
1024 case K_XLATE: /* switch to XLT ascii mode */
1025 case K_RAW: /* switch to RAW scancode mode */
1026 case K_CODE: /* switch to CODE mode */
1027 scp->kbd_mode = *(int *)data;
1028 if (scp == sc->cur_scp)
1029 kbd_ioctl(sc->kbd, cmd, data);
1036 case KDGKBMODE: /* get keyboard mode */
1037 *(int *)data = scp->kbd_mode;
1041 error = kbd_ioctl(sc->kbd, cmd, data);
1042 if (error == ENOIOCTL)
1046 case KDMKTONE: /* sound the bell */
1048 sc_bell(scp, (*(int*)data)&0xffff,
1049 (((*(int*)data)>>16)&0xffff)*hz/1000);
1051 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1054 case KIOCSOUND: /* make tone (*data) hz */
1055 if (scp == sc->cur_scp) {
1057 return sc_tone(*(int *)data);
1063 case KDGKBTYPE: /* get keyboard type */
1064 error = kbd_ioctl(sc->kbd, cmd, data);
1065 if (error == ENOIOCTL) {
1066 /* always return something? XXX */
1071 case KDSETLED: /* set keyboard LED status */
1072 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1074 scp->status &= ~LED_MASK;
1075 scp->status |= *(int *)data;
1076 if (scp == sc->cur_scp)
1077 update_kbd_leds(scp, scp->status);
1080 case KDGETLED: /* get keyboard LED status */
1081 if (scp == sc->cur_scp)
1082 save_kbd_state(scp);
1083 *(int *)data = scp->status & LED_MASK;
1086 case CONS_SETKBD: /* set the new keyboard */
1091 newkbd = kbd_get_keyboard(*(int *)data);
1092 if (newkbd == NULL) {
1097 if (sc->kbd != newkbd) {
1098 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1099 (void *)&sc->keyboard, sckbdevent, sc);
1100 /* i == newkbd->kb_index */
1102 if (sc->kbd != NULL) {
1103 save_kbd_state(sc->cur_scp);
1104 kbd_release(sc->kbd, (void *)&sc->keyboard);
1106 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1108 kbd_ioctl(sc->kbd, KDSKBMODE,
1109 (caddr_t)&sc->cur_scp->kbd_mode);
1110 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1113 error = EPERM; /* XXX */
1120 case CONS_RELKBD: /* release the current keyboard */
1123 if (sc->kbd != NULL) {
1124 save_kbd_state(sc->cur_scp);
1125 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1134 case CONS_GETTERM: /* get the current terminal emulator info */
1138 if (((term_info_t *)data)->ti_index == 0) {
1141 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1144 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1145 sizeof(((term_info_t *)data)->ti_name));
1146 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1147 sizeof(((term_info_t *)data)->ti_desc));
1148 ((term_info_t *)data)->ti_flags = 0;
1151 ((term_info_t *)data)->ti_name[0] = '\0';
1152 ((term_info_t *)data)->ti_desc[0] = '\0';
1153 ((term_info_t *)data)->ti_flags = 0;
1158 case CONS_SETTERM: /* set the current terminal emulator */
1160 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1161 /* FIXME: what if scp == sc_console! XXX */
1165 case GIO_SCRNMAP: /* get output translation table */
1166 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1169 case PIO_SCRNMAP: /* set output translation table */
1170 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1171 for (i=0; i<sizeof(sc->scr_map); i++) {
1172 sc->scr_rmap[sc->scr_map[i]] = i;
1176 case GIO_KEYMAP: /* get keyboard translation table */
1177 case PIO_KEYMAP: /* set keyboard translation table */
1178 case GIO_DEADKEYMAP: /* get accent key translation table */
1179 case PIO_DEADKEYMAP: /* set accent key translation table */
1180 case GETFKEY: /* get function key string */
1181 case SETFKEY: /* set function key string */
1182 error = kbd_ioctl(sc->kbd, cmd, data);
1183 if (error == ENOIOCTL)
1187 #ifndef SC_NO_FONT_LOADING
1189 case PIO_FONT8x8: /* set 8x8 dot font */
1190 if (!ISFONTAVAIL(sc->adp->va_flags))
1192 bcopy(data, sc->font_8, 8*256);
1193 sc->fonts_loaded |= FONT_8;
1196 * Always use the font page #0. XXX
1197 * Don't load if the current font size is not 8x8.
1199 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1200 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1203 case GIO_FONT8x8: /* get 8x8 dot font */
1204 if (!ISFONTAVAIL(sc->adp->va_flags))
1206 if (sc->fonts_loaded & FONT_8) {
1207 bcopy(sc->font_8, data, 8*256);
1213 case PIO_FONT8x14: /* set 8x14 dot font */
1214 if (!ISFONTAVAIL(sc->adp->va_flags))
1216 bcopy(data, sc->font_14, 14*256);
1217 sc->fonts_loaded |= FONT_14;
1220 * Always use the font page #0. XXX
1221 * Don't load if the current font size is not 8x14.
1223 if (ISTEXTSC(sc->cur_scp)
1224 && (sc->cur_scp->font_size >= 14)
1225 && (sc->cur_scp->font_size < 16))
1226 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1229 case GIO_FONT8x14: /* get 8x14 dot font */
1230 if (!ISFONTAVAIL(sc->adp->va_flags))
1232 if (sc->fonts_loaded & FONT_14) {
1233 bcopy(sc->font_14, data, 14*256);
1239 case PIO_FONT8x16: /* set 8x16 dot font */
1240 if (!ISFONTAVAIL(sc->adp->va_flags))
1242 bcopy(data, sc->font_16, 16*256);
1243 sc->fonts_loaded |= FONT_16;
1246 * Always use the font page #0. XXX
1247 * Don't load if the current font size is not 8x16.
1249 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1250 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1253 case GIO_FONT8x16: /* get 8x16 dot font */
1254 if (!ISFONTAVAIL(sc->adp->va_flags))
1256 if (sc->fonts_loaded & FONT_16) {
1257 bcopy(sc->font_16, data, 16*256);
1263 #endif /* SC_NO_FONT_LOADING */
1269 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
1270 if (error != ENOIOCTL)
1272 error = ttioctl(tp, cmd, data, flag);
1273 if (error != ENOIOCTL)
1279 scstart(struct tty *tp)
1283 u_char buf[PCBURST];
1284 scr_stat *scp = SC_STAT(tp->t_dev);
1286 if (scp->status & SLKED || scp->sc->blink_in_progress)
1289 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1290 tp->t_state |= TS_BUSY;
1293 len = q_to_b(rbp, buf, PCBURST);
1295 sc_puts(scp, buf, len);
1298 tp->t_state &= ~TS_BUSY;
1305 sccnprobe(struct consdev *cp)
1311 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1313 /* a video card is always required */
1314 if (!scvidprobe(unit, flags, TRUE))
1315 cp->cn_pri = CN_DEAD;
1317 /* syscons will become console even when there is no keyboard */
1318 sckbdprobe(unit, flags, TRUE);
1320 if (cp->cn_pri == CN_DEAD)
1323 /* initialize required fields */
1324 cp->cn_dev = makedev(CDEV_MAJOR, SC_CONSOLECTL);
1325 #endif /* __i386__ */
1329 * alpha use sccnattach() rather than cnprobe()/cninit()/cnterm()
1330 * interface to install the console. Always return CN_DEAD from
1333 cp->cn_pri = CN_DEAD;
1334 #endif /* __alpha__ */
1338 sccninit(struct consdev *cp)
1344 sc_get_cons_priority(&unit, &flags);
1345 scinit(unit, flags | SC_KERNEL_CONSOLE);
1346 sc_console_unit = unit;
1347 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1348 #endif /* __i386__ */
1351 /* SHOULDN'T REACH HERE */
1352 #endif /* __alpha__ */
1356 sccnterm(struct consdev *cp)
1358 /* we are not the kernel console any more, release everything */
1360 if (sc_console_unit < 0)
1361 return; /* shouldn't happen */
1365 sc_clear_screen(sc_console);
1366 sccnupdate(sc_console);
1368 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1369 sc_console_unit = -1;
1371 #endif /* __i386__ */
1374 /* do nothing XXX */
1375 #endif /* __alpha__ */
1383 static struct consdev consdev;
1387 bcopy(&sc_consdev, &consdev, sizeof(sc_consdev));
1388 consdev.cn_pri = sc_get_cons_priority(&unit, &flags);
1390 /* a video card is always required */
1391 if (!scvidprobe(unit, flags, TRUE))
1392 consdev.cn_pri = CN_DEAD;
1394 /* alpha doesn't allow the console being without a keyboard... Why? */
1395 if (!sckbdprobe(unit, flags, TRUE))
1396 consdev.cn_pri = CN_DEAD;
1398 if (consdev.cn_pri == CN_DEAD)
1401 scinit(unit, flags | SC_KERNEL_CONSOLE);
1402 sc_console_unit = unit;
1403 sc_console = SC_STAT(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1404 consdev.cn_dev = makedev(CDEV_MAJOR, 0);
1408 #endif /* __alpha__ */
1411 sccnputc(dev_t dev, int c)
1414 scr_stat *scp = sc_console;
1416 #ifndef SC_NO_HISTORY
1418 #endif /* !SC_NO_HISTORY */
1421 /* assert(sc_console != NULL) */
1423 #ifndef SC_NO_HISTORY
1424 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1425 scp->status &= ~SLKED;
1426 update_kbd_state(scp, scp->status, SLKED);
1427 if (scp->status & BUFFER_SAVED) {
1428 if (!sc_hist_restore(scp))
1429 sc_remove_cutmarking(scp);
1430 scp->status &= ~BUFFER_SAVED;
1431 scp->status |= CURSOR_ENABLED;
1432 sc_draw_cursor_image(scp);
1434 tp = VIRTUAL_TTY(scp->sc, scp->index);
1438 #endif /* !SC_NO_HISTORY */
1441 if (kernel_console_ts != NULL)
1442 scp->ts = kernel_console_ts;
1444 sc_puts(scp, buf, 1);
1447 s = spltty(); /* block sckbdevent and scrn_timer */
1455 return sccngetch(0);
1459 sccncheckc(dev_t dev)
1461 return sccngetch(SCGETC_NONBLOCK);
1465 sccndbctl(dev_t dev, int on)
1467 /* assert(sc_console_unit >= 0) */
1468 /* try to switch to the kernel console screen */
1469 if (on && debugger == 0) {
1471 * TRY to make sure the screen saver is stopped,
1472 * and the screen is updated before switching to
1477 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1478 && sc_console->smode.mode == VT_AUTO) {
1479 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1480 sc_switch_scr(sc_console->sc, sc_console->index);
1490 sccngetch(int flags)
1492 static struct fkeytab fkey;
1497 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1500 /* assert(sc_console != NULL) */
1503 * Stop the screen saver and update the screen if necessary.
1504 * What if we have been running in the screen saver code... XXX
1506 sc_touch_scrn_saver();
1507 scp = sc_console->sc->cur_scp; /* XXX */
1510 if (fkeycp < fkey.len) {
1512 return fkey.str[fkeycp++];
1515 if (scp->sc->kbd == NULL) {
1521 * Make sure the keyboard is accessible even when the kbd device
1522 * driver is disabled.
1524 kbd_enable(scp->sc->kbd);
1526 /* we shall always use the keyboard in the XLATE mode here */
1527 cur_mode = scp->kbd_mode;
1528 scp->kbd_mode = K_XLATE;
1529 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1531 kbd_poll(scp->sc->kbd, TRUE);
1532 c = scgetc(scp->sc, SCGETC_CN | flags);
1533 kbd_poll(scp->sc->kbd, FALSE);
1535 scp->kbd_mode = cur_mode;
1536 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1537 kbd_disable(scp->sc->kbd);
1540 switch (KEYFLAGS(c)) {
1541 case 0: /* normal char */
1543 case FKEY: /* function key */
1544 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1546 if ((p != NULL) && (fkey.len > 0)) {
1547 bcopy(p, fkey.str, fkey.len);
1561 sccnupdate(scr_stat *scp)
1563 /* this is a cut-down version of scrn_timer()... */
1565 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1568 if (debugger > 0 || panicstr || shutdown_in_progress) {
1569 sc_touch_scrn_saver();
1570 } else if (scp != scp->sc->cur_scp) {
1574 if (!run_scrn_saver)
1575 scp->sc->flags &= ~SC_SCRN_IDLE;
1577 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1578 if (scp->sc->flags & SC_SCRN_BLANKED)
1579 stop_scrn_saver(scp->sc, current_saver);
1580 #endif /* NSPLASH */
1582 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1583 || scp->sc->switch_in_progress)
1586 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1587 * when write_in_progress is non-zero. XXX
1590 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1591 scrn_update(scp, TRUE);
1595 scrn_timer(void *arg)
1597 static int kbd_interval = 0;
1604 again = (arg != NULL);
1606 sc = (sc_softc_t *)arg;
1607 else if (sc_console != NULL)
1608 sc = sc_console->sc;
1612 /* don't do anything when we are performing some I/O operations */
1613 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1615 timeout(scrn_timer, sc, hz / 10);
1620 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1621 /* try to allocate a keyboard automatically */
1622 if (++kbd_interval >= 25) {
1623 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1625 if (sc->keyboard >= 0) {
1626 sc->kbd = kbd_get_keyboard(sc->keyboard);
1627 kbd_ioctl(sc->kbd, KDSKBMODE,
1628 (caddr_t)&sc->cur_scp->kbd_mode);
1629 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1636 /* find the vty to update */
1639 /* should we stop the screen saver? */
1640 getmicrouptime(&tv);
1641 if (debugger > 0 || panicstr || shutdown_in_progress)
1642 sc_touch_scrn_saver();
1643 if (run_scrn_saver) {
1644 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1645 sc->flags |= SC_SCRN_IDLE;
1647 sc->flags &= ~SC_SCRN_IDLE;
1649 sc->scrn_time_stamp = tv.tv_sec;
1650 sc->flags &= ~SC_SCRN_IDLE;
1651 if (scrn_blank_time > 0)
1652 run_scrn_saver = TRUE;
1655 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1656 if (sc->flags & SC_SCRN_BLANKED)
1657 stop_scrn_saver(sc, current_saver);
1658 #endif /* NSPLASH */
1660 /* should we just return ? */
1661 if (sc->blink_in_progress || sc->switch_in_progress
1662 || sc->write_in_progress) {
1664 timeout(scrn_timer, sc, hz / 10);
1669 /* Update the screen */
1670 scp = sc->cur_scp; /* cur_scp may have changed... */
1671 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1672 scrn_update(scp, TRUE);
1675 /* should we activate the screen saver? */
1676 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1677 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1678 (*current_saver)(sc, TRUE);
1679 #endif /* NSPLASH */
1682 timeout(scrn_timer, sc, hz / 25);
1687 and_region(int *s1, int *e1, int s2, int e2)
1689 if (*e1 < s2 || e2 < *s1)
1691 *s1 = imax(*s1, s2);
1692 *e1 = imin(*e1, e2);
1697 scrn_update(scr_stat *scp, int show_cursor)
1704 /* assert(scp == scp->sc->cur_scp) */
1706 ++scp->sc->videoio_in_progress;
1708 #ifndef SC_NO_CUTPASTE
1709 /* remove the previous mouse pointer image if necessary */
1710 if (scp->status & MOUSE_VISIBLE) {
1712 e = scp->mouse_pos + scp->xsize + 1;
1713 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1714 || and_region(&s, &e, scp->start, scp->end)
1715 || ((scp->status & CURSOR_ENABLED) &&
1716 (scp->cursor_pos != scp->cursor_oldpos) &&
1717 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1718 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1719 sc_remove_mouse_image(scp);
1720 if (scp->end >= scp->xsize*scp->ysize)
1721 scp->end = scp->xsize*scp->ysize - 1;
1724 #endif /* !SC_NO_CUTPASTE */
1728 if (scp->end >= scp->xsize*scp->ysize) {
1729 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1730 scp->end = scp->xsize*scp->ysize - 1;
1732 if (scp->start < 0) {
1733 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1738 /* update screen image */
1739 if (scp->start <= scp->end) {
1740 if (scp->mouse_cut_end >= 0) {
1741 /* there is a marked region for cut & paste */
1742 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1743 start = scp->mouse_cut_start;
1744 end = scp->mouse_cut_end;
1746 start = scp->mouse_cut_end;
1747 end = scp->mouse_cut_start - 1;
1751 /* does the cut-mark region overlap with the update region? */
1752 if (and_region(&s, &e, scp->start, scp->end)) {
1753 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1756 if (and_region(&s, &e, scp->start, scp->end))
1757 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1759 e = scp->xsize*scp->ysize - 1;
1760 if (and_region(&s, &e, scp->start, scp->end))
1761 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1763 (*scp->rndr->draw)(scp, scp->start,
1764 scp->end - scp->start + 1, FALSE);
1767 (*scp->rndr->draw)(scp, scp->start,
1768 scp->end - scp->start + 1, FALSE);
1772 /* we are not to show the cursor and the mouse pointer... */
1775 scp->start = scp->xsize*scp->ysize - 1;
1776 --scp->sc->videoio_in_progress;
1780 /* update cursor image */
1781 if (scp->status & CURSOR_ENABLED) {
1784 /* did cursor move since last time ? */
1785 if (scp->cursor_pos != scp->cursor_oldpos) {
1786 /* do we need to remove old cursor image ? */
1787 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1788 sc_remove_cursor_image(scp);
1789 sc_draw_cursor_image(scp);
1791 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1792 /* cursor didn't move, but has been overwritten */
1793 sc_draw_cursor_image(scp);
1794 else if (scp->sc->flags & SC_BLINK_CURSOR)
1795 /* if it's a blinking cursor, update it */
1796 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1797 sc_inside_cutmark(scp,
1802 #ifndef SC_NO_CUTPASTE
1803 /* update "pseudo" mouse pointer image */
1804 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1805 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1806 scp->status &= ~MOUSE_MOVED;
1807 sc_draw_mouse_image(scp);
1810 #endif /* SC_NO_CUTPASTE */
1813 scp->start = scp->xsize*scp->ysize - 1;
1815 --scp->sc->videoio_in_progress;
1820 scsplash_callback(int event, void *arg)
1825 sc = (sc_softc_t *)arg;
1829 if (add_scrn_saver(scsplash_saver) == 0) {
1830 sc->flags &= ~SC_SAVER_FAILED;
1831 run_scrn_saver = TRUE;
1832 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1833 scsplash_stick(TRUE);
1834 (*current_saver)(sc, TRUE);
1840 if (current_saver == scsplash_saver) {
1841 scsplash_stick(FALSE);
1842 error = remove_scrn_saver(scsplash_saver);
1854 scsplash_saver(sc_softc_t *sc, int show)
1856 static int busy = FALSE;
1865 if (!(sc->flags & SC_SAVER_FAILED)) {
1866 if (!(sc->flags & SC_SCRN_BLANKED))
1867 set_scrn_saver_mode(scp, -1, NULL, 0);
1868 switch (splash(sc->adp, TRUE)) {
1869 case 0: /* succeeded */
1871 case EAGAIN: /* try later */
1872 restore_scrn_saver_mode(scp, FALSE);
1873 sc_touch_scrn_saver(); /* XXX */
1876 sc->flags |= SC_SAVER_FAILED;
1877 scsplash_stick(FALSE);
1878 restore_scrn_saver_mode(scp, TRUE);
1879 printf("scsplash_saver(): failed to put up the image\n");
1883 } else if (!sticky_splash) {
1884 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1885 restore_scrn_saver_mode(scp, TRUE);
1891 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1896 if (current_saver != none_saver) {
1897 error = remove_scrn_saver(current_saver);
1902 if (current_saver != none_saver)
1905 run_scrn_saver = FALSE;
1906 saver_mode = CONS_LKM_SAVER;
1907 current_saver = this_saver;
1912 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1914 if (current_saver != this_saver)
1919 * In order to prevent `current_saver' from being called by
1920 * the timeout routine `scrn_timer()' while we manipulate
1921 * the saver list, we shall set `current_saver' to `none_saver'
1922 * before stopping the current saver, rather than blocking by `splXX()'.
1924 current_saver = none_saver;
1926 stop_scrn_saver(this_saver);
1929 /* unblank all blanked screens */
1930 wait_scrn_saver_stop(NULL);
1934 current_saver = none_saver;
1939 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1943 /* assert(scp == scp->sc->cur_scp) */
1945 if (!ISGRAPHSC(scp))
1946 sc_remove_cursor_image(scp);
1947 scp->splash_save_mode = scp->mode;
1948 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1949 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1950 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1951 scp->sc->flags |= SC_SCRN_BLANKED;
1957 if (set_mode(scp) == 0) {
1958 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1959 scp->status |= GRAPHICS_MODE;
1960 #ifndef SC_NO_PALETTE_LOADING
1962 load_palette(scp->sc->adp, pal);
1964 sc_set_border(scp, border);
1968 scp->mode = scp->splash_save_mode;
1969 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1970 scp->status |= scp->splash_save_status;
1977 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1983 /* assert(scp == scp->sc->cur_scp) */
1986 status = scp->status;
1987 scp->mode = scp->splash_save_mode;
1988 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1989 scp->status |= scp->splash_save_status;
1990 scp->sc->flags &= ~SC_SCRN_BLANKED;
1992 if (!ISGRAPHSC(scp))
1993 sc_draw_cursor_image(scp);
1998 if (set_mode(scp) == 0) {
1999 #ifndef SC_NO_PALETTE_LOADING
2000 load_palette(scp->sc->adp, scp->sc->palette);
2007 scp->status = status;
2014 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2016 (*saver)(sc, FALSE);
2017 run_scrn_saver = FALSE;
2018 /* the screen saver may have chosen not to stop after all... */
2019 if (sc->flags & SC_SCRN_BLANKED)
2022 mark_all(sc->cur_scp);
2023 if (sc->delayed_next_scr)
2024 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2025 wakeup((caddr_t)&scrn_blanked);
2029 wait_scrn_saver_stop(sc_softc_t *sc)
2033 while (scrn_blanked > 0) {
2034 run_scrn_saver = FALSE;
2035 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2039 error = tsleep((caddr_t)&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2040 if ((error != 0) && (error != ERESTART))
2043 run_scrn_saver = FALSE;
2046 #endif /* NSPLASH */
2049 sc_touch_scrn_saver(void)
2051 scsplash_stick(FALSE);
2052 run_scrn_saver = FALSE;
2056 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2062 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2064 /* prevent switch if previously requested */
2065 if (sc->flags & SC_SCRN_VTYLOCK) {
2066 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2067 sc->cur_scp->bell_duration);
2071 /* delay switch if the screen is blanked or being updated */
2072 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2073 || sc->blink_in_progress || sc->videoio_in_progress) {
2074 sc->delayed_next_scr = next_scr + 1;
2075 sc_touch_scrn_saver();
2076 DPRINTF(5, ("switch delayed\n"));
2081 cur_scp = sc->cur_scp;
2083 /* we are in the middle of the vty switching process... */
2084 if (sc->switch_in_progress
2085 && (cur_scp->smode.mode == VT_PROCESS)
2087 if (cur_scp->proc != pfind(cur_scp->pid)) {
2089 * The controlling process has died!!. Do some clean up.
2090 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2091 * are not reset here yet; they will be cleared later.
2093 DPRINTF(5, ("cur_scp controlling process %d died, ",
2095 if (cur_scp->status & SWITCH_WAIT_REL) {
2097 * Force the previous switch to finish, but return now
2100 DPRINTF(5, ("reset WAIT_REL, "));
2101 finish_vt_rel(cur_scp, TRUE, &s);
2103 DPRINTF(5, ("finishing previous switch\n"));
2105 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2106 /* let's assume screen switch has been completed. */
2107 DPRINTF(5, ("reset WAIT_ACQ, "));
2108 finish_vt_acq(cur_scp);
2111 * We are in between screen release and acquisition, and
2112 * reached here via scgetc() or scrn_timer() which has
2113 * interrupted exchange_scr(). Don't do anything stupid.
2115 DPRINTF(5, ("waiting nothing, "));
2119 * The controlling process is alive, but not responding...
2120 * It is either buggy or it may be just taking time.
2121 * The following code is a gross kludge to cope with this
2122 * problem for which there is no clean solution. XXX
2124 if (cur_scp->status & SWITCH_WAIT_REL) {
2125 switch (sc->switch_in_progress++) {
2129 DPRINTF(5, ("sending relsig again, "));
2130 signal_vt_rel(cur_scp);
2137 * Act as if the controlling program returned
2140 DPRINTF(5, ("force reset WAIT_REL, "));
2141 finish_vt_rel(cur_scp, FALSE, &s);
2143 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2146 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2147 switch (sc->switch_in_progress++) {
2151 DPRINTF(5, ("sending acqsig again, "));
2152 signal_vt_acq(cur_scp);
2158 /* clear the flag and finish the previous switch */
2159 DPRINTF(5, ("force reset WAIT_ACQ, "));
2160 finish_vt_acq(cur_scp);
2168 * Return error if an invalid argument is given, or vty switch
2169 * is still in progress.
2171 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2172 || sc->switch_in_progress) {
2174 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2175 DPRINTF(5, ("error 1\n"));
2180 * Don't allow switching away from the graphics mode vty
2181 * if the switch mode is VT_AUTO, unless the next vty is the same
2182 * as the current or the current vty has been closed (but showing).
2184 tp = VIRTUAL_TTY(sc, cur_scp->index);
2185 if ((cur_scp->index != next_scr)
2187 && (cur_scp->smode.mode == VT_AUTO)
2188 && ISGRAPHSC(cur_scp)) {
2190 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2191 DPRINTF(5, ("error, graphics mode\n"));
2196 * Is the wanted vty open? Don't allow switching to a closed vty.
2197 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2198 * Note that we always allow the user to switch to the kernel
2199 * console even if it is closed.
2201 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2202 tp = VIRTUAL_TTY(sc, next_scr);
2203 if (!ISTTYOPEN(tp)) {
2205 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2206 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2209 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2211 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2216 /* this is the start of vty switching process... */
2217 ++sc->switch_in_progress;
2218 sc->delayed_next_scr = 0;
2219 sc->old_scp = cur_scp;
2220 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2221 if (sc->new_scp == sc->old_scp) {
2222 sc->switch_in_progress = 0;
2223 wakeup((caddr_t)&sc->new_scp->smode);
2225 DPRINTF(5, ("switch done (new == old)\n"));
2229 /* has controlling process died? */
2230 vt_proc_alive(sc->old_scp);
2231 vt_proc_alive(sc->new_scp);
2233 /* wait for the controlling process to release the screen, if necessary */
2234 if (signal_vt_rel(sc->old_scp)) {
2239 /* go set up the new vty screen */
2244 /* wake up processes waiting for this vty */
2245 wakeup((caddr_t)&sc->cur_scp->smode);
2247 /* wait for the controlling process to acknowledge, if necessary */
2248 if (signal_vt_acq(sc->cur_scp)) {
2253 sc->switch_in_progress = 0;
2254 if (sc->unit == sc_console_unit)
2255 cons_unavail = FALSE;
2257 DPRINTF(5, ("switch done\n"));
2263 do_switch_scr(sc_softc_t *sc, int s)
2265 vt_proc_alive(sc->new_scp);
2270 /* sc->cur_scp == sc->new_scp */
2271 wakeup((caddr_t)&sc->cur_scp->smode);
2273 /* wait for the controlling process to acknowledge, if necessary */
2274 if (!signal_vt_acq(sc->cur_scp)) {
2275 sc->switch_in_progress = 0;
2276 if (sc->unit == sc_console_unit)
2277 cons_unavail = FALSE;
2284 vt_proc_alive(scr_stat *scp)
2287 if (scp->proc == pfind(scp->pid))
2290 scp->smode.mode = VT_AUTO;
2291 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2297 signal_vt_rel(scr_stat *scp)
2299 if (scp->smode.mode != VT_PROCESS)
2301 scp->status |= SWITCH_WAIT_REL;
2302 psignal(scp->proc, scp->smode.relsig);
2303 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2308 signal_vt_acq(scr_stat *scp)
2310 if (scp->smode.mode != VT_PROCESS)
2312 if (scp->sc->unit == sc_console_unit)
2313 cons_unavail = TRUE;
2314 scp->status |= SWITCH_WAIT_ACQ;
2315 psignal(scp->proc, scp->smode.acqsig);
2316 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2321 finish_vt_rel(scr_stat *scp, int release, int *s)
2323 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2324 scp->status &= ~SWITCH_WAIT_REL;
2326 *s = do_switch_scr(scp->sc, *s);
2328 scp->sc->switch_in_progress = 0;
2335 finish_vt_acq(scr_stat *scp)
2337 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2338 scp->status &= ~SWITCH_WAIT_ACQ;
2339 scp->sc->switch_in_progress = 0;
2346 exchange_scr(sc_softc_t *sc)
2350 /* save the current state of video and keyboard */
2351 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2352 if (!ISGRAPHSC(sc->old_scp))
2353 sc_remove_cursor_image(sc->old_scp);
2354 if (sc->old_scp->kbd_mode == K_XLATE)
2355 save_kbd_state(sc->old_scp);
2357 /* set up the video for the new screen */
2358 scp = sc->cur_scp = sc->new_scp;
2359 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2362 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2363 (void *)sc->adp->va_window, FALSE);
2364 scp->status |= MOUSE_HIDDEN;
2365 sc_move_cursor(scp, scp->xpos, scp->ypos);
2366 if (!ISGRAPHSC(scp))
2367 sc_set_cursor_image(scp);
2368 #ifndef SC_NO_PALETTE_LOADING
2369 if (ISGRAPHSC(sc->old_scp))
2370 load_palette(sc->adp, sc->palette);
2372 sc_set_border(scp, scp->border);
2374 /* set up the keyboard for the new screen */
2375 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2376 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2377 update_kbd_state(scp, scp->status, LOCK_MASK);
2383 sc_puts(scr_stat *scp, u_char *buf, int len)
2386 /* make screensaver happy */
2387 if (!sticky_splash && scp == scp->sc->cur_scp)
2388 run_scrn_saver = FALSE;
2392 (*scp->tsw->te_puts)(scp, buf, len);
2394 if (scp->sc->delayed_next_scr)
2395 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2399 sc_draw_cursor_image(scr_stat *scp)
2401 /* assert(scp == scp->sc->cur_scp); */
2402 ++scp->sc->videoio_in_progress;
2403 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2404 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2405 sc_inside_cutmark(scp, scp->cursor_pos));
2406 scp->cursor_oldpos = scp->cursor_pos;
2407 --scp->sc->videoio_in_progress;
2411 sc_remove_cursor_image(scr_stat *scp)
2413 /* assert(scp == scp->sc->cur_scp); */
2414 ++scp->sc->videoio_in_progress;
2415 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2416 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2417 sc_inside_cutmark(scp, scp->cursor_oldpos));
2418 --scp->sc->videoio_in_progress;
2422 update_cursor_image(scr_stat *scp)
2426 if (scp->sc->flags & SC_CHAR_CURSOR) {
2427 scp->cursor_base = imax(0, scp->sc->cursor_base);
2428 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2430 scp->cursor_base = 0;
2431 scp->cursor_height = scp->font_size;
2433 blink = scp->sc->flags & SC_BLINK_CURSOR;
2435 /* assert(scp == scp->sc->cur_scp); */
2436 ++scp->sc->videoio_in_progress;
2437 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2438 sc_inside_cutmark(scp, scp->cursor_pos));
2439 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2440 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2441 sc_inside_cutmark(scp, scp->cursor_pos));
2442 --scp->sc->videoio_in_progress;
2446 sc_set_cursor_image(scr_stat *scp)
2448 if (scp->sc->flags & SC_CHAR_CURSOR) {
2449 scp->cursor_base = imax(0, scp->sc->cursor_base);
2450 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2452 scp->cursor_base = 0;
2453 scp->cursor_height = scp->font_size;
2456 /* assert(scp == scp->sc->cur_scp); */
2457 ++scp->sc->videoio_in_progress;
2458 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2459 scp->sc->flags & SC_BLINK_CURSOR);
2460 --scp->sc->videoio_in_progress;
2464 scinit(int unit, int flags)
2467 * When syscons is being initialized as the kernel console, malloc()
2468 * is not yet functional, because various kernel structures has not been
2469 * fully initialized yet. Therefore, we need to declare the following
2470 * static buffers for the console. This is less than ideal,
2471 * but is necessry evil for the time being. XXX
2473 static scr_stat main_console;
2474 static dev_t main_devs[MAXCONS];
2475 static struct tty main_tty;
2476 static u_short sc_buffer[ROW*COL]; /* XXX */
2477 #ifndef SC_NO_FONT_LOADING
2478 static u_char font_8[256*8];
2479 static u_char font_14[256*14];
2480 static u_char font_16[256*16];
2485 video_adapter_t *adp;
2490 /* one time initialization */
2491 if (init_done == COLD)
2492 sc_get_bios_values(&bios_value);
2496 * Allocate resources. Even if we are being called for the second
2497 * time, we must allocate them again, because they might have
2500 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2502 if (sc->adapter >= 0) {
2503 vid_release(sc->adp, (void *)&sc->adapter);
2507 if (sc->keyboard >= 0) {
2508 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2509 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2510 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2511 if (sc->kbd != NULL) {
2512 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2513 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2517 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2518 sc->adp = vid_get_adapter(sc->adapter);
2519 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2520 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2522 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2523 sc->kbd = kbd_get_keyboard(sc->keyboard);
2524 if (sc->kbd != NULL) {
2525 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2526 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2529 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2531 sc->initial_mode = sc->adp->va_initial_mode;
2533 #ifndef SC_NO_FONT_LOADING
2534 if (flags & SC_KERNEL_CONSOLE) {
2535 sc->font_8 = font_8;
2536 sc->font_14 = font_14;
2537 sc->font_16 = font_16;
2538 } else if (sc->font_8 == NULL) {
2539 /* assert(sc_malloc) */
2540 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2541 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2542 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2546 /* extract the hardware cursor location and hide the cursor for now */
2547 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2548 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2550 /* set up the first console */
2551 sc->first_vty = unit*MAXCONS;
2552 sc->vtys = MAXCONS; /* XXX: should be configurable */
2553 if (flags & SC_KERNEL_CONSOLE) {
2554 sc->dev = main_devs;
2555 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2556 sc->dev[0]->si_tty = &main_tty;
2557 ttyregister(&main_tty);
2558 scp = &main_console;
2559 init_scp(sc, sc->first_vty, scp);
2560 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2561 (void *)sc_buffer, FALSE);
2562 if (sc_init_emulator(scp, SC_DFLT_TERM))
2563 sc_init_emulator(scp, "*");
2564 (*scp->tsw->te_default_attr)(scp,
2565 kernel_default.std_color,
2566 kernel_default.rev_color);
2568 /* assert(sc_malloc) */
2569 sc->dev = malloc(sizeof(dev_t)*sc->vtys, M_DEVBUF, M_WAITOK);
2570 bzero(sc->dev, sizeof(dev_t)*sc->vtys);
2571 sc->dev[0] = makedev(CDEV_MAJOR, unit*MAXCONS);
2572 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2573 scp = alloc_scp(sc, sc->first_vty);
2575 SC_STAT(sc->dev[0]) = scp;
2578 /* copy screen to temporary buffer */
2579 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2580 (void *)scp->sc->adp->va_window, FALSE);
2582 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2584 /* move cursors to the initial positions */
2585 if (col >= scp->xsize)
2587 if (row >= scp->ysize)
2588 row = scp->ysize - 1;
2591 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2592 if (bios_value.cursor_end < scp->font_size)
2593 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2595 sc->cursor_base = 0;
2596 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2597 sc->cursor_height = imin(i, scp->font_size);
2598 #ifndef SC_NO_SYSMOUSE
2599 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2601 if (!ISGRAPHSC(scp)) {
2602 sc_set_cursor_image(scp);
2603 sc_draw_cursor_image(scp);
2606 /* save font and palette */
2607 #ifndef SC_NO_FONT_LOADING
2608 sc->fonts_loaded = 0;
2609 if (ISFONTAVAIL(sc->adp->va_flags)) {
2611 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2612 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2613 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2614 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2615 if (scp->font_size < 14) {
2616 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2617 } else if (scp->font_size >= 16) {
2618 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2620 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2622 #else /* !SC_DFLT_FONT */
2623 if (scp->font_size < 14) {
2624 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2625 sc->fonts_loaded = FONT_8;
2626 } else if (scp->font_size >= 16) {
2627 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2628 sc->fonts_loaded = FONT_16;
2630 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2631 sc->fonts_loaded = FONT_14;
2633 #endif /* SC_DFLT_FONT */
2634 /* FONT KLUDGE: always use the font page #0. XXX */
2635 sc_show_font(scp, 0);
2637 #endif /* !SC_NO_FONT_LOADING */
2639 #ifndef SC_NO_PALETTE_LOADING
2640 save_palette(sc->adp, sc->palette);
2644 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2645 /* we are ready to put up the splash image! */
2646 splash_init(sc->adp, scsplash_callback, sc);
2647 sc->flags |= SC_SPLASH_SCRN;
2649 #endif /* NSPLASH */
2652 /* the rest is not necessary, if we have done it once */
2653 if (sc->flags & SC_INIT_DONE)
2656 /* initialize mapscrn arrays to a one to one map */
2657 for (i = 0; i < sizeof(sc->scr_map); i++)
2658 sc->scr_map[i] = sc->scr_rmap[i] = i;
2660 sc->flags |= SC_INIT_DONE;
2665 scterm(int unit, int flags)
2670 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2672 return; /* shouldn't happen */
2675 /* this console is no longer available for the splash screen */
2676 if (sc->flags & SC_SPLASH_SCRN) {
2677 splash_term(sc->adp);
2678 sc->flags &= ~SC_SPLASH_SCRN;
2680 #endif /* NSPLASH */
2683 /* move the hardware cursor to the upper-left corner */
2684 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2687 /* release the keyboard and the video card */
2688 if (sc->keyboard >= 0)
2689 kbd_release(sc->kbd, &sc->keyboard);
2690 if (sc->adapter >= 0)
2691 vid_release(sc->adp, &sc->adapter);
2693 /* stop the terminal emulator, if any */
2694 scp = SC_STAT(sc->dev[0]);
2696 (*scp->tsw->te_term)(scp, &scp->ts);
2697 if (scp->ts != NULL)
2698 free(scp->ts, M_DEVBUF);
2700 /* clear the structure */
2701 if (!(flags & SC_KERNEL_CONSOLE)) {
2702 /* XXX: We need delete_dev() for this */
2703 free(sc->dev, M_DEVBUF);
2705 /* XXX: We need a ttyunregister for this */
2706 free(sc->tty, M_DEVBUF);
2708 #ifndef SC_NO_FONT_LOADING
2709 free(sc->font_8, M_DEVBUF);
2710 free(sc->font_14, M_DEVBUF);
2711 free(sc->font_16, M_DEVBUF);
2713 /* XXX vtb, history */
2715 bzero(sc, sizeof(*sc));
2722 scshutdown(void *arg, int howto)
2724 /* assert(sc_console != NULL) */
2726 sc_touch_scrn_saver();
2727 if (!cold && sc_console
2728 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2729 && sc_console->smode.mode == VT_AUTO)
2730 sc_switch_scr(sc_console->sc, sc_console->index);
2731 shutdown_in_progress = TRUE;
2735 sc_clean_up(scr_stat *scp)
2739 #endif /* NSPLASH */
2741 if (scp->sc->flags & SC_SCRN_BLANKED) {
2742 sc_touch_scrn_saver();
2744 if ((error = wait_scrn_saver_stop(scp->sc)))
2746 #endif /* NSPLASH */
2748 scp->status |= MOUSE_HIDDEN;
2749 sc_remove_mouse_image(scp);
2750 sc_remove_cutmarking(scp);
2755 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2761 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2762 if (!discard && (old.vtb_flags & VTB_VALID)) {
2763 /* retain the current cursor position and buffer contants */
2764 scp->cursor_oldpos = scp->cursor_pos;
2766 * This works only if the old buffer has the same size as or larger
2767 * than the new one. XXX
2769 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2773 sc_vtb_destroy(&old);
2776 #ifndef SC_NO_SYSMOUSE
2777 /* move the mouse cursor at the center of the screen */
2778 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2783 *alloc_scp(sc_softc_t *sc, int vty)
2787 /* assert(sc_malloc) */
2789 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2790 init_scp(sc, vty, scp);
2792 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2793 if (sc_init_emulator(scp, SC_DFLT_TERM))
2794 sc_init_emulator(scp, "*");
2796 #ifndef SC_NO_CUTPASTE
2797 sc_alloc_cut_buffer(scp, TRUE);
2800 #ifndef SC_NO_HISTORY
2801 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2808 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2812 bzero(scp, sizeof(*scp));
2817 scp->mode = sc->initial_mode;
2818 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2819 if (info.vi_flags & V_INFO_GRAPHICS) {
2820 scp->status |= GRAPHICS_MODE;
2821 scp->xpixel = info.vi_width;
2822 scp->ypixel = info.vi_height;
2823 scp->xsize = info.vi_width/8;
2824 scp->ysize = info.vi_height/info.vi_cheight;
2828 scp->xsize = info.vi_width;
2829 scp->ysize = info.vi_height;
2830 scp->xpixel = scp->xsize*8;
2831 scp->ypixel = scp->ysize*info.vi_cheight;
2832 if (info.vi_cheight < 14) {
2834 #ifndef SC_NO_FONT_LOADING
2835 scp->font = sc->font_8;
2839 } else if (info.vi_cheight >= 16) {
2840 scp->font_size = 16;
2841 #ifndef SC_NO_FONT_LOADING
2842 scp->font = sc->font_16;
2847 scp->font_size = 14;
2848 #ifndef SC_NO_FONT_LOADING
2849 scp->font = sc->font_14;
2855 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2856 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2857 scp->xoff = scp->yoff = 0;
2858 scp->xpos = scp->ypos = 0;
2859 scp->start = scp->xsize * scp->ysize - 1;
2864 scp->border = BG_BLACK;
2865 scp->cursor_base = sc->cursor_base;
2866 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2867 scp->mouse_cut_start = scp->xsize*scp->ysize;
2868 scp->mouse_cut_end = -1;
2869 scp->mouse_signal = 0;
2871 scp->mouse_proc = NULL;
2872 scp->kbd_mode = K_XLATE;
2873 scp->bell_pitch = bios_value.bell_pitch;
2874 scp->bell_duration = BELL_DURATION;
2875 scp->status |= (bios_value.shift_state & NLKED);
2876 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2879 scp->smode.mode = VT_AUTO;
2880 scp->history = NULL;
2881 scp->history_pos = 0;
2882 scp->history_size = 0;
2886 sc_init_emulator(scr_stat *scp, char *name)
2893 if (name == NULL) /* if no name is given, use the current emulator */
2895 else /* ...otherwise find the named emulator */
2896 sw = sc_term_match(name);
2901 if (strcmp(sw->te_renderer, "*") != 0) {
2902 rndr = sc_render_match(scp, sw->te_renderer,
2903 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2906 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2907 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2912 if (sw == scp->tsw) {
2913 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2915 sc_clear_screen(scp);
2916 /* assert(error == 0); */
2920 if (sc_malloc && (sw->te_size > 0))
2921 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
2924 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2929 (*scp->tsw->te_term)(scp, &scp->ts);
2930 if (scp->ts != NULL)
2931 free(scp->ts, M_DEVBUF);
2937 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2938 sc_clear_screen(scp);
2944 * scgetc(flags) - get character from keyboard.
2945 * If flags & SCGETC_CN, then avoid harmful side effects.
2946 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2947 * return NOKEY if there is nothing there.
2950 scgetc(sc_softc_t *sc, u_int flags)
2953 #ifndef SC_NO_HISTORY
2961 if (sc->kbd == NULL)
2966 /* I don't like this, but... XXX */
2967 if (flags & SCGETC_CN)
2968 sccnupdate(sc->cur_scp);
2971 /* first see if there is something in the keyboard port */
2973 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2975 if (!(flags & SCGETC_CN))
2976 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2977 } else if (c == NOKEY)
2983 /* make screensaver happy */
2985 sc_touch_scrn_saver();
2988 if (!(flags & SCGETC_CN))
2989 /* do the /dev/random device a favour */
2990 add_keyboard_randomness(c);
2993 if (scp->kbd_mode != K_XLATE)
2996 /* if scroll-lock pressed allow history browsing */
2997 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
2999 scp->status &= ~CURSOR_ENABLED;
3000 sc_remove_cursor_image(scp);
3002 #ifndef SC_NO_HISTORY
3003 if (!(scp->status & BUFFER_SAVED)) {
3004 scp->status |= BUFFER_SAVED;
3008 /* FIXME: key codes */
3009 case SPCLKEY | FKEY | F(49): /* home key */
3010 sc_remove_cutmarking(scp);
3014 case SPCLKEY | FKEY | F(57): /* end key */
3015 sc_remove_cutmarking(scp);
3019 case SPCLKEY | FKEY | F(50): /* up arrow key */
3020 sc_remove_cutmarking(scp);
3021 if (sc_hist_up_line(scp))
3022 if (!(flags & SCGETC_CN))
3023 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3026 case SPCLKEY | FKEY | F(58): /* down arrow key */
3027 sc_remove_cutmarking(scp);
3028 if (sc_hist_down_line(scp))
3029 if (!(flags & SCGETC_CN))
3030 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3033 case SPCLKEY | FKEY | F(51): /* page up key */
3034 sc_remove_cutmarking(scp);
3035 for (i=0; i<scp->ysize; i++)
3036 if (sc_hist_up_line(scp)) {
3037 if (!(flags & SCGETC_CN))
3038 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3043 case SPCLKEY | FKEY | F(59): /* page down key */
3044 sc_remove_cutmarking(scp);
3045 for (i=0; i<scp->ysize; i++)
3046 if (sc_hist_down_line(scp)) {
3047 if (!(flags & SCGETC_CN))
3048 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3053 #endif /* SC_NO_HISTORY */
3057 * Process and consume special keys here. Return a plain char code
3058 * or a char code with the META flag or a function key code.
3062 /* goto next_code */
3067 switch (KEYCHAR(c)) {
3069 case NLK: case CLK: case ALK:
3072 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3074 scp->status |= SLKED;
3076 if (scp->status & SLKED) {
3077 scp->status &= ~SLKED;
3078 #ifndef SC_NO_HISTORY
3079 if (scp->status & BUFFER_SAVED) {
3080 if (!sc_hist_restore(scp))
3081 sc_remove_cutmarking(scp);
3082 scp->status &= ~BUFFER_SAVED;
3083 scp->status |= CURSOR_ENABLED;
3084 sc_draw_cursor_image(scp);
3086 tp = VIRTUAL_TTY(sc, scp->index);
3094 /* NON-LOCKING KEYS */
3096 case LSH: case RSH: case LCTR: case RCTR:
3097 case LALT: case RALT: case ASH: case META:
3101 if (!(sc->flags & SC_SCRN_BLANKED))
3107 /* force activatation/deactivation of the screen saver */
3108 if (!(sc->flags & SC_SCRN_BLANKED)) {
3109 run_scrn_saver = TRUE;
3110 sc->scrn_time_stamp -= scrn_blank_time;
3114 * While devices are being probed, the screen saver need
3115 * to be invoked explictly. XXX
3117 if (sc->flags & SC_SCRN_BLANKED) {
3118 scsplash_stick(FALSE);
3119 stop_scrn_saver(sc, current_saver);
3121 if (!ISGRAPHSC(scp)) {
3122 scsplash_stick(TRUE);
3123 (*current_saver)(sc, TRUE);
3127 #endif /* NSPLASH */
3131 #ifndef SC_DISABLE_REBOOT
3137 #ifndef SC_DISABLE_REBOOT
3138 shutdown_nice(RB_HALT);
3143 #ifndef SC_DISABLE_REBOOT
3144 shutdown_nice(RB_HALT|RB_POWEROFF);
3150 apm_suspend(PMST_SUSPEND);
3153 apm_suspend(PMST_STANDBY);
3162 #ifndef SC_DISABLE_DDBKEY
3164 Debugger("manual escape to debugger");
3166 printf("No debugger in kernel\n");
3168 #else /* SC_DISABLE_DDBKEY */
3170 #endif /* SC_DISABLE_DDBKEY */
3174 if (enable_panic_key)
3175 panic("Forced by the panic key");
3179 this_scr = scp->index;
3180 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3181 sc->first_vty + i != this_scr;
3182 i = (i + 1)%sc->vtys) {
3183 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3184 if (ISTTYOPEN(tp)) {
3185 sc_switch_scr(scp->sc, sc->first_vty + i);
3192 this_scr = scp->index;
3193 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3194 sc->first_vty + i != this_scr;
3195 i = (i + sc->vtys - 1)%sc->vtys) {
3196 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3197 if (ISTTYOPEN(tp)) {
3198 sc_switch_scr(scp->sc, sc->first_vty + i);
3205 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3206 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3209 /* assert(c & FKEY) */
3210 if (!(sc->flags & SC_SCRN_BLANKED))
3214 /* goto next_code */
3216 /* regular keys (maybe MKEY is set) */
3217 if (!(sc->flags & SC_SCRN_BLANKED))
3226 scmmap(dev_t dev, vm_offset_t offset, int nprot)
3231 if (scp != scp->sc->cur_scp)
3233 return (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, offset, nprot);
3237 save_kbd_state(scr_stat *scp)
3242 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3243 if (error == ENOIOCTL)
3246 scp->status &= ~LOCK_MASK;
3247 scp->status |= state;
3253 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3258 if (mask != LOCK_MASK) {
3259 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3260 if (error == ENOIOCTL)
3265 state |= new_bits & mask;
3267 state = new_bits & LOCK_MASK;
3269 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3270 if (error == ENOIOCTL)
3276 update_kbd_leds(scr_stat *scp, int which)
3281 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3282 if (error == ENOIOCTL)
3288 set_mode(scr_stat *scp)
3292 /* reject unsupported mode */
3293 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3296 /* if this vty is not currently showing, do nothing */
3297 if (scp != scp->sc->cur_scp)
3300 /* setup video hardware for the given mode */
3301 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3302 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3303 (void *)scp->sc->adp->va_window, FALSE);
3305 #ifndef SC_NO_FONT_LOADING
3306 /* load appropriate font */
3307 if (!(scp->status & GRAPHICS_MODE)) {
3308 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3309 if (scp->font_size < 14) {
3310 if (scp->sc->fonts_loaded & FONT_8)
3311 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3312 } else if (scp->font_size >= 16) {
3313 if (scp->sc->fonts_loaded & FONT_16)
3314 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3316 if (scp->sc->fonts_loaded & FONT_14)
3317 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3321 * This is an interim kludge to display correct font.
3322 * Always use the font page #0 on the video plane 2.
3323 * Somehow we cannot show the font in other font pages on
3324 * some video cards... XXX
3326 sc_show_font(scp, 0);
3330 #endif /* !SC_NO_FONT_LOADING */
3332 sc_set_border(scp, scp->border);
3333 sc_set_cursor_image(scp);
3339 sc_set_border(scr_stat *scp, int color)
3341 ++scp->sc->videoio_in_progress;
3342 (*scp->rndr->draw_border)(scp, color);
3343 --scp->sc->videoio_in_progress;
3346 #ifndef SC_NO_FONT_LOADING
3348 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3349 int base, int count)
3354 sc->font_loading_in_progress = TRUE;
3355 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3356 sc->font_loading_in_progress = FALSE;
3360 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3361 int base, int count)
3366 sc->font_loading_in_progress = TRUE;
3367 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3368 sc->font_loading_in_progress = FALSE;
3372 sc_show_font(scr_stat *scp, int page)
3374 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3376 #endif /* !SC_NO_FONT_LOADING */
3379 sc_paste(scr_stat *scp, u_char *p, int count)
3384 if (scp->status & MOUSE_VISIBLE) {
3385 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3388 rmap = scp->sc->scr_rmap;
3389 for (; count > 0; --count)
3390 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3395 sc_bell(scr_stat *scp, int pitch, int duration)
3397 if (cold || shutdown_in_progress)
3400 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3403 if (scp->sc->flags & SC_VISUAL_BELL) {
3404 if (scp->sc->blink_in_progress)
3406 scp->sc->blink_in_progress = 3;
3407 if (scp != scp->sc->cur_scp)
3408 scp->sc->blink_in_progress += 2;
3409 blink_screen(scp->sc->cur_scp);
3411 if (scp != scp->sc->cur_scp)
3413 sysbeep(pitch, duration);
3418 blink_screen(void *arg)
3420 scr_stat *scp = arg;
3423 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3424 scp->sc->blink_in_progress = 0;
3426 tp = VIRTUAL_TTY(scp->sc, scp->index);
3429 if (scp->sc->delayed_next_scr)
3430 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3433 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3434 scp->sc->blink_in_progress & 1);
3435 scp->sc->blink_in_progress--;
3436 timeout(blink_screen, scp, hz / 10);