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.35 2008/08/10 19:47:31 swildner Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/eventhandler.h>
45 #include <sys/reboot.h>
49 #include <sys/signalvar.h>
50 #include <sys/sysctl.h>
52 #include <sys/kernel.h>
54 #include <sys/random.h>
55 #include <sys/thread2.h>
57 #include <machine/clock.h>
58 #include <machine/console.h>
59 #include <machine/psl.h>
60 #include <machine/pc/display.h>
62 #include <machine/apm_bios.h>
64 #include <machine/frame.h>
66 #include <dev/misc/kbd/kbdreg.h>
67 #include <dev/video/fb/fbreg.h>
68 #include <dev/video/fb/splashreg.h>
74 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
75 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
77 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
79 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
81 typedef struct default_attr {
82 int std_color; /* normal hardware color */
83 int rev_color; /* reverse hardware color */
86 static default_attr user_default = {
91 static default_attr kernel_default = {
93 SC_KERNEL_CONS_REV_ATTR,
96 static int sc_console_unit = -1;
97 static scr_stat *sc_console;
98 static struct tty *sc_console_tty;
99 static void *kernel_console_ts;
101 static char init_done = COLD;
102 static char shutdown_in_progress = FALSE;
103 static char sc_malloc = FALSE;
105 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
106 static int run_scrn_saver = FALSE; /* should run the saver? */
107 static long scrn_blank_time = 0; /* screen saver timeout value */
109 static int scrn_blanked; /* # of blanked screen */
110 static int sticky_splash = FALSE;
112 static void none_saver(sc_softc_t *sc, int blank) { }
113 static void (*current_saver)(sc_softc_t *, int) = none_saver;
116 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
120 static bios_values_t bios_value;
122 static int enable_panic_key;
123 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
126 #define SC_CONSOLECTL 255
128 #define VIRTUAL_TTY(sc, x) ((SC_DEV((sc),(x)) != NULL) ? \
129 (SC_DEV((sc),(x))->si_tty) : NULL)
130 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
133 static cdev_t cctl_dev;
136 static int scvidprobe(int unit, int flags, int cons);
137 static int sckbdprobe(int unit, int flags, int cons);
138 static void scmeminit(void *arg);
139 static int scdevtounit(cdev_t dev);
140 static kbd_callback_func_t sckbdevent;
141 static int scparam(struct tty *tp, struct termios *t);
142 static void scstart(struct tty *tp);
143 static void scinit(int unit, int flags);
144 static void scterm(int unit, int flags);
145 static void scshutdown(void *arg, int howto);
146 static u_int scgetc(sc_softc_t *sc, u_int flags);
148 #define SCGETC_NONBLOCK 2
149 static int sccngetch(int flags);
150 static void sccnupdate(scr_stat *scp);
151 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
152 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
153 static timeout_t scrn_timer;
154 static int and_region(int *s1, int *e1, int s2, int e2);
155 static void scrn_update(scr_stat *scp, int show_cursor);
158 static int scsplash_callback(int event, void *arg);
159 static void scsplash_saver(sc_softc_t *sc, int show);
160 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
161 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
162 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
163 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
164 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
165 static int wait_scrn_saver_stop(sc_softc_t *sc);
166 #define scsplash_stick(stick) (sticky_splash = (stick))
168 #define scsplash_stick(stick)
171 static void do_switch_scr(sc_softc_t *sc);
172 static int vt_proc_alive(scr_stat *scp);
173 static int signal_vt_rel(scr_stat *scp);
174 static int signal_vt_acq(scr_stat *scp);
175 static int finish_vt_rel(scr_stat *scp, int release);
176 static int finish_vt_acq(scr_stat *scp);
177 static void exchange_scr(sc_softc_t *sc);
178 static void update_cursor_image(scr_stat *scp);
179 static int save_kbd_state(scr_stat *scp);
180 static int update_kbd_state(scr_stat *scp, int state, int mask);
181 static int update_kbd_leds(scr_stat *scp, int which);
182 static timeout_t blink_screen;
184 #define CDEV_MAJOR 12
186 static cn_probe_t sccnprobe;
187 static cn_init_t sccninit;
188 static cn_init_t sccninit_fini;
189 static cn_getc_t sccngetc;
190 static cn_checkc_t sccncheckc;
191 static cn_putc_t sccnputc;
192 static cn_dbctl_t sccndbctl;
193 static cn_term_t sccnterm;
195 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
196 sccngetc, sccncheckc, sccnputc, sccndbctl);
198 static d_open_t scopen;
199 static d_close_t scclose;
200 static d_read_t scread;
201 static d_ioctl_t scioctl;
202 static d_mmap_t scmmap;
204 static struct dev_ops sc_ops = {
205 { "sc", CDEV_MAJOR, D_TTY | D_KQFILTER },
213 .d_kqfilter = ttykqfilter,
214 .d_revoke = ttyrevoke
218 sc_probe_unit(int unit, int flags)
220 if (!scvidprobe(unit, flags, FALSE)) {
222 kprintf("sc%d: no video adapter found.\n", unit);
226 /* syscons will be attached even when there is no keyboard */
227 sckbdprobe(unit, flags, FALSE);
232 /* probe video adapters, return TRUE if found */
234 scvidprobe(int unit, int flags, int cons)
237 * Access the video adapter driver through the back door!
238 * Video adapter drivers need to be configured before syscons.
239 * However, when syscons is being probed as the low-level console,
240 * they have not been initialized yet. We force them to initialize
241 * themselves here. XXX
243 vid_configure(cons ? VIO_PROBE_ONLY : 0);
245 return (vid_find_adapter("*", unit) >= 0);
248 /* probe the keyboard, return TRUE if found */
250 sckbdprobe(int unit, int flags, int cons)
252 /* access the keyboard driver through the backdoor! */
253 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
255 return (kbd_find_keyboard("*", unit) >= 0);
259 adapter_name(video_adapter_t *adp)
265 { KD_MONO, { "MDA", "MDA" } },
266 { KD_HERCULES, { "Hercules", "Hercules" } },
267 { KD_CGA, { "CGA", "CGA" } },
268 { KD_EGA, { "EGA", "EGA (mono)" } },
269 { KD_VGA, { "VGA", "VGA (mono)" } },
270 { KD_TGA, { "TGA", "TGA" } },
271 { -1, { "Unknown", "Unknown" } },
275 for (i = 0; names[i].type != -1; ++i)
276 if (names[i].type == adp->va_type)
278 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
282 sc_attach_unit(int unit, int flags)
292 flags &= ~SC_KERNEL_CONSOLE;
294 if (sc_console_unit == unit) {
296 * If this unit is being used as the system console, we need to
297 * adjust some variables and buffers before and after scinit().
299 /* assert(sc_console != NULL) */
300 flags |= SC_KERNEL_CONSOLE;
305 if (sc_console->tsw->te_size > 0) {
306 /* assert(sc_console->ts != NULL); */
307 kernel_console_ts = sc_console->ts;
308 sc_console->ts = kmalloc(sc_console->tsw->te_size,
309 M_SYSCONS, M_WAITOK);
310 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
311 (*sc_console->tsw->te_default_attr)(sc_console,
312 user_default.std_color,
313 user_default.rev_color);
319 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
322 * If this is the console we couldn't setup sc->dev before because
323 * malloc wasn't working. Set it up now.
325 if (flags & SC_KERNEL_CONSOLE) {
326 KKASSERT(sc->dev == NULL);
327 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
328 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
330 "ttyv%r", sc_console_unit*MAXCONS);
331 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
332 sc->dev[0]->si_drv1 = sc_console;
336 * Finish up the standard attach
339 callout_init(&sc->scrn_timer_ch);
340 scp = SC_STAT(sc->dev[0]);
341 if (sc_console == NULL) /* sc_console_unit < 0 */
345 if ((sc->config & SC_VESA800X600)
346 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
348 if (sc->flags & SC_SPLASH_SCRN)
349 splash_term(sc->adp);
351 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
352 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
353 sc->initial_mode = M_VESA_800x600;
355 /* put up the splash again! */
356 if (sc->flags & SC_SPLASH_SCRN)
357 splash_init(sc->adp, scsplash_callback, sc);
360 #endif /* SC_PIXEL_MODE */
362 /* initialize cursor */
364 update_cursor_image(scp);
366 /* get screen update going */
369 /* set up the keyboard */
370 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
371 update_kbd_state(scp, scp->status, LOCK_MASK);
373 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
374 unit, adapter_name(sc->adp), sc->vtys, sc->config);
376 kprintf("sc%d:", unit);
377 if (sc->adapter >= 0)
378 kprintf(" fb%d", sc->adapter);
379 if (sc->keyboard >= 0)
380 kprintf(", kbd%d", sc->keyboard);
382 kprintf(", terminal emulator: %s (%s)",
383 scp->tsw->te_name, scp->tsw->te_desc);
387 /* register a shutdown callback for the kernel console */
388 if (sc_console_unit == unit)
389 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
390 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
395 * The first vty already has struct tty and scr_stat initialized
396 * in scinit(). The other vtys will have these structs when
399 for (vc = 1; vc < sc->vtys; vc++) {
400 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
402 0600, "ttyv%r", vc + unit * MAXCONS);
405 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
406 UID_ROOT, GID_WHEEL, 0600, "consolectl");
407 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
408 cctl_dev->si_drv1 = sc_console;
420 * As soon as malloc() becomes functional, we had better allocate
421 * various buffers for the kernel console.
424 if (sc_console_unit < 0) /* sc_console == NULL */
427 /* copy the temporary buffer to the final buffer */
428 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
430 #ifndef SC_NO_CUTPASTE
431 sc_alloc_cut_buffer(sc_console, TRUE);
434 #ifndef SC_NO_HISTORY
435 /* initialize history buffer & pointers */
436 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
440 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
443 scdevtounit(cdev_t dev)
445 int vty = SC_VTY(dev);
447 if (vty == SC_CONSOLECTL)
448 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
449 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
456 scopen(struct dev_open_args *ap)
458 cdev_t dev = ap->a_head.a_dev;
459 int unit = scdevtounit(dev);
466 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
467 major(dev), minor(dev), unit, SC_VTY(dev)));
469 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
473 tp = dev->si_tty = ttymalloc(dev->si_tty);
474 tp->t_oproc = scstart;
475 tp->t_param = scparam;
476 tp->t_stop = nottystop;
480 if (!ISTTYOPEN(tp)) {
482 /* Use the current setting of the <-- key as default VERASE. */
483 /* If the Delete key is preferable, an stty is necessary */
484 if (sc->kbd != NULL) {
485 key.keynum = KEYCODE_BS;
486 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
487 tp->t_cc[VERASE] = key.key.map[0];
489 tp->t_iflag = TTYDEF_IFLAG;
490 tp->t_oflag = TTYDEF_OFLAG;
491 tp->t_cflag = TTYDEF_CFLAG;
492 tp->t_lflag = TTYDEF_LFLAG;
493 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
494 scparam(tp, &tp->t_termios);
495 (*linesw[tp->t_line].l_modem)(tp, 1);
498 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0))
501 error = (*linesw[tp->t_line].l_open)(dev, tp);
505 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
507 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
509 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
510 tp->t_winsize.ws_col = scp->xsize;
511 tp->t_winsize.ws_row = scp->ysize;
518 scclose(struct dev_close_args *ap)
520 cdev_t dev = ap->a_head.a_dev;
521 struct tty *tp = dev->si_tty;
525 if (SC_VTY(dev) != SC_CONSOLECTL) {
526 scp = SC_STAT(tp->t_dev);
527 /* were we in the middle of the VT switching process? */
528 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
529 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
530 cons_unavail = FALSE;
532 * note: must be called from a critical section because finish_vt_rel
533 * will call do_switch_scr which releases it temporarily
535 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
536 DPRINTF(5, ("reset WAIT_REL, "));
537 if (finish_vt_acq(scp) == 0) /* force acknowledge */
538 DPRINTF(5, ("reset WAIT_ACQ, "));
540 if (scp == &main_console) {
543 scp->smode.mode = VT_AUTO;
546 sc_vtb_destroy(&scp->vtb);
547 sc_vtb_destroy(&scp->scr);
548 sc_free_history_buffer(scp, scp->ysize);
550 kfree(scp, M_SYSCONS);
555 scp->smode.mode = VT_AUTO;
557 scp->kbd_mode = K_XLATE;
558 if (scp == scp->sc->cur_scp)
559 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
560 DPRINTF(5, ("done.\n"));
562 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
570 scread(struct dev_read_args *ap)
572 sc_touch_scrn_saver();
573 return (ttyread(ap));
577 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
586 * WARNING: In early boot sc->dev may not be setup yet.
588 sc = (sc_softc_t *)arg;
589 /* assert(thiskbd == sc->kbd) */
594 case KBDIO_UNLOADING:
597 kbd_release(thiskbd, (void *)&sc->keyboard);
604 * Loop while there is still input to get from the keyboard.
605 * I don't think this is nessesary, and it doesn't fix
606 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
608 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
609 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
610 if (!ISTTYOPEN(cur_tty)) {
611 cur_tty = sc_console_tty;
612 if (!ISTTYOPEN(cur_tty))
616 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
619 switch (KEYFLAGS(c)) {
620 case 0x0000: /* normal key */
621 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
623 case FKEY: /* function key, return string */
624 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
627 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
630 case MKEY: /* meta is active, prepend ESC */
631 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
632 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
634 case BKEY: /* backtab fixed sequence (esc [ Z) */
635 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
636 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
637 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
642 sc->cur_scp->status |= MOUSE_HIDDEN;
648 scparam(struct tty *tp, struct termios *t)
650 tp->t_ispeed = t->c_ispeed;
651 tp->t_ospeed = t->c_ospeed;
652 tp->t_cflag = t->c_cflag;
657 scioctl(struct dev_ioctl_args *ap)
659 cdev_t dev = ap->a_head.a_dev;
660 u_long cmd = ap->a_cmd;
661 caddr_t data = ap->a_data;
662 int flag = ap->a_fflag;
671 error = sc_vid_ioctl(tp, cmd, data, flag);
672 if (error != ENOIOCTL)
675 #ifndef SC_NO_HISTORY
676 error = sc_hist_ioctl(tp, cmd, data, flag);
677 if (error != ENOIOCTL)
681 #ifndef SC_NO_SYSMOUSE
682 error = sc_mouse_ioctl(tp, cmd, data, flag);
683 if (error != ENOIOCTL)
687 scp = SC_STAT(tp->t_dev);
688 /* assert(scp != NULL) */
689 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
693 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
694 if (error != ENOIOCTL)
698 switch (cmd) { /* process console hardware related ioctl's */
700 case GIO_ATTR: /* get current attributes */
701 /* this ioctl is not processed here, but in the terminal emulator */
704 case GIO_COLOR: /* is this a color console ? */
705 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
708 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
709 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
712 scrn_blank_time = *(int *)data;
713 run_scrn_saver = (scrn_blank_time != 0);
717 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
719 if (!ISGRAPHSC(sc->cur_scp))
720 sc_remove_cursor_image(sc->cur_scp);
721 if ((*(int*)data) & 0x01)
722 sc->flags |= SC_BLINK_CURSOR;
724 sc->flags &= ~SC_BLINK_CURSOR;
725 if ((*(int*)data) & 0x02) {
726 sc->flags |= SC_CHAR_CURSOR;
728 sc->flags &= ~SC_CHAR_CURSOR;
730 * The cursor shape is global property; all virtual consoles
731 * are affected. Update the cursor in the current console...
733 if (!ISGRAPHSC(sc->cur_scp)) {
734 sc_set_cursor_image(sc->cur_scp);
735 sc_draw_cursor_image(sc->cur_scp);
740 case CONS_BELLTYPE: /* set bell type sound/visual */
741 if ((*(int *)data) & 0x01)
742 sc->flags |= SC_VISUAL_BELL;
744 sc->flags &= ~SC_VISUAL_BELL;
745 if ((*(int *)data) & 0x02)
746 sc->flags |= SC_QUIET_BELL;
748 sc->flags &= ~SC_QUIET_BELL;
751 case CONS_GETINFO: /* get current (virtual) console info */
753 vid_info_t *ptr = (vid_info_t*)data;
754 if (ptr->size == sizeof(struct vid_info)) {
755 ptr->m_num = sc->cur_scp->index;
756 ptr->font_size = scp->font_size;
757 ptr->mv_col = scp->xpos;
758 ptr->mv_row = scp->ypos;
759 ptr->mv_csz = scp->xsize;
760 ptr->mv_rsz = scp->ysize;
762 * The following fields are filled by the terminal emulator. XXX
769 ptr->mv_grfc.fore = 0; /* not supported */
770 ptr->mv_grfc.back = 0; /* not supported */
771 ptr->mv_ovscan = scp->border;
772 if (scp == sc->cur_scp)
774 ptr->mk_keylock = scp->status & LOCK_MASK;
780 case CONS_GETVERS: /* get version number */
781 *(int*)data = 0x200; /* version 2.0 */
784 case CONS_IDLE: /* see if the screen has been idle */
786 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
787 * the user process may have been writing something on the
788 * screen and syscons is not aware of it. Declare the screen
789 * is NOT idle if it is in one of these modes. But there is
790 * an exception to it; if a screen saver is running in the
791 * graphics mode in the current screen, we should say that the
792 * screen has been idle.
794 *(int *)data = (sc->flags & SC_SCRN_IDLE)
795 && (!ISGRAPHSC(sc->cur_scp)
796 || (sc->cur_scp->status & SAVER_RUNNING));
799 case CONS_SAVERMODE: /* set saver mode */
800 switch(*(int *)data) {
803 /* if a LKM screen saver is running, stop it first. */
804 scsplash_stick(FALSE);
805 saver_mode = *(int *)data;
808 if ((error = wait_scrn_saver_stop(NULL))) {
813 run_scrn_saver = TRUE;
814 if (saver_mode == CONS_USR_SAVER)
815 scp->status |= SAVER_RUNNING;
817 scp->status &= ~SAVER_RUNNING;
818 scsplash_stick(TRUE);
823 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
824 scp->status &= ~SAVER_RUNNING;
825 saver_mode = *(int *)data;
833 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
835 * Note that this ioctl does not guarantee the screen saver
836 * actually starts or stops. It merely attempts to do so...
839 run_scrn_saver = (*(int *)data != 0);
841 sc->scrn_time_stamp -= scrn_blank_time;
845 case CONS_SCRSHOT: /* get a screen shot */
847 scrshot_t *ptr = (scrshot_t*)data;
849 if (ISGRAPHSC(scp)) {
853 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
857 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
858 ptr->xsize * ptr->ysize * sizeof(uint16_t));
863 case VT_SETMODE: /* set screen switcher mode */
865 struct vt_mode *mode;
867 mode = (struct vt_mode *)data;
868 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
869 if (scp->smode.mode == VT_PROCESS) {
870 if (scp->proc == pfind(scp->pid) && scp->proc != curproc) {
871 DPRINTF(5, ("error EPERM\n"));
876 if (mode->mode == VT_AUTO) {
877 scp->smode.mode = VT_AUTO;
880 DPRINTF(5, ("VT_AUTO, "));
881 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
882 cons_unavail = FALSE;
884 * note: must be called from a critical section because
885 * finish_vt_rel will call do_switch_scr which releases it
888 if (finish_vt_rel(scp, TRUE) == 0)
889 DPRINTF(5, ("reset WAIT_REL, "));
890 if (finish_vt_acq(scp) == 0)
891 DPRINTF(5, ("reset WAIT_ACQ, "));
893 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
894 || !ISSIGVALID(mode->frsig)) {
896 DPRINTF(5, ("error EINVAL\n"));
899 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
900 bcopy(data, &scp->smode, sizeof(struct vt_mode));
902 scp->pid = scp->proc->p_pid;
903 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
911 case VT_GETMODE: /* get screen switcher mode */
912 bcopy(&scp->smode, data, sizeof(struct vt_mode));
915 case VT_RELDISP: /* screen switcher ioctl */
918 * This must be the current vty which is in the VT_PROCESS
921 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
925 /* ...and this process is controlling it. */
926 if (scp->proc != curproc) {
931 switch(*(int *)data) {
932 case VT_FALSE: /* user refuses to release screen, abort */
934 * note: must be called from a critical section because
935 * finish_vt_rel will call do_switch_scr which releases it
938 if ((error = finish_vt_rel(scp, FALSE)) == 0)
939 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
941 case VT_TRUE: /* user has released screen, go on */
943 * note: must be called from a critical section because
944 * finish_vt_rel will call do_switch_scr which releases it
947 if ((error = finish_vt_rel(scp, TRUE)) == 0)
948 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
950 case VT_ACKACQ: /* acquire acknowledged, switch completed */
951 if ((error = finish_vt_acq(scp)) == 0)
952 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
960 case VT_OPENQRY: /* return free virtual console */
961 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
962 tp = VIRTUAL_TTY(sc, i);
963 if (!ISTTYOPEN(tp)) {
964 *(int *)data = i + 1;
970 case VT_ACTIVATE: /* switch to screen *data */
971 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
973 sc_clean_up(sc->cur_scp);
975 return sc_switch_scr(sc, i);
977 case VT_WAITACTIVE: /* wait for switch to occur */
978 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
979 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
982 error = sc_clean_up(sc->cur_scp);
986 scp = SC_STAT(SC_DEV(sc, i));
987 if (scp == scp->sc->cur_scp)
989 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
990 /* May return ERESTART */
993 case VT_GETACTIVE: /* get active vty # */
994 *(int *)data = sc->cur_scp->index + 1;
997 case VT_GETINDEX: /* get this vty # */
998 *(int *)data = scp->index + 1;
1001 case VT_LOCKSWITCH: /* prevent vty switching */
1002 if ((*(int *)data) & 0x01)
1003 sc->flags |= SC_SCRN_VTYLOCK;
1005 sc->flags &= ~SC_SCRN_VTYLOCK;
1008 case KDENABIO: /* allow io operations */
1009 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1012 if (securelevel > 0)
1014 #if defined(__i386__)
1015 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1016 #elif defined(__amd64__)
1017 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1021 case KDDISABIO: /* disallow io operations (default) */
1022 #if defined(__i386__)
1023 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1024 #elif defined(__amd64__)
1025 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1029 case KDSKBSTATE: /* set keyboard state (locks) */
1030 if (*(int *)data & ~LOCK_MASK)
1032 scp->status &= ~LOCK_MASK;
1033 scp->status |= *(int *)data;
1034 if (scp == sc->cur_scp)
1035 update_kbd_state(scp, scp->status, LOCK_MASK);
1038 case KDGKBSTATE: /* get keyboard state (locks) */
1039 if (scp == sc->cur_scp)
1040 save_kbd_state(scp);
1041 *(int *)data = scp->status & LOCK_MASK;
1044 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1045 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1046 error = kbd_ioctl(sc->kbd, cmd, data);
1047 if (error == ENOIOCTL)
1051 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1052 if (*(int *)data & ~0x7f)
1054 error = kbd_ioctl(sc->kbd, cmd, data);
1055 if (error == ENOIOCTL)
1059 case KDSKBMODE: /* set keyboard mode */
1060 switch (*(int *)data) {
1061 case K_XLATE: /* switch to XLT ascii mode */
1062 case K_RAW: /* switch to RAW scancode mode */
1063 case K_CODE: /* switch to CODE mode */
1064 scp->kbd_mode = *(int *)data;
1065 if (scp == sc->cur_scp)
1066 kbd_ioctl(sc->kbd, cmd, data);
1073 case KDGKBMODE: /* get keyboard mode */
1074 *(int *)data = scp->kbd_mode;
1078 error = kbd_ioctl(sc->kbd, cmd, data);
1079 if (error == ENOIOCTL)
1083 case KDMKTONE: /* sound the bell */
1085 sc_bell(scp, (*(int*)data)&0xffff,
1086 (((*(int*)data)>>16)&0xffff)*hz/1000);
1088 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1091 case KIOCSOUND: /* make tone (*data) hz */
1092 if (scp == sc->cur_scp) {
1094 return sc_tone(*(int *)data);
1100 case KDGKBTYPE: /* get keyboard type */
1101 error = kbd_ioctl(sc->kbd, cmd, data);
1102 if (error == ENOIOCTL) {
1103 /* always return something? XXX */
1108 case KDSETLED: /* set keyboard LED status */
1109 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1111 scp->status &= ~LED_MASK;
1112 scp->status |= *(int *)data;
1113 if (scp == sc->cur_scp)
1114 update_kbd_leds(scp, scp->status);
1117 case KDGETLED: /* get keyboard LED status */
1118 if (scp == sc->cur_scp)
1119 save_kbd_state(scp);
1120 *(int *)data = scp->status & LED_MASK;
1123 case CONS_SETKBD: /* set the new keyboard */
1128 newkbd = kbd_get_keyboard(*(int *)data);
1129 if (newkbd == NULL) {
1134 if (sc->kbd != newkbd) {
1135 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1136 (void *)&sc->keyboard, sckbdevent, sc);
1137 /* i == newkbd->kb_index */
1139 if (sc->kbd != NULL) {
1140 save_kbd_state(sc->cur_scp);
1141 kbd_release(sc->kbd, (void *)&sc->keyboard);
1143 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1145 kbd_ioctl(sc->kbd, KDSKBMODE,
1146 (caddr_t)&sc->cur_scp->kbd_mode);
1147 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1150 error = EPERM; /* XXX */
1157 case CONS_RELKBD: /* release the current keyboard */
1160 if (sc->kbd != NULL) {
1161 save_kbd_state(sc->cur_scp);
1162 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1171 case CONS_GETTERM: /* get the current terminal emulator info */
1175 if (((term_info_t *)data)->ti_index == 0) {
1178 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1181 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1182 sizeof(((term_info_t *)data)->ti_name));
1183 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1184 sizeof(((term_info_t *)data)->ti_desc));
1185 ((term_info_t *)data)->ti_flags = 0;
1188 ((term_info_t *)data)->ti_name[0] = '\0';
1189 ((term_info_t *)data)->ti_desc[0] = '\0';
1190 ((term_info_t *)data)->ti_flags = 0;
1195 case CONS_SETTERM: /* set the current terminal emulator */
1197 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1198 /* FIXME: what if scp == sc_console! XXX */
1202 case GIO_SCRNMAP: /* get output translation table */
1203 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1206 case PIO_SCRNMAP: /* set output translation table */
1207 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1208 for (i=0; i<sizeof(sc->scr_map); i++) {
1209 sc->scr_rmap[sc->scr_map[i]] = i;
1213 case GIO_KEYMAP: /* get keyboard translation table */
1214 case PIO_KEYMAP: /* set keyboard translation table */
1215 case GIO_DEADKEYMAP: /* get accent key translation table */
1216 case PIO_DEADKEYMAP: /* set accent key translation table */
1217 case GETFKEY: /* get function key string */
1218 case SETFKEY: /* set function key string */
1219 error = kbd_ioctl(sc->kbd, cmd, data);
1220 if (error == ENOIOCTL)
1224 #ifndef SC_NO_FONT_LOADING
1226 case PIO_FONT8x8: /* set 8x8 dot font */
1227 if (!ISFONTAVAIL(sc->adp->va_flags))
1229 bcopy(data, sc->font_8, 8*256);
1230 sc->fonts_loaded |= FONT_8;
1233 * Always use the font page #0. XXX
1234 * Don't load if the current font size is not 8x8.
1236 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1237 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1240 case GIO_FONT8x8: /* get 8x8 dot font */
1241 if (!ISFONTAVAIL(sc->adp->va_flags))
1243 if (sc->fonts_loaded & FONT_8) {
1244 bcopy(sc->font_8, data, 8*256);
1250 case PIO_FONT8x14: /* set 8x14 dot font */
1251 if (!ISFONTAVAIL(sc->adp->va_flags))
1253 bcopy(data, sc->font_14, 14*256);
1254 sc->fonts_loaded |= FONT_14;
1257 * Always use the font page #0. XXX
1258 * Don't load if the current font size is not 8x14.
1260 if (ISTEXTSC(sc->cur_scp)
1261 && (sc->cur_scp->font_size >= 14)
1262 && (sc->cur_scp->font_size < 16))
1263 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1266 case GIO_FONT8x14: /* get 8x14 dot font */
1267 if (!ISFONTAVAIL(sc->adp->va_flags))
1269 if (sc->fonts_loaded & FONT_14) {
1270 bcopy(sc->font_14, data, 14*256);
1276 case PIO_FONT8x16: /* set 8x16 dot font */
1277 if (!ISFONTAVAIL(sc->adp->va_flags))
1279 bcopy(data, sc->font_16, 16*256);
1280 sc->fonts_loaded |= FONT_16;
1283 * Always use the font page #0. XXX
1284 * Don't load if the current font size is not 8x16.
1286 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1287 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1290 case GIO_FONT8x16: /* get 8x16 dot font */
1291 if (!ISFONTAVAIL(sc->adp->va_flags))
1293 if (sc->fonts_loaded & FONT_16) {
1294 bcopy(sc->font_16, data, 16*256);
1300 #endif /* SC_NO_FONT_LOADING */
1306 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1307 if (error != ENOIOCTL)
1309 error = ttioctl(tp, cmd, data, flag);
1310 if (error != ENOIOCTL)
1316 scstart(struct tty *tp)
1320 u_char buf[PCBURST];
1321 scr_stat *scp = SC_STAT(tp->t_dev);
1323 if (scp->status & SLKED ||
1324 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1327 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1328 tp->t_state |= TS_BUSY;
1331 len = q_to_b(rbp, buf, PCBURST);
1333 sc_puts(scp, buf, len);
1336 tp->t_state &= ~TS_BUSY;
1343 sccnprobe(struct consdev *cp)
1348 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1350 /* a video card is always required */
1351 if (!scvidprobe(unit, flags, TRUE))
1352 cp->cn_pri = CN_DEAD;
1354 /* syscons will become console even when there is no keyboard */
1355 sckbdprobe(unit, flags, TRUE);
1357 if (cp->cn_pri == CN_DEAD)
1360 /* initialize required fields */
1361 cp->cn_probegood = 1;
1365 sccninit(struct consdev *cp)
1370 sc_get_cons_priority(&unit, &flags);
1371 scinit(unit, flags | SC_KERNEL_CONSOLE);
1372 sc_console_unit = unit;
1373 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1377 sccninit_fini(struct consdev *cp)
1379 if (cctl_dev == NULL)
1380 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1381 cp->cn_dev = cctl_dev;
1385 sccnterm(struct consdev *cp)
1387 /* we are not the kernel console any more, release everything */
1389 if (sc_console_unit < 0)
1390 return; /* shouldn't happen */
1393 sc_clear_screen(sc_console);
1394 sccnupdate(sc_console);
1396 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1397 sc_console_unit = -1;
1402 sccnputc(void *private, int c)
1405 scr_stat *scp = sc_console;
1407 #ifndef SC_NO_HISTORY
1409 #endif /* !SC_NO_HISTORY */
1411 /* assert(sc_console != NULL) */
1413 #ifndef SC_NO_HISTORY
1414 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1415 scp->status &= ~SLKED;
1416 update_kbd_state(scp, scp->status, SLKED);
1417 if (scp->status & BUFFER_SAVED) {
1418 if (!sc_hist_restore(scp))
1419 sc_remove_cutmarking(scp);
1420 scp->status &= ~BUFFER_SAVED;
1421 scp->status |= CURSOR_ENABLED;
1422 sc_draw_cursor_image(scp);
1424 tp = VIRTUAL_TTY(scp->sc, scp->index);
1428 #endif /* !SC_NO_HISTORY */
1431 if (kernel_console_ts != NULL)
1432 scp->ts = kernel_console_ts;
1434 sc_puts(scp, buf, 1);
1443 sccngetc(void *private)
1445 return sccngetch(0);
1449 sccncheckc(void *private)
1451 return sccngetch(SCGETC_NONBLOCK);
1455 sccndbctl(void *private, int on)
1457 /* assert(sc_console_unit >= 0) */
1458 /* try to switch to the kernel console screen */
1459 if (on && debugger == 0) {
1461 * TRY to make sure the screen saver is stopped,
1462 * and the screen is updated before switching to
1467 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1468 && sc_console->smode.mode == VT_AUTO) {
1469 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1470 sc_switch_scr(sc_console->sc, sc_console->index);
1480 sccngetch(int flags)
1482 static struct fkeytab fkey;
1490 /* assert(sc_console != NULL) */
1493 * Stop the screen saver and update the screen if necessary.
1494 * What if we have been running in the screen saver code... XXX
1496 sc_touch_scrn_saver();
1497 scp = sc_console->sc->cur_scp; /* XXX */
1500 if (fkeycp < fkey.len) {
1502 return fkey.str[fkeycp++];
1505 if (scp->sc->kbd == NULL) {
1511 * Make sure the keyboard is accessible even when the kbd device
1512 * driver is disabled.
1514 kbd_enable(scp->sc->kbd);
1516 /* we shall always use the keyboard in the XLATE mode here */
1517 cur_mode = scp->kbd_mode;
1518 scp->kbd_mode = K_XLATE;
1519 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1521 kbd_poll(scp->sc->kbd, TRUE);
1522 c = scgetc(scp->sc, SCGETC_CN | flags);
1523 kbd_poll(scp->sc->kbd, FALSE);
1525 scp->kbd_mode = cur_mode;
1526 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1527 kbd_disable(scp->sc->kbd);
1530 switch (KEYFLAGS(c)) {
1531 case 0: /* normal char */
1533 case FKEY: /* function key */
1534 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1536 if ((p != NULL) && (fkey.len > 0)) {
1537 bcopy(p, fkey.str, fkey.len);
1551 sccnupdate(scr_stat *scp)
1553 /* this is a cut-down version of scrn_timer()... */
1555 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1558 if (debugger > 0 || panicstr || shutdown_in_progress) {
1559 sc_touch_scrn_saver();
1560 } else if (scp != scp->sc->cur_scp) {
1564 if (!run_scrn_saver)
1565 scp->sc->flags &= ~SC_SCRN_IDLE;
1567 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1568 if (scp->sc->flags & SC_SCRN_BLANKED)
1569 stop_scrn_saver(scp->sc, current_saver);
1570 #endif /* NSPLASH */
1572 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1573 || scp->sc->switch_in_progress)
1576 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1577 * when write_in_progress is non-zero. XXX
1580 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1581 scrn_update(scp, TRUE);
1585 scrn_timer(void *arg)
1587 static int kbd_interval = 0;
1593 again = (arg != NULL);
1595 sc = (sc_softc_t *)arg;
1596 else if (sc_console != NULL)
1597 sc = sc_console->sc;
1601 /* don't do anything when we are performing some I/O operations */
1602 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1604 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1609 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1610 /* try to allocate a keyboard automatically */
1611 if (++kbd_interval >= 25) {
1612 sc->keyboard = kbd_allocate("*", -1, (void *)&sc->keyboard,
1614 if (sc->keyboard >= 0) {
1615 sc->kbd = kbd_get_keyboard(sc->keyboard);
1616 kbd_ioctl(sc->kbd, KDSKBMODE,
1617 (caddr_t)&sc->cur_scp->kbd_mode);
1618 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1625 /* should we stop the screen saver? */
1626 getmicrouptime(&tv);
1627 if (debugger > 0 || panicstr || shutdown_in_progress)
1628 sc_touch_scrn_saver();
1629 if (run_scrn_saver) {
1630 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1631 sc->flags |= SC_SCRN_IDLE;
1633 sc->flags &= ~SC_SCRN_IDLE;
1635 sc->scrn_time_stamp = tv.tv_sec;
1636 sc->flags &= ~SC_SCRN_IDLE;
1637 if (scrn_blank_time > 0)
1638 run_scrn_saver = TRUE;
1641 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1642 if (sc->flags & SC_SCRN_BLANKED)
1643 stop_scrn_saver(sc, current_saver);
1644 #endif /* NSPLASH */
1646 /* should we just return ? */
1647 if (sc->blink_in_progress || sc->switch_in_progress
1648 || sc->write_in_progress) {
1650 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1655 /* Update the screen */
1656 scp = sc->cur_scp; /* cur_scp may have changed... */
1657 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1658 scrn_update(scp, TRUE);
1661 /* should we activate the screen saver? */
1662 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1663 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1664 (*current_saver)(sc, TRUE);
1665 #endif /* NSPLASH */
1668 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1673 and_region(int *s1, int *e1, int s2, int e2)
1675 if (*e1 < s2 || e2 < *s1)
1677 *s1 = imax(*s1, s2);
1678 *e1 = imin(*e1, e2);
1683 scrn_update(scr_stat *scp, int show_cursor)
1690 /* assert(scp == scp->sc->cur_scp) */
1692 ++scp->sc->videoio_in_progress;
1694 #ifndef SC_NO_CUTPASTE
1695 /* remove the previous mouse pointer image if necessary */
1696 if (scp->status & MOUSE_VISIBLE) {
1698 e = scp->mouse_pos + scp->xsize + 1;
1699 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1700 || and_region(&s, &e, scp->start, scp->end)
1701 || ((scp->status & CURSOR_ENABLED) &&
1702 (scp->cursor_pos != scp->cursor_oldpos) &&
1703 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1704 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1705 sc_remove_mouse_image(scp);
1706 if (scp->end >= scp->xsize*scp->ysize)
1707 scp->end = scp->xsize*scp->ysize - 1;
1710 #endif /* !SC_NO_CUTPASTE */
1714 if (scp->end >= scp->xsize*scp->ysize) {
1715 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1716 scp->end = scp->xsize*scp->ysize - 1;
1718 if (scp->start < 0) {
1719 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
1724 /* update screen image */
1725 if (scp->start <= scp->end) {
1726 if (scp->mouse_cut_end >= 0) {
1727 /* there is a marked region for cut & paste */
1728 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1729 start = scp->mouse_cut_start;
1730 end = scp->mouse_cut_end;
1732 start = scp->mouse_cut_end;
1733 end = scp->mouse_cut_start - 1;
1737 /* does the cut-mark region overlap with the update region? */
1738 if (and_region(&s, &e, scp->start, scp->end)) {
1739 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1742 if (and_region(&s, &e, scp->start, scp->end))
1743 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1745 e = scp->xsize*scp->ysize - 1;
1746 if (and_region(&s, &e, scp->start, scp->end))
1747 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1749 (*scp->rndr->draw)(scp, scp->start,
1750 scp->end - scp->start + 1, FALSE);
1753 (*scp->rndr->draw)(scp, scp->start,
1754 scp->end - scp->start + 1, FALSE);
1758 /* we are not to show the cursor and the mouse pointer... */
1761 scp->start = scp->xsize*scp->ysize - 1;
1762 --scp->sc->videoio_in_progress;
1766 /* update cursor image */
1767 if (scp->status & CURSOR_ENABLED) {
1770 /* did cursor move since last time ? */
1771 if (scp->cursor_pos != scp->cursor_oldpos) {
1772 /* do we need to remove old cursor image ? */
1773 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1774 sc_remove_cursor_image(scp);
1775 sc_draw_cursor_image(scp);
1777 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1778 /* cursor didn't move, but has been overwritten */
1779 sc_draw_cursor_image(scp);
1780 else if (scp->sc->flags & SC_BLINK_CURSOR)
1781 /* if it's a blinking cursor, update it */
1782 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1783 sc_inside_cutmark(scp,
1788 #ifndef SC_NO_CUTPASTE
1789 /* update "pseudo" mouse pointer image */
1790 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1791 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1792 scp->status &= ~MOUSE_MOVED;
1793 sc_draw_mouse_image(scp);
1796 #endif /* SC_NO_CUTPASTE */
1799 scp->start = scp->xsize*scp->ysize - 1;
1801 --scp->sc->videoio_in_progress;
1806 scsplash_callback(int event, void *arg)
1811 sc = (sc_softc_t *)arg;
1815 if (add_scrn_saver(scsplash_saver) == 0) {
1816 sc->flags &= ~SC_SAVER_FAILED;
1817 run_scrn_saver = TRUE;
1818 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1819 scsplash_stick(TRUE);
1820 (*current_saver)(sc, TRUE);
1826 if (current_saver == scsplash_saver) {
1827 scsplash_stick(FALSE);
1828 error = remove_scrn_saver(scsplash_saver);
1840 scsplash_saver(sc_softc_t *sc, int show)
1842 static int busy = FALSE;
1851 if (!(sc->flags & SC_SAVER_FAILED)) {
1852 if (!(sc->flags & SC_SCRN_BLANKED))
1853 set_scrn_saver_mode(scp, -1, NULL, 0);
1854 switch (splash(sc->adp, TRUE)) {
1855 case 0: /* succeeded */
1857 case EAGAIN: /* try later */
1858 restore_scrn_saver_mode(scp, FALSE);
1859 sc_touch_scrn_saver(); /* XXX */
1862 sc->flags |= SC_SAVER_FAILED;
1863 scsplash_stick(FALSE);
1864 restore_scrn_saver_mode(scp, TRUE);
1865 kprintf("scsplash_saver(): failed to put up the image\n");
1869 } else if (!sticky_splash) {
1870 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1871 restore_scrn_saver_mode(scp, TRUE);
1877 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1882 if (current_saver != none_saver) {
1883 error = remove_scrn_saver(current_saver);
1888 if (current_saver != none_saver)
1891 run_scrn_saver = FALSE;
1892 saver_mode = CONS_LKM_SAVER;
1893 current_saver = this_saver;
1898 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1900 if (current_saver != this_saver)
1905 * In order to prevent `current_saver' from being called by
1906 * the timeout routine `scrn_timer()' while we manipulate
1907 * the saver list, we shall set `current_saver' to `none_saver'
1908 * before stopping the current saver, rather than blocking by `splXX()'.
1910 current_saver = none_saver;
1912 stop_scrn_saver(this_saver);
1915 /* unblank all blanked screens */
1916 wait_scrn_saver_stop(NULL);
1920 current_saver = none_saver;
1925 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1928 /* assert(scp == scp->sc->cur_scp) */
1930 if (!ISGRAPHSC(scp))
1931 sc_remove_cursor_image(scp);
1932 scp->splash_save_mode = scp->mode;
1933 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1934 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1935 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1936 scp->sc->flags |= SC_SCRN_BLANKED;
1942 if (set_mode(scp) == 0) {
1943 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1944 scp->status |= GRAPHICS_MODE;
1945 #ifndef SC_NO_PALETTE_LOADING
1947 load_palette(scp->sc->adp, pal);
1949 sc_set_border(scp, border);
1953 scp->mode = scp->splash_save_mode;
1954 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1955 scp->status |= scp->splash_save_status;
1962 restore_scrn_saver_mode(scr_stat *scp, int changemode)
1967 /* assert(scp == scp->sc->cur_scp) */
1970 status = scp->status;
1971 scp->mode = scp->splash_save_mode;
1972 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
1973 scp->status |= scp->splash_save_status;
1974 scp->sc->flags &= ~SC_SCRN_BLANKED;
1976 if (!ISGRAPHSC(scp))
1977 sc_draw_cursor_image(scp);
1982 if (set_mode(scp) == 0) {
1983 #ifndef SC_NO_PALETTE_LOADING
1984 load_palette(scp->sc->adp, scp->sc->palette);
1991 scp->status = status;
1998 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2000 (*saver)(sc, FALSE);
2001 run_scrn_saver = FALSE;
2002 /* the screen saver may have chosen not to stop after all... */
2003 if (sc->flags & SC_SCRN_BLANKED)
2006 mark_all(sc->cur_scp);
2007 if (sc->delayed_next_scr)
2008 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2009 wakeup((caddr_t)&scrn_blanked);
2013 wait_scrn_saver_stop(sc_softc_t *sc)
2017 while (scrn_blanked > 0) {
2018 run_scrn_saver = FALSE;
2019 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2023 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2024 /* May return ERESTART */
2028 run_scrn_saver = FALSE;
2031 #endif /* NSPLASH */
2034 sc_touch_scrn_saver(void)
2036 scsplash_stick(FALSE);
2037 run_scrn_saver = FALSE;
2041 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2046 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2048 /* prevent switch if previously requested */
2049 if (sc->flags & SC_SCRN_VTYLOCK) {
2050 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2051 sc->cur_scp->bell_duration);
2055 /* delay switch if the screen is blanked or being updated */
2056 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2057 || sc->blink_in_progress || sc->videoio_in_progress) {
2058 sc->delayed_next_scr = next_scr + 1;
2059 sc_touch_scrn_saver();
2060 DPRINTF(5, ("switch delayed\n"));
2065 cur_scp = sc->cur_scp;
2067 /* we are in the middle of the vty switching process... */
2068 if (sc->switch_in_progress
2069 && (cur_scp->smode.mode == VT_PROCESS)
2071 if (cur_scp->proc != pfind(cur_scp->pid)) {
2073 * The controlling process has died!!. Do some clean up.
2074 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2075 * are not reset here yet; they will be cleared later.
2077 DPRINTF(5, ("cur_scp controlling process %d died, ",
2079 if (cur_scp->status & SWITCH_WAIT_REL) {
2081 * Force the previous switch to finish, but return now
2084 * note: must be called from a critical section because
2085 * finish_vt_rel will call do_switch_scr which releases it
2088 DPRINTF(5, ("reset WAIT_REL, "));
2089 finish_vt_rel(cur_scp, TRUE);
2091 DPRINTF(5, ("finishing previous switch\n"));
2093 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2094 /* let's assume screen switch has been completed. */
2095 DPRINTF(5, ("reset WAIT_ACQ, "));
2096 finish_vt_acq(cur_scp);
2099 * We are in between screen release and acquisition, and
2100 * reached here via scgetc() or scrn_timer() which has
2101 * interrupted exchange_scr(). Don't do anything stupid.
2103 DPRINTF(5, ("waiting nothing, "));
2107 * The controlling process is alive, but not responding...
2108 * It is either buggy or it may be just taking time.
2109 * The following code is a gross kludge to cope with this
2110 * problem for which there is no clean solution. XXX
2112 if (cur_scp->status & SWITCH_WAIT_REL) {
2113 switch (sc->switch_in_progress++) {
2117 DPRINTF(5, ("sending relsig again, "));
2118 signal_vt_rel(cur_scp);
2125 * Act as if the controlling program returned
2128 * note: must be called from a critical section because
2129 * finish_vt_rel will call do_switch_scr which releases it
2132 DPRINTF(5, ("force reset WAIT_REL, "));
2133 finish_vt_rel(cur_scp, FALSE);
2135 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2138 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2139 switch (sc->switch_in_progress++) {
2143 DPRINTF(5, ("sending acqsig again, "));
2144 signal_vt_acq(cur_scp);
2150 /* clear the flag and finish the previous switch */
2151 DPRINTF(5, ("force reset WAIT_ACQ, "));
2152 finish_vt_acq(cur_scp);
2160 * Return error if an invalid argument is given, or vty switch
2161 * is still in progress.
2163 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2164 || sc->switch_in_progress) {
2166 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2167 DPRINTF(5, ("error 1\n"));
2172 * Don't allow switching away from the graphics mode vty
2173 * if the switch mode is VT_AUTO, unless the next vty is the same
2174 * as the current or the current vty has been closed (but showing).
2176 tp = VIRTUAL_TTY(sc, cur_scp->index);
2177 if ((cur_scp->index != next_scr)
2179 && (cur_scp->smode.mode == VT_AUTO)
2180 && ISGRAPHSC(cur_scp)) {
2182 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2183 DPRINTF(5, ("error, graphics mode\n"));
2188 * Is the wanted vty open? Don't allow switching to a closed vty.
2189 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2190 * Note that we always allow the user to switch to the kernel
2191 * console even if it is closed.
2193 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2194 tp = VIRTUAL_TTY(sc, next_scr);
2195 if (!ISTTYOPEN(tp)) {
2197 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2198 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2201 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2203 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2208 /* this is the start of vty switching process... */
2209 ++sc->switch_in_progress;
2210 sc->delayed_next_scr = 0;
2211 sc->old_scp = cur_scp;
2212 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2213 if (sc->new_scp == sc->old_scp) {
2214 sc->switch_in_progress = 0;
2215 wakeup((caddr_t)&sc->new_scp->smode);
2217 DPRINTF(5, ("switch done (new == old)\n"));
2221 /* has controlling process died? */
2222 vt_proc_alive(sc->old_scp);
2223 vt_proc_alive(sc->new_scp);
2225 /* wait for the controlling process to release the screen, if necessary */
2226 if (signal_vt_rel(sc->old_scp)) {
2231 /* go set up the new vty screen */
2236 /* wake up processes waiting for this vty */
2237 wakeup((caddr_t)&sc->cur_scp->smode);
2239 /* wait for the controlling process to acknowledge, if necessary */
2240 if (signal_vt_acq(sc->cur_scp)) {
2245 sc->switch_in_progress = 0;
2246 if (sc->unit == sc_console_unit)
2247 cons_unavail = FALSE;
2249 DPRINTF(5, ("switch done\n"));
2255 * NOTE: must be called from a critical section because do_switch_scr
2256 * will release it temporarily.
2259 do_switch_scr(sc_softc_t *sc)
2261 vt_proc_alive(sc->new_scp);
2266 /* sc->cur_scp == sc->new_scp */
2267 wakeup((caddr_t)&sc->cur_scp->smode);
2269 /* wait for the controlling process to acknowledge, if necessary */
2270 if (!signal_vt_acq(sc->cur_scp)) {
2271 sc->switch_in_progress = 0;
2272 if (sc->unit == sc_console_unit)
2273 cons_unavail = FALSE;
2278 vt_proc_alive(scr_stat *scp)
2281 if (scp->proc == pfind(scp->pid))
2284 scp->smode.mode = VT_AUTO;
2285 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2291 signal_vt_rel(scr_stat *scp)
2293 if (scp->smode.mode != VT_PROCESS)
2295 scp->status |= SWITCH_WAIT_REL;
2296 ksignal(scp->proc, scp->smode.relsig);
2297 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2302 signal_vt_acq(scr_stat *scp)
2304 if (scp->smode.mode != VT_PROCESS)
2306 if (scp->sc->unit == sc_console_unit)
2307 cons_unavail = TRUE;
2308 scp->status |= SWITCH_WAIT_ACQ;
2309 ksignal(scp->proc, scp->smode.acqsig);
2310 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2315 * NOTE: must be called from a critical section because do_switch_scr
2316 * will release it temporarily.
2319 finish_vt_rel(scr_stat *scp, int release)
2321 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2322 scp->status &= ~SWITCH_WAIT_REL;
2324 do_switch_scr(scp->sc);
2326 scp->sc->switch_in_progress = 0;
2333 finish_vt_acq(scr_stat *scp)
2335 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2336 scp->status &= ~SWITCH_WAIT_ACQ;
2337 scp->sc->switch_in_progress = 0;
2344 exchange_scr(sc_softc_t *sc)
2348 /* save the current state of video and keyboard */
2349 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2350 if (!ISGRAPHSC(sc->old_scp))
2351 sc_remove_cursor_image(sc->old_scp);
2352 if (sc->old_scp->kbd_mode == K_XLATE)
2353 save_kbd_state(sc->old_scp);
2355 /* set up the video for the new screen */
2356 scp = sc->cur_scp = sc->new_scp;
2357 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2360 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2361 (void *)sc->adp->va_window, FALSE);
2362 scp->status |= MOUSE_HIDDEN;
2363 sc_move_cursor(scp, scp->xpos, scp->ypos);
2364 if (!ISGRAPHSC(scp))
2365 sc_set_cursor_image(scp);
2366 #ifndef SC_NO_PALETTE_LOADING
2367 if (ISGRAPHSC(sc->old_scp))
2368 load_palette(sc->adp, sc->palette);
2370 sc_set_border(scp, scp->border);
2372 /* set up the keyboard for the new screen */
2373 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2374 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2375 update_kbd_state(scp, scp->status, LOCK_MASK);
2381 sc_puts(scr_stat *scp, u_char *buf, int len)
2384 /* make screensaver happy */
2385 if (!sticky_splash && scp == scp->sc->cur_scp)
2386 run_scrn_saver = FALSE;
2390 (*scp->tsw->te_puts)(scp, buf, len);
2392 if (scp->sc->delayed_next_scr)
2393 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2397 sc_draw_cursor_image(scr_stat *scp)
2399 /* assert(scp == scp->sc->cur_scp); */
2400 ++scp->sc->videoio_in_progress;
2401 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2402 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2403 sc_inside_cutmark(scp, scp->cursor_pos));
2404 scp->cursor_oldpos = scp->cursor_pos;
2405 --scp->sc->videoio_in_progress;
2409 sc_remove_cursor_image(scr_stat *scp)
2411 /* assert(scp == scp->sc->cur_scp); */
2412 ++scp->sc->videoio_in_progress;
2413 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2414 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2415 sc_inside_cutmark(scp, scp->cursor_oldpos));
2416 --scp->sc->videoio_in_progress;
2420 update_cursor_image(scr_stat *scp)
2424 if (scp->sc->flags & SC_CHAR_CURSOR) {
2425 scp->cursor_base = imax(0, scp->sc->cursor_base);
2426 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2428 scp->cursor_base = 0;
2429 scp->cursor_height = scp->font_size;
2431 blink = scp->sc->flags & SC_BLINK_CURSOR;
2433 /* assert(scp == scp->sc->cur_scp); */
2434 ++scp->sc->videoio_in_progress;
2435 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2436 sc_inside_cutmark(scp, scp->cursor_pos));
2437 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2438 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2439 sc_inside_cutmark(scp, scp->cursor_pos));
2440 --scp->sc->videoio_in_progress;
2444 sc_set_cursor_image(scr_stat *scp)
2446 if (scp->sc->flags & SC_CHAR_CURSOR) {
2447 scp->cursor_base = imax(0, scp->sc->cursor_base);
2448 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2450 scp->cursor_base = 0;
2451 scp->cursor_height = scp->font_size;
2454 /* assert(scp == scp->sc->cur_scp); */
2455 ++scp->sc->videoio_in_progress;
2456 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2457 scp->sc->flags & SC_BLINK_CURSOR);
2458 --scp->sc->videoio_in_progress;
2462 scinit(int unit, int flags)
2465 * When syscons is being initialized as the kernel console, malloc()
2466 * is not yet functional, because various kernel structures has not been
2467 * fully initialized yet. Therefore, we need to declare the following
2468 * static buffers for the console. This is less than ideal,
2469 * but is necessry evil for the time being. XXX
2471 static scr_stat main_console;
2472 static u_short sc_buffer[ROW*COL]; /* XXX */
2473 #ifndef SC_NO_FONT_LOADING
2474 static u_char font_8[256*8];
2475 static u_char font_14[256*14];
2476 static u_char font_16[256*16];
2481 video_adapter_t *adp;
2486 /* one time initialization */
2487 if (init_done == COLD)
2488 sc_get_bios_values(&bios_value);
2492 * Allocate resources. Even if we are being called for the second
2493 * time, we must allocate them again, because they might have
2496 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2498 if (sc->adapter >= 0) {
2499 vid_release(sc->adp, (void *)&sc->adapter);
2503 if (sc->keyboard >= 0) {
2504 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2505 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2506 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2507 if (sc->kbd != NULL) {
2508 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2509 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2513 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2514 sc->adp = vid_get_adapter(sc->adapter);
2515 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2516 sc->keyboard = kbd_allocate("*", unit, (void *)&sc->keyboard,
2518 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2519 sc->kbd = kbd_get_keyboard(sc->keyboard);
2520 if (sc->kbd != NULL) {
2521 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2522 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2525 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2527 sc->initial_mode = sc->adp->va_initial_mode;
2529 #ifndef SC_NO_FONT_LOADING
2530 if (flags & SC_KERNEL_CONSOLE) {
2531 sc->font_8 = font_8;
2532 sc->font_14 = font_14;
2533 sc->font_16 = font_16;
2534 } else if (sc->font_8 == NULL) {
2535 /* assert(sc_malloc) */
2536 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2537 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2538 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2542 /* extract the hardware cursor location and hide the cursor for now */
2543 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2544 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2546 /* set up the first console */
2547 sc->first_vty = unit*MAXCONS;
2548 sc->vtys = MAXCONS; /* XXX: should be configurable */
2549 if (flags & SC_KERNEL_CONSOLE) {
2550 scp = &main_console;
2551 sc->console_scp = scp;
2552 init_scp(sc, sc->first_vty, scp);
2553 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2554 (void *)sc_buffer, FALSE);
2555 if (sc_init_emulator(scp, SC_DFLT_TERM))
2556 sc_init_emulator(scp, "*");
2557 (*scp->tsw->te_default_attr)(scp,
2558 kernel_default.std_color,
2559 kernel_default.rev_color);
2561 /* assert(sc_malloc) */
2562 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2564 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2565 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2567 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2568 scp = alloc_scp(sc, sc->first_vty);
2569 sc->dev[0]->si_drv1 = scp;
2573 /* copy screen to temporary buffer */
2574 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2575 (void *)scp->sc->adp->va_window, FALSE);
2577 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2579 /* move cursors to the initial positions */
2580 if (col >= scp->xsize)
2582 if (row >= scp->ysize)
2583 row = scp->ysize - 1;
2586 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2587 if (bios_value.cursor_end < scp->font_size)
2588 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2590 sc->cursor_base = 0;
2591 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2592 sc->cursor_height = imin(i, scp->font_size);
2593 #ifndef SC_NO_SYSMOUSE
2594 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2596 if (!ISGRAPHSC(scp)) {
2597 sc_set_cursor_image(scp);
2598 sc_draw_cursor_image(scp);
2601 /* save font and palette */
2602 #ifndef SC_NO_FONT_LOADING
2603 sc->fonts_loaded = 0;
2604 if (ISFONTAVAIL(sc->adp->va_flags)) {
2606 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2607 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2608 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2609 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2610 if (scp->font_size < 14) {
2611 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2612 } else if (scp->font_size >= 16) {
2613 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2615 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2617 #else /* !SC_DFLT_FONT */
2618 if (scp->font_size < 14) {
2619 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2620 sc->fonts_loaded = FONT_8;
2621 } else if (scp->font_size >= 16) {
2622 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2623 sc->fonts_loaded = FONT_16;
2625 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2626 sc->fonts_loaded = FONT_14;
2628 #endif /* SC_DFLT_FONT */
2629 /* FONT KLUDGE: always use the font page #0. XXX */
2630 sc_show_font(scp, 0);
2632 #endif /* !SC_NO_FONT_LOADING */
2634 #ifndef SC_NO_PALETTE_LOADING
2635 save_palette(sc->adp, sc->palette);
2639 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2640 /* we are ready to put up the splash image! */
2641 splash_init(sc->adp, scsplash_callback, sc);
2642 sc->flags |= SC_SPLASH_SCRN;
2644 #endif /* NSPLASH */
2647 /* the rest is not necessary, if we have done it once */
2648 if (sc->flags & SC_INIT_DONE)
2651 /* initialize mapscrn arrays to a one to one map */
2652 for (i = 0; i < sizeof(sc->scr_map); i++)
2653 sc->scr_map[i] = sc->scr_rmap[i] = i;
2655 sc->flags |= SC_INIT_DONE;
2659 scterm(int unit, int flags)
2664 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2666 return; /* shouldn't happen */
2669 /* this console is no longer available for the splash screen */
2670 if (sc->flags & SC_SPLASH_SCRN) {
2671 splash_term(sc->adp);
2672 sc->flags &= ~SC_SPLASH_SCRN;
2674 #endif /* NSPLASH */
2677 /* move the hardware cursor to the upper-left corner */
2678 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2681 /* release the keyboard and the video card */
2682 if (sc->keyboard >= 0)
2683 kbd_release(sc->kbd, &sc->keyboard);
2684 if (sc->adapter >= 0)
2685 vid_release(sc->adp, &sc->adapter);
2688 * Stop the terminal emulator, if any. If operating on the
2689 * kernel console sc->dev may not be setup yet.
2691 if (flags & SC_KERNEL_CONSOLE)
2692 scp = sc->console_scp;
2694 scp = SC_STAT(sc->dev[0]);
2696 (*scp->tsw->te_term)(scp, &scp->ts);
2697 if (scp->ts != NULL)
2698 kfree(scp->ts, M_SYSCONS);
2700 /* clear the structure */
2701 if (!(flags & SC_KERNEL_CONSOLE)) {
2702 /* XXX: We need delete_dev() for this */
2703 kfree(sc->dev, M_SYSCONS);
2705 /* XXX: We need a ttyunregister for this */
2706 kfree(sc->tty, M_SYSCONS);
2708 #ifndef SC_NO_FONT_LOADING
2709 kfree(sc->font_8, M_SYSCONS);
2710 kfree(sc->font_14, M_SYSCONS);
2711 kfree(sc->font_16, M_SYSCONS);
2713 /* XXX vtb, history */
2715 bzero(sc, sizeof(*sc));
2721 scshutdown(void *arg, int howto)
2723 /* assert(sc_console != NULL) */
2725 sc_touch_scrn_saver();
2726 if (!cold && sc_console
2727 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2728 && sc_console->smode.mode == VT_AUTO)
2729 sc_switch_scr(sc_console->sc, sc_console->index);
2730 shutdown_in_progress = TRUE;
2734 sc_clean_up(scr_stat *scp)
2738 #endif /* NSPLASH */
2740 if (scp->sc->flags & SC_SCRN_BLANKED) {
2741 sc_touch_scrn_saver();
2743 if ((error = wait_scrn_saver_stop(scp->sc)))
2745 #endif /* NSPLASH */
2747 scp->status |= MOUSE_HIDDEN;
2748 sc_remove_mouse_image(scp);
2749 sc_remove_cutmarking(scp);
2754 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2760 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2761 if (!discard && (old.vtb_flags & VTB_VALID)) {
2762 /* retain the current cursor position and buffer contants */
2763 scp->cursor_oldpos = scp->cursor_pos;
2765 * This works only if the old buffer has the same size as or larger
2766 * than the new one. XXX
2768 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2772 sc_vtb_destroy(&old);
2775 #ifndef SC_NO_SYSMOUSE
2776 /* move the mouse cursor at the center of the screen */
2777 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2782 alloc_scp(sc_softc_t *sc, int vty)
2786 /* assert(sc_malloc) */
2788 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
2789 init_scp(sc, vty, scp);
2791 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2792 if (sc_init_emulator(scp, SC_DFLT_TERM))
2793 sc_init_emulator(scp, "*");
2795 #ifndef SC_NO_CUTPASTE
2796 sc_alloc_cut_buffer(scp, TRUE);
2799 #ifndef SC_NO_HISTORY
2800 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2807 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2811 bzero(scp, sizeof(*scp));
2816 scp->mode = sc->initial_mode;
2817 callout_init(&scp->blink_screen_ch);
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 scp->rndr->init(scp);
2916 sc_clear_screen(scp);
2917 /* assert(error == 0); */
2921 if (sc_malloc && (sw->te_size > 0))
2922 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
2925 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2930 (*scp->tsw->te_term)(scp, &scp->ts);
2931 if (scp->ts != NULL)
2932 kfree(scp->ts, M_SYSCONS);
2936 scp->rndr->init(scp);
2939 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2940 sc_clear_screen(scp);
2946 * scgetc(flags) - get character from keyboard.
2947 * If flags & SCGETC_CN, then avoid harmful side effects.
2948 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2949 * return NOKEY if there is nothing there.
2952 scgetc(sc_softc_t *sc, u_int flags)
2955 #ifndef SC_NO_HISTORY
2963 if (sc->kbd == NULL)
2968 /* I don't like this, but... XXX */
2969 if (flags & SCGETC_CN)
2970 sccnupdate(sc->cur_scp);
2973 /* first see if there is something in the keyboard port */
2975 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
2977 if (!(flags & SCGETC_CN))
2978 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
2979 } else if (c == NOKEY)
2985 /* make screensaver happy */
2987 sc_touch_scrn_saver();
2989 if (!(flags & SCGETC_CN))
2990 /* do the /dev/random device a favour */
2991 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 kprintf("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(struct dev_mmap_args *ap)
3230 scp = SC_STAT(ap->a_head.a_dev);
3231 if (scp != scp->sc->cur_scp)
3233 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3239 save_kbd_state(scr_stat *scp)
3244 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3245 if (error == ENOIOCTL)
3248 scp->status &= ~LOCK_MASK;
3249 scp->status |= state;
3255 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3260 if (mask != LOCK_MASK) {
3261 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3262 if (error == ENOIOCTL)
3267 state |= new_bits & mask;
3269 state = new_bits & LOCK_MASK;
3271 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3272 if (error == ENOIOCTL)
3278 update_kbd_leds(scr_stat *scp, int which)
3283 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3284 if (error == ENOIOCTL)
3290 set_mode(scr_stat *scp)
3294 /* reject unsupported mode */
3295 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3298 /* if this vty is not currently showing, do nothing */
3299 if (scp != scp->sc->cur_scp)
3302 /* setup video hardware for the given mode */
3303 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3304 scp->rndr->init(scp);
3305 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3306 (void *)scp->sc->adp->va_window, FALSE);
3308 #ifndef SC_NO_FONT_LOADING
3309 /* load appropriate font */
3310 if (!(scp->status & GRAPHICS_MODE)) {
3311 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3312 if (scp->font_size < 14) {
3313 if (scp->sc->fonts_loaded & FONT_8)
3314 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3315 } else if (scp->font_size >= 16) {
3316 if (scp->sc->fonts_loaded & FONT_16)
3317 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3319 if (scp->sc->fonts_loaded & FONT_14)
3320 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3324 * This is an interim kludge to display correct font.
3325 * Always use the font page #0 on the video plane 2.
3326 * Somehow we cannot show the font in other font pages on
3327 * some video cards... XXX
3329 sc_show_font(scp, 0);
3333 #endif /* !SC_NO_FONT_LOADING */
3335 sc_set_border(scp, scp->border);
3336 sc_set_cursor_image(scp);
3342 refresh_ega_palette(scr_stat *scp)
3346 int rsize, gsize, bsize;
3347 int rfld, gfld, bfld;
3350 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3351 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3352 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3353 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3354 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3355 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3357 for (i = 0; i < 16; i++) {
3358 reg = scp->sc->adp->va_palette_regs[i];
3360 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3361 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3362 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3364 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3369 sc_set_border(scr_stat *scp, int color)
3371 ++scp->sc->videoio_in_progress;
3372 (*scp->rndr->draw_border)(scp, color);
3373 --scp->sc->videoio_in_progress;
3376 #ifndef SC_NO_FONT_LOADING
3378 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3379 int base, int count)
3384 sc->font_loading_in_progress = TRUE;
3385 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3386 sc->font_loading_in_progress = FALSE;
3390 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3391 int base, int count)
3396 sc->font_loading_in_progress = TRUE;
3397 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3398 sc->font_loading_in_progress = FALSE;
3402 sc_show_font(scr_stat *scp, int page)
3404 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3406 #endif /* !SC_NO_FONT_LOADING */
3409 sc_paste(scr_stat *scp, u_char *p, int count)
3414 if (scp->status & MOUSE_VISIBLE) {
3415 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3418 rmap = scp->sc->scr_rmap;
3419 for (; count > 0; --count)
3420 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3425 sc_bell(scr_stat *scp, int pitch, int duration)
3427 if (cold || shutdown_in_progress)
3430 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3433 if (scp->sc->flags & SC_VISUAL_BELL) {
3434 if (scp->sc->blink_in_progress)
3436 scp->sc->blink_in_progress = 3;
3437 if (scp != scp->sc->cur_scp)
3438 scp->sc->blink_in_progress += 2;
3439 blink_screen(scp->sc->cur_scp);
3440 } else if (duration != 0 && pitch != 0) {
3441 if (scp != scp->sc->cur_scp)
3443 sysbeep(pitch, duration);
3448 blink_screen(void *arg)
3450 scr_stat *scp = arg;
3453 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3454 scp->sc->blink_in_progress = 0;
3456 tp = VIRTUAL_TTY(scp->sc, scp->index);
3459 if (scp->sc->delayed_next_scr)
3460 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3463 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3464 scp->sc->blink_in_progress & 1);
3465 scp->sc->blink_in_progress--;
3466 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);