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.33 2007/08/19 11:39:11 swildner Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/eventhandler.h>
43 #include <sys/reboot.h>
46 #include <sys/signalvar.h>
47 #include <sys/sysctl.h>
49 #include <sys/kernel.h>
51 #include <sys/random.h>
52 #include <sys/thread2.h>
54 #include <machine/clock.h>
55 #include <machine/console.h>
56 #include <machine/psl.h>
57 #include <machine/pc/display.h>
58 #include <machine/apm_bios.h>
59 #include <machine/frame.h>
61 #include <dev/misc/kbd/kbdreg.h>
62 #include <dev/video/fb/fbreg.h>
63 #include <dev/video/fb/splashreg.h>
69 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
70 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
72 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
74 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
76 typedef struct default_attr {
77 int std_color; /* normal hardware color */
78 int rev_color; /* reverse hardware color */
81 static default_attr user_default = {
86 static default_attr kernel_default = {
88 SC_KERNEL_CONS_REV_ATTR,
91 static int sc_console_unit = -1;
92 static scr_stat *sc_console;
93 static struct tty *sc_console_tty;
94 static void *kernel_console_ts;
96 static char init_done = COLD;
97 static char shutdown_in_progress = FALSE;
98 static char sc_malloc = FALSE;
100 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
101 static int run_scrn_saver = FALSE; /* should run the saver? */
102 static long scrn_blank_time = 0; /* screen saver timeout value */
104 static int scrn_blanked; /* # of blanked screen */
105 static int sticky_splash = FALSE;
107 static void none_saver(sc_softc_t *sc, int blank) { }
108 static void (*current_saver)(sc_softc_t *, int) = none_saver;
111 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
115 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(cdev_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);
138 static void scterm(int unit, int flags);
139 static void scshutdown(void *arg, int howto);
140 static u_int scgetc(sc_softc_t *sc, u_int flags);
142 #define SCGETC_NONBLOCK 2
143 static int sccngetch(int flags);
144 static void sccnupdate(scr_stat *scp);
145 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
146 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
147 static timeout_t scrn_timer;
148 static int and_region(int *s1, int *e1, int s2, int e2);
149 static void scrn_update(scr_stat *scp, int show_cursor);
152 static int scsplash_callback(int event, void *arg);
153 static void scsplash_saver(sc_softc_t *sc, int show);
154 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
155 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
156 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
157 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
158 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
159 static int wait_scrn_saver_stop(sc_softc_t *sc);
160 #define scsplash_stick(stick) (sticky_splash = (stick))
162 #define scsplash_stick(stick)
165 static void do_switch_scr(sc_softc_t *sc);
166 static int vt_proc_alive(scr_stat *scp);
167 static int signal_vt_rel(scr_stat *scp);
168 static int signal_vt_acq(scr_stat *scp);
169 static int finish_vt_rel(scr_stat *scp, int release);
170 static int finish_vt_acq(scr_stat *scp);
171 static void exchange_scr(sc_softc_t *sc);
172 static void update_cursor_image(scr_stat *scp);
173 static int save_kbd_state(scr_stat *scp);
174 static int update_kbd_state(scr_stat *scp, int state, int mask);
175 static int update_kbd_leds(scr_stat *scp, int which);
176 static timeout_t blink_screen;
178 #define CDEV_MAJOR 12
180 static cn_probe_t sccnprobe;
181 static cn_init_t sccninit;
182 static cn_init_t sccninit_fini;
183 static cn_getc_t sccngetc;
184 static cn_checkc_t sccncheckc;
185 static cn_putc_t sccnputc;
186 static cn_dbctl_t sccndbctl;
187 static cn_term_t sccnterm;
189 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
190 sccngetc, sccncheckc, sccnputc, sccndbctl);
192 static d_open_t scopen;
193 static d_close_t scclose;
194 static d_read_t scread;
195 static d_ioctl_t scioctl;
196 static d_mmap_t scmmap;
198 static struct dev_ops sc_ops = {
199 { "sc", CDEV_MAJOR, D_TTY | D_KQFILTER },
207 .d_kqfilter = ttykqfilter
211 sc_probe_unit(int unit, int flags)
213 if (!scvidprobe(unit, flags, FALSE)) {
215 kprintf("sc%d: no video adapter found.\n", unit);
219 /* syscons will be attached even when there is no keyboard */
220 sckbdprobe(unit, flags, FALSE);
225 /* probe video adapters, return TRUE if found */
227 scvidprobe(int unit, int flags, int cons)
230 * Access the video adapter driver through the back door!
231 * Video adapter drivers need to be configured before syscons.
232 * However, when syscons is being probed as the low-level console,
233 * they have not been initialized yet. We force them to initialize
234 * themselves here. XXX
236 vid_configure(cons ? VIO_PROBE_ONLY : 0);
238 return (vid_find_adapter("*", unit) >= 0);
241 /* probe the keyboard, return TRUE if found */
243 sckbdprobe(int unit, int flags, int cons)
245 /* access the keyboard driver through the backdoor! */
246 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
248 return (kbd_find_keyboard("*", unit) >= 0);
252 adapter_name(video_adapter_t *adp)
258 { KD_MONO, { "MDA", "MDA" } },
259 { KD_HERCULES, { "Hercules", "Hercules" } },
260 { KD_CGA, { "CGA", "CGA" } },
261 { KD_EGA, { "EGA", "EGA (mono)" } },
262 { KD_VGA, { "VGA", "VGA (mono)" } },
263 { KD_TGA, { "TGA", "TGA" } },
264 { -1, { "Unknown", "Unknown" } },
268 for (i = 0; names[i].type != -1; ++i)
269 if (names[i].type == adp->va_type)
271 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
275 sc_attach_unit(int unit, int flags)
285 flags &= ~SC_KERNEL_CONSOLE;
287 if (sc_console_unit == unit) {
289 * If this unit is being used as the system console, we need to
290 * adjust some variables and buffers before and after scinit().
292 /* assert(sc_console != NULL) */
293 flags |= SC_KERNEL_CONSOLE;
298 if (sc_console->tsw->te_size > 0) {
299 /* assert(sc_console->ts != NULL); */
300 kernel_console_ts = sc_console->ts;
301 sc_console->ts = kmalloc(sc_console->tsw->te_size,
302 M_SYSCONS, M_WAITOK);
303 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
304 (*sc_console->tsw->te_default_attr)(sc_console,
305 user_default.std_color,
306 user_default.rev_color);
312 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
315 * If this is the console we couldn't setup sc->dev before because
316 * malloc wasn't working. Set it up now.
318 if (flags & SC_KERNEL_CONSOLE) {
319 KKASSERT(sc->dev == NULL);
320 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
321 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
323 "ttyv%r", sc_console_unit*MAXCONS);
324 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
325 sc->dev[0]->si_drv1 = sc_console;
329 * Finish up the standard attach
332 callout_init(&sc->scrn_timer_ch);
333 scp = SC_STAT(sc->dev[0]);
334 if (sc_console == NULL) /* sc_console_unit < 0 */
338 if ((sc->config & SC_VESA800X600)
339 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
341 if (sc->flags & SC_SPLASH_SCRN)
342 splash_term(sc->adp);
344 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
345 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
346 sc->initial_mode = M_VESA_800x600;
348 /* put up the splash again! */
349 if (sc->flags & SC_SPLASH_SCRN)
350 splash_init(sc->adp, scsplash_callback, sc);
353 #endif /* SC_PIXEL_MODE */
355 /* initialize cursor */
357 update_cursor_image(scp);
359 /* get screen update going */
362 /* set up the keyboard */
363 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
364 update_kbd_state(scp, scp->status, LOCK_MASK);
366 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
367 unit, adapter_name(sc->adp), sc->vtys, sc->config);
369 kprintf("sc%d:", unit);
370 if (sc->adapter >= 0)
371 kprintf(" fb%d", sc->adapter);
372 if (sc->keyboard >= 0)
373 kprintf(", kbd%d", sc->keyboard);
375 kprintf(", terminal emulator: %s (%s)",
376 scp->tsw->te_name, scp->tsw->te_desc);
380 /* register a shutdown callback for the kernel console */
381 if (sc_console_unit == unit)
382 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
383 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
386 * create devices. dev_ops_add() must be called to make devices under
387 * this major number available to userland.
389 dev_ops_add(&sc_ops, ~(MAXCONS - 1), unit * MAXCONS);
391 for (vc = 0; vc < sc->vtys; vc++) {
392 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
393 UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
396 * The first vty already has struct tty and scr_stat initialized
397 * in scinit(). The other vtys will have these structs when
402 dev_ops_add(&sc_ops, -1, SC_CONSOLECTL); /* XXX */
403 dev = make_dev(&sc_ops, SC_CONSOLECTL,
404 UID_ROOT, GID_WHEEL, 0600, "consolectl");
405 dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
406 dev->si_drv1 = sc_console;
419 * As soon as malloc() becomes functional, we had better allocate
420 * various buffers for the kernel console.
423 if (sc_console_unit < 0) /* sc_console == NULL */
426 /* copy the temporary buffer to the final buffer */
427 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
429 #ifndef SC_NO_CUTPASTE
430 sc_alloc_cut_buffer(sc_console, TRUE);
433 #ifndef SC_NO_HISTORY
434 /* initialize history buffer & pointers */
435 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
439 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
442 scdevtounit(cdev_t dev)
444 int vty = SC_VTY(dev);
446 if (vty == SC_CONSOLECTL)
447 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
448 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
455 scopen(struct dev_open_args *ap)
457 cdev_t dev = ap->a_head.a_dev;
458 int unit = scdevtounit(dev);
465 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
466 major(dev), minor(dev), unit, SC_VTY(dev)));
468 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
472 tp = dev->si_tty = ttymalloc(dev->si_tty);
473 tp->t_oproc = scstart;
474 tp->t_param = scparam;
475 tp->t_stop = nottystop;
477 if (!ISTTYOPEN(tp)) {
479 /* Use the current setting of the <-- key as default VERASE. */
480 /* If the Delete key is preferable, an stty is necessary */
481 if (sc->kbd != NULL) {
482 key.keynum = KEYCODE_BS;
483 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
484 tp->t_cc[VERASE] = key.key.map[0];
486 tp->t_iflag = TTYDEF_IFLAG;
487 tp->t_oflag = TTYDEF_OFLAG;
488 tp->t_cflag = TTYDEF_CFLAG;
489 tp->t_lflag = TTYDEF_LFLAG;
490 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
491 scparam(tp, &tp->t_termios);
492 (*linesw[tp->t_line].l_modem)(tp, 1);
495 if (tp->t_state & TS_XCLUDE && suser_cred(ap->a_cred, 0))
498 error = (*linesw[tp->t_line].l_open)(dev, tp);
502 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
504 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
506 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
507 tp->t_winsize.ws_col = scp->xsize;
508 tp->t_winsize.ws_row = scp->ysize;
515 scclose(struct dev_close_args *ap)
517 cdev_t dev = ap->a_head.a_dev;
518 struct tty *tp = dev->si_tty;
522 if (SC_VTY(dev) != SC_CONSOLECTL) {
523 scp = SC_STAT(tp->t_dev);
524 /* were we in the middle of the VT switching process? */
525 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
526 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
527 cons_unavail = FALSE;
529 * note: must be called from a critical section because finish_vt_rel
530 * will call do_switch_scr which releases it temporarily
532 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
533 DPRINTF(5, ("reset WAIT_REL, "));
534 if (finish_vt_acq(scp) == 0) /* force acknowledge */
535 DPRINTF(5, ("reset WAIT_ACQ, "));
537 if (scp == &main_console) {
540 scp->smode.mode = VT_AUTO;
543 sc_vtb_destroy(&scp->vtb);
544 sc_vtb_destroy(&scp->scr);
545 sc_free_history_buffer(scp, scp->ysize);
547 kfree(scp, M_SYSCONS);
552 scp->smode.mode = VT_AUTO;
554 scp->kbd_mode = K_XLATE;
555 if (scp == scp->sc->cur_scp)
556 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
557 DPRINTF(5, ("done.\n"));
559 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
566 scread(struct dev_read_args *ap)
568 sc_touch_scrn_saver();
569 return (ttyread(ap));
573 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
581 sc = (sc_softc_t *)arg;
582 /* assert(thiskbd == sc->kbd) */
587 case KBDIO_UNLOADING:
590 kbd_release(thiskbd, (void *)&sc->keyboard);
597 * Loop while there is still input to get from the keyboard.
598 * I don't think this is nessesary, and it doesn't fix
599 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
601 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
603 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
604 if (!ISTTYOPEN(cur_tty)) {
605 cur_tty = sc_console_tty;
606 if (!ISTTYOPEN(cur_tty))
610 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
613 switch (KEYFLAGS(c)) {
614 case 0x0000: /* normal key */
615 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
617 case FKEY: /* function key, return string */
618 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
621 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
624 case MKEY: /* meta is active, prepend ESC */
625 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
626 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
628 case BKEY: /* backtab fixed sequence (esc [ Z) */
629 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
630 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
631 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
636 sc->cur_scp->status |= MOUSE_HIDDEN;
642 scparam(struct tty *tp, struct termios *t)
644 tp->t_ispeed = t->c_ispeed;
645 tp->t_ospeed = t->c_ospeed;
646 tp->t_cflag = t->c_cflag;
651 scioctl(struct dev_ioctl_args *ap)
653 cdev_t dev = ap->a_head.a_dev;
654 u_long cmd = ap->a_cmd;
655 caddr_t data = ap->a_data;
656 int flag = ap->a_fflag;
665 error = sc_vid_ioctl(tp, cmd, data, flag);
666 if (error != ENOIOCTL)
669 #ifndef SC_NO_HISTORY
670 error = sc_hist_ioctl(tp, cmd, data, flag);
671 if (error != ENOIOCTL)
675 #ifndef SC_NO_SYSMOUSE
676 error = sc_mouse_ioctl(tp, cmd, data, flag);
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);
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(uint16_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 != curproc) {
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;
878 * note: must be called from a critical section because
879 * finish_vt_rel will call do_switch_scr which releases it
882 if (finish_vt_rel(scp, TRUE) == 0)
883 DPRINTF(5, ("reset WAIT_REL, "));
884 if (finish_vt_acq(scp) == 0)
885 DPRINTF(5, ("reset WAIT_ACQ, "));
887 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
888 || !ISSIGVALID(mode->frsig)) {
890 DPRINTF(5, ("error EINVAL\n"));
893 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
894 bcopy(data, &scp->smode, sizeof(struct vt_mode));
896 scp->pid = scp->proc->p_pid;
897 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
905 case VT_GETMODE: /* get screen switcher mode */
906 bcopy(&scp->smode, data, sizeof(struct vt_mode));
909 case VT_RELDISP: /* screen switcher ioctl */
912 * This must be the current vty which is in the VT_PROCESS
915 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
919 /* ...and this process is controlling it. */
920 if (scp->proc != curproc) {
925 switch(*(int *)data) {
926 case VT_FALSE: /* user refuses to release screen, abort */
928 * note: must be called from a critical section because
929 * finish_vt_rel will call do_switch_scr which releases it
932 if ((error = finish_vt_rel(scp, FALSE)) == 0)
933 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
935 case VT_TRUE: /* user has released screen, go on */
937 * note: must be called from a critical section because
938 * finish_vt_rel will call do_switch_scr which releases it
941 if ((error = finish_vt_rel(scp, TRUE)) == 0)
942 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
944 case VT_ACKACQ: /* acquire acknowledged, switch completed */
945 if ((error = finish_vt_acq(scp)) == 0)
946 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
954 case VT_OPENQRY: /* return free virtual console */
955 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
956 tp = VIRTUAL_TTY(sc, i);
957 if (!ISTTYOPEN(tp)) {
958 *(int *)data = i + 1;
964 case VT_ACTIVATE: /* switch to screen *data */
965 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
967 sc_clean_up(sc->cur_scp);
969 return sc_switch_scr(sc, i);
971 case VT_WAITACTIVE: /* wait for switch to occur */
972 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
973 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
976 error = sc_clean_up(sc->cur_scp);
980 scp = SC_STAT(SC_DEV(sc, i));
981 if (scp == scp->sc->cur_scp)
983 while ((error=tsleep((caddr_t)&scp->smode, PCATCH,
984 "waitvt", 0)) == ERESTART) ;
987 case VT_GETACTIVE: /* get active vty # */
988 *(int *)data = sc->cur_scp->index + 1;
991 case VT_GETINDEX: /* get this vty # */
992 *(int *)data = scp->index + 1;
995 case VT_LOCKSWITCH: /* prevent vty switching */
996 if ((*(int *)data) & 0x01)
997 sc->flags |= SC_SCRN_VTYLOCK;
999 sc->flags &= ~SC_SCRN_VTYLOCK;
1002 case KDENABIO: /* allow io operations */
1003 error = suser_cred(ap->a_cred, 0);
1006 if (securelevel > 0)
1008 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1011 case KDDISABIO: /* disallow io operations (default) */
1012 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1015 case KDSKBSTATE: /* set keyboard state (locks) */
1016 if (*(int *)data & ~LOCK_MASK)
1018 scp->status &= ~LOCK_MASK;
1019 scp->status |= *(int *)data;
1020 if (scp == sc->cur_scp)
1021 update_kbd_state(scp, scp->status, LOCK_MASK);
1024 case KDGKBSTATE: /* get keyboard state (locks) */
1025 if (scp == sc->cur_scp)
1026 save_kbd_state(scp);
1027 *(int *)data = scp->status & LOCK_MASK;
1030 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1031 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1032 error = kbd_ioctl(sc->kbd, cmd, data);
1033 if (error == ENOIOCTL)
1037 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1038 if (*(int *)data & ~0x7f)
1040 error = kbd_ioctl(sc->kbd, cmd, data);
1041 if (error == ENOIOCTL)
1045 case KDSKBMODE: /* set keyboard mode */
1046 switch (*(int *)data) {
1047 case K_XLATE: /* switch to XLT ascii mode */
1048 case K_RAW: /* switch to RAW scancode mode */
1049 case K_CODE: /* switch to CODE mode */
1050 scp->kbd_mode = *(int *)data;
1051 if (scp == sc->cur_scp)
1052 kbd_ioctl(sc->kbd, cmd, data);
1059 case KDGKBMODE: /* get keyboard mode */
1060 *(int *)data = scp->kbd_mode;
1064 error = kbd_ioctl(sc->kbd, cmd, data);
1065 if (error == ENOIOCTL)
1069 case KDMKTONE: /* sound the bell */
1071 sc_bell(scp, (*(int*)data)&0xffff,
1072 (((*(int*)data)>>16)&0xffff)*hz/1000);
1074 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1077 case KIOCSOUND: /* make tone (*data) hz */
1078 if (scp == sc->cur_scp) {
1080 return sc_tone(*(int *)data);
1086 case KDGKBTYPE: /* get keyboard type */
1087 error = kbd_ioctl(sc->kbd, cmd, data);
1088 if (error == ENOIOCTL) {
1089 /* always return something? XXX */
1094 case KDSETLED: /* set keyboard LED status */
1095 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1097 scp->status &= ~LED_MASK;
1098 scp->status |= *(int *)data;
1099 if (scp == sc->cur_scp)
1100 update_kbd_leds(scp, scp->status);
1103 case KDGETLED: /* get keyboard LED status */
1104 if (scp == sc->cur_scp)
1105 save_kbd_state(scp);
1106 *(int *)data = scp->status & LED_MASK;
1109 case CONS_SETKBD: /* set the new keyboard */
1114 newkbd = kbd_get_keyboard(*(int *)data);
1115 if (newkbd == NULL) {
1120 if (sc->kbd != newkbd) {
1121 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1122 (void *)&sc->keyboard, sckbdevent, sc);
1123 /* i == newkbd->kb_index */
1125 if (sc->kbd != NULL) {
1126 save_kbd_state(sc->cur_scp);
1127 kbd_release(sc->kbd, (void *)&sc->keyboard);
1129 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1131 kbd_ioctl(sc->kbd, KDSKBMODE,
1132 (caddr_t)&sc->cur_scp->kbd_mode);
1133 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1136 error = EPERM; /* XXX */
1143 case CONS_RELKBD: /* release the current keyboard */
1146 if (sc->kbd != NULL) {
1147 save_kbd_state(sc->cur_scp);
1148 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1157 case CONS_GETTERM: /* get the current terminal emulator info */
1161 if (((term_info_t *)data)->ti_index == 0) {
1164 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1167 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1168 sizeof(((term_info_t *)data)->ti_name));
1169 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1170 sizeof(((term_info_t *)data)->ti_desc));
1171 ((term_info_t *)data)->ti_flags = 0;
1174 ((term_info_t *)data)->ti_name[0] = '\0';
1175 ((term_info_t *)data)->ti_desc[0] = '\0';
1176 ((term_info_t *)data)->ti_flags = 0;
1181 case CONS_SETTERM: /* set the current terminal emulator */
1183 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1184 /* FIXME: what if scp == sc_console! XXX */
1188 case GIO_SCRNMAP: /* get output translation table */
1189 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1192 case PIO_SCRNMAP: /* set output translation table */
1193 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1194 for (i=0; i<sizeof(sc->scr_map); i++) {
1195 sc->scr_rmap[sc->scr_map[i]] = i;
1199 case GIO_KEYMAP: /* get keyboard translation table */
1200 case PIO_KEYMAP: /* set keyboard translation table */
1201 case GIO_DEADKEYMAP: /* get accent key translation table */
1202 case PIO_DEADKEYMAP: /* set accent key translation table */
1203 case GETFKEY: /* get function key string */
1204 case SETFKEY: /* set function key string */
1205 error = kbd_ioctl(sc->kbd, cmd, data);
1206 if (error == ENOIOCTL)
1210 #ifndef SC_NO_FONT_LOADING
1212 case PIO_FONT8x8: /* set 8x8 dot font */
1213 if (!ISFONTAVAIL(sc->adp->va_flags))
1215 bcopy(data, sc->font_8, 8*256);
1216 sc->fonts_loaded |= FONT_8;
1219 * Always use the font page #0. XXX
1220 * Don't load if the current font size is not 8x8.
1222 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1223 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1226 case GIO_FONT8x8: /* get 8x8 dot font */
1227 if (!ISFONTAVAIL(sc->adp->va_flags))
1229 if (sc->fonts_loaded & FONT_8) {
1230 bcopy(sc->font_8, data, 8*256);
1236 case PIO_FONT8x14: /* set 8x14 dot font */
1237 if (!ISFONTAVAIL(sc->adp->va_flags))
1239 bcopy(data, sc->font_14, 14*256);
1240 sc->fonts_loaded |= FONT_14;
1243 * Always use the font page #0. XXX
1244 * Don't load if the current font size is not 8x14.
1246 if (ISTEXTSC(sc->cur_scp)
1247 && (sc->cur_scp->font_size >= 14)
1248 && (sc->cur_scp->font_size < 16))
1249 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1252 case GIO_FONT8x14: /* get 8x14 dot font */
1253 if (!ISFONTAVAIL(sc->adp->va_flags))
1255 if (sc->fonts_loaded & FONT_14) {
1256 bcopy(sc->font_14, data, 14*256);
1262 case PIO_FONT8x16: /* set 8x16 dot font */
1263 if (!ISFONTAVAIL(sc->adp->va_flags))
1265 bcopy(data, sc->font_16, 16*256);
1266 sc->fonts_loaded |= FONT_16;
1269 * Always use the font page #0. XXX
1270 * Don't load if the current font size is not 8x16.
1272 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1273 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1276 case GIO_FONT8x16: /* get 8x16 dot font */
1277 if (!ISFONTAVAIL(sc->adp->va_flags))
1279 if (sc->fonts_loaded & FONT_16) {
1280 bcopy(sc->font_16, data, 16*256);
1286 #endif /* SC_NO_FONT_LOADING */
1292 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1293 if (error != ENOIOCTL)
1295 error = ttioctl(tp, cmd, data, flag);
1296 if (error != ENOIOCTL)
1302 scstart(struct tty *tp)
1306 u_char buf[PCBURST];
1307 scr_stat *scp = SC_STAT(tp->t_dev);
1309 if (scp->status & SLKED ||
1310 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1313 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1314 tp->t_state |= TS_BUSY;
1317 len = q_to_b(rbp, buf, PCBURST);
1319 sc_puts(scp, buf, len);
1322 tp->t_state &= ~TS_BUSY;
1329 sccnprobe(struct consdev *cp)
1334 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1336 /* a video card is always required */
1337 if (!scvidprobe(unit, flags, TRUE))
1338 cp->cn_pri = CN_DEAD;
1340 /* syscons will become console even when there is no keyboard */
1341 sckbdprobe(unit, flags, TRUE);
1343 if (cp->cn_pri == CN_DEAD)
1346 /* initialize required fields */
1347 cp->cn_probegood = 1;
1351 sccninit(struct consdev *cp)
1356 sc_get_cons_priority(&unit, &flags);
1357 scinit(unit, flags | SC_KERNEL_CONSOLE);
1358 sc_console_unit = unit;
1359 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1363 sccninit_fini(struct consdev *cp)
1365 cp->cn_dev = make_dev(&sc_ops, SC_CONSOLECTL,
1366 UID_ROOT, GID_WHEEL, 0600, "consolectl");
1370 sccnterm(struct consdev *cp)
1372 /* we are not the kernel console any more, release everything */
1374 if (sc_console_unit < 0)
1375 return; /* shouldn't happen */
1378 sc_clear_screen(sc_console);
1379 sccnupdate(sc_console);
1381 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1382 sc_console_unit = -1;
1387 sccnputc(void *private, int c)
1390 scr_stat *scp = sc_console;
1392 #ifndef SC_NO_HISTORY
1394 #endif /* !SC_NO_HISTORY */
1396 /* assert(sc_console != NULL) */
1398 #ifndef SC_NO_HISTORY
1399 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1400 scp->status &= ~SLKED;
1401 update_kbd_state(scp, scp->status, SLKED);
1402 if (scp->status & BUFFER_SAVED) {
1403 if (!sc_hist_restore(scp))
1404 sc_remove_cutmarking(scp);
1405 scp->status &= ~BUFFER_SAVED;
1406 scp->status |= CURSOR_ENABLED;
1407 sc_draw_cursor_image(scp);
1409 tp = VIRTUAL_TTY(scp->sc, scp->index);
1413 #endif /* !SC_NO_HISTORY */
1416 if (kernel_console_ts != NULL)
1417 scp->ts = kernel_console_ts;
1419 sc_puts(scp, buf, 1);
1428 sccngetc(void *private)
1430 return sccngetch(0);
1434 sccncheckc(void *private)
1436 return sccngetch(SCGETC_NONBLOCK);
1440 sccndbctl(void *private, int on)
1442 /* assert(sc_console_unit >= 0) */
1443 /* try to switch to the kernel console screen */
1444 if (on && debugger == 0) {
1446 * TRY to make sure the screen saver is stopped,
1447 * and the screen is updated before switching to
1452 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1453 && sc_console->smode.mode == VT_AUTO) {
1454 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1455 sc_switch_scr(sc_console->sc, sc_console->index);
1465 sccngetch(int flags)
1467 static struct fkeytab fkey;
1475 /* assert(sc_console != NULL) */
1478 * Stop the screen saver and update the screen if necessary.
1479 * What if we have been running in the screen saver code... XXX
1481 sc_touch_scrn_saver();
1482 scp = sc_console->sc->cur_scp; /* XXX */
1485 if (fkeycp < fkey.len) {
1487 return fkey.str[fkeycp++];
1490 if (scp->sc->kbd == NULL) {
1496 * Make sure the keyboard is accessible even when the kbd device
1497 * driver is disabled.
1499 kbd_enable(scp->sc->kbd);
1501 /* we shall always use the keyboard in the XLATE mode here */
1502 cur_mode = scp->kbd_mode;
1503 scp->kbd_mode = K_XLATE;
1504 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1506 kbd_poll(scp->sc->kbd, TRUE);
1507 c = scgetc(scp->sc, SCGETC_CN | flags);
1508 kbd_poll(scp->sc->kbd, FALSE);
1510 scp->kbd_mode = cur_mode;
1511 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1512 kbd_disable(scp->sc->kbd);
1515 switch (KEYFLAGS(c)) {
1516 case 0: /* normal char */
1518 case FKEY: /* function key */
1519 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1521 if ((p != NULL) && (fkey.len > 0)) {
1522 bcopy(p, fkey.str, fkey.len);
1536 sccnupdate(scr_stat *scp)
1538 /* this is a cut-down version of scrn_timer()... */
1540 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1543 if (debugger > 0 || panicstr || shutdown_in_progress) {
1544 sc_touch_scrn_saver();
1545 } else if (scp != scp->sc->cur_scp) {
1549 if (!run_scrn_saver)
1550 scp->sc->flags &= ~SC_SCRN_IDLE;
1552 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1553 if (scp->sc->flags & SC_SCRN_BLANKED)
1554 stop_scrn_saver(scp->sc, current_saver);
1555 #endif /* NSPLASH */
1557 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1558 || scp->sc->switch_in_progress)
1561 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1562 * when write_in_progress is non-zero. XXX
1565 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1566 scrn_update(scp, TRUE);
1570 scrn_timer(void *arg)
1572 static int kbd_interval = 0;
1578 again = (arg != NULL);
1580 sc = (sc_softc_t *)arg;
1581 else if (sc_console != NULL)
1582 sc = sc_console->sc;
1586 /* don't do anything when we are performing some I/O operations */
1587 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1589 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1594 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1595 /* try to allocate a keyboard automatically */
1596 if (++kbd_interval >= 25) {
1597 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1599 if (sc->keyboard >= 0) {
1600 sc->kbd = kbd_get_keyboard(sc->keyboard);
1601 kbd_ioctl(sc->kbd, KDSKBMODE,
1602 (caddr_t)&sc->cur_scp->kbd_mode);
1603 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1610 /* find the vty to update */
1613 /* should we stop the screen saver? */
1614 getmicrouptime(&tv);
1615 if (debugger > 0 || panicstr || shutdown_in_progress)
1616 sc_touch_scrn_saver();
1617 if (run_scrn_saver) {
1618 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1619 sc->flags |= SC_SCRN_IDLE;
1621 sc->flags &= ~SC_SCRN_IDLE;
1623 sc->scrn_time_stamp = tv.tv_sec;
1624 sc->flags &= ~SC_SCRN_IDLE;
1625 if (scrn_blank_time > 0)
1626 run_scrn_saver = TRUE;
1629 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1630 if (sc->flags & SC_SCRN_BLANKED)
1631 stop_scrn_saver(sc, current_saver);
1632 #endif /* NSPLASH */
1634 /* should we just return ? */
1635 if (sc->blink_in_progress || sc->switch_in_progress
1636 || sc->write_in_progress) {
1638 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1643 /* Update the screen */
1644 scp = sc->cur_scp; /* cur_scp may have changed... */
1645 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1646 scrn_update(scp, TRUE);
1649 /* should we activate the screen saver? */
1650 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1651 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1652 (*current_saver)(sc, TRUE);
1653 #endif /* NSPLASH */
1656 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1661 and_region(int *s1, int *e1, int s2, int e2)
1663 if (*e1 < s2 || e2 < *s1)
1665 *s1 = imax(*s1, s2);
1666 *e1 = imin(*e1, e2);
1671 scrn_update(scr_stat *scp, int show_cursor)
1678 /* assert(scp == scp->sc->cur_scp) */
1680 ++scp->sc->videoio_in_progress;
1682 #ifndef SC_NO_CUTPASTE
1683 /* remove the previous mouse pointer image if necessary */
1684 if (scp->status & MOUSE_VISIBLE) {
1686 e = scp->mouse_pos + scp->xsize + 1;
1687 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1688 || and_region(&s, &e, scp->start, scp->end)
1689 || ((scp->status & CURSOR_ENABLED) &&
1690 (scp->cursor_pos != scp->cursor_oldpos) &&
1691 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1692 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1693 sc_remove_mouse_image(scp);
1694 if (scp->end >= scp->xsize*scp->ysize)
1695 scp->end = scp->xsize*scp->ysize - 1;
1698 #endif /* !SC_NO_CUTPASTE */
1702 if (scp->end >= scp->xsize*scp->ysize) {
1703 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1704 scp->end = scp->xsize*scp->ysize - 1;
1706 if (scp->start < 0) {
1707 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
1712 /* update screen image */
1713 if (scp->start <= scp->end) {
1714 if (scp->mouse_cut_end >= 0) {
1715 /* there is a marked region for cut & paste */
1716 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1717 start = scp->mouse_cut_start;
1718 end = scp->mouse_cut_end;
1720 start = scp->mouse_cut_end;
1721 end = scp->mouse_cut_start - 1;
1725 /* does the cut-mark region overlap with the update region? */
1726 if (and_region(&s, &e, scp->start, scp->end)) {
1727 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1730 if (and_region(&s, &e, scp->start, scp->end))
1731 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1733 e = scp->xsize*scp->ysize - 1;
1734 if (and_region(&s, &e, scp->start, scp->end))
1735 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1737 (*scp->rndr->draw)(scp, scp->start,
1738 scp->end - scp->start + 1, FALSE);
1741 (*scp->rndr->draw)(scp, scp->start,
1742 scp->end - scp->start + 1, FALSE);
1746 /* we are not to show the cursor and the mouse pointer... */
1749 scp->start = scp->xsize*scp->ysize - 1;
1750 --scp->sc->videoio_in_progress;
1754 /* update cursor image */
1755 if (scp->status & CURSOR_ENABLED) {
1758 /* did cursor move since last time ? */
1759 if (scp->cursor_pos != scp->cursor_oldpos) {
1760 /* do we need to remove old cursor image ? */
1761 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1762 sc_remove_cursor_image(scp);
1763 sc_draw_cursor_image(scp);
1765 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1766 /* cursor didn't move, but has been overwritten */
1767 sc_draw_cursor_image(scp);
1768 else if (scp->sc->flags & SC_BLINK_CURSOR)
1769 /* if it's a blinking cursor, update it */
1770 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1771 sc_inside_cutmark(scp,
1776 #ifndef SC_NO_CUTPASTE
1777 /* update "pseudo" mouse pointer image */
1778 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1779 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1780 scp->status &= ~MOUSE_MOVED;
1781 sc_draw_mouse_image(scp);
1784 #endif /* SC_NO_CUTPASTE */
1787 scp->start = scp->xsize*scp->ysize - 1;
1789 --scp->sc->videoio_in_progress;
1794 scsplash_callback(int event, void *arg)
1799 sc = (sc_softc_t *)arg;
1803 if (add_scrn_saver(scsplash_saver) == 0) {
1804 sc->flags &= ~SC_SAVER_FAILED;
1805 run_scrn_saver = TRUE;
1806 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1807 scsplash_stick(TRUE);
1808 (*current_saver)(sc, TRUE);
1814 if (current_saver == scsplash_saver) {
1815 scsplash_stick(FALSE);
1816 error = remove_scrn_saver(scsplash_saver);
1828 scsplash_saver(sc_softc_t *sc, int show)
1830 static int busy = FALSE;
1839 if (!(sc->flags & SC_SAVER_FAILED)) {
1840 if (!(sc->flags & SC_SCRN_BLANKED))
1841 set_scrn_saver_mode(scp, -1, NULL, 0);
1842 switch (splash(sc->adp, TRUE)) {
1843 case 0: /* succeeded */
1845 case EAGAIN: /* try later */
1846 restore_scrn_saver_mode(scp, FALSE);
1847 sc_touch_scrn_saver(); /* XXX */
1850 sc->flags |= SC_SAVER_FAILED;
1851 scsplash_stick(FALSE);
1852 restore_scrn_saver_mode(scp, TRUE);
1853 kprintf("scsplash_saver(): failed to put up the image\n");
1857 } else if (!sticky_splash) {
1858 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1859 restore_scrn_saver_mode(scp, TRUE);
1865 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1870 if (current_saver != none_saver) {
1871 error = remove_scrn_saver(current_saver);
1876 if (current_saver != none_saver)
1879 run_scrn_saver = FALSE;
1880 saver_mode = CONS_LKM_SAVER;
1881 current_saver = this_saver;
1886 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1888 if (current_saver != this_saver)
1893 * In order to prevent `current_saver' from being called by
1894 * the timeout routine `scrn_timer()' while we manipulate
1895 * the saver list, we shall set `current_saver' to `none_saver'
1896 * before stopping the current saver, rather than blocking by `splXX()'.
1898 current_saver = none_saver;
1900 stop_scrn_saver(this_saver);
1903 /* unblank all blanked screens */
1904 wait_scrn_saver_stop(NULL);
1908 current_saver = none_saver;
1913 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1916 /* assert(scp == scp->sc->cur_scp) */
1918 if (!ISGRAPHSC(scp))
1919 sc_remove_cursor_image(scp);
1920 scp->splash_save_mode = scp->mode;
1921 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1922 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1923 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1924 scp->sc->flags |= SC_SCRN_BLANKED;
1930 if (set_mode(scp) == 0) {
1931 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1932 scp->status |= GRAPHICS_MODE;
1933 #ifndef SC_NO_PALETTE_LOADING
1935 load_palette(scp->sc->adp, pal);
1937 sc_set_border(scp, border);
1941 scp->mode = scp->splash_save_mode;
1942 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1943 scp->status |= scp->splash_save_status;
1950 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1955 /* assert(scp == scp->sc->cur_scp) */
1958 status = scp->status;
1959 scp->mode = scp->splash_save_mode;
1960 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1961 scp->status |= scp->splash_save_status;
1962 scp->sc->flags &= ~SC_SCRN_BLANKED;
1964 if (!ISGRAPHSC(scp))
1965 sc_draw_cursor_image(scp);
1970 if (set_mode(scp) == 0) {
1971 #ifndef SC_NO_PALETTE_LOADING
1972 load_palette(scp->sc->adp, scp->sc->palette);
1979 scp->status = status;
1986 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
1988 (*saver)(sc, FALSE);
1989 run_scrn_saver = FALSE;
1990 /* the screen saver may have chosen not to stop after all... */
1991 if (sc->flags & SC_SCRN_BLANKED)
1994 mark_all(sc->cur_scp);
1995 if (sc->delayed_next_scr)
1996 sc_switch_scr(sc, sc->delayed_next_scr - 1);
1997 wakeup((caddr_t)&scrn_blanked);
2001 wait_scrn_saver_stop(sc_softc_t *sc)
2005 while (scrn_blanked > 0) {
2006 run_scrn_saver = FALSE;
2007 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2011 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2012 if ((error != 0) && (error != ERESTART))
2015 run_scrn_saver = FALSE;
2018 #endif /* NSPLASH */
2021 sc_touch_scrn_saver(void)
2023 scsplash_stick(FALSE);
2024 run_scrn_saver = FALSE;
2028 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2033 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2035 /* prevent switch if previously requested */
2036 if (sc->flags & SC_SCRN_VTYLOCK) {
2037 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2038 sc->cur_scp->bell_duration);
2042 /* delay switch if the screen is blanked or being updated */
2043 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2044 || sc->blink_in_progress || sc->videoio_in_progress) {
2045 sc->delayed_next_scr = next_scr + 1;
2046 sc_touch_scrn_saver();
2047 DPRINTF(5, ("switch delayed\n"));
2052 cur_scp = sc->cur_scp;
2054 /* we are in the middle of the vty switching process... */
2055 if (sc->switch_in_progress
2056 && (cur_scp->smode.mode == VT_PROCESS)
2058 if (cur_scp->proc != pfind(cur_scp->pid)) {
2060 * The controlling process has died!!. Do some clean up.
2061 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2062 * are not reset here yet; they will be cleared later.
2064 DPRINTF(5, ("cur_scp controlling process %d died, ",
2066 if (cur_scp->status & SWITCH_WAIT_REL) {
2068 * Force the previous switch to finish, but return now
2071 * note: must be called from a critical section because
2072 * finish_vt_rel will call do_switch_scr which releases it
2075 DPRINTF(5, ("reset WAIT_REL, "));
2076 finish_vt_rel(cur_scp, TRUE);
2078 DPRINTF(5, ("finishing previous switch\n"));
2080 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2081 /* let's assume screen switch has been completed. */
2082 DPRINTF(5, ("reset WAIT_ACQ, "));
2083 finish_vt_acq(cur_scp);
2086 * We are in between screen release and acquisition, and
2087 * reached here via scgetc() or scrn_timer() which has
2088 * interrupted exchange_scr(). Don't do anything stupid.
2090 DPRINTF(5, ("waiting nothing, "));
2094 * The controlling process is alive, but not responding...
2095 * It is either buggy or it may be just taking time.
2096 * The following code is a gross kludge to cope with this
2097 * problem for which there is no clean solution. XXX
2099 if (cur_scp->status & SWITCH_WAIT_REL) {
2100 switch (sc->switch_in_progress++) {
2104 DPRINTF(5, ("sending relsig again, "));
2105 signal_vt_rel(cur_scp);
2112 * Act as if the controlling program returned
2115 * note: must be called from a critical section because
2116 * finish_vt_rel will call do_switch_scr which releases it
2119 DPRINTF(5, ("force reset WAIT_REL, "));
2120 finish_vt_rel(cur_scp, FALSE);
2122 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2125 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2126 switch (sc->switch_in_progress++) {
2130 DPRINTF(5, ("sending acqsig again, "));
2131 signal_vt_acq(cur_scp);
2137 /* clear the flag and finish the previous switch */
2138 DPRINTF(5, ("force reset WAIT_ACQ, "));
2139 finish_vt_acq(cur_scp);
2147 * Return error if an invalid argument is given, or vty switch
2148 * is still in progress.
2150 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2151 || sc->switch_in_progress) {
2153 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2154 DPRINTF(5, ("error 1\n"));
2159 * Don't allow switching away from the graphics mode vty
2160 * if the switch mode is VT_AUTO, unless the next vty is the same
2161 * as the current or the current vty has been closed (but showing).
2163 tp = VIRTUAL_TTY(sc, cur_scp->index);
2164 if ((cur_scp->index != next_scr)
2166 && (cur_scp->smode.mode == VT_AUTO)
2167 && ISGRAPHSC(cur_scp)) {
2169 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2170 DPRINTF(5, ("error, graphics mode\n"));
2175 * Is the wanted vty open? Don't allow switching to a closed vty.
2176 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2177 * Note that we always allow the user to switch to the kernel
2178 * console even if it is closed.
2180 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2181 tp = VIRTUAL_TTY(sc, next_scr);
2182 if (!ISTTYOPEN(tp)) {
2184 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2185 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2188 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2190 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2195 /* this is the start of vty switching process... */
2196 ++sc->switch_in_progress;
2197 sc->delayed_next_scr = 0;
2198 sc->old_scp = cur_scp;
2199 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2200 if (sc->new_scp == sc->old_scp) {
2201 sc->switch_in_progress = 0;
2202 wakeup((caddr_t)&sc->new_scp->smode);
2204 DPRINTF(5, ("switch done (new == old)\n"));
2208 /* has controlling process died? */
2209 vt_proc_alive(sc->old_scp);
2210 vt_proc_alive(sc->new_scp);
2212 /* wait for the controlling process to release the screen, if necessary */
2213 if (signal_vt_rel(sc->old_scp)) {
2218 /* go set up the new vty screen */
2223 /* wake up processes waiting for this vty */
2224 wakeup((caddr_t)&sc->cur_scp->smode);
2226 /* wait for the controlling process to acknowledge, if necessary */
2227 if (signal_vt_acq(sc->cur_scp)) {
2232 sc->switch_in_progress = 0;
2233 if (sc->unit == sc_console_unit)
2234 cons_unavail = FALSE;
2236 DPRINTF(5, ("switch done\n"));
2242 * NOTE: must be called from a critical section because do_switch_scr
2243 * will release it temporarily.
2246 do_switch_scr(sc_softc_t *sc)
2248 vt_proc_alive(sc->new_scp);
2253 /* sc->cur_scp == sc->new_scp */
2254 wakeup((caddr_t)&sc->cur_scp->smode);
2256 /* wait for the controlling process to acknowledge, if necessary */
2257 if (!signal_vt_acq(sc->cur_scp)) {
2258 sc->switch_in_progress = 0;
2259 if (sc->unit == sc_console_unit)
2260 cons_unavail = FALSE;
2265 vt_proc_alive(scr_stat *scp)
2268 if (scp->proc == pfind(scp->pid))
2271 scp->smode.mode = VT_AUTO;
2272 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2278 signal_vt_rel(scr_stat *scp)
2280 if (scp->smode.mode != VT_PROCESS)
2282 scp->status |= SWITCH_WAIT_REL;
2283 ksignal(scp->proc, scp->smode.relsig);
2284 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2289 signal_vt_acq(scr_stat *scp)
2291 if (scp->smode.mode != VT_PROCESS)
2293 if (scp->sc->unit == sc_console_unit)
2294 cons_unavail = TRUE;
2295 scp->status |= SWITCH_WAIT_ACQ;
2296 ksignal(scp->proc, scp->smode.acqsig);
2297 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2302 * NOTE: must be called from a critical section because do_switch_scr
2303 * will release it temporarily.
2306 finish_vt_rel(scr_stat *scp, int release)
2308 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2309 scp->status &= ~SWITCH_WAIT_REL;
2311 do_switch_scr(scp->sc);
2313 scp->sc->switch_in_progress = 0;
2320 finish_vt_acq(scr_stat *scp)
2322 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2323 scp->status &= ~SWITCH_WAIT_ACQ;
2324 scp->sc->switch_in_progress = 0;
2331 exchange_scr(sc_softc_t *sc)
2335 /* save the current state of video and keyboard */
2336 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2337 if (!ISGRAPHSC(sc->old_scp))
2338 sc_remove_cursor_image(sc->old_scp);
2339 if (sc->old_scp->kbd_mode == K_XLATE)
2340 save_kbd_state(sc->old_scp);
2342 /* set up the video for the new screen */
2343 scp = sc->cur_scp = sc->new_scp;
2344 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2347 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2348 (void *)sc->adp->va_window, FALSE);
2349 scp->status |= MOUSE_HIDDEN;
2350 sc_move_cursor(scp, scp->xpos, scp->ypos);
2351 if (!ISGRAPHSC(scp))
2352 sc_set_cursor_image(scp);
2353 #ifndef SC_NO_PALETTE_LOADING
2354 if (ISGRAPHSC(sc->old_scp))
2355 load_palette(sc->adp, sc->palette);
2357 sc_set_border(scp, scp->border);
2359 /* set up the keyboard for the new screen */
2360 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2361 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2362 update_kbd_state(scp, scp->status, LOCK_MASK);
2368 sc_puts(scr_stat *scp, u_char *buf, int len)
2371 /* make screensaver happy */
2372 if (!sticky_splash && scp == scp->sc->cur_scp)
2373 run_scrn_saver = FALSE;
2377 (*scp->tsw->te_puts)(scp, buf, len);
2379 if (scp->sc->delayed_next_scr)
2380 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2384 sc_draw_cursor_image(scr_stat *scp)
2386 /* assert(scp == scp->sc->cur_scp); */
2387 ++scp->sc->videoio_in_progress;
2388 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2389 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2390 sc_inside_cutmark(scp, scp->cursor_pos));
2391 scp->cursor_oldpos = scp->cursor_pos;
2392 --scp->sc->videoio_in_progress;
2396 sc_remove_cursor_image(scr_stat *scp)
2398 /* assert(scp == scp->sc->cur_scp); */
2399 ++scp->sc->videoio_in_progress;
2400 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2401 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2402 sc_inside_cutmark(scp, scp->cursor_oldpos));
2403 --scp->sc->videoio_in_progress;
2407 update_cursor_image(scr_stat *scp)
2411 if (scp->sc->flags & SC_CHAR_CURSOR) {
2412 scp->cursor_base = imax(0, scp->sc->cursor_base);
2413 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2415 scp->cursor_base = 0;
2416 scp->cursor_height = scp->font_size;
2418 blink = scp->sc->flags & SC_BLINK_CURSOR;
2420 /* assert(scp == scp->sc->cur_scp); */
2421 ++scp->sc->videoio_in_progress;
2422 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2423 sc_inside_cutmark(scp, scp->cursor_pos));
2424 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2425 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2426 sc_inside_cutmark(scp, scp->cursor_pos));
2427 --scp->sc->videoio_in_progress;
2431 sc_set_cursor_image(scr_stat *scp)
2433 if (scp->sc->flags & SC_CHAR_CURSOR) {
2434 scp->cursor_base = imax(0, scp->sc->cursor_base);
2435 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2437 scp->cursor_base = 0;
2438 scp->cursor_height = scp->font_size;
2441 /* assert(scp == scp->sc->cur_scp); */
2442 ++scp->sc->videoio_in_progress;
2443 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2444 scp->sc->flags & SC_BLINK_CURSOR);
2445 --scp->sc->videoio_in_progress;
2449 scinit(int unit, int flags)
2452 * When syscons is being initialized as the kernel console, malloc()
2453 * is not yet functional, because various kernel structures has not been
2454 * fully initialized yet. Therefore, we need to declare the following
2455 * static buffers for the console. This is less than ideal,
2456 * but is necessry evil for the time being. XXX
2458 static scr_stat main_console;
2459 static u_short sc_buffer[ROW*COL]; /* XXX */
2460 #ifndef SC_NO_FONT_LOADING
2461 static u_char font_8[256*8];
2462 static u_char font_14[256*14];
2463 static u_char font_16[256*16];
2468 video_adapter_t *adp;
2473 /* one time initialization */
2474 if (init_done == COLD)
2475 sc_get_bios_values(&bios_value);
2479 * Allocate resources. Even if we are being called for the second
2480 * time, we must allocate them again, because they might have
2483 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2485 if (sc->adapter >= 0) {
2486 vid_release(sc->adp, (void *)&sc->adapter);
2490 if (sc->keyboard >= 0) {
2491 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2492 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2493 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2494 if (sc->kbd != NULL) {
2495 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2496 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2500 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2501 sc->adp = vid_get_adapter(sc->adapter);
2502 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2503 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2505 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2506 sc->kbd = kbd_get_keyboard(sc->keyboard);
2507 if (sc->kbd != NULL) {
2508 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2509 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2512 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2514 sc->initial_mode = sc->adp->va_initial_mode;
2516 #ifndef SC_NO_FONT_LOADING
2517 if (flags & SC_KERNEL_CONSOLE) {
2518 sc->font_8 = font_8;
2519 sc->font_14 = font_14;
2520 sc->font_16 = font_16;
2521 } else if (sc->font_8 == NULL) {
2522 /* assert(sc_malloc) */
2523 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2524 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2525 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2529 /* extract the hardware cursor location and hide the cursor for now */
2530 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2531 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2533 /* set up the first console */
2534 sc->first_vty = unit*MAXCONS;
2535 sc->vtys = MAXCONS; /* XXX: should be configurable */
2536 if (flags & SC_KERNEL_CONSOLE) {
2537 scp = &main_console;
2538 sc->console_scp = scp;
2539 init_scp(sc, sc->first_vty, scp);
2540 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2541 (void *)sc_buffer, FALSE);
2542 if (sc_init_emulator(scp, SC_DFLT_TERM))
2543 sc_init_emulator(scp, "*");
2544 (*scp->tsw->te_default_attr)(scp,
2545 kernel_default.std_color,
2546 kernel_default.rev_color);
2548 /* assert(sc_malloc) */
2549 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2550 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2551 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2552 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2553 scp = alloc_scp(sc, sc->first_vty);
2554 sc->dev[0]->si_drv1 = scp;
2558 /* copy screen to temporary buffer */
2559 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2560 (void *)scp->sc->adp->va_window, FALSE);
2562 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2564 /* move cursors to the initial positions */
2565 if (col >= scp->xsize)
2567 if (row >= scp->ysize)
2568 row = scp->ysize - 1;
2571 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2572 if (bios_value.cursor_end < scp->font_size)
2573 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2575 sc->cursor_base = 0;
2576 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2577 sc->cursor_height = imin(i, scp->font_size);
2578 #ifndef SC_NO_SYSMOUSE
2579 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2581 if (!ISGRAPHSC(scp)) {
2582 sc_set_cursor_image(scp);
2583 sc_draw_cursor_image(scp);
2586 /* save font and palette */
2587 #ifndef SC_NO_FONT_LOADING
2588 sc->fonts_loaded = 0;
2589 if (ISFONTAVAIL(sc->adp->va_flags)) {
2591 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2592 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2593 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2594 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2595 if (scp->font_size < 14) {
2596 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2597 } else if (scp->font_size >= 16) {
2598 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2600 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2602 #else /* !SC_DFLT_FONT */
2603 if (scp->font_size < 14) {
2604 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2605 sc->fonts_loaded = FONT_8;
2606 } else if (scp->font_size >= 16) {
2607 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2608 sc->fonts_loaded = FONT_16;
2610 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2611 sc->fonts_loaded = FONT_14;
2613 #endif /* SC_DFLT_FONT */
2614 /* FONT KLUDGE: always use the font page #0. XXX */
2615 sc_show_font(scp, 0);
2617 #endif /* !SC_NO_FONT_LOADING */
2619 #ifndef SC_NO_PALETTE_LOADING
2620 save_palette(sc->adp, sc->palette);
2624 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2625 /* we are ready to put up the splash image! */
2626 splash_init(sc->adp, scsplash_callback, sc);
2627 sc->flags |= SC_SPLASH_SCRN;
2629 #endif /* NSPLASH */
2632 /* the rest is not necessary, if we have done it once */
2633 if (sc->flags & SC_INIT_DONE)
2636 /* initialize mapscrn arrays to a one to one map */
2637 for (i = 0; i < sizeof(sc->scr_map); i++)
2638 sc->scr_map[i] = sc->scr_rmap[i] = i;
2640 sc->flags |= SC_INIT_DONE;
2644 scterm(int unit, int flags)
2649 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2651 return; /* shouldn't happen */
2654 /* this console is no longer available for the splash screen */
2655 if (sc->flags & SC_SPLASH_SCRN) {
2656 splash_term(sc->adp);
2657 sc->flags &= ~SC_SPLASH_SCRN;
2659 #endif /* NSPLASH */
2662 /* move the hardware cursor to the upper-left corner */
2663 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2666 /* release the keyboard and the video card */
2667 if (sc->keyboard >= 0)
2668 kbd_release(sc->kbd, &sc->keyboard);
2669 if (sc->adapter >= 0)
2670 vid_release(sc->adp, &sc->adapter);
2673 * Stop the terminal emulator, if any. If operating on the
2674 * kernel console sc->dev may not be setup yet.
2676 if (flags & SC_KERNEL_CONSOLE)
2677 scp = sc->console_scp;
2679 scp = SC_STAT(sc->dev[0]);
2681 (*scp->tsw->te_term)(scp, &scp->ts);
2682 if (scp->ts != NULL)
2683 kfree(scp->ts, M_SYSCONS);
2685 /* clear the structure */
2686 if (!(flags & SC_KERNEL_CONSOLE)) {
2687 /* XXX: We need delete_dev() for this */
2688 kfree(sc->dev, M_SYSCONS);
2690 /* XXX: We need a ttyunregister for this */
2691 kfree(sc->tty, M_SYSCONS);
2693 #ifndef SC_NO_FONT_LOADING
2694 kfree(sc->font_8, M_SYSCONS);
2695 kfree(sc->font_14, M_SYSCONS);
2696 kfree(sc->font_16, M_SYSCONS);
2698 /* XXX vtb, history */
2700 bzero(sc, sizeof(*sc));
2706 scshutdown(void *arg, int howto)
2708 /* assert(sc_console != NULL) */
2710 sc_touch_scrn_saver();
2711 if (!cold && sc_console
2712 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2713 && sc_console->smode.mode == VT_AUTO)
2714 sc_switch_scr(sc_console->sc, sc_console->index);
2715 shutdown_in_progress = TRUE;
2719 sc_clean_up(scr_stat *scp)
2723 #endif /* NSPLASH */
2725 if (scp->sc->flags & SC_SCRN_BLANKED) {
2726 sc_touch_scrn_saver();
2728 if ((error = wait_scrn_saver_stop(scp->sc)))
2730 #endif /* NSPLASH */
2732 scp->status |= MOUSE_HIDDEN;
2733 sc_remove_mouse_image(scp);
2734 sc_remove_cutmarking(scp);
2739 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2745 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2746 if (!discard && (old.vtb_flags & VTB_VALID)) {
2747 /* retain the current cursor position and buffer contants */
2748 scp->cursor_oldpos = scp->cursor_pos;
2750 * This works only if the old buffer has the same size as or larger
2751 * than the new one. XXX
2753 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2757 sc_vtb_destroy(&old);
2760 #ifndef SC_NO_SYSMOUSE
2761 /* move the mouse cursor at the center of the screen */
2762 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2767 alloc_scp(sc_softc_t *sc, int vty)
2771 /* assert(sc_malloc) */
2773 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
2774 init_scp(sc, vty, scp);
2776 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2777 if (sc_init_emulator(scp, SC_DFLT_TERM))
2778 sc_init_emulator(scp, "*");
2780 #ifndef SC_NO_CUTPASTE
2781 sc_alloc_cut_buffer(scp, TRUE);
2784 #ifndef SC_NO_HISTORY
2785 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2792 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2796 bzero(scp, sizeof(*scp));
2801 scp->mode = sc->initial_mode;
2802 callout_init(&scp->blink_screen_ch);
2803 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2804 if (info.vi_flags & V_INFO_GRAPHICS) {
2805 scp->status |= GRAPHICS_MODE;
2806 scp->xpixel = info.vi_width;
2807 scp->ypixel = info.vi_height;
2808 scp->xsize = info.vi_width/8;
2809 scp->ysize = info.vi_height/info.vi_cheight;
2813 scp->xsize = info.vi_width;
2814 scp->ysize = info.vi_height;
2815 scp->xpixel = scp->xsize*8;
2816 scp->ypixel = scp->ysize*info.vi_cheight;
2817 if (info.vi_cheight < 14) {
2819 #ifndef SC_NO_FONT_LOADING
2820 scp->font = sc->font_8;
2824 } else if (info.vi_cheight >= 16) {
2825 scp->font_size = 16;
2826 #ifndef SC_NO_FONT_LOADING
2827 scp->font = sc->font_16;
2832 scp->font_size = 14;
2833 #ifndef SC_NO_FONT_LOADING
2834 scp->font = sc->font_14;
2840 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2841 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2842 scp->xoff = scp->yoff = 0;
2843 scp->xpos = scp->ypos = 0;
2844 scp->start = scp->xsize * scp->ysize - 1;
2849 scp->border = BG_BLACK;
2850 scp->cursor_base = sc->cursor_base;
2851 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2852 scp->mouse_cut_start = scp->xsize*scp->ysize;
2853 scp->mouse_cut_end = -1;
2854 scp->mouse_signal = 0;
2856 scp->mouse_proc = NULL;
2857 scp->kbd_mode = K_XLATE;
2858 scp->bell_pitch = bios_value.bell_pitch;
2859 scp->bell_duration = BELL_DURATION;
2860 scp->status |= (bios_value.shift_state & NLKED);
2861 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2864 scp->smode.mode = VT_AUTO;
2865 scp->history = NULL;
2866 scp->history_pos = 0;
2867 scp->history_size = 0;
2871 sc_init_emulator(scr_stat *scp, char *name)
2878 if (name == NULL) /* if no name is given, use the current emulator */
2880 else /* ...otherwise find the named emulator */
2881 sw = sc_term_match(name);
2886 if (strcmp(sw->te_renderer, "*") != 0) {
2887 rndr = sc_render_match(scp, sw->te_renderer,
2888 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2891 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2892 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2897 if (sw == scp->tsw) {
2898 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2900 scp->rndr->init(scp);
2901 sc_clear_screen(scp);
2902 /* assert(error == 0); */
2906 if (sc_malloc && (sw->te_size > 0))
2907 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
2910 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2915 (*scp->tsw->te_term)(scp, &scp->ts);
2916 if (scp->ts != NULL)
2917 kfree(scp->ts, M_SYSCONS);
2921 scp->rndr->init(scp);
2924 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2925 sc_clear_screen(scp);
2931 * scgetc(flags) - get character from keyboard.
2932 * If flags & SCGETC_CN, then avoid harmful side effects.
2933 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2934 * return NOKEY if there is nothing there.
2937 scgetc(sc_softc_t *sc, u_int flags)
2940 #ifndef SC_NO_HISTORY
2948 if (sc->kbd == NULL)
2953 /* I don't like this, but... XXX */
2954 if (flags & SCGETC_CN)
2955 sccnupdate(sc->cur_scp);
2958 /* first see if there is something in the keyboard port */
2960 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2962 if (!(flags & SCGETC_CN))
2963 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2964 } else if (c == NOKEY)
2970 /* make screensaver happy */
2972 sc_touch_scrn_saver();
2974 if (!(flags & SCGETC_CN))
2975 /* do the /dev/random device a favour */
2976 add_keyboard_randomness(c);
2978 if (scp->kbd_mode != K_XLATE)
2981 /* if scroll-lock pressed allow history browsing */
2982 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
2984 scp->status &= ~CURSOR_ENABLED;
2985 sc_remove_cursor_image(scp);
2987 #ifndef SC_NO_HISTORY
2988 if (!(scp->status & BUFFER_SAVED)) {
2989 scp->status |= BUFFER_SAVED;
2993 /* FIXME: key codes */
2994 case SPCLKEY | FKEY | F(49): /* home key */
2995 sc_remove_cutmarking(scp);
2999 case SPCLKEY | FKEY | F(57): /* end key */
3000 sc_remove_cutmarking(scp);
3004 case SPCLKEY | FKEY | F(50): /* up arrow key */
3005 sc_remove_cutmarking(scp);
3006 if (sc_hist_up_line(scp))
3007 if (!(flags & SCGETC_CN))
3008 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3011 case SPCLKEY | FKEY | F(58): /* down arrow key */
3012 sc_remove_cutmarking(scp);
3013 if (sc_hist_down_line(scp))
3014 if (!(flags & SCGETC_CN))
3015 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3018 case SPCLKEY | FKEY | F(51): /* page up key */
3019 sc_remove_cutmarking(scp);
3020 for (i=0; i<scp->ysize; i++)
3021 if (sc_hist_up_line(scp)) {
3022 if (!(flags & SCGETC_CN))
3023 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3028 case SPCLKEY | FKEY | F(59): /* page down key */
3029 sc_remove_cutmarking(scp);
3030 for (i=0; i<scp->ysize; i++)
3031 if (sc_hist_down_line(scp)) {
3032 if (!(flags & SCGETC_CN))
3033 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3038 #endif /* SC_NO_HISTORY */
3042 * Process and consume special keys here. Return a plain char code
3043 * or a char code with the META flag or a function key code.
3047 /* goto next_code */
3052 switch (KEYCHAR(c)) {
3054 case NLK: case CLK: case ALK:
3057 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3059 scp->status |= SLKED;
3061 if (scp->status & SLKED) {
3062 scp->status &= ~SLKED;
3063 #ifndef SC_NO_HISTORY
3064 if (scp->status & BUFFER_SAVED) {
3065 if (!sc_hist_restore(scp))
3066 sc_remove_cutmarking(scp);
3067 scp->status &= ~BUFFER_SAVED;
3068 scp->status |= CURSOR_ENABLED;
3069 sc_draw_cursor_image(scp);
3071 tp = VIRTUAL_TTY(sc, scp->index);
3079 /* NON-LOCKING KEYS */
3081 case LSH: case RSH: case LCTR: case RCTR:
3082 case LALT: case RALT: case ASH: case META:
3086 if (!(sc->flags & SC_SCRN_BLANKED))
3092 /* force activatation/deactivation of the screen saver */
3093 if (!(sc->flags & SC_SCRN_BLANKED)) {
3094 run_scrn_saver = TRUE;
3095 sc->scrn_time_stamp -= scrn_blank_time;
3099 * While devices are being probed, the screen saver need
3100 * to be invoked explictly. XXX
3102 if (sc->flags & SC_SCRN_BLANKED) {
3103 scsplash_stick(FALSE);
3104 stop_scrn_saver(sc, current_saver);
3106 if (!ISGRAPHSC(scp)) {
3107 scsplash_stick(TRUE);
3108 (*current_saver)(sc, TRUE);
3112 #endif /* NSPLASH */
3116 #ifndef SC_DISABLE_REBOOT
3122 #ifndef SC_DISABLE_REBOOT
3123 shutdown_nice(RB_HALT);
3128 #ifndef SC_DISABLE_REBOOT
3129 shutdown_nice(RB_HALT|RB_POWEROFF);
3135 apm_suspend(PMST_SUSPEND);
3138 apm_suspend(PMST_STANDBY);
3147 #ifndef SC_DISABLE_DDBKEY
3149 Debugger("manual escape to debugger");
3151 kprintf("No debugger in kernel\n");
3153 #else /* SC_DISABLE_DDBKEY */
3155 #endif /* SC_DISABLE_DDBKEY */
3159 if (enable_panic_key)
3160 panic("Forced by the panic key");
3164 this_scr = scp->index;
3165 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3166 sc->first_vty + i != this_scr;
3167 i = (i + 1)%sc->vtys) {
3168 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3169 if (ISTTYOPEN(tp)) {
3170 sc_switch_scr(scp->sc, sc->first_vty + i);
3177 this_scr = scp->index;
3178 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3179 sc->first_vty + i != this_scr;
3180 i = (i + sc->vtys - 1)%sc->vtys) {
3181 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3182 if (ISTTYOPEN(tp)) {
3183 sc_switch_scr(scp->sc, sc->first_vty + i);
3190 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3191 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3194 /* assert(c & FKEY) */
3195 if (!(sc->flags & SC_SCRN_BLANKED))
3199 /* goto next_code */
3201 /* regular keys (maybe MKEY is set) */
3202 if (!(sc->flags & SC_SCRN_BLANKED))
3211 scmmap(struct dev_mmap_args *ap)
3215 scp = SC_STAT(ap->a_head.a_dev);
3216 if (scp != scp->sc->cur_scp)
3218 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3224 save_kbd_state(scr_stat *scp)
3229 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3230 if (error == ENOIOCTL)
3233 scp->status &= ~LOCK_MASK;
3234 scp->status |= state;
3240 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3245 if (mask != LOCK_MASK) {
3246 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3247 if (error == ENOIOCTL)
3252 state |= new_bits & mask;
3254 state = new_bits & LOCK_MASK;
3256 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3257 if (error == ENOIOCTL)
3263 update_kbd_leds(scr_stat *scp, int which)
3268 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3269 if (error == ENOIOCTL)
3275 set_mode(scr_stat *scp)
3279 /* reject unsupported mode */
3280 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3283 /* if this vty is not currently showing, do nothing */
3284 if (scp != scp->sc->cur_scp)
3287 /* setup video hardware for the given mode */
3288 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3289 scp->rndr->init(scp);
3290 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3291 (void *)scp->sc->adp->va_window, FALSE);
3293 #ifndef SC_NO_FONT_LOADING
3294 /* load appropriate font */
3295 if (!(scp->status & GRAPHICS_MODE)) {
3296 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3297 if (scp->font_size < 14) {
3298 if (scp->sc->fonts_loaded & FONT_8)
3299 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3300 } else if (scp->font_size >= 16) {
3301 if (scp->sc->fonts_loaded & FONT_16)
3302 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3304 if (scp->sc->fonts_loaded & FONT_14)
3305 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3309 * This is an interim kludge to display correct font.
3310 * Always use the font page #0 on the video plane 2.
3311 * Somehow we cannot show the font in other font pages on
3312 * some video cards... XXX
3314 sc_show_font(scp, 0);
3318 #endif /* !SC_NO_FONT_LOADING */
3320 sc_set_border(scp, scp->border);
3321 sc_set_cursor_image(scp);
3327 refresh_ega_palette(scr_stat *scp)
3331 int rsize, gsize, bsize;
3332 int rfld, gfld, bfld;
3335 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3336 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3337 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3338 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3339 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3340 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3342 for (i = 0; i < 16; i++) {
3343 reg = scp->sc->adp->va_palette_regs[i];
3345 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3346 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3347 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3349 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3354 sc_set_border(scr_stat *scp, int color)
3356 ++scp->sc->videoio_in_progress;
3357 (*scp->rndr->draw_border)(scp, color);
3358 --scp->sc->videoio_in_progress;
3361 #ifndef SC_NO_FONT_LOADING
3363 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3364 int base, int count)
3369 sc->font_loading_in_progress = TRUE;
3370 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3371 sc->font_loading_in_progress = FALSE;
3375 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3376 int base, int count)
3381 sc->font_loading_in_progress = TRUE;
3382 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3383 sc->font_loading_in_progress = FALSE;
3387 sc_show_font(scr_stat *scp, int page)
3389 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3391 #endif /* !SC_NO_FONT_LOADING */
3394 sc_paste(scr_stat *scp, u_char *p, int count)
3399 if (scp->status & MOUSE_VISIBLE) {
3400 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3403 rmap = scp->sc->scr_rmap;
3404 for (; count > 0; --count)
3405 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3410 sc_bell(scr_stat *scp, int pitch, int duration)
3412 if (cold || shutdown_in_progress)
3415 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3418 if (scp->sc->flags & SC_VISUAL_BELL) {
3419 if (scp->sc->blink_in_progress)
3421 scp->sc->blink_in_progress = 3;
3422 if (scp != scp->sc->cur_scp)
3423 scp->sc->blink_in_progress += 2;
3424 blink_screen(scp->sc->cur_scp);
3425 } else if (duration != 0 && pitch != 0) {
3426 if (scp != scp->sc->cur_scp)
3428 sysbeep(pitch, duration);
3433 blink_screen(void *arg)
3435 scr_stat *scp = arg;
3438 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3439 scp->sc->blink_in_progress = 0;
3441 tp = VIRTUAL_TTY(scp->sc, scp->index);
3444 if (scp->sc->delayed_next_scr)
3445 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3448 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3449 scp->sc->blink_in_progress & 1);
3450 scp->sc->blink_in_progress--;
3451 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);